Esempio n. 1
0
 function indexAction()
 {
     $date_s = NULL;
     $date_po = NULL;
     if (Arr::get($_GET, 'date_s')) {
         $date_s = strtotime(Arr::get($_GET, 'date_s'));
     }
     if (Arr::get($_GET, 'date_po')) {
         $date_po = strtotime(Arr::get($_GET, 'date_po'));
     }
     $page = (int) Route::param('page') ? (int) Route::param('page') : 1;
     $count = DB::select(array(DB::expr('COUNT(id)'), 'count'))->from($this->tablename);
     if ($date_s) {
         $count->where('created_at', '>=', $date_s);
     }
     if ($date_po) {
         $count->where('created_at', '<=', $date_po + 24 * 60 * 60 - 1);
     }
     $count = $count->count_all();
     $result = DB::select()->from($this->tablename);
     if ($date_s) {
         $result->where('created_at', '>=', $date_s);
     }
     if ($date_po) {
         $result->where('created_at', '<=', $date_po + 24 * 60 * 60 - 1);
     }
     $result = $result->order_by('created_at', 'DESC')->limit($this->limit)->offset(($page - 1) * $this->limit)->find_all();
     $pager = Pager::factory($page, $count, $this->limit)->create();
     $this->_toolbar = Widgets::get('Toolbar/List');
     $this->_content = View::tpl(array('result' => $result, 'tpl_folder' => $this->tpl_folder, 'tablename' => $this->tablename, 'count' => DB::select(array(DB::expr('COUNT(id)'), 'count'))->from($this->tablename)->count_all(), 'pager' => $pager, 'pageName' => 'Лента событий'), $this->tpl_folder . '/Index');
 }
Esempio n. 2
0
 public function innerAction()
 {
     $this->_template = 'CatalogItemsWithoutFilter';
     $page = !(int) Route::param('page') ? 1 : (int) Route::param('page');
     // Check for existance
     $brand = DB::select()->from('brands')->where('alias', '=', Route::param('alias'))->where('status', '=', 1)->as_object()->execute()->current();
     if (!$brand) {
         return Config::error();
     }
     // Seo
     $this->_seo['h1'] = $brand->h1;
     $this->_seo['title'] = $brand->title;
     $this->_seo['keywords'] = $brand->keywords;
     $this->_seo['description'] = $brand->description;
     $this->setBreadcrumbs($brand->name);
     // Get count items per page
     $limit = (int) Arr::get($_GET, 'per_page') ? (int) Arr::get($_GET, 'per_page') : Config::get('limit');
     // Get sort type
     $sort = in_array(Arr::get($_GET, 'sort'), array('name', 'created_at', 'cost')) ? Arr::get($_GET, 'sort') : 'sort';
     $type = in_array(strtolower(Arr::get($_GET, 'type')), array('asc', 'desc')) ? strtoupper(Arr::get($_GET, 'type')) : 'ASC';
     // Get popular items
     $result = DB::select(array('catalog_images.image', 'image'), 'catalog.*')->from('catalog')->join('catalog_images', 'LEFT')->on('catalog_images.catalog_id', '=', 'catalog.id')->on('catalog_images.main', '=', DB::expr('1'))->where('catalog.brand_id', '=', $brand->id)->where('catalog.status', '=', 1)->order_by('catalog.' . $sort, $type)->limit($limit)->offset(($page - 1) * $limit)->as_object()->execute();
     // Set description of the brand to show it above the sort part
     Config::set('brand_description', View::tpl(array('brand' => $brand), 'Brands/Inner'));
     // Count of parent groups
     $count = DB::select(array(DB::expr('COUNT(catalog.id)'), 'count'))->from('catalog')->where('brand_id', '=', $brand->id)->where('status', '=', 1)->as_object()->execute()->current()->count;
     // Generate pagination
     $pager = Pager::factory($page, $count, $limit)->create();
     // Render template
     $this->_content = View::tpl(array('result' => $result, 'pager' => $pager), 'Catalog/ItemsList');
 }
Esempio n. 3
0
 public function indexAction()
 {
     $this->_template = 'CatalogItemsWithoutFilter';
     $page = !(int) Route::param('page') ? 1 : (int) Route::param('page');
     // Seo
     $this->_seo['h1'] = 'Поиск';
     $this->_seo['title'] = 'Поиск';
     $this->_seo['keywords'] = 'Поиск';
     $this->_seo['description'] = 'Поиск';
     $this->setBreadcrumbs('Поиск');
     // Check query
     $query = Arr::get($_GET, 'query');
     if (!$query) {
         return $this->_content = $this->noResults();
     }
     // Get count items per page
     $limit = (int) Arr::get($_GET, 'per_page') ? (int) Arr::get($_GET, 'per_page') : conf::get('limit');
     // Get sort type
     $sort = in_array(Arr::get($_GET, 'sort'), array('name', 'created_at', 'cost')) ? Arr::get($_GET, 'sort') : 'sort';
     $type = in_array(strtolower(Arr::get($_GET, 'type')), array('asc', 'desc')) ? strtoupper(Arr::get($_GET, 'type')) : 'ASC';
     // Get items list
     $result = DB::select(array('catalog_images.image', 'image'), 'catalog.*')->from('catalog')->join('catalog_images', 'LEFT')->on('catalog_images.catalog_id', '=', 'catalog.id')->on('catalog_images.main', '=', DB::expr('1'))->or_where_open()->or_where('catalog.name', 'LIKE', DB::expr('"%' . $query . '%"'))->or_where('catalog.artikul', 'LIKE', DB::expr('"%' . $query . '%"'))->or_where_close()->where('catalog.status', '=', 1)->order_by('catalog.' . $sort, $type)->limit($limit, ($page - 1) * $limit)->as_object()->execute();
     // Check for empty list
     if (!count($result)) {
         return $this->_content = $this->noResults();
     }
     // Count of parent groups
     $count = DB::select(array(DB::expr('COUNT(catalog.id)'), 'count'))->from('catalog')->or_where_open()->or_where('catalog.name', 'LIKE', DB::expr('"%' . $query . '%"'))->or_where('catalog.artikul', 'LIKE', DB::expr('"%' . $query . '%"'))->or_where_close()->where('catalog.status', '=', 1)->as_object()->execute()->current()->count;
     // Generate pagination
     $pager = Pager::factory($page, $count, $limit)->create();
     // Render page
     $this->_content = View::tpl(array('result' => $result, 'pager' => $pager), 'Catalog/ItemsList');
 }
Esempio n. 4
0
 function addAction()
 {
     if ($_POST) {
         $post = $_POST['FORM'];
         $post['status'] = Arr::get($_POST, 'status', 0);
         $post['created_at'] = time();
         if (!trim(Arr::get($post, 'name'))) {
             Message::GetMessage(0, 'Наименование страницы не может быть пустым!');
         } else {
             if (!trim(Arr::get($post, 'url'))) {
                 Message::GetMessage(0, 'Ссылка не может быть пустой!');
             } else {
                 $res = Common::insert($this->tablename, $post)->execute();
                 if ($res) {
                     Message::GetMessage(1, 'Вы успешно добавили данные!');
                     HTTP::redirect('backend/' . Route::controller() . '/add');
                 } else {
                     Message::GetMessage(0, 'Не удалось добавить данные!');
                 }
             }
         }
         $result = Arr::to_object($post);
     } else {
         $result = array();
     }
     $this->_toolbar = Widgets::get('Toolbar/Edit');
     $this->_seo['h1'] = 'Добавление';
     $this->_seo['title'] = 'Добавление';
     $this->setBreadcrumbs('Добавление', 'backend/' . Route::controller() . '/add');
     $this->_content = View::tpl(array('obj' => $result, 'tpl_folder' => $this->tpl_folder, 'tablename' => $this->tablename), $this->tpl_folder . '/Form');
 }
Esempio n. 5
0
 public function setURI()
 {
     $uri = Arr::get($_SERVER, 'REQUEST_URI');
     $uri = explode('?', $uri);
     $this->_get = Arr::get($uri, 1, NULL) ? '?' . Arr::get($uri, 1, NULL) : NULL;
     $this->_uri = Arr::get($uri, 0, NULL);
     if (preg_match('/\\/page\\/' . $this->_current . '/', $this->_uri, $matches)) {
         $this->_uri = str_replace($matches, '', $this->_uri);
     }
 }
Esempio n. 6
0
 public function before()
 {
     parent::before();
     $this->_template = 'Afisha';
     $this->setBreadcrumbs('Афиша', 'afisha');
     // Set parameters for list items by $_GET
     // Get count items per page
     $this->limit = (int) Arr::get($_GET, 'per_page') ? (int) Arr::get($_GET, 'per_page') : Config::get('limit');
     // Get sort type
     $this->sort = 'afisha.' . (in_array(Arr::get($_GET, 'sort'), array('name', 'created_at', 'cost')) ? Arr::get($_GET, 'sort') : 'id');
     $this->type = in_array(strtolower(Arr::get($_GET, 'type')), array('asc', 'desc')) ? strtoupper(Arr::get($_GET, 'type')) : 'DESC';
 }
Esempio n. 7
0
 /**
  *  Delete image
  *  @param string $mainFolder - name of th block in Config/images.php
  *  @param string $filename   - name of the file we delete
  *  @return bool
  */
 public static function deleteImage($mainFolder, $filename)
 {
     $need = Config::get('images.' . $mainFolder);
     if (!$need) {
         return false;
     }
     foreach ($need as $one) {
         $file = HOST . HTML::media('/images/' . $mainFolder . '/' . Arr::get($one, 'path') . '/' . $filename);
         @unlink($file);
     }
     return true;
 }
Esempio n. 8
0
 public static function valid($post = array())
 {
     if (Route::param('id') && Arr::get($post, 'email')) {
         if (DB::select(array(DB::expr('COUNT(id)'), 'count'))->from('users')->where('email', '=', Arr::get($post, 'email'))->where('id', '!=', Route::param('id'))->count_all()) {
             Message::GetMessage(0, 'Указанный E-Mail уже занят!');
             return FALSE;
         }
     }
     if (Arr::get($_POST, 'password') and mb_strlen(Arr::get($_POST, 'password'), 'UTF-8') < Config::get('main.password_min_length')) {
         Message::GetMessage(0, 'Пароль должен быть не короче ' . Config::get('main.password_min_length') . ' символов!');
         return FALSE;
     }
     return parent::valid($post);
 }
Esempio n. 9
0
 public function action_edit()
 {
     $this->title = "Редактирование галереи";
     $id = $this->params[2];
     if (isset($_POST['update'])) {
         $fields = Arr::extract($_POST, ['name', 'comment']);
         if ($this->gallery->edit($id, $fields) !== false) {
             header('Location: /' . ADMIN_URL . '/gallery/all');
             exit;
         }
     } else {
         $fields = $this->gallery->one($id);
     }
     $this->content = View::template('gallery/v_edit.php', ['fields' => $fields]);
 }
Esempio n. 10
0
 public function moreAffisheAction()
 {
     $page = (int) Arr::get($_POST, 'page');
     if (!isset($page)) {
         $this->error('Ошибка загрузки');
     }
     // list posts
     if (isset($_SESSION['idCity'])) {
         // select places id
         $places = DB::select('id')->from('places')->where('city_id', '=', $_SESSION['idCity'])->where('status', '=', DB::expr(1))->as_object()->execute();
         $ids = array();
         foreach ($places as $key => $value) {
             $ids[] = $value->id;
         }
         if (count($ids) == 0) {
             $ids[] = 0;
         }
     }
     $dbObj = DB::select('afisha.*', array('places.name', 'p_name'), array(DB::expr('MIN(prices.price)'), 'p_from'), array(DB::expr('MAX(prices.price)'), 'p_to'))->from('afisha')->join('places', 'left outer')->on('afisha.place_id', '=', 'places.id')->on('places.status', '=', DB::expr(1))->join('prices', 'left outer')->on('afisha.id', '=', 'prices.afisha_id')->where('afisha.status', '=', 1)->where('afisha.event_date', '>', DB::expr(time()));
     if (isset($_SESSION['idCity'])) {
         $dbObj->where_open()->where('afisha.place_id', 'IN', $ids)->or_where('afisha.city_id', '=', $_SESSION['idCity'])->where_close();
     }
     $result = $dbObj->group_by('afisha.id')->order_by('afisha.event_date')->limit(Config::get('limit'))->offset(($page - 1) * (int) Config::get('limit'))->execute()->as_array();
     foreach ($result as $key => $value) {
         $result[$key]['p_name'] = Afisha\Models\Afisha::getItemPlace($value, true);
         $result[$key]['cost'] = Afisha\Models\Afisha::getItemPrice($value, true);
         $result[$key]['event_date'] = date('j', $value['event_date']) . ' ' . Dates::month(date('n', $value['event_date'])) . ' ' . date('Y', $value['event_date']);
         if (!is_file(HOST . HTML::media('images/afisha/medium/' . $value['image']))) {
             $result[$key]['image'] = false;
         }
     }
     // Count of all posts
     $dbObj = DB::select(array(DB::expr('COUNT(afisha.id)'), 'count'))->from('afisha');
     if (isset($_SESSION['idCity'])) {
         $dbObj->where_open()->where('afisha.place_id', 'IN', $ids)->or_where('afisha.city_id', '=', $_SESSION['idCity'])->where_close();
     }
     $count = $dbObj->where('afisha.status', '=', 1)->where('afisha.event_date', '>', DB::expr(time()))->as_object()->execute()->current()->count;
     // Set view button more load
     $showBut = true;
     if ($count <= Config::get('limit') * $page) {
         $showBut = false;
     }
     // Render template
     $this->success(array('result' => $result, 'showBut' => $showBut));
 }
Esempio n. 11
0
 public function action_edit()
 {
     $this->title = "Редактирование привилегии";
     $errors = [];
     $id = $this->params[2];
     if (isset($_POST['update'])) {
         $fields = Arr::extract($_POST, ['name', 'description']);
         if ($this->priv->edit($id, $fields) !== false) {
             header('Location: /' . ADMIN_URL . '/priv/all');
             exit;
         } else {
             $errors = $this->priv->errors();
         }
     } else {
         $fields = $this->priv->one($id);
     }
     $this->content = View::template('priv/v_edit.php', ['fields' => $fields, 'errors' => $errors]);
 }
Esempio n. 12
0
 private function seo()
 {
     if (!Config::get('error')) {
         $seo = DB::select('h1', 'title', 'keywords', 'description', 'text')->from('seo_links')->where('status', '=', 1)->where('link', '=', Arr::get($_SERVER, 'REQUEST_URI'))->as_object()->execute()->current();
         if ($seo) {
             $this->_seo['h1'] = $seo->h1;
             $this->_seo['title'] = $seo->title;
             $this->_seo['keywords'] = $seo->keywords;
             $this->_seo['description'] = $seo->description;
             $this->_seo['seo_text'] = $seo->text;
         }
     } else {
         $this->_seo['h1'] = 'Ошибка 404! Страница не найдена';
         $this->_seo['title'] = 'Ошибка 404! Страница не найдена';
         $this->_seo['keywords'] = 'Ошибка 404! Страница не найдена';
         $this->_seo['description'] = 'Ошибка 404! Страница не найдена';
         $this->_seo['seo_text'] = NULL;
     }
 }
Esempio n. 13
0
 function innerAction()
 {
     if (User::info()->role_id != 2 && User::info()->id != Route::param('id')) {
         $this->no_access();
     }
     //            Select current user
     $organizer = Model::getOrganizerById(Route::param('id'), 1);
     if (!$organizer) {
         $this->no_access();
     }
     $this->_seo['h1'] = 'Отчет организатора: ' . $organizer->name;
     $this->_seo['title'] = 'Отчет организатора: ' . $organizer->name;
     $this->setBreadcrumbs('Отчет организатора: ' . $organizer->name);
     //            Set filter vars
     $date_s = NULL;
     $date_po = NULL;
     $eventId = null;
     $status = null;
     if (Arr::get($_GET, 'date_s')) {
         $date_s = strtotime(Arr::get($_GET, 'date_s'));
     }
     if (Arr::get($_GET, 'date_po')) {
         $date_po = strtotime(Arr::get($_GET, 'date_po'));
     }
     if (Arr::get($_GET, 'event') != 0) {
         $eventId = Arr::get($_GET, 'event');
     }
     if (Arr::get($_GET, 'status') != 'null') {
         $status = Arr::get($_GET, 'status');
     }
     $filter = array('date_s' => $date_s, 'date_po' => $date_po, 'status' => $status, 'event_id' => $eventId, 'organizer_id' => $organizer->id, 'order' => array('created_at', 'DESC'));
     $posters = Model::getPosters($filter);
     //            Make array with all need data
     $result = array();
     foreach ($posters as $poster) {
         $result[$poster->id]['poster'] = $poster;
         $result[$poster->id]['detailed'] = Model::getDetailed($poster);
     }
     //            Rendering
     $this->_content = View::tpl(array('result' => $result, 'pay_statuses' => $this->pay_statuses, 'events' => DB::select()->from('afisha')->where('place_id', 'IS NOT', null)->where('organizer_id', '=', $organizer->id)->find_all(), 'tpl_folder' => $this->tpl_folder), $this->tpl_folder . '/Inner');
 }
Esempio n. 14
0
 public function action_edit()
 {
     $this->title = 'Редактировать страницу';
     $id = $this->params[2];
     $errors = [];
     if (isset($_POST['update'])) {
         $fields = Arr::extract($_POST, ['id_parent', 'url', 'title', 'content', 'base_template', 'inner_template']);
         if ($this->model->edit($id, $fields)) {
             header('Location: /' . ADMIN_URL . '/page/');
             exit;
         } else {
             $errors = $this->model->errors();
         }
     } else {
         $fields = $this->model->one($this->params[2]);
     }
     $this->scripts[] = 'ckeditor/ckeditor';
     $this->scripts[] = 'url_page';
     $this->scripts[] = 'ck_init';
     $this->content = View::template('page/v_edit.php', ['fields' => $fields, 'errors' => $errors, 'pages' => $this->model->tree(), 'base_templates' => Template::all('base'), 'inner_templates' => Template::all('inner')]);
 }
Esempio n. 15
0
 function editAction()
 {
     if ($_POST) {
         $post = $_POST['FORM'];
         $post['status'] = Arr::get($_POST, 'status', 0);
         $res = Common::update($this->tablename, $post)->where('id', '=', Arr::get($_POST, 'id'))->execute();
         if ($res) {
             Message::GetMessage(1, 'Вы успешно изменили данные!');
             HTTP::redirect('backend/' . Route::controller() . '/' . Route::action() . '/' . Route::param('id'));
         } else {
             Message::GetMessage(0, 'Не удалось изменить данные!');
         }
         $post['id'] = Arr::get($_POST, 'id');
         $result = Arr::to_object($post);
     } else {
         $result = DB::select()->from($this->tablename)->where('id', '=', (int) Route::param('id'))->find();
     }
     $this->_toolbar = Widgets::get('Toolbar/Edit');
     $this->_seo['h1'] = 'Редактирование';
     $this->_seo['title'] = 'Редактирование';
     $this->setBreadcrumbs('Редактирование', 'backend/' . Route::controller() . '/edit/' . (int) Route::param('id'));
     $this->_content = View::tpl(array('obj' => $result, 'tpl_folder' => $this->tpl_folder, 'tablename' => $this->tablename), $this->tpl_folder . '/Form');
 }
Esempio n. 16
0
 /**
  * @return array
  */
 public function execute()
 {
     $r = new \Core\Validation\Rules();
     foreach ($this->_rules as $field => $rules) {
         if (is_array($rules) && count($rules)) {
             foreach ($rules as $rule) {
                 $method = Arr::get($rule, 'key');
                 if (!method_exists($r, $method)) {
                     continue;
                 }
                 if (in_array($rule['key'], array('regex', 'min_length', 'max_length'))) {
                     $success = $r::$method(trim(Arr::get($this->_data, $field)), Arr::get($rule, 'value'));
                 } else {
                     $success = $r::$method(trim(Arr::get($this->_data, $field)));
                 }
                 if (!$success) {
                     $this->_errors[] = $rule['error'];
                 }
             }
         }
     }
     return $this->_errors;
 }
Esempio n. 17
0
 function editAction()
 {
     if (!User::admin()) {
         HTTP::redirect('backend/' . Route::controller() . '/login');
     }
     $user = User::info();
     if ($_POST) {
         $post = $_POST;
         if (strlen(Arr::get($post, 'password')) < $this->password_length or strlen(Arr::get($post, 'new_password')) < $this->password_length or strlen(Arr::get($post, 'confirm_password')) < $this->password_length or !User::factory()->check_password(Arr::get($post, 'password'), $user->password) or Arr::get($post, 'new_password') != Arr::get($post, 'confirm_password')) {
             Message::GetMessage(0, 'Вы что-то напутали с паролями!');
             HTTP::redirect('backend/' . Route::controller() . '/edit');
         }
         if (!strlen(trim(Arr::get($post, 'name')))) {
             Message::GetMessage(0, 'Имя не может быть пустым!');
             HTTP::redirect('backend/' . Route::controller() . '/edit');
         }
         if (!strlen(trim(Arr::get($post, 'login')))) {
             Message::GetMessage(0, 'Логин не может быть пустым!');
             HTTP::redirect('backend/' . Route::controller() . '/edit');
         }
         $count = DB::select(array(DB::expr('COUNT(id)'), 'count'))->from('users')->where('id', '!=', $user->id)->where('login', '=', Arr::get($post, 'login'))->count_all();
         if ($count) {
             Message::GetMessage(0, 'Пользователь с таким логином уже существует!');
             HTTP::redirect('backend/' . Route::controller() . '/edit');
         }
         $data = array('name' => Arr::get($post, 'name'), 'login' => Arr::get($post, 'login'), 'password' => User::factory()->hash_password(Arr::get($post, 'new_password')));
         Common::factory('users')->update($data, $user->id);
         Message::GetMessage(1, 'Вы успешно изменили данные!');
         HTTP::redirect('backend/' . Route::controller() . '/edit');
     }
     $this->_toolbar = Widgets::get('Toolbar/EditSaveOnly');
     $this->_seo['h1'] = 'Мой профиль';
     $this->_seo['title'] = 'Редактирование личных данных';
     $this->setBreadcrumbs('Мой профиль', 'backend/' . Route::controller() . '/' . Route::action());
     $this->_content = View::tpl(array('obj' => $user), 'Auth/Edit');
 }
Esempio n. 18
0
 function after_paymentAction()
 {
     if ($_POST) {
         $post = $_POST['FORM'];
         $post['status'] = Arr::get($_POST, 'status', 0);
         $res = Common::update($this->tablename, $post)->where('id', '=', Arr::get($_POST, 'id'))->execute();
         if ($res) {
             Message::GetMessage(1, 'Вы успешно изменили данные!');
             HTTP::redirect('backend/' . Route::controller() . '/' . Route::action());
         } else {
             Message::GetMessage(0, 'Не удалось изменить данные!');
         }
         $post['id'] = Arr::get($_POST, 'id');
         $result = Arr::to_object($post);
     } else {
         $result = DB::select()->from($this->tablename)->where('id', '=', 6)->find();
     }
     $this->_seo['h1'] = 'Управление страницей после оплаты';
     $this->_seo['title'] = 'Управление страницей после оплаты';
     $this->setBreadcrumbs('Управление страницей после оплаты', 'backend/' . Route::controller() . '/index');
     $this->_content = View::tpl(array('obj' => $result, 'tpl_folder' => $this->tpl_folder, 'tablename' => $this->tablename), $this->tpl_folder . '/Form');
 }
Esempio n. 19
0
 public function extendBroneAction()
 {
     $order = (int) Arr::get($_POST, 'order');
     $date = Arr::get($_POST, 'date');
     $time = Arr::get($_POST, 'time');
     if (!$order or !$date or !$time) {
         die(json_encode(array('success' => false, 'message' => 'Ошибка получения данных')));
     }
     $tS = strtotime($date . ' ' . $time . ':00');
     $newTS = $tS - Config::get('reserved_days') * 24 * 60 * 60;
     \Core\Common::update('afisha_orders', array('created_at' => $newTS))->where('id', '=', $order)->execute();
     // Get current order
     $afisha = DB::select()->from('afisha_orders')->where('id', '=', $order)->find();
     $prices = DB::select('id')->from('prices')->where('afisha_id', '=', $afisha->afisha_id)->find_all();
     $pricesArr = array();
     if ($prices->count()) {
         foreach ($prices as $key => $value) {
             $pricesArr[] = $value->id;
         }
         \Core\Common::update('seats', array('reserved_at' => $newTS))->where('view_key', 'IN', array_filter(explode(',', $afisha->seats_keys)))->where('price_id', 'IN', $pricesArr)->execute();
     }
     die(json_encode(array('success' => true, 'message' => 'Данные сохранены', 'reload' => true)));
 }
Esempio n. 20
0
 function addAction()
 {
     $itemSizes = Arr::get($_POST, 'SIZES', array());
     $specArray = Arr::get($_POST, 'SPEC', array());
     if ($_POST) {
         $post = $_POST['FORM'];
         // Set default settings for some fields
         $post['status'] = Arr::get($_POST, 'status', 0);
         $post['new'] = Arr::get($_POST, 'new', 0);
         $post['top'] = Arr::get($_POST, 'top', 0);
         $post['sale'] = Arr::get($_POST, 'sale', 0);
         $post['available'] = Arr::get($_POST, 'available', 0);
         $post['sex'] = Arr::get($_POST, 'sex', 0);
         $post['cost'] = (int) Arr::get($post, 'cost', 0);
         $post['cost_old'] = (int) Arr::get($post, 'cost_old', 0);
         $post['created_at'] = time();
         if (Arr::get($post, 'new')) {
             $post['new_from'] = time();
         }
         // Check form for rude errors
         if (!Arr::get($post, 'alias')) {
             Message::GetMessage(0, 'Алиас не может быть пустым!');
         } else {
             if (!Arr::get($post, 'name')) {
                 Message::GetMessage(0, 'Название не может быть пустым!');
             } else {
                 if (!Arr::get($post, 'cost')) {
                     Message::GetMessage(0, 'Цена не может быть пустой!');
                 } else {
                     $post['alias'] = Common::getUniqueAlias($this->tablename, Arr::get($post, 'alias'));
                     $res = Common::insert($this->tablename, $post)->execute();
                     if ($res) {
                         $id = $res[0];
                         foreach ($itemSizes as $size_id) {
                             DB::insert('catalog_sizes', array('catalog_id', 'size_id'))->values(array($id, $size_id))->execute();
                         }
                         foreach ($specArray as $key => $value) {
                             if (is_array($value)) {
                                 foreach ($value as $specification_value_id) {
                                     DB::insert('catalog_specifications_values', array('catalog_id', 'specification_value_id', 'specification_id'))->values(array($id, $specification_value_id, $key))->execute();
                                 }
                             } else {
                                 if ($value) {
                                     DB::insert('catalog_specifications_values', array('catalog_id', 'specification_value_id', 'specification_id'))->values(array($id, $value, $key))->execute();
                                 }
                             }
                         }
                         Message::GetMessage(1, 'Вы успешно добавили данные!');
                         HTTP::redirect('/backend/' . Route::controller() . '/edit/' . $id);
                     } else {
                         Message::GetMessage(0, 'Не удалось добавить данные!');
                     }
                 }
             }
         }
         $result = Arr::to_object($post);
         $parent_id = $result->parent_id;
         $models = DB::select()->from('models')->where('brand_id', '=', $result->brand_id)->find_all();
     } else {
         $result = array();
         $models = array();
         $parent_id = 0;
     }
     $this->_toolbar = Widgets::get('Toolbar/Edit');
     $this->_seo['h1'] = 'Добавление';
     $this->_seo['title'] = 'Добавление';
     $this->setBreadcrumbs('Добавление', 'backend/' . Route::controller() . '/add');
     $brands = DB::select('brands.*')->from('brands')->join('catalog_tree_brands')->on('catalog_tree_brands.brand_id', '=', 'brands.id')->where('catalog_tree_brands.catalog_tree_id', '=', $parent_id)->order_by('brands.name')->find_all();
     $sizes = DB::select('sizes.*')->from('sizes')->join('catalog_tree_sizes')->on('catalog_tree_sizes.size_id', '=', 'sizes.id')->where('catalog_tree_sizes.catalog_tree_id', '=', $parent_id)->order_by('sizes.name')->find_all();
     $specifications = DB::select('specifications.*')->from('specifications')->join('catalog_tree_specifications')->on('catalog_tree_specifications.specification_id', '=', 'specifications.id')->where('catalog_tree_specifications.catalog_tree_id', '=', $result->parent_id)->order_by('specifications.name')->find_all();
     $arr = array(0);
     foreach ($specifications as $s) {
         $arr[] = $s->id;
     }
     $specValues = DB::select()->from('specifications_values')->where('specification_id', 'IN', $arr)->order_by('name')->find_all();
     $arr = array();
     foreach ($specValues as $obj) {
         $arr[$obj->specification_id][] = $obj;
     }
     $this->_content = View::tpl(array('obj' => $result, 'tpl_folder' => $this->tpl_folder, 'tablename' => $this->tablename, 'tree' => Support::getSelectOptions('Catalog/Select', 'catalog_tree', $result->parent_id), 'brands' => $brands, 'sizes' => $sizes, 'models' => $models, 'itemSizes' => $itemSizes, 'specifications' => $specifications, 'specValues' => $arr, 'specArray' => $specArray), $this->tpl_folder . '/Form');
 }
Esempio n. 21
0
 public static function generateLink($key, $value = NULL, $fakeLink = NULL)
 {
     $link = $fakeLink ? $fakeLink : Arr::get($_SERVER, 'REQUEST_URI');
     $uri = explode('?', $link);
     $__get = array();
     if (count($uri) > 1) {
         $arr = explode('&', $uri[1]);
         foreach ($arr as $_a) {
             $g = urldecode($_a);
             $g = strip_tags($g);
             $g = stripslashes($g);
             $g = trim($g);
             $___get = explode('=', $g);
             $__get[$___get[0]] = $___get[1];
         }
     }
     if ($value === NULL) {
         if (!isset($__get[$key])) {
             return $link;
         }
         $arr = explode('&', $uri[1]);
         $get = array();
         foreach ($arr as $el) {
             $h = explode('=', $el);
             if ($key != $h[0]) {
                 $get[] = $h[0] . '=' . $h[1];
             }
         }
         $uri[1] = implode('&', $get);
         if ($uri[1]) {
             return $uri[0] . '?' . $uri[1];
         }
         return $uri[0];
     }
     if (!isset($__get[$key])) {
         if (isset($uri[1])) {
             return Arr::get($uri, 0) . '?' . Arr::get($uri, 1) . '&' . $key . '=' . $value;
         }
         return Arr::get($uri, 0) . '?' . $key . '=' . $value;
     }
     if (Arr::get($__get, $key) == $value) {
         return $link;
     }
     $arr = explode('&', $uri[1]);
     $get = array();
     foreach ($arr as $el) {
         $h = explode('=', $el);
         if ($key == $h[0]) {
             $get[] = $key . '=' . $value;
         } else {
             $get[] = $h[0] . '=' . $h[1];
         }
     }
     $uri[1] = implode('&', $get);
     return $uri[0] . '?' . $uri[1];
 }
Esempio n. 22
0
 function sendAction()
 {
     $emails = array();
     $list = array();
     if ($_POST) {
         $post = $_POST['FORM'];
         $subscribers = DB::select('email', 'hash', 'name')->from('subscribers')->where('status', '=', 1)->find_all();
         foreach ($subscribers as $obj) {
             if (filter_var($obj->email, FILTER_VALIDATE_EMAIL) and !in_array($obj->email, $emails)) {
                 $emails[] = $obj;
                 $list[] = $obj->email;
             }
         }
         if (!trim(Arr::get($post, 'subject'))) {
             Message::GetMessage(0, 'Поле "Тема" не может быть пустым!');
         } else {
             if (!trim(Arr::get($post, 'text'))) {
                 Message::GetMessage(0, 'Поле "Содержание" не может быть пустым!');
             } else {
                 if (empty($emails)) {
                     Message::GetMessage(0, 'Список выбраных E-Mail для рассылки пуст!');
                 } else {
                     $data = $post;
                     $data['count_emails'] = count($list);
                     $data['emails'] = implode(';', $list);
                     $res = Common::insert($this->tablename, $data)->execute();
                     foreach ($emails as $obj) {
                         $link = 'http://' . Arr::get($_SERVER, 'HTTP_HOST') . '/unsubscribe/hash/' . $obj->hash;
                         $from = array('{{unsubscribe}}', '{{user_name}}', '{{site}}', '{{date}}');
                         $to = array($link, $obj->name, Arr::get($_SERVER, 'HTTP_HOST'), date('d.m.Y'));
                         $message = str_replace($from, $to, Arr::get($post, 'text'));
                         $subject = str_replace($from, $to, Arr::get($post, 'subject'));
                         if (!Config::get('main.cron')) {
                             Email::send($subject, $message, $obj->email);
                         } else {
                             $data = array('subject' => $subject, 'text' => $message, 'email' => $obj->email);
                             $res = Common::insert(Config::get('main.tableCron'), $data)->execute();
                         }
                     }
                     Message::GetMessage(1, 'Письмо успешно разослано ' . $data['count_emails'] . ' подписчикам!');
                     HTTP::redirect('backend/' . Route::controller() . '/' . Route::action());
                 }
             }
         }
         $result = Arr::to_object($post);
     } else {
         $result = Arr::to_object(array('subscribers' => 1));
     }
     $this->_toolbar = Widgets::get('Toolbar/Subscribe');
     $this->_seo['h1'] = 'Отправка письма';
     $this->_seo['title'] = 'Отправка письма';
     $this->setBreadcrumbs('Отправка письма', 'backend/' . Route::controller() . '/add');
     $this->_content = View::tpl(array('obj' => $result, 'tpl_folder' => $this->tpl_folder, 'tablename' => $this->tablename), $this->tpl_folder . '/Send');
 }
Esempio n. 23
0
 public function sidebarBackend($array = array())
 {
     $result = DB::select()->from('menu')->where('status', '=', 1)->order_by('sort')->as_object()->execute();
     $arr = array();
     if (User::god()) {
         foreach ($result as $obj) {
             $arr[$obj->id_parent][] = $obj;
         }
     } else {
         $access = User::access();
         $_arr = array();
         foreach ($result as $obj) {
             $r = explode('/', trim($obj->link, '/'));
             if ($r[0] == 'seo') {
                 array_splice($r, 0, 1);
             }
             if (!$obj->link || Arr::get($access, $r[0], 'no') == 'edit' || Arr::get($access, $r[0]) == 'view' && Arr::get($r, 1) == 'index') {
                 $_arr[$obj->id_parent][] = $obj;
             } else {
                 if (!$obj->link || Arr::get($access, str_replace('seo_', '', $r[0]), 'no') == 'edit' || Arr::get($access, str_replace('seo_', '', $r[0])) == 'view' && Arr::get($r, 1) == 'index') {
                     $_arr[$obj->id_parent][] = $obj;
                 }
             }
         }
         $arr = array();
         foreach ($_arr[0] as $el) {
             if ($el->link || count(Arr::get($_arr, $el->id, array()))) {
                 $arr[0][] = $el;
             }
         }
         foreach ($_arr as $key => $el) {
             if ($key != 0) {
                 $arr[$key] = $el;
             }
         }
     }
     return $this->_data['sidebar'] = View::widget(array('result' => $arr, 'counts' => array()), 'Sidebar');
 }
Esempio n. 24
0
 /**
  *      Delete goods from the cart
  *      @param $catalog_id - goods ID
  */
 public function delete($catalog_id, $size_id)
 {
     if (Arr::get($this->_cart, $catalog_id . '-' . $size_id, false)) {
         unset($this->_cart[$catalog_id . '-' . $size_id]);
         DB::delete('carts_items')->where("catalog_id", "=", $catalog_id)->where("size_id", "=", $size_id)->where("cart_id", "=", $this->_cart_id)->execute();
         $this->recount();
     }
 }
Esempio n. 25
0
 function addAction()
 {
     if ($_POST) {
         $post = $_POST['FORM'];
         $post['status'] = Arr::get($_POST, 'status', 0);
         $post['created_at'] = time();
         if (!trim(Arr::get($post, 'name'))) {
             Message::GetMessage(0, 'Наименование страницы не может быть пустым!');
         } else {
             if (!trim(Arr::get($post, 'alias'))) {
                 Message::GetMessage(0, 'Алиас не может быть пустым!');
             } else {
                 if (!trim(Arr::get($post, 'brand_id'))) {
                     Message::GetMessage(0, 'Модель не может существовать без бренда!');
                 } else {
                     $post['alias'] = Common::getUniqueAlias($this->tablename, Arr::get($post, 'alias'));
                     $res = Common::insert($this->tablename, $post)->execute();
                     if ($res) {
                         Message::GetMessage(1, 'Вы успешно добавили данные!');
                         HTTP::redirect('backend/' . Route::controller() . '/add');
                     } else {
                         Message::GetMessage(0, 'Не удалось добавить данные!');
                     }
                 }
             }
         }
         $result = Arr::to_object($post);
     } else {
         $result = array();
     }
     $this->_toolbar = Widgets::get('Toolbar/Edit');
     $this->_seo['h1'] = 'Добавление';
     $this->_seo['title'] = 'Добавление';
     $this->setBreadcrumbs('Добавление', 'backend/' . Route::controller() . '/add');
     $this->_content = View::tpl(array('obj' => $result, 'tpl_folder' => $this->tpl_folder, 'tablename' => $this->tablename, 'brands' => DB::select()->from('brands')->order_by('name')->find_all()), $this->tpl_folder . '/Form');
 }
Esempio n. 26
0
 public static function sendOrderMessageUser(array $data)
 {
     $ip = \Core\System::getRealIP();
     $mail = DB::select()->from('mail_templates')->where('status', '=', 1)->where('id', '=', 12)->find();
     if (count($mail) == 0) {
         return false;
     }
     $dataTpl = \Core\View::tpl(array('order' => $data['order'], 'order_text' => $data['order_text']), 'Orders/Email');
     $from = array('{{site}}', '{{order_number}}', '{{link_user}}', '{{data}}', '{{ip}}', '{{date}}', '{{event_name}}');
     $to = array(Arr::get($_SERVER, 'HTTP_HOST'), $data['id_order'], '<a href="http://' . Arr::get($_SERVER, 'HTTP_HOST') . '/payment/' . $data['id_order'] . '">Ссылка</a>', $dataTpl, $ip, date('d.m.Y H:i'), $data['order']['event_name']);
     $subject = str_replace($from, $to, $mail->subject);
     $text = str_replace($from, $to, $mail->text);
     Email::send($subject, $text, $data['order']['email']);
 }
Esempio n. 27
0
 public function action_edit()
 {
     $this->title = 'Редактировать пользователя';
     $id = $this->params[2];
     $errors = [];
     $roles = $this->role->all();
     if (isset($_POST['update'])) {
         $fields = Arr::extract($_POST, ['name', 'email', 'id_role', 'role', 'datebirth']);
         if ($this->user->edit($id, $fields, $_FILES['file']) !== false) {
             //die();
             header('Location: /' . ADMIN_URL . '/user/one/' . $id);
             exit;
         }
     } else {
         $fields = $this->user->one($id);
         $errors = $this->user->errors();
     }
     $this->content = View::template('user/v_edit.php', ['fields' => $fields, 'roles' => $roles, 'errors' => $errors]);
 }
Esempio n. 28
0
 function innerAction()
 {
     if (User::info()->role_id != 2 && User::info()->id != Route::param('id') && User::info()->see_all_cashier_stat == 0) {
         $this->no_access();
     }
     //            Set filter vars
     $date_s = NULL;
     $date_po = NULL;
     $status = NULL;
     $eventId = null;
     $creatorId = null;
     if (Arr::get($_GET, 'date_s')) {
         $date_s = strtotime(Arr::get($_GET, 'date_s'));
     }
     if (Arr::get($_GET, 'date_po')) {
         $date_po = strtotime(Arr::get($_GET, 'date_po'));
     }
     if (isset($this->pay_statuses[Arr::get($_GET, 'status')])) {
         $status = Arr::get($_GET, 'status', 1);
     }
     if (Arr::get($_GET, 'status') == 'null') {
         $status = 'null';
     }
     if (Arr::get($_GET, 'event') != 0) {
         $eventId = Arr::get($_GET, 'event');
     }
     if (Arr::get($_GET, 'creator_id') != 0) {
         $creatorId = Arr::get($_GET, 'creator_id');
     }
     //            Select current user
     $cassier = DB::select()->from($this->tablename)->where($this->tablename . '.id', '=', Route::param('id'))->find();
     $this->_seo['h1'] = 'Статистика по ' . $cassier->name;
     $this->_seo['title'] = 'Статистика по ' . $cassier->name;
     $this->setBreadcrumbs('Статистика по ' . $cassier->name);
     $ordersQuery = DB::select()->from('afisha_orders')->where('payer_id', '=', $cassier->id);
     $this->setFilter($ordersQuery, $date_s, $date_po, $status, $eventId, $creatorId, 'afisha_orders');
     $orders = $ordersQuery->order_by('created_at', 'DESC')->find_all();
     //            Make array with all need data
     $afishaGroups = array();
     foreach ($orders as $order) {
         $afisha = DB::select()->from('afisha')->where('id', '=', $order->afisha_id)->find();
         $afishaGroups[$order->afisha_id]['afisha'] = $afisha;
         $afishaGroups[$order->afisha_id]['orders'][$order->id] = $order;
     }
     //            Rendering
     $this->_content = View::tpl(array('afishaGroups' => $afishaGroups, 'pay_statuses' => $this->pay_statuses, 'events' => DB::select()->from('afisha')->where('place_id', 'IS NOT', null)->find_all(), 'creators' => array(), 'pager' => '', 'tpl_folder' => $this->tpl_folder), $this->tpl_folder . '/Inner');
 }
Esempio n. 29
0
 function printTicketAction()
 {
     if (User::get_access_for_controller('afisha_brone') != 'edit') {
         $this->no_access();
     }
     $key = Route::param('key');
     $keys = (array) explode(',', $key);
     if (count($keys) == 0) {
         Message::GetMessage(0, 'Места не выбраны!');
         HTTP::redirect('backend/afisha/index');
     }
     $printType = Route::param('printType') ? Route::param('printType') : 'base';
     $afisha = DB::select('afisha.*', array('places.name', 'place'), 'places.filename', 'places.address', 'places.city_id')->from('afisha')->join('places')->on('afisha.place_id', '=', 'places.id')->where('afisha.id', '=', (int) Route::param('id'))->find();
     if (!$afisha) {
         return Config::error();
     }
     $city = DB::select()->from('cities')->where('id', '=', $afisha->city_id)->find();
     $seatStr = array();
     $termoSeatStr = array();
     try {
         $dom = Map::factory()->loadFile($afisha->filename)->getDomInstance();
         $gTag = $dom->getElementsByTagName('g');
         foreach ($gTag as $el) {
             $id = $el->getAttribute('id');
             if (in_array($id, $keys)) {
                 if ($el->parentNode->hasAttribute('data-plase')) {
                     $originalPlace = $el->parentNode->getAttribute('data-plase');
                 } elseif ($el->parentNode->parentNode->hasAttribute('data-plase')) {
                     $originalPlace = $el->parentNode->parentNode->getAttribute('data-plase');
                 }
                 if ($originalPlace) {
                     $place = $originalPlace;
                     $place = str_replace(array('места', 'Места'), 'место', $place);
                     $place = str_replace('(левая сторона)', '(лев. сторона)', $place);
                     $place = str_replace('(правая сторона)', '(пр. сторона)', $place);
                     $place = str_replace(',', '<br />', $place);
                     $place = str_replace('ряд', 'ряд:', $place);
                     $seatStr[$id] = $place;
                     $dataInit = json_decode($el->getAttribute('data-init'));
                     $seatStr[$id] .= $dataInit->seat;
                     //                          For termo print
                     preg_match('#^(.*)?, ряд ([0-9]+)#', $originalPlace, $matches);
                     $termoSeatStr[$id]['block'] = $matches[1];
                     $termoSeatStr[$id]['block'] = str_replace('(левая сторона)', '(лев. сторона)', $termoSeatStr[$id]['block']);
                     $termoSeatStr[$id]['block'] = str_replace('(правая сторона)', '(пр. сторона)', $termoSeatStr[$id]['block']);
                     $termoSeatStr[$id]['row'] = $matches[2];
                     $termoSeatStr[$id]['seat'] = $dataInit->seat;
                 }
             }
         }
     } catch (\Exception $e) {
         die('Ошибка загрузки карты');
     }
     $tickets = array();
     foreach ($keys as $key) {
         $priceRow = DB::select('price', 'seats.id')->from('prices')->join('seats', 'LEFT')->on('prices.id', '=', 'seats.price_id')->where('afisha_id', '=', $afisha->id)->where('seats.view_key', '=', $key)->find();
         $tickets[] = Arr::to_object(array('event_name' => $afisha->name, 'print_name' => $afisha->print_name, 'print_name_small' => $afisha->print_name_small, 'event_date' => date('j', $afisha->event_date) . ' ' . Dates::month(date('m', $afisha->event_date)) . ' ' . date('Y', $afisha->event_date) . ' в ' . $afisha->event_time, 'event_place' => $afisha->place, 'event_just_date' => date('j', $afisha->event_date) . ' ' . Dates::month(date('m', $afisha->event_date)) . ' ' . date('Y', $afisha->event_date), 'event_time' => $afisha->event_time, 'event_address' => $afisha->address, 'place_string' => $seatStr[$key], 'place_block' => $termoSeatStr[$key]['block'], 'place_row' => $termoSeatStr[$key]['row'], 'place_seat' => $termoSeatStr[$key]['seat'], 'price' => $priceRow->price, 'phone' => $city->phone, 'barcode' => $afisha->id . '-' . $key));
     }
     if ($printType == 'base') {
         echo View::tpl(array('tickets' => $tickets), 'Afisha_orders/Print');
     } else {
         echo View::tpl(array('tickets' => $tickets), 'Afisha_orders/PrintTermo');
     }
     die;
 }
Esempio n. 30
0
 function addAction()
 {
     $groupBrands = Arr::get($_POST, 'BRANDS', array());
     $groupSizes = Arr::get($_POST, 'SIZES', array());
     $groupSpec = Arr::get($_POST, 'SPEC', array());
     if ($_POST) {
         $post = $_POST['FORM'];
         $post['status'] = Arr::get($_POST, 'status', 0);
         $post['created_at'] = time();
         if (!trim(Arr::get($post, 'name'))) {
             Message::GetMessage(0, 'Наименование страницы не может быть пустым!');
         } else {
             if (!trim(Arr::get($post, 'alias'))) {
                 Message::GetMessage(0, 'Алиас не может быть пустым!');
             } else {
                 $post['alias'] = Common::getUniqueAlias($this->tablename, Arr::get($post, 'alias'));
                 $res = Common::insert($this->tablename, $post)->execute();
                 if ($res) {
                     $id = $res[0];
                     $filename = Files::uploadImage($this->image);
                     if ($filename) {
                         DB::update($this->tablename)->set(array('image' => $filename))->where('id', '=', $id)->execute();
                     }
                     foreach ($groupBrands as $brand_id) {
                         DB::insert('catalog_tree_brands', array('catalog_tree_id', 'brand_id'))->values(array($id, $brand_id))->execute();
                     }
                     foreach ($groupSizes as $size_id) {
                         DB::insert('catalog_tree_sizes', array('catalog_tree_id', 'size_id'))->values(array($id, $size_id))->execute();
                     }
                     foreach ($groupSpec as $specification_id) {
                         DB::insert('catalog_tree_specifications', array('catalog_tree_id', 'specification_id'))->values(array($id, $specification_id))->execute();
                     }
                     Message::GetMessage(1, 'Вы успешно добавили данные!');
                     HTTP::redirect('backend/' . Route::controller() . '/add');
                 } else {
                     Message::GetMessage(0, 'Не удалось добавить данные!');
                 }
             }
         }
         $result = Arr::to_object($post);
     } else {
         $result = array();
     }
     $this->_toolbar = Widgets::get('Toolbar/Edit');
     $this->_seo['h1'] = 'Добавление';
     $this->_seo['title'] = 'Добавление';
     $this->setBreadcrumbs('Добавление', 'backend/' . Route::controller() . '/add');
     $this->_content = View::tpl(array('obj' => $result, 'tpl_folder' => $this->tpl_folder, 'tablename' => $this->tablename, 'tree' => Support::getSelectOptions('Groups/Select', 'catalog_tree', $result->parent_id), 'brands' => DB::select()->from('brands')->order_by('name')->find_all(), 'sizes' => DB::select()->from('sizes')->order_by('name')->find_all(), 'specifications' => DB::select()->from('specifications')->order_by('name')->find_all(), 'groupBrands' => $groupBrands, 'groupSizes' => $groupSizes, 'groupSpec' => $groupSpec), $this->tpl_folder . '/Form');
 }