private static function row2array($row, $timezone, $hostname, $uid, $namespace_id)
 {
     $v = new vcalendar();
     $v->setConfig('unique_id', $hostname);
     $v->setProperty('method', 'PUBLISH');
     $v->setProperty("x-wr-calname", "AnimexxCal");
     $v->setProperty("X-WR-CALDESC", "Animexx Calendar");
     $v->setProperty("X-WR-TIMEZONE", $timezone);
     if ($row["adjust"]) {
         $start = datetime_convert('UTC', date_default_timezone_get(), $row["start"]);
         $finish = datetime_convert('UTC', date_default_timezone_get(), $row["finish"]);
     } else {
         $start = $row["start"];
         $finish = $row["finish"];
     }
     $allday = strpos($start, "00:00:00") !== false && strpos($finish, "00:00:00") !== false;
     /*
     
     if ($allday) {
     	$dat = Datetime::createFromFormat("Y-m-d H:i:s", $finish_tmp);
     	$dat->sub(new DateInterval("P1D"));
     	$finish = datetime_convert("UTC", date_default_timezone_get(), $dat->format("Y-m-d H:i:s"));
     	var_dump($finish);
     }
     */
     $subject = substr(preg_replace("/\\[[^\\]]*\\]/", "", $row["desc"]), 0, 100);
     $description = preg_replace("/\\[[^\\]]*\\]/", "", $row["desc"]);
     $vevent = dav_create_vevent(wdcal_mySql2icalTime($row["start"]), wdcal_mySql2icalTime($row["finish"]), false);
     $vevent->setLocation(icalendar_sanitize_string($row["location"]));
     $vevent->setSummary(icalendar_sanitize_string($subject));
     $vevent->setDescription(icalendar_sanitize_string($description));
     $v->setComponent($vevent);
     $ical = $v->createCalendar();
     return array("uid" => $uid, "namespace" => CALDAV_NAMESPACE_FRIENDICA_NATIVE, "namespace_id" => $namespace_id, "date" => $row["edited"], "data_uri" => "friendica-" . $namespace_id . "-" . $row["id"] . "@" . $hostname, "data_subject" => $subject, "data_location" => $row["location"], "data_description" => $description, "data_start" => $start, "data_end" => $finish, "data_allday" => $allday, "data_type" => $row["type"], "ical" => $ical, "ical_size" => strlen($ical), "ical_etag" => md5($ical));
 }
예제 #2
0
파일: Event.php 프로젝트: hugonicolas/Site
 public function ical($params)
 {
     $this->setView('ical.php');
     $official = isset($params['official']);
     $group_name = isset($params['group']) ? $params['group'] : null;
     $event_model = new Event_Model();
     $events = $event_model->getUpcoming($group_name, $official, false);
     // Creation of the iCal content
     $cache_entry = 'ical-' . (isset($group_name) ? $group_name : '') . '-' . ($official ? 'official' : 'non-official');
     $content = Cache::read($cache_entry);
     if (!$content) {
         require_once APP_DIR . 'classes/class.iCalcreator.php';
         $cal = new vcalendar();
         $cal->setConfig('unique_id', $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
         $cal->setProperty('method', 'PUBLISH');
         $cal->setProperty('x-wr-calname', $official ? __('EVENTS_TITLE_OFFICIAL') : __('EVENTS_TITLE_NONOFFICIAL'));
         $cal->setProperty('X-WR-CALDESC', '');
         $cal->setProperty('X-WR-TIMEZONE', date('e'));
         foreach ($events as $event) {
             $vevent = new vevent();
             $vevent->setProperty('dtstart', array('year' => (int) date('Y', $event['date_start']), 'month' => (int) date('n', $event['date_start']), 'day' => (int) date('j', $event['date_start']), 'hour' => (int) date('G', $event['date_start']), 'min' => (int) date('i', $event['date_start']), 'sec' => (int) date('s', $event['date_start'])));
             $vevent->setProperty('dtend', array('year' => (int) date('Y', $event['date_end']), 'month' => (int) date('n', $event['date_end']), 'day' => (int) date('j', $event['date_end']), 'hour' => (int) date('G', $event['date_end']), 'min' => (int) date('i', $event['date_end']), 'sec' => (int) date('s', $event['date_end'])));
             $vevent->setProperty('summary', $event['title']);
             $vevent->setProperty('description', $event['message']);
             $cal->setComponent($vevent);
         }
         $content = $cal->createCalendar();
         Cache::write($cache_entry, $content, 2 * 3600);
     }
     $this->set('content', $content);
 }
예제 #3
0
 function create($name, $description = '', $tz = 'US/Pacific')
 {
     $v = new vcalendar();
     $v->setConfig('unique_id', $name . '.' . 'yourdomain.com');
     $v->setProperty('method', 'PUBLISH');
     $v->setProperty('x-wr-calname', $name . ' Calendar');
     $v->setProperty("X-WR-CALDESC", $description);
     $v->setProperty("X-WR-TIMEZONE", $tz);
     $this->calendar = $v;
 }
예제 #4
0
 function display($tpl = null)
 {
     $mainframe = JFactory::getApplication();
     $option = JRequest::getCmd('option');
     $model = $this->getModel();
     $results = $model->getResults(JRequest::getVar('p', 0, '', 'int'));
     $project = $model->getProject(JRequest::getVar('p', 0, '', 'int'));
     $document = JFactory::getDocument();
     $v = new vcalendar();
     // initiate new CALENDAR
     $v->setConfig('project' . $project->id, $mainframe->getCfg('live_site'));
     // config with site domain
     $v->setProperty('X-WR-CALNAME', $project->name);
     // set some X-properties, name, content.. .
     $v->setProperty('X-WR-CALDESC', JText::_('COM_TRACKS_Project_calendar'));
     $v->setConfig("filename", 'project_' . $project->id . '.ics');
     foreach ((array) $results as $result) {
         if (!ereg('([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})', $result->start_date, $start_date)) {
             continue;
         }
         $e = new vevent();
         // initiate a new EVENT
         $e->setProperty('categories', $project->name);
         // catagorize
         $e->setProperty('dtstart', $start_date[1], $start_date[2], $start_date[3], $start_date[4], $start_date[5], $start_date[6]);
         if (ereg('([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})', $result->end_date, $end_date)) {
             $e->setProperty('dtend', $end_date[1], $end_date[2], $end_date[3], $end_date[4], $end_date[5], $end_date[6]);
         }
         $description = array();
         $description[] = $result->round_name;
         if ($result->winner && $result->winner->last_name) {
             $winner = JText::_('COM_TRACKS_Winner') . $result->winner->first_name . ' ' . $result->winner->last_name;
             if ($result->winner->team_name) {
                 $winner .= ' (' . $result->winner->team_name . ')';
             }
             $description[] = $winner;
         }
         $description = implode('\\n', $description);
         $e->setProperty('description', $description);
         // describe the event
         $e->setProperty('location', $result->round_name);
         // locate the event
         $v->addComponent($e);
         // add component to calendar
     }
     /* alt. production */
     // $v->returnCalendar();                       // generate and redirect output to user browser
     /* alt. dev. and test */
     $str = $v->createCalendar();
     // generate and get output in string, for testing?
     //      echo $str;return;
     $v->returnCalendar();
 }
예제 #5
0
파일: ics.php 프로젝트: newmight2015/psmpsm
 public function export(array $arguments, array $params = array())
 {
     $c = new vcalendar();
     $c->setProperty('calscale', 'GREGORIAN');
     $c->setProperty('method', 'PUBLISH');
     // if no post id are specified do not export those properties
     // as they would create a new calendar in outlook.
     // a user reported this in AIOEC-982 and said this would fix it
     if (true === $arguments['do_not_export_as_calendar']) {
         $c->setProperty('X-WR-CALNAME', get_bloginfo('name'));
         $c->setProperty('X-WR-CALDESC', get_bloginfo('description'));
     }
     $c->setProperty('X-FROM-URL', home_url());
     // Timezone setup
     $tz = $this->_registry->get('date.timezone')->get_default_timezone();
     if ($tz) {
         $c->setProperty('X-WR-TIMEZONE', $tz);
         $tz_xprops = array('X-LIC-LOCATION' => $tz);
         iCalUtilityFunctions::createTimezone($c, $tz, $tz_xprops);
     }
     $this->_taxonomy_model = $this->_registry->get('model.taxonomy');
     $post_ids = array();
     foreach ($arguments['events'] as $event) {
         $post_ids[] = $event->get('post_id');
     }
     $this->_taxonomy_model->update_meta($post_ids);
     foreach ($arguments['events'] as $event) {
         $c = $this->_insert_event_in_calendar($event, $c, true, $params);
     }
     $str = ltrim($c->createCalendar());
     return $str;
 }
예제 #6
0
 /**
  * Creates a new iCalendar resource
  * 
  * Property keys can be lowercase
  *
  * Returns generated guid, FALSE on error. $generated will be filled with
  * new generated resource (iCalComponent object)
  */
 function new_resource($properties, &$generated, $tz, $reminders = array())
 {
     $properties = array_change_key_case($properties, CASE_UPPER);
     $contents = '';
     $ical = new vcalendar($this->config);
     // Default CALSCALE in standard
     $ical->setProperty('calscale', 'GREGORIAN');
     $allday = isset($properties['ALLDAY']) && $properties['ALLDAY'] == 'true';
     if ($allday) {
         // Discard timezone
         $tz = $this->CI->timezonemanager->getTz('UTC');
     }
     // Add VTIMEZONE
     $this->add_vtimezone($ical, $tz->getName());
     $vevent =& $ical->newComponent('vevent');
     $now = $this->CI->dates->datetime2idt();
     $uid = $this->generate_guid();
     $vevent->setProperty('CREATED', $now);
     $vevent->setProperty('LAST-MODIFIED', $now);
     $vevent->setProperty('DTSTAMP', $now);
     $vevent->setProperty('UID', $uid);
     $vevent->setProperty('SEQUENCE', '0');
     // RFC5545, 3.8.7.4
     $vevent->setProperty('SUMMARY', $properties['SUMMARY']);
     // Rest of properties
     $add_prop = array('DTSTART', 'DTEND', 'DESCRIPTION', 'LOCATION', 'DURATION', 'RRULE', 'TRANSP', 'CLASS');
     foreach ($add_prop as $p) {
         if (isset($properties[$p]) && !empty($properties[$p])) {
             $params = FALSE;
             // Generate DTSTART/DTEND
             if ($p == 'DTSTART' || $p == 'DTEND') {
                 if ($tz->getName() != 'UTC') {
                     $params = array('TZID' => $tz->getName());
                 }
                 $properties[$p] = $this->CI->dates->datetime2idt($properties[$p], $tz);
                 // All day: use parameter VALUE=DATE
                 if ($allday) {
                     $params['VALUE'] = 'DATE';
                 }
             }
             $vevent->setProperty($p, $properties[$p], $params);
         }
     }
     // VALARM components (reminders)
     $vevent = $this->set_valarms($vevent, $reminders);
     $generated = $ical;
     return $uid;
 }
예제 #7
0
 /**
  * toICS()
  *
  * Outputs group schedules in ICS format
  */
 function toICS()
 {
     require_once BPSP_PLUGIN_DIR . '/schedules/iCalcreator.class.php';
     global $bp;
     define('ICAL_LANG', get_bloginfo('language'));
     $cal = new vcalendar();
     $cal->setConfig('unique_id', str_replace('http://', '', get_bloginfo('siteurl')));
     $cal->setConfig('filename', $bp->groups->current_group->slug);
     $cal->setProperty('X-WR-CALNAME', __('Calendar for: ', 'bpsp') . $bp->groups->current_group->name);
     $cal->setProperty('X-WR-CALDESC', $bp->groups->current_group->description);
     $cal->setProperty('X-WR-TIMEZONE', get_option('timezone_string'));
     $schedules = $this->has_schedules();
     $assignments = BPSP_Assignments::has_assignments();
     $entries = array_merge($assignments, $schedules);
     foreach ($entries as $entry) {
         setup_postdata($entry);
         $e = new vevent();
         if ($entry->post_type == "schedule") {
             $date = getdate(strtotime($entry->start_date));
         } elseif ($entry->post_type == "assignment") {
             $date = getdate(strtotime($entry->post_date));
         }
         $dtstart['year'] = $date['year'];
         $dtstart['month'] = $date['mon'];
         $dtstart['day'] = $date['mday'];
         $dtstart['hour'] = $date['hours'];
         $dtstart['min'] = $date['minutes'];
         $dtstart['sec'] = $date['seconds'];
         $e->setProperty('dtstart', $dtstart);
         $e->setProperty('description', get_the_content() . "\n\n" . $entry->permalink);
         if (!empty($entry->location)) {
             $e->setProperty('location', $entry->location);
         }
         if ($entry->post_type == "assignment") {
             $entry->end_date = $entry->due_date;
         }
         // make assignments compatible with schedule parser
         if (!empty($entry->end_date)) {
             $date = getdate(strtotime($entry->end_date));
             $dtend['year'] = $date['year'];
             $dtend['month'] = $date['mon'];
             $dtend['day'] = $date['mday'];
             $dtend['hour'] = $date['hours'];
             $dtend['min'] = $date['minutes'];
             $dtend['sec'] = $date['seconds'];
             $e->setProperty('dtend', $dtend);
         } else {
             $e->setProperty('duration', 0, 1, 0);
         }
         // Assume it's an one day event
         $e->setProperty('summary', get_the_title($entry->ID));
         $e->setProperty('status', 'CONFIRMED');
         $cal->setComponent($e);
     }
     header("HTTP/1.1 200 OK");
     die($cal->returnCalendar());
 }
예제 #8
0
$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
/* alt. production */
// $v->returnCalendar();                       // generate and redirect output to user browser
/* alt. dev. and test */
echo nl2br($v->createCalendar());
// generate and get output in string, for testing?
echo "<br />\n\n";
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */
$v = new vcalendar(array('unique_id' => 'kigkonsult.se'));
// initiate new CALENDAR
$v->setProperty('X-WR-CALNAME', 'Sample calendar');
// set some X-properties, name, content.. .
$v->setProperty('X-WR-CALDESC', 'Description of the calendar');
$v->setProperty('X-WR-TIMEZONE', 'Europe/Stockholm');
$e =& $v->newComponent('vevent');
// initiate a new 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
예제 #9
0
        $event = get_entity($filter);
        if (elgg_instanceof($event, 'object', 'event_calendar')) {
            $events = array(array('event' => $event));
        }
        break;
}
if (!$events) {
    register_error(elgg_echo('event_calendar:no_events_found'));
    forward(REFERER);
}
$events = event_calendar_flatten_event_structure($events);
$timezone = date_default_timezone_get();
//get_plugin_setting('timezone', 'event_connector');
$config = array('UNIQUE_ID' => elgg_get_site_url(), 'FILENAME' => 'Calendar.ics', 'TZID' => $timezone);
$v = new vcalendar($config);
$v->setProperty('method', 'PUBLISH');
$v->setProperty("X-WR-TIMEZONE", date_default_timezone_get());
$v->setProperty("calscale", "GREGORIAN");
$v->setProperty("version", "2.0");
$v->setProperty("X-WR-CALNAME", elgg_get_logged_in_user_entity()->username . "Calendar");
iCalUtilityFunctions::createTimezone($v, $timezone);
foreach ($events as $event) {
    //set default beginning and ending time
    $hb = 8;
    $he = 18;
    $mb = $me = $sb = $se = 0;
    if ($event->start_time) {
        $hb = (int) ($event->start_time / 60);
        $mb = $event->start_time % 60;
    }
    if ($event->end_time) {
예제 #10
0
 /**
  *  Generate ical file content
  *
  * @param $who             user ID
  * @param $who_group       group ID
  * @param $limititemtype   itemtype only display this itemtype (default '')
  *
  * @return icalendar string
  **/
 static function generateIcal($who, $who_group, $limititemtype = '')
 {
     global $CFG_GLPI;
     if ($who === 0 && $who_group === 0) {
         return false;
     }
     include_once GLPI_ROOT . "/lib/icalcreator/iCalcreator.class.php";
     $v = new vcalendar();
     if (!empty($CFG_GLPI["version"])) {
         $v->setConfig('unique_id', "GLPI-Planning-" . trim($CFG_GLPI["version"]));
     } else {
         $v->setConfig('unique_id', "GLPI-Planning-UnknownVersion");
     }
     $tz = date_default_timezone_get();
     $v->setConfig('TZID', $tz);
     $v->setProperty("method", "PUBLISH");
     $v->setProperty("version", "2.0");
     $v->setProperty("X-WR-TIMEZONE", $tz);
     $xprops = array("X-LIC-LOCATION" => $tz);
     iCalUtilityFunctions::createTimezone($v, $tz, $xprops);
     $v->setProperty("x-wr-calname", "GLPI-" . $who . "-" . $who_group);
     $v->setProperty("calscale", "GREGORIAN");
     $interv = array();
     $begin = time() - MONTH_TIMESTAMP * 12;
     $end = time() + MONTH_TIMESTAMP * 12;
     $begin = date("Y-m-d H:i:s", $begin);
     $end = date("Y-m-d H:i:s", $end);
     $params = array('who' => $who, 'who_group' => $who_group, 'begin' => $begin, 'end' => $end);
     $interv = array();
     if (empty($limititemtype)) {
         foreach ($CFG_GLPI['planning_types'] as $itemtype) {
             $interv = array_merge($interv, $itemtype::populatePlanning($params));
         }
     } else {
         $interv = $limititemtype::populatePlanning($params);
     }
     if (count($interv) > 0) {
         foreach ($interv as $key => $val) {
             $vevent = new vevent();
             //initiate EVENT
             if (isset($val['itemtype'])) {
                 if (isset($val[getForeignKeyFieldForItemType($val['itemtype'])])) {
                     $vevent->setProperty("uid", $val['itemtype'] . "#" . $val[getForeignKeyFieldForItemType($val['itemtype'])]);
                 } else {
                     $vevent->setProperty("uid", "Other#" . $key);
                 }
             } else {
                 $vevent->setProperty("uid", "Other#" . $key);
             }
             $vevent->setProperty("dstamp", $val["begin"]);
             $vevent->setProperty("dtstart", $val["begin"]);
             $vevent->setProperty("dtend", $val["end"]);
             if (isset($val["tickets_id"])) {
                 $vevent->setProperty("summary", sprintf(__('Ticket #%1$s %2$s'), $val["tickets_id"], $val["name"]));
             } else {
                 if (isset($val["name"])) {
                     $vevent->setProperty("summary", $val["name"]);
                 }
             }
             if (isset($val["content"])) {
                 $text = $val["content"];
                 // be sure to replace nl by \r\n
                 $text = preg_replace("/<br( [^>]*)?" . ">/i", "\r\n", $text);
                 $text = Html::clean($text);
                 $vevent->setProperty("description", $text);
             } else {
                 if (isset($val["name"])) {
                     $text = $val["name"];
                     // be sure to replace nl by \r\n
                     $text = preg_replace("/<br( [^>]*)?" . ">/i", "\r\n", $text);
                     $text = Html::clean($text);
                     $vevent->setProperty("description", $text);
                 }
             }
             if (isset($val["url"])) {
                 $vevent->setProperty("url", $val["url"]);
             }
             $v->setComponent($vevent);
         }
     }
     $v->sort();
     //       $v->parse();
     return $v->returnCalendar();
 }
예제 #11
0
 function _get_events_url(&$events, $url, $date)
 {
     $v = new vcalendar();
     $v->setConfig('unique_id', 'barchat');
     $v->setProperty('method', 'PUBLISH');
     $v->setProperty("x-wr-calname", "Calendar Sample");
     $v->setProperty("X-WR-CALDESC", "Calendar Description");
     $v->setProperty("X-WR-TIMEZONE", "America/New_York");
     $v->setConfig('url', $url);
     try {
         $v->parse();
     } catch (exception $e) {
     }
     $v->sort();
     $m = $date->format('n');
     $d = $date->format('j');
     $y = $date->format('Y');
     $eventArray = $v->selectComponents($y, $m, 1, $y, $m, 31);
     foreach ((array) $eventArray as $yearkey => $yeararray) {
         foreach ((array) $yeararray as $monthkey => $montharray) {
             foreach ((array) $montharray as $daykey => $dayarray) {
                 foreach ((array) $dayarray as $eventnumber => $event) {
                     //echo "{$y}-{$m}-{$daykey} [{$eventnumber}]: ";
                     $time = $event->dtstart['value'];
                     $tz = $event->dtstart['params']['TZID'] == '' ? 'America/New_York' : $event->dtstart['params']['TZID'];
                     if ($time['tz'] == 'Z') {
                         $tz = 'GMT';
                     }
                     if (isset($event->dtstart['params']['VALUE']) && $event->dtstart['params']['VALUE'] == 'DATE') {
                         $allday = new DateTime("{$time['year']}-{$time['month']}-{$time['day']}", new DateTimeZone($tz));
                         $allday->setTimezone(new DateTimeZone('America/New_York'));
                         $d = sprintf('%04d-%02d-%02d', $y, $m, $daykey);
                         if (!is_array($events[$d])) {
                             $events[$d] = array();
                         }
                         $alldayint = intval($allday->format('U'));
                         while (isset($events[$d][$alldayint])) {
                             $alldayint++;
                         }
                         $events[$d][$alldayint] = '<span class="calendartime">All Day</span> ' . trim($event->summary['value']);
                         //var_dump(date('r', $allday) . ' = ' . $allday);
                         //var_dump($event->summary['value']);
                     } else {
                         if (isset($event->xprop['X-CURRENT-DTSTART'])) {
                             $dt = new DateTime($event->xprop['X-CURRENT-DTSTART']['value'], new DateTimeZone($tz));
                         } else {
                             $dt = new DateTime("{$time['year']}-{$time['month']}-{$time['day']} {$time['hour']}:{$time['min']}:{$time['sec']}", new DateTimeZone($tz));
                         }
                         $dt->setTimezone(new DateTimeZone('America/New_York'));
                         if (isset($event->xprop['X-CURRENT-DTEND'])) {
                             $dte = new DateTime($event->xprop['X-CURRENT-DTEND']['value'], new DateTimeZone($tz));
                         } else {
                             $timee = $event->dtstart['value'];
                             $dte = new DateTime("{$timee['year']}-{$timee['month']}-{$timee['day']} {$timee['hour']}:{$timee['min']}:{$timee['sec']}", new DateTimeZone($tz));
                         }
                         $dte->setTimezone(new DateTimeZone('America/New_York'));
                         if (!is_array($events[$d])) {
                             $events[$d] = array();
                         }
                         $d = sprintf('%04d-%02d-%02d', $y, $m, $daykey);
                         $daytime = $dt->format('U');
                         while (isset($events[$d][$daytime])) {
                             $daytime++;
                         }
                         if ($dt->format('g:ia') != $dte->format('g:ia')) {
                             $events[$d][$daytime] = '<span class="calendartime">' . $dt->format('g:ia') . ' - ' . $dte->format('g:ia') . '</span> ' . trim($event->summary['value']);
                         } else {
                             $events[$d][$daytime] = '<span class="calendartime">' . $dt->format('g:ia') . '</span> ' . trim($event->summary['value']);
                         }
                         //var_dump($event->dtstart);
                         //var_dump($event->summary['value']);
                         //var_dump($dt->format('r'));
                         //var_dump($event);
                     }
                 }
             }
         }
     }
 }
예제 #12
0
 /**
  * function csv2iCal
  *
  * Convert csv file to iCal format and send file to browser (default) or save Ical file to disk
  * Definition iCal  : rcf2445, http://kigkonsult.se/downloads/index.php#rfc2445
  * Definition csv   : http://en.wikipedia.org/wiki/Comma-separated_values
  * Using iCalcreator: http://kigkonsult.se/downloads/index.php#iCalcreator
  * csv directory/file read/write
  *
  * @author Kjell-Inge Gustafsson <*****@*****.**>
  * @since  3.0 - 2011-12-21
  * @return bool return FALSE when error
  */
 public function csv2iCal()
 {
     $timeexec = array('start' => microtime(TRUE));
     if ($this->log) {
         $this->log->log(' ********** START **********', PEAR_LOG_NOTICE);
     }
     $conf = array();
     foreach ($this->config as $key => $value) {
         if (in_array(strtolower($key), array('inputdirectory', 'outputdirectory', 'inputfilename', 'outputfilename', 'inputurl', 'backup', 'save', 'skip'))) {
             continue;
         }
         if (in_array($key, array('del', 'sep', 'nl'))) {
             $conf[$key] = "{$value}";
         } else {
             $conf[strtoupper($value)] = strtoupper($key);
             // flip map names
             if ($this->log) {
                 $this->log->log("{$value} mapped to {$key}", PEAR_LOG_DEBUG);
             }
         }
     }
     $fp = false;
     $string_to_parse = $this->getConfig('string_to_parse');
     if ($string_to_parse) {
         $fp = fopen('php://temp/maxmemory:' . 1024 * 1024, 'rw');
         fputs($fp, $string_to_parse);
         fseek($fp, 0);
     } else {
         /** check input/output directory and filename */
         $inputdirFile = $outputdirFile = '';
         $inputFileParts = $outputFileParts = array();
         $remoteInput = $remoteOutput = FALSE;
         if (FALSE === $this->_fixIO('input', 'csv', $inputdirFile, $inputFileParts, $remoteInput)) {
             if ($this->log) {
                 $this->log->log(number_format(microtime(TRUE) - $timeexec['start'], 5) . ' sec', PEAR_LOG_ERR);
                 $this->log->log("ERROR 2, invalid input ({$inputdirFile})", PEAR_LOG_ERR);
                 $this->log->flush();
             }
             return FALSE;
         }
         if (FALSE === $this->_fixIO('output', FALSE, $outputdirFile, $outputFileParts, $remoteOutput)) {
             if (FALSE === $this->setConfig('outputfilename', $inputFileParts['filename'] . '.ics')) {
                 if ($this->log) {
                     $this->log->log(number_format(microtime(TRUE) - $timeexec['start'], 5) . ' sec', PEAR_LOG_ERR);
                     $this->log->log('ERROR 3,invalid output (' . $inputFileParts['filename'] . '.csv)', PEAR_LOG_ERR);
                     $this->log->flush();
                 }
                 return FALSE;
             }
             $outputdirFile = $this->getConfig('outputdirectory') . DIRECTORY_SEPARATOR . $inputFileParts['filename'] . '.ics';
             $outputFileParts = pathinfo($outputdirFile);
             if ($this->log) {
                 $this->log->log("output set to '{$outputdirFile}'", PEAR_LOG_NOTICE);
             }
         }
         if ($this->log) {
             $this->log->log("INPUT..FILE:{$inputdirFile}", PEAR_LOG_NOTICE);
             $this->log->log("OUTPUT.FILE:{$outputdirFile}", PEAR_LOG_NOTICE);
         }
         /** read csv file into input array */
         ini_set('auto_detect_line_endings', true);
         $fp = fopen($inputdirFile, "r");
         if (FALSE === $fp) {
             if ($this->log) {
                 $this->log->log("ERROR 4, unable to read file: '{$inputdirFile}'", PEAR_LOG_ERR);
                 $this->log->log(number_format(microtime(TRUE) - $timeexec['start'], 5) . ' sec', PEAR_LOG_DEBUG);
                 $this->log->flush();
             }
             return FALSE;
         }
     }
     $rows = array();
     while (FALSE !== ($row = fgetcsv($fp, FALSE, $conf['sep'], $conf['del']))) {
         $rows[] = $row;
     }
     fclose($fp);
     ini_set('auto_detect_line_endings', false);
     $cntrows = count($rows);
     /** iCalcreator checks when setting directory and filename */
     $calendar = new vcalendar();
     if (FALSE !== ($unique_id = $this->getConfig('unique_id'))) {
         $calendar->setConfig('unique_id', $unique_id);
     }
     if (!$this->getConfig('outputobj')) {
         if ($remoteOutput) {
             if (FALSE === $calendar->setConfig('url', $outputdirFile)) {
                 if ($this->log) {
                     $this->log->log("ERROR 5, iCalcreator: invalid url: '{$outputdirFile}'", PEAR_LOG_ERR);
                     $this->log->log(number_format(microtime(TRUE) - $timeexec['start'], 5) . ' sec', PEAR_LOG_DEBUG);
                     $this->log->flush();
                 }
                 return FALSE;
             }
         } else {
             if (FALSE === $calendar->setConfig('directory', $outputFileParts['dirname'])) {
                 if ($this->log) {
                     $this->log->log("ERROR 6, INPUT FILE:'{$inputdirFile}'  iCalcreator: invalid directory: '" . $outputFileParts['dirname'] . "'", PEAR_LOG_ERR);
                     $this->log->log(number_format(microtime(TRUE) - $timeexec['start'], 5) . ' sec', PEAR_LOG_DEBUG);
                     $this->log->flush();
                 }
                 return FALSE;
             }
             if (FALSE === $calendar->setConfig('filename', $outputFileParts['basename'])) {
                 if ($this->log) {
                     $this->log->log("ERROR 7, INPUT FILE:'{$inputdirFile}' iCalcreator: invalid filename: '" . $outputFileParts['basename'] . "'", PEAR_LOG_ERR);
                     $this->log->log(number_format(microtime(TRUE) - $timeexec['start'], 5) . ' sec', PEAR_LOG_DEBUG);
                     $this->log->flush();
                 }
                 return FALSE;
             }
         }
     }
     $timeexec['fileOk'] = microtime(TRUE);
     /** info rows */
     $actrow = 0;
     for ($row = $actrow; $row < $cntrows; $row++) {
         if (empty($rows[$row]) || 1 >= count($rows[$row]) || '' >= $rows[$row][1] || 'iCal' == substr($rows[$row][0], 0, 4) || 'kigkonsult.se' == $rows[$row][0]) {
             continue;
         } elseif ('TYPE' == strtoupper($rows[$row][0])) {
             $actrow = $row;
             break;
         } elseif ('CALSCALE' == strtoupper($rows[$row][0])) {
             $calendar->setProperty('CALSCALE', $rows[$row][1]);
         } elseif ('METHOD' == strtoupper($rows[$row][0])) {
             $calendar->setProperty('METHOD', $rows[$row][1]);
         } elseif ('X-' == substr($rows[$row][0], 0, 2)) {
             $calendar->setProperty($rows[$row][0], $rows[$row][1]);
         } elseif (2 >= count($rows[$row])) {
             continue;
         } else {
             $actrow = $row;
             break;
         }
     }
     $timeexec['infoOk'] = microtime(TRUE);
     $cntprops = 0;
     $proporder = array();
     /** fix opt. vtimezone */
     if ($actrow < $cntrows && (in_array('tzid', $rows[$actrow]) || in_array('TZID', $rows[$actrow]))) {
         foreach ($rows[$actrow] as $key => $header) {
             $header = strtoupper($header);
             if (isset($conf[$header])) {
                 $proporder[$conf[$header]] = $key;
                 // check map of userfriendly name to iCal property name
                 if ($this->log) {
                     $this->log->log("header row ix:{$key} => {$header}, replaced by " . $conf[$header], PEAR_LOG_DEBUG);
                 }
             } else {
                 $proporder[$header] = $key;
             }
         }
         if ($this->log) {
             $this->log->log("comp proporder=" . implode(',', array_flip($proporder)), PEAR_LOG_DEBUG);
         }
         $allowedProps = array('VTIMEZONE' => array('TZID', 'LAST-MODIFIED', 'TZURL'), 'STANDARD' => array('DTSTART', 'TZOFFSETTO', 'TZOFFSETFROM', 'COMMENT', 'RDATE', 'RRULE', 'TZNAME'), 'DAYLIGHT' => array('DTSTART', 'TZOFFSETTO', 'TZOFFSETFROM', 'COMMENT', 'RDATE', 'RRULE', 'TZNAME'));
         $actrow++;
         $comp = $subcomp = $actcomp = FALSE;
         for ($row = $actrow; $row < $cntrows; $row++) {
             if (empty($rows[$row]) || 1 >= count($rows[$row])) {
                 continue;
             }
             $compname = strtoupper($rows[$row][0]);
             if ('TYPE' == $compname) {
                 // next header
                 $actrow = $row;
                 break;
             }
             if ($comp && $subcomp) {
                 $comp->setComponent($subcomp);
                 $subcomp = FALSE;
             }
             if ('VTIMEZONE' == $compname) {
                 if ($comp) {
                     $calendar->setComponent($comp);
                 }
                 $comp = new vtimezone();
                 $actcomp =& $comp;
                 $cntprops += 1;
             } elseif ('STANDARD' == $compname) {
                 $subcomp = new vtimezone('STANDARD');
                 $actcomp =& $subcomp;
             } elseif ('DAYLIGHT' == $compname) {
                 $subcomp = new vtimezone('DAYLIGHT');
                 $actcomp =& $subcomp;
             } else {
                 if ($this->log) {
                     $this->log->log("skipped {$compname}", PEAR_LOG_WARNING);
                 }
                 continue;
             }
             foreach ($proporder as $propName => $col) {
                 // insert all properties into component
                 if (2 > $col || 'ORDER' == strtoupper($propName)) {
                     continue;
                 }
                 $propName = strtoupper($propName);
                 if ('X-' != substr($propName, 0, 2) && !in_array($propName, $allowedProps[$compname])) {
                     // check if allowed property for the component
                     if ($this->log) {
                         $this->log->log("skipped {$compname}: {$propName}", PEAR_LOG_DEBUG);
                     }
                     continue;
                 }
                 if (isset($rows[$row][$col]) && !empty($rows[$row][$col])) {
                     $rows[$row][$col] = str_replace(array("\r\n", "\n\r", "\n", "\r"), $conf['nl'], $rows[$row][$col]);
                     $value = FALSE !== strpos($rows[$row][$col], $conf['nl']) ? explode($conf['nl'], $rows[$row][$col]) : array($rows[$row][$col]);
                     foreach ($value as $val) {
                         if (empty($val) && '0' != $val) {
                             continue;
                         }
                         $del = FALSE !== strpos($val, ':') ? ';' : ':';
                         if (FALSE !== $actcomp->parse("{$propName}{$del}{$val}")) {
                             if ($this->log) {
                                 $this->log->log("iCalcreator->parse( '{$propName} {$val}' )", PEAR_LOG_DEBUG);
                             }
                         } elseif ($this->log) {
                             $this->log->log("ERROR 8, INPUT FILE:'{$inputdirFile}' iCalcreator: parse error: '{$propName}{$del}{$val}'", PEAR_LOG_ERR);
                         }
                     }
                     // end foreach( $value
                 }
                 // end if( isset
             }
             // end foreach( $proporder
         }
         // end for( $row = $actrow
         if ($comp && $subcomp) {
             $comp->setComponent($subcomp);
         }
         if ($comp) {
             $calendar->setComponent($comp);
         }
         $comp = $subcomp = $actcomp = FALSE;
     }
     $timeexec['zoneOk'] = microtime(TRUE);
     /** fix data */
     $proporder = array();
     if ($actrow < $cntrows && isset($rows[$actrow][0]) && 'TYPE' == strtoupper($rows[$actrow][0])) {
         foreach ($rows[$actrow] as $key => $header) {
             $header = strtoupper($header);
             if (isset($conf[$header])) {
                 $proporder[$conf[$header]] = $key;
                 // check map of user friendly name to iCal property name
                 if ($this->log) {
                     $this->log->log("header row ix:'{$key} => {$header}', mapped to '" . $conf[$header] . "'", PEAR_LOG_DEBUG);
                 }
             } else {
                 $proporder[$header] = $key;
             }
         }
         if ($this->log) {
             $this->log->log("comp proporder=" . implode(',', array_flip($proporder)), PEAR_LOG_DEBUG);
         }
         $allowedProps = array('VEVENT' => array('ATTACH', 'ATTENDEE', 'CATEGORIES', 'CLASS', 'COMMENT', 'CONTACT', 'CREATED', 'DESCRIPTION', 'DTEND', 'DTSTAMP', 'DTSTART', 'DURATION', 'EXDATE', 'RXRULE', 'GEO', 'LAST-MODIFIED', 'LOCATION', 'ORGANIZER', 'PRIORITY', 'RDATE', 'RECURRENCE-ID', 'RELATED-TO', 'RESOURCES', 'RRULE', 'REQUEST-STATUS', 'SEQUENCE', 'STATUS', 'SUMMARY', 'TRANSP', 'UID', 'URL'), 'VTODO' => array('ATTACH', 'ATTENDEE', 'CATEGORIES', 'CLASS', 'COMMENT', 'COMPLETED', 'CONTACT', 'CREATED', 'DESCRIPTION', 'DTSTAMP', 'DTSTART', 'DUE', 'DURATION', 'EXDATE', 'EXRULE', 'GEO', 'LAST-MODIFIED', 'LOCATION', 'ORGANIZER', 'PERCENT', 'PRIORITY', 'RDATE', 'RECURRENCE-ID', 'RELATED-TO', 'RESOURCES', 'RRULE', 'REQUEST-STATUS', 'SEQUENCE', 'STATUS', 'SUMMARY', 'UID', 'URL'), 'VJOURNAL' => array('ATTACH', 'ATTENDEE', 'CATEGORIES', 'CLASS', 'COMMENT', 'CONTACT', 'CREATED', 'DESCRIPTION', 'DTSTAMP', 'DTSTART', 'EXDATE', 'EXRULE', 'LAST-MODIFIED', 'ORGANIZER', 'RDATE', 'RECURRENCE-ID', 'RELATED-TO', 'RRULE', 'REQUEST-STATUS', 'SEQUENCE', 'STATUS', 'SUMMARY', 'UID', 'URL'), 'VFREEBUSY' => array('ATTENDEE', 'COMMENT', 'CONTACT', 'DTEND', 'DTSTAMP', 'DTSTART', 'DURATION', 'FREEBUSY', 'ORGANIZER', 'UID', 'URL'), 'VALARM' => array('ACTION', 'ATTACH', 'ATTENDEE', 'DESCRIPTION', 'DURATION', 'REPEAT', 'SUMMARY', 'TRIGGER'));
         $actrow++;
         $comp = $subcomp = $actcomp = FALSE;
         $allowedComps = array('VEVENT', 'VTODO', 'VJOURNAL', 'VFREEBUSY');
         for ($row = $actrow; $row < $cntrows; $row++) {
             if (empty($rows[$row]) || 1 >= count($rows[$row])) {
                 continue;
             }
             if ($comp && $subcomp) {
                 $comp->setComponent($subcomp);
                 $subcomp = FALSE;
             }
             $compname = strtoupper($rows[$row][0]);
             if ($this->log) {
                 $this->log->log("'{$compname}' START", PEAR_LOG_NOTICE);
             }
             if (in_array($compname, $allowedComps)) {
                 if ($comp) {
                     $calendar->setComponent($comp);
                 }
                 $comp = new $rows[$row][0]();
                 $actcomp =& $comp;
                 $cntprops += 1;
             } elseif ('VALARM' == $compname) {
                 $subcomp = new valarm();
                 $actcomp =& $subcomp;
             } else {
                 if ($this->log) {
                     $this->log->log("skipped {$compname}", PEAR_LOG_WARNING);
                 }
                 continue;
             }
             foreach ($proporder as $propName => $col) {
                 // insert all properties into component
                 if (2 > $col || 'ORDER' == strtoupper($propName)) {
                     continue;
                 }
                 $propName = strtoupper($propName);
                 if ($this->log) {
                     $this->log->log("{$compname} {$propName} START (col={$col})", PEAR_LOG_DEBUG);
                 }
                 if ('X-' != substr($propName, 0, 2) && !in_array($propName, $allowedProps[$compname])) {
                     // check if allowed property for the component
                     if ($this->log) {
                         $this->log->log("skipped {$compname} {$propName}", PEAR_LOG_NOTICE);
                     }
                     continue;
                 }
                 if (isset($rows[$row][$col]) && !empty($rows[$row][$col]) || 'SEQUENCE' == $propName && '0' == $rows[$row][$col]) {
                     $rows[$row][$col] = str_replace(array("\r\n", "\n\r", "\n", "\r"), $conf['nl'], $rows[$row][$col]);
                     $value = FALSE !== strpos($rows[$row][$col], $conf['nl']) ? explode($conf['nl'], $rows[$row][$col]) : array($rows[$row][$col]);
                     $ctests = array('://', 'fax:', 'cid:', 'sms:', 'tel:', 'urn:', 'crid:', 'news:', 'pres:', 'mailto:', 'MAILTO:');
                     foreach ($value as $val) {
                         if (empty($val) && '0' != $val && 0 != $val) {
                             continue;
                         }
                         if ('GEO' == $propName) {
                             $parseval = FALSE !== strpos($val, ':') ? "GEO{$val}" : "GEO:{$val}";
                             if (FALSE === $actcomp->parse($parseval)) {
                                 if ($this->log) {
                                     $this->log->log("ERROR 11, INPUT FILE:'{$inputdirFile}' iCalcreator: parse error: '{$parseval}'", PEAR_LOG_ERR);
                                 }
                             }
                         } elseif ('REQUEST-STATUS' == $propName) {
                             // 'REQUEST-STATUS' without any parameters.. .
                             if (FALSE === $actcomp->parse("{$propName}:{$val}")) {
                                 if ($this->log) {
                                     $this->log->log("ERROR 12, INPUT FILE:'{$inputdirFile}' iCalcreator: parse error: '{$propName}:{$val}'", PEAR_LOG_ERR);
                                 }
                             }
                         }
                         $cntm = $pos = 0;
                         foreach ($ctests as $tst) {
                             $cntm += substr_count($val, $tst);
                         }
                         $cntc = substr_count($val, ':');
                         $cntq = substr_count($val, '=');
                         $cnts = substr_count($val, ';');
                         if (0 == $cntq && 0 == $cnts) {
                             // no parameters
                             $del = ':';
                         } elseif (1 == $cntc && $cntq + 1 == $cnts) {
                             // parameters and colon
                             $del = ';';
                         } elseif ($cntc == $cntm + 1) {
                             $del = ';';
                         } else {
                             $del = 1 > $cntm && 0 < $cntc ? ';' : ':';
                         }
                         if ('X-' == substr($propName, 0, 2) || in_array($propName, array('CATEGORIES', 'COMMENT', 'CONTACT', 'DESCRIPTION', 'LOCATION', 'RESOURCES', 'SUMMARY'))) {
                             $val = str_replace(',', '\\,', $val);
                             if (FALSE !== ($pos = strpos($del . $val, ':'))) {
                                 while (FALSE !== ($pos2 = strpos($val, ';', $pos + 1))) {
                                     $val = substr($val, 0, $pos2) . '\\;' . substr($val, $pos2 + 1);
                                     if ($this->log) {
                                         $this->log->log("pos={$pos} pos2={$pos2} val='{$val}'", PEAR_LOG_DEBUG);
                                     }
                                     $pos = $pos2 + 1;
                                 }
                             }
                         }
                         if (FALSE === $actcomp->parse("{$propName}{$del}{$val}")) {
                             if ($this->log) {
                                 $this->log->log("ERROR 13, INPUT FILE:'{$inputdirFile}' iCalcreator: parse error: '{$propName}{$del}{$val}'", PEAR_LOG_ERR);
                             }
                         } elseif ($this->log) {
                             $this->log->log("iCalcreator->parse( '{$propName}{$del}{$val}' )", PEAR_LOG_DEBUG);
                         }
                     }
                     // end foreach( $value as $val
                 }
                 // end if( isset( $rows[$row][$col]
             }
             // end foreach( $proporder
         }
         // end for( $row = $actrow;
         if ($comp && $subcomp) {
             $comp->setComponent($subcomp);
         }
         if ($comp) {
             $calendar->setComponent($comp);
         }
     }
     $save = $this->getConfig('save');
     if ($this->log) {
         $timeexec['exit'] = microtime(TRUE);
         $msg = "INPUT '{$inputdirFile}'";
         $msg .= ' fileOk:' . number_format($timeexec['fileOk'] - $timeexec['start'], 5);
         $msg .= ' infoOk:' . number_format($timeexec['infoOk'] - $timeexec['fileOk'], 5);
         $msg .= ' zoneOk:' . number_format($timeexec['zoneOk'] - $timeexec['infoOk'], 5);
         $msg .= ' compOk:' . number_format($timeexec['exit'] - $timeexec['zoneOk'], 5);
         $msg .= ' total:' . number_format($timeexec['exit'] - $timeexec['start'], 5) . ' sec';
         $this->log->log($msg, PEAR_LOG_DEBUG);
         $msg = "'{$inputdirFile}' (" . $cntprops . ' components) start:' . date('H:i:s', $timeexec['start']);
         $msg .= ' total:' . number_format($timeexec['exit'] - $timeexec['start'], 5) . ' sec';
         if ($save) {
             $msg .= " -> '{$outputdirFile}'";
         }
         $this->log->log($msg, PEAR_LOG_NOTICE);
     }
     /** return calendar, save or send the file */
     if ($this->getConfig('outputobj')) {
         if ($this->log) {
             $this->log->log("INPUT FILE:'{$inputdirFile}' returning iCalcreator vcalendar instance", PEAR_LOG_NOTICE);
             $this->log->flush();
         }
         return $calendar;
         exit;
     }
     $d = $calendar->getConfig('directory');
     $f = $calendar->getConfig('filename');
     $df = $d . DIRECTORY_SEPARATOR . $f;
     if ($save) {
         if (FALSE !== $calendar->saveCalendar()) {
             if ($this->log) {
                 $this->log->log("INPUT FILE:'{$inputdirFile}' saved '{$df}'", PEAR_LOG_NOTICE);
                 $this->log->flush();
             }
             return TRUE;
         } else {
             // ??
             if ($this->log) {
                 $this->log->log("ERROR 16, INPUT FILE:'{$inputdirFile}' can't write to output file : '{$df}'", PEAR_LOG_ERR);
                 $this->log->flush();
             }
             return FALSE;
         }
     } else {
         if ($this->log) {
             $this->log->log("INPUT FILE:'{$inputdirFile}' returning : '{$f}'", PEAR_LOG_NOTICE);
             $this->log->flush();
         }
         $output = $calendar->createCalendar();
         $filesize = strlen($output);
         if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
             $output = gzencode($output, 9);
             $filesize = strlen($output);
             header('Content-Encoding: gzip');
             header('Vary: *');
         }
         header('Content-Type: text/calendar; charset=utf-8');
         header("Content-Disposition: attachment; filename='{$f}'");
         header('Cache-Control: max-age=10');
         header('Content-Length: ' . $filesize);
         echo $output;
     }
     return TRUE;
 }
예제 #13
0
 /**
  *  Generate ical file content
  *
  * @param $who user ID
  * @param $who_group group ID
  *
  * @return icalendar string
  **/
 static function generateIcal($who, $who_group)
 {
     global $CFG_GLPI, $LANG;
     if ($who == 0 && $who_group == 0) {
         return false;
     }
     include_once GLPI_ROOT . "/lib/icalcreator/iCalcreator.class.php";
     $v = new vcalendar();
     if (!empty($CFG_GLPI["version"])) {
         $v->setConfig('unique_id', "GLPI-Planning-" . trim($CFG_GLPI["version"]));
     } else {
         $v->setConfig('unique_id', "GLPI-Planning-UnknownVersion");
     }
     $v->setConfig('filename', "glpi.ics");
     $v->setProperty("method", "PUBLISH");
     $v->setProperty("version", "2.0");
     $v->setProperty("x-wr-calname", "GLPI-" . $who . "-" . $who_group);
     $v->setProperty("calscale", "GREGORIAN");
     $interv = array();
     $begin = time() - MONTH_TIMESTAMP * 12;
     $end = time() + MONTH_TIMESTAMP * 12;
     $begin = date("Y-m-d H:i:s", $begin);
     $end = date("Y-m-d H:i:s", $end);
     // ---------------Tracking
     $interv = TicketPlanning::populatePlanning(array('who' => $who, 'who_group' => $who_group, 'begin' => $begin, 'end' => $end));
     // ---------------Reminder
     $data = Reminder::populatePlanning(array('who' => $who, 'who_group' => $who_group, 'begin' => $begin, 'end' => $end));
     $interv = array_merge($interv, $data);
     // ---------------Plugin
     $data = doHookFunction("planning_populate", array("begin" => $begin, "end" => $end, "who" => $who, "who_group" => $who_group));
     if (isset($data["items"]) && count($data["items"])) {
         $interv = array_merge($data["items"], $interv);
     }
     if (count($interv) > 0) {
         foreach ($interv as $key => $val) {
             $vevent = new vevent();
             //initiate EVENT
             if (isset($val["tickettasks_id"])) {
                 $vevent->setProperty("uid", "Job#" . $val["tickettasks_id"]);
             } else {
                 if (isset($val["reminders_id"])) {
                     $vevent->setProperty("uid", "Event#" . $val["reminders_id"]);
                 } else {
                     if (isset($val['planningID'])) {
                         // Specify the ID (for plugins)
                         $vevent->setProperty("uid", "Plugin#" . $val['planningID']);
                     } else {
                         $vevent->setProperty("uid", "Plugin#" . $key);
                     }
                 }
             }
             $vevent->setProperty("dstamp", $val["begin"]);
             $vevent->setProperty("dtstart", $val["begin"]);
             $vevent->setProperty("dtend", $val["end"]);
             if (isset($val["tickets_id"])) {
                 $vevent->setProperty("summary", $LANG['planning'][8] . " # " . $val["tickets_id"] . " " . $LANG['document'][14] . " # " . $val["device"]);
             } else {
                 if (isset($val["name"])) {
                     $vevent->setProperty("summary", $val["name"]);
                 }
             }
             if (isset($val["content"])) {
                 $vevent->setProperty("description", html_clean($val["content"]));
             } else {
                 if (isset($val["name"])) {
                     $vevent->setProperty("description", $val["name"]);
                 }
             }
             if (isset($val["tickets_id"])) {
                 $vevent->setProperty("url", $CFG_GLPI["url_base"] . "/index.php?redirect=tracking_" . $val["tickets_id"]);
             }
             $v->setComponent($vevent);
         }
     }
     $v->sort();
     //$v->parse();
     return $v->returnCalendar();
 }
예제 #14
0
 /**
  * Export an event as iCalendar (ics)
  */
 public function generateIcal($eventID)
 {
     $ical = new \vcalendar();
     $ical->setConfig('ical_' . $this->id);
     $ical->setProperty('method', 'PUBLISH');
     $ical->setProperty("X-WR-TIMEZONE", $GLOBALS['TL_CONFIG']['timeZone']);
     $time = time();
     // Get event
     $objEvent = \CalendarEventsModel::findByPk($eventID);
     $vevent = new \vevent();
     if ($objEvent->addTime) {
         $vevent->setProperty('dtstart', array('year' => date('Y', $objEvent->startTime), 'month' => date('m', $objEvent->startTime), 'day' => date('d', $objEvent->startTime), 'hour' => date('H', $objEvent->startTime), 'min' => date('i', $objEvent->startTime), 'sec' => 0));
         $vevent->setProperty('dtend', array('year' => date('Y', $objEvent->endTime), 'month' => date('m', $objEvent->endTime), 'day' => date('d', $objEvent->endTime), 'hour' => date('H', $objEvent->endTime), 'min' => date('i', $objEvent->endTime), 'sec' => 0));
     } else {
         $vevent->setProperty('dtstart', date('Ymd', $objEvent->startDate), array('VALUE' => 'DATE'));
         if (!strlen($objEvent->endDate) || $objEvent->endDate == 0) {
             $vevent->setProperty('dtend', date('Ymd', $objEvent->startDate + 24 * 60 * 60), array('VALUE' => 'DATE'));
         } else {
             $vevent->setProperty('dtend', date('Ymd', $objEvent->endDate + 24 * 60 * 60), array('VALUE' => 'DATE'));
         }
     }
     $vevent->setProperty('summary', $objEvent->title, ENT_QUOTES, 'UTF-8');
     $vevent->setProperty('description', strip_tags($objEvent->details ? $objEvent->details : $objEvent->teaser));
     if ($objEvent->recurring) {
         $count = 0;
         $arrRepeat = deserialize($objEvent->repeatEach);
         $arg = $arrRepeat['value'];
         $unit = $arrRepeat['unit'];
         if ($arg == 1) {
             $unit = substr($unit, 0, -1);
         }
         $strtotime = '+ ' . $arg . ' ' . $unit;
         $newstart = strtotime($strtotime, $objEvent->startTime);
         $newend = strtotime($strtotime, $objEvent->endTime);
         $freq = 'YEARLY';
         switch ($arrRepeat['unit']) {
             case 'days':
                 $freq = 'DAILY';
                 break;
             case 'weeks':
                 $freq = 'WEEKLY';
                 break;
             case 'months':
                 $freq = 'MONTHLY';
                 break;
             case 'years':
                 $freq = 'YEARLY';
                 break;
         }
         $rrule = array('FREQ' => $freq);
         if ($objEvent->recurrences > 0) {
             $rrule['count'] = $objEvent->recurrences;
         }
         if ($arg > 1) {
             $rrule['INTERVAL'] = $arg;
         }
         $vevent->setProperty('rrule', $rrule);
     }
     /*
      * begin module event_recurrences handling
      */
     if ($objEvent->repeatExecptions) {
         $arrSkipDates = deserialize($objEvent->repeatExecptions);
         foreach ($arrSkipDates as $skipDate) {
             $exTStamp = strtotime($skipDate);
             $exdate = array(array(date('Y', $exTStamp), date('m', $exTStamp), date('d', $exTStamp), date('H', $objEvent->startTime), date('i', $objEvent->startTime), date('s', $objEvent->startTime)));
             $vevent->setProperty('exdate', $exdate);
         }
     }
     /*
      * end module event_recurrences handling
      */
     $ical->setComponent($vevent);
     $ical->setConfig("FILENAME", urlencode($objEvent->title) . ".ics");
     $ical->returnCalendar();
 }
예제 #15
0
 /**
  * Export all tasks of a user via iCal
  *
  * @param int $user User ID
  * @param bool $show_long
  * @return bool
  */
 function getIcal($user, $show_long = true)
 {
     $user = (int) $user;
     $show_long = (bool) $show_long;
     $username = $_SESSION["username"];
     $project = new project();
     $myprojects = $project->getMyProjects($user);
     $tasks = array();
     if (!empty($myprojects)) {
         foreach ($myprojects as $proj) {
             $task = $this->getAllMyProjectTasks($proj["ID"], 10000);
             if (!empty($task)) {
                 array_push($tasks, $task);
             }
         }
     }
     $etasks = reduceArray($tasks);
     require "class.ical.php";
     $heute = date("d-m-y");
     $cal = new vcalendar();
     $fname = "tasks_" . $username . ".ics";
     $cal->setConfig('directory', CL_ROOT . '/files/' . CL_CONFIG . '/ics');
     $cal->setConfig('filename', $fname);
     $cal->setConfig('unique_id', '');
     $cal->setProperty('X-WR-CALNAME', "Collabtive Aufgaben für " . $username);
     $cal->setProperty('X-WR-CALDESC', '');
     $cal->setProperty('CALSCALE', 'GREGORIAN');
     $cal->setProperty('METHOD', 'PUBLISH');
     foreach ($etasks as $etask) {
         // split date in Y / M / D / h / min / sek variables
         $jahr = date("Y", $etask["start"]);
         $monat = date("m", $etask["start"]);
         $tag = date("d", $etask["start"]);
         $std = date("h", $etask["start"]);
         $min = date("i", $etask["start"]);
         $sek = date("s", $etask["start"]);
         // split date in Y / M / D / h / min / sek variables
         $ejahr = date("Y", $etask['end']);
         $emonat = date("m", $etask['end']);
         $etag = date("d", $etask['end']);
         $estd = date("h", $etask['end']);
         $emin = date("i", $etask['end']);
         $esek = date("s", $etask['end']);
         $e = new vevent();
         $e->setProperty('categories', $etask['list']);
         if ($show_long) {
             // if we have a task lasting 10 month, normally it will be displayed every day within this time span.
             $e->setProperty('dtstart', $jahr, $monat, $tag, $std, $min);
             // 24 dec 2007 19.30
         } else {
             // if the show_long flag is set, it will only be shown at the due date
             $e->setProperty('dtstart', $ejahr, $emonat, $etag, $estd, $emin);
         }
         $e->setProperty('due', $ejahr, $emonat, $etag, $estd, $emin);
         // 24 dec 2007 19.30
         $e->setProperty('dtend', $ejahr, $emonat, $etag, $estd, $emin);
         $e->setProperty('description', $etask["text"]);
         $e->setProperty('status', "NEEDS-ACTION");
         // $e->setProperty('comment' , $etask[text]);
         $e->setProperty('summary', $etask["title"]);
         $e->setProperty('location', 'Work');
         $cal->setComponent($e);
     }
     $cal->returnCalendar();
     return true;
 }
예제 #16
0
 /**
  * return initialized calendar tool class for ics export
  * 
  * @return object
  */
 function getCalendarTool()
 {
     require_once JPATH_SITE . DS . 'components' . DS . 'com_redevent' . DS . 'classes' . DS . 'iCalcreator.class.php';
     $mainframe =& JFactory::getApplication();
     $offset = (double) $mainframe->getCfg('offset');
     $timezone_name = self::getTimeZone($offset);
     $vcal = new vcalendar();
     // initiate new CALENDAR
     if (!file_exists(JPATH_SITE . DS . 'cache' . DS . 'com_redevent')) {
         jimport('joomla.filesystem.folder');
         JFolder::create(JPATH_SITE . DS . 'cache' . DS . 'com_redevent');
     }
     $vcal->setConfig('directory', JPATH_SITE . DS . 'cache' . DS . 'com_redevent');
     $vcal->setProperty('unique_id', 'events@' . $mainframe->getCfg('sitename'));
     $vcal->setProperty("calscale", "GREGORIAN");
     $vcal->setProperty('method', 'PUBLISH');
     if ($timezone_name) {
         $vcal->setProperty("X-WR-TIMEZONE", $timezone_name);
     }
     return $vcal;
 }
예제 #17
0
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

error_reporting(E_ERROR);

require_once( 'iCalcreator.class.php' );
require_once( 'tz.php' );
$out = new vcalendar();
$v = new vcalendar(); // create a new calendar instance
$out->setXprop("X-WR-CALNAME","Facebook events");
$out->setConfig( 'unique_id', 'tevp.net-projects-calendars-fbevents' ); // set Your unique id, required if property UID is missing
$out->setProperty( 'method', 'PUBLISH' ); // required of some calendar software

$uid = $_GET["uid"];
$key = $_GET["key"];
$timezone = $_GET["timezone"];
$fb_url = $_GET["fb_url"];

if (!isset($timezone))
	$timezone = "Europe/London";

if (isset($action) && $action == "generate")
{
	preg_match("/fbcalendar.com\/cal\/(\d+)\/([\da-z]+)-\d+\/events\/ics/", $fb_url, $matches);
	if (count($matches) == 3)
	{
		$url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?uid=".$matches[1]."&key=".$matches[2]."&timezone=".$timezone;
예제 #18
0
 function display($tpl = null)
 {
     // Get a reference of the page instance in joomla
     $document = JFactory::getDocument();
     $model = $this->getModel();
     $project = $model->getProject();
     //$config		= $model->getTemplateConfig($this->getName());
     if (isset($project)) {
         $this->project = $project;
     }
     $this->overallconfig = $model->getOverallConfig();
     $this->config = $this->overallconfig;
     $this->matches = $model->getMatches();
     $this->teams = $model->getTeamsFromMatches($this->matches);
     // load a class that handles ical formats.
     require_once JLG_PATH_SITE . DS . 'helpers' . DS . 'iCalcreator.class.php';
     // create a new calendar instance
     $v = new vcalendar();
     foreach ($this->matches as $match) {
         $hometeam = $this->teams[$match->team1];
         $home = sprintf('%s', $hometeam->name);
         $guestteam = $this->teams[$match->team2];
         $guest = sprintf('%s', $guestteam->name);
         $summary = $match->project_name . ': ' . $home . ' - ' . $guest;
         //  check if match gots a date, if not it will not be included in ical
         if ($match->match_date) {
             $totalMatchTime = isset($project) ? $project->halftime * ($project->game_parts - 1) + $project->game_regular_time : 90;
             $start = JoomleagueHelper::getMatchStartTimestamp($match, 'Y-m-d H:i:s');
             $end = JoomleagueHelper::getMatchEndTimestamp($match, $totalMatchTime, 'Y-m-d H:i:s');
             // check if exist a playground in match or team or club
             $stringlocation = '';
             $stringname = '';
             if (!empty($match->playground_id)) {
                 $stringlocation = $match->playground_address . ", " . $match->playground_zipcode . " " . $match->playground_city;
                 $stringname = $match->playground_name;
             } elseif (!empty($match->team_playground_id)) {
                 $stringlocation = $match->team_playground_address . ", " . $match->team_playground_zipcode . " " . $match->team_playground_city;
                 $stringname = $match->team_playground_name;
             } elseif (!empty($match->club_playground_id)) {
                 $stringlocation = $match->club_playground_address . ", " . $match->club_playground_zipcode . " " . $match->club_playground_city;
                 $stringname = $match->club_playground_name;
             }
             $location = $stringlocation;
             //if someone want to insert more in description here is the place
             $description = $stringname;
             // create an event and insert it in calendar
             $vevent = new vevent();
             $timezone = JoomleagueHelper::getMatchTimezone($match);
             $vevent->setProperty("dtstart", $start, array("TZID" => $timezone));
             $vevent->setProperty("dtend", $end, array("TZID" => $timezone));
             $vevent->setProperty('LOCATION', $location);
             $vevent->setProperty('summary', $summary);
             $vevent->setProperty('description', $description);
             $v->setComponent($vevent);
         }
     }
     $v->setProperty("X-WR-TIMEZONE", $timezone);
     $xprops = array("X-LIC-LOCATION" => $timezone);
     iCalUtilityFunctions::createTimezone($v, $timezone, $xprops);
     $v->returnCalendar();
     //$debugstr = $v->createCalendar();
     //echo "<pre>";
     //echo $debugstr;
     // exit before display
     //		parent::display( $tpl );
 }
예제 #19
0
         }
     }
     break;
     // generate an ical feed
 // generate an ical feed
 case 'icalfeed':
     // the permissions for the single modules
     $permissions = array('calendar' => 'po_calendarevent');
     $modulename = registry::register('input')->get('module', '');
     // check for permission
     $userid = registry::fetch('user')->getUserIDfromExchangeKey(registry::register('input')->get('key', ''));
     if (isset($permissions[$modulename]) && registry::fetch('user')->check_auth($permissions[$modulename], false, $userid)) {
         require $eqdkp_root_path . 'libraries/icalcreator/iCalcreator.class.php';
         $v = new vcalendar();
         $v->setConfig('unique_id', registry::register('config')->get('server_name'));
         $v->setProperty('x-wr-calname', sprintf(registry::fetch('user')->lang('icalfeed_name'), registry::register('config')->get('guildtag')));
         $v->setProperty('X-WR-CALDESC', registry::fetch('user')->lang('icalfeed_description'));
         // set the timezone - required by some clients
         $timezone = registry::register('config')->get('timezone');
         $v->setProperty("X-WR-TIMEZONE", $timezone);
         iCalUtilityFunctions::createTimezone($v, $timezone, array("X-LIC-LOCATION" => $timezone));
         switch ($modulename) {
             case 'calendar':
                 $eventtypes = registry::register('input')->get('type', 'raids');
                 switch ($eventtypes) {
                     case 'raids':
                         $eventsfilter = true;
                         break;
                     case 'all':
                         $eventsfilter = false;
                         break;
 /**
  * @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";
 }
예제 #21
0
// Optionally filter down to specific brewer
if (isset($filter) && !empty($filter) && 'all' != $filter) {
    $query_brewLogs .= sprintf(' AND brewBrewerID = \'%s\'', $filter);
    $query_upcoming .= sprintf(' AND brewBrewerID = \'%s\'', $filter);
    // Update the title
    $user_query = 'SELECT realFirstName, realLastName 
                     FROM users
                    WHERE user_name = \'%s\'';
    $user_result = mysql_query(sprintf($user_query, $filter));
    if (!$user_result) {
        throw new Exception(mysql_error());
    }
    $user = mysql_fetch_assoc($user_result);
    $title = $user['realFirstName'] . ' ' . $user['realLastName'] . "'s " . $row_pref['menuCalendar'];
}
$cal->setProperty('x-wr-calname', $title);
// BrewBlogs with upcoming dates
$brews = mysql_query($query_brewLogs);
if (!$brews) {
    throw new Exception(mysql_error());
}
while ($row = mysql_fetch_assoc($brews)) {
    $brewDate = new BrewDate($row['brewDate']);
    $event = $brewDate->createVevent($cal);
    $event->setProperty('summary', 'Brew ' . $row['brewName']);
    $event->setProperty('description', urlForBrew($row['id'], $row['brewBrewerId']));
    // See what other steps we have
    $steps = array();
    foreach (array('brewPrimary', 'brewSecondary', 'brewTertiary', 'brewLager', 'brewAge') as $key) {
        if (!empty($row[$key])) {
            $steps[] = $key;
예제 #22
0
파일: index.php 프로젝트: phy25/bPlanner
 foreach ($t2 as $v) {
     // Merge itself
     if ($v instanceof LessonBITDeletion) {
         $t2MergedDeletion = $school->mergeChangedLesson($t2MergedDeletion, $v, 1);
     }
     /*else{
     		$t2Merged = $school->mergeChangedLesson($t2Merged, $v);
     	  }*/
     // Merge changes
     $t1 = $school->mergeChangedLesson($t1, $v);
 }
 $school->mergeNearSchedule($t1);
 $config = array("unique_id" => "bPlanner.phy25.com", "TZID" => "Asia/Shanghai");
 $v = new vcalendar($config);
 // create a new calendar object instance
 $v->setProperty("method", "PUBLISH");
 // required of some calendar software
 $v->setProperty("x-wr-calname", $tables[0]['stuname'] . "的课表 " . $tables[0]['year'] . '-' . $tables[0]['term']);
 // required of some calendar software
 $v->setProperty("X-WR-CALDESC", "");
 // required of some calendar software
 $v->setProperty("X-WR-TIMEZONE", "Asia/Shanghai");
 // required of some calendar software
 foreach ($t1 as $o) {
     $odata = array('name' => $o->name, 'credit' => $o->credit, 'tutor' => $o->tutor, 'schedule' => $o->schedule);
     if (count($o->schedule)) {
         foreach ($o->schedule as $os) {
             $startTimeTrans = array([], ['8', '00'], ['8', '50'], ['9', '50'], ['10', '40'], ['11', '30'], ['13', '20'], ['14', '10'], ['15', '10'], ['16', '00'], ['16', '50'], ['18', '30'], ['19', '20'], ['20', '10']);
             $endTimeTrans = array([], ['8', '45'], ['9', '35'], ['10', '35'], ['11', '25'], ['12', '15'], ['14', '05'], ['14', '55'], ['15', '55'], ['16', '45'], ['17', '35'], ['19', '15'], ['20', '05'], ['20', '55']);
             $dateArr = $school->getSchoolCalendar2Date($tables[0]['year'], $tables[0]['term'], $os->week[0], $os->day);
             $vevent = $v->newComponent("vevent");
예제 #23
0
$id = $id[1];
$agenda = new Agenda();
$agenda->type = $type;
//course,admin or personal
if (isset($_GET['course_id'])) {
    $course_info = api_get_course_info_by_id($_GET['course_id']);
    if (!empty($course_info)) {
        $agenda->set_course($course_info);
    }
}
$event = $agenda->get_event($id);
if (!empty($event)) {
    define('ICAL_LANG', api_get_language_isocode());
    $ical = new vcalendar();
    $ical->setConfig('unique_id', api_get_path(WEB_PATH));
    $ical->setProperty('method', 'PUBLISH');
    $ical->setConfig('url', api_get_path(WEB_PATH));
    $vevent = new vevent();
    switch ($_GET['class']) {
        case 'public':
            $vevent->setClass('PUBLIC');
            break;
        case 'private':
            $vevent->setClass('PRIVATE');
            break;
        case 'confidential':
            $vevent->setClass('CONFIDENTIAL');
            break;
        default:
            $vevent->setClass('PRIVATE');
            break;
  public function getIcal($studio = null) {
 
    error_reporting(0);
 
    sfProjectConfiguration::getActive()->loadHelpers(array("Number","Url","Date")); 
    
    require_once sfConfig::get('sf_lib_dir').'/vendor/icalcreator/iCalcreator.class.php';

    error_reporting(E_ALL ^ E_NOTICE);

    $config = array( "unique_id" => "downtownswing.rockstep.ch" );
    $v = new vcalendar( $config );
    
    $v->setProperty( "method",
                     "PUBLISH" );
    $v->setProperty( "X-WR-CALNAME",
                     "Downtownswing Kurse" );
    $v->setProperty( "X-WR-CALDESC",
                     "" );
    //$vcalendar->setProperty( "X-WR-RELCALID", $uuid );
    $v->setProperty( "X-WR-TIMEZONE",
                     "Europe/Zurich" ); 
    
    // TODO
    // - filter für kommende, publizierte artikel (model)
    // - verarbeitung von gecancelten events
    // - event uuid in db speichern und hier einsetzen (model, on publish, für updates + cancels)
    
    $lessons = Doctrine_Core::getTable('dsLesson')
    ->createQuery('a')
    ->execute();
    
    // todo
    // join dance, teachers, ..
  
    foreach( $lessons as $lesson ) {
      
      $e = & $v->newComponent( 'vevent' );
      
      $e->setUid( $lesson->getIcalUID() );
      $e->setSequence( $lesson->getIcalSequence() );
      
      $e->setProperty( 'categories'
                     , $lesson->getDance() );
      // $e->setProperty( 'dtstart', '2012-01-06 20:00:00' );
      
      $e->setProperty( 'dtstart', 
            $lesson->getDateTimeObject('date')->format('Y'), // date("Y", $lesson->getDate()), // date("Y", $lesson->getDateTimeObject('date')->format('Y') ),
            $lesson->getDateTimeObject('date')->format('m'), // date("m", $lesson->getDate()), //date("m", $lesson->getDateTimeObject('date')->format('m') ),
            $lesson->getDateTimeObject('date')->format('d'), // date("d", $lesson->getDate()), //date("d", $lesson->getDateTimeObject('date')->format('d') ),
            date('H', strtotime($lesson->getTime())),
            date('i', strtotime($lesson->getTime())),
            00);
     
      $e->setProperty( 'duration',
                        array( "min" => $lesson->getDuration() ));
      
     
      // summary
      $summary = $lesson->getName() ;
      $e->setProperty( "summary", strip_tags($summary));
      
      // description
      $description = $lesson->getClass()->getDance().", ".
        $lesson->getClass()->getTrack()->getType()."\r\n".
        $lesson->getClass()."\r\n".
        $lesson->getTeachersAsString();
      $e->setProperty( 'description',
                       $description );

      // location
      /*
      $e->setProperty( 'location',
                       strip_tags($lesson->getStudio()) );
      */
      /*
      $request = sfContext::getInstance()->getRequest();
      $url  = 'http'.($request->isSecure() ? 's' : '').'://'. $request->getHost();
      $url .= url_for('event_show',$event);
      
      $e->setProperty( "url",
                       strip_tags($url ));
      */
                             /*
      $e->setProperty( "contact", strip_tags($concert->getContact() ));
          //$e->setProperty( "organizer", strip_tags($concert->getContact() ));
          //$e->setProperty( "geo", 11.23456, -23.45678 );
       */
      
      $e->setProperty( 'last-modified' ,
                           $this->datestring2icalArr( $lesson->getCreatedAt() ));
      /*
      if($lesson->getUpdatedAt())
          $e->setProperty( 'last-modified' ,
                           $this->datestring2icalArr( $event->getUpdatedAt() ));
      else
          $e->setProperty( 'last-modified' ,
                           $this->datestring2icalArr( $event->getCreatedAt() ));
      }
      */
      }

      /* alt. production */
      //$v->returnCalendar();                       // generate and redirect output to user browser
      /* alt. dev. and test */
      //$this->ical = $v->createCalendar();         // generate and get output in string, for testing?
      //**
      //return sfView::NONE;

     return $v;
 }
 public function generate_ical()
 {
     $eventdata = $this->pdh->get('calendar_events', 'data', array($this->url_id));
     require $this->root_path . 'libraries/icalcreator/iCalcreator.class.php';
     $v = new vcalendar();
     $v->setConfig('unique_id', $this->config->get('server_name'));
     $v->setProperty('x-wr-calname', sprintf(registry::fetch('user')->lang('icalfeed_name'), registry::register('config')->get('guildtag')));
     $v->setProperty('X-WR-CALDESC', registry::fetch('user')->lang('icalfeed_description'));
     // set the timezone - required by some clients
     $timezone = registry::register('config')->get('timezone');
     $v->setProperty("X-WR-TIMEZONE", $timezone);
     iCalUtilityFunctions::createTimezone($v, $timezone, array("X-LIC-LOCATION" => $timezone));
     // Generate the vevents...
     $e = new vevent();
     $e->setProperty('dtstart', array("timestamp" => $eventdata['timestamp_start'] . 'Z'));
     $e->setProperty('dtend', array("timestamp" => $eventdata['timestamp_end'] . 'Z'));
     $e->setProperty('dtstamp', array("timestamp" => $this->time->time));
     $e->setProperty('summary', $this->pdh->get('event', 'name', array($eventdata['extension']['raid_eventid'])));
     $e->setProperty('description', $eventdata['notes']);
     $e->setProperty('class', 'PUBLIC');
     $e->setProperty('categories', 'PERSONAL');
     $v->setComponent($e);
     // Save or Output the ICS File..
     if ($icsfile == true) {
         $v->setConfig('filename', $icsfile);
         $v->saveCalendar();
     } else {
         header('Content-type: text/calendar; charset=utf-8;');
         header('Content-Disposition: filename=raidevent-' . $eventdata['timestamp_start'] . '.ics');
         echo $v->createCalendar();
         exit;
     }
 }
예제 #26
0
 * @copyright 2007-2011 Allon Moritz
 * @since 2.2.0
 */
defined('_JEXEC') or die;
include_once JPATH_BASE . '/components/com_gcalendar/libraries/ical/iCalcreator.class.php';
$event = $this->event;
$config = array('unique_id' => $event->getGCalId());
$v = new vcalendar($config);
$v->prodid = 'GCalendar';
$path = JPATH_ADMINISTRATOR . '/components/com_gcalendar/gcalendar.xml';
if (file_exists($path)) {
    $manifest = simplexml_load_file($path);
    $v->version = $manifest->version;
}
$tz = 'UTC';
$v->setProperty('method', 'PUBLISH');
$v->setProperty("x-wr-calname", $event->getParam('gcname'));
$v->setProperty("X-WR-CALDESC", "");
$v->setProperty("X-WR-TIMEZONE", $tz);
$xprops = array("X-LIC-LOCATION" => $tz);
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
    iCalUtilityFunctions::createTimezone($v, $tz, $xprops);
}
$vevent =& $v->newComponent('vevent');
if ($event->getDayType() == GCalendar_Entry::SINGLE_WHOLE_DAY || $event->getDayType() == GCalendar_Entry::MULTIPLE_WHOLE_DAY) {
    $vevent->setProperty('dtstart', $event->getStartDate()->format('Ymd'));
    $vevent->setProperty('dtend', $event->getEndDate()->format('Ymd'));
} else {
    $vevent->setProperty('dtstart', $event->getStartDate()->format('YmdHis'));
    $vevent->setProperty('dtend', $event->getEndDate()->format('YmdHis'));
}
 /**
  * export_events function
  *
  * Export events
  *
  * @return void
  **/
 function export_events()
 {
     global $ai1ec_events_helper, $ai1ec_exporter_helper, $ai1ec_localization_helper;
     $ai1ec_cat_ids = !empty($_REQUEST['ai1ec_cat_ids']) ? $_REQUEST['ai1ec_cat_ids'] : false;
     $ai1ec_tag_ids = !empty($_REQUEST['ai1ec_tag_ids']) ? $_REQUEST['ai1ec_tag_ids'] : false;
     $ai1ec_post_ids = !empty($_REQUEST['ai1ec_post_ids']) ? $_REQUEST['ai1ec_post_ids'] : false;
     if (!empty($_REQUEST['lang'])) {
         $ai1ec_localization_helper->set_language($_REQUEST['lang']);
     }
     $filter = array();
     if ($ai1ec_cat_ids) {
         $filter['cat_ids'] = explode(',', $ai1ec_cat_ids);
     }
     if ($ai1ec_tag_ids) {
         $filter['tag_ids'] = explode(',', $ai1ec_tag_ids);
     }
     if ($ai1ec_post_ids) {
         $filter['post_ids'] = explode(',', $ai1ec_post_ids);
     }
     // when exporting events by post_id, do not look up the event's start/end date/time
     $start = $ai1ec_post_ids !== false ? false : Ai1ec_Time_Utility::current_time(true) - 24 * 60 * 60;
     // Include any events ending today
     $end = false;
     $c = new vcalendar();
     $c->setProperty('calscale', 'GREGORIAN');
     $c->setProperty('method', 'PUBLISH');
     $c->setProperty('X-WR-CALNAME', get_bloginfo('name'));
     $c->setProperty('X-WR-CALDESC', get_bloginfo('description'));
     $c->setProperty('X-FROM-URL', home_url());
     // Timezone setup
     $tz = Ai1ec_Meta::get_option('timezone_string');
     if ($tz) {
         $c->setProperty('X-WR-TIMEZONE', $tz);
         $tz_xprops = array('X-LIC-LOCATION' => $tz);
         iCalUtilityFunctions::createTimezone($c, $tz, $tz_xprops);
     }
     $events = $ai1ec_events_helper->get_matching_events($start, $end, $filter);
     foreach ($events as $event) {
         $ai1ec_exporter_helper->insert_event_in_calendar($event, $c, $export = true);
     }
     $str = ltrim($c->createCalendar());
     header('Content-type: text/calendar; charset=utf-8');
     echo $str;
     exit;
 }
예제 #28
0
?>
        <div class="settingsbottom"></div></div>
    </td><td class="layout_rcolumn">
        <div class="banner60 pad020 text32"><?php 
echo _('Settings');
?>
</div>
        <div class="banner50 pad020 text16 fuscia_text"><?php 
echo _('ICal Events');
?>
</div>
        <div class="contentfull">
   <?php 
//start
$c = new vcalendar(array('unique_id' => 'ofuz.net'));
$c->setProperty("method", "PUBLISH");
// required of some calendar software
$c->setProperty("x-wr-calname", "Ofuz Task");
// required of some calendar software
$c->setProperty("X-WR-CALDESC", "Ofuz Task Description");
// required of some calendar software
//$c->setProperty( 'X-WR-CALNAME', 'Ofuz tasks' );
//$c->setProperty( 'X-WR-CALDESC', 'Description of the calendar' );
//echo "<br />";
$vivek = new task();
//echo $_SESSION['do_User']->iduser."<br /><br />";
//$users=$vivek->getAllTaskuser();
//print_r($users);
//echo "<br />";
$iduser = $_SESSION['do_User']->iduser;
//echo $user;
예제 #29
0
 /**
  * Export the Event with calendar and stop excuting script
  *      
  * @return null
  */
 function export()
 {
     global $_CONFIG;
     //create new calendar
     $objVCalendar = new \vcalendar();
     $objVCalendar->setConfig('unique_id', $_CONFIG['coreGlobalPageTitle']);
     $objVCalendar->setConfig('filename', urlencode($this->title) . '.ics');
     // set Your unique id
     //$v->setProperty('X-WR-CALNAME', 'Calendar Sample');
     //$v->setProperty('X-WR-CALDESC', 'Calendar Description');
     //$v->setProperty('X-WR-TIMEZONE', 'America/Los_Angeles');
     $objVCalendar->setProperty('X-MS-OLK-FORCEINSPECTOROPEN', 'TRUE');
     $objVCalendar->setProperty('METHOD', 'PUBLISH');
     // create an event calendar component
     $objVEvent = new \vevent();
     // start
     $startYear = date("Y", $this->startDate);
     $startMonth = date("m", $this->startDate);
     $startDay = date("d", $this->startDate);
     $startHour = date("H", $this->startDate);
     $startMinute = date("i", $this->startDate);
     $objVEvent->setProperty('dtstart', array('year' => $startYear, 'month' => $startMonth, 'day' => $startDay, 'hour' => $startHour, 'min' => $startMinute, 'sec' => 0));
     // end
     $endYear = date("Y", $this->endDate);
     $endMonth = date("m", $this->endDate);
     $endDay = date("d", $this->endDate);
     $endHour = date("H", $this->endDate);
     $endMinute = date("i", $this->endDate);
     $objVEvent->setProperty('dtend', array('year' => $endYear, 'month' => $endMonth, 'day' => $endDay, 'hour' => $endHour, 'min' => $endMinute, 'sec' => 0));
     // place
     if (!empty($this->place)) {
         $objVEvent->setProperty('location', html_entity_decode($this->place, ENT_QUOTES, CONTREXX_CHARSET));
     }
     // title
     $objVEvent->setProperty('summary', html_entity_decode($this->title, ENT_QUOTES, CONTREXX_CHARSET));
     // description
     $objVEvent->setProperty('description', html_entity_decode(strip_tags($this->description), ENT_QUOTES, CONTREXX_CHARSET));
     // organizer
     $objVEvent->setProperty('organizer', $_CONFIG['coreGlobalPageTitle'] . ' <' . $_CONFIG['coreAdminEmail'] . '>');
     // comment
     //$objVEvent->setProperty( 'comment', 'This is a comment' );
     // attendee
     //$objVEvent->setProperty( 'attendee', '*****@*****.**' );
     // ressourcen
     //$objVEvent->setProperty( 'resources', 'COMPUTER PROJECTOR' );
     // series type
     //$objVEvent->setProperty( 'rrule', array( 'FREQ' => 'WEEKLY', 'count' => 4));// weekly, four occasions
     // add event to calendar
     $objVCalendar->setComponent($objVEvent);
     $objVCalendar->returnCalendar();
     exit;
 }
예제 #30
0
 /**
  * Export to the specified format
  * @param array	$input	-	ATutor dates to be exported
  * @param int $mode	-	Mode of operation of export [ 0 | 1 ] 
  *							*	mode 0 - returns the exported dates as a string
  *							* 	mode 1 - returns the name of the file that has the exported dates
  * @param string $format - Export Format	DEFAULT 'ical'
  * @return string
  * @author Anurup Raveendran
  *
  */
 function cal_export($input = null, $mode, $format = 'ical')
 {
     $cal = "";
     //output
     $user = "";
     if ($input == null) {
         $time_zone = "";
     } else {
         $time_zone = $input['timezone'];
     }
     global $db;
     require_once 'iCalcreator.class.php';
     require_once 'html_parser.inc.php';
     $v = new vcalendar(array('unique_id' => 'Inclusive Design Insitute'));
     //create an instance of the ical obj
     // ADD EXTRA DETAILS
     if (isset($_SESSION['member_id'])) {
         // GET USER DETAILS
         $m_id = $_SESSION['member_id'];
         // GET TIME ZONE
         // CHECK USER TABLE FOR PREF_TIMEZONE
         $sql = "SELECT first_name,last_name,preferences FROM " . TABLE_PREFIX . "members WHERE member_id='" . $m_id . "'";
         $result = mysql_query($sql, $db) or die(mysql_error());
         $row = mysql_fetch_assoc($result);
         $user = $row['first_name'] . ' ' . $row['last_name'];
         if ($time_zone == "") {
             $prefs = unserialize($row['preferences']);
             $time_zone_offset = $prefs['PREF_TIMEZONE'];
             if ($time_zone_offset == "") {
                 // CHECK CONFIG TABLE SET BY ADMIN
                 $sql = "SELECT value \n\t\t\t\t\tFROM " . TABLE_PREFIX . "config\n\t\t\t\t\tWHERE name='pref_defaults'";
                 $result = mysql_query($sql, $db) or die(mysql_error());
                 if (mysql_num_rows($result) > 0) {
                     //pref_defaults is set
                     $row = mysql_fetch_row($result);
                     $prefs = unserialize($row[0]);
                     $time_zone_offset = $prefs['PREF_TIMEZONE'];
                 }
             }
             if ($time_zone_offset != "") {
                 $sql = "SELECT time_zone \n\t\t\t\t\t\tFROM " . TABLE_PREFIX . "calendar_timezone_offset \n\t\t\t\t\t\tWHERE offset='" . $time_zone_offset . "'";
                 $result = mysql_query($sql, $db) or die(mysql_error());
                 $row = mysql_fetch_row($result);
                 $time_zone = $row[0];
             } else {
                 // GET TIMEZONE FROM SERVER
                 $version = phpversion();
                 $version = str_replace('Current PHP version: ', '', $version);
                 $version = explode('.', $version);
                 if ($version[0] > 4) {
                     $time_zone = date_default_timezone_get();
                 } else {
                     // get from ini file
                     $time_zone = ini_get('date.timezone');
                 }
                 $sql = "SELECT offset \n\t\t\t\t\t\t\tFROM " . TABLE_PREFIX . "calendar_timezone_offset \n\t\t\t\t\t\t\tWHERE time_zone='" . $time_zone . "'";
                 $result = mysql_query($sql, $db) or die(mysql_error());
                 $row = mysql_fetch_row($result);
                 $time_zone_offset = $row[0];
             }
         } else {
             $sql = "SELECT offset \n\t\t\t\t\t\t\tFROM " . TABLE_PREFIX . "calendar_timezone_offset \n\t\t\t\t\t\t\tWHERE time_zone='" . $time_zone . "'";
             $result = mysql_query($sql, $db) or die(mysql_error());
             $row = mysql_fetch_row($result);
             $time_zone_offset = $row[0];
         }
     }
     /** HEADER **/
     $v->setProperty('X-WR-CALNAME', $user);
     $v->setProperty('X-WR-CALDESC', 'ATutor Dates');
     $v->setProperty('X-WR-TIMEZONE', $time_zone);
     // set the ical timezone component
     $e =& $v->newComponent('vtimezone');
     $e->setProperty('TZID', $time_zone);
     $e->setProperty('X-LIC-LOCATION', $time_zone);
     $t =& $e->newComponent('standard');
     $t->setProperty('tzoffsetfrom', $this->get_tz_offset($time_zone_offset));
     $t->setProperty('tzoffsetto', $this->get_tz_offset($time_zone_offset));
     $t->setProperty('dtstart', 1970, 1, 1, 0, 0, 00);
     /** HEADER **/
     // NOW LOAD THE EVENTS
     global $moduleFactory;
     $coursesmod = $moduleFactory->getModule("_core/courses");
     $assignmentsmod = $moduleFactory->getModule("_standard/assignments");
     $testsmod = $moduleFactory->getModule("_standard/tests");
     // GET ALL THE COURSES THE USER IS ENROLLED IN
     $sql = "SELECT course_id\n            \tFROM " . TABLE_PREFIX . "course_enrollment \n            \tWHERE member_id = '" . $_SESSION['member_id'] . "'";
     $course_result = mysql_query($sql, $db) or die(mysql_error());
     while ($row = mysql_fetch_row($course_result)) {
         $course = $coursesmod->extend_date($row[0]);
         $course = $course[0];
         // get the dates
         $course_start_unix_ts = $course[0]['unixts'];
         $course_end_unix_ts = $course[1]['unixts'];
         $cs =& $v->newComponent('vevent');
         // initiate COURSE_START event
         $cs->setProperty('dtstart', date("Y", $course_start_unix_ts), date("n", $course_start_unix_ts), date("j", $course_start_unix_ts), date("G", $course_start_unix_ts), date("m", $course_start_unix_ts), date("i", $course_start_unix_ts));
         // COURSE_START DTSTART
         $cs->setProperty('dtend', date("Y", $course_start_unix_ts), date("n", $course_start_unix_ts), date("j", $course_start_unix_ts), date("G", $course_start_unix_ts), date("m", $course_start_unix_ts), date("i", $course_start_unix_ts));
         // COURSE_START DTEND
         $cs->setProperty('dtstamp', date("Y"), date("n"), date("j"), date("G"), date("m"), date("i"));
         // CALENDAR TS
         //parse the html content to get the summary
         $html = str_get_html($course[0]['content']);
         foreach ($html->find('div.content') as $d) {
             $div = $d;
         }
         foreach ($div->find('span.module') as $m) {
             $module = $m->innertext;
         }
         foreach ($div->find('span.title') as $tl) {
             $title = $tl->innertext;
         }
         foreach ($div->find('span.content') as $c) {
             $content = $c->innertext;
         }
         unset($html);
         unset($div);
         $summary = $module . $title . $content;
         $cs->setProperty('summary', $summary);
         // SUMMARY
         $cs->setProperty('sequence', 0);
         // SEQUENCE NUMBER
         $cs->setProperty('status', 'CONFIRMED');
         // STATUS
         $cs->setProperty('transp', 'TRANSPARENT');
         // TRANSPARENCY
         $ce =& $v->newComponent('vevent');
         // initiate COURSE_END event
         $ce->setProperty('dtstart', date("Y", $course_end_unix_ts), date("n", $course_end_unix_ts), date("j", $course_end_unix_ts), date("G", $course_end_unix_ts), date("m", $course_end_unix_ts), date("i", $course_end_unix_ts));
         // COURSE_END DTSTART
         $ce->setProperty('dtend', date("Y", $course_end_unix_ts), date("n", $course_end_unix_ts), date("j", $course_end_unix_ts), date("G", $course_end_unix_ts), date("m", $course_end_unix_ts), date("i", $course_end_unix_ts));
         // COURSE_END DTEND
         $ce->setProperty('dtstamp', date("Y"), date("n"), date("j"), date("G"), date("m"), date("i"));
         // CALENDAR TS
         //parse the html content to get the summary
         $html = str_get_html($course[1]['content']);
         foreach ($html->find('div.content') as $d) {
             $div = $d;
         }
         foreach ($div->find('span.module') as $m) {
             $module = $m->innertext;
         }
         foreach ($div->find('span.title') as $tl) {
             $title = $tl->innertext;
         }
         foreach ($div->find('span.content') as $c) {
             $content = $c->innertext;
         }
         unset($html);
         unset($div);
         $summary = $module . $title . $content;
         $ce->setProperty('summary', $summary);
         // SUMMARY
         $ce->setProperty('sequence', 0);
         // SEQUENCE NUMBER
         $ce->setProperty('status', 'CONFIRMED');
         // STATUS
         $ce->setProperty('transp', 'TRANSPARENT');
         // TRANSPARENCY
         //GET THE ASSIGNMENTS FOR THIS COURSE
         $assignments = $assignmentsmod->extend_date($row[0]);
         foreach ($assignments as $key => $assignment) {
             // get the dates
             $assignment_due_unix_ts = $assignment[0]['unixts'];
             $assignment_cutoff_unix_ts = $assignment[1]['unixts'];
             $ad =& $v->newComponent('vevent');
             // initiate ASSIGNMENT_DUE event
             $ad->setProperty('dtstart', date("Y", $assignment_due_unix_ts), date("n", $assignment_due_unix_ts), date("j", $assignment_due_unix_ts), date("G", $assignment_due_unix_ts), date("m", $assignment_due_unix_ts), date("i", $assignment_due_unix_ts));
             // ASSIGNMENT_DUE DTSTART
             $ad->setProperty('dtend', date("Y", $assignment_due_unix_ts), date("n", $assignment_due_unix_ts), date("j", $assignment_due_unix_ts), date("G", $assignment_due_unix_ts), date("m", $assignment_due_unix_ts), date("i", $assignment_due_unix_ts));
             // ASSIGNMENT_DUE DTEND
             $ad->setProperty('dtstamp', date("Y"), date("n"), date("j"), date("G"), date("m"), date("i"));
             // WHEN THE CAL WAS EXPORTED
             //parse the html content to get the summary
             $html = str_get_html($assignment[0]['content']);
             foreach ($html->find('div.content') as $d) {
                 $div = $d;
             }
             foreach ($div->find('span.module') as $m) {
                 $module = $m->innertext;
             }
             foreach ($div->find('span.title') as $tl) {
                 $title = $tl->innertext;
             }
             foreach ($div->find('span.content') as $c) {
                 $content = $c->innertext;
             }
             unset($html);
             unset($div);
             $summary = $module . $title . $content;
             $ad->setProperty('summary', $summary);
             // SUMMARY
             $ad->setProperty('sequence', 0);
             $ad->setProperty('status', 'CONFIRMED');
             // STATUS
             $ad->setProperty('transp', 'TRANSPARENT');
             // TRANSPARENCY
             $ac =& $v->newComponent('vevent');
             // initiate ASSIGNMENT_CUTOFF event
             $ac->setProperty('dtstart', date("Y", $assignment_cutoff_unix_ts), date("n", $assignment_cutoff_unix_ts), date("j", $assignment_cutoff_unix_ts), date("G", $assignment_cutoff_unix_ts), date("m", $assignment_cutoff_unix_ts), date("i", $assignment_cutoff_unix_ts));
             // ASSIGNMENT_CUTOFF DTSTART
             $ac->setProperty('dtend', date("Y", $assignment_cutoff_unix_ts), date("n", $assignment_cutoff_unix_ts), date("j", $assignment_cutoff_unix_ts), date("G", $assignment_cutoff_unix_ts), date("m", $assignment_cutoff_unix_ts), date("i", $assignment_cutoff_unix_ts));
             // ASSIGNMENT_CUTOFF DTEND
             $ac->setProperty('dtstamp', date("Y"), date("n"), date("j"), date("G"), date("m"), date("i"));
             // WHEN THE CAL WAS EXPORTED
             //parse the html content to get the summary
             $html = str_get_html($assignment[1]['content']);
             foreach ($html->find('div.content') as $d) {
                 $div = $d;
             }
             foreach ($div->find('span.module') as $m) {
                 $module = $m->innertext;
             }
             foreach ($div->find('span.title') as $tl) {
                 $title = $tl->innertext;
             }
             foreach ($div->find('span.content') as $c) {
                 $content = $c->innertext;
             }
             unset($html);
             unset($div);
             $summary = $module . $title . $content;
             $ac->setProperty('summary', $summary);
             // SUMMARY
             $ac->setProperty('sequence', 0);
             $ac->setProperty('status', 'CONFIRMED');
             // STATUS
             $ac->setProperty('transp', 'TRANSPARENT');
             // TRANSPARENCY
         }
         //GET THE TESTS FOR THIS COURSE
         $tests = $testsmod->extend_date($row[0]);
         foreach ($tests as $test) {
             // get the dates
             $test_start_unix_ts = $test[0]['unixts'];
             $test_end_unix_ts = $test[1]['unixts'];
             $ts =& $v->newComponent('vevent');
             // initiate TEST_START event
             $ts->setProperty('dtstart', date("Y", $test_start_unix_ts), date("n", $test_start_unix_ts), date("j", $test_start_unix_ts), date("G", $test_start_unix_ts), date("m", $test_start_unix_ts), date("i", $test_start_unix_ts));
             // TEST_START DTSTART
             $ts->setProperty('dtend', date("Y", $test_start_unix_ts), date("n", $test_start_unix_ts), date("j", $test_start_unix_ts), date("G", $test_start_unix_ts), date("m", $test_start_unix_ts), date("i", $test_start_unix_ts));
             // TEST_START DTEND
             $ts->setProperty('dtstamp', date("Y"), date("n"), date("j"), date("G"), date("m"), date("i"));
             // CALENDAR TS
             //parse the html content to get the summary
             $html = str_get_html($test[0]['content']);
             foreach ($html->find('div.content') as $d) {
                 $div = $d;
             }
             foreach ($div->find('span.module') as $m) {
                 $module = $m->innertext;
             }
             foreach ($div->find('span.title') as $tl) {
                 $title = $tl->innertext;
             }
             foreach ($div->find('span.content') as $c) {
                 $content = $c->innertext;
             }
             unset($html);
             unset($div);
             $summary = $module . $title . $content;
             $ts->setProperty('summary', $summary);
             // SUMMARY
             $ts->setProperty('sequence', 0);
             // SEQUENCE NUMBER
             $ts->setProperty('status', 'CONFIRMED');
             // STATUS
             $ts->setProperty('transp', 'TRANSPARENT');
             // TRANSPARENCY
             $te =& $v->newComponent('vevent');
             // initiate TEST_END EVENT
             $te->setProperty('dtstart', date("Y", $test_end_unix_ts), date("n", $test_end_unix_ts), date("j", $test_end_unix_ts), date("G", $test_end_unix_ts), date("m", $test_end_unix_ts), date("i", $test_end_unix_ts));
             // TEST_END DTSTART
             $te->setProperty('dtend', date("Y", $test_end_unix_ts), date("n", $test_end_unix_ts), date("j", $test_end_unix_ts), date("G", $test_end_unix_ts), date("m", $test_end_unix_ts), date("i", $test_end_unix_ts));
             // TEST_END DTEND
             $te->setProperty('dtstamp', date("Y"), date("n"), date("j"), date("G"), date("m"), date("i"));
             // CALENDAR TS
             //parse the html content to get the summary
             $html = str_get_html($test[1]['content']);
             foreach ($html->find('div.content') as $d) {
                 $div = $d;
             }
             foreach ($div->find('span.module') as $m) {
                 $module = $m->innertext;
             }
             foreach ($div->find('span.title') as $tl) {
                 $title = $tl->innertext;
             }
             foreach ($div->find('span.content') as $c) {
                 $content = $c->innertext;
             }
             unset($html);
             unset($div);
             $summary = $module . $title . $content;
             $te->setProperty('summary', $summary);
             // SUMMARY
             $te->setProperty('sequence', 0);
             // SEQUENCE NUMBER
             $te->setProperty('status', 'CONFIRMED');
             // STATUS
             $te->setProperty('transp', 'TRANSPARENT');
             // TRANSPARENCY
         }
     }
     $str = $v->createCalendar();
     return $str;
 }