diff --git a/htdocs/admin/commande.php b/htdocs/admin/commande.php index 4908e7a0eea3172cd2724bcbbee54bd66c26fc23..391b399ceaa30fd3cdbc88191393a3de6adee676 100644 --- a/htdocs/admin/commande.php +++ b/htdocs/admin/commande.php @@ -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"; diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index ffef57c9d66e0118e3af52afa67088056c383e56..4f7f072947263f4e295af20b9d178d4446e5a9b9 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -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 diff --git a/htdocs/admin/propal.php b/htdocs/admin/propal.php index 150a86fc752037777f42078b05ffb597c85fe6b4..954ec82a9c2e825ed34b0beaaef1c6e76e339c04 100644 --- a/htdocs/admin/propal.php +++ b/htdocs/admin/propal.php @@ -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";