2017-05-10 13:30:35 +02:00
< ? php
2017-07-08 15:43:36 +02:00
/* Copyright ( C ) 2007 - 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
2017-05-27 13:46:34 +02:00
* Copyright ( C ) --- Put here your own copyright and developer email ---
2017-05-10 13:30:35 +02:00
*
2017-05-27 13:46:34 +02:00
* This program is free software ; you can redistribute it and / or modify
2017-05-10 13:30:35 +02:00
* it under the terms of the GNU General Public License as published by
2017-05-27 13:46:34 +02:00
* the Free Software Foundation ; either version 3 of the License , or
2017-05-10 13:30:35 +02:00
* ( 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
* 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
2017-05-27 13:46:34 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2017-05-10 13:30:35 +02:00
*/
/**
2017-05-27 13:46:34 +02:00
* \file htdocs / modulebuilder / template / myobject_list . php
2017-07-25 00:00:08 +02:00
* \ingroup mymodule
2017-07-25 01:21:20 +02:00
* \brief List page for myobject
2017-05-10 13:30:35 +02:00
*/
2018-04-21 12:00:55 +02:00
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Do not create database handler $db
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Do not load object $user
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); // Do not load object $mysoc
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Do not load object $langs
//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION','1'); // Do not check injection attack on GET parameters
//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION','1'); // Do not check injection attack on POST parameters
//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); // Do not check CSRF attack (test on referer + on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on).
//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK','1'); // Do not check style html tag into posted data
//if (! defined('NOIPCHECK')) define('NOIPCHECK','1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no need to load and show top and left menu
//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); // Do not load ajax.lib.php library
//if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT','auto'); // Force lang to a particular value
//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE','aloginmodule'); // Force authentication handler
2018-04-30 14:39:12 +02:00
//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN',1); // The main.inc.php does not make a redirect if not logged, instead show simple error message
2019-01-18 18:11:10 +01:00
//if (! defined("XFRAMEOPTIONS_ALLOWALL")) define('XFRAMEOPTIONS_ALLOWALL',1); // Do not add the HTTP header 'X-Frame-Options: SAMEORIGIN' but 'X-Frame-Options: ALLOWALL'
2017-05-10 13:30:35 +02:00
2017-06-23 20:03:15 +02:00
// Load Dolibarr environment
2017-05-27 13:46:34 +02:00
$res = 0 ;
2017-06-23 20:03:15 +02:00
// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
2018-07-26 11:50:54 +02:00
if ( ! $res && ! empty ( $_SERVER [ " CONTEXT_DOCUMENT_ROOT " ])) $res =@ include $_SERVER [ " CONTEXT_DOCUMENT_ROOT " ] . " /main.inc.php " ;
2018-05-23 17:16:58 +02:00
// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
2017-06-23 20:03:15 +02:00
$tmp = empty ( $_SERVER [ 'SCRIPT_FILENAME' ]) ? '' : $_SERVER [ 'SCRIPT_FILENAME' ]; $tmp2 = realpath ( __FILE__ ); $i = strlen ( $tmp ) - 1 ; $j = strlen ( $tmp2 ) - 1 ;
while ( $i > 0 && $j > 0 && isset ( $tmp [ $i ]) && isset ( $tmp2 [ $j ]) && $tmp [ $i ] == $tmp2 [ $j ]) { $i -- ; $j -- ; }
2018-07-26 11:50:54 +02:00
if ( ! $res && $i > 0 && file_exists ( substr ( $tmp , 0 , ( $i + 1 )) . " /main.inc.php " )) $res =@ include substr ( $tmp , 0 , ( $i + 1 )) . " /main.inc.php " ;
if ( ! $res && $i > 0 && file_exists ( dirname ( substr ( $tmp , 0 , ( $i + 1 ))) . " /main.inc.php " )) $res =@ include dirname ( substr ( $tmp , 0 , ( $i + 1 ))) . " /main.inc.php " ;
2017-06-23 20:03:15 +02:00
// Try main.inc.php using relative path
2018-07-26 11:50:54 +02:00
if ( ! $res && file_exists ( " ../main.inc.php " )) $res =@ include " ../main.inc.php " ;
if ( ! $res && file_exists ( " ../../main.inc.php " )) $res =@ include " ../../main.inc.php " ;
if ( ! $res && file_exists ( " ../../../main.inc.php " )) $res =@ include " ../../../main.inc.php " ;
2017-05-27 13:46:34 +02:00
if ( ! $res ) die ( " Include of main fails " );
2017-06-23 20:03:15 +02:00
2018-07-26 11:50:54 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php' ;
2017-05-10 13:30:35 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2017-05-27 13:46:34 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
2019-04-18 09:33:47 +02:00
// load mymodule libraries
2019-04-18 10:19:14 +02:00
require_once __DIR__ . '/class/myobject.class.php' ;
2019-04-18 09:33:47 +02:00
// for other modules
//dol_include_once('/othermodule/class/otherobject.class.php');
2017-05-10 13:30:35 +02:00
2018-05-26 17:57:30 +02:00
// Load translation files required by the page
2017-07-25 12:44:55 +02:00
$langs -> loadLangs ( array ( " mymodule@mymodule " , " other " ));
2017-05-10 13:30:35 +02:00
2019-01-27 11:55:16 +01:00
$action = GETPOST ( 'action' , 'aZ09' ) ? GETPOST ( 'action' , 'aZ09' ) : 'view' ; // The action 'add', 'create', 'edit', 'update', 'view', ...
$massaction = GETPOST ( 'massaction' , 'alpha' ); // The bulk action (combo box choice into lists)
$show_files = GETPOST ( 'show_files' , 'int' ); // Show files area generated by bulk actions ?
$confirm = GETPOST ( 'confirm' , 'alpha' ); // Result of a confirmation
2017-09-12 14:56:56 +02:00
$cancel = GETPOST ( 'cancel' , 'alpha' ); // We click on a Cancel button
$toselect = GETPOST ( 'toselect' , 'array' ); // Array of ids of elements selected into a list
2019-01-27 11:55:16 +01:00
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'myobjectlist' ; // To manage different context of search
$backtopage = GETPOST ( 'backtopage' , 'alpha' ); // Go back to a dedicated page
$optioncss = GETPOST ( 'optioncss' , 'aZ' ); // Option for the css output (always '' except when 'print')
2017-05-10 13:30:35 +02:00
2019-01-27 11:55:16 +01:00
$id = GETPOST ( 'id' , 'int' );
2017-05-27 13:46:34 +02:00
2017-05-10 13:30:35 +02:00
// Load variable for pagination
2019-01-27 11:55:16 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
$sortfield = GETPOST ( 'sortfield' , 'alpha' );
$sortorder = GETPOST ( 'sortorder' , 'alpha' );
$page = GETPOST ( 'page' , 'int' );
if ( empty ( $page ) || $page == - 1 || GETPOST ( 'button_search' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' ) || ( empty ( $toselect ) && $massaction === '0' )) { $page = 0 ; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
2017-05-10 13:30:35 +02:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2018-04-07 16:17:40 +02:00
//if (! $sortfield) $sortfield="p.date_fin";
//if (! $sortorder) $sortorder="DESC";
2017-07-11 20:47:49 +02:00
2017-07-12 13:25:18 +02:00
// Initialize technical objects
2019-01-03 11:47:27 +01:00
$object = new MyObject ( $db );
2017-07-12 13:25:18 +02:00
$extrafields = new ExtraFields ( $db );
2019-01-03 11:47:27 +01:00
$diroutputmassaction = $conf -> mymodule -> dir_output . '/temp/massgeneration/' . $user -> id ;
2017-07-12 13:25:18 +02:00
$hookmanager -> initHooks ( array ( 'myobjectlist' )); // Note that conf->hooks_modules contains array
// Fetch optionals attributes and labels
2018-11-07 12:25:22 +01:00
$extralabels = $extrafields -> fetch_name_optionals_label ( 'myobject' ); // Load $extrafields->attributes['myobject']
2019-01-27 11:55:16 +01:00
$search_array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element , '' , 'search_' );
2017-07-12 01:55:07 +02:00
// Default sort order (if not yet defined by previous GETPOST)
if ( ! $sortfield ) $sortfield = " t. " . key ( $object -> fields ); // Set here default search field. By default 1st field in definition.
2017-05-10 13:30:35 +02:00
if ( ! $sortorder ) $sortorder = " ASC " ;
2018-03-20 11:45:57 +01:00
// Security check
2017-05-27 13:46:34 +02:00
$socid = 0 ;
2018-03-20 11:45:57 +01:00
if ( $user -> societe_id > 0 ) // Protection if external user
2017-05-10 13:30:35 +02:00
{
2017-10-13 13:28:26 +02:00
//$socid = $user->societe_id;
2017-07-12 01:55:07 +02:00
accessforbidden ();
2017-05-10 13:30:35 +02:00
}
2018-03-20 11:45:57 +01:00
//$result = restrictedArea($user, 'mymodule', $id, '');
2017-05-10 13:30:35 +02:00
2017-07-11 20:47:49 +02:00
// Initialize array of search criterias
2019-01-27 11:55:16 +01:00
$search_all = trim ( GETPOST ( " search_all " , 'alpha' ));
2017-07-11 20:47:49 +02:00
$search = array ();
2017-07-12 01:55:07 +02:00
foreach ( $object -> fields as $key => $val )
2017-07-11 20:47:49 +02:00
{
2019-01-27 11:55:16 +01:00
if ( GETPOST ( 'search_' . $key , 'alpha' )) $search [ $key ] = GETPOST ( 'search_' . $key , 'alpha' );
2017-07-11 20:47:49 +02:00
}
2017-05-10 13:30:35 +02:00
2017-05-27 13:46:34 +02:00
// List of fields to search into when doing a "search in all"
2017-07-12 01:55:07 +02:00
$fieldstosearchall = array ();
foreach ( $object -> fields as $key => $val )
{
2017-10-13 13:28:26 +02:00
if ( $val [ 'searchall' ]) $fieldstosearchall [ 't.' . $key ] = $val [ 'label' ];
2017-07-12 01:55:07 +02:00
}
2017-05-27 13:46:34 +02:00
// Definition of fields for list
2017-07-12 01:55:07 +02:00
$arrayfields = array ();
foreach ( $object -> fields as $key => $val )
{
2017-07-22 01:00:43 +02:00
// If $val['visible']==0, then we never show the field
2018-01-15 17:38:15 +01:00
if ( ! empty ( $val [ 'visible' ])) $arrayfields [ 't.' . $key ] = array ( 'label' => $val [ 'label' ], 'checked' => (( $val [ 'visible' ] < 0 ) ? 0 : 1 ), 'enabled' => $val [ 'enabled' ], 'position' => $val [ 'position' ]);
2017-07-12 01:55:07 +02:00
}
2017-05-27 13:46:34 +02:00
// Extra fields
2018-04-13 17:54:27 +02:00
if ( is_array ( $extrafields -> attributes [ $object -> table_element ][ 'label' ]) && count ( $extrafields -> attributes [ $object -> table_element ][ 'label' ]) > 0 )
2017-05-27 13:46:34 +02:00
{
2018-04-12 23:16:23 +02:00
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'label' ] as $key => $val )
2017-10-13 13:28:26 +02:00
{
2018-04-12 23:16:23 +02:00
if ( ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'list' ][ $key ]))
$arrayfields [ " ef. " . $key ] = array ( 'label' => $extrafields -> attributes [ $object -> table_element ][ 'label' ][ $key ], 'checked' => (( $extrafields -> attributes [ $object -> table_element ][ 'list' ][ $key ] < 0 ) ? 0 : 1 ), 'position' => $extrafields -> attributes [ $object -> table_element ][ 'pos' ][ $key ], 'enabled' => ( abs ( $extrafields -> attributes [ $object -> table_element ][ 'list' ][ $key ]) != 3 && $extrafields -> attributes [ $object -> table_element ][ 'perms' ][ $key ]));
2017-10-13 13:28:26 +02:00
}
2017-05-10 13:30:35 +02:00
}
2018-01-15 18:11:56 +01:00
$object -> fields = dol_sort_array ( $object -> fields , 'position' );
$arrayfields = dol_sort_array ( $arrayfields , 'position' );
2017-05-10 13:30:35 +02:00
2017-05-27 13:46:34 +02:00
2017-05-10 13:30:35 +02:00
/*
2017-11-25 18:52:47 +01:00
* Actions
2017-05-10 13:30:35 +02:00
*/
2019-01-27 11:55:16 +01:00
if ( GETPOST ( 'cancel' , 'alpha' )) { $action = 'list' ; $massaction = '' ; }
if ( ! GETPOST ( 'confirmmassaction' , 'alpha' ) && $massaction != 'presend' && $massaction != 'confirm_presend' ) { $massaction = '' ; }
2017-05-10 13:30:35 +02:00
$parameters = array ();
2017-09-11 16:26:01 +02:00
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2017-05-10 13:30:35 +02:00
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
if ( empty ( $reshook ))
{
2017-10-13 13:28:26 +02:00
// Selection of new fields
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php' ;
// Purge search criteria
2019-01-27 11:55:16 +01:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) // All tests are required to be compatible with all browsers
2017-10-13 13:28:26 +02:00
{
foreach ( $object -> fields as $key => $val )
{
$search [ $key ] = '' ;
}
$toselect = '' ;
$search_array_options = array ();
}
2019-01-27 11:55:16 +01:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )
|| GETPOST ( 'button_search_x' , 'alpha' ) || GETPOST ( 'button_search.x' , 'alpha' ) || GETPOST ( 'button_search' , 'alpha' ))
2017-10-13 13:28:26 +02:00
{
$massaction = '' ; // Protection to avoid mass action if we force a new search during a mass action confirmation
}
// Mass actions
$objectclass = 'MyObject' ;
$objectlabel = 'MyObject' ;
$permtoread = $user -> rights -> mymodule -> read ;
$permtodelete = $user -> rights -> mymodule -> delete ;
$uploaddir = $conf -> mymodule -> dir_output ;
include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php' ;
2017-05-10 13:30:35 +02:00
}
2017-05-27 13:46:34 +02:00
2017-05-10 13:30:35 +02:00
/*
2017-11-25 18:52:47 +01:00
* View
2017-05-10 13:30:35 +02:00
*/
2017-05-27 13:46:34 +02:00
$form = new Form ( $db );
2017-07-12 11:52:07 +02:00
$now = dol_now ();
//$help_url="EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
2017-05-27 13:46:34 +02:00
$help_url = '' ;
2017-07-12 01:55:07 +02:00
$title = $langs -> trans ( 'ListOf' , $langs -> transnoentitiesnoconv ( " MyObjects " ));
2017-05-10 13:30:35 +02:00
2017-07-12 11:52:07 +02:00
// Build and execute select
// --------------------------------------------------------------------
2017-07-12 01:55:07 +02:00
$sql = 'SELECT ' ;
foreach ( $object -> fields as $key => $val )
{
2017-10-13 13:28:26 +02:00
$sql .= 't.' . $key . ', ' ;
2017-07-12 01:55:07 +02:00
}
2017-05-27 13:46:34 +02:00
// Add fields from extrafields
2018-04-12 23:16:23 +02:00
if ( ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'label' ]))
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'label' ] as $key => $val ) $sql .= ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $key ] != 'separate' ? " ef. " . $key . ' as options_' . $key . ', ' : '' );
2017-05-27 13:46:34 +02:00
// Add fields from hooks
$parameters = array ();
2017-09-11 16:26:01 +02:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListSelect' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2017-05-27 13:46:34 +02:00
$sql .= $hookmanager -> resPrint ;
2019-01-27 11:55:16 +01:00
$sql = preg_replace ( '/, $/' , '' , $sql );
2017-11-21 11:56:49 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . $object -> table_element . " as t " ;
2018-04-13 12:52:23 +02:00
if ( is_array ( $extrafields -> attributes [ $object -> table_element ][ 'label' ]) && count ( $extrafields -> attributes [ $object -> table_element ][ 'label' ])) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $object -> table_element . " _extrafields as ef on (t.rowid = ef.fk_object) " ;
if ( $object -> ismultientitymanaged == 1 ) $sql .= " WHERE t.entity IN ( " . getEntity ( $object -> element ) . " ) " ;
2017-10-20 23:48:42 +02:00
else $sql .= " WHERE 1 = 1 " ;
2017-07-12 01:55:07 +02:00
foreach ( $search as $key => $val )
{
2018-03-13 13:56:45 +01:00
if ( $key == 'status' && $search [ $key ] == - 1 ) continue ;
2019-05-08 01:09:38 +02:00
$mode_search = (( $object -> isInt ( $object -> fields [ $key ]) || $object -> isFloat ( $object -> fields [ $key ])) ? 1 : 0 );
2017-09-15 15:57:07 +02:00
if ( $search [ $key ] != '' ) $sql .= natural_search ( $key , $search [ $key ], (( $key == 'status' ) ? 2 : $mode_search ));
2017-07-12 01:55:07 +02:00
}
if ( $search_all ) $sql .= natural_search ( array_keys ( $fieldstosearchall ), $search_all );
2017-05-27 13:46:34 +02:00
// Add where from extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php' ;
2017-05-27 13:46:34 +02:00
// Add where from hooks
$parameters = array ();
2017-09-11 16:26:01 +02:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListWhere' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2017-05-27 13:46:34 +02:00
$sql .= $hookmanager -> resPrint ;
2017-09-18 15:48:04 +02:00
/* If a group by is required
$sql .= " GROUP BY "
foreach ( $object -> fields as $key => $val )
{
2018-04-13 12:52:23 +02:00
$sql .= 't.' . $key . ', ' ;
2017-09-18 15:48:04 +02:00
}
// Add fields from extrafields
2018-04-12 23:16:23 +02:00
if ( ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'label' ])) {
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'label' ] as $key => $val ) $sql .= ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $key ] != 'separate' ? " ef. " . $key . ', ' : '' );
2017-09-18 15:48:04 +02:00
// Add where from hooks
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListGroupBy' , $parameters ); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager -> resPrint ;
2018-04-13 12:52:23 +02:00
$sql = preg_replace ( '/, $/' , '' , $sql );
2017-09-18 15:48:04 +02:00
*/
2019-01-27 11:55:16 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2017-05-27 13:46:34 +02:00
// Count total nb of records
$nbtotalofrecords = '' ;
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST ))
{
2018-04-10 20:55:31 +02:00
$resql = $db -> query ( $sql );
$nbtotalofrecords = $db -> num_rows ( $resql );
2018-07-12 11:15:28 +02:00
if (( $page * $limit ) > $nbtotalofrecords ) // if total of record found is smaller than page * limit, goto and load page 0
2018-04-24 11:37:57 +02:00
{
$page = 0 ;
$offset = 0 ;
}
2017-06-07 16:44:04 +02:00
}
2018-07-12 11:15:28 +02:00
// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
2018-02-08 13:07:05 +01:00
if ( is_numeric ( $nbtotalofrecords ) && $limit > $nbtotalofrecords )
2018-02-04 12:59:02 +01:00
{
$num = $nbtotalofrecords ;
2018-02-15 19:49:50 +01:00
}
else
2018-02-04 12:59:02 +01:00
{
$sql .= $db -> plimit ( $limit + 1 , $offset );
2017-05-27 13:46:34 +02:00
2018-02-04 12:59:02 +01:00
$resql = $db -> query ( $sql );
if ( ! $resql )
{
dol_print_error ( $db );
exit ;
}
$num = $db -> num_rows ( $resql );
}
2017-05-27 13:46:34 +02:00
// Direct jump if only one record found
if ( $num == 1 && ! empty ( $conf -> global -> MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE ) && $search_all )
{
2017-10-13 13:28:26 +02:00
$obj = $db -> fetch_object ( $resql );
$id = $obj -> rowid ;
2018-10-31 20:10:20 +01:00
header ( " Location: " . dol_buildpath ( '/mymodule/myobject_card.php' , 1 ) . '?id=' . $id );
2017-10-13 13:28:26 +02:00
exit ;
2017-05-27 13:46:34 +02:00
}
2017-07-12 11:52:07 +02:00
// Output page
// --------------------------------------------------------------------
2017-05-27 13:46:34 +02:00
llxHeader ( '' , $title , $help_url );
2017-07-12 11:52:07 +02:00
// Example : Adding jquery code
print ' < script type = " text/javascript " language = " javascript " >
jQuery ( document ) . ready ( function () {
function init_myfunc ()
{
jQuery ( " #myid " ) . removeAttr ( \ ' disabled\ ' );
jQuery ( " #myid " ) . attr ( \ ' disabled\ ' , \ ' disabled\ ' );
}
init_myfunc ();
jQuery ( " #mybutton " ) . click ( function () {
init_myfunc ();
});
});
</ script > ' ;
2017-05-27 13:46:34 +02:00
$arrayofselected = is_array ( $toselect ) ? $toselect : array ();
$param = '' ;
2017-09-16 13:14:46 +02:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) $param .= '&contextpage=' . urlencode ( $contextpage );
if ( $limit > 0 && $limit != $conf -> liste_limit ) $param .= '&limit=' . urlencode ( $limit );
2017-07-12 11:52:07 +02:00
foreach ( $search as $key => $val )
{
2019-02-11 15:41:07 +01:00
if ( is_array ( $search [ $key ]) && count ( $search [ $key ])) foreach ( $search [ $key ] as $skey ) $param .= '&search_' . $key . '[]=' . urlencode ( $skey );
else $param .= '&search_' . $key . '=' . urlencode ( $search [ $key ]);
2017-07-12 11:52:07 +02:00
}
2017-09-16 13:14:46 +02:00
if ( $optioncss != '' ) $param .= '&optioncss=' . urlencode ( $optioncss );
2017-05-27 13:46:34 +02:00
// Add $param from extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php' ;
2017-05-27 13:46:34 +02:00
2017-07-25 01:22:06 +02:00
// List of mass actions available
2017-05-27 13:46:34 +02:00
$arrayofmassactions = array (
2019-05-10 19:32:46 +02:00
//'validate'=>$langs->trans("Validate"),
//'generate_doc'=>$langs->trans("ReGeneratePDF"),
//'builddoc'=>$langs->trans("PDFMerge"),
//'presend'=>$langs->trans("SendByMail"),
2017-05-27 13:46:34 +02:00
);
2019-04-09 01:22:59 +02:00
if ( $user -> rights -> mymodule -> delete ) $arrayofmassactions [ 'predelete' ] = '<span class="fa fa-trash paddingrightonly"></span>' . $langs -> trans ( " Delete " );
2019-01-27 11:55:16 +01:00
if ( GETPOST ( 'nomassaction' , 'int' ) || in_array ( $massaction , array ( 'presend' , 'predelete' ))) $arrayofmassactions = array ();
2017-05-27 13:46:34 +02:00
$massactionbutton = $form -> selectMassAction ( '' , $arrayofmassactions );
2018-02-04 12:59:02 +01:00
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2017-05-27 13:46:34 +02:00
if ( $optioncss != '' ) print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
print '<input type="hidden" name="action" value="list">' ;
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
print '<input type="hidden" name="page" value="' . $page . '">' ;
print '<input type="hidden" name="contextpage" value="' . $contextpage . '">' ;
2019-05-29 09:38:19 +02:00
$newcardbutton = dolGetButtonTitle ( $langs -> trans ( 'New' ), '' , 'fa fa-plus-circle' , DOL_URL_ROOT . '/mymodule/myobject_card.php?action=create&backtopage=' . urlencode ( $_SERVER [ 'PHP_SELF' ]), '' , $user -> rights -> mymodule -> write );
2018-04-15 17:37:49 +02:00
print_barre_liste ( $title , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , $massactionbutton , $num , $nbtotalofrecords , 'title_companies' , 0 , $newcardbutton , '' , $limit );
2017-05-27 13:46:34 +02:00
2017-11-11 16:03:22 +01:00
// Add code for pre mass action (confirmation or email presend form)
$topicmail = " SendMyObjectRef " ;
$modelmail = " myobject " ;
$objecttmp = new MyObject ( $db );
2017-11-15 11:39:11 +01:00
$trackid = 'xxxx' . $object -> id ;
2017-11-11 16:03:22 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php' ;
2019-04-10 15:11:38 +02:00
if ( $search_all )
2017-05-27 13:46:34 +02:00
{
2017-10-13 13:28:26 +02:00
foreach ( $fieldstosearchall as $key => $val ) $fieldstosearchall [ $key ] = $langs -> trans ( $val );
2019-04-10 15:11:38 +02:00
print '<div class="divsearchfieldfilter">' . $langs -> trans ( " FilterOnInto " , $search_all ) . join ( ', ' , $fieldstosearchall ) . '</div>' ;
2017-05-27 13:46:34 +02:00
}
$moreforfilter = '' ;
2017-10-20 23:48:42 +02:00
/* $moreforfilter .= '<div class="divsearchfield">' ;
2017-05-27 13:46:34 +02:00
$moreforfilter .= $langs -> trans ( 'MyFilter' ) . ': <input type="text" name="search_myfield" value="' . dol_escape_htmltag ( $search_myfield ) . '">' ;
2017-10-20 23:48:42 +02:00
$moreforfilter .= '</div>' ; */
2017-05-27 13:46:34 +02:00
$parameters = array ();
2017-09-11 16:26:01 +02:00
$reshook = $hookmanager -> executeHooks ( 'printFieldPreListTitle' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2017-05-27 13:46:34 +02:00
if ( empty ( $reshook )) $moreforfilter .= $hookmanager -> resPrint ;
else $moreforfilter = $hookmanager -> resPrint ;
if ( ! empty ( $moreforfilter ))
{
print '<div class="liste_titre liste_titre_bydiv centpercent">' ;
print $moreforfilter ;
2017-10-13 13:28:26 +02:00
print '</div>' ;
2017-05-27 13:46:34 +02:00
}
$varpage = empty ( $contextpage ) ? $_SERVER [ " PHP_SELF " ] : $contextpage ;
$selectedfields = $form -> multiSelectArrayWithCheckbox ( 'selectedfields' , $arrayfields , $varpage ); // This also change content of $arrayfields
2017-10-09 16:49:17 +02:00
$selectedfields .= ( count ( $arrayofmassactions ) ? $form -> showCheckAddButtons ( 'checkforselect' , 1 ) : '' );
2017-05-10 13:30:35 +02:00
2017-09-08 10:09:22 +02:00
print '<div class="div-table-responsive">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
2017-05-27 13:46:34 +02:00
print '<table class="tagtable liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
2017-05-10 13:30:35 +02:00
2017-05-27 13:46:34 +02:00
// Fields title search
2017-07-12 11:52:07 +02:00
// --------------------------------------------------------------------
2017-05-27 13:46:34 +02:00
print '<tr class="liste_titre">' ;
2017-07-12 11:52:07 +02:00
foreach ( $object -> fields as $key => $val )
{
2019-05-22 19:21:55 +02:00
$cssforfield = ( empty ( $val [ 'css' ]) ? '' : $val [ 'css' ]);
2018-11-11 15:06:08 +01:00
if ( $key == 'status' ) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'center' ;
2019-05-22 19:21:55 +02:00
elseif ( in_array ( $val [ 'type' ], array ( 'date' , 'datetime' , 'timestamp' ))) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'center' ;
elseif ( in_array ( $val [ 'type' ], array ( 'timestamp' ))) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'nowrap' ;
elseif ( in_array ( $val [ 'type' ], array ( 'double(24,8)' , 'double(6,3)' , 'integer' , 'real' , 'price' ))) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'right' ;
if ( ! empty ( $arrayfields [ 't.' . $key ][ 'checked' ]))
{
print '<td class="liste_titre' . ( $cssforfield ? ' ' . $cssforfield : '' ) . '">' ;
if ( is_array ( $val [ 'arrayofkeyval' ])) print $form -> selectarray ( 'search_' . $key , $val [ 'arrayofkeyval' ], $search [ $key ], $val [ 'notnull' ], 0 , 0 , '' , 0 , 0 , 0 , '' , 'maxwidth75' );
else print '<input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . dol_escape_htmltag ( $search [ $key ]) . '">' ;
print '</td>' ;
}
2017-07-12 11:52:07 +02:00
}
2017-05-27 13:46:34 +02:00
// Extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php' ;
2017-05-27 13:46:34 +02:00
// Fields from hook
$parameters = array ( 'arrayfields' => $arrayfields );
2017-09-11 16:26:01 +02:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListOption' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2017-05-27 13:46:34 +02:00
print $hookmanager -> resPrint ;
// Action column
2019-05-19 13:51:47 +02:00
print '<td class="liste_titre maxwidthsearch">' ;
2017-06-07 16:44:04 +02:00
$searchpicto = $form -> showFilterButtons ();
2017-05-27 13:46:34 +02:00
print $searchpicto ;
print '</td>' ;
print '</tr>' . " \n " ;
2017-06-07 16:44:04 +02:00
2017-07-12 11:52:07 +02:00
// Fields title label
// --------------------------------------------------------------------
2017-06-07 16:44:04 +02:00
print '<tr class="liste_titre">' ;
2017-07-12 11:52:07 +02:00
foreach ( $object -> fields as $key => $val )
{
2019-05-22 19:21:55 +02:00
$cssforfield = ( empty ( $val [ 'css' ]) ? '' : $val [ 'css' ]);
2018-11-11 15:06:08 +01:00
if ( $key == 'status' ) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'center' ;
2019-05-22 19:21:55 +02:00
elseif ( in_array ( $val [ 'type' ], array ( 'date' , 'datetime' , 'timestamp' ))) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'center' ;
elseif ( in_array ( $val [ 'type' ], array ( 'timestamp' ))) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'nowrap' ;
elseif ( in_array ( $val [ 'type' ], array ( 'double(24,8)' , 'double(6,3)' , 'integer' , 'real' , 'price' ))) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'right' ;
2018-11-11 15:06:08 +01:00
if ( ! empty ( $arrayfields [ 't.' . $key ][ 'checked' ]))
{
print getTitleFieldOfList ( $arrayfields [ 't.' . $key ][ 'label' ], 0 , $_SERVER [ 'PHP_SELF' ], 't.' . $key , '' , $param , ( $cssforfield ? 'class="' . $cssforfield . '"' : '' ), $sortfield , $sortorder , ( $cssforfield ? $cssforfield . ' ' : '' )) . " \n " ;
}
2017-07-12 11:52:07 +02:00
}
2017-06-07 16:44:04 +02:00
// Extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php' ;
2017-06-07 16:44:04 +02:00
// Hook fields
2018-02-25 12:58:17 +01:00
$parameters = array ( 'arrayfields' => $arrayfields , 'param' => $param , 'sortfield' => $sortfield , 'sortorder' => $sortorder );
2017-09-11 16:26:01 +02:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListTitle' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2017-06-07 16:44:04 +02:00
print $hookmanager -> resPrint ;
2019-01-28 01:46:59 +01:00
// Action column
2019-03-03 09:08:29 +01:00
print getTitleFieldOfList ( $selectedfields , 0 , $_SERVER [ " PHP_SELF " ], '' , '' , '' , '' , $sortfield , $sortorder , 'center maxwidthsearch ' ) . " \n " ;
2017-06-07 16:44:04 +02:00
print '</tr>' . " \n " ;
2017-05-27 13:46:34 +02:00
// Detect if we need a fetch on each output line
$needToFetchEachLine = 0 ;
2018-04-13 17:54:27 +02:00
if ( is_array ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ]) && count ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ]) > 0 )
2017-05-27 13:46:34 +02:00
{
2018-04-13 17:54:27 +02:00
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ] as $key => $val )
{
2019-01-27 11:55:16 +01:00
if ( preg_match ( '/\$object/' , $val )) $needToFetchEachLine ++ ; // There is at least one compute field that use $object
2018-04-13 17:54:27 +02:00
}
2017-05-27 13:46:34 +02:00
}
2017-05-10 13:30:35 +02:00
2017-07-12 11:52:07 +02:00
// Loop on record
// --------------------------------------------------------------------
2017-05-27 13:46:34 +02:00
$i = 0 ;
$totalarray = array ();
while ( $i < min ( $num , $limit ))
{
2017-10-13 13:28:26 +02:00
$obj = $db -> fetch_object ( $resql );
if ( empty ( $obj )) break ; // Should not happen
2017-09-21 18:35:47 +02:00
2017-10-13 13:28:26 +02:00
// Store properties in $object
2017-11-24 15:47:38 +01:00
$object -> id = $obj -> rowid ;
foreach ( $object -> fields as $key => $val )
{
2019-05-22 14:49:18 +02:00
if ( property_exists ( $obj , $key )) $object -> $key = $obj -> $key ;
2017-11-24 15:47:38 +01:00
}
2017-09-21 18:35:47 +02:00
2017-10-13 13:28:26 +02:00
// Show here line of result
print '<tr class="oddeven">' ;
foreach ( $object -> fields as $key => $val )
{
2019-05-22 19:21:55 +02:00
$cssforfield = ( empty ( $val [ 'css' ]) ? '' : $val [ 'css' ]);
2019-01-03 11:47:27 +01:00
if ( in_array ( $val [ 'type' ], array ( 'date' , 'datetime' , 'timestamp' ))) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'center' ;
elseif ( $key == 'status' ) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'center' ;
2019-01-11 17:05:50 +01:00
2019-01-03 11:47:27 +01:00
if ( in_array ( $val [ 'type' ], array ( 'timestamp' ))) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'nowrap' ;
elseif ( $key == 'ref' ) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'nowrap' ;
2019-01-11 17:05:50 +01:00
2019-05-08 01:09:38 +02:00
if ( in_array ( $val [ 'type' ], array ( 'double(24,8)' , 'double(6,3)' , 'integer' , 'real' , 'price' ))) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'right' ;
2019-03-12 19:30:32 +01:00
2019-01-03 11:47:27 +01:00
if ( ! empty ( $arrayfields [ 't.' . $key ][ 'checked' ]))
2017-11-24 15:47:38 +01:00
{
2019-05-22 19:21:55 +02:00
print '<td' . ( $cssforfield ? ' class="' . $cssforfield . '"' : '' ) . '>' ;
2019-03-13 19:06:45 +01:00
if ( $key == 'status' ) print $object -> getLibStatut ( 5 );
elseif ( in_array ( $val [ 'type' ], array ( 'date' , 'datetime' , 'timestamp' ))) print $object -> showOutputField ( $val , $key , $db -> jdate ( $obj -> $key ), '' );
else print $object -> showOutputField ( $val , $key , $obj -> $key , '' );
2017-11-24 15:47:38 +01:00
print '</td>' ;
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
if ( ! empty ( $val [ 'isameasure' ]))
2017-10-13 13:28:26 +02:00
{
2017-11-24 15:47:38 +01:00
if ( ! $i ) $totalarray [ 'pos' ][ $totalarray [ 'nbfield' ]] = 't.' . $key ;
$totalarray [ 'val' ][ 't.' . $key ] += $obj -> $key ;
2017-10-13 13:28:26 +02:00
}
2017-11-24 15:47:38 +01:00
}
2017-10-13 13:28:26 +02:00
}
// Extra fields
2017-11-27 15:24:29 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php' ;
2017-10-13 13:28:26 +02:00
// Fields from hook
2017-09-21 18:35:47 +02:00
$parameters = array ( 'arrayfields' => $arrayfields , 'obj' => $obj );
$reshook = $hookmanager -> executeHooks ( 'printFieldListValue' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2017-10-13 13:28:26 +02:00
print $hookmanager -> resPrint ;
// Action column
2019-03-03 09:08:29 +01:00
print '<td class="nowrap center">' ;
2017-09-21 18:35:47 +02:00
if ( $massactionbutton || $massaction ) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2017-10-13 13:28:26 +02:00
{
$selected = 0 ;
2017-09-21 18:35:47 +02:00
if ( in_array ( $obj -> rowid , $arrayofselected )) $selected = 1 ;
print '<input id="cb' . $obj -> rowid . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $obj -> rowid . '"' . ( $selected ? ' checked="checked"' : '' ) . '>' ;
2017-10-13 13:28:26 +02:00
}
2017-09-21 18:35:47 +02:00
print '</td>' ;
2017-10-13 13:28:26 +02:00
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
2017-09-21 18:35:47 +02:00
2017-10-13 13:28:26 +02:00
print '</tr>' ;
2017-09-21 18:35:47 +02:00
2017-10-13 13:28:26 +02:00
$i ++ ;
2017-05-27 13:46:34 +02:00
}
// Show total line
2017-07-24 13:55:12 +02:00
if ( isset ( $totalarray [ 'pos' ]))
2017-05-27 13:46:34 +02:00
{
2017-10-13 13:28:26 +02:00
print '<tr class="liste_total">' ;
$i = 0 ;
while ( $i < $totalarray [ 'nbfield' ])
{
$i ++ ;
2019-03-03 09:08:29 +01:00
if ( ! empty ( $totalarray [ 'pos' ][ $i ])) print '<td class="right">' . price ( $totalarray [ 'val' ][ $totalarray [ 'pos' ][ $i ]]) . '</td>' ;
2017-10-13 13:28:26 +02:00
else
{
if ( $i == 1 )
{
2019-01-19 12:53:47 +01:00
if ( $num < $limit ) print '<td class="left">' . $langs -> trans ( " Total " ) . '</td>' ;
else print '<td class="left">' . $langs -> trans ( " Totalforthispage " ) . '</td>' ;
2017-10-13 13:28:26 +02:00
}
else print '<td></td>' ;
}
}
print '</tr>' ;
2017-05-27 13:46:34 +02:00
}
2017-06-22 15:22:44 +02:00
// If no record found
if ( $num == 0 )
{
2017-10-13 13:28:26 +02:00
$colspan = 1 ;
foreach ( $arrayfields as $key => $val ) { if ( ! empty ( $val [ 'checked' ])) $colspan ++ ; }
print '<tr><td colspan="' . $colspan . '" class="opacitymedium">' . $langs -> trans ( " NoRecordFound " ) . '</td></tr>' ;
2017-06-22 15:22:44 +02:00
}
2017-05-27 13:46:34 +02:00
$db -> free ( $resql );
$parameters = array ( 'arrayfields' => $arrayfields , 'sql' => $sql );
2017-09-11 16:26:01 +02:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListFooter' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2017-05-27 13:46:34 +02:00
print $hookmanager -> resPrint ;
print '</table>' . " \n " ;
print '</div>' . " \n " ;
print '</form>' . " \n " ;
2019-01-27 11:55:16 +01:00
if ( in_array ( 'builddoc' , $arrayofmassactions ) && ( $nbtotalofrecords === '' || $nbtotalofrecords ))
2017-05-27 13:46:34 +02:00
{
2018-02-21 11:02:45 +01:00
$hidegeneratedfilelistifempty = 1 ;
if ( $massaction == 'builddoc' || $action == 'remove_file' || $show_files ) $hidegeneratedfilelistifempty = 0 ;
2017-10-13 13:28:26 +02:00
2018-07-26 11:57:25 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
2018-02-21 11:02:45 +01:00
$formfile = new FormFile ( $db );
2017-10-13 13:28:26 +02:00
2018-02-21 11:02:45 +01:00
// Show list of available documents
$urlsource = $_SERVER [ 'PHP_SELF' ] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder ;
2019-01-27 11:55:16 +01:00
$urlsource .= str_replace ( '&' , '&' , $param );
2017-10-13 13:28:26 +02:00
2018-02-21 11:02:45 +01:00
$filedir = $diroutputmassaction ;
$genallowed = $user -> rights -> mymodule -> read ;
2019-05-29 09:38:19 +02:00
$delallowed = $user -> rights -> mymodule -> write ;
2018-02-21 11:02:45 +01:00
2019-01-27 11:55:16 +01:00
print $formfile -> showdocuments ( 'massfilesarea_mymodule' , '' , $filedir , $urlsource , 0 , $delallowed , '' , 1 , 1 , 0 , 48 , 1 , $param , $title , '' , '' , '' , null , $hidegeneratedfilelistifempty );
2017-05-27 13:46:34 +02:00
}
2017-05-10 13:30:35 +02:00
// End of page
llxFooter ();
2017-05-27 13:46:34 +02:00
$db -> close ();