function partChoose() { $q_exam = "SELECT \n\t\t\texam.id AS exam,exam.name AS name,exam_paper.id AS exam_paper,exam_paper.is_extra_course AS is_extra_course,\n\t\t\tgrade.name AS grade_name,course.id AS course,course.name AS course_name,\n\t\t\texam_paper.students AS students, exam_paper.teacher_group AS teacher_group \n\t\tFROM \n\t\t\t(\n\t\t\t\t(\n\t\t\t\t\texam_paper LEFT JOIN exam ON (exam_paper.exam=exam.id)\n\t\t\t\t)\n\t\t\t\tLEFT JOIN course ON exam_paper.course=course.id\n\t\t\t)\n\t\t\tLEFT JOIN grade ON exam.grade=grade.id\n\t\tWHERE exam_paper.is_scoring=1\n\t\t\tAND (" . db_implode($_SESSION['teacher_group'], ' OR ', 'teacher_group') . ')'; $examArray = db_toArray($q_exam); if ($this->input->get('exam_paper')) { foreach ($examArray as $exam) { if ($exam['exam_paper'] == $this->input->get('exam_paper')) { $currentExam = $exam; } } } elseif (count($examArray) > 0) { $currentExam = $examArray[0]; } else { $currentExam = false; } $this->load->addViewData('currentExam', $currentExam); $q_partArray = "\n\t\t\tSELECT * FROM exam_part WHERE exam_paper='" . $currentExam['exam_paper'] . "'\n\t\t"; $partArray = db_toArray($q_partArray); $this->load->addViewData('partArray', $partArray); $q_students_left = "\n\t\t\tSELECT *\n\t\t\t\tFROM score\n\t\t\tWHERE score.exam_paper='" . $currentExam['exam_paper'] . "'\n\t\t\tGROUP BY student\n\t\t"; $r_students_left = mysql_query($q_students_left); $student_left = $currentExam['students']; $this->load->addViewData('student_left', $student_left); }
/** * Load agendas with ids including related Event_ids but without items * Check if it's allowed to view or if user is involved in one of the events * * @param array $params; [ids] for ids to get * @return agenda oder null if not found or not allowed */ public function loadAgendas($params) { $where = "id IN (" . db_implode($params["ids"]) . ")"; $data = churchcore_getTableData("cs_agenda", null, $where); $auth = churchservice_getAuthorization(); $allowedAgendas = array(); if (isset($auth["view agenda"])) { $allowedAgendas = $auth["view agenda"]; } if (!$data) { return null; } else { foreach ($data as $key => $d) { // Check if template $d->event_ids = $this->getBelongingEventIdsToAgenda($d->id); // Check if allowed if (!isset($allowedAgendas[$d->calcategory_id])) { // if not allowed, checked if I am involved in services of belonging events $involved = false; foreach ($d->event_ids as $event_id) { if (!$involved) { $involved = $this->isUserInvolved($event_id); } } if (!$involved) { unset($data[$key]); } } } return $data; } }
/** * get resources with booking dates * @param array $params * @return array resources */ function churchcal_getResource($params) { $resource_ids = $params["resource_id"]; $res = db_query("\n SELECT r.id resource_id, r.bezeichnung ort, s.bezeichnung status, b.status_id, b.id, b.startdate, b.enddate,\n b.repeat_id, b.repeat_frequence, b.repeat_until, b.repeat_option_id, b.text bezeichnung\n FROM {cr_resource} r, {cr_booking} b, {cr_status} s\n WHERE b.status_id!=99 AND s.id=b.status_id AND b.resource_id=r.id AND r.id IN (" . db_implode($resource_ids) . ")"); $excs = churchcore_getTableData("cr_exception", "except_date_start"); $adds = churchcore_getTableData("cr_addition", "add_date"); $arrs = array(); foreach ($res as $a) { if ($excs) { foreach ($excs as $exc) { if ($a->id == $exc->booking_id) { $a->exceptions[$exc->id] = $exc; } } } if ($adds) { foreach ($adds as $add) { if ($a->id == $add->booking_id) { $a->additions[$add->id] = $add; } } } $arrs[] = $a; } $ret = array(); foreach ($resource_ids as $id) { $ret[$id] = array(); foreach ($arrs as $d) { if ($d->resource_id == $id) { $ret[$id][$d->id] = $d; } } } return $ret; }
/** * 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); } } } }
/** * send sms * TODO: use sms template * * @param string $ids, comma separated * @param string $txt * @return array */ function churchdb_sendsms($ids, $txt) { global $user; $param = array(); // get cell phone number of user as sender from DB - maybe session contains an outdated one. $mobile = db_query("SELECT telefonhandy FROM {cdb_person}\n WHERE id=:id", array(":id" => $user->id))->fetch(); if (!empty($mobile->telefonhandy)) { $param["from"] = preg_replace('![^0-9]!', '', $mobile->telefonhandy); } else { $param["from"] = "ChurchTools"; } $db = db_query("SELECT id, telefonhandy, vorname, name, IF(spitzname != '', spitzname, vorname) AS spitzname\n FROM {cdb_person}\n WHERE id IN (" . db_implode($ids) . ")"); $res = array(); $res["withoutmobilecount"] = 0; $res["smscount"] = 0; foreach ($db as $p) { if (!$p->telefonhandy) { $res["withoutmobilecount"]++; $res[$p->id] = t("no.sms.sent.person.has.no.mobile.number"); } else { $param["to"] = $p->telefonhandy; $param["message"] = churchcore_personalizeTemplate($txt, $p); $res[$p->id] = churchdb_smspromote($param); $res["smscount"]++; } } return $res; }
/** * 根据post提交的数组,将日志标记为已审核,审核时间为自报时间 */ function review($post) { $post = array_trim($post); if ($post) { $condition = db_implode($post, $glue = ' OR ', 'id', ' = ', "'", "'", '`', 'key'); $this->db->query("UPDATE schedule SET `hours_checked` = `hours_own` WHERE " . $condition); return true; } }
/** * * @param unknown $params * @param string $withIntern * @return multitype:|Ambigous <multitype:multitype: , NULL, object, boolean, db_accessor> */ function churchcal_getCalPerCategory($params, $withIntern = null) { global $user; if ($withIntern == null) { $withIntern = $user == null || $user->id == -1 ? false : true; } $data = array(); $from = getConf("churchcal_entries_last_days", 180); $res = db_query("\n SELECT cal.*, CONCAT(p.vorname, ' ',p.name) AS modified_name, e.id AS event_id, e.startdate AS event_startdate,\n e.created_by_template_id AS event_template_id, b.id AS booking_id, b.startdate AS booking_startdate, b.enddate AS booking_enddate,\n b.resource_id AS booking_resource_id, b.status_id AS booking_status_id, b.location AS booking_location,\n b.note AS booking_note\n FROM {cc_cal} cal\n LEFT JOIN {cs_event} e ON (cal.id=e.cc_cal_id)\n LEFT JOIN {cr_booking} b ON (cal.id=b.cc_cal_id)\n LEFT JOIN {cdb_person} p ON (cal.modified_pid=p.id)\n WHERE cal.category_id IN (" . db_implode($params["category_ids"]) . ") " . (!$withIntern ? " and intern_yn=0" : "") . " AND( ( DATEDIFF ( cal.enddate , NOW() ) > - {$from} )\n OR ( cal.repeat_id>0 AND DATEDIFF (cal.repeat_until, NOW() ) > - {$from}) )\n "); $data = null; // collect bookings/events if more then one per calendar entry foreach ($res as $arr) { if (isset($data[$arr->id])) { $elem = $data[$arr->id]; } else { $elem = $arr; $req = churchcore_getTableData("cc_meetingrequest", null, "cal_id=" . $arr->id); if ($req) { $elem->meetingRequest = array(); foreach ($req as $r) { $elem->meetingRequest[$r->person_id] = $r; } } } if ($arr->booking_id) { $elem->bookings[$arr->booking_id] = array("id" => $arr->booking_id, "minpre" => (strtotime($arr->startdate) - strtotime($arr->booking_startdate)) / 60, "minpost" => (strtotime($arr->booking_enddate) - strtotime($arr->enddate)) / 60, "resource_id" => $arr->booking_resource_id, "status_id" => $arr->booking_status_id, "location" => $arr->booking_location, "note" => $arr->booking_note); unset($arr->booking_id); unset($arr->booking_startdate); unset($arr->booking_enddate); unset($arr->booking_resource_id); unset($arr->booking_status_id); unset($arr->booking_location); unset($arr->booking_note); } if ($arr->event_id) { // Get additional Service text infos, like "Preaching with [Vorname]" $service_texts = array(); $es = db_query("\n SELECT es.name, s.id, es.cdb_person_id, s.cal_text_template from {cs_service} s, {cs_eventservice} es\n WHERE es.event_id=:event_id AND es.service_id=s.id and es.valid_yn=1 and es.zugesagt_yn=1\n AND s.cal_text_template IS NOT NULL AND s.cal_text_template!=''", array(":event_id" => $arr->event_id)); foreach ($es as $e) { if ($e) { $txt = false; if (strpos($e->cal_text_template, "[") === false) { $txt = $e->cal_text_template; } $p = null; // First use person_id if ($e->cdb_person_id) { $p = db_query("SELECT * FROM {cdb_person}\n WHERE id=:id", array(":id" => $e->cdb_person_id))->fetch(); } // When not available use name if (!$p && $e->name) { $p = new stdClass(); $p->name = $e->name; } if ($p) { $txt = churchcore_personalizeTemplate($e->cal_text_template, $p); } if (!in_array($txt, $service_texts)) { $service_texts[] = $txt; } } } // Save event info $elem->csevents[$arr->event_id] = array("id" => $arr->event_id, "startdate" => $arr->event_startdate, "service_texts" => $service_texts, "eventTemplate" => $arr->event_template_id); } $data[$arr->id] = $elem; } $exceptions = churchcore_getTableData("cc_cal_except"); if ($exceptions) { foreach ($exceptions as $e) { // there may be exceptions without event if (isset($data[$e->cal_id])) { if (!isset($data[$e->cal_id]->exceptions)) { $data[$e->cal_id]->exceptions = array(); } $data[$e->cal_id]->exceptions[$e->id] = new stdClass(); $data[$e->cal_id]->exceptions[$e->id]->id = $e->id; $data[$e->cal_id]->exceptions[$e->id]->except_date_start = $e->except_date_start; $data[$e->cal_id]->exceptions[$e->id]->except_date_end = $e->except_date_end; } } } $additions = churchcore_getTableData("cc_cal_add"); if ($additions) { foreach ($additions as $e) { // there may be additions without event if (isset($data[$e->cal_id])) { if (!isset($data[$e->cal_id]->additions)) { $data[$e->cal_id]->additions = array(); } $data[$e->cal_id]->additions[$e->id] = new stdClass(); $data[$e->cal_id]->additions[$e->id]->id = $e->id; $data[$e->cal_id]->additions[$e->id]->add_date = $e->add_date; $data[$e->cal_id]->additions[$e->id]->with_repeat_yn = $e->with_repeat_yn; } } } $ret = array(); foreach ($params["category_ids"] as $cat) { $ret[$cat] = array(); if ($data) { foreach ($data as $d) { if ($d->category_id == $cat) { $ret[$cat][$d->id] = $d; } } } } return $ret; }
/** * TODO: churchdb_getTodos is not tested (where?) * explain, when gpg.status_no < -1 / replace status_nos by speaking constants * @return string */ function churchdb_getTodos() { global $user; $mygroups = churchdb_getMyGroups($user->id, true, true, false); $mysupergroups = churchdb_getMyGroups($user->id, true, true, true); if (!$mygroups) { return ""; } if (!$mysupergroups) { $mysupergroups = array(-1); } $groups = db_query("\n SELECT p.id, p.vorname, p.name, g.bezeichnung, gpg.status_no, s.bezeichnung AS status\n FROM {cdb_person} p, {cdb_gruppe} g, {cdb_gemeindeperson} gp, {cdb_gemeindeperson_gruppe} gpg, {cdb_gruppenteilnehmerstatus} s\n WHERE s.intern_code=gpg.status_no AND gpg.gemeindeperson_id=gp.id AND gp.person_id=p.id AND gpg.gruppe_id=g.id\n AND ((gpg.gruppe_id IN (" . db_implode($mygroups) . ") AND gpg.status_no<-1)\n OR (gpg.gruppe_id IN (" . db_implode($mysupergroups) . ") AND gpg.status_no=-1))\n ORDER BY status"); if (!$groups) { return ""; } $arr = array(); foreach ($groups as $g) { if (!isset($arr[$g->status_no])) { $arr[$g->status_no] = (object) array(); } if (!isset($arr[$g->status_no]->content)) { $arr[$g->status_no]->content = array(); } // TODO is this the same as the 2 lines above? // if (!isset($arr[$g->status_no])) $arr[$g->status_no] = (object) array ('content' => array()); $arr[$g->status_no]->content[] = $g; $arr[$g->status_no]->status_no = $g->status_no; $arr[$g->status_no]->status = $g->status; } $txt = ""; $entries = ""; $status = ""; $count = 0; foreach ($arr as $status) { $txt .= "<li><p>{$status->status} <label class='pull-right badge badge-" . ($status->status_no == -1 ? "important" : "info") . "'>" . count($status->content) . "</label>"; foreach ($status->content as $g) { $txt .= "<br/><small><a href='?q=churchdb#PersonView/searchEntry:#{$g->id}'>{$g->vorname} {$g->name}</a> - {$g->bezeichnung}</small>"; } } if ($txt != "") { $txt = '<ul>' . $txt . '</ul>'; } return $txt; }
/** * Load all Events and services in the current time slot * * @param array $params * @return array */ function churchservice_getAllEventData($params) { global $user; $id = null; if (isset($params["id"])) { $id = $params["id"]; } $auth = churchservice_getAuthorization(); include_once CHURCHCAL . '/churchcal_db.php'; $cat = churchcal_getAllowedCategories(false, true); $cat[] = -1; $lastday = -getConf('churchservice_entries_last_days'); $excs_db = db_query("SELECT id, cal_id, except_date_start, except_date_end FROM {cc_cal_except}"); $excs = array(); foreach ($excs_db as $exc) { if (!isset($excs[$exc->cal_id])) { $excs[$exc->cal_id] = array(); } $excs[$exc->cal_id][] = $exc; } $res = db_query('SELECT e.id, e.startdate startdate, e.valid_yn, cal.startdate cal_startdate, cal.enddate cal_enddate, e.cc_cal_id, cal.bezeichnung, e.special, cal.category_id, e.admin, cal.repeat_id, cal.repeat_until, cal.repeat_frequence, cal.repeat_option_id, cal.intern_yn, cal.notizen, cal.ort, cal.link, datediff(e.startdate,CURRENT_DATE) datediff FROM {cs_event} e, {cc_cal} cal WHERE cal.id=e.cc_cal_id AND ' . ($id != null ? "e.id={$id}" : "1=1") . " AND cal.category_id in (" . db_implode($cat) . ")" . " AND DATEDIFF(now(), e.startdate)<366*2"); $events = array(); if ($res != false) { foreach ($res as $arr) { if ($arr->repeat_frequence == null) { unset($arr->repeat_frequence); } if ($arr->repeat_option_id == null) { unset($arr->repeat_option_id); } if ($arr->repeat_until == null) { unset($arr->repeat_until); } if (isset($excs[$arr->cc_cal_id])) { $arr->exceptions = $excs[$arr->cc_cal_id]; } // here we go! $events[$arr->id] = $arr; $event_admin = false; if ($arr->admin == null) { unset($events[$arr->id]->admin); } else { if (in_array($user->id, explode(",", $arr->admin))) { $event_admin = true; } } if ($arr->special == null) { $events[$arr->id]->special = null; } // We don't have an enddate in cs-event, so we calculate it from the calendar $diff = strtotime($arr->cal_enddate) - strtotime($arr->cal_startdate); $event_enddate = new DateTime($arr->startdate); $event_enddate->modify("+" . $diff . " seconds"); $arr->enddate = $event_enddate->format('Y-m-d H:i:s'); if (1 == 1 && $arr->datediff > $lastday) { ///TODO: remove 1 == 1 // Check if agenda items are available for this event $b = db_query("SELECT * FROM {cs_event_item}\n WHERE event_id=:event_id limit 1", array(":event_id" => $arr->id))->fetch(); $arr->agenda = $b != false; $services = db_query("\n SELECT es.service_id, es.name, es.cdb_person_id, es.id eventservice_id, es.counter,\n es.zugesagt_yn, es.valid_yn, es.modified_date, es.modified_pid, es.mailsenddate,\n case when p.id is null then '?' else\n concat(p.vorname, ' ',p.name) end as modifieduser,\n es.reason, s.servicegroup_id, cmsuser.cmsuserid\n FROM {cs_service} s, {cs_eventservice} es left join {cdb_person} p on (es.modified_pid=p.id)\n LEFT JOIN {cdb_person} cmsuser on (es.cdb_person_id=cmsuser.id)\n WHERE es.service_id=s.id and event_id=:event_id", array(":event_id" => $arr->id)); $s = array(); foreach ($services as $service) { if ($service->servicegroup_id != null && (isset($auth["viewgroup"][$service->servicegroup_id]) || $event_admin)) { $s[] = churchservice_extractEventServiceData($service, $auth, $event_admin); } } if (count($s) > 0) { $events[$arr->id]->services = $s; } } } } return $events; }
/** * get ids of all persons in groups $myGroups * * @param array $myGroups, f.e. from churchdb_getMyGroups() * * @return array with person ids of persons in $myGroups */ function churchdb_getAllPeopleIdsFromGroups($myGroups) { $allPersons = null; if (count($myGroups)) { $res = db_query("SELECT p.id AS p_id\n FROM {cdb_person} p, {cdb_gemeindeperson} gp, {cdb_gemeindeperson_gruppe} gpg\n WHERE p.id=gp.person_id AND gpg.gemeindeperson_id=gp.id\n AND p.archiv_yn = 0\n AND gpg.gruppe_id IN (" . db_implode($myGroups) . ") "); foreach ($res as $p) { // FIXME: add "GROUP BY p_id" to sql to prevent double ids - also applicable for other queries here if (!isset($allPersons[$p->p_id])) { $allPersons[$p->p_id] = $p->p_id; } } } return $allPersons; }
/** * * @return string */ function churchwiki_getWikiInfos() { if (!user_access("view", "churchwiki")) { return ""; } $ids = user_access("view category", "churchwiki"); if (!$ids) { return ""; } $res = db_query("SELECT w.wikicategory_id, w.doc_id, wc.bezeichnung, DATE_FORMAT(w.modified_date , '%d.%m.%Y %H:%i') date,\n CONCAT(p.vorname, ' ', p.name) user\n FROM {cc_wiki} w, {cc_wikicategory} wc, {cdb_person} p\n WHERE wikicategory_id in (" . db_implode($ids) . ") AND w.wikicategory_id=wc.id\n AND w.modified_pid=p.id AND DATEDIFF(NOW(),modified_date)<2\n ORDER BY w.wikicategory_id, modified_date ASC"); $arr = array(); foreach ($res as $wiki) { $arr[$wiki->bezeichnung][$wiki->doc_id] = $wiki; } $txt = ""; foreach ($arr as $key => $cat) { $txt .= '<li><p>' . getConf("churchwiki_name", "Wiki") . ' ' . $key; foreach ($cat as $wiki) { $txt .= '<br/><small><a href="?q=churchwiki#WikiView/filterWikicategory_id:' . $wiki->wikicategory_id . '/doc:' . $wiki->doc_id . '">' . ($wiki->doc_id == "main" ? "Hauptseite" : $wiki->doc_id) . "</a>"; $txt .= " - {$wiki->date} {$wiki->user}</small>"; } } if ($txt != "") { $txt = "<ul>" . $txt . "</ul>"; } return $txt; }