function isUniqueUser($id)
    {
        $hcf = new HierarchyControlFactory();
        $hotf = new HierarchyObjectTypeFactory();
        $ph = array('hierarchy_control_id' => $this->getHierarchyControl(), 'id' => $id);
        //$query = 'select a.id from '. $this->getTable() .' as a, '. $pglf->getTable() .' as b where a.hierarchy_control_id = b.id AND a.user_id = ? AND b.deleted=0';
        $query = '
					select *
					from ' . $hotf->getTable() . ' as a
					LEFT JOIN ' . $this->getTable() . ' as b ON a.hierarchy_control_id = b.hierarchy_control_id
					LEFT JOIN ' . $hcf->getTable() . ' as c ON a.hierarchy_control_id = c.id
					WHERE a.object_type_id in (
							select object_type_id
							from hierarchy_object_type
							where hierarchy_control_id = ? )
					AND b.user_id = ?
					AND c.deleted = 0
				';
        $user_id = $this->db->GetOne($query, $ph);
        //Debug::Arr($user_id,'Unique User ID: '. $user_id, __FILE__, __LINE__, __METHOD__,10);
        if ($user_id === FALSE) {
            return TRUE;
        }
        return FALSE;
    }
    function getHierarchyChildrenByCompanyIdAndUserIdAndObjectTypeID($company_id, $user_id, $object_type_id = 100)
    {
        global $profiler;
        $profiler->startTimer("getPermissionHierarchyChildrenByCompanyIdAndUserId");
        if ($company_id == '') {
            return FALSE;
        }
        if ($user_id == '') {
            return FALSE;
        }
        if ($object_type_id == '') {
            return FALSE;
        }
        $retval = FALSE;
        $uf = new UserFactory();
        $hlf = new HierarchyLevelFactory();
        $huf = new HierarchyUserFactory();
        $hotf = new HierarchyObjectTypeFactory();
        $hcf = new HierarchyControlFactory();
        //When it comes to permissions we only consider subordinates, not other supervisors/managers in the hierarchy.
        $ph = array('user_id' => $user_id, 'company_id' => $company_id);
        //w.user_id != x.user_id, is there to make sure we exclude the current user from the subordinate list,
        //as we now allow superiors to also be subordinates in the same hierarchy.
        $query = '
						select w.user_id as user_id
						from ' . $huf->getTable() . ' as w
						LEFT JOIN ' . $hlf->getTable() . ' as x ON w.hierarchy_control_id = x.hierarchy_control_id
						LEFT JOIN ' . $hotf->getTable() . ' as y ON w.hierarchy_control_id = y.hierarchy_control_id
						LEFT JOIN ' . $uf->getTable() . ' as z ON x.user_id = z.id
						LEFT JOIN ' . $hcf->getTable() . ' as z2 ON w.hierarchy_control_id = z2.id
						WHERE
							x.user_id = ?
							AND z.company_id = ?
							AND y.object_type_id in (' . $this->getListSQL($object_type_id, $ph) . ')
							AND w.user_id != x.user_id
							AND ( x.deleted = 0 AND z2.deleted = 0 AND z.deleted = 0 )
					';
        //Debug::Text(' Query: '. $query, __FILE__, __LINE__, __METHOD__,10);
        $rs = $this->db->Execute($query, $ph);
        //Debug::Text(' Rows: '. $rs->RecordCount(), __FILE__, __LINE__, __METHOD__,10);
        if ($rs->RecordCount() > 0) {
            foreach ($rs as $row) {
                $retval[] = $row['user_id'];
            }
        }
        $profiler->stopTimer("getPermissionHierarchyChildrenByCompanyIdAndUserId");
        return $retval;
    }
 function createAuthorizationHierarchyControl($company_id, $child_user_ids)
 {
     $hcf = new HierarchyControlFactory();
     $hcf->setCompany($company_id);
     $hcf->setObjectType(array(50));
     $hcf->setName('Request');
     $hcf->setDescription('Request Hierarchy');
     if ($hcf->isValid()) {
         $insert_id = $hcf->Save(FALSE);
         Debug::Text('Hierarchy Control ID: ' . $insert_id, __FILE__, __LINE__, __METHOD__, 10);
         $hcf->setUser($child_user_ids);
         return $insert_id;
     }
     Debug::Text('Failed Creating Hierarchy Control!', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }
    function getByCompanyId($id, $limit = NULL, $page = NULL, $where = NULL, $order = NULL)
    {
        if ($id == '') {
            return FALSE;
        }
        $strict_order = TRUE;
        if ($order == NULL) {
            //$order = array('b.last_name' => 'asc');
            $strict_order = FALSE;
        }
        $hcf = new HierarchyControlFactory();
        $ph = array('id' => $id);
        $query = '
					select 	*
					from	' . $this->getTable() . ' as a,
							' . $hcf->getTable() . ' as b

					where	a.hierarchy_control_id = b.id
						AND b.company_id = ?
						AND b.deleted = 0
				';
        $query .= $this->getWhereSQL($where);
        $query .= $this->getSortSQL($order, $strict_order);
        if ($limit == NULL) {
            //Run query without limit
            $this->rs = $this->db->Execute($query, $ph);
        } else {
            $this->rs = $this->db->PageExecute($query, $limit, $page, $ph);
        }
        return $this;
    }
Example #5
0
    static function getPermissionHierarchySQL($company_id, $user_id, $outer_column)
    {
        $hlf = new HierarchyLevelFactory();
        $huf = new HierarchyUserFactory();
        $hotf = new HierarchyObjectTypeFactory();
        $hcf = new HierarchyControlFactory();
        $query = '
						LEFT JOIN (
							select phc_huf.user_id as user_id, 1 as is_child
							from ' . $huf->getTable() . ' as phc_huf
							LEFT JOIN ' . $hlf->getTable() . ' as phc_hlf ON phc_huf.hierarchy_control_id = phc_hlf.hierarchy_control_id
							LEFT JOIN ' . $hotf->getTable() . ' as phc_hotf ON phc_huf.hierarchy_control_id = phc_hotf.hierarchy_control_id
							LEFT JOIN ' . $hcf->getTable() . ' as phc_hcf ON phc_huf.hierarchy_control_id = phc_hcf.id
							WHERE
								phc_hlf.user_id = ' . (int) $user_id . '
								AND phc_hcf.company_id = ' . (int) $company_id . '
								AND phc_hotf.object_type_id = 100
								AND phc_huf.user_id != phc_hlf.user_id
								AND ( phc_hlf.deleted = 0 AND phc_hcf.deleted = 0 )
						) as phc ON ' . $outer_column . ' = phc.user_id
					';
        return $query;
    }
    function getHierarchyChildrenByCompanyIdAndUserIdAndObjectTypeID($company_id, $user_id, $object_type_id = 100)
    {
        global $profiler;
        $profiler->startTimer("getPermissionHierarchyChildrenByCompanyIdAndUserId");
        if ($company_id == '') {
            return FALSE;
        }
        if ($user_id == '') {
            return FALSE;
        }
        if ($object_type_id == '') {
            return FALSE;
        }
        $retval = FALSE;
        $uf = new UserFactory();
        $hlf = new HierarchyLevelFactory();
        $huf = new HierarchyUserFactory();
        $hotf = new HierarchyObjectTypeFactory();
        $hcf = new HierarchyControlFactory();
        //When it comes to permissions we only consider subordinates, not other supervisors/managers in the hierarchy.
        $ph = array('user_id' => $user_id, 'object_type_id' => $object_type_id, 'company_id' => $company_id);
        $query = '
						select w.user_id as user_id
						from ' . $huf->getTable() . ' as w
						LEFT JOIN ' . $hlf->getTable() . ' as x ON w.hierarchy_control_id = x.hierarchy_control_id
						LEFT JOIN ' . $hotf->getTable() . ' as y ON w.hierarchy_control_id = y.hierarchy_control_id
						LEFT JOIN ' . $uf->getTable() . ' as z ON x.user_id = z.id
						LEFT JOIN ' . $hcf->getTable() . ' as z2 ON w.hierarchy_control_id = z2.id
						WHERE
							x.user_id = ?
							AND y.object_type_id = ?
							AND z.company_id = ?
							AND z2.deleted = 0
					';
        /*
        		$query = '
        						select a.user_id as user_id
        						from '. $hlf->getTable() .' as a
        						LEFT JOIN '. $hlf->getTable() .' as b ON a.hierarchy_control_id = b.hierarchy_control_id AND b.user_id = ?
        						LEFT JOIN '. $hotf->getTable() .' as c ON a.hierarchy_control_id = c.hierarchy_control_id AND c.object_type_id = ?
        						LEFT JOIN '. $uf->getTable() .' as d ON a.user_id = d.id AND d.company_id = ?
        						LEFT JOIN '. $hcf->getTable() .' as e ON a.hierarchy_control_id = e.id
        						WHERE a.level > b.level
        							AND a.deleted = 0
        							AND b.deleted = 0
        							AND e.deleted = 0
        
        						UNION ALL
        
        						select w.user_id as user_id
        						from '. $huf->getTable() .' as w
        						LEFT JOIN '. $hlf->getTable() .' as x ON w.hierarchy_control_id = x.hierarchy_control_id
        						LEFT JOIN '. $hotf->getTable() .' as y ON w.hierarchy_control_id = y.hierarchy_control_id
        						LEFT JOIN '. $uf->getTable() .' as z ON x.user_id = z.id
        						LEFT JOIN '. $hcf->getTable() .' as z2 ON w.hierarchy_control_id = z2.id
        						WHERE
        							x.user_id = ?
        							AND y.object_type_id = ?
        							AND z.company_id = ?
        							AND z2.deleted = 0
        					';
        */
        //Debug::Text(' Query: '. $query, __FILE__, __LINE__, __METHOD__,10);
        $rs = $this->db->Execute($query, $ph);
        //Debug::Text(' Rows: '. $rs->RecordCount(), __FILE__, __LINE__, __METHOD__,10);
        if ($rs->RecordCount() > 0) {
            foreach ($rs as $row) {
                $retval[] = $row['user_id'];
            }
        }
        $profiler->stopTimer("getPermissionHierarchyChildrenByCompanyIdAndUserId");
        return $retval;
    }
    function getLevelsByUserIdAndObjectTypeID($user_id, $object_type_id = 50)
    {
        //Requests
        if ($user_id == '') {
            return FALSE;
        }
        if ($object_type_id == '') {
            return FALSE;
        }
        $uf = new UserFactory();
        $hotf = new HierarchyObjectTypeFactory();
        $hcf = new HierarchyControlFactory();
        $ph = array('user_id' => $user_id);
        $query = '
				select 	distinct (x.level) as level
				from	' . $this->getTable() . ' as x,
						' . $hcf->getTable() . ' as y,
					(
								select 	a.hierarchy_control_id,a.level
								from	' . $this->getTable() . ' as a
									LEFT JOIN ' . $hotf->getTable() . ' as b ON a.hierarchy_control_id = b.hierarchy_control_id
								where a.user_id = ?
									AND b.object_type_id in (' . $this->getListSQL($object_type_id, $ph) . ')
									AND a.deleted = 0
					) as z
				where
					x.hierarchy_control_id = y.id
					AND x.hierarchy_control_id = z.hierarchy_control_id
					AND x.level >= z.level
					AND ( x.deleted = 0 AND y.deleted = 0 )
				ORDER BY x.level asc
				';
        $rs = $this->db->Execute($query, $ph);
        //Debug::Text(' Rows: '. $rs->RecordCount(), __FILE__, __LINE__, __METHOD__,10);
        if ($rs->RecordCount() > 0) {
            //The retarr key is the value that will be displayed to the user when switching levels on the authorization page,
            //so we need to start that from 1 and increasing sequentially, regardless of what the actual hierarchy level is.
            $i = 1;
            foreach ($rs as $row) {
                $retarr[$i] = $row['level'];
                $i++;
            }
            return $retarr;
        }
        return FALSE;
    }
    function getAPISearchByCompanyIdAndArrayCriteria($company_id, $filter_data, $limit = NULL, $page = NULL, $where = NULL, $order = NULL)
    {
        if ($company_id == '') {
            return FALSE;
        }
        if (!is_array($order)) {
            //Use Filter Data ordering if its set.
            if (isset($filter_data['sort_column']) and $filter_data['sort_order']) {
                $order = array(Misc::trimSortPrefix($filter_data['sort_column']) => $filter_data['sort_order']);
            }
        }
        $additional_order_fields = array();
        $sort_column_aliases = array();
        $order = $this->getColumnsFromAliases($order, $sort_column_aliases);
        if ($order == NULL) {
            $order = array('level' => 'asc');
            $strict = FALSE;
        } else {
            //Always sort by last name,first name after other columns
            if (!isset($order['level'])) {
                $order['level'] = 'asc';
            }
            $strict = TRUE;
        }
        //Debug::Arr($order,'Order Data:', __FILE__, __LINE__, __METHOD__,10);
        //Debug::Arr($filter_data,'Filter Data:', __FILE__, __LINE__, __METHOD__,10);
        $uf = new UserFactory();
        $hcf = new HierarchyControlFactory();
        $ph = array('company_id' => $company_id);
        $query = '
					select 	a.*,
							y.first_name as created_by_first_name,
							y.middle_name as created_by_middle_name,
							y.last_name as created_by_last_name,
							z.first_name as updated_by_first_name,
							z.middle_name as updated_by_middle_name,
							z.last_name as updated_by_last_name
					from 	' . $this->getTable() . ' as a
						LEFT JOIN ' . $hcf->getTable() . ' as b ON ( a.hierarchy_control_id = b.id AND b.deleted = 0 )
						LEFT JOIN ' . $uf->getTable() . ' as y ON ( a.created_by = y.id AND y.deleted = 0 )
						LEFT JOIN ' . $uf->getTable() . ' as z ON ( a.updated_by = z.id AND z.deleted = 0 )
					where	b.company_id = ?
					';
        if (isset($filter_data['permission_children_ids']) and isset($filter_data['permission_children_ids'][0]) and !in_array(-1, (array) $filter_data['permission_children_ids'])) {
            $query .= ' AND a.created_by in (' . $this->getListSQL($filter_data['permission_children_ids'], $ph) . ') ';
        }
        if (isset($filter_data['id']) and isset($filter_data['id'][0]) and !in_array(-1, (array) $filter_data['id'])) {
            $query .= ' AND a.id in (' . $this->getListSQL($filter_data['id'], $ph) . ') ';
        }
        if (isset($filter_data['hierarchy_control_id']) and isset($filter_data['hierarchy_control_id'][0]) and !in_array(-1, (array) $filter_data['hierarchy_control_id'])) {
            $query .= ' AND a.hierarchy_control_id in (' . $this->getListSQL($filter_data['hierarchy_control_id'], $ph) . ') ';
        }
        $query .= isset($filter_data['created_by']) ? $this->getWhereClauseSQL(array('a.created_by', 'y.first_name', 'y.last_name'), $filter_data['created_by'], 'user_id_or_name', $ph) : NULL;
        $query .= isset($filter_data['updated_by']) ? $this->getWhereClauseSQL(array('a.updated_by', 'z.first_name', 'z.last_name'), $filter_data['updated_by'], 'user_id_or_name', $ph) : NULL;
        $query .= '
						AND a.deleted = 0
					';
        $query .= $this->getWhereSQL($where);
        $query .= $this->getSortSQL($order, $strict, $additional_order_fields);
        $this->ExecuteSQL($query, $ph, $limit, $page);
        return $this;
    }
    function getByHierarchyControlAndUserId($id, $user_id, $where = NULL, $order = NULL)
    {
        if ($id == '') {
            return FALSE;
        }
        if ($user_id == '') {
            return FALSE;
        }
        $hcf = new HierarchyControlFactory();
        $ph = array('id' => $id, 'user_id' => $user_id);
        $query = '
					select 	a.*
					from	' . $this->getTable() . ' as a,
							' . $hcf->getTable() . ' as b
					where	b.id = a.hierarchy_control_id
						AND a.hierarchy_control_id = ?
						AND a.user_id = ?
						AND b.deleted = 0
					';
        $query .= $this->getWhereSQL($where);
        $query .= $this->getSortSQL($order);
        $this->rs = $this->db->Execute($query, $ph);
        return $this;
    }
 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;
 }
 * $Date: 2009-07-07 14:26:01 -0700 (Tue, 07 Jul 2009) $
 */
require_once '../../includes/global.inc.php';
require_once Environment::getBasePath() . 'includes/Interface.inc.php';
if (!$permission->Check('hierarchy', 'enabled') or !($permission->Check('hierarchy', 'edit') or $permission->Check('hierarchy', 'edit_own'))) {
    $permission->Redirect(FALSE);
    //Redirect
}
//Debug::setVerbosity(11);
$smarty->assign('title', TTi18n::gettext($title = 'Edit Hierarchy List'));
// See index.php
/*
 * Get FORM variables
 */
extract(FormVariables::GetVariables(array('action', 'ids', 'hierarchy_control_id', 'hierarchy_control_data', 'hierarchy_level_data')));
$hcf = new HierarchyControlFactory();
$hlf = new HierarchyLevelFactory();
$action = Misc::findSubmitButton();
switch ($action) {
    case 'submit':
        //Debug::setVerbosity(11);
        Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10);
        $redirect = 0;
        $hcf->StartTransaction();
        $hcf->setId($hierarchy_control_data['id']);
        $hcf->setCompany($current_company->getId());
        if (isset($hierarchy_control_data['object_type_ids'])) {
            $hcf->setObjectType($hierarchy_control_data['object_type_ids']);
        } else {
            $hcf->setObjectType(FALSE);
        }