<?php /** * Site layout template * @var $this \spartaksun\addresses\Application */ $session = \spartaksun\addresses\components\Session::getInstance(); $auth = new \spartaksun\addresses\components\UserAuth(); ?> <!DOCTYPE html> <html lang="en-EN"> <head> <meta charset="UTF-8"/> <title>Address book</title> <link href="/css/style.css" rel="stylesheet"> <script src="/js/main.js"></script> </head> <body> <div class="wrapper"> <div class="container"> <div class="nav"> <ul class="navigation"> <li class="active"><a href="/">Main page</a></li> <?php if ($auth->isAuthenticate()) { ?> <li> <a href="/admin">Control panel</a> </li> <li>
} $app->redirect('/admin'); }); /* Login form */ $app->route('/login', function () use($app) { $form = new \spartaksun\addresses\form\LoginForm(); if (!empty($_POST['login'])) { if ($form->load($_POST['login']) && $form->login()) { $app->redirect('/admin'); } } $app->render('login_form', array('form' => $form)); }); /* Action logout */ $app->route('/logout', function () use($app) { $auth = new \spartaksun\addresses\components\UserAuth(); $auth->logout(); $app->redirect('/login'); }); /* Control panel index page */ $app->route('/admin', function () use($app) { $app->checkAuthenticate(); $tree = new \spartaksun\addresses\components\EmployeeTree(); $app->render('admin', array('tree' => $tree)); }); ## Run application try { $app->run(); } catch (\spartaksun\addresses\AddressBookException $e) { $app->render('error', array('message' => $e->getMessage())); }