function addAction() { if ($_POST) { $post = $_POST['FORM']; $post['status'] = Arr::get($_POST, 'status', 0); $post['main_show'] = Arr::get($_POST, 'main_show', 0); $post['event_date'] = strtotime(Arr::get($_POST['FORM'], 'event_date') . ' ' . Arr::get($_POST['FORM'], 'event_time')); $post['place_id'] = Arr::get($post, 'place_id', null); if ($post['place_id'] == 'another') { $post['place_id'] = 'null'; } else { $post['city_id'] = 'null'; } 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(); $places = $_POST['PLACES']; // Get list places if (count($places['cost']) > 1) { foreach ($places['cost'] as $key => $cost) { if ($cost == '') { continue; } // insert new price $resPrice = DB::insert('prices', array('afisha_id', 'price', 'color'))->values(array($res[0], $cost, $places['color'][$key]))->execute(); // insert all places (seats) if ($resPrice and $places['place'][$key] != '') { $priceId = $resPrice[0]; $seatsStr = $places['place'][$key]; $seatsArr = json_decode($seatsStr); if (count($seatsArr)) { foreach ($seatsArr as $seat) { DB::insert('seats', array('price_id', 'view_key', 'status', 'reserved_at'))->values(array($priceId, $seat->view_key, $seat->status, $seat->reserved_at))->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'); $cities = array(); $citiesObj = DB::select()->from('cities')->find_all(); foreach ($citiesObj as $key => $city) { $cities[$key]['name'] = $city->name; $cities[$key]['places'] = DB::select()->from('places')->where('city_id', '=', $city->id)->find_all(); } $this->_content = View::tpl(array('obj' => $result, 'cities' => $cities, 'tpl_folder' => $this->tpl_folder, 'places_list' => DB::select()->from('places')->where('status', '=', 1)->find_all(), 'tablename' => $this->tablename, 'organizers' => DB::select()->from('users')->where('status', '=', 1)->where('role_id', '=', 9)->find_all()), $this->tpl_folder . '/Form'); }
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 { if (!trim(Arr::get($post, 'alias'))) { Message::GetMessage(0, 'Алиас не может быть пустым!'); } else { if (!trim(Arr::get($post, 'brand_id'))) { Message::GetMessage(0, 'Модель не может существовать без бренда!'); } else { $post['alias'] = Common::getUniqueAlias($this->tablename, Arr::get($post, 'alias')); $res = Common::insert($this->tablename, $post)->execute(); if ($res) { 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, 'brands' => DB::select()->from('brands')->order_by('name')->find_all()), $this->tpl_folder . '/Form'); }
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'); }
function addAction() { if ($_POST) { $post = $_POST['FORM']; $post['status'] = Arr::get($_POST, 'status', 0); $post['show_image'] = Arr::get($_POST, 'show_image', 0); 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) { $filename = Files::uploadImage('news'); 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'); }
function addAction() { if ($_POST) { $error = 0; $post = $_POST['FORM']; $post['status'] = Arr::get($_POST, 'status', 0); if (!trim(Arr::get($post, 'name'))) { Message::GetMessage(0, 'Наименование страницы не может быть пустым!'); $error = 1; } if (!trim(Arr::get($post, 'alias'))) { Message::GetMessage(0, 'Алиас не может быть пустым!'); $error = 1; } if (!$error) { $post['alias'] = Common::getUniqueAlias($this->tablename, Arr::get($post, 'alias')); $res = Common::insert($this->tablename, $post)->execute(); if ($res) { Message::GetMessage(1, 'Вы успешно добавили данные!'); HTTP::redirect('backend/' . Route::controller() . '/' . Route::action()); } else { Message::GetMessage(0, 'Не удалось добавить данные!'); } } $result = Arr::to_object($post); } else { $result = array(); } $this->_toolbar = Widgets::get('Toolbar/Edit'); Config::set('colls', 'column-2'); $this->_seo['h1'] = 'Добавление'; $this->_seo['title'] = 'Добавление'; $this->setBreadcrumbs('Добавление', 'backend/' . Route::controller() . '/' . Route::action()); $this->_content = View::tpl(array('obj' => $result, 'tpl_folder' => $this->tpl_folder, 'tablename' => $this->tablename, 'tree' => Support::getSelectOptions('Content/Select', 'content', $result->parent_id)), $this->tpl_folder . '/Form'); }