/**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionView($id)
 {
     $user = $this->loadModel($id);
     if ($user->occupation_id == 5) {
         //avto
         if (Yii::app()->getRequest()->getParam('class') != '') {
             $avto = Avto::model()->findAllByAttributes(array('uid' => $id, 'class' => Yii::app()->getRequest()->getParam('class')));
         } else {
             $avto = Avto::model()->findAllByAttributes(array('uid' => $id));
         }
         $this->render('view_avto', array('model' => $user, 'avto' => $avto));
     } elseif ($user->occupation_id == 6) {
         //flo
         $flo = Flo::model()->findAllByAttributes(array('uid' => $id));
         $this->render('view_flo', array('model' => $user, 'flo' => $flo));
     } elseif ($user->occupation_id == 17) {
         //studio
         //$cond_hals='type="photo" and source="hall" and visible=1';
         $hals = StudioHals::model()->with('files')->findAllByAttributes(array('uid' => $id, 'visible' => 1));
         $banners = StudioBanners::model()->findByAttributes(array('uid' => $id));
         if (isset($_GET['calendar'])) {
             $this->render('view_studio_calendar', array('model' => $user));
         } elseif (isset($_GET['equip'])) {
             $this->render('view_studio_equip', array('model' => $user, 'equips' => StudioEquip::model()->findAllByAttributes(array('uid' => $id, 'visible' => 1))));
         } elseif (isset($_GET['prices'])) {
             $this->render('view_studio_prices', array('model' => $user, 'prices' => StudioHals::model()->findAllByAttributes(array('uid' => $id, 'visible' => 1))));
         } elseif (isset($_GET['rent'])) {
             $this->render('view_studio_rent', array('model' => $user, 'rent' => StudioRent::model()->findAllByAttributes(array('uid' => $id, 'visible' => 1))));
         } elseif (isset($_GET['halls'])) {
             if (isset($_GET['hid'])) {
                 $hals = StudioHals::model()->findAllByAttributes(array('uid' => $id, 'visible' => 1));
                 $hall = StudioHals::model()->with('files')->findByAttributes(array('id' => intval($_GET['hid']), 'uid' => $id, 'visible' => 1));
                 $this->render('view_studio_hals', array('model' => $user, 'hall' => $hall, 'hals' => $hals));
             } else {
                 $this->render('view_studio', array('model' => $user, 'hals' => $hals, 'banners' => $banners));
             }
         } else {
             $this->render('view_studio', array('model' => $user, 'hals' => $hals, 'banners' => $banners));
         }
     } elseif ($user->genre_id == '') {
         //other users without genres
         $flo = Flo::model()->findAllByAttributes(array('uid' => $id));
         $this->render('view_user', array('model' => $user, 'flo' => $flo));
     } else {
         if ($user->occupation_id == 2) {
             //video operator
             /*$portfolio=Files::model()->findAllByAttributes(array('uid'=>$id,'type'=>'video','source'=>'portfolio'));
                     $this->render('view_video',array(
             			'model'=>$this->loadModel($id),
                         'portfolio'=>$portfolio,
             		));*/
             $portfolio = Video::model()->findAllByAttributes(array('uid' => $id));
             $this->render('view_video', array('model' => $this->loadModel($id), 'portfolio' => $portfolio));
         } else {
             $portfolio = Portfolio::model()->findAllByAttributes(array('uid' => $id));
             $this->render('view', array('model' => $this->loadModel($id), 'portfolio' => $portfolio));
         }
     }
 }
 /**
  * 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)
 {
     $usr = Users::model()->findByPk(Yii::app()->user->id);
     if ($usr->genre_id == '') {
         $m = Flo::model()->findByPk($id);
         if ($m->uid == Yii::app()->user->id) {
             if (is_file(Yii::getPathOfAlias('webroot') . '/users/' . Yii::app()->user->id . '/' . $m->picture)) {
                 unlink(Yii::getPathOfAlias('webroot') . '/users/' . Yii::app()->user->id . '/' . $m->picture);
             }
             $m->delete();
             return true;
         } else {
             throw new CHttpException(404, 'The requested element does not exist.');
         }
     } else {
         $m = $this->loadModel($id);
         if ($m->uid == Yii::app()->user->id) {
             $files = Files::model()->findAll('portfolio_id=' . $m->id);
             if (count($files) > 0) {
                 foreach ($files as $file) {
                     Files::model()->deleteByPk($file->id);
                     if (is_file(Yii::getPathOfAlias('webroot') . '/users/' . Yii::app()->user->id . '/' . $file->file)) {
                         unlink(Yii::getPathOfAlias('webroot') . '/users/' . Yii::app()->user->id . '/' . $file->file);
                     }
                     if (is_file(Yii::getPathOfAlias('webroot') . '/users/' . Yii::app()->user->id . '/254_' . $file->file)) {
                         unlink(Yii::getPathOfAlias('webroot') . '/users/' . Yii::app()->user->id . '/254_' . $file->file);
                     }
                     if (is_file(Yii::getPathOfAlias('webroot') . '/users/' . Yii::app()->user->id . '/370_' . $file->file)) {
                         unlink(Yii::getPathOfAlias('webroot') . '/users/' . Yii::app()->user->id . '/370_' . $file->file);
                     }
                     if (is_file(Yii::getPathOfAlias('webroot') . '/users/' . Yii::app()->user->id . '/88_' . $file->file)) {
                         unlink(Yii::getPathOfAlias('webroot') . '/users/' . Yii::app()->user->id . '/88_' . $file->file);
                     }
                 }
             }
             //$m->delete();
             $m->picture = '';
             $m->visible = 0;
             $m->save();
         } else {
             throw new CHttpException(404, 'The requested album does not exist.');
         }
         $b = Yii::app()->getRequest()->getParam('back_url');
         $this->redirect($b != '' ? $b : array('index'));
         // 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('index'));
     }
 }
 public function CalcUsers($id)
 {
     if (isset(Yii::app()->request->cookies['city'])) {
         $city = 'city_id="' . Yii::app()->request->cookies['city']->value . '" or other_city="' . Yii::app()->request->cookies['city']->value . '"';
     } else {
         $city = 'city_id!="" or other_city!=""';
     }
     $users = Users::model()->findAllBySql('select id from {{users}} where (' . $city . ') and activate=1 and occupation_id=' . $id);
     $i = 0;
     foreach ($users as $user) {
         if ($id == 1 || $id == 2 || $id == 4 || $id == 18 || $id == 19 || $id == 17) {
             if (Files::model()->countByAttributes(array('uid' => $user->id)) >= 4) {
                 $i++;
             }
         } elseif ($id == 5) {
             if (Avto::model()->countByAttributes(array('uid' => $user->id)) >= 1) {
                 $i++;
             }
         } else {
             if (Flo::model()->countByAttributes(array('uid' => $user->id)) >= 1) {
                 $i++;
             }
         }
     }
     return $i;
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Flo the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Flo::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }