예제 #1
0
 /**
  * Function that create the exported file
  * @param Vtiger_Request $request
  * @param <Array> $result
  * @param Vtiger_Module_Model $moduleModel
  */
 public function output($request, $result, $moduleModel)
 {
     $fileName = $request->get('filename');
     $exportType = $this->getExportContentType($request);
     // Send the right content type and filename
     header("Content-type: {$exportType}");
     header("Content-Disposition: attachment; filename={$fileName}.ics");
     $timeZone = new iCalendar_timezone();
     $timeZoneId = split('/', date_default_timezone_get());
     if (!empty($timeZoneId[1])) {
         $zoneId = $timeZoneId[1];
     } else {
         $zoneId = $timeZoneId[0];
     }
     $timeZone->add_property('TZID', $zoneId);
     $timeZone->add_property('TZOFFSETTO', date('O'));
     if (date('I') == 1) {
         $timeZone->add_property('DAYLIGHTC', date('I'));
     } else {
         $timeZone->add_property('STANDARDC', date('I'));
     }
     $myiCal = new iCalendar();
     $myiCal->add_component($timeZone);
     while (!$result->EOF) {
         $eventFields = $result->fields;
         $id = $eventFields['activityid'];
         $type = $eventFields['activitytype'];
         if ($type != 'Task') {
             $temp = $moduleModel->get('eventFields');
             foreach ($temp as $fieldName => $access) {
                 $temp[$fieldName] = $eventFields[$fieldName];
             }
             $temp['id'] = $id;
             $iCalTask = new iCalendar_event();
             $iCalTask->assign_values($temp);
             $iCalAlarm = new iCalendar_alarm();
             $iCalAlarm->assign_values($temp);
             $iCalTask->add_component($iCalAlarm);
         } else {
             $temp = $moduleModel->get('todoFields');
             foreach ($temp as $fieldName => $access) {
                 $temp[$fieldName] = $eventFields[$fieldName];
             }
             $iCalTask = new iCalendar_todo();
             $iCalTask->assign_values($temp);
         }
         $myiCal->add_component($iCalTask);
         $result->MoveNext();
     }
     echo $myiCal->serialize();
 }
 /**
  * Echoes the ICS file information.
  *
  * @since 1.0.0
  *
  * @param iCalendar $iCalendar
  */
 public static function viewIcsFile(iCalendar $iCalendar)
 {
     echo "BEGIN:VCALENDAR<br />";
     echo "VERSION:2.0<br />";
     /** @var string $organizerName */
     $organizerName = $iCalendar->getOrganizerName();
     echo "PRODID:-//{$organizerName}//NONSGML {$iCalendar->getEventName()}//EN<br />";
     echo "METHOD:REQUEST<br />";
     echo "BEGIN:VEVENT<br />";
     echo "UID:" . date('Ymd') . 'T' . date('His') . "-" . rand();
     if (!empty($organizerName)) {
         echo "-{$organizerName}";
     }
     echo "<br />";
     echo "DTSTAMP:" . date('Ymd') . 'T' . date('His') . "<br />";
     echo "ORGANIZER:CN={$organizerName}:MAILTO:{$iCalendar->getOrganizerEmail()}<br />";
     echo "DTSTART:{$iCalendar->getEventStart()}<br />";
     echo "DTEND:{$iCalendar->getEventEnd()}<br />";
     echo "LOCATION:{$iCalendar->getEventLocation()}<br />";
     echo "SUMMARY:{$iCalendar->getEventName()}<br />";
     echo "DESCRIPTION: {$iCalendar->getEventDescription()}<br />";
     echo "END:VEVENT<br />";
     echo "END:VCALENDAR<br />";
 }
예제 #3
0
 /**
  * Function that create the exported file
  * @param Vtiger_Request $request
  * @param <Array> $result
  * @param Vtiger_Module_Model $moduleModel
  */
 public function output($request, $result, $moduleModel)
 {
     $fileName = $request->get('filename');
     $exportType = $this->getExportContentType($request);
     // Send the right content type and filename
     header("Content-type: {$exportType}");
     header("Content-Disposition: attachment; filename={$fileName}.ics");
     $timeZone = new iCalendar_timezone();
     $timeZoneId = split('/', date_default_timezone_get());
     if (!empty($timeZoneId[1])) {
         $zoneId = $timeZoneId[1];
     } else {
         $zoneId = $timeZoneId[0];
     }
     $timeZone->add_property('TZID', $zoneId);
     $timeZone->add_property('TZOFFSETTO', date('O'));
     if (date('I') == 1) {
         $timeZone->add_property('DAYLIGHTC', date('I'));
     } else {
         $timeZone->add_property('STANDARDC', date('I'));
     }
     $myiCal = new iCalendar();
     $myiCal->add_component($timeZone);
     while (!$result->EOF) {
         $eventFields = $result->fields;
         $id = $eventFields['activityid'];
         $type = $eventFields['activitytype'];
         if ($type != 'Task') {
             $temp = $moduleModel->get('eventFields');
             foreach ($temp as $fieldName => $access) {
                 /* Priority property of ical is Integer
                  * http://kigkonsult.se/iCalcreator/docs/using.html#PRIORITY
                  */
                 if ($fieldName == 'priority') {
                     $priorityMap = array('High' => '1', 'Medium' => '2', 'Low' => '3');
                     $priorityval = $eventFields[$fieldName];
                     $icalZeroPriority = 0;
                     if (array_key_exists($priorityval, $priorityMap)) {
                         $temp[$fieldName] = $priorityMap[$priorityval];
                     } else {
                         $temp[$fieldName] = $icalZeroPriority;
                     }
                 } else {
                     $temp[$fieldName] = $eventFields[$fieldName];
                 }
             }
             $temp['id'] = $id;
             $iCalTask = new iCalendar_event();
             $iCalTask->assign_values($temp);
             $iCalAlarm = new iCalendar_alarm();
             $iCalAlarm->assign_values($temp);
             $iCalTask->add_component($iCalAlarm);
         } else {
             $temp = $moduleModel->get('todoFields');
             foreach ($temp as $fieldName => $access) {
                 if ($fieldName == 'priority') {
                     $priorityMap = array('High' => '1', 'Medium' => '2', 'Low' => '3');
                     $priorityval = $eventFields[$fieldName];
                     $icalZeroPriority = 0;
                     if (array_key_exists($priorityval, $priorityMap)) {
                         $temp[$fieldName] = $priorityMap[$priorityval];
                     } else {
                         $temp[$fieldName] = $icalZeroPriority;
                     }
                 } else {
                     $temp[$fieldName] = $eventFields[$fieldName];
                 }
             }
             $iCalTask = new iCalendar_todo();
             $iCalTask->assign_values($temp);
         }
         $myiCal->add_component($iCalTask);
         $result->MoveNext();
     }
     echo $myiCal->serialize();
 }
예제 #4
0
    } else {
        // Parameters given but incorrect, redirect back to export page
        redirect($CFG->wwwroot . '/calendar/export.php');
        die;
    }
}
$whereclause = calendar_sql_where($timestart, $timeend, $users, $groups, array_keys($courses), false);
if ($whereclause === false) {
    $events = array();
} else {
    $events = get_records_select('event', $whereclause, 'timestart');
}
if ($events === false) {
    $events = array();
}
$ical = new iCalendar();
$ical->add_property('method', 'PUBLISH');
foreach ($events as $event) {
    $ev = new iCalendar_event();
    $ev->add_property('summary', $event->name);
    $ev->add_property('description', $event->description);
    $ev->add_property('class', 'PUBLIC');
    // PUBLIC / PRIVATE / CONFIDENTIAL
    $ev->add_property('last-modified', Bennu::timestamp_to_datetime($event->timemodified));
    $ev->add_property('dtstamp', Bennu::timestamp_to_datetime());
    // now
    $ev->add_property('dtstart', Bennu::timestamp_to_datetime($event->timestart));
    // when event starts
    if ($event->timeduration > 0) {
        //dtend is better than duration, because it works in Microsoft Outlook and works better in Korganizer
        $ev->add_property('dtend', Bennu::timestamp_to_datetime($event->timestart + $event->timeduration));
예제 #5
0
<?php

//header("Content-type: text/calendar;");
error_reporting(E_ALL);
include 'bennu/lib/bennu.inc.php';
$a = new iCalendar();
function leading_zeros($value, $places)
{
    // Function written by Marcus L. Griswold (vujsa)
    // Can be found at http://www.handyphp.com
    // Do not remove this header!
    $leading = "";
    if (is_numeric($value)) {
        for ($x = 1; $x <= $places; $x++) {
            $ceiling = pow(10, $x);
            if ($value < $ceiling) {
                $zeros = $places - $x;
                for ($y = 1; $y <= $zeros; $y++) {
                    $leading .= "0";
                }
                $x = $places + 1;
            }
        }
        $output = $leading . $value;
    } else {
        $output = $value;
    }
    return $output;
}
$apicode = file_get_contents("apicode.txt");
$fav = file_get_contents("http://www.thetvdb.com/api/User_Favorites.php?accountid=" . $_GET["accountid"]);
예제 #6
0
} else {
    $default_timezone = date_default_timezone_get();
    $tzid = split('/', $default_timezone);
}
if (!empty($tzid[1])) {
    $tz->add_property('TZID', $tzid[1]);
} else {
    $tz->add_property('TZID', $tzid[0]);
}
$tz->add_property('TZOFFSETTO', date('O'));
if (date('I') == 1) {
    $tz->add_property('DAYLIGHTC', date('I'));
} else {
    $tz->add_property('STANDARDC', date('I'));
}
$myical = new iCalendar();
$myical->add_component($tz);
while ($row = $adb->fetch_array($calendar_results)) {
    $this_event = $row;
    $id = $this_event['activityid'];
    $type = $this_event['activitytype'];
    if ($type != 'Task') {
        $temp = $event;
        foreach ($temp as $key => $val) {
            $temp[$key] = $this_event[$key];
        }
        $temp['id'] = $id;
        $ev = new iCalendar_event();
        $ev->assign_values($temp);
        $al = new iCalendar_alarm();
        $al->assign_values($temp);
예제 #7
0
 private function addLine(&$string, $prop, $value)
 {
     $string .= sprintf("%s:%s\n", $prop, iCalendar::ical_escape_text($value));
 }
예제 #8
0
 public function test_calendar_add_subscription()
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/lib/bennu/bennu.inc.php';
     $this->resetAfterTest(true);
     // Test for Microsoft Outlook 2010.
     $subscription = new stdClass();
     $subscription->name = 'Microsoft Outlook 2010';
     $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
     $subscription->eventtype = 'site';
     $id = calendar_add_subscription($subscription);
     $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/ms_outlook_2010.ics');
     $ical = new iCalendar();
     $ical->unserialize($calendar);
     $this->assertEquals($ical->parser_errors, array());
     $sub = calendar_get_subscription($id);
     $result = calendar_import_icalendar_events($ical, $sub->courseid, $sub->id);
     $count = $DB->count_records('event', array('subscriptionid' => $sub->id));
     $this->assertEquals($count, 1);
     // Test for OSX Yosemite.
     $subscription = new stdClass();
     $subscription->name = 'OSX Yosemite';
     $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
     $subscription->eventtype = 'site';
     $id = calendar_add_subscription($subscription);
     $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/osx_yosemite.ics');
     $ical = new iCalendar();
     $ical->unserialize($calendar);
     $this->assertEquals($ical->parser_errors, array());
     $sub = calendar_get_subscription($id);
     $result = calendar_import_icalendar_events($ical, $sub->courseid, $sub->id);
     $count = $DB->count_records('event', array('subscriptionid' => $sub->id));
     $this->assertEquals($count, 1);
     // Test for Google Gmail.
     $subscription = new stdClass();
     $subscription->name = 'Google Gmail';
     $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
     $subscription->eventtype = 'site';
     $id = calendar_add_subscription($subscription);
     $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/google_gmail.ics');
     $ical = new iCalendar();
     $ical->unserialize($calendar);
     $this->assertEquals($ical->parser_errors, array());
     $sub = calendar_get_subscription($id);
     $result = calendar_import_icalendar_events($ical, $sub->courseid, $sub->id);
     $count = $DB->count_records('event', array('subscriptionid' => $sub->id));
     $this->assertEquals($count, 1);
 }
예제 #9
0
 /**
  * Save a snip email attachment and associated it to a parent email.  Content is base64 encoded.
  *
  */
 protected function processEmailAttachment($data, $email)
 {
     if (substr($data['filename'], -4) === '.ics') {
         require_once 'modules/SNIP/iCalParser.php';
         $ic = new iCalendar();
         try {
             $ic->parse(base64_decode($data['content']));
             $ic->createSugarEvents($email);
         } catch (Exception $e) {
             $GLOBALS['log']->info("Could not process calendar attachment: " . $e->getMessage());
         }
     } else {
         $this->createNote($data, $email);
     }
 }
예제 #10
0
/**
* While we can construct our SQL to apply some filters in the query, other filters
* need to be checked against the retrieved record.  This is for handling those ones.
*
* @param array $filter An array of XMLElement which is the filter definition
* @param string $item The database row retrieved for this calendar item
*
* @return boolean True if the check succeeded, false otherwise.
*/
function apply_filter($filters, $item)
{
    global $session, $c, $request;
    if (count($filters) == 0) {
        return true;
    }
    dbg_error_log("calquery", "Applying filter for item '%s'", $item->dav_name);
    $ical = new iCalendar(array("icalendar" => $item->caldav_data));
    return $ical->TestFilter($filters);
}
예제 #11
0
/**
* Get XML response for items in the collection
* If '/' is requested, a list of visible users is given, otherwise
* a list of calendars for the user which are parented by this path.
*/
function get_collection_contents($depth, $collection, $parent_path = null)
{
    global $c, $session, $request, $reply, $property_list;
    $bound_from = $collection->bound_from();
    $bound_to = $collection->dav_name();
    if (!isset($parent_path)) {
        $parent_path = $collection->dav_name();
    }
    dbg_error_log('PROPFIND', 'Getting collection contents: Depth %d, Path: %s, Bound from: %s, Bound to: %s', $depth, $collection->dav_name(), $bound_from, $bound_to);
    $date_format = iCalendar::HttpDateFormat();
    $responses = array();
    if (!$collection->IsCalendar() && !$collection->IsAddressbook()) {
        /**
         * Calendar/Addressbook collections may not contain collections, so we won't look
         */
        $params = array(':session_principal' => $session->principal_id, ':scan_depth' => $c->permission_scan_depth);
        if ($bound_from == '/') {
            $sql = "SELECT usr.*, '/' || username || '/' AS dav_name, md5(username || updated::text) AS dav_etag, ";
            $sql .= "to_char(joined at time zone 'GMT',{$date_format}) AS created, ";
            $sql .= "to_char(updated at time zone 'GMT',{$date_format}) AS modified, ";
            $sql .= 'FALSE AS is_calendar, TRUE AS is_principal, FALSE AS is_addressbook, \'principal\' AS type, ';
            $sql .= 'principal_id AS collection_id, ';
            $sql .= 'principal.* ';
            $sql .= 'FROM usr JOIN principal USING (user_no) ';
            $sql .= "WHERE (pprivs(:session_principal::int8,principal.principal_id,:scan_depth::int) & 1::BIT(24))::INT4::BOOLEAN ";
            $sql .= 'ORDER BY usr.user_no';
        } else {
            $qry = new AwlQuery('SELECT * FROM dav_binding WHERE dav_binding.parent_container = :this_dav_name ORDER BY bind_id', array(':this_dav_name' => $bound_from));
            if ($qry->Exec('PROPFIND', __LINE__, __FILE__) && $qry->rows() > 0) {
                while ($binding = $qry->Fetch()) {
                    $resource = new DAVResource($binding->dav_name);
                    if ($resource->HavePrivilegeTo('DAV::read', false)) {
                        $resource->set_bind_location(str_replace($bound_from, $bound_to, $binding->dav_name));
                        $responses[] = $resource->RenderAsXML($property_list, $reply);
                        if ($depth > 0) {
                            $responses = array_merge($responses, get_collection_contents($depth - 1, $resource, $binding->dav_name));
                        }
                    }
                }
            }
            $sql = 'SELECT principal.*, collection.*, \'collection\' AS type ';
            $sql .= 'FROM collection LEFT JOIN principal USING (user_no) ';
            $sql .= 'WHERE parent_container = :this_dav_name ';
            $sql .= "AND (path_privs(:session_principal::int8,collection.dav_name,:scan_depth::int) & 1::BIT(24))::INT4::BOOLEAN ";
            $sql .= ' ORDER BY collection_id';
            $params[':this_dav_name'] = $bound_from;
        }
        $qry = new AwlQuery($sql, $params);
        if ($qry->Exec('PROPFIND', __LINE__, __FILE__) && $qry->rows() > 0) {
            while ($subcollection = $qry->Fetch()) {
                $resource = new DAVResource($subcollection);
                $resource->set_bind_location(str_replace($bound_from, $bound_to, $subcollection->dav_name));
                $responses[] = $resource->RenderAsXML($property_list, $reply);
                if ($depth > 0) {
                    $responses = array_merge($responses, get_collection_contents($depth - 1, $resource, str_replace($resource->parent_path(), $parent_path, $resource->dav_name())));
                }
            }
        }
        if ($collection->IsPrincipal()) {
            // Caldav Proxy: 5.1 par. 2: Add child resources calendar-proxy-(read|write)
            dbg_error_log('PROPFIND', 'Adding calendar-proxy-read and write. Path: %s', $bound_from);
            $response = add_proxy_response('read', $bound_from);
            if (isset($response)) {
                $responses[] = $response;
            }
            $response = add_proxy_response('write', $bound_from);
            if (isset($response)) {
                $responses[] = $response;
            }
        }
    }
    /**
     * freebusy permission is not allowed to see the items in a collection.  Must have at least read permission.
     */
    if ($collection->HavePrivilegeTo('DAV::read', false)) {
        dbg_error_log('PROPFIND', 'Getting collection items: Depth %d, Path: %s', $depth, $bound_from);
        $privacy_clause = ' ';
        $time_limit_clause = ' ';
        if ($collection->IsCalendar()) {
            if (!$collection->HavePrivilegeTo('all', false)) {
                $privacy_clause = " AND (calendar_item.class != 'PRIVATE' OR calendar_item.class IS NULL) ";
            }
            if (isset($c->hide_older_than) && intval($c->hide_older_than > 0)) {
                $time_limit_clause = " AND calendar_item.dtstart > (now() - interval '" . intval($c->hide_older_than) . " days') ";
            }
        }
        $sql = 'SELECT collection.*, principal.*, calendar_item.*, caldav_data.*, ';
        $sql .= "to_char(coalesce(calendar_item.created, caldav_data.created) at time zone 'GMT',{$date_format}) AS created, ";
        $sql .= "to_char(last_modified at time zone 'GMT',{$date_format}) AS modified, ";
        $sql .= 'summary AS dav_displayname ';
        $sql .= 'FROM caldav_data LEFT JOIN calendar_item USING( dav_id, user_no, dav_name, collection_id) ';
        $sql .= 'LEFT JOIN collection USING(collection_id,user_no) LEFT JOIN principal USING(user_no) ';
        $sql .= 'WHERE collection.dav_name = :collection_dav_name ' . $time_limit_clause . ' ' . $privacy_clause;
        if (isset($c->strict_result_ordering) && $c->strict_result_ordering) {
            $sql .= " ORDER BY caldav_data.dav_id";
        }
        $qry = new AwlQuery($sql, array(':collection_dav_name' => $bound_from));
        if ($qry->Exec('PROPFIND', __LINE__, __FILE__) && $qry->rows() > 0) {
            while ($item = $qry->Fetch()) {
                $resource = new DAVResource($item);
                $resource->set_bind_location(str_replace($bound_from, $bound_to, $item->dav_name));
                $responses[] = $resource->RenderAsXML($property_list, $reply, $parent_path);
            }
        }
    }
    return $responses;
}
예제 #12
0
 /**
  * Render icalendar from milestones
  *
  * @param string $calendar_name
  * @param array $milestones
  * @return null
  */
 private function renderCalendar(User $user, $calendar_name, $milestones, $user_active_projects)
 {
     $calendar = new iCalendar_Calendar();
     $calendar->setPropertyValue('VERSION', '2.0');
     $calendar->setPropertyValue('PRODID', '-//Apple Computer\\, Inc//iCal 1.5//EN');
     $calendar->setPropertyValue('X-WR-CALNAME', $calendar_name);
     $calendar->setPropertyValue('X-WR-TIMEZONE', 'GMT');
     if (is_array($user_active_projects)) {
         foreach ($user_active_projects as $project) {
             $assigned_tasks = $project->getUsersTasks(logged_user());
             if (is_array($assigned_tasks)) {
                 foreach ($assigned_tasks as $task) {
                     $todo = new iCalendar_Todo();
                     $todo->setPropertyValue('SUMMARY', $project->getName() . ": " . $task->getText());
                     $todo->setPropertyValue('UID', 'a9idfv00fd99q344o' . rand() . '*****@*****.**');
                     $date = $task->getDueDate();
                     if (!is_null($date)) {
                         $todo->setPropertyValue('DTSTART', $date->format('Ymd'), array('VALUE' => 'DATE'));
                     }
                     $priority = $task->getTaskList()->getPriority();
                     $priority = $priority ? $priority : 1;
                     $todo->setPropertyValue('PRIORITY', $priority);
                     $todo->setPropertyValue('STATUS', "NEEDS-ACTION");
                     $todo->setPropertyValue('URL', externalUrl($task->getCompleteUrl()));
                     $todo->setPropertyValue('DESCRIPTION', 'Bla Bla Bla');
                     // seting an alarm
                     $alarm = new iCalendar_Alarm();
                     $alarm->setPropertyValue('ACTION', 'DISPLAY');
                     $alarm->setPropertyValue('TRIGGER', '-P7D');
                     $alarm->setPropertyValue('DESCRIPTION', $project->getName() . ": " . $task->getText());
                     $todo->addComponent($alarm);
                     // end alarm
                     $calendar->addComponent($todo);
                 }
             }
         }
     }
     if (is_array($milestones)) {
         foreach ($milestones as $milestone) {
             if (!$user->isMemberOfOwnerCompany() && $milestone->isPrivate()) {
                 continue;
                 // hide private milestone
             }
             if (!$milestone->isCompleted()) {
                 $event = new iCalendar_Event();
                 $date = $milestone->getDueDate();
                 $event->setPropertyValue('DTSTART', $date->format('Ymd'), array('VALUE' => 'DATE'));
                 $date->advance(24 * 60 * 60);
                 $event->setPropertyValue('DTEND', $date->format('Ymd'), array('VALUE' => 'DATE'));
                 $event->setPropertyValue('UID', 'a9idfv00fd99q344o' . rand() . '*****@*****.**');
                 $event->setPropertyValue('SUMMARY', $milestone->getName() . ' (' . $milestone->getProject()->getName() . ')');
                 $event->setPropertyValue('DESCRIPTION', $desc = $milestone->getDescription());
                 $event->setPropertyValue('URL', externalUrl($milestone->getViewUrl()));
                 // setting an alarm
                 $alarm = new iCalendar_Alarm();
                 $alarm->setPropertyValue('ACTION', 'DISPLAY');
                 $alarm->setPropertyValue('TRIGGER', '-P7D');
                 $alarm->setPropertyValue('DESCRIPTION', $milestone->getName() . ' (' . $milestone->getProject()->getName() . ')');
                 $event->addComponent($alarm);
                 // end alarm
                 /* pre_var_dump($desc); */
                 $calendar->addComponent($event);
             }
             // if
         }
         // foreach
     }
     // if
     header('Content-Disposition: inline; filename=calendar.ics');
     $this->renderText(iCalendar::render($calendar), true);
     session_write_close();
     die;
 }
예제 #13
0
function get_freebusy($path_match, $range_start, $range_end, $bin_privs = null)
{
    global $request;
    //  printf( "Path: %s\n", $path_match);
    //  print_r($range_start);
    //  print_r($range_end);
    if (!isset($bin_privs)) {
        $bin_privs = $request->Privileges();
    }
    if (!isset($range_start) || !isset($range_end)) {
        $request->DoResponse(400, 'All valid freebusy requests MUST contain a time-range filter');
    }
    $params = array(':path_match' => $path_match, ':start' => $range_start->UTC(), ':end' => $range_end->UTC());
    $where = ' WHERE caldav_data.dav_name ~ :path_match ';
    $where .= 'AND rrule_event_overlaps( dtstart, dtend, rrule, :start, :end) ';
    $where .= "AND caldav_data.caldav_type IN ( 'VEVENT', 'VTODO' ) ";
    $where .= "AND (calendar_item.transp != 'TRANSPARENT' OR calendar_item.transp IS NULL) ";
    $where .= "AND (calendar_item.status != 'CANCELLED' OR calendar_item.status IS NULL) ";
    $where .= "AND collection.is_calendar AND collection.schedule_transp = 'opaque' ";
    if ($bin_privs != privilege_to_bits('all')) {
        $where .= "AND (calendar_item.class != 'PRIVATE' OR calendar_item.class IS NULL) ";
    }
    // $debugging = true;
    $fbtimes = array();
    $sql = 'SELECT caldav_data.caldav_data, calendar_item.rrule, calendar_item.transp, calendar_item.status, ';
    $sql .= "to_char(calendar_item.dtstart at time zone 'GMT'," . iCalendar::SqlUTCFormat() . ') AS start, ';
    $sql .= "to_char(calendar_item.dtend at time zone 'GMT'," . iCalendar::SqlUTCFormat() . ') AS finish, ';
    $sql .= "calendar_item.class, calendar_item.dav_id ";
    $sql .= 'FROM caldav_data INNER JOIN calendar_item USING(dav_id,user_no,dav_name,collection_id) ';
    $sql .= 'INNER JOIN collection USING(collection_id)';
    $sql .= $where;
    if (isset($c->strict_result_ordering) && $c->strict_result_ordering) {
        $sql .= ' ORDER BY dav_id';
    }
    $qry = new AwlQuery($sql, $params);
    if ($qry->Exec("REPORT", __LINE__, __FILE__) && $qry->rows() > 0) {
        while ($calendar_object = $qry->Fetch()) {
            $extra = '';
            if ($calendar_object->status == 'TENTATIVE') {
                $extra = ';BUSY-TENTATIVE';
            }
            //      else if ( $debugging ) {
            //        $extra = ';'.$calendar_object->dav_id;
            //      }
            dbg_error_log("REPORT", " FreeBusy: Not transparent, tentative or cancelled: %s, %s, %s", $calendar_object->start, $calendar_object->finish, $calendar_object->class);
            $ics = new vComponent($calendar_object->caldav_data);
            $expanded = expand_event_instances($ics, $range_start, $range_end);
            $expansion = $expanded->GetComponents(array('VEVENT' => true, 'VTODO' => true, 'VJOURNAL' => true));
            foreach ($expansion as $k => $v) {
                //        echo "=====================================================\n";
                //        printf( "Type: %s\n", $v->GetType());
                //        print_r($v);
                //        echo "-----------------------------------------------------\n";
                $start_date = $v->GetProperty('DTSTART');
                if (!isset($start_date)) {
                    continue;
                }
                $start_date = new RepeatRuleDateTime($start_date);
                $duration = $v->GetProperty('DURATION');
                $duration = !isset($duration) ? 'P1D' : $duration->Value();
                $end_date = clone $start_date;
                $end_date->modify($duration);
                if ($end_date == $start_date || $end_date < $range_start || $start_date > $range_end) {
                    continue;
                }
                $thisfb = $start_date->UTC() . '/' . $end_date->UTC() . $extra;
                array_push($fbtimes, $thisfb);
            }
        }
    }
    $freebusy = new iCalComponent();
    $freebusy->SetType('VFREEBUSY');
    $freebusy->AddProperty('DTSTAMP', date('Ymd\\THis\\Z'));
    $freebusy->AddProperty('DTSTART', $range_start->UTC());
    $freebusy->AddProperty('DTEND', $range_end->UTC());
    sort($fbtimes);
    foreach ($fbtimes as $k => $v) {
        $text = explode(';', $v, 2);
        $freebusy->AddProperty('FREEBUSY', $text[0], isset($text[1]) ? array('FBTYPE' => $text[1]) : null);
    }
    return $freebusy;
}
예제 #14
0
/**
* Get XML response for a single item.  Depth is irrelevant for this.
*/
function get_item($item_path)
{
    global $session;
    $responses = array();
    dbg_error_log("PROPFIND", "Getting item: Path: %s", $item_path);
    $sql = "SELECT caldav_data.dav_name, caldav_data, caldav_data.dav_etag ";
    $sql .= "FROM caldav_data WHERE dav_name = ?";
    $qry = new PgQuery($sql, PgQuery::Plain(iCalendar::HttpDateFormat()), PgQuery::Plain(iCalendar::HttpDateFormat()), $item_path);
    if ($qry->Exec("PROPFIND", __LINE__, __FILE__) && $qry->rows > 0) {
        while ($item = $qry->Fetch()) {
            $responses[] = item_to_xml($item);
        }
    }
    return $responses;
}
예제 #15
0
/**
 * From a URL, fetch the calendar and return an iCalendar object.
 *
 * @param string $url The iCalendar URL
 * @return stdClass The iCalendar object
 */
function calendar_get_icalendar($url)
{
    global $CFG;
    require_once $CFG->libdir . '/filelib.php';
    $curl = new curl();
    $curl->setopt(array('CURLOPT_FOLLOWLOCATION' => 1, 'CURLOPT_MAXREDIRS' => 5));
    $calendar = $curl->get($url);
    // Http code validation should actually be the job of curl class.
    if (!$calendar || $curl->info['http_code'] != 200 || !empty($curl->errorno)) {
        throw new moodle_exception('errorinvalidicalurl', 'calendar');
    }
    $ical = new iCalendar();
    $ical->unserialize($calendar);
    return $ical;
}
 /**
  * Render icalendar from milestones
  *
  * @param string $calendar_name
  * @param array $milestones
  * @return null
  */
 private function renderCalendar(User $user, $calendar_name, $milestones)
 {
     $calendar = new iCalendar_Calendar();
     $calendar->setPropertyValue('VERSION', '2.0');
     $calendar->setPropertyValue('PRODID', '-//Apple Computer\\, Inc//iCal 1.5//EN');
     $calendar->setPropertyValue('X-WR-CALNAME', $calendar_name);
     $calendar->setPropertyValue('X-WR-TIMEZONE', 'GMT');
     if (is_array($milestones)) {
         foreach ($milestones as $milestone) {
             if (!$user->isMemberOfOwnerCompany() && $milestone->isPrivate()) {
                 continue;
             }
             // hide private milestone
             if (!$milestone->isCompleted()) {
                 $event = new iCalendar_Event();
                 $date = $milestone->getDueDate();
                 $event->setPropertyValue('DTSTART', $date->format('Ymd'), array('VALUE' => 'DATE'));
                 $date->advance(24 * 60 * 60);
                 $event->setPropertyValue('DTEND', $date->format('Ymd'), array('VALUE' => 'DATE'));
                 $event->setPropertyValue('UID', $milestone->getId());
                 $event->setPropertyValue('SUMMARY', $milestone->getName() . ' (' . $milestone->getProject()->getName() . ')');
                 $event->setPropertyValue('DESCRIPTION', $desc = $milestone->getDescription());
                 /* pre_var_dump($desc); */
                 $calendar->addComponent($event);
             }
             // if
         }
         // foreach
     }
     // if
     header('Content-Disposition: inline; filename=calendar.ics');
     $this->renderText(iCalendar::render($calendar), true);
     die;
 }
예제 #17
0
if (!calendar_user_can_add_event($course)) {
    print_error('errorcannotimport', 'calendar');
}
$form = new calendar_addsubscription_form(null);
$form->set_data(array('course' => $course->id));
$importresults = '';
$formdata = $form->get_data();
if (!empty($formdata)) {
    require_sesskey();
    // Must have sesskey for all actions.
    $subscriptionid = calendar_add_subscription($formdata);
    if ($formdata->importfrom == CALENDAR_IMPORT_FROM_FILE) {
        // Blank the URL if it's a file import.
        $formdata->url = '';
        $calendar = $form->get_file_content('importfile');
        $ical = new iCalendar();
        $ical->unserialize($calendar);
        $importresults = calendar_import_icalendar_events($ical, $courseid, $subscriptionid);
    } else {
        try {
            $importresults = calendar_update_subscription_events($subscriptionid);
        } catch (moodle_exception $e) {
            // Delete newly added subscription and show invalid url error.
            calendar_delete_subscription($subscriptionid);
            print_error($e->errorcode, $e->module, $PAGE->url);
        }
    }
    // Redirect to prevent refresh issues.
    redirect($PAGE->url, $importresults);
} else {
    if (!empty($subscriptionid)) {
예제 #18
0
 /**
  * Setter for the event description. This value needs to be escaped.
  *
  * \param $str
  *   The description to set
  */
 function set_description($str)
 {
     $this->_set('description', iCalendar::escape_string($str));
 }