fixed a bug in user search

This commit is contained in:
SJ 2012-07-06 11:02:21 +02:00
parent f4314f5afd
commit 3a9b8a8ba0

View File

@ -164,13 +164,15 @@ class ModelUserUser extends Model {
$users = array(); $users = array();
$my_domain = array(); $my_domain = array();
$limit = ""; $limit = "";
$q = array();
$from = (int)$page * (int)$page_len; $from = (int)$page * (int)$page_len;
$search = preg_replace("/\s{1,}/", "", $search); $search = preg_replace("/\s{1,}/", "", $search);
if($search){ if($search){
$where_cond .= " AND email like '%" . $this->db->escape($search) . "%' "; $where_cond .= " AND email like ? ";
array_push($q, '%' . $search . '%');
} }
/* sort order */ /* sort order */
@ -182,7 +184,7 @@ class ModelUserUser extends Model {
if($page_len > 0) { $limit = " LIMIT " . (int)$from . ", " . (int)$page_len; } if($page_len > 0) { $limit = " LIMIT " . (int)$from . ", " . (int)$page_len; }
$query = $this->db->query("SELECT " . TABLE_USER . ".uid, isadmin, username, realname, domain, email FROM " . TABLE_USER . "," . TABLE_EMAIL . " $where_cond group by " . TABLE_USER . ".uid $_order $limit"); $query = $this->db->query("SELECT " . TABLE_USER . ".uid, isadmin, username, realname, domain, email FROM " . TABLE_USER . "," . TABLE_EMAIL . " $where_cond group by " . TABLE_USER . ".uid $_order $limit", $q);
foreach ($query->rows as $q) { foreach ($query->rows as $q) {
@ -205,12 +207,14 @@ class ModelUserUser extends Model {
public function count_users($search = '') { public function count_users($search = '') {
$where_cond = ""; $where_cond = "";
$q = array();
if($search){ if($search){
$where_cond .= " WHERE email like '%" . $this->db->escape($search) . "%' "; $where_cond .= " WHERE email like ? ";
array_push($q, '%' . $search . '%');
} }
$query = $this->db->query("SELECT COUNT(*) AS num, uid FROM " . TABLE_EMAIL . " $where_cond group by uid"); $query = $this->db->query("SELECT COUNT(*) AS num, uid FROM " . TABLE_EMAIL . " $where_cond group by uid", $q);
return $query->num_rows; return $query->num_rows;
} }