function actionView($id = array('1'))
 {
     $id = (int) $id[0];
     $data = $this->model->get_product($id);
     $data = array('title' => $data['title'], 'product_item' => $data, 'categories' => $this->model->get_categories(), 'products' => $this->model->get_data(), 'is_logged' => Session::is_logged(), 'is_filters_side' => true);
     $this->view->render('products/item.twig', $data);
 }
 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);
 }
 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);
 }
 function __construct()
 {
     parent::__construct();
     if (Session::is_logged() === false or $_SESSION['role'] != 2) {
         header("Location: /auth/index/ ");
     }
 }
Esempio n. 5
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);
 }
 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') {
         $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);
 }
Esempio n. 8
0
 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);
 }
 public function actionIndex()
 {
     if (isset($_POST['submit_export'])) {
         $products = $this->model->get_all_products();
         try {
             $file_path = ROOT . "/tmp/price-list.csv";
             if (!is_dir(ROOT . '/tmp/')) {
                 throw new Exception('Каталог tmp/ не найден.');
             }
             $fp = fopen($file_path, 'w+');
             if (!$fp) {
                 throw new Exception('Невозможно создать файл');
             }
             foreach ($products as $fields) {
                 fputcsv($fp, $fields);
             }
             fclose($fp);
             $this->file_dwonload($file_path);
             unlink($file_path);
             $this->model->delete_all_products();
             $result = 'Товар успешно экспортирован';
         } catch (Exception $e) {
             $errors[] = $e->getMessage();
         }
     }
     if (isset($_POST['submit_import'])) {
         if (is_uploaded_file($_FILES['file']['tmp_name'])) {
         }
         try {
             $handle = fopen($_FILES['file']['tmp_name'], "r");
             while (($data = fgetcsv($handle, 0, ",")) !== FALSE) {
                 $this->model->import_data($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]);
             }
             fclose($handle);
             $result = 'Товар успешно импортирован';
         } catch (Exception $e) {
             $errors[] = 'Не удалось импортировать';
         }
     }
     $data = array('title' => 'ВЫгрузка/загрузка товаров', 'is_logged' => Session::is_logged(), 'result' => isset($result) ? $result : null, 'errors' => isset($errors) ? $errors : null, 'user_name' => isset($_SESSION['user_name']) ? $_SESSION['user_name'] : 'Админ');
     $this->view->render('admin/export/index.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);
 }
 public function actionEdit($id = array('1'))
 {
     $id = (int) $id[0];
     try {
         $user = $this->model->getUserByID($id);
     } catch (Exception $e) {
         $errors[] = $e->getMessage();
     }
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $is_active = $_POST['is_active'];
         $role = $_POST['role'];
         try {
             $result = $this->model->update_user_role_active_by_id($id, $is_active, $role);
             $result = 'Пользователь ' . $user['name'] . ' успешно именен';
         } catch (Exception $e) {
             $errors[] = $e->getMessage();
         }
     }
     $data = array('title' => 'Редактирование пользователей', 'is_logged' => Session::is_logged(), 'user' => $user, 'result' => isset($result) ? $result : null, 'errors' => isset($errors) ? $errors : null, 'user_name' => isset($_SESSION['user_name']) ? $_SESSION['user_name'] : 'Админ');
     $this->view->render('admin/users/edit.twig', $data);
 }
Esempio n. 12
0
 function __construct()
 {
     $this->view = new View();
     $this->session = new Session();
     $this->data['is_logged'] = Session::is_logged();
 }
Esempio n. 13
0
 function actionIndex()
 {
     $data = array('title' => 'Главная страница', 'is_photo_slider' => false, 'is_slider' => true, 'is_right_sidebar' => true, 'categories' => $this->model->get_categories(), 'products' => $this->model->get_data(), 'is_logged' => Session::is_logged());
     $this->view->render('main_view.twig', $data);
 }
Esempio n. 14
0
 function actionIndex()
 {
     $data = array('title' => 'Ошибка 404', 'is_logged' => Session::is_logged());
     $this->view->render('404_view.twig', $data);
 }
Esempio n. 15
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);
     }
 }
Esempio n. 16
0
 function actionIndex()
 {
     $data = array('title' => 'О Компании', 'is_slider' => true, 'is_right_sidebar' => true, 'is_logged' => Session::is_logged(), 'categories' => $this->model->get_categories(), 'products' => $this->model->get_data());
     $this->view->render('about.twig', $data);
 }
Esempio n. 17
0
 function actionIndex()
 {
     $data = array('title' => 'Административная панель', 'is_logged' => Session::is_logged(), 'user_name' => isset($_SESSION['user_name']) ? $_SESSION['user_name'] : 'Админ');
     $this->view->render('admin/index.twig', $data);
 }