SimpleDesk API
Procedural File: Subs-SimpleDesk.php
Source Location: /source/Subs-SimpleDesk.phpThis file handles key functions for SimpleDesk that can be called on every page load, such as the custom query function to handle ticket visibility, the counter for active tickets in the menu header, or the action log.
Tags:
- since
- 1.0
Contains the following functions:
shd_allowed_to [line 521]
bool shd_allowed_to (
mixed $permission )
Determines if a user has a given permission within the system.
All SimpleDesk-specific permissions should be checked with this function. Any other permission check that is not specifically SimpleDesk-related should use allowedTo instead.
Tags:
- see
- shd_is_allowed_to()
- todo
- This function will likely be expanded to not use SMF's allowedTo function eventually, as its requirements will outgrow or replace conventional SMF permissions.
- since
- 1.0
Parameters
- mixed $permission
- A string or array of strings naming a permission or permissions that wish to be examined
Return value
Returns a type bool. True if any of the permission(s) outlined in $permission are true.shd_can_alter_urgency [line 254]
void shd_can_alter_urgency (
int $urgency, bool $ticket_starter, bool $closed, bool $deleted )
Determines if the current user can raise/lower the urgency of a ticket.
This function identifies whether the current user can raise or lower the urgency of a ticket based on the current urgency of the ticket and whether it is their ticket; this is used in the ticket display as well as the actions linked directly to modifying urgency (both AJAXively and non AJAXively)
Tags:
- see
- shd_urgency_change_noajax()
- since
- 1.0
Parameters
- int $urgency
- The current urgency of a ticket as an integer
- bool $ticket_starter
- Whether the user in question is the starter of the ticket (instead of querying to establish that, that detail should already be known to the calling function)
- bool $closed
- Whether the ticket is currently closed or not
- bool $deleted
- Whether the ticket is currently closed or not
Return value
This function has no return value.shd_clear_active_tickets [line 167]
void shd_clear_active_tickets (
[ $id = 0] )
Clears the cache of active tickets for the menu item.
shd_get_active_tickets() generates the number of active tickets for the user display, and caches it for 180 seconds normally. This function clears the cache and should be called whenever any operation modifies the state of a ticket.
Tags:
- see
- shd_get_active_tickets()
- since
- 1.0
Parameters
- $id
Return value
This function has no return value.shd_count_helpdesk_tickets [line 311]
int shd_count_helpdesk_tickets (
[string $status = ''], [bool $is_staff = false] )
Queries the database to find the number of applicable tickets
This function collects counts for the different states of tickets (new, with staff, with user, etc) of all the tickets visible to the user, and returns a selection of that dataset based on the values provided to $status and $is_staff.
Tags:
- since
- 1.0
Parameters
- string $status
- The relevant count of tickets to return:
- 'open': All tickets currently open that the user can see
- 'assigned': All tickets assigned to the current user
- 'new': All the new tickets that the user can see
- 'staff': All the tickets currently with staff (varies for staff vs user; user count here includes 'new' tickets)
- 'with_user': All the tickets pending user comment
- 'closed': All the tickets the user can see that are resolved
- 'recycled': All the tickets the user can see that are currently in the recycle bin
- 'withdeleted': All the tickets that have at least one deleted reply
- '' or unspecified: Return the total of all tickets in the helpdesk (subject to visibility)
- bool $is_staff
- If the user in question is staff or not.
Return value
Returns a type int. Number of applicable tickets.shd_db_query [line 48]
resource shd_db_query (
string $identifier, string $db_string, [array $db_values = array()], [resource $connection = null] )
Query wrapper around $smcFunc['db_query'] for helpdesk specific operations.
This function provides a basic wrapper around SMF's internal $smcFunc['db_query'] function, adding the parameter {query_see_ticket} to it, specifically so that ticket visibility can be enforced in a query without being aware of the specific rules for the user.
If not previously loaded, user permissions are loaded with shd_load_user_perms().
Tags:
- see
- shd_load_user_perms()
- since
- 1.0
Parameters
- string $identifier
- SMF-style query identifier for database backend-specific replacements
- string $db_string
- Standard SMF 2.0 style database query, including {query_see_ticket} if appropriate
- array $db_values
- Standard SMF 2.0 style hash map of parameters to inject into the query
- resource $connection
- A database connection variable, if supplied, to override the one used by SMF by default
Return value
Returns a type resource. Standard database query resource, suitable for processing with other $smcFunc['db_*'] functionsshd_determine_status [line 614]
int shd_determine_status (
string $action, [int $starter_id = 0], [int $replier_id = 0], [int $replies = -1] )
Establishes the next change of status of a ticket.
Tickets invariably have multiple changes of status during their life. All actions that could change a ticket's status should call here, even if it is a straight forward, one-route-only change of status since it is possible we could end up giving the user a choice one day over how statuses work, so we should route everything through here all the time.
Tags:
- since
- 1.0
Parameters
- string $action
- (required), represents the action carried out by the calling function Known values: new, resolve, unresolve, deleteticket, restoreticket, deletereply, restorereply, reply, merge, topictoticket (new is default)
- int $starter_id
- Numeric id of the ticket's starter (should be provided)
- int $replier_id
- Numeric id of the ticket's last reply author (should be provided)
- int $replies
- Number of replies in the ticket (should be provided)
Return value
Returns a type int. Returns an integer value that corresponds to the ticket's status, relating to one of the TICKET_STATUS states.shd_format_text [line 485]
string shd_format_text (
string $text, [bool $smileys = true], [string $cache = ''] )
Formats a string for bbcode and/or smileys.
Formatting is done according to the supplied settings and the master administration settings.
Tags:
- since
- 1.0
Parameters
- string $text
- Raw text with optional bbcode formatting
- bool $smileys
- Whether smileys should be used; this is not an override to the master administration setting of whether to use smileys or not, and that takes precedence.
- string $cache
- If specified, this will provide the cache'd id that SMF should use to cache the output if it is suitably large.
Return value
Returns a type string. Will return $text as processed for bbcode (if $modSettings['shd_allow_ticket_bbc'] permits) and smileys (if $modSettings['shd_allow_ticket_smileys'] and $smileys permits)shd_get_active_tickets [line 102]
string shd_get_active_tickets (
)
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 shd_clear_active_tickets() function.
Tags:
- see
- shd_clear_active_tickets()
- since
- 1.0
Return value
Returns a type string. A formatted string containing the language-specific version of "Helpdesk [x]" menu item with the x in boldshd_is_allowed_to [line 539]
void shd_is_allowed_to (
mixed $permission )
Enforces a user having a given permission and returning to a fatal error message if not.
All fatal-level SimpleDesk-specific permissions should be checked with this function. Any other permission check that is not specifically SimpleDesk-related should use isAllowedTo instead. Note that this is a void function because should this fail, SMF execution will be halted.
Tags:
- see
- shd_allowed_to()
- todo
- This function will likely be expanded to not use SMF's allowedTo function eventually, as its requirements will outgrow or replace conventional SMF permissions.
- since
- 1.0
Parameters
- mixed $permission
- A string or array of strings naming a permission or permissions that wish to be examined
Return value
This function has no return value.shd_load_ticket [line 425]
array shd_load_ticket (
[int $ticket = 0] )
Attempts to load a given ticket's data.
This function permission-checks, and throws appropriate errors if no ticket is specified either directly or through URL, or if the ticket is not accessible either through deletion or lack of permissions.
Tags:
- since
- 1.0
Parameters
- int $ticket
- The ticket to use; if none is specified, use the one from $_REQUEST['ticket'], which will have been processed into $context['ticket_id'] if it is available.
Return value
Returns a type array. A large hash map stating many ticket detailsshd_load_user_perms [line 75]
void shd_load_user_perms (
)
Defines user permissions, most importantly concerning ticket visibility
Populates specific parameters in $user_info, mostly to add {} abstract variables in $smcFunc['db_query'] data calls. The foremost one of these is {query_see_ticket}, an SQL clause constructed to ensure ticket visibility is maintained given the active user's permission set.
Tags:
- see
- shd_db_query()
- since
- 1.0
Return value
This function has no return value.shd_log_action [line 196]
void shd_log_action (
string $action, array $params )
Adds an action to the helpdesk internal action log.
This function deals with adding items to the action log maintained by the helpdesk.
Tags:
- see
- shd_load_action_log_entries()
- since
- 1.0
Parameters
- string $action
- Specifies the name of the action to log, which implies the image and language string (log_$action is the name of the image, and $txt['shd_log_$action'] is the string used to express the action, as listed in SimpleDesk-LogAction.english.php.
- array $params
- This is a list of named parameters in a hash array to be used in the language string later.
Return value
This function has no return value.shd_members_allowed_to [line 556]
array shd_members_allowed_to (
mixed $permission )
Identifies all members who hold a given permission.
Currently lists of staff are generated by users who hold shd_staff permission. This function identifies those users through an internal lookup provided by SMF.
Tags:
- see
- shd_allowed_to()
- todo
- This function will likely be expanded to not use SMF's permissions eventually.
- since
- 1.0
Parameters
- mixed $permission
- A string naming a permission that members should hold.
Return value
Returns a type array. Array of zero or more user ids who hold the stated permission.shd_no_expand_pageindex [line 677]
string shd_no_expand_pageindex (
string $base_url, int &$start, int $max_value, int $num_per_page, [bool $flexible_start = false] )
Wrapper function for constructPageIndex to forcibly block the extensible ... item in page indexes
SimpleDesk uses SMF's core page index function in numerous places, but unlike SMF, it often places it in containers that have backgrounds driven by menu_block.png, meaning that they are often fixed in height. Under some circumstances layout can be broken, so this function forcibly ensures the block can never expand to force wrapping.
Tags:
- since
- 1.0
Parameters
- string $base_url
- Form of URL pageindex links should take, using $1%d to represent the start point identifier.
- int &$start
- Position to start. If not a multiple of the number per page, it will be forced to become a multiple.
- int $max_value
- Number of items in total to paginate for.
- int $num_per_page
- Number of items to be shown on a page.
- bool $flexible_start
- Whether a more flexible % option is to be used in the base URL.
Return value
Returns a type string. The constructed page index, without Javascript expander(s).shd_profile_link [line 577]
string shd_profile_link (
string $name, [int $id = 0] )
Generates a profile link given user id and name.
SMF itself has loadMemberData() and loadMemberContext to perform this act, however those two functions are much larger and more complex than we need more often than not, especially when all we want/need is member name (and subsequently profile link)
Since profile links should be based on the view profile permission, we will need to establish that.
Tags:
- since
- 1.0
Parameters
- string $name
- The name to display. This should be a standard SMF type name, which means already sanitised for HTML.
- int $id
- The numeric id of the user we are linking to.



