2010-12-02 23:34:41 +00:00
< ? php
/**
* class . pagedTable . php
2012-10-17 14:28:05 -04:00
*
* @ package gulliver . system
2010-12-02 23:34:41 +00:00
*
* ProcessMaker Open Source Edition
2011-01-24 21:07:14 +00:00
* Copyright ( C ) 2004 - 2011 Colosa Inc .
2010-12-02 23:34:41 +00:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
2012-10-17 14:28:05 -04:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
2010-12-02 23:34:41 +00:00
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
2012-10-17 14:28:05 -04:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2010-12-02 23:34:41 +00:00
*
* For more information , contact Colosa Inc , 2566 Le Jeune Rd . ,
* Coral Gables , FL , 33134 , USA , or email info @ colosa . com .
*
*/
/**
* Class pagedTable
2012-10-17 14:28:05 -04:00
*
2010-12-02 23:34:41 +00:00
* @ author David S . Callizaya S . < davidsantos @ colosa . com >
* @ package gulliver . system
* @ access public
*/
class pagedTable
{
2012-10-17 14:28:05 -04:00
public $xmlFormFile ;
public $currentPage ;
public $orderBy = '' ;
2017-12-04 13:25:35 +00:00
public $filter = array ();
public $filterType = array ();
2012-10-17 14:28:05 -04:00
public $searchBy = '' ;
public $fastSearch = '' ;
public $order = '' ;
public $template = 'templates/paged-table.html' ;
public $tpl ;
2017-12-04 13:25:35 +00:00
public $style = array ();
2012-10-17 14:28:05 -04:00
public $rowsPerPage = 25 ;
public $ownerPage ;
public $popupPage ;
public $popupSubmit ;
public $popupWidth = 450 ;
public $popupHeight = 200 ;
public $ajaxServer ;
public $fields ;
public $query ;
public $totpages ;
//SQL QUERIES
public $sql = '' ;
public $sqlWhere = '' ;
public $sqlGroupBy = '' ;
public $sqlSelect = 'SELECT 1' ;
public $sqlDelete = '' ;
public $sqlInsert = '' ;
public $sqlUpdate = '' ;
public $fieldDataList = '' ;
2010-12-02 23:34:41 +00:00
2012-10-17 14:28:05 -04:00
//Configuration
public $xmlPopup = '' ;
public $addRow = false ;
public $deleteRow = false ;
public $editRow = false ;
public $notFields = ' title button linknew begingrid2 endgrid2 ' ; // These are not considered to build the sql queries (update,insert,delete)
2010-12-02 23:34:41 +00:00
2012-10-17 14:28:05 -04:00
//JavaScript Object attributes
public $onUpdateField = " " ;
public $onDeleteField = " " ;
public $afterDeleteField = " " ;
public $onInsertField = " " ;
2010-12-02 23:34:41 +00:00
2012-10-17 14:28:05 -04:00
//New gulliver
public $xmlForm ;
public $menu = '' ;
public $filterForm = '' ;
public $filterForm_Id = '' ;
public $name = 'pagedTable' ;
public $id = 'A1' ;
public $disableFooter = false ;
2017-08-14 15:53:48 -04:00
//This attribute is used to set STYLES to groups of TD, using the field type "cellMark" (see XmlFormFieldCellMark)
2012-10-17 14:28:05 -04:00
public $tdStyle = '' ;
public $tdClass = '' ;
//Config Save definition
public $__Configuration = 'orderBy,filter,fastSearch,style/*/showInTable' ; //order,rowsPerPage,disableFooter';
/**
* Function analizeSql
* You can to distribute the component of the query like : Select , Where , Group by and order by
*
* @ author David S . Callizaya S . < davidsantos @ colosa . com >
* @ access public
* @ return string
*/
2017-12-04 13:25:35 +00:00
public function analizeSql ()
2012-10-17 14:28:05 -04:00
{
2017-12-04 13:25:35 +00:00
if ( 1 === preg_match ( '/^\s*SELECT\s+(.+?)(?:\s+FROM\s+(.+?))(?:\s+WHERE\s+(.+?))?(?:\s+GROUP\s+BY\s+(.+?))?(?:\s+ORDER\s+BY\s+(.+?))?(?:\s+BETWEEN\s+(.+?)\s+AND\s+(.+?))?\s*$/im' , $this -> sqlSelect , $matches )) {
2012-10-17 14:28:05 -04:00
$this -> sqlSelect = 'SELECT ' . $matches [ 1 ] . (( $matches [ 2 ] != '' ) ? ' FROM ' . $matches [ 2 ] : '' );
$this -> sqlSelect = 'SELECT ' . $matches [ 1 ] . (( $matches [ 2 ] != '' ) ? ' FROM ' . $matches [ 2 ] : '' );
2010-12-02 23:34:41 +00:00
} else {
2012-10-17 14:28:05 -04:00
//echo('Warning: SQL Query is not well formed.');
return ;
}
2017-12-04 13:25:35 +00:00
$this -> sqlFrom = isset ( $matches [ 2 ]) ? $matches [ 2 ] : '' ;
$this -> sqlWhere = isset ( $matches [ 3 ]) ? $matches [ 3 ] : '' ;
$this -> sqlGroupBy = isset ( $matches [ 4 ]) ? $matches [ 4 ] : '' ;
$this -> sqlOrderBy = isset ( $matches [ 5 ]) ? $matches [ 5 ] : '' ;
2012-10-17 14:28:05 -04:00
$this -> order = '' ;
if ( $this -> sqlOrderBy != '' ) {
2017-12-04 13:25:35 +00:00
if ( $n = preg_match_all ( '/\b([\w\.]+)\b(?:\s+(ASC|DESC))?,?/im' , $this -> sqlOrderBy , $matches , PREG_SET_ORDER )) {
for ( $r = 0 ; $r < $n ; $r ++ ) {
if ( ! isset ( $matches [ $r ][ 2 ])) {
2012-10-17 14:28:05 -04:00
$matches [ $r ][ 2 ] = '' ;
}
if ( $matches [ $r ][ 2 ] == '' ) {
$matches [ $r ][ 2 ] = 'ASC' ;
}
2017-12-04 13:25:35 +00:00
$ord = G :: createUID ( '' , $matches [ $r ][ 1 ]) . '=' . urlencode ( $matches [ $r ][ 2 ]);
2012-10-17 14:28:05 -04:00
if ( $this -> order == '' ) {
$this -> order = $ord ;
} else {
$this -> order .= '&' . $ord ;
}
}
//Orden ascendente
if ( $n == 1 ) {
2017-12-04 13:25:35 +00:00
$this -> order = G :: createUID ( '' , $matches [ 0 ][ 1 ]) . '=' . $matches [ 0 ][ 2 ];
2012-10-17 14:28:05 -04:00
}
}
}
//Generate: $uniqueWhere=Identify a row bys its data content
//$this->fieldDataList=url text that dentify a row bys its data content
$uniqueWhere = '' ;
$this -> fieldDataList = '' ;
foreach ( $this -> fields as $r => $field ) {
2017-12-04 13:25:35 +00:00
if (( strpos ( $this -> notFields , ' ' . $this -> fields [ $r ][ 'Type' ] . ' ' ) === false )) {
2012-10-17 14:28:05 -04:00
if ( $uniqueWhere == '' ) {
$uniqueWhere = (( $this -> sqlWhere != '' ) ? ( '(' . $this -> sqlWhere . ') AND (' ) : '(' );
} else {
$uniqueWhere .= ' AND ' ;
}
$uniqueWhere .= $this -> fields [ $r ][ 'Name' ] . '=' . '@@' . $this -> fields [ $r ][ 'Name' ];
if ( $this -> fieldDataList == '' ) {
$this -> fieldDataList = '' ;
} else {
$this -> fieldDataList .= '&' ;
}
$this -> fieldDataList .= $this -> fields [ $r ][ 'Name' ] . '=' . '@@_' . $this -> fields [ $r ][ 'Name' ];
}
}
if ( $uniqueWhere != '' ) {
$uniqueWhere .= ')' ;
2010-12-02 23:34:41 +00:00
}
}
2012-10-17 14:28:05 -04:00
2010-12-02 23:34:41 +00:00
/**
2012-10-17 14:28:05 -04:00
* Function prepareQuery
*
* @ author David S . Callizaya S . < davidsantos @ colosa . com >
* @ access public
* @ return string
*/
2017-12-04 13:25:35 +00:00
public function prepareQuery ()
2012-10-17 14:28:05 -04:00
{
//DBConnection
2017-12-04 13:25:35 +00:00
if ( ! $this -> sqlConnection ) {
2012-10-17 14:28:05 -04:00
$this -> dbc = new DBConnection ();
} else {
2017-12-04 13:25:35 +00:00
if ( defined ( 'DB_' . $this -> sqlConnection . '_USER' )) {
if ( defined ( 'DB_' . $this -> sqlConnection . '_HOST' )) {
eval ( '$res[\'DBC_SERVER\'] = DB_' . $this -> sqlConnection . '_HOST;' );
2012-10-17 14:28:05 -04:00
} else {
$res [ 'DBC_SERVER' ] = DB_HOST ;
}
2017-12-04 13:25:35 +00:00
if ( defined ( 'DB_' . $this -> sqlConnection . '_USER' )) {
eval ( '$res[\'DBC_USERNAME\'] = DB_' . $this -> sqlConnection . '_USER;' );
2012-10-17 14:28:05 -04:00
}
2017-12-04 13:25:35 +00:00
if ( defined ( 'DB_' . $this -> sqlConnection . '_PASS' )) {
eval ( '$res[\'DBC_PASSWORD\'] = DB_' . $this -> sqlConnection . '_PASS;' );
2012-10-17 14:28:05 -04:00
} else {
$res [ 'DBC_PASSWORD' ] = DB_PASS ;
}
2017-12-04 13:25:35 +00:00
if ( defined ( 'DB_' . $this -> sqlConnection . '_NAME' )) {
eval ( '$res[\'DBC_DATABASE\'] = DB_' . $this -> sqlConnection . '_NAME;' );
2012-10-17 14:28:05 -04:00
} else {
$res [ 'DBC_DATABASE' ] = DB_NAME ;
}
2017-12-04 13:25:35 +00:00
if ( defined ( 'DB_' . $this -> sqlConnection . '_TYPE' )) {
eval ( '$res[\'DBC_TYPE\'] = DB_' . $this -> sqlConnection . '_TYPE;' );
2012-10-17 14:28:05 -04:00
} else {
2017-12-04 13:25:35 +00:00
$res [ 'DBC_TYPE' ] = defined ( 'DB_TYPE' ) ? DB_TYPE : 'mysql' ;
2012-10-17 14:28:05 -04:00
}
2017-12-04 13:25:35 +00:00
$this -> dbc = new DBConnection ( $res [ 'DBC_SERVER' ], $res [ 'DBC_USERNAME' ], $res [ 'DBC_PASSWORD' ], $res [ 'DBC_DATABASE' ], $res [ 'DBC_TYPE' ]);
2012-10-17 14:28:05 -04:00
} else {
$dbc = new DBConnection ();
2017-12-04 13:25:35 +00:00
$dbs = new DBSession ( $dbc );
$res = $dbs -> execute ( " select * from DB_CONNECTION WHERE DBC_UID= " . $this -> sqlConnection );
2012-10-17 14:28:05 -04:00
$res = $res -> read ();
2017-12-04 13:25:35 +00:00
$this -> dbc = new DBConnection ( $res [ 'DBC_SERVER' ], $res [ 'DBC_USERNAME' ], $res [ 'DBC_PASSWORD' ], $res [ 'DBC_DATABASE' ]);
2012-10-17 14:28:05 -04:00
}
}
2017-12-04 13:25:35 +00:00
$this -> ses = new DBSession ( $this -> dbc );
2012-10-17 14:28:05 -04:00
//Query
//Filter
2017-12-04 13:25:35 +00:00
if ( is_array ( $this -> filter )) {
2012-10-17 14:28:05 -04:00
$filterFields = $this -> filter ;
} else {
2017-12-04 13:25:35 +00:00
parse_str ( $this -> filter , $filterFields );
2012-10-17 14:28:05 -04:00
}
$this -> aFilter = $filterFields ;
$filter = '' ;
foreach ( $filterFields as $field => $like ) {
2017-12-04 13:25:35 +00:00
if ( $like !== '' ) {
2012-10-17 14:28:05 -04:00
if ( $filter !== '' ) {
$filter .= ' AND ' ;
}
2017-12-04 13:25:35 +00:00
$like = mysqli_real_escape_string ( $this -> dbc , $like );
if ( isset ( $this -> filterType [ $field ])) {
2012-10-17 14:28:05 -04:00
switch ( $this -> filterType [ $field ]) {
case '=' :
2017-12-04 13:25:35 +00:00
$filter .= $field . ' = "' . $like . '"' ;
2012-10-17 14:28:05 -04:00
break ;
case '<>' :
2017-12-04 13:25:35 +00:00
$filter .= $field . ' <> "' . $like . '"' ;
2012-10-17 14:28:05 -04:00
break ;
case 'contains' :
2017-12-04 13:25:35 +00:00
$filter .= $field . ' LIKE "%' . $like . '%"' ;
2012-10-17 14:28:05 -04:00
break ;
case 'like' :
2017-12-04 13:25:35 +00:00
$filter .= $field . ' LIKE "' . $like . '"' ;
2012-10-17 14:28:05 -04:00
break ;
}
} else {
2017-12-04 13:25:35 +00:00
$filter .= $field . ' = "' . $like . '"' ;
2012-10-17 14:28:05 -04:00
}
}
}
/*
* QuickSearch
*/
if ( $this -> searchBy !== '' ) {
2017-12-04 13:25:35 +00:00
$aSB = explode ( '|' , $this -> searchBy );
2012-10-17 14:28:05 -04:00
$subFilter = '' ;
foreach ( $aSB as $sBy ) {
$subFilter .= ( $subFilter !== '' ) ? ' OR ' : '' ;
2017-12-04 13:25:35 +00:00
$subFilter .= $sBy . ' LIKE "%' . G :: sqlEscape ( $this -> fastSearch , $this -> dbc -> type ) . '%"' ;
2012-10-17 14:28:05 -04:00
}
if ( $subFilter !== '' ) {
$filter .= ( $filter !== '' ) ? ' AND ' : '' ;
$filter .= '(' . $subFilter . ')' ;
}
}
//Merge sort array defined by USER with the array defined by SQL
2017-12-04 13:25:35 +00:00
parse_str ( $this -> order , $orderFields );
parse_str ( $this -> orderBy , $orderFields2 );
2012-10-17 14:28:05 -04:00
//User sort is more important (first in merge).
2017-12-04 13:25:35 +00:00
$orderFields3 = array_merge ( $orderFields2 , $orderFields );
2012-10-17 14:28:05 -04:00
//User sort is overwrites XMLs definition.
2017-12-04 13:25:35 +00:00
$orderFields = array_merge ( $orderFields3 , $orderFields2 );
2012-10-17 14:28:05 -04:00
//Order (BY SQL DEFINITION AND USER'S DEFINITION)
2017-12-04 13:25:35 +00:00
$this -> aOrder = array ();
2012-10-17 14:28:05 -04:00
$order = '' ;
foreach ( $orderFields as $field => $fieldOrder ) {
2017-12-04 13:25:35 +00:00
$field = G :: getUIDName ( $field , '' );
$fieldOrder = strtoupper ( $fieldOrder );
2012-10-17 14:28:05 -04:00
if ( $fieldOrder === 'A' ) {
$fieldOrder = 'ASC' ;
}
if ( $fieldOrder === 'D' ) {
$fieldOrder = 'DESC' ;
}
switch ( $fieldOrder ) {
case 'ASC' :
case 'DESC' :
if ( $order !== '' ) {
$order .= ', ' ;
}
$order .= $field . ' ' . $fieldOrder ;
$this -> aOrder [ $field ] = $fieldOrder ;
}
}
$this -> sql = $this -> sqlSelect . ((( $this -> sqlWhere != '' ) || ( $filter != '' )) ? ' WHERE ' : '' ) . (( $this -> sqlWhere != '' ) ? '(' . $this -> sqlWhere . ')' : '' ) . ((( $this -> sqlWhere != '' ) && ( $filter != '' )) ? ' AND ' : '' ) . (( $filter != '' ) ? '(' . $filter . ')' : '' ) . (( $this -> sqlGroupBy != '' ) ? ' GROUP BY ' . $this -> sqlGroupBy : '' ) . (( $order != '' ) ? ' ORDER BY ' . $order : '' );
//$this->query=$this->ses->execute($this->sql);
//$this->totpages=ceil($this->query->count()/$this->rowsPerPage);
return ;
2010-12-02 23:34:41 +00:00
}
2012-10-17 14:28:05 -04:00
/**
* Function setupFromXmlform
*
* @ author David S . Callizaya S . < davidsantos @ colosa . com >
* @ access public
* @ param string xmlForm
* @ return string
*/
2017-12-04 13:25:35 +00:00
public function setupFromXmlform ( $xmlForm )
2012-10-17 14:28:05 -04:00
{
$this -> xmlForm = $xmlForm ;
//Config
$this -> name = $xmlForm -> name ;
$this -> id = $xmlForm -> id ;
2017-12-04 13:25:35 +00:00
$this -> sqlConnection = (( isset ( $this -> xmlForm -> sqlConnection )) ? $this -> xmlForm -> sqlConnection : '' );
if ( isset ( $_GET [ 'page' ])) {
2012-10-17 14:28:05 -04:00
$this -> currentPage = $_GET [ 'page' ];
} else {
$this -> currentPage = 1 ;
}
2017-12-04 13:25:35 +00:00
if ( isset ( $_GET [ 'order' ])) {
$this -> orderBy = urldecode ( $_GET [ 'order' ]);
2012-10-17 14:28:05 -04:00
} else {
$this -> orderBy = " " ;
}
2017-12-04 13:25:35 +00:00
if ( isset ( $_GET [ 'filter' ])) {
$this -> filter = urldecode ( $_GET [ 'filter' ]);
2012-10-17 14:28:05 -04:00
} else {
$this -> filter = " " ;
}
2025-09-24 14:18:54 +00:00
$this -> ajaxServer = '../gulliver/pagedTableAjax' ;
$this -> ownerPage = SYS_CURRENT_URI ;
2012-10-17 14:28:05 -04:00
//Needed for $mysql_real_escape_string
$auxDbc = new DBConnection ();
2017-12-04 13:25:35 +00:00
if ( isset ( $this -> xmlForm -> sql )) {
$this -> sqlSelect = G :: replaceDataField ( $this -> xmlForm -> sql , $this -> xmlForm -> values );
2012-10-17 14:28:05 -04:00
} else {
2017-12-04 13:25:35 +00:00
trigger_Error ( 'Warning: sql query is empty' , E_USER_WARNING );
2012-10-17 14:28:05 -04:00
}
// Config attributes from XMLFORM file
2017-12-04 13:25:35 +00:00
$myAttributes = get_class_vars ( get_class ( $this ));
2012-10-17 14:28:05 -04:00
foreach ( $this -> xmlForm -> xmlform -> tree -> attribute as $atrib => $value ) {
2022-08-31 11:32:16 -04:00
if ( is_array ( $myAttributes ) && array_key_exists ( $atrib , $myAttributes )) {
2017-12-04 13:25:35 +00:00
eval ( 'settype($value,gettype($this->' . $atrib . '));' );
2012-10-17 14:28:05 -04:00
if ( $value !== '' ) {
2017-12-04 13:25:35 +00:00
eval ( '$this->' . $atrib . '=$value;' );
2012-10-17 14:28:05 -04:00
}
}
}
//Prepare the fields
2017-12-04 13:25:35 +00:00
$this -> style = array ();
2012-10-17 14:28:05 -04:00
$this -> gridWidth = " " ;
$this -> gridFields = " " ;
2017-12-04 13:25:35 +00:00
$this -> fieldsType = array ();
2012-10-17 14:28:05 -04:00
foreach ( $this -> xmlForm -> fields as $f => $v ) {
$r = $f ;
$this -> fields [ $r ][ 'Name' ] = $this -> xmlForm -> fields [ $f ] -> name ;
$this -> fields [ $r ][ 'Type' ] = $this -> xmlForm -> fields [ $f ] -> type ;
2017-12-04 13:25:35 +00:00
if ( isset ( $this -> xmlForm -> fields [ $f ] -> size )) {
2012-10-17 14:28:05 -04:00
$this -> fields [ $r ][ 'Size' ] = $this -> xmlForm -> fields [ $f ] -> size ;
}
$this -> fields [ $r ][ 'Label' ] = $this -> xmlForm -> fields [ $f ] -> label ;
}
//Autocomplete the sql queries
// Here we can to distribute the component of the query like: Select, Where, Group by and order by
$this -> analizeSql ();
//Set the default settings
$this -> defaultStyle ();
//continue whith the setup
$this -> gridWidth = '' ;
$this -> gridFields = '' ;
foreach ( $this -> xmlForm -> fields as $f => $v ) {
$r = $f ;
//Parse the column properties
foreach ( $this -> xmlForm -> fields [ $f ] as $attribute => $value ) {
2017-12-04 13:25:35 +00:00
if ( ! is_object ( $value )) {
2012-10-17 14:28:05 -04:00
$this -> style [ $r ][ $attribute ] = $value ;
}
}
//Needed for javascript
//only the visible columns's width and name are stored
if ( $this -> style [ $r ][ 'showInTable' ] != '0' ) {
$this -> gridWidth .= ',' . $this -> style [ $r ][ 'colWidth' ];
$this -> gridFields .= ',"form[' . $this -> fields [ $r ][ 'Name' ] . ']"' ;
}
}
$totalWidth = 0 ;
foreach ( $this -> fields as $r => $rval ) {
if ( $this -> style [ $r ][ 'showInTable' ] != '0' ) {
$totalWidth += $this -> style [ $r ][ 'colWidth' ];
}
}
$this -> totalWidth = $totalWidth ;
2010-12-02 23:34:41 +00:00
}
2012-10-17 14:28:05 -04:00
/**
* Function setupFromTable
*
* @ author David S . Callizaya S . < davidsantos @ colosa . com >
* @ access public
* @ param eter string table
* @ return string
*/
// function setupFromTable($table)
// {
//// var_dump2($table);
// //Config
// $this->rowsPerPage=25;
// if (isset($_GET['page']))
// $this->currentPage = $_GET['page'];
// else
// $this->currentPage = 1;
// if (isset($_GET['order']))
// $this->orderBy = urldecode($_GET['order']);
// else
// $this->orderBy = "";
// if (isset($_GET['filter']))
// $this->filter = urldecode($_GET['filter']);
// else
// $this->filter = "";
// $xmlPopup='';
// $this->xmlFormFile="";
///* if ($table->Action)
2025-09-24 14:18:54 +00:00
// $this->ajaxServer=$table->Action;
2012-10-17 14:28:05 -04:00
// else*/
2025-09-24 14:18:54 +00:00
// $this->ajaxServer='../gulliver/pagedTableAjax';
2012-10-17 14:28:05 -04:00
// $this->popupPage = $this->ajaxServer . '?function=printForm&filename=' . urlencode($xmlPopup);
2025-09-24 14:18:54 +00:00
// $this->ownerPage=SYS_CURRENT_URI;
2012-10-17 14:28:05 -04:00
// $this->sqlConnection='';
// if (isset($table->_source))
// $this->sqlSelect=$table->_source;
// if (isset($table->WhereClause)){
// if (strpos(strtoupper($table->WhereClause),'GROUP BY')!==FALSE)
// preg_match("/(.+)(GROUP BY)(.*)/",$table->WhereClause,$matches);
// else{
// $matches[1]=$table->WhereClause;$matches[2]='';
// }
// $this->sqlWhere=$matches[1];
// if (strcasecmp($matches[2],'GROUP BY')==0)
// $this->sqlGroupBy=' GROUP BY '.$matches[3];
// }
// if (strpos(strtoupper($this->sqlSelect),'WHERE')!==FALSE){
// preg_match("/SELECT(.+)FROM(.+)WHERE(.+)/",$this->sqlSelect,$matches);
// $this->sqlSelect='SELECT '.$matches[1].' FROM '.$matches[2];
// $this->sqlWhere=$matches[3];
// }
// // DBConnection
// // $this->prepareQuery();
// //Prepare the fields
// if ($table->show_nummbers=='YES'){
// $r=-1;
// $this->fields[$r]['Name']='numberlabel';
// $this->fields[$r]['Type']='numberlabel';
// $this->fields[$r]['Label']='#';
// }
// foreach ($table->Columns as $r => $value){
// $this->fields[$r]['Name']=$value['Name'];
// $this->fields[$r]['Type']=$value['Type'];
// $this->fields[$r]['Label']=((isset($table->Labels[$r]))?$table->Labels[$r]:'');
// //Default values for Label if it was empty
// if ($this->fields[$r]['Label']=='')
// switch($table->Columns[$r]['Type']){
// case 'image':
// case 'image-text':
// case 'jslink':
// //var_dump2($table->Columns[$r]);
// $this->fields[$r]['Label']=$value['Name'];
// }
// //Print the type of the field
// //$this->fields[$r]['Label'].='('.$this->fields[$r]['Type'].')';
// $r++;
// }
// //Add a delete column if sqlDelete is established
// /* if ($this->sqlDelete!='')
// {
// $this->fields[$r]['Name']='';
// $this->fields[$r]['Type']='linknew';
// $this->fields[$r]['Label']=G::LoadXml('labels','ID_DELETE');
// }*/
// //Set the default settings
// $this->defaultStyle();
// /* if ($this->sqlDelete!='')
// {
// $this->style[$r]['href']="#";
// $this->style[$r]['onclick']="document.getElementById('pagedTable').outerHTML=ajax_function('{$this->ajaxServer}','delete','".$this->fieldDataList."');";
// }*/
// //Prepare the columns's properties
// if ($table->show_nummbers=='YES'){
// $r=-1;
// $this->style[$r]['data']='@@_row__';
// $this->style[$r]['colWidth']=30;
// }
// $this->gridWidth='';
// $this->gridFields='';
// foreach ($table->Columns as $r => $value){
// //var_dump($value['Width']);
// $this->style[$r]['colWidth']=$value['Width'];
// $this->style[$r]['titleAlign']=$value['Align'];
// $this->style[$r]['href']=$value['Target'];
// // Add the row reference
// switch ($this->fields[$r]['Type']){
// case 'image-text':
// case 'textimage':
// case 'image':
// case 'link':
// //$this->style[$r]['href'].='/@@_row__.html'; // No
// if (substr($value['Content'],0,1)=='&')
// $this->style[$r]['href'].='/@@_'.substr($value['Content'],1).'.html';
// }
// // Extra events for each field
// $this->style[$r]['event']=$value['Extra'];
// if ($this->fields[$r]['Label']==''){
// $this->style[$r]['titleVisibility']='0';
// $this->fields[$r]['Label']=$this->fields[$r]['Name'];
// }
// //if ($value['orderByThis']===true) $this->orderBy=$value['Name'];
// //Needed for javascript
// //only the visible columns's width and name are stored
// if ($this->style[$r]['showInTable']!='0'){
// $this->gridWidth.=','.$this->style[$r]['colWidth'];
// $this->gridFields.=',"form['.$this->fields[$r]['Name'].']"';
// }
// $r++;
// }
// echo('<br>');
//// var_dump2($this);
// }
/**
* Function count
*
* @ author David S . Callizaya S . < davidsantos @ colosa . com >
* @ access public
* @ return string
*/
2017-12-04 13:25:35 +00:00
public function count ()
2012-10-17 14:28:05 -04:00
{
$this -> prepareQuery ();
return $this -> query -> count ();
2010-12-02 23:34:41 +00:00
}
2012-10-17 14:28:05 -04:00
/**
* Function renderTitle
*
* @ author David S . Callizaya S . < davidsantos @ colosa . com >
* @ access public
* @ return string
*/
2017-12-04 13:25:35 +00:00
public function renderTitle ()
2012-10-17 14:28:05 -04:00
{
//Render Title
$thereisnotitle = true ;
foreach ( $this -> fields as $r => $rval ) {
if ( $this -> fields [ $r ][ 'Type' ] === 'title' ) {
2017-12-04 13:25:35 +00:00
$this -> tpl -> assign ( " title " , $this -> fields [ $r ][ 'Label' ]);
2012-10-17 14:28:05 -04:00
$thereisnotitle = false ;
}
}
if ( $thereisnotitle ) {
2017-12-04 13:25:35 +00:00
$this -> tpl -> assign ( " title " , ' ' );
2012-10-17 14:28:05 -04:00
}
//Render headers
$this -> colCount = 0 ;
$this -> shownFields = '[' ;
foreach ( $this -> fields as $r => $rval ) {
if ( $this -> style [ $r ][ 'showInTable' ] != '0' ) {
2017-12-04 13:25:35 +00:00
$this -> tpl -> newBlock ( " headers " );
$sortOrder = ((( isset ( $this -> aOrder [ $this -> fields [ $r ][ 'Name' ]])) && ( $this -> aOrder [ $this -> fields [ $r ][ 'Name' ]] === 'ASC' )) ? 'DESC' : 'ASC' );
$sortOrder = ((( isset ( $this -> aOrder [ $this -> fields [ $r ][ 'Name' ]])) && ( $this -> aOrder [ $this -> fields [ $r ][ 'Name' ]] === 'DESC' )) ? '' : $sortOrder );
$this -> style [ $r ][ 'href' ] = $this -> ownerPage . '?order=' . ( $sortOrder !== '' ? urlencode ( G :: createUID ( '' , $this -> fields [ $r ][ 'Name' ]) . '=' . $sortOrder ) : '' ) . '&page=' . $this -> currentPage ;
$this -> style [ $r ][ 'onsort' ] = $this -> id . '.doSort("' . G :: createUID ( '' , $this -> fields [ $r ][ 'Name' ]) . '" , "' . $sortOrder . '");return false;' ;
if ( isset ( $this -> style [ $r ][ 'href' ])) {
$this -> tpl -> assign ( " href " , $this -> style [ $r ][ 'href' ]);
2012-10-17 14:28:05 -04:00
}
2017-12-04 13:25:35 +00:00
if ( isset ( $this -> style [ $r ][ 'onsort' ])) {
$this -> tpl -> assign ( " onclick " , htmlentities ( $this -> style [ $r ][ 'onsort' ], ENT_QUOTES , 'UTF-8' ));
2012-10-17 14:28:05 -04:00
}
2017-12-04 13:25:35 +00:00
if ( isset ( $this -> style [ $r ][ 'colWidth' ])) {
$this -> tpl -> assign ( " width " , $this -> style [ $r ][ 'colWidth' ]);
2012-10-17 14:28:05 -04:00
}
2017-12-04 13:25:35 +00:00
if ( isset ( $this -> style [ $r ][ 'colWidth' ])) {
$this -> tpl -> assign ( " widthPercent " , ( $this -> style [ $r ][ 'colWidth' ] * 100 / $this -> totalWidth ) . " % " );
2012-10-17 14:28:05 -04:00
}
2017-12-04 13:25:35 +00:00
if ( isset ( $this -> style [ $r ][ 'titleAlign' ])) {
$this -> tpl -> assign ( " align " , 'text-align:' . $this -> style [ $r ][ 'titleAlign' ] . ';' );
2012-10-17 14:28:05 -04:00
}
if ( $this -> style [ $r ][ 'titleVisibility' ] != '0' ) {
2017-12-04 13:25:35 +00:00
$sortOrder = ((( isset ( $this -> aOrder [ $this -> fields [ $r ][ 'Name' ]])) && ( $this -> aOrder [ $this -> fields [ $r ][ 'Name' ]] === 'ASC' )) ? 'b 2' : '' );
$sortOrder = ((( isset ( $this -> aOrder [ $this -> fields [ $r ][ 'Name' ]])) && ( $this -> aOrder [ $this -> fields [ $r ][ 'Name' ]] === 'DESC' )) ? 'b <' : $sortOrder );
$this -> tpl -> assign ( " header " , $this -> fields [ $r ][ 'Label' ] . $sortOrder );
$this -> tpl -> assign ( 'displaySeparator' , (( $this -> colCount == 0 ) || ( ! isset ( $this -> fields [ $r ][ 'Label' ])) || ( $this -> fields [ $r ][ 'Label' ] === '' )) ? 'display:none;' : '' );
2012-10-17 14:28:05 -04:00
} else {
2017-12-04 13:25:35 +00:00
$this -> tpl -> assign ( 'displaySeparator' , 'display:none;' );
2012-10-17 14:28:05 -04:00
}
$this -> colCount += 2 ;
$this -> shownFields .= ( $this -> shownFields !== '[' ) ? ',' : '' ;
$this -> shownFields .= '"' . $r . '"' ;
}
}
$this -> shownFields .= ']' ;
2010-12-02 23:34:41 +00:00
}
2012-10-17 14:28:05 -04:00
/**
* Function renderField
*
* @ author David S . Callizaya S . < davidsantos @ colosa . com >
* @ access public
* @ param eter string row
* @ param eter string r
* @ param eter string result
* @ return string
*/
2017-12-04 13:25:35 +00:00
public function renderField ( $row , $r , $result )
2012-10-17 14:28:05 -04:00
{
global $G_DATE_FORMAT ;
//BEGIN: Special content: __sqlEdit__,__sqlDelete__
$result [ 'sqlDelete__' ] = " pagedTable.event='Delete';pagedTable_DoIt=true;if (pagedTable.onDeleteField) pagedTable_DoIt=eval(pagedTable.onDeleteField);if (pagedTable_DoIt) document.getElementById('pagedTable').outerHTML=ajax_function(' { $this -> ajaxServer } ','delete','field='+encodeURIComponent(' " . ( $this -> fieldDataList ) . " '));if (pagedTable.afterDeleteField) return eval(pagedTable.afterDeleteField); else return false; " ;
$result [ 'sqlEdit__' ] = " pagedTable.event='Update';pagedTable.field=encodeURIComponent(' " . $this -> fieldDataList . " ');pagedTable.updateField(pagedTable.field);return false; " ;
$result [ 'pagedTableField__' ] = " ' " . $this -> fieldDataList . " ' " ;
$result [ 'row__' ] = $row ;
//END: Special content.
//Merge $result with $xmlForm values (for default valuesSettings)
2017-12-04 13:25:35 +00:00
$result = array_merge ( $this -> xmlForm -> values , $result );
2012-10-17 14:28:05 -04:00
switch ( true ) {
case ( $this -> style [ $r ][ 'data' ] != '' ) :
2017-12-04 13:25:35 +00:00
$value = (( isset ( $result [ $this -> style [ $r ][ 'data' ]])) ? $result [ $this -> style [ $r ][ 'data' ]] : '' );
2012-10-17 14:28:05 -04:00
break ;
default :
$value = $this -> fields [ $r ][ 'Label' ];
}
switch ( $this -> fields [ $r ][ 'Type' ]) {
case 'date' :
/*Accept dates like 20070515 without - or / to separate its parts*/
2017-12-04 13:25:35 +00:00
if ( strlen ( $value ) <= 10 && strlen ( $value ) > 4 ) {
$value = str_replace ( '/' , '-' , $value );
if ( strpos ( $value , '-' ) === false ) {
$value = substr ( $value , 0 , 4 ) . '-' . substr ( $value , 4 , 2 ) . '-' . substr ( $value , 6 , 2 );
2012-10-17 14:28:05 -04:00
}
}
}
2017-12-04 13:25:35 +00:00
$this -> tpl -> newBlock ( " field " );
$this -> tpl -> assign ( 'width' , $this -> style [ $r ][ 'colWidth' ]);
$this -> tpl -> assign ( 'widthPercent' , ( $this -> style [ $r ][ 'colWidth' ] * 100 / $this -> totalWidth ) . '%' );
$this -> tpl -> assign ( 'className' , ( isset ( $this -> style [ $r ][ 'colClassName' ]) && ( $this -> style [ $r ][ 'colClassName' ])) ? $this -> style [ $r ][ 'colClassName' ] : $this -> tdClass );
$this -> tpl -> assign ( 'style' , $this -> tdStyle );
if ( isset ( $this -> style [ $r ][ 'align' ])) {
$this -> tpl -> assign ( " align " , $this -> style [ $r ][ 'align' ]);
2012-10-17 14:28:05 -04:00
}
2017-12-04 13:25:35 +00:00
if ( isset ( $this -> style [ $r ][ 'colAlign' ])) {
$this -> tpl -> assign ( " align " , $this -> style [ $r ][ 'colAlign' ]);
2012-10-17 14:28:05 -04:00
}
/**
* BEGIN : Reeplace of @@ , @% , ...
* in field ' s attributes like onclick , link ,
* ...
*/
2017-12-04 13:25:35 +00:00
if ( isset ( $this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]] -> onclick )) {
$this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]] -> onclick = G :: replaceDataField ( $this -> style [ $r ][ 'onclick' ], $result );
2012-10-17 14:28:05 -04:00
}
2017-12-04 13:25:35 +00:00
if ( isset ( $this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]] -> link )) {
$this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]] -> link = G :: replaceDataField ( $this -> style [ $r ][ 'link' ], $result );
2012-10-17 14:28:05 -04:00
}
2017-12-04 13:25:35 +00:00
if ( isset ( $this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]] -> value )) {
$this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]] -> value = G :: replaceDataField ( $this -> style [ $r ][ 'value' ], $result );
2012-10-17 14:28:05 -04:00
}
/**
* BREAK : Reeplace of @@ , @% , ...
*/
/**
* Rendering of the field
*/
$this -> xmlForm -> setDefaultValues ();
2017-12-04 13:25:35 +00:00
$this -> xmlForm -> setValues ( $result );
2012-10-17 14:28:05 -04:00
$this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]] -> mode = 'view' ;
2017-12-04 13:25:35 +00:00
if (( array_search ( 'rendergrid' , get_class_methods ( get_class ( $this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]]))) !== false ) || ( array_search ( 'renderGrid' , get_class_methods ( get_class ( $this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]]))) !== false )) {
$htmlField = $this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]] -> renderGrid ( array ( $value
), $this -> xmlForm );
$this -> tpl -> assign ( " value " , $htmlField [ 0 ]);
2012-10-17 14:28:05 -04:00
} else {
}
/**
* CONTINUE : Reeplace of @@ , @% , ...
*/
2017-12-04 13:25:35 +00:00
if ( isset ( $this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]] -> onclick )) {
2012-10-17 14:28:05 -04:00
$this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]] -> onclick = $this -> style [ $r ][ 'onclick' ];
}
2017-12-04 13:25:35 +00:00
if ( isset ( $this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]] -> link )) {
2012-10-17 14:28:05 -04:00
$this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]] -> link = $this -> style [ $r ][ 'link' ];
}
2017-12-04 13:25:35 +00:00
if ( isset ( $this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]] -> value )) {
2012-10-17 14:28:05 -04:00
$this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]] -> value = $this -> style [ $r ][ 'value' ];
}
/**
* END : Reeplace of @@ , @% , ...
*/
return $this -> fields [ $r ][ 'Type' ];
2010-12-02 23:34:41 +00:00
}
2012-10-17 14:28:05 -04:00
/**
* Function defaultStyle
*
* @ author David S . Callizaya S . < davidsantos @ colosa . com >
* @ access public
* @ return string
*/
2017-12-04 13:25:35 +00:00
public function defaultStyle ()
2012-10-17 14:28:05 -04:00
{
// for($r=1;$r<=sizeof($this->fields);$r++)
foreach ( $this -> fields as $r => $rval ) {
2017-12-04 13:25:35 +00:00
$this -> style [ $r ] = array ( 'showInTable' => '1' , 'titleVisibility' => '1' , 'colWidth' => '150' , 'onclick' => '' , 'event' => ''
2012-10-17 14:28:05 -04:00
);
//Some widths
2017-12-04 13:25:35 +00:00
if ( ! ( strpos ( ' date linknew ' , ' ' . $this -> fields [ $r ][ 'Type' ] . ' ' ) === false )) {
2012-10-17 14:28:05 -04:00
$this -> style [ $r ][ 'colWidth' ] = '70' ;
//Data source:
}
2017-12-04 13:25:35 +00:00
if ( ! ( strpos ( ' title button linknew image-text jslink ' , ' ' . $this -> fields [ $r ][ 'Type' ] . ' ' ) === false )) {
2012-10-17 14:28:05 -04:00
$this -> style [ $r ][ 'data' ] = '' ; //If the control is a link it shows the label
} else {
$this -> style [ $r ][ 'data' ] = $this -> fields [ $r ][ 'Name' ]; //ELSE: The data value for that field
}
2017-12-04 13:25:35 +00:00
//Hidden fields
if ( ! isset ( $this -> style [ $r ][ 'showInTable' ])) {
if ( ! ( strpos ( ' title button endgrid2 submit password ' , ' ' . $this -> fields [ $r ][ 'Type' ] . ' ' ) === false )) {
2012-10-17 14:28:05 -04:00
$this -> style [ $r ][ 'showInTable' ] = '0' ;
} else {
$this -> style [ $r ][ 'showInTable' ] = '1' ;
}
}
//Hidden titles
2017-12-04 13:25:35 +00:00
if ( ! ( strpos ( ' linknew button endgrid2 ' , ' ' . $this -> fields [ $r ][ 'Type' ] . ' ' ) === false )) {
2012-10-17 14:28:05 -04:00
$this -> style [ $r ][ 'titleVisibility' ] = '0' ;
}
//Align titles
$this -> style [ $r ][ 'titleAlign' ] = 'center' ;
//Align fields
2017-12-04 13:25:35 +00:00
if ( isset ( $_SESSION [ 'SET_DIRECTION' ]) && ( strcasecmp ( $_SESSION [ 'SET_DIRECTION' ], 'rtl' ) === 0 )) {
2012-10-17 14:28:05 -04:00
$this -> style [ $r ][ 'align' ] = 'right' ;
} else {
$this -> style [ $r ][ 'align' ] = 'left' ;
}
2017-12-04 13:25:35 +00:00
if ( ! ( strpos ( ' linknew date ' , ' ' . $this -> fields [ $r ][ 'Type' ] . ' ' ) === false )) {
2012-10-17 14:28:05 -04:00
$this -> style [ $r ][ 'align' ] = 'center' ;
}
}
// Adjust the columns width to prevent overflow the page width
//Render headers
$totalWidth = 0 ;
foreach ( $this -> fields as $r => $rval ) {
if ( $this -> style [ $r ][ 'showInTable' ] != '0' ) {
$totalWidth += $this -> style [ $r ][ 'colWidth' ];
}
}
$this -> totalWidth = $totalWidth ;
$maxWidth = 1800 ;
$proportion = $totalWidth / $maxWidth ;
if ( $proportion > 1 ) {
$this -> totalWidth = 1800 ;
}
if ( $proportion > 1 ) {
foreach ( $this -> fields as $r => $rval ) {
if ( $this -> style [ $r ][ 'showInTable' ] != '0' ) {
$this -> style [ $r ][ 'colWidth' ] = $this -> style [ $r ][ 'colWidth' ] / $proportion ;
}
}
}
2010-12-02 23:34:41 +00:00
}
2012-10-17 14:28:05 -04:00
/**
* Function renderTable
*
* @ author David S . Callizaya S . < davidsantos @ colosa . com >
* @ param $block : = 'content' ( Prints contentBlock only )
* @ access public
* @ return string
*/
2017-12-04 13:25:35 +00:00
public function renderTable ( $block = '' )
2012-10-17 14:28:05 -04:00
{
2015-03-17 15:25:49 -04:00
$filter = new InputFilter ();
2017-12-04 13:25:35 +00:00
$this -> orderBy = $filter -> xssFilterHard ( $this -> orderBy );
$this -> currentPage = $filter -> xssFilterHard ( $this -> currentPage );
$this -> id = $filter -> xssFilterHard ( $this -> id );
$this -> name = $filter -> xssFilterHard ( $this -> name );
$this -> ownerPage = $filter -> xssFilterHard ( $this -> ownerPage );
2012-10-17 14:28:05 -04:00
// DBConnection
$this -> prepareQuery ();
//Query for get the number of rows
2017-12-04 13:25:35 +00:00
$this -> query = $this -> ses -> execute ( $this -> sql );
2012-10-17 14:28:05 -04:00
$this -> totRows = $this -> query -> count ();
2017-12-04 13:25:35 +00:00
$this -> totpages = ceil ( $this -> query -> count () / $this -> rowsPerPage );
2012-10-17 14:28:05 -04:00
//Query for obtain the records
2017-12-04 13:25:35 +00:00
$this -> query = $this -> ses -> execute ( $this -> sql . ' LIMIT ' . (( $this -> currentPage - 1 ) * $this -> rowsPerPage ) . ', ' . $this -> rowsPerPage );
2012-10-17 14:28:05 -04:00
// Prepare the template
2017-12-04 13:25:35 +00:00
$this -> tpl = new TemplatePower ( PATH_CORE . $this -> template );
2012-10-17 14:28:05 -04:00
$this -> tpl -> prepare ();
/**
* ******** HEAD BLOCK **************
*/
if (( $block === '' ) || ( $block === 'head' )) {
2017-12-04 13:25:35 +00:00
$this -> tpl -> newBlock ( 'headBlock' );
$this -> tpl -> assign ( 'pagedTable_Id' , $this -> id );
$this -> tpl -> assign ( 'pagedTable_Name' , $this -> name );
$this -> tpl -> assign ( 'pagedTable_Height' , $this -> xmlForm -> height );
$this -> xmlForm -> home = $filter -> xssFilterHard ( $this -> xmlForm -> home );
$this -> filterForm = $filter -> xssFilterHard ( $this -> filterForm );
$this -> menu = $filter -> xssFilterHard ( $this -> menu );
if ( file_exists ( $this -> xmlForm -> home . $this -> filterForm . '.xml' )) {
$filterForm = new filterForm ( $this -> filterForm , $this -> xmlForm -> home );
2012-10-17 14:28:05 -04:00
if ( $this -> menu === '' ) {
$this -> menu = 'gulliver/pagedTable_Options' ;
}
}
2017-12-04 13:25:35 +00:00
if ( file_exists ( $this -> xmlForm -> home . $this -> menu . '.xml' )) {
$menu = new xmlMenu ( $this -> menu , $this -> xmlForm -> home );
$this -> tpl -> newBlock ( 'headerBlock' );
2012-10-17 14:28:05 -04:00
$template = PATH_CORE . 'templates' . PATH_SEP . $menu -> type . '.html' ;
2017-12-04 13:25:35 +00:00
$menu -> setValues ( $this -> xmlForm -> values );
$menu -> setValues ( array ( 'PAGED_TABLE_ID' => $this -> id
));
$menu -> setValues ( array ( 'PAGED_TABLE_FAST_SEARCH' => $this -> fastSearch
));
if ( isset ( $filterForm -> name )) {
$menu -> setValues ( array ( 'SEARCH_FILTER_FORM' => $filterForm -> name
));
2012-10-17 14:28:05 -04:00
}
2017-12-04 13:25:35 +00:00
$this -> tpl -> assign ( 'content' , $menu -> render ( $template , $scriptCode ));
$oHeadPublisher = headPublisher :: getSingleton ();
$oHeadPublisher -> addScriptFile ( $menu -> scriptURL );
$oHeadPublisher -> addScriptCode ( $scriptCode );
2012-10-17 14:28:05 -04:00
}
2017-12-04 13:25:35 +00:00
if ( file_exists ( $this -> xmlForm -> home . $this -> filterForm . '.xml' )) {
$this -> tpl -> newBlock ( 'headerBlock' );
2012-10-17 14:28:05 -04:00
$this -> filterForm_Id = $filterForm -> id ;
$filterForm -> type = 'filterform' ;
$filterForm -> ajaxServer = '../gulliver/defaultAjax' ;
$template = PATH_CORE . 'templates/' . $filterForm -> type . '.html' ;
2017-12-04 13:25:35 +00:00
$filterForm -> setValues ( $this -> xmlForm -> values );
$filterForm -> setValues ( array ( 'PAGED_TABLE_ID' => $this -> id
));
$filterForm -> setValues ( array ( 'PAGED_TABLE_FAST_SEARCH' => $this -> fastSearch
));
$this -> tpl -> assign ( 'content' , $filterForm -> render ( $template , $scriptCode ));
$oHeadPublisher = headPublisher :: getSingleton ();
$oHeadPublisher -> addScriptFile ( $filterForm -> scriptURL );
$oHeadPublisher -> addScriptCode ( $scriptCode );
if ( isset ( $_SESSION )) {
2012-10-17 14:28:05 -04:00
$_SESSION [ $filterForm -> id ] = $filterForm -> values ;
}
}
}
/**
* ******** CONTENT BLOCK **************
*/
if (( $block === '' ) || ( $block === 'content' )) {
2017-12-04 13:25:35 +00:00
$this -> tpl -> newBlock ( 'contentBlock' );
$this -> tpl -> assign ( 'gridWidth' , '=[' . substr ( $this -> gridWidth , 1 ) . ']' );
$this -> tpl -> assign ( 'fieldNames' , '=[' . substr ( $this -> gridFields , 1 ) . ']' );
$this -> tpl -> assign ( 'ajaxUri' , '="' . addslashes ( $this -> ajaxServer ) . '"' );
$this -> tpl -> assign ( 'currentUri' , '="' . addslashes ( $this -> ownerPage ) . '"' );
$this -> tpl -> assign ( 'currentOrder' , '="' . addslashes ( $this -> orderBy ) . '"' );
$this -> tpl -> assign ( 'currentPage' , '=' . $this -> currentPage );
$this -> tpl -> assign ( 'currentFilter' , '="' . '"' );
$this -> tpl -> assign ( 'totalRows' , '=' . $this -> query -> count ());
$this -> tpl -> assign ( 'rowsPerPage' , '=' . $this -> rowsPerPage );
$this -> tpl -> assign ( 'popupPage' , '="' . addslashes ( $this -> popupPage ) . '"' );
$this -> tpl -> assign ( 'popupWidth' , '=' . $this -> popupWidth );
$this -> tpl -> assign ( 'popupHeight' , '=' . $this -> popupHeight );
$this -> tpl -> assign ( 'pagedTable_Id' , $this -> id );
$this -> tpl -> assign ( 'pagedTable_Name' , $this -> name );
$this -> tpl -> assign ( " pagedTable_JS " , " { $this -> id } .element=document.getElementById('pagedtable[ { $this -> id } ]'); " );
2012-10-17 14:28:05 -04:00
$this -> renderTitle ();
//Render rows
$gridRows = 0 ;
2017-12-04 13:25:35 +00:00
for ( $j = 0 ; $j < $this -> query -> count (); $j ++ ) {
2012-10-17 14:28:05 -04:00
$result = $this -> query -> read ();
//if (($j>=(($this->currentPage-1)*$this->rowsPerPage))&&($j<(($this->currentPage)*$this->rowsPerPage)))
//{
2017-12-04 13:25:35 +00:00
$gridRows ++ ;
$this -> tpl -> newBlock ( " row " );
$this -> tpl -> assign ( " class " , " Row " . (( $j % 2 ) + 1 ));
2012-10-17 14:28:05 -04:00
$this -> tdStyle = '' ;
$this -> tdClass = '' ;
foreach ( $this -> fields as $r => $rval ) {
2017-12-04 13:25:35 +00:00
if ( strcasecmp ( $this -> fields [ $r ][ 'Type' ], 'cellMark' ) == 0 ) {
2012-10-17 14:28:05 -04:00
$result1 = $result ;
$result1 [ 'row__' ] = $j + 1 ;
$this -> xmlForm -> setDefaultValues ();
2017-12-04 13:25:35 +00:00
$this -> xmlForm -> setValues ( $result1 );
$result1 = array_merge ( $this -> xmlForm -> values , $result1 );
$this -> tdStyle = $this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]] -> tdStyle ( $result1 , $this -> xmlForm );
$this -> tdClass = $this -> xmlForm -> fields [ $this -> fields [ $r ][ 'Name' ]] -> tdClass ( $result1 , $this -> xmlForm );
2012-10-17 14:28:05 -04:00
} elseif ( $this -> style [ $r ][ 'showInTable' ] != '0' ) {
2017-12-04 13:25:35 +00:00
$this -> renderField ( $j + 1 , $r , $result );
2012-10-17 14:28:05 -04:00
}
}
//}
}
2017-12-04 13:25:35 +00:00
$this -> tpl -> assign ( '_ROOT.gridRows' , '=' . $gridRows ); //number of rows in the current page
$this -> tpl -> newBlock ( 'rowTag' );
$this -> tpl -> assign ( 'rowId' , 'insertAtLast' );
2012-10-17 14:28:05 -04:00
if ( $this -> currentPage > 1 ) {
$firstUrl = $this -> ownerPage . '?order=' . $this -> orderBy . '&page=1' ;
2017-12-04 13:25:35 +00:00
$firstUrl = $filter -> xssFilterHard ( $firstUrl );
2012-10-17 14:28:05 -04:00
$firstAjax = $this -> id . " .doGoToPage(1);return false; " ;
2017-12-04 13:25:35 +00:00
$firstAjax = $filter -> xssFilterHard ( $firstAjax );
2012-10-17 14:28:05 -04:00
$prevpage = $this -> currentPage - 1 ;
$prevUrl = $this -> ownerPage . '?order=' . $this -> orderBy . '&page=' . $prevpage ;
2017-12-04 13:25:35 +00:00
$prevUrl = $filter -> xssFilterHard ( $prevUrl );
2012-10-17 14:28:05 -04:00
$prevAjax = $this -> id . " .doGoToPage( " . $prevpage . " );return false; " ;
2017-12-04 13:25:35 +00:00
$prevAjax = $filter -> xssFilterHard ( $prevAjax );
$first = " <a href= \" " . htmlentities ( $firstUrl , ENT_QUOTES , 'utf-8' ) . " \" onclick= \" " . $firstAjax . " \" class='firstPage'> </a> " ;
$prev = " <a href= \" " . htmlentities ( $prevUrl , ENT_QUOTES , 'utf-8' ) . " \" onclick= \" " . $prevAjax . " \" class='previousPage'> </a> " ;
2012-10-17 14:28:05 -04:00
} else {
$first = " <a class='noFirstPage'> </a> " ;
$prev = " <a class='noPreviousPage'> </a> " ;
}
if ( $this -> currentPage < $this -> totpages ) {
$lastUrl = $this -> ownerPage . '?order=' . $this -> orderBy . '&page=' . $this -> totpages ;
2017-12-04 13:25:35 +00:00
$lastUrl = $filter -> xssFilterHard ( $lastUrl );
2012-10-17 14:28:05 -04:00
$lastAjax = $this -> id . " .doGoToPage( " . $this -> totpages . " );return false; " ;
2017-12-04 13:25:35 +00:00
$lastAjax = $filter -> xssFilterHard ( $lastAjax );
2012-10-17 14:28:05 -04:00
$nextpage = $this -> currentPage + 1 ;
$nextUrl = $this -> ownerPage . '?order=' . $this -> orderBy . '&page=' . $nextpage ;
2017-12-04 13:25:35 +00:00
$nextUrl = $filter -> xssFilterHard ( $nextUrl );
2012-10-17 14:28:05 -04:00
$nextAjax = $this -> id . " .doGoToPage( " . $nextpage . " );return false; " ;
2017-12-04 13:25:35 +00:00
$nextAjax = $filter -> xssFilterHard ( $nextAjax );
$next = " <a href= \" " . htmlentities ( $nextUrl , ENT_QUOTES , 'utf-8' ) . " \" onclick= \" " . $nextAjax . " \" class='nextPage'> </a> " ;
$last = " <a href= \" " . htmlentities ( $lastUrl , ENT_QUOTES , 'utf-8' ) . " \" onclick= \" " . $lastAjax . " \" class='lastPage'> </a> " ;
2012-10-17 14:28:05 -04:00
} else {
$next = " <a class='noNextPage'> </a> " ;
$last = " <a class='noLastPage'> </a> " ;
}
$pagesEnum = '' ;
2017-12-04 13:25:35 +00:00
for ( $r = 1 ; $r <= $this -> totpages ; $r ++ ) {
2012-10-17 14:28:05 -04:00
if (( $r >= ( $this -> currentPage - 5 )) && ( $r <= ( $this -> currentPage + 5 ))) {
$pageAjax = $this -> id . " .doGoToPage( " . $r . " );return false; " ;
2017-12-04 13:25:35 +00:00
if ( $r != $this -> currentPage ) {
$pageAjax = $filter -> xssFilterHard ( $pageAjax );
$pagesEnum .= " <a href= \" " . htmlentities ( $this -> ownerPage . '?order=' . $this -> orderBy . '&page=' . $r , ENT_QUOTES , 'utf-8' ) . " \" onclick= \" " . $pageAjax . " \" > " . $r . " </a> " ;
2012-10-17 14:28:05 -04:00
} else {
$pagesEnum .= " <a> " . $r . " </a> " ;
}
}
}
if ( $this -> query -> count () === 0 ) {
2017-12-04 13:25:35 +00:00
$this -> tpl -> newBlock ( 'norecords' );
$this -> tpl -> assign ( " columnCount " , $this -> colCount );
2012-10-17 14:28:05 -04:00
$noRecordsFound = 'ID_NO_RECORDS_FOUND' ;
2017-12-04 13:25:35 +00:00
if ( G :: LoadTranslation ( $noRecordsFound )) {
$noRecordsFound = G :: LoadTranslation ( $noRecordsFound );
2012-10-17 14:28:05 -04:00
}
2017-12-04 13:25:35 +00:00
$this -> tpl -> assign ( " noRecordsFound " , $noRecordsFound );
2012-10-17 14:28:05 -04:00
}
2017-12-04 13:25:35 +00:00
if ( ! $this -> disableFooter ) {
$this -> tpl -> newBlock ( " bottomFooter " );
$this -> tpl -> assign ( " columnCount " , $this -> colCount );
$this -> tpl -> assign ( " pagedTableId " , $this -> id );
2012-10-17 14:28:05 -04:00
if (( $this -> query -> count () !== 0 )) {
if ( $this -> totpages > 1 ) {
2017-12-04 13:25:35 +00:00
$this -> tpl -> assign ( " first " , $first );
$this -> tpl -> assign ( " prev " , $prev );
$this -> tpl -> assign ( " next " , $next );
$this -> tpl -> assign ( " last " , $last );
2012-10-17 14:28:05 -04:00
}
2017-12-04 13:25:35 +00:00
$this -> tpl -> assign ( " currentPage " , $this -> currentPage );
$this -> tpl -> assign ( " totalPages " , $this -> totpages );
2012-10-17 14:28:05 -04:00
$firstRow = ( $this -> currentPage - 1 ) * $this -> rowsPerPage + 1 ;
$lastRow = $firstRow + $this -> query -> count () - 1 ;
2017-12-04 13:25:35 +00:00
$this -> tpl -> assign ( " firstRow " , $firstRow );
$this -> tpl -> assign ( " lastRow " , $lastRow );
$this -> tpl -> assign ( " totalRows " , $this -> totRows );
2012-10-17 14:28:05 -04:00
} else {
2017-12-04 13:25:35 +00:00
$this -> tpl -> assign ( " indexStyle " , 'visibility:hidden;' );
2012-10-17 14:28:05 -04:00
}
if ( $this -> searchBy ) {
2017-12-04 13:25:35 +00:00
$this -> tpl -> assign ( " fastSearchValue " , $this -> fastSearch );
2012-10-17 14:28:05 -04:00
} else {
2017-12-04 13:25:35 +00:00
$this -> tpl -> assign ( " fastSearchStyle " , 'visibility:hidden;' );
2012-10-17 14:28:05 -04:00
}
if ( $this -> addRow ) {
if ( $this -> sqlInsert != '' ) {
2017-12-04 13:25:35 +00:00
$this -> tpl -> assign ( " insert " , '<a href="#" onclick="pagedTable.event=\'Insert\';popup(\'' . $this -> popupPage . '\');return false;">' ./* G :: LoadXml ( 'labels' , 'ID_ADD_NEW' ) */
'ID_ADD_NEW' . '</a>' );
2012-10-17 14:28:05 -04:00
}
}
2017-12-04 13:25:35 +00:00
$this -> tpl -> assign ( " pagesEnum " , $pagesEnum );
} ?>
< script language = 'JavaScript' >
var < ? php echo $this -> id ?> <?php echo($this->name != '' ? '=' . $this->name : '')?>=
new G_PagedTable ();
< ? php echo $this -> id ?> .id<?php echo '="' . addslashes($this->id) . '"'?>;
< ? php echo $this -> id ?> .name<?php echo '="' . addslashes($this->name) . '"'?>;
< ? php echo $this -> id ?> .ajaxUri<?php echo '="' . addslashes($this->ajaxServer) . '?ptID=' . $this->id . '"'?>;
< ? php echo $this -> id ?> .currentOrder<?php echo '="' . addslashes($this->orderBy) . '"'?>;
< ? php echo $this -> id ?> .currentFilter;
< ? php echo $this -> id ?> .currentPage<?php echo '=' . $this->currentPage?>;
< ? php echo $this -> id ?> .totalRows<?php echo '=' . $this->query->count()?>;
< ? php echo $this -> id ?> .rowsPerPage<?php echo '=' . $this->rowsPerPage?>;
< ? php echo $this -> id ?> .popupPage<?php echo '="' . addslashes($this->popupPage) . '?ptID=' . $this->id . '"'?>;
< ? php echo $this -> id ?> .onUpdateField<?php echo '="' . addslashes($this->onUpdateField) . '"'?>;
< ? php echo $this -> id ?> .shownFields<?php echo '=' . $this->shownFields ?>;
2012-10-17 14:28:05 -04:00
2017-12-04 13:25:35 +00:00
var panelPopup ;
var popupWidth < ? php echo '=' . $this -> popupWidth ?> ;
var popupHeight < ? php echo '=' . $this -> popupHeight ?> ;
2012-10-17 14:28:05 -04:00
</ script >
2017-12-04 13:25:35 +00:00
< ? php
2012-10-17 14:28:05 -04:00
}
/**
* ******** CLOSE BLOCK **************
*/
if (( $block === '' ) || ( $block === 'close' )) {
2017-12-04 13:25:35 +00:00
$this -> tpl -> newBlock ( " closeBlock " );
2012-10-17 14:28:05 -04:00
}
$this -> tpl -> printToScreen ();
2017-12-04 13:25:35 +00:00
unset ( $this -> tpl );
unset ( $this -> dbc );
unset ( $this -> ses );
2016-08-29 11:19:32 -04:00
$_SESSION [ 'pagedTable[' . $this -> id . ']' ] = base64_encode ( serialize ( $this ));
2012-10-17 14:28:05 -04:00
return ;
2010-12-02 23:34:41 +00:00
}
2012-10-17 14:28:05 -04:00
/**
* Function printForm
*
* @ access public
* @ param string $filename
* @ param array $data
* @ return void
*/
2017-12-04 13:25:35 +00:00
public function printForm ( $filename , $data = array ())
2012-10-17 14:28:05 -04:00
{
// $G_FORM = new Form($filename, PATH_XMLFORM);
// echo $G_FORM->render(PATH_TPL . 'xmlform.html', $scriptContent);
global $G_PUBLISH ;
$G_PUBLISH = new Publisher ();
2017-12-04 13:25:35 +00:00
$G_PUBLISH -> AddContent ( 'xmlform' , 'xmlform' , $filename , '' , $data , $this -> popupSubmit );
G :: RenderPage ( " publish " , " blank " );
2010-12-02 23:34:41 +00:00
}
}
2012-10-17 14:28:05 -04:00
/**
* Function var_dump2
*
* @ access public
* @ param string $o
* @ return void
*/
2017-12-04 13:25:35 +00:00
function var_dump2 ( $o )
2010-12-02 23:34:41 +00:00
{
2017-12-04 13:25:35 +00:00
if ( is_object ( $o ) || is_array ( $o )) {
2012-10-17 14:28:05 -04:00
foreach ( $o as $key => $value ) {
2017-12-04 13:25:35 +00:00
echo ( '<b>' );
var_dump ( $key );
echo ( '</b>' );
print_r ( $value );
echo ( '<br>' );
2012-10-17 14:28:05 -04:00
}
} else {
2017-12-04 13:25:35 +00:00
var_dump ( $o );
2012-10-17 14:28:05 -04:00
}
}