2020-10-23 11:14:18 +02:00
< ? php
/* Copyright ( C ) 2001 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2018 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
* Copyright ( C ) 2012 - 2016 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2013 - 2019 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2013 - 2015 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
* Copyright ( C ) 2013 Jean Heimburger < jean @ tiaris . info >
* Copyright ( C ) 2013 Cédric Salvador < csalvador @ gpcsolutions . fr >
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
* Copyright ( C ) 2013 Adolfo segura < adolfo . segura @ gmail . com >
* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
* Copyright ( C ) 2016 Ferran Marcet < fmarcet @ 2 byte . es >
*
* 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 htdocs / multicurrency / multicurrency_rate . php
* \ingroup multicurrency
* \brief Page to list multicurrency rate
*/
require '../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/multicurrency.lib.php' ;
// Load translation files required by the page
$langs -> loadLangs ( array ( 'multicurrency' ));
$action = GETPOST ( 'action' , 'alpha' );
$massaction = GETPOST ( 'massaction' , 'alpha' );
$show_files = GETPOST ( 'show_files' , 'int' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
2020-10-31 18:51:30 +01:00
$toselect = GETPOST ( 'toselect' , 'array' );
$id_rate_selected = GETPOST ( 'id_rate' , 'int' );
$sall = trim (( GETPOST ( 'search_all' , 'alphanohtml' ) != '' ) ? GETPOST ( 'search_all' , 'alphanohtml' ) : GETPOST ( 'sall' , 'alphanohtml' ));
2020-12-23 14:46:07 +01:00
$search_date_sync = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'search_date_syncmonth' , 'int' ), GETPOST ( 'search_date_syncday' , 'int' ), GETPOST ( 'search_date_syncyear' , 'int' ));
$search_date_sync_end = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'search_date_sync_endmonth' , 'int' ), GETPOST ( 'search_date_sync_endday' , 'int' ), GETPOST ( 'search_date_sync_endyear' , 'int' ));
2020-10-23 11:14:18 +02:00
$search_rate = GETPOST ( 'search_rate' , 'alpha' );
$search_code = GETPOST ( 'search_code' , 'alpha' );
$multicurrency_code = GETPOST ( 'multicurrency_code' , 'alpha' );
2020-10-31 14:24:00 +01:00
$dateinput = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'dateinputmonth' , 'int' ), GETPOST ( 'dateinputday' , 'int' ), GETPOST ( 'dateinputyear' , 'int' ));
$rateinput = price2num ( GETPOST ( 'rateinput' , 'alpha' ));
2020-10-23 11:14:18 +02:00
$optioncss = GETPOST ( 'optioncss' , 'alpha' );
2020-10-31 18:51:30 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2022-01-13 11:09:37 +01:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-10-31 18:51:30 +01:00
$page = ( GETPOST ( " page " , 'int' ) ? GETPOST ( " page " , 'int' ) : 0 );
2020-10-23 11:14:18 +02:00
2021-02-26 18:26:44 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2020-10-23 11:14:18 +02:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2020-10-31 18:51:30 +01:00
if ( ! $sortfield ) $sortfield = " cr.date_sync " ;
2022-06-29 14:31:21 +02:00
if ( ! $sortorder ) $sortorder = " DESC " ;
2020-10-23 11:14:18 +02:00
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
2020-10-31 18:51:30 +01:00
$object = new CurrencyRate ( $db );
2020-10-23 11:14:18 +02:00
$extrafields = new ExtraFields ( $db );
2020-10-31 18:51:30 +01:00
$form = new Form ( $db );
2020-10-23 11:14:18 +02:00
2020-10-28 12:12:29 +01:00
$hookmanager -> initHooks ( array ( 'EditorRatelist' , 'globallist' ));
2021-02-26 18:26:44 +01:00
if ( empty ( $action )) {
$action = 'list' ;
}
2020-10-23 11:14:18 +02:00
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array (
'cr.date_sync' => " date_sync " ,
'cr.rate' => " rate " ,
'm.code' => " code " ,
);
// Definition of fields for lists
2020-10-31 18:51:30 +01:00
$arrayfields = array (
2020-10-31 14:24:00 +01:00
'cr.date_sync' => array ( 'label' => 'Date' , 'checked' => 1 ),
'cr.rate' => array ( 'label' => 'Rate' , 'checked' => 1 ),
'm.code' => array ( 'label' => 'Code' , 'checked' => 1 ),
2020-10-23 11:14:18 +02:00
);
$object -> fields = dol_sort_array ( $object -> fields , 'position' );
$arrayfields = dol_sort_array ( $arrayfields , 'position' );
2021-03-25 13:33:25 +01:00
// Access control
// TODO Open this page to a given permission so a sale representative can modify change rates. Permission should be added into module multicurrency.
// One permission to read rates (history) and one to add/edit rates.
if ( ! $user -> admin || empty ( $conf -> multicurrency -> enabled )) {
accessforbidden ();
}
2020-10-23 11:14:18 +02:00
2022-06-29 14:31:21 +02:00
$error = 0 ;
2020-10-23 11:14:18 +02:00
/*
* Actions
*/
2021-03-25 13:33:25 +01:00
2020-10-31 18:51:30 +01:00
if ( $action == " create " ) {
2022-06-29 14:31:21 +02:00
if ( empty ( $multicurrency_code ) || $multicurrency_code == '-1' ) {
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( " Currency " )), null , " errors " );
$error ++ ;
}
if ( $rateinput === '0' ) {
setEventMessages ( $langs -> trans ( 'NoEmptyRate' ), null , " errors " );
$error ++ ;
} elseif ( empty ( $rateinput )) {
setEventMessages ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( " Rate " )), null , " errors " );
$error ++ ;
}
if ( ! $error ) {
2020-10-23 11:14:18 +02:00
$currencyRate_static = new CurrencyRate ( $db );
$currency_static = new MultiCurrency ( $db );
$fk_currency = $currency_static -> getIdFromCode ( $db , $multicurrency_code );
$currencyRate_static -> fk_multicurrency = $fk_currency ;
$currencyRate_static -> entity = $conf -> entity ;
2021-01-11 14:06:21 +01:00
$currencyRate_static -> date_sync = $dateinput ;
2020-10-23 11:14:18 +02:00
$currencyRate_static -> rate = $rateinput ;
$result = $currencyRate_static -> create ( intval ( $fk_currency ));
2020-10-31 14:24:00 +01:00
if ( $result > 0 ) {
setEventMessages ( $langs -> trans ( 'successRateCreate' , $multicurrency_code ), null );
2020-10-23 11:14:18 +02:00
} else {
dol_syslog ( " currencyRate:createRate " , LOG_WARNING );
2020-10-31 14:24:00 +01:00
setEventMessages ( $currencyRate_static -> error , $currencyRate_static -> errors , 'errors' );
2020-10-23 11:14:18 +02:00
}
}
}
2020-10-31 18:51:30 +01:00
if ( $action == 'update' ) {
2020-10-23 11:14:18 +02:00
$currencyRate = new CurrencyRate ( $db );
$result = $currencyRate -> fetch ( $id_rate_selected );
2020-10-31 18:51:30 +01:00
if ( $result > 0 ) {
$currency_static = new MultiCurrency ( $db );
2020-10-23 11:14:18 +02:00
$fk_currency = $currency_static -> getIdFromCode ( $db , $multicurrency_code );
2020-10-31 14:24:00 +01:00
$currencyRate -> date_sync = $dateinput ;
2020-10-23 11:14:18 +02:00
$currencyRate -> fk_multicurrency = $fk_currency ;
2020-10-31 14:24:00 +01:00
$currencyRate -> rate = $rateinput ;
2020-10-23 11:14:18 +02:00
$res = $currencyRate -> update ();
2020-10-31 18:51:30 +01:00
if ( $res ) {
2020-10-31 14:24:00 +01:00
setEventMessages ( $langs -> trans ( 'successUpdateRate' ), null );
2020-10-31 18:51:30 +01:00
} else {
2020-10-31 14:24:00 +01:00
setEventMessages ( $currencyRate -> error , $currencyRate -> errors , " errors " );
2020-10-23 11:14:18 +02:00
}
2020-10-31 18:51:30 +01:00
} else {
2020-10-31 14:24:00 +01:00
setEventMessages ( $langs -> trans ( 'Error' ), null , " warnings " );
2020-10-23 11:14:18 +02:00
}
}
2020-10-31 18:51:30 +01:00
if ( $action == " deleteRate " ) {
2020-10-23 11:14:18 +02:00
$current_rate = new CurrencyRate ( $db );
$current_rate -> fetch ( intval ( $id_rate_selected ));
2020-10-31 18:51:30 +01:00
if ( $current_rate ) {
2020-10-23 11:14:18 +02:00
$current_currency = new MultiCurrency ( $db );
$current_currency -> fetch ( $current_rate -> fk_multicurrency );
2020-10-31 18:51:30 +01:00
if ( $current_currency ) {
2020-10-31 14:24:00 +01:00
$delayedhtmlcontent = $form -> formconfirm (
2020-10-23 11:14:18 +02:00
$_SERVER [ " PHP_SELF " ] . '?id_rate=' . $id_rate_selected ,
$langs -> trans ( 'DeleteLineRate' ),
$langs -> trans ( 'ConfirmDeleteLineRate' , $current_rate -> rate , $current_currency -> name , $current_rate -> date_sync ),
'confirm_delete' ,
'' ,
0 ,
1
);
2020-10-31 18:51:30 +01:00
} else {
2020-10-23 11:14:18 +02:00
dol_syslog ( " Multicurrency::fetch " , LOG_WARNING );
}
2020-10-31 18:51:30 +01:00
} else {
2020-10-23 11:14:18 +02:00
setEventMessage ( $langs -> trans ( 'NoCurrencyRateSelected' ), " warnings " );
}
}
2020-10-31 18:51:30 +01:00
if ( $action == " confirm_delete " ) {
2020-10-23 11:14:18 +02:00
$current_rate = new CurrencyRate ( $db );
$current_rate -> fetch ( intval ( $id_rate_selected ));
2020-10-31 18:51:30 +01:00
if ( $current_rate ) {
$result = $current_rate -> delete ();
if ( $result ) {
2020-10-31 14:24:00 +01:00
setEventMessages ( $langs -> trans ( 'successRateDelete' ), null );
2020-10-31 18:51:30 +01:00
} else {
2020-10-31 14:24:00 +01:00
setEventMessages ( $current_rate -> error , $current_rate -> errors , 'errors' );
2020-10-23 11:14:18 +02:00
}
2020-10-31 18:51:30 +01:00
} else {
2020-10-31 14:24:00 +01:00
setEventMessages ( $langs -> trans ( 'NoCurrencyRateSelected' ), null , " warnings " );
2020-10-23 11:14:18 +02:00
dol_syslog ( $langs -> trans ( 'NoCurrencyRateSelected' ), LOG_WARNING );
}
}
2020-10-31 18:51:30 +01:00
if ( GETPOST ( 'cancel' , 'alpha' )) { $action = 'list' ; $massaction = '' ; }
if ( ! GETPOST ( 'confirmmassaction' , 'alpha' ) && $massaction != 'presend' && $massaction != 'confirm_presend' ) { $massaction = '' ; }
2020-10-23 11:14:18 +02:00
2020-10-31 18:51:30 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2020-10-23 11:14:18 +02:00
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2021-04-29 17:37:19 +02:00
if ( empty ( $reshook )) {
2020-10-23 11:14:18 +02:00
// Selection of new fields
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php' ;
// Purge search criteria
2021-02-26 18:26:44 +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
2020-10-31 18:51:30 +01:00
$sall = " " ;
$search_date_sync = " " ;
2021-04-19 11:52:17 +02:00
$search_date_sync_end = " " ;
2020-10-31 18:51:30 +01:00
$search_rate = " " ;
$search_code = " " ;
$search_array_options = array ();
2020-10-23 11:14:18 +02:00
}
// Mass actions
2020-10-31 18:51:30 +01:00
$objectclass = " CurrencyRate " ;
2020-10-23 11:14:18 +02:00
$uploaddir = $conf -> multicurrency -> multidir_output ; // define only because core/actions_massactions.inc.php want it
$permtoread = $user -> admin ;
$permtodelete = $user -> admin ;
include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php' ;
}
2021-03-25 13:33:25 +01:00
2020-10-23 11:14:18 +02:00
/*
* View
*/
2021-11-17 11:14:12 +01:00
$form = new Form ( $db );
2020-10-23 11:14:18 +02:00
2020-10-31 18:51:30 +01:00
$title = $langs -> trans ( " CurrencyRate " );
2021-05-03 23:09:11 +02:00
$page_name = " MultiCurrencySetup " ;
2021-03-25 13:33:25 +01:00
$help_url = '' ;
2020-10-23 11:14:18 +02:00
2021-03-25 13:33:25 +01:00
llxHeader ( '' , $title , $help_url , '' );
2020-10-23 11:14:18 +02:00
// Subheader
$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToModuleList " ) . '</a>' ;
2022-03-07 19:46:24 +01:00
print load_fiche_titre ( $langs -> trans ( $page_name ), $linkback );
2020-10-23 11:14:18 +02:00
// Configuration header
$head = multicurrencyAdminPrepareHead ();
2022-03-07 19:46:24 +01:00
print dol_get_fiche_head ( $head , 'ratelist' , $langs -> trans ( " ModuleSetup " ), - 1 , " multicurrency " );
2020-10-23 11:14:18 +02:00
// ACTION
2020-12-23 14:51:13 +01:00
if ( ! in_array ( $action , array ( " updateRate " , " deleteRate " ))) {
2020-10-31 18:51:30 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="post" name="formulaire">' ;
2020-12-16 15:16:23 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2022-03-07 19:42:57 +01:00
print '<div class="div-table-responsive-no-min">' ;
2020-12-23 14:46:07 +01:00
print '<table class="noborder centpercent"><tr>' ;
2020-10-23 11:14:18 +02:00
2020-10-31 18:51:30 +01:00
print ' <td>' . $langs -> trans ( 'Date' ) . '</td>' ;
2020-10-31 14:24:00 +01:00
print ' <td>' ;
2020-12-23 14:46:07 +01:00
print $form -> selectDate ( $dateinput , 'dateinput' , 0 , 0 , 1 );
2020-10-31 14:24:00 +01:00
print '</td>' ;
2020-10-23 11:14:18 +02:00
2020-10-31 18:51:30 +01:00
print '<td> ' . $langs -> trans ( 'Currency' ) . '</td>' ;
2021-08-23 17:45:16 +02:00
print '<td>' . $form -> selectMultiCurrency (( GETPOSTISSET ( 'multicurrency_code' ) ? GETPOST ( 'multicurrency_code' , 'alpha' ) : $multicurrency_code ), 'multicurrency_code' , 1 , " code != ' " . $db -> escape ( $conf -> currency ) . " ' " , true ) . '</td>' ;
2020-10-23 11:14:18 +02:00
2022-06-29 14:31:21 +02:00
print ' <td>' . $langs -> trans ( 'Rate' ) . ' / ' . $langs -> getCurrencySymbol ( $conf -> currency ) . '</td>' ;
2021-04-29 15:59:55 +02:00
print ' <td><input type="text" min="0" step="any" class="maxwidth75" name="rateinput" value="' . dol_escape_htmltag ( $rateinput ) . '"></td>' ;
2020-10-23 11:14:18 +02:00
print '<td>' ;
print '<input type="hidden" name="action" value="create">' ;
2022-03-07 19:42:57 +01:00
print '<input type="submit" class="button button-add small" name="btnCreateCurrencyRate" value="' . $langs -> trans ( 'CreateRate' ) . '">' ;
2020-10-23 11:14:18 +02:00
print '</td>' ;
print '</tr></table>' ;
2022-03-07 19:42:57 +01:00
print '</div>' ;
2020-10-23 11:14:18 +02:00
print '</form>' ;
2020-10-31 14:24:00 +01:00
print '<br>' ;
2020-10-23 11:14:18 +02:00
}
2022-06-29 14:31:21 +02:00
$sql = 'SELECT cr.rowid, cr.date_sync, cr.rate, cr.entity, m.code, m.name' ;
2020-10-23 11:14:18 +02:00
// Add fields from hooks
2020-10-31 18:51:30 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListSelect' , $parameters ); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager -> resPrint ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'multicurrency_rate as cr ' ;
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " multicurrency AS m ON cr.fk_multicurrency = m.rowid " ;
2020-10-23 11:14:18 +02:00
if ( $sall ) $sql .= natural_search ( array_keys ( $fieldstosearchall ), $sall );
2021-04-29 17:37:19 +02:00
if ( $search_date_sync && $search_date_sync_end ) {
2021-04-19 14:24:56 +02:00
$sql .= " AND (cr.date_sync BETWEEN ' " . $db -> idate ( $search_date_sync ) . " ' AND ' " . $db -> idate ( $search_date_sync_end ) . " ') " ;
2020-12-23 14:46:07 +01:00
} elseif ( $search_date_sync && ! $search_date_sync_end ) {
2021-04-19 11:52:17 +02:00
$sql .= natural_search ( 'cr.date_sync' , $db -> idate ( $search_date_sync ));
2020-12-23 14:46:07 +01:00
}
2020-10-31 14:24:00 +01:00
if ( $search_rate ) $sql .= natural_search ( 'cr.rate' , $search_rate );
2020-10-23 11:14:18 +02:00
if ( $search_code ) $sql .= natural_search ( 'm.code' , $search_code );
2020-10-31 18:51:30 +01:00
$sql .= " WHERE m.code <> ' " . $db -> escape ( $conf -> currency ) . " ' " ;
2020-10-23 11:14:18 +02:00
// Add where from hooks
2020-10-31 18:51:30 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListWhere' , $parameters ); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager -> resPrint ;
$sql .= " GROUP BY cr.rowid, cr.date_sync, cr.rate, m.code, cr.entity, m.code, m.name " ;
2020-10-23 11:14:18 +02:00
// Add fields from hooks
2020-10-31 18:51:30 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldSelect' , $parameters ); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager -> resPrint ;
2020-10-23 11:14:18 +02:00
2020-10-31 18:51:30 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2020-10-23 11:14:18 +02:00
$nbtotalofrecords = '' ;
2021-02-26 18:26:44 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
2020-10-23 11:14:18 +02:00
$result = $db -> query ( $sql );
2020-10-31 18:51:30 +01:00
if ( $result ) {
2020-10-23 11:14:18 +02:00
$nbtotalofrecords = $db -> num_rows ( $result );
2021-02-26 18:26:44 +01:00
if (( $page * $limit ) > $nbtotalofrecords ) { // if total resultset is smaller then paging size (filtering), goto and load page 0
2020-10-23 11:14:18 +02:00
$page = 0 ;
$offset = 0 ;
}
2020-10-31 18:51:30 +01:00
} else {
2020-10-23 11:14:18 +02:00
setEventMessage ( $langs -> trans ( 'No_record_on_multicurrency_rate' ), 'warnings' );
}
}
2020-10-31 18:51:30 +01:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2020-10-23 11:14:18 +02:00
$resql = $db -> query ( $sql );
2021-02-26 18:26:44 +01:00
if ( $resql ) {
2020-10-23 11:14:18 +02:00
$num = $db -> num_rows ( $resql );
2020-10-31 18:51:30 +01:00
$arrayofselected = is_array ( $toselect ) ? $toselect : array ();
2020-10-23 11:14:18 +02:00
2020-10-31 18:51:30 +01:00
$param = '' ;
2021-02-26 18:26:44 +01:00
if ( ! empty ( $contextpage ) && $contextpage != $_SERVER [ " PHP_SELF " ]) {
$param .= '&contextpage=' . urlencode ( $contextpage );
}
if ( $limit > 0 && $limit != $conf -> liste_limit ) {
$param .= '&limit=' . urlencode ( $limit );
}
if ( $sall ) {
$param .= " &sall= " . urlencode ( $sall );
}
2020-10-23 11:14:18 +02:00
2020-12-23 14:46:07 +01:00
if ( $search_date_sync ) $param = " &search_date_sync= " . $search_date_sync ;
2021-04-19 11:52:17 +02:00
if ( $search_date_sync_end ) $param = " &search_date_sync_end= " . $search_date_sync_end ;
2020-10-31 18:51:30 +01:00
if ( $search_rate ) $param = " &search_rate= " . urlencode ( $search_rate );
2021-04-19 11:52:17 +02:00
if ( $search_code != '' ) $param .= " &search_code= " . urlencode ( $search_code );
2020-10-23 11:14:18 +02:00
// Add $param from extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php' ;
2021-02-26 18:26:44 +01:00
if ( $user -> admin ) {
$arrayofmassactions [ 'predelete' ] = $langs -> trans ( " Delete " );
}
if ( in_array ( $massaction , array ( 'presend' , 'predelete' ))) {
$arrayofmassactions = array ();
}
2020-10-31 18:51:30 +01:00
$massactionbutton = $form -> selectMassAction ( '' , $arrayofmassactions );
2020-10-23 11:14:18 +02:00
2020-10-31 14:24:00 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST" name="formulaire">' ;
2021-02-26 18:26:44 +01:00
if ( $optioncss != '' ) {
print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
}
2020-10-27 09:58:32 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2020-10-23 11:14:18 +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="page" value="' . $page . '">' ;
print '<input type="hidden" name="type" value="' . $type . '">' ;
print_barre_liste ( $texte , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , $massactionbutton , $num , $nbtotalofrecords , 'title_currency.png' , 0 , $newcardbutton , '' , $limit );
include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php' ;
2021-02-26 18:26:44 +01:00
if ( $sall ) {
foreach ( $fieldstosearchall as $key => $val ) {
$fieldstosearchall [ $key ] = $langs -> trans ( $val );
}
2020-10-31 18:51:30 +01:00
print '<div class="divsearchfieldfilter">' . $langs -> trans ( " FilterOnInto " , $sall ) . join ( ', ' , $fieldstosearchall ) . '</div>' ;
2020-10-23 11:14:18 +02:00
}
// Filter on categories
2020-10-31 18:51:30 +01:00
$moreforfilter = '' ;
2020-10-23 11:14:18 +02:00
2020-10-31 18:51:30 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldPreListTitle' , $parameters ); // Note that $action and $object may have been modified by hook
2021-02-26 18:26:44 +01:00
if ( empty ( $reshook )) {
$moreforfilter .= $hookmanager -> resPrint ;
} else {
$moreforfilter = $hookmanager -> resPrint ;
}
2020-10-23 11:14:18 +02:00
2021-02-26 18:26:44 +01:00
if ( $moreforfilter ) {
2020-10-23 11:14:18 +02:00
print '<div class="liste_titre liste_titre_bydiv centpercent">' ;
print $moreforfilter ;
print '</div>' ;
}
2020-10-31 18:51:30 +01:00
$varpage = empty ( $contextpage ) ? $_SERVER [ " PHP_SELF " ] : $contextpage ;
$selectedfields = $form -> multiSelectArrayWithCheckbox ( 'selectedfields' , $arrayfields , $varpage ); // This also change content of $arrayfields
2021-02-26 18:26:44 +01:00
if ( $massactionbutton ) {
$selectedfields .= $form -> showCheckAddButtons ( 'checkforselect' , 1 );
}
2020-10-23 11:14:18 +02:00
2022-03-07 19:42:57 +01:00
print '<div class="div-table-responsive">' ;
2021-11-17 11:14:12 +01:00
print '<table class="tagtable centpercent nomarginbottom liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' . " \n " ;
2020-10-23 11:14:18 +02:00
// Lines with input filters
print '<tr class="liste_titre_filter">' ;
// date
2021-05-03 23:09:11 +02:00
if ( ! empty ( $arrayfields [ 'cr.date_sync' ][ 'checked' ])) {
print '<td class="liste_titre" align="left">' ;
print $form -> selectDate ( dol_print_date ( $search_date_sync , " %Y-%m-%d " ), 'search_date_sync' , 0 , 0 , 1 );
print $form -> selectDate ( dol_print_date ( $search_date_sync_end , " %Y-%m-%d " ), 'search_date_sync_end' , 0 , 0 , 1 );
print '</td>' ;
}
// code
if ( ! empty ( $arrayfields [ 'm.code' ][ 'checked' ])) {
print '<td class="liste_titre" align="left">' ;
print $form -> selectMultiCurrency ( $multicurrency_code , 'search_code' , 1 , " code != ' " . $conf -> currency . " ' " , true );
print '</td>' ;
}
// rate
if ( ! empty ( $arrayfields [ 'cr.rate' ][ 'checked' ])) {
print '<td class="liste_titre" align="left">' ;
2022-03-07 19:42:57 +01:00
print '<input class="flat maxwidth75" type="text" name="search_rate" value="' . dol_escape_htmltag ( $search_rate ) . '">' ;
2021-05-03 23:09:11 +02:00
print '</td>' ;
}
2020-10-23 11:14:18 +02:00
// Fields from hook
2020-10-31 18:51:30 +01:00
$parameters = array ( 'arrayfields' => $arrayfields );
$reshook = $hookmanager -> executeHooks ( 'printFieldListOption' , $parameters ); // Note that $action and $object may have been modified by hook
2020-10-23 11:14:18 +02:00
print $hookmanager -> resPrint ;
print '<td class="liste_titre" align="middle">' ;
2020-10-31 18:51:30 +01:00
$searchpicto = $form -> showFilterButtons ();
2020-10-23 11:14:18 +02:00
print $searchpicto ;
print '</td>' ;
print '</tr>' ;
print '<tr class="liste_titre">' ;
2021-02-26 18:26:44 +01:00
if ( ! empty ( $arrayfields [ 'cr.date_sync' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 'cr.date_sync' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " cr.date_sync " , " " , $param , " " , $sortfield , $sortorder );
}
if ( ! empty ( $arrayfields [ 'm.code' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 'm.code' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " m.code " , " " , $param , " " , $sortfield , $sortorder );
}
if ( ! empty ( $arrayfields [ 'cr.rate' ][ 'checked' ])) {
print_liste_field_titre ( $arrayfields [ 'cr.rate' ][ 'label' ], $_SERVER [ " PHP_SELF " ], " cr.rate " , " " , $param , " " , $sortfield , $sortorder );
}
2020-10-23 11:14:18 +02:00
// Hook fields
2020-10-31 18:51:30 +01:00
$parameters = array ( 'arrayfields' => $arrayfields , 'param' => $param , 'sortfield' => $sortfield , 'sortorder' => $sortorder );
$reshook = $hookmanager -> executeHooks ( 'printFieldListTitle' , $parameters ); // Note that $action and $object may have been modified by hook
2020-10-23 11:14:18 +02:00
print $hookmanager -> resPrint ;
print_liste_field_titre ( $selectedfields , $_SERVER [ " PHP_SELF " ], " " , '' , '' , 'align="center"' , $sortfield , $sortorder , 'maxwidthsearch ' );
print " </tr> \n " ;
$i = 0 ;
2020-10-31 18:51:30 +01:00
$totalarray = array ();
2021-05-03 23:09:11 +02:00
while ( $i < min ( $num , $limit )) {
$obj = $db -> fetch_object ( $resql );
print '<tr class="oddeven">' ;
// USER REQUEST UPDATE FOR THIS LINE
if ( $action == " updateRate " && $obj -> rowid == $id_rate_selected ) {
// var_dump($obj);
print ' <td><input class="minwidth200" name="dateinput" value="' . date ( 'Y-m-d' , dol_stringtotime ( $obj -> date_sync )) . '" type="date"></td>' ;
print '<td>' . $form -> selectMultiCurrency ( $obj -> code , 'multicurrency_code' , 1 , " code != ' " . $conf -> currency . " ' " , true ) . '</td>' ;
2021-10-20 11:05:40 +02:00
print ' <td><input type="text" min ="0" step="any" class="minwidth200" name="rateinput" value="' . dol_escape_htmltag ( $obj -> rate ) . '"></td>' ;
2021-05-03 23:09:11 +02:00
print '<td class="center nowrap ">' ;
print '<input type="hidden" name="page" value="' . dol_escape_htmltag ( $page ) . '">' ;
print '<input type="hidden" name="id_rate" value="' . dol_escape_htmltag ( $obj -> rowid ) . '">' ;
print '<button type="submit" class="button" name="action" value="update">' . $langs -> trans ( " Modify " ) . '</button>' ;
print '<button type="submit" class="button" name="action" value="cancel">' . $langs -> trans ( " Cancel " ) . '</button>' ;
print '</td>' ;
} else {
// date_sync
if ( ! empty ( $arrayfields [ 'cr.date_sync' ][ 'checked' ])) {
print '<td class="tdoverflowmax200">' ;
print $obj -> date_sync ;
print " </td> \n " ;
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
}
2020-10-23 11:14:18 +02:00
2021-05-03 23:09:11 +02:00
// code
if ( ! empty ( $arrayfields [ 'm.code' ][ 'checked' ])) {
print '<td class="tdoverflowmax200">' ;
2022-06-29 14:31:21 +02:00
print $obj -> code ;
print ' - <span class="opacitymedium">' . $obj -> name . '</span>' ;
2021-05-03 23:09:11 +02:00
print " </td> \n " ;
2020-10-23 11:14:18 +02:00
2021-05-03 23:09:11 +02:00
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
}
2020-10-23 11:14:18 +02:00
2021-05-03 23:09:11 +02:00
// rate
if ( ! empty ( $arrayfields [ 'cr.rate' ][ 'checked' ])) {
print '<td class="tdoverflowmax200">' ;
print $obj -> rate ;
print " </td> \n " ;
if ( ! $i ) $totalarray [ 'nbfield' ] ++ ;
}
2021-04-29 17:34:56 +02:00
2020-10-23 11:14:18 +02:00
2021-05-03 23:09:11 +02:00
// Fields from hook
$parameters = array ( 'arrayfields' => $arrayfields , 'obj' => $obj );
$reshook = $hookmanager -> executeHooks ( 'printFieldListValue' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
// Action
print '<td class="nowrap" align="center">' ;
if ( $massactionbutton || $massaction ) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
$selected = 0 ;
if ( in_array ( $obj -> rowid , $arrayofselected )) {
$selected = 1 ;
}
2021-09-19 14:41:46 +02:00
print '<a class="editfielda marginleftonly marginrightonly" href="' . $_SERVER [ " PHP_SELF " ] . '?action=updateRate&token=' . newToken () . '&id_rate=' . $obj -> rowid . '">' . img_picto ( 'edit' , 'edit' ) . '</a>' ;
print '<a class="marginleftonly marginrightonly" href="' . $_SERVER [ " PHP_SELF " ] . '?action=deleteRate&token=' . newToken () . '&id_rate=' . $obj -> rowid . '">' . img_picto ( 'delete' , 'delete' ) . '</a>' ;
2021-05-03 23:09:11 +02:00
print '<input id="cb' . $obj -> rowid . '" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="' . $obj -> rowid . '"' . ( $selected ? ' checked="checked"' : '' ) . '>' ;
}
print '</td>' ;
if ( ! $i ) {
$totalarray [ 'nbfield' ] ++ ;
2021-04-29 17:37:19 +02:00
}
2020-10-23 11:14:18 +02:00
2021-05-03 23:09:11 +02:00
print " </tr> \n " ;
$i ++ ;
}
2021-04-29 17:37:19 +02:00
}
2020-10-23 11:14:18 +02:00
2021-04-29 17:37:19 +02:00
$db -> free ( $resql );
2020-10-23 11:14:18 +02:00
2021-04-29 17:37:19 +02:00
print " </table> " ;
print " </div> " ;
print '</form>' ;
} else {
dol_print_error ( $db );
}
2020-10-23 11:14:18 +02:00
2021-04-29 17:34:56 +02:00
llxFooter ();
$db -> close ();