2
0
forked from Wavyzz/dolibarr

Work on import module

This commit is contained in:
Laurent Destailleur
2009-05-19 18:11:47 +00:00
parent e02f581114
commit 75471b89ee
8 changed files with 144 additions and 117 deletions

View File

@@ -123,7 +123,7 @@ class FormFile
/**
* \brief Affiche la cartouche de la liste des documents d'une propale, facture...
* \param modulepart propal=propal, facture=facture, ...
* \param filename Sub dir to scan (vide si filedir deja complet)
* \param filename Sub dir to scan (use '' if filedir already complete)
* \param filedir Dir to scan
* \param urlsource Url of origin page (for return)
* \param genallowed Generation is allowed (1/0 or array of formats)
@@ -137,8 +137,6 @@ class FormFile
* \param param More param on http links
* \param title Title to show on top of form
* \param buttonlabel Label on submit button
* \remarks Le fichier de facture detaillee est de la forme
* REFFACTURE-XXXXXX-detail.pdf ou XXXXX est une forme diverse
* \return int <0 si ko, nbre de fichiers affiches si ok
*/
function show_documents($modulepart,$filename,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$modelliste=array(),$forcenomultilang=0,$iconPDF=0,$maxfilenamelength=28,$noform=0,$param='',$title='',$buttonlabel='')

View File

@@ -54,7 +54,6 @@ class Import
foreach($conf->file->dol_document_root as $dirroot)
{
$dir = $dirroot.'/includes/modules';
$handle=opendir($dir);
// Search available exports
$handle=@opendir($dir);

View File

@@ -364,16 +364,18 @@ if ($step == 2 && $datatoimport)
print '<form name="userfile" action="index.php" enctype="multipart/form-data" METHOD="POST">';
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='';
$fullpathfiletoimport='';
$var=true;
// Add help informations
print '<tr class="liste_titre"><td colspan="2">';
print '<tr class="liste_titre"><td colspan="4">';
print $langs->trans("FileMustHaveOneOfFollowingFormat");
print '</td></tr>';
$liste=$objmodelimport->liste_modeles($db);
@@ -382,44 +384,145 @@ if ($step == 2 && $datatoimport)
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td width="16">'.img_picto_common($key,$objmodelimport->getPicto($key)).'</td>';
print '<td>'.$objmodelimport->getDriverLabel($key).'</td>';
print '<td colspan="3">'.$objmodelimport->getDriverLabel($key).'</td>';
//print '<td>'.$objmodelimport->getLibLabel($key).'</td><td>'.$objmodelimport->getLibVersion($key).'</td>';
print '</tr>';
}
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("FileWithDataToImport").'</td></tr>';
print '<tr><td colspan="4">&nbsp;</td></tr>';
print '<tr><td colspan="4">'.$langs->trans("ChooseFileToImport").'</td></tr>';
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("FileWithDataToImport").'</td></tr>';
// Input file name box
$var=!$var;
print '<tr '.$bc[$var].'><td colspan="2">';
$var=false;
print '<tr '.$bc[$var].'><td colspan="4">';
print '<input type="file" name="userfile" size="20" maxlength="80"> &nbsp; &nbsp; ';
print '<input type="submit" class="button" value="'.$langs->trans("Upload").'" name="sendit">';
//print ' &nbsp; <input type="submit" value="'.$langs->trans("Cancel").'" name="cancelit"><br>';
print '<input type="submit" class="button" value="'.$langs->trans("AddFile").'" name="sendit">';
print '<input type="hidden" value="'.$step.'" name="step">';
print '<input type="hidden" value="'.$datatoimport.'" name="datatoimport">';
print "</tr>\n";
print '</table></form>';
if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
$imp = new DolibarrImport($db);
print "eee".$conf->import->dir_temp;
create_ext_dir($conf->import->dir_temp);
if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $imp->upload_dir . "/" . $_FILES['userfile']['name'],1) > 0)
create_exdir($conf->import->dir_temp);
$nowyearmonth=dol_date('YmdHis',dol_now(),0);
$fullpath=$conf->import->dir_temp . "/" . $nowyearmonth . '-'.$_FILES['userfile']['name'];
if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $fullpath,1) > 0)
{
$imp->ImportClients($imp->upload_dir . "/" . $_FILES['userfile']['name']);
print "Imports : ".$imp->nb_import."<br>";
print "Imports corrects : ".$imp->nb_import_ok."<br>";
print "Imports erreurs : ".$imp->nb_import_ko."<br>";
dol_syslog("File ".$fullpath." was added for import");
}
else
{
$mesg = "Files was not read";
$langs->load("errors");
$mesg = $langs->trans("ErrorFailedToSaveFile");
}
}
$dir = $conf->import->dir_temp;
// Search available imports
$handle=@opendir($dir);
if ($handle)
{
//print '<tr><td colspan="4">';
//print '<table class="noborder" width="100%">';
// Search available files to import
$i=0;
while (($file = readdir($handle))!==false)
{
if (eregi('^\.',$file)) continue;
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td width="16">'.img_mime($file).'</td>';
print '<td>'.$file.'</td>';
print '<td align="center">del</td>';
print '<td align="right">next</td>';
print '</tr>';
}
//print '</table></td></tr>';
}
print '</table></form>';
print '</div>';
if ($mesg) print $mesg;
}
if ($step == 3 && $datatoimport)
{
asort($array_selected);
llxHeader('',$langs->trans("NewImport"));
/*
* 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";
$hselected=$h;
$h++;
dol_fiche_head($head, $hselected, $langs->trans("NewImport"));
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>';
// Nbre champs importes
print '<tr><td width="25%">'.$langs->trans("ImportedFields").'</td>';
$list='';
foreach($array_selected as $code=>$value)
{
$list.=($list?',':'');
$list.=$langs->trans($objimport->array_import_fields[0][$code]);
}
print '<td>'.$list.'</td></tr>';
print '</table>';
print '<br>';
print $langs->trans("ChooseFieldsOrdersAndTitle").'<br>';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Entities").'</td>';
print '<td>'.$langs->trans("ImportedFields").'</td>';
print '<td align="right" colspan="2">'.$langs->trans("Position").'</td>';
print '<td>&nbsp;</td>';
print '<td>'.$langs->trans("FieldsTitle").'</td>';
print '</tr>';
// List deroulante des modeles d'import
/* print '<form action="import.php" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -497,94 +600,6 @@ if ($step == 2 && $datatoimport)
print '</table>';
*/
print '</div>';
if ($mesg) print $mesg;
/*
* Barre d'action
*
*/
print '<div class="tabsAction">';
if (sizeof($array_selected))
{
print '<a class="butAction" href="import.php?step=3&datatoimport='.$datatoimport.'">'.$langs->trans("NextStep").'</a>';
}
else
{
print '<a class="butActionRefused" href="#">'.$langs->trans("NextStep").'</a>';
}
print '</div>';
}
if ($step == 3 && $datatoimport)
{
asort($array_selected);
llxHeader('',$langs->trans("NewImport"));
/*
* 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";
$hselected=$h;
$h++;
dol_fiche_head($head, $hselected, $langs->trans("NewImport"));
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 donn<6E>es <20> 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>';
// Nbre champs import<72>s
print '<tr><td width="25%">'.$langs->trans("ImportedFields").'</td>';
$list='';
foreach($array_selected as $code=>$value)
{
$list.=($list?',':'');
$list.=$langs->trans($objimport->array_import_fields[0][$code]);
}
print '<td>'.$list.'</td></tr>';
print '</table>';
print '<br>';
print $langs->trans("ChooseFieldsOrdersAndTitle").'<br>';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Entities").'</td>';
print '<td>'.$langs->trans("ImportedFields").'</td>';
print '<td align="right" colspan="2">'.$langs->trans("Position").'</td>';
print '<td>&nbsp;</td>';
print '<td>'.$langs->trans("FieldsTitle").'</td>';
print '</tr>';
$var=true;
foreach($array_selected as $code=>$value)

View File

@@ -55,3 +55,4 @@ LineTotalVAT=Amount of VAT for line
TypeOfLineServiceOrProduct=Type of line (0=product, 1=service)
FileWithDataToImport=File with data to import
FileMustHaveOneOfFollowingFormat=File to import must have one of following format
ChooseFileToImport=Choose file to import...

View File

@@ -506,6 +506,8 @@ Informations=Informations
Page=Page
Notes=Notes
AddNewLine=Add new line
AddFile=Add file
ListOfFiles=List of available files
FreeZone=Free text
CloneMainAttributes=Clone object with its main attributes
PDFMerge=PDF Merge

View File

@@ -55,3 +55,4 @@ LineTotalVAT=Montant TVA de la ligne
TypeOfLineServiceOrProduct=Type de ligne (0=produit, 1=service)
FileWithDataToImport=Fichier contenant les données à importer
FileMustHaveOneOfFollowingFormat=Le fichier à importer doit avoir un des formats suivants
ChooseFileToImport=Choisissez le fichier à importer...

View File

@@ -506,6 +506,8 @@ Informations=Informations
Page=Page
Notes=Notes
AddNewLine=Ajout nouvelle ligne
AddFile=Ajouter fichier
ListOfFiles=Liste des fichiers disponibles
FreeZone=Zone libre
CloneMainAttributes=Cloner l'objet avec ces attributs principaux
PDFMerge=Fusion PDF

View File

@@ -37,7 +37,9 @@ if (! defined('ADODB_DATE_VERSION')) include_once(DOL_DOCUMENT_ROOT."/includes/a
/**
* \brief Return date for now
* \param mode 'gmt' => we return GMT timestamp, 'tzref' => we use the company timezone
* \param mode 'gmt' => we return GMT timestamp,
* 'tzref' => we use the company timezone
* 'tzuser' => we use the user timezone
* \return date Timestamp
*/
function dol_now($mode='tzref')
@@ -48,6 +50,11 @@ function dol_now($mode='tzref')
// TODO Should use the timezone of the company instead of timezone of server
$ret=mktime();
}
else if ($mode == 'tzuser')
{
// TODO Should use the timezone of the user instead of timezone of server
$ret=mktime();
}
return $ret;
}
@@ -559,6 +566,7 @@ function dolibarr_mktime($hour,$minute,$second,$month,$day,$year,$gm=0,$check=1)
* @param gm 1=Input informations are GMT values, otherwise local to user
* @param check 0=No check on parameters (Can use day 32, etc...)
* @return timestamp Date en timestamp, '' if error
* @see dol_date
*/
function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=0,$check=1)
{
@@ -614,9 +622,10 @@ function dolibarr_date($fmt, $timestamp, $gm=0)
/**
* \brief Returns formated date
* \param fmt Format (Exemple: 'Y-m-d H:i:s')
* \param timestamp Date. Exemple: Si timestamp=0 et gm=1, renvoi 01/01/1970 00:00:00
* \param timestamp Date. Example: If timestamp=0 and gm=1, return 01/01/1970 00:00:00
* \param gm 1 if timestamp was built with gmmktime, 0 if timestamp was build with mktime
* \return string Formated date
* \see dol_mktime
*/
function dol_date($fmt, $timestamp, $gm=0)
{