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 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 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; }
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; } } } //print_r($current_permissions); } $section_groups = Misc::prependArray(array(-1 => TTi18n::gettext('-- None --')), $pf->getOptions('section_group')); $section_group_map = $pf->getOptions('section_group_map'); $sections = $pf->getOptions('section'); $names = $pf->getOptions('name'); //Trim out ignored sections foreach ($section_groups as $section_group_key => $section_group_value) { if ($pf->isIgnore($section_group_key, NULL, $current_company->getProductEdition()) == TRUE) { unset($section_groups[$section_group_key]); } } unset($section_group_key, $section_group_value); if (!isset($group_id) or !isset($section_groups[$group_id])) { $group_id = 0; //None //$group_id = 'all'; //None }
//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; case 'check_for_updates':
//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"; } } //$pf->FailTransaction(); $pf->CommitTransaction(); } elseif ($ulf->getRecordCount() > 2) {
//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"; } } //$pf->FailTransaction(); $pf->CommitTransaction();