/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */
function smarty_function_EmbeddedAuthorizationList($params, &$smarty)
{
    global $current_company, $current_user;
    $object_type_id = $params['object_type_id'];
    $object_id = $params['object_id'];
    $ulf = new UserListFactory();
    $hlf = new HierarchyListFactory();
    $hotlf = new HierarchyObjectTypeListFactory();
    $alf = new AuthorizationListFactory();
    $alf->setObjectType($object_type_id);
    //$authorizing_obj = $alf->getObjectHandler()->getById( $object_id )->getCurrent();
    $tmp_authorizing_obj = $alf->getObjectHandler()->getById($object_id);
    if (is_object($tmp_authorizing_obj)) {
        $authorizing_obj = $tmp_authorizing_obj->getCurrent();
    } else {
        return FALSE;
    }
    //var_dump($authorizing_obj);
    unset($alf);
    $user_id = $authorizing_obj->getUserObject()->getId();
    $alf = new AuthorizationListFactory();
    $alf->getByObjectTypeAndObjectId($object_type_id, $object_id);
    foreach ($alf as $authorization_obj) {
        $authorization_data[] = array('id' => $authorization_obj->getId(), 'created_by_full_name' => $ulf->getById($authorization_obj->getCreatedBy())->getCurrent()->getFullName(), 'authorized' => $authorization_obj->getAuthorized(), 'created_date' => $authorization_obj->getCreatedDate(), 'created_by' => $authorization_obj->getCreatedBy(), 'updated_date' => $authorization_obj->getUpdatedDate(), 'updated_by' => $authorization_obj->getUpdatedBy(), 'deleted_date' => $authorization_obj->getDeletedDate(), 'deleted_by' => $authorization_obj->getDeletedBy());
        $user_id = $authorization_obj->getCreatedBy();
    }
    if ($authorizing_obj->getStatus() == 30) {
        //If the object is still pending authorization, display who its waiting on...
        $hierarchy_id = $hotlf->getByCompanyIdAndObjectTypeId($current_company->getId(), $object_type_id)->getCurrent()->getHierarchyControl();
        Debug::Text('Hierarchy ID: ' . $hierarchy_id, __FILE__, __LINE__, __METHOD__, 10);
        //Get Parents
        $parent_level_user_ids = $hlf->getParentLevelIdArrayByHierarchyControlIdAndUserId($hierarchy_id, $user_id);
        Debug::Arr($parent_level_user_ids, 'Parent Level Ids', __FILE__, __LINE__, __METHOD__, 10);
        if ($parent_level_user_ids !== FALSE and count($parent_level_user_ids) > 0) {
            Debug::Text('Adding Pending Line: ', __FILE__, __LINE__, __METHOD__, 10);
            foreach ($parent_level_user_ids as $parent_user_id) {
                $created_by_full_name[] = $ulf->getById($parent_user_id)->getCurrent()->getFullName();
            }
            $authorization_data[] = array('id' => NULL, 'created_by_full_name' => implode('<br>', $created_by_full_name), 'authorized' => NULL, 'created_date' => NULL, 'created_by' => NULL);
        }
    }
    $smarty->assign_by_ref('authorization_data', $authorization_data);
    $smarty->display('authorization/EmbeddedAuthorizationList.tpl');
}
foreach ($ulf as $user) {
    //Check authorize permissions for eact object type.
    if ($permission->Check('default_schedule', 'authorize', $user->getId(), $user->getCompany())) {
        //Get Hierarchy Control ID
        $default_schedule_hierarchy_id = $hotlf->getByCompanyIdAndObjectTypeId($user->getCompany(), 10)->getCurrent()->getHierarchyControl();
        Debug::Text('Default Schedule Hierarchy ID: ' . $default_schedule_hierarchy_id, __FILE__, __LINE__, __METHOD__, 10);
        //Get all levels below us.
        $default_schedule_levels = $hlf->getLevelsByHierarchyControlIdAndUserId($default_schedule_hierarchy_id, $user->getId());
        Debug::Arr($default_schedule_levels, 'Default Schedule Levels', __FILE__, __LINE__, __METHOD__, 10);
        $default_schedule_user_id = $user->getId();
        $default_schedule_node_data = $hlf->getByHierarchyControlIdAndUserId($default_schedule_hierarchy_id, $default_schedule_user_id);
        //Get current level IDs
        $default_schedule_current_level_user_ids = $hlf->getCurrentLevelIdArrayByHierarchyControlIdAndUserId($default_schedule_hierarchy_id, $default_schedule_user_id);
        Debug::Arr($default_schedule_current_level_user_ids, 'Default Schedule Current Level Ids', __FILE__, __LINE__, __METHOD__, 10);
        //Get Parents
        $default_schedule_parent_level_user_ids = $hlf->getParentLevelIdArrayByHierarchyControlIdAndUserId($default_schedule_hierarchy_id, $default_schedule_user_id);
        Debug::Arr($default_schedule_parent_level_user_ids, 'Default Schedule Parent Level Ids', __FILE__, __LINE__, __METHOD__, 10);
        //Get Children
        $default_schedule_child_level_user_ids = $hlf->getChildLevelIdArrayByHierarchyControlIdAndUserId($default_schedule_hierarchy_id, $default_schedule_user_id);
        Debug::Arr($default_schedule_child_level_user_ids, 'Default Schedule Child Level Ids', __FILE__, __LINE__, __METHOD__, 10);
        if (!($default_schedule_current_level_user_ids === FALSE and $default_schedule_parent_level_user_ids === FALSE and $default_schedule_child_level_user_ids === FALSE)) {
            $dsculf = new DefaultScheduleControlUserListFactory();
            $dsculf->getByUserIdListAndStatusAndNotAuthorized($default_schedule_current_level_user_ids, 30, $default_schedule_parent_level_user_ids, $default_schedule_current_level_user_ids, NULL, NULL, NULL, array('a.created_date' => 'asc'));
            $dsculf->getByUserIdListAndStatusAndNotAuthorized($default_schedule_child_level_user_ids, 30, $default_schedule_parent_level_user_ids, $default_schedule_current_level_user_ids, NULL, NULL, NULL, array('a.created_date' => 'asc'));
            foreach ($dsculf as $default_schedule_control_user) {
                //Grab authorizations for this object.
                Debug::Text('Default Schedule Control User ID: ' . $default_schedule_control_user->getId(), __FILE__, __LINE__, __METHOD__, 10);
                $default_schedule_control_user_data = $ulf->getById($default_schedule_control_user->getUser())->getCurrent();
                $default_schedule_controls[] = array('id' => $default_schedule_control_user->getId(), 'user_id' => $default_schedule_control_user->getUser(), 'user_full_name' => $default_schedule_control_user_data->getFullName(), 'name' => $default_schedule_control_user->getDefaultScheduleControlObject()->getName(), 'description' => $default_schedule_control_user->getDefaultScheduleControlObject()->getDescription());
            }
            if (isset($default_schedule_controls)) {
Пример #3
0
$smarty->assign('title', TTi18n::gettext($title = 'View Hierarchy'));
// See index.php
BreadCrumb::setCrumb($title);
/*
 * Get FORM variables
 */
extract(FormVariables::GetVariables(array('action', 'hierarchy_id', 'id')));
switch ($action) {
    default:
        if (isset($id)) {
            $hlf = new HierarchyListFactory();
            $tmp_id = $id;
            $i = 0;
            do {
                Debug::Text(' Iteration...', __FILE__, __LINE__, __METHOD__, 10);
                $parents = $hlf->getParentLevelIdArrayByHierarchyControlIdAndUserId($hierarchy_id, $tmp_id);
                $level = $hlf->getFastTreeObject()->getLevel($tmp_id) - 1;
                if (is_array($parents) and count($parents) > 0) {
                    $parent_users = array();
                    foreach ($parents as $user_id) {
                        //Get user information
                        $ulf = new UserListFactory();
                        $ulf->getById($user_id);
                        $user = $ulf->getCurrent();
                        unset($ulf);
                        $parent_users[] = array('name' => $user->getFullName());
                        unset($user);
                    }
                    $parent_groups[] = array('users' => $parent_users, 'level' => $level);
                    unset($parent_users);
                }
 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;
 }