From 7b5469007c92c28db2c9f1ee2069c40010b8f802 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Wed, 31 Aug 2011 08:10:39 +0000 Subject: [PATCH] Uniformize code --- htdocs/admin/commande.php | 11 +++++----- htdocs/admin/contract.php | 44 ++++++++++++++++++++++++++------------- htdocs/admin/propale.php | 4 +--- htdocs/admin/societe.php | 38 ++++++++++++++++++++------------- 4 files changed, 60 insertions(+), 37 deletions(-) diff --git a/htdocs/admin/commande.php b/htdocs/admin/commande.php index 63cdf3b1052..9cef57b8b6b 100644 --- a/htdocs/admin/commande.php +++ b/htdocs/admin/commande.php @@ -33,9 +33,7 @@ require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); require_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'); $langs->load("admin"); -$langs->load("bills"); -$langs->load("other"); -$langs->load("orders"); +$langs->load("errors"); if (!$user->admin) accessforbidden(); @@ -49,8 +47,9 @@ $value = GETPOST("value"); if ($action == 'updateMask') { - $maskconstorder=$_POST['maskconstorder']; - $maskorder=$_POST['maskorder']; + $maskconstorder=GETPOST("maskconstorder"); + $maskorder=GETPOST("maskorder"); + if ($maskconstorder) $res = dolibarr_set_const($db,$maskconstorder,$maskorder,'chaine',0,'',$conf->entity); if (! $res > 0) $error++; @@ -67,7 +66,7 @@ if ($action == 'updateMask') if ($action == 'specimen') { - $modele=$_GET["module"]; + $modele=GETPOST("module"); $commande = new Commande($db); $commande->initAsSpecimen(); diff --git a/htdocs/admin/contract.php b/htdocs/admin/contract.php index 51162ad5479..c8aa6b60388 100644 --- a/htdocs/admin/contract.php +++ b/htdocs/admin/contract.php @@ -26,13 +26,14 @@ require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); require_once(DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'); $langs->load("admin"); -$langs->load("bills"); -$langs->load("other"); -$langs->load("contracts"); +$langs->load("errors"); if (!$user->admin) accessforbidden(); +$action = GETPOST("action"); +$value = GETPOST("value"); + if (empty($conf->global->CONTRACT_ADDON)) { $conf->global->CONTRACT_ADDON='mod_contract_serpis'; @@ -43,24 +44,36 @@ if (empty($conf->global->CONTRACT_ADDON)) * Actions */ -if ($_POST["action"] == 'updateMask') +if ($action == 'updateMask') { $maskconst=$_POST['maskconstcontract']; $maskvalue=$_POST['maskcontract']; - if ($maskconst) dolibarr_set_const($db,$maskconst,$maskvalue,'chaine',0,'',$conf->entity); + if ($maskconst) $res = dolibarr_set_const($db,$maskconst,$maskvalue,'chaine',0,'',$conf->entity); + + if (! $res > 0) $error++; + + if (! $error) + { + $mesg = "".$langs->trans("SetupSaved").""; + } + else + { + $mesg = "".$langs->trans("Error").""; + } } -if ($_GET["action"] == 'setmod') +if ($action == 'setmod') { - dolibarr_set_const($db, "CONTRACT_ADDON",$_GET["value"],'chaine',0,'',$conf->entity); + dolibarr_set_const($db, "CONTRACT_ADDON",$value,'chaine',0,'',$conf->entity); } +/* // constants of magre model -if ($_POST["action"] == 'updateMatrice') dolibarr_set_const($db, "CONTRACT_NUM_MATRICE",$_POST["matrice"],'chaine',0,'',$conf->entity); -if ($_POST["action"] == 'updatePrefix') dolibarr_set_const($db, "CONTRACT_NUM_PREFIX",$_POST["prefix"],'chaine',0,'',$conf->entity); -if ($_POST["action"] == 'setOffset') dolibarr_set_const($db, "CONTRACT_NUM_DELTA",$_POST["offset"],'chaine',0,'',$conf->entity); -if ($_POST["action"] == 'setNumRestart') dolibarr_set_const($db, "CONTRACT_NUM_RESTART_BEGIN_YEAR",$_POST["numrestart"],'chaine',0,'',$conf->entity); - +if ($action == 'updateMatrice') dolibarr_set_const($db, "CONTRACT_NUM_MATRICE",$_POST["matrice"],'chaine',0,'',$conf->entity); +if ($action == 'updatePrefix') dolibarr_set_const($db, "CONTRACT_NUM_PREFIX",$_POST["prefix"],'chaine',0,'',$conf->entity); +if ($action == 'setOffset') dolibarr_set_const($db, "CONTRACT_NUM_DELTA",$_POST["offset"],'chaine',0,'',$conf->entity); +if ($action == 'setNumRestart') dolibarr_set_const($db, "CONTRACT_NUM_RESTART_BEGIN_YEAR",$_POST["numrestart"],'chaine',0,'',$conf->entity); +*/ /* * View @@ -127,12 +140,12 @@ if (is_resource($handle)) print ''; if ($conf->global->CONTRACT_ADDON == "$file") { - print img_picto($langs->trans("Activated"),'on'); + print img_picto($langs->trans("Activated"),'switch_on'); } else { print 'scandir.'&label='.urlencode($module->name).'">'; - print img_picto($langs->trans("Disabled"),'off'); + print img_picto($langs->trans("Disabled"),'switch_off'); print ''; } print ''; @@ -170,6 +183,9 @@ if (is_resource($handle)) } print '
'; + +dol_htmloutput_mesg($mesg); + $db->close(); llxFooter(); diff --git a/htdocs/admin/propale.php b/htdocs/admin/propale.php index b858ea6c96b..f1590913fdb 100644 --- a/htdocs/admin/propale.php +++ b/htdocs/admin/propale.php @@ -33,9 +33,7 @@ require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php"); $langs->load("admin"); -$langs->load("bills"); -$langs->load("propal"); -$langs->load("other"); +$langs->load("errors"); if (!$user->admin) accessforbidden(); diff --git a/htdocs/admin/societe.php b/htdocs/admin/societe.php index cc8f228275d..d8db16d4810 100644 --- a/htdocs/admin/societe.php +++ b/htdocs/admin/societe.php @@ -35,6 +35,7 @@ if (!$user->admin) accessforbidden(); $action=GETPOST("action"); +$value = GETPOST("value"); /* @@ -42,7 +43,7 @@ $action=GETPOST("action"); */ if ($action == 'setcodeclient') { - if (dolibarr_set_const($db, "SOCIETE_CODECLIENT_ADDON",$_GET["value"],'chaine',0,'',$conf->entity) > 0) + if (dolibarr_set_const($db, "SOCIETE_CODECLIENT_ADDON",$value,'chaine',0,'',$conf->entity) > 0) { Header("Location: ".$_SERVER["PHP_SELF"]); exit; @@ -55,7 +56,7 @@ if ($action == 'setcodeclient') if ($action == 'setcodecompta') { - if (dolibarr_set_const($db, "SOCIETE_CODECOMPTA_ADDON",$_GET["value"],'chaine',0,'',$conf->entity) > 0) + if (dolibarr_set_const($db, "SOCIETE_CODECOMPTA_ADDON",$value,'chaine',0,'',$conf->entity) > 0) { Header("Location: ".$_SERVER["PHP_SELF"]); exit; @@ -68,7 +69,8 @@ if ($action == 'setcodecompta') if ($action == 'COMPANY_USE_SEARCH_TO_SELECT') { - $res = dolibarr_set_const($db, "COMPANY_USE_SEARCH_TO_SELECT", $_POST["activate_COMPANY_USE_SEARCH_TO_SELECT"],'chaine',0,'',$conf->entity); + $companysearch = GETPOST("activate_COMPANY_USE_SEARCH_TO_SELECT"); + $res = dolibarr_set_const($db, "COMPANY_USE_SEARCH_TO_SELECT", $companysearch,'chaine',0,'',$conf->entity); if (! $res > 0) $error++; if (! $error) { @@ -114,11 +116,14 @@ if ($action == 'setModuleOptions') // Activate a document generator module if ($action == 'set') { + $label = GETPOST("label"); + $scandir = GETPOST("scandir"); + $type='company'; $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)"; - $sql.= " VALUES ('".$db->escape($_GET["value"])."','".$type."',".$conf->entity.", "; - $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", "; - $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null"); + $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)) { @@ -132,7 +137,7 @@ if ($action== 'del') { $type='company'; $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; - $sql.= " WHERE nom='".$db->escape($_GET["value"])."' AND type='".$type."' AND entity=".$conf->entity; + $sql.= " WHERE nom='".$db->escape($value)."' AND type='".$type."' AND entity=".$conf->entity; if ($db->query($sql)) { @@ -143,11 +148,14 @@ if ($action== 'del') // Define default generator if ($action == 'setdoc') { + $label = GETPOST("label"); + $scandir = GETPOST("scandir"); + $db->begin(); - if (dolibarr_set_const($db, "COMPANY_ADDON_PDF",$_GET["value"],'chaine',0,'',$conf->entity)) + if (dolibarr_set_const($db, "COMPANY_ADDON_PDF",$value,'chaine',0,'',$conf->entity)) { - $conf->global->COMPANY_ADDON_PDF = $_GET["value"]; + $conf->global->COMPANY_ADDON_PDF = $value; } // On active le modele @@ -160,9 +168,9 @@ if ($action == 'setdoc') $result1=$db->query($sql_del); $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)"; - $sql.= " VALUES ('".$db->escape($_GET["value"])."', '".$type."', ".$conf->entity.", "; - $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", "; - $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null"); + $sql.= " VALUES ('".$db->escape($value)."', '".$type."', ".$conf->entity.", "; + $sql.= ($label?"'".$db->escape($label)."'":'null').", "; + $sql.= (! empty($scandir)?"'".$db->escape($scandir)."'":"null"); $sql.= ")"; dol_syslog("societe.php ".$sql); $result2=$db->query($sql); @@ -180,8 +188,10 @@ if ($action == 'setdoc') //Activate ProfId if ($action == 'setprofid') { - $idprof="SOCIETE_IDPROF".$_GET["value"]."_UNIQUE"; - if (dolibarr_set_const($db, $idprof,$_GET["status"],'chaine',0,'',$conf->entity) > 0) + $status = GETPOST("status"); + + $idprof="SOCIETE_IDPROF".$value."_UNIQUE"; + if (dolibarr_set_const($db, $idprof,$status,'chaine',0,'',$conf->entity) > 0) { Header("Location: ".$_SERVER["PHP_SELF"]); exit;