Пример #1
0
/**
 *	Load the user preferences for the given user.
 *
 *	@param mixed $user Normally, an int being the user id of the user whose preferences should be attempted to be loaded. If === false, return the list of default prefs (for the pref UI), or if 0 or omitted, load the current user.
 *
 *	@return array If $user === false, the list of options, their types and default values is returned. Otherwise, return an array of prefs (adjusted for this user)
 *	@since 2.0
*/
function shd_load_user_prefs($user = 0)
{
    global $modSettings, $smcFunc, $user_info, $txt, $sourcedir;
    static $pref_groups = null, $base_prefs = null;
    if ($pref_groups === null) {
        $pref_groups = array('display' => array('icon' => 'preferences.png', 'enabled' => true), 'notify' => array('icon' => 'email.png', 'enabled' => true, 'check_all' => true), 'blocks' => array('icon' => 'log.png', 'enabled' => true), 'block_order' => array('icon' => 'move_down.png', 'enabled' => true));
        $base_prefs = array('display_unread_type' => array('options' => array('none' => 'shd_pref_display_unread_none', 'unread' => 'shd_pref_display_unread_unread', 'outstanding' => 'shd_pref_display_unread_outstanding'), 'default' => 'outstanding', 'type' => 'select', 'icon' => 'unread.png', 'group' => 'display', 'permission' => 'shd_staff', 'show' => empty($modSettings['shd_helpdesk_only']) && empty($modSettings['shd_disable_unread'])), 'display_order' => array('options' => array('asc' => 'shd_pref_display_order_asc', 'desc' => 'shd_pref_display_order_desc'), 'default' => 'asc', 'type' => 'select', 'icon' => 'move_down.png', 'group' => 'display', 'permission' => 'access_helpdesk', 'show' => true), 'blocks_assigned_count' => array('default' => 10, 'type' => 'int', 'icon' => 'assign.png', 'group' => 'blocks', 'permission' => 'shd_staff', 'show' => true), 'blocks_new_count' => array('default' => 10, 'type' => 'int', 'icon' => 'status.png', 'group' => 'blocks', 'permission' => 'access_helpdesk', 'show' => true), 'blocks_staff_count' => array('default' => 10, 'type' => 'int', 'icon' => 'staff.png', 'group' => 'blocks', 'permission' => 'access_helpdesk', 'show' => true), 'blocks_user_count' => array('default' => 10, 'type' => 'int', 'icon' => 'user.png', 'group' => 'blocks', 'permission' => 'access_helpdesk', 'show' => true), 'blocks_closed_count' => array('default' => 10, 'type' => 'int', 'icon' => 'resolved.png', 'group' => 'blocks', 'permission' => array('shd_view_closed_own', 'shd_view_closed_any'), 'show' => true), 'blocks_recycle_count' => array('default' => 10, 'type' => 'int', 'icon' => 'recycle.png', 'group' => 'blocks', 'permission' => 'shd_access_recyclebin', 'show' => true), 'blocks_withdeleted_count' => array('default' => 10, 'type' => 'int', 'icon' => 'recycle.png', 'group' => 'blocks', 'permission' => 'shd_access_recyclebin', 'show' => true), 'notify_new_ticket' => array('default' => 0, 'type' => 'check', 'icon' => 'log_newticket.png', 'group' => 'notify', 'permission' => 'shd_staff', 'show' => !empty($modSettings['shd_notify_new_ticket'])), 'notify_new_reply_own' => array('default' => 1, 'type' => 'check', 'icon' => 'log_newreply.png', 'group' => 'notify', 'permission' => 'shd_new_ticket', 'show' => !empty($modSettings['shd_notify_new_reply_own'])), 'notify_new_reply_assigned' => array('default' => 0, 'type' => 'check', 'icon' => 'log_assign.png', 'group' => 'notify', 'permission' => 'shd_staff', 'show' => !empty($modSettings['shd_notify_new_reply_assigned'])), 'notify_new_reply_previous' => array('default' => 0, 'type' => 'check', 'icon' => 'log_newreply.png', 'group' => 'notify', 'permission' => 'shd_staff', 'show' => !empty($modSettings['shd_notify_new_reply_previous'])), 'notify_new_reply_any' => array('default' => 0, 'type' => 'check', 'icon' => 'log_newreply.png', 'group' => 'notify', 'permission' => 'shd_staff', 'show' => !empty($modSettings['shd_notify_new_reply_any'])), 'notify_assign_me' => array('default' => 0, 'type' => 'check', 'icon' => 'assign.png', 'group' => 'notify', 'permission' => 'shd_staff', 'show' => !empty($modSettings['shd_notify_assign_me'])), 'notify_assign_own' => array('default' => 0, 'type' => 'check', 'icon' => 'assign.png', 'group' => 'notify', 'permission' => 'shd_new_ticket', 'show' => !empty($modSettings['shd_notify_assign_own'])), 'block_order_assigned_block' => array('default' => 'updated_asc', 'type' => 'select', 'icon' => 'assign.png', 'group' => 'block_order', 'permission' => 'shd_staff', 'show' => true), 'block_order_new_block' => array('default' => 'updated_asc', 'type' => 'select', 'icon' => 'status.png', 'group' => 'block_order', 'permission' => 'access_helpdesk', 'show' => true), 'block_order_staff_block' => array('default' => 'updated_asc', 'type' => 'select', 'icon' => 'staff.png', 'group' => 'block_order', 'permission' => 'access_helpdesk', 'show' => true), 'block_order_user_block' => array('default' => 'updated_asc', 'type' => 'select', 'icon' => 'user.png', 'group' => 'block_order', 'permission' => 'access_helpdesk', 'show' => true), 'block_order_closed_block' => array('default' => 'updated_desc', 'type' => 'select', 'icon' => 'resolved.png', 'group' => 'block_order', 'permission' => array('shd_view_closed_own', 'shd_view_closed_any'), 'show' => true), 'block_order_recycle_block' => array('default' => 'updated_desc', 'type' => 'select', 'icon' => 'recycle.png', 'group' => 'block_order', 'permission' => 'shd_access_recyclebin', 'show' => true), 'block_order_withdeleted_block' => array('default' => 'updated_desc', 'type' => 'select', 'icon' => 'recycle.png', 'group' => 'block_order', 'permission' => 'shd_access_recyclebin', 'show' => true));
        // We want to add the preferences per block. Because we already know what options there are per block elsewhere, let's reuse that.
        if (!function_exists('shd_get_block_columns')) {
            require_once $sourcedir . '/sd_source/SimpleDesk.php';
        }
        $blocks = array('assigned', 'new', 'staff', shd_allowed_to('shd_staff', 0) ? 'user_staff' : 'user_user', 'closed', 'recycled', 'withdeleted');
        foreach ($blocks as $block) {
            $items = shd_get_block_columns($block);
            if (empty($items)) {
                continue;
            }
            if ($block == 'user_staff' || $block == 'user_user') {
                $block = 'user';
            } elseif ($block == 'recycled') {
                $block = 'recycle';
            }
            $block_id = 'block_order_' . $block . '_block';
            $base_prefs[$block_id]['options'] = array();
            foreach ($items as $item) {
                if ($item != 'actions') {
                    $item = str_replace(array('_', 'startinguser'), array('', 'starter'), $item);
                    $base_prefs[$block_id]['options'][$item . '_asc'] = 'shd_pref_block_order_' . $item . '_asc';
                    $base_prefs[$block_id]['options'][$item . '_desc'] = 'shd_pref_block_order_' . $item . '_desc';
                }
            }
        }
        // Now engage any hooks.
        call_integration_hook('shd_hook_prefs', array(&$pref_groups, &$base_prefs));
        foreach ($base_prefs as $pref => $details) {
            if (empty($pref_groups[$details['group']]['enabled']) || empty($details['show'])) {
                unset($base_prefs[$pref]);
            }
        }
    }
    // Do we just want the prefs list?
    if ($user === false) {
        return array('groups' => $pref_groups, 'prefs' => $base_prefs);
    }
    $prefs = array();
    if ($user == 0 || $user == $user_info['id']) {
        $user = $user_info['id'];
        // Start with the defaults, but dealing with permissions as we go
        foreach ($base_prefs as $pref => $details) {
            if (empty($details['permission']) || shd_allowed_to($details['permission'], 0)) {
                $prefs[$pref] = $details['default'];
            }
        }
    } else {
        foreach ($base_prefs as $pref => $details) {
            if (empty($details['permission'])) {
                continue;
            }
            if (is_array($details['permission'])) {
                foreach ($details['permission'] as $perm) {
                    if (in_array($user, shd_members_allowed_to($perm))) {
                        $prefs[$pref] = $details['default'];
                        break;
                    }
                }
            } else {
                if (in_array($user, shd_members_allowed_to($details['permission']))) {
                    $prefs[$pref] = $details['default'];
                }
            }
        }
    }
    // Now, the database
    $query = $smcFunc['db_query']('', '
		SELECT variable, value
		FROM {db_prefix}helpdesk_preferences
		WHERE id_member = {int:user}', array('user' => (int) $user));
    while ($row = $smcFunc['db_fetch_assoc']($query)) {
        if (isset($prefs[$row['variable']])) {
            $prefs[$row['variable']] = $row['value'];
        }
    }
    return $prefs;
}
Пример #2
0
/**
 *	Set up the paginated lists of deleted/recyclebin tickets.
 *
 *	Much like the main helpdesk, this function prepares a list of all the deleted tickets, with a more specific
 *	list of columns that is better suited to recyclable or permadeletable tickets.
 *
 *	@see shd_main_helpdesk()
 *	@since 1.0
*/
function shd_recycle_bin()
{
    global $context, $txt, $smcFunc, $user_profile, $scripturl, $settings, $user_info;
    // Stuff we need to add to $context, the permission we want to use, page title etc etc
    $context += array('shd_permission' => 'shd_access_recyclebin', 'page_title' => $txt['shd_helpdesk'], 'sub_template' => 'recyclebin', 'ticket_blocks' => array('recycle' => array('block_icon' => 'recycle.png', 'title' => $txt['shd_status_' . TICKET_STATUS_DELETED . '_heading'], 'tickets' => array(), 'where' => 'hdt.status = ' . TICKET_STATUS_DELETED, 'display' => true, 'count' => shd_count_helpdesk_tickets('recycled'), 'columns' => shd_get_block_columns('recycled'), 'required' => true, 'collapsed' => false), 'withdeleted' => array('block_icon' => 'recycle.png', 'title' => $txt['shd_status_withdeleted_heading'], 'tickets' => array(), 'where' => 'hdt.status != ' . TICKET_STATUS_DELETED . ' AND hdt.deleted_replies > 0', 'display' => true, 'count' => shd_count_helpdesk_tickets('withdeleted'), 'columns' => shd_get_block_columns('withdeleted'), 'required' => true, 'collapsed' => false)));
    // Build the link tree.
    if (!empty($context['shd_dept_name']) && $context['shd_multi_dept']) {
        $context['linktree'][] = array('url' => $scripturl . '?' . $context['shd_home'] . $context['shd_dept_link'], 'name' => $context['shd_dept_name']);
    }
    $context['linktree'][] = array('url' => $scripturl . '?action=helpdesk;sa=recyclebin' . $context['shd_dept_link'], 'name' => $txt['shd_recycle_bin']);
    shd_helpdesk_listing();
}