Example #1
0
 public function init()
 {
     $data = $_REQUEST;
     if (isset($data[Profile::GET_CHANGE_PASSWORD_BUTTON])) {
         if (strlen($data[Profile::GET_CHANGE_PASSWORD]) > 0) {
             if (!User::passwordIsValid($data[Profile::GET_CHANGE_PASSWORD])) {
                 Flight::redirect($_SERVER['REDIRECT_URL'] . '?success=0');
             } else {
                 $user = Auth::getInstance()->getUser();
                 $user->password = User::getHashPassword(trim(strip_tags($data[Profile::GET_CHANGE_PASSWORD])), $user->login);
                 $user->save();
                 Flight::redirect($_SERVER['REDIRECT_URL'] . '?success=1');
                 return true;
             }
         }
         if (strlen($data[Profile::GET_CHANGE_PHONE]) > 0) {
             if (!User::validatePhone(trim($data[Profile::GET_CHANGE_PHONE]))) {
                 Flight::redirect($_SERVER['REDIRECT_URL'] . '?success=2');
             } else {
                 $user = Auth::getInstance()->getUser();
                 $user->number = trim($data[Profile::GET_CHANGE_PHONE]);
                 $user->save();
                 Flight::redirect($_SERVER['REDIRECT_URL'] . '?success=1');
                 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;
 }