From 2fbd6ac90c7d5a355da3446c7508032cda5cd09d Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 3 Feb 2006 16:42:39 +0000 Subject: [PATCH] integration support multiprix --- htdocs/admin/produit.php | 117 ++- htdocs/comm/addpropal.php | 7 +- htdocs/comm/fiche.php | 13 + htdocs/comm/propal.php | 7 +- htdocs/commande/commande.class.php | 35 +- htdocs/commande/fiche.php | 12 +- htdocs/compta/facture.php | 13 +- htdocs/contrat/contrat.class.php | 9 +- htdocs/contrat/fiche.php | 8 +- htdocs/master.inc.php | 1442 +++++++++++++++++++--------- htdocs/product.class.php | 240 ++++- htdocs/product/fiche.php | 51 +- htdocs/product/price.php | 83 +- htdocs/propal.class.php | 26 +- htdocs/societe.class.php | 33 +- 15 files changed, 1528 insertions(+), 568 deletions(-) diff --git a/htdocs/admin/produit.php b/htdocs/admin/produit.php index bc7e771582c..d2444b796b7 100644 --- a/htdocs/admin/produit.php +++ b/htdocs/admin/produit.php @@ -1,5 +1,6 @@ + * Copyright (C) 2006 Andre Cianfarani * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,8 +42,72 @@ if ($_POST["action"] == 'nbprod') Header("Location: produit.php"); exit; } - - +else if ($_POST["action"] == 'multiprix_num') +{ + dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", $_POST["value"]); + Header("Location: produit.php"); + exit; +} +if ($_GET["action"] == 'activate_multiprix') +{ + $res=$db -> desc_table(MAIN_DB_PREFIX."product_price","price_level"); + if(! $db -> fetch_row()) + { + // on ajoute le champ price_level dans la table product_price + $field_desc = array('type'=>'TINYINT','value'=>'4','default'=>'1'); + if(! $db -> add_field(MAIN_DB_PREFIX."product_price","price_level",$field_desc,"after date_price")) + { + dolibarr_print_error($db); + print ""; + } + else + { + // on ajoute le champ price_level dans la table societe + if(! $db -> add_field(MAIN_DB_PREFIX."societe","price_level",$field_desc)) + { + dolibarr_print_error($db); + print ""; + } + // on crée la table societe_prices + else + { + $table = MAIN_DB_PREFIX."societe_prices"; + $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); + $fields['fk_soc'] = array('type'=>'int','value'=>'11','null'=>'not null','default'=> '0'); + $fields['tms'] = array('type'=>'timestamp','value'=>'14','null'=>'not null'); + $fields['datec'] = array('type'=>'datetime','default'=> 'null'); + $fields['fk_user_author'] = array('type'=>'int','value'=>'11','default'=> 'null'); + $fields['price_level'] = array('type'=>'tinyint','value'=>'4','default'=> '1'); + if(! $db -> create_table($table,$fields,"rowid","MyISAM")) + { + dolibarr_print_error($db); + print ""; + } + else + { + dolibarr_set_const($db, "PRODUIT_MULTIPRICES", "1"); + dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", "6"); + Header("Location: produit.php"); + } + } + } + } + else + { + dolibarr_set_const($db, "PRODUIT_MULTIPRICES", "1"); + dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", "6"); + Header("Location: produit.php"); + } + exit; +} +else if ($_GET["action"] == 'disable_multiprix') +{ + //"ALTER TABLE ".MAIN_DB_PREFIX."product_price drop price_level" + dolibarr_del_const($db, "PRODUIT_MULTIPRICES"); + dolibarr_del_const($db, "PRODUIT_MULTIPRICES_LIMIT"); + Header("Location: produit.php"); + exit; +} /* * Affiche page @@ -72,6 +137,54 @@ print ''; print ''; print ''; +print '
'; + + +// multiprix activation/desactivation +print ''; +print ''; +print ''; +print ''; +print ''; +print "\n"; +print ""; +print ""; +print ""; +print ''; +print ''; +print ""; +print ''; +print '
'.$langs->trans("Name").' '.$langs->trans("Active").'
'.$langs->trans("MultiPricesAbility").''; +if($conf->global->PRODUIT_MULTIPRICES == 1) + print img_tick(); +print '"; +if($conf->global->PRODUIT_MULTIPRICES == 0) +print ''.$langs->trans("Activate").''; +else if($conf->global->PRODUIT_MULTIPRICES == 1) + print ''.$langs->trans("Disable").''; +print "
'; +print ''; +// multiprix nombre de prix a proposer +if($conf->global->PRODUIT_MULTIPRICES == 1) +{ + print '
'; + print "
"; + print ""; + print ""; + print ""; + print ' \n"; + print " \n"; + print " \n"; + print ""; + print ''; + print ""; + print ''; + print ''; + print '
'.$langs->trans("Name")."".$langs->trans("Value")." 
'.$langs->trans("MultiPricesNumPrices").'global->PRODUIT_MULTIPRICES_LIMIT."\">
'; + print '
'; +} + + $db->close(); diff --git a/htdocs/comm/addpropal.php b/htdocs/comm/addpropal.php index 597632b0870..74878aae2c6 100644 --- a/htdocs/comm/addpropal.php +++ b/htdocs/comm/addpropal.php @@ -1,6 +1,7 @@ * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2006 Andre Cianfarani * * 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 @@ -190,7 +191,11 @@ if ($_GET["action"] == 'create') for ($i = 1 ; $i <= PROPALE_NEW_FORM_NB_PRODUCT ; $i++) { print ''; - $form->select_produits('',"idprod".$i,'',$conf->produit->limit_size); + // multiprix + if($conf->global->PRODUIT_MULTIPRICES == 1) + $form->select_produits('',"idprod".$i,'',$conf->produit->limit_size,$soc->price_level); + else + $form->select_produits('',"idprod".$i,'',$conf->produit->limit_size); print ''; print ''; print ' %'; diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php index 2f397f0fa6b..ae012e9b813 100644 --- a/htdocs/comm/fiche.php +++ b/htdocs/comm/fiche.php @@ -2,6 +2,7 @@ /* Copyright (C) 2001-2005 Rodolphe Quiedeville * Copyright (C) 2004-2005 Laurent Destailleur * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2006 Andre Cianfarani * * 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 @@ -308,6 +309,18 @@ if ($_socid > 0) print ''; print ''; + // multiprix + if($conf->global->PRODUIT_MULTIPRICES == 1) + { + print ''; + print '
'; + print $langs->trans("PriceLevel"); + print ''; + print ''.img_edit($langs->trans("Modify")).''; + print '
'; + print ''.$objsoc->price_level.""; + print ''; + } print ""; diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index d1b4046f5b8..ef64c937529 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2005 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2006 Andre Cianfarani * * 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 @@ -882,7 +883,11 @@ if ($_GET['propalid'] > 0) $var=!$var; print ''; print ''; - $html->select_produits('','idprod','',$conf->produit->limit_size); + // multiprix + if($conf->global->PRODUIT_MULTIPRICES == 1) + $html->select_produits('','idprod','',$conf->produit->limit_size,$societe->price_level); + else + $html->select_produits('','idprod','',$conf->produit->limit_size); print '
'; print ''; print ''; diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index e5d285d5209..4f6f5336125 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -1,6 +1,7 @@ * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2006 Andre Cianfarani * * 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 @@ -216,6 +217,7 @@ class Commande */ function create($user) { + global $conf; /* On positionne en mode brouillon la commande */ $this->brouillon = 1; if (! $remise) @@ -241,12 +243,29 @@ class Commande $prod = new Product($this->db, $this->products[$i]); if ($prod->fetch($this->products[$i])) { - $this->insert_product_generic($prod->libelle, + // multiprix + if($conf->global->PRODUIT_MULTIPRICES == 1) + { + $this->soc_id; + $client = new Societe($this->db); + $client->fetch($this->soc_id); + //$prod->multiprices[$client->price_level] + $this->insert_product_generic($prod->libelle, + $prod->multiprices[$client->price_level], + $this->products_qty[$i], + $prod->tva_tx, + $this->products[$i], + $this->products_remise_percent[$i]); + } + else + { + $this->insert_product_generic($prod->libelle, $prod->price, $this->products_qty[$i], $prod->tva_tx, $this->products[$i], $this->products_remise_percent[$i]); + } } } $sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id; @@ -338,6 +357,7 @@ class Commande */ function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0) { + global $conf; // Nettoyage parametres $qty = ereg_replace(',','.',$qty); $pu = ereg_replace(',','.',$pu); @@ -358,7 +378,16 @@ class Commande if ($prod->fetch($fk_product) > 0) { $desc = $desc?$desc:$prod->libelle; - $pu = $prod->price; + // multiprix + if($conf->global->PRODUIT_MULTIPRICES == 1) + { + $client = new Societe($this->db); + $client->fetch($this->soc_id); + $pu = $prod->multiprices[$client->price_level]; + + } + else + $pu = $prod->price; $txtva = $prod->tva_tx; } } @@ -968,4 +997,4 @@ class CommandeLigne } } -?> \ No newline at end of file +?> diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 49aad3aa3be..933cc7e6e10 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -336,7 +336,11 @@ if ($_GET['action'] == 'create' && $user->rights->commande->creer) for ($i = 1 ; $i <= $NBLINES ; $i++) { print ''; - print $html->select_produits('','idprod'.$i,'',$conf->produit->limit_size); + // multiprix + if($conf->global->PRODUIT_MULTIPRICES == 1) + print $html->select_produits('','idprod'.$i,'',$conf->produit->limit_size,$soc->price_level); + else + print $html->select_produits('','idprod'.$i,'',$conf->produit->limit_size); print ''; print ''; print '%'; @@ -808,7 +812,11 @@ else $var=!$var; print ''; print ''; - $html->select_produits('','p_idprod','',$conf->produit->limit_size); + // multiprix + if($conf->global->PRODUIT_MULTIPRICES == 1) + $html->select_produits('','p_idprod','',$conf->produit->limit_size,$soc->price_level); + else + $html->select_produits('','p_idprod','',$conf->produit->limit_size); print '
'; print ''; print ''; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index feb80e3aeb8..2a568b957d3 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -3,6 +3,7 @@ * Copyright (C) 2004 Éric Seigne * Copyright (C) 2004-2005 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2006 Andre Cianfarani * * 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 @@ -763,7 +764,11 @@ if ($_GET['action'] == 'create') for ($i = 1 ; $i <= $NBLINES ; $i++) { print ''; - $html->select_produits('','idprod'.$i,'',$conf->produit->limit_size); + // multiprix + if($conf->global->PRODUIT_MULTIPRICES == 1) + $html->select_produits('','idprod'.$i,'',$conf->produit->limit_size,$soc->price_level); + else + $html->select_produits('','idprod'.$i,'',$conf->produit->limit_size); print ''; print ''; print '%'; @@ -1568,7 +1573,11 @@ else $var=! $var; print ''; print ''; - $html->select_produits('','idprod','',$conf->produit->limit_size); + // multiprix + if($conf->global->PRODUIT_MULTIPRICES == 1) + $html->select_produits('','idprod','',$conf->produit->limit_size,$soc->price_level); + else + $html->select_produits('','idprod','',$conf->produit->limit_size); print '
'; print ''; print ' '; diff --git a/htdocs/contrat/contrat.class.php b/htdocs/contrat/contrat.class.php index 6ba9c3f3ae2..a4e636417ee 100644 --- a/htdocs/contrat/contrat.class.php +++ b/htdocs/contrat/contrat.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2004-2005 Destailleur Laurent - * + * Copyright (C) 2006 Andre Cianfarani * 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 @@ -566,6 +566,7 @@ class Contrat function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $datestart, $dateend) { global $langs; + global $conf; dolibarr_syslog("contrat.class.php::addline $desc, $pu, $qty, $txtva, $fk_product, $remise_percent, $datestart, $dateend"); @@ -580,7 +581,11 @@ class Contrat if ($prod->fetch($fk_product) > 0) { $label = $prod->libelle; - $pu = $prod->price; + // multiprix + if($conf->global->PRODUIT_MULTIPRICES == 1) + $pu = $prod->multiprices[$this ->societe->price_level]; + else + $pu = $prod->price; $txtva = $prod->tva_tx; } } diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index 9ee543a5a8e..390c2a70ac9 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -1,7 +1,7 @@ * Copyright (C) 2004-2005 Laurent Destailleur - * + * Copyright (C) 2006 Andre Cianfarani * 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 @@ -809,7 +809,11 @@ else print ""; print ''; - $html->select_produits('','p_idprod','',$conf->produit->limit_size); + // multiprix + if($conf->global->PRODUIT_MULTIPRICES == 1) + $html->select_produits('','p_idprod','',$conf->produit->limit_size,$contrat->societe->price_level); + else + $html->select_produits('','p_idprod','',$conf->produit->limit_size); print '
'; print ''; print ''; diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index 418041b650c..1b2d53762ad 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -1,480 +1,962 @@ - - * Copyright (C) 2003 Xavier Dutoit - * Copyright (C) 2004 Laurent Destailleur - * Copyright (C) 2004 Sebastien Di Cintio - * Copyright (C) 2004 Benoit Mortier - * Copyright (C) 2005 Regis Houssin - * 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/master.inc.php - \brief Fichier de preparation de l'environnement Dolibarr - \version $Revision$ -*/ - -define('DOL_VERSION','2.1-alpha'); - -// La fonction clearstatcache ne doit pas etre appelé de manière globale car ralenti. -// Elle doit etre appelée uniquement par les pages qui ont besoin d'un cache fichier vidé, -// comme par exemple document.php -//clearstatcache(); - -// Forcage du parametrage PHP error_reporting (Dolibarr non utilisable en mode error E_ALL) -if (function_exists("define_syslog_variables")) -{ - define_syslog_variables(); -} -//error_reporting(E_ALL); -error_reporting(E_ALL ^ E_NOTICE); - -// Test si install ok -if (! @include_once("conf/conf.php")) -{ - Header("Location: install/index.php"); - exit; -} -else -{ - if (! isset($dolibarr_main_db_host)) - { - Header("Location: install/index.php"); - exit; - } -} - -if (! isset($dolibarr_main_db_type)) -{ - $dolibarr_main_db_type='mysql'; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql' -} -if (! $dolibarr_main_data_root) { - // Si repertoire documents non defini, on utilise celui par defaut - $dolibarr_main_data_root=ereg_replace("/htdocs","",$dolibarr_main_document_root); - $dolibarr_main_data_root.="/documents"; -} -define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root); -define('DOL_DATA_ROOT', $dolibarr_main_data_root); - -$uri=eregi_replace('^http(s?)://','',$dolibarr_main_url_root); -$pos = strstr ($uri, '/'); // $pos contient alors url sans nom domaine -if ($pos == '/') $pos = ''; // si $pos vaut /, on le met a '' -define('DOL_URL_ROOT', $pos); - - -/* - * Initialisation de l'objet $conf - */ -require_once(DOL_DOCUMENT_ROOT."/conf/conf.class.php"); -$conf = new Conf(); -$conf->db->host = $dolibarr_main_db_host; -$conf->db->name = $dolibarr_main_db_name; -$conf->db->user = $dolibarr_main_db_user; -$conf->db->pass = $dolibarr_main_db_pass; -$conf->db->type = $dolibarr_main_db_type; -if (! $conf->db->type) { $conf->db->type = 'mysql'; } // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql' -// Defini prefix -if (isset($_SERVER["LLX_DBNAME"])) $dolibarr_main_db_prefix=$_SERVER["LLX_DBNAME"]; -if (! isset($dolibarr_main_db_prefix) || ! $dolibarr_main_db_prefix) $dolibarr_main_db_prefix='llx_'; -$conf->db->prefix = $dolibarr_main_db_prefix; -define('MAIN_DB_PREFIX',$dolibarr_main_db_prefix); - -/* - * Chargement des includes principaux - */ -require_once(DOL_DOCUMENT_ROOT ."/lib/".$conf->db->type.".lib.php"); -require_once(DOL_DOCUMENT_ROOT ."/lib/functions.inc.php"); -require_once(DOL_DOCUMENT_ROOT ."/user.class.php"); -require_once(DOL_DOCUMENT_ROOT ."/menu.class.php"); -require_once(DOL_DOCUMENT_ROOT ."/html.form.class.php"); - - -$db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name); -if (! $db->connected) { - dolibarr_print_error($db,"host=".$conf->db->host.", user=".$conf->db->user.", databasename=".$conf->db->name.", ".$db->error); - exit; -} - - -$user = new User($db); - -/* - * Definition de toutes les Constantes globales d'environnement - * - En constante php (\todo a virer) - * - En $conf->global->key=value - */ -$sql = "SELECT name, value FROM ".MAIN_DB_PREFIX."const"; -$result = $db->query($sql); -if ($result) -{ - $numr = $db->num_rows($result); - $i = 0; - - while ($i < $numr) - { - $objp = $db->fetch_object($result); - $key=$objp->name; - $value=$objp->value; // Pas de stripslashes (ne s'applique pas sur lecture base mais après POST quand get_magic_quotes_gpc()==1) - define ("$key", $value); - $conf->global->$key=$value; - $i++; - } -} -$db->free($result); - -/* - * Nettoyage variables des gestionnaires de menu - * conf->menu_top et conf->menu_left sont d?finis dans main.inc.php (selon user) - */ -if (! $conf->global->MAIN_MENU_BARRETOP) $conf->global->MAIN_MENU_BARRETOP="default.php"; -if (! $conf->global->MAIN_MENUFRONT_BARRETOP) $conf->global->MAIN_MENUFRONT_BARRETOP="default.php"; -if (! $conf->global->MAIN_MENU_BARRELEFT) $conf->global->MAIN_MENU_BARRELEFT="default.php"; -if (! $conf->global->MAIN_MENUFRONT_BARRELEFT) $conf->global->MAIN_MENUFRONT_BARRELEFT="default.php"; - -/* - * Charge l'objet de traduction et positionne langage courant global - */ -if (! $conf->global->MAIN_LANG_DEFAULT) $conf->global->MAIN_LANG_DEFAULT="fr_FR"; - -require_once(DOL_DOCUMENT_ROOT ."/translate.class.php"); -$langs = new Translate(DOL_DOCUMENT_ROOT ."/langs"); -$langs->setDefaultLang($conf->global->MAIN_LANG_DEFAULT); -$langs->setPhpLang($conf->global->MAIN_LANG_DEFAULT); - - -/* - * Pour utiliser d'autres versions des librairies externes que les - * versions embarqu?es dans Dolibarr, d?finir les constantes adequates: - * Pour FPDF: FPDF_PATH - * Pour PEAR: PEAR_PATH - * Pour PHP_WriteExcel: PHP_WRITEEXCEL_PATH - * Pour PHPlot: PHPLOT_PATH - * Pour MagpieRss: MAGPIERSS_PATH - */ -if (! defined('FPDF_PATH')) { define('FPDF_PATH', DOL_DOCUMENT_ROOT .'/includes/fpdf/fpdf/'); } -if (! defined('PEAR_PATH')) { define('PEAR_PATH', DOL_DOCUMENT_ROOT .'/includes/pear/'); } -if (! defined('PHP_WRITEEXCEL_PATH')) { define('PHP_WRITEEXCEL_PATH',DOL_DOCUMENT_ROOT .'/includes/php_writeexcel/'); } -if (! defined('PHPLOT_PATH')) { define('PHPLOT_PATH', DOL_DOCUMENT_ROOT .'/includes/phplot/'); } -if (! defined('MAGPIERSS_PATH')) { define('MAGPIERSS_PATH', DOL_DOCUMENT_ROOT .'/includes/magpierss/'); } -if (! defined('JPGRAPH_PATH')) { define('JPGRAPH_PATH', DOL_DOCUMENT_ROOT .'/includes/jpgraph/'); } -define('FPDF_FONTPATH', FPDF_PATH . 'font/'); -define('MAGPIE_DIR', MAGPIERSS_PATH); - -// \todo Ajouter la ligne -// require_once(FPDF_PATH . "fpdf.php"); -// dans le fichier pdfdetail_standard_modeles du module telephonie afin de pouvoir la suivante -if (defined("MAIN_MODULE_TELEPHONIE") && MAIN_MODULE_TELEPHONIE) require_once(FPDF_PATH . "fpdf.php"); - -/* - * Autres parametres globaux de configurations - */ -$conf->users->dir_output=DOL_DATA_ROOT."/users"; - -/* - * Utilise dans tous les upload de fichier - * necessaire pour desactiver dans la demo - */ -if (defined('MAIN_UPLOAD_DOC') && MAIN_UPLOAD_DOC == 1) -{ - $conf->upload = 1; -} -else -{ - $conf->upload = 0; -} - - -/* - * Definition des parametres d'activation de module et dependants des modules - * Chargement d'include selon etat activation des modules - */ - -// Module bookmark4u -$conf->bookmark4u->enabled=defined('MAIN_MODULE_BOOKMARK4U')?MAIN_MODULE_BOOKMARK4U:0; -$conf->bookmark->enabled=defined('MAIN_MODULE_BOOKMARK')?MAIN_MODULE_BOOKMARK:0; -// Module deplacement -$conf->deplacement->enabled=defined("MAIN_MODULE_DEPLACEMENT")?MAIN_MODULE_DEPLACEMENT:0; -// Module mailing -$conf->mailing->enabled=defined("MAIN_MODULE_MAILING")?MAIN_MODULE_MAILING:0; -// Module externalrss -$conf->externalrss->enabled=defined("MAIN_MODULE_EXTERNALRSS")?MAIN_MODULE_EXTERNALRSS:0; -// Module commande client -$conf->commande->enabled=defined("MAIN_MODULE_COMMANDE")?MAIN_MODULE_COMMANDE:0; -$conf->commande->dir_output=DOL_DATA_ROOT."/commande"; -$conf->commande->dir_images=DOL_DATA_ROOT."/commande/images"; -// Module expeditions -$conf->expedition->enabled=defined("MAIN_MODULE_EXPEDITION")?MAIN_MODULE_EXPEDITION:0; -$conf->expedition->dir_output=DOL_DATA_ROOT."/expedition"; -$conf->expedition->dir_images=DOL_DATA_ROOT."/expedition/images"; -// Module societe -$conf->societe->enabled=defined("MAIN_MODULE_SOCIETE")?MAIN_MODULE_SOCIETE:0; -$conf->societe->dir_output=DOL_DATA_ROOT."/societe"; -$conf->societe->dir_images=DOL_DATA_ROOT."/societe/images"; -if (defined('SOCIETE_OUTPUTDIR') && SOCIETE_OUTPUTDIR) { $conf->societe->dir_output=SOCIETE_OUTPUTDIR; } # Pour passer outre le rep par d?faut -// Module commercial -$conf->commercial->enabled=defined("MAIN_MODULE_COMMERCIAL")?MAIN_MODULE_COMMERCIAL:0; -$conf->commercial->dir_output=DOL_DATA_ROOT."/rapport"; -// Module comptaexpert -$conf->comptaexpert->enabled=defined("MAIN_MODULE_COMPTABILITE_EXPERT")?MAIN_MODULE_COMPTABILITE_EXPERT:0; -$conf->comptaexpert->dir_output=DOL_DATA_ROOT."/comptaexpert"; -$conf->comptaexpert->dir_images=DOL_DATA_ROOT."/comptaexpert/images"; -// Module compta -$conf->compta->enabled=defined("MAIN_MODULE_COMPTABILITE")?MAIN_MODULE_COMPTABILITE:0; -$conf->compta->dir_output=DOL_DATA_ROOT."/compta"; -$conf->compta->dir_images=DOL_DATA_ROOT."/compta/images"; -// Module banque -$conf->banque->enabled=defined("MAIN_MODULE_BANQUE")?MAIN_MODULE_BANQUE:0; -$conf->banque->dir_output=DOL_DATA_ROOT."/banque"; -$conf->banque->dir_images=DOL_DATA_ROOT."/banque/images"; -// Module don -$conf->don->enabled=defined("MAIN_MODULE_DON")?MAIN_MODULE_DON:0; -$conf->don->dir_output=DOL_DATA_ROOT."/dons"; -$conf->don->dir_images=DOL_DATA_ROOT."/dons/images"; -// Module syslog -$conf->syslog->enabled=defined("MAIN_MODULE_SYSLOG")?MAIN_MODULE_SYSLOG:0; -// Module fournisseur -$conf->fournisseur->enabled=defined("MAIN_MODULE_FOURNISSEUR")?MAIN_MODULE_FOURNISSEUR:0; -// Module ficheinter -$conf->fichinter->enabled=defined("MAIN_MODULE_FICHEINTER")?MAIN_MODULE_FICHEINTER:0; -$conf->fichinter->dir_output=DOL_DATA_ROOT."/ficheinter"; -$conf->fichinter->dir_images=DOL_DATA_ROOT."/ficheinter/images"; -if (defined('FICHEINTER_OUTPUTDIR') && FICHEINTER_OUTPUTDIR) { $conf->fichinter->dir_output=FICHEINTER_OUTPUTDIR; } # Pour passer outre le rep par defaut -// Module adherent -$conf->adherent->enabled=defined("MAIN_MODULE_ADHERENT")?MAIN_MODULE_ADHERENT:0; -$conf->adherent->dir_output=DOL_DATA_ROOT."/adherent"; -// Module produit -$conf->produit->enabled=defined("MAIN_MODULE_PRODUIT")?MAIN_MODULE_PRODUIT:0; -$conf->produit->dir_output=DOL_DATA_ROOT."/produit"; -$conf->produit->dir_images=DOL_DATA_ROOT."/produit/images"; -// Module service -$conf->service->enabled=defined("MAIN_MODULE_SERVICE")?MAIN_MODULE_SERVICE:0; -$conf->service->dir_output=DOL_DATA_ROOT."/produit"; -$conf->service->dir_images=DOL_DATA_ROOT."/produit/images"; -// Module stock -$conf->stock->enabled=defined("MAIN_MODULE_STOCK")?MAIN_MODULE_STOCK:0; -// Module code barre -$conf->barcode->enabled=defined("MAIN_MODULE_BARCODE")?MAIN_MODULE_BARCODE:0; -// Module categorie -$conf->categorie->enabled=defined("MAIN_MODULE_CATEGORIE")?MAIN_MODULE_CATEGORIE:0; -// Module contrat -$conf->contrat->enabled=defined("MAIN_MODULE_CONTRAT")?MAIN_MODULE_CONTRAT:0; -// Module projet -$conf->projet->enabled=defined("MAIN_MODULE_PROJET")?MAIN_MODULE_PROJET:0; -// Module oscommerce -$conf->boutique->enabled=defined("MAIN_MODULE_BOUTIQUE")?MAIN_MODULE_BOUTIQUE:0; -$conf->boutique->livre->enabled=defined("BOUTIQUE_LIVRE")?BOUTIQUE_LIVRE:0; -$conf->boutique->album->enabled=defined("BOUTIQUE_ALBUM")?BOUTIQUE_ALBUM:0; -// Module postnuke -$conf->postnuke->enabled=defined("MAIN_MODULE_POSTNUKE")?MAIN_MODULE_POSTNUKE:0; -// Module clicktodial -$conf->clicktodial->enabled=defined("MAIN_MODULE_CLICKTODIAL")?MAIN_MODULE_CLICKTODIAL:0; -// Module prelevement -$conf->prelevement->enabled=defined("MAIN_MODULE_PRELEVEMENT")?MAIN_MODULE_PRELEVEMENT:0; -$conf->prelevement->dir_output=DOL_DATA_ROOT."/prelevement"; -$conf->prelevement->dir_images=DOL_DATA_ROOT."/prelevement/images"; -// Module webcal -$conf->webcal->enabled=defined('MAIN_MODULE_WEBCALENDAR')?MAIN_MODULE_WEBCALENDAR:0; -$conf->webcal->db->type=defined('PHPWEBCALENDAR_TYPE')?PHPWEBCALENDAR_TYPE:'mysql'; -$conf->webcal->db->host=defined('PHPWEBCALENDAR_HOST')?PHPWEBCALENDAR_HOST:''; -$conf->webcal->db->user=defined('PHPWEBCALENDAR_USER')?PHPWEBCALENDAR_USER:''; -$conf->webcal->db->pass=defined('PHPWEBCALENDAR_PASS')?PHPWEBCALENDAR_PASS:''; -$conf->webcal->db->name=defined('PHPWEBCALENDAR_DBNAME')?PHPWEBCALENDAR_DBNAME:''; -// Module facture -$conf->facture->enabled=defined("MAIN_MODULE_FACTURE")?MAIN_MODULE_FACTURE:0; -// \todo Ajouter la ligne -// require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php"); -// dans le fichier facturation-emission.php du module telephonie afin de pouvoir supprimer la suivante -if (defined("MAIN_MODULE_TELEPHONIE") && MAIN_MODULE_TELEPHONIE) require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php"); -$conf->facture->dir_output=DOL_DATA_ROOT."/facture"; -$conf->facture->dir_images=DOL_DATA_ROOT."/facture/images"; -if (defined('FAC_OUTPUTDIR') && FAC_OUTPUTDIR) { $conf->facture->dir_output=FAC_OUTPUTDIR; } # Pour passer outre le rep par defaut -// Module propal -$conf->propal->enabled=defined("MAIN_MODULE_PROPALE")?MAIN_MODULE_PROPALE:0; -if (! defined("PROPALE_NEW_FORM_NB_PRODUCT")) define("PROPALE_NEW_FORM_NB_PRODUCT", 4); -$conf->propal->dir_output=DOL_DATA_ROOT."/propale"; -$conf->propal->dir_images=DOL_DATA_ROOT."/propale/images"; -if (defined('PROPALE_OUTPUTDIR') && PROPALE_OUTPUTDIR) { $conf->propal->dir_output=PROPALE_OUTPUTDIR; } # Pour passer outre le rep par defaut -// Module telephonie -$conf->telephonie->enabled=defined("MAIN_MODULE_TELEPHONIE")?MAIN_MODULE_TELEPHONIE:0; -$conf->telephonie->dir_output=DOL_DATA_ROOT."/telephonie"; -$conf->telephonie->dir_images=DOL_DATA_ROOT."/telephonie/images"; -// Module energie -$conf->energie->enabled=defined("MAIN_MODULE_ENERGIE")?MAIN_MODULE_ENERGIE:0; -// Module domaine -$conf->domaine->enabled=0; -// Module voyage -$conf->voyage->enabled=0; -// Module actionscomm -$conf->actionscomm->dir_output=DOL_DATA_ROOT."/action"; -// Module export -$conf->export->enabled=defined("MAIN_MODULE_EXPORT")?MAIN_MODULE_EXPORT:0; -$conf->export->dir_ouput=DOL_DATA_ROOT."/export"; - - -/* - * Modification de quelques variable de conf en fonction des Constantes - */ - -// conf->use_preview_tabs -$conf->use_preview_tabs=1; -if (isset($conf->global->MAIN_USE_PREVIEW_TABS)) $conf->use_preview_tabs=$conf->global->MAIN_USE_PREVIEW_TABS; - -// conf->use_javascript -$conf->use_javascript=1; -if (isset($conf->global->MAIN_DISABLE_JAVASCRIPT)) $conf->use_javascript=! $conf->global->MAIN_DISABLE_JAVASCRIPT; - -// conf->monnaie -if (! $conf->global->MAIN_MONNAIE) $conf->global->MAIN_MONNAIE='EUR'; -$conf->monnaie=$conf->global->MAIN_MONNAIE; - -// $conf->compta->mode = Option du module Compta: Defini le mode de calcul des etats comptables (CA,...) -$conf->compta->mode = 'RECETTES-DEPENSES'; // Par d?faut -if (defined('COMPTA_MODE') && COMPTA_MODE) { - // Peut etre 'RECETTES-DEPENSES' ou 'CREANCES-DETTES' - $conf->compta->mode = COMPTA_MODE; -} - -// $conf->defaulttx -if (defined('FACTURE_TVAOPTION') && FACTURE_TVAOPTION == 'franchise') { - $conf->defaulttx='0'; // Taux par d?faut des factures clients -} -else { - $conf->defaulttx=''; // Pas de taux par d?faut des factures clients, le premier sera pris -} - -// $conf->liste_limit = constante de taille maximale des listes -if (! $conf->global->SIZE_LISTE_LIMIT) $conf->global->SIZE_LISTE_LIMIT=20; -$conf->liste_limit=$conf->global->SIZE_LISTE_LIMIT; - -// $conf->produit->limit_size = constante de taille maximale des select de produit -if (! isset($conf->global->PRODUIT_LIMIT_SIZE)) $conf->global->PRODUIT_LIMIT_SIZE=50; -$conf->produit->limit_size=$conf->global->PRODUIT_LIMIT_SIZE; - -// $conf->theme et $conf->css -if (! $conf->global->MAIN_THEME) $conf->global->MAIN_THEME="eldy"; -$conf->theme=$conf->global->MAIN_THEME; -$conf->css = "theme/".$conf->theme."/".$conf->theme.".css"; - -// $conf->email_from = email pour envoi par Dolibarr des mails auto (notifications, ...) -// $conf->mailing->email_from = email pour envoi par Dolibarr des mailings -$conf->email_from="dolibarr-robot@domain.com"; -if (defined('MAIN_EMAIL_FROM')) -{ - $conf->email_from=MAIN_EMAIL_FROM; -} -if (defined('MAILING_EMAIL_FROM')) -{ - $conf->mailing->email_from=MAILING_EMAIL_FROM; -} -else $conf->mailing->email_from=$conf->email_from; - -// $conf->adherent->email_resil, ... -if (defined("MAIN_MAIL_RESIL")) -{ - $conf->adherent->email_resil=MAIN_MAIL_RESIL; -} -if (defined("MAIN_MAIL_RESIL_SUBJECT")) -{ - $conf->adherent->email_resil_subject=MAIN_MAIL_RESIL_SUBJECT; -} -if (defined("MAIN_MAIL_VALID")) -{ - $conf->adherent->email_valid=MAIN_MAIL_VALID; -} -if (defined("MAIN_MAIL_VALID_SUBJECT")) -{ - $conf->adherent->email_valid_subject=MAIN_MAIL_VALID_SUBJECT; -} -if (defined("MAIN_MAIL_EDIT")) -{ - $conf->adherent->email_edit=MAIN_MAIL_EDIT; -} -if (defined("MAIN_MAIL_EDIT_SUBJECT")) -{ - $conf->adherent->email_edit_subject=MAIN_MAIL_EDIT_SUBJECT; -} -if (defined("MAIN_MAIL_NEW")) -{ - $conf->adherent->email_new=MAIN_MAIL_NEW; -} -if (defined("MAIN_MAIL_NEW_SUBJECT")) -{ - $conf->adherent->email_new_subject=MAIN_MAIL_NEW_SUBJECT; -} - -// Format de la date -// \todo Mettre format dans fichier langue -$conf->format_date_text_short="%d %b %Y"; -$conf->format_date_short="%d/%m/%Y"; - - -/* - * Creation objet mysoc - * Objet Societe qui contient carac de l'institution gérée par Dolibarr. - */ -require_once(DOL_DOCUMENT_ROOT ."/societe.class.php"); -$mysoc=new Societe($db); -$mysoc->id=0; -$mysoc->nom=$conf->global->MAIN_INFO_SOCIETE_NOM; -$mysoc->adresse=$conf->global->MAIN_INFO_SOCIETE_ADRESSE; -$mysoc->cp=$conf->global->MAIN_INFO_SOCIETE_CP; -$mysoc->ville=$conf->global->MAIN_INFO_SOCIETE_VILLE; -$mysoc->pays_code=$conf->global->MAIN_INFO_SOCIETE_PAYS; -$mysoc->tel=$conf->global->MAIN_INFO_SOCIETE_TEL; -$mysoc->fax=$conf->global->MAIN_INFO_SOCIETE_FAX; -$mysoc->url=$conf->global->MAIN_INFO_SOCIETE_WEB; -$mysoc->siren=$conf->global->MAIN_INFO_SIREN; -$mysoc->siret=$conf->global->MAIN_INFO_SIRET; -$mysoc->ape=$conf->global->MAIN_INFO_APE; -$mysoc->rcs=$conf->global->MAIN_INFO_RCS; -$mysoc->tvaintra=$conf->global->MAIN_INFO_TVAINTRA; -$mysoc->capital=$conf->global->MAIN_INFO_CAPITAL; -$mysoc->forme_juridique_code=$conf->global->MAIN_INFO_FORME_JURIDIQUE; -$mysoc->email=$conf->global->MAIN_INFO_SOCIETE_MAIL; - - -/* \todo Ajouter une option Gestion de la TVA dans le module compta qui permet de d?sactiver la fonction TVA - * (pour particuliers ou lib?raux en franchise) - * En attendant, valeur forc?e ? 1 - */ -$conf->compta->tva=1; - -// Delais de tolerance des alertes -$conf->actions->warning_delay=$conf->global->MAIN_DELAY_ACTIONS_TODO*24*60*60; -$conf->commande->traitement->warning_delay=$conf->global->MAIN_DELAY_ORDERS_TO_PROCESS*24*60*60; -$conf->propal->cloture->warning_delay=$conf->global->MAIN_DELAY_PROPALS_TO_CLOSE*24*60*60; -$conf->propal->facturation->warning_delay=$conf->global->MAIN_DELAY_PROPALS_TO_BILL*24*60*60; -$conf->facture->fournisseur->warning_delay=$conf->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY*24*60*60; -$conf->facture->client->warning_delay=$conf->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED*24*60*60; -$conf->contrat->services->inactifs->warning_delay=$conf->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES*24*60*60; -$conf->contrat->services->expires->warning_delay=$conf->global->MAIN_DELAY_RUNNING_SERVICES*24*60*60; -$conf->adherent->cotisation->warning_delay=$conf->global->MAIN_DELAY_MEMBERS*24*60*60; -$conf->bank->rappro->warning_delay=$conf->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE*24*60*60; - - -/* - */ -$bc[0]="class=\"impair\""; -$bc[1]="class=\"pair\""; -$yesno[0]="no"; -$yesno[1]="yes"; - -if ( ! defined('MENTION_NPR') ) define('MENTION_NPR','(npr)'); -?> + + * Copyright (C) 2003 Xavier Dutoit + * Copyright (C) 2004 Laurent Destailleur + * Copyright (C) 2004 Sebastien Di Cintio + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2005 Regis Houssin + * Copyright (C) 2005 Simon Tosser + * Copyright (C) 2005 Andre Cianfarani + * + * 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/master.inc.php + \brief Fichier de preparation de l'environnement Dolibarr + \version $Revision$ +*/ + +define('DOL_VERSION','2.0.0-alpha2'); + +// La fonction clearstatcache ne doit pas etre appel�de mani�e globale car ralenti. +// Elle doit etre appel� uniquement par les pages qui ont besoin d'un cache fichier vid� +// comme par exemple document.php +//clearstatcache(); + +// Forcage du parametrage PHP error_reporting (Dolibarr non utilisable en mode error E_ALL) +if (function_exists("define_syslog_variables")) +{ + define_syslog_variables(); +} +//error_reporting(E_ALL); +error_reporting(E_ALL ^ E_NOTICE); + +// Test si install ok +if (! @include_once("conf/conf.php")) +{ + Header("Location: install/index.php"); + exit; +} +else +{ + if (! isset($dolibarr_main_db_host)) + { + Header("Location: install/index.php"); + exit; + } +} + +if (! isset($dolibarr_main_db_type)) +{ + $dolibarr_main_db_type='mysql'; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql' +} +if (! $dolibarr_main_data_root) { + // Si repertoire documents non defini, on utilise celui par defaut + $dolibarr_main_data_root=ereg_replace("/htdocs","",$dolibarr_main_document_root); + $dolibarr_main_data_root.="/documents"; +} +define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root); +define('DOL_DATA_ROOT', $dolibarr_main_data_root); + +$uri=eregi_replace('^http(s?)://','',$dolibarr_main_url_root); +$pos = strstr ($uri, '/'); // $pos contient alors url sans nom domaine +if ($pos == '/') $pos = ''; // si $pos vaut /, on le met a '' +define('DOL_URL_ROOT', $pos); + + +/* + * Initialisation de l'objet $conf + */ +require_once(DOL_DOCUMENT_ROOT."/conf/conf.class.php"); +$conf = new Conf(); +$conf->db->host = $dolibarr_main_db_host; +$conf->db->name = $dolibarr_main_db_name; +$conf->db->user = $dolibarr_main_db_user; +$conf->db->pass = $dolibarr_main_db_pass; +$conf->db->type = $dolibarr_main_db_type; +if (! $conf->db->type) { $conf->db->type = 'mysql'; } // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql' +// Defini prefix +if (isset($_SERVER["LLX_DBNAME"])) $dolibarr_main_db_prefix=$_SERVER["LLX_DBNAME"]; +if (! isset($dolibarr_main_db_prefix) || ! $dolibarr_main_db_prefix) $dolibarr_main_db_prefix='llx_'; +$conf->db->prefix = $dolibarr_main_db_prefix; +define('MAIN_DB_PREFIX',$dolibarr_main_db_prefix); + +/* + * Chargement des includes principaux + */ +require_once(DOL_DOCUMENT_ROOT ."/lib/".$conf->db->type.".lib.php"); +require_once(DOL_DOCUMENT_ROOT ."/lib/functions.inc.php"); +require_once(DOL_DOCUMENT_ROOT ."/user.class.php"); +require_once(DOL_DOCUMENT_ROOT ."/menu.class.php"); +require_once(DOL_DOCUMENT_ROOT ."/html.form.class.php"); + + +$db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name); +if (! $db->connected) { + dolibarr_print_error($db,"host=".$conf->db->host.", user=".$conf->db->user.", databasename=".$conf->db->name.", ".$db->error); + exit; +} + + +$user = new User($db); + +/* + * Definition de toutes les Constantes globales d'environnement + * - En constante php (\todo a virer) + * - En $conf->global->key=value + */ +$sql = "SELECT name, value FROM ".MAIN_DB_PREFIX."const"; +$result = $db->query($sql); +if ($result) +{ + $numr = $db->num_rows($result); + $i = 0; + + while ($i < $numr) + { + $objp = $db->fetch_object($result); + $key=$objp->name; + $value=$objp->value; // Pas de stripslashes (ne s'applique pas sur lecture base mais apr� POST quand get_magic_quotes_gpc()==1) + define ("$key", $value); + $conf->global->$key=$value; + $i++; + } +} +$db->free($result); + +/* + * Nettoyage variables des gestionnaires de menu + * conf->menu_top et conf->menu_left sont d?finis dans main.inc.php (selon user) + */ +if (! $conf->global->MAIN_MENU_BARRETOP) $conf->global->MAIN_MENU_BARRETOP="default.php"; +if (! $conf->global->MAIN_MENUFRONT_BARRETOP) $conf->global->MAIN_MENUFRONT_BARRETOP="default.php"; +if (! $conf->global->MAIN_MENU_BARRELEFT) $conf->global->MAIN_MENU_BARRELEFT="default.php"; +if (! $conf->global->MAIN_MENUFRONT_BARRELEFT) $conf->global->MAIN_MENUFRONT_BARRELEFT="default.php"; + +/* + * Charge l'objet de traduction et positionne langage courant global + */ +if (! $conf->global->MAIN_LANG_DEFAULT) $conf->global->MAIN_LANG_DEFAULT="fr_FR"; + +require_once(DOL_DOCUMENT_ROOT ."/translate.class.php"); +$langs = new Translate(DOL_DOCUMENT_ROOT ."/langs"); +$langs->setDefaultLang($conf->global->MAIN_LANG_DEFAULT); +$langs->setPhpLang($conf->global->MAIN_LANG_DEFAULT); + + +/* + * Pour utiliser d'autres versions des librairies externes que les + * versions embarqu?es dans Dolibarr, d?finir les constantes adequates: + * Pour FPDF: FPDF_PATH + * Pour PEAR: PEAR_PATH + * Pour PHP_WriteExcel: PHP_WRITEEXCEL_PATH + * Pour PHPlot: PHPLOT_PATH + * Pour MagpieRss: MAGPIERSS_PATH + */ +if (! defined('FPDF_PATH')) { define('FPDF_PATH', DOL_DOCUMENT_ROOT .'/includes/fpdf/fpdf/'); } +if (! defined('PEAR_PATH')) { define('PEAR_PATH', DOL_DOCUMENT_ROOT .'/includes/pear/'); } +if (! defined('PHP_WRITEEXCEL_PATH')) { define('PHP_WRITEEXCEL_PATH',DOL_DOCUMENT_ROOT .'/includes/php_writeexcel/'); } +if (! defined('PHPLOT_PATH')) { define('PHPLOT_PATH', DOL_DOCUMENT_ROOT .'/includes/phplot/'); } +if (! defined('MAGPIERSS_PATH')) { define('MAGPIERSS_PATH', DOL_DOCUMENT_ROOT .'/includes/magpierss/'); } +if (! defined('JPGRAPH_PATH')) { define('JPGRAPH_PATH', DOL_DOCUMENT_ROOT .'/includes/jpgraph/'); } +define('FPDF_FONTPATH', FPDF_PATH . 'font/'); +define('MAGPIE_DIR', MAGPIERSS_PATH); + +// \todo Ajouter la ligne +// require_once(FPDF_PATH . "fpdf.php"); +// dans le fichier pdfdetail_standard_modeles du module telephonie afin de pouvoir la suivante +if (defined("MAIN_MODULE_TELEPHONIE") && MAIN_MODULE_TELEPHONIE) require_once(FPDF_PATH . "fpdf.php"); + +/* + * Autres parametres globaux de configurations + */ +$conf->users->dir_output=DOL_DATA_ROOT."/users"; + +/* + * Utilise dans tous les upload de fichier + * necessaire pour desactiver dans la demo + */ +if (defined('MAIN_UPLOAD_DOC') && MAIN_UPLOAD_DOC == 1) +{ + $conf->upload = 1; +} +else +{ + $conf->upload = 0; +} + + +/* + * Definition des parametres d'activation de module et dependants des modules + * Chargement d'include selon etat activation des modules + */ + +// Module bookmark4u +$conf->bookmark4u->enabled=defined('MAIN_MODULE_BOOKMARK4U')?MAIN_MODULE_BOOKMARK4U:0; +$conf->bookmark->enabled=defined('MAIN_MODULE_BOOKMARK')?MAIN_MODULE_BOOKMARK:0; +// Module deplacement +$conf->deplacement->enabled=defined("MAIN_MODULE_DEPLACEMENT")?MAIN_MODULE_DEPLACEMENT:0; +// Module mailing +$conf->mailing->enabled=defined("MAIN_MODULE_MAILING")?MAIN_MODULE_MAILING:0; +// Module externalrss +$conf->externalrss->enabled=defined("MAIN_MODULE_EXTERNALRSS")?MAIN_MODULE_EXTERNALRSS:0; +// Module commande client +$conf->commande->enabled=defined("MAIN_MODULE_COMMANDE")?MAIN_MODULE_COMMANDE:0; +$conf->commande->dir_output=DOL_DATA_ROOT."/commande"; +$conf->commande->dir_images=DOL_DATA_ROOT."/commande/images"; +// Module expeditions +$conf->expedition->enabled=defined("MAIN_MODULE_EXPEDITION")?MAIN_MODULE_EXPEDITION:0; +$conf->expedition->dir_output=DOL_DATA_ROOT."/expedition"; +$conf->expedition->dir_images=DOL_DATA_ROOT."/expedition/images"; +// Module societe +$conf->societe->enabled=defined("MAIN_MODULE_SOCIETE")?MAIN_MODULE_SOCIETE:0; +$conf->societe->dir_output=DOL_DATA_ROOT."/societe"; +$conf->societe->dir_images=DOL_DATA_ROOT."/societe/images"; +if (defined('SOCIETE_OUTPUTDIR') && SOCIETE_OUTPUTDIR) { $conf->societe->dir_output=SOCIETE_OUTPUTDIR; } # Pour passer outre le rep par d?faut +// Module commercial +$conf->commercial->enabled=defined("MAIN_MODULE_COMMERCIAL")?MAIN_MODULE_COMMERCIAL:0; +$conf->commercial->dir_output=DOL_DATA_ROOT."/rapport"; +// Module comptaexpert +$conf->comptaexpert->enabled=defined("MAIN_MODULE_COMPTABILITE_EXPERT")?MAIN_MODULE_COMPTABILITE_EXPERT:0; +$conf->comptaexpert->dir_output=DOL_DATA_ROOT."/comptaexpert"; +$conf->comptaexpert->dir_images=DOL_DATA_ROOT."/comptaexpert/images"; +// Module compta +$conf->compta->enabled=defined("MAIN_MODULE_COMPTABILITE")?MAIN_MODULE_COMPTABILITE:0; +$conf->compta->dir_output=DOL_DATA_ROOT."/compta"; +$conf->compta->dir_images=DOL_DATA_ROOT."/compta/images"; +// Module banque +$conf->banque->enabled=defined("MAIN_MODULE_BANQUE")?MAIN_MODULE_BANQUE:0; +$conf->banque->dir_output=DOL_DATA_ROOT."/banque"; +$conf->banque->dir_images=DOL_DATA_ROOT."/banque/images"; +// Module don +$conf->don->enabled=defined("MAIN_MODULE_DON")?MAIN_MODULE_DON:0; +$conf->don->dir_output=DOL_DATA_ROOT."/dons"; +$conf->don->dir_images=DOL_DATA_ROOT."/dons/images"; +// Module syslog +$conf->syslog->enabled=defined("MAIN_MODULE_SYSLOG")?MAIN_MODULE_SYSLOG:0; +// Module fournisseur +$conf->fournisseur->enabled=defined("MAIN_MODULE_FOURNISSEUR")?MAIN_MODULE_FOURNISSEUR:0; +// Module ficheinter +$conf->fichinter->enabled=defined("MAIN_MODULE_FICHEINTER")?MAIN_MODULE_FICHEINTER:0; +$conf->fichinter->dir_output=DOL_DATA_ROOT."/ficheinter"; +$conf->fichinter->dir_images=DOL_DATA_ROOT."/ficheinter/images"; +if (defined('FICHEINTER_OUTPUTDIR') && FICHEINTER_OUTPUTDIR) { $conf->fichinter->dir_output=FICHEINTER_OUTPUTDIR; } # Pour passer outre le rep par defaut +// Module adherent +$conf->adherent->enabled=defined("MAIN_MODULE_ADHERENT")?MAIN_MODULE_ADHERENT:0; +$conf->adherent->dir_output=DOL_DATA_ROOT."/adherent"; +// Module produit +$conf->produit->enabled=defined("MAIN_MODULE_PRODUIT")?MAIN_MODULE_PRODUIT:0; +$conf->produit->dir_output=DOL_DATA_ROOT."/produit"; +$conf->produit->dir_images=DOL_DATA_ROOT."/produit/images"; +$conf->produit->MultiPricesEnabled=defined("PRODUIT_MULTIPRICES")?PRODUIT_MULTIPRICES:0; +// Module service +$conf->service->enabled=defined("MAIN_MODULE_SERVICE")?MAIN_MODULE_SERVICE:0; +$conf->service->dir_output=DOL_DATA_ROOT."/produit"; +$conf->service->dir_images=DOL_DATA_ROOT."/produit/images"; +// Module stock +$conf->stock->enabled=defined("MAIN_MODULE_STOCK")?MAIN_MODULE_STOCK:0; +// Module code barre +$conf->barcode->enabled=defined("MAIN_MODULE_BARCODE")?MAIN_MODULE_BARCODE:0; +// Module categorie +$conf->categorie->enabled=defined("MAIN_MODULE_CATEGORIE")?MAIN_MODULE_CATEGORIE:0; +// Module contrat +$conf->contrat->enabled=defined("MAIN_MODULE_CONTRAT")?MAIN_MODULE_CONTRAT:0; +// Module projet +$conf->projet->enabled=defined("MAIN_MODULE_PROJET")?MAIN_MODULE_PROJET:0; +// Module oscommerce +$conf->boutique->enabled=defined("MAIN_MODULE_BOUTIQUE")?MAIN_MODULE_BOUTIQUE:0; +$conf->boutique->livre->enabled=defined("BOUTIQUE_LIVRE")?BOUTIQUE_LIVRE:0; +$conf->boutique->album->enabled=defined("BOUTIQUE_ALBUM")?BOUTIQUE_ALBUM:0; +// Module postnuke +$conf->postnuke->enabled=defined("MAIN_MODULE_POSTNUKE")?MAIN_MODULE_POSTNUKE:0; +// Module clicktodial +$conf->clicktodial->enabled=defined("MAIN_MODULE_CLICKTODIAL")?MAIN_MODULE_CLICKTODIAL:0; +// Module prelevement +$conf->prelevement->enabled=defined("MAIN_MODULE_PRELEVEMENT")?MAIN_MODULE_PRELEVEMENT:0; +$conf->prelevement->dir_output=DOL_DATA_ROOT."/prelevement"; +$conf->prelevement->dir_images=DOL_DATA_ROOT."/prelevement/images"; +// Module webcal +$conf->webcal->enabled=defined('MAIN_MODULE_WEBCALENDAR')?MAIN_MODULE_WEBCALENDAR:0; +$conf->webcal->db->type=defined('PHPWEBCALENDAR_TYPE')?PHPWEBCALENDAR_TYPE:'mysql'; +$conf->webcal->db->host=defined('PHPWEBCALENDAR_HOST')?PHPWEBCALENDAR_HOST:''; +$conf->webcal->db->user=defined('PHPWEBCALENDAR_USER')?PHPWEBCALENDAR_USER:''; +$conf->webcal->db->pass=defined('PHPWEBCALENDAR_PASS')?PHPWEBCALENDAR_PASS:''; +$conf->webcal->db->name=defined('PHPWEBCALENDAR_DBNAME')?PHPWEBCALENDAR_DBNAME:''; +// Module facture +$conf->facture->enabled=defined("MAIN_MODULE_FACTURE")?MAIN_MODULE_FACTURE:0; +// \todo Ajouter la ligne +// require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php"); +// dans le fichier facturation-emission.php du module telephonie afin de pouvoir supprimer la suivante +if (defined("MAIN_MODULE_TELEPHONIE") && MAIN_MODULE_TELEPHONIE) require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php"); +$conf->facture->dir_output=DOL_DATA_ROOT."/facture"; +$conf->facture->dir_images=DOL_DATA_ROOT."/facture/images"; +if (defined('FAC_OUTPUTDIR') && FAC_OUTPUTDIR) { $conf->facture->dir_output=FAC_OUTPUTDIR; } # Pour passer outre le rep par defaut +// Module propal +$conf->propal->enabled=defined("MAIN_MODULE_PROPALE")?MAIN_MODULE_PROPALE:0; +if (! defined("PROPALE_NEW_FORM_NB_PRODUCT")) define("PROPALE_NEW_FORM_NB_PRODUCT", 4); +$conf->propal->dir_output=DOL_DATA_ROOT."/propale"; +$conf->propal->dir_images=DOL_DATA_ROOT."/propale/images"; +if (defined('PROPALE_OUTPUTDIR') && PROPALE_OUTPUTDIR) { $conf->propal->dir_output=PROPALE_OUTPUTDIR; } # Pour passer outre le rep par defaut +// Module telephonie +$conf->telephonie->enabled=defined("MAIN_MODULE_TELEPHONIE")?MAIN_MODULE_TELEPHONIE:0; +$conf->telephonie->dir_output=DOL_DATA_ROOT."/telephonie"; +$conf->telephonie->dir_images=DOL_DATA_ROOT."/telephonie/images"; +// Module energie +$conf->energie->enabled=defined("MAIN_MODULE_ENERGIE")?MAIN_MODULE_ENERGIE:0; +// Module domaine +$conf->domaine->enabled=0; +// Module voyage +$conf->voyage->enabled=0; +// Module actionscomm +$conf->actionscomm->dir_output=DOL_DATA_ROOT."/action"; +// Module export +$conf->export->enabled=defined("MAIN_MODULE_EXPORT")?MAIN_MODULE_EXPORT:0; +$conf->export->dir_ouput=DOL_DATA_ROOT."/export"; + + +/* + * Modification de quelques variable de conf en fonction des Constantes + */ + +// conf->use_preview_tabs +$conf->use_preview_tabs=1; +if (isset($conf->global->MAIN_USE_PREVIEW_TABS)) $conf->use_preview_tabs=$conf->global->MAIN_USE_PREVIEW_TABS; + +// conf->use_javascript +$conf->use_javascript=1; +if (isset($conf->global->MAIN_DISABLE_JAVASCRIPT)) $conf->use_javascript=! $conf->global->MAIN_DISABLE_JAVASCRIPT; + +// conf->monnaie +if (! $conf->global->MAIN_MONNAIE) $conf->global->MAIN_MONNAIE='EUR'; +$conf->monnaie=$conf->global->MAIN_MONNAIE; + +// $conf->compta->mode = Option du module Compta: Defini le mode de calcul des etats comptables (CA,...) +$conf->compta->mode = 'RECETTES-DEPENSES'; // Par d?faut +if (defined('COMPTA_MODE') && COMPTA_MODE) { + // Peut etre 'RECETTES-DEPENSES' ou 'CREANCES-DETTES' + $conf->compta->mode = COMPTA_MODE; +} + +// $conf->defaulttx +if (defined('FACTURE_TVAOPTION') && FACTURE_TVAOPTION == 'franchise') { + $conf->defaulttx='0'; // Taux par d?faut des factures clients +} +else { + $conf->defaulttx=''; // Pas de taux par d?faut des factures clients, le premier sera pris +} + +// $conf->liste_limit = constante de taille maximale des listes +if (! $conf->global->SIZE_LISTE_LIMIT) $conf->global->SIZE_LISTE_LIMIT=20; +$conf->liste_limit=$conf->global->SIZE_LISTE_LIMIT; + +// $conf->produit->limit_size = constante de taille maximale des select de produit +if (! isset($conf->global->PRODUIT_LIMIT_SIZE)) $conf->global->PRODUIT_LIMIT_SIZE=50; +$conf->produit->limit_size=$conf->global->PRODUIT_LIMIT_SIZE; + +// $conf->theme et $conf->css +if (! $conf->global->MAIN_THEME) $conf->global->MAIN_THEME="eldy"; +$conf->theme=$conf->global->MAIN_THEME; +$conf->css = "theme/".$conf->theme."/".$conf->theme.".css"; + +// $conf->email_from = email pour envoi par Dolibarr des mails auto (notifications, ...) +// $conf->mailing->email_from = email pour envoi par Dolibarr des mailings +$conf->email_from="dolibarr-robot@domain.com"; +if (defined('MAIN_EMAIL_FROM')) +{ + $conf->email_from=MAIN_EMAIL_FROM; +} +if (defined('MAILING_EMAIL_FROM')) +{ + $conf->mailing->email_from=MAILING_EMAIL_FROM; +} +else $conf->mailing->email_from=$conf->email_from; + +// $conf->adherent->email_resil, ... +if (defined("MAIN_MAIL_RESIL")) +{ + $conf->adherent->email_resil=MAIN_MAIL_RESIL; +} +if (defined("MAIN_MAIL_RESIL_SUBJECT")) +{ + $conf->adherent->email_resil_subject=MAIN_MAIL_RESIL_SUBJECT; +} +if (defined("MAIN_MAIL_VALID")) +{ + $conf->adherent->email_valid=MAIN_MAIL_VALID; +} +if (defined("MAIN_MAIL_VALID_SUBJECT")) +{ + $conf->adherent->email_valid_subject=MAIN_MAIL_VALID_SUBJECT; +} +if (defined("MAIN_MAIL_EDIT")) +{ + $conf->adherent->email_edit=MAIN_MAIL_EDIT; +} +if (defined("MAIN_MAIL_EDIT_SUBJECT")) +{ + $conf->adherent->email_edit_subject=MAIN_MAIL_EDIT_SUBJECT; +} +if (defined("MAIN_MAIL_NEW")) +{ + $conf->adherent->email_new=MAIN_MAIL_NEW; +} +if (defined("MAIN_MAIL_NEW_SUBJECT")) +{ + $conf->adherent->email_new_subject=MAIN_MAIL_NEW_SUBJECT; +} + +// Format de la date +// \todo Mettre format dans fichier langue +$conf->format_date_text_short="%d %b %Y"; +$conf->format_date_short="%d/%m/%Y"; + + +/* + * Creation objet mysoc + * Objet Societe qui contient carac de l'institution g�� par Dolibarr. + */ +require_once(DOL_DOCUMENT_ROOT ."/societe.class.php"); +$mysoc=new Societe($db); +$mysoc->id=0; +$mysoc->nom=$conf->global->MAIN_INFO_SOCIETE_NOM; +$mysoc->adresse=$conf->global->MAIN_INFO_SOCIETE_ADRESSE; +$mysoc->cp=$conf->global->MAIN_INFO_SOCIETE_CP; +$mysoc->ville=$conf->global->MAIN_INFO_SOCIETE_VILLE; +$mysoc->pays_code=$conf->global->MAIN_INFO_SOCIETE_PAYS; +$mysoc->tel=$conf->global->MAIN_INFO_SOCIETE_TEL; +$mysoc->fax=$conf->global->MAIN_INFO_SOCIETE_FAX; +$mysoc->url=$conf->global->MAIN_INFO_SOCIETE_WEB; +$mysoc->siren=$conf->global->MAIN_INFO_SIREN; +$mysoc->siret=$conf->global->MAIN_INFO_SIRET; +$mysoc->ape=$conf->global->MAIN_INFO_APE; +$mysoc->rcs=$conf->global->MAIN_INFO_RCS; +$mysoc->tvaintra=$conf->global->MAIN_INFO_TVAINTRA; +$mysoc->capital=$conf->global->MAIN_INFO_CAPITAL; +$mysoc->forme_juridique_code=$conf->global->MAIN_INFO_FORME_JURIDIQUE; +$mysoc->email=$conf->global->MAIN_INFO_SOCIETE_MAIL; + + +/* \todo Ajouter une option Gestion de la TVA dans le module compta qui permet de d?sactiver la fonction TVA + * (pour particuliers ou lib?raux en franchise) + * En attendant, valeur forc?e ? 1 + */ +$conf->compta->tva=1; + +// Delais de tolerance des alertes +$conf->actions->warning_delay=$conf->global->MAIN_DELAY_ACTIONS_TODO*24*60*60; +$conf->commande->traitement->warning_delay=$conf->global->MAIN_DELAY_ORDERS_TO_PROCESS*24*60*60; +$conf->propal->cloture->warning_delay=$conf->global->MAIN_DELAY_PROPALS_TO_CLOSE*24*60*60; +$conf->propal->facturation->warning_delay=$conf->global->MAIN_DELAY_PROPALS_TO_BILL*24*60*60; +$conf->facture->fournisseur->warning_delay=$conf->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY*24*60*60; +$conf->facture->client->warning_delay=$conf->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED*24*60*60; +$conf->contrat->services->inactifs->warning_delay=$conf->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES*24*60*60; +$conf->contrat->services->expires->warning_delay=$conf->global->MAIN_DELAY_RUNNING_SERVICES*24*60*60; +$conf->adherent->cotisation->warning_delay=$conf->global->MAIN_DELAY_MEMBERS*24*60*60; +$conf->bank->rappro->warning_delay=$conf->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE*24*60*60; + + +/* + */ +$bc[0]="class=\"impair\""; +$bc[1]="class=\"pair\""; +$yesno[0]="no"; +$yesno[1]="yes"; + +if ( ! defined('MENTION_NPR') ) define('MENTION_NPR','(npr)'); +?> + + * Copyright (C) 2003 Xavier Dutoit + * Copyright (C) 2004 Laurent Destailleur + * Copyright (C) 2004 Sebastien Di Cintio + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2005 Regis Houssin + * 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/master.inc.php + \brief Fichier de preparation de l'environnement Dolibarr + \version $Revision$ +*/ + +define('DOL_VERSION','2.1-alpha'); + +// La fonction clearstatcache ne doit pas etre appel�de mani�e globale car ralenti. +// Elle doit etre appel� uniquement par les pages qui ont besoin d'un cache fichier vid� +// comme par exemple document.php +//clearstatcache(); + +// Forcage du parametrage PHP error_reporting (Dolibarr non utilisable en mode error E_ALL) +if (function_exists("define_syslog_variables")) +{ + define_syslog_variables(); +} +//error_reporting(E_ALL); +error_reporting(E_ALL ^ E_NOTICE); + +// Test si install ok +if (! @include_once("conf/conf.php")) +{ + Header("Location: install/index.php"); + exit; +} +else +{ + if (! isset($dolibarr_main_db_host)) + { + Header("Location: install/index.php"); + exit; + } +} + +if (! isset($dolibarr_main_db_type)) +{ + $dolibarr_main_db_type='mysql'; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql' +} +if (! $dolibarr_main_data_root) { + // Si repertoire documents non defini, on utilise celui par defaut + $dolibarr_main_data_root=ereg_replace("/htdocs","",$dolibarr_main_document_root); + $dolibarr_main_data_root.="/documents"; +} +define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root); +define('DOL_DATA_ROOT', $dolibarr_main_data_root); + +$uri=eregi_replace('^http(s?)://','',$dolibarr_main_url_root); +$pos = strstr ($uri, '/'); // $pos contient alors url sans nom domaine +if ($pos == '/') $pos = ''; // si $pos vaut /, on le met a '' +define('DOL_URL_ROOT', $pos); + + +/* + * Initialisation de l'objet $conf + */ +require_once(DOL_DOCUMENT_ROOT."/conf/conf.class.php"); +$conf = new Conf(); +$conf->db->host = $dolibarr_main_db_host; +$conf->db->name = $dolibarr_main_db_name; +$conf->db->user = $dolibarr_main_db_user; +$conf->db->pass = $dolibarr_main_db_pass; +$conf->db->type = $dolibarr_main_db_type; +if (! $conf->db->type) { $conf->db->type = 'mysql'; } // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql' +// Defini prefix +if (isset($_SERVER["LLX_DBNAME"])) $dolibarr_main_db_prefix=$_SERVER["LLX_DBNAME"]; +if (! isset($dolibarr_main_db_prefix) || ! $dolibarr_main_db_prefix) $dolibarr_main_db_prefix='llx_'; +$conf->db->prefix = $dolibarr_main_db_prefix; +define('MAIN_DB_PREFIX',$dolibarr_main_db_prefix); + +/* + * Chargement des includes principaux + */ +require_once(DOL_DOCUMENT_ROOT ."/lib/".$conf->db->type.".lib.php"); +require_once(DOL_DOCUMENT_ROOT ."/lib/functions.inc.php"); +require_once(DOL_DOCUMENT_ROOT ."/user.class.php"); +require_once(DOL_DOCUMENT_ROOT ."/menu.class.php"); +require_once(DOL_DOCUMENT_ROOT ."/html.form.class.php"); + + +$db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name); +if (! $db->connected) { + dolibarr_print_error($db,"host=".$conf->db->host.", user=".$conf->db->user.", databasename=".$conf->db->name.", ".$db->error); + exit; +} + + +$user = new User($db); + +/* + * Definition de toutes les Constantes globales d'environnement + * - En constante php (\todo a virer) + * - En $conf->global->key=value + */ +$sql = "SELECT name, value FROM ".MAIN_DB_PREFIX."const"; +$result = $db->query($sql); +if ($result) +{ + $numr = $db->num_rows($result); + $i = 0; + + while ($i < $numr) + { + $objp = $db->fetch_object($result); + $key=$objp->name; + $value=$objp->value; // Pas de stripslashes (ne s'applique pas sur lecture base mais apr� POST quand get_magic_quotes_gpc()==1) + define ("$key", $value); + $conf->global->$key=$value; + $i++; + } +} +$db->free($result); + +/* + * Nettoyage variables des gestionnaires de menu + * conf->menu_top et conf->menu_left sont d?finis dans main.inc.php (selon user) + */ +if (! $conf->global->MAIN_MENU_BARRETOP) $conf->global->MAIN_MENU_BARRETOP="default.php"; +if (! $conf->global->MAIN_MENUFRONT_BARRETOP) $conf->global->MAIN_MENUFRONT_BARRETOP="default.php"; +if (! $conf->global->MAIN_MENU_BARRELEFT) $conf->global->MAIN_MENU_BARRELEFT="default.php"; +if (! $conf->global->MAIN_MENUFRONT_BARRELEFT) $conf->global->MAIN_MENUFRONT_BARRELEFT="default.php"; + +/* + * Charge l'objet de traduction et positionne langage courant global + */ +if (! $conf->global->MAIN_LANG_DEFAULT) $conf->global->MAIN_LANG_DEFAULT="fr_FR"; + +require_once(DOL_DOCUMENT_ROOT ."/translate.class.php"); +$langs = new Translate(DOL_DOCUMENT_ROOT ."/langs"); +$langs->setDefaultLang($conf->global->MAIN_LANG_DEFAULT); +$langs->setPhpLang($conf->global->MAIN_LANG_DEFAULT); + + +/* + * Pour utiliser d'autres versions des librairies externes que les + * versions embarqu?es dans Dolibarr, d?finir les constantes adequates: + * Pour FPDF: FPDF_PATH + * Pour PEAR: PEAR_PATH + * Pour PHP_WriteExcel: PHP_WRITEEXCEL_PATH + * Pour PHPlot: PHPLOT_PATH + * Pour MagpieRss: MAGPIERSS_PATH + */ +if (! defined('FPDF_PATH')) { define('FPDF_PATH', DOL_DOCUMENT_ROOT .'/includes/fpdf/fpdf/'); } +if (! defined('PEAR_PATH')) { define('PEAR_PATH', DOL_DOCUMENT_ROOT .'/includes/pear/'); } +if (! defined('PHP_WRITEEXCEL_PATH')) { define('PHP_WRITEEXCEL_PATH',DOL_DOCUMENT_ROOT .'/includes/php_writeexcel/'); } +if (! defined('PHPLOT_PATH')) { define('PHPLOT_PATH', DOL_DOCUMENT_ROOT .'/includes/phplot/'); } +if (! defined('MAGPIERSS_PATH')) { define('MAGPIERSS_PATH', DOL_DOCUMENT_ROOT .'/includes/magpierss/'); } +if (! defined('JPGRAPH_PATH')) { define('JPGRAPH_PATH', DOL_DOCUMENT_ROOT .'/includes/jpgraph/'); } +define('FPDF_FONTPATH', FPDF_PATH . 'font/'); +define('MAGPIE_DIR', MAGPIERSS_PATH); + +// \todo Ajouter la ligne +// require_once(FPDF_PATH . "fpdf.php"); +// dans le fichier pdfdetail_standard_modeles du module telephonie afin de pouvoir la suivante +if (defined("MAIN_MODULE_TELEPHONIE") && MAIN_MODULE_TELEPHONIE) require_once(FPDF_PATH . "fpdf.php"); + +/* + * Autres parametres globaux de configurations + */ +$conf->users->dir_output=DOL_DATA_ROOT."/users"; + +/* + * Utilise dans tous les upload de fichier + * necessaire pour desactiver dans la demo + */ +if (defined('MAIN_UPLOAD_DOC') && MAIN_UPLOAD_DOC == 1) +{ + $conf->upload = 1; +} +else +{ + $conf->upload = 0; +} + + +/* + * Definition des parametres d'activation de module et dependants des modules + * Chargement d'include selon etat activation des modules + */ + +// Module bookmark4u +$conf->bookmark4u->enabled=defined('MAIN_MODULE_BOOKMARK4U')?MAIN_MODULE_BOOKMARK4U:0; +$conf->bookmark->enabled=defined('MAIN_MODULE_BOOKMARK')?MAIN_MODULE_BOOKMARK:0; +// Module deplacement +$conf->deplacement->enabled=defined("MAIN_MODULE_DEPLACEMENT")?MAIN_MODULE_DEPLACEMENT:0; +// Module mailing +$conf->mailing->enabled=defined("MAIN_MODULE_MAILING")?MAIN_MODULE_MAILING:0; +// Module externalrss +$conf->externalrss->enabled=defined("MAIN_MODULE_EXTERNALRSS")?MAIN_MODULE_EXTERNALRSS:0; +// Module commande client +$conf->commande->enabled=defined("MAIN_MODULE_COMMANDE")?MAIN_MODULE_COMMANDE:0; +$conf->commande->dir_output=DOL_DATA_ROOT."/commande"; +$conf->commande->dir_images=DOL_DATA_ROOT."/commande/images"; +// Module expeditions +$conf->expedition->enabled=defined("MAIN_MODULE_EXPEDITION")?MAIN_MODULE_EXPEDITION:0; +$conf->expedition->dir_output=DOL_DATA_ROOT."/expedition"; +$conf->expedition->dir_images=DOL_DATA_ROOT."/expedition/images"; +// Module societe +$conf->societe->enabled=defined("MAIN_MODULE_SOCIETE")?MAIN_MODULE_SOCIETE:0; +$conf->societe->dir_output=DOL_DATA_ROOT."/societe"; +$conf->societe->dir_images=DOL_DATA_ROOT."/societe/images"; +if (defined('SOCIETE_OUTPUTDIR') && SOCIETE_OUTPUTDIR) { $conf->societe->dir_output=SOCIETE_OUTPUTDIR; } # Pour passer outre le rep par d?faut +// Module commercial +$conf->commercial->enabled=defined("MAIN_MODULE_COMMERCIAL")?MAIN_MODULE_COMMERCIAL:0; +$conf->commercial->dir_output=DOL_DATA_ROOT."/rapport"; +// Module comptaexpert +$conf->comptaexpert->enabled=defined("MAIN_MODULE_COMPTABILITE_EXPERT")?MAIN_MODULE_COMPTABILITE_EXPERT:0; +$conf->comptaexpert->dir_output=DOL_DATA_ROOT."/comptaexpert"; +$conf->comptaexpert->dir_images=DOL_DATA_ROOT."/comptaexpert/images"; +// Module compta +$conf->compta->enabled=defined("MAIN_MODULE_COMPTABILITE")?MAIN_MODULE_COMPTABILITE:0; +$conf->compta->dir_output=DOL_DATA_ROOT."/compta"; +$conf->compta->dir_images=DOL_DATA_ROOT."/compta/images"; +// Module banque +$conf->banque->enabled=defined("MAIN_MODULE_BANQUE")?MAIN_MODULE_BANQUE:0; +$conf->banque->dir_output=DOL_DATA_ROOT."/banque"; +$conf->banque->dir_images=DOL_DATA_ROOT."/banque/images"; +// Module don +$conf->don->enabled=defined("MAIN_MODULE_DON")?MAIN_MODULE_DON:0; +$conf->don->dir_output=DOL_DATA_ROOT."/dons"; +$conf->don->dir_images=DOL_DATA_ROOT."/dons/images"; +// Module syslog +$conf->syslog->enabled=defined("MAIN_MODULE_SYSLOG")?MAIN_MODULE_SYSLOG:0; +// Module fournisseur +$conf->fournisseur->enabled=defined("MAIN_MODULE_FOURNISSEUR")?MAIN_MODULE_FOURNISSEUR:0; +// Module ficheinter +$conf->fichinter->enabled=defined("MAIN_MODULE_FICHEINTER")?MAIN_MODULE_FICHEINTER:0; +$conf->fichinter->dir_output=DOL_DATA_ROOT."/ficheinter"; +$conf->fichinter->dir_images=DOL_DATA_ROOT."/ficheinter/images"; +if (defined('FICHEINTER_OUTPUTDIR') && FICHEINTER_OUTPUTDIR) { $conf->fichinter->dir_output=FICHEINTER_OUTPUTDIR; } # Pour passer outre le rep par defaut +// Module adherent +$conf->adherent->enabled=defined("MAIN_MODULE_ADHERENT")?MAIN_MODULE_ADHERENT:0; +$conf->adherent->dir_output=DOL_DATA_ROOT."/adherent"; +// Module produit +$conf->produit->enabled=defined("MAIN_MODULE_PRODUIT")?MAIN_MODULE_PRODUIT:0; +$conf->produit->dir_output=DOL_DATA_ROOT."/produit"; +$conf->produit->dir_images=DOL_DATA_ROOT."/produit/images"; +// Module service +$conf->service->enabled=defined("MAIN_MODULE_SERVICE")?MAIN_MODULE_SERVICE:0; +$conf->service->dir_output=DOL_DATA_ROOT."/produit"; +$conf->service->dir_images=DOL_DATA_ROOT."/produit/images"; +// Module stock +$conf->stock->enabled=defined("MAIN_MODULE_STOCK")?MAIN_MODULE_STOCK:0; +// Module code barre +$conf->barcode->enabled=defined("MAIN_MODULE_BARCODE")?MAIN_MODULE_BARCODE:0; +// Module categorie +$conf->categorie->enabled=defined("MAIN_MODULE_CATEGORIE")?MAIN_MODULE_CATEGORIE:0; +// Module contrat +$conf->contrat->enabled=defined("MAIN_MODULE_CONTRAT")?MAIN_MODULE_CONTRAT:0; +// Module projet +$conf->projet->enabled=defined("MAIN_MODULE_PROJET")?MAIN_MODULE_PROJET:0; +// Module oscommerce +$conf->boutique->enabled=defined("MAIN_MODULE_BOUTIQUE")?MAIN_MODULE_BOUTIQUE:0; +$conf->boutique->livre->enabled=defined("BOUTIQUE_LIVRE")?BOUTIQUE_LIVRE:0; +$conf->boutique->album->enabled=defined("BOUTIQUE_ALBUM")?BOUTIQUE_ALBUM:0; +// Module postnuke +$conf->postnuke->enabled=defined("MAIN_MODULE_POSTNUKE")?MAIN_MODULE_POSTNUKE:0; +// Module clicktodial +$conf->clicktodial->enabled=defined("MAIN_MODULE_CLICKTODIAL")?MAIN_MODULE_CLICKTODIAL:0; +// Module prelevement +$conf->prelevement->enabled=defined("MAIN_MODULE_PRELEVEMENT")?MAIN_MODULE_PRELEVEMENT:0; +$conf->prelevement->dir_output=DOL_DATA_ROOT."/prelevement"; +$conf->prelevement->dir_images=DOL_DATA_ROOT."/prelevement/images"; +// Module webcal +$conf->webcal->enabled=defined('MAIN_MODULE_WEBCALENDAR')?MAIN_MODULE_WEBCALENDAR:0; +$conf->webcal->db->type=defined('PHPWEBCALENDAR_TYPE')?PHPWEBCALENDAR_TYPE:'mysql'; +$conf->webcal->db->host=defined('PHPWEBCALENDAR_HOST')?PHPWEBCALENDAR_HOST:''; +$conf->webcal->db->user=defined('PHPWEBCALENDAR_USER')?PHPWEBCALENDAR_USER:''; +$conf->webcal->db->pass=defined('PHPWEBCALENDAR_PASS')?PHPWEBCALENDAR_PASS:''; +$conf->webcal->db->name=defined('PHPWEBCALENDAR_DBNAME')?PHPWEBCALENDAR_DBNAME:''; +// Module facture +$conf->facture->enabled=defined("MAIN_MODULE_FACTURE")?MAIN_MODULE_FACTURE:0; +// \todo Ajouter la ligne +// require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php"); +// dans le fichier facturation-emission.php du module telephonie afin de pouvoir supprimer la suivante +if (defined("MAIN_MODULE_TELEPHONIE") && MAIN_MODULE_TELEPHONIE) require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php"); +$conf->facture->dir_output=DOL_DATA_ROOT."/facture"; +$conf->facture->dir_images=DOL_DATA_ROOT."/facture/images"; +if (defined('FAC_OUTPUTDIR') && FAC_OUTPUTDIR) { $conf->facture->dir_output=FAC_OUTPUTDIR; } # Pour passer outre le rep par defaut +// Module propal +$conf->propal->enabled=defined("MAIN_MODULE_PROPALE")?MAIN_MODULE_PROPALE:0; +if (! defined("PROPALE_NEW_FORM_NB_PRODUCT")) define("PROPALE_NEW_FORM_NB_PRODUCT", 4); +$conf->propal->dir_output=DOL_DATA_ROOT."/propale"; +$conf->propal->dir_images=DOL_DATA_ROOT."/propale/images"; +if (defined('PROPALE_OUTPUTDIR') && PROPALE_OUTPUTDIR) { $conf->propal->dir_output=PROPALE_OUTPUTDIR; } # Pour passer outre le rep par defaut +// Module telephonie +$conf->telephonie->enabled=defined("MAIN_MODULE_TELEPHONIE")?MAIN_MODULE_TELEPHONIE:0; +$conf->telephonie->dir_output=DOL_DATA_ROOT."/telephonie"; +$conf->telephonie->dir_images=DOL_DATA_ROOT."/telephonie/images"; +// Module energie +$conf->energie->enabled=defined("MAIN_MODULE_ENERGIE")?MAIN_MODULE_ENERGIE:0; +// Module domaine +$conf->domaine->enabled=0; +// Module voyage +$conf->voyage->enabled=0; +// Module actionscomm +$conf->actionscomm->dir_output=DOL_DATA_ROOT."/action"; +// Module export +$conf->export->enabled=defined("MAIN_MODULE_EXPORT")?MAIN_MODULE_EXPORT:0; +$conf->export->dir_ouput=DOL_DATA_ROOT."/export"; + + +/* + * Modification de quelques variable de conf en fonction des Constantes + */ + +// conf->use_preview_tabs +$conf->use_preview_tabs=1; +if (isset($conf->global->MAIN_USE_PREVIEW_TABS)) $conf->use_preview_tabs=$conf->global->MAIN_USE_PREVIEW_TABS; + +// conf->use_javascript +$conf->use_javascript=1; +if (isset($conf->global->MAIN_DISABLE_JAVASCRIPT)) $conf->use_javascript=! $conf->global->MAIN_DISABLE_JAVASCRIPT; + +// conf->monnaie +if (! $conf->global->MAIN_MONNAIE) $conf->global->MAIN_MONNAIE='EUR'; +$conf->monnaie=$conf->global->MAIN_MONNAIE; + +// $conf->compta->mode = Option du module Compta: Defini le mode de calcul des etats comptables (CA,...) +$conf->compta->mode = 'RECETTES-DEPENSES'; // Par d?faut +if (defined('COMPTA_MODE') && COMPTA_MODE) { + // Peut etre 'RECETTES-DEPENSES' ou 'CREANCES-DETTES' + $conf->compta->mode = COMPTA_MODE; +} + +// $conf->defaulttx +if (defined('FACTURE_TVAOPTION') && FACTURE_TVAOPTION == 'franchise') { + $conf->defaulttx='0'; // Taux par d?faut des factures clients +} +else { + $conf->defaulttx=''; // Pas de taux par d?faut des factures clients, le premier sera pris +} + +// $conf->liste_limit = constante de taille maximale des listes +if (! $conf->global->SIZE_LISTE_LIMIT) $conf->global->SIZE_LISTE_LIMIT=20; +$conf->liste_limit=$conf->global->SIZE_LISTE_LIMIT; + +// $conf->produit->limit_size = constante de taille maximale des select de produit +if (! isset($conf->global->PRODUIT_LIMIT_SIZE)) $conf->global->PRODUIT_LIMIT_SIZE=50; +$conf->produit->limit_size=$conf->global->PRODUIT_LIMIT_SIZE; + +// $conf->theme et $conf->css +if (! $conf->global->MAIN_THEME) $conf->global->MAIN_THEME="eldy"; +$conf->theme=$conf->global->MAIN_THEME; +$conf->css = "theme/".$conf->theme."/".$conf->theme.".css"; + +// $conf->email_from = email pour envoi par Dolibarr des mails auto (notifications, ...) +// $conf->mailing->email_from = email pour envoi par Dolibarr des mailings +$conf->email_from="dolibarr-robot@domain.com"; +if (defined('MAIN_EMAIL_FROM')) +{ + $conf->email_from=MAIN_EMAIL_FROM; +} +if (defined('MAILING_EMAIL_FROM')) +{ + $conf->mailing->email_from=MAILING_EMAIL_FROM; +} +else $conf->mailing->email_from=$conf->email_from; + +// $conf->adherent->email_resil, ... +if (defined("MAIN_MAIL_RESIL")) +{ + $conf->adherent->email_resil=MAIN_MAIL_RESIL; +} +if (defined("MAIN_MAIL_RESIL_SUBJECT")) +{ + $conf->adherent->email_resil_subject=MAIN_MAIL_RESIL_SUBJECT; +} +if (defined("MAIN_MAIL_VALID")) +{ + $conf->adherent->email_valid=MAIN_MAIL_VALID; +} +if (defined("MAIN_MAIL_VALID_SUBJECT")) +{ + $conf->adherent->email_valid_subject=MAIN_MAIL_VALID_SUBJECT; +} +if (defined("MAIN_MAIL_EDIT")) +{ + $conf->adherent->email_edit=MAIN_MAIL_EDIT; +} +if (defined("MAIN_MAIL_EDIT_SUBJECT")) +{ + $conf->adherent->email_edit_subject=MAIN_MAIL_EDIT_SUBJECT; +} +if (defined("MAIN_MAIL_NEW")) +{ + $conf->adherent->email_new=MAIN_MAIL_NEW; +} +if (defined("MAIN_MAIL_NEW_SUBJECT")) +{ + $conf->adherent->email_new_subject=MAIN_MAIL_NEW_SUBJECT; +} + +// Format de la date +// \todo Mettre format dans fichier langue +$conf->format_date_text_short="%d %b %Y"; +$conf->format_date_short="%d/%m/%Y"; + + +/* + * Creation objet mysoc + * Objet Societe qui contient carac de l'institution g�� par Dolibarr. + */ +require_once(DOL_DOCUMENT_ROOT ."/societe.class.php"); +$mysoc=new Societe($db); +$mysoc->id=0; +$mysoc->nom=$conf->global->MAIN_INFO_SOCIETE_NOM; +$mysoc->adresse=$conf->global->MAIN_INFO_SOCIETE_ADRESSE; +$mysoc->cp=$conf->global->MAIN_INFO_SOCIETE_CP; +$mysoc->ville=$conf->global->MAIN_INFO_SOCIETE_VILLE; +$mysoc->pays_code=$conf->global->MAIN_INFO_SOCIETE_PAYS; +$mysoc->tel=$conf->global->MAIN_INFO_SOCIETE_TEL; +$mysoc->fax=$conf->global->MAIN_INFO_SOCIETE_FAX; +$mysoc->url=$conf->global->MAIN_INFO_SOCIETE_WEB; +$mysoc->siren=$conf->global->MAIN_INFO_SIREN; +$mysoc->siret=$conf->global->MAIN_INFO_SIRET; +$mysoc->ape=$conf->global->MAIN_INFO_APE; +$mysoc->rcs=$conf->global->MAIN_INFO_RCS; +$mysoc->tvaintra=$conf->global->MAIN_INFO_TVAINTRA; +$mysoc->capital=$conf->global->MAIN_INFO_CAPITAL; +$mysoc->forme_juridique_code=$conf->global->MAIN_INFO_FORME_JURIDIQUE; +$mysoc->email=$conf->global->MAIN_INFO_SOCIETE_MAIL; + + +/* \todo Ajouter une option Gestion de la TVA dans le module compta qui permet de d?sactiver la fonction TVA + * (pour particuliers ou lib?raux en franchise) + * En attendant, valeur forc?e ? 1 + */ +$conf->compta->tva=1; + +// Delais de tolerance des alertes +$conf->actions->warning_delay=$conf->global->MAIN_DELAY_ACTIONS_TODO*24*60*60; +$conf->commande->traitement->warning_delay=$conf->global->MAIN_DELAY_ORDERS_TO_PROCESS*24*60*60; +$conf->propal->cloture->warning_delay=$conf->global->MAIN_DELAY_PROPALS_TO_CLOSE*24*60*60; +$conf->propal->facturation->warning_delay=$conf->global->MAIN_DELAY_PROPALS_TO_BILL*24*60*60; +$conf->facture->fournisseur->warning_delay=$conf->global->MAIN_DELAY_SUPPLIER_BILLS_TO_PAY*24*60*60; +$conf->facture->client->warning_delay=$conf->global->MAIN_DELAY_CUSTOMER_BILLS_UNPAYED*24*60*60; +$conf->contrat->services->inactifs->warning_delay=$conf->global->MAIN_DELAY_NOT_ACTIVATED_SERVICES*24*60*60; +$conf->contrat->services->expires->warning_delay=$conf->global->MAIN_DELAY_RUNNING_SERVICES*24*60*60; +$conf->adherent->cotisation->warning_delay=$conf->global->MAIN_DELAY_MEMBERS*24*60*60; +$conf->bank->rappro->warning_delay=$conf->global->MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE*24*60*60; + + +/* + */ +$bc[0]="class=\"impair\""; +$bc[1]="class=\"pair\""; +$yesno[0]="no"; +$yesno[1]="yes"; + +if ( ! defined('MENTION_NPR') ) define('MENTION_NPR','(npr)'); +?> diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 4a393f224ab..dc6a7ac22da 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2004-2005 Laurent Destailleur - * + * Copyright (C) 2006 Andre Cianfarani * 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 @@ -42,6 +42,7 @@ class Product var $libelle; var $description; var $price; + var $multiprices=array(); var $tva_tx; var $type; var $seuil_stock_alerte; @@ -248,30 +249,89 @@ class Product */ function _log_price($user) { - // On supprimme ligne existante au cas ou - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price "; - $sql .= "WHERE date_price = now()"; - $sql .= " and fk_product = ".$this->id; - $sql .= " and fk_user_author = ".$user->id; - $sql .= " and price = ".ereg_replace(",",".",$this->price); - $sql .= " and envente = ".$this->envente; - $sql .= " and tva_tx = ".$this->tva_tx; - - $this->db->query($sql); - - // On ajoute nouveau tarif - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price(date_price,fk_product,fk_user_author,price,envente,tva_tx) "; - $sql .= " VALUES(now(),".$this->id.",".$user->id.",".ereg_replace(",",".",$this->price).",".$this->envente.",".$this->tva_tx; - $sql .= ")"; - if ($this->db->query($sql) ) - { - return 1; - } - else - { - dolibarr_print_error($this->db); - return 0; - } + // MultiPrix : si activé, on gère tout ici, même le prix standard + global $conf; + if($conf->global->PRODUIT_MULTIPRICES == 1) + { + $queryError = false; + for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) + { + if($this->multiprices["$i"] != "") + { + // On supprimme ligne existante au cas ou + $sql_multiprix = "DELETE FROM ".MAIN_DB_PREFIX."product_price "; + $sql_multiprix .= "WHERE date_price = now()"; + $sql_multiprix .= " and fk_product = ".$this->id; + $sql_multiprix .= " and fk_user_author = ".$user->id; + $sql_multiprix .= " and price = ".ereg_replace(",",".",$this->multiprices["$i"]); + + $this->db->query($sql_multiprix); + + // On ajoute nouveau tarif + $sql_multiprix = "INSERT INTO ".MAIN_DB_PREFIX."product_price(date_price,fk_product,fk_user_author,price_level,price) "; + $sql_multiprix .= " VALUES(now(),".$this->id.",".$user->id.",".$i.",".ereg_replace(",",".",$this->multiprices["$i"]); + $sql_multiprix .= ")"; + if (! $this->db->query($sql_multiprix) ) + $queryError = true; + } + } + if (strlen(trim($this->price)) > 0 ) + { + // On supprimme ligne existante au cas ou + $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price "; + $sql .= "WHERE date_price = now()"; + $sql .= " and fk_product = ".$this->id; + $sql .= " and fk_user_author = ".$user->id; + $sql .= " and price = ".ereg_replace(",",".",$this->price); + $sql .= " and envente = ".$this->envente; + $sql .= " and tva_tx = ".$this->tva_tx; + + $this->db->query($sql); + + // On ajoute nouveau tarif + $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price(date_price,fk_product,fk_user_author,price,envente,tva_tx) "; + $sql .= " VALUES(now(),".$this->id.",".$user->id.",".ereg_replace(",",".",$this->price).",".$this->envente.",".$this->tva_tx; + $sql .= ")"; + if (! $this->db->query($sql) ) + $queryError = true; + } + if($queryError) + { + dolibarr_print_error($this->db); + return 0; + } + else + return 1; + } + else + { + // On supprimme ligne existante au cas ou + $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price "; + $sql .= "WHERE date_price = now()"; + $sql .= " and fk_product = ".$this->id; + $sql .= " and fk_user_author = ".$user->id; + $sql .= " and price = ".ereg_replace(",",".",$this->price); + $sql .= " and envente = ".$this->envente; + $sql .= " and tva_tx = ".$this->tva_tx; + + $this->db->query($sql); + + // On ajoute nouveau tarif + $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price(date_price,fk_product,fk_user_author,price,envente,tva_tx) "; + $sql .= " VALUES(now(),".$this->id.",".$user->id.",".ereg_replace(",",".",$this->price).",".$this->envente.",".$this->tva_tx; + $sql .= ")"; + + if ($this->db->query($sql) ) + { + return 1; + } + else + { + dolibarr_print_error($this->db); + return 0; + } + } + } @@ -396,29 +456,67 @@ class Product */ function update_price($id, $user) { - if (strlen(trim($this->price)) > 0 ) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."product "; - $sql .= " SET price = " . ereg_replace(",",".",$this->price); - $sql .= " WHERE rowid = " . $id; - - if ( $this->db->query($sql) ) - { - $this->_log_price($user); - return 1; - } - else - { - dolibarr_print_error($this->db); - return -1; - } - } - else - { - $this->error = "Prix saisi invalide."; - return -2; - } - } + //multiprix + global $conf; + if($conf->global->PRODUIT_MULTIPRICES == 1) + { + if (strlen(trim($this->price)) > 0 ) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."product "; + $sql .= " SET price = " . ereg_replace(",",".",$this->price); + $sql .= " WHERE rowid = " . $id; + + if ( $this->db->query($sql) ) + { + $this->_log_price($user); + return 1; + } + else + { + dolibarr_print_error($this->db); + return -1; + } + } + else if(count($this->multiprices) > 0) + { + $this->_log_price($user); + return 1; + } + else + { + $this->error = "Prix saisi invalide."; + return -2; + } + } + else + { + if (strlen(trim($this->price)) > 0 ) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."product "; + $sql .= " SET price = " . ereg_replace(",",".",$this->price); + $sql .= " WHERE rowid = " . $id; + + if ( $this->db->query($sql) ) + { + $this->_log_price($user); + return 1; + } + else + { + dolibarr_print_error($this->db); + return -1; + } + } + else + { + $this->error = "Prix saisi invalide."; + return -2; + } + } + + + + } /** @@ -430,6 +528,7 @@ class Product function fetch($id='',$ref='') { global $langs; + global $conf; // Verification parametres if (! $id && ! $ref) @@ -479,7 +578,50 @@ class Product } $this->db->free(); - + // multiprix + if($conf->global->PRODUIT_MULTIPRICES == 1) + { + if ($ref) + { + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product "; + $sql.= "WHERE ref = '".addslashes($ref)."'"; + $result = $this->db->query($sql) ; + if ($result) + { + $result = $this->db->fetch_array(); + $prodid = $result["rowid"]; + } + else + { + dolibarr_print_error($this->db); + return -1; + } + } + for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) + { + $sql= "SELECT price, tva_tx, envente "; + $sql.= "FROM ".MAIN_DB_PREFIX."product_price "; + $sql.= "where price_level=".$i." and "; + if ($id) $sql.= "fk_product = ".$id." "; + if ($ref) $sql.= "fk_product = ".$prodid." "; + $sql.= "order by date_price DESC limit 1"; + $result = $this->db->query($sql) ; + if ( $result ) + { + $result = $this->db->fetch_array(); + if($result["price"] != "") + $this -> multiprices[$i]=$result["price"]; + } + else + { + dolibarr_print_error($this->db); + return -1; + } + } + + } + + $sql = "SELECT reel, fk_entrepot"; $sql .= " FROM ".MAIN_DB_PREFIX."product_stock WHERE fk_product = ".$this->id; $result = $this->db->query($sql) ; diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index ce4b2d6089f..250ae8d301a 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2005 Laurent Destailleur * Copyright (C) 2005 Eric Seigne * Copyright (C) 2005 Régis Houssin + * Copyright (C) 2006 Andre Cianfarani * * 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 @@ -74,7 +75,17 @@ if ($_POST["action"] == 'add' && $user->rights->produit->creer) $product->duration_value = $_POST["duration_value"]; $product->duration_unit = $_POST["duration_unit"]; $product->seuil_stock_alerte = $_POST["seuil_stock_alerte"]; - + // MultiPrix + if($conf->global->PRODUIT_MULTIPRICES == 1) + { + for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) + { + if($_POST["price_".$i]) + $product->multiprices["$i"]=ereg_replace(" ","",$_POST["price_".$i]); + else + $product->multiprices["$i"] = ""; + } + } $e_product = $product; $id = $product->create($user); @@ -286,8 +297,18 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer) } print ''; print ''.$langs->trans("Label").''; - print ''.$langs->trans("SellingPrice").''; - + + if($conf->global->PRODUIT_MULTIPRICES == 1) + { + print ''.$langs->trans("SellingPrice").' 1'; + for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) + { + print ''.$langs->trans("SellingPrice").' '.$i.''; + } + } + // PRIX + else + print ''.$langs->trans("SellingPrice").''; $langs->load("bills"); print ''.$langs->trans("VATRate").''; print $html->select_tva("tva_tx",$conf->defaulttx,$mysoc,''); @@ -460,11 +481,25 @@ if ($_GET["id"] || $_GET["ref"]) // Libelle print ''.$langs->trans("Label").''.$product->libelle.''; print ''; - - // Prix - print ''.$langs->trans("SellingPrice").''.price($product->price).''; - print ''; - + + // MultiPrix + if($conf->global->PRODUIT_MULTIPRICES == 1) + { + print ''.$langs->trans("SellingPrice").' 1'.price($product->price).''; + print ''; + for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) + { + print ''.$langs->trans("SellingPrice").' '.$i.''.price($product->multiprices["$i"]).''; + print ''; + } + } + // Prix + else + { + print ''.$langs->trans("SellingPrice").''.price($product->price).''; + print ''; + } + // Statut print ''.$langs->trans("Status").''; if ($product->envente) print $langs->trans("OnSell"); diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 92594763075..587fd936723 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2005 Laurent Destailleur * Copyright (C) 2005 Eric Seigne * Copyright (C) 2005 Regis Houssin + * Copyright (C) 2006 Andre Cianfarani * * 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 @@ -57,9 +58,19 @@ if ($_POST["action"] == 'update_price' && $result = $product->fetch($_GET["id"]); $product->price = ereg_replace(" ","",$_POST["price"]); + // MultiPrix + if($conf->global->PRODUIT_MULTIPRICES == 1) + { + for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) + { + if($_POST["price_".$i]) + $product->multiprices["$i"]=ereg_replace(" ","",$_POST["price_".$i]); + else + $product->multiprices["$i"] = ""; + } + } if ( $product->update_price($product->id, $user) > 0 ) - { $_GET["action"] = ''; $mesg = 'Fiche mise à jour'; @@ -168,9 +179,20 @@ print ''; print ''.$langs->trans("Label").''.$product->libelle.''; print ''; -// Prix -print ''.$langs->trans("SellingPrice").''.price($product->price).''; +// MultiPrix +if($conf->global->PRODUIT_MULTIPRICES == 1) +{ + print ''.$langs->trans("SellingPrice").' 1'.price($product->price).''; + for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) + { + print ''.$langs->trans("SellingPrice").' '.$i.''.price($product->multiprices["$i"]).''; + print ''; + } +} +// Prix +else + print ''.$langs->trans("SellingPrice").''.price($product->price).''; // Statut print ''.$langs->trans("Status").''; if ($product->envente) print $langs->trans("OnSell"); @@ -213,20 +235,59 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer) print ''; print ''; print ''; + if($conf->global->PRODUIT_MULTIPRICES == 1) + print ''; + else print ''; print ''; print '
'.$langs->trans('SellingPrice').' 1
'.$langs->trans('SellingPrice').'
 '; print '
'; print ''; + // MultiPrix + if($conf->global->PRODUIT_MULTIPRICES == 1) + { + for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) + { + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'.$langs->trans("SellingPrice").' '.$i.'
 '; + print '
'; + print '
'; + } + } } // Liste des evolutions du prix -$sql = "SELECT p.rowid, p.price, ".$db->pdate("p.date_price")." as dp, u.rowid as user_id, u.login"; -$sql .= " FROM ".MAIN_DB_PREFIX."product_price as p, llx_user as u"; -$sql .= " WHERE fk_product = ".$product->id; -$sql .= " AND p.fk_user_author = u.rowid "; -$sql .= " ORDER BY p.date_price DESC "; +$sql = "SELECT p.rowid, p.price, "; +if($conf->global->PRODUIT_MULTIPRICES == 1) +{ + $sql .= "p.price_level, "; + $sql .= $db->pdate("p.date_price")." as dp, u.rowid as user_id, u.login"; + $sql .= " FROM ".MAIN_DB_PREFIX."product_price as p, llx_user as u"; + $sql .= " WHERE fk_product = ".$product->id; + $sql .= " AND p.fk_user_author = u.rowid "; + $sql .= " ORDER BY p.price_level ASC "; + $sql .= ",p.date_price DESC "; +} +else +{ + $sql .= $db->pdate("p.date_price")." as dp, u.rowid as user_id, u.login"; + $sql .= " FROM ".MAIN_DB_PREFIX."product_price as p, llx_user as u"; + $sql .= " WHERE fk_product = ".$product->id; + $sql .= " AND p.fk_user_author = u.rowid "; + $sql .= " ORDER BY p.date_price DESC "; +} + + + + + $sql .= $db->plimit(); $result = $db->query($sql) ; @@ -254,6 +315,8 @@ if ($result) print ''; print ''.$langs->trans("AppliedPricesFrom").''; + if($conf->global->PRODUIT_MULTIPRICES == 1) + print ''.$langs->trans("MultiPriceLevelsName").''; print ''.$langs->trans("Price").''; print ''.$langs->trans("ChangedBy").''; print ''; @@ -269,6 +332,10 @@ if ($result) // Date print "".dolibarr_print_date($objp->dp,"%d %b %Y %H:%M:%S").""; + // catégorie de Prix + if($conf->global->PRODUIT_MULTIPRICES == 1) + print "".$objp->price_level.""; + // Prix print "".price($objp->price).""; diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 1882a31dcf0..02be100d02b 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2004 Éric Seigne * Copyright (C) 2004-2005 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2006 Andre Cianfarani * * 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 @@ -132,7 +133,8 @@ class Propal */ function insert_product($idproduct, $qty, $remise_percent=0, $p_desc='') { - dolibarr_syslog("propal.class.php::insert_product $idproduct, $qty, $remise_percent, $p_desc"); + global $conf; + dolibarr_syslog("propal.class.php::insert_product $idproduct, $qty, $remise_percent, $p_desc"); if ($this->statut == 0) { // Nettoyage parametres @@ -141,13 +143,26 @@ class Propal if ($idproduct) { - $prod = new Product($this->db, $idproduct); + $prod = new Product($this->db, $idproduct); if ($prod->fetch($idproduct) > 0) { - $txtva = $prod->tva_tx; - $price = price2num($prod->price); - $subprice = price2num($prod->price); + // multiprix + if($conf->global->PRODUIT_MULTIPRICES == 1) + { + $this -> fetch_client(); + $price = price2num($prod->multiprices[$this->client->price_level]); + $subprice = price2num($prod->multiprices[$this->client->price_level]); + } + else + { + $price = price2num($prod->price); + $subprice = price2num($prod->price); + } + $txtva = $prod->tva_tx; + /* + */ + // Calcul remise et nouveau prix $remise = 0; if ($remise_percent > 0) @@ -341,7 +356,6 @@ class Propal function create() { global $langs,$conf; - // Définition paramètres $this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600); diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index 5fd5207362c..f3df034c1a6 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -3,7 +3,7 @@ * Copyright (C) 2004-2005 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2003 Brian Fraval - * + * Copyright (C) 2006 Andre Cianfarani * * 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 @@ -78,6 +78,8 @@ class Societe { var $stcomm_id; var $statut_commercial; + + var $price_level; /** @@ -406,7 +408,7 @@ class Societe { function fetch($socid, $user=0) { global $langs; - + global $conf; /* Lecture des permissions */ if ($user <> 0) { @@ -427,6 +429,9 @@ class Societe { } $sql = 'SELECT s.idp, s.nom, s.address,'.$this->db->pdate('s.datec').' as dc, prefix_comm'; + // multiprix + if($conf->global->PRODUIT_MULTIPRICES == 1) + $sql .= ', s.price_level'; $sql .= ','. $this->db->pdate('s.tms').' as date_update'; $sql .= ', s.tel, s.fax, s.url,s.cp,s.ville, s.note, s.siren, client, fournisseur'; $sql .= ', s.siret, s.capital, s.ape, s.tva_intra, s.rubrique'; @@ -536,6 +541,9 @@ class Societe { $this->rubrique = $obj->rubrique; $this->note = $obj->note; + // multiprix + if($conf->global->PRODUIT_MULTIPRICES == 1) + $this->price_level = $obj->price_level; $result = 1; } @@ -849,6 +857,27 @@ class Societe { } } +function set_price_level($price_level, $user) + { + if ($this->id) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; + $sql .= " SET price_level = '".$price_level."'"; + $sql .= " WHERE idp = " . $this->id .";"; + + $this->db->query($sql); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_prices "; + $sql .= " ( datec, fk_soc, price_level, fk_user_author )"; + $sql .= " VALUES (now(),".$this->id.",'".$price_level."',".$user->id.")"; + + if (! $this->db->query($sql) ) + { + dolibarr_print_error($this->db); + } + + } + } /** *