function _support_assigned in Support Ticketing System 6
Same name and namespace in other branches
- 7 support.module \_support_assigned()
Get list of available users to assign ticket to.
5 calls to _support_assigned()
- support_comment in ./
support.module - Implementation of hook_comment().
- support_mailcmd_support_fetch_message_alter in support_mailcmd/
support_mailcmd.module - Implementation of hook_support_fetch_message_alter().
- support_page_form in ./
support.module - Display tickets
- support_status_form in ./
support.module - Generate form for adding update to ticket. Enhances comment_form adding a ticket status bar.
- support_subscribe_form in ./
support.module - Provide option to subscribe/unsubscribe from ticket notification emails.
File
- ./
support.module, line 2340 - support.module
Code
function _support_assigned($assigned, $node, $limit = 9999) {
global $user;
static $available = array();
$counter = 0;
if (!$limit) {
return FALSE;
}
if (!isset($node->nid)) {
$node->nid = 0;
}
if (!isset($available["{$assigned}-{$node->nid}"])) {
if ($assigned && $assigned != $user->uid) {
$account = user_load($assigned);
$available["{$assigned}-{$node->nid}"][$account->uid] = $account->name;
$counter++;
}
// can always re-assign ticket to self
$available["{$assigned}-{$node->nid}"][$user->uid] = $user->name;
$counter++;
if (is_numeric($node->client) && (user_access('administer support') || user_access('can assign tickets to any user'))) {
$roles = array();
$client = db_result(db_query('SELECT name FROM {support_client} WHERE clid = %d', $node->client));
// retrieve all roles giving permission to access current tickets
$result = db_query("SELECT rid FROM {permission} WHERE perm LIKE '%%%s%%' OR perm LIKE '%%%s%%'", "access {$client} tickets", 'administer support');
while ($role = db_fetch_object($result)) {
$roles[$role->rid] = $role->rid;
}
// retrieve all users in appropriate roles
$accounts = array();
$all = FALSE;
foreach ($roles as $rid) {
if ($rid == DRUPAL_AUTHENTICATED_RID) {
$all = TRUE;
$result = db_query_range('SELECT uid FROM {users} WHERE status = 1', 0, $limit);
}
else {
$result = db_query_range('SELECT r.uid FROM {users_roles} r LEFT JOIN {users} u ON r.uid = u.uid WHERE r.rid = %d AND u.status = 1', $rid, 0, $limit);
}
while ($account = db_fetch_object($result)) {
$accounts[$account->uid] = $account->uid;
$counter++;
if (!$limit || $counter > $limit) {
return FALSE;
}
}
// we've already retrieved all active users, no need to search
// additional roles
if ($all) {
break;
}
}
// load users and allow them to be assigned
foreach ($accounts as $uid) {
$account = user_load(array(
'uid' => $uid,
));
$available["{$assigned}-{$node->nid}"][$account->uid] = $account->name;
}
// Filter uid1 if support_filter_uid1 enabled; however, don't filter if
// the ticket is already assigned to uid1, or current user is uid1.
if ($user->uid != 1 && $assigned != 1 && variable_get('support_filter_uid1', FALSE)) {
unset($available["{$assigned}-{$node->nid}"][1]);
}
}
// sort by name
asort($available["{$assigned}-{$node->nid}"]);
// can only unassign tickets if assigned to self, or have admin permissions
// (always put this at the top of the array)
if (!$assigned || $assigned == $user->uid || user_access('can assign tickets to any user') || user_access('administer support')) {
$available["{$assigned}-{$node->nid}"] = array(
0 => ' - ' . t('not assigned') . ' -',
) + $available["{$assigned}-{$node->nid}"];
}
}
return $available["{$assigned}-{$node->nid}"];
}