public function __construct()
 {
     if (static::class == 'App\\Controllers\\Edit' && Application::getCurrentByKey('role') != 'supervisor' || static::class == 'App\\Controllers\\Admin' && Application::getCurrentByKey('role') != 'admin') {
         throw new E403Exception(['class' => static::class, 'role' => Application::getCurrentByKey('role')]);
     }
     $this->view = new View();
 }
Пример #2
0
 public function actionEditing()
 {
     if (Application::getCurrentByKey('pageid')) {
         $condWhere['id'] = Application::getCurrentByKey('pageid');
         if ('operator' == Application::getCurrentByKey('role')) {
             $condWhere['author'] = Application::getCurrentByKey('username');
         }
         $this->view->items = Stuff::findByCondition($condWhere)[0];
     }
     $this->view->display($this->path . 'editing.php');
 }
Пример #3
0
 public function actionSpecific()
 {
     if (Application::getCurrentByKey('pageid')) {
         $condWhere['id'] = Application::getCurrentByKey('pageid');
         if ('operator' == Application::getCurrentByKey('role')) {
             $condWhere['author'] = Application::getCurrentByKey('username');
         }
         $this->view->items = Stuff::findByCondition($condWhere)[0];
         $this->view->display($this->path . 'specific.php');
     } else {
         header('Location: /');
     }
 }
Пример #4
0
    <title>Main page</title>
    <link type="text/css" rel="stylesheet" href="/style.css"/>
</head>
<body>
<div id="wrapper">
    <a href="/show/blog/">to blog</a><br>
    <a href="/show/polaroid/">to polaroid</a><br>
    <div class="form">
        <form action="/show/specific/" method="post"
              enctype="multipart/form-data" name="uploadform">
            <span> search by id: </span>
            <input type="search" id="search" name="id" value=""><input type="submit">
        </form>
        <br><a href="/auth/exit/">exit</a><br>
        <?php 
if ('admin' == \App\Classes\Application::getCurrentByKey('role')) {
    ?>
        <br><a href="/admin/log_request/">Просмотр логов</a><br>
        <?php 
}
?>
        <h1>Страница новостей</h1>
        <a href="/edit/editing/">Добавить новость</a>
        <br><br>
        <ul>
            <?php 
foreach ($items as $item) {
    ?>
                <li>
                    <a href="/show/specific/<?php 
    echo $item->getStuffId();
Пример #5
0
<?php

use App\Classes\Application;
use App\Classes\E403Exception;
use App\Classes\E404Exception;
use App\Classes\E405Exception;
require __DIR__ . '/autoload.php';
session_start();
define('PATH_ROOT', __DIR__);
/****************** parse url  ***************************************/
$urlPath = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$urlParts = explode('/', trim($urlPath, '/'));
$control = array_shift($urlParts);
$action = array_shift($urlParts);
/*********  check authentication and set/unset $_SESSION['id']  ***********/
if (!Application::getCurrentByKey('username') && $action != 'authentication') {
    $control = 'auth';
    $action = 'login';
} else {
    switch (true) {
        case !empty($urlParts):
            Application::setCurrentByKey(['pageid' => array_shift($urlParts)]);
            break;
        case !empty($_POST['id']):
            Application::setCurrentByKey(['pageid' => $_POST['id']]);
            break;
        case empty($control):
            Application::unsetCurrentByKey('pageid');
            break;
        default:
            break;