public function endAction() { $orderId = (int) Route::param('id'); if ($orderId and isset($_POST) and count($_POST) > 0) { $data = json_decode(base64_decode($_POST['data']), true); $order = DB::select()->from('afisha_orders')->where('id', '=', $orderId)->find(); if (!$order) { return Config::error(); } // update status if ($data['status'] && $data['status'] == 'success') { Common::update('afisha_orders', array('status' => 'success', 'updated_at' => time()))->where('id', '=', $orderId)->execute(); // Change status for seats $prices = DB::select('id')->from('prices')->where('afisha_id', '=', $order->afisha_id)->find_all(); $pricesArr = array(); if (count($prices)) { foreach ($prices as $key => $value) { $pricesArr[] = $value->id; } $res2 = \Core\Common::update('seats', array('status' => 3))->where('view_key', 'IN', array_filter(explode(',', $order->seats_keys)))->where('price_id', 'IN', $pricesArr)->execute(); } } } // HTTP::redirect('after_payment/'); return; }
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'); }
public function __construct() { if (self::$layout === NULL) { self::$layout = DB::select('zna')->from('config')->where('key', '=', DB::expr('"message_output"'))->as_object()->execute()->current()->zna; // self::$layout = Config::get('message_output'); } }
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'); }
public function indexAction() { $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('Карта сайта'); // Get pages $result = DB::select()->from('content')->where('status', '=', 1)->order_by('sort')->as_object()->execute(); $pages = array(); foreach ($result as $obj) { $pages[$obj->parent_id][] = $obj; } // Get catalog groups $result = DB::select()->from('catalog_tree')->where('status', '=', 1)->order_by('sort')->as_object()->execute(); $groups = array(); foreach ($result as $obj) { $groups[$obj->parent_id][] = $obj; } // Get catalog groups $brands = DB::select()->from('brands')->where('status', '=', 1)->order_by('sort')->as_object()->execute(); // Get news $news = DB::select()->from('news')->where('status', '=', 1)->order_by('date', 'DESC')->as_object()->execute(); // Get articles $articles = DB::select()->from('articles')->where('status', '=', 1)->order_by('id', 'DESC')->as_object()->execute(); // Render page $this->_content = View::tpl(array('pages' => $pages, 'groups' => $groups, 'news' => $news, 'articles' => $articles, 'brands' => $brands), 'Sitemap/Index'); }
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'); }
public static function countRows($status = NULL, $filter = null) { $result = DB::select(array(DB::expr('COUNT(' . static::$table . '.id)'), 'count'))->from(static::$table)->where('role_id', '=', 1); $result = parent::setFilter($result); if ($status !== NULL) { $result->where(static::$table . '.status', '=', $status); } return $result->count_all(); }
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'); }
public function indexAction() { $subscriber = DB::select()->from('subscribers')->where('hash', '=', Route::param('hash'))->where('status', '=', 1)->as_object()->execute()->current(); if (!$subscriber) { Message::GetMessage(0, 'Вы не подписаны на рассылку с нашего сайта!'); HTTP::redirect('/'); } DB::update('subscribers')->set(array('status' => 0, 'updated_at' => time()))->where('id', '=', $subscriber->id)->execute(); Message::GetMessage(1, 'Вы успешно отписались от рассылки новостей с нашего сайта!'); HTTP::redirect('/'); }
private static function getCosts() { if (null === self::$costs) { $res = DB::select('prices.price', 'prices.afisha_id', 'seats.view_key')->from('prices')->join('seats', 'LEFT')->on('prices.id', '=', 'seats.price_id')->find_all(); if ($res->count()) { foreach ($res as $obj) { self::$costs[$obj->afisha_id][$obj->view_key] = $obj->price; } } } return self::$costs; }
function editAction() { if ($_POST) { foreach ($_POST['FORM'] as $key => $value) { $res = Common::update($this->tablename, array('zna' => $value))->where('id', '=', $key)->execute(); } Message::GetMessage(1, 'Вы успешно изменили данные!'); HTTP::redirect('backend/' . Route::controller() . '/edit'); } $result = DB::select()->from($this->tablename)->where('status', '=', 1)->order_by('sort')->find_all(); $this->_toolbar = Widgets::get('Toolbar/EditSaveOnly'); $this->_content = View::tpl(array('result' => $result, 'tpl_folder' => $this->tpl_folder), $this->tpl_folder . '/Edit'); }
public function setSeoForItem($page) { $tpl = DB::select()->from('seo')->where('id', '=', 2)->as_object()->execute()->current(); $from = array('{{name}}', '{{group}}', '{{brand}}', '{{model}}'); $to = array($page->name, $page->parent_name, $page->brand_name, $page->model_name); $this->_seo['h1'] = str_replace($from, $to, $tpl->h1); $this->_seo['title'] = str_replace($from, $to, $tpl->title); $this->_seo['keywords'] = str_replace($from, $to, $tpl->keywords); $this->_seo['description'] = str_replace($from, $to, $tpl->description); $this->setBreadcrumbs('Каталог', '/catalog'); $this->generateParentBreadcrumbs($page->parent_id, 'catalog_tree', 'parent_id', '/catalog/'); $this->setBreadcrumbs($page->name); }
function indexAction() { $this->_seo['h1'] = 'Панель управления'; $this->_seo['title'] = 'Панель управления'; $count_catalog = DB::select(array(DB::expr('COUNT(id)'), 'count'))->from('catalog')->count_all(); $count_orders = DB::select(array(DB::expr('COUNT(id)'), 'count'))->from('orders')->count_all(); $count_comments = DB::select(array(DB::expr('COUNT(id)'), 'count'))->from('catalog_comments')->count_all(); $count_subscribers = DB::select(array(DB::expr('COUNT(id)'), 'count'))->from('subscribers')->count_all(); $count_users = DB::select(array(DB::expr('COUNT(id)'), 'count'))->from('users')->where('role_id', '!=', 2)->count_all(); $count_banners = DB::select(array(DB::expr('COUNT(id)'), 'count'))->from('banners')->count_all(); $count_articles = DB::select(array(DB::expr('COUNT(id)'), 'count'))->from('articles')->count_all(); $count_news = DB::select(array(DB::expr('COUNT(id)'), 'count'))->from('news')->count_all(); $this->_content = View::tpl(array('count_catalog' => $count_catalog, 'count_orders' => $count_orders, 'count_comments' => $count_comments, 'count_subscribers' => $count_subscribers, 'count_users' => $count_users, 'count_banners' => $count_banners, 'count_articles' => $count_articles, 'count_news' => $count_news), 'Index/Main'); }
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); }
/** * Check cron table if need and send some letters */ public function check() { if (!Config::get('main.cron') or !Config::get('main.selfCron')) { return false; } $ids = array(); $result = DB::select()->from(Config::get('main.tableCron'))->limit(Config::get('main.selfCron'))->as_object()->execute(); foreach ($result as $obj) { $ids[] = $obj->id; Email::send($obj->subject, $obj->text, $obj->email); } if (count($ids)) { DB::delete(Config::get('main.tableCron'))->where('id', 'IN', $ids)->execute(); } }
public function indexAction() { // Check for existance $page = DB::select('h1', 'title', 'keywords', 'description', 'text', 'name')->from('control')->where('alias', '=', 'contact')->as_object()->execute()->current(); if (!$page) { return conf::error(); } // Seo $this->_seo['h1'] = $page->h1; $this->_seo['title'] = $page->title; $this->_seo['keywords'] = $page->keywords; $this->_seo['description'] = $page->description; $this->setBreadcrumbs($page->name); // Render template $this->_content = View::tpl(array('text' => $page->text, 'kids' => array()), 'Contact/Index'); }
public function after_paymentAction() { $this->_template = 'Text'; // Check for existance $page = DB::select('h1', 'title', 'keywords', 'description', 'text')->from('control')->where('alias', '=', 'after_payment')->as_object()->execute()->current(); if (!$page) { return Config::error(); } // Seo $this->_seo['h1'] = $page->h1; $this->_seo['title'] = $page->title; $this->_seo['keywords'] = $page->keywords; $this->_seo['description'] = $page->description; // Render template $this->_content = $page->text; }
public static function getAccess($role_id) { $result = DB::select()->from('access')->where('role_id', '=', $role_id)->find_all(); $arr = array(); foreach ($result as $obj) { if ($obj->edit && $obj->view) { $arr[$obj->controller] = 'edit'; } else { if ($obj->view) { $arr[$obj->controller] = 'view'; } else { $arr[$obj->controller] = 'no'; } } } return $arr; }
public static function getList($filter = null) { $query = DB::select()->from(self::$table); if ($filter['id']) { $query->where('id', '=', $filter['id']); } if ($filter['afisha_id']) { $query->where('afisha_id', '=', $filter['afisha_id']); } if ($filter['price']) { $query->where('price', '=', $filter['price']); } if ($filter['order_by'] && count($filter['order_by']) == 2) { $query->order_by((string) $filter['order_by'][0], (string) $filter['order_by'][1]); } elseif ($filter['order_by']) { $query->order_by((string) $filter['order_by']); } return $query->find_all(); }
public function innerAction() { Config::set('content_class', 'new_block'); // Check for existance $obj = DB::select()->from('articles')->where('alias', '=', Route::param('alias'))->where('status', '=', 1)->find(); if (!$obj) { return Config::error(); } // Seo $this->_seo['h1'] = $obj->h1; $this->_seo['title'] = $obj->title; $this->_seo['keywords'] = $obj->keywords; $this->_seo['description'] = $obj->description; $this->setBreadcrumbs($obj->name); // Add plus one to views DB::update('articles')->set(array('views' => $obj->views + 1))->where('id', '=', $obj->id)->execute(); // Render template $this->_content = View::tpl(array('obj' => $obj), 'Articles/Inner'); }
public static function getSelectOptions($filename, $table, $parentID = NULL, $currentElement = 0, $sort = 'sort', $parentAlias = 'parent_id') { if ($filename != 'catalog/select') { $current = Route::param('id'); } else { $current = 0; } $tree = array(); $result = DB::select()->from($table)->order_by($sort)->as_object()->execute(); foreach ($result as $obj) { if (!$current) { $tree[$obj->{$parentAlias}][] = $obj; } else { if ($obj->parent_id != $current and $obj->id != $current) { $tree[$obj->{$parentAlias}][] = $obj; } } } return View::tpl(array('result' => $tree, 'currentParent' => 0, 'space' => '', 'filename' => $filename, 'parentID' => $parentID, 'parentAlias' => $parentAlias, 'currentID' => $currentElement), $filename); }
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'); }
public function indexAction() { // Check for existance $page = DB::select()->from('content')->where('alias', '=', Route::param('alias'))->where('status', '=', 1)->as_object()->execute()->current(); if (!$page) { return Config::error(); } // Seo $this->_seo['h1'] = $page->h1; $this->_seo['title'] = $page->title; $this->_seo['keywords'] = $page->keywords; $this->_seo['description'] = $page->description; $this->generateParentBreadcrumbs($page->parent_id, 'content', 'parent_id'); $this->setBreadcrumbs($page->name); // Add plus one to views DB::update('content')->set(array('views' => $page->views + 1))->where('id', '=', $page->id)->execute(); // Get content page children $kids = DB::select()->from('content')->where('status', '=', 1)->where('parent_id', '=', $page->id)->order_by('sort', 'ASC')->as_object()->execute(); // Render template $this->_content = View::tpl(array('text' => $page->text, 'kids' => $kids), 'Content/Page'); }
public static function getList($filter = array()) { $query = DB::select()->from(static::$table); if ($filter['id']) { $query->where('id', '=', $filter['id']); } if ($filter['view_key']) { $query->where('view_key', '=', $filter['view_key']); } if ($filter['price_id']) { $query->where('price_id', '=', $filter['price_id']); } if ($filter['price_id_in']) { $query->where('price_id', 'IN', (array) $filter['price_id_in']); } if ($filter['status']) { $query->where('status', '=', $filter['status']); } if ($filter['group_by']) { $query->group_by($filter['group_by']); } if ($filter['order_by'] && count($filter['order_by']) == 2) { $query->order_by((string) $filter['order_by'][0], (string) $filter['order_by'][1]); } elseif ($filter['order_by']) { $query->order_by((string) $filter['order_by']); } if ($filter['grouping']) { $result = array(); foreach ($query->find_all() as $obj) { $result[$obj->{$filter['grouping']}][] = $obj; } return $result; } else { if ($filter['as_array']) { return $query->as_assoc()->execute(); } else { return $query->find_all(); } } }
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() . '/edit/' . (int) 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'); }
public static function getList($filter = array()) { $query = DB::select()->from(self::$table); if (count($filter)) { foreach ($filter as $key => $value) { if (in_array($key, array('grouping', 'as_array'))) { continue; } $query->where($key, '=', $value); } } if ($filter['grouping']) { $result = array(); foreach ($query->find_all() as $obj) { $result[$obj->{$filter['grouping']}][] = $obj; } return $result; } else { if ($filter['as_array']) { return $query->as_assoc()->execute(); } return $query->find_all(); } }
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'); }
function createOrderAction() { if (User::get_access_for_controller('afisha_brone') != 'edit') { $this->no_access(); } $key = Route::param('key'); $keys = (array) explode(',', $key); $keys = array_filter($keys); if (count($keys) == 0) { Message::GetMessage(0, 'Места не выбраны!'); HTTP::redirect('backend/afisha/index'); } $afisha = DB::select('afisha.*', array('places.name', 'place'), 'places.filename', 'places.address')->from('afisha')->join('places')->on('afisha.place_id', '=', 'places.id')->where('afisha.id', '=', (int) Route::param('id'))->find(); if (!$afisha) { return Config::error(); } // Get prices by afisha ID $prices = DB::select('id')->from('prices')->where('afisha_id', '=', $afisha->id)->find_all(); if (count($prices) == 0) { Message::GetMessage(0, 'Ошибка создания заказа (выборка цен)'); HTTP::redirect('backend/afisha/index'); } $pricesIds = array(); foreach ($prices as $price) { $pricesIds[] = $price->id; } // Generate seats id from places list $seats = DB::select('id')->from('seats')->where('view_key', 'IN', $keys)->where('price_id', 'IN', $pricesIds)->and_where_open()->where('status', '=', 1)->or_where_open()->where('status', '=', 2)->where('reserved_at', '<', time() - 60 * 60 * 24 * Config::get('reserved_days'))->or_where_close()->and_where_close()->find_all(); if (count($seats) == 0) { Message::GetMessage(0, 'Ошибка создания заказа (выборка мест)'); HTTP::redirect('backend/afisha/index'); } $seatsId = array(); foreach ($seats as $seat) { $seatsId[] = $seat->id; } $orderType = (int) Route::param('orderType'); $data = array('afisha_id' => $afisha->id, 'is_admin' => User::info()->role_id == 2 ? 1 : 0, 'admin_brone' => $orderType, 'creator_id' => User::info()->id, 'seats_keys' => implode(',', $keys), 'created_at' => time(), 'first_created_at' => time(), 'status' => ''); $res = DB::insert('afisha_orders', array_keys($data))->values(array_values($data))->execute(); if ($res) { // Update status $res2 = DB::update('seats')->set(array('status' => $orderType == 1 ? 3 : 2, 'reserved_at' => time()))->where('id', 'IN', $seatsId)->execute(); Message::GetMessage(1, 'Заказ успешно создан!'); HTTP::redirect('backend/afisha_orders/edit/' . $res[0]); } else { Message::GetMessage(0, 'Ошибка создания заказа!'); HTTP::redirect('backend/afisha/index'); } }
public function headerNew($array = array()) { $count = 0; $result = DB::select(array(DB::expr('COUNT(id)'), 'count'))->from('log')->where('deleted', '=', 0)->as_object()->execute()->current(); if ($result) { $count = $result->count; } $result = DB::select()->from('log')->where('deleted', '=', 0)->limit(7)->as_object()->execute(); return $this->_data['headerNew'] = View::widget(array('count' => $count, 'result' => $result), 'HeaderNew'); }
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))); }