home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / calendar / calendar.inc < prev    next >
Text File  |  2004-03-08  |  9KB  |  237 lines

  1. <?php
  2.  
  3.  
  4. //show_days is the number of days to show (defined in index.php)
  5. //max_columns (defined in index.php)
  6. //day_start is the first day of the week (defined in index.php)
  7.  
  8. if ($show_days > 29)
  9. {
  10.     $day = 1;
  11. }
  12. if ($show_days > 4)
  13. {
  14.     //calculate the first day to display in the week view.
  15.     $weekday = date("w", $local_browse_time);
  16.     $tmpday = $day - $weekday + $_SESSION['GO_SESSION']['first_weekday'];
  17.     if ($tmpday > $day)
  18.     {
  19.         $tmpday = $tmpday -7;
  20.     }
  21.     $new_time = mktime(0,0,0,$month, $tmpday, $year);
  22.     $day = date("j", $new_time);
  23.     $month = date('m', $new_time);
  24.     $year = date('Y', $new_time);
  25. }
  26.  
  27. $interval_start_time = mktime(0,0,0,$month, $day, $year)-($_SESSION['GO_SESSION']['timezone']*3600);
  28. $interval_end_time = mktime(0,0,0,$month, $day+$show_days, $year)-($_SESSION['GO_SESSION']['timezone']*3600)-1;
  29.  
  30. $events = $cal->get_events_in_array($calendar_id, 0, $interval_start_time, $interval_end_time, $day, $month, $year, $_SESSION['GO_SESSION']['timezone'], $calendar['start_hour']);
  31.  
  32. //var_dump($events);
  33. //display the calendar
  34.  
  35. echo '<table border="0"><tr><td><h3>';
  36. echo $sc_view.': </h3></td><td>';
  37. $dropbox = new dropbox();
  38. $dropbox->add_value('1', '1 '.$sc_day);
  39. $dropbox->add_value('2', '2 '.$sc_days);
  40. $dropbox->add_value('5', '5 '.$sc_days);
  41. $dropbox->add_value('7', '1 '.$sc_week);
  42. $dropbox->add_value('14', '2 '.$sc_weeks);
  43. $dropbox->add_value('21', '3 '.$sc_weeks);
  44. $dropbox->add_value('35', '1 '.$sc_month);
  45. $dropbox->print_dropbox("show_days", $show_days, 'onchange="javascript:document.forms[0].submit()"');
  46.  
  47. echo '</td><td><h3><a href="javascript:goto_date('.($day-$show_days).', '.$month.', '.$year.');"><<</a> ';
  48. echo date($_SESSION['GO_SESSION']['date_format'], $interval_start_time+($_SESSION['GO_SESSION']['timezone']*3600)).' - '.date($_SESSION['GO_SESSION']['date_format'], $interval_end_time+($_SESSION['GO_SESSION']['timezone']*3600));
  49. echo ' <a href="javascript:goto_date('.($day+$show_days).', '.$month.', '.$year.');">>></a>';
  50. echo '</h3></td></tr></table>';
  51.  
  52.  
  53. echo '<table id="cal" width="100%">';
  54. $rows = $show_days/$max_columns;
  55. for($row=0;$row<$rows;$row++)
  56. {
  57.     $start_day = $row*$max_columns;
  58.     $end_day = $start_day+$max_columns;
  59.  
  60.     if ($end_day > $show_days)
  61.     {
  62.         $end_day = $show_days;
  63.     }
  64.  
  65.     $weeknumber = date("W", mktime(0,0,0,$month,$day+$start_day,$year));
  66.  
  67.     echo '<tr><td colspan="99" align="center" class="cal_title">';
  68.     echo $sc_week.' '.$weeknumber;
  69.     echo '</td></tr>';
  70.     //create table headings
  71.     echo '<tr>';
  72.     echo '<th width="40"></th>';
  73.  
  74.     for ($day_offset=$start_day;$day_offset<$end_day;$day_offset++)
  75.     {
  76.         $day_to_display = $day+$day_offset;
  77.         $new_time = mktime(0,0, 0, $month, $day_to_display, $year);
  78.         $new_date = date(DB_DATE_FORMAT, $new_time);
  79.         $new_day = date('j', $new_time);
  80.         $new_month = date('m', $new_time);
  81.         $new_year = date('Y', $new_time);
  82.  
  83.         //get holiday name if ever
  84.         $holiday_name = "";
  85.         if($holidays->get_holiday($GO_SECURITY->user_id, $calendar_id, $new_time))
  86.         {
  87.             $holiday_name = $holidays->f("name");
  88.         }
  89.  
  90.         if ($new_date == $current_date)
  91.         {
  92.             $class="HoverLinkSelected";
  93.         }else
  94.         {
  95.             $class="HoverLink";
  96.         }
  97.         $weekday = date('w', $new_time);
  98.         echo '<th><a href="index.php?calendar_id='.$calendar_id.'&year='.$new_year.'&month='.$new_month.'&day='.$new_day.'&show_days=1" class="'.$class.'">'.$full_days[$weekday].'<br />'.date($_SESSION['GO_SESSION']['date_format'],$new_time).'<br />'.$holiday_name.'</a>';
  99.             //$update_reminder = $cal->get_next_recurrence_time(47, $new_time);
  100.  
  101.             //echo date(DB_DATETIME_FORMAT, $update_reminder);
  102.         echo '</th>';
  103.     }
  104.     echo '</tr>';
  105.  
  106.     //process the all day events
  107.  
  108.     if (count($events['all_day']))
  109.     {
  110.         echo '<tr id="cal_all_day_events">';
  111.         echo '<td class="cal_hour"></td>';
  112.  
  113.         for ($day_offset=$start_day;$day_offset<$end_day;$day_offset++)
  114.         {
  115.             echo '<td>';
  116.             $day_to_display = $day+$day_offset;
  117.             $new_time = mktime(0,0, 0, $month, $day_to_display, $year);
  118.             $new_date = date('Ymd', $new_time);
  119.             if (isset($events['all_day'][$new_date]))
  120.             {
  121.                 $all_day_event_count = count($events['all_day'][$new_date]);
  122.  
  123.                 $height = round(100/$all_day_event_count,1);
  124.                 $height .= '%';
  125.  
  126.                 while ($event = array_shift($events['all_day'][$new_date]))
  127.                 {
  128.                     echo '<table id="cal_event" width="100%" style="background-color: #'.$event['background'].'" height="'.$height.'"><tr><td width="100%">';
  129.                     $link = $event['write_permission'] ? 'event.php' : 'show_event.php';
  130.                     echo '<a class="calendar_event_link" href="'.$link.'?event_id='.$event['id'].'">'.$event['name'].'</a>';
  131.                     echo'<br />';
  132.                     if (date($_SESSION['GO_SESSION']['date_format'], $event['start_time']) != date($_SESSION['GO_SESSION']['date_format'], $event['end_time']))
  133.                     {
  134.                         echo date($_SESSION['GO_SESSION']['date_format'], $event['start_time']).' - '.date($_SESSION['GO_SESSION']['date_format'], $event['end_time']).'<br />';
  135.                     }
  136.                     echo show_profile($event['user_id'], '', 'small_underline');
  137.                     if (($calendar['write_permission'] || $event['write_permission']) && !$print)
  138.                     {
  139.                         echo '</td><td valign="top" width="16" style="background-color: #'.$event['background'].'">';
  140.                         echo '<a href="delete_event.php?event_id='.$event['id'].'&return_to='.rawurlencode($_SERVER['REQUEST_URI']).'" title="'.$strDeleteItem.' "\''.$cal->f("name").'\'"><img src="'.$GO_THEME->images['delete'].'" border="0"></a>';
  141.  
  142.                     }
  143.                     echo '</td></tr></table>';
  144.                 }
  145.                 echo '</td>';
  146.             }
  147.         }
  148.         echo '</tr>';
  149.     }
  150.  
  151.     for ($hour_of_day=$calendar['start_hour'];$hour_of_day<=$calendar['end_hour'];$hour_of_day++)
  152.     {
  153.         echo '<tr id="'.$row.'_'.$hour_of_day.'"><td width="40" align="right" class="cal_hour">'.$hour_of_day.':00</td>';
  154.  
  155.         //display the days row by row
  156.         for ($day_offset=$start_day;$day_offset<$end_day;$day_offset++)
  157.         {
  158.             $day_to_display = $day+$day_offset;
  159.  
  160.             //make a valid date
  161.             $new_time = mktime(0,0, 0, $month, $day_to_display, $year);
  162.             $new_date = date('Ymd', $new_time);
  163.             $new_day = date("j", $new_time);
  164.             $new_month = date('m', $new_time);
  165.             $new_year = date('Y', $new_time);
  166.  
  167.  
  168.             if(isset($events['timed'][$new_date][$hour_of_day]))
  169.             {
  170.                 echo '<td height="100%">';
  171.                 $hour_event_count = count($events['timed'][$new_date][$hour_of_day]);
  172.  
  173.                 $height = round(100/$hour_event_count,1);
  174.                 $height .= '%';
  175.                 while($event = array_shift($events['timed'][$new_date][$hour_of_day]))
  176.                 {
  177.                     echo '<table id="cal_event" width="100%" height="'.$height.'" style="background-color: #'.$event['background'].'"><tr><td width="100%">';
  178.                     $link = $event['write_permission'] ? 'event.php' : 'show_event.php';
  179.                     echo '<a class="calendar_event_link" href="'.$link.'?event_id='.$event['id'].'&return_to='.rawurlencode($_SERVER['REQUEST_URI']).'">'.$event['name'].'</a>';
  180.                     echo'<br />';
  181.                     if (date($_SESSION['GO_SESSION']['date_format'], $event['start_time']) != date($_SESSION['GO_SESSION']['date_format'], $event['end_time']))
  182.                     {
  183.                         $date_format = $_SESSION['GO_SESSION']['date_format'].' '.$_SESSION['GO_SESSION']['time_format'];
  184.                     }else
  185.                     {
  186.                         $date_format = $_SESSION['GO_SESSION']['time_format'];
  187.                     }
  188.                     echo date($date_format, $event['start_time']).' - '.date($date_format, $event['end_time']).'<br />';
  189.  
  190.                     echo show_profile($event['user_id'], '', 'small_underline');
  191.                     if (($calendar['write_permission'] || $event['write_permission']) && !$print)
  192.                     {
  193.                         echo '</td><td valign="top" width="16">';
  194.                         echo '<a href="delete_event.php?event_id='.$event['id'].'&return_to='.rawurlencode($_SERVER['REQUEST_URI']).'" title="'.$strDeleteItem.' "\''.$cal->f("name").'\'"><img src="'.$GO_THEME->images['delete'].'" border="0"></a>';
  195.                     }
  196.                     echo '</td></tr></table>';
  197.  
  198.                 }
  199.             }else
  200.             {
  201.                 if (isset($events['backgrounds'][$new_date][$hour_of_day]))
  202.                 {
  203.                     $style = ' style="background-color: #'.$events['backgrounds'][$new_date][$hour_of_day].'"';
  204.                 }else
  205.                 {
  206.                     $style = '';
  207.                 }
  208.                 echo '<td height="100%"'.$style.'>';
  209.                 if(!$print && $calendar['write_permission'])
  210.                 {
  211.                     echo '<a onmouseover="javascript:glow_row(\''.$row.'_'.$hour_of_day.'\');" onmouseout="javascript:unglow_row(\''.$row.'_'.$hour_of_day.'\');" href="event.php?calendar_id='.$calendar_id.'&day='.$new_day.'&month='.$new_month.'&year='.$new_year.'&hour='.$hour_of_day.'"><img border="0" width="100%" height="12" src="'.$GO_THEME->images['blank'].'" /></a>';
  212.                 }
  213.  
  214.             }
  215.             echo '</td>';
  216.         }
  217.         echo '</tr>';
  218.     }
  219.  
  220. }
  221. echo '</table>';
  222. ?>
  223. <script type="text/javascript">
  224.  
  225. function glow_row(hour)
  226. {
  227.     table_row = get_object(hour);
  228.     table_row.style.backgroundColor = '#FFFFCC';
  229. }
  230.  
  231. function unglow_row(hour)
  232. {
  233.     table_row = get_object(hour);
  234.     table_row.style.backgroundColor = '';
  235. }
  236. </script>
  237.