2013-10-28 17:25:46 +01:00
|
|
|
<?php
|
2014-01-05 01:19:25 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | Piwigo - a PHP based photo gallery |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org |
|
|
|
|
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
|
|
|
|
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | This program is free software; you can redistribute it and/or modify |
|
|
|
|
// | it under the terms of the GNU General Public License as published by |
|
|
|
|
// | the Free Software Foundation |
|
|
|
|
// | |
|
|
|
|
// | This program is distributed in the hope that it will be useful, but |
|
|
|
|
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
|
|
// | General Public License for more details. |
|
|
|
|
// | |
|
|
|
|
// | You should have received a copy of the GNU General Public License |
|
|
|
|
// | along with this program; if not, write to the Free Software |
|
|
|
|
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|
|
|
|
// | USA. |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
|
2013-10-28 17:25:46 +01:00
|
|
|
define('PHPWG_ROOT_PATH','../');
|
|
|
|
define('IN_ADMIN', true);
|
|
|
|
|
|
|
|
include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
|
2013-12-20 13:59:07 +01:00
|
|
|
|
|
|
|
check_status(ACCESS_ADMINISTRATOR);
|
2013-10-28 17:25:46 +01:00
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Easy set variables
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Array of database columns which should be read and sent back to DataTables. Use a space where
|
|
|
|
* you want to insert a non-database field (for example a counter or static image)
|
|
|
|
*/
|
2013-11-13 15:40:00 +01:00
|
|
|
$aColumns = array('id', 'username', 'status', 'mail_address', 'registration_date');
|
2014-01-11 14:08:26 +01:00
|
|
|
$aColumns = trigger_change('user_list_columns', $aColumns);
|
2013-10-28 17:25:46 +01:00
|
|
|
|
|
|
|
/* Indexed column (used for fast and accurate table cardinality) */
|
|
|
|
$sIndexColumn = "id";
|
|
|
|
|
|
|
|
/* DB table to use */
|
|
|
|
$sTable = USERS_TABLE.' INNER JOIN '.USER_INFOS_TABLE.' AS ui ON id = ui.user_id';
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* If you just want to use the basic configuration for DataTables with PHP server-side, there is
|
|
|
|
* no need to edit below this line
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Paging
|
|
|
|
*/
|
|
|
|
$sLimit = "";
|
2013-11-18 06:03:00 +01:00
|
|
|
if ( isset( $_REQUEST['iDisplayStart'] ) && $_REQUEST['iDisplayLength'] != '-1' )
|
2013-10-28 17:25:46 +01:00
|
|
|
{
|
2013-11-18 06:03:00 +01:00
|
|
|
$sLimit = "LIMIT ".pwg_db_real_escape_string( $_REQUEST['iDisplayStart'] ).", ".
|
|
|
|
pwg_db_real_escape_string( $_REQUEST['iDisplayLength'] );
|
2013-10-28 17:25:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ordering
|
|
|
|
*/
|
2013-11-18 06:03:00 +01:00
|
|
|
if ( isset( $_REQUEST['iSortCol_0'] ) )
|
2013-10-28 17:25:46 +01:00
|
|
|
{
|
|
|
|
$sOrder = "ORDER BY ";
|
2013-11-18 06:03:00 +01:00
|
|
|
for ( $i=0 ; $i<intval( $_REQUEST['iSortingCols'] ) ; $i++ )
|
2013-10-28 17:25:46 +01:00
|
|
|
{
|
2013-11-18 06:03:00 +01:00
|
|
|
if ( $_REQUEST[ 'bSortable_'.intval($_REQUEST['iSortCol_'.$i]) ] == "true" )
|
2013-10-28 17:25:46 +01:00
|
|
|
{
|
2013-11-18 06:03:00 +01:00
|
|
|
$sOrder .= $aColumns[ intval( $_REQUEST['iSortCol_'.$i] ) ]."
|
|
|
|
".pwg_db_real_escape_string( $_REQUEST['sSortDir_'.$i] ) .", ";
|
2013-10-28 17:25:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$sOrder = substr_replace( $sOrder, "", -2 );
|
|
|
|
if ( $sOrder == "ORDER BY" )
|
|
|
|
{
|
|
|
|
$sOrder = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Filtering
|
|
|
|
* NOTE this does not match the built-in DataTables filtering which does it
|
|
|
|
* word by word on any field. It's possible to do here, but concerned about efficiency
|
|
|
|
* on very large tables, and MySQL's regex functionality is very limited
|
|
|
|
*/
|
|
|
|
$sWhere = "";
|
2013-11-18 06:03:00 +01:00
|
|
|
if ( $_REQUEST['sSearch'] != "" )
|
2013-10-28 17:25:46 +01:00
|
|
|
{
|
|
|
|
$sWhere = "WHERE (";
|
|
|
|
for ( $i=0 ; $i<count($aColumns) ; $i++ )
|
|
|
|
{
|
2013-11-18 06:03:00 +01:00
|
|
|
$sWhere .= $aColumns[$i]." LIKE '%".pwg_db_real_escape_string( $_REQUEST['sSearch'] )."%' OR ";
|
2013-10-28 17:25:46 +01:00
|
|
|
}
|
|
|
|
$sWhere = substr_replace( $sWhere, "", -3 );
|
|
|
|
$sWhere .= ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Individual column filtering */
|
|
|
|
for ( $i=0 ; $i<count($aColumns) ; $i++ )
|
|
|
|
{
|
2014-01-11 14:08:26 +01:00
|
|
|
if (isset($_REQUEST['bSearchable_'.$i]) && isset($_REQUEST['sSearch_'.$i])
|
|
|
|
&&$_REQUEST['bSearchable_'.$i] == "true" && $_REQUEST['sSearch_'.$i] != ''
|
|
|
|
)
|
2013-10-28 17:25:46 +01:00
|
|
|
{
|
|
|
|
if ( $sWhere == "" )
|
|
|
|
{
|
|
|
|
$sWhere = "WHERE ";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$sWhere .= " AND ";
|
|
|
|
}
|
2013-11-18 06:03:00 +01:00
|
|
|
$sWhere .= $aColumns[$i]." LIKE '%".pwg_db_real_escape_string($_REQUEST['sSearch_'.$i])."%' ";
|
2013-10-28 17:25:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SQL queries
|
|
|
|
* Get data to display
|
|
|
|
*/
|
|
|
|
$sQuery = "
|
|
|
|
SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
|
|
|
|
FROM $sTable
|
|
|
|
$sWhere
|
|
|
|
$sOrder
|
|
|
|
$sLimit
|
|
|
|
";
|
|
|
|
$rResult = pwg_query($sQuery);
|
|
|
|
|
|
|
|
/* Data set length after filtering */
|
2014-01-11 14:08:26 +01:00
|
|
|
$rResultFilterTotal = pwg_query('SELECT FOUND_ROWS();');
|
|
|
|
list($iFilteredTotal) = pwg_db_fetch_row($rResultFilterTotal);
|
2013-10-28 17:25:46 +01:00
|
|
|
|
|
|
|
/* Total data set length */
|
|
|
|
$sQuery = "
|
|
|
|
SELECT COUNT(".$sIndexColumn.")
|
|
|
|
FROM $sTable
|
|
|
|
";
|
|
|
|
$rResultTotal = pwg_query($sQuery);
|
|
|
|
$aResultTotal = pwg_db_fetch_array($rResultTotal);
|
|
|
|
$iTotal = $aResultTotal[0];
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Output
|
|
|
|
*/
|
|
|
|
$output = array(
|
2013-11-18 06:03:00 +01:00
|
|
|
"sEcho" => intval($_REQUEST['sEcho']),
|
2013-10-28 17:25:46 +01:00
|
|
|
"iTotalRecords" => $iTotal,
|
|
|
|
"iTotalDisplayRecords" => $iFilteredTotal,
|
|
|
|
"aaData" => array()
|
|
|
|
);
|
|
|
|
|
|
|
|
while ( $aRow = pwg_db_fetch_array( $rResult ) )
|
|
|
|
{
|
|
|
|
$row = array();
|
|
|
|
for ( $i=0 ; $i<count($aColumns) ; $i++ )
|
|
|
|
{
|
2013-12-20 13:36:59 +01:00
|
|
|
if ( $aColumns[$i] == "status" )
|
2013-10-28 17:25:46 +01:00
|
|
|
{
|
2013-12-20 13:36:59 +01:00
|
|
|
$row[] = l10n('user_status_'.$aRow[ $aColumns[$i] ]);
|
2013-10-28 17:25:46 +01:00
|
|
|
}
|
|
|
|
else if ( $aColumns[$i] != ' ' )
|
|
|
|
{
|
|
|
|
/* General output */
|
|
|
|
$row[] = $aRow[ $aColumns[$i] ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$output['aaData'][] = $row;
|
|
|
|
}
|
2014-01-11 14:08:26 +01:00
|
|
|
|
|
|
|
$output = trigger_change('after_render_user_list', $output);
|
2013-10-28 17:25:46 +01:00
|
|
|
|
|
|
|
echo json_encode( $output );
|
|
|
|
?>
|