diff --git a/htdocs/imports/emptyexample.php b/htdocs/imports/emptyexample.php new file mode 100644 index 00000000000..316fbb0e665 --- /dev/null +++ b/htdocs/imports/emptyexample.php @@ -0,0 +1,593 @@ + + * Copyright (C) 2005-2007 Regis Houssin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/** + * \file htdocs/imports/emptyexamples.php + * \ingroup import + * \brief Show examples of import file + * \version $Id$ + */ + +require_once("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); +require_once(DOL_DOCUMENT_ROOT."/html.formother.class.php"); +require_once(DOL_DOCUMENT_ROOT."/imports/import.class.php"); +require_once(DOL_DOCUMENT_ROOT.'/includes/modules/import/modules_import.php'); + +$langs->load("exports"); + + +if (! $user->societe_id == 0) +accessforbidden(); + +$array_match_file_to_database=isset($_SESSION["dol_array_match_file_to_database"])?$_SESSION["dol_array_match_file_to_database"]:array(); +$datatoimport=isset($_GET["datatoimport"])? $_GET["datatoimport"] : (isset($_POST["datatoimport"])?$_POST["datatoimport"]:''); +$action=isset($_GET["action"]) ? $_GET["action"] : (isset($_POST["action"])?$_POST["action"]:''); +$step=isset($_GET["step"])? $_GET["step"] : (isset($_POST["step"])?$_POST["step"]:1); +$import_name=isset($_POST["import_name"])? $_POST["import_name"] : ''; +$hexa=isset($_POST["hexa"])? $_POST["hexa"] : ''; +$importmodelid=isset($_POST["importmodelid"])? $_POST["importmodelid"] : ''; + +$objimport=new Import($db); +$objimport->load_arrays($user,$datatoimport); + +$objmodelimport=new ModeleImports(); +$html = new Form($db); +$htmlother = new FormOther($db); +$formfile = new FormFile($db); +$sqlusedforimport=''; + + +/* + * Actions + */ + +$objmodelimport=new ModeleImports(); + + + // Load source fields in input file + $fieldssource=array( + 1=>array('name'=>'aa','example1'=>'val1','example2'=>'val2'), + 2=>array('name'=>'bb','example1'=>'valb1','example2'=>'valb2') + ); + + // Load targets fields in database + $fieldstarget=$objimport->array_import_fields[0]; + + $maxpos=max(sizeof($fieldssource),sizeof($fieldstarget)); + + if (sizeof($array_match_file_to_database) == 0) + { + // This is first input in screen, we need to define the $array_match_file_to_database array + $pos=1; + while ($pos <= sizeof($fieldssource)) + { + if (sizeof($fieldssource) > 1 && $pos <= sizeof($fieldssource)) + { + $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; + break; + } + } + $pos++; + } + // Save the match array in session. We now will use the array in session. + $_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'; + $head[$h][1] = $langs->trans("Step")." 1"; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=2&datatoimport='.$datatoimport; + $head[$h][1] = $langs->trans("Step")." 2"; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/imports/import.php?'.$param; + $head[$h][1] = $langs->trans("Step")." 3"; + $hselected=$h; + $h++; + + dol_fiche_head($head, $hselected, $langs->trans("NewImport")); + + print ''; + + // Module + print ''; + print ''; + + // Lot de donnees a importer + print ''; + print ''; + + // Nbre champs importes + print ''; + print ''; + + print '
'.$langs->trans("Module").''; + //print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_module[0]->picto).' '; + print $objimport->array_import_module[0]->getName(); + print '
'.$langs->trans("DatasetToImport").''; + print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_icon[0]).' '; + print $objimport->array_import_label[0]; + print '
'.$langs->trans("FileToImport").''.$_GET["filetoimport"].'
'; + print '
'; + + + // Combo list of import models + print '
'; + print ''; + print ''; + print ''; + print ''; + print '
'; + print $langs->trans("SelectImportFields",img_picto('','uparrow','')).' '; + $htmlother->select_import_model($importmodelid,'importmodelid',$datatoimport,1); + print ''; + print '
'; + print '
'; + + // Title of array with fields + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + + // List of not imported fields + print ''; + + print ''; + print ''; + + print '
'.$langs->trans("FieldsInSourceFile").''.$langs->trans("FieldsInTargetDatabase").'
'; + + //var_dump($array_match_file_to_database); + $pos=1; + + print "\n\n"; + print '
'."\n"; + + // List of source fields +// print ''; + $var=true; + while ($pos <= $maxpos) + { + $var=!$var; + +// print "'; +// print ''; + + show_elem($fieldssource,$pos,$var,$keyfound); + + // Arrows +// print ''; + +// print ''; + +// print ''; + + $pos++; + + if ($pos > sizeof($fieldstarget)) break; + } + + // print '
'; + // Get name of database field at position $pos into $namefield + $namefield=''; + $posbis=1; + foreach($fieldstarget as $key => $val) + { + if ($posbis < $pos) + { + $posbis++; + continue; + } + // We found the key of targets that is at position pos + $namefield=$key; + break; + } + // Now we check if there is a file field linked to this $namefield database field + $keyfound=''; + foreach($fieldssource as $key => $val) + { + if (! empty($array_match_file_to_database[$key]) && $array_match_file_to_database[$key] == $namefield) + { +// print $langs->trans("Field").' '.$key.': '; +// print $fieldssource[$key]['name'].' ('.$fieldssource[$key]['example1'].')'; + $keyfound=$key; + break; + } + } +// print ' '; + if (sizeof($fieldssource) > 1 && $pos <= sizeof($fieldssource)) + { +// if ($pos < $maxpos) print ''.img_down().''; +// if ($pos > 1) print ''.img_up().''; + } +// print ' '; +// if (sizeof($fieldssource) > 1 && $pos <= sizeof($fieldssource)) print ' -> '; +// print '
'; + + print "
\n"; + print "\n"; + + + print '
'; + + // List of targets fields + $i = 0; + $var=true; + print ''; + foreach($fieldstarget as $code=>$label) + { + $var=!$var; + print ''; + + $i++; + + $entity=$objimport->array_import_entities[0][$code]; + $entityicon=$entitytoicon[$entity]?$entitytoicon[$entity]:$entity; + $entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$entity; + + print ''; + print ''; + + print ''; + $save_select.=$bit; + } + print '
'.img_object('',$entityicon).' '.$langs->trans($entitylang).''.$langs->trans($label).' ('.$code.')
'; + + print '
'.$langs->trans("NotImportedFields").'
'; + + print "\n\n"; + print '\n"; + print "\n"; + + print ''; + // Print empty cells + show_elem('','',$var,'none'); + print '
'; + + print ''; + + + if ($conf->use_javascript_ajax) + { + print "\n"; + print ''."\n"; + } + + + if ($mesg) print $mesg; + + /* + * Barre d'action + */ + print '
'; + + if (sizeof($array_match_file_to_database)) + { + print ''.$langs->trans("NextStep").''; + } + + print '
'; + + + // Area for profils import + if (sizeof($array_match_file_to_database)) + { + print '
'; + print $langs->trans("SaveImportModel"); + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + $var=false; + print ''; + print ''; + + // List of existing import profils + $sql = "SELECT rowid, label"; + $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 ''; + $i++; + } + } + else { + dol_print_error($db); + } + + print '
'.$langs->trans("ImportModelName").' 
'; + print ''; + print '
'; + print $obj->label; + print ''; + print 'rowid.'">'; + print img_delete(); + print ''; + print '
'; + print '
'; + } + +} + +if ($step == 4 && $datatoimport) +{ + asort($array_match_file_to_database); + + llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones'); + + /* + * Affichage onglets + */ + $h = 0; + + $head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=1'; + $head[$h][1] = $langs->trans("Step")." 1"; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=2&datatoimport='.$datatoimport; + $head[$h][1] = $langs->trans("Step")." 2"; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=3&datatoimport='.$datatoimport; + $head[$h][1] = $langs->trans("Step")." 3"; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=4&datatoimport='.$datatoimport; + $head[$h][1] = $langs->trans("Step")." 4"; + $hselected=$h; + $h++; + + dol_fiche_head($head, $hselected, $langs->trans("NewImport")); + + print ''; + + // Module + print ''; + print ''; + + // Lot de donnees a importer + print ''; + print ''; + + // Nbre champs importes + print ''; + $list=''; + foreach($array_match_file_to_database as $code=>$label) + { + $list.=($list?',':''); + $list.=$langs->trans($objimport->array_import_fields[0][$code]); + } + print ''; + + print '
'.$langs->trans("Module").''; + //print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_module[0]->picto).' '; + print $objimport->array_import_module[0]->getName(); + print '
'.$langs->trans("DatasetToImport").''; + print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_icon[0]).' '; + print $objimport->array_import_label[0]; + print '
'.$langs->trans("ImportedFields").''.$list.'
'; + print '
'; + + print $langs->trans("NowClickToGenerateToBuildImportFile").'
'; + + // Liste des formats d'imports disponibles + $var=true; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $liste=$objmodelimport->liste_modeles($db); + foreach($liste as $key) + { + $var=!$var; + print ''; + print ''; + print ''; + } + print '
'.$langs->trans("AvailableFormats").''.$langs->trans("LibraryUsed").''.$langs->trans("LibraryVersion").'
'.img_picto_common($key,$objmodelimport->getPicto($key)).''.$objmodelimport->getDriverLabel($key).''.$objmodelimport->getLibLabel($key).''.$objmodelimport->getLibVersion($key).'
'; + + print ''; + + print ''; + if ($mesg) + { + print ''; + } + if ($sqlusedforimport && $user->admin) + { + print ''; + } + print '
'; + print $mesg; + print '
'; + print info_admin($langs->trans("SQLUsedForImport").':
'.$sqlusedforimport); + print '
'; + + print ''; + print '
'; + + if (! is_dir($conf->import->dir_temp)) create_exdir($conf->import->dir_temp); + + // Affiche liste des documents + // NB: La fonction show_documents rescanne les modules qd genallowed=1 + $formfile->show_documents('import','',$conf->import->dir_temp.'/'.$user->id,$_SERVER["PHP_SELF"].'?step=4&datatoimport='.$datatoimport,$liste,1,(! empty($_POST['model'])?$_POST['model']:'csv'),'',1); + + print ' 
'; + + // If external library PHPEXCELREADER is available + // and defined by PHPEXCELREADER constant. + if (file_exists(PHPEXCELREADER.'excelreader.php')) + { + // Test d'affichage du tableau excel et csv + //print '
'; + //require_once(DOL_DOCUMENT_ROOT.'/lib/viewfiles.lib.php'); + //viewExcelFileContent($conf->import->dir_temp.'/1/import_member_1.xls',5,3); + //viewCsvFileContent($conf->import->dir_temp.'/1/import_member_1.csv',5); + //print '
'; + } +} + + +print '
'; + + +$db->close(); + +llxFooter('$Date$ - $Revision$'); + + +/* + * Function to put the movable box of a source field + */ +function show_elem($fieldssource,$pos,$var,$key) +{ + global $langs,$bc; + + print "\n\n\n"; + print '
'."\n"; + + print ''."\n"; + print ''; + if (empty($key)) + { + print ''; + print ''; + } + elseif ($key == 'none') + { + print ''; + print ''; + } + else + { + //print ''; + print ''; + print ''; + } + print ''; + + print "
'; + print img_picto($langs->trans("MoveBox",$pos),'uparrow','class="boxhandle" style="cursor:move;"'); + print ''; + print $langs->trans("NoFields"); + print ''; + print ' '; + print ''; + print ' '; + print ''.img_file('','').''; + // 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 + print img_picto($langs->trans("MoveBox",$pos),'uparrow','class="boxhandle" style="cursor:move;"'); + print ''; + print $langs->trans("Field").' '.$key.': '; + print ''.$fieldssource[$key]['name'].' ('.$fieldssource[$key]['example1'].')'; + print '
\n"; + + print "
\n"; + print "\n\n"; +} + + +?>