Пример #1
0
 public function testAssignedUserName()
 {
     global $locale;
     require_once 'include/Localization/Localization.php';
     $locale = new Localization();
     $testName = $locale->getLocaleFormattedName($this->user->first_name, $this->user->last_name);
     $testTemplate = new EmailTemplate();
     $testTemplate->retrieve($this->emailTemplate->id);
     $this->assertEquals($testName, $testTemplate->assigned_user_name, 'Assert that the assigned_user_name is the locale formatted name value');
 }
Пример #2
0
function get_user_array($add_blank = true, $status = "Active", $assigned_user = "", $use_real_name = false, $user_name_begins = null, $is_group = ' AND portal_only=0 ', $from_cache = true)
{
    global $locale;
    global $sugar_config;
    if (empty($locale)) {
        $locale = new Localization();
    }
    if ($from_cache) {
        $user_array = get_register_value('user_array', $add_blank . $status . $assigned_user);
    }
    if (!isset($user_array)) {
        $db = DBManagerFactory::getInstance();
        $temp_result = array();
        // Including deleted users for now.
        if (empty($status)) {
            $query = "SELECT id, first_name, last_name, user_name from users WHERE 1=1" . $is_group;
        } else {
            $query = "SELECT id, first_name, last_name, user_name from users WHERE status='{$status}'" . $is_group;
        }
        if (!empty($user_name_begins)) {
            $query .= " AND user_name LIKE '{$user_name_begins}%' ";
        }
        if (!empty($assigned_user)) {
            $query .= " OR id='{$assigned_user}'";
        }
        $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;
        if ($from_cache) {
            set_register_value('user_array', $add_blank . $status . $assigned_user, $temp_result);
        }
    }
    return $user_array;
}
 function action_get_userids()
 {
     global $db;
     require_once 'include/Localization/Localization.php';
     $locObject = new Localization();
     //2013-10-04 changed to total with ext 4.* so paging works properly Bug#505
     $returnArray['total'] = $db->getRowCount($db->query('SELECT id, user_name FROM users WHERE deleted = \'0\' AND status = \'Active\' AND user_name like \'' . $_REQUEST['query'] . '%\''));
     //if(isset($_REQUEST['query']) && $_REQUEST['query'] != '')
     //2013-10-04 changed to search also be name fields BUG#506
     $usersResult = $db->query('SELECT id, user_name, first_name, last_name FROM users WHERE deleted = \'0\' AND status = \'Active\' AND (user_name like \'%' . $_REQUEST['query'] . '%\' OR  first_name like \'%' . $_REQUEST['query'] . '%\' OR last_name like \'%' . $_REQUEST['query'] . '%\') LIMIT ' . $_REQUEST['start'] . ',' . $_REQUEST['limit']);
     //else
     //	$usersResult = $db->query('SELECT id, user_name FROM users WHERE deleted = \'0\' AND status = \'Active\'');
     while ($userRecord = $db->fetchByAssoc($usersResult)) {
         // bugfix 2010-09-28 since id was asisgned and not user name ..  no properly evaluates active user
         $returnArray['data'][] = array('value' => $userRecord['id'], 'text' => $locObject->getLocaleFormattedName($userRecord['first_name'], $userRecord['last_name']));
     }
     echo json_encode($returnArray);
 }
Пример #4
0
/**
 * get_user_array
 *
 * This is a helper function to return an Array of users depending on the parameters passed into the function.
 * This function uses the get_register_value function by default to use a caching layer where supported.
 * This function has been updated return the array sorted by user preference of name display (bug 62712)
 *
 * @param bool $add_blank Boolean value to add a blank entry to the array results, true by default
 * @param string $status String value indicating the status to filter users by, "Active" by default
 * @param string $user_id String value to specify a particular user id value (searches the id column of users table), blank by default
 * @param bool $use_real_name Boolean value indicating whether or not results should include the full name or just user_name, false by default
 * @param String $user_name_filter String value indicating the user_name filter (searches the user_name column of users table) to optionally search with, blank by default
 * @param string $portal_filter String query filter for portal users (defaults to searching non-portal users), change to blank if you wish to search for all users including portal users
 * @param bool $from_cache Boolean value indicating whether or not to use the get_register_value function for caching, true by default
 * @return array Array of users matching the filter criteria that may be from cache (if similar search was previously run)
 */
function get_user_array($add_blank = true, $status = "Active", $user_id = '', $use_real_name = false, $user_name_filter = '', $portal_filter = ' AND portal_only=0 ', $from_cache = true)
{
    global $locale, $sugar_config, $current_user;
    if (empty($locale)) {
        $locale = new Localization();
    }
    if ($from_cache) {
        $key_name = $add_blank . $status . $user_id . $use_real_name . $user_name_filter . $portal_filter;
        $user_array = get_register_value('user_array', $key_name);
    }
    if (empty($user_array)) {
        $db = DBManagerFactory::getInstance();
        $temp_result = array();
        // Including deleted users for now.
        if (empty($status)) {
            $query = "SELECT id, first_name, last_name, user_name from users WHERE 1=1" . $portal_filter;
        } else {
            $query = "SELECT id, first_name, last_name, user_name from users WHERE status='{$status}'" . $portal_filter;
        }
        /* BEGIN - SECURITY GROUPS */
        global $current_user, $sugar_config;
        if (!is_admin($current_user) && isset($sugar_config['securitysuite_filter_user_list']) && $sugar_config['securitysuite_filter_user_list'] == true && (empty($_REQUEST['module']) || $_REQUEST['module'] != 'Home') && (empty($_REQUEST['action']) || $_REQUEST['action'] != 'DynamicAction')) {
            require_once 'modules/SecurityGroups/SecurityGroup.php';
            global $current_user;
            $group_where = SecurityGroup::getGroupUsersWhere($current_user->id);
            $query .= " AND (" . $group_where . ") ";
        }
        /* END - SECURITY GROUPS */
        if (!empty($user_name_filter)) {
            $user_name_filter = $db->quote($user_name_filter);
            $query .= " AND user_name LIKE '{$user_name_filter}%' ";
        }
        if (!empty($user_id)) {
            $query .= " OR id='{$user_id}'";
        }
        //get the user preference for name formatting, to be used in order by
        $order_by_string = ' user_name ASC ';
        if (!empty($current_user) && !empty($current_user->id)) {
            $formatString = $current_user->getPreference('default_locale_name_format');
            //create the order by string based on position of first and last name in format string
            $order_by_string = ' user_name ASC ';
            $firstNamePos = strpos($formatString, 'f');
            $lastNamePos = strpos($formatString, 'l');
            if ($firstNamePos !== false || $lastNamePos !== false) {
                //its possible for first name to be skipped, check for this
                if ($firstNamePos === false) {
                    $order_by_string = 'last_name ASC';
                } else {
                    $order_by_string = $lastNamePos < $firstNamePos ? "last_name, first_name ASC" : "first_name, last_name ASC";
                }
            }
        }
        $query = $query . ' ORDER BY ' . $order_by_string;
        $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;
        if ($from_cache) {
            set_register_value('user_array', $key_name, $temp_result);
        }
    }
    return $user_array;
}
Пример #5
0
 function testFill_in_additional_detail_fields()
 {
     $locale = new Localization();
     $this->c->fill_in_additional_detail_fields();
     $localName = $locale->getLocaleFormattedName('testfirst', 'testlast');
     $this->assertEquals($this->c->name, $localName);
     //$this->assertEquals($this->c->name, 'testfirst testlast');
 }