Esempio n. 1
0
 public function actionAdd()
 {
     $model = new Banners();
     // Uncomment the following line if AJAX validation is needed
     //$this->performAjaxValidation($model);
     if (isset($_POST['Banners'])) {
         if ($_FILES['file']) {
             foreach ($_FILES['file']['name'] as $k => $v) {
                 if ($v) {
                     $file[$k] = CUploadedFile::getInstanceByName('file[' . $k . ']');
                     if (in_array(strtolower($file[$k]->getExtensionName()), array('jpg', 'gif', 'png', 'jpeg'))) {
                         $model->{$k} = $k . '.' . $file[$k]->getExtensionName();
                     } else {
                         $model->{$k} = CUploadedFile::getInstanceByName('file[' . $k . ']');
                     }
                 }
             }
         }
         $model->attributes = $_POST['Banners'];
         if ($model->save()) {
             if ($file) {
                 $folder = dirname(Yii::app()->request->scriptFile);
                 $folder .= '/userdata/banners/banners_' . $model->id . '/';
                 foreach ($file as $k => $v) {
                     if (in_array(strtolower($file[$k]->getExtensionName()), array('jpg', 'gif', 'png', 'jpeg'))) {
                         UploadImages::upload($file[$k]->getTempName(), $model->{$k}, $folder, 'banners', $k);
                     }
                 }
             }
             $this->redirect('/admin/banners/');
         }
     }
     $this->render('form', array('model' => $model, 'title' => 'Редактирование баннера'));
 }
Esempio n. 2
0
 public function addbanner()
 {
     $banner = new Banners();
     $banner->title = Input::get('title');
     $banner->url = Input::get('url');
     $banner->image_url = Input::get('image_url');
     $banner->save();
     return Redirect::to('backend/banners')->withMessage($this->notifyView(Lang::get('banners::messages.banner_created'), 'success'));
 }
Esempio n. 3
0
 public function actionAdd()
 {
     $this->layout = '//layouts/admin';
     $this->pageTitle = 'Новый баннер';
     $this->breadcrumbs = array('Баннеры' => array('/admin/banners'), 'Новый баннер');
     $success = false;
     if (isset($_POST['data'])) {
         $model = new Banners();
         $dataArray = $_POST['data'];
         $dataArray['is_active'] = isset($_POST['data']['is_active']) && $_POST['data']['is_active'] == 1 ? 1 : 0;
         $model->setAttributes($dataArray);
         if ($model->save()) {
             $success = true;
             if (isset($_FILES['img']) && $_FILES['img']['name']) {
                 $uploaddir = 'images/upload/' . date("d.m.Y", time());
                 if (!is_dir($uploaddir)) {
                     mkdir($uploaddir);
                 }
                 if (isset($_FILES['img'])) {
                     $tmp_name = $_FILES["img"]["tmp_name"];
                     $name = $_FILES["img"]["name"];
                     if ($name) {
                         $ext = explode(".", $name);
                         $uploadfile = $uploaddir . '/nc_' . $model->id . '_' . md5(basename($name) . time()) . "." . end($ext);
                         if (move_uploaded_file($tmp_name, $uploadfile)) {
                             $model->setAttributes(array("img" => "/" . $uploadfile));
                             $model->save();
                         }
                     }
                 }
             }
         }
     }
     if ($success) {
         $this->redirect("/admin/banners");
     }
     if (!isset($model) || !is_object($model)) {
         $model = new Banners();
     }
     $this->render('add', array("errors" => $model->errors));
 }
Esempio n. 4
0
 /**
  * Creates a new model
  * If creation is successful, the browser will be redirected to the 'view' page
  * @param integer $bannerarea
  */
 public function actionCreate($bannerarea)
 {
     $model = new Banners();
     $model->content_type = 1;
     $model->bannerarea = $bannerarea;
     $areaList = Bannerarea::createAreaList();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Banners'])) {
         $model->attributes = $_POST['Banners'];
         if ($model->save()) {
             $this->redirect(array('/banners'));
         }
     }
     $this->render('create', array('model' => $model, 'areaList' => $areaList));
 }
Esempio n. 5
0
 public function postCreatepublicacion()
 {
     $image = Input::file('image');
     $validator = Validator::make(array('image' => $image), array('image' => 'required|mimes:png,jpeg,gif'), array('mimes' => 'Tipo de imagen inválido, solo se admite los formatos PNG, JPEG, y GIF'));
     if ($validator->fails()) {
         return Redirect::to($this->route . '/createpublicacion')->with('msg_error', Lang::get('Tipo de imagen inválido, solo se admite los formatos PNG, JPEG, y GIF'));
     } else {
         $filename = Banners::upload($image);
         $type = 'publicaciones';
         $banner = new Banners();
         $banner->name = Input::get('name');
         $banner->url = Input::get('url');
         $banner->type = $type;
         $banner->status = 'draft';
         $banner->image = $filename;
         if ($banner->save()) {
             return Redirect::to($this->route . '/publicaciones')->with('msg_success', Lang::get('Publicação Adicionado'));
         } else {
             return Redirect::to($this->route . '/publicaciones')->with('msg_error', Lang::get('Publicação no Adicionado'));
         }
     }
 }
 public function saveBannerInfo()
 {
     $id = Input::get('id');
     $title = Input::get('title');
     $content = Input::get('content');
     $images = Input::file('images');
     if (empty($id)) {
         if (empty($images)) {
             return Redirect::Route('getBanners')->with('fail', 'Please choose a picture to upload.');
         } else {
             $iname = str_random(112) . '.' . $images->getClientOriginalExtension();
             $move = Image::make($images->getRealPath())->resize('750', '750')->save('images/' . $iname);
             if ($move) {
                 $getInformation = new Banners();
                 $getInformation['title'] = $title;
                 $getInformation['content'] = $content;
                 $getInformation['img'] = $iname;
                 if ($getInformation->save()) {
                     return Redirect::Route('getBanners')->with('success', 'Information successfully added.');
                 }
             } else {
                 return Redirect::Route('getBanners')->with('fail', 'Error Uploading! Please try again.');
             }
         }
     } else {
         if (empty($images)) {
             $getInformation = Banners::find($id);
             $getInformation['title'] = $title;
             $getInformation['content'] = $content;
             if ($getInformation->save()) {
                 return Redirect::Route('getBanners')->with('success', 'Information successfully added.');
             }
         } else {
             $iname = str_random(112) . '.' . $images->getClientOriginalExtension();
             $move = Image::make($images->getRealPath())->resize('750', '750')->save('images/' . $iname);
             if ($move) {
                 $getInformation = Banners::find($id);
                 $getInformation['title'] = $title;
                 $getInformation['content'] = $content;
                 $getInformation['img'] = $iname;
                 if ($getInformation->save()) {
                     return Redirect::Route('getBanners')->with('success', 'Information successfully added.');
                 }
             } else {
                 return Redirect::Route('getBanners')->with('fail', 'Error Uploading! Please try again.');
             }
         }
     }
 }
 public function postAction()
 {
     $bid = Arr::get($_POST, 'bid');
     $image = Arr::get($_POST, 'image', null);
     $imgList = Arr::get($_POST, 'imglist', array());
     $size = Arr::get($_POST, 'size', 'small');
     $title = Arr::get($_POST, 'title', 'unknown');
     $link = Arr::get($_POST, 'link', '#');
     $target = Arr::get($_POST, 'target', '_self');
     $start = Arr::get($_POST, 'on_time', 0);
     $end = Arr::get($_POST, 'off_time', 0);
     $status = Arr::get($_POST, 'status', '1');
     if ($image == null) {
         return Redirect::route('admin.banners.list', array($size, 'message' => 'error'));
     }
     $m = $bid != 'null' ? $m = Banners::find($bid) : null;
     if ($m == null) {
         $m = new Banners();
         $m->created_at = date('Y-m-d H:i:s');
     }
     $start = empty($start) ? 0 : strtotime($start);
     $end = empty($end) ? 0 : strtotime($end);
     $m->title = $title;
     $m->image = $image;
     $m->size = $size;
     $m->link = $link;
     $m->target = $target;
     $m->on_time = $start;
     $m->off_time = $end;
     $m->status = $status;
     $m->updated_at = date('Y-m-d H:i:s');
     $bool = $m->save();
     $list = explode($imgList, '=sep=');
     foreach ($list as $item) {
         if (md5($item) != md5($image)) {
             fps::getInstance()->delete($item);
         }
     }
     return Redirect::route('admin.banners.list', array($size, 'message' => 'success'));
 }