/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Employee(); $user = new RbacUser(); $disabled = ""; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (Yii::app()->user->checkAccess('employee.create')) { if (isset($_POST['Employee'])) { $model->attributes = $_POST['Employee']; $user->attributes = $_POST['RbacUser']; //$location_id = $_POST['Employee']['location']; 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()) { $user->employee_id = $model->id; if ($user->save()) { $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; if (!$authassigment->save()) { $transaction->rollback(); print_r($authassigment->errors); } } } } $transaction->commit(); Yii::app()->user->setFlash('success', '<strong>Well done!</strong> successfully saved.'); //$this->redirect(array('view', 'id' => $model->id)); $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'); } $this->render('create', 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() { $model = new RbacUser(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['RbacUser'])) { $model->attributes = $_POST['RbacUser']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }