Exemplo n.º 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     Yii::app()->bootstrap->registerJS();
     Yii::app()->bootstrap->registerJSBackend();
     $model = new Slideshow();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Slideshow'])) {
         $model->attributes = $_POST['Slideshow'];
         $imageArray = explode('/', $model->image);
         $getInstall = end($imageArray);
         $model->image = $getInstall;
         $model->datecreate = date_create()->format('Y-m-d H:i:s');
         $model->usercreate = Yii::app()->user->id;
         if ($model->save()) {
             Yii::app()->user->setFlash('createSlide', 'Tạo Slideshow thành công');
         }
         $this->refresh();
     }
     $this->render('create', array('model' => $model));
 }
Exemplo n.º 2
0
 public function postSlideHome($type)
 {
     if (\Request::ajax()) {
         if (isset($_POST["action"]) && $_POST["action"] == "delete") {
             $post = \Post::find($_POST["id"]);
             $isparent = \Post::where("parent_id", $post->id);
             if (count($isparent) > 0) {
                 echo "You cannot delete this record it is associated with a page or pageblock";
             } else {
                 if ($post->delete()) {
                     \Session::put("success_message", $post->title . " Succesfully Deleted");
                     if ($_POST['type'] == "slideshow") {
                         $image = \Slideshow::where("img_name", $_POST["image"])->first();
                         $image->status = 0;
                         $image->update();
                     }
                     echo "record successfully deleted";
                 } else {
                     \Session::put("error_message", $post->title . " Unexpected Error! Record could not be deleted");
                     echo "Unexpected Error! Record could not be deleted";
                 }
             }
         }
         if ($type == "slideimage") {
             $ds = DIRECTORY_SEPARATOR;
             //1
             $storeFolder = './uploads/slideshow';
             //stores file in slider folder in uploads
             if (!empty($_FILES)) {
                 $tempFile = $_FILES['file']['tmp_name'];
                 //3
                 $targetPath = $storeFolder . $ds;
                 //4
                 $targetFile = $targetPath . $_FILES['file']['name'];
                 //5
                 if (move_uploaded_file($tempFile, $targetFile)) {
                     $image = new \Slideshow();
                     $image->img_name = basename($_FILES['file']['name']);
                     $image->size = $_FILES['file']['size'];
                     $image->save();
                 }
             }
         }
         exit;
     }
     if ($type == "slidepost") {
         //not longeer function all post route through postAddPage method
         $validation = \Post::validate(\Input::all());
         $input = \Input::all();
         if ($validation->fails()) {
             if ($input['type'] == "page") {
                 return \Redirect::back()->withErrors($validation)->withInput();
             } elseif ($input['type'] == "post") {
                 return \Redirect::back()->withErrors($validation)->withInput();
             } elseif ($input['type'] == "category") {
                 return \Redirect::back()->withErrors($validation)->withInput();
             } elseif ($input['type'] == "custom menu") {
                 return \Redirect::back()->withErrors($validation)->withInput();
             }
         } else {
             $post = new \Post();
             isset($_POST['description']) ? $post->description = \Input::get("description") : "";
             $post->title = $input['title'];
             $post->p_content = $input['p_content'];
             $post->permalink = $input['permalink'];
             $post->type = $input['type'];
             $post->parent_id = $input['parent_id'];
             $post->image = isset($_POST['image']) ? $input['image'] : "";
             //$post->view_status      =   $input['view_status'];
             $post->created_by = "Admin";
             $post->meta_keyword = $input['meta_keyword'];
             $post->meta_description = $input['meta_description'];
             $post->meta_title = $input['meta_title'];
             //$post->image            =   (isset($file) && $file != "") ? $file : "";
             //var_dump($post);
             try {
                 $post = $post->save();
                 // $redirect = (isset($input['form_save'])) ? "backend/{$input['type']}s" : "backend/{$input['type']}s/create";
                 return \Redirect::back()->with('success_message', 'The ' . $input["type"] . ' was created.');
             } catch (ValidationException $e) {
                 return \Redirect::back()->withInput()->withErrors($e->getErrors());
             }
         }
     } elseif ($type == "pageblockimage") {
         // this procedure is used to add page block image
         $ds = DIRECTORY_SEPARATOR;
         //1
         $storeFolder = './uploads';
         //stores file in slider folder in image
         if (!empty($_FILES)) {
             $tempFile = $_FILES['file']['tmp_name'];
             //3
             $targetPath = $storeFolder . $ds;
             //4
             $targetFile = $targetPath . $_FILES['file']['name'];
             //5
             if (move_uploaded_file($tempFile, $targetFile)) {
                 echo "Image Uploaded";
                 exit;
             }
         }
     }
 }