ajax.php
changeset 174 d74ff822acc9
parent 144 380e55865f86
child 182 bf0fdec102e9
equal deleted inserted replaced
173:91127e62f38f 174:d74ff822acc9
    31       $filename = __FILE__;
    31       $filename = __FILE__;
    32     }
    32     }
    33     define('ENANO_ROOT', dirname($filename));
    33     define('ENANO_ROOT', dirname($filename));
    34     require(ENANO_ROOT.'/includes/functions.php');
    34     require(ENANO_ROOT.'/includes/functions.php');
    35     require(ENANO_ROOT.'/includes/dbal.php');
    35     require(ENANO_ROOT.'/includes/dbal.php');
       
    36     require(ENANO_ROOT.'/includes/json.php');
    36     $db = new mysql();
    37     $db = new mysql();
    37     $db->connect();
    38     $db->connect();
    38     
    39     
    39     // should be connected now
    40     // result is sent using JSON
       
    41     $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
       
    42     $return = Array(
       
    43         'mode' => 'success',
       
    44         'users_real' => Array()
       
    45       );
       
    46     
       
    47     // should be connected to the DB now
    40     $name = (isset($_GET['name'])) ? $db->escape($_GET['name']) : false;
    48     $name = (isset($_GET['name'])) ? $db->escape($_GET['name']) : false;
    41     if ( !$name )
    49     if ( !$name )
    42     {
    50     {
    43       die('userlist = new Array(); errorstring=\'Invalid URI\'');
    51       $return = array(
       
    52         'mode' => 'error',
       
    53         'error' => 'Invalid URI'
       
    54       );
       
    55       die( $json->encode($return) );
    44     }
    56     }
    45     $q = $db->sql_query('SELECT username,user_id FROM '.table_prefix.'users WHERE lcase(username) LIKE lcase(\'%'.$name.'%\');');
    57     $allowanon = ( isset($_GET['allowanon']) && $_GET['allowanon'] == '1' ) ? '' : ' AND user_id > 1';
       
    58     $q = $db->sql_query('SELECT username FROM '.table_prefix.'users WHERE lcase(username) LIKE lcase(\'%'.$name.'%\')' . $allowanon . ' ORDER BY username ASC;');
    46     if ( !$q )
    59     if ( !$q )
    47     {
    60     {
    48       die('userlist = new Array(); errorstring=\'MySQL error selecting username data: '.addslashes(mysql_error()).'\'');
    61       $return = array(
       
    62         'mode' => 'error',
       
    63         'error' => 'MySQL error selecting username data: '.addslashes(mysql_error())
       
    64       );
       
    65       die( $json->encode($return) );
    49     }
    66     }
    50     if($db->numrows() < 1)
       
    51     {
       
    52       die('userlist = new Array(); errorstring=\'No usernames found\';');
       
    53     }
       
    54     echo 'var errorstring = false; userlist = new Array();';
       
    55     $i = 0;
    67     $i = 0;
    56     while($r = $db->fetchrow())
    68     while($r = $db->fetchrow())
    57     {
    69     {
    58       echo "userlist[$i] = '".addslashes($r['username'])."'; ";
    70       $return['users_real'][] = $r['username'];
    59       $i++;
    71       $i++;
    60     }
    72     }
    61     $db->free_result();
    73     $db->free_result();
    62     
    74     
    63     // all done! :-)
    75     // all done! :-)
    64     $db->close();
    76     $db->close();
       
    77     
       
    78     echo $json->encode( $return );
       
    79     
    65     exit;
    80     exit;
    66   }
    81   }
    67  
    82  
    68   require('includes/common.php');
    83   require('includes/common.php');
    69   
    84