From 409a5ae576d9890cc4efae545f5115e9259b3cda Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Sat, 3 Sep 2011 13:30:50 +0000 Subject: [PATCH] Qual: Uniformize code --- htdocs/admin/societe.php | 2 -- htdocs/admin/syslog.php | 75 ++++++++++++++++++++++++++++++++-------- 2 files changed, 60 insertions(+), 17 deletions(-) diff --git a/htdocs/admin/societe.php b/htdocs/admin/societe.php index f761ff03b72..278cb00238b 100644 --- a/htdocs/admin/societe.php +++ b/htdocs/admin/societe.php @@ -74,12 +74,10 @@ if ($action == 'COMPANY_USE_SEARCH_TO_SELECT') if (! $res > 0) $error++; if (! $error) { - $db->commit(); $mesg = "".$langs->trans("SetupSaved").""; } else { - $db->rollback(); $mesg = "".$langs->trans("Error").""; } } diff --git a/htdocs/admin/syslog.php b/htdocs/admin/syslog.php index 8ad476207c3..bedb7321d67 100644 --- a/htdocs/admin/syslog.php +++ b/htdocs/admin/syslog.php @@ -32,51 +32,92 @@ accessforbidden(); $langs->load("admin"); $langs->load("other"); +$action = GETPOST("action"); /* * Actions */ -if (! empty($_POST["action"]) && $_POST["action"] == 'setlevel') +if ($action== 'setlevel') { - dolibarr_set_const($db,"SYSLOG_LEVEL",$_POST["level"],'chaine',0,'',0); - dol_syslog("admin/syslog: level ".$_POST["level"]); + $level = GETPOST("level"); + $res = dolibarr_set_const($db,"SYSLOG_LEVEL",$level,'chaine',0,'',0); + dol_syslog("admin/syslog: level ".$level); + + if (! $res > 0) $error++; + if (! $error) + { + $mesg = "".$langs->trans("SetupSaved").""; + } + else + { + $mesg = "".$langs->trans("Error").""; + } } -if (! empty($_POST["action"]) && $_POST["action"] == 'set') +if ($action == 'set') { - $optionlogoutput=$_POST["optionlogoutput"]; + $optionlogoutput=GETPOST("optionlogoutput"); + $facility=GETPOST("facility"); if ($optionlogoutput == "syslog") { if (defined($_POST["facility"])) { + $db->begin; // Only LOG_USER supported on Windows - if (! empty($_SERVER["WINDIR"])) $_POST["facility"]='LOG_USER'; + if (! empty($_SERVER["WINDIR"])) $facility='LOG_USER'; - dolibarr_del_const($db,"SYSLOG_FILE",0); - dolibarr_set_const($db,"SYSLOG_FACILITY",$_POST["facility"],'chaine',0,'',0); - dol_syslog("admin/syslog: facility ".$_POST["facility"]); + $res = dolibarr_del_const($db,"SYSLOG_FILE",0); + if (! $res > 0) $error++; + $res = dolibarr_set_const($db,"SYSLOG_FACILITY",$facility,'chaine',0,'',0); + if (! $res > 0) $error++; + dol_syslog("admin/syslog: facility ".$facility); + if (! $error) + { + $db->commit(); + $mesg = "".$langs->trans("SetupSaved").""; + } + else + { + $db->rollback(); + $mesg = "".$langs->trans("Error").""; + } } else { - print '
'.$langs->trans("ErrorUnknownSyslogConstant",$_POST["facility"]).'
'; + $mesg = "".$langs->trans("ErrorUnknownSyslogConstant",$facility).""; } } if ($optionlogoutput == "file") { - $filelog=$_POST["filename"]; + $filename=GETPOST("filename"); + $filelog=GETPOST("filename"); $filelog=preg_replace('/DOL_DATA_ROOT/i',DOL_DATA_ROOT,$filelog); $file=fopen($filelog,"a+"); if ($file) { fclose($file); - dolibarr_del_const($db,"SYSLOG_FACILITY",0); - dolibarr_set_const($db,"SYSLOG_FILE",$_POST["filename"],'chaine',0,'',0); - dol_syslog("admin/syslog: file ".$_POST["filename"]); + $db->begin; + $res = dolibarr_del_const($db,"SYSLOG_FACILITY",0); + if (! $res > 0) $error++; + $res = dolibarr_set_const($db,"SYSLOG_FILE",$filename,'chaine',0,'',0); + if (! $res > 0) $error++; + dol_syslog("admin/syslog: file ".$filename); + if (! $res > 0) $error++; + if (! $error) + { + $db->commit(); + $mesg = "".$langs->trans("SetupSaved").""; + } + else + { + $db->rollback(); + $mesg = "".$langs->trans("Error").""; + } } else { - print '
'.$langs->trans("ErrorFailedToOpenFile",$_POST["filename"]).'
'; + $mesg = "".$langs->trans("ErrorFailedToOpenFile",$filename).""; } } } @@ -163,5 +204,9 @@ print ''; print ''; print "\n"; +dol_htmloutput_mesg($mesg); + +$db->close(); + llxFooter(); ?>