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); }
/** * 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); }
public function getEvent($params) { $event = db_query("SELECT * FROM {cc_cal} WHERE id = :id", array(":id" => $params["id"]))->fetch(); if (!$event) { return null; } if (!churchcal_isAllowedToViewCategory($event->category_id)) { throw new CTNoPermission("view category", "churchcal"); } $dummy = churchcal_getCalPerCategory(array("category_ids" => array(0 => $event->category_id))); return $dummy[$event->category_id][$params["id"]]; }
function churchcal_saveSplittedEvent($params) { global $user; $res = new stdClass(); // if no splitDate given it is a new event without impact if (!isset($params["splitDate"])) { throw new CTException("saveSplittedEvent: splitDate not given!"); } $splitDate = new DateTime($params["splitDate"]); $untilEnd_yn = $params["untilEnd_yn"]; $pastEventId = $params["pastEvent"]["id"]; // Get originEvent out of Database $dummy = churchcal_getCalPerCategory(array("category_ids" => array(0 => $params["pastEvent"]["category_id"]))); $originEvent = (array) $dummy[$params["pastEvent"]["category_id"]][$params["newEvent"]["old_id"]]; // Copy all entries from past to new event, cause CR und CS does not have all infos and doesn't need it :) $pastEventDB = db_query("SELECT bezeichnung, ort, notizen, link, intern_yn, category_id " . "FROM {cc_cal} WHERE id = :id ", array(":id" => $pastEventId))->fetch(); if ($pastEventDB != false) { foreach ($pastEventDB as $key => $entry) { if (empty($params["pastEvent"][$key])) { $params["pastEvent"][$key] = $entry; } if (empty($params["newEvent"][$key])) { $params["newEvent"][$key] = $entry; } } } // Save new Event without impact on CS and CR ... $res = churchcal_createEvent($params["newEvent"], false, true); // ... and now bind related bookings and services to the new event $newEventId = $res["id"]; $params["newEvent"]["id"] = $newEventId; if (churchcore_isModuleActivated("churchservice")) { include_once './' . CHURCHSERVICE . '/churchservice_db.php'; churchservice_rebindServicesToNewEvent($pastEventId, $newEventId, $splitDate, $untilEnd_yn); $params["newEvent"]["cal_id"] = $newEventId; $startdate = new Datetime($params["newEvent"]["startdate"]); if ($splitDate->format("Y-m-d H:i") != $startdate->format("Y-m-d H:i")) { $params["newEvent"]["old_startdate"] = $splitDate; } churchservice_operateEventFromChurchCal($params["newEvent"]); } // Save old Event churchcal_updateEvent($params["pastEvent"], false, true); if (getVar("informCreator", "true", $params["newEvent"]) == "true" && $originEvent["modified_pid"] != $user->id) { $data = (array) churchcal_getEventChangeImpact(array("newEvent" => $params["newEvent"], "originEvent" => $originEvent, "pastEvent" => $params["pastEvent"])); $data["caption"] = $params["newEvent"]["bezeichnung"]; $data["startdate"] = churchcore_stringToDateDe($params["newEvent"]["startdate"]); $p = db_query("SELECT name, vorname, IF(spitzname, spitzname, vorname) AS nickname\n FROM {cdb_person}\n WHERE id=:id", array(":id" => $originEvent["modified_pid"]))->fetch(); $data["p"] = $p; // get populated template and send email $lang = getUserLanguage($params["modified_pid"]); $content = getTemplateContent('email/informCreator', 'churchcal', $data, null, $lang); churchcore_sendEMailToPersonIDs($originEvent["modified_pid"], "[" . getConf('site_name') . "] " . t2($lang, 'information.for.your.event'), $content, null, true); } return array("id" => $newEventId, "bookingIds" => $res["bookingIds"]); }