/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     Yii::app()->clientScript->registerPackage('office-edit');
     $model = new Office();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Office'])) {
         $model->attributes = $_POST['Office'];
         $model->user_id = Yii::app()->user->id;
         $fl = Files::model()->uploadFile('Office[avatar]');
         $model->avatar = $fl['filename'];
         $fl = Files::model()->uploadFile('Office[background]');
         $model->background = $fl['filename'];
         if (Yii::app()->request->getPost('city')) {
             $city = Yii::app()->request->getPost('city');
             $city = City::model()->find(array('select' => 'city_id', 'condition' => "`name` LIKE :city", 'params' => array(':city' => $city)));
             if ($city != null) {
                 $model->city_id = $city->city_id;
             } else {
                 $model->addError('city_id', Yii::t('errors', 'Такого города не существует'));
             }
         } else {
             $model->addError('city_id', Yii::t('errors', 'Нужно указать город'));
         }
         if ($model->save()) {
             $this->redirect(array('/office'));
         }
     }
     $country_id = 0;
     if (is_null($model->city_id)) {
         $country_id = 1894;
         $city = City::model()->find('city_id=1913')->name;
     } else {
         $country_id = $model->city->country_id;
         $city = $model->city->name;
     }
     $countries = CHtml::listData(Country::model()->findAll(array('select' => 'country_id, name')), 'country_id', 'name');
     $this->render('/office/create', array('model' => $model, 'country_id' => $country_id, 'countries' => $countries, 'city' => $city));
 }