This commit is contained in:
Laurent Destailleur 2011-09-10 12:21:41 +00:00
parent b4c1cfa5bd
commit 5fac7191cf
6 changed files with 173 additions and 112 deletions

View File

@ -48,8 +48,9 @@ class Export
/**
* \brief Constructeur de la classe
* \param DB Handler acces base de donnees
* Constructor
*
* @param DoliDB $DB Database handler
*/
function Export($DB)
{
@ -58,9 +59,11 @@ class Export
/**
* \brief Load an exportable dataset
* \param user Object user making export
* \param filter Load a particular dataset only
* Load an exportable dataset
*
* @param User $user Object user making export
* @param string $filter Load a particular dataset only
* @return int <0 if KO, >0 if OK
*/
function load_arrays($user,$filter='')
{
@ -70,13 +73,13 @@ class Export
$var=true;
$i=0;
foreach ($conf->file->dol_document_root as $type => $dirroot)
{
$modulesdir[] = $dirroot . "/includes/modules/";
if ($type == 'alt')
{
{
$handle=@opendir($dirroot);
if (is_resource($handle))
{
@ -185,7 +188,7 @@ class Export
$this->array_export_sql_end[$i]=$module->export_sql_end[$r];
//$this->array_export_sql[$i]=$module->export_sql[$r];
dol_syslog("Export loaded for module ".$modulename." with index ".$i.", dataset=".$module->export_code[$r].", nb of fields=".sizeof($module->export_fields_code[$r]));
dol_syslog("Export loaded for module ".$modulename." with index ".$i.", dataset=".$module->export_code[$r].", nb of fields=".count($module->export_fields_code[$r]));
$i++;
// }
}
@ -196,15 +199,18 @@ class Export
closedir($handle);
}
}
return 1;
}
/**
* \brief Build the sql export request
* \param indice Indice of export
* \param array_selected Filter on array of fields to export
* \remarks Les tableaux array_export_xxx sont deja chargees pour le bon datatoexport
* aussi le parametre datatoexport est inutilise
* Build the sql export request.
* Arrays this->array_export_xxx are already loaded for required datatoexport
*
* @param int $indice Indice of export
* @param array $array_selected Filter on array of fields to export
* @return string SQL String. Example "select s.rowid as r_rowid, s.status as s_status from ..."
*/
function build_sql($indice,$array_selected)
{
@ -228,14 +234,16 @@ class Export
}
/**
* \brief Build export file
* \param user User that export
* \param model Export format
* \param datatoexport Name of dataset to export
* \param array_selected Filter on array of fields to export
* \param sqlquery = '' if set, transmit a sql query instead of building it from arrays
* \remarks Les tableaux array_export_xxx sont deja chargees pour le bon datatoexport
* aussi le parametre datatoexport est inutilise
* Build export file.
* File is built into directory $conf->export->dir_temp.'/'.$user->id
* Arrays this->array_export_xxx are already loaded for required datatoexport
*
* @param User $user User that export
* @param string $model Export format
* @param string $datatoexport Name of dataset to export
* @param array $array_selected Filter on array of fields to export
* @param string $sqlquery If set, transmit a sql query instead of building it from arrays
* @return int <0 if KO, >0 if OK
*/
function build_file($user, $model, $datatoexport, $array_selected, $sqlquery = '')
{
@ -317,6 +325,7 @@ class Export
// Close file
$objmodel->close_file();
return 1;
}
else
{
@ -334,8 +343,10 @@ class Export
}
/**
* \brief Save an export model in database
* \param user Object user that save
* Save an export model in database
*
* @param User $user Object user that save
* @return int <0 if KO, >0 if OK
*/
function create($user)
{
@ -367,8 +378,10 @@ class Export
}
/**
* \brief Load an export profil from database
* \param rowid id of profil to load
* Load an export profil from database
*
* @param int $id Id of profil to load
* @return int <0 if KO, >0 if OK
*/
function fetch($id)
{
@ -377,7 +390,7 @@ class Export
$sql.= ' WHERE em.rowid = '.$id;
dol_syslog("Export::fetch sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql) ;
$result = $this->db->query($sql);
if ($result)
{
$obj = $this->db->fetch_object($result);
@ -405,10 +418,11 @@ class Export
/**
* \brief Delete object in database
* \param user User that delete
* \param notrigger 0=launch triggers after, 1=disable triggers
* \return int <0 if KO, >0 if OK
* Delete object in database
*
* @param User $user User that delete
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
function delete($user, $notrigger=0)
{

View File

@ -798,9 +798,10 @@ llxFooter();
/**
* \brief Return table name of an alias. For this, we look for the "tablename as alias" in sql string.
* \param code Alias.Fieldname
* \param sqlmaxforexport SQL request to parse
* Return table name of an alias. For this, we look for the "tablename as alias" in sql string.
*
* @param code Alias.Fieldname
* @param sqlmaxforexport SQL request to parse
*/
function getablenamefromfield($code,$sqlmaxforexport)
{

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
@ -41,8 +41,9 @@ class Import
/**
* \brief Constructor
* \param DB Database handler
* Constructor
*
* @param DoliDB $DB Database handler
*/
function Import($DB)
{
@ -51,9 +52,11 @@ class Import
/**
* Load description of an importable dataset
* @param user Object user making import
* @param filter Load a particular dataset only
* Load description of an importable dataset
*
* @param User $user Object user making import
* @param string $filter Load a particular dataset only
* @return int <0 if KO, >0 if OK
*/
function load_arrays($user,$filter='')
{
@ -152,7 +155,7 @@ class Import
// Tableau des regles de conversion d'une valeur depuis une autre source (cle=champ, valeur=tableau des regles)
$this->array_import_convertvalue[$i]=$module->import_convertvalue_array[$r];
dol_syslog("Import loaded for module ".$modulename." with index ".$i.", dataset=".$module->import_code[$r].", nb of fields=".sizeof($module->import_fields_code[$r]));
dol_syslog("Import loaded for module ".$modulename." with index ".$i.", dataset=".$module->import_code[$r].", nb of fields=".count($module->import_fields_code[$r]));
$i++;
// }
}
@ -163,18 +166,20 @@ class Import
}
}
closedir($handle);
return 1;
}
/**
* \brief Lance la generation du fichier example
* \param user User qui exporte
* \param model Modele d'export
* \param $headerlinefields Array of values for first line of example file
* \param $contentlinevalues Array of values for content line of example file
* \remarks Les tableaux array_export_xxx sont deja chargees pour le bon datatoexport
* aussi le parametre datatoexport est inutilise
* Build an import example file.
* Arrays this->array_export_xxx are already loaded for required datatoexport
*
* @param User $user User qui exporte
* @param string $model Modele d'export
* @param string $headerlinefields Array of values for first line of example file
* @param string $contentlinevalues Array of values for content line of example file
* @return string <0 if KO, >0 if OK
*/
function build_example_file($user, $model, $headerlinefields, $contentlinevalues)
{
@ -210,8 +215,10 @@ class Import
}
/**
* \brief Save an export model in database
* \param user Object user that save
* Save an export model in database
*
* @param User $user Object user that save
* @return int <0 if KO, >0 if OK
*/
function create($user)
{
@ -248,8 +255,10 @@ class Import
}
/**
* \brief Load an import profil from database
* \param rowid id of profil to load
* Load an import profil from database
*
* @param int $id Id of profil to load
* @return int <0 if KO, >0 if OK
*/
function fetch($id)
{
@ -285,10 +294,11 @@ class Import
}
/**
* \brief Delete object in database
* \param user User that delete
* \param notrigger 0=launch triggers after, 1=disable triggers
* \return int <0 if KO, >0 if OK
* Delete object in database
*
* @param User $user User that delete
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
function delete($user, $notrigger=0)
{

View File

@ -45,8 +45,9 @@ class ExportCsv extends ModeleExports
/**
* \brief Constructeur
* \param db Handler acces base de donnee
* Constructor
*
* @param DoliDB $db Database handler
*/
function ExportCsv($db)
{
@ -108,9 +109,11 @@ class ExportCsv extends ModeleExports
/**
* \brief Open output file
* \param file Path of filename
* \return int <0 if KO, >=0 if OK
* Open output file
*
* @param string $file Path of filename to generate
* @param Translate $outputlangs Output language object
* @return int <0 if KO, >=0 if OK
*/
function open_file($file,$outputlangs)
{
@ -133,8 +136,10 @@ class ExportCsv extends ModeleExports
}
/**
* \brief Output header into file
* \param langs Output language
* Output header into file
*
* @param Translate $outputlangs Output language object
* @return int <0 if KO, >0 if OK
*/
function write_header($outputlangs)
{
@ -143,10 +148,12 @@ class ExportCsv extends ModeleExports
/**
* Output title line into file
* @param array_export_fields_label Array with list of label of fields
* @param array_selected_sorted Array with list of field to export
* @param outputlangs Object lang to translate values
* Output title line into file
*
* @param array $array_export_fields_label Array with list of label of fields
* @param array $array_selected_sorted Array with list of field to export
* @param Translate $outputlangs Object lang to translate values
* @return int <0 if KO, >0 if OK
*/
function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs)
{
@ -174,10 +181,12 @@ class ExportCsv extends ModeleExports
/**
* Output record line into file
* @param array_selected_sorted Array with list of field to export
* @param objp A record from a fetch with all fields from select
* @param outputlangs Object lang to translate values
* Output record line into file
*
* @param array $array_selected_sorted Array with list of field to export
* @param resource $objp A record from a fetch with all fields from select
* @param Translate $outputlangs Object lang to translate values
* @return int <0 if KO, >0 if OK
*/
function write_record($array_selected_sorted,$objp,$outputlangs)
{
@ -197,6 +206,7 @@ class ExportCsv extends ModeleExports
{
$alias=str_replace(array('.','-'),'_',$code);
if (empty($alias)) dol_print_error('','Bad value for field with key='.$code.'. Try to redefine export.');
$newvalue=$outputlangs->convToOutputCharset($objp->$alias);
// Translation newvalue
@ -216,8 +226,10 @@ class ExportCsv extends ModeleExports
}
/**
* \brief Output footer into file
* \param outputlangs Output language
* Output footer into file
*
* @param Translate $outputlangs Output language object
* @return int <0 if KO, >0 if OK
*/
function write_footer($outputlangs)
{
@ -225,7 +237,9 @@ class ExportCsv extends ModeleExports
}
/**
* \brief Close file handle
* Close file handle
*
* @return int <0 if KO, >0 if OK
*/
function close_file()
{
@ -235,8 +249,9 @@ class ExportCsv extends ModeleExports
/**
* Clean a cell to respect rules of CSV file cells
* @param newvalue String to clean
* @return string Value cleaned
*
* @param string $newvalue String to clean
* @return string Value cleaned
*/
function csv_clean($newvalue)
{

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2006-2009 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
@ -49,7 +49,7 @@ class ExportExcel extends ModeleExports
/**
* Constructor
*
* @param db databse handler
* @param DoliDB $db Database handler
*/
function ExportExcel($db)
{
@ -109,8 +109,9 @@ class ExportExcel extends ModeleExports
/**
* Open output file
*
* @param file Path of filename
* @return int <0 if KO, >=0 if OK
* @param string $file File name to generate
* @param Translate $outputlangs Output language object
* @return int <0 if KO, >=0 if OK
*/
function open_file($file,$outputlangs)
{
@ -158,7 +159,8 @@ class ExportExcel extends ModeleExports
/**
* Write header
*
* @param outputlangs Object lang to translate values
* @param Translate $outputlangs Object lang to translate values
* @return int <0 if KO, >0 if OK
*/
function write_header($outputlangs)
{
@ -169,11 +171,12 @@ class ExportExcel extends ModeleExports
/**
* Output title line into file
* Output title line into file
*
* @param array_export_fields_label Array with list of label of fields
* @param array_selected_sorted Array with list of field to export
* @param outputlangs Object lang to translate values
* @param array $array_export_fields_label Array with list of label of fields
* @param array $array_selected_sorted Array with list of field to export
* @param Translate $outputlangs Object lang to translate values
* @return int <0 if KO, >0 if OK
*/
function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs)
{
@ -216,11 +219,12 @@ class ExportExcel extends ModeleExports
}
/**
* Output record line into file
* Output record line into file
*
* @param array_selected_sorted Array with list of field to export
* @param objp A record from a fetch with all fields from select
* @param outputlangs Object lang to translate values
* @param array $array_selected_sorted Array with list of field to export
* @param resource $objp A record from a fetch with all fields from select
* @param Translate $outputlangs Object lang to translate values
* @return int <0 if KO, >0 if OK
*/
function write_record($array_selected_sorted,$objp,$outputlangs)
{
@ -312,7 +316,8 @@ class ExportExcel extends ModeleExports
/**
* Write footer
*
* @param outputlangs Object lang to translate values
* @param Translate $outputlangs Output language object
* @return int <0 if KO, >0 if OK
*/
function write_footer($outputlangs)
{
@ -322,6 +327,8 @@ class ExportExcel extends ModeleExports
/**
* Close Excel file
*
* @return int <0 if KO, >0 if OK
*/
function close_file()
{
@ -344,8 +351,8 @@ class ExportExcel extends ModeleExports
/**
* Clean a cell to respect rules of Excel file cells
*
* @param newvalue String to clean
* @return string Value cleaned
* @param string $newvalue String to clean
* @return string Value cleaned
*/
function excel_clean($newvalue)
{

View File

@ -45,8 +45,9 @@ class ExportTsv extends ModeleExports
/**
* \brief Constructeur
* \param db Database handler
* Constructor
*
* @param DoliDB $db Database handler
*/
function ExportTsv($db)
{
@ -102,9 +103,11 @@ class ExportTsv extends ModeleExports
/**
* \brief Open output file
* \param file Path of filename
* \return int <0 if KO, >=0 if OK
* Open output file
*
* @param string $file Path of filename to generate
* @param Translate $outputlangs Output language object
* @return int <0 if KO, >=0 if OK
*/
function open_file($file,$outputlangs)
{
@ -127,8 +130,10 @@ class ExportTsv extends ModeleExports
}
/**
* \brief Output header into file
* \param langs Output language
* Output header into file
*
* @param Translate $outputlangs Output language object
* @return int <0 if KO, >0 if OK
*/
function write_header($outputlangs)
{
@ -137,10 +142,12 @@ class ExportTsv extends ModeleExports
/**
* Output title line into file
* @param array_export_fields_label Array with list of label of fields
* @param array_selected_sorted Array with list of field to export
* @param outputlangs Object lang to translate values
* Output title line into file
*
* @param array $array_export_fields_label Array with list of label of fields
* @param array $array_selected_sorted Array with list of field to export
* @param Translate $outputlangs Object lang to translate values
* @return int <0 if KO, >0 if OK
*/
function write_title($array_export_fields_label,$array_selected_sorted,$outputlangs)
{
@ -157,10 +164,12 @@ class ExportTsv extends ModeleExports
/**
* Output record line into file
* @param array_selected_sorted Array with list of field to export
* @param objp A record from a fetch with all fields from select
* @param outputlangs Object lang to translate values
* Output record line into file
*
* @param array $array_selected_sorted Array with list of field to export
* @param resource $objp A record from a fetch with all fields from select
* @param Translate $outputlangs Object lang to translate values
* @return int <0 if KO, >0 if OK
*/
function write_record($array_selected_sorted,$objp,$outputlangs)
{
@ -187,8 +196,10 @@ class ExportTsv extends ModeleExports
}
/**
* \brief Output footer into file
* \param outputlangs Output language
* Output footer into file
*
* @param Translate $outputlangs Output language object
* @return int <0 if KO, >0 if OK
*/
function write_footer($outputlangs)
{
@ -196,7 +207,9 @@ class ExportTsv extends ModeleExports
}
/**
* \brief Close file handle
* Close file handle
*
* @return int <0 if KO, >0 if OK
*/
function close_file()
{
@ -206,8 +219,9 @@ class ExportTsv extends ModeleExports
/**
* Clean a cell to respect rules of TSV file cells
* @param newvalue String to clean
* @return string Value cleaned
*
* @param string $newvalue String to clean
* @return string Value cleaned
*/
function tsv_clean($newvalue)
{