select_options.php 2.2 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. /* For licensing terms, see /dokeos_license.txt */
  3. $language_file = array('registration','messages','userInfo','admin');
  4. $cidReset = true;
  5. require '../inc/global.inc.php';
  6. $track_online_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ONLINE);
  7. $tbl_my_user = Database :: get_main_table(TABLE_MAIN_USER);
  8. $tbl_my_user_friend = Database :: get_main_table(TABLE_MAIN_USER_FRIEND);
  9. $search=Database::escape_string(Security::remove_XSS($_POST['search']));
  10. $current_date=date('Y-m-d H:i:s',time());
  11. $html_form='<select id="id_search_name" name="id_search_name" size="8"" style="width:350px;">';
  12. $user_id = api_get_user_id();
  13. $is_western_name_order = api_is_western_name_order();
  14. if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true') {
  15. $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
  16. FROM '.$tbl_my_user_friend.' uf ' .
  17. 'INNER JOIN '.$tbl_my_user.' AS u ON uf.friend_user_id = u.user_id ' .
  18. 'WHERE relation_type<>6 AND friend_user_id<>'.(int)$user_id.' AND '.($is_western_name_order ? 'concat(u.firstname, " ", u.lastname)' : 'concat(u.lastname, " ", u.firstname)').' like CONCAT("%","'.$search.'","%") ';
  19. } elseif (api_get_setting('allow_social_tool')=='false' && api_get_setting('allow_message_tool')=='true') {
  20. $valid=api_get_setting('time_limit_whosonline');
  21. $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
  22. FROM '.$tbl_my_user.' u INNER JOIN '.$track_online_table.' t ON u.user_id=t.login_user_id
  23. WHERE DATE_ADD(login_date,INTERVAL "'.$valid.'" MINUTE) >= "'.$current_date.'" AND '.($is_western_name_order ? 'concat(u.firstname, " ", u.lastname)' : 'concat(u.lastname, " ", u.firstname)').' like CONCAT("%","'.$search.'","%") ';
  24. }
  25. $res=Database::query($sql,__FILE__,__LINE__);
  26. while ($row=Database::fetch_array($res,'ASSOC')) {
  27. $html_form.='<option value="'.$row['id'].'">'.api_xml_http_response_encode($row['name']).'</option>';
  28. }
  29. $html_form.='</select>';
  30. echo $html_form;
  31. ?>