Uniformize code

This commit is contained in:
Juanjo Menent 2011-09-01 07:32:26 +00:00
parent 8f5b79c1bf
commit 0a51265512

View File

@ -30,9 +30,9 @@ require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
require_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'); require_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php');
$langs->load("admin"); $langs->load("admin");
$langs->load("companies"); //$langs->load("companies");
$langs->load("bills"); //$langs->load("bills");
$langs->load("other"); //$langs->load("other");
$langs->load("errors"); $langs->load("errors");
if (!$user->admin) if (!$user->admin)
@ -41,26 +41,37 @@ accessforbidden();
$action = GETPOST("action"); $action = GETPOST("action");
$value = GETPOST("value"); $value = GETPOST("value");
$typeconst=array('yesno','texte','chaine'); //$typeconst=array('yesno','texte','chaine');
/* /*
* Actions * Actions
*/ */
if ($_POST["action"] == 'updateMask') if ($action == 'updateMask')
{ {
$maskconstinvoice=$_POST['maskconstinvoice']; $maskconstinvoice=GETPOST("maskconstinvoice");
$maskconstcredit=$_POST['maskconstcredit']; $maskconstcredit=GETPOST("maskconstcredit");
$maskinvoice=$_POST['maskinvoice']; $maskinvoice=GETPOST("maskinvoice");
$maskcredit=$_POST['maskcredit']; $maskcredit=GETPOST("maskcredit");
if ($maskconstinvoice) dolibarr_set_const($db,$maskconstinvoice,$maskinvoice,'chaine',0,'',$conf->entity); if ($maskconstinvoice) $res = dolibarr_set_const($db,$maskconstinvoice,$maskinvoice,'chaine',0,'',$conf->entity);
if ($maskconstcredit) dolibarr_set_const($db,$maskconstcredit,$maskcredit,'chaine',0,'',$conf->entity); if ($maskconstcredit) $res = dolibarr_set_const($db,$maskconstcredit,$maskcredit,'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
if (! $error)
{
$mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
}
else
{
$mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
}
} }
if ($_GET["action"] == 'specimen') if ($action == 'specimen')
{ {
$modele=$_GET["module"]; $modele=GETPOST("module");
$facture = new Facture($db); $facture = new Facture($db);
$facture->initAsSpecimen(); $facture->initAsSpecimen();
@ -82,19 +93,19 @@ if ($_GET["action"] == 'specimen')
} }
else else
{ {
$mesg='<div class="error">'.$obj->error.'</div>'; $mesg='<font class="error">'.$obj->error.'</font>';
dol_syslog($obj->error, LOG_ERR); dol_syslog($obj->error, LOG_ERR);
} }
} }
else else
{ {
$mesg='<div class="error">'.$langs->trans("ErrorModuleNotFound").'</div>'; $mesg='<font class="error">'.$langs->trans("ErrorModuleNotFound").'</font>';
dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
} }
} }
// define constants for models generator that need parameters // define constants for models generator that need parameters
if ($_POST["action"] == 'setModuleOptions') if ($action == 'setModuleOptions')
{ {
$post_size=count($_POST); $post_size=count($_POST);
for($i=0;$i < $post_size;$i++) for($i=0;$i < $post_size;$i++)
@ -103,18 +114,31 @@ if ($_POST["action"] == 'setModuleOptions')
{ {
$param=$_POST["param".$i]; $param=$_POST["param".$i];
$value=$_POST["value".$i]; $value=$_POST["value".$i];
if ($param) dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity);
} }
} }
if (! $res > 0) $error++;
if (! $error)
{
$mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
}
else
{
$mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
}
} }
if ($_GET["action"] == 'set') if ($action == 'set')
{ {
$label = GETPOST("label");
$scandir = GETPOST("scandir");
$type='invoice'; $type='invoice';
$sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
$sql.= " VALUES ('".$db->escape($_GET["value"])."','".$type."',".$conf->entity.", "; $sql.= " VALUES ('".$db->escape($value)."','".$type."',".$conf->entity.", ";
$sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", "; $sql.= ($label?"'".$db->escape($label)."'":'null').", ";
$sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null"); $sql.= (! empty($scandir)?"'".$db->escape($scandir)."'":"null");
$sql.= ")"; $sql.= ")";
if ($db->query($sql)) if ($db->query($sql))
{ {
@ -122,7 +146,7 @@ if ($_GET["action"] == 'set')
} }
} }
if ($_GET["action"] == 'del') if ($action == 'del')
{ {
$type='invoice'; $type='invoice';
$sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
@ -136,29 +160,32 @@ if ($_GET["action"] == 'del')
} }
} }
if ($_GET["action"] == 'setdoc') if ($action == 'setdoc')
{ {
$label = GETPOST("label");
$scandir = GETPOST("scandir");
$db->begin(); $db->begin();
if (dolibarr_set_const($db, "FACTURE_ADDON_PDF",$_GET["value"],'chaine',0,'',$conf->entity)) if (dolibarr_set_const($db, "FACTURE_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
{ {
$conf->global->FACTURE_ADDON_PDF = $_GET["value"]; $conf->global->FACTURE_ADDON_PDF = $value;
} }
// On active le modele // On active le modele
$type='invoice'; $type='invoice';
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
$sql_del.= " WHERE nom = '".$db->escape($_GET["value"])."'"; $sql_del.= " WHERE nom = '".$db->escape($value)."'";
$sql_del.= " AND type = '".$type."'"; $sql_del.= " AND type = '".$type."'";
$sql_del.= " AND entity = ".$conf->entity; $sql_del.= " AND entity = ".$conf->entity;
dol_syslog("facture.php ".$sql_del); dol_syslog("facture.php ".$sql_del);
$result1=$db->query($sql_del); $result1=$db->query($sql_del);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
$sql.= " VALUES ('".$_GET["value"]."', '".$type."', ".$conf->entity.", "; $sql.= " VALUES ('".$value."', '".$type."', ".$conf->entity.", ";
$sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", "; $sql.= ($label?"'".$db->escape($label)."'":'null').", ";
$sql.= (! empty($_GET["scandir"])?"'".$_GET["scandir"]."'":"null"); $sql.= (! empty($scandir)?"'".$scandir."'":"null");
$sql.= ")"; $sql.= ")";
dol_syslog("facture.php ".$sql); dol_syslog("facture.php ".$sql);
$result2=$db->query($sql); $result2=$db->query($sql);
@ -173,36 +200,89 @@ if ($_GET["action"] == 'setdoc')
} }
} }
if ($_GET["action"] == 'setmod') if ($action == 'setmod')
{ {
// TODO Verifier si module numerotation choisi peut etre active // TODO Verifier si module numerotation choisi peut etre active
// par appel methode canBeActivated // par appel methode canBeActivated
dolibarr_set_const($db, "FACTURE_ADDON",$_GET["value"],'chaine',0,'',$conf->entity); dolibarr_set_const($db, "FACTURE_ADDON",$value,'chaine',0,'',$conf->entity);
} }
if ($_POST["action"] == 'setribchq') if ($action == 'setribchq')
{ {
dolibarr_set_const($db, "FACTURE_RIB_NUMBER",$_POST["rib"],'chaine',0,'',$conf->entity); $rib = GETPOST("rib");
dolibarr_set_const($db, "FACTURE_CHQ_NUMBER",$_POST["chq"],'chaine',0,'',$conf->entity); $chq = GETPOST("chq");
$res = dolibarr_set_const($db, "FACTURE_RIB_NUMBER",$rib,'chaine',0,'',$conf->entity);
$res = dolibarr_set_const($db, "FACTURE_CHQ_NUMBER",$chq,'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
if (! $error)
{
$mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
}
else
{
$mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
}
} }
if ($_POST["action"] == 'set_FACTURE_DRAFT_WATERMARK') if ($action == 'set_FACTURE_DRAFT_WATERMARK')
{ {
dolibarr_set_const($db, "FACTURE_DRAFT_WATERMARK",trim($_POST["FACTURE_DRAFT_WATERMARK"]),'chaine',0,'',$conf->entity); $draft = GETPOST("FACTURE_DRAFT_WATERMARK");
$res = dolibarr_set_const($db, "FACTURE_DRAFT_WATERMARK",trim($draft),'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
if (! $error)
{
$mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
}
else
{
$mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
}
} }
if ($_POST["action"] == 'set_FACTURE_FREE_TEXT') if ($action == 'set_FACTURE_FREE_TEXT')
{ {
dolibarr_set_const($db, "FACTURE_FREE_TEXT",$_POST["FACTURE_FREE_TEXT"],'chaine',0,'',$conf->entity); $free = GETPOST("FACTURE_FREE_TEXT");
$res = dolibarr_set_const($db, "FACTURE_FREE_TEXT",$free,'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
if (! $error)
{
$mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
}
else
{
$mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
}
} }
if ($_POST["action"] == 'setforcedate') if ($action == 'setforcedate')
{ {
dolibarr_set_const($db, "FAC_FORCE_DATE_VALIDATION",$_POST["forcedate"],'chaine',0,'',$conf->entity); $forcedate = GETPOST("forcedate");
$res = dolibarr_set_const($db, "FAC_FORCE_DATE_VALIDATION",$forcedate,'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
if (! $error)
{
$mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
}
else
{
$mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
}
} }
if ($_POST["action"] == 'update' || $_POST["action"] == 'add') /*if ($action == 'update' || $action == 'add')
{ {
if (! dolibarr_set_const($db, $_POST["constname"],$_POST["constvalue"],$typeconst[$_POST["consttype"]],0,isset($_POST["constnote"])?$_POST["constnote"]:'',$conf->entity)); if (! dolibarr_set_const($db, $_POST["constname"],$_POST["constvalue"],$typeconst[$_POST["consttype"]],0,isset($_POST["constnote"])?$_POST["constnote"]:'',$conf->entity));
{ {
@ -210,13 +290,14 @@ if ($_POST["action"] == 'update' || $_POST["action"] == 'add')
} }
} }
if ($_GET["action"] == 'delete') if ($action == 'delete')
{ {
if (! dolibarr_del_const($db, $_GET["rowid"],$conf->entity)); $rowid = GETPOST("rowid");
if (! dolibarr_del_const($db, $rowid,$conf->entity));
{ {
dol_print_error($db); dol_print_error($db);
} }
} }*/
/* /*
@ -717,6 +798,7 @@ print "</table>\n";
//dol_fiche_end(); //dol_fiche_end();
dol_htmloutput_mesg($mesg);
$db->close(); $db->close();