/** * Set pending action for items across the system. * * @param array $data array containing string 'appname' - the name of the module being looked up * string 'location' - the location within the module to look up * integer 'id' - id of the referenced item - could possibly be a bigint * integer 'responsible' - the user_id asked for approval * string 'responsible_type' - what type of responsible is asked for action (user,vendor or tenant) * string 'action' - what type of action is pending * string 'remark' - a general remark - if any * integer 'deadline' - unix timestamp if any deadline is given. * * @return integer $reminder number of request for this action */ public function set_pending_action($data = array()) { $appname = $data['appname']; $location = $data['location']; $item_id = $data['id']; //possible bigint $responsible = (int) $data['responsible']; $action = $this->db->db_addslashes($data['action']); $remark = $this->db->db_addslashes($data['remark']); $deadline = (int) $data['deadline']; if (!$item_id) { throw new Exception("No item_id given"); } $responsible_type = isset($data['responsible_type']) && $data['responsible_type'] ? $data['responsible_type'] : 'user'; if (!in_array($responsible_type, $this->valid_responsible_types)) { throw new Exception("'{$responsible_type}' is not a valid responsible_type"); } $sql = "SELECT id FROM fm_action_pending_category WHERE num = '{$action}'"; $this->db->query($sql, __LINE__, __FILE__); $this->db->next_record(); $action_category = $this->db->f('id'); if (!$action_category) { throw new Exception("'{$action}' is not a valid action_type"); } $location_id = $GLOBALS['phpgw']->locations->get_id($appname, $location); if (!$location_id) { throw new Exception("phpgwapi_locations::get_id ({$appname}, {$location}) returned 0"); } $reminder = 1; if ($this->db->get_transaction()) { $this->global_transaction = true; } else { $this->db->transaction_begin(); } $condition = " WHERE location_id = {$location_id}" . " AND item_id = {$item_id}" . " AND responsible = {$responsible}" . " AND action_category = {$action_category}" . " AND action_performed IS NULL" . " AND expired_on IS NULL"; $sql = "SELECT id, reminder FROM fm_action_pending {$condition}"; $this->db->query($sql, __LINE__, __FILE__); $this->db->next_record(); if ($this->db->f('reminder')) { $reminder = $this->db->f('reminder') + 1; $id = $this->db->f('id'); $value_set = array('expired_on' => phpgwapi_datetime::user_localtime(), 'expired_by' => $this->account); if ($deadline > 0) { $value_set['deadline'] = $deadline; } if (isset($data['close']) && $data['close']) { $value_set['action_performed'] = phpgwapi_datetime::user_localtime(); } $value_set = $this->db->validate_update($value_set); $sql = "UPDATE fm_action_pending SET {$value_set} WHERE id = {$id}"; $ok = !!$this->db->query($sql, __LINE__, __FILE__); if (isset($data['close']) && $data['close']) { if (!$this->global_transaction) { $this->db->transaction_commit(); } return $ok; } } //if nothing found - and you want to close if (isset($data['close']) && $data['close']) { return 0; } $values = array($item_id, $location_id, $responsible, $responsible_type, $action_category, phpgwapi_datetime::user_localtime(), $reminder, $deadline, phpgwapi_datetime::user_localtime(), $this->account, $remark); $values = $this->db->validate_insert($values); $sql = "INSERT INTO fm_action_pending (" . "item_id, location_id, responsible, responsible_type," . "action_category, action_requested, reminder, action_deadline," . "created_on, created_by, remark) VALUES ( {$values} {$vals})"; $this->db->query($sql, __LINE__, __FILE__); if (!$this->global_transaction) { $this->db->transaction_commit(); } return $reminder; }
* Based on Webcalendar by Craig Knudsen <*****@*****.**> * * http://www.radix.net/~cknudsen * * Written by Mark Peters <*****@*****.**> * * -------------------------------------------- * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * \**************************************************************************/ /* $Id$ */ if (!isset($GLOBALS['phpgw_info']['user']['preferences']['calendar']['mainscreen_showevents']) || !$GLOBALS['phpgw_info']['user']['preferences']['calendar']['mainscreen_showevents']) { return; } $GLOBALS['phpgw']->translation->add_app('calendar'); phpgw::import_class('phpgwapi.datetime'); $GLOBALS['date'] = date('Ymd', phpgwapi_datetime::user_localtime()); $GLOBALS['g_year'] = substr($GLOBALS['date'], 0, 4); $GLOBALS['g_month'] = substr($GLOBALS['date'], 4, 2); $GLOBALS['g_day'] = substr($GLOBALS['date'], 6, 2); $GLOBALS['owner'] = $GLOBALS['phpgw_info']['user']['account_id']; $GLOBALS['css'] = "\n<style type=\"text/css\">\n<!--\n" . "@import url('calendar/templates/base/css/base.css')\n-->\n</style>\n"; $page_ = explode('.', $GLOBALS['phpgw_info']['user']['preferences']['calendar']['defaultcalendar']); $_page = substr($page_[0], 0, 7); // makes planner from planner_{user|category} if ($_page == 'index' || $_page != 'day' && $_page != 'week' && $_page != 'month' && $_page != 'year' && $_page != 'planner') { $_page = 'month'; $GLOBALS['phpgw']->preferences->read(); $GLOBALS['phpgw']->preferences->add('calendar', 'defaultcalendar', 'month'); $GLOBALS['phpgw']->preferences->save_repository(); } if (!@file_exists(PHPGW_INCLUDE_ROOT . '/calendar/inc/hook_home_' . $_page . '.inc.php')) {
} $refer = explode('.', $GLOBALS['HTTP_GET_VARS']['menuaction']); $referrer = $refer[2]; $templates = array('head_tpl' => 'head.tpl', 'form_button_dropdown' => 'form_button_dropdown.tpl', 'form_button_script' => 'form_button_script.tpl'); $tpl->set_file($templates); $tpl->set_block('head_tpl', 'head', 'head'); $tpl->set_block('head_tpl', 'head_table', 'head_table'); $tpl->set_block('head_tpl', 'head_col', 'head_col'); $tpl->set_block('form_button_script', 'form_button'); if (floor(phpversion()) >= 4) { $tpl->set_var('cols', 8); } else { $tpl->set_var('cols', 7); } phpgw::import_class('phpgwapi.datetime'); $today = date('Ymd', phpgwapi_datetime::user_localtime()); $col_width = 12; add_col($tpl, ' <td width="2%"> </td>'); add_col($tpl, ' <td width="2%">' . add_image_ahref($this->page('day', array('date' => $today)), 'today', lang('Today')) . '</td>'); add_col($tpl, ' <td width="2%" align="left">' . add_image_ahref($this->page('week', array('date' => $today)), 'week', lang('This week')) . '</td>'); add_col($tpl, ' <td width="2%" align="left">' . add_image_ahref($this->page('month', array('date' => $today)), 'month', lang('This month')) . '</td>'); add_col($tpl, ' <td width="2%" align="left">' . add_image_ahref($this->page('year', array('date' => $today)), 'year', lang('This Year')) . '</td>'); if (floor(phpversion()) >= 4) { add_col($tpl, ' <td width="2%" align="left">' . add_image_ahref($this->page('planner', array('date' => $today)), 'planner', lang('Planner')) . '</td>'); $col_width += 2; } add_col($tpl, ' <td width="2%" align="left">' . add_image_ahref($this->page('matrixselect'), 'view', lang('Daily Matrix View')) . '</td>'); add_col($tpl, ' <td width="' . (100 - $col_width) . '%" align="left"' . (floor(phpversion()) < 4 ? ' colspan="2"' : '') . '> </td>'); $tpl->parse('row', 'head_table', True); $tpl->set_var('header_column', ''); $tpl->set_var('cols', $cols);
public function update_receipt($data) { $add_receipt = array(); $delete_receipt = array(); if ($data['events_orig']) { foreach ($data['events_orig'] as $schedule_time_id => $event_id) { if (!$data['events'][$schedule_time_id]) { $delete_receipt[$schedule_time_id] = $event_id; } } } if ($data['events']) { foreach ($data['events'] as $schedule_time_id => $event_id) { if (!$data['events_orig'][$schedule_time_id]) { $add_receipt[$schedule_time_id] = $event_id; } } } $this->_db->transaction_begin(); foreach ($delete_receipt as $schedule_time_id => $event_id) { $schedule = explode('_', $schedule_time_id); $schedule_time = $schedule[1]; $this->_db->query("DELETE FROM fm_event_receipt WHERE receipt_time = {$schedule_time} AND event_id = {$event_id}", __LINE__, __FILE__); $receipt['error'][] = array('msg' => "{$event_id}::{$schedule_time}"); } $entry_date = phpgwapi_datetime::user_localtime(); foreach ($add_receipt as $schedule_time_id => $event_id) { $schedule = explode('_', $schedule_time_id); $schedule_time = $schedule[1]; $vals = array($event_id, $schedule_time, $this->account, $entry_date); $vals = $this->_db->validate_insert($vals); $this->_db->query("INSERT INTO fm_event_receipt (event_id, receipt_time, user_id, entry_date) VALUES ({$vals})", __LINE__, __FILE__); $receipt['message'][] = array('msg' => "{$event_id}::{$schedule_time}"); } $this->_db->transaction_commit(); return $receipt; }
function display_week($startdate, $weekly, $cellclass, $display_name = false, $owner = 0, $monthstart = 0, $monthend = 0) { if ($owner == 0) { $owner = $GLOBALS['phpgw_info']['user']['account_id']; } $temp_owner = $this->bo->owner; $str = ''; $p = CreateObject('phpgwapi.Template', $this->template_dir); $p->set_unknowns('keep'); $p->set_file(array('month_header' => 'month_header.tpl', 'month_day' => 'month_day.tpl')); $p->set_block('month_header', 'monthly_header', 'monthly_header'); $p->set_block('month_header', 'month_column', 'month_column'); $p->set_block('month_day', 'month_daily', 'month_daily'); $p->set_block('month_day', 'day_event', 'day_event'); $p->set_block('month_day', 'event', 'event'); $p->set_var(array('extra' => '', 'cssclass' => $cellclass)); if ($display_name) { $p->set_var('column_data', $this->bo->contacts->get_name_of_person_id($owner)); $p->parse('column_header', 'month_column', True); } $today = date('Ymd', phpgwapi_datetime::user_localtime()); $daily = $this->set_week_array($startdate - phpgwapi_datetime::user_timezone(), $cellclass, $weekly); foreach ($daily as $date => $day_params) { $year = intval(substr($date, 0, 4)); $month = intval(substr($date, 4, 2)); $day = intval(substr($date, 6, 2)); $var = array('column_data' => '', 'extra' => ''); $p->set_var($var); if ($weekly || $date >= $monthstart && $date <= $monthend) { if ($day_params['new_event']) { $new_event_link = ' <a href="' . $this->page('add', array('date' => $date)) . '">' . '<img src="' . $GLOBALS['phpgw']->common->image('calendar', 'new') . '" width="10" height="10" alt="' . lang('New Entry') . '" title="' . lang('New Entry') . '" align="center">' . '</a>'; $day_number = '<a href="' . $this->page('day', array('date' => $date)) . '">' . $day . '</a>'; } else { $new_event_link = ''; $day_number = $day; } $var = array('extra' => $day_params['extra'], 'new_event_link' => $new_event_link, 'day_number' => $day_number); if ($day_params['week']) { $tmp_str = $this->week_type == 'new' ? ' ' : ' '; $var['new_event_link'] .= '<font size="-2">' . $tmp_str . '<a href="' . $this->page('week_new', array('date' => $date)) . '">' . $day_params['week'] . '</a>'; } $p->set_var($var); if (isset($day_params['holidays']) && is_array($day_params['holidays'])) { foreach ($day_params['holidays'] as $key => $value) { $var = array('day_events' => "<span class=\"holiday\">{$value}</span>"); $this->output_template_array($p, 'daily_events', 'event', $var); } } if ($day_params['appts'] || $this->week_type == 'new') { $p->set_var(array('events' => '')); $events = isset($this->bo->cached_events[$date]) ? $this->bo->cached_events[$date] : ''; if ($this->week_type != 'new') { foreach ($events as $event) { if ($this->bo->rejected_no_show($event) || !$this->bo->check_perms(PHPGW_ACL_READ)) { continue; // user does not want to see rejected events } $p->set_var('day_events', $this->link_to_entry($event, $month, $day, $year)); $p->parse('events', 'event', True); $p->set_var('day_events', ''); } } elseif ($this->week_type == 'new') { $day_to_display = array('year' => $year, 'month' => $month, 'day' => $day); $p->set_var('day_events', $this->print_day($day_to_display)); $p->parse('events', 'event', True); $p->set_var('day_events', ''); } } $p->parse('daily_events', 'day_event', True); $p->parse('column_data', 'month_daily', True); $p->set_var('daily_events', ''); $p->set_var('events', ''); } $p->parse('column_header', 'month_column', True); $p->set_var('column_data', ''); } $this->bo->owner = $temp_owner; return $p->fp('out', 'monthly_header'); }
function import($mime_msg = '', $isReturn = false, $timestamp = 0, $id = 0) { $this->line = 0; if (is_array($_FILES['uploadedfile']) && $_FILES['uploadedfile']['name'] != '') { $filename = $this->import_file(); $fp = fopen($filename, 'rt'); $mime_msg = explode("\n", fread($fp, filesize($filename))); fclose($fp); unlink($filename); } elseif (!$mime_msg) { if ($isReturn) { return false; } $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'calendar.uiicalendar.import', 'action' => 'GetFile')); } if (!isset($GLOBALS['uicalendar']) || !is_object($GLOBALS['uicalendar'])) { if (!isset($GLOBALS['bocalendar']) || !is_object($GLOBALS['bocalendar'])) { $so_event = createobject('calendar.socalendar', array('owner' => 0, 'filter' => '', 'category' => '')); } else { $so_event =& $GLOBALS['bocalendar']->so; } } else { $so_event =& $GLOBALS['uicalendar']->bo->so; } $datetime_vars = array('start' => 'dtstart', 'end' => 'dtend', 'modtime' => 'dtstamp', 'modtime' => 'last_modified'); $date_array = array('Y' => 'year', 'm' => 'month', 'd' => 'mday', 'H' => 'hour', 'i' => 'min', 's' => 'sec'); // time limit should be controlled elsewhere @set_time_limit(0); $gmt_offset = date('O', phpgwapi_datetime::user_localtime()); // offset to GMT $offset_mins = intval(substr($gmt_offset, 1, 2)) * 60 + intval(substr($gmt_offset, 3, 2)); $users_email = ExecMethod('phpgwapi.contacts.get_email', $GLOBALS['phpgw_info']['user']['person_id']); $cats = CreateObject('phpgwapi.categories'); $ical = $this->parse($mime_msg); switch ($ical['version']['value']) { case '1.0': $cat_sep = ';'; break; case '2.0': default: $cat_sep = ','; break; } $c_events = count($ical['event']); for ($i = 0; $i < $c_events; $i++) { if ($ical['event'][$i]['uid']['value']) { $uid_exists = $so_event->find_uid($ical['event'][$i]['uid']['value']); } else { $uid_exists = false; } if ($id > 0) { $uid_exists = $so_event->find_cal_id($id); } if ($uid_exists) { $event = $so_event->read_entry($uid_exists); $this->check_owner($event, $ical['event'][$i], $so_event); $event = $so_event->get_cached_event(); $so_event->add_entry($event); // $event = $so_event->get_cached_event(); } else { $so_event->event_init(); $so_event->add_attribute('id', 0); $so_event->add_attribute('reference', 0); } if ($ical['event'][$i]['summary']['value']) { $so_event->set_title($ical['event'][$i]['summary']['value']); } if ($ical['event'][$i]['description']['value']) { $so_event->set_description($ical['event'][$i]['description']['value']); } if ($ical['event'][$i]['location']['value']) { $so_event->add_attribute('location', $ical['event'][$i]['location']['value']); } if (isset($ical['event'][$i]['priority'])) { $so_event->add_attribute('priority', $ical['event'][$i]['priority']); } else { $so_event->add_attribute('priority', 2); } if (!isset($ical['event'][$i]['class'])) { $ical['event'][$i]['class'] = 1; } $so_event->set_class($ical['event'][$i]['class']); // Handle alarm import start if (count($ical['event'][$i]['alarm']) > 0) { for ($a = 0; $a < count($ical['event'][$i]['alarm']); ++$a) { $alarm_prior = substr($ical['event'][$i]['alarm'][$a]['trigger']['value'], 3); if ($string_pos = strpos($alarm_prior, "D")) { $alarm_prior_days = substr($alarm_prior, 0, $string_pos); $alarm_prior = substr($alarm_prior, $string_pos + 1); } if ($string_pos = strpos($alarm_prior, "H")) { $alarm_prior_hours = substr($alarm_prior, 0, $string_pos); $alarm_prior = substr($alarm_prior, $string_pos + 1); } if ($string_pos = strpos($alarm_prior, "M")) { $alarm_prior_min = substr($alarm_prior, 0, $string_pos); } $imported_alarm[$a] = array(time => mktime($ical['event'][$i]['dtstart']['hour'] - $alarm_prior_hours, $ical['event'][$i]['dtstart']['min'] - $alarm_prior_min + $offset_mins, $ical['event'][$i]['dtstart']['sec'], $ical['event'][$i]['dtstart']['month'], $ical['event'][$i]['dtstart']['mday'] - $alarm_prior_days, $ical['event'][$i]['dtstart']['year']), owner => $GLOBALS['phpgw_info']['user']['account_id'], enabled => 1); } $so_event->add_attribute('alarm', $imported_alarm); } // Handle alarm import end @reset($datetime_vars); while (list($e_datevar, $i_datevar) = each($datetime_vars)) { if (isset($ical['event'][$i][$i_datevar])) { $temp_time = $so_event->maketime($ical['event'][$i][$i_datevar]) + phpgwapi_datetime::user_timezone(); @reset($date_array); while (list($key, $var) = each($date_array)) { $event[$e_datevar][$var] = intval(date($key, $temp_time)); } $so_event->set_date($e_datevar, $event[$e_datevar]['year'], $event[$e_datevar]['month'], $event[$e_datevar]['mday'], $event[$e_datevar]['hour'], $event[$e_datevar]['min'] + $offset_mins, $event[$e_datevar]['sec']); } } // If a Timestamp is given from the sync module add it to the event if ($timestamp > 0) { $so_event->set_date("timestamp", date('Y', $timestamp), date('m', $timestamp), date('d', $timestamp), date('H', $timestamp), date('i', $timestamp), date('s', $timestamp)); } if (!isset($ical['event'][$i]['categories']['value']) || !$ical['event'][$i]['categories']['value']) { $so_event->set_category(0); } else { $ical_cats = array(); if (strpos($ical['event'][$i]['categories']['value'], $cat_sep)) { $ical_cats = explode($cat_sep, $ical['event'][$i]['categories']['value']); } else { $ical_cats[] = $ical['event'][$i]['categories']['value']; } @reset($ical_cats); $cat_id_nums = array(); while (list($key, $cat) = each($ical_cats)) { if (!$cats->exists('appandmains', $cat)) { $cats->add(array('name' => $cat, 'descr' => $cat, 'parent' => '', 'access' => 'private', 'data' => '')); } // $temp_id = $cats->name2id($cat); // echo 'Category Name : '.$cat.' : Category ID :'.$temp_id."<br />\n"; // $cat_id_nums[] = $temp_id; $cat_id_nums[] = $cats->name2id($cat); } @reset($cat_id_nums); if (count($cat_id_nums) > 1) { $so_event->set_category(implode($cat_id_nums, ',')); } else { $so_event->set_category($cat_id_nums[0]); } } //rrule $c_rrules = count($ical['event'][$i]['rrule']); for ($r = 0; $r < $c_rrules; ++$r) { if (isset($ical['event'][$i]['rrule'][$r])) { // recur_enddate if (isset($ical['event'][$i]['rrule'][$r]['until'])) { $recur_enddate['year'] = intval($ical['event'][$i]['rrule'][$r]['until']['year']); $recur_enddate['month'] = intval($ical['event'][$i]['rrule'][$r]['until']['month']); $recur_enddate['mday'] = intval($ical['event'][$i]['rrule'][$r]['until']['mday']); } else { if ($ical['event'][$i]['rrule'][$r]['count']) { $count = ($ical['event'][$i]['rrule'][$r]['count'] - 1) * $ical['event'][$i]['rrule'][$r]['interval']; switch ($ical['event'][$i]['rrule'][$r]['freq']) { case DAILY: $recur_enddate['year'] = $ical['event'][$i]['dtstart']['year']; $recur_enddate['month'] = $ical['event'][$i]['dtstart']['month']; // If an intervall is submittet we have to multiply the count with it to get the right enddate if ($ical['event'][$i]['rrule'][$r]['interval'] > 1) { $recur_enddate['mday'] = $ical['event'][$i]['dtstart']['mday'] + $count; } else { $recur_enddate['mday'] = $ical['event'][$i]['dtstart']['mday'] + $count; } // Only Weekdays means that that MO - FR are submitted meaning 5 days // so if tht occurs treat it that way if (count(explode(",", $ical['event'][$i]['rrule'][$r]['byday'])) == 5) { // Calculate over how many weeks the count lasts and add 2 days to every week for ($c = 0; $c < floor($count / 5); ++$c) { $weekend += 2; } $recur_enddate['mday'] = $ical['event'][$i]['dtstart']['mday'] + $count + $weekend; } break; case WEEKLY: $weekday_array = explode(",", $ical['event'][$i]['rrule'][$r]['byday']); $count_weekdays = count($weekday_array); $count_weeks = intval(floor($count / $count_weekdays)); if ($weekday_array['0'] == "SU") { $temp_array = $weekday_array; for ($t = 1; $t < count($weekday_array); ++$t) { $weekday_array[$t - 1] = $temp_array[$t]; } array_push($weekday_array, "SU"); } // If we have more than one week and the modulo is 0 the enddate is exactly $count_weeks later if ($count_weekdays > 1 && $count % $count_weekdays == 0) { $recur_enddate['mday'] = $ical['event'][$i]['dtstart']['mday'] + $count_weeks * 7; } else { if ($count_weekdays > 1) { // retrieve information about startdate $start_date = getdate(mktime(0, 0, 0, $ical['event'][$i]['dtstart']['month'], $ical['event'][$i]['dtstart']['mday'], $ical['event'][$i]['dtstart']['year'])); // Get the Weekday (MO, TU, WE ...) $start_weekday = strtoupper(substr($start_date['weekday'], 0, 2)); // Search for its position in array and add the amount of occuring dates till the next week $weekday_position = intval(array_search($start_weekday, $weekday_array)) + intval($count % $count_weekdays); // if the position exceeds array count start at the beginning of the array if ($weekday_position + 1 > count($weekday_array)) { $weekday_position = $weekday_position % count($weekday_array); ++$count_weeks; } $last_occurence_weekday = $weekday_array[$weekday_position]; switch ($last_occurence_weekday) { case MO: $last_weekday = 1; break; case TU: $last_weekday = 2; break; case WE: $last_weekday = 3; break; case TH: $last_weekday = 4; break; case FR: $last_weekday = 5; break; case SA: $last_weekday = 6; break; case SU: $last_weekday = 7; break; } $diff = $last_weekday - $start_date['wday']; $recur_enddate['mday'] = $ical['event'][$i]['dtstart']['mday'] + $count_weeks * 7 + $diff; } else { $recur_enddate['mday'] = $ical['event'][$i]['dtstart']['mday'] + $count * 7; } } $recur_enddate['year'] = $ical['event'][$i]['dtstart']['year']; $recur_enddate['month'] = $ical['event'][$i]['dtstart']['month']; break; case MONTHLY: // If the recurrence is monthly by monthday if ($ical['event'][$i]['rrule'][$r]['bymonthday']) { $recur_enddate['month'] = $ical['event'][$i]['dtstart']['month'] + $count; $recur_enddate['year'] = $ical['event'][$i]['dtstart']['year']; $recur_enddate['mday'] = $ical['event'][$i]['dtstart']['mday']; } else { $recur_enddate['month'] = $ical['event'][$i]['dtstart']['month'] + $count; $recur_enddate['year'] = $ical['event'][$i]['dtstart']['year']; $num_weekday_start = date("w", mktime(0, 0, 0, $ical['event'][$i]['dtstart']['month'], $ical['event'][$i]['dtstart']['mday'], $ical['event'][$i]['dtstart']['year'])); $num_first_weekday_in_endmonth = date("w", mktime(0, 0, 0, $recur_enddate['month'], 1, $recur_enddate['year'])); // calculate the first occurrence of the searched weekday $first_searched_weekday_in_month = 7 - $num_first_weekday_in_endmonth + $num_weekday_start; // because we are in the first week we have to subtract 1 from the count to get the correct enddate $which_week = ceil($ical['event'][$i]['dtstart']['mday'] / 7) - 1; $recur_enddate['mday'] = 1 + $first_searched_weekday_in_month + 7 * $which_week; } break; case YEARLY: if ($ical['event'][$i]['rrule'][$r]['bymonthday']) { $recur_enddate['year'] = $ical['event'][$i]['dtstart']['year'] + $count; $recur_enddate['month'] = $ical['event'][$i]['dtstart']['month']; $recur_enddate['mday'] = $ical['event'][$i]['dtstart']['mday']; } else { $recur_enddate['year'] = $ical['event'][$i]['dtstart']['year'] + $count; $recur_enddate['month'] = $ical['event'][$i]['dtstart']['month']; $num_weekday_start = date("w", mktime(0, 0, 0, $ical['event'][$i]['dtstart']['month'], $ical['event'][$i]['dtstart']['mday'], $ical['event'][$i]['dtstart']['year'])); $num_first_weekday_in_endmonth = date("w", mktime(0, 0, 0, $recur_enddate['month'], 1, $recur_enddate['year'])); // calculate the first occurrence of the searched weekday $first_searched_weekday_in_month = 7 - $num_first_weekday_in_endmonth + $num_weekday_start; // because we are in the first week we have to subtract 1 from the count to get the correct enddate $which_week = ceil($ical['event'][$i]['dtstart']['mday'] / 7) - 1; $recur_enddate['mday'] = 1 + $first_searched_weekday_in_month + 7 * $which_week; } break; } } else { $recur_enddate['year'] = 0; $recur_enddate['month'] = 0; $recur_enddate['mday'] = 0; } } // recur_data $recur_data = 0; if (isset($ical['event'][$i]['rrule'][$r]['byday'])) { $week_days = array(MCAL_M_SUNDAY => 'SU', MCAL_M_MONDAY => 'MO', MCAL_M_TUESDAY => 'TU', MCAL_M_WEDNESDAY => 'WE', MCAL_M_THURSDAY => 'TH', MCAL_M_FRIDAY => 'FR', MCAL_M_SATURDAY => 'SA'); @reset($week_days); while (list($key, $val) = each($week_days)) { if (strpos(' ' . $ical['event'][$i]['rrule'][$r]['byday'], $val)) { $recur_data += $key; } } } elseif (isset($ical['event'][$i]['rrule'][$r]['wkst'])) { $week_days = array(MCAL_M_SUNDAY => 'SU', MCAL_M_MONDAY => 'MO', MCAL_M_TUESDAY => 'TU', MCAL_M_WEDNESDAY => 'WE', MCAL_M_THURSDAY => 'TH', MCAL_M_FRIDAY => 'FR', MCAL_M_SATURDAY => 'SA'); @reset($week_days); while (list($key, $val) = each($week_days)) { if (strpos(' ' . $ical['event'][$i]['rrule'][$r]['wkst'], $val)) { $recur_data += $key; } } } // interval if (!isset($ical['event'][$i]['rrule'][$r]['interval'])) { $interval = 0; } else { if ($ical['event'][$i]['rrule'][$r]['interval'] == 1) { $interval = 0; } else { $interval = intval($ical['event'][$i]['rrule'][$r]['interval']); } } // recur_type switch ($ical['event'][$i]['rrule'][$r]['freq']) { case DAILY: $so_event->set_recur_daily($recur_enddate['year'], $recur_enddate['month'], $recur_enddate['mday'], $interval, $recur_data); break; case WEEKLY: $so_event->set_recur_weekly($recur_enddate['year'], $recur_enddate['month'], $recur_enddate['mday'], $interval, $recur_data); break; case MONTHLY: if ($ical['event'][$i]['rrule'][$r]['bymonthday']) { $so_event->set_recur_monthly_mday($recur_enddate['year'], $recur_enddate['month'], $recur_enddate['mday'], $interval); } else { // If the bymonthday value contains a "-" it's meant to be the last weekday in month so tell set_recur_monthly_wday // to set the recur_last_weekday_in_month to true (1) $this->debug("strstr ergebnis:" . strlen($ical['event'][$i]['rrule'][$r]['byday']), __LINE__, __FILE__); if (strlen($ical['event'][$i]['rrule'][$r]['byday']) > 3) { $so_event->set_recur_monthly_wday($recur_enddate['year'], $recur_enddate['month'], $recur_enddate['mday'], $interval, 1); } else { $so_event->set_recur_monthly_wday($recur_enddate['year'], $recur_enddate['month'], $recur_enddate['mday'], $interval, 0); } } break; case YEARLY: if ($ical['event'][$i]['rrule'][$r]['bymonthday']) { $so_event->set_recur_yearly($recur_enddate['year'], $recur_enddate['month'], $recur_enddate['mday'], $interval); } else { if (strlen($ical['event'][$i]['rrule'][$r]['byday']) > 3) { $so_event->set_recur_yearly_wday($recur_enddate['year'], $recur_enddate['month'], $recur_enddate['mday'], $interval, 1); } else { $so_event->set_recur_yearly_wday($recur_enddate['year'], $recur_enddate['month'], $recur_enddate['mday'], $interval, 0); } } break; } } else { $so_event->set_recur_none(); } if ($ical['event'][$i]['rrule'][$r]['count'] > 0) { $count = $ical['event'][$i]['rrule'][$r]['count']; } } // exdate $c_exdate = count($ical['event'][$i]['exdate']['0']['exdate']); if ($c_exdate > 0) { $ar_exdate = array(); for ($e = 0; $e < $c_exdate; ++$e) { $ical['event'][$i]['exdate']['0']['exdate'][$e]['value']['min'] += $offset_mins; array_push($ar_exdate, $so_event->maketime($ical['event'][$i]['exdate']['0']['exdate'][$e]['value'])); } $so_event->add_attribute('recur_exception', $ar_exdate); } // rdate $c_rdate = count($ical['event'][$i]['rdate']['0']); if ($c_rdate > 0) { $ar_rdate = array(); for ($e = 0; $e < $c_rdate; ++$e) { $ical['event'][$i]['rdate']['0']['rdate']['value']['min'] += $offset_mins; $rdate_start = $ical['event'][$i]['rdate']['0']['rdate']['value']; $ical['event'][$i]['rdate']['0']['rdate']['value']['hour'] += $ical['event'][$i]['dtend']['hour'] - $ical['event'][$i]['dtstart']['hour']; $ical['event'][$i]['rdate']['0']['rdate']['value']['min'] += $ical['event'][$i]['dtend']['min'] - $ical['event'][$i]['dtstart']['min']; +$offset_mins; $ical['event'][$i]['rdate']['0']['rdate']['value']['sec'] += $ical['event'][$i]['dtend']['sec'] - $ical['event'][$i]['dtstart']['sec']; $rdate_end = $ical['event'][$i]['rdate']['0']['rdate']['value']; $submit = $so_event->maketime($rdate_start) . "/" . $so_event->maketime($rdate_end); array_push($ar_rdate, $submit); } $so_event->add_attribute('recur_date', $ar_rdate); } // Owner if (!isset($ical['event'][$i]['organizer']) || isset($ical['event'][$i]['organizer']) && $this->is_owner($ical['event'][$i]['organizer'])) { $so_event->add_attribute('owner', $GLOBALS['phpgw_info']['user']['account_id']); $so_event->add_attribute('participants', 'A', intval($GLOBALS['phpgw_info']['user']['account_id'])); } else { // workaround for ical without organizer -> set current user as organizer (without this workaround, the entry wouldnt be shown in the calendar!) $so_event->add_attribute('participants', 'A', intval($GLOBALS['phpgw_info']['user']['account_id'])); } // Attendee // todo $event = $so_event->get_cached_event(); $so_event->add_entry($event); unset($this->event); } if ($isReturn == true) { if (isset($event['id'])) { return $event['id']; } else { return false; } } $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'calendar.uicalendar.view', 'cal_id' => $event['id'])); }
<?php /**************************************************************************\ * phpGroupWare - Calendar * * http://www.phpgroupware.org * * Based on Webcalendar by Craig Knudsen <*****@*****.**> * * http://www.radix.net/~cknudsen * * Modified by Mark Peters <*****@*****.**> * * -------------------------------------------- * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * \**************************************************************************/ /* $Id$ */ $GLOBALS['phpgw_info']['flags'] = array('currentapp' => 'calendar', 'noheader' => true, 'nonavbar' => true, 'noappheader' => true, 'noappfooter' => true, 'nofooter' => true); include '../header.inc.php'; phpgw::import_class('phpgwapi.datetime'); $cal = createObject('calendar.uicalendar'); $cal->index(array('menuaction' => 'calendar.uicalendar.index', 'date' => date('Ymd', phpgwapi_datetime::user_localtime())));