[25194] | 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 | */ |
---|
[25475] | 14 | $aColumns = array('id', 'username', 'status', 'mail_address', 'registration_date'); |
---|
[25194] | 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 = ""; |
---|
[25545] | 31 | if ( isset( $_REQUEST['iDisplayStart'] ) && $_REQUEST['iDisplayLength'] != '-1' ) |
---|
[25194] | 32 | { |
---|
[25545] | 33 | $sLimit = "LIMIT ".pwg_db_real_escape_string( $_REQUEST['iDisplayStart'] ).", ". |
---|
| 34 | pwg_db_real_escape_string( $_REQUEST['iDisplayLength'] ); |
---|
[25194] | 35 | } |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | /* |
---|
| 39 | * Ordering |
---|
| 40 | */ |
---|
[25545] | 41 | if ( isset( $_REQUEST['iSortCol_0'] ) ) |
---|
[25194] | 42 | { |
---|
| 43 | $sOrder = "ORDER BY "; |
---|
[25545] | 44 | for ( $i=0 ; $i<intval( $_REQUEST['iSortingCols'] ) ; $i++ ) |
---|
[25194] | 45 | { |
---|
[25545] | 46 | if ( $_REQUEST[ 'bSortable_'.intval($_REQUEST['iSortCol_'.$i]) ] == "true" ) |
---|
[25194] | 47 | { |
---|
[25545] | 48 | $sOrder .= $aColumns[ intval( $_REQUEST['iSortCol_'.$i] ) ]." |
---|
| 49 | ".pwg_db_real_escape_string( $_REQUEST['sSortDir_'.$i] ) .", "; |
---|
[25194] | 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 = ""; |
---|
[25545] | 68 | if ( $_REQUEST['sSearch'] != "" ) |
---|
[25194] | 69 | { |
---|
| 70 | $sWhere = "WHERE ("; |
---|
| 71 | for ( $i=0 ; $i<count($aColumns) ; $i++ ) |
---|
| 72 | { |
---|
[25545] | 73 | $sWhere .= $aColumns[$i]." LIKE '%".pwg_db_real_escape_string( $_REQUEST['sSearch'] )."%' OR "; |
---|
[25194] | 74 | } |
---|
| 75 | $sWhere = substr_replace( $sWhere, "", -3 ); |
---|
| 76 | $sWhere .= ')'; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | /* Individual column filtering */ |
---|
| 80 | for ( $i=0 ; $i<count($aColumns) ; $i++ ) |
---|
| 81 | { |
---|
[25545] | 82 | if ( $_REQUEST['bSearchable_'.$i] == "true" && $_REQUEST['sSearch_'.$i] != '' ) |
---|
[25194] | 83 | { |
---|
| 84 | if ( $sWhere == "" ) |
---|
| 85 | { |
---|
| 86 | $sWhere = "WHERE "; |
---|
| 87 | } |
---|
| 88 | else |
---|
| 89 | { |
---|
| 90 | $sWhere .= " AND "; |
---|
| 91 | } |
---|
[25545] | 92 | $sWhere .= $aColumns[$i]." LIKE '%".pwg_db_real_escape_string($_REQUEST['sSearch_'.$i])."%' "; |
---|
[25194] | 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( |
---|
[25545] | 132 | "sEcho" => intval($_REQUEST['sEcho']), |
---|
[25194] | 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 | { |
---|
[26049] | 143 | if ( $aColumns[$i] == "status" ) |
---|
[25194] | 144 | { |
---|
[26049] | 145 | $row[] = l10n('user_status_'.$aRow[ $aColumns[$i] ]); |
---|
[25194] | 146 | } |
---|
| 147 | else if ( $aColumns[$i] != ' ' ) |
---|
| 148 | { |
---|
| 149 | /* General output */ |
---|
| 150 | $row[] = $aRow[ $aColumns[$i] ]; |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | $output['aaData'][] = $row; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | echo json_encode( $output ); |
---|
| 157 | ?> |
---|