public function actionView($productId)
 {
     $categories = array();
     $categories = Platform::getPlatformList();
     $product = Products::getProductById($productId);
     $productId = $product['id'];
     $platform = Platform::getPlatformById($product['platform_id']);
     $comments = Comment::getCommentsByProductId($productId);
     //COMMENTS
     if (isset($_POST['submit'])) {
         $userComment = $_POST['message'];
         $errors = false;
         if (!Comment::validateMessage($userComment)) {
             $errors[] = "Введите собщение";
         }
         if (User::isGuest()) {
             $userName = $_POST['name'];
             $userEmail = $_POST['email'];
             if (!User::validateUsername($userName)) {
                 $errors[] = "Неверное имя";
             }
             if (!User::validateEmail($userEmail)) {
                 $errors[] = "Неверный Email";
             }
             $userId = false;
         } else {
             $userId = User::validateLogged();
             $user = User::getUserById($userId);
             $userName = $user['name'];
         }
         Comment::addComment($userComment, $userId, $userName, $productId);
     }
     require_once ROOT . '/views/product/view.php';
     return true;
 }
 public static function validateAdmin()
 {
     $userId = User::validateLogged();
     $user = User::getUserById($userId);
     if ($user['role'] == 'admin') {
         return true;
     }
     die("ACCESS DINIED");
 }
 public function actionEdit()
 {
     $userId = User::validateLogged();
     $user = User::getUserById($userId);
     $result = false;
     $username = $user['name'];
     if (isset($_POST['submit'])) {
         $username = $_POST['username'];
         $password = $_POST['password'];
         $confirm_password = $_POST['confirm-password'];
         $errors = false;
         if (!User::validateUsername($username)) {
             $errors[] = "Имя должно быть больше 5 символов";
         }
         if ($errors == false) {
             $result = User::edit($userId, $username, $password);
         }
     }
     require_once ROOT . '/views/cabinet/edit.php';
     return true;
 }
 public function actionOrder()
 {
     $platform = array();
     $errors = array();
     $userName = '';
     $userEmail = '';
     $userPhone = '';
     $userComment = '';
     $platform = Platform::getPlatformList();
     $result = false;
     if (isset($_POST['submit'])) {
         $userName = $_POST['name'];
         $userEmail = $_POST['email'];
         $userPhone = $_POST['phone'];
         $userComment = $_POST['message'];
         $errors = false;
         if (!User::validateUsername($userName)) {
             $errors[] = "Неверное имя";
         }
         if (!User::validateEmail($userEmail)) {
             $errors[] = "Неверный Email";
         }
         if (!User::validatePhone($userPhone)) {
             $errors[] = "Неккоректный телефон";
         }
         if ($errors == false) {
             $productsBasket = Basket::getProducts();
             if (User::isGuest()) {
                 $userId = false;
             } else {
                 $userId = User::validateLogged();
             }
             $result = Order::save($userName, $userEmail, $userPhone, $userComment, $userId, $productsBasket);
             if ($result) {
                 $adminEmail = "*****@*****.**";
                 $subject = "Новый заказ";
                 mail($adminEmail, $subject, $userComment);
                 Basket::clear();
             }
         } else {
             $productsInBasket = Basket::getProducts();
             $productId = array_keys($productsInBasket);
             $products = Products::getProductsByIdInBasket($productId);
             $totalPrice = Basket::getTotalPrice($products);
             $total = array_sum($totalPrice);
             $totalQuantity = Basket::countItem();
         }
     } else {
         $productsInbasket = Basket::getProducts();
         if ($productsInbasket == false) {
             header("Loaction: /");
         } else {
             $productId = array_keys($productsInbasket);
             $products = Products::getProductsByIdInBasket($productId);
             $totalPrice = Basket::getTotalPrice($products);
             $totalQuantity = Basket::countItem();
             $userName = false;
             $userEmail = false;
             $userPhone = false;
             $userComment = false;
             if (User::isGuest()) {
             } else {
                 $userId = User::validateLogged();
                 $user = User::getUserById($userId);
                 $userName = $user['name'];
                 $userEmail = $user['email'];
             }
         }
     }
     require_once ROOT . "/views/basket/order.php";
     return true;
 }