public static function add($name, $link, $type = 0) { // Check incoming data if (!$name or !$link) { return; } // Save log return DB::insert('log', array('name', 'link', 'type', 'ip', 'created_at'))->values(array($name, $link, $type, System::getRealIP(), time()))->execute(); }
/** * @param string $table - table in witch we insert data * @param array $data - associative array with insert data * @return DB object with part of the query */ public static function insert($table, $data) { foreach ($data as $key => $value) { if ($value == 'null') { $data[$key] = DB::expr('null'); } else { $data[$key] = stripslashes($value); } } if (!isset($data['created_at']) and Common::checkField($table, 'created_at')) { $data['created_at'] = time(); } $keys = $values = array(); foreach ($data as $key => $value) { $keys[] = $key; $values[] = $value; } return DB::insert($table, $keys)->values($values); }
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 addColorSpecificationValueAction() { $post = $_POST; // Check data $name = Arr::get($post, 'name'); $color = Arr::get($post, 'color'); $alias = Arr::get($post, 'alias'); $specification_id = Arr::get($post, 'specification_id'); if (!$name or !$alias or !$specification_id or !preg_match('/^#[0-9abcdef]{6}$/', $color, $matches)) { die(json_encode(array('success' => false, 'error' => 'Вы ввели не все данные'))); } // Get count of rows with the same alias and specification_id $count = DB::select(array(DB::expr('COUNT(id)'), 'count'))->from('specifications_values')->where('specification_id', '=', $specification_id)->where('alias', '=', $alias)->count_all(); // Error if such alias exists if ($count) { die(json_encode(array('success' => false, 'error' => 'Измените алиас. Такой уже есть'))); } // Trying to save data $result = DB::insert('specifications_values', array('name', 'alias', 'specification_id', 'status', 'color'))->values(array($name, $alias, $specification_id, 1, $color))->execute(); // Error if failed saving if (!$result) { die(json_encode(array('success' => false, 'error' => 'Ошибка на сервере. Повторите попытку позднее'))); } // Get full list of values for current specification $result = DB::select()->from('specifications_values')->where('specification_id', '=', $specification_id)->order_by('name')->find_all(); $arr = array(); foreach ($result as $obj) { $arr[] = $obj; } // Answer die(json_encode(array('success' => true, 'result' => $arr))); }
/** * Add goods to cart * @param int $catalog_id - goods ID * @param int $count - count goods in the cart */ public function add($catalog_id, $size_id, $count = 1) { if (!Arr::get($this->_cart, $catalog_id . '-' . $size_id, false)) { $this->_cart[$catalog_id . '-' . $size_id] = array('id' => $catalog_id, 'size' => $size_id, 'count' => $count); DB::insert('carts_items', array('catalog_id', 'size_id', 'cart_id', 'count'))->values(array($catalog_id, $size_id, $this->_cart_id, $count))->execute(); $this->recount(); return true; } foreach ($this->_cart as $key => $item) { if ($item['id'] == $catalog_id and $item['size'] == $size_id) { $this->_cart[$key]['count'] = $this->_cart[$key]['count'] + $count; DB::update('carts_items')->set(array('count' => $this->_cart[$key]['count']))->where('cart_id', '=', $this->_cart_id)->where('catalog_id', '=', $catalog_id)->where('size_id', '=', $size_id)->execute(); $this->recount(); return true; } } return false; }
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'); }
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'); }
public function broneAction() { // Check incoming data $event_name = Text::xssClean(Arr::get($this->post, 'event_name')); if (!$event_name) { $this->error('Вы не указали название события!'); } $name = Text::xssClean(Arr::get($this->post, 'name')); if (!$name) { $this->error('Вы не указали имя!'); } if (!filter_var(Arr::get($this->post, 'email'), FILTER_VALIDATE_EMAIL)) { $this->error('Вы указали неверный E-Mail!'); } $phone = trim(Arr::get($this->post, 'phone')); if (!$phone or !preg_match('/^\\(\\d{3}\\) \\d{3}\\-\\d{2}\\-\\d{2}$/', $phone, $matches)) { $this->error('Номер телефона введен неверно!'); } $text = Text::xssClean(Arr::get($this->post, 'text')); if (!$text) { $this->error('Вы не написали текст сообщения!'); } // Create data for saving $data = array(); $data['text'] = nl2br($text); $data['ip'] = System::getRealIP(); $data['event_name'] = $event_name; $data['name'] = $name; $data['phone'] = Arr::get($this->post, 'phone'); $data['email'] = Arr::get($this->post, 'email'); $data['created_at'] = time(); // Chec for bot $check = DB::select(array(DB::expr('COUNT(brone.id)'), 'count'))->from('brone')->where('ip', '=', Arr::get($data, 'ip'))->where('created_at', '>', time() - 60)->as_object()->execute()->current(); if (is_object($check) and $check->count) { $this->error('Нельзя так часто отправлять сообщения! Пожалуйста, повторите попытку через минуту'); } // Save contact message to database $keys = array(); $values = array(); foreach ($data as $key => $value) { $keys[] = $key; $values[] = $value; } $lastID = DB::insert('brone', $keys)->values($values)->execute(); $lastID = Arr::get($lastID, 0); // Save log $qName = 'Сообщение из формы бронирования билетов'; $url = '/backend/brone/edit/' . $lastID; Log::add($qName, $url, 2); // Send E-Mail to admin $mail = DB::select()->from('mail_templates')->where('id', '=', 13)->where('status', '=', 1)->as_object()->execute()->current(); if ($mail) { $from = array('{{site}}', '{{event_name}}', '{{name}}', '{{email}}', '{{phone}}', '{{text}}', '{{ip}}', '{{date}}'); $to = array(Arr::get($_SERVER, 'HTTP_HOST'), Arr::get($data, 'event_name'), Arr::get($data, 'name'), Arr::get($data, 'email'), Arr::get($data, 'phone'), Arr::get($data, 'text'), Arr::get($data, 'ip'), date('d.m.Y H:i')); $subject = str_replace($from, $to, $mail->subject); $text = str_replace($from, $to, $mail->text); Email::send($subject, $text); } $this->success('Сообщение отправлено!'); }