ajax.php
changeset 229 97ae8e9d5e29
parent 228 b0a4d179be85
child 304 e2cb5f1432c8
equal deleted inserted replaced
147:d8156d18ac58 229:97ae8e9d5e29
     1 <?php
     1 <?php
     2 
     2 
     3 /*
     3 /*
     4  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
     4  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
     5  * Version 1.0.2 (Coblynau)
     5  * Version 1.1.1
     6  * Copyright (C) 2006-2007 Dan Fuhry
     6  * Copyright (C) 2006-2007 Dan Fuhry
     7  *
     7  *
     8  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
     8  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
     9  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
     9  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    10  *
    10  *
    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   
    99         $page = new PageProcessor($paths->cpage['urlname_nons'], $paths->namespace);
   114         $page = new PageProcessor($paths->cpage['urlname_nons'], $paths->namespace);
   100         $page->send();
   115         $page->send();
   101       }
   116       }
   102       else
   117       else
   103       {
   118       {
   104         echo 'Error saving the page: '.$e;
   119         echo '<p>Error saving the page: '.$e.'</p>';
   105       }
   120       }
   106       break;
   121       break;
   107     case "protect":
   122     case "protect":
   108       echo PageUtils::protect($paths->cpage['urlname_nons'], $paths->namespace, (int)$_POST['level'], $_POST['reason']);
   123       echo PageUtils::protect($paths->cpage['urlname_nons'], $paths->namespace, (int)$_POST['level'], $_POST['reason']);
   109       break;
   124       break;