Passed
Push — master ( 49af33...3cffbe )
by Alxarafe
21:21
created
dolibarr/htdocs/dav/dav.class.php 1 patch
Braces   +63 added lines, -52 removed lines patch added patch discarded remove patch
@@ -82,14 +82,15 @@  discard block
 block discarded – undo
82 82
 						LEFT OUTER JOIN '.MAIN_DB_PREFIX.'user AS u ON (u.rowid=fk_element)
83 83
 						WHERE ar.element_type=\'user\' AND fk_actioncomm=a.id) AS other_users
84 84
 				FROM '.MAIN_DB_PREFIX.'actioncomm AS a';
85
-		if (! $this->user->rights->societe->client->voir )//FIXME si 'voir' on voit plus de chose ?
85
+		if (! $this->user->rights->societe->client->voir ) {
86
+		    //FIXME si 'voir' on voit plus de chose ?
86 87
 		{
87 88
 			$sql.=' LEFT OUTER JOIN '.MAIN_DB_PREFIX.'societe_commerciaux AS sc ON (a.fk_soc = sc.fk_soc AND sc.fk_user='.$this->user->id.')
88 89
 					LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON (s.rowid = sc.fk_soc)
89 90
 					LEFT JOIN '.MAIN_DB_PREFIX.'socpeople AS sp ON (sp.fk_soc = sc.fk_soc AND sp.rowid = a.fk_contact)
90 91
 					LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_cdav AS ac ON (a.id = ac.fk_object)';
91 92
 		}
92
-		else
93
+		} else
93 94
 		{
94 95
 			$sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON (s.rowid = a.fk_soc)
95 96
 					LEFT JOIN '.MAIN_DB_PREFIX.'socpeople AS sp ON (sp.rowid = a.fk_contact)
@@ -105,8 +106,7 @@  discard block
 block discarded – undo
105 106
 			if($ouri===false)
106 107
 			{
107 108
 				$sql.=' AND a.id = '.intval($oid);
108
-			}
109
-			else
109
+			} else
110 110
 			{
111 111
 				$sql.=' AND (a.id = '.intval($oid).' OR ac.uuidext = \''.$this->db->escape($ouri).'\')';
112 112
 			}
@@ -159,10 +159,11 @@  discard block
 block discarded – undo
159 159
 		$address[]='';
160 160
 		$address[]='';
161 161
 
162
-		if($obj->percent==-1 && trim($obj->datep)!='')
163
-			$type='VEVENT';
164
-		else
165
-			$type='VTODO';
162
+		if($obj->percent==-1 && trim($obj->datep)!='') {
163
+					$type='VEVENT';
164
+		} else {
165
+					$type='VTODO';
166
+		}
166 167
 
167 168
 		$timezone = date_default_timezone_get();
168 169
 
@@ -174,10 +175,11 @@  discard block
 block discarded – undo
174 175
 		$caldata.="CREATED:".gmdate('Ymd\THis', strtotime($obj->datec))."Z\n";
175 176
 		$caldata.="LAST-MODIFIED:".gmdate('Ymd\THis', strtotime($obj->lastupd))."Z\n";
176 177
 		$caldata.="DTSTAMP:".gmdate('Ymd\THis', strtotime($obj->lastupd))."Z\n";
177
-		if($obj->sourceuid=='')
178
-			$caldata.="UID:".$obj->id.'-ev-'.$calid.'-cal-'.CDAV_URI_KEY."\n";
179
-		else
180
-			$caldata.="UID:".$obj->sourceuid."\n";
178
+		if($obj->sourceuid=='') {
179
+					$caldata.="UID:".$obj->id.'-ev-'.$calid.'-cal-'.CDAV_URI_KEY."\n";
180
+		} else {
181
+					$caldata.="UID:".$obj->sourceuid."\n";
182
+		}
181 183
 		$caldata.="SUMMARY:".$obj->label."\n";
182 184
 		$caldata.="LOCATION:".$location."\n";
183 185
 		$caldata.="PRIORITY:".$obj->priority."\n";
@@ -186,40 +188,42 @@  discard block
 block discarded – undo
186 188
 			$caldata.="DTSTART;VALUE=DATE:".date('Ymd', strtotime($obj->datep))."\n";
187 189
 			if($type=='VEVENT')
188 190
 			{
189
-				if(trim($obj->datep2)!='')
190
-					$caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n";
191
-				else
192
-					$caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep)+(25*3600))."\n";
191
+				if(trim($obj->datep2)!='') {
192
+									$caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n";
193
+				} else {
194
+									$caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep)+(25*3600))."\n";
195
+				}
196
+			} elseif(trim($obj->datep2)!='') {
197
+							$caldata.="DUE;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n";
193 198
 			}
194
-			elseif(trim($obj->datep2)!='')
195
-				$caldata.="DUE;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n";
196
-		}
197
-		else
199
+		} else
198 200
 		{
199 201
 			$caldata.="DTSTART;TZID=".$timezone.":".strtr($obj->datep,array(" "=>"T", ":"=>"", "-"=>""))."\n";
200 202
 			if($type=='VEVENT')
201 203
 			{
202
-				if(trim($obj->datep2)!='')
203
-					$caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n";
204
-				else
205
-					$caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep,array(" "=>"T", ":"=>"", "-"=>""))."\n";
204
+				if(trim($obj->datep2)!='') {
205
+									$caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n";
206
+				} else {
207
+									$caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep,array(" "=>"T", ":"=>"", "-"=>""))."\n";
208
+				}
209
+			} elseif(trim($obj->datep2)!='') {
210
+							$caldata.="DUE;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n";
206 211
 			}
207
-			elseif(trim($obj->datep2)!='')
208
-				$caldata.="DUE;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n";
209 212
 		}
210 213
 		$caldata.="CLASS:PUBLIC\n";
211
-		if($obj->transparency==1)
212
-			$caldata.="TRANSP:TRANSPARENT\n";
213
-		else
214
-			$caldata.="TRANSP:OPAQUE\n";
214
+		if($obj->transparency==1) {
215
+					$caldata.="TRANSP:TRANSPARENT\n";
216
+		} else {
217
+					$caldata.="TRANSP:OPAQUE\n";
218
+		}
215 219
 
216
-		if($type=='VEVENT')
217
-			$caldata.="STATUS:CONFIRMED\n";
218
-		elseif($obj->percent==0)
219
-			$caldata.="STATUS:NEEDS-ACTION\n";
220
-		elseif($obj->percent==100)
221
-			$caldata.="STATUS:COMPLETED\n";
222
-		else
220
+		if($type=='VEVENT') {
221
+					$caldata.="STATUS:CONFIRMED\n";
222
+		} elseif($obj->percent==0) {
223
+					$caldata.="STATUS:NEEDS-ACTION\n";
224
+		} elseif($obj->percent==100) {
225
+					$caldata.="STATUS:COMPLETED\n";
226
+		} else
223 227
 		{
224 228
 			$caldata.="STATUS:IN-PROCESS\n";
225 229
 			$caldata.="PERCENT-COMPLETE:".$obj->percent."\n";
@@ -227,16 +231,22 @@  discard block
 block discarded – undo
227 231
 
228 232
 		$caldata.="DESCRIPTION:";
229 233
 		$caldata.=strtr($obj->note, array("\n"=>"\\n", "\r"=>""));
230
-		if(!empty($obj->soc_nom))
231
-			$caldata.="\\n*DOLIBARR-SOC: ".$obj->soc_nom;
232
-		if(!empty($obj->soc_phone))
233
-			$caldata.="\\n*DOLIBARR-SOC-TEL: ".$obj->soc_phone;
234
-		if(!empty($obj->firstname) || !empty($obj->lastname))
235
-			$caldata.="\\n*DOLIBARR-CTC: ".trim($obj->firstname.' '.$obj->lastname);
236
-		if(!empty($obj->phone) || !empty($obj->phone_perso) || !empty($obj->phone_mobile))
237
-			$caldata.="\\n*DOLIBARR-CTC-TEL: ".trim($obj->phone.' '.$obj->phone_perso.' '.$obj->phone_mobile);
238
-		if(strpos($obj->other_users,',')) // several
234
+		if(!empty($obj->soc_nom)) {
235
+					$caldata.="\\n*DOLIBARR-SOC: ".$obj->soc_nom;
236
+		}
237
+		if(!empty($obj->soc_phone)) {
238
+					$caldata.="\\n*DOLIBARR-SOC-TEL: ".$obj->soc_phone;
239
+		}
240
+		if(!empty($obj->firstname) || !empty($obj->lastname)) {
241
+					$caldata.="\\n*DOLIBARR-CTC: ".trim($obj->firstname.' '.$obj->lastname);
242
+		}
243
+		if(!empty($obj->phone) || !empty($obj->phone_perso) || !empty($obj->phone_mobile)) {
244
+					$caldata.="\\n*DOLIBARR-CTC-TEL: ".trim($obj->phone.' '.$obj->phone_perso.' '.$obj->phone_mobile);
245
+		}
246
+		if(strpos($obj->other_users,',')) {
247
+		    // several
239 248
 			$caldata.="\\n*DOLIBARR-USR: ".$obj->other_users;
249
+		}
240 250
 		$caldata.="\n";
241 251
 
242 252
 		$caldata.="END:".$type."\n";
@@ -257,11 +267,13 @@  discard block
 block discarded – undo
257 267
 		$calid = ($calendarId*1);
258 268
 		$calevents = array();
259 269
 
260
-		if(! $this->user->rights->agenda->myactions->read)
261
-			return $calevents;
270
+		if(! $this->user->rights->agenda->myactions->read) {
271
+					return $calevents;
272
+		}
262 273
 
263
-		if($calid!=$this->user->id && (!isset($this->user->rights->agenda->allactions->read) || !$this->user->rights->agenda->allactions->read))
264
-			return $calevents;
274
+		if($calid!=$this->user->id && (!isset($this->user->rights->agenda->allactions->read) || !$this->user->rights->agenda->allactions->read)) {
275
+					return $calevents;
276
+		}
265 277
 
266 278
 		$sql = $this->getSqlCalEvents($calid);
267 279
 
@@ -284,8 +296,7 @@  discard block
 block discarded – undo
284 296
 						'size' => strlen($calendardata),
285 297
 						'component' => strpos($calendardata, 'BEGIN:VEVENT')>0 ? 'vevent' : 'vtodo',
286 298
 					);
287
-				}
288
-				else
299
+				} else
289 300
 				{
290 301
 					$calevents[] = array(
291 302
 						// 'calendardata' => $calendardata,  not necessary because etag+size are present
Please login to merge, or discard this patch.
dolibarr/htdocs/dav/dav.lib.php 1 patch
Braces   +12 added lines, -10 removed lines patch added patch discarded remove patch
@@ -24,20 +24,22 @@
 block discarded – undo
24 24
 // define CDAV_CONTACT_TAG if not
25 25
 if(!defined('CDAV_CONTACT_TAG'))
26 26
 {
27
-	if(isset($conf->global->CDAV_CONTACT_TAG))
28
-		define('CDAV_CONTACT_TAG', $conf->global->CDAV_CONTACT_TAG);
29
-		else
30
-			define('CDAV_CONTACT_TAG', '');
31
-}
27
+	if(isset($conf->global->CDAV_CONTACT_TAG)) {
28
+			define('CDAV_CONTACT_TAG', $conf->global->CDAV_CONTACT_TAG);
29
+	} else {
30
+					define('CDAV_CONTACT_TAG', '');
31
+		}
32
+		}
32 33
 
33 34
 // define CDAV_URI_KEY if not
34 35
 if(!defined('CDAV_URI_KEY'))
35 36
 {
36
-	if(isset($conf->global->CDAV_URI_KEY))
37
-		define('CDAV_URI_KEY', $conf->global->CDAV_URI_KEY);
38
-		else
39
-			define('CDAV_URI_KEY', substr(md5($_SERVER['HTTP_HOST']),0,8));
40
-}
37
+	if(isset($conf->global->CDAV_URI_KEY)) {
38
+			define('CDAV_URI_KEY', $conf->global->CDAV_URI_KEY);
39
+	} else {
40
+					define('CDAV_URI_KEY', substr(md5($_SERVER['HTTP_HOST']),0,8));
41
+		}
42
+		}
41 43
 
42 44
 
43 45
 
Please login to merge, or discard this patch.
dolibarr/htdocs/dav/fileserver.php 1 patch
Braces   +45 added lines, -19 removed lines patch added patch discarded remove patch
@@ -21,12 +21,28 @@  discard block
 block discarded – undo
21 21
  *      \brief      Server DAV
22 22
  */
23 23
 
24
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
25
-if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1'); // If there is no menu to show
26
-if (! defined('NOREQUIREHTML'))  define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
27
-if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
28
-if (! defined('NOLOGIN'))  		 define("NOLOGIN",1);		// This means this output page does not require to be logged.
29
-if (! defined('NOCSRFCHECK'))  	 define("NOCSRFCHECK",1);	// We accept to go on this page from external web site.
24
+if (! defined('NOTOKENRENEWAL')) {
25
+    define('NOTOKENRENEWAL','1');
26
+}
27
+if (! defined('NOREQUIREMENU')) {
28
+    define('NOREQUIREMENU','1');
29
+}
30
+// If there is no menu to show
31
+if (! defined('NOREQUIREHTML')) {
32
+    define('NOREQUIREHTML','1');
33
+}
34
+// If we don't need to load the html.form.class.php
35
+if (! defined('NOREQUIREAJAX')) {
36
+    define('NOREQUIREAJAX','1');
37
+}
38
+if (! defined('NOLOGIN')) {
39
+    define("NOLOGIN",1);
40
+}
41
+// This means this output page does not require to be logged.
42
+if (! defined('NOCSRFCHECK')) {
43
+    define("NOCSRFCHECK",1);
44
+}
45
+// We accept to go on this page from external web site.
30 46
 
31 47
 require "../main.inc.php";
32 48
 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
@@ -47,8 +63,9 @@  discard block
 block discarded – undo
47 63
 $langs->loadLangs(array("main","other"));
48 64
 
49 65
 
50
-if(empty($conf->dav->enabled))
66
+if(empty($conf->dav->enabled)) {
51 67
 	accessforbidden();
68
+}
52 69
 
53 70
 
54 71
 // settings
@@ -63,21 +80,26 @@  discard block
 block discarded – undo
63 80
 	global $conf;
64 81
 	global $dolibarr_main_authentication;
65 82
 
66
-	if (empty($user->login))
67
-		return false;
68
-	if ($user->socid > 0)
69
-		return false;
70
-	if ($user->login != $username)
71
-		return false;
83
+	if (empty($user->login)) {
84
+			return false;
85
+	}
86
+	if ($user->socid > 0) {
87
+			return false;
88
+	}
89
+	if ($user->login != $username) {
90
+			return false;
91
+	}
72 92
 
73 93
 	// Authentication mode
74
-	if (empty($dolibarr_main_authentication))
75
-		$dolibarr_main_authentication='http,dolibarr';
94
+	if (empty($dolibarr_main_authentication)) {
95
+			$dolibarr_main_authentication='http,dolibarr';
96
+	}
76 97
 	$authmode = explode(',',$dolibarr_main_authentication);
77 98
 	$entity = (GETPOST('entity','int') ? GETPOST('entity','int') : (!empty($conf->entity) ? $conf->entity : 1));
78 99
 
79
-	if (checkLoginPassEntity($username,$password,$entity,$authmode) != $username)
80
-		return false;
100
+	if (checkLoginPassEntity($username,$password,$entity,$authmode) != $username) {
101
+			return false;
102
+	}
81 103
 
82 104
 	return true;
83 105
 });
@@ -131,7 +153,9 @@  discard block
 block discarded – undo
131 153
 // If you want to run the SabreDAV server in a custom location (using mod_rewrite for instance)
132 154
 // You can override the baseUri here.
133 155
 $baseUri = DOL_URL_ROOT.'/dav/fileserver.php/';
134
-if (isset($baseUri)) $server->setBaseUri($baseUri);
156
+if (isset($baseUri)) {
157
+    $server->setBaseUri($baseUri);
158
+}
135 159
 
136 160
 // Add authentication function
137 161
 if ((empty($conf->global->DAV_ALLOW_PUBLIC_DIR)
@@ -166,4 +190,6 @@  discard block
 block discarded – undo
166 190
 // And off we go!
167 191
 $server->exec();
168 192
 
169
-if (is_object($db)) $db->close();
193
+if (is_object($db)) {
194
+    $db->close();
195
+}
Please login to merge, or discard this patch.
dolibarr/htdocs/exports/class/export.class.php 1 patch
Braces   +127 added lines, -80 removed lines patch added patch discarded remove patch
@@ -108,8 +108,12 @@  discard block
 block discarded – undo
108 108
 						// Defined if module is enabled
109 109
 						$enabled=true;
110 110
 						$part=strtolower(preg_replace('/^mod/i','',$modulename));
111
-						if ($part == 'propale') $part='propal';
112
-						if (empty($conf->$part->enabled)) $enabled=false;
111
+						if ($part == 'propale') {
112
+						    $part='propal';
113
+						}
114
+						if (empty($conf->$part->enabled)) {
115
+						    $enabled=false;
116
+						}
113 117
 
114 118
 						if ($enabled)
115 119
 						{
@@ -124,10 +128,14 @@  discard block
 block discarded – undo
124 128
 							    foreach($module->export_code as $r => $value)
125 129
 								{
126 130
                                     //print $i.'-'.$filter.'-'.$modulename.'-'.join(',',$module->export_code).'<br>';
127
-								    if ($filter && ($filter != $module->export_code[$r])) continue;
131
+								    if ($filter && ($filter != $module->export_code[$r])) {
132
+								        continue;
133
+								    }
128 134
 
129 135
                                     // Test if condition to show are ok
130
-                                    if (! empty($module->export_enabled[$r]) && ! verifCond($module->export_enabled[$r])) continue;
136
+                                    if (! empty($module->export_enabled[$r]) && ! verifCond($module->export_enabled[$r])) {
137
+                                        continue;
138
+                                    }
131 139
 
132 140
                                     // Test if permissions are ok
133 141
 									$bool=true;
@@ -140,13 +148,16 @@  discard block
 block discarded – undo
140 148
 	    									if (! empty($perm[2]))
141 149
 	    									{
142 150
 	    										$bool=$user->rights->{$perm[0]}->{$perm[1]}->{$perm[2]};
143
-	    									}
144
-	    									else
151
+	    									} else
145 152
 	    									{
146 153
 	    										$bool=$user->rights->{$perm[0]}->{$perm[1]};
147 154
 	    									}
148
-	    									if ($perm[0]=='user' && $user->admin) $bool=true;
149
-	    									if (! $bool) break;
155
+	    									if ($perm[0]=='user' && $user->admin) {
156
+	    									    $bool=true;
157
+	    									}
158
+	    									if (! $bool) {
159
+	    									    break;
160
+	    									}
150 161
 										}
151 162
 									}
152 163
 									//print $bool." $perm[0]"."<br>";
@@ -229,10 +240,19 @@  discard block
 block discarded – undo
229 240
 		//print_r($array_selected);
230 241
 		foreach ($this->array_export_fields[$indice] as $key => $value)
231 242
 		{
232
-			if (! array_key_exists($key, $array_selected)) continue;		// Field not selected
233
-            if (preg_match('/^none\./', $key)) continue;                    // A field that must not appears into SQL
234
-			if ($i > 0) $sql.=', ';
235
-			else $i++;
243
+			if (! array_key_exists($key, $array_selected)) {
244
+			    continue;
245
+			}
246
+			// Field not selected
247
+            if (preg_match('/^none\./', $key)) {
248
+                continue;
249
+            }
250
+            // A field that must not appears into SQL
251
+			if ($i > 0) {
252
+			    $sql.=', ';
253
+			} else {
254
+			    $i++;
255
+			}
236 256
 
237 257
 			if (strpos($key, ' as ')===false) {
238 258
 				$newfield=$key.' as '.str_replace(array('.', '-','(',')'),'_',$key);
@@ -251,8 +271,12 @@  discard block
 block discarded – undo
251 271
 			// Loop on each condition to add
252 272
 			foreach ($array_filterValue as $key => $value)
253 273
 			{
254
-			    if (preg_match('/GROUP_CONCAT/i', $key)) continue;
255
-				if ($value != '') $sqlWhere.=" and ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
274
+			    if (preg_match('/GROUP_CONCAT/i', $key)) {
275
+			        continue;
276
+			    }
277
+				if ($value != '') {
278
+				    $sqlWhere.=" and ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
279
+				}
256 280
 			}
257 281
 			$sql.=$sqlWhere;
258 282
 		}
@@ -266,7 +290,9 @@  discard block
 block discarded – undo
266 290
 		    // Loop on each condition to add
267 291
 		    foreach ($array_filterValue as $key => $value)
268 292
 		    {
269
-		        if (preg_match('/GROUP_CONCAT/i', $key) and $value != '') $sql.=" HAVING ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
293
+		        if (preg_match('/GROUP_CONCAT/i', $key) and $value != '') {
294
+		            $sql.=" HAVING ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
295
+		        }
270 296
 		    }
271 297
 		}
272 298
 
@@ -290,10 +316,11 @@  discard block
 block discarded – undo
290 316
 		// build the input field on depend of the type of file
291 317
 		switch ($InfoFieldList[0]) {
292 318
 			case 'Text':
293
-				if (! (strpos($ValueField, '%') === false))
294
-					$szFilterQuery.=" ".$NameField." LIKE '".$ValueField."'";
295
-				else
296
-					$szFilterQuery.=" ".$NameField." = '".$ValueField."'";
319
+				if (! (strpos($ValueField, '%') === false)) {
320
+									$szFilterQuery.=" ".$NameField." LIKE '".$ValueField."'";
321
+				} else {
322
+									$szFilterQuery.=" ".$NameField." = '".$ValueField."'";
323
+				}
297 324
 				break;
298 325
 			case 'Date':
299 326
 				if (strpos($ValueField, "+") > 0)
@@ -302,13 +329,13 @@  discard block
 block discarded – undo
302 329
 					$ValueArray = explode("+", $ValueField);
303 330
 					$szFilterQuery ="(".$this->conditionDate($NameField,trim($ValueArray[0]),">=");
304 331
 					$szFilterQuery.=" AND ".$this->conditionDate($NameField,trim($ValueArray[1]),"<=").")";
305
-				}
306
-				else
332
+				} else
307 333
 				{
308
-					if (is_numeric(substr($ValueField,0,1)))
309
-						$szFilterQuery=$this->conditionDate($NameField,trim($ValueField),"=");
310
-					else
311
-						$szFilterQuery=$this->conditionDate($NameField,trim(substr($ValueField,1)),substr($ValueField,0,1));
334
+					if (is_numeric(substr($ValueField,0,1))) {
335
+											$szFilterQuery=$this->conditionDate($NameField,trim($ValueField),"=");
336
+					} else {
337
+											$szFilterQuery=$this->conditionDate($NameField,trim(substr($ValueField,1)),substr($ValueField,0,1));
338
+					}
312 339
 				}
313 340
 				break;
314 341
 			case 'Duree':
@@ -321,13 +348,13 @@  discard block
 block discarded – undo
321 348
 					$ValueArray = explode("+", $ValueField);
322 349
 					$szFilterQuery ="(".$NameField.">=".$ValueArray[0];
323 350
 					$szFilterQuery.=" AND ".$NameField."<=".$ValueArray[1].")";
324
-				}
325
-				else
351
+				} else
326 352
 				{
327
-					if (is_numeric(substr($ValueField,0,1)))
328
-						$szFilterQuery=" ".$NameField."=".$ValueField;
329
-					else
330
-						$szFilterQuery=" ".$NameField.substr($ValueField,0,1).substr($ValueField,1);
353
+					if (is_numeric(substr($ValueField,0,1))) {
354
+											$szFilterQuery=" ".$NameField."=".$ValueField;
355
+					} else {
356
+											$szFilterQuery=" ".$NameField.substr($ValueField,0,1).substr($ValueField,1);
357
+					}
331 358
 				}
332 359
 				break;
333 360
 			case 'Boolean':
@@ -335,13 +362,14 @@  discard block
 block discarded – undo
335 362
 				break;
336 363
 			case 'Status':
337 364
 			case 'List':
338
-				if (is_numeric($ValueField))
339
-					$szFilterQuery=" ".$NameField."=".$ValueField;
340
-				else {
341
-                    if (! (strpos($ValueField, '%') === false))
342
-                        $szFilterQuery=" ".$NameField." LIKE '".$ValueField."'";
343
-                    else
344
-                        $szFilterQuery=" ".$NameField." = '".$ValueField."'";
365
+				if (is_numeric($ValueField)) {
366
+									$szFilterQuery=" ".$NameField."=".$ValueField;
367
+				} else {
368
+                    if (! (strpos($ValueField, '%') === false)) {
369
+                                            $szFilterQuery=" ".$NameField." LIKE '".$ValueField."'";
370
+                    } else {
371
+                                            $szFilterQuery=" ".$NameField." = '".$ValueField."'";
372
+                    }
345 373
 				}
346 374
 				break;
347 375
 			default:
@@ -362,9 +390,13 @@  discard block
 block discarded – undo
362 390
 	function conditionDate($Field, $Value, $Sens)
363 391
 	{
364 392
 		// TODO date_format is forbidden, not performant and not portable. Use instead BETWEEN
365
-		if (strlen($Value)==4) $Condition=" date_format(".$Field.",'%Y') ".$Sens." '".$Value."'";
366
-		elseif (strlen($Value)==6) $Condition=" date_format(".$Field.",'%Y%m') ".$Sens." '".$Value."'";
367
-		else  $Condition=" date_format(".$Field.",'%Y%m%d') ".$Sens." ".$Value;
393
+		if (strlen($Value)==4) {
394
+		    $Condition=" date_format(".$Field.",'%Y') ".$Sens." '".$Value."'";
395
+		} elseif (strlen($Value)==6) {
396
+		    $Condition=" date_format(".$Field.",'%Y%m') ".$Sens." '".$Value."'";
397
+		} else {
398
+		    $Condition=" date_format(".$Field.",'%Y%m%d') ".$Sens." ".$Value;
399
+		}
368 400
 		return $Condition;
369 401
 	}
370 402
 
@@ -399,21 +431,30 @@  discard block
 block discarded – undo
399 431
 			    $szFilterField='<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
400 432
 				break;
401 433
 			case 'Status':
402
-				if (! empty($conf->global->MAIN_ACTIVATE_HTML5)) $szFilterField='<input type="number" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
403
-				else $szFilterField='<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
434
+				if (! empty($conf->global->MAIN_ACTIVATE_HTML5)) {
435
+				    $szFilterField='<input type="number" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
436
+				} else {
437
+				    $szFilterField='<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
438
+				}
404 439
 				break;
405 440
 			case 'Boolean':
406 441
 				$szFilterField='<select name="'.$NameField.'" class="flat">';
407 442
 				$szFilterField.='<option ';
408
-				if ($ValueField=='') $szFilterField.=' selected ';
443
+				if ($ValueField=='') {
444
+				    $szFilterField.=' selected ';
445
+				}
409 446
 				$szFilterField.=' value="">&nbsp;</option>';
410 447
 
411 448
 				$szFilterField.='<option ';
412
-				if ($ValueField=='yes' || $ValueField == '1') $szFilterField.=' selected ';
449
+				if ($ValueField=='yes' || $ValueField == '1') {
450
+				    $szFilterField.=' selected ';
451
+				}
413 452
 				$szFilterField.=' value="1">'.yn(1).'</option>';
414 453
 
415 454
 				$szFilterField.='<option ';
416
-				if ($ValueField=='no' || $ValueField=='0') $szFilterField.=' selected ';
455
+				if ($ValueField=='no' || $ValueField=='0') {
456
+				    $szFilterField.=' selected ';
457
+				}
417 458
 				$szFilterField.=' value="0">'.yn(0).'</option>';
418 459
 				$szFilterField.="</select>";
419 460
 				break;
@@ -422,13 +463,18 @@  discard block
 block discarded – undo
422 463
 				// 1 : Nom de la table
423 464
 				// 2 : Nom du champ contenant le libelle
424 465
 				// 3 : Name of field with key (if it is not "rowid"). Used this field as key for combo list.
425
-				if (count($InfoFieldList)==4)
426
-					$keyList=$InfoFieldList[3];
427
-				else
428
-					$keyList='rowid';
466
+				if (count($InfoFieldList)==4) {
467
+									$keyList=$InfoFieldList[3];
468
+				} else {
469
+									$keyList='rowid';
470
+				}
429 471
 				$sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3])?'':', '.$InfoFieldList[3].' as code');
430
-				if ($InfoFieldList[1] == 'c_stcomm') $sql = 'SELECT id as id, '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3])?'':', '.$InfoFieldList[3].' as code');
431
-				if ($InfoFieldList[1] == 'c_country') $sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label, code as code';
472
+				if ($InfoFieldList[1] == 'c_stcomm') {
473
+				    $sql = 'SELECT id as id, '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3])?'':', '.$InfoFieldList[3].' as code');
474
+				}
475
+				if ($InfoFieldList[1] == 'c_country') {
476
+				    $sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label, code as code';
477
+				}
432 478
 				$sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[1];
433 479
 
434 480
 				$resql = $this->db->query($sql);
@@ -466,8 +512,7 @@  discard block
 block discarded – undo
466 512
 							if (!empty($ValueField) && $ValueField == $obj->rowid)
467 513
 							{
468 514
 								$szFilterField.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
469
-							}
470
-							else
515
+							} else
471 516
 							{
472 517
 								$szFilterField.='<option value="'.$obj->rowid.'" >'.$labeltoshow.'</option>';
473 518
 							}
@@ -477,8 +522,9 @@  discard block
 block discarded – undo
477 522
 					$szFilterField.="</select>";
478 523
 
479 524
 					$this->db->free($resql);
525
+				} else {
526
+				    dol_print_error($this->db);
480 527
 				}
481
-				else dol_print_error($this->db);
482 528
 				break;
483 529
 		}
484 530
 
@@ -556,8 +602,9 @@  discard block
 block discarded – undo
556 602
 		require_once $dir.$file;
557 603
 		$objmodel = new $classname($this->db);
558 604
 
559
-		if (! empty($sqlquery)) $sql = $sqlquery;
560
-        else
605
+		if (! empty($sqlquery)) {
606
+		    $sql = $sqlquery;
607
+		} else
561 608
 		{
562 609
 			// Define value for indice from $datatoexport
563 610
 			$foundindice=0;
@@ -586,10 +633,11 @@  discard block
 block discarded – undo
586 633
 		if ($resql)
587 634
 		{
588 635
 			//$this->array_export_label[$indice]
589
-			if ($conf->global->EXPORT_PREFIX_SPEC)
590
-				$filename=$conf->global->EXPORT_PREFIX_SPEC."_".$datatoexport;
591
-			else
592
-				$filename="export_".$datatoexport;
636
+			if ($conf->global->EXPORT_PREFIX_SPEC) {
637
+							$filename=$conf->global->EXPORT_PREFIX_SPEC."_".$datatoexport;
638
+			} else {
639
+							$filename="export_".$datatoexport;
640
+			}
593 641
 			$filename.='.'.$objmodel->getDriverExtension();
594 642
 			$dirname=$conf->export->dir_temp.'/'.$user->id;
595 643
 
@@ -614,20 +662,27 @@  discard block
 block discarded – undo
614 662
 					{
615 663
 						foreach ($this->array_export_special[$indice] as $key => $value)
616 664
 						{
617
-							if (! array_key_exists($key, $array_selected)) continue;		// Field not selected
665
+							if (! array_key_exists($key, $array_selected)) {
666
+							    continue;
667
+							}
668
+							// Field not selected
618 669
 							// Operation NULLIFNEG
619 670
 							if ($this->array_export_special[$indice][$key]=='NULLIFNEG')
620 671
 							{
621 672
 								//$alias=$this->array_export_alias[$indice][$key];
622 673
 								$alias=str_replace(array('.', '-','(',')'),'_',$key);
623
-								if ($obj->$alias < 0) $obj->$alias='';
674
+								if ($obj->$alias < 0) {
675
+								    $obj->$alias='';
676
+								}
624 677
 							}
625 678
 							// Operation ZEROIFNEG
626 679
 							elseif ($this->array_export_special[$indice][$key]=='ZEROIFNEG')
627 680
 							{
628 681
 								//$alias=$this->array_export_alias[$indice][$key];
629 682
 								$alias=str_replace(array('.', '-','(',')'),'_',$key);
630
-								if ($obj->$alias < 0) $obj->$alias='0';
683
+								if ($obj->$alias < 0) {
684
+								    $obj->$alias='0';
685
+								}
631 686
 							}
632 687
 							// Operation INVOICEREMAINTOPAY
633 688
 							elseif ($this->array_export_special[$indice][$key]=='getRemainToPay')
@@ -648,8 +703,7 @@  discard block
 block discarded – undo
648 703
 								    $remaintopay=$tmpobjforcomputecall->getRemainToPay();
649 704
 								}
650 705
 								$obj->$alias=$remaintopay;
651
-							}
652
-							else
706
+							} else
653 707
 							{
654 708
 							    // TODO FIXME Export of compute field does not work. $obj containt $obj->alias_field and formulat will contains $obj->field
655 709
 							    $computestring=$this->array_export_special[$indice][$key];
@@ -672,15 +726,13 @@  discard block
 block discarded – undo
672 726
 				$objmodel->close_file();
673 727
 
674 728
         		return 1;
675
-			}
676
-			else
729
+			} else
677 730
 			{
678 731
 				$this->error=$objmodel->error;
679 732
 				dol_syslog("Export::build_file Error: ".$this->error, LOG_ERR);
680 733
 				return -1;
681 734
 			}
682
-		}
683
-		else
735
+		} else
684 736
 		{
685 737
 			$this->error=$this->db->error()." - sql=".$sql;
686 738
 			return -1;
@@ -723,8 +775,7 @@  discard block
 block discarded – undo
723 775
 		{
724 776
 			$this->db->commit();
725 777
 			return 1;
726
-		}
727
-		else
778
+		} else
728 779
 		{
729 780
 			$this->error=$this->db->lasterror();
730 781
 			$this->errno=$this->db->lasterrno();
@@ -760,14 +811,12 @@  discard block
 block discarded – undo
760 811
 				$this->hexafiltervalue	= $obj->filter;
761 812
 
762 813
 				return 1;
763
-			}
764
-			else
814
+			} else
765 815
 			{
766 816
 				$this->error="ModelNotFound";
767 817
 				return -2;
768 818
 			}
769
-		}
770
-		else
819
+		} else
771 820
 		{
772 821
 			dol_print_error($this->db);
773 822
 			return -3;
@@ -822,8 +871,7 @@  discard block
 block discarded – undo
822 871
 			}
823 872
 			$this->db->rollback();
824 873
 			return -1*$error;
825
-		}
826
-		else
874
+		} else
827 875
 		{
828 876
 			$this->db->commit();
829 877
 			return 1;
@@ -881,8 +929,7 @@  discard block
 block discarded – undo
881 929
 
882 930
 				$i++;
883 931
 			}
884
-		}
885
-		else {
932
+		} else {
886 933
 			dol_print_error($this->db);
887 934
 		}
888 935
 	}
Please login to merge, or discard this patch.
dolibarr/htdocs/exports/export.php 1 patch
Braces   +111 added lines, -69 removed lines patch added patch discarded remove patch
@@ -153,9 +153,11 @@  discard block
 block discarded – undo
153 153
  * Actions
154 154
  */
155 155
 
156
-if ($action=='selectfield')     // Selection of field at step 2
156
+if ($action=='selectfield') {
157
+    // Selection of field at step 2
157 158
 {
158 159
 	$fieldsarray=$objexport->array_export_fields[0];
160
+}
159 161
 	$fieldsentitiesarray=$objexport->array_export_entities[0];
160 162
     $fieldsdependenciesarray=$objexport->array_export_dependencies[0];
161 163
 
@@ -163,13 +165,15 @@  discard block
 block discarded – undo
163 165
     {
164 166
 		foreach($fieldsarray as $key=>$val)
165 167
 		{
166
-			if (! empty($array_selected[$key])) continue;		// If already selected, check next
168
+			if (! empty($array_selected[$key])) {
169
+			    continue;
170
+			}
171
+			// If already selected, check next
167 172
 			$array_selected[$key]=count($array_selected)+1;
168 173
 		    //print_r($array_selected);
169 174
 		    $_SESSION["export_selected_fields"]=$array_selected;
170 175
 		}
171
-    }
172
-    else
176
+    } else
173 177
     {
174 178
         $warnings=array();
175 179
 
@@ -183,15 +187,20 @@  discard block
 block discarded – undo
183 187
         {
184 188
             // We found a dependency on the type of field
185 189
             $tmp=$fieldsdependenciesarray[$fieldsentitiesarray[$field]]; // $fieldsdependenciesarray=array('element'=>'fd.rowid') or array('element'=>array('fd.rowid','ab.rowid'))
186
-            if (is_array($tmp)) $listofdependencies=$tmp;
187
-            else $listofdependencies=array($tmp);
188
-        }
189
-        else if (! empty($field) && ! empty($fieldsdependenciesarray[$field]))
190
+            if (is_array($tmp)) {
191
+                $listofdependencies=$tmp;
192
+            } else {
193
+                $listofdependencies=array($tmp);
194
+            }
195
+        } else if (! empty($field) && ! empty($fieldsdependenciesarray[$field]))
190 196
         {
191 197
             // We found a dependency on a dedicated field
192 198
             $tmp=$fieldsdependenciesarray[$field]; // $fieldsdependenciesarray=array('fd.fieldx'=>'fd.rowid') or array('fd.fieldx'=>array('fd.rowid','ab.rowid'))
193
-            if (is_array($tmp)) $listofdependencies=$tmp;
194
-            else $listofdependencies=array($tmp);
199
+            if (is_array($tmp)) {
200
+                $listofdependencies=$tmp;
201
+            } else {
202
+                $listofdependencies=array($tmp);
203
+            }
195 204
         }
196 205
 
197 206
         if (count($listofdependencies))
@@ -217,8 +226,7 @@  discard block
 block discarded – undo
217 226
     {
218 227
 		$array_selected=array();
219 228
 		$_SESSION["export_selected_fields"]=$array_selected;
220
-    }
221
-    else
229
+    } else
222 230
     {
223 231
 	    unset($array_selected[$_GET["field"]]);
224 232
 	    // Renumber fields of array_selected (from 1 to nb_elements)
@@ -238,8 +246,12 @@  discard block
 block discarded – undo
238 246
 if ($action=='downfield' || $action=='upfield')
239 247
 {
240 248
     $pos=$array_selected[$_GET["field"]];
241
-    if ($action=='downfield') $newpos=$pos+1;
242
-    if ($action=='upfield') $newpos=$pos-1;
249
+    if ($action=='downfield') {
250
+        $newpos=$pos+1;
251
+    }
252
+    if ($action=='upfield') {
253
+        $newpos=$pos-1;
254
+    }
243 255
     // Recherche code avec qui switcher
244 256
     $newcode="";
245 257
     foreach($array_selected as $code=>$value)
@@ -251,9 +263,11 @@  discard block
 block discarded – undo
251 263
         }
252 264
     }
253 265
     //print("Switch pos=$pos (code=".$_GET["field"].") and newpos=$newpos (code=$newcode)");
254
-    if ($newcode)   // Si newcode trouve (protection contre resoumission de page)
266
+    if ($newcode) {
267
+        // Si newcode trouve (protection contre resoumission de page)
255 268
     {
256 269
         $array_selected[$_GET["field"]]=$newpos;
270
+    }
257 271
         $array_selected[$newcode]=$pos;
258 272
         $_SESSION["export_selected_fields"]=$array_selected;
259 273
     }
@@ -282,8 +296,7 @@  discard block
 block discarded – undo
282 296
 	{
283 297
 		setEventMessages($objexport->error, $objexport->errors, 'errors');
284 298
 		$sqlusedforexport=$objexport->sqlusedforexport;
285
-	}
286
-	else
299
+	} else
287 300
 	{
288 301
 		setEventMessages($langs->trans("FileSuccessfullyBuilt"), null, 'mesgs');
289 302
 	    $sqlusedforexport=$objexport->sqlusedforexport;
@@ -296,8 +309,11 @@  discard block
 block discarded – undo
296 309
 	$file = $upload_dir . "/" . GETPOST('file');	// Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
297 310
 
298 311
 	$ret=dol_delete_file($file);
299
-	if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
300
-	else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
312
+	if ($ret) {
313
+	    setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
314
+	} else {
315
+	    setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
316
+	}
301 317
 	header('Location: '.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport);
302 318
 	exit;
303 319
 }
@@ -322,7 +338,9 @@  discard block
 block discarded – undo
322 338
 		$hexa='';
323 339
 		foreach($array_selected as $key=>$val)
324 340
 		{
325
-			if ($hexa) $hexa.=',';
341
+			if ($hexa) {
342
+			    $hexa.=',';
343
+			}
326 344
 			$hexa.=$key;
327 345
 		}
328 346
 
@@ -331,7 +349,9 @@  discard block
 block discarded – undo
331 349
 		{
332 350
 			foreach($array_filtervalue as $key=>$val)
333 351
 			{
334
-				if ($hexafiltervalue) $hexafiltervalue.=',';
352
+				if ($hexafiltervalue) {
353
+				    $hexafiltervalue.=',';
354
+				}
335 355
 				$hexafiltervalue.=$key.'='.$val;
336 356
 			}
337 357
 		}
@@ -345,17 +365,16 @@  discard block
 block discarded – undo
345 365
 		if ($result >= 0)
346 366
 		{
347 367
 			setEventMessages($langs->trans("ExportModelSaved",$objexport->model_name), null, 'mesgs');
348
-		}
349
-		else
368
+		} else
350 369
 		{
351 370
 			$langs->load("errors");
352
-			if ($objexport->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS')
353
-				setEventMessages($langs->trans("ErrorExportDuplicateProfil"), null, 'errors');
354
-			else
355
-				setEventMessages($objexport->error, $objexport->errors, 'errors');
371
+			if ($objexport->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
372
+							setEventMessages($langs->trans("ErrorExportDuplicateProfil"), null, 'errors');
373
+			} else {
374
+							setEventMessages($objexport->error, $objexport->errors, 'errors');
375
+			}
356 376
 		}
357
-	}
358
-	else
377
+	} else
359 378
 	{
360 379
 		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ExportModelName")), null, 'errors');
361 380
 	}
@@ -401,13 +420,18 @@  discard block
 block discarded – undo
401 420
 	if (is_array($objexport->array_export_TypeFields[0]))
402 421
 	{
403 422
 		$_SESSION["export_filtered_fields"]=array();
404
-		foreach($objexport->array_export_TypeFields[0] as $code => $type)	// $code: s.fieldname $value: Text|Boolean|List:ccc
423
+		foreach($objexport->array_export_TypeFields[0] as $code => $type) {
424
+		    // $code: s.fieldname $value: Text|Boolean|List:ccc
405 425
 		{
406 426
 			$newcode=(string) preg_replace('/\./','_',$code);
427
+		}
407 428
 			//print 'xxx'.$code."=".$newcode."=".$type."=".$_POST[$newcode]."\n<br>";
408 429
 			$filterqualified=1;
409
-			if (! isset($_POST[$newcode]) || $_POST[$newcode] == '') $filterqualified=0;
410
-			elseif (preg_match('/^List/',$type) && (is_numeric($_POST[$newcode]) && $_POST[$newcode] <= 0)) $filterqualified=0;
430
+			if (! isset($_POST[$newcode]) || $_POST[$newcode] == '') {
431
+			    $filterqualified=0;
432
+			} elseif (preg_match('/^List/',$type) && (is_numeric($_POST[$newcode]) && $_POST[$newcode] <= 0)) {
433
+			    $filterqualified=0;
434
+			}
411 435
 			if ($filterqualified)
412 436
 			{
413 437
 				//print 'Filter on '.$newcode.' type='.$type.' value='.$_POST[$newcode]."\n";
@@ -477,15 +501,13 @@  discard block
 block discarded – undo
477 501
             if ($objexport->array_export_perms[$key])
478 502
             {
479 503
             	print '<a href="'.DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$objexport->array_export_code[$key].'">'.img_picto($langs->trans("NewExport"),'filenew').'</a>';
480
-            }
481
-            else
504
+            } else
482 505
             {
483 506
             	print $langs->trans("NotEnoughPermissions");
484 507
             }
485 508
            	print '</td></tr>';
486 509
         }
487
-    }
488
-    else
510
+    } else
489 511
     {
490 512
         print '<tr><td '.$bc[false].' colspan="3">'.$langs->trans("NoExportableData").'</td></tr>';
491 513
     }
@@ -553,8 +575,11 @@  discard block
 block discarded – undo
553 575
     print '<input type="hidden" name="datatoexport" value="'.$datatoexport.'">';
554 576
     print '<table><tr><td colspan="2">';
555 577
     print $langs->trans("SelectExportFields").' ';
556
-    if(empty($conf->global->EXPORTS_SHARE_MODELS))$htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1,$user->id);
557
-	else $htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1);
578
+    if(empty($conf->global->EXPORTS_SHARE_MODELS)) {
579
+        $htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1,$user->id);
580
+    } else {
581
+	    $htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1);
582
+	}
558 583
     print ' ';
559 584
     print '<input type="submit" class="button" value="'.$langs->trans("Select").'">';
560 585
     print '</td></tr></table>';
@@ -618,8 +643,7 @@  discard block
 block discarded – undo
618 643
         if (! empty($objexport->array_export_special[0][$code]))
619 644
         {
620 645
             $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
621
-        }
622
-        else
646
+        } else
623 647
         {
624 648
             $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
625 649
         }
@@ -642,8 +666,7 @@  discard block
 block discarded – undo
642 666
             print $form->textwithpicto($text,$htmltext);
643 667
 			//print ' ('.$code.')';
644 668
             print '</td>';
645
-        }
646
-        else
669
+        } else
647 670
         {
648 671
         	// Fields not selected
649 672
             print '<td>';
@@ -672,13 +695,11 @@  discard block
 block discarded – undo
672 695
 		if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
673 696
 		{
674 697
 			print '<a class="butAction" href="export.php?step=3&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
675
-		}
676
-		else
698
+		} else
677 699
 		{
678 700
 			print '<a class="butAction" href="export.php?step=4&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
679 701
 		}
680
-	}
681
-	else
702
+	} else
682 703
 	{
683 704
 		print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("SelectAtLeastOneField")).'">'.$langs->trans("NextStep").'</a>';
684 705
 	}
@@ -688,10 +709,12 @@  discard block
 block discarded – undo
688 709
 
689 710
 if ($step == 3 && $datatoexport)
690 711
 {
691
-    if (count($array_selected) < 1)      // This occurs when going back to page after sessecion expired
712
+    if (count($array_selected) < 1) {
713
+        // This occurs when going back to page after sessecion expired
692 714
     {
693 715
         // Switch to step 2
694 716
         header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
717
+    }
695 718
         exit;
696 719
     }
697 720
 
@@ -809,8 +832,7 @@  discard block
 block discarded – undo
809 832
 			if (! empty($objexport->array_export_special[0][$code]))
810 833
 		{
811 834
 		    $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
812
-		}
813
-		else
835
+		} else
814 836
 		{
815 837
 		    $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
816 838
 		}
@@ -829,15 +851,18 @@  discard block
 block discarded – undo
829 851
 
830 852
 		// Filter value
831 853
 		print '<td>';
832
-		if (! empty($Typefieldsarray[$code]))	// Example: Text, List:c_country:label:rowid, Number, Boolean
854
+		if (! empty($Typefieldsarray[$code])) {
855
+		    // Example: Text, List:c_country:label:rowid, Number, Boolean
833 856
 		{
834 857
 			$szInfoFiltre=$objexport->genDocFilter($Typefieldsarray[$code]);
835
-			if ($szInfoFiltre)	// Is there an info help for this filter ?
858
+		}
859
+			if ($szInfoFiltre) {
860
+			    // Is there an info help for this filter ?
836 861
 			{
837 862
 				$tmp=$objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
838
-				print $form->textwithpicto($tmp, $szInfoFiltre);
839 863
 			}
840
-			else
864
+				print $form->textwithpicto($tmp, $szInfoFiltre);
865
+			} else
841 866
 			{
842 867
 				print $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
843 868
 			}
@@ -862,10 +887,12 @@  discard block
 block discarded – undo
862 887
 
863 888
 if ($step == 4 && $datatoexport)
864 889
 {
865
-    if (count($array_selected) < 1)     // This occurs when going back to page after sessecion expired
890
+    if (count($array_selected) < 1) {
891
+        // This occurs when going back to page after sessecion expired
866 892
     {
867 893
         // Switch to step 2
868 894
         header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
895
+    }
869 896
         exit;
870 897
     }
871 898
 
@@ -945,8 +972,11 @@  discard block
 block discarded – undo
945 972
     			if (isset($objexport->array_export_fields[0][$code]))
946 973
     			{
947 974
     				$list.=($list?', ':'');
948
-    				if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'');
949
-    				else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
975
+    				if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) {
976
+    				    $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'');
977
+    				} else {
978
+    				    $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
979
+    				}
950 980
     			}
951 981
     		}
952 982
     	}
@@ -1001,8 +1031,7 @@  discard block
 block discarded – undo
1001 1031
         if (! empty($objexport->array_export_special[0][$code]))
1002 1032
         {
1003 1033
             $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
1004
-        }
1005
-        else
1034
+        } else
1006 1035
         {
1007 1036
             $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
1008 1037
         }
@@ -1023,8 +1052,12 @@  discard block
 block discarded – undo
1023 1052
         print '<td align="right" width="100">';
1024 1053
         print $value.' ';
1025 1054
         print '</td><td align="center" width="20">';
1026
-        if ($value < count($array_selected)) print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=downfield&field='.$code.'">'.img_down().'</a>';
1027
-        if ($value > 1) print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=upfield&field='.$code.'">'.img_up().'</a>';
1055
+        if ($value < count($array_selected)) {
1056
+            print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=downfield&field='.$code.'">'.img_down().'</a>';
1057
+        }
1058
+        if ($value > 1) {
1059
+            print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=upfield&field='.$code.'">'.img_up().'</a>';
1060
+        }
1028 1061
         print '</td>';
1029 1062
 
1030 1063
         //print '<td>&nbsp;</td>';
@@ -1079,7 +1112,9 @@  discard block
 block discarded – undo
1079 1112
     	$sql = "SELECT rowid, label";
1080 1113
 		$sql.= " FROM ".MAIN_DB_PREFIX."export_model";
1081 1114
 		$sql.= " WHERE type = '".$datatoexport."'";
1082
-		if(empty($conf->global->EXPORTS_SHARE_MODELS))$sql.=" AND fk_user=".$user->id;
1115
+		if(empty($conf->global->EXPORTS_SHARE_MODELS)) {
1116
+		    $sql.=" AND fk_user=".$user->id;
1117
+		}
1083 1118
 		$sql.= " ORDER BY rowid";
1084 1119
 		$resql = $db->query($sql);
1085 1120
 		if ($resql)
@@ -1098,8 +1133,7 @@  discard block
 block discarded – undo
1098 1133
 				print '</tr>';
1099 1134
 				$i++;
1100 1135
 			}
1101
-		}
1102
-		else {
1136
+		} else {
1103 1137
 			dol_print_error($this->db);
1104 1138
 		}
1105 1139
 
@@ -1110,10 +1144,12 @@  discard block
 block discarded – undo
1110 1144
 
1111 1145
 if ($step == 5 && $datatoexport)
1112 1146
 {
1113
-    if (count($array_selected) < 1)      // This occurs when going back to page after sessecion expired
1147
+    if (count($array_selected) < 1) {
1148
+        // This occurs when going back to page after sessecion expired
1114 1149
     {
1115 1150
         // Switch to step 2
1116 1151
         header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
1152
+    }
1117 1153
         exit;
1118 1154
     }
1119 1155
 
@@ -1205,8 +1241,11 @@  discard block
 block discarded – undo
1205 1241
     			if (isset($objexport->array_export_fields[0][$code]))
1206 1242
     			{
1207 1243
     				$list.=($list?', ':'');
1208
-    				if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'');
1209
-    				else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
1244
+    				if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) {
1245
+    				    $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'');
1246
+    				} else {
1247
+    				    $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
1248
+    				}
1210 1249
     			}
1211 1250
     		}
1212 1251
     	}
@@ -1266,7 +1305,9 @@  discard block
 block discarded – undo
1266 1305
 
1267 1306
 	print '<div class="fichecenter"><div class="fichehalfleft">';
1268 1307
 
1269
-    if (! is_dir($conf->export->dir_temp)) dol_mkdir($conf->export->dir_temp);
1308
+    if (! is_dir($conf->export->dir_temp)) {
1309
+        dol_mkdir($conf->export->dir_temp);
1310
+    }
1270 1311
 
1271 1312
     // Affiche liste des documents
1272 1313
     // NB: La fonction show_documents rescanne les modules qd genallowed=1, sinon prend $liste
@@ -1303,6 +1344,7 @@  discard block
 block discarded – undo
1303 1344
 	if (preg_match($regexstring,$newsql,$reg))
1304 1345
 	{
1305 1346
 		return $reg[1];   // The tablename
1347
+	} else {
1348
+	    return '';
1349
+	}
1306 1350
 	}
1307
-	else return '';
1308
-}
Please login to merge, or discard this patch.
dolibarr/htdocs/exports/index.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -94,8 +94,7 @@
 block discarded – undo
94 94
 	if ($user->rights->export->creer)
95 95
 	{
96 96
 		print '<a class="butActionNew" href="'.DOL_URL_ROOT.'/exports/export.php?leftmenu=export">'.$langs->trans("NewExport").'<span class="fa fa-plus-circle valignmiddle"></span></a>';
97
-	}
98
-	else
97
+	} else
99 98
 	{
100 99
 		print '<a class="butActionNewRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("NewExport").'<span class="fa fa-plus-circle valignmiddle"></span></a>';
101 100
 	}
Please login to merge, or discard this patch.
dolibarr/htdocs/margin/productMargins.php 1 patch
Braces   +67 added lines, -46 removed lines patch added patch discarded remove patch
@@ -40,7 +40,9 @@  discard block
 block discarded – undo
40 40
 // Security check
41 41
 $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
42 42
 $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
43
-if (! empty($user->societe_id)) $socid=$user->societe_id;
43
+if (! empty($user->societe_id)) {
44
+    $socid=$user->societe_id;
45
+}
44 46
 $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
45 47
 $result=restrictedArea($user,'margins');
46 48
 
@@ -61,8 +63,7 @@  discard block
 block discarded – undo
61 63
 	{
62 64
 		$sortfield="f.datef";
63 65
 		$sortorder="DESC";
64
-	}
65
-	else
66
+	} else
66 67
 	{
67 68
 	    $sortfield="p.ref";
68 69
 	    $sortorder="ASC";
@@ -71,10 +72,12 @@  discard block
 block discarded – undo
71 72
 
72 73
 $startdate=$enddate='';
73 74
 
74
-if (!empty($_POST['startdatemonth']))
75
+if (!empty($_POST['startdatemonth'])) {
75 76
   $startdate  = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']);
76
-if (!empty($_POST['enddatemonth']))
77
+}
78
+if (!empty($_POST['enddatemonth'])) {
77 79
   $enddate  = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']);
80
+}
78 81
 
79 82
 
80 83
 /*
@@ -109,10 +112,13 @@  discard block
 block discarded – undo
109 112
   print $form->select_produits($id,'id','',20,0,1,2,'',1, array(), 0, 'All');
110 113
   print '</td></tr>';
111 114
 
112
-  if (! $sortorder) $sortorder="DESC";
113
-  if (! $sortfield) $sortfield="f.datef";
114
-}
115
-else {
115
+  if (! $sortorder) {
116
+      $sortorder="DESC";
117
+  }
118
+  if (! $sortfield) {
119
+      $sortfield="f.datef";
120
+  }
121
+  } else {
116 122
 	print '<tr><td class="titlefield">'.$langs->trans('ChooseProduct/Service').'</td>';
117 123
 	print '<td class="maxwidthonsmartphone" colspan="4">';
118 124
 	print $form->select_produits('','id','',20,0,1,2,'',1, array(), 0, 'All');
@@ -175,8 +181,12 @@  discard block
 block discarded – undo
175 181
 print '</form>';
176 182
 
177 183
 $sql = "SELECT p.label, p.rowid, p.fk_product_type, p.ref, p.entity as pentity,";
178
-if ($id > 0) $sql.= " d.fk_product,";
179
-if ($id > 0) $sql.= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,";
184
+if ($id > 0) {
185
+    $sql.= " d.fk_product,";
186
+}
187
+if ($id > 0) {
188
+    $sql.= " f.rowid as facid, f.ref, f.total as total_ht, f.datef, f.paye, f.fk_statut as statut,";
189
+}
180 190
 $sql.= " SUM(d.total_ht) as selling_price,";
181 191
 // Note: qty and buy_price_ht is always positive (if not your database may be corrupted, you can update this)
182 192
 $sql.= " SUM(".$db->ifsql('d.total_ht < 0','d.qty * d.buy_price_ht * -1','d.qty * d.buy_price_ht').") as buying_price,";
@@ -192,20 +202,27 @@  discard block
 block discarded – undo
192 202
 $sql.= ' AND f.entity IN ('.getEntity('invoice').')';
193 203
 $sql.= " AND f.fk_statut > 0";
194 204
 $sql.= " AND d.fk_facture = f.rowid";
195
-if ($id > 0)
205
+if ($id > 0) {
196 206
 	$sql.= " AND d.fk_product =".$id;
207
+}
197 208
 if (! empty($TSelectedCats)) {
198 209
 	$sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')';
199 210
 }
200
-if (!empty($startdate))
211
+if (!empty($startdate)) {
201 212
   $sql.= " AND f.datef >= '".$db->idate($startdate)."'";
202
-if (!empty($enddate))
213
+}
214
+if (!empty($enddate)) {
203 215
   $sql.= " AND f.datef <= '".$db->idate($enddate)."'";
216
+}
204 217
 $sql .= " AND d.buy_price_ht IS NOT NULL";
205
-if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)
218
+if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) {
206 219
 	$sql .= " AND d.buy_price_ht <> 0";
207
-if ($id > 0) $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, p.entity, d.fk_product, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut";
208
-else $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, p.entity";
220
+}
221
+if ($id > 0) {
222
+    $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, p.entity, d.fk_product, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut";
223
+} else {
224
+    $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, p.entity";
225
+}
209 226
 $sql.=$db->order($sortfield,$sortorder);
210 227
 // TODO: calculate total to display then restore pagination
211 228
 //$sql.= $db->plimit($conf->liste_limit +1, $offset);
@@ -220,10 +237,12 @@  discard block
 block discarded – undo
220 237
 	print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "&amp;id=".$id, $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1);
221 238
 
222 239
 	//var_dump($conf->global->MARGIN_TYPE);
223
-	if ($conf->global->MARGIN_TYPE == "1")
224
-	    $labelcostprice='BuyingPrice';
225
-	else   // value is 'costprice' or 'pmp'
240
+	if ($conf->global->MARGIN_TYPE == "1") {
241
+		    $labelcostprice='BuyingPrice';
242
+	} else {
243
+	    // value is 'costprice' or 'pmp'
226 244
 	    $labelcostprice='CostPrice';
245
+	}
227 246
 
228 247
 	$moreforfilter='';
229 248
 
@@ -235,18 +254,19 @@  discard block
 block discarded – undo
235 254
 	if ($id > 0) {
236 255
   		print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&amp;id=".$id,'',$sortfield,$sortorder);
237 256
   		print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&amp;id=".$id,'align="center"',$sortfield,$sortorder);
238
-  	}
239
-  	else
257
+  	} else
240 258
   	{
241 259
   		print_liste_field_titre("ProductService",$_SERVER["PHP_SELF"],"p.ref","","&amp;id=".$id,'',$sortfield,$sortorder);
242 260
   	}
243 261
 	print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
244 262
 	print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
245 263
 	print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
246
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
247
-		print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
248
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
249
-		print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
264
+	if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
265
+			print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
266
+	}
267
+	if (! empty($conf->global->DISPLAY_MARK_RATES)) {
268
+			print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;id=".$id,'align="right"',$sortfield,$sortorder);
269
+	}
250 270
 	print "</tr>\n";
251 271
 
252 272
 	$cumul_achat = 0;
@@ -266,8 +286,7 @@  discard block
 block discarded – undo
266 286
 			{
267 287
 				$marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ;
268 288
 				$markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ;
269
-			}
270
-			else
289
+			} else
271 290
 			{
272 291
 				$marginRate = ($pa != 0)?(100 * $marge / $pa):'' ;
273 292
 				$markRate = ($pv != 0)?(100 * $marge / $pv):'' ;
@@ -282,8 +301,7 @@  discard block
 block discarded – undo
282 301
 				print "</td>\n";
283 302
 				print "<td align=\"center\">";
284 303
 				print dol_print_date($db->jdate($objp->datef),'day')."</td>";
285
-			}
286
-			else {
304
+			} else {
287 305
 				print '<td>';
288 306
 				if ($objp->rowid > 0)
289 307
 				{
@@ -294,8 +312,7 @@  discard block
 block discarded – undo
294 312
     				$product_static->entity=$objp->pentity;
295 313
     				$text=$product_static->getNomUrl(1);
296 314
     				print $text.= ' - '.$objp->label;
297
-				}
298
-				else
315
+				} else
299 316
 				{
300 317
 				    print img_object('', 'product').' '.$langs->trans("NotPredefinedProducts");
301 318
 				}
@@ -305,10 +322,12 @@  discard block
 block discarded – undo
305 322
 			print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n";
306 323
 			print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n";
307 324
 			print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n";
308
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
309
-				print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
310
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
311
-				print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
325
+			if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
326
+							print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
327
+			}
328
+			if (! empty($conf->global->DISPLAY_MARK_RATES)) {
329
+							print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
330
+			}
312 331
 			print "</tr>\n";
313 332
 
314 333
 			$i++;
@@ -325,24 +344,26 @@  discard block
 block discarded – undo
325 344
 	$markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):'';
326 345
 
327 346
 	print '<tr class="liste_total">';
328
-	if ($id > 0)
329
-		print '<td colspan=2>';
330
-	else
331
-		print '<td>';
347
+	if ($id > 0) {
348
+			print '<td colspan=2>';
349
+	} else {
350
+			print '<td>';
351
+	}
332 352
 	print $langs->trans('TotalMargin')."</td>";
333 353
 	print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n";
334 354
 	print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n";
335 355
 	print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n";
336
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
337
-		print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
338
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
339
-		print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
356
+	if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
357
+			print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
358
+	}
359
+	if (! empty($conf->global->DISPLAY_MARK_RATES)) {
360
+			print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
361
+	}
340 362
 	print "</tr>\n";
341 363
 
342 364
 	print "</table>";
343 365
 	print '</div>';
344
-}
345
-else
366
+} else
346 367
 {
347 368
 	dol_print_error($db);
348 369
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/margin/lib/margins.lib.php 1 patch
Braces   +13 added lines, -12 removed lines patch added patch discarded remove patch
@@ -124,13 +124,11 @@  discard block
 block discarded – undo
124 124
 		if ($product->fetch_product_fournisseur_price($fk_pa))
125 125
 		{
126 126
 			$paht_ret = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100);
127
-		}
128
-		else
127
+		} else
129 128
 		{
130 129
 			$paht_ret = $paht;
131 130
 		}
132
-	}
133
-	else
131
+	} else
134 132
 	{
135 133
 		$paht_ret = $paht;
136 134
 	}
@@ -142,17 +140,20 @@  discard block
 block discarded – undo
142 140
 	$pu_ht_remise = price2num($pu_ht_remise, 'MU');
143 141
 
144 142
 	// calcul marge
145
-	if ($pu_ht_remise < 0)
146
-		$marge = -1 * (abs($pu_ht_remise) - $paht_ret);
147
-	else
148
-		$marge = $pu_ht_remise - $paht_ret;
143
+	if ($pu_ht_remise < 0) {
144
+			$marge = -1 * (abs($pu_ht_remise) - $paht_ret);
145
+	} else {
146
+			$marge = $pu_ht_remise - $paht_ret;
147
+	}
149 148
 
150 149
 	// calcul taux marge
151
-	if ($paht_ret != 0)
152
-		$marge_tx_ret = (100 * $marge) / $paht_ret;
150
+	if ($paht_ret != 0) {
151
+			$marge_tx_ret = (100 * $marge) / $paht_ret;
152
+	}
153 153
 	// calcul taux marque
154
-	if ($pu_ht_remise != 0)
155
-		$marque_tx_ret = (100 * $marge) / $pu_ht_remise;
154
+	if ($pu_ht_remise != 0) {
155
+			$marque_tx_ret = (100 * $marge) / $pu_ht_remise;
156
+	}
156 157
 
157 158
 	return array($paht_ret, $marge_tx_ret, $marque_tx_ret);
158 159
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/margin/agentMargins.php 1 patch
Braces   +62 added lines, -42 removed lines patch added patch discarded remove patch
@@ -43,21 +43,26 @@  discard block
 block discarded – undo
43 43
 $offset = $limit * $page;
44 44
 $pageprev = $page - 1;
45 45
 $pagenext = $page + 1;
46
-if (! $sortorder) $sortorder="ASC";
46
+if (! $sortorder) {
47
+    $sortorder="ASC";
48
+}
47 49
 if (! $sortfield)
48 50
 {
49
-	if ($agentid > 0)
50
-		$sortfield="s.nom";
51
-	else
52
-	    $sortfield="u.lastname";
53
-}
51
+	if ($agentid > 0) {
52
+			$sortfield="s.nom";
53
+	} else {
54
+		    $sortfield="u.lastname";
55
+	}
56
+	}
54 57
 
55 58
 $startdate=$enddate='';
56 59
 
57
-if (!empty($_POST['startdatemonth']))
60
+if (!empty($_POST['startdatemonth'])) {
58 61
   $startdate  = dol_mktime(0, 0, 0, $_POST['startdatemonth'],  $_POST['startdateday'],  $_POST['startdateyear']);
59
-if (!empty($_POST['enddatemonth']))
62
+}
63
+if (!empty($_POST['enddatemonth'])) {
60 64
   $enddate  = dol_mktime(23, 59, 59, $_POST['enddatemonth'],  $_POST['enddateday'],  $_POST['enddateyear']);
65
+}
61 66
 
62 67
 // Security check
63 68
 if ($user->rights->margins->read->all) {
@@ -126,7 +131,9 @@  discard block
 block discarded – undo
126 131
 print '</form>';
127 132
 
128 133
 $sql = "SELECT";
129
-if ($agentid > 0) $sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,";
134
+if ($agentid > 0) {
135
+    $sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,";
136
+}
130 137
 $sql.= " u.rowid as agent, u.login, u.lastname, u.firstname,";
131 138
 $sql.= " sum(d.total_ht) as selling_price,";
132 139
 // Note: qty and buy_price_ht is always positive (if not your database may be corrupted, you can update this)
@@ -142,27 +149,36 @@  discard block
 block discarded – undo
142 149
 $sql.= ' AND f.entity IN ('.getEntity('invoice').')';
143 150
 $sql.= " AND sc.fk_soc = f.fk_soc";
144 151
 $sql.= " AND (d.product_type = 0 OR d.product_type = 1)";
145
-if (! empty($conf->global->AGENT_CONTACT_TYPE))
152
+if (! empty($conf->global->AGENT_CONTACT_TYPE)) {
146 153
 	$sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = u.rowid) OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = u.rowid))";
147
-else
154
+} else {
148 155
 	$sql .= " AND sc.fk_user = u.rowid";
156
+}
149 157
 $sql.= " AND f.fk_statut > 0";
150 158
 $sql.= ' AND s.entity IN ('.getEntity('societe').')';
151 159
 $sql.= " AND d.fk_facture = f.rowid";
152 160
 if ($agentid > 0) {
153
-	if (! empty($conf->global->AGENT_CONTACT_TYPE))
154
-  		$sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))";
155
-	else
156
-	    $sql .= " AND sc.fk_user = ".$agentid;
157
-}
158
-if (!empty($startdate))
161
+	if (! empty($conf->global->AGENT_CONTACT_TYPE)) {
162
+	  		$sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))";
163
+	} else {
164
+		    $sql .= " AND sc.fk_user = ".$agentid;
165
+	}
166
+	}
167
+if (!empty($startdate)) {
159 168
   $sql.= " AND f.datef >= '".$db->idate($startdate)."'";
160
-if (!empty($enddate))
169
+}
170
+if (!empty($enddate)) {
161 171
   $sql.= " AND f.datef <= '".$db->idate($enddate)."'";
172
+}
162 173
 $sql .= " AND d.buy_price_ht IS NOT NULL";
163
-if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0";
164
-if ($agentid > 0) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname";
165
-else $sql.= " GROUP BY u.rowid, u.login, u.lastname, u.firstname";
174
+if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) {
175
+    $sql .= " AND d.buy_price_ht <> 0";
176
+}
177
+if ($agentid > 0) {
178
+    $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname";
179
+} else {
180
+    $sql.= " GROUP BY u.rowid, u.login, u.lastname, u.firstname";
181
+}
166 182
 $sql.=$db->order($sortfield,$sortorder);
167 183
 // TODO: calculate total to display then restore pagination
168 184
 //$sql.= $db->plimit($conf->liste_limit +1, $offset);
@@ -181,27 +197,32 @@  discard block
 block discarded – undo
181 197
 	print '<br>';
182 198
 	print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1);
183 199
 
184
-	if ($conf->global->MARGIN_TYPE == "1")
185
-	    $labelcostprice='BuyingPrice';
186
-	else   // value is 'costprice' or 'pmp'
200
+	if ($conf->global->MARGIN_TYPE == "1") {
201
+		    $labelcostprice='BuyingPrice';
202
+	} else {
203
+	    // value is 'costprice' or 'pmp'
187 204
 	    $labelcostprice='CostPrice';
205
+	}
188 206
 
189 207
 	$i = 0;
190 208
 	print "<table class=\"noborder\" width=\"100%\">";
191 209
 
192 210
 	print '<tr class="liste_titre">';
193
-	if ($agentid > 0)
194
-		print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&amp;agentid=".$agentid,'',$sortfield,$sortorder);
195
-	else
196
-		print_liste_field_titre("SalesRepresentative",$_SERVER["PHP_SELF"],"u.lastname","","&amp;agentid=".$agentid,'',$sortfield,$sortorder);
211
+	if ($agentid > 0) {
212
+			print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&amp;agentid=".$agentid,'',$sortfield,$sortorder);
213
+	} else {
214
+			print_liste_field_titre("SalesRepresentative",$_SERVER["PHP_SELF"],"u.lastname","","&amp;agentid=".$agentid,'',$sortfield,$sortorder);
215
+	}
197 216
 
198 217
 	print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
199 218
 	print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
200 219
 	print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
201
-	if (! empty($conf->global->DISPLAY_MARGIN_RATES))
202
-		print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
203
-	if (! empty($conf->global->DISPLAY_MARK_RATES))
204
-		print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
220
+	if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
221
+			print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
222
+	}
223
+	if (! empty($conf->global->DISPLAY_MARK_RATES)) {
224
+			print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&amp;agentid=".$agentid,'align="right"',$sortfield,$sortorder);
225
+	}
205 226
 	print "</tr>\n";
206 227
 
207 228
 	$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
@@ -221,8 +242,7 @@  discard block
 block discarded – undo
221 242
 			{
222 243
 				$marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ;
223 244
 				$markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ;
224
-			}
225
-			else
245
+			} else
226 246
 			{
227 247
 				$marginRate = ($pa != 0)?(100 * $marge / $pa):'' ;
228 248
 				$markRate = ($pv != 0)?(100 * $marge / $pv):'' ;
@@ -234,8 +254,7 @@  discard block
 block discarded – undo
234 254
 				$companystatic->name=$objp->name;
235 255
 				$companystatic->client=$objp->client;
236 256
 				print "<td>".$companystatic->getNomUrl(1,'customer')."</td>\n";
237
-			}
238
-			else {
257
+			} else {
239 258
 				$userstatic->fetch($objp->agent);
240 259
 				print "<td>".$userstatic->getFullName($langs,0,0,0)."</td>\n";
241 260
 			}
@@ -243,18 +262,19 @@  discard block
 block discarded – undo
243 262
 			print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n";
244 263
 			print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n";
245 264
 			print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n";
246
-			if (! empty($conf->global->DISPLAY_MARGIN_RATES))
247
-				print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
248
-			if (! empty($conf->global->DISPLAY_MARK_RATES))
249
-				print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
265
+			if (! empty($conf->global->DISPLAY_MARGIN_RATES)) {
266
+							print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n";
267
+			}
268
+			if (! empty($conf->global->DISPLAY_MARK_RATES)) {
269
+							print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n";
270
+			}
250 271
 			print "</tr>\n";
251 272
 
252 273
 			$i++;
253 274
 		}
254 275
 	}
255 276
 	print "</table>";
256
-}
257
-else
277
+} else
258 278
 {
259 279
 	dol_print_error($db);
260 280
 }
Please login to merge, or discard this patch.