lists.ajax 3.64 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
<?php
#
# Copyright (c) 2000-2016 University of Utah and the Flux Group.
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
#
chdir("..");
chdir("apt");
include_once("profile_defs.php");
include_once("instance_defs.php");
include_once("ajax-routines.ajax");

# We set this in CheckPageArgs
$target_project = null;

#
# Need to check the permission, since we allow admins to mess with
# other accounts.
#
function CheckPageArgs()
{
    global $this_user;
    global $ajax_args;

    if (!ISADMIN()) {
	SPITAJAX_ERROR(-1, "Not enough permission");
	return -1;
    }
    return 0;
}

function Do_SearchUsers()
{
    global $this_user;
    global $ajax_args;
    global $PORTAL_GENESIS;
    $results = array();

    if (CheckPageArgs()) {
        return;
    }
    if (!isset($ajax_args["text"])) {
	SPITAJAX_ERROR(-1, "Missing text to search for");
	return -1;
    }
    $text = $ajax_args["text"];
    if (!preg_match("/^\w*$/", $text)) {
	SPITAJAX_ERROR(-1, "Illegal text to search for");
	return -1;
    }
    $query_result =
69 70
        DBQueryFatal("select uid,usr_name,usr_affil,portal from users ".
                     "where portal='$PORTAL_GENESIS' and ".
71
                     "      (uid like '%${text}%' or ".
72 73
                     "       usr_affil like '%${text}%' or ".
                     "       LCASE(usr_email) like '%${text}%' or ".
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
                     "       usr_name like '%${text}%') ".
                     "order by uid");

    while ($row = mysql_fetch_array($query_result)) {
        $blob = array();
        
        $blob["usr_uid"]    = $row["uid"];
        $blob["usr_name"]   = $row["usr_name"];
        $blob["usr_affil"]  = $row["usr_affil"];
        $results[] = $blob;
    }
    SPITAJAX_RESPONSE($results);
}

function Do_SearchProjects()
{
    global $this_user;
    global $ajax_args;
    global $PORTAL_GENESIS;
    $results = array();

    if (CheckPageArgs()) {
        return;
    }
    if (!isset($ajax_args["text"])) {
	SPITAJAX_ERROR(-1, "Missing text to search for");
	return -1;
    }
    $text = $ajax_args["text"];
    if (!preg_match("/^\w*$/", $text)) {
	SPITAJAX_ERROR(-1, "Illegal text to search for");
	return -1;
    }
    $query_result =
108
        DBQueryFatal("select pid,u.uid,u.usr_name,u.usr_affil,p.portal ".
109 110
                     "  from projects as p ".
                     "left join users as u on u.uid_idx=p.head_idx ".
111
                     "where p.portal='$PORTAL_GENESIS' and ".
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
                     "      (pid like '%${text}%' or ".
                     "       u.usr_name like '%${text}%' or ".
                     "       u.usr_affil like '%${text}%') ".
                     "order by pid");

    while ($row = mysql_fetch_array($query_result)) {
        $blob = array();

        $blob["pid"]        = $row["pid"];
        $blob["usr_uid"]    = $row["uid"];
        $blob["usr_name"]   = $row["usr_name"];
        $blob["usr_affil"]  = $row["usr_affil"];
        $results[] = $blob;
    }
    SPITAJAX_RESPONSE($results);
}

# Local Variables:
# mode:php
# End:
?>