Beispiel #1
0
 public function createAlarms($alarms, &$vevent)
 {
     foreach ($alarms as $va) {
         $valarm = new valarm();
         $valarm->setProperty('ACTION', self::codeAlarmAction($va['type']));
         $duration = array();
         switch ($va['unit']) {
             case 'h':
                 $duration['hour'] = $va['time'];
                 break;
             case 'm':
                 $duration['min'] = $va['time'];
                 break;
             case 's':
                 $duration['sec'] = $va['time'];
                 break;
         }
         $valarm->setProperty('trigger', $duration);
         $vevent->setComponent($valarm);
     }
 }
Beispiel #2
0
// set some X-properties, name, content.. .
$v->setProperty('X-WR-CALDESC', 'Description of the calendar');
$v->setProperty('X-WR-TIMEZONE', 'Europe/Stockholm');
$e = new vevent();
// initiate EVENT
$e->setProperty('categories', 'FAMILY');
// catagorize
$e->setProperty('dtstart', 2007, 12, 24, 19, 30, 00);
// 24 dec 2007 19.30
$e->setProperty('duration', 0, 0, 3);
// 3 hours
$e->setProperty('description', 'x-mas evening - diner');
// describe the event
$e->setProperty('location', 'Home');
// locate the event
$a = new valarm();
// initiate ALARM
$a->setProperty('action', 'DISPLAY');
// set what to do
$a->setProperty('description', 'Buy X-mas gifts');
// describe alarm
$a->setProperty('trigger', array('week' => 1));
// set trigger one week before
$e->setComponent($a);
// add alarm component to event component as subcomponent
$v->setComponent($e);
// add event component to calendar
/* alt. production */
// $v->returnCalendar();                          // generate and redirect output to user browser
/* alt. dev. and test */
$str = $v->createCalendar();
Beispiel #3
0
 function converttoical($icalcomponent, $message, $mapping, $allday = false)
 {
     foreach ($mapping as $k => $e) {
         if (isset($message->{$e}[0])) {
             $val = $message->{$e}[0];
             if (!is_object($val) && !is_array($val)) {
                 $val = trim($val);
             }
             if ($val != '') {
                 $k = strtoupper($k);
                 // if found $k in message convert and put in event
                 if ($e[1] == 0) {
                     $icalcomponent->setProperty($k, $val);
                 }
                 if ($e[1] == 1) {
                     $val = trim($val);
                     switch ($k) {
                         case "CLASS":
                             switch ($val) {
                                 case "0":
                                     $val = "PUBLIC";
                                     break;
                                 case "1":
                                     $val = "PRIVATE";
                                     break;
                                 case "2":
                                     $val = "PRIVATE";
                                     break;
                                 case "3":
                                     $val = "CONFIDENTIAL";
                                     break;
                             }
                             break;
                         case "STATUS":
                             switch ($val) {
                                 case "1":
                                     $val = "TENTATIVE";
                                     break;
                                 case "3":
                                     $val = "CONFIRMED";
                                     break;
                                 case "5":
                                     $val = "CANCELLED";
                                     break;
                             }
                             break;
                         case "TRANSP":
                             switch ($val) {
                                 case "0":
                                     $val = "TRANSPARENT";
                                     break;
                                 case "2":
                                     $val = "OPAQUE";
                                     break;
                                 default:
                                     $val = "OPAQUE";
                             }
                             break;
                         case "PRIORITY":
                             switch ($val) {
                                 case "0":
                                     $val = "9";
                                     break;
                                 case "1":
                                     $val = "5";
                                     break;
                                 case "2":
                                     $val = "1";
                                     break;
                                 default:
                                     $val = "";
                             }
                             break;
                     }
                     $icalcomponent->setProperty($k, $val);
                 }
                 if ($e[1] == 2) {
                     $icalcomponent->setProperty($k, $val);
                 }
                 if ($e[1] == 3) {
                     // convert to date
                     $val = $this->parseDate($val);
                     if ($allday) {
                         $icalcomponent->setProperty($k, $val, array('VALUE' => 'DATE'));
                     } else {
                         $icalcomponent->setProperty($k, $val);
                     }
                 }
                 if ($e[1] == 4) {
                     // extract organizers name and email
                     if (trim($val) != '') {
                         $icalcomponent->setProperty($k, $val);
                     }
                 }
                 if ($e[1] == 5) {
                     // recurrence?
                     switch (trim($val->type)) {
                         case "0":
                             $args['FREQ'] = "DAILY";
                             break;
                         case "1":
                             $args['FREQ'] = "WEEKLY";
                             break;
                         case "2":
                             $args['FREQ'] = "MONTHLY";
                             break;
                         case "3":
                             $args['FREQ'] = "MONTHLY";
                             break;
                         case "5":
                             $args['FREQ'] = "YEARLY";
                             break;
                         case "6":
                             $args['FREQ'] = "YEARLY";
                             break;
                     }
                     if (isset($val->dayofweek) && $val->dayofweek != "" && is_numeric($val->dayofweek)) {
                         $tmp = "0000000" . decbin($val->dayofweek);
                         $args["BYDAY"] = array();
                         $len = strlen($tmp);
                         if (isset($val->weekofmonth) && $val->weekofmonth != "" && is_numeric($val->weekofmonth)) {
                             $wn = $val->weekofmonth;
                             if (substr($tmp, $len - 1, 1) == "1") {
                                 array_push($args["BYDAY"], array($wn, "DAY" => "SU"));
                             }
                             if (substr($tmp, $len - 2, 1) == "1") {
                                 array_push($args["BYDAY"], array($wn, "DAY" => "MO"));
                             }
                             if (substr($tmp, $len - 3, 1) == "1") {
                                 array_push($args["BYDAY"], array($wn, "DAY" => "TU"));
                             }
                             if (substr($tmp, $len - 4, 1) == "1") {
                                 array_push($args["BYDAY"], array($wn, "DAY" => "WE"));
                             }
                             if (substr($tmp, $len - 5, 1) == "1") {
                                 array_push($args["BYDAY"], array($wn, "DAY" => "TH"));
                             }
                             if (substr($tmp, $len - 6, 1) == "1") {
                                 array_push($args["BYDAY"], array($wn, "DAY" => "FR"));
                             }
                             if (substr($tmp, $len - 7, 1) == "1") {
                                 array_push($args["BYDAY"], array($wn, "DAY" => "SA"));
                             }
                         } else {
                             if (substr($tmp, $len - 1, 1) == "1") {
                                 array_push($args["BYDAY"], array("DAY" => "SU"));
                             }
                             if (substr($tmp, $len - 2, 1) == "1") {
                                 array_push($args["BYDAY"], array("DAY" => "MO"));
                             }
                             if (substr($tmp, $len - 3, 1) == "1") {
                                 array_push($args["BYDAY"], array("DAY" => "TU"));
                             }
                             if (substr($tmp, $len - 4, 1) == "1") {
                                 array_push($args["BYDAY"], array("DAY" => "WE"));
                             }
                             if (substr($tmp, $len - 5, 1) == "1") {
                                 array_push($args["BYDAY"], array("DAY" => "TH"));
                             }
                             if (substr($tmp, $len - 6, 1) == "1") {
                                 array_push($args["BYDAY"], array("DAY" => "FR"));
                             }
                             if (substr($tmp, $len - 7, 1) == "1") {
                                 array_push($args["BYDAY"], array("DAY" => "SA"));
                             }
                         }
                     }
                     if (isset($val->dayofmonth) && $val->dayofmonth != "" && is_numeric($val->dayofmonth)) {
                         $args['BYMONTHDAY'] = $val->dayofmonth;
                     }
                     if (isset($val->monthofyear) && $val->monthofyear != "" && is_numeric($val->monthofyear)) {
                         $args['BYMONTH'] = $val->monthofyear;
                     }
                     $args['INTERVAL'] = 1;
                     if (isset($val->interval) && $val->interval != "") {
                         $args['INTERVAL'] = $val->interval;
                     }
                     if (isset($val->until) && $val->until != "") {
                         $args['UNTIL'] = $this->parseGMTDate($val->until);
                     }
                     if (isset($val->occurrences) && $val->occurrences != "") {
                         $args['COUNT'] = $val->occurrences;
                     }
                     $icalcomponent->setProperty($k, $args);
                 }
                 if ($e[1] == 6) {
                     if ($val != "") {
                         $val = $this->parseDate($val);
                         $icalcomponent->setProperty($k, $val);
                         $icalcomponent->setProperty("PERCENT_COMPLETE", 100);
                         $icalcomponent->setProperty("STATUS", "COMPLETED");
                     }
                 }
                 if ($e[1] == 7) {
                     $valarm = new valarm();
                     $valarm->setProperty("ACTION", "DISPLAY");
                     $valarm->setProperty("DESCRIPTION", $icalcomponent->getProperty("SUMMARY"));
                     $valarm->setProperty("TRIGGER", "-PT0H" . $val . "M0S");
                     $icalcomponent->setComponent($valarm);
                 }
                 if ($e[1] == 8) {
                     $valarm = new valarm();
                     $valarm->setProperty("ACTION", "DISPLAY");
                     $valarm->setProperty("DESCRIPTION", $icalcomponent->getProperty("SUMMARY"));
                     $valarm->setProperty("TRIGGER", array("timestamp" => $val));
                     $icalcomponent->setComponent($valarm);
                 }
                 if ($e[1] == 9 && is_array($val)) {
                     foreach ($val as $att) {
                         $icalcomponent->setProperty($k, $att->email, array("CN" => $att->name));
                     }
                 }
                 if ($e[1] == 10) {
                     require_once 'z_RTF.php';
                     $rtfparser = new rtf();
                     $rtfparser->loadrtf(base64_decode($val));
                     $rtfparser->output("ascii");
                     $rtfparser->parse();
                     $icalcomponent->setProperty($k, $rtfparser->out);
                 }
             }
         }
     }
     return $icalcomponent;
 }
 /**
  * @param array $start
  * @param array $end
  * @param string $subject
  * @param bool $allday
  * @param string $description
  * @param string $location
  * @param null $color
  * @param string $timezone
  * @param bool $notification
  * @param null $notification_type
  * @param null $notification_value
  * @return array|string
  */
 public function addItem($start, $end, $subject, $allday = false, $description = "", $location = "", $color = null, $timezone = "", $notification = true, $notification_type = null, $notification_value = null)
 {
     $a = get_app();
     $v = new vcalendar();
     $v->setConfig('unique_id', $a->get_hostname());
     $v->setProperty('method', 'PUBLISH');
     $v->setProperty("x-wr-calname", "AnimexxCal");
     $v->setProperty("X-WR-CALDESC", "Animexx Calendar");
     $v->setProperty("X-WR-TIMEZONE", $a->timezone);
     $vevent = dav_create_vevent($start, $end, $allday);
     $vevent->setLocation(icalendar_sanitize_string($location));
     $vevent->setSummary(icalendar_sanitize_string($subject));
     $vevent->setDescription(icalendar_sanitize_string($description));
     if (!is_null($color) && $color >= 0) {
         $vevent->setProperty("X-ANIMEXX-COLOR", $color);
     }
     if ($notification && $notification_type == null) {
         if ($allday) {
             $notification_type = "hour";
             $notification_value = 24;
         } else {
             $notification_type = "minute";
             $notification_value = 60;
         }
     }
     if ($notification) {
         $valarm = new valarm();
         $valarm->setTrigger($notification_type == "year" ? $notification_value : 0, $notification_type == "month" ? $notification_value : 0, $notification_type == "day" ? $notification_value : 0, $notification_type == "week" ? $notification_value : 0, $notification_type == "hour" ? $notification_value : 0, $notification_type == "minute" ? $notification_value : 0, $notification_type == "second" ? $notification_value : 0, true, $notification_value > 0);
         $valarm->setAction("DISPLAY");
         $valarm->setDescription($subject);
         $vevent->setComponent($valarm);
     }
     $v->setComponent($vevent);
     $ical = $v->createCalendar();
     $obj_id = trim($vevent->getProperty("UID"));
     $calendarBackend = new Sabre_CalDAV_Backend_Std();
     $calendarBackend->createCalendarObject($this->getNamespace() . "-" . $this->namespace_id, $obj_id . ".ics", $ical);
     return $obj_id . ".ics";
 }
 /**
  * Save client event
  * @param web request $request
  */
 public function executeUpdateEvent($request)
 {
     $sf_user = $this->getUser();
     $sf_user_id = $sf_user->getGuardUser()->getId();
     $client_id = $request->getParameter('id');
     $client_profile = ProfilePeer::retrieveByPK($client_id);
     $sfguard_user_profile = $sf_user->getProfile();
     $sfguard_fullname = $sfguard_user_profile->getFullname();
     $sfguard_email = $sfguard_user_profile->getEmail();
     $start_hour = $request->getParameter('start_hour');
     $start_min = $request->getParameter('start_min');
     $time_mode = $request->getParameter('start_mn');
     $client_branch_id = BranchUsersPeer::getUserBranchId($client_profile->getUserId());
     $hour = sfConfig::get('mod_client_outlook_shour');
     $sc_hour = sfConfig::get('mod_client_secondhalf_shhour');
     if ($request->isMethod('post')) {
         $event_id = $this->getRequestParameter('event_id');
         $event_details = '';
         if ($event_id) {
             $event_details = pmProjectObjectsPeer::retrieveByPK($event_id);
             $this->form = new ClientEventForm($event_details);
         } else {
             $this->form = new ClientEventForm();
         }
         $event_data = $request->getParameter('pm_project_objects');
         if ($time_mode == 'AM') {
             $start_hour_value = $start_hour == 11 ? '00' : $hour[$start_hour];
             $date_field_1 = $event_data['date_field_1'] . ' ' . $start_hour_value . ':' . $start_min . ':00';
         } elseif ($time_mode == 'PM') {
             $start_hour_value = $start_hour == 11 ? $hour[$start_hour] : $sc_hour[$start_hour];
             $date_field_1 = $event_data['date_field_1'] . ' ' . $start_hour_value . ':' . $start_min . ':00';
         }
         $event_data['module'] = 'client event';
         $event_data['tree_left'] = $client_branch_id;
         $event_data['tree_right'] = $sf_user_id;
         $event_data['integer_field_2'] = $client_id;
         $event_data['date_field_1'] = $date_field_1;
         $event_data['contract_id'] = $request->getParameter('contract_id');
         $event_data['created_by_id'] = $sf_user_id;
         $event_data['updated_by_id'] = $sf_user_id;
         $this->form->bind($event_data);
         if ($this->form->isValid()) {
             $client_event = $this->form->save();
             $client_event->setParentId($client_event->getId());
             $client_event->setUpdatedAt($date_field_1);
             $client_event->save();
             // create instance of event class and add client event in event table
             $event = '';
             $c = new Criteria();
             $c->add(EventPeer::CEVENT_ID, $event_id);
             $event = EventPeer::doSelectOne($c);
             if (!$event) {
                 $event = new Event();
             }
             $event_start_date = $client_event->getDateField1();
             $client_full_name = $client_profile->getFname() . ' ' . $client_profile->getLname();
             $event->setUserId($client_profile->getUserId());
             $event->setSubject($client_full_name . ': ' . $client_event->getName() . ': ' . $client_event->getBody());
             $event->setBody($client_event->getName() . ': ' . $client_event->getBody());
             $event->setEventType('client event');
             $event->setStartTime($date_field_1);
             $event->setEndTime($date_field_1);
             $event->setCeventId($client_event->getId());
             $event->setCalendarId(calendarsPeer::getCalendarIdByUserId($sf_user_id));
             $event->save();
             $ical = $this->getICalData($event);
             $event->setUri($ical->filename);
             $event->setIcsData($ical->createCalendar());
             $event->setCreatedById($sf_user_id);
             $event->save();
             $events = $event;
             if ($time_mode == 'PM') {
                 $hour = sfConfig::get('mod_client_outlook_shour');
             } else {
                 $hour = sfConfig::get('mod_client_outlook_shour');
             }
             $start_time = strtotime($event_start_date);
             $end_time = strtotime($event_start_date);
             $hour_start = $hour[$start_hour];
             //set default 9:00am
             $minute_start = $start_min;
             $end_hr = $start_min;
             // star time
             $start = array('year' => date('Y', $start_time), 'month' => date('m', $start_time), 'day' => date('d', $start_time), 'hour' => $hour_start, 'min' => $minute_start, 'sec' => date('s', $start_time));
             $outlook_start = date('d-m-Y', $start_time);
             $metting_start_time = $hour_start . ':' . $minute_start . ':' . '00';
             $mode = $time_mode == 'PM' ? ' PM' : ' AM';
             $metting_start_time = $metting_start_time . $mode;
             sfConfig::set('sf_web_debug', false);
             $description = get_partial('message_data', array());
             $sender = str_replace('sender', "{$client_full_name}", $description);
             $topic = str_replace('topic', "{$client_event->getName()}", $sender);
             $time = str_replace('start', "{$outlook_start}", $topic);
             $s_t = str_replace('s_t', "{$metting_start_time}", $time);
             $place = str_replace('place', "{$client_event->getVarcharField1()}", $s_t);
             $subject = str_replace('subject', "{$client_event->getBody()}", $place);
             $involved_user = $client_event->getContractId();
             $c = new Criteria();
             $c->add(ProfilePeer::USER_ID, $involved_user);
             $involved_user_profile = ProfilePeer::doSelectOne($c);
             $organizer = $involved_user_profile->getEmail();
             if ($time_mode == 'PM') {
                 $outlook_hour = sfConfig::get('mod_client_soutlook_dhour');
             } else {
                 $outlook_hour = sfConfig::get('mod_client_secoutlook_sechour');
             }
             $time_start = array('year' => date('Y', $start_time), 'month' => date('m', $start_time), 'day' => date('d', $start_time), 'hour' => $outlook_hour[$hour_start], 'min' => $minute_start, 'sec' => date('s', $start_time));
             $v_event = new vevent();
             $v_event->setProperty("organizer", 'MAILTO:' . $organizer);
             //$v_event->setProperty("recurrence-id", $start);
             $v_event->setProperty('uid', md5($events->getId()));
             $v_event->setProperty('dtstamp', $events->getCreatedAt());
             $v_event->setProperty('dtstart', $time_start);
             $v_event->setProperty('location', $client_event->getVarcharField1());
             $v_event->setProperty('dtend', $time_start);
             $v_event->setProperty('summary', $events->getSubject());
             $v_event->setProperty('description', $subject);
             $v_event->setProperty("status", "CONFIRMED");
             $v_timezone = new vtimezone();
             $v_timezone->setProperty("tzid", "Pacific/Auckland");
             $v_event->setComponent($v_timezone);
             $cal_events[] = $v_event;
             $v_alarm = new valarm();
             $v_alarm->setProperty('trigger', 'PT15M');
             $v_alarm->setProperty('action', 'display');
             $v_alarm->setProperty('Description', "Reminder: " . $subject);
             $v_event->setComponent($v_alarm);
             $calendar_events = $cal_events;
             $config = array('unique_id' => 'ravebuild.com');
             $v_calendar = new vcalendar();
             $v_calendar->setProperty("method", "REQUEST");
             $mail_data = $this->setIcalEvents($v_calendar, $calendar_events);
             $all_events = $v_calendar->createCalendar();
             $send_mail = new mailSend();
             $send_mail->sendInvitationToUser($organizer, null, $all_events);
             $event_type = $event_id ? 'updated' : 'added';
             $modification_message = $event_id ? 'Update Client Event' : 'Add Client Event';
             $client_user_id = $client_profile->getUserId();
             $this->saveHistory($modification_message, $client_user_id);
             $sf_user->setFlash('notice', 'The Event "' . $client_event->getBody() . '" has been ' . $event_type . ' successfully.');
             $this->redirect($request->getReferer());
         }
     }
 }