r1991 + user accounts are now searchable by username
authorDenis Ovsienko <infrastation@yandex.ru>
Mon, 23 Jun 2008 11:41:40 +0000 (11:41 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Mon, 23 Jun 2008 11:41:40 +0000 (11:41 +0000)
inc/database.php
inc/interface.php

index de9785d..e327b7b 100644 (file)
@@ -1157,6 +1157,43 @@ function getIPv4VServiceSearchResult ($terms)
        return $ret;
 }
 
+function getAccountSearchResult ($terms)
+{
+       return getSearchResultByField
+       (
+               'UserAccount',
+               array ('user_id', 'user_name', 'user_realname'),
+               'user_name',
+               $terms,
+               'user_name'
+       );
+}
+
+function getSearchResultByField ($tname, $rcolumns, $scolumn, $terms, $ocolumn = '')
+{
+       $pfx = '';
+       $query = 'select ';
+       foreach ($rcolumns as $col)
+       {
+               $query .= $pfx . $col;
+               $pfx = ', ';
+       }
+       $pfx = '';
+       $query .= " from ${tname} where ";
+       foreach (explode (' ', $terms) as $term)
+       {
+               $query .= $pfx . "${scolumn} like '%${term}%'";
+               $pfx = ' or ';
+       }
+       if ($ocolumn != '')
+               $query .= " order by ${ocolumn}";
+       $result = useSelectBlade ($query, __FUNCTION__);
+       $ret = array();
+       while ($row = $result->fetch (PDO::FETCH_ASSOC))
+               $ret[] = $row;
+       return $ret;
+}
+
 // This function returns either port ID or NULL for specified arguments.
 function getPortID ($object_id, $port_name)
 {
index dad5522..4fb1294 100644 (file)
@@ -2728,6 +2728,13 @@ function renderSearchResults ()
                        $lasthit = 'ipv4vs';
                        $summary['ipv4vs'] = $tmp;
                }
+               $tmp = getAccountSearchResult ($terms);
+               if (count ($tmp))
+               {
+                       $nhits += count ($tmp);
+                       $lasthit = 'user';
+                       $summary['user'] = $tmp;
+               }
        }
        if ($nhits == 0)
                echo "<center><h2>Nothing found for '${terms}'</h2></center>";
@@ -2765,6 +2772,9 @@ function renderSearchResults ()
                        case 'ipv4vs':
                                echo "<script language='Javascript'>document.location='${root}?page=vservice&id=${record['id']}';//</script>";
                                break;
+                       case 'user':
+                               echo "<script language='Javascript'>document.location='${root}?page=user&user_id=${record['user_id']}';//</script>";
+                               break;
                }
                return;
        }
@@ -2840,7 +2850,21 @@ function renderSearchResults ()
                                        {
                                                echo "<tr class=row_${order}><td class=tdleft><a href='${root}?page=vservice&id=${vs['id']}'>";
                                                echo buildVServiceName ($vs);
-                                               echo "</a></td><td>${vs['name']}</td></tr>";
+                                               echo "</a></td><td class=tdleft>${vs['name']}</td></tr>";
+                                               $order = $nextorder[$order];
+                                       }
+                                       echo '</table>';
+                                       finishPortlet();
+                                       break;
+                               case 'user':
+                                       startPortlet ("<a href='${root}?page=userlist'>Users</a>");
+                                       echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
+                                       echo '<tr><th>username</th><th>realname</th></tr>';
+                                       foreach ($what as $item)
+                                       {
+                                               echo "<tr class=row_${order}><td class=tdleft><a href='${root}?page=user&user_id=${item['user_id']}'>";
+                                               echo $item['user_name'];
+                                               echo "</a></td><td class=tdleft>${item['user_realname']}</td></tr>";
                                                $order = $nextorder[$order];
                                        }
                                        echo '</table>';