Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

uniformise code

  • Loading branch information...
commit 06761d97539c09feec6f92ed8f6ac6e9ec63a934 1 parent 98f7186
@grandoc grandoc authored
Showing with 67 additions and 100 deletions.
  1. +67 −100 htdocs/admin/expedition.php
View
167 htdocs/admin/expedition.php
@@ -40,6 +40,9 @@
$action=GETPOST('action','alpha');
$value=GETPOST('value','alpha');
+$label = GETPOST('label','alpha');
+$scandir = GETPOST('scandir','alpha');
+$type='shipping';
if (empty($conf->global->EXPEDITION_ADDON_NUMBER))
{
@@ -50,6 +53,59 @@
/*
* Actions
*/
+ if ($action == 'updateMask')
+{
+ $maskconst=GETPOST('maskconstexpedition','alpha');
+ $maskvalue=GETPOST('maskexpedition','alpha');
+ if ($maskconst) $res = dolibarr_set_const($db,$maskconst,$maskvalue,'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 ($action == 'set_SHIPPING_FREE_TEXT')
+{
+ $freetext=GETPOST('SHIPPING_FREE_TEXT','alpha');
+ $res = dolibarr_set_const($db, "SHIPPING_FREE_TEXT",$freetext,'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 ($action == 'set_SHIPPING_DRAFT_WATERMARK')
+{
+ $draft=GETPOST('SHIPPING_DRAFT_WATERMARK','alpha');
+
+ $res = dolibarr_set_const($db, "SHIPPING_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 ($action == 'specimen')
{
$modele=GETPOST('module','alpha');
@@ -84,8 +140,8 @@
}
else
{
- $mesg='<font class="error">'.$module->error.'</font>';
- dol_syslog($module->error, LOG_ERR);
+ $mesg='<font class="error">'.$obj->error.'</font>';
+ dol_syslog($obj->error, LOG_ERR);
}
}
else
@@ -98,30 +154,13 @@
// Activate a model
if ($action == 'set')
{
- $label = GETPOST('label','alpha');
- $scandir = GETPOST('scandir','alpha');
-
- $type='shipping';
- $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.= ")";
- if ($db->query($sql))
- {
-
- }
+ $ret = addDocumentModel($value, $type, $label, $scandir);
}
if ($action == 'del')
{
- $type='shipping';
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
- $sql.= " WHERE nom = '".$db->escape($value)."'";
- $sql.= " AND type = '".$type."'";
- $sql.= " AND entity = ".$conf->entity;
-
- if ($db->query($sql))
+ $ret = delDocumentModel($value, $type);
+ if ($ret > 0)
{
if ($conf->global->EXPEDITION_ADDON_PDF == "$value") dolibarr_del_const($db, 'EXPEDITION_ADDON_PDF',$conf->entity);
}
@@ -130,37 +169,18 @@
// Set default model
if ($action == 'setdoc')
{
- $label = GETPOST('label','alpha');
- $scandir = GETPOST('scandir','alpha');
-
- $db->begin();
-
if (dolibarr_set_const($db, "EXPEDITION_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->EXPEDITION_ADDON_PDF = $value;
}
// On active le modele
- $type='shipping';
- $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
+ $ret = delDocumentModel($value, $type);
+ if ($ret > 0)
{
- $db->rollback();
+ $ret = addDocumentModel($value, $type, $label, $scandir);
}
}
@@ -240,68 +260,15 @@
// TODO Verifier si module numerotation choisi peut etre active
// par appel methode canBeActivated
- $module=GETPOST('module','alpha');
-
- dolibarr_set_const($db, "EXPEDITION_ADDON",$module,'chaine',0,'',$conf->entity);
+ dolibarr_set_const($db, "EXPEDITION_ADDON",$value,'chaine',0,'',$conf->entity);
}
-if ($action == 'updateMask')
-{
- $maskconst=GETPOST('maskconstexpedition','alpha');
- $maskvalue=GETPOST('maskexpedition','alpha');
- if ($maskconst) $res = dolibarr_set_const($db,$maskconst,$maskvalue,'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 ($action == 'setmodel')
{
dolibarr_set_const($db, "EXPEDITION_ADDON_NUMBER",$value,'chaine',0,'',$conf->entity);
}
-if ($action == 'set_SHIPPING_DRAFT_WATERMARK')
-{
- $draft=GETPOST('SHIPPING_DRAFT_WATERMARK','alpha');
- $res = dolibarr_set_const($db, "SHIPPING_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 ($action == 'set_SHIPPING_FREE_TEXT')
-{
- $free=GETPOST('SHIPPING_FREE_TEXT','alpha');
- $res = dolibarr_set_const($db, "SHIPPING_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>";
- }
-}
-
/*
* View
Please sign in to comment.
Something went wrong with that request. Please try again.