2009-03-25 22:26:15 +01:00
< ? php
2011-07-30 00:31:37 +02:00
/* Copyright ( C ) 2005 - 2011 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ capnetworks . com >
2012-09-28 10:23:04 +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
2011-08-01 01:45:11 +02:00
* along with this program . If not , see < http :// 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
$langs -> load ( " exports " );
2009-10-15 17:15:38 +02:00
$langs -> load ( " errors " );
2009-03-25 22:26:15 +01:00
2010-01-21 23:19:16 +01:00
// Security check
2012-09-02 22:48:52 +02:00
$result = restrictedArea ( $user , 'import' );
2009-03-25 22:26:15 +01:00
$entitytoicon = array (
'invoice' => 'bill' , 'invoice_line' => 'bill' ,
'order' => 'order' , 'order_line' => 'order' ,
'intervention' => 'intervention' , 'inter_line' => 'intervention' ,
'member' => 'user' , 'member_type' => 'group' , 'subscription' => 'payment' ,
'tax' => 'generic' , 'tax_type' => 'generic' ,
'account' => 'account' ,
'payment' => 'payment' ,
'product' => 'product' , 'stock' => 'generic' , 'warehouse' => 'stock' ,
'category' => 'generic' ,
2009-05-19 02:14:27 +02:00
'other' => 'generic'
);
2009-03-25 22:26:15 +01:00
$entitytolang = array ( // Translation code
'user' => 'User' ,
'company' => 'Company' , 'contact' => 'Contact' ,
'invoice' => 'Bill' , 'invoice_line' => 'InvoiceLine' ,
'order' => 'Order' , 'order_line' => 'OrderLine' ,
'intervention' => 'Intervention' , 'inter_line' => 'InterLine' ,
'member' => 'Member' , 'member_type' => 'MemberType' , 'subscription' => 'Subscription' ,
'tax' => 'SocialContribution' , 'tax_type' => 'DictionnarySocialContributions' ,
'account' => 'BankTransactions' ,
'payment' => 'Payment' ,
'product' => 'Product' , 'stock' => 'Stock' , 'warehouse' => 'Warehouse' ,
'category' => 'Category' ,
'other' => 'Other'
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' );
2012-09-02 22:48:52 +02:00
$action = GETPOST ( 'action' , 'alpha' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
2012-03-03 18:41:06 +01:00
$step = ( GETPOST ( 'step' ) ? GETPOST ( 'step' ) : 1 );
$import_name = GETPOST ( 'import_name' );
$hexa = GETPOST ( 'hexa' );
$importmodelid = GETPOST ( 'importmodelid' );
$excludefirstline = ( GETPOST ( 'excludefirstline' ) ? GETPOST ( 'excludefirstline' ) : 0 );
2012-09-28 10:23:04 +02:00
$separator = ( GETPOST ( 'separator' ) ? GETPOST ( 'separator' ) : ( ! empty ( $conf -> global -> IMPORT_CSV_SEPARATOR_TO_USE ) ? $conf -> global -> IMPORT_CSV_SEPARATOR_TO_USE : ',' ));
$enclosure = ( GETPOST ( 'enclosure' ) ? GETPOST ( 'enclosure' ) : '"' );
2009-03-25 22:26:15 +01:00
$objimport = new Import ( $db );
2009-11-08 20:28:44 +01:00
$objimport -> load_arrays ( $user ,( $step == 1 ? '' : $datatoimport ));
2009-03-25 22:26:15 +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
$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 ();
2009-10-19 22:17:19 +02:00
$fieldsarray = explode ( ',' , $serialized_array_match_file_to_database );
2009-09-12 04:07:25 +02:00
foreach ( $fieldsarray as $elem )
{
2009-10-19 22:17:19 +02:00
$tabelem = explode ( '=' , $elem , 2 );
2009-09-12 04:07:25 +02:00
$key = $tabelem [ 0 ];
2012-09-02 22:48:52 +02:00
$val = ( isset ( $tabelem [ 1 ]) ? $tabelem [ 1 ] : '' );
2009-09-12 04:07:25 +02:00
if ( $key && $val )
{
$array_match_file_to_database [ $key ] = $val ;
}
}
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
*/
2009-03-25 22:26:15 +01:00
if ( $action == 'builddoc' )
{
2009-05-19 02:14:27 +02:00
// Build import file
2013-09-06 13:25:45 +02:00
$result = $objimport -> build_file ( $user , GETPOST ( 'model' , 'alpha' ), $datatoimport , $array_match_file_to_database );
2009-03-25 22:26:15 +01:00
if ( $result < 0 )
{
2009-05-19 02:14:27 +02:00
$mesg = '<div class="error">' . $objimport -> error . '</div>' ;
2009-03-25 22:26:15 +01:00
}
else
{
2009-05-19 02:14:27 +02:00
$mesg = '<div class="ok">' . $langs -> trans ( " FileSuccessfullyBuilt " ) . '</div>' ;
}
2009-03-25 22:26:15 +01:00
}
if ( $action == 'deleteprof' )
{
if ( $_GET [ " id " ])
{
$objimport -> fetch ( $_GET [ " id " ]);
$result = $objimport -> delete ( $user );
}
}
2009-09-12 04:07:25 +02:00
// Save import config to database
2009-03-25 22:26:15 +01:00
if ( $action == 'add_import_model' )
{
if ( $import_name )
{
// Set save string
$hexa = '' ;
2009-06-07 20:08:41 +02:00
foreach ( $array_match_file_to_database as $key => $val )
2009-03-25 22:26:15 +01:00
{
if ( $hexa ) $hexa .= ',' ;
2009-09-12 04:07:25 +02: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 ;
2009-03-25 22:26:15 +01:00
2009-05-19 02:14:27 +02:00
$result = $objimport -> create ( $user );
2009-03-25 22:26:15 +01:00
if ( $result >= 0 )
{
2009-05-19 02:14:27 +02:00
$mesg = '<div class="ok">' . $langs -> trans ( " ImportModelSaved " , $objimport -> model_name ) . '</div>' ;
2009-03-25 22:26:15 +01:00
}
else
{
$langs -> load ( " errors " );
if ( $objimport -> errno == 'DB_ERROR_RECORD_ALREADY_EXISTS' )
{
$mesg = '<div class="error">' . $langs -> trans ( " ErrorImportDuplicateProfil " ) . '</div>' ;
}
else $mesg = '<div class="error">' . $objimport -> error . '</div>' ;
}
}
else
{
2009-05-19 02:14:27 +02:00
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " ImportModelName " )) . '</div>' ;
2009-03-25 22:26:15 +01:00
}
}
2009-09-30 18:02:54 +02:00
if ( $step == 3 && $datatoimport )
{
2012-09-02 22:48:52 +02:00
if ( GETPOST ( 'sendit' ) && ! empty ( $conf -> global -> MAIN_UPLOAD_DOC ))
2009-09-30 18:02:54 +02:00
{
2011-07-04 13:33:22 +02:00
dol_mkdir ( $conf -> import -> dir_temp );
$nowyearmonth = dol_print_date ( dol_now (), '%Y%m%d%H%M%S' );
2009-09-30 18:02:54 +02:00
$fullpath = $conf -> import -> dir_temp . " / " . $nowyearmonth . '-' . $_FILES [ 'userfile' ][ 'name' ];
if ( dol_move_uploaded_file ( $_FILES [ 'userfile' ][ 'tmp_name' ], $fullpath , 1 ) > 0 )
{
dol_syslog ( " File " . $fullpath . " was added for import " );
}
else
{
$langs -> load ( " errors " );
2012-09-03 17:14:33 +02:00
setEventMessage ( $langs -> trans ( " ErrorFailedToSaveFile " ), 'errors' );
2009-09-30 18:02:54 +02:00
}
}
2012-09-03 17:14:33 +02:00
// Delete file
if ( $action == 'confirm_deletefile' && $confirm == 'yes' )
{
$langs -> load ( " other " );
$param = '&datatoimport=' . $datatoimport . '&format=' . $format ;
if ( $excludefirstline ) $param .= '&excludefirstline=1' ;
$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 );
if ( $ret ) setEventMessage ( $langs -> trans ( " FileWasRemoved " , GETPOST ( 'urlfile' )));
else setEventMessage ( $langs -> trans ( " ErrorFailToDeleteFile " , GETPOST ( 'urlfile' )), 'errors' );
Header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?step=' . $step . $param );
exit ;
}
2009-09-30 18:02:54 +02:00
}
2009-09-15 00:36:36 +02:00
if ( $step == 4 && $action == 'select_model' )
2009-03-25 22:26:15 +01:00
{
2009-09-12 04:07:25 +02:00
// Reinit match arrays
$_SESSION [ " dol_array_match_file_to_database " ] = '' ;
$serialized_array_match_file_to_database = '' ;
$array_match_file_to_database = array ();
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 );
if ( $result > 0 )
{
2009-09-12 04:07:25 +02:00
$serialized_array_match_file_to_database = $objimport -> hexa ;
2009-10-19 22:17:19 +02:00
$fieldsarray = explode ( ',' , $serialized_array_match_file_to_database );
2009-09-12 04:07:25 +02:00
foreach ( $fieldsarray as $elem )
2009-03-25 22:26:15 +01:00
{
2009-10-19 22:17:19 +02:00
$tabelem = explode ( '=' , $elem );
2009-09-12 04:07:25 +02:00
$key = $tabelem [ 0 ];
$val = $tabelem [ 1 ];
if ( $key && $val )
{
$array_match_file_to_database [ $key ] = $val ;
}
2009-03-25 22:26:15 +01:00
}
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-10-01 23:31:55 +02:00
if ( $action == 'saveorder' )
{
// Enregistrement de la position des champs
dol_syslog ( " boxorder= " . $_GET [ 'boxorder' ] . " datatoimport= " . $_GET [ " datatoimport " ], LOG_DEBUG );
2009-10-19 22:17:19 +02:00
$part = explode ( ':' , $_GET [ 'boxorder' ]);
2009-10-01 23:31:55 +02:00
$colonne = $part [ 0 ];
$list = $part [ 1 ];
dol_syslog ( 'column=' . $colonne . ' list=' . $list );
// Init targets fields array
$fieldstarget = $objimport -> array_import_fields [ 0 ];
// Reinit match arrays. We redefine array_match_file_to_database
$serialized_array_match_file_to_database = '' ;
$array_match_file_to_database = array ();
2009-10-19 22:17:19 +02:00
$fieldsarray = explode ( ',' , $list );
2009-10-01 23:31:55 +02:00
$pos = 0 ;
foreach ( $fieldsarray as $fieldnb ) // For each elem in list. fieldnb start from 1 to ...
{
// Get name of database fields at position $pos and put it into $namefield
$posbis = 0 ; $namefield = '' ;
foreach ( $fieldstarget as $key => $val ) // key: val:
{
//dol_syslog('AjaxImport key='.$key.' val='.$val);
if ( $posbis < $pos )
{
$posbis ++ ;
continue ;
}
// We found the key of targets that is at position pos
$namefield = $key ;
//dol_syslog('AjaxImport Field name found for file field nb '.$fieldnb.'='.$namefield);
break ;
}
if ( $fieldnb && $namefield )
{
$array_match_file_to_database [ $fieldnb ] = $namefield ;
if ( $serialized_array_match_file_to_database ) $serialized_array_match_file_to_database .= ',' ;
$serialized_array_match_file_to_database .= ( $fieldnb . '=' . $namefield );
}
$pos ++ ;
}
// We save new matching in session
$_SESSION [ " dol_array_match_file_to_database " ] = $serialized_array_match_file_to_database ;
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
*/
2009-10-04 00:32:10 +02:00
// STEP 1: Page to select dataset to import
2009-03-25 22:26:15 +01:00
if ( $step == 1 || ! $datatoimport )
{
2009-09-12 04:07:25 +02:00
// Clean saved file-database matching
$serialized_array_match_file_to_database = '' ;
$array_match_file_to_database = array ();
$_SESSION [ " dol_array_match_file_to_database " ] = '' ;
2012-09-03 17:14:33 +02:00
$param = '' ;
2009-10-17 15:12:55 +02:00
if ( $excludefirstline ) $param .= '&excludefirstline=1' ;
2012-09-28 10:23:04 +02:00
if ( $separator ) $param .= '&separator=' . urlencode ( $separator );
if ( $enclosure ) $param .= '&enclosure=' . urlencode ( $enclosure );
2009-10-17 15:12:55 +02:00
2009-08-12 14:59:14 +02:00
llxHeader ( '' , $langs -> trans ( " NewImport " ), 'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones' );
2009-05-19 02:14:27 +02:00
2011-09-20 17:29:31 +02:00
$head = import_prepare_head ( $param , 1 );
2009-05-19 02:14:27 +02:00
2011-09-20 17:29:31 +02:00
dol_fiche_head ( $head , 'step1' , $langs -> trans ( " NewImport " ));
2009-05-19 02:14:27 +02:00
print '<table class="notopnoleftnoright" width="100%">' ;
print $langs -> trans ( " SelectImportDataSet " ) . '<br>' ;
// Affiche les modules d'imports
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Module " ) . '</td>' ;
print '<td>' . $langs -> trans ( " ImportableDatas " ) . '</td>' ;
print '<td> </td>' ;
print '</tr>' ;
$val = true ;
2011-09-17 21:49:50 +02:00
if ( count ( $objimport -> array_import_code ))
2009-05-19 02:14:27 +02:00
{
foreach ( $objimport -> array_import_code as $key => $value )
{
$val =! $val ;
print '<tr ' . $bc [ $val ] . '><td nospan="nospan">' ;
//print img_object($objimport->array_import_module[$key]->getName(),$import->array_import_module[$key]->picto).' ';
print $objimport -> array_import_module [ $key ] -> getName ();
print '</td><td>' ;
2009-03-25 22:26:15 +01:00
//print $value;
2009-05-19 02:14:27 +02:00
print img_object ( $objimport -> array_import_module [ $key ] -> getName (), $objimport -> array_import_icon [ $key ]) . ' ' ;
print $objimport -> array_import_label [ $key ];
print '</td><td align="right">' ;
if ( $objimport -> array_import_perms [ $key ])
{
2009-10-17 15:12:55 +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 " ), 'filenew' ) . '</a>' ;
2009-05-19 02:14:27 +02:00
}
else
{
print $langs -> trans ( " NotEnoughPermissions " );
}
print '</td></tr>' ;
}
}
else
{
print '<tr><td ' . $bc [ false ] . ' colspan="3">' . $langs -> trans ( " NoImportableData " ) . '</td></tr>' ;
}
print '</table>' ;
print '</table>' ;
2011-09-20 17:29:31 +02:00
dol_fiche_end ();
2009-05-19 02:14:27 +02:00
if ( $mesg ) print $mesg ;
2009-03-25 22:26:15 +01:00
}
2009-10-04 00:32:10 +02:00
// STEP 2: Page to select input format file
2009-03-25 22:26:15 +01:00
if ( $step == 2 && $datatoimport )
{
2009-10-17 15:12:55 +02:00
$param = '&datatoimport=' . $datatoimport ;
if ( $excludefirstline ) $param .= '&excludefirstline=1' ;
2012-09-28 10:23:04 +02:00
if ( $separator ) $param .= '&separator=' . urlencode ( $separator );
if ( $enclosure ) $param .= '&enclosure=' . urlencode ( $enclosure );
2009-10-17 15:12:55 +02:00
2009-08-12 14:59:14 +02:00
llxHeader ( '' , $langs -> trans ( " NewImport " ), 'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones' );
2009-03-25 22:26:15 +01:00
2011-09-20 17:29:31 +02:00
$head = import_prepare_head ( $param , 2 );
2009-05-19 02:14:27 +02:00
2011-09-20 17:29:31 +02:00
dol_fiche_head ( $head , 'step2' , $langs -> trans ( " NewImport " ));
2009-05-19 02:14:27 +02:00
print '<table width="100%" class="border">' ;
// Module
print '<tr><td width="25%">' . $langs -> trans ( " Module " ) . '</td>' ;
print '<td>' ;
//print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_module[0]->picto).' ';
print $objimport -> array_import_module [ 0 ] -> getName ();
print '</td></tr>' ;
// Lot de donnees a importer
print '<tr><td width="25%">' . $langs -> trans ( " DatasetToImport " ) . '</td>' ;
print '<td>' ;
print img_object ( $objimport -> array_import_module [ 0 ] -> getName (), $objimport -> array_import_icon [ 0 ]) . ' ' ;
print $objimport -> array_import_label [ 0 ];
print '</td></tr>' ;
print '</table>' ;
2009-09-12 04:07:25 +02:00
print '<br>' . " \n " ;
2009-03-25 22:26:15 +01:00
2009-05-19 20:11:47 +02:00
print '<form name="userfile" action="' . $_SERVER [ " PHP_SELF " ] . '" enctype="multipart/form-data" METHOD="POST">' ;
2009-05-19 02:14:27 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ '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
2011-07-30 00:31:37 +02:00
print $langs -> trans ( " ChooseFormatOfFileToImport " , img_picto ( '' , 'filenew' )) . '<br>' ;
2009-03-25 22:26:15 +01:00
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">' ;
2009-05-19 02:14:27 +02:00
2009-05-19 20:11:47 +02:00
$filetoimport = '' ;
2009-05-19 02:14:27 +02:00
$var = true ;
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>' ;
$liste = $objmodelimport -> liste_modeles ( $db );
foreach ( $liste as $key )
{
$var =! $var ;
print '<tr ' . $bc [ $var ] . '>' ;
2012-11-11 18:11:10 +01:00
print '<td width="16">' . img_picto_common ( $key , $objmodelimport -> getPictoForKey ( $key )) . '</td>' ;
$text = $objmodelimport -> getDriverDescForKey ( $key );
print '<td>' . $form -> textwithpicto ( $objmodelimport -> getDriverLabelForKey ( $key ), $text ) . '</td>' ;
2009-10-17 15:12:55 +02:00
print '<td align="center"><a href="' . DOL_URL_ROOT . '/imports/emptyexample.php?format=' . $key . $param . '" target="_blank">' . $langs -> trans ( " DownloadEmptyExample " ) . '</a></td>' ;
2009-09-15 00:36:36 +02:00
// Action button
print '<td align="right">' ;
2009-10-17 15:12:55 +02:00
print '<a href="' . DOL_URL_ROOT . '/imports/import.php?step=3&format=' . $key . $param . '">' . img_picto ( $langs -> trans ( " SelectFormat " ), 'filenew' ) . '</a>' ;
2009-09-15 00:36:36 +02:00
print '</td>' ;
2009-05-19 02:14:27 +02:00
print '</tr>' ;
}
2009-09-15 00:36:36 +02:00
print '</table></form>' ;
2011-09-20 17:29:31 +02:00
dol_fiche_end ();
2009-09-15 00:36:36 +02:00
if ( $mesg ) print $mesg ;
}
2009-10-04 00:32:10 +02:00
// STEP 3: Page to select file
2009-09-15 00:36:36 +02:00
if ( $step == 3 && $datatoimport )
{
2009-10-17 15:12:55 +02:00
$param = '&datatoimport=' . $datatoimport . '&format=' . $format ;
if ( $excludefirstline ) $param .= '&excludefirstline=1' ;
2012-09-28 10:23:04 +02:00
if ( $separator ) $param .= '&separator=' . urlencode ( $separator );
if ( $enclosure ) $param .= '&enclosure=' . urlencode ( $enclosure );
2009-10-17 15:12:55 +02:00
2009-10-03 01:07:31 +02:00
$liste = $objmodelimport -> liste_modeles ( $db );
2009-09-15 00:36:36 +02:00
llxHeader ( '' , $langs -> trans ( " NewImport " ), 'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones' );
2012-09-03 17:14:33 +02:00
$head = import_prepare_head ( $param , 3 );
2009-09-15 00:36:36 +02:00
2011-09-20 17:29:31 +02:00
dol_fiche_head ( $head , 'step3' , $langs -> trans ( " NewImport " ));
2009-09-15 00:36:36 +02:00
2012-09-02 22:48:52 +02:00
/*
* Confirm delete file
*/
if ( $action == 'delete' )
{
2013-09-06 12:10:09 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?urlfile=' . urlencode ( GETPOST ( 'urlfile' )) . '&step=3' . $param , $langs -> trans ( 'DeleteFile' ), $langs -> trans ( 'ConfirmDeleteFile' ), 'confirm_deletefile' , '' , 0 , 1 );
2014-04-24 01:26:28 +02:00
2012-09-02 22:48:52 +02:00
}
2009-09-15 00:36:36 +02:00
print '<table width="100%" class="border">' ;
// Module
print '<tr><td width="25%">' . $langs -> trans ( " Module " ) . '</td>' ;
print '<td>' ;
//print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_module[0]->picto).' ';
print $objimport -> array_import_module [ 0 ] -> getName ();
print '</td></tr>' ;
// Lot de donnees a importer
print '<tr><td width="25%">' . $langs -> trans ( " DatasetToImport " ) . '</td>' ;
print '<td>' ;
print img_object ( $objimport -> array_import_module [ 0 ] -> getName (), $objimport -> array_import_icon [ 0 ]) . ' ' ;
print $objimport -> array_import_label [ 0 ];
print '</td></tr>' ;
2009-10-04 00:32:10 +02:00
print '</table><br>' ;
print '<b>' . $langs -> trans ( " InformationOnSourceFile " ) . '</b>' ;
print '<table width="100%" class="border">' ;
//print '<tr><td colspan="2"><b>'.$langs->trans("InformationOnSourceFile").'</b></td></tr>';
2009-10-02 00:17:18 +02:00
2009-09-15 00:36:36 +02:00
// Source file format
print '<tr><td width="25%">' . $langs -> trans ( " SourceFileFormat " ) . '</td>' ;
print '<td>' ;
2012-11-11 18:11:10 +01:00
$text = $objmodelimport -> getDriverDescForKey ( $format );
print $form -> textwithpicto ( $objmodelimport -> getDriverLabelForKey ( $format ), $text );
2013-04-25 01:13:13 +02:00
print '</td><td align="right" class="nowrap"><a href="' . DOL_URL_ROOT . '/imports/emptyexample.php?format=' . $format . $param . '" target="_blank">' . $langs -> trans ( " DownloadEmptyExample " ) . '</a>' ;
2009-10-13 19:23:26 +02:00
2009-09-15 00:36:36 +02:00
print '</td></tr>' ;
print '</table>' ;
print '<br>' . " \n " ;
print '<form name="userfile" action="' . $_SERVER [ " PHP_SELF " ] . '" enctype="multipart/form-data" METHOD="POST">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="max_file_size" value="' . $conf -> maxfilesize . '">' ;
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">' ;
$filetoimport = '' ;
$var = true ;
2009-05-19 20:11:47 +02:00
2009-06-18 23:56:46 +02:00
print '<tr><td colspan="6">' . $langs -> trans ( " ChooseFileToImport " , img_picto ( '' , 'filenew' )) . '</td></tr>' ;
2009-05-19 20:11:47 +02:00
2009-05-20 13:09:56 +02:00
print '<tr class="liste_titre"><td colspan="6">' . $langs -> trans ( " FileWithDataToImport " ) . '</td></tr>' ;
2009-05-19 02:14:27 +02:00
// Input file name box
2009-05-19 20:11:47 +02:00
$var = false ;
2009-05-20 13:09:56 +02:00
print '<tr ' . $bc [ $var ] . '><td colspan="6">' ;
2009-05-19 02:14:27 +02:00
print '<input type="file" name="userfile" size="20" maxlength="80"> ' ;
2009-05-19 20:11:47 +02:00
print '<input type="submit" class="button" value="' . $langs -> trans ( " AddFile " ) . '" name="sendit">' ;
print '<input type="hidden" value="' . $step . '" name="step">' ;
2009-09-15 00:36:36 +02:00
print '<input type="hidden" value="' . $format . '" name="format">' ;
2009-10-17 15:12:55 +02:00
print '<input type="hidden" value="' . $excludefirstline . '" name="excludefirstline">' ;
2012-09-28 10:23:04 +02:00
print '<input type="hidden" value="' . $separator . '" name="separator">' ;
print '<input type="hidden" value="' . $enclosure . '" name="enclosure">' ;
2009-05-19 20:11:47 +02:00
print '<input type="hidden" value="' . $datatoimport . '" name="datatoimport">' ;
2009-03-25 22:26:15 +01:00
print " </tr> \n " ;
2009-05-19 02:14:27 +02:00
2009-05-19 20:11:47 +02:00
// Search available imports
2012-09-02 22:48:52 +02:00
$filearray = dol_dir_list ( $conf -> import -> dir_temp , 'files' , 0 , '' , '' , 'name' , SORT_DESC );
2011-12-22 00:24:26 +01:00
if ( count ( $filearray ) > 0 )
2009-05-19 20:11:47 +02:00
{
2011-12-22 00:24:26 +01:00
$dir = $conf -> import -> dir_temp ;
2009-05-19 20:11:47 +02:00
// Search available files to import
2009-05-22 01:45:20 +02:00
$i = 0 ;
2011-12-22 00:24:26 +01:00
foreach ( $filearray as $key => $val )
2009-05-22 01:45:20 +02:00
{
2011-12-22 00:24:26 +01:00
$file = $val [ 'name' ];
2009-10-04 19:18:09 +02:00
// readdir return value in ISO and we want UTF8 in memory
if ( ! utf8_check ( $file )) $file = utf8_encode ( $file );
2009-10-22 17:09:04 +02:00
if ( preg_match ( '/^\./' , $file )) continue ;
2009-05-22 01:45:20 +02:00
$modulepart = 'import' ;
2009-10-17 15:12:55 +02:00
$urlsource = $_SERVER [ " PHP_SELF " ] . '?step=' . $step . $param . '&filetoimport=' . urlencode ( $filetoimport );
2009-05-22 01:45:20 +02:00
$relativepath = $file ;
$var =! $var ;
print '<tr ' . $bc [ $var ] . '>' ;
2009-05-19 20:11:47 +02:00
print '<td width="16">' . img_mime ( $file ) . '</td>' ;
2009-10-13 19:23:26 +02:00
print '<td>' ;
2013-04-20 20:30:18 +02:00
print '<a data-ajax="false" href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&file=' . urlencode ( $relativepath ) . '&step=3' . $param . '" target="_blank">' ;
2009-10-13 19:23:26 +02:00
print $file ;
print '</a>' ;
print '</td>' ;
2009-05-20 13:09:56 +02:00
// Affiche taille fichier
2009-10-13 23:46:09 +02:00
print '<td align="right">' . dol_print_size ( dol_filesize ( $dir . '/' . $file )) . '</td>' ;
2009-05-20 13:09:56 +02:00
// Affiche date fichier
2009-10-13 23:46:09 +02:00
print '<td align="right">' . dol_print_date ( dol_filemtime ( $dir . '/' . $file ), 'dayhour' ) . '</td>' ;
2009-05-20 13:09:56 +02:00
// Del button
2012-09-02 22:48:52 +02:00
print '<td align="right"><a href="' . $_SERVER [ 'PHP_SELF' ] . '?action=delete&step=3' . $param . '&urlfile=' . urlencode ( $relativepath );
2009-05-20 13:09:56 +02:00
print '">' . img_delete () . '</a></td>' ;
// Action button
print '<td align="right">' ;
2012-09-03 17:14:33 +02:00
print '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?step=4' . $param . '&filetoimport=' . urlencode ( $relativepath ) . '">' . img_picto ( $langs -> trans ( " NewImport " ), 'filenew' ) . '</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
}
print '</table></form>' ;
2011-09-20 17:29:31 +02:00
dol_fiche_end ();
2009-05-19 20:11:47 +02:00
if ( $mesg ) print $mesg ;
}
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
2009-09-15 00:36:36 +02:00
if ( $step == 4 && $datatoimport )
2009-05-19 20:11:47 +02:00
{
2009-10-02 00:17:18 +02:00
$model = $format ;
2009-10-03 01:07:31 +02:00
$liste = $objmodelimport -> liste_modeles ( $db );
2009-10-02 00:17:18 +02:00
// Create classe to use for import
2011-10-24 14:11:49 +02: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 ;
2012-03-04 13:00:53 +01:00
$obj = new $classname ( $db , $datatoimport );
2012-09-28 10:23:04 +02:00
if ( $model == 'csv' ) {
$obj -> separator = $separator ;
$obj -> enclosure = $enclosure ;
}
2009-10-02 00:17:18 +02:00
2009-06-07 20:08:41 +02:00
// Load source fields in input file
2009-10-04 00:32:10 +02:00
$fieldssource = array ();
2009-10-03 01:07:31 +02:00
$result = $obj -> import_open_file ( $conf -> import -> dir_temp . '/' . $filetoimport , $langs );
if ( $result >= 0 )
{
// Read first line
$arrayrecord = $obj -> import_read_record ();
2009-10-04 00:32:10 +02:00
// Put into array fieldssource starting with 1.
2009-10-03 01:07:31 +02:00
$i = 1 ;
foreach ( $arrayrecord as $key => $val )
{
2009-10-13 19:23:26 +02: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
$fieldstarget = $objimport -> array_import_fields [ 0 ];
2011-09-17 21:49:50 +02: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)
2011-09-17 21:49:50 +02:00
if ( count ( $array_match_file_to_database ) == 0 )
2009-06-07 20:08:41 +02:00
{
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"]
2009-06-07 20:08:41 +02:00
$pos = 1 ;
2011-09-17 21:49:50 +02:00
$num = count ( $fieldssource );
while ( $pos <= $num )
2009-06-07 20:08:41 +02:00
{
2011-09-17 21:49:50 +02:00
if ( $num >= 1 && $pos <= $num )
2009-06-07 20:08:41 +02:00
{
$posbis = 1 ;
foreach ( $fieldstarget as $key => $val )
{
if ( $posbis < $pos )
{
$posbis ++ ;
continue ;
}
// We found the key of targets that is at position pos
$array_match_file_to_database [ $pos ] = $key ;
2009-09-12 04:07:25 +02:00
if ( $serialized_array_match_file_to_database ) $serialized_array_match_file_to_database .= ',' ;
$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.
2009-09-12 04:07:25 +02:00
$_SESSION [ " dol_array_match_file_to_database " ] = $serialized_array_match_file_to_database ;
2009-06-07 20:08:41 +02:00
}
2009-11-09 23:10:39 +01:00
$array_match_database_to_file = array_flip ( $array_match_file_to_database );
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)
2009-09-15 00:36:36 +02:00
$param = '&format=' . $format . '&datatoimport=' . $datatoimport . '&filetoimport=' . urlencode ( $filetoimport );
2009-10-17 15:12:55 +02:00
if ( $excludefirstline ) $param .= '&excludefirstline=1' ;
2012-09-28 10:23:04 +02:00
if ( $separator ) $param .= '&separator=' . urlencode ( $separator );
if ( $enclosure ) $param .= '&enclosure=' . urlencode ( $enclosure );
2009-08-30 23:56:03 +02:00
2009-08-12 14:59:14 +02:00
llxHeader ( '' , $langs -> trans ( " NewImport " ), 'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones' );
2009-05-19 20:11:47 +02:00
2011-09-20 17:29:31 +02:00
$head = import_prepare_head ( $param , 4 );
2009-09-15 00:36:36 +02:00
2011-09-20 17:29:31 +02:00
dol_fiche_head ( $head , 'step4' , $langs -> trans ( " NewImport " ));
2009-05-19 20:11:47 +02:00
print '<table width="100%" class="border">' ;
// Module
print '<tr><td width="25%">' . $langs -> trans ( " Module " ) . '</td>' ;
print '<td>' ;
//print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_module[0]->picto).' ';
print $objimport -> array_import_module [ 0 ] -> getName ();
print '</td></tr>' ;
// Lot de donnees a importer
print '<tr><td width="25%">' . $langs -> trans ( " DatasetToImport " ) . '</td>' ;
print '<td>' ;
print img_object ( $objimport -> array_import_module [ 0 ] -> getName (), $objimport -> array_import_icon [ 0 ]) . ' ' ;
print $objimport -> array_import_label [ 0 ];
print '</td></tr>' ;
2009-10-04 00:32:10 +02:00
print '</table><br>' ;
print '<b>' . $langs -> trans ( " InformationOnSourceFile " ) . '</b>' ;
print '<table width="100%" class="border">' ;
//print '<tr><td colspan="2"><b>'.$langs->trans("InformationOnSourceFile").'</b></td></tr>';
2009-10-02 00:17:18 +02:00
2009-09-15 00:36:36 +02:00
// Source file format
print '<tr><td width="25%">' . $langs -> trans ( " SourceFileFormat " ) . '</td>' ;
print '<td>' ;
2012-11-11 18:11:10 +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
if ( $model == 'csv' ) {
print '<tr><td width="25%">' . $langs -> trans ( " CsvOptions " ) . '</td>' ;
print '<td>' ;
print '<form>' ;
print '<input type="hidden" value="' . $step . '" name="step">' ;
print '<input type="hidden" value="' . $format . '" name="format">' ;
print '<input type="hidden" value="' . $excludefirstline . '" name="excludefirstline">' ;
print '<input type="hidden" value="' . $datatoimport . '" name="datatoimport">' ;
print '<input type="hidden" value="' . $filetoimport . '" name="filetoimport">' ;
print $langs -> trans ( " Separator " ) . ' : ' ;
print '<input type="text" size="1" name="separator" value="' . htmlentities ( $separator ) . '"/>' ;
print ' ' . $langs -> trans ( " Enclosure " ) . ' : ' ;
print '<input type="text" size="1" name="enclosure" value="' . htmlentities ( $enclosure ) . '"/>' ;
2012-10-18 13:25:32 +02:00
print '<input type="submit" value="' . $langs -> trans ( 'Update' ) . '" class="button" />' ;
2012-09-28 10:23:04 +02:00
print '</form>' ;
print '</td></tr>' ;
}
2009-09-15 00:36:36 +02:00
// File to import
2009-05-20 13:09:56 +02:00
print '<tr><td width="25%">' . $langs -> trans ( " FileToImport " ) . '</td>' ;
2009-10-13 19:23:26 +02:00
print '<td>' ;
$modulepart = 'import' ;
2012-01-18 00:16:02 +01:00
$relativepath = GETPOST ( 'filetoimport' );
2013-04-20 20:30:18 +02:00
print '<a data-ajax="false" href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&file=' . urlencode ( $relativepath ) . '&step=4' . $param . '" target="_blank">' ;
2009-10-13 19:23:26 +02:00
print $filetoimport ;
print '</a>' ;
print '</td></tr>' ;
2009-05-19 20:11:47 +02:00
print '</table>' ;
2009-09-12 04:07:25 +02:00
print '<br>' . " \n " ;
2009-05-19 20:11:47 +02:00
2009-10-13 19:23:26 +02:00
// List of source fields
print '<!-- List of source fields -->' . " \n " ;
2009-09-03 01:46:55 +02:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="select_model">' ;
2009-09-15 00:36:36 +02:00
print '<input type="hidden" name="step" value="4">' ;
print '<input type="hidden" name="format" value="' . $format . '">' ;
2009-09-03 01:46:55 +02:00
print '<input type="hidden" name="datatoimport" value="' . $datatoimport . '">' ;
2009-09-12 04:07:25 +02:00
print '<input type="hidden" name="filetoimport" value="' . $filetoimport . '">' ;
2009-10-17 15:12:55 +02:00
print '<input type="hidden" name="excludefirstline" value="' . $excludefirstline . '">' ;
2012-09-28 10:23:04 +02:00
print '<input type="hidden" name="separator" value="' . $separator . '">' ;
print '<input type="hidden" name="enclosure" value="' . $enclosure . '">' ;
2009-09-03 01:46:55 +02:00
print '<table><tr><td colspan="2">' ;
print $langs -> trans ( " SelectImportFields " , img_picto ( '' , 'uparrow' , '' )) . ' ' ;
$htmlother -> select_import_model ( $importmodelid , 'importmodelid' , $datatoimport , 1 );
print '<input type="submit" class="button" value="' . $langs -> trans ( " Select " ) . '">' ;
print '</td></tr></table>' ;
print '</form>' ;
2009-05-19 02:14:27 +02:00
2009-08-23 02:15:30 +02:00
// Title of array with fields
2009-05-22 01:45:20 +02:00
print '<table class="nobordernopadding" width="100%">' ;
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
2009-09-14 23:27:09 +02:00
$fieldsplaced = array ();
2009-10-01 23:31:55 +02:00
$valforsourcefieldnb = array ();
2009-10-04 20:01:30 +02:00
$listofkeys = array ();
2009-09-14 23:27:09 +02:00
foreach ( $array_match_file_to_database as $key => $val )
{
$listofkeys [ $key ] = 1 ;
}
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
2009-05-22 01:45:20 +02:00
$var = true ;
2009-09-14 23:27:09 +02:00
$lefti = 1 ;
foreach ( $array_match_file_to_database as $key => $val )
2009-03-25 22:26:15 +01:00
{
2009-05-22 01:45:20 +02:00
$var =! $var ;
2011-09-20 17:29:31 +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;
$listofkeys [ $key ] = 1 ;
$fieldsplaced [ $key ] = 1 ;
2009-10-01 23:31:55 +02:00
$valforsourcefieldnb [ $lefti ] = $key ;
2009-09-14 23:27:09 +02:00
$lefti ++ ;
2009-08-23 02:15:30 +02:00
2011-09-17 21:49:50 +02: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)
2009-09-14 23:27:09 +02:00
$more = 1 ;
2011-09-17 21:49:50 +02:00
$num = count ( $fieldssource );
while ( $lefti <= $num )
2009-09-14 23:27:09 +02:00
{
$var =! $var ;
$newkey = getnewkey ( $fieldssource , $listofkeys );
2011-09-20 17:29:31 +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;
$listofkeys [ $key ] = 1 ;
$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
2009-08-23 02:15:30 +02:00
// List of targets fields
2009-05-22 01:45:20 +02:00
$i = 0 ;
2009-05-19 02:14:27 +02:00
$var = true ;
2009-10-01 23:31:55 +02:00
$mandatoryfieldshavesource = true ;
2009-08-23 02:15:30 +02:00
print '<table width="100%" class="nobordernopadding">' ;
2009-05-22 01:45:20 +02:00
foreach ( $fieldstarget as $code => $label )
2009-05-19 02:14:27 +02:00
{
$var =! $var ;
2009-09-28 22:06:15 +02:00
print '<tr ' . $bc [ $var ] . ' height="20">' ;
2009-05-22 01:45:20 +02:00
$i ++ ;
2009-03-25 22:26:15 +01:00
2009-11-08 20:28:44 +01:00
$entity = ( ! empty ( $objimport -> array_import_entities [ 0 ][ $code ]) ? $objimport -> array_import_entities [ 0 ][ $code ] : $objimport -> array_import_icon [ 0 ]);
2009-10-21 15:09:42 +02:00
$tablealias = preg_replace ( '/(\..*)$/i' , '' , $code );
2009-10-01 13:48:20 +02:00
$tablename = $objimport -> array_import_tables [ 0 ][ $tablealias ];
2009-05-19 02:14:27 +02:00
$entityicon = $entitytoicon [ $entity ] ? $entitytoicon [ $entity ] : $entity ;
$entitylang = $entitytolang [ $entity ] ? $entitytolang [ $entity ] : $entity ;
2009-03-25 22:26:15 +01:00
2013-04-25 01:13:13 +02:00
print '<td class="nowrap" style="font-weight: normal">=>' . img_object ( '' , $entityicon ) . ' ' . $langs -> trans ( $entitylang ) . '</td>' ;
2009-09-28 22:06:15 +02:00
print '<td style="font-weight: normal">' ;
2009-10-22 17:09:04 +02:00
$newlabel = preg_replace ( '/\*$/' , '' , $label );
2009-10-01 23:31:55 +02:00
$text = $langs -> trans ( $newlabel );
$more = '' ;
2009-10-22 17:09:04 +02:00
if ( preg_match ( '/\*$/' , $label ))
2009-10-01 23:31:55 +02:00
{
2010-02-04 20:54:58 +01:00
$text = '<span class="fieldrequired">' . $text . '</span>' ;
2011-09-17 21:49:50 +02:00
$more = (( ! empty ( $valforsourcefieldnb [ $i ]) && $valforsourcefieldnb [ $i ] <= count ( $fieldssource )) ? '' : img_warning ( $langs -> trans ( " FieldNeedSource " )));
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
print '<td style="font-weight: normal" align="right">' ;
$filecolumn = $array_match_database_to_file [ $code ];
2010-01-08 18:33:30 +01:00
// Source field info
2009-11-09 23:10:39 +01:00
$htmltext = '<b><u>' . $langs -> trans ( " FieldSource " ) . '</u></b><br>' ;
2011-09-17 21:49:50 +02:00
if ( $filecolumn > count ( $fieldssource )) $htmltext .= $langs -> trans ( " DataComeFromNoWhere " ) . '<br>' ;
2009-11-09 23:10:39 +01:00
else
{
if ( empty ( $objimport -> array_import_convertvalue [ 0 ][ $code ])) // If source file does not need convertion
{
2010-01-08 18:33:30 +01:00
$filecolumntoshow = $filecolumn ;
$htmltext .= $langs -> trans ( " DataComeFromFileFieldNb " , $filecolumntoshow ) . '<br>' ;
2009-11-09 23:10:39 +01:00
}
else
{
2012-01-18 00:16:02 +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
}
}
2011-11-16 23:38:10 +01:00
$htmltext .= $langs -> trans ( " SourceRequired " ) . ': <b>' . yn ( preg_match ( '/\*$/' , $label )) . '</b><br>' ;
2009-11-09 23:10:39 +01:00
$example = $objimport -> array_import_examplevalues [ 0 ][ $code ];
2012-01-18 00:16:02 +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>' ;
}
else
{
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>' ;
if ( $objimport -> array_import_convertvalue [ 0 ][ $code ][ 'rule' ] == 'fetchidfromcodeid' ) $htmltext .= $langs -> trans ( " SourceExample " ) . ': <b>' . $langs -> trans ( " ExampleAnyCodeOrIdFoundIntoDictionnary " , $langs -> transnoentitiesnoconv ( $objimport -> array_import_convertvalue [ 0 ][ $code ][ 'dict' ])) . ( $example ? ' (' . $langs -> transnoentitiesnoconv ( " Example " ) . ': ' . $example . ')' : '' ) . '</b><br>' ;
}
2009-11-09 23:10:39 +01:00
$htmltext .= '<br>' ;
2010-01-08 18:33:30 +01:00
// Target field info
2009-11-09 23:10:39 +01:00
$htmltext .= '<b><u>' . $langs -> trans ( " FieldTarget " ) . '</u></b><br>' ;
if ( empty ( $objimport -> array_import_convertvalue [ 0 ][ $code ])) // If source file does not need convertion
{
$htmltext .= $langs -> trans ( " DataIsInsertedInto " ) . '<br>' ;
}
else
{
2012-01-18 00:16:02 +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
}
$htmltext .= $langs -> trans ( " FieldTitle " ) . " : <b> " . $langs -> trans ( $newlabel ) . " </b><br> " ;
$htmltext .= $langs -> trans ( " Table " ) . " -> " . $langs -> trans ( " Field " ) . ': <b>' . $tablename . " -> " . preg_replace ( '/^.*\./' , '' , $code ) . " </b><br> " ;
2011-11-08 10:18:45 +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>' ;
2009-05-22 01:45:20 +02:00
$save_select .= $bit ;
2009-05-19 02:14:27 +02:00
}
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
2009-09-14 23:27:09 +02:00
$nbofnotimportedfields = 0 ;
foreach ( $fieldssource as $key => $val )
{
if ( empty ( $fieldsplaced [ $key ]))
{
2009-09-28 22:06:15 +02:00
//$var=!$var;
2009-09-14 23:27:09 +02:00
$nbofnotimportedfields ++ ;
2011-09-20 17:29:31 +02:00
show_elem ( $fieldssource , $key , '' , $var , 'nostyle' );
2009-09-14 23:27:09 +02:00
//print '> '.$lefti.'-'.$key;
$listofkeys [ $key ] = 1 ;
$lefti ++ ;
}
}
// Print one more empty field
$newkey = getnewkey ( $fieldssource , $listofkeys );
2011-09-20 17:29:31 +02:00
show_elem ( $fieldssource , $newkey , '' , $var , 'nostyle' );
2009-09-14 23:27:09 +02:00
//print '> '.$lefti.'-'.$newkey;
$listofkeys [ $newkey ] = 1 ;
$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%">' ;
2009-09-14 23:27:09 +02:00
$i = 0 ;
while ( $i < $nbofnotimportedfields )
{
// Print empty cells
2011-09-20 17:29:31 +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>' ;
2009-03-25 22:26:15 +01:00
2011-09-20 17:29:31 +02:00
dol_fiche_end ();
2009-03-25 22:26:15 +01:00
2009-08-23 02:15:30 +02:00
if ( $conf -> use_javascript_ajax )
{
2010-08-25 00:18:50 +02:00
print '<script type="text/javascript" language="javascript">' ;
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 ();
}
});
});
' ;
print " \n " ;
print 'function updateOrder(){' . " \n " ;
2011-09-20 11:40:27 +02:00
print 'var left_list = cleanSerialize(jQuery("#left").sortable("serialize" ));' . " \n " ;
//print 'var right_list = cleanSerialize(jQuery("#right").sortable("serialize" ));'."\n";
2010-08-25 00:18:50 +02:00
print 'var boxorder = \'A:\' + left_list;' . " \n " ;
//print 'var boxorder = \'A:\' + left_list + \'-B:\' + right_list;'."\n";
2011-09-20 11:40:27 +02:00
//print 'alert(\'boxorder=\' + boxorder);';
2010-08-25 00:18:50 +02:00
//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
print 'var newlocation= \'' . $_SERVER [ " PHP_SELF " ] . '?step=4' . $param . '&action=saveorder&boxorder=\' + boxorder;' . " \n " ;
//print 'alert(newlocation);';
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
if ( $mesg ) print $mesg ;
2009-03-25 22:26:15 +01:00
2009-05-19 02:14:27 +02:00
/*
* Barre d ' action
*/
print '<div class="tabsAction">' ;
2009-03-25 22:26:15 +01:00
2011-09-17 21:49:50 +02:00
if ( count ( $array_match_file_to_database ))
2009-05-19 02:14:27 +02:00
{
2009-10-01 23:31:55 +02:00
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>' ;
2009-10-01 23:31:55 +02:00
}
else
{
2013-04-30 19:02:02 +02:00
print '<a class="butActionRefused" 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
2011-09-17 21:49:50 +02:00
if ( count ( $array_match_file_to_database ))
2009-05-19 02:14:27 +02:00
{
2009-09-12 04:07:25 +02:00
print '<br>' . " \n " ;
print '<!-- Area to add new import profile -->' . " \n " ;
2009-05-19 02:14:27 +02:00
print $langs -> trans ( " SaveImportModel " );
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">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ '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 . '">' ;
2009-09-12 04:07:25 +02: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 . '">' ;
2012-09-28 10:23:04 +02:00
print '<input type="hidden" name="excludefirstline" value="' . $excludefirstline . '">' ;
print '<input type="hidden" value="' . $separator . '" name="separator">' ;
print '<input type="hidden" value="' . $enclosure . '" name="enclosure">' ;
2009-03-25 22:26:15 +01:00
2009-08-23 02:15:30 +02:00
print '<table summary="selectofimportprofil" class="noborder" width="100%">' ;
2009-03-25 22:26:15 +01:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " ImportModelName " ) . '</td>' ;
print '<td> </td>' ;
print '</tr>' ;
$var = false ;
print '<tr ' . $bc [ $var ] . '>' ;
2009-09-28 22:06:15 +02:00
print '<td><input name="import_name" size="48" value=""></td><td align="right">' ;
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
$sql = " SELECT rowid, label " ;
2009-03-25 22:26:15 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " import_model " ;
$sql .= " WHERE type = ' " . $datatoimport . " ' " ;
$sql .= " ORDER BY rowid " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ;
$var = false ;
while ( $i < $num )
{
$var =! $var ;
$obj = $db -> fetch_object ( $resql );
print '<tr ' . $bc [ $var ] . '><td>' ;
print $obj -> label ;
print '</td><td align="right">' ;
2009-10-17 15:12:55 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?step=' . $step . $param . '&action=deleteprof&id=' . $obj -> rowid . '&filetoimport=' . urlencode ( $filetoimport ) . '">' ;
2009-03-25 22:26:15 +01:00
print img_delete ();
print '</a>' ;
print '</tr>' ;
$i ++ ;
}
}
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>' ;
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
2009-09-15 00:36:36 +02:00
if ( $step == 5 && $datatoimport )
2009-03-25 22:26:15 +01:00
{
2009-10-02 00:17:18 +02:00
$model = $format ;
2009-10-04 00:32:10 +02:00
$liste = $objmodelimport -> liste_modeles ( $db );
2009-10-02 00:17:18 +02:00
// Create classe to use for import
2011-10-24 14:11:49 +02: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 ;
2012-03-04 13:00:53 +01:00
$obj = new $classname ( $db , $datatoimport );
2012-09-28 10:23:04 +02:00
if ( $model == 'csv' ) {
$obj -> separator = $separator ;
$obj -> enclosure = $enclosure ;
}
2009-10-02 00:17:18 +02:00
2009-10-01 23:31:55 +02:00
// Load source fields in input file
2009-10-04 00:32:10 +02:00
$fieldssource = array ();
$result = $obj -> import_open_file ( $conf -> import -> dir_temp . '/' . $filetoimport , $langs );
if ( $result >= 0 )
{
// Read first line
$arrayrecord = $obj -> import_read_record ();
// Put into array fieldssource starting with 1.
$i = 1 ;
foreach ( $arrayrecord as $key => $val )
{
2009-10-13 19:23:26 +02: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
2009-10-13 23:46:09 +02:00
$nboflines = dol_count_nb_of_line ( $conf -> import -> dir_temp . '/' . $filetoimport );
2012-10-08 16:25:50 +02:00
$param = '&leftmenu=import&format=' . $format . '&datatoimport=' . $datatoimport . '&filetoimport=' . urlencode ( $filetoimport ) . '&nboflines=' . $nboflines . '&separator=' . urlencode ( $separator ) . '&enclosure=' . urlencode ( $enclosure );
2012-09-28 10:23:04 +02:00
$param2 = $param ;
if ( $excludefirstline ) {
$param .= '&excludefirstline=1' ;
}
2009-10-15 17:15:38 +02:00
2009-08-12 14:59:14 +02:00
llxHeader ( '' , $langs -> trans ( " NewImport " ), 'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones' );
2009-05-19 02:14:27 +02:00
2011-09-20 17:29:31 +02:00
$head = import_prepare_head ( $param , 5 );
2009-05-19 02:14:27 +02:00
2011-09-20 17:29:31 +02:00
dol_fiche_head ( $head , 'step5' , $langs -> trans ( " NewImport " ));
2009-09-15 00:36:36 +02:00
2009-05-19 02:14:27 +02:00
print '<table width="100%" class="border">' ;
// Module
print '<tr><td width="25%">' . $langs -> trans ( " Module " ) . '</td>' ;
print '<td>' ;
//print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_module[0]->picto).' ';
print $objimport -> array_import_module [ 0 ] -> getName ();
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>' ;
print img_object ( $objimport -> array_import_module [ 0 ] -> getName (), $objimport -> array_import_icon [ 0 ]) . ' ' ;
print $objimport -> array_import_label [ 0 ];
print '</td></tr>' ;
2009-10-04 00:32:10 +02:00
print '</table><br>' ;
print '<b>' . $langs -> trans ( " InformationOnSourceFile " ) . '</b>' ;
print '<table width="100%" class="border">' ;
//print '<tr><td colspan="2"><b>'.$langs->trans("InformationOnSourceFile").'</b></td></tr>';
2009-10-02 00:17:18 +02:00
2009-09-15 00:36:36 +02:00
// Source file format
2009-10-13 19:23:26 +02:00
print '<tr><td width="25%">' . $langs -> trans ( " SourceFileFormat " ) . '</td>' ;
2009-09-15 00:36:36 +02:00
print '<td>' ;
2012-11-11 18:11:10 +01:00
$text = $objmodelimport -> getDriverDescForKey ( $format );
print $form -> textwithpicto ( $objmodelimport -> getDriverLabelForKey ( $format ), $text );
2009-09-15 00:36:36 +02:00
print '</td></tr>' ;
// 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>' ;
$modulepart = 'import' ;
2012-01-18 00:16:02 +01:00
$relativepath = GETPOST ( 'filetoimport' );
2013-04-20 20:30:18 +02:00
print '<a data-ajax="false" href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&file=' . urlencode ( $relativepath ) . '&step=4' . $param . '" target="_blank">' ;
2009-10-13 19:23:26 +02:00
print $filetoimport ;
print '</a>' ;
print '</td></tr>' ;
2009-09-15 00:36:36 +02:00
2009-10-04 00:32:10 +02:00
// Nb of fields
print '<tr><td>' ;
print $langs -> trans ( " NbOfSourceLines " );
print '</td><td>' ;
print $nboflines ;
print '</td></tr>' ;
// Checkbox do not import first line
print '<tr><td>' ;
2009-10-15 17:15:38 +02:00
print $langs -> trans ( " Option " );
2009-10-04 00:32:10 +02:00
print '</td><td>' ;
2009-10-15 01:44:25 +02:00
print '<input type="checkbox" name="excludefirstline" value="1"' ;
2011-08-31 16:55:54 +02:00
print ( $excludefirstline ? ' checked="checked"' : '' );
2012-10-08 16:25:50 +02:00
print ' onClick="javascript: window.location=\'' . $_SERVER [ " PHP_SELF " ] . '?step=5&excludefirstline=' . ( $excludefirstline ? '0' : '1' ) . $param2 . '\';">' ;
2009-10-15 17:15:38 +02:00
print ' ' . $langs -> trans ( " DoNotImportFirstLine " );
2009-10-04 00:32:10 +02:00
print '</td></tr>' ;
print '</table>' ;
2009-10-15 17:15:38 +02:00
print '<br>' ;
2009-10-04 00:32:10 +02:00
print '<b>' . $langs -> trans ( " InformationOnTargetTables " ) . '</b>' ;
print '<table width="100%" class="border">' ;
//print '<tr><td colspan="2"><b>'.$langs->trans("InformationOnTargetTables").'</b></td></tr>';
// Tables imported
2009-10-13 19:23:26 +02:00
print '<tr><td width="25%">' ;
2009-10-04 00:32:10 +02:00
print $langs -> trans ( " TablesTarget " );
print '</td><td>' ;
$listtables = array ();
2009-10-13 19:23:26 +02:00
$sort_array_match_file_to_database = $array_match_file_to_database ;
2009-10-04 00:32:10 +02:00
foreach ( $array_match_file_to_database as $code => $label )
{
//var_dump($fieldssource);
2011-09-17 21:49:50 +02:00
if ( $code > count ( $fieldssource )) continue ;
2009-10-04 00:32:10 +02:00
//print $code.'-'.$label;
2009-10-21 15:09:42 +02:00
$alias = preg_replace ( '/(\..*)$/i' , '' , $label );
2009-10-04 00:32:10 +02:00
$listtables [ $alias ] = $objimport -> array_import_tables [ 0 ][ $alias ];
}
2011-09-17 21:49:50 +02:00
if ( count ( $listtables ))
2009-10-04 00:32:10 +02:00
{
$newval = '' ;
2009-10-13 19:23:26 +02:00
//ksort($listtables);
2009-10-04 00:32:10 +02:00
foreach ( $listtables as $val )
{
if ( $newval ) print ', ' ;
$newval = $val ;
// 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 ;
}
}
else print $langs -> trans ( " Error " );
print '</td></tr>' ;
// Fields imported
print '<tr><td>' ;
print $langs -> trans ( " FieldsTarget " ) . '</td><td>' ;
$listfields = array ();
$i = 0 ;
//print 'fieldsource='.$fieldssource;
2009-10-13 19:23:26 +02:00
$sort_array_match_file_to_database = $array_match_file_to_database ;
ksort ( $sort_array_match_file_to_database );
//var_dump($sort_array_match_file_to_database);
foreach ( $sort_array_match_file_to_database as $code => $label )
2009-10-04 00:32:10 +02:00
{
$i ++ ;
//var_dump($fieldssource);
2011-09-17 21:49:50 +02:00
if ( $code > count ( $fieldssource )) continue ;
2009-10-04 00:32:10 +02:00
//print $code.'-'.$label;
2009-10-21 15:09:42 +02:00
$alias = preg_replace ( '/(\..*)$/i' , '' , $label );
2009-10-17 15:12:55 +02:00
$listfields [ $i ] = $langs -> trans ( " Field " ) . ' ' . $code . '->' . $label ;
2009-10-04 00:32:10 +02:00
}
2011-09-17 21:49:50 +02:00
print count ( $listfields ) ? ( join ( ', ' , $listfields )) : $langs -> trans ( " Error " );
2009-10-04 00:32:10 +02:00
print '</td></tr>' ;
print '</table>' ;
2011-09-20 17:29:31 +02:00
dol_fiche_end ();
2009-09-15 00:36:36 +02:00
2009-10-17 15:12:55 +02:00
2010-10-02 01:37:36 +02:00
if ( GETPOST ( 'action' ) != 'launchsimu' )
{
// Show import id
print $langs -> trans ( " NowClickToTestTheImport " , $langs -> transnoentitiesnoconv ( " RunSimulateImportFile " )) . '<br>' ;
print '<br>' ;
// Actions
print '<center>' ;
if ( $user -> rights -> import -> run )
{
print '<a class="butAction" href="' . DOL_URL_ROOT . '/imports/import.php?leftmenu=import&step=5&action=launchsimu' . $param . '">' . $langs -> trans ( " RunSimulateImportFile " ) . '</a>' ;
}
else
{
2013-04-30 19:02:02 +02:00
print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " NotEnoughPermissions " )) . '">' . $langs -> trans ( " RunSimulateImportFile " ) . '</a>' ;
2010-10-02 01:37:36 +02:00
}
print '</center>' ;
}
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 ;
2010-12-08 14:13:17 +01:00
$importid = dol_print_date ( dol_now (), '%Y%m%d%H%M%S' );
2010-10-02 01:37:36 +02:00
//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 );
if ( $result > 0 )
{
2013-04-25 23:49:24 +02:00
$sourcelinenb = 0 ; $endoffile = 0 ;
2010-10-02 01:37:36 +02:00
// Loop on each input file record
2013-04-25 23:49:24 +02:00
while ( $sourcelinenb < $nboflines && ! $endoffile )
2010-10-02 01:37:36 +02:00
{
$sourcelinenb ++ ;
2012-01-18 00:16:02 +01:00
// Read line and stor it into $arrayrecord
2010-10-02 01:37:36 +02:00
$arrayrecord = $obj -> import_read_record ();
2013-06-05 16:24:32 +02:00
if ( $arrayrecord === false )
{
2013-04-25 23:49:24 +02: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-06-05 16:24:32 +02:00
$endoffile ++ ;
continue ;
2013-04-25 23:49:24 +02:00
}
2010-10-02 01:37:36 +02:00
if ( $excludefirstline && $sourcelinenb == 1 ) continue ;
2012-01-18 00:16:02 +01:00
//
2011-09-17 21:49:50 +02:00
$result = $obj -> import_insert ( $arrayrecord , $array_match_file_to_database , $objimport , count ( $fieldssource ), $importid );
2012-01-18 00:16:02 +01:00
2011-09-17 21:49:50 +02: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 ++ ;
2010-10-02 01:37:36 +02:00
}
// Close file
$obj -> import_close_file ();
}
else
{
print $langs -> trans ( " ErrorFailedToOpenFile " , $pathfile );
}
$db -> rollback (); // We force rollback because this was just a simulation.
// Show OK
2011-09-17 21:49:50 +02:00
if ( ! count ( $arrayoferrors ) && ! count ( $arrayofwarnings )) print img_picto ( $langs -> trans ( " OK " ), 'tick' ) . ' <b>' . $langs -> trans ( " NoError " ) . '</b><br><br>' ;
2010-10-02 01:37:36 +02:00
else print $langs -> trans ( " NbOfLinesOK " , $nbok ) . '</b><br><br>' ;
// Show Errors
//var_dump($arrayoferrors);
2011-09-17 21:49:50 +02:00
if ( count ( $arrayoferrors ))
2010-10-02 01:37:36 +02:00
{
2011-09-17 21:49:50 +02:00
print img_error () . ' <b>' . $langs -> trans ( " ErrorsOnXLines " , count ( $arrayoferrors )) . '</b><br>' ;
2010-10-02 01:37:36 +02:00
print '<table width="100%" class="border"><tr><td>' ;
foreach ( $arrayoferrors as $key => $val )
{
$nboferrors ++ ;
if ( $nboferrors > $maxnboferrors )
{
2011-09-17 21:49:50 +02:00
print $langs -> trans ( " TooMuchErrors " ,( count ( $arrayoferrors ) - $nboferrors )) . " <br> " ;
2010-10-02 01:37:36 +02:00
break ;
}
print '* ' . $langs -> trans ( " Line " ) . ' ' . $key . '<br>' ;
foreach ( $val as $i => $err )
{
print ' > ' . $err [ 'lib' ] . '<br>' ;
}
}
print '</td></tr></table>' ;
print '<br>' ;
}
// Show Warnings
//var_dump($arrayoferrors);
2011-09-17 21:49:50 +02:00
if ( count ( $arrayofwarnings ))
2010-10-02 01:37:36 +02:00
{
2011-09-17 21:49:50 +02:00
print img_warning () . ' <b>' . $langs -> trans ( " WarningsOnXLines " , count ( $arrayofwarnings )) . '</b><br>' ;
2010-10-02 01:37:36 +02:00
print '<table width="100%" class="border"><tr><td>' ;
foreach ( $arrayofwarnings as $key => $val )
{
$nbofwarnings ++ ;
if ( $nbofwarnings > $maxnbofwarnings )
{
2011-09-17 21:49:50 +02:00
print $langs -> trans ( " TooMuchWarnings " ,( count ( $arrayofwarnings ) - $nbofwarnings )) . " <br> " ;
2010-10-02 01:37:36 +02:00
break ;
}
print ' * ' . $langs -> trans ( " Line " ) . ' ' . $key . '<br>' ;
foreach ( $val as $i => $err )
{
print ' > ' . $err [ 'lib' ] . '<br>' ;
}
}
print '</td></tr></table>' ;
print '<br>' ;
}
// Show import id
2010-12-08 14:13:17 +01:00
$importid = dol_print_date ( dol_now (), '%Y%m%d%H%M%S' );
2010-10-02 01:37:36 +02:00
print '<center>' ;
print $langs -> trans ( " NowClickToRunTheImport " , $langs -> transnoentitiesnoconv ( " RunImportFile " )) . '<br>' ;
print $langs -> trans ( " DataLoadedWithId " , $importid ) . '<br>' ;
print '</center>' ;
print '<br>' ;
// Actions
print '<center>' ;
if ( $user -> rights -> import -> run )
{
if ( empty ( $nboferrors ))
{
print '<a class="butAction" href="' . DOL_URL_ROOT . '/imports/import.php?leftmenu=import&step=6&importid=' . $importid . $param . '">' . $langs -> trans ( " RunImportFile " ) . '</a>' ;
}
else
{
//print '<a class="butAction" href="'.DOL_URL_ROOT.'/imports/import.php?leftmenu=import&step=5&action=launchsimu'.$param.'">'.$langs->trans("RunSimulateImportFile").'</a>';
2011-09-20 13:56:16 +02:00
print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " CorrectErrorBeforeRunningImport " )) . '">' . $langs -> trans ( " RunImportFile " ) . '</a>' ;
2010-10-02 01:37:36 +02:00
}
}
else
{
2011-09-20 13:56:16 +02:00
print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " NotEnoughPermissions " )) . '">' . $langs -> trans ( " RunSimulateImportFile " ) . '</a>' ;
2010-10-02 01:37:36 +02:00
2011-09-20 13:56:16 +02:00
print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag ( $langs -> transnoentitiesnoconv ( " NotEnoughPermissions " )) . '">' . $langs -> trans ( " RunImportFile " ) . '</a>' ;
2010-10-02 01:37:36 +02:00
}
print '</center>' ;
}
if ( $mesg ) print $mesg ;
2009-10-04 00:32:10 +02:00
}
2010-10-02 01:37:36 +02:00
// STEP 6: Real import
2009-10-04 00:32:10 +02:00
if ( $step == 6 && $datatoimport )
2009-10-15 17:15:38 +02:00
{
$model = $format ;
$liste = $objmodelimport -> liste_modeles ( $db );
$importid = $_REQUEST [ " importid " ];
// Create classe to use for import
2011-10-24 14:11:49 +02: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 ;
2012-03-04 13:00:53 +01:00
$obj = new $classname ( $db , $datatoimport );
2012-09-28 10:23:04 +02:00
if ( $model == 'csv' ) {
$obj -> separator = $separator ;
$obj -> enclosure = $enclosure ;
}
2009-10-15 17:15:38 +02:00
// Load source fields in input file
$fieldssource = array ();
$result = $obj -> import_open_file ( $conf -> import -> dir_temp . '/' . $filetoimport , $langs );
if ( $result >= 0 )
{
// Read first line
$arrayrecord = $obj -> import_read_record ();
// Put into array fieldssource starting with 1.
$i = 1 ;
foreach ( $arrayrecord as $key => $val )
{
$fieldssource [ $i ][ 'example1' ] = dol_trunc ( $val [ 'val' ], 24 );
$i ++ ;
}
$obj -> import_close_file ();
}
$nboflines = ( ! empty ( $_GET [ " nboflines " ]) ? $_GET [ " nboflines " ] : dol_count_nb_of_line ( $conf -> import -> dir_temp . '/' . $filetoimport ));
$param = '&format=' . $format . '&datatoimport=' . $datatoimport . '&filetoimport=' . urlencode ( $filetoimport ) . '&nboflines=' . $nboflines ;
if ( $excludefirstline ) $param .= '&excludefirstline=1' ;
2012-09-28 10:23:04 +02:00
if ( $separator ) $param .= '&separator=' . urlencode ( $separator );
if ( $enclosure ) $param .= '&enclosure=' . urlencode ( $enclosure );
2009-10-15 17:15:38 +02:00
llxHeader ( '' , $langs -> trans ( " NewImport " ), 'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones' );
2011-09-20 17:29:31 +02:00
$head = import_prepare_head ( $param , 6 );
2009-10-15 17:15:38 +02:00
2011-09-20 17:29:31 +02:00
dol_fiche_head ( $head , 'step6' , $langs -> trans ( " NewImport " ));
2009-10-15 17:15:38 +02:00
print '<table width="100%" class="border">' ;
// Module
print '<tr><td width="25%">' . $langs -> trans ( " Module " ) . '</td>' ;
print '<td>' ;
//print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_module[0]->picto).' ';
print $objimport -> array_import_module [ 0 ] -> getName ();
print '</td></tr>' ;
// Lot de donnees a importer
print '<tr><td>' . $langs -> trans ( " DatasetToImport " ) . '</td>' ;
print '<td>' ;
print img_object ( $objimport -> array_import_module [ 0 ] -> getName (), $objimport -> array_import_icon [ 0 ]) . ' ' ;
print $objimport -> array_import_label [ 0 ];
print '</td></tr>' ;
print '</table><br>' ;
print '<b>' . $langs -> trans ( " InformationOnSourceFile " ) . '</b>' ;
print '<table width="100%" class="border">' ;
//print '<tr><td colspan="2"><b>'.$langs->trans("InformationOnSourceFile").'</b></td></tr>';
// Source file format
print '<tr><td width="25%">' . $langs -> trans ( " SourceFileFormat " ) . '</td>' ;
print '<td>' ;
2012-11-17 10:19:26 +01:00
$text = $objmodelimport -> getDriverDescForKey ( $format );
2012-11-11 18:11:10 +01:00
print $form -> textwithpicto ( $objmodelimport -> getDriverLabelForKey ( $format ), $text );
2009-10-15 17:15:38 +02:00
print '</td></tr>' ;
// File to import
print '<tr><td>' . $langs -> trans ( " FileToImport " ) . '</td>' ;
print '<td>' ;
$modulepart = 'import' ;
2012-01-18 00:16:02 +01:00
$relativepath = GETPOST ( 'filetoimport' );
2013-04-20 20:30:18 +02:00
print '<a data-ajax="false" href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&file=' . urlencode ( $relativepath ) . '&step=4' . $param . '" target="_blank">' ;
2009-10-15 17:15:38 +02:00
print $filetoimport ;
print '</a>' ;
print '</td></tr>' ;
// Nb of fields
print '<tr><td>' ;
print $langs -> trans ( " NbOfSourceLines " );
print '</td><td>' ;
print $nboflines ;
print '</td></tr>' ;
// Checkbox do not import first line
print '<tr><td>' ;
print $langs -> trans ( " Option " );
print '</td><td>' ;
2011-08-31 17:12:09 +02:00
print '<input type="checkbox" name="excludefirstline" value="1" disabled="disabled"' ;
2011-08-31 16:55:54 +02:00
print ( $excludefirstline ? ' checked="checked"' : '' );
2009-10-15 17:15:38 +02:00
print '>' ;
print ' ' . $langs -> trans ( " DoNotImportFirstLine " );
print '</td></tr>' ;
print '</table>' ;
print '<br>' ;
print '<b>' . $langs -> trans ( " InformationOnTargetTables " ) . '</b>' ;
print '<table width="100%" class="border">' ;
//print '<tr><td colspan="2"><b>'.$langs->trans("InformationOnTargetTables").'</b></td></tr>';
// Tables imported
print '<tr><td width="25%">' ;
print $langs -> trans ( " TablesTarget " );
print '</td><td>' ;
$listtables = array ();
foreach ( $array_match_file_to_database as $code => $label )
{
//var_dump($fieldssource);
2011-09-17 21:49:50 +02:00
if ( $code > count ( $fieldssource )) continue ;
2009-10-15 17:15:38 +02:00
//print $code.'-'.$label;
2009-10-21 15:09:42 +02:00
$alias = preg_replace ( '/(\..*)$/i' , '' , $label );
2009-10-15 17:15:38 +02:00
$listtables [ $alias ] = $objimport -> array_import_tables [ 0 ][ $alias ];
}
2011-09-17 21:49:50 +02:00
if ( count ( $listtables ))
2009-10-15 17:15:38 +02:00
{
$newval = '' ;
foreach ( $listtables as $val )
{
if ( $newval ) print ', ' ;
$newval = $val ;
// 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 ;
}
}
else print $langs -> trans ( " Error " );
print '</td></tr>' ;
// Fields imported
print '<tr><td>' ;
print $langs -> trans ( " FieldsTarget " ) . '</td><td>' ;
$listfields = array ();
$i = 0 ;
$sort_array_match_file_to_database = $array_match_file_to_database ;
ksort ( $sort_array_match_file_to_database );
//var_dump($sort_array_match_file_to_database);
foreach ( $sort_array_match_file_to_database as $code => $label )
{
$i ++ ;
//var_dump($fieldssource);
2011-09-17 21:49:50 +02:00
if ( $code > count ( $fieldssource )) continue ;
2009-10-15 17:15:38 +02:00
//print $code.'-'.$label;
2009-10-21 15:09:42 +02:00
$alias = preg_replace ( '/(\..*)$/i' , '' , $label );
2009-10-17 15:12:55 +02:00
$listfields [ $i ] = $langs -> trans ( " Field " ) . ' ' . $code . '->' . $label ;
2009-10-15 17:15:38 +02:00
}
2011-09-17 21:49:50 +02:00
print count ( $listfields ) ? ( join ( ', ' , $listfields )) : $langs -> trans ( " Error " );
2009-10-15 17:15:38 +02:00
print '</td></tr>' ;
print '</table>' ;
// 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 ;
2010-12-08 14:13:17 +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
2009-10-17 15:48:17 +02:00
$nbok = 0 ;
2009-10-15 17:15:38 +02:00
$pathfile = $conf -> import -> dir_temp . '/' . $filetoimport ;
$result = $obj -> import_open_file ( $pathfile , $langs );
if ( $result > 0 )
{
2013-04-25 23:49:24 +02:00
$sourcelinenb = 0 ; $endoffile = 0 ;
while ( $sourcelinenb < $nboflines && ! $endoffile )
2009-10-15 17:15:38 +02:00
{
$sourcelinenb ++ ;
2009-10-17 15:48:17 +02:00
$arrayrecord = $obj -> import_read_record ();
2013-04-25 23:49:24 +02:00
if ( $arrayrecord === false )
{
$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' );
$endoffile ++ ;
continue ;
}
2009-10-15 17:15:38 +02:00
if ( $excludefirstline && $sourcelinenb == 1 ) continue ;
2011-09-17 21:49:50 +02:00
$result = $obj -> import_insert ( $arrayrecord , $array_match_file_to_database , $objimport , count ( $fieldssource ), $importid );
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 ();
}
else
{
print $langs -> trans ( " ErrorFailedToOpenFile " , $pathfile );
}
2011-09-17 21:49:50 +02:00
if ( count ( $arrayoferrors ) > 0 ) $db -> rollback (); // We force rollback because this was errors.
2009-10-17 15:12:55 +02:00
else $db -> commit (); // We can commit if no errors.
2009-10-15 17:15:38 +02:00
2011-09-20 17:29:31 +02:00
dol_fiche_end ();
2009-10-15 17:15:38 +02:00
2009-10-17 15:12:55 +02:00
// Show result
2009-10-15 17:15:38 +02:00
print '<center>' ;
2009-10-17 15:48:17 +02:00
print '<br>' ;
print $langs -> trans ( " NbOfLinesImported " , $nbok ) . '</b><br><br>' ;
2009-10-17 15:12:55 +02:00
print $langs -> trans ( " FileWasImported " , $importid ) . '<br>' ;
print $langs -> trans ( " YouCanUseImportIdToFindRecord " , $importid ) . '<br>' ;
2009-10-15 17:15:38 +02:00
print '</center>' ;
if ( $mesg ) print $mesg ;
}
2009-03-25 22:26:15 +01:00
print '<br>' ;
2011-08-27 16:24:16 +02:00
llxFooter ();
2009-08-23 02:15:30 +02:00
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
*
* @ 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
* @ return void
2009-08-23 02:24:56 +02:00
*/
2011-09-20 17:29:31 +02:00
function show_elem ( $fieldssource , $pos , $key , $var , $nostyle = '' )
2009-08-23 02:15:30 +02:00
{
global $langs , $bc ;
2010-08-25 00:18:50 +02:00
print " \n \n <!-- Box " . $pos . " start --> \n " ;
print '<div class="box" style="padding: 0px 0px 0px 0px;" id="boxto_' . $pos . '">' . " \n " ;
2009-08-23 02:15:30 +02:00
print '<table summary="boxtable' . $pos . '" width="100%" class="nobordernopadding">' . " \n " ;
2011-09-17 21:49:50 +02:00
if ( $pos && $pos > count ( $fieldssource )) // No fields
2009-08-23 02:24:56 +02:00
{
2009-10-03 16:16:52 +02:00
print '<tr ' . ( $nostyle ? '' : $bc [ $var ]) . ' height="20">' ;
2009-08-30 23:56:03 +02:00
print '<td class="nocellnopadding" width="16" style="font-weight: normal">' ;
2009-09-08 01:49:16 +02:00
print img_picto (( $pos > 0 ? $langs -> trans ( " MoveField " , $pos ) : '' ), 'uparrow' , '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>' ;
2009-08-23 02:24:56 +02:00
}
2009-10-13 19:23:26 +02:00
elseif ( $key == 'none' ) // Empty line
2009-08-23 02:24:56 +02:00
{
2009-10-03 16:16:52 +02:00
print '<tr ' . ( $nostyle ? '' : $bc [ $var ]) . ' height="20">' ;
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>' ;
2009-08-23 02:24:56 +02:00
}
2009-09-14 23:27:09 +02:00
else // Print field of source file
2009-08-23 02:15:30 +02:00
{
2009-10-03 16:16:52 +02:00
print '<tr ' . ( $nostyle ? '' : $bc [ $var ]) . ' height="20">' ;
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
2009-09-08 01:49:16 +02:00
print img_picto ( $langs -> trans ( " MoveField " , $pos ), 'uparrow' , 'class="boxhandle" style="cursor:move;"' );
2009-08-23 02:15:30 +02:00
print '</td>' ;
2009-08-23 02:34:55 +02:00
print '<td style="font-weight: normal">' ;
2009-10-03 01:07:31 +02:00
print $langs -> trans ( " Field " ) . ' ' . $pos ;
2012-03-03 19:09:29 +01:00
$example = $fieldssource [ $pos ][ 'example1' ];
if ( $example )
{
if ( ! utf8_check ( $example )) $example = utf8_encode ( $example );
print ' (<i>' . $example . '</i>)' ;
}
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
*
2011-09-20 17:48:06 +02:00
* @ param array & $fieldssource Array of field source
* @ param array & $listofkey Array of keys
2011-09-20 17:29:31 +02:00
* @ return void
2009-09-14 23:27:09 +02:00
*/
function getnewkey ( & $fieldssource , & $listofkey )
{
2011-09-17 21:49:50 +02:00
$i = count ( $fieldssource ) + 1 ;
2009-09-14 23:27:09 +02:00
// Max number of key
$maxkey = 0 ;
foreach ( $listofkey as $key => $val )
{
$maxkey = max ( $maxkey , $key );
}
// Found next empty key
while ( $i <= $maxkey )
{
if ( empty ( $listofkey [ $i ])) break ;
else $i ++ ;
}
$listofkey [ $i ] = 1 ;
return $i ;
}
2009-03-25 22:26:15 +01:00
?>