function shd_profile_main($memID)
{
    global $context, $txt, $scripturl, $sourcedir, $user_info, $settings, $user_profile, $modSettings;
    // Load the profile details
    loadTemplate('sd_template/SimpleDesk-Profile', array('helpdesk', 'helpdesk_admin'));
    shd_load_language('sd_language/SimpleDeskProfile');
    $context['shd_preferences'] = shd_load_user_prefs();
    shd_load_plugin_files('hdprofile');
    shd_load_plugin_langfiles('hdprofile');
    $context['page_title'] = $txt['shd_profile_area'] . ' - ' . $txt['shd_profile_main'];
    $context['sub_template'] = 'shd_profile_main';
    $subActions = array('helpdesk' => 'shd_profile_frontpage', 'hd_prefs' => 'shd_profile_preferences', 'hd_showtickets' => 'shd_profile_show_tickets', 'hd_permissions' => 'shd_profile_permissions', 'hd_actionlog' => 'shd_profile_actionlog');
    $context['shd_profile_menu'] = array(array('image' => 'user.png', 'link' => $scripturl . '?action=profile;u=' . $context['member']['id'] . ';area=helpdesk', 'text' => $txt['shd_profile_home'], 'show' => true), array('image' => 'preferences.png', 'link' => $scripturl . '?action=profile;u=' . $context['member']['id'] . ';area=hd_prefs', 'text' => $txt['shd_profile_preferences'], 'show' => true), array('image' => 'ticket.png', 'link' => $scripturl . '?action=profile;u=' . $context['member']['id'] . ';area=hd_showtickets', 'text' => $txt['shd_profile_show_tickets'], 'show' => true), array('image' => 'permissions.png', 'link' => $scripturl . '?action=profile;u=' . $context['member']['id'] . ';area=hd_permissions', 'text' => $txt['shd_profile_permissions'], 'show' => !empty($context['helpdesk_menu']['areas']['hd_permissions']['enabled'])), array('image' => 'log.png', 'link' => $scripturl . '?action=profile;u=' . $context['member']['id'] . ';area=hd_actionlog', 'text' => $txt['shd_profile_actionlog'], 'show' => !empty($context['helpdesk_menu']['areas']['hd_actionlog']['enabled'])), array('image' => 'go_to_helpdesk.png', 'link' => $scripturl . '?action=helpdesk;sa=main', 'text' => $txt['shd_profile_go_to_helpdesk'], 'show' => true));
    // Int hooks - after we basically set everything up (so it's manipulatable by the hook, but before we do the last bits of finalisation)
    call_integration_hook('shd_hook_hdprofile', array(&$subActions, &$memID));
    // Make sure the menu is configured appropriately
    $context['shd_profile_menu'][count($context['shd_profile_menu']) - 1]['is_last'] = true;
    $_REQUEST['area'] = isset($_REQUEST['area']) && isset($subActions[$_REQUEST['area']]) ? $_REQUEST['area'] : 'helpdesk';
    $context['sub_action'] = $_REQUEST['area'];
    $subActions[$_REQUEST['area']]($memID);
    // Maintenance mode? If it were, the helpdesk is considered inactive for the purposes of everything to all but those without admin-helpdesk rights - but we must have them if we're here!
    if (!empty($modSettings['shd_maintenance_mode'])) {
        loadTemplate('sd_template/SimpleDesk');
        $temp_layers = $context['template_layers'];
        $context['template_layers'] = array();
        $added = false;
        foreach ($temp_layers as $layer) {
            $context['template_layers'][] = $layer;
            if ($layer == 'body') {
                $context['template_layers'][] = 'shd_maintenance';
                $added = true;
            }
        }
        // Well, we tried to add it as near the top as possible, but not all themes use the standard body layer.
        if (!$added) {
            $context['template_layers'][] = 'shd_maintenance';
        }
    }
    $context['template_layers'][] = 'shd_profile_navigation';
}
/**
 *	Adds the SimpleDesk action to the action list, and also handles most of the shutting down of forum items in helpdesk-only mode.
 *
 *	@param string &$actionArray The master list of actions from index.php
 *
 *	@since 2.0
*/
function shd_init_actions(&$actionArray)
{
    global $modSettings, $context;
    if (empty($modSettings['helpdesk_active'])) {
        return;
    }
    // Deal with SimpleDesk. If we're enabling HD only mode, rebuild everything, otherwise just add it to the array.
    $actionArray['helpdesk'] = array('sd_source/SimpleDesk.php', 'shd_main');
    // Rewrite the array for unread purposes.
    $context['shd_unread_actions'] = array('unread' => $actionArray['unread'], 'unreadreplies' => $actionArray['unreadreplies']);
    $actionArray['unread'] = array('sd_source/SimpleDesk-Unread.php', 'shd_unread_posts');
    $actionArray['unreadreplies'] = array('sd_source/SimpleDesk-Unread.php', 'shd_unread_posts');
    // If we're going to a help page (for admin), make sure to load the relevant text.
    if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'helpadmin') {
        shd_load_language('sd_language/SimpleDeskAdmin');
    }
    if (!empty($modSettings['shd_helpdesk_only'])) {
        // Firstly, remove all the standard actions we neither want nor need.
        // Note we did this to prevent breakage of other mods that may be installed, e.g. gallery or portal or something.
        $unwanted_actions = array('announce', 'attachapprove', 'buddy', 'calendar', 'clock', 'collapse', 'deletemsg', 'display', 'editpoll', 'editpoll2', 'emailuser', 'lock', 'lockvoting', 'markasread', 'mergetopics', 'moderate', 'modifycat', 'modifykarma', 'movetopic', 'movetopic2', 'notify', 'notifyboard', 'post', 'post2', 'printpage', 'quotefast', 'quickmod', 'quickmod2', 'recent', 'removepoll', 'removetopic2', 'reporttm', 'restoretopic', 'search', 'search2', 'sendtopic', 'smstats', 'splittopics', 'stats', 'sticky', 'about:mozilla', 'about:unknown', 'unread', 'unreadreplies', 'vote', 'viewquery', 'who', '.xml', 'xmlhttp');
        // that's the generic stuff, now for specific options
        if (!empty($modSettings['shd_disable_pm'])) {
            $unwanted_actions[] = 'pm';
        }
        if (!empty($modSettings['shd_disable_mlist'])) {
            $unwanted_actions[] = 'mlist';
        }
        foreach ($unwanted_actions as $unwanted) {
            if (isset($actionArray[$unwanted])) {
                unset($actionArray[$unwanted]);
            }
        }
        // Secondly, rewrite the defaults to point to helpdesk, for unknown actions. I'm doing this rather than munging the main code - easier to unbreak stuff
        if (empty($actionArray[$_GET['action']])) {
            $_GET['action'] = 'helpdesk';
        }
    }
    // Now engage any SD specific hooks.
    call_integration_hook('shd_hook_actions', array(&$actionArray));
    // Lastly, any other-action-specific hooks?
    if (!empty($_GET['action']) && !empty($actionArray[$_GET['action']])) {
        shd_load_plugin_files('action_' . $_GET['action']);
        shd_load_plugin_langfiles('action_' . $_GET['action']);
        call_integration_hook('shd_hook_action' . $_GET['action'], array(&$actionArray));
    }
    $context['master_action_list'] = array_keys($actionArray);
}
/**
 *	Perform all the operations required for SimpleDesk to safely start operations inside the admin panel.
 *
 *	@param array &$admin_areas The full admin area array from SMF's Admin.php.
 *	@since 2.0
*/
function shd_admin_bootstrap(&$admin_areas)
{
    global $sourcedir, $modSettings, $txt, $context, $scripturl;
    // Load the main admin language files and any needed for SD plugins in the admin panel.
    require_once $sourcedir . '/sd_source/SimpleDesk-Admin.php';
    shd_load_language('sd_language/SimpleDeskAdmin');
    shd_load_plugin_files('hdadmin');
    shd_load_plugin_langfiles('hdadmin');
    // Now add the main SimpleDesk menu
    if (!empty($modSettings['helpdesk_active'])) {
        // The helpdesk action log
        if (empty($modSettings['shd_disable_action_log'])) {
            $admin_areas['maintenance']['areas']['logs']['subsections']['helpdesklog'] = array($txt['shd_admin_helpdesklog'], 'admin_forum', 'url' => $scripturl . '?action=admin;area=helpdesk_info;sa=actionlog');
        }
        // The main menu
        $admin_areas['helpdesk_info'] = array('title' => $txt['shd_helpdesk'], 'enabled' => allowedTo('admin_forum') || shd_allowed_to('admin_helpdesk', 0), 'areas' => array('helpdesk_info' => array('label' => $txt['shd_admin_info'], 'file' => 'sd_source/SimpleDesk-Admin.php', 'icon' => 'shd/simpledesk.png', 'function' => 'shd_admin_main', 'subsections' => array('main' => array($txt['shd_admin_info']), 'actionlog' => array($txt['shd_admin_actionlog'], 'enabled' => empty($modSettings['shd_disable_action_log'])), 'support' => array($txt['shd_admin_support']))), 'helpdesk_options' => array('label' => $txt['shd_admin_options'], 'file' => 'sd_source/SimpleDesk-Admin.php', 'icon' => 'shd/options.png', 'function' => 'shd_admin_main', 'subsections' => array('display' => array($txt['shd_admin_options_display']), 'posting' => array($txt['shd_admin_options_posting']), 'admin' => array($txt['shd_admin_options_admin']), 'standalone' => array($txt['shd_admin_options_standalone']), 'actionlog' => array($txt['shd_admin_options_actionlog']), 'notifications' => array($txt['shd_admin_options_notifications']))), 'helpdesk_cannedreplies' => array('label' => $txt['shd_admin_cannedreplies'], 'file' => 'sd_source/SimpleDesk-Admin.php', 'icon' => 'shd/cannedreplies.png', 'function' => 'shd_admin_main', 'subsections' => array()), 'helpdesk_customfield' => array('label' => $txt['shd_admin_custom_fields'], 'file' => 'sd_source/SimpleDesk-Admin.php', 'icon' => 'shd/custom_fields.png', 'function' => 'shd_admin_main', 'subsections' => array()), 'helpdesk_depts' => array('label' => $txt['shd_admin_departments'], 'file' => 'sd_source/SimpleDesk-Admin.php', 'icon' => 'shd/departments.png', 'function' => 'shd_admin_main', 'subsections' => array()), 'helpdesk_permissions' => array('label' => $txt['shd_admin_permissions'], 'file' => 'sd_source/SimpleDesk-Admin.php', 'icon' => 'shd/permissions.png', 'function' => 'shd_admin_main', 'subsections' => array()), 'helpdesk_plugins' => array('label' => $txt['shd_admin_plugins'], 'file' => 'sd_source/SimpleDesk-Admin.php', 'icon' => 'shd/plugins.png', 'function' => 'shd_admin_main', 'subsections' => array()), 'helpdesk_maint' => array('label' => $txt['shd_admin_maint'], 'file' => 'sd_source/SimpleDesk-Admin.php', 'icon' => 'shd/maintenance.png', 'function' => 'shd_admin_main', 'subsections' => array('main' => array($txt['shd_admin_maint']), 'search' => array($txt['shd_maint_search_settings'])))));
        // Now engage any hooks.
        call_integration_hook('shd_hook_adminmenu', array(&$admin_areas));
    }
}
Example #4
0
/**
 *	Begins SimpleDesk general processing.
 *
 *	Several things are done here, the results of which are unilaterally assumed by all other SimpleDesk functions.
 *	- work out which departments are applicable, and which department we are currently in (as far as possible)
 *	- set up general navigation
 *	- see if the URL or POST data contains a ticket, if so sanitise and store that value
 *	- see if a msg was specified in the URL, if so identify the relevant ticket
 *	- add in the helpdesk CSS file
 *	- identify the sub action to direct them to, then send them on their way.
 *
 *	@since 1.0
*/
function shd_main()
{
    global $context, $txt, $settings, $sourcedir, $modSettings, $scripturl, $user_profile, $user_info, $smcFunc;
    // Basic sanity stuff
    if (!$modSettings['helpdesk_active']) {
        fatal_lang_error('shd_inactive', false);
    }
    // Let's be sneaky. Can they only access one department? If they can only access one department, put them there and make a note of it for later.
    $depts = shd_allowed_to('access_helpdesk', false);
    $context['shd_multi_dept'] = true;
    if (count($depts) == 1) {
        $_REQUEST['dept'] = $depts[0];
        $context['shd_multi_dept'] = false;
    } elseif (empty($_REQUEST['dept']) && !empty($context['queried_dept']) && in_array($context['queried_dept'], $depts)) {
        $_REQUEST['dept'] = $context['queried_dept'];
    }
    $context['shd_department'] = isset($_REQUEST['dept']) && in_array($_REQUEST['dept'], $depts) ? (int) $_REQUEST['dept'] : 0;
    $context['shd_dept_link'] = !empty($context['shd_department']) && $context['shd_multi_dept'] ? ';dept=' . $context['shd_department'] : '';
    shd_is_allowed_to('access_helpdesk', $context['shd_department']);
    // If we know the department up front, we probably should get it now. Tickets themselves will deal with this but most other places won't.
    // Note that we may already have loaded this if we went and got the department id earlier, but not always.
    if (!empty($context['shd_department']) && $context['shd_multi_dept'] && empty($context['shd_dept_name'])) {
        $query = $smcFunc['db_query']('', '
			SELECT dept_name
			FROM {db_prefix}helpdesk_depts
			WHERE id_dept = {int:dept}', array('dept' => $context['shd_department']));
        list($context['shd_dept_name']) = $smcFunc['db_fetch_row']($query);
        $smcFunc['db_free_result']($query);
    }
    // Load stuff: preferences the core template - and any hook-required files
    $context['shd_preferences'] = shd_load_user_prefs();
    $context['shd_home'] = 'action=helpdesk;sa=main';
    loadTemplate('sd_template/SimpleDesk');
    shd_load_plugin_files('helpdesk');
    shd_load_plugin_langfiles('helpdesk');
    // List of sub actions.
    $subactions = array('main' => array(null, 'shd_main_helpdesk'), 'dept' => array(null, 'shd_main_dept'), 'viewblock' => array(null, 'shd_view_block'), 'ticket' => array('SimpleDesk-Display.php', 'shd_view_ticket'), 'newticket' => array('SimpleDesk-Post.php', 'shd_post_ticket'), 'editticket' => array('SimpleDesk-Post.php', 'shd_post_ticket'), 'saveticket' => array('SimpleDesk-Post.php', 'shd_save_post'), 'reply' => array('SimpleDesk-Post.php', 'shd_post_reply'), 'savereply' => array('SimpleDesk-Post.php', 'shd_save_post'), 'editreply' => array('SimpleDesk-Post.php', 'shd_post_reply'), 'markunread' => array('SimpleDesk-MiscActions.php', 'shd_ticket_unread'), 'assign' => array('SimpleDesk-Assign.php', 'shd_assign'), 'assign2' => array('SimpleDesk-Assign.php', 'shd_assign2'), 'movedept' => array('SimpleDesk-MoveDept.php', 'shd_movedept'), 'movedept2' => array('SimpleDesk-MoveDept.php', 'shd_movedept2'), 'resolveticket' => array('SimpleDesk-MiscActions.php', 'shd_ticket_resolve'), 'relation' => array('SimpleDesk-MiscActions.php', 'shd_ticket_relation'), 'ajax' => array('SimpleDesk-AjaxHandler.php', 'shd_ajax'), 'privacychange' => array('SimpleDesk-MiscActions.php', 'shd_privacy_change_noajax'), 'urgencychange' => array('SimpleDesk-MiscActions.php', 'shd_urgency_change_noajax'), 'closedtickets' => array(null, 'shd_closed_tickets'), 'recyclebin' => array(null, 'shd_recycle_bin'), 'tickettotopic' => array('SimpleDesk-TicketTopicMove.php', 'shd_tickettotopic'), 'tickettotopic2' => array('SimpleDesk-TicketTopicMove.php', 'shd_tickettotopic2'), 'topictoticket' => array('SimpleDesk-TicketTopicMove.php', 'shd_topictoticket'), 'topictoticket2' => array('SimpleDesk-TicketTopicMove.php', 'shd_topictoticket2'), 'permadelete' => array('SimpleDesk-Delete.php', 'shd_perma_delete'), 'deleteticket' => array('SimpleDesk-Delete.php', 'shd_ticket_delete'), 'deletereply' => array('SimpleDesk-Delete.php', 'shd_reply_delete'), 'deleteattach' => array('SimpleDesk-Delete.php', 'shd_attach_delete'), 'restoreticket' => array('SimpleDesk-Delete.php', 'shd_ticket_restore'), 'restorereply' => array('SimpleDesk-Delete.php', 'shd_reply_restore'), 'emaillog' => array('SimpleDesk-Notifications.php', 'shd_notify_popup'), 'notify' => array('SimpleDesk-Notifications.php', 'shd_notify_ticket_options'), 'search' => array('SimpleDesk-Search.php', 'shd_search'), 'search2' => array('SimpleDesk-Search.php', 'shd_search2'));
    // Navigation menu
    $context['navigation'] = array('main' => array('text' => 'shd_home', 'lang' => true, 'url' => $scripturl . '?action=helpdesk;sa=main'), 'dept' => array('text' => 'shd_departments', 'test' => 'shd_multi_dept', 'lang' => true, 'url' => $scripturl . '?action=helpdesk;sa=dept'), 'newticket' => array('text' => 'shd_new_ticket', 'test' => 'can_new_ticket', 'lang' => true, 'url' => $scripturl . '?action=helpdesk;sa=newticket' . $context['shd_dept_link']), 'newticketproxy' => array('text' => 'shd_new_ticket_proxy', 'test' => 'can_proxy_ticket', 'lang' => true, 'url' => $scripturl . '?action=helpdesk;sa=newticket;proxy' . $context['shd_dept_link']), 'closedtickets' => array('text' => 'shd_tickets_closed', 'test' => 'can_view_closed', 'lang' => true, 'url' => $scripturl . '?action=helpdesk;sa=closedtickets' . $context['shd_dept_link']), 'recyclebin' => array('text' => 'shd_recycle_bin', 'test' => 'can_view_recycle', 'lang' => true, 'url' => $scripturl . '?action=helpdesk;sa=recyclebin' . $context['shd_dept_link']), 'search' => array('text' => 'shd_search_menu', 'test' => 'can_shd_search', 'lang' => true, 'url' => $scripturl . '?action=helpdesk;sa=search'), 'back' => array('text' => 'shd_back_to_hd', 'test' => 'display_back_to_hd', 'lang' => true, 'url' => $scripturl . '?' . $context['shd_home'] . $context['shd_dept_link']), 'options' => array('text' => 'shd_options', 'test' => 'can_view_options', 'lang' => true, 'url' => $scripturl . '?action=profile;area=hd_prefs'));
    // Build the link tree.
    $context['linktree'][] = array('url' => $scripturl . '?action=helpdesk;sa=main', 'name' => $txt['shd_helpdesk']);
    if (!$context['shd_multi_dept']) {
        $context['linktree'][] = array('url' => $scripturl . '?' . $context['shd_home'], 'name' => $txt['shd_linktree_tickets']);
    }
    // See if a ticket has been specified, like $topic can be.
    if (!empty($_REQUEST['ticket'])) {
        if (strpos($_REQUEST['ticket'], '.') === false) {
            $context['ticket_id'] = (int) $_REQUEST['ticket'];
            $context['ticket_start'] = 0;
        } else {
            list($context['ticket_id'], $context['ticket_start']) = explode('.', $_REQUEST['ticket']);
            $context['ticket_id'] = (int) $context['ticket_id'];
            if (!is_numeric($context['ticket_start'])) {
                // Let's see if it's 'new' first. If it is, great, we'll figure out the new point then throw it at the next one.
                if (substr($context['ticket_start'], 0, 3) == 'new') {
                    $query = shd_db_query('', '
						SELECT IFNULL(hdlr.id_msg, -1) + 1 AS new_from
						FROM {db_prefix}helpdesk_tickets AS hdt
							LEFT JOIN {db_prefix}helpdesk_log_read AS hdlr ON (hdlr.id_ticket = {int:ticket} AND hdlr.id_member = {int:member})
						WHERE {query_see_ticket}
							AND hdt.id_ticket = {int:ticket}
						LIMIT 1', array('member' => $user_info['id'], 'ticket' => $context['ticket_id']));
                    list($new_from) = $smcFunc['db_fetch_row']($query);
                    $smcFunc['db_free_result']($query);
                    $context['ticket_start'] = 'msg' . $new_from;
                    $context['ticket_start_newfrom'] = $new_from;
                }
                if (substr($context['ticket_start'], 0, 3) == 'msg') {
                    $virtual_msg = (int) substr($context['ticket_start'], 3);
                    $query = shd_db_query('', '
						SELECT COUNT(hdtr.id_msg)
						FROM {db_prefix}helpdesk_ticket_replies AS hdtr
							INNER JOIN {db_prefix}helpdesk_tickets AS hdt ON (hdtr.id_ticket = hdt.id_ticket)
						WHERE {query_see_ticket}
							AND hdtr.id_ticket = {int:ticket}
							AND hdtr.id_msg > hdt.id_first_msg
							AND hdtr.id_msg < {int:virtual_msg}' . (!isset($_GET['recycle']) ? '
							AND hdtr.message_status = {int:message_notdel}' : ''), array('ticket' => $context['ticket_id'], 'virtual_msg' => $virtual_msg, 'message_notdel' => MSG_STATUS_NORMAL));
                    list($context['ticket_start']) = $smcFunc['db_fetch_row']($query);
                    $smcFunc['db_free_result']($query);
                }
            } else {
                $context['ticket_start'] = (int) $context['ticket_start'];
                // it IS numeric but let's make sure it's the right kind of number
                $context['ticket_start_natural'] = true;
            }
        }
    }
    if (empty($context['ticket_start_newfrom'])) {
        $context['ticket_start_newfrom'] = empty($context['ticket_start']) ? 0 : $context['ticket_start'];
    }
    // Do we have just a message id? We can get the ticket from that - but only if we don't already have a ticket id!
    $_REQUEST['msg'] = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
    if (!empty($_REQUEST['msg']) && empty($context['ticket_id'])) {
        $query = shd_db_query('', '
			SELECT hdt.id_ticket, hdtr.id_msg
			FROM {db_prefix}helpdesk_ticket_replies AS hdtr
				INNER JOIN {db_prefix}helpdesk_tickets AS hdt ON (hdtr.id_ticket = hdt.id_ticket)
			WHERE {query_see_ticket}
				AND hdtr.id_msg = {int:msg}', array('msg' => $_REQUEST['msg']));
        if ($row = $smcFunc['db_fetch_row']($query)) {
            $context['ticket_id'] = (int) $row[0];
        }
        $smcFunc['db_free_result']($query);
    }
    $context['items_per_page'] = 10;
    $context['start'] = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
    // Load the custom CSS.
    if (empty($context['html_headers'])) {
        $context['html_headers'] = '';
    }
    $context['html_headers'] .= '
	<link rel="stylesheet" type="text/css" href="' . (file_exists($settings['theme_dir'] . '/css/helpdesk.css') ? $settings['theme_url'] . '/css/helpdesk.css' : $settings['default_theme_url'] . '/css/helpdesk.css') . '?' . $context['shd_css_version'] . '" />
	<script type="text/javascript" src="' . $settings['default_theme_url'] . '/scripts/helpdesk.js?' . $context['shd_scripts_version'] . '"></script>';
    // A custom css?
    if (file_exists($settings['default_theme_url'] . '/css/helpdesk_custom.css')) {
        $context['html_headers'] .= '
	<link rel="stylesheet" type="text/css" href="' . $settings['default_theme_url'] . '/css/helpdesk_custom.css?' . $context['shd_css_version'] . '" />';
    }
    if (file_exists($settings['theme_dir'] . '/css/helpdesk_custom.css')) {
        $context['html_headers'] .= '
	<link rel="stylesheet" type="text/css" href="' . $settings['theme_url'] . '/css/helpdesk_custom.css?' . $context['shd_css_version'] . '" />';
    }
    // Int hooks - after we basically set everything up (so it's manipulatable by the hook, but before we do the last bits of finalisation)
    call_integration_hook('shd_hook_helpdesk', array(&$subactions));
    // What are we doing?
    $_REQUEST['sa'] = !empty($_REQUEST['sa']) && isset($subactions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'main';
    $context['sub_action'] = $subactions[$_REQUEST['sa']];
    $context['can_new_ticket'] = shd_allowed_to('shd_new_ticket', $context['shd_department']);
    $context['can_proxy_ticket'] = $context['can_new_ticket'] && shd_allowed_to('shd_post_proxy', $context['shd_department']);
    $context['can_view_closed'] = shd_allowed_to(array('shd_view_closed_own', 'shd_view_closed_any'), $context['shd_department']);
    $context['can_view_recycle'] = shd_allowed_to('shd_access_recyclebin', $context['shd_department']);
    $context['display_back_to_hd'] = !in_array($_REQUEST['sa'], array('main', 'viewblock', 'recyclebin', 'closedtickets', 'dept'));
    $context['can_shd_search'] = shd_allowed_to('shd_search', 0);
    $context['can_view_options'] = shd_allowed_to(array('shd_view_preferences_own', 'shd_view_preferences_any'), 0);
    // Highlight the correct button.
    if (isset($context['navigation'][$_REQUEST['sa']])) {
        $context['navigation'][$_REQUEST['sa']]['active'] = true;
    }
    // Send them away.
    if ($context['sub_action'][0] !== null) {
        require $sourcedir . '/sd_source/' . $context['sub_action'][0];
    }
    $context['sub_action'][1]();
    // Maintenance mode? If it were, the helpdesk is considered inactive for the purposes of everything to all but those without admin-helpdesk rights - but we must have them if we're here!
    if (!empty($modSettings['shd_maintenance_mode']) && $_REQUEST['sa'] != 'ajax') {
        $context['template_layers'][] = 'shd_maintenance';
    }
    call_integration_hook('shd_hook_after_main');
}
Example #5
0
/**
 *	The start point for all interaction with the SimpleDesk administration area.
 *
 *	Enforces that users attempting to access the area have either forum or helpdesk administrative privileges, loads the SimpleDesk
 *	administrative CSS and Javascript and promptly directs users to the specific function for the task they are performing.
 *
 *	@since 1.0
*/
function shd_admin_main()
{
    global $context, $scripturl, $sourcedir, $settings, $txt, $modSettings, $scripturl;
    shd_init();
    shd_load_language('sd_language/SimpleDeskAdmin');
    // Kick them in the kneecaps!
    if (!shd_allowed_to('admin_helpdesk', 0)) {
        isAllowedTo('admin_forum');
    }
    // Templates and stuff (like hook files)
    loadTemplate('sd_template/SimpleDesk-Admin');
    $context['template_layers'][] = 'shd_nojs';
    $context['shd_preferences'] = shd_load_user_prefs();
    shd_load_plugin_files('hdadmin');
    shd_load_plugin_langfiles('hdadmin');
    // Load some extra CSS
    $context['html_headers'] .= '
	<link rel="stylesheet" type="text/css" href="' . $settings['default_theme_url'] . '/css/helpdesk_admin.css?' . $context['shd_css_version'] . '" />
	<link rel="stylesheet" type="text/css" href="' . $settings['default_theme_url'] . '/css/helpdesk.css?' . $context['shd_css_version'] . '" />
	<script type="text/javascript" src="' . $settings['default_theme_url'] . '/scripts/helpdesk_admin.js?' . $context['shd_scripts_version'] . '"></script>';
    $context['page_title'] = $txt['shd_admin_title'];
    // We need this for later
    require_once $sourcedir . '/ManageServer.php';
    // Create some subactions
    $subActions = array('helpdesk_info' => array(null, 'shd_admin_info'), 'helpdesk_options' => array(null, 'shd_admin_options'), 'helpdesk_cannedreplies' => array('SimpleDesk-AdminCannedReplies.php', 'shd_admin_canned'), 'helpdesk_customfield' => array('SimpleDesk-AdminCustomField.php', 'shd_admin_custom'), 'helpdesk_depts' => array('SimpleDesk-AdminDepartments.php', 'shd_admin_departments'), 'helpdesk_permissions' => array('SimpleDesk-AdminPermissions.php', 'shd_admin_permissions'), 'helpdesk_plugins' => array('SimpleDesk-AdminPlugins.php', 'shd_admin_plugins'), 'helpdesk_maint' => array('SimpleDesk-AdminMaint.php', 'shd_admin_maint'));
    // Int hooks - after we basically set everything up (so it's manipulatable by the hook, but before we do the last bits of finalisation)
    call_integration_hook('shd_hook_hdadmin', array(&$subActions));
    // Make sure we can find a subaction. If not set, default to info
    $_REQUEST['area'] = isset($_REQUEST['area']) && isset($subActions[$_REQUEST['area']]) ? $_REQUEST['area'] : 'helpdesk_info';
    $context['sub_action'] = $_REQUEST['area'];
    if (!empty($subActions[$_REQUEST['area']][0])) {
        require_once $sourcedir . '/sd_source/' . $subActions[$_REQUEST['area']][0];
    }
    // Call our subaction
    if ($_REQUEST['area'] == 'helpdesk_options') {
        $subActions[$_REQUEST['area']][1](false);
    } else {
        $subActions[$_REQUEST['area']][1]();
    }
    // Important ACS666 check up.
    if (isset($_REQUEST['cookies'])) {
        shd_do_important();
    }
    // Maintenance mode? If it were, the helpdesk is considered inactive for the purposes of everything to all but those without admin-helpdesk rights - but we must have them if we're here!
    if (!empty($modSettings['shd_maintenance_mode'])) {
        loadTemplate('sd_template/SimpleDesk');
        $temp_layers = $context['template_layers'];
        $context['template_layers'] = array();
        $added = false;
        foreach ($temp_layers as $layer) {
            $context['template_layers'][] = $layer;
            if ($layer == 'body') {
                $context['template_layers'][] = 'shd_maintenance';
                $added = true;
            }
        }
        // Well, we tried to add it as near the top as possible, but not all themes use the standard body layer.
        if (!$added) {
            $context['template_layers'][] = 'shd_maintenance';
        }
    }
    // Also, fix up the link tree while we're here.
    $linktree = $context['linktree'];
    $context['linktree'] = array();
    foreach ($linktree as $linktreeitem) {
        $context['linktree'][] = $linktreeitem;
        if ($linktreeitem['url'] == $scripturl . '?action=admin') {
            $context['linktree'][] = array('url' => $scripturl . '?action=admin;area=helpdesk_info', 'name' => $txt['shd_helpdesk']);
        }
    }
}