public function actionAdd($id = 0)
 {
     if (!empty($id)) {
         $Insurance = Insurance::model()->findByPk($id);
         if (!Yii::app()->user->checkAccess('admin') && ((Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY || Yii::app()->user->getProfile()->company_id != $Insurance->user->company_id) && (Yii::app()->getUser()->getProfile()->modules->insurance != '1' || $Insurance->user_id != Yii::app()->user->id) || Yii::app()->getUser()->getProfile()->company->active == '0')) {
             throw new CHttpException(403);
         }
         $Address = $Insurance->address;
         $ContentManager = null;
     } else {
         if (Yii::app()->user->getProfile()->content_manager == '0') {
             if (!Yii::app()->user->checkAccess('admin') && (Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY && Yii::app()->getUser()->getProfile()->modules->insurance != '1' || Yii::app()->getUser()->getProfile()->company->active == '0')) {
                 throw new CHttpException(403);
             } elseif (!Yii::app()->getUser()->getProfile()->company->validate) {
                 $this->redirect('/complete');
             }
             $ContentManager = null;
         } else {
             $ContentManager = new ContentManager();
         }
         $Insurance = new Insurance();
         $Address = new Address();
         $Address->setscenario('insurance');
     }
     //if(isset($_POST['save'])) {
     if (!empty($_POST)) {
         if (!empty($Insurance->address)) {
             Address::model()->deleteByPk($Insurance->address->address_id);
         }
         if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
             $ContentManager->setAttributes($_POST['ContentManager'], false);
             $contentValid = $ContentManager->validate();
         } else {
             $contentValid = true;
         }
         $Insurance->setAttributes($_POST['Insurance'], false);
         $Address->setAttributes($_POST['Address'], false);
         $valid = $Address->validate();
         $valid = $Insurance->validate() && $valid && $contentValid;
         if ($valid) {
             if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
                 $Insurance->user_id = User::createFakeUser($ContentManager);
                 $Insurance->contact_id = $Insurance->user_id;
             }
             $Address->save();
             $Insurance->address_id = $Address->address_id;
             $Insurance->save();
             $Insurance->autosearch();
             //                $this->redirect('/insurance');
             $this->render('insuranceaddsuccess', ['Insurance' => $Insurance, 'contacts' => User::getContact()]);
             exit;
         }
     }
     $this->render('add', ['Insurance' => $Insurance, 'Address' => $Address, 'contacts' => User::getContact(), 'ContentManager' => $ContentManager]);
 }
示例#2
0
 public function testValidatingCorrectLatitudeAndLongitudeLength()
 {
     $address = new Address();
     $address->latitude = -112.8327778;
     $validated = $address->validate();
     $this->assertTrue($validated);
     $address = new Address();
     $address->latitude = -112.83277785;
     //Length = 13
     $validated = $address->validate();
     $this->assertFalse($validated);
 }
示例#3
0
 /**
  * This function performs the validation work for complex object models.
  *
  * In addition to checking the current object, all related objects will
  * also be validated.  If all pass then <code>true</code> is returned; otherwise
  * an aggreagated array of ValidationFailed objects will be returned.
  *
  * @param array $columns Array of column names to validate.
  * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  */
 protected function doValidate($columns = null)
 {
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         $failureMap = array();
         // We call the validate method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aAccount !== null) {
             if (!$this->aAccount->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aAccount->getValidationFailures());
             }
         }
         if ($this->aAddress !== null) {
             if (!$this->aAddress->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aAddress->getValidationFailures());
             }
         }
         if (($retval = DomainPeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         if ($this->collHolidayDomains !== null) {
             foreach ($this->collHolidayDomains as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collPropertyValues !== null) {
             foreach ($this->collPropertyValues as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collUsers !== null) {
             foreach ($this->collUsers as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
 public function actionEditCommissioningBody()
 {
     if (isset($_GET['commissioning_body_id'])) {
         if (!($cb = CommissioningBody::model()->findByPk(@$_GET['commissioning_body_id']))) {
             throw new Exception("CommissioningBody not found: " . @$_GET['commissioning_body_id']);
         }
         if (!($address = $cb->contact->address)) {
             $address = new Address();
             $address->country_id = 1;
         }
     } else {
         $cb = new CommissioningBody();
         $address = new Address();
         $address->country_id = 1;
     }
     $errors = array();
     if (!empty($_POST)) {
         $cb->attributes = $_POST['CommissioningBody'];
         if (!$cb->validate()) {
             $errors = $cb->getErrors();
         }
         $address->attributes = $_POST['Address'];
         if (!$address->validate()) {
             $errors = array_merge($errors, $address->getErrors());
         }
         if (empty($errors)) {
             if (!($contact = $cb->contact)) {
                 $contact = new Contact();
                 if (!$contact->save()) {
                     throw new Exception("Unable to save contact for commissioning body: " . print_r($contact->getErrors(), true));
                 }
             }
             $cb->contact_id = $contact->id;
             $method = $cb->id ? 'edit' : 'add';
             $audit = $_POST;
             if ($method == 'edit') {
                 $audit['id'] = $cb->id;
             }
             if (!$cb->save()) {
                 throw new Exception("Unable to save CommissioningBody : " . print_r($cb->getErrors(), true));
             }
             $address->contact_id = $contact->id;
             if (!$address->save()) {
                 throw new Exception("Unable to save CommissioningBody address: " . print_r($address->getErrors(), true));
             }
             Audit::add('admin-CommissioningBody', $method, $cb->id);
             $this->redirect('/admin/commissioning_bodies');
         }
     } else {
         Audit::add('admin-CommissioningBody', 'view', @$_GET['commissioning_body_id']);
     }
     $this->render('/admin/editCommissioningBody', array('cb' => $cb, 'address' => $address, 'errors' => $errors));
 }
 public function actionAddcall($id = 0)
 {
     $flZayavka = 1;
     if (!empty($id)) {
         $this->pageTitle = Yii::t('MarketModule.default', 'Редактирование спецтехники');
         $title = Yii::t('MarketModule.default', 'Редактирование заявки на спецтехнику');
     } else {
         $this->pageTitle = Yii::t('MarketModule.default', 'Добавление спецтехники');
         $title = Yii::t('MarketModule.default', 'Добавление заявки на спецтехнику');
     }
     $this->breadcrumbs = array_merge([CHtml::encode(Yii::t('MarketModule.default', 'Заявки на спецтехнику')) => ['/specialtechniquecall']], [CHtml::encode($this->pageTitle)]);
     if (!empty($id)) {
         $SpecialTechnique = SpecialTechnique::model()->findByPk($id);
         if (!Yii::app()->user->checkAccess('admin') && ((Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY || Yii::app()->user->getProfile()->company_id != $SpecialTechnique->user->company_id) && (Yii::app()->getUser()->getProfile()->modules->specialtech != '1' || $SpecialTechnique->user_id != Yii::app()->user->id) || Yii::app()->getUser()->getProfile()->company->active == '0')) {
             throw new CHttpException(403);
         }
         $Address = $SpecialTechnique->address;
         $CostForm = $SpecialTechnique->getCostForm();
         $ContentManager = null;
     } else {
         if (Yii::app()->user->getProfile()->content_manager == '0') {
             if (!Yii::app()->user->checkAccess('admin') && (Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY && Yii::app()->getUser()->getProfile()->modules->specialtech != '1' || Yii::app()->getUser()->getProfile()->company->active == '0')) {
                 throw new CHttpException(403);
             } elseif (!Yii::app()->getUser()->getProfile()->company->validate) {
                 $this->redirect('/complete');
             }
             $ContentManager = null;
         } else {
             $ContentManager = new ContentManager();
         }
         $SpecialTechnique = new SpecialTechnique();
         $Address = new Address();
         $Address->setscenario('specialtechnique');
         $CostForm = new CostForm();
     }
     $contacts = User::getContact();
     if (!empty($_POST)) {
         if (!empty($SpecialTechnique->address)) {
             Address::model()->deleteByPk($SpecialTechnique->address->address_id);
         }
         $SpecialTechnique->setAttributes($_POST['SpecialTechnique'], false);
         $SpecialTechnique->type_request = 'request';
         $CostForm->setAttributes($_POST['CostForm'], false);
         $Address->setAttributes($_POST['Address'], false);
         if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
             $ContentManager->setAttributes($_POST['ContentManager'], false);
             $contentValid = $ContentManager->validate();
         } else {
             $contentValid = true;
         }
         $valid = $Address->validate();
         $valid = $SpecialTechnique->validate() && $CostForm->validate() && $valid && $contentValid;
         if (!$valid) {
             Yii::import('bootstrap.widgets.TbActiveForm');
             if ($ContentManager) {
                 echo TbActiveForm::validate(array($SpecialTechnique, $Address, $CostForm, $ContentManager));
             } else {
                 echo TbActiveForm::validate(array($SpecialTechnique, $Address, $CostForm));
             }
             Yii::app()->end();
         } else {
             if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
                 $SpecialTechnique->user_id = User::createFakeUser($ContentManager);
                 $SpecialTechnique->contact_id = $SpecialTechnique->user_id;
             }
             $Address->save();
             $SpecialTechnique->address_id = $Address->address_id;
             $SpecialTechnique->save();
             $SpecialTechnique->setRelations($_POST['SpecialTechnique']);
             $SpecialTechnique->setCost($CostForm);
             $SpecialTechnique->autosearch();
             //$this->redirect('/specialtechniquecall');
             echo CJSON::encode(array('status' => '500', 'redirect' => '/specialaddcallsuccess/' . $SpecialTechnique->special_technique_id));
             Yii::app()->end();
         }
     }
     $this->render('add', ['showPhoto' => false, 'CostForm' => $CostForm, 'SpecialTechnique' => $SpecialTechnique, 'contacts' => $contacts, 'Address' => $Address, 'title' => $title, 'ContentManager' => $ContentManager, 'flZayavka' => $flZayavka]);
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  */
 public function actionUpdate()
 {
     if (Yii::app()->user->checkAccess('updateUsers')) {
         $allowEdit = false;
         $model = $this->loadModel();
         $tmppw = $model->user_password;
         if (!empty($model->address_id)) {
             $address = Address::model()->findByPk($model->address_id);
         } else {
             $address = new Address();
         }
         $userManager = Yii::app()->user->IsManager;
         if ($model->user_id == Yii::app()->user->id || $userManager || Yii::app()->user->IsAdministrator) {
             $allowEdit = true;
         }
         if (isset($_POST['Users']) && isset($_POST['Address'])) {
             $model->attributes = $_POST['Users'];
             $address->attributes = $_POST['Address'];
             if (isset($_POST['Users']['user_password'])) {
                 $model->user_password = md5($model->user_password);
             }
             $valid = $address->validate();
             $valid = $model->validate() && $valid;
             if ($valid) {
                 $address->save(false);
                 $model->address_id = $address->primaryKey;
                 if ($model->save(false)) {
                     // Guardar log
                     $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'UserUpdated', 'log_resourceid' => $model->user_id, 'log_type' => 'updated', 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id);
                     Logs::model()->saveLog($attributes);
                     $this->redirect(array('view', 'id' => $model->user_id));
                 }
             }
         }
         $this->render('update', array('model' => $model, 'allowEdit' => $allowEdit, 'userManager' => $userManager, 'address' => $address));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
 /**
  * Updates a particular model.
  * @param integer $_GET['id'] the ID of the model to be updated
  * @return update view
  */
 public function actionUpdate()
 {
     // check if user has permissions to updateClients
     if (Yii::app()->user->checkAccess('updateClients')) {
         // get Clients object from $id parameter
         $model = $this->loadModel();
         // find client user data
         $modelUsers = Users::model()->together()->findByPk($model->user_id);
         // current user password
         $tmppw = $modelUsers->user_password;
         // if client hasn't address create an Address object, else load
         if (!empty($model->address_id)) {
             $address = Address::model()->findByPk($modelUsers->address_id);
         } else {
             $address = new Address();
         }
         // only users with administration rights or own user can update his profiles
         if ($modelUsers->user_id == Yii::app()->user->id || Yii::app()->user->IsAdministrator) {
             // if Users and Address form exist
             if (isset($_POST['Users']) && isset($_POST['Address'])) {
                 // set form elements to Users model attributes
                 $modelUsers->attributes = $_POST['Users'];
                 // set form elements to Address model attributes
                 $address->attributes = $_POST['Address'];
                 // if current password is different to new password
                 if (isset($_POST['Users']['user_password'])) {
                     $modelUsers->user_password = md5($modelUsers->user_password);
                 }
                 // validate both models
                 $valid = $address->validate();
                 $valid = $modelUsers->validate() && $valid;
                 if ($valid) {
                     // save address
                     $address->save(false);
                     $modelUsers->address_id = $address->primaryKey;
                     // save user
                     if ($modelUsers->save(false)) {
                         // save log
                         $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'ClientUpdated', 'log_resourceid' => $model->client_id, 'log_type' => Logs::LOG_UPDATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id);
                         Logs::model()->saveLog($attributes);
                         // to prevent F5 keypress, redirect to view page
                         $this->redirect(array('view', 'id' => $model->client_id));
                     }
                 }
             }
             $this->render('update', array('model' => $modelUsers, 'address' => $address));
         } else {
             throw new CHttpException(403, Yii::t('site', '403_Error'));
         }
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
 /**
  * Updates a particular model.
  * @return update view
  */
 public function actionUpdate()
 {
     // check if user has permissions to updateCompanies
     if (Yii::app()->user->checkAccess('updateCompanies')) {
         // get Company object from $id parameter
         $model = $this->loadModel();
         // if company hasn't address create an Address object, else load
         if (!empty($model->address_id)) {
             $address = Address::model()->findByPk($model->address_id);
         } else {
             $address = new Address();
         }
         // only users with administration rights or own user can update his profiles
         if (Yii::app()->user->IsAdministrator) {
             // if Company form exist
             if (isset($_POST['Companies'])) {
                 // set form elements to Companies model attributes
                 $model->attributes = $_POST['Companies'];
                 // set form elements to Address model attributes
                 $address->attributes = $_POST['Address'];
                 // validate both models
                 $valid = $address->validate();
                 $valid = $model->validate() && $valid;
                 if ($valid) {
                     // save address
                     $address->save(false);
                     $model->address_id = $address->primaryKey;
                     // save company
                     if ($model->save()) {
                         // save log
                         $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'CompanyUpdated', 'log_resourceid' => $model->company_id, 'log_type' => Logs::LOG_UPDATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id);
                         Logs::model()->saveLog($attributes);
                         // to prevent F5 keypress, redirect to view page
                         $this->redirect(array('view', 'id' => $model->company_id));
                     }
                 }
             }
         }
         $this->render('update', array('model' => $model, 'address' => $address));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
 public function actionAddcall($id = 0)
 {
     /*if(!Yii::app()->user->checkAccess('addSklad')) {
           throw new CHttpException(404,'Указанная запись не найдена');
       }*/
     if (!empty($id)) {
         $SkladCall = SkladCall::model()->findByPk($id);
         $Address = $SkladCall->address;
         $Area = $SkladCall->getAreaForm();
         if (!Yii::app()->user->checkAccess('admin') && ((Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY || Yii::app()->user->getProfile()->company_id != $SkladCall->user->company_id) && (Yii::app()->getUser()->getProfile()->modules->storage != '1' || $SkladCall->user_id != Yii::app()->user->id) || Yii::app()->getUser()->getProfile()->company->active == '0')) {
             throw new CHttpException(403);
         }
         $ContentManager = null;
     } else {
         if (Yii::app()->user->getProfile()->content_manager == '0') {
             if (!Yii::app()->user->checkAccess('admin') && (Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY && Yii::app()->getUser()->getProfile()->modules->storage != '1' || Yii::app()->getUser()->getProfile()->company->active == '0')) {
                 throw new CHttpException(403);
             } elseif (!Yii::app()->getUser()->getProfile()->company->validate) {
                 $this->redirect('/complete');
             }
             $ContentManager = null;
         } else {
             $ContentManager = new ContentManager();
         }
         $SkladCall = new SkladCall();
         $Address = new Address();
         $Address->setscenario('sklad');
         $Area = new AreaForm();
     }
     $contacts = User::getContact();
     if (isset($_POST['save'])) {
         if (!empty($_POST['SkladCall']['sklad_call_id'])) {
             $SkladCall = SkladCall::model()->findByPk($_POST['SkladCall']['sklad_call_id']);
         } else {
             $SkladCall = new SkladCall();
         }
         if (!empty($SkladCall->address)) {
             Address::model()->deleteByPk($SkladCall->address->address_id);
         }
         $SkladCall->setAttributes($_POST['SkladCall'], false);
         $Address->setAttributes($_POST['Address'], false);
         if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
             $ContentManager->setAttributes($_POST['ContentManager'], false);
             $contentValid = $ContentManager->validate();
         } else {
             $contentValid = true;
         }
         $valid = $Address->validate();
         $valid = $SkladCall->validate() && $valid && $contentValid;
         if ($valid) {
             if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
                 $SkladCall->user_id = User::createFakeUser($ContentManager);
                 $SkladCall->contact_id = $SkladCall->user_id;
             }
             $Address->save();
             $SkladCall->address_id = $Address->address_id;
             $SkladCall->save();
             $SkladCall->setRelations($_POST['SkladCall']);
             $SkladCall->setArea($_POST['AreaForm']);
             $SkladCall->autosearch();
             //$this->redirect('/storagecall');
             $this->render('skladaddcallsuccess', ['SkladCall' => $SkladCall, 'contacts' => $contacts, 'Area' => $Area, 'Address' => $Address]);
             exit;
         }
     }
     $this->render('addcall', ['SkladCall' => $SkladCall, 'contacts' => $contacts, 'Area' => $Area, 'Address' => $Address, 'ContentManager' => $ContentManager]);
 }
 /**
  * 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 actionAccountUpdate()
 {
     // check if user has permissions to permissionsConfiguration
     if (Yii::app()->user->checkAccess('permissionsConfiguration')) {
         // with user.account_id load account data
         $model = Accounts::model()->findByPk(Yii::app()->user->Accountid);
         // if account hasn't address create an Address object, else load
         if (!empty($model->address_id)) {
             $address = Address::model()->findByPk($model->address_id);
         } else {
             $address = new Address();
         }
         // if Accounts and Address form exist
         if (isset($_POST['Accounts'], $_POST['Address'])) {
             // set form elements to model attributes
             $model->attributes = $_POST['Accounts'];
             $address->attributes = $_POST['Address'];
             // validate both models
             $valid = $address->validate();
             $valid = $model->validate() && $valid;
             if ($valid) {
                 // save image path, if uploaded
                 if (isset($_FILES['Accounts']['name']['image']) && !empty($_FILES['Accounts']['name']['image'])) {
                     // create an instance of file uploaded
                     $model->image = CUploadedFile::getInstance($model, 'image');
                     if (!$model->image->getError()) {
                         $this->tmpFileName = trim(date('dmYHis-z-') . microtime());
                         $extension = $model->image->getExtensionName();
                         $extensionAllowed = array('jpg', 'jpeg', 'png');
                         // verify only allowed extensions
                         if (in_array($extension, $extensionAllowed)) {
                             // save image from tmp folder to defined folder, after set account_logo path
                             if ($model->image->saveAs(ConfigurationController::FOLDERIMAGES . $this->tmpFileName . '.' . $extension)) {
                                 $model->account_logo = ConfigurationController::FOLDERIMAGES . $this->tmpFileName . '.' . $extension;
                             }
                         }
                     }
                 }
                 // save address
                 $address->save(false);
                 $model->address_id = $address->primaryKey;
                 // save model
                 $model->save(false);
                 // to prevent F5 keypress, redirect to account page
                 $this->redirect(Yii::app()->createUrl('configuration/account'));
             }
         }
         $this->layout = 'column2';
         $this->render('accounts/update', array('model' => $model, 'address' => $address));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }