Results 1 to 2 of 2

Thread: Filter User Drop Down

  1. #1
    michaelest is offline Sugar Community Member
    Join Date
    Apr 2007
    Posts
    37

    Default Filter User Drop Down

    I have a need to mark certain users as "qualified" to handle certain issues.
    I've successfully added a custom field (check box -' is_qualified') to the USER module. I've tested it and the info is saved and retrieved from the database just fine.

    Now I want to filter the user drop down based on the status of one of those check boxes. How can I filter the user drop down to show only those users that are "qualified?"

    I'm using the code found on wiki to create the user drop down....
    get_select_options_with_id(get_user_array(FALSE), $assigned_user_id))
    Should I work with this or is there another way?

    Thanks.
    Last edited by michaelest; 2007-06-21 at 04:39 PM.

  2. #2
    michaelest is offline Sugar Community Member
    Join Date
    Apr 2007
    Posts
    37

    Default Re: Filter User Drop Down

    I think I just answered my own question. Here's what I did.

    I created a new function based off the get_user_array function in /include/Utils.php.

    The custom function looks like this...
    //begin custom code by michaelest
    function get_user_is_qualified($add_blank=true, $status="Active", $assigned_user="", $use_real_name=false, $user_name_begins = null, $is_group=' AND is_group=0 ') { //'function get_user_is_qualified' instead of 'function get_user_array'
    global $locale;
    global $sugar_config;

    if(empty($locale)) {
    require_once('include/Localization/Localization.php');
    $locale = new Localization();
    }
    $db = & PearDatabase::getInstance();
    $temp_result = Array();
    // Including deleted users for now.
    if (empty($status)) {
    $query = "SELECT id, first_name, last_name, user_name from users, users_cstm WHERE users.id=users_cstm.id_c AND 1=1".$is_group; //I look up in two tables 'users' and 'users_cstm'
    }
    else {
    $query = "SELECT id, first_name, last_name, user_name from users , users_cstm WHERE users.id=users_cstm.id_c AND status='$status'".$is_group; //I look up in two tables 'users' and 'users_cstm'
    }

    if (!empty($user_name_begins)) {
    $query .= " AND user_name LIKE '$user_name_begins%' ";
    }
    if (!empty($assigned_user)) {
    $query .= " OR id='$assigned_user'";
    }
    $query = $query.' AND users_cstm.is_qualified_c=1'; //look in 'users_cstm' to match users who 'is_qualified=1'
    $query = $query.' ORDER BY user_name ASC';

    $GLOBALS['log']->debug("get_user_array query: $query");
    $result = $db->query($query, true, "Error filling in user array: ");

    if ($add_blank==true) {
    // Add in a blank row
    $temp_result[''] = '';
    }

    // Get the id and the name.
    while($row = $db->fetchByAssoc($result)) {
    if($use_real_name == true || showFullName()) {
    if(isset($row['last_name'])) { // cn: we will ALWAYS have both first_name and last_name (empty value if blank in db)
    $temp_result[$row['id']] = $locale->getLocaleFormattedName($row['first_name'],$row['last_name']);
    } else {
    $temp_result[$row['id']] = $row['user_name'];
    }
    } else {
    $temp_result[$row['id']] = $row['user_name'];
    }
    }

    $user_array = $temp_result;
    //set_register_value('user_array', $add_blank. $status . $assigned_user, $temp_result);



    return $user_array;
    }
    //end custom by michaelest {
    Then, in my 'editview.php' file, I add a modified call using the code that calls the users drop down...
    $xtpl->assign("IS_QUALIFIED_C", get_select_options_with_id(get_user_is_qualified() , $focus->is_qualified_c));
    //this calls the custom function in utils.php and only those users with the 'is_qualified' flag set are listed in the drop down
    Now I just have to work on saving the data successfully.

    Just to be complete, you need to add the field to your editview.html file, something like this...
    <td class="dataLabel"><span sugar='slot29'>{MOD.LBL_IS_QUALIFIED_C}</span sugar='slot'></td>
    <td class="dataField"><span sugar='slot29b'><select tabindex='2' name="is_qualified_c" id='is_qualified_c'>{IS_QUALIFIED_C}</select></span sugar='slot'></td>
    Make sure you've updated your vardefs.php and en_us.lang.php files.

    I'll post more when I have it completed.

    - MichaelEst[
    Last edited by michaelest; 2007-06-22 at 07:59 AM. Reason: clarity

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Email and user setup confusion
    By Buckie in forum Help
    Replies: 1
    Last Post: 2006-01-18, 05:41 PM
  2. what is group user and portal user
    By bmk in forum General Discussion
    Replies: 0
    Last Post: 2006-01-11, 09:37 AM
  3. Create User Problems
    By morebob in forum General Discussion
    Replies: 2
    Last Post: 2005-06-23, 01:30 AM
  4. Cannot Login
    By Dillon in forum Help
    Replies: 16
    Last Post: 2004-10-13, 02:52 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •