Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

uniformise code

  • Loading branch information...
commit 06761d97539c09feec6f92ed8f6ac6e9ec63a934 1 parent 98f7186
Philippe Grand authored April 10, 2012

Showing 1 changed file with 67 additions and 100 deletions. Show diff stats Hide diff stats

  1. 167  htdocs/admin/expedition.php
167  htdocs/admin/expedition.php
@@ -40,6 +40,9 @@
40 40
 
41 41
 $action=GETPOST('action','alpha');
42 42
 $value=GETPOST('value','alpha');
  43
+$label = GETPOST('label','alpha');
  44
+$scandir = GETPOST('scandir','alpha');
  45
+$type='shipping';
43 46
 
44 47
 if (empty($conf->global->EXPEDITION_ADDON_NUMBER))
45 48
 {
@@ -50,6 +53,59 @@
50 53
 /*
51 54
  * Actions
52 55
  */
  56
+ if ($action == 'updateMask')
  57
+{
  58
+	$maskconst=GETPOST('maskconstexpedition','alpha');
  59
+	$maskvalue=GETPOST('maskexpedition','alpha');
  60
+	if ($maskconst) $res = dolibarr_set_const($db,$maskconst,$maskvalue,'chaine',0,'',$conf->entity);
  61
+
  62
+	if (! $res > 0) $error++;
  63
+
  64
+ 	if (! $error)
  65
+    {
  66
+        $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
  67
+    }
  68
+    else
  69
+    {
  70
+        $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
  71
+    }
  72
+}
  73
+
  74
+if ($action == 'set_SHIPPING_FREE_TEXT')
  75
+{
  76
+	$freetext=GETPOST('SHIPPING_FREE_TEXT','alpha');
  77
+	$res = dolibarr_set_const($db, "SHIPPING_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity);
  78
+
  79
+	if (! $res > 0) $error++;
  80
+
  81
+ 	if (! $error)
  82
+    {
  83
+        $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
  84
+    }
  85
+    else
  86
+    {
  87
+        $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
  88
+    }
  89
+}
  90
+
  91
+if ($action == 'set_SHIPPING_DRAFT_WATERMARK')
  92
+{
  93
+	$draft=GETPOST('SHIPPING_DRAFT_WATERMARK','alpha');
  94
+
  95
+	$res = dolibarr_set_const($db, "SHIPPING_DRAFT_WATERMARK",trim($draft),'chaine',0,'',$conf->entity);
  96
+
  97
+	if (! $res > 0) $error++;
  98
+
  99
+ 	if (! $error)
  100
+    {
  101
+        $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
  102
+    }
  103
+    else
  104
+    {
  105
+        $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
  106
+    }
  107
+}
  108
+
53 109
 if ($action == 'specimen')
54 110
 {
55 111
 	$modele=GETPOST('module','alpha');
@@ -84,8 +140,8 @@
84 140
 		}
85 141
 		else
86 142
 		{
87  
-			$mesg='<font class="error">'.$module->error.'</font>';
88  
-			dol_syslog($module->error, LOG_ERR);
  143
+			$mesg='<font class="error">'.$obj->error.'</font>';
  144
+			dol_syslog($obj->error, LOG_ERR);
89 145
 		}
90 146
 	}
91 147
 	else
@@ -98,30 +154,13 @@
98 154
 // Activate a model
99 155
 if ($action == 'set')
100 156
 {
101  
-	$label = GETPOST('label','alpha');
102  
-	$scandir = GETPOST('scandir','alpha');
103  
-
104  
-	$type='shipping';
105  
-    $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
106  
-    $sql.= " VALUES ('".$db->escape($value)."','".$type."',".$conf->entity.", ";
107  
-    $sql.= ($label?"'".$db->escape($label)."'":'null').", ";
108  
-    $sql.= (! empty($scandir)?"'".$db->escape($scandir)."'":"null");
109  
-    $sql.= ")";
110  
-	if ($db->query($sql))
111  
-	{
112  
-
113  
-	}
  157
+	$ret = addDocumentModel($value, $type, $label, $scandir);
114 158
 }
115 159
 
116 160
 if ($action == 'del')
117 161
 {
118  
-	$type='shipping';
119  
-	$sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
120  
-	$sql.= " WHERE nom = '".$db->escape($value)."'";
121  
-	$sql.= " AND type = '".$type."'";
122  
-	$sql.= " AND entity = ".$conf->entity;
123  
-
124  
-	if ($db->query($sql))
  162
+	$ret = delDocumentModel($value, $type);
  163
+	if ($ret > 0)
125 164
 	{
126 165
         if ($conf->global->EXPEDITION_ADDON_PDF == "$value") dolibarr_del_const($db, 'EXPEDITION_ADDON_PDF',$conf->entity);
127 166
 	}
@@ -130,37 +169,18 @@
130 169
 // Set default model
131 170
 if ($action == 'setdoc')
132 171
 {
133  
-	$label = GETPOST('label','alpha');
134  
-	$scandir = GETPOST('scandir','alpha');
135  
-
136  
-	$db->begin();
137  
-
138 172
 	if (dolibarr_set_const($db, "EXPEDITION_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
139 173
 	{
  174
+		// La constante qui a ete lue en avant du nouveau set
  175
+		// on passe donc par une variable pour avoir un affichage coherent
140 176
 		$conf->global->EXPEDITION_ADDON_PDF = $value;
141 177
 	}
142 178
 
143 179
 	// On active le modele
144  
-	$type='shipping';
145  
-	$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
146  
-	$sql_del.= " WHERE nom = '".$db->escape($value)."'";
147  
-	$sql_del.= " AND type = '".$type."'";
148  
-	$sql_del.= " AND entity = ".$conf->entity;
149  
-	$result1=$db->query($sql_del);
150  
-
151  
-    $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
152  
-    $sql.= " VALUES ('".$db->escape($value)."', '".$type."', ".$conf->entity.", ";
153  
-    $sql.= ($label?"'".$db->escape($label)."'":'null').", ";
154  
-    $sql.= (! empty($scandir)?"'".$db->escape($scandir)."'":"null");
155  
-    $sql.= ")";
156  
-	$result2=$db->query($sql);
157  
-	if ($result1 && $result2)
158  
-	{
159  
-		$db->commit();
160  
-	}
161  
-	else
  180
+	$ret = delDocumentModel($value, $type);
  181
+	if ($ret > 0)
162 182
 	{
163  
-		$db->rollback();
  183
+		$ret = addDocumentModel($value, $type, $label, $scandir);
164 184
 	}
165 185
 }
166 186
 
@@ -240,68 +260,15 @@
240 260
 	// TODO Verifier si module numerotation choisi peut etre active
241 261
 	// par appel methode canBeActivated
242 262
 
243  
-	$module=GETPOST('module','alpha');
244  
-
245  
-    dolibarr_set_const($db, "EXPEDITION_ADDON",$module,'chaine',0,'',$conf->entity);
  263
+    dolibarr_set_const($db, "EXPEDITION_ADDON",$value,'chaine',0,'',$conf->entity);
246 264
 
247 265
 }
248 266
 
249  
-if ($action == 'updateMask')
250  
-{
251  
-	$maskconst=GETPOST('maskconstexpedition','alpha');
252  
-	$maskvalue=GETPOST('maskexpedition','alpha');
253  
-	if ($maskconst) $res = dolibarr_set_const($db,$maskconst,$maskvalue,'chaine',0,'',$conf->entity);
254  
-
255  
-	if (! $res > 0) $error++;
256  
-
257  
- 	if (! $error)
258  
-    {
259  
-        $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
260  
-    }
261  
-    else
262  
-    {
263  
-        $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
264  
-    }
265  
-}
266  
-
267 267
 if ($action == 'setmodel')
268 268
 {
269 269
 	dolibarr_set_const($db, "EXPEDITION_ADDON_NUMBER",$value,'chaine',0,'',$conf->entity);
270 270
 }
271 271
 
272  
-if ($action == 'set_SHIPPING_DRAFT_WATERMARK')
273  
-{
274  
-	$draft=GETPOST('SHIPPING_DRAFT_WATERMARK','alpha');
275  
-	$res = dolibarr_set_const($db, "SHIPPING_DRAFT_WATERMARK",trim($draft),'chaine',0,'',$conf->entity);
276  
-
277  
-	if (! $res > 0) $error++;
278  
-
279  
- 	if (! $error)
280  
-    {
281  
-        $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
282  
-    }
283  
-    else
284  
-    {
285  
-        $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
286  
-    }
287  
-}
288  
-
289  
-if ($action == 'set_SHIPPING_FREE_TEXT')
290  
-{
291  
-	$free=GETPOST('SHIPPING_FREE_TEXT','alpha');
292  
-	$res = dolibarr_set_const($db, "SHIPPING_FREE_TEXT",$free,'chaine',0,'',$conf->entity);
293  
-	if (! $res > 0) $error++;
294  
-
295  
- 	if (! $error)
296  
-    {
297  
-        $mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
298  
-    }
299  
-    else
300  
-    {
301  
-        $mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
302  
-    }
303  
-}
304  
-
305 272
 
306 273
 /*
307 274
  * View

0 notes on commit 06761d9

Please sign in to comment.
Something went wrong with that request. Please try again.