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('/'); }
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 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); }
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'); }
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'); }
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'); }
public function setStatusMassAction() { if (!isset($_POST['ids'])) { die('Не указаны данные записи'); } $status = (int) Arr::get($_POST, 'status', 0); $ids = Arr::get($_POST, 'ids', 0); $table = Arr::get($_POST, 'table', 0); if (!empty($ids)) { DB::update($table)->set(array('status' => $status))->where('id', 'IN', $ids)->execute(); Message::GetMessage(1, 'Статусы изменены!'); } die(json_encode(array('success' => true))); }
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'); }
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)->find(); if (!$page) { Message::GetMessage(0, 'Данные не существуют!'); HTTP::redirect('backend/' . Route::controller() . '/index'); } DB::delete($this->tablename)->where('id', '=', $id)->execute(); Message::GetMessage(1, 'Данные удалены!'); HTTP::redirect('backend/' . Route::controller() . '/index'); }
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)->find(); if (!$page) { Message::GetMessage(0, 'Данные не существуют!'); HTTP::redirect('backend/' . Route::controller() . '/index'); } $images = DB::select()->from('catalog_images')->where('catalog_id', '=', $id)->find_all(); foreach ($images as $im) { @unlink(HOST . HTML::media('images/catalog/small/' . $im->image)); @unlink(HOST . HTML::media('images/catalog/medium/' . $im->image)); @unlink(HOST . HTML::media('images/catalog/big/' . $im->image)); @unlink(HOST . HTML::media('images/catalog/original/' . $im->image)); } DB::delete($this->tablename)->where('id', '=', $id)->execute(); Message::GetMessage(1, 'Данные удалены!'); HTTP::redirect('backend/' . Route::controller() . '/index'); }
public function registrationAction() { // Check incoming data $email = Arr::get($this->post, 'email'); if (!$email or !filter_var($email, FILTER_VALIDATE_EMAIL)) { $this->error('Вы неверно ввели E-Mail!'); } $user = DB::select()->from('users')->where('email', '=', $email)->as_object()->execute()->current(); if ($user) { if ($user->status) { $this->error('Пользователь с указанным E-Mail адресом уже зарегистрирован!'); } $this->error('Пользователь с указанным E-Mail адресом уже зарегистрирован, но либо заблокирован либо не подтвердил свой E-Mail адрес. Пожалуйста обратитесь к Администратору для решения сложившейся ситуации'); } $password = trim(Arr::get($this->post, 'password')); if (mb_strlen($password, 'UTF-8') < conf::get('main.password_min_length')) { $this->error('Пароль не может содержать меньше ' . conf::get('main.password_min_length') . ' символов!'); } $agree = Arr::get($this->post, 'agree'); if (!$agree) { $this->error('Вы должны принять условия соглашения для регистрации на нашем сайте!'); } // Create user data $data = array('email' => $email, 'password' => $password, 'ip' => System::getRealIP()); // Create user. Then send an email to user with confirmation link or authorize him to site $mail = DB::select()->from('mail_templates')->where('id', '=', 4)->where('status', '=', 1)->as_object()->execute()->current(); if ($mail) { // Creating of the new user and set his status to zero. He need to confirm his email $data['status'] = 0; User::factory()->registration($data); $user = DB::select()->from('users')->where('email', '=', $email)->as_object()->execute()->current(); // Save log $qName = 'Регистрация пользователя, требующая подтверждения'; $url = '/backend/users/edit/' . $user->id; Log::add($qName, $url, 1); // Sending letter to email $from = array('{{site}}', '{{ip}}', '{{date}}', '{{link}}'); $to = array(Arr::get($_SERVER, 'HTTP_HOST'), Arr::get($data, 'ip'), date('d.m.Y'), 'http://' . Arr::get($_SERVER, 'HTTP_HOST') . '/user/confirm/hash/' . $user->hash); $subject = str_replace($from, $to, $mail->subject); $text = str_replace($from, $to, $mail->text); Email::send($subject, $text, $user->email); // Inform user if mail is sended $this->success('Вам отправлено письмо подтверждения со ссылкой, кликнув по которой, Вы подтвердите свой адрес и будете автоматически авторизованы на сайте.'); } else { // Creating of the new user and set his status to 1. He must be redirected to his cabinet $data['status'] = 1; User::factory()->registration($data); $user = DB::select()->from('users')->where('email', '=', $email)->as_object()->execute()->current(); // Save log $qName = 'Регистрация пользователя'; $url = '/backend/users/edit/' . $user->id; Log::add($qName, $url, 1); // Authorization of the user User::factory()->auth($user, 0); Message::GetMessage(1, 'Вы успешно зарегистрировались на сайте! Пожалуйста укажите остальную информацию о себе в личном кабинете для того, что бы мы могли обращаться к Вам по имени'); $this->success(array('redirect' => '/user')); } }
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; }
function deleteAction() { $id = (int) Route::param('id'); $page = Model::getRow($id); if (!$page) { Message::GetMessage(0, 'Данные не существуют!'); HTTP::redirect('backend/' . Route::controller() . '/index'); } Model::delete($id); Message::GetMessage(1, 'Данные удалены!'); HTTP::redirect('backend/' . Route::controller() . '/index'); }
/** * @param array $data * @return bool */ public static function valid($data = array()) { if (!static::$rules) { return TRUE; } $valid = new Valid($data, static::$rules); $errors = $valid->execute(); if (!$errors) { return TRUE; } $message = Valid::message($errors); Message::GetMessage(0, $message, FALSE); return FALSE; }
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'); }
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'); } }
function archiveAction() { $id = (int) Route::param('id'); $page = Model::getRow($id); if (!$page) { Message::GetMessage(0, 'Данные не существуют!'); HTTP::redirect('backend/' . Route::controller() . '/index'); } if ($page->deleted) { Message::GetMessage(1, 'Данные уже в архиве!'); HTTP::redirect('backend/archive/admins'); } Model::update(Model::$table, array('deleted' => 1))->where('id', '=', $id)->execute(); Message::GetMessage(1, 'Данные перемещены в архив!'); HTTP::redirect('backend/' . Route::controller() . '/index'); }