Ejemplo 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');
 }
Ejemplo n.º 2
0
 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');
 }
Ejemplo n.º 3
0
 public function upload_imagesAction()
 {
     if (empty($_FILES['file'])) {
         die('No File!');
     }
     $confirm = false;
     $arr = explode('/', Arr::get($_SERVER, 'HTTP_REFERER'));
     $id_good = (int) end($arr);
     $headers = HTML::emu_getallheaders();
     if (array_key_exists('Upload-Filename', $headers)) {
         //                $data = file_get_contents('php://input');
         $name = $headers['Upload-Filename'];
     } else {
         $name = $_FILES['file']['name'];
     }
     $name = explode('.', $name);
     $ext = strtolower(end($name));
     if (!in_array($ext, Config::get('images.types'))) {
         die('Not image!');
     }
     $filename = Files::uploadImage('catalog');
     $has_main = DB::select(array(DB::expr('COUNT(id)'), 'count'))->from('catalog_images')->where('catalog_id', '=', $id_good)->where('main', '=', 1)->count_all();
     $data = array('catalog_id' => $id_good, 'image' => $filename);
     if (!$has_main) {
         $data['main'] = 1;
     }
     $keys = $values = array();
     foreach ($data as $key => $value) {
         $keys[] = $key;
         $values[] = $value;
     }
     DB::insert('catalog_images', $keys)->values($values)->execute();
     die(json_encode(array('confirm' => true)));
 }
Ejemplo n.º 4
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');
 }