示例#1
0
/**
 *	Sets up viewing the list of departments.
 *
 *	$context['dept_list'] contains the list of departments that the user can see, key/value pair, array is ordered according to the ordering specified in the Departments administration area.
 *	The key for $context['dept_list'] is the department's id, with the array content being:
 *	- id_dept - departmental id (numeric)
 *	- dept_name - department's name
 *	- tickets - an array containing three elements, open, closed and assigned - containing the counts thereof for each department for the current user.
 *	- new - boolean whether this department has some new items to be read by the current user
 *
 *	The linktree is also modified to inclue the department list.
 *
 *	@see shd_get_ticket_counts()
 *	@see shd_get_unread_departments()
 *	@since 2.0
*/
function shd_main_dept()
{
    global $context, $txt, $smcFunc, $scripturl, $user_info, $sourcedir;
    $dept_list = shd_allowed_to('access_helpdesk', false);
    $context += array('page_title' => $txt['shd_helpdesk'] . ' - ' . $txt['shd_departments'], 'sub_template' => 'shd_depts', 'shd_home_view' => shd_allowed_to('shd_staff', 0) ? 'staff' : 'user');
    // Get the departments and order them in the same order they would be on the board index.
    $context['dept_list'] = array();
    $query = $smcFunc['db_query']('', '
		SELECT hdd.id_dept, hdd.dept_name
		FROM {db_prefix}helpdesk_depts AS hdd
		WHERE hdd.id_dept IN ({array_int:depts})
		ORDER BY hdd.dept_order', array('depts' => $dept_list));
    while ($row = $smcFunc['db_fetch_assoc']($query)) {
        $context['dept_list'][$row['id_dept']] = array('id_dept' => $row['id_dept'], 'dept_name' => $row['dept_name'], 'tickets' => array('open' => 0, 'closed' => 0, 'assigned' => 0), 'new' => false);
    }
    $smcFunc['db_free_result']($query);
    require_once $sourcedir . '/sd_source/Subs-SimpleDeskBoardIndex.php';
    shd_get_ticket_counts();
    shd_get_unread_departments();
    $context['linktree'][] = array('url' => $scripturl . '?action=helpdesk;sa=dept', 'name' => $txt['shd_departments']);
}
function shd_add_to_boardindex(&$boardIndexOptions, &$categories)
{
    global $context, $modSettings, $smcFunc, $board, $txt, $scripturl, $settings;
    // Does the category exist? If it has no boards, it actually might not exist, daft as it sounds.
    // But it's more tricky than that, too! We need to be at the board index, not in a child board.
    if (!empty($board)) {
        return;
    }
    call_integration_hook('shd_hook_boardindex_before', array(&$boardIndexOptions, &$categories));
    // OK, so what helpdesks are we displaying?
    $depts = shd_allowed_to('access_helpdesk', false);
    if (empty($depts)) {
        return;
    }
    $cat_list = array();
    $query = $smcFunc['db_query']('', '
		SELECT id_dept, dept_name, description, board_cat, before_after
		FROM {db_prefix}helpdesk_depts
		WHERE id_dept IN ({array_int:depts})
		ORDER BY before_after DESC, dept_order', array('depts' => $depts));
    $depts = array_flip($depts);
    while ($row = $smcFunc['db_fetch_assoc']($query)) {
        if ($row['board_cat'] == 0) {
            unset($depts[$row['id_dept']]);
            continue;
        }
        $depts[$row['id_dept']] = $row;
        $cat_list[] = $row['board_cat'];
        $context['dept_list'][$row['id_dept']] = array('id_dept' => $row['id_dept'], 'dept_name' => $row['dept_name'], 'dept_desc' => $row['description'], 'tickets' => array('open' => 0, 'closed' => 0, 'assigned' => 0), 'new' => false);
    }
    if (empty($context['dept_list'])) {
        return;
    }
    $cat_list = array_unique($cat_list);
    // Do we have all these categories?
    foreach ($cat_list as $k => $v) {
        if (!empty($categories[$v])) {
            unset($cat_list[$k]);
        }
    }
    if (!empty($cat_list)) {
        // Uh oh, we have to load a category or two.
        $new_cats = array();
        $request = $smcFunc['db_query']('', '
			SELECT c.id_cat, c.name, c.can_collapse, IFNULL(cc.id_member, 0) AS is_collapsed
			FROM {db_prefix}categories AS c
				LEFT JOIN {db_prefix}collapsed_categories AS cc ON (cc.id_cat = c.id_cat AND cc.id_member = {int:current_member})
			WHERE c.id_cat IN ({array_int:cat})', array('cat' => $cat_list, 'current_member' => $context['user']['id']));
        while ($this_cat = $smcFunc['db_fetch_assoc']($request)) {
            $new_cats[$this_cat['id_cat']] = array('id' => $this_cat['id_cat'], 'name' => $this_cat['name'], 'is_collapsed' => isset($this_cat['can_collapse']) && $this_cat['can_collapse'] == 1 && $this_cat['is_collapsed'] > 0, 'can_collapse' => isset($this_cat['can_collapse']) && $this_cat['can_collapse'] == 1, 'collapse_href' => isset($this_cat['can_collapse']) ? $scripturl . '?action=collapse;c=' . $this_cat['id_cat'] . ';sa=' . ($this_cat['is_collapsed'] > 0 ? 'expand;' : 'collapse;') . $context['session_var'] . '=' . $context['session_id'] . '#c' . $this_cat['id_cat'] : '', 'collapse_image' => isset($this_cat['can_collapse']) ? '<img src="' . $settings['images_url'] . '/' . ($this_cat['is_collapsed'] > 0 ? 'expand.png" alt="+"' : 'collapse.png" alt="-"') . ' />' : '', 'href' => $scripturl . '#c' . $this_cat['id_cat'], 'boards' => array(), 'new' => false);
            $new_cats[$this_cat['id_cat']]['link'] = '<a id="c' . $this_cat['id_cat'] . '" href="' . (isset($this_cat['can_collapse']) ? $new_cats[$this_cat['id_cat']]['collapse_href'] : $new_cats[$this_cat['id_cat']]['href']) . '">' . $this_cat['name'] . '</a>';
        }
        $smcFunc['db_free_result']($request);
        // So, did we add any new categories? If we didn't, something's wrong - abort safely NOW.
        if (empty($new_cats)) {
            return;
        }
        // OK, so we have some categories to integrate.
        $old_cats = $categories;
        $categories = array();
        $request = $smcFunc['db_query']('', '
			SELECT id_cat
			FROM {db_prefix}categories
			ORDER BY cat_order');
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            if (isset($old_cats[$row['id_cat']])) {
                $categories[$row['id_cat']] = $old_cats[$row['id_cat']];
            } elseif (isset($new_cats[$row['id_cat']])) {
                $categories[$row['id_cat']] = $new_cats[$row['id_cat']];
            }
        }
        $smcFunc['db_free_result']($request);
    }
    // So, OK, the categories exist. Now we need to create our magic boards, and integrate them.
    // First we do the after's, in order.
    foreach ($depts as $dept) {
        if (empty($dept['before_after'])) {
            continue;
        }
        $dept['link'] = count($depts) != 0 ? ';dept=' . $dept['id_dept'] : '';
        $new_board = shd_dept_board($dept);
        $categories[$dept['board_cat']]['boards'][$new_board['id']] = $new_board;
    }
    // OK, now for the before's. Because we're merging, that means we're doing them last-first.
    $depts = array_reverse($depts);
    foreach ($depts as $dept) {
        if (!empty($dept['before_after'])) {
            continue;
        }
        $dept['link'] = count($depts) != 0 ? ';dept=' . $dept['id_dept'] : '';
        $new_board = shd_dept_board($dept);
        $categories[$dept['board_cat']]['boards'] = array_merge(array($new_board['id'] => $new_board), $categories[$dept['board_cat']]['boards']);
    }
    // Last but not least, fix up the replacements and some figuring out.
    shd_get_ticket_counts();
    shd_get_unread_departments();
    if (empty($context['shd_buffer_preg_replacements'])) {
        $context['shd_buffer_preg_replacements'] = array();
    }
    foreach ($context['dept_list'] as $dept => $dept_details) {
        // Inject the count of tickets.
        $dept_id = '~' . preg_quote(comma_format(-$dept), '~') . '\\s+' . preg_quote($txt['redirects'], '~') . '~';
        $context['shd_buffer_preg_replacements'][$dept_id] = $dept_details['tickets']['open'] . ' ' . ($dept_details['tickets']['open'] == 1 ? $txt['shd_open_ticket'] : $txt['shd_open_tickets']);
    }
    // Call the relevant function via hook.
    add_integration_function('shd_hook_buffer', 'shd_buffer_boardindex', false);
    call_integration_hook('shd_hook_boardindex_after', array(&$categories));
}