root/devel/mod/search/lib/search_suggest_users.php

Revision 1617, 2.5 kB (checked in by misja, 5 months ago)

Fixes #378, thanks joerosa

  • Property svn:mime-type set to text/plain
  • Property svn:eol-style set to native
Line 
1 <?php
2 global $CFG, $db, $PAGE;
3
4 if (isset($parameter) && $parameter) {
5    
6     if (!empty($PAGE->search_type_unformatted)) {
7                 $typeline = " AND user_type = " . $PAGE->search_type;
8             } else {
9                 $typeline = "";
10             }
11            
12     if (FALSE && $CFG->dbtype == 'mysql') {
13         // FIXME: full-text indexing turned off because it will only search for whole words and not parts
14         $dbname = $db->qstr($parameter);
15         $searchline = "SELECT DISTINCT name,username,MATCH(name) AGAINST (" . $dbname . ") AS score
16                        FROM ".$CFG->prefix."users WHERE (MATCH(name) AGAINST (" . $dbname . ") > 0) $typeline LIMIT 20";
17     } else {
18         $dbname = $db->qstr("%" . $parameter . "%");
19         $searchline = "SELECT DISTINCT username,name,ident
20                        FROM ".$CFG->prefix."users WHERE (name LIKE " . $dbname . " OR username LIKE " . $dbname . ") $typeline LIMIT 20";
21     }
22
23     if ($results = get_records_sql($searchline)) {
24         if (!empty($PAGE->search_type_unformatted) && $PAGE->search_type_unformatted == "person") {
25             $run_result .= "<h2>" . __gettext("Matching users:") . "</h2><p>";
26         } else if (!empty($PAGE->search_type_unformatted) && $PAGE->search_type_unformatted == "community") {
27             $run_result .= "<h2>" . __gettext("Matching communities:") . "</h2><p>";
28         } else {
29             $run_result .= "<h2>" . __gettext("Matching users and communities:") . "</h2><p>";
30         }
31         /*
32         foreach($results as $returned_name) {
33             $run_result .= "<a href=\"" . url . $returned_name->username . '/">' . htmlspecialchars($returned_name->name) . "</a> <br />";
34         }
35         */
36
37         $body = <<< END
38     <table class="userlist">
39         <tr>
40 END;
41         $i = 1;
42         $w = 100;
43         if (sizeof($results) > 4) {
44           $w = 50;
45         }
46
47         foreach($results as $key => $info) {
48           $friends_username = $info->username;
49           $friends_name = run("profile:display:name",$info->ident);
50           $info->icon = run("icons:get",$info->ident);
51           $friends_icon = user_icon_html($info->ident,$w);
52           $body .= <<< END
53         <td align="center">
54             <p>
55             <a href="{$CFG->wwwroot}{$friends_username}/">
56             {$friends_icon}</a><br />
57             <span class="userdetails">
58                 <a href="{$CFG->wwwroot}{$friends_username}/">{$friends_name}</a>
59             </span>
60             </p>
61         </td>
62 END;
63           if ($i % 5 == 0) {
64             $body .= "</tr><tr>";
65           }
66           $i++;
67         }
68         $body .= <<< END
69     </tr>
70     </table>
71 END;
72         $run_result .= $body;
73
74
75         $run_result .= "</p>";
76        
77     }
78    
79 }
80
81 ?>
Note: See TracBrowser for help on using the browser.