|
|
|
@ -34,57 +34,97 @@ switch ($action) { |
|
|
|
|
$tbl_my_user_friend = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
|
|
|
|
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); |
|
|
|
|
$tbl_access_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
|
|
|
|
$search = Database::escape_string($_REQUEST['tag']); |
|
|
|
|
|
|
|
|
|
$access_url_id = api_get_multiple_access_url() == 'true' ? api_get_current_access_url_id() : 0; |
|
|
|
|
$search = Database::escape_string($_REQUEST['tag']); |
|
|
|
|
|
|
|
|
|
$access_url_id = api_get_multiple_access_url() == 'true' ? api_get_current_access_url_id() : 1; |
|
|
|
|
$user_id = api_get_user_id(); |
|
|
|
|
$is_western_name_order = api_is_western_name_order(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$likeCondition = " AND (firstname LIKE '%$search%' OR lastname LIKE '%$search%' OR email LIKE '%$search%') "; |
|
|
|
|
|
|
|
|
|
if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool') == 'true') { |
|
|
|
|
//all users |
|
|
|
|
if (api_get_setting('allow_send_message_to_all_platform_users') == 'true' || api_is_platform_admin() ) { |
|
|
|
|
// All users |
|
|
|
|
if (api_get_setting('allow_send_message_to_all_platform_users') == 'true' || api_is_platform_admin() ) { |
|
|
|
|
if ($access_url_id != 0) { |
|
|
|
|
$sql = 'SELECT DISTINCT u.user_id as id, '.($is_western_name_order ? 'concat(u.firstname," ",u.lastname," ","( ",u.email," )")' : 'concat(u.lastname," ",u.firstname," ","( ",u.email," )")').' as name |
|
|
|
|
FROM '.$tbl_user.' u LEFT JOIN'.$tbl_access_url_rel_user.' r ON u.user_id = r.user_id |
|
|
|
|
WHERE u.status <> 6 AND u.user_id <>'.$user_id.' AND r.access_url_id = '.$access_url_id.' AND '.($is_western_name_order ? 'concat(u.firstname, " ", u.lastname)' : 'concat(u.lastname, " ", u.firstname)').' LIKE CONCAT("%","'.$search.'","%") '; |
|
|
|
|
$sql = "SELECT DISTINCT u.user_id as id, u.firstname, u.lastname, u.email |
|
|
|
|
FROM $tbl_user u LEFT JOIN $tbl_access_url_rel_user r ON u.user_id = r.user_id |
|
|
|
|
WHERE |
|
|
|
|
u.status <> 6 AND |
|
|
|
|
u.user_id <> $user_id AND |
|
|
|
|
r.access_url_id = $access_url_id |
|
|
|
|
$likeCondition "; |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
$sql = 'SELECT DISTINCT u.user_id as id, '.($is_western_name_order ? 'concat(u.firstname," ",u.lastname," ","( ",u.email," )")' : 'concat(u.lastname," ",u.firstname," ","( ",u.email," )")').' as name |
|
|
|
|
FROM '.$tbl_user.' u |
|
|
|
|
WHERE u.status <> 6 AND u.user_id <>'.$user_id.' AND '.($is_western_name_order ? 'concat(u.firstname, " ", u.lastname)' : 'concat(u.lastname, " ", u.firstname)').' LIKE CONCAT("%","'.$search.'","%") '; |
|
|
|
|
$sql = "SELECT DISTINCT u.user_id as id, u.firstname, u.lastname, u.email |
|
|
|
|
FROM $tbl_user u |
|
|
|
|
WHERE |
|
|
|
|
u.status <> 6 AND |
|
|
|
|
u.user_id <> $user_id |
|
|
|
|
$likeCondition "; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
} else { |
|
|
|
|
//only my contacts |
|
|
|
|
if ($access_url_id != 0) { |
|
|
|
|
$sql = 'SELECT DISTINCT u.user_id as id, '.($is_western_name_order ? 'concat(u.firstname," ",u.lastname," ","( ",u.email," )")' : 'concat(u.lastname," ",u.firstname," ","( ",u.email," )")').' as name |
|
|
|
|
FROM '.$tbl_access_url_rel_user.' r,'.$tbl_my_user_friend.' uf INNER JOIN '.$tbl_my_user.' AS u ON uf.friend_user_id = u.user_id ' . |
|
|
|
|
'WHERE u.status <> 6 AND relation_type NOT IN('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') |
|
|
|
|
AND uf.user_id = '.$user_id.' AND friend_user_id<>'.$user_id.' AND u.user_id = r.user_id AND r.access_url_id ='.$access_url_id.' |
|
|
|
|
AND '.($is_western_name_order ? 'concat(u.firstname, " ", u.lastname)' : 'concat(u.lastname, " ", u.firstname)').' LIKE CONCAT("%","'.$search.'","%") '; |
|
|
|
|
$sql = "SELECT DISTINCT u.user_id as id, u.firstname, u.lastname, u.email |
|
|
|
|
FROM $tbl_access_url_rel_user r, $tbl_my_user_friend uf |
|
|
|
|
INNER JOIN $tbl_my_user AS u |
|
|
|
|
ON uf.friend_user_id = u.user_id |
|
|
|
|
WHERE |
|
|
|
|
u.status <> 6 AND |
|
|
|
|
relation_type NOT IN(".USER_RELATION_TYPE_DELETED.", ".USER_RELATION_TYPE_RRHH.") AND |
|
|
|
|
uf.user_id = $user_id AND |
|
|
|
|
friend_user_id <> $user_id AND |
|
|
|
|
u.user_id = r.user_id AND |
|
|
|
|
r.access_url_id = $access_url_id |
|
|
|
|
$likeCondition"; |
|
|
|
|
} else { |
|
|
|
|
$sql = 'SELECT DISTINCT u.user_id as id, '.($is_western_name_order ? 'concat(u.firstname," ",u.lastname," ","( ",u.email," )")' : 'concat(u.lastname," ",u.firstname," ","( ",u.email," )")').' as name |
|
|
|
|
FROM '.$tbl_my_user_friend.' uf INNER JOIN '.$tbl_my_user.' AS u ON uf.friend_user_id = u.user_id ' . |
|
|
|
|
'WHERE u.status <> 6 AND relation_type NOT IN('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') |
|
|
|
|
AND uf.user_id = '.$user_id.' AND friend_user_id<>'.$user_id.' |
|
|
|
|
AND '.($is_western_name_order ? 'concat(u.firstname, " ", u.lastname)' : 'concat(u.lastname, " ", u.firstname)').' LIKE CONCAT("%","'.$search.'","%") '; |
|
|
|
|
$sql = "SELECT DISTINCT u.user_id as id, u.firstname, u.lastname, u.email |
|
|
|
|
FROM $tbl_my_user_friend uf |
|
|
|
|
INNER JOIN $tbl_my_user AS u |
|
|
|
|
ON uf.friend_user_id = u.user_id |
|
|
|
|
WHERE |
|
|
|
|
u.status <> 6 AND |
|
|
|
|
relation_type NOT IN(".USER_RELATION_TYPE_DELETED.", ".USER_RELATION_TYPE_RRHH.") AND |
|
|
|
|
uf.user_id = $user_id AND |
|
|
|
|
friend_user_id <> $user_id |
|
|
|
|
$likeCondition"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} elseif (api_get_setting('allow_social_tool')=='false' && api_get_setting('allow_message_tool')=='true') { |
|
|
|
|
|
|
|
|
|
$time_limit = api_get_setting('time_limit_whosonline'); |
|
|
|
|
|
|
|
|
|
$online_time = time() - $time_limit*60; |
|
|
|
|
$limit_date = api_get_utc_datetime($online_time); |
|
|
|
|
$sql = 'SELECT DISTINCT u.user_id as id, '.($is_western_name_order ? 'concat(u.firstname," ",u.lastname," ","( ",u.email," )")' : 'concat(u.lastname," ",u.firstname," ","( ",u.email," )")').' as name |
|
|
|
|
FROM '.$tbl_my_user.' u INNER JOIN '.$track_online_table.' t ON u.user_id=t.login_user_id |
|
|
|
|
WHERE login_date >= "'.$limit_date.'" AND '.($is_western_name_order ? 'concat(u.firstname, " ", u.lastname)' : 'concat(u.lastname, " ", u.firstname)').' LIKE CONCAT("%","'.$search.'","%") '; |
|
|
|
|
if (api_get_setting('allow_send_message_to_all_platform_users') == 'true') { |
|
|
|
|
$sql = "SELECT DISTINCT u.user_id as id, u.firstname, u.lastname, u.email |
|
|
|
|
FROM $tbl_user u LEFT JOIN $tbl_access_url_rel_user r ON u.user_id = r.user_id |
|
|
|
|
WHERE |
|
|
|
|
u.status <> 6 AND |
|
|
|
|
u.user_id <> $user_id AND |
|
|
|
|
r.access_url_id = $access_url_id |
|
|
|
|
$likeCondition "; |
|
|
|
|
} else { |
|
|
|
|
$time_limit = api_get_setting('time_limit_whosonline'); |
|
|
|
|
$online_time = time() - $time_limit*60; |
|
|
|
|
$limit_date = api_get_utc_datetime($online_time); |
|
|
|
|
$sql = "SELECT SELECT DISTINCT u.user_id as id, u.firstname, u.lastname, u.email |
|
|
|
|
FROM $tbl_my_user u INNER JOIN $track_online_table t |
|
|
|
|
ON u.user_id=t.login_user_id |
|
|
|
|
WHERE login_date >= '".$limit_date."' AND |
|
|
|
|
$likeCondition"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$sql .=' LIMIT 20'; |
|
|
|
|
$result=Database::query($sql); |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
|
|
|
|
|
$showEmail = api_get_setting('show_email_addresses'); |
|
|
|
|
$return = array(); |
|
|
|
|
if (Database::num_rows($result) > 0) { |
|
|
|
|
while ($row = Database::fetch_array($result, 'ASSOC')) { |
|
|
|
|
$return[] = array('caption'=>$row['name'], 'value'=>$row['id']); |
|
|
|
|
$name = api_get_person_name($row['firstname'], $row['lastname']); |
|
|
|
|
if ($showEmail == 'true') { |
|
|
|
|
$name .= ' ('.$row['email'].')'; |
|
|
|
|
} |
|
|
|
|
$return[] = array( |
|
|
|
|
'caption' => $name, |
|
|
|
|
'value' => $row['id'] |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
echo json_encode($return); |
|
|
|
|