Пример #1
0
 public function actionIndex()
 {
     $product_count_main_page = FL::fileGetContents('product_count_main_page.txt');
     $product_count_catalog_page = FL::fileGetContents('product_count_catalog_page.txt');
     $product_count_category_page = FL::fileGetContents('product_count_category_page.txt');
     if (isset($_POST['submit'])) {
         if (isset($_POST['productCountMainPage'])) {
             $productCountMainPage = FL::clearInt($_POST['productCountMainPage']);
             AdminModel::filePutContents(ROOT . '/config/product_count_main_page.txt', $productCountMainPage);
         }
         if (isset($_POST['productCountCatalogPage'])) {
             $productCountCatalogPage = FL::clearInt($_POST['productCountCatalogPage']);
             AdminModel::filePutContents(ROOT . '/config/product_count_catalog_page.txt', $productCountCatalogPage);
         }
         if (isset($_POST['productCountCategoryPage'])) {
             $productCountCategoryPage = FL::clearInt($_POST['productCountCategoryPage']);
             AdminModel::filePutContents(ROOT . '/config/product_count_category_page.txt', $productCountCategoryPage);
         }
         FL::redirectTo('/admin/view');
     }
     $view = new View();
     $view->product_count_main_page = $product_count_main_page;
     $view->product_count_catalog_page = $product_count_catalog_page;
     $view->product_count_category_page = $product_count_category_page;
     $view->display('admin_view/index.php');
     return true;
 }
Пример #2
0
 public function actionEdit($id)
 {
     $category = CategoryModel::getById($id);
     $totalCategories = CategoryModel::getTotal();
     if (isset($_POST['submit'])) {
         $name = FL::clearStr($_POST['name']);
         $sortOrder = FL::clearInt($_POST['sortOrder']);
         $status = FL::clearInt($_POST['status']);
         if (!FL::isValue($name)) {
             $errors[] = 'Название не может быть пустым';
         }
         if (empty($errors)) {
             $category->name = $name;
             $category->sort_order = $sortOrder;
             $category->status = $status;
             $result = $category->save();
             if (!$result) {
                 $errors[] = 'Редактирование не удалось';
             } else {
                 FL::redirectTo('/admin/category');
             }
         }
     }
     $view = new View();
     $view->category = $category;
     $view->totalCategories = $totalCategories;
     $view->display('admin_category/edit.php');
     return true;
 }
Пример #3
0
 public function actionAbout()
 {
     $categories = CategoryModel::getAllUsingColumns();
     $view = new View();
     $view->categories = $categories;
     $view->display('site/about.php');
     return true;
 }
Пример #4
0
 public function actionView($id)
 {
     $categories = CategoryModel::getAllUsingColumns();
     $product = ProductModel::getById($id);
     $view = new View();
     $view->categories = $categories;
     $view->product = $product;
     $view->display('product/view.php');
     return true;
 }
Пример #5
0
 public function actionView($id)
 {
     $categories = CategoryModel::getAllUsingColumns();
     $blog = BlogModel::getById($id);
     $view = new View();
     $view->categories = $categories;
     $view->blog = $blog;
     $view->display('blog/view.php');
     return true;
 }
Пример #6
0
 public function __construct()
 {
     $paramsPath = ROOT . '/config/db_params.php';
     $params = (include $paramsPath);
     $dsn = "mysql:host={$params['host']};dbname={$params['dbname']}";
     try {
         $this->db = new PDO($dsn, $params['user'], $params['password']);
         $this->db->exec("SET NAMES 'utf-8'");
     } catch (PDOException $e) {
         $logger = Logger::getInstance();
         $logger->setLog($e->getFile(), $e->getLine(), $e->getMessage());
         $view = new View();
         $view->error = "Нет соединения с БД";
         $view->display('error.php');
         die;
     }
 }
Пример #7
0
 public function actionEdit($id)
 {
     $order = ProductOrderModel::getById($id);
     if (isset($_POST['submit'])) {
         $status = (int) $_POST['status'];
         if ($status) {
             $order->status = $status;
             $result = $order->save();
             if ($result) {
                 FL::redirectTo('/admin/order');
             }
         }
     }
     $view = new View();
     $view->order = $order;
     $view->display('admin_order/edit.php');
     return true;
 }
Пример #8
0
 public function actionEdit($id)
 {
     $id = (int) $id;
     $name = '';
     $password = '';
     $errors = [];
     $user = UserModel::getUser('user');
     if (!$user) {
         FL::redirectTo('/');
     }
     $categories = CategoryModel::getAllUsingColumns();
     if (isset($_POST['submit'])) {
         $name = FL::clearStr($_POST['name']);
         $password = FL::clearStr($_POST['password']);
         if (!FL::isValue($name)) {
             $errors[] = 'Имя не может быть пустым';
         }
         if (!FL::isPassword($password)) {
             $errors[] = 'Пароль должен быть больше 5 символов';
         }
         if (empty($errors)) {
             $user = UserModel::getById($id);
             $user->name = $name;
             $user->password = $password;
             Session::deleteSession('user');
             Cookie::deleteCookie('user');
             $result = $user->save(false, true);
             if ($result) {
                 FL::redirectTo('/cabinet');
             }
         }
     }
     $view = new View();
     $view->categories = $categories;
     $view->id = $id;
     $view->errors = $errors;
     $view->password = $password;
     $view->user = $user;
     $view->display('cabinet/edit.php');
     return true;
 }
Пример #9
0
 public function actionCategory($categoryId, $page = 1)
 {
     $limit = FL::fileGetContents('product_count_category_page.txt');
     if (!$limit) {
         $limit = 9;
     }
     $page = (int) $page;
     $categories = CategoryModel::getAllUsingColumns();
     $products = ProductModel::getByCategoryId($categoryId, $limit, $page);
     if (!$products) {
         $products = [];
     }
     $total = ProductModel::getTotal('category_id', $categoryId);
     $pagination = FL::buildPagination($total, $page, $limit, 'page-');
     $view = new View();
     $view->categories = $categories;
     $view->products = $products;
     $view->categoryId = $categoryId;
     if (isset($pagination)) {
         $view->pagination = $pagination;
     }
     $view->display('catalog/category.php');
     return true;
 }
Пример #10
0
 public function actionCreate()
 {
     $errors = [];
     if (isset($_POST['submit'])) {
         $name = FL::clearStr($_POST['name']);
         $email = FL::clearStr($_POST['email']);
         $password = FL::clearStr($_POST['password']);
         if (!FL::isValue($name)) {
             $errors[] = 'Имя не может быть пустым';
         }
         if (!FL::isEmail($email)) {
             $errors[] = 'Некорректный email';
         }
         if (UserModel::getByColumn('email', $email)) {
             $errors[] = 'Такой email уже существует';
         }
         if (!FL::isPassword($password)) {
             $errors[] = 'Пароль должен быть больше 5 символов';
         }
         if (empty($errors)) {
             $user = new UserModel();
             $user->name = $name;
             $user->email = $email;
             $user->password = $password;
             $user->role = 'admin';
             $result = $user->save(false, true);
             if ($result) {
                 FL::redirectTo('/admin/user');
             }
         }
     }
     $view = new View();
     $view->errors = $errors;
     $view->display('admin_user/create.php');
     return true;
 }
Пример #11
0
<?php

use App\Components\Router;
use App\Components\View;
use App\Components\Logger;
use App\Components\FunctionLibrary as FL;
// Front Controller
// 1. Общие настройки
ini_set('display_errors', 1);
error_reporting(E_ALL);
session_start();
// 2. Подключение системных файлов
define('ROOT', dirname(__FILE__));
require_once ROOT . '/components/autoload.php';
// 3. Вызов Router
try {
    $router = new Router();
    $router->run();
    FL::deleteLink();
} catch (Exception $e) {
    $logger = Logger::getInstance();
    $logger->setLog($e->getFile(), $e->getLine(), $e->getMessage());
    $view = new View();
    $view->error = $e->getMessage();
    $view->display('error.php');
}
Пример #12
0
 public function actionOrder()
 {
     $userName = '';
     $errors = [];
     $categories = CategoryModel::getAllUsingColumns();
     $productsKeysArray = Session::getSession('products');
     if ($productsKeysArray) {
         $keysArray = array_keys($productsKeysArray);
         $keysString = implode(',', $keysArray);
         if ($keysString) {
             $products = ProductModel::getAll($keysString);
             $amountPrice = CartModel::amountProductsPriceInCart($productsKeysArray, $products);
         }
     }
     $user = UserModel::getUser('user');
     if ($user) {
         $userName = $user->name;
         $userId = $user->id;
     } else {
         $userId = 0;
     }
     if (isset($_POST['submit'])) {
         $name = FL::clearStr($_POST['name']);
         $phone = FL::clearStr($_POST['phone']);
         $comment = FL::clearStr($_POST['comment']);
         if (!FL::isValue($name)) {
             $errors[] = 'Имя не может быть пустым';
         }
         if (!FL::isValue($phone)) {
             $errors[] = 'Телефон не может быть пустым';
         }
         if (!FL::isPhone($phone)) {
             $errors[] = 'Невалидный телефон';
         }
         if (!FL::isValue($comment)) {
             $errors[] = 'Комментарий не может быть пустым';
         }
         if (empty($errors)) {
             $productsKeysArray = Session::getSession('products');
             if ($productsKeysArray) {
                 $products = json_encode($productsKeysArray);
             }
             $cart = new CartModel();
             $cart->user_name = $name;
             $cart->user_phone = $phone;
             $cart->user_comment = $comment;
             $cart->user_id = $userId;
             $cart->products = $products;
             $orderId = $cart->save();
             if ($orderId) {
                 Session::deleteSession('products');
                 Session::createSession('message', 'Заказ оформлен!');
                 FL::redirectTo('/cart');
             }
         }
     } else {
         $countProducts = CartModel::countProductsInCart();
         if ($countProducts <= 0) {
             FL::redirectTo('/');
         }
     }
     $view = new View();
     $view->categories = $categories;
     $view->amountPrice = $amountPrice;
     $view->userName = $userName;
     $view->errors = $errors;
     $view->display('cart/order.php');
     return true;
 }
Пример #13
0
 public function actionIndex()
 {
     $view = new View();
     $view->display('admin/index.php');
     return true;
 }
Пример #14
0
 public function actionDelete($id)
 {
     $product = ProductModel::getById($id);
     if (isset($_POST['delNo'])) {
         FL::redirectTo('/admin/product');
     }
     if (isset($_POST['delYes'])) {
         $result = ProductModel::delete($id);
         if ($result) {
             FL::redirectTo('/admin/product');
         }
     }
     $view = new View();
     $view->product = $product;
     $view->display('admin_product/delete.php');
     return true;
 }
Пример #15
0
 public function actionEdit($id)
 {
     $errors = [];
     $blog = BlogModel::getById($id);
     if (isset($_POST['submit'])) {
         $title = FL::clearStr($_POST['title']);
         $description = FL::clearStr($_POST['description']);
         $content = FL::clearStr($_POST['content']);
         if (!FL::isValue($title)) {
             $errors[] = 'Название не может быть пустым';
         }
         if (!FL::isValue($description)) {
             $errors[] = 'Описание не может быть пустым';
         }
         if (!FL::isValue($content)) {
             $errors[] = 'Контент не может быть пустым';
         }
         if (empty($errors)) {
             $blog->title = $title;
             $blog->description = $description;
             $blog->content = $content;
             $res = $blog->save();
             if ($res) {
                 if ($_FILES['image']['name'] && $_FILES['image']['type'] == 'image/jpeg') {
                     $fileName = 'blog' . $id . '.jpg';
                     $tmpName = $_FILES['image']['tmp_name'];
                     if (is_uploaded_file($tmpName)) {
                         $imagePath = '/images/blog/' . $fileName;
                         $destination = ROOT . '/template/images/blog/' . $fileName;
                         $result = move_uploaded_file($tmpName, $destination);
                         if ($result) {
                             $blog->image = $imagePath;
                             $blog->save();
                         }
                     }
                 }
             }
             FL::redirectTo('/admin/blog');
         }
     }
     $view = new View();
     $view->blog = $blog;
     $view->errors = $errors;
     $view->display('admin_blog/edit.php');
     return true;
 }
Пример #16
0
 public function actionLogin()
 {
     $email = '';
     $password = '';
     $remember = '';
     $errors = [];
     if (isset($_POST['submit'])) {
         $email = FL::clearStr($_POST['email']);
         $password = FL::clearStr($_POST['password']);
         if (isset($_POST['remember'])) {
             $remember = $_POST['remember'];
         }
         if (!FL::isEmail($email)) {
             $errors[] = 'Некорректный email';
         }
         if (!FL::isValue($password)) {
             $errors[] = 'Пароль не может быть пустым';
         }
         if (empty($errors)) {
             $user = UserModel::checkRegister($email, $password, $remember);
             if ($user) {
                 Session::createSession('user', $user, true);
                 FL::redirectTo('/cabinet');
             } else {
                 $errors[] = 'Неправильные данные для входа на сайт';
             }
         }
     }
     $categories = CategoryModel::getAllUsingColumns();
     $view = new View();
     $view->categories = $categories;
     $view->email = $email;
     $view->password = $password;
     $view->errors = $errors;
     $view->display('user/login.php');
     return true;
 }