1 | <?php |
---|
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 | |
---|
24 | define('PHPWG_ROOT_PATH','../'); |
---|
25 | define('IN_ADMIN', true); |
---|
26 | |
---|
27 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
28 | |
---|
29 | check_status(ACCESS_ADMINISTRATOR); |
---|
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 | */ |
---|
38 | $aColumns = array('id', 'username', 'status', 'mail_address', 'registration_date'); |
---|
39 | |
---|
40 | /* Indexed column (used for fast and accurate table cardinality) */ |
---|
41 | $sIndexColumn = "id"; |
---|
42 | |
---|
43 | /* DB table to use */ |
---|
44 | $sTable = USERS_TABLE.' INNER JOIN '.USER_INFOS_TABLE.' AS ui ON id = ui.user_id'; |
---|
45 | |
---|
46 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
---|
47 | * If you just want to use the basic configuration for DataTables with PHP server-side, there is |
---|
48 | * no need to edit below this line |
---|
49 | */ |
---|
50 | |
---|
51 | /* |
---|
52 | * Paging |
---|
53 | */ |
---|
54 | $sLimit = ""; |
---|
55 | if ( isset( $_REQUEST['iDisplayStart'] ) && $_REQUEST['iDisplayLength'] != '-1' ) |
---|
56 | { |
---|
57 | $sLimit = "LIMIT ".pwg_db_real_escape_string( $_REQUEST['iDisplayStart'] ).", ". |
---|
58 | pwg_db_real_escape_string( $_REQUEST['iDisplayLength'] ); |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | /* |
---|
63 | * Ordering |
---|
64 | */ |
---|
65 | if ( isset( $_REQUEST['iSortCol_0'] ) ) |
---|
66 | { |
---|
67 | $sOrder = "ORDER BY "; |
---|
68 | for ( $i=0 ; $i<intval( $_REQUEST['iSortingCols'] ) ; $i++ ) |
---|
69 | { |
---|
70 | if ( $_REQUEST[ 'bSortable_'.intval($_REQUEST['iSortCol_'.$i]) ] == "true" ) |
---|
71 | { |
---|
72 | $sOrder .= $aColumns[ intval( $_REQUEST['iSortCol_'.$i] ) ]." |
---|
73 | ".pwg_db_real_escape_string( $_REQUEST['sSortDir_'.$i] ) .", "; |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | $sOrder = substr_replace( $sOrder, "", -2 ); |
---|
78 | if ( $sOrder == "ORDER BY" ) |
---|
79 | { |
---|
80 | $sOrder = ""; |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | /* |
---|
86 | * Filtering |
---|
87 | * NOTE this does not match the built-in DataTables filtering which does it |
---|
88 | * word by word on any field. It's possible to do here, but concerned about efficiency |
---|
89 | * on very large tables, and MySQL's regex functionality is very limited |
---|
90 | */ |
---|
91 | $sWhere = ""; |
---|
92 | if ( $_REQUEST['sSearch'] != "" ) |
---|
93 | { |
---|
94 | $sWhere = "WHERE ("; |
---|
95 | for ( $i=0 ; $i<count($aColumns) ; $i++ ) |
---|
96 | { |
---|
97 | $sWhere .= $aColumns[$i]." LIKE '%".pwg_db_real_escape_string( $_REQUEST['sSearch'] )."%' OR "; |
---|
98 | } |
---|
99 | $sWhere = substr_replace( $sWhere, "", -3 ); |
---|
100 | $sWhere .= ')'; |
---|
101 | } |
---|
102 | |
---|
103 | /* Individual column filtering */ |
---|
104 | for ( $i=0 ; $i<count($aColumns) ; $i++ ) |
---|
105 | { |
---|
106 | if ( $_REQUEST['bSearchable_'.$i] == "true" && $_REQUEST['sSearch_'.$i] != '' ) |
---|
107 | { |
---|
108 | if ( $sWhere == "" ) |
---|
109 | { |
---|
110 | $sWhere = "WHERE "; |
---|
111 | } |
---|
112 | else |
---|
113 | { |
---|
114 | $sWhere .= " AND "; |
---|
115 | } |
---|
116 | $sWhere .= $aColumns[$i]." LIKE '%".pwg_db_real_escape_string($_REQUEST['sSearch_'.$i])."%' "; |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | /* |
---|
122 | * SQL queries |
---|
123 | * Get data to display |
---|
124 | */ |
---|
125 | $sQuery = " |
---|
126 | SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))." |
---|
127 | FROM $sTable |
---|
128 | $sWhere |
---|
129 | $sOrder |
---|
130 | $sLimit |
---|
131 | "; |
---|
132 | $rResult = pwg_query($sQuery); |
---|
133 | |
---|
134 | /* Data set length after filtering */ |
---|
135 | $sQuery = " |
---|
136 | SELECT FOUND_ROWS() |
---|
137 | "; |
---|
138 | $rResultFilterTotal = pwg_query($sQuery); |
---|
139 | $aResultFilterTotal = pwg_db_fetch_array($rResultFilterTotal); |
---|
140 | $iFilteredTotal = $aResultFilterTotal[0]; |
---|
141 | |
---|
142 | /* Total data set length */ |
---|
143 | $sQuery = " |
---|
144 | SELECT COUNT(".$sIndexColumn.") |
---|
145 | FROM $sTable |
---|
146 | "; |
---|
147 | $rResultTotal = pwg_query($sQuery); |
---|
148 | $aResultTotal = pwg_db_fetch_array($rResultTotal); |
---|
149 | $iTotal = $aResultTotal[0]; |
---|
150 | |
---|
151 | |
---|
152 | /* |
---|
153 | * Output |
---|
154 | */ |
---|
155 | $output = array( |
---|
156 | "sEcho" => intval($_REQUEST['sEcho']), |
---|
157 | "iTotalRecords" => $iTotal, |
---|
158 | "iTotalDisplayRecords" => $iFilteredTotal, |
---|
159 | "aaData" => array() |
---|
160 | ); |
---|
161 | |
---|
162 | while ( $aRow = pwg_db_fetch_array( $rResult ) ) |
---|
163 | { |
---|
164 | $row = array(); |
---|
165 | for ( $i=0 ; $i<count($aColumns) ; $i++ ) |
---|
166 | { |
---|
167 | if ( $aColumns[$i] == "status" ) |
---|
168 | { |
---|
169 | $row[] = l10n('user_status_'.$aRow[ $aColumns[$i] ]); |
---|
170 | } |
---|
171 | else if ( $aColumns[$i] != ' ' ) |
---|
172 | { |
---|
173 | /* General output */ |
---|
174 | $row[] = $aRow[ $aColumns[$i] ]; |
---|
175 | } |
---|
176 | } |
---|
177 | $output['aaData'][] = $row; |
---|
178 | } |
---|
179 | |
---|
180 | echo json_encode( $output ); |
---|
181 | ?> |
---|