Qual: Uniformize code

This commit is contained in:
Juanjo Menent 2011-09-03 13:30:50 +00:00
parent abcafd4db3
commit 409a5ae576
2 changed files with 60 additions and 17 deletions

View File

@ -74,12 +74,10 @@ if ($action == 'COMPANY_USE_SEARCH_TO_SELECT')
if (! $res > 0) $error++; if (! $res > 0) $error++;
if (! $error) if (! $error)
{ {
$db->commit();
$mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>"; $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
} }
else else
{ {
$db->rollback();
$mesg = "<font class=\"error\">".$langs->trans("Error")."</font>"; $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
} }
} }

View File

@ -32,51 +32,92 @@ accessforbidden();
$langs->load("admin"); $langs->load("admin");
$langs->load("other"); $langs->load("other");
$action = GETPOST("action");
/* /*
* Actions * Actions
*/ */
if (! empty($_POST["action"]) && $_POST["action"] == 'setlevel') if ($action== 'setlevel')
{ {
dolibarr_set_const($db,"SYSLOG_LEVEL",$_POST["level"],'chaine',0,'',0); $level = GETPOST("level");
dol_syslog("admin/syslog: level ".$_POST["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 = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
}
else
{
$mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
}
} }
if (! empty($_POST["action"]) && $_POST["action"] == 'set') if ($action == 'set')
{ {
$optionlogoutput=$_POST["optionlogoutput"]; $optionlogoutput=GETPOST("optionlogoutput");
$facility=GETPOST("facility");
if ($optionlogoutput == "syslog") if ($optionlogoutput == "syslog")
{ {
if (defined($_POST["facility"])) if (defined($_POST["facility"]))
{ {
$db->begin;
// Only LOG_USER supported on Windows // 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); $res = dolibarr_del_const($db,"SYSLOG_FILE",0);
dolibarr_set_const($db,"SYSLOG_FACILITY",$_POST["facility"],'chaine',0,'',0); if (! $res > 0) $error++;
dol_syslog("admin/syslog: facility ".$_POST["facility"]); $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 = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
} }
else else
{ {
print '<div class="error">'.$langs->trans("ErrorUnknownSyslogConstant",$_POST["facility"]).'</div>'; $db->rollback();
$mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
}
}
else
{
$mesg = "<font class=\"error\">".$langs->trans("ErrorUnknownSyslogConstant",$facility)."</font>";
} }
} }
if ($optionlogoutput == "file") if ($optionlogoutput == "file")
{ {
$filelog=$_POST["filename"]; $filename=GETPOST("filename");
$filelog=GETPOST("filename");
$filelog=preg_replace('/DOL_DATA_ROOT/i',DOL_DATA_ROOT,$filelog); $filelog=preg_replace('/DOL_DATA_ROOT/i',DOL_DATA_ROOT,$filelog);
$file=fopen($filelog,"a+"); $file=fopen($filelog,"a+");
if ($file) if ($file)
{ {
fclose($file); fclose($file);
dolibarr_del_const($db,"SYSLOG_FACILITY",0); $db->begin;
dolibarr_set_const($db,"SYSLOG_FILE",$_POST["filename"],'chaine',0,'',0); $res = dolibarr_del_const($db,"SYSLOG_FACILITY",0);
dol_syslog("admin/syslog: file ".$_POST["filename"]); 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 = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
} }
else else
{ {
print '<div class="error">'.$langs->trans("ErrorFailedToOpenFile",$_POST["filename"]).'</div>'; $db->rollback();
$mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
}
}
else
{
$mesg = "<font class=\"error\">".$langs->trans("ErrorFailedToOpenFile",$filename)."</font>";
} }
} }
} }
@ -163,5 +204,9 @@ print '</td></tr>';
print '</table>'; print '</table>';
print "</form>\n"; print "</form>\n";
dol_htmloutput_mesg($mesg);
$db->close();
llxFooter(); llxFooter();
?> ?>