source: branches/2.6/admin/user_list_backend.php @ 26827

Last change on this file since 26827 was 26618, checked in by mistic100, 11 years ago

add two triggers and user_list_backend.php and don't fail on unknown column

File size: 5.6 KB
Line 
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
24define('PHPWG_ROOT_PATH','../');
25define('IN_ADMIN', true);
26
27include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
28
29check_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$aColumns = trigger_change('user_list_columns', $aColumns);
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 = "";
56if ( isset( $_REQUEST['iDisplayStart'] ) && $_REQUEST['iDisplayLength'] != '-1' )
57{
58  $sLimit = "LIMIT ".pwg_db_real_escape_string( $_REQUEST['iDisplayStart'] ).", ".
59    pwg_db_real_escape_string( $_REQUEST['iDisplayLength'] );
60}
61       
62       
63/*
64 * Ordering
65 */
66if ( isset( $_REQUEST['iSortCol_0'] ) )
67{
68  $sOrder = "ORDER BY  ";
69  for ( $i=0 ; $i<intval( $_REQUEST['iSortingCols'] ) ; $i++ )
70  {
71    if ( $_REQUEST[ 'bSortable_'.intval($_REQUEST['iSortCol_'.$i]) ] == "true" )
72    {
73      $sOrder .= $aColumns[ intval( $_REQUEST['iSortCol_'.$i] ) ]."
74                                        ".pwg_db_real_escape_string( $_REQUEST['sSortDir_'.$i] ) .", ";
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 = "";
93if ( $_REQUEST['sSearch'] != "" )
94{
95  $sWhere = "WHERE (";
96  for ( $i=0 ; $i<count($aColumns) ; $i++ )
97  {
98    $sWhere .= $aColumns[$i]." LIKE '%".pwg_db_real_escape_string( $_REQUEST['sSearch'] )."%' OR ";
99  }
100  $sWhere = substr_replace( $sWhere, "", -3 );
101  $sWhere .= ')';
102}
103       
104/* Individual column filtering */
105for ( $i=0 ; $i<count($aColumns) ; $i++ )
106{
107  if (isset($_REQUEST['bSearchable_'.$i]) && isset($_REQUEST['sSearch_'.$i])
108      &&$_REQUEST['bSearchable_'.$i] == "true" && $_REQUEST['sSearch_'.$i] != ''
109    )
110  {
111    if ( $sWhere == "" )
112    {
113      $sWhere = "WHERE ";
114    }
115    else
116    {
117      $sWhere .= " AND ";
118    }
119    $sWhere .= $aColumns[$i]." LIKE '%".pwg_db_real_escape_string($_REQUEST['sSearch_'.$i])."%' ";
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 */
138$rResultFilterTotal = pwg_query('SELECT FOUND_ROWS();');
139list($iFilteredTotal) = pwg_db_fetch_row($rResultFilterTotal);
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(
155  "sEcho" => intval($_REQUEST['sEcho']),
156  "iTotalRecords" => $iTotal,
157  "iTotalDisplayRecords" => $iFilteredTotal,
158  "aaData" => array()
159        );
160       
161while ( $aRow = pwg_db_fetch_array( $rResult ) )
162{
163  $row = array();
164  for ( $i=0 ; $i<count($aColumns) ; $i++ )
165  {
166    if ( $aColumns[$i] == "status" )
167    {
168      $row[] = l10n('user_status_'.$aRow[ $aColumns[$i] ]);
169    }
170    else if ( $aColumns[$i] != ' ' )
171    {
172      /* General output */
173      $row[] = $aRow[ $aColumns[$i] ];
174    }
175  }
176  $output['aaData'][] = $row;
177}
178
179$output = trigger_change('after_render_user_list', $output);
180       
181echo json_encode( $output );
182?>
Note: See TracBrowser for help on using the repository browser.