home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / calendar / index.php < prev    next >
PHP Script  |  2004-03-08  |  9KB  |  230 lines

  1. <?php
  2. /*
  3. Copyright Intermesh 2003
  4. Author: Merijn Schering <mschering@intermesh.nl>
  5. Version: 1.0 Release date: 08 July 2003
  6.  
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.
  11. */
  12.  
  13.  
  14. //how many days does the user wants to see? (remember in cookie)
  15. $GO_CAL_SHOW_DAYS = isset($_COOKIE['GO_CAL_SHOW_DAYS']) ? $_COOKIE['GO_CAL_SHOW_DAYS'] : 7;
  16. $show_days = isset($_REQUEST['show_days']) ? $_REQUEST['show_days'] : $GO_CAL_SHOW_DAYS;
  17.  
  18. SetCookie("GO_CAL_SHOW_DAYS",$show_days,time()+3600*24*30,"/",'',0);
  19.  
  20. //are we in print view?
  21. $print = isset($_REQUEST['print']) ? true : false;
  22.  
  23. require("../../Group-Office.php");
  24.  
  25. $max_columns = 7;
  26.  
  27. require_once($GO_CONFIG->class_path.'calendar.class.inc');
  28. $cal = new calendar();
  29.  
  30. //get the local times
  31. $local_time = get_time();
  32. $year = isset($_REQUEST['year']) ? $_REQUEST['year'] : date("Y", $local_time);
  33. $month = isset($_REQUEST['month']) ? $_REQUEST['month'] : date("m", $local_time);
  34. $day = isset($_REQUEST['day']) ? $_REQUEST['day'] : date("j", $local_time);
  35. $hour = isset($_REQUEST['hour']) ? $_REQUEST['hour'] : date("H", $local_time);
  36. $min = isset($_REQUEST['min']) ? $_REQUEST['min'] : date("i", $local_time);
  37. $local_browse_time = mktime($hour, $min, 0, $month, $day, $year);
  38.  
  39. //recalculate date
  40. $year = date("Y", $local_browse_time);
  41. $month = date("m", $local_browse_time);
  42. $day = date("j", $local_browse_time);
  43. $hour = date("H", $local_browse_time);
  44. $min = date("i", $local_browse_time);
  45.  
  46.  
  47. //get the current date properties
  48. $current_year = date("Y", $local_time);
  49. $current_month = date("m", $local_time);
  50. $current_day = date("j", $local_time);
  51. $current_hour = date("H", $local_time);
  52. $current_min = date("i", $local_time);
  53. $current_date = date(DB_DATE_FORMAT, $local_time);
  54.  
  55. $hours = array("00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23");
  56. $mins = array("00","05","10","15","20","25","30","35","40","45","50","55");
  57.  
  58. for ($i=1;$i<32;$i++)
  59. {
  60.     $num_days[] = $i;
  61. }
  62.  
  63. for ($i=1;$i<13;$i++)
  64. {
  65.     $num_months[] = $i;
  66. }
  67.  
  68.  
  69. $years[0] = $year-4;
  70. $years[1] = $year-3;
  71. $years[2] = $year-2;
  72. $years[3] = $year-1;
  73. $years[4] = $year;
  74. $years[5] = $year+1;
  75. $years[6] = $year+2;
  76. $years[7] = $year+3;
  77. $years[8] = $year+4;
  78.  
  79.  
  80. $GO_SECURITY->authenticate();
  81. $GO_MODULES->authenticate('calendar');
  82. require($GO_LANGUAGE->get_language_file('calendar'));
  83.  
  84. $task = isset($_REQUEST['task']) ? $_REQUEST['task'] : '';
  85. $return_to = isset($_POST['return_to']) ? $_POST['return_to'] : '';
  86.  
  87. //get the calendar to display. If there isn't any create one
  88. $calendar_id = isset($_REQUEST['calendar_id']) ? $_REQUEST['calendar_id'] : $cal->get_default_calendar($GO_SECURITY->user_id);
  89.  
  90. if (!$calendar_id)
  91. {
  92.     require_once($GO_CONFIG->class_path.'users.class.inc');
  93.     $users = new users();
  94.     $user = $users->get_user($GO_SECURITY->user_id);
  95.     $calendar_name = $user["first_name"].' '.$user['last_name'];
  96.     $new_calendar_name = $calendar_name;
  97.     $x = 1;
  98.     while($cal->get_calendar_by_name($new_calendar_name))
  99.     {
  100.         $new_calendar_name = $calendar_name.' ('.$x.')';
  101.         $x++;
  102.     }
  103.  
  104.     if (!$calendar_id = $cal->add_calendar($GO_SECURITY->user_id, $user["first_name"].' '.$user['last_name'], '0', '23'))
  105.     {
  106.         $feedback = '<p class="Error">'.$strSaveError.'</p>';
  107.     }
  108. }
  109.  
  110. //get the calendar properties and check permissions
  111. if ($calendar = $cal->get_calendar($calendar_id))
  112. {
  113.     $calendar['read_permission'] = $GO_SECURITY->has_permission($GO_SECURITY->user_id, $calendar['acl_read']);
  114.     $calendar['write_permission'] = $GO_SECURITY->has_permission($GO_SECURITY->user_id, $calendar['acl_write']);
  115.     if (!$calendar['read_permission'] && !$calendar['write_permission'] )
  116.     {
  117.         header('Location: '.$GO_CONFIG->host.'error_docs/401.php');
  118.         exit();
  119.     }
  120.  
  121. }
  122. //automatically refresh this page
  123. //$auto_refresh_url = $GO_CONFIG->protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  124.  
  125. if (!$print) {
  126. $datepicker = new date_picker();
  127. $GO_HEADER['head'] = $datepicker->get_header();
  128. require($GO_THEME->theme_path."header.inc");
  129. ?>
  130. <script type="text/javascript">
  131. function date_picker(calendar) {
  132.     // Beware that this function is called even if the end-user only
  133.     // changed the month/year.  In order to determine if a date was
  134.     // clicked you can use the dateClicked property of the calendar:
  135.     if (calendar.dateClicked) {
  136.       // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
  137.       var y = calendar.date.getFullYear();
  138.       var m = calendar.date.getMonth()+1;     // integer, 0..11
  139.       var d = calendar.date.getDate();      // integer, 1..31
  140.       // redirect...
  141.       window.location = "index.php?calendar_id=<?php echo $calendar_id; ?>&show_days=<?php echo $show_days; ?>&day="+d+"&month="+m+"&year="+y;
  142.     }
  143.   };
  144.  
  145. function goto_date(day, month, year)
  146. {
  147.     document.forms[0].day.value = day;
  148.     document.forms[0].month.value = month;
  149.     document.forms[0].year.value = year;
  150.     document.forms[0].submit();
  151. }
  152. </script>
  153.  
  154. <table border="0" cellpadding="0" cellspacing="0">
  155. <tr>
  156.     <td class="ModuleIcons"><a href="event.php" class="small"><img src="<?php echo $GO_THEME->images['cal_compose']; ?>" border="0" width="32" height="32" /><br /><?php echo $sc_new_app; ?></a></td>
  157.     <td class="ModuleIcons"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?show_days=1&calendar_id=<?php echo $calendar_id; ?>&day=<?php echo $day; ?>&month=<?php echo $month; ?>&year=<?php echo $year; ?>" class="small"><img src="<?php echo $GO_THEME->images['cal_day']; ?>" border="0" width="32" height="32" /><br /><?php echo $sc_day_view; ?></a></td>
  158.     <td class="ModuleIcons"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?show_days=7&calendar_id=<?php echo $calendar_id; ?>&day=<?php echo $day; ?>&month=<?php echo $month; ?>&year=<?php echo $year; ?>" class="small"><img src="<?php echo $GO_THEME->images['cal_week']; ?>" border="0" width="32" height="32" /><br /><?php echo $sc_week_view; ?></a></td>
  159.     <td class="ModuleIcons"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?show_days=35&calendar_id=<?php echo $calendar_id; ?>&day=<?php echo $day; ?>&month=<?php echo $month; ?>&year=<?php echo $year; ?>" class="small"><img src="<?php echo $GO_THEME->images['cal_month']; ?>" border="0" width="32" height="32" /><br /><?php echo $sc_month_view; ?></a></td>
  160.     <td class="ModuleIcons"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?show_days=<?php echo $show_days; ?>&calendar_id=<?php echo $calendar_id; ?>&day=<?php echo $day; ?>&month=<?php echo $month; ?>&year=<?php echo $year; ?>&task=list_view" class="small"><img src="<?php echo $GO_THEME->images['cal_list']; ?>" border="0" width="32" height="32" /><br /><?php echo $sc_list_view; ?></a></td>
  161.     <td class="ModuleIcons"><a href="calendars.php?return_to=<?php echo $_SERVER['REQUEST_URI']; ?>" class="small"><img src="<?php echo $GO_THEME->images['cal_calendar']; ?>" border="0" width="32" height="32" /><br /><?php echo $sc_calendars; ?></a></td>
  162.     <td class="ModuleIcons"><a href="<?php echo $_SERVER['REQUEST_URI']; ?>" class="small"><img src="<?php echo $GO_THEME->images['cal_refresh']; ?>" border="0" width="32" height="32" /><br /><?php echo $sc_refresh; ?></a></td>
  163.     <td class="ModuleIcons"><a href="javascript:popup('<?php echo $GO_MODULES->url; ?>index.php?print=true&show_days=<?php echo $show_days; ?>&calendar_id=<?php echo $calendar_id; ?>&day=<?php echo $day; ?>&month=<?php echo $month; ?>&year=<?php echo $year; ?>','','')" class="small"><img src="<?php echo $GO_THEME->images['cal_print']; ?>" border="0" width="32" height="32" /><br /><?php echo $cmdPrint; ?></a></td>
  164. </tr>
  165. </table>
  166. <form name="calendar_form" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  167. <input type="hidden" name="task" value="<?php echo $task; ?>" />
  168. <input type="hidden" name="year" value="<?php echo $year; ?>" />
  169. <input type="hidden" name="month" value="<?php echo $month; ?>" />
  170. <input type="hidden" name="day" value="<?php echo $day; ?>" />
  171.  
  172. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  173. </tr>
  174. <tr>
  175.     <td valign="top" style="width: 18em;">
  176.     <?php
  177.     if ($cal->get_subscribed($GO_SECURITY->user_id) > 1)
  178.     {
  179.         echo '<table border="0"><tr><td><h3>'.$sc_calendar.':</h3></td><td>';
  180.         $dropbox = new dropbox();
  181.         $dropbox->add_sql_data("cal","id","name");
  182.         $dropbox->print_dropbox("calendar_id", $calendar_id, 'onchange="javascript:document.forms[0].submit()"');
  183.         echo '</td></tr></table>';
  184.     }
  185.     ?>
  186.     <div id="date_picker1_container" style="margin-right: 1em;"></div>
  187.     <div style="height: 2em;"></div>
  188.     <div id="date_picker2_container" style="margin-right: 1em;"></div>
  189.     </td>
  190.     <td valign="top">
  191.     <?php
  192.  
  193. }else
  194. {
  195.     require($GO_THEME->theme_path."simple_header.inc");
  196. }
  197.  
  198. require_once($GO_CONFIG->class_path.'cal_holidays.class.inc');
  199. $holidays = new holidays($GO_LANGUAGE);
  200.  
  201. if ($task == 'list_view')
  202. {
  203.     require('list_view.inc');
  204. }else
  205. {
  206.     require('calendar.inc');
  207. }
  208.  
  209.  
  210. if (!$print)
  211. {
  212.     ?>
  213.     </td>
  214. </tr>
  215. </table>
  216. </form>
  217. <?php
  218. require($GO_THEME->theme_path."footer.inc");
  219.  
  220. $next_month = $month+1;
  221. $datepicker->print_date_picker('date_picker1', '',$month.'/'.$day.'/'.$year, 'date_picker1_container', 'date_picker');
  222. $datepicker->print_date_picker('date_picker2', '',$next_month.'/'.$day.'/'.$year, 'date_picker2_container', 'date_picker');
  223.  
  224. }else
  225. {
  226.     echo "\n<script type=\"text/javascript\">\nwindow.print();\n</script>\n";
  227.     require($GO_THEME->theme_path."simple_footer.inc");
  228. }
  229. ?>
  230.