2019-10-15 19:59:16 +02:00
< ? php
/* Copyright ( C ) 2007 - 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
*
* 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 ; 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
* 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 , see < http :// www . gnu . org / licenses />.
*/
/**
* \file mo_list . php
* \ingroup mrp
* \brief List page for mo
*/
//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
2020-01-09 22:14:39 +01:00
//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', '1'); // The main.inc.php does not make a redirect if not logged, instead show simple error message
//if (! defined("XFRAMEOPTIONS_ALLOWALL")) define('XFRAMEOPTIONS_ALLOWALL', '1'); // Do not add the HTTP header 'X-Frame-Options: SAMEORIGIN' but 'X-Frame-Options: ALLOWALL'
2019-10-15 19:59:16 +02:00
// Load Dolibarr environment
2019-10-16 03:17:53 +02:00
require '../main.inc.php' ;
2019-10-22 13:52:18 +02:00
2019-10-15 19:59:16 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
// load mrp libraries
2019-11-12 09:46:08 +01:00
require_once __DIR__ . '/class/mo.class.php' ;
2019-10-15 19:59:16 +02:00
// for other modules
//dol_include_once('/othermodule/class/otherobject.class.php');
// Load translation files required by the page
2019-11-12 09:46:08 +01:00
$langs -> loadLangs ( array ( " mrp " , " other " ));
2019-10-15 19:59:16 +02:00
2019-11-12 09:46:08 +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
$cancel = GETPOST ( 'cancel' , 'alpha' ); // We click on a Cancel button
$toselect = GETPOST ( 'toselect' , 'array' ); // Array of ids of elements selected into a list
2020-01-09 22:14:39 +01:00
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'molist' ; // To manage different context of search
2019-11-12 09:46:08 +01:00
$backtopage = GETPOST ( 'backtopage' , 'alpha' ); // Go back to a dedicated page
$optioncss = GETPOST ( 'optioncss' , 'aZ' ); // Option for the css output (always '' except when 'print')
2019-10-15 19:59:16 +02:00
2019-11-12 09:46:08 +01:00
$id = GETPOST ( 'id' , 'int' );
2019-10-15 19:59:16 +02:00
// Load variable for pagination
2019-11-12 09:46:08 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2019-10-15 19:59:16 +02:00
$sortfield = GETPOST ( 'sortfield' , 'alpha' );
$sortorder = GETPOST ( 'sortorder' , 'alpha' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2019-10-15 19:59:16 +02:00
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
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
//if (! $sortfield) $sortfield="p.date_fin";
//if (! $sortorder) $sortorder="DESC";
// Initialize technical objects
$object = new Mo ( $db );
$extrafields = new ExtraFields ( $db );
2019-11-12 09:46:08 +01:00
$diroutputmassaction = $conf -> mrp -> dir_output . '/temp/massgeneration/' . $user -> id ;
$hookmanager -> initHooks ( array ( 'molist' )); // Note that conf->hooks_modules contains array
2019-10-15 19:59:16 +02:00
// Fetch optionals attributes and labels
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
$search_array_options = $extrafields -> getOptionalsFromPost ( $object -> table_element , '' , 'search_' );
// Default sort order (if not yet defined by previous GETPOST)
2019-11-12 09:46:08 +01:00
if ( ! $sortfield ) $sortfield = " t. " . key ( $object -> fields ); // Set here default search field. By default 1st field in definition.
if ( ! $sortorder ) $sortorder = " ASC " ;
2019-10-15 19:59:16 +02:00
// Security check
if ( empty ( $conf -> mrp -> enabled )) accessforbidden ( 'Module not enabled' );
2019-11-12 09:46:08 +01:00
$socid = 0 ;
2019-10-31 20:46:31 +01:00
if ( $user -> socid > 0 ) // Protection if external user
2019-10-15 19:59:16 +02:00
{
2019-10-31 20:46:31 +01:00
//$socid = $user->socid;
2019-10-15 19:59:16 +02:00
accessforbidden ();
}
//$result = restrictedArea($user, 'mrp', $id, '');
// Initialize array of search criterias
2020-05-04 13:24:09 +02:00
$search_all = GETPOST ( 'search_all' , 'alphanohtml' ) ? trim ( GETPOST ( 'search_all' , 'alphanohtml' )) : trim ( GETPOST ( 'sall' , 'alphanohtml' ));
2019-11-12 09:46:08 +01:00
$search = array ();
foreach ( $object -> fields as $key => $val )
2019-10-15 19:59:16 +02:00
{
2019-11-12 09:46:08 +01:00
if ( GETPOST ( 'search_' . $key , 'alpha' )) $search [ $key ] = GETPOST ( 'search_' . $key , 'alpha' );
2019-10-15 19:59:16 +02:00
}
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array ();
2019-11-12 09:46:08 +01:00
foreach ( $object -> fields as $key => $val )
2019-10-15 19:59:16 +02:00
{
2019-11-12 09:46:08 +01:00
if ( $val [ 'searchall' ]) $fieldstosearchall [ 't.' . $key ] = $val [ 'label' ];
2019-10-15 19:59:16 +02:00
}
// Definition of fields for list
2019-11-12 09:46:08 +01:00
$arrayfields = array ();
foreach ( $object -> fields as $key => $val )
2019-10-15 19:59:16 +02:00
{
// If $val['visible']==0, then we never show the field
2019-11-12 09:46:08 +01:00
if ( ! empty ( $val [ 'visible' ])) $arrayfields [ 't.' . $key ] = array ( 'label' => $val [ 'label' ], 'checked' => (( $val [ 'visible' ] < 0 ) ? 0 : 1 ), 'enabled' => ( $val [ 'enabled' ] && ( $val [ 'visible' ] != 3 )), 'position' => $val [ 'position' ]);
2019-10-15 19:59:16 +02:00
}
// Extra fields
if ( is_array ( $extrafields -> attributes [ $object -> table_element ][ 'label' ]) && count ( $extrafields -> attributes [ $object -> table_element ][ 'label' ]) > 0 )
{
2019-11-12 09:46:08 +01:00
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'label' ] as $key => $val )
2019-10-15 19:59:16 +02:00
{
2020-01-09 22:14:39 +01:00
if ( ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'list' ][ $key ])) {
$arrayfields [ " ef. " . $key ] = array (
'label' => $extrafields -> attributes [ $object -> table_element ][ 'label' ][ $key ],
2020-04-10 10:59:32 +02:00
'checked' => (( $extrafields -> attributes [ $object -> table_element ][ 'list' ][ $key ] < 0 ) ? 0 : 1 ),
2020-01-09 22:14:39 +01:00
'position' => $extrafields -> attributes [ $object -> table_element ][ 'pos' ][ $key ],
2020-04-10 10:59:32 +02:00
'enabled' => ( abs ( $extrafields -> attributes [ $object -> table_element ][ 'list' ][ $key ]) != 3 && $extrafields -> attributes [ $object -> table_element ][ 'perms' ][ $key ])
2020-01-09 22:14:39 +01:00
);
}
2019-10-15 19:59:16 +02:00
}
}
$object -> fields = dol_sort_array ( $object -> fields , 'position' );
$arrayfields = dol_sort_array ( $arrayfields , 'position' );
2020-01-09 22:14:39 +01:00
$permissiontoread = $user -> rights -> mrp -> read ;
$permissiontoadd = $user -> rights -> mrp -> write ;
$permissiontodelete = $user -> rights -> mrp -> delete ;
2019-10-15 19:59:16 +02:00
/*
* Actions
*/
2019-11-12 09:46:08 +01:00
if ( GETPOST ( 'cancel' , 'alpha' )) { $action = 'list' ; $massaction = '' ; }
if ( ! GETPOST ( 'confirmmassaction' , 'alpha' ) && $massaction != 'presend' && $massaction != 'confirm_presend' ) { $massaction = '' ; }
2019-10-15 19:59:16 +02:00
2019-11-12 09:46:08 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2019-10-15 19:59:16 +02:00
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
if ( empty ( $reshook ))
{
// Selection of new fields
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php' ;
// Purge search criteria
2019-11-12 09:46:08 +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
2019-10-15 19:59:16 +02:00
{
2019-11-12 09:46:08 +01:00
foreach ( $object -> fields as $key => $val )
2019-10-15 19:59:16 +02:00
{
2019-11-12 09:46:08 +01:00
$search [ $key ] = '' ;
2019-10-15 19:59:16 +02:00
}
2019-11-12 09:46:08 +01:00
$toselect = '' ;
$search_array_options = array ();
2019-10-15 19:59:16 +02: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' ))
{
2019-11-12 09:46:08 +01:00
$massaction = '' ; // Protection to avoid mass action if we force a new search during a mass action confirmation
2019-10-15 19:59:16 +02:00
}
// Mass actions
2019-11-12 09:46:08 +01:00
$objectclass = 'Mo' ;
$objectlabel = 'Mo' ;
2019-10-15 19:59:16 +02:00
$uploaddir = $conf -> mrp -> dir_output ;
include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php' ;
}
/*
* View
*/
2019-11-12 09:46:08 +01:00
$form = new Form ( $db );
2019-10-15 19:59:16 +02:00
2019-11-12 09:46:08 +01:00
$now = dol_now ();
2019-10-15 19:59:16 +02:00
//$help_url="EN:Module_Mo|FR:Module_Mo_FR|ES:Módulo_Mo";
2019-11-12 09:46:08 +01:00
$help_url = '' ;
2019-10-15 19:59:16 +02:00
$title = $langs -> trans ( 'ListOfManufacturingOrders' );
// Build and execute select
// --------------------------------------------------------------------
$sql = 'SELECT ' ;
2019-11-12 09:46:08 +01:00
foreach ( $object -> fields as $key => $val )
2019-10-15 19:59:16 +02:00
{
2019-11-12 09:46:08 +01:00
$sql .= 't.' . $key . ', ' ;
2019-10-15 19:59:16 +02:00
}
// Add fields from extrafields
2020-01-09 22:14:39 +01:00
if ( ! empty ( $extrafields -> attributes [ $object -> table_element ][ 'label' ])) {
2019-11-12 09:46:08 +01:00
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'label' ] as $key => $val ) $sql .= ( $extrafields -> attributes [ $object -> table_element ][ 'type' ][ $key ] != 'separate' ? " ef. " . $key . ' as options_' . $key . ', ' : '' );
2020-01-09 22:14:39 +01:00
}
2019-10-15 19:59:16 +02:00
// Add fields from hooks
2019-11-12 09:46:08 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListSelect' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2020-01-09 22:14:39 +01:00
$sql .= preg_replace ( '/^,/' , '' , $hookmanager -> resPrint );
$sql = preg_replace ( '/,\s*$/' , '' , $sql );
2019-11-12 09:46:08 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . $object -> table_element . " as t " ;
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 ) . " ) " ;
else $sql .= " WHERE 1 = 1 " ;
foreach ( $search as $key => $val )
2019-10-15 19:59:16 +02:00
{
if ( $key == 'status' && $search [ $key ] == - 1 ) continue ;
2019-11-12 09:46:08 +01:00
$mode_search = (( $object -> isInt ( $object -> fields [ $key ]) || $object -> isFloat ( $object -> fields [ $key ])) ? 1 : 0 );
2020-01-09 22:14:39 +01:00
if ( strpos ( $object -> fields [ $key ][ 'type' ], 'integer:' ) === 0 ) {
if ( $search [ $key ] == '-1' ) $search [ $key ] = '' ;
$mode_search = 2 ;
}
2019-11-12 09:46:08 +01:00
if ( $search [ $key ] != '' ) $sql .= natural_search ( $key , $search [ $key ], (( $key == 'status' ) ? 2 : $mode_search ));
2019-10-15 19:59:16 +02:00
}
2019-11-12 09:46:08 +01:00
if ( $search_all ) $sql .= natural_search ( array_keys ( $fieldstosearchall ), $search_all );
2020-01-09 22:14:39 +01:00
//$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
2019-10-15 19:59:16 +02:00
// Add where from extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php' ;
// Add where from hooks
2019-11-12 09:46:08 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListWhere' , $parameters , $object ); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager -> resPrint ;
2019-10-15 19:59:16 +02:00
/* If a group by is required
$sql .= " GROUP BY "
foreach ( $object -> fields as $key => $val )
{
$sql .= 't.' . $key . ', ' ;
}
// Add fields from extrafields
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 . ', ' : '' );
2020-01-09 22:14:39 +01:00
}
2019-10-15 19:59:16 +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 ;
2020-01-09 22:14:39 +01:00
$sql = preg_replace ( '/,\s*$/' , '' , $sql );
2019-10-15 19:59:16 +02:00
*/
2019-11-12 09:46:08 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2019-10-15 19:59:16 +02:00
// Count total nb of records
$nbtotalofrecords = '' ;
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST ))
{
$resql = $db -> query ( $sql );
$nbtotalofrecords = $db -> num_rows ( $resql );
if (( $page * $limit ) > $nbtotalofrecords ) // if total of record found is smaller than page * limit, goto and load page 0
{
$page = 0 ;
$offset = 0 ;
}
}
// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
2020-01-09 22:14:39 +01:00
if ( is_numeric ( $nbtotalofrecords ) && ( $limit > $nbtotalofrecords || empty ( $limit )))
2019-10-15 19:59:16 +02:00
{
$num = $nbtotalofrecords ;
2020-05-21 15:05:19 +02:00
} else {
2020-01-09 22:14:39 +01:00
if ( $limit ) $sql .= $db -> plimit ( $limit + 1 , $offset );
2019-10-15 19:59:16 +02:00
2019-11-12 09:46:08 +01:00
$resql = $db -> query ( $sql );
if ( ! $resql )
2019-10-15 19:59:16 +02:00
{
dol_print_error ( $db );
exit ;
}
$num = $db -> num_rows ( $resql );
}
// Direct jump if only one record found
2020-01-09 22:14:39 +01:00
if ( $num == 1 && ! empty ( $conf -> global -> MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE ) && $search_all && ! $page )
2019-10-15 19:59:16 +02:00
{
$obj = $db -> fetch_object ( $resql );
$id = $obj -> rowid ;
header ( " Location: " . dol_buildpath ( '/mrp/mo_card.php' , 1 ) . '?id=' . $id );
exit ;
}
// Output page
// --------------------------------------------------------------------
llxHeader ( '' , $title , $help_url );
// 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 > ' ;
2019-11-12 09:46:08 +01:00
$arrayofselected = is_array ( $toselect ) ? $toselect : array ();
2019-10-15 19:59:16 +02:00
2019-11-12 09:46:08 +01:00
$param = '' ;
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) $param .= '&contextpage=' . urlencode ( $contextpage );
if ( $limit > 0 && $limit != $conf -> liste_limit ) $param .= '&limit=' . urlencode ( $limit );
foreach ( $search as $key => $val )
2019-10-15 19:59:16 +02:00
{
2019-11-12 09:46:08 +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 ]);
2019-10-15 19:59:16 +02:00
}
2019-11-12 09:46:08 +01:00
if ( $optioncss != '' ) $param .= '&optioncss=' . urlencode ( $optioncss );
2019-10-15 19:59:16 +02:00
// Add $param from extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php' ;
// List of mass actions available
2019-11-12 09:46:08 +01:00
$arrayofmassactions = array (
2019-10-15 19:59:16 +02:00
//'validate'=>$langs->trans("Validate"),
//'generate_doc'=>$langs->trans("ReGeneratePDF"),
//'builddoc'=>$langs->trans("PDFMerge"),
//'presend'=>$langs->trans("SendByMail"),
);
2020-01-09 22:14:39 +01:00
if ( $permissiontodelete ) $arrayofmassactions [ 'predelete' ] = '<span class="fa fa-trash paddingrightonly"></span>' . $langs -> trans ( " Delete " );
2019-11-12 09:46:08 +01:00
if ( GETPOST ( 'nomassaction' , 'int' ) || in_array ( $massaction , array ( 'presend' , 'predelete' ))) $arrayofmassactions = array ();
$massactionbutton = $form -> selectMassAction ( '' , $arrayofmassactions );
2019-10-15 19:59:16 +02:00
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
if ( $optioncss != '' ) print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-10-15 19:59:16 +02:00
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="contextpage" value="' . $contextpage . '">' ;
2020-01-09 22:14:39 +01:00
$newcardbutton = dolGetButtonTitle ( $langs -> trans ( 'New' ), '' , 'fa fa-plus-circle' , DOL_URL_ROOT . '/mrp/mo_card.php?action=create&backtopage=' . urlencode ( $_SERVER [ 'PHP_SELF' ]), '' , $permissiontoadd );
2019-10-15 19:59:16 +02:00
2020-04-12 19:56:50 +02:00
print_barre_liste ( $title , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , $massactionbutton , $num , $nbtotalofrecords , 'mrp' , 0 , $newcardbutton , '' , $limit , 0 , 0 , 1 );
2019-10-15 19:59:16 +02:00
// Add code for pre mass action (confirmation or email presend form)
2019-11-12 09:46:08 +01:00
$topicmail = " SendMoRef " ;
$modelmail = " mo " ;
$objecttmp = new Mo ( $db );
$trackid = 'xxxx' . $object -> id ;
2019-10-15 19:59:16 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php' ;
if ( $search_all )
{
2019-11-12 09:46:08 +01:00
foreach ( $fieldstosearchall as $key => $val ) $fieldstosearchall [ $key ] = $langs -> trans ( $val );
print '<div class="divsearchfieldfilter">' . $langs -> trans ( " FilterOnInto " , $search_all ) . join ( ', ' , $fieldstosearchall ) . '</div>' ;
2019-10-15 19:59:16 +02:00
}
$moreforfilter = '' ;
/* $moreforfilter .= '<div class="divsearchfield">' ;
$moreforfilter .= $langs -> trans ( 'MyFilter' ) . ': <input type="text" name="search_myfield" value="' . dol_escape_htmltag ( $search_myfield ) . '">' ;
$moreforfilter .= '</div>' ; */
2019-11-12 09:46:08 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldPreListTitle' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2019-10-15 19:59:16 +02:00
if ( empty ( $reshook )) $moreforfilter .= $hookmanager -> resPrint ;
else $moreforfilter = $hookmanager -> resPrint ;
2019-11-12 09:46:08 +01:00
if ( ! empty ( $moreforfilter ))
2019-10-15 19:59:16 +02:00
{
print '<div class="liste_titre liste_titre_bydiv centpercent">' ;
print $moreforfilter ;
print '</div>' ;
}
2019-11-12 09:46:08 +01:00
$varpage = empty ( $contextpage ) ? $_SERVER [ " PHP_SELF " ] : $contextpage ;
$selectedfields = $form -> multiSelectArrayWithCheckbox ( 'selectedfields' , $arrayfields , $varpage ); // This also change content of $arrayfields
$selectedfields .= ( count ( $arrayofmassactions ) ? $form -> showCheckAddButtons ( 'checkforselect' , 1 ) : '' );
2019-10-15 19:59:16 +02:00
2019-11-12 09:46:08 +01:00
print '<div class="div-table-responsive">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
2020-03-27 11:15:38 +01:00
print '<table class="tagtable nobottomiftotal liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
2019-10-15 19:59:16 +02:00
// Fields title search
// --------------------------------------------------------------------
print '<tr class="liste_titre">' ;
2019-11-12 09:46:08 +01:00
foreach ( $object -> fields as $key => $val )
2019-10-15 19:59:16 +02:00
{
2019-11-12 09:46:08 +01:00
$cssforfield = ( empty ( $val [ 'css' ]) ? '' : $val [ 'css' ]);
if ( $key == 'status' ) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'center' ;
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' )) && $val [ 'label' ] != 'TechnicalID' ) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'right' ;
if ( ! empty ( $arrayfields [ 't.' . $key ][ 'checked' ]))
2019-10-15 19:59:16 +02:00
{
2019-11-12 09:46:08 +01:00
print '<td class="liste_titre' . ( $cssforfield ? ' ' . $cssforfield : '' ) . '">' ;
2019-10-16 03:17:53 +02:00
if ( is_array ( $val [ 'arrayofkeyval' ])) print $form -> selectarray ( 'search_' . $key , $val [ 'arrayofkeyval' ], $search [ $key ], $val [ 'notnull' ], 0 , 0 , '' , 1 , 0 , 0 , '' , 'maxwidth75' );
2020-01-09 22:14:39 +01:00
elseif ( strpos ( $val [ 'type' ], 'integer:' ) === 0 ) {
print $object -> showInputField ( $val , $key , $search [ $key ], '' , '' , 'search_' , 'maxwidth150' , 1 );
2020-05-21 15:05:19 +02:00
} elseif ( ! preg_match ( '/^(date|timestamp)/' , $val [ 'type' ])) print '<input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . dol_escape_htmltag ( $search [ $key ]) . '">' ;
2019-10-15 19:59:16 +02:00
print '</td>' ;
}
}
// Extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php' ;
// Fields from hook
2019-11-12 09:46:08 +01:00
$parameters = array ( 'arrayfields' => $arrayfields );
$reshook = $hookmanager -> executeHooks ( 'printFieldListOption' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2019-10-15 19:59:16 +02:00
print $hookmanager -> resPrint ;
// Action column
print '<td class="liste_titre maxwidthsearch">' ;
2019-11-12 09:46:08 +01:00
$searchpicto = $form -> showFilterButtons ();
2019-10-15 19:59:16 +02:00
print $searchpicto ;
print '</td>' ;
print '</tr>' . " \n " ;
// Fields title label
// --------------------------------------------------------------------
print '<tr class="liste_titre">' ;
2019-11-12 09:46:08 +01:00
foreach ( $object -> fields as $key => $val )
2019-10-15 19:59:16 +02:00
{
2019-11-12 09:46:08 +01:00
$cssforfield = ( empty ( $val [ 'css' ]) ? '' : $val [ 'css' ]);
if ( $key == 'status' ) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'center' ;
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' )) && $val [ 'label' ] != 'TechnicalID' ) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'right' ;
if ( ! empty ( $arrayfields [ 't.' . $key ][ 'checked' ]))
2019-10-15 19:59:16 +02:00
{
2019-11-12 09:46:08 +01:00
print getTitleFieldOfList ( $arrayfields [ 't.' . $key ][ 'label' ], 0 , $_SERVER [ 'PHP_SELF' ], 't.' . $key , '' , $param , ( $cssforfield ? 'class="' . $cssforfield . '"' : '' ), $sortfield , $sortorder , ( $cssforfield ? $cssforfield . ' ' : '' )) . " \n " ;
2019-10-15 19:59:16 +02:00
}
}
// Extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php' ;
// Hook fields
2019-11-12 09:46:08 +01:00
$parameters = array ( 'arrayfields' => $arrayfields , 'param' => $param , 'sortfield' => $sortfield , 'sortorder' => $sortorder );
$reshook = $hookmanager -> executeHooks ( 'printFieldListTitle' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2019-10-15 19:59:16 +02:00
print $hookmanager -> resPrint ;
// Action column
print getTitleFieldOfList ( $selectedfields , 0 , $_SERVER [ " PHP_SELF " ], '' , '' , '' , '' , $sortfield , $sortorder , 'center maxwidthsearch ' ) . " \n " ;
print '</tr>' . " \n " ;
// Detect if we need a fetch on each output line
2019-11-12 09:46:08 +01:00
$needToFetchEachLine = 0 ;
2019-10-15 19:59:16 +02:00
if ( is_array ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ]) && count ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ]) > 0 )
{
foreach ( $extrafields -> attributes [ $object -> table_element ][ 'computed' ] as $key => $val )
{
2019-11-12 09:46:08 +01:00
if ( preg_match ( '/\$object/' , $val )) $needToFetchEachLine ++ ; // There is at least one compute field that use $object
2019-10-15 19:59:16 +02:00
}
}
// Loop on record
// --------------------------------------------------------------------
2019-11-12 09:46:08 +01:00
$i = 0 ;
$totalarray = array ();
2020-01-09 22:14:39 +01:00
while ( $i < ( $limit ? min ( $num , $limit ) : $num ))
2019-10-15 19:59:16 +02:00
{
$obj = $db -> fetch_object ( $resql );
2019-11-12 09:46:08 +01:00
if ( empty ( $obj )) break ; // Should not happen
2019-10-15 19:59:16 +02:00
// Store properties in $object
2020-01-09 22:14:39 +01:00
$object -> setVarsFromFetchObj ( $obj );
2019-10-15 19:59:16 +02:00
// Show here line of result
print '<tr class="oddeven">' ;
2019-11-12 09:46:08 +01:00
foreach ( $object -> fields as $key => $val )
2019-10-15 19:59:16 +02:00
{
2019-11-12 09:46:08 +01:00
$cssforfield = ( empty ( $val [ 'css' ]) ? '' : $val [ 'css' ]);
if ( in_array ( $val [ 'type' ], array ( 'date' , 'datetime' , 'timestamp' ))) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'center' ;
elseif ( $key == 'status' ) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'center' ;
2019-10-15 19:59:16 +02:00
2019-11-12 09:46:08 +01:00
if ( in_array ( $val [ 'type' ], array ( 'timestamp' ))) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'nowrap' ;
elseif ( $key == 'ref' ) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'nowrap' ;
2019-10-15 19:59:16 +02:00
2019-11-12 09:46:08 +01:00
if ( in_array ( $val [ 'type' ], array ( 'double(24,8)' , 'double(6,3)' , 'integer' , 'real' , 'price' )) && $key != 'status' ) $cssforfield .= ( $cssforfield ? ' ' : '' ) . 'right' ;
2020-03-27 11:15:38 +01:00
if ( in_array ( $key , array ( 'fk_soc' , 'fk_user' , 'fk_warehouse' ))) $cssforfield = 'tdoverflowmax100' ;
2019-10-15 19:59:16 +02:00
2019-11-12 09:46:08 +01:00
if ( ! empty ( $arrayfields [ 't.' . $key ][ 'checked' ]))
2019-10-15 19:59:16 +02:00
{
print '<td' . ( $cssforfield ? ' class="' . $cssforfield . '"' : '' ) . '>' ;
if ( $key == 'status' ) print $object -> getLibStatut ( 5 );
2020-01-09 22:14:39 +01:00
else print $object -> showOutputField ( $val , $key , $object -> $key , '' );
2019-10-15 19:59:16 +02:00
print '</td>' ;
2019-11-12 09:46:08 +01:00
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
if ( ! empty ( $val [ 'isameasure' ]))
2019-10-15 19:59:16 +02:00
{
2019-11-12 09:46:08 +01:00
if ( ! $i ) $totalarray [ 'pos' ][ $totalarray [ 'nbfield' ]] = 't.' . $key ;
2020-01-09 22:14:39 +01:00
$totalarray [ 'val' ][ 't.' . $key ] += $object -> $key ;
2019-10-15 19:59:16 +02:00
}
}
}
// Extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php' ;
// Fields from hook
2020-01-09 22:14:39 +01:00
$parameters = array ( 'arrayfields' => $arrayfields , 'object' => $object , 'obj' => $obj , 'i' => $i , 'totalarray' =>& $totalarray );
2019-11-12 09:46:08 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListValue' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2019-10-15 19:59:16 +02:00
print $hookmanager -> resPrint ;
// Action column
print '<td class="nowrap center">' ;
if ( $massactionbutton || $massaction ) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{
2019-11-12 09:46:08 +01:00
$selected = 0 ;
2020-01-09 22:14:39 +01:00
if ( in_array ( $object -> id , $arrayofselected )) $selected = 1 ;
print '<input id="cb' . $object -> id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $object -> id . '"' . ( $selected ? ' checked="checked"' : '' ) . '>' ;
2019-10-15 19:59:16 +02:00
}
print '</td>' ;
2019-11-12 09:46:08 +01:00
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
2019-10-15 19:59:16 +02:00
2020-01-09 22:14:39 +01:00
print '</tr>' . " \n " ;
2019-10-15 19:59:16 +02:00
$i ++ ;
}
// Show total line
2019-11-05 12:47:38 +01:00
include DOL_DOCUMENT_ROOT . '/core/tpl/list_print_total.tpl.php' ;
2019-10-15 19:59:16 +02:00
// If no record found
if ( $num == 0 )
{
2019-11-12 09:46:08 +01:00
$colspan = 1 ;
foreach ( $arrayfields as $key => $val ) { if ( ! empty ( $val [ 'checked' ])) $colspan ++ ; }
2019-10-15 19:59:16 +02:00
print '<tr><td colspan="' . $colspan . '" class="opacitymedium">' . $langs -> trans ( " NoRecordFound " ) . '</td></tr>' ;
}
$db -> free ( $resql );
2019-11-12 09:46:08 +01:00
$parameters = array ( 'arrayfields' => $arrayfields , 'sql' => $sql );
$reshook = $hookmanager -> executeHooks ( 'printFieldListFooter' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2019-10-15 19:59:16 +02:00
print $hookmanager -> resPrint ;
print '</table>' . " \n " ;
print '</div>' . " \n " ;
print '</form>' . " \n " ;
if ( in_array ( 'builddoc' , $arrayofmassactions ) && ( $nbtotalofrecords === '' || $nbtotalofrecords ))
{
2019-11-12 09:46:08 +01:00
$hidegeneratedfilelistifempty = 1 ;
if ( $massaction == 'builddoc' || $action == 'remove_file' || $show_files ) $hidegeneratedfilelistifempty = 0 ;
2019-10-15 19:59:16 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
$formfile = new FormFile ( $db );
// Show list of available documents
2019-11-12 09:46:08 +01:00
$urlsource = $_SERVER [ 'PHP_SELF' ] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder ;
$urlsource .= str_replace ( '&' , '&' , $param );
2019-10-15 19:59:16 +02:00
2019-11-12 09:46:08 +01:00
$filedir = $diroutputmassaction ;
2020-01-09 22:14:39 +01:00
$genallowed = $permissiontoread ;
$delallowed = $permissiontoadd ;
2019-10-15 19:59:16 +02:00
print $formfile -> showdocuments ( 'massfilesarea_mrp' , '' , $filedir , $urlsource , 0 , $delallowed , '' , 1 , 1 , 0 , 48 , 1 , $param , $title , '' , '' , '' , null , $hidegeneratedfilelistifempty );
}
// End of page
llxFooter ();
$db -> close ();