*
* 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.
*
* $Id$
* $Source$
*/
/**
\file htdocs/exports/export.php
\ingroup export
\brief Page d'edition d'un export
\version $Revision$
*/
require_once("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/exports/export.class.php");
require_once(DOL_DOCUMENT_ROOT.'/includes/modules/export/modules_export.php');
$langs->load("exports");
$user->getrights();
if (! $user->societe_id == 0)
accessforbidden();
$entitytoicon=array(
'invoice'=>'bill','invoice_line'=>'bill',
'member'=>'user', 'member_type'=>'group');
$entitytolang=array(
'user'=>'User',
'company'=>'Company','contact'=>'Contact',
'invoice'=>'Bill','invoice_line'=>'InvoiceLine',
'member'=>'Member','member_type'=>'MemberType');
$array_selected=isset($_SESSION["export_selected_fields"])?$_SESSION["export_selected_fields"]:array();
$datatoexport=isset($_GET["datatoexport"])?$_GET["datatoexport"]:'';
$action=isset($_GET["action"]) ? $_GET["action"] : (isset($_POST["action"])?$_POST["action"]:'');
$step=isset($_GET["step"])?$_GET["step"]:'1';
$objexport=new Export($db);
$objexport->load_arrays($user,$datatoexport);
$objmodelexport=new ModeleExports();
/*
* Actions
*/
if ($action=='selectfield')
{
$array_selected[$_GET["field"]]=sizeof($array_selected)+1;
//print_r($array_selected);
$_SESSION["export_selected_fields"]=$array_selected;
}
if ($action=='unselectfield')
{
unset($array_selected[$_GET["field"]]);
// Renumerote champs de array_selected (de 1 à nb_elements)
asort($array_selected);
$i=0;
$array_selected_save=$array_selected;
foreach($array_selected as $code=>$value)
{
$i++;
$array_selected[$code]=$i;
//print "x $code x $i y
";
}
$_SESSION["export_selected_fields"]=$array_selected;
}
if ($action=='downfield' || $action=='upfield')
{
$pos=$array_selected[$_GET["field"]];
if ($action=='downfield') $newpos=$pos+1;
if ($action=='upfield') $newpos=$pos-1;
// Recherche code avec qui switché
$newcode="";
foreach($array_selected as $code=>$value)
{
if ($value == $newpos)
{
$newcode=$code;
break;
}
}
//print("Switch pos=$pos (code=".$_GET["field"].") and newpos=$newpos (code=$newcode)");
if ($newcode) // Si newcode trouvé (prtoection contre resoumission de page
{
$array_selected[$_GET["field"]]=$newpos;
$array_selected[$newcode]=$pos;
$_SESSION["export_selected_fields"]=$array_selected;
}
}
if ($step == 1 || $action == 'cleanselect')
{
$_SESSION["export_selected_fields"]=array();
$array_selected=array();
}
if ($action == 'builddoc')
{
// Genère le fichier
$result=$objexport->build_file($user, $_POST["model"], $datatoexport, $array_selected);
if ($result < 0)
{
$mesg='
'.$objexport->error.'
';
}
else
{
// $mesg=''.$langs->trans("FileSuccessfulyBuilt").'
';
}
}
/*
* Affichage Pages des Etapes
*/
if ($step == 1 || ! $datatoexport)
{
llxHeader('',$langs->trans("NewExport"));
/*
* Affichage onglets
*/
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
$head[$h][1] = $langs->trans("Step")." 1";
$hselected=$h;
$h++;
/*
$head[$h][0] = '';
$head[$h][1] = $langs->trans("Step")." 2";
$h++;
*/
dolibarr_fiche_head($head, $hselected, $langs->trans("NewExport"));
print '';
print $langs->trans("SelectExportDataSet").'
';
print '
';
// Affiche les modules d'exports
print '';
print '';
print '| '.$langs->trans("Module").' | ';
print ''.$langs->trans("ExportableDatas").' | ';
print ' | ';
print '
';
$val=true;
if (sizeof($objexport->array_export_code))
{
foreach ($objexport->array_export_code as $key => $value)
{
$val=!$val;
print '| ';
print img_object($objexport->array_export_module[$key]->getName(),$objexport->array_export_module[$key]->picto).' ';
print $objexport->array_export_module[$key]->getName();
print ' | ';
print $objexport->array_export_label[$key];
print ' | ';
print ''.img_picto($langs->trans("NewExport"),'filenew').'';
print ' |
';
}
}
else
{
print '| '.$langs->trans("NoExportableData").' |
';
}
print '
';
print '
';
}
if ($step == 2 && $datatoexport)
{
llxHeader('',$langs->trans("NewExport"));
/*
* Affichage onglets
*/
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
$head[$h][1] = $langs->trans("Step")." 1";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
$head[$h][1] = $langs->trans("Step")." 2";
$hselected=$h;
$h++;
dolibarr_fiche_head($head, $hselected, $langs->trans("NewExport"));
print '';
// Module
print '| '.$langs->trans("Module").' | ';
print '';
print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
print $objexport->array_export_module[0]->getName();
print ' |
';
// Lot de données à exporter
print '| '.$langs->trans("DatasetToExport").' | ';
print ''.$objexport->array_export_label[0].' |
';
print '
';
print '
';
print $langs->trans("SelectExportFields").'
';
print '';
print '';
print '| '.$langs->trans("Entities").' | ';
print ''.$langs->trans("ExportableFields").' | ';
print ' | ';
print ''.$langs->trans("ExportedFields").' | ';
print '
';
// Champs exportables
$fieldsarray=$objexport->array_export_fields[0];
# $this->array_export_module[0]=$module;
# $this->array_export_code[0]=$module->export_code[$r];
# $this->array_export_label[0]=$module->export_label[$r];
# $this->array_export_sql[0]=$module->export_sql[$r];
# $this->array_export_fields[0]=$module->export_fields_array[$r];
# $this->array_export_entities[0]=$module->export_fields_entities[$r];
# $this->array_export_alias[0]=$module->export_fields_alias[$r];
$var=true;
foreach($fieldsarray as $code=>$label)
{
$var=!$var;
print "";
$entity=$objexport->array_export_entities[0][$code];
$entityicon=$entitytoicon[$entity]?$entitytoicon[$entity]:$entity;
$entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$entity;
print '| '.img_object('',$entityicon).' '.$langs->trans($entitylang).' | ';
if (isset($array_selected[$code]) && $array_selected[$code])
{
// Champ sélectionné
print ' | ';
print ''.img_left().' | ';
print ''.$langs->trans($label).' ('.$code.') | ';
}
else
{
// Champ non sélectionné
print ''.$langs->trans($label).' ('.$code.') | ';
print ''.img_right().' | ';
print ' | ';
}
print '
';
}
print '
';
print '';
/*
* Barre d'action
*
*/
print '';
}
if ($step == 3 && $datatoexport)
{
asort($array_selected);
llxHeader('',$langs->trans("NewExport"));
/*
* Affichage onglets
*/
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
$head[$h][1] = $langs->trans("Step")." 1";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
$head[$h][1] = $langs->trans("Step")." 2";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
$head[$h][1] = $langs->trans("Step")." 3";
$hselected=$h;
$h++;
dolibarr_fiche_head($head, $hselected, $langs->trans("NewExport"));
print '';
// Module
print '| '.$langs->trans("Module").' | ';
print '';
print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
print $objexport->array_export_module[0]->getName();
print ' |
';
// Lot de données à exporter
print '| '.$langs->trans("DatasetToExport").' | ';
print ''.$objexport->array_export_label[0].' |
';
// Nbre champs exportés
print '| '.$langs->trans("ExportedFields").' | ';
$list='';
foreach($array_selected as $code=>$value)
{
$list.=($list?',':'');
$list.=$langs->trans($objexport->array_export_fields[0][$code]);
}
print ''.$list.' |
';
print '
';
print '
';
print $langs->trans("ChooseFieldsOrdersAndTitle").'
';
print '';
print '';
print '| '.$langs->trans("Entities").' | ';
print ''.$langs->trans("ExportedFields").' | ';
print ''.$langs->trans("Position").' | ';
print ' | ';
print ''.$langs->trans("FieldsTitle").' | ';
print '
';
$var=true;
foreach($array_selected as $code=>$value)
{
$var=!$var;
print "";
$entity=$objexport->array_export_entities[0][$code];
$entityicon=$entitytoicon[$entity]?$entitytoicon[$entity]:$entity;
$entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$entity;
print '| '.img_object('',$entityicon).' '.$langs->trans($entitylang).' | ';
print ''.$langs->trans($objexport->array_export_fields[0][$code]).' ('.$code.') | ';
print '';
print $value.' ';
print ' | ';
if ($value < sizeof($array_selected)) print ''.img_down().'';
if ($value > 1) print ''.img_up().'';
print ' | ';
print ' | ';
print ''.$langs->trans($objexport->array_export_fields[0][$code]).' | ';
print '
';
}
print '
';
print '';
/*
* Barre d'action
*
*/
print '';
}
if ($step == 4 && $datatoexport)
{
asort($array_selected);
llxHeader('',$langs->trans("NewExport"));
/*
* Affichage onglets
*/
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
$head[$h][1] = $langs->trans("Step")." 1";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
$head[$h][1] = $langs->trans("Step")." 2";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
$head[$h][1] = $langs->trans("Step")." 3";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
$head[$h][1] = $langs->trans("Step")." 4";
$hselected=$h;
$h++;
dolibarr_fiche_head($head, $hselected, $langs->trans("NewExport"));
print '';
// Module
print '| '.$langs->trans("Module").' | ';
print '';
print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
print $objexport->array_export_module[0]->getName();
print ' |
';
// Lot de données à exporter
print '| '.$langs->trans("DatasetToExport").' | ';
print ''.$objexport->array_export_label[0].' |
';
// Nbre champs exportés
print '| '.$langs->trans("ExportedFields").' | ';
$list='';
foreach($array_selected as $code=>$label)
{
$list.=($list?',':'');
$list.=$langs->trans($objexport->array_export_fields[0][$code]);
}
print ''.$list.' |
';
print '
';
print '
';
print $langs->trans("NowClickToGenerateToBuildExportFile").'
';
// Liste des formats d'exports disponibles
$var=true;
print '';
print '';
print '| '.$langs->trans("AvailableFormats").' | ';
print ''.$langs->trans("LibraryUsed").' | ';
print ''.$langs->trans("LibraryVersion").' | ';
print '
';
$liste=$objmodelexport->liste_modeles($db);
foreach($liste as $key)
{
$var=!$var;
print '| '.$objmodelexport->getDriverLabel($key).' | '.$objmodelexport->getLibLabel($key).' | '.$objmodelexport->getLibVersion($key).' |
';
}
print '
';
print '';
if ($mesg) print $mesg;
$htmlform=new Form($db);
print '| ';
if (! is_dir($conf->export->dir_ouput)) create_exdir($conf->export->dir_ouput);
// Affiche liste des documents
// NB: La fonction show_documents rescanne les modules qd genallowed=1
$htmlform->show_documents('export','',$conf->export->dir_ouput.'/'.$user->id,$_SERVER["PHP_SELF"].'?step=4&datatoexport='.$datatoexport,$liste,1,'csv','',1);
print ' | |
';
print '
';
}
$db->close();
llxFooter('$Date$ - $Revision$');
?>