1 | <?php |
---|
2 | define('PHPWG_ROOT_PATH','../'); |
---|
3 | define('IN_ADMIN', true); |
---|
4 | |
---|
5 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
6 | |
---|
7 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
---|
8 | * Easy set variables |
---|
9 | */ |
---|
10 | |
---|
11 | /* Array of database columns which should be read and sent back to DataTables. Use a space where |
---|
12 | * you want to insert a non-database field (for example a counter or static image) |
---|
13 | */ |
---|
14 | $aColumns = array('id', 'username', 'status', 'mail_address'); |
---|
15 | |
---|
16 | /* Indexed column (used for fast and accurate table cardinality) */ |
---|
17 | $sIndexColumn = "id"; |
---|
18 | |
---|
19 | /* DB table to use */ |
---|
20 | $sTable = USERS_TABLE.' INNER JOIN '.USER_INFOS_TABLE.' AS ui ON id = ui.user_id'; |
---|
21 | |
---|
22 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
---|
23 | * If you just want to use the basic configuration for DataTables with PHP server-side, there is |
---|
24 | * no need to edit below this line |
---|
25 | */ |
---|
26 | |
---|
27 | /* |
---|
28 | * Paging |
---|
29 | */ |
---|
30 | $sLimit = ""; |
---|
31 | if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) |
---|
32 | { |
---|
33 | $sLimit = "LIMIT ".pwg_db_real_escape_string( $_GET['iDisplayStart'] ).", ". |
---|
34 | pwg_db_real_escape_string( $_GET['iDisplayLength'] ); |
---|
35 | } |
---|
36 | |
---|
37 | |
---|
38 | /* |
---|
39 | * Ordering |
---|
40 | */ |
---|
41 | if ( isset( $_GET['iSortCol_0'] ) ) |
---|
42 | { |
---|
43 | $sOrder = "ORDER BY "; |
---|
44 | for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ ) |
---|
45 | { |
---|
46 | if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" ) |
---|
47 | { |
---|
48 | $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]." |
---|
49 | ".pwg_db_real_escape_string( $_GET['sSortDir_'.$i] ) .", "; |
---|
50 | } |
---|
51 | } |
---|
52 | |
---|
53 | $sOrder = substr_replace( $sOrder, "", -2 ); |
---|
54 | if ( $sOrder == "ORDER BY" ) |
---|
55 | { |
---|
56 | $sOrder = ""; |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | /* |
---|
62 | * Filtering |
---|
63 | * NOTE this does not match the built-in DataTables filtering which does it |
---|
64 | * word by word on any field. It's possible to do here, but concerned about efficiency |
---|
65 | * on very large tables, and MySQL's regex functionality is very limited |
---|
66 | */ |
---|
67 | $sWhere = ""; |
---|
68 | if ( $_GET['sSearch'] != "" ) |
---|
69 | { |
---|
70 | $sWhere = "WHERE ("; |
---|
71 | for ( $i=0 ; $i<count($aColumns) ; $i++ ) |
---|
72 | { |
---|
73 | $sWhere .= $aColumns[$i]." LIKE '%".pwg_db_real_escape_string( $_GET['sSearch'] )."%' OR "; |
---|
74 | } |
---|
75 | $sWhere = substr_replace( $sWhere, "", -3 ); |
---|
76 | $sWhere .= ')'; |
---|
77 | } |
---|
78 | |
---|
79 | /* Individual column filtering */ |
---|
80 | for ( $i=0 ; $i<count($aColumns) ; $i++ ) |
---|
81 | { |
---|
82 | if ( $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' ) |
---|
83 | { |
---|
84 | if ( $sWhere == "" ) |
---|
85 | { |
---|
86 | $sWhere = "WHERE "; |
---|
87 | } |
---|
88 | else |
---|
89 | { |
---|
90 | $sWhere .= " AND "; |
---|
91 | } |
---|
92 | $sWhere .= $aColumns[$i]." LIKE '%".pwg_db_real_escape_string($_GET['sSearch_'.$i])."%' "; |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | /* |
---|
98 | * SQL queries |
---|
99 | * Get data to display |
---|
100 | */ |
---|
101 | $sQuery = " |
---|
102 | SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))." |
---|
103 | FROM $sTable |
---|
104 | $sWhere |
---|
105 | $sOrder |
---|
106 | $sLimit |
---|
107 | "; |
---|
108 | $rResult = pwg_query($sQuery); |
---|
109 | |
---|
110 | /* Data set length after filtering */ |
---|
111 | $sQuery = " |
---|
112 | SELECT FOUND_ROWS() |
---|
113 | "; |
---|
114 | $rResultFilterTotal = pwg_query($sQuery); |
---|
115 | $aResultFilterTotal = pwg_db_fetch_array($rResultFilterTotal); |
---|
116 | $iFilteredTotal = $aResultFilterTotal[0]; |
---|
117 | |
---|
118 | /* Total data set length */ |
---|
119 | $sQuery = " |
---|
120 | SELECT COUNT(".$sIndexColumn.") |
---|
121 | FROM $sTable |
---|
122 | "; |
---|
123 | $rResultTotal = pwg_query($sQuery); |
---|
124 | $aResultTotal = pwg_db_fetch_array($rResultTotal); |
---|
125 | $iTotal = $aResultTotal[0]; |
---|
126 | |
---|
127 | |
---|
128 | /* |
---|
129 | * Output |
---|
130 | */ |
---|
131 | $output = array( |
---|
132 | "sEcho" => intval($_GET['sEcho']), |
---|
133 | "iTotalRecords" => $iTotal, |
---|
134 | "iTotalDisplayRecords" => $iFilteredTotal, |
---|
135 | "aaData" => array() |
---|
136 | ); |
---|
137 | |
---|
138 | while ( $aRow = pwg_db_fetch_array( $rResult ) ) |
---|
139 | { |
---|
140 | $row = array(); |
---|
141 | for ( $i=0 ; $i<count($aColumns) ; $i++ ) |
---|
142 | { |
---|
143 | if ( $aColumns[$i] == "version" ) |
---|
144 | { |
---|
145 | /* Special output formatting for 'version' column */ |
---|
146 | $row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ]; |
---|
147 | } |
---|
148 | else if ( $aColumns[$i] != ' ' ) |
---|
149 | { |
---|
150 | /* General output */ |
---|
151 | $row[] = $aRow[ $aColumns[$i] ]; |
---|
152 | } |
---|
153 | } |
---|
154 | $output['aaData'][] = $row; |
---|
155 | } |
---|
156 | |
---|
157 | echo json_encode( $output ); |
---|
158 | ?> |
---|