From 40b38892b5e6176cb1c209c4f249333ea38a4e7e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 6 Nov 2009 18:38:35 +0000 Subject: [PATCH] Fix: Usage of alternate document root works with invoice numbering modules. --- htdocs/admin/facture.php | 427 ++++++++++++++++++++------------------- htdocs/admin/propale.php | 121 +++++------ htdocs/facture.class.php | 33 +-- 3 files changed, 302 insertions(+), 279 deletions(-) diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index 5a56b90c369..73bb1537c45 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -37,7 +37,7 @@ $langs->load("bills"); $langs->load("other"); if (!$user->admin) - accessforbidden(); +accessforbidden(); $typeconst=array('yesno','texte','chaine'); $dir = DOL_DOCUMENT_ROOT."/includes/modules/facture/"; @@ -94,108 +94,108 @@ if ($_GET["action"] == 'specimen') if ($_GET["action"] == 'set') { $type='invoice'; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES ('".$_GET["value"]."','".$type."',".$conf->entity.")"; - if ($db->query($sql)) - { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES ('".$_GET["value"]."','".$type."',".$conf->entity.")"; + if ($db->query($sql)) + { - } + } } if ($_GET["action"] == 'del') { - $type='invoice'; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; - $sql.= " WHERE nom = '".$_GET["value"]; - $sql.= " AND type = '".$type."'"; - $sql.= " AND entity = ".$conf->entity; + $type='invoice'; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; + $sql.= " WHERE nom = '".$_GET["value"]; + $sql.= " AND type = '".$type."'"; + $sql.= " AND entity = ".$conf->entity; - if ($db->query($sql)) - { + if ($db->query($sql)) + { - } + } } if ($_GET["action"] == 'setdoc') { $db->begin(); - if (dolibarr_set_const($db, "FACTURE_ADDON_PDF",$_GET["value"],'chaine',0,'',$conf->entity)) - { - $conf->global->FACTURE_ADDON_PDF = $_GET["value"]; - } + if (dolibarr_set_const($db, "FACTURE_ADDON_PDF",$_GET["value"],'chaine',0,'',$conf->entity)) + { + $conf->global->FACTURE_ADDON_PDF = $_GET["value"]; + } - // On active le modele - $type='invoice'; - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; - $sql_del.= " WHERE nom = '".$_GET["value"]; - $sql_del.= " AND type = '".$type."'"; - $sql_del.= " AND entity = ".$conf->entity; - $result1=$db->query($sql_del); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom,type,entity) VALUES ('".$_GET["value"]."','".$type."',".$conf->entity.")"; - $result2=$db->query($sql); - if ($result1 && $result2) - { + // On active le modele + $type='invoice'; + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; + $sql_del.= " WHERE nom = '".$_GET["value"]; + $sql_del.= " AND type = '".$type."'"; + $sql_del.= " AND entity = ".$conf->entity; + $result1=$db->query($sql_del); + $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom,type,entity) VALUES ('".$_GET["value"]."','".$type."',".$conf->entity.")"; + $result2=$db->query($sql); + if ($result1 && $result2) + { $db->commit(); - } - else - { - $db->rollback(); - } + } + else + { + $db->rollback(); + } } if ($_GET["action"] == 'setmod') { - // TODO Verifier si module numerotation choisi peut etre active - // par appel methode canBeActivated + // TODO Verifier si module numerotation choisi peut etre active + // par appel methode canBeActivated dolibarr_set_const($db, "FACTURE_ADDON",$_GET["value"],'chaine',0,'',$conf->entity); } if ($_POST["action"] == 'setribchq') { - dolibarr_set_const($db, "FACTURE_RIB_NUMBER",$_POST["rib"],'chaine',0,'',$conf->entity); - dolibarr_set_const($db, "FACTURE_CHQ_NUMBER",$_POST["chq"],'chaine',0,'',$conf->entity); + dolibarr_set_const($db, "FACTURE_RIB_NUMBER",$_POST["rib"],'chaine',0,'',$conf->entity); + dolibarr_set_const($db, "FACTURE_CHQ_NUMBER",$_POST["chq"],'chaine',0,'',$conf->entity); } if ($_POST["action"] == 'set_FACTURE_DRAFT_WATERMARK') { - dolibarr_set_const($db, "FACTURE_DRAFT_WATERMARK",trim($_POST["FACTURE_DRAFT_WATERMARK"]),'chaine',0,'',$conf->entity); + dolibarr_set_const($db, "FACTURE_DRAFT_WATERMARK",trim($_POST["FACTURE_DRAFT_WATERMARK"]),'chaine',0,'',$conf->entity); } if ($_POST["action"] == 'set_FACTURE_FREE_TEXT') { - dolibarr_set_const($db, "FACTURE_FREE_TEXT",$_POST["FACTURE_FREE_TEXT"],'chaine',0,'',$conf->entity); + dolibarr_set_const($db, "FACTURE_FREE_TEXT",$_POST["FACTURE_FREE_TEXT"],'chaine',0,'',$conf->entity); } if ($_POST["action"] == 'setforcedate') { - dolibarr_set_const($db, "FAC_FORCE_DATE_VALIDATION",$_POST["forcedate"],'chaine',0,'',$conf->entity); + dolibarr_set_const($db, "FAC_FORCE_DATE_VALIDATION",$_POST["forcedate"],'chaine',0,'',$conf->entity); } if ($_POST["action"] == 'set_enable_editdelete') { - dolibarr_set_const($db, "FACTURE_ENABLE_EDITDELETE",$_POST["enable_editdelete"],'chaine',0,'',$conf->entity); + dolibarr_set_const($db, "FACTURE_ENABLE_EDITDELETE",$_POST["enable_editdelete"],'chaine',0,'',$conf->entity); } if ($_POST["action"] == 'set_use_bill_contact_as_recipient') { - dolibarr_set_const($db, "FACTURE_USE_BILL_CONTACT_AS_RECIPIENT",$_POST["use_bill_contact_as_recipient"],'chaine',0,'',$conf->entity); + dolibarr_set_const($db, "FACTURE_USE_BILL_CONTACT_AS_RECIPIENT",$_POST["use_bill_contact_as_recipient"],'chaine',0,'',$conf->entity); } if ($_POST["action"] == 'update' || $_POST["action"] == 'add') { if (! dolibarr_set_const($db, $_POST["constname"],$_POST["constvalue"],$typeconst[$_POST["consttype"]],0,isset($_POST["constnote"])?$_POST["constnote"]:'',$conf->entity)); { - dol_print_error($db); + dol_print_error($db); } } if ($_GET["action"] == 'delete') { - if (! dolibarr_del_const($db, $_GET["rowid"],$conf->entity)); - { - dol_print_error($db); - } + if (! dolibarr_del_const($db, $_GET["rowid"],$conf->entity)); + { + dol_print_error($db); + } } // defini les constantes du modele pluton @@ -248,96 +248,107 @@ print ''."\n"; clearstatcache(); -$handle=opendir($dir); - $var=true; -while (($file = readdir($handle))!==false) +foreach ($conf->file->dol_document_root as $dirroot) { - if (is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') - { - $filebis = $file."/".$file.".modules.php"; - if (is_readable($dir.$filebis)) + $dir = $dirroot . "/includes/modules/facture/"; + + if (is_dir($dir)) + { + $handle = opendir($dir); + if ($handle) { - // Chargement de la classe de num�rotation - require_once($dir.$filebis); - $classname = "mod_facture_".$file; - $module = new $classname($db); - - // Show modules according to features level - if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; - if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; - - if ($module->isEnabled()) - { - $var = !$var; - print ''; - echo "$file"; - print "\n"; - - print $module->info(); - - print ''; - - // Affiche example - print ''.$module->getExample().''; - - print ''; - if ($conf->global->FACTURE_ADDON == "$file") - { - print img_tick($langs->trans("Activated")); - } - else - { - print ''.$langs->trans("Default").''; - } - print ''; - - $facture=new Facture($db); - $facture->initAsSpecimen(); - - // Example for standard invoice - $htmltooltip=''; - $htmltooltip.=''.$langs->trans("Version").': '.$module->getVersion().'
'; - $facture->type=0; - $nextval=$module->getNextValue($mysoc,$facture); - if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval + while (($file = readdir($handle))!==false) + { + if (is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') { - $htmltooltip.=$langs->trans("NextValueForInvoices").': '; - if ($nextval) + $filebis = $file."/".$file.".modules.php"; + + if (is_readable($dir.$filebis)) { - $htmltooltip.=$nextval.'
'; - } - else - { - $htmltooltip.=$langs->trans($module->error).'
'; + // Chargement de la classe de num�rotation + require_once($dir.$filebis); + $classname = "mod_facture_".$file; + $module = new $classname($db); + + // Show modules according to features level + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; + if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; + + if ($module->isEnabled()) + { + $var = !$var; + print ''; + echo "$file"; + print "\n"; + + print $module->info(); + + print ''; + + // Affiche example + print ''.$module->getExample().''; + + print ''; + if ($conf->global->FACTURE_ADDON == "$file") + { + print img_tick($langs->trans("Activated")); + } + else + { + print ''.$langs->trans("Default").''; + } + print ''; + + $facture=new Facture($db); + $facture->initAsSpecimen(); + + // Example for standard invoice + $htmltooltip=''; + $htmltooltip.=''.$langs->trans("Version").': '.$module->getVersion().'
'; + $facture->type=0; + $nextval=$module->getNextValue($mysoc,$facture); + if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval + { + $htmltooltip.=$langs->trans("NextValueForInvoices").': '; + if ($nextval) + { + $htmltooltip.=$nextval.'
'; + } + else + { + $htmltooltip.=$langs->trans($module->error).'
'; + } + } + // Example for credit invoice + $facture->type=2; + $nextval=$module->getNextValue($mysoc,$facture); + if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval + { + $htmltooltip.=$langs->trans("NextValueForCreditNotes").': '; + if ($nextval) + { + $htmltooltip.=$nextval; + } + else + { + $htmltooltip.=$langs->trans($module->error); + } + } + + print ''; + print $html->textwithpicto('',$htmltooltip,1,0); + print ''; + + print "\n"; + } } } - // Example for credit invoice - $facture->type=2; - $nextval=$module->getNextValue($mysoc,$facture); - if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval - { - $htmltooltip.=$langs->trans("NextValueForCreditNotes").': '; - if ($nextval) - { - $htmltooltip.=$nextval; - } - else - { - $htmltooltip.=$langs->trans($module->error); - } - } - - print ''; - print $html->textwithpicto('',$htmltooltip,1,0); - print ''; - - print "\n"; - } + } + closedir($handle); } - } + } } -closedir($handle); print ''; @@ -387,20 +398,20 @@ $handle=opendir($dir); $var=True; while (($file = readdir($handle))!==false) { - if (preg_match('/\.modules\.php$/i',$file) && substr($file,0,4) == 'pdf_') - { - $var = !$var; - $name = substr($file, 4, strlen($file) -16); - $classname = substr($file, 0, strlen($file) -12); + if (preg_match('/\.modules\.php$/i',$file) && substr($file,0,4) == 'pdf_') + { + $var = !$var; + $name = substr($file, 4, strlen($file) -16); + $classname = substr($file, 0, strlen($file) -12); - print ''; - echo "$name"; - print "\n"; + print ''; + echo "$name"; + print "\n"; - require_once($dir.$file); - $module = new $classname($db); - print $module->description; - print ''; + require_once($dir.$file); + $module = new $classname($db); + print $module->description; + print ''; // Active if (in_array($name, $def)) @@ -438,28 +449,28 @@ while (($file = readdir($handle))!==false) print ''; // Info - $htmltooltip = ''.$langs->trans("Name").': '.$module->name; - $htmltooltip.='
'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); - $htmltooltip.='
'.$langs->trans("Height").'/'.$langs->trans("Width").': '.$module->page_hauteur.'/'.$module->page_largeur; - $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; - $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); - $htmltooltip.='
'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1); - $htmltooltip.='
'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1); - $htmltooltip.='
'.$langs->trans("Escompte").': '.yn($module->option_escompte,1,1); - $htmltooltip.='
'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1); - $htmltooltip.='
'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1); + $htmltooltip = ''.$langs->trans("Name").': '.$module->name; + $htmltooltip.='
'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); + $htmltooltip.='
'.$langs->trans("Height").'/'.$langs->trans("Width").': '.$module->page_hauteur.'/'.$module->page_largeur; + $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; + $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); + $htmltooltip.='
'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1); + $htmltooltip.='
'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1); + $htmltooltip.='
'.$langs->trans("Escompte").': '.yn($module->option_escompte,1,1); + $htmltooltip.='
'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1); + $htmltooltip.='
'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1); $htmltooltip.='
'.$langs->trans("WatermarkOnDraftInvoices").': '.yn($module->option_draft_watermark,1,1); - print ''; - print $html->textwithpicto('',$htmltooltip,1,0); - print ''; - print ''; - print ''.img_object($langs->trans("Preview"),'bill').''; - print ''; + print ''; + print $html->textwithpicto('',$htmltooltip,1,0); + print ''; + print ''; + print ''.img_object($langs->trans("Preview"),'bill').''; + print ''; - print "\n"; - } + print "\n"; + } } closedir($handle); @@ -490,39 +501,39 @@ print "".$langs->trans("SuggestPaymentByRIBOnAccount").""; print ""; if ($conf->banque->enabled) { - $sql = "SELECT rowid, label"; - $sql.= " FROM ".MAIN_DB_PREFIX."bank_account"; - $sql.= " WHERE clos = 0"; - $sql.= " AND courant = 1"; - $sql.= " AND entity = ".$conf->entity; - $resql=$db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - if ($num > 0) { - print ""; + print ''; + while ($i < $num) + { + $var=!$var; + $row = $db->fetch_row($resql); - print ''; + print ''; - $i++; - } - print ""; - } else { - print "".$langs->trans("NoActiveBankAccountDefined").""; - } - } + $i++; + } + print ""; + } else { + print "".$langs->trans("NoActiveBankAccountDefined").""; + } + } } else { - print $langs->trans("BankModuleNotActive"); + print $langs->trans("BankModuleNotActive"); } print ""; $var=!$var; @@ -542,18 +553,18 @@ $var=True; $resql=$db->query($sql); if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) { - $var=!$var; - $row = $db->fetch_row($resql); + $var=!$var; + $row = $db->fetch_row($resql); - print ''; + print ''; - $i++; + $i++; } } print ""; @@ -602,19 +613,19 @@ print "\n"; print ''; /* -$var=! $var; -print '
'; -print ''; -print ''; -print ''; -print $langs->trans("UsBillingContactAsIncoiveRecipientIfExist"); -print ''; -print $html->selectyesno("use_bill_contact_as_recipient",$conf->global->FACTURE_USE_BILL_CONTACT_AS_RECIPIENT,1); -print ''; -print ''; -print "\n"; -print '
'; -*/ + $var=! $var; + print '
'; + print ''; + print ''; + print ''; + print $langs->trans("UsBillingContactAsIncoiveRecipientIfExist"); + print ''; + print $html->selectyesno("use_bill_contact_as_recipient",$conf->global->FACTURE_USE_BILL_CONTACT_AS_RECIPIENT,1); + print ''; + print ''; + print "\n"; + print '
'; + */ $var=! $var; print '
'; diff --git a/htdocs/admin/propale.php b/htdocs/admin/propale.php index 62f5dd835dd..25fd9736719 100644 --- a/htdocs/admin/propale.php +++ b/htdocs/admin/propale.php @@ -186,7 +186,6 @@ if ($_GET["action"] == 'setmod') llxHeader('',$langs->trans("PropalSetup")); -$dir = "../includes/modules/propale/"; $html=new Form($db); @@ -210,75 +209,83 @@ print ''."\n"; clearstatcache(); -$handle = opendir($dir); -if ($handle) +$var=true; +foreach ($conf->file->dol_document_root as $dirroot) { - $var=true; - while (($file = readdir($handle))!==false) + $dir = $dirroot . "/includes/modules/propale/"; + + if (is_dir($dir)) { - if (substr($file, 0, 12) == 'mod_propale_' && substr($file, strlen($file)-3, 3) == 'php') + $handle = opendir($dir); + if ($handle) { - $file = substr($file, 0, strlen($file)-4); - - require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/".$file.".php"); - - $module = new $file; - - // Show modules according to features level - if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; - if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; - - if ($module->isEnabled()) + while (($file = readdir($handle))!==false) { - $var=!$var; - print ''.$module->nom."\n"; - print $module->info(); - print ''; - - // Examples - print ''.$module->getExample()."\n"; - - print ''; - if ($conf->global->PROPALE_ADDON == "$file") + if (substr($file, 0, 12) == 'mod_propale_' && substr($file, strlen($file)-3, 3) == 'php') { - print img_tick($langs->trans("Activated")); - } - else - { - print ''.$langs->trans("Activate").''; - } - print ''; + $file = substr($file, 0, strlen($file)-4); - $propale=new Propal($db); - $propale->initAsSpecimen(); + require_once($dir.$file.".php"); - // Info - $htmltooltip=''; - $htmltooltip.=''.$langs->trans("Version").': '.$module->getVersion().'
'; - $facture->type=0; - $nextval=$module->getNextValue($mysoc,$propale); - if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval - { - $htmltooltip.=''.$langs->trans("NextValue").': '; - if ($nextval) + $module = new $file; + + // Show modules according to features level + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; + if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; + + if ($module->isEnabled()) { - $htmltooltip.=$nextval.'
'; - } - else - { - $htmltooltip.=$langs->trans($module->error).'
'; + $var=!$var; + print ''.$module->nom."\n"; + print $module->info(); + print ''; + + // Examples + print ''.$module->getExample()."\n"; + + print ''; + if ($conf->global->PROPALE_ADDON == "$file") + { + print img_tick($langs->trans("Activated")); + } + else + { + print ''.$langs->trans("Activate").''; + } + print ''; + + $propale=new Propal($db); + $propale->initAsSpecimen(); + + // Info + $htmltooltip=''; + $htmltooltip.=''.$langs->trans("Version").': '.$module->getVersion().'
'; + $facture->type=0; + $nextval=$module->getNextValue($mysoc,$propale); + if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval + { + $htmltooltip.=''.$langs->trans("NextValue").': '; + if ($nextval) + { + $htmltooltip.=$nextval.'
'; + } + else + { + $htmltooltip.=$langs->trans($module->error).'
'; + } + } + + print ''; + print $html->textwithpicto('',$htmltooltip,1,0); + print ''; + + print "\n"; } } - - print ''; - print $html->textwithpicto('',$htmltooltip,1,0); - print ''; - - print "\n"; } + closedir($handle); } } - closedir($handle); } print "
\n"; diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index a8fd7b1abb3..5da837164a1 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -2166,18 +2166,23 @@ class Facture extends CommonObject */ function getNextNumRef($soc) { - global $db, $langs; + global $conf, $db, $langs; $langs->load("bills"); - $dir = DOL_DOCUMENT_ROOT . "/includes/modules/facture/"; - if (defined("FACTURE_ADDON") && FACTURE_ADDON) { $file = FACTURE_ADDON."/".FACTURE_ADDON.".modules.php"; - - // Chargement de la classe de numerotation $classname = "mod_facture_".FACTURE_ADDON; - require_once($dir.$file); + + // Include file with class + $mybool=false; + foreach ($conf->file->dol_document_root as $dirroot) + { + $dir = $dirroot."/includes/modules/facture/"; + // Load file with numbering class (if found) + $mybool|=@include_once($dir.$file); + } + if (! $mybool) dol_print_error('',"Failed to include file ".$file); $obj = new $classname(); @@ -2185,14 +2190,14 @@ class Facture extends CommonObject $numref = $obj->getNumRef($soc,$this); if ( $numref != "") - { - return $numref; - } - else - { - dol_print_error($db,"Facture::getNextNumRef ".$obj->error); - return ""; - } + { + return $numref; + } + else + { + dol_print_error($db,"Facture::getNextNumRef ".$obj->error); + return ""; + } } else {