Uniformisation du code: Tous les modules de gnration de document PDF s'active dans la table llx_document_model plutot que les n tables llx_xxxx_model_pdf.

Cela rduit le nombres de tables et permet plus de mutualisation du code. Ainsi, tous les modules peuvent avoir maintenant plusieurs modle actifs, et 1 modle dfaut.
This commit is contained in:
Laurent Destailleur
2006-04-28 22:54:02 +00:00
parent 1222d9a1d9
commit ad4c4e7acd
29 changed files with 946 additions and 659 deletions

View File

@@ -33,9 +33,10 @@
require("./pre.inc.php");
$langs->load("admin");
$langs->load("bills");
$langs->load("other");
$langs->load("orders");
llxHeader();
if (!$user->admin)
accessforbidden();
@@ -45,50 +46,76 @@ if (!$user->admin)
* Actions
*/
if ($_GET["action"] == 'setmod')
{
dolibarr_set_const($db,'COMMANDE_ADDON',$_GET["value"]);
}
if ($_GET["action"] == 'set')
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_model_pdf (nom) VALUES ('".$_GET["value"]."')";
$resql=$db->query($sql);
if (! $resql)
$type='order';
$sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type) VALUES ('".$_GET["value"]."','".$type."')";
if ($db->query($sql))
{
dolibarr_print_error($db);
}
}
if ($_GET["action"] == 'setpdf')
{
dolibarr_set_const($db,'COMMANDE_ADDON_PDF',$_GET["value"]);
// On active le modele
$sql_del = "delete from ".MAIN_DB_PREFIX."commande_model_pdf where nom = '".$_GET["value"]."';";
$resql=$db->query($sql_del);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_model_pdf (nom) VALUES ('".$_GET["value"]."')";
$resql=$db->query($sql);
if (! $resql)
{
dolibarr_print_error($db);
}
}
if ($_GET["action"] == 'del')
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_model_pdf WHERE nom='".$_GET["value"]."'";
$resql=$db->query($sql);
if (! $resql)
$sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom='".$_GET["value"]."'";
if ($db->query($sql))
{
dolibarr_print_error($db);
}
}
if ($_GET["action"] == 'setdoc')
{
$db->begin();
if (dolibarr_set_const($db, "COMMANDE_ADDON_PDF",$_GET["value"]))
{
// La constante qui a <20>t<EFBFBD> lue en avant du nouveau set
// on passe donc par une variable pour avoir un affichage coh<6F>rent
$conf->global->COMMANDE_ADDON_PDF = $_GET["value"];
}
// On active le modele
$type='order';
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model where nom = '".$_GET["value"]."'";
$result1=$db->query($sql_del);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom,type) VALUES ('".$_GET["value"]."','".$type."')";
$result2=$db->query($sql);
if ($result1 && $result2)
{
$db->commit();
}
else
{
$db->rollback();
}
}
if ($_GET["action"] == 'setmod')
{
// \todo Verifier si module numerotation choisi peut etre activ<69>
// par appel methode canBeActivated
if (dolibarr_set_const($db, "COMMANDE_ADDON",$_GET["value"]))
{
// la constante qui a <20>t<EFBFBD> lue en avant du nouveau set
// on passe donc par une variable pour avoir un affichage coh<6F>rent
$conf->global->COMMANDE_ADDON = $_GET["value"];
}
}
/*
* Affichage page
*/
llxHeader();
$dir = "../includes/modules/commande/";
$html=new Form($db);
print_titre($langs->trans("OrdersSetup"));
@@ -98,9 +125,11 @@ print_titre($langs->trans("OrdersNumberingModules"));
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td width="100">'.$langs->trans("Name").'</td><td>'.$langs->trans("Description").'</td>';
print '<td width="100">'.$langs->trans("Name").'</td>';
print '<td>'.$langs->trans("Description").'</td>';
print '<td>'.$langs->trans("Example").'</td>';
print '<td align="center" width="60">'.$langs->trans("Activated").'</td>';
print '<td align="center" width="16">'.$langs->trans("Info").'</td>';
print "</tr>\n";
clearstatcache();
@@ -119,27 +148,37 @@ if ($handle)
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/commande/".$file.".php");
$modCommande = new $file;
$module = new $file;
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$modCommande->nom."</td><td>\n";
print $modCommande->info();
print '<tr '.$bc[$var].'><td>'.$module->nom."</td><td>\n";
print $module->info();
print '</td>';
print '<td align="center" nowrap>';
print $modCommande->getExample();
print '</td>';
// Examples
print '<td nowrap="nowrap">'.$module->getExample()."</td>\n";
print '<td align="center">';
if ($conf->global->COMMANDE_ADDON == "$file")
{
print '<td align="center">';
print img_tick();
print '</td>';
print img_tick($langs->trans("Activated"));
}
else
{
print '<td align="center"><a href="commande.php?action=setmod&amp;value='.$file.'">'.$langs->trans("Activate").'</a></td>';
print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'" alt="'.$langs->trans("Default").'">'.$langs->trans("Activate").'</a>';
}
print '</td>';
// Info
$htmltooltip='';
$nextval=$module->getNextValue();
if ($nextval != $langs->trans("NotAvailable"))
{
$htmltooltip='<b>'.$langs->trans("NextValue").'</b>: '.$nextval;
}
print '<td align="center" '.$html->tooltip_properties($htmltooltip).'>';
print ($htmltooltip?img_help(0):'');
print '</td>';
print '</tr>';
}
@@ -147,26 +186,19 @@ if ($handle)
closedir($handle);
}
print '</table>';
print '</table><br>';
/*
* PDF
* Modeles de documents
*/
print '<br>';
print_titre($langs->trans("OrdersModelModule"));
print "<table class=\"noborder\" width=\"100%\">\n";
print "<tr class=\"liste_titre\">\n";
print ' <td width="100">'.$langs->trans("Name")."</td>\n";
print " <td>".$langs->trans("Description")."</td>\n";
print ' <td align="center" width="100">'.$langs->trans("Activated")."</td>\n";
print ' <td align="center" width="60">'.$langs->trans("Default")."</td>\n";
print "</tr>\n";
clearstatcache();
// Defini tableau def de modele propal
$type='order';
$def = array();
$sql = "SELECT nom FROM ".MAIN_DB_PREFIX."commande_model_pdf";
$sql = "SELECT nom";
$sql.= " FROM ".MAIN_DB_PREFIX."document_model";
$sql.= " WHERE type = '".$type."'";
$resql=$db->query($sql);
if ($resql)
{
@@ -174,8 +206,8 @@ if ($resql)
$num_rows=$db->num_rows($resql);
while ($i < $num_rows)
{
$obj = $db->fetch_object($resql);
array_push($def, $obj->nom);
$array = $db->fetch_array($resql);
array_push($def, $array[0]);
$i++;
}
}
@@ -183,8 +215,23 @@ else
{
dolibarr_print_error($db);
}
$dir = "../includes/modules/commande/";
print "<table class=\"noborder\" width=\"100%\">\n";
print "<tr class=\"liste_titre\">\n";
print ' <td width="100">'.$langs->trans("Name")."</td>\n";
print " <td>".$langs->trans("Description")."</td>\n";
print '<td align="center" width="60">'.$langs->trans("Activated")."</td>\n";
print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
print '<td align="center" width="16">'.$langs->trans("Info").'</td>';
print "</tr>\n";
clearstatcache();
$handle=opendir($dir);
$var=True;
$var=true;
while (($file = readdir($handle))!==false)
{
if (eregi('\.modules\.php$',$file) && substr($file,0,4) == 'pdf_')
@@ -197,40 +244,56 @@ while (($file = readdir($handle))!==false)
print "$name";
print "</td>\n <td>\n";
require_once($dir.$file);
$obj = new $classname($db);
print $obj->description;
$module = new $classname($db);
print $module->description;
print "</td>\n";
// Activ<69>
print "<td align=\"center\">\n";
if (in_array($name, $def))
{
print img_tick().' ';
if ($conf->global->COMMANDE_ADDON_PDF != "$name")
print "<td align=\"center\">\n";
if ($conf->global->COMMANDE_ADDON_PDF != "$name")
{
print '<a href="commande.php?action=del&amp;value='.$name.'">'.$langs->trans("Disable").'</a>';
print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'">';
print img_tick($langs->trans("Disable"));
print '</a>';
}
else
{
print img_tick($langs->trans("Enabled"));
}
print "</td>";
}
else
{
print '<a href="commande.php?action=set&amp;value='.$name.'">'.$langs->trans("Activate").'</a>';
print "<td align=\"center\">\n";
print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'">'.$langs->trans("Activate").'</a>';
print "</td>";
}
print "</td>\n";
// Defaut
print "<td align=\"center\">";
if ($conf->global->COMMANDE_ADDON_PDF == "$name")
{
print img_tick();
print img_tick($langs->trans("Default"));
}
else
{
print '<a href="commande.php?action=setpdf&amp;value='.$name.'">'.$langs->trans("Default").'</a>';
print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'" alt="'.$langs->trans("Default").'">'.$langs->trans("Default").'</a>';
}
print '</td></tr>';
print '</td>';
// Info
$htmltooltip = '<b>'.$langs->trans("Type").'</b>: '.($module->type?$module->type:$langs->trans("Unknown"));
$htmltooltip.='<br><b>'.$langs->trans("Width").'</b>: '.$module->page_largeur;
$htmltooltip.='<br><b>'.$langs->trans("Height").'</b>: '.$module->page_hauteur;
$htmltooltip.='<br>'.$langs->trans("FeaturesSupported").':';
$htmltooltip.='<br><b>'.$langs->trans("Logo").'</b>: '.yn($module->option_logo);
$htmltooltip.='<br><b>'.$langs->trans("PaymentMode").'</b>: '.yn($module->option_modereg);
$htmltooltip.='<br><b>'.$langs->trans("PaymentConditions").'</b>: '.yn($module->option_condreg);
print '<td align="center" '.$html->tooltip_properties($htmltooltip).'>'.img_help(0).'</td>';
print "</tr>\n";
}
}
closedir($handle);