diff --git a/htdocs/admin/import/dolibarrimport.class.php b/htdocs/admin/import/dolibarrimport.class.php deleted file mode 100644 index c4c60cd8521..00000000000 --- a/htdocs/admin/import/dolibarrimport.class.php +++ /dev/null @@ -1,183 +0,0 @@ - - * - * 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); - - } -} -?> diff --git a/htdocs/admin/import/import.php b/htdocs/admin/import/import.php deleted file mode 100644 index c8b8e5dcbf2..00000000000 --- a/htdocs/admin/import/import.php +++ /dev/null @@ -1,87 +0,0 @@ - - * - * 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 "
"; - -print '
'; -print ''; - -print ''; -print ''; - -print "\n"; -print '
Importer un fichier clients
"; -print '
'; -print '   '; -print '
'; - -print "
'; - - -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."
"; - print "Imports corrects : ".$imp->nb_import_ok."
"; - print "Imports erreurs : ".$imp->nb_import_ko."
"; - - } - else - { - $mesg = "Le fichier n'a pas été téléchargé"; - } -} - -$db->close(); - -llxFooter('$Date$ - $Revision$'); -?> diff --git a/htdocs/admin/import/pre.inc.php b/htdocs/admin/import/pre.inc.php deleted file mode 100644 index 6d17d2657bd..00000000000 --- a/htdocs/admin/import/pre.inc.php +++ /dev/null @@ -1,75 +0,0 @@ - - * Copyright (C) 2004-2006 Laurent Destailleur - * Copyright (C) 2005 Simon Tosser - * - * 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); -} - -?> diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index b1afbf7d9cb..7d866012ac2 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -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; diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index a7256f2fa57..825dfee37cd 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -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='
'.$langs->trans("NoCloneOptionsSpecified").'
'; + } + 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�passant la limite ? + // Echec transfert (fichier depassant la limite ?) $mesg = '
'.$langs->trans("ErrorFileNotUploaded").'
'; // print_r($_FILES); } @@ -1231,6 +1256,19 @@ else print '
'; } + // 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 '
'; + } + /* * Commande */ @@ -2001,6 +2039,12 @@ else } } + // Clone + if ($user->rights->commande->creer) + { + print ''.$langs->trans("ToClone").''; + } + // Delete order if ($user->rights->commande->supprimer) { diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index 00bd3e96f56..b3dc4baa055 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -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 ''.$langs->trans("NoExportableData").''; + print ''.$langs->trans("NoExportableData").''; } print ''; diff --git a/htdocs/exports/pre.inc.php b/htdocs/exports/pre.inc.php index f63eaa541b6..c83a81f1a58 100644 --- a/htdocs/exports/pre.inc.php +++ b/htdocs/exports/pre.inc.php @@ -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"); diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 9add64182b3..f4017b5ea00 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.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) { diff --git a/htdocs/imports/import.class.php b/htdocs/imports/import.class.php new file mode 100644 index 00000000000..b356173eea1 --- /dev/null +++ b/htdocs/imports/import.class.php @@ -0,0 +1,291 @@ + + * + * 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]
"); + 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]"."
"; + + // 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); + + } +} +?> diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php new file mode 100644 index 00000000000..4f5ed4e2033 --- /dev/null +++ b/htdocs/imports/import.php @@ -0,0 +1,796 @@ + + * Copyright (C) 2005-2007 Regis Houssin + * + * 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
"; + } + $_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� + $newcode=""; + foreach($array_selected as $code=>$value) + { + if ($value == $newpos) + { + $newcode=$code; + break; + } + } + //print("Switch pos=$pos (code=".$_GET["field"].") and newpos=$newpos (code=$newcode)"); + if ($newcode) // Si newcode trouv� (prtoection contre resoumission de page + { + $array_selected[$_GET["field"]]=$newpos; + $array_selected[$newcode]=$pos; + $_SESSION["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='
'.$objimport->error.'
'; + } + else + { + $mesg='
'.$langs->trans("FileSuccessfullyBuilt").'
'; + $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='
'.$langs->trans("ImportModelSaved",$objimport->model_name).'
'; + } + else + { + $langs->load("errors"); + if ($objimport->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $mesg='
'.$langs->trans("ErrorImportDuplicateProfil").'
'; + } + else $mesg='
'.$objimport->error.'
'; + } + } + else + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("ImportModelName")).'
'; + } +} + +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 ''; + + print $langs->trans("SelectImportDataSet").'
'; + + // Affiche les modules d'imports + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + $val=true; + if (sizeof($objimport->array_import_code)) + { + foreach ($objimport->array_import_code as $key => $value) + { + $val=!$val; + print ''; + } + } + else + { + print ''; + } + print '
'.$langs->trans("Module").''.$langs->trans("ImportableDatas").' 
'; + //print img_object($objimport->array_import_module[$key]->getName(),$import->array_import_module[$key]->picto).' '; + print $objimport->array_import_module[$key]->getName(); + print ''; + //print $value; + print img_object($objimport->array_import_module[$key]->getName(),$objimport->array_import_icon[$key]).' '; + print $objimport->array_import_label[$key]; + print ''; + if ($objimport->array_import_perms[$key]) + { + print ''.img_picto($langs->trans("NewImport"),'filenew').''; + } + else + { + print $langs->trans("NotEnoughPermissions"); + } + print '
'.$langs->trans("NoImportableData").'
'; + + print ''; + + print ''; + + 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 '
'; + print ''; + + print ''; + print ''; + + print "\n"; + print '
Importer un fichier clients
"; + print '
'; + print '   '; + print '
'; + + print "
'; + + 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."
"; + print "Imports corrects : ".$imp->nb_import_ok."
"; + print "Imports erreurs : ".$imp->nb_import_ko."
"; + + } + else + { + $mesg = "Le fichier n'a pas �t� t�l�charg�"; + } + } + + + print ''; + + // Module + print ''; + print ''; + + // Lot de donnees a importer + print ''; + print ''; + + print '
'.$langs->trans("Module").''; + //print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_module[0]->picto).' '; + print $objimport->array_import_module[0]->getName(); + print '
'.$langs->trans("DatasetToImport").''; + print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_icon[0]).' '; + print $objimport->array_import_label[0]; + print '
'; + print '
'; + + // Liste deroulante des modeles d'import + print '
'; + print ''; + print ''; + print ''; + print '
'; + print $langs->trans("SelectImportFields"); + print ''; + $htmlother->select_import_model($importmodelid,'importmodelid',$datatoimport,1); + print ''; + print '
'; + print '
'; + + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + // 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 ""; + + $i++; + + $entity=$objimport->array_import_entities[0][$code]; + $entityicon=$entitytoicon[$entity]?$entitytoicon[$entity]:$entity; + $entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$entity; + + print ''; + if ((isset($array_selected[$code]) && $array_selected[$code]) || $modelchoice == 1) + { + // Selected fields + print ''; + print ''; + print ''; + $bit=1; + } + else + { + // Fields not selected + print ''; + print ''; + print ''; + $bit=0; + } + + print ''; + $save_select.=$bit; + } + + print '
'.$langs->trans("Entities").''.$langs->trans("ImportableFields").''; + print ''.$langs->trans("All").""; + print '/'; + print ''.$langs->trans("None").""; + print ''.$langs->trans("ImportedFields").'
'.img_object('',$entityicon).' '.$langs->trans($entitylang).' '.img_left().''.$langs->trans($label).' ('.$code.')'.$langs->trans($label).' ('.$code.')'.img_right().' 
'; + + print ''; + + if ($mesg) print $mesg; + + /* + * Barre d'action + * + */ + print '
'; + + if (sizeof($array_selected)) + { + print ''.$langs->trans("NextStep").''; + } + else + { + print ''.$langs->trans("NextStep").''; + } + + print '
'; + +} + +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 ''; + + // Module + print ''; + print ''; + + // Lot de donn�es � importer + print ''; + print ''; + + // Nbre champs import�s + print ''; + $list=''; + foreach($array_selected as $code=>$value) + { + $list.=($list?',':''); + $list.=$langs->trans($objimport->array_import_fields[0][$code]); + } + print ''; + + print '
'.$langs->trans("Module").''; + //print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_module[0]->picto).' '; + print $objimport->array_import_module[0]->getName(); + print '
'.$langs->trans("DatasetToImport").''; + print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_icon[0]).' '; + print $objimport->array_import_label[0]; + print '
'.$langs->trans("ImportedFields").''.$list.'
'; + print '
'; + + print $langs->trans("ChooseFieldsOrdersAndTitle").'
'; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $var=true; + foreach($array_selected as $code=>$value) + { + $var=!$var; + print ""; + + $entity=$objimport->array_import_entities[0][$code]; + $entityicon=$entitytoicon[$entity]?$entitytoicon[$entity]:$entity; + $entitylang=$entitytolang[$entity]?$entitytolang[$entity]:$entity; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + } + + print '
'.$langs->trans("Entities").''.$langs->trans("ImportedFields").''.$langs->trans("Position").' '.$langs->trans("FieldsTitle").'
'.img_object('',$entityicon).' '.$langs->trans($entitylang).''.$langs->trans($objimport->array_import_fields[0][$code]).' ('.$code.')'; + print $value.' '; + print ''; + if ($value < sizeof($array_selected)) print ''.img_down().''; + if ($value > 1) print ''.img_up().''; + print ' '.$langs->trans($objimport->array_import_fields[0][$code]).'
'; + + + print ''; + + if ($mesg) print $mesg; + + /* + * Barre d'action + * + */ + print '
'; + + if (sizeof($array_selected)) + { + print ''.$langs->trans("NextStep").''; + } + + print '
'; + + + // Area for profils import + if (sizeof($array_selected)) + { + print '
'; + print $langs->trans("SaveImportModel"); + + print '
'; + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + $var=false; + print ''; + print ''; + + // 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 ''; + $i++; + } + } + else { + dol_print_error($this->db); + } + + print '
'.$langs->trans("ImportModelName").' 
'; + print ''; + print '
'; + print $obj->label; + print ''; + print 'rowid.'">'; + print img_delete(); + print ''; + print '
'; + print '
'; + } + +} + +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 ''; + + // Module + print ''; + print ''; + + // Lot de donnees a importer + print ''; + print ''; + + // Nbre champs importes + print ''; + $list=''; + foreach($array_selected as $code=>$label) + { + $list.=($list?',':''); + $list.=$langs->trans($objimport->array_import_fields[0][$code]); + } + print ''; + + print '
'.$langs->trans("Module").''; + //print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_module[0]->picto).' '; + print $objimport->array_import_module[0]->getName(); + print '
'.$langs->trans("DatasetToImport").''; + print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_icon[0]).' '; + print $objimport->array_import_label[0]; + print '
'.$langs->trans("ImportedFields").''.$list.'
'; + print '
'; + + print $langs->trans("NowClickToGenerateToBuildImportFile").'
'; + + // Liste des formats d'imports disponibles + $var=true; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $liste=$objmodelimport->liste_modeles($db); + foreach($liste as $key) + { + $var=!$var; + print ''; + } + print '
'.$langs->trans("AvailableFormats").''.$langs->trans("LibraryUsed").''.$langs->trans("LibraryVersion").'
'.$objmodelimport->getDriverLabel($key).''.$objmodelimport->getLibLabel($key).''.$objmodelimport->getLibVersion($key).'
'; + + print ''; + + print ''; + if ($mesg) + { + print ''; + } + if ($sqlusedforimport && $user->admin) + { + print ''; + } + print '
'; + print $mesg; + print '
'; + print info_admin($langs->trans("SQLUsedForImport").':
'.$sqlusedforimport); + print '
'; + + print ''; + print '
'; + + 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 ' 
'; + + // 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 '
'; + //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 '
'; + } +} + + +print '
'; + + +$db->close(); + +llxFooter('$Date$ - $Revision$'); +?> diff --git a/htdocs/admin/import/index.php b/htdocs/imports/index.php similarity index 76% rename from htdocs/admin/import/index.php rename to htdocs/imports/index.php index 2a50fbb2287..a900fbebbbd 100644 --- a/htdocs/admin/import/index.php +++ b/htdocs/imports/index.php @@ -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 '
'; print ''; -print '
'; +print '
'; -// Liste des formats d'exports disponibles +// Liste des formats d'imports disponibles $var=true; print ''; print ''; @@ -62,8 +62,8 @@ print ''; print ''; print ''; -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 '
'.$langs->trans("LibraryUsed").''.$langs->trans("LibraryVersion").'
'; -print '
'; +print ''; -// Affiche les modules d'exports +// Affiche les modules d'imports print ''; print ''; print ''; @@ -90,26 +90,26 @@ print ''; //print ''; print ''; $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 ''; // print ''; print ''; } - print ''; + print ''; } else { diff --git a/htdocs/imports/pre.inc.php b/htdocs/imports/pre.inc.php new file mode 100644 index 00000000000..c83a81f1a58 --- /dev/null +++ b/htdocs/imports/pre.inc.php @@ -0,0 +1,43 @@ + + * + * 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); +} + +?> diff --git a/htdocs/admin/import/sample.csv b/htdocs/imports/sample.csv similarity index 100% rename from htdocs/admin/import/sample.csv rename to htdocs/imports/sample.csv diff --git a/htdocs/includes/menus/barre_left/eldy_backoffice.php b/htdocs/includes/menus/barre_left/eldy_backoffice.php index 33d3e4b698e..3da1a614dcf 100644 --- a/htdocs/includes/menus/barre_left/eldy_backoffice.php +++ b/htdocs/includes/menus/barre_left/eldy_backoffice.php @@ -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)) diff --git a/htdocs/includes/menus/barre_left/eldy_frontoffice.php b/htdocs/includes/menus/barre_left/eldy_frontoffice.php index 3fc4ac9cf73..0657f3547d9 100644 --- a/htdocs/includes/menus/barre_left/eldy_frontoffice.php +++ b/htdocs/includes/menus/barre_left/eldy_frontoffice.php @@ -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"); diff --git a/htdocs/includes/menus/init_menu_auguria.sql b/htdocs/includes/menus/init_menu_auguria.sql index d2710fa0aa0..6a6414ef53d 100644 --- a/htdocs/includes/menus/init_menu_auguria.sql +++ b/htdocs/includes/menus/init_menu_auguria.sql @@ -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); diff --git a/htdocs/includes/modules/export/export_csv.modules.php b/htdocs/includes/modules/export/export_csv.modules.php index d829c624334..28ab9c5c63e 100644 --- a/htdocs/includes/modules/export/export_csv.modules.php +++ b/htdocs/includes/modules/export/export_csv.modules.php @@ -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 { diff --git a/htdocs/includes/modules/export/modules_export.php b/htdocs/includes/modules/export/modules_export.php index f79d1630fa5..bf29faa1d67 100644 --- a/htdocs/includes/modules/export/modules_export.php +++ b/htdocs/includes/modules/export/modules_export.php @@ -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�j� charg�es pour le bon datatoexport + * aussi le parametre datatoexport est inutilis� */ function build_file($model, $datatoexport, $array_selected) { diff --git a/htdocs/includes/modules/import/import_csv.modules.php b/htdocs/includes/modules/import/import_csv.modules.php new file mode 100644 index 00000000000..2281daf1df8 --- /dev/null +++ b/htdocs/includes/modules/import/import_csv.modules.php @@ -0,0 +1,212 @@ + +* +* 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?'"':''); + } + +} + +?> diff --git a/htdocs/includes/modules/import/modules_import.php b/htdocs/includes/modules/import/modules_import.php new file mode 100644 index 00000000000..7622c70cc61 --- /dev/null +++ b/htdocs/includes/modules/import/modules_import.php @@ -0,0 +1,164 @@ + + * Copyright (C) 2005-2007 Regis Houssin + * + * 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; + } + } + +} + + +?> diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 3ce3d75ab91..293d16c465f 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -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 %s ? DisabledBecauseReplacedInvoice=Action disabled because invoice has been replaced diff --git a/htdocs/langs/en_US/exports.lang b/htdocs/langs/en_US/exports.lang index 8376d4afa9b..80233930f48 100644 --- a/htdocs/langs/en_US/exports.lang +++ b/htdocs/langs/en_US/exports.lang @@ -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 %s. ExportableFields=Exportable fields ExportedFields=Exported fields +ImportModelName=Import profile name +ImportModelSaved=Import profile saved under name %s. +ImportableFields=Importable fields +ImportedFields=Imported fields DatasetToExport=Dataset to export +DatasetToImport=Dataset to import Dataset=Dataset ChooseFieldsOrdersAndTitle=Choose fields order... FieldsOrder=Fields order diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 2e3cf4f3e2a..b85bafcb45c 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -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 diff --git a/htdocs/langs/en_US/orders.lang b/htdocs/langs/en_US/orders.lang index f235005c70e..57f23abae51 100755 --- a/htdocs/langs/en_US/orders.lang +++ b/htdocs/langs/en_US/orders.lang @@ -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 %s ? Error_COMMANDE_SUPPLIER_ADDON_NotDefined=Constant COMMANDE_SUPPLIER_ADDON not defined Error_COMMANDE_ADDON_NotDefined=Constant COMMANDE_ADDON not defined diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang index 02fe6ecc0ea..b685b34de0e 100644 --- a/htdocs/langs/fr_FR/bills.lang +++ b/htdocs/langs/fr_FR/bills.lang @@ -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 %s ? DisabledBecauseReplacedInvoice=Action désactivée car facture remplacée diff --git a/htdocs/langs/fr_FR/exports.lang b/htdocs/langs/fr_FR/exports.lang index 122e6c2bc01..1c3657065ca 100644 --- a/htdocs/langs/fr_FR/exports.lang +++ b/htdocs/langs/fr_FR/exports.lang @@ -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 %s. ExportableFields=Champs exportables ExportedFields=Champs à exporter +ImportModelName=Nom du profil d'import +ImportModelSaved=Profil d'import sauvé sous le nom %s. +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 \ No newline at end of file diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 6dfb7d3f940..cc158e550d1 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -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 diff --git a/htdocs/langs/fr_FR/orders.lang b/htdocs/langs/fr_FR/orders.lang index e8c1b82d05e..f6c13ea2e08 100755 --- a/htdocs/langs/fr_FR/orders.lang +++ b/htdocs/langs/fr_FR/orders.lang @@ -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 %s ? Error_COMMANDE_SUPPLIER_ADDON_NotDefined=Constante COMMANDE_SUPPLIER_ADDON non définie Error_COMMANDE_ADDON_NotDefined=Constante COMMANDE_ADDON non définie diff --git a/htdocs/lib/fourn.lib.php b/htdocs/lib/fourn.lib.php index 794605e9197..eeb28facd23 100644 --- a/htdocs/lib/fourn.lib.php +++ b/htdocs/lib/fourn.lib.php @@ -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++; diff --git a/htdocs/pre.inc.php b/htdocs/pre.inc.php index ba5ced1fc25..00c0f2ccbcb 100644 --- a/htdocs/pre.inc.php +++ b/htdocs/pre.inc.php @@ -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)
'.$langs->trans("Module").''.$langs->trans("ImportableDatas").' 
'; - 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 ''; - $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 ''; -// print ''.img_picto($langs->trans("NewExport"),'filenew').''; +// print ''.img_picto($langs->trans("NewImport"),'filenew').''; // print '