예제 #1
0
 public function actionAddcompany()
 {
     $companyModel = new Company();
     $userLoginModel = new UserLogin();
     $userProfileModel = new UserProfile();
     if (isset($_POST['Company'])) {
         $companyModel->attributes = $_POST['Company'];
         $userLoginModel->attributes = $_POST['UserLogin'];
         $userProfileModel->attributes = $_POST['UserProfile'];
         if ($companyModel->validate()) {
             if ($companyModel->save()) {
                 $userLoginModel->UserRoleID = 2;
                 // $userLoginModel->LoginEmail = '*****@*****.**';
                 $userLoginModel->UserPassword = md5($userLoginModel->UserPassword);
                 $userLoginModel->IsPasswordReset = 1;
                 $userLoginModel->IsActive = 1;
                 $userLoginModel->save();
                 $userProfileModel->UserLoginID = $userLoginModel->UserLoginID;
                 $userProfileModel->CompanyID = $companyModel->CompanyID;
                 // $userProfileModel->FirstName = 'Test';
                 // $userProfileModel->LastName = 'test';
                 $userProfileModel->AgreeToTerms = 0;
                 $userProfileModel->IsFacilitator = 0;
                 $userProfileModel->save();
                 $this->redirect(Yii::app()->createUrl('admin/setup', array('id' => $companyModel->CompanyID)));
             }
         }
     }
     $this->render('add-company', array('companyModel' => $companyModel, 'userLoginModel' => $userLoginModel, 'userProfileModel' => $userProfileModel));
 }
예제 #2
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->aCategory !== null) {
             if (!$this->aCategory->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aCategory->getValidationFailures());
             }
         }
         if ($this->aElementStatus !== null) {
             if (!$this->aElementStatus->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aElementStatus->getValidationFailures());
             }
         }
         if ($this->aCompany !== null) {
             if (!$this->aCompany->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aCompany->getValidationFailures());
             }
         }
         if (($retval = ElementPeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         if ($this->collPreferences !== null) {
             foreach ($this->collPreferences as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collOrders !== null) {
             foreach ($this->collOrders as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collElementFiles !== null) {
             foreach ($this->collElementFiles as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
예제 #3
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'show' page.
  */
 public function actionCreate()
 {
     $model = new Company($this->action->id);
     if (isset($_POST['Company'])) {
         // collect user input data
         $model->attributes = $_POST['Company'];
         // validate with the current action as scenario and save without validation
         if (($validated = $model->validate()) !== false && ($saved = $model->save(false)) !== false) {
             if (isset($_POST['User2Company'])) {
                 // assigned users
                 $model->allUser2Company = array(0 => new User2Company('create'));
                 //createCompany
                 $model->allUser2Company[0]->companyId = $model->id;
                 foreach ($model->allUser2Company as $user2Company) {
                     $user2Company->attributes = $_POST['User2Company'];
                     $user2Company->position = 'owner';
                     $user2Company->save();
                 }
             }
             if (isset($_POST['Location'])) {
                 // assigned locations
                 $model->allLocation = array(0 => new Location('reate'));
                 foreach ($model->allLocation as $location) {
                     // collect user input data
                     $location->attributes = $_POST['Location'];
                     // validate and create/update record
                     if ($location->save()) {
                         $location2Record = new Location2Record('create');
                         $location2Record->locationId = $location->id;
                         $location2Record->record = get_class($model);
                         $location2Record->recordId = $model->id;
                         $location2Record->save();
                     }
                 }
             }
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', 'The new "{title}" company record has been successfully created.', array('{title}' => MHtml::wrapInTag($model->title, 'strong'))));
             // go to the 'show' page
             $this->redirect(array('show', 'id' => $model->id));
         }
     } else {
         // pre-assigned attributes (default values for a new record)
         $model->isActive = Company::IS_ACTIVE;
     }
     if (!isset($model->allUser2Company[0])) {
         // new associated user
         $model->allUser2Company = array(0 => new User2Company('create'));
     }
     $model->allUser2Company[0]->companyId = $model->id;
     if (!isset($model->allLocation[0])) {
         // new associated location
         $model->allLocation = array(0 => new Location('create'));
     }
     // display the create form
     $this->render($this->action->id, array('model' => $model));
 }
 public function saveOrder()
 {
     $inputShipFrom = Input::get('shipFrom');
     $inputShipFrom = $this->jsonToInputArray($inputShipFrom);
     $inputshipTo = Input::get('shipTo');
     $inputshipTo = $this->jsonToInputArray($inputshipTo);
     $inputItem = Input::get('itemDetail');
     $inputItem = $this->jsonToInputArray($inputItem);
     $inputCompany = Input::get('companyInfo');
     $inputCompany = $this->jsonToInputArray($inputCompany);
     $result = array('errors' => '', 'result' => '');
     $foundErrors = false;
     //validate ship from info.
     $shipFrom = new ShipFrom();
     if ($shipFrom->validate($inputShipFrom) === false) {
         $foundErrors = true;
         $messages = $shipFrom->messages();
         if (count($messages)) {
             foreach ($messages as $message) {
                 $result['errors'] .= "<li>{$message}</li>";
             }
         }
     }
     //validate ship to information
     $shipTo = new ShipTo();
     if ($shipTo->validate($inputshipTo) === false) {
         $foundErrors = true;
         $messages = $shipTo->messages();
         if (count($messages)) {
             foreach ($messages as $message) {
                 $result['errors'] .= "<li>{$message}</li>";
             }
         }
     }
     //validate item information
     $item = new Item();
     if ($item->validate($inputItem) === false) {
         $foundErrors = true;
         $messages = $item->messages();
         if (count($messages)) {
             foreach ($messages as $message) {
                 $result['errors'] .= "<li>{$message}</li>";
             }
         }
     }
     //validate company information
     $company = new Company();
     if ($company->validate($inputCompany) === false) {
         $foundErrors = true;
         $messages = $company->messages();
         if (count($messages)) {
             foreach ($messages as $message) {
                 $result['errors'] .= "<li>{$message}</li>";
             }
         }
     }
     if ($foundErrors == true) {
         echo json_encode($result);
         return;
     }
     $data = array('shipFrom' => $inputShipFrom, 'shipTo' => $inputshipTo, 'item' => $inputItem, 'company' => $inputCompany);
     $action = Input::get('action');
     if ($action == 'update') {
         $orderId = Input::get('order_id');
         if (Order::update($orderId, $data) == true) {
             $result['result'] = 'success';
         } else {
             $result['errors'] = "<li>There was a problem with record update.Please try later.</li>";
         }
     } else {
         //create new order
         $newOrderId = Order::insert($data);
         if (is_numeric($newOrderId) && $newOrderId > 0) {
             $result['result'] = 'success';
         }
     }
     echo json_encode($result);
 }
예제 #5
0
파일: User.php 프로젝트: septembermd/n1
 /**
  * Before model saved
  *
  * @return bool
  */
 public function beforeSave()
 {
     // Save new company, if id is not numeric then user added a custom value
     $company = Company::model()->countByAttributes(['id' => $this->company_id]);
     if ($company == 0) {
         $company = new Company();
         $company->setAttribute('title', $this->company_id);
         if (!$company->validate()) {
             $this->addErrors($company->getErrors());
         } else {
             if ($company->save()) {
                 $this->company_id = $company->id;
             } else {
                 $this->addError('company_id', [Yii::t('main', 'Error saving new company.')]);
             }
         }
     }
     // If model is updating
     if (!$this->isNewRecord) {
         $this->beforeUpdate();
     }
     return parent::beforeSave();
 }
예제 #6
0
include "header.php";
$company = new Company();
try {
    if (!$user->level) {
        throw new LoginException("You must be logged in to use this feature.");
    }
    if ($user->level < 2) {
        throw new LoginException("You do not have permission to use this feature.  Please log into the Administrator account.");
    }
    list($company->name, $company->address, $company->city, $company->state, $company->zip, $company->phone, $company->logo) = $input->getInputValues('name', 'address', 'city', 'state', 'zip', 'phone', 'logo');
    $id = $company->exists();
    if ($id) {
        $company->id = $id;
    }
    if ($company->name) {
        $company->validate();
        if ($company->save()) {
            flash("Company Information Updated");
        } else {
            throw new Exception("Could Not Save To Database.");
        }
    } else {
        if ($id) {
            $company->load($id);
        }
    }
    include "../views/companyinfo.php";
} catch (LoginException $e) {
    $redirect = "companyinfo.php";
    include "../views/login.php";
    throw $e;