SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict anita_86's Avatar
    Join Date
    Aug 2010
    Location
    Nagpur, India
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Event Manager In PHP

    Hi!I am a newbie in PHP & have got a task of making event manager in PHP that too with different user levels. The problem is I cant find the exact code I am looking for. Can anyone please guide me how to display the events from database according to the user level??

  2. #2
    SitePoint Evangelist mrwooster's Avatar
    Join Date
    Jan 2006
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to have a look at Access Control Lists. These allow you to assign different permission levels to users and display content according to their permission level.

    There are a lots of solutions out there.

  3. #3
    SitePoint Addict anita_86's Avatar
    Join Date
    Aug 2010
    Location
    Nagpur, India
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Problem is not with access levels but with the calendar and event display

  4. #4
    SitePoint Evangelist mrwooster's Avatar
    Join Date
    Jan 2006
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you provide some code example of how user access is determined... this will help us understand the problem a bit better. There are many ways that user access could be implemented so until we know which one you are using its a bit tricky to help.

    Ty

  5. #5
    SitePoint Addict anita_86's Avatar
    Join Date
    Aug 2010
    Location
    Nagpur, India
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <?PHP
    $user=$_GET['level'];
    $id=$_GET['id'];
    if($user=="1")
    {
    $query=mysql_query("SELECT * FROM mssgs WHERE uid='".$id."'");
    }
    // ..& so on
    ?>
    I found the following code which is simple to change but it is using external XML file and I dont know a damn about XML
    Code:
    <?
    if (!isset($_GET['year']))
    {
    $year = date(Y);
    }
    // otherwise, save this POST data under a simpler variable name
    else 
    {
    $year = $_GET['year'];
    }
    // get the month number (1-12) if one not provided
    if (!isset($_GET['monthNo'])) {
    $monthNo = date(n);
    }
    // otherwise, save this POST data under a simpler variable name
    else {
    $monthNo = $_GET['monthNo'];
    }
    // get current month name
    $monthName = date(F, mktime(0, 0, 0, $monthNo, 1, $year));
    // get the number of days in this month
    $daysInMonth = date(t, mktime(0, 0, 0, $monthNo, 1, $year));
    // get XML data
    //$data = implode("", file($xmlFile));
    // create XML parser
    //$parser = xml_parser_create();
    // set parser options
    //xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    //xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    // parse XML data into arrays
    //xml_parse_into_struct($parser, $data, $values, $tags);
    // free parser
    //xml_parser_free($parser);
    // set variables for cycling through parsed XML data
    $i = 0; // set the array counter variable
    $lookForMonth = 0; // set default to false
    $getDays = 0; // set default to false
    // cycle through parsed XML data
    while ($i < count($values)) {
    // if close tag of current month and year, stop cycle
    if ($getDays && $values[$i][tag] == $monthName) {
    break;
    }
    // if open tag of current year, start looking for current month 
    if ($values[$i][tag] == "Y$year" && $values[$i][type] == "open") {
    $lookForMonth = 1;
    }
    // get days
    if ($getDays) {
    // get day number from tag name
    $day = $values[$i][tag];
    // cut "D" off tag name
    $day = substr($day, 1);
    // put day number as key and event description as value in new array
    $event[$day] = $values[$i][value];
    }
    // if tag of current month, start getting days
    if ($lookForMonth && $values[$i][tag] == $monthName) {
    $getDays = 1;
    }
    // increment counter
    $i++;
    }
    // PRINT CALENDAR
    // print the HTML document header
    echo "<html>\n\n";
    echo "<head>\n";
    echo "<title>Calendar</title>\n";
    echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"calendar.css\">\n";
    echo "</head>\n\n";
    echo "<body>\n";
    // print the calendar table head
    echo "<table align=\"center\">\n";
    echo "<caption>$monthName $year</caption>\n";
    echo "<tr>\n";
    echo "\t<th>Sunday</th>\n";
    echo "\t<th>Monday</th>\n";
    echo "\t<th>Tuesday</th>\n";
    echo "\t<th>Wednesday</th>\n";
    echo "\t<th>Thursday</th>\n";
    echo "\t<th>Friday</th>\n";
    echo "\t<th>Saturday</th>\n";
    echo "</tr>\n";
    // for each day of the month
    for ($dayNo = 1; $dayNo <= $daysInMonth; $dayNo++) {
    // get the day name
    $dayName = date(D, mktime(0, 0, 0, $monthNo, $dayNo, $year));
    // if the first day of the month is not Sunday
    if ($dayNo == 1 && $dayName != "Sun") {
    // start a new row
    echo "<tr>\n";
    // get the day of the week number (0-6)
    $dayOfWeek = date(w, mktime(0, 0, 0, $monthNo, $dayNo, $year));
    // print empty table cells until we reach the first day of the month
    for ($i = 0; $i < $dayOfWeek; $i++) {
    echo "\t<td></td>\n";
    }
    }
    // if Sunday, start a new row
    if ($dayName == "Sun") {
    echo "<tr>\n";
    }
    // if event exists for this day, print day cell with event
    if (isset($event[$dayNo])) {
    echo "\t<td class=\"event\"><b>$dayNo</b> $event[$dayNo]</td>\n";
    }
    // otherwise, print day cell without event
    else {
    echo "\t<td><b>$dayNo</b></td>\n";
    }
    // if Saturday, close this row
    if ($dayName == "Sat") {
    echo "</tr>\n";
    }
    // if the last day of the month is not Saturday
    if ($dayNo == $daysInMonth && $dayName != "Sat") {
    // get the day of the week number (0-6)
    $dayOfWeek = date(w, mktime(0, 0, 0, $monthNo, $dayNo, $year));
    // print empty table cells until we reach Saturday
    for ($i = 6; $i > $dayOfWeek; $i--) {
    echo "\t<td></td>\n";
    }
    // close this row
    echo "</tr>\n";
    }
    }
    // close the table
    echo "</table>\n";
    echo "<br>\n";
    // PRINT NAVIGATION MENU
    // calculate previous month
    $prevMonth = $monthNo - 1;
    // if previous month number is 0, reset to 12 and decrement year
    if ($prevMonth == 0) {
    $prevMonth = 12;
    $prevYear = $year - 1;
    }
    // otherwise, keep same year
    else {
    $prevYear = $year;
    }
    // calculate next month
    $nextMonth = $monthNo + 1;
    // if next month number is 13, reset to 1 and increment year
    if ($nextMonth == 13) {
    $nextMonth = 1;
    $nextYear = $year + 1;
    }
    // otherwise, keep same year
    else {
    $nextYear = $year;
    }
    // get previous month name
    $prevMonthName = date(F, mktime(0, 0, 0, $prevMonth, 1, $prevYear));
    // get next month name
    $nextMonthName = date(F, mktime(0, 0, 0, $nextMonth, 1, $nextYear));
    // print links for previous and next months
    echo "<p align=\"center\">[ <a href=\"?year=$prevYear&monthNo=$prevMonth\"><< $prevMonthName</a> | <a href=\"?year=$nextYear&monthNo=$nextMonth\">$nextMonthName >></a> ]</p>\n";
    // print the HTML document footer
    echo "</body>\n\n";
    echo "</html>";
    ?>
    It displays events in following code:
    Code:
    // if event exists for this day, print day cell with event
    if (isset($event[$dayNo])) {
    echo "\t<td class=\"event\"><b>$dayNo</b> $event[$dayNo]</td>\n";
    }
    // otherwise, print day cell without event
    else {
    echo "\t<td><b>$dayNo</b></td>\n";
    }
    But the values are posted through XML and not PHP.
    I need desperate help with the query where I can check whether the day has events and print it on that too according with the user level.

  6. #6
    SitePoint Evangelist mrwooster's Avatar
    Join Date
    Jan 2006
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you can check a users level like this

    PHP Code:
    if ($user == "1") {
     
    // Do something that a user with level 1 access can do

    I have to say, I am still a little confused what you are asking.... it looks like you already have some access control in place.

  7. #7
    SitePoint Addict anita_86's Avatar
    Join Date
    Aug 2010
    Location
    Nagpur, India
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeh I have a login panel through which a user access the data. If user is admin, he can access all the data in the event calender.
    So if user level==1, all events from the database have to display which I have saved in mysql database.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •