/** * Defines the helpdesk menu item, including the number of active tickets to be displayed to the user. * * Identifies the number of tickets that a user might be interested in, and generates the menu text for the main menu * to include this; note that the value should be cached through SMF's functions. The cache is also clearable, through * the {@link shd_clear_active_tickets()} function. * * @return string A formatted string containing the language-specific version of "Helpdesk [x]" menu item with the x in bold * @see shd_clear_active_tickets() * @since 1.0 */ function shd_get_active_tickets() { global $modSettings, $user_info, $smcFunc, $context, $txt; if (empty($txt['shd_helpdesk'])) { // provide a last-ditch fallback in the event we can't even find the file; SimpleDesk.{language}.php should be loaded by now (falling back to english if lang-specific doesn't exist) $txt['shd_helpdesk'] = 'Helpdesk'; } if (!$modSettings['helpdesk_active'] || $context['user']['is_guest'] || !empty($context['shd_maintenance_mode']) || !empty($modSettings['shd_hidemenuitem'])) { return $txt['shd_helpdesk']; } // Have we already run on this page? If so we already have the answer. if (!empty($context['active_tickets'])) { return $txt['shd_helpdesk'] . $context['active_tickets']; } // Can we get it from the cache? $temp = cache_get_data('shd_active_tickets_' . $user_info['id'], 180); if ($temp !== null) { list($context['active_tickets'], $context['active_tickets_raw']) = $temp; $context['menu_buttons']['helpdesk']['alttitle'] = $txt['shd_helpdesk'] . !empty($context['active_tickets_raw']) ? ' [' . $context['active_tickets_raw'] . ']' : ''; return $txt['shd_helpdesk'] . $context['active_tickets']; } shd_init(); // Figure out the status(es) that the ticket could be. if (shd_allowed_to('shd_staff', 0)) { $status = array(TICKET_STATUS_NEW, TICKET_STATUS_PENDING_STAFF); } else { $status = array(TICKET_STATUS_PENDING_USER); } // user actually needs to deal with this $query = shd_db_query('', ' SELECT COUNT(id_ticket) FROM {db_prefix}helpdesk_tickets AS hdt WHERE {query_see_ticket} AND status IN ({array_int:status})', array('status' => $status)); $context['active_tickets_raw'] = 0; $row = $smcFunc['db_fetch_row']($query); if (!empty($row[0])) { $context['menu_buttons']['helpdesk']['alttitle'] = $txt['shd_helpdesk'] . ' [' . $row[0] . ']'; $context['active_tickets'] = ' [<strong>' . $row[0] . '</strong>]'; $context['active_tickets_raw'] = $row[0]; // in case you want to do something funky in the theme later? } else { $context['active_tickets'] = ''; } cache_put_data('shd_active_tickets_' . $user_info['id'], array($context['active_tickets'], $context['active_tickets_raw']), 120); return $txt['shd_helpdesk'] . $context['active_tickets']; }
/** * 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']); } } }