function createUserPermission($user_id, $preset_id) { if (isset($this->permission_presets[$preset_id])) { $pclf = new PermissionControlListFactory(); $pclf->getById($this->permission_presets[$preset_id]); if ($pclf->getRecordCount() > 0) { $pc_obj = $pclf->getCurrent(); $puf = new PermissionUserFactory(); $puf->setPermissionControl($pc_obj->getId()); $puf->setUser($user_id); if ($puf->isValid()) { Debug::Text('Assigning User ID: ' . $user_id . ' To Permission Control: ' . $this->permission_presets[$preset_id] . ' Preset: ' . $preset_id, __FILE__, __LINE__, __METHOD__, 10); $puf->Save(); return TRUE; } } } Debug::Text('Failed Assigning User to Permission Control! User ID: ' . $user_id . ' Preset: ' . $preset_id, __FILE__, __LINE__, __METHOD__, 10); return FALSE; }
if ($permission->Check('user', 'edit') or $permission->Check('user', 'edit_own') and $is_owner === TRUE or $permission->Check('user', 'edit_child') and $is_child === TRUE) { $user_title = NULL; if ($user->getTitle() != 0 and is_object($user->getTitleObject())) { $user_title = $user->getTitleObject()->getName(); } Debug::Text('Title: ' . $user_title, __FILE__, __LINE__, __METHOD__, 10); if ($permission->Check('user', 'view_sin') == TRUE) { $sin_number = $user->getSIN(); } else { $sin_number = $user->getSecureSIN(); } $user_data = array('id' => $user->getId(), 'company_id' => $user->getCompany(), 'status' => $user->getStatus(), 'user_name' => $user->getUserName(), 'title_id' => $user->getTitle(), 'title' => $user_title, 'phone_id' => $user->getPhoneId(), 'ibutton_id' => $user->getIbuttonId(), 'employee_number' => $user->getEmployeeNumber(), 'first_name' => $user->getFirstName(), 'middle_name' => $user->getMiddleName(), 'last_name' => $user->getLastName(), 'second_last_name' => $user->getSecondLastName(), 'sex' => $user->getSex(), 'address1' => $user->getAddress1(), 'address2' => $user->getAddress2(), 'city' => $user->getCity(), 'province' => $user->getProvince(), 'country' => $user->getCountry(), 'postal_code' => $user->getPostalCode(), 'work_phone' => $user->getWorkPhone(), 'work_phone_ext' => $user->getWorkPhoneExt(), 'home_phone' => $user->getHomePhone(), 'mobile_phone' => $user->getMobilePhone(), 'fax_phone' => $user->getFaxPhone(), 'home_email' => $user->getHomeEmail(), 'work_email' => $user->getWorkEmail(), 'birth_date' => $user->getBirthDate(), 'hire_date' => $user->getHireDate(), 'termination_date' => $user->getTerminationDate(), 'sin' => $sin_number, 'other_id1' => $user->getOtherID1(), 'other_id2' => $user->getOtherID2(), 'other_id3' => $user->getOtherID3(), 'other_id4' => $user->getOtherID4(), 'other_id5' => $user->getOtherID5(), 'note' => $user->getNote(), 'default_branch_id' => $user->getDefaultBranch(), 'default_department_id' => $user->getDefaultDepartment(), 'group_id' => $user->getGroup(), 'currency_id' => $user->getCurrency(), 'is_owner' => $is_owner, 'is_child' => $is_child, 'created_date' => $user->getCreatedDate(), 'created_by' => $user->getCreatedBy(), 'updated_date' => $user->getUpdatedDate(), 'updated_by' => $user->getUpdatedBy(), 'deleted_date' => $user->getDeletedDate(), 'deleted_by' => $user->getDeletedBy()); $pclfb = new PermissionControlListFactory(); $pclfb->getByCompanyIdAndUserId($user->getCompany(), $id); if ($pclfb->getRecordCount() > 0) { $user_data['permission_control_id'] = $pclfb->getCurrent()->getId(); } $ppslfb = new PayPeriodScheduleListFactory(); $ppslfb->getByUserId($id); if ($ppslfb->getRecordCount() > 0) { $user_data['pay_period_schedule_id'] = $ppslfb->getCurrent()->getId(); } $pglf = new PolicyGroupListFactory(); $pglf->getByUserIds($id); if ($pglf->getRecordCount() > 0) { $user_data['policy_group_id'] = $pglf->getCurrent()->getId(); } $hclf = new HierarchyControlListFactory(); $hclf->getObjectTypeAppendedListByCompanyIDAndUserID($user->getCompany(), $user->getID()); $user_data['hierarchy_control'] = $hclf->getArrayByListFactory($hclf, FALSE, TRUE, FALSE); unset($hclf);
$uf->setUserName($user_data['user_name']); if (!empty($user_data['password']) and $user_data['password'] == $user_data['password2']) { $uf->setPassword($user_data['password']); } else { $uf->Validator->isTrue($uf->password_validator_label, FALSE, $uf->password_validator_match_msg); } $uf->setEmployeeNumber(1); $uf->setFirstName($user_data['first_name']); $uf->setLastName($user_data['last_name']); $uf->setWorkEmail($user_data['work_email']); //Get Permission Control with highest ID, assume its for Administrators //and use it. $pclf = new PermissionControlListFactory(); $pclf->getByCompanyId($user_data['company_id'], NULL, NULL, NULL, array('id' => 'desc')); if ($pclf->getRecordCount() > 0) { $pc_obj = $pclf->getCurrent(); if (is_object($pc_obj)) { Debug::Text('Adding User to Permission Control: ' . $pc_obj->getId(), __FILE__, __LINE__, __METHOD__, 10); $uf->setPermissionControl($pc_obj->getId()); } } if ($uf->isValid()) { $user_id = $uf->Save(); $uf->CommitTransaction(); if ($external_installer == 1) { Redirect::Page(URLBuilder::getURL(NULL, 'Done.php')); } else { Redirect::Page(URLBuilder::getURL(NULL, 'MaintenanceJobs.php')); } break; }
function applyPreset($permission_control_id, $preset, $preset_flags) { $preset_permissions = $this->getPresetPermissions($preset, $preset_flags); if (!is_array($preset_permissions)) { return FALSE; } $this->setPermissionControl($permission_control_id); $pf = new PermissionFactory(); $pf->StartTransaction(); //Delete all previous permissions for this user. $this->deletePermissions($this->getCompany(), $permission_control_id); foreach ($preset_permissions as $section => $permissions) { foreach ($permissions as $name => $value) { Debug::Text('Setting Permission - Section: ' . $section . ' Name: ' . $name . ' Value: ' . (int) $value, __FILE__, __LINE__, __METHOD__, 10); $pf->setPermissionControl($permission_control_id); $pf->setSection($section); $pf->setName($name); $pf->setValue((int) $value); if ($pf->isValid()) { $pf->save(); } } } //Clear cache for all users assigned to this permission_control_id $pclf = new PermissionControlListFactory(); $pclf->getById($permission_control_id); if ($pclf->getRecordCount() > 0) { $pc_obj = $pclf->getCurrent(); if (is_array($pc_obj->getUser())) { foreach ($pc_obj->getUser() as $user_id) { $pf->clearCache($user_id, $this->getCompany()); } } } unset($pclf, $pc_obj, $user_id); //$pf->FailTransaction(); $pf->CommitTransaction(); return TRUE; }
function postSave() { $this->removeCache($this->getId()); if ($this->getDeleted() == FALSE and $this->getPermissionControl() !== FALSE) { Debug::text('Permission Group is set...', __FILE__, __LINE__, __METHOD__, 10); $pclf = new PermissionControlListFactory(); $pclf->getByCompanyIdAndUserID($this->getCompany(), $this->getId()); if ($pclf->getRecordCount() > 0) { Debug::text('Already assigned to a Permission Group...', __FILE__, __LINE__, __METHOD__, 10); $pc_obj = $pclf->getCurrent(); if ($pc_obj->getId() == $this->getPermissionControl()) { $add_permission_control = FALSE; } else { Debug::text('Permission Group has changed...', __FILE__, __LINE__, __METHOD__, 10); //Remove user from current schedule. $pulf = new PermissionUserListFactory(); $pulf->getByPermissionControlIdAndUserID($pc_obj->getId(), $this->getId()); Debug::text('Record Count: ' . $pulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($pulf->getRecordCount() > 0) { foreach ($pulf as $pu_obj) { Debug::text('Deleteing from Permission Group: ' . $pu_obj->getPermissionControl(), __FILE__, __LINE__, __METHOD__, 10); $pu_obj->Delete(); } } $add_permission_control = TRUE; } } else { Debug::text('NOT Already assigned to a Permission Group...', __FILE__, __LINE__, __METHOD__, 10); $add_permission_control = TRUE; } if ($this->getPermissionControl() !== FALSE and $add_permission_control == TRUE) { Debug::text('Adding user to Permission Group...', __FILE__, __LINE__, __METHOD__, 10); //Add to new permission group $puf = new PermissionUserFactory(); $puf->setPermissionControl($this->getPermissionControl()); $puf->setUser($this->getID()); if ($puf->isValid()) { $puf->Save(); //Clear permission class for this employee. $pf = new PermissionFactory(); $pf->clearCache($this->getID(), $this->getCompany()); } } unset($add_permission_control); } if ($this->getDeleted() == FALSE and $this->getPayPeriodSchedule() !== FALSE) { Debug::text('Pay Period Schedule is set...', __FILE__, __LINE__, __METHOD__, 10); $ppslf = new PayPeriodScheduleListFactory(); $ppslf->getByUserId($this->getId()); if ($ppslf->getRecordCount() > 0) { $pps_obj = $ppslf->getCurrent(); if ($this->getPayPeriodSchedule() == $pps_obj->getId()) { Debug::text('Already assigned to this Pay Period Schedule...', __FILE__, __LINE__, __METHOD__, 10); $add_pay_period_schedule = FALSE; } else { Debug::text('Changing Pay Period Schedule...', __FILE__, __LINE__, __METHOD__, 10); //Remove user from current schedule. $ppsulf = new PayPeriodScheduleUserListFactory(); $ppsulf->getByPayPeriodScheduleIdAndUserID($pps_obj->getId(), $this->getId()); Debug::text('Record Count: ' . $ppsulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($ppsulf->getRecordCount() > 0) { foreach ($ppsulf as $ppsu_obj) { Debug::text('Deleteing from Pay Period Schedule: ' . $ppsu_obj->getPayPeriodSchedule(), __FILE__, __LINE__, __METHOD__, 10); $ppsu_obj->Delete(); } } $add_pay_period_schedule = TRUE; } } else { Debug::text('Not assigned to ANY Pay Period Schedule...', __FILE__, __LINE__, __METHOD__, 10); $add_pay_period_schedule = TRUE; } if ($this->getPayPeriodSchedule() !== FALSE and $add_pay_period_schedule == TRUE) { //Add to new pay period schedule $ppsuf = new PayPeriodScheduleUserFactory(); $ppsuf->setPayPeriodSchedule($this->getPayPeriodSchedule()); $ppsuf->setUser($this->getID()); if ($ppsuf->isValid()) { $ppsuf->Save(); } } unset($add_pay_period_schedule); } if ($this->getDeleted() == FALSE and $this->getPolicyGroup() !== FALSE) { Debug::text('Policy Group is set...', __FILE__, __LINE__, __METHOD__, 10); $pglf = new PolicyGroupListFactory(); $pglf->getByUserIds($this->getId()); if ($pglf->getRecordCount() > 0) { $pg_obj = $pglf->getCurrent(); if ($this->getPolicyGroup() == $pg_obj->getId()) { Debug::text('Already assigned to this Policy Group...', __FILE__, __LINE__, __METHOD__, 10); $add_policy_group = FALSE; } else { Debug::text('Changing Policy Group...', __FILE__, __LINE__, __METHOD__, 10); //Remove user from current schedule. $pgulf = new PolicyGroupUserListFactory(); $pgulf->getByPolicyGroupIdAndUserId($pg_obj->getId(), $this->getId()); Debug::text('Record Count: ' . $pgulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($pgulf->getRecordCount() > 0) { foreach ($pgulf as $pgu_obj) { Debug::text('Deleteing from Policy Group: ' . $pgu_obj->getPolicyGroup(), __FILE__, __LINE__, __METHOD__, 10); $pgu_obj->Delete(); } } $add_policy_group = TRUE; } } else { Debug::text('Not assigned to ANY Policy Group...', __FILE__, __LINE__, __METHOD__, 10); $add_policy_group = TRUE; } if ($this->getPolicyGroup() !== FALSE and $add_policy_group == TRUE) { //Add to new policy group $pguf = new PolicyGroupUserFactory(); $pguf->setPolicyGroup($this->getPolicyGroup()); $pguf->setUser($this->getID()); if ($pguf->isValid()) { $pguf->Save(); } } unset($add_policy_group); } if ($this->getDeleted() == FALSE and $this->getHierarchyControl() !== FALSE) { Debug::text('Hierarchies are set...', __FILE__, __LINE__, __METHOD__, 10); $hierarchy_control_data = array_unique(array_values((array) $this->getHierarchyControl())); //Debug::Arr($hierarchy_control_data, 'Setting hierarchy control data...', __FILE__, __LINE__, __METHOD__, 10); if (is_array($hierarchy_control_data)) { $hclf = new HierarchyControlListFactory(); $hclf->getObjectTypeAppendedListByCompanyIDAndUserID($this->getCompany(), $this->getID()); $existing_hierarchy_control_data = array_unique(array_values((array) $hclf->getArrayByListFactory($hclf, FALSE, TRUE, FALSE))); //Debug::Arr($existing_hierarchy_control_data, 'Existing hierarchy control data...', __FILE__, __LINE__, __METHOD__, 10); $hierarchy_control_delete_diff = array_diff($existing_hierarchy_control_data, $hierarchy_control_data); //Debug::Arr($hierarchy_control_delete_diff, 'Hierarchy control delete diff: ', __FILE__, __LINE__, __METHOD__, 10); //Remove user from existing hierarchy control if (is_array($hierarchy_control_delete_diff)) { foreach ($hierarchy_control_delete_diff as $hierarchy_control_id) { if ($hierarchy_control_id != 0) { $hulf = new HierarchyUserListFactory(); $hulf->getByHierarchyControlAndUserID($hierarchy_control_id, $this->getID()); if ($hulf->getRecordCount() > 0) { Debug::text('Deleting user from hierarchy control ID: ' . $hierarchy_control_id, __FILE__, __LINE__, __METHOD__, 10); $hulf->getCurrent()->Delete(); } } } } unset($hierarchy_control_delete_diff, $hulf, $hclf, $hierarchy_control_id); $hierarchy_control_add_diff = array_diff($hierarchy_control_data, $existing_hierarchy_control_data); //Debug::Arr($hierarchy_control_add_diff, 'Hierarchy control add diff: ', __FILE__, __LINE__, __METHOD__, 10); if (is_array($hierarchy_control_add_diff)) { foreach ($hierarchy_control_add_diff as $hierarchy_control_id) { Debug::text('Hierarchy data changed...', __FILE__, __LINE__, __METHOD__, 10); if ($hierarchy_control_id != 0) { $huf = new HierarchyUserFactory(); $huf->setHierarchyControl($hierarchy_control_id); $huf->setUser($this->getId()); if ($huf->isValid()) { Debug::text('Adding user to hierarchy control ID: ' . $hierarchy_control_id, __FILE__, __LINE__, __METHOD__, 10); $huf->Save(); } } } } unset($hierarchy_control_add, $huf, $hierarchy_control_id); } } if (isset($this->is_new) and $this->is_new == TRUE) { $udlf = new UserDefaultListFactory(); $udlf->getByCompanyId($this->getCompany()); if ($udlf->getRecordCount() > 0) { Debug::Text('Using User Defaults', __FILE__, __LINE__, __METHOD__, 10); $udf_obj = $udlf->getCurrent(); Debug::text('Inserting Default Deductions...', __FILE__, __LINE__, __METHOD__, 10); $company_deduction_ids = $udf_obj->getCompanyDeduction(); if (is_array($company_deduction_ids) and count($company_deduction_ids) > 0) { foreach ($company_deduction_ids as $company_deduction_id) { $udf = new UserDeductionFactory(); $udf->setUser($this->getId()); $udf->setCompanyDeduction($company_deduction_id); if ($udf->isValid()) { $udf->Save(); } } } unset($company_deduction_ids, $company_deduction_id, $udf); Debug::text('Inserting Default Prefs...', __FILE__, __LINE__, __METHOD__, 10); $upf = new UserPreferenceFactory(); $upf->setUser($this->getId()); $upf->setLanguage($udf_obj->getLanguage()); $upf->setDateFormat($udf_obj->getDateFormat()); $upf->setTimeFormat($udf_obj->getTimeFormat()); $upf->setTimeUnitFormat($udf_obj->getTimeUnitFormat()); $upf->setTimeZone($udf_obj->getTimeZone()); $upf->setItemsPerPage($udf_obj->getItemsPerPage()); $upf->setStartWeekDay($udf_obj->getStartWeekDay()); $upf->setEnableEmailNotificationException($udf_obj->getEnableEmailNotificationException()); $upf->setEnableEmailNotificationMessage($udf_obj->getEnableEmailNotificationMessage()); $upf->setEnableEmailNotificationHome($udf_obj->getEnableEmailNotificationHome()); if ($upf->isValid()) { $upf->Save(); } } } if ($this->getDeleted() == TRUE) { //Remove them from the authorization hierarchy, policy group, and pay period schedule. //Delete any accruals for them as well. //Pay Period Schedule $ppslf = new PayPeriodScheduleListFactory(); $ppslf->getByUserId($this->getId()); if ($ppslf->getRecordCount() > 0) { $pps_obj = $ppslf->getCurrent(); //Remove user from current schedule. $ppsulf = new PayPeriodScheduleUserListFactory(); $ppsulf->getByPayPeriodScheduleIdAndUserID($pps_obj->getId(), $this->getId()); Debug::text('Record Count: ' . $ppsulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($ppsulf->getRecordCount() > 0) { foreach ($ppsulf as $ppsu_obj) { Debug::text('Deleteing from Pay Period Schedule: ' . $ppsu_obj->getPayPeriodSchedule(), __FILE__, __LINE__, __METHOD__, 10); $ppsu_obj->Delete(); } } } //Policy Group $pglf = new PolicyGroupListFactory(); $pglf->getByUserIds($this->getId()); if ($pglf->getRecordCount() > 0) { $pg_obj = $pglf->getCurrent(); $pgulf = new PolicyGroupUserListFactory(); $pgulf->getByPolicyGroupIdAndUserId($pg_obj->getId(), $this->getId()); Debug::text('Record Count: ' . $pgulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($pgulf->getRecordCount() > 0) { foreach ($pgulf as $pgu_obj) { Debug::text('Deleteing from Policy Group: ' . $pgu_obj->getPolicyGroup(), __FILE__, __LINE__, __METHOD__, 10); $pgu_obj->Delete(); } } } //Hierarchy $hclf = new HierarchyControlListFactory(); $hclf->getByCompanyId($this->getCompany()); if ($hclf->getRecordCount() > 0) { foreach ($hclf as $hc_obj) { $hf = new HierarchyListFactory(); $hf->setUser($this->getID()); $hf->setHierarchyControl($hc_obj->getId()); $hf->Delete(); } $hf->removeCache(NULL, $hf->getTable(TRUE)); //On delete we have to delete the entire group. unset($hf); } //Accrual balances $alf = new AccrualListFactory(); $alf->getByUserIdAndCompanyId($this->getId(), $this->getCompany()); if ($alf->getRecordCount() > 0) { foreach ($alf as $a_obj) { $a_obj->setDeleted(TRUE); if ($a_obj->isValid()) { $a_obj->Save(); } } } } return TRUE; }