示例#1
0
        }
        //Get include employee list.
        $ulf = new UserListFactory();
        $ulf->getByCompanyId($current_company->getId());
        $raw_user_options = $ulf->getArrayByListFactory($ulf, FALSE, TRUE);
        //$raw_user_list_options = UserListFactory::getByCompanyIdArray( $current_company->getId() );
        //Only allow them to select employees not already in the tree.
        unset($parent_list_options[$id]);
        //If we're editing a single entry, include that user in the list.
        $parent_list_keys = array_keys($parent_list_options);
        $user_options = Misc::arrayDiffByKey((array) $parent_list_keys, $raw_user_options);
        $src_user_options = Misc::arrayDiffByKey((array) $user_data['user_id'], $user_options);
        $selected_user_options = Misc::arrayIntersectByKey((array) $user_data['user_id'], $user_options);
        //$smarty->assign_by_ref('user_list_options', $user_list_options);
        $smarty->assign_by_ref('src_user_options', $src_user_options);
        $smarty->assign_by_ref('selected_user_options', $selected_user_options);
        $smarty->assign_by_ref('parent_list_options', $parent_list_options);
        if (isset($id) and $id != '' and $redirect == 0) {
            Debug::Text(' ID: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
            $node = $hlf->getByHierarchyControlIdAndUserId($hierarchy_id, $id);
            $smarty->assign_by_ref('selected_node', $node);
        } else {
            $id = $user_data['user_id'][0];
        }
        break;
}
$smarty->assign_by_ref('hierarchy_id', $hierarchy_id);
$smarty->assign_by_ref('id', $id);
$smarty->assign_by_ref('old_id', $id);
$smarty->assign_by_ref('hf', $hf);
$smarty->display('hierarchy/EditHierarchy.tpl');
$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
        $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.
 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;
 }