function createPermissionGroups($company_id) { Debug::text('Adding Preset Permission Groups: ' . $company_id, __FILE__, __LINE__, __METHOD__, 9); $pf = new PermissionFactory(); $pf->StartTransaction(); if (getTTProductEdition() == 20) { $preset_flags = array('invoice' => 0, 'job' => 1, 'document' => 0); /* $preset_flags = array( 'job' => 1, 'invoice' => 1, 'document' => 1, ); */ } else { $preset_flags = array(); } $preset_options = $pf->getOptions('preset'); foreach ($preset_options as $preset_id => $preset_name) { $pcf = new PermissionControlFactory(); $pcf->setCompany($company_id); $pcf->setName($preset_name); $pcf->setDescription(''); if ($pcf->isValid()) { $pcf_id = $pcf->Save(FALSE); $this->permission_presets[$preset_id] = $pcf_id; $pf->applyPreset($pcf_id, $preset_id, $preset_flags); } } //$pf->FailTransaction(); $pf->CommitTransaction(); }
function postSave() { $pf = new PermissionFactory(); $clear_cache_user_ids = array_merge((array) $this->getUser(), (array) $this->tmp_previous_user_ids); foreach ($clear_cache_user_ids as $user_id) { $pf->clearCache($user_id, $this->getCompany()); } }
function postSave() { $this->removeCache($this->getId()); $this->remoteSave(); if ($this->getDeleted() == FALSE) { //Add base currency for this new company. if ($this->getEnableAddCurrency() == TRUE) { $clf = new CurrencyListFactory(); $clf->getByCompanyId($this->getId()); if ($clf->getRecordCount() == 0) { Debug::text('Adding Default Currency', __FILE__, __LINE__, __METHOD__, 9); $cf = new CurrencyFactory(); $country_to_currency_map_arr = $cf->getOptions('country_currency'); if (isset($country_to_currency_map_arr[$this->getCountry()])) { $base_currency = $country_to_currency_map_arr[$this->getCountry()]; Debug::text('Found Base Currency For Country: ' . $this->getCountry() . ' Currency: ' . $base_currency, __FILE__, __LINE__, __METHOD__, 9); } else { Debug::text('DID NOT Find Base Currency For Country: ' . $this->getCountry() . ' Using default USD.', __FILE__, __LINE__, __METHOD__, 9); $base_currency = 'USD'; } $cf->setCompany($this->getId()); $cf->setStatus(10); $cf->setName($base_currency); $cf->setISOCode($base_currency); $cf->setConversionRate('1.000000000'); $cf->setAutoUpdate(FALSE); $cf->setBase(TRUE); $cf->setDefault(TRUE); if ($cf->isValid()) { $cf->Save(); } } } if ($this->getEnableAddPermissionGroupPreset() == TRUE) { Debug::text('Adding Preset Permission Groups', __FILE__, __LINE__, __METHOD__, 9); $pf = new PermissionFactory(); $pf->StartTransaction(); if ($this->getProductEdition() == 20) { $preset_flags = array('job' => 1, 'invoice' => 1, 'document' => 1); } else { $preset_flags = array(); } $preset_options = $pf->getOptions('preset'); foreach ($preset_options as $preset_id => $preset_name) { $pcf = new PermissionControlFactory(); $pcf->setCompany($this->getId()); $pcf->setName($preset_name); $pcf->setDescription(''); if ($pcf->isValid()) { $pcf_id = $pcf->Save(FALSE); $pf->applyPreset($pcf_id, $preset_id, $preset_flags); } } //$pf->FailTransaction(); $pf->CommitTransaction(); } if ($this->getEnableAddStation() == TRUE) { Debug::text('Adding Default Station', __FILE__, __LINE__, __METHOD__, 9); //Enable punching in from all stations $sf = new StationFactory(); $sf->setCompany($this->getId()); $sf->setStatus(20); $sf->setType(10); $sf->setSource('ANY'); $sf->setStation('ANY'); $sf->setDescription('All stations'); $sf->setGroupSelectionType(10); $sf->setBranchSelectionType(10); $sf->setDepartmentSelectionType(10); if ($sf->isValid()) { $sf->Save(); } } if ($this->getEnableAddPayStubEntryAccountPreset() == TRUE) { Debug::text('Adding Pay Stub Entry Account Presets', __FILE__, __LINE__, __METHOD__, 9); PayStubEntryAccountFactory::addPresets($this->getId()); } if ($this->getEnableAddCompanyDeductionPreset() == TRUE) { Debug::text('Adding Company Deduction Presets', __FILE__, __LINE__, __METHOD__, 9); CompanyDeductionFactory::addPresets($this->getId()); } if ($this->getEnableAddRecurringHolidayPreset() == TRUE) { Debug::text('Adding Recurring Holiday Presets', __FILE__, __LINE__, __METHOD__, 9); RecurringHolidayFactory::addPresets($this->getId(), $this->getCountry()); } } if ($this->getDeleted() == TRUE) { $ulf = new UserListFactory(); $ulf->getByCompanyId($this->getID()); if ($ulf->getRecordCount() > 0) { $ulf->StartTransaction(); foreach ($ulf as $u_obj) { Debug::text('Deleting User ID: ' . $u_obj->getId(), __FILE__, __LINE__, __METHOD__, 9); $u_obj->setDeleted(TRUE); if ($u_obj->isValid()) { $u_obj->Save(); } } $ulf->CommitTransaction(); } } return TRUE; }
function preInstall() { Debug::text('preInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9); /* Permission System Upgrade. - Use direct query to get current permission data and store in memory for postInstall. */ $query = 'select company_id,user_id,section,name,value from permission where deleted = 0 order by company_id, user_id, section, name'; $rs = $this->getDatabaseConnection()->Execute($query); foreach ($rs as $row) { $user_permission_data[$row['company_id']][$row['user_id']][$row['section']][$row['name']] = $row['value']; //If employee has Punch In/Out permission enabled, add individual punch permission too. if ($row['section'] == 'punch' and $row['name'] == 'punch_in_out' and $row['value'] == 1) { $user_permission_data[$row['company_id']][$row['user_id']]['punch']['edit_transfer'] = 1; $user_permission_data[$row['company_id']][$row['user_id']]['punch']['edit_branch'] = 1; $user_permission_data[$row['company_id']][$row['user_id']]['punch']['edit_department'] = 1; $user_permission_data[$row['company_id']][$row['user_id']]['punch']['edit_note'] = 1; $user_permission_data[$row['company_id']][$row['user_id']]['punch']['edit_other_id1'] = 1; $user_permission_data[$row['company_id']][$row['user_id']]['punch']['edit_other_id2'] = 1; $user_permission_data[$row['company_id']][$row['user_id']]['punch']['edit_other_id3'] = 1; $user_permission_data[$row['company_id']][$row['user_id']]['punch']['edit_other_id4'] = 1; $user_permission_data[$row['company_id']][$row['user_id']]['punch']['edit_other_id5'] = 1; if (isset($user_permission_data[$row['company_id']][$row['user_id']]['job']['enabled']) and $user_permission_data[$row['company_id']][$row['user_id']]['job']['enabled'] == 1) { $user_permission_data[$row['company_id']][$row['user_id']]['punch']['edit_job'] = 1; $user_permission_data[$row['company_id']][$row['user_id']]['punch']['edit_job_item'] = 1; $user_permission_data[$row['company_id']][$row['user_id']]['punch']['edit_quantity'] = 1; $user_permission_data[$row['company_id']][$row['user_id']]['punch']['edit_bad_quantity'] = 1; } } $user_permission_data[$row['company_id']][$row['user_id']]['absence']['enabled'] = 1; $user_permission_data[$row['company_id']][$row['user_id']]['absence']['view_own'] = 1; //We added the "Absence" permission section, so we need to copy punch permissions to this. if ($row['section'] == 'punch' and $row['name'] == 'view_child' and $row['value'] == 1) { $user_permission_data[$row['company_id']][$row['user_id']]['absence']['view_child'] = 1; } if ($row['section'] == 'punch' and $row['name'] == 'edit_child' and $row['value'] == 1) { $user_permission_data[$row['company_id']][$row['user_id']]['absence']['edit_child'] = 1; $user_permission_data[$row['company_id']][$row['user_id']]['absence']['add'] = 1; } if ($row['section'] == 'punch' and $row['name'] == 'delete_child' and $row['value'] == 1) { $user_permission_data[$row['company_id']][$row['user_id']]['absence']['delete_child'] = 1; } if ($row['section'] == 'punch' and $row['name'] == 'view' and $row['value'] == 1) { $user_permission_data[$row['company_id']][$row['user_id']]['absence']['view'] = 1; } if ($row['section'] == 'punch' and $row['name'] == 'edit' and $row['value'] == 1) { $user_permission_data[$row['company_id']][$row['user_id']]['absence']['edit'] = 1; $user_permission_data[$row['company_id']][$row['user_id']]['absence']['add'] = 1; } if ($row['section'] == 'punch' and $row['name'] == 'delete' and $row['value'] == 1) { $user_permission_data[$row['company_id']][$row['user_id']]['absence']['delete'] = 1; } } //Group Permissions together if (isset($user_permission_data)) { foreach ($user_permission_data as $company_id => $user_ids) { //Get default employee permissions to start from. if (isset($user_permission_data[$company_id]['-1'])) { $this->permission_groups[$company_id]['default'] = $user_permission_data[$company_id]['-1']; } else { $this->permission_groups[$company_id]['default'] = array(); } unset($user_permission_data[$company_id]['-1']); $x = 1; foreach ($user_ids as $user_id => $permission_user_data) { $permission_no_differences_found = FALSE; foreach ($this->permission_groups[$company_id] as $group_name => $permission_group_data) { Debug::text('Company ID: ' . $company_id . ' Checking Permission Differences Between User ID: ' . $user_id . ' AND Group: ' . $group_name, __FILE__, __LINE__, __METHOD__, 10); //Need to diff the arrays both directions, because the diff function only checks in one direction on its own. $forward_permission_diff_arr = Misc::array_diff_assoc_recursive($permission_user_data, $permission_group_data); $reverse_permission_diff_arr = Misc::array_diff_assoc_recursive($permission_group_data, $permission_user_data); Debug::text('Permission User Data Count: ' . count($permission_user_data, COUNT_RECURSIVE) . ' Permission Group Data Count: ' . count($permission_group_data, COUNT_RECURSIVE), __FILE__, __LINE__, __METHOD__, 10); if ($forward_permission_diff_arr == FALSE and $reverse_permission_diff_arr == FALSE) { Debug::text('No Differences Found in Permissions! ', __FILE__, __LINE__, __METHOD__, 10); $permission_no_differences_found = TRUE; if ($user_id != -1) { $this->permission_group_users[$company_id][$group_name][] = $user_id; } break; } else { Debug::text('Differences Found in Permissions! ', __FILE__, __LINE__, __METHOD__, 10); //Debug::Arr($forward_permission_diff_arr, 'Forward Permission Differences:', __FILE__, __LINE__, __METHOD__, 10); //Debug::Arr($reverse_permission_diff_arr, 'Reverse Permission Differences:', __FILE__, __LINE__, __METHOD__, 10); } } unset($forward_permission_diff_arr, $reverse_permission_diff_arr); if ($permission_no_differences_found == FALSE) { Debug::text('Creating New Permission Group...: ' . $x, __FILE__, __LINE__, __METHOD__, 10); $pf = new PermissionFactory(); $preset_arr = array(10, 18, 20, 30, 40); foreach ($preset_arr as $preset) { $tmp_preset_permissions = $pf->getPresetPermissions($preset, array()); $preset_permission_diff_arr = Misc::array_diff_assoc_recursive($permission_user_data, $tmp_preset_permissions); $preset_permission_diff_count = count($preset_permission_diff_arr, COUNT_RECURSIVE); Debug::text('Preset Permission Diff Count...: ' . $preset_permission_diff_count . ' Preset ID: ' . $preset, __FILE__, __LINE__, __METHOD__, 10); $preset_match[$preset] = $preset_permission_diff_count; } unset($preset_arr, $tmp_preset_permissions); krsort($preset_match); //Flip the array so if there are more then one preset with the same match_count, we use the smallest preset value. $preset_match = array_flip($preset_match); //Flip the array back so the key is the match_preset again. $preset_match = array_flip($preset_match); foreach ($preset_match as $best_match_preset => $match_value) { break; } //Debug::Arr($preset_match, 'zPreset Match Array: ', __FILE__, __LINE__, __METHOD__, 10); //Create new group name, based on closest preset match $preset_name_options = $pf->getOptions('preset'); if (isset($preset_name_options[$best_match_preset])) { $group_name = $preset_name_options[$best_match_preset] . ' (' . $match_value . ') #' . $x; } else { $group_name = 'Group #' . $x; } Debug::text('Group Name: ' . $group_name, __FILE__, __LINE__, __METHOD__, 10); $this->permission_groups[$company_id][$group_name] = $permission_user_data; if ($user_id != -1) { $this->permission_group_users[$company_id][$group_name][] = $user_id; } unset($pf, $best_match_preset, $match_value); $x++; } } ksort($this->permission_group_users[$company_id]); ksort($this->permission_groups[$company_id]); unset($permission_user_data, $permission_group_data, $group_name, $company_id, $user_id); } unset($user_permission_data); } return TRUE; }
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; }
if ($pcf_id != '' and isset($data['preset'])) { Debug::Text('Applying Preset!', __FILE__, __LINE__, __METHOD__, 10); $pf = new PermissionFactory(); $pf->applyPreset($pcf_id, $data['preset'], $data['preset_flags']); } } } //$pcf->FailTransaction(); $pcf->CommitTransaction(); Redirect::Page(URLBuilder::getURL(array(), 'PermissionControlList.php')); break; } } $pcf->FailTransaction(); default: $pf = new PermissionFactory(); $plf = new PermissionListFactory(); if (isset($id)) { BreadCrumb::setCrumb($title); $pclf = new PermissionControlListFactory(); $pclf->getByIdAndCompanyId($id, $current_company->getId()); foreach ($pclf as $pc_obj) { $data = array('id' => $pc_obj->getId(), 'name' => $pc_obj->getName(), 'description' => $pc_obj->getDescription(), 'user_ids' => $pc_obj->getUser(), 'created_date' => $pc_obj->getCreatedDate(), 'created_by' => $pc_obj->getCreatedBy(), 'updated_date' => $pc_obj->getUpdatedDate(), 'updated_by' => $pc_obj->getUpdatedBy(), 'deleted_date' => $pc_obj->getDeletedDate(), 'deleted_by' => $pc_obj->getDeletedBy()); } //$plf->getAllPermissionsByCompanyIdAndPermissionControlId($company_id, $id); $plf->getByCompanyIdAndPermissionControlId($current_company->getId(), $id); if ($plf->getRecordCount() > 0) { Debug::Text('Found Current Permissions!', __FILE__, __LINE__, __METHOD__, 10); foreach ($plf as $p_obj) { foreach ($plf as $p_obj) { $current_permissions[$p_obj->getSection()][$p_obj->getName()] = $p_obj;
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; }
case 'university': //Debug::setVerbosity( 11 ); Debug::Text('Redirect to Online University!', __FILE__, __LINE__, __METHOD__, 10); //Generate encoded data as well. $encoded_data = NULL; if (is_object($current_company) and is_object($current_user)) { //If for some reason the registration key isn't set, generate a random one now. if (isset($system_settings) and (!isset($system_settings['registration_key']) or $system_settings['registration_key'] == '')) { $sslf->setName('registration_key'); $sslf->setValue(md5(uniqid())); if ($sslf->isValid() == TRUE) { $sslf->Save(); } } //Get permissions of current user so we can show them the proper courses. $pf = new PermissionFactory(); $permission_sections = $pf->getOptions('section'); foreach ($permission_sections as $section => $name) { $permission_arr[$section] = $permission->Check($section, 'enabled'); } $encoded_data = array('company_name' => $current_company->getName(), 'product_edition' => $current_company->getProductEdition(), 'version' => $system_settings['system_version'], 'registration_key' => $system_settings['registration_key'], 'first_name' => $current_user->getFirstName(), 'last_name' => $current_user->getLastName(), 'work_email' => $current_user->getWorkEmail(), 'permissions' => $permission_arr); if (function_exists('gzdeflate')) { $encoded_data = urlencode(base64_encode(gzdeflate(serialize($encoded_data)))); } else { $encoded_data = urlencode(base64_encode(serialize($encoded_data))); } //Debug::Text(' Encoded Data ('.strlen($encoded_data).'): '. $encoded_data, __FILE__, __LINE__, __METHOD__,10); } Redirect::Page(URLBuilder::getURL(array('data' => $encoded_data), 'https://www.timetrex.com/university.php')); exit; break;
$help_output = "Usage: set_admin_permissions.php [user_name]\n"; echo $help_output; } else { //Handle command line arguments $last_arg = count($argv) - 1; if (isset($argv[$last_arg]) and $argv[$last_arg] != '') { $user_name = $argv[$last_arg]; //Get user_id from user_name $ulf = new UserListFactory(); $ulf->getByUserName($user_name); if ($ulf->getRecordCount() == 1) { echo "Found user, apply administrator permissions...\n"; ob_flush(); $u_obj = $ulf->getCurrent(); //Create new Permission Group just for this purpose. $pf = new PermissionFactory(); $pf->StartTransaction(); $preset_flags = array(); $preset_options = $pf->getOptions('preset'); $pcf = new PermissionControlFactory(); $pcf->setCompany($u_obj->getCompany()); $pcf->setName('Administrator Fix (' . rand(1, 1000) . ')'); $pcf->setDescription('Created By set_admin_permissions.php'); if ($pcf->isValid()) { $pcf_id = $pcf->Save(FALSE); $pcf->setUser(array($u_obj->getId())); $pcf->Save(); if ($pf->applyPreset($pcf_id, 40, $preset_flags) == TRUE) { echo "Success!\n"; } }
$help_output = "Usage: set_admin_permissions.php [user_name]\n"; echo $help_output; } else { //Handle command line arguments $last_arg = count($argv) - 1; if (isset($argv[$last_arg]) and $argv[$last_arg] != '') { $user_name = $argv[$last_arg]; //Get user_id from user_name $ulf = new UserListFactory(); $ulf->getByUserName($user_name); if ($ulf->getRecordCount() == 1) { echo "Found user, apply administrator permissions...\n"; ob_flush(); $u_obj = $ulf->getCurrent(); //Create new Permission Group just for this purpose. $pf = new PermissionFactory(); $pf->StartTransaction(); //Apply all preset flags, including 0 => "system" $preset_flags = array_merge(array(0), array_keys($pf->getOptions('preset_flags'))); $pcf = new PermissionControlFactory(); $pcf->setCompany($u_obj->getCompany()); $pcf->setLevel(25); $pcf->setName('Administrator Fix (' . rand(1, 1000) . ')'); $pcf->setDescription('Created By set_admin_permissions.php'); if ($pcf->isValid()) { $pcf_id = $pcf->Save(FALSE); $pcf->setUser(array($u_obj->getId())); $pcf->Save(); if ($pf->applyPreset($pcf_id, 40, $preset_flags) == TRUE) { echo "Success!\n"; }