Example #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($idTree)
 {
     $modelTree = Tree::model()->find('id=:id AND module=:module AND organization=:organization', array(':id' => $idTree, ':module' => 'news', ':organization' => Yii::app()->session['code_no']));
     if ($modelTree === null) {
         throw new CHttpException(404, 'Страница не найдена.');
     }
     if (!(Yii::app()->user->admin || Access::model()->checkAccessUserForTree($idTree))) {
         throw new CHttpException(403, 'Доступ запрещен.');
     }
     $model = new News();
     $model->id_tree = $idTree;
     $model->flag_enable = true;
     $model->date_start_pub = date('d.m.Y');
     $model->date_end_pub = date('01.m.Y', PHP_INT_MAX);
     $model->author = Yii::app()->user->name;
     $model->general_page = 0;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['News'])) {
         $model->attributes = $_POST['News'];
         $model->log_change = LogChange::setLog($model->log_change, 'создание');
         if ($model->save()) {
             // сохраняем файлы
             $model->saveFiles($model->id, $idTree);
             // сохраняем изображения
             $model->saveImages($model->id, $idTree);
             // сохраняем миниатюра изображения
             $model->saveThumbailForNews($model);
             $this->redirect(array('view', 'id' => $model->id, 'idTree' => $idTree));
         }
     }
     $this->render('create', array('model' => $model, 'idTree' => $idTree));
 }
 /**
  * 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, $idTree)
 {
     $model = $this->loadModel($id, $idTree);
     $model->id_tree = $idTree;
     $model->author = Yii::app()->user->name;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Telephone'])) {
         $model->attributes = $_POST['Telephone'];
         $model->log_change = LogChange::setLog($model->log_change, 'изменение');
         $tempFile = CUploadedFile::getInstance($model, 'tel_file');
         if ($tempFile != null) {
             try {
                 unlink(Yii::app()->params['pathTelephones'] . '/' . $model->telephone_file);
             } catch (exception $e) {
             }
             $file_name = $model->ifns_code . '_' . date('Ymd_His') . '.' . pathinfo($tempFile->getName(), PATHINFO_EXTENSION);
             $model->telephone_file = $file_name;
             $tempFile->saveAs(Yii::app()->params['pathTelephones'] . '/' . $file_name);
         }
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id, 'idTree' => $idTree));
         }
     }
     $this->render('update', array('model' => $model, 'idTree' => $idTree));
 }
Example #3
0
 protected function beforeSave()
 {
     if ($this->isNewRecord) {
         $this->date_create = new CDbExpression('NOW()');
         $this->author = Yii::app()->user->name;
     }
     $this->log_change = LogChange::setLog($this->log_change, $this->isNewRecord ? 'создание' : 'изменение');
     return parent::beforeSave();
 }
Example #4
0
 /**
  * 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, $idTree)
 {
     if (Yii::app()->request->isPostRequest) {
         if (!Yii::app()->user->admin) {
             $model = $this->loadModel($id, $idTree);
             $model->date_delete = new CDbExpression('getdate()');
             $model->log_change = LogChange::setLog($model->log_change, 'удаление');
             $model->save();
         } else {
             // we only allow deletion via POST request
             $this->loadModel($id, $idTree)->delete();
         }
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'idTree' => $idTree));
         }
     } else {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }
Example #5
0
 protected function beforeSave()
 {
     $this->ifns_ufns_date = $this->ifns_ufns_date == '' ? new CDbExpression('NULL') : new CDbExpression("STR_TO_DATE('" . $this->ifns_ufns_date . "','%d.%m.%Y')");
     $this->ufns_fns_date = $this->ufns_fns_date == '' ? new CDbExpression('NULL') : new CDbExpression("STR_TO_DATE('" . $this->ufns_fns_date . "','%d.%m.%Y')");
     $this->fns_ufns_date = $this->fns_ufns_date == '' ? new CDbExpression('NULL') : new CDbExpression("STR_TO_DATE('" . $this->fns_ufns_date . "','%d.%m.%Y')");
     $this->ufns_ifns_date = $this->ufns_ifns_date == '' ? new CDbExpression('NULL') : new CDbExpression("STR_TO_DATE('" . $this->ufns_ifns_date . "','%d.%m.%Y')");
     $this->date_execution = $this->date_execution == '' ? new CDbExpression('NULL') : new CDbExpression("STR_TO_DATE('" . $this->date_execution . "','%d.%m.%Y')");
     /*                   
     if ($this->ifns_ufns_date=='')  $this->ifns_ufns_date   = new CDbExpression('NULL');
     if ($this->ufns_fns_date=='')   $this->ufns_fns_date    = new CDbExpression('NULL');
     if ($this->fns_ufns_date=='')   $this->fns_ufns_date    = new CDbExpression('NULL');
     if ($this->ufns_ifns_date=='')  $this->ufns_ifns_date   = new CDbExpression('NULL');
     if ($this->date_execution=='')  $this->date_execution   = new CDbExpression('NULL'); 
     */
     if ($this->isNewRecord) {
         $this->date_create = new CDbExpression('NOW()');
     }
     $this->log_change = LogChange::setLog($this->log_change, $this->isNewRecord ? 'создание' : 'изменение');
     return parent::beforeSave();
 }
Example #6
0
 /** Восстановление записи **/
 public function actionRestore($id, $idTree)
 {
     if (!Yii::app()->user->admin) {
         return;
     }
     $model = $this->loadModel($id, $idTree);
     $model->date_delete = new CDbExpression('NULL');
     $model->log_change = LogChange::setLog($model->log_change, 'восстановление');
     $model->save();
     $this->redirect(array('view', 'id' => $model->id, 'idTree' => $idTree));
 }