home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / calendar / event.php < prev    next >
PHP Script  |  2004-03-08  |  48KB  |  1,344 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. //get the local times
  16. $local_time = get_time();
  17. $year = isset($_REQUEST['year']) ? $_REQUEST['year'] : date("Y", $local_time);
  18. $month = isset($_REQUEST['month']) ? $_REQUEST['month'] : date("m", $local_time);
  19. $day = isset($_REQUEST['day']) ? $_REQUEST['day'] : date("j", $local_time);
  20. $hour = isset($_REQUEST['hour']) ? $_REQUEST['hour'] : date("H", $local_time);
  21. $min = isset($_REQUEST['min']) ? $_REQUEST['min'] : date("i", $local_time);
  22.  
  23. $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", "24");
  24. $mins = array("00","05","10","15","20","25","30","35","40","45","50","55");
  25. for ($i=1;$i<32;$i++)
  26. {
  27.     $num_days[] = $i;
  28. }
  29.  
  30. for ($i=1;$i<13;$i++)
  31. {
  32.     $num_months[] = $i;
  33. }
  34.  
  35. $years[0] = $year-4;
  36. $years[1] = $year-3;
  37. $years[2] = $year-2;
  38. $years[3] = $year-1;
  39. $years[4] = $year;
  40. $years[5] = $year+1;
  41. $years[6] = $year+2;
  42. $years[7] = $year+3;
  43. $years[8] = $year+4;
  44.  
  45.  
  46. $GO_SECURITY->authenticate();
  47. $GO_MODULES->authenticate('calendar');
  48. require($GO_LANGUAGE->get_language_file('calendar'));
  49.  
  50. require($GO_CONFIG->class_path.'calendar.class.inc');
  51. $cal = new calendar();
  52.  
  53. $task = isset($_POST['task']) ? $_POST['task'] : '';
  54. $return_to = isset($_REQUEST['return_to']) ? $_REQUEST['return_to'] : $_SERVER['HTTP_REFERER'];
  55.  
  56. $calendar_id = isset($_REQUEST['calendar_id']) ? $_REQUEST['calendar_id'] : $cal->get_default_calendar($GO_SECURITY->user_id);
  57. $event_id = isset($_REQUEST['event_id']) ? $_REQUEST['event_id'] : 0;
  58.  
  59. if ($task == 'save_event')
  60. {
  61.     $name = trim($_POST['name']);
  62.     if ($name == '')
  63.     {
  64.         $feedback = '<p class="Error">'.$error_missing_field.'</p>';
  65.     }elseif(!isset($_POST['calendars']) || count($_POST['calendars']) == 0)
  66.     {
  67.         $feedback = '<p class="Error">'.$sc_select_calendar_please.'</p>';
  68.     }else
  69.     {
  70.         $repeat_forever = isset($_POST['repeat_forever']) ? '1' : '0';
  71.         $repeat_every = isset($_POST['repeat_every']) ? $_POST['repeat_every'] : '0';
  72.         $month_time = isset($_POST['month_time']) ? $_POST['month_time'] : '';
  73.  
  74.         //Times given by users are in thier timezone.
  75.         //convert all times to GMT timestamps in format 0000-00-00 00:00
  76.  
  77.         //don't use times and timezones with all day events
  78.         $repeat_end_date = isset($_POST['repeat_end_date']) ? $_POST['repeat_end_date'] : '0-0-0';
  79.         $end_date_array = explode('-',$_POST['end_date']);
  80.         $start_date_array = explode('-',$_POST['start_date']);
  81.         $repeat_end_date_array = explode('-',$repeat_end_date);
  82.         $end_year = $end_date_array[2];
  83.         $start_year = $start_date_array[2];
  84.  
  85.         $repeat_end_year = $repeat_end_date_array[2];
  86.  
  87.         if ($_SESSION['GO_SESSION']['date_format'] == "m-d-Y")
  88.         {
  89.             $start_month = $start_date_array[0];
  90.             $start_day = $start_date_array[1];
  91.             $end_month = $end_date_array[0];
  92.             $end_day = $end_date_array[1];
  93.             $repeat_end_month = $repeat_end_date_array[0];
  94.             $repeat_end_day = $repeat_end_date_array[1];
  95.         }else
  96.         {
  97.             $start_month = $start_date_array[1];
  98.             $start_day = $start_date_array[0];
  99.             $end_month = $end_date_array[1];
  100.             $end_day = $end_date_array[0];
  101.             $repeat_end_month = $repeat_end_date_array[1];
  102.             $repeat_end_day = $repeat_end_date_array[0];
  103.         }
  104.  
  105.         if (isset($_POST['all_day_event']))
  106.         {
  107.             $all_day_event = '1';
  108.             $start_hour = '0';
  109.             $start_min = '0';
  110.             $end_hour = '0';
  111.             $end_min = '0';
  112.  
  113.             $start_time = mktime($start_hour, $start_min, 0, $start_month, $start_day, $start_year);
  114.             $end_time = mktime($end_hour, $end_min, 0, $end_month, $end_day, $end_year);
  115.         }else
  116.         {
  117.             $all_day_event = '0';
  118.             $start_min = $_POST['start_min'];
  119.             $start_hour = $_POST['start_hour'];
  120.             $end_hour = $_POST['end_hour'];
  121.             $end_min = $_POST['end_min'];
  122.  
  123.             //substract timezone offset
  124.             $start_time = mktime($start_hour, $start_min, 0, $start_month, $start_day, $start_year)-($_SESSION['GO_SESSION']['timezone']*3600);
  125.             $end_time = mktime($end_hour, $end_min, 0, $end_month, $end_day, $end_year)-($_SESSION['GO_SESSION']['timezone']*3600);
  126.         }
  127.  
  128.         if ($_POST['repeat_type'] != REPEAT_NONE)
  129.         {
  130.             $repeat_end_time = isset($_POST['repeat_forever']) ? '0' : mktime(0, 0, 0, $repeat_end_month, $repeat_end_day, $repeat_end_year);
  131.         }else
  132.         {
  133.             $repeat_end_time=0;
  134.         }
  135.  
  136.         $shift_day=0;
  137.         //shift the selected weekdays to GMT time
  138.         if (!isset($_POST['all_day_event']))
  139.         {
  140.             $shifted_start_hour = $start_hour - $_SESSION['GO_SESSION']['timezone'];
  141.             if ($shifted_start_hour > 23)
  142.             {
  143.                 $shifted_start_hour = $shifted_start_hour - 24;
  144.                 $shift_day = 1;
  145.             }elseif($shifted_start_hour < 0)
  146.             {
  147.                 $shifted_start_hour = 24 + $shifted_start_hour;
  148.                 $shift_day = -1;
  149.             }
  150.         }
  151.  
  152.         switch($shift_day)
  153.         {
  154.             case 0:
  155.                 $mon = isset($_POST['repeat_days_1']) ? '1' : '0';
  156.                 $tue = isset($_POST['repeat_days_2']) ? '1' : '0';
  157.                 $wed = isset($_POST['repeat_days_3']) ? '1' : '0';
  158.                 $thu = isset($_POST['repeat_days_4']) ? '1' : '0';
  159.                 $fri = isset($_POST['repeat_days_5']) ? '1' : '0';
  160.                 $sat = isset($_POST['repeat_days_6']) ? '1' : '0';
  161.                 $sun = isset($_POST['repeat_days_0']) ? '1' : '0';
  162.             break;
  163.  
  164.             case 1:
  165.                 $mon = isset($_POST['repeat_days_0']) ? '1' : '0';
  166.                 $tue = isset($_POST['repeat_days_1']) ? '1' : '0';
  167.                 $wed = isset($_POST['repeat_days_2']) ? '1' : '0';
  168.                 $thu = isset($_POST['repeat_days_3']) ? '1' : '0';
  169.                 $fri = isset($_POST['repeat_days_4']) ? '1' : '0';
  170.                 $sat = isset($_POST['repeat_days_5']) ? '1' : '0';
  171.                 $sun = isset($_POST['repeat_days_6']) ? '1' : '0';
  172.  
  173.             break;
  174.  
  175.             case -1:
  176.                 $mon = isset($_POST['repeat_days_2']) ? '1' : '0';
  177.                 $tue = isset($_POST['repeat_days_3']) ? '1' : '0';
  178.                 $wed = isset($_POST['repeat_days_4']) ? '1' : '0';
  179.                 $thu = isset($_POST['repeat_days_5']) ? '1' : '0';
  180.                 $fri = isset($_POST['repeat_days_6']) ? '1' : '0';
  181.                 $sat = isset($_POST['repeat_days_0']) ? '1' : '0';
  182.                 $sun = isset($_POST['repeat_days_1']) ? '1' : '0';
  183.             break;
  184.  
  185.         }
  186.  
  187.         if ($event_id > 0)
  188.         {
  189.             if (!$cal->update_event($event_id, $GO_SECURITY->user_id, $start_time, $end_time, $all_day_event, $name, $_POST['description'], $_POST['contact_id'], $_POST['reminder'], $_POST['location'], $_POST['background'], $_POST['repeat_type'], $repeat_end_time, $month_time, $repeat_forever, $repeat_every,  $mon, $tue, $wed, $thu, $fri, $sat, $sun))
  190.             {
  191.                 $feedback = '<p class="Error">'.$strSaveError.'</p>';
  192.             }else
  193.             {
  194.                 $cal->remove_participants($event_id);
  195.             }
  196.  
  197.         }else
  198.         {
  199.             $acl_read = $GO_SECURITY->get_new_acl('Event read: '.$event_id);
  200.             $acl_write = $GO_SECURITY->get_new_acl('Event read: '.$event_id);
  201.  
  202.             if (!$acl_read || !$acl_write || !$event_id = $cal->add_event($GO_SECURITY->user_id, $start_time, $end_time, $all_day_event, $name, $_POST['description'], $_POST['contact_id'], $_POST['reminder'], $_POST['location'], $_POST['background'], $_POST['repeat_type'], $repeat_end_time, $month_time, $repeat_forever, $repeat_every, $mon, $tue, $wed, $thu, $fri, $sat, $sun, $acl_read, $acl_write))
  203.             {
  204.                 $GO_SECURITY->delete_acl($acl_read);
  205.                 $GO_SECURITY->delete_acl($acl_write);
  206.                 $feedback = '<p class="Error">'.$strSaveError.'</p>';
  207.             }else
  208.             {
  209.                 $GO_SECURITY->add_user_to_acl($GO_SECURITY->user_id, $acl_write);
  210.                 if (!isset($_POST['private']) && $calendar = $cal->get_calendar($calendar_id))
  211.                 {
  212.                     $GO_SECURITY->add_group_to_acl($GO_SECURITY->group_everyone, $acl_read);
  213.                 }
  214.             }
  215.         }
  216.         if (!isset($feedback))
  217.         {
  218.             //enter the event in all selected calendars
  219.             $cal2 = new calendar();
  220.             $cal->get_subscribed($GO_SECURITY->user_id);
  221.             while ($cal->next_record())
  222.             {
  223.                 if ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $cal->f('acl_write')))
  224.                 {
  225.                     if (in_array($cal->f('id'), $_POST['calendars']))
  226.                     {
  227.                         if (!$cal2->event_is_subscribed($event_id, $cal->f('id')))
  228.                         {
  229.                             $cal2->subscribe_event($event_id, $cal->f('id'));
  230.                         }
  231.                     }else
  232.                     {
  233.                         if ($cal2->event_is_subscribed($event_id, $cal->f('id')))
  234.                         {
  235.                             $cal2->unsubscribe_event($event_id, $cal->f('id'));
  236.                         }
  237.                     }
  238.                 }
  239.             }
  240.  
  241.             //set the reminder
  242.             if ($_POST['reminder'] > 0)
  243.             {
  244.                 $next_recurrence_time = $cal->get_next_recurrence_time($event_id);
  245.                 //echo date(DB_DATETIME_FORMAT, $next_recurrence_time);
  246.  
  247.                 $remind_time = $next_recurrence_time - $_POST['reminder'];
  248.                 $cal->insert_reminder($GO_SECURITY->user_id, $event_id, $remind_time);
  249.             }
  250.  
  251.             //send an invitation mail to all participants
  252.             $participants = cut_address($_POST['to'], $charset);
  253.  
  254.             $mail_body  = '<html><body>'.$sc_invited.'<br /><br />';
  255.             $mail_body  .= '<table border="0"><tr><td>'.$sc_title.':</td><td>'.$name.'</td></tr>';
  256.  
  257.             if ($_POST['contact_id'] > 0)
  258.             {
  259.                 $mail_body  .= '<tr><td>'.$sc_client.':</td>';
  260.                 $mail_body  .= '<td>'.show_contact($_POST['contact_id']).'</td></tr>';
  261.             }
  262.             if ($_POST['description'] != '')
  263.             {
  264.                 $mail_body  .= '<tr><td valign="top">'.$strDescription.':</td>';
  265.                 $mail_body  .='<td>'.text_to_html($_POST['description']).'</td></tr>';
  266.             }
  267.  
  268.             if ($_POST['location'] != '')
  269.             {
  270.                 $mail_body  .= '<tr><td>'.$sc_location.':</td>';
  271.                 $mail_body  .= '<td>'.text_to_html($_POST['location']).'</td></tr>';
  272.             }
  273.  
  274.             $mail_body  .= '<tr><td>'.$sc_type.':</td>';
  275.             $mail_body  .= '<td>'.$sc_types[$_POST['repeat_type']].'</td></tr>';
  276.  
  277.             //don't calculate timezone offset for all day events
  278.             $timezone_offset = isset($_POST['all_day_event']) ? 0 : ($_SESSION['GO_SESSION']['timezone']*3600);
  279.             if ($_SESSION['GO_SESSION']['timezone'] > 0)
  280.             {
  281.                 $gmt_string = '\G\M\T +'.$_SESSION['GO_SESSION']['timezone'];
  282.             }elseif($_SESSION['GO_SESSION']['timezone'] < 0)
  283.             {
  284.                 $gmt_string = '\G\M\T '.$_SESSION['GO_SESSION']['timezone'];
  285.             }else
  286.             {
  287.                 $gmt_string = '\G\M\T';
  288.             }
  289.  
  290.             if (isset($_POST['all_day_event']))
  291.             {
  292.                 $event_datetime_format = $_SESSION['GO_SESSION']['date_format'];
  293.             }else
  294.             {
  295.                 $event_datetime_format = $_SESSION['GO_SESSION']['date_format'].' '.$_SESSION['GO_SESSION']['time_format'].' '.$gmt_string;
  296.             }
  297.             $event_time_format = $_SESSION['GO_SESSION']['time_format'].' '.$gmt_string;
  298.  
  299.             switch($_POST['repeat_type'])
  300.             {
  301.                 case REPEAT_NONE:
  302.  
  303.                     $mail_body  .= '<tr><td>'.$sc_start_at.':</td><td>'.date($event_datetime_format, $start_time+($_SESSION['GO_SESSION']['timezone']*3600)).'</td></tr>';
  304.                     if ($end_time != $start_time)
  305.                     {
  306.                         $mail_body  .= '<tr><td>'.$sc_end_at.':</td><td>'.date($event_datetime_format, $end_time+($_SESSION['GO_SESSION']['timezone']*3600)).'</td></tr>';
  307.                     }
  308.                 break;
  309.  
  310.                 case REPEAT_WEEKLY:
  311.                     if(!isset($_POST['all_day_event']))
  312.                     {
  313.                         $mail_body .= '<tr><td>'.$sc_start_at.':</td><td>'.date($event_time_format, $start_time+($_SESSION['GO_SESSION']['timezone']*3600)).'</td></tr>';
  314.                         if ($end_time != $start_time)
  315.                         {
  316.                             $mail_body .= '<tr><td>'.$sc_end_at.':</td><td>'.date($event_time_format, $end_time+($_SESSION['GO_SESSION']['timezone']*3600)).'</td></tr>';
  317.                         }
  318.                     }
  319.  
  320.                     $mail_body .= '<tr><td>'.$sc_at_days.':</td><td>';
  321.  
  322.                     $local_start_hour = date('H',$start_time-$timezone_offset) + ($timezone_offset/3600);
  323.                     if ($local_start_hour > 23)
  324.                     {
  325.                         $local_start_hour = $local_start_hour - 24;
  326.                         $shift_day = 1;
  327.                     }elseif($local_start_hour < 0)
  328.                     {
  329.                         $local_start_hour = 24 + $local_start_hour;
  330.                         $shift_day = -1;
  331.                     }else
  332.                     {
  333.                         $shift_day = 0;
  334.                     }
  335.  
  336.                     $event['days'] = array();
  337.                     if (isset($_POST['repeat_days_0']))
  338.                     {
  339.                         $event['days'][] = $full_days[0+$shift_day];
  340.                     }
  341.                     if (isset($_POST['repeat_days_1']))
  342.                     {
  343.                         $event['days'][] = $full_days[1+$shift_day];
  344.                     }
  345.  
  346.                     if (isset($_POST['repeat_days_2']))
  347.                     {
  348.                         $event['days'][] = $full_days[2+$shift_day];
  349.                     }
  350.  
  351.                     if (isset($_POST['repeat_days_3']))
  352.                     {
  353.                         $event['days'][] = $full_days[3+$shift_day];
  354.                     }
  355.  
  356.                     if (isset($_POST['repeat_days_4']))
  357.                     {
  358.                         $event['days'][] = $full_days[4+$shift_day];
  359.                     }
  360.  
  361.                     if (isset($_POST['repeat_days_5']))
  362.                     {
  363.                         $event['days'][] = $full_days[5+$shift_day];
  364.                     }
  365.  
  366.                     if (isset($_POST['repeat_days_6']))
  367.                     {
  368.                         $event['days'][] = $full_days[6]+$shift_day;
  369.                     }
  370.                     $mail_body .= implode(', ', $event['days']);
  371.  
  372.                     $mail_body .= '</td></tr>';
  373.  
  374.                     $mail_body .= '<tr><td>'.$sc_cycle_end.':</td><td>';
  375.                     if ($repeat_forever == '1')
  376.                     {
  377.                         $mail_body .= $sc_noend;
  378.                     }else
  379.                     {
  380.                         $mail_body .= date($_SESSION['GO_SESSION']['date_format'], $repeat_end_time);
  381.                     }
  382.                     $mail_body .= '</td></tr>';
  383.  
  384.                 break;
  385.  
  386.                 case REPEAT_DAILY:
  387.                     if(!isset($_POST['all_day_event']))
  388.                     {
  389.                         $mail_body .= '<tr><td>'.$sc_start_at.':</td><td>'.date($event_datetime_format, $start_time+($_SESSION['GO_SESSION']['timezone']*3600)).'</td></tr>';
  390.                         $mail_body .= '<tr><td>'.$sc_end_at.':</td><td>'.date($event_datetime_format, $end_time+($_SESSION['GO_SESSION']['timezone']*3600)).'</td></tr>';
  391.                     }
  392.                     $mail_body .= '<tr><td>'.$sc_cycle_end.':</td><td>';
  393.                     if (isset($repeat_forever))
  394.                     {
  395.                         $mail_body .= $sc_noend;
  396.                     }else
  397.                     {
  398.                         $mail_body .= date($_SESSION['GO_SESSION']['date_format'], $repeat_end_time);
  399.                     }
  400.                     $mail_body .= '</td></tr>';
  401.                 break;
  402.  
  403.                 case REPEAT_MONTH_DATE:
  404.  
  405.                     if(!isset($_POST['all_day_event']))
  406.                     {
  407.                         $mail_body .= '<tr><td>'.$sc_start_at.':</td><td>'.date($event_datetime_format, $start_time+($_SESSION['GO_SESSION']['timezone']*3600)).'</td></tr>';
  408.                         if ($end_time != $start_time)
  409.                         {
  410.                             $mail_body .= '<tr><td>'.$sc_end_at.':</td><td>'.date($event_datetime_format, $end_time+($_SESSION['GO_SESSION']['timezone']*3600)).'</td></tr>';
  411.                         }
  412.                     }else
  413.                     {
  414.                         $mail_body .= '<tr><td>'.$sc_start_at.':</td><td>'.$sc_day.' '.date('d', $start_time).'</td></tr>';
  415.                         $mail_body .= '<tr><td>'.$sc_end_at.':</td><td>'.$sc_day.' '.date('d', $start_time).'</td></tr>';
  416.                     }
  417.  
  418.                     $mail_body .= '<tr><td>'.$sc_cycle_end.':</td><td>';
  419.                     if ($repeat_forever == '1')
  420.                     {
  421.                         $mail_body .= $sc_noend;
  422.                     }else
  423.                     {
  424.                         $mail_body .= date($_SESSION['GO_SESSION']['date_format'], $repeat_end_time);
  425.                     }
  426.  
  427.                 break;
  428.  
  429.                 case REPEAT_MONTH_DAY:
  430.                     if(!isset($_POST['all_day_event']))
  431.                     {
  432.                         $mail_body .= '<tr><td>'.$sc_start_at.':</td><td>'.date($event_datetime_format, $start_time+($_SESSION['GO_SESSION']['timezone']*3600)).'</td></tr>';
  433.                         if (isset($repeat_forever))
  434.                         {
  435.                             $mail_body .= '<tr><td>'.$sc_end_at.':</td><td>'.date($event_datetime_format, $end_time+($_SESSION['GO_SESSION']['timezone']*3600)).'</td></tr>';
  436.                         }
  437.                     }
  438.  
  439.                     $local_start_hour = date('H',$start_time-$timezone_offset) + ($timezone_offset/3600);
  440.                     if ($local_start_hour > 23)
  441.                     {
  442.                         $local_start_hour = $local_start_hour - 24;
  443.                         $shift_day = 1;
  444.                     }elseif($local_start_hour < 0)
  445.                     {
  446.                         $local_start_hour = 24 + $local_start_hour;
  447.                         $shift_day = -1;
  448.                     }else
  449.                     {
  450.                         $shift_day = 0;
  451.                     }
  452.  
  453.                     if (isset($_POST['repeat_days_0']))
  454.                     {
  455.                         $event['days'][] = $full_days[0+$shift_day];
  456.                     }
  457.                     if (isset($_POST['repeat_days_1']))
  458.                     {
  459.                         $event['days'][] = $full_days[1+$shift_day];
  460.                     }
  461.  
  462.                     if (isset($_POST['repeat_days_2']))
  463.                     {
  464.                         $event['days'][] = $full_days[2+$shift_day];
  465.                     }
  466.  
  467.                     if (isset($_POST['repeat_days_3']))
  468.                     {
  469.                         $event['days'][] = $full_days[3+$shift_day];
  470.                     }
  471.  
  472.                     if (isset($_POST['repeat_days_4']))
  473.                     {
  474.                         $event['days'][] = $full_days[4+$shift_day];
  475.                     }
  476.  
  477.                     if (isset($_POST['repeat_days_5']))
  478.                     {
  479.                         $event['days'][] = $full_days[5+$shift_day];
  480.                     }
  481.  
  482.                     if (isset($_POST['repeat_days_6']))
  483.                     {
  484.                         $event['days'][] = $full_days[6]+$shift_day;
  485.                     }
  486.                     $mail_body .= implode(', ', $event['days']);
  487.  
  488.                     $mail_body .= '</td></tr>';
  489.  
  490.                     $mail_body .= '<tr><td>'.$sc_cycle_end.':</td><td>';
  491.                     if ($repeat_forever == '1')
  492.                     {
  493.                         $mail_body .= $sc_noend;
  494.                     }else
  495.                     {
  496.                         $mail_body .= date($_SESSION['GO_SESSION']['date_format'], $repeat_end_time);
  497.                     }
  498.  
  499.  
  500.                 break;
  501.  
  502.                 case REPEAT_YEARLY;
  503.                     if(!isset($_POST['all_day_event']))
  504.                     {
  505.                         $mail_body .= '<tr><td>'.$sc_start_at.':</td><td>'.date($event_datetime_format, $start_time+($_SESSION['GO_SESSION']['timezone']*3600)).'</td></tr>';
  506.                         if ($end_time != $start_time)
  507.                         {
  508.                             $mail_body .= '<tr><td>'.$sc_end_at.':</td><td>'.date($event_datetime_format, $end_time+($_SESSION['GO_SESSION']['timezone']*3600)).'</td></tr>';
  509.                         }
  510.                     }else
  511.                     {
  512.                         $mail_body .= '<tr><td>'.$sc_start_at.':</td><td>'.$sc_day.' '.date('d', $start_time).'</td></tr>';
  513.                         $mail_body .= '<tr><td>'.$sc_end_at.':</td><td>'.$sc_day.' '.date('d', $start_time).'</td></tr>';
  514.                     }
  515.  
  516.                     $mail_body .= '<tr><td>'.$sc_cycle_end.':</td><td>';
  517.                     if ($repeat_forever == '1')
  518.                     {
  519.                         $mail_body .= $sc_noend;
  520.                     }else
  521.                     {
  522.                         $mail_body .= date($_SESSION['GO_SESSION']['date_format'], $repeat_end_time);
  523.                     }
  524.  
  525.                 break;
  526.             }
  527.  
  528.             $mail_body .= '</table><br /><br />'.$sc_accept_question.'<br /><br />';
  529.  
  530.             require_once($GO_CONFIG->class_path."users.class.inc");
  531.             $users = new users();
  532.             require_once($GO_CONFIG->class_path."addressbook.class.inc");
  533.             $ab = new addressbook();
  534.  
  535.             for ($i=0;$i<sizeof($participants);$i++)
  536.             {
  537.                 $id = 0;
  538.                 $user_profile = $ab->get_contact_profile_by_email($participants[$i], $GO_SECURITY->user_id);
  539.                 $id = $user_profile["source_id"];
  540.                 if (!$user_profile)
  541.                 {
  542.                     $user_profile = $users->get_profile_by_email($participants[$i]);
  543.                     $id = $user_profile["id"];
  544.                 }
  545.  
  546.                 if ($user_profile)
  547.                 {
  548.                     $middle_name = $user_profile['middle_name'] == '' ? '' : $user_profile['middle_name'].' ';
  549.                     $profile_name = $user_profile['first_name'].' '.$middle_name.$user_profile['last_name'];
  550.                 }else
  551.                 {
  552.                     $profile_name = $participants[$i];
  553.                 }
  554.  
  555.                 if ($id == 0)
  556.                 {
  557.                     $nouser_link = '<p><a href="'.$GO_CONFIG->full_url.'/index.php?return_to='.urlencode($GO_MODULES->url.'accept.php?event_id='.$event_id.'&member=false&email='.$participants[$i]).'" class="blue">'.$sc_accept.'</a> | <a href="'.$GO_CONFIG->full_url.'/index.php?return_to='.urlencode($GO_MODULES->url.'decline.php?event_id='.$event_id.'&member=false&email='.$participants[$i]).'" class="blue">'.$sc_decline.'</a></p>';
  558.                     if (sendmail($participants[$i], $_SESSION['GO_SESSION']["email"], $_SESSION['GO_SESSION']['name'], $name, $mail_body.$nouser_link,'3 (Normal)', 'text/html'))
  559.                     {
  560.                         $cal->add_participant($event_id, $participants[$i], $participants[$i]);
  561.                     }
  562.                 }else
  563.                 {
  564.                     $user_link = '<p class="cmd"><a href="'.$GO_CONFIG->full_url.'/index.php?return_to='.urlencode($GO_MODULES->url.'accept.php?event_id='.$event_id.'&member=true&email='.$participants[$i]).'" class="blue">'.$sc_accept.'</a> | <a href="'.$GO_CONFIG->full_url.'/index.php?return_to='.urlencode($GO_MODULES->url.'decline.php?event_id='.$event_id.'&member=true&email='.$participants[$i]).'" class="blue">'.$sc_decline.'</a></p>';
  565.                     if ($GO_SECURITY->user_id != $id)
  566.                     {
  567.                         if (sendmail($participants[$i], $_SESSION['GO_SESSION']["email"], $_SESSION['GO_SESSION']['name'], $name, $mail_body.$user_link,'3 (Normal)', 'text/html'))
  568.                         {
  569.                             $cal->add_participant($event_id, $profile_name, $user_profile["email"], $id);
  570.                         }
  571.                     }else
  572.                     {
  573.                         $cal->add_participant($event_id, $profile_name, $user_profile["email"], $id);
  574.                         $cal->set_event_status($event_id, '1', $user_profile["email"]);
  575.                     }
  576.                 }
  577.             }
  578.             if ($_POST['close'] == 'true')
  579.             {
  580.                 header('Location: '.$return_to);
  581.                 exit();
  582.             }else
  583.             {
  584.                 $task = '';
  585.             }
  586.         }
  587.     }
  588. }
  589.  
  590. if ($event_id > 0 && $task != 'save_event')
  591. {
  592.     //get the event
  593.     $event = $cal->get_event($event_id);
  594.  
  595.     if (!$event['write_permission'] = $GO_SECURITY->has_permission($GO_SECURITY->user_id, $event['acl_write']))
  596.     {
  597.         header('Location: '.$GO_CONFIG->host.'error_docs/403.php');
  598.         exit();
  599.     }
  600.  
  601.  
  602.     //populate an address string of the participants
  603.     $event['to'] = '';
  604.     $cal->get_participants($event_id);
  605.     while ($cal->next_record())
  606.     {
  607.         if ($event['to'] == '')
  608.         {
  609.             $event['to'] = $cal->f("email");
  610.         }else
  611.         {
  612.             $event['to'] .= ', '.$cal->f("email");
  613.         }
  614.     }
  615.  
  616.     //don't calculate timezone offset for all day events
  617.     $timezone_offset = ($event['all_day_event'] == '0') ? ($_SESSION['GO_SESSION']['timezone']*3600) : 0;
  618.  
  619.     $gmt_start_time = $event['start_time'];
  620.     $event['start_time'] += $timezone_offset;
  621.     $event['start_hour'] = date('G', $event['start_time']);
  622.     $event['start_min'] = date('i', $event['start_time']);
  623.  
  624.     $event['end_time'] += $timezone_offset;
  625.     $event['end_hour'] = date('G', $event['end_time']);
  626.     $event['end_min'] = date('i', $event['end_time']);
  627.  
  628.     $event['start_date'] = date($_SESSION['GO_SESSION']['date_format'], $event['start_time']);
  629.     $event['end_date'] = date($_SESSION['GO_SESSION']['date_format'], $event['end_time']);
  630.  
  631.     $event['repeat_end_date'] = date($_SESSION['GO_SESSION']['date_format'], $event['repeat_end_time']);
  632.  
  633.     if ($event['repeat_type'] != REPEAT_NONE)
  634.     {
  635.         if ($event['repeat_forever'] == '0')
  636.         {
  637.             $event['repeat_end_date'] = date($_SESSION['GO_SESSION']['date_format'], $event['repeat_end_time']);
  638.         }else
  639.         {
  640.             $event['repeat_end_date'] = date($_SESSION['GO_SESSION']['date_format'], $event['end_time']);
  641.         }
  642.     }else
  643.     {
  644.         $event['repeat_end_date'] = date($_SESSION['GO_SESSION']['date_format'], $event['start_time']);
  645.     }
  646.  
  647.     //to what calendars is this event subscribed?
  648.     $event['calendars'] = array();
  649.     $cal->get_event_subscribtions($event_id);
  650.     while($cal->next_record())
  651.     {
  652.         $event['calendars'][] = $cal->f('calendar_id');
  653.     }
  654.  
  655.     //shift the selected weekdays to local time
  656.     $local_start_hour = date('G', $gmt_start_time) + $_SESSION['GO_SESSION']['timezone'];
  657.     if ($local_start_hour > 23)
  658.     {
  659.         $local_start_hour = $local_start_hour - 24;
  660.         $shift_day = 1;
  661.     }elseif($local_start_hour < 0)
  662.     {
  663.         $local_start_hour = 24 + $local_start_hour;
  664.         $shift_day = -1;
  665.     }else
  666.     {
  667.         $shift_day = 0;
  668.     }
  669.  
  670.     switch($shift_day)
  671.     {
  672.         case 1:
  673.             $mon = $event['sun'] == '1' ? '1' : '0';
  674.             $tue = $event['mon'] == '1' ? '1' : '0';
  675.             $wed = $event['tue'] == '1' ? '1' : '0';
  676.             $thu = $event['wed'] == '1' ? '1' : '0';
  677.             $fri = $event['thu'] == '1' ? '1' : '0';
  678.             $sat = $event['fri'] == '1' ? '1' : '0';
  679.             $sun = $event['sat'] == '1' ? '1' : '0';
  680.         break;
  681.  
  682.         case -1:
  683.             $mon = $event['tue'] == '1' ? '1' : '0';
  684.             $tue = $event['wed'] == '1' ? '1' : '0';
  685.             $wed = $event['thu'] == '1' ? '1' : '0';
  686.             $thu = $event['fri'] == '1' ? '1' : '0';
  687.             $fri = $event['sat'] == '1' ? '1' : '0';
  688.             $sat = $event['sun'] == '1' ? '1' : '0';
  689.             $sun = $event['mon'] == '1' ? '1' : '0';
  690.         break;
  691.  
  692.     }
  693.  
  694.     if ($shift_day != 0)
  695.     {
  696.         $event['sun'] = $sun;
  697.         $event['mon'] =    $mon;
  698.         $event['tue'] =    $tue;
  699.         $event['wed'] =    $wed;
  700.         $event['thu'] =    $thu;
  701.         $event['fri'] =    $fri;
  702.         $event['sat'] =    $sat;
  703.     }
  704.  
  705.     $title = $event['name'];
  706. }else
  707. {
  708.     $title = $sc_new_app;
  709.     $requested_time=mktime($hour,0,0,$month, $day, $year);
  710.     $requested_date=date($_SESSION['GO_SESSION']['date_format'], $requested_time);
  711.     //new event declare all vars
  712.     $event['calendars'] = isset($_POST['calendars']) ? $_POST['calendars'] : array();
  713.     $event['description'] = isset($_POST['description']) ? $_POST['description'] : '';
  714.     $event['name'] = isset($_POST['name']) ? $_POST['name'] : '';
  715.     $event['to'] = isset($_POST['to']) ? $_POST['to'] : '';
  716.     $event['contact_id'] = isset($_REQUEST['contact_id']) ? $_REQUEST['contact_id'] : '';
  717.  
  718.     $event['start_date'] = isset($_POST['start_date']) ? $_POST['start_date'] : $requested_date;
  719.     $event['start_hour'] = isset($_POST['start_hour']) ? $_POST['start_hour'] : $hour;
  720.     $event['start_min'] = isset($_POST['start_min']) ? $_POST['start_min'] : '00';
  721.  
  722.     $event['end_date'] = isset($_POST['end_date']) ? $_POST['end_date'] : $requested_date;
  723.     $event['end_hour'] = isset($_POST['end_hour']) ? $_POST['end_hour'] : $hour;
  724.     $event['end_min'] = isset($_POST['end_min']) ? $_POST['end_min'] : '30';
  725.  
  726.     $event['repeat_end_date'] = isset($_POST['repeat_end_date']) ? $_POST['repeat_end_date'] : $requested_date;
  727.  
  728.     $event['repeat_type'] = isset($_POST['repeat_type']) ? $_POST['repeat_type'] : REPEAT_NONE;
  729.     $event['all_day_event'] = isset($_POST['all_day_event']) ? $_POST['all_day_event'] :'0';
  730.     $event['repeat_forever'] = isset($_POST['repeat_forever']) ? $_POST['repeat_forever'] :'0';
  731.     $event['repeat_every'] = isset($_POST['repeat_every']) ? $_POST['repeat_every'] :'0';
  732.     $event['month_time'] = isset($_POST['month_time']) ? $_POST['month_time'] : '0';
  733.  
  734.     $event['sun'] = isset($_POST['repeat_days_0']) ? true : false;
  735.     $event['mon'] = isset($_POST['repeat_days_1']) ? true : false;
  736.     $event['tue'] = isset($_POST['repeat_days_2']) ? true : false;
  737.     $event['wed'] = isset($_POST['repeat_days_3']) ? true : false;
  738.     $event['thu'] = isset($_POST['repeat_days_4']) ? true : false;
  739.     $event['fri'] = isset($_POST['repeat_days_5']) ? true : false;
  740.     $event['sat'] = isset($_POST['repeat_days_6']) ? true : false;
  741.     $event['reminder'] = isset($_POST['reminder']) ? $_POST['reminder'] :'0';
  742.     $event['background'] = isset($_POST['background']) ? $_POST['background'] :'FFFFCC';
  743.     $event['location'] = isset($_POST['location']) ? $_POST['location'] :'';
  744. }
  745.  
  746. $datepicker = new date_picker();
  747. $GO_HEADER['head'] = $datepicker->get_header();
  748. require($GO_THEME->theme_path.'header.inc');
  749.  
  750. echo '<form name="event_form" method="post" action="'.$_SERVER['PHP_SELF'].'">';
  751. echo '<input type="hidden" name="calendar_id" value="'.$calendar_id.'" />';
  752. echo '<input type="hidden" name="event_id" value="'.$event_id.'" />';
  753. echo '<input type="hidden" name="task" value="" />';
  754. echo '<input type="hidden" name="close" value="false" />';
  755. echo '<input type="hidden" name="return_to" value="'.$return_to.'" />';
  756.  
  757. //address_string used by the addressbok selector
  758. echo '<input type="hidden" name="address_string" value="" />';
  759.  
  760. $tabtable = new tabtable('event_table', $title, '600', '400', '120', '', true);
  761. if ($event_id > 0)
  762. {
  763.     $tabtable->add_tab('properties', $strProperties);
  764.     if ($cal->get_participants($event_id))
  765.     {
  766.         $tabtable->add_tab('participants', $sc_participants);
  767.     }
  768.     $tabtable->add_tab('read_permissions', $strReadRights);
  769.     $tabtable->add_tab('write_permissions', $strWriteRights);
  770. }
  771. $tabtable->print_head();
  772. echo '<br />';
  773. switch($tabtable->get_active_tab_id())
  774. {
  775.     case 'participants':
  776.         echo '<input type="hidden" name="status" />';
  777.         echo '<table border="0">';
  778.         echo '<tr><td><h3>'.$strName.'</td>';
  779.         echo '<td><h3>'.$strEmail.'</td>';
  780.         echo '<td><h3>'.$sc_status.'</td></tr>';
  781.  
  782.         while ($cal->next_record())
  783.         {
  784.             echo '<tr><td nowrap>'.show_profile_by_email($cal->f('email'), $cal->f('name')).' </td>';
  785.             echo '<td nowrap>'.mail_to($cal->f('email')).' </td><td>';
  786.             switch($cal->f('status'))
  787.             {
  788.                 case '0':
  789.                     echo $sc_not_responded;
  790.                 break;
  791.  
  792.                 case '1':
  793.                     echo $sc_accepted;
  794.                 break;
  795.  
  796.                 case '2':
  797.                     echo $sc_declined;
  798.                 break;
  799.  
  800.             }
  801.             echo '</td></tr>';
  802.         }
  803.         echo '</table>';
  804.         $status = $cal->get_event_status($event_id, $_SESSION['GO_SESSION']['email']);
  805.         if($status !== false)
  806.         {
  807.             echo '<br />';
  808.             switch ($status)
  809.             {
  810.                 case '0';
  811.                     $button = new button($sc_accept, "javascript:document.location='".$_SERVER['REQUEST_URI']."&status=1'");
  812.                     echo '  ';
  813.                     $button = new button($sc_decline, "javascript:document.location='".$_SERVER['REQUEST_URI']."&status=2'");
  814.                 break;
  815.  
  816.                 case '1';
  817.                     $button = new button($sc_decline, "javascript:document.location='".$_SERVER['REQUEST_URI']."&status=2'");
  818.                 break;
  819.  
  820.                 case '2';
  821.                     $button = new button($sc_accept, "javascript:document.location='".$_SERVER['REQUEST_URI']."&status=1'");
  822.                 break;
  823.             }
  824.         }
  825.         echo '<br /><br />';
  826.         $button = new button($cmdCancel,"javascript:document.location='".$return_to."'");
  827.     break;
  828.     case 'read_permissions':
  829.         $read_only = ($event['user_id'] == $GO_SECURITY->user_id) ? false : true;
  830.         print_acl($event['acl_read'], $read_only);
  831.         echo '<br /><br />';
  832.         $button = new button($cmdCancel,"javascript:document.location='".$return_to."'");
  833.     break;
  834.  
  835.     case 'write_permissions':
  836.         $read_only = ($event['user_id'] == $GO_SECURITY->user_id) ? false : true;
  837.         print_acl($event['acl_write'], $read_only);
  838.         echo '<br /><br />';
  839.         $button = new button($cmdCancel,"javascript:document.location='".$return_to."'");
  840.     break;
  841.  
  842.     default:
  843.  
  844.         echo '<table border="0" cellpadding="2" cellspacing="0">';
  845.         if (isset($feedback))
  846.             echo '<tr><td colspan="2" class="Error">'.$feedback.'</td></tr>';
  847.         echo '<tr><td>'.$strName.': </td><td><input type="text" class="textbox" maxlength="50" name="name" style="width: 300px;" value="'.$event['name'].'" /></td></tr>';
  848.         echo '<tr><td>';
  849.         $contacts_module = $GO_MODULES->get_module('addressbook');
  850.         if (!$contacts_module || !($GO_SECURITY->has_permission($GO_SECURITY->user_id, $contacts_module['acl_read']) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $contacts_module['acl_write'])))
  851.         {
  852.             $contacts_module = false;
  853.         }
  854.         if ($contacts_module)
  855.         {
  856.             echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td><a class=\"normal\" href=\"javascript:open_addressbook('to',document.event_form.to.value)\"><img src=\"".$GO_THEME->images['addressbook_small']."\" width=\"16\" height=\"16\" border=\"0\" /></a> </td><td><a class=\"normal\" href=\"javascript:open_addressbook('to',document.event_form.to.value)\">$sc_participants</a>: </td></tr></table></td>";
  857.         }else
  858.         {
  859.             echo $sc_participants.": ";
  860.         }
  861.         echo '<td nowrap><input type="text" class="textbox" name="to" value="'.$event['to'].'" style="width: 300px;" /></td></tr>';
  862.  
  863.         if($contacts_module)
  864.         {
  865.             if ($event['contact_id'] > 0)
  866.             {
  867.                 require_once($GO_CONFIG->class_path.'addressbook.class.inc');
  868.                 $ab = new addressbook();
  869.                 $contact = $ab->get_contact($event['contact_id']);
  870.                 $middle_name = $contact['middle_name'] == '' ? '' : $contact['middle_name'].' ';
  871.                 $contact_name = $contact['first_name'].' '.$middle_name.$contact['last_name'];
  872.             }else
  873.             {
  874.                 $contact_name = isset($_POST['contact_name']) ? $_POST['contact_name'] : '';
  875.             }
  876.  
  877.             echo '<tr><td><table border="0" cellpadding="0" cellspacing="0"><tr><td><a class="normal" href="javascript:popup(\''.$contacts_module['url'].'select.php?show_contacts=true&multiselect=false&GO_HANDLER='.$GO_MODULES->url.'add_client.php&pass_value=id\',\'550\',\'400\')"><img src="'.$GO_THEME->images['addressbook_small'].'" width="16" height="16" border="0" /></a> </td><td><a class="normal" href="javascript:popup(\''.$contacts_module['url'].'select.php?show_contacts=true&multiselect=false&GO_HANDLER='.$GO_MODULES->url.'add_client.php&pass_value=id\',\'550\',\'400\')">'.$sc_client.'</a>: </td></tr></table></td>';
  878.             echo '<td><input type="hidden" value="'.$event['contact_id'].'" name="contact_id" /><input type="hidden" value="'.$contact_name.'" name="contact_name" /><input type="text" name="contact_name_text" class="textbox" style="width: 300px;" value="'.$contact_name.'" disabled>';
  879.             echo " <a href='javascript:remove_client()' title=\"".$strDeleteItem."\"><img src=\"".$GO_THEME->images['delete']."\" border=\"0\"></a></td></tr>";
  880.         }else
  881.         {
  882.             echo '<input type="hidden" value="0" name="contact_id" />';
  883.         }
  884.         echo '<tr><td>'.$sc_location.':</td><td><input type="text" class="textbox" style="width: 300px;" name="location" value="'.$event['location'].'" /></td></tr>';
  885.         echo '<tr><td valign="top">'.$sc_description.': </td><td><textarea class="textbox" name="description" cols="60" rows="4">'.$event['description'].'</textarea></td></tr>';
  886.         echo '<tr><td colspan="2"> </td></tr>';
  887.  
  888.         echo '<tr><td>'.$sc_start_at.': </td><td>';
  889.         echo '<table border="0" cellpadding="0" cellspacing="0"><tr><td>';
  890.  
  891.         $datepicker->print_date_picker('start_date', $_SESSION['GO_SESSION']['date_format'], $event['start_date']);
  892.  
  893.         echo '</td><td>  ';
  894.  
  895.         $dropbox = new dropbox();
  896.         $dropbox->add_arrays($hours, $hours);
  897.         $dropbox->print_dropbox("start_hour", $event['start_hour']);
  898.         echo ' : ';
  899.         $dropbox = new dropbox();
  900.         $dropbox->add_arrays($mins, $mins);
  901.         $dropbox->print_dropbox("start_min", $event['start_min']);
  902.  
  903.         echo '</td></tr></table>';
  904.         echo '</td></tr>';
  905.  
  906.         echo '<tr><td>'.$sc_end_at.': </td><td>';
  907.  
  908.         echo '<table border="0" cellpadding="0" cellspacing="0"><tr><td>';
  909.         $datepicker->print_date_picker('end_date', $_SESSION['GO_SESSION']['date_format'], $event['end_date']);
  910.         echo '</td><td>  ';
  911.         $dropbox = new dropbox();
  912.         $dropbox->add_arrays($hours, $hours);
  913.         $dropbox->print_dropbox("end_hour", $event['end_hour']);
  914.         echo ' : ';
  915.         $dropbox = new dropbox();
  916.         $dropbox->add_arrays($mins, $mins);
  917.         $dropbox->print_dropbox("end_min", $event['end_min']);
  918.         echo '</td></tr></table>';
  919.         echo '</td></tr>';
  920.  
  921.         $all_day_event = ($event['all_day_event'] == '1') ? true : false;
  922.  
  923.         echo '<tr><td> </td><td>';
  924.         $checkbox = new checkbox('all_day_event', '1', $sc_notime, $all_day_event, false, 'onclick="javascript:disable_time()"');
  925.         echo '</td></tr>';
  926.  
  927.         echo '<tr><td colspan="2"> </td></tr>';
  928.  
  929.         echo '<tr><td>'.$sc_recur_every.':</td><td>';
  930.  
  931.         $dropbox = new dropbox();
  932.         for ($i=1;$i<11;$i++)
  933.         {
  934.             $dropbox->add_value($i, $i);
  935.         }
  936.         $dropbox->print_dropbox('repeat_every', $event['repeat_every']);
  937.         $dropbox = new dropbox();
  938.         $dropbox->add_value('0', $sc_types1[REPEAT_NONE]);
  939.         $dropbox->add_value('1', $sc_types1[REPEAT_DAILY]);
  940.         $dropbox->add_value('2', $sc_types1[REPEAT_WEEKLY]);
  941.         $dropbox->add_value('3', $sc_types1[REPEAT_MONTH_DATE]);
  942.         $dropbox->add_value('4', $sc_types1[REPEAT_MONTH_DAY]);
  943.         $dropbox->add_value('5', $sc_types1[REPEAT_YEARLY]);
  944.         $dropbox->print_dropbox('repeat_type', $event['repeat_type'], 'onclick="javascript:toggle_repeat(this.value);"');
  945.  
  946.         echo '</td></tr>';
  947.  
  948.         echo '<tr><td>'.$sc_at_days.':</td><td>';
  949.         echo '<table border="0" cellpadding="0" cellspacing="0"><tr>';
  950.         echo '<td>';
  951.         $dropbox = new dropbox();
  952.         $dropbox->add_arrays(array(1,2,3,4), $month_times);
  953.         $dropbox->print_dropbox("month_time", $event['month_time']);
  954.         echo '</td>';
  955.  
  956.  
  957.         $day_data_field[0] = 'sun';
  958.         $day_data_field[1] = 'mon';
  959.         $day_data_field[2] = 'tue';
  960.         $day_data_field[3] = 'wed';
  961.         $day_data_field[4] = 'thu';
  962.         $day_data_field[5] = 'fri';
  963.         $day_data_field[6] = 'sat';
  964.  
  965.         $day_number = $_SESSION['GO_SESSION']['first_weekday'];
  966.  
  967.         for ($i=0;$i<7;$i++)
  968.         {
  969.             if ($day_number == 7) $day_number = 0;
  970.             echo '<td>';
  971.             $checkbox = new checkbox('repeat_days_'.$day_number, '1', $days[$day_number], $event[$day_data_field[$day_number]]);
  972.             echo '</td>';
  973.             $day_number++;
  974.         }
  975.         echo '</tr></table></td></tr>';
  976.         echo '<tr><td>'.$sc_cycle_end.': </td><td>';
  977.         $datepicker->print_date_picker('repeat_end_date', $_SESSION['GO_SESSION']['date_format'], $event['repeat_end_date']);
  978.  
  979.         $repeat_forever = $event['repeat_forever'] == '1' ? true : false;
  980.         $checkbox = new checkbox('repeat_forever', '1', $sc_noend, $repeat_forever, false, 'onclick="javascript:toggle_repeat_end_info()"');
  981.         echo '</td></tr>';
  982.  
  983.         echo '<tr><td colspan="2"> </td></tr>';
  984.  
  985.         echo '<tr><td>'.$sc_reminder.':</td><td>';
  986.  
  987.         $dropbox=new dropbox();
  988.         $dropbox->add_value('0', ' ');
  989.         $dropbox->add_value('300', '5 '.$sc_mins);
  990.         $dropbox->add_value('900', '15 '.$sc_mins);
  991.         $dropbox->add_value('1800', '30 '.$sc_mins);
  992.         $dropbox->add_value('2700', '45 '.$sc_mins);
  993.         $dropbox->add_value('3600', '1 '.$sc_hour);
  994.         $dropbox->add_value('7200', '2 '.$sc_hours);
  995.         $dropbox->add_value('10800', '3 '.$sc_hours);
  996.         $dropbox->add_value('14400', '4 '.$sc_hours);
  997.         $dropbox->add_value('18000', '5 '.$sc_hours);
  998.         $dropbox->add_value('21600', '6 '.$sc_hours);
  999.         $dropbox->add_value('25200', '7 '.$sc_hours);
  1000.         $dropbox->add_value('28800', '8 '.$sc_hours);
  1001.         $dropbox->add_value('32400', '9 '.$sc_hours);
  1002.         $dropbox->add_value('36000', '10 '.$sc_hours);
  1003.         $dropbox->add_value('39600', '11 '.$sc_hours);
  1004.         $dropbox->add_value('43200', '12 '.$sc_hours);
  1005.         $dropbox->add_value('86400', '1 '.$sc_day);
  1006.         $dropbox->add_value('172800', '2 '.$sc_days);
  1007.         $dropbox->add_value('259200', '3 '.$sc_days);
  1008.         $dropbox->add_value('345600', '4 '.$sc_days);
  1009.         $dropbox->add_value('432000', '5 '.$sc_days);
  1010.         $dropbox->add_value('518400', '6 '.$sc_days);
  1011.         $dropbox->add_value('604800', '1 '.$sc_week);
  1012.         $dropbox->add_value('1209600', '2 '.$sc_weeks);
  1013.         $dropbox->add_value('1814400', '3 '.$sc_weeks);
  1014.         $dropbox->print_dropbox('reminder', $event['reminder']);
  1015.  
  1016.         echo '</td></tr>';
  1017.         echo '<tr><td colspan="2"> </td></tr>';
  1018.         echo '<tr><td nowrap>'.$sc_background.': </td><td>';
  1019.  
  1020.         echo '<table border="0"><tr>';
  1021.         echo '<td id="FFFFCC" style="background-color: #FFFFCC; border: 1px solid #aaa;"><a href="javascript:select_background(\'FFFFCC\');"><img border="0" height="16" width="16" src="'.$GO_THEME->images['blank'].'" /></a></td>';
  1022.         echo '<td id="FF6666" style="background-color: #FF6666; border: 1px solid #aaa;"><a href="javascript:select_background(\'FF6666\');"><img border="0" height="16" width="16" src="'.$GO_THEME->images['blank'].'" /></a></td>';
  1023.         echo '<td id="CCFFCC" style="background-color: #CCFFCC; border: 1px solid #aaa;"><a href="javascript:select_background(\'CCFFCC\');"><img border="0" height="16" width="16" src="'.$GO_THEME->images['blank'].'" /></a></td>';
  1024.         echo '<td id="99CCFF" style="background-color: #99CCFF; border: 1px solid #aaa;"><a href="javascript:select_background(\'99CCFF\');"><img border="0" height="16" width="16" src="'.$GO_THEME->images['blank'].'" /></a></td>';
  1025.         echo '<td id="FF99FF" style="background-color: #FF99FF; border: 1px solid #aaa;"><a href="javascript:select_background(\'FF99FF\');"><img border="0" height="16" width="16" src="'.$GO_THEME->images['blank'].'" /></a></td>';
  1026.         echo '<td id="FFCC66" style="background-color: #FFCC66; border: 1px solid #aaa;"><a href="javascript:select_background(\'FFCC66\');"><img border="0" height="16" width="16" src="'.$GO_THEME->images['blank'].'" /></a></td>';
  1027.         echo '<td id="CCCC66" style="background-color: #CCCC66; border: 1px solid #aaa;"><a href="javascript:select_background(\'CCCC66\');"><img border="0" height="16" width="16" src="'.$GO_THEME->images['blank'].'" /></a></td>';
  1028.         echo '<td id="F1F1F1" style="background-color: #F1F1F1; border: 1px solid #aaa;"><a href="javascript:select_background(\'F1F1F1\');"><img border="0" height="16" width="16" src="'.$GO_THEME->images['blank'].'" /></a></td>';
  1029.         echo '<td id="FFCCFF" style="background-color: #FFCCFF; border: 1px solid #aaa;"><a href="javascript:select_background(\'FFCCFF\');"><img border="0" height="16" width="16" src="'.$GO_THEME->images['blank'].'" /></a></td>';
  1030.         echo '</tr></table>';
  1031.         echo '<input type="hidden" name="background" value="'.$event['background'].'" />';
  1032.         echo '</td></tr>';
  1033.  
  1034.         if ($event_id == 0)
  1035.         {
  1036.             $private_check = isset($_POST['private']) ? 'checked' : '';
  1037.             echo '<tr><td> </td><td>';
  1038.             $checkbox = new checkbox('private', 'true', $sc_private_event, $private_check);
  1039.             echo '</td></tr>';
  1040.         }
  1041.  
  1042.         $calendar_count = $cal->get_subscribed($GO_SECURITY->user_id);
  1043.         $dropbox= new dropbox();
  1044.         $count = 0;
  1045.         while ($cal->next_record())
  1046.         {
  1047.             if ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $cal->f('acl_write')))
  1048.             {
  1049.                 //remember the first ab that is writable
  1050.                 if(!isset($first_writable_cal))
  1051.                 {
  1052.                     $first_writable_cal = $cal->f('id');
  1053.                 }
  1054.                 $dropbox->add_value($cal->f('id'), $cal->f('name'));
  1055.                 $count++;
  1056.             }
  1057.         }
  1058.  
  1059.         //get the given addressbook_id
  1060.         if ($calendar_id > 0)
  1061.         {
  1062.              $calendar = $cal->get_calendar($calendar_id);
  1063.         }
  1064.  
  1065.         //if there was no or a read only addressbook given then change to the first writable
  1066.         if (!$calendar || !$GO_SECURITY->has_permission($GO_SECURITY->user_id, $calendar['acl_write']))
  1067.         {
  1068.             //there is no writable addressbook so add one
  1069.             if (!isset($first_writable_cal))
  1070.             {
  1071.                 $cal_name = $_SESSION['GO_SESSION']['name'];
  1072.                 $new_cal_name = $cal_name;
  1073.                 $x = 1;
  1074.                 while($cal->get_calendar_by_name($new_cal_name))
  1075.                 {
  1076.                     $new_cal_name = $cal_name.' ('.$x.')';
  1077.                     $x++;
  1078.                 }
  1079.                 $calendar_id = $cal->add_calendar($GO_SECURITY->user_id, $new_cal_name, 0, 23);
  1080.                 $dropbox->add_value($calendar_id, $new_cal_name);
  1081.             }else
  1082.             {
  1083.                 $calendar_id = $first_writable_cal;
  1084.             }
  1085.         }
  1086.  
  1087.         if (count($event['calendars']) == 0)
  1088.         {
  1089.             $event['calendars'][] = $calendar_id;
  1090.         }
  1091.  
  1092.         for($i=0;$i<count($event['calendars']);$i++)
  1093.         {
  1094.             if ($dropbox->is_in_dropbox($event['calendars'][$i]))
  1095.             {
  1096.                 echo '<input type="hidden" name="calendars[]" value="'.$event['calendars'][$i].'" />';
  1097.             }
  1098.         }
  1099.  
  1100.         echo '<tr><td valign="top">'.$sc_put_in.':</td>';
  1101.         echo '<td><table border="0">';
  1102.         $dropbox->print_dropbox('calendars[]', $event['calendars'], '', true, '5');
  1103.         echo '</table></td></tr>';
  1104.  
  1105.         echo '<tr><td colspan="2">';
  1106.         $button = new button($cmdOk, "javascript:save_event('true');");
  1107.         echo '  ';
  1108.         $button = new button($cmdApply, "javascript:save_event('false');");
  1109.         echo '  ';
  1110.         $button = new button($cmdCancel, "javascript:document.location='$return_to'");
  1111.         echo '</td></tr>';
  1112.         echo '</table>';
  1113.         ?>
  1114.         <script type="text/javascript" language="javascript">
  1115.         function select_background(color)
  1116.         {
  1117.             active_table_cell = document.getElementById(document.event_form.background.value);
  1118.             table_cell = document.getElementById(color);
  1119.             active_table_cell.style.border = '1px solid #aaa';
  1120.             table_cell.style.border = '2px solid black';
  1121.             document.event_form.background.value = color;
  1122.  
  1123.         }
  1124.         select_background('<?php echo $event['background']; ?>');
  1125.  
  1126.  
  1127.         toggle_repeat('<?php echo $event['repeat_type']; ?>');
  1128.         <?php
  1129.  
  1130.         if ($event['all_day_event'] == '1')
  1131.         {
  1132.             echo 'disable_time();';
  1133.         }
  1134.  
  1135.         if ($event['repeat_forever'] == '1')
  1136.         {
  1137.             echo 'toggle_repeat_end_info();';
  1138.         }
  1139.  
  1140.         if ($contacts_module)
  1141.         {
  1142.  
  1143.         ?>
  1144.             function open_addressbook(field, address_string)
  1145.             {
  1146.                 //popup('<?php echo $contacts_module['url']."select.php?multiselect=true&require_email_address=true&SET_HANDLER=".$GO_MODULES->url."add_contacts.php&SET_FIELD="; ?>'+field+'&address_string='+escape(address_string),'550','400');
  1147.  
  1148.                 var popup = window.open('about:blank', 'ab_select', 'width=550,height=400,scrollbars=yes,resizable=yes,status=yes');
  1149.                 if (!popup.opener) popup.opener = self;
  1150.                 popup.focus();
  1151.  
  1152.                 document.event_form.address_string.value = address_string;
  1153.                 document.event_form.action = '<?php echo $contacts_module['url']."select.php?show_contacts=true&show_users=true&show_companies=true&multiselect=true&require_email_address=true&GO_HANDLER=".$GO_MODULES->url."add_contacts.php&GO_FIELD="; ?>'+field;
  1154.                 document.event_form.target = 'ab_select';
  1155.                 document.event_form.submit();
  1156.                 document.event_form.target = '_self';
  1157.                 document.event_form.action = '<?php echo $_SERVER['PHP_SELF']; ?>';
  1158.             }
  1159.         <?php
  1160.         }
  1161.         ?>
  1162.  
  1163.         function get_date(dateString)
  1164.         {
  1165.             <?php
  1166.             if ($_SESSION['GO_SESSION']['date_format'] == "m-j-Y")
  1167.             {
  1168.                 echo "
  1169.                     var date = new Date(dateString.substring(6,10),
  1170.                                 dateString.substring(3,5)-1,
  1171.                                 dateString.substring(0,2),
  1172.                                 dateString.substring(11,13),
  1173.                                 dateString.substring(14,16)
  1174.                                 );";
  1175.             }else
  1176.             {
  1177.                 echo "
  1178.                     var date = new Date(dateString.substring(6,10),
  1179.                                 dateString.substring(0,2),
  1180.                                 dateString.substring(3,5)-1,
  1181.                                 dateString.substring(11,13),
  1182.                                 dateString.substring(14,16)
  1183.                                 );";
  1184.             }
  1185.             ?>
  1186.  
  1187.             return date;
  1188.         }
  1189.  
  1190.         function save_event(close)
  1191.         {
  1192.             start_date = get_date(document.event_form.start_date.value.replace(/-/g,'/')+' '+document.event_form.start_hour.value+':'+document.event_form.start_min.value+':00');
  1193.             end_date = get_date(document.event_form.end_date.value.replace(/-/g,'/')+' '+document.event_form.end_hour.value+':'+document.event_form.end_min.value+':00');
  1194.             repeat_end_date = get_date(document.event_form.repeat_end_date.value.replace(/-/g,'/')+' 00:00:00');
  1195.  
  1196.             if (start_date > end_date)
  1197.             {
  1198.                 alert("<?php echo $sc_start_later; ?>");
  1199.                 return;
  1200.             }
  1201.             if (document.event_form.repeat_type.value != '0')
  1202.             {
  1203.                 if ((start_date >= repeat_end_date) && document.event_form.repeat_forever.checked == false)
  1204.                 {
  1205.                     alert("<?php echo $sc_cycle_start_later; ?>");
  1206.                     return;
  1207.                 }
  1208.             }
  1209.  
  1210.             if (document.event_form.repeat_type.value == '1' && document.event_form.reminder.value > 43200)
  1211.             {
  1212.                 alert("<?php echo $sc_reminder_set_to_early; ?>");
  1213.                 return;
  1214.             }
  1215.  
  1216.             if (document.event_form.repeat_type.value == '2' && document.event_form.reminder.value > 518400)
  1217.             {
  1218.                     alert("<?php echo $sc_reminder_set_to_early; ?>");
  1219.                     return;
  1220.             }
  1221.  
  1222.             if (document.event_form.repeat_type.value == '2' || document.event_form.repeat_type.value == '4')
  1223.             {
  1224.                 if (document.event_form.repeat_days_0.checked == false && document.event_form.repeat_days_1.checked == false && document.event_form.repeat_days_2.checked == false && document.event_form.repeat_days_3.checked == false && document.event_form.repeat_days_4.checked == false && document.event_form.repeat_days_5.checked == false && document.event_form.repeat_days_6.checked == false)
  1225.                 {
  1226.                     alert("<?php echo $sc_never_happens; ?>");
  1227.                     return;
  1228.                 }
  1229.             }
  1230.             document.event_form.task.value = 'save_event';
  1231.             document.event_form.close.value = close;
  1232.  
  1233.             document.event_form.submit();
  1234.  
  1235.         }
  1236.  
  1237.         function remove_client()
  1238.         {
  1239.             document.event_form.contact_id.value = 0;
  1240.             document.event_form.contact_name.value = '';
  1241.             document.event_form.contact_name_text.value = '';
  1242.         }
  1243.  
  1244.         function toggle_repeat_end_info()
  1245.         {
  1246.             document.event_form.repeat_end_date.disabled = !document.event_form.repeat_end_date.disabled;
  1247.         }
  1248.  
  1249.         function disable_time()
  1250.         {
  1251.             if (document.event_form.start_hour.disabled==false)
  1252.             {
  1253.                 document.event_form.start_hour.disabled=true;
  1254.                 document.event_form.start_min.disabled=true;
  1255.                 document.event_form.end_hour.disabled=true;
  1256.                 document.event_form.end_min.disabled=true;
  1257.             }else
  1258.             {
  1259.                 document.event_form.start_hour.disabled=false;
  1260.                 document.event_form.start_min.disabled=false;
  1261.                 document.event_form.end_hour.disabled=false;
  1262.                 document.event_form.end_min.disabled=false;
  1263.             }
  1264.         }
  1265.  
  1266.         function toggle_repeat(repeat)
  1267.         {
  1268.  
  1269.             document.event_form.repeat_type.value = repeat;
  1270.             switch(repeat)
  1271.             {
  1272.                 case '0':
  1273.                     disable_days(true);
  1274.                     document.event_form.month_time.disabled = true;
  1275.                     disable_repeat_end_date(true);
  1276.                     document.event_form.repeat_every.disabled = true;
  1277.                 break;
  1278.  
  1279.                 case '1':
  1280.                     disable_days(true);
  1281.                     document.event_form.month_time.disabled = true;
  1282.                     disable_repeat_end_date(false);
  1283.                     document.event_form.repeat_every.disabled = false;
  1284.                 break;
  1285.  
  1286.                 case '2':
  1287.                     disable_days(false);
  1288.                     document.event_form.month_time.disabled = true;
  1289.                     disable_repeat_end_date(false);
  1290.                     document.event_form.repeat_every.disabled = false;
  1291.                 break;
  1292.  
  1293.                 case '3':
  1294.                     disable_days(true);
  1295.                     disable_repeat_end_date(false);
  1296.                 break;
  1297.  
  1298.                 case '4':
  1299.                     disable_days(false);
  1300.                     document.event_form.month_time.disabled = false;
  1301.                     disable_repeat_end_date(false);
  1302.                     document.event_form.repeat_every.disabled = false;
  1303.                 break;
  1304.  
  1305.                 case '5':
  1306.                     disable_days(true);
  1307.                     document.event_form.month_time.disabled = true;
  1308.                     disable_repeat_end_date(false);
  1309.                     document.event_form.repeat_every.disabled = false;
  1310.                 break;
  1311.             }
  1312.         }
  1313.  
  1314.         function disable_days(disable)
  1315.         {
  1316.             document.event_form.repeat_days_0.disabled=disable;
  1317.             document.event_form.repeat_days_1.disabled=disable;
  1318.             document.event_form.repeat_days_2.disabled=disable;
  1319.             document.event_form.repeat_days_3.disabled=disable;
  1320.             document.event_form.repeat_days_4.disabled=disable;
  1321.             document.event_form.repeat_days_5.disabled=disable;
  1322.             document.event_form.repeat_days_6.disabled=disable;
  1323.  
  1324.         }
  1325.  
  1326.         function disable_repeat_end_date(disable)
  1327.         {
  1328.             document.event_form.repeat_forever.disabled=disable;
  1329.             if (disable == true || (disable==false && document.event_form.repeat_forever.checked == false))
  1330.             {
  1331.                 document.event_form.repeat_end_date.disabled=disable;
  1332.             }
  1333.         }
  1334.  
  1335.         document.event_form.name.focus();
  1336.         </script>
  1337.         <?php
  1338.     break;
  1339. }
  1340. $tabtable->print_foot();
  1341. echo '</form>';
  1342. require($GO_THEME->theme_path.'footer.inc');
  1343. ?>
  1344.