예제 #1
0
            if ($model->save()) {
                if (isset($_POST['delete_current_image']) && $_POST['delete_current_image'] == 'on') {
                    $model->removeImage();
                }
                $model->saveImage();
                $this->redirect(array('view', 'id' => $model->id));
            }
        }
        $this->render('update', array('model' => $model, 'actions' => $this->listActionsCanAccess));
    }
    /**
	 * Deletes a particular model.
	 * If deletion is successful, the browser will be redirected to the 'admin' page.
	 * @param integer $id the ID of the model to be deleted
	 */
    public function actionDelete($id)
    {
        if (Yii::app()->request->isPostRequest) {
            // we only allow deletion via POST request
            $model = $this->loadModel($id);
            if (!empty($model->large_image)) {
                $ImageProcessing = new ImageProcessing();
                $ImageProcessing->delete(YII_UPLOAD_DIR . '/' . Banners::$folderUpload . "/" . $model->large_image);
                //                                $ImageProcessing->delete(Banners::$folderUpload."/".$model->large_image);
                //                                $ImageProcessing->delete(Banners::$folderUpload."/thumbs/".$model->large_image);
            }
예제 #2
0
 //            }
 //        }
 //        else{
 //             if ($this->banner_type == TOP || $this->banner_type == BOTTOM) {
 //                $ImageProcessing->file = $this->large_image;
 //                $ImageProcessing->thumbs = self::$aSizeBannerTop;    //resize Of banner
 //                $ImageProcessing->create_thumbs();
 //             }
 //             else{
 //                 $ImageProcessing->file = $this->large_image;
 //                $ImageProcessing->thumbs = self::$aSizeBannerMiddle;    //resize Of banner
 //                $ImageProcessing->create_thumbs();
 //             }
 /**
  * Apr 01, 2014 - ANH DUNG
  * To do: delete file  of model ProTransactionsVendorPurchaserDetail
  * @param: $model ProTransactionsVendorPurchaserDetail
  * @param: $nameField ex: upload_employment_pass_passport
  * @param: $pathUpload ex: 'upload/tenant' 
  */
 public static function deleteOldFile($model, $nameField)
 {
     $pathUpload = self::$folderUpload;
     $modelDel = self::model()->findByPk($model->id);
     if (is_null($modelDel) || empty($modelDel->{$nameField})) {
         return;
     }
     $ImageProcessing = new ImageProcessing();
     $ImageProcessing->folder = '/' . $pathUpload . '/' . $modelDel->id;
     $ImageProcessing->delete($ImageProcessing->folder . '/' . $modelDel->{$nameField});
 }
 /**
  * @Author: ANH DUNG  Apr 01, 2014
  * @Todo: only remove file of transaction
  * @Param: $modelDel is model ProTransactionsPropertyDocument     
  */
 public static function removeFile($modelDel)
 {
     $ImageProcessing = new ImageProcessing();
     $ImageProcessing->folder = '/' . self::$folderUpload . '/' . $modelDel->transactions_id;
     $ImageProcessing->delete($ImageProcessing->folder . '/' . $modelDel->file_name);
 }
예제 #5
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     try {
         $model = Pages::model()->findbyPk($id);
         $model->scenario = 'update';
         // Uncomment the following line if AJAX validation is needed
         // $this->performAjaxValidation($model);
         $old_image = $model->featured_image;
         $old_home_page = $model->thumb_image;
         if (isset($_POST['Pages'])) {
             $oldImg = $model->banner;
             $model->attributes = $_POST['Pages'];
             $uploadFile = CUploadedFile::getInstance($model, 'banner');
             $model->parent_id = $_POST['Pages']['parent_id'];
             //                $model->show_footer = $_POST['Pages']['show_footer'];
             //                $model->show_home_page = $_POST['Pages']['show_home_page'];
             //                $model->short_content = $_POST['Pages']['short_content'];
             //                $model->order = $_POST['Pages']['order'];
             if (isset($_POST['ck'])) {
                 $model->show_desc = 1;
             } else {
                 $model->show_desc = 0;
             }
             $isEmptyFileInput = empty($_FILES["Pages"]["name"]["imageFile"]);
             $new_banner = '';
             if (!$isEmptyFileInput) {
                 //has file input
                 $model->imageFile = CUploadedFile::getInstance($model, 'imageFile');
             }
             $isEmptyHomePageInput = empty($_FILES["Pages"]["name"]["thumbFile"]);
             $new_home_page = '';
             if (!$isEmptyHomePageInput) {
                 //has file input
                 $model->thumbFile = CUploadedFile::getInstance($model, 'thumbFile');
             }
             if ($model->validate()) {
                 if ($uploadFile) {
                     // remove old image and save new image to disk
                     $model->removeBanner($oldImg);
                     $model->saveBanner($uploadFile);
                 } else {
                     $model->banner = $oldImg;
                     // keep old image
                 }
                 if (!$isEmptyFileInput) {
                     //has file input
                     $errorBanner = false;
                     if (MyFunctionCustom::bannerIsSmall($model->imageFile->getTempName(), Pages::$aSizeBanner['960x252']['width'], Pages::$aSizeBanner['960x252']['height'])) {
                         $errorBanner = true;
                     }
                     //Checked size of banner
                     if ($errorBanner) {
                         $model->addError('imageFile', 'Banner file size need larger than 960x252.');
                     } else {
                         $ext_banner = $model->imageFile->getExtensionName();
                         $timestamp_banner = time();
                         $new_banner = $timestamp_banner . '.' . $ext_banner;
                     }
                 }
                 if (!$isEmptyHomePageInput) {
                     //has file input
                     //Checked size of banner
                     $errorBanner = false;
                     if (MyFunctionCustom::bannerEqual($model->thumbFile->getTempName(), Pages::$aSizeHomePage['204x94']['width'], Pages::$aSizeHomePage['204x94']['height'])) {
                         $errorBanner = true;
                     }
                     //Checked size of banner
                     if ($errorBanner) {
                         $model->addError('thumbFile', 'Thumb file size must be equal 204x94.');
                     } else {
                         $ext_home_page = $model->thumbFile->getExtensionName();
                         $timestamp_home_page = time();
                         $model->thumb_image = $timestamp_home_page . '.' . $ext_home_page;
                     }
                 }
                 if (!$model->hasErrors()) {
                     if (isset($_POST['delete_current_image']) && $_POST['delete_current_image'] == 'on') {
                         Pages::deleteImage($model);
                         $model->featured_image = NULL;
                         if (!$isEmptyFileInput) {
                             $ImageProcessing = new ImageProcessing();
                             $ImageProcessing->delete('upload/admin/' . Pages::$folderUpload . '/' . $model->id . '/' . $old_image);
                             $ImageProcessing->createDirectoryByPath('upload/admin/' . Pages::$folderUpload . '/' . $model->id);
                             $model->imageFile->saveAs(YII_UPLOAD_DIR . '/admin/' . Pages::$folderUpload . '/' . $model->id . '/' . $new_banner);
                             $model->featured_image = $new_banner;
                             $model->resizeBanner();
                         }
                         $model->update();
                     } else {
                         if ($new_banner != NULL) {
                             $model->featured_image = $new_banner;
                         }
                         if ($model->update()) {
                             if (!$isEmptyFileInput) {
                                 $ImageProcessing = new ImageProcessing();
                                 $ImageProcessing->delete('upload/admin/' . Pages::$folderUpload . '/' . $model->id . '/' . $old_image);
                                 $ImageProcessing->createDirectoryByPath('upload/admin/' . Pages::$folderUpload . '/' . $model->id);
                                 $model->imageFile->saveAs(YII_UPLOAD_DIR . '/admin/' . Pages::$folderUpload . '/' . $model->id . '/' . $model->featured_image);
                                 $model->resizeBanner();
                             }
                         }
                     }
                     //For home page
                     if (isset($_POST['delete_current_image_home_page']) && $_POST['delete_current_image_home_page'] == 'on') {
                         Pages::deleteImage($model, true);
                         $model->thumb_image = NULL;
                         if (!$isEmptyHomePageInput) {
                             $ImageProcessing = new ImageProcessing();
                             $ImageProcessing->delete('upload/admin/' . Pages::$folderUpload . '/' . $model->id . '/' . $old_home_page);
                             $ImageProcessing->createDirectoryByPath('upload/admin/' . Pages::$folderUpload . '/' . $model->id);
                             $model->thumbFile->saveAs(YII_UPLOAD_DIR . '/admin/' . Pages::$folderUpload . '/' . $model->id . '/' . $new_home_page);
                             $model->thumb_image = $new_home_page;
                             $model->resizeHomePages();
                         }
                         $model->update();
                     } else {
                         if ($new_home_page != NULL) {
                             $model->thumb_image = $new_home_page;
                         }
                         if ($model->update()) {
                             if (!$isEmptyHomePageInput) {
                                 $ImageProcessing = new ImageProcessing();
                                 $ImageProcessing->delete('upload/admin/' . Pages::$folderUpload . '/' . $model->id . '/' . $old_home_page);
                                 $ImageProcessing->createDirectoryByPath('upload/admin/' . Pages::$folderUpload . '/' . $model->id);
                                 $model->thumbFile->saveAs(YII_UPLOAD_DIR . '/admin/' . Pages::$folderUpload . '/' . $model->id . '/' . $model->thumb_image);
                                 $model->resizeHomePages();
                             }
                         }
                     }
                     $this->redirect(array('view', 'id' => $model->id));
                 }
             }
         }
         $this->render('update', array('model' => $model, 'actions' => $this->listActionsCanAccess));
     } catch (exception $e) {
         Yii::log("Exception " . print_r($e, true), 'error');
         throw new CHttpException("Exception " . print_r($e, true));
     }
 }
예제 #6
0
파일: Users.php 프로젝트: jasonhai/onehome
     $fileName = $mProTransactionsVendorPurchaserDetail->scanned_employment_pass;
     $url_download = Yii::app()->createAbsoluteUrl('/') . "/{$fileFolder}/{$fileModelId}/{$fileName}";
     MyFormat::DownloadFile($url_download, $pathSaveFile, $fileName);
     $mUser->upload_employment_pass_passport = $fileName;
 }
 if (!empty($mProTransactionsVendorPurchaserDetail->scanned_passport)) {
     $fileName = $mProTransactionsVendorPurchaserDetail->scanned_passport;
     $url_download = Yii::app()->createAbsoluteUrl('/') . "/{$fileFolder}/{$fileModelId}/{$fileName}";
     MyFormat::DownloadFile($url_download, $pathSaveFile, $fileName);
     $mUser->scanned_passport = $fileName;
예제 #7
0
 /**
  * @Author: Jason  Apr 11, 2014
  * @Todo: only remove file of report defect
  * @Param: $modelDel is model DeportDefect
  * @Param: $nameField field file in model report
  */
 public static function removeFile($modelDel, $nameField, $pathUpload)
 {
     $ImageProcessing = new ImageProcessing();
     $ImageProcessing->folder = '/' . $pathUpload . '/' . $modelDel->id;
     $ImageProcessing->delete($ImageProcessing->folder . '/' . $modelDel->{$nameField});
     //        $ImageHelper = new ImageHelper();
     //        $ImageHelper->folder = '/'.$pathUpload;
     //        $ImageHelper->deleteFile($ImageHelper->folder . '/' . $modelRemove->$fieldName);
     //        foreach ( $aSize as $key => $value) {
     //            $ImageHelper->deleteFile($ImageHelper->folder . '/' . $key . '/' . $modelRemove->$fieldName);
     //        }
     foreach (self::$aSize as $key => $value) {
         $ImageProcessing->deleteFile($ImageProcessing->folder . '/' . $key . '/' . $modelDel->{$nameField});
     }
 }
예제 #8
0
파일: Pages.php 프로젝트: jasonhai/onehome
 /**
  * <Jason>
  * 09-08-2013
  * To do: deleteImage of category
  */
 public static function deleteImage($model, $is_home_page = false)
 {
     $model = Pages::model()->findByPk($model->id);
     if ($is_home_page == true) {
         if (is_null($model) || empty($model->thumb_image)) {
             return;
         }
         $ImageProcessing = new ImageProcessing();
         $ImageProcessing->folder = '/upload/admin/pages/' . $model->id;
         $ImageProcessing->delete($ImageProcessing->folder . '/' . $model->thumb_image);
         foreach (Pages::$aSizeHomePage as $key => $value) {
             $ImageProcessing->delete($ImageProcessing->folder . '/' . $key . '/' . $model->thumb_image);
         }
     } else {
         if (is_null($model) || empty($model->featured_image)) {
             return;
         }
         $ImageProcessing = new ImageProcessing();
         $ImageProcessing->folder = '/upload/admin/pages/' . $model->id;
         $ImageProcessing->delete($ImageProcessing->folder . '/' . $model->featured_image);
         foreach (Pages::$aSizeBanner as $key => $value) {
             $ImageProcessing->delete($ImageProcessing->folder . '/' . $key . '/' . $model->featured_image);
         }
     }
 }
예제 #9
0
 /**
  * @Author: Jul 08, 2014 - ANH DUNG
  * @Todo: only remove file
  * @Param: $modelDel is model ProAirconService
  * @Param: $nameField field file in model: upload_service_documents
  * @Param: $pathUpload self::$folderUpload)
  */
 public static function removeFile($modelDel, $nameField, $pathUpload)
 {
     $ImageProcessing = new ImageProcessing();
     //        $ImageProcessing->folder = '/'.$pathUpload.'/'.$modelDel->id;
     $ImageProcessing->folder = '/' . $pathUpload;
     $ImageProcessing->delete($ImageProcessing->folder . '/' . $modelDel->{$nameField});
 }