From b0e3b124e04021d0b756fdd42027e63d58fa9cea Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 2 Sep 2009 23:46:55 +0000 Subject: [PATCH] Work on import module --- htdocs/exports/export.php | 9 ++-- htdocs/html.formother.class.php | 47 +++++++++++++++++++ htdocs/imports/ajaximport.php | 46 ++++++++++++++---- htdocs/imports/import.php | 82 ++++++++++++++++++--------------- htdocs/langs/en_US/exports.lang | 3 +- htdocs/langs/fr_FR/exports.lang | 3 +- htdocs/master.inc.php | 1 + 7 files changed, 138 insertions(+), 53 deletions(-) diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index 398e413ffb6..7946a59d4ee 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -361,15 +361,14 @@ if ($step == 2 && $datatoexport) print ''; print '
'; - // Liste deroulante des modeles d'export - print '
'; + // Combo list of export models + print ''; print ''; print ''; print ''; print ''; - print ''; @@ -337,7 +337,8 @@ if ($step == 2 && $datatoimport) $var=!$var; print ''; print ''; - print ''; + print ''; + print ''; //print ''; print ''; } @@ -463,9 +464,13 @@ if ($step == 3 && $datatoimport) $_SESSION["dol_array_match_file_to_database"]=$array_match_file_to_database; } + // Now $array_match_file_to_database contains fieldnb(1,2,3...)=>fielddatabase(key in $array_match_file_to_database) + llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones'); + $param='step=3&datatoimport='.$datatoimport.'&filetoimport='.urlencode($_GET["filetoimport"]); + $h = 0; $head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=1'; @@ -476,7 +481,7 @@ if ($step == 3 && $datatoimport) $head[$h][1] = $langs->trans("Step")." 2"; $h++; - $head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=3&datatoimport='.$datatoimport.'&filetoimport='.urlencode($_GET["filetoimport"]); + $head[$h][0] = DOL_URL_ROOT.'/imports/import.php?'.$param; $head[$h][1] = $langs->trans("Step")." 3"; $hselected=$h; $h++; @@ -507,7 +512,18 @@ if ($step == 3 && $datatoimport) print '
'; - print $langs->trans("SelectImportFields",img_picto('','uparrow','')); + // Combo list of import models + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; - print $langs->trans("SelectExportFields"); - print ''; + print '
'; + print $langs->trans("SelectExportFields").' '; $htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1); print ''; print '
'; diff --git a/htdocs/html.formother.class.php b/htdocs/html.formother.class.php index 57920ec39c5..3499d0fe58f 100644 --- a/htdocs/html.formother.class.php +++ b/htdocs/html.formother.class.php @@ -102,6 +102,53 @@ class FormOther } + /** + * \brief Retourne la liste des modeles d'import + * \param selected Id modele pre-selectionne + * \param htmlname Nom de la zone select + * \param type Type des modeles recherches + * \param useempty Affiche valeur vide dans liste + */ + function select_import_model($selected='',$htmlname='importmodelid',$type='',$useempty=0) + { + $sql = "SELECT rowid, label"; + $sql.= " FROM ".MAIN_DB_PREFIX."import_model"; + $sql.= " WHERE type = '".$type."'"; + $sql.= " ORDER BY rowid"; + $result = $this->db->query($sql); + if ($result) + { + print '"; + } + else { + dol_print_error($this->db); + } + } + + /** * \brief Retourne la liste des ecotaxes avec tooltip sur le libelle * \param selected code ecotaxes pre-selectionne diff --git a/htdocs/imports/ajaximport.php b/htdocs/imports/ajaximport.php index c5bb91d8707..ef75ffeb9ae 100644 --- a/htdocs/imports/ajaximport.php +++ b/htdocs/imports/ajaximport.php @@ -18,7 +18,7 @@ */ /** - * \file htdocs/ajaximport.php + * \file htdocs/imports/ajaximport.php * \brief File to return Ajax response on Fields move in import page * \version $Id$ */ @@ -28,7 +28,6 @@ if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // This is to make Dolibarr working with Plesk set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs'); @@ -38,24 +37,55 @@ $entityCookieName = "DOLENTITYID_dolibarr"; if (isset($_COOKIE[$entityCookieName])) $_SESSION["dol_entity"] = $_COOKIE[$entityCookieName]; require('../master.inc.php'); +require_once(DOL_DOCUMENT_ROOT."/imports/import.class.php"); +require_once(DOL_DOCUMENT_ROOT.'/includes/modules/import/modules_import.php'); // Enregistrement de la position des champs - -//$_SESSION["dol_array_match_file_to_database"] -dol_syslog("AjaxImport boxorder=".$_GET['boxorder']." userid=".$_GET['userid'], LOG_DEBUG); - -$part=split(':',$collist); +dol_syslog("AjaxImport boxorder=".$_GET['boxorder']." userid=".$_GET['userid']." datatoimport=".$_GET["datatoimport"], LOG_DEBUG); +$part=split(':',$_GET['boxorder']); $colonne=$part[0]; $list=$part[1]; dol_syslog('AjaxImport column='.$colonne.' list='.$list); +// Init object $objimport that describe the predefined import +$fuser->id=$_GET['userid']; +$fuser->fetch(); +$objimport=new Import($db); +$datatoimport=isset($_GET["datatoimport"])? $_GET["datatoimport"] : (isset($_POST["datatoimport"])?$_POST["datatoimport"]:''); +$objimport->load_arrays($fuser,$datatoimport); -// We define array_match_file_to_database +// Init targets fields array +$fieldstarget=$objimport->array_import_fields[0]; + +// We redefine array_match_file_to_database $array_match_file_to_database=array(); +$listelem=split(',',$list); +$pos=0; +foreach($listelem as $fieldnb) +{ + //dol_syslog("Fieldnb in file=".$fieldnb." => keynb in targets=".$pos); + // Get name of database field at position $pos into $namefield + $posbis=0;$namefield=''; + foreach($fieldstarget as $key => $val) + { + if ($posbis < $pos) + { + $posbis++; + continue; + } + // We found the key of targets that is at position pos + $namefield=$key; + break; + } + if (! empty($fieldnb)) $array_match_file_to_database[$fieldnb]=$namefield; + + $pos++; +} // We save new matching in session $_SESSION["dol_array_match_file_to_database"]=$array_match_file_to_database; +dol_syslog('AjaxImport dol_array_match_file_to_database='.var_export($array_match_file_to_database,true)); ?> diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index 9c9d8a55887..504263ff5df 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -327,7 +327,7 @@ if ($step == 2 && $datatoimport) $fullpathfiletoimport=''; $var=true; - // Add help informations + // Add format informations and link to download example print '
'; print $langs->trans("FileMustHaveOneOfFollowingFormat"); print '
'.img_picto_common($key,$objmodelimport->getPicto($key)).''.$objmodelimport->getDriverLabel($key).''.$objmodelimport->getDriverLabel($key).''.$langs->trans("DownloadEmptyExample").''.$objmodelimport->getLibLabel($key).''.$objmodelimport->getLibVersion($key).'
'; + print $langs->trans("SelectImportFields",img_picto('','uparrow','')).' '; + $htmlother->select_import_model($importmodelid,'importmodelid',$datatoimport,1); + print ''; + print '
'; + print '
'; // Title of array with fields print ''; @@ -616,36 +632,24 @@ if ($step == 3 && $datatoimport) print ''; - + // List of not imported fields print ''; - print ''; + print ''; print '
'.$langs->trans("NotImportedFields").'
'; + print '
'; print "\n\n"; print '\n"; print "\n"; + print ''; + // Print empty cells + show_elem('','',$var,'none'); print '
'; @@ -656,19 +660,21 @@ if ($step == 3 && $datatoimport) if ($conf->use_javascript_ajax) { print "\n"; - print '