/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $this->layout = ''; $model = new User(); $profile = new Profile(); $this->performAjaxValidation(array($model, $profile)); if (isset($_POST['User'])) { $post_user = $_POST['User']; /** * for customer user * - email is username * - password generated */ if (isset($_POST['user_type']) && $_POST['user_type'] == 'customer') { $post_user['username'] = $post_user['email']; $post_user['password'] = DbrLib::rand_string(8); $post_user['status'] = User::STATUS_ACTIVE; } $model->attributes = $post_user; $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password); $profile->attributes = $_POST['Profile']; $profile->user_id = 0; if ($model->validate() && $profile->validate()) { $model->password = Yii::app()->controller->module->encrypting($model->password); if ($model->save()) { if (Yii::app()->sysCompany->getActiveCompany()) { //create person $model_person = new PprsPerson(); $model_person->pprs_first_name = $profile->first_name; $model_person->pprs_second_name = $profile->last_name; if (isset($post_user['ccmp_id'])) { $model_person->pprs_ccmp_id = $post_user['ccmp_id']; } else { $model_person->pprs_ccmp_id = Yii::app()->sysCompany->getActiveCompany(); } $model_person->save(); } $profile->user_id = $model->id; $profile->person_id = $model_person->primaryKey; $profile->save(); /** * customer user * - add role user customer * - redirect to view */ if (isset($_POST['user_type']) && $_POST['user_type'] == 'customer') { //add role user customer $aa_model = new Authassignment(); $aa_model->itemname = Yii::app()->getModule('user')->customerUser['role']; $aa_model->userid = $model->id; $aa_model->save(); //redirect to view $this->redirect(array('viewCustomer', 'id' => $model->id)); } } $this->redirect(array('view', 'id' => $model->id)); } else { $profile->validate(); } } if (isset($_GET['type']) && $_GET['type'] == 'customer') { $this->menu_route = "user/admin/customerAdmin"; $view = 'create_customer'; } else { $view = 'create'; } if (Yii::app()->getModule('user')->view) { $alt_view = Yii::app()->getModule('user')->view . '.admin.' . $view; if (is_readable(Yii::getPathOfAlias($alt_view) . '.php')) { $view = $alt_view; $this->layout = Yii::app()->getModule('user')->layout; } } $this->render($view, array('model' => $model, 'profile' => $profile)); }
/** * crreate person for company * @param int $ccmp_id company id * @return type * @throws CHttpException */ public function actionAjaxCreateSpec($ccmp_id) { $model = new PprsPerson(); $model->{$field} = $value; try { if (!$model->save()) { return var_export($model->getErrors()); } } catch (Exception $e) { throw new CHttpException(500, $e->getMessage()); } $ccuc = new CcucUserCompany(); $ccuc->ccuc_ccmp_id = $ccmp_id; $ccuc->ccuc_person_id = $model->pprs_id; $ccuc->ccuc_status = CcucUserCompany::CCUC_STATUS_PERSON; $ccuc->save(); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $this->layout = ''; $model = new User(); $profile = new Profile(); $this->performAjaxValidation(array($model, $profile)); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password); $profile->attributes = $_POST['Profile']; $profile->user_id = 0; if ($model->validate() && $profile->validate()) { $model->password = Yii::app()->controller->module->encrypting($model->password); if ($model->save()) { if (Yii::app()->sysCompany->getActiveCompany()) { //create person $model_person = new PprsPerson(); $model_person->pprs_first_name = $profile->first_name; $model_person->pprs_second_name = $profile->last_name; $model_person->pprs_ccmp_id = Yii::app()->sysCompany->getActiveCompany(); $model_person->save(); } $profile->user_id = $model->id; $profile->person_id = $model_person->primaryKey; $profile->save(); } $this->redirect(array('view', 'id' => $model->id)); } else { $profile->validate(); } } $view = 'create'; if (Yii::app()->getModule('user')->view) { $alt_view = Yii::app()->getModule('user')->view . '.admin.' . $view; if (is_readable(Yii::getPathOfAlias($alt_view) . '.php')) { $view = $alt_view; $this->layout = Yii::app()->getModule('user')->layout; } } $this->render($view, array('model' => $model, 'profile' => $profile)); }