Passed
Push — master ( 49af33...3cffbe )
by Alxarafe
21:21
created
dolibarr/htdocs/core/class/html.formbarcode.class.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -176,8 +176,7 @@
 block discarded – undo
176 176
             }
177 177
             $out .= "</select>";
178 178
             $out .= ajax_combobox("select_".$htmlname);
179
-        }
180
-        else {
179
+        } else {
181 180
             dol_print_error($this->db);
182 181
         }
183 182
         return $out;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/CSMSFile.class.php 1 patch
Braces   +38 added lines, -24 removed lines patch added patch discarded remove patch
@@ -65,8 +65,12 @@  discard block
 block discarded – undo
65 65
 
66 66
 		// On definit fin de ligne
67 67
 		$this->eol="\n";
68
-		if (preg_match('/^win/i',PHP_OS)) $this->eol="\r\n";
69
-		if (preg_match('/^mac/i',PHP_OS)) $this->eol="\r";
68
+		if (preg_match('/^win/i',PHP_OS)) {
69
+		    $this->eol="\r\n";
70
+		}
71
+		if (preg_match('/^mac/i',PHP_OS)) {
72
+		    $this->eol="\r";
73
+		}
70 74
 
71 75
 		// If ending method not defined
72 76
 		if (empty($conf->global->MAIN_SMS_SENDMODE))
@@ -108,15 +112,19 @@  discard block
 block discarded – undo
108 112
 
109 113
         $this->message=stripslashes($this->message);
110 114
 
111
-        if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms();
115
+        if (! empty($conf->global->MAIN_SMS_DEBUG)) {
116
+            $this->dump_sms();
117
+        }
112 118
 
113 119
 		if (empty($conf->global->MAIN_DISABLE_ALL_SMS))
114 120
 		{
115 121
 
116 122
 		    // Action according to choosed sending method
117
-		    if ($conf->global->MAIN_SMS_SENDMODE == 'ovh')    // Backward compatibility    @deprecated
123
+		    if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') {
124
+		        // Backward compatibility    @deprecated
118 125
 			{
119 126
 				dol_include_once('/ovh/class/ovhsms.class.php');
127
+		    }
120 128
 				$sms=new OvhSms($this->db);
121 129
 				$sms->expe=$this->addr_from;
122 130
 				$sms->dest=$this->addr_to;
@@ -131,17 +139,19 @@  discard block
 block discarded – undo
131 139
 				{
132 140
 					$this->error=$sms->error;
133 141
 					dol_syslog("CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR);
134
-				}
135
-				else
142
+				} else
136 143
 				{
137 144
 					dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG);
138 145
 					//var_dump($res);        // 1973128
139
-					if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res);
146
+					if (! empty($conf->global->MAIN_SMS_DEBUG)) {
147
+					    $this->dump_sms_result($res);
148
+					}
140 149
 				}
141
-			}
142
-		    else if (! empty($conf->global->MAIN_SMS_SENDMODE))    // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
150
+			} else if (! empty($conf->global->MAIN_SMS_SENDMODE)) {
151
+		        // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
143 152
 		    {
144 153
 		        $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE);
154
+		    }
145 155
 		        $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]);
146 156
 		        dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
147 157
 		        try
@@ -162,28 +172,26 @@  discard block
 block discarded – undo
162 172
     				if ($res <= 0)
163 173
     				{
164 174
     					dol_syslog("CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR);
165
-    				}
166
-    				else
175
+    				} else
167 176
     				{
168 177
     					dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG);
169 178
     					//var_dump($res);        // 1973128
170
-    					if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res);
179
+    					if (! empty($conf->global->MAIN_SMS_DEBUG)) {
180
+    					    $this->dump_sms_result($res);
181
+    					}
171 182
     				}
172
-		        }
173
-		        catch(Exception $e)
183
+		        } catch(Exception $e)
174 184
 		        {
175 185
 		            dol_print_error('','Error to get list of senders: '.$e->getMessage());
176 186
 		        }
177
-		    }
178
-			else
187
+		    } else
179 188
 			{
180 189
 				// Send sms method not correctly defined
181 190
 				// --------------------------------------
182 191
 
183 192
 				return 'Bad value for MAIN_SMS_SENDMODE constant';
184 193
 			}
185
-		}
186
-		else
194
+		} else
187 195
 		{
188 196
 			$this->error='No sms sent. Feature is disabled by option MAIN_DISABLE_ALL_SMS';
189 197
 			dol_syslog("CSMSFile::sendfile: ".$this->error, LOG_WARNING);
@@ -207,9 +215,11 @@  discard block
 block discarded – undo
207 215
         // phpcs:enable
208 216
 		global $conf,$dolibarr_main_data_root;
209 217
 
210
-		if (@is_writeable($dolibarr_main_data_root))	// Avoid fatal error on fopen with open_basedir
218
+		if (@is_writeable($dolibarr_main_data_root)) {
219
+		    // Avoid fatal error on fopen with open_basedir
211 220
 		{
212 221
 			$outputfile=$dolibarr_main_data_root."/dolibarr_sms.log";
222
+		}
213 223
 			$fp = fopen($outputfile,"w");
214 224
 
215 225
 			fputs($fp, "From: ".$this->addr_from."\n");
@@ -221,8 +231,9 @@  discard block
 block discarded – undo
221 231
 			fputs($fp, "Message:\n".$this->message);
222 232
 
223 233
 			fclose($fp);
224
-			if (! empty($conf->global->MAIN_UMASK))
225
-			@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
234
+			if (! empty($conf->global->MAIN_UMASK)) {
235
+						@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
236
+			}
226 237
 		}
227 238
 	}
228 239
 
@@ -239,16 +250,19 @@  discard block
 block discarded – undo
239 250
         // phpcs:enable
240 251
         global $conf,$dolibarr_main_data_root;
241 252
 
242
-        if (@is_writeable($dolibarr_main_data_root))    // Avoid fatal error on fopen with open_basedir
253
+        if (@is_writeable($dolibarr_main_data_root)) {
254
+            // Avoid fatal error on fopen with open_basedir
243 255
         {
244 256
         	$outputfile=$dolibarr_main_data_root."/dolibarr_sms.log";
257
+        }
245 258
             $fp = fopen($outputfile,"a+");
246 259
 
247 260
             fputs($fp, "\nResult id=".$result);
248 261
 
249 262
             fclose($fp);
250
-            if (! empty($conf->global->MAIN_UMASK))
251
-            @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
263
+            if (! empty($conf->global->MAIN_UMASK)) {
264
+                        @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
265
+            }
252 266
         }
253 267
     }
254 268
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/fileupload.class.php 1 patch
Braces   +17 added lines, -29 removed lines patch added patch discarded remove patch
@@ -62,46 +62,36 @@  discard block
 block discarded – undo
62 62
 		if ($element == 'propal') {
63 63
 			$pathname = 'comm/propal';
64 64
 			$dir_output=$conf->$element->dir_output;
65
-		}
66
-		elseif ($element == 'facture') {
65
+		} elseif ($element == 'facture') {
67 66
 			$pathname = 'compta/facture';
68 67
 			$dir_output=$conf->$element->dir_output;
69
-		}
70
-		elseif ($element == 'project') {
68
+		} elseif ($element == 'project') {
71 69
 			$element = $pathname = 'projet';
72 70
 			$dir_output=$conf->$element->dir_output;
73
-		}
74
-		elseif ($element == 'project_task') {
71
+		} elseif ($element == 'project_task') {
75 72
 			$pathname = 'projet'; $filename='task';
76 73
 			$dir_output=$conf->projet->dir_output;
77 74
 			$parentForeignKey = 'fk_project';
78 75
 			$parentClass = 'Project';
79 76
 			$parentElement = 'projet';
80 77
 			$parentObject = 'project';
81
-		}
82
-		elseif ($element == 'fichinter') {
78
+		} elseif ($element == 'fichinter') {
83 79
 			$element='ficheinter';
84 80
 			$dir_output=$conf->$element->dir_output;
85
-		}
86
-		elseif ($element == 'order_supplier') {
81
+		} elseif ($element == 'order_supplier') {
87 82
 			$pathname = 'fourn'; $filename='fournisseur.commande';
88 83
 			$dir_output=$conf->fournisseur->commande->dir_output;
89
-		}
90
-		elseif ($element == 'invoice_supplier') {
84
+		} elseif ($element == 'invoice_supplier') {
91 85
 			$pathname = 'fourn'; $filename='fournisseur.facture';
92 86
 			$dir_output=$conf->fournisseur->facture->dir_output;
93
-		}
94
-		elseif ($element == 'product') {
87
+		} elseif ($element == 'product') {
95 88
 			$dir_output = $conf->product->multidir_output[$conf->entity];
96
-		}
97
-		elseif ($element == 'productbatch') {
89
+		} elseif ($element == 'productbatch') {
98 90
 			$dir_output = $conf->productbatch->multidir_output[$conf->entity];
99
-		}
100
-		elseif ($element == 'action') {
91
+		} elseif ($element == 'action') {
101 92
 			$pathname = 'comm/action'; $filename='actioncomm';
102 93
 			$dir_output=$conf->agenda->dir_output;
103
-		}
104
-		elseif ($element == 'chargesociales') {
94
+		} elseif ($element == 'chargesociales') {
105 95
 			$pathname = 'compta/sociales'; $filename='chargesociales';
106 96
 			$dir_output=$conf->tax->dir_output;
107 97
 		} else {
@@ -282,10 +272,11 @@  discard block
 block discarded – undo
282 272
 
283 273
 			$res=vignette($file_path,$maxwidthmini,$maxheightmini,'_mini');  // We don't use ->addThumbs here because there is no object and we don't need all thumbs, only the "mini".
284 274
 
285
-			if (preg_match('/error/i',$res)) return false;
275
+			if (preg_match('/error/i',$res)) {
276
+			    return false;
277
+			}
286 278
 			return true;
287
-		}
288
-		else
279
+		} else
289 280
 		{
290 281
 			return false;
291 282
 		}
@@ -437,8 +428,7 @@  discard block
 block discarded – undo
437 428
 				} else {
438 429
 					dol_move_uploaded_file($uploaded_file, $file_path, 1, 0, 0, 0, 'userfile');
439 430
 				}
440
-			}
441
-			else
431
+			} else
442 432
 			{
443 433
 				// Non-multipart uploads (PUT method support)
444 434
 				file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0);
@@ -455,8 +445,7 @@  discard block
 block discarded – undo
455 445
 						$file->{$version.'_url'} = $options['upload_url'].rawurlencode($tmp[0].'_mini.'.$tmp[1]);
456 446
 					}
457 447
 				}
458
-			}
459
-			else if ($this->options['discard_aborted_uploads'])
448
+			} else if ($this->options['discard_aborted_uploads'])
460 449
 			{
461 450
 				unlink($file_path);
462 451
 				$file->error = 'abort';
@@ -479,8 +468,7 @@  discard block
 block discarded – undo
479 468
 		if ($file_name)
480 469
 		{
481 470
 			$info = $this->getFileObject($file_name);
482
-		}
483
-		else
471
+		} else
484 472
 		{
485 473
 			$info = $this->getFileObjects();
486 474
 		}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formprojet.class.php 1 patch
Braces   +123 added lines, -69 removed lines patch added patch discarded remove patch
@@ -97,8 +97,7 @@  discard block
 block discarded – undo
97 97
 			));
98 98
 
99 99
 			$out.='<input type="text" class="minwidth200'.($morecss?' '.$morecss:'').'" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' />';
100
-		}
101
-		else
100
+		} else
102 101
 		{
103 102
 			$out.=$this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, $discard_closed, $forcefocus, $disabled, 0, $filterkey, 1, $forceaddid, $htmlid, $morecss);
104 103
 		}
@@ -106,7 +105,9 @@  discard block
 block discarded – undo
106 105
 		{
107 106
 			if (class_exists('Form'))
108 107
 			{
109
-				if (empty($form)) $form=new Form($this->db);
108
+				if (empty($form)) {
109
+				    $form=new Form($this->db);
110
+				}
110 111
 				$out.=$form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
111 112
 			}
112 113
 		}
@@ -115,8 +116,9 @@  discard block
 block discarded – undo
115 116
 		{
116 117
 		    print $out;
117 118
 		    return '';
119
+		} else {
120
+		    return $out;
118 121
 		}
119
-		else return $out;
120 122
 	}
121 123
 
122 124
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -147,13 +149,17 @@  discard block
 block discarded – undo
147 149
 
148 150
 		require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
149 151
 
150
-		if (empty($htmlid)) $htmlid = $htmlname;
152
+		if (empty($htmlid)) {
153
+		    $htmlid = $htmlname;
154
+		}
151 155
 
152 156
 		$out='';
153 157
 		$outarray=array();
154 158
 
155 159
 		$hideunselectables = false;
156
-		if (! empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) $hideunselectables = true;
160
+		if (! empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) {
161
+		    $hideunselectables = true;
162
+		}
157 163
 
158 164
 		$projectsListId = false;
159 165
 		if (empty($user->rights->projet->all->lire))
@@ -166,17 +172,26 @@  discard block
 block discarded – undo
166 172
 		$sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name, s.name_alias';
167 173
 		$sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p LEFT JOIN '.MAIN_DB_PREFIX .'societe as s ON s.rowid = p.fk_soc';
168 174
 		$sql.= " WHERE p.entity IN (".getEntity('project').")";
169
-		if ($projectsListId !== false) $sql.= " AND p.rowid IN (".$projectsListId.")";
170
-		if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
175
+		if ($projectsListId !== false) {
176
+		    $sql.= " AND p.rowid IN (".$projectsListId.")";
177
+		}
178
+		if ($socid == 0) {
179
+		    $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
180
+		}
171 181
 		if ($socid > 0)
172 182
 		{
173
-		    if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY))  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
174
-		    else if ($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all')    // PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
183
+		    if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY)) {
184
+		        $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
185
+		    } else if ($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all') {
186
+		        // PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
175 187
 		    {
176 188
 		        $sql.= " AND (p.fk_soc IN (".$socid.", ".$conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") OR p.fk_soc IS NULL)";
177 189
 		    }
190
+		    }
191
+		}
192
+		if (!empty($filterkey)) {
193
+		    $sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
178 194
 		}
179
-		if (!empty($filterkey)) $sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
180 195
 		$sql.= " ORDER BY p.ref ASC";
181 196
 
182 197
 		$resql=$this->db->query($sql);
@@ -208,12 +223,13 @@  discard block
 block discarded – undo
208 223
 					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
209 224
 					{
210 225
 						// Do nothing
211
-					}
212
-					else
226
+					} else
213 227
 					{
214
-						if ($discard_closed == 1 && $obj->fk_statut == 2 && $obj->rowid != $selected) // We discard closed except if selected
228
+						if ($discard_closed == 1 && $obj->fk_statut == 2 && $obj->rowid != $selected) {
229
+						    // We discard closed except if selected
215 230
 						{
216 231
 							$i++;
232
+						}
217 233
 							continue;
218 234
 						}
219 235
 
@@ -224,7 +240,9 @@  discard block
 block discarded – undo
224 240
 						if ($obj->name)
225 241
 						{
226 242
 						    $labeltoshow.=' - '.$obj->name;
227
-						    if ($obj->name_alias) $labeltoshow.=' ('.$obj->name_alias.')';
243
+						    if ($obj->name_alias) {
244
+						        $labeltoshow.=' ('.$obj->name_alias.')';
245
+						    }
228 246
 						}
229 247
 
230 248
 						$disabled=0;
@@ -232,13 +250,13 @@  discard block
 block discarded – undo
232 250
 						{
233 251
 							$disabled=1;
234 252
 							$labeltoshow.=' - '.$langs->trans("Draft");
235
-						}
236
-						else if ($obj->fk_statut == 2)
253
+						} else if ($obj->fk_statut == 2)
237 254
 						{
238
-							if ($discard_closed == 2) $disabled=1;
255
+							if ($discard_closed == 2) {
256
+							    $disabled=1;
257
+							}
239 258
 							$labeltoshow.=' - '.$langs->trans("Closed");
240
-						}
241
-						else if ( empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) &&  $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
259
+						} else if ( empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) &&  $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
242 260
 						{
243 261
 							$disabled=1;
244 262
 							$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
@@ -249,17 +267,17 @@  discard block
 block discarded – undo
249 267
 							$out.= '<option value="'.$obj->rowid.'" selected';
250 268
 							//if ($disabled) $out.=' disabled';						// with select2, field can't be preselected if disabled
251 269
 							$out.= '>'.$labeltoshow.'</option>';
252
-						}
253
-						else
270
+						} else
254 271
 						{
255 272
 							if ($hideunselectables && $disabled && ($selected != $obj->rowid))
256 273
 							{
257 274
 								$resultat='';
258
-							}
259
-							else
275
+							} else
260 276
 							{
261 277
 								$resultat='<option value="'.$obj->rowid.'"';
262
-								if ($disabled) $resultat.=' disabled';
278
+								if ($disabled) {
279
+								    $resultat.=' disabled';
280
+								}
263 281
 								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
264 282
 								//else $labeltoshow.=' ('.$langs->trans("Private").')';
265 283
 								$resultat.='>';
@@ -284,18 +302,20 @@  discard block
 block discarded – undo
284 302
 			$this->db->free($resql);
285 303
 
286 304
 			if (!$mode) {
287
-				if (empty($option_only)) $out.= '</select>';
305
+				if (empty($option_only)) {
306
+				    $out.= '</select>';
307
+				}
288 308
 				if (empty($nooutput))
289 309
 				{
290 310
 				    print $out;
291 311
 				    return '';
312
+				} else {
313
+				    return $out;
292 314
 				}
293
-				else return $out;
294 315
 			} else {
295 316
 				return $outarray;
296 317
 			}
297
-		}
298
-		else
318
+		} else
299 319
 		{
300 320
 			dol_print_error($this->db);
301 321
 			return -1;
@@ -334,7 +354,9 @@  discard block
 block discarded – undo
334 354
 		$out='';
335 355
 
336 356
 		$hideunselectables = false;
337
-		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
357
+		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) {
358
+		    $hideunselectables = true;
359
+		}
338 360
 
339 361
 		if (empty($projectsListId))
340 362
 		{
@@ -353,9 +375,15 @@  discard block
 block discarded – undo
353 375
 		$sql.= ' '.MAIN_DB_PREFIX.'projet_task as t';
354 376
 		$sql.= " WHERE p.entity IN (".getEntity('project').")";
355 377
 		$sql.= " AND t.fk_projet = p.rowid";
356
-		if ($projectsListId) $sql.= " AND p.rowid IN (".$projectsListId.")";
357
-		if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
358
-		if ($socid > 0)  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
378
+		if ($projectsListId) {
379
+		    $sql.= " AND p.rowid IN (".$projectsListId.")";
380
+		}
381
+		if ($socid == 0) {
382
+		    $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
383
+		}
384
+		if ($socid > 0) {
385
+		    $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
386
+		}
359 387
 		$sql.= " ORDER BY p.ref, t.ref ASC";
360 388
 
361 389
 		$resql=$this->db->query($sql);
@@ -375,8 +403,11 @@  discard block
 block discarded – undo
375 403
 			}
376 404
 			if (! empty($show_empty)) {
377 405
 				$out.= '<option value="0" class="optiongrey">';
378
-				if (! is_numeric($show_empty)) $out.=$show_empty;
379
-				else $out.='&nbsp;';
406
+				if (! is_numeric($show_empty)) {
407
+				    $out.=$show_empty;
408
+				} else {
409
+				    $out.='&nbsp;';
410
+				}
380 411
 				$out.= '</option>';
381 412
 			}
382 413
 			$num = $this->db->num_rows($resql);
@@ -390,8 +421,7 @@  discard block
 block discarded – undo
390 421
 					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && empty($usertofilter->rights->societe->lire))
391 422
 					{
392 423
 						// Do nothing
393
-					}
394
-					else
424
+					} else
395 425
 					{
396 426
 						if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED)
397 427
 						{
@@ -408,20 +438,22 @@  discard block
 block discarded – undo
408 438
 							//else $labeltoshow.=' ('.$langs->trans("Private").')';
409 439
 							$labeltoshow.=' '.dol_trunc($obj->title,$maxlength);
410 440
 
411
-							if ($obj->name) $labeltoshow.=' ('.$obj->name.')';
441
+							if ($obj->name) {
442
+							    $labeltoshow.=' ('.$obj->name.')';
443
+							}
412 444
 
413 445
 							$disabled=0;
414 446
 							if ($obj->fk_statut == Project::STATUS_DRAFT)
415 447
 							{
416 448
 								$disabled=1;
417 449
 								$labeltoshow.=' - '.$langs->trans("Draft");
418
-							}
419
-							else if ($obj->fk_statut == Project::STATUS_CLOSED)
450
+							} else if ($obj->fk_statut == Project::STATUS_CLOSED)
420 451
 							{
421
-								if ($discard_closed == 2) $disabled=1;
452
+								if ($discard_closed == 2) {
453
+								    $disabled=1;
454
+								}
422 455
 								$labeltoshow.=' - '.$langs->trans("Closed");
423
-							}
424
-							else if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
456
+							} else if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
425 457
 							{
426 458
 								$disabled=1;
427 459
 								$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
@@ -437,17 +469,17 @@  discard block
 block discarded – undo
437 469
 							$out.= '<option value="'.$obj->rowid.'" selected';
438 470
 							//if ($disabled) $out.=' disabled';						// with select2, field can't be preselected if disabled
439 471
 							$out.= '>'.$labeltoshow.'</option>';
440
-						}
441
-						else
472
+						} else
442 473
 						{
443 474
 							if ($hideunselectables && $disabled && ($selected != $obj->rowid))
444 475
 							{
445 476
 								$resultat='';
446
-							}
447
-							else
477
+							} else
448 478
 							{
449 479
 								$resultat='<option value="'.$obj->rowid.'"';
450
-								if ($disabled) $resultat.=' disabled';
480
+								if ($disabled) {
481
+								    $resultat.=' disabled';
482
+								}
451 483
 								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
452 484
 								//else $labeltoshow.=' ('.$langs->trans("Private").')';
453 485
 								$resultat.='>';
@@ -468,8 +500,7 @@  discard block
 block discarded – undo
468 500
 
469 501
 			$this->db->free($resql);
470 502
 			return $num;
471
-		}
472
-		else
503
+		} else
473 504
 		{
474 505
 			dol_print_error($this->db);
475 506
 			return -1;
@@ -493,10 +524,15 @@  discard block
 block discarded – undo
493 524
         // phpcs:enable
494 525
 		global $conf, $langs;
495 526
 
496
-		if ($table_element == 'projet_task') return '';		// Special cas of element we never link to a project (already always done)
527
+		if ($table_element == 'projet_task') {
528
+		    return '';
529
+		}
530
+		// Special cas of element we never link to a project (already always done)
497 531
 
498 532
 		$linkedtothirdparty=false;
499
-		if (! in_array($table_element, array('don','expensereport_det','expensereport','loan','stock_mouvement','payment_salary','payment_various','chargesociales'))) $linkedtothirdparty=true;
533
+		if (! in_array($table_element, array('don','expensereport_det','expensereport','loan','stock_mouvement','payment_salary','payment_various','chargesociales'))) {
534
+		    $linkedtothirdparty=true;
535
+		}
500 536
 
501 537
 		$sqlfilter='';
502 538
 
@@ -550,18 +586,31 @@  discard block
 block discarded – undo
550 586
 				$sql = "SELECT t.rowid, t.ref";
551 587
 				break;
552 588
 		}
553
-		if ($linkedtothirdparty) $sql.=", s.nom as name";
589
+		if ($linkedtothirdparty) {
590
+		    $sql.=", s.nom as name";
591
+		}
554 592
 		$sql.= " FROM ".MAIN_DB_PREFIX.$table_element." as t";
555
-		if ($linkedtothirdparty) $sql.=", ".MAIN_DB_PREFIX."societe as s";
593
+		if ($linkedtothirdparty) {
594
+		    $sql.=", ".MAIN_DB_PREFIX."societe as s";
595
+		}
556 596
 		$sql.= " WHERE ".$projectkey." is null";
557 597
 		if (! empty($socid) && $linkedtothirdparty)
558 598
 		{
559
-		    if (is_numeric($socid)) $sql.= " AND t.fk_soc=".$socid;
560
-		    else $sql.= " AND t.fk_soc IN (".$socid.")";
599
+		    if (is_numeric($socid)) {
600
+		        $sql.= " AND t.fk_soc=".$socid;
601
+		    } else {
602
+		        $sql.= " AND t.fk_soc IN (".$socid.")";
603
+		    }
604
+		}
605
+		if (! in_array($table_element, array('expensereport_det','stock_mouvement'))) {
606
+		    $sql.= ' AND t.entity IN ('.getEntity('project').')';
607
+		}
608
+		if ($linkedtothirdparty) {
609
+		    $sql.=" AND s.rowid = t.fk_soc";
610
+		}
611
+		if ($sqlfilter) {
612
+		    $sql.= " AND ".$sqlfilter;
561 613
 		}
562
-		if (! in_array($table_element, array('expensereport_det','stock_mouvement'))) $sql.= ' AND t.entity IN ('.getEntity('project').')';
563
-		if ($linkedtothirdparty) $sql.=" AND s.rowid = t.fk_soc";
564
-		if ($sqlfilter) $sql.= " AND ".$sqlfilter;
565 614
 		$sql.= " ORDER BY ref DESC";
566 615
 
567 616
 		dol_syslog(get_class($this).'::select_element', LOG_DEBUG);
@@ -578,8 +627,12 @@  discard block
 block discarded – undo
578 627
 				{
579 628
 					$obj = $this->db->fetch_object($resql);
580 629
 					$ref=$obj->ref?$obj->ref:$obj->rowid;
581
-					if (! empty($obj->ref_supplier)) $ref.=' ('.$obj->ref_supplier.')';
582
-					if (! empty($obj->name)) $ref.=' - '.$obj->name;
630
+					if (! empty($obj->ref_supplier)) {
631
+					    $ref.=' ('.$obj->ref_supplier.')';
632
+					}
633
+					if (! empty($obj->name)) {
634
+					    $ref.=' - '.$obj->name;
635
+					}
583 636
 					$sellist .='<option value="'.$obj->rowid.'">'.$ref.'</option>';
584 637
 					$i++;
585 638
 				}
@@ -594,8 +647,7 @@  discard block
 block discarded – undo
594 647
 			$this->db->free($resql);
595 648
 
596 649
 			return $sellist;
597
-		}
598
-		else
650
+		} else
599 651
 		{
600 652
 			dol_print_error($this->db);
601 653
 			$this->error=$this->db->lasterror();
@@ -650,16 +702,19 @@  discard block
 block discarded – undo
650 702
 					$obj = $this->db->fetch_object($resql);
651 703
 
652 704
 					$sellist .='<option value="'.$obj->rowid.'" defaultpercent="'.$obj->percent.'" elemcode="'.$obj->code.'"';
653
-					if ($obj->rowid == $preselected) $sellist .= ' selected="selected"';
705
+					if ($obj->rowid == $preselected) {
706
+					    $sellist .= ' selected="selected"';
707
+					}
654 708
 					$sellist .= '>';
655 709
 					if ($useshortlabel)
656 710
 					{
657 711
 						$finallabel = ($langs->transnoentitiesnoconv("OppStatus".$obj->code) != "OppStatus".$obj->code ? $langs->transnoentitiesnoconv("OppStatus".$obj->code) : $obj->label);
658
-					}
659
-					else
712
+					} else
660 713
 					{
661 714
 						$finallabel = ($langs->transnoentitiesnoconv("OppStatus".$obj->code) != "OppStatus".$obj->code ? $langs->transnoentitiesnoconv("OppStatus".$obj->code) : $obj->label);
662
-						if ($showpercent) $finallabel.= ' ('.$obj->percent.'%)';
715
+						if ($showpercent) {
716
+						    $finallabel.= ' ('.$obj->percent.'%)';
717
+						}
663 718
 					}
664 719
 					$sellist .= $finallabel;
665 720
 					$sellist .='</option>';
@@ -676,8 +731,7 @@  discard block
 block discarded – undo
676 731
 			$this->db->free($resql);
677 732
 
678 733
 			return $sellist;
679
-		}
680
-		else
734
+		} else
681 735
 		{
682 736
 			$this->error=$this->db->lasterror();
683 737
 			$this->errors[]=$this->db->lasterror();
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formother.class.php 1 patch
Braces   +145 added lines, -83 removed lines patch added patch discarded remove patch
@@ -73,7 +73,9 @@  discard block
 block discarded – undo
73 73
         $sql = "SELECT rowid, label";
74 74
         $sql.= " FROM ".MAIN_DB_PREFIX."export_model";
75 75
         $sql.= " WHERE type = '".$type."'";
76
-		if (!empty($fk_user)) $sql.=" AND fk_user=".$fk_user;
76
+		if (!empty($fk_user)) {
77
+		    $sql.=" AND fk_user=".$fk_user;
78
+		}
77 79
         $sql.= " ORDER BY rowid";
78 80
         $result = $this->db->query($sql);
79 81
         if ($result)
@@ -92,8 +94,7 @@  discard block
 block discarded – undo
92 94
                 if ($selected == $obj->rowid)
93 95
                 {
94 96
                     print '<option value="'.$obj->rowid.'" selected>';
95
-                }
96
-                else
97
+                } else
97 98
                 {
98 99
                     print '<option value="'.$obj->rowid.'">';
99 100
                 }
@@ -102,8 +103,7 @@  discard block
 block discarded – undo
102 103
                 $i++;
103 104
             }
104 105
             print "</select>";
105
-        }
106
-        else {
106
+        } else {
107 107
             dol_print_error($this->db);
108 108
         }
109 109
     }
@@ -143,8 +143,7 @@  discard block
 block discarded – undo
143 143
                 if ($selected == $obj->rowid)
144 144
                 {
145 145
                     print '<option value="'.$obj->rowid.'" selected>';
146
-                }
147
-                else
146
+                } else
148 147
                 {
149 148
                     print '<option value="'.$obj->rowid.'">';
150 149
                 }
@@ -153,8 +152,7 @@  discard block
 block discarded – undo
153 152
                 $i++;
154 153
             }
155 154
             print "</select>";
156
-        }
157
-        else {
155
+        } else {
158 156
             dol_print_error($this->db);
159 157
         }
160 158
     }
@@ -195,8 +193,7 @@  discard block
 block discarded – undo
195 193
                     if ($selected && $selected == $obj->rowid)
196 194
                     {
197 195
                         print '<option value="'.$obj->rowid.'" selected>';
198
-                    }
199
-                    else
196
+                    } else
200 197
                     {
201 198
                         print '<option value="'.$obj->rowid.'">';
202 199
                         //print '<option onmouseover="showtip(\''.$obj->label.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
@@ -209,8 +206,7 @@  discard block
 block discarded – undo
209 206
             }
210 207
             print '</select>';
211 208
             return 0;
212
-        }
213
-        else
209
+        } else
214 210
         {
215 211
             dol_print_error($this->db);
216 212
             return 1;
@@ -255,8 +251,7 @@  discard block
 block discarded – undo
255 251
     				if (($selected && $selected == $obj->taux) || $num == 1)
256 252
     				{
257 253
     					$out.='<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>';
258
-    				}
259
-    				else
254
+    				} else
260 255
     				{
261 256
     					$out.='<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>';
262 257
     					//print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
@@ -268,8 +263,7 @@  discard block
 block discarded – undo
268 263
     		}
269 264
     		$out.='</select>';
270 265
     		return $out;
271
-    	}
272
-    	else
266
+    	} else
273 267
     	{
274 268
     		dol_print_error($this->db);
275 269
     		return '';
@@ -294,15 +288,16 @@  discard block
 block discarded – undo
294 288
     {
295 289
         // phpcs:enable
296 290
         $return = '<select class="flat" name="'.$htmlname.'" '.($disabled?'disabled':'').'>';
297
-        if ($showempty) $return.='<option value="-1"'.(($selected == -1 || $selected == '')?' selected':'').'>&nbsp;</option>';
291
+        if ($showempty) {
292
+            $return.='<option value="-1"'.(($selected == -1 || $selected == '')?' selected':'').'>&nbsp;</option>';
293
+        }
298 294
 
299 295
         for ($i = $start ; $i <= $end ; $i += $increment)
300 296
         {
301 297
             if ($selected != '' && (int) $selected == $i)
302 298
             {
303 299
                 $return.= '<option value="'.$i.'" selected>';
304
-            }
305
-            else
300
+            } else
306 301
             {
307 302
                 $return.= '<option value="'.$i.'">';
308 303
             }
@@ -355,14 +350,19 @@  discard block
 block discarded – undo
355 350
 
356 351
         // Print a select with each of them
357 352
         $moreforfilter.='<select class="flat minwidth100'.($morecss?' '.$morecss:'').'" id="select_categ_'.$htmlname.'" name="'.$htmlname.'">';
358
-        if ($showempty) $moreforfilter.='<option value="0">&nbsp;</option>';	// Should use -1 to say nothing
353
+        if ($showempty) {
354
+            $moreforfilter.='<option value="0">&nbsp;</option>';
355
+        }
356
+        // Should use -1 to say nothing
359 357
 
360 358
         if (is_array($tab_categs))
361 359
         {
362 360
             foreach ($tab_categs as $categ)
363 361
             {
364 362
                 $moreforfilter.='<option value="'.$categ['id'].'"';
365
-                if ($categ['id'] == $selected) $moreforfilter.=' selected';
363
+                if ($categ['id'] == $selected) {
364
+                    $moreforfilter.=' selected';
365
+                }
366 366
                 $moreforfilter.='>'.dol_trunc($categ['fulllabel'],50,'middle').'</option>';
367 367
             }
368 368
         }
@@ -409,14 +409,20 @@  discard block
 block discarded – undo
409 409
         }
410 410
         // Select each sales and print them in a select input
411 411
         $out.='<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
412
-        if ($showempty) $out.='<option value="0">&nbsp;</option>';
412
+        if ($showempty) {
413
+            $out.='<option value="0">&nbsp;</option>';
414
+        }
413 415
 
414 416
         // Get list of users allowed to be viewed
415 417
         $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut, u.login";
416 418
         $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u";
417 419
         $sql_usr.= " WHERE u.entity IN (0,".$conf->entity.")";
418
-        if (empty($user->rights->user->user->lire)) $sql_usr.=" AND u.rowid = ".$user->id;
419
-        if (! empty($user->societe_id)) $sql_usr.=" AND u.fk_soc = ".$user->societe_id;
420
+        if (empty($user->rights->user->user->lire)) {
421
+            $sql_usr.=" AND u.rowid = ".$user->id;
422
+        }
423
+        if (! empty($user->societe_id)) {
424
+            $sql_usr.=" AND u.fk_soc = ".$user->societe_id;
425
+        }
420 426
         // Add existing sales representatives of thirdparty of external user
421 427
         if (empty($user->rights->user->user->lire) && $user->societe_id)
422 428
         {
@@ -437,7 +443,9 @@  discard block
 block discarded – undo
437 443
 
438 444
                 $out.='<option value="'.$obj_usr->rowid.'"';
439 445
 
440
-                if ($obj_usr->rowid == $selected) $out.=' selected';
446
+                if ($obj_usr->rowid == $selected) {
447
+                    $out.=' selected';
448
+                }
441 449
 
442 450
                 $out.='>';
443 451
                 $out.=dolGetFirstLastname($obj_usr->firstname,$obj_usr->lastname);
@@ -465,8 +473,7 @@  discard block
 block discarded – undo
465 473
                 $out.='</option>';
466 474
             }
467 475
             $this->db->free($resql_usr);
468
-        }
469
-        else
476
+        } else
470 477
         {
471 478
             dol_print_error($this->db);
472 479
         }
@@ -502,15 +509,16 @@  discard block
 block discarded – undo
502 509
         if ($tasksarray)
503 510
         {
504 511
         	print '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
505
-            if ($useempty) print '<option value="0">&nbsp;</option>';
512
+            if ($useempty) {
513
+                print '<option value="0">&nbsp;</option>';
514
+            }
506 515
             $j=0;
507 516
             $level=0;
508 517
             $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
509 518
             print '</select>';
510 519
 
511 520
             print ajax_combobox($htmlname);
512
-        }
513
-        else
521
+        } else
514 522
         {
515 523
             print '<div class="warning">'.$langs->trans("NoProject").'</div>';
516 524
         }
@@ -544,20 +552,23 @@  discard block
 block discarded – undo
544 552
 				//var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id);		// $lines[$i]->id may be empty if project has no lines
545 553
 
546 554
                 // Break on a new project
547
-                if ($parent == 0)	// We are on a task at first level
555
+                if ($parent == 0) {
556
+                    // We are on a task at first level
548 557
                 {
549 558
                     if ($lines[$i]->fk_project != $lastprojectid)	// Break found on project
550 559
                     {
551 560
                         if ($i > 0) print '<option value="0" disabled>----------</option>';
561
+                }
552 562
                         print '<option value="'.$lines[$i]->fk_project.'_0"';
553
-                        if ($selectedproject == $lines[$i]->fk_project) print ' selected';
563
+                        if ($selectedproject == $lines[$i]->fk_project) {
564
+                            print ' selected';
565
+                        }
554 566
                         print '>';	// Project -> Task
555 567
                         print $langs->trans("Project").' '.$lines[$i]->projectref;
556 568
                         if (empty($lines[$i]->public))
557 569
                         {
558 570
                             print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
559
-                        }
560
-                        else
571
+                        } else
561 572
                         {
562 573
                             print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
563 574
                         }
@@ -572,31 +583,41 @@  discard block
 block discarded – undo
572 583
                 $newdisablechildoftaskid=$disablechildoftaskid;
573 584
 
574 585
                 // Print task
575
-                if (isset($lines[$i]->id))		// We use isset because $lines[$i]->id may be null if project has no task and are on root project (tasks may be caught by a left join). We enter here only if '0' or >0
586
+                if (isset($lines[$i]->id)) {
587
+                    // We use isset because $lines[$i]->id may be null if project has no task and are on root project (tasks may be caught by a left join). We enter here only if '0' or >0
576 588
                 {
577 589
                 	// Check if we must disable entry
578 590
                 	$disabled=0;
591
+                }
579 592
                 	if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_parent == $disablechildoftaskid)))
580 593
                 	{
581 594
                			$disabled++;
582
-               			if ($lines[$i]->fk_parent == $disablechildoftaskid) $newdisablechildoftaskid=$lines[$i]->id;	// If task is child of a disabled parent, we will propagate id to disable next child too
595
+               			if ($lines[$i]->fk_parent == $disablechildoftaskid) {
596
+               			    $newdisablechildoftaskid=$lines[$i]->id;
597
+               			}
598
+               			// If task is child of a disabled parent, we will propagate id to disable next child too
583 599
                 	}
584 600
 
585 601
                     print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
586
-                    if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) print ' selected';
587
-                    if ($disabled) print ' disabled';
602
+                    if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) {
603
+                        print ' selected';
604
+                    }
605
+                    if ($disabled) {
606
+                        print ' disabled';
607
+                    }
588 608
                     print '>';
589 609
                     print $langs->trans("Project").' '.$lines[$i]->projectref;
590 610
                     print ' '.$lines[$i]->projectlabel;
591 611
                     if (empty($lines[$i]->public))
592 612
                     {
593 613
                         print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
594
-                    }
595
-                    else
614
+                    } else
596 615
                     {
597 616
                         print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
598 617
                     }
599
-                    if ($lines[$i]->id) print ' > ';
618
+                    if ($lines[$i]->id) {
619
+                        print ' > ';
620
+                    }
600 621
                     for ($k = 0 ; $k < $level ; $k++)
601 622
                     {
602 623
                         print "&nbsp;&nbsp;&nbsp;";
@@ -606,7 +627,9 @@  discard block
 block discarded – undo
606 627
                 }
607 628
 
608 629
                 $level++;
609
-                if ($lines[$i]->id) $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
630
+                if ($lines[$i]->id) {
631
+                    $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
632
+                }
610 633
                 $level--;
611 634
             }
612 635
         }
@@ -625,12 +648,17 @@  discard block
 block discarded – undo
625 648
     {
626 649
     	$textcolor='FFF';
627 650
     	include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
628
-    	if(colorIsLight($color)) $textcolor='000';
651
+    	if(colorIsLight($color)) {
652
+    	    $textcolor='000';
653
+    	}
629 654
 
630 655
     	$color = colorArrayToHex(colorStringToArray($color,array()),'');
631 656
 
632
-		if ($color) print '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #'.$textcolor.'; background-color: #'.$color.'" value="'.$color.'">';
633
-		else print $textifnotdefined;
657
+		if ($color) {
658
+		    print '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #'.$textcolor.'; background-color: #'.$color.'" value="'.$color.'">';
659
+		} else {
660
+		    print $textifnotdefined;
661
+		}
634 662
     }
635 663
 
636 664
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -721,8 +749,7 @@  discard block
 block discarded – undo
721 749
 	             </script>';
722 750
             }
723 751
             $out.= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat'.($morecss?' '.$morecss:'').'" type="text" value="'.$set_color.'" />';
724
-        }
725
-        else  // In most cases, this is not used. We used instead function with no specific list of colors
752
+        } else  // In most cases, this is not used. We used instead function with no specific list of colors
726 753
         {
727 754
             if (empty($conf->dol_use_jmobile))
728 755
             {
@@ -743,7 +770,9 @@  discard block
 block discarded – undo
743 770
             foreach ($arrayofcolors as $val)
744 771
             {
745 772
                 $out.= '<option value="'.$val.'"';
746
-                if ($set_color == $val) $out.= ' selected';
773
+                if ($set_color == $val) {
774
+                    $out.= ' selected';
775
+                }
747 776
                 $out.= '>'.$val.'</option>';
748 777
             }
749 778
             $out.= '</select>';
@@ -827,8 +856,7 @@  discard block
 block discarded – undo
827 856
             if ($selected == $key)
828 857
             {
829 858
                 $select_week .= '<option value="'.$key.'" selected>';
830
-            }
831
-            else
859
+            } else
832 860
             {
833 861
                 $select_week .= '<option value="'.$key.'">';
834 862
             }
@@ -857,8 +885,13 @@  discard block
 block discarded – undo
857 885
 
858 886
         require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
859 887
 
860
-        if ($longlabel) $montharray = monthArray($langs, 0);	// Get array
861
-        else $montharray = monthArray($langs, 1);
888
+        if ($longlabel) {
889
+            $montharray = monthArray($langs, 0);
890
+        }
891
+        // Get array
892
+        else {
893
+            $montharray = monthArray($langs, 1);
894
+        }
862 895
 
863 896
         $select_month = '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
864 897
         if ($useempty)
@@ -870,8 +903,7 @@  discard block
 block discarded – undo
870 903
             if ($selected == $key)
871 904
             {
872 905
                 $select_month .= '<option value="'.$key.'" selected>';
873
-            }
874
-            else
906
+            } else
875 907
             {
876 908
                 $select_month .= '<option value="'.$key.'">';
877 909
             }
@@ -924,13 +956,17 @@  discard block
 block discarded – undo
924 956
         $currentyear = date("Y")+$offset;
925 957
         $max_year = $currentyear+$max_year;
926 958
         $min_year = $currentyear-$min_year;
927
-        if(empty($selected) && empty($useempty)) $selected = $currentyear;
959
+        if(empty($selected) && empty($useempty)) {
960
+            $selected = $currentyear;
961
+        }
928 962
 
929 963
         $out.= '<select class="flat'.($morecss?' '.$morecss:'').'" id="' . $htmlname . '" name="' . $htmlname . '"'.$option.' >';
930 964
         if($useempty)
931 965
         {
932 966
         	$selected_html='';
933
-            if ($selected == '') $selected_html = ' selected';
967
+            if ($selected == '') {
968
+                $selected_html = ' selected';
969
+            }
934 970
             $out.= '<option value=""' . $selected_html . '>&nbsp;</option>';
935 971
         }
936 972
         if (! $invert)
@@ -938,16 +974,19 @@  discard block
 block discarded – undo
938 974
             for ($y = $max_year; $y >= $min_year; $y--)
939 975
             {
940 976
                 $selected_html='';
941
-                if ($selected > 0 && $y == $selected) $selected_html = ' selected';
977
+                if ($selected > 0 && $y == $selected) {
978
+                    $selected_html = ' selected';
979
+                }
942 980
                 $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
943 981
             }
944
-        }
945
-        else
982
+        } else
946 983
         {
947 984
             for ($y = $min_year; $y <= $max_year; $y++)
948 985
             {
949 986
                 $selected_html='';
950
-                if ($selected > 0 && $y == $selected) $selected_html = ' selected';
987
+                if ($selected > 0 && $y == $selected) {
988
+                    $selected_html = ' selected';
989
+                }
951 990
                 $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
952 991
             }
953 992
         }
@@ -984,8 +1023,7 @@  discard block
 block discarded – undo
984 1023
             $langs->load("companies");
985 1024
             print ' &nbsp; <a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$socid.'&action=create&origin='.$origin.'&originid='.$originid.'>'.$langs->trans("AddAddress").'</a>';
986 1025
             print '</form>';
987
-        }
988
-        else
1026
+        } else
989 1027
         {
990 1028
             if ($selected)
991 1029
             {
@@ -993,8 +1031,7 @@  discard block
 block discarded – undo
993 1031
                 $address=new Address($this->db);
994 1032
                 $result=$address->fetch_address($selected);
995 1033
                 print '<a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$address->socid.'&id='.$address->id.'&action=edit&origin='.$origin.'&originid='.$originid.'>'.$address->label.'</a>';
996
-            }
997
-            else
1034
+            } else
998 1035
             {
999 1036
                 print "&nbsp;";
1000 1037
             }
@@ -1028,7 +1065,10 @@  discard block
 block discarded – undo
1028 1065
         $boxidactivatedforuser=array();
1029 1066
         foreach($boxactivated as $box)
1030 1067
         {
1031
-        	if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) $boxidactivatedforuser[$box->id]=$box->id;	// We keep only boxes to show for user
1068
+        	if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) {
1069
+        	    $boxidactivatedforuser[$box->id]=$box->id;
1070
+        	}
1071
+        	// We keep only boxes to show for user
1032 1072
         }
1033 1073
 
1034 1074
         // Define selectboxlist
@@ -1039,7 +1079,10 @@  discard block
 block discarded – undo
1039 1079
         	$langs->load("boxes");	// Load label of boxes
1040 1080
         	foreach($boxactivated as $box)
1041 1081
         	{
1042
-        		if (! empty($boxidactivatedforuser[$box->id])) continue;	// Already visible for user
1082
+        		if (! empty($boxidactivatedforuser[$box->id])) {
1083
+        		    continue;
1084
+        		}
1085
+        		// Already visible for user
1043 1086
         		$label=$langs->transnoentitiesnoconv($box->boxlabel);
1044 1087
         		//if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
1045 1088
         		if (preg_match('/graph/',$box->class) && $conf->browser->layout != 'phone')
@@ -1050,7 +1093,9 @@  discard block
 block discarded – undo
1050 1093
         	}
1051 1094
             foreach($boxidactivatedforuser as $boxid)
1052 1095
         	{
1053
-       			if (empty($boxorder)) $boxorder.='A:';
1096
+       			if (empty($boxorder)) {
1097
+       			    $boxorder.='A:';
1098
+       			}
1054 1099
   				$boxorder.=$boxid.',';
1055 1100
         	}
1056 1101
 
@@ -1064,7 +1109,9 @@  discard block
 block discarded – undo
1064 1109
 			$selectboxlist.='<input type="hidden" name="areacode" value="'.$areacode.'">';
1065 1110
 			$selectboxlist.='<input type="hidden" name="boxorder" value="'.$boxorder.'">';
1066 1111
 			$selectboxlist.=Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth150onsmartphone', 0, 'hidden selected', 0, 1);
1067
-            if (empty($conf->use_javascript_ajax)) $selectboxlist.=' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1112
+            if (empty($conf->use_javascript_ajax)) {
1113
+                $selectboxlist.=' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1114
+            }
1068 1115
             $selectboxlist.='</form>';
1069 1116
             if (! empty($conf->use_javascript_ajax))
1070 1117
             {
@@ -1115,7 +1162,9 @@  discard block
 block discarded – undo
1115 1162
 	        			window.location.search=\'mainmenu='.GETPOST("mainmenu","aZ09").'&leftmenu='.GETPOST('leftmenu',"aZ09").'&action=addbox&boxid=\'+boxid;
1116 1163
 	                }
1117 1164
 	        	});';
1118
-	        	if (! count($arrayboxtoactivatelabel)) $selectboxlist.='jQuery("#boxcombo").hide();';
1165
+	        	if (! count($arrayboxtoactivatelabel)) {
1166
+	        	    $selectboxlist.='jQuery("#boxcombo").hide();';
1167
+	        	}
1119 1168
 	        	$selectboxlist.='
1120 1169
 
1121 1170
 	        	jQuery("#boxhalfleft, #boxhalfright").sortable({
@@ -1158,16 +1207,25 @@  discard block
 block discarded – undo
1158 1207
 
1159 1208
             // Define $box_max_lines
1160 1209
             $box_max_lines=5;
1161
-            if (! empty($conf->global->MAIN_BOXES_MAXLINES)) $box_max_lines=$conf->global->MAIN_BOXES_MAXLINES;
1210
+            if (! empty($conf->global->MAIN_BOXES_MAXLINES)) {
1211
+                $box_max_lines=$conf->global->MAIN_BOXES_MAXLINES;
1212
+            }
1162 1213
 
1163 1214
             $ii=0;
1164 1215
             foreach ($boxactivated as $key => $box)
1165 1216
             {
1166
-            	if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1167
-				if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) $box->box_order='A'.sprintf("%02d",($ii+1));	// When box_order was not yet set to Axx or Bxx and is still 0
1168
-            	if (preg_match('/^A/i',$box->box_order)) // column A
1217
+            	if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1218
+            	    continue;
1219
+            	}
1220
+				if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1221
+				    $box->box_order='A'.sprintf("%02d",($ii+1));
1222
+				}
1223
+				// When box_order was not yet set to Axx or Bxx and is still 0
1224
+            	if (preg_match('/^A/i',$box->box_order)) {
1225
+            	    // column A
1169 1226
                 {
1170 1227
                     $ii++;
1228
+            	}
1171 1229
                     //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1172 1230
                     //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1173 1231
                     // Show box
@@ -1190,11 +1248,18 @@  discard block
 block discarded – undo
1190 1248
             $ii=0;
1191 1249
             foreach ($boxactivated as $key => $box)
1192 1250
             {
1193
-            	if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1194
-            	if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) $box->box_order='B'.sprintf("%02d",($ii+1));	// When box_order was not yet set to Axx or Bxx and is still 0
1195
-            	if (preg_match('/^B/i',$box->box_order)) // colonne B
1251
+            	if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1252
+            	    continue;
1253
+            	}
1254
+            	if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1255
+            	    $box->box_order='B'.sprintf("%02d",($ii+1));
1256
+            	}
1257
+            	// When box_order was not yet set to Axx or Bxx and is still 0
1258
+            	if (preg_match('/^B/i',$box->box_order)) {
1259
+            	    // colonne B
1196 1260
                 {
1197 1261
                     $ii++;
1262
+            	}
1198 1263
                     //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1199 1264
                     //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1200 1265
                     // Show box
@@ -1262,8 +1327,7 @@  discard block
 block discarded – undo
1262 1327
                     if ($selected == $obj->rowid || $selected == $obj->$keyfield)
1263 1328
                     {
1264 1329
                         print '<option value="'.$obj->$keyfield.'" selected>';
1265
-                    }
1266
-                    else
1330
+                    } else
1267 1331
                     {
1268 1332
                         print '<option value="'.$obj->$keyfield.'">';
1269 1333
                     }
@@ -1272,13 +1336,11 @@  discard block
 block discarded – undo
1272 1336
                     $i++;
1273 1337
                 }
1274 1338
                 print "</select>";
1275
-            }
1276
-            else
1339
+            } else
1277 1340
 			{
1278 1341
                 print $langs->trans("DictionaryEmpty");
1279 1342
             }
1280
-        }
1281
-        else {
1343
+        } else {
1282 1344
             dol_print_error($this->db);
1283 1345
         }
1284 1346
     }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formmail.class.php 1 patch
Braces   +235 added lines, -126 removed lines patch added patch discarded remove patch
@@ -166,7 +166,9 @@  discard block
 block discarded – undo
166 166
 		// Set tmp user directory
167 167
 		$vardir=$conf->user->dir_output."/".$user->id;
168 168
 		$upload_dir = $vardir.'/temp/';                     // TODO Add $keytoavoidconflict in upload_dir path
169
-		if (is_dir($upload_dir)) dol_delete_dir_recursive($upload_dir);
169
+		if (is_dir($upload_dir)) {
170
+		    dol_delete_dir_recursive($upload_dir);
171
+		}
170 172
 
171 173
 		$keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid;   // this->trackid must be defined
172 174
 		unset($_SESSION["listofpaths".$keytoavoidconflict]);
@@ -190,13 +192,23 @@  discard block
 block discarded – undo
190 192
 		$listofnames=array();
191 193
 		$listofmimes=array();
192 194
 
193
-		if (empty($file)) $file=basename($path);
194
-		if (empty($type)) $type=dol_mimetype($file);
195
+		if (empty($file)) {
196
+		    $file=basename($path);
197
+		}
198
+		if (empty($type)) {
199
+		    $type=dol_mimetype($file);
200
+		}
195 201
 
196 202
 		$keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid;   // this->trackid must be defined
197
-		if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
198
-		if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
199
-		if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
203
+		if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) {
204
+		    $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
205
+		}
206
+		if (! empty($_SESSION["listofnames".$keytoavoidconflict])) {
207
+		    $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
208
+		}
209
+		if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) {
210
+		    $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
211
+		}
200 212
 		if (! in_array($file,$listofnames))
201 213
 		{
202 214
 			$listofpaths[]=$path;
@@ -223,9 +235,15 @@  discard block
 block discarded – undo
223 235
 		$listofmimes=array();
224 236
 
225 237
 		$keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid;   // this->trackid must be defined
226
-		if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
227
-		if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
228
-		if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
238
+		if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) {
239
+		    $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
240
+		}
241
+		if (! empty($_SESSION["listofnames".$keytoavoidconflict])) {
242
+		    $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
243
+		}
244
+		if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) {
245
+		    $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
246
+		}
229 247
 		if ($keytodelete >= 0)
230 248
 		{
231 249
 			unset ($listofpaths[$keytodelete]);
@@ -252,9 +270,15 @@  discard block
 block discarded – undo
252 270
 		$listofmimes=array();
253 271
 
254 272
 		$keytoavoidconflict = empty($this->trackid)?'':'-'.$this->trackid;   // this->trackid must be defined
255
-		if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
256
-		if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
257
-		if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
273
+		if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) {
274
+		    $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
275
+		}
276
+		if (! empty($_SESSION["listofnames".$keytoavoidconflict])) {
277
+		    $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
278
+		}
279
+		if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) {
280
+		    $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
281
+		}
258 282
 		return array('paths'=>$listofpaths, 'names'=>$listofnames, 'mimes'=>$listofmimes);
259 283
 	}
260 284
 
@@ -290,7 +314,9 @@  discard block
 block discarded – undo
290 314
         // phpcs:enable
291 315
 		global $conf, $langs, $user, $hookmanager, $form;
292 316
 
293
-		if (! is_object($form)) $form=new Form($this->db);
317
+		if (! is_object($form)) {
318
+		    $form=new Form($this->db);
319
+		}
294 320
 
295 321
 		// Load translation files required by the page
296 322
         $langs->loadLangs(array('other', 'mails'));
@@ -314,8 +340,7 @@  discard block
 block discarded – undo
314 340
 		if (!empty($reshook))
315 341
 		{
316 342
 			return $hookmanager->resPrint;
317
-		}
318
-		else
343
+		} else
319 344
 		{
320 345
 			$out='';
321 346
 
@@ -324,7 +349,9 @@  discard block
 block discarded – undo
324 349
 			// Define output language
325 350
 			$outputlangs = $langs;
326 351
 			$newlang = '';
327
-			if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $this->param['langsmodels'];
352
+			if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
353
+			    $newlang = $this->param['langsmodels'];
354
+			}
328 355
 			if (! empty($newlang))
329 356
 			{
330 357
 				$outputlangs = new Translate("", $conf);
@@ -362,9 +389,15 @@  discard block
 block discarded – undo
362 389
 				}
363 390
 			}
364 391
 
365
-	   		if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
366
-	   		if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
367
-	   		if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
392
+	   		if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) {
393
+	   		    $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]);
394
+	   		}
395
+	   		if (! empty($_SESSION["listofnames".$keytoavoidconflict])) {
396
+	   		    $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]);
397
+	   		}
398
+	   		if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) {
399
+	   		    $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]);
400
+	   		}
368 401
 
369 402
 
370 403
 			$out.= "\n".'<!-- Begin form mail type='.$this->param["models"].' --><div id="mailformdiv"></div>'."\n";
@@ -404,13 +437,16 @@  discard block
 block discarded – undo
404 437
 					if (preg_match('/\((.*)\)/', $line->label, $reg))
405 438
 					{
406 439
 						$modelmail_array[$line->id]=$langs->trans($reg[1]);		// langs->trans when label is __(xxx)__
407
-					}
408
-					else
440
+					} else
409 441
 					{
410 442
 						$modelmail_array[$line->id]=$line->label;
411 443
 					}
412
-					if ($line->lang) $modelmail_array[$line->id].=' ('.$line->lang.')';
413
-					if ($line->private) $modelmail_array[$line->id].=' - '.$langs->trans("Private");
444
+					if ($line->lang) {
445
+					    $modelmail_array[$line->id].=' ('.$line->lang.')';
446
+					}
447
+					if ($line->private) {
448
+					    $modelmail_array[$line->id].=' - '.$langs->trans("Private");
449
+					}
414 450
 					//if ($line->fk_user != $user->id) $modelmail_array[$line->id].=' - '.$langs->trans("By").' ';
415 451
 				}
416 452
 			}
@@ -421,13 +457,14 @@  discard block
 block discarded – undo
421 457
 				// If list of template is filled
422 458
 				$out.= '<div class="center" style="padding: 0px 0 12px 0">'."\n";
423 459
 				$out.= '<span class="opacitymedium">'.$langs->trans('SelectMailModel').':</span> '.$this->selectarray('modelmailselected', $modelmail_array, 0, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100');
424
-				if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')),1);
460
+				if ($user->admin) {
461
+				    $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')),1);
462
+				}
425 463
 				$out.= ' &nbsp; ';
426 464
 				$out.= '<input class="button" type="submit" value="'.$langs->trans('Apply').'" name="modelselected" id="modelselected">';
427 465
 				$out.= ' &nbsp; ';
428 466
 				$out.= '</div>';
429
-			}
430
-			elseif (! empty($this->param['models']) && in_array($this->param['models'], array(
467
+			} elseif (! empty($this->param['models']) && in_array($this->param['models'], array(
431 468
 					'propal_send','order_send','facture_send',
432 469
 					'shipping_send','fichinter_send','supplier_proposal_send','order_supplier_send',
433 470
 					'invoice_supplier_send','thirdparty','contract','user','all'
@@ -436,7 +473,9 @@  discard block
 block discarded – undo
436 473
 				// If list of template is empty
437 474
 				$out.= '<div class="center" style="padding: 0px 0 12px 0">'."\n";
438 475
 				$out.= $langs->trans('SelectMailModel').': <select name="modelmailselected" disabled="disabled"><option value="none">'.$langs->trans("NoTemplateDefined").'</option></select>';    // Do not put 'disabled' on 'option' tag, it is already on 'select' and it makes chrome crazy.
439
-				if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')),1);
476
+				if ($user->admin) {
477
+				    $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFrom", $langs->transnoentitiesnoconv('Setup').' - '.$langs->transnoentitiesnoconv('EMails')),1);
478
+				}
440 479
 				$out.= ' &nbsp; ';
441 480
 				$out.= '<input class="button" type="submit" value="'.$langs->trans('Apply').'" name="modelselected" disabled="disabled" id="modelselected">';
442 481
 				$out.= ' &nbsp; ';
@@ -449,17 +488,27 @@  discard block
 block discarded – undo
449 488
 
450 489
 			// Substitution array/string
451 490
 			$helpforsubstitution='';
452
-			if (is_array($this->substit) && count($this->substit)) $helpforsubstitution.=$langs->trans('AvailableVariables').' :<br>'."\n";
491
+			if (is_array($this->substit) && count($this->substit)) {
492
+			    $helpforsubstitution.=$langs->trans('AvailableVariables').' :<br>'."\n";
493
+			}
453 494
 			foreach($this->substit as $key => $val)
454 495
 			{
455 496
 				$helpforsubstitution.=$key.' -> '.$langs->trans(dol_string_nohtmltag($val)).'<br>';
456 497
 			}
457
-			if (! empty($this->withsubstit))		// Unset or set ->withsubstit=0 to disable this.
498
+			if (! empty($this->withsubstit)) {
499
+			    // Unset or set ->withsubstit=0 to disable this.
458 500
 			{
459 501
 				$out.= '<tr><td colspan="2" align="right">';
502
+			}
460 503
 				//$out.='<div class="floatright">';
461
-				if (is_numeric($this->withsubstit)) $out.= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip');	// Old usage
462
-				else $out.= $form->textwithpicto($langs->trans('AvailableVariables'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip');															// New usage
504
+				if (is_numeric($this->withsubstit)) {
505
+				    $out.= $form->textwithpicto($langs->trans("EMailTestSubstitutionReplacedByGenericValues"), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip');
506
+				}
507
+				// Old usage
508
+				else {
509
+				    $out.= $form->textwithpicto($langs->trans('AvailableVariables'), $helpforsubstitution, 1, 'help', '', 0, 2, 'substittooltip');
510
+				}
511
+				// New usage
463 512
 				$out.= "</td></tr>\n";
464 513
 				//$out.='</div>';
465 514
 			}
@@ -490,8 +539,7 @@  discard block
 block discarded – undo
490 539
 						if ($this->frommail)
491 540
 						{
492 541
 							$out.= ' &lt;'.$this->frommail.'&gt;';
493
-						}
494
-						else
542
+						} else
495 543
 						{
496 544
 							if ($this->fromtype)
497 545
 							{
@@ -507,8 +555,7 @@  discard block
 block discarded – undo
507 555
 						{
508 556
 							$langs->load('errors');
509 557
 							$liste['user'] = $user->getFullName($langs) . ' &lt;'.$langs->trans('ErrorNoMailDefinedForThisUser').'&gt;';
510
-						}
511
-						else
558
+						} else
512 559
 						{
513 560
 							$liste['user'] = $user->getFullName($langs) .' &lt;'.$user->email.'&gt;';
514 561
 						}
@@ -548,8 +595,9 @@  discard block
 block discarded – undo
548 595
 								}
549 596
 								$i++;
550 597
 							}
598
+						} else {
599
+						    dol_print_error($this->db);
551 600
 						}
552
-						else dol_print_error($this->db);
553 601
 
554 602
 						foreach($listaliases as $typealias => $listalias)
555 603
 						{
@@ -563,7 +611,9 @@  discard block
 block discarded – undo
563 611
 								{
564 612
 									$listaliasval=preg_replace('/</', '&lt;', $listaliasval);
565 613
 									$listaliasval=preg_replace('/>/', '&gt;', $listaliasval);
566
-									if (! preg_match('/&lt;/', $listaliasval)) $listaliasval='&lt;'.$listaliasval.'&gt;';
614
+									if (! preg_match('/&lt;/', $listaliasval)) {
615
+									    $listaliasval='&lt;'.$listaliasval.'&gt;';
616
+									}
567 617
 									$liste[$typealias.'_'.$posalias]=$listaliasval;
568 618
 								}
569 619
 							}
@@ -576,7 +626,9 @@  discard block
 block discarded – undo
576 626
 						{
577 627
 							$defaultfrom = $this->fromtype;
578 628
 						}
579
-						if (! empty($hookmanager->resArray['defaultfrom'])) $defaultfrom=$hookmanager->resArray['defaultfrom'];
629
+						if (! empty($hookmanager->resArray['defaultfrom'])) {
630
+						    $defaultfrom=$hookmanager->resArray['defaultfrom'];
631
+						}
580 632
 
581 633
 						// Using combo here make the '<email>' no more visible on list.
582 634
 						//$out.= ' '.$form->selectarray('fromtype', $liste, $this->fromtype, 0, 0, 0, '', 0, 0, 0, '', 'fromforsendingprofile maxwidth200onsmartphone', 1, '', $disablebademails);
@@ -584,8 +636,7 @@  discard block
 block discarded – undo
584 636
 					}
585 637
 
586 638
 					$out.= "</td></tr>\n";
587
-				}
588
-				else
639
+				} else
589 640
 				{
590 641
 					$out.= '<tr><td class="fieldrequired width200">'.$langs->trans("MailFrom")."</td><td>";
591 642
 					$out.= $langs->trans("Name").':<input type="text" id="fromname" name="fromname" class="maxwidth200onsmartphone" value="'.$this->fromname.'" />';
@@ -599,8 +650,11 @@  discard block
 block discarded – undo
599 650
 			if (! empty($this->withto) || is_array($this->withto))
600 651
 			{
601 652
 				$out.= '<tr><td class="fieldrequired">';
602
-				if ($this->withtofree) $out.= $form->textwithpicto($langs->trans("MailTo"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
603
-				else $out.= $langs->trans("MailTo");
653
+				if ($this->withtofree) {
654
+				    $out.= $form->textwithpicto($langs->trans("MailTo"),$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"));
655
+				} else {
656
+				    $out.= $langs->trans("MailTo");
657
+				}
604 658
 				$out.= '</td><td>';
605 659
 				if ($this->withtoreadonly)
606 660
 				{
@@ -613,14 +667,12 @@  discard block
 block discarded – undo
613 667
 							$soc=new Societe($this->db);
614 668
 							$soc->fetch($this->toid);
615 669
 							$out.= $soc->getNomUrl(1);
616
-						}
617
-						else if ($this->totype == 'contact')
670
+						} else if ($this->totype == 'contact')
618 671
 						{
619 672
 							$contact=new Contact($this->db);
620 673
 							$contact->fetch($this->toid);
621 674
 							$out.= $contact->getNomUrl(1);
622
-						}
623
-						else
675
+						} else
624 676
 						{
625 677
 							$out.= $this->toname;
626 678
 						}
@@ -629,14 +681,12 @@  discard block
 block discarded – undo
629 681
 						{
630 682
 							$out.= '<br>'.$langs->trans("and").' <input class="minwidth200" id="sendto" name="sendto" value="'.(! is_array($this->withto) && ! is_numeric($this->withto)? (isset($_REQUEST["sendto"])?$_REQUEST["sendto"]:$this->withto) :"").'" />';
631 683
 						}
632
-					}
633
-					else
684
+					} else
634 685
 					{
635 686
 						// Note withto may be a text like 'AllRecipientSelected'
636 687
 						$out.= (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
637 688
 					}
638
-				}
639
-				else
689
+				} else
640 690
 				{
641 691
 					if (! empty($this->withtofree))
642 692
 					{
@@ -644,7 +694,9 @@  discard block
 block discarded – undo
644 694
 					}
645 695
 					if (! empty($this->withto) && is_array($this->withto))
646 696
 					{
647
-						if (! empty($this->withtofree)) $out.= " ".$langs->trans("and")."/".$langs->trans("or")." ";
697
+						if (! empty($this->withtofree)) {
698
+						    $out.= " ".$langs->trans("and")."/".$langs->trans("or")." ";
699
+						}
648 700
 						// multiselect array convert html entities into options tags, even if we dont want this, so we encode them a second time
649 701
 						$tmparray = $this->withto;
650 702
 						foreach($tmparray as $key => $val)
@@ -708,8 +760,7 @@  discard block
 block discarded – undo
708 760
 				if ($this->withtoccreadonly)
709 761
 				{
710 762
 					$out.= (! is_array($this->withtocc) && ! is_numeric($this->withtocc))?$this->withtocc:"";
711
-				}
712
-				else
763
+				} else
713 764
 				{
714 765
 					$out.= '<input class="minwidth200" id="sendtocc" name="sendtocc" value="'.((! is_array($this->withtocc) && ! is_numeric($this->withtocc))? (isset($_POST["sendtocc"])?$_POST["sendtocc"]:$this->withtocc) : (isset($_POST["sendtocc"])?$_POST["sendtocc"]:"") ).'" />';
715 766
 					if (! empty($this->withtocc) && is_array($this->withtocc))
@@ -790,11 +841,13 @@  discard block
 block discarded – undo
790 841
 
791 842
 				$out.= '<td>';
792 843
 
793
-				if ($this->withmaindocfile)	// withmaindocfile is set to 1 or -1 to show the checkbox (-1 = checked or 1 = not checked)
844
+				if ($this->withmaindocfile) {
845
+				    // withmaindocfile is set to 1 or -1 to show the checkbox (-1 = checked or 1 = not checked)
794 846
 				{
795 847
 					if (GETPOSTISSET('sendmail'))
796 848
 					{
797 849
 						$this->withmaindocfile = (GETPOST('addmaindocfile', 'alpha') ? -1 : 1);
850
+				}
798 851
 					}
799 852
 					// If a template was selected, we use setup of template to define if join file checkbox is selected or not.
800 853
 					elseif (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0)
@@ -840,20 +893,23 @@  discard block
 block discarded – undo
840 893
 							}
841 894
 							$out.= '<br></div>';
842 895
 						}
843
-					}
844
-					else if (empty($this->withmaindocfile))		// Do not show message if we asked to show the checkbox
896
+					} else if (empty($this->withmaindocfile)) {
897
+					    // Do not show message if we asked to show the checkbox
845 898
 					{
846 899
 						$out.= $langs->trans("NoAttachedFiles").'<br>';
847 900
 					}
848
-					if ($this->withfile == 2)	// Can add other files
901
+					}
902
+					if ($this->withfile == 2) {
903
+					    // Can add other files
849 904
 					{
850 905
 						if (!empty($conf->global->FROM_MAIL_USE_INPUT_FILE_MULTIPLE)) $out.= '<input type="file" class="flat" id="addedfile" name="addedfile[]" value="'.$langs->trans("Upload").'" multiple />';
851
-						else $out.= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
906
+					} else {
907
+						    $out.= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
908
+						}
852 909
 						$out.= ' ';
853 910
 						$out.= '<input class="button" type="submit" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
854 911
 					}
855
-				}
856
-				else
912
+				} else
857 913
 				{
858 914
 					$out.=$this->withfile;
859 915
 				}
@@ -879,16 +935,24 @@  discard block
 block discarded – undo
879 935
 				if (empty($this->substit['__REF__']))
880 936
 				{
881 937
 					$paymenturl='';
882
-				}
883
-				else
938
+				} else
884 939
 				{
885 940
 					// Set the online payment url link into __ONLINE_PAYMENT_URL__ key
886 941
 					require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
887 942
 					$langs->loadLangs(array('paypal','other'));
888 943
 					$typeforonlinepayment='free';
889
-					if ($this->param["models"]=='order'   || $this->param["models"]=='order_send')   $typeforonlinepayment='order';		// TODO use detection on something else than template
890
-					if ($this->param["models"]=='invoice' || $this->param["models"]=='facture_send') $typeforonlinepayment='invoice';	// TODO use detection on something else than template
891
-					if ($this->param["models"]=='member') $typeforonlinepayment='member';												// TODO use detection on something else than template
944
+					if ($this->param["models"]=='order'   || $this->param["models"]=='order_send') {
945
+					    $typeforonlinepayment='order';
946
+					}
947
+					// TODO use detection on something else than template
948
+					if ($this->param["models"]=='invoice' || $this->param["models"]=='facture_send') {
949
+					    $typeforonlinepayment='invoice';
950
+					}
951
+					// TODO use detection on something else than template
952
+					if ($this->param["models"]=='member') {
953
+					    $typeforonlinepayment='member';
954
+					}
955
+					// TODO use detection on something else than template
892 956
 					$url=getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit['__REF__']);
893 957
 					$paymenturl=$url;
894 958
 
@@ -900,8 +964,7 @@  discard block
 block discarded – undo
900 964
 					$langs->load('other');
901 965
 					$this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__']=str_replace('\n', "\n", $langs->transnoentities("PredefinedMailContentLink", $paymenturl));
902 966
 					$this->substit['__ONLINE_PAYMENT_URL__']=$paymenturl;
903
-				}
904
-				else
967
+				} else
905 968
 				{
906 969
 					$this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__']='';
907 970
 					$this->substit['__ONLINE_PAYMENT_URL__']='';
@@ -928,8 +991,9 @@  discard block
 block discarded – undo
928 991
 					$defaultmessage = dol_nl2br($defaultmessage);
929 992
 				}
930 993
 
931
-				if (isset($_POST["message"]) && ! $_POST['modelselected']) $defaultmessage=$_POST["message"];
932
-				else
994
+				if (isset($_POST["message"]) && ! $_POST['modelselected']) {
995
+				    $defaultmessage=$_POST["message"];
996
+				} else
933 997
 				{
934 998
 					$defaultmessage=make_substitutions($defaultmessage,$this->substit);
935 999
 					// Clean first \n and br (to avoid empty line when CONTACTCIVNAME is empty)
@@ -946,17 +1010,21 @@  discard block
 block discarded – undo
946 1010
 				{
947 1011
 					$out.= nl2br($defaultmessage);
948 1012
 					$out.= '<input type="hidden" id="message" name="message" value="'.$defaultmessage.'" />';
949
-				}
950
-				else
1013
+				} else
951 1014
 				{
952
-					if (! isset($this->ckeditortoolbar)) $this->ckeditortoolbar = 'dolibarr_notes';
1015
+					if (! isset($this->ckeditortoolbar)) {
1016
+					    $this->ckeditortoolbar = 'dolibarr_notes';
1017
+					}
953 1018
 
954 1019
 					// Editor wysiwyg
955 1020
 					require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
956 1021
 					if ($this->withfckeditor == -1)
957 1022
 					{
958
-						if (! empty($conf->global->FCKEDITOR_ENABLE_MAIL)) $this->withfckeditor=1;
959
-						else $this->withfckeditor=0;
1023
+						if (! empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
1024
+						    $this->withfckeditor=1;
1025
+						} else {
1026
+						    $this->withfckeditor=0;
1027
+						}
960 1028
 					}
961 1029
 
962 1030
 					$doleditor=new DolEditor('message',$defaultmessage,'',280,$this->ckeditortoolbar,'In',true,true,$this->withfckeditor,8,'95%');
@@ -985,7 +1053,9 @@  discard block
 block discarded – undo
985 1053
 				$out.= '</div>'."\n";
986 1054
 			}
987 1055
 
988
-			if ($this->withform == 1) $out.= '</form>'."\n";
1056
+			if ($this->withform == 1) {
1057
+			    $out.= '</form>'."\n";
1058
+			}
989 1059
 
990 1060
 			// Disable enter key if option MAIN_MAILFORM_DISABLE_ENTERKEY is set
991 1061
 			if (! empty($conf->global->MAIN_MAILFORM_DISABLE_ENTERKEY))
@@ -1037,11 +1107,21 @@  discard block
 block discarded – undo
1037 1107
 		}
1038 1108
 
1039 1109
 		$showinfobcc='';
1040
-		if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) && ! empty($this->param['models']) && $this->param['models'] == 'propal_send') $showinfobcc=$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO;
1041
-		if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) && ! empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') $showinfobcc=$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO;
1042
-		if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) && ! empty($this->param['models']) && $this->param['models'] == 'order_send') $showinfobcc=$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO;
1043
-		if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) && ! empty($this->param['models']) && $this->param['models'] == 'facture_send') $showinfobcc=$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO;
1044
-		if ($showinfobcc) $out.=' + '.$showinfobcc;
1110
+		if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) && ! empty($this->param['models']) && $this->param['models'] == 'propal_send') {
1111
+		    $showinfobcc=$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO;
1112
+		}
1113
+		if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) && ! empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') {
1114
+		    $showinfobcc=$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO;
1115
+		}
1116
+		if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) && ! empty($this->param['models']) && $this->param['models'] == 'order_send') {
1117
+		    $showinfobcc=$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO;
1118
+		}
1119
+		if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) && ! empty($this->param['models']) && $this->param['models'] == 'facture_send') {
1120
+		    $showinfobcc=$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO;
1121
+		}
1122
+		if ($showinfobcc) {
1123
+		    $out.=' + '.$showinfobcc;
1124
+		}
1045 1125
 		$out.= "</td></tr>\n";
1046 1126
 		return $out;
1047 1127
 	}
@@ -1083,10 +1163,18 @@  discard block
 block discarded – undo
1083 1163
 			$out.= yn($this->withdeliveryreceipt);
1084 1164
 		} else {
1085 1165
 			$defaultvaluefordeliveryreceipt=0;
1086
-			if (! empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_PROPAL) && ! empty($this->param['models']) && $this->param['models'] == 'propal_send') $defaultvaluefordeliveryreceipt=1;
1087
-			if (! empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_PROPOSAL) && ! empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') $defaultvaluefordeliveryreceipt=1;
1088
-			if (! empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_ORDER) && ! empty($this->param['models']) && $this->param['models'] == 'order_send') $defaultvaluefordeliveryreceipt=1;
1089
-			if (! empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_INVOICE) && ! empty($this->param['models']) && $this->param['models'] == 'facture_send') $defaultvaluefordeliveryreceipt=1;
1166
+			if (! empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_PROPAL) && ! empty($this->param['models']) && $this->param['models'] == 'propal_send') {
1167
+			    $defaultvaluefordeliveryreceipt=1;
1168
+			}
1169
+			if (! empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_SUPPLIER_PROPOSAL) && ! empty($this->param['models']) && $this->param['models'] == 'supplier_proposal_send') {
1170
+			    $defaultvaluefordeliveryreceipt=1;
1171
+			}
1172
+			if (! empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_ORDER) && ! empty($this->param['models']) && $this->param['models'] == 'order_send') {
1173
+			    $defaultvaluefordeliveryreceipt=1;
1174
+			}
1175
+			if (! empty($conf->global->MAIL_FORCE_DELIVERY_RECEIPT_INVOICE) && ! empty($this->param['models']) && $this->param['models'] == 'facture_send') {
1176
+			    $defaultvaluefordeliveryreceipt=1;
1177
+			}
1090 1178
 			$out.= $form->selectyesno('deliveryreceipt', (isset($_POST["deliveryreceipt"])?$_POST["deliveryreceipt"]:$defaultvaluefordeliveryreceipt), 1);
1091 1179
 		}
1092 1180
 		$out.= "</td></tr>\n";
@@ -1155,13 +1243,29 @@  discard block
 block discarded – undo
1155 1243
 		$sql.= " WHERE (type_template='".$db->escape($type_template)."' OR type_template='all')";
1156 1244
 		$sql.= " AND entity IN (".getEntity('c_email_templates').")";
1157 1245
 		$sql.= " AND (private = 0 OR fk_user = ".$user->id.")";				// Get all public or private owned
1158
-		if ($active >= 0) $sql.=" AND active = ".$active;
1159
-		if ($label) $sql.=" AND label ='".$db->escape($label)."'";
1160
-		if (! ($id > 0) && is_object($outputlangs)) $sql.= " AND (lang = '".$db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang = '')";
1161
-		if ($id > 0)   $sql.= " AND rowid=".$id;
1162
-		if ($id == -1) $sql.= " AND position=0";
1163
-		if (is_object($outputlangs)) $sql.= $db->order("position,lang,label","ASC,DESC,ASC");		// We want line with lang set first, then with lang null or ''
1164
-		else $sql.= $db->order("position,lang,label","ASC,ASC,ASC");		// If no language provided, we give priority to lang not defined
1246
+		if ($active >= 0) {
1247
+		    $sql.=" AND active = ".$active;
1248
+		}
1249
+		if ($label) {
1250
+		    $sql.=" AND label ='".$db->escape($label)."'";
1251
+		}
1252
+		if (! ($id > 0) && is_object($outputlangs)) {
1253
+		    $sql.= " AND (lang = '".$db->escape($outputlangs->defaultlang)."' OR lang IS NULL OR lang = '')";
1254
+		}
1255
+		if ($id > 0) {
1256
+		    $sql.= " AND rowid=".$id;
1257
+		}
1258
+		if ($id == -1) {
1259
+		    $sql.= " AND position=0";
1260
+		}
1261
+		if (is_object($outputlangs)) {
1262
+		    $sql.= $db->order("position,lang,label","ASC,DESC,ASC");
1263
+		}
1264
+		// We want line with lang set first, then with lang null or ''
1265
+		else {
1266
+		    $sql.= $db->order("position,lang,label","ASC,ASC,ASC");
1267
+		}
1268
+		// If no language provided, we give priority to lang not defined
1165 1269
 		$sql.= $db->plimit(1);
1166 1270
 		//print $sql;
1167 1271
 
@@ -1179,26 +1283,13 @@  discard block
 block discarded – undo
1179 1283
 				$ret->content = $obj->content;
1180 1284
 				$ret->content_lines = $obj->content_lines;
1181 1285
 				$ret->joinfiles = $obj->joinfiles;
1182
-			}
1183
-			elseif($id == -2) {
1286
+			} elseif($id == -2) {
1184 1287
 				// Not found with the provided label
1185 1288
 				return -1;
1186
-			}
1187
-			else {	// If there is no template at all
1289
+			} else {	// If there is no template at all
1188 1290
 				$defaultmessage='';
1189 1291
 				if ($type_template=='body')							{ $defaultmessage=$this->withbody; }		// Special case to use this->withbody as content
1190
-				elseif ($type_template=='facture_send')				{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendInvoice"); }
1191
-				elseif ($type_template=='facture_relance')			{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendInvoiceReminder"); }
1192
-				elseif ($type_template=='propal_send')				{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendProposal"); }
1193
-				elseif ($type_template=='supplier_proposal_send')	{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal"); }
1194
-				elseif ($type_template=='order_send')				{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendOrder"); }
1195
-				elseif ($type_template=='order_supplier_send')		{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder"); }
1196
-				elseif ($type_template=='invoice_supplier_send')	{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice"); }
1197
-				elseif ($type_template=='shipping_send')			{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendShipping"); }
1198
-				elseif ($type_template=='fichinter_send')			{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendFichInter"); }
1199
-				elseif ($type_template=='thirdparty')				{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentThirdparty"); }
1200
-				elseif ($type_template=='user')				        { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentUser"); }
1201
-				elseif (!empty($type_template))				        { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContent".ucfirst($type_template)); }
1292
+				elseif ($type_template=='facture_send')				{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendInvoice"); } elseif ($type_template=='facture_relance')			{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendInvoiceReminder"); } elseif ($type_template=='propal_send')				{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendProposal"); } elseif ($type_template=='supplier_proposal_send')	{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendSupplierProposal"); } elseif ($type_template=='order_send')				{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendOrder"); } elseif ($type_template=='order_supplier_send')		{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendSupplierOrder"); } elseif ($type_template=='invoice_supplier_send')	{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendSupplierInvoice"); } elseif ($type_template=='shipping_send')			{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendShipping"); } elseif ($type_template=='fichinter_send')			{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentSendFichInter"); } elseif ($type_template=='thirdparty')				{ $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentThirdparty"); } elseif ($type_template=='user')				        { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContentUser"); } elseif (!empty($type_template))				        { $defaultmessage=$outputlangs->transnoentities("PredefinedMailContent".ucfirst($type_template)); }
1202 1293
 
1203 1294
 				$ret->label = 'default';
1204 1295
 				$ret->lang = $outputlangs->defaultlang;
@@ -1210,8 +1301,7 @@  discard block
 block discarded – undo
1210 1301
 
1211 1302
 			$db->free($resql);
1212 1303
 			return $ret;
1213
-		}
1214
-		else
1304
+		} else
1215 1305
 		{
1216 1306
 			dol_print_error($db);
1217 1307
 			return -1;
@@ -1236,7 +1326,9 @@  discard block
 block discarded – undo
1236 1326
 		$sql.= " WHERE type_template='".$this->db->escape($type_template)."'";
1237 1327
 		$sql.= " AND entity IN (".getEntity('c_email_templates').")";
1238 1328
 		$sql.= " AND (fk_user is NULL or fk_user = 0 or fk_user = ".$user->id.")";
1239
-		if (is_object($outputlangs)) $sql.= " AND (lang = '".$outputlangs->defaultlang."' OR lang IS NULL OR lang = '')";
1329
+		if (is_object($outputlangs)) {
1330
+		    $sql.= " AND (lang = '".$outputlangs->defaultlang."' OR lang IS NULL OR lang = '')";
1331
+		}
1240 1332
 		$sql.= $this->db->order("lang,label","ASC");
1241 1333
 		//print $sql;
1242 1334
 
@@ -1246,8 +1338,7 @@  discard block
 block discarded – undo
1246 1338
 			$num= $this->db->num_rows($resql);
1247 1339
 			$this->db->free($resql);
1248 1340
 			return $num;
1249
-		}
1250
-		else
1341
+		} else
1251 1342
 		{
1252 1343
 			$this->error=get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1253 1344
 			return -1;
@@ -1273,7 +1364,9 @@  discard block
 block discarded – undo
1273 1364
 		$sql.= " WHERE type_template IN ('".$this->db->escape($type_template)."', 'all')";
1274 1365
 		$sql.= " AND entity IN (".getEntity('c_email_templates').")";
1275 1366
 		$sql.= " AND (private = 0 OR fk_user = ".$user->id.")";		// See all public templates or templates I own.
1276
-		if ($active >= 0) $sql.=" AND active = ".$active;
1367
+		if ($active >= 0) {
1368
+		    $sql.=" AND active = ".$active;
1369
+		}
1277 1370
 		//if (is_object($outputlangs)) $sql.= " AND (lang = '".$outputlangs->defaultlang."' OR lang IS NULL OR lang = '')";	// Return all languages
1278 1371
 		$sql.= $this->db->order("position,lang,label","ASC");
1279 1372
 		//print $sql;
@@ -1300,8 +1393,7 @@  discard block
 block discarded – undo
1300 1393
 			}
1301 1394
 			$this->db->free($resql);
1302 1395
 			return $num;
1303
-		}
1304
-		else
1396
+		} else
1305 1397
 		{
1306 1398
 			$this->error=get_class($this).' '.__METHOD__.' ERROR:'.$this->db->lasterror();
1307 1399
 			return -1;
@@ -1350,7 +1442,9 @@  discard block
 block discarded – undo
1350 1442
 				// Create dynamic tags for __PRODUCT_EXTRAFIELD_FIELD__
1351 1443
 				if (!empty($line->fk_product))
1352 1444
 				{
1353
-					if (! is_object($extrafields)) $extrafields = new ExtraFields($this->db);
1445
+					if (! is_object($extrafields)) {
1446
+					    $extrafields = new ExtraFields($this->db);
1447
+					}
1354 1448
 					$extrafields->fetch_name_optionals_label('product', true);
1355 1449
 					$product = new Product($this->db);
1356 1450
 					$product->fetch($line->fk_product, '', '', 1);
@@ -1419,21 +1513,34 @@  discard block
 block discarded – undo
1419 1513
 				//,'__PERSONALIZED__' => 'Personalized'	// Hidden because not used yet in mass emailing
1420 1514
 
1421 1515
 			$onlinepaymentenabled = 0;
1422
-			if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
1423
-			if (! empty($conf->paybox->enabled)) $onlinepaymentenabled++;
1424
-			if (! empty($conf->stripe->enabled)) $onlinepaymentenabled++;
1516
+			if (! empty($conf->paypal->enabled)) {
1517
+			    $onlinepaymentenabled++;
1518
+			}
1519
+			if (! empty($conf->paybox->enabled)) {
1520
+			    $onlinepaymentenabled++;
1521
+			}
1522
+			if (! empty($conf->stripe->enabled)) {
1523
+			    $onlinepaymentenabled++;
1524
+			}
1425 1525
 			if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
1426 1526
 			{
1427 1527
 				$tmparray['__SECUREKEYPAYMENT__']=$conf->global->PAYMENT_SECURITY_TOKEN;
1428 1528
 				if (! empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
1429 1529
 				{
1430
-					if ($conf->adherent->enabled) $tmparray['__SECUREKEYPAYMENT_MEMBER__']='SecureKeyPAYMENTUniquePerMember';
1431
-					if ($conf->facture->enabled)  $tmparray['__SECUREKEYPAYMENT_INVOICE__']='SecureKeyPAYMENTUniquePerInvoice';
1432
-					if ($conf->commande->enabled) $tmparray['__SECUREKEYPAYMENT_ORDER__']='SecureKeyPAYMENTUniquePerOrder';
1433
-					if ($conf->contrat->enabled)  $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__']='SecureKeyPAYMENTUniquePerContractLine';
1530
+					if ($conf->adherent->enabled) {
1531
+					    $tmparray['__SECUREKEYPAYMENT_MEMBER__']='SecureKeyPAYMENTUniquePerMember';
1532
+					}
1533
+					if ($conf->facture->enabled) {
1534
+					    $tmparray['__SECUREKEYPAYMENT_INVOICE__']='SecureKeyPAYMENTUniquePerInvoice';
1535
+					}
1536
+					if ($conf->commande->enabled) {
1537
+					    $tmparray['__SECUREKEYPAYMENT_ORDER__']='SecureKeyPAYMENTUniquePerOrder';
1538
+					}
1539
+					if ($conf->contrat->enabled) {
1540
+					    $tmparray['__SECUREKEYPAYMENT_CONTRACTLINE__']='SecureKeyPAYMENTUniquePerContractLine';
1541
+					}
1434 1542
 				}
1435
-			}
1436
-			else
1543
+			} else
1437 1544
 			{
1438 1545
 				/* No need to show into tooltip help, option is not enabled
1439 1546
 				$vars['__SECUREKEYPAYMENT__']='';
@@ -1447,7 +1554,9 @@  discard block
 block discarded – undo
1447 1554
 
1448 1555
 		foreach($tmparray as $key => $val)
1449 1556
 		{
1450
-			if (empty($val)) $tmparray[$key]=$key;
1557
+			if (empty($val)) {
1558
+			    $tmparray[$key]=$key;
1559
+			}
1451 1560
 		}
1452 1561
 
1453 1562
 		return $tmparray;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/notify.class.php 1 patch
Braces   +146 added lines, -66 removed lines patch added patch discarded remove patch
@@ -113,24 +113,42 @@  discard block
 block discarded – undo
113 113
 		$listofnotiftodo=$this->getNotificationsArray($action,$socid,$object,0);
114 114
 
115 115
 		$nb=-1;
116
-		if (is_array($listofnotiftodo)) $nb=count($listofnotiftodo);
117
-		if ($nb < 0)  $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend");
118
-		if ($nb == 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent");
119
-   		if ($nb == 1) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent");
120
-   		if ($nb >= 2) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb);
116
+		if (is_array($listofnotiftodo)) {
117
+		    $nb=count($listofnotiftodo);
118
+		}
119
+		if ($nb < 0) {
120
+		    $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend");
121
+		}
122
+		if ($nb == 0) {
123
+		    $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent");
124
+		}
125
+   		if ($nb == 1) {
126
+   		    $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent");
127
+   		}
128
+   		if ($nb >= 2) {
129
+   		    $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb);
130
+   		}
121 131
 
122 132
    		if (is_array($listofnotiftodo))
123 133
    		{
124 134
 			$i=0;
125 135
 			foreach ($listofnotiftodo as $key => $val)
126 136
 			{
127
-				if ($i) $texte.=', ';
128
-				else $texte.=' (';
129
-				if ($val['isemailvalid']) $texte.=$val['email'];
130
-				else $texte.=$val['emaildesc'];
137
+				if ($i) {
138
+				    $texte.=', ';
139
+				} else {
140
+				    $texte.=' (';
141
+				}
142
+				if ($val['isemailvalid']) {
143
+				    $texte.=$val['email'];
144
+				} else {
145
+				    $texte.=$val['emaildesc'];
146
+				}
131 147
 				$i++;
132 148
 			}
133
-			if ($i) $texte.=')';
149
+			if ($i) {
150
+			    $texte.=')';
151
+			}
134 152
    		}
135 153
 
136 154
 		return $texte;
@@ -154,7 +172,9 @@  discard block
 block discarded – undo
154 172
 		$resarray=array();
155 173
 
156 174
 		$valueforthreshold = 0;
157
-		if (is_object($object)) $valueforthreshold = $object->total_ht;
175
+		if (is_object($object)) {
176
+		    $valueforthreshold = $object->total_ht;
177
+		}
158 178
 
159 179
 		if (! $error)
160 180
 		{
@@ -170,11 +190,19 @@  discard block
 block discarded – undo
170 190
 				$sql.= " AND n.fk_soc = s.rowid";
171 191
 				if ($notifcode)
172 192
 				{
173
-					if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
174
-					else $sql.= " AND a.code = '".$notifcode."'";			// New usage
193
+					if (is_numeric($notifcode)) {
194
+					    $sql.= " AND n.fk_action = ".$notifcode;
195
+					}
196
+					// Old usage
197
+					else {
198
+					    $sql.= " AND a.code = '".$notifcode."'";
199
+					}
200
+					// New usage
175 201
 				}
176 202
 				$sql.= " AND s.entity IN (".getEntity('societe').")";
177
-				if ($socid > 0) $sql.= " AND s.rowid = ".$socid;
203
+				if ($socid > 0) {
204
+				    $sql.= " AND s.rowid = ".$socid;
205
+				}
178 206
 
179 207
 				dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
180 208
 
@@ -190,12 +218,13 @@  discard block
 block discarded – undo
190 218
 						{
191 219
 							$newval2=trim($obj->email);
192 220
 							$isvalid=isValidEmail($newval2);
193
-							if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
221
+							if (empty($resarray[$newval2])) {
222
+							    $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
223
+							}
194 224
 						}
195 225
 						$i++;
196 226
 					}
197
-				}
198
-				else
227
+				} else
199 228
 				{
200 229
 					$error++;
201 230
 					$this->error=$this->db->lasterror();
@@ -215,11 +244,19 @@  discard block
 block discarded – undo
215 244
 				$sql.= " AND a.rowid = n.fk_action";
216 245
 				if ($notifcode)
217 246
 				{
218
-					if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
219
-					else $sql.= " AND a.code = '".$notifcode."'";			// New usage
247
+					if (is_numeric($notifcode)) {
248
+					    $sql.= " AND n.fk_action = ".$notifcode;
249
+					}
250
+					// Old usage
251
+					else {
252
+					    $sql.= " AND a.code = '".$notifcode."'";
253
+					}
254
+					// New usage
220 255
 				}
221 256
 				$sql.= " AND c.entity IN (".getEntity('user').")";
222
-				if ($userid > 0) $sql.= " AND c.rowid = ".$userid;
257
+				if ($userid > 0) {
258
+				    $sql.= " AND c.rowid = ".$userid;
259
+				}
223 260
 
224 261
 				dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG);
225 262
 
@@ -235,12 +272,13 @@  discard block
 block discarded – undo
235 272
 						{
236 273
 							$newval2=trim($obj->email);
237 274
 							$isvalid=isValidEmail($newval2);
238
-							if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
275
+							if (empty($resarray[$newval2])) {
276
+							    $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid);
277
+							}
239 278
 						}
240 279
 						$i++;
241 280
 					}
242
-				}
243
-				else
281
+				} else
244 282
 				{
245 283
 					$error++;
246 284
 					$this->error=$this->db->lasterror();
@@ -257,15 +295,20 @@  discard block
 block discarded – undo
257 295
 				{
258 296
 					if ($notifcode)
259 297
 					{
260
-						if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
261
-					}
262
-					else
298
+						if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
299
+						    continue;
300
+						}
301
+					} else
263 302
 					{
264
-						if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
303
+						if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
304
+						    continue;
305
+						}
265 306
 					}
266 307
 
267 308
 					$threshold = (float) $reg[1];
268
-					if ($valueforthreshold < $threshold) continue;
309
+					if ($valueforthreshold < $threshold) {
310
+					    continue;
311
+					}
269 312
 
270 313
 					$tmpemail=explode(',',$val);
271 314
 					foreach($tmpemail as $key2 => $val2)
@@ -277,22 +320,30 @@  discard block
 block discarded – undo
277 320
 							{
278 321
 								$tmpuser=new User($this->db);
279 322
 								$tmpuser->fetch($user->fk_user);
280
-								if ($tmpuser->email) $newval2=trim($tmpuser->email);
281
-								else $newval2='';
323
+								if ($tmpuser->email) {
324
+								    $newval2=trim($tmpuser->email);
325
+								} else {
326
+								    $newval2='';
327
+								}
328
+							} else {
329
+							    $newval2='';
282 330
 							}
283
-							else $newval2='';
284 331
 						}
285 332
 						if ($newval2)
286 333
 						{
287 334
 							$isvalid=isValidEmail($newval2, 0);
288
-							if (empty($resarray[$newval2])) $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid);
335
+							if (empty($resarray[$newval2])) {
336
+							    $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid);
337
+							}
289 338
 						}
290 339
 					}
291 340
 				}
292 341
 			}
293 342
 		}
294 343
 
295
-		if ($error) return -1;
344
+		if ($error) {
345
+		    return -1;
346
+		}
296 347
 
297 348
 		//var_dump($resarray);
298 349
 		return $resarray;
@@ -315,7 +366,9 @@  discard block
 block discarded – undo
315 366
 		global $hookmanager;
316 367
 		global $dolibarr_main_url_root;
317 368
 
318
-		if (! in_array($notifcode, $this->arrayofnotifsupported)) return 0;
369
+		if (! in_array($notifcode, $this->arrayofnotifsupported)) {
370
+		    return 0;
371
+		}
319 372
 
320 373
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
321 374
 		if (! is_object($hookmanager))
@@ -336,7 +389,9 @@  discard block
 block discarded – undo
336 389
 
337 390
 		// Define some vars
338 391
 		$application = 'Dolibarr';
339
-		if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE;
392
+		if (! empty($conf->global->MAIN_APPLICATION_TITLE)) {
393
+		    $application = $conf->global->MAIN_APPLICATION_TITLE;
394
+		}
340 395
 		$replyto = $conf->notification->email_from;
341 396
 		$object_type = '';
342 397
 		$link = '';
@@ -358,8 +413,14 @@  discard block
 block discarded – undo
358 413
 			$sql.= " ".MAIN_DB_PREFIX."societe as s";
359 414
 			$sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
360 415
 			$sql.= " AND n.fk_soc = s.rowid";
361
-			if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
362
-			else $sql.= " AND a.code = '".$notifcode."'";	// New usage
416
+			if (is_numeric($notifcode)) {
417
+			    $sql.= " AND n.fk_action = ".$notifcode;
418
+			}
419
+			// Old usage
420
+			else {
421
+			    $sql.= " AND a.code = '".$notifcode."'";
422
+			}
423
+			// New usage
363 424
 			$sql .= " AND s.rowid = ".$object->socid;
364 425
 
365 426
 			$sql.= "\nUNION\n";
@@ -372,8 +433,14 @@  discard block
 block discarded – undo
372 433
 		$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,";
373 434
 		$sql.= " ".MAIN_DB_PREFIX."notify_def as n";
374 435
 		$sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action";
375
-		if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode;	// Old usage
376
-		else $sql.= " AND a.code = '".$this->db->escape($notifcode)."'";	// New usage
436
+		if (is_numeric($notifcode)) {
437
+		    $sql.= " AND n.fk_action = ".$notifcode;
438
+		}
439
+		// Old usage
440
+		else {
441
+		    $sql.= " AND a.code = '".$this->db->escape($notifcode)."'";
442
+		}
443
+		// New usage
377 444
 
378 445
 		$result = $this->db->query($sql);
379 446
 		if ($result)
@@ -391,9 +458,11 @@  discard block
 block discarded – undo
391 458
 			if ($num > 0)
392 459
 			{
393 460
 				$i = 0;
394
-				while ($i < $num && ! $error)	// For each notification couple defined (third party/actioncode)
461
+				while ($i < $num && ! $error) {
462
+				    // For each notification couple defined (third party/actioncode)
395 463
 				{
396 464
 					$obj = $this->db->fetch_object($result);
465
+				}
397 466
 
398 467
 					$sendto = dolGetFirstLastname($obj->firstname,$obj->lastname) . " <".$obj->email.">";
399 468
 					$notifcodedefid = $obj->adid;
@@ -510,8 +579,7 @@  discard block
 block discarded – undo
510 579
 						{
511 580
 							// We can't add PDF as it is not generated yet.
512 581
 							$filepdf = '';
513
-						}
514
-						else
582
+						} else
515 583
 						{
516 584
 							$filepdf = $pdf_path;
517 585
 						}
@@ -520,14 +588,20 @@  discard block
 block discarded – undo
520 588
 						$message.= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
521 589
 						$message.= "\n";
522 590
 						$message.= $mesg;
523
-						if ($link) $message.= "\n" . $urlwithroot . $link;
591
+						if ($link) {
592
+						    $message.= "\n" . $urlwithroot . $link;
593
+						}
524 594
 
525 595
 						$parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list);
526 596
 						$reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
527 597
 						if (empty($reshook))
528 598
 						{
529
-							if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
530
-							if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
599
+							if (! empty($hookmanager->resArray['subject'])) {
600
+							    $subject.=$hookmanager->resArray['subject'];
601
+							}
602
+							if (! empty($hookmanager->resArray['message'])) {
603
+							    $message.=$hookmanager->resArray['message'];
604
+							}
531 605
 						}
532 606
 
533 607
 						$mailfile = new CMailFile(
@@ -549,8 +623,7 @@  discard block
 block discarded – undo
549 623
 							if ($obj->type_target == 'touserid') {
550 624
 	 							$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)";
551 625
 								$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')";
552
-							}
553
-							else {
626
+							} else {
554 627
 								$sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)";
555 628
 								$sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')";
556 629
 							}
@@ -558,26 +631,22 @@  discard block
 block discarded – undo
558 631
 							{
559 632
 								dol_print_error($this->db);
560 633
 							}
561
-						}
562
-						else
634
+						} else
563 635
 						{
564 636
 							$error++;
565 637
 							$this->errors[]=$mailfile->error;
566 638
 						}
567
-					}
568
-					else
639
+					} else
569 640
 				  {
570 641
 						dol_syslog("No notification sent for ".$sendto." because email is empty");
571 642
 					}
572 643
 					$i++;
573 644
 				}
574
-			}
575
-			else
645
+			} else
576 646
 			{
577 647
 				dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".$object->socid);
578 648
 			}
579
-		}
580
-		else
649
+		} else
581 650
 		{
582 651
 	   		$error++;
583 652
 			$this->errors[]=$this->db->lasterror();
@@ -590,7 +659,9 @@  discard block
 block discarded – undo
590 659
 		{
591 660
 			foreach($conf->global as $key => $val)
592 661
 			{
593
-				if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue;
662
+				if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) {
663
+				    continue;
664
+				}
594 665
 
595 666
 				$threshold = (float) $reg[1];
596 667
 				if (!empty($object->total_ht) && $object->total_ht <= $threshold)
@@ -603,7 +674,9 @@  discard block
 block discarded – undo
603 674
 
604 675
 				$sendto = $conf->global->$param;
605 676
 				$notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid');
606
-				if ($notifcodedefid <= 0) dol_print_error($this->db, 'Failed to get id from code');
677
+				if ($notifcodedefid <= 0) {
678
+				    dol_print_error($this->db, 'Failed to get id from code');
679
+				}
607 680
 
608 681
 				$object_type = '';
609 682
 				$link = '';
@@ -718,8 +791,7 @@  discard block
 block discarded – undo
718 791
 				{
719 792
 					// We can't add PDF as it is not generated yet.
720 793
 					$filepdf = '';
721
-				}
722
-				else
794
+				} else
723 795
 				{
724 796
 					$filepdf = $pdf_path;
725 797
 				}
@@ -740,7 +812,9 @@  discard block
 block discarded – undo
740 812
 					{
741 813
 						$supervisoruser=new User($this->db);
742 814
 						$supervisoruser->fetch($user->fk_user);
743
-						if ($supervisoruser->email) $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>');
815
+						if ($supervisoruser->email) {
816
+						    $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>');
817
+						}
744 818
 					}
745 819
 					dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval);
746 820
 					$sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto);
@@ -755,8 +829,12 @@  discard block
 block discarded – undo
755 829
 					$reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
756 830
 					if (empty($reshook))
757 831
 					{
758
-						if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
759
-						if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
832
+						if (! empty($hookmanager->resArray['subject'])) {
833
+						    $subject.=$hookmanager->resArray['subject'];
834
+						}
835
+						if (! empty($hookmanager->resArray['message'])) {
836
+						    $message.=$hookmanager->resArray['message'];
837
+						}
760 838
 					}
761 839
 					$mailfile = new CMailFile(
762 840
 						$subject,
@@ -780,8 +858,7 @@  discard block
 block discarded – undo
780 858
 						{
781 859
 							dol_print_error($this->db);
782 860
 						}
783
-					}
784
-					else
861
+					} else
785 862
 					{
786 863
 						$error++;
787 864
 						$this->errors[]=$mailfile->error;
@@ -790,7 +867,10 @@  discard block
 block discarded – undo
790 867
 			}
791 868
 		}
792 869
 
793
-		if (! $error) return $num;
794
-		else return -1 * $error;
870
+		if (! $error) {
871
+		    return $num;
872
+		} else {
873
+		    return -1 * $error;
874
+		}
795 875
 	}
796 876
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/dolgeoip.class.php 1 patch
Braces   +19 added lines, -13 removed lines patch added patch discarded remove patch
@@ -46,14 +46,16 @@  discard block
 block discarded – undo
46 46
 		if ($type == 'country')
47 47
 		{
48 48
 		    // geoip may have been already included with PEAR
49
-		    if (! function_exists('geoip_country_code_by_name')) $res=include_once GEOIP_PATH.'geoip.inc';
50
-		}
51
-		else if ($type == 'city')
49
+		    if (! function_exists('geoip_country_code_by_name')) {
50
+		        $res=include_once GEOIP_PATH.'geoip.inc';
51
+		    }
52
+		} else if ($type == 'city')
52 53
 		{
53 54
 		    // geoip may have been already included with PEAR
54
-		    if (! function_exists('geoip_country_code_by_name')) $res=include_once GEOIP_PATH.'geoipcity.inc';
55
-		}
56
-		else { print 'ErrorBadParameterInConstructor'; return 0; }
55
+		    if (! function_exists('geoip_country_code_by_name')) {
56
+		        $res=include_once GEOIP_PATH.'geoipcity.inc';
57
+		    }
58
+		} else { print 'ErrorBadParameterInConstructor'; return 0; }
57 59
 
58 60
 		// Here, function exists (embedded into PHP or exists because we made include)
59 61
 		if (empty($type) || empty($datfile))
@@ -73,8 +75,7 @@  discard block
 block discarded – undo
73 75
 		if (function_exists('geoip_open'))
74 76
 		{
75 77
 			$this->gi = geoip_open($datfile,GEOIP_STANDARD);
76
-		}
77
-		else
78
+		} else
78 79
 		{
79 80
 		    $this->gi = 'NOGI';    // We are using embedded php geoip functions
80 81
 		    //print 'function_exists(geoip_country_code_by_name))='.function_exists('geoip_country_code_by_name');
@@ -98,10 +99,11 @@  discard block
 block discarded – undo
98 99
 		{
99 100
 		    // geoip_country_code_by_addr does not exists
100 101
     		return strtolower(geoip_country_code_by_name($ip));
101
-		}
102
-		else
102
+		} else
103 103
 		{
104
-		    if (! function_exists('geoip_country_code_by_addr')) return strtolower(geoip_country_code_by_name($this->gi, $ip));
104
+		    if (! function_exists('geoip_country_code_by_addr')) {
105
+		        return strtolower(geoip_country_code_by_name($this->gi, $ip));
106
+		    }
105 107
 		    return strtolower(geoip_country_code_by_addr($this->gi, $ip));
106 108
 		}
107 109
 	}
@@ -128,7 +130,9 @@  discard block
 block discarded – undo
128 130
 	 */
129 131
 	function getVersion()
130 132
 	{
131
-	    if ($this->gi == 'NOGI') return geoip_database_info();
133
+	    if ($this->gi == 'NOGI') {
134
+	        return geoip_database_info();
135
+	    }
132 136
 		return 'Not available (not using PHP internal geo functions)';
133 137
 	}
134 138
 
@@ -139,9 +143,11 @@  discard block
 block discarded – undo
139 143
 	 */
140 144
 	function close()
141 145
 	{
142
-	    if (function_exists('geoip_close'))    // With some geoip with PEAR, geoip_close function may not exists
146
+	    if (function_exists('geoip_close')) {
147
+	        // With some geoip with PEAR, geoip_close function may not exists
143 148
 	    {
144 149
 	        geoip_close($this->gi);
145 150
 	    }
151
+	    }
146 152
 	}
147 153
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/stats.class.php 1 patch
Braces   +99 added lines, -53 removed lines patch added patch discarded remove patch
@@ -46,7 +46,9 @@  discard block
 block discarded – undo
46 46
 	{
47 47
 		global $conf,$user,$langs;
48 48
 
49
-	    if ($startyear > $endyear) return -1;
49
+	    if ($startyear > $endyear) {
50
+	        return -1;
51
+	    }
50 52
 
51 53
 		$datay=array();
52 54
 
@@ -71,19 +73,19 @@  discard block
 block discarded – undo
71 73
 				$foundintocache=1;
72 74
 
73 75
 				$this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$filedate;
74
-			}
75
-			else
76
+			} else
76 77
 			{
77 78
 				dol_syslog(get_class($this).'::'.__FUNCTION__." cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it.");
78 79
 			}
79 80
 		}
80 81
 		// Load file into $data
81
-		if ($foundintocache)    // Cache file found and is not too old
82
+		if ($foundintocache) {
83
+		    // Cache file found and is not too old
82 84
 		{
83 85
 			dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate.".");
84
-			$data = json_decode(file_get_contents($newpathofdestfile), true);
85 86
 		}
86
-		else
87
+			$data = json_decode(file_get_contents($newpathofdestfile), true);
88
+		} else
87 89
 		{
88 90
 			$year=$startyear;
89 91
 			while ($year <= $endyear)
@@ -110,11 +112,15 @@  discard block
 block discarded – undo
110 112
 		if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1))
111 113
 		{
112 114
 			dol_syslog(get_class($this).'::'.__FUNCTION__." save cache file ".$newpathofdestfile." onto disk.");
113
-			if (! dol_is_dir($conf->user->dir_temp)) dol_mkdir($conf->user->dir_temp);
115
+			if (! dol_is_dir($conf->user->dir_temp)) {
116
+			    dol_mkdir($conf->user->dir_temp);
117
+			}
114 118
 			$fp = fopen($newpathofdestfile, 'w');
115 119
 			fwrite($fp, json_encode($data));
116 120
 			fclose($fp);
117
-			if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
121
+			if (! empty($conf->global->MAIN_UMASK)) {
122
+			    $newmask=$conf->global->MAIN_UMASK;
123
+			}
118 124
 			@chmod($newpathofdestfile, octdec($newmask));
119 125
 
120 126
 			$this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$nowgmt;
@@ -140,7 +146,9 @@  discard block
 block discarded – undo
140 146
 	{
141 147
 		global $conf,$user,$langs;
142 148
 
143
-        if ($startyear > $endyear) return -1;
149
+        if ($startyear > $endyear) {
150
+            return -1;
151
+        }
144 152
 
145 153
         $datay=array();
146 154
 
@@ -165,20 +173,20 @@  discard block
 block discarded – undo
165 173
         		$foundintocache=1;
166 174
 
167 175
         		$this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$filedate;
168
-        	}
169
-        	else
176
+        	} else
170 177
         	{
171 178
         		dol_syslog(get_class($this).'::'.__FUNCTION__." cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it.");
172 179
         	}
173 180
         }
174 181
 
175 182
         // Load file into $data
176
-        if ($foundintocache)    // Cache file found and is not too old
183
+        if ($foundintocache) {
184
+            // Cache file found and is not too old
177 185
         {
178 186
         	dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate.".");
179
-        	$data = json_decode(file_get_contents($newpathofdestfile), true);
180 187
         }
181
-        else
188
+        	$data = json_decode(file_get_contents($newpathofdestfile), true);
189
+        } else
182 190
 		{
183 191
 			$year=$startyear;
184 192
 			while($year <= $endyear)
@@ -205,16 +213,21 @@  discard block
 block discarded – undo
205 213
 		if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1))
206 214
 		{
207 215
 			dol_syslog(get_class($this).'::'.__FUNCTION__." save cache file ".$newpathofdestfile." onto disk.");
208
-			if (! dol_is_dir($conf->user->dir_temp)) dol_mkdir($conf->user->dir_temp);
216
+			if (! dol_is_dir($conf->user->dir_temp)) {
217
+			    dol_mkdir($conf->user->dir_temp);
218
+			}
209 219
 			$fp = fopen($newpathofdestfile, 'w');
210 220
 			if ($fp)
211 221
 			{
212 222
 				fwrite($fp, json_encode($data));
213 223
 				fclose($fp);
214
-				if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
224
+				if (! empty($conf->global->MAIN_UMASK)) {
225
+				    $newmask=$conf->global->MAIN_UMASK;
226
+				}
215 227
 				@chmod($newpathofdestfile, octdec($newmask));
228
+			} else {
229
+			    dol_syslog("Failed to write cache file", LOG_ERR);
216 230
 			}
217
-			else dol_syslog("Failed to write cache file", LOG_ERR);
218 231
 			$this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$nowgmt;
219 232
 		}
220 233
 
@@ -230,7 +243,9 @@  discard block
 block discarded – undo
230 243
 	 */
231 244
 	function getAverageByMonthWithPrevYear($endyear,$startyear)
232 245
 	{
233
-        if ($startyear > $endyear) return -1;
246
+        if ($startyear > $endyear) {
247
+            return -1;
248
+        }
234 249
 
235 250
         $datay=array();
236 251
 
@@ -291,20 +306,20 @@  discard block
 block discarded – undo
291 306
         		$foundintocache=1;
292 307
 
293 308
         		$this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$filedate;
294
-        	}
295
-        	else
309
+        	} else
296 310
         	{
297 311
         		dol_syslog(get_class($this).'::'.__FUNCTION__." cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it.");
298 312
         	}
299 313
         }
300 314
 
301 315
         // Load file into $data
302
-        if ($foundintocache)    // Cache file found and is not too old
316
+        if ($foundintocache) {
317
+            // Cache file found and is not too old
303 318
         {
304 319
         	dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate.".");
305
-        	$data = json_decode(file_get_contents($newpathofdestfile), true);
306 320
         }
307
-        else
321
+        	$data = json_decode(file_get_contents($newpathofdestfile), true);
322
+        } else
308 323
 		{
309 324
 			$data=$this->getAllByProduct($year);
310 325
 			//					$data[$i][]=$datay[$year][$i][1];	// set yval for x=i
@@ -314,13 +329,17 @@  discard block
 block discarded – undo
314 329
 		if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1))
315 330
 		{
316 331
 			dol_syslog(get_class($this).'::'.__FUNCTION__." save cache file ".$newpathofdestfile." onto disk.");
317
-			if (! dol_is_dir($conf->user->dir_temp)) dol_mkdir($conf->user->dir_temp);
332
+			if (! dol_is_dir($conf->user->dir_temp)) {
333
+			    dol_mkdir($conf->user->dir_temp);
334
+			}
318 335
 			$fp = fopen($newpathofdestfile, 'w');
319 336
 			if ($fp)
320 337
 			{
321 338
 				fwrite($fp, json_encode($data));
322 339
 				fclose($fp);
323
-				if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
340
+				if (! empty($conf->global->MAIN_UMASK)) {
341
+				    $newmask=$conf->global->MAIN_UMASK;
342
+				}
324 343
 				@chmod($newpathofdestfile, octdec($newmask));
325 344
 			}
326 345
 			$this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$nowgmt;
@@ -356,8 +375,7 @@  discard block
 block discarded – undo
356 375
 				$i++;
357 376
 			}
358 377
 			$this->db->free($resql);
359
-		}
360
-		else {
378
+		} else {
361 379
 			dol_print_error($this->db);
362 380
 		}
363 381
 		return $result;
@@ -384,22 +402,29 @@  discard block
 block discarded – undo
384 402
 				$row = $this->db->fetch_object($resql);
385 403
 				$result[$i]['year'] = $row->year;
386 404
 				$result[$i]['nb'] = $row->nb;
387
-				if($i>0 && $row->nb) $result[$i-1]['nb_diff'] = ($result[$i-1]['nb'] - $row->nb) / $row->nb * 100;
405
+				if($i>0 && $row->nb) {
406
+				    $result[$i-1]['nb_diff'] = ($result[$i-1]['nb'] - $row->nb) / $row->nb * 100;
407
+				}
388 408
 				$result[$i]['total'] = $row->total;
389
-				if($i>0 && $row->total) $result[$i-1]['total_diff'] = ($result[$i-1]['total'] - $row->total) / $row->total * 100;
409
+				if($i>0 && $row->total) {
410
+				    $result[$i-1]['total_diff'] = ($result[$i-1]['total'] - $row->total) / $row->total * 100;
411
+				}
390 412
 				$result[$i]['avg'] = $row->avg;
391
-				if($i>0 && $row->avg) $result[$i-1]['avg_diff'] = ($result[$i-1]['avg'] - $row->avg) / $row->avg * 100;
413
+				if($i>0 && $row->avg) {
414
+				    $result[$i-1]['avg_diff'] = ($result[$i-1]['avg'] - $row->avg) / $row->avg * 100;
415
+				}
392 416
 				// For some $sql only
393 417
 				if (isset($row->weighted))
394 418
 				{
395 419
 				    $result[$i]['weighted'] = $row->weighted;
396
-				    if($i>0 && $row->weighted) $result[$i-1]['avg_weighted'] = ($result[$i-1]['weighted'] - $row->weighted) / $row->weighted * 100;
420
+				    if($i>0 && $row->weighted) {
421
+				        $result[$i-1]['avg_weighted'] = ($result[$i-1]['weighted'] - $row->weighted) / $row->weighted * 100;
422
+				    }
397 423
 				}
398 424
 				$i++;
399 425
 			}
400 426
 			$this->db->free($resql);
401
-		}
402
-		else {
427
+		} else {
403 428
 			dol_print_error($this->db);
404 429
 		}
405 430
 		return $result;
@@ -434,8 +459,7 @@  discard block
 block discarded – undo
434 459
 				$i++;
435 460
 			}
436 461
 			$this->db->free($resql);
437
-		}
438
-		else
462
+		} else
439 463
 		{
440 464
 			dol_print_error($this->db);
441 465
 		}
@@ -450,9 +474,13 @@  discard block
 block discarded – undo
450 474
 		for ($i = 1 ; $i < 13 ; $i++)
451 475
 		{
452 476
 			$month='unknown';
453
-			if ($format == 0) $month=$langs->transnoentitiesnoconv('MonthShort'.sprintf("%02d", $i));
454
-			elseif ($format == 1) $month=$i;
455
-			elseif ($format == 2) $month=$langs->transnoentitiesnoconv('MonthVeryShort'.sprintf("%02d", $i));
477
+			if ($format == 0) {
478
+			    $month=$langs->transnoentitiesnoconv('MonthShort'.sprintf("%02d", $i));
479
+			} elseif ($format == 1) {
480
+			    $month=$i;
481
+			} elseif ($format == 2) {
482
+			    $month=$langs->transnoentitiesnoconv('MonthVeryShort'.sprintf("%02d", $i));
483
+			}
456 484
 			//$month=dol_print_date(dol_mktime(12,0,0,$i,1,$year),($format?"%m":"%b"));
457 485
 			//$month=dol_substr($month,0,3);
458 486
 			$data[$i-1] = array($month, $res[$i]);
@@ -492,8 +520,9 @@  discard block
 block discarded – undo
492 520
 		  		$i++;
493 521
 		  	}
494 522
 		  	$this->db->free($resql);
495
-		}
496
-        else dol_print_error($this->db);
523
+		} else {
524
+            dol_print_error($this->db);
525
+        }
497 526
 
498 527
 		for ($i = 1 ; $i < 13 ; $i++)
499 528
 		{
@@ -505,9 +534,13 @@  discard block
 block discarded – undo
505 534
 		for ($i = 1 ; $i < 13 ; $i++)
506 535
 		{
507 536
 			$month='unknown';
508
-			if ($format == 0) $month=$langs->transnoentitiesnoconv('MonthShort'.sprintf("%02d", $i));
509
-			elseif ($format == 1) $month=$i;
510
-			elseif ($format == 2) $month=$langs->transnoentitiesnoconv('MonthVeryShort'.sprintf("%02d", $i));
537
+			if ($format == 0) {
538
+			    $month=$langs->transnoentitiesnoconv('MonthShort'.sprintf("%02d", $i));
539
+			} elseif ($format == 1) {
540
+			    $month=$i;
541
+			} elseif ($format == 2) {
542
+			    $month=$langs->transnoentitiesnoconv('MonthVeryShort'.sprintf("%02d", $i));
543
+			}
511 544
 			//$month=dol_print_date(dol_mktime(12,0,0,$i,1,$year),($format?"%m":"%b"));
512 545
 			//$month=dol_substr($month,0,3);
513 546
 			$data[$i-1] = array($month, $res[$i]);
@@ -545,8 +578,9 @@  discard block
 block discarded – undo
545 578
 		  		$i++;
546 579
 		  	}
547 580
 		  	$this->db->free($resql);
548
-		}
549
-        else dol_print_error($this->db);
581
+		} else {
582
+            dol_print_error($this->db);
583
+        }
550 584
 
551 585
 		for ($i = 1 ; $i < 13 ; $i++)
552 586
 		{
@@ -558,9 +592,13 @@  discard block
 block discarded – undo
558 592
 		for ($i = 1 ; $i < 13 ; $i++)
559 593
 		{
560 594
 			$month='unknown';
561
-			if ($format == 0) $month=$langs->transnoentitiesnoconv('MonthShort'.sprintf("%02d", $i));
562
-			elseif ($format == 1) $month=$i;
563
-			elseif ($format == 2) $month=$langs->transnoentitiesnoconv('MonthVeryShort'.sprintf("%02d", $i));
595
+			if ($format == 0) {
596
+			    $month=$langs->transnoentitiesnoconv('MonthShort'.sprintf("%02d", $i));
597
+			} elseif ($format == 1) {
598
+			    $month=$i;
599
+			} elseif ($format == 2) {
600
+			    $month=$langs->transnoentitiesnoconv('MonthVeryShort'.sprintf("%02d", $i));
601
+			}
564 602
 			//$month=dol_print_date(dol_mktime(12,0,0,$i,1,$year),($format?"%m":"%b"));
565 603
 			//$month=dol_substr($month,0,3);
566 604
 			$data[$i-1] = array($month, $res[$i]);
@@ -593,14 +631,22 @@  discard block
 block discarded – undo
593 631
 			while ($i < $num)
594 632
 			{
595 633
 		  		$row = $this->db->fetch_row($resql);
596
-		  		if ($i < $limit || $num == $limit) $result[$i] = array($row[0],$row[1]);	// Ref of product, nb
597
-		  		else $other += $row[1];
634
+		  		if ($i < $limit || $num == $limit) {
635
+		  		    $result[$i] = array($row[0],$row[1]);
636
+		  		}
637
+		  		// Ref of product, nb
638
+		  		else {
639
+		  		    $other += $row[1];
640
+		  		}
598 641
 		  		$i++;
599 642
 		  	}
600
-		  	if ($num > $limit) $result[$i] = array($langs->transnoentitiesnoconv("Other"),$other);
643
+		  	if ($num > $limit) {
644
+		  	    $result[$i] = array($langs->transnoentitiesnoconv("Other"),$other);
645
+		  	}
601 646
 		  	$this->db->free($resql);
602
-		}
603
-        else dol_print_error($this->db);
647
+		} else {
648
+            dol_print_error($this->db);
649
+        }
604 650
 
605 651
 		return $result;
606 652
 	}
Please login to merge, or discard this patch.