/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Authassignment(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Authassignment'])) { $model->attributes = $_POST['Authassignment']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->itemname)); } } $this->render('create', array('model' => $model)); }
/** * 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 actionUpdate($id) { $disabled = ""; if (Yii::app()->user->checkAccess('employee.update')) { $model = $this->loadModel($id); $user = RbacUser::model()->find('employee_id=:employeeID', array(':employeeID' => (int) $id)); $criteria = new CDbCriteria(); $criteria->condition = 'userid=:userId'; $criteria->select = 'itemname'; $criteria->params = array(':userId' => $user->id); $authassigment = Authassignment::model()->findAll($criteria); $auth_items = array(); foreach ($authassigment as $auth_item) { $auth_items[] = $auth_item->itemname; } $user->items = $auth_items; $user->sales = $auth_items; $user->employees = $auth_items; $user->customers = $auth_items; $user->store = $auth_items; $user->suppliers = $auth_items; $user->receivings = $auth_items; $user->reports = $auth_items; $user->invoices = $auth_items; $user->payments = $auth_items; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Employee'])) { $model->attributes = $_POST['Employee']; $user->attributes = $_POST['RbacUser']; if ($_POST['Employee']['year'] !== "" || $_POST['Employee']['month'] !== "" || $_POST['Employee']['day'] !== "") { $dob = $_POST['Employee']['year'] . '-' . $_POST['Employee']['month'] . '-' . $_POST['Employee']['day']; $model->dob = $dob; } // validate BOTH $a and $b $valid = $model->validate(); $valid = $user->validate() && $valid; if ($valid) { $transaction = $model->dbConnection->beginTransaction(); try { if ($model->save()) { if ($user->save()) { // Delete all existing granted module Authassignment::model()->deleteAuthassignment($user->id); $assignitems = array('items', 'sales', 'employees', 'customers', 'suppliers', 'store', 'receivings', 'reports', 'invoices', 'payments'); foreach ($assignitems as $assignitem) { if (!empty($_POST['RbacUser'][$assignitem])) { foreach ($_POST['RbacUser'][$assignitem] as $itemId) { $authassigment = new Authassignment(); $authassigment->userid = $user->id; $authassigment->itemname = $itemId; $authassigment->save(); } } } $transaction->commit(); Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, 'Employee : <strong>' . ucwords($model->last_name . ' ' . $model->first_name) . '</strong> have been saved successfully!'); $this->redirect(array('admin')); } else { Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few things up and try submitting again.'); } } } catch (Exception $e) { $transaction->rollback(); Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few things up and try submitting again.' . $e); } } } } else { throw new CHttpException(403, 'You are not authorized to perform this action'); } if (strtolower($user->user_name) == strtolower('admin') || strtolower($user->user_name) == strtolower('super')) { $disabled = "true"; } $this->render('update', array('model' => $model, 'user' => $user, 'disabled' => $disabled)); }
/** * 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)); }
/** * Displays a particular model. */ public function actionView() { $this->layout = ''; $model = $this->loadModel(); //update record if (isset($_POST['user_role_name']) || isset($_POST['user_sys_ccmp_id'])) { //cheked roles $aChecked = Authassignment::model()->getUserRoles($model->id); //get in form checked $aPostRole = array(); if (isset($_POST['user_role_name'])) { foreach ($_POST['user_role_name'] as $nRoleId) { $aPostRole[] = $nRoleId; } } $aDelRole = array_diff($aChecked, $aPostRole); $aNewRole = array_diff($aPostRole, $aChecked); $UserAdminRoles = Yii::app()->getModule('user')->UserAdminRoles; foreach ($aNewRole as $sRoleName) { // can not add no User Admin roles defined in main config if (!in_array($sRoleName, $UserAdminRoles)) { continue; } $aa_model = new Authassignment(); $aa_model->itemname = $sRoleName; $aa_model->userid = $model->id; if (!$aa_model->save()) { print_r($aa_model->errors); exit; } } if (!empty($aDelRole)) { Authassignment::model()->deleteAll("`userid` = :userid AND itemname in('" . implode("','", $aDelRole) . "')", array(':userid' => $model->id)); } //checked companies $aUserCompanies = CcucUserCompany::model()->getUserCompnies($model->id, CcucUserCompany::CCUC_STATUS_SYS); $aChecked = array(); foreach ($aUserCompanies as $UC) { $aChecked[] = $UC->ccuc_ccmp_id; } //get in form checked $aPostSysCcmp = array(); if (isset($_POST['user_sys_ccmp_id'])) { foreach ($_POST['user_sys_ccmp_id'] as $ccmp_id) { $aPostSysCcmp[] = $ccmp_id; } } $aDelSysCcmpid = array_diff($aChecked, $aPostSysCcmp); $aNewSysCcmpid = array_diff($aPostSysCcmp, $aChecked); $list = array(); if (UserModule::isAdmin()) { //for admin get all sys companies $criteria = new CDbCriteria(); $criteria->compare('t.ccxg_ccgr_id', 1); //1 - syscompany $model_ccxg = CcxgCompanyXGroup::model()->findAll($criteria); foreach ($model_ccxg as $mCcxg) { $list[$mCcxg->ccxg_ccmp_id] = 1; } } else { foreach (Yii::app()->sysCompany->getClientCompanies() as $mCcmp) { $list[$mCcmp->ccucCcmp->ccmp_id] = 1; } } foreach ($aNewSysCcmpid as $cmmp_id) { // can not add no User Admin sys ccmp if (!isset($list[$cmmp_id])) { continue; } //create ccuc (company <==> person) $mCcuc = new CcucUserCompany(); $mCcuc->ccuc_ccmp_id = $cmmp_id; $mCcuc->ccuc_status = CcucUserCompany::CCUC_STATUS_SYS; $mCcuc->ccuc_person_id = $model->profile->person_id; $mCcuc->save(); if (!$mCcuc->save()) { print_r($mCcuc->errors); exit; } } if (!empty($aDelSysCcmpid)) { CcucUserCompany::model()->deleteAll("`ccuc_status` = :ccuc_status " . " AND `ccuc_person_id` = :ccuc_person_id " . " AND ccuc_ccmp_id in('" . implode("','", $aDelSysCcmpid) . "')", array(':ccuc_person_id' => $model->profile->person_id, ':ccuc_status' => CcucUserCompany::CCUC_STATUS_SYS)); } } $view = 'view'; 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; } } $model = $this->loadModel(); $this->render($view, array('model' => $model)); }