--- casetracker.module 2009-03-15 18:27:39.000000000 -0500 +++ ../casetracker2/casetracker.module 2009-05-19 09:58:17.000000000 -0500 @@ -36,6 +36,7 @@ function casetracker_perm() { return array( 'access case tracker', 'administer case tracker', + 'assign cases', ); } @@ -363,7 +364,7 @@ function casetracker_case_form_common(&$ ); } - $options = casetracker_user_options(); + $options = casetracker_user_options($node, user_access('assign_cases')); $form['casetracker']['assign_to'] = array( '#type' => 'textfield', @@ -791,11 +792,22 @@ function casetracker_project_options() { } /** - * API function that returns valid user options. + * API function that returns valid user options. If $permission_to_assign is TRUE, it returns all active users. + * Otherwise, it returns the default assign_to, the current assign_to (if assigned), and the current user. + * + * @param $node + * The case node, used to get the currently assigned user + * @param $permission_to_assign + * Whether or not the user has permission to assign or not + * @returns + * All users if $permission_to_assign == TRUE, otherwise the default assign-to, the current assign_to, + * and the current user. */ -function casetracker_user_options() { +function casetracker_user_options($node = NULL, $permission_to_assign = FALSE) { $group = module_exists('og') ? og_get_group_context() : NULL; $options = array(0 => variable_get('casetracker_default_assign_to', variable_get('anonymous', t('Anonymous')))); + $options[$node->casetracker->assign_to] = db_result(db_query("SELECT name FROM {users} WHERE uid = %d", $node->casetracker->assign_to)); + if($permission_to_assign){ if ($group) { $gid = $group->nid; $results = db_query('SELECT u.uid, u.name FROM {users} u INNER JOIN {og_uid} ou ON u.uid = ou.uid WHERE u.status > 0 AND u.uid > 0 AND ou.nid = %d ORDER BY u.name ASC', $gid); @@ -806,6 +818,12 @@ function casetracker_user_options() { while ($result = db_fetch_object($results)) { $options[$result->uid] = check_plain($result->name); } + } else { + global $user; + if($user->name != $options[0]){ + $options[$user->uid] = $user->name; + } + } return $options; }