home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / admin / calendar.php < prev    next >
Encoding:
PHP Script  |  2003-12-22  |  12.0 KB  |  373 lines

  1. <?php
  2. /////////////////////////////////////////////////////////
  3. //    
  4. //    source/calendar.php
  5. //
  6. //    (C)Copyright 2002-2003 Ryo Chijiiwa <Ryo@IlohaMail.org>
  7. //
  8. //        This file is part of IlohaMail.
  9. //        IlohaMail is free software released under the GPL 
  10. //        license.  See enclosed file COPYING for details,
  11. //        or see http://www.fsf.org/copyleft/gpl.html
  12. //
  13. /////////////////////////////////////////////////////////
  14.  
  15. /********************************************************
  16.  
  17.     AUTHOR: Ryo Chijiiwa <ryo@ilohamail.org>
  18.     FILE:  source/compose.php
  19.     PURPOSE:
  20.         Display calendar...
  21.     
  22. ********************************************************/
  23.  
  24. include("../include/super2global.inc");
  25. include("../include/header_main.inc");
  26. include("../lang/".$my_prefs["lang"]."dates.inc");
  27. include("../lang/".$my_prefs["lang"]."calendar.inc");
  28. include("../include/icl.inc");
  29. include("../include/version.inc");
  30. include("../conf/defaults.inc");
  31. include("../include/calendar.inc");
  32.  
  33. //authenticate
  34. $conn=iil_Connect($host, $loginID, $password, $AUTH_MODE);
  35. if ($conn){
  36.     iil_Close($conn);
  37. }else{
  38.     echo "Authentication failed.";
  39.     echo "</body></html>\n";
  40.     exit;
  41. }
  42.  
  43. //make sure feature is not disabled
  44. if ($DISABLE_CALENDAR){
  45.     echo $calStr["disabled"];
  46.     echo "</body></html>\n";
  47.     exit;
  48. }
  49.  
  50. if ($edit_cal || $delete_cal){
  51.     include("../include/edit_calendar.inc");
  52. }
  53.  
  54. echo "<center>\n";
  55.  
  56. if (($go_month > 0) && ($go_year > 0)) $date = formatCalDate($go_month, 1, $go_year);
  57.  
  58. if (empty($date)) $date = date("Ymd", time());
  59. if (strlen($date)==8){
  60.     $current_year = substr($date, 0, 4);
  61.     $current_month = substr($date, 4, 2);
  62.     $current_day = substr($date, 6, 2);
  63. }
  64. if (!isset($current_ts)) $current_ts = mktime(0, 0, 0, $current_month, $current_day, $current_year);
  65.  
  66. //what's today's day of week?
  67. $dow = date("w", $current_ts);
  68.  
  69. if (!isset($disp_mode)) $disp_mode = 0;
  70. //0: begin on sunday
  71. //1: begin on monday
  72. //2: begin 3 days ago
  73. //3: begin today
  74. if ($disp_mode==0) $offset = $dow;
  75. else if ($disp_mode==1) $offset = $dow-1;
  76. else if ($disp_mode==2) $offset = 3;
  77. else if ($disp_mode==3) $offset = 0;
  78.  
  79. //time stamp for last sunday (beginning of week)
  80. $start_ts = $current_ts - ($offset * (60 * 60 * 24));
  81.  
  82. //time stamp for next saturday (end of week)
  83. $end_ts = $start_ts + (60 * 60 * 24 * 6);
  84.  
  85. //which week of the month?
  86. $end_day = date("d", $end_ts);
  87. $wom = (int)($end_day / 7);
  88. if (($end_day % 7) != 0) $wom++;
  89.  
  90. //starting date
  91. $start_date = date("Ymd", $start_ts);
  92. $end_date = date("Ymd", $end_ts);
  93.  
  94. //create hash tables for day-of-week <-> date
  95. for ($i=0; $i<7; $i++){
  96.     $temp_ts = $start_ts + ($i * (60 * 60 * 24));
  97.     $temp_date = date("Ymd", $temp_ts);
  98.     $temp_dow = date("w", $temp_ts);
  99.     $date_dow[$temp_date] = "d".$temp_dow;        //date to day-of-week lookup
  100.     $dow_date["d".$temp_dow] = $temp_date;        //day-of-week to date lookup
  101.     $schedule2[$temp_date]["dow"] = $temp_dow;
  102. }
  103.  
  104. $sql = "SELECT * FROM $DB_CALENDAR_TABLE WHERE userID='$session_dataID' ";
  105. $sql.= "and ((beginDate<='$end_date' and endDate>='$start_date') ";
  106. $sql.= "or (endDate<='$end_date' and endDate>='$start_date'))";
  107.  
  108. $backend_result = false;
  109.  
  110. if ($backend!="FS"){
  111.     include_once("../conf/db_conf.php");
  112.     include_once("../include/idba.$DB_TYPE.inc");
  113.     
  114.     if (!isset($db)) $db = new idba_obj;
  115.     if ($db->connect()){
  116.         $backend_result = $db->query($sql);
  117.     }else{
  118.         $backend_result = false;
  119.     }
  120. }
  121. if ($backend_result){
  122.     if ($db->num_rows($backend_result) > 0){
  123.         //initialize schedule array
  124.         //$schedule = array();
  125.         
  126.         //echo $backend_num_rows($backend_result)." rows";
  127.         
  128.         //loop through records
  129.         while( $a = $db->fetch_row($backend_result) ){
  130.             //create & initialize new scheduleItem object
  131.             $item = new scheduleItem;
  132.             $item->id = $a["id"];
  133.             $item->title = $a["title"];
  134.             $item->place = $a["place"];
  135.             $item->description = $a["description"];
  136.             $item->participants = $a["participants"];
  137.             $item->beginTime = $a["beginTime"];
  138.             $item->endTime = $a["endTime"];
  139.             $item->color = $a["color"];
  140.             
  141.             //echo "<!-- ".$a["id"].":".$a["color"]." //-->\n";
  142.             
  143.             $pattern = $a["pattern"];
  144.             $beginDate = $a["beginDate"];
  145.             $endDate = $a["endDate"];
  146.             
  147.             //non-repeating event
  148.             //if (strpos($pattern, "d:")===false){
  149.             $pattern = chop($pattern);
  150.             if (empty($pattern)){
  151.                 
  152.                 if ($beginDate == $endDate){
  153.                 //single day event
  154.                     $schedule2[$beginDate][$item->beginTime][] = $item;
  155.                 }else{
  156.                 //multi-day event
  157.                     if (($beginDate>=$start_date) && ($beginDate <= $end_date)){
  158.                         //insert event for first day (event ends at midnight)
  159.                         $temp_item = $item;
  160.                         $temp_item->endTime = 2400;
  161.                         $schedule2[$beginDate][$item->beginTime][]=$temp_item;                    }
  162.                     if (($endDate<=$end_date) && ($endDate >= $start_date)){
  163.                         //insert event for last day (event beings at midnight)
  164.                         $temp_item = $item;
  165.                         $temp_item->beginTime = 0;
  166.                         $schedule2[$endDate][0][]=$temp_item;
  167.                     }
  168.                     
  169.                     if (($endDate-$beginDate)>1){
  170.                         //if event spans more than two days, insert events for all days inbetween
  171.                         
  172.                         if (!empty($date_dow[$beginDate])) $fromD = $date_dow[$beginDate][1]+1;
  173.                         else $fromD = 0;
  174.                         if (!empty($date_dow[$endDate])) $untilD = $date_dow[$endDate][1];
  175.                         else $untilD = 7;
  176.                         
  177.                         reset($date_dow);
  178.                         while ( list($k,$v) = each($date_dow) ){
  179.                             if (($k > $beginDate) && ($k < $endDate)){
  180.                                 $temp_item = $item;
  181.                                 $temp_item->beginTime = 0;
  182.                                 $temp_item->endTime = 2400;
  183.                                 $schedule2[$k][0][]=$temp_item;
  184.                             }
  185.                         }
  186.                         
  187.                     }
  188.                 }
  189.             }else{
  190.             //repeating event
  191.                 //check if this week is included in repetition
  192.                 if ((strpos($pattern,"w:all")!==false) || (strpos($pattern, "w".$wom)!==false)){
  193.                     $words = explode(" ", $pattern);
  194.                     while( list($k,$w)=each($words) ) if ($w[0]=="d") $dowpat=$w;
  195.                     $dowpat = substr($dowpat, 2);
  196.                     $dows = explode(",", $dowpat);
  197.                     while( list($k, $d)=each($dows) ){
  198.                         if (($dow_date["d".$d]>$start_date) && ($dow_date["d".$d]<$end_date)){
  199.                             $schedule2[$dow_date["d".$d]][$item->beginTime][]=$item;
  200.                         }
  201.                     }
  202.                 }else if (false !== ($pos=strpos($pattern, "m:"))){
  203.                     $repeat_day = substr($pattern, $pos+2, 2);
  204.                     $repeat_date = $current_year.$current_month.$repeat_day;
  205.                     if (($repeat_date >= $start_date) && ($repeat_date <= $end_date))
  206.                         $schedule2[$repeat_date][$item->beginTime][]=$item;
  207.                 }else if (false !== ($pos=strpos($pattern, "y:"))){
  208.                     $repeat_date = substr($pattern, $pos+2, 4);
  209.                     $repeat_date = $current_year.$repeat_date;
  210.                     if (($repeat_date >= $start_date) && ($repeat_date <= $end_date))
  211.                         $schedule2[$repeat_date][$item->beginTime][]=$item;                    
  212.                 }
  213.             }
  214.         }
  215.  
  216.     }else{
  217.         echo $error;
  218.     }
  219.  
  220.     if (is_array($schedule2)){
  221.         $start_date_a = getdate($start_ts);
  222.         $end_date_a = getdate($end_ts);
  223.         
  224.         $last_ts = $current_ts - (60 * 60 * 24 * 7);
  225.         $next_ts = $current_ts + (60 * 60 * 24 * 7);
  226.         
  227.         echo "<table width=\"60%\" cellspacing=0 cellpadding=0>\n";
  228.         echo "<tr bgcolor=\"".$my_colors["main_head_bg"]."\">";
  229.         echo "<td width=\"15%\" align=\"left\">";
  230.             echo "<a class=mainHeading href=\"calendar.php?user=$user&date=".date("Ymd",$last_ts)."&mode=$mode\"><<</a";
  231.         echo "</td>\n";
  232.         echo "<td width=\"70%\" align=\"center\">";
  233.             echo "<span class=\"bigTitle\">";
  234.             $wdate_a = array("m"=>$lang_datetime["short_mon"][$start_date_a["mon"]], "d"=>$start_date_a["mday"], "y"=>$start_date_a["year"]);
  235.             $wdate_str = LangInsertStringsFromAK($lang_datetime["verbal"], $wdate_a);
  236.             echo str_replace("%d", $wdate_str, $calStr["weekof"]);
  237.             echo "</span>\n";
  238.         echo "</td>\n";
  239.         echo "<td width=\"15%\" align=\"right\">";
  240.                 echo "<a class=mainHeading href=\"calendar.php?user=$user&date=".date("Ymd",$next_ts)."&mode=$mode\">>></a";
  241.         echo "</td>\n";
  242.         echo "</table>\n";
  243.         
  244.         $dsow = array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
  245.         
  246.         //display weekly schedule
  247.         echo "\n<p>\n";
  248.         echo '<table width="95%" border="0" cellspacing="1" cellpadding="3" bgcolor="'.$my_colors["main_head_bg"].'">';
  249.         
  250.         //show tabl header -days of week and dates
  251.         echo "\n<tr>\n";
  252.         reset($date_dow);
  253.         while ( list($k,$d)=each($date_dow) ){
  254.             $tbh_month = (int)substr($k, 4, 2);
  255.             $tbh_day = (int)substr($k, 6, 2);
  256.             $tbh_a = array("m"=>$lang_datetime["short_mon"][$tbh_month], "d"=>$tbh_day);
  257.             $tbh_str = LangInsertStringsFromAK($lang_datetime["verbal_short"], $tbh_a);
  258.             echo "<td align=\"center\" bgcolor=\"".$my_colors["main_hilite"]."\" width=\"14%\">";
  259.             echo ($k==$date?"<b>":"").$lang_datetime["dsow"][$d[1]]."<br>".$tbh_str.($k==$date?"</b>":"");
  260.             echo "</td>\n";
  261.         }
  262.         echo "</tr>\n";
  263.         
  264.         //show schedule
  265.         echo "<tr>\n";
  266.         reset($schedule2);
  267.         while (list($k,$schedules)=each($schedule2)){
  268.             if (!empty($k)){
  269.                 echo "<td align=\"left\" valign=\"top\" bgcolor=\"".$my_colors["main_bg"]."\" width=\"14%\"><span class=\"small\">";
  270.                 echo "[<a href=\"edit_calendar.php?user=$user&date=".$k."edit=\">+</a>]\n";
  271.                 
  272.                 $schedules = $schedule2[$k];
  273.                 
  274.                 //echo count($schedules);
  275.                 
  276.                 ksort($schedules);
  277.                 reset($schedules);
  278.                 while(list($start, $blah) = each($schedules)){
  279.                     if (strcmp($start,"date")!=0){
  280.                         if (is_array($schedules[$start])){
  281.                             while ( list($k2, $item)=each($schedules[$start]) ){
  282.                                 //$item = $schedules[$start];
  283.                                 echo "<p>";
  284.                         
  285.                                 if (!empty($item->color)) $style="style=\"color: ".$item->color."\"";
  286.                                 else $style="";
  287.                         
  288.                                 if (($item->beginTime+$item->endTime)!=0){
  289.                                     echo LangFormatIntTime($item->beginTime, $my_prefs["clock_system"], $lang_datetime["ampm"], $lang_datetime["time_format"]);
  290.                                     //echo $item->beginTime;
  291.                                     echo "-";
  292.                                     //echo $item->endTime;
  293.                                     echo LangFormatIntTime($item->endTime, $my_prefs["clock_system"], $lang_datetime["ampm"], $lang_datetime["time_format"]);
  294.                                     echo ":<br>\n";
  295.                                 }
  296.                                 echo "<a href=\"edit_calendar.php?user=$user&edit=".$item->id."\" $style>";
  297.                                 echo $item->title;
  298.                                 echo (!empty($item->place)?" @":"").$item->place;
  299.                                 echo "</a>\n";
  300.                             }
  301.                         }
  302.                     }
  303.                 }
  304.                 echo "</span></td>\n";
  305.             } //if
  306.         }//while
  307.     }
  308.     echo "</tr>\n";
  309.     echo "</table>\n";
  310. }//if ($backend_result)
  311.  
  312.  
  313. //default values for month/year
  314. $month = (int)$current_month;
  315. $year = (int)$current_year;
  316. $prev_month = ($month>1?$month-1:12);
  317. $prev_year = ($month==1?$year-1:$year);
  318. $next_month = ($month<12?$month+1:1);
  319. $next_year = ($month==12?$year+1:$year);
  320.  
  321. echo "<p>\n";
  322. echo "<table cellspacing=0 cellpadding=0><tr bgcolor=\"".$my_colors["main_head_bg"]."\">\n";
  323. echo "<td valign=\"middle\">";
  324. echo "<a class=mainHeading href=\"calendar.php?user=$user&date=".formatCalDate($current_month, $current_day, $current_year-1)."\"> << </a>\n";
  325. echo "<a class=mainHeading href=\"calendar.php?user=$user&date=".formatCalDate($prev_month, $current_day, $prev_year)."\"> < </a>\n";
  326. echo "</td>";
  327. ?>
  328. <td class=mainHeading valign=bottom>
  329. <form method="POST" action="calendar.php">
  330.     <input type="hidden" name="user" value="<?php echo $user ?>">
  331.     <select name="go_month">
  332.     <?php
  333.     for ($i=1;$i<=12;$i++) echo "<option value=\"$i\" ".($i==$current_month?"SELECTED":"").">".$lang_months[$i]."\n";
  334.     ?>
  335.     </select>
  336.     <select name="go_year">
  337.     <?php
  338.     for ($i=-5;$i<=10;$i++){
  339.         $go_year = $current_year + $i;
  340.         echo "<option value=\"$go_year\" ".($go_year==$current_year?"SELECTED":"").">$go_year\n";
  341.     }
  342.     ?>
  343.     </select>
  344.     <input type="submit" name="go" value="<?php echo $calStr["go"]?>">
  345. </form>
  346. </td>
  347. <?php
  348. echo "<td valign=\"middle\">";
  349. echo "<a class=mainHeading href=\"calendar.php?user=$user&date=".formatCalDate($next_month, $current_day, $next_year)."\"> > </a>\n";
  350. echo "<a class=mainHeading href=\"calendar.php?user=$user&date=".formatCalDate($current_month, $current_day, $current_year+1)."\"> >> </a>\n";
  351. echo "</td>";
  352. echo "</tr></table>\n";
  353. echo "<p><table wdith=\"95%\" cellspacing=\"10\"><tr>\n";
  354. echo "<td valign=\"top\">";
  355. $month = $prev_month;
  356. $year = $prev_year;
  357. include("../include/display_monthly_calendar.inc");
  358. echo "</td><td valign=\"top\">";
  359. $month = (int)$current_month;
  360. $year = $current_year;
  361. include("../include/display_monthly_calendar.inc");
  362. echo "</td><td valign=\"top\">";
  363. $month = $next_month;
  364. $year = $next_year;
  365. include("../include/display_monthly_calendar.inc");
  366. echo "</td>";
  367. echo "</tr></table>";
  368.  
  369.  
  370. echo "</center>";
  371.  
  372. ?>
  373.