function SetCommonLoginStatus(&$tpl, $paramArray = array()) { $toolbar_tpl = new HTML_Template_IT("./"); $toolbar_tpl->loadTemplatefile("common_loginstatus.tpl.html", true, true); // parse the section depending on the current state of the user if (!IsLogged()) { // not logged, calculate return page $returnPage = $_SERVER['PHP_SELF']; $getCount = count($_GET); if ($getCount > 0) { $returnPage .= "?"; $i = 0; foreach (array_keys($_GET) as $getParam) { $returnPage .= $getParam . "=" . $_GET[$getParam]; if ($i < $getCount - 1) { $returnPage .= "&"; } $i++; } } $toolbar_tpl->setCurrentBlock("not_logged"); $toolbar_tpl->setVariable("RETURN_PAGE", urlencode($returnPage)); $toolbar_tpl->parseCurrentBlock("not_logged"); } else { if (array_key_exists("ItemId", $paramArray)) { $projectId = GetProjectIdForItem($paramArray["ItemId"]); } elseif (array_key_exists("UnitId", $paramArray)) { $projectId = GetProjectIdForUnit($paramArray["UnitId"]); } elseif (array_key_exists("ProjectId", $paramArray)) { $projectId = $paramArray["ProjectId"]; } else { $projectId = ""; } if ($projectId == "") { // no project Id, we simply indicate the logged in state $toolbar_tpl->setCurrentBlock("logged"); $toolbar_tpl->setVariable("USERNAME", GetLoggedUserName()); $toolbar_tpl->parseCurrentBlock("logged"); } else { if (!IsWriter($projectId)) { // no write access to project $toolbar_tpl->setCurrentBlock("not_allowed"); $toolbar_tpl->setVariable("USERNAME", GetLoggedUserName()); $toolbar_tpl->parseCurrentBlock("not_allowed"); } else { // full write access $toolbar_tpl->setCurrentBlock("logged_and_write"); $toolbar_tpl->setVariable("USERNAME", GetLoggedUserName()); $toolbar_tpl->parseCurrentBlock("logged_and_write"); } } } $tpl->setVariable("COMMON_LOGIN_STATUS", $toolbar_tpl->get()); }
function GetLoginSuccessfulPage($originPage) { $tpl = new HTML_Template_IT("./"); $tpl->loadTemplatefile("loginsuccessful.tpl.html", true, true); SetCommonLoginStatus($tpl); SetCommonToolbar($tpl); SetCommonFooter($tpl); $tpl->setVariable("USERNAME", GetLoggedUserName()); $tpl->setVariable("ORIGIN_PAGE", $originPage); // print the output return $tpl->get(); }
require_once "page_blocks.php"; require_once "loginfailed.php"; require_once "loginsuccessful.php"; require_once "loggedout.php"; // logout if asked to do so if (array_key_exists("action", $_GET) && $_GET["action"] == "logout") { Logout(); } // get the page to which we should return to, or default to index.php if (array_key_exists("returnTo", $_GET)) { $returnTo = $_GET["returnTo"]; } else { $returnTo = "index.php"; } // force the check of the currently checked user GetLoggedUserName(); if ($lastLoginResult == LLR_LOGGED_IN) { print GetLoginSuccessfulPage($returnTo); } elseif ($lastLoginResult == LLR_INVALID_LOGIN) { print GetLoginFailedPage(); } elseif ($lastLoginResult == LLR_NOW_LOGGED_OUT) { print GetLoggedOutPage(); } else { $tpl = new HTML_Template_IT("./"); $tpl->loadTemplatefile("login.tpl.html", true, true); SetCommonLoginStatus($tpl); SetCommonToolbar($tpl); SetCommonFooter($tpl); $tpl->setVariable("RETURN_TO", urlencode($returnTo)); $msg = ""; if ($lastLoginResult != LLR_NOT_LOGGED_IN) {
$adminIds = GetAdminUsersId(); if (!is_array($adminIds)) { die($adminIds); } if (!array_key_exists("is_admin", $_POST)) { $adminCount = 0; foreach ($adminIds as $adminId) { if ($adminId != $_POST["Id"]) { $adminCount++; } } $AtLeastOneAdmin = $adminCount > 0; } if ($AtLeastOneAdmin) { $userInfos = GetUserInfosById($_POST["Id"]); if ($userInfos["username"] == GetLoggedUserName() && $userInfos["IsAdmin"] == "Y" && !array_key_exists("is_admin", $_POST)) { $result = "You cannot revoke your own admin status. Please ask another admin to do so."; } elseif (!array_key_exists("is_admin", $_POST) && !array_key_exists("projects", $_POST)) { $result = "Non admin users must have at least one project assigned"; } else { $result = ModifyUser($_POST["Id"], $_POST["md5_hash"], $_POST["full_name"], $_POST["email"], array_key_exists("can_upload", $_POST) ? "Y" : "N", array_key_exists("is_power", $_POST) ? "Y" : "N", array_key_exists("is_admin", $_POST) ? "Y" : "N", array_key_exists("projects", $_POST) ? $_POST["projects"] : array()); } } else { $result = "There must always be at least one admin in the system."; } EndAccessToDB(); } if ($result == "") { $msg = "Modification successful"; } else { $msg = "Error while modifying: " . $result;
function GetLoggedUserId() { StartAccessToDB(); $LoggedUserName = GetLoggedUserName(); if ($LoggedUserName == "") { $result = -1; } else { $userInfos = GetUserInfos($LoggedUserName); if (is_array($userInfos)) { $result = $userInfos["Id"]; } else { $result = -1; } } EndAccessToDB(); return $result; }