/** * get master data * @see CTModuleInterface::getMasterData() * * @return array */ public function getMasterData() { global $user, $base_url, $files_dir, $config; $res = churchdb_getMasterDataTables(); $res["feldtyp"] = churchcore_getTableData("cdb_feldtyp"); $res["fields"] = getAllFields(); $res["groups"] = getAllGroups(); $res["tags"] = getAllTags(); $res["FUNachfolgeDomains"] = array("0" => array("id" => "0", "bezeichnung" => "Kein"), "1" => array("id" => "1", "bezeichnung" => $res["fields"]["f_group"]["fields"]["gruppentyp_id"]["text"]), "2" => array("id" => "2", "bezeichnung" => $res["fields"]["f_group"]["fields"]["distrikt_id"]["text"]), "3" => array("id" => "3", "bezeichnung" => t("group"))); $res["groupMemberTypes"] = getGroupMemberTypes(); $res["groupFilterTypes"] = churchdb_getGroupFilterTypes(); // master data information for maintain masterdata and statistics if (user_access("edit masterdata", "churchdb") || user_access("view statistics", "churchdb")) { $res["masterDataTables"] = churchdb_getMasterDataTablenames(); } $res["user_pid"] = $user->id; $res["userid"] = $user->vorname . " " . $user->cmsuserid . " [" . $user->id . "]"; $res["auth"] = churchdb_getAuthForAjax(); $res["site_name"] = getConf('site_name'); $res["modulespath"] = churchdb_getModulesPath(); $res["files_url"] = $base_url . $files_dir; $res["modulename"] = "churchdb"; $res["max_uploadfile_size_kb"] = getConf('max_uploadfile_size_kb'); $res["adminemail"] = getConf('site_mail', ''); $res["max_exporter"] = getConf('churchdb_maxexporter', '150'); $res["groupnotchoosable"] = getConf('churchdb_groupnotchoosable', 30); $res["home_lat"] = getConf('churchdb_home_lat', '53.568537'); $res["home_lng"] = getConf('churchdb_home_lng', '10.03656'); $res["settings"] = churchdb_getUserSettings($user->id); $res["last_log_id"] = churchdb_getLastLogId(); $res["mailchimp"] = getConf('churchdb_mailchimp_apikey') != ""; $res["views"] = array("ArchiveView" => array("filename" => "cdb_archiveview"), "MapView" => array("filename" => "cdb_mapview"), "StatisticView" => array("filename" => "cdb_statisticview"), "SettingsView" => array("filename" => "cdb_settingsview"), "MaintainView" => array("filename" => "cdb_maintainview"), "WeekView" => array("filename" => "../churchresource/cr_weekview")); if (user_access("administer persons", "churchcore")) { $res["auth_table"] = churchdb_getAuthTable(); } if (isset($res["auth"]["edit newsletter"])) { $nl = churchdb_getTableData("cdb_newsletter"); $newsletter = array(); foreach ($res["auth"]["edit newsletter"] as $n) { $newsletter = $nl[$n]; } $res["newsletter"] = $newsletter; } return $res; }
/** * save data array * * @param array $fields * @param int $primary_key - id von person_id * @param array $data_arr * * @return Gibt das alte Array zurueck */ function saveDataArray($fields, $primary_key, $data_arr) { global $user; $res = db_query("SELECT * FROM {" . $fields["tablename"] . "} WHERE " . $fields["idname"] . "=" . $primary_key); $old_arr = $res->fetch(); $error_str = ""; $auth = churchdb_getAuthForAjax(); $person_id = null; if ($fields["tablename"] == "cdb_person" || $fields["tablename"] == "cdb_gemeindeperson") { if (churchdb_isPersonSuperLeaderOfPerson($user->id, $primary_key)) { $auth["leader"] = true; $auth["superleader"] = true; } else { if (churchdb_isPersonLeaderOfPerson($user->id, $primary_key)) { $auth["leader"] = true; } } } else { if ($fields["tablename"] == "cdb_gruppe") { $myGroups = churchdb_getMyGroups($user->id, true, false, true); if (count($myGroups)) { $auth["superleader"] = true; $auth["leader"] = true; } else { $myGroups = churchdb_getMyGroups($user->id, true, true); if (count($myGroups)) { $auth["leader"] = true; } } } } // TODO: use new db methods, with :params $sql = "UPDATE {" . $fields["tablename"] . "} SET "; foreach ($data_arr as $key => $param) { if (isset($fields["fields"][$key])) { if (!isset($fields["fields"][$key]["auth"]) || checkFieldAuth($fields["fields"][$key]["auth"], $auth)) { $param = str_replace("'", "\\'", $param); switch ($fields["fields"][$key]["type"]) { case "number": if ($param == "") { $sql = $sql . $fields["fields"][$key]["sql"] . "=null, "; } else { $sql = $sql . $fields["fields"][$key]["sql"] . "=" . $param . ", "; } break; case "textarea": case "text": case "select": $sql = $sql . $fields["fields"][$key]["sql"] . "='" . $param . "', "; break; case "checkbox": $sql = $sql . $fields["fields"][$key]["sql"] . "=" . $param . ", "; break; case "date": if ($param != "" && $param != "null") { $sql = $sql . $fields["fields"][$key]["sql"] . "='" . $param . "', "; } else { $sql = $sql . $fields["fields"][$key]["sql"] . "=null, "; } break; } } else { $error_str .= "Fehlendes Recht " . $fields["fields"][$key]["auth"] . " fuer Update von Feld: " . $key . ". "; } } } if ($error_str) { throw new CTException($error_str); } // if no change date given set it to now() if (isset($data_arr['letzteaenderung'])) { $sql .= " letzteaenderung='" . $data_arr['letzteaenderung'] . "',"; } else { $sql .= " letzteaenderung=now(),"; } $sql .= " aenderunguser='******' WHERE " . $fields["idname"] . "=" . $primary_key; // cdb_log('Update sql:'.$sql,2,-1,CDB_LOG_PERSON,1); db_query($sql); return $old_arr; }