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); }
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)); }
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(); }
public function onPreInit($param) { if (isset($_GET['idtm_termin'])) { $TerminRecord = TerminRecord::finder()->findByPK($_GET['idtm_termin']); } else { echo "Kein Termin"; exit; } date_default_timezone_set('Europe/Berlin'); $v = new vcalendar(); // initiate new CALENDAR $v->setConfig('pliq_hpartner', 'planlogiq.com'); // config with site domain $e = new vevent(); // initiate a new EVENT $SDateArray = explode('-', $TerminRecord->ter_startdate); $EDateArray = explode('-', $TerminRecord->ter_enddate); $STimeArray = explode(':', $TerminRecord->ter_starttime); $ETimeArray = explode(':', $TerminRecord->ter_endtime); $e->setProperty('categories', ActivityRecord::finder()->findByPK($TerminRecord->idtm_activity)->act_name); // catagorize $e->setProperty('dtstart', $SDateArray[0], $SDateArray[1], $SDateArray[2], $STimeArray[0], $STimeArray[1], 00); // 24 dec 2006 19.30 $e->setProperty('dtend', $EDateArray[0], $EDateArray[1], $EDateArray[2], $ETimeArray[0], $ETimeArray[1], 00); // 24 dec 2006 19.30 //$e->setProperty( 'duration' // , 0, 0, 3 ); // 3 hours $e->setProperty('summary', $TerminRecord->ter_betreff); // describe the event $e->setProperty('description', $TerminRecord->ter_descr); // describe the event $e->setProperty('location', $TerminRecord->ter_ort); // 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? $this->getResponse()->appendHeader("Content-Type:" . $this->header); $this->getResponse()->appendHeader("Content-Disposition:inline;filename=" . $this->docName . '.' . $this->ext); echo $str; $writer->save('php://output'); exit; }
/** * Create calendar * Adds timezone component, when not already done * * @see http://kigkonsult.se/iCalcreator/docs/using.html#createTimezone * * @return string */ public function createCalendar() { // add timezone component if ($this->timezone && $this->getComponent('VTIMEZONE') === false) { $xprops = array('X-LIC-LOCATION' => $this->timezone); \iCalUtilityFunctions::createTimezone($this, $this->timezone, $xprops); } return parent::createCalendar(); }
} } else { $calendar = new vcalendar(); $calsql = $data->select_query("calendar_items", "WHERE allowed = 1 AND trash=0"); while ($temp = $data->fetch_array($calsql)) { $groups = unserialize($temp['groups']); if (is_array($groups)) { $allowed = in_group($groups); } else { $allowed = true; } if ($allowed) { $e = new vevent(); $e->setProperty('categories', $config['troopname'] . " Calendar"); $date = getdate($temp['startdate']); $e->setProperty('dtstart', $date['year'], $date['mon'], $date['mday'], $date['hours'], $date['minutes'], 00); $date = getdate($temp['enddate']); $e->setProperty('dtend', $date['year'], $date['mon'], $date['mday'], $date['hours'], $date['minutes'], 00); $e->setProperty('summary', censor($temp['summary'])); $e->setProperty('description', $temp['detail'] != NULL ? truncate(strip_tags(censor($temp['detail']))) : "No details"); $calendar->addComponent($e); } } header('Content-type: text/calendar'); header('Content-Disposition: attachment; filename="calendar.ics"'); echo $calendar->createCalendar(); exit; } $tpl->assign("show_detail", $show_detail); $pagename = "Calender"; $dbpage = true;
$vevent->setProperty("dtstart", array("year" => $dateArr[0], "month" => $dateArr[1], "day" => $dateArr[2], "hour" => $startTimeTrans[$os->startTime][0], "min" => $startTimeTrans[$os->startTime][1], "sec" => 0)); $vevent->setProperty("dtend", array("year" => $dateArr[0], "month" => $dateArr[1], "day" => $dateArr[2], "hour" => $endTimeTrans[$os->startTime][0], "min" => $endTimeTrans[$os->startTime + $os->durationTime - 1][1], "sec" => 0)); $vevent->setProperty("LOCATION", $os->location); // property name - case independent $vevent->setProperty("summary", $o->name); $vevent->setProperty("description", $o->tutor); if (count($os->week) > 1) { // Set recurrence rule $endWeek = $os->week[count($os->week) - 1]; $iWeek = $os->week[0]; $weekdayTrans = array('', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'); $vevent->setProperty("RRULE", array("FREQ" => "WEEKLY", "COUNT" => $endWeek - $iWeek + 1, "INTERVAL" => 1, "WKST" => $weekdayTrans[$os->day])); for (; $iWeek < $endWeek; $iWeek++) { if (!in_array($iWeek, $os->week)) { $dateArr = $school->getSchoolCalendar2Date($tables[0]['year'], $tables[0]['term'], $iWeek, $os->day); $vevent->setProperty("EXDATE", array(array($dateArr[0], $dateArr[1], $dateArr[2], $startTimeTrans[$os->startTime][0], $startTimeTrans[$os->startTime][1], 0))); } } } //$schedArr[$os->day][$os->startTime][] = $os; } } } $preData = $v->createCalendar(); include 'showdata.inc.php'; include 'footer.inc.php'; exit; } include 'header.inc.php'; include 'login.inc.php'; include 'footer.inc.php';
/** * @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"; }
$data = get($url, -1); if ($data != "") { preg_match("/(<h2>.*?)<h2>/s", $data, $matches); $data = $matches[1]; $lines = explode("\n", $data, 2); $title = strip_tags($lines[0]); #print "Title: $title\n"; $vevent->setProperty("SUMMARY", $title); preg_match("/When:<\\/dt><dd>([^<]+)<\\/dd>/", $data, $matches); $when = explode(",", $matches[1]); $time = strptime($when[1], "%e %B %Y"); $times = explode("-", $when[0]); $start = $vevent->getProperty('DTSTART'); $start['tz'] = $tzid; $vevent->setProperty('DTSTART', $start); $end = $vevent->getProperty('DTEND'); $end['tz'] = $tzid; $vevent->setProperty('DTEND', $end); $content = trim(substr(strstr($data, "</dl>"), 5)); $content .= "\n{$url}\n"; #print $content."\n"; $vevent->setProperty('description', $content); } $loc = $vevent->getProperty("location"); if ($loc == "Limehouse town hall") { $vevent->setProperty("location", "Limehouse Town Hall, 646 Commercial Road London, E14 7HA, United Kingdom"); } $out->addComponent($vevent); } print $out->createCalendar();
/** * 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; }
/** * 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; }
/** * @param string $iCal * @param string $myEmail * @param int $answer possible values: accept: 1, maybe: 2, decline: 3 */ public static function answerInvitation(string $iCal, string $myEmail, int $answer) { if ($answer == "1") { $text = "akzeptiert"; } if ($answer == "2") { $text = "vorläufig akzeptiert"; } if ($answer == "3") { $text = "abgelehnt"; } $VC = new vcalendar(); $VC->parse($iCal); $event = $VC->getComponent("vevent"); $targetAttendee = "MAILTO:" . $myEmail; $i = 1; while ($valueOccur = $event->getProperty("ATTENDEE", $i, true)) { if (stripos($valueOccur["value"], $targetAttendee) === false) { $i++; continue; } $params = $valueOccur["params"]; if ($answer == "1") { $params["PARTSTAT"] = "ACCEPTED"; } if ($answer == "2") { $params["PARTSTAT"] = "TENTATIVE"; } if ($answer == "3") { $params["PARTSTAT"] = "DECLINED"; } if (isset($params["RSVP"])) { unset($params["RSVP"]); } $event->setAttendee($targetAttendee, $params, $i); $i++; } $i = 1; while ($valueOccur = $event->getProperty("ATTENDEE", $i, true)) { if (stripos($valueOccur["value"], $targetAttendee) === false) { $i++; $event->deleteProperty("ATTENDEE"); continue; } $i++; } $event->setProperty("DTSTAMP", gmdate("Ymd") . "T" . gmdate("His") . "Z"); $event->setProperty("LAST-MODIFIED", gmdate("Ymd") . "T" . gmdate("His") . "Z"); $VC->deleteComponent("vevent"); $VC->setComponent($event); $VC->setMethod("REPLY"); $ics = $VC->createCalendar(); $fromName = Session::currentUser()->A("name"); $from = Session::currentUser()->A("UserEmail"); $mail = new htmlMimeMail5(); $mail->setFrom(utf8_decode($fromName . " <" . $from . ">")); if (!ini_get('safe_mode')) { $mail->setReturnPath($from); } $mail->setSubject(utf8_decode("Antwort Termineinladung (" . ucfirst($text) . "): " . $event->getProperty("SUMMARY"))); $mail->addAttachment(new stringAttachment($ics, "invite.ics", 'application/ics')); $mail->setCalendar($ics, "REPLY"); $mail->setCalendarCharset("UTF-8"); $mail->setTextCharset("UTF-8"); $mail->setText("{$fromName} hat diesen Termin {$text}"); $organizer = str_replace("MAILTO:", "", $event->getProperty("ORGANIZER")); return $mail->send(array($organizer)); }
$v->setConfig('filename', "danaevents-" . $v->getConfig('filename')); $v->setXprop("X-WR-CALNAME", $data['title']); $v->setXprop("X-WR-CALDESC", $data['description']); foreach ($data['items'] as $item) { $lines = explode("\n", $item['description']); //<p>28/05/2008, 19:00 - 20:30</p> //print $lines[count($lines)-1]; preg_match("/(\\d+)\\/(\\d+)\\/(\\d+), (\\d+):(\\d+) - (\\d+):(\\d+)/", $lines[count($lines) - 1], $matches); //print_r($matches); //exit; $vevent = new vevent(); // create an event calendar component $vevent->setProperty('dtstart', array('year' => $matches[3], 'month' => $matches[2], 'day' => $matches[1], 'hour' => $matches[4], 'min' => $matches[5], 'sec' => 0)); $vevent->setProperty('dtend', array('year' => $matches[3], 'month' => $matches[2], 'day' => $matches[1], 'hour' => $matches[6], 'min' => $matches[7], 'sec' => 0)); $vevent->setProperty('LOCATION', '165 Queen\'s Gate, South Kensington, London, SW7 5HD'); // property name - case independent $vevent->setProperty('summary', $item['title']); preg_match("/href=\"([^\"]+)/", $lines[0], $matches); array_pop($lines); array_pop($lines); $desc = trim(strip_tags(html_entity_decode(implode("\n", $lines)))); $desc = str_replace("’", "'", $desc); $desc = str_replace("‘", "'", $desc); $desc .= "\n\n<a href=\"" . $matches[1] . "\">More info</a>"; $vevent->setProperty('description', $desc); $v->setComponent($vevent); // add event to calendar } //$v->returnCalendar(); print $v->createCalendar();
/** * Render iCal data * * @param string $name iCalendar name * @param array $objects * @param boolean $include_project_name * @return void */ function render_icalendar($name, $objects, $include_project_name = false) { require_once ANGIE_PATH . '/classes/icalendar/iCalCreator.class.php'; $calendar = new vcalendar(); //$calendar->setProperty('VERSION', '1.0'); $calendar->setProperty('X-WR-CALNAME', $name); $calendar->setProperty('METHOD', 'PUBLISH'); $projects = array(); foreach ($objects as $object) { $summary = $object->getName(); if ($include_project_name) { $project_id = $object->getProjectId(); if (isset($projects[$project_id])) { $summary .= ' | ' . $projects[$project_id]->getName(); } else { $project = $object->getProject(); if (instance_of($project, 'Project')) { $projects[$project_id] = $project; $summary .= ' | ' . $projects[$project_id]->getName(); } // if } // if } // if switch (strtolower($object->getType())) { case 'milestone': $start_on = $object->getStartOn(); $due_on = $object->getDueOn(); $due_on->advance(24 * 60 * 60, true); // One day shift because iCal and Windows Calendar don't include last day $start_on_year = $start_on->getYear(); $start_on_month = $start_on->getMonth() < 10 ? '0' . $start_on->getMonth() : $start_on->getMonth(); $start_on_day = $start_on->getDay() < 10 ? '0' . $start_on->getDay() : $start_on->getDay(); $due_on_year = $due_on->getYear(); $due_on_month = $due_on->getMonth() < 10 ? '0' . $due_on->getMonth() : $due_on->getMonth(); $due_on_day = $due_on->getDay() < 10 ? '0' . $due_on->getDay() : $due_on->getDay(); $event = new vevent(); $event->setProperty('dtstart', array($start_on_year, $start_on_month, $start_on_day), array('VALUE' => 'DATE')); $event->setProperty('dtend', array($due_on_year, $due_on_month, $due_on_day), array('VALUE' => 'DATE')); $event->setProperty('dtstamp', date('Ymd')); $event->setProperty('summary', $summary); if ($object->getBody()) { $event->setProperty('description', html_to_text($object->getFormattedBody()) . "\n\n" . lang('Details: ') . $object->getViewUrl()); } else { $event->setProperty('description', lang('Details') . ': ' . $object->getViewUrl()); } // if switch ($object->getPriority()) { case PRIORITY_HIGHEST: $event->setProperty('priority', 1); break; case PRIORITY_HIGH: $event->setProperty('priority', 3); break; case PRIORITY_LOW: $event->setProperty('priority', 7); break; case PRIORITY_LOWEST: $event->setProperty('priority', 9); break; case PRIORITY_ONGOING: $event->setProperty('priority', 11); break; case PRIORITY_HOLD: $event->setProperty('priority', 13); break; default: $event->setProperty('priority', 5); } // switch $calendar->addComponent($event); break; case 'ticket': case 'task': $start_on = $object->getCreatedOn(); $due_on = $object->getDueOn(); $todo = new vtodo(); $todo->setProperty('summary', $summary); $todo->setProperty('description', $object->getName() . "\n\n" . lang('Details') . ': ' . $object->getViewUrl()); switch ($object->getPriority()) { case PRIORITY_HIGHEST: $todo->setProperty('priority', 1); break; case PRIORITY_HIGH: $todo->setProperty('priority', 3); break; case PRIORITY_LOW: $todo->setProperty('priority', 7); break; case PRIORITY_LOWEST: $todo->setProperty('priority', 9); break; case PRIORITY_ONGOING: $todo->setProperty('priority', 11); break; case PRIORITY_HOLD: $todo->setProperty('priority', 13); break; default: $todo->setProperty('priority', 5); } // switch if (instance_of($due_on, 'DateValue')) { $due_on_year = $due_on->getYear(); $due_on_month = $due_on->getMonth() < 10 ? '0' . $due_on->getMonth() : $due_on->getMonth(); $due_on_day = $due_on->getDay() < 10 ? '0' . $due_on->getDay() : $due_on->getDay(); $todo->setProperty('due', $due_on_year, $due_on_month, $due_on_day); } // if $calendar->addComponent($todo); break; default: break; } } // foreach $cal = $calendar->createCalendar(); header('Content-Type: text/calendar; charset=UTF-8'); header('Content-Disposition: attachment; filename="' . $name . '.ics"'); header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Pragma: no-cache'); print $cal; die; }
//Get events $q = $dbh->prepare("SELECT * FROM `cm_events_responsibles`,`cm_events`\n\t\tWHERE cm_events_responsibles.username = ?\n\t\tAND cm_events_responsibles.event_id = cm_events.id\n\t\tORDER by cm_events.start DESC"); $q->bindParam(1, $user); $q->execute(); $events = $q->fetchAll(PDO::FETCH_ASSOC); foreach ($events as $event) { $case_name = case_id_to_casename($dbh, $event['case_id']); $e = new vevent(); // initiate EVENT if ($event['all_day'] == '1') { $start = explode(' ', $event['start']); //all-day events are date only $e->setProperty('dtstart', $start[0]); if ($event['end'] == null) { $e->setProperty('dtend', $start[0]); //make end same as event } else { $end = explode(' ', $event['end']); $e->setProperty('dtend', $end[0]); } } else { $e->setProperty('dtstart', $event['start']); $e->setProperty('dtend', $event['end']); } $e->setProperty('summary', $case_name . ": " . $event['task']); $e->setProperty('description', $event['notes']); $v->setComponent($e); } $cal = $v->createCalendar(); echo $cal; }
function send_iCal($entry_id) { global $login; // ## Getting entry $entry = getEntry($entry_id); if (!count($entry)) { return FALSE; } $description = template_ical($entry); // ## Making iCal-element $c = new vcalendar(); $e = new vevent(); $e->setProperty('dtstart', date('Y', $entry['time_start']), date('m', $entry['time_start']), date('d', $entry['time_start']), date('H', $entry['time_start']), date('i', $entry['time_start']), date('s', $entry['time_start'])); $e->setProperty('dtend', date('Y', $entry['time_end']), date('m', $entry['time_end']), date('d', $entry['time_end']), date('H', $entry['time_end']), date('i', $entry['time_end']), date('s', $entry['time_end'])); $e->setProperty('summary', $entry['entry_name']); $e->setProperty('class', 'PUBLIC'); $e->setProperty('description', $description); $e->setProperty('UID', 'entry' . $entry['entry_id'] . '@booking.jaermuseet.no'); $c->setProperty('method', 'REQUEST'); $c->setComponent($e); $ical = str_replace('DTSTART', 'X-GWITEM-TYPE:APPOINTMENT' . chr(10) . 'DTSTART', $c->createCalendar()); // ## Sending mail // Need to find who we are sending it to $users = array(); foreach ($entry['user_assigned'] as $user_id) { $user = getUser($user_id); if (count($user)) { $users[$user_id] = $user['user_email']; } } // Sending to the users foreach ($users as $user_mail) { $rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$rand}x"; $subject = 'Stadfesting av bestilling - ' . date('d-m-Y', $entry['time_start']) . ': ' . $entry['entry_name']; if (isset($login['user_email']) && $login['user_email'] != '') { $headers = 'From: ' . $login['user_email']; } else { $headers = 'From: ' . constant('EMAIL_FROM'); } // Add the headers for a file attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // Add a multipart boundary above the plain message $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . "{$description}\n\n"; // iCal $message .= "--{$mime_boundary}\n" . "Content-class: urn:content-classes:calendarmessage\n" . "Content-type: text/calendar; method=REQUEST; name=meeting.ics; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n"; $message .= $ical; $message .= "\n--{$mime_boundary}--"; $ok = mail($user_mail, $subject, $message, $headers); $ok = true; if (!$ok) { // TODO: Error handling for mail not sent echo 'Faild sending mail. Please contact somebody!!'; exit; } else { // It's okey... } } // ## Loging iCal sending // TODO: Log iCal sending return TRUE; }
$apikey = $_SESSION['do_User']->api_key; $c->setConfig(array("directory" => "Calevents", "filename" => "{$iduser}.ics")); $vivek->getAllTaskByuser($iduser); while ($vivek->fetch()) { $stdt = explode('-', $vivek->getData("due_date_dateformat")); $startdate = "{$stdt['0']}" . "{$stdt['1']}" . "{$stdt['2']}"; $enddate = $startdate; $e =& $c->newComponent('vevent'); //$e->setProperty( 'dtstart', $startdate ); //$e->setProperty( 'dtend', $enddate ); $e->setProperty("dtstart", "{$startdate}", array("VALUE" => "DATE")); $e->setProperty('description', $vivek->getData("task_description")); $e->setProperty('summary', $vivek->getData("task_description")); $e->setProperty('class', 'PUBLIC'); } $c->createCalendar(); $str = $c->saveCalendar(); $tt = $_SERVER["SERVER_NAME"]; $path = "http://" . "{$tt}" . "/" . "Calevents/" . "{$iduser}.ics"; $ff = "Calevents/{$iduser}.ics"; system("chmod 0777 {$ff}"); echo _('Your iCal URL is : ' . $path . ' '); } else { echo _('You do not yet have an API key. '); echo _('Please generate one '); echo $e_set_api->getLink('here'); echo '<div class="spacerblock_20"></div>'; } ?> </div> <div class="solidline"></div>
function ChangeMessage($folderid, $id, $message) { debugLog('CalDAV::ChangeMessage(' . $folderid . ', ' . $id . ', ..)'); debugLog("CalDAV::Their Message = "); if (trim($id) != "") { $return = $this->StatMessage($folderid, $id); } else { $return = false; } if ($return === false) { debugLog('CalDAV::Found new message on device'); #create new id, this is a new record from device. $date = date('Ymd\\THisT'); $unique = substr(microtime(), 2, 4); $base = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPrRsStTuUvVxXuUvVwWzZ1234567890'; $start = 0; $end = strlen($base) - 1; $length = 6; $str = null; for ($p = 0; $p < $length; $p++) { $unique .= $base[mt_rand($start, $end)]; } $id = $date . '-' . $unique . ".ics"; } else { debugLog('CalDAV::Event Already On Server'); } $task = false; if ($folderid == "tasks") { $vtodo = $this->converttovtodo($message); if (substr($id, strlen($id) - 4) == ".ics") { $vtodo->setProperty("UID", substr($id, 0, -4)); } else { $vtodo->setProperty("UID", $id); } } else { $vevent = $this->converttovevent($message); $exarray = array(); if (isset($message->exceptions) && is_array($message->exceptions)) { $deletedarray = array(); foreach ($message->exceptions as $ex) { if ($ex->deleted == "1") { array_push($deletedarray, $this->parseDate($ex->exceptionstarttime)); } else { debugLog('CalDAV::Found non deleted exception Converting...'); $tmpevent = $this->converttovevent($ex); if (isset($ex->alldayevent) && $ex->alldayevent == "1") { $tmpevent->setProperty("recurrence-id", $this->parseDate($ex->exceptionstarttime), array('VALUE' => 'DATE')); } else { $tmpevent->setProperty("recurrence-id", $this->parseDate($ex->exceptionstarttime)); } array_push($exarray, $tmpevent); } } debugLog("CalDAV:: " . print_r($deletedarray, true)); if (count($deletedarray) > 0) { $vevent->setProperty("exdate", $deletedarray); } } if (substr($id, strlen($id) - 4) == ".ics") { $vevent->setProperty("UID", substr($id, 0, -4)); } else { $vevent->setProperty("UID", $id); } } # $somethingelse = convert2ical(); debugLog('CalDAV::Converted to iCal: '); $v = new vcalendar(); if ($folderid == "tasks") { $v->setComponent($vtodo); } else { $v->setComponent($vevent); if (count($exarray) > 0) { foreach ($exarray as $exvevent) { $sdt = $exvevent->getProperty("dtstart"); if (substr($id, strlen($id) - 4) == ".ics") { $exvevent->setProperty("UID", substr($id, 0, -4)); } else { $exvevent->setProperty("UID", $id); } $v->setComponent($exvevent); } } } $output = $v->createCalendar(); debugLog("CalDAV::putting to " . $this->_path . $id); $etag = "*"; if ($return) { $etag = $return['etag']; } $retput = $this->cdc->DoPUTRequest($this->_path . $id, $output, $etag); debugLog("CalDAV::output putted etag: {$etag} new etag: {$retput}"); $obj = array(); $obj["etag"] = $retput; $obj["href"] = $id; $obj["data"] = $output; if ($folderid == "calendar") { $this->_events[$id] = $obj; } else { $this->_tasks[$id] = $obj; } return $this->StatMessage($folderid, $id); }
$e->setProperty('rrule', array('FREQ' => 'YEARLY')); $c->setComponent($e); $str = $c->createCalendar(); echo $str; echo "<br />\n\n"; /* * BEGIN:VTODO * UID:19970901T130000Z-123404@host.com * DTSTAMP:19970901T1300Z * DTSTART:19970415T133000Z * DUE:19970416T045959Z * SUMMARY:1996 Income Tax Preparation * CLASS:CONFIDENTIAL * CATEGORIES:FAMILY,FINANCE * PRIORITY:1 * STATUS:NEEDS-ACTION * END:VTODO */ $c = new vcalendar(); $t = new vtodo(); $t->setProperty('dtstart', '19970415T133000 GMT'); $t->setProperty('due', '19970416T045959 GMT'); $t->setProperty('summary', '1996 Income Tax Preparation'); $t->setProperty('class', 'CONFIDENTIAL'); $t->setProperty('categories', 'FAMILY'); $t->setProperty('categories', 'FINANCE'); $t->setProperty('priority', 1); $t->setProperty('status', 'NEEDS-ACTION'); $c->setComponent($t); $str = $c->createCalendar(); echo $str;
$description = substr($description,0,strrpos($description, "\\n")); $description .= "\\n\\n$url"; $vevent->deleteProperty('description'); $vevent->setProperty('description',$description); $start = $vevent->getProperty('DTSTART'); $start['tz'] = $tzid; $vevent->setProperty('DTSTART',$start); $end = $vevent->getProperty('DTEND'); $end['tz'] = $tzid; $vevent->setProperty('DTEND',$end); $vevent->deleteProperty('CLASS'); // stop blanking some events $stamp = $vevent->getProperty('DTSTAMP'); $stamp = mktime($stamp['hour'],$stamp['minute'],$stamp['second'],$stamp['month'],$stamp['day'],$stamp['year']); if ($stamp < $self_age) { $vevent->setProperty('DTSTAMP', array("timestamp"=>$self_age)); $vevent->setProperty('LAST-MODIFIED', array("timestamp"=>$self_age)); } $out->addComponent($vevent); } $str = $out->createCalendar(); // generate and get output in string, for testing? echo $str; ?>
$ts->setProperty('tzoffsetfrom', '-0400'); $ts->setProperty('tzoffsetto', '-0500'); $ts->setProperty('tzname', 'EST'); $td =& $t->newComponent('daylight'); // initiate timezone daylight $td->setProperty('dtstart', 1997, 10, 26, 2); $rdate1 = array('year' => 1997, 'month' => 4, 'day' => 6, 'hour' => 02, 'min' => 0, 'sec' => 0); $td->setProperty('rdate', array($rdate1)); $td->setProperty('tzoffsetfrom', '-0500'); $td->setProperty('tzoffsetto', '-0400'); $td->setProperty('tzname', 'EDT'); /* 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"; /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* * Samples from RFC2445, all output as strings to display */ /* * Example: The following is an example of the "VEVENT" calendar * component used to represent a meeting that will also be opaque to * searches for busy time: * BEGIN:VEVENT * UID:19970901T130000Z-123401@host.com * DTSTAMP:19970901T1300Z * DTSTART:19970903T163000Z * DTEND:19970903T190000Z
} if (isset($_GET["debug"])) { echo "<pre>"; foreach ($listeEvt as $evt) { echo $evt; } echo "</pre>"; } else { // sortie au format iCalendar $sourcesEnteteICal = array(); foreach (array_keys($listeSourcesAAnalyser) as $src) { array_push($sourcesEnteteICal, $SOURCES[$src]["nomSite"]); } $vcal = new vcalendar(array("unique_id" => "[" . implode(',', $sourcesEnteteICal) . "]")); foreach ($listeEvt as $evmt) { $event =& $vcal->newComponent("vevent"); // si la date de fin n'est pas positionnée if ($evmt->dateFin == 0) { // on déclare l'évènement comme un évènement à la journée $event->setProperty("dtstart", array("timestamp" => $evmt->dateDebut, "tz" => "Europe/Paris"), array("VALUE" => "DATE")); } else { // on déclare l'évènement entre deux dates $event->setProperty("dtstart", array("timestamp" => $evmt->dateDebut, "tz" => "Europe/Paris"), array("VALUE" => "DATE-TIME")); $event->setProperty("dtend", array("timestamp" => $evmt->dateFin, "tz" => "Europe/Paris"), array("VALUE" => "DATE-TIME")); } $event->setProperty("summary", '[' . $evmt->lieu . '] ' . $evmt->description); $event->setProperty("description", $evmt->description . '\\n' . $evmt->lien); $event->setProperty("location", $evmt->lieu); } echo $vcal->createCalendar(); }