public function actionCreate() { // check permissions // if (!Yii::app()->user->checkAccess('manageUser')) { // Helper::authException(); // } // models $UserLogin = new UserLogin(); $UserProfile = new UserProfile(); $criteria3 = new CDbCriteria(); $criteria3->condition = '(companyID = :companyID AND IsActive=1)'; $criteria3->params = array(':companyID' => Yii::app()->user->companyID); $criteria3->order = 'Email'; $userManagers = UserProfile::model()->with('userLogin')->findAllByAttributes(array(), $criteria3); $managersArray = array(); $managersArray[0] = "Please Select..."; foreach ($userManagers as $UserManager) { //if ($UserManager->ManagerEmail == '') { //$managersArray[$UserManager->Email] = $UserManager->Email; $managersArray[$UserManager->Email] = $UserManager->Email; //} elseif (Helper::hasRole('lacekAdministrator')) { // $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc; // } } // add default (empty value) to front of array $managerArray = $managersArray; // role array for select $userRoles = UserRole::model()->findAll(); $rolesArray = array(); foreach ($userRoles as $UserRole) { if ($UserRole->RoleType != 'lacekAdministrator') { $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc; } elseif (Helper::hasRole('lacekAdministrator')) { $rolesArray[$UserRole->UserRoleID] = $UserRole->RoleDesc; } } // add default (empty value) to front of array $rolesArray = $rolesArray; // form processing if (isset($_POST['UserLogin'], $_POST['UserProfile'])) { // redirect to the dashboard if 'Cancel' button clicked if (isset($_POST['button-cancel'])) { $this->redirect($this->createUrl('user/dashboard')); } // set UserLogin attributes and scenario $UserLogin->attributes = $_POST['UserLogin']; $UserLogin->IsPasswordReset = 1; // force password reset on first login $UserLogin->IsActive = 1; $UserLogin->scenario = 'create'; $UserLogin->UserRoleID = 1; // set UserProfile attributes $UserProfile->attributes = $_POST['UserProfile']; $UserProfile->CompanyID = Yii::app()->user->companyID; $UserProfile->Email = $UserLogin->LoginEmail; // validate form submission $valid = $UserLogin->validate(); $valid = $UserProfile->validate() && $valid; if ($valid) { // save UserLogin if (!$UserLogin->save(false)) { throw new CHttpException(400, 'Error when trying to create user.'); } // save UserProfile $UserProfile->UserLoginID = $UserLogin->UserLoginID; // set newly generated EventID if (!$UserProfile->save(false)) { throw new CHttpException(400, 'Error when trying to create user.'); } if ($UserProfile->ManagerEmail) { $UserProfilex = UserProfile::model()->findByAttributes(array('Email' => $UserProfile->ManagerEmail)); $candidateModel = new Candidate(); $candidateModel->CompanyID = $UserProfile->CompanyID; $candidateModel->EmployeeID = $UserProfile->EmployeeID; $candidateModel->FirstName = $UserProfile->FirstName; $candidateModel->MiddleName = $UserProfile->MiddleName; $candidateModel->LastName = $UserProfile->LastName; $candidateModel->Title = $UserProfile->Title; $candidateModel->Email = $UserProfile->Email; $candidateModel->CompanyPositionID = 1; $candidateModel->HireDate = date("Y-m-d"); $candidateModel->PositionDate = date("Y-m-d"); $candidateModel->IsActive = 1; $candidateModel->UserProfileID = $UserProfilex->UserProfileID; //$candidateModel->UserProfileId=2; //print_r($candidateModel); // die($UserProfilex->UserProfileID); // if ($candidateModel->validate()) { // if ($candidateModel->save()) { $candidateModel->save(); $performanceModel = new Performance(); $ratingModel = new Rating(); $planningModel = new Planning(); $currentYear = date('Y'); // insert new record $performanceModel->CandidateID = $candidateModel->CandidateID; $performanceModel->PerformanceYear = $currentYear; $ratingModel->CandidateID = $candidateModel->CandidateID; $ratingModel->RatingYear = $currentYear; $planningModel->CandidateID = $candidateModel->CandidateID; $planningModel->PlanningYear = $currentYear; $planningModel->CurrentPositionLevel = 3; $planningModel->NextStepPositionLevel = 3; $planningModel->LongTermPositionLevel = 3; $performanceModel->save(); $ratingModel->save(); $planningModel->save(); //} //} // else //{ // $errores = $candidateModel->getErrors(); // print_r($errores); // die(); // } } // set success message for user Yii::app()->user->setFlash('success', 'A new user was successfully created.'); // return to empty create user form if adding another, else go to user dashboard if (isset($_POST['button-submit-add'])) { $this->redirect($this->createUrl('user/create')); } else { $this->redirect($this->createUrl('user/dashboard')); } } } // clear password $UserLogin->UserPassword = null; // render view $this->render('create', array('UserLogin' => $UserLogin, 'UserProfile' => $UserProfile, 'rolesArray' => $rolesArray, 'managersArray' => $managerArray)); }
public function actionAddcandidate() { if (!isset(Yii::app()->user->userProfileID)) { $this->redirect('/user/login'); } // renders the view file 'protected/views/site/index.php' // using the default layout 'protected/views/layouts/main.php' $candidateModel = new Candidate(); $performanceModel = new Performance(); $ratingModel = new Rating(); $planningModel = new Planning(); if (isset($_POST['Candidate'])) { $candidateModel->attributes = $_POST['Candidate']; $candidateModel->IsActive = 1; //$candidateModel->UserProfileID = Yii::app()->user->userProfileID; $candidateModel->CompanyID = Yii::app()->user->companyID; if ($candidateModel->validate()) { if ($candidateModel->save()) { $currentYear = date('Y'); // insert new record $performanceModel->CandidateID = $candidateModel->CandidateID; $performanceModel->PerformanceYear = $currentYear; $ratingModel->CandidateID = $candidateModel->CandidateID; $ratingModel->RatingYear = $currentYear; $planningModel->CandidateID = $candidateModel->CandidateID; $planningModel->PlanningYear = $currentYear; $planningModel->CurrentPositionLevel = $_POST['Candidate']['CompanyPositionID']; if ($_POST['Candidate']['CompanyPositionID'] == 5) { $planningModel->NextStepPositionLevel = 5; $planningModel->LongTermPositionLevel = 5; } else { $planningModel->NextStepPositionLevel = $_POST['Candidate']['CompanyPositionID']; $planningModel->LongTermPositionLevel = $_POST['Candidate']['CompanyPositionID']; } $performanceModel->save(); $ratingModel->save(); $planningModel->save(); $this->redirect(Yii::app()->createUrl('company/candidates')); } } } $criteria3 = new CDbCriteria(); $criteria3->condition = 'companyID = :companyID'; $criteria3->params = array(':companyID' => Yii::app()->user->companyID); $criteria3->order = 'Email'; $userManagers = UserProfile::model()->findAllByAttributes(array(), $criteria3); $managersArray = array(); foreach ($userManagers as $UserManager) { $managersArray[$UserManager->UserProfileID] = $UserManager->Email; } $managerArray = $managersArray; $companyPositions = Helper::getCompanyPositions(Yii::app()->user->companyID); $this->render('candidate-form', array('candidateModel' => $candidateModel, 'planningModel' => $planningModel, 'companyPositionSelect' => $companyPositions, 'managerArray' => $managerArray)); }