/**
  * 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 = ProAirconService::model()->findByPk($id);
         if (is_null($model)) {
             throw new Exception('id not valid');
         }
         $old_upload_service_documents = $model->upload_service_documents;
         $model->scenario = 'updateTelemarketer';
         $model->schedule_date = MyFormat::dateConverYmdToDmy($model->schedule_date, "d/m/Y");
         $this->layout = 'ajax';
         if (isset($_POST['ProAirconService'])) {
             $model->attributes = $_POST['ProAirconService'];
             $model->upload_service_documents = CUploadedFile::getInstance($model, 'upload_service_documents');
             if (is_null($model->upload_service_documents)) {
                 $model->upload_service_documents = $old_upload_service_documents;
             } else {
                 $model->validate();
                 if (!$model->hasErrors()) {
                     $mOld = ProAirconService::model()->findByPk($model->id);
                     ProAirconService::removeFile($mOld, 'upload_service_documents', ProAirconService::$folderUpload);
                     $model->upload_service_documents = ProAirconService::save_photo($model);
                 }
             }
             if ($model->save()) {
                 die('<script type="text/javascript">parent.$.fn.colorbox.close(); parent.$.fn.yiiGridView.update("pro-defect-grid");</script>');
             }
         }
         $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));
     }
 }
Esempio n. 2
0
 public function beforeDelete()
 {
     try {
         ProAirconService::removeFile($this, 'upload_service_documents', ProAirconService::$folderUpload);
     } catch (Exception $ex) {
         echo $ex->getMessage();
         die;
     }
     return parent::beforeDelete();
 }