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

  1. <?php
  2. /*
  3. Copyright Georg Lorenz
  4. Author: Georg Lorenz <georg@lonux.de>
  5. Version: 1.0 Release date: 29 January 2004
  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. $min_year = 1970;
  14. $max_year = 2037;
  15. $date_format = $_SESSION['GO_SESSION']['date_format'];
  16. $current_date = getdate();
  17. $current_year = $current_date["year"];
  18.  
  19. for($i=-2;$i<3;$i++)
  20. {
  21.     if($i==0)
  22.         $years[] = $year;
  23.     elseif(($year + $i) >= $min_year && ($year + $i) <= $max_year)
  24.         $years[] = $year + $i;
  25. }
  26.  
  27. if(!in_array($current_year, $years))
  28.     array_unshift($years, $current_year);
  29.  
  30. $calendar_id = (isset($calendar_id) && $calendar_id > 0) ? $calendar_id : $cal->get_default_calendar($GO_SECURITY->user_id);
  31. ?>
  32.  
  33. <table border="0" cellpadding="10">
  34. <tr>
  35.     <td>
  36.     <?php
  37.  
  38.     if(count($regions) == 0)
  39.     {
  40.         echo '<tr><td>'.$sc_holidays_no_file_prefix.$GO_LANGUAGE->language.$sc_holidays_no_file_suffix.'</td></tr>';
  41.         echo '<tr><td>';
  42.         $button = new button($cmdBack, "javascript:document.location='".$return_to."'");
  43.     }else
  44.     {
  45.         switch ($task)
  46.         {
  47.             case 'edit_holiday':
  48.                 ?>
  49.                 <input type="hidden" name="holiday_id" value="<?php echo $holiday_id; ?>" />
  50.                 <input type="hidden" name="year" value="<?php echo $year; ?>" />
  51.                 <input type="hidden" name="region" value="<?php echo $region; ?>" />
  52.                 <?php
  53.                 if ($holiday_id > 0)
  54.                 {
  55.                     if($holidays->get_holiday_by_id($holiday_id))
  56.                     {
  57.                         $date = date($date_format, $holidays->f("date"));
  58.                         $name = $holidays->f("name");
  59.                     }
  60.                 // if $date contains array values obtained by function getdate() -> not compatible with date_picker
  61.                 // then redefine the $date variable to be compatible with date_picker control
  62.                 }elseif(is_array($date))
  63.                 {
  64.                     $date = date($date_format);
  65.                 }
  66.  
  67.                 if (isset($feedback)) echo $feedback;
  68.                 ?>
  69.                 <table border="0">
  70.                 <tr>
  71.                     <td>
  72.                     <table border="0">
  73.                     <tr>
  74.                         <?php
  75.                         echo '<td>'.$strDate.':</td><td>';
  76.                         $datepicker->print_date_picker('date', $date_format, $date);
  77.                         echo '</td>';
  78.                         ?>
  79.                     </tr>
  80.                     <tr>
  81.                         <td><?php echo $strName; ?>:</td>
  82.                         <td><input type="text" class="textbox" name="name" value="<?php if (isset($name)) echo $name; ?>" style="width: 300px;" /></td>
  83.                     </tr>
  84.                     <tr>
  85.                         <td colspan="2">
  86.                         <?php
  87.                         $button = new button($cmdOk, 'javascript:save_holiday();');
  88.                         echo '  ';
  89.                         $button = new button($cmdCancel, 'javascript:cancel_holidays();');
  90.                         ?>
  91.                         </td>
  92.                     </tr>
  93.                     </table>
  94.                     </td>
  95.                 </tr>
  96.                 </table>
  97.                 <?php
  98.             break;
  99.  
  100.             case 'generate_holidays':
  101.                 $count = $holidays->get_holidays($GO_SECURITY->user_id, $calendar_id, $year);
  102.                 $holidays->generate_holidays($region, $year);
  103.                 ?>
  104.                 <input type="hidden" name="year" value="<?php echo $year ?>" />
  105.                 <input type="hidden" name="region" value="<?php echo $region ?>" />
  106.                 <br /><br /><table border="0">
  107.                 <tr>
  108.                     <td>
  109.                     <?php
  110.                     if (isset($feedback)) echo $feedback;
  111.                     echo $sc_holidays_text2;
  112.  
  113.                     if(is_array($holidays->holidays))
  114.                     {
  115.                         echo '<br /><br /><table border="0"><tr><td><h3>'.$strDate.'</h3></td><td><h3>'.$strName.'</h3></td><td></td><td></td></tr>';
  116.                         foreach($holidays->holidays as $index => $value)
  117.                         {
  118.                             echo '<tr><td width="40%">'.date($date_format, $index).'</td><td>'.$value.'</td></tr>';
  119.                         }
  120.                         echo '</table><br />';
  121.                         echo '  ';
  122.                         $button = new button($cmdApply, 'javascript:apply_holidays('.$count.');');
  123.                         echo '  ';
  124.                         $button = new button($cmdCancel, 'javascript:cancel_holidays();');
  125.                     }
  126.                     ?>
  127.                     </td>
  128.                 </tr>
  129.                 </table>
  130.                 <?php
  131.             break;
  132.  
  133.             default:
  134.                 ?>
  135.                 <input type="hidden" name="year" />
  136.                 <input type="hidden" name="holiday_id" />
  137.                 <input type="hidden" name="region" value="<?php echo $region ?>"/>
  138.                 <a class="normal" href="javascript:edit_holiday(0);"><?php echo $cmdAdd; ?></a>
  139.                 <br /><br />
  140.                 <table border="0" cellpadding="4">
  141.                 <tr>
  142.                     <td>
  143.                     <?php
  144.                     $holidays->get_holidays($GO_SECURITY->user_id, $calendar_id, $year);
  145.  
  146.                     if ($holidays->num_rows() > 0)
  147.                     {
  148.                         $output_lines = '<br /><table border="0"><tr><td><h3>'.$strDate.'</h3></td><td><h3>'.$strName.'</h3></td><td></td><td></td></tr>';
  149.                         while($holidays->next_record())
  150.                         {
  151.                             $output_lines .= '<tr><td width="30%">'.date($date_format, $holidays->f('date')).'</td><td width="60%">'.$holidays->f('name').'</td>';
  152.                             $output_lines .= '<td><a href=\'javascript:edit_holiday('.$holidays->f('id').')\' title="'.$strEdit.' \''.$holidays->f('name').'\'"><img src="'.$GO_THEME->images['edit'].'" border="0" /></a></td>';
  153.                             $output_lines .= '<td><a href=\'javascript:delete_holiday('.$holidays->f('id').', "'.$holidays->f('name').'")\' title="'.$strDeleteItem.' \''.$holidays->f('name').'\'"><img src="'.$GO_THEME->images['delete'].'" border="0" /></a></td></tr>';
  154.                         }
  155.                     }else
  156.                     {
  157.                         $output_lines = '<br /><br /><table border="0"><tr><td>'.$strNoHolidays.'</td></tr></table><br /><table border="0">';
  158.                     }
  159.  
  160.                     $region = !empty($region) ? $region : $holidays->get_region($GO_SECURITY->user_id, $calendar_id);
  161.  
  162.                     if (isset($feedback)) echo $feedback;
  163.                     echo $sc_holidays_text1;
  164.                     echo '<br /><br /><table border="0">';
  165.                     echo '<tr><td>'.$strLocalization.':</td><td>';
  166.                     //if(count($regions) > 1)
  167.                     //{
  168.                         $dropbox = new dropbox();
  169.                         $dropbox->add_arrays($regions, $regions);
  170.                         $dropbox->print_dropbox('region',$region,'onchange="javascript:document.forms[0].submit()"');
  171.                     /*}else
  172.                     {
  173.                         echo $region;
  174.                     }*/
  175.                     echo '</td></tr>';
  176.                     echo '<tr><td>'.$strYear.':</td><td>';
  177.                     $dropbox = new dropbox();
  178.                     $dropbox->add_arrays($years, $years);
  179.                     $dropbox->print_dropbox('year',$year,'onchange="javascript:document.forms[0].submit()"');
  180.                     echo '</td></tr></table>';
  181.                     echo $output_lines;
  182.                     echo '</table><br />';
  183.  
  184.                     $button = new button($cmdGenerate, 'javascript:generate_holidays('.$year.');');
  185.                     if($holidays->num_rows() > 0)
  186.                     {
  187.                         echo '  ';
  188.                         $button = new button($cmdDelete, 'javascript:delete_holidays('.$year.');');
  189.                     }
  190.                     echo '  ';
  191.                     $button = new button($cmdClose,"javascript:document.location='".$return_to."'");
  192.                     ?>
  193.                     </td>
  194.                 </tr>
  195.                 </table>
  196.  
  197.                 <?php
  198.             break;
  199.         }
  200.     }
  201.     ?>
  202.     </td>
  203. </tr>
  204. </table>
  205.  
  206. <script type="text/javascript">
  207. function delete_holiday(holiday_id, holiday_name)
  208. {
  209.     if (confirm("<?php echo $strDeletePrefix; ?>'"+holiday_name+"'<?php echo $strDeleteSuffix; ?>"))
  210.     {
  211.         document.forms[0].task.value='delete_holiday';
  212.         document.forms[0].holiday_id.value=holiday_id;
  213.         document.forms[0].submit();
  214.     }
  215. }
  216.  
  217. function delete_holidays(year)
  218. {
  219.     if (confirm("<?php echo $strDeleteHolidaysPrefix; ?>"+year+"<?php echo $strDeleteHolidaysSuffix; ?>"))
  220.     {
  221.         document.forms[0].task.value='delete_holidays';
  222.         document.forms[0].year.value=year;
  223.         document.forms[0].submit();
  224.     }
  225. }
  226.  
  227. function edit_holiday(id)
  228. {
  229.     document.forms[0].task.value='edit_holiday';
  230.     document.forms[0].holiday_id.value=id;
  231.     document.forms[0].submit();
  232. }
  233.  
  234. function cancel_holidays()
  235. {
  236.     document.forms[0].task.value='';
  237.     document.forms[0].submit();
  238. }
  239.  
  240. function save_holiday()
  241. {
  242.     document.forms[0].task.value='save_holiday';
  243.     document.forms[0].submit();
  244. }
  245.  
  246. function generate_holidays(year)
  247. {
  248.     document.forms[0].task.value='generate_holidays';
  249.     document.forms[0].year.value=year;
  250.     document.forms[0].submit();
  251. }
  252.  
  253. function apply_holidays(holidays_count)
  254. {
  255.     var apply=true;
  256.     if (holidays_count > 0)
  257.     {
  258.         if (!confirm("<?php echo $strReplaceHolidays; ?>"))
  259.         {
  260.             apply=false;
  261.         }
  262.     }
  263.     if (apply)
  264.     {
  265.         document.forms[0].task.value='apply_holidays';
  266.         document.forms[0].submit();
  267.     }
  268. }
  269. </script>
  270.