Ajout possibilit d'enregistrer des modles d'exports afin de ne pas les selectionner chaque fois, fonctionnalit oprationnel mais reste la fignoler !!
This commit is contained in:
parent
83b82453a5
commit
9b966925e8
@ -41,6 +41,11 @@ class Export
|
||||
var $array_export_fields=array(); // Tableau des liste de champ+libellé à exporter
|
||||
var $array_export_alias=array(); // Tableau des liste de champ+alias à exporter
|
||||
|
||||
// Création des modéles d'export
|
||||
var $hexa;
|
||||
var $datatoexport;
|
||||
var $model_name;
|
||||
|
||||
|
||||
/**
|
||||
* \brief Constructeur de la classe
|
||||
@ -205,6 +210,76 @@ class Export
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Créé un modéle d'export
|
||||
* \param user Objet utilisateur qui crée
|
||||
*/
|
||||
function create($user)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
dolibarr_syslog("Export.class.php::create");
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'export_model (';
|
||||
$sql.= 'nom, type, field)';
|
||||
$sql.= " VALUES ('".$this->model_name."', '".$this->datatoexport."', '".$this->hexa."')";
|
||||
|
||||
dolibarr_syslog("Export.class.php::create sql=".$sql);
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Recupère de la base les caractéristiques d'un modele d'export
|
||||
* \param rowid id du modéle à récupérer
|
||||
*/
|
||||
function fetch($id)
|
||||
{
|
||||
$sql = 'SELECT em.rowid, em.field, em.nom, em.type';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'export_model as em';
|
||||
$sql.= ' WHERE em.rowid = '.$id;
|
||||
|
||||
dolibarr_syslog("Export::fetch sql=$sql");
|
||||
|
||||
$result = $this->db->query($sql) ;
|
||||
if ($result)
|
||||
{
|
||||
$obj = $this->db->fetch_object($result);
|
||||
if ($obj)
|
||||
{
|
||||
$this->id = $obj->rowid;
|
||||
$this->hexa = $obj->field;
|
||||
$this->model_name = $obj->nom;
|
||||
$this->datatoexport = $obj->type;
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error="Model not found";
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@ -51,14 +51,18 @@ $entitytolang=array(
|
||||
'member'=>'Member','member_type'=>'MemberType');
|
||||
|
||||
$array_selected=isset($_SESSION["export_selected_fields"])?$_SESSION["export_selected_fields"]:array();
|
||||
$datatoexport=isset($_GET["datatoexport"])?$_GET["datatoexport"]:'';
|
||||
$datatoexport=isset($_GET["datatoexport"])? $_GET["datatoexport"] : (isset($_POST["datatoexport"])?$_POST["datatoexport"]:'');
|
||||
$action=isset($_GET["action"]) ? $_GET["action"] : (isset($_POST["action"])?$_POST["action"]:'');
|
||||
$step=isset($_GET["step"])?$_GET["step"]:'1';
|
||||
$step=isset($_GET["step"])? $_GET["step"] : (isset($_POST["step"])?$_POST["step"]:1);
|
||||
$export_name=isset($_POST["export_name"])? $_POST["export_name"] : '';
|
||||
$hexa=isset($_POST["hexa"])? $_POST["hexa"] : '';
|
||||
$exportmodelid=isset($_POST["exportmodelid"])? $_POST["exportmodelid"] : '';
|
||||
|
||||
$objexport=new Export($db);
|
||||
$objexport->load_arrays($user,$datatoexport);
|
||||
|
||||
$objmodelexport=new ModeleExports();
|
||||
$html = new Form($db);
|
||||
|
||||
|
||||
/*
|
||||
@ -131,6 +135,26 @@ if ($action == 'builddoc')
|
||||
}
|
||||
}
|
||||
|
||||
if ($step == 2 && $action == 'add')
|
||||
{
|
||||
$objexport->model_name = $export_name;
|
||||
$objexport->datatoexport = $datatoexport;
|
||||
$objexport->hexa = $hexa;
|
||||
|
||||
$result = $objexport->create($user);
|
||||
}
|
||||
|
||||
if ($step == 2 && $action == 'select_model')
|
||||
{
|
||||
$_SESSION["export_selected_fields"]=array();
|
||||
$array_selected=array();
|
||||
$result = $objexport->fetch($exportmodelid);
|
||||
if ($result > 0)
|
||||
{
|
||||
$binaire = hexbin($objexport->hexa);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Affichage Pages des Etapes
|
||||
@ -229,6 +253,18 @@ if ($step == 2 && $datatoexport)
|
||||
// Lot de données à exporter
|
||||
print '<tr><td width="25%">'.$langs->trans("DatasetToExport").'</td>';
|
||||
print '<td>'.$objexport->array_export_label[0].'</td></tr>';
|
||||
|
||||
// Liste déroulante des modéles d'export
|
||||
print '<tr><td width="25%">'.$langs->trans("ExportModel").'</td>';
|
||||
print '<form action="export.php" method="post">';
|
||||
print '<input type="hidden" name="action" value="select_model">';
|
||||
print '<input type="hidden" name="step" value="2">';
|
||||
print '<input type="hidden" name="datatoexport" value="'.$datatoexport.'">';
|
||||
print '<td>';
|
||||
$html->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1);
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("Select").'">';
|
||||
print '</td></form></tr>';
|
||||
|
||||
|
||||
print '</table>';
|
||||
print '<br>';
|
||||
@ -255,22 +291,34 @@ if ($step == 2 && $datatoexport)
|
||||
# $this->array_export_alias[0]=$module->export_fields_alias[$r];
|
||||
|
||||
$var=true;
|
||||
$i = 0;
|
||||
|
||||
foreach($fieldsarray as $code=>$label)
|
||||
{
|
||||
$var=!$var;
|
||||
print "<tr $bc[$var]>";
|
||||
|
||||
$modelchoice = substr($binaire,$i,1);
|
||||
$i++;
|
||||
|
||||
$entity=$objexport->array_export_entities[0][$code];
|
||||
$entityicon=$entitytoicon[$entity]?$entitytoicon[$entity]:$entity;
|
||||
$entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$entity;
|
||||
|
||||
print '<td>'.img_object('',$entityicon).' '.$langs->trans($entitylang).'</td>';
|
||||
if (isset($array_selected[$code]) && $array_selected[$code])
|
||||
if (isset($array_selected[$code]) && $array_selected[$code] || $modelchoice == 1)
|
||||
{
|
||||
// Champ sélectionné
|
||||
print '<td> </td>';
|
||||
print '<td><a href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=unselectfield&field='.$code.'">'.img_left().'</a></td>';
|
||||
print '<td>'.$langs->trans($label).' ('.$code.')</td>';
|
||||
if ($modelchoice == 1)
|
||||
{
|
||||
$array_selected[$code]=sizeof($array_selected)+1;
|
||||
$_SESSION["export_selected_fields"]=$array_selected;
|
||||
}
|
||||
|
||||
$bit=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -278,11 +326,13 @@ if ($step == 2 && $datatoexport)
|
||||
print '<td>'.$langs->trans($label).' ('.$code.')</td>';
|
||||
print '<td><a href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field='.$code.'">'.img_right().'</a></td>';
|
||||
print '<td> </td>';
|
||||
$bit=0;
|
||||
}
|
||||
|
||||
print '</tr>';
|
||||
$save_select.=$bit;
|
||||
}
|
||||
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '</div>';
|
||||
@ -295,7 +345,18 @@ if ($step == 2 && $datatoexport)
|
||||
|
||||
if (sizeof($array_selected))
|
||||
{
|
||||
print '<form action="export.php" method="post">';
|
||||
print '<input type="hidden" name="action" value="add">';
|
||||
print '<input type="hidden" name="step" value="2">';
|
||||
print '<input type="hidden" name="datatoexport" value="'.$datatoexport.'">';
|
||||
print '<input type="hidden" name="hexa" value="'.$hexa.'">';
|
||||
print '<table class="noborder" width="100%"><tr>';
|
||||
print '<td><input name="export_name" size="20" value="">';
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
|
||||
print '</form>';
|
||||
print '<a class="butAction" href="export.php?step=3&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
|
||||
print '</td></tr>';
|
||||
print '</table>';
|
||||
}
|
||||
|
||||
print '</div>';
|
||||
|
||||
@ -2923,6 +2923,53 @@ class Form
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retourne la liste des modéles d'export
|
||||
* \param selected Id modéle présélectionné
|
||||
* \param htmlname Nom de la zone select
|
||||
* \param type Type des modéles recherchés
|
||||
* \param useempty Affiche valeur vide dans liste
|
||||
*/
|
||||
function select_export_model($selected='',$htmlname='exportmodelid',$type='',$useempty=0)
|
||||
{
|
||||
|
||||
$sql = "SELECT rowid, nom";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."export_model";
|
||||
$sql.= " WHERE type = '".$type."'";
|
||||
$sql.= " ORDER BY rowid";
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
print '<select class="flat" name="'.$htmlname.'">';
|
||||
if ($useempty)
|
||||
{
|
||||
print '<option value="-1"> </option>';
|
||||
}
|
||||
|
||||
$num = $this->db->num_rows($result);
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $this->db->fetch_object($result);
|
||||
if ($selected == $obj->rowid)
|
||||
{
|
||||
print '<option value="'.$obj->rowid.'" selected="true">';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<option value="'.$obj->rowid.'">';
|
||||
}
|
||||
print $obj->nom;
|
||||
print '</option>';
|
||||
$i++;
|
||||
}
|
||||
print "</select>";
|
||||
}
|
||||
else {
|
||||
dolibarr_print_error($this->db);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@ -2329,4 +2329,32 @@ function clean_html($StringHtml)
|
||||
return $CleanString;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Convertir de l'héxadécimal en binaire
|
||||
\param string bin
|
||||
\return string x
|
||||
*/
|
||||
function binhex($bin, $pad=false, $upper=false){
|
||||
$last = strlen($bin)-1;
|
||||
for($i=0; $i<=$last; $i++){ $x += $bin[$last-$i] * pow(2,$i); }
|
||||
$x = dechex($x);
|
||||
if($pad){ while(strlen($x) < intval(strlen($bin))/4){ $x = "0$x"; } }
|
||||
if($upper){ $x = strtoupper($x); }
|
||||
return $x;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Convertir de l'héxadécimal en binaire
|
||||
\param string hexa
|
||||
\return string bin
|
||||
*/
|
||||
function hexbin($hexa){
|
||||
$bin='';
|
||||
for($i=0;$i<strlen($hexa);$i++)
|
||||
{
|
||||
$bin.=str_pad(decbin(hexdec($hexa{$i})),4,'0',STR_PAD_LEFT);
|
||||
}
|
||||
return $bin;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@ -904,4 +904,14 @@ ALTER TABLE llx_document_model ADD UNIQUE uk_document_model (nom,type);
|
||||
|
||||
ALTER TABLE llx_chargesociales drop column date_pai;
|
||||
|
||||
UPDATE llx_facture SET type=0 where type=3;
|
||||
UPDATE llx_facture SET type=0 where type=3;
|
||||
|
||||
create table llx_export_model
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
label varchar(50) NOT NULL,
|
||||
type varchar(20) NOT NULL,
|
||||
field varchar(20) NOT NULL
|
||||
)type=innodb;
|
||||
|
||||
ALTER TABLE llx_export_model ADD UNIQUE uk_export_model (label);
|
||||
25
mysql/tables/llx_export_model.key.sql
Normal file
25
mysql/tables/llx_export_model.key.sql
Normal file
@ -0,0 +1,25 @@
|
||||
-- ===================================================================
|
||||
-- Copyright (C) 2007 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
-- Copyright (C) 2007 Regis Houssin <regis.houssin@cap-networks.com>
|
||||
--
|
||||
-- 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$
|
||||
--
|
||||
-- ===================================================================
|
||||
|
||||
|
||||
ALTER TABLE llx_export_model ADD UNIQUE uk_export_model (label);
|
||||
32
mysql/tables/llx_export_model.sql
Normal file
32
mysql/tables/llx_export_model.sql
Normal file
@ -0,0 +1,32 @@
|
||||
-- ===================================================================
|
||||
-- Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
-- Copyright (C) 2007 Regis Houssin <regis.houssin@cap-networks.com>
|
||||
--
|
||||
-- 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$
|
||||
--
|
||||
-- Liste des modeles de document disponibles
|
||||
--
|
||||
-- ===================================================================
|
||||
|
||||
create table llx_export_model
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
label varchar(50) NOT NULL,
|
||||
type varchar(20) NOT NULL,
|
||||
field varchar(20) NOT NULL
|
||||
)type=innodb;
|
||||
Loading…
Reference in New Issue
Block a user