/** Display the requested page. */ function displayPage($webPage) { setcookie("last-page", full_url($_SERVER)); if (isset($_SESSION["message"])) { $message = $_SESSION["message"]; $this->tpl->assign('message', $message); unset($_SESSION["message"]); } try { if (isset($this->pdo)) { $sth = $this->pdo->prepare("SELECT COUNT(alerts.id) AS c FROM alerts WHERE resolved = 0"); $sth->execute(); $countAlerts = $sth->fetch(PDO::FETCH_ASSOC); $countAlerts = $countAlerts["c"]; $this->tpl->assign('countAlerts', $countAlerts); } } catch (Exception $e) { Log::getLogger()->write(Log::LOG_ERROR, "Unable to request DB", $e); $this->tpl->assign('countAlerts', 0); } try { switch ($webPage) { case CONTROLLER_DASHBOARD: $c = new DashboardController($this->pdo); $c->buildTemplate($this->tpl); break; case CONTROLLER_ADMIN: $c = new AdminController($this->pdo); $c->buildTemplate($this->tpl); break; case CONTROLLER_PROFILE: $c = new ProfileController($this->pdo); $c->buildTemplate($this->tpl); break; case CONTROLLER_HELP: $c = new HelpController($this->pdo); $c->buildTemplate($this->tpl); break; case CONTROLLER_LOGIN: $c = new LoginController($this->pdo); $c->buildTemplate($this->tpl); break; case CONTROLLER_DEFAULT: default: $this->tpl->display('controller_blank.tpl'); break; } } catch (SecurityAccessException $sae) { if ($this->tpl->getTemplateVars('message') == null) { $_SESSION["message"] = array("type" => "danger", "title" => "Accès interdit", "descr" => "Cette page est protégée. Veuillez vous connecter avec un compte ayant accès à cette page."); $this->tpl->assign('message', $_SESSION["message"]); unset($_SESSION["message"]); } // A Security Access Exception occurs when the user cannot see the asked page. // So in this case let's redirect to login page. $c = new LoginController($this->pdo); $c->buildTemplate($this->tpl); } catch (SecurityException $se) { // A Security Exception is more generic so display a message. Log::getLogger()->write(Log::LOG_ALERT, "Security Exception dropped on dispatcher", $se); $_SESSION["message"] = array("type" => "danger", "title" => "Erreur", "descr" => $se->getMessage()); $this->tpl->assign('message', $_SESSION["message"]); unset($_SESSION["message"]); $this->tpl->display('controller_error.tpl'); } catch (Exception $e) { Log::getLogger()->write(Log::LOG_ERROR, "Unknown Exception dropped on dispatcher", $e); // A very generic exception. $_SESSION["message"] = array("type" => "danger", "title" => "Erreur", "descr" => $e->getMessage()); $this->tpl->assign('message', $_SESSION["message"]); unset($_SESSION["message"]); $this->tpl->display('controller_error.tpl'); } }