コード例 #1
0
function churchcal__ical()
{
    global $base_url, $config;
    include_once CHURCHCAL . "/churchcal_db.php";
    drupal_add_http_header('Content-Type', 'text/calendar;charset=utf-8', false);
    drupal_add_http_header('Content-Disposition', 'inline;filename="ChurchTools.ics"', false);
    drupal_add_http_header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', false);
    drupal_add_http_header('Cache-Control', 'private', true);
    $content = drupal_get_header();
    $cat_names = null;
    if (isset($_GET["security"]) && isset($_GET["id"])) {
        $db = db_query("select * from {cc_calcategory} where id=:id and randomurl=:randomurl", array(":id" => $_GET["id"], ":randomurl" => $_GET["security"]))->fetch();
        if ($db != false) {
            $cat_names[$_GET["id"]] = new stdClass();
            $cat_names[$_GET["id"]]->bezeichnung = $db->bezeichnung;
            $cats = array(0 => $_GET["id"]);
        }
    }
    if ($cat_names == null) {
        $cats = churchcal_getAllowedCategories(false, true);
        $cat_names = churchcal_getAllowedCategories(false, false);
    }
    $arr = churchcal_getCalPerCategory(array("category_ids" => $cats), false);
    $txt = "";
    foreach ($arr as $cats) {
        foreach ($cats as $res) {
            $res->startdate = new DateTime($res->startdate);
            $res->enddate = new DateTime($res->enddate);
            $diff = $res->enddate->format("U") - $res->startdate->format("U");
            $subid = 0;
            foreach (getAllDatesWithRepeats($res, -90, 400) as $d) {
                $txt .= "BEGIN:VEVENT\r\n";
                $txt .= "ORGANIZER:MAILTO:" . variable_get('site_mail', '') . "\r\n";
                $txt .= "SUMMARY:" . $res->bezeichnung . "\r\n";
                //$txt.="X-MICROSOFT-CDO-BUSYSTATUS:BUSY\r\n";
                if ($res->link != "") {
                    $txt .= "URL:" . $res->link . "\r\n";
                } else {
                    $txt .= "URL:" . $base_url . "?q=churchcal\r\n";
                }
                if ($res->ort != "") {
                    $txt .= "LOCATION:" . $res->ort . "\r\n";
                }
                $subid++;
                $txt .= "UID:" . $res->id . "_{$subid}\r\n";
                $txt .= "DTSTAMP:" . churchcore_stringToDateICal($res->modified_date) . "\r\n";
                $ts = $diff + $d->format("U");
                //$enddate=new DateTime("@$ts");
                $enddate = clone $d;
                $enddate->modify("+{$diff} seconds");
                // Ganztagestermin
                if ($res->startdate->format('His') == "000000" && $res->enddate->format('His') == "000000") {
                    $txt .= "DTSTART;VALUE=DATE:" . $d->format('Ymd') . "\r\n";
                    $txt .= "DTEND;VALUE=DATE:" . date('Ymd', strtotime('+1 day', $enddate->format("U"))) . "\r\n";
                } else {
                    $txt .= "DTSTART:" . $d->format('Ymd\\THis') . "\r\n";
                    $txt .= "DTEND:" . $enddate->format('Ymd\\THis') . "\r\n";
                }
                $txt .= 'DESCRIPTION:Kalender:' . $cat_names[$res->category_id]->bezeichnung . ' - Cal[' . $res->id . '] - ' . $res->notizen . "\r\n";
                $txt .= "END:VEVENT\r\n";
            }
        }
    }
    echo surroundWithVCALENDER($txt);
}
コード例 #2
0
ファイル: churchcal.php プロジェクト: toXel/churchtools_basic
/**
 * use template for calendar entries, include text added by surroundWithVCALENDER
 */
function churchcal__ical()
{
    global $base_url, $config;
    include_once CHURCHCAL . "/churchcal_db.php";
    drupal_add_http_header('Content-Type', 'text/calendar;charset=utf-8', false);
    drupal_add_http_header('Content-Disposition', 'inline;filename="ChurchTools.ics"', false);
    drupal_add_http_header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', false);
    drupal_add_http_header('Cache-Control', 'private', true);
    $content = drupal_get_header();
    $catNames = null;
    if (($security = getVar("security")) && ($id = getVar("id"))) {
        $db = db_query("SELECT * FROM {cc_calcategory}\n                    WHERE id=:id AND randomurl=:randomurl", array(":id" => $id, ":randomurl" => $security))->fetch();
        if ($db) {
            $catNames[$id] = new stdClass();
            $catNames[$id]->bezeichnung = $db->bezeichnung;
            $cats = array(0 => $id);
        }
    }
    if (!$catNames) {
        $cats = churchcal_getAllowedCategories(false, true);
        $catNames = churchcal_getAllowedCategories(false, false);
    }
    $arr = churchcal_getCalPerCategory(array("category_ids" => $cats), false);
    $txt = "";
    foreach ($arr as $cats) {
        foreach ($cats as $res) {
            $res->startdate = new DateTime($res->startdate);
            $res->enddate = new DateTime($res->enddate);
            $diff = $res->enddate->format("U") - $res->startdate->format("U");
            // TODO: use DateTime function like next line?
            //     $diff = $res->enddate->diff($res->startdate);
            $subid = 0;
            foreach (getAllDatesWithRepeats($res, -90, 730) as $d) {
                $txt .= "BEGIN:VEVENT" . NL;
                $txt .= "ORGANIZER:MAILTO:" . getConf('site_mail', '') . NL;
                $txt .= "SUMMARY:" . $res->bezeichnung . NL;
                //$txt.="X-MICROSOFT-CDO-BUSYSTATUS:BUSY" . NL;
                if ($res->link != "") {
                    $txt .= "URL:" . $res->link . NL;
                } else {
                    $txt .= "URL:" . $base_url . "?q=churchcal" . NL;
                }
                if ($res->ort != "") {
                    $txt .= "LOCATION:" . $res->ort . NL;
                }
                $subid++;
                $txt .= "UID:{$res->id}_{$subid}" . NL;
                $txt .= "DTSTAMP:" . churchcore_stringToDateICal($res->modified_date) . NL;
                $enddate = clone $d;
                $enddate->modify("+{$diff} seconds");
                // all day event
                if ($res->startdate->format('His') == "000000" && $res->enddate->format('His') == "000000") {
                    $txt .= "DTSTART;VALUE=DATE:" . $d->format('Ymd') . NL;
                    $txt .= "DTEND;VALUE=DATE:" . date('Ymd', strtotime('+1 day', $enddate->format("U"))) . NL;
                } else {
                    $txt .= "DTSTART:" . $d->format('Ymd\\THis') . NL;
                    $txt .= "DTEND:" . $enddate->format('Ymd\\THis') . NL;
                }
                $txt .= 'DESCRIPTION:Kalender:' . $catNames[$res->category_id]->bezeichnung;
                if (!empty($res->notizen)) {
                    $txt .= ' - ' . cleanICal($res->notizen);
                }
                $txt .= NL;
                $txt .= "END:VEVENT" . NL;
            }
        }
    }
    echo surroundWithVCALENDER($txt);
}