示例#1
0
/**
 * 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);
}
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);
}
/**
 * echo ical for services to do from user id (read from request)
 */
function churchservice_ical()
{
    global $base_url, $config;
    if (!($id = readVar("id"))) {
        echo t("please.specify.id");
    }
    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', false);
    $content = drupal_get_header();
    include_once './' . CHURCHSERVICE . '/churchservice_db.php';
    $arr = churchservice_getUserCurrentServices($id);
    // TODO: use txt Template
    $txt = "";
    foreach ($arr as $res) {
        $txt .= "BEGIN:VEVENT\r\n";
        $txt .= "ORGANIZER:MAILTO:" . readConf('site_mail', '') . "\r\n";
        if ($res->zugesagt_yn == 1) {
            $txt .= "SUMMARY:" . $res->dienst . " (" . $res->servicegroup . ")\r\n";
        } else {
            $txt .= "SUMMARY:Anfrage: " . $res->dienst . " (" . $res->servicegroup . ")?\r\n";
        }
        $txt .= "X-MICROSOFT-CDO-BUSYSTATUS:BUSY\r\n";
        $txt .= "URL:" . $base_url . "/?q=churchservice/entrylist\r\n";
        if ($res->ort != "") {
            $txt .= "LOCATION:" . $res->ort . "\r\n";
        }
        $txt .= "DESCRIPTION:" . $res->dienst . " (" . $res->servicegroup . ") bei " . $res->event . ".";
        if ($res->zugesagt_yn == 1) {
            $txt .= "\r\n";
        } else {
            $txt .= " " . t("request.from") . " {$res->vorname} {$res->name} [{$res->modified_pid}]\r\n";
        }
        $txt .= "DTSTAMP:" . $res->modified_date . "\r\n";
        $txt .= "UID:" . $res->eventservice_id . "\r\n";
        $txt .= "DTSTART;TZID=" . $config["timezone"] . ":" . $res->datum_start . "\r\n";
        $txt .= "DTEND;TZID=" . $config["timezone"] . ":" . $res->datum_end . "\r\n";
        $txt .= "END:VEVENT\r\n";
    }
    echo surroundWithVCALENDER($txt);
}