Exemplo n.º 1
0
 function check_repeating_events($datetime)
 {
     @reset($this->repeating_events);
     $search_date_full = date('Ymd', $datetime);
     $search_date_year = date('Y', $datetime);
     $search_date_month = date('m', $datetime);
     $search_date_day = date('d', $datetime);
     $search_date_dow = date('w', $datetime);
     $search_date_week = date('YW', $datetime);
     $search_beg_day = mktime(13, 0, 0, $search_date_month, $search_date_day, $search_date_year);
     if ($this->debug) {
         echo '<!-- Search Date Full = ' . $search_date_full . ' -->' . "\n";
     }
     $repeated = $this->repeating_events;
     $r_events = count($repeated);
     for ($i = 0; $i < $r_events; $i++) {
         if ($this->repeating_events[$i]['repeat_type'] != 0) {
             $rep_events = $this->repeating_events[$i];
             $id = $rep_events['id'];
             $rep_events['start']['month'] = date('m', $rep_events['start_date']);
             $rep_events['start']['mday'] = date('d', $rep_events['start_date']);
             $rep_events['start']['year'] = date('Y', $rep_events['start_date']);
             //					$event_beg_day = mktime(0,0,0,$rep_events['start']['month'],$rep_events['start']['mday'],$rep_events['start']['year']);
             $event_beg_day = $rep_events['start_date'];
             $event_beg_week = date('YW', $rep_events['start_date']);
             if (isset($rep_events['end_date']) && $rep_events['end_date']) {
                 $event_recur_time = $rep_events['end_date'];
             } else {
                 $event_recur_time = mktime(0, 0, 0, 1, 1, 2030);
             }
             /*
             					if($rep_events['recur_enddate']['month'] != 0 && $rep_events['recur_enddate']['mday'] != 0 && $rep_events['recur_enddate']['year'] != 0)
             					{
             						$event_recur_time = $this->maketime($rep_events['recur_enddate']);
             					}
             					else
             					{
             						$event_recur_time = mktime(0,0,0,1,1,2030);
             					}
             */
             $end_recur_date = date('Ymd', $event_recur_time);
             $full_event_date = date('Ymd', $event_beg_day);
             if ($this->debug) {
                 echo '<!-- check_repeating_events - Processing ID - ' . $id . ' -->' . "\n";
                 echo '<!-- check_repeating_events - Recurring End Date - ' . $end_recur_date . ' -->' . "\n";
             }
             // only repeat after the beginning, and if there is an rpt_end before the end date
             if ($search_date_full > $end_recur_date || $search_date_full < $full_event_date) {
                 continue;
             }
             if ($search_date_full == $full_event_date) {
                 $this->sort_event($rep_events, $search_date_full);
                 continue;
             } else {
                 $freq = isset($rep_events['repeat_interval']) && $rep_events['repeat_interval'] ? $rep_events['repeat_interval'] : 1;
                 $type = $rep_events['repeat_type'];
                 switch ($type) {
                     case MCAL_RECUR_DAILY:
                         if ($this->debug) {
                             echo '<!-- check_repeating_events - MCAL_RECUR_DAILY - ' . $id . ' -->' . "\n";
                         }
                         //if ($freq == 1 && $rep_events['recur_enddate']['month'] != 0 && $rep_events['recur_enddate']['mday'] != 0 && $rep_events['recur_enddate']['year'] != 0 && $search_date_full <= $end_recur_date)
                         if ($freq == 1 && $rep_events['end_date'] && $search_date_full <= $end_recur_date) {
                             $this->sort_event($rep_events, $search_date_full);
                         } elseif (floor(($search_beg_day - $event_beg_day) / 86400) % $freq) {
                             continue;
                         } else {
                             $this->sort_event($rep_events, $search_date_full);
                         }
                         break;
                     case MCAL_RECUR_WEEKLY:
                         $test = ($search_beg_day - $event_beg_day) / 604800 / $freq;
                         $test_subtract = floor($test);
                         //if (floor(($search_beg_day - $event_beg_day)/604800) % $freq)
                         if (!$rep_events['rpt_day']) {
                             if (!($test - $test_subtract)) {
                                 $this->sort_event($rep_events, $search_date_full);
                             }
                         } else {
                             $test = ($search_date_week - $event_beg_week) / $freq;
                             $test_subtract = floor($test);
                             if ($test - $test_subtract) {
                                 continue;
                             }
                             $check = 0;
                             switch ($search_date_dow) {
                                 case 0:
                                     $check = MCAL_M_SUNDAY;
                                     break;
                                 case 1:
                                     $check = MCAL_M_MONDAY;
                                     break;
                                 case 2:
                                     $check = MCAL_M_TUESDAY;
                                     break;
                                 case 3:
                                     $check = MCAL_M_WEDNESDAY;
                                     break;
                                 case 4:
                                     $check = MCAL_M_THURSDAY;
                                     break;
                                 case 5:
                                     $check = MCAL_M_FRIDAY;
                                     break;
                                 case 6:
                                     $check = MCAL_M_SATURDAY;
                                     break;
                             }
                             if ($rep_events['rpt_day'] & $check) {
                                 $this->sort_event($rep_events, $search_date_full);
                             }
                         }
                         break;
                     case MCAL_RECUR_MONTHLY_WDAY:
                         if ((($search_date_year - $rep_events['start']['year']) * 12 + $search_date_month - $rep_events['start']['month']) % $freq) {
                             continue;
                         }
                         if (phpgwapi_datetime::day_of_week($rep_events['start']['year'], $rep_events['start']['month'], $rep_events['start']['mday']) == phpgwapi_datetime::day_of_week($search_date_year, $search_date_month, $search_date_day) && ceil($rep_events['start']['mday'] / 7) == ceil($search_date_day / 7)) {
                             $this->sort_event($rep_events, $search_date_full);
                         }
                         break;
                     case MCAL_RECUR_MONTHLY_MDAY:
                         if ((($search_date_year - $rep_events['start']['year']) * 12 + $search_date_month - $rep_events['start']['month']) % $freq) {
                             continue;
                         }
                         if ($search_date_day == $rep_events['start']['mday']) {
                             $this->sort_event($rep_events, $search_date_full);
                         }
                         break;
                     case MCAL_RECUR_YEARLY:
                         if (($search_date_year - $rep_events['start']['year']) % $freq) {
                             continue;
                         }
                         if (date('dm', $datetime) == date('dm', $event_beg_day)) {
                             $this->sort_event($rep_events, $search_date_full);
                         }
                         break;
                 }
             }
         }
     }
     // end for loop
 }
 /**
  * planner_prepare - prepare the planner view
  *
  * - sets global environment variables
  * - initializes class member variables used in multiple planner related functions
  * - generates header lines for the planner view (month, calendar week, days)
  */
 function planner_prepare($no_header = False)
 {
     // set some globals
     //
     if (!$no_header) {
         unset($GLOBALS['phpgw_info']['flags']['noheader']);
         unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
         if ($this->always_app_header) {
             $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'] . ' - ' . lang('Group Planner');
         }
         //$GLOBALS['phpgw']->common->phpgw_header();
         $this->header();
     }
     // intervals_per_day can be configured in preferences now :-)
     //
     if (!$this->bo->prefs['calendar']['planner_intervals_per_day']) {
         $GLOBALS['phpgw']->preferences->read();
         $GLOBALS['phpgw']->preferences->add('calendar', 'planner_intervals_per_day', 3);
         $GLOBALS['phpgw']->preferences->save_repository();
         $this->bo->prefs['calendar']['planner_intervals_per_day'] = 3;
     }
     $intervals_per_day = $this->bo->prefs['calendar']['planner_intervals_per_day'];
     $this->bo->save_sessiondata();
     // need to save $this->bo->save_owner
     // set title for table and rows of planner view
     //
     if ($this->bo->sortby == 'category') {
         $title = lang('Category');
     } else {
         $title = lang('User');
         $this->set_planner_group_members();
     }
     // create/initialize variables directly used for HTML code generation
     //
     $this->planner_html = CreateObject('calendar.html');
     $this->planner_header = array();
     $this->planner_rows = array();
     // generate header lines with days and associated months
     //
     $hdr =& $this->planner_header;
     $hdr[0]['0'] = $title;
     $hdr[0]['.0'] = 'rowspan="3"';
     $this->planner_days = 0;
     // reset
     $m = $this->bo->month;
     $y = $this->bo->year;
     $this->bo->read_holidays($y);
     for ($i = 1; $i <= $this->bo->num_months; $i++, $m++) {
         if ($m == 13) {
             $m = 1;
             $y++;
             // "wrap-around" into new year
             $this->bo->read_holidays($y);
         }
         $days = phpgwapi_datetime::days_in_month($m, $y);
         $d = mktime(0, 0, 0, $m, 1, $y);
         $month = lang(date('F', $d)) . strftime(' %Y', $d);
         $cssclass = $m % 2 ? 'row_on' : 'row_off';
         $cols = $days * $intervals_per_day;
         $hdr[0]['.' . $i] = 'classr="' . $cssclass . '" colspan="' . $cols . '" align ="center"';
         $prev_month = sprintf('%04d%02d01', $y - ($m == 1), $m > 1 ? $m - 1 : 12);
         $next_month = sprintf('%04d%02d01', $y + ($m == 12), $m < 12 ? $m + 1 : 1);
         $prev_link = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'calendar.uicalendar.planner', 'date' => $prev_month));
         $next_link = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'calendar.uicalendar.planner', 'date' => $next_month));
         $hdr[0][$i] = "<b><a href=\"{$prev_link}\">&lt;&lt;</a> &nbsp {$month} &nbsp <a href=\"{$next_link}\">&gt;&gt;</a></b>";
         $add_owner = array();
         // if no add-rights on the showed cal use own cal
         if ((!isset($this->bo->save_owner) || !$this->bo->save_owner) && !$this->bo->check_perms(PHPGW_ACL_ADD) || !$this->bo->check_perms(PHPGW_ACL_ADD, 0, isset($this->bo->save_owner) ? $this->bo->save_owner : '')) {
             $add_owner = array('owner' => $this->bo->contacts->is_contact($GLOBALS['phpgw_info']['user']['account_id']));
         } else {
             $add_owner = array('owner' => isset($this->bo->save_owner) && $this->bo->save_owner ? $this->bo->save_owner : $this->bo->contacts->is_contact($GLOBALS['phpgw_info']['user']['account_id']));
         }
         for ($d = 1; $d <= $days; $d++) {
             $dayname = substr(lang(date('D', mktime(0, 0, 0, $m, $d, $y))), 0, 2);
             $index = $d + $this->planner_days;
             $hdr[2]['.' . $index] = 'colspan="' . $intervals_per_day . '" align="center"';
             // highlight today, saturday, sunday and holidays
             //
             $dow = phpgwapi_datetime::day_of_week($y, $m, $d);
             $date = sprintf("%04d%02d%02d", $y, $m, $d);
             if ($date == date('Ymd')) {
                 $cssclass = 'cal_today';
             } elseif (isset($this->bo->cached_holidays[$date]) && $this->bo->cached_holidays[$date]) {
                 $cssclass = $this->bo->holiday_class;
                 $hdr[2]['.' . $index] .= ' title="' . $this->bo->cached_holidays[$date][0]['name'] . '"';
             } elseif ($dow == 0 || $dow == 6) {
                 $cssclass = 'th';
             }
             $hdr[2]['.' . $index] .= " class=\"{$cssclass}\"";
             $hdr[2][$index] = '<a href="' . $this->planner_html->link('/index.php', array('menuaction' => 'calendar.uicalendar.add', 'date' => $date) + $add_owner) . '">' . $dayname . '<br />' . $d . '</a>';
         }
         $this->planner_days += $days;
     }
     // create/initialize member variables describing the time interval to be displayed
     //
     $this->planner_end_month = $m - 1;
     $this->planner_end_year = $y;
     $this->planner_days_in_end_month = phpgwapi_datetime::days_in_month($this->planner_end_month, $this->planner_end_year);
     $this->planner_firstday = intval(date('Ymd', mktime(0, 0, 0, $this->bo->month, 1, $this->bo->year)));
     $this->planner_lastday = intval(date('Ymd', mktime(0, 0, 0, $this->planner_end_month, $this->planner_days_in_end_month, $this->planner_end_year)));
     // generate line with calendar weeks in observed interval
     //
     $d = mktime(0, 0, 0, $this->bo->month, 1, $this->bo->year);
     $w = date('W', $d);
     if ($w == 'W') {
         $w = 1 + intval(date('z', $d) / 7);
         // a bit simplistic
     }
     $offset = (7 - date("w", $d) + 1) % 7;
     $offset = $offset == 0 ? 7 : $offset;
     $cssclass = $w % 2 ? 'th' : 'row_on';
     $hdr[1]['.' . $w] = 'class="' . $cssclass . '" colspan="' . $intervals_per_day * $offset . '" align="left"';
     $hdr[1][$w] = '';
     if ($offset >= 3) {
         $hdr[1][$w] .= '<font size="-2"> ' . lang('week') . ' ' . $w . ' </font>';
     }
     $days_left = $this->planner_days - $offset;
     $colspan = 7 * $intervals_per_day;
     while ($days_left > 0) {
         $colspan = $days_left < 7 ? $days_left * $intervals_per_day : $colspan;
         $d += 604800;
         // 7 days whith 24 hours (1h == 3600 seconds) each
         $w = date('W', $d);
         if ($w == 'W') {
             $w = 1 + intval(date('z', $d) / 7);
             // a bit simplistic
         }
         $w += isset($hdr[1][$w]) ? 1 : 0;
         // bug in "date('W')" ?
         $cssclass = $w % 2 ? 'th' : 'row_on';
         $hdr[1]['.' . $w] = 'cssclass="' . $cssclass . '" colspan="' . $colspan . '" align="left"';
         $hdr[1][$w] = '';
         if ($days_left >= 3) {
             $hdr[1][$w] .= '<font size="-2"> ' . lang('week') . ' ' . $w . ' </font>';
         }
         $days_left -= 7;
     }
     return $hdr;
 }