/** * delete cal event * @param array $params * @param string $source; default: null * @throws CTNoPermission */ function churchcal_deleteEvent($params, $source = null) { global $user; $id = $params["id"]; $logger = db_query("SELECT * FROM {cc_cal} WHERE id=:id", array(":id" => $params["id"]))->fetch(); if (!$logger) { return; } if (!churchcal_isAllowedToEditEvent($id)) { throw new CTNoPermission("AllowToEditEvent", "churchcal"); } // inform other modules if (!$source || $source != "churchresource") { include_once CHURCHRESOURCE . '/churchresource_db.php'; if (!$source) { $source = "churchcal"; } $params["cal_id"] = $params["id"]; churchresource_deleteResourcesFromChurchCal($params, $source); } if (!$source || $source != "churchservice") { include_once CHURCHSERVICE . '/churchservice_db.php'; $cs_params = array_merge(array(), $params); $cs_params["cal_id"] = $params["id"]; $cs_params["informDeleteEvent"] = 1; $cs_params["deleteCalEntry"] = 1; if (!$source) { $source = "churchcal"; } $db = db_query("SELECT * FROM {cs_event}\n WHERE cc_cal_id=:cal_id", array(":cal_id" => $cs_params["cal_id"])); foreach ($db as $cs) { $cs_params["id"] = $cs->id; churchservice_deleteEvent($cs_params, $source); } } db_query("DELETE FROM {cc_meetingrequest} WHERE cal_id=:id", array(":id" => $id)); db_query("DELETE FROM {cc_cal_except} WHERE cal_id=:id", array(":id" => $id)); db_query("DELETE FROM {cc_cal_add} WHERE cal_id=:id", array(":id" => $id)); db_query("DELETE FROM {cc_cal} WHERE id=:id", array(":id" => $id)); $data = db_query("select * from {cc_calcategory} where id=:id", array(":id" => $logger->category_id))->fetch(); $txt = $user->vorname . " " . $user->name . " hat in Kalender "; if ($data != false) { $txt .= $data->bezeichnung; } else { $txt .= $logger->category_id; } $txt .= " einen Termin gelöscht: <br>"; $txt .= churchcore_CCEventData2String($logger); ct_notify("category", $logger->category_id, $txt); }
/** * Store all Exception and Addition changes for communication to other modules * * @param array $params * @param string $sourc; controls cooperation between modules if event comes from another modulee * @param boolean $withoutPerm If permission will be checked. */ function churchcal_updateEvent($params, $callCS = true, $withoutPerm = false) { global $user, $base_url; $changes = array(); if (!$withoutPerm && !churchcal_isAllowedToEditCategory($params["category_id"])) { throw new CTNoPermission("AllowedToEditCategory[" . $params["category_id"] . "] (newCat)", "churchcal"); } $old_cal = db_query("SELECT *\n FROM {cc_cal}\n WHERE id=:id", array(":id" => $params["id"]))->fetch(); // can user edit old event category? if (!$withoutPerm && !churchcal_isAllowedToEditCategory($old_cal->category_id)) { throw new CTNoPermission("AllowedToEditCategory[" . $old_cal->category_id . "] (oldCat)", "churchcal"); } // When empty, load originEvent for later sending Change protocol $dummy = churchcal_getCalPerCategory(array("category_ids" => array(0 => $old_cal->category_id))); $originEvent = (array) $dummy[$old_cal->category_id][$params["id"]]; if (isset($params["notizen"])) { $params["notizen"] = str_replace('\\"', '"', $params["notizen"]); } $i = new CTInterface(); $i->setParam("startdate", false); $i->setParam("enddate", false); $i->setParam("bezeichnung", false); $i->setParam("category_id", false); $i->setParam("ort", false); $i->setParam("notizen", false); $i->setParam("intern_yn", false); $i->setParam("link", false); $i->setParam("repeat_id", false); $i->setParam("repeat_until", false); $i->setParam("repeat_frequence", false); $i->setParam("repeat_option_id", false); if (isset($params["modified_pid"])) { $i->setParam("modified_pid"); } // not with ", false" cause this cause an update $f = $i->getDBInsertArrayFromParams($params); if (count($f)) { db_update("cc_cal")->fields($f)->condition("id", $params["id"], "=")->execute(); } // get all exceptions for event $exc = churchcore_getTableData("cc_cal_except", null, "cal_id=" . $params["id"]); // look which are already in DB if (!empty($params["exceptions"])) { foreach ($params["exceptions"] as $exception) { if ($exception["id"] > 0) { $exc[$exception["id"]]->vorhanden = true; } else { $add_exc = array("cal_id" => $params["id"], "except_date_start" => $exception["except_date_start"], "except_date_end" => $exception["except_date_end"]); churchcal_addException($add_exc); $changes["add_exception"][] = $add_exc; } } } // delete removed exceptions from DB if ($exc) { foreach ($exc as $e) { if (!isset($e->vorhanden)) { $del_exc = array("id" => $e->id, "except_date_start" => $e->except_date_start, "except_date_end" => $e->except_date_end); churchcal_delException($del_exc); $changes["del_exception"][] = $del_exc; } } } // get all additions $add = churchcore_getTableData("cc_cal_add", null, "cal_id=" . $params["id"]); // look which are already in DB. if (!empty($params["additions"])) { foreach ($params["additions"] as $addition) { if ($addition["id"] > 0) { $add[$addition["id"]]->vorhanden = true; } else { $add_add = array("cal_id" => $params["id"], "add_date" => $addition["add_date"], "with_repeat_yn" => $addition["with_repeat_yn"]); churchcal_addAddition($add_add); $changes["add_addition"][] = $add_add; } } } // delete from DB which are deleted. if ($add) { foreach ($add as $a) { if (!isset($a->vorhanden)) { $del_add = array("id" => $a->id, "add_date" => $a->add_date); churchcal_delAddition($del_add); $changes["del_addition"][] = $del_add; } } } // meeting request if (isset($params["meetingRequest"])) { churchcal_handleMeetingRequest($params["id"], $params); } // Call other modules $newBookingIds = null; if (churchcore_isModuleActivated("churchresource")) { include_once CHURCHRESOURCE . '/churchresource_db.php'; $newBookingIds = churchresource_operateResourcesFromChurchCal($params); } $newCSIds = null; if ($callCS) { if (churchcore_isModuleActivated("churchservice")) { include_once CHURCHSERVICE . '/churchservice_db.php'; $newCSIds = churchservice_operateEventFromChurchCal($params); } } // Notification $data = db_query("select * from {cc_calcategory} where id=:id", array(":id" => $params["category_id"]))->fetch(); $txt = $user->vorname . " " . $user->name . " hat einen Termin angepasst im Kalender "; if ($data != false) { $txt .= $data->bezeichnung; } else { $txt .= $params["category_id"]; } $txt .= " auf:<br>"; $txt .= churchcore_CCEventData2String($params); ct_notify("category", $params["category_id"], $txt); // Inform creator when I am allowed and when it is not me! if ($callCS && getVar("informCreator", "true") == "true" && $originEvent["modified_pid"] != $user->id) { $data = (array) churchcal_getEventChangeImpact(array("newEvent" => $params, "originEvent" => $originEvent, "pastEvent" => null)); if (!empty($data["bookings"]) || !empty($data["cal"])) { $data["new"] = false; $data["caption"] = $params["bezeichnung"]; $data["startdate"] = churchcore_stringToDateDe($params["startdate"]); $data["eventUrl"] = $base_url . "?q=churchcal&category_id=" . $params["category_id"] . "&id=" . $params["id"]; $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("cseventIds" => $newCSIds, "bookingIds" => $newBookingIds); }
public function notify($domain_type, $domain_id, $txt, $loglevel = 2) { ct_notify($domain_type, $domain_id, $txt, $loglevel = 2); }
/** * update event service * * @param array $params * @throws CTNoPermission * @return array */ function churchservice_updateEventService($params) { global $user, $base_url; $id = $params["id"]; $name = isset($params["name"]) ? $params["name"] : null; $cdb_person_id = isset($params["cdb_person_id"]) ? $params["cdb_person_id"] : null; $reason = isset($params["reason"]) ? $params["reason"] : null; $zugesagt_yn = $params["zugesagt_yn"]; include_once CHURCHSERVICE . "/churchservice_db.php"; $res = array(); if ($name == "null") { $name = null; } if ($cdb_person_id == "null") { $cdb_person_id = null; } // look if event is still valid $arr = db_query("SELECT * FROM {cs_eventservice} WHERE id=:id", array(":id" => $id))->fetch(); if (!$arr) { return "Entry not found, id not valid!"; } if ($arr->valid_yn != 1 && !isset($params["valid_yn"])) { return "Eintrag konnte nicht angepasst werden, da veraltet. Bitte neu laden!"; } // check auth $auth = churchservice_getAuthorization(); // Es ist trotzdem erlaubt, wenn die PersonId eingetragen ist, dann wurde er ja angefragt if (!isset($auth["editservice"][$arr->service_id]) && !isset($auth["memberservice"][$arr->service_id]) && !churchService_adminOfEvent($arr->event_id) && $arr->cdb_person_id != $user->id) { throw new CTNoPermission("editservice", "churchservice"); } // Wenn die neue �nderung vom gleichen User kommt und noch kein Cron gelaufen ist, // Oder wenn valid_yn valide ist, denn dann soll es upgedates werden! // brauchen wir kein neuen Insert, sondern machen nur ein Update. // Denn wahrscheinlich war es vorher nur ein Versehen. // TODO: translation correct? // if changing user is the same as last time and cron had not yet run // or if valid_yn is valide (update wished), we dont need an insert, only an update, // because the last edit probably was a mistake $dt = new datetime(); if ($arr->modified_pid == $user->id && $arr->mailsenddate == null || isset($params["valid_yn"])) { $valid_yn = 1; if (isset($params["valid_yn"])) { $valid_yn = $params["valid_yn"]; } db_update("cs_eventservice")->fields(array("name" => $name, "cdb_person_id" => $cdb_person_id, "valid_yn" => $valid_yn, "zugesagt_yn" => $zugesagt_yn, "reason" => $reason, "mailsenddate" => null, "modified_date" => $dt->format('Y-m-d H:i:s'), "modified_pid" => $user->id))->condition("id", $id, "=")->execute(); $new_id = $id; } else { // new entry for edit $new_id = db_insert("cs_eventservice")->fields(array("event_id" => $arr->event_id, "service_id" => $arr->service_id, "valid_yn" => 1, "counter" => $arr->counter, "name" => $name, "cdb_person_id" => $cdb_person_id, "zugesagt_yn" => $zugesagt_yn, "reason" => $reason, "modified_date" => $dt->format('Y-m-d H:i:s'), "modified_pid" => $user->id))->execute(); //if all ok set existing entry to old db_update("cs_eventservice")->fields(array("valid_yn" => 0))->condition("id", $id, "=")->execute(); } include_once CHURCHCORE . "/churchcore_db.php"; $leader = churchcore_getPersonById($arr->modified_pid); $event = db_query("SELECT e.startdate datum, c.bezeichnung FROM {cs_event} e, {cc_cal} c\n WHERE e.cc_cal_id=c.id and e.id=:event_id", array(":event_id" => $arr->event_id))->fetch(); $service = churchcore_getTableData("cs_service", "", "id=" . $arr->service_id); if ($event && $service) { $service = $service[$arr->service_id]; $subject = "[" . readConf('site_name', "ChurchTools") . "] "; $txt = ""; // confirm if ($zugesagt_yn == 1) { $txt .= t("surname.name.has.approved.name.for.service.x.for.date.event", $user->vorname, $user->name, $service->bezeichnung, $event->datum, $event->bezeichnung, $name); $subject .= t("surname.name.has.approved.a.request", $user->vorname, $user->name); } else { if ($name) { $txt .= t("surname.name.has.proposed.name.for.service.x.for.date.event", $user->vorname, $user->name, $service->bezeichnung, $event->datum, $event->bezeichnung, $name); $subject .= t("surname.name.has.proposed.someone", $user->vorname, $user->name); } else { $txt .= t("surname.name.has.canceled.the.service.x.for.date.event", $user->vorname, $user->name, $service->bezeichnung, $event->datum, $event->bezeichnung); $subject .= t("surname.name.has.canceled.a.request", $user->vorname, $user->name); } } if ($reason != null) { $txt .= "<p>Folgendes wurde als Grund angegeben: " . $reason; } ct_notify("service", $arr->service_id, $txt); if ($leader != null) { // send mail, if someone other then the inquirer himself confirmed or canceled //TODO: maybe use asker, better to understand for nonenglish programmers //TODO: use email template if (!empty($leader->email) && $user != null && $leader->id != $user->id) { $setting = churchcore_getUserSettings("churchservice", $leader->id); if (isset($setting["informInquirer"]) && $setting["informInquirer"] == 1) { $txt = "<h3>Hallo " . $leader->vorname . ",</h3><p>\n " . $txt; $txt .= '<p><a href="' . $base_url . '?q=churchservice&id=' . $arr->event_id . '" class="btn btn-primary">Event aufrufen</a>'; churchservice_send_mail($subject, $txt, $leader->email); } } if (!isset($setting["informInquirer"])) { churchcore_saveUserSetting("churchservice", $leader->id, "informInquirer", 0); } } } $arr = db_query("SELECT es.*, concat(p.vorname,' ',p.name) as modifieduser FROM {cs_eventservice} es, {cdb_person} p \n WHERE p.id=es.modified_pid and es.id=:id", array(":id" => $new_id))->fetch(); $res["eventservice"] = churchservice_extractEventServiceData($arr); $res["result"] = true; return $res; }