public function actionEdit($id = array('1'))
 {
     $id = (int) $id[0];
     try {
         $product = $this->model->get_product($id);
         $categories = $this->model->get_categories();
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $product_name = ClearInput::clearInput($_POST['product_name'], 's');
         if (mb_strlen($product_name) < 2) {
             $errors[] = 'Название должно иметь больше двух символов';
         }
         $product_img = ClearInput::clearInput($_POST['product_img'], 's');
         $mark = ClearInput::clearInput($_POST['mark'], 's');
         if (mb_strlen($mark) < 2) {
             $errors[] = 'Бранд должн иметь больше двух символов';
         }
         $count = ClearInput::clearInput($_POST['count'], 'i+');
         $price = ClearInput::clearInput($_POST['price'], 'f');
         $description = ClearInput::clearInput($_POST['description'], 's');
         $category_id = ClearInput::clearInput($_POST['catalog_id'], 'i+');
         if (!isset($errors)) {
             try {
                 $this->model->update_product($id, $product_name, $product_img, $mark, $count, $price, $description, $category_id);
                 $result = 'Товар успешно Именен';
             } catch (Exception $e) {
                 $errors[] = $e->getMessage();
             }
         }
     }
     $data = array('title' => 'Редактировать товпр', 'is_logged' => Session::is_logged(), 'user_name' => isset($_SESSION['user_name']) ? $_SESSION['user_name'] : 'Админ', 'result' => isset($result) ? $result : null, 'errors' => isset($errors) ? $errors : null, 'product' => isset($product) ? $product : null, 'categories' => isset($categories) ? $categories : null);
     $this->view->render('admin/products/edit.twig', $data);
 }
示例#2
0
 function actionIndex()
 {
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         if (!ClearInput::validate_email($_POST['email'])) {
             $errors[] = 'Email не валидный';
         }
         $email = $_POST['email'];
         $password = ClearInput::clearInput($_POST['password'], 's');
         if (strlen($password) < 6) {
             $errors[] = 'Введено меньше 6 символов';
         }
         if (!($user = $this->model->getUserByEmail($email))) {
             $errors[] = 'Неверен Email';
         }
         if ($user['password'] != UserModel::encrypt_pass($password)) {
             $errors[] = "Пароль не верен";
         }
         if (!isset($errors)) {
             $hash = md5(UserModel::generateCode(10));
             $this->model->updateUserHashById($user['id'], $hash);
             $ses_data = array('id' => $user['id'], 'name' => $user['name'], 'role' => $user['role']);
             $this->session->start($ses_data, $hash);
             if ($user['role'] == 2) {
                 header("Location: /admin/");
             } else {
                 header("Location: / ");
             }
         }
     }
     $data = array('title' => 'Авторизация', 'is_logged' => Session::is_logged(), 'user_name' => isset($_SESSION['user_name']) ? $_SESSION['user_name'] : null, 'errors' => isset($errors) ? $errors : null);
     $this->view->render('auth_view.twig', $data);
 }
 public function actionEdit($id = array('1'))
 {
     $id = (int) $id[0];
     try {
         $category = $this->model->find_category_by_id($id);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $category_name = ClearInput::clearInput($_POST['category_name'], 's');
         if (mb_strlen($category_name) < 2) {
             $errors[] = 'Название должно иметь больше двух символов';
         }
         if (!isset($errors)) {
             try {
                 $this->model->update_category_by_id($id, $category_name);
                 $result = 'Категория изменина успешно';
             } catch (Exception $e) {
                 $errors[] = $e->getMessage();
             }
         }
     }
     $data = array('title' => 'Редактирование категории товаров', 'is_logged' => Session::is_logged(), 'user_name' => isset($_SESSION['user_name']) ? $_SESSION['user_name'] : 'Админ', 'result' => isset($result) ? $result : null, 'errors' => isset($errors) ? $errors : null, 'category' => isset($category) ? $category : null);
     $this->view->render('admin/category/edit.twig', $data);
 }
示例#4
0
 public function actionOrder()
 {
     if (Session::is_logged() === false) {
         $errors[] = 'Вы не авторизованы';
     }
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $payment_methot = ClearInput::clearInput($_POST['payment_methot'], 's');
         $delivery_service = ClearInput::clearInput($_POST['delivery_service'], 's');
         $message = ClearInput::clearInput($_POST['message'], 's');
         try {
             //fetch all from cart
             $cart_products = $this->cart->get_cart($_SESSION['user_id']);
         } catch (Exception $e) {
             $errors[] = $e->getMessage();
         }
         if (!isset($errors) && sizeof($cart_products) > 0) {
             try {
                 //Добавить заказ
                 $this->cart->add_to_order($_SESSION['user_id'], $payment_methot, $delivery_service, $message);
                 //Удалить заказаный товар из корзины
                 $this->cart->remove_all($_SESSION['user_id']);
                 //Получить настройки config.ini
                 $config = parse_ini_file(ROOT . "/app/config/config.ini");
                 //сообщение администратору
                 $body = "Поступил новый заказ";
                 $subject = 'Новый заказ';
                 $emails = $config['admin_email'];
                 try {
                     $mail = new SendEmail($body, $emails, $subject);
                     $result = 'Письмо успешно отправлено';
                 } catch (Exception $e) {
                     $errors[] = $e->getMessage();
                 }
                 //Получить email пользователя
                 $user = new UserModel();
                 $user = $user->getUserByID($_SESSION['user_id']);
                 //Сообщение покупателю
                 $body = "Заказ принят. Ожидайте скоро с вами свяжустся";
                 $subject = 'Заказ';
                 $emails = $user['email'];
                 try {
                     $mail = new SendEmail($body, $emails, $subject);
                     $result = 'Письмо успешно отправлено';
                 } catch (Exception $e) {
                     $errors[] = $e->getMessage();
                 }
                 $result = 'Заказ принят';
             } catch (Exception $e) {
                 $errors[] = $e->getMessage();
             }
         }
         $data = array('title' => 'Заказ', 'result' => isset($result) ? $result : null, 'errors' => isset($errors) ? $errors : null, 'categories' => $this->model->get_categories(), 'products' => $this->model->get_data(), 'is_logged' => Session::is_logged());
         $this->view->render('/cart/result.twig', $data);
     }
 }
 function actionIndex()
 {
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $whom = ClearInput::clearInput($_POST['whom'], 'i+');
         $subject = ClearInput::clearInput($_POST['subject'], 's');
         if (mb_strlen($subject) < 3) {
             $errors[] = 'Тема письма должна содежать более 3 символов';
         }
         $text = ClearInput::clearInput($_POST['text']);
         if (mb_strlen($subject) < 3) {
             $errors[] = 'Текст письма должен содежать более 3 символов';
         }
         //если клиенты, вытаскиваем все email
         if (!isset($errors) && $whom == 0) {
             try {
                 //Получение email всех клиентов
                 $user = new UserModel();
                 $user = $user->getAllusers_by_role($whom);
                 $uc = sizeof($user);
                 for ($i = 0; $i < $uc; ++$i) {
                     $uEmails[] = $user[$i]['email'];
                 }
             } catch (Exception $e) {
                 $errors[] = $e->getMessage();
             }
         }
         //если администраторы, вытаскиваем все email
         if (!isset($errors) && $whom == 2) {
             try {
                 //Получение email всех клиентов
                 $user = new UserModel();
                 $user = $user->getAllusers_by_role($whom);
                 $uc = sizeof($user);
                 for ($i = 0; $i < $uc; ++$i) {
                     $uEmails[] = $user[$i]['email'];
                 }
             } catch (Exception $e) {
                 $errors[] = $e->getMessage();
             }
         }
         //отправка писем
         if (isset($uEmails) && !isset($errors)) {
             try {
                 $mail = new SendEmail($text, $uEmails, $subject);
                 $result = 'Письма успешно отправлены';
             } catch (Exception $e) {
                 $errors[] = $e->getMessage();
             }
         }
     }
     $data = array('title' => 'Рассылка писем', 'is_logged' => Session::is_logged(), 'errors' => isset($errors) ? $errors : null, 'result' => isset($result) ? $result : null, 'user_name' => isset($_SESSION['user_name']) ? $_SESSION['user_name'] : 'Админ');
     $this->view->render('admin/mail/index.twig', $data);
 }
 function actionIndex()
 {
     $managers = $this->model->getManagers();
     /*  Google capcha settings */
     $config = parse_ini_file(ROOT . "/app/config/config.ini");
     $secret = $config['Secret_key'];
     $publicKey = $config['Site_key'];
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $recaptcha = $_POST['g-recaptcha-response'];
         if (!empty($recaptcha)) {
             $google_url = "https://www.google.com/recaptcha/api/siteverify";
             $ip = $_SERVER['REMOTE_ADDR'];
             $url = $google_url . "?secret=" . $secret . "&response=" . $recaptcha . "&remoteip=" . $ip;
             $res = $this->getCurlData($url);
             $res = json_decode($res, true);
             //reCaptcha введена
             if ($res['success']) {
                 $fio = ClearInput::clearInput($_POST['fio'], 's');
                 if (mb_strlen($fio) < 6) {
                     $errors[] = 'Поле ФИО должно иметь больше 6 символов';
                 }
                 if (!($phone = ClearInput::cheackPhone($_POST['tel']))) {
                     $errors[] = 'Телефон должен быть из 10 цифр например:  044 537 02 22';
                 }
                 if (!($email = ClearInput::validate_email($_POST['email']))) {
                     $errors[] = 'Email не валидный';
                 }
                 $message = ClearInput::clearInput($_POST['message'], 's');
                 if (mb_strlen($message) < 6) {
                     $errors[] = 'Сообщение должно иметь больше 6 символов';
                 }
             } else {
                 $errors[] = "Please re-enter your reCAPTCHA.";
             }
         } else {
             $errors[] = "Please re-enter your reCAPTCHA.";
         }
         if (!isset($errors)) {
             $body = "ФИО: {$fio} <br/>\n                      Телефон: {$phone} <br/>\n                      Email: {$email} <br/>\n                      {$message}";
             $subject = 'Форма связаться с нами';
             $emails = $config['admin_email'];
             try {
                 $mail = new SendEmail($body, $emails, $subject);
                 $result = 'Письмо успешно отправлено';
             } catch (Exception $e) {
                 $errors[] = $e->getMessage();
             }
         }
     }
     $products = new ProductsModel();
     $data = array('title' => 'Контакты', 'is_left_slider' => true, 'is_right_slider' => true, 'is_logged' => Session::is_logged(), 'categories' => $products->get_categories(), 'products' => $products->get_data(), 'managers' => $managers, 'errors' => isset($errors) ? $errors : null, 'result' => isset($result) ? $result : null, 'capchaPublicKey' => $publicKey);
     $this->view->render('contact_view.twig', $data);
 }
 function actionIndex()
 {
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         if (isset($_POST['category_id']) || isset($_POST['from']) || isset($_POST['to']) || isset($_POST['brand'])) {
             $category_id = ClearInput::clearInput($_POST['category_id'], 'i+');
             $from = ClearInput::clearInput($_POST['from'], 'i+');
             $to = ClearInput::clearInput($_POST['to'], 'i+');
             if (empty($to)) {
                 $to = 999999;
             }
             $brand = ClearInput::clearInput($_POST['brand'], 's');
             $data = array('title' => 'Продукция', 'is_left_sidebar' => true, 'is_filters_side' => true, 'products' => $this->model->filter_data($category_id, $from, $to, $brand), 'categories' => $this->model->get_categories(), 'is_logged' => Session::is_logged());
             $this->view->render('products/index.twig', $data);
         }
     } else {
         $data = array('title' => 'Продукция', 'is_left_sidebar' => true, 'is_filters_side' => true, 'products' => $this->model->get_data(), 'categories' => $this->model->get_categories(), 'is_logged' => Session::is_logged());
         $this->view->render('products/index.twig', $data);
     }
 }
 function actionIndex()
 {
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $word = ClearInput::clearInput($_POST['search'], 's');
         if (mb_strlen($word) <= 3) {
             $errors[] = 'Введите больше 3-х ссимволов';
         }
         if (!isset($errors)) {
             try {
                 $searched_products = $this->model->search($word);
                 $result = 'найдено ' . count($searched_products);
             } catch (Exception $e) {
                 $errors[] = $e->getMessage();
             }
         }
     }
     $data = array('title' => 'Поиск по сайту', 'is_left_sidebar' => true, 'is_logged' => Session::is_logged(), 'categories' => $this->model->get_categories(), 'products' => $this->model->get_data(), 'searched_products' => isset($searched_products) ? $searched_products : null, 'result' => isset($result) ? $result : null, 'word' => isset($word) ? $word : null, 'errors' => isset($errors) ? $errors : null);
     $this->view->render('search.twig', $data);
 }
 function actionView($id = 1)
 {
     $id = (int) $id[0];
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $new_status = ClearInput::clearInput($_POST['status']);
         $usr_id = ClearInput::clearInput($_POST['usr_id'], 'i+');
         try {
             $this->model->update_order_status_by_id($id, $new_status);
             $user = new UserModel();
             $user = $user->getUserByID($usr_id);
         } catch (Exception $e) {
             $errors[] = $e->getMessage();
         }
         if (!isset($errors)) {
             $body = "Статус заказа изменен на - {$new_status}";
             $subject = 'Статус заказа';
             $emails = $user['email'];
             try {
                 $mail = new SendEmail($body, $emails, $subject);
             } catch (Exception $e) {
                 $errors[] = $e->getMessage();
             }
         }
     }
     try {
         $order = $this->model->get_order_by_id($id);
         $products = $this->model->get_products_from_order_by_id($id);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     if (isset($products)) {
         //count total price cart
         $cpc = sizeof($products);
         for ($i = 0; $i < $cpc; ++$i) {
             $total_count[] = $products[$i]['price'];
         }
         $total_price = array_sum($total_count);
     }
     $data = array('title' => 'Просмотр заказа', 'is_logged' => Session::is_logged(), 'order' => isset($order) ? $order : null, 'errors' => isset($errors) ? $errors : null, 'total_price' => isset($total_price) ? $total_price : null, 'products' => isset($products) ? $products : null, 'user_name' => isset($_SESSION['user_name']) ? $_SESSION['user_name'] : 'Админ');
     $this->view->render('admin/orders/view.twig', $data);
 }