Exemplo n.º 1
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 {
             $res = Common::insert($this->tablename, $post)->execute();
             if ($res) {
                 $filename = Files::uploadImage($this->image);
                 if ($filename) {
                     DB::update($this->tablename)->set(array('image' => $filename))->where('id', '=', $res[0])->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), $this->tpl_folder . '/Form');
 }
Exemplo n.º 2
0
 public static function delete($id)
 {
     // Check id for not doing query to database if we don't need it
     if (!$id) {
         return false;
     }
     // Set field "deleted" as 1
     return DB::update('log')->set(array('deleted' => 1, 'updated_at' => time()))->where('id', '=', $id)->execute();
 }
Exemplo n.º 3
0
 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('/');
 }
Exemplo n.º 4
0
 public function showAction()
 {
     $item = Model::getItem(Route::param('alias'));
     if (!$item->id) {
         return Config::error();
     }
     // Add plus one to views
     DB::update('afisha')->set(array('views' => (int) $item->views + 1))->where('id', '=', $item->id)->execute();
     // Seo
     $this->setSeoForItem($item);
     // Render template
     $this->_content = View::tpl(array('obj' => $item), 'Afisha/Item');
 }
Exemplo n.º 5
0
 /**
  * @param string $table - table in witch we update data
  * @param array $data - associative array with data to update
  * @return DB object with part of the query
  */
 public static function update($table, $data)
 {
     foreach ($data as $key => $value) {
         if ($value == 'null') {
             $data[$key] = DB::expr('null');
         } else {
             $data[$key] = stripslashes($value);
         }
     }
     if (!isset($data['updated_at']) and Common::checkField($table, 'updated_at')) {
         $data['updated_at'] = time();
     }
     return DB::update($table)->set($data);
 }
Exemplo n.º 6
0
 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');
 }
Exemplo n.º 7
0
 public function indexAction()
 {
     // Get item information from database
     $item = DB::select('catalog.*', array('brands.name', 'brand_name'), array('brands.alias', 'brand_alias'), array('models.name', 'model_name'), array('catalog_tree.name', 'parent_name'))->from('catalog')->join('catalog_tree', 'LEFT')->on('catalog.parent_id', '=', 'catalog_tree.id')->join('brands', 'LEFT')->on('catalog.brand_id', '=', 'brands.id')->on('brands.status', '=', DB::expr('1'))->join('models', 'LEFT')->on('catalog.model_id', '=', 'models.id')->on('models.status', '=', DB::expr('1'))->where('catalog.status', '=', 1)->where('catalog.alias', '=', Route::param('alias'))->as_object()->execute()->current();
     if (!$item) {
         return Config::error();
     }
     Route::factory()->setParam('id', $item->id);
     Route::factory()->setParam('group', $item->parent_id);
     // Add to cookie viewed list
     Catalog::factory()->addViewed($item->id);
     // Add plus one to views
     DB::update('catalog')->set(array('views' => (int) $item->views + 1))->where('id', '=', $item->id)->execute();
     // Seo
     $this->setSeoForItem($item);
     // Get images
     $images = DB::select('image')->from('catalog_images')->where('catalog_id', '=', $item->id)->order_by('sort')->as_object()->execute();
     // Get item sizes
     $sizes = DB::select('sizes.*')->from('sizes')->join('catalog_sizes', 'LEFT')->on('catalog_sizes.size_id', '=', 'sizes.id')->where('catalog_sizes.catalog_id', '=', $item->id)->where('sizes.status', '=', 1)->order_by('sizes.name')->as_object()->execute();
     // Get current item specifications list
     $specifications = DB::select('specifications.*')->from('specifications')->join('catalog_tree_specifications', 'LEFT')->on('catalog_tree_specifications.specification_id', '=', 'specifications.id')->where('catalog_tree_specifications.catalog_tree_id', '=', $item->parent_id)->where('specifications.status', '=', 1)->order_by('specifications.name')->as_object()->execute();
     $res = DB::select()->from('specifications_values')->join('catalog_specifications_values', 'LEFT')->on('catalog_specifications_values.specification_value_id', '=', 'specifications_values.id')->where('catalog_specifications_values.catalog_id', '=', $item->id)->where('status', '=', 1)->where('catalog_specifications_values.specification_value_id', '!=', 0)->as_object()->execute();
     $specValues = array();
     foreach ($res as $obj) {
         $specValues[$obj->specification_id][] = $obj;
     }
     $spec = array();
     foreach ($specifications as $obj) {
         if (isset($specValues[$obj->id]) and is_array($specValues[$obj->id]) and count($specValues[$obj->id])) {
             if ($obj->type_id == 3) {
                 $spec[$obj->name] = '';
                 foreach ($specValues[$obj->id] as $o) {
                     $spec[$obj->name] .= $o->name . ', ';
                 }
                 $spec[$obj->name] = substr($spec[$obj->name], 0, -2);
             } else {
                 $spec[$obj->name] = $specValues[$obj->id][0]->name;
             }
         }
     }
     // Render template
     $this->_content = View::tpl(array('obj' => $item, 'images' => $images, 'sizes' => $sizes, 'specifications' => $spec), 'Catalog/Item');
 }
Exemplo n.º 8
0
 public function confirmAction()
 {
     if (U::info()) {
         return Config::error();
     }
     if (!Route::param('hash')) {
         return Config::error();
     }
     $user = U::factory()->get_user_by_hash(Route::param('hash'));
     if (!$user) {
         return Config::error();
     }
     if ($user->status) {
         Message::GetMessage(0, 'Вы уже подтвердили свой E-Mail!');
         HTTP::redirect('/');
     }
     DB::update('users')->set(array('status' => 1, 'updated_at' => time()))->where('id', '=', $user->id)->execute();
     U::factory()->auth($user, 0);
     Message::GetMessage(1, 'Вы успешно зарегистрировались на сайте! Пожалуйста укажите остальную информацию о себе в личном кабинете для того, что бы мы могли обращаться к Вам по имени');
     HTTP::redirect('/user');
 }
Exemplo n.º 9
0
 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');
 }
Exemplo n.º 10
0
 public function updateSeatsAction()
 {
     $post = $_POST;
     $afisha_id = $post['afisha_id'];
     $list_keys = $post['list'];
     if (!$afisha_id or !$list_keys) {
         die(json_encode(array('success' => false, 'message' => 'Ошибка получения данных')));
     }
     $afisha = DB::select()->from('afisha_orders')->where('id', '=', (int) $afisha_id)->find();
     $prices = DB::select('id')->from('prices')->where('afisha_id', '=', $afisha->afisha_id)->find_all();
     $keys = (array) array_filter(explode(',', $list_keys));
     $pricesArr = array();
     if (count($prices)) {
         foreach ($prices as $key => $value) {
             $pricesArr[] = $value->id;
         }
         //                Reset old seats
         \Core\Common::update('seats', array('status' => 1, 'reserved_at' => DB::expr(NULL)))->where('view_key', 'IN', array_filter(explode(',', $afisha->seats_keys)))->where('price_id', 'IN', $pricesArr)->execute();
         //                Write new seats
         // Generate seats id from places list
         $seats = DB::select('id')->from('seats')->where('view_key', 'IN', $keys)->where('price_id', 'IN', $pricesArr)->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();
         $seatsId = array();
         foreach ($seats as $seat) {
             $seatsId[] = $seat->id;
         }
         DB::update('seats')->set(array('status' => 2, 'reserved_at' => time()))->where('id', 'IN', $seatsId)->execute();
     }
     $res = \Core\Common::update('afisha_orders', array('seats_keys' => $list_keys))->where('id', '=', (int) $afisha_id)->execute();
     if ($res) {
         die(json_encode(array('success' => true, 'message' => 'Данные сохранены', 'reload' => true)));
     } else {
         die(json_encode(array('success' => false, 'message' => 'Ошибка обновления данных')));
     }
 }
Exemplo n.º 11
0
 /**
  *      Change count in the cart
  *      @param int $catalog_id - goods ID
  *      @param int $count - new count in the cart
  */
 public function edit($catalog_id, $size_id, $count)
 {
     if (Arr::get($this->_cart, $catalog_id . '-' . $size_id, false)) {
         $this->_cart[$catalog_id . '-' . $size_id]['count'] = $count;
         DB::update('carts_items')->set(array('count' => $count))->where('cart_id', '=', $this->_cart_id)->where('catalog_id', '=', $catalog_id)->where('size_id', '=', $size_id)->execute();
         $this->recount();
         return true;
     }
     return false;
 }
Exemplo n.º 12
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');
 }
Exemplo n.º 13
0
 /**
  *      Update users password
  *      @param $id - ID of the user who needs a new password
  *      @param $password - desired password
  *      @param $salt - Salt for hash. If empty - use salt default
  */
 public function update_password($id = NULL, $password = NULL, $salt = NULL)
 {
     if ($id == NULL) {
         return false;
     }
     if ($password == NULL) {
         return false;
     }
     return DB::update($this->_tbl)->set(array('password' => $this->hash_password($password, $salt), 'updated_at' => time()))->where('id', '=', $id)->execute();
 }
Exemplo n.º 14
0
 public function orderAction()
 {
     // Check incoming data
     $name = Text::xssClean(Arr::get($this->post, 'name'));
     if (!$name) {
         $this->error('Вы не указали имя!');
     }
     $email = Text::xssClean(Arr::get($this->post, 'email'));
     if (!$email or !filter_var($email, FILTER_VALIDATE_EMAIL)) {
         $this->error('Вы указали неверный e-mail!');
     }
     $phone = Text::xssClean(Arr::get($this->post, 'phone'));
     if (!$phone or !preg_match('/\\(\\d{3}\\)\\s\\d{3}-\\d{2}-\\d{2}/', $phone, $matches)) {
         $this->error('Вы указали неверный телефон!');
     }
     $places = Text::xssClean(Arr::get($this->post, 'seats'));
     $places = array_filter(explode(',', $places));
     if (!$places or !is_array($places)) {
         $this->error('Вы не выбрали места!');
     }
     $message = nl2br(Text::xssClean(Arr::get($this->post, 'message', null)));
     $afishaId = (int) Text::xssClean(Arr::get($this->post, 'id'));
     // Get prices by afisha ID
     $prices = DB::select('id')->from('prices')->where('afisha_id', '=', $afishaId)->find_all();
     if (count($prices) == 0) {
         $this->error('Ошибка создания заказа (выборка цен)');
     }
     $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', $places)->where('price_id', 'IN', $pricesIds)->and_where_open()->where('status', '=', 1)->or_where_open()->where('status', '=', 2)->where('reserved_at', '<', time() - 60 * 60 * 24 * conf::get('reserved_days'))->or_where_close()->and_where_close()->find_all();
     if (count($seats) == 0) {
         $this->error('Ошибка создания заказа (выборка мест)');
     }
     $seatsId = array();
     foreach ($seats as $seat) {
         $seatsId[] = $seat->id;
     }
     $data = array('afisha_id' => $afishaId, 'name' => $name, 'email' => $email, 'phone' => $phone, 'message' => $message, 'seats_keys' => implode(',', $places), 'created_at' => time(), 'first_created_at' => time(), 'updated_at' => time(), 'ip' => System::getRealIP());
     $res = \Core\Common::insert('afisha_orders', $data)->execute();
     if (!$res) {
         $this->error('ошибка создания заказа');
     }
     // Update status
     $res2 = DB::update('seats')->set(array('status' => 2, 'reserved_at' => time()))->where('id', 'IN', $seatsId)->execute();
     $afisha = DB::select()->from('afisha')->where('id', '=', $afishaId)->find();
     $data['event_name'] = $afisha->name;
     // Send email messages for adimn and user
     Afisha\Models\Afisha::sendOrderMessageAdmin(array('id_order' => $res[0], 'order' => $data, 'order_text' => Arr::get($this->post, 'order')));
     Afisha\Models\Afisha::sendOrderMessageUser(array('id_order' => $res[0], 'order' => $data, 'order_text' => Arr::get($this->post, 'order')));
     // Save log
     $qName = 'Новый заказ';
     $url = '/backend/afisha_orders/edit/' . $res[0];
     Log::add($qName, $url, 8);
     $response = array();
     // Redirect to payment system
     if (Arr::get($this->post, 'action') == 'payment') {
         $response['redirect'] = \Core\HTML::link('payment/' . $res[0]);
     } else {
         $response['reload'] = true;
     }
     $response['response'] = 'Ваш заказ отправлен';
     return $this->success($response);
 }
Exemplo n.º 15
0
 function deleteAction()
 {
     $id = (int) Route::param('id');
     if (!$id) {
         Message::GetMessage(0, 'Данные не существуют!');
         HTTP::redirect('backend/' . Route::controller() . '/index');
     }
     $page = DB::select()->from($this->tablename)->where('id', '=', $id)->as_object()->execute()->current();
     if (!$page) {
         Message::GetMessage(0, 'Данные не существуют!');
         HTTP::redirect('backend/' . Route::controller() . '/index');
     }
     DB::update($this->tablename)->set(array('parent_id' => $page->parent_id))->where('parent_id', '=', $id)->execute();
     DB::delete($this->tablename)->where('id', '=', $id)->execute();
     Message::GetMessage(1, 'Данные удалены!');
     HTTP::redirect('backend/' . Route::controller() . '/index');
 }
Exemplo n.º 16
0
 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');
     }
 }
Exemplo n.º 17
0
 function printAction()
 {
     if (User::get_access_for_controller('afisha_brone') != 'edit') {
         $this->no_access();
     }
     $seats = (array) $_POST['SEATS'];
     $printType = $_POST['print-type'] ? $_POST['print-type'] : 'base';
     if (count($seats) == 0) {
         Message::GetMessage(0, 'Места не выбраны!');
         HTTP::redirect('backend/afisha_orders/edit/' . Route::param('id'));
     }
     $order = DB::select()->from($this->tablename)->where('id', '=', Route::param('id'))->find();
     if (!$order) {
         return Config::error();
     }
     $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', '=', $order->afisha_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, $seats)) {
                 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 = str_replace('(левая сторона)', '(лев. сторона)', $originalPlace);
                     $place = str_replace('(правая сторона)', '(пр. сторона)', $place);
                     $place = str_replace(',', '<br />', $place);
                     $place = str_replace('ряд', 'ряд:', $place);
                     $seatStr[$id] = str_replace(array('места', 'Места'), 'место', $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]['row'] = $matches[2];
                     $termoSeatStr[$id]['seat'] = $dataInit->seat;
                     $termoSeatStr[$id]['block'] = str_replace('(левая сторона)', '(лев. сторона)', $termoSeatStr[$id]['block']);
                     $termoSeatStr[$id]['block'] = str_replace('(правая сторона)', '(пр. сторона)', $termoSeatStr[$id]['block']);
                 }
             }
         }
     } catch (\Exception $e) {
         die('Ошибка загрузки карты');
     }
     $tickets = array();
     foreach ($seats as $seat) {
         if (User::info()->role_id != 2 && User::get_access_for_controller('afisha_print_unlimit') == 'edit' && strpos($order->printed_seats, $seat) !== false) {
             continue;
         }
         $priceRow = DB::select('price')->from('prices')->join('seats', 'LEFT')->on('prices.id', '=', 'seats.price_id')->where('afisha_id', '=', $order->afisha_id)->where('seats.view_key', '=', $seat)->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('d', $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[$seat], 'place_block' => $termoSeatStr[$seat]['block'], 'place_row' => $termoSeatStr[$seat]['row'], 'place_seat' => $termoSeatStr[$seat]['seat'], 'price' => $priceRow->price, 'phone' => $city->phone, 'barcode' => $afisha->id . '-' . $order->id . '-' . $seat));
     }
     //            Update print seats keys
     if (User::info()->role_id != 2 && User::get_access_for_controller('afisha_print_unlimit') == 'edit') {
         $oldSeats = $order->printed_seats;
         $newSeats = array();
         if (strlen($oldSeats)) {
             $oldSeats = explode(',', $oldSeats);
             if (count($oldSeats)) {
                 $newSeats = (array) $oldSeats;
             }
         }
         foreach ($seats as $seat) {
             $newSeats[] = $seat;
         }
         $newSeats = array_filter(array_unique($newSeats));
         $newSeats = implode(',', $newSeats);
         DB::update($this->tablename)->set(array('printed_seats' => $newSeats))->where('id', '=', $order->id)->execute();
     }
     //            Update order status
     $newOrder = DB::select()->from('afisha_orders')->where('id', '=', $order->id)->find();
     $printedAllSeats = true;
     $printedSeats = array_filter(explode(',', $newOrder->printed_seats));
     foreach (array_filter(explode(',', $newOrder->seats_keys)) as $seat) {
         if (!in_array($seat, $printedSeats)) {
             $printedAllSeats = false;
         }
     }
     if (User::info()->role_id != 2 && $printedAllSeats) {
         \Core\Common::update('afisha_orders', array('status' => 'success'))->where('id', '=', (int) $order->id)->execute();
         $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;
             }
             \Core\Common::update('seats', array('status' => 3))->where('view_key', 'IN', array_filter(explode(',', $order->seats_keys)))->where('price_id', 'IN', $pricesArr)->execute();
         }
     }
     if ($printType == 'base') {
         echo View::tpl(array('tickets' => $tickets), 'Afisha_orders/Print');
     } else {
         echo View::tpl(array('tickets' => $tickets), 'Afisha_orders/PrintTermo');
     }
     die;
 }
Exemplo n.º 18
0
 public function listAction()
 {
     $this->_template = 'ItemsList';
     Route::factory()->setAction('list');
     // Filter parameters to array if need
     Filter::setFilterParameters();
     // Set filter elements sortable
     Filter::setSortElements();
     $page = !(int) Route::param('page') ? 1 : (int) Route::param('page');
     // Check for existance
     $group = DB::select()->from('catalog_tree')->where('alias', '=', Route::param('alias'))->where('status', '=', 1)->as_object()->execute()->current();
     if (!$group) {
         return Config::error();
     }
     // Seo
     $this->setSeoForGroup($group);
     // Add plus one to views
     DB::update('catalog_tree')->set(array('views' => (int) $group->views + 1))->where('id', '=', $group->id)->execute();
     // Get items list
     $result = Filter::getFilteredItemsList($this->limit, ($page - 1) * $this->limit, $this->sort, $this->type);
     // Generate filter add for sql queries
     $add = Filter::getSql();
     // Count of parent groups
     $count = DB::query(Database::SELECT, 'SELECT COUNT(DISTINCT catalog.id) AS count FROM catalog ' . $add['join'] . 'WHERE catalog.parent_id = "' . $group->id . '" AND catalog.status = "1"' . $add['where'])->as_object()->execute()->current();
     if ($count) {
         $count = $count->count;
     } else {
         $count = 0;
     }
     // Generate pagination
     $pager = Pager::factory($page, $count, $this->limit)->create();
     // Render page
     $this->_content = View::tpl(array('result' => $result, 'pager' => $pager), 'Catalog/ItemsList');
 }