Skip to content
Snippets Groups Projects
Commit 3e1d2c3e authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Qual: Mutualized and uniformize code

parent c4f90f81
No related branches found
No related tags found
No related merge requests found
......@@ -118,7 +118,7 @@ else if ($action == 'specimen')
}
// Activate a model
else if ($action == 'set')
if ($action == 'set')
{
$ret = addDocumentModel($value, $type, $label, $scandir);
}
......@@ -264,14 +264,14 @@ foreach ($dirmodels as $reldir)
require_once $dir.$file.'.php';
$module = new $file;
$module = new $file($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())
{
// 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;
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$module->nom."</td><td>\n";
print $module->info();
......@@ -323,7 +323,7 @@ foreach ($dirmodels as $reldir)
print $form->textwithpicto('',$htmltooltip,1,0);
print '</td>';
print '</tr>';
print "</tr>\n";
}
}
}
......@@ -331,17 +331,16 @@ foreach ($dirmodels as $reldir)
}
}
}
print '</table><br>';
print "</table><br>\n";
/*
* Document templates generators
*/
print_titre($langs->trans("OrdersModelModule"));
// Load array def with activated templates
$type='order';
$def = array();
$sql = "SELECT nom";
$sql.= " FROM ".MAIN_DB_PREFIX."document_model";
......
......@@ -40,6 +40,9 @@ if (! $user->admin) accessforbidden();
$action = GETPOST('action','alpha');
$value = GETPOST('value','alpha');
$label = GETPOST('label','alpha');
$scandir = GETPOST('scandir','alpha');
$type='invoice';
/*
......@@ -137,78 +140,40 @@ if ($action == 'setModuleOptions')
}
}
if ($action == 'set')
// Activate a model
else if ($action == 'set')
{
$label = GETPOST('label','alpha');
$scandir = GETPOST('scandir','alpha');
$type='invoice';
$sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
$sql.= " VALUES ('".$db->escape($value)."','".$type."',".$conf->entity.", ";
$sql.= ($label?"'".$db->escape($label)."'":'null').", ";
$sql.= (! empty($scandir)?"'".$db->escape($scandir)."'":"null");
$sql.= ")";
if ($db->query($sql))
{
}
$ret = addDocumentModel($value, $type, $label, $scandir);
}
if ($action == 'del')
else if ($action == 'del')
{
$type='invoice';
$sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
$sql.= " WHERE nom = '".$db->escape($value)."'";
$sql.= " AND type = '".$type."'";
$sql.= " AND entity = ".$conf->entity;
if ($db->query($sql))
{
$ret = delDocumentModel($value, $type);
if ($ret > 0)
{
if ($conf->global->FACTURE_ADDON_PDF == "$value") dolibarr_del_const($db, 'FACTURE_ADDON_PDF',$conf->entity);
}
}
}
if ($action == 'setdoc')
// Set default model
else if ($action == 'setdoc')
{
$label = GETPOST('label','alpha');
$scandir = GETPOST('scandir','alpha');
$db->begin();
if (dolibarr_set_const($db, "FACTURE_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
{
$conf->global->FACTURE_ADDON_PDF = $value;
}
// On active le modele
$type='invoice';
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
$sql_del.= " WHERE nom = '".$db->escape($value)."'";
$sql_del.= " AND type = '".$type."'";
$sql_del.= " AND entity = ".$conf->entity;
dol_syslog("Delete from model table ".$sql_del);
$result1=$db->query($sql_del);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
$sql.= " VALUES ('".$value."', '".$type."', ".$conf->entity.", ";
$sql.= ($label?"'".$db->escape($label)."'":'null').", ";
$sql.= (! empty($scandir)?"'".$scandir."'":"null");
$sql.= ")";
dol_syslog("Insert into model table ".$sql);
$result2=$db->query($sql);
if ($result1 && $result2)
{
$db->commit();
}
else
{
dol_syslog("Error ".$db->lasterror(), LOG_ERR);
$db->rollback();
}
if (dolibarr_set_const($db, "FACTURE_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
{
// La constante qui a ete lue en avant du nouveau set
// on passe donc par une variable pour avoir un affichage coherent
$conf->global->FACTURE_ADDON_PDF = $value;
}
// On active le modele
$ret = delDocumentModel($value, $type);
if ($ret > 0)
{
$ret = addDocumentModel($value, $type, $label, $scandir);
}
}
if ($action == 'setmod')
else if ($action == 'setmod')
{
// TODO Verifier si module numerotation choisi peut etre active
// par appel methode canBeActivated
......
......@@ -193,8 +193,7 @@ if ($action == 'setModuleOptions')
}
// Activate a model
if ($action == 'set')
{
$ret = addDocumentModel($value, $type, $label, $scandir);
......@@ -359,16 +358,16 @@ print "</table><br>\n";
/*
* Modeles de documents
* Document templates generators
*/
print_titre($langs->trans("ProposalsPDFModules"));
// Defini tableau def de modele propal
// Load array def with activated templates
$def = array();
$sql = "SELECT nom";
$sql.= " FROM ".MAIN_DB_PREFIX."document_model";
$sql.= " WHERE type = 'propal'";
$sql.= " WHERE type = '".$type."'";
$sql.= " AND entity = ".$conf->entity;
$resql=$db->query($sql);
if ($resql)
......@@ -390,7 +389,7 @@ else
print "<table class=\"noborder\" width=\"100%\">\n";
print "<tr class=\"liste_titre\">\n";
print " <td width=\"140\">".$langs->trans("Name")."</td>\n";
print " <td>".$langs->trans("Name")."</td>\n";
print " <td>".$langs->trans("Description")."</td>\n";
print '<td align="center" width="40">'.$langs->trans("Status")."</td>\n";
print '<td align="center" width="40">'.$langs->trans("Default")."</td>\n";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment