public function createAction() { $this->view->Title = "Quản lý quảng cáo"; $this->view->headTitle($this->view->Title); if ($this->getRequest()->isPost()) { $request = $this->getRequest()->getParams(); $Banner = new Banner(); $Banner->merge($request); if ($Banner->trySave()) { $folder = $Banner->id; } if ($_FILES['images']['name']) { $dirname = "uploads/banner/" . $folder . "/"; $upload = new My_Plugin_Upload(); $error = $upload->uploadImageFile($_FILES['images'], 2048, 1024, 1024000, array("image/png", "image/jpg", "image/gif", "image/x-png", "image/jpeg"), $dirname); if (!$error) { $filename = $upload->fileName; } } if (count($error) == 0) { if ($filename != "") { $Banner->image = $filename; } $Banner->save(); $this->Member->log('Quảng cáo:' . $Banner->name . '(' . $Banner->id . ')', 'Tạo mới'); My_Plugin_Libs::setSplash('Quảng cáo: <b>' . $Banner->name . '</b> đã tạo thành công. '); $this->_redirect($this->_helper->url('index', 'banner', 'admin')); } if (count($error)) { $this->view->error = $error; } } }
function active($id) { $banners = new Banner($id); if (!$banners->exists()) { show_404(); } $banners->active = ($banners->active + 1) % 2; if ($banners->save()) { flash_message('success', 'Thành công. Thao tác đã được thực hiện.'); redirect($this->admin . 'banners/list_all/'); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Banner(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Banner'])) { $model->attributes = $_POST['Banner']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Banner(); $this->tituloManual = "Cadastrar banner"; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Banner'])) { $model->attributes = $_POST['Banner']; if ($model->save()) { $this->redirect(array('index')); } } $this->render('create', array('arrayTipoSabor' => TipoSabor::getArrayTipoSabor(), 'model' => $model)); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // $authuser = Auth::user(); if (!File::exists('images/banners/')) { $result = File::makeDirectory('images/banners/', 0777); } $rules = array('seccion' => 'required', 'imagen' => 'required|mimes:png,gif,jpeg,txt,pdf,doc,rtf|max:200000000'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('vistausuario/banners/create')->withErrors($validator)->withInput(); } else { $file = Input::file('imagen'); $id = Str::random(4); $date_now = new DateTime(); $destinationPath = 'images/banners/'; $filename = $date_now->format('YmdHis') . $id; $mime_type = $file->getMimeType(); $extension = $file->getClientOriginalExtension(); $upload_success = $file->move($destinationPath, $filename . '.' . $extension); $banner = new Banner(); $banner->usuario_id = $authuser->id; $banner->banner_img = $filename . '.' . $extension; $banner->solicitar_habilitar = 1; $banner->habilitar = 0; $banner->link = Input::get('link'); $banner->seccion = Input::get('seccion'); $banner->save(); //TODO: Crear pago pendiente //Generar row en cobros y cobros_pendientes //'BLOG-IZQUIERDA' => 'BLOG - IZQUIERDA', 'BLOG-DERECHA' => 'BLOG - DERECHA','DIRECTORIO-IZQUIERDA' => 'DIRECTORIO - IZQUIERDA', 'DIRECTORIO-DERECHA' => 'DIRECTORIO - DERECHA','EVENTOS-IZQUIERDA' => 'EVENTOS - IZQUIERDA', 'EVENTOS-DERECHA' => 'EVENTOS - DERECHA','CLASIFICADOS-IZQUIERDA' => 'CLASIFICADOS - IZQUIERDA', 'CLASIFICADOS-DERECHA' => 'CLASIFICADOS - DERECHA','VIDEOBLOG-IZQUIERDA' => 'VIDEOBLOG - IZQUIERDA', 'VIDEOBLOG-DERECHA' => 'VIDEOBLOG - DERECHA' $cobrotipoBanner = CobroTipo::where('tipo', 'BANNER-' . Input::get('seccion'))->first(); $cobro = new Cobro(); $cobro->tipo_id = $cobrotipoBanner->id; $cobro->usuario_id = $authuser->id; $cobro->estado = 'pendiente'; $cobro->datosAdicionales = $banner->id; $cobro->save(); $id = Str::random(4); $date_now = new DateTime(); $cobrop = new CobroPendiente(); $cobrop->cobro_id = $cobro->id; $cobrop->fecha = $date_now; $cobrop->cobro_concepto = 'TODCONS' . $cobro->id . 'BANN' . $banner->id . $date_now->format('YmdHi') . $id; // Concepto = clave_empresa+ clave_cobro+ clave_tipo_cobro + clave_objeto_de_cobro + fecha+4_digitos_random (Por favor mejorar!!) $cobrop->save(); return Redirect::to("vistausuario/banners")->with(array('usuarioimg' => $authuser->imagen, 'usuarionombre' => $authuser->nombre, 'usuarioid' => $authuser->id)); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $rules = ['empresa' => 'required', 'file' => 'required']; if (!Banner::isValid(Input::all(), $rules)) { return Redirect::back()->withInput()->withErrors(Banner::$errors); } $banner = new Banner(); $banner->empresa = Input::get('empresa'); $banner->file = Input::get('file'); $banner->link = Input::get('link'); $banner->posicion = Input::get('posicion'); $banner->activo = Input::get('activo'); $banner->save(); return Redirect::to('/banners'); }
/** * 录入 * */ public function actionCreate() { parent::_acl('banner_create'); $model = new Banner(); if (isset($_POST['Banner'])) { $file = XUpload::upload($_FILES['attach']); $model->attributes = $_POST['Banner']; if (is_array($file)) { $model->image = $file['pathname']; } if ($model->save()) { AdminLogger::_create(array('catalog' => 'create', 'intro' => '录入banner,ID:' . $model->id)); $this->redirect(array('index')); } } $this->render('create', array('model' => $model)); }
public function actionAdd() { if (empty($_POST)) { $stations = Banner::model()->getBannertSation(); $viewData = array(); $viewData['stations'] = $stations; $this->render('add', $viewData); exit; } $res = array('statusCode' => 200, 'message' => '添加成功!'); try { $banner_name = ''; $image = CUploadedFile::getInstanceByName('banner_image'); if ($image) { $dir = Yii::getPathOfAlias('webroot') . '/images/banner'; // $extension = substr(strrchr($image->name, '.'), 1); $extension = $image->getExtensionName(); $banner_name = time() . '_' . rand(100, 999) . '.' . $extension; $imagePath = $dir . '/' . $banner_name; $image->saveAs($imagePath, true); } $m = new Banner(); $m->title = $_REQUEST['title']; $m->station = $_REQUEST['station']; $m->img = $banner_name; $m->link = $_REQUEST['link']; $m->sort = $_REQUEST['sort']; $m->is_show = $_REQUEST['is_show']; $m->start_time = strtotime($_REQUEST['start_time']); $m->end_time = strtotime($_REQUEST['end_time']); $m->add_time = time(); $flag = $m->save(); if (!$flag) { throw new exception('添加失败'); } } catch (Exception $e) { $res['statusCode'] = 300; $res['message'] = '失败【' . $e->getMessage() . '】'; } $res['navTabId'] = 'bannerList'; $res['callbackType'] = 'closeCurrent'; $res['forwardUrl'] = '/manage/banner/index'; $this->ajaxDwzReturn($res); }
public function insert() { $rules = array('image_banner' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('admin/addbanner')->withErrors($validator)->withInput(); } else { $image = explode(url() . '/', Input::get('image_banner')); $realpath = public_path($image[1]); $newname = date('YmdHis') . '.jpg'; File::move($realpath, 'images/slider/' . $newname); // insert to db $banner = new Banner(); $banner->image = 'images/slider/' . $newname; $banner->save(); Session::flash('success', 'New banner created'); return Redirect::to('admin/banners'); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // $validation = Validate::BannerValidation(Input::all()); if ($validation->fails()) { return Redirect::to('banner/create')->withErrors($validation)->withInput(); } else { $banner = new Banner(); $banner->title = Input::get('title'); $banner->image = ""; $banner->save(); mkdir("img/banners/" . $banner->id, 0700); $destinationPath = 'img/banners/' . $banner->id; $filename = $banner->id . "." . Input::file('image')->getClientOriginalExtension(); Input::file('image')->move($destinationPath, $filename); $banner2 = Banner::find($banner->id); $banner2->image = 'img/banners/' . $banner->id . "/" . $filename; $banner2->save(); return Redirect::to('admin/banner'); } }
public function banners($do = '', $id = '') { $this->data['heading'] = 'Administrasi: Banner'; switch ($do) { case 'form': if (post('submit')) { $data = [User::primary() => 1, 'tgl_input' => date('Y-m-d'), 'judul' => post('judul'), 'keterangan' => post('keterangan'), 'url' => post('url'), 'gambar' => post('gambar'), 'tgl_mulai' => formatTanggal(post('tgl_mulai'), 'Y-m-d'), 'tgl_akhir' => formatTanggal(post('tgl_akhir'), 'Y-m-d'), 'aktif' => post('aktif'), 'tipe' => post('tipe')]; try { $upload = new Upload('gambar'); $data['gambar'] = $upload->doUpload(); } catch (Exception $e) { setAlert('error', $e->getMessage()); } if (Banner::save($data, $id)) { if ($id) { setAlert('success', 'Berhasil memperbarui data banner <b>' . $data['judul'] . '</b>'); } else { setAlert('success', 'Berhasil menambahkan banner <b>' . $data['judul'] . '</b>'); } return redirect('admin-shop/banners'); } setAlert('error', 'Terjadi kesalahan dalam penyimpanan banner <b>' . $data['judul'] . '</b>'); return redirect($this->uri->path()); } else { if ($id) { $this->data['data'] = Banner::show([Banner::primary() => $id])->fetchOne(); } return $this->render('banner-form', $this->data); } break; case 'delete': if (Banner::del([Banner::primary() => $id])) { setAlert('success', 'Banner berhasil terhapus'); } else { setAlert('error', 'Terjadi kesalahan dalam penghapusan banner'); } return redirect('admin-shop/banners'); break; default: $this->data['data'] = Banner::show(); return $this->render('banner-table', $this->data); break; } }
function upload_file($origin, $dest, $tmp_name, $overwrite = false) { FileManagerController::_checkPermission(); $origin = basename($origin); $full_dest = $dest . $origin; $file_name = $origin; for ($i = 1; file_exists($full_dest); $i++) { if ($overwrite) { unlink($full_dest); continue; } $file_ext = strpos($origin, '.') === false ? '' : '.' . substr(strrchr($origin, '.'), 1); $file_name = substr($origin, 0, strlen($origin) - strlen($file_ext)) . '_' . $i . $file_ext; $full_dest = $dest . $file_name; } if (move_uploaded_file($tmp_name, $full_dest)) { //Add Banner to database $data = $_POST['banner']; Flash::set('post_data', (object) $data); $last_banner = Record::query('Select sequence from ' . TABLE_PREFIX . 'banner order by sequence desc LIMIT 0,1'); $last_banner = $last_banner->fetchObject(); $last_seq = $last_banner->sequence; $banner = new Banner($data); $banner->filename = $file_name; $banner->source = URL_PUBLIC . 'public/banner/' . $file_name; $banner->sequence = $last_seq + 1; if (!$banner->save()) { Flash::set('error', __('Banner has not been added. Name must be unique!')); redirect(get_url('banner', 'add')); } else { Flash::set('success', __('Banner has been added!')); //Observer::notify('snippet_after_add', $banner); } // change mode of the dire to 0644 by default chmod($full_dest, 0644); return $file_name; } return false; }
/** * Processes the new banner and redirects to the banner list */ public function banner_new() { // get the validated input $input = $this->__validate($_POST); // attempt to upload the image if (!$input['image'] = $this->__upload('banner',$input)) $this->display('banner/views/edit',$input); // set the created date $input['created'] = date('Y-m-d H:i:s'); $input['updated'] = date('Y-m-d H:i:s'); // save the new banner, if there is an issue delete the uploaded image $record = new Banner($input); if (!$record->save()) { $fullpath = CMS_ROOT."/{$this->settings['imgpath']}/{$input['image']}"; if (!unlink($fullpath)) { Flash::set('error','Banners - '.__('Could not save banner in database and permission denied deleting image!')); $this->display('banner/views/edit',$input); } Flash::set('error','Banners - '.__('Could not save banner in database!')); $this->display('banner/views/edit',$input); } // pat on the back and send back to banner list Flash::set('success','Banners - '.__('banner saved!')); redirect(get_url('plugin/banner/banner_list')); }//*/
function banner_save() { if ($_POST) { $banner = new Banner($id); $_POST['status'] = "approve"; $_POST['start_date'] = Date2DB($_POST['start_date']); $_POST['end_date'] = Date2DB($_POST['end_date']); $banner->from_array($_POST); $banner->save(); set_notify('success', lang('save_data_complete')); } redirect('home/banner'); }
public function updateBanner() { if (Input::has('pk')) { if (!Request::ajax()) { return App::abort(404); } return self::updateQuickEdit(); } else { if (!Request::ajax()) { return App::abort(404); } } $arrReturn = ['status' => 'error']; $banner = new Banner(); $banner->name = Input::get('name'); $banner->order_no = (int) Input::get('order_no'); $banner->active = Input::has('active') ? 1 : 0; if (Input::hasFile('image')) { $oldPath = $banner->image; $path = VIImage::upload(Input::file('image'), public_path('assets' . DS . 'images' . DS . 'banners'), 1440, false); $path = str_replace(public_path() . DS, '', $path); $banner->image = str_replace(DS, '/', $path); if ($oldPath == $banner->image) { unset($oldPath); } } $pass = $banner->valid(); if ($pass) { $banner->save(); if (isset($oldPath) && File::exists(public_path($oldPath))) { File::delete(public_path($oldPath)); } $arrReturn = ['status' => 'ok']; $arrReturn['message'] = $banner->name . ' has been saved'; $arrReturn['data'] = $banner; } else { $arrReturn['message'] = ''; $arrErr = $pass->messages()->all(); foreach ($arrErr as $value) { $arrReturn['message'] .= "{$value}\n"; } } $response = Response::json($arrReturn); $response->header('Content-Type', 'application/json'); return $response; }
public function add_banner() { try { $banner_title = Input::get("banner_title"); $banner_description = Input::get("banner_description"); $banner_order = Input::get("banner_order"); $destinationPath_Banner = 'asserts/images/Banner'; $banner_images = null; if (Input::hasfile("file")) { $file_Banner = Input::file("file"); $banner_images = $file_Banner->getClientOriginalName(); $upload_success_banner = $file_Banner->move($destinationPath_Banner, $banner_images); } $_banner = new Banner(); $_banner->banner_title = $banner_title; $_banner->banner_description = $banner_description; $_banner->banner_images = $banner_images; $_banner->banner_order = $banner_order; $_banner->save(); } catch (Exception $_ex) { Session::flash('error', '$$$ --- Error Banner -' . $banner_title . '(' . $_ex->getMessage() . ') --- $$$'); } Session::flash('success', '$$$ --- Add - ' . $banner_title . ' Successfully --- $$$'); return Redirect::to('qlm-admin/add-new-banner'); }
public function actionCrearbanner() { $banner = new Banner(); if (isset($_POST['Banner'])) { $banner->attributes = $_POST['Banner']; if (isset(Yii::app()->session['bn'])) { $bn = Yii::app()->session['bn']; } $banner->imagen = $_POST['Banner']['imagen'] != '' ? $bn . $_POST['Banner']['imagen'] : NULL; $banner->imagen_mobile = $_POST['Banner']['imagen_mobile'] != '' ? $bn . $_POST['Banner']['imagen_mobile'] : NULL; if (empty($_POST['Banner']['fin_contador']) || $_POST['Banner']['fin_contador'] == '0000-00-00 00:00:00') { $banner->fin_contador = NULL; } if (empty($_POST['Banner']['inicio_publicacion']) || $_POST['Banner']['inicio_publicacion'] == '0000-00-00 00:00:00') { $banner->inicio_publicacion = NULL; } if (empty($_POST['Banner']['fin_publicacion']) || $_POST['Banner']['fin_publicacion'] == '0000-00-00 00:00:00') { $banner->fin_publicacion = NULL; } if ($banner->save()) { Yii::app()->user->setFlash('success', 'Banner ' . $banner->nombre . ' guardado con éxito'); $this->redirect(array('viewbanner', 'id' => $banner->getPrimaryKey())); } //if($banner->save()) } //if(isset($_POST['Banner'])) // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $this->render('crearBanner', array('model' => $banner)); }