2009-03-25 22:26:15 +01:00
< ? php
2016-11-19 02:16:12 +01:00
/* Copyright ( C ) 2005 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ inodbox . com >
2015-05-13 07:46:12 +02:00
* Copyright ( C ) 2012 Christophe Battarel < christophe . battarel @ altairis . fr >
2009-03-25 22:26:15 +01:00
*
* 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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2009-03-25 22:26:15 +01: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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2009-03-25 22:26:15 +01:00
*/
/**
* \file htdocs / imports / import . php
* \ingroup import
2011-02-05 19:42:34 +01:00
* \brief Pages of import Wizard
2009-03-25 22:26:15 +01:00
*/
2012-08-22 23:11:24 +02:00
require_once '../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/imports/class/import.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/modules/import/modules_import.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/import.lib.php' ;
2009-03-25 22:26:15 +01:00
2018-05-26 21:11:25 +02:00
// Load translation files required by the page
2018-05-26 15:41:32 +02:00
$langs -> loadLangs ( array ( 'exports' , 'compta' , 'errors' ));
2009-03-25 22:26:15 +01:00
2010-01-21 23:19:16 +01:00
// Security check
2019-11-13 19:35:02 +01:00
$result = restrictedArea ( $user , 'import' );
2020-12-03 19:45:36 +01:00
// Map icons, array duplicated in export.php, was not synchronized, TODO put it somewhere only once
2019-11-13 19:35:02 +01:00
$entitytoicon = array (
2020-12-03 19:45:36 +01:00
'invoice' => 'bill' ,
2021-02-26 18:20:21 +01:00
'invoice_line' => 'bill' ,
2020-12-03 19:45:36 +01:00
'order' => 'order' ,
2021-02-26 18:20:21 +01:00
'order_line' => 'order' ,
2020-12-03 19:45:36 +01:00
'propal' => 'propal' ,
2021-02-26 18:20:21 +01:00
'propal_line' => 'propal' ,
2020-12-03 19:45:36 +01:00
'intervention' => 'intervention' ,
2021-02-26 18:20:21 +01:00
'inter_line' => 'intervention' ,
2020-12-03 19:45:36 +01:00
'member' => 'user' ,
2021-02-26 18:20:21 +01:00
'member_type' => 'group' ,
'subscription' => 'payment' ,
'payment' => 'payment' ,
2020-12-03 19:45:36 +01:00
'tax' => 'bill' ,
2021-02-26 18:20:21 +01:00
'tax_type' => 'generic' ,
'other' => 'generic' ,
2020-12-03 19:45:36 +01:00
'account' => 'account' ,
'product' => 'product' ,
2021-02-26 18:20:21 +01:00
'virtualproduct' => 'product' ,
2020-12-03 19:45:36 +01:00
'subproduct' => 'product' ,
'product_supplier_ref' => 'product' ,
2021-02-26 18:20:21 +01:00
'stock' => 'stock' ,
2020-12-03 19:45:36 +01:00
'warehouse' => 'stock' ,
'batch' => 'stock' ,
'stockbatch' => 'stock' ,
'category' => 'category' ,
'shipment' => 'sending' ,
2021-02-26 18:20:21 +01:00
'shipment_line' => 'sending' ,
'reception' => 'sending' ,
'reception_line' => 'sending' ,
2020-12-03 19:45:36 +01:00
'expensereport' => 'trip' ,
2021-02-26 18:20:21 +01:00
'expensereport_line' => 'trip' ,
2020-12-03 19:45:36 +01:00
'holiday' => 'holiday' ,
2021-02-26 18:20:21 +01:00
'contract_line' => 'contract' ,
'translation' => 'generic' ,
'bomm' => 'bom' ,
'bomline' => 'bom'
2009-05-19 02:14:27 +02:00
);
2020-12-03 19:45:36 +01:00
// Translation code, array duplicated in export.php, was not synchronized, TODO put it somewhere only once
$entitytolang = array (
'user' => 'User' ,
'company' => 'Company' ,
2021-02-26 18:20:21 +01:00
'contact' => 'Contact' ,
2020-12-03 19:45:36 +01:00
'invoice' => 'Bill' ,
2021-02-26 18:20:21 +01:00
'invoice_line' => 'InvoiceLine' ,
2020-12-03 19:45:36 +01:00
'order' => 'Order' ,
2021-02-26 18:20:21 +01:00
'order_line' => 'OrderLine' ,
'propal' => 'Proposal' ,
'propal_line' => 'ProposalLine' ,
2020-12-03 19:45:36 +01:00
'intervention' => 'Intervention' ,
2021-02-26 18:20:21 +01:00
'inter_line' => 'InterLine' ,
2020-12-03 19:45:36 +01:00
'member' => 'Member' ,
2021-02-26 18:20:21 +01:00
'member_type' => 'MemberType' ,
'subscription' => 'Subscription' ,
2020-12-03 19:45:36 +01:00
'tax' => 'SocialContribution' ,
2021-02-26 18:20:21 +01:00
'tax_type' => 'DictionarySocialContributions' ,
2020-12-03 19:45:36 +01:00
'account' => 'BankTransactions' ,
'payment' => 'Payment' ,
'product' => 'Product' ,
'virtualproduct' => 'AssociatedProducts' ,
'subproduct' => 'SubProduct' ,
'product_supplier_ref' => 'SupplierPrices' ,
'service' => 'Service' ,
2021-02-26 18:20:21 +01:00
'stock' => 'Stock' ,
2020-12-03 19:45:36 +01:00
'movement' => 'StockMovement' ,
'batch' => 'Batch' ,
'stockbatch' => 'StockDetailPerBatch' ,
'warehouse' => 'Warehouse' ,
'category' => 'Category' ,
'other' => 'Other' ,
2021-02-26 18:20:21 +01:00
'trip' => 'TripsAndExpenses' ,
'shipment' => 'Shipments' ,
'shipment_line' => 'ShipmentLine' ,
'project' => 'Projects' ,
'projecttask' => 'Tasks' ,
'task_time' => 'TaskTimeSpent' ,
2020-12-03 19:45:36 +01:00
'action' => 'Event' ,
'expensereport' => 'ExpenseReport' ,
'expensereport_line' => 'ExpenseReportLine' ,
'holiday' => 'TitreRequestCP' ,
'contract' => 'Contract' ,
2021-02-26 18:20:21 +01:00
'contract_line' => 'ContractLine' ,
'translation' => 'Translation' ,
'bom' => 'BOM' ,
'bomline' => 'BOMLine'
2009-05-19 02:14:27 +02:00
);
2009-03-25 22:26:15 +01:00
2012-03-03 18:41:06 +01:00
$datatoimport = GETPOST ( 'datatoimport' );
$format = GETPOST ( 'format' );
$filetoimport = GETPOST ( 'filetoimport' );
2019-01-27 11:55:16 +01:00
$action = GETPOST ( 'action' , 'alpha' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
2012-03-03 18:41:06 +01:00
$step = ( GETPOST ( 'step' ) ? GETPOST ( 'step' ) : 1 );
2019-11-13 19:35:02 +01:00
$import_name = GETPOST ( 'import_name' );
2012-03-03 18:41:06 +01:00
$hexa = GETPOST ( 'hexa' );
2019-11-13 19:35:02 +01:00
$importmodelid = GETPOST ( 'importmodelid' );
2022-04-13 16:21:25 +02:00
$excludefirstline = ( GETPOST ( 'excludefirstline' ) ? GETPOST ( 'excludefirstline' ) : 1 );
2016-08-22 12:25:03 +02:00
$endatlinenb = ( GETPOST ( 'endatlinenb' ) ? GETPOST ( 'endatlinenb' ) : '' );
2017-10-03 11:28:13 +02:00
$updatekeys = ( GETPOST ( 'updatekeys' , 'array' ) ? GETPOST ( 'updatekeys' , 'array' ) : array ());
2020-09-28 20:05:58 +02:00
$separator = ( GETPOST ( 'separator' , 'nohtml' ) ? GETPOST ( 'separator' , 'nohtml' ) : ( ! empty ( $conf -> global -> IMPORT_CSV_SEPARATOR_TO_USE ) ? $conf -> global -> IMPORT_CSV_SEPARATOR_TO_USE : ',' ));
$enclosure = ( GETPOST ( 'enclosure' , 'nohtml' ) ? GETPOST ( 'enclosure' , 'nohtml' ) : '"' );
2022-02-18 16:53:55 +01:00
$separator_used = str_replace ( '\t' , " \t " , $separator );
2009-03-25 22:26:15 +01:00
2019-11-13 19:35:02 +01:00
$objimport = new Import ( $db );
$objimport -> load_arrays ( $user , ( $step == 1 ? '' : $datatoimport ));
2009-03-25 22:26:15 +01:00
2019-11-13 19:35:02 +01:00
$objmodelimport = new ModeleImports ();
2009-10-02 00:17:18 +02:00
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2009-03-25 22:26:15 +01:00
$htmlother = new FormOther ( $db );
$formfile = new FormFile ( $db );
2009-09-12 04:07:25 +02:00
// Init $array_match_file_to_database from _SESSION
2019-11-13 19:35:02 +01:00
$serialized_array_match_file_to_database = isset ( $_SESSION [ " dol_array_match_file_to_database " ]) ? $_SESSION [ " dol_array_match_file_to_database " ] : '' ;
$array_match_file_to_database = array ();
$fieldsarray = explode ( ',' , $serialized_array_match_file_to_database );
2021-02-26 18:20:21 +01:00
foreach ( $fieldsarray as $elem ) {
2019-11-13 19:35:02 +01:00
$tabelem = explode ( '=' , $elem , 2 );
$key = $tabelem [ 0 ];
$val = ( isset ( $tabelem [ 1 ]) ? $tabelem [ 1 ] : '' );
2022-04-13 16:21:25 +02:00
if ( $key && $val ) {
2019-11-13 19:35:02 +01:00
$array_match_file_to_database [ $key ] = $val ;
2009-09-12 04:07:25 +02:00
}
}
2009-03-25 22:26:15 +01:00
/*
* Actions
*/
2011-09-20 17:29:31 +02:00
2009-09-12 04:07:25 +02:00
/*
2009-03-25 22:26:15 +01:00
if ( $action == 'downfield' || $action == 'upfield' )
{
2009-06-07 20:08:41 +02:00
$pos = $array_match_file_to_database [ $_GET [ " field " ]];
2009-05-19 02:14:27 +02:00
if ( $action == 'downfield' ) $newpos = $pos + 1 ;
if ( $action == 'upfield' ) $newpos = $pos - 1 ;
2009-06-07 20:08:41 +02:00
// Recherche code avec qui switcher
2009-05-19 02:14:27 +02:00
$newcode = " " ;
2009-06-07 20:08:41 +02:00
foreach ( $array_match_file_to_database as $code => $value )
2009-05-19 02:14:27 +02:00
{
if ( $value == $newpos )
{
$newcode = $code ;
break ;
}
}
//print("Switch pos=$pos (code=".$_GET["field"].") and newpos=$newpos (code=$newcode)");
2009-06-07 20:08:41 +02:00
if ( $newcode ) // Si newcode trouve (protection contre resoumission de page)
2009-05-19 02:14:27 +02:00
{
2009-06-07 20:08:41 +02:00
$array_match_file_to_database [ $_GET [ " field " ]] = $newpos ;
$array_match_file_to_database [ $newcode ] = $pos ;
2009-09-12 04:07:25 +02:00
$_SESSION [ " dol_array_match_file_to_database " ] = $serialized_array_match_file_to_database ;
2009-05-19 02:14:27 +02:00
}
2009-03-25 22:26:15 +01:00
}
2009-09-12 04:07:25 +02:00
*/
2021-02-26 18:20:21 +01:00
if ( $action == 'builddoc' ) {
2009-05-19 02:14:27 +02:00
// Build import file
2019-11-13 19:35:02 +01:00
$result = $objimport -> build_file ( $user , GETPOST ( 'model' , 'alpha' ), $datatoimport , $array_match_file_to_database );
2021-02-26 18:20:21 +01:00
if ( $result < 0 ) {
2015-12-11 09:54:30 +01:00
setEventMessages ( $objimport -> error , $objimport -> errors , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2015-12-11 09:54:30 +01:00
setEventMessages ( $langs -> trans ( " FileSuccessfullyBuilt " ), null , 'mesgs' );
2009-05-19 02:14:27 +02:00
}
2009-03-25 22:26:15 +01:00
}
2021-02-26 18:20:21 +01:00
if ( $action == 'deleteprof' ) {
if ( GETPOST ( " id " , 'int' )) {
2020-09-30 18:39:23 +02:00
$objimport -> fetch ( GETPOST ( " id " , 'int' ));
2019-11-13 19:35:02 +01:00
$result = $objimport -> delete ( $user );
2009-03-25 22:26:15 +01:00
}
}
2009-09-12 04:07:25 +02:00
// Save import config to database
2021-02-26 18:20:21 +01:00
if ( $action == 'add_import_model' ) {
if ( $import_name ) {
2009-03-25 22:26:15 +01:00
// Set save string
2019-11-13 19:35:02 +01:00
$hexa = '' ;
2021-02-26 18:20:21 +01:00
foreach ( $array_match_file_to_database as $key => $val ) {
if ( $hexa ) {
$hexa .= ',' ;
}
2019-11-13 19:35:02 +01:00
$hexa .= $key . '=' . $val ;
2009-03-25 22:26:15 +01:00
}
2009-05-19 02:14:27 +02:00
$objimport -> model_name = $import_name ;
$objimport -> datatoimport = $datatoimport ;
$objimport -> hexa = $hexa ;
2021-06-21 15:03:45 +02:00
$objimport -> fk_user = ( GETPOST ( 'visibility' , 'aZ09' ) == 'all' ? 0 : $user -> id );
2009-03-25 22:26:15 +01:00
2009-05-19 02:14:27 +02:00
$result = $objimport -> create ( $user );
2021-02-26 18:20:21 +01:00
if ( $result >= 0 ) {
2015-12-11 09:54:30 +01:00
setEventMessages ( $langs -> trans ( " ImportModelSaved " , $objimport -> model_name ), null , 'mesgs' );
2020-05-21 15:05:19 +02:00
} else {
2009-03-25 22:26:15 +01:00
$langs -> load ( " errors " );
2021-02-26 18:20:21 +01:00
if ( $objimport -> errno == 'DB_ERROR_RECORD_ALREADY_EXISTS' ) {
2015-12-11 09:54:30 +01:00
setEventMessages ( $langs -> trans ( " ErrorImportDuplicateProfil " ), null , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2015-12-11 09:54:30 +01:00
setEventMessages ( $objimport -> error , null , 'errors' );
2009-03-25 22:26:15 +01:00
}
}
2020-05-21 15:05:19 +02:00
} else {
2015-10-17 17:09:34 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " ImportModelName " )), null , 'errors' );
2009-03-25 22:26:15 +01:00
}
}
2021-02-26 18:20:21 +01:00
if ( $step == 3 && $datatoimport ) {
if ( GETPOST ( 'sendit' ) && ! empty ( $conf -> global -> MAIN_UPLOAD_DOC )) {
2011-07-04 13:33:22 +02:00
dol_mkdir ( $conf -> import -> dir_temp );
2019-11-13 19:35:02 +01:00
$nowyearmonth = dol_print_date ( dol_now (), '%Y%m%d%H%M%S' );
2009-09-30 18:02:54 +02:00
2019-11-13 19:35:02 +01:00
$fullpath = $conf -> import -> dir_temp . " / " . $nowyearmonth . '-' . $_FILES [ 'userfile' ][ 'name' ];
2021-02-26 18:20:21 +01:00
if ( dol_move_uploaded_file ( $_FILES [ 'userfile' ][ 'tmp_name' ], $fullpath , 1 ) > 0 ) {
2009-09-30 18:02:54 +02:00
dol_syslog ( " File " . $fullpath . " was added for import " );
2020-05-21 15:05:19 +02:00
} else {
2009-09-30 18:02:54 +02:00
$langs -> load ( " errors " );
2015-12-11 09:54:30 +01:00
setEventMessages ( $langs -> trans ( " ErrorFailedToSaveFile " ), null , 'errors' );
2009-09-30 18:02:54 +02:00
}
}
2012-09-03 17:14:33 +02:00
// Delete file
2021-02-26 18:20:21 +01:00
if ( $action == 'confirm_deletefile' && $confirm == 'yes' ) {
2012-09-03 17:14:33 +02:00
$langs -> load ( " other " );
2020-09-30 18:44:26 +02:00
$param = '&datatoimport=' . urlencode ( $datatoimport ) . '&format=' . urlencode ( $format );
2021-02-26 18:20:21 +01:00
if ( $excludefirstline ) {
$param .= '&excludefirstline=' . urlencode ( $excludefirstline );
}
if ( $endatlinenb ) {
$param .= '&endatlinenb=' . urlencode ( $endatlinenb );
}
2017-11-06 12:59:58 +01:00
2019-11-13 19:35:02 +01:00
$file = $conf -> import -> dir_temp . '/' . GETPOST ( 'urlfile' ); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
$ret = dol_delete_file ( $file );
2021-02-26 18:20:21 +01:00
if ( $ret ) {
setEventMessages ( $langs -> trans ( " FileWasRemoved " , GETPOST ( 'urlfile' )), null , 'mesgs' );
} else {
setEventMessages ( $langs -> trans ( " ErrorFailToDeleteFile " , GETPOST ( 'urlfile' )), null , 'errors' );
}
2012-09-03 17:14:33 +02:00
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?step=' . $step . $param );
exit ;
}
2009-09-30 18:02:54 +02:00
}
2021-02-26 18:20:21 +01:00
if ( $step == 4 && $action == 'select_model' ) {
2009-09-12 04:07:25 +02:00
// Reinit match arrays
2019-11-13 19:35:02 +01:00
$_SESSION [ " dol_array_match_file_to_database " ] = '' ;
$serialized_array_match_file_to_database = '' ;
$array_match_file_to_database = array ();
2009-09-12 04:07:25 +02:00
2009-08-30 23:56:03 +02:00
// Load model from $importmodelid and set $array_match_file_to_database
// and $_SESSION["dol_array_match_file_to_database"]
2009-05-19 02:14:27 +02:00
$result = $objimport -> fetch ( $importmodelid );
2021-02-26 18:20:21 +01:00
if ( $result > 0 ) {
2019-11-13 19:35:02 +01:00
$serialized_array_match_file_to_database = $objimport -> hexa ;
$fieldsarray = explode ( ',' , $serialized_array_match_file_to_database );
2021-02-26 18:20:21 +01:00
foreach ( $fieldsarray as $elem ) {
2019-11-13 19:35:02 +01:00
$tabelem = explode ( '=' , $elem );
$key = $tabelem [ 0 ];
$val = $tabelem [ 1 ];
2021-02-26 18:20:21 +01:00
if ( $key && $val ) {
2019-11-13 19:35:02 +01:00
$array_match_file_to_database [ $key ] = $val ;
2009-09-12 04:07:25 +02:00
}
2009-03-25 22:26:15 +01:00
}
2019-11-13 19:35:02 +01:00
$_SESSION [ " dol_array_match_file_to_database " ] = $serialized_array_match_file_to_database ;
2009-05-19 02:14:27 +02:00
}
2009-03-25 22:26:15 +01:00
}
2021-02-26 18:20:21 +01:00
if ( $action == 'saveorder' ) {
2009-10-01 23:31:55 +02:00
// Enregistrement de la position des champs
2021-03-31 12:41:44 +02:00
dol_syslog ( " boxorder= " . GETPOST ( 'boxorder' ) . " datatoimport= " . GETPOST ( " datatoimport " ), LOG_DEBUG );
$part = explode ( ':' , GETPOST ( 'boxorder' ));
2019-11-13 19:35:02 +01:00
$colonne = $part [ 0 ];
$list = $part [ 1 ];
2009-10-01 23:31:55 +02:00
dol_syslog ( 'column=' . $colonne . ' list=' . $list );
// Init targets fields array
2019-11-13 19:35:02 +01:00
$fieldstarget = $objimport -> array_import_fields [ 0 ];
2009-10-01 23:31:55 +02:00
// Reinit match arrays. We redefine array_match_file_to_database
2019-11-13 19:35:02 +01:00
$serialized_array_match_file_to_database = '' ;
$array_match_file_to_database = array ();
$fieldsarray = explode ( ',' , $list );
$pos = 0 ;
2021-02-26 18:20:21 +01:00
foreach ( $fieldsarray as $fieldnb ) { // For each elem in list. fieldnb start from 1 to ...
2009-10-01 23:31:55 +02:00
// Get name of database fields at position $pos and put it into $namefield
2022-04-13 16:21:25 +02:00
$posbis = 0 ; $namefield = '' ;
2021-02-26 18:20:21 +01:00
foreach ( $fieldstarget as $key => $val ) { // key: val:
2009-10-01 23:31:55 +02:00
//dol_syslog('AjaxImport key='.$key.' val='.$val);
2021-02-26 18:20:21 +01:00
if ( $posbis < $pos ) {
2009-10-01 23:31:55 +02:00
$posbis ++ ;
continue ;
}
// We found the key of targets that is at position pos
2019-11-13 19:35:02 +01:00
$namefield = $key ;
2009-10-01 23:31:55 +02:00
//dol_syslog('AjaxImport Field name found for file field nb '.$fieldnb.'='.$namefield);
break ;
}
2021-02-26 18:20:21 +01:00
if ( $fieldnb && $namefield ) {
2019-11-13 19:35:02 +01:00
$array_match_file_to_database [ $fieldnb ] = $namefield ;
2021-02-26 18:20:21 +01:00
if ( $serialized_array_match_file_to_database ) {
$serialized_array_match_file_to_database .= ',' ;
}
2019-11-13 19:35:02 +01:00
$serialized_array_match_file_to_database .= ( $fieldnb . '=' . $namefield );
2009-10-01 23:31:55 +02:00
}
$pos ++ ;
}
// We save new matching in session
2019-11-13 19:35:02 +01:00
$_SESSION [ " dol_array_match_file_to_database " ] = $serialized_array_match_file_to_database ;
2009-10-01 23:31:55 +02:00
dol_syslog ( 'dol_array_match_file_to_database=' . $serialized_array_match_file_to_database );
}
2009-03-25 22:26:15 +01:00
/*
2009-10-01 23:31:55 +02:00
* View
2009-03-25 22:26:15 +01:00
*/
2021-03-16 14:00:25 +01:00
$help_url = 'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones' ;
2009-10-04 00:32:10 +02:00
// STEP 1: Page to select dataset to import
2021-02-26 18:20:21 +01:00
if ( $step == 1 || ! $datatoimport ) {
2009-09-12 04:07:25 +02:00
// Clean saved file-database matching
2019-11-13 19:35:02 +01:00
$serialized_array_match_file_to_database = '' ;
$array_match_file_to_database = array ();
$_SESSION [ " dol_array_match_file_to_database " ] = '' ;
2009-09-12 04:07:25 +02:00
2019-11-13 19:35:02 +01:00
$param = '' ;
2021-02-26 18:20:21 +01:00
if ( $excludefirstline ) {
$param .= '&excludefirstline=' . urlencode ( $excludefirstline );
}
if ( $endatlinenb ) {
$param .= '&endatlinenb=' . urlencode ( $endatlinenb );
}
if ( $separator ) {
$param .= '&separator=' . urlencode ( $separator );
}
if ( $enclosure ) {
$param .= '&enclosure=' . urlencode ( $enclosure );
}
2009-10-17 15:12:55 +02:00
2021-03-16 14:00:25 +01:00
llxHeader ( '' , $langs -> trans ( " NewImport " ), $help_url );
2009-05-19 02:14:27 +02:00
2020-10-31 14:32:18 +01:00
$head = import_prepare_head ( $param , 1 );
2009-05-19 02:14:27 +02:00
2020-12-16 16:06:33 +01:00
print dol_get_fiche_head ( $head , 'step1' , '' , - 1 );
2009-05-19 02:14:27 +02:00
2018-01-03 14:46:18 +01:00
print '<div class="opacitymedium">' . $langs -> trans ( " SelectImportDataSet " ) . '</div><br>' ;
2009-05-19 02:14:27 +02:00
// Affiche les modules d'imports
2019-11-13 19:35:02 +01:00
print '<div class="div-table-responsive-no-min">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2009-05-19 02:14:27 +02:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Module " ) . '</td>' ;
print '<td>' . $langs -> trans ( " ImportableDatas " ) . '</td>' ;
print '<td> </td>' ;
print '</tr>' ;
2019-06-21 14:27:38 +02:00
2021-02-26 18:20:21 +01:00
if ( count ( $objimport -> array_import_module )) {
2020-09-10 15:43:50 +02:00
$sortedarrayofmodules = dol_sort_array ( $objimport -> array_import_module , 'position_of_profile' , 'asc' , 0 , 0 , 1 );
2021-02-26 18:20:21 +01:00
foreach ( $sortedarrayofmodules as $key => $value ) {
2020-09-10 15:43:50 +02:00
//var_dump($key.' '.$value['position_of_profile'].' '.$value['import_code'].' '.$objimport->array_import_module[$key]['module']->getName().' '.$objimport->array_import_code[$key]);
2019-06-21 14:27:38 +02:00
print '<tr class="oddeven"><td>' ;
2020-09-10 15:43:50 +02:00
$titleofmodule = $objimport -> array_import_module [ $key ][ 'module' ] -> getName ();
2014-05-11 17:52:16 +02:00
// Special cas for import common to module/services
2021-02-26 18:20:21 +01:00
if ( in_array ( $objimport -> array_import_code [ $key ], array ( 'produit_supplierprices' , 'produit_multiprice' , 'produit_languages' ))) {
$titleofmodule = $langs -> trans ( " ProductOrService " );
}
2014-05-11 17:52:16 +02:00
print $titleofmodule ;
2009-05-19 02:14:27 +02:00
print '</td><td>' ;
2020-12-03 19:45:36 +01:00
$entity = preg_replace ( '/:.*$/' , '' , $objimport -> array_import_icon [ $key ]);
$entityicon = strtolower ( ! empty ( $entitytoicon [ $entity ]) ? $entitytoicon [ $entity ] : $entity );
2020-12-13 16:27:44 +01:00
print img_object ( $objimport -> array_import_module [ $key ][ 'module' ] -> getName (), $entityicon ) . ' ' ;
2009-05-19 02:14:27 +02:00
print $objimport -> array_import_label [ $key ];
2020-10-31 14:32:18 +01:00
print '</td><td style="text-align: right">' ;
2021-02-26 18:20:21 +01:00
if ( $objimport -> array_import_perms [ $key ]) {
2020-10-08 11:52:58 +02:00
print '<a href="' . DOL_URL_ROOT . '/imports/import.php?step=2&datatoimport=' . $objimport -> array_import_code [ $key ] . $param . '">' . img_picto ( $langs -> trans ( " NewImport " ), 'next' , 'class="fa-15x"' ) . '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2009-05-19 02:14:27 +02:00
print $langs -> trans ( " NotEnoughPermissions " );
}
print '</td></tr>' ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-06-21 14:27:38 +02:00
print '<tr><td class="oddeven" colspan="3">' . $langs -> trans ( " NoImportableData " ) . '</td></tr>' ;
2009-05-19 02:14:27 +02:00
}
print '</table>' ;
2020-10-31 14:32:18 +01:00
print '</div>' ;
2009-05-19 02:14:27 +02:00
2020-10-31 14:32:18 +01:00
print dol_get_fiche_end ();
2009-03-25 22:26:15 +01:00
}
2009-10-04 00:32:10 +02:00
// STEP 2: Page to select input format file
2021-02-26 18:20:21 +01:00
if ( $step == 2 && $datatoimport ) {
2020-09-30 18:44:26 +02:00
$param = '&datatoimport=' . urlencode ( $datatoimport );
2021-02-26 18:20:21 +01:00
if ( $excludefirstline ) {
$param .= '&excludefirstline=' . urlencode ( $excludefirstline );
}
if ( $endatlinenb ) {
$param .= '&endatlinenb=' . urlencode ( $endatlinenb );
}
if ( $separator ) {
$param .= '&separator=' . urlencode ( $separator );
}
if ( $enclosure ) {
$param .= '&enclosure=' . urlencode ( $enclosure );
}
2009-10-17 15:12:55 +02:00
2021-03-16 14:00:25 +01:00
llxHeader ( '' , $langs -> trans ( " NewImport " ), $help_url );
2009-03-25 22:26:15 +01:00
2020-10-31 14:32:18 +01:00
$head = import_prepare_head ( $param , 2 );
2009-05-19 02:14:27 +02:00
2020-12-16 16:06:33 +01:00
print dol_get_fiche_head ( $head , 'step2' , '' , - 2 );
2009-05-19 02:14:27 +02:00
2017-04-17 04:22:53 +02:00
print '<div class="underbanner clearboth"></div>' ;
print '<div class="fichecenter">' ;
2009-05-19 02:14:27 +02:00
2021-06-22 15:25:49 +02:00
print '<table class="border tableforfield centpercent">' ;
2009-05-19 02:14:27 +02:00
// Module
2021-10-28 11:33:22 +02:00
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " Module " ) . '</td>' ;
2009-05-19 02:14:27 +02:00
print '<td>' ;
2020-09-10 15:43:50 +02:00
$titleofmodule = $objimport -> array_import_module [ 0 ][ 'module' ] -> getName ();
2014-05-11 17:52:16 +02:00
// Special cas for import common to module/services
2021-02-26 18:20:21 +01:00
if ( in_array ( $objimport -> array_import_code [ 0 ], array ( 'produit_supplierprices' , 'produit_multiprice' , 'produit_languages' ))) {
$titleofmodule = $langs -> trans ( " ProductOrService " );
}
2014-05-11 17:52:16 +02:00
print $titleofmodule ;
2009-05-19 02:14:27 +02:00
print '</td></tr>' ;
2021-06-22 15:25:49 +02:00
// Dataset to import
2016-11-19 02:16:12 +01:00
print '<tr><td>' . $langs -> trans ( " DatasetToImport " ) . '</td>' ;
2009-05-19 02:14:27 +02:00
print '<td>' ;
2020-12-03 19:45:36 +01:00
$entity = preg_replace ( '/:.*$/' , '' , $objimport -> array_import_icon [ 0 ]);
$entityicon = strtolower ( ! empty ( $entitytoicon [ $entity ]) ? $entitytoicon [ $entity ] : $entity );
2020-12-13 16:27:44 +01:00
print img_object ( $objimport -> array_import_module [ 0 ][ 'module' ] -> getName (), $entityicon ) . ' ' ;
2009-05-19 02:14:27 +02:00
print $objimport -> array_import_label [ 0 ];
print '</td></tr>' ;
print '</table>' ;
2019-03-03 13:38:45 +01:00
print '</div>' ;
2017-11-06 12:59:58 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2017-11-06 12:59:58 +01:00
2009-05-19 20:11:47 +02:00
print '<form name="userfile" action="' . $_SERVER [ " PHP_SELF " ] . '" enctype="multipart/form-data" METHOD="POST">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2009-03-25 22:26:15 +01:00
print '<input type="hidden" name="max_file_size" value="' . $conf -> maxfilesize . '">' ;
2009-05-19 02:14:27 +02:00
2021-04-08 17:49:13 +02:00
print '<br>' ;
2020-12-04 20:02:04 +01:00
print '<span class="opacitymedium">' ;
$s = $langs -> trans ( " ChooseFormatOfFileToImport " , '{s1}' );
$s = str_replace ( '{s1}' , img_picto ( '' , 'next' ), $s );
print $s ;
print '</span><br><br>' ;
2019-03-04 10:42:09 +01:00
2021-04-08 17:49:13 +02:00
print '<br>' ;
2019-11-13 19:35:02 +01:00
print '<div class="div-table-responsive-no-min">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
2021-04-30 15:22:17 +02:00
print '<table class="noborder centpercent" cellpadding="4">' ;
2009-05-19 02:14:27 +02:00
2019-11-13 19:35:02 +01:00
$filetoimport = '' ;
2009-05-19 02:14:27 +02:00
2009-09-03 01:46:55 +02:00
// Add format informations and link to download example
2009-05-20 13:09:56 +02:00
print '<tr class="liste_titre"><td colspan="6">' ;
2009-05-19 02:14:27 +02:00
print $langs -> trans ( " FileMustHaveOneOfFollowingFormat " );
print '</td></tr>' ;
2021-02-09 14:22:47 +01:00
$list = $objmodelimport -> liste_modeles ( $db );
2021-02-26 18:20:21 +01:00
foreach ( $list as $key ) {
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2019-01-27 11:55:16 +01:00
print '<td width="16">' . img_picto_common ( $key , $objmodelimport -> getPictoForKey ( $key )) . '</td>' ;
2020-10-31 14:32:18 +01:00
$text = $objmodelimport -> getDriverDescForKey ( $key );
print '<td>' . $form -> textwithpicto ( $objmodelimport -> getDriverLabelForKey ( $key ), $text ) . '</td>' ;
2021-04-08 17:49:13 +02:00
print '<td style="text-align:center">' ;
2021-11-22 02:35:55 +01:00
print img_picto ( '' , 'download' , 'class="paddingright opacitymedium"' ) . '<a href="' . DOL_URL_ROOT . '/imports/emptyexample.php?format=' . $key . $param . '" target="_blank" rel="noopener noreferrer">' . $langs -> trans ( " DownloadEmptyExample " );
2021-06-22 15:25:49 +02:00
print '</a>' ;
print ' <span class="opacitymedium hideonsmartphone">(' . $langs -> trans ( " StarAreMandatory " ) . ')</span>' ;
2021-04-08 17:49:13 +02:00
print '</td>' ;
2009-09-15 00:36:36 +02:00
// Action button
2018-12-20 16:49:17 +01:00
print '<td style="text-align:right">' ;
2020-10-08 11:59:33 +02:00
print '<a href="' . DOL_URL_ROOT . '/imports/import.php?step=3&format=' . $key . $param . '">' . img_picto ( $langs -> trans ( " SelectFormat " ), 'next' , 'class="fa-15x"' ) . '</a>' ;
2009-09-15 00:36:36 +02:00
print '</td>' ;
2009-05-19 02:14:27 +02:00
print '</tr>' ;
}
2019-03-04 10:42:09 +01:00
print '</table>' ;
print '</div>' ;
print '</form>' ;
2009-09-15 00:36:36 +02:00
}
2009-10-04 00:32:10 +02:00
// STEP 3: Page to select file
2021-02-26 18:20:21 +01:00
if ( $step == 3 && $datatoimport ) {
2020-09-30 18:44:26 +02:00
$param = '&datatoimport=' . urlencode ( $datatoimport ) . '&format=' . urlencode ( $format );
2021-02-26 18:20:21 +01:00
if ( $excludefirstline ) {
$param .= '&excludefirstline=' . urlencode ( $excludefirstline );
}
if ( $endatlinenb ) {
$param .= '&endatlinenb=' . urlencode ( $endatlinenb );
}
if ( $separator ) {
$param .= '&separator=' . urlencode ( $separator );
}
if ( $enclosure ) {
$param .= '&enclosure=' . urlencode ( $enclosure );
}
2009-10-17 15:12:55 +02:00
2021-02-09 14:24:53 +01:00
$list = $objmodelimport -> liste_modeles ( $db );
2009-10-03 01:07:31 +02:00
2021-03-16 14:00:25 +01:00
llxHeader ( '' , $langs -> trans ( " NewImport " ), $help_url );
2009-09-15 00:36:36 +02:00
2020-10-31 14:32:18 +01:00
$head = import_prepare_head ( $param , 3 );
2009-09-15 00:36:36 +02:00
2020-12-16 16:06:33 +01:00
print dol_get_fiche_head ( $head , 'step3' , '' , - 2 );
2009-09-15 00:36:36 +02:00
2012-09-02 22:48:52 +02:00
/*
* Confirm delete file
*/
2021-02-26 18:20:21 +01:00
if ( $action == 'delete' ) {
2016-03-25 15:53:44 +01:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?urlfile=' . urlencode ( GETPOST ( 'urlfile' )) . '&step=3' . $param , $langs -> trans ( 'DeleteFile' ), $langs -> trans ( 'ConfirmDeleteFile' ), 'confirm_deletefile' , '' , 0 , 1 );
2012-09-02 22:48:52 +02:00
}
2009-09-15 00:36:36 +02:00
2017-04-17 04:22:53 +02:00
print '<div class="underbanner clearboth"></div>' ;
print '<div class="fichecenter">' ;
2017-11-06 12:59:58 +01:00
2021-10-28 11:33:22 +02:00
print '<table class="border tableforfield centpercent">' ;
2009-09-15 00:36:36 +02:00
// Module
2021-10-28 11:33:22 +02:00
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " Module " ) . '</td>' ;
2009-09-15 00:36:36 +02:00
print '<td>' ;
2020-09-10 15:43:50 +02:00
$titleofmodule = $objimport -> array_import_module [ 0 ][ 'module' ] -> getName ();
2014-05-11 17:52:16 +02:00
// Special cas for import common to module/services
2021-02-26 18:20:21 +01:00
if ( in_array ( $objimport -> array_import_code [ 0 ], array ( 'produit_supplierprices' , 'produit_multiprice' , 'produit_languages' ))) {
$titleofmodule = $langs -> trans ( " ProductOrService " );
}
2014-05-11 17:52:16 +02:00
print $titleofmodule ;
2009-09-15 00:36:36 +02:00
print '</td></tr>' ;
// Lot de donnees a importer
2016-11-19 02:16:12 +01:00
print '<tr><td>' . $langs -> trans ( " DatasetToImport " ) . '</td>' ;
2009-09-15 00:36:36 +02:00
print '<td>' ;
2020-12-03 19:45:36 +01:00
$entity = preg_replace ( '/:.*$/' , '' , $objimport -> array_import_icon [ 0 ]);
$entityicon = strtolower ( ! empty ( $entitytoicon [ $entity ]) ? $entitytoicon [ $entity ] : $entity );
2020-12-13 16:27:44 +01:00
print img_object ( $objimport -> array_import_module [ 0 ][ 'module' ] -> getName (), $entityicon ) . ' ' ;
2009-09-15 00:36:36 +02:00
print $objimport -> array_import_label [ 0 ];
print '</td></tr>' ;
2017-03-30 15:39:50 +02:00
print '</table>' ;
2017-04-17 04:22:53 +02:00
print '</div>' ;
2017-11-06 12:59:58 +01:00
2021-04-08 17:49:13 +02:00
print load_fiche_titre ( $langs -> trans ( " InformationOnSourceFile " ), '' , 'file-export' );
2017-11-06 12:59:58 +01:00
2017-04-17 04:22:53 +02:00
print '<div class="underbanner clearboth"></div>' ;
print '<div class="fichecenter">' ;
2019-03-03 12:41:08 +01:00
print '<table width="100%" class="border tableforfield">' ;
2009-10-02 00:17:18 +02:00
2009-09-15 00:36:36 +02:00
// Source file format
2021-10-28 11:33:22 +02:00
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " SourceFileFormat " ) . '</td>' ;
2021-06-22 15:45:47 +02:00
print '<td class="nowraponall">' ;
2020-10-31 14:32:18 +01:00
$text = $objmodelimport -> getDriverDescForKey ( $format );
print $form -> textwithpicto ( $objmodelimport -> getDriverLabelForKey ( $format ), $text );
2021-04-08 17:49:13 +02:00
print '</td><td style="text-align:right" class="nowrap">' ;
2021-11-22 02:35:55 +01:00
print img_picto ( '' , 'download' , 'class="paddingright opacitymedium"' ) . '<a href="' . DOL_URL_ROOT . '/imports/emptyexample.php?format=' . $format . $param . '" target="_blank" rel="noopener noreferrer">' . $langs -> trans ( " DownloadEmptyExample " );
2021-06-22 15:45:47 +02:00
print '</a>' ;
print ' <span class="opacitymedium hideonsmartphone">(' . $langs -> trans ( " StarAreMandatory " ) . ')</span>' ;
2009-09-15 00:36:36 +02:00
print '</td></tr>' ;
print '</table>' ;
2017-04-17 04:22:53 +02:00
print '</div>' ;
2017-11-06 12:59:58 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2009-09-15 00:36:36 +02:00
2020-03-12 18:55:08 +01:00
2020-04-10 10:59:32 +02:00
if ( $format == 'xlsx' && ! class_exists ( 'XMLWriter' )) {
2020-03-12 18:55:08 +01:00
$langs -> load ( " install " );
print info_admin ( $langs -> trans ( " ErrorPHPDoesNotSupport " , 'php-xml' ), 0 , 0 , 1 , 'error' );
}
2020-10-31 14:32:18 +01:00
print '<br>' ;
2017-11-06 12:59:58 +01:00
2009-09-15 00:36:36 +02:00
print '<form name="userfile" action="' . $_SERVER [ " PHP_SELF " ] . '" enctype="multipart/form-data" METHOD="POST">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2009-09-15 00:36:36 +02:00
print '<input type="hidden" name="max_file_size" value="' . $conf -> maxfilesize . '">' ;
2017-11-06 12:59:58 +01:00
2016-12-07 12:41:48 +01:00
print '<input type="hidden" value="' . $step . '" name="step">' ;
2020-12-04 20:02:04 +01:00
print '<input type="hidden" value="' . dol_escape_htmltag ( $format ) . '" name="format">' ;
2016-12-07 12:41:48 +01:00
print '<input type="hidden" value="' . $excludefirstline . '" name="excludefirstline">' ;
print '<input type="hidden" value="' . $endatlinenb . '" name="endatlinenb">' ;
2018-09-04 10:53:42 +02:00
print '<input type="hidden" value="' . dol_escape_htmltag ( $separator ) . '" name="separator">' ;
print '<input type="hidden" value="' . dol_escape_htmltag ( $enclosure ) . '" name="enclosure">' ;
2020-12-04 20:02:04 +01:00
print '<input type="hidden" value="' . dol_escape_htmltag ( $datatoimport ) . '" name="datatoimport">' ;
2017-11-06 12:59:58 +01:00
2020-12-04 20:02:04 +01:00
print '<span class="opacitymedium">' ;
$s = $langs -> trans ( " ChooseFileToImport " , '{s1}' );
$s = str_replace ( '{s1}' , img_picto ( '' , 'next' ), $s );
print $s ;
print '</span><br><br>' ;
2018-06-23 14:23:07 +02:00
2019-11-13 19:35:02 +01:00
$filetoimport = '' ;
2009-05-19 20:11:47 +02:00
2009-05-19 02:14:27 +02:00
// Input file name box
2021-06-22 15:45:47 +02:00
print '<div class="marginbottomonly">' ;
2019-07-20 13:09:25 +02:00
print '<input type="file" name="userfile" size="20" maxlength="80"> ' ;
2019-11-13 19:35:02 +01:00
$out = ( empty ( $conf -> global -> MAIN_UPLOAD_DOC ) ? ' disabled' : '' );
2021-06-22 15:45:47 +02:00
print '<input type="submit" class="button small" value="' . $langs -> trans ( " AddFile " ) . '"' . $out . ' name="sendit">' ;
2019-11-13 19:35:02 +01:00
$out = '' ;
2021-02-26 18:20:21 +01:00
if ( ! empty ( $conf -> global -> MAIN_UPLOAD_DOC )) {
2019-11-13 19:35:02 +01:00
$max = $conf -> global -> MAIN_UPLOAD_DOC ; // In Kb
$maxphp = @ ini_get ( 'upload_max_filesize' ); // In unknown
2021-02-26 18:20:21 +01:00
if ( preg_match ( '/k$/i' , $maxphp )) {
$maxphp = $maxphp * 1 ;
}
if ( preg_match ( '/m$/i' , $maxphp )) {
$maxphp = $maxphp * 1024 ;
}
if ( preg_match ( '/g$/i' , $maxphp )) {
$maxphp = $maxphp * 1024 * 1024 ;
}
if ( preg_match ( '/t$/i' , $maxphp )) {
$maxphp = $maxphp * 1024 * 1024 * 1024 ;
}
2019-11-13 19:35:02 +01:00
$maxphp2 = @ ini_get ( 'post_max_size' ); // In unknown
2021-02-26 18:20:21 +01:00
if ( preg_match ( '/k$/i' , $maxphp2 )) {
$maxphp2 = $maxphp2 * 1 ;
}
if ( preg_match ( '/m$/i' , $maxphp2 )) {
$maxphp2 = $maxphp2 * 1024 ;
}
if ( preg_match ( '/g$/i' , $maxphp2 )) {
$maxphp2 = $maxphp2 * 1024 * 1024 ;
}
if ( preg_match ( '/t$/i' , $maxphp2 )) {
$maxphp2 = $maxphp2 * 1024 * 1024 * 1024 ;
}
2019-07-20 13:09:25 +02:00
// Now $max and $maxphp and $maxphp2 are in Kb
$maxmin = $max ;
$maxphptoshow = $maxphptoshowparam = '' ;
2021-02-26 18:20:21 +01:00
if ( $maxphp > 0 ) {
2019-11-13 19:35:02 +01:00
$maxmin = min ( $max , $maxphp );
2019-07-20 13:09:25 +02:00
$maxphptoshow = $maxphp ;
$maxphptoshowparam = 'upload_max_filesize' ;
}
2021-02-26 18:20:21 +01:00
if ( $maxphp2 > 0 ) {
2019-11-13 19:35:02 +01:00
$maxmin = min ( $max , $maxphp2 );
2021-02-26 18:20:21 +01:00
if ( $maxphp2 < $maxphp ) {
2019-07-20 13:09:25 +02:00
$maxphptoshow = $maxphp2 ;
$maxphptoshowparam = 'post_max_size' ;
}
}
2016-12-07 12:41:48 +01:00
2020-10-31 14:32:18 +01:00
$langs -> load ( 'other' );
$out .= ' ' ;
$out .= info_admin ( $langs -> trans ( " ThisLimitIsDefinedInSetup " , $max , $maxphptoshow ), 1 );
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01:00
$out .= ' (' . $langs -> trans ( " UploadDisabled " ) . ')' ;
2016-12-07 12:41:48 +01:00
}
print $out ;
2021-06-22 15:45:47 +02:00
print '</div>' ;
2009-05-19 20:11:47 +02:00
// Search available imports
2019-11-13 19:35:02 +01:00
$filearray = dol_dir_list ( $conf -> import -> dir_temp , 'files' , 0 , '' , '' , 'name' , SORT_DESC );
2021-02-26 18:20:21 +01:00
if ( count ( $filearray ) > 0 ) {
2021-10-26 14:31:55 +02:00
print '<div class="div-table-responsive-no-min">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '<table class="noborder centpercent" width="100%" cellpadding="4">' ;
2019-11-13 19:35:02 +01:00
$dir = $conf -> import -> dir_temp ;
2009-05-19 20:11:47 +02:00
// Search available files to import
2019-11-13 19:35:02 +01:00
$i = 0 ;
2021-02-26 18:20:21 +01:00
foreach ( $filearray as $key => $val ) {
2020-10-31 14:32:18 +01:00
$file = $val [ 'name' ];
2011-12-22 00:24:26 +01:00
2009-10-04 19:18:09 +02:00
// readdir return value in ISO and we want UTF8 in memory
2021-02-26 18:20:21 +01:00
if ( ! utf8_check ( $file )) {
$file = utf8_encode ( $file );
}
2009-10-04 19:18:09 +02:00
2021-02-26 18:20:21 +01:00
if ( preg_match ( '/^\./' , $file )) {
continue ;
}
2009-05-22 01:45:20 +02:00
2019-11-13 19:35:02 +01:00
$modulepart = 'import' ;
$urlsource = $_SERVER [ " PHP_SELF " ] . '?step=' . $step . $param . '&filetoimport=' . urlencode ( $filetoimport );
$relativepath = $file ;
2017-11-06 12:59:58 +01:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2009-10-13 19:23:26 +02:00
print '<td>' ;
2021-10-28 11:33:22 +02:00
print img_mime ( $file , '' , 'pictofixedwidth' );
2021-11-22 02:35:55 +01:00
print '<a data-ajax="false" href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&file=' . urlencode ( $relativepath ) . '&step=3' . $param . '" target="_blank" rel="noopener noreferrer">' ;
2020-10-31 14:32:18 +01:00
print $file ;
print '</a>' ;
2009-10-13 19:23:26 +02:00
print '</td>' ;
2009-05-20 13:09:56 +02:00
// Affiche taille fichier
2018-12-20 16:49:17 +01:00
print '<td style="text-align:right">' . dol_print_size ( dol_filesize ( $dir . '/' . $file )) . '</td>' ;
2009-05-20 13:09:56 +02:00
// Affiche date fichier
2019-01-27 11:55:16 +01:00
print '<td style="text-align:right">' . dol_print_date ( dol_filemtime ( $dir . '/' . $file ), 'dayhour' ) . '</td>' ;
2009-05-20 13:09:56 +02:00
// Del button
2020-10-01 10:50:54 +02:00
print '<td style="text-align:right"><a href="' . $_SERVER [ 'PHP_SELF' ] . '?action=delete&token=' . newToken () . '&step=3' . $param . '&urlfile=' . urlencode ( $relativepath );
2009-05-20 13:09:56 +02:00
print '">' . img_delete () . '</a></td>' ;
// Action button
2018-12-20 16:49:17 +01:00
print '<td style="text-align:right">' ;
2020-10-08 11:59:33 +02:00
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?step=4' . $param . '&filetoimport=' . urlencode ( $relativepath ) . '">' . img_picto ( $langs -> trans ( " NewImport " ), 'next' , 'class="fa-15x"' ) . '</a>' ;
2009-05-20 13:09:56 +02:00
print '</td>' ;
2009-05-19 20:11:47 +02:00
print '</tr>' ;
2009-05-22 01:45:20 +02:00
}
2009-05-19 20:11:47 +02:00
2021-10-26 14:31:55 +02:00
print '</table>' ;
print '</div>' ;
}
2019-03-04 10:42:09 +01:00
print '</form>' ;
2009-05-19 20:11:47 +02:00
}
2009-09-15 00:36:36 +02:00
2009-10-04 00:32:10 +02:00
// STEP 4: Page to make matching between source file and database fields
2021-02-26 18:20:21 +01:00
if ( $step == 4 && $datatoimport ) {
2019-11-13 19:35:02 +01:00
$model = $format ;
2021-02-09 14:24:53 +01:00
$list = $objmodelimport -> liste_modeles ( $db );
2009-10-02 00:17:18 +02:00
// Create classe to use for import
2019-11-13 19:35:02 +01:00
$dir = DOL_DOCUMENT_ROOT . " /core/modules/import/ " ;
2009-10-02 00:17:18 +02:00
$file = " import_ " . $model . " .modules.php " ;
$classname = " Import " . ucfirst ( $model );
2012-08-22 23:11:24 +02:00
require_once $dir . $file ;
2019-01-27 11:55:16 +01:00
$obj = new $classname ( $db , $datatoimport );
2021-02-26 18:20:21 +01:00
if ( $model == 'csv' ) {
2022-02-18 16:53:55 +01:00
$obj -> separator = $separator_used ;
2020-10-31 14:32:18 +01:00
$obj -> enclosure = $enclosure ;
}
if ( $model == 'xlsx' ) {
2021-02-26 18:20:21 +01:00
if ( ! preg_match ( '/\.xlsx$/i' , $filetoimport )) {
2020-10-31 14:32:18 +01:00
$langs -> load ( " errors " );
$param = '&datatoimport=' . $datatoimport . '&format=' . $format ;
setEventMessages ( $langs -> trans ( " ErrorFileMustHaveFormat " , $model ), null , 'errors' );
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . '?step=3' . $param . '&filetoimport=' . urlencode ( $relativepath ));
exit ;
}
2012-09-28 10:23:04 +02:00
}
2017-11-06 12:59:58 +01:00
2016-06-05 02:24:31 +02:00
if ( GETPOST ( 'update' )) {
2019-11-13 19:35:02 +01:00
$array_match_file_to_database = array ();
2016-06-04 01:28:51 +02:00
}
2009-10-02 00:17:18 +02:00
2009-06-07 20:08:41 +02:00
// Load source fields in input file
2019-11-13 19:35:02 +01:00
$fieldssource = array ();
$result = $obj -> import_open_file ( $conf -> import -> dir_temp . '/' . $filetoimport , $langs );
2021-02-26 18:20:21 +01:00
if ( $result >= 0 ) {
2009-10-03 01:07:31 +02:00
// Read first line
2019-11-13 19:35:02 +01:00
$arrayrecord = $obj -> import_read_record ();
2009-10-04 00:32:10 +02:00
// Put into array fieldssource starting with 1.
2019-11-13 19:35:02 +01:00
$i = 1 ;
2021-02-26 18:20:21 +01:00
foreach ( $arrayrecord as $key => $val ) {
2019-11-13 19:35:02 +01:00
$fieldssource [ $i ][ 'example1' ] = dol_trunc ( $val [ 'val' ], 24 );
2009-10-03 01:07:31 +02:00
$i ++ ;
}
$obj -> import_close_file ();
}
2009-06-07 20:08:41 +02:00
// Load targets fields in database
2019-11-13 19:35:02 +01:00
$fieldstarget = $objimport -> array_import_fields [ 0 ];
2009-06-07 20:08:41 +02:00
2019-11-13 19:35:02 +01:00
$maxpos = max ( count ( $fieldssource ), count ( $fieldstarget ));
2009-06-07 20:08:41 +02:00
2009-10-04 20:01:30 +02:00
//var_dump($array_match_file_to_database);
2009-11-09 23:10:39 +01:00
// Is it a first time in page (if yes, we must initialize array_match_file_to_database)
2021-02-26 18:20:21 +01:00
if ( count ( $array_match_file_to_database ) == 0 ) {
2009-09-12 04:07:25 +02:00
// This is first input in screen, we need to define
// $array_match_file_to_database
// $serialized_array_match_file_to_database
// $_SESSION["dol_array_match_file_to_database"]
2019-11-13 19:35:02 +01:00
$pos = 1 ;
$num = count ( $fieldssource );
2021-02-26 18:20:21 +01:00
while ( $pos <= $num ) {
if ( $num >= 1 && $pos <= $num ) {
2019-11-13 19:35:02 +01:00
$posbis = 1 ;
2021-02-26 18:20:21 +01:00
foreach ( $fieldstarget as $key => $val ) {
if ( $posbis < $pos ) {
2009-06-07 20:08:41 +02:00
$posbis ++ ;
continue ;
}
// We found the key of targets that is at position pos
2019-11-13 19:35:02 +01:00
$array_match_file_to_database [ $pos ] = $key ;
2021-02-26 18:20:21 +01:00
if ( $serialized_array_match_file_to_database ) {
$serialized_array_match_file_to_database .= ',' ;
}
2019-11-13 19:35:02 +01:00
$serialized_array_match_file_to_database .= ( $pos . '=' . $key );
2009-06-07 20:08:41 +02:00
break ;
}
}
$pos ++ ;
}
// Save the match array in session. We now will use the array in session.
2019-11-13 19:35:02 +01:00
$_SESSION [ " dol_array_match_file_to_database " ] = $serialized_array_match_file_to_database ;
2009-06-07 20:08:41 +02:00
}
2019-11-13 19:35:02 +01:00
$array_match_database_to_file = array_flip ( $array_match_file_to_database );
2009-11-09 23:10:39 +01:00
2009-09-12 04:07:25 +02:00
//print $serialized_array_match_file_to_database;
//print $_SESSION["dol_array_match_file_to_database"];
//var_dump($array_match_file_to_database);exit;
2009-06-07 20:08:41 +02:00
2009-09-03 01:46:55 +02:00
// Now $array_match_file_to_database contains fieldnb(1,2,3...)=>fielddatabase(key in $array_match_file_to_database)
2020-09-30 18:44:26 +02:00
$param = '&format=' . $format . '&datatoimport=' . urlencode ( $datatoimport ) . '&filetoimport=' . urlencode ( $filetoimport );
2021-02-26 18:20:21 +01:00
if ( $excludefirstline ) {
$param .= '&excludefirstline=' . urlencode ( $excludefirstline );
}
if ( $endatlinenb ) {
$param .= '&endatlinenb=' . urlencode ( $endatlinenb );
}
if ( $separator ) {
$param .= '&separator=' . urlencode ( $separator );
}
if ( $enclosure ) {
$param .= '&enclosure=' . urlencode ( $enclosure );
}
2009-08-30 23:56:03 +02:00
2021-03-16 14:00:25 +01:00
llxHeader ( '' , $langs -> trans ( " NewImport " ), $help_url );
2009-05-19 20:11:47 +02:00
2020-10-31 14:32:18 +01:00
$head = import_prepare_head ( $param , 4 );
2009-09-15 00:36:36 +02:00
2020-12-16 16:06:33 +01:00
print dol_get_fiche_head ( $head , 'step4' , '' , - 2 );
2017-04-17 04:22:53 +02:00
print '<div class="underbanner clearboth"></div>' ;
print '<div class="fichecenter">' ;
2009-05-19 20:11:47 +02:00
2019-03-03 12:41:08 +01:00
print '<table width="100%" class="border tableforfield">' ;
2009-05-19 20:11:47 +02:00
// Module
2021-10-28 11:33:22 +02:00
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " Module " ) . '</td>' ;
2009-05-19 20:11:47 +02:00
print '<td>' ;
2020-09-10 15:43:50 +02:00
$titleofmodule = $objimport -> array_import_module [ 0 ][ 'module' ] -> getName ();
2014-05-11 17:52:16 +02:00
// Special cas for import common to module/services
2021-02-26 18:20:21 +01:00
if ( in_array ( $objimport -> array_import_code [ 0 ], array ( 'produit_supplierprices' , 'produit_multiprice' , 'produit_languages' ))) {
$titleofmodule = $langs -> trans ( " ProductOrService " );
}
2014-05-11 17:52:16 +02:00
print $titleofmodule ;
2009-05-19 20:11:47 +02:00
print '</td></tr>' ;
// Lot de donnees a importer
2016-11-19 02:16:12 +01:00
print '<tr><td>' . $langs -> trans ( " DatasetToImport " ) . '</td>' ;
2009-05-19 20:11:47 +02:00
print '<td>' ;
2020-12-03 19:45:36 +01:00
$entity = preg_replace ( '/:.*$/' , '' , $objimport -> array_import_icon [ 0 ]);
$entityicon = strtolower ( ! empty ( $entitytoicon [ $entity ]) ? $entitytoicon [ $entity ] : $entity );
2020-12-13 16:27:44 +01:00
print img_object ( $objimport -> array_import_module [ 0 ][ 'module' ] -> getName (), $entityicon ) . ' ' ;
2009-05-19 20:11:47 +02:00
print $objimport -> array_import_label [ 0 ];
print '</td></tr>' ;
2017-03-30 15:39:50 +02:00
print '</table>' ;
2017-04-17 04:22:53 +02:00
print '</div>' ;
2017-11-06 12:59:58 +01:00
2021-04-08 17:49:13 +02:00
print load_fiche_titre ( $langs -> trans ( " InformationOnSourceFile " ), '' , 'file-export' );
2019-12-23 12:24:27 +01:00
2017-04-17 04:22:53 +02:00
print '<div class="underbanner clearboth"></div>' ;
print '<div class="fichecenter">' ;
2019-03-03 12:41:08 +01:00
print '<table width="100%" class="border tableforfield">' ;
2009-10-02 00:17:18 +02:00
2009-09-15 00:36:36 +02:00
// Source file format
2021-10-28 11:33:22 +02:00
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " SourceFileFormat " ) . '</td>' ;
2009-09-15 00:36:36 +02:00
print '<td>' ;
2020-10-31 14:32:18 +01:00
$text = $objmodelimport -> getDriverDescForKey ( $format );
print $form -> textwithpicto ( $objmodelimport -> getDriverLabelForKey ( $format ), $text );
2009-09-15 00:36:36 +02:00
print '</td></tr>' ;
2012-09-28 10:23:04 +02:00
// Separator and enclosure
2020-10-31 14:32:18 +01:00
if ( $model == 'csv' ) {
2016-11-19 02:16:12 +01:00
print '<tr><td>' . $langs -> trans ( " CsvOptions " ) . '</td>' ;
2012-09-28 10:23:04 +02:00
print '<td>' ;
print '<form>' ;
2020-05-30 02:40:05 +02:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2012-09-28 10:23:04 +02:00
print '<input type="hidden" value="' . $step . '" name="step">' ;
print '<input type="hidden" value="' . $format . '" name="format">' ;
print '<input type="hidden" value="' . $excludefirstline . '" name="excludefirstline">' ;
2016-02-20 02:21:24 +01:00
print '<input type="hidden" value="' . $endatlinenb . '" name="endatlinenb">' ;
2012-09-28 10:23:04 +02:00
print '<input type="hidden" value="' . $datatoimport . '" name="datatoimport">' ;
print '<input type="hidden" value="' . $filetoimport . '" name="filetoimport">' ;
print $langs -> trans ( " Separator " ) . ' : ' ;
2018-09-04 10:53:42 +02:00
print '<input type="text" size="1" name="separator" value="' . dol_escape_htmltag ( $separator ) . '"/>' ;
2012-09-28 10:23:04 +02:00
print ' ' . $langs -> trans ( " Enclosure " ) . ' : ' ;
2021-10-28 11:33:22 +02:00
print '<input type="text" size="1" name="enclosure" value="' . dol_escape_htmltag ( $enclosure ) . '"/> ' ;
print '<input name="update" type="submit" value="' . $langs -> trans ( 'Update' ) . '" class="button small" />' ;
2012-09-28 10:23:04 +02:00
print '</form>' ;
print '</td></tr>' ;
2020-10-31 14:32:18 +01:00
}
2012-09-28 10:23:04 +02:00
2009-09-15 00:36:36 +02:00
// File to import
2016-11-19 02:16:12 +01:00
print '<tr><td>' . $langs -> trans ( " FileToImport " ) . '</td>' ;
2009-10-13 19:23:26 +02:00
print '<td>' ;
2019-11-13 19:35:02 +01:00
$modulepart = 'import' ;
$relativepath = GETPOST ( 'filetoimport' );
2021-11-22 02:35:55 +01:00
print '<a data-ajax="false" href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&file=' . urlencode ( $relativepath ) . '&step=4' . $param . '" target="_blank" rel="noopener noreferrer">' ;
2021-10-28 11:33:22 +02:00
print img_mime ( $file , '' , 'pictofixedwidth' );
2020-10-31 14:32:18 +01:00
print $filetoimport ;
print '</a>' ;
2009-10-13 19:23:26 +02:00
print '</td></tr>' ;
2009-05-19 20:11:47 +02:00
print '</table>' ;
2017-04-17 04:22:53 +02:00
print '</div>' ;
2017-11-06 12:59:58 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2017-11-06 12:59:58 +01:00
2009-09-12 04:07:25 +02:00
print '<br>' . " \n " ;
2009-05-19 20:11:47 +02:00
2020-10-31 14:32:18 +01:00
// List of source fields
print '<!-- List of source fields -->' . " \n " ;
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="action" value="select_model">' ;
print '<input type="hidden" name="step" value="4">' ;
print '<input type="hidden" name="format" value="' . $format . '">' ;
print '<input type="hidden" name="datatoimport" value="' . $datatoimport . '">' ;
print '<input type="hidden" name="filetoimport" value="' . $filetoimport . '">' ;
print '<input type="hidden" name="excludefirstline" value="' . $excludefirstline . '">' ;
print '<input type="hidden" name="endatlinenb" value="' . $endatlinenb . '">' ;
print '<input type="hidden" name="separator" value="' . dol_escape_htmltag ( $separator ) . '">' ;
print '<input type="hidden" name="enclosure" value="' . dol_escape_htmltag ( $enclosure ) . '">' ;
print '<div class="marginbottomonly">' ;
2020-12-04 20:02:04 +01:00
print '<span class="opacitymedium">' ;
$s = $langs -> trans ( " SelectImportFields " , '{s1}' );
$s = str_replace ( '{s1}' , img_picto ( '' , 'grip_title' , '' , false , 0 , 0 , '' , '' , 0 ), $s );
print $s ;
print '</span> ' ;
2021-06-21 15:03:45 +02:00
$htmlother -> select_import_model ( $importmodelid , 'importmodelid' , $datatoimport , 1 , $user -> id );
2020-10-31 14:32:18 +01:00
print '<input type="submit" class="button" value="' . $langs -> trans ( " Select " ) . '">' ;
print '</div>' ;
print '</form>' ;
2009-05-19 02:14:27 +02:00
2009-08-23 02:15:30 +02:00
// Title of array with fields
2020-10-31 14:32:18 +01:00
print '<div class="div-table-responsive-no-min">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '<table class="noborder centpercent">' ;
2009-05-22 01:45:20 +02:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " FieldsInSourceFile " ) . '</td>' ;
print '<td>' . $langs -> trans ( " FieldsInTargetDatabase " ) . '</td>' ;
print '</tr>' ;
2009-05-19 02:14:27 +02:00
2009-09-14 23:35:42 +02:00
//var_dump($array_match_file_to_database);
2009-06-07 20:08:41 +02:00
print '<tr valign="top"><td width="50%">' ;
2009-05-19 02:14:27 +02:00
2019-11-13 19:35:02 +01:00
$fieldsplaced = array ();
$valforsourcefieldnb = array ();
$listofkeys = array ();
2021-02-26 18:20:21 +01:00
foreach ( $array_match_file_to_database as $key => $val ) {
2019-11-13 19:35:02 +01:00
$listofkeys [ $key ] = 1 ;
2009-09-14 23:27:09 +02:00
}
2009-08-23 02:15:30 +02:00
print " \n <!-- Box left container --> \n " ;
2010-08-25 00:18:50 +02:00
print '<div id="left" class="connectedSortable">' . " \n " ;
2009-08-23 02:15:30 +02:00
// List of source fields
2019-11-13 19:35:02 +01:00
$var = true ;
$lefti = 1 ;
2021-02-26 18:20:21 +01:00
foreach ( $array_match_file_to_database as $key => $val ) {
2019-11-13 19:35:02 +01:00
$var = ! $var ;
2022-04-13 16:21:25 +02:00
show_elem ( $fieldssource , $key , $val , $var ); // key is field number in source file
2009-09-14 23:27:09 +02:00
//print '> '.$lefti.'-'.$key.'-'.$val;
2019-11-13 19:35:02 +01:00
$listofkeys [ $key ] = 1 ;
$fieldsplaced [ $key ] = 1 ;
$valforsourcefieldnb [ $lefti ] = $key ;
2009-09-14 23:27:09 +02:00
$lefti ++ ;
2009-08-23 02:15:30 +02:00
2021-02-26 18:20:21 +01:00
if ( $lefti > count ( $fieldstarget )) {
break ; // Other fields are in the not imported area
}
2009-09-14 23:27:09 +02:00
}
2009-10-01 23:31:55 +02:00
//var_dump($valforsourcefieldnb);
2009-08-23 02:15:30 +02:00
2011-09-17 21:49:50 +02:00
// Complete source fields from count($fieldssource)+1 to count($fieldstarget)
2019-11-13 19:35:02 +01:00
$more = 1 ;
$num = count ( $fieldssource );
2021-02-26 18:20:21 +01:00
while ( $lefti <= $num ) {
2019-11-13 19:35:02 +01:00
$var = ! $var ;
$newkey = getnewkey ( $fieldssource , $listofkeys );
2022-04-13 16:21:25 +02:00
show_elem ( $fieldssource , $newkey , '' , $var ); // key start after field number in source file
2009-09-14 23:27:09 +02:00
//print '> '.$lefti.'-'.$newkey;
2019-11-13 19:35:02 +01:00
$listofkeys [ $key ] = 1 ;
2009-09-14 23:27:09 +02:00
$lefti ++ ;
$more ++ ;
2009-05-22 01:45:20 +02:00
}
2009-06-07 20:08:41 +02:00
2009-08-23 02:15:30 +02:00
print " </div> \n " ;
2014-04-24 01:26:28 +02:00
print " <!-- End box left container --> \n " ;
2009-08-23 02:15:30 +02:00
2009-06-07 20:08:41 +02:00
print '</td><td width="50%">' ;
2009-05-19 02:14:27 +02:00
2018-12-20 16:49:17 +01:00
// List of target fields
2022-04-13 16:21:25 +02:00
$height = '24px' ; //needs px for css height attribute below
2009-05-22 01:45:20 +02:00
$i = 0 ;
2019-11-13 19:35:02 +01:00
$mandatoryfieldshavesource = true ;
2021-12-23 11:25:57 +01:00
2022-04-13 16:21:25 +02:00
print '<table width="100%" class="nobordernopadding">' ;
2021-02-26 18:20:21 +01:00
foreach ( $fieldstarget as $code => $label ) {
2018-12-20 16:49:17 +01:00
print '<tr class="oddeven" style="height:' . $height . '">' ;
2009-05-22 01:45:20 +02:00
$i ++ ;
2019-11-13 19:35:02 +01:00
$entity = ( ! empty ( $objimport -> array_import_entities [ 0 ][ $code ]) ? $objimport -> array_import_entities [ 0 ][ $code ] : $objimport -> array_import_icon [ 0 ]);
2016-12-07 11:50:08 +01:00
2019-11-13 19:35:02 +01:00
$tablealias = preg_replace ( '/(\..*)$/i' , '' , $code );
$tablename = $objimport -> array_import_tables [ 0 ][ $tablealias ];
2016-12-07 11:50:08 +01:00
2022-04-13 16:21:25 +02:00
$entityicon = $entitytoicon [ $entity ] ? $entitytoicon [ $entity ] : $entity ; // $entityicon must string name of picto of the field like 'project', 'company', 'contact', 'modulename', ...
2019-11-13 19:35:02 +01:00
$entitylang = $entitytolang [ $entity ] ? $entitytolang [ $entity ] : $objimport -> array_import_label [ 0 ]; // $entitylang must be a translation key to describe object the field is related to, like 'Company', 'Contact', 'MyModyle', ...
2009-03-25 22:26:15 +01:00
2021-06-22 15:45:47 +02:00
print '<td class="nowraponall" style="font-weight: normal">=>' . img_object ( '' , $entityicon ) . ' ' . $langs -> trans ( $entitylang ) . '</td>' ;
print '<td class="nowraponall" style="font-weight: normal">' ;
2019-11-13 19:35:02 +01:00
$newlabel = preg_replace ( '/\*$/' , '' , $label );
$text = $langs -> trans ( $newlabel );
$more = '' ;
2021-02-26 18:20:21 +01:00
if ( preg_match ( '/\*$/' , $label )) {
2019-11-13 19:35:02 +01:00
$text = '<span class="fieldrequired">' . $text . '</span>' ;
$more = (( ! empty ( $valforsourcefieldnb [ $i ]) && $valforsourcefieldnb [ $i ] <= count ( $fieldssource )) ? '' : img_warning ( $langs -> trans ( " FieldNeedSource " )));
2021-02-26 18:20:21 +01:00
if ( $mandatoryfieldshavesource ) {
$mandatoryfieldshavesource = ( ! empty ( $valforsourcefieldnb [ $i ]) && ( $valforsourcefieldnb [ $i ] <= count ( $fieldssource )));
}
2009-10-01 23:31:55 +02:00
//print 'xx'.($i).'-'.$valforsourcefieldnb[$i].'-'.$mandatoryfieldshavesource;
}
2009-11-09 23:10:39 +01:00
print $text ;
print '</td>' ;
// Info field
2021-06-22 15:45:47 +02:00
print '<td class="nowraponall" style="font-weight:normal; text-align:right">' ;
2022-04-13 16:21:25 +02:00
$filecolumn = $array_match_database_to_file [ $code ];
2010-01-08 18:33:30 +01:00
// Source field info
2019-11-13 19:35:02 +01:00
$htmltext = '<b><u>' . $langs -> trans ( " FieldSource " ) . '</u></b><br>' ;
2021-02-26 18:20:21 +01:00
if ( $filecolumn > count ( $fieldssource )) {
$htmltext .= $langs -> trans ( " DataComeFromNoWhere " ) . '<br>' ;
} else {
if ( empty ( $objimport -> array_import_convertvalue [ 0 ][ $code ])) { // If source file does not need convertion
2019-11-13 19:35:02 +01:00
$filecolumntoshow = $filecolumn ;
$htmltext .= $langs -> trans ( " DataComeFromFileFieldNb " , $filecolumntoshow ) . '<br>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-26 18:20:21 +01:00
if ( $objimport -> array_import_convertvalue [ 0 ][ $code ][ 'rule' ] == 'fetchidfromref' ) {
$htmltext .= $langs -> trans ( " DataComeFromIdFoundFromRef " , $filecolumn , $langs -> transnoentitiesnoconv ( $entitylang )) . '<br>' ;
}
if ( $objimport -> array_import_convertvalue [ 0 ][ $code ][ 'rule' ] == 'fetchidfromcodeid' ) {
$htmltext .= $langs -> trans ( " DataComeFromIdFoundFromCodeId " , $filecolumn , $langs -> transnoentitiesnoconv ( $objimport -> array_import_convertvalue [ 0 ][ $code ][ 'dict' ])) . '<br>' ;
}
2009-11-09 23:10:39 +01:00
}
}
2015-07-04 02:08:06 +02:00
// Source required
2019-11-13 19:35:02 +01:00
$htmltext .= $langs -> trans ( " SourceRequired " ) . ': <b>' . yn ( preg_match ( '/\*$/' , $label )) . '</b><br>' ;
2022-04-13 16:21:25 +02:00
$example = $objimport -> array_import_examplevalues [ 0 ][ $code ];
2015-07-04 02:08:06 +02:00
// Example
2021-02-26 18:20:21 +01:00
if ( empty ( $objimport -> array_import_convertvalue [ 0 ][ $code ])) { // If source file does not need convertion
if ( $example ) {
$htmltext .= $langs -> trans ( " SourceExample " ) . ': <b>' . $example . '</b><br>' ;
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-26 18:20:21 +01:00
if ( $objimport -> array_import_convertvalue [ 0 ][ $code ][ 'rule' ] == 'fetchidfromref' ) {
$htmltext .= $langs -> trans ( " SourceExample " ) . ': <b>' . $langs -> transnoentitiesnoconv ( " ExampleAnyRefFoundIntoElement " , $entitylang ) . ( $example ? ' (' . $langs -> transnoentitiesnoconv ( " Example " ) . ': ' . $example . ')' : '' ) . '</b><br>' ;
} elseif ( $objimport -> array_import_convertvalue [ 0 ][ $code ][ 'rule' ] == 'fetchidfromcodeid' ) {
$htmltext .= $langs -> trans ( " SourceExample " ) . ': <b>' . $langs -> trans ( " ExampleAnyCodeOrIdFoundIntoDictionary " , $langs -> transnoentitiesnoconv ( $objimport -> array_import_convertvalue [ 0 ][ $code ][ 'dict' ])) . ( $example ? ' (' . $langs -> transnoentitiesnoconv ( " Example " ) . ': ' . $example . ')' : '' ) . '</b><br>' ;
} elseif ( $example ) {
$htmltext .= $langs -> trans ( " SourceExample " ) . ': <b>' . $example . '</b><br>' ;
}
2012-01-18 00:16:02 +01:00
}
2015-07-04 02:08:06 +02:00
// Format control rule
2021-02-26 18:20:21 +01:00
if ( ! empty ( $objimport -> array_import_regex [ 0 ][ $code ])) {
2019-11-13 19:35:02 +01:00
$htmltext .= $langs -> trans ( " FormatControlRule " ) . ': <b>' . $objimport -> array_import_regex [ 0 ][ $code ] . '</b><br>' ;
2015-07-04 02:08:06 +02:00
}
2019-11-13 19:35:02 +01:00
$htmltext .= '<br>' ;
2010-01-08 18:33:30 +01:00
// Target field info
2019-11-13 19:35:02 +01:00
$htmltext .= '<b><u>' . $langs -> trans ( " FieldTarget " ) . '</u></b><br>' ;
2021-02-26 18:20:21 +01:00
if ( empty ( $objimport -> array_import_convertvalue [ 0 ][ $code ])) { // If source file does not need convertion
2019-11-13 19:35:02 +01:00
$htmltext .= $langs -> trans ( " DataIsInsertedInto " ) . '<br>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-26 18:20:21 +01:00
if ( $objimport -> array_import_convertvalue [ 0 ][ $code ][ 'rule' ] == 'fetchidfromref' ) {
$htmltext .= $langs -> trans ( " DataIDSourceIsInsertedInto " ) . '<br>' ;
}
if ( $objimport -> array_import_convertvalue [ 0 ][ $code ][ 'rule' ] == 'fetchidfromcodeid' ) {
$htmltext .= $langs -> trans ( " DataCodeIDSourceIsInsertedInto " ) . '<br>' ;
}
2009-11-09 23:10:39 +01:00
}
2019-11-13 19:35:02 +01:00
$htmltext .= $langs -> trans ( " FieldTitle " ) . " : <b> " . $langs -> trans ( $newlabel ) . " </b><br> " ;
$htmltext .= $langs -> trans ( " Table " ) . " -> " . $langs -> trans ( " Field " ) . ': <b>' . $tablename . " -> " . preg_replace ( '/^.*\./' , '' , $code ) . " </b><br> " ;
2019-01-27 11:55:16 +01:00
print $form -> textwithpicto ( $more , $htmltext );
2009-09-28 22:06:15 +02:00
print '</td>' ;
2009-03-25 22:26:15 +01:00
2009-05-19 02:14:27 +02:00
print '</tr>' ;
}
print '</table>' ;
2009-03-25 22:26:15 +01:00
2009-05-22 01:45:20 +02:00
print '</td></tr>' ;
2009-09-03 01:46:55 +02:00
// List of not imported fields
2009-08-23 02:15:30 +02:00
print '<tr class="liste_titre"><td colspan="2">' . $langs -> trans ( " NotImportedFields " ) . '</td></tr>' ;
2009-09-03 01:46:55 +02:00
print '<tr valign="top"><td width="50%">' ;
2009-08-23 02:15:30 +02:00
2009-10-01 23:31:55 +02:00
print " \n <!-- Box ignore container --> \n " ;
2010-08-25 00:18:50 +02:00
print '<div id="right" class="connectedSortable">' . " \n " ;
2009-08-23 02:15:30 +02:00
2019-11-13 19:35:02 +01:00
$nbofnotimportedfields = 0 ;
2021-02-26 18:20:21 +01:00
foreach ( $fieldssource as $key => $val ) {
if ( empty ( $fieldsplaced [ $key ])) {
2017-04-14 11:22:48 +02:00
//
2009-09-14 23:27:09 +02:00
$nbofnotimportedfields ++ ;
2022-04-13 16:21:25 +02:00
show_elem ( $fieldssource , $key , '' , $var , 'nostyle' );
2009-09-14 23:27:09 +02:00
//print '> '.$lefti.'-'.$key;
2019-11-13 19:35:02 +01:00
$listofkeys [ $key ] = 1 ;
2009-09-14 23:27:09 +02:00
$lefti ++ ;
}
}
// Print one more empty field
2019-11-13 19:35:02 +01:00
$newkey = getnewkey ( $fieldssource , $listofkeys );
2022-04-13 16:21:25 +02:00
show_elem ( $fieldssource , $newkey , '' , $var , 'nostyle' );
2009-09-14 23:27:09 +02:00
//print '> '.$lefti.'-'.$newkey;
2019-11-13 19:35:02 +01:00
$listofkeys [ $newkey ] = 1 ;
2009-09-14 23:27:09 +02:00
$nbofnotimportedfields ++ ;
2009-08-23 02:15:30 +02:00
print " </div> \n " ;
2009-10-01 23:31:55 +02:00
print " <!-- End box ignore container --> \n " ;
2009-08-23 02:15:30 +02:00
2009-09-03 01:46:55 +02:00
print '</td>' ;
print '<td width="50%">' ;
2019-11-13 19:35:02 +01:00
$i = 0 ;
2021-02-26 18:20:21 +01:00
while ( $i < $nbofnotimportedfields ) {
2009-09-14 23:27:09 +02:00
// Print empty cells
2022-04-13 16:21:25 +02:00
show_elem ( '' , '' , 'none' , $var , 'nostyle' );
2009-09-14 23:27:09 +02:00
$i ++ ;
}
2009-08-23 02:15:30 +02:00
print '</td></tr>' ;
2009-05-22 01:45:20 +02:00
print '</table>' ;
2020-10-31 14:32:18 +01:00
print '</div>' ;
2009-03-25 22:26:15 +01:00
2021-02-26 18:20:21 +01:00
if ( $conf -> use_javascript_ajax ) {
2021-11-29 15:09:18 +01:00
print '<script type="text/javascript">' ;
2022-04-13 16:21:25 +02:00
print ' jQuery ( function () {
jQuery ( " #left, #right " ) . sortable ({
/* placeholder: \'ui-state-highlight\', */
handle : \ ' . boxhandle\ ' ,
revert : \ ' invalid\ ' ,
items : \ ' . box\ ' ,
containment : \ ' . fiche\ ' ,
connectWith : \ ' . connectedSortable\ ' ,
stop : function ( event , ui ) {
updateOrder ();
}
});
});
' ;
2020-10-31 14:32:18 +01:00
print " \n " ;
2022-04-13 16:21:25 +02:00
print 'function updateOrder(){' . " \n " ;
print 'var left_list = cleanSerialize(jQuery("#left").sortable("serialize" ));' . " \n " ;
//print 'var right_list = cleanSerialize(jQuery("#right").sortable("serialize" ));'."\n";
print 'var boxorder = \'A:\' + left_list;' . " \n " ;
//print 'var boxorder = \'A:\' + left_list + \'-B:\' + right_list;'."\n";
//print 'alert(\'boxorder=\' + boxorder);';
//print 'var userid = \''.$user->id.'\';'."\n";
//print 'var datatoimport = "'.$datatoimport.'";'."\n";
// print 'jQuery.ajax({ url: "ajaximport.php?step=4&boxorder=" + boxorder + "&userid=" + userid + "&datatoimport=" + datatoimport,
// async: false
// });'."\n";
// Now reload page
2021-10-02 12:58:15 +02:00
print 'var newlocation= \'' . $_SERVER [ " PHP_SELF " ] . '?step=4' . $param . '&action=saveorder&token=' . newToken () . '&boxorder=\' + boxorder;' . " \n " ;
2022-04-13 16:21:25 +02:00
//print 'alert(newlocation);';
2020-10-31 14:32:18 +01:00
print 'window.location.href=newlocation;' . " \n " ;
print '}' . " \n " ;
print '</script>' . " \n " ;
2009-08-23 02:15:30 +02:00
}
2009-05-19 02:14:27 +02:00
/*
2021-03-16 04:22:55 +01:00
* Action bar
2009-05-19 02:14:27 +02:00
*/
print '<div class="tabsAction">' ;
2009-03-25 22:26:15 +01:00
2021-02-26 18:20:21 +01:00
if ( count ( $array_match_file_to_database )) {
if ( $mandatoryfieldshavesource ) {
2009-10-17 15:12:55 +02:00
print '<a class="butAction" href="import.php?step=5' . $param . '&filetoimport=' . urlencode ( $filetoimport ) . '">' . $langs -> trans ( " NextStep " ) . '</a>' ;
2020-05-21 15:05:19 +02:00
} else {
2018-11-13 21:40:17 +01:00
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " SomeMandatoryFieldHaveNoSource " )) . '">' . $langs -> trans ( " NextStep " ) . '</a>' ;
2009-10-01 23:31:55 +02:00
}
2009-05-19 02:14:27 +02:00
}
2009-03-25 22:26:15 +01:00
2009-05-19 02:14:27 +02:00
print '</div>' ;
2009-03-25 22:26:15 +01:00
// Area for profils import
2021-02-26 18:20:21 +01:00
if ( count ( $array_match_file_to_database )) {
2009-09-12 04:07:25 +02:00
print '<br>' . " \n " ;
print '<!-- Area to add new import profile -->' . " \n " ;
2019-03-03 12:41:08 +01:00
print '<div class="marginbottomonly"><span class="opacitymedium">' . $langs -> trans ( " SaveImportModel " ) . '</span></div>' ;
2009-03-25 22:26:15 +01:00
2009-09-12 04:07:25 +02:00
print '<form class="nocellnopadd" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2009-05-19 02:14:27 +02:00
print '<input type="hidden" name="action" value="add_import_model">' ;
print '<input type="hidden" name="step" value="' . $step . '">' ;
2009-10-03 08:36:13 +02:00
print '<input type="hidden" name="format" value="' . $format . '">' ;
2009-05-19 02:14:27 +02:00
print '<input type="hidden" name="datatoimport" value="' . $datatoimport . '">' ;
2020-10-31 14:32:18 +01:00
print '<input type="hidden" name="filetoimport" value="' . $filetoimport . '">' ;
2009-05-19 02:14:27 +02:00
print '<input type="hidden" name="hexa" value="' . $hexa . '">' ;
2020-10-31 14:32:18 +01:00
print '<input type="hidden" name="excludefirstline" value="' . $excludefirstline . '">' ;
print '<input type="hidden" name="endatlinenb" value="' . $endatlinenb . '">' ;
print '<input type="hidden" value="' . dol_escape_htmltag ( $separator ) . '" name="separator">' ;
print '<input type="hidden" value="' . dol_escape_htmltag ( $enclosure ) . '" name="enclosure">' ;
2009-03-25 22:26:15 +01:00
2021-06-22 15:45:47 +02:00
print '<div class="div-table-responsive-no-min">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
2019-11-05 21:24:41 +01:00
print '<table summary="selectofimportprofil" class="noborder centpercent">' ;
2009-03-25 22:26:15 +01:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " ImportModelName " ) . '</td>' ;
2021-06-21 15:03:45 +02:00
print '<td>' . $langs -> trans ( " Visibility " ) . '</td>' ;
print '<td></td>' ;
2009-03-25 22:26:15 +01:00
print '</tr>' ;
2018-06-23 14:23:07 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2021-06-22 15:45:47 +02:00
print '<td><input name="import_name" value=""></td>' ;
2021-06-21 15:03:45 +02:00
print '<td>' ;
$arrayvisibility = array ( 'private' => $langs -> trans ( " Private " ), 'all' => $langs -> trans ( " Everybody " ));
print $form -> selectarray ( 'visibility' , $arrayvisibility , 'private' );
print '</td>' ;
print '<td class="right">' ;
2009-09-28 22:06:15 +02:00
print '<input type="submit" class="button" value="' . $langs -> trans ( " SaveImportProfile " ) . '">' ;
2009-05-19 02:14:27 +02:00
print '</td></tr>' ;
2009-03-25 22:26:15 +01:00
2009-05-19 02:14:27 +02:00
// List of existing import profils
2021-06-21 15:03:45 +02:00
$sql = " SELECT rowid, label, fk_user, entity " ;
2019-11-13 19:35:02 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " import_model " ;
2020-09-20 02:57:15 +02:00
$sql .= " WHERE type = ' " . $db -> escape ( $datatoimport ) . " ' " ;
2021-06-21 15:03:45 +02:00
if ( empty ( $conf -> global -> EXPORTS_SHARE_MODELS )) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
$sql .= " AND fk_user IN (0, " . (( int ) $user -> id ) . " ) " ;
}
2019-11-13 19:35:02 +01:00
$sql .= " ORDER BY rowid " ;
2021-06-21 15:03:45 +02:00
2009-03-25 22:26:15 +01:00
$resql = $db -> query ( $sql );
2021-02-26 18:20:21 +01:00
if ( $resql ) {
2009-03-25 22:26:15 +01:00
$num = $db -> num_rows ( $resql );
2021-06-21 15:03:45 +02:00
$tmpuser = new user ( $db );
2009-03-25 22:26:15 +01:00
$i = 0 ;
2021-02-26 18:20:21 +01:00
while ( $i < $num ) {
2009-03-25 22:26:15 +01:00
$obj = $db -> fetch_object ( $resql );
2021-06-21 15:03:45 +02:00
2017-04-14 13:02:29 +02:00
print '<tr class="oddeven"><td>' ;
2009-03-25 22:26:15 +01:00
print $obj -> label ;
2021-06-21 15:03:45 +02:00
print '</td>' ;
print '<td>' ;
if ( empty ( $obj -> fk_user )) {
print $langs -> trans ( " Everybody " );
} else {
$tmpuser -> fetch ( $obj -> fk_user );
print $tmpuser -> getNomUrl ( 1 );
}
print '</td>' ;
print '<td class="right">' ;
2020-09-30 18:39:23 +02:00
print '<a class="reposition" href="' . $_SERVER [ " PHP_SELF " ] . '?step=' . $step . $param . '&action=deleteprof&token=' . newToken () . '&id=' . $obj -> rowid . '&filetoimport=' . urlencode ( $filetoimport ) . '">' ;
2009-03-25 22:26:15 +01:00
print img_delete ();
print '</a>' ;
print '</tr>' ;
$i ++ ;
}
2020-05-21 15:05:19 +02:00
} else {
2009-05-20 13:33:44 +02:00
dol_print_error ( $db );
2009-03-25 22:26:15 +01:00
}
2009-05-19 02:14:27 +02:00
print '</table>' ;
2021-06-22 15:45:47 +02:00
print '</div>' ;
2009-05-19 02:14:27 +02:00
print '</form>' ;
}
2009-03-25 22:26:15 +01:00
}
2009-10-04 00:32:10 +02:00
2010-10-02 01:37:36 +02:00
// STEP 5: Summary of choices and launch simulation
2021-02-26 18:20:21 +01:00
if ( $step == 5 && $datatoimport ) {
2021-02-05 14:34:04 +01:00
$max_execution_time_for_importexport = ( empty ( $conf -> global -> IMPORT_MAX_EXECUTION_TIME ) ? 300 : $conf -> global -> IMPORT_MAX_EXECUTION_TIME ); // 5mn if not defined
$max_time = @ ini_get ( " max_execution_time " );
2021-02-26 18:20:21 +01:00
if ( $max_time && $max_time < $max_execution_time_for_importexport ) {
2021-02-05 14:34:04 +01:00
dol_syslog ( " max_execution_time= " . $max_time . " is lower than max_execution_time_for_importexport= " . $max_execution_time_for_importexport . " . We try to increase it dynamically. " );
@ ini_set ( " max_execution_time " , $max_execution_time_for_importexport ); // This work only if safe mode is off. also web servers has timeout of 300
}
2019-11-13 19:35:02 +01:00
$model = $format ;
2021-02-09 14:24:53 +01:00
$list = $objmodelimport -> liste_modeles ( $db );
2009-10-02 00:17:18 +02:00
// Create classe to use for import
2019-11-13 19:35:02 +01:00
$dir = DOL_DOCUMENT_ROOT . " /core/modules/import/ " ;
2009-10-02 00:17:18 +02:00
$file = " import_ " . $model . " .modules.php " ;
$classname = " Import " . ucfirst ( $model );
2012-08-22 23:11:24 +02:00
require_once $dir . $file ;
2019-01-27 11:55:16 +01:00
$obj = new $classname ( $db , $datatoimport );
2012-09-28 10:23:04 +02:00
if ( $model == 'csv' ) {
2022-02-18 16:53:55 +01:00
$obj -> separator = $separator_used ;
2020-10-31 14:32:18 +01:00
$obj -> enclosure = $enclosure ;
2012-09-28 10:23:04 +02:00
}
2009-10-02 00:17:18 +02:00
2009-10-01 23:31:55 +02:00
// Load source fields in input file
2019-11-13 19:35:02 +01:00
$fieldssource = array ();
$result = $obj -> import_open_file ( $conf -> import -> dir_temp . '/' . $filetoimport , $langs );
2016-04-11 15:19:58 +02:00
2021-02-26 18:20:21 +01:00
if ( $result >= 0 ) {
2009-10-04 00:32:10 +02:00
// Read first line
2019-11-13 19:35:02 +01:00
$arrayrecord = $obj -> import_read_record ();
2009-10-04 00:32:10 +02:00
// Put into array fieldssource starting with 1.
2019-11-13 19:35:02 +01:00
$i = 1 ;
2021-02-26 18:20:21 +01:00
foreach ( $arrayrecord as $key => $val ) {
2019-11-13 19:35:02 +01:00
$fieldssource [ $i ][ 'example1' ] = dol_trunc ( $val [ 'val' ], 24 );
2009-10-04 00:32:10 +02:00
$i ++ ;
}
$obj -> import_close_file ();
}
2009-05-19 02:14:27 +02:00
2019-11-13 19:35:02 +01:00
$nboflines = $obj -> import_get_nb_of_lines ( $conf -> import -> dir_temp . '/' . $filetoimport );
2009-10-13 23:46:09 +02:00
2020-09-30 18:44:26 +02:00
$param = '&leftmenu=import&format=' . urlencode ( $format ) . '&datatoimport=' . urlencode ( $datatoimport ) . '&filetoimport=' . urlencode ( $filetoimport ) . '&nboflines=' . urlencode ( $nboflines ) . '&separator=' . urlencode ( $separator ) . '&enclosure=' . urlencode ( $enclosure );
2019-11-13 19:35:02 +01:00
$param2 = $param ; // $param2 = $param without excludefirstline and endatlinenb
2021-02-26 18:20:21 +01:00
if ( $excludefirstline ) {
$param .= '&excludefirstline=' . urlencode ( $excludefirstline );
}
if ( $endatlinenb ) {
$param .= '&endatlinenb=' . urlencode ( $endatlinenb );
}
if ( ! empty ( $updatekeys )) {
$param .= '&updatekeys[]=' . implode ( '&updatekeys[]=' , $updatekeys );
}
2017-11-06 12:59:58 +01:00
2019-01-27 11:55:16 +01:00
llxHeader ( '' , $langs -> trans ( " NewImport " ), 'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones' );
2009-05-19 02:14:27 +02:00
2020-10-31 14:32:18 +01:00
$head = import_prepare_head ( $param , 5 );
2009-05-19 02:14:27 +02:00
2017-11-06 12:59:58 +01:00
2020-10-31 14:32:18 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '?' . $param2 . '" method="POST">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="step" value="5">' ; // step 5
print '<input type="hidden" name="action" value="launchsimu">' ; // step 5
2017-11-06 12:59:58 +01:00
2020-12-16 16:06:33 +01:00
print dol_get_fiche_head ( $head , 'step5' , '' , - 2 );
2009-09-15 00:36:36 +02:00
2017-04-17 04:22:53 +02:00
print '<div class="underbanner clearboth"></div>' ;
print '<div class="fichecenter">' ;
2009-05-19 02:14:27 +02:00
2019-03-03 12:41:08 +01:00
print '<table width="100%" class="border tableforfield">' ;
2009-05-19 02:14:27 +02:00
// Module
2021-10-28 11:33:22 +02:00
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " Module " ) . '</td>' ;
2009-05-19 02:14:27 +02:00
print '<td>' ;
2020-09-10 15:43:50 +02:00
$titleofmodule = $objimport -> array_import_module [ 0 ][ 'module' ] -> getName ();
2014-05-11 17:52:16 +02:00
// Special cas for import common to module/services
2021-02-26 18:20:21 +01:00
if ( in_array ( $objimport -> array_import_code [ 0 ], array ( 'produit_supplierprices' , 'produit_multiprice' , 'produit_languages' ))) {
$titleofmodule = $langs -> trans ( " ProductOrService " );
}
2014-05-11 17:52:16 +02:00
print $titleofmodule ;
2009-05-19 02:14:27 +02:00
print '</td></tr>' ;
// Lot de donnees a importer
2009-10-13 19:23:26 +02:00
print '<tr><td>' . $langs -> trans ( " DatasetToImport " ) . '</td>' ;
2009-05-19 02:14:27 +02:00
print '<td>' ;
2020-12-03 19:45:36 +01:00
$entity = preg_replace ( '/:.*$/' , '' , $objimport -> array_import_icon [ 0 ]);
$entityicon = strtolower ( ! empty ( $entitytoicon [ $entity ]) ? $entitytoicon [ $entity ] : $entity );
2020-12-13 16:27:44 +01:00
print img_object ( $objimport -> array_import_module [ 0 ][ 'module' ] -> getName (), $entityicon ) . ' ' ;
2009-05-19 02:14:27 +02:00
print $objimport -> array_import_label [ 0 ];
print '</td></tr>' ;
2017-03-30 15:39:50 +02:00
print '</table>' ;
2017-04-17 04:22:53 +02:00
print '</div>' ;
2017-11-06 12:59:58 +01:00
2021-04-08 17:49:13 +02:00
print load_fiche_titre ( $langs -> trans ( " InformationOnSourceFile " ), '' , 'file-export' );
2019-12-23 12:24:27 +01:00
2017-04-17 04:22:53 +02:00
print '<div class="underbanner clearboth"></div>' ;
print '<div class="fichecenter">' ;
2019-03-03 12:41:08 +01:00
print '<table width="100%" class="border tableforfield">' ;
2009-10-02 00:17:18 +02:00
2009-09-15 00:36:36 +02:00
// Source file format
2021-10-28 11:33:22 +02:00
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " SourceFileFormat " ) . '</td>' ;
2009-09-15 00:36:36 +02:00
print '<td>' ;
2020-10-31 14:32:18 +01:00
$text = $objmodelimport -> getDriverDescForKey ( $format );
print $form -> textwithpicto ( $objmodelimport -> getDriverLabelForKey ( $format ), $text );
2009-09-15 00:36:36 +02:00
print '</td></tr>' ;
2016-02-20 02:21:24 +01:00
// Separator and enclosure
if ( $model == 'csv' ) {
2020-10-31 14:32:18 +01:00
print '<tr><td>' . $langs -> trans ( " CsvOptions " ) . '</td>' ;
print '<td>' ;
print $langs -> trans ( " Separator " ) . ' : ' . dol_escape_htmltag ( $separator );
print ' ' . $langs -> trans ( " Enclosure " ) . ' : ' . dol_escape_htmltag ( $enclosure );
print '</td></tr>' ;
2016-02-20 02:21:24 +01:00
}
2017-11-06 12:59:58 +01:00
2009-09-15 00:36:36 +02:00
// File to import
2009-10-04 00:32:10 +02:00
print '<tr><td>' . $langs -> trans ( " FileToImport " ) . '</td>' ;
2009-10-13 19:23:26 +02:00
print '<td>' ;
2019-11-13 19:35:02 +01:00
$modulepart = 'import' ;
$relativepath = GETPOST ( 'filetoimport' );
2021-11-22 02:35:55 +01:00
print '<a data-ajax="false" href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&file=' . urlencode ( $relativepath ) . '&step=4' . $param . '" target="_blank" rel="noopener noreferrer">' ;
2021-10-28 11:33:22 +02:00
print img_mime ( $file , '' , 'pictofixedwidth' );
2020-10-31 14:32:18 +01:00
print $filetoimport ;
print '</a>' ;
print '</td></tr>' ;
2009-09-15 00:36:36 +02:00
2018-12-20 16:49:17 +01:00
// Total lines in source file
2009-10-04 00:32:10 +02:00
print '<tr><td>' ;
print $langs -> trans ( " NbOfSourceLines " );
print '</td><td>' ;
print $nboflines ;
print '</td></tr>' ;
2018-12-20 16:49:17 +01:00
// Range of lines to import
2009-10-04 00:32:10 +02:00
print '<tr><td>' ;
2017-03-30 15:39:50 +02:00
print $langs -> trans ( " ImportFromToLine " );
2009-10-04 00:32:10 +02:00
print '</td><td>' ;
2021-02-26 18:20:21 +01:00
if ( $action == 'launchsimu' ) {
2021-10-27 09:23:03 +02:00
print '<input type="number" class="maxwidth50 right" name="excludefirstlinebis" disabled="disabled" value="' . $excludefirstline . '">' ;
2020-10-31 14:32:18 +01:00
print '<input type="hidden" name="excludefirstline" value="' . $excludefirstline . '">' ;
2020-05-21 15:05:19 +02:00
} else {
2021-10-27 09:23:03 +02:00
print '<input type="number" class="maxwidth50 right" name="excludefirstline" value="' . $excludefirstline . '">' ;
2020-10-31 14:32:18 +01:00
print $form -> textwithpicto ( " " , $langs -> trans ( " SetThisValueTo2ToExcludeFirstLine " ));
2016-02-20 02:21:24 +01:00
}
2017-03-30 15:39:50 +02:00
print ' - ' ;
2021-02-26 18:20:21 +01:00
if ( $action == 'launchsimu' ) {
2020-10-31 14:32:18 +01:00
print '<input type="text" class="maxwidth50" name="endatlinenbbis" disabled="disabled" value="' . $endatlinenb . '">' ;
print '<input type="hidden" name="endatlinenb" value="' . $endatlinenb . '">' ;
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01:00
print '<input type="text" class="maxwidth50" name="endatlinenb" value="' . $endatlinenb . '">' ;
print $form -> textwithpicto ( " " , $langs -> trans ( " KeepEmptyToGoToEndOfFile " ));
2016-02-20 02:21:24 +01:00
}
2021-02-26 18:20:21 +01:00
if ( $action == 'launchsimu' ) {
print ' <a href="' . $_SERVER [ " PHP_SELF " ] . '?step=5' . $param . '">' . $langs -> trans ( " Modify " ) . '</a>' ;
}
2016-02-20 02:21:24 +01:00
print '</td></tr>' ;
2017-03-30 15:39:50 +02:00
2018-12-20 16:49:17 +01:00
// Keys for data UPDATE (not INSERT of new data)
2016-08-22 12:25:03 +02:00
print '<tr><td>' ;
print $langs -> trans ( " KeysToUseForUpdates " );
print '</td><td>' ;
2019-11-13 19:35:02 +01:00
if ( $action == 'launchsimu' ) {
2021-02-26 18:20:21 +01:00
if ( count ( $updatekeys )) {
2017-11-06 12:59:58 +01:00
print $form -> multiselectarray ( 'updatekeysbis' , $objimport -> array_import_updatekeys [ 0 ], $updatekeys , 0 , 0 , '' , 1 , '80%' , 'disabled' );
2020-05-21 15:05:19 +02:00
} else {
2017-04-17 04:22:53 +02:00
print '<span class="opacitymedium">' . $langs -> trans ( " NoUpdateAttempt " ) . '</span> -' ;
}
2019-11-13 19:35:02 +01:00
foreach ( $updatekeys as $val ) {
2016-08-22 12:25:03 +02:00
print '<input type="hidden" name="updatekeys[]" value="' . $val . '">' ;
}
print ' <a href="' . $_SERVER [ " PHP_SELF " ] . '?step=5' . $param . '">' . $langs -> trans ( " Modify " ) . '</a>' ;
} else {
2021-02-26 18:20:21 +01:00
if ( is_array ( $objimport -> array_import_updatekeys [ 0 ]) && count ( $objimport -> array_import_updatekeys [ 0 ])) { //TODO dropdown UL is created inside nested SPANS
2018-06-23 14:23:07 +02:00
print $form -> multiselectarray ( 'updatekeys' , $objimport -> array_import_updatekeys [ 0 ], $updatekeys , 0 , 0 , '' , 1 , '80%' );
print $form -> textwithpicto ( " " , $langs -> trans ( " SelectPrimaryColumnsForUpdateAttempt " ));
2020-05-21 15:05:19 +02:00
} else {
2018-06-23 14:23:07 +02:00
print '<span class="opacitymedium">' . $langs -> trans ( " UpdateNotYetSupportedForThisImport " ) . '</span>' ;
2017-03-31 14:21:51 +02:00
}
2016-08-22 12:25:03 +02:00
}
/* echo '<pre>' ;
print_r ( $objimport -> array_import_updatekeys );
echo '</pre>' ; */
print '</td></tr>' ;
2017-11-06 12:59:58 +01:00
2009-10-04 00:32:10 +02:00
print '</table>' ;
2017-04-17 04:22:53 +02:00
print '</div>' ;
2017-11-06 12:59:58 +01:00
2009-10-15 17:15:38 +02:00
2021-04-08 17:49:13 +02:00
print load_fiche_titre ( $langs -> trans ( " InformationOnTargetTables " ), '' , 'file-import' );
2019-12-23 12:24:27 +01:00
2017-04-17 04:22:53 +02:00
print '<div class="underbanner clearboth"></div>' ;
print '<div class="fichecenter">' ;
2017-11-06 12:59:58 +01:00
2019-03-03 12:41:08 +01:00
print '<table width="100%" class="border tableforfield">' ;
2009-10-04 00:32:10 +02:00
// Tables imported
2021-10-28 11:33:22 +02:00
print '<tr><td class="titlefieldcreate">' ;
2009-10-04 00:32:10 +02:00
print $langs -> trans ( " TablesTarget " );
print '</td><td>' ;
2019-11-13 19:35:02 +01:00
$listtables = array ();
$sort_array_match_file_to_database = $array_match_file_to_database ;
2021-02-26 18:20:21 +01:00
foreach ( $array_match_file_to_database as $code => $label ) {
2009-10-04 00:32:10 +02:00
//var_dump($fieldssource);
2021-02-26 18:20:21 +01:00
if ( $code > count ( $fieldssource )) {
continue ;
}
2009-10-04 00:32:10 +02:00
//print $code.'-'.$label;
2019-11-13 19:35:02 +01:00
$alias = preg_replace ( '/(\..*)$/i' , '' , $label );
$listtables [ $alias ] = $objimport -> array_import_tables [ 0 ][ $alias ];
2009-10-04 00:32:10 +02:00
}
2021-02-26 18:20:21 +01:00
if ( count ( $listtables )) {
2019-11-13 19:35:02 +01:00
$newval = '' ;
2009-10-13 19:23:26 +02:00
//ksort($listtables);
2021-02-26 18:20:21 +01:00
foreach ( $listtables as $val ) {
if ( $newval ) {
print ', ' ;
}
2019-11-13 19:35:02 +01:00
$newval = $val ;
2009-10-04 00:32:10 +02:00
// Link to Dolibarr wiki pages
/* $helppagename = 'EN:Table_' . $newval ;
if ( $helppagename && empty ( $conf -> global -> MAIN_HELP_DISABLELINK ))
{
// Get helpbaseurl, helppage and mode from helppagename and langs
$arrayres = getHelpParamFor ( $helppagename , $langs );
$helpbaseurl = $arrayres [ 'helpbaseurl' ];
$helppage = $arrayres [ 'helppage' ];
$mode = $arrayres [ 'mode' ];
$newval .= ' <a href="' . sprintf ( $helpbaseurl , $helppage ) . '">' . img_picto ( $langs -> trans ( $mode == 'wiki' ? 'GoToWikiHelpPage' : 'GoToHelpPage' ), DOL_URL_ROOT . '/theme/common/helpdoc.png' , '' , 1 ) . '</a>' ;
} */
print $newval ;
}
2021-02-26 18:20:21 +01:00
} else {
print $langs -> trans ( " Error " );
}
2009-10-04 00:32:10 +02:00
print '</td></tr>' ;
// Fields imported
print '<tr><td>' ;
print $langs -> trans ( " FieldsTarget " ) . '</td><td>' ;
2019-11-13 19:35:02 +01:00
$listfields = array ();
$i = 0 ;
2009-10-04 00:32:10 +02:00
//print 'fieldsource='.$fieldssource;
2019-11-13 19:35:02 +01:00
$sort_array_match_file_to_database = $array_match_file_to_database ;
2009-10-13 19:23:26 +02:00
ksort ( $sort_array_match_file_to_database );
//var_dump($sort_array_match_file_to_database);
2021-02-26 18:20:21 +01:00
foreach ( $sort_array_match_file_to_database as $code => $label ) {
2009-10-04 00:32:10 +02:00
$i ++ ;
//var_dump($fieldssource);
2021-02-26 18:20:21 +01:00
if ( $code > count ( $fieldssource )) {
continue ;
}
2009-10-04 00:32:10 +02:00
//print $code.'-'.$label;
2019-11-13 19:35:02 +01:00
$alias = preg_replace ( '/(\..*)$/i' , '' , $label );
$listfields [ $i ] = $langs -> trans ( " Field " ) . ' ' . $code . '->' . $label ;
2009-10-04 00:32:10 +02:00
}
2019-11-13 19:35:02 +01:00
print count ( $listfields ) ? ( join ( ', ' , $listfields )) : $langs -> trans ( " Error " );
2009-10-04 00:32:10 +02:00
print '</td></tr>' ;
print '</table>' ;
2017-04-17 04:22:53 +02:00
print '</div>' ;
2017-11-06 12:59:58 +01:00
2020-10-31 14:32:18 +01:00
print dol_get_fiche_end ();
2021-02-26 18:20:21 +01:00
if ( $action != 'launchsimu' ) {
2020-10-31 14:32:18 +01:00
// Show import id
print '<br><span class="opacitymedium">' ;
print $langs -> trans ( " NowClickToTestTheImport " , $langs -> transnoentitiesnoconv ( " RunSimulateImportFile " )) . '</span><br>' ;
print '<br>' ;
// Actions
print '<div class="center">' ;
2021-02-26 18:20:21 +01:00
if ( $user -> rights -> import -> run ) {
2020-10-31 14:32:18 +01:00
print '<input type="submit" class="butAction" value="' . $langs -> trans ( " RunSimulateImportFile " ) . '">' ;
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " NotEnoughPermissions " )) . '">' . $langs -> trans ( " RunSimulateImportFile " ) . '</a>' ;
}
print '</div>' ;
} else {
// Launch import
$arrayoferrors = array ();
$arrayofwarnings = array ();
$maxnboferrors = empty ( $conf -> global -> IMPORT_MAX_NB_OF_ERRORS ) ? 50 : $conf -> global -> IMPORT_MAX_NB_OF_ERRORS ;
$maxnbofwarnings = empty ( $conf -> global -> IMPORT_MAX_NB_OF_WARNINGS ) ? 50 : $conf -> global -> IMPORT_MAX_NB_OF_WARNINGS ;
$nboferrors = 0 ;
$nbofwarnings = 0 ;
$importid = dol_print_date ( dol_now (), '%Y%m%d%H%M%S' );
//var_dump($array_match_file_to_database);
$db -> begin ();
// Open input file
$nbok = 0 ;
$pathfile = $conf -> import -> dir_temp . '/' . $filetoimport ;
$result = $obj -> import_open_file ( $pathfile , $langs );
2021-02-26 18:20:21 +01:00
if ( $result > 0 ) {
2020-10-31 14:32:18 +01:00
global $tablewithentity_cache ;
$tablewithentity_cache = array ();
$sourcelinenb = 0 ; $endoffile = 0 ;
// Loop on each input file record
2021-02-26 18:20:21 +01:00
while (( $sourcelinenb < $nboflines ) && ! $endoffile ) {
2020-10-31 14:32:18 +01:00
$sourcelinenb ++ ;
// Read line and store it into $arrayrecord
//dol_syslog("line ".$sourcelinenb.' - '.$nboflines.' - '.$excludefirstline.' - '.$endatlinenb);
$arrayrecord = $obj -> import_read_record ();
2021-02-26 18:20:21 +01:00
if ( $arrayrecord === false ) {
2019-11-13 19:35:02 +01:00
$arrayofwarnings [ $sourcelinenb ][ 0 ] = array ( 'lib' => 'File has ' . $nboflines . ' lines. However we reach end of file after record ' . $sourcelinenb . '. This may occurs when some records are split onto several lines. Ensure the complete string is delimited correctly when there is a separator character in the text string.' , 'type' => 'EOF_RECORD_ON_SEVERAL_LINES' );
2020-10-31 14:32:18 +01:00
$endoffile ++ ;
continue ;
}
2021-02-26 18:20:21 +01:00
if ( $excludefirstline && ( $sourcelinenb < $excludefirstline )) {
continue ;
}
if ( $endatlinenb && ( $sourcelinenb > $endatlinenb )) {
break ;
}
2020-10-31 14:32:18 +01:00
// Run import
$result = $obj -> import_insert ( $arrayrecord , $array_match_file_to_database , $objimport , count ( $fieldssource ), $importid , $updatekeys );
2021-02-26 18:20:21 +01:00
if ( count ( $obj -> errors )) {
$arrayoferrors [ $sourcelinenb ] = $obj -> errors ;
}
if ( count ( $obj -> warnings )) {
$arrayofwarnings [ $sourcelinenb ] = $obj -> warnings ;
}
if ( ! count ( $obj -> errors ) && ! count ( $obj -> warnings )) {
$nbok ++ ;
}
2020-10-31 14:32:18 +01:00
}
// Close file
$obj -> import_close_file ();
} else {
print $langs -> trans ( " ErrorFailedToOpenFile " , $pathfile );
}
$error = 0 ;
// Run the sql after import if defined
//var_dump($objimport->array_import_run_sql_after[0]);
2021-02-26 18:20:21 +01:00
if ( ! empty ( $objimport -> array_import_run_sql_after [ 0 ]) && is_array ( $objimport -> array_import_run_sql_after [ 0 ])) {
2020-10-31 14:32:18 +01:00
$i = 0 ;
2021-02-26 18:20:21 +01:00
foreach ( $objimport -> array_import_run_sql_after [ 0 ] as $sqlafterimport ) {
2020-10-31 14:32:18 +01:00
$i ++ ;
$resqlafterimport = $db -> query ( $sqlafterimport );
2021-02-26 18:20:21 +01:00
if ( ! $resqlafterimport ) {
2020-10-31 14:32:18 +01:00
$arrayoferrors [ 'none' ][] = array ( 'lib' => $langs -> trans ( " Error running final request: " . $sqlafterimport ));
$error ++ ;
}
}
}
$db -> rollback (); // We force rollback because this was just a simulation.
// Show OK
if ( ! count ( $arrayoferrors ) && ! count ( $arrayofwarnings )) {
print '<div class="center">' . img_picto ( $langs -> trans ( " OK " ), 'tick' ) . ' <b>' . $langs -> trans ( " NoError " ) . '</b></div><br><br>' ;
2021-02-05 14:34:04 +01:00
print '<div class="ok">' ;
2021-02-05 14:51:54 +01:00
print $langs -> trans ( " NbInsert " , empty ( $obj -> nbinsert ) ? 0 : $obj -> nbinsert ) . '<br>' ;
2021-10-28 11:33:22 +02:00
print $langs -> trans ( " NbUpdate " , empty ( $obj -> nbupdate ) ? 0 : $obj -> nbupdate ) . '<br>' ;
2021-02-05 14:34:04 +01:00
print '</div>' ;
2021-10-28 11:33:22 +02:00
print '<br>' ;
2021-02-26 18:20:21 +01:00
} else {
2021-10-28 11:33:22 +02:00
print '<br>' ;
print '<div class="info">' ;
print $langs -> trans ( " NbOfLinesOK " , $nbok ) . '<br>' ;
print '</div>' ;
print '<br>' ;
2021-02-26 18:20:21 +01:00
}
2010-10-02 01:37:36 +02:00
2020-10-31 14:32:18 +01:00
// Show Errors
//var_dump($arrayoferrors);
2021-02-26 18:20:21 +01:00
if ( count ( $arrayoferrors )) {
2020-10-31 14:32:18 +01:00
print img_error () . ' <b>' . $langs -> trans ( " ErrorsOnXLines " , count ( $arrayoferrors )) . '</b><br>' ;
print '<table width="100%" class="border"><tr><td>' ;
2021-02-26 18:20:21 +01:00
foreach ( $arrayoferrors as $key => $val ) {
2020-10-31 14:32:18 +01:00
$nboferrors ++ ;
2021-02-26 18:20:21 +01:00
if ( $nboferrors > $maxnboferrors ) {
2020-10-31 14:32:18 +01:00
print $langs -> trans ( " TooMuchErrors " , ( count ( $arrayoferrors ) - $nboferrors )) . " <br> " ;
break ;
}
print '* ' . $langs -> trans ( " Line " ) . ' ' . $key . '<br>' ;
2021-02-26 18:20:21 +01:00
foreach ( $val as $i => $err ) {
2020-10-31 14:32:18 +01:00
print ' > ' . $err [ 'lib' ] . '<br>' ;
}
}
print '</td></tr></table>' ;
print '<br>' ;
}
// Show Warnings
//var_dump($arrayoferrors);
2021-02-26 18:20:21 +01:00
if ( count ( $arrayofwarnings )) {
2020-10-31 14:32:18 +01:00
print img_warning () . ' <b>' . $langs -> trans ( " WarningsOnXLines " , count ( $arrayofwarnings )) . '</b><br>' ;
print '<table width="100%" class="border"><tr><td>' ;
2021-02-26 18:20:21 +01:00
foreach ( $arrayofwarnings as $key => $val ) {
2020-10-31 14:32:18 +01:00
$nbofwarnings ++ ;
2021-02-26 18:20:21 +01:00
if ( $nbofwarnings > $maxnbofwarnings ) {
2020-10-31 14:32:18 +01:00
print $langs -> trans ( " TooMuchWarnings " , ( count ( $arrayofwarnings ) - $nbofwarnings )) . " <br> " ;
break ;
}
print ' * ' . $langs -> trans ( " Line " ) . ' ' . $key . '<br>' ;
2021-02-26 18:20:21 +01:00
foreach ( $val as $i => $err ) {
2020-10-31 14:32:18 +01:00
print ' > ' . $err [ 'lib' ] . '<br>' ;
}
}
print '</td></tr></table>' ;
print '<br>' ;
}
// Show import id
$importid = dol_print_date ( dol_now (), '%Y%m%d%H%M%S' );
print '<div class="center">' ;
print '<span class="opacitymedium">' . $langs -> trans ( " NowClickToRunTheImport " , $langs -> transnoentitiesnoconv ( " RunImportFile " )) . '</span><br>' ;
2021-02-26 18:20:21 +01:00
if ( empty ( $nboferrors )) {
print $langs -> trans ( " DataLoadedWithId " , $importid ) . '<br>' ;
}
2020-10-31 14:32:18 +01:00
print '</div>' ;
print '<br>' ;
// Actions
print '<div class="center">' ;
2021-02-26 18:20:21 +01:00
if ( $user -> rights -> import -> run ) {
if ( empty ( $nboferrors )) {
2020-10-31 14:32:18 +01:00
print '<a class="butAction" href="' . DOL_URL_ROOT . '/imports/import.php?leftmenu=import&step=6&importid=' . $importid . $param . '">' . $langs -> trans ( " RunImportFile " ) . '</a>' ;
} else {
//print '<input type="submit" class="butAction" value="'.dol_escape_htmltag($langs->trans("RunSimulateImportFile")).'">';
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " CorrectErrorBeforeRunningImport " )) . '">' . $langs -> trans ( " RunImportFile " ) . '</a>' ;
}
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " NotEnoughPermissions " )) . '">' . $langs -> trans ( " RunSimulateImportFile " ) . '</a>' ;
print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " NotEnoughPermissions " )) . '">' . $langs -> trans ( " RunImportFile " ) . '</a>' ;
}
print '</div>' ;
}
print '</form>' ;
2009-10-04 00:32:10 +02:00
}
2010-10-02 01:37:36 +02:00
// STEP 6: Real import
2021-02-26 18:20:21 +01:00
if ( $step == 6 && $datatoimport ) {
2021-02-05 14:34:04 +01:00
$max_execution_time_for_importexport = ( empty ( $conf -> global -> IMPORT_MAX_EXECUTION_TIME ) ? 300 : $conf -> global -> IMPORT_MAX_EXECUTION_TIME ); // 5mn if not defined
$max_time = @ ini_get ( " max_execution_time " );
2021-02-26 18:20:21 +01:00
if ( $max_time && $max_time < $max_execution_time_for_importexport ) {
2021-02-05 14:34:04 +01:00
dol_syslog ( " max_execution_time= " . $max_time . " is lower than max_execution_time_for_importexport= " . $max_execution_time_for_importexport . " . We try to increase it dynamically. " );
@ ini_set ( " max_execution_time " , $max_execution_time_for_importexport ); // This work only if safe mode is off. also web servers has timeout of 300
}
2019-11-13 19:35:02 +01:00
$model = $format ;
2021-02-09 14:24:53 +01:00
$list = $objmodelimport -> liste_modeles ( $db );
2021-02-05 14:34:04 +01:00
$importid = GETPOST ( " importid " , 'alphanohtml' );
2009-10-15 17:15:38 +02:00
// Create classe to use for import
2019-11-13 19:35:02 +01:00
$dir = DOL_DOCUMENT_ROOT . " /core/modules/import/ " ;
2009-10-15 17:15:38 +02:00
$file = " import_ " . $model . " .modules.php " ;
$classname = " Import " . ucfirst ( $model );
2012-08-22 23:11:24 +02:00
require_once $dir . $file ;
2019-01-27 11:55:16 +01:00
$obj = new $classname ( $db , $datatoimport );
2012-09-28 10:23:04 +02:00
if ( $model == 'csv' ) {
2022-02-18 16:53:55 +01:00
$obj -> separator = $separator_used ;
2020-10-31 14:32:18 +01:00
$obj -> enclosure = $enclosure ;
2012-09-28 10:23:04 +02:00
}
2009-10-15 17:15:38 +02:00
// Load source fields in input file
2019-11-13 19:35:02 +01:00
$fieldssource = array ();
$result = $obj -> import_open_file ( $conf -> import -> dir_temp . '/' . $filetoimport , $langs );
2021-02-26 18:20:21 +01:00
if ( $result >= 0 ) {
2009-10-15 17:15:38 +02:00
// Read first line
2019-11-13 19:35:02 +01:00
$arrayrecord = $obj -> import_read_record ();
2009-10-15 17:15:38 +02:00
// Put into array fieldssource starting with 1.
2019-11-13 19:35:02 +01:00
$i = 1 ;
2021-02-26 18:20:21 +01:00
foreach ( $arrayrecord as $key => $val ) {
2019-11-13 19:35:02 +01:00
$fieldssource [ $i ][ 'example1' ] = dol_trunc ( $val [ 'val' ], 24 );
2009-10-15 17:15:38 +02:00
$i ++ ;
}
$obj -> import_close_file ();
}
2019-11-13 19:35:02 +01:00
$nboflines = ( ! empty ( $_GET [ " nboflines " ]) ? $_GET [ " nboflines " ] : dol_count_nb_of_line ( $conf -> import -> dir_temp . '/' . $filetoimport ));
2009-10-15 17:15:38 +02:00
2020-09-30 18:44:26 +02:00
$param = '&format=' . $format . '&datatoimport=' . urlencode ( $datatoimport ) . '&filetoimport=' . urlencode ( $filetoimport ) . '&nboflines=' . urlencode ( $nboflines );
2021-02-26 18:20:21 +01:00
if ( $excludefirstline ) {
$param .= '&excludefirstline=' . urlencode ( $excludefirstline );
}
if ( $endatlinenb ) {
$param .= '&endatlinenb=' . urlencode ( $endatlinenb );
}
if ( $separator ) {
$param .= '&separator=' . urlencode ( $separator );
}
if ( $enclosure ) {
$param .= '&enclosure=' . urlencode ( $enclosure );
}
2009-10-15 17:15:38 +02:00
2019-01-27 11:55:16 +01:00
llxHeader ( '' , $langs -> trans ( " NewImport " ), 'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones' );
2009-10-15 17:15:38 +02:00
2020-10-31 14:32:18 +01:00
$head = import_prepare_head ( $param , 6 );
2009-10-15 17:15:38 +02:00
2020-12-16 16:06:33 +01:00
print dol_get_fiche_head ( $head , 'step6' , '' , - 1 );
2009-10-15 17:15:38 +02:00
2017-11-06 12:59:58 +01:00
print '<div class="underbanner clearboth"></div>' ;
print '<div class="fichecenter">' ;
2009-10-15 17:15:38 +02:00
print '<table width="100%" class="border">' ;
// Module
2021-10-28 11:33:22 +02:00
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " Module " ) . '</td>' ;
2009-10-15 17:15:38 +02:00
print '<td>' ;
2020-09-10 15:43:50 +02:00
$titleofmodule = $objimport -> array_import_module [ 0 ][ 'module' ] -> getName ();
2014-05-11 17:52:16 +02:00
// Special cas for import common to module/services
2021-02-26 18:20:21 +01:00
if ( in_array ( $objimport -> array_import_code [ 0 ], array ( 'produit_supplierprices' , 'produit_multiprice' , 'produit_languages' ))) {
$titleofmodule = $langs -> trans ( " ProductOrService " );
}
2014-05-11 17:52:16 +02:00
print $titleofmodule ;
2009-10-15 17:15:38 +02:00
print '</td></tr>' ;
// Lot de donnees a importer
print '<tr><td>' . $langs -> trans ( " DatasetToImport " ) . '</td>' ;
print '<td>' ;
2020-12-03 19:45:36 +01:00
$entity = preg_replace ( '/:.*$/' , '' , $objimport -> array_import_icon [ 0 ]);
$entityicon = strtolower ( ! empty ( $entitytoicon [ $entity ]) ? $entitytoicon [ $entity ] : $entity );
2020-12-13 16:27:44 +01:00
print img_object ( $objimport -> array_import_module [ 0 ][ 'module' ] -> getName (), $entityicon ) . ' ' ;
2009-10-15 17:15:38 +02:00
print $objimport -> array_import_label [ 0 ];
print '</td></tr>' ;
2017-03-30 15:39:50 +02:00
print '</table>' ;
2017-11-06 12:59:58 +01:00
print '</div>' ;
2021-04-08 17:49:13 +02:00
print load_fiche_titre ( $langs -> trans ( " InformationOnSourceFile " ), '' , 'file-export' );
2019-12-23 12:24:27 +01:00
2017-11-06 12:59:58 +01:00
print '<div class="underbanner clearboth"></div>' ;
print '<div class="fichecenter">' ;
2009-10-15 17:15:38 +02:00
print '<table width="100%" class="border">' ;
// Source file format
2021-10-28 11:33:22 +02:00
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " SourceFileFormat " ) . '</td>' ;
2009-10-15 17:15:38 +02:00
print '<td>' ;
2020-10-31 14:32:18 +01:00
$text = $objmodelimport -> getDriverDescForKey ( $format );
print $form -> textwithpicto ( $objmodelimport -> getDriverLabelForKey ( $format ), $text );
2009-10-15 17:15:38 +02:00
print '</td></tr>' ;
2016-11-19 02:16:12 +01:00
// Separator and enclosure
if ( $model == 'csv' ) {
2020-10-31 14:32:18 +01:00
print '<tr><td>' . $langs -> trans ( " CsvOptions " ) . '</td>' ;
print '<td>' ;
print $langs -> trans ( " Separator " ) . ' : ' ;
print htmlentities ( $separator );
print ' ' . $langs -> trans ( " Enclosure " ) . ' : ' ;
print htmlentities ( $enclosure );
print '</td></tr>' ;
2016-11-19 02:16:12 +01:00
}
2017-11-06 12:59:58 +01:00
2009-10-15 17:15:38 +02:00
// File to import
print '<tr><td>' . $langs -> trans ( " FileToImport " ) . '</td>' ;
print '<td>' ;
2019-11-13 19:35:02 +01:00
$modulepart = 'import' ;
2020-10-31 14:32:18 +01:00
$relativepath = GETPOST ( 'filetoimport' );
2021-11-22 02:35:55 +01:00
print '<a data-ajax="false" href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&file=' . urlencode ( $relativepath ) . '&step=4' . $param . '" target="_blank" rel="noopener noreferrer">' ;
2021-10-28 11:33:22 +02:00
print img_mime ( $file , '' , 'pictofixedwidth' );
2020-10-31 14:32:18 +01:00
print $filetoimport ;
print '</a>' ;
2009-10-15 17:15:38 +02:00
print '</td></tr>' ;
// Nb of fields
print '<tr><td>' ;
print $langs -> trans ( " NbOfSourceLines " );
print '</td><td>' ;
print $nboflines ;
print '</td></tr>' ;
2016-02-20 02:21:24 +01:00
// Do not import first lines
2009-10-15 17:15:38 +02:00
print '<tr><td>' ;
2016-02-20 02:21:24 +01:00
print $langs -> trans ( " ImportFromLine " );
2009-10-15 17:15:38 +02:00
print '</td><td>' ;
2016-02-20 02:21:24 +01:00
print '<input type="text" size="4" name="excludefirstline" disabled="disabled" value="' . $excludefirstline . '">' ;
2009-10-15 17:15:38 +02:00
print '</td></tr>' ;
2016-02-20 02:21:24 +01:00
// Do not import end lines
print '<tr><td>' ;
print $langs -> trans ( " EndAtLineNb " );
print '</td><td>' ;
2020-10-31 14:32:18 +01:00
print '<input type="text" size="4" name="endatlinenb" disabled="disabled" value="' . $endatlinenb . '">' ;
2016-02-20 02:21:24 +01:00
print '</td></tr>' ;
2017-11-06 12:59:58 +01:00
2009-10-15 17:15:38 +02:00
print '</table>' ;
2017-11-06 12:59:58 +01:00
print '</div>' ;
2009-10-15 17:15:38 +02:00
print '<br>' ;
2017-11-06 12:59:58 +01:00
print '<b>' . $langs -> trans ( " InformationOnTargetTables " ) . '</b>' ;
print '<div class="underbanner clearboth"></div>' ;
print '<div class="fichecenter">' ;
2021-04-08 17:49:13 +02:00
print '<table class="border centpercent">' ;
2009-10-15 17:15:38 +02:00
// Tables imported
print '<tr><td width="25%">' ;
print $langs -> trans ( " TablesTarget " );
print '</td><td>' ;
2019-11-13 19:35:02 +01:00
$listtables = array ();
2021-02-26 18:20:21 +01:00
foreach ( $array_match_file_to_database as $code => $label ) {
2009-10-15 17:15:38 +02:00
//var_dump($fieldssource);
2021-02-26 18:20:21 +01:00
if ( $code > count ( $fieldssource )) {
continue ;
}
2009-10-15 17:15:38 +02:00
//print $code.'-'.$label;
2019-11-13 19:35:02 +01:00
$alias = preg_replace ( '/(\..*)$/i' , '' , $label );
$listtables [ $alias ] = $objimport -> array_import_tables [ 0 ][ $alias ];
2009-10-15 17:15:38 +02:00
}
2021-02-26 18:20:21 +01:00
if ( count ( $listtables )) {
2019-11-13 19:35:02 +01:00
$newval = '' ;
2021-02-26 18:20:21 +01:00
foreach ( $listtables as $val ) {
if ( $newval ) {
print ', ' ;
}
2019-11-13 19:35:02 +01:00
$newval = $val ;
2009-10-15 17:15:38 +02:00
// Link to Dolibarr wiki pages
/* $helppagename = 'EN:Table_' . $newval ;
if ( $helppagename && empty ( $conf -> global -> MAIN_HELP_DISABLELINK ))
{
// Get helpbaseurl, helppage and mode from helppagename and langs
$arrayres = getHelpParamFor ( $helppagename , $langs );
$helpbaseurl = $arrayres [ 'helpbaseurl' ];
$helppage = $arrayres [ 'helppage' ];
$mode = $arrayres [ 'mode' ];
$newval .= ' <a href="' . sprintf ( $helpbaseurl , $helppage ) . '">' . img_picto ( $langs -> trans ( $mode == 'wiki' ? 'GoToWikiHelpPage' : 'GoToHelpPage' ), DOL_URL_ROOT . '/theme/common/helpdoc.png' , '' , 1 ) . '</a>' ;
} */
print $newval ;
}
2021-02-26 18:20:21 +01:00
} else {
print $langs -> trans ( " Error " );
}
2009-10-15 17:15:38 +02:00
print '</td></tr>' ;
// Fields imported
print '<tr><td>' ;
print $langs -> trans ( " FieldsTarget " ) . '</td><td>' ;
2019-11-13 19:35:02 +01:00
$listfields = array ();
$i = 0 ;
$sort_array_match_file_to_database = $array_match_file_to_database ;
2009-10-15 17:15:38 +02:00
ksort ( $sort_array_match_file_to_database );
//var_dump($sort_array_match_file_to_database);
2021-02-26 18:20:21 +01:00
foreach ( $sort_array_match_file_to_database as $code => $label ) {
2009-10-15 17:15:38 +02:00
$i ++ ;
//var_dump($fieldssource);
2021-02-26 18:20:21 +01:00
if ( $code > count ( $fieldssource )) {
continue ;
}
2009-10-15 17:15:38 +02:00
//print $code.'-'.$label;
2019-11-13 19:35:02 +01:00
$alias = preg_replace ( '/(\..*)$/i' , '' , $label );
$listfields [ $i ] = $langs -> trans ( " Field " ) . ' ' . $code . '->' . $label ;
2009-10-15 17:15:38 +02:00
}
2019-11-13 19:35:02 +01:00
print count ( $listfields ) ? ( join ( ', ' , $listfields )) : $langs -> trans ( " Error " );
2009-10-15 17:15:38 +02:00
print '</td></tr>' ;
print '</table>' ;
2017-11-06 12:59:58 +01:00
print '</div>' ;
2009-10-15 17:15:38 +02:00
// Launch import
2019-11-13 19:35:02 +01:00
$arrayoferrors = array ();
$arrayofwarnings = array ();
$maxnboferrors = empty ( $conf -> global -> IMPORT_MAX_NB_OF_ERRORS ) ? 50 : $conf -> global -> IMPORT_MAX_NB_OF_ERRORS ;
$maxnbofwarnings = empty ( $conf -> global -> IMPORT_MAX_NB_OF_WARNINGS ) ? 50 : $conf -> global -> IMPORT_MAX_NB_OF_WARNINGS ;
$nboferrors = 0 ;
$nbofwarnings = 0 ;
2009-10-15 17:15:38 +02:00
2019-11-13 19:35:02 +01:00
$importid = dol_print_date ( dol_now (), '%Y%m%d%H%M%S' );
2009-10-15 17:15:38 +02:00
//var_dump($array_match_file_to_database);
2009-10-17 15:12:55 +02:00
$db -> begin ();
2009-10-15 17:15:38 +02:00
// Open input file
2019-11-13 19:35:02 +01:00
$nbok = 0 ;
$pathfile = $conf -> import -> dir_temp . '/' . $filetoimport ;
$result = $obj -> import_open_file ( $pathfile , $langs );
2021-02-26 18:20:21 +01:00
if ( $result > 0 ) {
2020-10-31 14:32:18 +01:00
global $tablewithentity_cache ;
$tablewithentity_cache = array ();
2019-11-13 19:35:02 +01:00
$sourcelinenb = 0 ; $endoffile = 0 ;
2014-03-19 20:23:29 +01:00
2021-02-26 18:20:21 +01:00
while ( $sourcelinenb < $nboflines && ! $endoffile ) {
2009-10-15 17:15:38 +02:00
$sourcelinenb ++ ;
2019-11-13 19:35:02 +01:00
$arrayrecord = $obj -> import_read_record ();
2021-02-26 18:20:21 +01:00
if ( $arrayrecord === false ) {
2019-11-13 19:35:02 +01:00
$arrayofwarnings [ $sourcelinenb ][ 0 ] = array ( 'lib' => 'File has ' . $nboflines . ' lines. However we reach end of file after record ' . $sourcelinenb . '. This may occurs when some records are split onto several lines.' , 'type' => 'EOF_RECORD_ON_SEVERAL_LINES' );
2013-04-25 23:49:24 +02:00
$endoffile ++ ;
continue ;
}
2021-02-26 18:20:21 +01:00
if ( $excludefirstline && ( $sourcelinenb < $excludefirstline )) {
continue ;
}
if ( $endatlinenb && ( $sourcelinenb > $endatlinenb )) {
break ;
}
2009-10-15 17:15:38 +02:00
2016-02-20 02:21:24 +01:00
// Run import
2019-11-13 19:35:02 +01:00
$result = $obj -> import_insert ( $arrayrecord , $array_match_file_to_database , $objimport , count ( $fieldssource ), $importid , $updatekeys );
2017-11-06 12:59:58 +01:00
2021-02-26 18:20:21 +01:00
if ( count ( $obj -> errors )) {
$arrayoferrors [ $sourcelinenb ] = $obj -> errors ;
}
if ( count ( $obj -> warnings )) {
$arrayofwarnings [ $sourcelinenb ] = $obj -> warnings ;
}
if ( ! count ( $obj -> errors ) && ! count ( $obj -> warnings )) {
$nbok ++ ;
}
2009-10-15 17:15:38 +02:00
}
// Close file
$obj -> import_close_file ();
2020-05-21 15:05:19 +02:00
} else {
2019-01-27 11:55:16 +01:00
print $langs -> trans ( " ErrorFailedToOpenFile " , $pathfile );
2009-10-15 17:15:38 +02:00
}
2021-02-26 18:20:21 +01:00
if ( count ( $arrayoferrors ) > 0 ) {
$db -> rollback (); // We force rollback because this was errors.
} else {
2020-10-31 14:32:18 +01:00
$error = 0 ;
2017-11-06 12:59:58 +01:00
2016-04-11 18:08:03 +02:00
// Run the sql after import if defined
2020-10-31 14:32:18 +01:00
//var_dump($objimport->array_import_run_sql_after[0]);
2021-02-26 18:20:21 +01:00
if ( ! empty ( $objimport -> array_import_run_sql_after [ 0 ]) && is_array ( $objimport -> array_import_run_sql_after [ 0 ])) {
2020-10-31 14:32:18 +01:00
$i = 0 ;
2021-02-26 18:20:21 +01:00
foreach ( $objimport -> array_import_run_sql_after [ 0 ] as $sqlafterimport ) {
2020-10-31 14:32:18 +01:00
$i ++ ;
$resqlafterimport = $db -> query ( $sqlafterimport );
2021-02-26 18:20:21 +01:00
if ( ! $resqlafterimport ) {
2020-10-31 14:32:18 +01:00
$arrayoferrors [ 'none' ][] = array ( 'lib' => $langs -> trans ( " Error running final request: " . $sqlafterimport ));
$error ++ ;
}
}
}
2021-02-26 18:20:21 +01:00
if ( ! $error ) {
$db -> commit (); // We can commit if no errors.
} else {
$db -> rollback ();
}
2016-04-11 18:08:03 +02:00
}
2017-11-06 12:59:58 +01:00
2020-10-31 14:32:18 +01:00
print dol_get_fiche_end ();
2011-09-20 17:29:31 +02:00
2009-10-15 17:15:38 +02:00
2009-10-17 15:12:55 +02:00
// Show result
2009-10-17 15:48:17 +02:00
print '<br>' ;
2021-02-05 14:34:04 +01:00
print '<div class="ok">' ;
2019-01-27 11:55:16 +01:00
print $langs -> trans ( " NbOfLinesImported " , $nbok ) . '</b><br>' ;
2021-02-05 14:51:54 +01:00
print $langs -> trans ( " NbInsert " , empty ( $obj -> nbinsert ) ? 0 : $obj -> nbinsert ) . '<br>' ;
print $langs -> trans ( " NbUpdate " , empty ( $obj -> nbupdate ) ? 0 : $obj -> nbupdate ) . '<br><br>' ;
2021-02-05 14:34:04 +01:00
print '</div>' ;
print '<div class="center">' ;
2019-01-27 11:55:16 +01:00
print $langs -> trans ( " FileWasImported " , $importid ) . '<br>' ;
2021-02-05 14:34:04 +01:00
print '<span class="opacitymedium">' . $langs -> trans ( " YouCanUseImportIdToFindRecord " , $importid ) . '</span><br>' ;
2014-11-25 20:13:43 +01:00
print '</div>' ;
2009-10-15 17:15:38 +02:00
}
2009-03-25 22:26:15 +01:00
print '<br>' ;
2018-08-13 11:25:48 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-01-18 00:16:02 +01:00
$db -> close ();
2009-08-23 02:15:30 +02:00
2011-09-20 17:29:31 +02:00
/**
2009-08-23 02:24:56 +02:00
* Function to put the movable box of a source field
2011-09-20 17:29:31 +02:00
*
2022-04-13 16:21:25 +02:00
* @ param array $fieldssource List of source fields
* @ param int $pos Pos
* @ param string $key Key
* @ param boolean $var Line style ( odd or not )
* @ param int $nostyle Hide style
2011-09-20 17:29:31 +02:00
* @ return void
2009-08-23 02:24:56 +02:00
*/
2022-04-13 16:21:25 +02:00
function show_elem ( $fieldssource , $pos , $key , $var , $nostyle = '' )
2009-08-23 02:15:30 +02:00
{
2019-11-13 19:35:02 +01:00
global $langs , $bc ;
2009-08-23 02:15:30 +02:00
2022-04-13 16:21:25 +02:00
$height = '24px' ;
2017-11-06 12:59:58 +01:00
2020-10-31 14:32:18 +01:00
if ( $key == 'none' ) {
//stop multiple duplicate ids with no number
print " \n \n <!-- Box_no-key start--> \n " ;
print '<div class="box boximport" style="padding:0;">' . " \n " ;
print '<table summary="boxtable_no-key" width="100%" class="nobordernopadding">' . " \n " ;
} else {
print " \n \n <!-- Box " . $pos . " start --> \n " ;
print '<div class="box boximport" style="padding: 0;" id="boxto_' . $pos . '">' . " \n " ;
2009-08-23 02:15:30 +02:00
2020-10-31 14:32:18 +01:00
print '<table summary="boxtable' . $pos . '" width="100%" class="nobordernopadding">' . " \n " ;
}
2018-12-20 16:49:17 +01:00
2021-02-26 18:20:21 +01:00
if ( $pos && $pos > count ( $fieldssource )) { // No fields
2019-11-13 19:35:02 +01:00
print '<tr' . ( $nostyle ? '' : ' ' . $bc [ $var ]) . ' style="height:' . $height . '">' ;
2009-08-30 23:56:03 +02:00
print '<td class="nocellnopadding" width="16" style="font-weight: normal">' ;
2022-04-13 16:21:25 +02:00
print img_picto (( $pos > 0 ? $langs -> trans ( " MoveField " , $pos ) : '' ), 'grip_title' , 'class="boxhandle" style="cursor:move;"' );
2009-08-30 23:56:03 +02:00
print '</td>' ;
print '<td style="font-weight: normal">' ;
print $langs -> trans ( " NoFields " );
print '</td>' ;
2009-10-03 16:16:52 +02:00
print '</tr>' ;
2021-02-26 18:20:21 +01:00
} elseif ( $key == 'none' ) { // Empty line
2019-11-13 19:35:02 +01:00
print '<tr' . ( $nostyle ? '' : ' ' . $bc [ $var ]) . ' style="height:' . $height . '">' ;
2009-08-30 23:56:03 +02:00
print '<td class="nocellnopadding" width="16" style="font-weight: normal">' ;
2009-09-03 01:46:55 +02:00
print ' ' ;
2009-08-30 23:56:03 +02:00
print '</td>' ;
print '<td style="font-weight: normal">' ;
2009-09-03 01:46:55 +02:00
print ' ' ;
2009-08-30 23:56:03 +02:00
print '</td>' ;
2009-10-03 16:16:52 +02:00
print '</tr>' ;
2021-06-22 15:45:47 +02:00
} else {
// Print field of source file
2019-11-13 19:35:02 +01:00
print '<tr' . ( $nostyle ? '' : ' ' . $bc [ $var ]) . ' style="height:' . $height . '">' ;
2009-08-23 02:34:55 +02:00
print '<td class="nocellnopadding" width="16" style="font-weight: normal">' ;
2009-08-23 02:15:30 +02:00
// The image must have the class 'boxhandle' beause it's value used in DOM draggable objects to define the area used to catch the full object
2022-04-13 16:21:25 +02:00
print img_picto ( $langs -> trans ( " MoveField " , $pos ), 'grip_title' , 'class="boxhandle" style="cursor:move;"' );
2009-08-23 02:15:30 +02:00
print '</td>' ;
2022-04-13 16:21:25 +02:00
print '<td class="nowraponall" style="font-weight: normal">' ;
print $langs -> trans ( " Field " ) . ' ' . $pos ;
$example = $fieldssource [ $pos ][ 'example1' ];
2021-02-26 18:20:21 +01:00
if ( $example ) {
if ( ! utf8_check ( $example )) {
$example = utf8_encode ( $example );
}
2020-10-31 14:32:18 +01:00
print ' (<i>' . $example . '</i>)' ;
2012-03-03 19:09:29 +01:00
}
2009-08-23 02:15:30 +02:00
print '</td>' ;
2009-10-03 16:16:52 +02:00
print '</tr>' ;
2009-08-23 02:15:30 +02:00
}
print " </table> \n " ;
print " </div> \n " ;
print " <!-- Box end --> \n \n " ;
}
2009-09-14 23:27:09 +02:00
/**
* Return not used field number
2011-09-20 17:29:31 +02:00
*
2014-09-27 16:00:11 +02:00
* @ param array $fieldssource Array of field source
* @ param array $listofkey Array of keys
2015-03-17 00:21:17 +01:00
* @ return integer
2009-09-14 23:27:09 +02:00
*/
2019-01-27 15:20:16 +01:00
function getnewkey ( & $fieldssource , & $listofkey )
2009-09-14 23:27:09 +02:00
{
2019-11-13 19:35:02 +01:00
$i = count ( $fieldssource ) + 1 ;
2009-09-14 23:27:09 +02:00
// Max number of key
2019-11-13 19:35:02 +01:00
$maxkey = 0 ;
2021-02-26 18:20:21 +01:00
foreach ( $listofkey as $key => $val ) {
2019-11-13 19:35:02 +01:00
$maxkey = max ( $maxkey , $key );
2009-09-14 23:27:09 +02:00
}
// Found next empty key
2021-02-26 18:20:21 +01:00
while ( $i <= $maxkey ) {
if ( empty ( $listofkey [ $i ])) {
break ;
} else {
$i ++ ;
}
2009-09-14 23:27:09 +02:00
}
2019-11-13 19:35:02 +01:00
$listofkey [ $i ] = 1 ;
2009-09-14 23:27:09 +02:00
return $i ;
}