Add first files for import module
This commit is contained in:
parent
3c7142bbcc
commit
c85b9cb017
@ -1,183 +0,0 @@
|
||||
<?php
|
||||
/* Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/admin/import/dolibarrimport.class.php
|
||||
* \ingroup import
|
||||
* \brief Fichier de la classe des imports
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* \class DolibarrImport
|
||||
* \brief Classe permettant la gestion des imports
|
||||
*/
|
||||
class DolibarrImport
|
||||
{
|
||||
/**
|
||||
* \brief Constructeur de la classe
|
||||
* \param DB Handler accès base de données
|
||||
*/
|
||||
function DolibarrImport($DB)
|
||||
{
|
||||
$this->db=$DB;
|
||||
}
|
||||
/*
|
||||
\brief Importe un fichier clients
|
||||
*/
|
||||
function ImportClients($file)
|
||||
{
|
||||
$this->nb_import_ok = 0;
|
||||
$this->nb_import_ko = 0;
|
||||
$this->nb_import = 0;
|
||||
|
||||
dol_syslog("DolibarrImport::ImportClients($file)", LOG_DEBUG);
|
||||
|
||||
$this->ReadFile($file);
|
||||
|
||||
foreach ($this->lines as $this->line)
|
||||
{
|
||||
$societe = new Societe($this->db);
|
||||
|
||||
$this->SetInfosTiers($societe);
|
||||
|
||||
$societe->client = 1;
|
||||
$societe->tva_assuj = $this->line[12];
|
||||
$societe->code_client = $this->line[13];
|
||||
$societe->tva_intra = $this->line[14];
|
||||
|
||||
$this->nb_import++;
|
||||
|
||||
if ( $societe->create($user) == 0)
|
||||
{
|
||||
dol_syslog("DolibarrImport::ImportClients ".$societe->nom." SUCCESS", LOG_DEBUG);
|
||||
$this->nb_import_ok++;
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_syslog("DolibarrImport::ImportClients ".$societe->nom." ERROR", LOG_ERR);
|
||||
$this->nb_import_ko++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function SetInfosTiers(&$obj)
|
||||
{
|
||||
$obj->nom = $this->line[0];
|
||||
$obj->adresse = $this->line[1];
|
||||
|
||||
if (strlen(trim($this->line[2])) > 0)
|
||||
$obj->adresse .= "\n". trim($this->line[2]);
|
||||
|
||||
if (strlen(trim($this->line[3])) > 0)
|
||||
$obj->adresse .= "\n". trim($this->line[3]);
|
||||
|
||||
$obj->cp = $this->line[4];
|
||||
$obj->ville = $this->line[5];
|
||||
$obj->tel = $this->line[6];
|
||||
$obj->fax = $this->line[7];
|
||||
$obj->email = $this->line[8];
|
||||
$obj->url = $this->line[9];
|
||||
$obj->siren = $this->line[10];
|
||||
$obj->siret = $this->line[11];
|
||||
}
|
||||
|
||||
|
||||
function ReadFile($file)
|
||||
{
|
||||
$this->errno = 0;
|
||||
|
||||
if (is_readable($file))
|
||||
{
|
||||
dol_syslog("DolibarrImport::ReadFile Lecture du fichier $file", LOG_DEBUG);
|
||||
|
||||
$line = 0;
|
||||
$hf = fopen ($file, "r");
|
||||
$line = 0;
|
||||
$i=0;
|
||||
|
||||
$this->lines = array();
|
||||
|
||||
|
||||
while (!feof($hf) )
|
||||
{
|
||||
$cont = fgets($hf, 1024);
|
||||
|
||||
if (strlen(trim($cont)) > 0)
|
||||
{
|
||||
$this->lines[$i] = explode(";", $cont);
|
||||
}
|
||||
$i++;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errno = -2;
|
||||
}
|
||||
|
||||
return $errno;
|
||||
}
|
||||
|
||||
/*
|
||||
\brief Cree le repertoire de backup
|
||||
*/
|
||||
function CreateBackupDir()
|
||||
{
|
||||
$time = time();
|
||||
|
||||
$upload_dir = DOL_DATA_ROOT."/import/";
|
||||
|
||||
if (! is_dir($upload_dir))
|
||||
{
|
||||
umask(0);
|
||||
if (! mkdir($upload_dir, 0755))
|
||||
{
|
||||
dol_syslog("DolibarrImport::ReadFile Impossible de créer $upload_dir",LOG_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
$upload_dir = DOL_DATA_ROOT."/import/".strftime("%Y",$time);
|
||||
|
||||
if (! is_dir($upload_dir))
|
||||
{
|
||||
umask(0);
|
||||
if (! mkdir($upload_dir, 0755))
|
||||
{
|
||||
dol_syslog("DolibarrImport::ReadFile Impossible de créer $upload_dir",LOG_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
$upload_dir = DOL_DATA_ROOT."/import/".strftime("%Y",$time)."/".strftime("%d-%m-%Y",$time);
|
||||
|
||||
if (! is_dir($upload_dir))
|
||||
{
|
||||
umask(0);
|
||||
if (! mkdir($upload_dir, 0755))
|
||||
{
|
||||
dol_syslog("DolibarrImport::ReadFile Impossible de créer $upload_dir",LOG_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
$this->upload_dir = DOL_DATA_ROOT."/import/".strftime("%Y",$time)."/".strftime("%d-%m-%Y",$time);
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,87 +0,0 @@
|
||||
<?php
|
||||
/* Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
*
|
||||
* 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/admin/index.php
|
||||
\brief Page d'import de donnee
|
||||
\version $Revision$
|
||||
*/
|
||||
|
||||
require("./pre.inc.php");
|
||||
|
||||
require(DOL_DOCUMENT_ROOT.'/admin/import/dolibarrimport.class.php');
|
||||
|
||||
$langs->load("admin");
|
||||
$langs->load("companies");
|
||||
|
||||
if (!$user->admin)
|
||||
accessforbidden();
|
||||
|
||||
/*
|
||||
* Affichage page
|
||||
*/
|
||||
llxHeader();
|
||||
|
||||
$form = new Form($db);
|
||||
|
||||
print_fiche_titre($langs->trans("ImportArea"),'','setup');
|
||||
|
||||
print "<br>";
|
||||
|
||||
print '<form name="userfile" action="index.php" enctype="multipart/form-data" METHOD="POST">';
|
||||
print '<input type="hidden" name="max_file_size" value="'.$conf->maxfilesize.'">';
|
||||
|
||||
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
|
||||
print '<tr class="liste_titre"><td>Importer un fichier clients</td></tr>';
|
||||
|
||||
print "<tr $bc[1]><td>";
|
||||
print '<input type="file" name="userfile" size="20" maxlength="80"><br />';
|
||||
print '<input type="submit" value="'.$langs->trans("Upload").'" name="sendit"> ';
|
||||
print '<input type="submit" value="'.$langs->trans("Cancel").'" name="cancelit"><br>';
|
||||
|
||||
print "</tr>\n";
|
||||
print '</table></form>';
|
||||
|
||||
|
||||
if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
|
||||
{
|
||||
$imp = new DolibarrImport($db);
|
||||
$imp->CreateBackupDir();
|
||||
if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $imp->upload_dir . "/" . $_FILES['userfile']['name'],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>";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg = "Le fichier n'a pas été téléchargé";
|
||||
}
|
||||
}
|
||||
|
||||
$db->close();
|
||||
|
||||
llxFooter('$Date$ - $Revision$');
|
||||
?>
|
||||
@ -1,75 +0,0 @@
|
||||
<?php
|
||||
/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005 Simon Tosser <simon@kornog-computing.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$
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/admin/pre.inc.php
|
||||
\brief Fichier gestionnaire du menu de gauche de l'espace configuration
|
||||
\version $Revision$
|
||||
*/
|
||||
|
||||
require("../../main.inc.php");
|
||||
|
||||
$langs->load("admin");
|
||||
|
||||
|
||||
function llxHeader($head = "", $title="", $help_url='')
|
||||
{
|
||||
global $user, $langs;
|
||||
|
||||
top_menu($head);
|
||||
|
||||
$menu = new Menu();
|
||||
$langs->load("admin");
|
||||
$langs->load("users");
|
||||
|
||||
$menu->add(DOL_URL_ROOT."/admin/company.php", $langs->trans("MenuCompanySetup"));
|
||||
|
||||
$menu->add(DOL_URL_ROOT."/admin/modules.php", $langs->trans("Modules"));
|
||||
|
||||
$menu->add(DOL_URL_ROOT."/admin/menus.php", $langs->trans("Menus"));
|
||||
|
||||
$menu->add(DOL_URL_ROOT."/admin/ihm.php", $langs->trans("GUISetup"));
|
||||
|
||||
$menu->add(DOL_URL_ROOT."/admin/boxes.php", $langs->trans("Boxes"));
|
||||
|
||||
$menu->add(DOL_URL_ROOT."/admin/delais.php",$langs->trans("Alerts"));
|
||||
|
||||
$menu->add(DOL_URL_ROOT."/admin/triggers.php", $langs->trans("Triggers"));
|
||||
|
||||
$menu->add(DOL_URL_ROOT."/admin/import/", $langs->trans("Imports"));
|
||||
|
||||
$menu->add(DOL_URL_ROOT."/admin/perms.php", $langs->trans("Security"));
|
||||
|
||||
$langs->load("users");
|
||||
$menu->add(DOL_URL_ROOT."/user/home.php", $langs->trans("MenuUsersAndGroups"));
|
||||
|
||||
$menu->add(DOL_URL_ROOT."/admin/dict.php", $langs->trans("DictionnarySetup"));
|
||||
|
||||
$menu->add(DOL_URL_ROOT."/admin/const.php", $langs->trans("OtherSetup"));
|
||||
|
||||
$menu->add(DOL_URL_ROOT."/admin/system/", $langs->trans("System"));
|
||||
|
||||
left_menu($menu->liste, $help_url);
|
||||
}
|
||||
|
||||
?>
|
||||
@ -62,6 +62,7 @@ class Commande extends CommonObject
|
||||
var $adresse_livraison_id;
|
||||
var $adresse;
|
||||
var $date; // Date commande
|
||||
var $date_commande; // Date commande (deprecated)
|
||||
var $date_livraison; // Date livraison souhaitee
|
||||
var $fk_remise_except;
|
||||
var $remise_percent;
|
||||
@ -71,6 +72,9 @@ class Commande extends CommonObject
|
||||
var $remise_absolue;
|
||||
var $modelpdf;
|
||||
var $info_bits;
|
||||
var $source; // Origin of order
|
||||
|
||||
var $user_author_id;
|
||||
|
||||
var $lines = array();
|
||||
|
||||
@ -468,19 +472,19 @@ class Commande extends CommonObject
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Cree la commande
|
||||
* \param user Objet utilisateur qui cree
|
||||
* \brief Create order
|
||||
* \param user Objet utilisateur qui cree
|
||||
*/
|
||||
function create($user)
|
||||
{
|
||||
global $conf,$langs,$mysoc;
|
||||
|
||||
// Nettoyage parametres
|
||||
// Clean parameters
|
||||
$this->brouillon = 1; // On positionne en mode brouillon la commande
|
||||
|
||||
dol_syslog("Commande::create");
|
||||
|
||||
// Verification parametres
|
||||
// Check parameters
|
||||
if (! empty($conf->global->COMMANDE_REQUIRE_SOURCE) && $this->source < 0)
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Source"));
|
||||
@ -505,9 +509,9 @@ class Commande extends CommonObject
|
||||
$sql.= ' ref, fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note, note_public, ref_client,';
|
||||
$sql.= ' model_pdf, fk_cond_reglement, fk_mode_reglement, date_livraison, fk_adresse_livraison,';
|
||||
$sql.= ' remise_absolue, remise_percent)';
|
||||
$sql.= " VALUES ('".$this->ref."',".$this->socid.", ".$this->db->idate(mktime()).", ".$user->id.', '.$this->projetid.',';
|
||||
$sql.= " VALUES ('(PROV)',".$this->socid.", ".$this->db->idate(gmmktime()).", ".$user->id.', '.$this->projetid.',';
|
||||
$sql.= ' '.$this->db->idate($this->date_commande).',';
|
||||
$sql.= ' '.($this->source>=0?$this->source:'null').', ';
|
||||
$sql.= ' '.($this->source>=0 && $this->source != '' ?$this->source:'null').', ';
|
||||
$sql.= " '".addslashes($this->note)."', ";
|
||||
$sql.= " '".addslashes($this->note_public)."', ";
|
||||
$sql.= " '".addslashes($this->ref_client)."', '".$this->modelpdf."', '".$this->cond_reglement_id."', '".$this->mode_reglement_id."',";
|
||||
@ -523,13 +527,13 @@ class Commande extends CommonObject
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'commande');
|
||||
|
||||
if ($this->id)
|
||||
{
|
||||
/*
|
||||
* Insertion du detail des produits dans la base
|
||||
*/
|
||||
for ($i = 0 ; $i < sizeof($this->lines) ; $i++)
|
||||
{
|
||||
$resql = $this->addline(
|
||||
{
|
||||
/*
|
||||
* Insertion du detail des produits dans la base
|
||||
*/
|
||||
for ($i = 0 ; $i < sizeof($this->lines) ; $i++)
|
||||
{
|
||||
$resql = $this->addline(
|
||||
$this->id,
|
||||
$this->lines[$i]->desc,
|
||||
$this->lines[$i]->subprice,
|
||||
@ -537,73 +541,69 @@ class Commande extends CommonObject
|
||||
$this->lines[$i]->tva_tx,
|
||||
$this->lines[$i]->fk_product,
|
||||
$this->lines[$i]->remise_percent,
|
||||
$this->lines[$i]->fk_remise_except,
|
||||
$this->lines[$i]->info_bits,
|
||||
0,
|
||||
$this->lines[$i]->fk_remise_except,
|
||||
'HT',
|
||||
0,
|
||||
// Added by Matelli (http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html)
|
||||
// Add start and end dates to the new line
|
||||
$this->lines[$i]->date_start,
|
||||
$this->lines[$i]->date_end,
|
||||
$this->lines[$i]->type
|
||||
$this->lines[$i]->product_type
|
||||
);
|
||||
|
||||
if ($resql < 0)
|
||||
{
|
||||
$this->error=$this->db->error;
|
||||
dol_print_error($this->db);
|
||||
break;
|
||||
$this->error=$this->db->error;
|
||||
dol_print_error($this->db);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Mise a jour ref
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id;
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
if ($this->id && $this->propale_id)
|
||||
{
|
||||
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'co_pr (fk_commande, fk_propale) VALUES ('.$this->id.','.$this->propale_id.')';
|
||||
$this->db->query($sql);
|
||||
// Mise a jour ref
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id;
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
if ($this->id && $this->propale_id)
|
||||
{
|
||||
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'co_pr (fk_commande, fk_propale) VALUES ('.$this->id.','.$this->propale_id.')';
|
||||
$this->db->query($sql);
|
||||
|
||||
// On recupere les differents contact interne et externe
|
||||
$prop = New Propal($this->db, $this->socid, $this->propale_id);
|
||||
// On recupere les differents contact interne et externe
|
||||
$prop = New Propal($this->db, $this->socid, $this->propale_id);
|
||||
|
||||
// On recupere le commercial suivi propale
|
||||
$this->userid = $prop->getIdcontact('internal', 'SALESREPFOLL');
|
||||
// On recupere le commercial suivi propale
|
||||
$this->userid = $prop->getIdcontact('internal', 'SALESREPFOLL');
|
||||
|
||||
if ($this->userid)
|
||||
{
|
||||
//On passe le commercial suivi propale en commercial suivi commande
|
||||
$this->add_contact($this->userid[0], 'SALESREPFOLL', 'internal');
|
||||
}
|
||||
if ($this->userid)
|
||||
{
|
||||
//On passe le commercial suivi propale en commercial suivi commande
|
||||
$this->add_contact($this->userid[0], 'SALESREPFOLL', 'internal');
|
||||
}
|
||||
|
||||
// On recupere le contact client suivi propale
|
||||
$this->contactid = $prop->getIdcontact('external', 'CUSTOMER');
|
||||
// On recupere le contact client suivi propale
|
||||
$this->contactid = $prop->getIdcontact('external', 'CUSTOMER');
|
||||
|
||||
if ($this->contactid)
|
||||
{
|
||||
//On passe le contact client suivi propale en contact client suivi commande
|
||||
$this->add_contact($this->contactid[0], 'CUSTOMER', 'external');
|
||||
}
|
||||
}
|
||||
if ($this->contactid)
|
||||
{
|
||||
//On passe le contact client suivi propale en contact client suivi commande
|
||||
$this->add_contact($this->contactid[0], 'CUSTOMER', 'external');
|
||||
}
|
||||
}
|
||||
|
||||
// Appel des triggers
|
||||
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||
$interface=new Interfaces($this->db);
|
||||
$result=$interface->run_triggers('ORDER_CREATE',$this,$user,$langs,$conf);
|
||||
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
||||
// Fin appel triggers
|
||||
// Appel des triggers
|
||||
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||
$interface=new Interfaces($this->db);
|
||||
$result=$interface->run_triggers('ORDER_CREATE',$this,$user,$langs,$conf);
|
||||
if ($result < 0) { $error++; $this->errors=$interface->errors; }
|
||||
// Fin appel triggers
|
||||
|
||||
$this->db->commit();
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
$this->db->commit();
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -614,6 +614,65 @@ class Commande extends CommonObject
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Load an object from its id and create a new one in database
|
||||
* \param fromid Id of object to clone
|
||||
* \param invertdetail Reverse sign of amounts for lines
|
||||
* \return int New id of clone
|
||||
*/
|
||||
function createFromClone($fromid,$invertdetail=0)
|
||||
{
|
||||
global $user,$langs;
|
||||
|
||||
$error=0;
|
||||
|
||||
$object=new Commande($this->db);
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
// Load source object
|
||||
$object->fetch($fromid);
|
||||
$object->id=0;
|
||||
$object->statut=0;
|
||||
|
||||
// Clear fields
|
||||
$object->user_author_id = $user->id;
|
||||
$object->user_valid = '';
|
||||
$object->date_creation = '';
|
||||
$object->date_validation = '';
|
||||
$object->ref_client = '';
|
||||
|
||||
// Create clone
|
||||
$result=$object->create($user);
|
||||
|
||||
// Other options
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error=$object->error;
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// End
|
||||
if (! $error)
|
||||
{
|
||||
$this->db->commit();
|
||||
return $object->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Add a line
|
||||
* \param commandeid Id de la commande
|
||||
@ -624,7 +683,7 @@ class Commande extends CommonObject
|
||||
* \param fk_product Id du produit/service predefini
|
||||
* \param remise_percent Pourcentage de remise de la ligne
|
||||
* \param info_bits Bits de type de lignes
|
||||
* \param fk_remise_exscept Id remise
|
||||
* \param fk_remise_except Id remise
|
||||
* \param price_base_type HT or TTC
|
||||
* \param pu_ttc Prix unitaire TTC
|
||||
* \param date_start Start date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html)
|
||||
@ -640,7 +699,7 @@ class Commande extends CommonObject
|
||||
function addline($commandeid, $desc, $pu_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $info_bits=0, $fk_remise_except=0, $price_base_type='HT', $pu_ttc=0, $date_start='', $date_end='', $type=0)
|
||||
{
|
||||
dol_syslog("Commande::addline commandeid=$commandeid, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_percent=$remise_percent, info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, date_start=$date_start, date_end=$date_end, type=$type", LOG_DEBUG);
|
||||
|
||||
|
||||
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
|
||||
|
||||
// Clean parameters
|
||||
@ -704,7 +763,7 @@ class Commande extends CommonObject
|
||||
$ligne->total_tva=$total_tva;
|
||||
$ligne->total_ttc=$total_ttc;
|
||||
$ligne->product_type=$type;
|
||||
|
||||
|
||||
// \TODO Ne plus utiliser
|
||||
$ligne->price=$price;
|
||||
$ligne->remise=$remise;
|
||||
@ -856,6 +915,7 @@ class Commande extends CommonObject
|
||||
$this->total_tva = $obj->total_tva;
|
||||
$this->total_ttc = $obj->total_ttc;
|
||||
$this->date = $obj->date_commande;
|
||||
$this->date_commande = $obj->date_commande;
|
||||
$this->remise = $obj->remise;
|
||||
$this->remise_percent = $obj->remise_percent;
|
||||
$this->remise_absolue = $obj->remise_absolue;
|
||||
@ -1004,9 +1064,10 @@ class Commande extends CommonObject
|
||||
*/
|
||||
function fetch_lines($only_product=0)
|
||||
{
|
||||
$this->lignes=array();
|
||||
|
||||
$sql = 'SELECT l.rowid, l.fk_product, l.fk_commande, l.description, l.price, l.qty, l.tva_tx,';
|
||||
$this->lignes=array(); // deprecated
|
||||
$this->lines=array();
|
||||
|
||||
$sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.fk_commande, l.description, l.price, l.qty, l.tva_tx,';
|
||||
$sql.= ' l.fk_remise_except, l.remise_percent, l.subprice, l.marge_tx, l.marque_tx, l.rang, l.info_bits,';
|
||||
$sql.= ' l.total_ht, l.total_ttc, l.total_tva, l.date_start, l.date_end,';
|
||||
$sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label';
|
||||
@ -1031,8 +1092,9 @@ class Commande extends CommonObject
|
||||
$ligne->rowid = $objp->rowid; // \deprecated
|
||||
$ligne->id = $objp->rowid;
|
||||
$ligne->fk_commande = $objp->fk_commande;
|
||||
$ligne->commande_id = $objp->fk_commande; // \deprecated
|
||||
$ligne->desc = $objp->description; // Description ligne
|
||||
$ligne->commande_id = $objp->fk_commande; // \deprecated
|
||||
$ligne->desc = $objp->description; // Description ligne
|
||||
$ligne->product_type = $objp->product_type;
|
||||
$ligne->qty = $objp->qty;
|
||||
$ligne->tva_tx = $objp->tva_tx;
|
||||
$ligne->total_ht = $objp->total_ht;
|
||||
@ -1061,6 +1123,7 @@ class Commande extends CommonObject
|
||||
}
|
||||
$this->db->free($result);
|
||||
|
||||
$this->lines = $this->lignes; // For backward compatibility
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
@ -2183,10 +2246,8 @@ class CommandeLigne
|
||||
$sql = 'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.price, cd.qty, cd.tva_tx,';
|
||||
$sql.= ' cd.remise, cd.remise_percent, cd.fk_remise_except, cd.subprice,';
|
||||
$sql.= ' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc, cd.marge_tx, cd.marque_tx, cd.rang,';
|
||||
$sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc';
|
||||
// Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html)
|
||||
// Load start and end dates from the database
|
||||
$sql.= ','.$this->db->pdate('cd.date_start').' as date_start,'.$this->db->pdate('cd.date_end').' as date_end';
|
||||
$sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc,';
|
||||
$sql.= ' '.$this->db->pdate('cd.date_start').' as date_start,'.$this->db->pdate('cd.date_end').' as date_end';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as cd';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON cd.fk_product = p.rowid';
|
||||
$sql.= ' WHERE cd.rowid = '.$rowid;
|
||||
|
||||
@ -70,6 +70,31 @@ if ($_GET["projetid"])
|
||||
/* Actions */
|
||||
/******************************************************************************/
|
||||
|
||||
// Action clone object
|
||||
if ($_POST["action"] == 'confirm_clone' && $_POST['confirm'] == 'yes')
|
||||
{
|
||||
if (1==0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
|
||||
{
|
||||
$mesg='<div class="error">'.$langs->trans("NoCloneOptionsSpecified").'</div>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$object=new Commande($db);
|
||||
$result=$object->createFromClone($_REQUEST['id']);
|
||||
if ($result > 0)
|
||||
{
|
||||
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg=$object->error;
|
||||
$_GET['action']='';
|
||||
$_GET['id']=$_REQUEST['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Suppression de la commande
|
||||
if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes')
|
||||
{
|
||||
@ -680,7 +705,7 @@ if ($_POST['addfile'])
|
||||
}
|
||||
else
|
||||
{
|
||||
// Echec transfert (fichier d<EFBFBD>passant la limite ?
|
||||
// Echec transfert (fichier depassant la limite ?)
|
||||
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
|
||||
// print_r($_FILES);
|
||||
}
|
||||
@ -1231,6 +1256,19 @@ else
|
||||
print '<br>';
|
||||
}
|
||||
|
||||
// Clone confirmation
|
||||
if ($_GET["action"] == 'clone')
|
||||
{
|
||||
// Create an array for form
|
||||
$formquestion=array(
|
||||
//'text' => $langs->trans("ConfirmClone"),
|
||||
//array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1)
|
||||
);
|
||||
// Paiement incomplet. On demande si motif = escompte ou autre
|
||||
$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$commande->id,$langs->trans('CloneOrder'),$langs->trans('ConfirmCloneOrder',$commande->ref),'confirm_clone',$formquestion,'yes');
|
||||
print '<br>';
|
||||
}
|
||||
|
||||
/*
|
||||
* Commande
|
||||
*/
|
||||
@ -2001,6 +2039,12 @@ else
|
||||
}
|
||||
}
|
||||
|
||||
// Clone
|
||||
if ($user->rights->commande->creer)
|
||||
{
|
||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$commande->id.'&action=clone&object=order">'.$langs->trans("ToClone").'</a>';
|
||||
}
|
||||
|
||||
// Delete order
|
||||
if ($user->rights->commande->supprimer)
|
||||
{
|
||||
|
||||
@ -33,7 +33,7 @@ require_once(DOL_DOCUMENT_ROOT.'/includes/modules/export/modules_export.php');
|
||||
$langs->load("exports");
|
||||
|
||||
|
||||
if (! $user->societe_id == 0)
|
||||
if (! $user->admin)
|
||||
accessforbidden();
|
||||
|
||||
$entitytoicon=array(
|
||||
@ -307,7 +307,7 @@ if ($step == 1 || ! $datatoexport)
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td '.$bc[false].' colspan="2">'.$langs->trans("NoExportableData").'</td></tr>';
|
||||
print '<tr><td '.$bc[false].' colspan="3">'.$langs->trans("NoExportableData").'</td></tr>';
|
||||
}
|
||||
print '</table>';
|
||||
|
||||
|
||||
@ -14,17 +14,14 @@
|
||||
* 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/pre.inc.php
|
||||
\ingroup core
|
||||
\brief Fichier de gestion du menu gauche de l'espace exports
|
||||
\version $Revision$
|
||||
*/
|
||||
* \file htdocs/exports/pre.inc.php
|
||||
* \ingroup core
|
||||
* \brief Fichier de gestion du menu gauche de l'espace exports
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
require("../main.inc.php");
|
||||
|
||||
|
||||
@ -2809,8 +2809,8 @@ class FactureLigne
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Recupére l'objet ligne de facture
|
||||
\param rowid id de la ligne de facture
|
||||
* \brief Recupére l'objet ligne de facture
|
||||
* \param rowid id de la ligne de facture
|
||||
*/
|
||||
function fetch($rowid)
|
||||
{
|
||||
|
||||
291
htdocs/imports/import.class.php
Normal file
291
htdocs/imports/import.class.php
Normal file
@ -0,0 +1,291 @@
|
||||
<?php
|
||||
/* Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/admin/import/import.class.php
|
||||
* \ingroup import
|
||||
* \brief Fichier de la classe des imports
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* \class Import
|
||||
* \brief Classe permettant la gestion des imports
|
||||
*/
|
||||
class Import
|
||||
{
|
||||
/**
|
||||
* \brief Constructeur de la classe
|
||||
* \param DB Database handler
|
||||
*/
|
||||
function Import($DB)
|
||||
{
|
||||
$this->db=$DB;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Load an importable dataset
|
||||
* \param user Object user making export
|
||||
* \param filter Code export pour charger un lot de donnees particulier
|
||||
*/
|
||||
function load_arrays($user,$filter='')
|
||||
{
|
||||
global $langs,$conf;
|
||||
|
||||
dol_syslog("Import::load_arrays user=".$user->id." filter=".$filter);
|
||||
|
||||
$dir=DOL_DOCUMENT_ROOT."/includes/modules";
|
||||
$handle=opendir($dir);
|
||||
|
||||
// Recherche des exports disponibles
|
||||
$var=True;
|
||||
$i=0;
|
||||
while (($file = readdir($handle))!==false)
|
||||
{
|
||||
if (eregi("^(mod.*)\.class\.php",$file,$reg))
|
||||
{
|
||||
$modulename=$reg[1];
|
||||
|
||||
// Defined if module is enabled
|
||||
$enabled=true;
|
||||
$part=strtolower(eregi_replace('^mod','',$modulename));
|
||||
if (empty($conf->$part->enabled)) $enabled=false;
|
||||
|
||||
if ($enabled)
|
||||
{
|
||||
// Chargement de la classe
|
||||
$file = $dir."/".$modulename.".class.php";
|
||||
$classname = $modulename;
|
||||
require_once($file);
|
||||
$module = new $classname($this->db);
|
||||
|
||||
if (is_array($module->export_code))
|
||||
{
|
||||
foreach($module->export_code as $r => $value)
|
||||
{
|
||||
if ($filter && ($filter != $module->export_code[$r])) continue;
|
||||
|
||||
// Test si permissions ok \todo tester sur toutes permissions
|
||||
$perm=$module->export_permission[$r][0];
|
||||
//print_r("$perm[0]-$perm[1]-$perm[2]<br>");
|
||||
if ($perm[2])
|
||||
{
|
||||
$bool=$user->rights->$perm[0]->$perm[1]->$perm[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
$bool=$user->rights->$perm[0]->$perm[1];
|
||||
}
|
||||
if ($perm[0]=='user' && $user->admin) $bool=true;
|
||||
//print $bool." $perm[0]"."<br>";
|
||||
|
||||
// Permissions ok
|
||||
// if ($bool)
|
||||
// {
|
||||
// Charge fichier lang en rapport
|
||||
$langtoload=$module->getLangFilesArray();
|
||||
if (is_array($langtoload))
|
||||
{
|
||||
foreach($langtoload as $key)
|
||||
{
|
||||
$langs->load($key);
|
||||
}
|
||||
}
|
||||
|
||||
// Module
|
||||
$this->array_export_module[$i]=$module;
|
||||
// Permission
|
||||
$this->array_export_perms[$i]=$bool;
|
||||
// Icon
|
||||
$this->array_export_icon[$i]=(isset($module->export_icon[$r])?$module->export_icon[$r]:$module->picto);
|
||||
// Code du dataset export
|
||||
$this->array_export_code[$i]=$module->export_code[$r];
|
||||
// Libelle du dataset export
|
||||
$this->array_export_label[$i]=$module->getDatasetLabel($r);
|
||||
// Tableau des champ a exporter (cle=champ, valeur=libelle)
|
||||
$this->array_export_fields[$i]=$module->export_fields_array[$r];
|
||||
// Tableau des entites a exporter (cle=champ, valeur=entite)
|
||||
$this->array_export_entities[$i]=$module->export_entities_array[$r];
|
||||
// Tableau des alias a exporter (cle=champ, valeur=alias)
|
||||
$this->array_export_alias[$i]=$module->export_alias_array[$r];
|
||||
// Tableau des operations speciales sur champ
|
||||
$this->array_export_special[$i]=$module->export_special_array[$r];
|
||||
|
||||
// Requete sql du dataset
|
||||
$this->array_export_sql_start[$i]=$module->export_sql_start[$r];
|
||||
$this->array_export_sql_end[$i]=$module->export_sql_end[$r];
|
||||
//$this->array_export_sql[$i]=$module->export_sql[$r];
|
||||
|
||||
dol_syslog("Import loaded for module ".$modulename." with index ".$i.", dataset=".$module->export_code[$r].", nb of fields=".sizeof($module->export_fields_code[$r]));
|
||||
$i++;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* \brief Importe un fichier clients
|
||||
*/
|
||||
function ImportClients($file)
|
||||
{
|
||||
$this->nb_import_ok = 0;
|
||||
$this->nb_import_ko = 0;
|
||||
$this->nb_import = 0;
|
||||
|
||||
dol_syslog("Import::ImportClients($file)", LOG_DEBUG);
|
||||
|
||||
$this->ReadFile($file);
|
||||
|
||||
foreach ($this->lines as $this->line)
|
||||
{
|
||||
$societe = new Societe($this->db);
|
||||
|
||||
$this->SetInfosTiers($societe);
|
||||
|
||||
$societe->client = 1;
|
||||
$societe->tva_assuj = $this->line[12];
|
||||
$societe->code_client = $this->line[13];
|
||||
$societe->tva_intra = $this->line[14];
|
||||
|
||||
$this->nb_import++;
|
||||
|
||||
if ( $societe->create($user) == 0)
|
||||
{
|
||||
dol_syslog("Import::ImportClients ".$societe->nom." SUCCESS", LOG_DEBUG);
|
||||
$this->nb_import_ok++;
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_syslog("Import::ImportClients ".$societe->nom." ERROR", LOG_ERR);
|
||||
$this->nb_import_ko++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function SetInfosTiers(&$obj)
|
||||
{
|
||||
$obj->nom = $this->line[0];
|
||||
$obj->adresse = $this->line[1];
|
||||
|
||||
if (strlen(trim($this->line[2])) > 0)
|
||||
$obj->adresse .= "\n". trim($this->line[2]);
|
||||
|
||||
if (strlen(trim($this->line[3])) > 0)
|
||||
$obj->adresse .= "\n". trim($this->line[3]);
|
||||
|
||||
$obj->cp = $this->line[4];
|
||||
$obj->ville = $this->line[5];
|
||||
$obj->tel = $this->line[6];
|
||||
$obj->fax = $this->line[7];
|
||||
$obj->email = $this->line[8];
|
||||
$obj->url = $this->line[9];
|
||||
$obj->siren = $this->line[10];
|
||||
$obj->siret = $this->line[11];
|
||||
}
|
||||
|
||||
|
||||
function ReadFile($file)
|
||||
{
|
||||
$this->errno = 0;
|
||||
|
||||
if (is_readable($file))
|
||||
{
|
||||
dol_syslog("Import::ReadFile Lecture du fichier $file", LOG_DEBUG);
|
||||
|
||||
$line = 0;
|
||||
$hf = fopen ($file, "r");
|
||||
$line = 0;
|
||||
$i=0;
|
||||
|
||||
$this->lines = array();
|
||||
|
||||
|
||||
while (!feof($hf) )
|
||||
{
|
||||
$cont = fgets($hf, 1024);
|
||||
|
||||
if (strlen(trim($cont)) > 0)
|
||||
{
|
||||
$this->lines[$i] = explode(";", $cont);
|
||||
}
|
||||
$i++;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errno = -2;
|
||||
}
|
||||
|
||||
return $errno;
|
||||
}
|
||||
|
||||
/*
|
||||
\brief Cree le repertoire de backup
|
||||
*/
|
||||
function CreateBackupDir()
|
||||
{
|
||||
$time = time();
|
||||
|
||||
$upload_dir = DOL_DATA_ROOT."/import/";
|
||||
|
||||
if (! is_dir($upload_dir))
|
||||
{
|
||||
umask(0);
|
||||
if (! mkdir($upload_dir, 0755))
|
||||
{
|
||||
dol_syslog("Import::ReadFile Impossible de creer $upload_dir",LOG_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
$upload_dir = DOL_DATA_ROOT."/import/".strftime("%Y",$time);
|
||||
|
||||
if (! is_dir($upload_dir))
|
||||
{
|
||||
umask(0);
|
||||
if (! mkdir($upload_dir, 0755))
|
||||
{
|
||||
dol_syslog("Import::ReadFile Impossible de creer $upload_dir",LOG_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
$upload_dir = DOL_DATA_ROOT."/import/".strftime("%Y",$time)."/".strftime("%d-%m-%Y",$time);
|
||||
|
||||
if (! is_dir($upload_dir))
|
||||
{
|
||||
umask(0);
|
||||
if (! mkdir($upload_dir, 0755))
|
||||
{
|
||||
dol_syslog("Import::ReadFile Impossible de creer $upload_dir",LOG_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
$this->upload_dir = DOL_DATA_ROOT."/import/".strftime("%Y",$time)."/".strftime("%d-%m-%Y",$time);
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
796
htdocs/imports/import.php
Normal file
796
htdocs/imports/import.php
Normal file
@ -0,0 +1,796 @@
|
||||
<?php
|
||||
/* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/imports/import.php
|
||||
* \ingroup import
|
||||
* \brief Page d'edition d'un import
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
require_once("./pre.inc.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/html.formother.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/imports/import.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT.'/includes/modules/import/modules_import.php');
|
||||
|
||||
$langs->load("exports");
|
||||
|
||||
|
||||
if (! $user->societe_id == 0)
|
||||
accessforbidden();
|
||||
|
||||
$entitytoicon=array(
|
||||
'invoice'=>'bill','invoice_line'=>'bill',
|
||||
'order'=>'order' ,'order_line'=>'order',
|
||||
'intervention'=>'intervention' ,'inter_line'=>'intervention',
|
||||
'member'=>'user' ,'member_type'=>'group','subscription'=>'payment',
|
||||
'tax'=>'generic' ,'tax_type'=>'generic',
|
||||
'account'=>'account',
|
||||
'payment'=>'payment',
|
||||
'product'=>'product','stock'=>'generic','warehouse'=>'stock',
|
||||
'category'=>'generic',
|
||||
'other'=>'generic',
|
||||
);
|
||||
$entitytolang=array( // Translation code
|
||||
'user'=>'User',
|
||||
'company'=>'Company','contact'=>'Contact',
|
||||
'invoice'=>'Bill','invoice_line'=>'InvoiceLine',
|
||||
'order'=>'Order','order_line'=>'OrderLine',
|
||||
'intervention'=>'Intervention' ,'inter_line'=>'InterLine',
|
||||
'member'=>'Member','member_type'=>'MemberType','subscription'=>'Subscription',
|
||||
'tax'=>'SocialContribution','tax_type'=>'DictionnarySocialContributions',
|
||||
'account'=>'BankTransactions',
|
||||
'payment'=>'Payment',
|
||||
'product'=>'Product','stock'=>'Stock','warehouse'=>'Warehouse',
|
||||
'category'=>'Category',
|
||||
'other'=>'Other'
|
||||
);
|
||||
|
||||
$array_selected=isset($_SESSION["import_selected_fields"])?$_SESSION["import_selected_fields"]:array();
|
||||
$datatoimport=isset($_GET["datatoimport"])? $_GET["datatoimport"] : (isset($_POST["datatoimport"])?$_POST["datatoimport"]:'');
|
||||
$action=isset($_GET["action"]) ? $_GET["action"] : (isset($_POST["action"])?$_POST["action"]:'');
|
||||
$step=isset($_GET["step"])? $_GET["step"] : (isset($_POST["step"])?$_POST["step"]:1);
|
||||
$import_name=isset($_POST["import_name"])? $_POST["import_name"] : '';
|
||||
$hexa=isset($_POST["hexa"])? $_POST["hexa"] : '';
|
||||
$importmodelid=isset($_POST["importmodelid"])? $_POST["importmodelid"] : '';
|
||||
|
||||
$objimport=new Import($db);
|
||||
$objimport->load_arrays($user,$datatoimport);
|
||||
|
||||
$objmodelimport=new ModeleImports();
|
||||
$html = new Form($db);
|
||||
$htmlother = new FormOther($db);
|
||||
$formfile = new FormFile($db);
|
||||
$sqlusedforimport='';
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if ($action=='selectfield')
|
||||
{
|
||||
if ($_GET["field"]=='all')
|
||||
{
|
||||
$fieldsarray=$objimport->array_import_alias[0];
|
||||
foreach($fieldsarray as $key=>$val)
|
||||
{
|
||||
if (! empty($array_selected[$key])) continue; // If already selected, select next
|
||||
$array_selected[$key]=sizeof($array_selected)+1;
|
||||
//print_r($array_selected);
|
||||
$_SESSION["import_selected_fields"]=$array_selected;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$array_selected[$_GET["field"]]=sizeof($array_selected)+1;
|
||||
//print_r($array_selected);
|
||||
$_SESSION["import_selected_fields"]=$array_selected;
|
||||
}
|
||||
|
||||
}
|
||||
if ($action=='unselectfield')
|
||||
{
|
||||
if ($_GET["field"]=='all')
|
||||
{
|
||||
$array_selected=array();
|
||||
$_SESSION["import_selected_fields"]=$array_selected;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($array_selected[$_GET["field"]]);
|
||||
// Renumber fields of array_selected (from 1 to 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<br>";
|
||||
}
|
||||
$_SESSION["import_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<63>
|
||||
$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<75> (prtoection contre resoumission de page
|
||||
{
|
||||
$array_selected[$_GET["field"]]=$newpos;
|
||||
$array_selected[$newcode]=$pos;
|
||||
$_SESSION["import_selected_fields"]=$array_selected;
|
||||
}
|
||||
}
|
||||
|
||||
if ($step == 1 || $action == 'cleanselect')
|
||||
{
|
||||
$_SESSION["import_selected_fields"]=array();
|
||||
$array_selected=array();
|
||||
}
|
||||
|
||||
if ($action == 'builddoc')
|
||||
{
|
||||
// Build import file
|
||||
$result=$objimport->build_file($user, $_POST['model'], $datatoimport, $array_selected);
|
||||
if ($result < 0)
|
||||
{
|
||||
$mesg='<div class="error">'.$objimport->error.'</div>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg='<div class="ok">'.$langs->trans("FileSuccessfullyBuilt").'</div>';
|
||||
$sqlusedforimport=$objimport->sqlusedforimport;
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'deleteprof')
|
||||
{
|
||||
if ($_GET["id"])
|
||||
{
|
||||
$objimport->fetch($_GET["id"]);
|
||||
$result=$objimport->delete($user);
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'add_import_model')
|
||||
{
|
||||
if ($import_name)
|
||||
{
|
||||
asort($array_selected);
|
||||
|
||||
// Set save string
|
||||
$hexa='';
|
||||
foreach($array_selected as $key=>$val)
|
||||
{
|
||||
if ($hexa) $hexa.=',';
|
||||
$hexa.=$key;
|
||||
}
|
||||
|
||||
$objimport->model_name = $import_name;
|
||||
$objimport->datatoimport = $datatoimport;
|
||||
$objimport->hexa = $hexa;
|
||||
|
||||
$result = $objimport->create($user);
|
||||
if ($result >= 0)
|
||||
{
|
||||
$mesg='<div class="ok">'.$langs->trans("ImportModelSaved",$objimport->model_name).'</div>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs->load("errors");
|
||||
if ($objimport->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS')
|
||||
{
|
||||
$mesg='<div class="error">'.$langs->trans("ErrorImportDuplicateProfil").'</div>';
|
||||
}
|
||||
else $mesg='<div class="error">'.$objimport->error.'</div>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("ImportModelName")).'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($step == 2 && $action == 'select_model')
|
||||
{
|
||||
$_SESSION["import_selected_fields"]=array();
|
||||
$array_selected=array();
|
||||
$result = $objimport->fetch($importmodelid);
|
||||
if ($result > 0)
|
||||
{
|
||||
$fieldsarray=split(',',$objimport->hexa);
|
||||
$i=1;
|
||||
foreach($fieldsarray as $val)
|
||||
{
|
||||
$array_selected[$val]=$i;
|
||||
$i++;
|
||||
}
|
||||
$_SESSION["import_selected_fields"]=$array_selected;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Affichage Pages des Etapes
|
||||
*/
|
||||
|
||||
|
||||
if ($step == 1 || ! $datatoimport)
|
||||
{
|
||||
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";
|
||||
$hselected=$h;
|
||||
$h++;
|
||||
|
||||
/*
|
||||
$head[$h][0] = '';
|
||||
$head[$h][1] = $langs->trans("Step")." 2";
|
||||
$h++;
|
||||
*/
|
||||
|
||||
dol_fiche_head($head, $hselected, $langs->trans("NewImport"));
|
||||
|
||||
|
||||
print '<table class="notopnoleftnoright" width="100%">';
|
||||
|
||||
print $langs->trans("SelectImportDataSet").'<br>';
|
||||
|
||||
// Affiche les modules d'imports
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Module").'</td>';
|
||||
print '<td>'.$langs->trans("ImportableDatas").'</td>';
|
||||
print '<td> </td>';
|
||||
print '</tr>';
|
||||
$val=true;
|
||||
if (sizeof($objimport->array_import_code))
|
||||
{
|
||||
foreach ($objimport->array_import_code as $key => $value)
|
||||
{
|
||||
$val=!$val;
|
||||
print '<tr '.$bc[$val].'><td nospan="nospan">';
|
||||
//print img_object($objimport->array_import_module[$key]->getName(),$import->array_import_module[$key]->picto).' ';
|
||||
print $objimport->array_import_module[$key]->getName();
|
||||
print '</td><td>';
|
||||
//print $value;
|
||||
print img_object($objimport->array_import_module[$key]->getName(),$objimport->array_import_icon[$key]).' ';
|
||||
print $objimport->array_import_label[$key];
|
||||
print '</td><td align="right">';
|
||||
if ($objimport->array_import_perms[$key])
|
||||
{
|
||||
print '<a href="'.DOL_URL_ROOT.'/imports/import.php?step=2&datatoimprt='.$objimport->array_import_code[$key].'">'.img_picto($langs->trans("NewImport"),'filenew').'</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("NotEnoughPermissions");
|
||||
}
|
||||
print '</td></tr>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td '.$bc[false].' colspan="3">'.$langs->trans("NoImportableData").'</td></tr>';
|
||||
}
|
||||
print '</table>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '</div>';
|
||||
|
||||
if ($mesg) print $mesg;
|
||||
|
||||
}
|
||||
|
||||
if ($step == 2 && $datatoimport)
|
||||
{
|
||||
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";
|
||||
$hselected=$h;
|
||||
$h++;
|
||||
|
||||
dol_fiche_head($head, $hselected, $langs->trans("NewImport"));
|
||||
|
||||
|
||||
print '<form name="userfile" action="index.php" enctype="multipart/form-data" METHOD="POST">';
|
||||
print '<input type="hidden" name="max_file_size" value="'.$conf->maxfilesize.'">';
|
||||
|
||||
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
|
||||
print '<tr class="liste_titre"><td>Importer un fichier clients</td></tr>';
|
||||
|
||||
print "<tr $bc[1]><td>";
|
||||
print '<input type="file" name="userfile" size="20" maxlength="80"><br />';
|
||||
print '<input type="submit" value="'.$langs->trans("Upload").'" name="sendit"> ';
|
||||
print '<input type="submit" value="'.$langs->trans("Cancel").'" name="cancelit"><br>';
|
||||
|
||||
print "</tr>\n";
|
||||
print '</table></form>';
|
||||
|
||||
if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
|
||||
{
|
||||
$imp = new DolibarrImport($db);
|
||||
$imp->CreateBackupDir();
|
||||
if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $imp->upload_dir . "/" . $_FILES['userfile']['name'],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>";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg = "Le fichier n'a pas <20>t<EFBFBD> t<>l<EFBFBD>charg<72>";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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>';
|
||||
|
||||
print '</table>';
|
||||
print '<br>';
|
||||
|
||||
// Liste deroulante des modeles d'import
|
||||
print '<form action="import.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="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];
|
||||
|
||||
# $this->array_import_module[0]=$module;
|
||||
# $this->array_import_code[0]=$module->import_code[$r];
|
||||
# $this->array_import_label[0]=$module->import_label[$r];
|
||||
# $this->array_import_sql[0]=$module->import_sql[$r];
|
||||
# $this->array_import_fields[0]=$module->import_fields_array[$r];
|
||||
# $this->array_import_entities[0]=$module->import_fields_entities[$r];
|
||||
# $this->array_import_alias[0]=$module->import_fields_alias[$r];
|
||||
|
||||
$var=true;
|
||||
$i = 0;
|
||||
|
||||
foreach($fieldsarray as $code=>$label)
|
||||
{
|
||||
$var=!$var;
|
||||
print "<tr $bc[$var]>";
|
||||
|
||||
$i++;
|
||||
|
||||
$entity=$objimport->array_import_entities[0][$code];
|
||||
$entityicon=$entitytoicon[$entity]?$entitytoicon[$entity]:$entity;
|
||||
$entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$entity;
|
||||
|
||||
print '<td nowrap="nowrap">'.img_object('',$entityicon).' '.$langs->trans($entitylang).'</td>';
|
||||
if ((isset($array_selected[$code]) && $array_selected[$code]) || $modelchoice == 1)
|
||||
{
|
||||
// Selected fields
|
||||
print '<td> </td>';
|
||||
print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?step=2&datatoimport='.$datatoimport.'&action=unselectfield&field='.$code.'">'.img_left().'</a></td>';
|
||||
print '<td>'.$langs->trans($label).' ('.$code.')</td>';
|
||||
$bit=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fields not selected
|
||||
print '<td>'.$langs->trans($label).' ('.$code.')</td>';
|
||||
print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?step=2&datatoimport='.$datatoimport.'&action=selectfield&field='.$code.'">'.img_right().'</a></td>';
|
||||
print '<td> </td>';
|
||||
$bit=0;
|
||||
}
|
||||
|
||||
print '</tr>';
|
||||
$save_select.=$bit;
|
||||
}
|
||||
|
||||
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> </td>';
|
||||
print '<td>'.$langs->trans("FieldsTitle").'</td>';
|
||||
print '</tr>';
|
||||
|
||||
$var=true;
|
||||
foreach($array_selected as $code=>$value)
|
||||
{
|
||||
$var=!$var;
|
||||
print "<tr $bc[$var]>";
|
||||
|
||||
$entity=$objimport->array_import_entities[0][$code];
|
||||
$entityicon=$entitytoicon[$entity]?$entitytoicon[$entity]:$entity;
|
||||
$entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$entity;
|
||||
|
||||
print '<td>'.img_object('',$entityicon).' '.$langs->trans($entitylang).'</td>';
|
||||
|
||||
print '<td>'.$langs->trans($objimport->array_import_fields[0][$code]).' ('.$code.')</td>';
|
||||
|
||||
print '<td align="right" width="100">';
|
||||
print $value.' ';
|
||||
print '</td><td align="center" width="20">';
|
||||
if ($value < sizeof($array_selected)) print '<a href="'.$_SERVER["PHP_SELF"].'?step=3&datatoimport='.$datatoimport.'&action=downfield&field='.$code.'">'.img_down().'</a>';
|
||||
if ($value > 1) print '<a href="'.$_SERVER["PHP_SELF"].'?step=3&datatoimport='.$datatoimport.'&action=upfield&field='.$code.'">'.img_up().'</a>';
|
||||
print '</td>';
|
||||
|
||||
print '<td> </td>';
|
||||
|
||||
print '<td>'.$langs->trans($objimport->array_import_fields[0][$code]).'</td>';
|
||||
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
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=4&datatoimport='.$datatoimport.'">'.$langs->trans("NextStep").'</a>';
|
||||
}
|
||||
|
||||
print '</div>';
|
||||
|
||||
|
||||
// Area for profils import
|
||||
if (sizeof($array_selected))
|
||||
{
|
||||
print '<br>';
|
||||
print $langs->trans("SaveImportModel");
|
||||
|
||||
print '<form class="nocellnopadd" action="import.php" method="post">';
|
||||
print '<input type="hidden" name="action" value="add_import_model">';
|
||||
print '<input type="hidden" name="step" value="'.$step.'">';
|
||||
print '<input type="hidden" name="datatoimport" value="'.$datatoimport.'">';
|
||||
print '<input type="hidden" name="hexa" value="'.$hexa.'">';
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("ImportModelName").'</td>';
|
||||
print '<td> </td>';
|
||||
print '</tr>';
|
||||
$var=false;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td><input name="import_name" size="32" value=""></td><td align="right">';
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
|
||||
print '</td></tr>';
|
||||
|
||||
// List of existing import profils
|
||||
$sql = "SELECT rowid, label";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."import_model";
|
||||
$sql.= " WHERE type = '".$datatoimport."'";
|
||||
$sql.= " ORDER BY rowid";
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
$var=false;
|
||||
while ($i < $num)
|
||||
{
|
||||
$var=!$var;
|
||||
$obj = $db->fetch_object($resql);
|
||||
print '<tr '.$bc[$var].'><td>';
|
||||
print $obj->label;
|
||||
print '</td><td align="right">';
|
||||
print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoimport='.$datatoimport.'&action=deleteprof&id='.$obj->rowid.'">';
|
||||
print img_delete();
|
||||
print '</a>';
|
||||
print '</tr>';
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
print '</form>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($step == 4 && $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";
|
||||
$h++;
|
||||
|
||||
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=4&datatoimport='.$datatoimport;
|
||||
$head[$h][1] = $langs->trans("Step")." 4";
|
||||
$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=>$label)
|
||||
{
|
||||
$list.=($list?',':'');
|
||||
$list.=$langs->trans($objimport->array_import_fields[0][$code]);
|
||||
}
|
||||
print '<td>'.$list.'</td></tr>';
|
||||
|
||||
print '</table>';
|
||||
print '<br>';
|
||||
|
||||
print $langs->trans("NowClickToGenerateToBuildImportFile").'<br>';
|
||||
|
||||
// Liste des formats d'imports disponibles
|
||||
$var=true;
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("AvailableFormats").'</td>';
|
||||
print '<td>'.$langs->trans("LibraryUsed").'</td>';
|
||||
print '<td>'.$langs->trans("LibraryVersion").'</td>';
|
||||
print '</tr>';
|
||||
|
||||
$liste=$objmodelimport->liste_modeles($db);
|
||||
foreach($liste as $key)
|
||||
{
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'><td>'.$objmodelimport->getDriverLabel($key).'</td><td>'.$objmodelimport->getLibLabel($key).'</td><td>'.$objmodelimport->getLibVersion($key).'</td></tr>';
|
||||
}
|
||||
print '</table>';
|
||||
|
||||
print '</div>';
|
||||
|
||||
print '<table width="100%">';
|
||||
if ($mesg)
|
||||
{
|
||||
print '<tr><td colspan="2">';
|
||||
print $mesg;
|
||||
print '</td></tr>';
|
||||
}
|
||||
if ($sqlusedforimport && $user->admin)
|
||||
{
|
||||
print '<tr><td>';
|
||||
print info_admin($langs->trans("SQLUsedForImport").':<br> '.$sqlusedforimport);
|
||||
print '</td></tr>';
|
||||
}
|
||||
print '</table>';
|
||||
|
||||
print '<table width="100%"><tr><td width="50%">';
|
||||
|
||||
if (! is_dir($conf->import->dir_temp)) create_exdir($conf->import->dir_temp);
|
||||
|
||||
// Affiche liste des documents
|
||||
// NB: La fonction show_documents rescanne les modules qd genallowed=1
|
||||
$formfile->show_documents('import','',$conf->import->dir_temp.'/'.$user->id,$_SERVER["PHP_SELF"].'?step=4&datatoimport='.$datatoimport,$liste,1,(! empty($_POST['model'])?$_POST['model']:'csv'),'',1);
|
||||
|
||||
print '</td><td width="50%"> </td></tr>';
|
||||
print '</table>';
|
||||
|
||||
// If external library PHPEXCELREADER is available
|
||||
// and defined by PHPEXCELREADER constant.
|
||||
if (file_exists(PHPEXCELREADER.'excelreader.php'))
|
||||
{
|
||||
// Test d'affichage du tableau excel et csv
|
||||
//print '<table width="100%"><tr><td>';
|
||||
//require_once(DOL_DOCUMENT_ROOT.'/lib/viewfiles.lib.php');
|
||||
//viewExcelFileContent($conf->import->dir_temp.'/1/import_member_1.xls',5,3);
|
||||
//viewCsvFileContent($conf->import->dir_temp.'/1/import_member_1.csv',5);
|
||||
//print '</td></tr></table>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
print '<br>';
|
||||
|
||||
|
||||
$db->close();
|
||||
|
||||
llxFooter('$Date$ - $Revision$');
|
||||
?>
|
||||
@ -27,7 +27,7 @@
|
||||
*/
|
||||
|
||||
require_once("./pre.inc.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/admin/import/dolibarrimport.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/imports/import.class.php");
|
||||
|
||||
$langs->load("exports");
|
||||
|
||||
@ -36,8 +36,8 @@ if (! $user->societe_id == 0)
|
||||
|
||||
|
||||
|
||||
$export=new DolibarrImport($db);
|
||||
//$export->load_arrays($user);
|
||||
$import=new Import($db);
|
||||
//$import->load_arrays($user);
|
||||
|
||||
|
||||
llxHeader('',$langs->trans("ImportArea"));
|
||||
@ -50,10 +50,10 @@ print '<br>';
|
||||
|
||||
print '<table class="notopnoleftnoright" width="100%">';
|
||||
|
||||
print '<tr><td valign="top" width="30%" class="notopnoleft">';
|
||||
print '<tr><td valign="top" width="40%" class="notopnoleft">';
|
||||
|
||||
|
||||
// Liste des formats d'exports disponibles
|
||||
// Liste des formats d'imports disponibles
|
||||
$var=true;
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
@ -62,8 +62,8 @@ print '<td>'.$langs->trans("LibraryUsed").'</td>';
|
||||
print '<td>'.$langs->trans("LibraryVersion").'</td>';
|
||||
print '</tr>';
|
||||
|
||||
include_once(DOL_DOCUMENT_ROOT.'/includes/modules/export/modules_export.php');
|
||||
$model=new ModeleExports();
|
||||
include_once(DOL_DOCUMENT_ROOT.'/includes/modules/import/modules_import.php');
|
||||
$model=new ModeleImports();
|
||||
$liste=$model->liste_modeles($db);
|
||||
|
||||
foreach($liste as $key)
|
||||
@ -79,10 +79,10 @@ foreach($liste as $key)
|
||||
print '</table>';
|
||||
|
||||
|
||||
print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
|
||||
print '</td><td valign="top" width="60%" class="notopnoleftnoright">';
|
||||
|
||||
|
||||
// Affiche les modules d'exports
|
||||
// Affiche les modules d'imports
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Module").'</td>';
|
||||
@ -90,26 +90,26 @@ print '<td>'.$langs->trans("ImportableDatas").'</td>';
|
||||
//print '<td> </td>';
|
||||
print '</tr>';
|
||||
$val=true;
|
||||
if (sizeof($export->array_export_code))
|
||||
if (sizeof($import->array_import_code))
|
||||
{
|
||||
foreach ($export->array_export_code as $key => $value)
|
||||
foreach ($import->array_import_code as $key => $value)
|
||||
{
|
||||
$val=!$val;
|
||||
print '<tr '.$bc[$val].'><td>';
|
||||
print img_object($export->array_export_module[$key]->getName(),$export->array_export_module[$key]->picto).' ';
|
||||
print $export->array_export_module[$key]->getName();
|
||||
print img_object($import->array_import_module[$key]->getName(),$import->array_import_module[$key]->picto).' ';
|
||||
print $import->array_import_module[$key]->getName();
|
||||
print '</td><td>';
|
||||
$string=$langs->trans($export->array_export_label[$key]);
|
||||
print ($string!=$export->array_export_label[$key]?$string:$export->array_export_label[$key]);
|
||||
$string=$langs->trans($import->array_import_label[$key]);
|
||||
print ($string!=$import->array_import_label[$key]?$string:$import->array_import_label[$key]);
|
||||
print '</td>';
|
||||
// print '<td width="24">';
|
||||
// print '<a href="'.DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$export->array_export_code[$key].'&action=cleanselect">'.img_picto($langs->trans("NewExport"),'filenew').'</a>';
|
||||
// print '<a href="'.DOL_URL_ROOT.'/imports/import.php?step=2&datatoimport='.$import->array_import_code[$key].'&action=cleanselect">'.img_picto($langs->trans("NewImport"),'filenew').'</a>';
|
||||
// print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
}
|
||||
|
||||
print '<tr class="total"><td class="total" colspan="2" align="center"><form action="'.DOL_URL_ROOT.'/admin/import.php?leftmenu=import"><input type="submit" class="button" value="'.$langs->trans("NewExport").'"></form></td></tr>';
|
||||
print '<tr class="total"><td class="total" colspan="2" align="center"><form action="'.DOL_URL_ROOT.'/admin/import.php?leftmenu=import"><input type="submit" class="button" value="'.$langs->trans("NewImport").'"></form></td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
43
htdocs/imports/pre.inc.php
Normal file
43
htdocs/imports/pre.inc.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* Copyright (C) 2005 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
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/exports/pre.inc.php
|
||||
* \ingroup core
|
||||
* \brief Fichier de gestion du menu gauche de l'espace exports
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
require("../main.inc.php");
|
||||
|
||||
|
||||
function llxHeader($head = '', $title='', $help_url='')
|
||||
{
|
||||
global $user, $conf, $langs;
|
||||
|
||||
top_menu($head, $title);
|
||||
|
||||
$menu = new Menu();
|
||||
|
||||
$menu->add(DOL_URL_ROOT."/exports/index.php", $langs->trans("Exports"));
|
||||
$menu->add_submenu(DOL_URL_ROOT."/exports/export.php", $langs->trans("NewExport"));
|
||||
|
||||
left_menu($menu->liste, $help_url);
|
||||
}
|
||||
|
||||
?>
|
||||
@ -813,8 +813,8 @@ class MenuLeft {
|
||||
if (! empty($conf->global->MAIN_MODULE_IMPORT))
|
||||
{
|
||||
$langs->load("exports");
|
||||
$newmenu->add_submenu(DOL_URL_ROOT."/admin/import/index.php?leftmenu=import",$langs->trans("FormatedImport"),0, $user->rights->import->lire);
|
||||
$newmenu->add_submenu(DOL_URL_ROOT."/admin/import/import.php?leftmenu=import",$langs->trans("NewImport"),1, $user->rights->import->creer);
|
||||
$newmenu->add_submenu(DOL_URL_ROOT."/imports/index.php?leftmenu=import",$langs->trans("FormatedImport"),0, $user->rights->import->lire);
|
||||
$newmenu->add_submenu(DOL_URL_ROOT."/imports/import.php?leftmenu=import",$langs->trans("NewImport"),1, $user->rights->import->creer);
|
||||
}
|
||||
|
||||
if (! empty($conf->global->MAIN_MODULE_DOMAIN))
|
||||
|
||||
@ -771,13 +771,20 @@ class MenuLeft {
|
||||
*/
|
||||
}
|
||||
|
||||
if ($conf->export->enabled)
|
||||
if (! empty($conf->export->enabled))
|
||||
{
|
||||
$langs->load("exports");
|
||||
$newmenu->add_submenu(DOL_URL_ROOT."/exports/index.php?leftmenu=export",$langs->trans("FormatedExport"),0, $user->rights->export->lire);
|
||||
$newmenu->add_submenu(DOL_URL_ROOT."/exports/export.php?leftmenu=export",$langs->trans("NewExport"),1, $user->rights->export->creer);
|
||||
}
|
||||
|
||||
if (! empty($conf->global->MAIN_MODULE_IMPORT))
|
||||
{
|
||||
$langs->load("exports");
|
||||
$newmenu->add_submenu(DOL_URL_ROOT."/imports/index.php?leftmenu=import",$langs->trans("FormatedImport"),0, $user->rights->import->lire);
|
||||
$newmenu->add_submenu(DOL_URL_ROOT."/imports/import.php?leftmenu=import",$langs->trans("NewImport"),1, $user->rights->import->creer);
|
||||
}
|
||||
|
||||
if ($conf->global->MAIN_MODULE_DOMAIN)
|
||||
{
|
||||
$langs->load("domains");
|
||||
|
||||
@ -264,8 +264,8 @@ insert into `llx_menu` (`menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`,
|
||||
insert into `llx_menu` (`menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position) values ('auguria', 'left', 3902__+MAX_llx_menu__, 'tools', '', 3900__+MAX_llx_menu__, '/comm/mailing/liste.php?leftmenu=mailing', 'List', 1, 'mails', '$user->rights->mailing->lire', '', 0, 1);
|
||||
insert into `llx_menu` (`menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position) values ('auguria', 'left', 4100__+MAX_llx_menu__, 'tools', '', 8__+MAX_llx_menu__, '/exports/index.php?leftmenu=export', 'FormatedExport', 0, 'exports', '$user->rights->export->lire', '', 2, 2);
|
||||
insert into `llx_menu` (`menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position) values ('auguria', 'left', 4101__+MAX_llx_menu__, 'tools', '', 4100__+MAX_llx_menu__, '/exports/export.php?leftmenu=export', 'NewExport', 1, 'exports', '$user->rights->export->creer', '', 2, 0);
|
||||
insert into `llx_menu` (`menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position) values ('auguria', 'left', 4130__+MAX_llx_menu__, 'tools', '', 8__+MAX_llx_menu__, '/admin/import/index.php?leftmenu=import', 'FormatedImport', 0, 'exports', '$user->rights->import->lire', '', 2, 2);
|
||||
insert into `llx_menu` (`menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position) values ('auguria', 'left', 4131__+MAX_llx_menu__, 'tools', '', 4130__+MAX_llx_menu__, '/admin/import/import.php?leftmenu=import', 'NewImport', 1, 'exports', '$user->rights->import->creer', '', 2, 0);
|
||||
insert into `llx_menu` (`menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position) values ('auguria', 'left', 4130__+MAX_llx_menu__, 'tools', '', 8__+MAX_llx_menu__, '/imports/index.php?leftmenu=import', 'FormatedImport', 0, 'exports', '$user->rights->import->lire', '', 2, 2);
|
||||
insert into `llx_menu` (`menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position) values ('auguria', 'left', 4131__+MAX_llx_menu__, 'tools', '', 4130__+MAX_llx_menu__, '/imports/import.php?leftmenu=import', 'NewImport', 1, 'exports', '$user->rights->import->creer', '', 2, 0);
|
||||
|
||||
insert into `llx_menu` (`menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position) values ('auguria', 'left', 4200__+MAX_llx_menu__, 'members', '', 13__+MAX_llx_menu__, '/adherents/index.php?leftmenu=members&mainmenu=members', 'Members', 0, 'members', '$user->rights->adherent->lire', '', 2, 0);
|
||||
insert into `llx_menu` (`menu_handler`, `type`, `rowid`, `mainmenu`, `leftmenu`, `fk_menu`, `url`, `titre`, `level`, `langs`, perms, `target`, `user`, position) values ('auguria', 'left', 4201__+MAX_llx_menu__, 'members', '', 4200__+MAX_llx_menu__, '/adherents/fiche.php?action=create', 'NewMember', 1, 'members', '$user->rights->adherent->creer', '', 2, 0);
|
||||
|
||||
@ -30,7 +30,7 @@ require_once(DOL_DOCUMENT_ROOT ."/includes/modules/export/modules_export.php");
|
||||
|
||||
/**
|
||||
* \class ExportCsv
|
||||
* \brief Classe permettant de generer les factures au modele Crabe
|
||||
* \brief Classe permettant de generer les fichiers exports au format CSV
|
||||
*/
|
||||
class ExportCsv extends ModeleExports
|
||||
{
|
||||
|
||||
@ -19,29 +19,28 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/includes/modules/export/modules_export.php
|
||||
\ingroup export
|
||||
\brief Fichier contenant la classe mère de generation des exports
|
||||
\version $Id$
|
||||
* \file htdocs/includes/modules/export/modules_export.php
|
||||
* \ingroup export
|
||||
* \brief File of parent class for export modules
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT.'/lib/functions.lib.php');
|
||||
|
||||
|
||||
/**
|
||||
\class ModeleExports
|
||||
\brief Classe mère des modèles de format d'export
|
||||
* \class ModeleExports
|
||||
* \brief Parent class for export modules
|
||||
*/
|
||||
|
||||
class ModeleExports
|
||||
{
|
||||
var $error='';
|
||||
|
||||
var $driverlabel;
|
||||
var $driverversion;
|
||||
var $driverlabel=array();
|
||||
var $driverversion=array();
|
||||
|
||||
var $libabel;
|
||||
var $libversion;
|
||||
var $liblabel=array();
|
||||
var $libversion=array();
|
||||
|
||||
|
||||
/**
|
||||
@ -52,7 +51,7 @@ class ModeleExports
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Charge en memoire et renvoie la liste des modèles actifs
|
||||
* \brief Charge en memoire et renvoie la liste des modeles actifs
|
||||
* \param db Handler de base
|
||||
*/
|
||||
function liste_modeles($db)
|
||||
@ -129,8 +128,8 @@ class ModeleExports
|
||||
|
||||
/**
|
||||
* \brief Lance la generation du fichier
|
||||
* \remarks Les tableaux array_export_xxx sont déjà chargées pour le bon datatoexport
|
||||
* aussi le parametre datatoexport est inutilisé
|
||||
* \remarks Les tableaux array_export_xxx sont d<EFBFBD>j<EFBFBD> charg<EFBFBD>es pour le bon datatoexport
|
||||
* aussi le parametre datatoexport est inutilis<EFBFBD>
|
||||
*/
|
||||
function build_file($model, $datatoexport, $array_selected)
|
||||
{
|
||||
|
||||
212
htdocs/includes/modules/import/import_csv.modules.php
Normal file
212
htdocs/includes/modules/import/import_csv.modules.php
Normal file
@ -0,0 +1,212 @@
|
||||
<?php
|
||||
/* Copyright (C) 2006-2009 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
|
||||
* 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.
|
||||
* or see http://www.gnu.org/
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/includes/modules/export/export_csv.modules.php
|
||||
* \ingroup export
|
||||
* \brief File to build exports with CSV format
|
||||
* \author Laurent Destailleur
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/import/modules_import.php");
|
||||
|
||||
|
||||
/**
|
||||
* \class ImportCsv
|
||||
* \brief Classe permettant de lire les fichiers imports CSV
|
||||
*/
|
||||
class ImportCsv extends ModeleImports
|
||||
{
|
||||
var $id;
|
||||
var $label;
|
||||
var $extension;
|
||||
var $version;
|
||||
|
||||
var $label_lib;
|
||||
var $version_lib;
|
||||
|
||||
var $separator;
|
||||
|
||||
var $handle; // Handle fichier
|
||||
|
||||
|
||||
/**
|
||||
* \brief Constructeur
|
||||
* \param db Handler acces base de donnee
|
||||
*/
|
||||
function ImportCsv($db)
|
||||
{
|
||||
global $conf;
|
||||
$this->db = $db;
|
||||
|
||||
$this->id='csv'; // Same value then xxx in file name export_xxx.modules.php
|
||||
$this->label='Csv (Comma Separated Value)'; // Label of driver
|
||||
$this->extension='csv'; // Extension for generated file by this driver
|
||||
$ver=split(' ','$Revision$');
|
||||
$this->version=$ver[2]; // Driver version
|
||||
|
||||
// If driver use an external library, put its name here
|
||||
$this->label_lib='Dolibarr';
|
||||
$this->version_lib=DOL_VERSION;
|
||||
|
||||
$this->separator=',';
|
||||
if (! empty($conf->global->EXPORT_CSV_SEPARATOR_TO_USE)) $this->separator=$conf->global->EXPORT_CSV_SEPARATOR_TO_USE;
|
||||
}
|
||||
|
||||
function getDriverId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
function getDriverLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
function getDriverExtension()
|
||||
{
|
||||
return $this->extension;
|
||||
}
|
||||
|
||||
function getDriverVersion()
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
function getLibLabel()
|
||||
{
|
||||
return $this->label_lib;
|
||||
}
|
||||
|
||||
function getLibVersion()
|
||||
{
|
||||
return $this->version_lib;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Open output file
|
||||
* \param file Path of filename
|
||||
* \return int <0 if KO, >=0 if OK
|
||||
*/
|
||||
function open_file($file,$outputlangs)
|
||||
{
|
||||
global $langs;
|
||||
|
||||
dol_syslog("ImportCsv::open_file file=".$file);
|
||||
|
||||
$ret=1;
|
||||
|
||||
$outputlangs->load("exports");
|
||||
$this->handle = fread($file, "wt");
|
||||
if (! $this->handle)
|
||||
{
|
||||
$langs->load("errors");
|
||||
$this->error=$langs->trans("ErrorFailToOpenFile",$file);
|
||||
$ret=-1;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Output header into file
|
||||
* \param langs Output language
|
||||
*/
|
||||
function read_header($outputlangs)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Output record line into file
|
||||
*/
|
||||
function read_record($array_alias,$array_selected_sorted,$objp,$outputlangs)
|
||||
{
|
||||
global $conf;
|
||||
if (! empty($conf->global->EXPORT_CSV_FORCE_CHARSET)) $outputlangs->charset_output=$conf->global->EXPORT_CSV_FORCE_CHARSET;
|
||||
|
||||
$this->col=0;
|
||||
foreach($array_selected_sorted as $code => $value)
|
||||
{
|
||||
$alias=$array_alias[$code];
|
||||
if (empty($alias)) dol_print_error('','Bad value for field with code='.$code.'. Try to redefine export.');
|
||||
$newvalue=$outputlangs->convToOutputCharset($objp->$alias);
|
||||
|
||||
// Translation newvalue
|
||||
if (eregi('^\((.*)\)$',$newvalue,$reg))
|
||||
{
|
||||
$newvalue=$outputlangs->transnoentities($reg[1]);
|
||||
}
|
||||
|
||||
$newvalue=$this->csv_clean($newvalue);
|
||||
|
||||
fwrite($this->handle,$newvalue.$this->separator);
|
||||
$this->col++;
|
||||
}
|
||||
fwrite($this->handle,"\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Close file handle
|
||||
*/
|
||||
function close_file()
|
||||
{
|
||||
fclose($this->handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean a cell to respect rules of CSV file cells
|
||||
* @param newvalue String to clean
|
||||
* @return string Value cleaned
|
||||
*/
|
||||
function csv_clean($newvalue)
|
||||
{
|
||||
$addquote=0;
|
||||
|
||||
// Rule Dolibarr: No HTML
|
||||
$newvalue=dol_string_nohtmltag($newvalue);
|
||||
|
||||
// Rule 1 CSV: No CR, LF in cells
|
||||
$newvalue=ereg_replace("\r",'',$newvalue);
|
||||
$newvalue=ereg_replace("\n",'\n',$newvalue);
|
||||
|
||||
// Rule 2 CSV: If value contains ", we must duplicate ", and add "
|
||||
if (ereg('"',$newvalue))
|
||||
{
|
||||
$addquote=1;
|
||||
$newvalue=ereg_replace('"','""',$newvalue);
|
||||
}
|
||||
|
||||
// Rule 3 CSV: If value contains separator, we must add "
|
||||
if (ereg($this->separator,$newvalue))
|
||||
{
|
||||
$addquote=1;
|
||||
}
|
||||
|
||||
return ($addquote?'"':'').$newvalue.($addquote?'"':'');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
164
htdocs/includes/modules/import/modules_import.php
Normal file
164
htdocs/includes/modules/import/modules_import.php
Normal file
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
/* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
|
||||
*
|
||||
* 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.
|
||||
* or see http://www.gnu.org/
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/includes/modules/import/modules_import.php
|
||||
* \ingroup export
|
||||
* \brief File of parent class for import file readers
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT.'/lib/functions.lib.php');
|
||||
|
||||
|
||||
/**
|
||||
* \class ModeleImports
|
||||
* \brief Parent class for import file readers
|
||||
*/
|
||||
class ModeleImports
|
||||
{
|
||||
var $error='';
|
||||
|
||||
var $driverlabel=array();
|
||||
var $driverversion=array();
|
||||
|
||||
var $liblabel=array();
|
||||
var $libversion=array();
|
||||
|
||||
|
||||
/**
|
||||
* \brief Constructeur
|
||||
*/
|
||||
function ModeleImports()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Charge en memoire et renvoie la liste des modeles actifs
|
||||
* \param db Handler de base
|
||||
*/
|
||||
function liste_modeles($db)
|
||||
{
|
||||
dol_syslog("ModeleImport::loadFormat");
|
||||
|
||||
$dir=DOL_DOCUMENT_ROOT."/includes/modules/import/";
|
||||
$handle=opendir($dir);
|
||||
|
||||
// Recherche des fichiers drivers imports disponibles
|
||||
$var=True;
|
||||
$i=0;
|
||||
while (($file = readdir($handle))!==false)
|
||||
{
|
||||
if (eregi("^import_(.*)\.modules\.php",$file,$reg))
|
||||
{
|
||||
$moduleid=$reg[1];
|
||||
|
||||
// Chargement de la classe
|
||||
$file = $dir."/import_".$moduleid.".modules.php";
|
||||
$classname = "Import".ucfirst($moduleid);
|
||||
|
||||
require_once($file);
|
||||
$module = new $classname($db);
|
||||
|
||||
// Driver properties
|
||||
$this->driverlabel[$module->id]=$module->getDriverLabel();
|
||||
$this->driverversion[$module->id]=$module->getDriverVersion();
|
||||
// If use an external lib
|
||||
$this->liblabel[$module->id]=$module->getLibLabel();
|
||||
$this->libversion[$module->id]=$module->getLibVersion();
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
return array_keys($this->driverlabel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Renvoi libelle d'un driver export
|
||||
*/
|
||||
function getDriverLabel($key)
|
||||
{
|
||||
return $this->driverlabel[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Renvoi version d'un driver export
|
||||
*/
|
||||
function getDriverVersion($key)
|
||||
{
|
||||
return $this->driverversion[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Renvoi libelle de librairie externe du driver
|
||||
*/
|
||||
function getLibLabel($key)
|
||||
{
|
||||
return $this->liblabel[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Renvoi version de librairie externe du driver
|
||||
*/
|
||||
function getLibVersion($key)
|
||||
{
|
||||
return $this->libversion[$key];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Lance lecture fichier
|
||||
* \remarks Les tableaux array_import_xxx sont deja chargees pour le bon datatoexport
|
||||
*/
|
||||
function load_file($model, $array_selected)
|
||||
{
|
||||
global $langs;
|
||||
|
||||
dol_syslog("Import::load_file $model, $array_selected");
|
||||
|
||||
// Creation de la classe d'export du model ImportXXX
|
||||
$dir = DOL_DOCUMENT_ROOT . "/includes/modules/import/";
|
||||
$file = "import_".$model.".modules.php";
|
||||
$classname = "Import".$model;
|
||||
require_once($dir.$file);
|
||||
$obj = new $classname($db);
|
||||
|
||||
// Execute requete import
|
||||
$sql=$this->array_export_sql[0];
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog("Error: sql=$sql ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@ -261,7 +261,6 @@ PaymentNumber=Payment number
|
||||
RemoveDiscount=Remove discount
|
||||
WatermarkOnDraftBill=Watermark on draft invoices (nothing if empty)
|
||||
CloneInvoice=Clone invoice
|
||||
CloneMainAttributes=Clone object with its main attributes
|
||||
ConfirmCloneInvoice=Are you sure you want to clone this invoice <b>%s</b> ?
|
||||
DisabledBecauseReplacedInvoice=Action disabled because invoice has been replaced
|
||||
|
||||
|
||||
@ -7,13 +7,21 @@ NewImport=New import
|
||||
ExportableDatas=Exportable dataset
|
||||
ImportableDatas=Importable dataset
|
||||
SelectExportDataSet=Choose dataset you want to export...
|
||||
SelectImportDataSet=Choose dataset you want to import...
|
||||
SelectExportFields=Choose fields you want to export, or select a predefined export profil
|
||||
SelectImportFields=Choose fields you want to import, or select a predefined import profil
|
||||
SaveExportModel=Save this export profile if you plan to reuse it later...
|
||||
SaveImportModel=Save this import profile if you plan to reuse it later...
|
||||
ExportModelName=Export profile name
|
||||
ExportModelSaved=Export profile saved under name <b>%s</b>.
|
||||
ExportableFields=Exportable fields
|
||||
ExportedFields=Exported fields
|
||||
ImportModelName=Import profile name
|
||||
ImportModelSaved=Import profile saved under name <b>%s</b>.
|
||||
ImportableFields=Importable fields
|
||||
ImportedFields=Imported fields
|
||||
DatasetToExport=Dataset to export
|
||||
DatasetToImport=Dataset to import
|
||||
Dataset=Dataset
|
||||
ChooseFieldsOrdersAndTitle=Choose fields order...
|
||||
FieldsOrder=Fields order
|
||||
|
||||
@ -502,6 +502,7 @@ Page=Page
|
||||
Notes=Notes
|
||||
AddNewLine=Add new line
|
||||
FreeZone=Free text
|
||||
CloneMainAttributes=Clone object with its main attributes
|
||||
# Week day
|
||||
Day1=Monday
|
||||
Day2=Tuesday
|
||||
|
||||
@ -100,6 +100,8 @@ UseCustomerContactAsOrderRecipientIfExist=Use customer contact address if define
|
||||
RunningOrders=Orders on process
|
||||
UserWithApproveOrderGrant=Useres granted with "approve orders" permission.
|
||||
PaymentOrderRef=Payment of order %s
|
||||
CloneOrder=Clone order
|
||||
ConfirmCloneOrder=Are you sure you want to clone this order <b>%s</b> ?
|
||||
|
||||
Error_COMMANDE_SUPPLIER_ADDON_NotDefined=Constant COMMANDE_SUPPLIER_ADDON not defined
|
||||
Error_COMMANDE_ADDON_NotDefined=Constant COMMANDE_ADDON not defined
|
||||
|
||||
@ -261,7 +261,6 @@ RemoveDiscount=Supprimer remise
|
||||
WatermarkOnDraftBill=Filigrane sur les brouillons de factures (aucun si vide)
|
||||
UnpayedNotChecked=Aucune facture impayées n'a été sélectionnée
|
||||
CloneInvoice=Cloner facture
|
||||
CloneMainAttributes=Cloner l'objet avec ces attributs principaux
|
||||
ConfirmCloneInvoice=Etes-vous sur de vouloir cloner cette facture <b>%s</b> ?
|
||||
DisabledBecauseReplacedInvoice=Action désactivée car facture remplacée
|
||||
|
||||
|
||||
@ -6,14 +6,22 @@ NewExport=Nouvel export
|
||||
NewImport=Nouvel import
|
||||
ExportableDatas=Lot de données exportables
|
||||
ImportableDatas=Lot de données importables
|
||||
SelectImportDataSet=Choisissez un lot prédéfini de données que vous désirez importer...
|
||||
SelectExportDataSet=Choisissez un lot prédéfini de données que vous désirez exporter...
|
||||
SelectImportFields=Choisissez les champs à importer, ou choisissez un profil d'import prédéfini
|
||||
SelectExportFields=Choisissez les champs à exporter, ou choisissez un profil d'export prédéfini
|
||||
SaveExportModel=Enregistrer ce profil d'export si vous désirez le réutiliser ultérieurement...
|
||||
SaveImportModel=Enregistrer ce profil d'import si vous désirez le réutiliser ultérieurement...
|
||||
ExportModelName=Nom du profil d'export
|
||||
ExportModelSaved=Profil d'export sauvé sous le nom <b>%s</b>.
|
||||
ExportableFields=Champs exportables
|
||||
ExportedFields=Champs à exporter
|
||||
ImportModelName=Nom du profil d'import
|
||||
ImportModelSaved=Profil d'import sauvé sous le nom <b>%s</b>.
|
||||
ImportableFields=Champs importables
|
||||
ImportedFields=Champs à importer
|
||||
DatasetToExport=Lot de données à exporter
|
||||
DatasetToImport=Lot de données à importer
|
||||
Dataset=Lot de données
|
||||
ChooseFieldsOrdersAndTitle=Choisissez l'ordre des champs...
|
||||
FieldsOrder=Ordre des champs
|
||||
@ -32,6 +40,6 @@ FormatedExportDesc1=Cet espace permet de réaliser des exports personalisés des
|
||||
FormatedExportDesc2=La première étape est de choisir un des lots de données prédéfinis, ensuite de choisir les champs que vous voulez dans votre fichier résultat, et dans quel ordre.
|
||||
FormatedExportDesc3=Une fois les données sélectionnées, il est possible de choisir le format du fichier export généré.
|
||||
Sheet=Feuille
|
||||
NoImportableData=Pas de type de données importable (aucun module contenant des définitions de données importable n'est actif)
|
||||
NoImportableData=Pas tables de données importable (aucun module contenant des définitions de profils d'import n'est actif)
|
||||
FileSuccessfullyBuilt=Fichier export généré
|
||||
SQLUsedForExport=Requête SQL utilisée pour construire le fichier export
|
||||
@ -502,6 +502,7 @@ Page=Page
|
||||
Notes=Notes
|
||||
AddNewLine=Ajout nouvelle ligne
|
||||
FreeZone=Zone libre
|
||||
CloneMainAttributes=Cloner l'objet avec ces attributs principaux
|
||||
# Week day
|
||||
Day1=Lundi
|
||||
Day2=Mardi
|
||||
|
||||
@ -100,6 +100,8 @@ UseCustomerContactAsOrderRecipientIfExist=Utiliser adresse contact suivi client
|
||||
RunningOrders=Commandes en cours
|
||||
UserWithApproveOrderGrant=Utilisateurs habilités à approuver les commandes
|
||||
PaymentOrderRef=Paiement commande %s
|
||||
CloneOrder=Cloner commande
|
||||
ConfirmCloneOrder=Etes-vous sur de vouloir cloner cette commande <b>%s</b> ?
|
||||
|
||||
Error_COMMANDE_SUPPLIER_ADDON_NotDefined=Constante COMMANDE_SUPPLIER_ADDON non définie
|
||||
Error_COMMANDE_ADDON_NotDefined=Constante COMMANDE_ADDON non définie
|
||||
|
||||
@ -83,7 +83,7 @@ function ordersupplier_prepare_head($commande)
|
||||
$head = array();
|
||||
|
||||
$head[$h][0] = DOL_URL_ROOT.'/fourn/commande/fiche.php?id='.$commande->id;
|
||||
$head[$h][1] = $langs->trans("Card");
|
||||
$head[$h][1] = $langs->trans("OrderCard");
|
||||
$head[$h][2] = 'card';
|
||||
$h++;
|
||||
|
||||
@ -102,7 +102,7 @@ function ordersupplier_prepare_head($commande)
|
||||
$h++;
|
||||
|
||||
$head[$h][0] = DOL_URL_ROOT.'/fourn/commande/note.php?id='.$commande->id;
|
||||
$head[$h][1] = $langs->trans("Note");
|
||||
$head[$h][1] = $langs->trans("Notes");
|
||||
$head[$h][2] = 'note';
|
||||
$h++;
|
||||
|
||||
|
||||
@ -161,7 +161,15 @@ function llxHeader($head = '', $title='', $help_url='')
|
||||
if (! empty($conf->export->enabled))
|
||||
{
|
||||
$langs->load("exports");
|
||||
$menu->add(DOL_URL_ROOT."/exports/index.php", $langs->trans("Exports"));
|
||||
$menu->add_submenu(DOL_URL_ROOT."/exports/index.php?leftmenu=export",$langs->trans("FormatedExport"),0, $user->rights->export->lire);
|
||||
$menu->add_submenu(DOL_URL_ROOT."/exports/export.php?leftmenu=export",$langs->trans("NewExport"),1, $user->rights->export->creer);
|
||||
}
|
||||
|
||||
if (! empty($conf->global->MAIN_MODULE_IMPORT))
|
||||
{
|
||||
$langs->load("exports");
|
||||
$menu->add_submenu(DOL_URL_ROOT."/imports/index.php?leftmenu=import",$langs->trans("FormatedImport"),0, $user->rights->import->lire);
|
||||
$menu->add_submenu(DOL_URL_ROOT."/imports/import.php?leftmenu=import",$langs->trans("NewImport"),1, $user->rights->import->creer);
|
||||
}
|
||||
|
||||
if ($user->rights->user->user->lire || $user->admin)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user