/** * 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'); }
* In accordance with Section 7(b) of the GNU Affero General Public License * version 3, these Appropriate Legal Notices must retain the display of the * "Powered by TimeTrex" logo. If the display of the logo is not reasonably * feasible for technical reasons, the Appropriate Legal Notices must display * the words "Powered by TimeTrex". ********************************************************************************/ /* * $Revision: 1396 $ * $Id: AuthorizationNotify.php 1396 2007-11-07 16:49:35Z ipso $ * $Date: 2007-11-07 08:49:35 -0800 (Wed, 07 Nov 2007) $ */ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'global.inc.php'; require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'CLI.inc.php'; $permission = new Permission(); $hlf = new HierarchyListFactory(); $hotlf = new HierarchyObjectTypeListFactory(); //Get all users $ulf = new UserListFactory(); $ulf->getByStatus(10, NULL, array('company_id' => 'asc')); 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
function getByCompanyIdArray($id) { $hotlf = new HierarchyObjectTypeListFactory(); $hotlf->getByCompanyId($id); $object_type = array(); foreach ($hotlf as $object_type) { $object_types[] = $object_type->getObjectType(); } return $object_types; }
function getEmailMessageAddresses() { $olf = $this->getObjectHandler(); if (is_object($olf)) { $olf->getById($this->getObject()); if ($olf->getRecordCount() > 0) { $obj = $olf->getCurrent(); switch ($this->getObjectType()) { case 5: case 100: Debug::Text('Email Object Type... Parent ID: ' . $this->getParent(), __FILE__, __LINE__, __METHOD__, 10); if ($this->getParent() == 0) { $user_ids[] = $obj->getId(); } else { $mlf = new MessageListFactory(); $mlf->getById($this->getParent()); if ($mlf->getRecordCount() > 0) { $m_obj = $mlf->getCurrent(); $user_ids[] = $m_obj->getCreatedBy(); } Debug::Text('cEmail Object Type... Parent ID: ' . $this->getParent(), __FILE__, __LINE__, __METHOD__, 10); } break; case 40: $user_ids[] = $obj->getId(); break; case 50: //Request //Get all users who have contributed to the thread. $mlf = new MessageListFactory(); $mlf->getMessagesInThreadById($this->getId()); Debug::Text(' Messages In Thread: ' . $mlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($mlf->getRecordCount() > 0) { foreach ($mlf as $m_obj) { $user_ids[] = $m_obj->getCreatedBy(); } } unset($mlf, $m_obj); //Debug::Arr($user_ids, 'User IDs in Thread: ', __FILE__, __LINE__, __METHOD__,10); //Only alert direct supervisor to request at this point. Because we need to take into account //if the request was authorized or not to determine if we should email the next higher level in the hierarchy. if ($this->getParent() == 0) { //Get direct parent in hierarchy. $u_obj = $obj->getUserObject(); //Find proper hierarchy to use for this object $hotlf = new HierarchyObjectTypeListFactory(); $control_id = $hotlf->getByCompanyIdAndObjectTypeId($u_obj->getCompany(), $this->getObjectType())->getCurrent()->getHierarchyControl(); Debug::Text(' Hierarchy Control ID: ' . $control_id, __FILE__, __LINE__, __METHOD__, 10); $hlf = new HierarchyListFactory(); $node_data = $hlf->getByHierarchyControlIdAndUserId($control_id, $u_obj->getId()); if ($node_data['parent_id'] != 0) { $user_ids[] = $node_data['parent_id']; } unset($hotlf, $control_id, $hlf, $node_data); } global $current_user; if (isset($current_user) and is_object($current_user) and isset($user_ids) and is_array($user_ids)) { $user_ids = array_unique($user_ids); $current_user_key = array_search($current_user->getId(), $user_ids); Debug::Text(' Current User Key: ' . $current_user_key, __FILE__, __LINE__, __METHOD__, 10); if ($current_user_key !== FALSE) { Debug::Text(' Removing Current User From Recipient List...' . $current_user->getId(), __FILE__, __LINE__, __METHOD__, 10); unset($user_ids[$current_user_key]); } } else { Debug::Text(' Current User Object not available...', __FILE__, __LINE__, __METHOD__, 10); } unset($current_user, $current_user_key); break; case 90: $user_ids[] = $obj->getUser(); break; } } if (isset($user_ids) and is_array($user_ids)) { //Get user preferences and determine if they accept email notifications. Debug::Arr($user_ids, 'Recipient User Ids: ', __FILE__, __LINE__, __METHOD__, 10); $uplf = new UserPreferenceListFactory(); $uplf->getByUserId($user_ids); if ($uplf->getRecordCount() > 0) { foreach ($uplf as $up_obj) { if ($up_obj->getEnableEmailNotificationMessage() == TRUE and $up_obj->getUserObject()->getStatus() == 10) { if ($up_obj->getUserObject()->getWorkEmail() != '') { $retarr[] = $up_obj->getUserObject()->getWorkEmail(); } if ($up_obj->getEnableEmailNotificationHome() and $up_obj->getUserObject()->getHomeEmail() != '') { $retarr[] = $up_obj->getUserObject()->getHomeEmail(); } } } if (isset($retarr)) { Debug::Arr($retarr, 'Recipient Email Addresses: ', __FILE__, __LINE__, __METHOD__, 10); return $retarr; } } } } return FALSE; }
function setObjectTypeIds($ids) { if (is_array($ids)) { if (!$this->isNew()) { //If needed, delete mappings first. $lf_a = new HierarchyObjectTypeListFactory(); $lf_a->getByHierarchyControlId($this->getId()); $tmp_ids = array(); foreach ($lf_a as $obj) { $id = $obj->getId(); Debug::text('Hierarchy Object Type ID: ' . $obj->getId() . ' ID: ' . $id, __FILE__, __LINE__, __METHOD__, 10); //Delete users that are not selected. if (!in_array($id, $ids)) { Debug::text('Deleting: ' . $id, __FILE__, __LINE__, __METHOD__, 10); $obj->Delete(); } else { //Save ID's that need to be updated. Debug::text('NOT Deleting : ' . $id, __FILE__, __LINE__, __METHOD__, 10); $tmp_ids[] = $id; } } unset($id, $obj); } foreach ($ids as $id) { if (isset($ids) and !in_array($id, $tmp_ids)) { $f = new HierarchyObjectTypeFactory(); $f->setHierarchyControl($this->getId()); $f->setObjectType($id); if ($this->Validator->isTrue('object_type', $f->Validator->isValid(), TTi18n::gettext('Object type is already assigned to another hierarchy'))) { $f->save(); } } } return TRUE; } return FALSE; }
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; }
if ($last_new_level > $last_saved_level) { $last_level = $last_new_level; } else { $last_level = $last_saved_level; } Debug::Text('Last level: ' . $last_level, __FILE__, __LINE__, __METHOD__, 10); $hierarchy_level_data[$next_blank_id] = array('id' => $next_blank_id, 'level' => $last_level + 1); } elseif ($action != 'submit' and $action != 'delete_level') { //New hierarchy. $hierarchy_level_data[-1] = array('id' => -1, 'level' => 1); } $prepend_array_option = array(0 => TTi18n::gettext('-- Please Choose --')); $ulf = new UserListFactory(); $user_options = $ulf->getByCompanyIDArray($current_company->getId(), FALSE, TRUE); //Select box options; $hotlf = new HierarchyObjectTypeListFactory(); $hierarchy_control_data['user_options'] = $user_options; $hierarchy_control_data['level_user_options'] = Misc::prependArray($prepend_array_option, $user_options); $hierarchy_control_data['object_type_options'] = $hotlf->getOptions('object_type'); if (isset($hierarchy_control_data['user_ids']) and is_array($hierarchy_control_data['user_ids'])) { $tmp_user_options = $user_options; foreach ($hierarchy_control_data['user_ids'] as $user_id) { if (isset($tmp_user_options[$user_id])) { $filter_user_options[$user_id] = $tmp_user_options[$user_id]; } } unset($user_id); } $smarty->assign_by_ref('filter_user_options', $filter_user_options); $smarty->assign_by_ref('hierarchy_control_data', $hierarchy_control_data); $smarty->assign_by_ref('hierarchy_level_data', $hierarchy_level_data);