source: trunk/admin/user_list_backend.php @ 26049

Last change on this file since 26049 was 26049, checked in by plg, 10 years ago

feature 1668: translate user status in user list

File size: 3.8 KB
Line 
1<?php
2define('PHPWG_ROOT_PATH','../');
3define('IN_ADMIN', true);
4
5include_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', 'registration_date');
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 = "";
31if ( isset( $_REQUEST['iDisplayStart'] ) && $_REQUEST['iDisplayLength'] != '-1' )
32{
33  $sLimit = "LIMIT ".pwg_db_real_escape_string( $_REQUEST['iDisplayStart'] ).", ".
34    pwg_db_real_escape_string( $_REQUEST['iDisplayLength'] );
35}
36       
37       
38/*
39 * Ordering
40 */
41if ( isset( $_REQUEST['iSortCol_0'] ) )
42{
43  $sOrder = "ORDER BY  ";
44  for ( $i=0 ; $i<intval( $_REQUEST['iSortingCols'] ) ; $i++ )
45  {
46    if ( $_REQUEST[ 'bSortable_'.intval($_REQUEST['iSortCol_'.$i]) ] == "true" )
47    {
48      $sOrder .= $aColumns[ intval( $_REQUEST['iSortCol_'.$i] ) ]."
49                                        ".pwg_db_real_escape_string( $_REQUEST['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 = "";
68if ( $_REQUEST['sSearch'] != "" )
69{
70  $sWhere = "WHERE (";
71  for ( $i=0 ; $i<count($aColumns) ; $i++ )
72  {
73    $sWhere .= $aColumns[$i]." LIKE '%".pwg_db_real_escape_string( $_REQUEST['sSearch'] )."%' OR ";
74  }
75  $sWhere = substr_replace( $sWhere, "", -3 );
76  $sWhere .= ')';
77}
78       
79/* Individual column filtering */
80for ( $i=0 ; $i<count($aColumns) ; $i++ )
81{
82  if ( $_REQUEST['bSearchable_'.$i] == "true" && $_REQUEST['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($_REQUEST['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($_REQUEST['sEcho']),
133  "iTotalRecords" => $iTotal,
134  "iTotalDisplayRecords" => $iFilteredTotal,
135  "aaData" => array()
136        );
137       
138while ( $aRow = pwg_db_fetch_array( $rResult ) )
139{
140  $row = array();
141  for ( $i=0 ; $i<count($aColumns) ; $i++ )
142  {
143    if ( $aColumns[$i] == "status" )
144    {
145      $row[] = l10n('user_status_'.$aRow[ $aColumns[$i] ]);
146    }
147    else if ( $aColumns[$i] != ' ' )
148    {
149      /* General output */
150      $row[] = $aRow[ $aColumns[$i] ];
151    }
152  }
153  $output['aaData'][] = $row;
154}
155       
156echo json_encode( $output );
157?>
Note: See TracBrowser for help on using the repository browser.