home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / calendar / calendar.php < prev    next >
PHP Script  |  2004-03-08  |  7KB  |  244 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. require("../../Group-Office.php");
  14.  
  15. $GO_SECURITY->authenticate();
  16. $GO_MODULES->authenticate('calendar');
  17. require($GO_LANGUAGE->get_language_file('calendar'));
  18.  
  19. require($GO_CONFIG->class_path.'calendar.class.inc');
  20. $cal = new calendar();
  21.  
  22. require($GO_CONFIG->class_path.'cal_holidays.class.inc');
  23. $holidays = new holidays($GO_LANGUAGE);
  24.  
  25. $regions = $holidays->get_regions($GO_LANGUAGE->language);
  26.  
  27. $region = isset($_REQUEST['region']) ? $_REQUEST['region'] : '';
  28. $date = isset($_REQUEST['date']) ? $_REQUEST['date'] : getdate();
  29. $year = isset($_POST['year']) ? $_POST['year'] : $date["year"];
  30. $month = isset($_POST['month']) ? $_POST['month'] : $date["mon"];
  31. $day = isset($_POST['day']) ? $_POST['day'] : $date["mday"];
  32. $holiday_id = isset($_REQUEST['holiday_id']) ? $_REQUEST['holiday_id'] : 0;
  33.  
  34.  
  35. $task = isset($_POST['task']) ? $_POST['task'] : '';
  36. $return_to = isset($_REQUEST['return_to']) ? $_REQUEST['return_to'] : $_SERVER['HTTP_REFERER'];
  37.  
  38. $calendar_id = isset($_REQUEST['calendar_id']) ? $_REQUEST['calendar_id'] : 0;
  39.  
  40. $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");
  41.  
  42. switch($task)
  43. {
  44.  
  45.     case 'save':
  46.  
  47.         $name = trim($_POST['name']);
  48.         if ($name != "")
  49.         {
  50.             if (validate_input($name))
  51.             {
  52.                 if ($calendar_id > 0)
  53.                 {
  54.                     $existing_calendar = $cal->get_calendar_by_name($name);
  55.  
  56.                     if ($existing_calendar && $existing_calendar['id'] != $calendar_id)
  57.                     {
  58.                         $feedback = "<p class=\"Error\">".$sc_calendar_exists."</p>";
  59.  
  60.                     }else
  61.                     {
  62.                         $cal->update_calendar($calendar_id, $name, $_POST['calendar_start_hour'], $_POST['calendar_end_hour']);
  63.                         if ($_POST['close'] == 'true')
  64.                         {
  65.                             header('Location: '.$return_to);
  66.                             exit();
  67.                         }
  68.                     }
  69.                 }else
  70.                 {
  71.                     if ($cal->get_calendar_by_name($name))
  72.                     {
  73.                         $feedback = "<p class=\"Error\">".$sc_calendar_exists."</p>";
  74.                     }else
  75.                     {
  76.                         if ($calendar_id = $cal->add_calendar($GO_SECURITY->user_id, $name, $_POST['calendar_start_hour'], $_POST['calendar_end_hour']))
  77.                         {
  78.                             if ($_POST['close'] == 'true')
  79.                             {
  80.                                 header('Location: '.$return_to);
  81.                                 exit();
  82.                             }
  83.                         }else
  84.                         {
  85.                             $feedback = "<p class=\"Error\">".$strSaveError."</p>";
  86.                         }
  87.                     }
  88.                 }
  89.             }else
  90.             {
  91.                 $feedback = "<p class=\"Error\">".$invalid_input.": \\ / & ? </p>";
  92.             }
  93.         }else
  94.         {
  95.             $feedback = "<p class=\"Error\">".$error_missing_field."</p>";
  96.         }
  97.     break;
  98.  
  99.     case 'delete_holiday':
  100.         $holidays->delete_holiday($holiday_id);
  101.         $task = "";
  102.     break;
  103.  
  104.     case 'delete_holidays':
  105.         $holidays->delete_holidays($GO_SECURITY->user_id, $calendar_id, $year, $region);
  106.         $task = "";
  107.     break;
  108.  
  109.     case 'apply_holidays':
  110.         $holidays->add_holidays($GO_SECURITY->user_id, $calendar_id, $year, $region);
  111.         $task = "";
  112.     break;
  113.  
  114.     case 'save_holiday':
  115.         if($name != '')
  116.             {
  117.                 $date = date_to_unixtime($date);;
  118.                 if($holiday_id > 0)
  119.                     $holidays->update_holiday($holiday_id, $date, $name);
  120.                 else
  121.                     $holidays->add_holiday($GO_SECURITY->user_id, $calendar_id, $region, $date, $name);
  122.                 $task = "";
  123.             }else
  124.             {
  125.                 $feedback = '<p class="Error">'.$error_missing_field.'</p>';
  126.                 $task = "edit_holiday";
  127.             }
  128.     break;
  129. }
  130.  
  131. if ($calendar_id > 0)
  132. {
  133.     $calendar = $cal->get_calendar($calendar_id);
  134.     $title = $calendar['name'];
  135. }else
  136. {
  137.     $calendar['start_hour'] = isset($_POST['calendar_start_hour']) ? $_POST['calendar_start_hour'] : '00';
  138.     $calendar['end_hour'] = isset($_POST['calendar_end_hour']) ? $_POST['calendar_end_hour'] : '23';
  139.     $calendar['name'] = isset($_POST['name']) ? $_POST['name'] : '';
  140.     $title = $sc_new_calendar;
  141. }
  142.  
  143. $tabtable = new tabtable('calendar', $title, '400', '400', '120', '', true);
  144. if ($calendar_id > 0)
  145. {
  146.     $tabtable->add_tab('scheduler.inc', $sc_calendars);
  147.     $tabtable->add_tab('holidays', $sc_holidays);
  148.     $tabtable->add_tab('read_permissions', $strReadRights);
  149.     $tabtable->add_tab('write_permissions', $strWriteRights);
  150. }
  151.  
  152.  
  153. if ($tabtable->get_active_tab_id() == 'holidays')
  154. {
  155.     $datepicker = new date_picker();
  156.     $GO_HEADER['head'] = $datepicker->get_header();
  157. }
  158. require($GO_THEME->theme_path.'header.inc');
  159.  
  160. echo '<form name="event" method="post" action="'.$_SERVER['PHP_SELF'].'">';
  161. echo '<input type="hidden" name="calendar_id" value="'.$calendar_id.'" />';
  162. echo '<input type="hidden" name="task" value="" />';
  163. echo '<input type="hidden" name="close" value="false" />';
  164. echo '<input type="hidden" name="return_to" value="'.$return_to.'" />';
  165.  
  166. $tabtable->print_head();
  167. switch($tabtable->get_active_tab_id())
  168. {
  169.  
  170.     case 'read_permissions':
  171.         $read_only = ($calendar['user_id'] == $GO_SECURITY->user_id) ? false : true;
  172.         print_acl($calendar['acl_read'], $read_only);
  173.         echo '<br /><br />';
  174.         $button = new button($cmdClose,"javascript:document.location='".$return_to."'");
  175.     break;
  176.  
  177.     case 'write_permissions':
  178.         $read_only = ($calendar['user_id'] == $GO_SECURITY->user_id) ? false : true;
  179.         print_acl($calendar['acl_write'], $read_only);
  180.         echo '<br /><br />';
  181.         $button = new button($cmdClose,"javascript:document.location='".$return_to."'");
  182.     break;
  183.  
  184.     case 'holidays':
  185.         require('holidays.inc');
  186.     break;
  187.  
  188.     default:
  189.     ?>
  190.     <table border="0" cellpadding="5" cellspacing="0">
  191.     <?php
  192.     if (isset($feedback))
  193.     {
  194.         echo '<tr><td colspan="2">'.$feedback.'</td></tr>';
  195.     }
  196.     ?>
  197.     <tr>
  198.         <td>
  199.         <?php echo $strName; ?>:
  200.         </td>
  201.         <td>
  202.         <input type="text" class="textbox" name="name" maxlength="100" size="50" value="<?php echo $calendar['name']; ?>" />
  203.         </td>
  204.     </tr>
  205.     <tr>
  206.         <td>
  207.         <?php echo $sc_show_hours; ?>:
  208.         </td>
  209.         <td>
  210.         <?php
  211.         $dropbox = new dropbox();
  212.         $dropbox->add_arrays($hours, $hours);
  213.         $dropbox->print_dropbox('calendar_start_hour', $calendar['start_hour']);
  214.         ?>
  215.          <?php echo $sc_to; ?> 
  216.         <?php
  217.  
  218.         $dropbox = new dropbox();
  219.         $dropbox->add_arrays($hours, $hours);
  220.         $dropbox->print_dropbox('calendar_end_hour', $calendar['end_hour']);
  221.         ?>
  222.         </td>
  223.     </tr>
  224.     <tr>
  225.         <td colspan="2">
  226.             <?php
  227.             $button = new button($cmdOk,"javascript:document.forms[0].close.value='true';document.forms[0].task.value='save';document.forms[0].submit()");
  228.             echo '  ';
  229.             $button = new button($cmdApply,"javascript:document.forms[0].task.value='save';document.forms[0].submit()");
  230.             echo '  ';
  231.             $button = new button($cmdClose,"javascript:document.location='".$return_to."'");
  232.             ?>
  233.         </td>
  234.     </tr>
  235.     </table>
  236.  
  237.     <?php
  238.     break;
  239. }
  240. $tabtable->print_foot();
  241. echo '</form>';
  242. require($GO_THEME->theme_path.'footer.inc');
  243. ?>
  244.