\n";
+print "\n";
+print " | ".$langs->trans("Name")." | \n";
+print " ".$langs->trans("Description")." | \n";
+print ' '.$langs->trans("Activated")." | \n";
+print ' '.$langs->trans("Default")." | \n";
print "
\n";
clearstatcache();
+$def = array();
+$sql = "SELECT nom FROM ".MAIN_DB_PREFIX."commande_model_pdf";
+$resql=$db->query($sql);
+if ($resql)
+{
+ $i = 0;
+ $num_rows=$db->num_rows($resql);
+ while ($i < $num_rows)
+ {
+ $array = $db->fetch_array($resql);
+ array_push($def, $array[0]);
+ $i++;
+ }
+}
+else
+{
+ dolibarr_print_error($db);
+}
$handle=opendir($dir);
-
$var=True;
while (($file = readdir($handle))!==false)
{
- if (eregi('\.modules\.php$',$file) && substr($file,0,4) == 'pdf_')
+ if (eregi('\.modules\.php$',$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";
- require_once($dir.$file);
- $obj = new $classname($db);
-
- print $obj->description;
-
- print ' | ';
-
- if ($commande_addon_var_pdf == "$name")
- {
- print ' ';
- print ' | ';
- print img_tick();
- }
- else
- {
- print ' ';
- // print $commande_addon_var_pdf."iii";
- print ' | ';
- print ''.$langs->trans("Default").'';
- }
- print " |
\n";
-
+
+ $var=!$var;
+ print "\n | ";
+ print "$name";
+ print " | \n \n";
+ require_once($dir.$file);
+ $obj = new $classname($db);
+
+ print $obj->description;
+
+ print " | \n \n";
+
+ if (in_array($name, $def))
+ {
+ print img_tick();
+ print " | \n ";
+ print ''.$langs->trans("Disable").'';
+ }
+ else
+ {
+ print " ";
+ print " | \n ";
+ print ''.$langs->trans("Activate").'';
+ }
+
+ print " | \n ";
+
+ if ($commande_addon_var_pdf == "$name")
+ {
+ print img_tick();
+ }
+ else
+ {
+ print ''.$langs->trans("Activate").'';
+ }
+ print ' |
';
}
}
closedir($handle);
diff --git a/htdocs/includes/modules/commande/modules_commande.php b/htdocs/includes/modules/commande/modules_commande.php
index c1dabf800a1..64358fce26b 100644
--- a/htdocs/includes/modules/commande/modules_commande.php
+++ b/htdocs/includes/modules/commande/modules_commande.php
@@ -25,19 +25,19 @@
*/
/**
- \file htdocs/includes/modules/commande/modules_commande.php
- \ingroup commande
- \brief Fichier contenant la classe mère de generation des commandes en PDF
- et la classe mère de numérotation des commandes
- \version $Revision$
+ \file htdocs/includes/modules/commande/modules_commande.php
+ \ingroup commande
+ \brief Fichier contenant la classe mère de generation des commandes en PDF
+ et la classe mère de numérotation des commandes
+ \version $Revision$
*/
require_once(FPDF_PATH.'fpdf.php');
/**
- \class ModelePDFCommandes
- \brief Classe mère des modèles de commandes
+ \class ModelePDFCommandes
+ \brief Classe mère des modèles de commandes
*/
class ModelePDFCommandes extends FPDF
@@ -55,21 +55,29 @@ class ModelePDFCommandes extends FPDF
/**
* \brief Renvoi la liste des modèles actifs
*/
- function liste_modeles()
+ function liste_modeles($db)
{
$liste=array();
- $dir = "../includes/modules/commande/";
- $handle = opendir($dir);
- $var=True;
- while (($file = readdir($handle))!==false)
- {
- if (eregi('\.modules\.php$',$file) && substr($file,0,4) == 'pdf_')
- {
- $name = substr($file, 4, strlen($file) -16);
- $liste[$name] = $name;
- // $classname = substr($file, 0, strlen($file) -12);
- }
- }
+ $sql ="SELECT nom as id, nom as lib";
+ $sql.=" FROM ".MAIN_DB_PREFIX."commande_model_pdf";
+
+ $resql = $db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ $i = 0;
+ while ($i < $num)
+ {
+ $row = $db->fetch_row($resql);
+ $liste[$row[0]]=$row[1];
+ $i++;
+ }
+ }
+ else
+ {
+ $this->error=$db->error();
+ return -1;
+ }
return $liste;
}
@@ -79,7 +87,7 @@ class ModelePDFCommandes extends FPDF
/**
\class ModeleNumRefCommandes
- \brief Classe mère des modèles de numérotation des références de commandes
+ \brief Classe mère des modèles de numérotation des références de commandes
*/
class ModeleNumRefCommandes
@@ -136,14 +144,14 @@ function commande_pdf_create($db, $comid, $modele='')
if (! strlen($modele))
{
if (defined("COMMANDE_ADDON_PDF") && COMMANDE_ADDON_PDF)
- {
- $modele = COMMANDE_ADDON_PDF;
- }
+ {
+ $modele = COMMANDE_ADDON_PDF;
+ }
else
- {
+ {
print $langs->trans("Error")." ".$langs->trans("Error_PROPALE_ADDON_PDF_NotDefined");
- return 0;
- }
+ return 0;
+ }
}
// Charge le modele
$file = "pdf_".$modele.".modules.php";
@@ -155,17 +163,17 @@ function commande_pdf_create($db, $comid, $modele='')
$obj = new $classname($db);
if ( $obj->write_pdf_file($comid) > 0)
- {
- // on supprime l'image correspondant au preview
- commande_delete_preview($db, $comid);
- return 1;
- }
+ {
+ // on supprime l'image correspondant au preview
+ commande_delete_preview($db, $comid);
+ return 1;
+ }
else
- {
- dolibarr_syslog("Erreur dans commande_pdf_create");
- dolibarr_print_error($db,$obj->pdferror());
- return 0;
- }
+ {
+ dolibarr_syslog("Erreur dans commande_pdf_create");
+ dolibarr_print_error($db,$obj->pdferror());
+ return 0;
+ }
}
else
{
@@ -175,27 +183,27 @@ function commande_pdf_create($db, $comid, $modele='')
}
function commande_delete_preview($db, $propalid)
{
- global $langs,$conf;
+ global $langs,$conf;
- $com = new Commande($db,"",$propalid);
- $com->fetch($propalid);
- $client = new Societe($db);
+ $com = new Commande($db,"",$propalid);
+ $com->fetch($propalid);
+ $client = new Societe($db);
$client->fetch($com->soc_id);
- if ($conf->commande->dir_output)
- {
- $comref = sanitize_string($com->ref);
- $dir = $conf->commande->dir_output . "/" . $comref ;
- $file = $dir . "/" . $comref . ".pdf.png";
+ if ($conf->commande->dir_output)
+ {
+ $comref = sanitize_string($com->ref);
+ $dir = $conf->commande->dir_output . "/" . $comref ;
+ $file = $dir . "/" . $comref . ".pdf.png";
- if ( file_exists( $file ) && is_writable( $file ) )
- {
- if ( ! unlink($file) )
- {
- $this->error=$langs->trans("ErrorFailedToOpenFile",$file);
- return 0;
- }
- }
- }
+ if ( file_exists( $file ) && is_writable( $file ) )
+ {
+ if ( ! unlink($file) )
+ {
+ $this->error=$langs->trans("ErrorFailedToOpenFile",$file);
+ return 0;
+ }
+ }
+ }
}
?>
diff --git a/htdocs/includes/modules/modCommande.class.php b/htdocs/includes/modules/modCommande.class.php
index 00b9f603339..96af6fde042 100644
--- a/htdocs/includes/modules/modCommande.class.php
+++ b/htdocs/includes/modules/modCommande.class.php
@@ -127,8 +127,10 @@ class modCommande extends DolibarrModules
// Dir
$this->dirs[0] = $conf->commande->dir_output;
$this->dirs[1] = $conf->commande->dir_images;
-
- $sql = array();
+ $sql = array(
+ "DELETE FROM ".MAIN_DB_PREFIX."commande_model_pdf WHERE nom = '".$this->const[0][2]."'",
+ "INSERT INTO ".MAIN_DB_PREFIX."commande_model_pdf (nom) VALUES('".$this->const[0][2]."');",
+ );
return $this->_init($sql);
}
@@ -141,7 +143,7 @@ class modCommande extends DolibarrModules
function remove()
{
$sql = array();
-
+
return $this->_remove($sql);
}