public function getMasterData() { global $user, $base_url; $ret = array(); $ret["modulename"] = "churchcal"; $ret["modulespath"] = CHURCHCAL; $ret["churchservice_name"] = variable_get("churchservice_name"); $ret["churchcal_name"] = variable_get("churchcal_name"); $ret["churchresource_name"] = variable_get("churchresource_name"); $ret["maincal_name"] = variable_get("churchcal_maincalname", "Gemeindekalender"); $ret["base_url"] = $base_url; $ret["user_pid"] = $user->id; if (user_access("view", "churchdb")) { $ret["absent_reason"] = churchcore_getTableData("cs_absent_reason"); } if (user_access("view", "churchresource") || user_access("create bookings", "churchresource")) { $ret["resources"] = churchcore_getTableData("cr_resource"); $ret["resourceTypes"] = churchcore_getTableData("cr_resourcetype"); $ret["bookingStatus"] = churchcore_getTableData("cr_status"); } $ret["category"] = churchcal_getAllowedCategories(true); $ret["settings"] = churchcore_getUserSettings("churchcal", $user->id); $ret["repeat"] = churchcore_getTableData("cc_repeat"); if (count($ret["settings"]) == 0) { $arr["checkboxEvents"] = "true"; $ret["settings"] = $arr; } $ret["auth"] = churchcal_getAuthForAjax(); return $ret; }
/** * get getMasterData */ public function getMasterData() { global $user, $base_url; $ret = array(); $ret["modulename"] = "churchcal"; $ret["modulespath"] = CHURCHCAL; $ret["churchservice_name"] = getConf("churchservice_name"); $ret["churchcal_name"] = getConf("churchcal_name"); $ret["churchresource_name"] = getConf("churchresource_name"); $ret["maincal_name"] = getConf("churchcal_maincalname", "Gemeindekalender"); $ret["firstDayInWeek"] = getConf("churchcal_firstdayinweek", 1); $ret["notification"] = churchcore_getMyNotifications(); $ret["notificationtype"] = churchcore_getTableData("cc_notificationtype"); $ret["reminder"] = ct_getMyReminders($user->id, "event"); $ret["base_url"] = $base_url; $ret["user_pid"] = $user->id; if (user_access("view", "churchdb")) { $ret["cdb_bereich"] = churchcore_getTableData("cdb_bereich"); $ret["cdb_status"] = churchcore_getTableData("cdb_status"); $ret["cdb_station"] = churchcore_getTableData("cdb_station"); $ret["absent_reason"] = churchcore_getTableData("cs_absent_reason"); foreach ($ret["absent_reason"] as $key => $reason) { if (isset($reason->color)) { $ret["absent_reason"][$key]->textColor = getContrastYIQ($reason->color); } } } if (user_access("view", "churchresource") || user_access("create bookings", "churchresource")) { $ret["resources"] = churchcore_getTableData("cr_resource"); $ret["resourceTypes"] = churchcore_getTableData("cr_resourcetype"); $ret["bookingStatus"] = churchcore_getTableData("cr_status"); } $ret["category"] = churchcal_getAllowedCategories(true); $ret["settings"] = churchcore_getUserSettings("churchcal", $user->id); $ret["repeat"] = churchcore_getTableData("cc_repeat"); if (count($ret["settings"]) == 0) { $arr["checkboxEvents"] = "true"; $ret["settings"] = $arr; } $ret["auth"] = churchcal_getAuthForAjax(); $ret["views"] = array("WeekView" => array("filename" => "../churchresource/cr_weekview")); return $ret; }
public function getSettings() { global $user; return churchcore_getUserSettings($this->modulename, $user->id); }
/** * inform leader about open event services * TODO: no idea if this could be improved - lots of sql requests and loops * @return boolean */ function churchservice_inform_leader() { global $base_url; include_once "churchservice_db.php"; // get all group ids from services $res = db_query("SELECT cdb_gruppen_ids FROM {cs_service}\n WHERE cdb_gruppen_ids!='' AND cdb_gruppen_ids IS NOT NULL"); // TODO: use WHERE cdb_gruppen_ids > '' ? // WHERE cdb_gruppen_ids>''); // TODO: works too $arr = array(); foreach ($res as $g) { $arr[] = $g->cdb_gruppen_ids; } if (!count($arr)) { return false; } // get persons being (co)leader of one of this service groups $res = db_query("SELECT p.id AS person_id, gpg.gruppe_id, p.email, p.vorname, p.name, p.spitzname, p.cmsuserid\n FROM {cdb_person} p, {cdb_gemeindeperson_gruppe} gpg, {cdb_gemeindeperson} gp\n WHERE gpg.gemeindeperson_id = gp.id AND p.id = gp.person_id AND status_no >= 1 AND status_no <= 2\n AND gpg.gruppe_id IN (" . db_implode($arr) . ")"); // Aggregiere nach Person_Id P1[G1,G2,G3],P2[G3] $persons = array(); foreach ($res as $p) { $data = churchcore_getUserSettings("churchservice", $p->person_id); // if person has rights and has not deselected info emails $auth = getUserAuthorization($p->person_id); if (isset($auth["churchservice"]["view"]) && (!isset($data["informLeader"]) || $data["informLeader"])) { if (!isset($data["informLeader"])) { $data["informLeader"] = 1; churchcore_saveUserSetting("churchservice", $p->person_id, "informLeader", "1"); } if (empty($persons[$p->person_id])) { $persons[$p->person_id] = array("group" => array(), "service" => array(), "person" => $p); } $persons[$p->person_id]["group"][] = $p->gruppe_id; } } // who should get an email? foreach ($persons as $person_id => $p) { if (!ct_checkUserMail($person_id, "informLeaderService", -1, 6 * 24)) { $persons[$person_id] = null; // unset($persons[$person_id])? } } // get matching services // TODO: nearly the same request as above (additonal bezeichnung, id service_id) $res = db_query("SELECT cdb_gruppen_ids, bezeichnung, id AS service_id\n FROM {cs_service}\n WHERE cdb_gruppen_ids is not null"); foreach ($res as $d) { $group_ids = explode(",", $d->cdb_gruppen_ids); foreach ($persons as $key => $person) { if ($person) { foreach ($person["group"] as $person_group) { if (in_array($person_group, $group_ids)) { $persons[$key]["service"][] = $d->service_id; } } } } } // get events for each person // TODO: add DAYS_TO_INFORM_LEADER_ABOUT_OPEN_SERVICES to $conf? foreach ($persons as $person_id => $person) { if ($person) { $res = db_query("SELECT es.id, c.bezeichnung AS event,\n DATE_FORMAT(e.startdate, '%d.%m.%Y %H:%i') AS datum, es.name, s.bezeichnung AS service\n FROM {cs_event} e, {cs_eventservice} es, {cs_service} s, {cc_cal} c\n WHERE e.valid_yn=1 AND c.id=e.cc_cal_id AND es.service_id in (" . db_implode($person["service"]) . ")\n AND es.event_id = e.id AND es.service_id = s.id AND es.valid_yn = 1 AND zugesagt_yn = 0\n AND e.startdate > current_date AND DATEDIFF(e.startdate,CURRENT_DATE) <= " . DAYS_TO_INFORM_LEADER_ABOUT_OPEN_SERVICES . "\n ORDER BY e.startdate"); $openServices = array(); foreach ($res as $s) { $openServices[] = $s; } if (count($openServices)) { $data = array('moreInfoUrl' => "{$base_url}?q=churchservice", 'settingsUrl' => "{$base_url}?q=churchservice#SettingsView", 'openServices' => $openServices, 'surname' => $person["person"]->vorname, 'nickname' => $person["person"]->spitzname ? $person["person"]->spitzname : $person["person"]->vorname, 'name' => $person["person"]->name); $lang = getUserLanguage($person["person"]->person_id); $content = getTemplateContent('email/openServicesLeaderInfo', 'churchservice', $data, null, $lang); churchservice_send_mail("[" . getConf('site_name') . "] " . t2($lang, 'open.services'), $content, $person["person"]->email); } } } }
function _getExportTemplateByName($templatename = null) { global $user; if ($templatename == null) { return null; } $settings = churchcore_getUserSettings("churchdb", $user->id); if (!isset($settings["exportTemplate"][$templatename])) { throw new Exception("Template '" . $templatename . "' not found!"); } return $settings["exportTemplate"][$templatename]; }
/** * get user settings for churchDB * * @param int $user_pid * @return array */ function churchdb_getUserSettings($user_pid) { $arr = churchcore_getUserSettings("churchdb", $user_pid); if (empty($arr["mailerType"])) { $arr["mailerType"] = 0; } if (empty($arr["mailerSeparator"])) { if (readConf('churchdb_emailseparator', ';') == ';') { $arr["mailerSeparator"] = 0; } else { $arr["mailerSeparator"] = 1; } } return $arr; }
/** * * @param string $templatename * @throws Exception * @return NULL */ function _getExportTemplateByName($templatename = null) { global $user; if (!$templatename) { return null; } $settings = churchcore_getUserSettings("churchdb", $user->id); if (!isset($settings["exportTemplate"][$templatename])) { throw new Exception(t('template.x.not.found', $templatename)); } return $settings["exportTemplate"][$templatename]; }
/** * get user settings and set remindMe to on if not yet * * @param int $user_pid * @return array with settings */ function churchservice_getUserSettings($user_pid) { $arr = churchcore_getUserSettings("churchservice", $user_pid); $arr2 = churchcore_getUserSettings("churchdb", $user_pid); if (!isset($arr["remindMe"])) { $arr["remindMe"] = "1"; churchcore_saveUserSetting("churchservice", $user_pid, "remindMe", "1"); } if (isset($arr2["signature"])) { $arr["signature"] = $arr2["signature"]; } return $arr; }
function churchservice_inform_leader() { global $base_url; include_once "churchservice_db.php"; // Hole erst mal die Gruppen_Ids, damit ich gleich nicht alle Personen holen mu� $res = db_query("SELECT cdb_gruppen_ids FROM {cs_service} where cdb_gruppen_ids!='' and cdb_gruppen_ids is not null"); $arr = array(); foreach ($res as $g) { $arr[] = $g->cdb_gruppen_ids; } if (count($arr) == 0) { return false; } // Hole nun die Person/Gruppen wo die Person Leiter oder Co-Leiter ist $res = db_query("SELECT p.id person_id, gpg.gruppe_id, p.email, p.vorname, p.cmsuserid FROM {cdb_person} p, {cdb_gemeindeperson_gruppe} gpg, {cdb_gemeindeperson} gp\n where gpg.gemeindeperson_id=gp.id and p.id=gp.person_id and status_no>=1 and status_no<=2\n and gpg.gruppe_id in (" . implode(",", $arr) . ")"); // Aggregiere nach Person_Id P1[G1,G2,G3],P2[G3] $persons = array(); foreach ($res as $p) { $data = churchcore_getUserSettings("churchservice", $p->person_id); // Darf er �berhaupt noch, und wenn ja dann schaue ob der Leiter es will. // (Wenn noch nicht best�tigt, dann wird davon ausgegangen $auth = getUserAuthorization($p->person_id); if (isset($auth["churchservice"]["view"]) && (!isset($data["informLeader"]) || $data["informLeader"] == 1)) { if (!isset($data["informLeader"])) { $data["informLeader"] = 1; churchcore_saveUserSetting("churchservice", $p->person_id, "informLeader", "1"); } if (isset($persons[$p->person_id])) { $arr = $persons[$p->person_id]["group"]; } else { $persons[$p->person_id] = array(); $arr = array(); $persons[$p->person_id]["service"] = array(); $persons[$p->person_id]["person"] = $p; } $arr[] = $p->gruppe_id; $persons[$p->person_id]["group"] = $arr; } } // Gehe nun die Personen durch und schaue wer seit einer Zeit keine Mail mehr bekommen hatte. foreach ($persons as $person_id => $p) { if (!churchcore_checkUserMail($person_id, "informLeaderService", -1, 6 * 24)) { $persons[$person_id] = null; } } // Suche nun dazu die passenden Services $res = db_query("SELECT cdb_gruppen_ids, bezeichnung, id service_id FROM {cs_service} where cdb_gruppen_ids is not null"); foreach ($res as $d) { $gruppen_ids = explode(",", $d->cdb_gruppen_ids); foreach ($persons as $key => $person) { if ($person != null) { foreach ($person["group"] as $person_group) { if (in_array($person_group, $gruppen_ids)) { $persons[$key]["service"][] = $d->service_id; } } } } } // Gehe nun die Personen durch und suche nach Events foreach ($persons as $person_id => $person) { if ($person != null) { $res = db_query("SELECT es.id, c.bezeichnung event, DATE_FORMAT(e.startdate, '%d.%m.%Y %H:%i') datum, es.name, s.bezeichnung service \n FROM {cs_event} e, {cs_eventservice} es, {cs_service} s, {cc_cal} c \n where e.valid_yn=1 and c.id=e.cc_cal_id and es.service_id in (" . implode(",", $person["service"]) . ")\n and es.event_id=e.id and es.service_id=s.id and es.valid_yn=1 and zugesagt_yn=0\n and e.startdate>current_date and datediff(e.startdate,CURRENT_DATE)<=60 order by e.startdate"); $txt = ''; foreach ($res as $es) { $txt .= "<li>" . $es->datum . " " . $es->event . " - Dienst " . $es->service . ": "; $txt .= '<font style="color:red">'; if ($es->name == null) { $txt .= "?"; } else { $txt .= $es->name . "?"; } $txt .= '</font>'; } if ($txt != '') { $txt = "<h3>Hallo " . $person["person"]->vorname . "!</h3><p>Es sind in den nächsten 60 Tagen noch folgende Dienste offen:<ul>" . $txt . "</ul>"; $txt .= '<p><a href="' . $base_url . '/?q=churchservice" class="btn">' . t("more.information") . '</a> '; $txt .= '<p><a href="' . $base_url . '/?q=churchservice#SettingsView" class="btn">Benachrichtigung deaktivieren</a>'; churchservice_send_mail("[" . readConf('site_name', 'ChurchTools') . "] Offene Dienste", $txt, $person["person"]->email); } } } }