function setHierarchyControl($id)
 {
     $id = trim($id);
     $hclf = new HierarchyControlListFactory();
     if ($this->Validator->isResultSetWithRows('hierarchy_control_id', $hclf->getByID($id), TTi18n::gettext('Invalid Hierarchy Control'))) {
         $this->data['hierarchy_control_id'] = $id;
         return TRUE;
     }
     return FALSE;
 }
 function getByCompanyIdAndHierarchyControlId($company_id, $tree_id)
 {
     if ($company_id == '') {
         return FALSE;
     }
     if ($tree_id == '') {
         return FALSE;
     }
     $hclf = new HierarchyControlListFactory();
     $hclf->getByIdAndCompanyId($tree_id, $company_id);
     if ($hclf->getRecordCount() == 0) {
         return FALSE;
     }
     return $this->getByHierarchyControlId($tree_id);
 }
     } else {
         $delete = FALSE;
     }
     $hclf = new HierarchyControlListFactory();
     foreach ($ids as $id) {
         //$dsclf->GetByIdAndUserId($id, $current_user->getId() );
         $hclf->GetById($id);
         foreach ($hclf as $hierarchy_control) {
             $hierarchy_control->setDeleted($delete);
             $hierarchy_control->Save();
         }
     }
     Redirect::Page(URLBuilder::getURL(NULL, 'HierarchyControlList.php'));
     break;
 default:
     $hclf = new HierarchyControlListFactory();
     $hclf->GetByCompanyId($current_company->getId(), $current_user_prefs->getItemsPerPage(), $page, NULL, $sort_array);
     $pager = new Pager($hclf);
     $hotf = new HierarchyObjectTypeFactory();
     $object_type_options = $hotf->getOptions('object_type');
     foreach ($hclf as $hierarchy_control) {
         $object_type_ids = $hierarchy_control->getObjectType();
         $object_types = array();
         foreach ($object_type_ids as $object_type_id) {
             if (isset($object_type_options[$object_type_id])) {
                 $object_types[] = $object_type_options[$object_type_id];
             }
         }
         $hierarchy_controls[] = array('id' => $hierarchy_control->getId(), 'name' => $hierarchy_control->getName(), 'description' => $hierarchy_control->getDescription(), 'object_types' => $object_types, 'deleted' => $hierarchy_control->getDeleted());
         unset($object_types);
     }
Exemple #4
0
     if (!isset($user_data['hire_date']) or $user_data['hire_date'] == '') {
         $user_data['hire_date'] = time();
     }
 }
 //var_dump($user_data);
 //Select box options;
 $blf = new BranchListFactory();
 $branch_options = $blf->getByCompanyIdArray($company_id);
 $dlf = new DepartmentListFactory();
 $department_options = $dlf->getByCompanyIdArray($company_id);
 $culf = new CurrencyListFactory();
 $culf->getByCompanyId($company_id);
 $currency_options = $culf->getArrayByListFactory($culf, FALSE, TRUE);
 $hotf = new HierarchyObjectTypeFactory();
 $hierarchy_object_type_options = $hotf->getOptions('object_type');
 $hclf = new HierarchyControlListFactory();
 $hclf->getObjectTypeAppendedListByCompanyID($company_id);
 $hierarchy_control_options = $hclf->getArrayByListFactory($hclf, TRUE, TRUE);
 //Select box options;
 $user_data['branch_options'] = $branch_options;
 $user_data['department_options'] = $department_options;
 $user_data['currency_options'] = $currency_options;
 $user_data['sex_options'] = $uf->getOptions('sex');
 $user_data['status_options'] = $uf->getOptions('status');
 $clf = new CompanyListFactory();
 $user_data['country_options'] = $clf->getOptions('country');
 $user_data['province_options'] = $clf->getOptions('province', $user_data['country']);
 $utlf = new UserTitleListFactory();
 $user_titles = $utlf->getByCompanyIdArray($company_id);
 $user_data['title_options'] = $user_titles;
 //Get Permission Groups
 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;
 }
 function postInstall()
 {
     Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     //Go through all pay period schedules and update the annual pay period column
     $ppslf = new PayPeriodScheduleListFactory();
     $ppslf->getAll();
     if ($ppslf->getRecordCount() > 0) {
         foreach ($ppslf as $pps_obj) {
             $pps_obj->setAnnualPayPeriods($pps_obj->calcAnnualPayPeriods());
             if ($pps_obj->isValid()) {
                 $pps_obj->Save();
             }
         }
     }
     //Go through all employee wages and update HourlyRate to the accurate annual hourly rate.
     //**Handle this in 1034A postInstall() instead, as it needs to handle incorrect effective_dates properly.
     /*
     $uwlf = new UserWageListFactory();
     $uwlf->getAll();
     if ( $uwlf->getRecordCount() > 0 ) {
     	foreach( $uwlf as $uw_obj ) {
     		$uw_obj->setHourlyRate( $uw_obj->calcHourlyRate( time(), TRUE ) );
     		if ( $uw_obj->isValid() ) {
     			$uw_obj->Save();
     		}
     	}
     }
     */
     //Upgrade to new hierarchy format.
     $clf = new CompanyListFactory();
     $clf->getAll();
     if ($clf->getRecordCount() > 0) {
         foreach ($clf as $c_obj) {
             if ($c_obj->getStatus() != 30) {
                 /*
                 					if ( !($c_obj->getId() == 1052) ) { //$c_obj->getId() == 1009 OR $c_obj->getId() == 1087 OR
                 						continue;
                 					}
                 */
                 $company_id = $c_obj->getId();
                 Debug::Text(' Company ID: ' . $company_id, __FILE__, __LINE__, __METHOD__, 10);
                 $hclf = new HierarchyControlListFactory();
                 $hclf->StartTransaction();
                 $hclf->getByCompanyId($company_id);
                 if ($hclf->getRecordCount() > 0) {
                     foreach ($hclf as $hc_obj) {
                         $paths_to_root = array();
                         $hierarchy_id = $hc_obj->getId();
                         $hlf = new HierarchyListFactory();
                         $hierarchy_users = $hlf->getByCompanyIdAndHierarchyControlId($company_id, $hierarchy_id);
                         if (is_array($hierarchy_users) and count($hierarchy_users) > 0) {
                             $hotlf = new HierarchyObjectTypeListFactory();
                             $hotlf->getByHierarchyControlId($hierarchy_id);
                             if ($hotlf->getRecordCount() > 0) {
                                 foreach ($hotlf as $hot_obj) {
                                     $object_types[$hierarchy_id][] = $hot_obj->getObjectType();
                                 }
                             }
                             foreach ($hierarchy_users as $hierarchy_user_arr) {
                                 Debug::Text(' Checking User ID: ' . $hierarchy_user_arr['id'], __FILE__, __LINE__, __METHOD__, 10);
                                 $id = $hierarchy_user_arr['id'];
                                 $tmp_id = $id;
                                 $i = 0;
                                 do {
                                     Debug::Text(' Iteration...', __FILE__, __LINE__, __METHOD__, 10);
                                     $hlf_b = new HierarchyListFactory();
                                     $parents = $hlf_b->getParentLevelIdArrayByHierarchyControlIdAndUserId($hierarchy_id, $tmp_id);
                                     sort($parents);
                                     $level = $hlf_b->getFastTreeObject()->getLevel($tmp_id) - 1;
                                     if (is_array($parents) and count($parents) > 0) {
                                         $parent_users = array();
                                         foreach ($parents as $user_id) {
                                             $parent_users[] = $user_id;
                                             unset($user);
                                         }
                                         $parent_groups[$level] = $parent_users;
                                         unset($parent_users);
                                     }
                                     if (isset($parents[0])) {
                                         $tmp_id = $parents[0];
                                     }
                                     $i++;
                                 } while (is_array($parents) and count($parents) > 0 and $i < 100);
                                 if (isset($parent_groups)) {
                                     $serialized_path = serialize($parent_groups);
                                     $paths_to_root[$serialized_path][] = $id;
                                     unset($serialized_path);
                                 }
                                 unset($parent_groups, $parents);
                             }
                         }
                         Debug::Arr($paths_to_root, ' Paths To Root: ', __FILE__, __LINE__, __METHOD__, 10);
                         //Decode path_to_root array
                         if (isset($paths_to_root) and count($paths_to_root) > 0) {
                             foreach ($paths_to_root as $serialized_path => $children) {
                                 $path_arr = unserialize($serialized_path);
                                 $decoded_paths[] = array('hierarchy_control_id' => $hierarchy_id, 'path' => $path_arr, 'children' => $children);
                             }
                             unset($path_arr, $children);
                             Debug::Arr($decoded_paths, ' Decoded Paths: ', __FILE__, __LINE__, __METHOD__, 10);
                             if (isset($decoded_paths) and is_array($decoded_paths)) {
                                 foreach ($decoded_paths as $decoded_path) {
                                     Debug::Text(' Company ID: ' . $company_id, __FILE__, __LINE__, __METHOD__, 10);
                                     //Create new hierarchy_control
                                     $hcf = new HierarchyControlFactory();
                                     $hcf->setCompany($company_id);
                                     $hcf->setObjectType($object_types[$decoded_path['hierarchy_control_id']]);
                                     //Generate meaningful name
                                     $name = FALSE;
                                     if (isset($decoded_path['path']) and is_array($decoded_path['path'])) {
                                         ksort($decoded_path['path']);
                                         //Sort by level.
                                         foreach ($decoded_path['path'] as $level => $superior_ids) {
                                             foreach ($superior_ids as $superior_id) {
                                                 $ulf = new UserListFactory();
                                                 $ulf->getById($superior_id);
                                                 if ($ulf->getRecordCount() > 0) {
                                                     $name[] = $level . '. ' . $ulf->getCurrent()->getFullName();
                                                 }
                                             }
                                         }
                                         unset($level, $superior_ids, $superior_id);
                                     }
                                     if (isset($name)) {
                                         $name = $hc_obj->getName() . ' ' . implode(', ', $name) . ' (#' . rand(1000, 9999) . ')';
                                     } else {
                                         $name = $hc_obj->getName() . ' (#' . rand(1000, 9999) . ')';
                                     }
                                     $hcf->setName(substr($name, 0, 249));
                                     $hcf->setDescription(TTi18n::getText('Automatically created by TimeTrex'));
                                     if ($hcf->isValid()) {
                                         $hc_id = $hcf->Save(FALSE);
                                         Debug::Text('Hierarchy Control ID: ' . $hc_id, __FILE__, __LINE__, __METHOD__, 10);
                                         $hcf->setUser($decoded_path['children']);
                                         if (isset($decoded_path['path']) and is_array($decoded_path['path'])) {
                                             foreach ($decoded_path['path'] as $level => $superior_ids) {
                                                 foreach ($superior_ids as $superior_id) {
                                                     $hlf = new HierarchyLevelFactory();
                                                     $hlf->setHierarchyControl($hc_id);
                                                     $hlf->setLevel($level);
                                                     $hlf->setUser($superior_id);
                                                     if ($hlf->isValid()) {
                                                         $hlf->Save();
                                                         Debug::Text('Saving Level Row ID... User ID: ' . $superior_id, __FILE__, __LINE__, __METHOD__, 10);
                                                     }
                                                 }
                                             }
                                             unset($level, $superior_ids, $superior_id);
                                         }
                                     }
                                 }
                             }
                             unset($decoded_paths);
                         }
                         //Delete existing hierarchy control.
                         $hc_obj->setDeleted(TRUE);
                         if ($hc_obj->isValid() == TRUE) {
                             $hc_obj->Save();
                         }
                     }
                 }
                 //$hclf->FailTransaction();
                 $hclf->CommitTransaction();
             }
         }
     }
     //Go through each permission group, and enable break policies for anyone who can see meal policies
     $clf = new CompanyListFactory();
     $clf->getAll();
     if ($clf->getRecordCount() > 0) {
         foreach ($clf as $c_obj) {
             Debug::text('Company: ' . $c_obj->getName(), __FILE__, __LINE__, __METHOD__, 9);
             if ($c_obj->getStatus() != 30) {
                 $pclf = new PermissionControlListFactory();
                 $pclf->getByCompanyId($c_obj->getId());
                 if ($pclf->getRecordCount() > 0) {
                     foreach ($pclf as $pc_obj) {
                         Debug::text('Permission Group: ' . $pc_obj->getName(), __FILE__, __LINE__, __METHOD__, 9);
                         $plf = new PermissionListFactory();
                         $plf->getByCompanyIdAndPermissionControlIdAndSectionAndName($c_obj->getId(), $pc_obj->getId(), 'meal_policy', 'enabled');
                         if ($plf->getRecordCount() > 0) {
                             Debug::text('Found permission group with meal policy enabled: ' . $plf->getCurrent()->getValue(), __FILE__, __LINE__, __METHOD__, 9);
                             $pc_obj->setPermission(array('break_policy' => array('enabled' => TRUE, 'view' => TRUE, 'add' => TRUE, 'edit' => TRUE, 'delete' => TRUE)));
                         } else {
                             Debug::text('Permission group does NOT have meal policy enabled...', __FILE__, __LINE__, __METHOD__, 9);
                         }
                     }
                 }
             }
         }
     }
     //Add MiscDaily cronjob to database.
     $cjf = new CronJobFactory();
     $cjf->setName('MiscDaily');
     $cjf->setMinute(55);
     $cjf->setHour(1);
     $cjf->setDayOfMonth('*');
     $cjf->setMonth('*');
     $cjf->setDayOfWeek('*');
     $cjf->setCommand('MiscDaily.php');
     $cjf->Save();
     //Add MiscWeekly cronjob to database.
     $cjf = new CronJobFactory();
     $cjf->setName('MiscWeekly');
     $cjf->setMinute(55);
     $cjf->setHour(1);
     $cjf->setDayOfMonth('*');
     $cjf->setMonth('*');
     $cjf->setDayOfWeek('0');
     //Sunday morning.
     $cjf->setCommand('MiscWeekly.php');
     $cjf->Save();
     return TRUE;
 }
                     foreach ($hllf as $hl_obj) {
                         $hl_obj->setDeleted(TRUE);
                         if ($hl_obj->isValid()) {
                             $hl_obj->Save();
                         }
                     }
                 }
             }
             unset($hierarchy_level_data[$hl_id]);
         }
         unset($hl_id);
     }
 default:
     if (isset($hierarchy_control_id)) {
         BreadCrumb::setCrumb($title);
         $hclf = new HierarchyControlListFactory();
         $hclf->getByIdAndCompanyId($hierarchy_control_id, $current_company->getId());
         foreach ($hclf as $hierarchy_control) {
             $hierarchy_control_data = array('id' => $hierarchy_control->getId(), 'name' => $hierarchy_control->getName(), 'description' => $hierarchy_control->getDescription(), 'object_type_ids' => $hierarchy_control->getObjectType(), 'user_ids' => $hierarchy_control->getUser(), 'created_date' => $hierarchy_control->getCreatedDate(), 'created_by' => $hierarchy_control->getCreatedBy(), 'updated_date' => $hierarchy_control->getUpdatedDate(), 'updated_by' => $hierarchy_control->getUpdatedBy(), 'deleted_date' => $hierarchy_control->getDeletedDate(), 'deleted_by' => $hierarchy_control->getDeletedBy());
         }
         $hllf = new HierarchyLevelListFactory();
         $hllf->getByHierarchyControlId($hierarchy_control_id);
         if ($hllf->getRecordCount() > 0) {
             foreach ($hllf as $hl_obj) {
                 $hierarchy_level_data[] = array('id' => $hl_obj->getId(), 'level' => $hl_obj->getLevel(), 'user_id' => $hl_obj->getUser());
             }
         } else {
             $hierarchy_level_data[-1] = array('id' => -1, 'level' => 1);
         }
     } elseif ($action == 'add_level') {
         Debug::Text('Adding Blank Level', __FILE__, __LINE__, __METHOD__, 10);