/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $model = new User();
         if (isset($_POST['User'])) {
             $model->attributes = $_POST['User'];
             $model->password = crypt(Sysparam::model()->findByPk(AppConstants::RESET_PASSWORD_DEFAULT)->value);
             if ($model->save()) {
                 $authAssign = new AuthAssignment();
                 $authAssign->itemname = $model->role;
                 $authAssign->userid = $model->nick;
                 $authAssign->save();
                 $fsu = new FileSystemUtil();
                 $fsu->createUserTmpFoderIfNotExists($model->nick);
                 $this->audit->logAudit(Yii::app()->user->id, new DateTime(), AppConstants::AUDIT_OBJECT_USER, AppConstants::AUDIT_OPERATION_NEW, $model->nick);
                 $this->render('/site/successfullOperation', array('header' => 'Usuario creado con éxito', 'message' => 'Haga click en volver para regresar a la gestión de usuarios', 'returnUrl' => Yii::app()->createUrl('user/admin'), 'viewUrl' => Yii::app()->createUrl("user/view", array("id" => $model->nick))));
                 $transaction->commit();
                 return;
             } else {
                 $transaction->rollback();
             }
         }
         $this->render('create', array('model' => $model));
     } catch (Exception $exc) {
         Yii::log($exc->getMessage(), DBLog::LOG_LEVEL_ERROR);
         $transaction->rollback();
     }
 }
 /**
  * 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)
 {
     $model = $this->loadModel($id);
     $fsUtil = new FileSystemUtil();
     if (isset($_POST['Property'])) {
         $model->attributes = $_POST['Property'];
         if ($model->save()) {
             //elimino las imagenes viejas de el sistema de archivos y de la bd (las referencias)
             $fsUtil->deleteImagesFromProperty($id);
             $model->deleteAllImages();
             //guardo las imagenes nuevas para el inmueble
             $images = $fsUtil->getTmpFilesNames();
             foreach ($images as $img) {
                 $imgInm = new ImagenInmueble();
                 $imgInm->id_inmueble = $model->id;
                 $imgInm->ruta = $img;
                 if ($imgInm->save()) {
                     $fsUtil->copyFileFromTmpToFs($imgInm->ruta, $model->id);
                 }
             }
             $this->audit->registrarAuditoria(Yii::app()->user->id, new DateTime(), Constants::AUDITORIA_OBJETO_INMUEBLE, Constants::AUDITORIA_OPERACION_MODIFICACION, $model->id);
             $this->render('/site/successfullOperation', array('header' => 'Inmueble modificado con éxito', 'message' => 'Haga click en volver para regresar a la gestión de inmuebles', 'returnUrl' => Yii::app()->createUrl('inmueble/admin'), 'viewUrl' => Yii::app()->createUrl("inmueble/view", array("id" => $model->id))));
             return;
         }
     }
     $fsUtil->clearUserTmpFolder();
     $fsUtil->copyPropertyFilesFromFsToTmp($model->id);
     $this->render('update', array('model' => $model));
 }
 public function actionProfilePhoto()
 {
     $u = User::model()->findByPk(Yii::app()->user->id);
     if ($u->photo == null) {
         $fs = new FileSystemUtil();
         $photoUrl = $fs->getStaticFile("no-photo.jpg");
         if (file_exists($photoUrl)) {
             Response::sendImage($photoUrl);
         } else {
             die($photoUrl . " no-photo.jpg no existe");
         }
     } else {
         Response::sendByteArray($u->photo);
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->password = crypt(Sysparam::model()->findByPk(Constants::PARAMETRO_CONTRASENIA_REINICIO)->value);
         if ($model->save()) {
             $authAssign = new AuthAssignment();
             $authAssign->itemname = $model->role;
             $authAssign->userid = $model->nick;
             $authAssign->save();
             $fsu = new FileSystemUtil();
             $fsu->createUserTmpFoderIfNotExists($model->nick);
             $this->audit->logAudit(Yii::app()->user->id, new DateTime(), Constants::AUDITORIA_OBJETO_USUARIO, Constants::AUDITORIA_OPERACION_ALTA, $model->nick);
             $this->render('/site/successfullOperation', array('header' => 'Usuario creado con éxito', 'message' => 'Haga click en volver para regresar a la gestión de usuarios', 'returnUrl' => Yii::app()->createUrl('user/admin'), 'viewUrl' => Yii::app()->createUrl("user/view", array("id" => $model->nick))));
             return;
         }
     }
     $this->render('create', array('model' => $model));
 }