<?php

include_once ROOT . '/components/islogin.php';
include_once ROOT . '/models/AuthModel.php';
include_once ROOT . '/models/ArticleModel.php';
if (CheckForLogIn::isLogin()) {
    $regId = base64_decode(base64_decode($_COOKIE['h3']));
    $user_info_array = GetMainUserInfo::GetInfo($regId);
    if ($user_info_array['is_admin'] == 1) {
        $article_name = $_POST['article_name'];
        $article_short_contents = $_POST['article_short_contents'];
        $article_contents = $_POST['article_contents'];
        $article_author = $user_info_array['reg_name'] . ' ' . $user_info_array['reg_surname'];
        $article_picture_array = explode('/', $_FILES['article_picture']['type']);
        $article_picture_type = array_pop($article_picture_array);
        $last_article_id = Article::getLastArticleId();
        $new_picture_name = $last_article_id['article_id'] + 1;
        copy($_FILES['article_picture']['tmp_name'], ROOT . '/uploads/articles/' . $new_picture_name . '.' . $article_picture_type);
        // копируем временный файл в аплоад папку (до окончания работы скрипта)
        $article_picture = '/uploads/articles/' . $new_picture_name . '.' . $article_picture_type;
        Article::createArticle($article_name, $article_short_contents, $article_contents, $article_picture, $article_author);
        unset($_POST['article_name'], $_POST['article_short_contents'], $_POST['article_contents']);
        $all_articles = Article::getList();
        $articlesCount = count($all_articles);
        $get_id = ceil($articlesCount / 4);
        header('Location: /articles-navigation/1');
        // перенаправление на страниу с только что добавленной статьей
    } else {
        header('Location: /articles-navigation/1');
    }
} else {