コード例 #1
0
function export_ical()
{
    global $publish_fullname, $user;
    $res = get_events_for_publish();
    $entry_array = array();
    $count = 0;
    while ($entry = dbi_fetch_row($res)) {
        $entry_array[$count++] = $entry;
    }
    if ($count > 0) {
        echo "BEGIN:VCALENDAR\r\n";
        $title = "X-WR-CALNAME;VALUE=TEXT:" . (empty($publish_fullname) ? $user : translate($publish_fullname));
        $title = str_replace(",", "\\,", $title);
        echo "{$title}\r\n";
        if (preg_match("/WebCalendar v(\\S+)/", $PROGRAM_NAME, $match)) {
            echo "PRODID:-//WebCalendar-{$match['1']}\r\n";
        } else {
            echo "PRODID:-//WebCalendar-UnknownVersion\r\n";
        }
        echo "VERSION:2.0\r\n";
        echo "METHOD:PUBLISH\r\n";
    }
    while (list($key, $row) = each($entry_array)) {
        $uid = $row[0];
        $export_uid = generate_uid($uid);
        $name = $row[1];
        $priority = $row[2];
        $date = $row[3];
        $time = $row[4];
        $status = $row[5];
        $create_by = $row[6];
        $access = $row[7];
        $duration = $row[8];
        $description = $row[9];
        /* Start of event */
        echo "BEGIN:VEVENT\r\n";
        /* UID of the event (folded to 76 char) */
        $array = export_fold_lines("UID:{$export_uid}");
        while (list($key, $value) = each($array)) {
            echo "{$value}\r\n";
        }
        $name = preg_replace("/\r/", "", $name);
        $name = preg_replace("/\n/", "\\n", $name);
        $name = preg_replace("/\\\\/", "\\\\\\", $name);
        // ??
        $description = preg_replace("/\r/", "", $description);
        $description = preg_replace("/\n/", "\\n", $description);
        $description = preg_replace("/\\\\/", "\\\\\\", $description);
        // ??
        /* SUMMARY of the event (folded to 76 char) */
        $name = "SUMMARY:" . $name;
        $array = export_fold_lines($name, "utf8");
        while (list($key, $value) = each($array)) {
            echo "{$value}\r\n";
        }
        /* DESCRIPTION if any (folded to 76 char) */
        if ($description != "") {
            $description = "DESCRIPTION:" . $description;
            $array = export_fold_lines($description, "utf8");
            while (list($key, $value) = each($array)) {
                echo "{$value}\r\n";
            }
        }
        /* CLASS either "PRIVATE" or "PUBLIC" (the default) */
        if ($access == "R") {
            echo "CLASS:PRIVATE\r\n";
        } else {
            echo "CLASS:PUBLIC\r\n";
        }
        /* Time - all times are utc */
        export_time($date, $duration, $time, "ical");
        /* Recurrence */
        export_recurrence_ical($uid, $date);
        /* handle alarms */
        export_alarm_ical($uid, $description);
        /* Goodbye event */
        echo "END:VEVENT\r\n";
    }
    if ($count > 0) {
        echo "END:VCALENDAR\r\n";
    }
}
コード例 #2
0
function export_ical($id)
{
    global $prodid;
    header("Content-Type: text/calendar");
    //header ( "Content-Type: text/plain" );
    $res = export_get_event_entry($id);
    $entry_array = array();
    $count = 0;
    while ($entry = dbi_fetch_row($res)) {
        $entry_array[$count++] = $entry;
    }
    if ($count > 0) {
        echo "BEGIN:VCALENDAR\r\n";
        echo "{$prodid}\r\n";
        echo "VERSION:2.0\r\n";
        echo "METHOD:PUBLISH\r\n";
    }
    while (list($key, $row) = each($entry_array)) {
        $uid = $row[0];
        $export_uid = generate_uid();
        $name = $row[1];
        $priority = $row[2];
        $date = $row[3];
        $time = $row[4];
        $status = $row[5];
        $create_by = $row[6];
        $access = $row[7];
        $duration = $row[8];
        $description = $row[9];
        /* Start of event */
        echo "BEGIN:VEVENT\r\n";
        /* UID of the event (folded to 76 char) */
        $array = export_fold_lines("UID:{$export_uid}");
        while (list($key, $value) = each($array)) {
            echo "{$value}\r\n";
        }
        $name = preg_replace("/\r/", "", $name);
        $name = preg_replace("/\n/", "\\n", $name);
        $name = preg_replace("/\\\\/", "\\\\\\", $name);
        // ??
        $description = preg_replace("/\r/", "", $description);
        $description = preg_replace("/\n/", "\\n", $description);
        $description = preg_replace("/\\\\/", "\\\\\\", $description);
        // ??
        /* SUMMARY of the event (folded to 76 char) */
        $name = "SUMMARY:" . $name;
        $array = export_fold_lines($name, "utf8");
        while (list($key, $value) = each($array)) {
            echo "{$value}\r\n";
        }
        /* DESCRIPTION if any (folded to 76 char) */
        if ($description != "") {
            $description = "DESCRIPTION:" . $description;
            $array = export_fold_lines($description, "utf8");
            while (list($key, $value) = each($array)) {
                echo "{$value}\r\n";
            }
        }
        /* CLASS either "PRIVATE" or "PUBLIC" (the default) */
        if ($access == "R") {
            echo "CLASS:PRIVATE\r\n";
        } else {
            echo "CLASS:PUBLIC\r\n";
        }
        // ATTENDEE of the event
        $attendee = export_get_attendee($row[0], "ical");
        for ($i = 0; $i < count($attendee); $i++) {
            $attendee[$i] = export_fold_lines($attendee[$i], "utf8");
            while (list($key, $value) = each($attendee[$i])) {
                echo "{$value}\r\n";
            }
        }
        /* Time - all times are utc */
        export_time($date, $duration, $time, "ical");
        /* Recurrence */
        export_recurrence_ical($uid, $date);
        // FIXME: handle alarms
        export_alarm_ical($uid, $description);
        /* Goodbye event */
        echo "END:VEVENT\r\n";
    }
    //end while (list($key,$row) = each($entry_array))
    if ($count > 0) {
        echo "END:VCALENDAR\r\n";
    }
}
コード例 #3
0
 function print_upcoming_event($e, $date)
 {
     global $display_link, $link_target, $SERVER_URL, $charset, $login, $display_tzid, $showTime, $showPopups, $eventinfo, $username, $hcalendar_output, $UPCOMING_DISPLAY_CAT_ICONS;
     $popupid = 'pop' . $e->getId() . '-' . $date;
     $private = $confidential = false;
     // Access: P=Public, R=Private, C=Confidential
     if ($e->getAccess() == 'R') {
         // not a public event, so we will just display "Private"
         $private = true;
     } else {
         if ($e->getAccess() == 'C') {
             // not a public event, so we will just display "Confidential"
             $confidential = true;
         }
     }
     if (!empty($SERVER_URL) && !$private && !$confidential) {
         echo "<div class=\"vevent\">\n";
         if ($display_link) {
             if ($showPopups) {
                 $timestr = '';
                 if ($e->isAllDay()) {
                     $timestr = translate('All day event');
                 } else {
                     if ($e->getTime() >= 0) {
                         $timestr = display_time($e->getDatetime());
                         if ($e->getDuration() > 0) {
                             $timestr .= ' - ' . display_time($e->getEndDateTime());
                         }
                     }
                 }
                 $eventinfo .= build_entry_popup('eventinfo-' . $popupid, $username, $e->getDescription(), $timestr, site_extras_for_popup($e->getId()), $e->getLocation(), $e->getName(), $e->getId());
             }
             $link = "<a class=\"entry\" id=\"{$popupid}\" title=\"" . htmlspecialchars($e->getName()) . '" href="' . $SERVER_URL . 'view_entry.php?id=' . $e->getID() . "&amp;date={$date}&amp;user="******"\" target=\"{$link_target}\"";
             }
             $link .= '>';
             if (empty($UPCOMING_DISPLAY_CAT_ICONS) || $UPCOMING_DISPLAY_CAT_ICONS != 'N') {
                 $catNum = abs($e->getCategory());
                 if ($catNum > 0) {
                     $catIcon = 'icons/cat-' . $catNum . '.gif';
                     if (file_exists($catIcon)) {
                         echo $link . '<img src="' . $catIcon . '" alt="category icon" border="0"/></a>';
                     }
                 }
             }
             echo $link;
         }
     }
     if ($private) {
         echo '[' . translate('Private') . ']';
     } else {
         if ($confidential) {
             echo '[' . translate('Confidential') . ']';
         } else {
             echo '<span class="summary">' . htmlspecialchars($e->getName()) . '</span>';
         }
     }
     if ($display_link && !empty($SERVER_URL) && !$private) {
         echo '</a>';
     }
     //added for hCalendar
     if ($hcalendar_output) {
         echo '<abbr class="dtstart" title="' . export_ts_utc_date($e->getDateTimeTS()) . '">' . $e->getDateTime() . "</abbr>\n";
         echo '<abbr class="dtend" title="' . export_ts_utc_date($e->getEndDateTimeTS()) . '">' . $e->getEndDateTimeTS() . "</abbr>\n";
         echo '<span class="description">' . $e->getDescription() . "</span>\n";
         if (strlen($e->getLocation()) > 0) {
             echo '<span class="location">' . $e->getLocation() . "</span>\n";
         }
         $categories = get_categories_by_id($e->getId(), $username);
         $category = implode(', ', $categories);
         if (strlen($category) > 0) {
             echo '<span class="categories">' . htmlentities($category) . "</span>\n";
         }
         if (strlen($e->getUrl()) > 0) {
             echo '<span class="url">' . $e->getUrl() . "</span>\n";
         }
         $rrule = export_recurrence_ical($e->getId());
         if (strlen($rrule) > 6) {
             echo '<span class="rrule">' . substr($rrule, 6) . "</span>\n";
         }
     }
     if ($showTime) {
         //show event time if requested (default=don't show)
         if ($e->isAllDay()) {
             echo ' (' . translate('All day event') . ")\n";
         } else {
             if ($e->getTime() != -1) {
                 echo ' (' . display_time($e->getDateTime(), $display_tzid) . ")\n";
             }
         }
     }
     echo "</div>\n";
 }
コード例 #4
0
ファイル: view_entry.php プロジェクト: rhertzog/lcs
      </tr>' : '') . '
      <tr>
        <td class="aligntop bold">' . translate('Due Date') . ':</td>
        <td>' . date_to_str($due_date) . '</td>
      </tr>
      <tr>
        <td class="aligntop bold">' . translate('Due Time') . ':</td>
        <td>' . display_time($due_date . sprintf("%06d", $due_time), 2) . '</td>
      </tr>' . (!empty($cal_completed) ? '
      <tr>
        <td class="aligntop bold">' . translate('Completed') . ':</td>
        <td>' . date_to_str($cal_completed) : '') : '') . '</td>
      </tr>' . ($event_repeats ? '
      <tr>
        <td class="aligntop bold">' . translate('Repeat Type') . ':</td>
        <td>' . export_recurrence_ical($id, true) . '</td>
      </tr>' : '') . ($eType != 'task' && $event_time >= 0 ? '
      <tr>
        <td class="aligntop bold">' . translate('Time') . ':</td>
        <td>' . ($duration == 1440 && $event_time == 0 ? translate('All day event') : display_time($display_date . sprintf("%06d", $event_time), empty($end_str) ? 2 : 0) . $end_str) . '</td>
      </tr>' : '');
if ($duration > 0 && $duration != 1440) {
    $dur_h = intval($duration / 60);
    $dur_m = $duration - $dur_h * 60;
    echo '
      <tr>
        <td class="aligntop bold">' . translate('Duration') . ':</td>
        <td>' . ($dur_h > 0 ? $dur_h . ' ' . translate('hour' . ($dur_h == 1 ? '' : 's')) . ' ' : '') . ($dur_m > 0 ? $dur_m . ' ' . translate('minutes') : '') . '</td>
      </tr>';
}
echo ($DISABLE_PRIORITY_FIELD != 'Y' ? '
コード例 #5
0
ファイル: xcal.php プロジェクト: rhertzog/lcs
function export_ical($id = 'all', $attachment = false)
{
    global $publish_fullname, $login, $cal_type, $cat_filter, $vtimezone_data, $use_vtimezone;
    $exportId = -1;
    $ret = $Vret = $vtimezone_data = $use_vtimezone = '';
    $res = export_get_event_entry($id, $attachment);
    $entry_array = array();
    $count = 0;
    while ($entry = dbi_fetch_row($res)) {
        $entry_array[$count++] = $entry;
    }
    dbi_free_result($res);
    //abort if no records to output
    if ($count == 0) {
        return;
    }
    // Always output something, even if no records come back
    // This prevents errors on the iCal client
    $ret = "BEGIN:VCALENDAR\r\n";
    $title = utf8_encode('X-WR-CALNAME;VALUE=TEXT:' . (empty($publish_fullname) ? $login : translate($publish_fullname)));
    $title = str_replace(',', "\\,", $title);
    $ret .= "{$title}\r\n";
    $ret .= generate_prodid('ics');
    $ret .= "VERSION:2.0\r\n";
    $ret .= "METHOD:PUBLISH\r\n";
    while (list($key, $row) = each($entry_array)) {
        $id = $row[0];
        $event_uid = generate_uid($id);
        $name = $row[1];
        $priority = $row[2];
        $date = $row[3];
        $time = sprintf("%06d", $row[4]);
        $status = $row[5];
        $create_by = $row[6];
        $access = $row[7];
        $duration = $row[8];
        $description = $row[9];
        // New columns to support tasks
        $percent = empty($row[10]) ? 0 : $row[10];
        $completed = empty($row[11]) ? '' : substr($row[11], 0, 8) . 'T' . sprintf("%06d", substr($row[11], 9, 6));
        $due_date = $row[12];
        $due_time = $row[13];
        $location = $row[14];
        $url = $row[15];
        $cal_type = $row[16];
        $moddate = $row[17];
        $modtime = $row[18];
        // Figure out Categories
        $categories = get_categories_by_id($id, $login);
        // Add entry in webcal_import_data if it does not exist.
        // Even thought we're exporting, this data needs to be valid
        // for proper parsing of response from iCal client.
        // If this is the first event that has never been published,
        // then create a new import instance to associate with what we are doing.
        $sql = 'SELECT wid.cal_external_id
      FROM webcal_import_data wid, webcal_entry_user weu
      WHERE wid.cal_id = weu.cal_id AND wid.cal_id = ? AND
      weu.cal_login = ?';
        $res = dbi_execute($sql, array($id, $login));
        if ($res) {
            if ($row = dbi_fetch_row($res)) {
                // event has been published (or imported) before
                $event_uid = $row[0];
            } else {
                if ($exportId < 0) {
                    // This is first event that has not been published before.
                    // Create an entry in webcal_import.
                    // It would be nice if we could put a name in here of who
                    // or where the remote cal subscription is coming from in case
                    // they update some of our events. But, I cannot see a way to
                    // do that.
                    $exportId = create_import_instance();
                }
                if ($attachment == false) {
                    save_uid_for_event($exportId, $id, $event_uid);
                }
            }
            dbi_free_result($res);
        }
        // get recurrance info
        $recurrance = export_recurrence_ical($id);
        if (!empty($recurrance)) {
            $use_vtimezone = true;
        }
        /* snippet from RFC2445
          The "VTIMEZONE" calendar component MUST be present if the iCalendar
           object contains an RRULE that generates dates on both sides of a time
           zone shift (e.g. both in Standard Time and Daylight Saving Time)
           unless the iCalendar object intends to convey a floating time (See
           the section "4.1.10.11 Time" for proper interpretation of floating
           time). It can be present if the iCalendar object does not contain
           such a RRULE. In addition, if a RRULE is present, there MUST be valid
           time zone information for all recurrence instances.
        
           However, this is not possible to implement at this time
           */
        // if Categories were selected as an export filter, then abort this
        // event if it does not contain that category
        if (!empty($cat_filter)) {
            if (count($categories) == 0 || !array_key_exists($cat_filter, $categories)) {
                continue;
            }
        }
        if ($cal_type == 'E' || $cal_type == 'M') {
            $exporting_event = true;
            /* Start of event */
            $Vret .= "BEGIN:VEVENT\r\n";
        } else {
            if ($cal_type == 'T' || $cal_type == 'N') {
                $exporting_event = false;
                /* Start of VTODO */
                $Vret .= "BEGIN:VTODO\r\n";
            } else {
                if ($cal_type == 'J' || $cal_type == 'O') {
                    $exporting_event = false;
                    /* Start of VJOURNAL */
                    $Vret .= "BEGIN:VJOURNAL\r\n";
                }
            }
        }
        /* UID of the event (folded to 76 char) */
        $array = export_fold_lines("UID:{$event_uid}");
        while (list($key, $value) = each($array)) {
            $Vret .= "{$value}\r\n";
        }
        $Vret .= 'LAST-MODIFIED:' . export_get_utc_date($moddate, $modtime) . "\r\n";
        $name = preg_replace("/\r/", ' ', $name);
        // escape,;  \ in octal ascii
        $name = addcslashes($name, ",;\\");
        $description = preg_replace("/\r/", ' ', $description);
        $description = addcslashes($description, ",;\\");
        $description = str_replace(chr(10), chr(92) . chr(110), $description);
        /* SUMMARY of the event (folded to 76 char) */
        $name = 'SUMMARY:' . $name;
        $array = export_fold_lines($name, 'utf8');
        while (list($key, $value) = each($array)) {
            $Vret .= "{$value}\r\n";
        }
        /* DESCRIPTION if any (folded to 76 char) */
        if ($description != '') {
            $description = 'DESCRIPTION:' . $description;
            $array = export_fold_lines($description, 'utf8');
            while (list($key, $value) = each($array)) {
                $Vret .= "{$value}\r\n";
            }
        }
        /* LOCATION if any (folded to 76 char) */
        if ($location != '') {
            $location = 'LOCATION:' . $location;
            $array = export_fold_lines($location, 'utf8');
            while (list($key, $value) = each($array)) {
                $Vret .= "{$value}\r\n";
            }
        }
        /* URL if any (folded to 76 char) */
        if ($url != '') {
            $url = 'URL:' . $url;
            $array = export_fold_lines($url, 'utf8');
            while (list($key, $value) = each($array)) {
                $Vret .= "{$value}\r\n";
            }
        }
        /* CATEGORIES if any (folded to 76 char) */
        if (isset($categories) && count($categories)) {
            $categories = 'CATEGORIES:' . implode(',', $categories);
            $array = export_fold_lines($categories, 'utf8');
            while (list($key, $value) = each($array)) {
                $Vret .= "{$value}\r\n";
            }
        }
        /* CLASS either "PRIVATE", "CONFIDENTIAL",  or "PUBLIC" (the default) */
        if ($access == 'R') {
            $Vret .= "CLASS:PRIVATE\r\n";
        } else {
            if ($access == 'C') {
                $Vret .= "CLASS:CONFIDENTIAL\r\n";
            } else {
                $Vret .= "CLASS:PUBLIC\r\n";
            }
        }
        /* STATUS */
        if ($cal_type == 'E' || $cal_type == 'M') {
            if ($status == 'A') {
                $Vret .= "STATUS:CONFIRMED\r\n";
            } else {
                if ($status == 'W') {
                    $Vret .= "STATUS:TENTATIVE\r\n";
                } else {
                    if ($status == 'D') {
                        $Vret .= "STATUS:CANCELLED\r\n";
                    }
                }
            }
        } else {
            if ($cal_type == 'T' || $cal_type == 'N') {
                if ($status == 'A' && empty($completed)) {
                    $Vret .= "STATUS:IN-PROCESS\r\n";
                } else {
                    if ($status == 'A') {
                        $Vret .= "STATUS:COMPLETED\r\n";
                    } else {
                        if ($status == 'W') {
                            $Vret .= "STATUS:NEEDS-ACTION\r\n";
                        } else {
                            if ($status == 'D') {
                                $Vret .= "STATUS:CANCELLED\r\n";
                            }
                        }
                    }
                }
            }
        }
        // ATTENDEE of the event
        $attendee = export_get_attendee($id, 'ical');
        $attendcnt = count($attendee);
        for ($i = 0; $i < $attendcnt; $i++) {
            $attendee[$i] = export_fold_lines($attendee[$i], 'utf8');
            while (list($key, $value) = each($attendee[$i])) {
                $Vret .= "{$value}\r\n";
            }
        }
        /* Time - all times are utc */
        $Vret .= export_time($date, $duration, $time, 'ical', $cal_type);
        // VTODO specific items
        $task_complete = false;
        if ($cal_type == 'T' || $cal_type == 'N') {
            $Vret .= 'DUE:' . $due_date . 'T' . sprintf("%06d", $due_time) . "Z\r\n";
            if (!empty($completed)) {
                $Vret .= 'COMPLETED:' . $completed . "\r\n";
                $task_complete = true;
            }
            $Vret .= 'PERCENT-COMPLETE:' . $percent . "\r\n";
        }
        /* Recurrence */
        $Vret .= $recurrance;
        /* handle alarms */
        $Vret .= export_alarm_ical($id, $date, $description, $task_complete);
        if ($cal_type == 'E' || $cal_type == 'M') {
            /* End of event */
            $Vret .= "END:VEVENT\r\n";
        } else {
            if ($cal_type == 'T' || $cal_type == 'N') {
                /* Start of VTODO */
                $Vret .= "END:VTODO\r\n";
            } else {
                if ($cal_type == 'J' || $cal_type == 'O') {
                    /* Start of VJOURNAL */
                    $Vret .= "END:VJOURNAL\r\n";
                }
            }
        }
    }
    /* VTIMEZONE Set in export_time () if needed */
    $ret .= $vtimezone_data . $Vret;
    $ret .= "END:VCALENDAR\r\n";
    // attachment will be true if called during email creation
    if (!$attachment) {
        echo $ret;
    } else {
        return $ret;
    }
}