public function getPricesAction() { $post = $_POST; // Check data $id_afisha = Arr::get($post, 'id_afisha'); if (!isset($id_afisha)) { die(json_encode(array('success' => false, 'error' => 'Ошибка обработки'))); } $result = DB::select()->from('prices')->where('afisha_id', '=', $id_afisha)->execute()->as_array(); foreach ($result as $key => $value) { $result[$key]['place_list'] = \Modules\Afisha\Models\Afisha::getPlaceListJson($value['id'], true); } if (count($result)) { die(json_encode(array('success' => true, 'result' => $result))); } die(json_encode(array('success' => false, 'data' => 'Ошибка поиска данных'))); }
public function mainAfisha() { // list posts $result = \Modules\Afisha\Models\Afisha::getWidgetRows(); if (count($result) == 0) { return $this->_data['mainAfisha'] = ''; } return $this->_data['mainAfisha'] = View::widget(array('result' => $result), 'MainAfisha'); }
<td width="40%"><a href="/backend/<?php echo \Core\Route::controller(); ?> /edit/<?php echo $obj->id; ?> "><?php echo $obj->name; ?> </a></td> <td width="10%"><?php echo ($obj->p_name or strlen($obj->place_name) != 0) ? \Modules\Afisha\Models\Afisha::getItemPlace($obj) : '----'; ?> </td> <td width="10%"><?php echo \Modules\Afisha\Models\Afisha::getItemPrice($obj); ?> </td> <td width="20%"><a href="/afisha/<?php echo $obj->alias; ?> " target="_blank"><?php echo $obj->alias; ?> </a></td> <td width="10%"><?php echo date('d.m.Y', $obj->event_date); ?> </td> <td><?php echo $obj->main_show ? '<span style="color: green;">Да</span>' : '<span style="color: red">Нет</span>';
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)); }
public function mapAction() { // Get afisha post and validate $item = Model::getItem(Route::param('alias')); if (!$item->id) { return Config::error(); } // Seo $this->setSeoForItem($item, true); $this->setBreadcrumbs('Схема зала'); // Get seats for available places $seats = Model::getMapSeats($item->id); // Get prices list $prices = Model::getMapPrices($item->id, true); try { $map = Map::factory(); $map->loadFile($item->p_filename); $map->addPrices($prices); $mapTpl = $map->parseDom($seats, true); } catch (\Exception $e) { if ($item->url != '') { header('Location: ' . $item->url); } else { HTTP::redirect('brone?name=' . $item->name); } exit; } $this->_content = View::tpl(array('item' => $item, 'map' => $mapTpl), 'Map/Main'); }
function editAction() { $result = DB::select()->from($this->tablename)->where('id', '=', Route::param('id'))->find(); // Set edit access for myself orders if ($result->creator_id == User::info()->id) { User::factory()->_current_access = 'edit'; } if (User::info()->role_id != 2 and $result->admin_brone == 1) { $this->no_access(); } $afisha = DB::select('afisha.*', array('places.name', 'place'), 'places.filename')->from('afisha')->join('places')->on('afisha.place_id', '=', 'places.id')->where('afisha.id', '=', $result->afisha_id)->find(); // Generate and parse inner map $orderSeats = array(); $viewKeys = array_filter(explode(',', $result->seats_keys)); if (count($viewKeys)) { $prices = DB::select()->from('prices')->where('afisha_id', '=', $result->afisha_id)->find_all(); if (count($prices)) { $pricesIds = array(); foreach ($prices as $key => $value) { $pricesIds[] = $value->id; } $seatsQuery = DB::select()->from('seats')->where('view_key', 'IN', $viewKeys)->where('price_id', 'IN', $pricesIds)->execute()->as_array(); foreach ($seatsQuery as $key => $value) { $orderSeats[$value['view_key']] = $value; } } } $seatsStr = array(); if ($afisha) { $seats = \Modules\Afisha\Models\Afisha::getMapSeats($result->afisha_id); $mapObj = Map::factory()->loadFile($afisha->filename); $innerMap = $mapObj->parseDomOrder($orderSeats, $seats, true, true); $seatsArr = array(); foreach ($seats as $seat) { $seatsArr[] = $seat['view_key']; } try { $dom = Map::factory()->loadFile($afisha->filename)->getDomInstance(); $gTag = $dom->getElementsByTagName('g'); foreach ($gTag as $el) { $id = $el->getAttribute('id'); if (in_array($id, $seatsArr)) { if ($el->parentNode->hasAttribute('data-plase')) { $place = $el->parentNode->getAttribute('data-plase'); } elseif ($el->parentNode->parentNode->hasAttribute('data-plase')) { $place = $el->parentNode->parentNode->getAttribute('data-plase'); } if ($place) { $place = str_replace('(левая сторона)', '(лев. сторона)', $place); $place = str_replace('(правая сторона)', '(пр. сторона)', $place); $seatsStr[$id] = str_replace(array('места', 'Места'), 'место', $place); $dataInit = json_decode($el->getAttribute('data-init')); $seatsStr[$id] .= $dataInit->seat; } } } } catch (\Exception $e) { die('Ошибка загрузки карты'); } } else { $innerMap = ''; $afisha = Arr::to_object(array()); } $map = View::tpl(array('map' => $innerMap), 'Map/Main'); $payer = null; if ($result->payer_id != 0) { $payer = DB::select()->from('users')->where('id', '=', $result->payer_id)->find(); } $this->_seo['h1'] = 'Заказ №' . Route::param('id'); $this->_seo['title'] = 'Заказ №' . Route::param('id'); $this->setBreadcrumbs('Заказ №' . Route::param('id'), 'backend/afisha_orders/edit/' . (int) Route::param('id')); $this->_content = View::tpl(array('obj' => $result, 'afisha' => $afisha, 'map' => $map, 'pay_statuses' => $this->pay_statuses, 'seat_statuses' => $this->seat_statuses, 'tpl_folder' => $this->tpl_folder, 'tablename' => $this->tablename, 'seatsStr' => $seatsStr, 'payer' => $payer), $this->tpl_folder . '/Inner'); }
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); }