Work on import module

This commit is contained in:
Laurent Destailleur 2009-05-20 11:09:56 +00:00
parent 841869ede5
commit c13477f860
5 changed files with 61 additions and 51 deletions

View File

@ -78,15 +78,22 @@ else $type=dol_mimetype($original_file);
// Define attachment (attachment=true to force choice popup 'open'/'save as')
$attachment = true;
// Documents
if (eregi('\.doc$',$original_file)) { $attachment = true; }
if (eregi('\.ppt$',$original_file)) { $attachment = true; }
if (eregi('\.xls$',$original_file)) { $attachment = true; }
if (eregi('\.pdf$',$original_file)) { $attachment = true; }
// Misc
if (eregi('\.sql$',$original_file)) { $attachment = true; }
if (eregi('\.html$',$original_file)) { $attachment = false; }
// Text files
if (eregi('\.csv$',$original_file)) { $attachment = true; }
if (eregi('\.tsv$',$original_file)) { $attachment = true; }
if (eregi('\.pdf$',$original_file)) { $attachment = true; }
if (eregi('\.xls$',$original_file)) { $attachment = true; }
// Images
if (eregi('\.jpg$',$original_file)) { $attachment = true; }
if (eregi('\.png$',$original_file)) { $attachment = true; }
if (eregi('\.tiff$',$original_file)) { $attachment = true; }
// Calendar
if (eregi('\.vcs$',$original_file)) { $attachment = true; }
if (eregi('\.ics$',$original_file)) { $attachment = true; }
if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false;
@ -364,7 +371,7 @@ if ($modulepart)
$sqlprotectagainstexternals = '';
}
// Wrapping pour les exports
// Wrapping for export module
if ($modulepart == 'export')
{
// Aucun test necessaire car on force le rep de doanwload sur
@ -374,6 +381,16 @@ if ($modulepart)
$sqlprotectagainstexternals = '';
}
// Wrapping for import module
if ($modulepart == 'import')
{
// Aucun test necessaire car on force le rep de doanwload sur
// le rep export qui est propre a l'utilisateur
$accessallowed=1;
$original_file=$conf->import->dir_temp.'/'.$original_file;
$sqlprotectagainstexternals = '';
}
// Wrapping pour l'editeur wysiwyg
if ($modulepart == 'editor')
{

View File

@ -376,7 +376,7 @@ class FormFile
print '</a>';
if (!$iconPDF) print '</td>';
// Affiche taille fichier
if (!$iconPDF) print '<td align="right">'.filesize($filedir."/".$file["name"]). ' bytes</td>';
if (!$iconPDF) print '<td align="right">'.dol_filesize($filedir."/".$file["name"]).'</td>';
// Affiche date fichier
if (!$iconPDF) print '<td align="right">'.dol_print_date(filemtime($filedir."/".$file["name"]),'dayhour').'</td>';
@ -489,4 +489,16 @@ class FormFile
}
/**
* Return size of a file with units
*
* @param $pathoffile
* @return string File size with units translated
*/
function dol_filesize($pathoffile)
{
global $langs;
return filesize($pathoffile). ' '.$langs->trans("Bytes");
}
?>

View File

@ -375,7 +375,7 @@ if ($step == 2 && $datatoimport)
$var=true;
// Add help informations
print '<tr class="liste_titre"><td colspan="4">';
print '<tr class="liste_titre"><td colspan="6">';
print $langs->trans("FileMustHaveOneOfFollowingFormat");
print '</td></tr>';
$liste=$objmodelimport->liste_modeles($db);
@ -384,20 +384,20 @@ if ($step == 2 && $datatoimport)
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td width="16">'.img_picto_common($key,$objmodelimport->getPicto($key)).'</td>';
print '<td colspan="3">'.$objmodelimport->getDriverLabel($key).'</td>';
print '<td colspan="5">'.$objmodelimport->getDriverLabel($key).'</td>';
//print '<td>'.$objmodelimport->getLibLabel($key).'</td><td>'.$objmodelimport->getLibVersion($key).'</td>';
print '</tr>';
}
print '<tr><td colspan="4">&nbsp;</td></tr>';
print '<tr><td colspan="6">&nbsp;</td></tr>';
print '<tr><td colspan="4">'.$langs->trans("ChooseFileToImport").'</td></tr>';
print '<tr><td colspan="6">'.$langs->trans("ChooseFileToImport").'</td></tr>';
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("FileWithDataToImport").'</td></tr>';
print '<tr class="liste_titre"><td colspan="6">'.$langs->trans("FileWithDataToImport").'</td></tr>';
// Input file name box
$var=false;
print '<tr '.$bc[$var].'><td colspan="4">';
print '<tr '.$bc[$var].'><td colspan="6">';
print '<input type="file" name="userfile" size="20" maxlength="80"> &nbsp; &nbsp; ';
print '<input type="submit" class="button" value="'.$langs->trans("AddFile").'" name="sendit">';
print '<input type="hidden" value="'.$step.'" name="step">';
@ -436,12 +436,25 @@ if ($step == 2 && $datatoimport)
{
if (eregi('^\.',$file)) continue;
$modulepart='import';
$urlsource=$_SERVER["PHP_SELF"].'?step='.$step.'&datatoimport='.$datatoimport;
$relativepath=$file;
$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>';
// Affiche taille fichier
print '<td align="right">'.dol_filesize($dir.'/'.$file).'</td>';
// Affiche date fichier
print '<td align="right">'.dol_print_date(filemtime($dir.'/'.$file),'dayhour').'</td>';
// Del button
print '<td align="right"><a href="'.DOL_URL_ROOT.'/document.php?action=remove_file&amp;modulepart='.$modulepart.'&amp;file='.urlencode($relativepath);
print '&amp;urlsource='.urlencode($urlsource);
print '">'.img_delete().'</a></td>';
// Action button
print '<td align="right">';
print '<a href="'.DOL_URL_ROOT.'/imports/import.php?step=3&datatoimport='.$datatoimport.'&filetoimport='.urlencode($relativepath).'">'.img_picto($langs->trans("NewImport"),'filenew').'</a>';
print '</td>';
print '</tr>';
}
//print '</table></td></tr>';
@ -499,57 +512,24 @@ if ($step == 3 && $datatoimport)
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 '<tr><td width="25%">'.$langs->trans("FileToImport").'</td>';
print '<td>'.$_GET["filetoimport"].'</td></tr>';
print '</table>';
print '<br>';
print $langs->trans("ChooseFieldsOrdersAndTitle").'<br>';
print $langs->trans("SelectImportFields");
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("FieldsTitle").'</td>';
print '<td>&nbsp;</td>';
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'].'">';
print '<input type="hidden" name="action" value="select_model">';
print '<input type="hidden" name="step" value="2">';
print '<input type="hidden" name="datatoimport" value="'.$datatoimport.'">';
print '<table><tr><td>';
print $langs->trans("SelectImportFields");
print '</td><td>';
$htmlother->select_import_model($importmodelid,'importmodelid',$datatoimport,1);
print '<input type="submit" class="button" value="'.$langs->trans("Select").'">';
print '</td></tr></table>';
print '</form>';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Entities").'</td>';
print '<td>'.$langs->trans("ImportableFields").'</td>';
print '<td width="12" align="middle">';
print '<a title='.$langs->trans("All").' alt='.$langs->trans("All").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoimport='.$datatoimport.'&action=selectfield&field=all">'.$langs->trans("All")."</a>";
print '/';
print '<a title='.$langs->trans("None").' alt='.$langs->trans("None").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoimport='.$datatoimport.'&action=unselectfield&field=all">'.$langs->trans("None")."</a>";
print '</td>';
print '<td width="44%">'.$langs->trans("ImportedFields").'</td>';
print '</tr>';
// Champs importables
$fieldsarray=$objimport->array_import_fields[0];
@ -598,7 +578,6 @@ if ($step == 3 && $datatoimport)
}
print '</table>';
*/
$var=true;

View File

@ -54,5 +54,6 @@ LineTotalTTC=Amount with tax for line
LineTotalVAT=Amount of VAT for line
TypeOfLineServiceOrProduct=Type of line (0=product, 1=service)
FileWithDataToImport=File with data to import
FileToImport=File to import
FileMustHaveOneOfFollowingFormat=File to import must have one of following format
ChooseFileToImport=Choose file to import...

View File

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