From 294b4865d116c1b83b21ea0f9ff428615682739f Mon Sep 17 00:00:00 2001 From: Grand Philippe Date: Sun, 17 Mar 2013 16:10:43 +0100 Subject: [PATCH] normalize and simplify code --- htdocs/admin/supplier_invoice.php | 96 +++++++++++-------------------- 1 file changed, 34 insertions(+), 62 deletions(-) diff --git a/htdocs/admin/supplier_invoice.php b/htdocs/admin/supplier_invoice.php index 49e31d1b86c..f28e3d1a244 100644 --- a/htdocs/admin/supplier_invoice.php +++ b/htdocs/admin/supplier_invoice.php @@ -53,10 +53,10 @@ $specimenthirdparty->initAsSpecimen(); if ($action == 'updateMask') { - $maskconstorder=GETPOST('maskconstorder','alpha'); - $maskorder=GETPOST('maskorder','alpha'); + $maskconstinvoice=GETPOST('maskconstinvoice','alpha'); + $maskvalue=GETPOST('maskvalue','alpha'); - if ($maskconstorder) $res = dolibarr_set_const($db,$maskconstorder,$maskorder,'chaine',0,'',$conf->entity); + if ($maskconstinvoice) $res = dolibarr_set_const($db,$maskconstinvoice,$maskvalue,'chaine',0,'',$conf->entity); if (! $res > 0) $error++; @@ -116,71 +116,37 @@ if ($action == 'specimen') // For invoices } } -if ($action == 'set') +// Activate a model +else if ($action == 'set') { - $label = GETPOST('label','alpha'); - $scandir = GETPOST('scandir','alpha'); - - $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.= ")"; - $res=$db->query($sql); - if ($res) - { - - } - // else dol_print_error($db); + $ret = addDocumentModel($value, $type, $label, $scandir); } -if ($action == 'del') +else if ($action == 'del') { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; - $sql.= " WHERE nom = '".$value."'"; - $sql.= " AND type = '".$type."'"; - $sql.= " AND entity = ".$conf->entity; - $db->query($sql); - if ($res) - { - - } - // else dol_print_error($db); + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF == "$value") dolibarr_del_const($db, 'INVOICE_SUPPLIER_ADDON_PDF',$conf->entity); + } } -if ($action == 'setdoc') +// Set default model +else if ($action == 'setdoc') { - $label = GETPOST('label','alpha'); - $scandir = GETPOST('scandir','alpha'); + if (dolibarr_set_const($db, "INVOICE_SUPPLIER_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->INVOICE_SUPPLIER_ADDON_PDF = $value; + } - $db->begin(); - - if ($type == 'order_supplier' && dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_PDF",$value,'chaine',0,'',$conf->entity)) - { - $conf->global->INVOICE_SUPPLIER_ADDON_PDF = $value; - } - - // On active le modele - $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; - $result1=$db->query($sql_del); - - $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.= ")"; - $result2=$db->query($sql); - if ($result1 && $result2) - { - $db->commit(); - } - else - { - $db->rollback(); - } + // On active le modele + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + $ret = addDocumentModel($value, $type, $label, $scandir); + } } if ($action == 'setmod') @@ -294,7 +260,7 @@ foreach ($dirmodels as $reldir) print $module->info(); print ''; - // Show example of numbering module + // Show example of numbering model print ''; $tmp=$module->getExample(); if (preg_match('/^Error/',$tmp)) { @@ -447,7 +413,7 @@ foreach ($dirmodels as $reldir) print ""; } - // Defaut + // Default print ''; if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF == "$name") { @@ -484,6 +450,12 @@ foreach ($dirmodels as $reldir) } print '
'; +print '
'; + +/* + * Other options + * + */ print_titre($langs->trans("OtherOptions")); print '';