Exemplo n.º 1
0
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $file = new File();
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     $model->date_registration = Tools::DateTimeToShow($model->date_registration, '/', false);
     if (isset($_POST['Car']) && isset($_POST['File'])) {
         $model->attributes = $_POST['Car'];
         $file->attributes = $_POST['File'];
         $model->date_registration = Tools::dateToSave($model->date_registration);
         $file->file = CUploadedFile::getInstance($file, 'file');
         if ($file->file != null) {
             if (file_exists(Yii::app()->params['pathUpload'] . $model->pic) && $model->pic != 'noimage.jpg') {
                 unlink(Yii::app()->params['pathUpload'] . $model->pic);
             }
             if ($file->file != null) {
                 $filename = time() . '.' . $file->file->getExtensionName();
                 $file->file->saveAs(Yii::app()->params['pathUpload'] . $filename);
                 $model->pic = $filename;
             }
         }
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->car_id));
         }
     }
     $this->render('update', array('model' => $model, 'file' => $file));
 }
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     if ($model->status != 1) {
         throw new CHttpException(404, 'ไม่สามารถแก้ไขคำรองได้ เนื่องจากคำร้องได้ผ่านการรับเรื่องแล้ว กรุณาตรวจสอบ');
     }
     $model->departure_time = Tools::DateTimeToShow($model->departure_time, '/', false);
     $model->back_time = Tools::DateTimeToShow($model->back_time, '/', false);
     $file = new FileOther();
     //        $startOld = $model->departure_time;
     //        $endOld = $model->back_time;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['PaperApproval']) && isset($_POST['FileOther'])) {
         $model->attributes = $_POST['PaperApproval'];
         $file->attributes = $_POST['FileOther'];
         $file->file = CUploadedFile::getInstance($file, 'file');
         $model->validate();
         $file->validate();
         if ($model->getErrors() == null && $file->getErrors() == null) {
             $model->departure_time = Tools::dateToSave($model->departure_time);
             $model->back_time = Tools::dateToSave($model->back_time);
             if ($file->file != null) {
                 if ($model->file != null) {
                     if (file_exists(Yii::app()->params['pathUpload'] . $model->file)) {
                         unlink(Yii::app()->params['pathUpload'] . $model->file);
                     }
                 }
                 if ($file->file != null) {
                     $filename = time() . '.' . $file->file->getExtensionName();
                     $file->file->saveAs(Yii::app()->params['pathUpload'] . $filename);
                     $model->file = $filename;
                 }
             }
             if ($model->save()) {
                 $this->redirect(array('view', 'id' => $model->paper_approval_id));
             }
         }
     }
     $this->render('update', array('model' => $model, 'file' => $file));
 }
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     if ($model->status != 0) {
         throw new CHttpException(404, 'ไม่สามารถแก้ไขคำรองได้ เนื่องจากคำร้องได้ผ่านการรับเรื่องแล้ว กรุณาตรวจสอบ');
     }
     $model->date_start = Tools::DateTimeToShow($model->date_start, '/', false);
     $model->date_end = Tools::DateTimeToShow($model->date_end, '/', false);
     $service_radio = 0;
     if ($model->service_charge_out > 0) {
         $service_radio = 1;
     }
     $service_room = 0;
     if ($model->service_room_multi > 0) {
         $service_room = 1;
     }
     $file = new FileOther();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['PaperApprovalBus']) && isset($_POST['FileOther'])) {
         $model->attributes = $_POST['PaperApprovalBus'];
         $file->attributes = $_POST['FileOther'];
         $service_radio = 0;
         if (isset($_POST['service-radio'])) {
             $service_radio = $_POST['service-radio'];
         }
         $service_room = 0;
         if (isset($_POST['service_room-radio'])) {
             $service_room = $_POST['service_room-radio'];
         }
         $file->file = CUploadedFile::getInstance($file, 'file');
         if ($service_radio == 0) {
             $model->service_charge_out = 0;
         }
         if ($service_radio == 1) {
             $model->service_charge_in = 0;
         }
         if ($service_room == 0) {
             $model->service_room_multi = 0;
         }
         if ($service_room == 1) {
             $model->service_room = 0;
         }
         $model->validate();
         $file->validate();
         if ($model->getErrors() == null && $file->getErrors() == null) {
             $model->date_start = Tools::dateToSave($model->date_start);
             $model->date_end = Tools::dateToSave($model->date_end);
             if ($file->file != null) {
                 if ($model->file != null) {
                     if (file_exists(Yii::app()->params['pathUpload'] . $model->file)) {
                         unlink(Yii::app()->params['pathUpload'] . $model->file);
                     }
                 }
                 if ($file->file != null) {
                     $filename = time() . '.' . $file->file->getExtensionName();
                     $file->file->saveAs(Yii::app()->params['pathUpload'] . $filename);
                     $model->file = $filename;
                 }
             }
             if ($model->save()) {
                 $this->redirect(array('view', 'id' => $model->paper_approval_bus_id));
             }
         }
     }
     $this->render('update', array('model' => $model, 'file' => $file, 'service_radio' => $service_radio, 'service_room' => $service_room));
 }