/** * Save user settings * * @param string $modulename * @param int $user_pid; or array which holds pid in first key * @param string $attrib * @param mixed $val */ function churchcore_saveUserSetting($modulename, $user_pid, $attrib, $val) { if ($user_pid == null || $user_pid <= 0) { return; } //TODO: simplify by foreach ((array) $user_pid)? if (is_array($user_pid)) { foreach ($user_pid as $pid) { _churchcore_savePidUserSetting($modulename, $pid, $attrib, $val); } } else { _churchcore_savePidUserSetting($modulename, $user_pid, $attrib, $val); } }
/** * * @param array $u userdata * @param bool $rember_me * @return NULL */ function login_user($u, $rember_me = false, $redirect = true) { global $q, $q_orig, $config; if (empty($u->id)) { addErrorMessage(t("login.error.no.id.specified")); return null; } $_SESSION["email"] = $u->email; if (!$u->cmsuserid) { $u->cmsuserid = "{$u->vorname} {$u->name} [" . $u->id . "]"; db_query("UPDATE {cdb_person}\n SET cmsuserid=:cmsuserid\n WHERE id=:id", array(':cmsuserid' => $u->cmsuserid, ':id' => $u->id)); } if ($u->loginstr) { db_query("UPDATE {cdb_person}\n SET loginstr=NULL\n WHERE id=:id", array(':id' => $u->id)); } $u->auth = getUserAuthorization($u->id); $_SESSION["user"] = $u; // TODO: make time configurable // login is valid for 6 days $cookieExpireTime = time() + 60 * 60 * 24 * 6; setcookie("RememberMe", $rember_me, $cookieExpireTime); $_SESSION["sessionid"] = random_string(); setcookie("CC_SessionId", $_SESSION["sessionid"], $cookieExpireTime); $dt = new DateTime(); db_query("UPDATE {cdb_person} SET lastlogin=NOW(), loginerrorcount=0 WHERE id=:id", array(':id' => $u->id)); // Get language form user setting, if not available set it from current cookie $lang = getUserSetting("churchcore", $u->id, "language"); if (!$lang) { _churchcore_savePidUserSetting("churchcore", $u->id, "language", getConf("language")); } else { setcookie("language", $lang, time() + 60 * 60 * 24 * 30); } // 30 days db_query("DELETE FROM {cc_session} WHERE datediff(NOW(), datum)>7"); db_query("INSERT INTO {cc_session} (person_id, session, hostname, datum)\n VALUES (:id, :session, :host, :date)", array(':id' => $u->id, ':session' => $_SESSION["sessionid"], ':host' => $_SERVER["HTTP_HOST"], ':date' => $dt->format('Y-m-d H:i:s'))); if ($u->email) { // look for family users with the same email $res = db_query("SELECT * FROM {cdb_person}\n WHERE email=:email AND archiv_yn=0", array(":email" => $u->email)); $family = array(); $count = 0; foreach ($res as $p) { if ($p->id != $u->id) { $family[$p->id] = $p; } $count++; if ($count > 15) { break; } //no family should have more then 15 users } if (count($family)) { $_SESSION["family"] = $family; } } ct_log("Login succeed: {$u->email} with " . getVar('HTTP_USER_AGENT', "Unkown Browser", $_SERVER), 2, -1, "login"); if ($redirect) { // on switching family login dont forward to login again if ($q != $q_orig) { header("Location: " . $_SERVER["REQUEST_URI"]); } else { if ($q == "login") { header("Location: ?q=home"); } } } }
/** * Save user settings * * @param unknown_type $modulename * @param unknown_type $user_pid Array oder nur die pid * @param unknown_type $attrib * @param unknown_type $val */ function churchcore_saveUserSetting($modulename, $user_pid, $attrib, $val) { if ($user_pid == null || $user_pid <= 0) { return; } if (gettype($user_pid) == "array") { foreach ($user_pid as $pid) { _churchcore_savePidUserSetting($modulename, $pid, $attrib, $val); } } else { _churchcore_savePidUserSetting($modulename, $user_pid, $attrib, $val); } }
public function setLanguage($params) { global $user; setcookie("language", $params["language"], time() + 60 * 60 * 24 * 30); // 30 days _churchcore_savePidUserSetting("churchcore", $user->id, "language", $params["language"]); }