[25194] | 1 | <?php |
---|
[26461] | 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | Piwigo - a PHP based photo gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org | |
---|
| 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
| 23 | |
---|
[25194] | 24 | define('PHPWG_ROOT_PATH','../'); |
---|
| 25 | define('IN_ADMIN', true); |
---|
| 26 | |
---|
| 27 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
[26050] | 28 | |
---|
| 29 | check_status(ACCESS_ADMINISTRATOR); |
---|
[25194] | 30 | |
---|
| 31 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
---|
| 32 | * Easy set variables |
---|
| 33 | */ |
---|
| 34 | |
---|
| 35 | /* Array of database columns which should be read and sent back to DataTables. Use a space where |
---|
| 36 | * you want to insert a non-database field (for example a counter or static image) |
---|
| 37 | */ |
---|
[25475] | 38 | $aColumns = array('id', 'username', 'status', 'mail_address', 'registration_date'); |
---|
[26618] | 39 | $aColumns = trigger_change('user_list_columns', $aColumns); |
---|
[25194] | 40 | |
---|
| 41 | /* Indexed column (used for fast and accurate table cardinality) */ |
---|
| 42 | $sIndexColumn = "id"; |
---|
| 43 | |
---|
| 44 | /* DB table to use */ |
---|
| 45 | $sTable = USERS_TABLE.' INNER JOIN '.USER_INFOS_TABLE.' AS ui ON id = ui.user_id'; |
---|
| 46 | |
---|
| 47 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
---|
| 48 | * If you just want to use the basic configuration for DataTables with PHP server-side, there is |
---|
| 49 | * no need to edit below this line |
---|
| 50 | */ |
---|
| 51 | |
---|
| 52 | /* |
---|
| 53 | * Paging |
---|
| 54 | */ |
---|
| 55 | $sLimit = ""; |
---|
[25545] | 56 | if ( isset( $_REQUEST['iDisplayStart'] ) && $_REQUEST['iDisplayLength'] != '-1' ) |
---|
[25194] | 57 | { |
---|
[25545] | 58 | $sLimit = "LIMIT ".pwg_db_real_escape_string( $_REQUEST['iDisplayStart'] ).", ". |
---|
| 59 | pwg_db_real_escape_string( $_REQUEST['iDisplayLength'] ); |
---|
[25194] | 60 | } |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | /* |
---|
| 64 | * Ordering |
---|
| 65 | */ |
---|
[25545] | 66 | if ( isset( $_REQUEST['iSortCol_0'] ) ) |
---|
[25194] | 67 | { |
---|
| 68 | $sOrder = "ORDER BY "; |
---|
[25545] | 69 | for ( $i=0 ; $i<intval( $_REQUEST['iSortingCols'] ) ; $i++ ) |
---|
[25194] | 70 | { |
---|
[25545] | 71 | if ( $_REQUEST[ 'bSortable_'.intval($_REQUEST['iSortCol_'.$i]) ] == "true" ) |
---|
[25194] | 72 | { |
---|
[25545] | 73 | $sOrder .= $aColumns[ intval( $_REQUEST['iSortCol_'.$i] ) ]." |
---|
| 74 | ".pwg_db_real_escape_string( $_REQUEST['sSortDir_'.$i] ) .", "; |
---|
[25194] | 75 | } |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | $sOrder = substr_replace( $sOrder, "", -2 ); |
---|
| 79 | if ( $sOrder == "ORDER BY" ) |
---|
| 80 | { |
---|
| 81 | $sOrder = ""; |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | /* |
---|
| 87 | * Filtering |
---|
| 88 | * NOTE this does not match the built-in DataTables filtering which does it |
---|
| 89 | * word by word on any field. It's possible to do here, but concerned about efficiency |
---|
| 90 | * on very large tables, and MySQL's regex functionality is very limited |
---|
| 91 | */ |
---|
| 92 | $sWhere = ""; |
---|
[25545] | 93 | if ( $_REQUEST['sSearch'] != "" ) |
---|
[25194] | 94 | { |
---|
| 95 | $sWhere = "WHERE ("; |
---|
| 96 | for ( $i=0 ; $i<count($aColumns) ; $i++ ) |
---|
| 97 | { |
---|
[25545] | 98 | $sWhere .= $aColumns[$i]." LIKE '%".pwg_db_real_escape_string( $_REQUEST['sSearch'] )."%' OR "; |
---|
[25194] | 99 | } |
---|
| 100 | $sWhere = substr_replace( $sWhere, "", -3 ); |
---|
| 101 | $sWhere .= ')'; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | /* Individual column filtering */ |
---|
| 105 | for ( $i=0 ; $i<count($aColumns) ; $i++ ) |
---|
| 106 | { |
---|
[26618] | 107 | if (isset($_REQUEST['bSearchable_'.$i]) && isset($_REQUEST['sSearch_'.$i]) |
---|
| 108 | &&$_REQUEST['bSearchable_'.$i] == "true" && $_REQUEST['sSearch_'.$i] != '' |
---|
| 109 | ) |
---|
[25194] | 110 | { |
---|
| 111 | if ( $sWhere == "" ) |
---|
| 112 | { |
---|
| 113 | $sWhere = "WHERE "; |
---|
| 114 | } |
---|
| 115 | else |
---|
| 116 | { |
---|
| 117 | $sWhere .= " AND "; |
---|
| 118 | } |
---|
[25545] | 119 | $sWhere .= $aColumns[$i]." LIKE '%".pwg_db_real_escape_string($_REQUEST['sSearch_'.$i])."%' "; |
---|
[25194] | 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | /* |
---|
| 125 | * SQL queries |
---|
| 126 | * Get data to display |
---|
| 127 | */ |
---|
| 128 | $sQuery = " |
---|
| 129 | SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))." |
---|
| 130 | FROM $sTable |
---|
| 131 | $sWhere |
---|
| 132 | $sOrder |
---|
| 133 | $sLimit |
---|
| 134 | "; |
---|
| 135 | $rResult = pwg_query($sQuery); |
---|
| 136 | |
---|
| 137 | /* Data set length after filtering */ |
---|
[26618] | 138 | $rResultFilterTotal = pwg_query('SELECT FOUND_ROWS();'); |
---|
| 139 | list($iFilteredTotal) = pwg_db_fetch_row($rResultFilterTotal); |
---|
[25194] | 140 | |
---|
| 141 | /* Total data set length */ |
---|
| 142 | $sQuery = " |
---|
| 143 | SELECT COUNT(".$sIndexColumn.") |
---|
| 144 | FROM $sTable |
---|
| 145 | "; |
---|
| 146 | $rResultTotal = pwg_query($sQuery); |
---|
| 147 | $aResultTotal = pwg_db_fetch_array($rResultTotal); |
---|
| 148 | $iTotal = $aResultTotal[0]; |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | /* |
---|
| 152 | * Output |
---|
| 153 | */ |
---|
| 154 | $output = array( |
---|
[25545] | 155 | "sEcho" => intval($_REQUEST['sEcho']), |
---|
[25194] | 156 | "iTotalRecords" => $iTotal, |
---|
| 157 | "iTotalDisplayRecords" => $iFilteredTotal, |
---|
| 158 | "aaData" => array() |
---|
| 159 | ); |
---|
| 160 | |
---|
| 161 | while ( $aRow = pwg_db_fetch_array( $rResult ) ) |
---|
| 162 | { |
---|
| 163 | $row = array(); |
---|
| 164 | for ( $i=0 ; $i<count($aColumns) ; $i++ ) |
---|
| 165 | { |
---|
[26049] | 166 | if ( $aColumns[$i] == "status" ) |
---|
[25194] | 167 | { |
---|
[26049] | 168 | $row[] = l10n('user_status_'.$aRow[ $aColumns[$i] ]); |
---|
[25194] | 169 | } |
---|
| 170 | else if ( $aColumns[$i] != ' ' ) |
---|
| 171 | { |
---|
| 172 | /* General output */ |
---|
| 173 | $row[] = $aRow[ $aColumns[$i] ]; |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | $output['aaData'][] = $row; |
---|
| 177 | } |
---|
[26618] | 178 | |
---|
| 179 | $output = trigger_change('after_render_user_list', $output); |
---|
[25194] | 180 | |
---|
| 181 | echo json_encode( $output ); |
---|
| 182 | ?> |
---|