Passed
Branch develop (3e586d)
by
unknown
31:25
created
htdocs/core/lib/functions.lib.php 2 patches
Braces   +1692 added lines, -594 removed lines patch added patch discarded remove patch
@@ -87,7 +87,9 @@  discard block
 block discarded – undo
87 87
 	} else {
88 88
 		$out = '';
89 89
 		$addzero = array('user', 'usergroup', 'c_email_templates', 'email_template', 'default_values');
90
-		if (in_array($element, $addzero)) $out .= '0,';
90
+		if (in_array($element, $addzero)) {
91
+			$out .= '0,';
92
+		}
91 93
 		$out .= $conf->entity;
92 94
 		return $out;
93 95
 	}
@@ -216,7 +218,9 @@  discard block
 block discarded – undo
216 218
 
217 219
 	$relativepathstring = $_SERVER["PHP_SELF"];
218 220
 	// Clean $relativepathstring
219
-	if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'), '/').'/', '', $relativepathstring);
221
+	if (constant('DOL_URL_ROOT')) {
222
+		$relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'), '/').'/', '', $relativepathstring);
223
+	}
220 224
 	$relativepathstring = preg_replace('/^\//', '', $relativepathstring);
221 225
 	$relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
222 226
 	//var_dump($relativepathstring);
@@ -224,18 +228,22 @@  discard block
 block discarded – undo
224 228
 
225 229
 	// Code for search criteria persistence.
226 230
 	// Retrieve values if restore_lastsearch_values
227
-	if (!empty($_GET['restore_lastsearch_values']))        // Use $_GET here and not GETPOST
231
+	if (!empty($_GET['restore_lastsearch_values'])) {
232
+		// Use $_GET here and not GETPOST
228 233
 	{
229 234
 		if (!empty($_SESSION['lastsearch_values_'.$relativepathstring]))	// If there is saved values
230 235
 		{
231 236
 			$tmp = json_decode($_SESSION['lastsearch_values_'.$relativepathstring], true);
237
+	}
232 238
 			if (is_array($tmp))
233 239
 			{
234 240
 				foreach ($tmp as $key => $val)
235 241
 				{
236
-					if ($key == $paramname)	// We are on the requested parameter
242
+					if ($key == $paramname) {
243
+						// We are on the requested parameter
237 244
 					{
238 245
 						$isset = 1;
246
+					}
239 247
 						break;
240 248
 					}
241 249
 				}
@@ -288,7 +296,9 @@  discard block
 block discarded – undo
288 296
 {
289 297
 	global $mysoc, $user, $conf;
290 298
 
291
-	if (empty($paramname)) return 'BadFirstParameterForGETPOST';
299
+	if (empty($paramname)) {
300
+		return 'BadFirstParameterForGETPOST';
301
+	}
292 302
 	if (empty($check))
293 303
 	{
294 304
 		dol_syslog("Deprecated use of GETPOST, called with 1st param = ".$paramname." and 2nd param is '', when calling page ".$_SERVER["PHP_SELF"], LOG_WARNING);
@@ -296,17 +306,25 @@  discard block
 block discarded – undo
296 306
 		//var_dump(debug_backtrace()[0]);
297 307
 	}
298 308
 
299
-	if (empty($method)) $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] : '');
300
-	elseif ($method == 1) $out = isset($_GET[$paramname]) ? $_GET[$paramname] : '';
301
-	elseif ($method == 2) $out = isset($_POST[$paramname]) ? $_POST[$paramname] : '';
302
-	elseif ($method == 3) $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] : '');
303
-	else return 'BadThirdParameterForGETPOST';
309
+	if (empty($method)) {
310
+		$out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] : '');
311
+	} elseif ($method == 1) {
312
+		$out = isset($_GET[$paramname]) ? $_GET[$paramname] : '';
313
+	} elseif ($method == 2) {
314
+		$out = isset($_POST[$paramname]) ? $_POST[$paramname] : '';
315
+	} elseif ($method == 3) {
316
+		$out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] : '');
317
+	} else {
318
+		return 'BadThirdParameterForGETPOST';
319
+	}
304 320
 
305 321
 	if (empty($method) || $method == 3 || $method == 4)
306 322
 	{
307 323
 		$relativepathstring = $_SERVER["PHP_SELF"];
308 324
 		// Clean $relativepathstring
309
-		if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'), '/').'/', '', $relativepathstring);
325
+		if (constant('DOL_URL_ROOT')) {
326
+			$relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'), '/').'/', '', $relativepathstring);
327
+		}
310 328
 		$relativepathstring = preg_replace('/^\//', '', $relativepathstring);
311 329
 		$relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
312 330
 		//var_dump($relativepathstring);
@@ -314,18 +332,22 @@  discard block
 block discarded – undo
314 332
 
315 333
 		// Code for search criteria persistence.
316 334
 		// Retrieve values if restore_lastsearch_values
317
-		if (!empty($_GET['restore_lastsearch_values']))        // Use $_GET here and not GETPOST
335
+		if (!empty($_GET['restore_lastsearch_values'])) {
336
+			// Use $_GET here and not GETPOST
318 337
 		{
319 338
 			if (!empty($_SESSION['lastsearch_values_'.$relativepathstring]))	// If there is saved values
320 339
 			{
321 340
 				$tmp = json_decode($_SESSION['lastsearch_values_'.$relativepathstring], true);
341
+		}
322 342
 				if (is_array($tmp))
323 343
 				{
324 344
 					foreach ($tmp as $key => $val)
325 345
 					{
326
-						if ($key == $paramname)	// We are on the requested parameter
346
+						if ($key == $paramname) {
347
+							// We are on the requested parameter
327 348
 						{
328 349
 							$out = $val;
350
+						}
329 351
 							break;
330 352
 						}
331 353
 					}
@@ -343,12 +365,14 @@  discard block
 block discarded – undo
343 365
 				$out = $_SESSION['lastsearch_limit_'.$relativepathstring];
344 366
 			}
345 367
 		} // Else, retreive default values if we are not doing a sort
346
-		elseif (!isset($_GET['sortfield']))	// If we did a click on a field to sort, we do no apply default values. Same if option MAIN_ENABLE_DEFAULT_VALUES is not set
368
+		elseif (!isset($_GET['sortfield'])) {
369
+			// If we did a click on a field to sort, we do no apply default values. Same if option MAIN_ENABLE_DEFAULT_VALUES is not set
347 370
 		{
348 371
 			if (!empty($_GET['action']) && $_GET['action'] == 'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname]))
349 372
 			{
350 373
 				// Search default value from $object->field
351 374
 				global $object;
375
+		}
352 376
 				if (is_object($object) && isset($object->fields[$paramname]['default']))
353 377
 				{
354 378
 					$out = $object->fields[$paramname]['default'];
@@ -359,13 +383,15 @@  discard block
 block discarded – undo
359 383
 			    if (!empty($_GET['action']) && (preg_match('/^create/', $_GET['action']) || preg_match('/^presend/', $_GET['action'])) && !isset($_GET[$paramname]) && !isset($_POST[$paramname]))
360 384
 				{
361 385
 					// Now search in setup to overwrite default values
362
-					if (!empty($user->default_values))		// $user->default_values defined from menu 'Setup - Default values'
386
+					if (!empty($user->default_values)) {
387
+						// $user->default_values defined from menu 'Setup - Default values'
363 388
 					{
364 389
 						if (isset($user->default_values[$relativepathstring]['createform']))
365 390
 						{
366 391
 							foreach ($user->default_values[$relativepathstring]['createform'] as $defkey => $defval)
367 392
 							{
368 393
 								$qualified = 0;
394
+					}
369 395
 								if ($defkey != '_noquery_')
370 396
 								{
371 397
 									$tmpqueryarraytohave = explode('&', $defkey);
@@ -373,11 +399,17 @@  discard block
 block discarded – undo
373 399
 									$foundintru = 0;
374 400
 									foreach ($tmpqueryarraytohave as $tmpquerytohave)
375 401
 									{
376
-										if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) $foundintru = 1;
402
+										if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
403
+											$foundintru = 1;
404
+										}
405
+									}
406
+									if (!$foundintru) {
407
+										$qualified = 1;
377 408
 									}
378
-									if (!$foundintru) $qualified = 1;
379 409
 									//var_dump($defkey.'-'.$qualified);
380
-								} else $qualified = 1;
410
+								} else {
411
+									$qualified = 1;
412
+								}
381 413
 
382 414
 								if ($qualified)
383 415
 								{
@@ -395,7 +427,8 @@  discard block
 block discarded – undo
395 427
 				//elseif (preg_match('/list.php$/', $_SERVER["PHP_SELF"]) && ! empty($paramname) && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
396 428
 				elseif (!empty($paramname) && !isset($_GET[$paramname]) && !isset($_POST[$paramname]))
397 429
 				{
398
-					if (!empty($user->default_values))		// $user->default_values defined from menu 'Setup - Default values'
430
+					if (!empty($user->default_values)) {
431
+						// $user->default_values defined from menu 'Setup - Default values'
399 432
 					{
400 433
 						//var_dump($user->default_values[$relativepathstring]);
401 434
 						if ($paramname == 'sortfield' || $paramname == 'sortorder')			// Sorted on which fields ? ASC or DESC ?
@@ -405,6 +438,7 @@  discard block
 block discarded – undo
405 438
 								foreach ($user->default_values[$relativepathstring]['sortorder'] as $defkey => $defval)
406 439
 								{
407 440
 									$qualified = 0;
441
+					}
408 442
 									if ($defkey != '_noquery_')
409 443
 									{
410 444
 										$tmpqueryarraytohave = explode('&', $defkey);
@@ -412,18 +446,26 @@  discard block
 block discarded – undo
412 446
 										$foundintru = 0;
413 447
 										foreach ($tmpqueryarraytohave as $tmpquerytohave)
414 448
 										{
415
-											if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) $foundintru = 1;
449
+											if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
450
+												$foundintru = 1;
451
+											}
452
+										}
453
+										if (!$foundintru) {
454
+											$qualified = 1;
416 455
 										}
417
-										if (!$foundintru) $qualified = 1;
418 456
 										//var_dump($defkey.'-'.$qualified);
419
-									} else $qualified = 1;
457
+									} else {
458
+										$qualified = 1;
459
+									}
420 460
 
421 461
 									if ($qualified)
422 462
 									{
423 463
 										$forbidden_chars_to_replace = array(" ", "'", "/", "\\", ":", "*", "?", "\"", "<", ">", "|", "[", "]", ";", "="); // we accept _, -, . and ,
424 464
 										foreach ($user->default_values[$relativepathstring]['sortorder'][$defkey] as $key => $val)
425 465
 										{
426
-											if ($out) $out .= ', ';
466
+											if ($out) {
467
+												$out .= ', ';
468
+											}
427 469
 											if ($paramname == 'sortfield')
428 470
 											{
429 471
 												$out .= dol_string_nospecial($key, '', $forbidden_chars_to_replace);
@@ -439,9 +481,11 @@  discard block
 block discarded – undo
439 481
 							}
440 482
 						} elseif (isset($user->default_values[$relativepathstring]['filters']))
441 483
 						{
442
-							foreach ($user->default_values[$relativepathstring]['filters'] as $defkey => $defval)	// $defkey is a querystring like 'a=b&c=d', $defval is key of user
484
+							foreach ($user->default_values[$relativepathstring]['filters'] as $defkey => $defval) {
485
+								// $defkey is a querystring like 'a=b&c=d', $defval is key of user
443 486
 							{
444 487
 								$qualified = 0;
488
+							}
445 489
 								if ($defkey != '_noquery_')
446 490
 								{
447 491
 									$tmpqueryarraytohave = explode('&', $defkey);
@@ -449,11 +493,17 @@  discard block
 block discarded – undo
449 493
 									$foundintru = 0;
450 494
 									foreach ($tmpqueryarraytohave as $tmpquerytohave)
451 495
 									{
452
-										if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) $foundintru = 1;
496
+										if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
497
+											$foundintru = 1;
498
+										}
499
+									}
500
+									if (!$foundintru) {
501
+										$qualified = 1;
453 502
 									}
454
-									if (!$foundintru) $qualified = 1;
455 503
 									//var_dump($defkey.'-'.$qualified);
456
-								} else $qualified = 1;
504
+								} else {
505
+									$qualified = 1;
506
+								}
457 507
 
458 508
 								if ($qualified)
459 509
 								{
@@ -486,9 +536,12 @@  discard block
 block discarded – undo
486 536
 	{
487 537
 		$reg = array();
488 538
 		$maxloop = 20; $loopnb = 0; // Protection against infinite loop
489
-		while (preg_match('/__([A-Z0-9]+_?[A-Z0-9]+)__/i', $out, $reg) && ($loopnb < $maxloop))    // Detect '__ABCDEF__' as key 'ABCDEF' and '__ABC_DEF__' as key 'ABC_DEF'. Detection is also correct when 2 vars are side by side.
539
+		while (preg_match('/__([A-Z0-9]+_?[A-Z0-9]+)__/i', $out, $reg) && ($loopnb < $maxloop)) {
540
+			// Detect '__ABCDEF__' as key 'ABCDEF' and '__ABC_DEF__' as key 'ABC_DEF'. Detection is also correct when 2 vars are side by side.
490 541
 		{
491
-			$loopnb++; $newout = '';
542
+			$loopnb++;
543
+		}
544
+		$newout = '';
492 545
 
493 546
 			if ($reg[1] == 'DAY') {
494 547
 				$tmp = dol_getdate(dol_now(), true);
@@ -546,7 +599,9 @@  discard block
 block discarded – undo
546 599
 			if (!is_numeric($out)) { $out = ''; }
547 600
 			break;
548 601
 		case 'intcomma':
549
-			if (preg_match('/[^0-9,-]+/i', $out)) $out = '';
602
+			if (preg_match('/[^0-9,-]+/i', $out)) {
603
+				$out = '';
604
+			}
550 605
 			break;
551 606
 		case 'alpha':
552 607
 			if (!is_array($out)) {
@@ -562,25 +617,33 @@  discard block
 block discarded – undo
562 617
 			if (!is_array($out))
563 618
 			{
564 619
 				$out = trim($out);
565
-				if (preg_match('/[^a-z]+/i', $out)) $out = '';
620
+				if (preg_match('/[^a-z]+/i', $out)) {
621
+					$out = '';
622
+				}
566 623
 			}
567 624
 			break;
568 625
 		case 'aZ09':
569 626
 			if (!is_array($out))
570 627
 			{
571 628
 				$out = trim($out);
572
-				if (preg_match('/[^a-z0-9_\-\.]+/i', $out)) $out = '';
629
+				if (preg_match('/[^a-z0-9_\-\.]+/i', $out)) {
630
+					$out = '';
631
+				}
573 632
 			}
574 633
 			break;
575 634
 		case 'aZ09comma':		// great to sanitize sortfield or sortorder params that can be t.abc,t.def_gh
576 635
 			if (!is_array($out))
577 636
 			{
578 637
 				$out = trim($out);
579
-				if (preg_match('/[^a-z0-9_\-\.,]+/i', $out)) $out = '';
638
+				if (preg_match('/[^a-z0-9_\-\.,]+/i', $out)) {
639
+					$out = '';
640
+				}
580 641
 			}
581 642
 			break;
582 643
 		case 'array':
583
-			if (!is_array($out) || empty($out)) $out = array();
644
+			if (!is_array($out) || empty($out)) {
645
+				$out = array();
646
+			}
584 647
 			break;
585 648
 		case 'nohtml':
586 649
 			$out = dol_string_nohtmltag($out, 0);
@@ -598,7 +661,9 @@  discard block
 block discarded – undo
598 661
 			$out = dol_string_onlythesehtmltags($out, 0);
599 662
 			break;
600 663
 		case 'custom':
601
-			if (empty($filter)) return 'BadFourthParameterForGETPOST';
664
+			if (empty($filter)) {
665
+				return 'BadFourthParameterForGETPOST';
666
+			}
602 667
 			$out = filter_var($out, $filter, $options);
603 668
 			break;
604 669
 	}
@@ -615,10 +680,12 @@  discard block
 block discarded – undo
615 680
 			// - posted value not empty, or
616 681
 			// - if posted value is empty and a default value exists that is not empty (it means we did a filter to an empty value when default was not).
617 682
 
618
-			if ($out != '')		// $out = '0' or 'abc', it is a search criteria to keep
683
+			if ($out != '') {
684
+				// $out = '0' or 'abc', it is a search criteria to keep
619 685
 			{
620 686
 				$user->lastsearch_values_tmp[$relativepathstring][$paramname] = $out;
621 687
 			}
688
+			}
622 689
 		}
623 690
 	}
624 691
 
@@ -643,21 +710,28 @@  discard block
 block discarded – undo
643 710
 		// If prefix is for email
644 711
 		if ($mode == 'email')
645 712
 		{
646
-		    if (!empty($conf->global->MAIL_PREFIX_FOR_EMAIL_ID))	// If MAIL_PREFIX_FOR_EMAIL_ID is set (a value initialized with a random value is recommended)
713
+		    if (!empty($conf->global->MAIL_PREFIX_FOR_EMAIL_ID)) {
714
+		    	// If MAIL_PREFIX_FOR_EMAIL_ID is set (a value initialized with a random value is recommended)
647 715
 			{
648 716
 				if ($conf->global->MAIL_PREFIX_FOR_EMAIL_ID != 'SERVER_NAME') return $conf->global->MAIL_PREFIX_FOR_EMAIL_ID;
649
-				elseif (isset($_SERVER["SERVER_NAME"])) return $_SERVER["SERVER_NAME"];
717
+		    } elseif (isset($_SERVER["SERVER_NAME"])) {
718
+					return $_SERVER["SERVER_NAME"];
719
+				}
650 720
 			}
651 721
 
652 722
 			// The recommended value (may be not defined for old versions)
653
-			if (!empty($conf->file->instance_unique_id)) return $conf->file->instance_unique_id;
723
+			if (!empty($conf->file->instance_unique_id)) {
724
+				return $conf->file->instance_unique_id;
725
+			}
654 726
 
655 727
 			// For backward compatibility
656 728
 			return dol_hash(DOL_DOCUMENT_ROOT.DOL_URL_ROOT, '3');
657 729
 		}
658 730
 
659 731
 		// The recommended value (may be not defined for old versions)
660
-		if (!empty($conf->file->instance_unique_id)) return $conf->file->instance_unique_id;
732
+		if (!empty($conf->file->instance_unique_id)) {
733
+			return $conf->file->instance_unique_id;
734
+		}
661 735
 
662 736
 		// For backward compatibility
663 737
 		if (isset($_SERVER["SERVER_NAME"]) && isset($_SERVER["DOCUMENT_ROOT"]))
@@ -714,16 +788,21 @@  discard block
 block discarded – undo
714 788
 
715 789
 	$path = preg_replace('/^\//', '', $path);
716 790
 
717
-	if (empty($type))	// For a filesystem path
791
+	if (empty($type)) {
792
+		// For a filesystem path
718 793
 	{
719
-		$res = DOL_DOCUMENT_ROOT.'/'.$path; // Standard default path
794
+		$res = DOL_DOCUMENT_ROOT.'/'.$path;
795
+	}
796
+	// Standard default path
720 797
 		if (is_array($conf->file->dol_document_root))
721 798
 		{
722
-			foreach ($conf->file->dol_document_root as $key => $dirroot)	// ex: array("main"=>"/home/main/htdocs", "alt0"=>"/home/dirmod/htdocs", ...)
799
+			foreach ($conf->file->dol_document_root as $key => $dirroot) {
800
+				// ex: array("main"=>"/home/main/htdocs", "alt0"=>"/home/dirmod/htdocs", ...)
723 801
 			{
724 802
 				if ($key == 'main')
725 803
 				{
726 804
 					continue;
805
+			}
727 806
 				}
728 807
 				if (file_exists($dirroot.'/'.$path))
729 808
 				{
@@ -732,10 +811,12 @@  discard block
 block discarded – undo
732 811
 				}
733 812
 			}
734 813
 		}
735
-		if ($returnemptyifnotfound)								// Not found into alternate dir
814
+		if ($returnemptyifnotfound) {
815
+			// Not found into alternate dir
736 816
 		{
737 817
 			if ($returnemptyifnotfound == 1 || !file_exists($res)) return '';
738 818
 		}
819
+		}
739 820
 	} else // For an url path
740 821
 	{
741 822
 		// We try to get local path of file on filesystem from url
@@ -743,17 +824,27 @@  discard block
 block discarded – undo
743 824
 		// works only for some web server and some setup. This is bugged when
744 825
 		// using proxy, rewriting, virtual path, etc...
745 826
 		$res = '';
746
-		if ($type == 1) $res = DOL_URL_ROOT.'/'.$path; // Standard value
747
-		if ($type == 2) $res = DOL_MAIN_URL_ROOT.'/'.$path; // Standard value
748
-		if ($type == 3) $res = DOL_URL_ROOT.'/'.$path;
827
+		if ($type == 1) {
828
+			$res = DOL_URL_ROOT.'/'.$path;
829
+		}
830
+		// Standard value
831
+		if ($type == 2) {
832
+			$res = DOL_MAIN_URL_ROOT.'/'.$path;
833
+		}
834
+		// Standard value
835
+		if ($type == 3) {
836
+			$res = DOL_URL_ROOT.'/'.$path;
837
+		}
749 838
 
750
-		foreach ($conf->file->dol_document_root as $key => $dirroot)	// ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
839
+		foreach ($conf->file->dol_document_root as $key => $dirroot) {
840
+			// ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
751 841
 		{
752 842
 			if ($key == 'main')
753 843
 			{
754 844
 				if ($type == 3)
755 845
 				{
756 846
 					global $dolibarr_main_url_root;
847
+		}
757 848
 
758 849
 					// Define $urlwithroot
759 850
 					$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
@@ -832,10 +923,15 @@  discard block
 block discarded – undo
832 923
 function dol_size($size, $type = '')
833 924
 {
834 925
 	global $conf;
835
-	if (empty($conf->dol_optimize_smallscreen)) return $size;
836
-	if ($type == 'width' && $size > 250) return 250;
837
-	else return 10;
838
-}
926
+	if (empty($conf->dol_optimize_smallscreen)) {
927
+		return $size;
928
+	}
929
+	if ($type == 'width' && $size > 250) {
930
+		return 250;
931
+	} else {
932
+		return 10;
933
+	}
934
+	}
839 935
 
840 936
 
841 937
 /**
@@ -941,7 +1037,9 @@  discard block
 block discarded – undo
941 1037
 {
942 1038
 	$forbidden_chars_to_replace = array(" ", "'", "/", "\\", ":", "*", "?", "\"", "<", ">", "|", "[", "]", ",", ";", "=", '°'); // more complete than dol_sanitizeFileName
943 1039
 	$forbidden_chars_to_remove = array();
944
-	if (is_array($badcharstoreplace)) $forbidden_chars_to_replace = $badcharstoreplace;
1040
+	if (is_array($badcharstoreplace)) {
1041
+		$forbidden_chars_to_replace = $badcharstoreplace;
1042
+	}
945 1043
 	//$forbidden_chars_to_remove=array("(",")");
946 1044
 
947 1045
 	return str_replace($forbidden_chars_to_replace, $newstr, str_replace($forbidden_chars_to_remove, "", $str));
@@ -962,8 +1060,9 @@  discard block
 block discarded – undo
962 1060
 	$substitjs = array("&#039;"=>"\\'", "\r"=>'\\r');
963 1061
 	//$substitjs['</']='<\/';	// We removed this. Should be useless.
964 1062
 	if (empty($noescapebackslashn)) { $substitjs["\n"] = '\\n'; $substitjs['\\'] = '\\\\'; }
965
-	if (empty($mode)) { $substitjs["'"] = "\\'"; $substitjs['"'] = "\\'"; } elseif ($mode == 1) $substitjs["'"] = "\\'";
966
-	elseif ($mode == 2) { $substitjs['"'] = '\\"'; } elseif ($mode == 3) { $substitjs["'"] = "\\'"; $substitjs['"'] = "\\\""; }
1063
+	if (empty($mode)) { $substitjs["'"] = "\\'"; $substitjs['"'] = "\\'"; } elseif ($mode == 1) {
1064
+		$substitjs["'"] = "\\'";
1065
+	} elseif ($mode == 2) { $substitjs['"'] = '\\"'; } elseif ($mode == 3) { $substitjs["'"] = "\\'"; $substitjs['"'] = "\\\""; }
967 1066
 	return strtr($stringtoescape, $substitjs);
968 1067
 }
969 1068
 
@@ -991,7 +1090,9 @@  discard block
 block discarded – undo
991 1090
  */
992 1091
 function dol_escape_htmltag($stringtoescape, $keepb = 0, $keepn = 0, $keepmoretags = '', $escapeonlyhtmltags = 0)
993 1092
 {
994
-	if ($keepmoretags == 'common') $keepmoretags = 'html,body,a,em,i,u,ul,li,br,div,img,font,p,span,strong,table,tr,td,th,tbody';
1093
+	if ($keepmoretags == 'common') {
1094
+		$keepmoretags = 'html,body,a,em,i,u,ul,li,br,div,img,font,p,span,strong,table,tr,td,th,tbody';
1095
+	}
995 1096
 	// TODO Implement $keepmoretags
996 1097
 
997 1098
 	// escape quotes and backslashes, newlines, etc.
@@ -1000,8 +1101,12 @@  discard block
 block discarded – undo
1000 1101
 	} else {
1001 1102
 		$tmp = html_entity_decode($stringtoescape, ENT_COMPAT, 'UTF-8');
1002 1103
 	}
1003
-	if (!$keepb) $tmp = strtr($tmp, array("<b>"=>'', '</b>'=>''));
1004
-	if (!$keepn) $tmp = strtr($tmp, array("\r"=>'\\r', "\n"=>'\\n'));
1104
+	if (!$keepb) {
1105
+		$tmp = strtr($tmp, array("<b>"=>'', '</b>'=>''));
1106
+	}
1107
+	if (!$keepn) {
1108
+		$tmp = strtr($tmp, array("\r"=>'\\r', "\n"=>'\\n'));
1109
+	}
1005 1110
 	if ($escapeonlyhtmltags) {
1006 1111
 		return htmlspecialchars($tmp, ENT_COMPAT, 'UTF-8');
1007 1112
 	} else {
@@ -1059,13 +1164,18 @@  discard block
 block discarded – undo
1059 1164
     global $conf, $user, $debugbar;
1060 1165
 
1061 1166
 	// If syslog module enabled
1062
-	if (empty($conf->syslog->enabled)) return;
1167
+	if (empty($conf->syslog->enabled)) {
1168
+		return;
1169
+	}
1063 1170
 
1064 1171
 	// Check if we are into execution of code of a website
1065 1172
 	if (defined('USEEXTERNALSERVER') && ! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) {
1066 1173
 		global $website, $websitekey;
1067
-		if (is_object($website) && ! empty($website->ref)) $suffixinfilename.='_website_'.$website->ref;
1068
-		elseif (! empty($websitekey)) $suffixinfilename.='_website_'.$websitekey;
1174
+		if (is_object($website) && ! empty($website->ref)) {
1175
+			$suffixinfilename.='_website_'.$website->ref;
1176
+		} elseif (! empty($websitekey)) {
1177
+			$suffixinfilename.='_website_'.$websitekey;
1178
+		}
1069 1179
 	}
1070 1180
 
1071 1181
 	if ($ident < 0)
@@ -1084,7 +1194,9 @@  discard block
 block discarded – undo
1084 1194
 		{
1085 1195
 			throw new Exception('Incorrect log level');
1086 1196
 		}
1087
-		if ($level > $conf->global->SYSLOG_LEVEL) return;
1197
+		if ($level > $conf->global->SYSLOG_LEVEL) {
1198
+			return;
1199
+		}
1088 1200
 
1089 1201
 		$message = preg_replace('/password=\'[^\']*\'/', 'password=\'hidden\'', $message); // protection to avoid to have value of password in log
1090 1202
 
@@ -1116,18 +1228,29 @@  discard block
 block discarded – undo
1116 1228
 		if (!empty($remoteip)) {
1117 1229
 			$data['ip'] = $remoteip;
1118 1230
 			// This is when server run behind a reverse proxy
1119
-			if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != $remoteip) $data['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'].' -> '.$data['ip'];
1120
-			elseif (!empty($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP'] != $remoteip) $data['ip'] = $_SERVER['HTTP_CLIENT_IP'].' -> '.$data['ip'];
1231
+			if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != $remoteip) {
1232
+				$data['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'].' -> '.$data['ip'];
1233
+			} elseif (!empty($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP'] != $remoteip) {
1234
+				$data['ip'] = $_SERVER['HTTP_CLIENT_IP'].' -> '.$data['ip'];
1235
+			}
1121 1236
 		} // This is when PHP session is ran inside a web server but not inside a client request (example: init code of apache)
1122
-		elseif (!empty($_SERVER['SERVER_ADDR'])) $data['ip'] = $_SERVER['SERVER_ADDR'];
1237
+		elseif (!empty($_SERVER['SERVER_ADDR'])) {
1238
+			$data['ip'] = $_SERVER['SERVER_ADDR'];
1239
+		}
1123 1240
 		// This is when PHP session is ran outside a web server, like from Windows command line (Not always defined, but useful if OS defined it).
1124
-		elseif (!empty($_SERVER['COMPUTERNAME'])) $data['ip'] = $_SERVER['COMPUTERNAME'].(empty($_SERVER['USERNAME']) ? '' : '@'.$_SERVER['USERNAME']);
1241
+		elseif (!empty($_SERVER['COMPUTERNAME'])) {
1242
+			$data['ip'] = $_SERVER['COMPUTERNAME'].(empty($_SERVER['USERNAME']) ? '' : '@'.$_SERVER['USERNAME']);
1243
+		}
1125 1244
 		// This is when PHP session is ran outside a web server, like from Linux command line (Not always defined, but usefull if OS defined it).
1126
-		elseif (!empty($_SERVER['LOGNAME'])) $data['ip'] = '???@'.$_SERVER['LOGNAME'];
1245
+		elseif (!empty($_SERVER['LOGNAME'])) {
1246
+			$data['ip'] = '???@'.$_SERVER['LOGNAME'];
1247
+		}
1127 1248
 		// Loop on each log handler and send output
1128 1249
 		foreach ($conf->loghandlers as $loghandlerinstance)
1129 1250
 		{
1130
-			if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) continue;
1251
+			if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
1252
+				continue;
1253
+			}
1131 1254
 			$loghandlerinstance->export($data, $suffixinfilename);
1132 1255
 		}
1133 1256
 		unset($data);
@@ -1184,7 +1307,9 @@  discard block
 block discarded – undo
1184 1307
 
1185 1308
 	// Show title
1186 1309
 	$showtitle = 1;
1187
-	if (!empty($conf->dol_optimize_smallscreen)) $showtitle = 0;
1310
+	if (!empty($conf->dol_optimize_smallscreen)) {
1311
+		$showtitle = 0;
1312
+	}
1188 1313
 
1189 1314
 	$out = "\n".'<!-- dol_fiche_head - dol_get_fiche_head -->';
1190 1315
 
@@ -1193,14 +1318,19 @@  discard block
 block discarded – undo
1193 1318
 	}
1194 1319
 
1195 1320
 	// Show right part
1196
-	if ($morehtmlright) $out .= '<div class="inline-block floatright tabsElem">'.$morehtmlright.'</div>'; // Output right area first so when space is missing, text is in front of tabs and not under.
1321
+	if ($morehtmlright) {
1322
+		$out .= '<div class="inline-block floatright tabsElem">'.$morehtmlright.'</div>';
1323
+	}
1324
+	// Output right area first so when space is missing, text is in front of tabs and not under.
1197 1325
 
1198 1326
 	// Show title
1199 1327
 	if (!empty($title) && $showtitle)
1200 1328
 	{
1201 1329
 		$limittitle = 30;
1202 1330
 		$out .= '<a class="tabTitle">';
1203
-		if ($picto && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $out .= img_picto($title, ($pictoisfullpath ? '' : 'object_').$picto, '', $pictoisfullpath, 0, 0, '', 'imgTabTitle').' ';
1331
+		if ($picto && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1332
+			$out .= img_picto($title, ($pictoisfullpath ? '' : 'object_').$picto, '', $pictoisfullpath, 0, 0, '', 'imgTabTitle').' ';
1333
+		}
1204 1334
 		$out .= '<span class="tabTitleText">'.dol_trunc($title, $limittitle).'</span>';
1205 1335
 		$out .= '</a>';
1206 1336
 	}
@@ -1212,7 +1342,9 @@  discard block
 block discarded – undo
1212 1342
 	if (is_array($links) && !empty($links))
1213 1343
 	{
1214 1344
 		$keys = array_keys($links);
1215
-		if (count($keys)) $maxkey = max($keys);
1345
+		if (count($keys)) {
1346
+			$maxkey = max($keys);
1347
+		}
1216 1348
 	}
1217 1349
 
1218 1350
 	// Show tabs
@@ -1220,7 +1352,9 @@  discard block
 block discarded – undo
1220 1352
 	if (empty($limittoshow)) {
1221 1353
 		$limittoshow = (empty($conf->global->MAIN_MAXTABS_IN_CARD) ? 99 : $conf->global->MAIN_MAXTABS_IN_CARD);
1222 1354
 	}
1223
-	if (!empty($conf->dol_optimize_smallscreen)) $limittoshow = 2;
1355
+	if (!empty($conf->dol_optimize_smallscreen)) {
1356
+		$limittoshow = 2;
1357
+	}
1224 1358
 
1225 1359
 	$displaytab = 0;
1226 1360
 	$nbintab = 0;
@@ -1230,7 +1364,9 @@  discard block
 block discarded – undo
1230 1364
 	{
1231 1365
 		if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
1232 1366
 			// If active tab is already present
1233
-			if ($i >= $limittoshow) $limittoshow--;
1367
+			if ($i >= $limittoshow) {
1368
+				$limittoshow--;
1369
+			}
1234 1370
 		}
1235 1371
 	}
1236 1372
 
@@ -1278,9 +1414,11 @@  discard block
 block discarded – undo
1278 1414
 			$outmore .= '<div class="popuptab wordwrap" style="display:inherit;">';
1279 1415
 			if (isset($links[$i][2]) && $links[$i][2] == 'image')
1280 1416
 			{
1281
-				if (!empty($links[$i][0]))
1282
-					$outmore .= '<a class="tabimage'.($morecss ? ' '.$morecss : '').'" href="'.$links[$i][0].'">'.$links[$i][1].'</a>'."\n";
1283
-				else $outmore .= '<span class="tabspan">'.$links[$i][1].'</span>'."\n";
1417
+				if (!empty($links[$i][0])) {
1418
+									$outmore .= '<a class="tabimage'.($morecss ? ' '.$morecss : '').'" href="'.$links[$i][0].'">'.$links[$i][1].'</a>'."\n";
1419
+				} else {
1420
+					$outmore .= '<span class="tabspan">'.$links[$i][1].'</span>'."\n";
1421
+				}
1284 1422
 			} elseif (!empty($links[$i][1]))
1285 1423
 			{
1286 1424
 				$outmore .= '<a'.(!empty($links[$i][2]) ? ' id="'.$links[$i][2].'"' : '').' class="wordwrap inline-block'.($morecss ? ' '.$morecss : '').'" href="'.$links[$i][0].'">';
@@ -1293,11 +1431,15 @@  discard block
 block discarded – undo
1293 1431
 		}
1294 1432
 		$displaytab = $i;
1295 1433
 	}
1296
-	if ($popuptab) $outmore .= '</div>';
1434
+	if ($popuptab) {
1435
+		$outmore .= '</div>';
1436
+	}
1297 1437
 
1298
-	if ($popuptab)	// If there is some tabs not shown
1438
+	if ($popuptab) {
1439
+		// If there is some tabs not shown
1299 1440
 	{
1300 1441
 		$left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');
1442
+	}
1301 1443
 		$right = ($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right');
1302 1444
 
1303 1445
 		$tabsname = $moretabssuffix;
@@ -1320,7 +1462,9 @@  discard block
 block discarded – undo
1320 1462
 		$out .= "</div>\n";
1321 1463
 	}
1322 1464
 
1323
-	if (!$notab || $notab == -1 || $notab == -2) $out .= "\n".'<div class="tabBar'.($notab == -1 ? '' : ($notab == -2 ? ' tabBarNoTop' : ' tabBarWithBottom')).'">'."\n";
1465
+	if (!$notab || $notab == -1 || $notab == -2) {
1466
+		$out .= "\n".'<div class="tabBar'.($notab == -1 ? '' : ($notab == -2 ? ' tabBarNoTop' : ' tabBarWithBottom')).'">'."\n";
1467
+	}
1324 1468
 
1325 1469
 	$parameters = array('tabname' => $active, 'out' => $out);
1326 1470
 	$reshook = $hookmanager->executeHooks('printTabsHead', $parameters); // This hook usage is called just before output the head of tabs. Take also a look at "completeTabsHead"
@@ -1351,9 +1495,12 @@  discard block
 block discarded – undo
1351 1495
  */
1352 1496
 function dol_get_fiche_end($notab = 0)
1353 1497
 {
1354
-	if (!$notab || $notab == -1) return "\n</div>\n";
1355
-	else return '';
1356
-}
1498
+	if (!$notab || $notab == -1) {
1499
+		return "\n</div>\n";
1500
+	} else {
1501
+		return '';
1502
+	}
1503
+	}
1357 1504
 
1358 1505
 /**
1359 1506
  *  Show tab footer of a card.
@@ -1384,27 +1531,59 @@  discard block
 block discarded – undo
1384 1531
 	$showimage = 1;
1385 1532
 	$entity = (empty($object->entity) ? $conf->entity : $object->entity);
1386 1533
 	$showbarcode = empty($conf->barcode->enabled) ? 0 : ($object->barcode ? 1 : 0);
1387
-	if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode = 0;
1534
+	if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
1535
+		$showbarcode = 0;
1536
+	}
1388 1537
 	$modulepart = 'unknown';
1389 1538
 
1390
-	if ($object->element == 'societe')         $modulepart = 'societe';
1391
-	if ($object->element == 'contact')         $modulepart = 'contact';
1392
-	if ($object->element == 'member')          $modulepart = 'memberphoto';
1393
-	if ($object->element == 'user')            $modulepart = 'userphoto';
1394
-	if ($object->element == 'product')         $modulepart = 'product';
1395
-	if ($object->element == 'ticket')          $modulepart = 'ticket';
1539
+	if ($object->element == 'societe') {
1540
+		$modulepart = 'societe';
1541
+	}
1542
+	if ($object->element == 'contact') {
1543
+		$modulepart = 'contact';
1544
+	}
1545
+	if ($object->element == 'member') {
1546
+		$modulepart = 'memberphoto';
1547
+	}
1548
+	if ($object->element == 'user') {
1549
+		$modulepart = 'userphoto';
1550
+	}
1551
+	if ($object->element == 'product') {
1552
+		$modulepart = 'product';
1553
+	}
1554
+	if ($object->element == 'ticket') {
1555
+		$modulepart = 'ticket';
1556
+	}
1396 1557
 
1397 1558
 	if (class_exists("Imagick"))
1398 1559
 	{
1399
-		if ($object->element == 'propal')            $modulepart = 'propal';
1400
-		if ($object->element == 'commande')          $modulepart = 'commande';
1401
-		if ($object->element == 'facture')           $modulepart = 'facture';
1402
-		if ($object->element == 'fichinter')         $modulepart = 'ficheinter';
1403
-		if ($object->element == 'contrat')           $modulepart = 'contract';
1404
-		if ($object->element == 'supplier_proposal') $modulepart = 'supplier_proposal';
1405
-		if ($object->element == 'order_supplier')    $modulepart = 'supplier_order';
1406
-		if ($object->element == 'invoice_supplier')  $modulepart = 'supplier_invoice';
1407
-		if ($object->element == 'expensereport')     $modulepart = 'expensereport';
1560
+		if ($object->element == 'propal') {
1561
+			$modulepart = 'propal';
1562
+		}
1563
+		if ($object->element == 'commande') {
1564
+			$modulepart = 'commande';
1565
+		}
1566
+		if ($object->element == 'facture') {
1567
+			$modulepart = 'facture';
1568
+		}
1569
+		if ($object->element == 'fichinter') {
1570
+			$modulepart = 'ficheinter';
1571
+		}
1572
+		if ($object->element == 'contrat') {
1573
+			$modulepart = 'contract';
1574
+		}
1575
+		if ($object->element == 'supplier_proposal') {
1576
+			$modulepart = 'supplier_proposal';
1577
+		}
1578
+		if ($object->element == 'order_supplier') {
1579
+			$modulepart = 'supplier_order';
1580
+		}
1581
+		if ($object->element == 'invoice_supplier') {
1582
+			$modulepart = 'supplier_invoice';
1583
+		}
1584
+		if ($object->element == 'expensereport') {
1585
+			$modulepart = 'expensereport';
1586
+		}
1408 1587
 	}
1409 1588
 
1410 1589
 	if ($object->element == 'product')
@@ -1412,9 +1591,12 @@  discard block
 block discarded – undo
1412 1591
 		$width = 80; $cssclass = 'photoref';
1413 1592
 		$showimage = $object->is_photo_available($conf->product->multidir_output[$entity]);
1414 1593
 		$maxvisiblephotos = (isset($conf->global->PRODUCT_MAX_VISIBLE_PHOTO) ? $conf->global->PRODUCT_MAX_VISIBLE_PHOTO : 5);
1415
-		if ($conf->browser->layout == 'phone') $maxvisiblephotos = 1;
1416
-		if ($showimage) $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">'.$object->show_photos('product', $conf->product->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, $width, 0).'</div>';
1417
-		else {
1594
+		if ($conf->browser->layout == 'phone') {
1595
+			$maxvisiblephotos = 1;
1596
+		}
1597
+		if ($showimage) {
1598
+			$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">'.$object->show_photos('product', $conf->product->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, $width, 0).'</div>';
1599
+		} else {
1418 1600
 			if (!empty($conf->global->PRODUCT_NODISPLAYIFNOPHOTO)) {
1419 1601
 				$nophoto = '';
1420 1602
 				$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"></div>';
@@ -1428,7 +1610,9 @@  discard block
 block discarded – undo
1428 1610
 		$width = 80; $cssclass = 'photoref';
1429 1611
 		$showimage = $object->is_photo_available($conf->ticket->multidir_output[$entity].'/'.$object->ref);
1430 1612
 		$maxvisiblephotos = (isset($conf->global->TICKET_MAX_VISIBLE_PHOTO) ? $conf->global->TICKET_MAX_VISIBLE_PHOTO : 2);
1431
-		if ($conf->browser->layout == 'phone') $maxvisiblephotos = 1;
1613
+		if ($conf->browser->layout == 'phone') {
1614
+			$maxvisiblephotos = 1;
1615
+		}
1432 1616
 		if ($showimage)
1433 1617
 		{
1434 1618
 			$showphoto = $object->show_photos('ticket', $conf->ticket->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, $width, 0);
@@ -1467,7 +1651,10 @@  discard block
 block discarded – undo
1467 1651
 					} else {
1468 1652
 						$subdir = get_exdir($object->id, 0, 0, 1, $object, $modulepart);
1469 1653
 					}
1470
-					if (empty($subdir)) $subdir = 'errorgettingsubdirofobject'; // Protection to avoid to return empty path
1654
+					if (empty($subdir)) {
1655
+						$subdir = 'errorgettingsubdirofobject';
1656
+					}
1657
+					// Protection to avoid to return empty path
1471 1658
 
1472 1659
 					$filepath = $dir_output.$subdir."/";
1473 1660
 
@@ -1486,11 +1673,15 @@  discard block
 block discarded – undo
1486 1673
 						// Conversion du PDF en image png si fichier png non existant
1487 1674
 						if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf)))
1488 1675
 						{
1489
-							if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS))		// If you experience trouble with pdf thumb generation and imagick, you can disable here.
1676
+							if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) {
1677
+								// If you experience trouble with pdf thumb generation and imagick, you can disable here.
1490 1678
 							{
1491 1679
 								include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1680
+							}
1492 1681
 								$ret = dol_convert_file($filepdf, 'png', $fileimage, '0'); // Convert first page of PDF into a file _preview.png
1493
-								if ($ret < 0) $error++;
1682
+								if ($ret < 0) {
1683
+									$error++;
1684
+								}
1494 1685
 							}
1495 1686
 						}
1496 1687
 					}
@@ -1498,7 +1689,9 @@  discard block
 block discarded – undo
1498 1689
 					if ($pdfexists && !$error)
1499 1690
 					{
1500 1691
 						$heightforphotref = 70;
1501
-						if (!empty($conf->dol_optimize_smallscreen)) $heightforphotref = 60;
1692
+						if (!empty($conf->dol_optimize_smallscreen)) {
1693
+							$heightforphotref = 60;
1694
+						}
1502 1695
 						// If the preview file is found
1503 1696
 						if (file_exists($fileimage))
1504 1697
 						{
@@ -1520,9 +1713,11 @@  discard block
 block discarded – undo
1520 1713
 				}
1521 1714
 			}
1522 1715
 
1523
-			if (!$phototoshow)      // Show No photo link (picto of object)
1716
+			if (!$phototoshow) {
1717
+				// Show No photo link (picto of object)
1524 1718
 			{
1525 1719
 			    $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">';
1720
+			}
1526 1721
 				if ($object->element == 'action')
1527 1722
 				{
1528 1723
 					$width = 80;
@@ -1531,7 +1726,10 @@  discard block
 block discarded – undo
1531 1726
 				} else {
1532 1727
 					$width = 14; $cssclass = 'photorefcenter';
1533 1728
 					$picto = $object->picto;
1534
-					if ($object->element == 'project' && !$object->public) $picto = 'project'; // instead of projectpub
1729
+					if ($object->element == 'project' && !$object->public) {
1730
+						$picto = 'project';
1731
+					}
1732
+					// instead of projectpub
1535 1733
 					$nophoto = img_picto('No photo', 'object_'.$picto);
1536 1734
 				}
1537 1735
 				$morehtmlleft .= '<!-- No photo to show -->';
@@ -1544,7 +1742,9 @@  discard block
 block discarded – undo
1544 1742
 		}
1545 1743
 	}
1546 1744
 
1547
-	if ($showbarcode) $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">'.$form->showbarcode($object).'</div>';
1745
+	if ($showbarcode) {
1746
+		$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">'.$form->showbarcode($object).'</div>';
1747
+	}
1548 1748
 
1549 1749
 	if ($object->element == 'societe')
1550 1750
 	{
@@ -1572,26 +1772,40 @@  discard block
 block discarded – undo
1572 1772
 	} elseif (in_array($object->element, array('facture', 'invoice', 'invoice_supplier', 'chargesociales', 'loan')))
1573 1773
 	{
1574 1774
 		$tmptxt = $object->getLibStatut(6, $object->totalpaye);
1575
-		if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) $tmptxt = $object->getLibStatut(5, $object->totalpaye);
1775
+		if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
1776
+			$tmptxt = $object->getLibStatut(5, $object->totalpaye);
1777
+		}
1576 1778
 		$morehtmlstatus .= $tmptxt;
1577 1779
 	} elseif ($object->element == 'contrat' || $object->element == 'contract')
1578 1780
 	{
1579
-		if ($object->statut == 0) $morehtmlstatus .= $object->getLibStatut(5);
1580
-		else $morehtmlstatus .= $object->getLibStatut(4);
1781
+		if ($object->statut == 0) {
1782
+			$morehtmlstatus .= $object->getLibStatut(5);
1783
+		} else {
1784
+			$morehtmlstatus .= $object->getLibStatut(4);
1785
+		}
1581 1786
 	} elseif ($object->element == 'facturerec')
1582 1787
 	{
1583
-		if ($object->frequency == 0) $morehtmlstatus .= $object->getLibStatut(2);
1584
-		else $morehtmlstatus .= $object->getLibStatut(5);
1788
+		if ($object->frequency == 0) {
1789
+			$morehtmlstatus .= $object->getLibStatut(2);
1790
+		} else {
1791
+			$morehtmlstatus .= $object->getLibStatut(5);
1792
+		}
1585 1793
 	} elseif ($object->element == 'project_task')
1586 1794
 	{
1587 1795
 		$object->fk_statut = 1;
1588
-		if ($object->progress > 0) $object->fk_statut = 2;
1589
-		if ($object->progress >= 100) $object->fk_statut = 3;
1796
+		if ($object->progress > 0) {
1797
+			$object->fk_statut = 2;
1798
+		}
1799
+		if ($object->progress >= 100) {
1800
+			$object->fk_statut = 3;
1801
+		}
1590 1802
 		$tmptxt = $object->getLibStatut(5);
1591 1803
 		$morehtmlstatus .= $tmptxt; // No status on task
1592 1804
 	} else { // Generic case
1593 1805
 		$tmptxt = $object->getLibStatut(6);
1594
-		if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) $tmptxt = $object->getLibStatut(5);
1806
+		if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
1807
+			$tmptxt = $object->getLibStatut(5);
1808
+		}
1595 1809
 		$morehtmlstatus .= $tmptxt;
1596 1810
 	}
1597 1811
 
@@ -1607,12 +1821,16 @@  discard block
 block discarded – undo
1607 1821
 	}
1608 1822
 
1609 1823
 	// Add alias for thirdparty
1610
-	if (!empty($object->name_alias)) $morehtmlref .= '<div class="refidno">'.$object->name_alias.'</div>';
1824
+	if (!empty($object->name_alias)) {
1825
+		$morehtmlref .= '<div class="refidno">'.$object->name_alias.'</div>';
1826
+	}
1611 1827
 
1612 1828
 	// Add label
1613 1829
 	if (in_array($object->element, array('product', 'bank_account', 'project_task')))
1614 1830
 	{
1615
-		if (!empty($object->label)) $morehtmlref .= '<div class="refidno">'.$object->label.'</div>';
1831
+		if (!empty($object->label)) {
1832
+			$morehtmlref .= '<div class="refidno">'.$object->label.'</div>';
1833
+		}
1616 1834
 	}
1617 1835
 
1618 1836
 	if (method_exists($object, 'getBannerAddress') && !in_array($object->element, array('product', 'bookmark', 'ecm_directories', 'ecm_files')))
@@ -1650,11 +1868,15 @@  discard block
 block discarded – undo
1650 1868
 {
1651 1869
 	global $langs;
1652 1870
 	$ret = '';
1653
-	if ($fieldrequired) $ret .= '<span class="fieldrequired">';
1871
+	if ($fieldrequired) {
1872
+		$ret .= '<span class="fieldrequired">';
1873
+	}
1654 1874
 	$ret .= '<label for="'.$fieldkey.'">';
1655 1875
 	$ret .= $langs->trans($langkey);
1656 1876
 	$ret .= '</label>';
1657
-	if ($fieldrequired) $ret .= '</span>';
1877
+	if ($fieldrequired) {
1878
+		$ret .= '</span>';
1879
+	}
1658 1880
 	return $ret;
1659 1881
 }
1660 1882
 
@@ -1669,7 +1891,9 @@  discard block
 block discarded – undo
1669 1891
 {
1670 1892
 	global $bc;
1671 1893
 	$ret = ' '.$bc[$var];
1672
-	if ($moreclass) $ret = preg_replace('/class=\"/', 'class="'.$moreclass.' ', $ret);
1894
+	if ($moreclass) {
1895
+		$ret = preg_replace('/class=\"/', 'class="'.$moreclass.' ', $ret);
1896
+	}
1673 1897
 	return $ret;
1674 1898
 }
1675 1899
 
@@ -1699,36 +1923,48 @@  discard block
 block discarded – undo
1699 1923
 		$ret .= ($extralangcode ? $object->array_languages['address'][$extralangcode] : $object->address);
1700 1924
 	}
1701 1925
 	// Zip/Town/State
1702
-	if (in_array($object->country_code, array('AU', 'CA', 'US')) || !empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS))   	// US: title firstname name \n address lines \n town, state, zip \n country
1926
+	if (in_array($object->country_code, array('AU', 'CA', 'US')) || !empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS)) {
1927
+		// US: title firstname name \n address lines \n town, state, zip \n country
1703 1928
 	{
1704 1929
 		$town = ($extralangcode ? $object->array_languages['town'][$extralangcode] : $object->town);
1930
+	}
1705 1931
 		$ret .= ($ret ? $sep : '').$town;
1706 1932
 		if ($object->state)
1707 1933
 		{
1708 1934
 			$ret .= ($ret ? ", " : '').$object->state;
1709 1935
 		}
1710
-		if ($object->zip) $ret .= ($ret ? ", " : '').$object->zip;
1711
-	} elseif (in_array($object->country_code, array('GB', 'UK'))) // UK: title firstname name \n address lines \n town state \n zip \n country
1936
+		if ($object->zip) {
1937
+			$ret .= ($ret ? ", " : '').$object->zip;
1938
+		}
1939
+	} elseif (in_array($object->country_code, array('GB', 'UK'))) {
1940
+		// UK: title firstname name \n address lines \n town state \n zip \n country
1712 1941
 	{
1713 1942
 		$town = ($extralangcode ? $object->array_languages['town'][$extralangcode] : $object->town);
1943
+	}
1714 1944
 		$ret .= ($ret ? $sep : '').$town;
1715 1945
 		if ($object->state)
1716 1946
 		{
1717 1947
 			$ret .= ($ret ? ", " : '').$object->state;
1718 1948
 		}
1719
-		if ($object->zip) $ret .= ($ret ? $sep : '').$object->zip;
1720
-	} elseif (in_array($object->country_code, array('ES', 'TR'))) // ES: title firstname name \n address lines \n zip town \n state \n country
1949
+		if ($object->zip) {
1950
+			$ret .= ($ret ? $sep : '').$object->zip;
1951
+		}
1952
+	} elseif (in_array($object->country_code, array('ES', 'TR'))) {
1953
+		// ES: title firstname name \n address lines \n zip town \n state \n country
1721 1954
 	{
1722 1955
 		$ret .= ($ret ? $sep : '').$object->zip;
1956
+	}
1723 1957
 		$town = ($extralangcode ? $object->array_languages['town'][$extralangcode] : $object->town);
1724 1958
 		$ret .= ($town ? (($object->zip ? ' ' : '').$town) : '');
1725 1959
 		if ($object->state)
1726 1960
 		{
1727 1961
 			$ret .= "\n".$object->state;
1728 1962
 		}
1729
-	} elseif (in_array($object->country_code, array('IT'))) // IT: tile firstname name\n address lines \n zip (Code Departement) \n country
1963
+	} elseif (in_array($object->country_code, array('IT'))) {
1964
+		// IT: tile firstname name\n address lines \n zip (Code Departement) \n country
1730 1965
 	{
1731 1966
 		$ret .= ($ret ? $sep : '').$object->zip;
1967
+	}
1732 1968
 		$town = ($extralangcode ? $object->array_languages['town'][$extralangcode] : $object->town);
1733 1969
 		$ret .= ($town ? (($object->zip ? ' ' : '').$town) : '');
1734 1970
 		$ret .= ($object->state_code ? (' '.($object->state_code)) : '');
@@ -1742,7 +1978,9 @@  discard block
 block discarded – undo
1742 1978
 			$ret .= ($ret ? ", " : '').$object->state;
1743 1979
 		}
1744 1980
 	}
1745
-	if (!is_object($outputlangs)) $outputlangs = $langs;
1981
+	if (!is_object($outputlangs)) {
1982
+		$outputlangs = $langs;
1983
+	}
1746 1984
 	if ($withcountry)
1747 1985
 	{
1748 1986
 		$langs->load("dict");
@@ -1766,8 +2004,10 @@  discard block
 block discarded – undo
1766 2004
 {
1767 2005
 	if ((abs($ts) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range
1768 2006
 		return ($is_gmt) ? @gmstrftime($fmt, $ts) : @strftime($fmt, $ts);
1769
-	} else return 'Error date into a not supported range';
1770
-}
2007
+	} else {
2008
+		return 'Error date into a not supported range';
2009
+	}
2010
+	}
1771 2011
 
1772 2012
 /**
1773 2013
  *	Output date in a string format according to outputlangs (or langs if not defined).
@@ -1817,31 +2057,57 @@  discard block
 block discarded – undo
1817 2057
 			}
1818 2058
 		}
1819 2059
 	}
1820
-	if (!is_object($outputlangs)) $outputlangs = $langs;
1821
-	if (!$format) $format = 'daytextshort';
2060
+	if (!is_object($outputlangs)) {
2061
+		$outputlangs = $langs;
2062
+	}
2063
+	if (!$format) {
2064
+		$format = 'daytextshort';
2065
+	}
1822 2066
 	$reduceformat = (!empty($conf->dol_optimize_smallscreen) && in_array($format, array('day', 'dayhour'))) ? 1 : 0;
1823 2067
 	$formatwithoutreduce = preg_replace('/reduceformat/', '', $format);
1824 2068
 	if ($formatwithoutreduce != $format) { $format = $formatwithoutreduce; $reduceformat = 1; }  // so format 'dayreduceformat' is processed like day
1825 2069
 
1826 2070
 	// Change predefined format into computer format. If found translation in lang file we use it, otherwise we use default.
1827 2071
 	// TODO Add format daysmallyear and dayhoursmallyear
1828
-	if ($format == 'day')				$format = ($outputlangs->trans("FormatDateShort") != "FormatDateShort" ? $outputlangs->trans("FormatDateShort") : $conf->format_date_short);
1829
-	elseif ($format == 'hour')			$format = ($outputlangs->trans("FormatHourShort") != "FormatHourShort" ? $outputlangs->trans("FormatHourShort") : $conf->format_hour_short);
1830
-	elseif ($format == 'hourduration')	$format = ($outputlangs->trans("FormatHourShortDuration") != "FormatHourShortDuration" ? $outputlangs->trans("FormatHourShortDuration") : $conf->format_hour_short_duration);
1831
-	elseif ($format == 'daytext')			 $format = ($outputlangs->trans("FormatDateText") != "FormatDateText" ? $outputlangs->trans("FormatDateText") : $conf->format_date_text);
1832
-	elseif ($format == 'daytextshort')	$format = ($outputlangs->trans("FormatDateTextShort") != "FormatDateTextShort" ? $outputlangs->trans("FormatDateTextShort") : $conf->format_date_text_short);
1833
-	elseif ($format == 'dayhour')			 $format = ($outputlangs->trans("FormatDateHourShort") != "FormatDateHourShort" ? $outputlangs->trans("FormatDateHourShort") : $conf->format_date_hour_short);
1834
-	elseif ($format == 'dayhoursec')		 $format = ($outputlangs->trans("FormatDateHourSecShort") != "FormatDateHourSecShort" ? $outputlangs->trans("FormatDateHourSecShort") : $conf->format_date_hour_sec_short);
1835
-	elseif ($format == 'dayhourtext')		 $format = ($outputlangs->trans("FormatDateHourText") != "FormatDateHourText" ? $outputlangs->trans("FormatDateHourText") : $conf->format_date_hour_text);
1836
-	elseif ($format == 'dayhourtextshort') $format = ($outputlangs->trans("FormatDateHourTextShort") != "FormatDateHourTextShort" ? $outputlangs->trans("FormatDateHourTextShort") : $conf->format_date_hour_text_short);
2072
+	if ($format == 'day') {
2073
+		$format = ($outputlangs->trans("FormatDateShort") != "FormatDateShort" ? $outputlangs->trans("FormatDateShort") : $conf->format_date_short);
2074
+	} elseif ($format == 'hour') {
2075
+		$format = ($outputlangs->trans("FormatHourShort") != "FormatHourShort" ? $outputlangs->trans("FormatHourShort") : $conf->format_hour_short);
2076
+	} elseif ($format == 'hourduration') {
2077
+		$format = ($outputlangs->trans("FormatHourShortDuration") != "FormatHourShortDuration" ? $outputlangs->trans("FormatHourShortDuration") : $conf->format_hour_short_duration);
2078
+	} elseif ($format == 'daytext') {
2079
+		$format = ($outputlangs->trans("FormatDateText") != "FormatDateText" ? $outputlangs->trans("FormatDateText") : $conf->format_date_text);
2080
+	} elseif ($format == 'daytextshort') {
2081
+		$format = ($outputlangs->trans("FormatDateTextShort") != "FormatDateTextShort" ? $outputlangs->trans("FormatDateTextShort") : $conf->format_date_text_short);
2082
+	} elseif ($format == 'dayhour') {
2083
+		$format = ($outputlangs->trans("FormatDateHourShort") != "FormatDateHourShort" ? $outputlangs->trans("FormatDateHourShort") : $conf->format_date_hour_short);
2084
+	} elseif ($format == 'dayhoursec') {
2085
+		$format = ($outputlangs->trans("FormatDateHourSecShort") != "FormatDateHourSecShort" ? $outputlangs->trans("FormatDateHourSecShort") : $conf->format_date_hour_sec_short);
2086
+	} elseif ($format == 'dayhourtext') {
2087
+		$format = ($outputlangs->trans("FormatDateHourText") != "FormatDateHourText" ? $outputlangs->trans("FormatDateHourText") : $conf->format_date_hour_text);
2088
+	} elseif ($format == 'dayhourtextshort') {
2089
+		$format = ($outputlangs->trans("FormatDateHourTextShort") != "FormatDateHourTextShort" ? $outputlangs->trans("FormatDateHourTextShort") : $conf->format_date_hour_text_short);
2090
+	}
1837 2091
 	// Format not sensitive to language
1838
-	elseif ($format == 'dayhourlog')		 $format = '%Y%m%d%H%M%S';
1839
-	elseif ($format == 'dayhourldap')		 $format = '%Y%m%d%H%M%SZ';
1840
-	elseif ($format == 'dayhourxcard')	$format = '%Y%m%dT%H%M%SZ';
1841
-	elseif ($format == 'dayxcard')	 	$format = '%Y%m%d';
1842
-	elseif ($format == 'dayrfc')			 $format = '%Y-%m-%d'; // DATE_RFC3339
1843
-	elseif ($format == 'dayhourrfc')		 $format = '%Y-%m-%dT%H:%M:%SZ'; // DATETIME RFC3339
1844
-	elseif ($format == 'standard')		$format = '%Y-%m-%d %H:%M:%S';
2092
+	elseif ($format == 'dayhourlog') {
2093
+		$format = '%Y%m%d%H%M%S';
2094
+	} elseif ($format == 'dayhourldap') {
2095
+		$format = '%Y%m%d%H%M%SZ';
2096
+	} elseif ($format == 'dayhourxcard') {
2097
+		$format = '%Y%m%dT%H%M%SZ';
2098
+	} elseif ($format == 'dayxcard') {
2099
+		$format = '%Y%m%d';
2100
+	} elseif ($format == 'dayrfc') {
2101
+		$format = '%Y-%m-%d';
2102
+	}
2103
+	// DATE_RFC3339
2104
+	elseif ($format == 'dayhourrfc') {
2105
+		$format = '%Y-%m-%dT%H:%M:%SZ';
2106
+	}
2107
+	// DATETIME RFC3339
2108
+	elseif ($format == 'standard') {
2109
+		$format = '%Y-%m-%d %H:%M:%S';
2110
+	}
1845 2111
 
1846 2112
 	if ($reduceformat)
1847 2113
 	{
@@ -1850,33 +2116,44 @@  discard block
 block discarded – undo
1850 2116
 	}
1851 2117
 
1852 2118
 	// If date undefined or "", we return ""
1853
-	if (dol_strlen($time) == 0) return ''; // $time=0 allowed (it means 01/01/1970 00:00:00)
2119
+	if (dol_strlen($time) == 0) {
2120
+		return '';
2121
+	}
2122
+	// $time=0 allowed (it means 01/01/1970 00:00:00)
1854 2123
 
1855 2124
 	// Clean format
1856
-	if (preg_match('/%b/i', $format))		// There is some text to translate
2125
+	if (preg_match('/%b/i', $format)) {
2126
+		// There is some text to translate
1857 2127
 	{
1858 2128
 		// We inhibate translation to text made by strftime functions. We will use trans instead later.
1859 2129
 		$format = str_replace('%b', '__b__', $format);
2130
+	}
1860 2131
 		$format = str_replace('%B', '__B__', $format);
1861 2132
 	}
1862
-	if (preg_match('/%a/i', $format))		// There is some text to translate
2133
+	if (preg_match('/%a/i', $format)) {
2134
+		// There is some text to translate
1863 2135
 	{
1864 2136
 		// We inhibate translation to text made by strftime functions. We will use trans instead later.
1865 2137
 		$format = str_replace('%a', '__a__', $format);
2138
+	}
1866 2139
 		$format = str_replace('%A', '__A__', $format);
1867 2140
 	}
1868 2141
 
1869 2142
 
1870 2143
 	// Analyze date
1871 2144
 	$reg = array();
1872
-	if (preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i', $time, $reg))	// Deprecated. Ex: 1970-01-01, 1970-01-01 01:00:00, 19700101010000
2145
+	if (preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i', $time, $reg)) {
2146
+		// Deprecated. Ex: 1970-01-01, 1970-01-01 01:00:00, 19700101010000
1873 2147
 	{
1874 2148
 	    dol_print_error("Functions.lib::dol_print_date function called with a bad value from page ".$_SERVER["PHP_SELF"]);
2149
+	}
1875 2150
 	    return '';
1876
-	} elseif (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $time, $reg))    // Still available to solve problems in extrafields of type date
2151
+	} elseif (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $time, $reg)) {
2152
+		// Still available to solve problems in extrafields of type date
1877 2153
 	{
1878 2154
 	    // This part of code should not be used.
1879 2155
 	    dol_syslog("Functions.lib::dol_print_date function called with a bad value from page ".$_SERVER["PHP_SELF"], LOG_WARNING);
2156
+	}
1880 2157
 	    //if (function_exists('debug_print_backtrace')) debug_print_backtrace();
1881 2158
 	    // Date has format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'
1882 2159
 	    $syear	= (!empty($reg[1]) ? $reg[1] : '');
@@ -1890,12 +2167,17 @@  discard block
 block discarded – undo
1890 2167
 	    $ret = adodb_strftime($format, $time + $offsettz + $offsetdst, $to_gmt);
1891 2168
 	} else {
1892 2169
 		// Date is a timestamps
1893
-		if ($time < 100000000000)	// Protection against bad date values
2170
+		if ($time < 100000000000) {
2171
+			// Protection against bad date values
1894 2172
 		{
1895
-			$timetouse = $time + $offsettz + $offsetdst; // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
2173
+			$timetouse = $time + $offsettz + $offsetdst;
2174
+		}
2175
+		// TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
1896 2176
 
1897 2177
 			$ret = adodb_strftime($format, $timetouse, $to_gmt);
1898
-		} else $ret = 'Bad value '.$time.' for date';
2178
+		} else {
2179
+			$ret = 'Bad value '.$time.' for date';
2180
+		}
1899 2181
 	}
1900 2182
 
1901 2183
 	if (preg_match('/__b__/i', $format))
@@ -1971,8 +2253,14 @@  discard block
 block discarded – undo
1971 2253
 	global $conf;
1972 2254
 
1973 2255
 	$usealternatemethod = false;
1974
-	if ($timestamp <= 0) $usealternatemethod = true; // <= 1970
1975
-	if ($timestamp >= 2145913200) $usealternatemethod = true; // >= 2038
2256
+	if ($timestamp <= 0) {
2257
+		$usealternatemethod = true;
2258
+	}
2259
+	// <= 1970
2260
+	if ($timestamp >= 2145913200) {
2261
+		$usealternatemethod = true;
2262
+	}
2263
+	// >= 2038
1976 2264
 
1977 2265
 	if ($usealternatemethod)
1978 2266
 	{
@@ -2009,19 +2297,37 @@  discard block
 block discarded – undo
2009 2297
 	//print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -";
2010 2298
 
2011 2299
 	// Clean parameters
2012
-	if ($hour == -1 || empty($hour)) $hour = 0;
2013
-	if ($minute == -1 || empty($minute)) $minute = 0;
2014
-	if ($second == -1 || empty($second)) $second = 0;
2300
+	if ($hour == -1 || empty($hour)) {
2301
+		$hour = 0;
2302
+	}
2303
+	if ($minute == -1 || empty($minute)) {
2304
+		$minute = 0;
2305
+	}
2306
+	if ($second == -1 || empty($second)) {
2307
+		$second = 0;
2308
+	}
2015 2309
 
2016 2310
 	// Check parameters
2017 2311
 	if ($check)
2018 2312
 	{
2019
-		if (!$month || !$day)  return '';
2020
-		if ($day > 31) return '';
2021
-		if ($month > 12) return '';
2022
-		if ($hour < 0 || $hour > 24) return '';
2023
-		if ($minute < 0 || $minute > 60) return '';
2024
-		if ($second < 0 || $second > 60) return '';
2313
+		if (!$month || !$day) {
2314
+			return '';
2315
+		}
2316
+		if ($day > 31) {
2317
+			return '';
2318
+		}
2319
+		if ($month > 12) {
2320
+			return '';
2321
+		}
2322
+		if ($hour < 0 || $hour > 24) {
2323
+			return '';
2324
+		}
2325
+		if ($minute < 0 || $minute > 60) {
2326
+			return '';
2327
+		}
2328
+		if ($second < 0 || $second > 60) {
2329
+			return '';
2330
+		}
2025 2331
 	}
2026 2332
 
2027 2333
 	if (empty($gm) || $gm === 'server')
@@ -2077,10 +2383,15 @@  discard block
 block discarded – undo
2077 2383
 {
2078 2384
 	$ret = 0;
2079 2385
 
2080
-	if ($mode == 'gmt') $ret = time(); // Time for now at greenwich.
2081
-	elseif ($mode == 'tzserver')		// Time for now with PHP server timezone added
2386
+	if ($mode == 'gmt') {
2387
+		$ret = time();
2388
+	}
2389
+	// Time for now at greenwich.
2390
+	elseif ($mode == 'tzserver') {
2391
+		// Time for now with PHP server timezone added
2082 2392
 	{
2083 2393
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
2394
+	}
2084 2395
 		$tzsecond = getServerTimeZoneInt('now'); // Contains tz+dayling saving time
2085 2396
 		$ret = (int) (dol_now('gmt') + ($tzsecond * 3600));
2086 2397
 	} /*elseif ($mode == 'tzref')				// Time for now with parent company timezone is added
@@ -2089,10 +2400,12 @@  discard block
 block discarded – undo
2089 2400
 		$tzsecond=getParentCompanyTimeZoneInt();    // Contains tz+dayling saving time
2090 2401
 		$ret=dol_now('gmt')+($tzsecond*3600);
2091 2402
 	}*/
2092
-	elseif ($mode == 'tzuser')				// Time for now with user timezone added
2403
+	elseif ($mode == 'tzuser') {
2404
+		// Time for now with user timezone added
2093 2405
 	{
2094 2406
 		//print 'time: '.time();
2095 2407
 		$offsettz = (empty($_SESSION['dol_tz']) ? 0 : $_SESSION['dol_tz']) * 60 * 60;
2408
+	}
2096 2409
 		$offsetdst = (empty($_SESSION['dol_dst']) ? 0 : $_SESSION['dol_dst']) * 60 * 60;
2097 2410
 		$ret = (int) (dol_now('gmt') + ($offsettz + $offsetdst));
2098 2411
 	}
@@ -2114,7 +2427,9 @@  discard block
 block discarded – undo
2114 2427
 	global $conf, $langs;
2115 2428
 	$level = 1024;
2116 2429
 
2117
-	if (!empty($conf->dol_optimize_smallscreen)) $shortunit = 1;
2430
+	if (!empty($conf->dol_optimize_smallscreen)) {
2431
+		$shortunit = 1;
2432
+	}
2118 2433
 
2119 2434
 	// Set value text
2120 2435
 	if (empty($shortvalue) || $size < ($level * 10))
@@ -2146,15 +2461,23 @@  discard block
 block discarded – undo
2146 2461
 {
2147 2462
 	global $langs;
2148 2463
 
2149
-	if (empty($url)) return '';
2464
+	if (empty($url)) {
2465
+		return '';
2466
+	}
2150 2467
 
2151 2468
 	$link = '<a href="';
2152
-	if (!preg_match('/^http/i', $url)) $link .= 'http://';
2469
+	if (!preg_match('/^http/i', $url)) {
2470
+		$link .= 'http://';
2471
+	}
2153 2472
 	$link .= $url;
2154 2473
 	$link .= '"';
2155
-	if ($target) $link .= ' target="'.$target.'"';
2474
+	if ($target) {
2475
+		$link .= ' target="'.$target.'"';
2476
+	}
2156 2477
 	$link .= '>';
2157
-	if (!preg_match('/^http/i', $url)) $link .= 'http://';
2478
+	if (!preg_match('/^http/i', $url)) {
2479
+		$link .= 'http://';
2480
+	}
2158 2481
 	$link .= dol_trunc($url, $max);
2159 2482
 	$link .= '</a>';
2160 2483
 	return '<div class="nospan float" style="margin-right: 10px">'.($withpicto ?img_picto($langs->trans("Url"), 'globe').' ' : '').$link.'</div>';
@@ -2178,14 +2501,20 @@  discard block
 block discarded – undo
2178 2501
 
2179 2502
 	$newemail = $email;
2180 2503
 
2181
-	if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) $withpicto = 0;
2504
+	if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) {
2505
+		$withpicto = 0;
2506
+	}
2182 2507
 
2183
-	if (empty($email)) return '&nbsp;';
2508
+	if (empty($email)) {
2509
+		return '&nbsp;';
2510
+	}
2184 2511
 
2185 2512
 	if (!empty($addlink))
2186 2513
 	{
2187 2514
 		$newemail = '<a style="text-overflow: ellipsis;" href="';
2188
-		if (!preg_match('/^mailto:/i', $email)) $newemail .= 'mailto:';
2515
+		if (!preg_match('/^mailto:/i', $email)) {
2516
+			$newemail .= 'mailto:';
2517
+		}
2189 2518
 		$newemail .= $email;
2190 2519
 		$newemail .= '">';
2191 2520
 		$newemail .= dol_trunc($email, $max);
@@ -2199,8 +2528,12 @@  discard block
 block discarded – undo
2199 2528
 		if (($cid || $socid) && !empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
2200 2529
 		{
2201 2530
 			$type = 'AC_EMAIL'; $link = '';
2202
-			if (!empty($conf->global->AGENDA_ADDACTIONFOREMAIL)) $link = '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$type.'&amp;contactid='.$cid.'&amp;socid='.$socid.'">'.img_object($langs->trans("AddAction"), "calendar").'</a>';
2203
-			if ($link) $newemail = '<div>'.$newemail.' '.$link.'</div>';
2531
+			if (!empty($conf->global->AGENDA_ADDACTIONFOREMAIL)) {
2532
+				$link = '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$type.'&amp;contactid='.$cid.'&amp;socid='.$socid.'">'.img_object($langs->trans("AddAction"), "calendar").'</a>';
2533
+			}
2534
+			if ($link) {
2535
+				$newemail = '<div>'.$newemail.' '.$link.'</div>';
2536
+			}
2204 2537
 		}
2205 2538
 	} else {
2206 2539
 		if ($showinvalid && !isValidEmail($email))
@@ -2266,7 +2599,9 @@  discard block
 block discarded – undo
2266 2599
 
2267 2600
 	$htmllink = $value;
2268 2601
 
2269
-	if (empty($value)) return '&nbsp;';
2602
+	if (empty($value)) {
2603
+		return '&nbsp;';
2604
+	}
2270 2605
 
2271 2606
 	if (!empty($type))
2272 2607
 	{
@@ -2290,7 +2625,9 @@  discard block
 block discarded – undo
2290 2625
 		{
2291 2626
 			$addlink = 'AC_SKYPE';
2292 2627
 			$link = '';
2293
-			if (!empty($conf->global->AGENDA_ADDACTIONFORSKYPE)) $link = '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$addlink.'&amp;contactid='.$cid.'&amp;socid='.$socid.'">'.img_object($langs->trans("AddAction"), "calendar").'</a>';
2628
+			if (!empty($conf->global->AGENDA_ADDACTIONFORSKYPE)) {
2629
+				$link = '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$addlink.'&amp;contactid='.$cid.'&amp;socid='.$socid.'">'.img_object($langs->trans("AddAction"), "calendar").'</a>';
2630
+			}
2294 2631
 			$htmllink .= ($link ? ' '.$link : '');
2295 2632
 		}
2296 2633
 		$htmllink .= '</div>';
@@ -2322,11 +2659,17 @@  discard block
 block discarded – undo
2322 2659
 	// Clean phone parameter
2323 2660
 	$phone = preg_replace("/[\s.-]/", "", trim($phone));
2324 2661
 	if (empty($phone)) { return ''; }
2325
-	if ($conf->global->MAIN_PHONE_SEPAR) $separ = $conf->global->MAIN_PHONE_SEPAR;
2326
-	if (empty($countrycode)) $countrycode = $mysoc->country_code;
2662
+	if ($conf->global->MAIN_PHONE_SEPAR) {
2663
+		$separ = $conf->global->MAIN_PHONE_SEPAR;
2664
+	}
2665
+	if (empty($countrycode)) {
2666
+		$countrycode = $mysoc->country_code;
2667
+	}
2327 2668
 
2328 2669
 	// Short format for small screens
2329
-	if ($conf->dol_optimize_smallscreen) $separ = '';
2670
+	if ($conf->dol_optimize_smallscreen) {
2671
+		$separ = '';
2672
+	}
2330 2673
 
2331 2674
 	$newphone = $phone;
2332 2675
 	if (strtoupper($countrycode) == "FR")
@@ -2572,21 +2915,29 @@  discard block
 block discarded – undo
2572 2915
 			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 1).$separ.substr($newphone, 4, 4).$separ.substr($newphone, 8, 4);
2573 2916
 		}
2574 2917
 	}
2575
-	if (!empty($addlink))	// Link on phone number (+ link to add action if conf->global->AGENDA_ADDACTIONFORPHONE set)
2918
+	if (!empty($addlink)) {
2919
+		// Link on phone number (+ link to add action if conf->global->AGENDA_ADDACTIONFORPHONE set)
2576 2920
 	{
2577 2921
 		if ($conf->browser->layout == 'phone' || (!empty($conf->clicktodial->enabled) && !empty($conf->global->CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS)))	// If phone or option for, we use link of phone
2578 2922
 		{
2579 2923
 			$newphoneform = $newphone;
2924
+	}
2580 2925
 			$newphone = '<a href="tel:'.$phone.'"';
2581 2926
 			$newphone .= '>'.$newphoneform.'</a>';
2582
-		} elseif (!empty($conf->clicktodial->enabled) && $addlink == 'AC_TEL')		// If click to dial, we use click to dial url
2927
+		} elseif (!empty($conf->clicktodial->enabled) && $addlink == 'AC_TEL') {
2928
+			// If click to dial, we use click to dial url
2583 2929
 		{
2584 2930
 			if (empty($user->clicktodial_loaded)) $user->fetch_clicktodial();
2931
+		}
2585 2932
 
2586 2933
 			// Define urlmask
2587 2934
 			$urlmask = 'ErrorClickToDialModuleNotConfigured';
2588
-			if (!empty($conf->global->CLICKTODIAL_URL)) $urlmask = $conf->global->CLICKTODIAL_URL;
2589
-			if (!empty($user->clicktodial_url)) $urlmask = $user->clicktodial_url;
2935
+			if (!empty($conf->global->CLICKTODIAL_URL)) {
2936
+				$urlmask = $conf->global->CLICKTODIAL_URL;
2937
+			}
2938
+			if (!empty($user->clicktodial_url)) {
2939
+				$urlmask = $user->clicktodial_url;
2940
+			}
2590 2941
 
2591 2942
 			$clicktodial_poste = (!empty($user->clicktodial_poste) ?urlencode($user->clicktodial_poste) : '');
2592 2943
 			$clicktodial_login = (!empty($user->clicktodial_login) ?urlencode($user->clicktodial_login) : '');
@@ -2601,7 +2952,9 @@  discard block
 block discarded – undo
2601 2952
 			$url = make_substitutions($url, $substitarray);
2602 2953
 			$newphonesav = $newphone;
2603 2954
 			$newphone = '<a href="'.$url.'"';
2604
-			if (!empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) $newphone .= ' target="_blank"';
2955
+			if (!empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) {
2956
+				$newphone .= ' target="_blank"';
2957
+			}
2605 2958
 			$newphone .= '>'.$newphonesav.'</a>';
2606 2959
 		}
2607 2960
 
@@ -2609,9 +2962,15 @@  discard block
 block discarded – undo
2609 2962
 		if (!empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
2610 2963
 		{
2611 2964
 			$type = 'AC_TEL'; $link = '';
2612
-			if ($addlink == 'AC_FAX') $type = 'AC_FAX';
2613
-			if (!empty($conf->global->AGENDA_ADDACTIONFORPHONE)) $link = '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$type.($cid ? '&amp;contactid='.$cid : '').($socid ? '&amp;socid='.$socid : '').'">'.img_object($langs->trans("AddAction"), "calendar").'</a>';
2614
-			if ($link) $newphone = '<div>'.$newphone.' '.$link.'</div>';
2965
+			if ($addlink == 'AC_FAX') {
2966
+				$type = 'AC_FAX';
2967
+			}
2968
+			if (!empty($conf->global->AGENDA_ADDACTIONFORPHONE)) {
2969
+				$link = '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode='.$type.($cid ? '&amp;contactid='.$cid : '').($socid ? '&amp;socid='.$socid : '').'">'.img_object($langs->trans("AddAction"), "calendar").'</a>';
2970
+			}
2971
+			if ($link) {
2972
+				$newphone = '<div>'.$newphone.' '.$link.'</div>';
2973
+			}
2615 2974
 		}
2616 2975
 	}
2617 2976
 
@@ -2640,11 +2999,17 @@  discard block
 block discarded – undo
2640 2999
 				$picto = '';
2641 3000
 			}
2642 3001
 		}
2643
-		if ($adddivfloat) $rep .= '<div class="nospan float" style="margin-right: 10px">';
2644
-		else $rep .= '<span style="margin-right: 10px;">';
3002
+		if ($adddivfloat) {
3003
+			$rep .= '<div class="nospan float" style="margin-right: 10px">';
3004
+		} else {
3005
+			$rep .= '<span style="margin-right: 10px;">';
3006
+		}
2645 3007
 		$rep .= ($withpicto ?img_picto($titlealt, 'object_'.$picto.'.png').' ' : '').$newphone;
2646
-		if ($adddivfloat) $rep .= '</div>';
2647
-		else $rep .= '</span>';
3008
+		if ($adddivfloat) {
3009
+			$rep .= '</div>';
3010
+		} else {
3011
+			$rep .= '</span>';
3012
+		}
2648 3013
 	}
2649 3014
 
2650 3015
 	return $rep;
@@ -2663,17 +3028,23 @@  discard block
 block discarded – undo
2663 3028
 
2664 3029
 	$ret = '';
2665 3030
 
2666
-	if (empty($mode)) $ret .= $ip;
3031
+	if (empty($mode)) {
3032
+		$ret .= $ip;
3033
+	}
2667 3034
 
2668 3035
 	if ($mode != 2)
2669 3036
 	{
2670 3037
 		$countrycode = dolGetCountryCodeFromIp($ip);
2671
-		if ($countrycode)	// If success, countrycode is us, fr, ...
3038
+		if ($countrycode) {
3039
+			// If success, countrycode is us, fr, ...
2672 3040
 		{
2673 3041
 			if (file_exists(DOL_DOCUMENT_ROOT.'/theme/common/flags/'.$countrycode.'.png'))
2674 3042
 			{
2675 3043
 				$ret .= ' '.img_picto($countrycode.' '.$langs->trans("AccordingToGeoIPDatabase"), DOL_URL_ROOT.'/theme/common/flags/'.$countrycode.'.png', '', 1);
2676
-			} else $ret .= ' ('.$countrycode.')';
3044
+		}
3045
+			} else {
3046
+				$ret .= ' ('.$countrycode.')';
3047
+			}
2677 3048
 		} else {
2678 3049
 			// Nothing
2679 3050
 		}
@@ -2776,17 +3147,32 @@  discard block
 block discarded – undo
2776 3147
 		}
2777 3148
 		if (empty($reshook))
2778 3149
 		{
2779
-			if (empty($charfornl)) $out .= nl2br($address);
2780
-			else $out .= preg_replace('/[\r\n]+/', $charfornl, $address);
3150
+			if (empty($charfornl)) {
3151
+				$out .= nl2br($address);
3152
+			} else {
3153
+				$out .= preg_replace('/[\r\n]+/', $charfornl, $address);
3154
+			}
2781 3155
 
2782 3156
 			// TODO Remove this block, we can add this using the hook now
2783 3157
 			$showgmap = $showomap = 0;
2784
-			if (($element == 'thirdparty' || $element == 'societe') && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS)) $showgmap = 1;
2785
-			if ($element == 'contact' && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS)) $showgmap = 1;
2786
-			if ($element == 'member' && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS)) $showgmap = 1;
2787
-			if (($element == 'thirdparty' || $element == 'societe') && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS)) $showomap = 1;
2788
-			if ($element == 'contact' && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS)) $showomap = 1;
2789
-			if ($element == 'member' && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS)) $showomap = 1;
3158
+			if (($element == 'thirdparty' || $element == 'societe') && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS)) {
3159
+				$showgmap = 1;
3160
+			}
3161
+			if ($element == 'contact' && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS)) {
3162
+				$showgmap = 1;
3163
+			}
3164
+			if ($element == 'member' && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS)) {
3165
+				$showgmap = 1;
3166
+			}
3167
+			if (($element == 'thirdparty' || $element == 'societe') && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS)) {
3168
+				$showomap = 1;
3169
+			}
3170
+			if ($element == 'contact' && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS)) {
3171
+				$showomap = 1;
3172
+			}
3173
+			if ($element == 'member' && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS)) {
3174
+				$showomap = 1;
3175
+			}
2790 3176
 			if ($showgmap)
2791 3177
 			{
2792 3178
 				$url = dol_buildpath('/google/gmaps.php?mode='.$element.'&id='.$id, 1);
@@ -2799,9 +3185,12 @@  discard block
 block discarded – undo
2799 3185
 			}
2800 3186
 		}
2801 3187
 	}
2802
-	if ($noprint) return $out;
2803
-	else print $out;
2804
-}
3188
+	if ($noprint) {
3189
+		return $out;
3190
+	} else {
3191
+		print $out;
3192
+	}
3193
+	}
2805 3194
 
2806 3195
 
2807 3196
 /**
@@ -2813,8 +3202,12 @@  discard block
 block discarded – undo
2813 3202
  */
2814 3203
 function isValidEmail($address, $acceptsupervisorkey = 0)
2815 3204
 {
2816
-	if ($acceptsupervisorkey && $address == '__SUPERVISOREMAIL__') return true;
2817
-	if (filter_var($address, FILTER_VALIDATE_EMAIL)) return true;
3205
+	if ($acceptsupervisorkey && $address == '__SUPERVISOREMAIL__') {
3206
+		return true;
3207
+	}
3208
+	if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
3209
+		return true;
3210
+	}
2818 3211
 
2819 3212
 	return false;
2820 3213
 }
@@ -2839,8 +3232,12 @@  discard block
 block discarded – undo
2839 3232
 			$mxhosts = array();
2840 3233
 			$weight = array();
2841 3234
 			getmxrr(idn_to_ascii($domain), $mxhosts, $weight);
2842
-			if (count($mxhosts) > 1) return 1;
2843
-			if (count($mxhosts) == 1 && !empty($mxhosts[0])) return 1;
3235
+			if (count($mxhosts) > 1) {
3236
+				return 1;
3237
+			}
3238
+			if (count($mxhosts) == 1 && !empty($mxhosts[0])) {
3239
+				return 1;
3240
+			}
2844 3241
 
2845 3242
 			return 0;
2846 3243
 		}
@@ -2870,9 +3267,12 @@  discard block
 block discarded – undo
2870 3267
  */
2871 3268
 function dol_strlen($string, $stringencoding = 'UTF-8')
2872 3269
 {
2873
-	if (function_exists('mb_strlen')) return mb_strlen($string, $stringencoding);
2874
-	else return strlen($string);
2875
-}
3270
+	if (function_exists('mb_strlen')) {
3271
+		return mb_strlen($string, $stringencoding);
3272
+	} else {
3273
+		return strlen($string);
3274
+	}
3275
+	}
2876 3276
 
2877 3277
 /**
2878 3278
  * Make a substring. Works even if mbstring module is not enabled for better compatibility.
@@ -2888,7 +3288,9 @@  discard block
 block discarded – undo
2888 3288
 {
2889 3289
 	global $langs;
2890 3290
 
2891
-	if (empty($stringencoding)) $stringencoding = $langs->charset_output;
3291
+	if (empty($stringencoding)) {
3292
+		$stringencoding = $langs->charset_output;
3293
+	}
2892 3294
 
2893 3295
 	$ret = '';
2894 3296
 	if (empty($trunconbytes))
@@ -2928,20 +3330,29 @@  discard block
 block discarded – undo
2928 3330
 {
2929 3331
 	global $conf;
2930 3332
 
2931
-	if ($size == 0 || !empty($conf->global->MAIN_DISABLE_TRUNC)) return $string;
3333
+	if ($size == 0 || !empty($conf->global->MAIN_DISABLE_TRUNC)) {
3334
+		return $string;
3335
+	}
2932 3336
 
2933
-	if (empty($stringencoding)) $stringencoding = 'UTF-8';
3337
+	if (empty($stringencoding)) {
3338
+		$stringencoding = 'UTF-8';
3339
+	}
2934 3340
 	// reduce for small screen
2935
-	if ($conf->dol_optimize_smallscreen == 1 && $display == 1) $size = round($size / 3);
3341
+	if ($conf->dol_optimize_smallscreen == 1 && $display == 1) {
3342
+		$size = round($size / 3);
3343
+	}
2936 3344
 
2937 3345
 	// We go always here
2938 3346
 	if ($trunc == 'right')
2939 3347
 	{
2940 3348
 		$newstring = dol_textishtml($string) ?dol_string_nohtmltag($string, 1) : $string;
2941
-		if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 3)))    // If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ...
3349
+		if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 3))) {
3350
+			// If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ...
2942 3351
 		return dol_substr($newstring, 0, $size, $stringencoding).($nodot ? '' : '...');
2943
-		else //return 'u'.$size.'-'.$newstring.'-'.dol_strlen($newstring,$stringencoding).'-'.$string;
3352
+		} else {
3353
+			//return 'u'.$size.'-'.$newstring.'-'.dol_strlen($newstring,$stringencoding).'-'.$string;
2944 3354
 		return $string;
3355
+		}
2945 3356
 	} elseif ($trunc == 'middle')
2946 3357
 	{
2947 3358
 		$newstring = dol_textishtml($string) ?dol_string_nohtmltag($string, 1) : $string;
@@ -2950,21 +3361,30 @@  discard block
 block discarded – undo
2950 3361
 			$size1 = round($size / 2);
2951 3362
 			$size2 = round($size / 2);
2952 3363
 			return dol_substr($newstring, 0, $size1, $stringencoding).'...'.dol_substr($newstring, dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
2953
-		} else return $string;
3364
+		} else {
3365
+			return $string;
3366
+		}
2954 3367
 	} elseif ($trunc == 'left')
2955 3368
 	{
2956 3369
 		$newstring = dol_textishtml($string) ?dol_string_nohtmltag($string, 1) : $string;
2957
-		if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 3)))    // If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ...
3370
+		if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 3))) {
3371
+			// If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ...
2958 3372
 		return '...'.dol_substr($newstring, dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
2959
-		else return $string;
3373
+		} else {
3374
+			return $string;
3375
+		}
2960 3376
 	} elseif ($trunc == 'wrap')
2961 3377
 	{
2962 3378
 		$newstring = dol_textishtml($string) ?dol_string_nohtmltag($string, 1) : $string;
2963
-		if (dol_strlen($newstring, $stringencoding) > ($size + 1))
2964
-		return dol_substr($newstring, 0, $size, $stringencoding)."\n".dol_trunc(dol_substr($newstring, $size, dol_strlen($newstring, $stringencoding) - $size, $stringencoding), $size, $trunc);
2965
-		else return $string;
2966
-	} else return 'BadParam3CallingDolTrunc';
2967
-}
3379
+		if (dol_strlen($newstring, $stringencoding) > ($size + 1)) {
3380
+				return dol_substr($newstring, 0, $size, $stringencoding)."\n".dol_trunc(dol_substr($newstring, $size, dol_strlen($newstring, $stringencoding) - $size, $stringencoding), $size, $trunc);
3381
+		} else {
3382
+			return $string;
3383
+		}
3384
+	} else {
3385
+		return 'BadParam3CallingDolTrunc';
3386
+	}
3387
+	}
2968 3388
 
2969 3389
 /**
2970 3390
  *	Show picto whatever it's its name (generic function)
@@ -3097,7 +3517,9 @@  discard block
 block discarded – undo
3097 3517
 			} elseif (in_array($pictowithouttext, array('1uparrow', '1downarrow', '1leftarrow', '1rightarrow', '1uparrow_selected', '1downarrow_selected', '1leftarrow_selected', '1rightarrow_selected'))) {
3098 3518
 			    $convertarray = array('1uparrow'=>'caret-up', '1downarrow'=>'caret-down', '1leftarrow'=>'caret-left', '1rightarrow'=>'caret-right', '1uparrow_selected'=>'caret-up', '1downarrow_selected'=>'caret-down', '1leftarrow_selected'=>'caret-left', '1rightarrow_selected'=>'caret-right');
3099 3519
 			    $fakey = 'fa-'.$convertarray[$pictowithouttext];
3100
-			    if (preg_match('/selected/', $pictowithouttext)) $facolor = '#888';
3520
+			    if (preg_match('/selected/', $pictowithouttext)) {
3521
+			    	$facolor = '#888';
3522
+			    }
3101 3523
 				$marginleftonlyshort = 1;
3102 3524
 			} elseif (!empty($arrayconvpictotofa[$pictowithouttext]))
3103 3525
 			{
@@ -3239,9 +3661,12 @@  discard block
 block discarded – undo
3239 3661
  */
3240 3662
 function img_object($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $srconly = 0, $notitle = 0)
3241 3663
 {
3242
-	if (strpos($picto, '^') === 0) return img_picto($titlealt, str_replace('^', '', $picto), $moreatt, $pictoisfullpath, $srconly, $notitle);
3243
-	else return img_picto($titlealt, 'object_'.$picto, $moreatt, $pictoisfullpath, $srconly, $notitle);
3244
-}
3664
+	if (strpos($picto, '^') === 0) {
3665
+		return img_picto($titlealt, str_replace('^', '', $picto), $moreatt, $pictoisfullpath, $srconly, $notitle);
3666
+	} else {
3667
+		return img_picto($titlealt, 'object_'.$picto, $moreatt, $pictoisfullpath, $srconly, $notitle);
3668
+	}
3669
+	}
3245 3670
 
3246 3671
 /**
3247 3672
  *	Show weather picto
@@ -3263,7 +3688,9 @@  discard block
 block discarded – undo
3263 3688
 		$leveltopicto = array(0=>'weather-clear.png', 1=>'weather-few-clouds.png', 2=>'weather-clouds.png', 3=>'weather-many-clouds.png', 4=>'weather-storm.png');
3264 3689
 		//return '<i class="fa fa-weather-level'.$picto.'"></i>';
3265 3690
 		$picto = $leveltopicto[$picto];
3266
-	} elseif (!preg_match('/(\.png|\.gif)$/i', $picto)) $picto .= '.png';
3691
+	} elseif (!preg_match('/(\.png|\.gif)$/i', $picto)) {
3692
+		$picto .= '.png';
3693
+	}
3267 3694
 
3268 3695
 	$path = DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/weather/'.$picto;
3269 3696
 
@@ -3284,17 +3711,22 @@  discard block
 block discarded – undo
3284 3711
 {
3285 3712
 	global $conf;
3286 3713
 
3287
-	if (!preg_match('/(\.png|\.gif)$/i', $picto)) $picto .= '.png';
3714
+	if (!preg_match('/(\.png|\.gif)$/i', $picto)) {
3715
+		$picto .= '.png';
3716
+	}
3288 3717
 
3289
-	if ($pictoisfullpath) $path = $picto;
3290
-	else {
3718
+	if ($pictoisfullpath) {
3719
+		$path = $picto;
3720
+	} else {
3291 3721
 		$path = DOL_URL_ROOT.'/theme/common/'.$picto;
3292 3722
 
3293 3723
 		if (!empty($conf->global->MAIN_MODULE_CAN_OVERWRITE_COMMONICONS))
3294 3724
 		{
3295 3725
 			$themepath = DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/'.$picto;
3296 3726
 
3297
-			if (file_exists($themepath)) $path = $themepath;
3727
+			if (file_exists($themepath)) {
3728
+				$path = $themepath;
3729
+			}
3298 3730
 		}
3299 3731
 	}
3300 3732
 
@@ -3334,7 +3766,9 @@  discard block
 block discarded – undo
3334 3766
 			$numaction = 0;
3335 3767
 		}
3336 3768
 	}
3337
-	if (!is_numeric($numaction)) $numaction = 0;
3769
+	if (!is_numeric($numaction)) {
3770
+		$numaction = 0;
3771
+	}
3338 3772
 
3339 3773
 	return img_picto($titlealt, 'stcomm'.$numaction.'.png');
3340 3774
 }
@@ -3350,7 +3784,9 @@  discard block
 block discarded – undo
3350 3784
 {
3351 3785
 	global $langs;
3352 3786
 
3353
-	if ($titlealt == 'default') $titlealt = $langs->trans('Show');
3787
+	if ($titlealt == 'default') {
3788
+		$titlealt = $langs->trans('Show');
3789
+	}
3354 3790
 
3355 3791
 	return img_picto($titlealt, 'pdf'.$size.'.png');
3356 3792
 }
@@ -3366,7 +3802,9 @@  discard block
 block discarded – undo
3366 3802
 {
3367 3803
 	global $langs;
3368 3804
 
3369
-	if ($titlealt == 'default') $titlealt = $langs->trans('Add');
3805
+	if ($titlealt == 'default') {
3806
+		$titlealt = $langs->trans('Add');
3807
+	}
3370 3808
 
3371 3809
 	return img_picto($titlealt, 'edit_add.png', $other);
3372 3810
 }
@@ -3381,7 +3819,9 @@  discard block
 block discarded – undo
3381 3819
 {
3382 3820
 	global $langs;
3383 3821
 
3384
-	if ($titlealt == 'default') $titlealt = $langs->trans('Remove');
3822
+	if ($titlealt == 'default') {
3823
+		$titlealt = $langs->trans('Remove');
3824
+	}
3385 3825
 
3386 3826
 	return img_picto($titlealt, 'edit_remove.png', $other);
3387 3827
 }
@@ -3398,7 +3838,9 @@  discard block
 block discarded – undo
3398 3838
 {
3399 3839
 	global $langs;
3400 3840
 
3401
-	if ($titlealt == 'default') $titlealt = $langs->trans('Modify');
3841
+	if ($titlealt == 'default') {
3842
+		$titlealt = $langs->trans('Modify');
3843
+	}
3402 3844
 
3403 3845
 	return img_picto($titlealt, 'edit.png', ($float ? 'style="float: '.($langs->tab_translate["DIRECTION"] == 'rtl' ? 'left' : 'right').'"' : "").($other ? ' '.$other : ''));
3404 3846
 }
@@ -3415,7 +3857,9 @@  discard block
 block discarded – undo
3415 3857
 {
3416 3858
 	global $langs;
3417 3859
 
3418
-	if ($titlealt == 'default') $titlealt = $langs->trans('View');
3860
+	if ($titlealt == 'default') {
3861
+		$titlealt = $langs->trans('View');
3862
+	}
3419 3863
 
3420 3864
 	$moreatt = ($float ? 'style="float: right" ' : '').$other;
3421 3865
 
@@ -3434,7 +3878,9 @@  discard block
 block discarded – undo
3434 3878
 {
3435 3879
 	global $langs;
3436 3880
 
3437
-	if ($titlealt == 'default') $titlealt = $langs->trans('Delete');
3881
+	if ($titlealt == 'default') {
3882
+		$titlealt = $langs->trans('Delete');
3883
+	}
3438 3884
 
3439 3885
 	return img_picto($titlealt, 'delete.png', $other, false, 0, 0, '', $morecss);
3440 3886
 }
@@ -3449,7 +3895,9 @@  discard block
 block discarded – undo
3449 3895
 function img_printer($titlealt = "default", $other = '')
3450 3896
 {
3451 3897
 	global $langs;
3452
-	if ($titlealt == "default") $titlealt = $langs->trans("Print");
3898
+	if ($titlealt == "default") {
3899
+		$titlealt = $langs->trans("Print");
3900
+	}
3453 3901
 	return img_picto($titlealt, 'printer.png', $other);
3454 3902
 }
3455 3903
 
@@ -3464,7 +3912,9 @@  discard block
 block discarded – undo
3464 3912
 {
3465 3913
 	global $langs;
3466 3914
 
3467
-	if ($titlealt == 'default') $titlealt = $langs->trans('Split');
3915
+	if ($titlealt == 'default') {
3916
+		$titlealt = $langs->trans('Split');
3917
+	}
3468 3918
 
3469 3919
 	return img_picto($titlealt, 'split.png', $other);
3470 3920
 }
@@ -3482,8 +3932,11 @@  discard block
 block discarded – undo
3482 3932
 
3483 3933
 	if ($usealttitle)
3484 3934
 	{
3485
-		if (is_string($usealttitle)) $usealttitle = dol_escape_htmltag($usealttitle);
3486
-		else $usealttitle = $langs->trans('Info');
3935
+		if (is_string($usealttitle)) {
3936
+			$usealttitle = dol_escape_htmltag($usealttitle);
3937
+		} else {
3938
+			$usealttitle = $langs->trans('Info');
3939
+		}
3487 3940
 	}
3488 3941
 
3489 3942
 	return img_picto($usealttitle, 'info.png', 'style="vertical-align: middle;'.($usehelpcursor == 1 ? ' cursor: help' : ($usehelpcursor == 2 ? ' cursor: pointer' : '')).'"');
@@ -3499,7 +3952,9 @@  discard block
 block discarded – undo
3499 3952
 {
3500 3953
 	global $langs;
3501 3954
 
3502
-	if ($titlealt == 'default') $titlealt = $langs->trans('Informations');
3955
+	if ($titlealt == 'default') {
3956
+		$titlealt = $langs->trans('Informations');
3957
+	}
3503 3958
 
3504 3959
 	return img_picto($titlealt, 'info.png', 'style="vertical-align: middle;"');
3505 3960
 }
@@ -3516,7 +3971,9 @@  discard block
 block discarded – undo
3516 3971
 {
3517 3972
 	global $langs;
3518 3973
 
3519
-	if ($titlealt == 'default') $titlealt = $langs->trans('Warning');
3974
+	if ($titlealt == 'default') {
3975
+		$titlealt = $langs->trans('Warning');
3976
+	}
3520 3977
 
3521 3978
 	//return '<div class="imglatecoin">'.img_picto($titlealt, 'warning_white.png', 'class="pictowarning valignmiddle"'.($moreatt ? ($moreatt == '1' ? ' style="float: right"' : ' '.$moreatt): '')).'</div>';
3522 3979
 	return img_picto($titlealt, 'warning.png', 'class="'.$morecss.'"'.($moreatt ? ($moreatt == '1' ? ' style="float: right"' : ' '.$moreatt) : ''));
@@ -3532,7 +3989,9 @@  discard block
 block discarded – undo
3532 3989
 {
3533 3990
 	global $langs;
3534 3991
 
3535
-	if ($titlealt == 'default') $titlealt = $langs->trans('Error');
3992
+	if ($titlealt == 'default') {
3993
+		$titlealt = $langs->trans('Error');
3994
+	}
3536 3995
 
3537 3996
 	return img_picto($titlealt, 'error.png');
3538 3997
 }
@@ -3548,7 +4007,9 @@  discard block
 block discarded – undo
3548 4007
 {
3549 4008
 	global $langs;
3550 4009
 
3551
-	if ($titlealt == 'default') $titlealt = $langs->trans('Next');
4010
+	if ($titlealt == 'default') {
4011
+		$titlealt = $langs->trans('Next');
4012
+	}
3552 4013
 
3553 4014
 	//return img_picto($titlealt, 'next.png', $moreatt);
3554 4015
 	return '<span class="fa fa-chevron-right paddingright paddingleft" title="'.dol_escape_htmltag($titlealt).'"></span>';
@@ -3565,7 +4026,9 @@  discard block
 block discarded – undo
3565 4026
 {
3566 4027
 	global $langs;
3567 4028
 
3568
-	if ($titlealt == 'default') $titlealt = $langs->trans('Previous');
4029
+	if ($titlealt == 'default') {
4030
+		$titlealt = $langs->trans('Previous');
4031
+	}
3569 4032
 
3570 4033
 	//return img_picto($titlealt, 'previous.png', $moreatt);
3571 4034
 	return '<span class="fa fa-chevron-left paddingright paddingleft" title="'.dol_escape_htmltag($titlealt).'"></span>';
@@ -3583,7 +4046,9 @@  discard block
 block discarded – undo
3583 4046
 {
3584 4047
 	global $langs;
3585 4048
 
3586
-	if ($titlealt == 'default') $titlealt = $langs->trans('Down');
4049
+	if ($titlealt == 'default') {
4050
+		$titlealt = $langs->trans('Down');
4051
+	}
3587 4052
 
3588 4053
 	return img_picto($titlealt, ($selected ? '1downarrow_selected.png' : '1downarrow.png'), 'class="imgdown'.($moreclass ? " ".$moreclass : "").'"');
3589 4054
 }
@@ -3600,7 +4065,9 @@  discard block
 block discarded – undo
3600 4065
 {
3601 4066
 	global $langs;
3602 4067
 
3603
-	if ($titlealt == 'default') $titlealt = $langs->trans('Up');
4068
+	if ($titlealt == 'default') {
4069
+		$titlealt = $langs->trans('Up');
4070
+	}
3604 4071
 
3605 4072
 	return img_picto($titlealt, ($selected ? '1uparrow_selected.png' : '1uparrow.png'), 'class="imgup'.($moreclass ? " ".$moreclass : "").'"');
3606 4073
 }
@@ -3636,7 +4103,9 @@  discard block
 block discarded – undo
3636 4103
 {
3637 4104
 	global $langs;
3638 4105
 
3639
-	if ($titlealt == 'default') $titlealt = $langs->trans('Right');
4106
+	if ($titlealt == 'default') {
4107
+		$titlealt = $langs->trans('Right');
4108
+	}
3640 4109
 
3641 4110
 	return img_picto($titlealt, ($selected ? '1rightarrow_selected.png' : '1rightarrow.png'), $moreatt);
3642 4111
 }
@@ -3652,9 +4121,13 @@  discard block
 block discarded – undo
3652 4121
 {
3653 4122
 	global $langs;
3654 4123
 
3655
-	if ($titlealt == 'default') $titlealt = $langs->trans('Active');
4124
+	if ($titlealt == 'default') {
4125
+		$titlealt = $langs->trans('Active');
4126
+	}
3656 4127
 
3657
-	if ($allow == 1) return img_picto($titlealt, 'tick.png');
4128
+	if ($allow == 1) {
4129
+		return img_picto($titlealt, 'tick.png');
4130
+	}
3658 4131
 
3659 4132
 	return '-';
3660 4133
 }
@@ -3668,7 +4141,9 @@  discard block
 block discarded – undo
3668 4141
  */
3669 4142
 function img_credit_card($brand, $morecss = null)
3670 4143
 {
3671
-	if (is_null($morecss)) $morecss = 'fa-2x';
4144
+	if (is_null($morecss)) {
4145
+		$morecss = 'fa-2x';
4146
+	}
3672 4147
 
3673 4148
 	if ($brand == 'visa' || $brand == 'Visa') {
3674 4149
 		$brand = 'cc-visa';
@@ -3705,7 +4180,9 @@  discard block
 block discarded – undo
3705 4180
 	$mimeimg = dol_mimetype($file, '', 2);
3706 4181
 	$mimefa = dol_mimetype($file, '', 4);
3707 4182
 
3708
-	if (empty($titlealt)) $titlealt = 'Mime type: '.$mimetype;
4183
+	if (empty($titlealt)) {
4184
+		$titlealt = 'Mime type: '.$mimetype;
4185
+	}
3709 4186
 
3710 4187
 	//return img_picto_common($titlealt, 'mime/'.$mimeimg, 'class="'.$morecss.'"');
3711 4188
 	return '<i class="fa fa-'.$mimefa.' paddingright"'.($titlealt ? ' title="'.$titlealt.'"' : '').'></i>';
@@ -3723,7 +4200,9 @@  discard block
 block discarded – undo
3723 4200
 {
3724 4201
 	global $conf, $langs;
3725 4202
 
3726
-	if ($titlealt == 'default') $titlealt = $langs->trans('Search');
4203
+	if ($titlealt == 'default') {
4204
+		$titlealt = $langs->trans('Search');
4205
+	}
3727 4206
 
3728 4207
 	$img = img_picto($titlealt, 'search.png', $other, false, 1);
3729 4208
 
@@ -3744,7 +4223,9 @@  discard block
 block discarded – undo
3744 4223
 {
3745 4224
 	global $conf, $langs;
3746 4225
 
3747
-	if ($titlealt == 'default') $titlealt = $langs->trans('Search');
4226
+	if ($titlealt == 'default') {
4227
+		$titlealt = $langs->trans('Search');
4228
+	}
3748 4229
 
3749 4230
 	$img = img_picto($titlealt, 'searchclear.png', $other, false, 1);
3750 4231
 
@@ -3773,7 +4254,9 @@  discard block
 block discarded – undo
3773 4254
 	{
3774 4255
 		$result = img_picto($text, 'info', 'class="hideonsmartphone'.($morecss ? ' '.$morecss : '').'"');
3775 4256
 	} else {
3776
-		if (empty($conf->use_javascript_ajax)) $textfordropdown = '';
4257
+		if (empty($conf->use_javascript_ajax)) {
4258
+			$textfordropdown = '';
4259
+		}
3777 4260
 
3778 4261
 		$class = (empty($admin) ? 'undefined' : ($admin == '1' ? 'info' : $admin));
3779 4262
 		$result = ($nodiv ? '' : '<div class="'.$class.' hideonsmartphone'.($morecss ? ' '.$morecss : '').($textfordropdown ? ' hidden' : '').'">').'<span class="fa fa-info-circle" title="'.dol_escape_htmltag($admin ? $langs->trans('InfoAdmin') : $langs->trans('Note')).'"></span> '.$text.($nodiv ? '' : '</div>');
@@ -3826,15 +4309,21 @@  discard block
 block discarded – undo
3826 4309
 	// Load translation files required by the page
3827 4310
     $langs->loadLangs(array('main', 'errors'));
3828 4311
 
3829
-	if ($_SERVER['DOCUMENT_ROOT'])    // Mode web
4312
+	if ($_SERVER['DOCUMENT_ROOT']) {
4313
+		// Mode web
3830 4314
 	{
3831 4315
 		$out .= $langs->trans("DolibarrHasDetectedError").".<br>\n";
3832
-		if (!empty($conf->global->MAIN_FEATURES_LEVEL)) $out .= "You use an experimental or develop level of features, so please do NOT report any bugs, except if problem is confirmed moving option MAIN_FEATURES_LEVEL back to 0.<br>\n";
4316
+	}
4317
+		if (!empty($conf->global->MAIN_FEATURES_LEVEL)) {
4318
+			$out .= "You use an experimental or develop level of features, so please do NOT report any bugs, except if problem is confirmed moving option MAIN_FEATURES_LEVEL back to 0.<br>\n";
4319
+		}
3833 4320
 		$out .= $langs->trans("InformationToHelpDiagnose").":<br>\n";
3834 4321
 
3835 4322
 		$out .= "<b>".$langs->trans("Date").":</b> ".dol_print_date(time(), 'dayhourlog')."<br>\n";
3836 4323
 		$out .= "<b>".$langs->trans("Dolibarr").":</b> ".DOL_VERSION." - https://www.dolibarr.org<br>\n";
3837
-		if (isset($conf->global->MAIN_FEATURES_LEVEL)) $out .= "<b>".$langs->trans("LevelOfFeature").":</b> ".$conf->global->MAIN_FEATURES_LEVEL."<br>\n";
4324
+		if (isset($conf->global->MAIN_FEATURES_LEVEL)) {
4325
+			$out .= "<b>".$langs->trans("LevelOfFeature").":</b> ".$conf->global->MAIN_FEATURES_LEVEL."<br>\n";
4326
+		}
3838 4327
 		if (function_exists("phpversion"))
3839 4328
 		{
3840 4329
 			$out .= "<b>".$langs->trans("PHP").":</b> ".phpversion()."<br>\n";
@@ -3865,9 +4354,11 @@  discard block
 block discarded – undo
3865 4354
 
3866 4355
 	if (is_object($db))
3867 4356
 	{
3868
-		if ($_SERVER['DOCUMENT_ROOT'])  // Mode web
4357
+		if ($_SERVER['DOCUMENT_ROOT']) {
4358
+			// Mode web
3869 4359
 		{
3870 4360
 			$out .= "<b>".$langs->trans("DatabaseTypeManager").":</b> ".$db->type."<br>\n";
4361
+		}
3871 4362
 			$out .= "<b>".$langs->trans("RequestLastAccessInError").":</b> ".($db->lastqueryerror() ?dol_escape_htmltag($db->lastqueryerror()) : $langs->trans("ErrorNoRequestInError"))."<br>\n";
3872 4363
 			$out .= "<b>".$langs->trans("ReturnCodeLastAccessInError").":</b> ".($db->lasterrno() ?dol_escape_htmltag($db->lasterrno()) : $langs->trans("ErrorNoRequestInError"))."<br>\n";
3873 4364
 			$out .= "<b>".$langs->trans("InformationLastAccessInError").":</b> ".($db->lasterror() ?dol_escape_htmltag($db->lasterror()) : $langs->trans("ErrorNoRequestInError"))."<br>\n";
@@ -3889,17 +4380,26 @@  discard block
 block discarded – undo
3889 4380
 		$langs->load("errors");
3890 4381
 
3891 4382
 		// Merge all into $errors array
3892
-		if (is_array($error) && is_array($errors)) $errors = array_merge($error, $errors);
3893
-		elseif (is_array($error)) $errors = $error;
3894
-		elseif (is_array($errors)) $errors = array_merge(array($error), $errors);
3895
-		else $errors = array_merge(array($error));
4383
+		if (is_array($error) && is_array($errors)) {
4384
+			$errors = array_merge($error, $errors);
4385
+		} elseif (is_array($error)) {
4386
+			$errors = $error;
4387
+		} elseif (is_array($errors)) {
4388
+			$errors = array_merge(array($error), $errors);
4389
+		} else {
4390
+			$errors = array_merge(array($error));
4391
+		}
3896 4392
 
3897 4393
 		foreach ($errors as $msg)
3898 4394
 		{
3899
-			if (empty($msg)) continue;
3900
-			if ($_SERVER['DOCUMENT_ROOT'])  // Mode web
4395
+			if (empty($msg)) {
4396
+				continue;
4397
+			}
4398
+			if ($_SERVER['DOCUMENT_ROOT']) {
4399
+				// Mode web
3901 4400
 			{
3902 4401
 				$out .= "<b>".$langs->trans("Message").":</b> ".dol_escape_htmltag($msg)."<br>\n";
4402
+			}
3903 4403
 			} else // Mode CLI
3904 4404
 			{
3905 4405
 				$out .= '> '.$langs->transnoentities("Message").":\n".$msg."\n";
@@ -3917,8 +4417,9 @@  discard block
 block discarded – undo
3917 4417
 		$out .= "<br>\n";
3918 4418
 	}
3919 4419
 
3920
-	if (empty($dolibarr_main_prod)) print $out;
3921
-	else {
4420
+	if (empty($dolibarr_main_prod)) {
4421
+		print $out;
4422
+	} else {
3922 4423
 		// This should not happen, except if there is a bug somewhere. Enabled and check log in such case.
3923 4424
 		print 'This website or feature is currently temporarly not available.<br><br>This may be due to a maintenance operation. Current status of operation are on next line...<br><br>'."\n";
3924 4425
 		$langs->load("errors");
@@ -3944,14 +4445,18 @@  discard block
 block discarded – undo
3944 4445
 {
3945 4446
 	global $langs, $conf;
3946 4447
 
3947
-	if (empty($email)) $email = $conf->global->MAIN_INFO_SOCIETE_MAIL;
4448
+	if (empty($email)) {
4449
+		$email = $conf->global->MAIN_INFO_SOCIETE_MAIL;
4450
+	}
3948 4451
 
3949 4452
 	$langs->load("errors");
3950 4453
 	$now = dol_now();
3951 4454
 
3952 4455
 	print '<br><div class="center login_main_message"><div class="'.$morecss.'">';
3953 4456
 	print $langs->trans("ErrorContactEMail", $email, $prefixcode.dol_print_date($now, '%Y%m%d%H%M%S'));
3954
-	if ($errormessage) print '<br><br>'.$errormessage;
4457
+	if ($errormessage) {
4458
+		print '<br><br>'.$errormessage;
4459
+	}
3955 4460
 	if (is_array($errormessages) && count($errormessages))
3956 4461
 	{
3957 4462
 		foreach ($errormessages as $mesgtoshow)
@@ -4004,14 +4509,19 @@  discard block
 block discarded – undo
4004 4509
 	global $conf, $langs, $form;
4005 4510
 	//print "$name, $file, $field, $begin, $options, $moreattrib, $sortfield, $sortorder<br>\n";
4006 4511
 
4007
-	if ($moreattrib == 'class="right"') $prefix .= 'right '; // For backward compatibility
4512
+	if ($moreattrib == 'class="right"') {
4513
+		$prefix .= 'right ';
4514
+	}
4515
+	// For backward compatibility
4008 4516
 
4009 4517
 	$sortorder = strtoupper($sortorder);
4010 4518
 	$out = '';
4011 4519
 	$sortimg = '';
4012 4520
 
4013 4521
 	$tag = 'th';
4014
-	if ($thead == 2) $tag = 'div';
4522
+	if ($thead == 2) {
4523
+		$tag = 'div';
4524
+	}
4015 4525
 
4016 4526
 	$tmpsortfield = explode(',', $sortfield);
4017 4527
 	$sortfield1 = trim($tmpsortfield[0]); // If $sortfield is 'd.datep,d.id', it becomes 'd.datep'
@@ -4034,28 +4544,36 @@  discard block
 block discarded – undo
4034 4544
 		$out .= '>';
4035 4545
 	}
4036 4546
 
4037
-	if (empty($thead) && $field && empty($disablesortlink))    // If this is a sort field
4547
+	if (empty($thead) && $field && empty($disablesortlink)) {
4548
+		// If this is a sort field
4038 4549
 	{
4039 4550
 		$options = preg_replace('/sortfield=([a-zA-Z0-9,\s\.]+)/i', '', $moreparam);
4551
+	}
4040 4552
 		$options = preg_replace('/sortorder=([a-zA-Z0-9,\s\.]+)/i', '', $options);
4041 4553
 		$options = preg_replace('/&+/i', '&', $options);
4042
-		if (!preg_match('/^&/', $options)) $options = '&'.$options;
4554
+		if (!preg_match('/^&/', $options)) {
4555
+			$options = '&'.$options;
4556
+		}
4043 4557
 
4044 4558
 		$sortordertouseinlink = '';
4045
-		if ($field1 != $sortfield1) // We are on another field than current sorted field
4559
+		if ($field1 != $sortfield1) {
4560
+			// We are on another field than current sorted field
4046 4561
 		{
4047 4562
 			if (preg_match('/^DESC/i', $sortorder))
4048 4563
 			{
4049 4564
 				$sortordertouseinlink .= str_repeat('desc,', count(explode(',', $field)));
4565
+		}
4050 4566
 			} else // We reverse the var $sortordertouseinlink
4051 4567
 			{
4052 4568
 				$sortordertouseinlink .= str_repeat('asc,', count(explode(',', $field)));
4053 4569
 			}
4054 4570
 		} else // We are on field that is the first current sorting criteria
4055 4571
 		{
4056
-			if (preg_match('/^ASC/i', $sortorder))	// We reverse the var $sortordertouseinlink
4572
+			if (preg_match('/^ASC/i', $sortorder)) {
4573
+				// We reverse the var $sortordertouseinlink
4057 4574
 			{
4058 4575
 				$sortordertouseinlink .= str_repeat('desc,', count(explode(',', $field)));
4576
+			}
4059 4577
 			} else {
4060 4578
 				$sortordertouseinlink .= str_repeat('asc,', count(explode(',', $field)));
4061 4579
 			}
@@ -4066,20 +4584,29 @@  discard block
 block discarded – undo
4066 4584
 		$out .= '>';
4067 4585
 	}
4068 4586
 
4069
-	if ($tooltip) $out .= $form->textwithpicto($langs->trans($name), $langs->trans($tooltip));
4070
-	else $out .= $langs->trans($name);
4587
+	if ($tooltip) {
4588
+		$out .= $form->textwithpicto($langs->trans($name), $langs->trans($tooltip));
4589
+	} else {
4590
+		$out .= $langs->trans($name);
4591
+	}
4071 4592
 
4072
-	if (empty($thead) && $field && empty($disablesortlink))    // If this is a sort field
4593
+	if (empty($thead) && $field && empty($disablesortlink)) {
4594
+		// If this is a sort field
4073 4595
 	{
4074 4596
 		$out .= '</a>';
4075 4597
 	}
4598
+	}
4076 4599
 
4077
-	if (empty($thead) && $field)    // If this is a sort field
4600
+	if (empty($thead) && $field) {
4601
+		// If this is a sort field
4078 4602
 	{
4079 4603
 		$options = preg_replace('/sortfield=([a-zA-Z0-9,\s\.]+)/i', '', $moreparam);
4604
+	}
4080 4605
 		$options = preg_replace('/sortorder=([a-zA-Z0-9,\s\.]+)/i', '', $options);
4081 4606
 		$options = preg_replace('/&+/i', '&', $options);
4082
-		if (!preg_match('/^&/', $options)) $options = '&'.$options;
4607
+		if (!preg_match('/^&/', $options)) {
4608
+			$options = '&'.$options;
4609
+		}
4083 4610
 
4084 4611
 		if (!$sortorder || $field1 != $sortfield1)
4085 4612
 		{
@@ -4156,12 +4683,16 @@  discard block
 block discarded – undo
4156 4683
 
4157 4684
 	$return = '';
4158 4685
 
4159
-	if ($picto == 'setup') $picto = 'generic';
4686
+	if ($picto == 'setup') {
4687
+		$picto = 'generic';
4688
+	}
4160 4689
 
4161 4690
 	$return .= "\n";
4162 4691
 	$return .= '<table '.($id ? 'id="'.$id.'" ' : '').'class="centpercent notopnoleftnoright table-fiche-title'.($morecssontable ? ' '.$morecssontable : '').'">'; // maring bottom must be same than into print_barre_list
4163 4692
 	$return .= '<tr class="titre">';
4164
-	if ($picto) $return .= '<td class="nobordernopadding widthpictotitle valignmiddle col-picto">'.img_picto('', $picto, 'class="valignmiddle widthpictotitle pictotitle"', $pictoisfullpath).'</td>';
4693
+	if ($picto) {
4694
+		$return .= '<td class="nobordernopadding widthpictotitle valignmiddle col-picto">'.img_picto('', $picto, 'class="valignmiddle widthpictotitle pictotitle"', $pictoisfullpath).'</td>';
4695
+	}
4165 4696
 	$return .= '<td class="nobordernopadding valignmiddle col-title">';
4166 4697
 	$return .= '<div class="titre inline-block">'.$titre.'</div>';
4167 4698
 	$return .= '</td>';
@@ -4209,9 +4740,15 @@  discard block
 block discarded – undo
4209 4740
 	$savtotalnboflines = $totalnboflines;
4210 4741
 	$totalnboflines = abs($totalnboflines);
4211 4742
 
4212
-	if ($picto == 'setup') $picto = 'title_setup.png';
4213
-	if (($conf->browser->name == 'ie') && $picto == 'generic') $picto = 'title.gif';
4214
-	if ($limit < 0) $limit = $conf->liste_limit;
4743
+	if ($picto == 'setup') {
4744
+		$picto = 'title_setup.png';
4745
+	}
4746
+	if (($conf->browser->name == 'ie') && $picto == 'generic') {
4747
+		$picto = 'title.gif';
4748
+	}
4749
+	if ($limit < 0) {
4750
+		$limit = $conf->liste_limit;
4751
+	}
4215 4752
 	if ($savlimit != 0 && (($num > $limit) || ($num == -1) || ($limit == 0)))
4216 4753
 	{
4217 4754
 		$nextpage = 1;
@@ -4226,10 +4763,14 @@  discard block
 block discarded – undo
4226 4763
 
4227 4764
 	// Left
4228 4765
 
4229
-	if ($picto && $titre) print '<td class="nobordernopadding widthpictotitle valignmiddle col-picto">'.img_picto('', $picto, 'class="valignmiddle pictotitle widthpictotitle"', $pictoisfullpath).'</td>';
4766
+	if ($picto && $titre) {
4767
+		print '<td class="nobordernopadding widthpictotitle valignmiddle col-picto">'.img_picto('', $picto, 'class="valignmiddle pictotitle widthpictotitle"', $pictoisfullpath).'</td>';
4768
+	}
4230 4769
 	print '<td class="nobordernopadding valignmiddle col-title">';
4231 4770
 	print '<div class="titre inline-block">'.$titre;
4232
-	if (!empty($titre) && $savtotalnboflines >= 0 && (string) $savtotalnboflines != '') print '<span class="opacitymedium colorblack paddingleft">('.$totalnboflines.')</span>';
4771
+	if (!empty($titre) && $savtotalnboflines >= 0 && (string) $savtotalnboflines != '') {
4772
+		print '<span class="opacitymedium colorblack paddingleft">('.$totalnboflines.')</span>';
4773
+	}
4233 4774
 	print '</div></td>';
4234 4775
 
4235 4776
 	// Center
@@ -4240,19 +4781,28 @@  discard block
 block discarded – undo
4240 4781
 
4241 4782
 	// Right
4242 4783
 	print '<td class="nobordernopadding valignmiddle right">';
4243
-	if ($sortfield) $options .= "&sortfield=".urlencode($sortfield);
4244
-	if ($sortorder) $options .= "&sortorder=".urlencode($sortorder);
4784
+	if ($sortfield) {
4785
+		$options .= "&sortfield=".urlencode($sortfield);
4786
+	}
4787
+	if ($sortorder) {
4788
+		$options .= "&sortorder=".urlencode($sortorder);
4789
+	}
4245 4790
 	// Show navigation bar
4246 4791
 	$pagelist = '';
4247 4792
 	if ($savlimit != 0 && ($page > 0 || $num > $limit))
4248 4793
 	{
4249
-		if ($totalnboflines)	// If we know total nb of lines
4794
+		if ($totalnboflines) {
4795
+			// If we know total nb of lines
4250 4796
 		{
4251 4797
 			// Define nb of extra page links before and after selected page + ... + first or last
4252 4798
 			$maxnbofpage = (empty($conf->dol_optimize_smallscreen) ? 4 : 0);
4799
+		}
4253 4800
 
4254
-			if ($limit > 0) $nbpages = ceil($totalnboflines / $limit);
4255
-			else $nbpages = 1;
4801
+			if ($limit > 0) {
4802
+				$nbpages = ceil($totalnboflines / $limit);
4803
+			} else {
4804
+				$nbpages = 1;
4805
+			}
4256 4806
 			$cpt = ($page - $maxnbofpage);
4257 4807
 			if ($cpt < 0) { $cpt = 0; }
4258 4808
 
@@ -4260,8 +4810,11 @@  discard block
 block discarded – undo
4260 4810
 			{
4261 4811
 				if (empty($pagenavastextinput)) {
4262 4812
 					$pagelist .= '<li class="pagination"><a href="'.$file.'?page=0'.$options.'">1</a></li>';
4263
-					if ($cpt > 2) $pagelist .= '<li class="pagination"><span class="inactive">...</span></li>';
4264
-					elseif ($cpt == 2) $pagelist .= '<li class="pagination"><a href="'.$file.'?page=1'.$options.'">2</a></li>';
4813
+					if ($cpt > 2) {
4814
+						$pagelist .= '<li class="pagination"><span class="inactive">...</span></li>';
4815
+					} elseif ($cpt == 2) {
4816
+						$pagelist .= '<li class="pagination"><a href="'.$file.'?page=1'.$options.'">2</a></li>';
4817
+					}
4265 4818
 				}
4266 4819
 			}
4267 4820
 
@@ -4287,8 +4840,11 @@  discard block
 block discarded – undo
4287 4840
 			if (empty($pagenavastextinput)) {
4288 4841
 				if ($cpt < $nbpages)
4289 4842
 				{
4290
-					if ($cpt < $nbpages - 2) $pagelist .= '<li class="pagination"><span class="inactive">...</span></li>';
4291
-					elseif ($cpt == $nbpages - 2) $pagelist .= '<li class="pagination"><a href="'.$file.'?page='.($nbpages - 2).$options.'">'.($nbpages - 1).'</a></li>';
4843
+					if ($cpt < $nbpages - 2) {
4844
+						$pagelist .= '<li class="pagination"><span class="inactive">...</span></li>';
4845
+					} elseif ($cpt == $nbpages - 2) {
4846
+						$pagelist .= '<li class="pagination"><a href="'.$file.'?page='.($nbpages - 2).$options.'">'.($nbpages - 1).'</a></li>';
4847
+					}
4292 4848
 					$pagelist .= '<li class="pagination"><a href="'.$file.'?page='.($nbpages - 1).$options.'">'.$nbpages.'</a></li>';
4293 4849
 				}
4294 4850
 			} else {
@@ -4348,15 +4904,21 @@  discard block
 block discarded – undo
4348 4904
 		$pagesizechoices = '10:10,15:15,20:20,30:30,40:40,50:50,100:100,250:250,500:500,1000:1000,5000:5000';
4349 4905
 		//$pagesizechoices.=',0:'.$langs->trans("All");     // Not yet supported
4350 4906
 		//$pagesizechoices.=',2:2';
4351
-		if (!empty($conf->global->MAIN_PAGESIZE_CHOICES)) $pagesizechoices = $conf->global->MAIN_PAGESIZE_CHOICES;
4907
+		if (!empty($conf->global->MAIN_PAGESIZE_CHOICES)) {
4908
+			$pagesizechoices = $conf->global->MAIN_PAGESIZE_CHOICES;
4909
+		}
4352 4910
 
4353 4911
 		print '<li class="pagination">';
4354 4912
 		print '<select class="flat selectlimit" name="limit" title="'.dol_escape_htmltag($langs->trans("MaxNbOfRecordPerPage")).'">';
4355 4913
 		$tmpchoice = explode(',', $pagesizechoices);
4356 4914
 		$tmpkey = $limit.':'.$limit;
4357
-		if (!in_array($tmpkey, $tmpchoice)) $tmpchoice[] = $tmpkey;
4915
+		if (!in_array($tmpkey, $tmpchoice)) {
4916
+			$tmpchoice[] = $tmpkey;
4917
+		}
4358 4918
 		$tmpkey = $conf->liste_limit.':'.$conf->liste_limit;
4359
-		if (!in_array($tmpkey, $tmpchoice)) $tmpchoice[] = $tmpkey;
4919
+		if (!in_array($tmpkey, $tmpchoice)) {
4920
+			$tmpchoice[] = $tmpkey;
4921
+		}
4360 4922
 		asort($tmpchoice, SORT_NUMERIC);
4361 4923
 		foreach ($tmpchoice as $val)
4362 4924
 		{
@@ -4444,12 +5006,15 @@  discard block
 block discarded – undo
4444 5006
 	}
4445 5007
 
4446 5008
 	// If rate is '9/9/9' we don't change it.  If rate is '9.000' we apply price()
4447
-	if (!preg_match('/\//', $rate)) $ret = price($rate, 0, '', 0, 0).($addpercent ? '%' : '');
4448
-	else {
5009
+	if (!preg_match('/\//', $rate)) {
5010
+		$ret = price($rate, 0, '', 0, 0).($addpercent ? '%' : '');
5011
+	} else {
4449 5012
 		// TODO Split on / and output with a price2num to have clean numbers without ton of 000.
4450 5013
 		$ret = $rate.($addpercent ? '%' : '');
4451 5014
 	}
4452
-	if (($info_bits & 1) && $usestarfornpr >= 0) $ret .= ' *';
5015
+	if (($info_bits & 1) && $usestarfornpr >= 0) {
5016
+		$ret .= ' *';
5017
+	}
4453 5018
 	$ret .= $morelabel;
4454 5019
 	return $ret;
4455 5020
 }
@@ -4475,21 +5040,35 @@  discard block
 block discarded – undo
4475 5040
 	global $langs, $conf;
4476 5041
 
4477 5042
 	// Clean parameters
4478
-	if (empty($amount)) $amount = 0; // To have a numeric value if amount not defined or = ''
5043
+	if (empty($amount)) {
5044
+		$amount = 0;
5045
+	}
5046
+	// To have a numeric value if amount not defined or = ''
4479 5047
 	$amount = (is_numeric($amount) ? $amount : 0); // Check if amount is numeric, for example, an error occured when amount value = o (letter) instead 0 (number)
4480
-	if ($rounding < 0) $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
5048
+	if ($rounding < 0) {
5049
+		$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
5050
+	}
4481 5051
 	$nbdecimal = $rounding;
4482 5052
 
4483 5053
 	// Output separators by default (french)
4484 5054
 	$dec = ','; $thousand = ' ';
4485 5055
 
4486 5056
 	// If $outlangs not forced, we use use language
4487
-	if (!is_object($outlangs)) $outlangs = $langs;
5057
+	if (!is_object($outlangs)) {
5058
+		$outlangs = $langs;
5059
+	}
4488 5060
 
4489
-	if ($outlangs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal")  $dec = $outlangs->transnoentitiesnoconv("SeparatorDecimal");
4490
-	if ($outlangs->transnoentitiesnoconv("SeparatorThousand") != "SeparatorThousand") $thousand = $outlangs->transnoentitiesnoconv("SeparatorThousand");
4491
-	if ($thousand == 'None') $thousand = '';
4492
-	elseif ($thousand == 'Space') $thousand = ' ';
5061
+	if ($outlangs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal") {
5062
+		$dec = $outlangs->transnoentitiesnoconv("SeparatorDecimal");
5063
+	}
5064
+	if ($outlangs->transnoentitiesnoconv("SeparatorThousand") != "SeparatorThousand") {
5065
+		$thousand = $outlangs->transnoentitiesnoconv("SeparatorThousand");
5066
+	}
5067
+	if ($thousand == 'None') {
5068
+		$thousand = '';
5069
+	} elseif ($thousand == 'Space') {
5070
+		$thousand = ' ';
5071
+	}
4493 5072
 	//print "outlangs=".$outlangs->defaultlang." amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'<br>";
4494 5073
 
4495 5074
 	//print "amount=".$amount."-";
@@ -4502,7 +5081,9 @@  discard block
 block discarded – undo
4502 5081
 	$end = '';
4503 5082
 
4504 5083
 	// We increase nbdecimal if there is more decimal than asked (to not loose information)
4505
-	if (dol_strlen($decpart) > $nbdecimal) $nbdecimal = dol_strlen($decpart);
5084
+	if (dol_strlen($decpart) > $nbdecimal) {
5085
+		$nbdecimal = dol_strlen($decpart);
5086
+	}
4506 5087
 	// Si on depasse max
4507 5088
 	if ($trunc && $nbdecimal > $conf->global->MAIN_MAX_DECIMALS_SHOWN)
4508 5089
 	{
@@ -4515,7 +5096,9 @@  discard block
 block discarded – undo
4515 5096
 	}
4516 5097
 
4517 5098
 	// If force rounding
4518
-	if ($forcerounding >= 0) $nbdecimal = $forcerounding;
5099
+	if ($forcerounding >= 0) {
5100
+		$nbdecimal = $forcerounding;
5101
+	}
4519 5102
 
4520 5103
 	// Format number
4521 5104
 	$output = number_format($amount, $nbdecimal, $dec, $thousand);
@@ -4528,7 +5111,9 @@  discard block
 block discarded – undo
4528 5111
 	$cursymbolbefore = $cursymbolafter = '';
4529 5112
 	if ($currency_code)
4530 5113
 	{
4531
-		if ($currency_code == 'auto') $currency_code = $conf->currency;
5114
+		if ($currency_code == 'auto') {
5115
+			$currency_code = $conf->currency;
5116
+		}
4532 5117
 
4533 5118
 		$listofcurrenciesbefore = array('AUD', 'CAD', 'CNY', 'COP', 'CLP', 'GBP', 'HKD', 'MXN', 'PEN', 'USD');
4534 5119
 		$listoflanguagesbefore = array('nl_NL');
@@ -4572,14 +5157,22 @@  discard block
 block discarded – undo
4572 5157
 	// Numbers must be '1234.56'
4573 5158
 	// Decimal delimiter for PHP and database SQL requests must be '.'
4574 5159
 	$dec = ','; $thousand = ' ';
4575
-	if ($langs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal")  $dec = $langs->transnoentitiesnoconv("SeparatorDecimal");
4576
-	if ($langs->transnoentitiesnoconv("SeparatorThousand") != "SeparatorThousand") $thousand = $langs->transnoentitiesnoconv("SeparatorThousand");
4577
-	if ($thousand == 'None') $thousand = '';
4578
-	elseif ($thousand == 'Space') $thousand = ' ';
5160
+	if ($langs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal") {
5161
+		$dec = $langs->transnoentitiesnoconv("SeparatorDecimal");
5162
+	}
5163
+	if ($langs->transnoentitiesnoconv("SeparatorThousand") != "SeparatorThousand") {
5164
+		$thousand = $langs->transnoentitiesnoconv("SeparatorThousand");
5165
+	}
5166
+	if ($thousand == 'None') {
5167
+		$thousand = '';
5168
+	} elseif ($thousand == 'Space') {
5169
+		$thousand = ' ';
5170
+	}
4579 5171
 	//print "amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'<br>";
4580 5172
 
4581 5173
 	// Convert value to universal number format (no thousand separator, '.' as decimal separator)
4582
-	if ($alreadysqlnb != 1)	// If not a PHP number or unknown, we change format
5174
+	if ($alreadysqlnb != 1) {
5175
+		// If not a PHP number or unknown, we change format
4583 5176
 	{
4584 5177
 		//print 'PP'.$amount.' - '.$dec.' - '.$thousand.' - '.intval($amount).'<br>';
4585 5178
 
@@ -4588,7 +5181,9 @@  discard block
 block discarded – undo
4588 5181
 		if (is_numeric($amount))
4589 5182
 		{
4590 5183
 			// We put in temps value of decimal ("0.00001"). Works with 0 and 2.0E-5 and 9999.10
4591
-			$temps = sprintf("%0.10F", $amount - intval($amount)); // temps=0.0000000000 or 0.0000200000 or 9999.1000000000
5184
+			$temps = sprintf("%0.10F", $amount - intval($amount));
5185
+	}
5186
+	// temps=0.0000000000 or 0.0000200000 or 9999.1000000000
4592 5187
 			$temps = preg_replace('/([\.1-9])0+$/', '\\1', $temps); // temps=0. or 0.00002 or 9999.1
4593 5188
 			$nbofdec = max(0, dol_strlen($temps) - 2); // -2 to remove "0."
4594 5189
 			$amount = number_format($amount, $nbofdec, $dec, $thousand);
@@ -4596,7 +5191,10 @@  discard block
 block discarded – undo
4596 5191
 		//print "QQ".$amount.'<br>';
4597 5192
 
4598 5193
 		// Now make replace (the main goal of function)
4599
-		if ($thousand != ',' && $thousand != '.') $amount = str_replace(',', '.', $amount); // To accept 2 notations for french users
5194
+		if ($thousand != ',' && $thousand != '.') {
5195
+			$amount = str_replace(',', '.', $amount);
5196
+		}
5197
+		// To accept 2 notations for french users
4600 5198
 		$amount = str_replace(' ', '', $amount); // To avoid spaces
4601 5199
 		$amount = str_replace($thousand, '', $amount); // Replace of thousand before replace of dec to avoid pb if thousand is .
4602 5200
 		$amount = str_replace($dec, '.', $amount);
@@ -4606,14 +5204,25 @@  discard block
 block discarded – undo
4606 5204
 	if ($rounding)
4607 5205
 	{
4608 5206
 		$nbofdectoround = '';
4609
-		if ($rounding == 'MU')     $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_UNIT;
4610
-		elseif ($rounding == 'MT') $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_TOT;
4611
-		elseif ($rounding == 'MS') $nbofdectoround = empty($conf->global->MAIN_MAX_DECIMALS_STOCK) ? 5 : $conf->global->MAIN_MAX_DECIMALS_STOCK;
4612
-		elseif ($rounding == 'CR') $nbofdectoround = 8;
4613
-		elseif (is_numeric($rounding))  $nbofdectoround = $rounding;
5207
+		if ($rounding == 'MU') {
5208
+			$nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_UNIT;
5209
+		} elseif ($rounding == 'MT') {
5210
+			$nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_TOT;
5211
+		} elseif ($rounding == 'MS') {
5212
+			$nbofdectoround = empty($conf->global->MAIN_MAX_DECIMALS_STOCK) ? 5 : $conf->global->MAIN_MAX_DECIMALS_STOCK;
5213
+		} elseif ($rounding == 'CR') {
5214
+			$nbofdectoround = 8;
5215
+		} elseif (is_numeric($rounding)) {
5216
+			$nbofdectoround = $rounding;
5217
+		}
4614 5218
 		//print "RR".$amount.' - '.$nbofdectoround.'<br>';
4615
-		if (dol_strlen($nbofdectoround)) $amount = round($amount, $nbofdectoround); // $nbofdectoround can be 0.
4616
-		else return 'ErrorBadParameterProvidedToFunction';
5219
+		if (dol_strlen($nbofdectoround)) {
5220
+			$amount = round($amount, $nbofdectoround);
5221
+		}
5222
+		// $nbofdectoround can be 0.
5223
+		else {
5224
+			return 'ErrorBadParameterProvidedToFunction';
5225
+		}
4617 5226
 		//print 'SS'.$amount.' - '.$nbofdec.' - '.$dec.' - '.$thousand.' - '.$nbofdectoround.'<br>';
4618 5227
 
4619 5228
 		// Convert amount to format with dolibarr dec and thousand (this is because PHP convert a number
@@ -4630,7 +5239,10 @@  discard block
 block discarded – undo
4630 5239
 
4631 5240
 		// Always make replace because each math function (like round) replace
4632 5241
 		// with local values and we want a number that has a SQL string format x.y
4633
-		if ($thousand != ',' && $thousand != '.') $amount = str_replace(',', '.', $amount); // To accept 2 notations for french users
5242
+		if ($thousand != ',' && $thousand != '.') {
5243
+			$amount = str_replace(',', '.', $amount);
5244
+		}
5245
+		// To accept 2 notations for french users
4634 5246
 		$amount = str_replace(' ', '', $amount); // To avoid spaces
4635 5247
 		$amount = str_replace($thousand, '', $amount); // Replace of thousand before replace of dec to avoid pb if thousand is .
4636 5248
 		$amount = str_replace($dec, '.', $amount);
@@ -4706,15 +5318,19 @@  discard block
 block discarded – undo
4706 5318
 {
4707 5319
 	global $db, $conf, $mysoc;
4708 5320
 
4709
-	if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) $thirdparty_seller = $mysoc;
5321
+	if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) {
5322
+		$thirdparty_seller = $mysoc;
5323
+	}
4710 5324
 
4711 5325
 	dol_syslog("get_localtax tva=".$vatrate." local=".$local." thirdparty_buyer id=".(is_object($thirdparty_buyer) ? $thirdparty_buyer->id : '')."/country_code=".(is_object($thirdparty_buyer) ? $thirdparty_buyer->country_code : '')." thirdparty_seller id=".$thirdparty_seller->id."/country_code=".$thirdparty_seller->country_code." thirdparty_seller localtax1_assuj=".$thirdparty_seller->localtax1_assuj."  thirdparty_seller localtax2_assuj=".$thirdparty_seller->localtax2_assuj);
4712 5326
 
4713 5327
 	$vatratecleaned = $vatrate;
4714 5328
 	$reg = array();
4715
-	if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg))      // If vat is "xx (yy)"
5329
+	if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
5330
+		// If vat is "xx (yy)"
4716 5331
 	{
4717 5332
 		$vatratecleaned = trim($reg[1]);
5333
+	}
4718 5334
 		$vatratecode = $reg[2];
4719 5335
 	}
4720 5336
 
@@ -4724,33 +5340,50 @@  discard block
 block discarded – undo
4724 5340
 	}*/
4725 5341
 
4726 5342
 	// Some test to guess with no need to make database access
4727
-	if ($mysoc->country_code == 'ES') // For spain localtaxes 1 and 2, tax is qualified if buyer use local tax
5343
+	if ($mysoc->country_code == 'ES') {
5344
+		// For spain localtaxes 1 and 2, tax is qualified if buyer use local tax
4728 5345
 	{
4729 5346
 		if ($local == 1)
4730 5347
 		{
4731 5348
 			if (!$mysoc->localtax1_assuj || (string) $vatratecleaned == "0") return 0;
5349
+	}
4732 5350
 			if ($thirdparty_seller->id == $mysoc->id)
4733 5351
 			{
4734
-				if (!$thirdparty_buyer->localtax1_assuj) return 0;
5352
+				if (!$thirdparty_buyer->localtax1_assuj) {
5353
+					return 0;
5354
+				}
4735 5355
 			} else {
4736
-				if (!$thirdparty_seller->localtax1_assuj) return 0;
5356
+				if (!$thirdparty_seller->localtax1_assuj) {
5357
+					return 0;
5358
+				}
4737 5359
 			}
4738 5360
 		}
4739 5361
 
4740 5362
 		if ($local == 2)
4741 5363
 		{
4742 5364
 			//if (! $mysoc->localtax2_assuj || (string) $vatratecleaned == "0") return 0;
4743
-			if (!$mysoc->localtax2_assuj) return 0; // If main vat is 0, IRPF may be different than 0.
5365
+			if (!$mysoc->localtax2_assuj) {
5366
+				return 0;
5367
+			}
5368
+			// If main vat is 0, IRPF may be different than 0.
4744 5369
 			if ($thirdparty_seller->id == $mysoc->id)
4745 5370
 			{
4746
-				if (!$thirdparty_buyer->localtax2_assuj) return 0;
5371
+				if (!$thirdparty_buyer->localtax2_assuj) {
5372
+					return 0;
5373
+				}
4747 5374
 			} else {
4748
-				if (!$thirdparty_seller->localtax2_assuj) return 0;
5375
+				if (!$thirdparty_seller->localtax2_assuj) {
5376
+					return 0;
5377
+				}
4749 5378
 			}
4750 5379
 		}
4751 5380
 	} else {
4752
-		if ($local == 1 && !$thirdparty_seller->localtax1_assuj) return 0;
4753
-		if ($local == 2 && !$thirdparty_seller->localtax2_assuj) return 0;
5381
+		if ($local == 1 && !$thirdparty_seller->localtax1_assuj) {
5382
+			return 0;
5383
+		}
5384
+		if ($local == 2 && !$thirdparty_seller->localtax2_assuj) {
5385
+			return 0;
5386
+		}
4754 5387
 	}
4755 5388
 
4756 5389
 	// For some country MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY is forced to on.
@@ -4766,27 +5399,33 @@  discard block
 block discarded – undo
4766 5399
 		{
4767 5400
 			if ($thirdparty_seller != $mysoc)
4768 5401
 			{
4769
-				if (!isOnlyOneLocalTax($local))  // TODO We should provide $vatrate to search on correct line and not always on line with highest vat rate
5402
+				if (!isOnlyOneLocalTax($local)) {
5403
+					// TODO We should provide $vatrate to search on correct line and not always on line with highest vat rate
4770 5404
 				{
4771 5405
 					return $thirdparty_seller->localtax1_value;
4772 5406
 				}
5407
+				}
4773 5408
 			} else // i am the seller
4774 5409
 			{
4775
-				if (!isOnlyOneLocalTax($local))  // TODO If seller is me, why not always returning this, even if there is only one locatax vat.
5410
+				if (!isOnlyOneLocalTax($local)) {
5411
+					// TODO If seller is me, why not always returning this, even if there is only one locatax vat.
4776 5412
 				{
4777 5413
 					return $conf->global->MAIN_INFO_VALUE_LOCALTAX1;
4778 5414
 				}
5415
+				}
4779 5416
 			}
4780 5417
 		}
4781 5418
 		if ($local == 2)
4782 5419
 		{
4783 5420
 			if ($thirdparty_seller != $mysoc)
4784 5421
 			{
4785
-				if (!isOnlyOneLocalTax($local))  // TODO We should provide $vatrate to search on correct line and not always on line with highest vat rate
5422
+				if (!isOnlyOneLocalTax($local)) {
5423
+					// TODO We should provide $vatrate to search on correct line and not always on line with highest vat rate
4786 5424
 				// TODO We should also return value defined on thirdparty only if defined
4787 5425
 				{
4788 5426
 					return $thirdparty_seller->localtax2_value;
4789 5427
 				}
5428
+				}
4790 5429
 			} else // i am the seller
4791 5430
 			{
4792 5431
 				if (in_array($mysoc->country_code, array('ES')))
@@ -4804,16 +5443,24 @@  discard block
 block discarded – undo
4804 5443
    	$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
4805 5444
    	$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$thirdparty_seller->country_code."'";
4806 5445
    	$sql .= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
4807
-   	if ($vatratecode) $sql .= " AND t.code ='".$vatratecode."'"; // If we have the code, we use it in priority
4808
-   	else $sql .= " AND t.recuperableonly ='".$vatnpr."'";
5446
+   	if ($vatratecode) {
5447
+   		$sql .= " AND t.code ='".$vatratecode."'";
5448
+   	}
5449
+   	// If we have the code, we use it in priority
5450
+   	else {
5451
+   		$sql .= " AND t.recuperableonly ='".$vatnpr."'";
5452
+   	}
4809 5453
    	dol_syslog("get_localtax", LOG_DEBUG);
4810 5454
    	$resql = $db->query($sql);
4811 5455
 
4812 5456
    	if ($resql)
4813 5457
    	{
4814 5458
    		$obj = $db->fetch_object($resql);
4815
-   		if ($local == 1) return $obj->localtax1;
4816
-   		elseif ($local == 2) return $obj->localtax2;
5459
+   		if ($local == 1) {
5460
+   			return $obj->localtax1;
5461
+   		} elseif ($local == 2) {
5462
+   			return $obj->localtax2;
5463
+   		}
4817 5464
 	}
4818 5465
 
4819 5466
 	return 0;
@@ -4862,8 +5509,11 @@  discard block
 block discarded – undo
4862 5509
 	if ($resql)
4863 5510
 	{
4864 5511
 		$obj = $db->fetch_object($resql);
4865
-		if ($local == 1) return $obj->localtax1;
4866
-		elseif ($local == 2) return $obj->localtax2;
5512
+		if ($local == 1) {
5513
+			return $obj->localtax1;
5514
+		} elseif ($local == 2) {
5515
+			return $obj->localtax2;
5516
+		}
4867 5517
 	}
4868 5518
 
4869 5519
 	return 0;
@@ -4890,13 +5540,16 @@  discard block
 block discarded – undo
4890 5540
 	// Search local taxes
4891 5541
 	$sql = "SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy";
4892 5542
 	$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t";
4893
-	if ($firstparamisid) $sql .= " WHERE t.rowid = ".(int) $vatrate;
4894
-	else {
5543
+	if ($firstparamisid) {
5544
+		$sql .= " WHERE t.rowid = ".(int) $vatrate;
5545
+	} else {
4895 5546
 		$vatratecleaned = $vatrate;
4896 5547
 		$vatratecode = '';
4897
-		if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg))      // If vat is "xx (yy)"
5548
+		if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
5549
+			// If vat is "xx (yy)"
4898 5550
 		{
4899 5551
 			$vatratecleaned = $reg[1];
5552
+		}
4900 5553
 			$vatratecode = $reg[2];
4901 5554
 		}
4902 5555
 
@@ -4905,16 +5558,23 @@  discard block
 block discarded – undo
4905 5558
 		else $sql.= " WHERE t.fk_pays = c.rowid AND c.code = '".$seller->country_code."'";*/
4906 5559
 		$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$seller->country_code."'";
4907 5560
 		$sql .= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
4908
-		if ($vatratecode) $sql .= " AND t.code = '".$vatratecode."'";
5561
+		if ($vatratecode) {
5562
+			$sql .= " AND t.code = '".$vatratecode."'";
5563
+		}
4909 5564
 	}
4910 5565
 
4911 5566
 	$resql = $db->query($sql);
4912 5567
 	if ($resql)
4913 5568
 	{
4914 5569
 		$obj = $db->fetch_object($resql);
4915
-		if ($obj) return array('rowid'=>$obj->rowid, 'code'=>$obj->code, 'rate'=>$obj->rate, 'npr'=>$obj->npr, 'accountancy_code_sell'=>$obj->accountancy_code_sell, 'accountancy_code_buy'=>$obj->accountancy_code_buy);
4916
-		else return array();
4917
-	} else dol_print_error($db);
5570
+		if ($obj) {
5571
+			return array('rowid'=>$obj->rowid, 'code'=>$obj->code, 'rate'=>$obj->rate, 'npr'=>$obj->npr, 'accountancy_code_sell'=>$obj->accountancy_code_sell, 'accountancy_code_buy'=>$obj->accountancy_code_buy);
5572
+		} else {
5573
+			return array();
5574
+		}
5575
+	} else {
5576
+		dol_print_error($db);
5577
+	}
4918 5578
 
4919 5579
 	return array();
4920 5580
 }
@@ -4944,22 +5604,32 @@  discard block
 block discarded – undo
4944 5604
 	// Search local taxes
4945 5605
 	$sql  = "SELECT t.taux as rate, t.code, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.accountancy_code_sell, t.accountancy_code_buy";
4946 5606
 	$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t";
4947
-	if ($firstparamisid) $sql .= " WHERE t.rowid = ".(int) $vatrate;
4948
-	else {
5607
+	if ($firstparamisid) {
5608
+		$sql .= " WHERE t.rowid = ".(int) $vatrate;
5609
+	} else {
4949 5610
 		$vatratecleaned = $vatrate;
4950 5611
 		$vatratecode = '';
4951 5612
 		$reg = array();
4952
-		if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg))      // If vat is "x.x (yy)"
5613
+		if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
5614
+			// If vat is "x.x (yy)"
4953 5615
 		{
4954 5616
 			$vatratecleaned = $reg[1];
5617
+		}
4955 5618
 			$vatratecode = $reg[2];
4956 5619
 		}
4957 5620
 
4958 5621
 		$sql .= ", ".MAIN_DB_PREFIX."c_country as c";
4959
-		if ($mysoc->country_code == 'ES') $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$buyer->country_code."'"; // local tax in spain use the buyer country ??
4960
-		else $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$seller->country_code."'";
5622
+		if ($mysoc->country_code == 'ES') {
5623
+			$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$buyer->country_code."'";
5624
+		}
5625
+		// local tax in spain use the buyer country ??
5626
+		else {
5627
+			$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$seller->country_code."'";
5628
+		}
4961 5629
 		$sql .= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
4962
-		if ($vatratecode) $sql .= " AND t.code = '".$vatratecode."'";
5630
+		if ($vatratecode) {
5631
+			$sql .= " AND t.code = '".$vatratecode."'";
5632
+		}
4963 5633
 	}
4964 5634
 
4965 5635
 	$resql = $db->query($sql);
@@ -5008,16 +5678,22 @@  discard block
 block discarded – undo
5008 5678
 		$product = new Product($db);
5009 5679
 		$result = $product->fetch($idprod);
5010 5680
 
5011
-		if ($mysoc->country_code == $thirdparty_seller->country_code) // If selling country is ours
5681
+		if ($mysoc->country_code == $thirdparty_seller->country_code) {
5682
+			// If selling country is ours
5012 5683
 		{
5013 5684
 			if ($idprodfournprice > 0)     // We want vat for product for a "supplier" object
5014 5685
 			{
5015 5686
 				$product->get_buyprice($idprodfournprice, 0, 0, 0);
5687
+		}
5016 5688
 				$ret = $product->vatrate_supplier;
5017
-				if ($product->default_vat_code) $ret .= ' ('.$product->default_vat_code.')';
5689
+				if ($product->default_vat_code) {
5690
+					$ret .= ' ('.$product->default_vat_code.')';
5691
+				}
5018 5692
 			} else {
5019 5693
 				$ret = $product->tva_tx; // Default vat of product we defined
5020
-				if ($product->default_vat_code) $ret .= ' ('.$product->default_vat_code.')';
5694
+				if ($product->default_vat_code) {
5695
+					$ret .= ' ('.$product->default_vat_code.')';
5696
+				}
5021 5697
 			}
5022 5698
 			$found = 1;
5023 5699
 		} else {
@@ -5044,11 +5720,18 @@  discard block
 block discarded – undo
5044 5720
 				if ($obj)
5045 5721
 				{
5046 5722
 					$ret = $obj->vat_rate;
5047
-					if ($obj->default_vat_code) $ret .= ' ('.$obj->default_vat_code.')';
5723
+					if ($obj->default_vat_code) {
5724
+						$ret .= ' ('.$obj->default_vat_code.')';
5725
+					}
5048 5726
 				}
5049 5727
 				$db->free($sql);
5050
-			} else dol_print_error($db);
5051
-		} else $ret = $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS; // Forced value if autodetect fails
5728
+			} else {
5729
+				dol_print_error($db);
5730
+			}
5731
+		} else {
5732
+			$ret = $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;
5733
+		}
5734
+		// Forced value if autodetect fails
5052 5735
 	}
5053 5736
 
5054 5737
 	dol_syslog("get_product_vat_for_country: ret=".$ret);
@@ -5081,7 +5764,8 @@  discard block
 block discarded – undo
5081 5764
 		$product = new Product($db);
5082 5765
 		$result = $product->fetch($idprod);
5083 5766
 
5084
-		if ($mysoc->country_code == $thirdparty_seller->country_code) // If selling country is ours
5767
+		if ($mysoc->country_code == $thirdparty_seller->country_code) {
5768
+			// If selling country is ours
5085 5769
 		{
5086 5770
 			/* Not defined yet, so we don't use this
5087 5771
 			if ($local==1) $ret=$product->localtax1_tx;
@@ -5097,6 +5781,7 @@  discard block
 block discarded – undo
5097 5781
 	{
5098 5782
 		// If vat of product for the country not found or not defined, we return higher vat of country.
5099 5783
 		$sql = "SELECT taux as vat_rate, localtax1, localtax2";
5784
+		}
5100 5785
 		$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
5101 5786
 		$sql .= " WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$thirdparty_seller->country_code."'";
5102 5787
 		$sql .= " ORDER BY t.taux DESC, t.recuperableonly ASC";
@@ -5108,10 +5793,15 @@  discard block
 block discarded – undo
5108 5793
 			$obj = $db->fetch_object($resql);
5109 5794
 			if ($obj)
5110 5795
 			{
5111
-				if ($local == 1) $ret = $obj->localtax1;
5112
-				elseif ($local == 2) $ret = $obj->localtax2;
5796
+				if ($local == 1) {
5797
+					$ret = $obj->localtax1;
5798
+				} elseif ($local == 2) {
5799
+					$ret = $obj->localtax2;
5800
+				}
5113 5801
 			}
5114
-		} else dol_print_error($db);
5802
+		} else {
5803
+			dol_print_error($db);
5804
+		}
5115 5805
 	}
5116 5806
 
5117 5807
 	dol_syslog("get_product_localtax_for_country: ret=".$ret);
@@ -5173,11 +5863,13 @@  discard block
 block discarded – undo
5173 5863
 
5174 5864
 	// Si le (pays vendeur = pays acheteur) alors la TVA par defaut=TVA du produit vendu. Fin de regle.
5175 5865
 	if (($seller_country_code == $buyer_country_code)
5176
-	|| (in_array($seller_country_code, array('FR,MC')) && in_array($buyer_country_code, array('FR', 'MC')))) // Warning ->country_code not always defined
5866
+	|| (in_array($seller_country_code, array('FR,MC')) && in_array($buyer_country_code, array('FR', 'MC')))) {
5867
+		// Warning ->country_code not always defined
5177 5868
 	{
5178 5869
 		//print 'VATRULE 2';
5179 5870
 		return get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournprice);
5180 5871
 	}
5872
+	}
5181 5873
 
5182 5874
 	// Si (vendeur et acheteur dans Communaute europeenne) et (bien vendu = moyen de transports neuf comme auto, bateau, avion) alors TVA par defaut=0 (La TVA doit etre paye par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de regle.
5183 5875
 	// Not supported
@@ -5261,24 +5953,38 @@  discard block
 block discarded – undo
5261 5953
 {
5262 5954
 	global $mysoc;
5263 5955
 
5264
-	if (!is_object($thirdparty_seller)) return -1;
5265
-	if (!is_object($thirdparty_buyer)) return -1;
5956
+	if (!is_object($thirdparty_seller)) {
5957
+		return -1;
5958
+	}
5959
+	if (!is_object($thirdparty_buyer)) {
5960
+		return -1;
5961
+	}
5266 5962
 
5267
-	if ($local == 1) // Localtax 1
5963
+	if ($local == 1) {
5964
+		// Localtax 1
5268 5965
 	{
5269 5966
 		if ($mysoc->country_code == 'ES')
5270 5967
 		{
5271 5968
 			if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) return 0;
5969
+	}
5272 5970
 		} else {
5273 5971
 			// Si vendeur non assujeti a Localtax1, localtax1 par default=0
5274
-			if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) return 0;
5275
-			if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj == 'localtax1off') return 0;
5972
+			if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) {
5973
+				return 0;
5974
+			}
5975
+			if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj == 'localtax1off') {
5976
+				return 0;
5977
+			}
5276 5978
 		}
5277
-	} elseif ($local == 2) //I Localtax 2
5979
+	} elseif ($local == 2) {
5980
+		//I Localtax 2
5278 5981
 	{
5279 5982
 		// Si vendeur non assujeti a Localtax2, localtax2 par default=0
5280 5983
 		if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) return 0;
5281
-		if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj == 'localtax2off') return 0;
5984
+	}
5985
+		if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj == 'localtax2off') {
5986
+			return 0;
5987
+		}
5282 5988
 	}
5283 5989
 
5284 5990
 	if ($thirdparty_seller->country_code == $thirdparty_buyer->country_code)
@@ -5301,25 +6007,44 @@  discard block
 block discarded – undo
5301 6007
 {
5302 6008
 	global $langs;
5303 6009
 	$result = 'unknown'; $classname = '';
5304
-	if ($yesno == 1 || strtolower($yesno) == 'yes' || strtolower($yesno) == 'true') 	// A mettre avant test sur no a cause du == 0
6010
+	if ($yesno == 1 || strtolower($yesno) == 'yes' || strtolower($yesno) == 'true') {
6011
+		// A mettre avant test sur no a cause du == 0
5305 6012
 	{
5306 6013
 		$result = $langs->trans('yes');
5307
-		if ($case == 1 || $case == 3) $result = $langs->trans("Yes");
5308
-		if ($case == 2) $result = '<input type="checkbox" value="1" checked disabled>';
5309
-		if ($case == 3) $result = '<input type="checkbox" value="1" checked disabled> '.$result;
6014
+	}
6015
+		if ($case == 1 || $case == 3) {
6016
+			$result = $langs->trans("Yes");
6017
+		}
6018
+		if ($case == 2) {
6019
+			$result = '<input type="checkbox" value="1" checked disabled>';
6020
+		}
6021
+		if ($case == 3) {
6022
+			$result = '<input type="checkbox" value="1" checked disabled> '.$result;
6023
+		}
5310 6024
 
5311 6025
 		$classname = 'ok';
5312 6026
 	} elseif ($yesno == 0 || strtolower($yesno) == 'no' || strtolower($yesno) == 'false')
5313 6027
 	{
5314 6028
 		$result = $langs->trans("no");
5315
-		if ($case == 1 || $case == 3) $result = $langs->trans("No");
5316
-		if ($case == 2) $result = '<input type="checkbox" value="0" disabled>';
5317
-		if ($case == 3) $result = '<input type="checkbox" value="0" disabled> '.$result;
6029
+		if ($case == 1 || $case == 3) {
6030
+			$result = $langs->trans("No");
6031
+		}
6032
+		if ($case == 2) {
6033
+			$result = '<input type="checkbox" value="0" disabled>';
6034
+		}
6035
+		if ($case == 3) {
6036
+			$result = '<input type="checkbox" value="0" disabled> '.$result;
6037
+		}
5318 6038
 
5319
-		if ($color == 2) $classname = 'ok';
5320
-		else $classname = 'error';
6039
+		if ($color == 2) {
6040
+			$classname = 'ok';
6041
+		} else {
6042
+			$classname = 'error';
6043
+		}
6044
+	}
6045
+	if ($color) {
6046
+		return '<font class="'.$classname.'">'.$result.'</font>';
5321 6047
 	}
5322
-	if ($color) return '<font class="'.$classname.'">'.$result.'</font>';
5323 6048
 	return $result;
5324 6049
 }
5325 6050
 
@@ -5345,16 +6070,27 @@  discard block
 block discarded – undo
5345 6070
 	$path = '';
5346 6071
 
5347 6072
 	$arrayforoldpath = array('cheque', 'user', 'category', 'holiday', 'supplier_invoice', 'invoice_supplier', 'mailing', 'supplier_payment');
5348
-	if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) $arrayforoldpath[] = 'product';
6073
+	if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
6074
+		$arrayforoldpath[] = 'product';
6075
+	}
5349 6076
 	if (!empty($level) && in_array($modulepart, $arrayforoldpath))
5350 6077
 	{
5351 6078
 		// This part should be removed once all code is using "get_exdir" to forge path, with all parameters provided.
5352
-		if (empty($alpha)) $num = preg_replace('/([^0-9])/i', '', $num);
5353
-		else $num = preg_replace('/^.*\-/i', '', $num);
6079
+		if (empty($alpha)) {
6080
+			$num = preg_replace('/([^0-9])/i', '', $num);
6081
+		} else {
6082
+			$num = preg_replace('/^.*\-/i', '', $num);
6083
+		}
5354 6084
 		$num = substr("000".$num, -$level);
5355
-		if ($level == 1) $path = substr($num, 0, 1);
5356
-		if ($level == 2) $path = substr($num, 1, 1).'/'.substr($num, 0, 1);
5357
-		if ($level == 3) $path = substr($num, 2, 1).'/'.substr($num, 1, 1).'/'.substr($num, 0, 1);
6085
+		if ($level == 1) {
6086
+			$path = substr($num, 0, 1);
6087
+		}
6088
+		if ($level == 2) {
6089
+			$path = substr($num, 1, 1).'/'.substr($num, 0, 1);
6090
+		}
6091
+		if ($level == 3) {
6092
+			$path = substr($num, 2, 1).'/'.substr($num, 1, 1).'/'.substr($num, 0, 1);
6093
+		}
5358 6094
 	} else {
5359 6095
 		// TODO
5360 6096
 		// We will enhance here a common way of forging path for document storage
@@ -5367,7 +6103,9 @@  discard block
 block discarded – undo
5367 6103
 		}
5368 6104
 	}
5369 6105
 
5370
-	if (empty($withoutslash) && !empty($path)) $path .= '/';
6106
+	if (empty($withoutslash) && !empty($path)) {
6107
+		$path .= '/';
6108
+	}
5371 6109
 
5372 6110
 	return $path;
5373 6111
 }
@@ -5387,7 +6125,9 @@  discard block
 block discarded – undo
5387 6125
 	dol_syslog("functions.lib::dol_mkdir: dir=".$dir, LOG_INFO);
5388 6126
 
5389 6127
 	$dir_osencoded = dol_osencode($dir);
5390
-	if (@is_dir($dir_osencoded)) return 0;
6128
+	if (@is_dir($dir_osencoded)) {
6129
+		return 0;
6130
+	}
5391 6131
 
5392 6132
 	$nberr = 0;
5393 6133
 	$nbcreated = 0;
@@ -5403,9 +6143,15 @@  discard block
 block discarded – undo
5403 6143
 	$num = count($cdir);
5404 6144
 	for ($i = 0; $i < $num; $i++)
5405 6145
 	{
5406
-		if ($i > 0) $ccdir .= '/'.$cdir[$i];
5407
-		else $ccdir .= $cdir[$i];
5408
-		if (preg_match("/^.:$/", $ccdir, $regs)) continue; // Si chemin Windows incomplet, on poursuit par rep suivant
6146
+		if ($i > 0) {
6147
+			$ccdir .= '/'.$cdir[$i];
6148
+		} else {
6149
+			$ccdir .= $cdir[$i];
6150
+		}
6151
+		if (preg_match("/^.:$/", $ccdir, $regs)) {
6152
+			continue;
6153
+		}
6154
+		// Si chemin Windows incomplet, on poursuit par rep suivant
5409 6155
 
5410 6156
 		// Attention, le is_dir() peut echouer bien que le rep existe.
5411 6157
 		// (ex selon config de open_basedir)
@@ -5469,7 +6215,9 @@  discard block
 block discarded – undo
5469 6215
  */
5470 6216
 function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto = 'UTF-8', $strip_tags = 0)
5471 6217
 {
5472
-	if ($removelinefeed == 2) $stringtoclean = preg_replace('/<br[^>]*>(\n|\r)+/ims', '<br>', $stringtoclean);
6218
+	if ($removelinefeed == 2) {
6219
+		$stringtoclean = preg_replace('/<br[^>]*>(\n|\r)+/ims', '<br>', $stringtoclean);
6220
+	}
5473 6221
 	$temp = preg_replace('/<br[^>]*>/i', "\n", $stringtoclean);
5474 6222
 
5475 6223
 	if ($strip_tags) {
@@ -5486,7 +6234,9 @@  discard block
 block discarded – undo
5486 6234
 	$temp = dol_html_entity_decode($temp, ENT_COMPAT, $pagecodeto);
5487 6235
 
5488 6236
 	// Supprime aussi les retours
5489
-	if ($removelinefeed == 1) $temp = str_replace(array("\r\n", "\r", "\n"), " ", $temp);
6237
+	if ($removelinefeed == 1) {
6238
+		$temp = str_replace(array("\r\n", "\r", "\n"), " ", $temp);
6239
+	}
5490 6240
 
5491 6241
 	// et les espaces doubles
5492 6242
 	while (strpos($temp, "  "))
@@ -5589,7 +6339,10 @@  discard block
 block discarded – undo
5589 6339
 
5590 6340
 		$text = strtr($text, $repTable);
5591 6341
 		if ($charset == 'UTF-8') { $pattern = '/(<br[^>]*>)/Uu'; } // /U is to have UNGREEDY regex to limit to one html tag. /u is for UTF8 support
5592
-		else $pattern = '/(<br[^>]*>)/U'; // /U is to have UNGREEDY regex to limit to one html tag.
6342
+		else {
6343
+			$pattern = '/(<br[^>]*>)/U';
6344
+		}
6345
+		// /U is to have UNGREEDY regex to limit to one html tag.
5593 6346
 		$a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
5594 6347
 
5595 6348
 		$firstline = '';
@@ -5597,8 +6350,11 @@  discard block
 block discarded – undo
5597 6350
 		$nba = count($a); // 2x nb of lines in $a because $a contains also a line for each new line separator
5598 6351
 		while (($i < $nba) && ($i < ($nboflines * 2)))
5599 6352
 		{
5600
-			if ($i % 2 == 0) $firstline .= $a[$i];
5601
-			elseif (($i < (($nboflines * 2) - 1)) && ($i < ($nba - 1))) $firstline .= ($ishtml ? "<br>\n" : "\n");
6353
+			if ($i % 2 == 0) {
6354
+				$firstline .= $a[$i];
6355
+			} elseif (($i < (($nboflines * 2) - 1)) && ($i < ($nba - 1))) {
6356
+				$firstline .= ($ishtml ? "<br>\n" : "\n");
6357
+			}
5602 6358
 			$i++;
5603 6359
 		}
5604 6360
 		unset($a);
@@ -5648,15 +6404,24 @@  discard block
 block discarded – undo
5648 6404
 function dol_htmlentitiesbr($stringtoencode, $nl2brmode = 0, $pagecodefrom = 'UTF-8', $removelasteolbr = 1)
5649 6405
 {
5650 6406
 	$newstring = $stringtoencode;
5651
-	if (dol_textishtml($stringtoencode))	// Check if text is already HTML or not
6407
+	if (dol_textishtml($stringtoencode)) {
6408
+		// Check if text is already HTML or not
5652 6409
 	{
5653
-		$newstring = preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>/i', '<br>', $newstring); // Replace "<br type="_moz" />" by "<br>". It's same and avoid pb with FPDF.
5654
-		if ($removelasteolbr) $newstring = preg_replace('/<br>$/i', '', $newstring); // Remove last <br> (remove only last one)
6410
+		$newstring = preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>/i', '<br>', $newstring);
6411
+	}
6412
+	// Replace "<br type="_moz" />" by "<br>". It's same and avoid pb with FPDF.
6413
+		if ($removelasteolbr) {
6414
+			$newstring = preg_replace('/<br>$/i', '', $newstring);
6415
+		}
6416
+		// Remove last <br> (remove only last one)
5655 6417
 		$newstring = strtr($newstring, array('&'=>'__and__', '<'=>'__lt__', '>'=>'__gt__', '"'=>'__dquot__'));
5656 6418
 		$newstring = dol_htmlentities($newstring, ENT_COMPAT, $pagecodefrom); // Make entity encoding
5657 6419
 		$newstring = strtr($newstring, array('__and__'=>'&', '__lt__'=>'<', '__gt__'=>'>', '__dquot__'=>'"'));
5658 6420
 	} else {
5659
-		if ($removelasteolbr) $newstring = preg_replace('/(\r\n|\r|\n)$/i', '', $newstring); // Remove last \n (may remove several)
6421
+		if ($removelasteolbr) {
6422
+			$newstring = preg_replace('/(\r\n|\r|\n)$/i', '', $newstring);
6423
+		}
6424
+		// Remove last \n (may remove several)
5660 6425
 		$newstring = dol_nl2br(dol_htmlentities($newstring, ENT_COMPAT, $pagecodefrom), $nl2brmode);
5661 6426
 	}
5662 6427
 	// Other substitutions that htmlentities does not do
@@ -5705,9 +6470,13 @@  discard block
 block discarded – undo
5705 6470
 function dol_html_entity_decode($a, $b, $c = 'UTF-8', $keepsomeentities = 0)
5706 6471
 {
5707 6472
 	$newstring = $a;
5708
-	if ($keepsomeentities) $newstring = strtr($newstring, array('&amp;'=>'__andamp__', '&lt;'=>'__andlt__', '&gt;'=>'__andgt__', '"'=>'__dquot__'));
6473
+	if ($keepsomeentities) {
6474
+		$newstring = strtr($newstring, array('&amp;'=>'__andamp__', '&lt;'=>'__andlt__', '&gt;'=>'__andgt__', '"'=>'__dquot__'));
6475
+	}
5709 6476
 	$newstring = html_entity_decode($newstring, $b, $c);
5710
-	if ($keepsomeentities) $newstring = strtr($newstring, array('__andamp__'=>'&amp;', '__andlt__'=>'&lt;', '__andgt__'=>'&gt;', '__dquot__'=>'"'));
6477
+	if ($keepsomeentities) {
6478
+		$newstring = strtr($newstring, array('__andamp__'=>'&amp;', '__andlt__'=>'&lt;', '__andgt__'=>'&gt;', '__dquot__'=>'"'));
6479
+	}
5711 6480
 	return $newstring;
5712 6481
 }
5713 6482
 
@@ -5748,7 +6517,9 @@  discard block
 block discarded – undo
5748 6517
 			$out .= $s[$scursor];
5749 6518
 		}
5750 6519
 	}
5751
-	if ($clean) return $out;
6520
+	if ($clean) {
6521
+		return $out;
6522
+	}
5752 6523
 	return $ok;
5753 6524
 }
5754 6525
 
@@ -5762,7 +6533,9 @@  discard block
 block discarded – undo
5762 6533
  */
5763 6534
 function dol_nboflines($s, $maxchar = 0)
5764 6535
 {
5765
-	if ($s == '') return 0;
6536
+	if ($s == '') {
6537
+		return 0;
6538
+	}
5766 6539
 	$arraystring = explode("\n", $s);
5767 6540
 	$nb = count($arraystring);
5768 6541
 
@@ -5782,11 +6555,16 @@  discard block
 block discarded – undo
5782 6555
 function dol_nboflines_bis($text, $maxlinesize = 0, $charset = 'UTF-8')
5783 6556
 {
5784 6557
 	$repTable = array("\t" => " ", "\n" => "<br>", "\r" => " ", "\0" => " ", "\x0B" => " ");
5785
-	if (dol_textishtml($text)) $repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
6558
+	if (dol_textishtml($text)) {
6559
+		$repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
6560
+	}
5786 6561
 
5787 6562
 	$text = strtr($text, $repTable);
5788 6563
 	if ($charset == 'UTF-8') { $pattern = '/(<br[^>]*>)/Uu'; } // /U is to have UNGREEDY regex to limit to one html tag. /u is for UTF8 support
5789
-	else $pattern = '/(<br[^>]*>)/U'; // /U is to have UNGREEDY regex to limit to one html tag.
6564
+	else {
6565
+		$pattern = '/(<br[^>]*>)/U';
6566
+	}
6567
+	// /U is to have UNGREEDY regex to limit to one html tag.
5790 6568
 	$a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
5791 6569
 
5792 6570
 	$nblines = (int) floor((count($a) + 1) / 2);
@@ -5824,25 +6602,51 @@  discard block
 block discarded – undo
5824 6602
 {
5825 6603
 	if ($option == 1)
5826 6604
 	{
5827
-		if (preg_match('/<html/i', $msg))				return true;
5828
-		elseif (preg_match('/<body/i', $msg))			return true;
5829
-		elseif (preg_match('/<\/textarea/i', $msg))	  return true;
5830
-		elseif (preg_match('/<br/i', $msg))				return true;
6605
+		if (preg_match('/<html/i', $msg)) {
6606
+			return true;
6607
+		} elseif (preg_match('/<body/i', $msg)) {
6608
+			return true;
6609
+		} elseif (preg_match('/<\/textarea/i', $msg)) {
6610
+			return true;
6611
+		} elseif (preg_match('/<br/i', $msg)) {
6612
+			return true;
6613
+		}
5831 6614
 		return false;
5832 6615
 	} else {
5833
-		if (preg_match('/<html/i', $msg))				return true;
5834
-		elseif (preg_match('/<body/i', $msg))			return true;
5835
-		elseif (preg_match('/<\/textarea/i', $msg))	  return true;
5836
-		elseif (preg_match('/<(b|em|i|u)>/i', $msg))		return true;
5837
-		elseif (preg_match('/<br\/>/i', $msg))	  return true;
5838
-		elseif (preg_match('/<(br|div|font|li|p|span|strong|table)>/i', $msg)) 	  return true;
5839
-		elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*>/i', $msg)) return true;
5840
-		elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*\/>/i', $msg)) return true;
5841
-		elseif (preg_match('/<img\s+[^<>]*src[^<>]*>/i', $msg)) return true; // must accept <img src="http://example.com/aaa.png" />
5842
-		elseif (preg_match('/<a\s+[^<>]*href[^<>]*>/i', $msg)) return true; // must accept <a href="http://example.com/aaa.png" />
5843
-		elseif (preg_match('/<h[0-9]>/i', $msg))			return true;
5844
-		elseif (preg_match('/&[A-Z0-9]{1,6};/i', $msg))	return true; // Html entities names (http://www.w3schools.com/tags/ref_entities.asp)
5845
-		elseif (preg_match('/&#[0-9]{2,3};/i', $msg))	return true; // Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp)
6616
+		if (preg_match('/<html/i', $msg)) {
6617
+			return true;
6618
+		} elseif (preg_match('/<body/i', $msg)) {
6619
+			return true;
6620
+		} elseif (preg_match('/<\/textarea/i', $msg)) {
6621
+			return true;
6622
+		} elseif (preg_match('/<(b|em|i|u)>/i', $msg)) {
6623
+			return true;
6624
+		} elseif (preg_match('/<br\/>/i', $msg)) {
6625
+			return true;
6626
+		} elseif (preg_match('/<(br|div|font|li|p|span|strong|table)>/i', $msg)) {
6627
+			return true;
6628
+		} elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*>/i', $msg)) {
6629
+			return true;
6630
+		} elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*\/>/i', $msg)) {
6631
+			return true;
6632
+		} elseif (preg_match('/<img\s+[^<>]*src[^<>]*>/i', $msg)) {
6633
+			return true;
6634
+		}
6635
+		// must accept <img src="http://example.com/aaa.png" />
6636
+		elseif (preg_match('/<a\s+[^<>]*href[^<>]*>/i', $msg)) {
6637
+			return true;
6638
+		}
6639
+		// must accept <a href="http://example.com/aaa.png" />
6640
+		elseif (preg_match('/<h[0-9]>/i', $msg)) {
6641
+			return true;
6642
+		} elseif (preg_match('/&[A-Z0-9]{1,6};/i', $msg)) {
6643
+			return true;
6644
+		}
6645
+		// Html entities names (http://www.w3schools.com/tags/ref_entities.asp)
6646
+		elseif (preg_match('/&#[0-9]{2,3};/i', $msg)) {
6647
+			return true;
6648
+		}
6649
+		// Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp)
5846 6650
 
5847 6651
 		return false;
5848 6652
 	}
@@ -6045,10 +6849,14 @@  discard block
 block discarded – undo
6045 6849
 			if ($object->id > 0)
6046 6850
 			{
6047 6851
 				$substitutionarray['__MEMBER_ID__'] = $object->id;
6048
-				if (method_exists($object, 'getCivilityLabel')) $substitutionarray['__MEMBER_CIVILITY__'] = $object->getCivilityLabel();
6852
+				if (method_exists($object, 'getCivilityLabel')) {
6853
+					$substitutionarray['__MEMBER_CIVILITY__'] = $object->getCivilityLabel();
6854
+				}
6049 6855
 				$substitutionarray['__MEMBER_FIRSTNAME__'] = $object->firstname;
6050 6856
 				$substitutionarray['__MEMBER_LASTNAME__'] = $object->lastname;
6051
-				if (method_exists($object, 'getFullName')) $substitutionarray['__MEMBER_FULLNAME__'] = $object->getFullName($outputlangs);
6857
+				if (method_exists($object, 'getFullName')) {
6858
+					$substitutionarray['__MEMBER_FULLNAME__'] = $object->getFullName($outputlangs);
6859
+				}
6052 6860
 				$substitutionarray['__MEMBER_COMPANY__'] = $object->societe;
6053 6861
 				$substitutionarray['__MEMBER_ADDRESS__'] = $object->address;
6054 6862
 				$substitutionarray['__MEMBER_ZIP__'] = $object->zip;
@@ -6126,9 +6934,11 @@  discard block
 block discarded – undo
6126 6934
 				$substitutionarray['__PROJECT_REF__'] = (is_object($object->project) ? $object->project->ref : '');
6127 6935
 				$substitutionarray['__PROJECT_NAME__'] = (is_object($object->project) ? $object->project->title : '');
6128 6936
 			}
6129
-			if (is_object($object->projet) && $object->projet->id > 0)	// Deprecated, for backward compatibility
6937
+			if (is_object($object->projet) && $object->projet->id > 0) {
6938
+				// Deprecated, for backward compatibility
6130 6939
 			{
6131 6940
 				$substitutionarray['__PROJECT_ID__'] = (is_object($object->projet) ? $object->projet->id : '');
6941
+			}
6132 6942
 				$substitutionarray['__PROJECT_REF__'] = (is_object($object->projet) ? $object->projet->ref : '');
6133 6943
 				$substitutionarray['__PROJECT_NAME__'] = (is_object($object->projet) ? $object->projet->title : '');
6134 6944
 			}
@@ -6147,8 +6957,12 @@  discard block
 block discarded – undo
6147 6957
 					$datenextexpiration = '';
6148 6958
 					foreach ($object->lines as $line)
6149 6959
 					{
6150
-						if ($line->date_ouverture_prevue > $dateplannedstart) $dateplannedstart = $line->date_ouverture_prevue;
6151
-						if ($line->statut == 4 && $line->date_fin_prevue && (!$datenextexpiration || $line->date_fin_prevue < $datenextexpiration)) $datenextexpiration = $line->date_fin_prevue;
6960
+						if ($line->date_ouverture_prevue > $dateplannedstart) {
6961
+							$dateplannedstart = $line->date_ouverture_prevue;
6962
+						}
6963
+						if ($line->statut == 4 && $line->date_fin_prevue && (!$datenextexpiration || $line->date_fin_prevue < $datenextexpiration)) {
6964
+							$datenextexpiration = $line->date_fin_prevue;
6965
+						}
6152 6966
 					}
6153 6967
 					$substitutionarray['__CONTRACT_HIGHEST_PLANNED_START_DATE__'] = dol_print_date($dateplannedstart, 'dayrfc');
6154 6968
 					$substitutionarray['__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] = dol_print_date($dateplannedstart, 'standard');
@@ -6160,7 +6974,9 @@  discard block
 block discarded – undo
6160 6974
 			// Create dynamic tags for __EXTRAFIELD_FIELD__
6161 6975
 			if ($object->table_element && $object->id > 0)
6162 6976
 			{
6163
-				if (!is_object($extrafields)) $extrafields = new ExtraFields($db);
6977
+				if (!is_object($extrafields)) {
6978
+					$extrafields = new ExtraFields($db);
6979
+				}
6164 6980
 				$extrafields->fetch_name_optionals_label($object->table_element, true);
6165 6981
 
6166 6982
 				if ($object->fetch_optionals() > 0)
@@ -6195,9 +7011,15 @@  discard block
 block discarded – undo
6195 7011
 				require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
6196 7012
 				$outputlangs->loadLangs(array('paypal', 'other'));
6197 7013
 				$typeforonlinepayment = 'free';
6198
-				if (is_object($object) && $object->element == 'commande') $typeforonlinepayment = 'order';
6199
-				if (is_object($object) && $object->element == 'facture')  $typeforonlinepayment = 'invoice';
6200
-				if (is_object($object) && $object->element == 'member')   $typeforonlinepayment = 'member';
7014
+				if (is_object($object) && $object->element == 'commande') {
7015
+					$typeforonlinepayment = 'order';
7016
+				}
7017
+				if (is_object($object) && $object->element == 'facture') {
7018
+					$typeforonlinepayment = 'invoice';
7019
+				}
7020
+				if (is_object($object) && $object->element == 'member') {
7021
+					$typeforonlinepayment = 'member';
7022
+				}
6201 7023
 				$url = getOnlinePaymentUrl(0, $typeforonlinepayment, $substitutionarray['__REF__']);
6202 7024
 				$paymenturl = $url;
6203 7025
 			}
@@ -6210,19 +7032,31 @@  discard block
 block discarded – undo
6210 7032
 				if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD) && is_object($object) && $object->element == 'propal')
6211 7033
 				{
6212 7034
 					$substitutionarray['__DIRECTDOWNLOAD_URL_PROPOSAL__'] = $object->getLastMainDocLink($object->element);
6213
-				} else $substitutionarray['__DIRECTDOWNLOAD_URL_PROPOSAL__'] = '';
7035
+				} else {
7036
+					$substitutionarray['__DIRECTDOWNLOAD_URL_PROPOSAL__'] = '';
7037
+				}
6214 7038
 				if (!empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD) && is_object($object) && $object->element == 'commande')
6215 7039
 				{
6216 7040
 					$substitutionarray['__DIRECTDOWNLOAD_URL_ORDER__'] = $object->getLastMainDocLink($object->element);
6217
-				} else $substitutionarray['__DIRECTDOWNLOAD_URL_ORDER__'] = '';
7041
+				} else {
7042
+					$substitutionarray['__DIRECTDOWNLOAD_URL_ORDER__'] = '';
7043
+				}
6218 7044
 				if (!empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD) && is_object($object) && $object->element == 'facture')
6219 7045
 				{
6220 7046
 					$substitutionarray['__DIRECTDOWNLOAD_URL_INVOICE__'] = $object->getLastMainDocLink($object->element);
6221
-				} else $substitutionarray['__DIRECTDOWNLOAD_URL_INVOICE__'] = '';
7047
+				} else {
7048
+					$substitutionarray['__DIRECTDOWNLOAD_URL_INVOICE__'] = '';
7049
+				}
6222 7050
 
6223
-				if (is_object($object) && $object->element == 'propal') $substitutionarray['__URL_PROPOSAL__'] = DOL_MAIN_URL_ROOT."/comm/propal/card.php?id=".$object->id;
6224
-				if (is_object($object) && $object->element == 'commande') $substitutionarray['__URL_ORDER__'] = DOL_MAIN_URL_ROOT."/commande/card.php?id=".$object->id;
6225
-				if (is_object($object) && $object->element == 'facture') $substitutionarray['__URL_INVOICE__'] = DOL_MAIN_URL_ROOT."/compta/facture/card.php?id=".$object->id;
7051
+				if (is_object($object) && $object->element == 'propal') {
7052
+					$substitutionarray['__URL_PROPOSAL__'] = DOL_MAIN_URL_ROOT."/comm/propal/card.php?id=".$object->id;
7053
+				}
7054
+				if (is_object($object) && $object->element == 'commande') {
7055
+					$substitutionarray['__URL_ORDER__'] = DOL_MAIN_URL_ROOT."/commande/card.php?id=".$object->id;
7056
+				}
7057
+				if (is_object($object) && $object->element == 'facture') {
7058
+					$substitutionarray['__URL_INVOICE__'] = DOL_MAIN_URL_ROOT."/compta/facture/card.php?id=".$object->id;
7059
+				}
6226 7060
 			}
6227 7061
 		}
6228 7062
 	}
@@ -6234,14 +7068,22 @@  discard block
 block discarded – undo
6234 7068
 		$substitutionarray['__AMOUNT__']          = is_object($object) ? $object->total_ttc : '';
6235 7069
 		$substitutionarray['__AMOUNT_EXCL_TAX__'] = is_object($object) ? $object->total_ht : '';
6236 7070
 		$substitutionarray['__AMOUNT_VAT__']      = is_object($object) ? ($object->total_vat ? $object->total_vat : $object->total_tva) : '';
6237
-		if ($onlykey != 2 || $mysoc->useLocalTax(1)) $substitutionarray['__AMOUNT_TAX2__']     = is_object($object) ? $object->total_localtax1 : '';
6238
-		if ($onlykey != 2 || $mysoc->useLocalTax(2)) $substitutionarray['__AMOUNT_TAX3__']     = is_object($object) ? $object->total_localtax2 : '';
7071
+		if ($onlykey != 2 || $mysoc->useLocalTax(1)) {
7072
+			$substitutionarray['__AMOUNT_TAX2__']     = is_object($object) ? $object->total_localtax1 : '';
7073
+		}
7074
+		if ($onlykey != 2 || $mysoc->useLocalTax(2)) {
7075
+			$substitutionarray['__AMOUNT_TAX3__']     = is_object($object) ? $object->total_localtax2 : '';
7076
+		}
6239 7077
 
6240 7078
 		$substitutionarray['__AMOUNT_FORMATED__']          = is_object($object) ? ($object->total_ttc ? price($object->total_ttc, 0, $outputlangs, 0, 0, -1, $conf->currency) : null) : '';
6241 7079
 		$substitutionarray['__AMOUNT_EXCL_TAX_FORMATED__'] = is_object($object) ? ($object->total_ht ? price($object->total_ht, 0, $outputlangs, 0, 0, -1, $conf->currency) : null) : '';
6242 7080
 		$substitutionarray['__AMOUNT_VAT_FORMATED__']      = is_object($object) ? ($object->total_vat ? price($object->total_vat, 0, $outputlangs, 0, 0, -1, $conf->currency) : ($object->total_tva ? price($object->total_tva, 0, $outputlangs, 0, 0, -1, $conf->currency) : null)) : '';
6243
-		if ($onlykey != 2 || $mysoc->useLocalTax(1)) $substitutionarray['__AMOUNT_TAX2_FORMATED__']     = is_object($object) ? ($object->total_localtax1 ? price($object->total_localtax1, 0, $outputlangs, 0, 0, -1, $conf->currency) : null) : '';
6244
-		if ($onlykey != 2 || $mysoc->useLocalTax(2)) $substitutionarray['__AMOUNT_TAX3_FORMATED__']     = is_object($object) ? ($object->total_localtax2 ? price($object->total_localtax2, 0, $outputlangs, 0, 0, -1, $conf->currency) : null) : '';
7081
+		if ($onlykey != 2 || $mysoc->useLocalTax(1)) {
7082
+			$substitutionarray['__AMOUNT_TAX2_FORMATED__']     = is_object($object) ? ($object->total_localtax1 ? price($object->total_localtax1, 0, $outputlangs, 0, 0, -1, $conf->currency) : null) : '';
7083
+		}
7084
+		if ($onlykey != 2 || $mysoc->useLocalTax(2)) {
7085
+			$substitutionarray['__AMOUNT_TAX3_FORMATED__']     = is_object($object) ? ($object->total_localtax2 ? price($object->total_localtax2, 0, $outputlangs, 0, 0, -1, $conf->currency) : null) : '';
7086
+		}
6245 7087
 
6246 7088
 		// TODO Add keys for foreign multicurrency
6247 7089
 
@@ -6317,9 +7159,13 @@  discard block
 block discarded – undo
6317 7159
 {
6318 7160
 	global $conf, $langs;
6319 7161
 
6320
-	if (!is_array($substitutionarray)) return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
7162
+	if (!is_array($substitutionarray)) {
7163
+		return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
7164
+	}
6321 7165
 
6322
-	if (empty($outputlangs)) $outputlangs = $langs;
7166
+	if (empty($outputlangs)) {
7167
+		$outputlangs = $langs;
7168
+	}
6323 7169
 
6324 7170
 	// Make substitution for language keys: __(AnyTranslationKey)__ or __(AnyTranslationKey|langfile)__
6325 7171
 	if (is_object($outputlangs))
@@ -6328,11 +7174,15 @@  discard block
 block discarded – undo
6328 7174
 		while (preg_match('/__\(([^\)]+)\)__/', $text, $reg))
6329 7175
 		{
6330 7176
 			$msgishtml = 0;
6331
-			if (dol_textishtml($text, 1)) $msgishtml = 1;
7177
+			if (dol_textishtml($text, 1)) {
7178
+				$msgishtml = 1;
7179
+			}
6332 7180
 
6333 7181
 			// If key is __(TranslationKey|langfile)__, then force load of langfile.lang
6334 7182
 			$tmp = explode('|', $reg[1]);
6335
-			if (!empty($tmp[1])) $outputlangs->load($tmp[1]);
7183
+			if (!empty($tmp[1])) {
7184
+				$outputlangs->load($tmp[1]);
7185
+			}
6336 7186
 
6337 7187
 			$text = preg_replace('/__\('.preg_quote($reg[1], '/').'\)__/', $msgishtml ?dol_htmlentitiesbr($outputlangs->transnoentitiesnoconv($reg[1])) : $outputlangs->transnoentitiesnoconv($reg[1]), $text);
6338 7188
 		}
@@ -6344,21 +7194,35 @@  discard block
 block discarded – undo
6344 7194
 	while (preg_match('/__\[([^\]]+)\]__/', $text, $reg))
6345 7195
 	{
6346 7196
 		$msgishtml = 0;
6347
-		if (dol_textishtml($text, 1)) $msgishtml = 1;
7197
+		if (dol_textishtml($text, 1)) {
7198
+			$msgishtml = 1;
7199
+		}
6348 7200
 
6349 7201
 		$keyfound = $reg[1];
6350
-		if (preg_match('/(_pass|_pw|password|secret|_key|key$)/i', $keyfound)) $newval = '*****forbidden*****';
6351
-		else $newval = empty($conf->global->$keyfound) ? '' : $conf->global->$keyfound;
7202
+		if (preg_match('/(_pass|_pw|password|secret|_key|key$)/i', $keyfound)) {
7203
+			$newval = '*****forbidden*****';
7204
+		} else {
7205
+			$newval = empty($conf->global->$keyfound) ? '' : $conf->global->$keyfound;
7206
+		}
6352 7207
 		$text = preg_replace('/__\['.preg_quote($keyfound, '/').'\]__/', $msgishtml ?dol_htmlentitiesbr($newval) : $newval, $text);
6353 7208
 	}
6354 7209
 
6355 7210
 	// Make substitition for array $substitutionarray
6356 7211
 	foreach ($substitutionarray as $key => $value)
6357 7212
 	{
6358
-		if (!isset($value)) continue; // If value is null, it same than not having substitution key at all into array, we do not replace.
7213
+		if (!isset($value)) {
7214
+			continue;
7215
+		}
7216
+		// If value is null, it same than not having substitution key at all into array, we do not replace.
6359 7217
 
6360
-		if ($key == '__SIGNATURE__' && (!empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) $value = ''; // Protection
6361
-		if ($key == '__USER_SIGNATURE__' && (!empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) $value = ''; // Protection
7218
+		if ($key == '__SIGNATURE__' && (!empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) {
7219
+			$value = '';
7220
+		}
7221
+		// Protection
7222
+		if ($key == '__USER_SIGNATURE__' && (!empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) {
7223
+			$value = '';
7224
+		}
7225
+		// Protection
6362 7226
 
6363 7227
 		$text = str_replace("$key", "$value", $text); // We must keep the " to work when value is 123.5 for example
6364 7228
 	}
@@ -6405,7 +7269,9 @@  discard block
 block discarded – undo
6405 7269
 		$dir = dol_buildpath($reldir, 0);
6406 7270
 
6407 7271
 		// Check if directory exists
6408
-		if (!dol_is_dir($dir)) continue;
7272
+		if (!dol_is_dir($dir)) {
7273
+			continue;
7274
+		}
6409 7275
 
6410 7276
 		$substitfiles = dol_dir_list($dir, 'files', 0, 'functions_');
6411 7277
 		foreach ($substitfiles as $substitfile)
@@ -6419,7 +7285,9 @@  discard block
 block discarded – undo
6419 7285
 				require_once $dir.$substitfile['name'];
6420 7286
 				// Call the user's function, and only if it is defined
6421 7287
 				$function_name = $module."_".$callfunc;
6422
-				if (function_exists($function_name)) $function_name($substitutionarray, $outputlangs, $object, $parameters);
7288
+				if (function_exists($function_name)) {
7289
+					$function_name($substitutionarray, $outputlangs, $object, $parameters);
7290
+				}
6423 7291
 			}
6424 7292
 		}
6425 7293
 	}
@@ -6455,7 +7323,9 @@  discard block
 block discarded – undo
6455 7323
 
6456 7324
 	$out = '';
6457 7325
 
6458
-	if (!is_object($outputlangs)) $outputlangs = $langs;
7326
+	if (!is_object($outputlangs)) {
7327
+		$outputlangs = $langs;
7328
+	}
6459 7329
 
6460 7330
 	if ($date_start && $date_end)
6461 7331
 	{
@@ -6487,11 +7357,15 @@  discard block
 block discarded – undo
6487 7357
 
6488 7358
 	$ret = '';
6489 7359
 	// If order not defined, we use the setup
6490
-	if ($nameorder < 0) $nameorder = (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION) ? 1 : 0);
7360
+	if ($nameorder < 0) {
7361
+		$nameorder = (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION) ? 1 : 0);
7362
+	}
6491 7363
 	if ($nameorder && $nameorder != 2 && $nameorder != 3)
6492 7364
 	{
6493 7365
 		$ret .= $firstname;
6494
-		if ($firstname && $lastname) $ret .= ' ';
7366
+		if ($firstname && $lastname) {
7367
+			$ret .= ' ';
7368
+		}
6495 7369
 		$ret .= $lastname;
6496 7370
 	} elseif ($nameorder == 2 || $nameorder == 3)
6497 7371
 	{
@@ -6502,7 +7376,9 @@  discard block
 block discarded – undo
6502 7376
 	    }
6503 7377
 	} else {
6504 7378
 		$ret .= $lastname;
6505
-		if ($firstname && $lastname) $ret .= ' ';
7379
+		if ($firstname && $lastname) {
7380
+			$ret .= ' ';
7381
+		}
6506 7382
 		$ret .= $firstname;
6507 7383
 	}
6508 7384
 	return $ret;
@@ -6522,14 +7398,18 @@  discard block
 block discarded – undo
6522 7398
 function setEventMessage($mesgs, $style = 'mesgs')
6523 7399
 {
6524 7400
 	//dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);		This is not deprecated, it is used by setEventMessages function
6525
-	if (!is_array($mesgs))		// If mesgs is a string
7401
+	if (!is_array($mesgs)) {
7402
+		// If mesgs is a string
6526 7403
 	{
6527 7404
 		if ($mesgs) $_SESSION['dol_events'][$style][] = $mesgs;
7405
+	}
6528 7406
 	} else // If mesgs is an array
6529 7407
 	{
6530 7408
 		foreach ($mesgs as $mesg)
6531 7409
 		{
6532
-			if ($mesg) $_SESSION['dol_events'][$style][] = $mesg;
7410
+			if ($mesg) {
7411
+				$_SESSION['dol_events'][$style][] = $mesg;
7412
+			}
6533 7413
 		}
6534 7414
 	}
6535 7415
 }
@@ -6559,10 +7439,16 @@  discard block
 block discarded – undo
6559 7439
 		}
6560 7440
 		if (empty($messagekey) || empty($_COOKIE["DOLHIDEMESSAGE".$messagekey]))
6561 7441
 		{
6562
-			if (!in_array((string) $style, array('mesgs', 'warnings', 'errors'))) dol_print_error('', 'Bad parameter style='.$style.' for setEventMessages');
6563
-			if (empty($mesgs)) setEventMessage($mesg, $style);
6564
-			else {
6565
-				if (!empty($mesg) && !in_array($mesg, $mesgs)) setEventMessage($mesg, $style); // Add message string if not already into array
7442
+			if (!in_array((string) $style, array('mesgs', 'warnings', 'errors'))) {
7443
+				dol_print_error('', 'Bad parameter style='.$style.' for setEventMessages');
7444
+			}
7445
+			if (empty($mesgs)) {
7446
+				setEventMessage($mesg, $style);
7447
+			} else {
7448
+				if (!empty($mesg) && !in_array($mesg, $mesgs)) {
7449
+					setEventMessage($mesg, $style);
7450
+				}
7451
+				// Add message string if not already into array
6566 7452
 				setEventMessage($mesgs, $style);
6567 7453
 			}
6568 7454
 		}
@@ -6582,19 +7468,25 @@  discard block
 block discarded – undo
6582 7468
 {
6583 7469
 	// Show mesgs
6584 7470
 	if (isset($_SESSION['dol_events']['mesgs'])) {
6585
-		if (empty($disabledoutputofmessages)) dol_htmloutput_mesg('', $_SESSION['dol_events']['mesgs']);
7471
+		if (empty($disabledoutputofmessages)) {
7472
+			dol_htmloutput_mesg('', $_SESSION['dol_events']['mesgs']);
7473
+		}
6586 7474
 		unset($_SESSION['dol_events']['mesgs']);
6587 7475
 	}
6588 7476
 
6589 7477
 	// Show errors
6590 7478
 	if (isset($_SESSION['dol_events']['errors'])) {
6591
-		if (empty($disabledoutputofmessages)) dol_htmloutput_mesg('', $_SESSION['dol_events']['errors'], 'error');
7479
+		if (empty($disabledoutputofmessages)) {
7480
+			dol_htmloutput_mesg('', $_SESSION['dol_events']['errors'], 'error');
7481
+		}
6592 7482
 		unset($_SESSION['dol_events']['errors']);
6593 7483
 	}
6594 7484
 
6595 7485
 	// Show warnings
6596 7486
 	if (isset($_SESSION['dol_events']['warnings'])) {
6597
-		if (empty($disabledoutputofmessages)) dol_htmloutput_mesg('', $_SESSION['dol_events']['warnings'], 'warning');
7487
+		if (empty($disabledoutputofmessages)) {
7488
+			dol_htmloutput_mesg('', $_SESSION['dol_events']['warnings'], 'warning');
7489
+		}
6598 7490
 		unset($_SESSION['dol_events']['warnings']);
6599 7491
 	}
6600 7492
 }
@@ -6638,7 +7530,9 @@  discard block
 block discarded – undo
6638 7530
 			{
6639 7531
 				$ret++;
6640 7532
 				$out .= $langs->trans($message);
6641
-				if ($ret < count($mesgarray)) $out .= "<br>\n";
7533
+				if ($ret < count($mesgarray)) {
7534
+					$out .= "<br>\n";
7535
+				}
6642 7536
 			}
6643 7537
 		}
6644 7538
 		if ($mesgstring)
@@ -6707,7 +7601,9 @@  discard block
 block discarded – undo
6707 7601
  */
6708 7602
 function dol_htmloutput_mesg($mesgstring = '', $mesgarray = array(), $style = 'ok', $keepembedded = 0)
6709 7603
 {
6710
-	if (empty($mesgstring) && (!is_array($mesgarray) || count($mesgarray) == 0)) return;
7604
+	if (empty($mesgstring) && (!is_array($mesgarray) || count($mesgarray) == 0)) {
7605
+		return;
7606
+	}
6711 7607
 
6712 7608
 	$iserror = 0;
6713 7609
 	$iswarning = 0;
@@ -6718,10 +7614,17 @@  discard block
 block discarded – undo
6718 7614
 			if ($val && preg_match('/class="error"/i', $val)) { $iserror++; break; }
6719 7615
 			if ($val && preg_match('/class="warning"/i', $val)) { $iswarning++; break; }
6720 7616
 		}
6721
-	} elseif ($mesgstring && preg_match('/class="error"/i', $mesgstring)) $iserror++;
6722
-	elseif ($mesgstring && preg_match('/class="warning"/i', $mesgstring)) $iswarning++;
6723
-	if ($style == 'error') $iserror++;
6724
-	if ($style == 'warning') $iswarning++;
7617
+	} elseif ($mesgstring && preg_match('/class="error"/i', $mesgstring)) {
7618
+		$iserror++;
7619
+	} elseif ($mesgstring && preg_match('/class="warning"/i', $mesgstring)) {
7620
+		$iswarning++;
7621
+	}
7622
+	if ($style == 'error') {
7623
+		$iserror++;
7624
+	}
7625
+	if ($style == 'warning') {
7626
+		$iswarning++;
7627
+	}
6725 7628
 
6726 7629
 	if ($iserror || $iswarning)
6727 7630
 	{
@@ -6748,8 +7651,10 @@  discard block
 block discarded – undo
6748 7651
 			$mesgarray = $newmesgarray;
6749 7652
 		}
6750 7653
 		print get_htmloutput_mesg($mesgstring, $mesgarray, ($iserror ? 'error' : 'warning'), $keepembedded);
6751
-	} else print get_htmloutput_mesg($mesgstring, $mesgarray, 'ok', $keepembedded);
6752
-}
7654
+	} else {
7655
+		print get_htmloutput_mesg($mesgstring, $mesgarray, 'ok', $keepembedded);
7656
+	}
7657
+	}
6753 7658
 
6754 7659
 /**
6755 7660
  *  Print formated error messages to output (Used to show messages on html output).
@@ -6805,7 +7710,9 @@  discard block
 block discarded – undo
6805 7710
                 ($order == 'asc') ? asort($temp) : arsort($temp);
6806 7711
             } else {
6807 7712
                 ($case_sensitive) ? natsort($temp) : natcasesort($temp);
6808
-                if ($order != 'asc') $temp = array_reverse($temp, true);
7713
+                if ($order != 'asc') {
7714
+                	$temp = array_reverse($temp, true);
7715
+                }
6809 7716
             }
6810 7717
 
6811 7718
 			$sorted = array();
@@ -6834,17 +7741,39 @@  discard block
 block discarded – undo
6834 7741
 	$strLength = dol_strlen($str);
6835 7742
 	for ($i = 0; $i < $strLength; $i++)
6836 7743
 	{
6837
-		if (ord($str[$i]) < 0x80) continue; // 0bbbbbbb
6838
-		elseif ((ord($str[$i]) & 0xE0) == 0xC0) $n = 1; // 110bbbbb
6839
-		elseif ((ord($str[$i]) & 0xF0) == 0xE0) $n = 2; // 1110bbbb
6840
-		elseif ((ord($str[$i]) & 0xF8) == 0xF0) $n = 3; // 11110bbb
6841
-		elseif ((ord($str[$i]) & 0xFC) == 0xF8) $n = 4; // 111110bb
6842
-		elseif ((ord($str[$i]) & 0xFE) == 0xFC) $n = 5; // 1111110b
6843
-		else return false; // Does not match any model
6844
-		for ($j = 0; $j < $n; $j++) { // n bytes matching 10bbbbbb follow ?
6845
-			if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80))
7744
+		if (ord($str[$i]) < 0x80) {
7745
+			continue;
7746
+		}
7747
+		// 0bbbbbbb
7748
+		elseif ((ord($str[$i]) & 0xE0) == 0xC0) {
7749
+			$n = 1;
7750
+		}
7751
+		// 110bbbbb
7752
+		elseif ((ord($str[$i]) & 0xF0) == 0xE0) {
7753
+			$n = 2;
7754
+		}
7755
+		// 1110bbbb
7756
+		elseif ((ord($str[$i]) & 0xF8) == 0xF0) {
7757
+			$n = 3;
7758
+		}
7759
+		// 11110bbb
7760
+		elseif ((ord($str[$i]) & 0xFC) == 0xF8) {
7761
+			$n = 4;
7762
+		}
7763
+		// 111110bb
7764
+		elseif ((ord($str[$i]) & 0xFE) == 0xFC) {
7765
+			$n = 5;
7766
+		}
7767
+		// 1111110b
7768
+		else {
6846 7769
 			return false;
6847 7770
 		}
7771
+		// Does not match any model
7772
+		for ($j = 0; $j < $n; $j++) { // n bytes matching 10bbbbbb follow ?
7773
+			if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80)) {
7774
+						return false;
7775
+			}
7776
+		}
6848 7777
 	}
6849 7778
 	return true;
6850 7779
 }
@@ -6859,9 +7788,14 @@  discard block
 block discarded – undo
6859 7788
 {
6860 7789
 	if (function_exists('mb_check_encoding')) {
6861 7790
 		//if (mb_detect_encoding($str, 'ASCII', true) return false;
6862
-		if (!mb_check_encoding($str, 'ASCII')) return false;
7791
+		if (!mb_check_encoding($str, 'ASCII')) {
7792
+			return false;
7793
+		}
6863 7794
 	} else {
6864
-		if (preg_match('/[^\x00-\x7f]/', $str)) return false; // Contains a byte > 7f
7795
+		if (preg_match('/[^\x00-\x7f]/', $str)) {
7796
+			return false;
7797
+		}
7798
+		// Contains a byte > 7f
6865 7799
 	}
6866 7800
 
6867 7801
 	return true;
@@ -6880,11 +7814,21 @@  discard block
 block discarded – undo
6880 7814
 	global $conf;
6881 7815
 
6882 7816
 	$tmp = ini_get("unicode.filesystem_encoding"); // Disponible avec PHP 6.0
6883
-	if (empty($tmp) && !empty($_SERVER["WINDIR"])) $tmp = 'iso-8859-1'; // By default for windows
6884
-	if (empty($tmp)) $tmp = 'utf-8'; // By default for other
6885
-	if (!empty($conf->global->MAIN_FILESYSTEM_ENCODING)) $tmp = $conf->global->MAIN_FILESYSTEM_ENCODING;
7817
+	if (empty($tmp) && !empty($_SERVER["WINDIR"])) {
7818
+		$tmp = 'iso-8859-1';
7819
+	}
7820
+	// By default for windows
7821
+	if (empty($tmp)) {
7822
+		$tmp = 'utf-8';
7823
+	}
7824
+	// By default for other
7825
+	if (!empty($conf->global->MAIN_FILESYSTEM_ENCODING)) {
7826
+		$tmp = $conf->global->MAIN_FILESYSTEM_ENCODING;
7827
+	}
6886 7828
 
6887
-	if ($tmp == 'iso-8859-1') return utf8_decode($str);
7829
+	if ($tmp == 'iso-8859-1') {
7830
+		return utf8_decode($str);
7831
+	}
6888 7832
 	return $str;
6889 7833
 }
6890 7834
 
@@ -6907,12 +7851,17 @@  discard block
 block discarded – undo
6907 7851
 	global $cache_codes;
6908 7852
 
6909 7853
 	// If key empty
6910
-	if ($key == '') return '';
7854
+	if ($key == '') {
7855
+		return '';
7856
+	}
6911 7857
 
6912 7858
 	// Check in cache
6913
-	if (isset($cache_codes[$tablename][$key][$fieldid]))	// Can be defined to 0 or ''
7859
+	if (isset($cache_codes[$tablename][$key][$fieldid])) {
7860
+		// Can be defined to 0 or ''
6914 7861
 	{
6915
-		return $cache_codes[$tablename][$key][$fieldid]; // Found in cache
7862
+		return $cache_codes[$tablename][$key][$fieldid];
7863
+	}
7864
+	// Found in cache
6916 7865
 	}
6917 7866
 
6918 7867
 	dol_syslog('dol_getIdFromCode (value for field '.$fieldid.' from key '.$key.' not found into cache)', LOG_DEBUG);
@@ -6920,15 +7869,19 @@  discard block
 block discarded – undo
6920 7869
 	$sql = "SELECT ".$fieldid." as valuetoget";
6921 7870
 	$sql .= " FROM ".MAIN_DB_PREFIX.$tablename;
6922 7871
 	$sql .= " WHERE ".$fieldkey." = '".$db->escape($key)."'";
6923
-	if (!empty($entityfilter))
6924
-		$sql .= " AND entity IN (".getEntity($tablename).")";
7872
+	if (!empty($entityfilter)) {
7873
+			$sql .= " AND entity IN (".getEntity($tablename).")";
7874
+	}
6925 7875
 
6926 7876
 	$resql = $db->query($sql);
6927 7877
 	if ($resql)
6928 7878
 	{
6929 7879
 		$obj = $db->fetch_object($resql);
6930
-		if ($obj) $cache_codes[$tablename][$key][$fieldid] = $obj->valuetoget;
6931
-		else $cache_codes[$tablename][$key][$fieldid] = '';
7880
+		if ($obj) {
7881
+			$cache_codes[$tablename][$key][$fieldid] = $obj->valuetoget;
7882
+		} else {
7883
+			$cache_codes[$tablename][$key][$fieldid] = '';
7884
+		}
6932 7885
 		$db->free($resql);
6933 7886
 		return $cache_codes[$tablename][$key][$fieldid];
6934 7887
 	} else {
@@ -6982,11 +7935,17 @@  discard block
 block discarded – undo
6982 7935
 	//print $s."<br>\n";
6983 7936
 	if ($returnvalue)
6984 7937
 	{
6985
-		if ($hideerrors) return @eval('return '.$s.';');
6986
-		else return eval('return '.$s.';');
7938
+		if ($hideerrors) {
7939
+			return @eval('return '.$s.';');
7940
+		} else {
7941
+			return eval('return '.$s.';');
7942
+		}
6987 7943
 	} else {
6988
-		if ($hideerrors) @eval($s);
6989
-		else eval($s);
7944
+		if ($hideerrors) {
7945
+			@eval($s);
7946
+		} else {
7947
+			eval($s);
7948
+		}
6990 7949
 	}
6991 7950
 }
6992 7951
 
@@ -7012,7 +7971,9 @@  discard block
 block discarded – undo
7012 7971
 {
7013 7972
 	global $langs;
7014 7973
 
7015
-	if (empty($codelang)) return '';
7974
+	if (empty($codelang)) {
7975
+		return '';
7976
+	}
7016 7977
 
7017 7978
 	if ($codelang == 'auto')
7018 7979
 	{
@@ -7027,8 +7988,9 @@  discard block
 block discarded – undo
7027 7988
 		'sv_SV' => 'se'
7028 7989
 	);
7029 7990
 
7030
-	if (isset($langtocountryflag[$codelang])) $flagImage = $langtocountryflag[$codelang];
7031
-	else {
7991
+	if (isset($langtocountryflag[$codelang])) {
7992
+		$flagImage = $langtocountryflag[$codelang];
7993
+	} else {
7032 7994
 		$tmparray = explode('_', $codelang);
7033 7995
 		$flagImage = empty($tmparray[1]) ? $tmparray[0] : $tmparray[1];
7034 7996
 	}
@@ -7047,14 +8009,25 @@  discard block
 block discarded – undo
7047 8009
 {
7048 8010
 	global $mysoc;
7049 8011
 
7050
-	if (empty($countrycode)) return null;
8012
+	if (empty($countrycode)) {
8013
+		return null;
8014
+	}
7051 8015
 
7052
-	if (strtoupper($countrycode) == 'MQ') return 'fr_CA';
7053
-	if (strtoupper($countrycode) == 'SE') return 'sv_SE'; // se_SE is Sami/Sweden, and we want in priority sv_SE for SE country
8016
+	if (strtoupper($countrycode) == 'MQ') {
8017
+		return 'fr_CA';
8018
+	}
8019
+	if (strtoupper($countrycode) == 'SE') {
8020
+		return 'sv_SE';
8021
+	}
8022
+	// se_SE is Sami/Sweden, and we want in priority sv_SE for SE country
7054 8023
 	if (strtoupper($countrycode) == 'CH')
7055 8024
 	{
7056
-		if ($mysoc->country_code == 'FR') return 'fr_CH';
7057
-		if ($mysoc->country_code == 'DE') return 'de_CH';
8025
+		if ($mysoc->country_code == 'FR') {
8026
+			return 'fr_CH';
8027
+		}
8028
+		if ($mysoc->country_code == 'DE') {
8029
+			return 'de_CH';
8030
+		}
7058 8031
 	}
7059 8032
 
7060 8033
 	// Locale list taken from:
@@ -7232,13 +8205,17 @@  discard block
 block discarded – undo
7232 8205
 	);
7233 8206
 
7234 8207
 	$buildprimarykeytotest = strtolower($countrycode).'-'.strtoupper($countrycode);
7235
-	if (in_array($buildprimarykeytotest, $locales)) return strtolower($countrycode).'_'.strtoupper($countrycode);
8208
+	if (in_array($buildprimarykeytotest, $locales)) {
8209
+		return strtolower($countrycode).'_'.strtoupper($countrycode);
8210
+	}
7236 8211
 
7237
-	if (function_exists('locale_get_primary_language') && function_exists('locale_get_region'))    // Need extension php-intl
8212
+	if (function_exists('locale_get_primary_language') && function_exists('locale_get_region')) {
8213
+		// Need extension php-intl
7238 8214
 	{
7239 8215
 	    foreach ($locales as $locale)
7240 8216
     	{
7241 8217
     		$locale_language = locale_get_primary_language($locale);
8218
+	}
7242 8219
     		$locale_region = locale_get_region($locale);
7243 8220
     		if (strtoupper($countrycode) == $locale_region)
7244 8221
     		{
@@ -7294,37 +8271,51 @@  discard block
 block discarded – undo
7294 8271
 
7295 8272
 			if ($mode == 'add' && !preg_match('/^\-/', $values[1]))
7296 8273
 			{
7297
-				if (count($values) == 6)       // new declaration with permissions:  $value='objecttype:+tabname1:Title1:langfile@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__'
8274
+				if (count($values) == 6) {
8275
+					// new declaration with permissions:  $value='objecttype:+tabname1:Title1:langfile@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__'
7298 8276
 				{
7299 8277
 					if ($values[0] != $type) continue;
8278
+				}
7300 8279
 
7301 8280
 					if (verifCond($values[4]))
7302 8281
 					{
7303
-						if ($values[3]) $langs->load($values[3]);
8282
+						if ($values[3]) {
8283
+							$langs->load($values[3]);
8284
+						}
7304 8285
 						if (preg_match('/SUBSTITUTION_([^_]+)/i', $values[2], $reg))
7305 8286
 						{
7306 8287
 							$substitutionarray = array();
7307 8288
 							complete_substitutions_array($substitutionarray, $langs, $object, array('needforkey'=>$values[2]));
7308 8289
 							$label = make_substitutions($reg[1], $substitutionarray);
7309
-						} else $label = $langs->trans($values[2]);
8290
+						} else {
8291
+							$label = $langs->trans($values[2]);
8292
+						}
7310 8293
 
7311 8294
 						$head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[5]), 1);
7312 8295
 						$head[$h][1] = $label;
7313 8296
 						$head[$h][2] = str_replace('+', '', $values[1]);
7314 8297
 						$h++;
7315 8298
 					}
7316
-				} elseif (count($values) == 5)       // deprecated
8299
+				} elseif (count($values) == 5) {
8300
+					// deprecated
7317 8301
 				{
7318 8302
 					dol_syslog('Passing 5 values in tabs module_parts is deprecated. Please update to 6 with permissions.', LOG_WARNING);
8303
+				}
7319 8304
 
7320
-					if ($values[0] != $type) continue;
7321
-					if ($values[3]) $langs->load($values[3]);
8305
+					if ($values[0] != $type) {
8306
+						continue;
8307
+					}
8308
+					if ($values[3]) {
8309
+						$langs->load($values[3]);
8310
+					}
7322 8311
 					if (preg_match('/SUBSTITUTION_([^_]+)/i', $values[2], $reg))
7323 8312
 					{
7324 8313
 						$substitutionarray = array();
7325 8314
 						complete_substitutions_array($substitutionarray, $langs, $object, array('needforkey'=>$values[2]));
7326 8315
 						$label = make_substitutions($reg[1], $substitutionarray);
7327
-					} else $label = $langs->trans($values[2]);
8316
+					} else {
8317
+						$label = $langs->trans($values[2]);
8318
+					}
7328 8319
 
7329 8320
 					$head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[4]), 1);
7330 8321
 					$head[$h][1] = $label;
@@ -7333,7 +8324,9 @@  discard block
 block discarded – undo
7333 8324
 				}
7334 8325
 			} elseif ($mode == 'remove' && preg_match('/^\-/', $values[1]))
7335 8326
 			{
7336
-				if ($values[0] != $type) continue;
8327
+				if ($values[0] != $type) {
8328
+					continue;
8329
+				}
7337 8330
 				$tabname = str_replace('-', '', $values[1]);
7338 8331
 				foreach ($head as $key => $val)
7339 8332
 				{
@@ -7379,8 +8372,11 @@  discard block
 block discarded – undo
7379 8372
 	global $action;
7380 8373
 	global $micro_start_time;
7381 8374
 
7382
-	if ($zone == 'private') print "\n".'<!-- Common footer for private page -->'."\n";
7383
-	else print "\n".'<!-- Common footer for public page -->'."\n";
8375
+	if ($zone == 'private') {
8376
+		print "\n".'<!-- Common footer for private page -->'."\n";
8377
+	} else {
8378
+		print "\n".'<!-- Common footer for public page -->'."\n";
8379
+	}
7384 8380
 
7385 8381
 	// A div to store page_y POST parameter so we can read it using javascript
7386 8382
 	print "\n<!-- A div to store page_y POST parameter -->\n";
@@ -7390,7 +8386,9 @@  discard block
 block discarded – undo
7390 8386
 	$reshook = $hookmanager->executeHooks('printCommonFooter', $parameters); // Note that $action and $object may have been modified by some hooks
7391 8387
 	if (empty($reshook))
7392 8388
 	{
7393
-		if (!empty($conf->global->MAIN_HTML_FOOTER)) print $conf->global->MAIN_HTML_FOOTER."\n";
8389
+		if (!empty($conf->global->MAIN_HTML_FOOTER)) {
8390
+			print $conf->global->MAIN_HTML_FOOTER."\n";
8391
+		}
7394 8392
 
7395 8393
 		print "\n";
7396 8394
 		if (!empty($conf->use_javascript_ajax))
@@ -7415,7 +8413,9 @@  discard block
 block discarded – undo
7415 8413
 				print '/* JS CODE TO ENABLE to manage focus and mandatory form fields */'."\n";
7416 8414
 				$relativepathstring = $_SERVER["PHP_SELF"];
7417 8415
 				// Clean $relativepathstring
7418
-				if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'), '/').'/', '', $relativepathstring);
8416
+				if (constant('DOL_URL_ROOT')) {
8417
+					$relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'), '/').'/', '', $relativepathstring);
8418
+				}
7419 8419
 				$relativepathstring = preg_replace('/^\//', '', $relativepathstring);
7420 8420
 				$relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
7421 8421
 				//$tmpqueryarraywehave = explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
@@ -7432,11 +8432,17 @@  discard block
 block discarded – undo
7432 8432
 							{
7433 8433
 								$tmpquerytohaveparam = explode('=', $tmpquerytohave);
7434 8434
 								//print "console.log('".$tmpquerytohaveparam[0]." ".$tmpquerytohaveparam[1]." ".GETPOST($tmpquerytohaveparam[0])."');";
7435
-								if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] != GETPOST($tmpquerytohaveparam[0]))) $foundintru = 1;
8435
+								if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] != GETPOST($tmpquerytohaveparam[0]))) {
8436
+									$foundintru = 1;
8437
+								}
8438
+							}
8439
+							if (!$foundintru) {
8440
+								$qualified = 1;
7436 8441
 							}
7437
-							if (!$foundintru) $qualified = 1;
7438 8442
 							//var_dump($defkey.'-'.$qualified);
7439
-						} else $qualified = 1;
8443
+						} else {
8444
+							$qualified = 1;
8445
+						}
7440 8446
 
7441 8447
 						if ($qualified)
7442 8448
 						{
@@ -7463,11 +8469,17 @@  discard block
 block discarded – undo
7463 8469
 							{
7464 8470
 								$tmpquerytohaveparam = explode('=', $tmpquerytohave);
7465 8471
 								//print "console.log('".$tmpquerytohaveparam[0]." ".$tmpquerytohaveparam[1]." ".GETPOST($tmpquerytohaveparam[0])."');";
7466
-								if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] != GETPOST($tmpquerytohaveparam[0]))) $foundintru = 1;
8472
+								if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] != GETPOST($tmpquerytohaveparam[0]))) {
8473
+									$foundintru = 1;
8474
+								}
8475
+							}
8476
+							if (!$foundintru) {
8477
+								$qualified = 1;
7467 8478
 							}
7468
-							if (!$foundintru) $qualified = 1;
7469 8479
 							//var_dump($defkey.'-'.$qualified);
7470
-						} else $qualified = 1;
8480
+						} else {
8481
+							$qualified = 1;
8482
+						}
7471 8483
 
7472 8484
 						if ($qualified)
7473 8485
 						{
@@ -7491,11 +8503,15 @@  discard block
 block discarded – undo
7491 8503
 				print "\n";
7492 8504
 				print "/* JS CODE TO ENABLE to add memory info */\n";
7493 8505
 				print 'window.console && console.log("';
7494
-				if (!empty($conf->global->MEMCACHED_SERVER)) print 'MEMCACHED_SERVER='.$conf->global->MEMCACHED_SERVER.' - ';
8506
+				if (!empty($conf->global->MEMCACHED_SERVER)) {
8507
+					print 'MEMCACHED_SERVER='.$conf->global->MEMCACHED_SERVER.' - ';
8508
+				}
7495 8509
 				print 'MAIN_OPTIMIZE_SPEED='.(isset($conf->global->MAIN_OPTIMIZE_SPEED) ? $conf->global->MAIN_OPTIMIZE_SPEED : 'off');
7496
-				if (!empty($micro_start_time))   // Works only if MAIN_SHOW_TUNING_INFO is defined at $_SERVER level. Not in global variable.
8510
+				if (!empty($micro_start_time)) {
8511
+					// Works only if MAIN_SHOW_TUNING_INFO is defined at $_SERVER level. Not in global variable.
7497 8512
 				{
7498 8513
 					$micro_end_time = microtime(true);
8514
+				}
7499 8515
 					print ' - Build time: '.ceil(1000 * ($micro_end_time - $micro_start_time)).' ms';
7500 8516
 				}
7501 8517
 
@@ -7549,9 +8565,11 @@  discard block
 block discarded – undo
7549 8565
 	        $debugbar['time']->stopMeasure('pageaftermaster');
7550 8566
 	        print '<!-- Output debugbar data -->'."\n";
7551 8567
 		    print $debugbar->getRenderer()->render();
7552
-		} elseif (count($conf->logbuffer))    // If there is some logs in buffer to show
8568
+		} elseif (count($conf->logbuffer)) {
8569
+			// If there is some logs in buffer to show
7553 8570
 		{
7554 8571
 			print "\n";
8572
+		}
7555 8573
 			print "<!-- Start of log output\n";
7556 8574
 			//print '<div class="hidden">'."\n";
7557 8575
 			foreach ($conf->logbuffer as $logline)
@@ -7658,7 +8676,9 @@  discard block
 block discarded – undo
7658 8676
 
7659 8677
 	$crits = explode(' ', $value);
7660 8678
 	$res = '';
7661
-	if (!is_array($fields)) $fields = array($fields);
8679
+	if (!is_array($fields)) {
8680
+		$fields = array($fields);
8681
+	}
7662 8682
 
7663 8683
 	$nboffields = count($fields);
7664 8684
 	$end2 = count($crits);
@@ -7694,7 +8714,9 @@  discard block
 block discarded – undo
7694 8714
 			} elseif ($mode == 2 || $mode == -2)
7695 8715
 			{
7696 8716
 				$newres .= ($i2 > 0 ? ' OR ' : '').$field." ".($mode == -2 ? 'NOT ' : '')."IN (".$db->escape(trim($crit)).")";
7697
-				if ($mode == -2) $newres .= ' OR '.$field.' IS NULL';
8717
+				if ($mode == -2) {
8718
+					$newres .= ' OR '.$field.' IS NULL';
8719
+				}
7698 8720
 				$i2++; // a criteria was added to string
7699 8721
 			} elseif ($mode == 3 || $mode == -3)
7700 8722
 			{
@@ -7713,7 +8735,9 @@  discard block
 block discarded – undo
7713 8735
 					$newres .= ($i2 > 0 ? ' OR ' : '').$field." ".($mode == -3 ? 'NOT ' : '')."IN (".$listofcodes.")";
7714 8736
 					$i2++; // a criteria was added to string
7715 8737
 				}
7716
-				if ($mode == -3) $newres .= ' OR '.$field.' IS NULL';
8738
+				if ($mode == -3) {
8739
+					$newres .= ' OR '.$field.' IS NULL';
8740
+				}
7717 8741
 			} elseif ($mode == 4)
7718 8742
 			{
7719 8743
 			    $tmparray = explode(',', trim($crit));
@@ -7739,13 +8763,17 @@  discard block
 block discarded – undo
7739 8763
 				$i3 = 0;
7740 8764
 				foreach ($tmpcrits as $tmpcrit)
7741 8765
 				{
7742
-                    if ($tmpcrit !== '0' && empty($tmpcrit)) continue;
8766
+                    if ($tmpcrit !== '0' && empty($tmpcrit)) {
8767
+                    	continue;
8768
+                    }
7743 8769
 
7744 8770
 					$newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
7745 8771
 
7746
-					if (preg_match('/\.(id|rowid)$/', $field))	// Special case for rowid that is sometimes a ref so used as a search field
8772
+					if (preg_match('/\.(id|rowid)$/', $field)) {
8773
+						// Special case for rowid that is sometimes a ref so used as a search field
7747 8774
 					{
7748 8775
 						$newres .= $field." = ".(is_numeric(trim($tmpcrit)) ?trim($tmpcrit) : '0');
8776
+					}
7749 8777
 					} else {
7750 8778
 						$newres .= $field." LIKE '";
7751 8779
 
@@ -7778,7 +8806,9 @@  discard block
 block discarded – undo
7778 8806
 			}
7779 8807
 			$i++;
7780 8808
 		}
7781
-		if ($newres) $res = $res.($res ? ' AND ' : '').($i2 > 1 ? '(' : '').$newres.($i2 > 1 ? ')' : '');
8809
+		if ($newres) {
8810
+			$res = $res.($res ? ' AND ' : '').($i2 > 1 ? '(' : '').$newres.($i2 > 1 ? ')' : '');
8811
+		}
7782 8812
 		$j++;
7783 8813
 	}
7784 8814
 	$res = ($nofirstand ? "" : " AND ")."(".$res.")";
@@ -7819,22 +8849,40 @@  discard block
 block discarded – undo
7819 8849
 function getImageFileNameForSize($file, $extName, $extImgTarget = '')
7820 8850
 {
7821 8851
 	$dirName = dirname($file);
7822
-	if ($dirName == '.') $dirName = '';
8852
+	if ($dirName == '.') {
8853
+		$dirName = '';
8854
+	}
7823 8855
 
7824 8856
 	$fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp|\.webp)$/i', '', $file); // We remove extension, whatever is its case
7825 8857
 	$fileName = basename($fileName);
7826 8858
 
7827
-	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.jpg$/i', $file) ? '.jpg' : '');
7828
-	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.jpeg$/i', $file) ? '.jpeg' : '');
7829
-	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.gif$/i', $file) ? '.gif' : '');
7830
-	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.png$/i', $file) ? '.png' : '');
7831
-	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.bmp$/i', $file) ? '.bmp' : '');
7832
-	if (empty($extImgTarget)) $extImgTarget = (preg_match('/\.webp$/i', $file) ? '.webp' : '');
8859
+	if (empty($extImgTarget)) {
8860
+		$extImgTarget = (preg_match('/\.jpg$/i', $file) ? '.jpg' : '');
8861
+	}
8862
+	if (empty($extImgTarget)) {
8863
+		$extImgTarget = (preg_match('/\.jpeg$/i', $file) ? '.jpeg' : '');
8864
+	}
8865
+	if (empty($extImgTarget)) {
8866
+		$extImgTarget = (preg_match('/\.gif$/i', $file) ? '.gif' : '');
8867
+	}
8868
+	if (empty($extImgTarget)) {
8869
+		$extImgTarget = (preg_match('/\.png$/i', $file) ? '.png' : '');
8870
+	}
8871
+	if (empty($extImgTarget)) {
8872
+		$extImgTarget = (preg_match('/\.bmp$/i', $file) ? '.bmp' : '');
8873
+	}
8874
+	if (empty($extImgTarget)) {
8875
+		$extImgTarget = (preg_match('/\.webp$/i', $file) ? '.webp' : '');
8876
+	}
7833 8877
 
7834
-	if (!$extImgTarget) return $file;
8878
+	if (!$extImgTarget) {
8879
+		return $file;
8880
+	}
7835 8881
 
7836 8882
 	$subdir = '';
7837
-	if ($extName) $subdir = 'thumbs/';
8883
+	if ($extName) {
8884
+		$subdir = 'thumbs/';
8885
+	}
7838 8886
 
7839 8887
 	return ($dirName ? $dirName.'/' : '').$subdir.$fileName.$extName.$extImgTarget; // New filename for thumb
7840 8888
 }
@@ -7853,7 +8901,9 @@  discard block
 block discarded – undo
7853 8901
 {
7854 8902
 	global $conf, $langs;
7855 8903
 
7856
-	if (empty($conf->use_javascript_ajax)) return '';
8904
+	if (empty($conf->use_javascript_ajax)) {
8905
+		return '';
8906
+	}
7857 8907
 
7858 8908
 	$mime_preview = array('bmp', 'jpeg', 'png', 'gif', 'tiff', 'pdf', 'plain', 'css', 'svg+xml', 'webp');
7859 8909
 	//$mime_preview[]='vnd.oasis.opendocument.presentation';
@@ -7862,14 +8912,20 @@  discard block
 block discarded – undo
7862 8912
 
7863 8913
 	if ($alldata == 1)
7864 8914
 	{
7865
-		if ($num_mime !== false) return array('target'=>'_blank', 'css'=>'documentpreview', 'url'=>DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&attachment=0&file='.urlencode($relativepath).($param ? '&'.$param : ''), 'mime'=>dol_mimetype($relativepath),);
7866
-		else return array();
8915
+		if ($num_mime !== false) {
8916
+			return array('target'=>'_blank', 'css'=>'documentpreview', 'url'=>DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&attachment=0&file='.urlencode($relativepath).($param ? '&'.$param : ''), 'mime'=>dol_mimetype($relativepath),);
8917
+		} else {
8918
+			return array();
8919
+		}
7867 8920
 	}
7868 8921
 
7869 8922
 	// old behavior
7870
-	if ($num_mime !== false) return 'javascript:document_preview(\''.dol_escape_js(DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&attachment=0&file='.urlencode($relativepath).($param ? '&'.$param : '')).'\', \''.dol_mimetype($relativepath).'\', \''.dol_escape_js($langs->trans('Preview')).'\')';
7871
-	else return '';
7872
-}
8923
+	if ($num_mime !== false) {
8924
+		return 'javascript:document_preview(\''.dol_escape_js(DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&attachment=0&file='.urlencode($relativepath).($param ? '&'.$param : '')).'\', \''.dol_mimetype($relativepath).'\', \''.dol_escape_js($langs->trans('Preview')).'\')';
8925
+	} else {
8926
+		return '';
8927
+	}
8928
+	}
7873 8929
 
7874 8930
 
7875 8931
 /**
@@ -7887,7 +8943,9 @@  discard block
 block discarded – undo
7887 8943
 				    jQuery("'.((strpos($htmlname, '.') === 0 ? '' : '#').$htmlname).'").click(function() { jQuery(this).select(); } );
7888 8944
 				});
7889 8945
 		    </script>';
7890
-	if ($addlink) $out .= ' <a href="'.$addlink.'" target="_blank">'.$langs->trans("Link").'</a>';
8946
+	if ($addlink) {
8947
+		$out .= ' <a href="'.$addlink.'" target="_blank">'.$langs->trans("Link").'</a>';
8948
+	}
7891 8949
 	return $out;
7892 8950
 }
7893 8951
 
@@ -8029,7 +9087,9 @@  discard block
 block discarded – undo
8029 9087
 	{
8030 9088
 		$dictvalues[$tablename] = array();
8031 9089
 		$sql = 'SELECT * FROM '.$tablename.' WHERE 1'; // Here select * is allowed as it is generic code and we don't have list of fields
8032
-		if ($checkentity) $sql .= ' AND entity IN (0,'.getEntity($tablename).')';
9090
+		if ($checkentity) {
9091
+			$sql .= ' AND entity IN (0,'.getEntity($tablename).')';
9092
+		}
8033 9093
 
8034 9094
 		$resql = $db->query($sql);
8035 9095
 		if ($resql)
@@ -8043,10 +9103,15 @@  discard block
 block discarded – undo
8043 9103
 		}
8044 9104
 	}
8045 9105
 
8046
-	if (!empty($dictvalues[$tablename][$id])) return $dictvalues[$tablename][$id]->{$field}; // Found
9106
+	if (!empty($dictvalues[$tablename][$id])) {
9107
+		return $dictvalues[$tablename][$id]->{$field};
9108
+	}
9109
+	// Found
8047 9110
 	else // Not found
8048 9111
 	{
8049
-		if ($id > 0) return $id;
9112
+		if ($id > 0) {
9113
+			return $id;
9114
+		}
8050 9115
 		return '';
8051 9116
 	}
8052 9117
 }
@@ -8065,9 +9130,11 @@  discard block
 block discarded – undo
8065 9130
 	{
8066 9131
 		$res = 0;
8067 9132
 		$tmp = explode(',', $stringcolor);
8068
-		if (count($tmp) > 1)   // This is a comma RGB ('255','255','255')
9133
+		if (count($tmp) > 1) {
9134
+			// This is a comma RGB ('255','255','255')
8069 9135
 		{
8070 9136
 			$r = $tmp[0];
9137
+		}
8071 9138
 			$g = $tmp[1];
8072 9139
 			$b = $tmp[2];
8073 9140
 		} else {
@@ -8079,7 +9146,9 @@  discard block
 block discarded – undo
8079 9146
 			$b = hexdec($hexb);
8080 9147
 		}
8081 9148
 		$bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm
8082
-		if ($bright > 0.6) $res = 1;
9149
+		if ($bright > 0.6) {
9150
+			$res = 1;
9151
+		}
8083 9152
 	}
8084 9153
 	return $res;
8085 9154
 }
@@ -8098,7 +9167,10 @@  discard block
 block discarded – undo
8098 9167
 
8099 9168
 	//print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
8100 9169
 	//print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
8101
-	if (empty($menuentry['enabled'])) return 0; // Entry disabled by condition
9170
+	if (empty($menuentry['enabled'])) {
9171
+		return 0;
9172
+	}
9173
+	// Entry disabled by condition
8102 9174
 	if ($type_user && $menuentry['module'])
8103 9175
 	{
8104 9176
 		$tmploops = explode('|', $menuentry['module']);
@@ -8109,11 +9181,23 @@  discard block
 block discarded – undo
8109 9181
 				$found++; break;
8110 9182
 			}
8111 9183
 		}
8112
-		if (!$found) return 0; // Entry is for menus all excluded to external users
9184
+		if (!$found) {
9185
+			return 0;
9186
+		}
9187
+		// Entry is for menus all excluded to external users
9188
+	}
9189
+	if (!$menuentry['perms'] && $type_user) {
9190
+		return 0;
8113 9191
 	}
8114
-	if (!$menuentry['perms'] && $type_user) return 0; // No permissions and user is external
8115
-	if (!$menuentry['perms'] && !empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED))	return 0; // No permissions and option to hide when not allowed, even for internal user, is on
8116
-	if (!$menuentry['perms']) return 2; // No permissions and user is external
9192
+	// No permissions and user is external
9193
+	if (!$menuentry['perms'] && !empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED)) {
9194
+		return 0;
9195
+	}
9196
+	// No permissions and option to hide when not allowed, even for internal user, is on
9197
+	if (!$menuentry['perms']) {
9198
+		return 2;
9199
+	}
9200
+	// No permissions and user is external
8117 9201
 	return 1;
8118 9202
 }
8119 9203
 
@@ -8230,9 +9314,13 @@  discard block
 block discarded – undo
8230 9314
         // For small screen, we always use the short label instead of long label.
8231 9315
         if (!empty($conf->dol_optimize_smallscreen))
8232 9316
         {
8233
-        	if ($displayMode == 0) $displayMode = 1;
8234
-        	elseif ($displayMode == 4) $displayMode = 2;
8235
-        	elseif ($displayMode == 6) $displayMode = 5;
9317
+        	if ($displayMode == 0) {
9318
+        		$displayMode = 1;
9319
+        	} elseif ($displayMode == 4) {
9320
+        		$displayMode = 2;
9321
+        	} elseif ($displayMode == 6) {
9322
+        		$displayMode = 5;
9323
+        	}
8236 9324
         }
8237 9325
 
8238 9326
         // For backward compatibility. Image's filename are still in French, so we use this array to convert
@@ -8381,9 +9469,13 @@  discard block
 block discarded – undo
8381 9469
     }
8382 9470
 
8383 9471
     $class = 'btnTitle';
8384
-    if ($iconClass == 'fa fa-plus-circle') $class .= ' btnTitlePlus';
9472
+    if ($iconClass == 'fa fa-plus-circle') {
9473
+    	$class .= ' btnTitlePlus';
9474
+    }
8385 9475
 
8386
-    if (!empty($params['morecss'])) $class .= ' '.$params['morecss'];
9476
+    if (!empty($params['morecss'])) {
9477
+    	$class .= ' '.$params['morecss'];
9478
+    }
8387 9479
 
8388 9480
     $attr = array(
8389 9481
         'class' => $class
@@ -8565,9 +9657,15 @@  discard block
 block discarded – undo
8565 9657
 		$subelement = 'product';
8566 9658
 	}
8567 9659
 
8568
-	if (empty($classfile)) $classfile = strtolower($subelement);
8569
-	if (empty($classname)) $classname = ucfirst($subelement);
8570
-	if (empty($classpath)) $classpath = $module.'/class';
9660
+	if (empty($classfile)) {
9661
+		$classfile = strtolower($subelement);
9662
+	}
9663
+	if (empty($classname)) {
9664
+		$classname = ucfirst($subelement);
9665
+	}
9666
+	if (empty($classpath)) {
9667
+		$classpath = $module.'/class';
9668
+	}
8571 9669
 
8572 9670
 	$element_properties = array(
8573 9671
 		'module' => $module,
Please login to merge, or discard this patch.
Indentation   +426 added lines, -426 removed lines patch added patch discarded remove patch
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 			}
357 357
 			if (!empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES))
358 358
 			{
359
-			    if (!empty($_GET['action']) && (preg_match('/^create/', $_GET['action']) || preg_match('/^presend/', $_GET['action'])) && !isset($_GET[$paramname]) && !isset($_POST[$paramname]))
359
+				if (!empty($_GET['action']) && (preg_match('/^create/', $_GET['action']) || preg_match('/^presend/', $_GET['action'])) && !isset($_GET[$paramname]) && !isset($_POST[$paramname]))
360 360
 				{
361 361
 					// Now search in setup to overwrite default values
362 362
 					if (!empty($user->default_values))		// $user->default_values defined from menu 'Setup - Default values'
@@ -628,22 +628,22 @@  discard block
 block discarded – undo
628 628
 
629 629
 if (!function_exists('dol_getprefix'))
630 630
 {
631
-    /**
632
-     *  Return a prefix to use for this Dolibarr instance, for session/cookie names or email id.
633
-     *  The prefix is unique for instance and avoid conflict between multi-instances, even when having two instances with same root dir
634
-     *  or two instances in same virtual servers.
635
-     *
636
-     *  @param  string  $mode                   '' (prefix for session name) or 'email' (prefix for email id)
637
-     *  @return	string                          A calculated prefix
638
-     */
639
-    function dol_getprefix($mode = '')
640
-    {
641
-        global $conf;
631
+	/**
632
+	 *  Return a prefix to use for this Dolibarr instance, for session/cookie names or email id.
633
+	 *  The prefix is unique for instance and avoid conflict between multi-instances, even when having two instances with same root dir
634
+	 *  or two instances in same virtual servers.
635
+	 *
636
+	 *  @param  string  $mode                   '' (prefix for session name) or 'email' (prefix for email id)
637
+	 *  @return	string                          A calculated prefix
638
+	 */
639
+	function dol_getprefix($mode = '')
640
+	{
641
+		global $conf;
642 642
 
643 643
 		// If prefix is for email
644 644
 		if ($mode == 'email')
645 645
 		{
646
-		    if (!empty($conf->global->MAIL_PREFIX_FOR_EMAIL_ID))	// If MAIL_PREFIX_FOR_EMAIL_ID is set (a value initialized with a random value is recommended)
646
+			if (!empty($conf->global->MAIL_PREFIX_FOR_EMAIL_ID))	// If MAIL_PREFIX_FOR_EMAIL_ID is set (a value initialized with a random value is recommended)
647 647
 			{
648 648
 				if ($conf->global->MAIL_PREFIX_FOR_EMAIL_ID != 'SERVER_NAME') return $conf->global->MAIL_PREFIX_FOR_EMAIL_ID;
649 649
 				elseif (isset($_SERVER["SERVER_NAME"])) return $_SERVER["SERVER_NAME"];
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
 		return rawurldecode($string);
907 907
 	} else {
908 908
 		// See http://www.ascii-code.com/
909
-        $string = strtr(
909
+		$string = strtr(
910 910
 			$str,
911 911
 			"\xC0\xC1\xC2\xC3\xC4\xC5\xC7
912 912
 			\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
  */
1057 1057
 function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = '', $restricttologhandler = '', $logcontext = null)
1058 1058
 {
1059
-    global $conf, $user, $debugbar;
1059
+	global $conf, $user, $debugbar;
1060 1060
 
1061 1061
 	// If syslog module enabled
1062 1062
 	if (empty($conf->syslog->enabled)) return;
@@ -1090,9 +1090,9 @@  discard block
 block discarded – undo
1090 1090
 
1091 1091
 		// If adding log inside HTML page is required
1092 1092
 		if ((!empty($_REQUEST['logtohtml']) && !empty($conf->global->MAIN_ENABLE_LOG_TO_HTML))
1093
-		    || (!empty($user->rights->debugbar->read) && is_object($debugbar)))
1093
+			|| (!empty($user->rights->debugbar->read) && is_object($debugbar)))
1094 1094
 		{
1095
-		    $conf->logbuffer[] = dol_print_date(time(), "%Y-%m-%d %H:%M:%S")." ".$logLevels[$level]." ".$message;
1095
+			$conf->logbuffer[] = dol_print_date(time(), "%Y-%m-%d %H:%M:%S")." ".$logLevels[$level]." ".$message;
1096 1096
 		}
1097 1097
 
1098 1098
 		//TODO: Remove this. MAIN_ENABLE_LOG_INLINE_HTML should be deprecated and use a log handler dedicated to HTML output
@@ -1522,7 +1522,7 @@  discard block
 block discarded – undo
1522 1522
 
1523 1523
 			if (!$phototoshow)      // Show No photo link (picto of object)
1524 1524
 			{
1525
-			    $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">';
1525
+				$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">';
1526 1526
 				if ($object->element == 'action')
1527 1527
 				{
1528 1528
 					$width = 80;
@@ -1871,23 +1871,23 @@  discard block
 block discarded – undo
1871 1871
 	$reg = array();
1872 1872
 	if (preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i', $time, $reg))	// Deprecated. Ex: 1970-01-01, 1970-01-01 01:00:00, 19700101010000
1873 1873
 	{
1874
-	    dol_print_error("Functions.lib::dol_print_date function called with a bad value from page ".$_SERVER["PHP_SELF"]);
1875
-	    return '';
1874
+		dol_print_error("Functions.lib::dol_print_date function called with a bad value from page ".$_SERVER["PHP_SELF"]);
1875
+		return '';
1876 1876
 	} elseif (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $time, $reg))    // Still available to solve problems in extrafields of type date
1877 1877
 	{
1878
-	    // This part of code should not be used.
1879
-	    dol_syslog("Functions.lib::dol_print_date function called with a bad value from page ".$_SERVER["PHP_SELF"], LOG_WARNING);
1880
-	    //if (function_exists('debug_print_backtrace')) debug_print_backtrace();
1881
-	    // Date has format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'
1882
-	    $syear	= (!empty($reg[1]) ? $reg[1] : '');
1883
-	    $smonth = (!empty($reg[2]) ? $reg[2] : '');
1884
-	    $sday	= (!empty($reg[3]) ? $reg[3] : '');
1885
-	    $shour	= (!empty($reg[4]) ? $reg[4] : '');
1886
-	    $smin	= (!empty($reg[5]) ? $reg[5] : '');
1887
-	    $ssec	= (!empty($reg[6]) ? $reg[6] : '');
1888
-
1889
-	    $time = dol_mktime($shour, $smin, $ssec, $smonth, $sday, $syear, true);
1890
-	    $ret = adodb_strftime($format, $time + $offsettz + $offsetdst, $to_gmt);
1878
+		// This part of code should not be used.
1879
+		dol_syslog("Functions.lib::dol_print_date function called with a bad value from page ".$_SERVER["PHP_SELF"], LOG_WARNING);
1880
+		//if (function_exists('debug_print_backtrace')) debug_print_backtrace();
1881
+		// Date has format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'
1882
+		$syear	= (!empty($reg[1]) ? $reg[1] : '');
1883
+		$smonth = (!empty($reg[2]) ? $reg[2] : '');
1884
+		$sday	= (!empty($reg[3]) ? $reg[3] : '');
1885
+		$shour	= (!empty($reg[4]) ? $reg[4] : '');
1886
+		$smin	= (!empty($reg[5]) ? $reg[5] : '');
1887
+		$ssec	= (!empty($reg[6]) ? $reg[6] : '');
1888
+
1889
+		$time = dol_mktime($shour, $smin, $ssec, $smonth, $sday, $syear, true);
1890
+		$ret = adodb_strftime($format, $time + $offsettz + $offsetdst, $to_gmt);
1891 1891
 	} else {
1892 1892
 		// Date is a timestamps
1893 1893
 		if ($time < 100000000000)	// Protection against bad date values
@@ -2232,23 +2232,23 @@  discard block
 block discarded – undo
2232 2232
  */
2233 2233
 function getArrayOfSocialNetworks()
2234 2234
 {
2235
-    global $conf, $db;
2236
-    $sql = "SELECT rowid, code, label, url, icon, active FROM ".MAIN_DB_PREFIX."c_socialnetworks";
2237
-    $sql .= " WHERE entity=".$conf->entity;
2238
-    $socialnetworks = array();
2239
-    $resql = $db->query($sql);
2240
-    if ($resql) {
2241
-        while ($obj = $db->fetch_object($resql)) {
2242
-            $socialnetworks[$obj->code] = array(
2243
-                'rowid' => $obj->rowid,
2244
-                'label' => $obj->label,
2245
-                'url' => $obj->url,
2246
-                'icon' => $obj->icon,
2247
-                'active' => $obj->active,
2248
-            );
2249
-        }
2250
-    }
2251
-    return $socialnetworks;
2235
+	global $conf, $db;
2236
+	$sql = "SELECT rowid, code, label, url, icon, active FROM ".MAIN_DB_PREFIX."c_socialnetworks";
2237
+	$sql .= " WHERE entity=".$conf->entity;
2238
+	$socialnetworks = array();
2239
+	$resql = $db->query($sql);
2240
+	if ($resql) {
2241
+		while ($obj = $db->fetch_object($resql)) {
2242
+			$socialnetworks[$obj->code] = array(
2243
+				'rowid' => $obj->rowid,
2244
+				'label' => $obj->label,
2245
+				'url' => $obj->url,
2246
+				'icon' => $obj->icon,
2247
+				'active' => $obj->active,
2248
+			);
2249
+		}
2250
+	}
2251
+	return $socialnetworks;
2252 2252
 }
2253 2253
 
2254 2254
 /**
@@ -2435,7 +2435,7 @@  discard block
 block discarded – undo
2435 2435
 		}
2436 2436
 	} elseif (strtoupper($countrycode) == "MU")
2437 2437
 	{
2438
-        //Maurice
2438
+		//Maurice
2439 2439
 		if (dol_strlen($phone) == 11)
2440 2440
 		{//ex: +230_ABC_DE_FG
2441 2441
 			$newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 2).$separ.substr($newphone, 9, 2);
@@ -2565,10 +2565,10 @@  discard block
 block discarded – undo
2565 2565
 		}
2566 2566
 	} elseif (strtoupper($countrycode) == "AU")
2567 2567
 	{
2568
-        //Australie
2568
+		//Australie
2569 2569
 		if (dol_strlen($phone) == 12)
2570 2570
 		{
2571
-            //ex: +61_A_BCDE_FGHI
2571
+			//ex: +61_A_BCDE_FGHI
2572 2572
 			$newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 1).$separ.substr($newphone, 4, 4).$separ.substr($newphone, 8, 4);
2573 2573
 		}
2574 2574
 	}
@@ -3003,39 +3003,39 @@  discard block
 block discarded – undo
3003 3003
 		$fullpathpicto = $picto;
3004 3004
 		$reg = array();
3005 3005
 		if (preg_match('/class="([^"]+)"/', $moreatt, $reg)) {
3006
-		    $morecss .= ($morecss ? ' ' : '').$reg[1];
3007
-		    $moreatt = str_replace('class="'.$reg[1].'"', '', $moreatt);
3006
+			$morecss .= ($morecss ? ' ' : '').$reg[1];
3007
+			$moreatt = str_replace('class="'.$reg[1].'"', '', $moreatt);
3008 3008
 		}
3009 3009
 	} else {
3010 3010
 		$pictowithouttext = preg_replace('/(\.png|\.gif|\.svg)$/', '', $picto);
3011
-        if (empty($srconly) && in_array($pictowithouttext, array(
3012
-        		'1downarrow', '1uparrow', '1leftarrow', '1rightarrow', '1uparrow_selected', '1downarrow_selected', '1leftarrow_selected', '1rightarrow_selected',
3013
-        		'accountancy', 'address', 'bank_account', 'barcode', 'bank', 'bill', 'bookmark', 'bom', 'building',
3014
-        		'cash-register', 'category', 'check', 'clock', 'close_title', 'company', 'contact', 'contract', 'cubes',
3015
-        		'delete', 'dolly', 'dollyrevert', 'edit', 'ellipsis-h', 'external-link-alt', 'external-link-square-alt',
3016
-        		'filter', 'file-code', 'file-export', 'file-import', 'file-upload', 'folder', 'folder-open', 'globe', 'globe-americas', 'grip', 'grip_title', 'help',
3017
-        		'intervention', 'label', 'language', 'list', 'listlight', 'lot',
3018
-        		'map-marker-alt', 'money-bill-alt', 'mrp', 'note',
3019
-        		'object_accounting', 'object_action', 'object_account', 'object_barcode', 'object_bill', 'object_billa', 'object_billd', 'object_bom',
3020
-	        	'object_category', 'object_conversation', 'object_bookmark', 'object_bug', 'object_dolly', 'object_dollyrevert', 'object_generic', 'object_folder',
3021
-        		'object_list-alt', 'object_calendar', 'object_calendarweek', 'object_calendarmonth', 'object_calendarday', 'object_calendarperuser',
3022
-        		'object_cash-register', 'object_company', 'object_contact', 'object_contract', 'object_donation', 'object_dynamicprice',
3023
-        		'object_globe', 'object_holiday', 'object_hrm', 'object_invoice', 'object_intervention', 'object_label',
3024
-        		'object_margin', 'object_money-bill-alt', 'object_multicurrency', 'object_order', 'object_payment',
3025
-        		'object_lot', 'object_mrp', 'object_payment', 'object_product', 'object_propal',
3026
-        		'object_other', 'object_paragraph', 'object_poll', 'object_printer', 'object_project', 'object_projectpub', 'object_propal', 'object_resource', 'object_rss', 'object_projecttask',
3027
-        		'object_recruitmentjobposition',
3028
-        		'object_shipment', 'object_supplier_invoice', 'object_supplier_invoicea', 'object_supplier_invoiced', 'object_supplier_order', 'object_supplier_proposal', 'object_service', 'object_stock',
3029
-        		'object_technic', 'object_ticket', 'object_trip', 'object_user', 'object_group', 'object_member',
3030
-        		'object_phoning', 'object_phoning_mobile', 'object_phoning_fax', 'object_email', 'object_website',
3031
-        		'off', 'on', 'order',
3032
-        		'paiment', 'play', 'playdisabled', 'poll', 'printer', 'product', 'propal', 'projecttask', 'stock', 'resize', 'service', 'stats', 'trip',
3011
+		if (empty($srconly) && in_array($pictowithouttext, array(
3012
+				'1downarrow', '1uparrow', '1leftarrow', '1rightarrow', '1uparrow_selected', '1downarrow_selected', '1leftarrow_selected', '1rightarrow_selected',
3013
+				'accountancy', 'address', 'bank_account', 'barcode', 'bank', 'bill', 'bookmark', 'bom', 'building',
3014
+				'cash-register', 'category', 'check', 'clock', 'close_title', 'company', 'contact', 'contract', 'cubes',
3015
+				'delete', 'dolly', 'dollyrevert', 'edit', 'ellipsis-h', 'external-link-alt', 'external-link-square-alt',
3016
+				'filter', 'file-code', 'file-export', 'file-import', 'file-upload', 'folder', 'folder-open', 'globe', 'globe-americas', 'grip', 'grip_title', 'help',
3017
+				'intervention', 'label', 'language', 'list', 'listlight', 'lot',
3018
+				'map-marker-alt', 'money-bill-alt', 'mrp', 'note',
3019
+				'object_accounting', 'object_action', 'object_account', 'object_barcode', 'object_bill', 'object_billa', 'object_billd', 'object_bom',
3020
+				'object_category', 'object_conversation', 'object_bookmark', 'object_bug', 'object_dolly', 'object_dollyrevert', 'object_generic', 'object_folder',
3021
+				'object_list-alt', 'object_calendar', 'object_calendarweek', 'object_calendarmonth', 'object_calendarday', 'object_calendarperuser',
3022
+				'object_cash-register', 'object_company', 'object_contact', 'object_contract', 'object_donation', 'object_dynamicprice',
3023
+				'object_globe', 'object_holiday', 'object_hrm', 'object_invoice', 'object_intervention', 'object_label',
3024
+				'object_margin', 'object_money-bill-alt', 'object_multicurrency', 'object_order', 'object_payment',
3025
+				'object_lot', 'object_mrp', 'object_payment', 'object_product', 'object_propal',
3026
+				'object_other', 'object_paragraph', 'object_poll', 'object_printer', 'object_project', 'object_projectpub', 'object_propal', 'object_resource', 'object_rss', 'object_projecttask',
3027
+				'object_recruitmentjobposition',
3028
+				'object_shipment', 'object_supplier_invoice', 'object_supplier_invoicea', 'object_supplier_invoiced', 'object_supplier_order', 'object_supplier_proposal', 'object_service', 'object_stock',
3029
+				'object_technic', 'object_ticket', 'object_trip', 'object_user', 'object_group', 'object_member',
3030
+				'object_phoning', 'object_phoning_mobile', 'object_phoning_fax', 'object_email', 'object_website',
3031
+				'off', 'on', 'order',
3032
+				'paiment', 'play', 'playdisabled', 'poll', 'printer', 'product', 'propal', 'projecttask', 'stock', 'resize', 'service', 'stats', 'trip',
3033 3033
 				'setup', 'sign-out', 'split', 'stripe-s', 'switch_off', 'switch_on', 'tools', 'unlink', 'uparrow', 'user', 'vcard', 'wrench',
3034 3034
 				'jabber', 'skype', 'twitter', 'facebook', 'linkedin', 'instagram', 'snapchat', 'youtube', 'google-plus-g', 'whatsapp',
3035 3035
 				'chevron-left', 'chevron-right', 'chevron-down', 'chevron-top',
3036
-        		'home', 'hrm', 'companies', 'products', 'commercial', 'invoicing', 'pencil-ruler', 'preview', 'project', 'projectpub', 'supplier_invoice', 'members', 'ticket', 'generic',
3037
-        		'error', 'warning', 'supplier_proposal', 'supplier_order', 'supplier_invoice',
3038
-        		'title_setup', 'title_accountancy', 'title_bank', 'title_hrm', 'title_agenda'
3036
+				'home', 'hrm', 'companies', 'products', 'commercial', 'invoicing', 'pencil-ruler', 'preview', 'project', 'projectpub', 'supplier_invoice', 'members', 'ticket', 'generic',
3037
+				'error', 'warning', 'supplier_proposal', 'supplier_order', 'supplier_invoice',
3038
+				'title_setup', 'title_accountancy', 'title_bank', 'title_hrm', 'title_agenda'
3039 3039
 			)
3040 3040
 		)) {
3041 3041
 			$fakey = $pictowithouttext;
@@ -3050,40 +3050,40 @@  discard block
 block discarded – undo
3050 3050
 
3051 3051
 			$pictowithouttext = str_replace('object_', '', $pictowithouttext);
3052 3052
 
3053
-		    $arrayconvpictotofa = array(
3054
-		    	'account'=>'university', 'accountancy'=>'money-check-alt', 'action'=>'calendar-alt', 'address'=> 'address-book',
3055
-		    	'bank_account'=>'university', 'bill'=>'file-invoice-dollar', 'billa'=>'file-excel', 'supplier_invoicea'=>'file-excel', 'billd'=>'file-medical', 'supplier_invoiced'=>'file-medical', 'bom'=>'cubes',
3056
-		    	'company'=>'building', 'contact'=>'address-book', 'contract'=>'suitcase', 'conversation'=>'comments', 'donation'=>'file-alt', 'dynamicprice'=>'hand-holding-usd',
3057
-		    	'setup'=>'cog', 'companies'=>'building', 'products'=>'cube', 'commercial'=>'suitcase', 'invoicing'=>'coins',
3058
-		    	'accounting'=>'chart-line', 'category'=>'tag', 'dollyrevert'=>'dolly',
3059
-		    	'hrm'=>'user-tie', 'margin'=>'calculator', 'members'=>'users', 'ticket'=>'ticket-alt', 'globe'=>'external-link-alt', 'lot'=>'barcode',
3060
-		    	'email'=>'at',
3061
-		    	'edit'=>'pencil-alt', 'grip_title'=>'arrows-alt', 'grip'=>'arrows-alt', 'help'=>'question-circle',
3062
-		    	'generic'=>'file', 'holiday'=>'umbrella-beach', 'label'=>'layer-group',
3063
-		    	'member'=>'users', 'mrp'=>'cubes', 'trip'=>'wallet', 'group'=>'users',
3064
-		    	'sign-out'=>'sign-out-alt',
3065
-		    	'switch_off'=>'toggle-off', 'switch_on'=>'toggle-on', 'check'=>'check', 'bookmark'=>'star', 'bookmark'=>'star',
3066
-		    	'bank'=>'university', 'close_title'=>'window-close', 'delete'=>'trash', 'edit'=>'pencil-alt', 'filter'=>'filter',
3067
-		    	'list-alt'=>'list-alt', 'calendar'=>'calendar-alt', 'calendarweek'=>'calendar-week', 'calendarmonth'=>'calendar-alt', 'calendarday'=>'calendar-day', 'calendarperuser'=>'table',
3068
-		    	'intervention'=>'ambulance', 'invoice'=>'file-invoice-dollar', 'multicurrency'=>'dollar-sign', 'order'=>'file-invoice',
3069
-		    	'error'=>'exclamation-triangle', 'warning'=>'exclamation-triangle',
3070
-		    	'other'=>'square',
3071
-		    	'playdisabled'=>'play', 'poll'=>'check-double', 'preview'=>'binoculars', 'project'=>'sitemap', 'projectpub'=>'sitemap', 'projecttask'=>'tasks', 'propal'=>'file-signature',
3053
+			$arrayconvpictotofa = array(
3054
+				'account'=>'university', 'accountancy'=>'money-check-alt', 'action'=>'calendar-alt', 'address'=> 'address-book',
3055
+				'bank_account'=>'university', 'bill'=>'file-invoice-dollar', 'billa'=>'file-excel', 'supplier_invoicea'=>'file-excel', 'billd'=>'file-medical', 'supplier_invoiced'=>'file-medical', 'bom'=>'cubes',
3056
+				'company'=>'building', 'contact'=>'address-book', 'contract'=>'suitcase', 'conversation'=>'comments', 'donation'=>'file-alt', 'dynamicprice'=>'hand-holding-usd',
3057
+				'setup'=>'cog', 'companies'=>'building', 'products'=>'cube', 'commercial'=>'suitcase', 'invoicing'=>'coins',
3058
+				'accounting'=>'chart-line', 'category'=>'tag', 'dollyrevert'=>'dolly',
3059
+				'hrm'=>'user-tie', 'margin'=>'calculator', 'members'=>'users', 'ticket'=>'ticket-alt', 'globe'=>'external-link-alt', 'lot'=>'barcode',
3060
+				'email'=>'at',
3061
+				'edit'=>'pencil-alt', 'grip_title'=>'arrows-alt', 'grip'=>'arrows-alt', 'help'=>'question-circle',
3062
+				'generic'=>'file', 'holiday'=>'umbrella-beach', 'label'=>'layer-group',
3063
+				'member'=>'users', 'mrp'=>'cubes', 'trip'=>'wallet', 'group'=>'users',
3064
+				'sign-out'=>'sign-out-alt',
3065
+				'switch_off'=>'toggle-off', 'switch_on'=>'toggle-on', 'check'=>'check', 'bookmark'=>'star', 'bookmark'=>'star',
3066
+				'bank'=>'university', 'close_title'=>'window-close', 'delete'=>'trash', 'edit'=>'pencil-alt', 'filter'=>'filter',
3067
+				'list-alt'=>'list-alt', 'calendar'=>'calendar-alt', 'calendarweek'=>'calendar-week', 'calendarmonth'=>'calendar-alt', 'calendarday'=>'calendar-day', 'calendarperuser'=>'table',
3068
+				'intervention'=>'ambulance', 'invoice'=>'file-invoice-dollar', 'multicurrency'=>'dollar-sign', 'order'=>'file-invoice',
3069
+				'error'=>'exclamation-triangle', 'warning'=>'exclamation-triangle',
3070
+				'other'=>'square',
3071
+				'playdisabled'=>'play', 'poll'=>'check-double', 'preview'=>'binoculars', 'project'=>'sitemap', 'projectpub'=>'sitemap', 'projecttask'=>'tasks', 'propal'=>'file-signature',
3072 3072
 				'recruitmentjobposition'=>'door-open', 'resize'=>'crop', 'supplier_order'=>'dol-order_supplier', 'supplier_proposal'=>'file-signature',
3073
-		    	'payment'=>'money-check-alt', 'phoning'=>'phone', 'phoning_mobile'=>'mobile-alt', 'phoning_fax'=>'fax', 'printer'=>'print', 'product'=>'cube', 'service'=>'concierge-bell',
3074
-		    	'resource'=>'laptop-house',
3075
-		    	'shipment'=>'dolly', 'stock'=>'box-open', 'stats' => 'chart-bar', 'split'=>'code-branch', 'supplier_invoice'=>'file-invoice-dollar', 'technic'=>'cogs', 'ticket'=>'ticket-alt',
3076
-		    	'title_setup'=>'tools', 'title_accountancy'=>'money-check-alt', 'title_bank'=>'university', 'title_hrm'=>'umbrella-beach',
3077
-		    	'title_agenda'=>'calendar-alt',
3078
-		    	'uparrow'=>'mail-forward', 'vcard'=>'address-card',
3079
-		    	'jabber'=>'comment-o',
3080
-		    	'website'=>'globe-americas'
3081
-		    );
3073
+				'payment'=>'money-check-alt', 'phoning'=>'phone', 'phoning_mobile'=>'mobile-alt', 'phoning_fax'=>'fax', 'printer'=>'print', 'product'=>'cube', 'service'=>'concierge-bell',
3074
+				'resource'=>'laptop-house',
3075
+				'shipment'=>'dolly', 'stock'=>'box-open', 'stats' => 'chart-bar', 'split'=>'code-branch', 'supplier_invoice'=>'file-invoice-dollar', 'technic'=>'cogs', 'ticket'=>'ticket-alt',
3076
+				'title_setup'=>'tools', 'title_accountancy'=>'money-check-alt', 'title_bank'=>'university', 'title_hrm'=>'umbrella-beach',
3077
+				'title_agenda'=>'calendar-alt',
3078
+				'uparrow'=>'mail-forward', 'vcard'=>'address-card',
3079
+				'jabber'=>'comment-o',
3080
+				'website'=>'globe-americas'
3081
+			);
3082 3082
 			if ($pictowithouttext == 'off') {
3083
-			    $fakey = 'fa-square';
3083
+				$fakey = 'fa-square';
3084 3084
 				$fasize = '1.3em';
3085 3085
 			} elseif ($pictowithouttext == 'on') {
3086
-			    $fakey = 'fa-check-square';
3086
+				$fakey = 'fa-check-square';
3087 3087
 				$fasize = '1.3em';
3088 3088
 			} elseif ($pictowithouttext == 'listlight') {
3089 3089
 				$fakey = 'fa-download';
@@ -3092,12 +3092,12 @@  discard block
 block discarded – undo
3092 3092
 				$fakey = 'fa-print';
3093 3093
 				$fasize = '1.2em';
3094 3094
 			} elseif ($pictowithouttext == 'note') {
3095
-			    $fakey = 'fa-sticky-note';
3095
+				$fakey = 'fa-sticky-note';
3096 3096
 				$marginleftonlyshort = 1;
3097 3097
 			} elseif (in_array($pictowithouttext, array('1uparrow', '1downarrow', '1leftarrow', '1rightarrow', '1uparrow_selected', '1downarrow_selected', '1leftarrow_selected', '1rightarrow_selected'))) {
3098
-			    $convertarray = array('1uparrow'=>'caret-up', '1downarrow'=>'caret-down', '1leftarrow'=>'caret-left', '1rightarrow'=>'caret-right', '1uparrow_selected'=>'caret-up', '1downarrow_selected'=>'caret-down', '1leftarrow_selected'=>'caret-left', '1rightarrow_selected'=>'caret-right');
3099
-			    $fakey = 'fa-'.$convertarray[$pictowithouttext];
3100
-			    if (preg_match('/selected/', $pictowithouttext)) $facolor = '#888';
3098
+				$convertarray = array('1uparrow'=>'caret-up', '1downarrow'=>'caret-down', '1leftarrow'=>'caret-left', '1rightarrow'=>'caret-right', '1uparrow_selected'=>'caret-up', '1downarrow_selected'=>'caret-down', '1leftarrow_selected'=>'caret-left', '1rightarrow_selected'=>'caret-right');
3099
+				$fakey = 'fa-'.$convertarray[$pictowithouttext];
3100
+				if (preg_match('/selected/', $pictowithouttext)) $facolor = '#888';
3101 3101
 				$marginleftonlyshort = 1;
3102 3102
 			} elseif (!empty($arrayconvpictotofa[$pictowithouttext]))
3103 3103
 			{
@@ -3159,20 +3159,20 @@  discard block
 block discarded – undo
3159 3159
 			}
3160 3160
 
3161 3161
 			// This snippet only needed since function img_edit accepts only one additional parameter: no separate one for css only.
3162
-            // class/style need to be extracted to avoid duplicate class/style validation errors when $moreatt is added to the end of the attributes.
3163
-            $reg = array();
3162
+			// class/style need to be extracted to avoid duplicate class/style validation errors when $moreatt is added to the end of the attributes.
3163
+			$reg = array();
3164 3164
 			if (preg_match('/class="([^"]+)"/', $moreatt, $reg)) {
3165
-                $morecss .= ($morecss ? ' ' : '').$reg[1];
3166
-                $moreatt = str_replace('class="'.$reg[1].'"', '', $moreatt);
3167
-            }
3168
-            if (preg_match('/style="([^"]+)"/', $moreatt, $reg)) {
3169
-                $morestyle = ' '.$reg[1];
3170
-                $moreatt = str_replace('style="'.$reg[1].'"', '', $moreatt);
3171
-            }
3172
-            $moreatt = trim($moreatt);
3173
-
3174
-            $enabledisablehtml = '<span class="'.$fa.' '.$fakey.($marginleftonlyshort ? ($marginleftonlyshort == 1 ? ' marginleftonlyshort' : ' marginleftonly') : '');
3175
-            $enabledisablehtml .= ($morecss ? ' '.$morecss : '').'" style="'.($fasize ? ('font-size: '.$fasize.';') : '').($facolor ? (' color: '.$facolor.';') : '').($morestyle ? ' '.$morestyle : '').'"'.(($notitle || empty($titlealt)) ? '' : ' title="'.dol_escape_htmltag($titlealt).'"').($moreatt ? ' '.$moreatt : '').'>';
3165
+				$morecss .= ($morecss ? ' ' : '').$reg[1];
3166
+				$moreatt = str_replace('class="'.$reg[1].'"', '', $moreatt);
3167
+			}
3168
+			if (preg_match('/style="([^"]+)"/', $moreatt, $reg)) {
3169
+				$morestyle = ' '.$reg[1];
3170
+				$moreatt = str_replace('style="'.$reg[1].'"', '', $moreatt);
3171
+			}
3172
+			$moreatt = trim($moreatt);
3173
+
3174
+			$enabledisablehtml = '<span class="'.$fa.' '.$fakey.($marginleftonlyshort ? ($marginleftonlyshort == 1 ? ' marginleftonlyshort' : ' marginleftonly') : '');
3175
+			$enabledisablehtml .= ($morecss ? ' '.$morecss : '').'" style="'.($fasize ? ('font-size: '.$fasize.';') : '').($facolor ? (' color: '.$facolor.';') : '').($morestyle ? ' '.$morestyle : '').'"'.(($notitle || empty($titlealt)) ? '' : ' title="'.dol_escape_htmltag($titlealt).'"').($moreatt ? ' '.$moreatt : '').'>';
3176 3176
 			if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
3177 3177
 				$enabledisablehtml .= $titlealt;
3178 3178
 			}
@@ -3221,7 +3221,7 @@  discard block
 block discarded – undo
3221 3221
 		return $fullpathpicto;
3222 3222
 	}
3223 3223
 		// tag title is used for tooltip on <a>, tag alt can be used with very simple text on image for blind people
3224
-    return '<img src="'.$fullpathpicto.'" alt="'.dol_escape_htmltag($alt).'"'.(($notitle || empty($titlealt)) ? '' : ' title="'.dol_escape_htmltag($titlealt).'"').($moreatt ? ' '.$moreatt.($morecss ? ' class="'.$morecss.'"' : '') : ' class="inline-block'.($morecss ? ' '.$morecss : '').'"').'>'; // Alt is used for accessibility, title for popup
3224
+	return '<img src="'.$fullpathpicto.'" alt="'.dol_escape_htmltag($alt).'"'.(($notitle || empty($titlealt)) ? '' : ' title="'.dol_escape_htmltag($titlealt).'"').($moreatt ? ' '.$moreatt.($morecss ? ' class="'.$morecss.'"' : '') : ' class="inline-block'.($morecss ? ' '.$morecss : '').'"').'>'; // Alt is used for accessibility, title for popup
3225 3225
 }
3226 3226
 
3227 3227
 /**
@@ -3824,7 +3824,7 @@  discard block
 block discarded – undo
3824 3824
 		$langs->load("main");
3825 3825
 	}
3826 3826
 	// Load translation files required by the page
3827
-    $langs->loadLangs(array('main', 'errors'));
3827
+	$langs->loadLangs(array('main', 'errors'));
3828 3828
 
3829 3829
 	if ($_SERVER['DOCUMENT_ROOT'])    // Mode web
3830 3830
 	{
@@ -3860,7 +3860,7 @@  discard block
 block discarded – undo
3860 3860
 
3861 3861
 	if (!empty($conf->modules))
3862 3862
 	{
3863
-	    $out .= "<b>".$langs->trans("Modules").":</b> ".join(', ', $conf->modules)."<br>\n";
3863
+		$out .= "<b>".$langs->trans("Modules").":</b> ".join(', ', $conf->modules)."<br>\n";
3864 3864
 	}
3865 3865
 
3866 3866
 	if (is_object($db))
@@ -4534,7 +4534,7 @@  discard block
 block discarded – undo
4534 4534
 		$listoflanguagesbefore = array('nl_NL');
4535 4535
 		if (in_array($currency_code, $listofcurrenciesbefore) || in_array($outlangs->defaultlang, $listoflanguagesbefore))
4536 4536
 		{
4537
-		    $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
4537
+			$cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
4538 4538
 		} else {
4539 4539
 			$tmpcur = $outlangs->getCurrencySymbol($currency_code);
4540 4540
 			$cursymbolafter .= ($tmpcur == $currency_code ? ' '.$tmpcur : $tmpcur);
@@ -5360,7 +5360,7 @@  discard block
 block discarded – undo
5360 5360
 		// We will enhance here a common way of forging path for document storage
5361 5361
 		// Here, object->id, object->ref and modulepart are required.
5362 5362
 		//var_dump($modulepart);
5363
-        if (in_array($modulepart, array('thirdparty', 'contact', 'member', 'propal', 'proposal', 'commande', 'order', 'facture', 'invoice',
5363
+		if (in_array($modulepart, array('thirdparty', 'contact', 'member', 'propal', 'proposal', 'commande', 'order', 'facture', 'invoice',
5364 5364
 			'supplier_order', 'supplier_proposal', 'shipment', 'contract', 'expensereport', 'ficheinter')))
5365 5365
 		{
5366 5366
 			$path = ($object->ref ? $object->ref : $object->id);
@@ -5864,18 +5864,18 @@  discard block
 block discarded – undo
5864 5864
  */
5865 5865
 function dol_concatdesc($text1, $text2, $forxml = false, $invert = false)
5866 5866
 {
5867
-    if (!empty($invert))
5868
-    {
5869
-            $tmp = $text1;
5870
-            $text1 = $text2;
5871
-            $text2 = $tmp;
5872
-    }
5867
+	if (!empty($invert))
5868
+	{
5869
+			$tmp = $text1;
5870
+			$text1 = $text2;
5871
+			$text2 = $tmp;
5872
+	}
5873 5873
 
5874
-    $ret = '';
5875
-    $ret .= (!dol_textishtml($text1) && dol_textishtml($text2)) ? dol_nl2br(dol_escape_htmltag($text1, 0, 1, '', 1), 0, $forxml) : $text1;
5876
-    $ret .= (!empty($text1) && !empty($text2)) ? ((dol_textishtml($text1) || dol_textishtml($text2)) ? ($forxml ? "<br \>\n" : "<br>\n") : "\n") : "";
5877
-    $ret .= (dol_textishtml($text1) && !dol_textishtml($text2)) ? dol_nl2br(dol_escape_htmltag($text2, 0, 1, '', 1), 0, $forxml) : $text2;
5878
-    return $ret;
5874
+	$ret = '';
5875
+	$ret .= (!dol_textishtml($text1) && dol_textishtml($text2)) ? dol_nl2br(dol_escape_htmltag($text1, 0, 1, '', 1), 0, $forxml) : $text1;
5876
+	$ret .= (!empty($text1) && !empty($text2)) ? ((dol_textishtml($text1) || dol_textishtml($text2)) ? ($forxml ? "<br \>\n" : "<br>\n") : "\n") : "";
5877
+	$ret .= (dol_textishtml($text1) && !dol_textishtml($text2)) ? dol_nl2br(dol_escape_htmltag($text2, 0, 1, '', 1), 0, $forxml) : $text2;
5878
+	return $ret;
5879 5879
 }
5880 5880
 
5881 5881
 
@@ -5901,7 +5901,7 @@  discard block
 block discarded – undo
5901 5901
 		// Add SIGNATURE into substitutionarray first, so, when we will make the substitution,
5902 5902
 		// this will include signature content first and then replace var found into content of signature
5903 5903
 		$signature = $user->signature;
5904
-        $substitutionarray = array_merge($substitutionarray, array(
5904
+		$substitutionarray = array_merge($substitutionarray, array(
5905 5905
 		'__USER_SIGNATURE__' => (string) (($signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ? dol_trunc(dol_string_nohtmltag($signature), 30) : $signature) : '')
5906 5906
 		)
5907 5907
 			);
@@ -5911,11 +5911,11 @@  discard block
 block discarded – undo
5911 5911
 			$substitutionarray['__SIGNATURE__'] = (string) (($signature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ? dol_trunc(dol_string_nohtmltag($signature), 30) : $signature) : '');
5912 5912
 		}
5913 5913
 
5914
-        $substitutionarray = array_merge($substitutionarray, array(
5914
+		$substitutionarray = array_merge($substitutionarray, array(
5915 5915
 		'__USER_ID__' => (string) $user->id,
5916 5916
 		'__USER_LOGIN__' => (string) $user->login,
5917
-        '__USER_EMAIL__' => (string) $user->email,
5918
-        '__USER_LASTNAME__' => (string) $user->lastname,
5917
+		'__USER_EMAIL__' => (string) $user->email,
5918
+		'__USER_LASTNAME__' => (string) $user->lastname,
5919 5919
 		'__USER_FIRSTNAME__' => (string) $user->firstname,
5920 5920
 		'__USER_FULLNAME__' => (string) $user->getFullName($outputlangs),
5921 5921
 		'__USER_SUPERVISOR_ID__' => (string) ($user->fk_user ? $user->fk_user : '0'),
@@ -5925,7 +5925,7 @@  discard block
 block discarded – undo
5925 5925
 	}
5926 5926
 	if ((empty($exclude) || !in_array('mycompany', $exclude)) && is_object($mysoc))
5927 5927
 	{
5928
-        $substitutionarray = array_merge($substitutionarray, array(
5928
+		$substitutionarray = array_merge($substitutionarray, array(
5929 5929
 			'__MYCOMPANY_NAME__'    => $mysoc->name,
5930 5930
 			'__MYCOMPANY_EMAIL__'   => $mysoc->email,
5931 5931
 			'__MYCOMPANY_PROFID1__' => $mysoc->idprof1,
@@ -5941,8 +5941,8 @@  discard block
 block discarded – undo
5941 5941
 			'__MYCOMPANY_TOWN__'    => $mysoc->town,
5942 5942
 			'__MYCOMPANY_COUNTRY__'    => $mysoc->country,
5943 5943
 			'__MYCOMPANY_COUNTRY_ID__' => $mysoc->country_id,
5944
-        	'__MYCOMPANY_COUNTRY_CODE__' => $mysoc->country_code,
5945
-        	'__MYCOMPANY_CURRENCY_CODE__' => $conf->currency
5944
+			'__MYCOMPANY_COUNTRY_CODE__' => $mysoc->country_code,
5945
+			'__MYCOMPANY_CURRENCY_CODE__' => $conf->currency
5946 5946
 		));
5947 5947
 	}
5948 5948
 
@@ -6019,7 +6019,7 @@  discard block
 block discarded – undo
6019 6019
 
6020 6020
 			if (!empty($conf->expedition->enabled))
6021 6021
 			{
6022
-			    $substitutionarray['__SHIPPINGTRACKNUM__'] = 'Shipping tacking number';
6022
+				$substitutionarray['__SHIPPINGTRACKNUM__'] = 'Shipping tacking number';
6023 6023
 				$substitutionarray['__SHIPPINGTRACKNUMURL__'] = 'Shipping tracking url';
6024 6024
 			}
6025 6025
 		} else {
@@ -6169,17 +6169,17 @@  discard block
 block discarded – undo
6169 6169
 					{
6170 6170
 						foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
6171 6171
 							$substitutionarray['__EXTRAFIELD_'.strtoupper($key).'__'] = $object->array_options['options_'.$key];
6172
-                            if ($extrafields->attribute_type[$key] == 'date') {
6173
-                                $substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = dol_print_date($object->array_options['options_' . $key], 'day');
6174
-                                $substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '_LOCALE__'] = dol_print_date($object->array_options['options_' . $key], 'day', 'tzserver', $outputlangs);
6175
-                                $substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '_RFC__'] = dol_print_date($object->array_options['options_' . $key], 'dayrfc');
6176
-                            } elseif ($extrafields->attribute_type[$key] == 'datetime') {
6177
-                                $datetime = $object->array_options['options_'.$key];
6178
-                                $substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour') : '');
6179
-                                $substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '_LOCALE__'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour', 'tzserver', $outputlangs) : '');
6180
-                                $substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '_DAY_LOCALE__'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'day', 'tzserver', $outputlangs) : '');
6181
-                                $substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '_RFC__'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhourrfc') : '');
6182
-                            }
6172
+							if ($extrafields->attribute_type[$key] == 'date') {
6173
+								$substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = dol_print_date($object->array_options['options_' . $key], 'day');
6174
+								$substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '_LOCALE__'] = dol_print_date($object->array_options['options_' . $key], 'day', 'tzserver', $outputlangs);
6175
+								$substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '_RFC__'] = dol_print_date($object->array_options['options_' . $key], 'dayrfc');
6176
+							} elseif ($extrafields->attribute_type[$key] == 'datetime') {
6177
+								$datetime = $object->array_options['options_'.$key];
6178
+								$substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour') : '');
6179
+								$substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '_LOCALE__'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour', 'tzserver', $outputlangs) : '');
6180
+								$substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '_DAY_LOCALE__'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'day', 'tzserver', $outputlangs) : '');
6181
+								$substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '_RFC__'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhourrfc') : '');
6182
+							}
6183 6183
 						}
6184 6184
 					}
6185 6185
 				}
@@ -6265,7 +6265,7 @@  discard block
 block discarded – undo
6265 6265
 		$tmp4 = dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']);
6266 6266
 		$tmp5 = dol_get_next_month($tmp['mon'], $tmp['year']);
6267 6267
 
6268
-        $substitutionarray = array_merge($substitutionarray, array(
6268
+		$substitutionarray = array_merge($substitutionarray, array(
6269 6269
 			'__DAY__' => (string) $tmp['mday'],
6270 6270
 			'__DAY_TEXT__' => $outputlangs->trans('Day'.$tmp['wday']), // Monday
6271 6271
 			'__DAY_TEXT_SHORT__' => $outputlangs->trans($tmp['weekday'].'Min'), // Mon
@@ -6495,11 +6495,11 @@  discard block
 block discarded – undo
6495 6495
 		$ret .= $lastname;
6496 6496
 	} elseif ($nameorder == 2 || $nameorder == 3)
6497 6497
 	{
6498
-	    $ret .= $firstname;
6499
-	    if (empty($ret) && $nameorder == 3)
6500
-	    {
6501
-	    	$ret .= $lastname;
6502
-	    }
6498
+		$ret .= $firstname;
6499
+		if (empty($ret) && $nameorder == 3)
6500
+		{
6501
+			$ret .= $lastname;
6502
+		}
6503 6503
 	} else {
6504 6504
 		$ret .= $lastname;
6505 6505
 		if ($firstname && $lastname) $ret .= ' ';
@@ -6801,12 +6801,12 @@  discard block
 block discarded – undo
6801 6801
 				}
6802 6802
 			}
6803 6803
 
6804
-            if (!$natsort) {
6805
-                ($order == 'asc') ? asort($temp) : arsort($temp);
6806
-            } else {
6807
-                ($case_sensitive) ? natsort($temp) : natcasesort($temp);
6808
-                if ($order != 'asc') $temp = array_reverse($temp, true);
6809
-            }
6804
+			if (!$natsort) {
6805
+				($order == 'asc') ? asort($temp) : arsort($temp);
6806
+			} else {
6807
+				($case_sensitive) ? natsort($temp) : natcasesort($temp);
6808
+				if ($order != 'asc') $temp = array_reverse($temp, true);
6809
+			}
6810 6810
 
6811 6811
 			$sorted = array();
6812 6812
 
@@ -7236,18 +7236,18 @@  discard block
 block discarded – undo
7236 7236
 
7237 7237
 	if (function_exists('locale_get_primary_language') && function_exists('locale_get_region'))    // Need extension php-intl
7238 7238
 	{
7239
-	    foreach ($locales as $locale)
7240
-    	{
7241
-    		$locale_language = locale_get_primary_language($locale);
7242
-    		$locale_region = locale_get_region($locale);
7243
-    		if (strtoupper($countrycode) == $locale_region)
7244
-    		{
7245
-    			//var_dump($locale.'-'.$locale_language.'-'.$locale_region);
7246
-    			return strtolower($locale_language).'_'.strtoupper($locale_region);
7247
-    		}
7248
-    	}
7239
+		foreach ($locales as $locale)
7240
+		{
7241
+			$locale_language = locale_get_primary_language($locale);
7242
+			$locale_region = locale_get_region($locale);
7243
+			if (strtoupper($countrycode) == $locale_region)
7244
+			{
7245
+				//var_dump($locale.'-'.$locale_language.'-'.$locale_region);
7246
+				return strtolower($locale_language).'_'.strtoupper($locale_region);
7247
+			}
7248
+		}
7249 7249
 	} else {
7250
-        dol_syslog("Warning Exention php-intl is not available", LOG_WARNING);
7250
+		dol_syslog("Warning Exention php-intl is not available", LOG_WARNING);
7251 7251
 	}
7252 7252
 
7253 7253
 	return null;
@@ -7357,7 +7357,7 @@  discard block
 block discarded – undo
7357 7357
 		if ($reshook > 0)
7358 7358
 		{
7359 7359
 			$head = $hookmanager->resArray;
7360
-            $h = count($head);
7360
+			$h = count($head);
7361 7361
 		}
7362 7362
 	}
7363 7363
 }
@@ -7540,15 +7540,15 @@  discard block
 block discarded – undo
7540 7540
 		// Add Xdebug coverage of code
7541 7541
 		if (defined('XDEBUGCOVERAGE'))
7542 7542
 		{
7543
-		    print_r(xdebug_get_code_coverage());
7543
+			print_r(xdebug_get_code_coverage());
7544 7544
 		}
7545 7545
 
7546 7546
 		// Add DebugBar data
7547
-	    if (!empty($user->rights->debugbar->read) && is_object($debugbar))
7548
-	    {
7549
-	        $debugbar['time']->stopMeasure('pageaftermaster');
7550
-	        print '<!-- Output debugbar data -->'."\n";
7551
-		    print $debugbar->getRenderer()->render();
7547
+		if (!empty($user->rights->debugbar->read) && is_object($debugbar))
7548
+		{
7549
+			$debugbar['time']->stopMeasure('pageaftermaster');
7550
+			print '<!-- Output debugbar data -->'."\n";
7551
+			print $debugbar->getRenderer()->render();
7552 7552
 		} elseif (count($conf->logbuffer))    // If there is some logs in buffer to show
7553 7553
 		{
7554 7554
 			print "\n";
@@ -7716,30 +7716,30 @@  discard block
 block discarded – undo
7716 7716
 				if ($mode == -3) $newres .= ' OR '.$field.' IS NULL';
7717 7717
 			} elseif ($mode == 4)
7718 7718
 			{
7719
-			    $tmparray = explode(',', trim($crit));
7720
-			    if (count($tmparray))
7721
-			    {
7722
-			        $listofcodes = '';
7723
-			        foreach ($tmparray as $val)
7724
-			        {
7725
-			            if ($val)
7726
-			            {
7727
-			                $newres .= ($i2 > 0 ? ' OR (' : '(').$field.' LIKE \''.$db->escape(trim($val)).',%\'';
7728
-			                $newres .= ' OR '.$field.' = \''.$db->escape(trim($val)).'\'';
7729
-			                $newres .= ' OR '.$field.' LIKE \'%,'.$db->escape(trim($val)).'\'';
7730
-			                $newres .= ' OR '.$field.' LIKE \'%,'.$db->escape(trim($val)).',%\'';
7731
-			                $newres .= ')';
7732
-			                $i2++;
7733
-			            }
7734
-			        }
7735
-			    }
7719
+				$tmparray = explode(',', trim($crit));
7720
+				if (count($tmparray))
7721
+				{
7722
+					$listofcodes = '';
7723
+					foreach ($tmparray as $val)
7724
+					{
7725
+						if ($val)
7726
+						{
7727
+							$newres .= ($i2 > 0 ? ' OR (' : '(').$field.' LIKE \''.$db->escape(trim($val)).',%\'';
7728
+							$newres .= ' OR '.$field.' = \''.$db->escape(trim($val)).'\'';
7729
+							$newres .= ' OR '.$field.' LIKE \'%,'.$db->escape(trim($val)).'\'';
7730
+							$newres .= ' OR '.$field.' LIKE \'%,'.$db->escape(trim($val)).',%\'';
7731
+							$newres .= ')';
7732
+							$i2++;
7733
+						}
7734
+					}
7735
+				}
7736 7736
 			} else // $mode=0
7737 7737
 			{
7738 7738
 				$tmpcrits = explode('|', $crit);
7739 7739
 				$i3 = 0;
7740 7740
 				foreach ($tmpcrits as $tmpcrit)
7741 7741
 				{
7742
-                    if ($tmpcrit !== '0' && empty($tmpcrit)) continue;
7742
+					if ($tmpcrit !== '0' && empty($tmpcrit)) continue;
7743 7743
 
7744 7744
 					$newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
7745 7745
 
@@ -7917,19 +7917,19 @@  discard block
 block discarded – undo
7917 7917
 	if (preg_match('/\.tsv$/i', $tmpfile)) { $mime = 'text/tab-separated-values'; $imgmime = 'text.png'; $famime = 'file-text-o'; }
7918 7918
 	if (preg_match('/\.(cf|conf|log)$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $famime = 'file-text-o'; }
7919 7919
 	if (preg_match('/\.ini$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'ini'; $famime = 'file-text-o'; }
7920
-    if (preg_match('/\.md$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'md'; $famime = 'file-text-o'; }
7920
+	if (preg_match('/\.md$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'md'; $famime = 'file-text-o'; }
7921 7921
 	if (preg_match('/\.css$/i', $tmpfile)) { $mime = 'text/css'; $imgmime = 'css.png'; $srclang = 'css'; $famime = 'file-text-o'; }
7922 7922
 	// Certificate files
7923 7923
 	if (preg_match('/\.(crt|cer|key|pub)$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $famime = 'file-text-o'; }
7924 7924
 	// XML based (HTML/XML/XAML)
7925 7925
 	if (preg_match('/\.(html|htm|shtml)$/i', $tmpfile)) { $mime = 'text/html'; $imgmime = 'html.png'; $srclang = 'html'; $famime = 'file-text-o'; }
7926 7926
 	if (preg_match('/\.(xml|xhtml)$/i', $tmpfile)) { $mime = 'text/xml'; $imgmime = 'other.png'; $srclang = 'xml'; $famime = 'file-text-o'; }
7927
-    if (preg_match('/\.xaml$/i', $tmpfile)) { $mime = 'text/xml'; $imgmime = 'other.png'; $srclang = 'xaml'; $famime = 'file-text-o'; }
7927
+	if (preg_match('/\.xaml$/i', $tmpfile)) { $mime = 'text/xml'; $imgmime = 'other.png'; $srclang = 'xaml'; $famime = 'file-text-o'; }
7928 7928
 	// Languages
7929 7929
 	if (preg_match('/\.bas$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'bas'; $famime = 'file-code-o'; }
7930 7930
 	if (preg_match('/\.(c)$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'c'; $famime = 'file-code-o'; }
7931 7931
 	if (preg_match('/\.(cpp)$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'cpp'; $famime = 'file-code-o'; }
7932
-    if (preg_match('/\.cs$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'cs'; $famime = 'file-code-o'; }
7932
+	if (preg_match('/\.cs$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'cs'; $famime = 'file-code-o'; }
7933 7933
 	if (preg_match('/\.(h)$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'h'; $famime = 'file-code-o'; }
7934 7934
 	if (preg_match('/\.(java|jsp)$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'text.png'; $srclang = 'java'; $famime = 'file-code-o'; }
7935 7935
 	if (preg_match('/\.php([0-9]{1})?$/i', $tmpfile)) { $mime = 'text/plain'; $imgmime = 'php.png'; $srclang = 'php'; $famime = 'file-code-o'; }
@@ -8059,7 +8059,7 @@  discard block
 block discarded – undo
8059 8059
  */
8060 8060
 function colorIsLight($stringcolor)
8061 8061
 {
8062
-    $stringcolor = str_replace('#', '', $stringcolor);
8062
+	$stringcolor = str_replace('#', '', $stringcolor);
8063 8063
 	$res = -1;
8064 8064
 	if (!empty($stringcolor))
8065 8065
 	{
@@ -8142,28 +8142,28 @@  discard block
 block discarded – undo
8142 8142
  */
8143 8143
 function dolGetBadge($label, $html = '', $type = 'primary', $mode = '', $url = '', $params = array())
8144 8144
 {
8145
-    $attr = array(
8146
-    	'class'=>'badge '.(!empty($mode) ? ' badge-'.$mode : '').(!empty($type) ? ' badge-'.$type : '').(empty($params['css']) ? '' : ' '.$params['css'])
8147
-    );
8145
+	$attr = array(
8146
+		'class'=>'badge '.(!empty($mode) ? ' badge-'.$mode : '').(!empty($type) ? ' badge-'.$type : '').(empty($params['css']) ? '' : ' '.$params['css'])
8147
+	);
8148 8148
 
8149
-    if (empty($html)) {
8150
-        $html = $label;
8151
-    }
8149
+	if (empty($html)) {
8150
+		$html = $label;
8151
+	}
8152 8152
 
8153
-    if (!empty($url)) {
8154
-        $attr['href'] = $url;
8155
-    }
8153
+	if (!empty($url)) {
8154
+		$attr['href'] = $url;
8155
+	}
8156 8156
 
8157
-    if ($mode === 'dot') {
8158
-        $attr['class'] .= ' classfortooltip';
8159
-        $attr['title'] = $html;
8160
-        $attr['aria-label'] = $label;
8161
-        $html = '';
8162
-    }
8157
+	if ($mode === 'dot') {
8158
+		$attr['class'] .= ' classfortooltip';
8159
+		$attr['title'] = $html;
8160
+		$attr['aria-label'] = $label;
8161
+		$html = '';
8162
+	}
8163 8163
 
8164
-    // Override attr
8165
-    if (!empty($params['attr']) && is_array($params['attr'])) {
8166
-        foreach ($params['attr']as $key => $value) {
8164
+	// Override attr
8165
+	if (!empty($params['attr']) && is_array($params['attr'])) {
8166
+		foreach ($params['attr']as $key => $value) {
8167 8167
 			if ($key == 'class') {
8168 8168
 				$attr['class'] .= ' '.$value;
8169 8169
 			} elseif ($key == 'classOverride') {
@@ -8171,24 +8171,24 @@  discard block
 block discarded – undo
8171 8171
 			} else {
8172 8172
 				$attr[$key] = $value;
8173 8173
 			}
8174
-        }
8175
-    }
8174
+		}
8175
+	}
8176 8176
 
8177
-    // TODO: add hook
8177
+	// TODO: add hook
8178 8178
 
8179
-    // escape all attribute
8180
-    $attr = array_map('dol_escape_htmltag', $attr);
8179
+	// escape all attribute
8180
+	$attr = array_map('dol_escape_htmltag', $attr);
8181 8181
 
8182
-    $TCompiledAttr = array();
8183
-    foreach ($attr as $key => $value) {
8184
-        $TCompiledAttr[] = $key.'="'.$value.'"';
8185
-    }
8182
+	$TCompiledAttr = array();
8183
+	foreach ($attr as $key => $value) {
8184
+		$TCompiledAttr[] = $key.'="'.$value.'"';
8185
+	}
8186 8186
 
8187
-    $compiledAttributes = !empty($TCompiledAttr) ?implode(' ', $TCompiledAttr) : '';
8187
+	$compiledAttributes = !empty($TCompiledAttr) ?implode(' ', $TCompiledAttr) : '';
8188 8188
 
8189
-    $tag = !empty($url) ? 'a' : 'span';
8189
+	$tag = !empty($url) ? 'a' : 'span';
8190 8190
 
8191
-    return '<'.$tag.' '.$compiledAttributes.'>'.$html.'</'.$tag.'>';
8191
+	return '<'.$tag.' '.$compiledAttributes.'>'.$html.'</'.$tag.'>';
8192 8192
 }
8193 8193
 
8194 8194
 
@@ -8206,83 +8206,83 @@  discard block
 block discarded – undo
8206 8206
  */
8207 8207
 function dolGetStatus($statusLabel = '', $statusLabelShort = '', $html = '', $statusType = 'status0', $displayMode = 0, $url = '', $params = array())
8208 8208
 {
8209
-    global $conf;
8210
-
8211
-    $return = '';
8212
-    $dolGetBadgeParams = array();
8213
-
8214
-    if (!empty($params['badgeParams'])) {
8215
-        $dolGetBadgeParams = $params['badgeParams'];
8216
-    }
8217
-
8218
-    // TODO : add a hook
8219
-
8220
-    if ($displayMode == 0) {
8221
-        $return = !empty($html) ? $html : $statusLabel;
8222
-    } elseif ($displayMode == 1) {
8223
-        $return = !empty($html) ? $html : (!empty($statusLabelShort) ? $statusLabelShort : $statusLabel);
8224
-    } // Use status with images (for backward compatibility)
8225
-    elseif (!empty($conf->global->MAIN_STATUS_USES_IMAGES)) {
8226
-        $return = '';
8227
-        $htmlLabel      = (in_array($displayMode, array(1, 2, 5)) ? '<span class="hideonsmartphone">' : '').(!empty($html) ? $html : $statusLabel).(in_array($displayMode, array(1, 2, 5)) ? '</span>' : '');
8228
-        $htmlLabelShort = (in_array($displayMode, array(1, 2, 5)) ? '<span class="hideonsmartphone">' : '').(!empty($html) ? $html : (!empty($statusLabelShort) ? $statusLabelShort : $statusLabel)).(in_array($displayMode, array(1, 2, 5)) ? '</span>' : '');
8229
-
8230
-        // For small screen, we always use the short label instead of long label.
8231
-        if (!empty($conf->dol_optimize_smallscreen))
8232
-        {
8233
-        	if ($displayMode == 0) $displayMode = 1;
8234
-        	elseif ($displayMode == 4) $displayMode = 2;
8235
-        	elseif ($displayMode == 6) $displayMode = 5;
8236
-        }
8237
-
8238
-        // For backward compatibility. Image's filename are still in French, so we use this array to convert
8239
-        $statusImg = array(
8240
-        	'status0' => 'statut0',
8241
-        	'status1' => 'statut1',
8242
-        	'status2' => 'statut2',
8243
-        	'status3' => 'statut3',
8244
-        	'status4' => 'statut4',
8245
-        	'status5' => 'statut5',
8246
-        	'status6' => 'statut6',
8247
-        	'status7' => 'statut7',
8248
-        	'status8' => 'statut8',
8249
-        	'status9' => 'statut9'
8250
-        );
8251
-
8252
-        if (!empty($statusImg[$statusType])) {
8253
-            $htmlImg = img_picto($statusLabel, $statusImg[$statusType]);
8254
-        } else {
8255
-            $htmlImg = img_picto($statusLabel, $statusType);
8256
-        }
8257
-
8258
-        if ($displayMode === 2) {
8259
-            $return = $htmlImg.' '.$htmlLabelShort;
8260
-        } elseif ($displayMode === 3) {
8261
-            $return = $htmlImg;
8262
-        } elseif ($displayMode === 4) {
8263
-            $return = $htmlImg.' '.$htmlLabel;
8264
-        } elseif ($displayMode === 5) {
8265
-            $return = $htmlLabelShort.' '.$htmlImg;
8266
-        } else { // $displayMode >= 6
8267
-            $return = $htmlLabel.' '.$htmlImg;
8268
-        }
8269
-    } // Use new badge
8270
-    elseif (empty($conf->global->MAIN_STATUS_USES_IMAGES) && !empty($displayMode)) {
8271
-        $statusLabelShort = !empty($statusLabelShort) ? $statusLabelShort : $statusLabel;
8209
+	global $conf;
8210
+
8211
+	$return = '';
8212
+	$dolGetBadgeParams = array();
8213
+
8214
+	if (!empty($params['badgeParams'])) {
8215
+		$dolGetBadgeParams = $params['badgeParams'];
8216
+	}
8217
+
8218
+	// TODO : add a hook
8219
+
8220
+	if ($displayMode == 0) {
8221
+		$return = !empty($html) ? $html : $statusLabel;
8222
+	} elseif ($displayMode == 1) {
8223
+		$return = !empty($html) ? $html : (!empty($statusLabelShort) ? $statusLabelShort : $statusLabel);
8224
+	} // Use status with images (for backward compatibility)
8225
+	elseif (!empty($conf->global->MAIN_STATUS_USES_IMAGES)) {
8226
+		$return = '';
8227
+		$htmlLabel      = (in_array($displayMode, array(1, 2, 5)) ? '<span class="hideonsmartphone">' : '').(!empty($html) ? $html : $statusLabel).(in_array($displayMode, array(1, 2, 5)) ? '</span>' : '');
8228
+		$htmlLabelShort = (in_array($displayMode, array(1, 2, 5)) ? '<span class="hideonsmartphone">' : '').(!empty($html) ? $html : (!empty($statusLabelShort) ? $statusLabelShort : $statusLabel)).(in_array($displayMode, array(1, 2, 5)) ? '</span>' : '');
8229
+
8230
+		// For small screen, we always use the short label instead of long label.
8231
+		if (!empty($conf->dol_optimize_smallscreen))
8232
+		{
8233
+			if ($displayMode == 0) $displayMode = 1;
8234
+			elseif ($displayMode == 4) $displayMode = 2;
8235
+			elseif ($displayMode == 6) $displayMode = 5;
8236
+		}
8237
+
8238
+		// For backward compatibility. Image's filename are still in French, so we use this array to convert
8239
+		$statusImg = array(
8240
+			'status0' => 'statut0',
8241
+			'status1' => 'statut1',
8242
+			'status2' => 'statut2',
8243
+			'status3' => 'statut3',
8244
+			'status4' => 'statut4',
8245
+			'status5' => 'statut5',
8246
+			'status6' => 'statut6',
8247
+			'status7' => 'statut7',
8248
+			'status8' => 'statut8',
8249
+			'status9' => 'statut9'
8250
+		);
8251
+
8252
+		if (!empty($statusImg[$statusType])) {
8253
+			$htmlImg = img_picto($statusLabel, $statusImg[$statusType]);
8254
+		} else {
8255
+			$htmlImg = img_picto($statusLabel, $statusType);
8256
+		}
8257
+
8258
+		if ($displayMode === 2) {
8259
+			$return = $htmlImg.' '.$htmlLabelShort;
8260
+		} elseif ($displayMode === 3) {
8261
+			$return = $htmlImg;
8262
+		} elseif ($displayMode === 4) {
8263
+			$return = $htmlImg.' '.$htmlLabel;
8264
+		} elseif ($displayMode === 5) {
8265
+			$return = $htmlLabelShort.' '.$htmlImg;
8266
+		} else { // $displayMode >= 6
8267
+			$return = $htmlLabel.' '.$htmlImg;
8268
+		}
8269
+	} // Use new badge
8270
+	elseif (empty($conf->global->MAIN_STATUS_USES_IMAGES) && !empty($displayMode)) {
8271
+		$statusLabelShort = !empty($statusLabelShort) ? $statusLabelShort : $statusLabel;
8272 8272
 
8273 8273
 		$dolGetBadgeParams['attr']['class'] = 'badge-status';
8274 8274
 		$dolGetBadgeParams['attr']['title'] = $statusLabel;
8275 8275
 
8276
-        if ($displayMode == 3) {
8277
-            $return = dolGetBadge($statusLabel, '', $statusType, 'dot', $url, $dolGetBadgeParams);
8278
-        } elseif ($displayMode === 5) {
8279
-            $return = dolGetBadge($statusLabelShort, $html, $statusType, '', $url, $dolGetBadgeParams);
8280
-        } else {
8281
-            $return = dolGetBadge($statusLabel, $html, $statusType, '', $url, $dolGetBadgeParams);
8282
-        }
8283
-    }
8276
+		if ($displayMode == 3) {
8277
+			$return = dolGetBadge($statusLabel, '', $statusType, 'dot', $url, $dolGetBadgeParams);
8278
+		} elseif ($displayMode === 5) {
8279
+			$return = dolGetBadge($statusLabelShort, $html, $statusType, '', $url, $dolGetBadgeParams);
8280
+		} else {
8281
+			$return = dolGetBadge($statusLabel, $html, $statusType, '', $url, $dolGetBadgeParams);
8282
+		}
8283
+	}
8284 8284
 
8285
-    return $return;
8285
+	return $return;
8286 8286
 }
8287 8287
 
8288 8288
 
@@ -8300,63 +8300,63 @@  discard block
 block discarded – undo
8300 8300
  */
8301 8301
 function dolGetButtonAction($label, $html = '', $actionType = 'default', $url = '', $id = '', $userRight = 1, $params = array())
8302 8302
 {
8303
-    $class = 'butAction';
8304
-    if ($actionType == 'danger' || $actionType == 'delete') {
8305
-        $class = 'butActionDelete';
8306
-    }
8303
+	$class = 'butAction';
8304
+	if ($actionType == 'danger' || $actionType == 'delete') {
8305
+		$class = 'butActionDelete';
8306
+	}
8307 8307
 
8308
-    $attr = array(
8309
-        'class' => $class
8310
-        ,'href' => empty($url) ? '' : $url
8311
-    );
8308
+	$attr = array(
8309
+		'class' => $class
8310
+		,'href' => empty($url) ? '' : $url
8311
+	);
8312 8312
 
8313
-    if (empty($html)) {
8314
-        $html = $label;
8315
-    } else {
8316
-        $attr['aria-label'] = $label;
8317
-    }
8313
+	if (empty($html)) {
8314
+		$html = $label;
8315
+	} else {
8316
+		$attr['aria-label'] = $label;
8317
+	}
8318 8318
 
8319
-    if (empty($userRight)) {
8320
-        $attr['class'] = 'butActionRefused';
8321
-        $attr['href'] = '';
8322
-    }
8319
+	if (empty($userRight)) {
8320
+		$attr['class'] = 'butActionRefused';
8321
+		$attr['href'] = '';
8322
+	}
8323 8323
 
8324
-    if (!empty($id)) {
8325
-        $attr['id'] = $id;
8326
-    }
8324
+	if (!empty($id)) {
8325
+		$attr['id'] = $id;
8326
+	}
8327 8327
 
8328
-    // Override attr
8329
-    if (!empty($params['attr']) && is_array($params['attr'])) {
8330
-        foreach ($params['attr'] as $key => $value) {
8331
-            if ($key == 'class') {
8332
-                $attr['class'] .= ' '.$value;
8333
-            } elseif ($key == 'classOverride') {
8334
-                $attr['class'] = $value;
8335
-            } else {
8336
-                $attr[$key] = $value;
8337
-            }
8338
-        }
8339
-    }
8328
+	// Override attr
8329
+	if (!empty($params['attr']) && is_array($params['attr'])) {
8330
+		foreach ($params['attr'] as $key => $value) {
8331
+			if ($key == 'class') {
8332
+				$attr['class'] .= ' '.$value;
8333
+			} elseif ($key == 'classOverride') {
8334
+				$attr['class'] = $value;
8335
+			} else {
8336
+				$attr[$key] = $value;
8337
+			}
8338
+		}
8339
+	}
8340 8340
 
8341
-    if (isset($attr['href']) && empty($attr['href'])) {
8342
-        unset($attr['href']);
8343
-    }
8341
+	if (isset($attr['href']) && empty($attr['href'])) {
8342
+		unset($attr['href']);
8343
+	}
8344 8344
 
8345
-    // TODO : add a hook
8345
+	// TODO : add a hook
8346 8346
 
8347
-    // escape all attribute
8348
-    $attr = array_map('dol_escape_htmltag', $attr);
8347
+	// escape all attribute
8348
+	$attr = array_map('dol_escape_htmltag', $attr);
8349 8349
 
8350
-    $TCompiledAttr = array();
8351
-    foreach ($attr as $key => $value) {
8352
-        $TCompiledAttr[] = $key.'="'.$value.'"';
8353
-    }
8350
+	$TCompiledAttr = array();
8351
+	foreach ($attr as $key => $value) {
8352
+		$TCompiledAttr[] = $key.'="'.$value.'"';
8353
+	}
8354 8354
 
8355
-    $compiledAttributes = !empty($TCompiledAttr) ?implode(' ', $TCompiledAttr) : '';
8355
+	$compiledAttributes = !empty($TCompiledAttr) ?implode(' ', $TCompiledAttr) : '';
8356 8356
 
8357
-    $tag = !empty($attr['href']) ? 'a' : 'span';
8357
+	$tag = !empty($attr['href']) ? 'a' : 'span';
8358 8358
 
8359
-    return '<div class="inline-block divButAction"><'.$tag.' '.$compiledAttributes.'>'.$html.'</'.$tag.'></div>';
8359
+	return '<div class="inline-block divButAction"><'.$tag.' '.$compiledAttributes.'>'.$html.'</'.$tag.'></div>';
8360 8360
 }
8361 8361
 
8362 8362
 /**
@@ -8373,85 +8373,85 @@  discard block
 block discarded – undo
8373 8373
  */
8374 8374
 function dolGetButtonTitle($label, $helpText = '', $iconClass = 'fa fa-file', $url = '', $id = '', $status = 1, $params = array())
8375 8375
 {
8376
-    global $langs, $conf, $user;
8376
+	global $langs, $conf, $user;
8377 8377
 
8378
-    // Actually this conf is used in css too for external module compatibility and smooth transition to this function
8379
-    if (!empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED) && (!$user->admin) && $status <= 0) {
8380
-        return '';
8381
-    }
8378
+	// Actually this conf is used in css too for external module compatibility and smooth transition to this function
8379
+	if (!empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED) && (!$user->admin) && $status <= 0) {
8380
+		return '';
8381
+	}
8382 8382
 
8383
-    $class = 'btnTitle';
8384
-    if ($iconClass == 'fa fa-plus-circle') $class .= ' btnTitlePlus';
8383
+	$class = 'btnTitle';
8384
+	if ($iconClass == 'fa fa-plus-circle') $class .= ' btnTitlePlus';
8385 8385
 
8386
-    if (!empty($params['morecss'])) $class .= ' '.$params['morecss'];
8386
+	if (!empty($params['morecss'])) $class .= ' '.$params['morecss'];
8387 8387
 
8388
-    $attr = array(
8389
-        'class' => $class
8390
-        ,'href' => empty($url) ? '' : $url
8391
-    );
8388
+	$attr = array(
8389
+		'class' => $class
8390
+		,'href' => empty($url) ? '' : $url
8391
+	);
8392 8392
 
8393
-    if (!empty($helpText)) {
8394
-        $attr['title'] = dol_escape_htmltag($helpText);
8395
-    }
8393
+	if (!empty($helpText)) {
8394
+		$attr['title'] = dol_escape_htmltag($helpText);
8395
+	}
8396 8396
 
8397
-    if ($status <= 0) {
8398
-        $attr['class'] .= ' refused';
8397
+	if ($status <= 0) {
8398
+		$attr['class'] .= ' refused';
8399 8399
 
8400
-        $attr['href'] = '';
8400
+		$attr['href'] = '';
8401 8401
 
8402
-        if ($status == -1) { // disable
8403
-            $attr['title'] = dol_escape_htmltag($langs->transnoentitiesnoconv("FeatureDisabled"));
8404
-        } elseif ($status == 0) { // Not enough permissions
8405
-            $attr['title'] = dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions"));
8406
-        }
8407
-    }
8402
+		if ($status == -1) { // disable
8403
+			$attr['title'] = dol_escape_htmltag($langs->transnoentitiesnoconv("FeatureDisabled"));
8404
+		} elseif ($status == 0) { // Not enough permissions
8405
+			$attr['title'] = dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions"));
8406
+		}
8407
+	}
8408 8408
 
8409
-    if (!empty($attr['title'])) {
8410
-        $attr['class'] .= ' classfortooltip';
8411
-    }
8409
+	if (!empty($attr['title'])) {
8410
+		$attr['class'] .= ' classfortooltip';
8411
+	}
8412 8412
 
8413
-    if (empty($id)) {
8414
-        $attr['id'] = $id;
8415
-    }
8413
+	if (empty($id)) {
8414
+		$attr['id'] = $id;
8415
+	}
8416 8416
 
8417
-    // Override attr
8418
-    if (!empty($params['attr']) && is_array($params['attr'])) {
8419
-        foreach ($params['attr'] as $key => $value) {
8420
-            if ($key == 'class') {
8421
-                $attr['class'] .= ' '.$value;
8422
-            } elseif ($key == 'classOverride') {
8423
-                $attr['class'] = $value;
8424
-            } else {
8425
-                $attr[$key] = $value;
8426
-            }
8427
-        }
8428
-    }
8417
+	// Override attr
8418
+	if (!empty($params['attr']) && is_array($params['attr'])) {
8419
+		foreach ($params['attr'] as $key => $value) {
8420
+			if ($key == 'class') {
8421
+				$attr['class'] .= ' '.$value;
8422
+			} elseif ($key == 'classOverride') {
8423
+				$attr['class'] = $value;
8424
+			} else {
8425
+				$attr[$key] = $value;
8426
+			}
8427
+		}
8428
+	}
8429 8429
 
8430
-    if (isset($attr['href']) && empty($attr['href'])) {
8431
-        unset($attr['href']);
8432
-    }
8430
+	if (isset($attr['href']) && empty($attr['href'])) {
8431
+		unset($attr['href']);
8432
+	}
8433 8433
 
8434
-    // TODO : add a hook
8434
+	// TODO : add a hook
8435 8435
 
8436
-    // escape all attribute
8437
-    $attr = array_map('dol_escape_htmltag', $attr);
8436
+	// escape all attribute
8437
+	$attr = array_map('dol_escape_htmltag', $attr);
8438 8438
 
8439
-    $TCompiledAttr = array();
8440
-    foreach ($attr as $key => $value) {
8441
-        $TCompiledAttr[] = $key.'="'.$value.'"';
8442
-    }
8439
+	$TCompiledAttr = array();
8440
+	foreach ($attr as $key => $value) {
8441
+		$TCompiledAttr[] = $key.'="'.$value.'"';
8442
+	}
8443 8443
 
8444
-    $compiledAttributes = (empty($TCompiledAttr) ? '' : implode(' ', $TCompiledAttr));
8444
+	$compiledAttributes = (empty($TCompiledAttr) ? '' : implode(' ', $TCompiledAttr));
8445 8445
 
8446
-    $tag = (empty($attr['href']) ? 'span' : 'a');
8446
+	$tag = (empty($attr['href']) ? 'span' : 'a');
8447 8447
 
8448
-    $button = '';
8449
-    $button .= '<'.$tag.' '.$compiledAttributes.' >';
8450
-    $button .= '<span class="'.$iconClass.' valignmiddle btnTitle-icon"></span>';
8451
-    $button .= '<span class="valignmiddle text-plus-circle btnTitle-label'.(empty($params['forcenohideoftext']) ? ' hideonsmartphone' : '').'">'.$label.'</span>';
8452
-    $button .= '</'.$tag.'>';
8448
+	$button = '';
8449
+	$button .= '<'.$tag.' '.$compiledAttributes.' >';
8450
+	$button .= '<span class="'.$iconClass.' valignmiddle btnTitle-icon"></span>';
8451
+	$button .= '<span class="valignmiddle text-plus-circle btnTitle-label'.(empty($params['forcenohideoftext']) ? ' hideonsmartphone' : '').'">'.$label.'</span>';
8452
+	$button .= '</'.$tag.'>';
8453 8453
 
8454
-    return $button;
8454
+	return $button;
8455 8455
 }
8456 8456
 
8457 8457
 /**
@@ -8616,12 +8616,12 @@  discard block
 block discarded – undo
8616 8616
  */
8617 8617
 function isAFileWithExecutableContent($filename)
8618 8618
 {
8619
-    if (preg_match('/\.(htm|html|js|phar|php|php\d+|phtml|pht|pl|py|cgi|ksh|sh|shtml|bash|bat|cmd|wpk|exe|dmg)$/i', $filename))
8620
-    {
8621
-        return true;
8622
-    }
8619
+	if (preg_match('/\.(htm|html|js|phar|php|php\d+|phtml|pht|pl|py|cgi|ksh|sh|shtml|bash|bat|cmd|wpk|exe|dmg)$/i', $filename))
8620
+	{
8621
+		return true;
8622
+	}
8623 8623
 
8624
-    return false;
8624
+	return false;
8625 8625
 }
8626 8626
 
8627 8627
 /**
Please login to merge, or discard this patch.
htdocs/compta/paiement/class/paiement.class.php 2 patches
Indentation   +490 added lines, -490 removed lines patch added patch discarded remove patch
@@ -38,17 +38,17 @@  discard block
 block discarded – undo
38 38
  */
39 39
 class Paiement extends CommonObject
40 40
 {
41
-    /**
41
+	/**
42 42
 	 * @var string ID to identify managed object
43 43
 	 */
44 44
 	public $element = 'payment';
45 45
 
46
-    /**
46
+	/**
47 47
 	 * @var string Name of table without prefix where object is stored
48 48
 	 */
49 49
 	public $table_element = 'paiement';
50 50
 
51
-    /**
51
+	/**
52 52
 	 * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
53 53
 	 */
54 54
 	public $picto = 'payment';
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 * @deprecated
61 61
 	 * @see $amount, $amounts
62 62
 	 */
63
-    public $total;
63
+	public $total;
64 64
 
65 65
 	/**
66 66
 	 * @deprecated
@@ -77,68 +77,68 @@  discard block
 block discarded – undo
77 77
 	public $paiementid; // Type of payment. Id saved into fields fk_paiement on llx_paiement
78 78
 	public $paiementcode; // Code of payment.
79 79
 
80
-    /**
81
-     * @var string type libelle
82
-     */
83
-    public $type_label;
84
-
85
-    /**
86
-     * @var string type code
87
-     */
88
-    public $type_code;
89
-
90
-    /**
91
-     * @var string Numero du CHQ, VIR, etc...
92
-     * @deprecated
93
-     * @see $num_payment
94
-     */
95
-    public $numero;
96
-
97
-    /**
98
-     * @var string Numero du CHQ, VIR, etc...
99
-     * @deprecated
100
-     * @see $num_payment
101
-     */
102
-    public $num_paiement;
103
-
104
-    /**
105
-     * @var string Numero du CHQ, VIR, etc...
106
-     */
107
-    public $num_payment;
108
-
109
-    /**
110
-     * @var string Id of external payment mode
111
-     */
112
-    public $ext_payment_id;
113
-
114
-    /**
115
-     * @var string Name of external payment mode
116
-     */
117
-    public $ext_payment_site;
118
-
119
-    /**
120
-     * @var int bank account id of payment
121
-     * @deprecated
122
-     * @see $fk_account
123
-     */
124
-    public $bank_account;
125
-
126
-    /**
127
-     * @var int bank account id of payment
128
-     */
129
-    public $fk_account;
130
-
131
-    /**
132
-     * @var int id of payment line in bank account
133
-     */
134
-    public $bank_line;
80
+	/**
81
+	 * @var string type libelle
82
+	 */
83
+	public $type_label;
84
+
85
+	/**
86
+	 * @var string type code
87
+	 */
88
+	public $type_code;
89
+
90
+	/**
91
+	 * @var string Numero du CHQ, VIR, etc...
92
+	 * @deprecated
93
+	 * @see $num_payment
94
+	 */
95
+	public $numero;
96
+
97
+	/**
98
+	 * @var string Numero du CHQ, VIR, etc...
99
+	 * @deprecated
100
+	 * @see $num_payment
101
+	 */
102
+	public $num_paiement;
103
+
104
+	/**
105
+	 * @var string Numero du CHQ, VIR, etc...
106
+	 */
107
+	public $num_payment;
108
+
109
+	/**
110
+	 * @var string Id of external payment mode
111
+	 */
112
+	public $ext_payment_id;
113
+
114
+	/**
115
+	 * @var string Name of external payment mode
116
+	 */
117
+	public $ext_payment_site;
118
+
119
+	/**
120
+	 * @var int bank account id of payment
121
+	 * @deprecated
122
+	 * @see $fk_account
123
+	 */
124
+	public $bank_account;
125
+
126
+	/**
127
+	 * @var int bank account id of payment
128
+	 */
129
+	public $fk_account;
130
+
131
+	/**
132
+	 * @var int id of payment line in bank account
133
+	 */
134
+	public $bank_line;
135 135
 
136 136
 	// fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...)
137
-    // fk_paiement dans llx_paiement_facture est le rowid du paiement
138
-    /**
139
-     * @var int payment id
140
-     */
141
-    public $fk_paiement; // Type of payment
137
+	// fk_paiement dans llx_paiement_facture est le rowid du paiement
138
+	/**
139
+	 * @var int payment id
140
+	 */
141
+	public $fk_paiement; // Type of payment
142 142
 
143 143
 
144 144
 	/**
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
 				$this->type_label = $obj->type_label;
196 196
 				$this->type_code      = $obj->type_code;
197 197
 				$this->statut         = $obj->statut;
198
-                $this->ext_payment_id = $obj->ext_payment_id;
199
-                $this->ext_payment_site = $obj->ext_payment_site;
198
+				$this->ext_payment_id = $obj->ext_payment_id;
199
+				$this->ext_payment_site = $obj->ext_payment_site;
200 200
 
201 201
 				$this->bank_account   = $obj->fk_account; // deprecated
202 202
 				$this->fk_account     = $obj->fk_account;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 	 *  @param  Societe   $thirdparty           Thirdparty
225 225
 	 *  @return int                 			id of created payment, < 0 if error
226 226
 	 */
227
-    public function create($user, $closepaidinvoices = 0, $thirdparty = null)
227
+	public function create($user, $closepaidinvoices = 0, $thirdparty = null)
228 228
 	{
229 229
 		global $conf, $langs;
230 230
 
@@ -233,10 +233,10 @@  discard block
 block discarded – undo
233 233
 
234 234
 		$now = dol_now();
235 235
 
236
-        // Clean parameters
237
-        $totalamount = 0;
236
+		// Clean parameters
237
+		$totalamount = 0;
238 238
 		$totalamount_converted = 0;
239
-        $atleastonepaymentnotnull = 0;
239
+		$atleastonepaymentnotnull = 0;
240 240
 
241 241
 		if ($way == 'dolibarr')
242 242
 		{
@@ -263,16 +263,16 @@  discard block
 block discarded – undo
263 263
 		$totalamount_converted = price2num($totalamount_converted);
264 264
 
265 265
 		// Check parameters
266
-        if (empty($totalamount) && empty($atleastonepaymentnotnull))	 // We accept negative amounts for withdraw reject but not empty arrays
267
-        {
268
-        	$this->errors[] = 'TotalAmountEmpty';
269
-        	$this->error = 'TotalAmountEmpty';
270
-        	return -1;
271
-        }
266
+		if (empty($totalamount) && empty($atleastonepaymentnotnull))	 // We accept negative amounts for withdraw reject but not empty arrays
267
+		{
268
+			$this->errors[] = 'TotalAmountEmpty';
269
+			$this->error = 'TotalAmountEmpty';
270
+			return -1;
271
+		}
272 272
 
273
-        dol_syslog(get_class($this)."::create insert paiement", LOG_DEBUG);
273
+		dol_syslog(get_class($this)."::create insert paiement", LOG_DEBUG);
274 274
 
275
-        $this->db->begin();
275
+		$this->db->begin();
276 276
 
277 277
 		$this->ref = $this->getNextNumRef(is_object($thirdparty) ? $thirdparty : '');
278 278
 
@@ -314,17 +314,17 @@  discard block
 block discarded – undo
314 314
 						$invoice->fetch($facid);
315 315
 
316 316
 						// If we want to closed payed invoices
317
-					    if ($closepaidinvoices)
318
-					    {
319
-                            $paiement = $invoice->getSommePaiement();
320
-                            $creditnotes = $invoice->getSumCreditNotesUsed();
321
-                            $deposits = $invoice->getSumDepositsUsed();
322
-                            $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
323
-                            $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
317
+						if ($closepaidinvoices)
318
+						{
319
+							$paiement = $invoice->getSommePaiement();
320
+							$creditnotes = $invoice->getSumCreditNotesUsed();
321
+							$deposits = $invoice->getSumDepositsUsed();
322
+							$alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
323
+							$remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
324 324
 
325 325
 							//var_dump($invoice->total_ttc.' - '.$paiement.' -'.$creditnotes.' - '.$deposits.' - '.$remaintopay);exit;
326 326
 
327
-                            //Invoice types that are eligible for changing status to paid
327
+							//Invoice types that are eligible for changing status to paid
328 328
 							$affected_types = array(
329 329
 								Facture::TYPE_STANDARD,
330 330
 								Facture::TYPE_REPLACEMENT,
@@ -333,15 +333,15 @@  discard block
 block discarded – undo
333 333
 								Facture::TYPE_SITUATION
334 334
 							);
335 335
 
336
-                            if (!in_array($invoice->type, $affected_types)) dol_syslog("Invoice ".$facid." is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more.");
337
-                            elseif ($remaintopay) dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing more.");
338
-                            //else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
339
-                            else {
340
-                                // If invoice is a down payment, we also convert down payment to discount
341
-                                if ($invoice->type == Facture::TYPE_DEPOSIT)
342
-                                {
343
-			                        $amount_ht = $amount_tva = $amount_ttc = array();
344
-			                        $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
336
+							if (!in_array($invoice->type, $affected_types)) dol_syslog("Invoice ".$facid." is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more.");
337
+							elseif ($remaintopay) dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing more.");
338
+							//else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
339
+							else {
340
+								// If invoice is a down payment, we also convert down payment to discount
341
+								if ($invoice->type == Facture::TYPE_DEPOSIT)
342
+								{
343
+									$amount_ht = $amount_tva = $amount_ttc = array();
344
+									$multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
345 345
 
346 346
 									// Insert one discount by VAT rate category
347 347
 									$discount = new DiscountAbsolute($this->db);
@@ -382,48 +382,48 @@  discard block
 block discarded – undo
382 382
 										}
383 383
 									}
384 384
 
385
-                                    if ($error)
386
-                                    {
387
-                                        setEventMessages($discount->error, $discount->errors, 'errors');
388
-                                        $error++;
389
-                                    }
390
-                                }
391
-
392
-                                // Set invoice to paid
393
-                                if (!$error)
394
-                                {
395
-                                    $result = $invoice->set_paid($user, '', '');
396
-                                    if ($result < 0)
397
-                                    {
398
-                                        $this->error = $invoice->error;
399
-                                        $error++;
400
-                                    }
401
-                                }
402
-                            }
403
-					    }
404
-
405
-					    // Regenerate documents of invoices
406
-                        if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
407
-                        {
408
-                        	dol_syslog(get_class($this).'::create Regenerate the document after inserting payment for thirdparty default_lang='.(is_object($invoice->thirdparty) ? $invoice->thirdparty->default_lang : 'null'), LOG_DEBUG);
409
-
410
-                            $newlang = '';
411
-                            $outputlangs = $langs;
412
-                            if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
413
-                            	$invoice->fetch_thirdparty();
414
-                            	$newlang = $invoice->thirdparty->default_lang;
415
-                            }
416
-                            if (!empty($newlang)) {
417
-                            	$outputlangs = new Translate("", $conf);
418
-                            	$outputlangs->setDefaultLang($newlang);
419
-                            }
420
-                            $ret = $invoice->fetch($facid); // Reload to get new records
421
-                            $result = $invoice->generateDocument($invoice->modelpdf, $outputlangs);
422
-                            if ($result < 0) {
423
-                            	setEventMessages($invoice->error, $invoice->errors, 'errors');
424
-                            	$error++;
425
-                            }
426
-                        }
385
+									if ($error)
386
+									{
387
+										setEventMessages($discount->error, $discount->errors, 'errors');
388
+										$error++;
389
+									}
390
+								}
391
+
392
+								// Set invoice to paid
393
+								if (!$error)
394
+								{
395
+									$result = $invoice->set_paid($user, '', '');
396
+									if ($result < 0)
397
+									{
398
+										$this->error = $invoice->error;
399
+										$error++;
400
+									}
401
+								}
402
+							}
403
+						}
404
+
405
+						// Regenerate documents of invoices
406
+						if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
407
+						{
408
+							dol_syslog(get_class($this).'::create Regenerate the document after inserting payment for thirdparty default_lang='.(is_object($invoice->thirdparty) ? $invoice->thirdparty->default_lang : 'null'), LOG_DEBUG);
409
+
410
+							$newlang = '';
411
+							$outputlangs = $langs;
412
+							if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
413
+								$invoice->fetch_thirdparty();
414
+								$newlang = $invoice->thirdparty->default_lang;
415
+							}
416
+							if (!empty($newlang)) {
417
+								$outputlangs = new Translate("", $conf);
418
+								$outputlangs->setDefaultLang($newlang);
419
+							}
420
+							$ret = $invoice->fetch($facid); // Reload to get new records
421
+							$result = $invoice->generateDocument($invoice->modelpdf, $outputlangs);
422
+							if ($result < 0) {
423
+								setEventMessages($invoice->error, $invoice->errors, 'errors');
424
+								$error++;
425
+							}
426
+						}
427 427
 					} else {
428 428
 						$this->error = $this->db->lasterror();
429 429
 						$error++;
@@ -447,9 +447,9 @@  discard block
 block discarded – undo
447 447
 
448 448
 		if (!$error)
449 449
 		{
450
-		    $this->amount = $total;
451
-		    $this->total = $total; // deprecated
452
-		    $this->multicurrency_amount = $mtotal;
450
+			$this->amount = $total;
451
+			$this->total = $total; // deprecated
452
+			$this->multicurrency_amount = $mtotal;
453 453
 			$this->db->commit();
454 454
 			return $this->id;
455 455
 		} else {
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 	 *  @param	int		$notrigger		No trigger
468 468
 	 *  @return int     				<0 si ko, >0 si ok
469 469
 	 */
470
-    public function delete($notrigger = 0)
470
+	public function delete($notrigger = 0)
471 471
 	{
472 472
 		global $conf, $user, $langs;
473 473
 
@@ -503,16 +503,16 @@  discard block
 block discarded – undo
503 503
 				$accline->id = $accline->rowid = $bank_line_id;    // If not found, we set artificially rowid to allow delete of llx_bank_url
504 504
 			}
505 505
 
506
-            // Delete bank account url lines linked to payment
506
+			// Delete bank account url lines linked to payment
507 507
 			$result = $accline->delete_urls($user);
508
-            if ($result < 0)
509
-            {
510
-                $this->error = $accline->error;
508
+			if ($result < 0)
509
+			{
510
+				$this->error = $accline->error;
511 511
 				$this->db->rollback();
512 512
 				return -3;
513
-            }
513
+			}
514 514
 
515
-            // Delete bank account lines linked to payment
515
+			// Delete bank account lines linked to payment
516 516
 			$result = $accline->delete($user);
517 517
 			if ($result < 0)
518 518
 			{
@@ -528,10 +528,10 @@  discard block
 block discarded – undo
528 528
 			$result = $this->call_trigger('PAYMENT_CUSTOMER_DELETE', $user);
529 529
 			if ($result < 0)
530 530
 			{
531
-			    $this->db->rollback();
532
-			    return -1;
533
-            }
534
-            // End call triggers
531
+				$this->db->rollback();
532
+				return -1;
533
+			}
534
+			// End call triggers
535 535
 		}
536 536
 
537 537
 		// Delete payment (into paiement_facture and paiement)
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
 		{
544 544
 			$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement';
545 545
 			$sql .= ' WHERE rowid = '.$this->id;
546
-		    dol_syslog($sql);
546
+			dol_syslog($sql);
547 547
 			$result = $this->db->query($sql);
548 548
 			if (!$result)
549 549
 			{
@@ -562,144 +562,144 @@  discard block
 block discarded – undo
562 562
 	}
563 563
 
564 564
 
565
-    /**
566
-     *      Add a record into bank for payment + links between this bank record and sources of payment.
567
-     *      All payment properties (this->amount, this->amounts, ...) must have been set first like after a call to create().
568
-     *
569
-     *      @param	User	$user               Object of user making payment
570
-     *      @param  string	$mode               'payment', 'payment_supplier'
571
-     *      @param  string	$label              Label to use in bank record. Note: If label is '(WithdrawalPayment)', a third entry 'widthdraw' is added into bank_url.
572
-     *      @param  int		$accountid          Id of bank account to do link with
573
-     *      @param  string	$emetteur_nom       Name of transmitter
574
-     *      @param  string	$emetteur_banque    Name of bank
575
-     *      @param	int		$notrigger			No trigger
576
-     *      @return int                 		<0 if KO, bank_line_id if OK
577
-     */
578
-    public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque, $notrigger = 0)
579
-    {
580
-        global $conf, $langs, $user;
565
+	/**
566
+	 *      Add a record into bank for payment + links between this bank record and sources of payment.
567
+	 *      All payment properties (this->amount, this->amounts, ...) must have been set first like after a call to create().
568
+	 *
569
+	 *      @param	User	$user               Object of user making payment
570
+	 *      @param  string	$mode               'payment', 'payment_supplier'
571
+	 *      @param  string	$label              Label to use in bank record. Note: If label is '(WithdrawalPayment)', a third entry 'widthdraw' is added into bank_url.
572
+	 *      @param  int		$accountid          Id of bank account to do link with
573
+	 *      @param  string	$emetteur_nom       Name of transmitter
574
+	 *      @param  string	$emetteur_banque    Name of bank
575
+	 *      @param	int		$notrigger			No trigger
576
+	 *      @return int                 		<0 if KO, bank_line_id if OK
577
+	 */
578
+	public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque, $notrigger = 0)
579
+	{
580
+		global $conf, $langs, $user;
581 581
 
582
-        $error = 0;
583
-        $bank_line_id = 0;
582
+		$error = 0;
583
+		$bank_line_id = 0;
584 584
 
585
-        if (!empty($conf->banque->enabled))
586
-        {
587
-        	if ($accountid <= 0)
588
-        	{
589
-        		$this->error = 'Bad value for parameter accountid='.$accountid;
590
-        		dol_syslog(get_class($this).'::addPaymentToBank '.$this->error, LOG_ERR);
591
-        		return -1;
592
-        	}
585
+		if (!empty($conf->banque->enabled))
586
+		{
587
+			if ($accountid <= 0)
588
+			{
589
+				$this->error = 'Bad value for parameter accountid='.$accountid;
590
+				dol_syslog(get_class($this).'::addPaymentToBank '.$this->error, LOG_ERR);
591
+				return -1;
592
+			}
593 593
 
594
-        	$this->db->begin();
594
+			$this->db->begin();
595 595
 
596
-        	$this->fk_account = $accountid;
596
+			$this->fk_account = $accountid;
597 597
 
598
-        	include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
598
+			include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
599 599
 
600
-            dol_syslog("$user->id, $mode, $label, $this->fk_account, $emetteur_nom, $emetteur_banque");
600
+			dol_syslog("$user->id, $mode, $label, $this->fk_account, $emetteur_nom, $emetteur_banque");
601 601
 
602
-            $acc = new Account($this->db);
603
-            $result = $acc->fetch($this->fk_account);
602
+			$acc = new Account($this->db);
603
+			$result = $acc->fetch($this->fk_account);
604 604
 
605 605
 			$totalamount = $this->amount;
606
-            if (empty($totalamount)) $totalamount = $this->total; // For backward compatibility
607
-
608
-            // if dolibarr currency != bank currency then we received an amount in customer currency (currently I don't manage the case : my currency is USD, the customer currency is EUR and he paid me in GBP. Seems no sense for me)
609
-            if (!empty($conf->multicurrency->enabled) && $conf->currency != $acc->currency_code) $totalamount = $this->multicurrency_amount;
610
-
611
-            if ($mode == 'payment_supplier') $totalamount = -$totalamount;
612
-
613
-            // Insert payment into llx_bank
614
-            $bank_line_id = $acc->addline(
615
-                $this->datepaye,
616
-                $this->paiementid, // Payment mode id or code ("CHQ or VIR for example")
617
-                $label,
618
-                $totalamount, // Sign must be positive when we receive money (customer payment), negative when you give money (supplier invoice or credit note)
619
-                $this->num_payment,
620
-                '',
621
-                $user,
622
-                $emetteur_nom,
623
-                $emetteur_banque
624
-            );
625
-
626
-            // Mise a jour fk_bank dans llx_paiement
627
-            // On connait ainsi le paiement qui a genere l'ecriture bancaire
628
-            if ($bank_line_id > 0)
629
-            {
630
-                $result = $this->update_fk_bank($bank_line_id);
631
-                if ($result <= 0)
632
-                {
633
-                    $error++;
634
-                    dol_print_error($this->db);
635
-                }
636
-
637
-                // Add link 'payment', 'payment_supplier' in bank_url between payment and bank transaction
638
-                if (!$error)
639
-                {
640
-                    $url = '';
641
-                    if ($mode == 'payment') $url = DOL_URL_ROOT.'/compta/paiement/card.php?id=';
642
-                    if ($mode == 'payment_supplier') $url = DOL_URL_ROOT.'/fourn/paiement/card.php?id=';
643
-                    if ($url)
644
-                    {
645
-                        $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
646
-                        if ($result <= 0)
647
-                        {
648
-                            $error++;
649
-                            dol_print_error($this->db);
650
-                        }
651
-                    }
652
-                }
653
-
654
-                // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
655
-                //if (! $error && $label != '(WithdrawalPayment)')
656
-                if (!$error)
657
-                {
658
-                    $linkaddedforthirdparty = array();
659
-                    foreach ($this->amounts as $key => $value)  // We should have invoices always for same third party but we loop in case of.
660
-                    {
661
-                        if ($mode == 'payment')
662
-                        {
663
-                            $fac = new Facture($this->db);
664
-                            $fac->fetch($key);
665
-                            $fac->fetch_thirdparty();
666
-                            if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) // Not yet done for this thirdparty
667
-                            {
668
-                                $result = $acc->add_url_line(
669
-                                    $bank_line_id,
670
-                                    $fac->thirdparty->id,
671
-                                    DOL_URL_ROOT.'/comm/card.php?socid=',
672
-                                    $fac->thirdparty->name,
673
-                                    'company'
674
-                                );
675
-                                if ($result <= 0) dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
676
-                                $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
677
-                            }
678
-                        }
679
-                        if ($mode == 'payment_supplier')
680
-                        {
681
-                            $fac = new FactureFournisseur($this->db);
682
-                            $fac->fetch($key);
683
-                            $fac->fetch_thirdparty();
684
-                            if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) // Not yet done for this thirdparty
685
-                            {
686
-                                $result = $acc->add_url_line(
687
-                                    $bank_line_id,
688
-                                    $fac->thirdparty->id,
689
-                                    DOL_URL_ROOT.'/fourn/card.php?socid=',
690
-                                    $fac->thirdparty->name,
691
-                                    'company'
692
-                                );
693
-                                if ($result <= 0) dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
694
-                                $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
695
-                            }
696
-                        }
697
-                    }
698
-                }
606
+			if (empty($totalamount)) $totalamount = $this->total; // For backward compatibility
607
+
608
+			// if dolibarr currency != bank currency then we received an amount in customer currency (currently I don't manage the case : my currency is USD, the customer currency is EUR and he paid me in GBP. Seems no sense for me)
609
+			if (!empty($conf->multicurrency->enabled) && $conf->currency != $acc->currency_code) $totalamount = $this->multicurrency_amount;
610
+
611
+			if ($mode == 'payment_supplier') $totalamount = -$totalamount;
612
+
613
+			// Insert payment into llx_bank
614
+			$bank_line_id = $acc->addline(
615
+				$this->datepaye,
616
+				$this->paiementid, // Payment mode id or code ("CHQ or VIR for example")
617
+				$label,
618
+				$totalamount, // Sign must be positive when we receive money (customer payment), negative when you give money (supplier invoice or credit note)
619
+				$this->num_payment,
620
+				'',
621
+				$user,
622
+				$emetteur_nom,
623
+				$emetteur_banque
624
+			);
625
+
626
+			// Mise a jour fk_bank dans llx_paiement
627
+			// On connait ainsi le paiement qui a genere l'ecriture bancaire
628
+			if ($bank_line_id > 0)
629
+			{
630
+				$result = $this->update_fk_bank($bank_line_id);
631
+				if ($result <= 0)
632
+				{
633
+					$error++;
634
+					dol_print_error($this->db);
635
+				}
636
+
637
+				// Add link 'payment', 'payment_supplier' in bank_url between payment and bank transaction
638
+				if (!$error)
639
+				{
640
+					$url = '';
641
+					if ($mode == 'payment') $url = DOL_URL_ROOT.'/compta/paiement/card.php?id=';
642
+					if ($mode == 'payment_supplier') $url = DOL_URL_ROOT.'/fourn/paiement/card.php?id=';
643
+					if ($url)
644
+					{
645
+						$result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
646
+						if ($result <= 0)
647
+						{
648
+							$error++;
649
+							dol_print_error($this->db);
650
+						}
651
+					}
652
+				}
653
+
654
+				// Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
655
+				//if (! $error && $label != '(WithdrawalPayment)')
656
+				if (!$error)
657
+				{
658
+					$linkaddedforthirdparty = array();
659
+					foreach ($this->amounts as $key => $value)  // We should have invoices always for same third party but we loop in case of.
660
+					{
661
+						if ($mode == 'payment')
662
+						{
663
+							$fac = new Facture($this->db);
664
+							$fac->fetch($key);
665
+							$fac->fetch_thirdparty();
666
+							if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) // Not yet done for this thirdparty
667
+							{
668
+								$result = $acc->add_url_line(
669
+									$bank_line_id,
670
+									$fac->thirdparty->id,
671
+									DOL_URL_ROOT.'/comm/card.php?socid=',
672
+									$fac->thirdparty->name,
673
+									'company'
674
+								);
675
+								if ($result <= 0) dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
676
+								$linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
677
+							}
678
+						}
679
+						if ($mode == 'payment_supplier')
680
+						{
681
+							$fac = new FactureFournisseur($this->db);
682
+							$fac->fetch($key);
683
+							$fac->fetch_thirdparty();
684
+							if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) // Not yet done for this thirdparty
685
+							{
686
+								$result = $acc->add_url_line(
687
+									$bank_line_id,
688
+									$fac->thirdparty->id,
689
+									DOL_URL_ROOT.'/fourn/card.php?socid=',
690
+									$fac->thirdparty->name,
691
+									'company'
692
+								);
693
+								if ($result <= 0) dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
694
+								$linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
695
+							}
696
+						}
697
+					}
698
+				}
699 699
 
700 700
 				// Add link 'WithdrawalPayment' in bank_url
701 701
 				if (!$error && $label == '(WithdrawalPayment)') {
702
-                    $result = $acc->add_url_line(
702
+					$result = $acc->add_url_line(
703 703
 						$bank_line_id,
704 704
 						$this->id_prelevement,
705 705
 						DOL_URL_ROOT.'/compta/prelevement/card.php?id=',
@@ -708,45 +708,45 @@  discard block
 block discarded – undo
708 708
 					);
709 709
 				}
710 710
 
711
-	            if (!$error && !$notrigger)
711
+				if (!$error && !$notrigger)
712 712
 				{
713 713
 					// Appel des triggers
714 714
 					$result = $this->call_trigger('PAYMENT_ADD_TO_BANK', $user);
715
-				    if ($result < 0) { $error++; }
716
-				    // Fin appel triggers
715
+					if ($result < 0) { $error++; }
716
+					// Fin appel triggers
717 717
 				}
718
-            } else {
719
-                $this->error = $acc->error;
720
-                $error++;
721
-            }
722
-
723
-            if (!$error)
724
-            {
725
-            	$this->db->commit();
726
-            } else {
727
-            	$this->db->rollback();
728
-            }
729
-        }
730
-
731
-        if (!$error)
732
-        {
733
-            return $bank_line_id;
734
-        } else {
735
-            return -1;
736
-        }
737
-    }
738
-
739
-
740
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
718
+			} else {
719
+				$this->error = $acc->error;
720
+				$error++;
721
+			}
722
+
723
+			if (!$error)
724
+			{
725
+				$this->db->commit();
726
+			} else {
727
+				$this->db->rollback();
728
+			}
729
+		}
730
+
731
+		if (!$error)
732
+		{
733
+			return $bank_line_id;
734
+		} else {
735
+			return -1;
736
+		}
737
+	}
738
+
739
+
740
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
741 741
 	/**
742 742
 	 *      Mise a jour du lien entre le paiement et la ligne generee dans llx_bank
743 743
 	 *
744 744
 	 *      @param	int		$id_bank    Id compte bancaire
745 745
 	 *      @return	int					<0 if KO, >0 if OK
746 746
 	 */
747
-    public function update_fk_bank($id_bank)
747
+	public function update_fk_bank($id_bank)
748 748
 	{
749
-        // phpcs:enable
749
+		// phpcs:enable
750 750
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' set fk_bank = '.$id_bank;
751 751
 		$sql .= ' WHERE rowid = '.$this->id;
752 752
 
@@ -756,102 +756,102 @@  discard block
 block discarded – undo
756 756
 		{
757 757
 			return 1;
758 758
 		} else {
759
-            $this->error = $this->db->lasterror();
760
-            dol_syslog(get_class($this).'::update_fk_bank '.$this->error);
759
+			$this->error = $this->db->lasterror();
760
+			dol_syslog(get_class($this).'::update_fk_bank '.$this->error);
761 761
 			return -1;
762 762
 		}
763
-    }
764
-
765
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
766
-    /**
767
-     *	Updates the payment date
768
-     *
769
-     *  @param	int	$date   New date
770
-     *  @return int					<0 if KO, 0 if OK
771
-     */
772
-    public function update_date($date)
773
-    {
774
-        // phpcs:enable
775
-        $error = 0;
776
-
777
-        if (!empty($date) && $this->statut != 1)
778
-        {
779
-            $this->db->begin();
780
-
781
-            dol_syslog(get_class($this)."::update_date with date = ".$date, LOG_DEBUG);
782
-
783
-            $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
784
-            $sql .= " SET datep = '".$this->db->idate($date)."'";
785
-            $sql .= " WHERE rowid = ".$this->id;
786
-
787
-            $result = $this->db->query($sql);
788
-            if (!$result)
789
-            {
790
-                $error++;
791
-                $this->error = 'Error -1 '.$this->db->error();
792
-            }
793
-
794
-            $type = $this->element;
795
-
796
-            $sql = "UPDATE ".MAIN_DB_PREFIX.'bank';
797
-            $sql .= " SET dateo = '".$this->db->idate($date)."', datev = '".$this->db->idate($date)."'";
798
-            $sql .= " WHERE rowid IN (SELECT fk_bank FROM ".MAIN_DB_PREFIX."bank_url WHERE type = '".$type."' AND url_id = ".$this->id.")";
799
-            $sql .= " AND rappro = 0";
800
-
801
-            $result = $this->db->query($sql);
802
-            if (!$result)
803
-            {
804
-                $error++;
805
-                $this->error = 'Error -1 '.$this->db->error();
806
-            }
807
-
808
-            if (!$error)
809
-            {
810
-            }
811
-
812
-            if (!$error)
813
-            {
814
-                $this->datepaye = $date;
815
-                $this->date = $date;
816
-
817
-                $this->db->commit();
818
-                return 0;
819
-            } else {
820
-                $this->db->rollback();
821
-                return -2;
822
-            }
823
-        }
824
-        return -1; //no date given or already validated
825
-    }
826
-
827
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
828
-    /**
829
-     *  Updates the payment number
830
-     *
831
-     *  @param	string	$num		New num
832
-     *  @return int					<0 if KO, 0 if OK
833
-     */
834
-    public function update_num($num)
835
-    {
836
-        // phpcs:enable
837
-        if (!empty($num) && $this->statut != 1) {
838
-            $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
839
-            $sql .= " SET num_paiement = '".$this->db->escape($num)."'";
840
-            $sql .= " WHERE rowid = ".$this->id;
841
-
842
-            dol_syslog(get_class($this)."::update_num", LOG_DEBUG);
843
-            $result = $this->db->query($sql);
844
-            if ($result)
845
-            {
846
-            	$this->num_payment = $this->db->escape($num);
847
-                return 0;
848
-            } else {
849
-                $this->error = 'Error -1 '.$this->db->error();
850
-                return -2;
851
-            }
852
-        }
853
-        return -1; //no num given or already validated
854
-    }
763
+	}
764
+
765
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
766
+	/**
767
+	 *	Updates the payment date
768
+	 *
769
+	 *  @param	int	$date   New date
770
+	 *  @return int					<0 if KO, 0 if OK
771
+	 */
772
+	public function update_date($date)
773
+	{
774
+		// phpcs:enable
775
+		$error = 0;
776
+
777
+		if (!empty($date) && $this->statut != 1)
778
+		{
779
+			$this->db->begin();
780
+
781
+			dol_syslog(get_class($this)."::update_date with date = ".$date, LOG_DEBUG);
782
+
783
+			$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
784
+			$sql .= " SET datep = '".$this->db->idate($date)."'";
785
+			$sql .= " WHERE rowid = ".$this->id;
786
+
787
+			$result = $this->db->query($sql);
788
+			if (!$result)
789
+			{
790
+				$error++;
791
+				$this->error = 'Error -1 '.$this->db->error();
792
+			}
793
+
794
+			$type = $this->element;
795
+
796
+			$sql = "UPDATE ".MAIN_DB_PREFIX.'bank';
797
+			$sql .= " SET dateo = '".$this->db->idate($date)."', datev = '".$this->db->idate($date)."'";
798
+			$sql .= " WHERE rowid IN (SELECT fk_bank FROM ".MAIN_DB_PREFIX."bank_url WHERE type = '".$type."' AND url_id = ".$this->id.")";
799
+			$sql .= " AND rappro = 0";
800
+
801
+			$result = $this->db->query($sql);
802
+			if (!$result)
803
+			{
804
+				$error++;
805
+				$this->error = 'Error -1 '.$this->db->error();
806
+			}
807
+
808
+			if (!$error)
809
+			{
810
+			}
811
+
812
+			if (!$error)
813
+			{
814
+				$this->datepaye = $date;
815
+				$this->date = $date;
816
+
817
+				$this->db->commit();
818
+				return 0;
819
+			} else {
820
+				$this->db->rollback();
821
+				return -2;
822
+			}
823
+		}
824
+		return -1; //no date given or already validated
825
+	}
826
+
827
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
828
+	/**
829
+	 *  Updates the payment number
830
+	 *
831
+	 *  @param	string	$num		New num
832
+	 *  @return int					<0 if KO, 0 if OK
833
+	 */
834
+	public function update_num($num)
835
+	{
836
+		// phpcs:enable
837
+		if (!empty($num) && $this->statut != 1) {
838
+			$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
839
+			$sql .= " SET num_paiement = '".$this->db->escape($num)."'";
840
+			$sql .= " WHERE rowid = ".$this->id;
841
+
842
+			dol_syslog(get_class($this)."::update_num", LOG_DEBUG);
843
+			$result = $this->db->query($sql);
844
+			if ($result)
845
+			{
846
+				$this->num_payment = $this->db->escape($num);
847
+				return 0;
848
+			} else {
849
+				$this->error = 'Error -1 '.$this->db->error();
850
+				return -2;
851
+			}
852
+		}
853
+		return -1; //no num given or already validated
854
+	}
855 855
 
856 856
 	/**
857 857
 	 *    Validate payment
@@ -859,8 +859,8 @@  discard block
 block discarded – undo
859 859
 	 *	  @param	User	$user		User making validation
860 860
 	 *    @return   int     			<0 if KO, >0 if OK
861 861
 	 */
862
-    public function valide(User $user = null)
863
-    {
862
+	public function valide(User $user = null)
863
+	{
864 864
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 1 WHERE rowid = '.$this->id;
865 865
 
866 866
 		dol_syslog(get_class($this).'::valide', LOG_DEBUG);
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
 			dol_syslog(get_class($this).'::valide '.$this->error);
874 874
 			return -1;
875 875
 		}
876
-    }
876
+	}
877 877
 
878 878
 	/**
879 879
 	 *    Reject payment
@@ -881,8 +881,8 @@  discard block
 block discarded – undo
881 881
 	 *	  @param	User	$user		User making reject
882 882
 	 *    @return   int     			<0 if KO, >0 if OK
883 883
 	 */
884
-    public function reject(User $user = null)
885
-    {
884
+	public function reject(User $user = null)
885
+	{
886 886
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 2 WHERE rowid = '.$this->id;
887 887
 
888 888
 		dol_syslog(get_class($this).'::reject', LOG_DEBUG);
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
 			dol_syslog(get_class($this).'::reject '.$this->error);
896 896
 			return -1;
897 897
 		}
898
-    }
898
+	}
899 899
 
900 900
 	/**
901 901
 	 *    Information sur l'objet
@@ -903,8 +903,8 @@  discard block
 block discarded – undo
903 903
 	 *    @param   int     $id      id du paiement dont il faut afficher les infos
904 904
 	 *    @return  void
905 905
 	 */
906
-    public function info($id)
907
-    {
906
+	public function info($id)
907
+	{
908 908
 		$sql = 'SELECT p.rowid, p.datec, p.fk_user_creat, p.fk_user_modif, p.tms';
909 909
 		$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p';
910 910
 		$sql .= ' WHERE p.rowid = '.$id;
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
 		} else {
938 938
 			dol_print_error($this->db);
939 939
 		}
940
-    }
940
+	}
941 941
 
942 942
 	/**
943 943
 	 *  Return list of invoices the payment is related to.
@@ -945,8 +945,8 @@  discard block
 block discarded – undo
945 945
 	 *  @param	string		$filter         Filter
946 946
 	 *  @return int|array					<0 if KO or array of invoice id
947 947
 	 */
948
-    public function getBillsArray($filter = '')
949
-    {
948
+	public function getBillsArray($filter = '')
949
+	{
950 950
 		$sql = 'SELECT pf.fk_facture';
951 951
 		$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf, '.MAIN_DB_PREFIX.'facture as f'; // We keep link on invoice to allow use of some filters on invoice
952 952
 		$sql .= ' WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = '.$this->id;
@@ -971,39 +971,39 @@  discard block
 block discarded – undo
971 971
 			dol_syslog(get_class($this).'::getBillsArray Error '.$this->error.' -', LOG_DEBUG);
972 972
 			return -1;
973 973
 		}
974
-    }
975
-
976
-    /**
977
-     *  Return list of amounts of payments.
978
-     *
979
-     *  @return int|array					Array of amount of payments
980
-     */
981
-    public function getAmountsArray()
982
-    {
983
-    	$sql = 'SELECT pf.fk_facture, pf.amount';
984
-    	$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
985
-    	$sql .= ' WHERE pf.fk_paiement = '.$this->id;
986
-    	$resql = $this->db->query($sql);
987
-    	if ($resql)
988
-    	{
989
-    		$i = 0;
990
-    		$num = $this->db->num_rows($resql);
991
-    		$amounts = array();
992
-
993
-    		while ($i < $num)
994
-    		{
995
-    			$obj = $this->db->fetch_object($resql);
996
-    			$amounts[$obj->fk_facture] = $obj->amount;
997
-    			$i++;
998
-    		}
999
-
1000
-    		return $amounts;
1001
-    	} else {
1002
-    		$this->error = $this->db->error();
1003
-    		dol_syslog(get_class($this).'::getAmountsArray Error '.$this->error.' -', LOG_DEBUG);
1004
-    		return -1;
1005
-    	}
1006
-    }
974
+	}
975
+
976
+	/**
977
+	 *  Return list of amounts of payments.
978
+	 *
979
+	 *  @return int|array					Array of amount of payments
980
+	 */
981
+	public function getAmountsArray()
982
+	{
983
+		$sql = 'SELECT pf.fk_facture, pf.amount';
984
+		$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
985
+		$sql .= ' WHERE pf.fk_paiement = '.$this->id;
986
+		$resql = $this->db->query($sql);
987
+		if ($resql)
988
+		{
989
+			$i = 0;
990
+			$num = $this->db->num_rows($resql);
991
+			$amounts = array();
992
+
993
+			while ($i < $num)
994
+			{
995
+				$obj = $this->db->fetch_object($resql);
996
+				$amounts[$obj->fk_facture] = $obj->amount;
997
+				$i++;
998
+			}
999
+
1000
+			return $amounts;
1001
+		} else {
1002
+			$this->error = $this->db->error();
1003
+			dol_syslog(get_class($this).'::getAmountsArray Error '.$this->error.' -', LOG_DEBUG);
1004
+			return -1;
1005
+		}
1006
+	}
1007 1007
 
1008 1008
 	/**
1009 1009
 	 *      Return next reference of customer invoice not already used (or last reference)
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
 	 *      @param     string		$mode		'next' for next value or 'last' for last value
1014 1014
 	 *      @return    string					free ref or last ref
1015 1015
 	 */
1016
-    public function getNextNumRef($soc, $mode = 'next')
1016
+	public function getNextNumRef($soc, $mode = 'next')
1017 1017
 	{
1018 1018
 		global $conf, $db, $langs;
1019 1019
 		$langs->load("bills");
@@ -1093,7 +1093,7 @@  discard block
 block discarded – undo
1093 1093
 	 *
1094 1094
 	 * 	@return 	string 	'dolibarr' if standard comportment or paid in main currency, 'customer' if payment received from multicurrency inputs
1095 1095
 	 */
1096
-    public function getWay()
1096
+	public function getWay()
1097 1097
 	{
1098 1098
 		global $conf;
1099 1099
 
@@ -1121,7 +1121,7 @@  discard block
 block discarded – undo
1121 1121
 	 *	@param	string		$option		''=Create a specimen invoice with lines, 'nolines'=No lines
1122 1122
 	 *  @return	void
1123 1123
 	 */
1124
-    public function initAsSpecimen($option = '')
1124
+	public function initAsSpecimen($option = '')
1125 1125
 	{
1126 1126
 		global $user, $langs, $conf;
1127 1127
 
@@ -1144,50 +1144,50 @@  discard block
 block discarded – undo
1144 1144
 	 *	@param	int		$withpicto		0=No picto, 1=Include picto into link, 2=Only picto
1145 1145
 	 *	@param	string	$option			Sur quoi pointe le lien
1146 1146
 	 *  @param  string  $mode           'withlistofinvoices'=Include list of invoices into tooltip
1147
-     *  @param	int  	$notooltip		1=Disable tooltip
1147
+	 *  @param	int  	$notooltip		1=Disable tooltip
1148 1148
 	 *	@return	string					Chaine avec URL
1149 1149
 	 */
1150
-    public function getNomUrl($withpicto = 0, $option = '', $mode = 'withlistofinvoices', $notooltip = 0)
1150
+	public function getNomUrl($withpicto = 0, $option = '', $mode = 'withlistofinvoices', $notooltip = 0)
1151 1151
 	{
1152 1152
 		global $conf, $langs;
1153 1153
 
1154 1154
 		if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
1155 1155
 
1156 1156
 		$result = '';
1157
-        $label = '<u>'.$langs->trans("Payment").'</u><br>';
1158
-        $label .= '<strong>'.$langs->trans("Ref").':</strong> '.$this->ref;
1159
-        if ($this->datepaye ? $this->datepaye : $this->date) $label .= '<br><strong>'.$langs->trans("Date").':</strong> '.dol_print_date($this->datepaye ? $this->datepaye : $this->date, 'dayhour');
1160
-        if ($mode == 'withlistofinvoices')
1161
-        {
1162
-            $arraybill = $this->getBillsArray();
1163
-            if (is_array($arraybill) && count($arraybill) > 0)
1164
-            {
1165
-            	include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1166
-            	$facturestatic = new Facture($this->db);
1167
-            	foreach ($arraybill as $billid)
1168
-            	{
1169
-            		$facturestatic->fetch($billid);
1170
-            		$label .= '<br> '.$facturestatic->getNomUrl(1).' '.$facturestatic->getLibStatut(2, 1);
1171
-            	}
1172
-            }
1173
-        }
1174
-
1175
-        $linkclose = '';
1176
-        if (empty($notooltip))
1177
-        {
1178
-        	if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1179
-        	{
1180
-        		$label = $langs->trans("ShowMyObject");
1181
-        		$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1182
-        	}
1183
-        	$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1184
-        	$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
1185
-        } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1186
-
1187
-        $url = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$this->id;
1188
-
1189
-        $linkstart = '<a href="'.$url.'"';
1190
-        $linkstart .= $linkclose.'>';
1157
+		$label = '<u>'.$langs->trans("Payment").'</u><br>';
1158
+		$label .= '<strong>'.$langs->trans("Ref").':</strong> '.$this->ref;
1159
+		if ($this->datepaye ? $this->datepaye : $this->date) $label .= '<br><strong>'.$langs->trans("Date").':</strong> '.dol_print_date($this->datepaye ? $this->datepaye : $this->date, 'dayhour');
1160
+		if ($mode == 'withlistofinvoices')
1161
+		{
1162
+			$arraybill = $this->getBillsArray();
1163
+			if (is_array($arraybill) && count($arraybill) > 0)
1164
+			{
1165
+				include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1166
+				$facturestatic = new Facture($this->db);
1167
+				foreach ($arraybill as $billid)
1168
+				{
1169
+					$facturestatic->fetch($billid);
1170
+					$label .= '<br> '.$facturestatic->getNomUrl(1).' '.$facturestatic->getLibStatut(2, 1);
1171
+				}
1172
+			}
1173
+		}
1174
+
1175
+		$linkclose = '';
1176
+		if (empty($notooltip))
1177
+		{
1178
+			if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1179
+			{
1180
+				$label = $langs->trans("ShowMyObject");
1181
+				$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1182
+			}
1183
+			$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1184
+			$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
1185
+		} else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1186
+
1187
+		$url = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$this->id;
1188
+
1189
+		$linkstart = '<a href="'.$url.'"';
1190
+		$linkstart .= $linkclose.'>';
1191 1191
 		$linkend = '</a>';
1192 1192
 
1193 1193
 		$result .= $linkstart;
@@ -1204,12 +1204,12 @@  discard block
 block discarded – undo
1204 1204
 	 * @param	int		$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
1205 1205
 	 * @return  string				Libelle
1206 1206
 	 */
1207
-    public function getLibStatut($mode = 0)
1207
+	public function getLibStatut($mode = 0)
1208 1208
 	{
1209 1209
 		return $this->LibStatut($this->statut, $mode);
1210 1210
 	}
1211 1211
 
1212
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1212
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1213 1213
 	/**
1214 1214
 	 * Renvoi le libelle d'un statut donne
1215 1215
 	 *
@@ -1217,9 +1217,9 @@  discard block
 block discarded – undo
1217 1217
 	 * @param   int		$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
1218 1218
 	 * @return	string  		    Libelle du statut
1219 1219
 	 */
1220
-    public function LibStatut($status, $mode = 0)
1220
+	public function LibStatut($status, $mode = 0)
1221 1221
 	{
1222
-        // phpcs:enable
1222
+		// phpcs:enable
1223 1223
 		global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
1224 1224
 
1225 1225
 		$langs->load('compta');
@@ -1261,16 +1261,16 @@  discard block
 block discarded – undo
1261 1261
 		return '';
1262 1262
 	}
1263 1263
 
1264
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1264
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1265 1265
 	/**
1266 1266
 	 *  Load the third party of object, from id into this->thirdparty
1267 1267
 	 *
1268 1268
 	 *	@param		int		$force_thirdparty_id	Force thirdparty id
1269 1269
 	 *	@return		int								<0 if KO, >0 if OK
1270 1270
 	 */
1271
-    public function fetch_thirdparty($force_thirdparty_id = 0)
1271
+	public function fetch_thirdparty($force_thirdparty_id = 0)
1272 1272
 	{
1273
-        // phpcs:enable
1273
+		// phpcs:enable
1274 1274
 		include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1275 1275
 
1276 1276
 		if (empty($force_thirdparty_id))
Please login to merge, or discard this patch.
Braces   +84 added lines, -32 removed lines patch added patch discarded remove patch
@@ -168,12 +168,13 @@  discard block
 block discarded – undo
168 168
 		$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
169 169
 		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
170 170
 		$sql .= ' WHERE p.entity IN ('.getEntity('invoice').')';
171
-		if ($id > 0)
172
-			$sql .= ' AND p.rowid = '.$id;
173
-		elseif ($ref)
174
-			$sql .= " AND p.ref = '".$ref."'";
175
-		elseif ($fk_bank)
176
-			$sql .= ' AND p.fk_bank = '.$fk_bank;
171
+		if ($id > 0) {
172
+					$sql .= ' AND p.rowid = '.$id;
173
+		} elseif ($ref) {
174
+					$sql .= " AND p.ref = '".$ref."'";
175
+		} elseif ($fk_bank) {
176
+					$sql .= ' AND p.fk_bank = '.$fk_bank;
177
+		}
177 178
 
178 179
 		$resql = $this->db->query($sql);
179 180
 		if ($resql)
@@ -247,25 +248,31 @@  discard block
 block discarded – undo
247 248
 			$amounts_to_update = &$this->amounts;
248 249
 		}
249 250
 
250
-		foreach ($amounts as $key => $value)	// How payment is dispatch
251
+		foreach ($amounts as $key => $value) {
252
+			// How payment is dispatch
251 253
 		{
252 254
 			$value_converted = Multicurrency::getAmountConversionFromInvoiceRate($key, $value, $way);
255
+		}
253 256
 			$totalamount_converted += $value_converted;
254 257
 			$amounts_to_update[$key] = price2num($value_converted, 'MT');
255 258
 
256 259
 			$newvalue = price2num($value, 'MT');
257 260
 			$amounts[$key] = $newvalue;
258 261
 			$totalamount += $newvalue;
259
-			if (!empty($newvalue)) $atleastonepaymentnotnull++;
262
+			if (!empty($newvalue)) {
263
+				$atleastonepaymentnotnull++;
264
+			}
260 265
 		}
261 266
 
262 267
 		$totalamount = price2num($totalamount);
263 268
 		$totalamount_converted = price2num($totalamount_converted);
264 269
 
265 270
 		// Check parameters
266
-        if (empty($totalamount) && empty($atleastonepaymentnotnull))	 // We accept negative amounts for withdraw reject but not empty arrays
271
+        if (empty($totalamount) && empty($atleastonepaymentnotnull)) {
272
+        	// We accept negative amounts for withdraw reject but not empty arrays
267 273
         {
268 274
         	$this->errors[] = 'TotalAmountEmpty';
275
+        }
269 276
         	$this->error = 'TotalAmountEmpty';
270 277
         	return -1;
271 278
         }
@@ -333,8 +340,11 @@  discard block
 block discarded – undo
333 340
 								Facture::TYPE_SITUATION
334 341
 							);
335 342
 
336
-                            if (!in_array($invoice->type, $affected_types)) dol_syslog("Invoice ".$facid." is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more.");
337
-                            elseif ($remaintopay) dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing more.");
343
+                            if (!in_array($invoice->type, $affected_types)) {
344
+                            	dol_syslog("Invoice ".$facid." is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more.");
345
+                            } elseif ($remaintopay) {
346
+                            	dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing more.");
347
+                            }
338 348
                             //else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
339 349
                             else {
340 350
                                 // If invoice is a down payment, we also convert down payment to discount
@@ -433,10 +443,12 @@  discard block
 block discarded – undo
433 443
 				}
434 444
 			}
435 445
 
436
-			if (!$error)    // All payments into $this->amounts were recorded without errors
446
+			if (!$error) {
447
+				// All payments into $this->amounts were recorded without errors
437 448
 			{
438 449
 				// Appel des triggers
439 450
 				$result = $this->call_trigger('PAYMENT_CUSTOMER_CREATE', $user);
451
+			}
440 452
 				if ($result < 0) { $error++; }
441 453
 				// Fin appel triggers
442 454
 			}
@@ -603,12 +615,19 @@  discard block
 block discarded – undo
603 615
             $result = $acc->fetch($this->fk_account);
604 616
 
605 617
 			$totalamount = $this->amount;
606
-            if (empty($totalamount)) $totalamount = $this->total; // For backward compatibility
618
+            if (empty($totalamount)) {
619
+            	$totalamount = $this->total;
620
+            }
621
+            // For backward compatibility
607 622
 
608 623
             // if dolibarr currency != bank currency then we received an amount in customer currency (currently I don't manage the case : my currency is USD, the customer currency is EUR and he paid me in GBP. Seems no sense for me)
609
-            if (!empty($conf->multicurrency->enabled) && $conf->currency != $acc->currency_code) $totalamount = $this->multicurrency_amount;
624
+            if (!empty($conf->multicurrency->enabled) && $conf->currency != $acc->currency_code) {
625
+            	$totalamount = $this->multicurrency_amount;
626
+            }
610 627
 
611
-            if ($mode == 'payment_supplier') $totalamount = -$totalamount;
628
+            if ($mode == 'payment_supplier') {
629
+            	$totalamount = -$totalamount;
630
+            }
612 631
 
613 632
             // Insert payment into llx_bank
614 633
             $bank_line_id = $acc->addline(
@@ -638,8 +657,12 @@  discard block
 block discarded – undo
638 657
                 if (!$error)
639 658
                 {
640 659
                     $url = '';
641
-                    if ($mode == 'payment') $url = DOL_URL_ROOT.'/compta/paiement/card.php?id=';
642
-                    if ($mode == 'payment_supplier') $url = DOL_URL_ROOT.'/fourn/paiement/card.php?id=';
660
+                    if ($mode == 'payment') {
661
+                    	$url = DOL_URL_ROOT.'/compta/paiement/card.php?id=';
662
+                    }
663
+                    if ($mode == 'payment_supplier') {
664
+                    	$url = DOL_URL_ROOT.'/fourn/paiement/card.php?id=';
665
+                    }
643 666
                     if ($url)
644 667
                     {
645 668
                         $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
@@ -656,14 +679,17 @@  discard block
 block discarded – undo
656 679
                 if (!$error)
657 680
                 {
658 681
                     $linkaddedforthirdparty = array();
659
-                    foreach ($this->amounts as $key => $value)  // We should have invoices always for same third party but we loop in case of.
682
+                    foreach ($this->amounts as $key => $value) {
683
+                    	// We should have invoices always for same third party but we loop in case of.
660 684
                     {
661 685
                         if ($mode == 'payment')
662 686
                         {
663 687
                             $fac = new Facture($this->db);
688
+                    }
664 689
                             $fac->fetch($key);
665 690
                             $fac->fetch_thirdparty();
666
-                            if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) // Not yet done for this thirdparty
691
+                            if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) {
692
+                            	// Not yet done for this thirdparty
667 693
                             {
668 694
                                 $result = $acc->add_url_line(
669 695
                                     $bank_line_id,
@@ -672,7 +698,10 @@  discard block
 block discarded – undo
672 698
                                     $fac->thirdparty->name,
673 699
                                     'company'
674 700
                                 );
675
-                                if ($result <= 0) dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
701
+                            }
702
+                                if ($result <= 0) {
703
+                                	dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
704
+                                }
676 705
                                 $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
677 706
                             }
678 707
                         }
@@ -681,7 +710,8 @@  discard block
 block discarded – undo
681 710
                             $fac = new FactureFournisseur($this->db);
682 711
                             $fac->fetch($key);
683 712
                             $fac->fetch_thirdparty();
684
-                            if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) // Not yet done for this thirdparty
713
+                            if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) {
714
+                            	// Not yet done for this thirdparty
685 715
                             {
686 716
                                 $result = $acc->add_url_line(
687 717
                                     $bank_line_id,
@@ -690,7 +720,10 @@  discard block
 block discarded – undo
690 720
                                     $fac->thirdparty->name,
691 721
                                     'company'
692 722
                                 );
693
-                                if ($result <= 0) dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
723
+                            }
724
+                                if ($result <= 0) {
725
+                                	dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
726
+                                }
694 727
                                 $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
695 728
                             }
696 729
                         }
@@ -950,7 +983,9 @@  discard block
 block discarded – undo
950 983
 		$sql = 'SELECT pf.fk_facture';
951 984
 		$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf, '.MAIN_DB_PREFIX.'facture as f'; // We keep link on invoice to allow use of some filters on invoice
952 985
 		$sql .= ' WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = '.$this->id;
953
-		if ($filter) $sql .= ' AND '.$filter;
986
+		if ($filter) {
987
+			$sql .= ' AND '.$filter;
988
+		}
954 989
 		$resql = $this->db->query($sql);
955 990
 		if ($resql)
956 991
 		{
@@ -1019,9 +1054,13 @@  discard block
 block discarded – undo
1019 1054
 		$langs->load("bills");
1020 1055
 
1021 1056
 		// Clean parameters (if not defined or using deprecated value)
1022
-		if (empty($conf->global->PAYMENT_ADDON)) $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1023
-		elseif ($conf->global->PAYMENT_ADDON == 'ant') $conf->global->PAYMENT_ADDON = 'mod_payment_ant';
1024
-		elseif ($conf->global->PAYMENT_ADDON == 'cicada') $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1057
+		if (empty($conf->global->PAYMENT_ADDON)) {
1058
+			$conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1059
+		} elseif ($conf->global->PAYMENT_ADDON == 'ant') {
1060
+			$conf->global->PAYMENT_ADDON = 'mod_payment_ant';
1061
+		} elseif ($conf->global->PAYMENT_ADDON == 'cicada') {
1062
+			$conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1063
+		}
1025 1064
 
1026 1065
 		if (!empty($conf->global->PAYMENT_ADDON))
1027 1066
 		{
@@ -1102,9 +1141,11 @@  discard block
 block discarded – undo
1102 1141
 		{
1103 1142
 			foreach ($this->multicurrency_amounts as $value)
1104 1143
 			{
1105
-				if (!empty($value)) // one value found then payment is in invoice currency
1144
+				if (!empty($value)) {
1145
+					// one value found then payment is in invoice currency
1106 1146
 				{
1107 1147
 					$way = 'customer';
1148
+				}
1108 1149
 					break;
1109 1150
 				}
1110 1151
 			}
@@ -1151,12 +1192,17 @@  discard block
 block discarded – undo
1151 1192
 	{
1152 1193
 		global $conf, $langs;
1153 1194
 
1154
-		if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
1195
+		if (!empty($conf->dol_no_mouse_hover)) {
1196
+			$notooltip = 1;
1197
+		}
1198
+		// Force disable tooltips
1155 1199
 
1156 1200
 		$result = '';
1157 1201
         $label = '<u>'.$langs->trans("Payment").'</u><br>';
1158 1202
         $label .= '<strong>'.$langs->trans("Ref").':</strong> '.$this->ref;
1159
-        if ($this->datepaye ? $this->datepaye : $this->date) $label .= '<br><strong>'.$langs->trans("Date").':</strong> '.dol_print_date($this->datepaye ? $this->datepaye : $this->date, 'dayhour');
1203
+        if ($this->datepaye ? $this->datepaye : $this->date) {
1204
+        	$label .= '<br><strong>'.$langs->trans("Date").':</strong> '.dol_print_date($this->datepaye ? $this->datepaye : $this->date, 'dayhour');
1205
+        }
1160 1206
         if ($mode == 'withlistofinvoices')
1161 1207
         {
1162 1208
             $arraybill = $this->getBillsArray();
@@ -1182,7 +1228,9 @@  discard block
 block discarded – undo
1182 1228
         	}
1183 1229
         	$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1184 1230
         	$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
1185
-        } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1231
+        } else {
1232
+        	$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1233
+        }
1186 1234
 
1187 1235
         $url = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$this->id;
1188 1236
 
@@ -1191,8 +1239,12 @@  discard block
 block discarded – undo
1191 1239
 		$linkend = '</a>';
1192 1240
 
1193 1241
 		$result .= $linkstart;
1194
-		if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1195
-		if ($withpicto && $withpicto != 2) $result .= ($this->ref ? $this->ref : $this->id);
1242
+		if ($withpicto) {
1243
+			$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1244
+		}
1245
+		if ($withpicto && $withpicto != 2) {
1246
+			$result .= ($this->ref ? $this->ref : $this->id);
1247
+		}
1196 1248
 		$result .= $linkend;
1197 1249
 
1198 1250
 		return $result;
Please login to merge, or discard this patch.
htdocs/compta/sociales/class/paymentsocialcontribution.class.php 2 patches
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -47,8 +47,8 @@  discard block
 block discarded – undo
47 47
 	public $picto = 'payment';
48 48
 
49 49
 	/**
50
-     * @var int ID
51
-     */
50
+	 * @var int ID
51
+	 */
52 52
 	public $fk_charge;
53 53
 
54 54
 	public $datec = '';
@@ -61,12 +61,12 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	public $total;
63 63
 
64
-    public $amount; // Total amount of payment
65
-    public $amounts = array(); // Array of amounts
64
+	public $amount; // Total amount of payment
65
+	public $amounts = array(); // Array of amounts
66 66
 
67
-    /**
68
-     * @var int ID
69
-     */
67
+	/**
68
+	 * @var int ID
69
+	 */
70 70
 	public $fk_typepaiement;
71 71
 
72 72
 	/**
@@ -81,18 +81,18 @@  discard block
 block discarded – undo
81 81
 	public $num_payment;
82 82
 
83 83
 	/**
84
-     * @var int ID
85
-     */
84
+	 * @var int ID
85
+	 */
86 86
 	public $fk_bank;
87 87
 
88 88
 	/**
89
-     * @var int ID
90
-     */
89
+	 * @var int ID
90
+	 */
91 91
 	public $fk_user_creat;
92 92
 
93 93
 	/**
94
-     * @var int ID
95
-     */
94
+	 * @var int ID
95
+	 */
96 96
 	public $fk_user_modif;
97 97
 
98 98
 	/**
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 
108 108
 	/**
109 109
 	 *  Create payment of social contribution into database.
110
-     *  Use this->amounts to have list of lines for the payment
111
-     *
110
+	 *  Use this->amounts to have list of lines for the payment
111
+	 *
112 112
 	 *  @param      User	$user   				User making payment
113 113
 	 *	@param		int		$closepaidcontrib   	1=Also close payed contributions to paid, 0=Do nothing more
114 114
 	 *  @return     int     						<0 if KO, id of payment if OK
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 
120 120
 		$error = 0;
121 121
 
122
-        $now = dol_now();
122
+		$now = dol_now();
123 123
 
124 124
 		dol_syslog(get_class($this)."::create", LOG_DEBUG);
125 125
 
@@ -141,17 +141,17 @@  discard block
 block discarded – undo
141 141
 		if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat;
142 142
 		if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif;
143 143
 
144
-        $totalamount = 0;
145
-        foreach ($this->amounts as $key => $value)  // How payment is dispatch
146
-        {
147
-            $newvalue = price2num($value, 'MT');
148
-            $this->amounts[$key] = $newvalue;
149
-            $totalamount += $newvalue;
150
-        }
151
-        $totalamount = price2num($totalamount);
144
+		$totalamount = 0;
145
+		foreach ($this->amounts as $key => $value)  // How payment is dispatch
146
+		{
147
+			$newvalue = price2num($value, 'MT');
148
+			$this->amounts[$key] = $newvalue;
149
+			$totalamount += $newvalue;
150
+		}
151
+		$totalamount = price2num($totalamount);
152 152
 
153
-        // Check parameters
154
-        if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null
153
+		// Check parameters
154
+		if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null
155 155
 
156 156
 
157 157
 		$this->db->begin();
@@ -208,9 +208,9 @@  discard block
 block discarded – undo
208 208
 
209 209
 		if ($totalamount != 0 && !$error)
210 210
 		{
211
-		    $this->amount = $totalamount;
212
-            $this->total = $totalamount; // deprecated
213
-		    $this->db->commit();
211
+			$this->amount = $totalamount;
212
+			$this->total = $totalamount; // deprecated
213
+			$this->db->commit();
214 214
 			return $this->id;
215 215
 		} else {
216 216
 			$this->error = $this->db->error();
@@ -374,16 +374,16 @@  discard block
 block discarded – undo
374 374
 
375 375
 		$this->db->begin();
376 376
 
377
-	    if ($this->bank_line > 0)
378
-        {
379
-        	$accline = new AccountLine($this->db);
377
+		if ($this->bank_line > 0)
378
+		{
379
+			$accline = new AccountLine($this->db);
380 380
 			$accline->fetch($this->bank_line);
381 381
 			$result = $accline->delete();
382 382
 			if ($result < 0) {
383 383
 				$this->errors[] = $accline->error;
384 384
 				$error++;
385 385
 			}
386
-        }
386
+		}
387 387
 
388 388
 		if (!$error)
389 389
 		{
@@ -462,11 +462,11 @@  discard block
 block discarded – undo
462 462
 
463 463
 
464 464
 	/**
465
-     *  Initialise an instance with random values.
466
-     *  Used to build previews or test instances.
467
-     *	id must be 0 if object instance is a specimen.
468
-     *
469
-     *  @return	void
465
+	 *  Initialise an instance with random values.
466
+	 *  Used to build previews or test instances.
467
+	 *	id must be 0 if object instance is a specimen.
468
+	 *
469
+	 *  @return	void
470 470
 	 */
471 471
 	public function initAsSpecimen()
472 472
 	{
@@ -487,102 +487,102 @@  discard block
 block discarded – undo
487 487
 	}
488 488
 
489 489
 
490
-    /**
491
-     *      Add record into bank for payment with links between this bank record and invoices of payment.
492
-     *      All payment properties must have been set first like after a call to create().
493
-     *
494
-     *      @param	User	$user               Object of user making payment
495
-     *      @param  string	$mode               'payment_sc'
496
-     *      @param  string	$label              Label to use in bank record
497
-     *      @param  int		$accountid          Id of bank account to do link with
498
-     *      @param  string	$emetteur_nom       Name of transmitter
499
-     *      @param  string	$emetteur_banque    Name of bank
500
-     *      @return int                 		<0 if KO, >0 if OK
501
-     */
502
-    public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
503
-    {
504
-        global $conf;
490
+	/**
491
+	 *      Add record into bank for payment with links between this bank record and invoices of payment.
492
+	 *      All payment properties must have been set first like after a call to create().
493
+	 *
494
+	 *      @param	User	$user               Object of user making payment
495
+	 *      @param  string	$mode               'payment_sc'
496
+	 *      @param  string	$label              Label to use in bank record
497
+	 *      @param  int		$accountid          Id of bank account to do link with
498
+	 *      @param  string	$emetteur_nom       Name of transmitter
499
+	 *      @param  string	$emetteur_banque    Name of bank
500
+	 *      @return int                 		<0 if KO, >0 if OK
501
+	 */
502
+	public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
503
+	{
504
+		global $conf;
505 505
 
506 506
 		// Clean data
507
-        $this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
508
-
509
-        $error = 0;
510
-
511
-        if (!empty($conf->banque->enabled))
512
-        {
513
-            include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
514
-
515
-            $acc = new Account($this->db);
516
-            $acc->fetch($accountid);
517
-
518
-            $total = $this->total;
519
-            if ($mode == 'payment_sc') $total = -$total;
520
-
521
-            // Insert payment into llx_bank
522
-            $bank_line_id = $acc->addline(
523
-                $this->datepaye,
524
-                $this->paiementtype, // Payment mode id or code ("CHQ or VIR for example")
525
-                $label,
526
-                $total,
527
-                $this->num_payment,
528
-                '',
529
-                $user,
530
-                $emetteur_nom,
531
-                $emetteur_banque
532
-            );
533
-
534
-            // Mise a jour fk_bank dans llx_paiement.
535
-            // On connait ainsi le paiement qui a genere l'ecriture bancaire
536
-            if ($bank_line_id > 0)
537
-            {
538
-                $result = $this->update_fk_bank($bank_line_id);
539
-                if ($result <= 0)
540
-                {
541
-                    $error++;
542
-                    dol_print_error($this->db);
543
-                }
544
-
545
-                // Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction
546
-                $url = '';
547
-                if ($mode == 'payment_sc') $url = DOL_URL_ROOT.'/compta/payment_sc/card.php?id=';
548
-                if ($url)
549
-                {
550
-                    $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
551
-                    if ($result <= 0)
552
-                    {
553
-                        $error++;
554
-                        dol_print_error($this->db);
555
-                    }
556
-                }
557
-
558
-                // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
559
-                $linkaddedforthirdparty = array();
560
-                foreach ($this->amounts as $key => $value)
561
-                {
562
-                    if ($mode == 'payment_sc')
563
-                    {
564
-                        $socialcontrib = new ChargeSociales($this->db);
565
-                        $socialcontrib->fetch($key);
566
-                        $result = $acc->add_url_line($bank_line_id, $socialcontrib->id, DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_label.(($socialcontrib->lib && $socialcontrib->lib != $socialcontrib->type_label) ? ' ('.$socialcontrib->lib.')' : ''), 'sc');
567
-                        if ($result <= 0) dol_print_error($this->db);
568
-                    }
569
-                }
570
-            } else {
571
-                $this->error = $acc->error;
572
-                $error++;
573
-            }
574
-        }
575
-
576
-        if (!$error)
577
-        {
578
-            return 1;
579
-        } else {
580
-            return -1;
581
-        }
582
-    }
583
-
584
-
585
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
507
+		$this->num_payment = trim($this->num_payment ? $this->num_payment : $this->num_paiement);
508
+
509
+		$error = 0;
510
+
511
+		if (!empty($conf->banque->enabled))
512
+		{
513
+			include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
514
+
515
+			$acc = new Account($this->db);
516
+			$acc->fetch($accountid);
517
+
518
+			$total = $this->total;
519
+			if ($mode == 'payment_sc') $total = -$total;
520
+
521
+			// Insert payment into llx_bank
522
+			$bank_line_id = $acc->addline(
523
+				$this->datepaye,
524
+				$this->paiementtype, // Payment mode id or code ("CHQ or VIR for example")
525
+				$label,
526
+				$total,
527
+				$this->num_payment,
528
+				'',
529
+				$user,
530
+				$emetteur_nom,
531
+				$emetteur_banque
532
+			);
533
+
534
+			// Mise a jour fk_bank dans llx_paiement.
535
+			// On connait ainsi le paiement qui a genere l'ecriture bancaire
536
+			if ($bank_line_id > 0)
537
+			{
538
+				$result = $this->update_fk_bank($bank_line_id);
539
+				if ($result <= 0)
540
+				{
541
+					$error++;
542
+					dol_print_error($this->db);
543
+				}
544
+
545
+				// Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction
546
+				$url = '';
547
+				if ($mode == 'payment_sc') $url = DOL_URL_ROOT.'/compta/payment_sc/card.php?id=';
548
+				if ($url)
549
+				{
550
+					$result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
551
+					if ($result <= 0)
552
+					{
553
+						$error++;
554
+						dol_print_error($this->db);
555
+					}
556
+				}
557
+
558
+				// Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
559
+				$linkaddedforthirdparty = array();
560
+				foreach ($this->amounts as $key => $value)
561
+				{
562
+					if ($mode == 'payment_sc')
563
+					{
564
+						$socialcontrib = new ChargeSociales($this->db);
565
+						$socialcontrib->fetch($key);
566
+						$result = $acc->add_url_line($bank_line_id, $socialcontrib->id, DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_label.(($socialcontrib->lib && $socialcontrib->lib != $socialcontrib->type_label) ? ' ('.$socialcontrib->lib.')' : ''), 'sc');
567
+						if ($result <= 0) dol_print_error($this->db);
568
+					}
569
+				}
570
+			} else {
571
+				$this->error = $acc->error;
572
+				$error++;
573
+			}
574
+		}
575
+
576
+		if (!$error)
577
+		{
578
+			return 1;
579
+		} else {
580
+			return -1;
581
+		}
582
+	}
583
+
584
+
585
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
586 586
 	/**
587 587
 	 *  Mise a jour du lien entre le paiement de  charge et la ligne dans llx_bank generee
588 588
 	 *
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
 	 */
592 592
 	public function update_fk_bank($id_bank)
593 593
 	{
594
-        // phpcs:enable
594
+		// phpcs:enable
595 595
 		$sql = "UPDATE ".MAIN_DB_PREFIX."paiementcharge SET fk_bank = ".$id_bank." WHERE rowid = ".$this->id;
596 596
 
597 597
 		dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
 		return $this->LibStatut($this->statut, $mode);
618 618
 	}
619 619
 
620
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
620
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
621 621
 	/**
622 622
 	 * Renvoi le libelle d'un statut donne
623 623
 	 *
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
 	 */
628 628
 	public function LibStatut($status, $mode = 0)
629 629
 	{
630
-        // phpcs:enable
630
+		// phpcs:enable
631 631
 		global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
632 632
 
633 633
 		$langs->load('compta');
@@ -683,17 +683,17 @@  discard block
 block discarded – undo
683 683
 		$result = '';
684 684
 
685 685
 		if (empty($this->ref)) $this->ref = $this->lib;
686
-        $label = $langs->trans("Payment").': '.$this->ref;
686
+		$label = $langs->trans("Payment").': '.$this->ref;
687 687
 
688
-        if (!empty($this->id)) {
689
-            $link = '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
690
-            $linkend = '</a>';
688
+		if (!empty($this->id)) {
689
+			$link = '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
690
+			$linkend = '</a>';
691 691
 
692
-            if ($withpicto) $result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' ');
693
-            if ($withpicto && $withpicto != 2) $result .= ' ';
694
-            if ($withpicto != 2) $result .= $link.($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref).$linkend;
695
-        }
692
+			if ($withpicto) $result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' ');
693
+			if ($withpicto && $withpicto != 2) $result .= ' ';
694
+			if ($withpicto != 2) $result .= $link.($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref).$linkend;
695
+		}
696 696
 
697
-        return $result;
698
-    }
697
+		return $result;
698
+	}
699 699
 }
Please login to merge, or discard this patch.
Braces   +90 added lines, -29 removed lines patch added patch discarded remove patch
@@ -131,27 +131,51 @@  discard block
 block discarded – undo
131 131
 		}
132 132
 
133 133
 		// Clean parameters
134
-		if (isset($this->fk_charge)) $this->fk_charge = (int) $this->fk_charge;
135
-		if (isset($this->amount)) $this->amount = trim($this->amount);
136
-		if (isset($this->fk_typepaiement)) $this->fk_typepaiement = (int) $this->fk_typepaiement;
137
-		if (isset($this->num_paiement)) $this->num_paiement = trim($this->num_paiement); // deprecated
138
-		if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
139
-		if (isset($this->note)) $this->note = trim($this->note);
140
-		if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank;
141
-		if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat;
142
-		if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif;
134
+		if (isset($this->fk_charge)) {
135
+			$this->fk_charge = (int) $this->fk_charge;
136
+		}
137
+		if (isset($this->amount)) {
138
+			$this->amount = trim($this->amount);
139
+		}
140
+		if (isset($this->fk_typepaiement)) {
141
+			$this->fk_typepaiement = (int) $this->fk_typepaiement;
142
+		}
143
+		if (isset($this->num_paiement)) {
144
+			$this->num_paiement = trim($this->num_paiement);
145
+		}
146
+		// deprecated
147
+		if (isset($this->num_payment)) {
148
+			$this->num_payment = trim($this->num_payment);
149
+		}
150
+		if (isset($this->note)) {
151
+			$this->note = trim($this->note);
152
+		}
153
+		if (isset($this->fk_bank)) {
154
+			$this->fk_bank = (int) $this->fk_bank;
155
+		}
156
+		if (isset($this->fk_user_creat)) {
157
+			$this->fk_user_creat = (int) $this->fk_user_creat;
158
+		}
159
+		if (isset($this->fk_user_modif)) {
160
+			$this->fk_user_modif = (int) $this->fk_user_modif;
161
+		}
143 162
 
144 163
         $totalamount = 0;
145
-        foreach ($this->amounts as $key => $value)  // How payment is dispatch
164
+        foreach ($this->amounts as $key => $value) {
165
+        	// How payment is dispatch
146 166
         {
147 167
             $newvalue = price2num($value, 'MT');
168
+        }
148 169
             $this->amounts[$key] = $newvalue;
149 170
             $totalamount += $newvalue;
150 171
         }
151 172
         $totalamount = price2num($totalamount);
152 173
 
153 174
         // Check parameters
154
-        if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null
175
+        if ($totalamount == 0) {
176
+        	return -1;
177
+        }
178
+        // On accepte les montants negatifs pour les rejets de prelevement mais pas null
155 179
 
156 180
 
157 181
 		$this->db->begin();
@@ -194,7 +218,9 @@  discard block
 block discarded – undo
194 218
 							if ($remaintopay == 0)
195 219
 							{
196 220
 								$result = $contrib->set_paid($user);
197
-							} else dol_syslog("Remain to pay for conrib ".$contribid." not null. We do nothing.");
221
+							} else {
222
+								dol_syslog("Remain to pay for conrib ".$contribid." not null. We do nothing.");
223
+							}
198 224
 						}
199 225
 					}
200 226
 				}
@@ -204,7 +230,9 @@  discard block
 block discarded – undo
204 230
 		}
205 231
 
206 232
 		$result = $this->call_trigger('PAYMENTSOCIALCONTRIBUTION_CREATE', $user);
207
-		if ($result < 0) $error++;
233
+		if ($result < 0) {
234
+			$error++;
235
+		}
208 236
 
209 237
 		if ($totalamount != 0 && !$error)
210 238
 		{
@@ -302,15 +330,34 @@  discard block
 block discarded – undo
302 330
 
303 331
 		// Clean parameters
304 332
 
305
-		if (isset($this->fk_charge)) $this->fk_charge = (int) $this->fk_charge;
306
-		if (isset($this->amount)) $this->amount = trim($this->amount);
307
-		if (isset($this->fk_typepaiement)) $this->fk_typepaiement = (int) $this->fk_typepaiement;
308
-		if (isset($this->num_paiement)) $this->num_paiement = trim($this->num_paiement); // deprecated
309
-		if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
310
-		if (isset($this->note)) $this->note = trim($this->note);
311
-		if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank;
312
-		if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat;
313
-		if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif;
333
+		if (isset($this->fk_charge)) {
334
+			$this->fk_charge = (int) $this->fk_charge;
335
+		}
336
+		if (isset($this->amount)) {
337
+			$this->amount = trim($this->amount);
338
+		}
339
+		if (isset($this->fk_typepaiement)) {
340
+			$this->fk_typepaiement = (int) $this->fk_typepaiement;
341
+		}
342
+		if (isset($this->num_paiement)) {
343
+			$this->num_paiement = trim($this->num_paiement);
344
+		}
345
+		// deprecated
346
+		if (isset($this->num_payment)) {
347
+			$this->num_payment = trim($this->num_payment);
348
+		}
349
+		if (isset($this->note)) {
350
+			$this->note = trim($this->note);
351
+		}
352
+		if (isset($this->fk_bank)) {
353
+			$this->fk_bank = (int) $this->fk_bank;
354
+		}
355
+		if (isset($this->fk_user_creat)) {
356
+			$this->fk_user_creat = (int) $this->fk_user_creat;
357
+		}
358
+		if (isset($this->fk_user_modif)) {
359
+			$this->fk_user_modif = (int) $this->fk_user_modif;
360
+		}
314 361
 
315 362
 
316 363
 
@@ -516,7 +563,9 @@  discard block
 block discarded – undo
516 563
             $acc->fetch($accountid);
517 564
 
518 565
             $total = $this->total;
519
-            if ($mode == 'payment_sc') $total = -$total;
566
+            if ($mode == 'payment_sc') {
567
+            	$total = -$total;
568
+            }
520 569
 
521 570
             // Insert payment into llx_bank
522 571
             $bank_line_id = $acc->addline(
@@ -544,7 +593,9 @@  discard block
 block discarded – undo
544 593
 
545 594
                 // Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction
546 595
                 $url = '';
547
-                if ($mode == 'payment_sc') $url = DOL_URL_ROOT.'/compta/payment_sc/card.php?id=';
596
+                if ($mode == 'payment_sc') {
597
+                	$url = DOL_URL_ROOT.'/compta/payment_sc/card.php?id=';
598
+                }
548 599
                 if ($url)
549 600
                 {
550 601
                     $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
@@ -564,7 +615,9 @@  discard block
 block discarded – undo
564 615
                         $socialcontrib = new ChargeSociales($this->db);
565 616
                         $socialcontrib->fetch($key);
566 617
                         $result = $acc->add_url_line($bank_line_id, $socialcontrib->id, DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_label.(($socialcontrib->lib && $socialcontrib->lib != $socialcontrib->type_label) ? ' ('.$socialcontrib->lib.')' : ''), 'sc');
567
-                        if ($result <= 0) dol_print_error($this->db);
618
+                        if ($result <= 0) {
619
+                        	dol_print_error($this->db);
620
+                        }
568 621
                     }
569 622
                 }
570 623
             } else {
@@ -682,16 +735,24 @@  discard block
 block discarded – undo
682 735
 
683 736
 		$result = '';
684 737
 
685
-		if (empty($this->ref)) $this->ref = $this->lib;
738
+		if (empty($this->ref)) {
739
+			$this->ref = $this->lib;
740
+		}
686 741
         $label = $langs->trans("Payment").': '.$this->ref;
687 742
 
688 743
         if (!empty($this->id)) {
689 744
             $link = '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
690 745
             $linkend = '</a>';
691 746
 
692
-            if ($withpicto) $result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' ');
693
-            if ($withpicto && $withpicto != 2) $result .= ' ';
694
-            if ($withpicto != 2) $result .= $link.($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref).$linkend;
747
+            if ($withpicto) {
748
+            	$result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' ');
749
+            }
750
+            if ($withpicto && $withpicto != 2) {
751
+            	$result .= ' ';
752
+            }
753
+            if ($withpicto != 2) {
754
+            	$result .= $link.($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref).$linkend;
755
+            }
695 756
         }
696 757
 
697 758
         return $result;
Please login to merge, or discard this patch.
htdocs/compta/facture/class/facture.class.php 2 patches
Indentation   +644 added lines, -644 removed lines patch added patch discarded remove patch
@@ -100,13 +100,13 @@  discard block
 block discarded – undo
100 100
 	public $author;
101 101
 
102 102
 	/**
103
-     * @var int ID
104
-     */
103
+	 * @var int ID
104
+	 */
105 105
 	public $fk_user_author;
106 106
 
107 107
 	/**
108
-     * @var int ID
109
-     */
108
+	 * @var int ID
109
+	 */
110 110
 	public $fk_user_valid;
111 111
 
112 112
 	public $date; // Date invoice
@@ -153,8 +153,8 @@  discard block
 block discarded – undo
153 153
 	public $mode_reglement_code; // Code in llx_c_paiement
154 154
 
155 155
 	/**
156
-     * @var int ID Field to store bank id to use when payment mode is withdraw
157
-     */
156
+	 * @var int ID Field to store bank id to use when payment mode is withdraw
157
+	 */
158 158
 	public $fk_bank;
159 159
 
160 160
 	/**
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
 
176 176
 	// Multicurrency
177 177
 	/**
178
-     * @var int ID
179
-     */
178
+	 * @var int ID
179
+	 */
180 180
 	public $fk_multicurrency;
181 181
 
182 182
 	public $multicurrency_code;
@@ -323,30 +323,30 @@  discard block
 block discarded – undo
323 323
 	);
324 324
 	// END MODULEBUILDER PROPERTIES
325 325
 
326
-    /**
327
-     * Standard invoice
328
-     */
329
-    const TYPE_STANDARD = 0;
326
+	/**
327
+	 * Standard invoice
328
+	 */
329
+	const TYPE_STANDARD = 0;
330 330
 
331
-    /**
332
-     * Replacement invoice
333
-     */
334
-    const TYPE_REPLACEMENT = 1;
331
+	/**
332
+	 * Replacement invoice
333
+	 */
334
+	const TYPE_REPLACEMENT = 1;
335 335
 
336
-    /**
337
-     * Credit note invoice
338
-     */
339
-    const TYPE_CREDIT_NOTE = 2;
336
+	/**
337
+	 * Credit note invoice
338
+	 */
339
+	const TYPE_CREDIT_NOTE = 2;
340 340
 
341
-    /**
342
-     * Deposit invoice
343
-     */
344
-    const TYPE_DEPOSIT = 3;
341
+	/**
342
+	 * Deposit invoice
343
+	 */
344
+	const TYPE_DEPOSIT = 3;
345 345
 
346
-    /**
347
-     * Proforma invoice (should not be used. a proforma is an order)
348
-     */
349
-    const TYPE_PROFORMA = 4;
346
+	/**
347
+	 * Proforma invoice (should not be used. a proforma is an order)
348
+	 */
349
+	const TYPE_PROFORMA = 4;
350 350
 
351 351
 	/**
352 352
 	 * Situation invoice
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 	 * 	@param	int		$forceduedate	If set, do not recalculate due date from payment condition but force it with value
408 408
 	 *	@return	int						<0 if KO, >0 if OK
409 409
 	 */
410
-    public function create(User $user, $notrigger = 0, $forceduedate = 0)
410
+	public function create(User $user, $notrigger = 0, $forceduedate = 0)
411 411
 	{
412 412
 		global $langs, $conf, $mysoc, $hookmanager;
413 413
 		$error = 0;
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 		// Create invoice from a template invoice
462 462
 		if ($this->fac_rec > 0)
463 463
 		{
464
-		    $this->fk_fac_rec_source = $this->fac_rec;
464
+			$this->fk_fac_rec_source = $this->fac_rec;
465 465
 
466 466
 			require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
467 467
 			$_facrec = new FactureRec($this->db);
@@ -503,9 +503,9 @@  discard block
 block discarded – undo
503 503
 			$this->ref_client = trim($this->ref_client);
504 504
 			$this->note_public = trim($this->note_public);
505 505
 			$this->note_private = trim($this->note_private);
506
-		    $this->note_private = dol_concatdesc($this->note_private, $langs->trans("GeneratedFromRecurringInvoice", $_facrec->ref));
506
+			$this->note_private = dol_concatdesc($this->note_private, $langs->trans("GeneratedFromRecurringInvoice", $_facrec->ref));
507 507
 
508
-		    $this->array_options = $_facrec->array_options;
508
+			$this->array_options = $_facrec->array_options;
509 509
 
510 510
 			//if (! $this->remise) $this->remise = 0;
511 511
 			if (!$this->mode_reglement_id) $this->mode_reglement_id = 0;
@@ -520,12 +520,12 @@  discard block
 block discarded – undo
520 520
 			// For recurring invoices, update date and number of last generation of recurring template invoice, before inserting new invoice
521 521
 			if ($_facrec->frequency > 0)
522 522
 			{
523
-			    dol_syslog("This is a recurring invoice so we set date_last_gen and next date_when");
524
-			    if (empty($_facrec->date_when)) $_facrec->date_when = $now;
525
-                $next_date = $_facrec->getNextDate(); // Calculate next date
526
-                $result = $_facrec->setValueFrom('date_last_gen', $now, '', null, 'date', '', $user, '');
527
-                //$_facrec->setValueFrom('nb_gen_done', $_facrec->nb_gen_done + 1);		// Not required, +1 already included into setNextDate when second param is 1.
528
-                $result = $_facrec->setNextDate($next_date, 1);
523
+				dol_syslog("This is a recurring invoice so we set date_last_gen and next date_when");
524
+				if (empty($_facrec->date_when)) $_facrec->date_when = $now;
525
+				$next_date = $_facrec->getNextDate(); // Calculate next date
526
+				$result = $_facrec->setValueFrom('date_last_gen', $now, '', null, 'date', '', $user, '');
527
+				//$_facrec->setValueFrom('nb_gen_done', $_facrec->nb_gen_done + 1);		// Not required, +1 already included into setNextDate when second param is 1.
528
+				$result = $_facrec->setNextDate($next_date, 1);
529 529
 			}
530 530
 
531 531
 			// Define lang of customer
@@ -536,8 +536,8 @@  discard block
 block discarded – undo
536 536
 			if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->default_lang)) $newlang = $this->default_lang; // for thirdparty
537 537
 			if (!empty($newlang))
538 538
 			{
539
-			    $outputlangs = new Translate("", $conf);
540
-			    $outputlangs->setDefaultLang($newlang);
539
+				$outputlangs = new Translate("", $conf);
540
+				$outputlangs->setDefaultLang($newlang);
541 541
 			}
542 542
 
543 543
 			// Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
@@ -567,16 +567,16 @@  discard block
 block discarded – undo
567 567
 		}
568 568
 
569 569
 		// Define due date if not already defined
570
-        if (empty($forceduedate)) {
571
-            $duedate = $this->calculate_date_lim_reglement();
572
-            /*if ($duedate < 0) {	Regression, a date can be negative if before 1970.
570
+		if (empty($forceduedate)) {
571
+			$duedate = $this->calculate_date_lim_reglement();
572
+			/*if ($duedate < 0) {	Regression, a date can be negative if before 1970.
573 573
                 dol_syslog(__METHOD__ . ' Error in calculate_date_lim_reglement. We got ' . $duedate, LOG_ERR);
574 574
                 return -1;
575 575
             }*/
576
-            $this->date_lim_reglement = $duedate;
577
-        } else {
578
-            $this->date_lim_reglement = $forceduedate;
579
-        }
576
+			$this->date_lim_reglement = $duedate;
577
+		} else {
578
+			$this->date_lim_reglement = $forceduedate;
579
+		}
580 580
 
581 581
 		// Insert into database
582 582
 		$socid = $this->socid;
@@ -595,17 +595,17 @@  discard block
 block discarded – undo
595 595
 		$sql .= ", note_private";
596 596
 		$sql .= ", note_public";
597 597
 		$sql .= ", ref_client, ref_int";
598
-        $sql .= ", fk_account";
598
+		$sql .= ", fk_account";
599 599
 		$sql .= ", module_source, pos_source, fk_fac_rec_source, fk_facture_source, fk_user_author, fk_projet";
600 600
 		$sql .= ", fk_cond_reglement, fk_mode_reglement, date_lim_reglement, model_pdf";
601 601
 		$sql .= ", situation_cycle_ref, situation_counter, situation_final";
602 602
 		$sql .= ", fk_incoterms, location_incoterms";
603
-        $sql .= ", fk_multicurrency";
604
-        $sql .= ", multicurrency_code";
605
-        $sql .= ", multicurrency_tx";
606
-        $sql .= ", retained_warranty";
607
-        $sql .= ", retained_warranty_date_limit";
608
-        $sql .= ", retained_warranty_fk_cond_reglement";
603
+		$sql .= ", fk_multicurrency";
604
+		$sql .= ", multicurrency_code";
605
+		$sql .= ", multicurrency_tx";
606
+		$sql .= ", retained_warranty";
607
+		$sql .= ", retained_warranty_date_limit";
608
+		$sql .= ", retained_warranty_fk_cond_reglement";
609 609
 		$sql .= ")";
610 610
 		$sql .= " VALUES (";
611 611
 		$sql .= "'(PROV)'";
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
 		$sql .= ", ".($this->situation_counter ? "'".$this->db->escape($this->situation_counter)."'" : "null");
637 637
 		$sql .= ", ".($this->situation_final ? $this->situation_final : 0);
638 638
 		$sql .= ", ".(int) $this->fk_incoterms;
639
-        $sql .= ", '".$this->db->escape($this->location_incoterms)."'";
639
+		$sql .= ", '".$this->db->escape($this->location_incoterms)."'";
640 640
 		$sql .= ", ".(int) $this->fk_multicurrency;
641 641
 		$sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
642 642
 		$sql .= ", ".(double) $this->multicurrency_tx;
@@ -667,27 +667,27 @@  discard block
 block discarded – undo
667 667
 			{
668 668
 				foreach ($this->linked_objects as $origin => $tmp_origin_id)
669 669
 				{
670
-				    if (is_array($tmp_origin_id))       // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
671
-				    {
672
-				        foreach ($tmp_origin_id as $origin_id)
673
-				        {
674
-				            $ret = $this->add_object_linked($origin, $origin_id);
675
-				            if (!$ret)
676
-				            {
677
-				                $this->error = $this->db->lasterror();
678
-				                $error++;
679
-				            }
680
-				        }
681
-				    } else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1))
682
-				    {
683
-				        $origin_id = $tmp_origin_id;
684
-    					$ret = $this->add_object_linked($origin, $origin_id);
685
-    					if (!$ret)
686
-    					{
687
-    						$this->error = $this->db->lasterror();
688
-    						$error++;
689
-    					}
690
-				    }
670
+					if (is_array($tmp_origin_id))       // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
671
+					{
672
+						foreach ($tmp_origin_id as $origin_id)
673
+						{
674
+							$ret = $this->add_object_linked($origin, $origin_id);
675
+							if (!$ret)
676
+							{
677
+								$this->error = $this->db->lasterror();
678
+								$error++;
679
+							}
680
+						}
681
+					} else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1))
682
+					{
683
+						$origin_id = $tmp_origin_id;
684
+						$ret = $this->add_object_linked($origin, $origin_id);
685
+						if (!$ret)
686
+						{
687
+							$this->error = $this->db->lasterror();
688
+							$error++;
689
+						}
690
+					}
691 691
 				}
692 692
 			}
693 693
 
@@ -698,20 +698,20 @@  discard block
 block discarded – undo
698 698
 				$originidforcontact = $this->origin_id;
699 699
 				if ($originforcontact == 'shipping')     // shipment and order share the same contacts. If creating from shipment we take data of order
700 700
 				{
701
-				    require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
702
-				    $exp = new Expedition($this->db);
703
-				    $exp->fetch($this->origin_id);
704
-				    $exp->fetchObjectLinked(null, '', null, '', 'OR', 1, 'sourcetype', 0);
705
-				    if (count($exp->linkedObjectsIds['commande']) > 0)
706
-				    {
707
-				        foreach ($exp->linkedObjectsIds['commande'] as $key => $value)
708
-				        {
709
-				            $originforcontact = 'commande';
710
-				            if (is_object($value)) $originidforcontact = $value->id;
711
-				            else $originidforcontact = $value;
712
-				            break; // We take first one
713
-				        }
714
-				    }
701
+					require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
702
+					$exp = new Expedition($this->db);
703
+					$exp->fetch($this->origin_id);
704
+					$exp->fetchObjectLinked(null, '', null, '', 'OR', 1, 'sourcetype', 0);
705
+					if (count($exp->linkedObjectsIds['commande']) > 0)
706
+					{
707
+						foreach ($exp->linkedObjectsIds['commande'] as $key => $value)
708
+						{
709
+							$originforcontact = 'commande';
710
+							if (is_object($value)) $originidforcontact = $value->id;
711
+							else $originidforcontact = $value;
712
+							break; // We take first one
713
+						}
714
+					}
715 715
 				}
716 716
 
717 717
 				$sqlcontact = "SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc";
@@ -720,11 +720,11 @@  discard block
 block discarded – undo
720 720
 				$resqlcontact = $this->db->query($sqlcontact);
721 721
 				if ($resqlcontact)
722 722
 				{
723
-				    while ($objcontact = $this->db->fetch_object($resqlcontact))
724
-				    {
725
-				        //print $objcontact->code.'-'.$objcontact->source.'-'.$objcontact->fk_socpeople."\n";
726
-				        $this->add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source); // May failed because of duplicate key or because code of contact type does not exists for new object
727
-				    }
723
+					while ($objcontact = $this->db->fetch_object($resqlcontact))
724
+					{
725
+						//print $objcontact->code.'-'.$objcontact->source.'-'.$objcontact->fk_socpeople."\n";
726
+						$this->add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source); // May failed because of duplicate key or because code of contact type does not exists for new object
727
+					}
728 728
 				} else dol_print_error($resqlcontact);
729 729
 			}
730 730
 
@@ -764,12 +764,12 @@  discard block
 block discarded – undo
764 764
 						$newinvoiceline->fk_parent_line = $fk_parent_line;
765 765
 
766 766
 						if ($this->type === Facture::TYPE_REPLACEMENT && $newinvoiceline->fk_remise_except) {
767
-                            $discount = new DiscountAbsolute($this->db);
768
-                            $discount->fetch($newinvoiceline->fk_remise_except);
767
+							$discount = new DiscountAbsolute($this->db);
768
+							$discount->fetch($newinvoiceline->fk_remise_except);
769 769
 
770
-						    $discountId = $soc->set_remise_except($discount->amount_ht, $user, $discount->description, $discount->tva_tx);
771
-						    $newinvoiceline->fk_remise_except = $discountId;
772
-                        }
770
+							$discountId = $soc->set_remise_except($discount->amount_ht, $user, $discount->description, $discount->tva_tx);
771
+							$newinvoiceline->fk_remise_except = $discountId;
772
+						}
773 773
 
774 774
 						$result = $newinvoiceline->insert();
775 775
 
@@ -793,13 +793,13 @@  discard block
 block discarded – undo
793 793
 
794 794
 				foreach ($this->lines as $i => $val)
795 795
 				{
796
-                	$line = $this->lines[$i];
796
+					$line = $this->lines[$i];
797 797
 
798
-                	// Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array
799
-				    //if (! is_object($line)) $line=json_decode(json_encode($line), false);  // convert recursively array into object.
800
-                	if (!is_object($line)) $line = (object) $line;
798
+					// Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array
799
+					//if (! is_object($line)) $line=json_decode(json_encode($line), false);  // convert recursively array into object.
800
+					if (!is_object($line)) $line = (object) $line;
801 801
 
802
-				    if ($result >= 0)
802
+					if ($result >= 0)
803 803
 					{
804 804
 						// Reset fk_parent_line for no child products and special product
805 805
 						if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 							$origintype = $this->element;
819 819
 						}
820 820
 
821
-                        $result = $this->addline(
821
+						$result = $this->addline(
822 822
 							$line->desc,
823 823
 							$line->subprice,
824 824
 							$line->qty,
@@ -837,8 +837,8 @@  discard block
 block discarded – undo
837 837
 							$line->product_type,
838 838
 							$line->rang,
839 839
 							$line->special_code,
840
-	                        $origintype,
841
-	                        $originid,
840
+							$origintype,
841
+							$originid,
842 842
 							$fk_parent_line,
843 843
 							$line->fk_fournprice,
844 844
 							$line->pa_ht,
@@ -896,26 +896,26 @@  discard block
 block discarded – undo
896 896
 					$buyprice = empty($_facrec->lines[$i]->buyprice) ? 0 : $_facrec->lines[$i]->buyprice;
897 897
 					// If buyprice not defined from template invoice, we try to guess the best value
898 898
 					if (!$buyprice && $_facrec->lines[$i]->fk_product > 0)
899
-                    {
900
-                        require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
901
-                        $producttmp = new ProductFournisseur($this->db);
902
-                        $producttmp->fetch($_facrec->lines[$i]->fk_product);
903
-
904
-                        // If margin module defined on costprice, we try the costprice
905
-                        // If not defined or if module margin defined and pmp and stock module enabled, we try pmp price
906
-                        // else we get the best supplier price
907
-                        if ($conf->global->MARGIN_TYPE == 'costprice' && !empty($producttmp->cost_price)) $buyprice = $producttmp->cost_price;
908
-                        elseif (!empty($conf->stock->enabled) && ($conf->global->MARGIN_TYPE == 'costprice' || $conf->global->MARGIN_TYPE == 'pmp') && !empty($producttmp->pmp)) $buyprice = $producttmp->pmp;
909
-                        else {
910
-                            if ($producttmp->find_min_price_product_fournisseur($_facrec->lines[$i]->fk_product) > 0)
911
-                            {
912
-                                if ($producttmp->product_fourn_price_id > 0)
913
-                                {
914
-                                    $buyprice = price2num($producttmp->fourn_unitprice * (1 - $producttmp->fourn_remise_percent / 100) + $producttmp->fourn_remise, 'MU');
915
-                                }
916
-                            }
917
-                        }
918
-                    }
899
+					{
900
+						require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
901
+						$producttmp = new ProductFournisseur($this->db);
902
+						$producttmp->fetch($_facrec->lines[$i]->fk_product);
903
+
904
+						// If margin module defined on costprice, we try the costprice
905
+						// If not defined or if module margin defined and pmp and stock module enabled, we try pmp price
906
+						// else we get the best supplier price
907
+						if ($conf->global->MARGIN_TYPE == 'costprice' && !empty($producttmp->cost_price)) $buyprice = $producttmp->cost_price;
908
+						elseif (!empty($conf->stock->enabled) && ($conf->global->MARGIN_TYPE == 'costprice' || $conf->global->MARGIN_TYPE == 'pmp') && !empty($producttmp->pmp)) $buyprice = $producttmp->pmp;
909
+						else {
910
+							if ($producttmp->find_min_price_product_fournisseur($_facrec->lines[$i]->fk_product) > 0)
911
+							{
912
+								if ($producttmp->product_fourn_price_id > 0)
913
+								{
914
+									$buyprice = price2num($producttmp->fourn_unitprice * (1 - $producttmp->fourn_remise_percent / 100) + $producttmp->fourn_remise, 'MU');
915
+								}
916
+							}
917
+						}
918
+					}
919 919
 
920 920
 					$result_insert = $this->addline(
921 921
 						$_facrec->lines[$i]->desc,
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
 						'',
940 940
 						0,
941 941
 						0,
942
-					    $fk_product_fournisseur_price,
942
+						$fk_product_fournisseur_price,
943 943
 						$buyprice,
944 944
 						$_facrec->lines[$i]->label,
945 945
 						empty($_facrec->lines[$i]->array_options) ?null:$_facrec->lines[$i]->array_options,
@@ -968,17 +968,17 @@  discard block
 block discarded – undo
968 968
 					// Actions on extra fields
969 969
 					if (!$error)
970 970
 					{
971
-					    $result = $this->insertExtraFields();
972
-					    if ($result < 0) $error++;
971
+						$result = $this->insertExtraFields();
972
+						if ($result < 0) $error++;
973 973
 					}
974 974
 
975
-			        if (!$error && !$notrigger)
976
-			        {
977
-			            // Call trigger
978
-			            $result = $this->call_trigger('BILL_CREATE', $user);
979
-			            if ($result < 0) $error++;
980
-			            // End call triggers
981
-			        }
975
+					if (!$error && !$notrigger)
976
+					{
977
+						// Call trigger
978
+						$result = $this->call_trigger('BILL_CREATE', $user);
979
+						if ($result < 0) $error++;
980
+						// End call triggers
981
+					}
982 982
 
983 983
 					if (!$error)
984 984
 					{
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
 	 *	@param		int		$invertdetail	Reverse sign of amounts for lines
1014 1014
 	 *	@return		int						<0 if KO, >0 if OK
1015 1015
 	 */
1016
-    public function createFromCurrent(User $user, $invertdetail = 0)
1016
+	public function createFromCurrent(User $user, $invertdetail = 0)
1017 1017
 	{
1018 1018
 		global $conf;
1019 1019
 
@@ -1024,13 +1024,13 @@  discard block
 block discarded – undo
1024 1024
 		// fetch optionals attributes and labels
1025 1025
 		$this->fetch_optionals();
1026 1026
 
1027
-        if (!empty($this->array_options)) {
1028
-                    $facture->array_options = $this->array_options;
1029
-        }
1027
+		if (!empty($this->array_options)) {
1028
+					$facture->array_options = $this->array_options;
1029
+		}
1030 1030
 
1031
-        foreach ($this->lines as &$line) {
1032
-                    $line->fetch_optionals(); //fetch extrafields
1033
-        }
1031
+		foreach ($this->lines as &$line) {
1032
+					$line->fetch_optionals(); //fetch extrafields
1033
+		}
1034 1034
 
1035 1035
 		$facture->fk_facture_source = $this->fk_facture_source;
1036 1036
 		$facture->type 			    = $this->type;
@@ -1056,9 +1056,9 @@  discard block
 block discarded – undo
1056 1056
 		$facture->situation_cycle_ref = $this->situation_cycle_ref;
1057 1057
 		$facture->situation_final = $this->situation_final;
1058 1058
 
1059
-        $facture->retained_warranty = $this->retained_warranty;
1060
-        $facture->retained_warranty_fk_cond_reglement = $this->retained_warranty_fk_cond_reglement;
1061
-        $facture->retained_warranty_date_limit = $this->retained_warranty_date_limit;
1059
+		$facture->retained_warranty = $this->retained_warranty;
1060
+		$facture->retained_warranty_fk_cond_reglement = $this->retained_warranty_fk_cond_reglement;
1061
+		$facture->retained_warranty_date_limit = $this->retained_warranty_date_limit;
1062 1062
 
1063 1063
 
1064 1064
 		// Loop on each line of new invoice
@@ -1105,7 +1105,7 @@  discard block
 block discarded – undo
1105 1105
 	/**
1106 1106
 	 *	Load an object from its id and create a new one in database
1107 1107
 	 *
1108
-     *	@param      User	$user        	User that clone
1108
+	 *	@param      User	$user        	User that clone
1109 1109
 	 *  @param  	int 	$fromid         Id of object to clone
1110 1110
 	 * 	@return		int					    New id of clone
1111 1111
 	 */
@@ -1128,11 +1128,11 @@  discard block
 block discarded – undo
1128 1128
 
1129 1129
 			if ($objsoc->fetch($this->socid) > 0)
1130 1130
 			{
1131
-			    $object->socid = $objsoc->id;
1132
-			    $object->cond_reglement_id	= (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1133
-			    $object->mode_reglement_id	= (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1134
-			    $object->fk_project = '';
1135
-			    $object->fk_delivery_address = '';
1131
+				$object->socid = $objsoc->id;
1132
+				$object->cond_reglement_id	= (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1133
+				$object->mode_reglement_id	= (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1134
+				$object->fk_project = '';
1135
+				$object->fk_delivery_address = '';
1136 1136
 			}
1137 1137
 
1138 1138
 			// TODO Change product price if multi-prices
@@ -1161,10 +1161,10 @@  discard block
 block discarded – undo
1161 1161
 		// Loop on each line of new invoice
1162 1162
 		foreach ($object->lines as $i => $line)
1163 1163
 		{
1164
-		    if (($object->lines[$i]->info_bits & 0x02) == 0x02)	// We do not clone line of discounts
1164
+			if (($object->lines[$i]->info_bits & 0x02) == 0x02)	// We do not clone line of discounts
1165 1165
 			{
1166
-			    unset($object->lines[$i]);
1167
-			    unset($object->products[$i]); // Tant que products encore utilise
1166
+				unset($object->lines[$i]);
1167
+				unset($object->products[$i]); // Tant que products encore utilise
1168 1168
 			}
1169 1169
 						// Bloc to update dates of service (month by month only if previously filled at 1d near start or end of month)
1170 1170
 			// If it's a service with start and end dates
@@ -1198,13 +1198,13 @@  discard block
 block discarded – undo
1198 1198
 		if ($result < 0) $error++;
1199 1199
 		else {
1200 1200
 			// copy internal contacts
1201
-		    if ($object->copy_linked_contact($this, 'internal') < 0)
1201
+			if ($object->copy_linked_contact($this, 'internal') < 0)
1202 1202
 				$error++;
1203 1203
 
1204 1204
 			// copy external contacts if same company
1205 1205
 			elseif ($this->socid == $object->socid)
1206 1206
 			{
1207
-			    if ($object->copy_linked_contact($this, 'external') < 0)
1207
+				if ($object->copy_linked_contact($this, 'external') < 0)
1208 1208
 					$error++;
1209 1209
 			}
1210 1210
 		}
@@ -1241,7 +1241,7 @@  discard block
 block discarded – undo
1241 1241
 	 *  @param		User			$user				Object user
1242 1242
 	 *  @return     int             					<0 if KO, 0 if nothing done, 1 if OK
1243 1243
 	 */
1244
-    public function createFromOrder($object, User $user)
1244
+	public function createFromOrder($object, User $user)
1245 1245
 	{
1246 1246
 		global $conf, $hookmanager;
1247 1247
 
@@ -1294,7 +1294,7 @@  discard block
 block discarded – undo
1294 1294
 			$marginInfos			= getMarginInfos($object->lines[$i]->subprice, $object->lines[$i]->remise_percent, $object->lines[$i]->tva_tx, $object->lines[$i]->localtax1_tx, $object->lines[$i]->localtax2_tx, $object->lines[$i]->fk_fournprice, $object->lines[$i]->pa_ht);
1295 1295
 			$line->pa_ht			= $marginInfos[0];
1296 1296
 
1297
-            // get extrafields from original line
1297
+			// get extrafields from original line
1298 1298
 			$object->lines[$i]->fetch_optionals();
1299 1299
 			foreach ($object->lines[$i]->array_options as $options_key => $value)
1300 1300
 				$line->array_options[$options_key] = $value;
@@ -1316,17 +1316,17 @@  discard block
 block discarded – undo
1316 1316
 
1317 1317
 		if (empty($conf->global->MAIN_DISABLE_PROPAGATE_NOTES_FROM_ORIGIN))
1318 1318
 		{
1319
-		    $this->note_private = $object->note_private;
1320
-            $this->note_public = $object->note_public;
1319
+			$this->note_private = $object->note_private;
1320
+			$this->note_public = $object->note_public;
1321 1321
 		}
1322 1322
 
1323
-        $this->module_source = $object->module_source;
1323
+		$this->module_source = $object->module_source;
1324 1324
 		$this->pos_source = $object->pos_source;
1325 1325
 
1326 1326
 		$this->origin = $object->element;
1327 1327
 		$this->origin_id = $object->id;
1328 1328
 
1329
-        // get extrafields from original line
1329
+		// get extrafields from original line
1330 1330
 		$object->fetch_optionals();
1331 1331
 		foreach ($object->array_options as $options_key => $value)
1332 1332
 			$this->array_options[$options_key] = $value;
@@ -1365,13 +1365,13 @@  discard block
 block discarded – undo
1365 1365
 	 *  @param  int		$max             			Maxlength of ref
1366 1366
 	 *  @param  int		$short           			1=Return just URL
1367 1367
 	 *  @param  string  $moretitle       			Add more text to title tooltip
1368
-     *  @param	int  	$notooltip		 			1=Disable tooltip
1369
-     *  @param  int     $addlinktonotes  			1=Add link to notes
1370
-     *  @param  int     $save_lastsearch_value		-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
1371
-     *  @param  string  $target                     Target of link ('', '_self', '_blank', '_parent', '_backoffice', ...)
1368
+	 *  @param	int  	$notooltip		 			1=Disable tooltip
1369
+	 *  @param  int     $addlinktonotes  			1=Add link to notes
1370
+	 *  @param  int     $save_lastsearch_value		-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
1371
+	 *  @param  string  $target                     Target of link ('', '_self', '_blank', '_parent', '_backoffice', ...)
1372 1372
 	 *  @return string 			         			String with URL
1373 1373
 	 */
1374
-    public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '', $notooltip = 0, $addlinktonotes = 0, $save_lastsearch_value = -1, $target = '')
1374
+	public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '', $notooltip = 0, $addlinktonotes = 0, $save_lastsearch_value = -1, $target = '')
1375 1375
 	{
1376 1376
 		global $langs, $conf, $user, $mysoc;
1377 1377
 
@@ -1382,8 +1382,8 @@  discard block
 block discarded – undo
1382 1382
 		if ($option == 'withdraw') $url = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$this->id;
1383 1383
 		else $url = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$this->id;
1384 1384
 
1385
-        if (!$user->rights->facture->lire)
1386
-            $option = 'nolink';
1385
+		if (!$user->rights->facture->lire)
1386
+			$option = 'nolink';
1387 1387
 
1388 1388
 		if ($option !== 'nolink')
1389 1389
 		{
@@ -1399,56 +1399,56 @@  discard block
 block discarded – undo
1399 1399
 		if ($this->type == self::TYPE_REPLACEMENT) $picto .= 'r'; // Replacement invoice
1400 1400
 		if ($this->type == self::TYPE_CREDIT_NOTE) $picto .= 'a'; // Credit note
1401 1401
 		if ($this->type == self::TYPE_DEPOSIT) $picto .= 'd'; // Deposit invoice
1402
-        $label = '';
1403
-
1404
-        if ($user->rights->facture->lire) {
1405
-            $label = '<u>'.$langs->trans("Invoice").'</u>';
1406
-            if ($this->type == self::TYPE_REPLACEMENT) $label = '<u>'.$langs->transnoentitiesnoconv("ReplacementInvoice").'</u>';
1407
-            if ($this->type == self::TYPE_CREDIT_NOTE) $label = '<u>'.$langs->transnoentitiesnoconv("CreditNote").'</u>';
1408
-            if ($this->type == self::TYPE_DEPOSIT)     $label = '<u>'.$langs->transnoentitiesnoconv("Deposit").'</u>';
1409
-            if ($this->type == self::TYPE_SITUATION)   $label = '<u>'.$langs->transnoentitiesnoconv("InvoiceSituation").'</u>';
1410
-            if (!empty($this->ref))
1411
-                $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1412
-            if (!empty($this->ref_client))
1413
-                $label .= '<br><b>'.$langs->trans('RefCustomer').':</b> '.$this->ref_client;
1414
-            if (!empty($this->date))
1415
-              	$label .= '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->date, 'day');
1416
-            if (!empty($this->total_ht))
1417
-                $label .= '<br><b>'.$langs->trans('AmountHT').':</b> '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
1418
-            if (!empty($this->total_tva))
1419
-                $label .= '<br><b>'.$langs->trans('AmountVAT').':</b> '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
1420
-            if (!empty($this->total_localtax1) && $this->total_localtax1 != 0)		// We keep test != 0 because $this->total_localtax1 can be '0.00000000'
1421
-            	$label .= '<br><b>'.$langs->transcountry('AmountLT1', $mysoc->country_code).':</b> '.price($this->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency);
1422
-            if (!empty($this->total_localtax2) && $this->total_localtax2 != 0)
1423
-            	$label .= '<br><b>'.$langs->transcountry('AmountLT2', $mysoc->country_code).':</b> '.price($this->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency);
1424
-            if (!empty($this->total_ttc))
1425
-                $label .= '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
1426
-    		if ($moretitle) $label .= ' - '.$moretitle;
1427
-    		if (isset($this->statut) && isset($this->alreadypaid)) {
1428
-    			$label .= '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5, $this->alreadypaid);
1429
-    		}
1430
-        }
1402
+		$label = '';
1403
+
1404
+		if ($user->rights->facture->lire) {
1405
+			$label = '<u>'.$langs->trans("Invoice").'</u>';
1406
+			if ($this->type == self::TYPE_REPLACEMENT) $label = '<u>'.$langs->transnoentitiesnoconv("ReplacementInvoice").'</u>';
1407
+			if ($this->type == self::TYPE_CREDIT_NOTE) $label = '<u>'.$langs->transnoentitiesnoconv("CreditNote").'</u>';
1408
+			if ($this->type == self::TYPE_DEPOSIT)     $label = '<u>'.$langs->transnoentitiesnoconv("Deposit").'</u>';
1409
+			if ($this->type == self::TYPE_SITUATION)   $label = '<u>'.$langs->transnoentitiesnoconv("InvoiceSituation").'</u>';
1410
+			if (!empty($this->ref))
1411
+				$label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1412
+			if (!empty($this->ref_client))
1413
+				$label .= '<br><b>'.$langs->trans('RefCustomer').':</b> '.$this->ref_client;
1414
+			if (!empty($this->date))
1415
+			  	$label .= '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->date, 'day');
1416
+			if (!empty($this->total_ht))
1417
+				$label .= '<br><b>'.$langs->trans('AmountHT').':</b> '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
1418
+			if (!empty($this->total_tva))
1419
+				$label .= '<br><b>'.$langs->trans('AmountVAT').':</b> '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
1420
+			if (!empty($this->total_localtax1) && $this->total_localtax1 != 0)		// We keep test != 0 because $this->total_localtax1 can be '0.00000000'
1421
+				$label .= '<br><b>'.$langs->transcountry('AmountLT1', $mysoc->country_code).':</b> '.price($this->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency);
1422
+			if (!empty($this->total_localtax2) && $this->total_localtax2 != 0)
1423
+				$label .= '<br><b>'.$langs->transcountry('AmountLT2', $mysoc->country_code).':</b> '.price($this->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency);
1424
+			if (!empty($this->total_ttc))
1425
+				$label .= '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
1426
+			if ($moretitle) $label .= ' - '.$moretitle;
1427
+			if (isset($this->statut) && isset($this->alreadypaid)) {
1428
+				$label .= '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5, $this->alreadypaid);
1429
+			}
1430
+		}
1431 1431
 
1432 1432
 		$linkclose = ($target ? ' target="'.$target.'"' : '');
1433 1433
 		if (empty($notooltip) && $user->rights->facture->lire)
1434 1434
 		{
1435
-		    if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1436
-		    {
1437
-		        $label = $langs->trans("Invoice");
1438
-		        $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1439
-		    }
1440
-		    $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1441
-		    $linkclose .= ' class="classfortooltip"';
1435
+			if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1436
+			{
1437
+				$label = $langs->trans("Invoice");
1438
+				$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1439
+			}
1440
+			$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1441
+			$linkclose .= ' class="classfortooltip"';
1442 1442
 		}
1443 1443
 
1444
-        $linkstart = '<a href="'.$url.'"';
1445
-        $linkstart .= $linkclose.'>';
1444
+		$linkstart = '<a href="'.$url.'"';
1445
+		$linkstart .= $linkclose.'>';
1446 1446
 		$linkend = '</a>';
1447 1447
 
1448
-        if ($option == 'nolink') {
1449
-            $linkstart = '';
1450
-            $linkend = '';
1451
-        }
1448
+		if ($option == 'nolink') {
1449
+			$linkstart = '';
1450
+			$linkend = '';
1451
+		}
1452 1452
 
1453 1453
 		$result .= $linkstart;
1454 1454
 		if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
@@ -1457,19 +1457,19 @@  discard block
 block discarded – undo
1457 1457
 
1458 1458
 		if ($addlinktonotes)
1459 1459
 		{
1460
-		    $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
1461
-		    if ($txttoshow)
1462
-		    {
1463
-                //$notetoshow = $langs->trans("ViewPrivateNote").':<br>'.dol_string_nohtmltag($txttoshow, 1);
1464
-		    	$notetoshow = $langs->trans("ViewPrivateNote").':<br>'.$txttoshow;
1465
-    		    $result .= ' <span class="note inline-block">';
1466
-    		    $result .= '<a href="'.DOL_URL_ROOT.'/compta/facture/note.php?id='.$this->id.'" class="classfortooltip" title="'.dol_escape_htmltag($notetoshow, 1, 1).'">';
1467
-    		    $result .= img_picto('', 'note');
1468
-    		    $result .= '</a>';
1469
-    		    //$result.=img_picto($langs->trans("ViewNote"),'object_generic');
1470
-    		    //$result.='</a>';
1471
-    		    $result .= '</span>';
1472
-		    }
1460
+			$txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
1461
+			if ($txttoshow)
1462
+			{
1463
+				//$notetoshow = $langs->trans("ViewPrivateNote").':<br>'.dol_string_nohtmltag($txttoshow, 1);
1464
+				$notetoshow = $langs->trans("ViewPrivateNote").':<br>'.$txttoshow;
1465
+				$result .= ' <span class="note inline-block">';
1466
+				$result .= '<a href="'.DOL_URL_ROOT.'/compta/facture/note.php?id='.$this->id.'" class="classfortooltip" title="'.dol_escape_htmltag($notetoshow, 1, 1).'">';
1467
+				$result .= img_picto('', 'note');
1468
+				$result .= '</a>';
1469
+				//$result.=img_picto($langs->trans("ViewNote"),'object_generic');
1470
+				//$result.='</a>';
1471
+				$result .= '</span>';
1472
+			}
1473 1473
 		}
1474 1474
 
1475 1475
 		return $result;
@@ -1507,10 +1507,10 @@  discard block
 block discarded – undo
1507 1507
 		$sql .= ", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
1508 1508
 		$sql .= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
1509 1509
 		$sql .= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
1510
-        $sql .= ', f.fk_incoterms, f.location_incoterms';
1511
-        $sql .= ', f.module_source, f.pos_source';
1512
-        $sql .= ", i.libelle as label_incoterms";
1513
-        $sql .= ", f.retained_warranty as retained_warranty, f.retained_warranty_date_limit as retained_warranty_date_limit, f.retained_warranty_fk_cond_reglement as retained_warranty_fk_cond_reglement";
1510
+		$sql .= ', f.fk_incoterms, f.location_incoterms';
1511
+		$sql .= ', f.module_source, f.pos_source';
1512
+		$sql .= ", i.libelle as label_incoterms";
1513
+		$sql .= ", f.retained_warranty as retained_warranty, f.retained_warranty_date_limit as retained_warranty_date_limit, f.retained_warranty_fk_cond_reglement as retained_warranty_fk_cond_reglement";
1514 1514
 		$sql .= ' FROM '.MAIN_DB_PREFIX.'facture as f';
1515 1515
 		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
1516 1516
 		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id';
@@ -1641,7 +1641,7 @@  discard block
 block discarded – undo
1641 1641
 	}
1642 1642
 
1643 1643
 
1644
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1644
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1645 1645
 	/**
1646 1646
 	 *	Load all detailed lines into this->lines
1647 1647
 	 *
@@ -1653,7 +1653,7 @@  discard block
 block discarded – undo
1653 1653
 	public function fetch_lines($only_product = 0, $loadalsotranslation = 0)
1654 1654
 	{
1655 1655
 		global $langs, $conf;
1656
-        // phpcs:enable
1656
+		// phpcs:enable
1657 1657
 		$this->lines = array();
1658 1658
 
1659 1659
 		$sql = 'SELECT l.rowid, l.fk_facture, l.fk_product, l.fk_parent_line, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx,';
@@ -1697,7 +1697,7 @@  discard block
 block discarded – undo
1697 1697
 				$line->qty              = $objp->qty;
1698 1698
 				$line->subprice         = $objp->subprice;
1699 1699
 
1700
-                $line->vat_src_code = $objp->vat_src_code;
1700
+				$line->vat_src_code = $objp->vat_src_code;
1701 1701
 				$line->tva_tx           = $objp->tva_tx;
1702 1702
 				$line->localtax1_tx     = $objp->localtax1_tx;
1703 1703
 				$line->localtax2_tx     = $objp->localtax2_tx;
@@ -1740,14 +1740,14 @@  discard block
 block discarded – undo
1740 1740
 				$line->multicurrency_total_tva 	= $objp->multicurrency_total_tva;
1741 1741
 				$line->multicurrency_total_ttc 	= $objp->multicurrency_total_ttc;
1742 1742
 
1743
-                $line->fetch_optionals();
1743
+				$line->fetch_optionals();
1744 1744
 
1745 1745
 				// multilangs
1746
-        		if (!empty($conf->global->MAIN_MULTILANGS) && !empty($objp->fk_product) && !empty($loadalsotranslation)) {
1747
-        		    $line = new Product($this->db);
1748
-        		    $line->fetch($objp->fk_product);
1749
-        		    $line->getMultiLangs();
1750
-        		}
1746
+				if (!empty($conf->global->MAIN_MULTILANGS) && !empty($objp->fk_product) && !empty($loadalsotranslation)) {
1747
+					$line = new Product($this->db);
1748
+					$line->fetch($objp->fk_product);
1749
+					$line->getMultiLangs();
1750
+				}
1751 1751
 
1752 1752
 				$this->lines[$i] = $line;
1753 1753
 
@@ -1767,7 +1767,7 @@  discard block
 block discarded – undo
1767 1767
 	 *
1768 1768
 	 * @return	void
1769 1769
 	 */
1770
-    public function fetchPreviousNextSituationInvoice()
1770
+	public function fetchPreviousNextSituationInvoice()
1771 1771
 	{
1772 1772
 		global $conf;
1773 1773
 
@@ -1789,13 +1789,13 @@  discard block
 block discarded – undo
1789 1789
 				$invoice = new Facture($this->db);
1790 1790
 				if ($invoice->fetch($objp->rowid) > 0)
1791 1791
 				{
1792
-				    if ($objp->situation_counter < $this->situation_counter
1793
-				        || ($objp->situation_counter == $this->situation_counter && $objp->rowid < $this->id) // This case appear when there are credit notes
1794
-				       )
1792
+					if ($objp->situation_counter < $this->situation_counter
1793
+						|| ($objp->situation_counter == $this->situation_counter && $objp->rowid < $this->id) // This case appear when there are credit notes
1794
+					   )
1795 1795
 					{
1796
-					    $this->tab_previous_situation_invoice[] = $invoice;
1796
+						$this->tab_previous_situation_invoice[] = $invoice;
1797 1797
 					} else {
1798
-					    $this->tab_next_situation_invoice[] = $invoice;
1798
+						$this->tab_next_situation_invoice[] = $invoice;
1799 1799
 					}
1800 1800
 				}
1801 1801
 			}
@@ -1809,7 +1809,7 @@  discard block
 block discarded – undo
1809 1809
 	 *      @param      int		$notrigger	    0=launch triggers after, 1=disable triggers
1810 1810
 	 *      @return     int      			   	<0 if KO, >0 if OK
1811 1811
 	 */
1812
-    public function update(User $user, $notrigger = 0)
1812
+	public function update(User $user, $notrigger = 0)
1813 1813
 	{
1814 1814
 		global $conf;
1815 1815
 
@@ -1917,16 +1917,16 @@  discard block
 block discarded – undo
1917 1917
 	}
1918 1918
 
1919 1919
 
1920
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1920
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1921 1921
 	/**
1922 1922
 	 *    Add a discount line into an invoice (as an invoice line) using an existing absolute discount (Consume the discount)
1923 1923
 	 *
1924 1924
 	 *    @param     int	$idremise	Id of absolute discount
1925 1925
 	 *    @return    int          		>0 if OK, <0 if KO
1926 1926
 	 */
1927
-    public function insert_discount($idremise)
1927
+	public function insert_discount($idremise)
1928 1928
 	{
1929
-        // phpcs:enable
1929
+		// phpcs:enable
1930 1930
 		global $langs;
1931 1931
 
1932 1932
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
@@ -1962,12 +1962,12 @@  discard block
 block discarded – undo
1962 1962
 			// Get buy/cost price of invoice that is source of discount
1963 1963
 			if ($remise->fk_facture_source > 0)
1964 1964
 			{
1965
-    			$srcinvoice = new Facture($this->db);
1966
-    			$srcinvoice->fetch($remise->fk_facture_source);
1967
-    			include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php'; // TODO Move this into commonobject
1968
-    			$formmargin = new FormMargin($this->db);
1969
-    			$arraytmp = $formmargin->getMarginInfosArray($srcinvoice, false);
1970
-        		$facligne->pa_ht = $arraytmp['pa_total'];
1965
+				$srcinvoice = new Facture($this->db);
1966
+				$srcinvoice->fetch($remise->fk_facture_source);
1967
+				include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php'; // TODO Move this into commonobject
1968
+				$formmargin = new FormMargin($this->db);
1969
+				$arraytmp = $formmargin->getMarginInfosArray($srcinvoice, false);
1970
+				$facligne->pa_ht = $arraytmp['pa_total'];
1971 1971
 			}
1972 1972
 
1973 1973
 			$facligne->total_ht  = -$remise->amount_ht;
@@ -2012,7 +2012,7 @@  discard block
 block discarded – undo
2012 2012
 		}
2013 2013
 	}
2014 2014
 
2015
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2015
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2016 2016
 	/**
2017 2017
 	 *	Set customer ref
2018 2018
 	 *
@@ -2020,10 +2020,10 @@  discard block
 block discarded – undo
2020 2020
 	 *  @param     	int		$notrigger		1=Does not execute triggers, 0= execute triggers
2021 2021
 	 *	@return		int						<0 if KO, >0 if OK
2022 2022
 	 */
2023
-    public function set_ref_client($ref_client, $notrigger = 0)
2023
+	public function set_ref_client($ref_client, $notrigger = 0)
2024 2024
 	{
2025
-        // phpcs:enable
2026
-	    global $user;
2025
+		// phpcs:enable
2026
+		global $user;
2027 2027
 
2028 2028
 		$error = 0;
2029 2029
 
@@ -2081,7 +2081,7 @@  discard block
 block discarded – undo
2081 2081
 	 *	@param		int		$idwarehouse	Id warehouse to use for stock change.
2082 2082
 	 *	@return		int						<0 if KO, 0=Refused, >0 if OK
2083 2083
 	 */
2084
-    public function delete($user, $notrigger = 0, $idwarehouse = -1)
2084
+	public function delete($user, $notrigger = 0, $idwarehouse = -1)
2085 2085
 	{
2086 2086
 		global $langs, $conf;
2087 2087
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@@ -2101,10 +2101,10 @@  discard block
 block discarded – undo
2101 2101
 
2102 2102
 		if (!$error && !$notrigger)
2103 2103
 		{
2104
-            // Call trigger
2105
-            $result = $this->call_trigger('BILL_DELETE', $user);
2106
-            if ($result < 0) $error++;
2107
-            // End call triggers
2104
+			// Call trigger
2105
+			$result = $this->call_trigger('BILL_DELETE', $user);
2106
+			if ($result < 0) $error++;
2107
+			// End call triggers
2108 2108
 		}
2109 2109
 
2110 2110
 		// Removed extrafields
@@ -2176,7 +2176,7 @@  discard block
 block discarded – undo
2176 2176
 				}
2177 2177
 			}
2178 2178
 
2179
-            // Invoice line extrafileds
2179
+			// Invoice line extrafileds
2180 2180
 			$main = MAIN_DB_PREFIX.'facturedet';
2181 2181
 			$ef = $main."_extrafields";
2182 2182
 			$sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_facture = $rowid)";
@@ -2242,7 +2242,7 @@  discard block
 block discarded – undo
2242 2242
 		}
2243 2243
 	}
2244 2244
 
2245
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2245
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2246 2246
 	/**
2247 2247
 	 *  Tag the invoice as paid completely (if close_code is filled) => this->fk_statut=2, this->paye=1
2248 2248
 	 *  or partialy (if close_code filled) + appel trigger BILL_PAYED => this->fk_statut=2, this->paye stay 0
@@ -2252,9 +2252,9 @@  discard block
 block discarded – undo
2252 2252
 	 *	@param  string	$close_note	Commentaire renseigne si on classe a payee alors que paiement incomplet (cas escompte par exemple)
2253 2253
 	 *  @return int         		<0 if KO, >0 if OK
2254 2254
 	 */
2255
-    public function set_paid($user, $close_code = '', $close_note = '')
2255
+	public function set_paid($user, $close_code = '', $close_note = '')
2256 2256
 	{
2257
-        // phpcs:enable
2257
+		// phpcs:enable
2258 2258
 		$error = 0;
2259 2259
 
2260 2260
 		if ($this->paye != 1)
@@ -2277,10 +2277,10 @@  discard block
 block discarded – undo
2277 2277
 			$resql = $this->db->query($sql);
2278 2278
 			if ($resql)
2279 2279
 			{
2280
-	            // Call trigger
2281
-	            $result = $this->call_trigger('BILL_PAYED', $user);
2282
-	            if ($result < 0) $error++;
2283
-	            // End call triggers
2280
+				// Call trigger
2281
+				$result = $this->call_trigger('BILL_PAYED', $user);
2282
+				if ($result < 0) $error++;
2283
+				// End call triggers
2284 2284
 			} else {
2285 2285
 				$error++;
2286 2286
 				$this->error = $this->db->lasterror();
@@ -2300,7 +2300,7 @@  discard block
 block discarded – undo
2300 2300
 	}
2301 2301
 
2302 2302
 
2303
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2303
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2304 2304
 	/**
2305 2305
 	 *  Tag la facture comme non payee completement + appel trigger BILL_UNPAYED
2306 2306
 	 *	Fonction utilisee quand un paiement prelevement est refuse,
@@ -2309,9 +2309,9 @@  discard block
 block discarded – undo
2309 2309
 	 *  @param	User	$user       Object user that change status
2310 2310
 	 *  @return int         		<0 if KO, >0 if OK
2311 2311
 	 */
2312
-    public function set_unpaid($user)
2312
+	public function set_unpaid($user)
2313 2313
 	{
2314
-        // phpcs:enable
2314
+		// phpcs:enable
2315 2315
 		$error = 0;
2316 2316
 
2317 2317
 		$this->db->begin();
@@ -2326,10 +2326,10 @@  discard block
 block discarded – undo
2326 2326
 		$resql = $this->db->query($sql);
2327 2327
 		if ($resql)
2328 2328
 		{
2329
-            // Call trigger
2330
-            $result = $this->call_trigger('BILL_UNPAYED', $user);
2331
-            if ($result < 0) $error++;
2332
-            // End call triggers
2329
+			// Call trigger
2330
+			$result = $this->call_trigger('BILL_UNPAYED', $user);
2331
+			if ($result < 0) $error++;
2332
+			// End call triggers
2333 2333
 		} else {
2334 2334
 			$error++;
2335 2335
 			$this->error = $this->db->error();
@@ -2347,7 +2347,7 @@  discard block
 block discarded – undo
2347 2347
 	}
2348 2348
 
2349 2349
 
2350
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2350
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2351 2351
 	/**
2352 2352
 	 *	Tag invoice as canceled, with no payment on it (example for replacement invoice or payment never received) + call trigger BILL_CANCEL
2353 2353
 	 *	Warning, if option to decrease stock on invoice was set, this function does not change stock (it might be a cancel because
@@ -2358,9 +2358,9 @@  discard block
 block discarded – undo
2358 2358
 	 *	@param	string	$close_note		Comment
2359 2359
 	 *	@return int         			<0 if KO, >0 if OK
2360 2360
 	 */
2361
-    public function set_canceled($user, $close_code = '', $close_note = '')
2361
+	public function set_canceled($user, $close_code = '', $close_note = '')
2362 2362
 	{
2363
-        // phpcs:enable
2363
+		// phpcs:enable
2364 2364
 
2365 2365
 		dol_syslog(get_class($this)."::set_canceled rowid=".$this->id, LOG_DEBUG);
2366 2366
 
@@ -2384,14 +2384,14 @@  discard block
 block discarded – undo
2384 2384
 			$resql = $this->db->query($sql);
2385 2385
 			if ($resql)
2386 2386
 			{
2387
-	            // Call trigger
2388
-	            $result = $this->call_trigger('BILL_CANCEL', $user);
2389
-	            if ($result < 0)
2390
-	            {
2387
+				// Call trigger
2388
+				$result = $this->call_trigger('BILL_CANCEL', $user);
2389
+				if ($result < 0)
2390
+				{
2391 2391
 					$this->db->rollback();
2392 2392
 					return -1;
2393 2393
 				}
2394
-	            // End call triggers
2394
+				// End call triggers
2395 2395
 
2396 2396
 				$this->db->commit();
2397 2397
 				return 1;
@@ -2417,9 +2417,9 @@  discard block
 block discarded – undo
2417 2417
 	 * @param	int		$notrigger		1=Does not execute triggers, 0= execute triggers
2418 2418
 	 * @param	int		$batch_rule		0=do not decrement batch, else batch rule to use
2419 2419
 	 *                                 	1=take in batches ordered by sellby and eatby dates
2420
-     * @return	int						<0 if KO, 0=Nothing done because invoice is not a draft, >0 if OK
2420
+	 * @return	int						<0 if KO, 0=Nothing done because invoice is not a draft, >0 if OK
2421 2421
 	 */
2422
-    public function validate($user, $force_number = '', $idwarehouse = 0, $notrigger = 0, $batch_rule = 0)
2422
+	public function validate($user, $force_number = '', $idwarehouse = 0, $notrigger = 0, $batch_rule = 0)
2423 2423
 	{
2424 2424
 		global $conf, $langs;
2425 2425
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@@ -2450,12 +2450,12 @@  discard block
 block discarded – undo
2450 2450
 		}
2451 2451
 		if (count($this->lines) <= 0)
2452 2452
 		{
2453
-        	$langs->load("errors");
2453
+			$langs->load("errors");
2454 2454
 			$this->error = $langs->trans("ErrorObjectMustHaveLinesToBeValidated", $this->ref);
2455 2455
 			return -1;
2456 2456
 		}
2457 2457
 		if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->facture->creer))
2458
-       	|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->facture->invoice_advance->validate)))
2458
+	   	|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->facture->invoice_advance->validate)))
2459 2459
 		{
2460 2460
 			$this->error = 'Permission denied';
2461 2461
 			dol_syslog(get_class($this)."::validate ".$this->error.' MAIN_USE_ADVANCED_PERMS='.$conf->global->MAIN_USE_ADVANCED_PERMS, LOG_ERR);
@@ -2667,10 +2667,10 @@  discard block
 block discarded – undo
2667 2667
 			// Trigger calls
2668 2668
 			if (!$error && !$notrigger)
2669 2669
 			{
2670
-	            // Call trigger
2671
-	            $result = $this->call_trigger('BILL_VALIDATE', $user);
2672
-	            if ($result < 0) $error++;
2673
-	            // End call triggers
2670
+				// Call trigger
2671
+				$result = $this->call_trigger('BILL_VALIDATE', $user);
2672
+				if ($result < 0) $error++;
2673
+				// End call triggers
2674 2674
 			}
2675 2675
 
2676 2676
 			if (!$error)
@@ -2698,16 +2698,16 @@  discard block
 block discarded – undo
2698 2698
 						if (@rename($dirsource, $dirdest))
2699 2699
 						{
2700 2700
 							dol_syslog("Rename ok");
2701
-	                        // Rename docs starting with $oldref with $newref
2702
-	                        $listoffiles = dol_dir_list($conf->facture->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
2703
-	                        foreach ($listoffiles as $fileentry)
2704
-	                        {
2705
-	                        	$dirsource = $fileentry['name'];
2706
-	                        	$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
2707
-	                        	$dirsource = $fileentry['path'].'/'.$dirsource;
2708
-	                        	$dirdest = $fileentry['path'].'/'.$dirdest;
2709
-	                        	@rename($dirsource, $dirdest);
2710
-	                        }
2701
+							// Rename docs starting with $oldref with $newref
2702
+							$listoffiles = dol_dir_list($conf->facture->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
2703
+							foreach ($listoffiles as $fileentry)
2704
+							{
2705
+								$dirsource = $fileentry['name'];
2706
+								$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
2707
+								$dirsource = $fileentry['path'].'/'.$dirsource;
2708
+								$dirdest = $fileentry['path'].'/'.$dirdest;
2709
+								@rename($dirsource, $dirdest);
2710
+							}
2711 2711
 						}
2712 2712
 					}
2713 2713
 				}
@@ -2731,20 +2731,20 @@  discard block
 block discarded – undo
2731 2731
 				$this->date_validation = $now;
2732 2732
 				$i = 0;
2733 2733
 
2734
-                if (!empty($conf->global->INVOICE_USE_SITUATION))
2735
-                {
2736
-                	$final = true;
2737
-    				$nboflines = count($this->lines);
2738
-    				while (($i < $nboflines) && $final) {
2739
-    					$final = ($this->lines[$i]->situation_percent == 100);
2740
-    					$i++;
2741
-    				}
2734
+				if (!empty($conf->global->INVOICE_USE_SITUATION))
2735
+				{
2736
+					$final = true;
2737
+					$nboflines = count($this->lines);
2738
+					while (($i < $nboflines) && $final) {
2739
+						$final = ($this->lines[$i]->situation_percent == 100);
2740
+						$i++;
2741
+					}
2742 2742
 
2743
-    				if (empty($final)) $this->situation_final = 0;
2744
-    				else $this->situation_final = 1;
2743
+					if (empty($final)) $this->situation_final = 0;
2744
+					else $this->situation_final = 1;
2745 2745
 
2746
-				    $this->setFinal($user);
2747
-                }
2746
+					$this->setFinal($user);
2747
+				}
2748 2748
 			}
2749 2749
 		} else {
2750 2750
 			$error++;
@@ -2766,7 +2766,7 @@  discard block
 block discarded – undo
2766 2766
 	 * @param	Translate	$langs	Translate object
2767 2767
 	 * @return bool		false if KO, true if OK
2768 2768
 	 */
2769
-    public function updatePriceNextInvoice(&$langs)
2769
+	public function updatePriceNextInvoice(&$langs)
2770 2770
 	{
2771 2771
 		foreach ($this->tab_next_situation_invoice as $next_invoice)
2772 2772
 		{
@@ -2810,7 +2810,7 @@  discard block
 block discarded – undo
2810 2810
 	 */
2811 2811
 	public function setDraft($user, $idwarehouse = -1)
2812 2812
 	{
2813
-        // phpcs:enable
2813
+		// phpcs:enable
2814 2814
 		global $conf, $langs;
2815 2815
 
2816 2816
 		$error = 0;
@@ -2931,37 +2931,37 @@  discard block
 block discarded – undo
2931 2931
 	 *  @param		double		$pu_ht_devise		Unit price in currency
2932 2932
 	 *  @return    	int             				<0 if KO, Id of line if OK
2933 2933
 	 */
2934
-    public function addline(
2935
-        $desc,
2936
-        $pu_ht,
2937
-        $qty,
2938
-        $txtva,
2939
-        $txlocaltax1 = 0,
2940
-        $txlocaltax2 = 0,
2941
-        $fk_product = 0,
2942
-        $remise_percent = 0,
2943
-        $date_start = '',
2944
-        $date_end = '',
2945
-        $ventil = 0,
2946
-        $info_bits = 0,
2947
-        $fk_remise_except = '',
2948
-        $price_base_type = 'HT',
2949
-        $pu_ttc = 0,
2950
-        $type = self::TYPE_STANDARD,
2951
-        $rang = -1,
2952
-        $special_code = 0,
2953
-        $origin = '',
2954
-        $origin_id = 0,
2955
-        $fk_parent_line = 0,
2956
-        $fk_fournprice = null,
2957
-        $pa_ht = 0,
2958
-        $label = '',
2959
-        $array_options = 0,
2960
-        $situation_percent = 100,
2961
-        $fk_prev_id = 0,
2962
-        $fk_unit = null,
2963
-        $pu_ht_devise = 0
2964
-    ) {
2934
+	public function addline(
2935
+		$desc,
2936
+		$pu_ht,
2937
+		$qty,
2938
+		$txtva,
2939
+		$txlocaltax1 = 0,
2940
+		$txlocaltax2 = 0,
2941
+		$fk_product = 0,
2942
+		$remise_percent = 0,
2943
+		$date_start = '',
2944
+		$date_end = '',
2945
+		$ventil = 0,
2946
+		$info_bits = 0,
2947
+		$fk_remise_except = '',
2948
+		$price_base_type = 'HT',
2949
+		$pu_ttc = 0,
2950
+		$type = self::TYPE_STANDARD,
2951
+		$rang = -1,
2952
+		$special_code = 0,
2953
+		$origin = '',
2954
+		$origin_id = 0,
2955
+		$fk_parent_line = 0,
2956
+		$fk_fournprice = null,
2957
+		$pa_ht = 0,
2958
+		$label = '',
2959
+		$array_options = 0,
2960
+		$situation_percent = 100,
2961
+		$fk_prev_id = 0,
2962
+		$fk_unit = null,
2963
+		$pu_ht_devise = 0
2964
+	) {
2965 2965
 		// Deprecation warning
2966 2966
 		if ($label) {
2967 2967
 			dol_syslog(__METHOD__.": using line label is deprecated", LOG_WARNING);
@@ -3027,8 +3027,8 @@  discard block
 block discarded – undo
3027 3027
 				$product_type = $product->type;
3028 3028
 
3029 3029
 				if (!empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE) && $product_type == 0 && $product->stock_reel < $qty) {
3030
-                    $langs->load("errors");
3031
-				    $this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnInvoice', $product->ref);
3030
+					$langs->load("errors");
3031
+					$this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnInvoice', $product->ref);
3032 3032
 					$this->db->rollback();
3033 3033
 					return -3;
3034 3034
 				}
@@ -3061,8 +3061,8 @@  discard block
 block discarded – undo
3061 3061
 
3062 3062
 			// MultiCurrency
3063 3063
 			$multicurrency_total_ht = $tabprice[16];
3064
-            $multicurrency_total_tva = $tabprice[17];
3065
-            $multicurrency_total_ttc = $tabprice[18];
3064
+			$multicurrency_total_tva = $tabprice[17];
3065
+			$multicurrency_total_ttc = $tabprice[18];
3066 3066
 			$pu_ht_devise = $tabprice[19];
3067 3067
 
3068 3068
 			// Rank to use
@@ -3125,8 +3125,8 @@  discard block
 block discarded – undo
3125 3125
 			$this->line->multicurrency_code = $this->multicurrency_code;
3126 3126
 			$this->line->multicurrency_subprice		= $pu_ht_devise;
3127 3127
 			$this->line->multicurrency_total_ht 	= $multicurrency_total_ht;
3128
-            $this->line->multicurrency_total_tva 	= $multicurrency_total_tva;
3129
-            $this->line->multicurrency_total_ttc 	= $multicurrency_total_ttc;
3128
+			$this->line->multicurrency_total_tva 	= $multicurrency_total_tva;
3129
+			$this->line->multicurrency_total_ttc 	= $multicurrency_total_ttc;
3130 3130
 
3131 3131
 			if (is_array($array_options) && count($array_options) > 0) {
3132 3132
 				$this->line->array_options = $array_options;
@@ -3183,14 +3183,14 @@  discard block
 block discarded – undo
3183 3183
 	 * 	@param		int			$pa_ht				Price (without tax) of product when it was bought
3184 3184
 	 * 	@param		string		$label				Label of the line (deprecated, do not use)
3185 3185
 	 * 	@param		int			$special_code		Special code (also used by externals modules!)
3186
-     *  @param		array		$array_options		extrafields array
3186
+	 *  @param		array		$array_options		extrafields array
3187 3187
 	 * 	@param      int         $situation_percent  Situation advance percentage
3188 3188
 	 * 	@param 		string		$fk_unit 			Code of the unit to use. Null to use the default one
3189 3189
 	 * 	@param		double		$pu_ht_devise		Unit price in currency
3190 3190
 	 * 	@param		int			$notrigger			disable line update trigger
3191 3191
 	 *  @return    	int             				< 0 if KO, > 0 if OK
3192 3192
 	 */
3193
-    public function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $price_base_type = 'HT', $info_bits = 0, $type = self::TYPE_STANDARD, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = null, $pa_ht = 0, $label = '', $special_code = 0, $array_options = 0, $situation_percent = 100, $fk_unit = null, $pu_ht_devise = 0, $notrigger = 0)
3193
+	public function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $price_base_type = 'HT', $info_bits = 0, $type = self::TYPE_STANDARD, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = null, $pa_ht = 0, $label = '', $special_code = 0, $array_options = 0, $situation_percent = 100, $fk_unit = null, $pu_ht_devise = 0, $notrigger = 0)
3194 3194
 	{
3195 3195
 		global $conf, $user;
3196 3196
 		// Deprecation warning
@@ -3232,7 +3232,7 @@  discard block
 block discarded – undo
3232 3232
 			$remise_percent = price2num($remise_percent);
3233 3233
 			$qty			= price2num($qty);
3234 3234
 			$pu 			= price2num($pu);
3235
-        	$pu_ht_devise = price2num($pu_ht_devise);
3235
+			$pu_ht_devise = price2num($pu_ht_devise);
3236 3236
 			$pa_ht			= price2num($pa_ht);
3237 3237
 			$txtva			= price2num($txtva);
3238 3238
 			$txlocaltax1	= price2num($txlocaltax1);
@@ -3248,12 +3248,12 @@  discard block
 block discarded – undo
3248 3248
 			$localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
3249 3249
 
3250 3250
 			// Clean vat code
3251
-    		$vat_src_code = '';
3252
-    		if (preg_match('/\((.*)\)/', $txtva, $reg))
3253
-    		{
3254
-    		    $vat_src_code = $reg[1];
3255
-    		    $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
3256
-    		}
3251
+			$vat_src_code = '';
3252
+			if (preg_match('/\((.*)\)/', $txtva, $reg))
3253
+			{
3254
+				$vat_src_code = $reg[1];
3255
+				$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
3256
+			}
3257 3257
 
3258 3258
 			$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, $situation_percent, $this->multicurrency_tx, $pu_ht_devise);
3259 3259
 
@@ -3268,8 +3268,8 @@  discard block
 block discarded – undo
3268 3268
 
3269 3269
 			// MultiCurrency
3270 3270
 			$multicurrency_total_ht = $tabprice[16];
3271
-            $multicurrency_total_tva = $tabprice[17];
3272
-            $multicurrency_total_ttc = $tabprice[18];
3271
+			$multicurrency_total_tva = $tabprice[17];
3272
+			$multicurrency_total_ttc = $tabprice[18];
3273 3273
 			$pu_ht_devise = $tabprice[19];
3274 3274
 
3275 3275
 			// Old properties: $price, $remise (deprecated)
@@ -3294,8 +3294,8 @@  discard block
 block discarded – undo
3294 3294
 				$product_type = $product->type;
3295 3295
 
3296 3296
 				if (!empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE) && $product_type == 0 && $product->stock_reel < $qty) {
3297
-                    $langs->load("errors");
3298
-				    $this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnInvoice', $product->ref);
3297
+					$langs->load("errors");
3298
+					$this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnInvoice', $product->ref);
3299 3299
 					$this->db->rollback();
3300 3300
 					return -3;
3301 3301
 				}
@@ -3305,7 +3305,7 @@  discard block
 block discarded – undo
3305 3305
 
3306 3306
 			$line->oldline = $staticline;
3307 3307
 			$this->line = $line;
3308
-            $this->line->context = $this->context;
3308
+			$this->line->context = $this->context;
3309 3309
 
3310 3310
 			// Reorder if fk_parent_line change
3311 3311
 			if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line)
@@ -3350,8 +3350,8 @@  discard block
 block discarded – undo
3350 3350
 			// Multicurrency
3351 3351
 			$this->line->multicurrency_subprice		= $pu_ht_devise;
3352 3352
 			$this->line->multicurrency_total_ht 	= $multicurrency_total_ht;
3353
-            $this->line->multicurrency_total_tva 	= $multicurrency_total_tva;
3354
-            $this->line->multicurrency_total_ttc 	= $multicurrency_total_ttc;
3353
+			$this->line->multicurrency_total_tva 	= $multicurrency_total_tva;
3354
+			$this->line->multicurrency_total_ttc 	= $multicurrency_total_ttc;
3355 3355
 
3356 3356
 			if (is_array($array_options) && count($array_options) > 0) {
3357 3357
 				// We replace values in this->line->array_options only for entries defined into $array_options
@@ -3371,7 +3371,7 @@  discard block
 block discarded – undo
3371 3371
 				$this->db->commit();
3372 3372
 				return $result;
3373 3373
 			} else {
3374
-			    $this->error = $this->line->error;
3374
+				$this->error = $this->line->error;
3375 3375
 				$this->db->rollback();
3376 3376
 				return -1;
3377 3377
 			}
@@ -3388,7 +3388,7 @@  discard block
 block discarded – undo
3388 3388
 	 * @param	float	$situation_percent	progress percentage need to be test
3389 3389
 	 * @return false if KO, true if OK
3390 3390
 	 */
3391
-    public function checkProgressLine($idline, $situation_percent)
3391
+	public function checkProgressLine($idline, $situation_percent)
3392 3392
 	{
3393 3393
 		$sql = 'SELECT fd.situation_percent FROM '.MAIN_DB_PREFIX.'facturedet fd
3394 3394
 				INNER JOIN '.MAIN_DB_PREFIX.'facture f ON (fd.fk_facture = f.rowid)
@@ -3408,7 +3408,7 @@  discard block
 block discarded – undo
3408 3408
 		else return $situation_percent < $obj->situation_percent;
3409 3409
 	}
3410 3410
 
3411
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3411
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3412 3412
 	/**
3413 3413
 	 * Update invoice line with percentage
3414 3414
 	 *
@@ -3416,16 +3416,16 @@  discard block
 block discarded – undo
3416 3416
 	 * @param  int          $percent    Percentage
3417 3417
 	 * @return void
3418 3418
 	 */
3419
-    public function update_percent($line, $percent)
3419
+	public function update_percent($line, $percent)
3420 3420
 	{
3421
-        // phpcs:enable
3422
-	    global $mysoc, $user;
3421
+		// phpcs:enable
3422
+		global $mysoc, $user;
3423 3423
 
3424
-	    // Progress should never be changed for discount lines
3425
-	    if (($line->info_bits & 2) == 2)
3426
-	    {
3427
-	    	return;
3428
-	    }
3424
+		// Progress should never be changed for discount lines
3425
+		if (($line->info_bits & 2) == 2)
3426
+		{
3427
+			return;
3428
+		}
3429 3429
 
3430 3430
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
3431 3431
 
@@ -3451,9 +3451,9 @@  discard block
 block discarded – undo
3451 3451
 	 *	@param		int		$rowid		Id of line to delete
3452 3452
 	 *	@return		int					<0 if KO, >0 if OK
3453 3453
 	 */
3454
-    public function deleteline($rowid)
3454
+	public function deleteline($rowid)
3455 3455
 	{
3456
-        global $user;
3456
+		global $user;
3457 3457
 
3458 3458
 		dol_syslog(get_class($this)."::deleteline rowid=".$rowid, LOG_DEBUG);
3459 3459
 
@@ -3481,7 +3481,7 @@  discard block
 block discarded – undo
3481 3481
 
3482 3482
 		$line = new FactureLigne($this->db);
3483 3483
 
3484
-        $line->context = $this->context;
3484
+		$line->context = $this->context;
3485 3485
 
3486 3486
 		// For triggers
3487 3487
 		$result = $line->fetch($rowid);
@@ -3507,7 +3507,7 @@  discard block
 block discarded – undo
3507 3507
 		}
3508 3508
 	}
3509 3509
 
3510
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3510
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3511 3511
 	/**
3512 3512
 	 *	Set percent discount
3513 3513
 	 *
@@ -3516,9 +3516,9 @@  discard block
 block discarded – undo
3516 3516
 	 *  @param     	int		$notrigger	1=Does not execute triggers, 0= execute triggers
3517 3517
 	 *	@return		int 		<0 if ko, >0 if ok
3518 3518
 	 */
3519
-    public function set_remise($user, $remise, $notrigger = 0)
3519
+	public function set_remise($user, $remise, $notrigger = 0)
3520 3520
 	{
3521
-        // phpcs:enable
3521
+		// phpcs:enable
3522 3522
 		// Clean parameters
3523 3523
 		if (empty($remise)) $remise = 0;
3524 3524
 
@@ -3571,7 +3571,7 @@  discard block
 block discarded – undo
3571 3571
 	}
3572 3572
 
3573 3573
 
3574
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3574
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3575 3575
 	/**
3576 3576
 	 *	Set absolute discount
3577 3577
 	 *
@@ -3580,9 +3580,9 @@  discard block
 block discarded – undo
3580 3580
 	 *  @param     	int		$notrigger	1=Does not execute triggers, 0= execute triggers
3581 3581
 	 *	@return		int 				<0 if KO, >0 if OK
3582 3582
 	 */
3583
-    public function set_remise_absolue($user, $remise, $notrigger = 0)
3583
+	public function set_remise_absolue($user, $remise, $notrigger = 0)
3584 3584
 	{
3585
-        // phpcs:enable
3585
+		// phpcs:enable
3586 3586
 		if (empty($remise)) $remise = 0;
3587 3587
 
3588 3588
 		if ($user->rights->facture->creer)
@@ -3645,7 +3645,7 @@  discard block
 block discarded – undo
3645 3645
 	 *      @param     string		$mode		'next' for next value or 'last' for last value
3646 3646
 	 *      @return    string					free ref or last ref
3647 3647
 	 */
3648
-    public function getNextNumRef($soc, $mode = 'next')
3648
+	public function getNextNumRef($soc, $mode = 'next')
3649 3649
 	{
3650 3650
 		global $conf, $langs;
3651 3651
 
@@ -3743,7 +3743,7 @@  discard block
 block discarded – undo
3743 3743
 	 *	@param  int		$id		Id of object to load
3744 3744
 	 *	@return	void
3745 3745
 	 */
3746
-    public function info($id)
3746
+	public function info($id)
3747 3747
 	{
3748 3748
 		$sql = 'SELECT c.rowid, datec, date_valid as datev, tms as datem,';
3749 3749
 		$sql .= ' date_closing as dateclosing,';
@@ -3789,7 +3789,7 @@  discard block
 block discarded – undo
3789 3789
 	}
3790 3790
 
3791 3791
 
3792
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3792
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3793 3793
 	/**
3794 3794
 	 *  Return list of invoices (eventually filtered on a user) into an array
3795 3795
 	 *
@@ -3803,9 +3803,9 @@  discard block
 block discarded – undo
3803 3803
 	 *  @param    	string	$sortorder		Sort order
3804 3804
 	 *  @return     array|int             	-1 if KO, array with result if OK
3805 3805
 	 */
3806
-    public function liste_array($shortlist = 0, $draft = 0, $excluser = '', $socid = 0, $limit = 0, $offset = 0, $sortfield = 'f.datef,f.rowid', $sortorder = 'DESC')
3806
+	public function liste_array($shortlist = 0, $draft = 0, $excluser = '', $socid = 0, $limit = 0, $offset = 0, $sortfield = 'f.datef,f.rowid', $sortorder = 'DESC')
3807 3807
 	{
3808
-        // phpcs:enable
3808
+		// phpcs:enable
3809 3809
 		global $conf, $user;
3810 3810
 
3811 3811
 		$ga = array();
@@ -3860,7 +3860,7 @@  discard block
 block discarded – undo
3860 3860
 	}
3861 3861
 
3862 3862
 
3863
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3863
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3864 3864
 	/**
3865 3865
 	 *	Return list of invoices qualified to be replaced by another invoice.
3866 3866
 	 *	Invoices matching the following rules are returned:
@@ -3869,9 +3869,9 @@  discard block
 block discarded – undo
3869 3869
 	 *	@param		int		$socid		Id thirdparty
3870 3870
 	 *	@return    	array|int			Array of invoices ('id'=>id, 'ref'=>ref, 'status'=>status, 'paymentornot'=>0/1)
3871 3871
 	 */
3872
-    public function list_replacable_invoices($socid = 0)
3872
+	public function list_replacable_invoices($socid = 0)
3873 3873
 	{
3874
-        // phpcs:enable
3874
+		// phpcs:enable
3875 3875
 		global $conf;
3876 3876
 
3877 3877
 		$return = array();
@@ -3908,7 +3908,7 @@  discard block
 block discarded – undo
3908 3908
 	}
3909 3909
 
3910 3910
 
3911
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3911
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3912 3912
 	/**
3913 3913
 	 *	Return list of invoices qualified to be corrected by a credit note.
3914 3914
 	 *	Invoices matching the following rules are returned:
@@ -3917,9 +3917,9 @@  discard block
 block discarded – undo
3917 3917
 	 *	@param		int		$socid		Id thirdparty
3918 3918
 	 *	@return    	array				Array of invoices ($id => array('ref'=>,'paymentornot'=>,'status'=>,'paye'=>)
3919 3919
 	 */
3920
-    public function list_qualified_avoir_invoices($socid = 0)
3920
+	public function list_qualified_avoir_invoices($socid = 0)
3921 3921
 	{
3922
-        // phpcs:enable
3922
+		// phpcs:enable
3923 3923
 		global $conf;
3924 3924
 
3925 3925
 		$return = array();
@@ -3938,17 +3938,17 @@  discard block
 block discarded – undo
3938 3938
 		$sql .= " AND f.type != ".self::TYPE_CREDIT_NOTE; // Type non 2 si facture non avoir
3939 3939
 
3940 3940
 		if (!empty($conf->global->INVOICE_USE_SITUATION_CREDIT_NOTE)) {
3941
-		    // Select the last situation invoice
3942
-		    $sqlSit = 'SELECT MAX(fs.rowid)';
3943
-		    $sqlSit .= " FROM ".MAIN_DB_PREFIX."facture as fs";
3944
-		    $sqlSit .= " WHERE fs.entity IN (".getEntity('invoice').")";
3945
-		    $sqlSit .= " AND fs.type = ".self::TYPE_SITUATION;
3946
-		    $sqlSit .= " AND fs.fk_statut in (".self::STATUS_VALIDATED.",".self::STATUS_CLOSED.")";
3947
-		    $sqlSit .= " GROUP BY fs.situation_cycle_ref";
3948
-		    $sqlSit .= " ORDER BY fs.situation_counter";
3949
-            $sql .= " AND ( f.type != ".self::TYPE_SITUATION." OR f.rowid IN (".$sqlSit.") )"; // Type non 5 si facture non avoir
3941
+			// Select the last situation invoice
3942
+			$sqlSit = 'SELECT MAX(fs.rowid)';
3943
+			$sqlSit .= " FROM ".MAIN_DB_PREFIX."facture as fs";
3944
+			$sqlSit .= " WHERE fs.entity IN (".getEntity('invoice').")";
3945
+			$sqlSit .= " AND fs.type = ".self::TYPE_SITUATION;
3946
+			$sqlSit .= " AND fs.fk_statut in (".self::STATUS_VALIDATED.",".self::STATUS_CLOSED.")";
3947
+			$sqlSit .= " GROUP BY fs.situation_cycle_ref";
3948
+			$sqlSit .= " ORDER BY fs.situation_counter";
3949
+			$sql .= " AND ( f.type != ".self::TYPE_SITUATION." OR f.rowid IN (".$sqlSit.") )"; // Type non 5 si facture non avoir
3950 3950
 		} else {
3951
-		    $sql .= " AND f.type != ".self::TYPE_SITUATION; // Type non 5 si facture non avoir
3951
+			$sql .= " AND f.type != ".self::TYPE_SITUATION; // Type non 5 si facture non avoir
3952 3952
 		}
3953 3953
 
3954 3954
 		if ($socid > 0) $sql .= " AND f.fk_soc = ".$socid;
@@ -3979,16 +3979,16 @@  discard block
 block discarded – undo
3979 3979
 	}
3980 3980
 
3981 3981
 
3982
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3982
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3983 3983
 	/**
3984 3984
 	 *	Load indicators for dashboard (this->nbtodo and this->nbtodolate)
3985 3985
 	 *
3986 3986
 	 *	@param  User		$user    	Object user
3987 3987
 	 *	@return WorkboardResponse|int 	<0 if KO, WorkboardResponse if OK
3988 3988
 	 */
3989
-    public function load_board($user)
3989
+	public function load_board($user)
3990 3990
 	{
3991
-        // phpcs:enable
3991
+		// phpcs:enable
3992 3992
 		global $conf, $langs;
3993 3993
 
3994 3994
 		$clause = " WHERE";
@@ -4051,7 +4051,7 @@  discard block
 block discarded – undo
4051 4051
 	 *
4052 4052
 	 *	@return     array       Liste des id contacts facturation
4053 4053
 	 */
4054
-    public function getIdBillingContact()
4054
+	public function getIdBillingContact()
4055 4055
 	{
4056 4056
 		return $this->getIdContact('external', 'BILLING');
4057 4057
 	}
@@ -4061,7 +4061,7 @@  discard block
 block discarded – undo
4061 4061
 	 *
4062 4062
 	 *	@return     array       Liste des id contacts livraison
4063 4063
 	 */
4064
-    public function getIdShippingContact()
4064
+	public function getIdShippingContact()
4065 4065
 	{
4066 4066
 		return $this->getIdContact('external', 'SHIPPING');
4067 4067
 	}
@@ -4075,7 +4075,7 @@  discard block
 block discarded – undo
4075 4075
 	 *	@param	string		$option		''=Create a specimen invoice with lines, 'nolines'=No lines
4076 4076
 	 *  @return	void
4077 4077
 	 */
4078
-    public function initAsSpecimen($option = '')
4078
+	public function initAsSpecimen($option = '')
4079 4079
 	{
4080 4080
 		global $conf, $langs;
4081 4081
 
@@ -4083,7 +4083,7 @@  discard block
 block discarded – undo
4083 4083
 		$arraynow = dol_getdate($now);
4084 4084
 		$nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
4085 4085
 
4086
-        // Load array of products prodids
4086
+		// Load array of products prodids
4087 4087
 		$num_prods = 0;
4088 4088
 		$prodids = array();
4089 4089
 		$sql = "SELECT rowid";
@@ -4228,15 +4228,15 @@  discard block
 block discarded – undo
4228 4228
 		}
4229 4229
 	}
4230 4230
 
4231
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
4231
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
4232 4232
 	/**
4233 4233
 	 *      Load indicators for dashboard (this->nbtodo and this->nbtodolate)
4234 4234
 	 *
4235 4235
 	 *      @return         int     <0 if KO, >0 if OK
4236 4236
 	 */
4237
-    public function load_state_board()
4237
+	public function load_state_board()
4238 4238
 	{
4239
-        // phpcs:enable
4239
+		// phpcs:enable
4240 4240
 		global $conf, $user;
4241 4241
 
4242 4242
 		$this->nb = array();
@@ -4261,7 +4261,7 @@  discard block
 block discarded – undo
4261 4261
 			{
4262 4262
 				$this->nb["invoices"] = $obj->nb;
4263 4263
 			}
4264
-            $this->db->free($resql);
4264
+			$this->db->free($resql);
4265 4265
 			return 1;
4266 4266
 		} else {
4267 4267
 			dol_print_error($this->db);
@@ -4275,9 +4275,9 @@  discard block
 block discarded – undo
4275 4275
 	 *
4276 4276
 	 * 	@return int		>0 if OK, <0 if KO
4277 4277
 	 */
4278
-    public function getLinesArray()
4278
+	public function getLinesArray()
4279 4279
 	{
4280
-	    return $this->fetch_lines();
4280
+		return $this->fetch_lines();
4281 4281
 	}
4282 4282
 
4283 4283
 	/**
@@ -4321,7 +4321,7 @@  discard block
 block discarded – undo
4321 4321
 	 *
4322 4322
 	 * @return int >= 1 if OK, -1 if error
4323 4323
 	 */
4324
-    public function newCycle()
4324
+	public function newCycle()
4325 4325
 	{
4326 4326
 		$sql = 'SELECT max(situation_cycle_ref) FROM '.MAIN_DB_PREFIX.'facture as f';
4327 4327
 		$sql .= " WHERE f.entity IN (".getEntity('invoice', 0).")";
@@ -4344,27 +4344,27 @@  discard block
 block discarded – undo
4344 4344
 		}
4345 4345
 	}
4346 4346
 
4347
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
4347
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
4348 4348
 	/**
4349 4349
 	 * Checks if the invoice is the first of a cycle
4350 4350
 	 *
4351 4351
 	 * @return boolean
4352 4352
 	 */
4353
-    public function is_first()
4353
+	public function is_first()
4354 4354
 	{
4355
-        // phpcs:enable
4355
+		// phpcs:enable
4356 4356
 		return ($this->situation_counter == 1);
4357 4357
 	}
4358 4358
 
4359
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
4359
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
4360 4360
 	/**
4361 4361
 	 * Returns an array containing the previous situations as Facture objects
4362 4362
 	 *
4363 4363
 	 * @return mixed -1 if error, array of previous situations
4364 4364
 	 */
4365
-    public function get_prev_sits()
4365
+	public function get_prev_sits()
4366 4366
 	{
4367
-        // phpcs:enable
4367
+		// phpcs:enable
4368 4368
 		global $conf;
4369 4369
 
4370 4370
 		$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture';
@@ -4396,7 +4396,7 @@  discard block
 block discarded – undo
4396 4396
 	 *  @param     	int		$notrigger	1=Does not execute triggers, 0= execute triggers
4397 4397
 	 *	@return		int 				<0 if KO, >0 if OK
4398 4398
 	 */
4399
-    public function setFinal(User $user, $notrigger = 0)
4399
+	public function setFinal(User $user, $notrigger = 0)
4400 4400
 	{
4401 4401
 		$error = 0;
4402 4402
 
@@ -4435,15 +4435,15 @@  discard block
 block discarded – undo
4435 4435
 		}
4436 4436
 	}
4437 4437
 
4438
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
4438
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
4439 4439
 	/**
4440 4440
 	 * Checks if the invoice is the last in its cycle
4441 4441
 	 *
4442 4442
 	 * @return bool Last of the cycle status
4443 4443
 	 */
4444
-    public function is_last_in_cycle()
4444
+	public function is_last_in_cycle()
4445 4445
 	{
4446
-        // phpcs:enable
4446
+		// phpcs:enable
4447 4447
 		global $conf;
4448 4448
 
4449 4449
 		if (!empty($this->situation_cycle_ref)) {
@@ -4501,21 +4501,21 @@  discard block
 block discarded – undo
4501 4501
 		$hasDelay = $this->date_lim_reglement < ($now - $conf->facture->client->warning_delay);
4502 4502
 		if ($hasDelay && !empty($this->retained_warranty) && !empty($this->retained_warranty_date_limit))
4503 4503
 		{
4504
-		    $totalpaye = $this->getSommePaiement();
4505
-		    $totalpaye = floatval($totalpaye);
4506
-		    $RetainedWarrantyAmount = $this->getRetainedWarrantyAmount();
4507
-		    if ($totalpaye >= 0 && $RetainedWarrantyAmount >= 0)
4508
-		    {
4509
-		        if (($totalpaye < $this->total_ttc - $RetainedWarrantyAmount) && $this->date_lim_reglement < ($now - $conf->facture->client->warning_delay))
4510
-		        {
4511
-		            $hasDelay = 1;
4512
-		        } elseif ($totalpaye < $this->total_ttc && $this->retained_warranty_date_limit < ($now - $conf->facture->client->warning_delay))
4513
-		        {
4514
-		            $hasDelay = 1;
4515
-		        } else {
4516
-		            $hasDelay = 0;
4517
-		        }
4518
-		    }
4504
+			$totalpaye = $this->getSommePaiement();
4505
+			$totalpaye = floatval($totalpaye);
4506
+			$RetainedWarrantyAmount = $this->getRetainedWarrantyAmount();
4507
+			if ($totalpaye >= 0 && $RetainedWarrantyAmount >= 0)
4508
+			{
4509
+				if (($totalpaye < $this->total_ttc - $RetainedWarrantyAmount) && $this->date_lim_reglement < ($now - $conf->facture->client->warning_delay))
4510
+				{
4511
+					$hasDelay = 1;
4512
+				} elseif ($totalpaye < $this->total_ttc && $this->retained_warranty_date_limit < ($now - $conf->facture->client->warning_delay))
4513
+				{
4514
+					$hasDelay = 1;
4515
+				} else {
4516
+					$hasDelay = 0;
4517
+				}
4518
+			}
4519 4519
 		}
4520 4520
 
4521 4521
 		return $hasDelay;
@@ -4566,45 +4566,45 @@  discard block
 block discarded – undo
4566 4566
 	public function getRetainedWarrantyAmount($rounding = -1)
4567 4567
 	{
4568 4568
 		global $conf;
4569
-	    if (empty($this->retained_warranty)) {
4570
-	        return -1;
4571
-	    }
4572
-
4573
-	    $retainedWarrantyAmount = 0;
4574
-
4575
-	    // Billed - retained warranty
4576
-	    if ($this->type == Facture::TYPE_SITUATION && !empty($conf->global->INVOICE_RETAINED_WARRANTY_LIMITED_TO_FINAL_SITUATION))
4577
-	    {
4578
-	        $displayWarranty = true;
4579
-	        // Check if this situation invoice is 100% for real
4580
-	        if (!empty($this->lines)) {
4581
-	            foreach ($this->lines as $i => $line) {
4582
-	                if ($line->product_type < 2 && $line->situation_percent < 100) {
4583
-	                    $displayWarranty = false;
4584
-	                    break;
4585
-	            	}
4586
-	            }
4587
-	        }
4588
-
4589
-	        if ($displayWarranty && !empty($this->situation_final))
4590
-	        {
4591
-	            $this->fetchPreviousNextSituationInvoice();
4592
-	            $TPreviousIncoice = $this->tab_previous_situation_invoice;
4593
-
4594
-	            $total2BillWT = 0;
4595
-	            foreach ($TPreviousIncoice as &$fac) {
4596
-	                $total2BillWT += $fac->total_ttc;
4597
-	            }
4598
-	            $total2BillWT += $this->total_ttc;
4599
-
4600
-	            $retainedWarrantyAmount = $total2BillWT * $this->retained_warranty / 100;
4601
-	        } else {
4602
-	            return -1;
4603
-	        }
4604
-	    } else {
4605
-	        // Because one day retained warranty could be used on standard invoices
4606
-	        $retainedWarrantyAmount = $this->total_ttc * $this->retained_warranty / 100;
4607
-	    }
4569
+		if (empty($this->retained_warranty)) {
4570
+			return -1;
4571
+		}
4572
+
4573
+		$retainedWarrantyAmount = 0;
4574
+
4575
+		// Billed - retained warranty
4576
+		if ($this->type == Facture::TYPE_SITUATION && !empty($conf->global->INVOICE_RETAINED_WARRANTY_LIMITED_TO_FINAL_SITUATION))
4577
+		{
4578
+			$displayWarranty = true;
4579
+			// Check if this situation invoice is 100% for real
4580
+			if (!empty($this->lines)) {
4581
+				foreach ($this->lines as $i => $line) {
4582
+					if ($line->product_type < 2 && $line->situation_percent < 100) {
4583
+						$displayWarranty = false;
4584
+						break;
4585
+					}
4586
+				}
4587
+			}
4588
+
4589
+			if ($displayWarranty && !empty($this->situation_final))
4590
+			{
4591
+				$this->fetchPreviousNextSituationInvoice();
4592
+				$TPreviousIncoice = $this->tab_previous_situation_invoice;
4593
+
4594
+				$total2BillWT = 0;
4595
+				foreach ($TPreviousIncoice as &$fac) {
4596
+					$total2BillWT += $fac->total_ttc;
4597
+				}
4598
+				$total2BillWT += $this->total_ttc;
4599
+
4600
+				$retainedWarrantyAmount = $total2BillWT * $this->retained_warranty / 100;
4601
+			} else {
4602
+				return -1;
4603
+			}
4604
+		} else {
4605
+			// Because one day retained warranty could be used on standard invoices
4606
+			$retainedWarrantyAmount = $this->total_ttc * $this->retained_warranty / 100;
4607
+		}
4608 4608
 
4609 4609
 		if ($rounding < 0) {
4610 4610
 			$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
@@ -4614,7 +4614,7 @@  discard block
 block discarded – undo
4614 4614
 			return round($retainedWarrantyAmount, $rounding);
4615 4615
 		}
4616 4616
 
4617
-	    return $retainedWarrantyAmount;
4617
+		return $retainedWarrantyAmount;
4618 4618
 	}
4619 4619
 
4620 4620
 	/**
@@ -4625,28 +4625,28 @@  discard block
 block discarded – undo
4625 4625
 	 */
4626 4626
 	public function setRetainedWarranty($value)
4627 4627
 	{
4628
-	    dol_syslog(get_class($this).'::setRetainedWarranty('.$value.')');
4629
-	    if ($this->statut >= 0)
4630
-	    {
4631
-	        $fieldname = 'retained_warranty';
4632
-	        $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
4633
-	        $sql .= ' SET '.$fieldname.' = '.floatval($value);
4634
-	        $sql .= ' WHERE rowid='.$this->id;
4635
-
4636
-	        if ($this->db->query($sql))
4637
-	        {
4638
-	            $this->retained_warranty = floatval($value);
4639
-	            return 1;
4640
-	        } else {
4641
-	            dol_syslog(get_class($this).'::setRetainedWarranty Erreur '.$sql.' - '.$this->db->error());
4642
-	            $this->error = $this->db->error();
4643
-	            return -1;
4644
-	        }
4645
-	    } else {
4646
-	        dol_syslog(get_class($this).'::setRetainedWarranty, status of the object is incompatible');
4647
-	        $this->error = 'Status of the object is incompatible '.$this->statut;
4648
-	        return -2;
4649
-	    }
4628
+		dol_syslog(get_class($this).'::setRetainedWarranty('.$value.')');
4629
+		if ($this->statut >= 0)
4630
+		{
4631
+			$fieldname = 'retained_warranty';
4632
+			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
4633
+			$sql .= ' SET '.$fieldname.' = '.floatval($value);
4634
+			$sql .= ' WHERE rowid='.$this->id;
4635
+
4636
+			if ($this->db->query($sql))
4637
+			{
4638
+				$this->retained_warranty = floatval($value);
4639
+				return 1;
4640
+			} else {
4641
+				dol_syslog(get_class($this).'::setRetainedWarranty Erreur '.$sql.' - '.$this->db->error());
4642
+				$this->error = $this->db->error();
4643
+				return -1;
4644
+			}
4645
+		} else {
4646
+			dol_syslog(get_class($this).'::setRetainedWarranty, status of the object is incompatible');
4647
+			$this->error = 'Status of the object is incompatible '.$this->statut;
4648
+			return -2;
4649
+		}
4650 4650
 	}
4651 4651
 
4652 4652
 
@@ -4659,33 +4659,33 @@  discard block
 block discarded – undo
4659 4659
 	 */
4660 4660
 	public function setRetainedWarrantyDateLimit($timestamp, $dateYmd = false)
4661 4661
 	{
4662
-	    if (!$timestamp && $dateYmd) {
4663
-	        $timestamp = $this->db->jdate($dateYmd);
4664
-	    }
4665
-
4666
-
4667
-	    dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit('.$timestamp.')');
4668
-	    if ($this->statut >= 0)
4669
-	    {
4670
-	        $fieldname = 'retained_warranty_date_limit';
4671
-	        $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
4672
-	        $sql .= ' SET '.$fieldname.' = '.(strval($timestamp) != '' ? '\''.$this->db->idate($timestamp).'\'' : 'null');
4673
-	        $sql .= ' WHERE rowid='.$this->id;
4674
-
4675
-	        if ($this->db->query($sql))
4676
-	        {
4677
-	            $this->retained_warranty_date_limit = $timestamp;
4678
-	            return 1;
4679
-	        } else {
4680
-	            dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit Erreur '.$sql.' - '.$this->db->error());
4681
-	            $this->error = $this->db->error();
4682
-	            return -1;
4683
-	        }
4684
-	    } else {
4685
-	        dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit, status of the object is incompatible');
4686
-	        $this->error = 'Status of the object is incompatible '.$this->statut;
4687
-	        return -2;
4688
-	    }
4662
+		if (!$timestamp && $dateYmd) {
4663
+			$timestamp = $this->db->jdate($dateYmd);
4664
+		}
4665
+
4666
+
4667
+		dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit('.$timestamp.')');
4668
+		if ($this->statut >= 0)
4669
+		{
4670
+			$fieldname = 'retained_warranty_date_limit';
4671
+			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
4672
+			$sql .= ' SET '.$fieldname.' = '.(strval($timestamp) != '' ? '\''.$this->db->idate($timestamp).'\'' : 'null');
4673
+			$sql .= ' WHERE rowid='.$this->id;
4674
+
4675
+			if ($this->db->query($sql))
4676
+			{
4677
+				$this->retained_warranty_date_limit = $timestamp;
4678
+				return 1;
4679
+			} else {
4680
+				dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit Erreur '.$sql.' - '.$this->db->error());
4681
+				$this->error = $this->db->error();
4682
+				return -1;
4683
+			}
4684
+		} else {
4685
+			dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit, status of the object is incompatible');
4686
+			$this->error = 'Status of the object is incompatible '.$this->statut;
4687
+			return -2;
4688
+		}
4689 4689
 	}
4690 4690
 }
4691 4691
 
@@ -4695,12 +4695,12 @@  discard block
 block discarded – undo
4695 4695
  */
4696 4696
 class FactureLigne extends CommonInvoiceLine
4697 4697
 {
4698
-    /**
4698
+	/**
4699 4699
 	 * @var string ID to identify managed object
4700 4700
 	 */
4701 4701
 	public $element = 'facturedet';
4702 4702
 
4703
-    /**
4703
+	/**
4704 4704
 	 * @var string Name of table without prefix where object is stored
4705 4705
 	 */
4706 4706
 	public $table_element = 'facturedet';
@@ -4785,7 +4785,7 @@  discard block
 block discarded – undo
4785 4785
 	 *	@param	int		$rowid      id of invoice line to get
4786 4786
 	 *	@return	int					<0 if KO, >0 if OK
4787 4787
 	 */
4788
-    public function fetch($rowid)
4788
+	public function fetch($rowid)
4789 4789
 	{
4790 4790
 		$sql = 'SELECT fd.rowid, fd.fk_facture, fd.fk_parent_line, fd.fk_product, fd.product_type, fd.label as custom_label, fd.description, fd.price, fd.qty, fd.vat_src_code, fd.tva_tx,';
4791 4791
 		$sql .= ' fd.localtax1_tx, fd. localtax2_tx, fd.remise, fd.remise_percent, fd.fk_remise_except, fd.subprice,';
@@ -4863,7 +4863,7 @@  discard block
 block discarded – undo
4863 4863
 
4864 4864
 			return 1;
4865 4865
 		} else {
4866
-		    $this->error = $this->db->lasterror();
4866
+			$this->error = $this->db->lasterror();
4867 4867
 			return -1;
4868 4868
 		}
4869 4869
 	}
@@ -4875,15 +4875,15 @@  discard block
 block discarded – undo
4875 4875
 	 *  @param      int     $noerrorifdiscountalreadylinked  1=Do not make error if lines is linked to a discount and discount already linked to another
4876 4876
 	 *	@return		int						                 <0 if KO, >0 if OK
4877 4877
 	 */
4878
-    public function insert($notrigger = 0, $noerrorifdiscountalreadylinked = 0)
4878
+	public function insert($notrigger = 0, $noerrorifdiscountalreadylinked = 0)
4879 4879
 	{
4880 4880
 		global $langs, $user, $conf;
4881 4881
 
4882 4882
 		$error = 0;
4883 4883
 
4884
-        $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'.
4884
+		$pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'.
4885 4885
 
4886
-        dol_syslog(get_class($this)."::insert rang=".$this->rang, LOG_DEBUG);
4886
+		dol_syslog(get_class($this)."::insert rang=".$this->rang, LOG_DEBUG);
4887 4887
 
4888 4888
 		// Clean parameters
4889 4889
 		$this->desc = trim($this->desc);
@@ -4957,7 +4957,7 @@  discard block
 block discarded – undo
4957 4957
 		$sql .= " ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
4958 4958
 		$sql .= " '".$this->db->escape($this->desc)."',";
4959 4959
 		$sql .= " ".price2num($this->qty).",";
4960
-        $sql .= " ".(empty($this->vat_src_code) ? "''" : "'".$this->db->escape($this->vat_src_code)."'").",";
4960
+		$sql .= " ".(empty($this->vat_src_code) ? "''" : "'".$this->db->escape($this->vat_src_code)."'").",";
4961 4961
 		$sql .= " ".price2num($this->tva_tx).",";
4962 4962
 		$sql .= " ".price2num($this->localtax1_tx).",";
4963 4963
 		$sql .= " ".price2num($this->localtax2_tx).",";
@@ -5001,14 +5001,14 @@  discard block
 block discarded – undo
5001 5001
 			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'facturedet');
5002 5002
 			$this->rowid = $this->id; // For backward compatibility
5003 5003
 
5004
-            if (!$error)
5005
-            {
5006
-            	$result = $this->insertExtraFields();
5007
-            	if ($result < 0)
5008
-            	{
5009
-            		$error++;
5010
-            	}
5011
-            }
5004
+			if (!$error)
5005
+			{
5006
+				$result = $this->insertExtraFields();
5007
+				if ($result < 0)
5008
+				{
5009
+					$error++;
5010
+				}
5011
+			}
5012 5012
 
5013 5013
 			// Si fk_remise_except defini, on lie la remise a la facture
5014 5014
 			// ce qui la flague comme "consommee".
@@ -5021,16 +5021,16 @@  discard block
 block discarded – undo
5021 5021
 					// Check if discount was found
5022 5022
 					if ($result > 0)
5023 5023
 					{
5024
-					    // Check if discount not already affected to another invoice
5024
+						// Check if discount not already affected to another invoice
5025 5025
 						if ($discount->fk_facture_line > 0)
5026 5026
 						{
5027
-						    if (empty($noerrorifdiscountalreadylinked))
5028
-						    {
5029
-    							$this->error = $langs->trans("ErrorDiscountAlreadyUsed", $discount->id);
5030
-    							dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR);
5031
-    							$this->db->rollback();
5032
-    							return -3;
5033
-						    }
5027
+							if (empty($noerrorifdiscountalreadylinked))
5028
+							{
5029
+								$this->error = $langs->trans("ErrorDiscountAlreadyUsed", $discount->id);
5030
+								dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR);
5031
+								$this->db->rollback();
5032
+								return -3;
5033
+							}
5034 5034
 						} else {
5035 5035
 							$result = $discount->link_to_invoice($this->rowid, 0);
5036 5036
 							if ($result < 0)
@@ -5057,14 +5057,14 @@  discard block
 block discarded – undo
5057 5057
 
5058 5058
 			if (!$notrigger)
5059 5059
 			{
5060
-                // Call trigger
5061
-                $result = $this->call_trigger('LINEBILL_INSERT', $user);
5062
-                if ($result < 0)
5063
-                {
5060
+				// Call trigger
5061
+				$result = $this->call_trigger('LINEBILL_INSERT', $user);
5062
+				if ($result < 0)
5063
+				{
5064 5064
 					$this->db->rollback();
5065 5065
 					return -2;
5066 5066
 				}
5067
-                // End call triggers
5067
+				// End call triggers
5068 5068
 			}
5069 5069
 
5070 5070
 			$this->db->commit();
@@ -5083,7 +5083,7 @@  discard block
 block discarded – undo
5083 5083
 	 *	@param		int		$notrigger	Disable triggers
5084 5084
 	 *	@return		int					<0 if KO, >0 if OK
5085 5085
 	 */
5086
-    public function update($user = '', $notrigger = 0)
5086
+	public function update($user = '', $notrigger = 0)
5087 5087
 	{
5088 5088
 		global $user, $conf;
5089 5089
 
@@ -5129,34 +5129,34 @@  discard block
 block discarded – undo
5129 5129
 
5130 5130
 		$this->db->begin();
5131 5131
 
5132
-        // Mise a jour ligne en base
5133
-        $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet SET";
5134
-        $sql .= " description='".$this->db->escape($this->desc)."'";
5135
-        $sql .= ", label=".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
5136
-        $sql .= ", subprice=".price2num($this->subprice)."";
5137
-        $sql .= ", remise_percent=".price2num($this->remise_percent)."";
5138
-        if ($this->fk_remise_except) $sql .= ", fk_remise_except=".$this->fk_remise_except;
5139
-        else $sql .= ", fk_remise_except=null";
5132
+		// Mise a jour ligne en base
5133
+		$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet SET";
5134
+		$sql .= " description='".$this->db->escape($this->desc)."'";
5135
+		$sql .= ", label=".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
5136
+		$sql .= ", subprice=".price2num($this->subprice)."";
5137
+		$sql .= ", remise_percent=".price2num($this->remise_percent)."";
5138
+		if ($this->fk_remise_except) $sql .= ", fk_remise_except=".$this->fk_remise_except;
5139
+		else $sql .= ", fk_remise_except=null";
5140 5140
 		$sql .= ", vat_src_code = '".(empty($this->vat_src_code) ? '' : $this->db->escape($this->vat_src_code))."'";
5141
-        $sql .= ", tva_tx=".price2num($this->tva_tx)."";
5142
-        $sql .= ", localtax1_tx=".price2num($this->localtax1_tx)."";
5143
-        $sql .= ", localtax2_tx=".price2num($this->localtax2_tx)."";
5141
+		$sql .= ", tva_tx=".price2num($this->tva_tx)."";
5142
+		$sql .= ", localtax1_tx=".price2num($this->localtax1_tx)."";
5143
+		$sql .= ", localtax2_tx=".price2num($this->localtax2_tx)."";
5144 5144
 		$sql .= ", localtax1_type='".$this->db->escape($this->localtax1_type)."'";
5145 5145
 		$sql .= ", localtax2_type='".$this->db->escape($this->localtax2_type)."'";
5146
-        $sql .= ", qty=".price2num($this->qty);
5147
-        $sql .= ", date_start=".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null");
5148
-        $sql .= ", date_end=".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null");
5149
-        $sql .= ", product_type=".$this->product_type;
5150
-        $sql .= ", info_bits='".$this->db->escape($this->info_bits)."'";
5151
-        $sql .= ", special_code='".$this->db->escape($this->special_code)."'";
5152
-        if (empty($this->skip_update_total))
5153
-        {
5154
-        	$sql .= ", total_ht=".price2num($this->total_ht);
5155
-        	$sql .= ", total_tva=".price2num($this->total_tva);
5156
-        	$sql .= ", total_ttc=".price2num($this->total_ttc);
5157
-        	$sql .= ", total_localtax1=".price2num($this->total_localtax1);
5158
-        	$sql .= ", total_localtax2=".price2num($this->total_localtax2);
5159
-        }
5146
+		$sql .= ", qty=".price2num($this->qty);
5147
+		$sql .= ", date_start=".(!empty($this->date_start) ? "'".$this->db->idate($this->date_start)."'" : "null");
5148
+		$sql .= ", date_end=".(!empty($this->date_end) ? "'".$this->db->idate($this->date_end)."'" : "null");
5149
+		$sql .= ", product_type=".$this->product_type;
5150
+		$sql .= ", info_bits='".$this->db->escape($this->info_bits)."'";
5151
+		$sql .= ", special_code='".$this->db->escape($this->special_code)."'";
5152
+		if (empty($this->skip_update_total))
5153
+		{
5154
+			$sql .= ", total_ht=".price2num($this->total_ht);
5155
+			$sql .= ", total_tva=".price2num($this->total_tva);
5156
+			$sql .= ", total_ttc=".price2num($this->total_ttc);
5157
+			$sql .= ", total_localtax1=".price2num($this->total_localtax1);
5158
+			$sql .= ", total_localtax2=".price2num($this->total_localtax2);
5159
+		}
5160 5160
 		$sql .= ", fk_product_fournisseur_price=".(!empty($this->fk_fournprice) ? "'".$this->db->escape($this->fk_fournprice)."'" : "null");
5161 5161
 		$sql .= ", buy_price_ht='".price2num($this->pa_ht)."'";
5162 5162
 		$sql .= ", fk_parent_line=".($this->fk_parent_line > 0 ? $this->fk_parent_line : "null");
@@ -5167,9 +5167,9 @@  discard block
 block discarded – undo
5167 5167
 
5168 5168
 		// Multicurrency
5169 5169
 		$sql .= ", multicurrency_subprice=".price2num($this->multicurrency_subprice)."";
5170
-        $sql .= ", multicurrency_total_ht=".price2num($this->multicurrency_total_ht)."";
5171
-        $sql .= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
5172
-        $sql .= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
5170
+		$sql .= ", multicurrency_total_ht=".price2num($this->multicurrency_total_ht)."";
5171
+		$sql .= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
5172
+		$sql .= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
5173 5173
 
5174 5174
 		$sql .= " WHERE rowid = ".$this->rowid;
5175 5175
 
@@ -5177,26 +5177,26 @@  discard block
 block discarded – undo
5177 5177
 		$resql = $this->db->query($sql);
5178 5178
 		if ($resql)
5179 5179
 		{
5180
-        	if (!$error)
5181
-        	{
5182
-        		$this->id = $this->rowid;
5183
-        		$result = $this->insertExtraFields();
5184
-        		if ($result < 0)
5185
-        		{
5186
-        			$error++;
5187
-        		}
5188
-        	}
5180
+			if (!$error)
5181
+			{
5182
+				$this->id = $this->rowid;
5183
+				$result = $this->insertExtraFields();
5184
+				if ($result < 0)
5185
+				{
5186
+					$error++;
5187
+				}
5188
+			}
5189 5189
 
5190 5190
 			if (!$error && !$notrigger)
5191 5191
 			{
5192
-                // Call trigger
5193
-                $result = $this->call_trigger('LINEBILL_UPDATE', $user);
5194
-                if ($result < 0)
5192
+				// Call trigger
5193
+				$result = $this->call_trigger('LINEBILL_UPDATE', $user);
5194
+				if ($result < 0)
5195 5195
  				{
5196 5196
 					$this->db->rollback();
5197 5197
 					return -2;
5198 5198
 				}
5199
-                // End call triggers
5199
+				// End call triggers
5200 5200
 			}
5201 5201
 			$this->db->commit();
5202 5202
 			return 1;
@@ -5210,10 +5210,10 @@  discard block
 block discarded – undo
5210 5210
 	/**
5211 5211
 	 * 	Delete line in database
5212 5212
 	 *  TODO Add param User $user and notrigger (see skeleton)
5213
-     *
5213
+	 *
5214 5214
 	 *	@return	    int		           <0 if KO, >0 if OK
5215 5215
 	 */
5216
-    public function delete()
5216
+	public function delete()
5217 5217
 	{
5218 5218
 		global $user;
5219 5219
 
@@ -5228,13 +5228,13 @@  discard block
 block discarded – undo
5228 5228
 		}
5229 5229
 		// End call triggers
5230 5230
 
5231
-        // extrafields
5232
-        $result = $this->deleteExtraFields();
5233
-        if ($result < 0)
5234
-        {
5235
-            $this->db->rollback();
5236
-            return -1;
5237
-        }
5231
+		// extrafields
5232
+		$result = $this->deleteExtraFields();
5233
+		if ($result < 0)
5234
+		{
5235
+			$this->db->rollback();
5236
+			return -1;
5237
+		}
5238 5238
 
5239 5239
 		$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$this->rowid;
5240 5240
 		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
@@ -5249,16 +5249,16 @@  discard block
 block discarded – undo
5249 5249
 		}
5250 5250
 	}
5251 5251
 
5252
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
5252
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
5253 5253
 	/**
5254
-     *	Update DB line fields total_xxx
5254
+	 *	Update DB line fields total_xxx
5255 5255
 	 *	Used by migration
5256 5256
 	 *
5257 5257
 	 *	@return		int		<0 if KO, >0 if OK
5258 5258
 	 */
5259
-    public function update_total()
5259
+	public function update_total()
5260 5260
 	{
5261
-        // phpcs:enable
5261
+		// phpcs:enable
5262 5262
 		$this->db->begin();
5263 5263
 		dol_syslog(get_class($this)."::update_total", LOG_DEBUG);
5264 5264
 
@@ -5289,7 +5289,7 @@  discard block
 block discarded – undo
5289 5289
 		}
5290 5290
 	}
5291 5291
 
5292
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
5292
+	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
5293 5293
 	/**
5294 5294
 	 * Returns situation_percent of the previous line.
5295 5295
 	 * Warning: If invoice is a replacement invoice, this->fk_prev_id is id of the replaced line.
@@ -5298,14 +5298,14 @@  discard block
 block discarded – undo
5298 5298
 	 * @param  bool    $include_credit_note		Include credit note or not
5299 5299
 	 * @return int                     >= 0
5300 5300
 	 */
5301
-    public function get_prev_progress($invoiceid, $include_credit_note = true)
5301
+	public function get_prev_progress($invoiceid, $include_credit_note = true)
5302 5302
 	{
5303
-        // phpcs:enable
5303
+		// phpcs:enable
5304 5304
 		global $invoicecache;
5305 5305
 		if (is_null($this->fk_prev_id) || empty($this->fk_prev_id) || $this->fk_prev_id == "") {
5306 5306
 			return 0;
5307 5307
 		} else {
5308
-		    // If invoice is not a situation invoice, this->fk_prev_id is used for something else
5308
+			// If invoice is not a situation invoice, this->fk_prev_id is used for something else
5309 5309
 			if (!isset($invoicecache[$invoiceid])) {
5310 5310
 				$invoicecache[$invoiceid] = new Facture($this->db);
5311 5311
 				$invoicecache[$invoiceid]->fetch($invoiceid);
@@ -5320,20 +5320,20 @@  discard block
 block discarded – undo
5320 5320
 				$returnPercent = floatval($res['situation_percent']);
5321 5321
 
5322 5322
 				if ($include_credit_note) {
5323
-				    $sql = 'SELECT fd.situation_percent FROM '.MAIN_DB_PREFIX.'facturedet fd';
5324
-				    $sql .= ' JOIN '.MAIN_DB_PREFIX.'facture f ON (f.rowid = fd.fk_facture) ';
5325
-				    $sql .= ' WHERE fd.fk_prev_id ='.$this->fk_prev_id;
5326
-				    $sql .= ' AND f.situation_cycle_ref = '.$invoicecache[$invoiceid]->situation_cycle_ref; // Prevent cycle outed
5327
-				    $sql .= ' AND f.type = '.Facture::TYPE_CREDIT_NOTE;
5328
-
5329
-				    $res = $this->db->query($sql);
5330
-				    if ($res) {
5331
-				        while ($obj = $this->db->fetch_object($res)) {
5332
-				            $returnPercent = $returnPercent + floatval($obj->situation_percent);
5333
-				        }
5334
-				    } else {
5335
-				    	dol_print_error($this->db);
5336
-				    }
5323
+					$sql = 'SELECT fd.situation_percent FROM '.MAIN_DB_PREFIX.'facturedet fd';
5324
+					$sql .= ' JOIN '.MAIN_DB_PREFIX.'facture f ON (f.rowid = fd.fk_facture) ';
5325
+					$sql .= ' WHERE fd.fk_prev_id ='.$this->fk_prev_id;
5326
+					$sql .= ' AND f.situation_cycle_ref = '.$invoicecache[$invoiceid]->situation_cycle_ref; // Prevent cycle outed
5327
+					$sql .= ' AND f.type = '.Facture::TYPE_CREDIT_NOTE;
5328
+
5329
+					$res = $this->db->query($sql);
5330
+					if ($res) {
5331
+						while ($obj = $this->db->fetch_object($res)) {
5332
+							$returnPercent = $returnPercent + floatval($obj->situation_percent);
5333
+						}
5334
+					} else {
5335
+						dol_print_error($this->db);
5336
+					}
5337 5337
 				}
5338 5338
 
5339 5339
 				return $returnPercent;
Please login to merge, or discard this patch.
Braces   +627 added lines, -227 removed lines patch added patch discarded remove patch
@@ -45,8 +45,12 @@  discard block
 block discarded – undo
45 45
 require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
46 46
 require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
47 47
 
48
-if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
49
-if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
48
+if (!empty($conf->accounting->enabled)) {
49
+	require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
50
+}
51
+if (!empty($conf->accounting->enabled)) {
52
+	require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
53
+}
50 54
 
51 55
 /**
52 56
  *	Class to manage invoices
@@ -413,18 +417,27 @@  discard block
 block discarded – undo
413 417
 		$error = 0;
414 418
 
415 419
 		// Clean parameters
416
-		if (empty($this->type)) $this->type = self::TYPE_STANDARD;
420
+		if (empty($this->type)) {
421
+			$this->type = self::TYPE_STANDARD;
422
+		}
417 423
 		$this->ref_client = trim($this->ref_client);
418 424
 		$this->note = (isset($this->note) ? trim($this->note) : trim($this->note_private)); // deprecated
419 425
 		$this->note_private = (isset($this->note_private) ? trim($this->note_private) : trim($this->note_private));
420 426
 		$this->note_public = trim($this->note_public);
421
-		if (!$this->cond_reglement_id) $this->cond_reglement_id = 0;
422
-		if (!$this->mode_reglement_id) $this->mode_reglement_id = 0;
427
+		if (!$this->cond_reglement_id) {
428
+			$this->cond_reglement_id = 0;
429
+		}
430
+		if (!$this->mode_reglement_id) {
431
+			$this->mode_reglement_id = 0;
432
+		}
423 433
 		$this->brouillon = 1;
424 434
 
425 435
 		// Multicurrency (test on $this->multicurrency_tx because we should take the default rate only if not using origin rate)
426
-		if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $this->date);
427
-		else $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
436
+		if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
437
+			list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $this->date);
438
+		} else {
439
+			$this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
440
+		}
428 441
 		if (empty($this->fk_multicurrency))
429 442
 		{
430 443
 			$this->multicurrency_code = $conf->currency;
@@ -473,10 +486,12 @@  discard block
 block discarded – undo
473 486
 			$nextdatewhen = dol_time_plus_duree($originaldatewhen, $_facrec->frequency, $_facrec->unit_frequency);
474 487
 			$previousdaynextdatewhen = dol_time_plus_duree($nextdatewhen, -1, 'd');
475 488
 
476
-			if (!empty($_facrec->frequency))  // Invoice are created on same thirdparty than template when there is a recurrence, but not necessarly when there is no recurrence.
489
+			if (!empty($_facrec->frequency)) {
490
+				// Invoice are created on same thirdparty than template when there is a recurrence, but not necessarly when there is no recurrence.
477 491
 			{
478 492
 				$this->socid = $_facrec->socid;
479 493
 			}
494
+			}
480 495
 			$this->entity            = $_facrec->entity; // Invoice created in same entity than template
481 496
 
482 497
 			// Fields coming from GUI (priority on template). TODO Value of template should be used as default value on GUI so we can use here always value from GUI
@@ -499,7 +514,9 @@  discard block
 block discarded – undo
499 514
 			$this->location_incoterms = $_facrec->location_incoterms;
500 515
 
501 516
 			// Clean parameters
502
-			if (!$this->type) $this->type = self::TYPE_STANDARD;
517
+			if (!$this->type) {
518
+				$this->type = self::TYPE_STANDARD;
519
+			}
503 520
 			$this->ref_client = trim($this->ref_client);
504 521
 			$this->note_public = trim($this->note_public);
505 522
 			$this->note_private = trim($this->note_private);
@@ -508,7 +525,9 @@  discard block
 block discarded – undo
508 525
 		    $this->array_options = $_facrec->array_options;
509 526
 
510 527
 			//if (! $this->remise) $this->remise = 0;
511
-			if (!$this->mode_reglement_id) $this->mode_reglement_id = 0;
528
+			if (!$this->mode_reglement_id) {
529
+				$this->mode_reglement_id = 0;
530
+			}
512 531
 			$this->brouillon = 1;
513 532
 
514 533
 			$this->linked_objects = $_facrec->linkedObjectsIds;
@@ -521,7 +540,9 @@  discard block
 block discarded – undo
521 540
 			if ($_facrec->frequency > 0)
522 541
 			{
523 542
 			    dol_syslog("This is a recurring invoice so we set date_last_gen and next date_when");
524
-			    if (empty($_facrec->date_when)) $_facrec->date_when = $now;
543
+			    if (empty($_facrec->date_when)) {
544
+			    	$_facrec->date_when = $now;
545
+			    }
525 546
                 $next_date = $_facrec->getNextDate(); // Calculate next date
526 547
                 $result = $_facrec->setValueFrom('date_last_gen', $now, '', null, 'date', '', $user, '');
527 548
                 //$_facrec->setValueFrom('nb_gen_done', $_facrec->nb_gen_done + 1);		// Not required, +1 already included into setNextDate when second param is 1.
@@ -532,8 +553,14 @@  discard block
 block discarded – undo
532 553
 			$outputlangs = $langs;
533 554
 			$newlang = '';
534 555
 
535
-			if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->thirdparty->default_lang)) $newlang = $this->thirdparty->default_lang; // for proposal, order, invoice, ...
536
-			if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->default_lang)) $newlang = $this->default_lang; // for thirdparty
556
+			if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->thirdparty->default_lang)) {
557
+				$newlang = $this->thirdparty->default_lang;
558
+			}
559
+			// for proposal, order, invoice, ...
560
+			if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->default_lang)) {
561
+				$newlang = $this->default_lang;
562
+			}
563
+			// for thirdparty
537 564
 			if (!empty($newlang))
538 565
 			{
539 566
 			    $outputlangs = new Translate("", $conf);
@@ -655,11 +682,16 @@  discard block
 block discarded – undo
655 682
 			$sql = 'UPDATE '.MAIN_DB_PREFIX."facture SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".$this->id;
656 683
 
657 684
 			$resql = $this->db->query($sql);
658
-			if (!$resql) $error++;
685
+			if (!$resql) {
686
+				$error++;
687
+			}
659 688
 
660
-			if (!empty($this->linkedObjectsIds) && empty($this->linked_objects))	// To use new linkedObjectsIds instead of old linked_objects
689
+			if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
690
+				// To use new linkedObjectsIds instead of old linked_objects
661 691
 			{
662
-				$this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds
692
+				$this->linked_objects = $this->linkedObjectsIds;
693
+			}
694
+			// TODO Replace linked_objects with linkedObjectsIds
663 695
 			}
664 696
 
665 697
 			// Add object linked
@@ -667,11 +699,13 @@  discard block
 block discarded – undo
667 699
 			{
668 700
 				foreach ($this->linked_objects as $origin => $tmp_origin_id)
669 701
 				{
670
-				    if (is_array($tmp_origin_id))       // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
702
+				    if (is_array($tmp_origin_id)) {
703
+				    	// New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
671 704
 				    {
672 705
 				        foreach ($tmp_origin_id as $origin_id)
673 706
 				        {
674 707
 				            $ret = $this->add_object_linked($origin, $origin_id);
708
+				    }
675 709
 				            if (!$ret)
676 710
 				            {
677 711
 				                $this->error = $this->db->lasterror();
@@ -692,13 +726,17 @@  discard block
 block discarded – undo
692 726
 			}
693 727
 
694 728
 			// Propagate contacts
695
-			if (!$error && $this->id && !empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN) && !empty($this->origin) && !empty($this->origin_id))   // Get contact from origin object
729
+			if (!$error && $this->id && !empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN) && !empty($this->origin) && !empty($this->origin_id)) {
730
+				// Get contact from origin object
696 731
 			{
697 732
 				$originforcontact = $this->origin;
733
+			}
698 734
 				$originidforcontact = $this->origin_id;
699
-				if ($originforcontact == 'shipping')     // shipment and order share the same contacts. If creating from shipment we take data of order
735
+				if ($originforcontact == 'shipping') {
736
+					// shipment and order share the same contacts. If creating from shipment we take data of order
700 737
 				{
701 738
 				    require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
739
+				}
702 740
 				    $exp = new Expedition($this->db);
703 741
 				    $exp->fetch($this->origin_id);
704 742
 				    $exp->fetchObjectLinked(null, '', null, '', 'OR', 1, 'sourcetype', 0);
@@ -707,8 +745,11 @@  discard block
 block discarded – undo
707 745
 				        foreach ($exp->linkedObjectsIds['commande'] as $key => $value)
708 746
 				        {
709 747
 				            $originforcontact = 'commande';
710
-				            if (is_object($value)) $originidforcontact = $value->id;
711
-				            else $originidforcontact = $value;
748
+				            if (is_object($value)) {
749
+				            	$originidforcontact = $value->id;
750
+				            } else {
751
+				            	$originidforcontact = $value;
752
+				            }
712 753
 				            break; // We take first one
713 754
 				        }
714 755
 				    }
@@ -725,15 +766,19 @@  discard block
 block discarded – undo
725 766
 				        //print $objcontact->code.'-'.$objcontact->source.'-'.$objcontact->fk_socpeople."\n";
726 767
 				        $this->add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source); // May failed because of duplicate key or because code of contact type does not exists for new object
727 768
 				    }
728
-				} else dol_print_error($resqlcontact);
769
+				} else {
770
+					dol_print_error($resqlcontact);
771
+				}
729 772
 			}
730 773
 
731 774
 			/*
732 775
 			 *  Insert lines of invoices, if not from template invoice, into database
733 776
 			 */
734
-			if (!$error && empty($this->fac_rec) && count($this->lines) && is_object($this->lines[0]))	// If this->lines is array of InvoiceLines (preferred mode)
777
+			if (!$error && empty($this->fac_rec) && count($this->lines) && is_object($this->lines[0])) {
778
+				// If this->lines is array of InvoiceLines (preferred mode)
735 779
 			{
736 780
 				$fk_parent_line = 0;
781
+			}
737 782
 
738 783
 				dol_syslog("There is ".count($this->lines)." lines that are invoice lines objects");
739 784
 				foreach ($this->lines as $i => $val)
@@ -745,14 +790,18 @@  discard block
 block discarded – undo
745 790
 					$newinvoiceline->origin_id = $this->lines[$i]->id;
746 791
 
747 792
 					// Auto set date of service ?
748
-					if ($this->lines[$i]->date_start_fill == 1 && $originaldatewhen)			// $originaldatewhen is defined when generating from recurring invoice only
793
+					if ($this->lines[$i]->date_start_fill == 1 && $originaldatewhen) {
794
+						// $originaldatewhen is defined when generating from recurring invoice only
749 795
 					{
750 796
 						$newinvoiceline->date_start = $originaldatewhen;
751 797
 					}
752
-					if ($this->lines[$i]->date_end_fill == 1 && $previousdaynextdatewhen)	// $previousdaynextdatewhen is defined when generating from recurring invoice only
798
+					}
799
+					if ($this->lines[$i]->date_end_fill == 1 && $previousdaynextdatewhen) {
800
+						// $previousdaynextdatewhen is defined when generating from recurring invoice only
753 801
 					{
754 802
 						$newinvoiceline->date_end = $previousdaynextdatewhen;
755 803
 					}
804
+					}
756 805
 
757 806
 					if ($result >= 0)
758 807
 					{
@@ -785,9 +834,11 @@  discard block
 block discarded – undo
785 834
 						break;
786 835
 					}
787 836
 				}
788
-			} elseif (!$error && empty($this->fac_rec)) 		// If this->lines is an array of invoice line arrays
837
+			} elseif (!$error && empty($this->fac_rec)) {
838
+				// If this->lines is an array of invoice line arrays
789 839
 			{
790 840
 				$fk_parent_line = 0;
841
+			}
791 842
 
792 843
 				dol_syslog("There is ".count($this->lines)." lines that are array lines");
793 844
 
@@ -797,7 +848,9 @@  discard block
 block discarded – undo
797 848
 
798 849
                 	// Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array
799 850
 				    //if (! is_object($line)) $line=json_decode(json_encode($line), false);  // convert recursively array into object.
800
-                	if (!is_object($line)) $line = (object) $line;
851
+                	if (!is_object($line)) {
852
+                		$line = (object) $line;
853
+                	}
801 854
 
802 855
 				    if ($result >= 0)
803 856
 					{
@@ -808,7 +861,9 @@  discard block
 block discarded – undo
808 861
 
809 862
 						// Complete vat rate with code
810 863
 						$vatrate = $line->tva_tx;
811
-						if ($line->vat_src_code && !preg_match('/\(.*\)/', $vatrate)) $vatrate .= ' ('.$line->vat_src_code.')';
864
+						if ($line->vat_src_code && !preg_match('/\(.*\)/', $vatrate)) {
865
+							$vatrate .= ' ('.$line->vat_src_code.')';
866
+						}
812 867
 
813 868
 						if (!empty($conf->global->MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION)) {
814 869
 							$originid = $line->origin_id;
@@ -888,7 +943,9 @@  discard block
 block discarded – undo
888 943
 					*/
889 944
 					$tva_tx = $_facrec->lines[$i]->tva_tx.($_facrec->lines[$i]->vat_src_code ? '('.$_facrec->lines[$i]->vat_src_code.')' : '');
890 945
 					$tva_npr = $_facrec->lines[$i]->info_bits;
891
-					if (empty($tva_tx)) $tva_npr = 0;
946
+					if (empty($tva_tx)) {
947
+						$tva_npr = 0;
948
+					}
892 949
 					$localtax1_tx = $_facrec->lines[$i]->localtax1_tx;
893 950
 					$localtax2_tx = $_facrec->lines[$i]->localtax2_tx;
894 951
 
@@ -904,9 +961,11 @@  discard block
 block discarded – undo
904 961
                         // If margin module defined on costprice, we try the costprice
905 962
                         // If not defined or if module margin defined and pmp and stock module enabled, we try pmp price
906 963
                         // else we get the best supplier price
907
-                        if ($conf->global->MARGIN_TYPE == 'costprice' && !empty($producttmp->cost_price)) $buyprice = $producttmp->cost_price;
908
-                        elseif (!empty($conf->stock->enabled) && ($conf->global->MARGIN_TYPE == 'costprice' || $conf->global->MARGIN_TYPE == 'pmp') && !empty($producttmp->pmp)) $buyprice = $producttmp->pmp;
909
-                        else {
964
+                        if ($conf->global->MARGIN_TYPE == 'costprice' && !empty($producttmp->cost_price)) {
965
+                        	$buyprice = $producttmp->cost_price;
966
+                        } elseif (!empty($conf->stock->enabled) && ($conf->global->MARGIN_TYPE == 'costprice' || $conf->global->MARGIN_TYPE == 'pmp') && !empty($producttmp->pmp)) {
967
+                        	$buyprice = $producttmp->pmp;
968
+                        } else {
910 969
                             if ($producttmp->find_min_price_product_fournisseur($_facrec->lines[$i]->fk_product) > 0)
911 970
                             {
912 971
                                 if ($producttmp->product_fourn_price_id > 0)
@@ -969,14 +1028,18 @@  discard block
 block discarded – undo
969 1028
 					if (!$error)
970 1029
 					{
971 1030
 					    $result = $this->insertExtraFields();
972
-					    if ($result < 0) $error++;
1031
+					    if ($result < 0) {
1032
+					    	$error++;
1033
+					    }
973 1034
 					}
974 1035
 
975 1036
 			        if (!$error && !$notrigger)
976 1037
 			        {
977 1038
 			            // Call trigger
978 1039
 			            $result = $this->call_trigger('BILL_CREATE', $user);
979
-			            if ($result < 0) $error++;
1040
+			            if ($result < 0) {
1041
+			            	$error++;
1042
+			            }
980 1043
 			            // End call triggers
981 1044
 			        }
982 1045
 
@@ -1161,9 +1224,11 @@  discard block
 block discarded – undo
1161 1224
 		// Loop on each line of new invoice
1162 1225
 		foreach ($object->lines as $i => $line)
1163 1226
 		{
1164
-		    if (($object->lines[$i]->info_bits & 0x02) == 0x02)	// We do not clone line of discounts
1227
+		    if (($object->lines[$i]->info_bits & 0x02) == 0x02) {
1228
+		    	// We do not clone line of discounts
1165 1229
 			{
1166 1230
 			    unset($object->lines[$i]);
1231
+		    }
1167 1232
 			    unset($object->products[$i]); // Tant que products encore utilise
1168 1233
 			}
1169 1234
 						// Bloc to update dates of service (month by month only if previously filled at 1d near start or end of month)
@@ -1195,17 +1260,20 @@  discard block
 block discarded – undo
1195 1260
 		// Create clone
1196 1261
 		$object->context['createfromclone'] = 'createfromclone';
1197 1262
 		$result = $object->create($user);
1198
-		if ($result < 0) $error++;
1199
-		else {
1263
+		if ($result < 0) {
1264
+			$error++;
1265
+		} else {
1200 1266
 			// copy internal contacts
1201
-		    if ($object->copy_linked_contact($this, 'internal') < 0)
1202
-				$error++;
1267
+		    if ($object->copy_linked_contact($this, 'internal') < 0) {
1268
+		    				$error++;
1269
+		    }
1203 1270
 
1204 1271
 			// copy external contacts if same company
1205 1272
 			elseif ($this->socid == $object->socid)
1206 1273
 			{
1207
-			    if ($object->copy_linked_contact($this, 'external') < 0)
1208
-					$error++;
1274
+			    if ($object->copy_linked_contact($this, 'external') < 0) {
1275
+			    					$error++;
1276
+			    }
1209 1277
 			}
1210 1278
 		}
1211 1279
 
@@ -1217,7 +1285,9 @@  discard block
 block discarded – undo
1217 1285
 				$parameters = array('objFrom'=>$this);
1218 1286
 				$action = '';
1219 1287
 				$reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1220
-				if ($reshook < 0) $error++;
1288
+				if ($reshook < 0) {
1289
+					$error++;
1290
+				}
1221 1291
 			}
1222 1292
 		}
1223 1293
 
@@ -1296,8 +1366,9 @@  discard block
 block discarded – undo
1296 1366
 
1297 1367
             // get extrafields from original line
1298 1368
 			$object->lines[$i]->fetch_optionals();
1299
-			foreach ($object->lines[$i]->array_options as $options_key => $value)
1300
-				$line->array_options[$options_key] = $value;
1369
+			foreach ($object->lines[$i]->array_options as $options_key => $value) {
1370
+							$line->array_options[$options_key] = $value;
1371
+			}
1301 1372
 
1302 1373
 			$this->lines[$i] = $line;
1303 1374
 		}
@@ -1328,8 +1399,9 @@  discard block
 block discarded – undo
1328 1399
 
1329 1400
         // get extrafields from original line
1330 1401
 		$object->fetch_optionals();
1331
-		foreach ($object->array_options as $options_key => $value)
1332
-			$this->array_options[$options_key] = $value;
1402
+		foreach ($object->array_options as $options_key => $value) {
1403
+					$this->array_options[$options_key] = $value;
1404
+		}
1333 1405
 
1334 1406
 		// Possibility to add external linked objects with hooks
1335 1407
 		$this->linked_objects[$this->origin] = $this->origin_id;
@@ -1348,13 +1420,19 @@  discard block
 block discarded – undo
1348 1420
 			$parameters = array('objFrom'=>$object);
1349 1421
 			$action = '';
1350 1422
 			$reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1351
-			if ($reshook < 0) $error++;
1423
+			if ($reshook < 0) {
1424
+				$error++;
1425
+			}
1352 1426
 
1353 1427
 			if (!$error)
1354 1428
 			{
1355 1429
 				return 1;
1356
-			} else return -1;
1357
-		} else return -1;
1430
+			} else {
1431
+				return -1;
1432
+			}
1433
+		} else {
1434
+			return -1;
1435
+		}
1358 1436
 	}
1359 1437
 
1360 1438
 	/**
@@ -1375,55 +1453,96 @@  discard block
 block discarded – undo
1375 1453
 	{
1376 1454
 		global $langs, $conf, $user, $mysoc;
1377 1455
 
1378
-		if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
1456
+		if (!empty($conf->dol_no_mouse_hover)) {
1457
+			$notooltip = 1;
1458
+		}
1459
+		// Force disable tooltips
1379 1460
 
1380 1461
 		$result = '';
1381 1462
 
1382
-		if ($option == 'withdraw') $url = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$this->id;
1383
-		else $url = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$this->id;
1463
+		if ($option == 'withdraw') {
1464
+			$url = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$this->id;
1465
+		} else {
1466
+			$url = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$this->id;
1467
+		}
1384 1468
 
1385
-        if (!$user->rights->facture->lire)
1386
-            $option = 'nolink';
1469
+        if (!$user->rights->facture->lire) {
1470
+                    $option = 'nolink';
1471
+        }
1387 1472
 
1388 1473
 		if ($option !== 'nolink')
1389 1474
 		{
1390 1475
 			// Add param to save lastsearch_values or not
1391 1476
 			$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1392
-			if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
1393
-			if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
1477
+			if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1478
+				$add_save_lastsearch_values = 1;
1479
+			}
1480
+			if ($add_save_lastsearch_values) {
1481
+				$url .= '&save_lastsearch_values=1';
1482
+			}
1394 1483
 		}
1395 1484
 
1396
-		if ($short) return $url;
1485
+		if ($short) {
1486
+			return $url;
1487
+		}
1397 1488
 
1398 1489
 		$picto = $this->picto;
1399
-		if ($this->type == self::TYPE_REPLACEMENT) $picto .= 'r'; // Replacement invoice
1400
-		if ($this->type == self::TYPE_CREDIT_NOTE) $picto .= 'a'; // Credit note
1401
-		if ($this->type == self::TYPE_DEPOSIT) $picto .= 'd'; // Deposit invoice
1490
+		if ($this->type == self::TYPE_REPLACEMENT) {
1491
+			$picto .= 'r';
1492
+		}
1493
+		// Replacement invoice
1494
+		if ($this->type == self::TYPE_CREDIT_NOTE) {
1495
+			$picto .= 'a';
1496
+		}
1497
+		// Credit note
1498
+		if ($this->type == self::TYPE_DEPOSIT) {
1499
+			$picto .= 'd';
1500
+		}
1501
+		// Deposit invoice
1402 1502
         $label = '';
1403 1503
 
1404 1504
         if ($user->rights->facture->lire) {
1405 1505
             $label = '<u>'.$langs->trans("Invoice").'</u>';
1406
-            if ($this->type == self::TYPE_REPLACEMENT) $label = '<u>'.$langs->transnoentitiesnoconv("ReplacementInvoice").'</u>';
1407
-            if ($this->type == self::TYPE_CREDIT_NOTE) $label = '<u>'.$langs->transnoentitiesnoconv("CreditNote").'</u>';
1408
-            if ($this->type == self::TYPE_DEPOSIT)     $label = '<u>'.$langs->transnoentitiesnoconv("Deposit").'</u>';
1409
-            if ($this->type == self::TYPE_SITUATION)   $label = '<u>'.$langs->transnoentitiesnoconv("InvoiceSituation").'</u>';
1410
-            if (!empty($this->ref))
1411
-                $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1412
-            if (!empty($this->ref_client))
1413
-                $label .= '<br><b>'.$langs->trans('RefCustomer').':</b> '.$this->ref_client;
1414
-            if (!empty($this->date))
1415
-              	$label .= '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->date, 'day');
1416
-            if (!empty($this->total_ht))
1417
-                $label .= '<br><b>'.$langs->trans('AmountHT').':</b> '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
1418
-            if (!empty($this->total_tva))
1419
-                $label .= '<br><b>'.$langs->trans('AmountVAT').':</b> '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
1420
-            if (!empty($this->total_localtax1) && $this->total_localtax1 != 0)		// We keep test != 0 because $this->total_localtax1 can be '0.00000000'
1506
+            if ($this->type == self::TYPE_REPLACEMENT) {
1507
+            	$label = '<u>'.$langs->transnoentitiesnoconv("ReplacementInvoice").'</u>';
1508
+            }
1509
+            if ($this->type == self::TYPE_CREDIT_NOTE) {
1510
+            	$label = '<u>'.$langs->transnoentitiesnoconv("CreditNote").'</u>';
1511
+            }
1512
+            if ($this->type == self::TYPE_DEPOSIT) {
1513
+            	$label = '<u>'.$langs->transnoentitiesnoconv("Deposit").'</u>';
1514
+            }
1515
+            if ($this->type == self::TYPE_SITUATION) {
1516
+            	$label = '<u>'.$langs->transnoentitiesnoconv("InvoiceSituation").'</u>';
1517
+            }
1518
+            if (!empty($this->ref)) {
1519
+                            $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1520
+            }
1521
+            if (!empty($this->ref_client)) {
1522
+                            $label .= '<br><b>'.$langs->trans('RefCustomer').':</b> '.$this->ref_client;
1523
+            }
1524
+            if (!empty($this->date)) {
1525
+                          	$label .= '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->date, 'day');
1526
+            }
1527
+            if (!empty($this->total_ht)) {
1528
+                            $label .= '<br><b>'.$langs->trans('AmountHT').':</b> '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
1529
+            }
1530
+            if (!empty($this->total_tva)) {
1531
+                            $label .= '<br><b>'.$langs->trans('AmountVAT').':</b> '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
1532
+            }
1533
+            if (!empty($this->total_localtax1) && $this->total_localtax1 != 0) {
1534
+            	// We keep test != 0 because $this->total_localtax1 can be '0.00000000'
1421 1535
             	$label .= '<br><b>'.$langs->transcountry('AmountLT1', $mysoc->country_code).':</b> '.price($this->total_localtax1, 0, $langs, 0, -1, -1, $conf->currency);
1422
-            if (!empty($this->total_localtax2) && $this->total_localtax2 != 0)
1423
-            	$label .= '<br><b>'.$langs->transcountry('AmountLT2', $mysoc->country_code).':</b> '.price($this->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency);
1424
-            if (!empty($this->total_ttc))
1425
-                $label .= '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
1426
-    		if ($moretitle) $label .= ' - '.$moretitle;
1536
+            }
1537
+            if (!empty($this->total_localtax2) && $this->total_localtax2 != 0) {
1538
+                        	$label .= '<br><b>'.$langs->transcountry('AmountLT2', $mysoc->country_code).':</b> '.price($this->total_localtax2, 0, $langs, 0, -1, -1, $conf->currency);
1539
+            }
1540
+            if (!empty($this->total_ttc)) {
1541
+                            $label .= '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
1542
+            }
1543
+    		if ($moretitle) {
1544
+    			$label .= ' - '.$moretitle;
1545
+    		}
1427 1546
     		if (isset($this->statut) && isset($this->alreadypaid)) {
1428 1547
     			$label .= '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5, $this->alreadypaid);
1429 1548
     		}
@@ -1451,8 +1570,12 @@  discard block
 block discarded – undo
1451 1570
         }
1452 1571
 
1453 1572
 		$result .= $linkstart;
1454
-		if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1455
-		if ($withpicto != 2) $result .= ($max ?dol_trunc($this->ref, $max) : $this->ref);
1573
+		if ($withpicto) {
1574
+			$result .= img_object(($notooltip ? '' : $label), $picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1575
+		}
1576
+		if ($withpicto != 2) {
1577
+			$result .= ($max ?dol_trunc($this->ref, $max) : $this->ref);
1578
+		}
1456 1579
 		$result .= $linkend;
1457 1580
 
1458 1581
 		if ($addlinktonotes)
@@ -1489,7 +1612,9 @@  discard block
 block discarded – undo
1489 1612
 	{
1490 1613
 		global $conf;
1491 1614
 
1492
-		if (empty($rowid) && empty($ref) && empty($ref_ext)) return -1;
1615
+		if (empty($rowid) && empty($ref) && empty($ref_ext)) {
1616
+			return -1;
1617
+		}
1493 1618
 
1494 1619
 		$sql = 'SELECT f.rowid,f.entity,f.ref,f.ref_client,f.ref_ext,f.ref_int,f.type,f.fk_soc';
1495 1620
 		$sql .= ', f.tva, f.localtax1, f.localtax2, f.total, f.total_ttc, f.revenuestamp';
@@ -1516,12 +1641,20 @@  discard block
 block discarded – undo
1516 1641
 		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id';
1517 1642
 		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON f.fk_incoterms = i.rowid';
1518 1643
 
1519
-		if ($rowid) $sql .= " WHERE f.rowid=".$rowid;
1520
-		else {
1644
+		if ($rowid) {
1645
+			$sql .= " WHERE f.rowid=".$rowid;
1646
+		} else {
1521 1647
 			$sql .= ' WHERE f.entity IN ('.getEntity('invoice').')'; // Dont't use entity if you use rowid
1522
-			if ($ref)     $sql .= " AND f.ref='".$this->db->escape($ref)."'";
1523
-			if ($ref_ext) $sql .= " AND f.ref_ext='".$this->db->escape($ref_ext)."'";
1524
-			if ($notused) $sql .= " AND f.ref_int='".$this->db->escape($notused)."'"; // deprecated
1648
+			if ($ref) {
1649
+				$sql .= " AND f.ref='".$this->db->escape($ref)."'";
1650
+			}
1651
+			if ($ref_ext) {
1652
+				$sql .= " AND f.ref_ext='".$this->db->escape($ref_ext)."'";
1653
+			}
1654
+			if ($notused) {
1655
+				$sql .= " AND f.ref_int='".$this->db->escape($notused)."'";
1656
+			}
1657
+			// deprecated
1525 1658
 		}
1526 1659
 
1527 1660
 		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
@@ -1613,7 +1746,9 @@  discard block
 block discarded – undo
1613 1746
 					$this->fetchPreviousNextSituationInvoice();
1614 1747
 				}
1615 1748
 
1616
-				if ($this->statut == self::STATUS_DRAFT)	$this->brouillon = 1;
1749
+				if ($this->statut == self::STATUS_DRAFT) {
1750
+					$this->brouillon = 1;
1751
+				}
1617 1752
 
1618 1753
 				// Retreive all extrafield
1619 1754
 				// fetch optionals attributes and labels
@@ -1816,18 +1951,43 @@  discard block
 block discarded – undo
1816 1951
 		$error = 0;
1817 1952
 
1818 1953
 		// Clean parameters
1819
-		if (empty($this->type)) $this->type = self::TYPE_STANDARD;
1820
-		if (isset($this->ref)) $this->ref = trim($this->ref);
1821
-		if (isset($this->ref_client)) $this->ref_client = trim($this->ref_client);
1822
-		if (isset($this->increment)) $this->increment = trim($this->increment);
1823
-		if (isset($this->close_code)) $this->close_code = trim($this->close_code);
1824
-		if (isset($this->close_note)) $this->close_note = trim($this->close_note);
1825
-		if (isset($this->note) || isset($this->note_private)) $this->note = (isset($this->note) ? trim($this->note) : trim($this->note_private)); // deprecated
1826
-		if (isset($this->note) || isset($this->note_private)) $this->note_private = (isset($this->note_private) ? trim($this->note_private) : trim($this->note));
1827
-		if (isset($this->note_public)) $this->note_public = trim($this->note_public);
1828
-		if (isset($this->modelpdf)) $this->modelpdf = trim($this->modelpdf);
1829
-		if (isset($this->import_key)) $this->import_key = trim($this->import_key);
1830
-		if (isset($this->retained_warranty)) $this->retained_warranty = floatval($this->retained_warranty);
1954
+		if (empty($this->type)) {
1955
+			$this->type = self::TYPE_STANDARD;
1956
+		}
1957
+		if (isset($this->ref)) {
1958
+			$this->ref = trim($this->ref);
1959
+		}
1960
+		if (isset($this->ref_client)) {
1961
+			$this->ref_client = trim($this->ref_client);
1962
+		}
1963
+		if (isset($this->increment)) {
1964
+			$this->increment = trim($this->increment);
1965
+		}
1966
+		if (isset($this->close_code)) {
1967
+			$this->close_code = trim($this->close_code);
1968
+		}
1969
+		if (isset($this->close_note)) {
1970
+			$this->close_note = trim($this->close_note);
1971
+		}
1972
+		if (isset($this->note) || isset($this->note_private)) {
1973
+			$this->note = (isset($this->note) ? trim($this->note) : trim($this->note_private));
1974
+		}
1975
+		// deprecated
1976
+		if (isset($this->note) || isset($this->note_private)) {
1977
+			$this->note_private = (isset($this->note_private) ? trim($this->note_private) : trim($this->note));
1978
+		}
1979
+		if (isset($this->note_public)) {
1980
+			$this->note_public = trim($this->note_public);
1981
+		}
1982
+		if (isset($this->modelpdf)) {
1983
+			$this->modelpdf = trim($this->modelpdf);
1984
+		}
1985
+		if (isset($this->import_key)) {
1986
+			$this->import_key = trim($this->import_key);
1987
+		}
1988
+		if (isset($this->retained_warranty)) {
1989
+			$this->retained_warranty = floatval($this->retained_warranty);
1990
+		}
1831 1991
 
1832 1992
 
1833 1993
 		// Check parameters
@@ -1896,7 +2056,9 @@  discard block
 block discarded – undo
1896 2056
 		{
1897 2057
 			// Call trigger
1898 2058
 			$result = $this->call_trigger('BILL_MODIFY', $user);
1899
-			if ($result < 0) $error++;
2059
+			if ($result < 0) {
2060
+				$error++;
2061
+			}
1900 2062
 			// End call triggers
1901 2063
 		}
1902 2064
 
@@ -1939,9 +2101,11 @@  discard block
 block discarded – undo
1939 2101
 
1940 2102
 		if ($result > 0)
1941 2103
 		{
1942
-			if ($remise->fk_facture)	// Protection against multiple submission
2104
+			if ($remise->fk_facture) {
2105
+				// Protection against multiple submission
1943 2106
 			{
1944 2107
 				$this->error = $langs->trans("ErrorDiscountAlreadyUsed");
2108
+			}
1945 2109
 				$this->db->rollback();
1946 2110
 				return -5;
1947 2111
 			}
@@ -2030,9 +2194,11 @@  discard block
 block discarded – undo
2030 2194
 		$this->db->begin();
2031 2195
 
2032 2196
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
2033
-		if (empty($ref_client))
2034
-			$sql .= ' SET ref_client = NULL';
2035
-		else $sql .= ' SET ref_client = \''.$this->db->escape($ref_client).'\'';
2197
+		if (empty($ref_client)) {
2198
+					$sql .= ' SET ref_client = NULL';
2199
+		} else {
2200
+			$sql .= ' SET ref_client = \''.$this->db->escape($ref_client).'\'';
2201
+		}
2036 2202
 		$sql .= ' WHERE rowid = '.$this->id;
2037 2203
 
2038 2204
 		dol_syslog(__METHOD__.' this->id='.$this->id.', ref_client='.$ref_client, LOG_DEBUG);
@@ -2052,7 +2218,9 @@  discard block
 block discarded – undo
2052 2218
 		{
2053 2219
 			// Call trigger
2054 2220
 			$result = $this->call_trigger('BILL_MODIFY', $user);
2055
-			if ($result < 0) $error++;
2221
+			if ($result < 0) {
2222
+				$error++;
2223
+			}
2056 2224
 			// End call triggers
2057 2225
 		}
2058 2226
 
@@ -2093,7 +2261,9 @@  discard block
 block discarded – undo
2093 2261
 		// Test to avoid invoice deletion (allowed if draft)
2094 2262
 		$result = $this->is_erasable();
2095 2263
 
2096
-		if ($result <= 0) return 0;
2264
+		if ($result <= 0) {
2265
+			return 0;
2266
+		}
2097 2267
 
2098 2268
 		$error = 0;
2099 2269
 
@@ -2103,7 +2273,9 @@  discard block
 block discarded – undo
2103 2273
 		{
2104 2274
             // Call trigger
2105 2275
             $result = $this->call_trigger('BILL_DELETE', $user);
2106
-            if ($result < 0) $error++;
2276
+            if ($result < 0) {
2277
+            	$error++;
2278
+            }
2107 2279
             // End call triggers
2108 2280
 		}
2109 2281
 
@@ -2121,7 +2293,9 @@  discard block
 block discarded – undo
2121 2293
 		{
2122 2294
 			// Delete linked object
2123 2295
 			$res = $this->deleteObjectLinked();
2124
-			if ($res < 0) $error++;
2296
+			if ($res < 0) {
2297
+				$error++;
2298
+			}
2125 2299
 		}
2126 2300
 
2127 2301
 		if (!$error)
@@ -2170,8 +2344,12 @@  discard block
 block discarded – undo
2170 2344
 						$mouvP = new MouvementStock($this->db);
2171 2345
 						$mouvP->origin = &$this;
2172 2346
 						// We decrease stock for product
2173
-						if ($this->type == self::TYPE_CREDIT_NOTE) $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceDeleteDolibarr", $this->ref));
2174
-						else $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans("InvoiceDeleteDolibarr", $this->ref)); // we use 0 for price, to not change the weighted average value
2347
+						if ($this->type == self::TYPE_CREDIT_NOTE) {
2348
+							$result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceDeleteDolibarr", $this->ref));
2349
+						} else {
2350
+							$result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans("InvoiceDeleteDolibarr", $this->ref));
2351
+						}
2352
+						// we use 0 for price, to not change the weighted average value
2175 2353
 					}
2176 2354
 				}
2177 2355
 			}
@@ -2200,13 +2378,17 @@  discard block
 block discarded – undo
2200 2378
 					{
2201 2379
 						$dir = $conf->facture->dir_output."/".$ref;
2202 2380
 						$file = $conf->facture->dir_output."/".$ref."/".$ref.".pdf";
2203
-						if (file_exists($file))	// We must delete all files before deleting directory
2381
+						if (file_exists($file)) {
2382
+							// We must delete all files before deleting directory
2204 2383
 						{
2205 2384
 							$ret = dol_delete_preview($this);
2385
+						}
2206 2386
 
2207
-							if (!dol_delete_file($file, 0, 0, 0, $this)) // For triggers
2387
+							if (!dol_delete_file($file, 0, 0, 0, $this)) {
2388
+								// For triggers
2208 2389
 							{
2209 2390
 								$langs->load("errors");
2391
+							}
2210 2392
 								$this->error = $langs->trans("ErrorFailToDeleteFile", $file);
2211 2393
 								$this->db->rollback();
2212 2394
 								return 0;
@@ -2214,9 +2396,11 @@  discard block
 block discarded – undo
2214 2396
 						}
2215 2397
 						if (file_exists($dir))
2216 2398
 						{
2217
-							if (!dol_delete_dir_recursive($dir)) // For remove dir and meta
2399
+							if (!dol_delete_dir_recursive($dir)) {
2400
+								// For remove dir and meta
2218 2401
 							{
2219 2402
 								$langs->load("errors");
2403
+							}
2220 2404
 								$this->error = $langs->trans("ErrorFailToDeleteDir", $dir);
2221 2405
 								$this->db->rollback();
2222 2406
 								return 0;
@@ -2267,9 +2451,15 @@  discard block
 block discarded – undo
2267 2451
 
2268 2452
 			$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture SET';
2269 2453
 			$sql .= ' fk_statut='.self::STATUS_CLOSED;
2270
-			if (!$close_code) $sql .= ', paye=1';
2271
-			if ($close_code) $sql .= ", close_code='".$this->db->escape($close_code)."'";
2272
-			if ($close_note) $sql .= ", close_note='".$this->db->escape($close_note)."'";
2454
+			if (!$close_code) {
2455
+				$sql .= ', paye=1';
2456
+			}
2457
+			if ($close_code) {
2458
+				$sql .= ", close_code='".$this->db->escape($close_code)."'";
2459
+			}
2460
+			if ($close_note) {
2461
+				$sql .= ", close_note='".$this->db->escape($close_note)."'";
2462
+			}
2273 2463
 			$sql .= ', fk_user_closing = '.$user->id;
2274 2464
 			$sql .= ", date_closing = '".$this->db->idate($now)."'";
2275 2465
 			$sql .= ' WHERE rowid = '.$this->id;
@@ -2279,7 +2469,9 @@  discard block
 block discarded – undo
2279 2469
 			{
2280 2470
 	            // Call trigger
2281 2471
 	            $result = $this->call_trigger('BILL_PAYED', $user);
2282
-	            if ($result < 0) $error++;
2472
+	            if ($result < 0) {
2473
+	            	$error++;
2474
+	            }
2283 2475
 	            // End call triggers
2284 2476
 			} else {
2285 2477
 				$error++;
@@ -2328,7 +2520,9 @@  discard block
 block discarded – undo
2328 2520
 		{
2329 2521
             // Call trigger
2330 2522
             $result = $this->call_trigger('BILL_UNPAYED', $user);
2331
-            if ($result < 0) $error++;
2523
+            if ($result < 0) {
2524
+            	$error++;
2525
+            }
2332 2526
             // End call triggers
2333 2527
 		} else {
2334 2528
 			$error++;
@@ -2368,8 +2562,12 @@  discard block
 block discarded – undo
2368 2562
 
2369 2563
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture SET';
2370 2564
 		$sql .= ' fk_statut='.self::STATUS_ABANDONED;
2371
-		if ($close_code) $sql .= ", close_code='".$this->db->escape($close_code)."'";
2372
-		if ($close_note) $sql .= ", close_note='".$this->db->escape($close_note)."'";
2565
+		if ($close_code) {
2566
+			$sql .= ", close_code='".$this->db->escape($close_code)."'";
2567
+		}
2568
+		if ($close_note) {
2569
+			$sql .= ", close_note='".$this->db->escape($close_note)."'";
2570
+		}
2373 2571
 		$sql .= ' WHERE rowid = '.$this->id;
2374 2572
 
2375 2573
 		$resql = $this->db->query($sql);
@@ -2465,12 +2663,14 @@  discard block
 block discarded – undo
2465 2663
 		$this->db->begin();
2466 2664
 
2467 2665
 		// Check parameters
2468
-		if ($this->type == self::TYPE_REPLACEMENT)		// si facture de remplacement
2666
+		if ($this->type == self::TYPE_REPLACEMENT) {
2667
+			// si facture de remplacement
2469 2668
 		{
2470 2669
 			// Controle que facture source connue
2471 2670
 			if ($this->fk_facture_source <= 0)
2472 2671
 			{
2473 2672
 				$this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("InvoiceReplacement"));
2673
+		}
2474 2674
 				$this->db->rollback();
2475 2675
 				return -10;
2476 2676
 			}
@@ -2509,11 +2709,13 @@  discard block
 block discarded – undo
2509 2709
 		if ($force_number)
2510 2710
 		{
2511 2711
 			$num = $force_number;
2512
-		} elseif (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) // empty should not happened, but when it occurs, the test save life
2712
+		} elseif (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) {
2713
+			// empty should not happened, but when it occurs, the test save life
2513 2714
 		{
2514 2715
 			if (!empty($conf->global->FAC_FORCE_DATE_VALIDATION))	// If option enabled, we force invoice date
2515 2716
 			{
2516 2717
 				$this->date = dol_now();
2718
+		}
2517 2719
 				$this->date_lim_reglement = $this->calculate_date_lim_reglement();
2518 2720
 			}
2519 2721
 			$num = $this->getNextNumRef($this->thirdparty);
@@ -2529,9 +2731,11 @@  discard block
 block discarded – undo
2529 2731
 			// Validate
2530 2732
 			$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
2531 2733
 			$sql .= " SET ref='".$num."', fk_statut = ".self::STATUS_VALIDATED.", fk_user_valid = ".($user->id > 0 ? $user->id : "null").", date_valid = '".$this->db->idate($now)."'";
2532
-			if (!empty($conf->global->FAC_FORCE_DATE_VALIDATION))	// If option enabled, we force invoice date
2734
+			if (!empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
2735
+				// If option enabled, we force invoice date
2533 2736
 			{
2534 2737
 				$sql .= ", datef='".$this->db->idate($this->date)."'";
2738
+			}
2535 2739
 				$sql .= ", date_lim_reglement='".$this->db->idate($this->date_lim_reglement)."'";
2536 2740
 			}
2537 2741
 			$sql .= ' WHERE rowid = '.$this->id;
@@ -2609,7 +2813,10 @@  discard block
 block discarded – undo
2609 2813
 											}
2610 2814
 
2611 2815
 											foreach ($batchList as $batch) {
2612
-												if ($batch->qty <= 0) continue; // try to decrement only batches have positive quantity first
2816
+												if ($batch->qty <= 0) {
2817
+													continue;
2818
+												}
2819
+												// try to decrement only batches have positive quantity first
2613 2820
 
2614 2821
 												// enough quantity in this batch
2615 2822
 												if ($batch->qty >= $product_qty_remain) {
@@ -2627,7 +2834,9 @@  discard block
 block discarded – undo
2627 2834
 
2628 2835
 												$product_qty_remain -= $product_batch_qty;
2629 2836
 												// all product quantity was decremented
2630
-												if ($product_qty_remain <= 0) break;
2837
+												if ($product_qty_remain <= 0) {
2838
+													break;
2839
+												}
2631 2840
 											}
2632 2841
 
2633 2842
 											if (!$error && $product_qty_remain > 0) {
@@ -2669,7 +2878,9 @@  discard block
 block discarded – undo
2669 2878
 			{
2670 2879
 	            // Call trigger
2671 2880
 	            $result = $this->call_trigger('BILL_VALIDATE', $user);
2672
-	            if ($result < 0) $error++;
2881
+	            if ($result < 0) {
2882
+	            	$error++;
2883
+	            }
2673 2884
 	            // End call triggers
2674 2885
 			}
2675 2886
 
@@ -2740,8 +2951,11 @@  discard block
 block discarded – undo
2740 2951
     					$i++;
2741 2952
     				}
2742 2953
 
2743
-    				if (empty($final)) $this->situation_final = 0;
2744
-    				else $this->situation_final = 1;
2954
+    				if (empty($final)) {
2955
+    					$this->situation_final = 0;
2956
+    				} else {
2957
+    					$this->situation_final = 1;
2958
+    				}
2745 2959
 
2746 2960
 				    $this->setFinal($user);
2747 2961
                 }
@@ -2851,8 +3065,12 @@  discard block
 block discarded – undo
2851 3065
 						$mouvP = new MouvementStock($this->db);
2852 3066
 						$mouvP->origin = &$this;
2853 3067
 						// We decrease stock for product
2854
-						if ($this->type == self::TYPE_CREDIT_NOTE) $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr", $this->ref));
2855
-						else $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans("InvoiceBackToDraftInDolibarr", $this->ref)); // we use 0 for price, to not change the weighted average value
3068
+						if ($this->type == self::TYPE_CREDIT_NOTE) {
3069
+							$result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr", $this->ref));
3070
+						} else {
3071
+							$result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans("InvoiceBackToDraftInDolibarr", $this->ref));
3072
+						}
3073
+						// we use 0 for price, to not change the weighted average value
2856 3074
 					}
2857 3075
 				}
2858 3076
 			}
@@ -2977,17 +3195,39 @@  discard block
 block discarded – undo
2977 3195
 			include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
2978 3196
 
2979 3197
 			// Clean parameters
2980
-			if (empty($remise_percent)) $remise_percent = 0;
2981
-			if (empty($qty)) $qty = 0;
2982
-			if (empty($info_bits)) $info_bits = 0;
2983
-			if (empty($rang)) $rang = 0;
2984
-			if (empty($ventil)) $ventil = 0;
2985
-			if (empty($txtva)) $txtva = 0;
2986
-			if (empty($txlocaltax1)) $txlocaltax1 = 0;
2987
-			if (empty($txlocaltax2)) $txlocaltax2 = 0;
2988
-			if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line = 0;
2989
-			if (empty($fk_prev_id)) $fk_prev_id = 'null';
2990
-			if (!isset($situation_percent) || $situation_percent > 100 || (string) $situation_percent == '') $situation_percent = 100;
3198
+			if (empty($remise_percent)) {
3199
+				$remise_percent = 0;
3200
+			}
3201
+			if (empty($qty)) {
3202
+				$qty = 0;
3203
+			}
3204
+			if (empty($info_bits)) {
3205
+				$info_bits = 0;
3206
+			}
3207
+			if (empty($rang)) {
3208
+				$rang = 0;
3209
+			}
3210
+			if (empty($ventil)) {
3211
+				$ventil = 0;
3212
+			}
3213
+			if (empty($txtva)) {
3214
+				$txtva = 0;
3215
+			}
3216
+			if (empty($txlocaltax1)) {
3217
+				$txlocaltax1 = 0;
3218
+			}
3219
+			if (empty($txlocaltax2)) {
3220
+				$txlocaltax2 = 0;
3221
+			}
3222
+			if (empty($fk_parent_line) || $fk_parent_line < 0) {
3223
+				$fk_parent_line = 0;
3224
+			}
3225
+			if (empty($fk_prev_id)) {
3226
+				$fk_prev_id = 'null';
3227
+			}
3228
+			if (!isset($situation_percent) || $situation_percent > 100 || (string) $situation_percent == '') {
3229
+				$situation_percent = 100;
3230
+			}
2991 3231
 
2992 3232
 			$remise_percent = price2num($remise_percent);
2993 3233
 			$qty = price2num($qty);
@@ -3009,7 +3249,9 @@  discard block
 block discarded – undo
3009 3249
 			}
3010 3250
 
3011 3251
 			// Check parameters
3012
-			if ($type < 0) return -1;
3252
+			if ($type < 0) {
3253
+				return -1;
3254
+			}
3013 3255
 
3014 3256
 			if ($date_start && $date_end && $date_start > $date_end) {
3015 3257
 				$langs->load("errors");
@@ -3136,7 +3378,9 @@  discard block
 block discarded – undo
3136 3378
 			if ($result > 0)
3137 3379
 			{
3138 3380
 				// Reorder if child line
3139
-				if (!empty($fk_parent_line)) $this->line_order(true, 'DESC');
3381
+				if (!empty($fk_parent_line)) {
3382
+					$this->line_order(true, 'DESC');
3383
+				}
3140 3384
 
3141 3385
 				// Mise a jour informations denormalisees au niveau de la facture meme
3142 3386
 				$result = $this->update_price(1, 'auto', 0, $mysoc); // The addline method is designed to add line from user input so total calculation with update_price must be done using 'auto' mode.
@@ -3210,7 +3454,9 @@  discard block
 block discarded – undo
3210 3454
 			{
3211 3455
 				if (!$this->checkProgressLine($rowid, $situation_percent))
3212 3456
 				{
3213
-					if (!$this->error) $this->error = $langs->trans('invoiceLineProgressError');
3457
+					if (!$this->error) {
3458
+						$this->error = $langs->trans('invoiceLineProgressError');
3459
+					}
3214 3460
 					return -3;
3215 3461
 				}
3216 3462
 			}
@@ -3224,10 +3470,18 @@  discard block
 block discarded – undo
3224 3470
 			$this->db->begin();
3225 3471
 
3226 3472
 			// Clean parameters
3227
-			if (empty($qty)) $qty = 0;
3228
-			if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line = 0;
3229
-			if (empty($special_code) || $special_code == 3) $special_code = 0;
3230
-			if (!isset($situation_percent) || $situation_percent > 100 || (string) $situation_percent == '') $situation_percent = 100;
3473
+			if (empty($qty)) {
3474
+				$qty = 0;
3475
+			}
3476
+			if (empty($fk_parent_line) || $fk_parent_line < 0) {
3477
+				$fk_parent_line = 0;
3478
+			}
3479
+			if (empty($special_code) || $special_code == 3) {
3480
+				$special_code = 0;
3481
+			}
3482
+			if (!isset($situation_percent) || $situation_percent > 100 || (string) $situation_percent == '') {
3483
+				$situation_percent = 100;
3484
+			}
3231 3485
 
3232 3486
 			$remise_percent = price2num($remise_percent);
3233 3487
 			$qty			= price2num($qty);
@@ -3239,7 +3493,9 @@  discard block
 block discarded – undo
3239 3493
 			$txlocaltax2	= price2num($txlocaltax2);
3240 3494
 
3241 3495
 			// Check parameters
3242
-			if ($type < 0) return -1;
3496
+			if ($type < 0) {
3497
+				return -1;
3498
+			}
3243 3499
 
3244 3500
 			// Calculate total with, without tax and tax from qty, pu, remise_percent and txtva
3245 3501
 			// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
@@ -3364,7 +3620,9 @@  discard block
 block discarded – undo
3364 3620
 			if ($result > 0)
3365 3621
 			{
3366 3622
 				// Reorder if child line
3367
-				if (!empty($fk_parent_line)) $this->line_order(true, 'DESC');
3623
+				if (!empty($fk_parent_line)) {
3624
+					$this->line_order(true, 'DESC');
3625
+				}
3368 3626
 
3369 3627
 				// Mise a jour info denormalisees au niveau facture
3370 3628
 				$this->update_price(1);
@@ -3404,8 +3662,11 @@  discard block
 block discarded – undo
3404 3662
 
3405 3663
 		$obj = $this->db->fetch_object($result);
3406 3664
 
3407
-		if ($obj === null) return true;
3408
-		else return $situation_percent < $obj->situation_percent;
3665
+		if ($obj === null) {
3666
+			return true;
3667
+		} else {
3668
+			return $situation_percent < $obj->situation_percent;
3669
+		}
3409 3670
 	}
3410 3671
 
3411 3672
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
@@ -3430,7 +3691,9 @@  discard block
 block discarded – undo
3430 3691
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
3431 3692
 
3432 3693
 		// Cap percentages to 100
3433
-		if ($percent > 100) $percent = 100;
3694
+		if ($percent > 100) {
3695
+			$percent = 100;
3696
+		}
3434 3697
 		$line->situation_percent = $percent;
3435 3698
 		$tabprice = calcul_price_total($line->qty, $line->subprice, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 0, 'HT', 0, $line->product_type, $mysoc, '', $percent);
3436 3699
 		$line->total_ht = $tabprice[0];
@@ -3485,7 +3748,9 @@  discard block
 block discarded – undo
3485 3748
 
3486 3749
 		// For triggers
3487 3750
 		$result = $line->fetch($rowid);
3488
-		if (!($result > 0)) dol_print_error($this->db, $line->error, $line->errors);
3751
+		if (!($result > 0)) {
3752
+			dol_print_error($this->db, $line->error, $line->errors);
3753
+		}
3489 3754
 
3490 3755
 		if ($line->delete($user) > 0)
3491 3756
 		{
@@ -3520,7 +3785,9 @@  discard block
 block discarded – undo
3520 3785
 	{
3521 3786
         // phpcs:enable
3522 3787
 		// Clean parameters
3523
-		if (empty($remise)) $remise = 0;
3788
+		if (empty($remise)) {
3789
+			$remise = 0;
3790
+		}
3524 3791
 
3525 3792
 		if ($user->rights->facture->creer)
3526 3793
 		{
@@ -3547,7 +3814,9 @@  discard block
 block discarded – undo
3547 3814
 			{
3548 3815
 				// Call trigger
3549 3816
 				$result = $this->call_trigger('BILL_MODIFY', $user);
3550
-				if ($result < 0) $error++;
3817
+				if ($result < 0) {
3818
+					$error++;
3819
+				}
3551 3820
 				// End call triggers
3552 3821
 			}
3553 3822
 
@@ -3583,7 +3852,9 @@  discard block
 block discarded – undo
3583 3852
     public function set_remise_absolue($user, $remise, $notrigger = 0)
3584 3853
 	{
3585 3854
         // phpcs:enable
3586
-		if (empty($remise)) $remise = 0;
3855
+		if (empty($remise)) {
3856
+			$remise = 0;
3857
+		}
3587 3858
 
3588 3859
 		if ($user->rights->facture->creer)
3589 3860
 		{
@@ -3617,7 +3888,9 @@  discard block
 block discarded – undo
3617 3888
 			{
3618 3889
 				// Call trigger
3619 3890
 				$result = $this->call_trigger('BILL_MODIFY', $user);
3620
-				if ($result < 0) $error++;
3891
+				if ($result < 0) {
3892
+					$error++;
3893
+				}
3621 3894
 				// End call triggers
3622 3895
 			}
3623 3896
 
@@ -3657,7 +3930,9 @@  discard block
 block discarded – undo
3657 3930
 			$addonConstName = 'TAKEPOS_REF_ADDON';
3658 3931
 
3659 3932
 			// Clean parameters (if not defined or using deprecated value)
3660
-			if (empty($conf->global->TAKEPOS_REF_ADDON)) $conf->global->TAKEPOS_REF_ADDON = 'mod_takepos_ref_simple';
3933
+			if (empty($conf->global->TAKEPOS_REF_ADDON)) {
3934
+				$conf->global->TAKEPOS_REF_ADDON = 'mod_takepos_ref_simple';
3935
+			}
3661 3936
 
3662 3937
 			$addon = $conf->global->TAKEPOS_REF_ADDON;
3663 3938
 		} else {
@@ -3668,9 +3943,13 @@  discard block
 block discarded – undo
3668 3943
 			$addonConstName = 'FACTURE_ADDON';
3669 3944
 
3670 3945
 			// Clean parameters (if not defined or using deprecated value)
3671
-			if (empty($conf->global->FACTURE_ADDON)) $conf->global->FACTURE_ADDON = 'mod_facture_terre';
3672
-			elseif ($conf->global->FACTURE_ADDON == 'terre') $conf->global->FACTURE_ADDON = 'mod_facture_terre';
3673
-			elseif ($conf->global->FACTURE_ADDON == 'mercure') $conf->global->FACTURE_ADDON = 'mod_facture_mercure';
3946
+			if (empty($conf->global->FACTURE_ADDON)) {
3947
+				$conf->global->FACTURE_ADDON = 'mod_facture_terre';
3948
+			} elseif ($conf->global->FACTURE_ADDON == 'terre') {
3949
+				$conf->global->FACTURE_ADDON = 'mod_facture_terre';
3950
+			} elseif ($conf->global->FACTURE_ADDON == 'mercure') {
3951
+				$conf->global->FACTURE_ADDON = 'mod_facture_mercure';
3952
+			}
3674 3953
 
3675 3954
 			$addon = $conf->global->FACTURE_ADDON;
3676 3955
 		}
@@ -3812,18 +4091,30 @@  discard block
 block discarded – undo
3812 4091
 
3813 4092
 		$sql = "SELECT s.rowid, s.nom as name, s.client,";
3814 4093
 		$sql .= " f.rowid as fid, f.ref as ref, f.datef as df";
3815
-		if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user";
4094
+		if (!$user->rights->societe->client->voir && !$socid) {
4095
+			$sql .= ", sc.fk_soc, sc.fk_user";
4096
+		}
3816 4097
 		$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f";
3817
-		if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
4098
+		if (!$user->rights->societe->client->voir && !$socid) {
4099
+			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
4100
+		}
3818 4101
 		$sql .= " WHERE f.entity IN (".getEntity('invoice').")";
3819 4102
 		$sql .= " AND f.fk_soc = s.rowid";
3820
-		if (!$user->rights->societe->client->voir && !$socid) //restriction
4103
+		if (!$user->rights->societe->client->voir && !$socid) {
4104
+			//restriction
3821 4105
 		{
3822 4106
 			$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
3823 4107
 		}
3824
-		if ($socid) $sql .= " AND s.rowid = ".$socid;
3825
-		if ($draft) $sql .= " AND f.fk_statut = ".self::STATUS_DRAFT;
3826
-		if (is_object($excluser)) $sql .= " AND f.fk_user_author <> ".$excluser->id;
4108
+		}
4109
+		if ($socid) {
4110
+			$sql .= " AND s.rowid = ".$socid;
4111
+		}
4112
+		if ($draft) {
4113
+			$sql .= " AND f.fk_statut = ".self::STATUS_DRAFT;
4114
+		}
4115
+		if (is_object($excluser)) {
4116
+			$sql .= " AND f.fk_user_author <> ".$excluser->id;
4117
+		}
3827 4118
 		$sql .= $this->db->order($sortfield, $sortorder);
3828 4119
 		$sql .= $this->db->plimit($limit, $offset);
3829 4120
 
@@ -3886,7 +4177,9 @@  discard block
 block discarded – undo
3886 4177
 		$sql .= " AND f.paye = 0"; // Pas classee payee completement
3887 4178
 		$sql .= " AND pf.fk_paiement IS NULL"; // Aucun paiement deja fait
3888 4179
 		$sql .= " AND ff.fk_statut IS NULL"; // Renvoi vrai si pas facture de remplacement
3889
-		if ($socid > 0) $sql .= " AND f.fk_soc = ".$socid;
4180
+		if ($socid > 0) {
4181
+			$sql .= " AND f.fk_soc = ".$socid;
4182
+		}
3890 4183
 		$sql .= " ORDER BY f.ref";
3891 4184
 
3892 4185
 		dol_syslog(get_class($this)."::list_replacable_invoices", LOG_DEBUG);
@@ -3951,7 +4244,9 @@  discard block
 block discarded – undo
3951 4244
 		    $sql .= " AND f.type != ".self::TYPE_SITUATION; // Type non 5 si facture non avoir
3952 4245
 		}
3953 4246
 
3954
-		if ($socid > 0) $sql .= " AND f.fk_soc = ".$socid;
4247
+		if ($socid > 0) {
4248
+			$sql .= " AND f.fk_soc = ".$socid;
4249
+		}
3955 4250
 		$sql .= " ORDER BY f.ref";
3956 4251
 
3957 4252
 		dol_syslog(get_class($this)."::list_qualified_avoir_invoices", LOG_DEBUG);
@@ -3961,8 +4256,12 @@  discard block
 block discarded – undo
3961 4256
 			while ($obj = $this->db->fetch_object($resql))
3962 4257
 			{
3963 4258
 				$qualified = 0;
3964
-				if ($obj->fk_statut == self::STATUS_VALIDATED) $qualified = 1;
3965
-				if ($obj->fk_statut == self::STATUS_CLOSED) $qualified = 1;
4259
+				if ($obj->fk_statut == self::STATUS_VALIDATED) {
4260
+					$qualified = 1;
4261
+				}
4262
+				if ($obj->fk_statut == self::STATUS_CLOSED) {
4263
+					$qualified = 1;
4264
+				}
3966 4265
 				if ($qualified)
3967 4266
 				{
3968 4267
 					//$ref=$obj->ref;
@@ -4004,7 +4303,9 @@  discard block
 block discarded – undo
4004 4303
 		$sql .= $clause." f.paye=0";
4005 4304
 		$sql .= " AND f.entity IN (".getEntity('invoice').")";
4006 4305
 		$sql .= " AND f.fk_statut = ".self::STATUS_VALIDATED;
4007
-		if ($user->socid) $sql .= " AND f.fk_soc = ".$user->socid;
4306
+		if ($user->socid) {
4307
+			$sql .= " AND f.fk_soc = ".$user->socid;
4308
+		}
4008 4309
 
4009 4310
 		$resql = $this->db->query($sql);
4010 4311
 		if ($resql)
@@ -4145,9 +4446,11 @@  discard block
 block discarded – undo
4145 4446
 				$line->localtax1_tx = 0;
4146 4447
 				$line->localtax2_tx = 0;
4147 4448
 				$line->remise_percent = 0;
4148
-				if ($xnbp == 1)        // Qty is negative (product line)
4449
+				if ($xnbp == 1) {
4450
+					// Qty is negative (product line)
4149 4451
 				{
4150 4452
 					$prodid = mt_rand(1, $num_prods);
4453
+				}
4151 4454
 					$line->fk_product = $prodids[$prodid];
4152 4455
 					$line->qty = -1;
4153 4456
 					$line->total_ht = -100;
@@ -4156,9 +4459,11 @@  discard block
 block discarded – undo
4156 4459
 					$line->multicurrency_total_ht = -200;
4157 4460
 					$line->multicurrency_total_ttc = -239.2;
4158 4461
 					$line->multicurrency_total_tva = -39.2;
4159
-				} elseif ($xnbp == 2)    // UP is negative (free line)
4462
+				} elseif ($xnbp == 2) {
4463
+					// UP is negative (free line)
4160 4464
 				{
4161 4465
 					$line->subprice = -100;
4466
+				}
4162 4467
 					$line->total_ht = -100;
4163 4468
 					$line->total_ttc = -119.6;
4164 4469
 					$line->total_tva = -19.6;
@@ -4166,9 +4471,11 @@  discard block
 block discarded – undo
4166 4471
 					$line->multicurrency_total_ht = -200;
4167 4472
 					$line->multicurrency_total_ttc = -239.2;
4168 4473
 					$line->multicurrency_total_tva = -39.2;
4169
-				} elseif ($xnbp == 3)    // Discount is 50% (product line)
4474
+				} elseif ($xnbp == 3) {
4475
+					// Discount is 50% (product line)
4170 4476
 				{
4171 4477
 					$prodid = mt_rand(1, $num_prods);
4478
+				}
4172 4479
 					$line->fk_product = $prodids[$prodid];
4173 4480
 					$line->total_ht = 50;
4174 4481
 					$line->total_ttc = 59.8;
@@ -4416,7 +4723,9 @@  discard block
 block discarded – undo
4416 4723
 		{
4417 4724
 			// Call trigger
4418 4725
 			$result = $this->call_trigger('BILL_MODIFY', $user);
4419
-			if ($result < 0) $error++;
4726
+			if ($result < 0) {
4727
+				$error++;
4728
+			}
4420 4729
 			// End call triggers
4421 4730
 		}
4422 4731
 
@@ -4496,7 +4805,9 @@  discard block
 block discarded – undo
4496 4805
 		$now = dol_now();
4497 4806
 
4498 4807
 		// Paid invoices have status STATUS_CLOSED
4499
-		if ($this->statut != Facture::STATUS_VALIDATED) return false;
4808
+		if ($this->statut != Facture::STATUS_VALIDATED) {
4809
+			return false;
4810
+		}
4500 4811
 
4501 4812
 		$hasDelay = $this->date_lim_reglement < ($now - $conf->facture->client->warning_delay);
4502 4813
 		if ($hasDelay && !empty($this->retained_warranty) && !empty($this->retained_warranty_date_limit))
@@ -4887,27 +5198,67 @@  discard block
 block discarded – undo
4887 5198
 
4888 5199
 		// Clean parameters
4889 5200
 		$this->desc = trim($this->desc);
4890
-		if (empty($this->tva_tx)) $this->tva_tx = 0;
4891
-		if (empty($this->localtax1_tx)) $this->localtax1_tx = 0;
4892
-		if (empty($this->localtax2_tx)) $this->localtax2_tx = 0;
4893
-		if (empty($this->localtax1_type)) $this->localtax1_type = 0;
4894
-		if (empty($this->localtax2_type)) $this->localtax2_type = 0;
4895
-		if (empty($this->total_localtax1)) $this->total_localtax1 = 0;
4896
-		if (empty($this->total_localtax2)) $this->total_localtax2 = 0;
4897
-		if (empty($this->rang)) $this->rang = 0;
4898
-		if (empty($this->remise_percent)) $this->remise_percent = 0;
4899
-		if (empty($this->info_bits)) $this->info_bits = 0;
4900
-		if (empty($this->subprice)) $this->subprice = 0;
4901
-		if (empty($this->special_code)) $this->special_code = 0;
4902
-		if (empty($this->fk_parent_line)) $this->fk_parent_line = 0;
4903
-		if (empty($this->fk_prev_id)) $this->fk_prev_id = 0;
4904
-		if (!isset($this->situation_percent) || $this->situation_percent > 100 || (string) $this->situation_percent == '') $this->situation_percent = 100;
4905
-
4906
-		if (empty($this->pa_ht)) $this->pa_ht = 0;
4907
-		if (empty($this->multicurrency_subprice)) $this->multicurrency_subprice = 0;
4908
-		if (empty($this->multicurrency_total_ht)) $this->multicurrency_total_ht = 0;
4909
-		if (empty($this->multicurrency_total_tva)) $this->multicurrency_total_tva = 0;
4910
-		if (empty($this->multicurrency_total_ttc)) $this->multicurrency_total_ttc = 0;
5201
+		if (empty($this->tva_tx)) {
5202
+			$this->tva_tx = 0;
5203
+		}
5204
+		if (empty($this->localtax1_tx)) {
5205
+			$this->localtax1_tx = 0;
5206
+		}
5207
+		if (empty($this->localtax2_tx)) {
5208
+			$this->localtax2_tx = 0;
5209
+		}
5210
+		if (empty($this->localtax1_type)) {
5211
+			$this->localtax1_type = 0;
5212
+		}
5213
+		if (empty($this->localtax2_type)) {
5214
+			$this->localtax2_type = 0;
5215
+		}
5216
+		if (empty($this->total_localtax1)) {
5217
+			$this->total_localtax1 = 0;
5218
+		}
5219
+		if (empty($this->total_localtax2)) {
5220
+			$this->total_localtax2 = 0;
5221
+		}
5222
+		if (empty($this->rang)) {
5223
+			$this->rang = 0;
5224
+		}
5225
+		if (empty($this->remise_percent)) {
5226
+			$this->remise_percent = 0;
5227
+		}
5228
+		if (empty($this->info_bits)) {
5229
+			$this->info_bits = 0;
5230
+		}
5231
+		if (empty($this->subprice)) {
5232
+			$this->subprice = 0;
5233
+		}
5234
+		if (empty($this->special_code)) {
5235
+			$this->special_code = 0;
5236
+		}
5237
+		if (empty($this->fk_parent_line)) {
5238
+			$this->fk_parent_line = 0;
5239
+		}
5240
+		if (empty($this->fk_prev_id)) {
5241
+			$this->fk_prev_id = 0;
5242
+		}
5243
+		if (!isset($this->situation_percent) || $this->situation_percent > 100 || (string) $this->situation_percent == '') {
5244
+			$this->situation_percent = 100;
5245
+		}
5246
+
5247
+		if (empty($this->pa_ht)) {
5248
+			$this->pa_ht = 0;
5249
+		}
5250
+		if (empty($this->multicurrency_subprice)) {
5251
+			$this->multicurrency_subprice = 0;
5252
+		}
5253
+		if (empty($this->multicurrency_total_ht)) {
5254
+			$this->multicurrency_total_ht = 0;
5255
+		}
5256
+		if (empty($this->multicurrency_total_tva)) {
5257
+			$this->multicurrency_total_tva = 0;
5258
+		}
5259
+		if (empty($this->multicurrency_total_ttc)) {
5260
+			$this->multicurrency_total_ttc = 0;
5261
+		}
4911 5262
 
4912 5263
 		// if buy price not defined, define buyprice as configured in margin admin
4913 5264
 		if ($this->pa_ht == 0 && $pa_ht_isemptystring)
@@ -5093,28 +5444,66 @@  discard block
 block discarded – undo
5093 5444
 
5094 5445
 		// Clean parameters
5095 5446
 		$this->desc = trim($this->desc);
5096
-		if (empty($this->tva_tx)) $this->tva_tx = 0;
5097
-		if (empty($this->localtax1_tx)) $this->localtax1_tx = 0;
5098
-		if (empty($this->localtax2_tx)) $this->localtax2_tx = 0;
5099
-		if (empty($this->localtax1_type)) $this->localtax1_type = 0;
5100
-		if (empty($this->localtax2_type)) $this->localtax2_type = 0;
5101
-		if (empty($this->total_localtax1)) $this->total_localtax1 = 0;
5102
-		if (empty($this->total_localtax2)) $this->total_localtax2 = 0;
5103
-		if (empty($this->remise_percent)) $this->remise_percent = 0;
5104
-		if (empty($this->info_bits)) $this->info_bits = 0;
5105
-		if (empty($this->special_code)) $this->special_code = 0;
5106
-		if (empty($this->product_type)) $this->product_type = 0;
5107
-		if (empty($this->fk_parent_line)) $this->fk_parent_line = 0;
5108
-		if (!isset($this->situation_percent) || $this->situation_percent > 100 || (string) $this->situation_percent == '') $this->situation_percent = 100;
5109
-		if (empty($this->pa_ht)) $this->pa_ht = 0;
5110
-
5111
-		if (empty($this->multicurrency_subprice)) $this->multicurrency_subprice = 0;
5112
-		if (empty($this->multicurrency_total_ht)) $this->multicurrency_total_ht = 0;
5113
-		if (empty($this->multicurrency_total_tva)) $this->multicurrency_total_tva = 0;
5114
-		if (empty($this->multicurrency_total_ttc)) $this->multicurrency_total_ttc = 0;
5447
+		if (empty($this->tva_tx)) {
5448
+			$this->tva_tx = 0;
5449
+		}
5450
+		if (empty($this->localtax1_tx)) {
5451
+			$this->localtax1_tx = 0;
5452
+		}
5453
+		if (empty($this->localtax2_tx)) {
5454
+			$this->localtax2_tx = 0;
5455
+		}
5456
+		if (empty($this->localtax1_type)) {
5457
+			$this->localtax1_type = 0;
5458
+		}
5459
+		if (empty($this->localtax2_type)) {
5460
+			$this->localtax2_type = 0;
5461
+		}
5462
+		if (empty($this->total_localtax1)) {
5463
+			$this->total_localtax1 = 0;
5464
+		}
5465
+		if (empty($this->total_localtax2)) {
5466
+			$this->total_localtax2 = 0;
5467
+		}
5468
+		if (empty($this->remise_percent)) {
5469
+			$this->remise_percent = 0;
5470
+		}
5471
+		if (empty($this->info_bits)) {
5472
+			$this->info_bits = 0;
5473
+		}
5474
+		if (empty($this->special_code)) {
5475
+			$this->special_code = 0;
5476
+		}
5477
+		if (empty($this->product_type)) {
5478
+			$this->product_type = 0;
5479
+		}
5480
+		if (empty($this->fk_parent_line)) {
5481
+			$this->fk_parent_line = 0;
5482
+		}
5483
+		if (!isset($this->situation_percent) || $this->situation_percent > 100 || (string) $this->situation_percent == '') {
5484
+			$this->situation_percent = 100;
5485
+		}
5486
+		if (empty($this->pa_ht)) {
5487
+			$this->pa_ht = 0;
5488
+		}
5489
+
5490
+		if (empty($this->multicurrency_subprice)) {
5491
+			$this->multicurrency_subprice = 0;
5492
+		}
5493
+		if (empty($this->multicurrency_total_ht)) {
5494
+			$this->multicurrency_total_ht = 0;
5495
+		}
5496
+		if (empty($this->multicurrency_total_tva)) {
5497
+			$this->multicurrency_total_tva = 0;
5498
+		}
5499
+		if (empty($this->multicurrency_total_ttc)) {
5500
+			$this->multicurrency_total_ttc = 0;
5501
+		}
5115 5502
 
5116 5503
 		// Check parameters
5117
-		if ($this->product_type < 0) return -1;
5504
+		if ($this->product_type < 0) {
5505
+			return -1;
5506
+		}
5118 5507
 
5119 5508
 		// if buy price not defined, define buyprice as configured in margin admin
5120 5509
 		if ($this->pa_ht == 0 && $pa_ht_isemptystring)
@@ -5135,8 +5524,11 @@  discard block
 block discarded – undo
5135 5524
         $sql .= ", label=".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
5136 5525
         $sql .= ", subprice=".price2num($this->subprice)."";
5137 5526
         $sql .= ", remise_percent=".price2num($this->remise_percent)."";
5138
-        if ($this->fk_remise_except) $sql .= ", fk_remise_except=".$this->fk_remise_except;
5139
-        else $sql .= ", fk_remise_except=null";
5527
+        if ($this->fk_remise_except) {
5528
+        	$sql .= ", fk_remise_except=".$this->fk_remise_except;
5529
+        } else {
5530
+        	$sql .= ", fk_remise_except=null";
5531
+        }
5140 5532
 		$sql .= ", vat_src_code = '".(empty($this->vat_src_code) ? '' : $this->db->escape($this->vat_src_code))."'";
5141 5533
         $sql .= ", tva_tx=".price2num($this->tva_tx)."";
5142 5534
         $sql .= ", localtax1_tx=".price2num($this->localtax1_tx)."";
@@ -5160,7 +5552,9 @@  discard block
 block discarded – undo
5160 5552
 		$sql .= ", fk_product_fournisseur_price=".(!empty($this->fk_fournprice) ? "'".$this->db->escape($this->fk_fournprice)."'" : "null");
5161 5553
 		$sql .= ", buy_price_ht='".price2num($this->pa_ht)."'";
5162 5554
 		$sql .= ", fk_parent_line=".($this->fk_parent_line > 0 ? $this->fk_parent_line : "null");
5163
-		if (!empty($this->rang)) $sql .= ", rang=".$this->rang;
5555
+		if (!empty($this->rang)) {
5556
+			$sql .= ", rang=".$this->rang;
5557
+		}
5164 5558
 		$sql .= ", situation_percent=".$this->situation_percent;
5165 5559
 		$sql .= ", fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
5166 5560
 		$sql .= ", fk_user_modif =".$user->id;
@@ -5263,8 +5657,12 @@  discard block
 block discarded – undo
5263 5657
 		dol_syslog(get_class($this)."::update_total", LOG_DEBUG);
5264 5658
 
5265 5659
 		// Clean parameters
5266
-		if (empty($this->total_localtax1)) $this->total_localtax1 = 0;
5267
-		if (empty($this->total_localtax2)) $this->total_localtax2 = 0;
5660
+		if (empty($this->total_localtax1)) {
5661
+			$this->total_localtax1 = 0;
5662
+		}
5663
+		if (empty($this->total_localtax2)) {
5664
+			$this->total_localtax2 = 0;
5665
+		}
5268 5666
 
5269 5667
 		// Mise a jour ligne en base
5270 5668
 		$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet SET";
@@ -5310,7 +5708,9 @@  discard block
 block discarded – undo
5310 5708
 				$invoicecache[$invoiceid] = new Facture($this->db);
5311 5709
 				$invoicecache[$invoiceid]->fetch($invoiceid);
5312 5710
 			}
5313
-			if ($invoicecache[$invoiceid]->type != Facture::TYPE_SITUATION) return 0;
5711
+			if ($invoicecache[$invoiceid]->type != Facture::TYPE_SITUATION) {
5712
+				return 0;
5713
+			}
5314 5714
 
5315 5715
 			$sql = 'SELECT situation_percent FROM '.MAIN_DB_PREFIX.'facturedet WHERE rowid='.$this->fk_prev_id;
5316 5716
 			$resql = $this->db->query($sql);
Please login to merge, or discard this patch.
htdocs/modulebuilder/template/myobject_list.php 1 patch
Braces   +181 added lines, -66 removed lines patch added patch discarded remove patch
@@ -44,17 +44,31 @@  discard block
 block discarded – undo
44 44
 // Load Dolibarr environment
45 45
 $res = 0;
46 46
 // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
47
-if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
47
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
48
+	$res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
49
+}
48 50
 // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
49 51
 $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
50 52
 while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
51
-if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
52
-if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
53
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
54
+	$res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
55
+}
56
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
57
+	$res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
58
+}
53 59
 // Try main.inc.php using relative path
54
-if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php";
55
-if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
56
-if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
57
-if (!$res) die("Include of main fails");
60
+if (!$res && file_exists("../main.inc.php")) {
61
+	$res = @include "../main.inc.php";
62
+}
63
+if (!$res && file_exists("../../main.inc.php")) {
64
+	$res = @include "../../main.inc.php";
65
+}
66
+if (!$res && file_exists("../../../main.inc.php")) {
67
+	$res = @include "../../../main.inc.php";
68
+}
69
+if (!$res) {
70
+	die("Include of main fails");
71
+}
58 72
 
59 73
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
60 74
 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
@@ -104,23 +118,32 @@  discard block
 block discarded – undo
104 118
 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
105 119
 
106 120
 // Default sort order (if not yet defined by previous GETPOST)
107
-if (!$sortfield) $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
108
-if (!$sortorder) $sortorder = "ASC";
121
+if (!$sortfield) {
122
+	$sortfield = "t.".key($object->fields);
123
+}
124
+// Set here default search field. By default 1st field in definition.
125
+if (!$sortorder) {
126
+	$sortorder = "ASC";
127
+}
109 128
 
110 129
 // Initialize array of search criterias
111 130
 $search_all = GETPOST('search_all', 'alphanohtml') ? trim(GETPOST('search_all', 'alphanohtml')) : trim(GETPOST('sall', 'alphanohtml'));
112 131
 $search = array();
113 132
 foreach ($object->fields as $key => $val)
114 133
 {
115
-	if (GETPOST('search_'.$key, 'alpha') !== '') $search[$key] = GETPOST('search_'.$key, 'alpha');
116
-}
134
+	if (GETPOST('search_'.$key, 'alpha') !== '') {
135
+		$search[$key] = GETPOST('search_'.$key, 'alpha');
136
+	}
137
+	}
117 138
 
118 139
 // List of fields to search into when doing a "search in all"
119 140
 $fieldstosearchall = array();
120 141
 foreach ($object->fields as $key => $val)
121 142
 {
122
-	if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label'];
123
-}
143
+	if ($val['searchall']) {
144
+		$fieldstosearchall['t.'.$key] = $val['label'];
145
+	}
146
+	}
124 147
 
125 148
 // Definition of fields for list
126 149
 $arrayfields = array();
@@ -160,13 +183,17 @@  discard block
 block discarded – undo
160 183
 $permissiontodelete = $user->rights->mymodule->myobject->delete;
161 184
 
162 185
 // Security check
163
-if (empty($conf->mymodule->enabled)) accessforbidden('Module not enabled');
186
+if (empty($conf->mymodule->enabled)) {
187
+	accessforbidden('Module not enabled');
188
+}
164 189
 $socid = 0;
165
-if ($user->socid > 0)	// Protection if external user
190
+if ($user->socid > 0) {
191
+	// Protection if external user
166 192
 {
167 193
 	//$socid = $user->socid;
168 194
 	accessforbidden();
169 195
 }
196
+}
170 197
 //$result = restrictedArea($user, 'mymodule', $id, '');
171 198
 //if (!$permissiontoread) accessforbidden();
172 199
 
@@ -181,7 +208,9 @@  discard block
 block discarded – undo
181 208
 
182 209
 $parameters = array();
183 210
 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
184
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
211
+if ($reshook < 0) {
212
+	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
213
+}
185 214
 
186 215
 if (empty($reshook))
187 216
 {
@@ -189,11 +218,13 @@  discard block
 block discarded – undo
189 218
 	include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
190 219
 
191 220
 	// Purge search criteria
192
-	if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
221
+	if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
222
+		// All tests are required to be compatible with all browsers
193 223
 	{
194 224
 		foreach ($object->fields as $key => $val)
195 225
 		{
196 226
 			$search[$key] = '';
227
+	}
197 228
 		}
198 229
 		$toselect = '';
199 230
 		$search_array_options = array();
@@ -235,28 +266,43 @@  discard block
 block discarded – undo
235 266
 }
236 267
 // Add fields from extrafields
237 268
 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
238
-	foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : '');
239
-}
269
+	foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
270
+		$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : '');
271
+	}
272
+	}
240 273
 // Add fields from hooks
241 274
 $parameters = array();
242 275
 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
243 276
 $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
244 277
 $sql = preg_replace('/,\s*$/', '', $sql);
245 278
 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
246
-if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
247
-if ($object->ismultientitymanaged == 1) $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
248
-else $sql .= " WHERE 1 = 1";
279
+if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
280
+	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
281
+}
282
+if ($object->ismultientitymanaged == 1) {
283
+	$sql .= " WHERE t.entity IN (".getEntity($object->element).")";
284
+} else {
285
+	$sql .= " WHERE 1 = 1";
286
+}
249 287
 foreach ($search as $key => $val)
250 288
 {
251
-	if ($key == 'status' && $search[$key] == -1) continue;
289
+	if ($key == 'status' && $search[$key] == -1) {
290
+		continue;
291
+	}
252 292
 	$mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
253 293
 	if (strpos($object->fields[$key]['type'], 'integer:') === 0) {
254
-		if ($search[$key] == '-1') $search[$key] = '';
294
+		if ($search[$key] == '-1') {
295
+			$search[$key] = '';
296
+		}
255 297
 		$mode_search = 2;
256 298
 	}
257
-	if ($search[$key] != '') $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
299
+	if ($search[$key] != '') {
300
+		$sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
301
+	}
302
+	}
303
+if ($search_all) {
304
+	$sql .= natural_search(array_keys($fieldstosearchall), $search_all);
258 305
 }
259
-if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
260 306
 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
261 307
 // Add where from extra fields
262 308
 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
@@ -290,9 +336,11 @@  discard block
 block discarded – undo
290 336
 {
291 337
 	$resql = $db->query($sql);
292 338
 	$nbtotalofrecords = $db->num_rows($resql);
293
-	if (($page * $limit) > $nbtotalofrecords)	// if total of record found is smaller than page * limit, goto and load page 0
339
+	if (($page * $limit) > $nbtotalofrecords) {
340
+		// if total of record found is smaller than page * limit, goto and load page 0
294 341
 	{
295 342
 		$page = 0;
343
+	}
296 344
 		$offset = 0;
297 345
 	}
298 346
 }
@@ -301,7 +349,9 @@  discard block
 block discarded – undo
301 349
 {
302 350
 	$num = $nbtotalofrecords;
303 351
 } else {
304
-	if ($limit) $sql .= $db->plimit($limit + 1, $offset);
352
+	if ($limit) {
353
+		$sql .= $db->plimit($limit + 1, $offset);
354
+	}
305 355
 
306 356
 	$resql = $db->query($sql);
307 357
 	if (!$resql)
@@ -346,14 +396,23 @@  discard block
 block discarded – undo
346 396
 $arrayofselected = is_array($toselect) ? $toselect : array();
347 397
 
348 398
 $param = '';
349
-if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
350
-if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
399
+if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
400
+	$param .= '&contextpage='.urlencode($contextpage);
401
+}
402
+if ($limit > 0 && $limit != $conf->liste_limit) {
403
+	$param .= '&limit='.urlencode($limit);
404
+}
351 405
 foreach ($search as $key => $val)
352 406
 {
353
-	if (is_array($search[$key]) && count($search[$key])) foreach ($search[$key] as $skey) $param .= '&search_'.$key.'[]='.urlencode($skey);
354
-	else $param .= '&search_'.$key.'='.urlencode($search[$key]);
407
+	if (is_array($search[$key]) && count($search[$key])) {
408
+		foreach ($search[$key] as $skey) $param .= '&search_'.$key.'[]='.urlencode($skey);
409
+	} else {
410
+		$param .= '&search_'.$key.'='.urlencode($search[$key]);
411
+	}
412
+	}
413
+if ($optioncss != '') {
414
+	$param .= '&optioncss='.urlencode($optioncss);
355 415
 }
356
-if ($optioncss != '')     $param .= '&optioncss='.urlencode($optioncss);
357 416
 // Add $param from extra fields
358 417
 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
359 418
 
@@ -364,12 +423,18 @@  discard block
 block discarded – undo
364 423
 	//'builddoc'=>$langs->trans("PDFMerge"),
365 424
 	//'presend'=>$langs->trans("SendByMail"),
366 425
 );
367
-if ($permissiontodelete) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
368
-if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
426
+if ($permissiontodelete) {
427
+	$arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
428
+}
429
+if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
430
+	$arrayofmassactions = array();
431
+}
369 432
 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
370 433
 
371 434
 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
372
-if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
435
+if ($optioncss != '') {
436
+	print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
437
+}
373 438
 print '<input type="hidden" name="token" value="'.newToken().'">';
374 439
 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
375 440
 print '<input type="hidden" name="action" value="list">';
@@ -391,7 +456,9 @@  discard block
 block discarded – undo
391 456
 
392 457
 if ($search_all)
393 458
 {
394
-	foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
459
+	foreach ($fieldstosearchall as $key => $val) {
460
+		$fieldstosearchall[$key] = $langs->trans($val);
461
+	}
395 462
 	print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
396 463
 }
397 464
 
@@ -402,8 +469,11 @@  discard block
 block discarded – undo
402 469
 
403 470
 $parameters = array();
404 471
 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
405
-if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
406
-else $moreforfilter = $hookmanager->resPrint;
472
+if (empty($reshook)) {
473
+	$moreforfilter .= $hookmanager->resPrint;
474
+} else {
475
+	$moreforfilter = $hookmanager->resPrint;
476
+}
407 477
 
408 478
 if (!empty($moreforfilter))
409 479
 {
@@ -426,17 +496,25 @@  discard block
 block discarded – undo
426 496
 foreach ($object->fields as $key => $val)
427 497
 {
428 498
 	$cssforfield = (empty($val['css']) ? '' : $val['css']);
429
-	if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
430
-	elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
431
-	elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
432
-	elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right';
499
+	if ($key == 'status') {
500
+		$cssforfield .= ($cssforfield ? ' ' : '').'center';
501
+	} elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
502
+		$cssforfield .= ($cssforfield ? ' ' : '').'center';
503
+	} elseif (in_array($val['type'], array('timestamp'))) {
504
+		$cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
505
+	} elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
506
+		$cssforfield .= ($cssforfield ? ' ' : '').'right';
507
+	}
433 508
 	if (!empty($arrayfields['t.'.$key]['checked']))
434 509
 	{
435 510
 		print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
436
-		if (is_array($val['arrayofkeyval'])) print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth75');
437
-		elseif (strpos($val['type'], 'integer:') === 0) {
511
+		if (is_array($val['arrayofkeyval'])) {
512
+			print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth75');
513
+		} elseif (strpos($val['type'], 'integer:') === 0) {
438 514
 			print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1);
439
-		} elseif (!preg_match('/^(date|timestamp)/', $val['type'])) print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">';
515
+		} elseif (!preg_match('/^(date|timestamp)/', $val['type'])) {
516
+			print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">';
517
+		}
440 518
 		print '</td>';
441 519
 	}
442 520
 }
@@ -461,10 +539,15 @@  discard block
 block discarded – undo
461 539
 foreach ($object->fields as $key => $val)
462 540
 {
463 541
 	$cssforfield = (empty($val['css']) ? '' : $val['css']);
464
-	if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
465
-	elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
466
-	elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
467
-	elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right';
542
+	if ($key == 'status') {
543
+		$cssforfield .= ($cssforfield ? ' ' : '').'center';
544
+	} elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
545
+		$cssforfield .= ($cssforfield ? ' ' : '').'center';
546
+	} elseif (in_array($val['type'], array('timestamp'))) {
547
+		$cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
548
+	} elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
549
+		$cssforfield .= ($cssforfield ? ' ' : '').'right';
550
+	}
468 551
 	if (!empty($arrayfields['t.'.$key]['checked']))
469 552
 	{
470 553
 		print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
@@ -487,7 +570,10 @@  discard block
 block discarded – undo
487 570
 {
488 571
 	foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val)
489 572
 	{
490
-		if (preg_match('/\$object/', $val)) $needToFetchEachLine++; // There is at least one compute field that use $object
573
+		if (preg_match('/\$object/', $val)) {
574
+			$needToFetchEachLine++;
575
+		}
576
+		// There is at least one compute field that use $object
491 577
 	}
492 578
 }
493 579
 
@@ -499,7 +585,10 @@  discard block
 block discarded – undo
499 585
 while ($i < ($limit ? min($num, $limit) : $num))
500 586
 {
501 587
 	$obj = $db->fetch_object($resql);
502
-	if (empty($obj)) break; // Should not happen
588
+	if (empty($obj)) {
589
+		break;
590
+	}
591
+	// Should not happen
503 592
 
504 593
 	// Store properties in $object
505 594
 	$object->setVarsFromFetchObj($obj);
@@ -509,25 +598,40 @@  discard block
 block discarded – undo
509 598
 	foreach ($object->fields as $key => $val)
510 599
 	{
511 600
 		$cssforfield = (empty($val['css']) ? '' : $val['css']);
512
-		if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
513
-		elseif ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
601
+		if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
602
+			$cssforfield .= ($cssforfield ? ' ' : '').'center';
603
+		} elseif ($key == 'status') {
604
+			$cssforfield .= ($cssforfield ? ' ' : '').'center';
605
+		}
514 606
 
515
-		if (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
516
-		elseif ($key == 'ref') $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
607
+		if (in_array($val['type'], array('timestamp'))) {
608
+			$cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
609
+		} elseif ($key == 'ref') {
610
+			$cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
611
+		}
517 612
 
518
-		if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') $cssforfield .= ($cssforfield ? ' ' : '').'right';
613
+		if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') {
614
+			$cssforfield .= ($cssforfield ? ' ' : '').'right';
615
+		}
519 616
 		//if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
520 617
 
521 618
 		if (!empty($arrayfields['t.'.$key]['checked']))
522 619
 		{
523 620
 			print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
524
-			if ($key == 'status') print $object->getLibStatut(5);
525
-			else print $object->showOutputField($val, $key, $object->$key, '');
621
+			if ($key == 'status') {
622
+				print $object->getLibStatut(5);
623
+			} else {
624
+				print $object->showOutputField($val, $key, $object->$key, '');
625
+			}
526 626
 			print '</td>';
527
-			if (!$i) $totalarray['nbfield']++;
627
+			if (!$i) {
628
+				$totalarray['nbfield']++;
629
+			}
528 630
 			if (!empty($val['isameasure']))
529 631
 			{
530
-				if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
632
+				if (!$i) {
633
+					$totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
634
+				}
531 635
 				$totalarray['val']['t.'.$key] += $object->$key;
532 636
 			}
533 637
 		}
@@ -540,14 +644,20 @@  discard block
 block discarded – undo
540 644
 	print $hookmanager->resPrint;
541 645
 	// Action column
542 646
 	print '<td class="nowrap center">';
543
-	if ($massactionbutton || $massaction)   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
647
+	if ($massactionbutton || $massaction) {
648
+		// If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
544 649
 	{
545 650
 		$selected = 0;
546
-		if (in_array($object->id, $arrayofselected)) $selected = 1;
651
+	}
652
+		if (in_array($object->id, $arrayofselected)) {
653
+			$selected = 1;
654
+		}
547 655
 		print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
548 656
 	}
549 657
 	print '</td>';
550
-	if (!$i) $totalarray['nbfield']++;
658
+	if (!$i) {
659
+		$totalarray['nbfield']++;
660
+	}
551 661
 
552 662
 	print '</tr>'."\n";
553 663
 
@@ -561,7 +671,10 @@  discard block
 block discarded – undo
561 671
 if ($num == 0)
562 672
 {
563 673
 	$colspan = 1;
564
-	foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
674
+	foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) {
675
+		$colspan++;
676
+	}
677
+	}
565 678
 	print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
566 679
 }
567 680
 
@@ -580,7 +693,9 @@  discard block
 block discarded – undo
580 693
 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords))
581 694
 {
582 695
 	$hidegeneratedfilelistifempty = 1;
583
-	if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0;
696
+	if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
697
+		$hidegeneratedfilelistifempty = 0;
698
+	}
584 699
 
585 700
 	require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
586 701
 	$formfile = new FormFile($db);
Please login to merge, or discard this patch.
htdocs/core/class/commonobject.class.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
 
698 698
 				if (!empty($extralanguages->attributes[$elementforaltlanguage]['address']) || !empty($extralanguages->attributes[$elementforaltlanguage]['town']))
699 699
 				{
700
-					$out .= "<!-- alternatelanguage for '".$elementforaltlanguage."' set to fields '".join(',', $extralanguages->attributes[$elementforaltlanguage]). "' -->\n";
700
+					$out .= "<!-- alternatelanguage for '".$elementforaltlanguage."' set to fields '".join(',', $extralanguages->attributes[$elementforaltlanguage])."' -->\n";
701 701
 					$this->fetchValuesForExtraLanguages();
702 702
 					if (!is_object($form)) $form = new Form($this->db);
703 703
 					$htmltext = '';
@@ -1816,7 +1816,7 @@  discard block
 block discarded – undo
1816 1816
 		} elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid
1817 1817
 		elseif ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid
1818 1818
 		if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid)  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc";
1819
-		$sql .= " WHERE te.".$fieldid." < '".$this->db->escape($fieldid=='rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
1819
+		$sql .= " WHERE te.".$fieldid." < '".$this->db->escape($fieldid == 'rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
1820 1820
 		if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id;
1821 1821
 		if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)';
1822 1822
 		if (!empty($filter))
@@ -1869,7 +1869,7 @@  discard block
 block discarded – undo
1869 1869
 		} elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid
1870 1870
 		elseif ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid
1871 1871
 		if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc";
1872
-		$sql .= " WHERE te.".$fieldid." > '".$this->db->escape($fieldid=='rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
1872
+		$sql .= " WHERE te.".$fieldid." > '".$this->db->escape($fieldid == 'rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
1873 1873
 		if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id;
1874 1874
 		if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)';
1875 1875
 		if (!empty($filter))
@@ -4786,7 +4786,7 @@  discard block
 block discarded – undo
4786 4786
 				    return -1;
4787 4787
 			    }
4788 4788
 		    } else {
4789
-		    	if (! $filefound) {
4789
+		    	if (!$filefound) {
4790 4790
 			    	$this->error = $langs->trans("Error").' Failed to load doc generator with modelpaths='.$modelspath.' - modele='.$modele;
4791 4791
 			    	dol_print_error('', $this->error);
4792 4792
 		    	} else {
@@ -6724,8 +6724,8 @@  discard block
 block discarded – undo
6724 6724
 
6725 6725
 		$out = '';
6726 6726
 
6727
-		$parameters=array();
6728
-		$reshook=$hookmanager->executeHooks('showOptionals', $parameters, $this, $action); // Note that $action and $object may have been modified by hook
6727
+		$parameters = array();
6728
+		$reshook = $hookmanager->executeHooks('showOptionals', $parameters, $this, $action); // Note that $action and $object may have been modified by hook
6729 6729
 		if (empty($reshook))
6730 6730
 		{
6731 6731
 			if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label']) > 0)
@@ -7976,7 +7976,7 @@  discard block
 block discarded – undo
7976 7976
             foreach ($this->childtablesoncascade as $table)
7977 7977
             {
7978 7978
 	            $deleteFromObject = explode(':', $table);
7979
-	            if (count($deleteFromObject)>=2) {
7979
+	            if (count($deleteFromObject) >= 2) {
7980 7980
 		            $className = str_replace('@', '', $deleteFromObject[0]);
7981 7981
 		            $filePath = $deleteFromObject[1];
7982 7982
 		            $columnName = $deleteFromObject[2];
@@ -7996,12 +7996,12 @@  discard block
 block discarded – undo
7996 7996
 						}
7997 7997
 		            } else {
7998 7998
 			            $error++;
7999
-						$this->errors[] = 'Cannot include child class file ' .$filePath;
7999
+						$this->errors[] = 'Cannot include child class file '.$filePath;
8000 8000
 			            break;
8001 8001
 		            }
8002 8002
 	            } else {
8003 8003
 	            	// Delete record in child table
8004
-	            	$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $table . ' WHERE ' . $this->fk_element . ' = ' . $this->id;
8004
+	            	$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.$this->fk_element.' = '.$this->id;
8005 8005
 
8006 8006
 		            $resql = $this->db->query($sql);
8007 8007
 		            if (!$resql) {
@@ -8068,8 +8068,8 @@  discard block
 block discarded – undo
8068 8068
 		if (!empty($parentId) && !empty($parentField)) {
8069 8069
 			$this->db->begin();
8070 8070
 
8071
-			$sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . $this->table_element;
8072
-			$sql .= ' WHERE '.$parentField.' = ' . (int) $parentId;
8071
+			$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element;
8072
+			$sql .= ' WHERE '.$parentField.' = '.(int) $parentId;
8073 8073
 
8074 8074
 			$resql = $this->db->query($sql);
8075 8075
 			if (!$resql) {
Please login to merge, or discard this patch.
Braces   +1305 added lines, -459 removed lines patch added patch discarded remove patch
@@ -475,23 +475,31 @@  discard block
 block discarded – undo
475 475
 		$sql .= " FROM ".MAIN_DB_PREFIX.$element;
476 476
 		$sql .= " WHERE entity IN (".getEntity($element).")";
477 477
 
478
-		if ($id > 0) $sql .= " AND rowid = ".$db->escape($id);
479
-		elseif ($ref) $sql .= " AND ref = '".$db->escape($ref)."'";
480
-		elseif ($ref_ext) $sql .= " AND ref_ext = '".$db->escape($ref_ext)."'";
481
-		else {
478
+		if ($id > 0) {
479
+			$sql .= " AND rowid = ".$db->escape($id);
480
+		} elseif ($ref) {
481
+			$sql .= " AND ref = '".$db->escape($ref)."'";
482
+		} elseif ($ref_ext) {
483
+			$sql .= " AND ref_ext = '".$db->escape($ref_ext)."'";
484
+		} else {
482 485
 			$error = 'ErrorWrongParameters';
483 486
 			dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR);
484 487
 			return -1;
485 488
 		}
486
-		if ($ref || $ref_ext) $sql .= " AND entity = ".$conf->entity;
489
+		if ($ref || $ref_ext) {
490
+			$sql .= " AND entity = ".$conf->entity;
491
+		}
487 492
 
488 493
 		dol_syslog(get_class()."::isExistingObject", LOG_DEBUG);
489 494
 		$resql = $db->query($sql);
490 495
 		if ($resql)
491 496
 		{
492 497
 			$num = $db->num_rows($resql);
493
-			if ($num > 0) return 1;
494
-			else return 0;
498
+			if ($num > 0) {
499
+				return 1;
500
+			} else {
501
+				return 0;
502
+			}
495 503
 		}
496 504
 		return -1;
497 505
 	}
@@ -561,13 +569,18 @@  discard block
 block discarded – undo
561 569
 		//print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n";
562 570
 		$lastname = $this->lastname;
563 571
 		$firstname = $this->firstname;
564
-		if (empty($lastname))  $lastname = (isset($this->lastname) ? $this->lastname : (isset($this->name) ? $this->name : (isset($this->nom) ? $this->nom : (isset($this->societe) ? $this->societe : (isset($this->company) ? $this->company : '')))));
572
+		if (empty($lastname)) {
573
+			$lastname = (isset($this->lastname) ? $this->lastname : (isset($this->name) ? $this->name : (isset($this->nom) ? $this->nom : (isset($this->societe) ? $this->societe : (isset($this->company) ? $this->company : '')))));
574
+		}
565 575
 
566 576
 		$ret = '';
567 577
 		if ($option && $this->civility_code)
568 578
 		{
569
-			if ($langs->transnoentitiesnoconv("Civility".$this->civility_code) != "Civility".$this->civility_code) $ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_code).' ';
570
-			else $ret .= $this->civility_code.' ';
579
+			if ($langs->transnoentitiesnoconv("Civility".$this->civility_code) != "Civility".$this->civility_code) {
580
+				$ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_code).' ';
581
+			} else {
582
+				$ret .= $this->civility_code.' ';
583
+			}
571 584
 		}
572 585
 
573 586
 		$ret .= dolGetFirstLastname($firstname, $lastname, $nameorder);
@@ -686,7 +699,9 @@  discard block
 block discarded – undo
686 699
 
687 700
 			// List of extra languages
688 701
 			$arrayoflangcode = array();
689
-			if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE)) $arrayoflangcode[] = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
702
+			if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE)) {
703
+				$arrayoflangcode[] = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
704
+			}
690 705
 
691 706
 			if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
692 707
 				if (!is_object($extralanguages)) {
@@ -699,7 +714,9 @@  discard block
 block discarded – undo
699 714
 				{
700 715
 					$out .= "<!-- alternatelanguage for '".$elementforaltlanguage."' set to fields '".join(',', $extralanguages->attributes[$elementforaltlanguage]). "' -->\n";
701 716
 					$this->fetchValuesForExtraLanguages();
702
-					if (!is_object($form)) $form = new Form($this->db);
717
+					if (!is_object($form)) {
718
+						$form = new Form($this->db);
719
+					}
703 720
 					$htmltext = '';
704 721
 					// If there is extra languages
705 722
 					foreach ($arrayoflangcode as $extralangcode) {
@@ -723,7 +740,9 @@  discard block
 block discarded – undo
723 740
 			$outdone++;
724 741
 		}
725 742
 
726
-		if (!empty($this->phone) || !empty($this->phone_pro) || !empty($this->phone_mobile) || !empty($this->phone_perso) || !empty($this->fax) || !empty($this->office_phone) || !empty($this->user_mobile) || !empty($this->office_fax)) $out .= ($outdone ? '<br>' : '');
743
+		if (!empty($this->phone) || !empty($this->phone_pro) || !empty($this->phone_mobile) || !empty($this->phone_perso) || !empty($this->fax) || !empty($this->office_phone) || !empty($this->user_mobile) || !empty($this->office_fax)) {
744
+			$out .= ($outdone ? '<br>' : '');
745
+		}
727 746
 		if (!empty($this->phone) && empty($this->phone_pro)) {		// For objects that store pro phone into ->phone
728 747
 			$out .= dol_print_phone($this->phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePro")); $outdone++;
729 748
 		}
@@ -749,7 +768,9 @@  discard block
 block discarded – undo
749 768
 			$out .= dol_print_phone($this->office_fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', '&nbsp;', 'fax', $langs->trans("Fax")); $outdone++;
750 769
 		}
751 770
 
752
-		if ($out) $out .= '<div style="clear: both;"></div>';
771
+		if ($out) {
772
+			$out .= '<div style="clear: both;"></div>';
773
+		}
753 774
 		$outdone = 0;
754 775
 		if (!empty($this->email))
755 776
 		{
@@ -773,15 +794,25 @@  discard block
 block discarded – undo
773 794
 					$outdone++;
774 795
 				}
775 796
 			} else {
776
-				if ($this->skype) $outsocialnetwork .= dol_print_socialnetworks($this->skype, $this->id, $object->id, 'skype');
797
+				if ($this->skype) {
798
+					$outsocialnetwork .= dol_print_socialnetworks($this->skype, $this->id, $object->id, 'skype');
799
+				}
777 800
 				$outdone++;
778
-				if ($this->jabberid) $outsocialnetwork .= dol_print_socialnetworks($this->jabberid, $this->id, $object->id, 'jabber');
801
+				if ($this->jabberid) {
802
+					$outsocialnetwork .= dol_print_socialnetworks($this->jabberid, $this->id, $object->id, 'jabber');
803
+				}
779 804
 				$outdone++;
780
-				if ($this->twitter) $outsocialnetwork .= dol_print_socialnetworks($this->twitter, $this->id, $object->id, 'twitter');
805
+				if ($this->twitter) {
806
+					$outsocialnetwork .= dol_print_socialnetworks($this->twitter, $this->id, $object->id, 'twitter');
807
+				}
781 808
 				$outdone++;
782
-				if ($this->facebook) $outsocialnetwork .= dol_print_socialnetworks($this->facebook, $this->id, $object->id, 'facebook');
809
+				if ($this->facebook) {
810
+					$outsocialnetwork .= dol_print_socialnetworks($this->facebook, $this->id, $object->id, 'facebook');
811
+				}
783 812
 				$outdone++;
784
-				if ($this->linkedin) $outsocialnetwork .= dol_print_socialnetworks($this->linkedin, $this->id, $object->id, 'linkedin');
813
+				if ($this->linkedin) {
814
+					$outsocialnetwork .= dol_print_socialnetworks($this->linkedin, $this->id, $object->id, 'linkedin');
815
+				}
785 816
 				$outdone++;
786 817
 			}
787 818
 
@@ -790,8 +821,11 @@  discard block
 block discarded – undo
790 821
 			}
791 822
 		}
792 823
 
793
-		if ($out) return '<!-- BEGIN part to show address block -->'."\n".$out.'<!-- END Part to show address block -->'."\n";
794
-		else return '';
824
+		if ($out) {
825
+			return '<!-- BEGIN part to show address block -->'."\n".$out.'<!-- END Part to show address block -->'."\n";
826
+		} else {
827
+			return '';
828
+		}
795 829
 	}
796 830
 
797 831
 	/**
@@ -844,7 +878,9 @@  discard block
 block discarded – undo
844 878
 					$this->errors = $ecmfile->errors;
845 879
 				}
846 880
 				*/
847
-			} else return '';
881
+			} else {
882
+				return '';
883
+			}
848 884
 		} elseif (empty($ecmfile->share))
849 885
 		{
850 886
 			// Add entry into index
@@ -853,7 +889,9 @@  discard block
 block discarded – undo
853 889
 				require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
854 890
 				$ecmfile->share = getRandomPassword(true);
855 891
 				$ecmfile->update($user);
856
-			} else return '';
892
+			} else {
893
+				return '';
894
+			}
857 895
 		}
858 896
 		// Define $urlwithroot
859 897
 		$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
@@ -869,8 +907,13 @@  discard block
 block discarded – undo
869 907
 		//if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart;		// For sharing with hash (so public files), modulepart is not required.
870 908
 		//if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; 					// For sharing with hash (so public files), entity is not required.
871 909
 		//$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath);								// No need of name of file for public link, we will use the hash
872
-		if (!empty($ecmfile->share)) $paramlink .= ($paramlink ? '&' : '').'hashp='.$ecmfile->share; // Hash for public share
873
-		if ($forcedownload) $paramlink .= ($paramlink ? '&' : '').'attachment=1';
910
+		if (!empty($ecmfile->share)) {
911
+			$paramlink .= ($paramlink ? '&' : '').'hashp='.$ecmfile->share;
912
+		}
913
+		// Hash for public share
914
+		if ($forcedownload) {
915
+			$paramlink .= ($paramlink ? '&' : '').'attachment=1';
916
+		}
874 917
 
875 918
 		if ($relativelink)
876 919
 		{
@@ -934,7 +977,9 @@  discard block
 block discarded – undo
934 977
 			if ($resql)
935 978
 			{
936 979
 				$obj = $this->db->fetch_object($resql);
937
-				if ($obj) $id_type_contact = $obj->rowid;
980
+				if ($obj) {
981
+					$id_type_contact = $obj->rowid;
982
+				}
938 983
 			}
939 984
 		}
940 985
 
@@ -998,7 +1043,9 @@  discard block
 block discarded – undo
998 1043
 					return -1;
999 1044
 				}
1000 1045
 			}
1001
-		} else return 0;
1046
+		} else {
1047
+			return 0;
1048
+		}
1002 1049
 	}
1003 1050
 
1004 1051
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
@@ -1040,8 +1087,12 @@  discard block
 block discarded – undo
1040 1087
 		// Insert into database
1041 1088
 		$sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set";
1042 1089
 		$sql .= " statut = ".$statut;
1043
-		if ($type_contact_id) $sql .= ", fk_c_type_contact = '".$type_contact_id."'";
1044
-		if ($fk_socpeople) $sql .= ", fk_socpeople = '".$fk_socpeople."'";
1090
+		if ($type_contact_id) {
1091
+			$sql .= ", fk_c_type_contact = '".$type_contact_id."'";
1092
+		}
1093
+		if ($fk_socpeople) {
1094
+			$sql .= ", fk_socpeople = '".$fk_socpeople."'";
1095
+		}
1045 1096
 		$sql .= " where rowid = ".$rowid;
1046 1097
 		$resql = $this->db->query($sql);
1047 1098
 		if ($resql)
@@ -1112,8 +1163,9 @@  discard block
 block discarded – undo
1112 1163
 
1113 1164
 		$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact";
1114 1165
 		$sql .= " WHERE element_id = ".$this->id;
1115
-		if ($listId)
1116
-			$sql .= " AND fk_c_type_contact IN (".$listId.")";
1166
+		if ($listId) {
1167
+					$sql .= " AND fk_c_type_contact IN (".$listId.")";
1168
+		}
1117 1169
 
1118 1170
 		dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG);
1119 1171
 		if ($this->db->query($sql))
@@ -1143,22 +1195,38 @@  discard block
 block discarded – undo
1143 1195
 		$tab = array();
1144 1196
 
1145 1197
 		$sql = "SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact"; // This field contains id of llx_socpeople or id of llx_user
1146
-		if ($source == 'internal') $sql .= ", '-1' as socid, t.statut as statuscontact, t.login, t.photo";
1147
-		if ($source == 'external' || $source == 'thirdparty') $sql .= ", t.fk_soc as socid, t.statut as statuscontact";
1198
+		if ($source == 'internal') {
1199
+			$sql .= ", '-1' as socid, t.statut as statuscontact, t.login, t.photo";
1200
+		}
1201
+		if ($source == 'external' || $source == 'thirdparty') {
1202
+			$sql .= ", t.fk_soc as socid, t.statut as statuscontact";
1203
+		}
1148 1204
 		$sql .= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email";
1149 1205
 		$sql .= ", tc.source, tc.element, tc.code, tc.libelle";
1150 1206
 		$sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact tc";
1151 1207
 		$sql .= ", ".MAIN_DB_PREFIX."element_contact ec";
1152
-		if ($source == 'internal') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid";
1153
-		if ($source == 'external' || $source == 'thirdparty') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid";
1208
+		if ($source == 'internal') {
1209
+			$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid";
1210
+		}
1211
+		if ($source == 'external' || $source == 'thirdparty') {
1212
+			$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid";
1213
+		}
1154 1214
 		$sql .= " WHERE ec.element_id =".$this->id;
1155 1215
 		$sql .= " AND ec.fk_c_type_contact=tc.rowid";
1156 1216
 		$sql .= " AND tc.element='".$this->db->escape($this->element)."'";
1157
-		if ($code) $sql .= " AND tc.code = '".$this->db->escape($code)."'";
1158
-		if ($source == 'internal') $sql .= " AND tc.source = 'internal'";
1159
-		if ($source == 'external' || $source == 'thirdparty') $sql .= " AND tc.source = 'external'";
1217
+		if ($code) {
1218
+			$sql .= " AND tc.code = '".$this->db->escape($code)."'";
1219
+		}
1220
+		if ($source == 'internal') {
1221
+			$sql .= " AND tc.source = 'internal'";
1222
+		}
1223
+		if ($source == 'external' || $source == 'thirdparty') {
1224
+			$sql .= " AND tc.source = 'external'";
1225
+		}
1160 1226
 		$sql .= " AND tc.active=1";
1161
-		if ($status >= 0) $sql .= " AND ec.statut = ".$status;
1227
+		if ($status >= 0) {
1228
+			$sql .= " AND ec.statut = ".$status;
1229
+		}
1162 1230
 		$sql .= " ORDER BY t.lastname ASC";
1163 1231
 
1164 1232
 		dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG);
@@ -1244,16 +1312,27 @@  discard block
 block discarded – undo
1244 1312
         // phpcs:enable
1245 1313
 		global $langs;
1246 1314
 
1247
-		if (empty($order)) $order = 'position';
1248
-		if ($order == 'position') $order .= ',code';
1315
+		if (empty($order)) {
1316
+			$order = 'position';
1317
+		}
1318
+		if ($order == 'position') {
1319
+			$order .= ',code';
1320
+		}
1249 1321
 
1250 1322
 		$tab = array();
1251 1323
 		$sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position";
1252 1324
 		$sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";
1253 1325
 		$sql .= " WHERE tc.element='".$this->db->escape($this->element)."'";
1254
-		if ($activeonly == 1) $sql .= " AND tc.active=1"; // only the active types
1255
-		if (!empty($source) && $source != 'all') $sql .= " AND tc.source='".$this->db->escape($source)."'";
1256
-		if (!empty($code)) $sql .= " AND tc.code='".$this->db->escape($code)."'";
1326
+		if ($activeonly == 1) {
1327
+			$sql .= " AND tc.active=1";
1328
+		}
1329
+		// only the active types
1330
+		if (!empty($source) && $source != 'all') {
1331
+			$sql .= " AND tc.source='".$this->db->escape($source)."'";
1332
+		}
1333
+		if (!empty($code)) {
1334
+			$sql .= " AND tc.code='".$this->db->escape($code)."'";
1335
+		}
1257 1336
 		$sql .= $this->db->order($order, 'ASC');
1258 1337
 
1259 1338
 		//print "sql=".$sql;
@@ -1268,8 +1347,11 @@  discard block
 block discarded – undo
1268 1347
 
1269 1348
 				$transkey = "TypeContact_".$this->element."_".$source."_".$obj->code;
1270 1349
 				$libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle);
1271
-				if (empty($option)) $tab[$obj->rowid] = $libelle_type;
1272
-				else $tab[$obj->code] = $libelle_type;
1350
+				if (empty($option)) {
1351
+					$tab[$obj->rowid] = $libelle_type;
1352
+				} else {
1353
+					$tab[$obj->code] = $libelle_type;
1354
+				}
1273 1355
 				$i++;
1274 1356
 			}
1275 1357
 			return $tab;
@@ -1310,14 +1392,18 @@  discard block
 block discarded – undo
1310 1392
 			$sqlWhere[] = " tc.element <> '".$this->db->escape($excludeelement)."'";
1311 1393
 		}
1312 1394
 
1313
-		if ($activeonly == 1)
1314
-			$sqlWhere[] = " tc.active=1"; // only the active types
1395
+		if ($activeonly == 1) {
1396
+					$sqlWhere[] = " tc.active=1";
1397
+		}
1398
+		// only the active types
1315 1399
 
1316
-		if (!empty($source) && $source != 'all')
1317
-			$sqlWhere[] = " tc.source='".$this->db->escape($source)."'";
1400
+		if (!empty($source) && $source != 'all') {
1401
+					$sqlWhere[] = " tc.source='".$this->db->escape($source)."'";
1402
+		}
1318 1403
 
1319
-		if (!empty($code))
1320
-			$sqlWhere[] = " tc.code='".$this->db->escape($code)."'";
1404
+		if (!empty($code)) {
1405
+					$sqlWhere[] = " tc.code='".$this->db->escape($code)."'";
1406
+		}
1321 1407
 
1322 1408
 		if (count($sqlWhere) > 0) {
1323 1409
 			$sql .= " WHERE ".implode(' AND ', $sqlWhere);
@@ -1347,9 +1433,11 @@  discard block
 block discarded – undo
1347 1433
 						$libelle_element = $langs->trans('ContactDefault_'.$obj->element);
1348 1434
 						$transkey = "TypeContact_".$obj->element."_".$source."_".$obj->code;
1349 1435
 						$libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle);
1350
-						if (empty($option))
1436
+						if (empty($option)) {
1437
+													$tab[$obj->rowid] = $libelle_element.' - '.$libelle_type;
1438
+						} else {
1351 1439
 							$tab[$obj->rowid] = $libelle_element.' - '.$libelle_type;
1352
-						else $tab[$obj->rowid] = $libelle_element.' - '.$libelle_type;
1440
+						}
1353 1441
 					}
1354 1442
 				}
1355 1443
 			}
@@ -1391,19 +1479,31 @@  discard block
 block discarded – undo
1391 1479
 
1392 1480
 		$sql = "SELECT ec.fk_socpeople";
1393 1481
 		$sql .= " FROM ".MAIN_DB_PREFIX."element_contact as ec,";
1394
-		if ($source == 'internal') $sql .= " ".MAIN_DB_PREFIX."user as c,";
1395
-		if ($source == 'external') $sql .= " ".MAIN_DB_PREFIX."socpeople as c,";
1482
+		if ($source == 'internal') {
1483
+			$sql .= " ".MAIN_DB_PREFIX."user as c,";
1484
+		}
1485
+		if ($source == 'external') {
1486
+			$sql .= " ".MAIN_DB_PREFIX."socpeople as c,";
1487
+		}
1396 1488
 		$sql .= " ".MAIN_DB_PREFIX."c_type_contact as tc";
1397 1489
 		$sql .= " WHERE ec.element_id = ".$id;
1398 1490
 		$sql .= " AND ec.fk_socpeople = c.rowid";
1399
-		if ($source == 'internal') $sql .= " AND c.entity IN (".getEntity('user').")";
1400
-		if ($source == 'external') $sql .= " AND c.entity IN (".getEntity('societe').")";
1491
+		if ($source == 'internal') {
1492
+			$sql .= " AND c.entity IN (".getEntity('user').")";
1493
+		}
1494
+		if ($source == 'external') {
1495
+			$sql .= " AND c.entity IN (".getEntity('societe').")";
1496
+		}
1401 1497
 		$sql .= " AND ec.fk_c_type_contact = tc.rowid";
1402 1498
 		$sql .= " AND tc.element = '".$element."'";
1403 1499
 		$sql .= " AND tc.source = '".$source."'";
1404
-		if ($code) $sql .= " AND tc.code = '".$code."'";
1500
+		if ($code) {
1501
+			$sql .= " AND tc.code = '".$code."'";
1502
+		}
1405 1503
 		$sql .= " AND tc.active = 1";
1406
-		if ($status) $sql .= " AND ec.statut = ".$status;
1504
+		if ($status) {
1505
+			$sql .= " AND ec.statut = ".$status;
1506
+		}
1407 1507
 
1408 1508
 		dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG);
1409 1509
 		$resql = $this->db->query($sql);
@@ -1432,9 +1532,13 @@  discard block
 block discarded – undo
1432 1532
 	public function fetch_contact($contactid = null)
1433 1533
 	{
1434 1534
         // phpcs:enable
1435
-		if (empty($contactid)) $contactid = $this->contact_id;
1535
+		if (empty($contactid)) {
1536
+			$contactid = $this->contact_id;
1537
+		}
1436 1538
 
1437
-		if (empty($contactid)) return 0;
1539
+		if (empty($contactid)) {
1540
+			return 0;
1541
+		}
1438 1542
 
1439 1543
 		require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
1440 1544
 		$contact = new Contact($this->db);
@@ -1455,14 +1559,16 @@  discard block
 block discarded – undo
1455 1559
         // phpcs:enable
1456 1560
 		global $conf;
1457 1561
 
1458
-		if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id))
1459
-			return 0;
1562
+		if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) {
1563
+					return 0;
1564
+		}
1460 1565
 
1461 1566
 		require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
1462 1567
 
1463 1568
 		$idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty);
1464
-		if ($force_thirdparty_id)
1465
-			$idtofetch = $force_thirdparty_id;
1569
+		if ($force_thirdparty_id) {
1570
+					$idtofetch = $force_thirdparty_id;
1571
+		}
1466 1572
 
1467 1573
 		if ($idtofetch) {
1468 1574
 			$thirdparty = new Societe($this->db);
@@ -1475,7 +1581,9 @@  discard block
 block discarded – undo
1475 1581
 			}
1476 1582
 
1477 1583
 			return $result;
1478
-		} else return -1;
1584
+		} else {
1585
+			return -1;
1586
+		}
1479 1587
 	}
1480 1588
 
1481 1589
 
@@ -1521,18 +1629,24 @@  discard block
 block discarded – undo
1521 1629
 		dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type);
1522 1630
 
1523 1631
 		$idtype = $this->barcode_type;
1524
-		if (empty($idtype) && $idtype != '0')	// If type of barcode no set, we try to guess. If set to '0' it means we forced to have type remain not defined
1632
+		if (empty($idtype) && $idtype != '0') {
1633
+			// If type of barcode no set, we try to guess. If set to '0' it means we forced to have type remain not defined
1525 1634
 		{
1526 1635
 			if ($this->element == 'product')      $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
1527
-			elseif ($this->element == 'societe') $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY;
1528
-			else dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING);
1636
+		} elseif ($this->element == 'societe') {
1637
+				$idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY;
1638
+			} else {
1639
+				dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING);
1640
+			}
1529 1641
 		}
1530 1642
 
1531 1643
 		if ($idtype > 0)
1532 1644
 		{
1533
-			if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder))    // If data not already loaded
1645
+			if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) {
1646
+				// If data not already loaded
1534 1647
 			{
1535 1648
 				$sql = "SELECT rowid, code, libelle as label, coder";
1649
+			}
1536 1650
 				$sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
1537 1651
 				$sql .= " WHERE rowid = ".$idtype;
1538 1652
 				dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG);
@@ -1565,8 +1679,13 @@  discard block
 block discarded – undo
1565 1679
         // phpcs:enable
1566 1680
 		include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1567 1681
 
1568
-		if (empty($this->fk_project) && !empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility
1569
-		if (empty($this->fk_project)) return 0;
1682
+		if (empty($this->fk_project) && !empty($this->fk_projet)) {
1683
+			$this->fk_project = $this->fk_projet;
1684
+		}
1685
+		// For backward compatibility
1686
+		if (empty($this->fk_project)) {
1687
+			return 0;
1688
+		}
1570 1689
 
1571 1690
 		$project = new Project($this->db);
1572 1691
 		$result = $project->fetch($this->fk_project);
@@ -1587,7 +1706,9 @@  discard block
 block discarded – undo
1587 1706
         // phpcs:enable
1588 1707
 		include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
1589 1708
 
1590
-		if (empty($this->fk_product)) return 0;
1709
+		if (empty($this->fk_product)) {
1710
+			return 0;
1711
+		}
1591 1712
 
1592 1713
 		$product = new Product($this->db);
1593 1714
 		$result = $product->fetch($this->fk_product);
@@ -1621,9 +1742,15 @@  discard block
 block discarded – undo
1621 1742
 	public function fetch_origin()
1622 1743
 	{
1623 1744
         // phpcs:enable
1624
-		if ($this->origin == 'shipping') $this->origin = 'expedition';
1625
-		if ($this->origin == 'delivery') $this->origin = 'livraison';
1626
-        if ($this->origin == 'order_supplier') $this->origin = 'commandeFournisseur';
1745
+		if ($this->origin == 'shipping') {
1746
+			$this->origin = 'expedition';
1747
+		}
1748
+		if ($this->origin == 'delivery') {
1749
+			$this->origin = 'livraison';
1750
+		}
1751
+        if ($this->origin == 'order_supplier') {
1752
+        	$this->origin = 'commandeFournisseur';
1753
+        }
1627 1754
 
1628 1755
 		$origin = $this->origin;
1629 1756
 
@@ -1715,29 +1842,48 @@  discard block
 block discarded – undo
1715 1842
 	{
1716 1843
 		global $user, $langs, $conf;
1717 1844
 
1718
-		if (empty($table)) 	  $table = $this->table_element;
1719
-		if (empty($id))    	  $id = $this->id;
1720
-		if (empty($format))   $format = 'text';
1721
-		if (empty($id_field)) $id_field = 'rowid';
1845
+		if (empty($table)) {
1846
+			$table = $this->table_element;
1847
+		}
1848
+		if (empty($id)) {
1849
+			$id = $this->id;
1850
+		}
1851
+		if (empty($format)) {
1852
+			$format = 'text';
1853
+		}
1854
+		if (empty($id_field)) {
1855
+			$id_field = 'rowid';
1856
+		}
1722 1857
 
1723 1858
 		$error = 0;
1724 1859
 
1725 1860
 		$this->db->begin();
1726 1861
 
1727 1862
 		// Special case
1728
-		if ($table == 'product' && $field == 'note_private') $field = 'note';
1729
-		if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod';
1863
+		if ($table == 'product' && $field == 'note_private') {
1864
+			$field = 'note';
1865
+		}
1866
+		if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) {
1867
+			$fk_user_field = 'fk_user_mod';
1868
+		}
1730 1869
 
1731 1870
 		$sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET ";
1732 1871
 
1733
-		if ($format == 'text') $sql .= $field." = '".$this->db->escape($value)."'";
1734
-		elseif ($format == 'int') $sql .= $field." = ".$this->db->escape($value);
1735
-		elseif ($format == 'date') $sql .= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null");
1872
+		if ($format == 'text') {
1873
+			$sql .= $field." = '".$this->db->escape($value)."'";
1874
+		} elseif ($format == 'int') {
1875
+			$sql .= $field." = ".$this->db->escape($value);
1876
+		} elseif ($format == 'date') {
1877
+			$sql .= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null");
1878
+		}
1736 1879
 
1737 1880
 		if ($fk_user_field)
1738 1881
 		{
1739
-			if (!empty($fuser) && is_object($fuser)) $sql .= ", ".$fk_user_field." = ".$fuser->id;
1740
-			elseif (empty($fuser) || $fuser != 'none') $sql .= ", ".$fk_user_field." = ".$user->id;
1882
+			if (!empty($fuser) && is_object($fuser)) {
1883
+				$sql .= ", ".$fk_user_field." = ".$fuser->id;
1884
+			} elseif (empty($fuser) || $fuser != 'none') {
1885
+				$sql .= ", ".$fk_user_field." = ".$user->id;
1886
+			}
1741 1887
 		}
1742 1888
 
1743 1889
 		$sql .= " WHERE ".$id_field." = ".$id;
@@ -1755,13 +1901,20 @@  discard block
 block discarded – undo
1755 1901
 				} else {
1756 1902
 					$result = $this->fetchCommon($id);
1757 1903
 				}
1758
-				if ($result >= 0) $result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors
1759
-				if ($result < 0) $error++;
1904
+				if ($result >= 0) {
1905
+					$result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user);
1906
+				}
1907
+				// This may set this->errors
1908
+				if ($result < 0) {
1909
+					$error++;
1910
+				}
1760 1911
 			}
1761 1912
 
1762 1913
 			if (!$error)
1763 1914
 			{
1764
-				if (property_exists($this, $field)) $this->$field = $value;
1915
+				if (property_exists($this, $field)) {
1916
+					$this->$field = $value;
1917
+				}
1765 1918
 				$this->db->commit();
1766 1919
 				return 1;
1767 1920
 			} else {
@@ -1794,16 +1947,23 @@  discard block
 block discarded – undo
1794 1947
 			dol_print_error('', get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined");
1795 1948
 			return -1;
1796 1949
 		}
1797
-		if ($fieldid == 'none') return 1;
1950
+		if ($fieldid == 'none') {
1951
+			return 1;
1952
+		}
1798 1953
 
1799 1954
 		// Security on socid
1800 1955
 		$socid = 0;
1801
-		if ($user->socid > 0) $socid = $user->socid;
1956
+		if ($user->socid > 0) {
1957
+			$socid = $user->socid;
1958
+		}
1802 1959
 
1803 1960
 		// this->ismultientitymanaged contains
1804 1961
 		// 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table
1805 1962
 		$aliastablesociete = 's';
1806
-		if ($this->element == 'societe') $aliastablesociete = 'te'; // te as table_element
1963
+		if ($this->element == 'societe') {
1964
+			$aliastablesociete = 'te';
1965
+		}
1966
+		// te as table_element
1807 1967
 
1808 1968
 		$sql = "SELECT MAX(te.".$fieldid.")";
1809 1969
 		$sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te";
@@ -1813,21 +1973,39 @@  discard block
 block discarded – undo
1813 1973
 		if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
1814 1974
 			$tmparray = explode('@', $this->ismultientitymanaged);
1815 1975
 			$sql .= ", ".MAIN_DB_PREFIX.$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity
1816
-		} elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid
1817
-		elseif ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid
1818
-		if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid)  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc";
1976
+		} elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
1977
+			$sql .= ", ".MAIN_DB_PREFIX."societe as s";
1978
+		}
1979
+		// If we need to link to societe to limit select to socid
1980
+		elseif ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
1981
+			$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid";
1982
+		}
1983
+		// If we need to link to societe to limit select to socid
1984
+		if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) {
1985
+			$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc";
1986
+		}
1819 1987
 		$sql .= " WHERE te.".$fieldid." < '".$this->db->escape($fieldid=='rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
1820
-		if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id;
1821
-		if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)';
1988
+		if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) {
1989
+			$sql .= " AND sc.fk_user = ".$user->id;
1990
+		}
1991
+		if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) {
1992
+			$sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)';
1993
+		}
1822 1994
 		if (!empty($filter))
1823 1995
 		{
1824
-			if (!preg_match('/^\s*AND/i', $filter)) $sql .= " AND "; // For backward compatibility
1996
+			if (!preg_match('/^\s*AND/i', $filter)) {
1997
+				$sql .= " AND ";
1998
+			}
1999
+			// For backward compatibility
1825 2000
 			$sql .= $filter;
1826 2001
 		}
1827 2002
 		if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
1828 2003
 			$tmparray = explode('@', $this->ismultientitymanaged);
1829 2004
 			$sql .= ' AND te.'.$tmparray[0].' = '.($tmparray[1] == 'societe' ? 's' : 'parenttable').'.rowid'; // If we need to link to this table to limit select to entity
1830
-		} elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid
2005
+		} elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
2006
+			$sql .= ' AND te.fk_soc = s.rowid';
2007
+		}
2008
+		// If we need to link to societe to limit select to socid
1831 2009
 		if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
1832 2010
 			if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1833 2011
 				if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
@@ -1844,9 +2022,15 @@  discard block
 block discarded – undo
1844 2022
 			$tmparray = explode('@', $this->ismultientitymanaged);
1845 2023
 			$sql .= ' AND parenttable.entity IN ('.getEntity($tmparray[1]).')';
1846 2024
 		}
1847
-		if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql .= ' AND te.fk_soc = '.$socid;
1848
-		if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql .= ' AND (te.fk_soc = '.$socid.' OR te.fk_soc IS NULL)';
1849
-		if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql .= ' AND te.rowid = '.$socid;
2025
+		if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') {
2026
+			$sql .= ' AND te.fk_soc = '.$socid;
2027
+		}
2028
+		if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') {
2029
+			$sql .= ' AND (te.fk_soc = '.$socid.' OR te.fk_soc IS NULL)';
2030
+		}
2031
+		if ($this->restrictiononfksoc && $socid && $this->element == 'societe') {
2032
+			$sql .= ' AND te.rowid = '.$socid;
2033
+		}
1850 2034
 		//print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>";
1851 2035
 
1852 2036
 		$result = $this->db->query($sql);
@@ -1866,21 +2050,39 @@  discard block
 block discarded – undo
1866 2050
 		if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
1867 2051
 			$tmparray = explode('@', $this->ismultientitymanaged);
1868 2052
 			$sql .= ", ".MAIN_DB_PREFIX.$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity
1869
-		} elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid
1870
-		elseif ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid
1871
-		if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc";
2053
+		} elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
2054
+			$sql .= ", ".MAIN_DB_PREFIX."societe as s";
2055
+		}
2056
+		// If we need to link to societe to limit select to socid
2057
+		elseif ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
2058
+			$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid";
2059
+		}
2060
+		// If we need to link to societe to limit select to socid
2061
+		if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) {
2062
+			$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc";
2063
+		}
1872 2064
 		$sql .= " WHERE te.".$fieldid." > '".$this->db->escape($fieldid=='rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
1873
-		if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id;
1874
-		if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)';
2065
+		if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) {
2066
+			$sql .= " AND sc.fk_user = ".$user->id;
2067
+		}
2068
+		if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) {
2069
+			$sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)';
2070
+		}
1875 2071
 		if (!empty($filter))
1876 2072
 		{
1877
-			if (!preg_match('/^\s*AND/i', $filter)) $sql .= " AND "; // For backward compatibility
2073
+			if (!preg_match('/^\s*AND/i', $filter)) {
2074
+				$sql .= " AND ";
2075
+			}
2076
+			// For backward compatibility
1878 2077
 			$sql .= $filter;
1879 2078
 		}
1880 2079
 		if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
1881 2080
 			$tmparray = explode('@', $this->ismultientitymanaged);
1882 2081
 			$sql .= ' AND te.'.$tmparray[0].' = '.($tmparray[1] == 'societe' ? 's' : 'parenttable').'.rowid'; // If we need to link to this table to limit select to entity
1883
-		} elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid
2082
+		} elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
2083
+			$sql .= ' AND te.fk_soc = s.rowid';
2084
+		}
2085
+		// If we need to link to societe to limit select to socid
1884 2086
 		if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
1885 2087
 			if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1886 2088
 				if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
@@ -1897,9 +2099,15 @@  discard block
 block discarded – undo
1897 2099
 			$tmparray = explode('@', $this->ismultientitymanaged);
1898 2100
 			$sql .= ' AND parenttable.entity IN ('.getEntity($tmparray[1]).')';
1899 2101
 		}
1900
-		if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql .= ' AND te.fk_soc = '.$socid;
1901
-		if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql .= ' AND (te.fk_soc = '.$socid.' OR te.fk_soc IS NULL)';
1902
-		if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql .= ' AND te.rowid = '.$socid;
2102
+		if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') {
2103
+			$sql .= ' AND te.fk_soc = '.$socid;
2104
+		}
2105
+		if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') {
2106
+			$sql .= ' AND (te.fk_soc = '.$socid.' OR te.fk_soc IS NULL)';
2107
+		}
2108
+		if ($this->restrictiononfksoc && $socid && $this->element == 'societe') {
2109
+			$sql .= ' AND te.rowid = '.$socid;
2110
+		}
1903 2111
 		//print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>";
1904 2112
 		// Rem: Bug in some mysql version: SELECT MIN(rowid) FROM llx_socpeople WHERE rowid > 1 when one row in database with rowid=1, returns 1 instead of null
1905 2113
 
@@ -1931,8 +2139,11 @@  discard block
 block discarded – undo
1931 2139
 		$i = 0;
1932 2140
 		while ($i < $num)
1933 2141
 		{
1934
-			if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid'];
1935
-			else $contactAlreadySelected[$i] = $tab[$i]['id'];
2142
+			if ($source == 'thirdparty') {
2143
+				$contactAlreadySelected[$i] = $tab[$i]['socid'];
2144
+			} else {
2145
+				$contactAlreadySelected[$i] = $tab[$i]['id'];
2146
+			}
1936 2147
 			$i++;
1937 2148
 		}
1938 2149
 		return $contactAlreadySelected;
@@ -1954,20 +2165,29 @@  discard block
 block discarded – undo
1954 2165
 		}
1955 2166
 
1956 2167
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1957
-		if (!empty($this->fields['fk_project']))		// Common case
2168
+		if (!empty($this->fields['fk_project'])) {
2169
+			// Common case
1958 2170
 		{
1959 2171
 			if ($projectid) $sql .= ' SET fk_project = '.$projectid;
1960
-			else $sql .= ' SET fk_project = NULL';
2172
+		} else {
2173
+				$sql .= ' SET fk_project = NULL';
2174
+			}
1961 2175
 			$sql .= ' WHERE rowid = '.$this->id;
1962
-		} elseif ($this->table_element == 'actioncomm')	// Special case for actioncomm
2176
+		} elseif ($this->table_element == 'actioncomm') {
2177
+			// Special case for actioncomm
1963 2178
 		{
1964 2179
 			if ($projectid) $sql .= ' SET fk_project = '.$projectid;
1965
-			else $sql .= ' SET fk_project = NULL';
2180
+		} else {
2181
+				$sql .= ' SET fk_project = NULL';
2182
+			}
1966 2183
 			$sql .= ' WHERE id = '.$this->id;
1967 2184
 		} else // Special case for old architecture objects
1968 2185
 		{
1969
-			if ($projectid) $sql .= ' SET fk_projet = '.$projectid;
1970
-			else $sql .= ' SET fk_projet = NULL';
2186
+			if ($projectid) {
2187
+				$sql .= ' SET fk_projet = '.$projectid;
2188
+			} else {
2189
+				$sql .= ' SET fk_projet = NULL';
2190
+			}
1971 2191
 			$sql .= ' WHERE rowid = '.$this->id;
1972 2192
 		}
1973 2193
 
@@ -1995,8 +2215,12 @@  discard block
 block discarded – undo
1995 2215
 		{
1996 2216
 			// TODO uniformize field name
1997 2217
 			$fieldname = 'fk_mode_reglement';
1998
-			if ($this->element == 'societe') $fieldname = 'mode_reglement';
1999
-			if (get_class($this) == 'Fournisseur') $fieldname = 'mode_reglement_supplier';
2218
+			if ($this->element == 'societe') {
2219
+				$fieldname = 'mode_reglement';
2220
+			}
2221
+			if (get_class($this) == 'Fournisseur') {
2222
+				$fieldname = 'mode_reglement_supplier';
2223
+			}
2000 2224
 
2001 2225
 			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2002 2226
 			$sql .= ' SET '.$fieldname.' = '.(($id > 0 || $id == '0') ? $id : 'NULL');
@@ -2006,7 +2230,9 @@  discard block
 block discarded – undo
2006 2230
 			{
2007 2231
 				$this->mode_reglement_id = $id;
2008 2232
 				// for supplier
2009
-				if (get_class($this) == 'Fournisseur') $this->mode_reglement_supplier_id = $id;
2233
+				if (get_class($this) == 'Fournisseur') {
2234
+					$this->mode_reglement_supplier_id = $id;
2235
+				}
2010 2236
 				return 1;
2011 2237
 			} else {
2012 2238
 				dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error());
@@ -2042,7 +2268,9 @@  discard block
 block discarded – undo
2042 2268
 				$this->multicurrency_code = $code;
2043 2269
 
2044 2270
 				list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code);
2045
-				if ($rate) $this->setMulticurrencyRate($rate, 2);
2271
+				if ($rate) {
2272
+					$this->setMulticurrencyRate($rate, 2);
2273
+				}
2046 2274
 
2047 2275
 				return 1;
2048 2276
 			} else {
@@ -2174,8 +2402,12 @@  discard block
 block discarded – undo
2174 2402
 		{
2175 2403
 			// TODO uniformize field name
2176 2404
 			$fieldname = 'fk_cond_reglement';
2177
-			if ($this->element == 'societe') $fieldname = 'cond_reglement';
2178
-			if (get_class($this) == 'Fournisseur') $fieldname = 'cond_reglement_supplier';
2405
+			if ($this->element == 'societe') {
2406
+				$fieldname = 'cond_reglement';
2407
+			}
2408
+			if (get_class($this) == 'Fournisseur') {
2409
+				$fieldname = 'cond_reglement_supplier';
2410
+			}
2179 2411
 
2180 2412
 			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2181 2413
 			$sql .= ' SET '.$fieldname.' = '.(($id > 0 || $id == '0') ? $id : 'NULL');
@@ -2185,7 +2417,9 @@  discard block
 block discarded – undo
2185 2417
 			{
2186 2418
 				$this->cond_reglement_id = $id;
2187 2419
 				// for supplier
2188
-				if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id;
2420
+				if (get_class($this) == 'Fournisseur') {
2421
+					$this->cond_reglement_supplier_id = $id;
2422
+				}
2189 2423
 				$this->cond_reglement = $id; // for compatibility
2190 2424
 				return 1;
2191 2425
 			} else {
@@ -2244,7 +2478,9 @@  discard block
 block discarded – undo
2244 2478
 	public function setDeliveryAddress($id)
2245 2479
 	{
2246 2480
 		$fieldname = 'fk_delivery_address';
2247
-		if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address';
2481
+		if ($this->element == 'delivery' || $this->element == 'shipping') {
2482
+			$fieldname = 'fk_address';
2483
+		}
2248 2484
 
2249 2485
 		$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id;
2250 2486
 		$sql .= " WHERE rowid = ".$this->id." AND fk_statut = 0";
@@ -2274,7 +2510,9 @@  discard block
 block discarded – undo
2274 2510
 	{
2275 2511
 		global $user;
2276 2512
 
2277
-		if (empty($userused)) $userused = $user;
2513
+		if (empty($userused)) {
2514
+			$userused = $user;
2515
+		}
2278 2516
 
2279 2517
 		$error = 0;
2280 2518
 
@@ -2285,7 +2523,9 @@  discard block
 block discarded – undo
2285 2523
 
2286 2524
 		$this->db->begin();
2287 2525
 
2288
-		if ($shipping_method_id < 0) $shipping_method_id = 'NULL';
2526
+		if ($shipping_method_id < 0) {
2527
+			$shipping_method_id = 'NULL';
2528
+		}
2289 2529
 		dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')');
2290 2530
 
2291 2531
 		$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
@@ -2302,7 +2542,9 @@  discard block
 block discarded – undo
2302 2542
 				// Call trigger
2303 2543
 				$this->context = array('shippingmethodupdate'=>1);
2304 2544
 				$result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $userused);
2305
-				if ($result < 0) $error++;
2545
+				if ($result < 0) {
2546
+					$error++;
2547
+				}
2306 2548
 				// End call trigger
2307 2549
 			}
2308 2550
 		}
@@ -2330,7 +2572,9 @@  discard block
 block discarded – undo
2330 2572
 			dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined", LOG_ERR);
2331 2573
 			return -1;
2332 2574
 		}
2333
-		if ($warehouse_id < 0) $warehouse_id = 'NULL';
2575
+		if ($warehouse_id < 0) {
2576
+			$warehouse_id = 'NULL';
2577
+		}
2334 2578
 		dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')');
2335 2579
 
2336 2580
 		$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
@@ -2396,7 +2640,9 @@  discard block
 block discarded – undo
2396 2640
 	{
2397 2641
 		global $user;
2398 2642
 
2399
-		if (empty($userused)) $userused = $user;
2643
+		if (empty($userused)) {
2644
+			$userused = $user;
2645
+		}
2400 2646
 
2401 2647
 		$error = 0;
2402 2648
 
@@ -2406,7 +2652,9 @@  discard block
 block discarded – undo
2406 2652
 		}
2407 2653
 		$this->db->begin();
2408 2654
 
2409
-		if ($fk_account < 0) $fk_account = 'NULL';
2655
+		if ($fk_account < 0) {
2656
+			$fk_account = 'NULL';
2657
+		}
2410 2658
 		dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')');
2411 2659
 
2412 2660
 		$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
@@ -2425,7 +2673,9 @@  discard block
 block discarded – undo
2425 2673
 				// Call trigger
2426 2674
 				$this->context = array('bankaccountupdate'=>1);
2427 2675
 				$result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $userused);
2428
-				if ($result < 0) $error++;
2676
+				if ($result < 0) {
2677
+					$error++;
2678
+				}
2429 2679
 				// End call trigger
2430 2680
 			}
2431 2681
 		}
@@ -2471,8 +2721,12 @@  discard block
 block discarded – undo
2471 2721
 		$nl = 0;
2472 2722
 		$sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line;
2473 2723
 		$sql .= ' WHERE '.$this->fk_element.'='.$this->id;
2474
-		if (!$renum) $sql .= ' AND rang = 0';
2475
-		if ($renum) $sql .= ' AND rang <> 0';
2724
+		if (!$renum) {
2725
+			$sql .= ' AND rang = 0';
2726
+		}
2727
+		if ($renum) {
2728
+			$sql .= ' AND rang <> 0';
2729
+		}
2476 2730
 
2477 2731
 		dol_syslog(get_class($this)."::line_order", LOG_DEBUG);
2478 2732
 		$resql = $this->db->query($sql);
@@ -2480,7 +2734,9 @@  discard block
 block discarded – undo
2480 2734
 		{
2481 2735
 			$row = $this->db->fetch_row($resql);
2482 2736
 			$nl = $row[0];
2483
-		} else dol_print_error($this->db);
2737
+		} else {
2738
+			dol_print_error($this->db);
2739
+		}
2484 2740
 		if ($nl > 0)
2485 2741
 		{
2486 2742
 			// The goal of this part is to reorder all lines, with all children lines sharing the same
@@ -2490,7 +2746,9 @@  discard block
 block discarded – undo
2490 2746
 			// We first search all lines that are parent lines (for multilevel details lines)
2491 2747
 			$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line;
2492 2748
 			$sql .= ' WHERE '.$this->fk_element.' = '.$this->id;
2493
-			if ($fk_parent_line) $sql .= ' AND fk_parent_line IS NULL';
2749
+			if ($fk_parent_line) {
2750
+				$sql .= ' AND fk_parent_line IS NULL';
2751
+			}
2494 2752
 			$sql .= ' ORDER BY rang ASC, rowid '.$rowidorder;
2495 2753
 
2496 2754
 			dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG);
@@ -2552,7 +2810,9 @@  discard block
 block discarded – undo
2552 2810
 			if ($this->db->num_rows($resql) > 0) {
2553 2811
 				while ($row = $this->db->fetch_row($resql)) {
2554 2812
 					$rows[] = $row[0];
2555
-					if (!empty($includealltree)) $rows = array_merge($rows, $this->getChildrenOfLine($row[0]), $includealltree);
2813
+					if (!empty($includealltree)) {
2814
+						$rows = array_merge($rows, $this->getChildrenOfLine($row[0]), $includealltree);
2815
+					}
2556 2816
 				}
2557 2817
 			}
2558 2818
 		}
@@ -2612,7 +2872,9 @@  discard block
 block discarded – undo
2612 2872
 	public function updateRangOfLine($rowid, $rang)
2613 2873
 	{
2614 2874
 		$fieldposition = 'rang'; // @todo Rename 'rang' into 'position'
2615
-		if (in_array($this->table_element_line, array('bom_bomline', 'ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
2875
+		if (in_array($this->table_element_line, array('bom_bomline', 'ecm_files', 'emailcollector_emailcollectoraction'))) {
2876
+			$fieldposition = 'position';
2877
+		}
2616 2878
 
2617 2879
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang;
2618 2880
 		$sql .= ' WHERE rowid = '.$rowid;
@@ -2653,7 +2915,9 @@  discard block
 block discarded – undo
2653 2915
 		if ($rang > 1)
2654 2916
 		{
2655 2917
 			$fieldposition = 'rang';
2656
-			if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
2918
+			if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) {
2919
+				$fieldposition = 'position';
2920
+			}
2657 2921
 
2658 2922
 			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang;
2659 2923
 			$sql .= ' WHERE '.$this->fk_element.' = '.$this->id;
@@ -2685,7 +2949,9 @@  discard block
 block discarded – undo
2685 2949
 		if ($rang < $max)
2686 2950
 		{
2687 2951
 			$fieldposition = 'rang';
2688
-			if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
2952
+			if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) {
2953
+				$fieldposition = 'position';
2954
+			}
2689 2955
 
2690 2956
 			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang;
2691 2957
 			$sql .= ' WHERE '.$this->fk_element.' = '.$this->id;
@@ -2754,7 +3020,9 @@  discard block
 block discarded – undo
2754 3020
 	{
2755 3021
         // phpcs:enable
2756 3022
         $positionfield = 'rang';
2757
-		if ($this->table_element == 'bom') $positionfield = 'position';
3023
+		if ($this->table_element == 'bom') {
3024
+			$positionfield = 'position';
3025
+		}
2758 3026
 
2759 3027
 		// Search the last rang with fk_parent_line
2760 3028
 		if ($fk_parent_line)
@@ -2849,7 +3117,9 @@  discard block
 block discarded – undo
2849 3117
 		}
2850 3118
 		// Special cas
2851 3119
 		//var_dump($this->table_element);exit;
2852
-		if ($this->table_element == 'product') $suffix = '';
3120
+		if ($this->table_element == 'product') {
3121
+			$suffix = '';
3122
+		}
2853 3123
 
2854 3124
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2855 3125
 		$sql .= " SET note".$suffix." = ".(!empty($note) ? ("'".$this->db->escape($note)."'") : "NULL");
@@ -2859,9 +3129,11 @@  discard block
 block discarded – undo
2859 3129
 		dol_syslog(get_class($this)."::update_note", LOG_DEBUG);
2860 3130
 		if ($this->db->query($sql))
2861 3131
 		{
2862
-			if ($suffix == '_public') $this->note_public = $note;
2863
-			elseif ($suffix == '_private') $this->note_private = $note;
2864
-			else {
3132
+			if ($suffix == '_public') {
3133
+				$this->note_public = $note;
3134
+			} elseif ($suffix == '_private') {
3135
+				$this->note_private = $note;
3136
+			} else {
2865 3137
 				$this->note = $note; // deprecated
2866 3138
 				$this->note_private = $note;
2867 3139
 			}
@@ -2913,36 +3185,45 @@  discard block
 block discarded – undo
2913 3185
 
2914 3186
 		// Some external module want no update price after a trigger because they have another method to calculate the total (ex: with an extrafield)
2915 3187
 		$MODULE = "";
2916
-		if ($this->element == 'propal')
2917
-			$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL";
2918
-		elseif ($this->element == 'commande' || $this->element == 'order')
2919
-			$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER";
2920
-		elseif ($this->element == 'facture' || $this->element == 'invoice')
2921
-			$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE";
2922
-		elseif ($this->element == 'facture_fourn' || $this->element == 'supplier_invoice' || $this->element == 'invoice_supplier')
2923
-			$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE";
2924
-		elseif ($this->element == 'order_supplier' || $this->element == 'supplier_order')
2925
-			$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER";
2926
-		elseif ($this->element == 'supplier_proposal')
2927
-			$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL";
3188
+		if ($this->element == 'propal') {
3189
+					$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL";
3190
+		} elseif ($this->element == 'commande' || $this->element == 'order') {
3191
+					$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER";
3192
+		} elseif ($this->element == 'facture' || $this->element == 'invoice') {
3193
+					$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE";
3194
+		} elseif ($this->element == 'facture_fourn' || $this->element == 'supplier_invoice' || $this->element == 'invoice_supplier') {
3195
+					$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE";
3196
+		} elseif ($this->element == 'order_supplier' || $this->element == 'supplier_order') {
3197
+					$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER";
3198
+		} elseif ($this->element == 'supplier_proposal') {
3199
+					$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL";
3200
+		}
2928 3201
 
2929 3202
 		if (!empty($MODULE)) {
2930 3203
 			if (!empty($conf->global->$MODULE)) {
2931 3204
 				$modsactivated = explode(',', $conf->global->$MODULE);
2932 3205
 				foreach ($modsactivated as $mod) {
2933
-					if ($conf->$mod->enabled)
2934
-						return 1; // update was disabled by specific setup
3206
+					if ($conf->$mod->enabled) {
3207
+											return 1;
3208
+					}
3209
+					// update was disabled by specific setup
2935 3210
 				}
2936 3211
 			}
2937 3212
 		}
2938 3213
 
2939 3214
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
2940 3215
 
2941
-		if ($roundingadjust == '-1') $roundingadjust = 'auto'; // For backward compatibility
3216
+		if ($roundingadjust == '-1') {
3217
+			$roundingadjust = 'auto';
3218
+		}
3219
+		// For backward compatibility
2942 3220
 
2943 3221
 		$forcedroundingmode = $roundingadjust;
2944
-		if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode = $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND;
2945
-		elseif ($forcedroundingmode == 'auto') $forcedroundingmode = '0';
3222
+		if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) {
3223
+			$forcedroundingmode = $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND;
3224
+		} elseif ($forcedroundingmode == 'auto') {
3225
+			$forcedroundingmode = '0';
3226
+		}
2946 3227
 
2947 3228
 		$error = 0;
2948 3229
 
@@ -2965,15 +3246,22 @@  discard block
 block discarded – undo
2965 3246
 
2966 3247
 		$sql = 'SELECT rowid, qty, '.$fieldup.' as up, remise_percent, total_ht, '.$fieldtva.' as total_tva, total_ttc, '.$fieldlocaltax1.' as total_localtax1, '.$fieldlocaltax2.' as total_localtax2,';
2967 3248
 		$sql .= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type';
2968
-		if ($this->table_element_line == 'facturedet') $sql .= ', situation_percent';
3249
+		if ($this->table_element_line == 'facturedet') {
3250
+			$sql .= ', situation_percent';
3251
+		}
2969 3252
 		$sql .= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
2970 3253
 		$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line;
2971 3254
 		$sql .= ' WHERE '.$this->fk_element.' = '.$this->id;
2972 3255
 		if ($exclspec)
2973 3256
 		{
2974 3257
 			$product_field = 'product_type';
2975
-			if ($this->table_element_line == 'contratdet') $product_field = ''; // contratdet table has no product_type field
2976
-			if ($product_field) $sql .= ' AND '.$product_field.' <> 9';
3258
+			if ($this->table_element_line == 'contratdet') {
3259
+				$product_field = '';
3260
+			}
3261
+			// contratdet table has no product_type field
3262
+			if ($product_field) {
3263
+				$sql .= ' AND '.$product_field.' <> 9';
3264
+			}
2977 3265
 		}
2978 3266
 		$sql .= ' ORDER by rowid'; // We want to be sure to always use same order of line to not change lines differently when option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND is used
2979 3267
 
@@ -3003,10 +3291,12 @@  discard block
 block discarded – undo
3003 3291
 				$parameters = array('fk_element' => $obj->rowid);
3004 3292
 				$reshook = $hookmanager->executeHooks('changeRoundingMode', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
3005 3293
 
3006
-				if (empty($reshook) && $forcedroundingmode == '0')	// Check if data on line are consistent. This may solve lines that were not consistent because set with $forcedroundingmode='auto'
3294
+				if (empty($reshook) && $forcedroundingmode == '0') {
3295
+					// Check if data on line are consistent. This may solve lines that were not consistent because set with $forcedroundingmode='auto'
3007 3296
 				{
3008 3297
 					// This part of code is to fix data. We should not call it too often.
3009 3298
 					$localtax_array = array($obj->localtax1_type, $obj->localtax1_tx, $obj->localtax2_type, $obj->localtax2_tx);
3299
+				}
3010 3300
 					$tmpcal = calcul_price_total($obj->qty, $obj->up, $obj->remise_percent, $obj->vatrate, $obj->localtax1_tx, $obj->localtax2_tx, 0, 'HT', $obj->info_bits, $obj->product_type, $seller, $localtax_array, (isset($obj->situation_percent) ? $obj->situation_percent : 100), $multicurrency_tx);
3011 3301
 
3012 3302
 					$diff_when_using_price_ht = price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); // If price was set with tax price adn unit price HT has a low number of digits, then we may have a diff on recalculation from unit price HT.
@@ -3019,7 +3309,9 @@  discard block
 block discarded – undo
3019 3309
 						$sqlfix = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid;
3020 3310
 						dol_syslog('We found unconsistent data into detailed line (diff_when_using_price_ht = '.$diff_when_using_price_ht.' and diff_on_current_total = '.$diff_on_current_total.') for line rowid = '.$obj->rowid." (total vat of line calculated=".$tmpcal[1].", database=".$obj->total_tva."). We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix, LOG_WARNING);
3021 3311
 						$resqlfix = $this->db->query($sqlfix);
3022
-						if (!$resqlfix) dol_print_error($this->db, 'Failed to update line');
3312
+						if (!$resqlfix) {
3313
+							dol_print_error($this->db, 'Failed to update line');
3314
+						}
3023 3315
 						$obj->total_tva = $tmpcal[1];
3024 3316
 						$obj->total_ttc = $tmpcal[2];
3025 3317
 					}
@@ -3034,16 +3326,24 @@  discard block
 block discarded – undo
3034 3326
 				$this->multicurrency_total_tva       += $obj->multicurrency_total_tva;
3035 3327
 				$this->multicurrency_total_ttc       += $obj->multicurrency_total_ttc;
3036 3328
 
3037
-				if (!isset($total_ht_by_vats[$obj->vatrate]))  $total_ht_by_vats[$obj->vatrate] = 0;
3038
-				if (!isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate] = 0;
3039
-				if (!isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate] = 0;
3329
+				if (!isset($total_ht_by_vats[$obj->vatrate])) {
3330
+					$total_ht_by_vats[$obj->vatrate] = 0;
3331
+				}
3332
+				if (!isset($total_tva_by_vats[$obj->vatrate])) {
3333
+					$total_tva_by_vats[$obj->vatrate] = 0;
3334
+				}
3335
+				if (!isset($total_ttc_by_vats[$obj->vatrate])) {
3336
+					$total_ttc_by_vats[$obj->vatrate] = 0;
3337
+				}
3040 3338
 				$total_ht_by_vats[$obj->vatrate]  += $obj->total_ht;
3041 3339
 				$total_tva_by_vats[$obj->vatrate] += $obj->total_tva;
3042 3340
 				$total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc;
3043 3341
 
3044
-				if ($forcedroundingmode == '1')	// Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency
3342
+				if ($forcedroundingmode == '1') {
3343
+					// Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency
3045 3344
 				{
3046 3345
 					$tmpvat = price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1);
3346
+				}
3047 3347
 					$diff = price2num($total_tva_by_vats[$obj->vatrate] - $tmpvat, 'MT', 1);
3048 3348
 					//print 'Line '.$i.' rowid='.$obj->rowid.' vat_rate='.$obj->vatrate.' total_ht='.$obj->total_ht.' total_tva='.$obj->total_tva.' total_ttc='.$obj->total_ttc.' total_ht_by_vats='.$total_ht_by_vats[$obj->vatrate].' total_tva_by_vats='.$total_tva_by_vats[$obj->vatrate].' (new calculation = '.$tmpvat.') total_ttc_by_vats='.$total_ttc_by_vats[$obj->vatrate].($diff?" => DIFF":"")."<br>\n";
3049 3349
 					if ($diff)
@@ -3057,7 +3357,9 @@  discard block
 block discarded – undo
3057 3357
 						$sqlfix = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".($obj->total_tva - $diff).", total_ttc = ".($obj->total_ttc - $diff)." WHERE rowid = ".$obj->rowid;
3058 3358
 						dol_syslog('We found a difference of '.$diff.' for line rowid = '.$obj->rowid.". We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix);
3059 3359
 								$resqlfix = $this->db->query($sqlfix);
3060
-								if (!$resqlfix) dol_print_error($this->db, 'Failed to update line');
3360
+								if (!$resqlfix) {
3361
+									dol_print_error($this->db, 'Failed to update line');
3362
+								}
3061 3363
 								$this->total_tva -= $diff;
3062 3364
 								$this->total_ttc -= $diff;
3063 3365
 								$total_tva_by_vats[$obj->vatrate] -= $diff;
@@ -3098,11 +3400,21 @@  discard block
 block discarded – undo
3098 3400
 			$fieldlocaltax2 = 'localtax2';
3099 3401
 			$fieldttc = 'total_ttc';
3100 3402
 			// Specific code for backward compatibility with old field names
3101
-			if ($this->element == 'facture' || $this->element == 'facturerec')             $fieldht = 'total';
3102
-			if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva = 'total_tva';
3103
-			if ($this->element == 'propal')                                                $fieldttc = 'total';
3104
-			if ($this->element == 'expensereport')                                         $fieldtva = 'total_tva';
3105
-			if ($this->element == 'supplier_proposal')                                     $fieldttc = 'total';
3403
+			if ($this->element == 'facture' || $this->element == 'facturerec') {
3404
+				$fieldht = 'total';
3405
+			}
3406
+			if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') {
3407
+				$fieldtva = 'total_tva';
3408
+			}
3409
+			if ($this->element == 'propal') {
3410
+				$fieldttc = 'total';
3411
+			}
3412
+			if ($this->element == 'expensereport') {
3413
+				$fieldtva = 'total_tva';
3414
+			}
3415
+			if ($this->element == 'supplier_proposal') {
3416
+				$fieldttc = 'total';
3417
+			}
3106 3418
 
3107 3419
 			if (empty($nodatabaseupdate))
3108 3420
 			{
@@ -3156,10 +3468,18 @@  discard block
 block discarded – undo
3156 3468
 		$origin_id = (!empty($origin_id) ? $origin_id : $this->origin_id);
3157 3469
 
3158 3470
 		// Special case
3159
-		if ($origin == 'order') $origin = 'commande';
3160
-		if ($origin == 'invoice') $origin = 'facture';
3161
-		if ($origin == 'invoice_template') $origin = 'facturerec';
3162
-		if ($origin == 'supplierorder') $origin = 'order_supplier';
3471
+		if ($origin == 'order') {
3472
+			$origin = 'commande';
3473
+		}
3474
+		if ($origin == 'invoice') {
3475
+			$origin = 'facture';
3476
+		}
3477
+		if ($origin == 'invoice_template') {
3478
+			$origin = 'facturerec';
3479
+		}
3480
+		if ($origin == 'supplierorder') {
3481
+			$origin = 'order_supplier';
3482
+		}
3163 3483
 		$this->db->begin();
3164 3484
 
3165 3485
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
@@ -3223,12 +3543,16 @@  discard block
 block discarded – undo
3223 3543
 		if (!empty($sourceid) && !empty($sourcetype) && empty($targetid))
3224 3544
 		{
3225 3545
 			$justsource = true; // the source (id and type) is a search criteria
3226
-			if (!empty($targettype)) $withtargettype = true;
3546
+			if (!empty($targettype)) {
3547
+				$withtargettype = true;
3548
+			}
3227 3549
 		}
3228 3550
 		if (!empty($targetid) && !empty($targettype) && empty($sourceid))
3229 3551
 		{
3230 3552
 			$justtarget = true; // the target (id and type) is a search criteria
3231
-			if (!empty($sourcetype)) $withsourcetype = true;
3553
+			if (!empty($sourcetype)) {
3554
+				$withsourcetype = true;
3555
+			}
3232 3556
 		}
3233 3557
 
3234 3558
 		$sourceid = (!empty($sourceid) ? $sourceid : $this->id);
@@ -3251,11 +3575,15 @@  discard block
 block discarded – undo
3251 3575
 			if ($justsource)
3252 3576
 			{
3253 3577
 				$sql .= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'";
3254
-				if ($withtargettype) $sql .= " AND targettype = '".$targettype."'";
3578
+				if ($withtargettype) {
3579
+					$sql .= " AND targettype = '".$targettype."'";
3580
+				}
3255 3581
 			} elseif ($justtarget)
3256 3582
 			{
3257 3583
 				$sql .= "fk_target = ".$targetid." AND targettype = '".$targettype."'";
3258
-				if ($withsourcetype) $sql .= " AND sourcetype = '".$sourcetype."'";
3584
+				if ($withsourcetype) {
3585
+					$sql .= " AND sourcetype = '".$sourcetype."'";
3586
+				}
3259 3587
 			}
3260 3588
 		} else {
3261 3589
 			$sql .= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')";
@@ -3297,10 +3625,12 @@  discard block
 block discarded – undo
3297 3625
 			if (!empty($this->linkedObjectsIds))
3298 3626
 			{
3299 3627
 				$tmparray = $this->linkedObjectsIds;
3300
-				foreach ($tmparray as $objecttype => $objectids)       // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...)
3628
+				foreach ($tmparray as $objecttype => $objectids) {
3629
+					// $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...)
3301 3630
 				{
3302 3631
 					// Parse element/subelement (ex: project_task, cabinetmed_consultation, ...)
3303 3632
 					$module = $element = $subelement = $objecttype;
3633
+				}
3304 3634
 					if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier'
3305 3635
 						&& preg_match('/^([^_]+)_([^_]+)/i', $objecttype, $regs))
3306 3636
 					{
@@ -3360,9 +3690,11 @@  discard block
 block discarded – undo
3360 3690
 							//print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname);
3361 3691
 							if (class_exists($classname))
3362 3692
 							{
3363
-								foreach ($objectids as $i => $objectid)	// $i is rowid into llx_element_element
3693
+								foreach ($objectids as $i => $objectid) {
3694
+									// $i is rowid into llx_element_element
3364 3695
 								{
3365 3696
 									$object = new $classname($this->db);
3697
+								}
3366 3698
 									$ret = $object->fetch($objectid);
3367 3699
 									if ($ret >= 0)
3368 3700
 									{
@@ -3398,8 +3730,11 @@  discard block
 block discarded – undo
3398 3730
 		$updatesource = false;
3399 3731
 		$updatetarget = false;
3400 3732
 
3401
-		if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource = true;
3402
-		elseif (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) $updatetarget = true;
3733
+		if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) {
3734
+			$updatesource = true;
3735
+		} elseif (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) {
3736
+			$updatetarget = true;
3737
+		}
3403 3738
 
3404 3739
 		$sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET ";
3405 3740
 		if ($updatesource)
@@ -3442,8 +3777,11 @@  discard block
 block discarded – undo
3442 3777
 		$deletesource = false;
3443 3778
 		$deletetarget = false;
3444 3779
 
3445
-		if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource = true;
3446
-		elseif (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) $deletetarget = true;
3780
+		if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) {
3781
+			$deletesource = true;
3782
+		} elseif (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) {
3783
+			$deletetarget = true;
3784
+		}
3447 3785
 
3448 3786
 		$sourceid = (!empty($sourceid) ? $sourceid : $this->id);
3449 3787
 		$sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element);
@@ -3503,18 +3841,34 @@  discard block
 block discarded – undo
3503 3841
 		$this->db->begin();
3504 3842
 
3505 3843
 		$fieldstatus = "fk_statut";
3506
-		if ($elementTable == 'facture_rec') $fieldstatus = "suspended";
3507
-		if ($elementTable == 'mailing') $fieldstatus = "statut";
3508
-		if ($elementTable == 'cronjob') $fieldstatus = "status";
3509
-		if ($elementTable == 'user') $fieldstatus = "statut";
3510
-		if ($elementTable == 'expensereport') $fieldstatus = "fk_statut";
3511
-		if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus = "status";
3512
-		if (is_array($this->fields) && array_key_exists('status', $this->fields)) $fieldstatus = 'status';
3844
+		if ($elementTable == 'facture_rec') {
3845
+			$fieldstatus = "suspended";
3846
+		}
3847
+		if ($elementTable == 'mailing') {
3848
+			$fieldstatus = "statut";
3849
+		}
3850
+		if ($elementTable == 'cronjob') {
3851
+			$fieldstatus = "status";
3852
+		}
3853
+		if ($elementTable == 'user') {
3854
+			$fieldstatus = "statut";
3855
+		}
3856
+		if ($elementTable == 'expensereport') {
3857
+			$fieldstatus = "fk_statut";
3858
+		}
3859
+		if ($elementTable == 'commande_fournisseur_dispatch') {
3860
+			$fieldstatus = "status";
3861
+		}
3862
+		if (is_array($this->fields) && array_key_exists('status', $this->fields)) {
3863
+			$fieldstatus = 'status';
3864
+		}
3513 3865
 
3514 3866
 		$sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable;
3515 3867
 		$sql .= " SET ".$fieldstatus." = ".$status;
3516 3868
 		// If status = 1 = validated, update also fk_user_valid
3517
-		if ($status == 1 && $elementTable == 'expensereport') $sql .= ", fk_user_valid = ".$user->id;
3869
+		if ($status == 1 && $elementTable == 'expensereport') {
3870
+			$sql .= ", fk_user_valid = ".$user->id;
3871
+		}
3518 3872
 		$sql .= " WHERE rowid=".$elementId;
3519 3873
 
3520 3874
 		dol_syslog(get_class($this)."::setStatut", LOG_DEBUG);
@@ -3525,19 +3879,36 @@  discard block
 block discarded – undo
3525 3879
 			// Try autoset of trigkey
3526 3880
 			if (empty($trigkey))
3527 3881
 			{
3528
-				if ($this->element == 'supplier_proposal' && $status == 2) $trigkey = 'SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class
3529
-				if ($this->element == 'supplier_proposal' && $status == 3) $trigkey = 'SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class
3530
-				if ($this->element == 'supplier_proposal' && $status == 4) $trigkey = 'SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class
3531
-				if ($this->element == 'fichinter' && $status == 3) $trigkey = 'FICHINTER_CLASSIFY_DONE';
3532
-				if ($this->element == 'fichinter' && $status == 2) $trigkey = 'FICHINTER_CLASSIFY_BILLED';
3533
-				if ($this->element == 'fichinter' && $status == 1) $trigkey = 'FICHINTER_CLASSIFY_UNBILLED';
3882
+				if ($this->element == 'supplier_proposal' && $status == 2) {
3883
+					$trigkey = 'SUPPLIER_PROPOSAL_SIGN';
3884
+				}
3885
+				// 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class
3886
+				if ($this->element == 'supplier_proposal' && $status == 3) {
3887
+					$trigkey = 'SUPPLIER_PROPOSAL_REFUSE';
3888
+				}
3889
+				// 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class
3890
+				if ($this->element == 'supplier_proposal' && $status == 4) {
3891
+					$trigkey = 'SUPPLIER_PROPOSAL_CLOSE';
3892
+				}
3893
+				// 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class
3894
+				if ($this->element == 'fichinter' && $status == 3) {
3895
+					$trigkey = 'FICHINTER_CLASSIFY_DONE';
3896
+				}
3897
+				if ($this->element == 'fichinter' && $status == 2) {
3898
+					$trigkey = 'FICHINTER_CLASSIFY_BILLED';
3899
+				}
3900
+				if ($this->element == 'fichinter' && $status == 1) {
3901
+					$trigkey = 'FICHINTER_CLASSIFY_UNBILLED';
3902
+				}
3534 3903
 			}
3535 3904
 
3536 3905
 			if ($trigkey)
3537 3906
 			{
3538 3907
 				// Call trigger
3539 3908
 				$result = $this->call_trigger($trigkey, $user);
3540
-				if ($result < 0) $error++;
3909
+				if ($result < 0) {
3910
+					$error++;
3911
+				}
3541 3912
 				// End call triggers
3542 3913
 			}
3543 3914
 
@@ -3545,9 +3916,11 @@  discard block
 block discarded – undo
3545 3916
 			{
3546 3917
 				$this->db->commit();
3547 3918
 
3548
-				if (empty($savElementId))    // If the element we update was $this (so $elementId is null)
3919
+				if (empty($savElementId)) {
3920
+					// If the element we update was $this (so $elementId is null)
3549 3921
 				{
3550 3922
 					$this->statut = $status;
3923
+				}
3551 3924
 					$this->status = $status;
3552 3925
 				}
3553 3926
 
@@ -3576,8 +3949,13 @@  discard block
 block discarded – undo
3576 3949
 	{
3577 3950
 		global $conf;
3578 3951
 
3579
-		if (empty($id) && empty($ref)) return 0;
3580
-		if (!empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default.
3952
+		if (empty($id) && empty($ref)) {
3953
+			return 0;
3954
+		}
3955
+		if (!empty($conf->global->MAIN_DISABLE_CANVAS)) {
3956
+			return 0;
3957
+		}
3958
+		// To increase speed. Not enabled by default.
3581 3959
 
3582 3960
 		// Clean parameters
3583 3961
 		$ref = trim($ref);
@@ -3585,8 +3963,12 @@  discard block
 block discarded – undo
3585 3963
 		$sql = "SELECT rowid, canvas";
3586 3964
 		$sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element;
3587 3965
 		$sql .= " WHERE entity IN (".getEntity($this->element).")";
3588
-		if (!empty($id))  $sql .= " AND rowid = ".$id;
3589
-		if (!empty($ref)) $sql .= " AND ref = '".$this->db->escape($ref)."'";
3966
+		if (!empty($id)) {
3967
+			$sql .= " AND rowid = ".$id;
3968
+		}
3969
+		if (!empty($ref)) {
3970
+			$sql .= " AND ref = '".$this->db->escape($ref)."'";
3971
+		}
3590 3972
 
3591 3973
 		$resql = $this->db->query($sql);
3592 3974
 		if ($resql)
@@ -3596,7 +3978,9 @@  discard block
 block discarded – undo
3596 3978
 			{
3597 3979
 				$this->canvas = $obj->canvas;
3598 3980
 				return 1;
3599
-			} else return 0;
3981
+			} else {
3982
+				return 0;
3983
+			}
3600 3984
 		} else {
3601 3985
 			dol_print_error($this->db);
3602 3986
 			return -1;
@@ -3633,7 +4017,9 @@  discard block
 block discarded – undo
3633 4017
 	{
3634 4018
 		global $langs;
3635 4019
 
3636
-		if (empty($id)) $id = $this->id;
4020
+		if (empty($id)) {
4021
+			$id = $this->id;
4022
+		}
3637 4023
 
3638 4024
 		// Check parameters
3639 4025
 		if (!isset($this->childtables) || !is_array($this->childtables) || count($this->childtables) == 0)
@@ -3667,9 +4053,11 @@  discard block
 block discarded – undo
3667 4053
 					$langs->load("errors");
3668 4054
 					//print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild;
3669 4055
 					$haschild += $obj->nb;
3670
-					if (is_numeric($elementname))	// old usage
4056
+					if (is_numeric($elementname)) {
4057
+						// old usage
3671 4058
 					{
3672 4059
 						$this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table);
4060
+					}
3673 4061
 					} else // new usage: $elementname=Translation key
3674 4062
 					{
3675 4063
 						$this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname));
@@ -3685,7 +4073,9 @@  discard block
 block discarded – undo
3685 4073
 		{
3686 4074
 			$this->errors[] = "ErrorRecordHasChildren";
3687 4075
 			return $haschild;
3688
-		} else return 0;
4076
+		} else {
4077
+			return 0;
4078
+		}
3689 4079
 	}
3690 4080
 
3691 4081
 	/**
@@ -3701,12 +4091,24 @@  discard block
 block discarded – undo
3701 4091
 		foreach ($this->lines as $key => $val)
3702 4092
 		{
3703 4093
 			$qualified = 0;
3704
-			if ($predefined == -1) $qualified = 1;
3705
-			if ($predefined == 1 && $val->fk_product > 0) $qualified = 1;
3706
-			if ($predefined == 0 && $val->fk_product <= 0) $qualified = 1;
3707
-			if ($predefined == 2 && $val->fk_product > 0 && $val->product_type == 0) $qualified = 1;
3708
-			if ($predefined == 3 && $val->fk_product > 0 && $val->product_type == 1) $qualified = 1;
3709
-			if ($qualified) $nb++;
4094
+			if ($predefined == -1) {
4095
+				$qualified = 1;
4096
+			}
4097
+			if ($predefined == 1 && $val->fk_product > 0) {
4098
+				$qualified = 1;
4099
+			}
4100
+			if ($predefined == 0 && $val->fk_product <= 0) {
4101
+				$qualified = 1;
4102
+			}
4103
+			if ($predefined == 2 && $val->fk_product > 0 && $val->product_type == 0) {
4104
+				$qualified = 1;
4105
+			}
4106
+			if ($predefined == 3 && $val->fk_product > 0 && $val->product_type == 1) {
4107
+				$qualified = 1;
4108
+			}
4109
+			if ($qualified) {
4110
+				$nb++;
4111
+			}
3710 4112
 		}
3711 4113
 		dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies');
3712 4114
 		return $nb;
@@ -3770,16 +4172,24 @@  discard block
 block discarded – undo
3770 4172
 		{
3771 4173
 			if (isset($line->qty_asked))
3772 4174
 			{
3773
-				if (empty($totalOrdered)) $totalOrdered = 0; // Avoid warning because $totalOrdered is ''
4175
+				if (empty($totalOrdered)) {
4176
+					$totalOrdered = 0;
4177
+				}
4178
+				// Avoid warning because $totalOrdered is ''
3774 4179
 				$totalOrdered += $line->qty_asked; // defined for shipment only
3775 4180
 			}
3776 4181
 			if (isset($line->qty_shipped))
3777 4182
 			{
3778
-				if (empty($totalToShip)) $totalToShip = 0; // Avoid warning because $totalToShip is ''
4183
+				if (empty($totalToShip)) {
4184
+					$totalToShip = 0;
4185
+				}
4186
+				// Avoid warning because $totalToShip is ''
3779 4187
 				$totalToShip += $line->qty_shipped; // defined for shipment only
3780 4188
 			} elseif ($line->element == 'commandefournisseurdispatch' && isset($line->qty))
3781 4189
 			{
3782
-				if (empty($totalToShip)) $totalToShip = 0;
4190
+				if (empty($totalToShip)) {
4191
+					$totalToShip = 0;
4192
+				}
3783 4193
 				$totalToShip += $line->qty; // defined for reception only
3784 4194
 			}
3785 4195
 
@@ -3803,16 +4213,28 @@  discard block
 block discarded – undo
3803 4213
 
3804 4214
 			$weightUnit = 0;
3805 4215
 			$volumeUnit = 0;
3806
-			if (!empty($weight_units)) $weightUnit = $weight_units;
3807
-			if (!empty($volume_units)) $volumeUnit = $volume_units;
4216
+			if (!empty($weight_units)) {
4217
+				$weightUnit = $weight_units;
4218
+			}
4219
+			if (!empty($volume_units)) {
4220
+				$volumeUnit = $volume_units;
4221
+			}
3808 4222
 
3809
-			if (empty($totalWeight)) $totalWeight = 0; // Avoid warning because $totalWeight is ''
3810
-			if (empty($totalVolume)) $totalVolume = 0; // Avoid warning because $totalVolume is ''
4223
+			if (empty($totalWeight)) {
4224
+				$totalWeight = 0;
4225
+			}
4226
+			// Avoid warning because $totalWeight is ''
4227
+			if (empty($totalVolume)) {
4228
+				$totalVolume = 0;
4229
+			}
4230
+			// Avoid warning because $totalVolume is ''
3811 4231
 
3812 4232
 			//var_dump($line->volume_units);
3813
-			if ($weight_units < 50)   // < 50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch)
4233
+			if ($weight_units < 50) {
4234
+				// < 50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch)
3814 4235
 			{
3815 4236
 				$trueWeightUnit = pow(10, $weightUnit);
4237
+			}
3816 4238
 				$totalWeight += $weight * $qty * $trueWeightUnit;
3817 4239
 			} else {
3818 4240
 				if ($weight_units == 99) {
@@ -3827,10 +4249,12 @@  discard block
 block discarded – undo
3827 4249
 					$totalWeight += $weight * $qty; // This may be wrong if we mix different units
3828 4250
 				}
3829 4251
 			}
3830
-			if ($volume_units < 50)   // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch)
4252
+			if ($volume_units < 50) {
4253
+				// >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch)
3831 4254
 			{
3832 4255
 				//print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit;
3833 4256
 				$trueVolumeUnit = pow(10, $volumeUnit);
4257
+			}
3834 4258
 				//print $line->volume;
3835 4259
 				$totalVolume += $volume * $qty * $trueVolumeUnit;
3836 4260
 			} else {
@@ -3958,7 +4382,9 @@  discard block
 block discarded – undo
3958 4382
 				$this->errors[] = $this->db->lasterror();
3959 4383
 				return -1;
3960 4384
 			}
3961
-		} else return -1;
4385
+		} else {
4386
+			return -1;
4387
+		}
3962 4388
 	}
3963 4389
 
3964 4390
 
@@ -4008,7 +4434,9 @@  discard block
 block discarded – undo
4008 4434
 			} else {
4009 4435
 				$res = include $tpl; // for debug
4010 4436
 			}
4011
-			if ($res) break;
4437
+			if ($res) {
4438
+				break;
4439
+			}
4012 4440
 		}
4013 4441
 	}
4014 4442
 
@@ -4039,7 +4467,9 @@  discard block
 block discarded – undo
4039 4467
 
4040 4468
 		// Define usemargins
4041 4469
 		$usemargins = 0;
4042
-		if (!empty($conf->margin->enabled) && !empty($this->element) && in_array($this->element, array('facture', 'facturerec', 'propal', 'commande'))) $usemargins = 1;
4470
+		if (!empty($conf->margin->enabled) && !empty($this->element) && in_array($this->element, array('facture', 'facturerec', 'propal', 'commande'))) {
4471
+			$usemargins = 1;
4472
+		}
4043 4473
 
4044 4474
 		$num = count($this->lines);
4045 4475
 
@@ -4072,7 +4502,9 @@  discard block
 block discarded – undo
4072 4502
 				} else {
4073 4503
 					$res = include $tpl; // for debug
4074 4504
 				}
4075
-				if ($res) break;
4505
+				if ($res) {
4506
+					break;
4507
+				}
4076 4508
 			}
4077 4509
 		}
4078 4510
 
@@ -4085,11 +4517,13 @@  discard block
 block discarded – undo
4085 4517
 			$line->fetch_optionals();
4086 4518
 
4087 4519
 			//if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line)))
4088
-			if (is_object($hookmanager))   // Old code is commented on preceding line.
4520
+			if (is_object($hookmanager)) {
4521
+				// Old code is commented on preceding line.
4089 4522
 			{
4090 4523
 				if (empty($line->fk_parent_line))
4091 4524
 				{
4092 4525
 					$parameters = array('line'=>$line, 'num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'table_element_line'=>$line->table_element);
4526
+			}
4093 4527
 					$reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
4094 4528
 				} else {
4095 4529
 					$parameters = array('line'=>$line, 'num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'table_element_line'=>$line->table_element, 'fk_parent_line'=>$line->fk_parent_line);
@@ -4163,8 +4597,13 @@  discard block
 block discarded – undo
4163 4597
 
4164 4598
 					$outputlangs = $langs;
4165 4599
 					$newlang = '';
4166
-					if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
4167
-					if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang) && is_object($this->thirdparty)) $newlang = $this->thirdparty->default_lang; // To use language of customer
4600
+					if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
4601
+						$newlang = GETPOST('lang_id', 'aZ09');
4602
+					}
4603
+					if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang) && is_object($this->thirdparty)) {
4604
+						$newlang = $this->thirdparty->default_lang;
4605
+					}
4606
+					// To use language of customer
4168 4607
 					if (!empty($newlang))
4169 4608
 					{
4170 4609
 						$outputlangs = new Translate("", $conf);
@@ -4200,7 +4639,9 @@  discard block
 block discarded – undo
4200 4639
 				} else {
4201 4640
 					$res = include $tpl; // for debug
4202 4641
 				}
4203
-				if ($res) break;
4642
+				if ($res) {
4643
+					break;
4644
+				}
4204 4645
 			}
4205 4646
 		}
4206 4647
 
@@ -4229,7 +4670,9 @@  discard block
 block discarded – undo
4229 4670
 				} else {
4230 4671
 					$res = include $tpl; // for debug
4231 4672
 				}
4232
-				if ($res) break;
4673
+				if ($res) {
4674
+					break;
4675
+				}
4233 4676
 			}
4234 4677
 		}
4235 4678
 	}
@@ -4257,7 +4700,9 @@  discard block
 block discarded – undo
4257 4700
 		print '<td>'.$langs->trans('Description').'</td>';
4258 4701
 		print '<td class="right">'.$langs->trans('VATRate').'</td>';
4259 4702
 		print '<td class="right">'.$langs->trans('PriceUHT').'</td>';
4260
-		if (!empty($conf->multicurrency->enabled)) print '<td class="right">'.$langs->trans('PriceUHTCurrency').'</td>';
4703
+		if (!empty($conf->multicurrency->enabled)) {
4704
+			print '<td class="right">'.$langs->trans('PriceUHTCurrency').'</td>';
4705
+		}
4261 4706
 		print '<td class="right">'.$langs->trans('Qty').'</td>';
4262 4707
 		if ($conf->global->PRODUCT_USE_UNITS)
4263 4708
 		{
@@ -4312,24 +4757,32 @@  discard block
 block discarded – undo
4312 4757
 			$date_start = $line->date_start;
4313 4758
 		} else {
4314 4759
 			$date_start = $line->date_debut_prevue;
4315
-			if ($line->date_debut_reel) $date_start = $line->date_debut_reel;
4760
+			if ($line->date_debut_reel) {
4761
+				$date_start = $line->date_debut_reel;
4762
+			}
4316 4763
 		}
4317 4764
 		if (!empty($line->date_end))
4318 4765
 		{
4319 4766
 			$date_end = $line->date_end;
4320 4767
 		} else {
4321 4768
 			$date_end = $line->date_fin_prevue;
4322
-			if ($line->date_fin_reel) $date_end = $line->date_fin_reel;
4769
+			if ($line->date_fin_reel) {
4770
+				$date_end = $line->date_fin_reel;
4771
+			}
4323 4772
 		}
4324 4773
 
4325 4774
         $this->tpl['id'] = $line->id;
4326 4775
 
4327 4776
 		$this->tpl['label'] = '';
4328
-		if (!empty($line->fk_parent_line)) $this->tpl['label'] .= img_picto('', 'rightarrow');
4777
+		if (!empty($line->fk_parent_line)) {
4778
+			$this->tpl['label'] .= img_picto('', 'rightarrow');
4779
+		}
4329 4780
 
4330
-		if (($line->info_bits & 2) == 2)  // TODO Not sure this is used for source object
4781
+		if (($line->info_bits & 2) == 2) {
4782
+			// TODO Not sure this is used for source object
4331 4783
 		{
4332 4784
 			$discount = new DiscountAbsolute($this->db);
4785
+		}
4333 4786
 			$discount->fk_soc = $this->socid;
4334 4787
 			$this->tpl['label'] .= $discount->getNomUrl(0, 'discount');
4335 4788
 		} elseif (!empty($line->fk_product))
@@ -4367,14 +4820,18 @@  discard block
 block discarded – undo
4367 4820
 
4368 4821
 		if (!empty($line->desc))
4369 4822
 		{
4370
-			if ($line->desc == '(CREDIT_NOTE)')  // TODO Not sure this is used for source object
4823
+			if ($line->desc == '(CREDIT_NOTE)') {
4824
+				// TODO Not sure this is used for source object
4371 4825
 			{
4372 4826
 				$discount = new DiscountAbsolute($this->db);
4827
+			}
4373 4828
 				$discount->fetch($line->fk_remise_except);
4374 4829
 				$this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0));
4375
-			} elseif ($line->desc == '(DEPOSIT)')  // TODO Not sure this is used for source object
4830
+			} elseif ($line->desc == '(DEPOSIT)') {
4831
+				// TODO Not sure this is used for source object
4376 4832
 			{
4377 4833
 				$discount = new DiscountAbsolute($this->db);
4834
+			}
4378 4835
 				$discount->fetch($line->fk_remise_except);
4379 4836
 				$this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0));
4380 4837
 			} elseif ($line->desc == '(EXCESS RECEIVED)')
@@ -4397,17 +4854,23 @@  discard block
 block discarded – undo
4397 4854
         // VAT Rate
4398 4855
         $this->tpl['vat_rate'] = vatrate($line->tva_tx, true);
4399 4856
         $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : '';
4400
-        if (!empty($line->vat_src_code) && !preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'] .= ' ('.$line->vat_src_code.')';
4857
+        if (!empty($line->vat_src_code) && !preg_match('/\(/', $this->tpl['vat_rate'])) {
4858
+        	$this->tpl['vat_rate'] .= ' ('.$line->vat_src_code.')';
4859
+        }
4401 4860
 
4402 4861
 		$this->tpl['price'] = price($line->subprice);
4403 4862
 		$this->tpl['multicurrency_price'] = price($line->multicurrency_subprice);
4404 4863
 		$this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : '&nbsp;';
4405
-		if ($conf->global->PRODUCT_USE_UNITS) $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long'));
4864
+		if ($conf->global->PRODUCT_USE_UNITS) {
4865
+			$this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long'));
4866
+		}
4406 4867
 		$this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : '&nbsp;';
4407 4868
 
4408 4869
 		// Is the line strike or not
4409 4870
 		$this->tpl['strike'] = 0;
4410
-		if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike'] = 1;
4871
+		if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) {
4872
+			$this->tpl['strike'] = 1;
4873
+		}
4411 4874
 
4412 4875
 		// Output template part (modules that overwrite templates must declare this into descriptor)
4413 4876
 		// Use global variables + $dateSelector + $seller and $buyer
@@ -4426,7 +4889,9 @@  discard block
 block discarded – undo
4426 4889
 			} else {
4427 4890
 				$res = include $tpl; // for debug
4428 4891
 			}
4429
-			if ($res) break;
4892
+			if ($res) {
4893
+				break;
4894
+			}
4430 4895
 		}
4431 4896
 	}
4432 4897
 
@@ -4577,13 +5042,20 @@  discard block
 block discarded – undo
4577 5042
 			$classname = '';
4578 5043
 			$filefound = '';
4579 5044
 		    $dirmodels = array('/');
4580
-		    if (is_array($conf->modules_parts['models'])) $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
5045
+		    if (is_array($conf->modules_parts['models'])) {
5046
+		    	$dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
5047
+		    }
4581 5048
 		    foreach ($dirmodels as $reldir)
4582 5049
 		    {
4583 5050
 			    foreach (array('doc', 'pdf') as $prefix)
4584 5051
 			    {
4585
-				    if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php
4586
-				    else $file = $prefix."_".$modele.".modules.php";
5052
+				    if (in_array(get_class($this), array('Adherent'))) {
5053
+				    	$file = $prefix."_".$modele.".class.php";
5054
+				    }
5055
+				    // Member module use prefix_module.class.php
5056
+				    else {
5057
+				    	$file = $prefix."_".$modele.".modules.php";
5058
+				    }
4587 5059
 
4588 5060
 				    // On verifie l'emplacement du modele
4589 5061
 				    $file = dol_buildpath($reldir.$modelspath.$file, 0);
@@ -4594,7 +5066,9 @@  discard block
 block discarded – undo
4594 5066
 					    break;
4595 5067
 				    }
4596 5068
 			    }
4597
-			    if ($filefound) break;
5069
+			    if ($filefound) {
5070
+			    	break;
5071
+			    }
4598 5072
 		    }
4599 5073
 
4600 5074
 		    // If generator was found
@@ -4626,7 +5100,9 @@  discard block
 block discarded – undo
4626 5100
 						    if (is_dir($tmpdir))
4627 5101
 						    {
4628 5102
 							    $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.od(s|t)$', '', 'name', SORT_ASC, 0);
4629
-							    if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles);
5103
+							    if (count($tmpfiles)) {
5104
+							    	$listoffiles = array_merge($listoffiles, $tmpfiles);
5105
+							    }
4630 5106
 						    }
4631 5107
 					    }
4632 5108
 
@@ -4686,9 +5162,11 @@  discard block
 block discarded – undo
4686 5162
 					    $destfile = basename($destfull);
4687 5163
 					    $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $upload_dir);
4688 5164
 
4689
-					    if (!preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir))     // If not a tmp dir
5165
+					    if (!preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
5166
+					    	// If not a tmp dir
4690 5167
 					    {
4691 5168
 						    $filename = basename($destfile);
5169
+					    }
4692 5170
 						    $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
4693 5171
 						    $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
4694 5172
 
@@ -4701,8 +5179,12 @@  discard block
 block discarded – undo
4701 5179
 						    if ($this->element == 'propal')
4702 5180
 						    {
4703 5181
 							    $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok
4704
-							    if ($useonlinesignature) $setsharekey = true;
4705
-							    if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true;
5182
+							    if ($useonlinesignature) {
5183
+							    	$setsharekey = true;
5184
+							    }
5185
+							    if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) {
5186
+							    	$setsharekey = true;
5187
+							    }
4706 5188
 						    }
4707 5189
 						    if ($this->element == 'commande' && !empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) {
4708 5190
 							    $setsharekey = true;
@@ -4715,9 +5197,11 @@  discard block
 block discarded – undo
4715 5197
 						    }
4716 5198
 
4717 5199
 						    if ($setsharekey) {
4718
-							    if (empty($ecmfile->share))	// Because object not found or share not set yet
5200
+							    if (empty($ecmfile->share)) {
5201
+							    	// Because object not found or share not set yet
4719 5202
 							    {
4720 5203
 								    require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
5204
+							    }
4721 5205
 								    $ecmfile->share = getRandomPassword(true);
4722 5206
 							    }
4723 5207
 						    }
@@ -4758,7 +5242,9 @@  discard block
 block discarded – undo
4758 5242
 
4759 5243
 						    // Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set)
4760 5244
 						    $update_main_doc_field = 0;
4761
-						    if (!empty($obj->update_main_doc_field)) $update_main_doc_field = 1;
5245
+						    if (!empty($obj->update_main_doc_field)) {
5246
+						    	$update_main_doc_field = 1;
5247
+						    }
4762 5248
 						    if ($update_main_doc_field && !empty($this->table_element))
4763 5249
 						    {
4764 5250
 							    $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".$this->db->escape($ecmfile->filepath.'/'.$ecmfile->filename)."'";
@@ -4795,7 +5281,9 @@  discard block
 block discarded – undo
4795 5281
 		    	}
4796 5282
 			    return -1;
4797 5283
 		    }
4798
-		} else return $reshook;
5284
+		} else {
5285
+			return $reshook;
5286
+		}
4799 5287
 	}
4800 5288
 
4801 5289
 	/**
@@ -4846,13 +5334,21 @@  discard block
 block discarded – undo
4846 5334
 		global $conf, $_POST;
4847 5335
 
4848 5336
 		// If param here has been posted, we use this value first.
4849
-		if (GETPOSTISSET($fieldname)) return GETPOST($fieldname, 'alphanohtml', 3);
5337
+		if (GETPOSTISSET($fieldname)) {
5338
+			return GETPOST($fieldname, 'alphanohtml', 3);
5339
+		}
4850 5340
 
4851
-		if (isset($alternatevalue)) return $alternatevalue;
5341
+		if (isset($alternatevalue)) {
5342
+			return $alternatevalue;
5343
+		}
4852 5344
 
4853 5345
 		$newelement = $this->element;
4854
-		if ($newelement == 'facture') $newelement = 'invoice';
4855
-		if ($newelement == 'commande') $newelement = 'order';
5346
+		if ($newelement == 'facture') {
5347
+			$newelement = 'invoice';
5348
+		}
5349
+		if ($newelement == 'commande') {
5350
+			$newelement = 'order';
5351
+		}
4856 5352
 		if (empty($newelement))
4857 5353
 		{
4858 5354
 			dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
@@ -4861,7 +5357,9 @@  discard block
 block discarded – undo
4861 5357
 
4862 5358
 		$keyforfieldname = strtoupper($newelement.'_DEFAULT_'.$fieldname);
4863 5359
 		//var_dump($keyforfieldname);
4864
-		if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname;
5360
+		if (isset($conf->global->$keyforfieldname)) {
5361
+			return $conf->global->$keyforfieldname;
5362
+		}
4865 5363
 
4866 5364
 		// TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname
4867 5365
 	}
@@ -4934,7 +5432,10 @@  discard block
 block discarded – undo
4934 5432
 		$this->array_languages = array();
4935 5433
 
4936 5434
 		$element = $this->element;
4937
-		if ($element == 'categorie') $element = 'categories'; // For compatibility
5435
+		if ($element == 'categorie') {
5436
+			$element = 'categories';
5437
+		}
5438
+		// For compatibility
4938 5439
 
4939 5440
 		// Request to get translation values for object
4940 5441
 		$sql = "SELECT rowid, property, lang , value";
@@ -4971,8 +5472,11 @@  discard block
 block discarded – undo
4971 5472
 
4972 5473
 			$this->db->free($resql);
4973 5474
 
4974
-			if ($numrows) return $numrows;
4975
-			else return 0;
5475
+			if ($numrows) {
5476
+				return $numrows;
5477
+			} else {
5478
+				return 0;
5479
+			}
4976 5480
 		} else {
4977 5481
 			dol_print_error($this->db);
4978 5482
 			return -1;
@@ -4992,15 +5496,21 @@  discard block
 block discarded – undo
4992 5496
 		// Get extra fields
4993 5497
 		foreach ($_POST as $postfieldkey => $postfieldvalue) {
4994 5498
 			$tmparray = explode('-', $postfieldkey);
4995
-			if ($tmparray[0] != 'field') continue;
5499
+			if ($tmparray[0] != 'field') {
5500
+				continue;
5501
+			}
4996 5502
 
4997 5503
 			$element = $tmparray[1];
4998 5504
 			$key = $tmparray[2];
4999 5505
 			$codelang = $tmparray[3];
5000 5506
 			//var_dump("postfieldkey=".$postfieldkey." element=".$element." key=".$key." codelang=".$codelang);
5001 5507
 
5002
-			if (!empty($onlykey) && $key != $onlykey) continue;
5003
-			if ($element != $this->element) continue;
5508
+			if (!empty($onlykey) && $key != $onlykey) {
5509
+				continue;
5510
+			}
5511
+			if ($element != $this->element) {
5512
+				continue;
5513
+			}
5004 5514
 
5005 5515
 			$key_type = $this->fields[$key]['type'];
5006 5516
 
@@ -5014,7 +5524,9 @@  discard block
 block discarded – undo
5014 5524
 			{
5015 5525
 				$perms = dol_eval($this->fields[$key]['perms'], 1);
5016 5526
 			}*/
5017
-			if (empty($enabled)) continue;
5527
+			if (empty($enabled)) {
5528
+				continue;
5529
+			}
5018 5530
 			//if (empty($perms)) continue;
5019 5531
 
5020 5532
 			if (in_array($key_type, array('date')))
@@ -5041,7 +5553,9 @@  discard block
 block discarded – undo
5041 5553
 				$value_key = price2num($value_arr);
5042 5554
 			} else {
5043 5555
 				$value_key = GETPOST($postfieldkey);
5044
-				if (in_array($key_type, array('link')) && $value_key == '-1') $value_key = '';
5556
+				if (in_array($key_type, array('link')) && $value_key == '-1') {
5557
+					$value_key = '';
5558
+				}
5045 5559
 			}
5046 5560
 
5047 5561
 			$this->array_languages[$key][$codelang] = $value_key;
@@ -5094,8 +5608,12 @@  discard block
 block discarded – undo
5094 5608
 		// phpcs:enable
5095 5609
 		global $conf, $extrafields;
5096 5610
 
5097
-		if (empty($rowid)) $rowid = $this->id;
5098
-		if (empty($rowid)) $rowid = $this->rowid;
5611
+		if (empty($rowid)) {
5612
+			$rowid = $this->id;
5613
+		}
5614
+		if (empty($rowid)) {
5615
+			$rowid = $this->rowid;
5616
+		}
5099 5617
 
5100 5618
 		// To avoid SQL errors. Probably not the better solution though
5101 5619
 		if (!$this->table_element) {
@@ -5125,7 +5643,10 @@  discard block
 block discarded – undo
5125 5643
 		}
5126 5644
 
5127 5645
 		$table_element = $this->table_element;
5128
-		if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility
5646
+		if ($table_element == 'categorie') {
5647
+			$table_element = 'categories';
5648
+		}
5649
+		// For compatibility
5129 5650
 
5130 5651
 		// Request to get complementary values
5131 5652
 		if (is_array($optionsArray) && count($optionsArray) > 0)
@@ -5182,8 +5703,11 @@  discard block
 block discarded – undo
5182 5703
 
5183 5704
 				$this->db->free($resql);
5184 5705
 
5185
-				if ($numrows) return $numrows;
5186
-				else return 0;
5706
+				if ($numrows) {
5707
+					return $numrows;
5708
+				} else {
5709
+					return 0;
5710
+				}
5187 5711
 			} else {
5188 5712
 				dol_print_error($this->db);
5189 5713
 				return -1;
@@ -5202,12 +5726,17 @@  discard block
 block discarded – undo
5202 5726
 	{
5203 5727
 		global $conf;
5204 5728
 
5205
-		if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0;
5729
+		if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
5730
+			return 0;
5731
+		}
5206 5732
 
5207 5733
 		$this->db->begin();
5208 5734
 
5209 5735
 		$table_element = $this->table_element;
5210
-		if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility
5736
+		if ($table_element == 'categorie') {
5737
+			$table_element = 'categories';
5738
+		}
5739
+		// For compatibility
5211 5740
 
5212 5741
 		$sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id;
5213 5742
 		dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG);
@@ -5237,9 +5766,13 @@  discard block
 block discarded – undo
5237 5766
 	{
5238 5767
 		global $conf, $langs, $user;
5239 5768
 
5240
-		if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0;
5769
+		if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
5770
+			return 0;
5771
+		}
5241 5772
 
5242
-		if (empty($userused)) $userused = $user;
5773
+		if (empty($userused)) {
5774
+			$userused = $user;
5775
+		}
5243 5776
 
5244 5777
 		$error = 0;
5245 5778
 
@@ -5254,10 +5787,13 @@  discard block
 block discarded – undo
5254 5787
 			//Eliminate copied source object extra_fields that do not exist in target object
5255 5788
 			$new_array_options = array();
5256 5789
 			foreach ($this->array_options as $key => $value) {
5257
-				if (in_array(substr($key, 8), array_keys($target_extrafields)))	// We remove the 'options_' from $key for test
5790
+				if (in_array(substr($key, 8), array_keys($target_extrafields))) {
5791
+					// We remove the 'options_' from $key for test
5258 5792
 					$new_array_options[$key] = $value;
5259
-				elseif (in_array($key, array_keys($target_extrafields)))		// We test on $key that does not contains the 'options_' prefix
5793
+				} elseif (in_array($key, array_keys($target_extrafields))) {
5794
+					// We test on $key that does not contains the 'options_' prefix
5260 5795
 					$new_array_options['options_'.$key] = $value;
5796
+				}
5261 5797
 			}
5262 5798
 
5263 5799
 			foreach ($new_array_options as $key => $value)
@@ -5272,8 +5808,12 @@  discard block
 block discarded – undo
5272 5808
 			   	if ($attributeRequired)
5273 5809
 			   	{
5274 5810
 			   		$mandatorypb = false;
5275
-			   		if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb = true;
5276
-			   		if ($this->array_options[$key] === '') $mandatorypb = true;
5811
+			   		if ($attributeType == 'link' && $this->array_options[$key] == '-1') {
5812
+			   			$mandatorypb = true;
5813
+			   		}
5814
+			   		if ($this->array_options[$key] === '') {
5815
+			   			$mandatorypb = true;
5816
+			   		}
5277 5817
 			   		if ($mandatorypb)
5278 5818
 			   		{
5279 5819
 			   		    dol_syslog("Mandatory extra field ".$key." is empty");
@@ -5341,12 +5881,15 @@  discard block
 block discarded – undo
5341 5881
 			   					//global $action;		// $action may be 'create', 'update', 'update_extras'...
5342 5882
 			   					//var_dump($action);
5343 5883
 			   					//var_dump($this->oldcopy);exit;
5344
-			   					if (is_object($this->oldcopy))		// If this->oldcopy is not defined, we can't know if we change attribute or not, so we must keep value
5884
+			   					if (is_object($this->oldcopy)) {
5885
+			   						// If this->oldcopy is not defined, we can't know if we change attribute or not, so we must keep value
5345 5886
 			   					{
5346 5887
 			   						//var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]);
5347 5888
 				   					if ($this->array_options[$key] == $this->oldcopy->array_options[$key])	// If old value crypted in database is same than submited new value, it means we don't change it, so we don't update.
5348 5889
 				   					{
5349
-				   						$new_array_options[$key] = $this->array_options[$key]; // Value is kept
5890
+				   						$new_array_options[$key] = $this->array_options[$key];
5891
+			   					}
5892
+			   					// Value is kept
5350 5893
 				   					} else {
5351 5894
 										// var_dump($algo);
5352 5895
 										$newvalue = dol_hash($this->array_options[$key], $algo);
@@ -5380,17 +5923,23 @@  discard block
 block discarded – undo
5380 5923
 						dol_include_once($InfoFieldList[1]);
5381 5924
 						if ($InfoFieldList[0] && class_exists($InfoFieldList[0]))
5382 5925
 						{
5383
-							if ($value == '-1')	// -1 is key for no defined in combo list of objects
5926
+							if ($value == '-1') {
5927
+								// -1 is key for no defined in combo list of objects
5384 5928
 							{
5385 5929
 								$new_array_options[$key] = '';
5930
+							}
5386 5931
 							} elseif ($value)
5387 5932
 							{
5388 5933
 								$object = new $InfoFieldList[0]($this->db);
5389
-								if (is_numeric($value)) $res = $object->fetch($value);
5390
-								else $res = $object->fetch('', $value);
5934
+								if (is_numeric($value)) {
5935
+									$res = $object->fetch($value);
5936
+								} else {
5937
+									$res = $object->fetch('', $value);
5938
+								}
5391 5939
 
5392
-								if ($res > 0) $new_array_options[$key] = $object->id;
5393
-								else {
5940
+								if ($res > 0) {
5941
+									$new_array_options[$key] = $object->id;
5942
+								} else {
5394 5943
 									$this->error = "Id/Ref '".$value."' for object '".$object->element."' not found";
5395 5944
 									$this->db->rollback();
5396 5945
 									return -1;
@@ -5406,7 +5955,10 @@  discard block
 block discarded – undo
5406 5955
 			$this->db->begin();
5407 5956
 
5408 5957
 			$table_element = $this->table_element;
5409
-			if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility
5958
+			if ($table_element == 'categorie') {
5959
+				$table_element = 'categories';
5960
+			}
5961
+			// For compatibility
5410 5962
 
5411 5963
 			dol_syslog(get_class($this)."::insertExtraFields delete then insert", LOG_DEBUG);
5412 5964
 
@@ -5418,18 +5970,22 @@  discard block
 block discarded – undo
5418 5970
 			{
5419 5971
 				$attributeKey = substr($key, 8); // Remove 'options_' prefix
5420 5972
 				// Add field of attribut
5421
-				if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator
5973
+				if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') {
5974
+					// Only for other type than separator
5422 5975
 					$sql .= ",".$attributeKey;
5976
+				}
5423 5977
 			}
5424 5978
 			// We must insert a default value for fields for other entities that are mandatory to avoid not null error
5425 5979
 			if (is_array($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities']))
5426 5980
 			{
5427 5981
     			foreach ($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as  $tmpkey => $tmpval)
5428 5982
     			{
5429
-    			    if (!isset($extrafields->attributes[$this->table_element]['type'][$tmpkey]))    // If field not already added previously
5983
+    			    if (!isset($extrafields->attributes[$this->table_element]['type'][$tmpkey])) {
5984
+    			    	// If field not already added previously
5430 5985
     			    {
5431 5986
     			        $sql .= ",".$tmpkey;
5432 5987
     			    }
5988
+    			    }
5433 5989
     			}
5434 5990
 			}
5435 5991
 			$sql .= ") VALUES (".$this->id;
@@ -5438,11 +5994,13 @@  discard block
 block discarded – undo
5438 5994
 			{
5439 5995
 				$attributeKey = substr($key, 8); // Remove 'options_' prefix
5440 5996
 				// Add field of attribute
5441
-				if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator)
5997
+				if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') {
5998
+					// Only for other type than separator)
5442 5999
 				{
5443 6000
 					if ($new_array_options[$key] != '' || $new_array_options[$key] == '0')
5444 6001
 					{
5445 6002
 						$sql .= ",'".$this->db->escape($new_array_options[$key])."'";
6003
+				}
5446 6004
 					} else {
5447 6005
 						$sql .= ",null";
5448 6006
 					}
@@ -5453,10 +6011,13 @@  discard block
 block discarded – undo
5453 6011
 			{
5454 6012
 			    foreach ($extrafields->attributes[$this->table_element]['mandatoryfieldsofotherentities'] as  $tmpkey => $tmpval)
5455 6013
     			{
5456
-    			    if (!isset($extrafields->attributes[$this->table_element]['type'][$tmpkey]))    // If field not already added previously
6014
+    			    if (!isset($extrafields->attributes[$this->table_element]['type'][$tmpkey])) {
6015
+    			    	// If field not already added previously
5457 6016
     			    {
5458 6017
                         if (in_array($tmpval, array('int', 'double'))) $sql .= ", 0";
5459
-                        else $sql .= ", ''";
6018
+    			    } else {
6019
+                        	$sql .= ", ''";
6020
+                        }
5460 6021
     			    }
5461 6022
     			}
5462 6023
 			}
@@ -5476,7 +6037,9 @@  discard block
 block discarded – undo
5476 6037
 				// Call trigger
5477 6038
 				$this->context = array('extrafieldaddupdate'=>1);
5478 6039
 				$result = $this->call_trigger($trigger, $userused);
5479
-				if ($result < 0) $error++;
6040
+				if ($result < 0) {
6041
+					$error++;
6042
+				}
5480 6043
 				// End call trigger
5481 6044
 			}
5482 6045
 
@@ -5488,7 +6051,9 @@  discard block
 block discarded – undo
5488 6051
 				$this->db->commit();
5489 6052
 				return 1;
5490 6053
 			}
5491
-		} else return 0;
6054
+		} else {
6055
+			return 0;
6056
+		}
5492 6057
 	}
5493 6058
 
5494 6059
 	/**
@@ -5505,11 +6070,16 @@  discard block
 block discarded – undo
5505 6070
 	{
5506 6071
 		global $conf, $langs, $user;
5507 6072
 
5508
-		if (empty($userused)) $userused = $user;
6073
+		if (empty($userused)) {
6074
+			$userused = $user;
6075
+		}
5509 6076
 
5510 6077
 		$error = 0;
5511 6078
 
5512
-		if (!empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) return 0; // For avoid conflicts if trigger used
6079
+		if (!empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) {
6080
+			return 0;
6081
+		}
6082
+		// For avoid conflicts if trigger used
5513 6083
 
5514 6084
 		if (is_array($this->array_languages))
5515 6085
 		{
@@ -5562,7 +6132,10 @@  discard block
 block discarded – undo
5562 6132
 			$this->db->begin();
5563 6133
 
5564 6134
 			$table_element = $this->table_element;
5565
-			if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility
6135
+			if ($table_element == 'categorie') {
6136
+				$table_element = 'categories';
6137
+			}
6138
+			// For compatibility
5566 6139
 
5567 6140
 			dol_syslog(get_class($this)."::insertExtraLanguages delete then insert", LOG_DEBUG);
5568 6141
 
@@ -5594,7 +6167,9 @@  discard block
 block discarded – undo
5594 6167
 				// Call trigger
5595 6168
 				$this->context = array('extralanguagesaddupdate'=>1);
5596 6169
 				$result = $this->call_trigger($trigger, $userused);
5597
-				if ($result < 0) $error++;
6170
+				if ($result < 0) {
6171
+					$error++;
6172
+				}
5598 6173
 				// End call trigger
5599 6174
 			}
5600 6175
 
@@ -5606,7 +6181,9 @@  discard block
 block discarded – undo
5606 6181
 				$this->db->commit();
5607 6182
 				return 1;
5608 6183
 			}
5609
-		} else return 0;
6184
+		} else {
6185
+			return 0;
6186
+		}
5610 6187
 	}
5611 6188
 
5612 6189
 	/**
@@ -5623,9 +6200,13 @@  discard block
 block discarded – undo
5623 6200
 	{
5624 6201
 		global $conf, $langs, $user;
5625 6202
 
5626
-		if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0;
6203
+		if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
6204
+			return 0;
6205
+		}
5627 6206
 
5628
-		if (empty($userused)) $userused = $user;
6207
+		if (empty($userused)) {
6208
+			$userused = $user;
6209
+		}
5629 6210
 
5630 6211
 		$error = 0;
5631 6212
 
@@ -5718,7 +6299,9 @@  discard block
 block discarded – undo
5718 6299
 				// Call trigger
5719 6300
 				$this->context = array('extrafieldupdate'=>1);
5720 6301
 				$result = $this->call_trigger($trigger, $userused);
5721
-				if ($result < 0) $error++;
6302
+				if ($result < 0) {
6303
+					$error++;
6304
+				}
5722 6305
 				// End call trigger
5723 6306
 			}
5724 6307
 
@@ -5731,7 +6314,9 @@  discard block
 block discarded – undo
5731 6314
 				$this->db->commit();
5732 6315
 				return 1;
5733 6316
 			}
5734
-		} else return 0;
6317
+		} else {
6318
+			return 0;
6319
+		}
5735 6320
 	}
5736 6321
 
5737 6322
 	/**
@@ -5748,11 +6333,16 @@  discard block
 block discarded – undo
5748 6333
 	{
5749 6334
 		global $conf, $langs, $user;
5750 6335
 
5751
-		if (empty($userused)) $userused = $user;
6336
+		if (empty($userused)) {
6337
+			$userused = $user;
6338
+		}
5752 6339
 
5753 6340
 		$error = 0;
5754 6341
 
5755
-		if (!empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) return 0; // For avoid conflicts if trigger used
6342
+		if (!empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) {
6343
+			return 0;
6344
+		}
6345
+		// For avoid conflicts if trigger used
5756 6346
 
5757 6347
 		return 0;
5758 6348
 	}
@@ -5836,8 +6426,11 @@  discard block
 block discarded – undo
5836 6426
 
5837 6427
 		if ($computed)
5838 6428
 		{
5839
-			if (!preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
5840
-			else return '';
6429
+			if (!preg_match('/^search_/', $keyprefix)) {
6430
+				return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
6431
+			} else {
6432
+				return '';
6433
+			}
5841 6434
 		}
5842 6435
 
5843 6436
 		// Set value of $morecss. For this, we use in priority showsize from parameters, then $val['css'] then autodefine
@@ -5849,9 +6442,11 @@  discard block
 block discarded – undo
5849 6442
 			if ($type == 'date')
5850 6443
 			{
5851 6444
 				$morecss = 'minwidth100imp';
5852
-			} elseif ($type == 'datetime' || $type == 'link')	// link means an foreign key to another primary id
6445
+			} elseif ($type == 'datetime' || $type == 'link') {
6446
+				// link means an foreign key to another primary id
5853 6447
 			{
5854 6448
 				$morecss = 'minwidth200imp';
6449
+			}
5855 6450
 			} elseif (in_array($type, array('int', 'integer', 'price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type))
5856 6451
 			{
5857 6452
 				$morecss = 'maxwidth75';
@@ -5881,7 +6476,9 @@  discard block
 block discarded – undo
5881 6476
 			$showtime = in_array($type, array('datetime')) ? 1 : 0;
5882 6477
 
5883 6478
 			// Do not show current date when field not required (see selectDate() method)
5884
-			if (!$required && $value == '') $value = '-1';
6479
+			if (!$required && $value == '') {
6480
+				$value = '-1';
6481
+			}
5885 6482
 
5886 6483
 			// TODO Must also support $moreparam
5887 6484
 			$out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1);
@@ -5904,9 +6501,11 @@  discard block
 block discarded – undo
5904 6501
 			$out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>';
5905 6502
 		} elseif ($type == 'text')
5906 6503
 		{
5907
-			if (!preg_match('/search_/', $keyprefix))		// If keyprefix is search_ or search_options_, we must just use a simple text field
6504
+			if (!preg_match('/search_/', $keyprefix)) {
6505
+				// If keyprefix is search_ or search_options_, we must just use a simple text field
5908 6506
 			{
5909 6507
 				require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
6508
+			}
5910 6509
 				$doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, false, ROWS_5, '90%');
5911 6510
 				$out = $doleditor->Create(1);
5912 6511
 			} else {
@@ -5914,9 +6513,11 @@  discard block
 block discarded – undo
5914 6513
 			}
5915 6514
 		} elseif ($type == 'html')
5916 6515
 		{
5917
-			if (!preg_match('/search_/', $keyprefix))		// If keyprefix is search_ or search_options_, we must just use a simple text field
6516
+			if (!preg_match('/search_/', $keyprefix)) {
6517
+				// If keyprefix is search_ or search_options_, we must just use a simple text field
5918 6518
 			{
5919 6519
 				require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
6520
+			}
5920 6521
 				$doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, !empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5, '90%');
5921 6522
 				$out = $doleditor->Create(1);
5922 6523
 			} else {
@@ -5953,10 +6554,14 @@  discard block
 block discarded – undo
5953 6554
 			}
5954 6555
 
5955 6556
 			$out .= '<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>';
5956
-                if ((!isset($this->fields[$key]['default'])) || ($this->fields[$key]['notnull'] != 1))$out .= '<option value="0">&nbsp;</option>';
6557
+                if ((!isset($this->fields[$key]['default'])) || ($this->fields[$key]['notnull'] != 1)) {
6558
+                	$out .= '<option value="0">&nbsp;</option>';
6559
+                }
5957 6560
 			foreach ($param['options'] as $key => $val)
5958 6561
 			{
5959
-				if ((string) $key == '') continue;
6562
+				if ((string) $key == '') {
6563
+					continue;
6564
+				}
5960 6565
 				list($val, $parent) = explode('|', $val);
5961 6566
 				$out .= '<option value="'.$key.'"';
5962 6567
 				$out .= (((string) $value == (string) $key) ? ' selected' : '');
@@ -6096,7 +6701,9 @@  discard block
 block discarded – undo
6096 6701
 									$labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
6097 6702
 								}
6098 6703
 							}
6099
-							if (empty($labeltoshow)) $labeltoshow = '(not defined)';
6704
+							if (empty($labeltoshow)) {
6705
+								$labeltoshow = '(not defined)';
6706
+							}
6100 6707
 							if ($value == $obj->rowid)
6101 6708
 							{
6102 6709
 								$out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
@@ -6290,11 +6897,16 @@  discard block
 block discarded – undo
6290 6897
 			$out = $form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty, '', '', $morecss, $moreparam, 0, empty($val['disabled']) ? 0 : 1);
6291 6898
 
6292 6899
 			if (!empty($param_list_array[2])) {		// If the entry into $fields is set to add a create button
6293
-				if (!GETPOSTISSET('backtopage') && empty($val['disabled']) && empty($nonewbutton))	// To avoid to open several times the 'Create Object' button and to avoid to have button if field is protected by a "disabled".
6900
+				if (!GETPOSTISSET('backtopage') && empty($val['disabled']) && empty($nonewbutton)) {
6901
+					// To avoid to open several times the 'Create Object' button and to avoid to have button if field is protected by a "disabled".
6294 6902
 				{
6295 6903
 		   			list($class, $classfile) = explode(':', $param_list[0]);
6296
-		   			if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path = dol_buildpath(dirname(dirname($classfile)).'/card.php', 1);
6297
-		   			else $url_path = dol_buildpath(dirname(dirname($classfile)).'/'.strtolower($class).'_card.php', 1);
6904
+				}
6905
+		   			if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) {
6906
+		   				$url_path = dol_buildpath(dirname(dirname($classfile)).'/card.php', 1);
6907
+		   			} else {
6908
+		   				$url_path = dol_buildpath(dirname(dirname($classfile)).'/'.strtolower($class).'_card.php', 1);
6909
+		   			}
6298 6910
 		   			$paramforthenewlink = '';
6299 6911
 		   			$paramforthenewlink .= (GETPOSTISSET('action') ? '&action='.GETPOST('action', 'aZ09') : '');
6300 6912
 		   			$paramforthenewlink .= (GETPOSTISSET('id') ? '&id='.GETPOST('id', 'int') : '');
@@ -6386,9 +6998,16 @@  discard block
 block discarded – undo
6386 6998
 		{
6387 6999
 			$type = 'varchar'; // convert varchar(xx) int varchar
6388 7000
 			$size = $reg[1];
6389
-		} elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar
6390
-		if (is_array($val['arrayofkeyval'])) $type = 'select';
6391
-		if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type = 'link';
7001
+		} elseif (preg_match('/varchar/', $type)) {
7002
+			$type = 'varchar';
7003
+		}
7004
+		// convert varchar(xx) int varchar
7005
+		if (is_array($val['arrayofkeyval'])) {
7006
+			$type = 'select';
7007
+		}
7008
+		if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) {
7009
+			$type = 'link';
7010
+		}
6392 7011
 
6393 7012
 		$default = $val['default'];
6394 7013
 		$computed = $val['computed'];
@@ -6397,7 +7016,9 @@  discard block
 block discarded – undo
6397 7016
 		$param = array();
6398 7017
 		$param['options'] = array();
6399 7018
 
6400
-		if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval'];
7019
+		if (is_array($val['arrayofkeyval'])) {
7020
+			$param['options'] = $val['arrayofkeyval'];
7021
+		}
6401 7022
 		if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg))
6402 7023
 		{
6403 7024
 			$type = 'link';
@@ -6412,7 +7033,9 @@  discard block
 block discarded – undo
6412 7033
 		$help = $val['help'];
6413 7034
 		$hidden = (($val['visible'] == 0) ? 1 : 0); // If zero, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller)
6414 7035
 
6415
-		if ($hidden) return '';
7036
+		if ($hidden) {
7037
+			return '';
7038
+		}
6416 7039
 
6417 7040
 		// If field is a computed field, value must become result of compute
6418 7041
 		if ($computed)
@@ -6453,9 +7076,11 @@  discard block
 block discarded – undo
6453 7076
 		}
6454 7077
 
6455 7078
 		// Format output value differently according to properties of field
6456
-		if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value = $this->getNomUrl(1, '', 0, '', 1);
6457
-		elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value = $this->getLibStatut(3);
6458
-		elseif ($type == 'date')
7079
+		if ($key == 'ref' && method_exists($this, 'getNomUrl')) {
7080
+			$value = $this->getNomUrl(1, '', 0, '', 1);
7081
+		} elseif ($key == 'status' && method_exists($this, 'getLibStatut')) {
7082
+			$value = $this->getLibStatut(3);
7083
+		} elseif ($type == 'date')
6459 7084
 		{
6460 7085
 			if (!empty($value)) {
6461 7086
 				$value = dol_print_date($value, 'day');
@@ -6576,7 +7201,9 @@  discard block
 block discarded – undo
6576 7201
 						$value = $obj->{$InfoFieldList[1]};
6577 7202
 					}
6578 7203
 				}
6579
-			} else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
7204
+			} else {
7205
+				dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
7206
+			}
6580 7207
 		} elseif ($type == 'radio')
6581 7208
 		{
6582 7209
 			$value = $param['options'][$value];
@@ -6685,7 +7312,9 @@  discard block
 block discarded – undo
6685 7312
 					dol_syslog('Error bad setup of extrafield', LOG_WARNING);
6686 7313
 					return 'Error bad setup of extrafield';
6687 7314
 				}
6688
-			} else $value = '';
7315
+			} else {
7316
+				$value = '';
7317
+			}
6689 7318
 		} elseif ($type == 'text' || $type == 'html')
6690 7319
 		{
6691 7320
 			$value = dol_htmlentitiesbr($value);
@@ -6720,7 +7349,9 @@  discard block
 block discarded – undo
6720 7349
 	{
6721 7350
 		global $db, $conf, $langs, $action, $form, $hookmanager;
6722 7351
 
6723
-		if (!is_object($form)) $form = new Form($db);
7352
+		if (!is_object($form)) {
7353
+			$form = new Form($db);
7354
+		}
6724 7355
 
6725 7356
 		$out = '';
6726 7357
 
@@ -6739,7 +7370,9 @@  discard block
 block discarded – undo
6739 7370
 				foreach ($extrafields->attributes[$this->table_element]['label'] as $key=>$label)
6740 7371
 				{
6741 7372
 					// Show only the key field in params
6742
-					if (is_array($params) && array_key_exists('onlykey', $params) && $key != $params['onlykey']) continue;
7373
+					if (is_array($params) && array_key_exists('onlykey', $params) && $key != $params['onlykey']) {
7374
+						continue;
7375
+					}
6743 7376
 
6744 7377
 					// @todo Add test also on 'enabled' (different than 'list' that is 'visibility')
6745 7378
 					$enabled = 1;
@@ -6747,7 +7380,9 @@  discard block
 block discarded – undo
6747 7380
 					{
6748 7381
 	                    $enabled = dol_eval($extrafields->attributes[$this->table_element]['enabled'][$key], 1);
6749 7382
 	                }
6750
-					if (empty($enabled)) continue;
7383
+					if (empty($enabled)) {
7384
+						continue;
7385
+					}
6751 7386
 
6752 7387
 					$visibility = 1;
6753 7388
 					if ($visibility && isset($extrafields->attributes[$this->table_element]['list'][$key]))
@@ -6761,10 +7396,20 @@  discard block
 block discarded – undo
6761 7396
 						$perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1);
6762 7397
 					}
6763 7398
 
6764
-					if (($mode == 'create') && abs($visibility) != 1 && abs($visibility) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list
6765
-					elseif (($mode == 'edit') && abs($visibility) != 1 && abs($visibility) != 3 && abs($visibility) != 4) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list and <> 4 = not visible at the creation
6766
-					elseif ($mode == 'view' && empty($visibility)) continue;
6767
-					if (empty($perms)) continue;
7399
+					if (($mode == 'create') && abs($visibility) != 1 && abs($visibility) != 3) {
7400
+						continue;
7401
+					}
7402
+					// <> -1 and <> 1 and <> 3 = not visible on forms, only on list
7403
+					elseif (($mode == 'edit') && abs($visibility) != 1 && abs($visibility) != 3 && abs($visibility) != 4) {
7404
+						continue;
7405
+					}
7406
+					// <> -1 and <> 1 and <> 3 = not visible on forms, only on list and <> 4 = not visible at the creation
7407
+					elseif ($mode == 'view' && empty($visibility)) {
7408
+						continue;
7409
+					}
7410
+					if (empty($perms)) {
7411
+						continue;
7412
+					}
6768 7413
 					// Load language if required
6769 7414
 					if (!empty($extrafields->attributes[$this->table_element]['langfile'][$key])) {
6770 7415
 						$langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]);
@@ -6851,10 +7496,12 @@  discard block
 block discarded – undo
6851 7496
 						if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date', 'datetime')))
6852 7497
 						{
6853 7498
 							$datenotinstring = $this->array_options['options_'.$key];
6854
-							if (!is_numeric($this->array_options['options_'.$key]))	// For backward compatibility
7499
+							if (!is_numeric($this->array_options['options_'.$key])) {
7500
+								// For backward compatibility
6855 7501
 							{
6856 7502
 								$datenotinstring = $this->db->jdate($datenotinstring);
6857 7503
 							}
7504
+							}
6858 7505
 							$value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix) ?dol_mktime(GETPOST($keyprefix.'options_'.$key.$keysuffix."hour", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."min", 'int', 3), 0, GETPOST($keyprefix.'options_'.$key.$keysuffix."month", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."day", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."year", 'int', 3)) : $datenotinstring;
6859 7506
 						}
6860 7507
 						// Convert float submited string into real php numeric (value in memory must be a php numeric)
@@ -6865,8 +7512,11 @@  discard block
 block discarded – undo
6865 7512
 						// HTML, select, integer and text add default value
6866 7513
 						if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('html', 'text', 'select', 'int')))
6867 7514
 						{
6868
-							if ($action == 'create') $value = $extrafields->attributes[$this->table_element]['default'][$key];
6869
-							else $value = $this->array_options['options_'.$key];
7515
+							if ($action == 'create') {
7516
+								$value = $extrafields->attributes[$this->table_element]['default'][$key];
7517
+							} else {
7518
+								$value = $this->array_options['options_'.$key];
7519
+							}
6870 7520
 						}
6871 7521
 
6872 7522
 						$labeltoshow = $langs->trans($label);
@@ -6880,14 +7530,24 @@  discard block
 block discarded – undo
6880 7530
 						$tpl_context = isset($params["tpl_context"]) ? $params["tpl_context"] : "none";
6881 7531
 						if ($tpl_context == "public") {	// Public page : red dot instead of fieldrequired characters
6882 7532
 							$out .= '">';
6883
-							if (!empty($extrafields->attributes[$this->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $helptoshow);
6884
-							else $out .= $labeltoshow;
6885
-							if ($mode != 'view' && !empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= '&nbsp;<font color="red">*</font>';
7533
+							if (!empty($extrafields->attributes[$this->table_element]['help'][$key])) {
7534
+								$out .= $form->textwithpicto($labeltoshow, $helptoshow);
7535
+							} else {
7536
+								$out .= $labeltoshow;
7537
+							}
7538
+							if ($mode != 'view' && !empty($extrafields->attributes[$this->table_element]['required'][$key])) {
7539
+								$out .= '&nbsp;<font color="red">*</font>';
7540
+							}
6886 7541
 						} else {
6887
-							if ($mode != 'view' && !empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired';
7542
+							if ($mode != 'view' && !empty($extrafields->attributes[$this->table_element]['required'][$key])) {
7543
+								$out .= ' fieldrequired';
7544
+							}
6888 7545
 							$out .= '">';
6889
-							if (!empty($extrafields->attributes[$this->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $helptoshow);
6890
-							else $out .= $labeltoshow;
7546
+							if (!empty($extrafields->attributes[$this->table_element]['help'][$key])) {
7547
+								$out .= $form->textwithpicto($labeltoshow, $helptoshow);
7548
+							} else {
7549
+								$out .= $labeltoshow;
7550
+							}
6891 7551
 						}
6892 7552
 						$out .= '</td>';
6893 7553
 
@@ -6912,8 +7572,11 @@  discard block
 block discarded – undo
6912 7572
 							$out .='<td class="'.$this->element.'_extras_'.$key.'"></td>';
6913 7573
 						}*/
6914 7574
 
6915
-						if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>';
6916
-						else $out .= '</tr>';
7575
+						if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) {
7576
+							$out .= '</tr>';
7577
+						} else {
7578
+							$out .= '</tr>';
7579
+						}
6917 7580
 						$e++;
6918 7581
 					}
6919 7582
 				}
@@ -6970,7 +7633,9 @@  discard block
 block discarded – undo
6970 7633
 		global $user;
6971 7634
 
6972 7635
 		$element = $this->element;
6973
-		if ($element == 'facturerec') $element = 'facture';
7636
+		if ($element == 'facturerec') {
7637
+			$element = 'facture';
7638
+		}
6974 7639
 
6975 7640
 		return $user->rights->{$element};
6976 7641
 	}
@@ -6995,7 +7660,10 @@  discard block
 block discarded – undo
6995 7660
 
6996 7661
 			if (!$db->query($sql))
6997 7662
 			{
6998
-				if ($ignoreerrors) return true; // TODO Not enough. If there is A-B on kept thirdarty and B-C on old one, we must get A-B-C after merge. Not A-B.
7663
+				if ($ignoreerrors) {
7664
+					return true;
7665
+				}
7666
+				// TODO Not enough. If there is A-B on kept thirdarty and B-C on old one, we must get A-B-C after merge. Not A-B.
6999 7667
 				//$this->errors = $db->lasterror();
7000 7668
 				return false;
7001 7669
 			}
@@ -7022,9 +7690,11 @@  discard block
 block discarded – undo
7022 7690
 
7023 7691
 		$buyPrice = 0;
7024 7692
 
7025
-		if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) // In most cases, test here is false
7693
+		if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) {
7694
+			// In most cases, test here is false
7026 7695
 		{
7027 7696
 			$buyPrice = $unitPrice * (1 - $discountPercent / 100);
7697
+		}
7028 7698
 		} else {
7029 7699
 			// Get cost price for margin calculation
7030 7700
 			if (!empty($fk_product))
@@ -7171,18 +7841,26 @@  discard block
 block discarded – undo
7171 7841
 					if ($size == 1 || $size == 'small') {   // Format vignette
7172 7842
 						// Find name of thumb file
7173 7843
 						$photo_vignette = basename(getImageFileNameForSize($dir.$file, '_small'));
7174
-						if (!dol_is_file($dirthumb.$photo_vignette)) $photo_vignette = '';
7844
+						if (!dol_is_file($dirthumb.$photo_vignette)) {
7845
+							$photo_vignette = '';
7846
+						}
7175 7847
 
7176 7848
 						// Get filesize of original file
7177 7849
 						$imgarray = dol_getImageSize($dir.$photo);
7178 7850
 
7179 7851
 						if ($nbbyrow > 0)
7180 7852
 						{
7181
-							if ($nbphoto == 1) $return .= '<table class="valigntop center centpercent" style="border: 0; padding: 2px; border-spacing: 2px; border-collapse: separate;">';
7853
+							if ($nbphoto == 1) {
7854
+								$return .= '<table class="valigntop center centpercent" style="border: 0; padding: 2px; border-spacing: 2px; border-collapse: separate;">';
7855
+							}
7182 7856
 
7183
-							if ($nbphoto % $nbbyrow == 1) $return .= '<tr class="center valignmiddle" style="border: 1px">';
7857
+							if ($nbphoto % $nbbyrow == 1) {
7858
+								$return .= '<tr class="center valignmiddle" style="border: 1px">';
7859
+							}
7184 7860
 							$return .= '<td style="width: '.ceil(100 / $nbbyrow).'%" class="photo">';
7185
-						} elseif ($nbbyrow < 0) $return .= '<div class="inline-block">';
7861
+						} elseif ($nbbyrow < 0) {
7862
+							$return .= '<div class="inline-block">';
7863
+						}
7186 7864
 
7187 7865
 						$return .= "\n";
7188 7866
 
@@ -7190,15 +7868,20 @@  discard block
 block discarded – undo
7190 7868
 						if (empty($nolink))
7191 7869
 						{
7192 7870
 							$urladvanced = getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity='.$this->entity);
7193
-							if ($urladvanced) $return .= '<a href="'.$urladvanced.'">';
7194
-							else $return .= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">';
7871
+							if ($urladvanced) {
7872
+								$return .= '<a href="'.$urladvanced.'">';
7873
+							} else {
7874
+								$return .= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">';
7875
+							}
7195 7876
 						}
7196 7877
 
7197 7878
 						// Show image (width height=$maxHeight)
7198 7879
 						// Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine
7199 7880
 						$alt = $langs->transnoentitiesnoconv('File').': '.$relativefile;
7200 7881
 						$alt .= ' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height'];
7201
-						if ($notitle) $alt = '';
7882
+						if ($notitle) {
7883
+							$alt = '';
7884
+						}
7202 7885
 
7203 7886
 						if ($usesharelink)
7204 7887
 						{
@@ -7227,10 +7910,14 @@  discard block
 block discarded – undo
7227 7910
 							}
7228 7911
 						}
7229 7912
 
7230
-						if (empty($nolink)) $return .= '</a>';
7913
+						if (empty($nolink)) {
7914
+							$return .= '</a>';
7915
+						}
7231 7916
 						$return .= "\n";
7232 7917
 
7233
-						if ($showfilename) $return .= '<br>'.$viewfilename;
7918
+						if ($showfilename) {
7919
+							$return .= '<br>'.$viewfilename;
7920
+						}
7234 7921
 						if ($showaction)
7235 7922
 						{
7236 7923
 							$return .= '<br>';
@@ -7255,14 +7942,20 @@  discard block
 block discarded – undo
7255 7942
 						if ($nbbyrow > 0)
7256 7943
 						{
7257 7944
 							$return .= '</td>';
7258
-							if (($nbphoto % $nbbyrow) == 0) $return .= '</tr>';
7259
-						} elseif ($nbbyrow < 0) $return .= '</div>';
7945
+							if (($nbphoto % $nbbyrow) == 0) {
7946
+								$return .= '</tr>';
7947
+							}
7948
+						} elseif ($nbbyrow < 0) {
7949
+							$return .= '</div>';
7950
+						}
7260 7951
 					}
7261 7952
 
7262 7953
 					if (empty($size)) {     // Format origine
7263 7954
 						$return .= '<img class="photo photowithmargin" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">';
7264 7955
 
7265
-						if ($showfilename) $return .= '<br>'.$viewfilename;
7956
+						if ($showfilename) {
7957
+							$return .= '<br>'.$viewfilename;
7958
+						}
7266 7959
 						if ($showaction)
7267 7960
 						{
7268 7961
 							// Special case for product
@@ -7279,7 +7972,9 @@  discard block
 block discarded – undo
7279 7972
 					}
7280 7973
 
7281 7974
 					// On continue ou on arrete de boucler ?
7282
-					if ($nbmax && $nbphoto >= $nbmax) break;
7975
+					if ($nbmax && $nbphoto >= $nbmax) {
7976
+						break;
7977
+					}
7283 7978
 				}
7284 7979
 			}
7285 7980
 
@@ -7294,7 +7989,9 @@  discard block
 block discarded – undo
7294 7989
 						$nbphoto++;
7295 7990
 					}
7296 7991
 
7297
-					if ($nbphoto) $return .= '</table>';
7992
+					if ($nbphoto) {
7993
+						$return .= '</table>';
7994
+					}
7298 7995
 				}
7299 7996
 			}
7300 7997
 		}
@@ -7315,8 +8012,11 @@  discard block
 block discarded – undo
7315 8012
 	{
7316 8013
 		if (is_array($info))
7317 8014
 		{
7318
-			if (isset($info['type']) && $info['type'] == 'array') return true;
7319
-			else return false;
8015
+			if (isset($info['type']) && $info['type'] == 'array') {
8016
+				return true;
8017
+			} else {
8018
+				return false;
8019
+			}
7320 8020
 		}
7321 8021
 		return false;
7322 8022
 	}
@@ -7329,7 +8029,9 @@  discard block
 block discarded – undo
7329 8029
 	 */
7330 8030
 	public function isDate($info)
7331 8031
 	{
7332
-		if (isset($info['type']) && ($info['type'] == 'date' || $info['type'] == 'datetime' || $info['type'] == 'timestamp')) return true;
8032
+		if (isset($info['type']) && ($info['type'] == 'date' || $info['type'] == 'datetime' || $info['type'] == 'timestamp')) {
8033
+			return true;
8034
+		}
7333 8035
 		return false;
7334 8036
 	}
7335 8037
 
@@ -7343,9 +8045,14 @@  discard block
 block discarded – undo
7343 8045
 	{
7344 8046
 		if (is_array($info))
7345 8047
 		{
7346
-			if (isset($info['type']) && ($info['type'] == 'duration')) return true;
7347
-			else return false;
7348
-		} else return false;
8048
+			if (isset($info['type']) && ($info['type'] == 'duration')) {
8049
+				return true;
8050
+			} else {
8051
+				return false;
8052
+			}
8053
+		} else {
8054
+			return false;
8055
+		}
7349 8056
 	}
7350 8057
 
7351 8058
 	/**
@@ -7358,9 +8065,14 @@  discard block
 block discarded – undo
7358 8065
 	{
7359 8066
 		if (is_array($info))
7360 8067
 		{
7361
-			if (isset($info['type']) && ($info['type'] == 'int' || preg_match('/^integer/i', $info['type']))) return true;
7362
-			else return false;
7363
-		} else return false;
8068
+			if (isset($info['type']) && ($info['type'] == 'int' || preg_match('/^integer/i', $info['type']))) {
8069
+				return true;
8070
+			} else {
8071
+				return false;
8072
+			}
8073
+		} else {
8074
+			return false;
8075
+		}
7364 8076
 	}
7365 8077
 
7366 8078
 	/**
@@ -7373,8 +8085,11 @@  discard block
 block discarded – undo
7373 8085
 	{
7374 8086
 		if (is_array($info))
7375 8087
 		{
7376
-			if (isset($info['type']) && (preg_match('/^(double|real|price)/i', $info['type']))) return true;
7377
-			else return false;
8088
+			if (isset($info['type']) && (preg_match('/^(double|real|price)/i', $info['type']))) {
8089
+				return true;
8090
+			} else {
8091
+				return false;
8092
+			}
7378 8093
 		}
7379 8094
 		return false;
7380 8095
 	}
@@ -7389,8 +8104,11 @@  discard block
 block discarded – undo
7389 8104
 	{
7390 8105
 		if (is_array($info))
7391 8106
 		{
7392
-			if (isset($info['type']) && $info['type'] == 'text') return true;
7393
-			else return false;
8107
+			if (isset($info['type']) && $info['type'] == 'text') {
8108
+				return true;
8109
+			} else {
8110
+				return false;
8111
+			}
7394 8112
 		}
7395 8113
 		return false;
7396 8114
 	}
@@ -7405,8 +8123,11 @@  discard block
 block discarded – undo
7405 8123
 	{
7406 8124
 		if (is_array($info))
7407 8125
 		{
7408
-			if (isset($info['notnull']) && $info['notnull'] != '1') return true;
7409
-			else return false;
8126
+			if (isset($info['notnull']) && $info['notnull'] != '1') {
8127
+				return true;
8128
+			} else {
8129
+				return false;
8130
+			}
7410 8131
 		}
7411 8132
 		return true;
7412 8133
 	}
@@ -7421,8 +8142,11 @@  discard block
 block discarded – undo
7421 8142
 	{
7422 8143
 		if (is_array($info))
7423 8144
 		{
7424
-			if (isset($info['notnull']) && $info['notnull'] == '-1') return true;
7425
-			else return false;
8145
+			if (isset($info['notnull']) && $info['notnull'] == '-1') {
8146
+				return true;
8147
+			} else {
8148
+				return false;
8149
+			}
7426 8150
 		}
7427 8151
 		return false;
7428 8152
 	}
@@ -7437,8 +8161,11 @@  discard block
 block discarded – undo
7437 8161
 	{
7438 8162
 		if (is_array($info))
7439 8163
 		{
7440
-			if (isset($info['index']) && $info['index'] == true) return true;
7441
-			else return false;
8164
+			if (isset($info['index']) && $info['index'] == true) {
8165
+				return true;
8166
+			} else {
8167
+				return false;
8168
+			}
7442 8169
 		}
7443 8170
 		return false;
7444 8171
 	}
@@ -7456,7 +8183,8 @@  discard block
 block discarded – undo
7456 8183
 		global $conf;
7457 8184
 
7458 8185
 		$queryarray = array();
7459
-		foreach ($this->fields as $field => $info)	// Loop on definition of fields
8186
+		foreach ($this->fields as $field => $info) {
8187
+			// Loop on definition of fields
7460 8188
 		{
7461 8189
 			// Depending on field type ('datetime', ...)
7462 8190
 			if ($this->isDate($info))
@@ -7464,6 +8192,7 @@  discard block
 block discarded – undo
7464 8192
 				if (empty($this->{$field}))
7465 8193
 				{
7466 8194
 					$queryarray[$field] = null;
8195
+		}
7467 8196
 				} else {
7468 8197
 					$queryarray[$field] = $this->db->idate($this->{$field});
7469 8198
 				}
@@ -7480,24 +8209,43 @@  discard block
 block discarded – undo
7480 8209
 			} elseif ($this->isDuration($info))
7481 8210
 			{
7482 8211
 				// $this->{$field} may be null, '', 0, '0', 123, '123'
7483
-				if ($this->{$field} != '' || !empty($info['notnull'])) $queryarray[$field] = (int) $this->{$field};		// If '0', it may be set to null later if $info['notnull'] == -1
7484
-				else $queryarray[$field] = null;
8212
+				if ($this->{$field} != '' || !empty($info['notnull'])) {
8213
+					$queryarray[$field] = (int) $this->{$field};
8214
+				}
8215
+				// If '0', it may be set to null later if $info['notnull'] == -1
8216
+				else {
8217
+					$queryarray[$field] = null;
8218
+				}
7485 8219
 			} elseif ($this->isInt($info) || $this->isFloat($info))
7486 8220
 			{
7487
-				if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field] = $conf->entity;
7488
-				else {
8221
+				if ($field == 'entity' && is_null($this->{$field})) {
8222
+					$queryarray[$field] = $conf->entity;
8223
+				} else {
7489 8224
 					// $this->{$field} may be null, '', 0, '0', 123, '123'
7490 8225
 					if ($this->{$field} != '' || !empty($info['notnull'])) {
7491
-						if ($this->isInt($info)) $queryarray[$field] = (int) $this->{$field};	// If '0', it may be set to null later if $info['notnull'] == -1
7492
-						if ($this->isFloat($info)) $queryarray[$field] = (double) $this->{$field};	// If '0', it may be set to null later if $info['notnull'] == -1
7493
-					} else $queryarray[$field] = null;
8226
+						if ($this->isInt($info)) {
8227
+							$queryarray[$field] = (int) $this->{$field};
8228
+						}
8229
+						// If '0', it may be set to null later if $info['notnull'] == -1
8230
+						if ($this->isFloat($info)) {
8231
+							$queryarray[$field] = (double) $this->{$field};
8232
+						}
8233
+						// If '0', it may be set to null later if $info['notnull'] == -1
8234
+					} else {
8235
+						$queryarray[$field] = null;
8236
+					}
7494 8237
 				}
7495 8238
 			} else {
7496 8239
 				$queryarray[$field] = $this->{$field};
7497 8240
 			}
7498 8241
 
7499
-			if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]);
7500
-			if (!empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; // May force 0 to null
8242
+			if ($info['type'] == 'timestamp' && empty($queryarray[$field])) {
8243
+				unset($queryarray[$field]);
8244
+			}
8245
+			if (!empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) {
8246
+				$queryarray[$field] = null;
8247
+			}
8248
+			// May force 0 to null
7501 8249
 		}
7502 8250
 
7503 8251
 		return $queryarray;
@@ -7515,25 +8263,34 @@  discard block
 block discarded – undo
7515 8263
 		{
7516 8264
 			if ($this->isDate($info))
7517 8265
 			{
7518
-				if (empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0;
7519
-				else $this->{$field} = strtotime($obj->{$field});
8266
+				if (empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') {
8267
+					$this->{$field} = 0;
8268
+				} else {
8269
+					$this->{$field} = strtotime($obj->{$field});
8270
+				}
7520 8271
 			} elseif ($this->isArray($info))
7521 8272
 			{
7522 8273
 				if (!empty($obj->{$field})) {
7523 8274
 					$this->{$field} = @unserialize($obj->{$field});
7524 8275
 					// Hack for data not in UTF8
7525
-					if ($this->{$field } === false) @unserialize(utf8_decode($obj->{$field}));
8276
+					if ($this->{$field } === false) {
8277
+						@unserialize(utf8_decode($obj->{$field}));
8278
+					}
7526 8279
 				} else {
7527 8280
 					$this->{$field} = array();
7528 8281
 				}
7529 8282
 			} elseif ($this->isInt($info))
7530 8283
 			{
7531
-				if ($field == 'rowid') $this->id = (int) $obj->{$field};
7532
-				else {
8284
+				if ($field == 'rowid') {
8285
+					$this->id = (int) $obj->{$field};
8286
+				} else {
7533 8287
 					if ($this->isForcedToNullIfZero($info))
7534 8288
 					{
7535
-						if (empty($obj->{$field})) $this->{$field} = null;
7536
-						else $this->{$field} = (double) $obj->{$field};
8289
+						if (empty($obj->{$field})) {
8290
+							$this->{$field} = null;
8291
+						} else {
8292
+							$this->{$field} = (double) $obj->{$field};
8293
+						}
7537 8294
 					} else {
7538 8295
 						if (!is_null($obj->{$field}) || (isset($info['notnull']) && $info['notnull'] == 1)) {
7539 8296
 							$this->{$field} = (int) $obj->{$field};
@@ -7546,8 +8303,11 @@  discard block
 block discarded – undo
7546 8303
 			{
7547 8304
 				if ($this->isForcedToNullIfZero($info))
7548 8305
 				{
7549
-					if (empty($obj->{$field})) $this->{$field} = null;
7550
-					else $this->{$field} = (double) $obj->{$field};
8306
+					if (empty($obj->{$field})) {
8307
+						$this->{$field} = null;
8308
+					} else {
8309
+						$this->{$field} = (double) $obj->{$field};
8310
+					}
7551 8311
 				} else {
7552 8312
 					if (!is_null($obj->{$field}) || (isset($info['notnull']) && $info['notnull'] == 1)) {
7553 8313
 						$this->{$field} = (double) $obj->{$field};
@@ -7561,7 +8321,9 @@  discard block
 block discarded – undo
7561 8321
 		}
7562 8322
 
7563 8323
 		// If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions.
7564
-		if (!isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id;
8324
+		if (!isset($this->fields['ref']) && isset($this->id)) {
8325
+			$this->ref = $this->id;
8326
+		}
7565 8327
 	}
7566 8328
 
7567 8329
 	/**
@@ -7584,13 +8346,19 @@  discard block
 block discarded – undo
7584 8346
 	 */
7585 8347
 	protected function quote($value, $fieldsentry)
7586 8348
 	{
7587
-		if (is_null($value)) return 'NULL';
7588
-		elseif (preg_match('/^(int|double|real|price)/i', $fieldsentry['type'])) return $this->db->escape("$value");
7589
-		elseif ($fieldsentry['type'] == 'boolean') {
7590
-		    if ($value) return 'true';
7591
-		    else return 'false';
7592
-        }
7593
-		else return "'".$this->db->escape($value)."'";
8349
+		if (is_null($value)) {
8350
+			return 'NULL';
8351
+		} elseif (preg_match('/^(int|double|real|price)/i', $fieldsentry['type'])) {
8352
+			return $this->db->escape("$value");
8353
+		} elseif ($fieldsentry['type'] == 'boolean') {
8354
+		    if ($value) {
8355
+		    	return 'true';
8356
+		    } else {
8357
+		    	return 'false';
8358
+		    }
8359
+        } else {
8360
+			return "'".$this->db->escape($value)."'";
8361
+		}
7594 8362
 	}
7595 8363
 
7596 8364
 
@@ -7612,10 +8380,17 @@  discard block
 block discarded – undo
7612 8380
 
7613 8381
 		$fieldvalues = $this->setSaveQuery();
7614 8382
 
7615
-		if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation'] = $this->db->idate($now);
7616
-		if (array_key_exists('fk_user_creat', $fieldvalues) && !($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat'] = $user->id;
8383
+		if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) {
8384
+			$fieldvalues['date_creation'] = $this->db->idate($now);
8385
+		}
8386
+		if (array_key_exists('fk_user_creat', $fieldvalues) && !($fieldvalues['fk_user_creat'] > 0)) {
8387
+			$fieldvalues['fk_user_creat'] = $user->id;
8388
+		}
7617 8389
 		unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert.
7618
-		if (array_key_exists('ref', $fieldvalues)) $fieldvalues['ref'] = dol_string_nospecial($fieldvalues['ref']); // If field is a ref, we sanitize data
8390
+		if (array_key_exists('ref', $fieldvalues)) {
8391
+			$fieldvalues['ref'] = dol_string_nospecial($fieldvalues['ref']);
8392
+		}
8393
+		// If field is a ref, we sanitize data
7619 8394
 
7620 8395
 		$keys = array();
7621 8396
 		$values = array();
@@ -7629,8 +8404,12 @@  discard block
 block discarded – undo
7629 8404
 		foreach ($keys as $key)
7630 8405
 		{
7631 8406
 			// If field is an implicit foreign key field
7632
-			if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key] = '';
7633
-			if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key] = '';
8407
+			if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') {
8408
+				$values[$key] = '';
8409
+			}
8410
+			if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') {
8411
+				$values[$key] = '';
8412
+			}
7634 8413
 
7635 8414
 			//var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1));
7636 8415
 			if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && !isset($values[$key]) && is_null($this->fields[$key]['default']))
@@ -7641,13 +8420,20 @@  discard block
 block discarded – undo
7641 8420
 
7642 8421
 			// If field is an implicit foreign key field
7643 8422
 			if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) {
7644
-				if (isset($this->fields[$key]['default'])) $values[$key] = $this->fields[$key]['default'];
7645
-				else $values[$key] = 'null';
8423
+				if (isset($this->fields[$key]['default'])) {
8424
+					$values[$key] = $this->fields[$key]['default'];
8425
+				} else {
8426
+					$values[$key] = 'null';
8427
+				}
8428
+			}
8429
+			if (!empty($this->fields[$key]['foreignkey']) && empty($values[$key])) {
8430
+				$values[$key] = 'null';
7646 8431
 			}
7647
-			if (!empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key] = 'null';
7648 8432
 		}
7649 8433
 
7650
-		if ($error) return -1;
8434
+		if ($error) {
8435
+			return -1;
8436
+		}
7651 8437
 
7652 8438
 		$this->db->begin();
7653 8439
 
@@ -7691,7 +8477,9 @@  discard block
 block discarded – undo
7691 8477
 		if (!$error)
7692 8478
 		{
7693 8479
 			$result = $this->insertExtraFields();
7694
-			if ($result < 0) $error++;
8480
+			if ($result < 0) {
8481
+				$error++;
8482
+			}
7695 8483
 		}
7696 8484
 
7697 8485
 		// Create lines
@@ -7707,7 +8495,9 @@  discard block
 block discarded – undo
7707 8495
 
7708 8496
 				// Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array
7709 8497
 				//if (! is_object($line)) $line=json_decode(json_encode($line), false);  // convert recursively array into object.
7710
-				if (!is_object($line)) $line = (object) $line;
8498
+				if (!is_object($line)) {
8499
+					$line = (object) $line;
8500
+				}
7711 8501
 
7712 8502
 				$result = $line->create($user, 1);
7713 8503
 				if ($result < 0)
@@ -7749,19 +8539,32 @@  discard block
 block discarded – undo
7749 8539
 	 */
7750 8540
 	public function fetchCommon($id, $ref = null, $morewhere = '')
7751 8541
 	{
7752
-		if (empty($id) && empty($ref) && empty($morewhere)) return -1;
8542
+		if (empty($id) && empty($ref) && empty($morewhere)) {
8543
+			return -1;
8544
+		}
7753 8545
 
7754 8546
 		$fieldlist = $this->getFieldList();
7755
-		if (empty($fieldlist)) return 0;
8547
+		if (empty($fieldlist)) {
8548
+			return 0;
8549
+		}
7756 8550
 
7757 8551
 		$sql = 'SELECT '.$fieldlist;
7758 8552
 		$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
7759 8553
 
7760
-		if (!empty($id))  $sql .= ' WHERE rowid = '.$id;
7761
-		elseif (!empty($ref)) $sql .= " WHERE ref = ".$this->quote($ref, $this->fields['ref']);
7762
-		else $sql .= ' WHERE 1 = 1'; // usage with empty id and empty ref is very rare
7763
-		if (empty($id) && isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' AND entity IN ('.getEntity($this->table_element).')';
7764
-		if ($morewhere)   $sql .= $morewhere;
8554
+		if (!empty($id)) {
8555
+			$sql .= ' WHERE rowid = '.$id;
8556
+		} elseif (!empty($ref)) {
8557
+			$sql .= " WHERE ref = ".$this->quote($ref, $this->fields['ref']);
8558
+		} else {
8559
+			$sql .= ' WHERE 1 = 1';
8560
+		}
8561
+		// usage with empty id and empty ref is very rare
8562
+		if (empty($id) && isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
8563
+			$sql .= ' AND entity IN ('.getEntity($this->table_element).')';
8564
+		}
8565
+		if ($morewhere) {
8566
+			$sql .= $morewhere;
8567
+		}
7765 8568
 		$sql .= ' LIMIT 1'; // This is a fetch, to be sure to get only one record
7766 8569
 
7767 8570
 		$res = $this->db->query($sql);
@@ -7807,7 +8610,9 @@  discard block
 block discarded – undo
7807 8610
 		$sql = 'SELECT '.$objectline->getFieldList();
7808 8611
 		$sql .= ' FROM '.MAIN_DB_PREFIX.$objectline->table_element;
7809 8612
 		$sql .= ' WHERE fk_'.$this->element.' = '.$this->id;
7810
-		if ($morewhere)   $sql .= $morewhere;
8613
+		if ($morewhere) {
8614
+			$sql .= $morewhere;
8615
+		}
7811 8616
 		if (isset($objectline->fields['position'])) {
7812 8617
 			$sql .= $this->db->order('position', 'ASC');
7813 8618
 		}
@@ -7856,10 +8661,17 @@  discard block
 block discarded – undo
7856 8661
 
7857 8662
 		$fieldvalues = $this->setSaveQuery();
7858 8663
 
7859
-		if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification'] = $this->db->idate($now);
7860
-		if (array_key_exists('fk_user_modif', $fieldvalues) && !($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif'] = $user->id;
8664
+		if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) {
8665
+			$fieldvalues['date_modification'] = $this->db->idate($now);
8666
+		}
8667
+		if (array_key_exists('fk_user_modif', $fieldvalues) && !($fieldvalues['fk_user_modif'] > 0)) {
8668
+			$fieldvalues['fk_user_modif'] = $user->id;
8669
+		}
7861 8670
 		unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update.
7862
-		if (array_key_exists('ref', $fieldvalues)) $fieldvalues['ref'] = dol_string_nospecial($fieldvalues['ref']); // If field is a ref, we sanitize data
8671
+		if (array_key_exists('ref', $fieldvalues)) {
8672
+			$fieldvalues['ref'] = dol_string_nospecial($fieldvalues['ref']);
8673
+		}
8674
+		// If field is a ref, we sanitize data
7863 8675
 
7864 8676
 		$keys = array();
7865 8677
 		$values = array();
@@ -7874,8 +8686,14 @@  discard block
 block discarded – undo
7874 8686
 		// Clean and check mandatory
7875 8687
 		foreach ($keys as $key)
7876 8688
 		{
7877
-			if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key] = ''; // This is an implicit foreign key field
7878
-			if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key] = ''; // This is an explicit foreign key field
8689
+			if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') {
8690
+				$values[$key] = '';
8691
+			}
8692
+			// This is an implicit foreign key field
8693
+			if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') {
8694
+				$values[$key] = '';
8695
+			}
8696
+			// This is an explicit foreign key field
7879 8697
 
7880 8698
 			//var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1));
7881 8699
 			/*
@@ -7944,11 +8762,13 @@  discard block
 block discarded – undo
7944 8762
 
7945 8763
 		$this->db->begin();
7946 8764
 
7947
-		if ($forcechilddeletion)	// Force also delete of childtables that should lock deletion in standard case when option force is off
8765
+		if ($forcechilddeletion) {
8766
+			// Force also delete of childtables that should lock deletion in standard case when option force is off
7948 8767
 		{
7949 8768
 			foreach ($this->childtables as $table)
7950 8769
 			{
7951 8770
 				$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.$this->fk_element.' = '.$this->id;
8771
+		}
7952 8772
 				$resql = $this->db->query($sql);
7953 8773
 				if (!$resql)
7954 8774
 				{
@@ -7958,9 +8778,11 @@  discard block
 block discarded – undo
7958 8778
 					return -1;
7959 8779
 				}
7960 8780
 			}
7961
-		} elseif (!empty($this->fk_element) && !empty($this->childtables))	// If object has childs linked with a foreign key field, we check all child tables.
8781
+		} elseif (!empty($this->fk_element) && !empty($this->childtables)) {
8782
+			// If object has childs linked with a foreign key field, we check all child tables.
7962 8783
 		{
7963 8784
 			$objectisused = $this->isObjectUsed($this->id);
8785
+		}
7964 8786
 			if (!empty($objectisused))
7965 8787
 			{
7966 8788
 				dol_syslog(get_class($this)."::deleteCommon Can't delete record as it has some child", LOG_WARNING);
@@ -8129,7 +8951,9 @@  discard block
 block discarded – undo
8129 8951
 
8130 8952
 		// Call trigger
8131 8953
 		$result = $this->call_trigger('LINE'.strtoupper($tmpforobjectclass).'_DELETE', $user);
8132
-		if ($result < 0) return -1;
8954
+		if ($result < 0) {
8955
+			return -1;
8956
+		}
8133 8957
 		// End call triggers
8134 8958
 
8135 8959
 		$this->db->begin();
@@ -8200,7 +9024,9 @@  discard block
 block discarded – undo
8200 9024
 			if (!$error && !$notrigger) {
8201 9025
 				// Call trigger
8202 9026
 				$result = $this->call_trigger($triggercode, $user);
8203
-				if ($result < 0) $error++;
9027
+				if ($result < 0) {
9028
+					$error++;
9029
+				}
8204 9030
 			}
8205 9031
 
8206 9032
 			if (!$error) {
@@ -8230,14 +9056,30 @@  discard block
 block discarded – undo
8230 9056
 	    global $user;
8231 9057
 
8232 9058
 		$this->id = 0;
8233
-		if (array_key_exists('label', $this->fields)) $this->label = 'This is label';
8234
-		if (array_key_exists('note_public', $this->fields)) $this->note_public = 'Public note';
8235
-		if (array_key_exists('note_private', $this->fields)) $this->note_private = 'Private note';
8236
-		if (array_key_exists('date_creation', $this->fields)) $this->date_creation = (dol_now() - 3600 * 24);
8237
-		if (array_key_exists('date_modification', $this->fields)) $this->date_modification = (dol_now() - 3600 * 24);
8238
-		if (array_key_exists('fk_user_creat', $this->fields)) $this->fk_user_creat = $user->id;
8239
-		if (array_key_exists('fk_user_modif', $this->fields)) $this->fk_user_modif = $user->id;
8240
-		if (array_key_exists('date', $this->fields)) $this->date = dol_now();
9059
+		if (array_key_exists('label', $this->fields)) {
9060
+			$this->label = 'This is label';
9061
+		}
9062
+		if (array_key_exists('note_public', $this->fields)) {
9063
+			$this->note_public = 'Public note';
9064
+		}
9065
+		if (array_key_exists('note_private', $this->fields)) {
9066
+			$this->note_private = 'Private note';
9067
+		}
9068
+		if (array_key_exists('date_creation', $this->fields)) {
9069
+			$this->date_creation = (dol_now() - 3600 * 24);
9070
+		}
9071
+		if (array_key_exists('date_modification', $this->fields)) {
9072
+			$this->date_modification = (dol_now() - 3600 * 24);
9073
+		}
9074
+		if (array_key_exists('fk_user_creat', $this->fields)) {
9075
+			$this->fk_user_creat = $user->id;
9076
+		}
9077
+		if (array_key_exists('fk_user_modif', $this->fields)) {
9078
+			$this->fk_user_modif = $user->id;
9079
+		}
9080
+		if (array_key_exists('date', $this->fields)) {
9081
+			$this->date = dol_now();
9082
+		}
8241 9083
 		// ...
8242 9084
 	}
8243 9085
 
@@ -8281,7 +9123,9 @@  discard block
 block discarded – undo
8281 9123
      */
8282 9124
     public function trimParameters($parameters)
8283 9125
     {
8284
-        if (!is_array($parameters)) return;
9126
+        if (!is_array($parameters)) {
9127
+        	return;
9128
+        }
8285 9129
         foreach ($parameters as $parameter) {
8286 9130
             if (isset($this->$parameter)) {
8287 9131
                 $this->$parameter = trim($this->$parameter);
@@ -8382,7 +9226,9 @@  discard block
 block discarded – undo
8382 9226
 	{
8383 9227
 		$this->db->begin();
8384 9228
 
8385
-		if (empty($type)) $type = $this->table_element;
9229
+		if (empty($type)) {
9230
+			$type = $this->table_element;
9231
+		}
8386 9232
 
8387 9233
 		require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
8388 9234
 		$categorystatic = new Categorie($this->db);
Please login to merge, or discard this patch.
htdocs/core/class/html.form.class.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
 
648 648
 		$disabled = 0;
649 649
 		$ret = '<div class="centpercent center">';
650
-                $ret .= '<select class="flat'.(empty($conf->use_javascript_ajax) ? '' : ' hideobject').' ' . $name . ' ' . $name . 'select valignmiddle alignstart" name="' . $name . '"'.($disabled ? ' disabled="disabled"' : '').'>';
650
+                $ret .= '<select class="flat'.(empty($conf->use_javascript_ajax) ? '' : ' hideobject').' '.$name.' '.$name.'select valignmiddle alignstart" name="'.$name.'"'.($disabled ? ' disabled="disabled"' : '').'>';
651 651
 
652 652
 		// Complete list with data from external modules. THe module can use $_SERVER['PHP_SELF'] to know on which page we are, or use the $parameters['currentcontext'] completed by executeHooks.
653 653
 		$parameters = array();
@@ -666,11 +666,11 @@  discard block
 block discarded – undo
666 666
 
667 667
 		$ret .= '</select>';
668 668
 
669
-                if (empty($conf->dol_optimize_smallscreen)) $ret .= ajax_combobox('.' . $name . 'select');
669
+                if (empty($conf->dol_optimize_smallscreen)) $ret .= ajax_combobox('.'.$name.'select');
670 670
 
671 671
 		// Warning: if you set submit button to disabled, post using 'Enter' will no more work if there is no another input submit. So we add a hidden button
672 672
 		$ret .= '<input type="submit" name="confirmmassactioninvisible" style="display: none" tabindex="-1">'; // Hidden button BEFORE so it is the one used when we submit with ENTER.
673
-                $ret .= '<input type="submit" disabled name="confirmmassaction" class="button'.(empty($conf->use_javascript_ajax) ? '' : ' hideobject').' ' . $name . ' ' . $name . 'confirmed" value="'.dol_escape_htmltag($langs->trans("Confirm")).'">';
673
+                $ret .= '<input type="submit" disabled name="confirmmassaction" class="button'.(empty($conf->use_javascript_ajax) ? '' : ' hideobject').' '.$name.' '.$name.'confirmed" value="'.dol_escape_htmltag($langs->trans("Confirm")).'">';
674 674
 		$ret .= '</div>';
675 675
 
676 676
 		if (!empty($conf->use_javascript_ajax))
@@ -701,11 +701,11 @@  discard block
 block discarded – undo
701 701
         		}
702 702
 
703 703
         	jQuery(document).ready(function () {
704
-                    initCheckForSelect(0, "' . $name . '", "' . $cssclass . '");
705
-                    jQuery(".' . $cssclass . '").click(function() {
706
-                        initCheckForSelect(1, "'.$name.'", "' . $cssclass . '");
704
+                    initCheckForSelect(0, "' . $name.'", "'.$cssclass.'");
705
+                    jQuery(".' . $cssclass.'").click(function() {
706
+                        initCheckForSelect(1, "'.$name.'", "'.$cssclass.'");
707 707
                     });
708
-                        jQuery(".' . $name . 'select").change(function() {
708
+                        jQuery(".' . $name.'select").change(function() {
709 709
         			var massaction = $( this ).val();
710 710
         			var urlform = $( this ).closest("form").attr("action").replace("#show_files","");
711 711
         			if (massaction == "builddoc")
@@ -717,14 +717,14 @@  discard block
 block discarded – undo
717 717
         	        /* Warning: if you set submit button to disabled, post using Enter will no more work if there is no other button */
718 718
         			if ($(this).val() != \'0\')
719 719
     	  			{
720
-                                        jQuery(".' . $name . 'confirmed").prop(\'disabled\', false);
721
-										jQuery(".' . $name . 'other").hide();	/* To disable if another div was open */
722
-                                        jQuery(".' . $name . '"+massaction).show();
720
+                                        jQuery(".' . $name.'confirmed").prop(\'disabled\', false);
721
+										jQuery(".' . $name.'other").hide();	/* To disable if another div was open */
722
+                                        jQuery(".' . $name.'"+massaction).show();
723 723
     	  			}
724 724
     	  			else
725 725
     	  			{
726
-                                        jQuery(".' . $name . 'confirmed").prop(\'disabled\', true);
727
-										jQuery(".' . $name . 'other").hide();	/* To disable any div open */
726
+                                        jQuery(".' . $name.'confirmed").prop(\'disabled\', true);
727
+										jQuery(".' . $name.'other").hide();	/* To disable any div open */
728 728
     	  			}
729 729
     	        });
730 730
         	});
@@ -6500,7 +6500,7 @@  discard block
 block discarded – undo
6500 6500
 
6501 6501
 		if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) return '';
6502 6502
 
6503
-		$tmpvar = "MAIN_SELECTEDFIELDS_".$varpage;	// To get list of saved seleteced properties
6503
+		$tmpvar = "MAIN_SELECTEDFIELDS_".$varpage; // To get list of saved seleteced properties
6504 6504
 		if (!empty($user->conf->$tmpvar))
6505 6505
 		{
6506 6506
 			$tmparray = explode(',', $user->conf->$tmpvar);
@@ -7520,10 +7520,10 @@  discard block
 block discarded – undo
7520 7520
 
7521 7521
 		$out = '';
7522 7522
 		$id = uniqid();
7523
-                if (!empty($conf->use_javascript_ajax)) $out .= '<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass . 's" name="' . $cssclass . 's" class="checkallactions"></div>';
7523
+                if (!empty($conf->use_javascript_ajax)) $out .= '<div class="inline-block checkallactions"><input type="checkbox" id="'.$cssclass.'s" name="'.$cssclass.'s" class="checkallactions"></div>';
7524 7524
 		$out .= '<script>
7525 7525
             $(document).ready(function() {
7526
-                $("#' . $cssclass . 's").click(function() {
7526
+                $("#' . $cssclass.'s").click(function() {
7527 7527
                     if($(this).is(\':checked\')){
7528 7528
                         console.log("We check all '.$cssclass.'");
7529 7529
                 		$(".'.$cssclass.'").prop(\'checked\', true).trigger(\'change\');
@@ -7533,10 +7533,10 @@  discard block
 block discarded – undo
7533 7533
                         console.log("We uncheck all");
7534 7534
                 		$(".'.$cssclass.'").prop(\'checked\', false).trigger(\'change\');
7535 7535
                     }'."\n";
7536
-                if ($calljsfunction) $out .= 'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname . '", "' . $cssclass . '"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
7536
+                if ($calljsfunction) $out .= 'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "'.$massactionname.'", "'.$cssclass.'"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
7537 7537
 		$out .= '         });
7538 7538
 
7539
-                $(".' . $cssclass . '").change(function() {
7539
+                $(".' . $cssclass.'").change(function() {
7540 7540
 				$(this).closest("tr").toggleClass("highlight", this.checked);
7541 7541
 			});
7542 7542
 
Please login to merge, or discard this patch.
Braces   +1472 added lines, -515 removed lines patch added patch discarded remove patch
@@ -116,40 +116,70 @@  discard block
 block discarded – undo
116 116
 			{
117 117
 				$tmp = explode(':', $typeofdata);
118 118
 				$ret .= '<div class="editkey_'.$tmp[0].(!empty($tmp[1]) ? ' '.$tmp[1] : '').'" id="'.$htmlname.'">';
119
-				if ($fieldrequired) $ret .= '<span class="fieldrequired">';
119
+				if ($fieldrequired) {
120
+					$ret .= '<span class="fieldrequired">';
121
+				}
120 122
 				if ($help) {
121 123
 					$ret .= $this->textwithpicto($langs->trans($text), $help);
122 124
 				} else {
123 125
 					$ret .= $langs->trans($text);
124 126
 				}
125
-				if ($fieldrequired) $ret .= '</span>';
127
+				if ($fieldrequired) {
128
+					$ret .= '</span>';
129
+				}
126 130
 				$ret .= '</div>'."\n";
127 131
 			} else {
128
-				if ($fieldrequired) $ret .= '<span class="fieldrequired">';
132
+				if ($fieldrequired) {
133
+					$ret .= '<span class="fieldrequired">';
134
+				}
129 135
 				if ($help) {
130 136
 					$ret .= $this->textwithpicto($langs->trans($text), $help);
131 137
 				} else {
132 138
 					$ret .= $langs->trans($text);
133 139
 				}
134
-				if ($fieldrequired) $ret .= '</span>';
140
+				if ($fieldrequired) {
141
+					$ret .= '</span>';
142
+				}
135 143
 			}
136 144
 		} else {
137
-			if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
138
-			if ($fieldrequired) $ret .= '<span class="fieldrequired">';
145
+			if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) {
146
+				$ret .= '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
147
+			}
148
+			if ($fieldrequired) {
149
+				$ret .= '<span class="fieldrequired">';
150
+			}
139 151
 			if ($help) {
140 152
 				$ret .= $this->textwithpicto($langs->trans($text), $help);
141 153
 			} else {
142 154
 				$ret .= $langs->trans($text);
143 155
 			}
144
-			if ($fieldrequired) $ret .= '</span>';
145
-			if (!empty($notabletag)) $ret .= ' ';
146
-			if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= '</td>';
147
-			if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= '<td class="right">';
148
-			if ($htmlname && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&amp;'.$paramid.'='.$object->id.$moreparam.'">'.img_edit($langs->trans('Edit'), ($notabletag ? 0 : 1)).'</a>';
149
-			if (!empty($notabletag) && $notabletag == 1) $ret .= ' : ';
150
-			if (!empty($notabletag) && $notabletag == 3) $ret .= ' ';
151
-			if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= '</td>';
152
-			if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) $ret .= '</tr></table>';
156
+			if ($fieldrequired) {
157
+				$ret .= '</span>';
158
+			}
159
+			if (!empty($notabletag)) {
160
+				$ret .= ' ';
161
+			}
162
+			if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) {
163
+				$ret .= '</td>';
164
+			}
165
+			if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) {
166
+				$ret .= '<td class="right">';
167
+			}
168
+			if ($htmlname && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) {
169
+				$ret .= '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&amp;'.$paramid.'='.$object->id.$moreparam.'">'.img_edit($langs->trans('Edit'), ($notabletag ? 0 : 1)).'</a>';
170
+			}
171
+			if (!empty($notabletag) && $notabletag == 1) {
172
+				$ret .= ' : ';
173
+			}
174
+			if (!empty($notabletag) && $notabletag == 3) {
175
+				$ret .= ' ';
176
+			}
177
+			if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) {
178
+				$ret .= '</td>';
179
+			}
180
+			if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) {
181
+				$ret .= '</tr></table>';
182
+			}
153 183
 		}
154 184
 
155 185
 		return $ret;
@@ -180,12 +210,16 @@  discard block
 block discarded – undo
180 210
 		$ret = '';
181 211
 
182 212
 		// Check parameters
183
-		if (empty($typeofdata)) return 'ErrorBadParameter';
213
+		if (empty($typeofdata)) {
214
+			return 'ErrorBadParameter';
215
+		}
184 216
 
185 217
 		// When option to edit inline is activated
186
-		if (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && !preg_match('/^select;|datehourpicker/', $typeofdata)) // TODO add jquery timepicker and support select
218
+		if (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && !preg_match('/^select;|datehourpicker/', $typeofdata)) {
219
+			// TODO add jquery timepicker and support select
187 220
 		{
188 221
 			$ret .= $this->editInPlace($object, $value, $htmlname, $perm, $typeofdata, $editvalue, $extObject, $custommsg);
222
+		}
189 223
 		} else {
190 224
 			if (GETPOST('action', 'aZ09') == 'edit'.$htmlname)
191 225
 			{
@@ -194,8 +228,12 @@  discard block
 block discarded – undo
194 228
 				$ret .= '<input type="hidden" name="action" value="set'.$htmlname.'">';
195 229
 				$ret .= '<input type="hidden" name="token" value="'.newToken().'">';
196 230
 				$ret .= '<input type="hidden" name="'.$paramid.'" value="'.$object->id.'">';
197
-				if (empty($notabletag)) $ret .= '<table class="nobordernopadding centpercent" cellpadding="0" cellspacing="0">';
198
-				if (empty($notabletag)) $ret .= '<tr><td>';
231
+				if (empty($notabletag)) {
232
+					$ret .= '<table class="nobordernopadding centpercent" cellpadding="0" cellspacing="0">';
233
+				}
234
+				if (empty($notabletag)) {
235
+					$ret .= '<tr><td>';
236
+				}
199 237
 				if (preg_match('/^(string|safehtmlstring|email)/', $typeofdata))
200 238
 				{
201 239
 					$tmp = explode(':', $typeofdata);
@@ -205,9 +243,11 @@  discard block
 block discarded – undo
205 243
 					$tmp = explode(':', $typeofdata);
206 244
 					$valuetoshow = price2num($editvalue ? $editvalue : $value);
207 245
 					$ret .= '<input type="text" id="'.$htmlname.'" name="'.$htmlname.'" value="'.($valuetoshow != '' ?price($valuetoshow) : '').'"'.($tmp[1] ? ' size="'.$tmp[1].'"' : '').'>';
208
-				} elseif (preg_match('/^text/', $typeofdata) || preg_match('/^note/', $typeofdata))	// if wysiwyg is enabled $typeofdata = 'ckeditor'
246
+				} elseif (preg_match('/^text/', $typeofdata) || preg_match('/^note/', $typeofdata)) {
247
+					// if wysiwyg is enabled $typeofdata = 'ckeditor'
209 248
 				{
210 249
 					$tmp = explode(':', $typeofdata);
250
+				}
211 251
 					$cols = $tmp[2];
212 252
 					$morealt = '';
213 253
 					if (preg_match('/%/', $cols))
@@ -247,25 +287,41 @@  discard block
 block discarded – undo
247 287
 					$doleditor = new DolEditor($htmlname, ($editvalue ? $editvalue : $value), ($tmp[2] ? $tmp[2] : ''), ($tmp[3] ? $tmp[3] : '100'), ($tmp[1] ? $tmp[1] : 'dolibarr_notes'), 'In', ($tmp[5] ? $tmp[5] : 0), (isset($tmp[8]) ? ($tmp[8] ?true:false) : true), true, ($tmp[6] ? $tmp[6] : '20'), ($tmp[7] ? $tmp[7] : '100'));
248 288
 					$ret .= $doleditor->Create(1);
249 289
 				}
250
-				if (empty($notabletag)) $ret .= '</td>';
290
+				if (empty($notabletag)) {
291
+					$ret .= '</td>';
292
+				}
251 293
 
252
-				if (empty($notabletag)) $ret .= '<td class="left">';
294
+				if (empty($notabletag)) {
295
+					$ret .= '<td class="left">';
296
+				}
253 297
 				//else $ret.='<div class="clearboth"></div>';
254 298
 				$ret .= '<input type="submit" class="button'.(empty($notabletag) ? '' : ' ').'" name="modify" value="'.$langs->trans("Modify").'">';
255
-				if (preg_match('/ckeditor|textarea/', $typeofdata) && empty($notabletag)) $ret .= '<br>'."\n";
299
+				if (preg_match('/ckeditor|textarea/', $typeofdata) && empty($notabletag)) {
300
+					$ret .= '<br>'."\n";
301
+				}
256 302
 				$ret .= '<input type="submit" class="button'.(empty($notabletag) ? '' : ' ').'" name="cancel" value="'.$langs->trans("Cancel").'">';
257
-				if (empty($notabletag)) $ret .= '</td>';
303
+				if (empty($notabletag)) {
304
+					$ret .= '</td>';
305
+				}
258 306
 
259
-				if (empty($notabletag)) $ret .= '</tr></table>'."\n";
307
+				if (empty($notabletag)) {
308
+					$ret .= '</tr></table>'."\n";
309
+				}
260 310
 				$ret .= '</form>'."\n";
261 311
 			} else {
262
-				if (preg_match('/^(email)/', $typeofdata))              $ret .= dol_print_email($value, 0, 0, 0, 0, 1);
263
-				elseif (preg_match('/^(amount|numeric)/', $typeofdata)) $ret .= ($value != '' ? price($value, '', $langs, 0, -1, -1, $conf->currency) : '');
264
-				elseif (preg_match('/^text/', $typeofdata) || preg_match('/^note/', $typeofdata))  $ret .= dol_htmlentitiesbr($value);
265
-				elseif (preg_match('/^safehtmlstring/', $typeofdata)) $ret .= dol_string_onlythesehtmltags($value);
266
-				elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') $ret .= dol_print_date($value, 'day');
267
-				elseif ($typeofdata == 'dayhour' || $typeofdata == 'datehourpicker') $ret .= dol_print_date($value, 'dayhour');
268
-				elseif (preg_match('/^select;/', $typeofdata))
312
+				if (preg_match('/^(email)/', $typeofdata)) {
313
+					$ret .= dol_print_email($value, 0, 0, 0, 0, 1);
314
+				} elseif (preg_match('/^(amount|numeric)/', $typeofdata)) {
315
+					$ret .= ($value != '' ? price($value, '', $langs, 0, -1, -1, $conf->currency) : '');
316
+				} elseif (preg_match('/^text/', $typeofdata) || preg_match('/^note/', $typeofdata)) {
317
+					$ret .= dol_htmlentitiesbr($value);
318
+				} elseif (preg_match('/^safehtmlstring/', $typeofdata)) {
319
+					$ret .= dol_string_onlythesehtmltags($value);
320
+				} elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') {
321
+					$ret .= dol_print_date($value, 'day');
322
+				} elseif ($typeofdata == 'dayhour' || $typeofdata == 'datehourpicker') {
323
+					$ret .= dol_print_date($value, 'dayhour');
324
+				} elseif (preg_match('/^select;/', $typeofdata))
269 325
 				{
270 326
 					$arraydata = explode(',', preg_replace('/^select;/', '', $typeofdata));
271 327
 					$arraylist = array();
@@ -319,7 +375,9 @@  discard block
 block discarded – undo
319 375
 
320 376
 		// List of extra languages
321 377
 		$arrayoflangcode = array();
322
-		if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE)) $arrayoflangcode[] = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
378
+		if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE)) {
379
+			$arrayoflangcode[] = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
380
+		}
323 381
 
324 382
 		if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
325 383
 			if (!is_object($extralanguages)) {
@@ -391,9 +449,13 @@  discard block
 block discarded – undo
391 449
 		$out = '';
392 450
 
393 451
 		// Check parameters
394
-		if (preg_match('/^text/', $inputType)) $value = dol_nl2br($value);
395
-		elseif (preg_match('/^numeric/', $inputType)) $value = price($value);
396
-		elseif ($inputType == 'day' || $inputType == 'datepicker') $value = dol_print_date($value, 'day');
452
+		if (preg_match('/^text/', $inputType)) {
453
+			$value = dol_nl2br($value);
454
+		} elseif (preg_match('/^numeric/', $inputType)) {
455
+			$value = price($value);
456
+		} elseif ($inputType == 'day' || $inputType == 'datepicker') {
457
+			$value = dol_print_date($value, 'day');
458
+		}
397 459
 
398 460
 		if ($condition)
399 461
 		{
@@ -422,23 +484,35 @@  discard block
 block discarded – undo
422 484
 			{
423 485
 				$tmp = explode(':', $inputType);
424 486
 				$inputType = $tmp[0];
425
-				if (!empty($tmp[1])) $inputOption = $tmp[1];
426
-				if (!empty($tmp[2])) $savemethod = $tmp[2];
487
+				if (!empty($tmp[1])) {
488
+					$inputOption = $tmp[1];
489
+				}
490
+				if (!empty($tmp[2])) {
491
+					$savemethod = $tmp[2];
492
+				}
427 493
 				$out .= '<input id="width_'.$htmlname.'" value="'.$inputOption.'" type="hidden"/>'."\n";
428 494
 			} elseif ((preg_match('/^day$/', $inputType)) || (preg_match('/^datepicker/', $inputType)) || (preg_match('/^datehourpicker/', $inputType)))
429 495
 			{
430 496
 				$tmp = explode(':', $inputType);
431 497
 				$inputType = $tmp[0];
432
-				if (!empty($tmp[1])) $inputOption = $tmp[1];
433
-				if (!empty($tmp[2])) $savemethod = $tmp[2];
498
+				if (!empty($tmp[1])) {
499
+					$inputOption = $tmp[1];
500
+				}
501
+				if (!empty($tmp[2])) {
502
+					$savemethod = $tmp[2];
503
+				}
434 504
 
435 505
 				$out .= '<input id="timestamp" type="hidden"/>'."\n"; // Use for timestamp format
436 506
 			} elseif (preg_match('/^(select|autocomplete)/', $inputType))
437 507
 			{
438 508
 				$tmp = explode(':', $inputType);
439 509
 				$inputType = $tmp[0]; $loadmethod = $tmp[1];
440
-				if (!empty($tmp[2])) $savemethod = $tmp[2];
441
-				if (!empty($tmp[3])) $button_only = true;
510
+				if (!empty($tmp[2])) {
511
+					$savemethod = $tmp[2];
512
+				}
513
+				if (!empty($tmp[3])) {
514
+					$button_only = true;
515
+				}
442 516
 			} elseif (preg_match('/^textarea/', $inputType))
443 517
 			{
444 518
 				$tmp = explode(':', $inputType);
@@ -449,9 +523,15 @@  discard block
 block discarded – undo
449 523
 			{
450 524
 				$tmp = explode(':', $inputType);
451 525
 				$inputType = $tmp[0]; $toolbar = $tmp[1];
452
-				if (!empty($tmp[2])) $width = $tmp[2];
453
-				if (!empty($tmp[3])) $heigth = $tmp[3];
454
-				if (!empty($tmp[4])) $savemethod = $tmp[4];
526
+				if (!empty($tmp[2])) {
527
+					$width = $tmp[2];
528
+				}
529
+				if (!empty($tmp[3])) {
530
+					$heigth = $tmp[3];
531
+				}
532
+				if (!empty($tmp[4])) {
533
+					$savemethod = $tmp[4];
534
+				}
455 535
 
456 536
 				if (!empty($conf->fckeditor->enabled))
457 537
 				{
@@ -465,17 +545,25 @@  discard block
 block discarded – undo
465 545
 			$out .= '<input id="table_element_'.$htmlname.'" value="'.$table_element.'" type="hidden"/>'."\n";
466 546
 			$out .= '<input id="fk_element_'.$htmlname.'" value="'.$fk_element.'" type="hidden"/>'."\n";
467 547
 			$out .= '<input id="loadmethod_'.$htmlname.'" value="'.$loadmethod.'" type="hidden"/>'."\n";
468
-			if (!empty($savemethod))	$out .= '<input id="savemethod_'.$htmlname.'" value="'.$savemethod.'" type="hidden"/>'."\n";
469
-			if (!empty($ext_element))	$out .= '<input id="ext_element_'.$htmlname.'" value="'.$ext_element.'" type="hidden"/>'."\n";
548
+			if (!empty($savemethod)) {
549
+				$out .= '<input id="savemethod_'.$htmlname.'" value="'.$savemethod.'" type="hidden"/>'."\n";
550
+			}
551
+			if (!empty($ext_element)) {
552
+				$out .= '<input id="ext_element_'.$htmlname.'" value="'.$ext_element.'" type="hidden"/>'."\n";
553
+			}
470 554
 			if (!empty($custommsg))
471 555
 			{
472 556
 				if (is_array($custommsg))
473 557
 				{
474
-					if (!empty($custommsg['success']))
475
-						$out .= '<input id="successmsg_'.$htmlname.'" value="'.$custommsg['success'].'" type="hidden"/>'."\n";
476
-						if (!empty($custommsg['error']))
477
-							$out .= '<input id="errormsg_'.$htmlname.'" value="'.$custommsg['error'].'" type="hidden"/>'."\n";
478
-				} else $out .= '<input id="successmsg_'.$htmlname.'" value="'.$custommsg.'" type="hidden"/>'."\n";
558
+					if (!empty($custommsg['success'])) {
559
+											$out .= '<input id="successmsg_'.$htmlname.'" value="'.$custommsg['success'].'" type="hidden"/>'."\n";
560
+					}
561
+						if (!empty($custommsg['error'])) {
562
+													$out .= '<input id="errormsg_'.$htmlname.'" value="'.$custommsg['error'].'" type="hidden"/>'."\n";
563
+						}
564
+				} else {
565
+					$out .= '<input id="successmsg_'.$htmlname.'" value="'.$custommsg.'" type="hidden"/>'."\n";
566
+				}
479 567
 			}
480 568
 			if ($inputType == 'textarea') {
481 569
 				$out .= '<input id="textarea_'.$htmlname.'_rows" value="'.$rows.'" type="hidden"/>'."\n";
@@ -511,12 +599,20 @@  discard block
 block discarded – undo
511 599
 	 */
512 600
 	public function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img = '', $extracss = '', $notabs = 3, $incbefore = '', $noencodehtmltext = 0, $tooltiptrigger = '', $forcenowrap = 0)
513 601
 	{
514
-		if ($incbefore) $text = $incbefore.$text;
515
-		if (!$htmltext) return $text;
602
+		if ($incbefore) {
603
+			$text = $incbefore.$text;
604
+		}
605
+		if (!$htmltext) {
606
+			return $text;
607
+		}
516 608
 
517 609
 		$tag = 'td';
518
-		if ($notabs == 2) $tag = 'div';
519
-		if ($notabs == 3) $tag = 'span';
610
+		if ($notabs == 2) {
611
+			$tag = 'div';
612
+		}
613
+		if ($notabs == 3) {
614
+			$tag = 'span';
615
+		}
520 616
 		// Sanitize tooltip
521 617
 		$htmltext = str_replace(array("\r", "\n"), '', $htmltext);
522 618
 
@@ -538,17 +634,36 @@  discard block
 block discarded – undo
538 634
 		if ($tooltipon == 2 || $tooltipon == 3)
539 635
 		{
540 636
 			$paramfortooltipimg = ' class="'.$classfortooltip.($notabs != 3 ? ' inline-block' : '').($extracss ? ' '.$extracss : '').'" style="padding: 0px;'.($extrastyle ? ' '.$extrastyle : '').'"';
541
-			if ($tooltiptrigger == '') $paramfortooltipimg .= ' title="'.($noencodehtmltext ? $htmltext : dol_escape_htmltag($htmltext, 1)).'"'; // Attribut to put on img tag to store tooltip
542
-			else $paramfortooltipimg .= ' dolid="'.$tooltiptrigger.'"';
543
-		} else $paramfortooltipimg = ($extracss ? ' class="'.$extracss.'"' : '').($extrastyle ? ' style="'.$extrastyle.'"' : ''); // Attribut to put on td text tag
637
+			if ($tooltiptrigger == '') {
638
+				$paramfortooltipimg .= ' title="'.($noencodehtmltext ? $htmltext : dol_escape_htmltag($htmltext, 1)).'"';
639
+			}
640
+			// Attribut to put on img tag to store tooltip
641
+			else {
642
+				$paramfortooltipimg .= ' dolid="'.$tooltiptrigger.'"';
643
+			}
644
+		} else {
645
+			$paramfortooltipimg = ($extracss ? ' class="'.$extracss.'"' : '').($extrastyle ? ' style="'.$extrastyle.'"' : '');
646
+		}
647
+		// Attribut to put on td text tag
544 648
 		if ($tooltipon == 1 || $tooltipon == 3)
545 649
 		{
546 650
 			$paramfortooltiptd = ' class="'.($tooltipon == 3 ? 'cursorpointer ' : '').$classfortooltip.' inline-block'.($extracss ? ' '.$extracss : '').'" style="padding: 0px;'.($extrastyle ? ' '.$extrastyle : '').'" ';
547
-			if ($tooltiptrigger == '') $paramfortooltiptd .= ' title="'.($noencodehtmltext ? $htmltext : dol_escape_htmltag($htmltext, 1)).'"'; // Attribut to put on td tag to store tooltip
548
-			else $paramfortooltiptd .= ' dolid="'.$tooltiptrigger.'"';
549
-		} else $paramfortooltiptd = ($extracss ? ' class="'.$extracss.'"' : '').($extrastyle ? ' style="'.$extrastyle.'"' : ''); // Attribut to put on td text tag
550
-		if (empty($notabs)) $s .= '<table class="nobordernopadding"><tr style="height: auto;">';
551
-		elseif ($notabs == 2) $s .= '<div class="inline-block'.($forcenowrap ? ' nowrap' : '').'">';
651
+			if ($tooltiptrigger == '') {
652
+				$paramfortooltiptd .= ' title="'.($noencodehtmltext ? $htmltext : dol_escape_htmltag($htmltext, 1)).'"';
653
+			}
654
+			// Attribut to put on td tag to store tooltip
655
+			else {
656
+				$paramfortooltiptd .= ' dolid="'.$tooltiptrigger.'"';
657
+			}
658
+		} else {
659
+			$paramfortooltiptd = ($extracss ? ' class="'.$extracss.'"' : '').($extrastyle ? ' style="'.$extrastyle.'"' : '');
660
+		}
661
+		// Attribut to put on td text tag
662
+		if (empty($notabs)) {
663
+			$s .= '<table class="nobordernopadding"><tr style="height: auto;">';
664
+		} elseif ($notabs == 2) {
665
+			$s .= '<div class="inline-block'.($forcenowrap ? ' nowrap' : '').'">';
666
+		}
552 667
 		// Define value if value is before
553 668
 		if ($direction < 0) {
554 669
 			$s .= '<'.$tag.$paramfortooltipimg;
@@ -559,15 +674,22 @@  discard block
 block discarded – undo
559 674
 		}
560 675
 		// Use another method to help avoid having a space in value in order to use this value with jquery
561 676
 		// Define label
562
-		if ((string) $text != '') $s .= '<'.$tag.$paramfortooltiptd.'>'.$text.'</'.$tag.'>';
677
+		if ((string) $text != '') {
678
+			$s .= '<'.$tag.$paramfortooltiptd.'>'.$text.'</'.$tag.'>';
679
+		}
563 680
 		// Define value if value is after
564 681
 		if ($direction > 0) {
565 682
 			$s .= '<'.$tag.$paramfortooltipimg;
566
-			if ($tag == 'td') $s .= ' class="valignmiddle" width="14"';
683
+			if ($tag == 'td') {
684
+				$s .= ' class="valignmiddle" width="14"';
685
+			}
567 686
 			$s .= '>'.$textfordialog.$img.'</'.$tag.'>';
568 687
 		}
569
-		if (empty($notabs)) $s .= '</tr></table>';
570
-		elseif ($notabs == 2) $s .= '</div>';
688
+		if (empty($notabs)) {
689
+			$s .= '</tr></table>';
690
+		} elseif ($notabs == 2) {
691
+			$s .= '</div>';
692
+		}
571 693
 
572 694
 		return $s;
573 695
 	}
@@ -591,17 +713,23 @@  discard block
 block discarded – undo
591 713
 		global $conf, $langs;
592 714
 
593 715
 		$alt = '';
594
-		if ($tooltiptrigger) $alt = $langs->transnoentitiesnoconv("ClickToShowHelp");
716
+		if ($tooltiptrigger) {
717
+			$alt = $langs->transnoentitiesnoconv("ClickToShowHelp");
718
+		}
595 719
 
596 720
 		//For backwards compatibility
597
-		if ($type == '0') $type = 'info';
598
-		elseif ($type == '1') $type = 'help';
721
+		if ($type == '0') {
722
+			$type = 'info';
723
+		} elseif ($type == '1') {
724
+			$type = 'help';
725
+		}
599 726
 
600 727
 		// If info or help with no javascript, show only text
601 728
 		if (empty($conf->use_javascript_ajax))
602 729
 		{
603
-			if ($type == 'info' || $type == 'infoclickable' || $type == 'help' || $type == 'helpclickable')	return $text;
604
-			else {
730
+			if ($type == 'info' || $type == 'infoclickable' || $type == 'help' || $type == 'helpclickable') {
731
+				return $text;
732
+			} else {
605 733
 				$alt = $htmltext;
606 734
 				$htmltext = '';
607 735
 			}
@@ -610,7 +738,9 @@  discard block
 block discarded – undo
610 738
 		// If info or help with smartphone, show only text (tooltip hover can't works)
611 739
 		if (!empty($conf->dol_no_mouse_hover) && empty($tooltiptrigger))
612 740
 		{
613
-			if ($type == 'info' || $type == 'infoclickable' || $type == 'help' || $type == 'helpclickable') return $text;
741
+			if ($type == 'info' || $type == 'infoclickable' || $type == 'help' || $type == 'helpclickable') {
742
+				return $text;
743
+			}
614 744
 		}
615 745
 		// If info or help with smartphone, show only text (tooltip on click does not works with dialog on smaprtphone)
616 746
 		//if (! empty($conf->dol_no_mouse_hover) && ! empty($tooltiptrigger))
@@ -619,13 +749,22 @@  discard block
 block discarded – undo
619 749
 		//}
620 750
 
621 751
 		$img = '';
622
-		if ($type == 'info') $img = img_help(0, $alt);
623
-		elseif ($type == 'help') $img = img_help(($tooltiptrigger != '' ? 2 : 1), $alt);
624
-		elseif ($type == 'helpclickable') $img = img_help(($tooltiptrigger != '' ? 2 : 1), $alt);
625
-		elseif ($type == 'superadmin') $img = img_picto($alt, 'redstar');
626
-		elseif ($type == 'admin') $img = img_picto($alt, 'star');
627
-		elseif ($type == 'warning') $img = img_warning($alt);
628
-		elseif ($type != 'none') $img = img_picto($alt, $type); // $type can be an image path
752
+		if ($type == 'info') {
753
+			$img = img_help(0, $alt);
754
+		} elseif ($type == 'help') {
755
+			$img = img_help(($tooltiptrigger != '' ? 2 : 1), $alt);
756
+		} elseif ($type == 'helpclickable') {
757
+			$img = img_help(($tooltiptrigger != '' ? 2 : 1), $alt);
758
+		} elseif ($type == 'superadmin') {
759
+			$img = img_picto($alt, 'redstar');
760
+		} elseif ($type == 'admin') {
761
+			$img = img_picto($alt, 'star');
762
+		} elseif ($type == 'warning') {
763
+			$img = img_warning($alt);
764
+		} elseif ($type != 'none') {
765
+			$img = img_picto($alt, $type);
766
+		}
767
+		// $type can be an image path
629 768
 
630 769
 		return $this->textwithtooltip($text, $htmltext, ((($tooltiptrigger && !$img) || strpos($type, 'clickable')) ? 3 : 2), $direction, $img, $extracss, $notabs, '', $noencodehtmltext, $tooltiptrigger, $forcenowrap);
631 770
 	}
@@ -653,7 +792,9 @@  discard block
 block discarded – undo
653 792
 		$parameters = array();
654 793
 		$reshook = $hookmanager->executeHooks('addMoreMassActions', $parameters); // Note that $action and $object may have been modified by hook
655 794
 		// check if there is a mass action
656
-		if (count($arrayofaction) == 0 && empty($hookmanager->resPrint)) return;
795
+		if (count($arrayofaction) == 0 && empty($hookmanager->resPrint)) {
796
+			return;
797
+		}
657 798
 		if (empty($reshook))
658 799
 		{
659 800
 			$ret .= '<option value="0"'.($disabled ? ' disabled="disabled"' : '').'>-- '.$langs->trans("SelectAction").' --</option>';
@@ -666,7 +807,9 @@  discard block
 block discarded – undo
666 807
 
667 808
 		$ret .= '</select>';
668 809
 
669
-                if (empty($conf->dol_optimize_smallscreen)) $ret .= ajax_combobox('.' . $name . 'select');
810
+                if (empty($conf->dol_optimize_smallscreen)) {
811
+                	$ret .= ajax_combobox('.' . $name . 'select');
812
+                }
670 813
 
671 814
 		// Warning: if you set submit button to disabled, post using 'Enter' will no more work if there is no another input submit. So we add a hidden button
672 815
 		$ret .= '<input type="submit" name="confirmmassactioninvisible" style="display: none" tabindex="-1">'; // Hidden button BEFORE so it is the one used when we submit with ENTER.
@@ -794,20 +937,27 @@  discard block
 block discarded – undo
794 937
 					$i++;
795 938
 				}
796 939
 
797
-				if (empty($disablefavorites)) array_multisort($favorite, SORT_DESC, $label, SORT_ASC, $countryArray);
798
-				else $countryArray = dol_sort_array($countryArray, 'label');
940
+				if (empty($disablefavorites)) {
941
+					array_multisort($favorite, SORT_DESC, $label, SORT_ASC, $countryArray);
942
+				} else {
943
+					$countryArray = dol_sort_array($countryArray, 'label');
944
+				}
799 945
 
800 946
 				if ($showempty)
801 947
 				{
802 948
 					$out .= '<option value="">&nbsp;</option>'."\n";
803 949
 				}
804 950
 
805
-				if ($addspecialentries)	// Add dedicated entries for groups of countries
951
+				if ($addspecialentries) {
952
+					// Add dedicated entries for groups of countries
806 953
 				{
807 954
 					//if ($showempty) $out.= '<option value="" disabled class="selectoptiondisabledwhite">--------------</option>';
808 955
 					$out .= '<option value="special_allnotme"'.($selected == 'special_allnotme' ? ' selected' : '').'>'.$langs->trans("CountriesExceptMe", $langs->transnoentitiesnoconv("Country".$mysoc->country_code)).'</option>';
956
+				}
809 957
 					$out .= '<option value="special_eec"'.($selected == 'special_eec' ? ' selected' : '').'>'.$langs->trans("CountriesInEEC").'</option>';
810
-					if ($mysoc->isInEEC()) $out .= '<option value="special_eecnotme"'.($selected == 'special_eecnotme' ? ' selected' : '').'>'.$langs->trans("CountriesInEECExceptMe", $langs->transnoentitiesnoconv("Country".$mysoc->country_code)).'</option>';
958
+					if ($mysoc->isInEEC()) {
959
+						$out .= '<option value="special_eecnotme"'.($selected == 'special_eecnotme' ? ' selected' : '').'>'.$langs->trans("CountriesInEECExceptMe", $langs->transnoentitiesnoconv("Country".$mysoc->country_code)).'</option>';
960
+					}
811 961
 					$out .= '<option value="special_noteec"'.($selected == 'special_noteec' ? ' selected' : '').'>'.$langs->trans("CountriesNotInEEC").'</option>';
812 962
 					$out .= '<option value="" disabled class="selectoptiondisabledwhite">--------------</option>';
813 963
 				}
@@ -815,10 +965,17 @@  discard block
 block discarded – undo
815 965
 				foreach ($countryArray as $row)
816 966
 				{
817 967
 					//if (empty($showempty) && empty($row['rowid'])) continue;
818
-					if (empty($row['rowid'])) continue;
819
-					if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row['code_iso'], $exclude_country_code)) continue; // exclude some countries
968
+					if (empty($row['rowid'])) {
969
+						continue;
970
+					}
971
+					if (is_array($exclude_country_code) && count($exclude_country_code) && in_array($row['code_iso'], $exclude_country_code)) {
972
+						continue;
973
+					}
974
+					// exclude some countries
820 975
 
821
-					if (empty($disablefavorites) && $row['favorite'] && $row['code_iso']) $atleastonefavorite++;
976
+					if (empty($disablefavorites) && $row['favorite'] && $row['code_iso']) {
977
+						$atleastonefavorite++;
978
+					}
822 979
 					if (empty($row['favorite']) && $atleastonefavorite)
823 980
 					{
824 981
 						$atleastonefavorite = 0;
@@ -831,9 +988,14 @@  discard block
 block discarded – undo
831 988
 					} else {
832 989
 						$out .= '<option value="'.($usecodeaskey ? ($usecodeaskey == 'code2' ? $row['code_iso'] : $row['code_iso3']) : $row['rowid']).'">';
833 990
 					}
834
-					if ($row['label']) $out .= dol_trunc($row['label'], $maxlength, 'middle');
835
-					else $out .= '&nbsp;';
836
-					if ($row['code_iso']) $out .= ' ('.$row['code_iso'].')';
991
+					if ($row['label']) {
992
+						$out .= dol_trunc($row['label'], $maxlength, 'middle');
993
+					} else {
994
+						$out .= '&nbsp;';
995
+					}
996
+					if ($row['code_iso']) {
997
+						$out .= ' ('.$row['code_iso'].')';
998
+					}
837 999
 					$out .= '</option>';
838 1000
 				}
839 1001
 			}
@@ -919,7 +1081,9 @@  discard block
 block discarded – undo
919 1081
 						$out .= '<option value="'.$row['rowid'].'">';
920 1082
 					}
921 1083
 
922
-					if ($row['code']) $out .= $row['code'];
1084
+					if ($row['code']) {
1085
+						$out .= $row['code'];
1086
+					}
923 1087
 
924 1088
 					$out .= '</option>';
925 1089
 				}
@@ -960,21 +1124,29 @@  discard block
 block discarded – undo
960 1124
 		if ($forceall == 1 || (empty($forceall) && !empty($conf->product->enabled) && !empty($conf->service->enabled))
961 1125
 			|| (empty($forceall) && empty($conf->product->enabled) && empty($conf->service->enabled)))
962 1126
 		{
963
-			if (empty($hidetext)) print $langs->trans("Type").': ';
1127
+			if (empty($hidetext)) {
1128
+				print $langs->trans("Type").': ';
1129
+			}
964 1130
 			print '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">';
965 1131
 			if ($showempty)
966 1132
 			{
967 1133
 				print '<option value="-1"';
968
-				if ($selected == -1) print ' selected';
1134
+				if ($selected == -1) {
1135
+					print ' selected';
1136
+				}
969 1137
 				print '>&nbsp;</option>';
970 1138
 			}
971 1139
 
972 1140
 			print '<option value="0"';
973
-			if (0 == $selected) print ' selected';
1141
+			if (0 == $selected) {
1142
+				print ' selected';
1143
+			}
974 1144
 			print '>'.$langs->trans("Product");
975 1145
 
976 1146
 			print '<option value="1"';
977
-			if (1 == $selected) print ' selected';
1147
+			if (1 == $selected) {
1148
+				print ' selected';
1149
+			}
978 1150
 			print '>'.$langs->trans("Service");
979 1151
 
980 1152
 			print '</select>';
@@ -990,9 +1162,12 @@  discard block
 block discarded – undo
990 1162
 			print $langs->trans("Product");
991 1163
 			print '<input type="hidden" name="'.$htmlname.'" value="0">';
992 1164
 		}
993
-		if ($forceall < 0)	// This should happened only for contracts when both predefined product and service are disabled.
1165
+		if ($forceall < 0) {
1166
+			// This should happened only for contracts when both predefined product and service are disabled.
994 1167
 		{
995
-			print '<input type="hidden" name="'.$htmlname.'" value="1">'; // By default we set on service for contract. If CONTRACT_SUPPORT_PRODUCTS is set, forceall should be 1 not -1
1168
+			print '<input type="hidden" name="'.$htmlname.'" value="1">';
1169
+		}
1170
+		// By default we set on service for contract. If CONTRACT_SUPPORT_PRODUCTS is set, forceall should be 1 not -1
996 1171
 		}
997 1172
 	}
998 1173
 
@@ -1008,7 +1183,10 @@  discard block
 block discarded – undo
1008 1183
 		global $langs;
1009 1184
 
1010 1185
 		$num = count($this->cache_types_fees);
1011
-		if ($num > 0) return 0; // Cache already loaded
1186
+		if ($num > 0) {
1187
+			return 0;
1188
+		}
1189
+		// Cache already loaded
1012 1190
 
1013 1191
 		dol_syslog(__METHOD__, LOG_DEBUG);
1014 1192
 
@@ -1065,21 +1243,27 @@  discard block
 block discarded – undo
1065 1243
 		if ($showempty)
1066 1244
 		{
1067 1245
 			print '<option value="-1"';
1068
-			if ($selected == -1) print ' selected';
1246
+			if ($selected == -1) {
1247
+				print ' selected';
1248
+			}
1069 1249
 			print '>&nbsp;</option>';
1070 1250
 		}
1071 1251
 
1072 1252
 		foreach ($this->cache_types_fees as $key => $value)
1073 1253
 		{
1074 1254
 			print '<option value="'.$key.'"';
1075
-			if ($key == $selected) print ' selected';
1255
+			if ($key == $selected) {
1256
+				print ' selected';
1257
+			}
1076 1258
 			print '>';
1077 1259
 			print $value;
1078 1260
 			print '</option>';
1079 1261
 		}
1080 1262
 
1081 1263
 		print '</select>';
1082
-		if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1264
+		if ($user->admin) {
1265
+			print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1266
+		}
1083 1267
 	}
1084 1268
 
1085 1269
 
@@ -1145,8 +1329,9 @@  discard block
 block discarded – undo
1145 1329
 			$urloption = 'htmlname='.urlencode($htmlname).'&outjson=1&filter='.urlencode($filter).($showtype ? '&showtype='.urlencode($showtype) : '');
1146 1330
 			$out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
1147 1331
 			$out .= '<style type="text/css">.ui-autocomplete { z-index: 250; }</style>';
1148
-			if (empty($hidelabel)) print $langs->trans("RefOrLabel").' : ';
1149
-			elseif ($hidelabel > 1) {
1332
+			if (empty($hidelabel)) {
1333
+				print $langs->trans("RefOrLabel").' : ';
1334
+			} elseif ($hidelabel > 1) {
1150 1335
 				$placeholder = ' placeholder="'.$langs->trans("RefOrLabel").'"';
1151 1336
 				if ($hidelabel == 2) {
1152 1337
 					$out .= img_picto($langs->trans("Search"), 'search');
@@ -1193,8 +1378,11 @@  discard block
 block discarded – undo
1193 1378
 		$num = 0;
1194 1379
 		$outarray = array();
1195 1380
 
1196
-		if ($selected === '') $selected = array();
1197
-		elseif (!is_array($selected)) $selected = array($selected);
1381
+		if ($selected === '') {
1382
+			$selected = array();
1383
+		} elseif (!is_array($selected)) {
1384
+			$selected = array($selected);
1385
+		}
1198 1386
 
1199 1387
 		// Clean $filter that may contains sql conditions so sql code
1200 1388
 		if (function_exists('testSqlAndScriptInject')) {
@@ -1212,15 +1400,25 @@  discard block
 block discarded – undo
1212 1400
 		}
1213 1401
 
1214 1402
 		$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
1215
-		if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1403
+		if (!$user->rights->societe->client->voir && !$user->socid) {
1404
+			$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1405
+		}
1216 1406
 		if ($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST) {
1217 1407
 			$sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."c_country as dictp ON dictp.rowid=s.fk_pays";
1218 1408
 		}
1219 1409
 		$sql .= " WHERE s.entity IN (".getEntity('societe').")";
1220
-		if (!empty($user->socid)) $sql .= " AND s.rowid = ".$user->socid;
1221
-		if ($filter) $sql .= " AND (".$filter.")";
1222
-		if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
1223
-		if (!empty($conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) $sql .= " AND s.status <> 0";
1410
+		if (!empty($user->socid)) {
1411
+			$sql .= " AND s.rowid = ".$user->socid;
1412
+		}
1413
+		if ($filter) {
1414
+			$sql .= " AND (".$filter.")";
1415
+		}
1416
+		if (!$user->rights->societe->client->voir && !$user->socid) {
1417
+			$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
1418
+		}
1419
+		if (!empty($conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) {
1420
+			$sql .= " AND s.status <> 0";
1421
+		}
1224 1422
 		// Add criteria
1225 1423
 		if ($filterkey && $filterkey != '')
1226 1424
 		{
@@ -1229,13 +1427,19 @@  discard block
 block discarded – undo
1229 1427
 			// For natural search
1230 1428
 			$scrit = explode(' ', $filterkey);
1231 1429
 			$i = 0;
1232
-			if (count($scrit) > 1) $sql .= "(";
1430
+			if (count($scrit) > 1) {
1431
+				$sql .= "(";
1432
+			}
1233 1433
 			foreach ($scrit as $crit) {
1234
-				if ($i > 0) $sql .= " AND ";
1434
+				if ($i > 0) {
1435
+					$sql .= " AND ";
1436
+				}
1235 1437
 				$sql .= "(s.nom LIKE '".$this->db->escape($prefix.$crit)."%')";
1236 1438
 				$i++;
1237 1439
 			}
1238
-			if (count($scrit) > 1) $sql .= ")";
1440
+			if (count($scrit) > 1) {
1441
+				$sql .= ")";
1442
+			}
1239 1443
 			if (!empty($conf->barcode->enabled))
1240 1444
 			{
1241 1445
 				$sql .= " OR s.barcode LIKE '".$this->db->escape($prefix.$filterkey)."%'";
@@ -1265,10 +1469,15 @@  discard block
 block discarded – undo
1265 1469
 			{
1266 1470
 				// Do not use textifempty = ' ' or '&nbsp;' here, or search on key will search on ' key'.
1267 1471
 				//if (! empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
1268
-				if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty);
1269
-				else $textifempty .= $langs->trans("All");
1472
+				if ($showempty && !is_numeric($showempty)) {
1473
+					$textifempty = $langs->trans($showempty);
1474
+				} else {
1475
+					$textifempty .= $langs->trans("All");
1476
+				}
1477
+			}
1478
+			if ($showempty) {
1479
+				$out .= '<option value="-1">'.$textifempty.'</option>'."\n";
1270 1480
 			}
1271
-			if ($showempty) $out .= '<option value="-1">'.$textifempty.'</option>'."\n";
1272 1481
 
1273 1482
 			$num = $this->db->num_rows($resql);
1274 1483
 			$i = 0;
@@ -1296,11 +1505,21 @@  discard block
 block discarded – undo
1296 1505
 
1297 1506
 					if ($showtype)
1298 1507
 					{
1299
-						if ($obj->client || $obj->fournisseur) $label .= ' (';
1300
-						if ($obj->client == 1 || $obj->client == 3) $label .= $langs->trans("Customer");
1301
-						if ($obj->client == 2 || $obj->client == 3) $label .= ($obj->client == 3 ? ', ' : '').$langs->trans("Prospect");
1302
-						if ($obj->fournisseur) $label .= ($obj->client ? ', ' : '').$langs->trans("Supplier");
1303
-						if ($obj->client || $obj->fournisseur) $label .= ')';
1508
+						if ($obj->client || $obj->fournisseur) {
1509
+							$label .= ' (';
1510
+						}
1511
+						if ($obj->client == 1 || $obj->client == 3) {
1512
+							$label .= $langs->trans("Customer");
1513
+						}
1514
+						if ($obj->client == 2 || $obj->client == 3) {
1515
+							$label .= ($obj->client == 3 ? ', ' : '').$langs->trans("Prospect");
1516
+						}
1517
+						if ($obj->fournisseur) {
1518
+							$label .= ($obj->client ? ', ' : '').$langs->trans("Supplier");
1519
+						}
1520
+						if ($obj->client || $obj->fournisseur) {
1521
+							$label .= ')';
1522
+						}
1304 1523
 					}
1305 1524
 
1306 1525
 					if ($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST) {
@@ -1323,7 +1542,9 @@  discard block
 block discarded – undo
1323 1542
 					}
1324 1543
 
1325 1544
 					$i++;
1326
-					if (($i % 10) == 0) $out .= "\n";
1545
+					if (($i % 10) == 0) {
1546
+						$out .= "\n";
1547
+					}
1327 1548
 				}
1328 1549
 			}
1329 1550
 			$out .= '</select>'."\n";
@@ -1333,7 +1554,9 @@  discard block
 block discarded – undo
1333 1554
 
1334 1555
 		$this->result = array('nbofthirdparties'=>$num);
1335 1556
 
1336
-		if ($outputmode) return $outarray;
1557
+		if ($outputmode) {
1558
+			return $outarray;
1559
+		}
1337 1560
 		return $out;
1338 1561
 	}
1339 1562
 
@@ -1360,7 +1583,9 @@  discard block
 block discarded – undo
1360 1583
 		$sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re";
1361 1584
 		$sql .= " WHERE re.fk_soc = ".(int) $socid;
1362 1585
 		$sql .= " AND re.entity = ".$conf->entity;
1363
-		if ($filter) $sql .= " AND ".$filter;
1586
+		if ($filter) {
1587
+			$sql .= " AND ".$filter;
1588
+		}
1364 1589
 		$sql .= " ORDER BY re.description ASC";
1365 1590
 
1366 1591
 		dol_syslog(get_class($this)."::select_remises", LOG_DEBUG);
@@ -1380,13 +1605,23 @@  discard block
 block discarded – undo
1380 1605
 				{
1381 1606
 					$obj = $this->db->fetch_object($resql);
1382 1607
 					$desc = dol_trunc($obj->description, 40);
1383
-					if (preg_match('/\(CREDIT_NOTE\)/', $desc)) $desc = preg_replace('/\(CREDIT_NOTE\)/', $langs->trans("CreditNote"), $desc);
1384
-					if (preg_match('/\(DEPOSIT\)/', $desc)) $desc = preg_replace('/\(DEPOSIT\)/', $langs->trans("Deposit"), $desc);
1385
-					if (preg_match('/\(EXCESS RECEIVED\)/', $desc)) $desc = preg_replace('/\(EXCESS RECEIVED\)/', $langs->trans("ExcessReceived"), $desc);
1386
-					if (preg_match('/\(EXCESS PAID\)/', $desc)) $desc = preg_replace('/\(EXCESS PAID\)/', $langs->trans("ExcessPaid"), $desc);
1608
+					if (preg_match('/\(CREDIT_NOTE\)/', $desc)) {
1609
+						$desc = preg_replace('/\(CREDIT_NOTE\)/', $langs->trans("CreditNote"), $desc);
1610
+					}
1611
+					if (preg_match('/\(DEPOSIT\)/', $desc)) {
1612
+						$desc = preg_replace('/\(DEPOSIT\)/', $langs->trans("Deposit"), $desc);
1613
+					}
1614
+					if (preg_match('/\(EXCESS RECEIVED\)/', $desc)) {
1615
+						$desc = preg_replace('/\(EXCESS RECEIVED\)/', $langs->trans("ExcessReceived"), $desc);
1616
+					}
1617
+					if (preg_match('/\(EXCESS PAID\)/', $desc)) {
1618
+						$desc = preg_replace('/\(EXCESS PAID\)/', $langs->trans("ExcessPaid"), $desc);
1619
+					}
1387 1620
 
1388 1621
 					$selectstring = '';
1389
-					if ($selected > 0 && $selected == $obj->rowid) $selectstring = ' selected';
1622
+					if ($selected > 0 && $selected == $obj->rowid) {
1623
+						$selectstring = ' selected';
1624
+					}
1390 1625
 
1391 1626
 					$disabled = '';
1392 1627
 					if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue)
@@ -1398,7 +1633,9 @@  discard block
 block discarded – undo
1398 1633
 					if (!empty($conf->global->MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST) && !empty($obj->fk_facture_source))
1399 1634
 					{
1400 1635
 						$tmpfac = new Facture($this->db);
1401
-						if ($tmpfac->fetch($obj->fk_facture_source) > 0) $desc = $desc.' - '.$tmpfac->ref;
1636
+						if ($tmpfac->fetch($obj->fk_facture_source) > 0) {
1637
+							$desc = $desc.' - '.$tmpfac->ref;
1638
+						}
1402 1639
 					}
1403 1640
 
1404 1641
 					print '<option value="'.$obj->rowid.'"'.$selectstring.$disabled.'>'.$desc.' ('.price($obj->amount_ht).' '.$langs->trans("HT").' - '.price($obj->amount_ttc).' '.$langs->trans("TTC").')</option>';
@@ -1470,10 +1707,15 @@  discard block
 block discarded – undo
1470 1707
 
1471 1708
 		$langs->load('companies');
1472 1709
 
1473
-		if (empty($htmlid)) $htmlid = $htmlname;
1710
+		if (empty($htmlid)) {
1711
+			$htmlid = $htmlname;
1712
+		}
1474 1713
 
1475
-		if ($selected === '') $selected = array();
1476
-		elseif (!is_array($selected)) $selected = array($selected);
1714
+		if ($selected === '') {
1715
+			$selected = array();
1716
+		} elseif (!is_array($selected)) {
1717
+			$selected = array($selected);
1718
+		}
1477 1719
 		$out = '';
1478 1720
 
1479 1721
 		if (!is_object($hookmanager))
@@ -1484,12 +1726,20 @@  discard block
 block discarded – undo
1484 1726
 
1485 1727
 		// We search third parties
1486 1728
 		$sql = "SELECT sp.rowid, sp.lastname, sp.statut, sp.firstname, sp.poste";
1487
-		if ($showsoc > 0) $sql .= " , s.nom as company";
1729
+		if ($showsoc > 0) {
1730
+			$sql .= " , s.nom as company";
1731
+		}
1488 1732
 		$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
1489
-		if ($showsoc > 0) $sql .= " LEFT OUTER JOIN  ".MAIN_DB_PREFIX."societe as s ON s.rowid=sp.fk_soc";
1733
+		if ($showsoc > 0) {
1734
+			$sql .= " LEFT OUTER JOIN  ".MAIN_DB_PREFIX."societe as s ON s.rowid=sp.fk_soc";
1735
+		}
1490 1736
 		$sql .= " WHERE sp.entity IN (".getEntity('socpeople').")";
1491
-		if ($socid > 0 || $socid == -1) $sql .= " AND sp.fk_soc=".$socid;
1492
-		if (!empty($conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) $sql .= " AND sp.statut <> 0";
1737
+		if ($socid > 0 || $socid == -1) {
1738
+			$sql .= " AND sp.fk_soc=".$socid;
1739
+		}
1740
+		if (!empty($conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) {
1741
+			$sql .= " AND sp.statut <> 0";
1742
+		}
1493 1743
 		$sql .= " ORDER BY sp.lastname ASC";
1494 1744
 
1495 1745
 		dol_syslog(get_class($this)."::select_contacts", LOG_DEBUG);
@@ -1504,9 +1754,15 @@  discard block
 block discarded – undo
1504 1754
 				$out .= ajax_combobox($htmlid, $events, $conf->global->CONTACT_USE_SEARCH_TO_SELECT);
1505 1755
 			}
1506 1756
 
1507
-			if ($htmlname != 'none' && !$options_only) $out .= '<select class="flat'.($moreclass ? ' '.$moreclass : '').'" id="'.$htmlid.'" name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').' '.(!empty($moreparam) ? $moreparam : '').'>';
1508
-			if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) $out .= '<option value="0"'.(in_array(0, $selected) ? ' selected' : '').'>&nbsp;</option>';
1509
-			if ($showempty == 2) $out .= '<option value="0"'.(in_array(0, $selected) ? ' selected' : '').'>-- '.$langs->trans("Internal").' --</option>';
1757
+			if ($htmlname != 'none' && !$options_only) {
1758
+				$out .= '<select class="flat'.($moreclass ? ' '.$moreclass : '').'" id="'.$htmlid.'" name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').' '.(!empty($moreparam) ? $moreparam : '').'>';
1759
+			}
1760
+			if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) {
1761
+				$out .= '<option value="0"'.(in_array(0, $selected) ? ' selected' : '').'>&nbsp;</option>';
1762
+			}
1763
+			if ($showempty == 2) {
1764
+				$out .= '<option value="0"'.(in_array(0, $selected) ? ' selected' : '').'>-- '.$langs->trans("Internal").' --</option>';
1765
+			}
1510 1766
 
1511 1767
 			$num = $this->db->num_rows($resql);
1512 1768
 			$i = 0;
@@ -1526,32 +1782,52 @@  discard block
 block discarded – undo
1526 1782
 						if ($htmlname != 'none')
1527 1783
 						{
1528 1784
 							$disabled = 0;
1529
-							if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) $disabled = 1;
1530
-							if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) $disabled = 1;
1785
+							if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) {
1786
+								$disabled = 1;
1787
+							}
1788
+							if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
1789
+								$disabled = 1;
1790
+							}
1531 1791
 							if (!empty($selected) && in_array($obj->rowid, $selected))
1532 1792
 							{
1533 1793
 								$out .= '<option value="'.$obj->rowid.'"';
1534
-								if ($disabled) $out .= ' disabled';
1794
+								if ($disabled) {
1795
+									$out .= ' disabled';
1796
+								}
1535 1797
 								$out .= ' selected>';
1536 1798
 								$out .= $contactstatic->getFullName($langs);
1537
-								if ($showfunction && $obj->poste) $out .= ' ('.$obj->poste.')';
1538
-								if (($showsoc > 0) && $obj->company) $out .= ' - ('.$obj->company.')';
1799
+								if ($showfunction && $obj->poste) {
1800
+									$out .= ' ('.$obj->poste.')';
1801
+								}
1802
+								if (($showsoc > 0) && $obj->company) {
1803
+									$out .= ' - ('.$obj->company.')';
1804
+								}
1539 1805
 								$out .= '</option>';
1540 1806
 							} else {
1541 1807
 								$out .= '<option value="'.$obj->rowid.'"';
1542
-								if ($disabled) $out .= ' disabled';
1808
+								if ($disabled) {
1809
+									$out .= ' disabled';
1810
+								}
1543 1811
 								$out .= '>';
1544 1812
 								$out .= $contactstatic->getFullName($langs);
1545
-								if ($showfunction && $obj->poste) $out .= ' ('.$obj->poste.')';
1546
-								if (($showsoc > 0) && $obj->company) $out .= ' - ('.$obj->company.')';
1813
+								if ($showfunction && $obj->poste) {
1814
+									$out .= ' ('.$obj->poste.')';
1815
+								}
1816
+								if (($showsoc > 0) && $obj->company) {
1817
+									$out .= ' - ('.$obj->company.')';
1818
+								}
1547 1819
 								$out .= '</option>';
1548 1820
 							}
1549 1821
 						} else {
1550 1822
 							if (in_array($obj->rowid, $selected))
1551 1823
 							{
1552 1824
 								$out .= $contactstatic->getFullName($langs);
1553
-								if ($showfunction && $obj->poste) $out .= ' ('.$obj->poste.')';
1554
-								if (($showsoc > 0) && $obj->company) $out .= ' - ('.$obj->company.')';
1825
+								if ($showfunction && $obj->poste) {
1826
+									$out .= ' ('.$obj->poste.')';
1827
+								}
1828
+								if (($showsoc > 0) && $obj->company) {
1829
+									$out .= ' - ('.$obj->company.')';
1830
+								}
1555 1831
 							}
1556 1832
 						}
1557 1833
 					}
@@ -1639,19 +1915,27 @@  discard block
 block discarded – undo
1639 1915
 		global $conf, $user, $langs, $hookmanager;
1640 1916
 
1641 1917
 		// If no preselected user defined, we take current user
1642
-		if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && empty($conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) $selected = $user->id;
1918
+		if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && empty($conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) {
1919
+			$selected = $user->id;
1920
+		}
1643 1921
 
1644
-		if ($selected === '') $selected = array();
1645
-		elseif (!is_array($selected)) $selected = array($selected);
1922
+		if ($selected === '') {
1923
+			$selected = array();
1924
+		} elseif (!is_array($selected)) {
1925
+			$selected = array($selected);
1926
+		}
1646 1927
 
1647 1928
 		$excludeUsers = null;
1648 1929
 		$includeUsers = null;
1649 1930
 
1650 1931
 		// Permettre l'exclusion d'utilisateurs
1651
-		if (is_array($exclude))	$excludeUsers = implode(",", $exclude);
1932
+		if (is_array($exclude)) {
1933
+			$excludeUsers = implode(",", $exclude);
1934
+		}
1652 1935
 		// Permettre l'inclusion d'utilisateurs
1653
-		if (is_array($include))	$includeUsers = implode(",", $include);
1654
-		elseif ($include == 'hierarchy')
1936
+		if (is_array($include)) {
1937
+			$includeUsers = implode(",", $include);
1938
+		} elseif ($include == 'hierarchy')
1655 1939
 		{
1656 1940
 			// Build list includeUsers to have only hierarchy
1657 1941
 			$includeUsers = implode(",", $user->getAllChildIds(0));
@@ -1674,8 +1958,11 @@  discard block
 block discarded – undo
1674 1958
 		if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity)
1675 1959
 		{
1676 1960
 			$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entity as e ON e.rowid=u.entity";
1677
-			if ($force_entity) $sql .= " WHERE u.entity IN (0,".$force_entity.")";
1678
-			else $sql .= " WHERE u.entity IS NOT NULL";
1961
+			if ($force_entity) {
1962
+				$sql .= " WHERE u.entity IN (0,".$force_entity.")";
1963
+			} else {
1964
+				$sql .= " WHERE u.entity IS NOT NULL";
1965
+			}
1679 1966
 		} else {
1680 1967
 			if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1681 1968
 			{
@@ -1686,19 +1973,33 @@  discard block
 block discarded – undo
1686 1973
 				$sql .= " WHERE u.entity IN (0,".$conf->entity.")";
1687 1974
 			}
1688 1975
 		}
1689
-		if (!empty($user->socid)) $sql .= " AND u.fk_soc = ".$user->socid;
1690
-		if (is_array($exclude) && $excludeUsers) $sql .= " AND u.rowid NOT IN (".$excludeUsers.")";
1691
-		if ($includeUsers) $sql .= " AND u.rowid IN (".$includeUsers.")";
1692
-		if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX) || $noactive) $sql .= " AND u.statut <> 0";
1693
-		if (!empty($morefilter)) $sql .= " ".$morefilter;
1976
+		if (!empty($user->socid)) {
1977
+			$sql .= " AND u.fk_soc = ".$user->socid;
1978
+		}
1979
+		if (is_array($exclude) && $excludeUsers) {
1980
+			$sql .= " AND u.rowid NOT IN (".$excludeUsers.")";
1981
+		}
1982
+		if ($includeUsers) {
1983
+			$sql .= " AND u.rowid IN (".$includeUsers.")";
1984
+		}
1985
+		if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX) || $noactive) {
1986
+			$sql .= " AND u.statut <> 0";
1987
+		}
1988
+		if (!empty($morefilter)) {
1989
+			$sql .= " ".$morefilter;
1990
+		}
1694 1991
 
1695 1992
 		//Add hook to filter on user (for exemple on usergroup define in custom modules)
1696 1993
 		$reshook = $hookmanager->executeHooks('addSQLWhereFilterOnSelectUsers', array(), $this, $action);
1697
-		if (!empty($reshook)) $sql .= $hookmanager->resPrint;
1994
+		if (!empty($reshook)) {
1995
+			$sql .= $hookmanager->resPrint;
1996
+		}
1698 1997
 
1699
-		if (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION))	// MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
1998
+		if (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)) {
1999
+			// MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
1700 2000
 		{
1701 2001
 			$sql .= " ORDER BY u.firstname ASC";
2002
+		}
1702 2003
 		} else {
1703 2004
 			$sql .= " ORDER BY u.lastname ASC";
1704 2005
 		}
@@ -1717,8 +2018,12 @@  discard block
 block discarded – undo
1717 2018
 
1718 2019
 				// do not use maxwidthonsmartphone by default. Set it by caller so auto size to 100% will work when not defined
1719 2020
 				$out .= '<select class="flat'.($morecss ? ' minwidth100imp '.$morecss : ' minwidth200').'" id="'.$htmlname.'" name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').' '.($disabled ? ' disabled' : '').'>';
1720
-				if ($show_empty && !$multiple) $out .= '<option value="-1"'.((empty($selected) || in_array(-1, $selected)) ? ' selected' : '').'>&nbsp;</option>'."\n";
1721
-				if ($show_every) $out .= '<option value="-2"'.((in_array(-2, $selected)) ? ' selected' : '').'>-- '.$langs->trans("Everybody").' --</option>'."\n";
2021
+				if ($show_empty && !$multiple) {
2022
+					$out .= '<option value="-1"'.((empty($selected) || in_array(-1, $selected)) ? ' selected' : '').'>&nbsp;</option>'."\n";
2023
+				}
2024
+				if ($show_every) {
2025
+					$out .= '<option value="-2"'.((in_array(-2, $selected)) ? ' selected' : '').'>-- '.$langs->trans("Everybody").' --</option>'."\n";
2026
+				}
1722 2027
 
1723 2028
 				$userstatic = new User($this->db);
1724 2029
 
@@ -1731,16 +2036,22 @@  discard block
 block discarded – undo
1731 2036
 					$userstatic->firstname = $obj->firstname;
1732 2037
 
1733 2038
 					$disableline = '';
1734
-					if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) $disableline = ($enableonlytext ? $enableonlytext : '1');
2039
+					if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
2040
+						$disableline = ($enableonlytext ? $enableonlytext : '1');
2041
+					}
1735 2042
 
1736 2043
 					if ((is_object($selected) && $selected->id == $obj->rowid) || (!is_object($selected) && in_array($obj->rowid, $selected)))
1737 2044
 					{
1738 2045
 						$out .= '<option value="'.$obj->rowid.'"';
1739
-						if ($disableline) $out .= ' disabled';
2046
+						if ($disableline) {
2047
+							$out .= ' disabled';
2048
+						}
1740 2049
 						$out .= ' selected>';
1741 2050
 					} else {
1742 2051
 						$out .= '<option value="'.$obj->rowid.'"';
1743
-						if ($disableline) $out .= ' disabled';
2052
+						if ($disableline) {
2053
+							$out .= ' disabled';
2054
+						}
1744 2055
 						$out .= '>';
1745 2056
 					}
1746 2057
 
@@ -1802,7 +2113,9 @@  discard block
 block discarded – undo
1802 2113
 			dol_print_error($this->db);
1803 2114
 		}
1804 2115
 
1805
-		if ($outputmode) return $outarray;
2116
+		if ($outputmode) {
2117
+			return $outarray;
2118
+		}
1806 2119
 		return $out;
1807 2120
 	}
1808 2121
 
@@ -1857,12 +2170,18 @@  discard block
 block discarded – undo
1857 2170
 		}
1858 2171
 		$nbassignetouser = count($assignedtouser);
1859 2172
 
1860
-		if ($nbassignetouser && $action != 'view') $out .= '<br>';
1861
-		if ($nbassignetouser) $out .= '<ul class="attendees">';
2173
+		if ($nbassignetouser && $action != 'view') {
2174
+			$out .= '<br>';
2175
+		}
2176
+		if ($nbassignetouser) {
2177
+			$out .= '<ul class="attendees">';
2178
+		}
1862 2179
 		$i = 0; $ownerid = 0;
1863 2180
 		foreach ($assignedtouser as $key => $value)
1864 2181
 		{
1865
-			if ($value['id'] == $ownerid) continue;
2182
+			if ($value['id'] == $ownerid) {
2183
+				continue;
2184
+			}
1866 2185
 
1867 2186
 			$out .= '<li>';
1868 2187
 			$userstatic->fetch($value['id']);
@@ -1888,7 +2207,9 @@  discard block
 block discarded – undo
1888 2207
 			$out .= '</li>';
1889 2208
 			$i++;
1890 2209
 		}
1891
-		if ($nbassignetouser) $out .= '</ul>';
2210
+		if ($nbassignetouser) {
2211
+			$out .= '</ul>';
2212
+		}
1892 2213
 
1893 2214
 		//$out.='</form>';
1894 2215
 		return $out;
@@ -1928,7 +2249,9 @@  discard block
 block discarded – undo
1928 2249
 
1929 2250
 		// check parameters
1930 2251
 		$price_level = (!empty($price_level) ? $price_level : 0);
1931
-		if (is_null($ajaxoptions)) $ajaxoptions = array();
2252
+		if (is_null($ajaxoptions)) {
2253
+			$ajaxoptions = array();
2254
+		}
1932 2255
 
1933 2256
 		if (strval($filtertype) === '' && (!empty($conf->product->enabled) || !empty($conf->service->enabled))) {
1934 2257
 			if (!empty($conf->product->enabled) && empty($conf->service->enabled)) {
@@ -2040,8 +2363,9 @@  discard block
 block discarded – undo
2040 2363
 				</script>
2041 2364
                 <?php
2042 2365
 			}
2043
-			if (empty($hidelabel)) print $langs->trans("RefOrLabel").' : ';
2044
-			elseif ($hidelabel > 1) {
2366
+			if (empty($hidelabel)) {
2367
+				print $langs->trans("RefOrLabel").' : ';
2368
+			} elseif ($hidelabel > 1) {
2045 2369
 				$placeholder = ' placeholder="'.$langs->trans("RefOrLabel").'"';
2046 2370
 				if ($hidelabel == 2) {
2047 2371
 					print img_picto($langs->trans("Search"), 'search');
@@ -2155,11 +2479,15 @@  discard block
 block discarded – undo
2155 2479
 		if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))
2156 2480
 		{
2157 2481
 			$sql .= ", (SELECT pp.rowid FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid";
2158
-			if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $sql .= " AND price_level=".$price_level;
2482
+			if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
2483
+				$sql .= " AND price_level=".$price_level;
2484
+			}
2159 2485
 			$sql .= " ORDER BY date_price";
2160 2486
 			$sql .= " DESC LIMIT 1) as price_rowid";
2161 2487
 			$sql .= ", (SELECT pp.price_by_qty FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; // price_by_qty is 1 if some prices by qty exists in subtable
2162
-			if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $sql .= " AND price_level=".$price_level;
2488
+			if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
2489
+				$sql .= " AND price_level=".$price_level;
2490
+			}
2163 2491
 			$sql .= " ORDER BY date_price";
2164 2492
 			$sql .= " DESC LIMIT 1) as price_by_qty";
2165 2493
 			$selectFields .= ", price_rowid, price_by_qty";
@@ -2208,14 +2536,17 @@  discard block
 block discarded – undo
2208 2536
 		} elseif ($finished == 1)
2209 2537
 		{
2210 2538
 			$sql .= " AND p.finished = ".$finished;
2211
-			if ($status >= 0)  $sql .= " AND p.tosell = ".$status;
2539
+			if ($status >= 0) {
2540
+				$sql .= " AND p.tosell = ".$status;
2541
+			}
2212 2542
 		} elseif ($status >= 0)
2213 2543
 		{
2214 2544
 			$sql .= " AND p.tosell = ".$status;
2215 2545
 		}
2216 2546
 		// Filter by product type
2217
-		if (strval($filtertype) != '') $sql .= " AND p.fk_product_type = ".$filtertype;
2218
-		elseif (empty($conf->product->enabled)) { // when product module is disabled, show services only
2547
+		if (strval($filtertype) != '') {
2548
+			$sql .= " AND p.fk_product_type = ".$filtertype;
2549
+		} elseif (empty($conf->product->enabled)) { // when product module is disabled, show services only
2219 2550
 			$sql .= " AND p.fk_product_type = 1";
2220 2551
 		} elseif (empty($conf->service->enabled)) { // when service module is disabled, show products only
2221 2552
 			$sql .= " AND p.fk_product_type = 0";
@@ -2228,23 +2559,37 @@  discard block
 block discarded – undo
2228 2559
 			// For natural search
2229 2560
 			$scrit = explode(' ', $filterkey);
2230 2561
 			$i = 0;
2231
-			if (count($scrit) > 1) $sql .= "(";
2562
+			if (count($scrit) > 1) {
2563
+				$sql .= "(";
2564
+			}
2232 2565
 			foreach ($scrit as $crit)
2233 2566
 			{
2234
-				if ($i > 0) $sql .= " AND ";
2567
+				if ($i > 0) {
2568
+					$sql .= " AND ";
2569
+				}
2235 2570
 				$sql .= "(p.ref LIKE '".$db->escape($prefix.$crit)."%' OR p.label LIKE '".$db->escape($prefix.$crit)."%'";
2236
-				if (!empty($conf->global->MAIN_MULTILANGS)) $sql .= " OR pl.label LIKE '".$db->escape($prefix.$crit)."%'";
2571
+				if (!empty($conf->global->MAIN_MULTILANGS)) {
2572
+					$sql .= " OR pl.label LIKE '".$db->escape($prefix.$crit)."%'";
2573
+				}
2237 2574
 				if (!empty($conf->global->PRODUCT_AJAX_SEARCH_ON_DESCRIPTION))
2238 2575
 				{
2239 2576
 					$sql .= " OR p.description LIKE '".$db->escape($prefix.$crit)."%'";
2240
-					if (!empty($conf->global->MAIN_MULTILANGS)) $sql .= " OR pl.description LIKE '".$db->escape($prefix.$crit)."%'";
2577
+					if (!empty($conf->global->MAIN_MULTILANGS)) {
2578
+						$sql .= " OR pl.description LIKE '".$db->escape($prefix.$crit)."%'";
2579
+					}
2580
+				}
2581
+				if (!empty($conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) {
2582
+					$sql .= " OR pfp.ref_fourn LIKE '".$db->escape($prefix.$crit)."%'";
2241 2583
 				}
2242
-				if (!empty($conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) $sql .= " OR pfp.ref_fourn LIKE '".$db->escape($prefix.$crit)."%'";
2243 2584
 				$sql .= ")";
2244 2585
 				$i++;
2245 2586
 			}
2246
-			if (count($scrit) > 1) $sql .= ")";
2247
-		  	if (!empty($conf->barcode->enabled)) $sql .= " OR p.barcode LIKE '".$db->escape($prefix.$filterkey)."%'";
2587
+			if (count($scrit) > 1) {
2588
+				$sql .= ")";
2589
+			}
2590
+		  	if (!empty($conf->barcode->enabled)) {
2591
+		  		$sql .= " OR p.barcode LIKE '".$db->escape($prefix.$filterkey)."%'";
2592
+		  	}
2248 2593
 			$sql .= ')';
2249 2594
 		}
2250 2595
 		if (count($warehouseStatusArray))
@@ -2290,12 +2635,19 @@  discard block
 block discarded – undo
2290 2635
 			//if (! empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
2291 2636
 			if (!empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT))
2292 2637
 			{
2293
-				if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty);
2294
-				else $textifempty .= $langs->trans("All");
2638
+				if ($showempty && !is_numeric($showempty)) {
2639
+					$textifempty = $langs->trans($showempty);
2640
+				} else {
2641
+					$textifempty .= $langs->trans("All");
2642
+				}
2295 2643
 			} else {
2296
-			    if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty);
2644
+			    if ($showempty && !is_numeric($showempty)) {
2645
+			    	$textifempty = $langs->trans($showempty);
2646
+			    }
2647
+			}
2648
+			if ($showempty) {
2649
+				$out .= '<option value="0" selected>'.$textifempty.'</option>';
2297 2650
 			}
2298
-			if ($showempty) $out .= '<option value="0" selected>'.$textifempty.'</option>';
2299 2651
 
2300 2652
 			$i = 0;
2301 2653
 			while ($num && $i < $num)
@@ -2373,7 +2725,9 @@  discard block
 block discarded – undo
2373 2725
 
2374 2726
 			$this->db->free($result);
2375 2727
 
2376
-			if (empty($outputmode)) return $out;
2728
+			if (empty($outputmode)) {
2729
+				return $out;
2730
+			}
2377 2731
 			return $outarray;
2378 2732
 		} else {
2379 2733
 			dol_print_error($db);
@@ -2416,8 +2770,12 @@  discard block
 block discarded – undo
2416 2770
 		$maxlengtharticle = (empty($conf->global->PRODUCT_MAX_LENGTH_COMBO) ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO);
2417 2771
 
2418 2772
 		$label = $objp->label;
2419
-		if (!empty($objp->label_translated)) $label = $objp->label_translated;
2420
-		if (!empty($filterkey) && $filterkey != '') $label = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $label, 1);
2773
+		if (!empty($objp->label_translated)) {
2774
+			$label = $objp->label_translated;
2775
+		}
2776
+		if (!empty($filterkey) && $filterkey != '') {
2777
+			$label = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $label, 1);
2778
+		}
2421 2779
 
2422 2780
 		$outkey = $objp->rowid;
2423 2781
 		$outref = $objp->ref;
@@ -2431,7 +2789,9 @@  discard block
 block discarded – undo
2431 2789
 		$outdurationvalue = $outtype == Product::TYPE_SERVICE ?substr($objp->duration, 0, dol_strlen($objp->duration) - 1) : '';
2432 2790
 		$outdurationunit = $outtype == Product::TYPE_SERVICE ?substr($objp->duration, -1) : '';
2433 2791
 
2434
-		if ($outorigin && !empty($conf->global->PRODUCT_SHOW_ORIGIN_IN_COMBO))  require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
2792
+		if ($outorigin && !empty($conf->global->PRODUCT_SHOW_ORIGIN_IN_COMBO)) {
2793
+			require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
2794
+		}
2435 2795
 
2436 2796
         // Units
2437 2797
         $outvalUnits = '';
@@ -2480,22 +2840,35 @@  discard block
 block discarded – undo
2480 2840
 		if (!empty($conf->stock->enabled) && isset($objp->stock) && ($objp->fk_product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)))
2481 2841
 		{
2482 2842
 		    if (!empty($user->rights->stock->lire)) {
2483
-    			if ($objp->stock > 0) $opt .= ' class="product_line_stock_ok"';
2484
-	       		elseif ($objp->stock <= 0) $opt .= ' class="product_line_stock_too_low"';
2843
+    			if ($objp->stock > 0) {
2844
+    				$opt .= ' class="product_line_stock_ok"';
2845
+    			} elseif ($objp->stock <= 0) {
2846
+	       			$opt .= ' class="product_line_stock_too_low"';
2847
+	       		}
2485 2848
 		    }
2486 2849
 		}
2487 2850
 		$opt .= '>';
2488 2851
 		$opt .= $objp->ref;
2489
-		if ($outbarcode) $opt .= ' ('.$outbarcode.')';
2852
+		if ($outbarcode) {
2853
+			$opt .= ' ('.$outbarcode.')';
2854
+		}
2490 2855
 		$opt .= ' - '.dol_trunc($label, $maxlengtharticle);
2491
-		if ($outorigin && !empty($conf->global->PRODUCT_SHOW_ORIGIN_IN_COMBO)) $opt .= ' ('.getCountry($outorigin, 1).')';
2856
+		if ($outorigin && !empty($conf->global->PRODUCT_SHOW_ORIGIN_IN_COMBO)) {
2857
+			$opt .= ' ('.getCountry($outorigin, 1).')';
2858
+		}
2492 2859
 
2493 2860
 		$objRef = $objp->ref;
2494
-		if (!empty($filterkey) && $filterkey != '') $objRef = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $objRef, 1);
2861
+		if (!empty($filterkey) && $filterkey != '') {
2862
+			$objRef = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $objRef, 1);
2863
+		}
2495 2864
 		$outval .= $objRef;
2496
-		if ($outbarcode) $outval .= ' ('.$outbarcode.')';
2865
+		if ($outbarcode) {
2866
+			$outval .= ' ('.$outbarcode.')';
2867
+		}
2497 2868
 		$outval .= ' - '.dol_trunc($label, $maxlengtharticle);
2498
-		if ($outorigin && !empty($conf->global->PRODUCT_SHOW_ORIGIN_IN_COMBO)) $outval .= ' ('.getCountry($outorigin, 1).')';
2869
+		if ($outorigin && !empty($conf->global->PRODUCT_SHOW_ORIGIN_IN_COMBO)) {
2870
+			$outval .= ' ('.getCountry($outorigin, 1).')';
2871
+		}
2499 2872
 
2500 2873
         // Units
2501 2874
         $opt .= $outvalUnits;
@@ -2628,9 +3001,11 @@  discard block
 block discarded – undo
2628 3001
     			}
2629 3002
     			$outval .= $langs->transnoentities("Stock").':'.$objp->stock;
2630 3003
     			$outval .= '</span>';
2631
-    			if (empty($novirtualstock) && !empty($conf->global->STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO))  // Warning, this option may slow down combo list generation
3004
+    			if (empty($novirtualstock) && !empty($conf->global->STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO)) {
3005
+    				// Warning, this option may slow down combo list generation
2632 3006
     			{
2633 3007
     			    $langs->load("stocks");
3008
+    			}
2634 3009
 
2635 3010
     			    $tmpproduct = new Product($this->db);
2636 3011
     			    $tmpproduct->fetch($objp->rowid, '', '', '', 1, 1, 1); // Load product without lang and prices arrays (we just need to make ->virtual_stock() after)
@@ -2740,10 +3115,14 @@  discard block
 block discarded – undo
2740 3115
         if ($conf->global->PRODUCT_USE_UNITS) {
2741 3116
             $sql .= ", u.label as unit_long, u.short_label as unit_short, p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units";
2742 3117
         }
2743
-        if (!empty($conf->barcode->enabled)) $sql .= ", pfp.barcode";
3118
+        if (!empty($conf->barcode->enabled)) {
3119
+        	$sql .= ", pfp.barcode";
3120
+        }
2744 3121
 		$sql .= " FROM ".MAIN_DB_PREFIX."product as p";
2745 3122
 		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (".getEntity('product').") )";
2746
-		if ($socid) $sql .= " AND pfp.fk_soc = ".$socid;
3123
+		if ($socid) {
3124
+			$sql .= " AND pfp.fk_soc = ".$socid;
3125
+		}
2747 3126
 		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid";
2748 3127
         // Units
2749 3128
         if ($conf->global->PRODUCT_USE_UNITS) {
@@ -2751,8 +3130,12 @@  discard block
 block discarded – undo
2751 3130
         }
2752 3131
 		$sql .= " WHERE p.entity IN (".getEntity('product').")";
2753 3132
 		$sql .= " AND p.tobuy = 1";
2754
-		if (strval($filtertype) != '') $sql .= " AND p.fk_product_type=".$this->db->escape($filtertype);
2755
-		if (!empty($filtre)) $sql .= " ".$filtre;
3133
+		if (strval($filtertype) != '') {
3134
+			$sql .= " AND p.fk_product_type=".$this->db->escape($filtertype);
3135
+		}
3136
+		if (!empty($filtre)) {
3137
+			$sql .= " ".$filtre;
3138
+		}
2756 3139
 		// Add criteria on ref/label
2757 3140
 		if ($filterkey != '')
2758 3141
 		{
@@ -2761,14 +3144,20 @@  discard block
 block discarded – undo
2761 3144
 			// For natural search
2762 3145
 			$scrit = explode(' ', $filterkey);
2763 3146
 			$i = 0;
2764
-			if (count($scrit) > 1) $sql .= "(";
3147
+			if (count($scrit) > 1) {
3148
+				$sql .= "(";
3149
+			}
2765 3150
 			foreach ($scrit as $crit)
2766 3151
 			{
2767
-				if ($i > 0) $sql .= " AND ";
3152
+				if ($i > 0) {
3153
+					$sql .= " AND ";
3154
+				}
2768 3155
 				$sql .= "(pfp.ref_fourn LIKE '".$this->db->escape($prefix.$crit)."%' OR p.ref LIKE '".$this->db->escape($prefix.$crit)."%' OR p.label LIKE '".$this->db->escape($prefix.$crit)."%')";
2769 3156
 				$i++;
2770 3157
 			}
2771
-			if (count($scrit) > 1) $sql .= ")";
3158
+			if (count($scrit) > 1) {
3159
+				$sql .= ")";
3160
+			}
2772 3161
 			if (!empty($conf->barcode->enabled)) {
2773 3162
                 $sql .= " OR p.barcode LIKE '".$this->db->escape($prefix.$filterkey)."%'";
2774 3163
                 $sql .= " OR pfp.barcode LIKE '".$this->db->escape($prefix.$filterkey)."%'";
@@ -2791,8 +3180,11 @@  discard block
 block discarded – undo
2791 3180
 
2792 3181
 			//$out.='<select class="flat" id="select'.$htmlname.'" name="'.$htmlname.'">';	// remove select to have id same with combo and ajax
2793 3182
 			$out .= '<select class="flat maxwidthonsmartphone'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
2794
-			if (!$selected) $out .= '<option value="0" selected>&nbsp;</option>';
2795
-			else $out .= '<option value="0">&nbsp;</option>';
3183
+			if (!$selected) {
3184
+				$out .= '<option value="0" selected>&nbsp;</option>';
3185
+			} else {
3186
+				$out .= '<option value="0">&nbsp;</option>';
3187
+			}
2796 3188
 
2797 3189
 			$i = 0;
2798 3190
 			while ($i < $num)
@@ -2800,7 +3192,10 @@  discard block
 block discarded – undo
2800 3192
 				$objp = $this->db->fetch_object($result);
2801 3193
 
2802 3194
 				$outkey = $objp->idprodfournprice; // id in table of price
2803
-				if (!$outkey && $alsoproductwithnosupplierprice) $outkey = 'idprod_'.$objp->rowid; // id of product
3195
+				if (!$outkey && $alsoproductwithnosupplierprice) {
3196
+					$outkey = 'idprod_'.$objp->rowid;
3197
+				}
3198
+				// id of product
2804 3199
 
2805 3200
 				$outref = $objp->ref;
2806 3201
 				$outval = '';
@@ -2848,11 +3243,17 @@  discard block
 block discarded – undo
2848 3243
                 }
2849 3244
 
2850 3245
 				$objRef = $objp->ref;
2851
-				if ($filterkey && $filterkey != '') $objRef = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $objRef, 1);
3246
+				if ($filterkey && $filterkey != '') {
3247
+					$objRef = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $objRef, 1);
3248
+				}
2852 3249
 				$objRefFourn = $objp->ref_fourn;
2853
-				if ($filterkey && $filterkey != '') $objRefFourn = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $objRefFourn, 1);
3250
+				if ($filterkey && $filterkey != '') {
3251
+					$objRefFourn = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $objRefFourn, 1);
3252
+				}
2854 3253
 				$label = $objp->label;
2855
-				if ($filterkey && $filterkey != '') $label = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $label, 1);
3254
+				if ($filterkey && $filterkey != '') {
3255
+					$label = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $label, 1);
3256
+				}
2856 3257
 
2857 3258
 				$optlabel = $objp->ref;
2858 3259
 				if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) {
@@ -2939,9 +3340,11 @@  discard block
 block discarded – undo
2939 3340
 						$outvallabel .= " - ".$reputations[$objp->supplier_reputation];
2940 3341
 					}
2941 3342
 				} else {
2942
-					if (empty($alsoproductwithnosupplierprice))     // No supplier price defined for couple product/supplier
3343
+					if (empty($alsoproductwithnosupplierprice)) {
3344
+						// No supplier price defined for couple product/supplier
2943 3345
 					{
2944 3346
 						$optlabel .= " - <span class='opacitymedium'>".$langs->trans("NoPriceDefinedForThisSupplier").'</span>';
3347
+					}
2945 3348
 						$outvallabel .= ' - '.$langs->transnoentities("NoPriceDefinedForThisSupplier");
2946 3349
 					} else // No supplier price defined for product, even on other suppliers
2947 3350
 					{
@@ -2951,8 +3354,12 @@  discard block
 block discarded – undo
2951 3354
 				}
2952 3355
 
2953 3356
 				$opt = '<option value="'.$outkey.'"';
2954
-				if ($selected && $selected == $objp->idprodfournprice) $opt .= ' selected';
2955
-				if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) $opt .= ' disabled';
3357
+				if ($selected && $selected == $objp->idprodfournprice) {
3358
+					$opt .= ' selected';
3359
+				}
3360
+				if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
3361
+					$opt .= ' disabled';
3362
+				}
2956 3363
 				if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0)
2957 3364
 				{
2958 3365
 					$opt .= ' pbq="'.$objp->idprodfournprice.'" data-pbq="'.$objp->idprodfournprice.'" data-pbqqty="'.$objp->quantity.'" data-pbqup="'.$objp->unitprice.'" data-pbqpercent="'.$objp->remise_percent.'"';
@@ -2989,7 +3396,9 @@  discard block
 block discarded – undo
2989 3396
 			include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
2990 3397
 			$out .= ajax_combobox($htmlname);
2991 3398
 
2992
-			if (empty($outputmode)) return $out;
3399
+			if (empty($outputmode)) {
3400
+				return $out;
3401
+			}
2993 3402
 			return $outarray;
2994 3403
 		} else {
2995 3404
 			dol_print_error($this->db);
@@ -3087,7 +3496,9 @@  discard block
 block discarded – undo
3087 3496
 						$opt .= " - ";
3088 3497
 						$opt .= price($objp->unitprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE) ? (1 - $objp->remise_percent / 100) : 1), 1, $langs, 0, 0, -1, $conf->currency)."/".$langs->trans("Unit");
3089 3498
 					}
3090
-					if ($objp->duration) $opt .= " - ".$objp->duration;
3499
+					if ($objp->duration) {
3500
+						$opt .= " - ".$objp->duration;
3501
+					}
3091 3502
 					$opt .= "</option>\n";
3092 3503
 
3093 3504
 					$form .= $opt;
@@ -3127,7 +3538,9 @@  discard block
 block discarded – undo
3127 3538
 		if ($resql)
3128 3539
 		{
3129 3540
 			print '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">';
3130
-			if ($showempty) print '<option value="0">&nbsp;</option>';
3541
+			if ($showempty) {
3542
+				print '<option value="0">&nbsp;</option>';
3543
+			}
3131 3544
 			$num = $this->db->num_rows($resql);
3132 3545
 			$i = 0;
3133 3546
 			if ($num)
@@ -3165,7 +3578,10 @@  discard block
 block discarded – undo
3165 3578
 		global $langs;
3166 3579
 
3167 3580
 		$num = count($this->cache_conditions_paiements);
3168
-		if ($num > 0) return 0; // Cache already loaded
3581
+		if ($num > 0) {
3582
+			return 0;
3583
+		}
3584
+		// Cache already loaded
3169 3585
 
3170 3586
 		dol_syslog(__METHOD__, LOG_DEBUG);
3171 3587
 
@@ -3212,7 +3628,10 @@  discard block
 block discarded – undo
3212 3628
 		global $langs;
3213 3629
 
3214 3630
 		$num = count($this->cache_availability);
3215
-		if ($num > 0) return 0; // Cache already loaded
3631
+		if ($num > 0) {
3632
+			return 0;
3633
+		}
3634
+		// Cache already loaded
3216 3635
 
3217 3636
 		dol_syslog(__METHOD__, LOG_DEBUG);
3218 3637
 
@@ -3265,7 +3684,9 @@  discard block
 block discarded – undo
3265 3684
 		dol_syslog(__METHOD__." selected=".$selected.", htmlname=".$htmlname, LOG_DEBUG);
3266 3685
 
3267 3686
 		print '<select id="'.$htmlname.'" class="flat" name="'.$htmlname.'">';
3268
-		if ($addempty) print '<option value="0">&nbsp;</option>';
3687
+		if ($addempty) {
3688
+			print '<option value="0">&nbsp;</option>';
3689
+		}
3269 3690
 		foreach ($this->cache_availability as $id => $arrayavailability)
3270 3691
 		{
3271 3692
 			if ($selected == $id)
@@ -3278,7 +3699,9 @@  discard block
 block discarded – undo
3278 3699
 			print '</option>';
3279 3700
 		}
3280 3701
 		print '</select>';
3281
-		if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
3702
+		if ($user->admin) {
3703
+			print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
3704
+		}
3282 3705
 	}
3283 3706
 
3284 3707
 	/**
@@ -3291,7 +3714,10 @@  discard block
 block discarded – undo
3291 3714
 		global $langs;
3292 3715
 
3293 3716
 		$num = count($this->cache_demand_reason);
3294
-		if ($num > 0) return 0; // Cache already loaded
3717
+		if ($num > 0) {
3718
+			return 0;
3719
+		}
3720
+		// Cache already loaded
3295 3721
 
3296 3722
 		$sql = "SELECT rowid, code, label";
3297 3723
 		$sql .= " FROM ".MAIN_DB_PREFIX.'c_input_reason';
@@ -3309,8 +3735,14 @@  discard block
 block discarded – undo
3309 3735
 
3310 3736
 				// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
3311 3737
 				$label = ($obj->label != '-' ? $obj->label : '');
3312
-				if ($langs->trans("DemandReasonType".$obj->code) != ("DemandReasonType".$obj->code)) $label = $langs->trans("DemandReasonType".$obj->code); // So translation key DemandReasonTypeSRC_XXX will work
3313
-				if ($langs->trans($obj->code) != $obj->code) $label = $langs->trans($obj->code); // So translation key SRC_XXX will work
3738
+				if ($langs->trans("DemandReasonType".$obj->code) != ("DemandReasonType".$obj->code)) {
3739
+					$label = $langs->trans("DemandReasonType".$obj->code);
3740
+				}
3741
+				// So translation key DemandReasonTypeSRC_XXX will work
3742
+				if ($langs->trans($obj->code) != $obj->code) {
3743
+					$label = $langs->trans($obj->code);
3744
+				}
3745
+				// So translation key SRC_XXX will work
3314 3746
 
3315 3747
 				$tmparray[$obj->rowid]['id']   = $obj->rowid;
3316 3748
 				$tmparray[$obj->rowid]['code'] = $obj->code;
@@ -3345,10 +3777,14 @@  discard block
 block discarded – undo
3345 3777
 		$this->loadCacheInputReason();
3346 3778
 
3347 3779
 		print '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">';
3348
-		if ($addempty) print '<option value="0"'.(empty($selected) ? ' selected' : '').'>&nbsp;</option>';
3780
+		if ($addempty) {
3781
+			print '<option value="0"'.(empty($selected) ? ' selected' : '').'>&nbsp;</option>';
3782
+		}
3349 3783
 		foreach ($this->cache_demand_reason as $id => $arraydemandreason)
3350 3784
 		{
3351
-			if ($arraydemandreason['code'] == $exclude) continue;
3785
+			if ($arraydemandreason['code'] == $exclude) {
3786
+				continue;
3787
+			}
3352 3788
 
3353 3789
 			if ($selected && ($selected == $arraydemandreason['id'] || $selected == $arraydemandreason['code']))
3354 3790
 			{
@@ -3361,7 +3797,9 @@  discard block
 block discarded – undo
3361 3797
 			print '</option>';
3362 3798
 		}
3363 3799
 		print '</select>';
3364
-		if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
3800
+		if ($user->admin) {
3801
+			print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
3802
+		}
3365 3803
 	}
3366 3804
 
3367 3805
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
@@ -3376,7 +3814,10 @@  discard block
 block discarded – undo
3376 3814
 		global $langs;
3377 3815
 
3378 3816
 		$num = count($this->cache_types_paiements);
3379
-		if ($num > 0) return $num; // Cache already loaded
3817
+		if ($num > 0) {
3818
+			return $num;
3819
+		}
3820
+		// Cache already loaded
3380 3821
 
3381 3822
 		dol_syslog(__METHOD__, LOG_DEBUG);
3382 3823
 
@@ -3440,10 +3881,14 @@  discard block
 block discarded – undo
3440 3881
 		$this->load_cache_conditions_paiements();
3441 3882
 
3442 3883
 		// Set default value if not already set by caller
3443
-		if (empty($selected) && !empty($conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID)) $selected = $conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID;
3884
+		if (empty($selected) && !empty($conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID)) {
3885
+			$selected = $conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID;
3886
+		}
3444 3887
 
3445 3888
 		print '<select id="'.$htmlname.'" class="flat selectpaymentterms'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">';
3446
-		if ($addempty) print '<option value="0">&nbsp;</option>';
3889
+		if ($addempty) {
3890
+			print '<option value="0">&nbsp;</option>';
3891
+		}
3447 3892
 		foreach ($this->cache_conditions_paiements as $id => $arrayconditions)
3448 3893
 		{
3449 3894
 			if ($selected == $id)
@@ -3456,7 +3901,9 @@  discard block
 block discarded – undo
3456 3901
 			print '</option>';
3457 3902
 		}
3458 3903
 		print '</select>';
3459
-		if ($user->admin && empty($noinfoadmin)) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
3904
+		if ($user->admin && empty($noinfoadmin)) {
3905
+			print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
3906
+		}
3460 3907
 	}
3461 3908
 
3462 3909
 
@@ -3484,48 +3931,78 @@  discard block
 block discarded – undo
3484 3931
 		dol_syslog(__METHOD__." ".$selected.", ".$htmlname.", ".$filtertype.", ".$format, LOG_DEBUG);
3485 3932
 
3486 3933
 		$filterarray = array();
3487
-		if ($filtertype == 'CRDT')  	$filterarray = array(0, 2, 3);
3488
-		elseif ($filtertype == 'DBIT') 	$filterarray = array(1, 2, 3);
3489
-		elseif ($filtertype != '' && $filtertype != '-1') $filterarray = explode(',', $filtertype);
3934
+		if ($filtertype == 'CRDT') {
3935
+			$filterarray = array(0, 2, 3);
3936
+		} elseif ($filtertype == 'DBIT') {
3937
+			$filterarray = array(1, 2, 3);
3938
+		} elseif ($filtertype != '' && $filtertype != '-1') {
3939
+			$filterarray = explode(',', $filtertype);
3940
+		}
3490 3941
 
3491 3942
 		$this->load_cache_types_paiements();
3492 3943
 
3493 3944
 		// Set default value if not already set by caller
3494
-		if (empty($selected) && !empty($conf->global->MAIN_DEFAULT_PAYMENT_TYPE_ID)) $selected = $conf->global->MAIN_DEFAULT_PAYMENT_TYPE_ID;
3945
+		if (empty($selected) && !empty($conf->global->MAIN_DEFAULT_PAYMENT_TYPE_ID)) {
3946
+			$selected = $conf->global->MAIN_DEFAULT_PAYMENT_TYPE_ID;
3947
+		}
3495 3948
 
3496 3949
 		print '<select id="select'.$htmlname.'" class="flat selectpaymenttypes'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">';
3497
-		if ($empty) print '<option value="">&nbsp;</option>';
3950
+		if ($empty) {
3951
+			print '<option value="">&nbsp;</option>';
3952
+		}
3498 3953
 		foreach ($this->cache_types_paiements as $id => $arraytypes)
3499 3954
 		{
3500 3955
 			// If not good status
3501
-			if ($active >= 0 && $arraytypes['active'] != $active) continue;
3956
+			if ($active >= 0 && $arraytypes['active'] != $active) {
3957
+				continue;
3958
+			}
3502 3959
 
3503 3960
 			// On passe si on a demande de filtrer sur des modes de paiments particuliers
3504
-			if (count($filterarray) && !in_array($arraytypes['type'], $filterarray)) continue;
3961
+			if (count($filterarray) && !in_array($arraytypes['type'], $filterarray)) {
3962
+				continue;
3963
+			}
3505 3964
 
3506 3965
 			// We discard empty line if showempty is on because an empty line has already been output.
3507
-			if ($empty && empty($arraytypes['code'])) continue;
3966
+			if ($empty && empty($arraytypes['code'])) {
3967
+				continue;
3968
+			}
3508 3969
 
3509
-			if ($format == 0) print '<option value="'.$id.'"';
3510
-			elseif ($format == 1) print '<option value="'.$arraytypes['code'].'"';
3511
-			elseif ($format == 2) print '<option value="'.$arraytypes['code'].'"';
3512
-			elseif ($format == 3) print '<option value="'.$id.'"';
3970
+			if ($format == 0) {
3971
+				print '<option value="'.$id.'"';
3972
+			} elseif ($format == 1) {
3973
+				print '<option value="'.$arraytypes['code'].'"';
3974
+			} elseif ($format == 2) {
3975
+				print '<option value="'.$arraytypes['code'].'"';
3976
+			} elseif ($format == 3) {
3977
+				print '<option value="'.$id.'"';
3978
+			}
3513 3979
 			// Print attribute selected or not
3514 3980
 			if ($format == 1 || $format == 2) {
3515
-				if ($selected == $arraytypes['code']) print ' selected';
3981
+				if ($selected == $arraytypes['code']) {
3982
+					print ' selected';
3983
+				}
3516 3984
 			} else {
3517
-				if ($selected == $id) print ' selected';
3985
+				if ($selected == $id) {
3986
+					print ' selected';
3987
+				}
3518 3988
 			}
3519 3989
 			print '>';
3520
-			if ($format == 0) $value = ($maxlength ?dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']);
3521
-			elseif ($format == 1) $value = $arraytypes['code'];
3522
-			elseif ($format == 2) $value = ($maxlength ?dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']);
3523
-			elseif ($format == 3) $value = $arraytypes['code'];
3990
+			if ($format == 0) {
3991
+				$value = ($maxlength ?dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']);
3992
+			} elseif ($format == 1) {
3993
+				$value = $arraytypes['code'];
3994
+			} elseif ($format == 2) {
3995
+				$value = ($maxlength ?dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']);
3996
+			} elseif ($format == 3) {
3997
+				$value = $arraytypes['code'];
3998
+			}
3524 3999
 			print $value ? $value : '&nbsp;';
3525 4000
 			print '</option>';
3526 4001
 		}
3527 4002
 		print '</select>';
3528
-		if ($user->admin && !$noadmininfo) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4003
+		if ($user->admin && !$noadmininfo) {
4004
+			print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4005
+		}
3529 4006
 	}
3530 4007
 
3531 4008
 
@@ -3582,7 +4059,9 @@  discard block
 block discarded – undo
3582 4059
 		$sql = "SELECT rowid, code, libelle as label";
3583 4060
 		$sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode";
3584 4061
 		$sql .= " WHERE active > 0";
3585
-		if ($filtre) $sql .= " AND ".$filtre;
4062
+		if ($filtre) {
4063
+			$sql .= " AND ".$filtre;
4064
+		}
3586 4065
 		$sql .= " ORDER BY libelle ASC";
3587 4066
 
3588 4067
 		dol_syslog(get_class($this)."::selectShippingMode", LOG_DEBUG);
@@ -3607,7 +4086,9 @@  discard block
 block discarded – undo
3607 4086
 					$i++;
3608 4087
 				}
3609 4088
 				print "</select>";
3610
-				if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4089
+				if ($user->admin) {
4090
+					print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
4091
+				}
3611 4092
 			} else {
3612 4093
 				print $langs->trans("NoShippingMethodDefined");
3613 4094
 			}
@@ -3725,15 +4206,19 @@  discard block
 block discarded – undo
3725 4206
 		$resql = $this->db->query($sql);
3726 4207
 		if ($resql && $this->db->num_rows($resql) > 0)
3727 4208
 		{
3728
-			if ($showempty) $return .= '<option value="none"></option>';
4209
+			if ($showempty) {
4210
+				$return .= '<option value="none"></option>';
4211
+			}
3729 4212
 
3730 4213
 			while ($res = $this->db->fetch_object($resql))
3731 4214
 			{
3732 4215
 			    $unitLabel = $res->label;
3733
-			    if (!empty($langs->tab_translate['unit'.$res->code]))	// check if Translation is available before
4216
+			    if (!empty($langs->tab_translate['unit'.$res->code])) {
4217
+			    	// check if Translation is available before
3734 4218
 			    {
3735 4219
 			        $unitLabel = $langs->trans('unit'.$res->code) != $res->label ? $langs->trans('unit'.$res->code) : $res->label;
3736 4220
 			    }
4221
+			    }
3737 4222
 
3738 4223
 				if ($selected == $res->rowid)
3739 4224
 				{
@@ -3772,8 +4257,12 @@  discard block
 block discarded – undo
3772 4257
 		$sql = "SELECT rowid, label, bank, clos as status, currency_code";
3773 4258
 		$sql .= " FROM ".MAIN_DB_PREFIX."bank_account";
3774 4259
 		$sql .= " WHERE entity IN (".getEntity('bank_account').")";
3775
-		if ($status != 2) $sql .= " AND clos = ".(int) $status;
3776
-		if ($filtre) $sql .= " AND ".$filtre;
4260
+		if ($status != 2) {
4261
+			$sql .= " AND clos = ".(int) $status;
4262
+		}
4263
+		if ($filtre) {
4264
+			$sql .= " AND ".$filtre;
4265
+		}
3777 4266
 		$sql .= " ORDER BY label";
3778 4267
 
3779 4268
 		dol_syslog(get_class($this)."::select_comptes", LOG_DEBUG);
@@ -3800,15 +4289,22 @@  discard block
 block discarded – undo
3800 4289
 						print '<option value="'.$obj->rowid.'">';
3801 4290
 					}
3802 4291
 					print trim($obj->label);
3803
-					if ($showcurrency) print ' ('.$obj->currency_code.')';
3804
-					if ($status == 2 && $obj->status == 1) print ' ('.$langs->trans("Closed").')';
4292
+					if ($showcurrency) {
4293
+						print ' ('.$obj->currency_code.')';
4294
+					}
4295
+					if ($status == 2 && $obj->status == 1) {
4296
+						print ' ('.$langs->trans("Closed").')';
4297
+					}
3805 4298
 					print '</option>';
3806 4299
 					$i++;
3807 4300
 				}
3808 4301
 				print "</select>";
3809 4302
 			} else {
3810
-				if ($status == 0) print '<span class="opacitymedium">'.$langs->trans("NoActiveBankAccountDefined").'</span>';
3811
-				else print '<span class="opacitymedium">'.$langs->trans("NoBankAccountFound").'</span>';
4303
+				if ($status == 0) {
4304
+					print '<span class="opacitymedium">'.$langs->trans("NoActiveBankAccountDefined").'</span>';
4305
+				} else {
4306
+					print '<span class="opacitymedium">'.$langs->trans("NoBankAccountFound").'</span>';
4307
+				}
3812 4308
 			}
3813 4309
 		} else {
3814 4310
 			dol_print_error($this->db);
@@ -3839,8 +4335,12 @@  discard block
 block discarded – undo
3839 4335
 		$sql = "SELECT rowid, name, fk_country, status, entity";
3840 4336
 		$sql .= " FROM ".MAIN_DB_PREFIX."establishment";
3841 4337
 		$sql .= " WHERE 1=1";
3842
-		if ($status != 2) $sql .= " AND status = ".(int) $status;
3843
-		if ($filtre) $sql .= " AND ".$filtre;
4338
+		if ($status != 2) {
4339
+			$sql .= " AND status = ".(int) $status;
4340
+		}
4341
+		if ($filtre) {
4342
+			$sql .= " AND ".$filtre;
4343
+		}
3844 4344
 		$sql .= " ORDER BY name";
3845 4345
 
3846 4346
 		dol_syslog(get_class($this)."::select_establishment", LOG_DEBUG);
@@ -3867,14 +4367,19 @@  discard block
 block discarded – undo
3867 4367
 						print '<option value="'.$obj->rowid.'">';
3868 4368
 					}
3869 4369
 					print trim($obj->name);
3870
-					if ($status == 2 && $obj->status == 1) print ' ('.$langs->trans("Closed").')';
4370
+					if ($status == 2 && $obj->status == 1) {
4371
+						print ' ('.$langs->trans("Closed").')';
4372
+					}
3871 4373
 					print '</option>';
3872 4374
 					$i++;
3873 4375
 				}
3874 4376
 				print "</select>";
3875 4377
 			} else {
3876
-				if ($status == 0) print '<span class="opacitymedium">'.$langs->trans("NoActiveEstablishmentDefined").'</span>';
3877
-				else print '<span class="opacitymedium">'.$langs->trans("NoEstablishmentFound").'</span>';
4378
+				if ($status == 0) {
4379
+					print '<span class="opacitymedium">'.$langs->trans("NoActiveEstablishmentDefined").'</span>';
4380
+				} else {
4381
+					print '<span class="opacitymedium">'.$langs->trans("NoEstablishmentFound").'</span>';
4382
+				}
3878 4383
 			}
3879 4384
 		} else {
3880 4385
 			dol_print_error($this->db);
@@ -3898,7 +4403,9 @@  discard block
 block discarded – undo
3898 4403
 			print '<input type="hidden" name="action" value="setbankaccount">';
3899 4404
 			print '<input type="hidden" name="token" value="'.newToken().'">';
3900 4405
 			$nbaccountfound = $this->select_comptes($selected, $htmlname, 0, '', $addempty);
3901
-			if ($nbaccountfound > 0) print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
4406
+			if ($nbaccountfound > 0) {
4407
+				print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
4408
+			}
3902 4409
 			print '</form>';
3903 4410
 		} else {
3904 4411
 			$langs->load('banks');
@@ -3907,7 +4414,9 @@  discard block
 block discarded – undo
3907 4414
 				require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
3908 4415
 				$bankstatic = new Account($this->db);
3909 4416
 				$result = $bankstatic->fetch($selected);
3910
-				if ($result) print $bankstatic->getNomUrl(1);
4417
+				if ($result) {
4418
+					print $bankstatic->getNomUrl(1);
4419
+				}
3911 4420
 			} else {
3912 4421
 				print "&nbsp;";
3913 4422
 			}
@@ -3963,11 +4472,15 @@  discard block
 block discarded – undo
3963 4472
 				while ($i < $num)
3964 4473
 				{
3965 4474
 					$objp = $this->db->fetch_object($result);
3966
-					if ($objp) $cate_arbo[$objp->rowid] = array('id'=>$objp->rowid, 'fulllabel'=>$objp->label);
4475
+					if ($objp) {
4476
+						$cate_arbo[$objp->rowid] = array('id'=>$objp->rowid, 'fulllabel'=>$objp->label);
4477
+					}
3967 4478
 					$i++;
3968 4479
 				}
3969 4480
 				$this->db->free($result);
3970
-			} else dol_print_error($this->db);
4481
+			} else {
4482
+				dol_print_error($this->db);
4483
+			}
3971 4484
 		} else {
3972 4485
 			$cat = new Categorie($this->db);
3973 4486
             $cate_arbo = $cat->get_full_arbo($type, $markafterid, $include);
@@ -3977,8 +4490,9 @@  discard block
 block discarded – undo
3977 4490
 		$outarray = array();
3978 4491
 		if (is_array($cate_arbo))
3979 4492
 		{
3980
-			if (!count($cate_arbo)) $output .= '<option value="-1" disabled>'.$langs->trans("NoCategoriesDefined").'</option>';
3981
-			else {
4493
+			if (!count($cate_arbo)) {
4494
+				$output .= '<option value="-1" disabled>'.$langs->trans("NoCategoriesDefined").'</option>';
4495
+			} else {
3982 4496
 				$output .= '<option value="-1">&nbsp;</option>';
3983 4497
 				foreach ($cate_arbo as $key => $value)
3984 4498
 				{
@@ -3997,7 +4511,9 @@  discard block
 block discarded – undo
3997 4511
 		$output .= '</select>';
3998 4512
 		$output .= "\n";
3999 4513
 
4000
-		if ($outputmode) return $outarray;
4514
+		if ($outputmode) {
4515
+			return $outarray;
4516
+		}
4001 4517
 		return $output;
4002 4518
 	}
4003 4519
 
@@ -4060,7 +4576,9 @@  discard block
 block discarded – undo
4060 4576
 
4061 4577
 		// Clean parameters
4062 4578
 		$newselectedchoice = empty($selectedchoice) ? "no" : $selectedchoice;
4063
-		if ($conf->browser->layout == 'phone') $width = '95%';
4579
+		if ($conf->browser->layout == 'phone') {
4580
+			$width = '95%';
4581
+		}
4064 4582
 
4065 4583
 		// Set height automatically if not defined
4066 4584
 		if (empty($height)) {
@@ -4104,7 +4622,9 @@  discard block
 block discarded – undo
4104 4622
 					} elseif ($input['type'] == 'select')
4105 4623
 					{
4106 4624
 						$more .= '<div class="tagtr"><div class="tagtd'.(empty($input['tdclass']) ? '' : (' '.$input['tdclass'])).'">';
4107
-						if (!empty($input['label'])) $more .= $input['label'].'</div><div class="tagtd left">';
4625
+						if (!empty($input['label'])) {
4626
+							$more .= $input['label'].'</div><div class="tagtd left">';
4627
+						}
4108 4628
 						$more .= $this->selectarray($input['name'], $input['values'], $input['default'], 1, 0, 0, $moreattr, 0, 0, 0, '', $morecss);
4109 4629
 						$more .= '</div></div>'."\n";
4110 4630
 					} elseif ($input['type'] == 'checkbox')
@@ -4112,9 +4632,15 @@  discard block
 block discarded – undo
4112 4632
 						$more .= '<div class="tagtr">';
4113 4633
 						$more .= '<div class="tagtd'.(empty($input['tdclass']) ? '' : (' '.$input['tdclass'])).'">'.$input['label'].' </div><div class="tagtd">';
4114 4634
 						$more .= '<input type="checkbox" class="flat'.$morecss.'" id="'.$input['name'].'" name="'.$input['name'].'"'.$moreattr;
4115
-						if (!is_bool($input['value']) && $input['value'] != 'false' && $input['value'] != '0') $more .= ' checked';
4116
-						if (is_bool($input['value']) && $input['value']) $more .= ' checked';
4117
-						if (isset($input['disabled'])) $more .= ' disabled';
4635
+						if (!is_bool($input['value']) && $input['value'] != 'false' && $input['value'] != '0') {
4636
+							$more .= ' checked';
4637
+						}
4638
+						if (is_bool($input['value']) && $input['value']) {
4639
+							$more .= ' checked';
4640
+						}
4641
+						if (isset($input['disabled'])) {
4642
+							$more .= ' disabled';
4643
+						}
4118 4644
 						$more .= ' /></div>';
4119 4645
 						$more .= '</div>'."\n";
4120 4646
 					} elseif ($input['type'] == 'radio')
@@ -4123,10 +4649,15 @@  discard block
 block discarded – undo
4123 4649
 						foreach ($input['values'] as $selkey => $selval)
4124 4650
 						{
4125 4651
 							$more .= '<div class="tagtr">';
4126
-							if ($i == 0) $more .= '<div class="tagtd'.(empty($input['tdclass']) ? ' tdtop' : (' tdtop '.$input['tdclass'])).'">'.$input['label'].'</div>';
4127
-							else $more .= '<div clas="tagtd'.(empty($input['tdclass']) ? '' : (' "'.$input['tdclass'])).'">&nbsp;</div>';
4652
+							if ($i == 0) {
4653
+								$more .= '<div class="tagtd'.(empty($input['tdclass']) ? ' tdtop' : (' tdtop '.$input['tdclass'])).'">'.$input['label'].'</div>';
4654
+							} else {
4655
+								$more .= '<div clas="tagtd'.(empty($input['tdclass']) ? '' : (' "'.$input['tdclass'])).'">&nbsp;</div>';
4656
+							}
4128 4657
 							$more .= '<div class="tagtd"><input type="radio" class="flat'.$morecss.'" id="'.$input['name'].'" name="'.$input['name'].'" value="'.$selkey.'"'.$moreattr;
4129
-							if ($input['disabled']) $more .= ' disabled';
4658
+							if ($input['disabled']) {
4659
+								$more .= ' disabled';
4660
+							}
4130 4661
 							$more .= ' /> ';
4131 4662
 							$more .= $selval;
4132 4663
 							$more .= '</div></div>'."\n";
@@ -4146,7 +4677,9 @@  discard block
 block discarded – undo
4146 4677
 					} elseif ($input['type'] == 'other')
4147 4678
 					{
4148 4679
 						$more .= '<div class="tagtr"><div class="tagtd'.(empty($input['tdclass']) ? '' : (' '.$input['tdclass'])).'">';
4149
-						if (!empty($input['label'])) $more .= $input['label'].'</div><div class="tagtd">';
4680
+						if (!empty($input['label'])) {
4681
+							$more .= $input['label'].'</div><div class="tagtd">';
4682
+						}
4150 4683
 						$more .= $input['value'];
4151 4684
 						$more .= '</div></div>'."\n";
4152 4685
 					} elseif ($input['type'] == 'onecolumn')
@@ -4164,8 +4697,12 @@  discard block
 block discarded – undo
4164 4697
 		// JQUI method dialog is broken with jmobile, we use standard HTML.
4165 4698
 		// Note: When using dol_use_jmobile or no js, you must also check code for button use a GET url with action=xxx and check that you also output the confirm code when action=xxx
4166 4699
 		// See page product/card.php for example
4167
-		if (!empty($conf->dol_use_jmobile)) $useajax = 0;
4168
-		if (empty($conf->use_javascript_ajax)) $useajax = 0;
4700
+		if (!empty($conf->dol_use_jmobile)) {
4701
+			$useajax = 0;
4702
+		}
4703
+		if (empty($conf->use_javascript_ajax)) {
4704
+			$useajax = 0;
4705
+		}
4169 4706
 
4170 4707
 		if ($useajax)
4171 4708
 		{
@@ -4187,8 +4724,12 @@  discard block
 block discarded – undo
4187 4724
 				foreach ($formquestion as $key => $input)
4188 4725
 				{
4189 4726
 					//print "xx ".$key." rr ".is_array($input)."<br>\n";
4190
-					if (is_array($input) && isset($input['name'])) array_push($inputok, $input['name']);
4191
-					if (isset($input['inputko']) && $input['inputko'] == 1) array_push($inputko, $input['name']);
4727
+					if (is_array($input) && isset($input['name'])) {
4728
+						array_push($inputok, $input['name']);
4729
+					}
4730
+					if (isset($input['inputko']) && $input['inputko'] == 1) {
4731
+						array_push($inputko, $input['name']);
4732
+					}
4192 4733
 				}
4193 4734
 			}
4194 4735
 			// Show JQuery confirm box.
@@ -4277,7 +4818,9 @@  discard block
 block discarded – undo
4277 4818
 		} else {
4278 4819
 			$formconfirm .= "\n<!-- begin formconfirm page=".$page." -->\n";
4279 4820
 
4280
-			if (empty($disableformtag)) $formconfirm .= '<form method="POST" action="'.$page.'" class="notoptoleftroright">'."\n";
4821
+			if (empty($disableformtag)) {
4822
+				$formconfirm .= '<form method="POST" action="'.$page.'" class="notoptoleftroright">'."\n";
4823
+			}
4281 4824
 
4282 4825
 			$formconfirm .= '<input type="hidden" name="action" value="'.$action.'">'."\n";
4283 4826
 			$formconfirm .= '<input type="hidden" name="token" value="'.newToken().'">'."\n";
@@ -4311,7 +4854,9 @@  discard block
 block discarded – undo
4311 4854
 
4312 4855
 			$formconfirm .= '</table>'."\n";
4313 4856
 
4314
-			if (empty($disableformtag)) $formconfirm .= "</form>\n";
4857
+			if (empty($disableformtag)) {
4858
+				$formconfirm .= "</form>\n";
4859
+			}
4315 4860
 			$formconfirm .= '<br>';
4316 4861
 
4317 4862
 			$formconfirm .= "<!-- end formconfirm -->\n";
@@ -4514,11 +5059,16 @@  discard block
 block discarded – undo
4514 5059
 			$ret .= '<td class="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
4515 5060
 			$ret .= '</tr></table></form>';
4516 5061
 		} else {
4517
-			if ($displayhour) $ret .= dol_print_date($selected, 'dayhour');
4518
-			else $ret .= dol_print_date($selected, 'day');
5062
+			if ($displayhour) {
5063
+				$ret .= dol_print_date($selected, 'dayhour');
5064
+			} else {
5065
+				$ret .= dol_print_date($selected, 'day');
5066
+			}
4519 5067
 		}
4520 5068
 
4521
-		if (empty($nooutput)) print $ret;
5069
+		if (empty($nooutput)) {
5070
+			print $ret;
5071
+		}
4522 5072
 		return $ret;
4523 5073
 	}
4524 5074
 
@@ -4654,7 +5204,9 @@  discard block
 block discarded – undo
4654 5204
 			if (!empty($rate))
4655 5205
 			{
4656 5206
 				print price($rate, 1, $langs, 1, 0);
4657
-				if ($currency && $rate != 1) print ' &nbsp; ('.price($rate, 1, $langs, 1, 0).' '.$currency.' = 1 '.$conf->currency.')';
5207
+				if ($currency && $rate != 1) {
5208
+					print ' &nbsp; ('.price($rate, 1, $langs, 1, 0).' '.$currency.' = 1 '.$conf->currency.')';
5209
+				}
4658 5210
 			} else {
4659 5211
 				print 1;
4660 5212
 			}
@@ -4691,24 +5243,42 @@  discard block
 block discarded – undo
4691 5243
 			if (!empty($discount_type)) {
4692 5244
 				if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS))
4693 5245
 				{
4694
-					if (!$filter || $filter == "fk_invoice_supplier_source IS NULL") $translationKey = 'HasAbsoluteDiscountFromSupplier'; // If we want deposit to be substracted to payments only and not to total of final invoice
4695
-					else $translationKey = 'HasCreditNoteFromSupplier';
5246
+					if (!$filter || $filter == "fk_invoice_supplier_source IS NULL") {
5247
+						$translationKey = 'HasAbsoluteDiscountFromSupplier';
5248
+					}
5249
+					// If we want deposit to be substracted to payments only and not to total of final invoice
5250
+					else {
5251
+						$translationKey = 'HasCreditNoteFromSupplier';
5252
+					}
4696 5253
 				} else {
4697
-					if (!$filter || $filter == "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") $translationKey = 'HasAbsoluteDiscountFromSupplier';
4698
-					else $translationKey = 'HasCreditNoteFromSupplier';
5254
+					if (!$filter || $filter == "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
5255
+						$translationKey = 'HasAbsoluteDiscountFromSupplier';
5256
+					} else {
5257
+						$translationKey = 'HasCreditNoteFromSupplier';
5258
+					}
4699 5259
 				}
4700 5260
 			} else {
4701 5261
 				if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS))
4702 5262
 				{
4703
-					if (!$filter || $filter == "fk_facture_source IS NULL") $translationKey = 'CompanyHasAbsoluteDiscount'; // If we want deposit to be substracted to payments only and not to total of final invoice
4704
-					else $translationKey = 'CompanyHasCreditNote';
5263
+					if (!$filter || $filter == "fk_facture_source IS NULL") {
5264
+						$translationKey = 'CompanyHasAbsoluteDiscount';
5265
+					}
5266
+					// If we want deposit to be substracted to payments only and not to total of final invoice
5267
+					else {
5268
+						$translationKey = 'CompanyHasCreditNote';
5269
+					}
4705 5270
 				} else {
4706
-					if (!$filter || $filter == "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") $translationKey = 'CompanyHasAbsoluteDiscount';
4707
-					else $translationKey = 'CompanyHasCreditNote';
5271
+					if (!$filter || $filter == "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
5272
+						$translationKey = 'CompanyHasAbsoluteDiscount';
5273
+					} else {
5274
+						$translationKey = 'CompanyHasCreditNote';
5275
+					}
4708 5276
 				}
4709 5277
 			}
4710 5278
 			print $langs->trans($translationKey, price($amount, 0, $langs, 0, 0, -1, $conf->currency));
4711
-			if (empty($hidelist)) print ': ';
5279
+			if (empty($hidelist)) {
5280
+				print ': ';
5281
+			}
4712 5282
 			print '</div>';
4713 5283
 			if (empty($hidelist))
4714 5284
 			{
@@ -4719,15 +5289,19 @@  discard block
 block discarded – undo
4719 5289
 				} else {
4720 5290
 					$newfilter .= ' AND fk_facture IS NULL AND fk_facture_line IS NULL'; // Customer discounts available
4721 5291
 				}
4722
-				if ($filter) $newfilter .= ' AND ('.$filter.')';
5292
+				if ($filter) {
5293
+					$newfilter .= ' AND ('.$filter.')';
5294
+				}
4723 5295
 				$nbqualifiedlines = $this->select_remises($selected, $htmlname, $newfilter, $socid, $maxvalue);
4724 5296
 				if ($nbqualifiedlines > 0)
4725 5297
 				{
4726 5298
 					print ' &nbsp; <input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("UseLine")).'"';
4727
-					if (!empty($discount_type) && $filter && $filter != "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')")
4728
-						print ' title="'.$langs->trans("UseCreditNoteInInvoicePayment").'"';
4729
-					if (empty($discount_type) && $filter && $filter != "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')")
4730
-						print ' title="'.$langs->trans("UseCreditNoteInInvoicePayment").'"';
5299
+					if (!empty($discount_type) && $filter && $filter != "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") {
5300
+											print ' title="'.$langs->trans("UseCreditNoteInInvoicePayment").'"';
5301
+					}
5302
+					if (empty($discount_type) && $filter && $filter != "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") {
5303
+											print ' title="'.$langs->trans("UseCreditNoteInInvoicePayment").'"';
5304
+					}
4731 5305
 
4732 5306
 					print '>';
4733 5307
 				}
@@ -4836,8 +5410,11 @@  discard block
 block discarded – undo
4836 5410
 			}
4837 5411
 		}
4838 5412
 
4839
-		if ($nooutput) return $out;
4840
-		else print $out;
5413
+		if ($nooutput) {
5414
+			return $out;
5415
+		} else {
5416
+			print $out;
5417
+		}
4841 5418
 	}
4842 5419
 
4843 5420
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
@@ -4871,7 +5448,10 @@  discard block
 block discarded – undo
4871 5448
 
4872 5449
 		$out = '';
4873 5450
 
4874
-		if ($selected == 'euro' || $selected == 'euros') $selected = 'EUR'; // Pour compatibilite
5451
+		if ($selected == 'euro' || $selected == 'euros') {
5452
+			$selected = 'EUR';
5453
+		}
5454
+		// Pour compatibilite
4875 5455
 
4876 5456
 		$out .= '<select class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'" id="'.$htmlname.'">';
4877 5457
 		foreach ($langs->cache_currencies as $code_iso => $currency)
@@ -4892,7 +5472,9 @@  discard block
 block discarded – undo
4892 5472
 			$out .= '</option>';
4893 5473
 		}
4894 5474
 		$out .= '</select>';
4895
-		if ($user->admin) $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5475
+		if ($user->admin) {
5476
+			$out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
5477
+		}
4896 5478
 
4897 5479
 		// Make select dynamic
4898 5480
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
@@ -4922,12 +5504,16 @@  discard block
 block discarded – undo
4922 5504
 		$resql = $db->query($sql);
4923 5505
 		if ($resql)
4924 5506
 		{
4925
-			while ($obj = $db->fetch_object($resql)) $TCurrency[$obj->code] = $obj->code;
5507
+			while ($obj = $db->fetch_object($resql)) {
5508
+				$TCurrency[$obj->code] = $obj->code;
5509
+			}
4926 5510
 		}
4927 5511
 
4928 5512
 		$out = '';
4929 5513
 		$out .= '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
4930
-		if ($useempty) $out .= '<option value="">&nbsp;</option>';
5514
+		if ($useempty) {
5515
+			$out .= '<option value="">&nbsp;</option>';
5516
+		}
4931 5517
 		// If company current currency not in table, we add it into list. Should always be available.
4932 5518
 		if (!in_array($conf->currency, $TCurrency))
4933 5519
 		{
@@ -4939,8 +5525,11 @@  discard block
 block discarded – undo
4939 5525
 			{
4940 5526
 				if (isset($TCurrency[$code_iso]))
4941 5527
 				{
4942
-					if (!empty($selected) && $selected == $code_iso) $out .= '<option value="'.$code_iso.'" selected="selected">';
4943
-					else $out .= '<option value="'.$code_iso.'">';
5528
+					if (!empty($selected) && $selected == $code_iso) {
5529
+						$out .= '<option value="'.$code_iso.'" selected="selected">';
5530
+					} else {
5531
+						$out .= '<option value="'.$code_iso.'">';
5532
+					}
4944 5533
 
4945 5534
 					$out .= $currency['label'];
4946 5535
 					$out .= ' ('.$langs->getCurrencySymbol($code_iso).')';
@@ -4970,7 +5559,10 @@  discard block
 block discarded – undo
4970 5559
 		global $langs;
4971 5560
 
4972 5561
 		$num = count($this->cache_vatrates);
4973
-		if ($num > 0) return $num; // Cache already loaded
5562
+		if ($num > 0) {
5563
+			return $num;
5564
+		}
5565
+		// Cache already loaded
4974 5566
 
4975 5567
 		dol_syslog(__METHOD__, LOG_DEBUG);
4976 5568
 
@@ -5002,10 +5594,18 @@  discard block
 block discarded – undo
5002 5594
 					$this->cache_vatrates[$i]['label'] = $obj->taux.'%'.($obj->code ? ' ('.$obj->code.')' : ''); // Label must contains only 0-9 , . % or *
5003 5595
 					$this->cache_vatrates[$i]['labelallrates'] = $obj->taux.'/'.($obj->localtax1 ? $obj->localtax1 : '0').'/'.($obj->localtax2 ? $obj->localtax2 : '0').($obj->code ? ' ('.$obj->code.')' : ''); // Must never be used as key, only label
5004 5596
 					$positiverates = '';
5005
-					if ($obj->taux) $positiverates .= ($positiverates ? '/' : '').$obj->taux;
5006
-					if ($obj->localtax1) $positiverates .= ($positiverates ? '/' : '').$obj->localtax1;
5007
-					if ($obj->localtax2) $positiverates .= ($positiverates ? '/' : '').$obj->localtax2;
5008
-					if (empty($positiverates)) $positiverates = '0';
5597
+					if ($obj->taux) {
5598
+						$positiverates .= ($positiverates ? '/' : '').$obj->taux;
5599
+					}
5600
+					if ($obj->localtax1) {
5601
+						$positiverates .= ($positiverates ? '/' : '').$obj->localtax1;
5602
+					}
5603
+					if ($obj->localtax2) {
5604
+						$positiverates .= ($positiverates ? '/' : '').$obj->localtax2;
5605
+					}
5606
+					if (empty($positiverates)) {
5607
+						$positiverates = '0';
5608
+					}
5009 5609
 					$this->cache_vatrates[$i]['labelpositiverates'] = $positiverates.($obj->code ? ' ('.$obj->code.')' : ''); // Must never be used as key, only label
5010 5610
 				}
5011 5611
 
@@ -5087,28 +5687,36 @@  discard block
 block discarded – undo
5087 5687
 		} else {
5088 5688
 			$code_country = "'".$mysoc->country_code."'"; // Pour compatibilite ascendente
5089 5689
 		}
5090
-		if (!empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC))    // If option to have vat for end customer for services is on
5690
+		if (!empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC)) {
5691
+			// If option to have vat for end customer for services is on
5091 5692
 		{
5092 5693
 			require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
5694
+		}
5093 5695
 			if (!isInEEC($societe_vendeuse) && (!is_object($societe_acheteuse) || (isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany())))
5094 5696
 			{
5095 5697
 				// We also add the buyer
5096 5698
 				if (is_numeric($type))
5097 5699
 				{
5098
-					if ($type == 1) // We know product is a service
5700
+					if ($type == 1) {
5701
+						// We know product is a service
5099 5702
 					{
5100 5703
 						$code_country .= ",'".$societe_acheteuse->country_code."'";
5101 5704
 					}
5102
-				} elseif (!$idprod)  // We don't know type of product
5705
+					}
5706
+				} elseif (!$idprod) {
5707
+					// We don't know type of product
5103 5708
 				{
5104 5709
 					$code_country .= ",'".$societe_acheteuse->country_code."'";
5710
+				}
5105 5711
 				} else {
5106 5712
 					$prodstatic = new Product($this->db);
5107 5713
 					$prodstatic->fetch($idprod);
5108
-					if ($prodstatic->type == Product::TYPE_SERVICE)   // We know product is a service
5714
+					if ($prodstatic->type == Product::TYPE_SERVICE) {
5715
+						// We know product is a service
5109 5716
 					{
5110 5717
 						$code_country .= ",'".$societe_acheteuse->country_code."'";
5111 5718
 					}
5719
+					}
5112 5720
 				}
5113 5721
 			}
5114 5722
 		}
@@ -5128,15 +5736,20 @@  discard block
 block discarded – undo
5128 5736
 			        $defaultcode = $reg[1];
5129 5737
 			        $defaulttx = preg_replace('/\s*\(.*\)/', '', $defaulttx);
5130 5738
 		        }
5131
-				if (empty($defaulttx)) $defaultnpr = 0;
5739
+				if (empty($defaulttx)) {
5740
+					$defaultnpr = 0;
5741
+				}
5132 5742
 			}
5133 5743
 
5134 5744
 			// Si taux par defaut n'a pu etre determine, on prend dernier de la liste.
5135 5745
 			// Comme ils sont tries par ordre croissant, dernier = plus eleve = taux courant
5136 5746
 			if ($defaulttx < 0 || dol_strlen($defaulttx) == 0)
5137 5747
 			{
5138
-				if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS)) $defaulttx = $this->cache_vatrates[$num - 1]['txtva'];
5139
-				else $defaulttx = ($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS == 'none' ? '' : $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS);
5748
+				if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS)) {
5749
+					$defaulttx = $this->cache_vatrates[$num - 1]['txtva'];
5750
+				} else {
5751
+					$defaulttx = ($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS == 'none' ? '' : $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS);
5752
+				}
5140 5753
 			}
5141 5754
 
5142 5755
 			// Disabled if seller is not subject to VAT
@@ -5152,28 +5765,38 @@  discard block
 block discarded – undo
5152 5765
 				}
5153 5766
 			}
5154 5767
 
5155
-			if (!$options_only) $return .= '<select class="flat minwidth75imp" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled ? ' disabled' : '').$title.'>';
5768
+			if (!$options_only) {
5769
+				$return .= '<select class="flat minwidth75imp" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled ? ' disabled' : '').$title.'>';
5770
+			}
5156 5771
 
5157 5772
 			$selectedfound = false;
5158 5773
 			foreach ($this->cache_vatrates as $rate)
5159 5774
 			{
5160 5775
 				// Keep only 0 if seller is not subject to VAT
5161
-				if ($disabled && $rate['txtva'] != 0) continue;
5776
+				if ($disabled && $rate['txtva'] != 0) {
5777
+					continue;
5778
+				}
5162 5779
 
5163 5780
 				// Define key to use into select list
5164 5781
 				$key = $rate['txtva'];
5165 5782
 				$key .= $rate['nprtva'] ? '*' : '';
5166
-				if ($mode > 0 && $rate['code']) $key .= ' ('.$rate['code'].')';
5167
-				if ($mode < 0) $key = $rate['rowid'];
5783
+				if ($mode > 0 && $rate['code']) {
5784
+					$key .= ' ('.$rate['code'].')';
5785
+				}
5786
+				if ($mode < 0) {
5787
+					$key = $rate['rowid'];
5788
+				}
5168 5789
 
5169 5790
 				$return .= '<option value="'.$key.'"';
5170 5791
 				if (!$selectedfound)
5171 5792
 				{
5172
-					if ($defaultcode) // If defaultcode is defined, we used it in priority to select combo option instead of using rate+npr flag
5793
+					if ($defaultcode) {
5794
+						// If defaultcode is defined, we used it in priority to select combo option instead of using rate+npr flag
5173 5795
 					{
5174 5796
 						if ($defaultcode == $rate['code'])
5175 5797
 						{
5176 5798
 							$return .= ' selected';
5799
+					}
5177 5800
 							$selectedfound = true;
5178 5801
 						}
5179 5802
 					} elseif ($rate['txtva'] == $defaulttx && $rate['nprtva'] == $defaultnpr)
@@ -5196,7 +5819,9 @@  discard block
 block discarded – undo
5196 5819
 				$return .= '</option>';
5197 5820
 			}
5198 5821
 
5199
-			if (!$options_only) $return .= '</select>';
5822
+			if (!$options_only) {
5823
+				$return .= '</select>';
5824
+			}
5200 5825
 		} else {
5201 5826
 			$return .= $this->error;
5202 5827
 		}
@@ -5295,12 +5920,20 @@  discard block
 block discarded – undo
5295 5920
 
5296 5921
 		$retstring = '';
5297 5922
 
5298
-		if ($prefix == '') $prefix = 're';
5299
-		if ($h == '') $h = 0;
5300
-		if ($m == '') $m = 0;
5923
+		if ($prefix == '') {
5924
+			$prefix = 're';
5925
+		}
5926
+		if ($h == '') {
5927
+			$h = 0;
5928
+		}
5929
+		if ($m == '') {
5930
+			$m = 0;
5931
+		}
5301 5932
 		$emptydate = 0;
5302 5933
 		$emptyhours = 0;
5303
-        if ($stepminutes <= 0 || $stepminutes > 30) $stepminutes = 1;
5934
+        if ($stepminutes <= 0 || $stepminutes > 30) {
5935
+        	$stepminutes = 1;
5936
+        }
5304 5937
 		if ($empty == 1) { $emptydate = 1; $emptyhours = 1; }
5305 5938
 		if ($empty == 2) { $emptydate = 0; $emptyhours = 1; }
5306 5939
 		$orig_set_time = $set_time;
@@ -5312,10 +5945,12 @@  discard block
 block discarded – undo
5312 5945
 		}
5313 5946
 
5314 5947
 		// Analysis of the pre-selection date
5315
-		if (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', $set_time, $reg))	// deprecated usage
5948
+		if (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/', $set_time, $reg)) {
5949
+			// deprecated usage
5316 5950
 		{
5317 5951
 			// Date format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'
5318 5952
 			$syear	= (!empty($reg[1]) ? $reg[1] : '');
5953
+		}
5319 5954
 			$smonth = (!empty($reg[2]) ? $reg[2] : '');
5320 5955
 			$sday	= (!empty($reg[3]) ? $reg[3] : '');
5321 5956
 			$shour	= (!empty($reg[4]) ? $reg[4] : '');
@@ -5345,8 +5980,12 @@  discard block
 block discarded – undo
5345 5980
 			$smin = !isset($conf->global->MAIN_DEFAULT_DATE_MIN) ? ($h == -1 ? '59' : '') : $conf->global->MAIN_DEFAULT_DATE_MIN;
5346 5981
 			$ssec = !isset($conf->global->MAIN_DEFAULT_DATE_SEC) ? ($h == -1 ? '59' : '') : $conf->global->MAIN_DEFAULT_DATE_SEC;
5347 5982
 		}
5348
-		if ($h == 3) $shour = '';
5349
-		if ($m == 3) $smin = '';
5983
+		if ($h == 3) {
5984
+			$shour = '';
5985
+		}
5986
+		if ($m == 3) {
5987
+			$smin = '';
5988
+		}
5350 5989
 
5351 5990
 		// You can set MAIN_POPUP_CALENDAR to 'eldy' or 'jquery'
5352 5991
 		$usecalendar = 'combo';
@@ -5383,7 +6022,9 @@  discard block
 block discarded – undo
5383 6022
 						$base = DOL_URL_ROOT.'/core/';
5384 6023
 						$retstring .= ' onClick="showDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput").'\',\''.$langs->defaultlang.'\');"';
5385 6024
 						$retstring .= '>'.img_object($langs->trans("SelectDate"), 'calendarday', 'class="datecallink"').'</button>';
5386
-					} else $retstring .= '<button id="'.$prefix.'Button" type="button" class="dpInvisibleButtons">'.img_object($langs->trans("Disabled"), 'calendarday', 'class="datecallink"').'</button>';
6025
+					} else {
6026
+						$retstring .= '<button id="'.$prefix.'Button" type="button" class="dpInvisibleButtons">'.img_object($langs->trans("Disabled"), 'calendarday', 'class="datecallink"').'</button>';
6027
+					}
5387 6028
 
5388 6029
 					$retstring .= '<input type="hidden" id="'.$prefix.'day"   name="'.$prefix.'day"   value="'.$sday.'">'."\n";
5389 6030
 					$retstring .= '<input type="hidden" id="'.$prefix.'month" name="'.$prefix.'month" value="'.$smonth.'">'."\n";
@@ -5503,7 +6144,9 @@  discard block
 block discarded – undo
5503 6144
 			}
5504 6145
 		}
5505 6146
 
5506
-		if ($d && $h) $retstring .= ($h == 2 ? '<br>' : ' ');
6147
+		if ($d && $h) {
6148
+			$retstring .= ($h == 2 ? '<br>' : ' ');
6149
+		}
5507 6150
 
5508 6151
 		if ($h)
5509 6152
 		{
@@ -5513,28 +6156,40 @@  discard block
 block discarded – undo
5513 6156
 				$openinghours = explode(',', $openinghours);
5514 6157
 				$hourstart = $openinghours[0];
5515 6158
 				$hourend = $openinghours[1];
5516
-				if ($hourend < $hourstart) $hourend = $hourstart;
6159
+				if ($hourend < $hourstart) {
6160
+					$hourend = $hourstart;
6161
+				}
5517 6162
 			}
5518 6163
 			// Show hour
5519 6164
 			$retstring .= '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth50 '.($fullday ? $fullday.'hour' : '').'" id="'.$prefix.'hour" name="'.$prefix.'hour">';
5520
-			if ($emptyhours) $retstring .= '<option value="-1">&nbsp;</option>';
6165
+			if ($emptyhours) {
6166
+				$retstring .= '<option value="-1">&nbsp;</option>';
6167
+			}
5521 6168
 			for ($hour = $hourstart; $hour < $hourend; $hour++)
5522 6169
 			{
5523
-				if (strlen($hour) < 2) $hour = "0".$hour;
6170
+				if (strlen($hour) < 2) {
6171
+					$hour = "0".$hour;
6172
+				}
5524 6173
 				$retstring .= '<option value="'.$hour.'"'.(($hour == $shour) ? ' selected' : '').'>'.$hour.(empty($conf->dol_optimize_smallscreen) ? '' : 'H').'</option>';
5525 6174
 			}
5526 6175
 			$retstring .= '</select>';
5527
-			if ($m && empty($conf->dol_optimize_smallscreen)) $retstring .= ":";
6176
+			if ($m && empty($conf->dol_optimize_smallscreen)) {
6177
+				$retstring .= ":";
6178
+			}
5528 6179
 		}
5529 6180
 
5530 6181
 		if ($m)
5531 6182
 		{
5532 6183
 			// Show minutes
5533 6184
 			$retstring .= '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth50 '.($fullday ? $fullday.'min' : '').'" id="'.$prefix.'min" name="'.$prefix.'min">';
5534
-			if ($emptyhours) $retstring .= '<option value="-1">&nbsp;</option>';
6185
+			if ($emptyhours) {
6186
+				$retstring .= '<option value="-1">&nbsp;</option>';
6187
+			}
5535 6188
 			for ($min = 0; $min < 60; $min += $stepminutes)
5536 6189
 			{
5537
-				if (strlen($min) < 2) $min = "0".$min;
6190
+				if (strlen($min) < 2) {
6191
+					$min = "0".$min;
6192
+				}
5538 6193
 				$retstring .= '<option value="'.$min.'"'.(($min == $smin) ? ' selected' : '').'>'.$min.(empty($conf->dol_optimize_smallscreen) ? '' : '').'</option>';
5539 6194
 			}
5540 6195
 			$retstring .= '</select>';
@@ -5547,7 +6202,8 @@  discard block
 block discarded – undo
5547 6202
 		{
5548 6203
 			// Script which will be inserted in the onClick of the "Now" link
5549 6204
 			$reset_scripts = "";
5550
-            if ($addnowlink == 2) // local computer time
6205
+            if ($addnowlink == 2) {
6206
+            	// local computer time
5551 6207
             {
5552 6208
                 // pad add leading 0 on numbers
5553 6209
                 $reset_scripts .= "Number.prototype.pad = function(size) {
@@ -5557,11 +6213,14 @@  discard block
 block discarded – undo
5557 6213
                     };
5558 6214
                     var d = new Date();";
5559 6215
             }
6216
+            }
5560 6217
 
5561 6218
 			// Generate the date part, depending on the use or not of the javascript calendar
5562
-            if ($addnowlink == 1) // server time expressed in user time setup
6219
+            if ($addnowlink == 1) {
6220
+            	// server time expressed in user time setup
5563 6221
             {
5564 6222
                 $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date(dol_now(), 'day', 'tzuser').'\');';
6223
+            }
5565 6224
                 $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.dol_print_date(dol_now(), '%d', 'tzuser').'\');';
5566 6225
                 $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.dol_print_date(dol_now(), '%m', 'tzuser').'\');';
5567 6226
                 $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.dol_print_date(dol_now(), '%Y', 'tzuser').'\');';
@@ -5593,7 +6252,9 @@  discard block
 block discarded – undo
5593 6252
 			// Update the hour part
5594 6253
 			if ($h)
5595 6254
 			{
5596
-				if ($fullday) $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
6255
+				if ($fullday) {
6256
+					$reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
6257
+				}
5597 6258
 				//$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
5598 6259
                 if ($addnowlink == 1)
5599 6260
                 {
@@ -5603,12 +6264,16 @@  discard block
 block discarded – undo
5603 6264
                     $reset_scripts .= 'jQuery(\'#'.$prefix.'hour\').val(d.getHours().pad());';
5604 6265
                 }
5605 6266
 
5606
-				if ($fullday) $reset_scripts .= ' } ';
6267
+				if ($fullday) {
6268
+					$reset_scripts .= ' } ';
6269
+				}
5607 6270
 			}
5608 6271
 			// Update the minute part
5609 6272
 			if ($m)
5610 6273
 			{
5611
-				if ($fullday) $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
6274
+				if ($fullday) {
6275
+					$reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
6276
+				}
5612 6277
 				//$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
5613 6278
                 if ($addnowlink == 1)
5614 6279
                 {
@@ -5617,7 +6282,9 @@  discard block
 block discarded – undo
5617 6282
                 {
5618 6283
                     $reset_scripts .= 'jQuery(\'#'.$prefix.'min\').val(d.getMinutes().pad());';
5619 6284
                 }
5620
-				if ($fullday) $reset_scripts .= ' } ';
6285
+				if ($fullday) {
6286
+					$reset_scripts .= ' } ';
6287
+				}
5621 6288
 			}
5622 6289
 			// If reset_scripts is not empty, print the link with the reset_scripts in the onClick
5623 6290
 			if ($reset_scripts && empty($conf->dol_optimize_smallscreen))
@@ -5642,16 +6309,24 @@  discard block
 block discarded – undo
5642 6309
 			// Update the hour part
5643 6310
 			if ($h)
5644 6311
 			{
5645
-				if ($fullday) $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
6312
+				if ($fullday) {
6313
+					$reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
6314
+				}
5646 6315
 				$reset_scripts .= 'jQuery(\'#'.$prefix.'hour\').val(\''.dol_print_date(dol_now(), '%H').'\');';
5647
-				if ($fullday) $reset_scripts .= ' } ';
6316
+				if ($fullday) {
6317
+					$reset_scripts .= ' } ';
6318
+				}
5648 6319
 			}
5649 6320
 			// Update the minute part
5650 6321
 			if ($m)
5651 6322
 			{
5652
-				if ($fullday) $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
6323
+				if ($fullday) {
6324
+					$reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
6325
+				}
5653 6326
 				$reset_scripts .= 'jQuery(\'#'.$prefix.'min\').val(\''.dol_print_date(dol_now(), '%M').'\');';
5654
-				if ($fullday) $reset_scripts .= ' } ';
6327
+				if ($fullday) {
6328
+					$reset_scripts .= ' } ';
6329
+				}
5655 6330
 			}
5656 6331
 			// If reset_scripts is not empty, print the link with the reset_scripts in the onClick
5657 6332
 			if ($reset_scripts && empty($conf->dol_optimize_smallscreen))
@@ -5666,7 +6341,9 @@  discard block
 block discarded – undo
5666 6341
 		if ($conf->use_javascript_ajax && $adddateof)
5667 6342
 		{
5668 6343
 			$tmparray = dol_getdate($adddateof);
5669
-			if (empty($labeladddateof)) $labeladddateof = $langs->trans("DateInvoice");
6344
+			if (empty($labeladddateof)) {
6345
+				$labeladddateof = $langs->trans("DateInvoice");
6346
+			}
5670 6347
 			$retstring .= ' - <button class="dpInvisibleButtons datenowlink" id="dateofinvoice" type="button" name="_dateofinvoice" value="now" onclick="jQuery(\'#re\').val(\''.dol_print_date($adddateof, 'day').'\');jQuery(\'#reday\').val(\''.$tmparray['mday'].'\');jQuery(\'#remonth\').val(\''.$tmparray['mon'].'\');jQuery(\'#reyear\').val(\''.$tmparray['year'].'\');">'.$labeladddateof.'</a>';
5671 6348
 		}
5672 6349
 
@@ -5707,9 +6384,11 @@  discard block
 block discarded – undo
5707 6384
 
5708 6385
 		if ($typehour == 'select') {
5709 6386
 			$retstring .= '<select class="flat" id="select_'.$prefix.'hour" name="'.$prefix.'hour"'.($disabled ? ' disabled' : '').'>';
5710
-			for ($hour = 0; $hour < 25; $hour++)	// For a duration, we allow 24 hours
6387
+			for ($hour = 0; $hour < 25; $hour++) {
6388
+				// For a duration, we allow 24 hours
5711 6389
 			{
5712 6390
 				$retstring .= '<option value="'.$hour.'"';
6391
+			}
5713 6392
 				if ($hourSelected == $hour)
5714 6393
 				{
5715 6394
 					$retstring .= " selected";
@@ -5723,12 +6402,18 @@  discard block
 block discarded – undo
5723 6402
 			return 'BadValueForParameterTypeHour';
5724 6403
 		}
5725 6404
 
5726
-		if ($typehour != 'text') $retstring .= ' '.$langs->trans('HourShort');
5727
-		else $retstring .= '<span class="hideonsmartphone">:</span>';
6405
+		if ($typehour != 'text') {
6406
+			$retstring .= ' '.$langs->trans('HourShort');
6407
+		} else {
6408
+			$retstring .= '<span class="hideonsmartphone">:</span>';
6409
+		}
5728 6410
 
5729 6411
 		// Minutes
5730
-		if ($minunderhours) $retstring .= '<br>';
5731
-		else $retstring .= '<span class="hideonsmartphone">&nbsp;</span>';
6412
+		if ($minunderhours) {
6413
+			$retstring .= '<br>';
6414
+		} else {
6415
+			$retstring .= '<span class="hideonsmartphone">&nbsp;</span>';
6416
+		}
5732 6417
 
5733 6418
 		if ($typehour == 'select' || $typehour == 'textselect')
5734 6419
 		{
@@ -5736,7 +6421,9 @@  discard block
 block discarded – undo
5736 6421
 			for ($min = 0; $min <= 55; $min = $min + 5)
5737 6422
 			{
5738 6423
 				$retstring .= '<option value="'.$min.'"';
5739
-				if ($minSelected == $min) $retstring .= ' selected';
6424
+				if ($minSelected == $min) {
6425
+					$retstring .= ' selected';
6426
+				}
5740 6427
 				$retstring .= '>'.$min.'</option>';
5741 6428
 			}
5742 6429
 			$retstring .= "</select>";
@@ -5745,11 +6432,15 @@  discard block
 block discarded – undo
5745 6432
 			$retstring .= '<input placeholder="'.$langs->trans('MinuteShort').'" type="number" min="0" name="'.$prefix.'min"'.($disabled ? ' disabled' : '').' class="flat maxwidth50 inputminute" value="'.(($minSelected != '') ? ((int) $minSelected) : '').'">';
5746 6433
 		}
5747 6434
 
5748
-		if ($typehour != 'text') $retstring .= ' '.$langs->trans('MinuteShort');
6435
+		if ($typehour != 'text') {
6436
+			$retstring .= ' '.$langs->trans('MinuteShort');
6437
+		}
5749 6438
 
5750 6439
 		//$retstring.="&nbsp;";
5751 6440
 
5752
-		if (!empty($nooutput)) return $retstring;
6441
+		if (!empty($nooutput)) {
6442
+			return $retstring;
6443
+		}
5753 6444
 
5754 6445
 		print $retstring;
5755 6446
 		return;
@@ -5809,8 +6500,12 @@  discard block
 block discarded – undo
5809 6500
 
5810 6501
 		//var_dump($objecttmp->filter);
5811 6502
 		$prefixforautocompletemode = $objecttmp->element;
5812
-		if ($prefixforautocompletemode == 'societe') $prefixforautocompletemode = 'company';
5813
-		if ($prefixforautocompletemode == 'product') $prefixforautocompletemode = 'produit';
6503
+		if ($prefixforautocompletemode == 'societe') {
6504
+			$prefixforautocompletemode = 'company';
6505
+		}
6506
+		if ($prefixforautocompletemode == 'product') {
6507
+			$prefixforautocompletemode = 'produit';
6508
+		}
5814 6509
 		$confkeyforautocompletemode = strtoupper($prefixforautocompletemode).'_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT
5815 6510
 
5816 6511
 		dol_syslog(get_class($this)."::selectForForms object->filter=".$objecttmp->filter, LOG_DEBUG);
@@ -5834,7 +6529,9 @@  discard block
 block discarded – undo
5834 6529
 			// Activate the auto complete using ajax call.
5835 6530
 			$out .= ajax_autocompleter($preselectedvalue, $htmlname, $urlforajaxcall, $urloption, $conf->global->$confkeyforautocompletemode, 0, array());
5836 6531
 			$out .= '<style type="text/css">.ui-autocomplete { z-index: 250; }</style>';
5837
-			if ($placeholder) $placeholder = ' placeholder="'.$placeholder.'"';
6532
+			if ($placeholder) {
6533
+				$placeholder = ' placeholder="'.$placeholder.'"';
6534
+			}
5838 6535
 			$out .= '<input type="text" class="'.$morecss.'"'.($disabled ? ' disabled="disabled"' : '').' name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' />';
5839 6536
 		} else {
5840 6537
 			// Immediate load of table record. Note: filter is inside $objecttmp->filter
@@ -5855,9 +6552,13 @@  discard block
 block discarded – undo
5855 6552
 		global $db;
5856 6553
 
5857 6554
 		//dol_syslog("Convert matches ".$matches[1]);
5858
-		if (empty($matches[1])) return '';
6555
+		if (empty($matches[1])) {
6556
+			return '';
6557
+		}
5859 6558
 		$tmp = explode(':', $matches[1]);
5860
-		if (count($tmp) < 3) return '';
6559
+		if (count($tmp) < 3) {
6560
+			return '';
6561
+		}
5861 6562
 
5862 6563
 		$tmpescaped = $tmp[2];
5863 6564
 		$regbis = array();
@@ -5895,17 +6596,25 @@  discard block
 block discarded – undo
5895 6596
 		//print "$objecttmp->filter, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled";
5896 6597
 
5897 6598
 		$prefixforautocompletemode = $objecttmp->element;
5898
-		if ($prefixforautocompletemode == 'societe') $prefixforautocompletemode = 'company';
6599
+		if ($prefixforautocompletemode == 'societe') {
6600
+			$prefixforautocompletemode = 'company';
6601
+		}
5899 6602
 		$confkeyforautocompletemode = strtoupper($prefixforautocompletemode).'_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT
5900 6603
 
5901
-		if (!empty($objecttmp->fields))	// For object that declare it, it is better to use declared fields (like societe, contact, ...)
6604
+		if (!empty($objecttmp->fields)) {
6605
+			// For object that declare it, it is better to use declared fields (like societe, contact, ...)
5902 6606
 		{
5903 6607
 			$tmpfieldstoshow = '';
6608
+		}
5904 6609
 			foreach ($objecttmp->fields as $key => $val)
5905 6610
 			{
5906
-				if ($val['showoncombobox']) $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '').'t.'.$key;
6611
+				if ($val['showoncombobox']) {
6612
+					$tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '').'t.'.$key;
6613
+				}
6614
+			}
6615
+			if ($tmpfieldstoshow) {
6616
+				$fieldstoshow = $tmpfieldstoshow;
5907 6617
 			}
5908
-			if ($tmpfieldstoshow) $fieldstoshow = $tmpfieldstoshow;
5909 6618
 		} else {
5910 6619
 			// For backward compatibility
5911 6620
 			$objecttmp->fields['ref'] = array('type'=>'varchar(30)', 'label'=>'Ref', 'showoncombobox'=>1);
@@ -5933,20 +6642,30 @@  discard block
 block discarded – undo
5933 6642
 			$tmparray = explode('@', $objecttmp->ismultientitymanaged);
5934 6643
 			$sql .= ' INNER JOIN '.MAIN_DB_PREFIX.$tmparray[1].' as parenttable ON parenttable.rowid = t.'.$tmparray[0];
5935 6644
 		}
5936
-		if ($objecttmp->ismultientitymanaged == 'fk_soc@societe')
5937
-			if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
6645
+		if ($objecttmp->ismultientitymanaged == 'fk_soc@societe') {
6646
+					if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
6647
+		}
5938 6648
 		$sql .= " WHERE 1=1";
5939
-		if (isset($objecttmp->ismultientitymanaged) && $objecttmp->ismultientitymanaged == 1) $sql .= " AND t.entity IN (".getEntity($objecttmp->table_element).")";
6649
+		if (isset($objecttmp->ismultientitymanaged) && $objecttmp->ismultientitymanaged == 1) {
6650
+			$sql .= " AND t.entity IN (".getEntity($objecttmp->table_element).")";
6651
+		}
5940 6652
 		if (isset($objecttmp->ismultientitymanaged) && !is_numeric($objecttmp->ismultientitymanaged)) {
5941 6653
 			$sql .= ' AND parenttable.entity = t.'.$tmparray[0];
5942 6654
 		}
5943 6655
 		if ($objecttmp->ismultientitymanaged == 1 && !empty($user->socid)) {
5944
-			if ($objecttmp->element == 'societe') $sql .= " AND t.rowid = ".$user->socid;
5945
-			else $sql .= " AND t.fk_soc = ".$user->socid;
6656
+			if ($objecttmp->element == 'societe') {
6657
+				$sql .= " AND t.rowid = ".$user->socid;
6658
+			} else {
6659
+				$sql .= " AND t.fk_soc = ".$user->socid;
6660
+			}
6661
+		}
6662
+		if ($searchkey != '') {
6663
+			$sql .= natural_search(explode(',', $fieldstoshow), $searchkey);
5946 6664
 		}
5947
-		if ($searchkey != '') $sql .= natural_search(explode(',', $fieldstoshow), $searchkey);
5948 6665
 		if ($objecttmp->ismultientitymanaged == 'fk_soc@societe') {
5949
-			if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
6666
+			if (!$user->rights->societe->client->voir && !$user->socid) {
6667
+				$sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
6668
+			}
5950 6669
 		}
5951 6670
 		if ($objecttmp->filter) {	 // Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
5952 6671
 			/*if (! DolibarrApi::_checkFilters($objecttmp->filter))
@@ -5979,10 +6698,15 @@  discard block
 block discarded – undo
5979 6698
 			//if (! empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
5980 6699
 			if (!empty($conf->global->$confkeyforautocompletemode))
5981 6700
 			{
5982
-				if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty);
5983
-				else $textifempty .= $langs->trans("All");
6701
+				if ($showempty && !is_numeric($showempty)) {
6702
+					$textifempty = $langs->trans($showempty);
6703
+				} else {
6704
+					$textifempty .= $langs->trans("All");
6705
+				}
6706
+			}
6707
+			if ($showempty) {
6708
+				$out .= '<option value="-1">'.$textifempty.'</option>'."\n";
5984 6709
 			}
5985
-			if ($showempty) $out .= '<option value="-1">'.$textifempty.'</option>'."\n";
5986 6710
 
5987 6711
 			$num = $this->db->num_rows($resql);
5988 6712
 			$i = 0;
@@ -6011,7 +6735,9 @@  discard block
 block discarded – undo
6011 6735
 					}
6012 6736
 
6013 6737
 					$i++;
6014
-					if (($i % 10) == 0) $out .= "\n";
6738
+					if (($i % 10) == 0) {
6739
+						$out .= "\n";
6740
+					}
6015 6741
 				}
6016 6742
 			}
6017 6743
 
@@ -6022,7 +6748,9 @@  discard block
 block discarded – undo
6022 6748
 
6023 6749
 		$this->result = array('nbofelement'=>$num);
6024 6750
 
6025
-		if ($outputmode) return $outarray;
6751
+		if ($outputmode) {
6752
+			return $outarray;
6753
+		}
6026 6754
 		return $out;
6027 6755
 	}
6028 6756
 
@@ -6059,7 +6787,9 @@  discard block
 block discarded – undo
6059 6787
 		//if (preg_match('/^multi/',$htmlname)) $jsbeautify = 1;
6060 6788
 		$jsbeautify = 1;
6061 6789
 
6062
-		if ($value_as_key) $array = array_combine($array, $array);
6790
+		if ($value_as_key) {
6791
+			$array = array_combine($array, $array);
6792
+		}
6063 6793
 
6064 6794
 		$out = '';
6065 6795
 
@@ -6081,8 +6811,13 @@  discard block
 block discarded – undo
6081 6811
 		if ($show_empty)
6082 6812
 		{
6083 6813
 			$textforempty = ' ';
6084
-			if (!empty($conf->use_javascript_ajax)) $textforempty = '&nbsp;'; // If we use ajaxcombo, we need &nbsp; here to avoid to have an empty element that is too small.
6085
-			if (!is_numeric($show_empty)) $textforempty = $show_empty;
6814
+			if (!empty($conf->use_javascript_ajax)) {
6815
+				$textforempty = '&nbsp;';
6816
+			}
6817
+			// If we use ajaxcombo, we need &nbsp; here to avoid to have an empty element that is too small.
6818
+			if (!is_numeric($show_empty)) {
6819
+				$textforempty = $show_empty;
6820
+			}
6086 6821
 			$out .= '<option class="optiongrey" '.($moreparamonempty ? $moreparamonempty.' ' : '').'value="'.($show_empty < 0 ? $show_empty : -1).'"'.($id == $show_empty ? ' selected' : '').'>'.$textforempty.'</option>'."\n";
6087 6822
 		}
6088 6823
 
@@ -6093,19 +6828,28 @@  discard block
 block discarded – undo
6093 6828
 			{
6094 6829
 				foreach ($array as $key => $value)
6095 6830
 				{
6096
-				    if (!is_array($value)) $array[$key] = $langs->trans($value);
6097
-				    else $array[$key]['label'] = $langs->trans($value['label']);
6831
+				    if (!is_array($value)) {
6832
+				    	$array[$key] = $langs->trans($value);
6833
+				    } else {
6834
+				    	$array[$key]['label'] = $langs->trans($value['label']);
6835
+				    }
6098 6836
 				}
6099 6837
 			}
6100 6838
 
6101 6839
 			// Sort
6102
-			if ($sort == 'ASC') asort($array);
6103
-			elseif ($sort == 'DESC') arsort($array);
6840
+			if ($sort == 'ASC') {
6841
+				asort($array);
6842
+			} elseif ($sort == 'DESC') {
6843
+				arsort($array);
6844
+			}
6104 6845
 
6105 6846
 			foreach ($array as $key => $tmpvalue)
6106 6847
 			{
6107
-			    if (is_array($tmpvalue)) $value = $tmpvalue['label'];
6108
-			    else $value = $tmpvalue;
6848
+			    if (is_array($tmpvalue)) {
6849
+			    	$value = $tmpvalue['label'];
6850
+			    } else {
6851
+			    	$value = $tmpvalue;
6852
+			    }
6109 6853
 
6110 6854
 				$disabled = ''; $style = '';
6111 6855
 				if (!empty($disablebademail))
@@ -6120,28 +6864,46 @@  discard block
 block discarded – undo
6120 6864
 
6121 6865
 				if ($key_in_label)
6122 6866
 				{
6123
-					if (empty($nohtmlescape)) $selectOptionValue = dol_escape_htmltag($key.' - '.($maxlen ?dol_trunc($value, $maxlen) : $value));
6124
-					else $selectOptionValue = $key.' - '.($maxlen ?dol_trunc($value, $maxlen) : $value);
6867
+					if (empty($nohtmlescape)) {
6868
+						$selectOptionValue = dol_escape_htmltag($key.' - '.($maxlen ?dol_trunc($value, $maxlen) : $value));
6869
+					} else {
6870
+						$selectOptionValue = $key.' - '.($maxlen ?dol_trunc($value, $maxlen) : $value);
6871
+					}
6125 6872
 				} else {
6126
-					if (empty($nohtmlescape)) $selectOptionValue = dol_escape_htmltag($maxlen ?dol_trunc($value, $maxlen) : $value);
6127
-					else $selectOptionValue = $maxlen ?dol_trunc($value, $maxlen) : $value;
6128
-					if ($value == '' || $value == '-') $selectOptionValue = '&nbsp;';
6873
+					if (empty($nohtmlescape)) {
6874
+						$selectOptionValue = dol_escape_htmltag($maxlen ?dol_trunc($value, $maxlen) : $value);
6875
+					} else {
6876
+						$selectOptionValue = $maxlen ?dol_trunc($value, $maxlen) : $value;
6877
+					}
6878
+					if ($value == '' || $value == '-') {
6879
+						$selectOptionValue = '&nbsp;';
6880
+					}
6129 6881
 				}
6130 6882
 
6131 6883
 				$out .= '<option value="'.$key.'"';
6132 6884
 				$out .= $style.$disabled;
6133 6885
 				if (is_array($id)) {
6134
-					if (in_array($key, $id) && !$disabled) $out .= ' selected'; // To preselect a value
6886
+					if (in_array($key, $id) && !$disabled) {
6887
+						$out .= ' selected';
6888
+					}
6889
+					// To preselect a value
6135 6890
 				} else {
6136 6891
 					$id = (string) $id; // if $id = 0, then $id = '0'
6137
-					if ($id != '' && $id == $key && !$disabled) $out .= ' selected'; // To preselect a value
6892
+					if ($id != '' && $id == $key && !$disabled) {
6893
+						$out .= ' selected';
6894
+					}
6895
+					// To preselect a value
6896
+				}
6897
+				if ($nohtmlescape) {
6898
+					$out .= ' data-html="'.dol_escape_htmltag($selectOptionValue).'"';
6138 6899
 				}
6139
-				if ($nohtmlescape) $out .= ' data-html="'.dol_escape_htmltag($selectOptionValue).'"';
6140 6900
 				if (is_array($tmpvalue))
6141 6901
 				{
6142 6902
 				    foreach ($tmpvalue as $keyforvalue => $valueforvalue)
6143 6903
 				    {
6144
-				        if (preg_match('/^data-/', $keyforvalue)) $out .= ' '.$keyforvalue.'="'.$valueforvalue.'"';
6904
+				        if (preg_match('/^data-/', $keyforvalue)) {
6905
+				        	$out .= ' '.$keyforvalue.'="'.$valueforvalue.'"';
6906
+				        }
6145 6907
 				    }
6146 6908
 				}
6147 6909
 				$out .= '>';
@@ -6180,7 +6942,9 @@  discard block
 block discarded – undo
6180 6942
 		global $delayedhtmlcontent;
6181 6943
 
6182 6944
 		// TODO Use an internal dolibarr component instead of select2
6183
-		if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT')) return '';
6945
+		if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT')) {
6946
+			return '';
6947
+		}
6184 6948
 
6185 6949
 		$out = '<select type="text" class="'.$htmlname.($morecss ? ' '.$morecss : '').'" '.($moreparam ? $moreparam.' ' : '').'name="'.$htmlname.'"></select>';
6186 6950
 
@@ -6280,7 +7044,9 @@  discard block
 block discarded – undo
6280 7044
 		global $delayedhtmlcontent;
6281 7045
 
6282 7046
 		// TODO Use an internal dolibarr component instead of select2
6283
-		if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT')) return '';
7047
+		if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT')) {
7048
+			return '';
7049
+		}
6284 7050
 
6285 7051
 		$out = '<select type="text" class="'.$htmlname.($morecss ? ' '.$morecss : '').'" '.($moreparam ? $moreparam.' ' : '').'name="'.$htmlname.'"><option></option></select>';
6286 7052
 
@@ -6397,8 +7163,11 @@  discard block
 block discarded – undo
6397 7163
 		$out = '';
6398 7164
 
6399 7165
 		if ($addjscombo < 0) {
6400
-		    if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $addjscombo = 1;
6401
-		    else $addjscombo = 0;
7166
+		    if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
7167
+		    	$addjscombo = 1;
7168
+		    } else {
7169
+		    	$addjscombo = 0;
7170
+		    }
6402 7171
 		}
6403 7172
 
6404 7173
 		// Add code for jquery to use multiselect
@@ -6459,7 +7228,9 @@  discard block
 block discarded – undo
6459 7228
 		$out .= '<select id="'.$htmlname.'" class="multiselect'.($morecss ? ' '.$morecss : '').'" multiple name="'.$htmlname.'[]"'.($moreattrib ? ' '.$moreattrib : '').($width ? ' style="width: '.(preg_match('/%/', $width) ? $width : $width.'px').'"' : '').'>'."\n";
6460 7229
 		if (is_array($array) && !empty($array))
6461 7230
 		{
6462
-			if ($value_as_key) $array = array_combine($array, $array);
7231
+			if ($value_as_key) {
7232
+				$array = array_combine($array, $array);
7233
+			}
6463 7234
 
6464 7235
 			if (!empty($array))
6465 7236
 			{
@@ -6498,7 +7269,9 @@  discard block
 block discarded – undo
6498 7269
 	{
6499 7270
 		global $conf, $langs, $user;
6500 7271
 
6501
-		if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) return '';
7272
+		if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
7273
+			return '';
7274
+		}
6502 7275
 
6503 7276
 		$tmpvar = "MAIN_SELECTEDFIELDS_".$varpage;	// To get list of saved seleteced properties
6504 7277
 		if (!empty($user->conf->$tmpvar))
@@ -6508,8 +7281,11 @@  discard block
 block discarded – undo
6508 7281
 			{
6509 7282
 				//var_dump($key);
6510 7283
 				//var_dump($tmparray);
6511
-				if (in_array($key, $tmparray)) $array[$key]['checked'] = 1;
6512
-				else $array[$key]['checked'] = 0;
7284
+				if (in_array($key, $tmparray)) {
7285
+					$array[$key]['checked'] = 1;
7286
+				} else {
7287
+					$array[$key]['checked'] = 0;
7288
+				}
6513 7289
 			}
6514 7290
 		}
6515 7291
 
@@ -6691,25 +7467,46 @@  discard block
 block discarded – undo
6691 7467
 				// To work with non standard path
6692 7468
 				if ($objecttype == 'facture') {
6693 7469
 					$tplpath = 'compta/'.$element;
6694
-					if (empty($conf->facture->enabled)) continue; // Do not show if module disabled
7470
+					if (empty($conf->facture->enabled)) {
7471
+						continue;
7472
+					}
7473
+					// Do not show if module disabled
6695 7474
 				} elseif ($objecttype == 'facturerec') {
6696 7475
 					$tplpath = 'compta/facture';
6697 7476
 					$tplname = 'linkedobjectblockForRec';
6698
-					if (empty($conf->facture->enabled)) continue; // Do not show if module disabled
7477
+					if (empty($conf->facture->enabled)) {
7478
+						continue;
7479
+					}
7480
+					// Do not show if module disabled
6699 7481
 				} elseif ($objecttype == 'propal') {
6700 7482
 					$tplpath = 'comm/'.$element;
6701
-					if (empty($conf->propal->enabled)) continue; // Do not show if module disabled
7483
+					if (empty($conf->propal->enabled)) {
7484
+						continue;
7485
+					}
7486
+					// Do not show if module disabled
6702 7487
 				} elseif ($objecttype == 'supplier_proposal') {
6703
-					if (empty($conf->supplier_proposal->enabled)) continue; // Do not show if module disabled
7488
+					if (empty($conf->supplier_proposal->enabled)) {
7489
+						continue;
7490
+					}
7491
+					// Do not show if module disabled
6704 7492
 				} elseif ($objecttype == 'shipping' || $objecttype == 'shipment') {
6705 7493
 					$tplpath = 'expedition';
6706
-					if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled
7494
+					if (empty($conf->expedition->enabled)) {
7495
+						continue;
7496
+					}
7497
+					// Do not show if module disabled
6707 7498
 				} elseif ($objecttype == 'reception') {
6708 7499
         			$tplpath = 'reception';
6709
-        			if (empty($conf->reception->enabled)) continue; // Do not show if module disabled
7500
+        			if (empty($conf->reception->enabled)) {
7501
+        				continue;
7502
+        			}
7503
+        			// Do not show if module disabled
6710 7504
         		} elseif ($objecttype == 'delivery') {
6711 7505
 					$tplpath = 'livraison';
6712
-					if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled
7506
+					if (empty($conf->expedition->enabled)) {
7507
+						continue;
7508
+					}
7509
+					// Do not show if module disabled
6713 7510
 				} elseif ($objecttype == 'invoice_supplier') {
6714 7511
 					$tplpath = 'fourn/facture';
6715 7512
 				} elseif ($objecttype == 'order_supplier') {
@@ -6728,9 +7525,11 @@  discard block
 block discarded – undo
6728 7525
 				$dirtpls = array_merge($conf->modules_parts['tpl'], array('/'.$tplpath.'/tpl'));
6729 7526
 				foreach ($dirtpls as $reldir)
6730 7527
 				{
6731
-					if ($nboftypesoutput == ($nbofdifferenttypes - 1))    // No more type to show after
7528
+					if ($nboftypesoutput == ($nbofdifferenttypes - 1)) {
7529
+						// No more type to show after
6732 7530
 					{
6733 7531
 						global $noMoreLinkedObjectBlockAfter;
7532
+					}
6734 7533
 						$noMoreLinkedObjectBlockAfter = 1;
6735 7534
 					}
6736 7535
 
@@ -6779,19 +7578,25 @@  discard block
 block discarded – undo
6779 7578
 		$linktoelemlist = '';
6780 7579
 		$listofidcompanytoscan = '';
6781 7580
 
6782
-		if (!is_object($object->thirdparty)) $object->fetch_thirdparty();
7581
+		if (!is_object($object->thirdparty)) {
7582
+			$object->fetch_thirdparty();
7583
+		}
6783 7584
 
6784 7585
 		$possiblelinks = array();
6785 7586
 		if (is_object($object->thirdparty) && !empty($object->thirdparty->id) && $object->thirdparty->id > 0)
6786 7587
 		{
6787 7588
 			$listofidcompanytoscan = $object->thirdparty->id;
6788
-			if (($object->thirdparty->parent > 0) && !empty($conf->global->THIRDPARTY_INCLUDE_PARENT_IN_LINKTO)) $listofidcompanytoscan .= ','.$object->thirdparty->parent;
7589
+			if (($object->thirdparty->parent > 0) && !empty($conf->global->THIRDPARTY_INCLUDE_PARENT_IN_LINKTO)) {
7590
+				$listofidcompanytoscan .= ','.$object->thirdparty->parent;
7591
+			}
6789 7592
 			if (($object->fk_project > 0) && !empty($conf->global->THIRDPARTY_INCLUDE_PROJECT_THIRDPARY_IN_LINKTO))
6790 7593
 			{
6791 7594
 				include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
6792 7595
 				$tmpproject = new Project($this->db);
6793 7596
 				$tmpproject->fetch($object->fk_project);
6794
-				if ($tmpproject->socid > 0 && ($tmpproject->socid != $object->thirdparty->id)) $listofidcompanytoscan .= ','.$tmpproject->socid;
7597
+				if ($tmpproject->socid > 0 && ($tmpproject->socid != $object->thirdparty->id)) {
7598
+					$listofidcompanytoscan .= ','.$tmpproject->socid;
7599
+				}
6795 7600
 				unset($tmpproject);
6796 7601
 			}
6797 7602
 
@@ -6814,9 +7619,12 @@  discard block
 block discarded – undo
6814 7619
 		$hookmanager->initHooks(array('commonobject'));
6815 7620
 		$parameters = array('listofidcompanytoscan' => $listofidcompanytoscan);
6816 7621
 
6817
-		if (!empty($listofidcompanytoscan))  // If empty, we don't have criteria to scan the object we can link to
7622
+		if (!empty($listofidcompanytoscan)) {
7623
+			// If empty, we don't have criteria to scan the object we can link to
6818 7624
 		{
6819
-            $reshook = $hookmanager->executeHooks('showLinkToObjectBlock', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
7625
+            $reshook = $hookmanager->executeHooks('showLinkToObjectBlock', $parameters, $object, $action);
7626
+		}
7627
+		// Note that $action and $object may have been modified by hook
6820 7628
 		}
6821 7629
 
6822 7630
 		if (empty($reshook))
@@ -6837,7 +7645,9 @@  discard block
 block discarded – undo
6837 7645
 		{
6838 7646
 			$num = 0;
6839 7647
 
6840
-			if (empty($possiblelink['enabled'])) continue;
7648
+			if (empty($possiblelink['enabled'])) {
7649
+				continue;
7650
+			}
6841 7651
 
6842 7652
 			if (!empty($possiblelink['perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto)))
6843 7653
 			{
@@ -6893,9 +7703,13 @@  discard block
 block discarded – undo
6893 7703
 				}
6894 7704
 
6895 7705
 				//$linktoelem.=($linktoelem?' &nbsp; ':'');
6896
-				if ($num > 0) $linktoelemlist .= '<li><a href="#linkto'.$key.'" class="linkto dropdowncloseonclick" rel="'.$key.'">'.$langs->trans($possiblelink['label']).' ('.$num.')</a></li>';
7706
+				if ($num > 0) {
7707
+					$linktoelemlist .= '<li><a href="#linkto'.$key.'" class="linkto dropdowncloseonclick" rel="'.$key.'">'.$langs->trans($possiblelink['label']).' ('.$num.')</a></li>';
7708
+				}
6897 7709
 				//else $linktoelem.=$langs->trans($possiblelink['label']);
6898
-				else $linktoelemlist .= '<li><span class="linktodisabled">'.$langs->trans($possiblelink['label']).' (0)</span></li>';
7710
+				else {
7711
+					$linktoelemlist .= '<li><span class="linktodisabled">'.$langs->trans($possiblelink['label']).' (0)</span></li>';
7712
+				}
6899 7713
 			}
6900 7714
 		}
6901 7715
 
@@ -6904,7 +7718,9 @@  discard block
 block discarded – undo
6904 7718
 			$linktoelem = '
6905 7719
     		<dl class="dropdown" id="linktoobjectname">
6906 7720
     		';
6907
-			if (!empty($conf->use_javascript_ajax)) $linktoelem .= '<dt><a href="#linktoobjectname">'.$langs->trans("LinkTo").'...</a></dt>';
7721
+			if (!empty($conf->use_javascript_ajax)) {
7722
+				$linktoelem .= '<dt><a href="#linktoobjectname">'.$langs->trans("LinkTo").'...</a></dt>';
7723
+			}
6908 7724
 			$linktoelem .= '<dd>
6909 7725
     		<div class="multiselectlinkto">
6910 7726
     		<ul class="ulselectedfields">'.$linktoelemlist.'
@@ -6957,7 +7773,9 @@  discard block
 block discarded – undo
6957 7773
 		$disabled = ($disabled ? ' disabled' : '');
6958 7774
 
6959 7775
 		$resultyesno = '<select class="flat width75" id="'.$htmlname.'" name="'.$htmlname.'"'.$disabled.'>'."\n";
6960
-		if ($useempty) $resultyesno .= '<option value="-1"'.(($value < 0) ? ' selected' : '').'>&nbsp;</option>'."\n";
7776
+		if ($useempty) {
7777
+			$resultyesno .= '<option value="-1"'.(($value < 0) ? ' selected' : '').'>&nbsp;</option>'."\n";
7778
+		}
6961 7779
 		if (("$value" == 'yes') || ($value == 1))
6962 7780
 		{
6963 7781
 			$resultyesno .= '<option value="'.$yes.'" selected>'.$langs->trans("Yes").'</option>'."\n";
@@ -7041,8 +7859,12 @@  discard block
 block discarded – undo
7041 7859
 		global $langs, $conf, $hookmanager, $extralanguages;
7042 7860
 
7043 7861
 		$ret = '';
7044
-		if (empty($fieldid))  $fieldid = 'rowid';
7045
-		if (empty($fieldref)) $fieldref = 'ref';
7862
+		if (empty($fieldid)) {
7863
+			$fieldid = 'rowid';
7864
+		}
7865
+		if (empty($fieldref)) {
7866
+			$fieldref = 'ref';
7867
+		}
7046 7868
 
7047 7869
 		// Add where from hooks
7048 7870
 		if (is_object($hookmanager))
@@ -7061,9 +7883,11 @@  discard block
 block discarded – undo
7061 7883
 			// Special case for project/task page
7062 7884
 			if ($paramid == 'project_ref')
7063 7885
 			{
7064
-			    if (preg_match('/\/tasks\/(task|contact|note|document)\.php/', $navurl))     // TODO Remove this when nav with project_ref on task pages are ok
7886
+			    if (preg_match('/\/tasks\/(task|contact|note|document)\.php/', $navurl)) {
7887
+			    	// TODO Remove this when nav with project_ref on task pages are ok
7065 7888
 			    {
7066 7889
 				    $navurl = preg_replace('/\/tasks\/(task|contact|time|note|document)\.php/', '/tasks.php', $navurl);
7890
+			    }
7067 7891
     				$paramid = 'ref';
7068 7892
 			    }
7069 7893
 			}
@@ -7089,7 +7913,9 @@  discard block
 block discarded – undo
7089 7913
 		$ret .= '<!-- Start banner content --><div style="vertical-align: middle">';
7090 7914
 
7091 7915
 		// Right part of banner
7092
-		if ($morehtmlright) $ret .= '<div class="inline-block floatleft">'.$morehtmlright.'</div>';
7916
+		if ($morehtmlright) {
7917
+			$ret .= '<div class="inline-block floatleft">'.$morehtmlright.'</div>';
7918
+		}
7093 7919
 
7094 7920
 		if ($previous_ref || $next_ref || $morehtml)
7095 7921
 		{
@@ -7111,20 +7937,33 @@  discard block
 block discarded – undo
7111 7937
 
7112 7938
 		$parameters = array();
7113 7939
 		$reshook = $hookmanager->executeHooks('moreHtmlStatus', $parameters, $object); // Note that $action and $object may have been modified by hook
7114
-		if (empty($reshook)) $morehtmlstatus .= $hookmanager->resPrint;
7115
-		else $morehtmlstatus = $hookmanager->resPrint;
7116
-		if ($morehtmlstatus) $ret .= '<div class="statusref">'.$morehtmlstatus.'</div>';
7940
+		if (empty($reshook)) {
7941
+			$morehtmlstatus .= $hookmanager->resPrint;
7942
+		} else {
7943
+			$morehtmlstatus = $hookmanager->resPrint;
7944
+		}
7945
+		if ($morehtmlstatus) {
7946
+			$ret .= '<div class="statusref">'.$morehtmlstatus.'</div>';
7947
+		}
7117 7948
 
7118 7949
 		$parameters = array();
7119 7950
 		$reshook = $hookmanager->executeHooks('moreHtmlRef', $parameters, $object); // Note that $action and $object may have been modified by hook
7120
-		if (empty($reshook)) $morehtmlref .= $hookmanager->resPrint;
7121
-		elseif ($reshook > 0) $morehtmlref = $hookmanager->resPrint;
7951
+		if (empty($reshook)) {
7952
+			$morehtmlref .= $hookmanager->resPrint;
7953
+		} elseif ($reshook > 0) {
7954
+			$morehtmlref = $hookmanager->resPrint;
7955
+		}
7122 7956
 
7123 7957
 		// Left part of banner
7124 7958
 		if ($morehtmlleft)
7125 7959
 		{
7126
-			if ($conf->browser->layout == 'phone') $ret .= '<!-- morehtmlleft --><div class="floatleft">'.$morehtmlleft.'</div>'; // class="center" to have photo in middle
7127
-			else $ret .= '<!-- morehtmlleft --><div class="inline-block floatleft">'.$morehtmlleft.'</div>';
7960
+			if ($conf->browser->layout == 'phone') {
7961
+				$ret .= '<!-- morehtmlleft --><div class="floatleft">'.$morehtmlleft.'</div>';
7962
+			}
7963
+			// class="center" to have photo in middle
7964
+			else {
7965
+				$ret .= '<!-- morehtmlleft --><div class="inline-block floatleft">'.$morehtmlleft.'</div>';
7966
+			}
7128 7967
 		}
7129 7968
 
7130 7969
 		//if ($conf->browser->layout == 'phone') $ret.='<div class="clearboth"></div>';
@@ -7137,7 +7976,9 @@  discard block
 block discarded – undo
7137 7976
 
7138 7977
 			// List of extra languages
7139 7978
 			$arrayoflangcode = array();
7140
-			if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE)) $arrayoflangcode[] = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
7979
+			if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE)) {
7980
+				$arrayoflangcode[] = $conf->global->PDF_USE_ALSO_LANGUAGE_CODE;
7981
+			}
7141 7982
 
7142 7983
 			if (is_array($arrayoflangcode) && count($arrayoflangcode)) {
7143 7984
 				if (!is_object($extralanguages)) {
@@ -7221,14 +8062,18 @@  discard block
 block discarded – undo
7221 8062
 		global $conf;
7222 8063
 
7223 8064
 		//Check if barcode is filled in the card
7224
-		if (empty($object->barcode)) return '';
8065
+		if (empty($object->barcode)) {
8066
+			return '';
8067
+		}
7225 8068
 
7226 8069
 		// Complete object if not complete
7227 8070
 		if (empty($object->barcode_type_code) || empty($object->barcode_type_coder))
7228 8071
 		{
7229 8072
 			$result = $object->fetch_barcode();
7230 8073
 			//Check if fetch_barcode() failed
7231
-			if ($result < 1) return '<!-- ErrorFetchBarcode -->';
8074
+			if ($result < 1) {
8075
+				return '<!-- ErrorFetchBarcode -->';
8076
+			}
7232 8077
 		}
7233 8078
 
7234 8079
 		// Barcode image
@@ -7266,9 +8111,15 @@  discard block
 block discarded – undo
7266 8111
 			$dir = $conf->societe->multidir_output[$entity];
7267 8112
 			if (!empty($object->logo))
7268 8113
 			{
7269
-				if ((string) $imagesize == 'mini') $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty').'/logos/'.getImageFileNameForSize($object->logo, '_mini'); // getImageFileNameForSize include the thumbs
7270
-				elseif ((string) $imagesize == 'small') $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty').'/logos/'.getImageFileNameForSize($object->logo, '_small');
7271
-				else $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty').'/logos/'.$object->logo;
8114
+				if ((string) $imagesize == 'mini') {
8115
+					$file = get_exdir(0, 0, 0, 0, $object, 'thirdparty').'/logos/'.getImageFileNameForSize($object->logo, '_mini');
8116
+				}
8117
+				// getImageFileNameForSize include the thumbs
8118
+				elseif ((string) $imagesize == 'small') {
8119
+					$file = get_exdir(0, 0, 0, 0, $object, 'thirdparty').'/logos/'.getImageFileNameForSize($object->logo, '_small');
8120
+				} else {
8121
+					$file = get_exdir(0, 0, 0, 0, $object, 'thirdparty').'/logos/'.$object->logo;
8122
+				}
7272 8123
 				$originalfile = get_exdir(0, 0, 0, 0, $object, 'thirdparty').'/logos/'.$object->logo;
7273 8124
 			}
7274 8125
 			$email = $object->email;
@@ -7277,9 +8128,13 @@  discard block
 block discarded – undo
7277 8128
 			$dir = $conf->societe->multidir_output[$entity].'/contact';
7278 8129
 			if (!empty($object->photo))
7279 8130
 			{
7280
-				if ((string) $imagesize == 'mini') $file = get_exdir(0, 0, 0, 0, $object, 'contact').'/photos/'.getImageFileNameForSize($object->photo, '_mini');
7281
-				elseif ((string) $imagesize == 'small') $file = get_exdir(0, 0, 0, 0, $object, 'contact').'/photos/'.getImageFileNameForSize($object->photo, '_small');
7282
-				else $file = get_exdir(0, 0, 0, 0, $object, 'contact').'/photos/'.$object->photo;
8131
+				if ((string) $imagesize == 'mini') {
8132
+					$file = get_exdir(0, 0, 0, 0, $object, 'contact').'/photos/'.getImageFileNameForSize($object->photo, '_mini');
8133
+				} elseif ((string) $imagesize == 'small') {
8134
+					$file = get_exdir(0, 0, 0, 0, $object, 'contact').'/photos/'.getImageFileNameForSize($object->photo, '_small');
8135
+				} else {
8136
+					$file = get_exdir(0, 0, 0, 0, $object, 'contact').'/photos/'.$object->photo;
8137
+				}
7283 8138
 				$originalfile = get_exdir(0, 0, 0, 0, $object, 'contact').'/photos/'.$object->photo;
7284 8139
 			}
7285 8140
 			$email = $object->email;
@@ -7289,12 +8144,19 @@  discard block
 block discarded – undo
7289 8144
 			$dir = $conf->user->dir_output;
7290 8145
 			if (!empty($object->photo))
7291 8146
 			{
7292
-				if ((string) $imagesize == 'mini') $file = get_exdir(0, 0, 0, 0, $object, 'user').$object->id.'/'.getImageFileNameForSize($object->photo, '_mini');
7293
-				elseif ((string) $imagesize == 'small') $file = get_exdir(0, 0, 0, 0, $object, 'user').$object->id.'/'.getImageFileNameForSize($object->photo, '_small');
7294
-				else $file = get_exdir(0, 0, 0, 0, $object, 'user').'/'.$object->id.'/'.$object->photo;
8147
+				if ((string) $imagesize == 'mini') {
8148
+					$file = get_exdir(0, 0, 0, 0, $object, 'user').$object->id.'/'.getImageFileNameForSize($object->photo, '_mini');
8149
+				} elseif ((string) $imagesize == 'small') {
8150
+					$file = get_exdir(0, 0, 0, 0, $object, 'user').$object->id.'/'.getImageFileNameForSize($object->photo, '_small');
8151
+				} else {
8152
+					$file = get_exdir(0, 0, 0, 0, $object, 'user').'/'.$object->id.'/'.$object->photo;
8153
+				}
7295 8154
 				$originalfile = get_exdir(0, 0, 0, 0, $object, 'user').'/'.$object->id.'/'.$object->photo;
7296 8155
 			}
7297
-			if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile = $object->id.".jpg"; // For backward compatibility
8156
+			if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) {
8157
+				$altfile = $object->id.".jpg";
8158
+			}
8159
+			// For backward compatibility
7298 8160
 			$email = $object->email;
7299 8161
 			$capture = 'user';
7300 8162
 		} elseif ($modulepart == 'memberphoto')
@@ -7302,12 +8164,19 @@  discard block
 block discarded – undo
7302 8164
 			$dir = $conf->adherent->dir_output;
7303 8165
 			if (!empty($object->photo))
7304 8166
 			{
7305
-				if ((string) $imagesize == 'mini') $file = get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.getImageFileNameForSize($object->photo, '_mini');
7306
-				elseif ((string) $imagesize == 'small') $file = get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.getImageFileNameForSize($object->photo, '_small');
7307
-				else $file = get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.$object->photo;
8167
+				if ((string) $imagesize == 'mini') {
8168
+					$file = get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.getImageFileNameForSize($object->photo, '_mini');
8169
+				} elseif ((string) $imagesize == 'small') {
8170
+					$file = get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.getImageFileNameForSize($object->photo, '_small');
8171
+				} else {
8172
+					$file = get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.$object->photo;
8173
+				}
7308 8174
 				$originalfile = get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.$object->photo;
7309 8175
 			}
7310
-			if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile = $object->id.".jpg"; // For backward compatibility
8176
+			if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) {
8177
+				$altfile = $object->id.".jpg";
8178
+			}
8179
+			// For backward compatibility
7311 8180
 			$email = $object->email;
7312 8181
 			$capture = 'user';
7313 8182
 		} else {
@@ -7315,16 +8184,25 @@  discard block
 block discarded – undo
7315 8184
 			$dir = $conf->$modulepart->dir_output;
7316 8185
 			if (!empty($object->photo))
7317 8186
 			{
7318
-				if ((string) $imagesize == 'mini') $file = get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.getImageFileNameForSize($object->photo, '_mini');
7319
-				elseif ((string) $imagesize == 'small') $file = get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.getImageFileNameForSize($object->photo, '_small');
7320
-				else $file = get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.$object->photo;
8187
+				if ((string) $imagesize == 'mini') {
8188
+					$file = get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.getImageFileNameForSize($object->photo, '_mini');
8189
+				} elseif ((string) $imagesize == 'small') {
8190
+					$file = get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.getImageFileNameForSize($object->photo, '_small');
8191
+				} else {
8192
+					$file = get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.$object->photo;
8193
+				}
7321 8194
 				$originalfile = get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.$object->photo;
7322 8195
 			}
7323
-			if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile = $object->id.".jpg"; // For backward compatibility
8196
+			if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) {
8197
+				$altfile = $object->id.".jpg";
8198
+			}
8199
+			// For backward compatibility
7324 8200
 			$email = $object->email;
7325 8201
 		}
7326 8202
 
7327
-		if ($forcecapture) $capture = $forcecapture;
8203
+		if ($forcecapture) {
8204
+			$capture = $forcecapture;
8205
+		}
7328 8206
 
7329 8207
 		if ($dir)
7330 8208
 		{
@@ -7333,31 +8211,47 @@  discard block
 block discarded – undo
7333 8211
 				if ($addlinktofullsize)
7334 8212
 				{
7335 8213
 					$urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 0, '&entity='.$entity);
7336
-					if ($urladvanced) $ret .= '<a href="'.$urladvanced.'">';
7337
-					else $ret .= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($originalfile).'&cache='.$cache.'">';
8214
+					if ($urladvanced) {
8215
+						$ret .= '<a href="'.$urladvanced.'">';
8216
+					} else {
8217
+						$ret .= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($originalfile).'&cache='.$cache.'">';
8218
+					}
7338 8219
 				}
7339 8220
 				$ret .= '<img alt="Photo" class="photo'.$modulepart.($cssclass ? ' '.$cssclass : '').' photologo'.(preg_replace('/[^a-z]/i', '_', $file)).'" '.($width ? ' width="'.$width.'"' : '').($height ? ' height="'.$height.'"' : '').' src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($file).'&cache='.$cache.'">';
7340
-				if ($addlinktofullsize) $ret .= '</a>';
8221
+				if ($addlinktofullsize) {
8222
+					$ret .= '</a>';
8223
+				}
7341 8224
 			} elseif ($altfile && file_exists($dir."/".$altfile))
7342 8225
 			{
7343 8226
 				if ($addlinktofullsize)
7344 8227
 				{
7345 8228
 					$urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 0, '&entity='.$entity);
7346
-					if ($urladvanced) $ret .= '<a href="'.$urladvanced.'">';
7347
-					else $ret .= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($originalfile).'&cache='.$cache.'">';
8229
+					if ($urladvanced) {
8230
+						$ret .= '<a href="'.$urladvanced.'">';
8231
+					} else {
8232
+						$ret .= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($originalfile).'&cache='.$cache.'">';
8233
+					}
7348 8234
 				}
7349 8235
 				$ret .= '<img class="photo'.$modulepart.($cssclass ? ' '.$cssclass : '').'" alt="Photo alt" id="photologo'.(preg_replace('/[^a-z]/i', '_', $file)).'" class="'.$cssclass.'" '.($width ? ' width="'.$width.'"' : '').($height ? ' height="'.$height.'"' : '').' src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($altfile).'&cache='.$cache.'">';
7350
-				if ($addlinktofullsize) $ret .= '</a>';
8236
+				if ($addlinktofullsize) {
8237
+					$ret .= '</a>';
8238
+				}
7351 8239
 			} else {
7352 8240
 				$nophoto = '/public/theme/common/nophoto.png';
7353
-				if (in_array($modulepart, array('userphoto', 'contact', 'memberphoto')))	// For module that are "physical" users
8241
+				if (in_array($modulepart, array('userphoto', 'contact', 'memberphoto'))) {
8242
+					// For module that are "physical" users
7354 8243
 				{
7355 8244
 					if ($modulepart == 'memberphoto' && strpos($object->morphy, 'mor') !== false) {
7356 8245
 						$nophoto = '/public/theme/common/company.png';
8246
+				}
7357 8247
 					} else {
7358 8248
 						$nophoto = '/public/theme/common/user_anonymous.png';
7359
-						if ($object->gender == 'man') $nophoto = '/public/theme/common/user_man.png';
7360
-						if ($object->gender == 'woman') $nophoto = '/public/theme/common/user_woman.png';
8249
+						if ($object->gender == 'man') {
8250
+							$nophoto = '/public/theme/common/user_man.png';
8251
+						}
8252
+						if ($object->gender == 'woman') {
8253
+							$nophoto = '/public/theme/common/user_woman.png';
8254
+						}
7361 8255
 					}
7362 8256
 				}
7363 8257
 
@@ -7378,13 +8272,19 @@  discard block
 block discarded – undo
7378 8272
 
7379 8273
 			if ($caneditfield)
7380 8274
 			{
7381
-				if ($object->photo) $ret .= "<br>\n";
8275
+				if ($object->photo) {
8276
+					$ret .= "<br>\n";
8277
+				}
7382 8278
 				$ret .= '<table class="nobordernopadding centpercent">';
7383
-				if ($object->photo) $ret .= '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
8279
+				if ($object->photo) {
8280
+					$ret .= '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
8281
+				}
7384 8282
 				$ret .= '<tr><td class="tdoverflow"><input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput" accept="image/*"'.($capture ? ' capture="'.$capture.'"' : '').'></td></tr>';
7385 8283
 				$ret .= '</table>';
7386 8284
 			}
7387
-		} else dol_print_error('', 'Call of showphoto with wrong parameters modulepart='.$modulepart);
8285
+		} else {
8286
+			dol_print_error('', 'Call of showphoto with wrong parameters modulepart='.$modulepart);
8287
+		}
7388 8288
 
7389 8289
 		return $ret;
7390 8290
 	}
@@ -7412,11 +8312,17 @@  discard block
 block discarded – undo
7412 8312
 		global $conf, $user, $langs;
7413 8313
 
7414 8314
 		// Permettre l'exclusion de groupes
7415
-		if (is_array($exclude))	$excludeGroups = implode("','", $exclude);
8315
+		if (is_array($exclude)) {
8316
+			$excludeGroups = implode("','", $exclude);
8317
+		}
7416 8318
 		// Permettre l'inclusion de groupes
7417
-		if (is_array($include))	$includeGroups = implode("','", $include);
8319
+		if (is_array($include)) {
8320
+			$includeGroups = implode("','", $include);
8321
+		}
7418 8322
 
7419
-		if (!is_array($selected)) $selected = array($selected);
8323
+		if (!is_array($selected)) {
8324
+			$selected = array($selected);
8325
+		}
7420 8326
 
7421 8327
 		$out = '';
7422 8328
 
@@ -7430,13 +8336,20 @@  discard block
 block discarded – undo
7430 8336
 		if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity)
7431 8337
 		{
7432 8338
 			$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entity as e ON e.rowid=ug.entity";
7433
-			if ($force_entity) $sql .= " WHERE ug.entity IN (0,".$force_entity.")";
7434
-			else $sql .= " WHERE ug.entity IS NOT NULL";
8339
+			if ($force_entity) {
8340
+				$sql .= " WHERE ug.entity IN (0,".$force_entity.")";
8341
+			} else {
8342
+				$sql .= " WHERE ug.entity IS NOT NULL";
8343
+			}
7435 8344
 		} else {
7436 8345
 			$sql .= " WHERE ug.entity IN (0,".$conf->entity.")";
7437 8346
 		}
7438
-		if (is_array($exclude) && $excludeGroups) $sql .= " AND ug.rowid NOT IN ('".$excludeGroups."')";
7439
-		if (is_array($include) && $includeGroups) $sql .= " AND ug.rowid IN ('".$includeGroups."')";
8347
+		if (is_array($exclude) && $excludeGroups) {
8348
+			$sql .= " AND ug.rowid NOT IN ('".$excludeGroups."')";
8349
+		}
8350
+		if (is_array($include) && $includeGroups) {
8351
+			$sql .= " AND ug.rowid IN ('".$includeGroups."')";
8352
+		}
7440 8353
 		$sql .= " ORDER BY ug.nom ASC";
7441 8354
 
7442 8355
 		dol_syslog(get_class($this)."::select_dolgroups", LOG_DEBUG);
@@ -7453,16 +8366,22 @@  discard block
 block discarded – undo
7453 8366
 			$i = 0;
7454 8367
 			if ($num)
7455 8368
 			{
7456
-				if ($show_empty && !$multiple) $out .= '<option value="-1"'.(in_array(-1, $selected) ? ' selected' : '').'>&nbsp;</option>'."\n";
8369
+				if ($show_empty && !$multiple) {
8370
+					$out .= '<option value="-1"'.(in_array(-1, $selected) ? ' selected' : '').'>&nbsp;</option>'."\n";
8371
+				}
7457 8372
 
7458 8373
 				while ($i < $num)
7459 8374
 				{
7460 8375
 					$obj = $this->db->fetch_object($resql);
7461 8376
 					$disableline = 0;
7462
-					if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) $disableline = 1;
8377
+					if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) {
8378
+						$disableline = 1;
8379
+					}
7463 8380
 
7464 8381
 					$out .= '<option value="'.$obj->rowid.'"';
7465
-					if ($disableline) $out .= ' disabled';
8382
+					if ($disableline) {
8383
+						$out .= ' disabled';
8384
+					}
7466 8385
 					if ((is_object($selected[0]) && $selected[0]->id == $obj->rowid) || (!is_object($selected[0]) && in_array($obj->rowid, $selected)))
7467 8386
 					{
7468 8387
 						$out .= ' selected';
@@ -7479,7 +8398,9 @@  discard block
 block discarded – undo
7479 8398
 					$i++;
7480 8399
 				}
7481 8400
 			} else {
7482
-				if ($show_empty) $out .= '<option value="-1"'.(in_array(-1, $selected) ? ' selected' : '').'></option>'."\n";
8401
+				if ($show_empty) {
8402
+					$out .= '<option value="-1"'.(in_array(-1, $selected) ? ' selected' : '').'></option>'."\n";
8403
+				}
7483 8404
 				$out .= '<option value="" disabled>'.$langs->trans("NoUserGroupDefined").'</option>';
7484 8405
 			}
7485 8406
 			$out .= '</select>';
@@ -7520,7 +8441,9 @@  discard block
 block discarded – undo
7520 8441
 
7521 8442
 		$out = '';
7522 8443
 		$id = uniqid();
7523
-                if (!empty($conf->use_javascript_ajax)) $out .= '<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass . 's" name="' . $cssclass . 's" class="checkallactions"></div>';
8444
+                if (!empty($conf->use_javascript_ajax)) {
8445
+                	$out .= '<div class="inline-block checkallactions"><input type="checkbox" id="' . $cssclass . 's" name="' . $cssclass . 's" class="checkallactions"></div>';
8446
+                }
7524 8447
 		$out .= '<script>
7525 8448
             $(document).ready(function() {
7526 8449
                 $("#' . $cssclass . 's").click(function() {
@@ -7533,7 +8456,9 @@  discard block
 block discarded – undo
7533 8456
                         console.log("We uncheck all");
7534 8457
                 		$(".'.$cssclass.'").prop(\'checked\', false).trigger(\'change\');
7535 8458
                     }'."\n";
7536
-                if ($calljsfunction) $out .= 'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname . '", "' . $cssclass . '"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
8459
+                if ($calljsfunction) {
8460
+                	$out .= 'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0, "' . $massactionname . '", "' . $cssclass . '"); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
8461
+                }
7537 8462
 		$out .= '         });
7538 8463
 
7539 8464
                 $(".' . $cssclass . '").change(function() {
@@ -7584,21 +8509,27 @@  discard block
 block discarded – undo
7584 8509
         $out = '';
7585 8510
         $sql = 'SELECT rowid, label FROM '.MAIN_DB_PREFIX.'c_exp_tax_cat WHERE active = 1';
7586 8511
 		$sql .= ' AND entity IN (0,'.getEntity('exp_tax_cat').')';
7587
-		if (!empty($excludeid)) $sql .= ' AND rowid NOT IN ('.implode(',', $excludeid).')';
8512
+		if (!empty($excludeid)) {
8513
+			$sql .= ' AND rowid NOT IN ('.implode(',', $excludeid).')';
8514
+		}
7588 8515
 		$sql .= ' ORDER BY label';
7589 8516
 
7590 8517
 		$resql = $db->query($sql);
7591 8518
 		if ($resql)
7592 8519
 		{
7593 8520
 			$out = '<select id="select_'.$htmlname.'" name="'.$htmlname.'" class="'.$htmlname.' flat minwidth75imp">';
7594
-			if ($useempty) $out .= '<option value="0">&nbsp;</option>';
8521
+			if ($useempty) {
8522
+				$out .= '<option value="0">&nbsp;</option>';
8523
+			}
7595 8524
 
7596 8525
 			while ($obj = $db->fetch_object($resql))
7597 8526
 			{
7598 8527
 				$out .= '<option '.($selected == $obj->rowid ? 'selected="selected"' : '').' value="'.$obj->rowid.'">'.$langs->trans($obj->label).'</option>';
7599 8528
 			}
7600 8529
 			$out .= '</select>';
7601
-			if (!empty($htmlname) && $user->admin) $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
8530
+			if (!empty($htmlname) && $user->admin) {
8531
+				$out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
8532
+			}
7602 8533
 
7603 8534
 			if (!empty($target))
7604 8535
 			{
@@ -7614,7 +8545,9 @@  discard block
 block discarded – undo
7614 8545
 								$("select[name='.$target.']").on("change", function() {
7615 8546
 									var current_val = $(this).val();
7616 8547
 									if (current_val == '.$obj->id.') {';
7617
-						if (!empty($default_selected) || !empty($selected)) $out .= '$("select[name='.$htmlname.']").val("'.($default_selected > 0 ? $default_selected : $selected).'");';
8548
+						if (!empty($default_selected) || !empty($selected)) {
8549
+							$out .= '$("select[name='.$htmlname.']").val("'.($default_selected > 0 ? $default_selected : $selected).'");';
8550
+						}
7618 8551
 
7619 8552
 						$out .= '
7620 8553
 										$("select[name='.$htmlname.']").change();
@@ -7677,7 +8610,9 @@  discard block
 block discarded – undo
7677 8610
 		if ($resql)
7678 8611
 		{
7679 8612
 			$out = '<select id="select_'.$htmlname.'" name="'.$htmlname.'" class="'.$htmlname.' flat minwidth75imp">';
7680
-			if ($useempty) $out .= '<option value="0"></option>';
8613
+			if ($useempty) {
8614
+				$out .= '<option value="0"></option>';
8615
+			}
7681 8616
 
7682 8617
 			while ($obj = $db->fetch_object($resql))
7683 8618
 			{
@@ -7713,11 +8648,17 @@  discard block
 block discarded – undo
7713 8648
 		if ($resql)
7714 8649
 		{
7715 8650
 			$out = '<select id="select_'.$htmlname.'" name="'.$htmlname.'" class="'.$htmlname.' flat minwidth75imp">';
7716
-			if ($useempty) $out .= '<option value="0"></option>';
7717
-			if ($allchoice) $out .= '<option value="-1">'.$langs->trans('AllExpenseReport').'</option>';
8651
+			if ($useempty) {
8652
+				$out .= '<option value="0"></option>';
8653
+			}
8654
+			if ($allchoice) {
8655
+				$out .= '<option value="-1">'.$langs->trans('AllExpenseReport').'</option>';
8656
+			}
7718 8657
 
7719 8658
 			$field = 'code';
7720
-			if ($useid) $field = 'id';
8659
+			if ($useid) {
8660
+				$field = 'id';
8661
+			}
7721 8662
 
7722 8663
 			while ($obj = $db->fetch_object($resql))
7723 8664
 			{
@@ -7764,7 +8705,9 @@  discard block
 block discarded – undo
7764 8705
 		$out = '';
7765 8706
 
7766 8707
 		$hideunselectables = false;
7767
-		if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
8708
+		if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) {
8709
+			$hideunselectables = true;
8710
+		}
7768 8711
 
7769 8712
 		if (empty($projectsListId))
7770 8713
 		{
@@ -7806,8 +8749,11 @@  discard block
 block discarded – undo
7806 8749
 			}
7807 8750
 			if (!empty($show_empty)) {
7808 8751
 				$out .= '<option value="0" class="optiongrey">';
7809
-				if (!is_numeric($show_empty)) $out .= $show_empty;
7810
-				else $out .= '&nbsp;';
8752
+				if (!is_numeric($show_empty)) {
8753
+					$out .= $show_empty;
8754
+				} else {
8755
+					$out .= '&nbsp;';
8756
+				}
7811 8757
 				$out .= '</option>';
7812 8758
 			}
7813 8759
 			$num = $this->db->num_rows($resql);
@@ -7833,7 +8779,10 @@  discard block
 block discarded – undo
7833 8779
 						if ($showproject == 'all')
7834 8780
 						{
7835 8781
 							$labeltoshow .= dol_trunc($obj->ref, 18); // Invoice ref
7836
-							if ($obj->name) $labeltoshow .= ' - '.$obj->name; // Soc name
8782
+							if ($obj->name) {
8783
+								$labeltoshow .= ' - '.$obj->name;
8784
+							}
8785
+							// Soc name
7837 8786
 
7838 8787
 							$disabled = 0;
7839 8788
 							if ($obj->fk_statut == Project::STATUS_DRAFT)
@@ -7842,7 +8791,9 @@  discard block
 block discarded – undo
7842 8791
 								$labeltoshow .= ' - '.$langs->trans("Draft");
7843 8792
 							} elseif ($obj->fk_statut == Project::STATUS_CLOSED)
7844 8793
 							{
7845
-								if ($discard_closed == 2) $disabled = 1;
8794
+								if ($discard_closed == 2) {
8795
+									$disabled = 1;
8796
+								}
7846 8797
 								$labeltoshow .= ' - '.$langs->trans("Closed");
7847 8798
 							} elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid))
7848 8799
 							{
@@ -7862,7 +8813,9 @@  discard block
 block discarded – undo
7862 8813
 								$resultat = '';
7863 8814
 							} else {
7864 8815
 								$resultat = '<option value="'.$obj->rowid.'"';
7865
-								if ($disabled) $resultat .= ' disabled';
8816
+								if ($disabled) {
8817
+									$resultat .= ' disabled';
8818
+								}
7866 8819
 								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
7867 8820
 								//else $labeltoshow.=' ('.$langs->trans("Private").')';
7868 8821
 								$resultat .= '>';
@@ -7919,8 +8872,12 @@  discard block
 block discarded – undo
7919 8872
 		// For compatibility with forms that show themself the search criteria in addition of this component, we output the fields
7920 8873
 		foreach ($arrayofcriterias as $criterias) {
7921 8874
 		    foreach ($criterias as $criteriafamilykey => $criteriafamilyval) {
7922
-		    	if (in_array('search_'.$criteriafamilykey, $arrayofinputfieldsalreadyoutput)) continue;
7923
-		        if (in_array($criteriafamilykey, array('rowid', 'ref_ext', 'entity', 'extraparams'))) continue;
8875
+		    	if (in_array('search_'.$criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
8876
+		    		continue;
8877
+		    	}
8878
+		        if (in_array($criteriafamilykey, array('rowid', 'ref_ext', 'entity', 'extraparams'))) {
8879
+		        	continue;
8880
+		        }
7924 8881
 		        if (in_array($criteriafamilyval['type'], array('date', 'datetime', 'timestamp'))) {
7925 8882
 		            $ret .= '<input type="hidden" name="search_'.$criteriafamilykey.'_start">';
7926 8883
 		            $ret .= '<input type="hidden" name="search_'.$criteriafamilykey.'_startyear">';
Please login to merge, or discard this patch.
htdocs/core/tpl/extrafields_view.tpl.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 if (empty($reshook) && is_array($extrafields->attributes[$object->table_element]['label']))
52 52
 {
53 53
 	$lastseparatorkeyfound = '';
54
-    $extrafields_collapse_num = '';
55
-    $extrafields_collapse_num_old = '';
56
-    $i = 0;
54
+	$extrafields_collapse_num = '';
55
+	$extrafields_collapse_num_old = '';
56
+	$i = 0;
57 57
 	foreach ($extrafields->attributes[$object->table_element]['label'] as $tmpkeyextra => $tmplabelextra)
58 58
 	{
59 59
 		$i++;
@@ -94,19 +94,19 @@  discard block
 block discarded – undo
94 94
 		// Print line tr of extra field
95 95
 		if ($extrafields->attributes[$object->table_element]['type'][$tmpkeyextra] == 'separate')
96 96
 		{
97
-            $extrafields_collapse_num = '';
98
-            $extrafield_param = $extrafields->attributes[$object->table_element]['param'][$tmpkeyextra];
99
-            if (!empty($extrafield_param) && is_array($extrafield_param)) {
100
-                $extrafield_param_list = array_keys($extrafield_param['options']);
97
+			$extrafields_collapse_num = '';
98
+			$extrafield_param = $extrafields->attributes[$object->table_element]['param'][$tmpkeyextra];
99
+			if (!empty($extrafield_param) && is_array($extrafield_param)) {
100
+				$extrafield_param_list = array_keys($extrafield_param['options']);
101 101
 
102
-                if (count($extrafield_param_list) > 0) {
103
-                    $extrafield_collapse_display_value = intval($extrafield_param_list[0]);
102
+				if (count($extrafield_param_list) > 0) {
103
+					$extrafield_collapse_display_value = intval($extrafield_param_list[0]);
104 104
 
105
-                    if ($extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2) {
106
-                        $extrafields_collapse_num = $extrafields->attributes[$object->table_element]['pos'][$tmpkeyextra];
107
-                    }
108
-                }
109
-            }
105
+					if ($extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2) {
106
+						$extrafields_collapse_num = $extrafields->attributes[$object->table_element]['pos'][$tmpkeyextra];
107
+					}
108
+				}
109
+			}
110 110
 
111 111
 			print $extrafields->showSeparator($tmpkeyextra, $object);
112 112
 
@@ -149,11 +149,11 @@  discard block
 block discarded – undo
149 149
 			$isdraft = ((isset($object->statut) && $object->statut == 0) || (isset($object->status) && $object->status == 0));
150 150
 			if (($isdraft || !empty($extrafields->attributes[$object->table_element]['alwayseditable'][$tmpkeyextra]))
151 151
 				&& $permok && $enabled != 5 && ($action != 'edit_extras' || GETPOST('attribute') != $tmpkeyextra)
152
-			    && empty($extrafields->attributes[$object->table_element]['computed'][$tmpkeyextra]))
152
+				&& empty($extrafields->attributes[$object->table_element]['computed'][$tmpkeyextra]))
153 153
 			{
154
-			    $fieldid = 'id';
155
-			    if ($object->table_element == 'societe') $fieldid = 'socid';
156
-			    print '<td class="right"><a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?'.$fieldid.'='.$object->id.'&action=edit_extras&attribute='.$tmpkeyextra.'&ignorecollapsesetup=1">'.img_edit().'</a></td>';
154
+				$fieldid = 'id';
155
+				if ($object->table_element == 'societe') $fieldid = 'socid';
156
+				print '<td class="right"><a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?'.$fieldid.'='.$object->id.'&action=edit_extras&attribute='.$tmpkeyextra.'&ignorecollapsesetup=1">'.img_edit().'</a></td>';
157 157
 			}
158 158
 			print '</tr></table>';
159 159
 			print '</td>';
@@ -178,9 +178,9 @@  discard block
 block discarded – undo
178 178
 			//TODO Improve element and rights detection
179 179
 			if ($action == 'edit_extras' && $permok && GETPOST('attribute', 'none') == $tmpkeyextra)
180 180
 			{
181
-			    $fieldid = 'id';
182
-			    if ($object->table_element == 'societe') $fieldid = 'socid';
183
-			    print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formextra">';
181
+				$fieldid = 'id';
182
+				if ($object->table_element == 'societe') $fieldid = 'socid';
183
+				print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formextra">';
184 184
 				print '<input type="hidden" name="action" value="update_extras">';
185 185
 				print '<input type="hidden" name="attribute" value="'.$tmpkeyextra.'">';
186 186
 				print '<input type="hidden" name="token" value="'.newToken().'">';
Please login to merge, or discard this patch.
Braces   +77 added lines, -25 removed lines patch added patch discarded remove patch
@@ -32,19 +32,31 @@  discard block
 block discarded – undo
32 32
 	exit;
33 33
 }
34 34
 
35
-if (!is_object($form)) $form = new Form($db);
35
+if (!is_object($form)) {
36
+	$form = new Form($db);
37
+}
36 38
 
37 39
 
38 40
 ?>
39 41
 <!-- BEGIN PHP TEMPLATE extrafields_view.tpl.php -->
40 42
 <?php
41
-if (!is_array($parameters)) $parameters = array();
42
-if (!empty($cols)) $parameters['colspan'] = ' colspan="'.$cols.'"';
43
-if (!empty($cols)) $parameters['cols'] = $cols;
44
-if (!empty($object->fk_soc)) $parameters['socid'] = $object->fk_soc;
43
+if (!is_array($parameters)) {
44
+	$parameters = array();
45
+}
46
+if (!empty($cols)) {
47
+	$parameters['colspan'] = ' colspan="'.$cols.'"';
48
+}
49
+if (!empty($cols)) {
50
+	$parameters['cols'] = $cols;
51
+}
52
+if (!empty($object->fk_soc)) {
53
+	$parameters['socid'] = $object->fk_soc;
54
+}
45 55
 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action);
46 56
 print $hookmanager->resPrint;
47
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
57
+if ($reshook < 0) {
58
+	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
59
+}
48 60
 
49 61
 
50 62
 //var_dump($extrafields->attributes[$object->table_element]);
@@ -77,12 +89,23 @@  discard block
 block discarded – undo
77 89
 		}
78 90
 		//print $tmpkeyextra.'-'.$enabled.'-'.$perms.'-'.$tmplabelextra.$_POST["options_" . $tmpkeyextra].'<br>'."\n";
79 91
 
80
-		if (empty($enabled)) continue; // 0 = Never visible field
81
-		if (abs($enabled) != 1 && abs($enabled) != 3 && abs($enabled) != 5 && abs($enabled) != 4) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list <> 4 = not visible at the creation
82
-		if (empty($perms)) continue; // 0 = Not visible
92
+		if (empty($enabled)) {
93
+			continue;
94
+		}
95
+		// 0 = Never visible field
96
+		if (abs($enabled) != 1 && abs($enabled) != 3 && abs($enabled) != 5 && abs($enabled) != 4) {
97
+			continue;
98
+		}
99
+		// <> -1 and <> 1 and <> 3 = not visible on forms, only on list <> 4 = not visible at the creation
100
+		if (empty($perms)) {
101
+			continue;
102
+		}
103
+		// 0 = Not visible
83 104
 
84 105
 		// Load language if required
85
-		if (!empty($extrafields->attributes[$object->table_element]['langfile'][$tmpkeyextra])) $langs->load($extrafields->attributes[$object->table_element]['langfile'][$tmpkeyextra]);
106
+		if (!empty($extrafields->attributes[$object->table_element]['langfile'][$tmpkeyextra])) {
107
+			$langs->load($extrafields->attributes[$object->table_element]['langfile'][$tmpkeyextra]);
108
+		}
86 109
 		if ($action == 'edit_extras')
87 110
 		{
88 111
 			$value = (isset($_POST["options_".$tmpkeyextra]) ? $_POST["options_".$tmpkeyextra] : $object->array_options["options_".$tmpkeyextra]);
@@ -126,25 +149,48 @@  discard block
 block discarded – undo
126 149
 			print '<tr>';
127 150
 
128 151
 			print '<td class="';
129
-			if ((!empty($action) && ($action == 'create' || $action == 'edit')) && !empty($extrafields->attributes[$object->table_element]['required'][$tmpkeyextra])) print ' fieldrequired';
152
+			if ((!empty($action) && ($action == 'create' || $action == 'edit')) && !empty($extrafields->attributes[$object->table_element]['required'][$tmpkeyextra])) {
153
+				print ' fieldrequired';
154
+			}
130 155
 			print '">';
131
-			if (!empty($extrafields->attributes[$object->table_element]['help'][$tmpkeyextra])) print $form->textwithpicto($langs->trans($tmplabelextra), $langs->trans($extrafields->attributes[$object->table_element]['help'][$tmpkeyextra]));
132
-			else print $langs->trans($tmplabelextra);
156
+			if (!empty($extrafields->attributes[$object->table_element]['help'][$tmpkeyextra])) {
157
+				print $form->textwithpicto($langs->trans($tmplabelextra), $langs->trans($extrafields->attributes[$object->table_element]['help'][$tmpkeyextra]));
158
+			} else {
159
+				print $langs->trans($tmplabelextra);
160
+			}
133 161
 			print '</td>';
134 162
 
135 163
 			//TODO Improve element and rights detection
136 164
 			//var_dump($user->rights);
137 165
 			$permok = false;
138 166
 			$keyforperm = $object->element;
139
-			if ($object->element == 'fichinter') $keyforperm = 'ficheinter';
140
-			if (isset($user->rights->$keyforperm)) $permok = $user->rights->$keyforperm->creer || $user->rights->$keyforperm->create || $user->rights->$keyforperm->write;
141
-			if ($object->element == 'order_supplier')   $permok = $user->rights->fournisseur->commande->creer;
142
-			if ($object->element == 'invoice_supplier') $permok = $user->rights->fournisseur->facture->creer;
143
-			if ($object->element == 'shipping')         $permok = $user->rights->expedition->creer;
144
-			if ($object->element == 'delivery')         $permok = $user->rights->expedition->livraison->creer;
145
-			if ($object->element == 'productlot')       $permok = $user->rights->stock->creer;
146
-			if ($object->element == 'facturerec') 	    $permok = $user->rights->facture->creer;
147
-			if ($object->element == 'mo') 	    		$permok = $user->rights->mrp->write;
167
+			if ($object->element == 'fichinter') {
168
+				$keyforperm = 'ficheinter';
169
+			}
170
+			if (isset($user->rights->$keyforperm)) {
171
+				$permok = $user->rights->$keyforperm->creer || $user->rights->$keyforperm->create || $user->rights->$keyforperm->write;
172
+			}
173
+			if ($object->element == 'order_supplier') {
174
+				$permok = $user->rights->fournisseur->commande->creer;
175
+			}
176
+			if ($object->element == 'invoice_supplier') {
177
+				$permok = $user->rights->fournisseur->facture->creer;
178
+			}
179
+			if ($object->element == 'shipping') {
180
+				$permok = $user->rights->expedition->creer;
181
+			}
182
+			if ($object->element == 'delivery') {
183
+				$permok = $user->rights->expedition->livraison->creer;
184
+			}
185
+			if ($object->element == 'productlot') {
186
+				$permok = $user->rights->stock->creer;
187
+			}
188
+			if ($object->element == 'facturerec') {
189
+				$permok = $user->rights->facture->creer;
190
+			}
191
+			if ($object->element == 'mo') {
192
+				$permok = $user->rights->mrp->write;
193
+			}
148 194
 
149 195
 			$isdraft = ((isset($object->statut) && $object->statut == 0) || (isset($object->status) && $object->status == 0));
150 196
 			if (($isdraft || !empty($extrafields->attributes[$object->table_element]['alwayseditable'][$tmpkeyextra]))
@@ -152,7 +198,9 @@  discard block
 block discarded – undo
152 198
 			    && empty($extrafields->attributes[$object->table_element]['computed'][$tmpkeyextra]))
153 199
 			{
154 200
 			    $fieldid = 'id';
155
-			    if ($object->table_element == 'societe') $fieldid = 'socid';
201
+			    if ($object->table_element == 'societe') {
202
+			    	$fieldid = 'socid';
203
+			    }
156 204
 			    print '<td class="right"><a class="reposition editfielda" href="'.$_SERVER['PHP_SELF'].'?'.$fieldid.'='.$object->id.'&action=edit_extras&attribute='.$tmpkeyextra.'&ignorecollapsesetup=1">'.img_edit().'</a></td>';
157 205
 			}
158 206
 			print '</tr></table>';
@@ -167,10 +215,12 @@  discard block
 block discarded – undo
167 215
 			{
168 216
 				$datenotinstring = $object->array_options['options_'.$tmpkeyextra];
169 217
 				// print 'X'.$object->array_options['options_' . $tmpkeyextra].'-'.$datenotinstring.'x';
170
-				if (!is_numeric($object->array_options['options_'.$tmpkeyextra]))	// For backward compatibility
218
+				if (!is_numeric($object->array_options['options_'.$tmpkeyextra])) {
219
+					// For backward compatibility
171 220
 				{
172 221
 					$datenotinstring = $db->jdate($datenotinstring);
173 222
 				}
223
+				}
174 224
 				//print 'x'.$object->array_options['options_' . $tmpkeyextra].'-'.$datenotinstring.' - '.dol_print_date($datenotinstring, 'dayhour');
175 225
 				$value = isset($_POST["options_".$tmpkeyextra]) ? dol_mktime($_POST["options_".$tmpkeyextra."hour"], $_POST["options_".$tmpkeyextra."min"], 0, $_POST["options_".$tmpkeyextra."month"], $_POST["options_".$tmpkeyextra."day"], $_POST["options_".$tmpkeyextra."year"]) : $datenotinstring;
176 226
 			}
@@ -179,7 +229,9 @@  discard block
 block discarded – undo
179 229
 			if ($action == 'edit_extras' && $permok && GETPOST('attribute', 'none') == $tmpkeyextra)
180 230
 			{
181 231
 			    $fieldid = 'id';
182
-			    if ($object->table_element == 'societe') $fieldid = 'socid';
232
+			    if ($object->table_element == 'societe') {
233
+			    	$fieldid = 'socid';
234
+			    }
183 235
 			    print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formextra">';
184 236
 				print '<input type="hidden" name="action" value="update_extras">';
185 237
 				print '<input type="hidden" name="attribute" value="'.$tmpkeyextra.'">';
Please login to merge, or discard this patch.
htdocs/core/menus/standard/eldy.lib.php 1 patch
Indentation   +361 added lines, -361 removed lines patch added patch discarded remove patch
@@ -56,19 +56,19 @@  discard block
 block discarded – undo
56 56
 
57 57
 	if (empty($noout)) print_start_menu_array();
58 58
 
59
-    $usemenuhider = 1;
59
+	$usemenuhider = 1;
60 60
 
61 61
 	// Show/Hide vertical menu. The hamburger icon for .menuhider action.
62 62
 	if ($mode != 'jmobile' && $mode != 'topnb' && $usemenuhider && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
63 63
 	{
64
-    	$showmode = 1;
65
-    	$classname = 'class="tmenu menuhider"';
66
-    	$idsel = 'menu';
64
+		$showmode = 1;
65
+		$classname = 'class="tmenu menuhider"';
66
+		$idsel = 'menu';
67 67
 
68
-    	$menu->add('#', (!empty($conf->global->THEME_TOPMENU_DISABLE_IMAGE) ? '<span class="fa fa-bars"></span>' : ''), 0, $showmode, $atarget, "xxx", '', 0, $id, $idsel, $classname);
68
+		$menu->add('#', (!empty($conf->global->THEME_TOPMENU_DISABLE_IMAGE) ? '<span class="fa fa-bars"></span>' : ''), 0, $showmode, $atarget, "xxx", '', 0, $id, $idsel, $classname);
69 69
 	}
70 70
 
71
-    $menu_arr = array();
71
+	$menu_arr = array();
72 72
 
73 73
 	// Home
74 74
 	$menu_arr[] = array(
@@ -92,9 +92,9 @@  discard block
 block discarded – undo
92 92
 
93 93
 	// Members
94 94
 	$tmpentry = array(
95
-	    'enabled' => (!empty($conf->adherent->enabled)),
96
-	    'perms' => (!empty($user->rights->adherent->lire)),
97
-	    'module' => 'adherent'
95
+		'enabled' => (!empty($conf->adherent->enabled)),
96
+		'perms' => (!empty($user->rights->adherent->lire)),
97
+		'module' => 'adherent'
98 98
 	);
99 99
 	$menu_arr[] = array(
100 100
 		'name' => 'Members',
@@ -117,13 +117,13 @@  discard block
 block discarded – undo
117 117
 
118 118
 	// Third parties
119 119
 	$tmpentry = array(
120
-	    'enabled'=> ((!empty($conf->societe->enabled) &&
121
-	        (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) || empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))
122
-	        )
123
-	        || (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled))
124
-	        ),
125
-	    'perms'=> (!empty($user->rights->societe->lire) || !empty($user->rights->fournisseur->lire)),
126
-	    'module'=>'societe|fournisseur'
120
+		'enabled'=> ((!empty($conf->societe->enabled) &&
121
+			(empty($conf->global->SOCIETE_DISABLE_PROSPECTS) || empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))
122
+			)
123
+			|| (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled))
124
+			),
125
+		'perms'=> (!empty($user->rights->societe->lire) || !empty($user->rights->fournisseur->lire)),
126
+		'module'=>'societe|fournisseur'
127 127
 	);
128 128
 	$menu_arr[] = array(
129 129
 		'name' => 'Companies',
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	$tmpentry = array(
149 149
 		'enabled'=> (!empty($conf->product->enabled) || !empty($conf->service->enabled) || !empty($conf->expedition->enabled)),
150 150
 		'perms'=> (!empty($user->rights->produit->lire) || !empty($user->rights->service->lire) || !empty($user->rights->expedition->lire)),
151
-	    'module'=>'product|service'
151
+		'module'=>'product|service'
152 152
 	);
153 153
 	$menu_arr[] = array(
154 154
 		'name' => 'Products',
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 					? (array("TMenuProducts", " | ", "TMenuServices"))
158 158
 					: (!empty($conf->product->enabled) ? "TMenuProducts" : "TMenuServices"),
159 159
 		'level' => 0,
160
-	    'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
160
+		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
161 161
 		'target' => $atarget,
162 162
 		'mainmenu' => "products",
163 163
 		'leftmenu' => '',
@@ -173,34 +173,34 @@  discard block
 block discarded – undo
173 173
 
174 174
 	// MRP
175 175
 	$tmpentry = array(
176
-	    'enabled'=>(!empty($conf->bom->enabled) || !empty($conf->mrp->enabled)),
177
-	    'perms'=>(!empty($user->rights->bom->read) || !empty($user->rights->mrp->read)),
178
-	    'module'=>'bom|mrp'
176
+		'enabled'=>(!empty($conf->bom->enabled) || !empty($conf->mrp->enabled)),
177
+		'perms'=>(!empty($user->rights->bom->read) || !empty($user->rights->mrp->read)),
178
+		'module'=>'bom|mrp'
179 179
 	);
180 180
 	$menu_arr[] = array(
181
-	    'name' => 'TMenuMRP',
182
-	    'link' => '/mrp/index.php?mainmenu=mrp&amp;leftmenu=',
183
-	    'title' => "TMenuMRP",
184
-	    'level' => 0,
185
-	    'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
186
-	    'target' => $atarget,
187
-	    'mainmenu' => "mrp",
188
-	    'leftmenu' => '',
189
-	    'position' => 30,
190
-	    'id' => $id,
191
-	    'idsel' => 'mrp',
192
-	    'classname' =>  $classname = ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "mrp") ? 'class="tmenusel"' : 'class="tmenu"',
193
-	    'prefix' => '',
194
-	    'session' => (($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "mrp") ? 0 : 1),
195
-	    'loadLangs' => array("mrp"),
196
-	    'submenus' => array(),
181
+		'name' => 'TMenuMRP',
182
+		'link' => '/mrp/index.php?mainmenu=mrp&amp;leftmenu=',
183
+		'title' => "TMenuMRP",
184
+		'level' => 0,
185
+		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
186
+		'target' => $atarget,
187
+		'mainmenu' => "mrp",
188
+		'leftmenu' => '',
189
+		'position' => 30,
190
+		'id' => $id,
191
+		'idsel' => 'mrp',
192
+		'classname' =>  $classname = ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "mrp") ? 'class="tmenusel"' : 'class="tmenu"',
193
+		'prefix' => '',
194
+		'session' => (($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == "mrp") ? 0 : 1),
195
+		'loadLangs' => array("mrp"),
196
+		'submenus' => array(),
197 197
 	);
198 198
 
199 199
 	// Projects
200 200
 	$tmpentry = array(
201
-	    'enabled'=> (!empty($conf->projet->enabled) ? 1 : 0),
202
-	    'perms'=> (!empty($user->rights->projet->lire) ? 1 : 0),
203
-	    'module'=>'projet'
201
+		'enabled'=> (!empty($conf->projet->enabled) ? 1 : 0),
202
+		'perms'=> (!empty($user->rights->projet->lire) ? 1 : 0),
203
+		'module'=>'projet'
204 204
 	);
205 205
 	$menu_arr[] = array(
206 206
 		'name' => 'Projet',
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 					? (($conf->global->PROJECT_USE_OPPORTUNITIES == 2) ? "Leads" : "Projects")
210 210
 					: "Projects",
211 211
 		'level' => 0,
212
-	    'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
212
+		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
213 213
 		'target' => $atarget,
214 214
 		'mainmenu' => "project",
215 215
 		'leftmenu' => '',
@@ -225,14 +225,14 @@  discard block
 block discarded – undo
225 225
 
226 226
 	// Commercial
227 227
 	$tmpentry = array(
228
-	    'enabled'=>(!empty($conf->propal->enabled) ||
229
-	        !empty($conf->commande->enabled) ||
230
-	    	!empty($conf->fournisseur->enabled) ||
231
-	    	!empty($conf->supplier_proposal->enabled) ||
232
-	    	!empty($conf->supplier_order->enabled) ||
233
-	    	!empty($conf->contrat->enabled) ||
234
-	        !empty($conf->ficheinter->enabled)
235
-	        ) ? 1 : 0,
228
+		'enabled'=>(!empty($conf->propal->enabled) ||
229
+			!empty($conf->commande->enabled) ||
230
+			!empty($conf->fournisseur->enabled) ||
231
+			!empty($conf->supplier_proposal->enabled) ||
232
+			!empty($conf->supplier_order->enabled) ||
233
+			!empty($conf->contrat->enabled) ||
234
+			!empty($conf->ficheinter->enabled)
235
+			) ? 1 : 0,
236 236
 		'perms'=>(!empty($user->rights->propal->lire) ||
237 237
 				  !empty($user->rights->commande->lire) ||
238 238
 				  !empty($user->rights->fournisseur->lire) ||
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 				  !empty($user->rights->contrat->lire) ||
242 242
 				  !empty($user->rights->ficheinter->lire)
243 243
 			),
244
-	    'module'=>'propal|commande|supplier_proposal|supplier_order|contrat|ficheinter'
244
+		'module'=>'propal|commande|supplier_proposal|supplier_order|contrat|ficheinter'
245 245
 	);
246 246
 
247 247
 	$onlysupplierorder = !empty($user->rights->fournisseur->commande->lire) &&
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 		'link' => ($onlysupplierorder ? '/fourn/commande/index.php?mainmenu=commercial&amp;leftmenu=' : '/comm/index.php?mainmenu=commercial&amp;leftmenu='),
258 258
 		'title' => "Commercial",
259 259
 		'level' => 0,
260
-	    'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
260
+		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
261 261
 		'target' => $atarget,
262 262
 		'mainmenu' => "commercial",
263 263
 		'leftmenu' => '',
@@ -273,25 +273,25 @@  discard block
 block discarded – undo
273 273
 
274 274
 	// Billing - Financial
275 275
 	$tmpentry = array(
276
-	    'enabled'=>(!empty($conf->facture->enabled) ||
277
-	        !empty($conf->don->enabled) ||
278
-	        !empty($conf->tax->enabled) ||
279
-	        !empty($conf->salaries->enabled) ||
280
-	        !empty($conf->supplier_invoice->enabled) ||
281
-	        !empty($conf->loan->enabled) ||
282
-            !empty($conf->margins->enabled)
283
-	        ) ? 1 : 0,
284
-	    'perms'=>(!empty($user->rights->facture->lire) || !empty($user->rights->don->contact->lire)
285
-	        || !empty($user->rights->tax->charges->lire) || !empty($user->rights->salaries->read)
286
-	        || !empty($user->rights->fournisseur->facture->lire) || !empty($user->rights->loan->read) || !empty($user->rights->margins->liretous)),
287
-	    'module'=>'facture|supplier_invoice|don|tax|salaries|loan'
276
+		'enabled'=>(!empty($conf->facture->enabled) ||
277
+			!empty($conf->don->enabled) ||
278
+			!empty($conf->tax->enabled) ||
279
+			!empty($conf->salaries->enabled) ||
280
+			!empty($conf->supplier_invoice->enabled) ||
281
+			!empty($conf->loan->enabled) ||
282
+			!empty($conf->margins->enabled)
283
+			) ? 1 : 0,
284
+		'perms'=>(!empty($user->rights->facture->lire) || !empty($user->rights->don->contact->lire)
285
+			|| !empty($user->rights->tax->charges->lire) || !empty($user->rights->salaries->read)
286
+			|| !empty($user->rights->fournisseur->facture->lire) || !empty($user->rights->loan->read) || !empty($user->rights->margins->liretous)),
287
+		'module'=>'facture|supplier_invoice|don|tax|salaries|loan'
288 288
 	);
289 289
 	$menu_arr[] = array(
290 290
 		'name' => 'Compta',
291 291
 		'link' => '/compta/index.php?mainmenu=billing&amp;leftmenu=',
292 292
 		'title' =>  "MenuFinancial",
293 293
 		'level' => 0,
294
-	    'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
294
+		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
295 295
 		'target' => $atarget,
296 296
 		'mainmenu' => "billing",
297 297
 		'leftmenu' => '',
@@ -307,16 +307,16 @@  discard block
 block discarded – undo
307 307
 
308 308
 	// Bank
309 309
 	$tmpentry = array(
310
-	    'enabled'=>(!empty($conf->banque->enabled) || !empty($conf->prelevement->enabled)),
310
+		'enabled'=>(!empty($conf->banque->enabled) || !empty($conf->prelevement->enabled)),
311 311
 		'perms'=>(!empty($user->rights->banque->lire) || !empty($user->rights->prelevement->lire) || !empty($user->rights->paymentbybanktransfer->read)),
312
-	    'module'=>'banque|prelevement|paymentbybanktransfer'
312
+		'module'=>'banque|prelevement|paymentbybanktransfer'
313 313
 	);
314 314
 	$menu_arr[] = array(
315 315
 		'name' => 'Bank',
316 316
 		'link' => '/compta/bank/list.php?mainmenu=bank&amp;leftmenu=',
317 317
 		'title' =>  "MenuBankCash",
318 318
 		'level' => 0,
319
-	    'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
319
+		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
320 320
 		'target' => $atarget,
321 321
 		'mainmenu' => "bank",
322 322
 		'leftmenu' => '',
@@ -334,16 +334,16 @@  discard block
 block discarded – undo
334 334
 
335 335
 	// Accounting
336 336
 	$tmpentry = array(
337
-	    'enabled'=>(!empty($conf->comptabilite->enabled) || !empty($conf->accounting->enabled) || !empty($conf->asset->enabled)),
338
-	    'perms'=>(!empty($user->rights->compta->resultat->lire) || !empty($user->rights->accounting->mouvements->lire) || !empty($user->rights->asset->read)),
339
-        'module'=>'comptabilite|accounting|asset'
337
+		'enabled'=>(!empty($conf->comptabilite->enabled) || !empty($conf->accounting->enabled) || !empty($conf->asset->enabled)),
338
+		'perms'=>(!empty($user->rights->compta->resultat->lire) || !empty($user->rights->accounting->mouvements->lire) || !empty($user->rights->asset->read)),
339
+		'module'=>'comptabilite|accounting|asset'
340 340
 	);
341 341
 	$menu_arr[] = array(
342 342
 		'name' => 'Accounting',
343 343
 		'link' => '/accountancy/index.php?mainmenu=accountancy&amp;leftmenu=',
344 344
 		'title' =>  "MenuAccountancy",
345 345
 		'level' => 0,
346
-	    'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
346
+		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
347 347
 		'target' => $atarget,
348 348
 		'mainmenu' => "accountancy",
349 349
 		'leftmenu' => '',
@@ -363,14 +363,14 @@  discard block
 block discarded – undo
363 363
 	$tmpentry = array(
364 364
 		'enabled'=>(!empty($conf->hrm->enabled) || !empty($conf->holiday->enabled) || !empty($conf->deplacement->enabled) || !empty($conf->expensereport->enabled) || !empty($conf->recruitment->enabled)),
365 365
 		'perms'=>(!empty($user->rights->hrm->employee->read) || !empty($user->rights->holiday->write) || !empty($user->rights->deplacement->lire) || !empty($user->rights->expensereport->lire) || !empty($user->rights->recruitment->recruitmentjobposition->read)),
366
-	    'module'=>'hrm|holiday|deplacement|expensereport|recruitment'
366
+		'module'=>'hrm|holiday|deplacement|expensereport|recruitment'
367 367
 	);
368 368
 	$menu_arr[] = array(
369 369
 		'name' => 'HRM',
370 370
 		'link' => '/hrm/index.php?mainmenu=hrm&amp;leftmenu=',
371 371
 		'title' =>  "HRM",
372 372
 		'level' => 0,
373
-	    'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
373
+		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
374 374
 		'target' => $atarget,
375 375
 		'mainmenu' => "hrm",
376 376
 		'leftmenu' => '',
@@ -388,16 +388,16 @@  discard block
 block discarded – undo
388 388
 
389 389
 	// Tools
390 390
 	$tmpentry = array(
391
-	    'enabled'=>1,
392
-	    'perms'=>1,
393
-	    'module'=>''
391
+		'enabled'=>1,
392
+		'perms'=>1,
393
+		'module'=>''
394 394
 	);
395 395
 	$menu_arr[] = array(
396 396
 		'name' => 'Tools',
397 397
 		'link' => '/core/tools.php?mainmenu=tools&amp;leftmenu=',
398 398
 		'title' =>  "Tools",
399 399
 		'level' => 0,
400
-	    'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
400
+		'enabled' => $showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal),
401 401
 		'target' => $atarget,
402 402
 		'mainmenu' => "tools",
403 403
 		'leftmenu' => '',
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 		{
463 463
 			$newTabMenu[$i]['url'] = make_substitutions($newTabMenu[$i]['url'], $substitarray);
464 464
 
465
-		    // url = url from host, shorturl = relative path into dolibarr sources
465
+			// url = url from host, shorturl = relative path into dolibarr sources
466 466
 			$url = $shorturl = $newTabMenu[$i]['url'];
467 467
 			if (!preg_match("/^(http:\/\/|https:\/\/)/i", $newTabMenu[$i]['url']))	// Do not change url content for external links
468 468
 			{
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 				//$url.="idmenu=".$newTabMenu[$i]['rowid'];    // Already done by menuLoad
475 475
 				$url = dol_buildpath($url, 1).($param ? '?'.$param : '');
476 476
 				//$shorturl = $shorturl.($param?'?'.$param:'');
477
-                $shorturl = $url;
477
+				$shorturl = $url;
478 478
 				if (DOL_URL_ROOT) $shorturl = preg_replace('/^'.preg_quote(DOL_URL_ROOT, '/').'/', '', $shorturl);
479 479
 			}
480 480
 
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
 	// Sort on position
491 491
 	$menu->liste = dol_sort_array($menu->liste, 'position');
492 492
 
493
-    // Output menu entries
493
+	// Output menu entries
494 494
 	// Show logo company
495 495
 	if (empty($conf->global->MAIN_MENU_INVERT) && empty($noout) && !empty($conf->global->MAIN_SHOW_LOGO) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
496 496
 	{
@@ -525,20 +525,20 @@  discard block
 block discarded – undo
525 525
 		print_end_menu_entry(4);
526 526
 	}
527 527
 
528
-    if (empty($noout)) {
529
-        foreach ($menu->liste as $menuval) {
530
-            print_start_menu_entry($menuval['idsel'], $menuval['classname'], $menuval['enabled']);
531
-            print_text_menu_entry($menuval['titre'], $menuval['enabled'], (($menuval['url'] != '#' && !preg_match('/^(http:\/\/|https:\/\/)/i', $menuval['url'])) ? DOL_URL_ROOT:'').$menuval['url'], $menuval['id'], $menuval['idsel'], $menuval['classname'], ($menuval['target'] ? $menuval['target'] : $atarget));
532
-            print_end_menu_entry($menuval['enabled']);
533
-        }
534
-    }
528
+	if (empty($noout)) {
529
+		foreach ($menu->liste as $menuval) {
530
+			print_start_menu_entry($menuval['idsel'], $menuval['classname'], $menuval['enabled']);
531
+			print_text_menu_entry($menuval['titre'], $menuval['enabled'], (($menuval['url'] != '#' && !preg_match('/^(http:\/\/|https:\/\/)/i', $menuval['url'])) ? DOL_URL_ROOT:'').$menuval['url'], $menuval['id'], $menuval['idsel'], $menuval['classname'], ($menuval['target'] ? $menuval['target'] : $atarget));
532
+			print_end_menu_entry($menuval['enabled']);
533
+		}
534
+	}
535 535
 
536 536
 	$showmode = 1;
537
-    if (empty($noout)) {
538
-        print_start_menu_entry('', 'class="tmenuend"', $showmode);
539
-        print_end_menu_entry($showmode);
540
-        print_end_menu_array();
541
-    }
537
+	if (empty($noout)) {
538
+		print_start_menu_entry('', 'class="tmenuend"', $showmode);
539
+		print_end_menu_entry($showmode);
540
+		print_end_menu_array();
541
+	}
542 542
 
543 543
 	return 0;
544 544
 }
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
  */
552 552
 function print_start_menu_array()
553 553
 {
554
-    global $conf;
554
+	global $conf;
555 555
 
556 556
 	print '<div class="tmenudiv">';
557 557
 	print '<ul role="navigation" class="tmenu"'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '' : ' title="Top menu"').'>';
@@ -665,26 +665,26 @@  discard block
 block discarded – undo
665 665
 	$mainmenu = ($forcemainmenu ? $forcemainmenu : $_SESSION["mainmenu"]);
666 666
 	$leftmenu = ($forceleftmenu ? '' : (empty($_SESSION["leftmenu"]) ? 'none' : $_SESSION["leftmenu"]));
667 667
 
668
-    $usemenuhider = 0;
668
+	$usemenuhider = 0;
669 669
 
670 670
 	if (is_array($moredata) && !empty($moredata['searchform']))	// searchform can contains select2 code or link to show old search form or link to switch on search page
671 671
 	{
672
-        print "\n";
673
-        print "<!-- Begin SearchForm -->\n";
674
-        print '<div id="blockvmenusearch" class="blockvmenusearch">'."\n";
675
-        print $moredata['searchform'];
676
-        print '</div>'."\n";
677
-        print "<!-- End SearchForm -->\n";
672
+		print "\n";
673
+		print "<!-- Begin SearchForm -->\n";
674
+		print '<div id="blockvmenusearch" class="blockvmenusearch">'."\n";
675
+		print $moredata['searchform'];
676
+		print '</div>'."\n";
677
+		print "<!-- End SearchForm -->\n";
678 678
 	}
679 679
 
680 680
 	if (is_array($moredata) && !empty($moredata['bookmarks']))
681 681
 	{
682
-	    print "\n";
683
-	    print "<!-- Begin Bookmarks -->\n";
684
-	    print '<div id="blockvmenubookmarks" class="blockvmenubookmarks">'."\n";
685
-	    print $moredata['bookmarks'];
686
-	    print '</div>'."\n";
687
-	    print "<!-- End Bookmarks -->\n";
682
+		print "\n";
683
+		print "<!-- Begin Bookmarks -->\n";
684
+		print '<div id="blockvmenubookmarks" class="blockvmenubookmarks">'."\n";
685
+		print $moredata['bookmarks'];
686
+		print '</div>'."\n";
687
+		print "<!-- End Bookmarks -->\n";
688 688
 	}
689 689
 
690 690
 	$substitarray = getCommonSubstitutionArray($langs, 0, null, null);
@@ -710,8 +710,8 @@  discard block
 block discarded – undo
710 710
 
711 711
 			if ($usemenuhider || empty($leftmenu) || $leftmenu == "setup")
712 712
 			{
713
-			    // Load translation files required by the page
714
-                $langs->loadLangs(array("admin", "help"));
713
+				// Load translation files required by the page
714
+				$langs->loadLangs(array("admin", "help"));
715 715
 
716 716
 				$warnpicto = '';
717 717
 				if (empty($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY))
@@ -747,15 +747,15 @@  discard block
 block discarded – undo
747 747
 			$newmenu->add("/admin/tools/index.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("AdminTools"), 0, $user->admin, '', $mainmenu, 'admintools', 0, '', '', '', '<i class="fa fa-server fa-fw paddingright"></i>');
748 748
 			if ($usemenuhider || empty($leftmenu) || preg_match('/^admintools/', $leftmenu))
749 749
 			{
750
-			    // Load translation files required by the page
751
-                $langs->loadLangs(array('admin', 'help'));
750
+				// Load translation files required by the page
751
+				$langs->loadLangs(array('admin', 'help'));
752 752
 
753 753
 				$newmenu->add('/admin/system/dolibarr.php?mainmenu=home&amp;leftmenu=admintools_info', $langs->trans('InfoDolibarr'), 1);
754 754
 				if ($usemenuhider || empty($leftmenu) || $leftmenu == 'admintools_info') {
755
-                    $newmenu->add('/admin/system/modules.php?mainmenu=home&amp;leftmenu=admintools_info', $langs->trans('Modules'), 2);
756
-				    $newmenu->add('/admin/triggers.php?mainmenu=home&amp;leftmenu=admintools_info', $langs->trans('Triggers'), 2);
757
-                    $newmenu->add('/admin/system/filecheck.php?mainmenu=home&amp;leftmenu=admintools_info', $langs->trans('FileCheck'), 2);
758
-                }
755
+					$newmenu->add('/admin/system/modules.php?mainmenu=home&amp;leftmenu=admintools_info', $langs->trans('Modules'), 2);
756
+					$newmenu->add('/admin/triggers.php?mainmenu=home&amp;leftmenu=admintools_info', $langs->trans('Triggers'), 2);
757
+					$newmenu->add('/admin/system/filecheck.php?mainmenu=home&amp;leftmenu=admintools_info', $langs->trans('FileCheck'), 2);
758
+				}
759 759
 				$newmenu->add('/admin/system/browser.php?mainmenu=home&amp;leftmenu=admintools', $langs->trans('InfoBrowser'), 1);
760 760
 				$newmenu->add('/admin/system/os.php?mainmenu=home&amp;leftmenu=admintools', $langs->trans('InfoOS'), 1);
761 761
 				$newmenu->add('/admin/system/web.php?mainmenu=home&amp;leftmenu=admintools', $langs->trans('InfoWebServer'), 1);
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
 				if (!empty($conf->product->enabled) || !empty($conf->service->enabled))
775 775
 				{
776 776
 					$langs->load("products");
777
-				    $newmenu->add("/product/admin/product_tools.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("ProductVatMassChange"), 1, $user->admin);
777
+					$newmenu->add("/product/admin/product_tools.php?mainmenu=home&amp;leftmenu=admintools", $langs->trans("ProductVatMassChange"), 1, $user->admin);
778 778
 				}
779 779
 			}
780 780
 
@@ -905,33 +905,33 @@  discard block
 block discarded – undo
905 905
 				$newmenu->add("/comm/propal/card.php?action=create&amp;leftmenu=propals", $langs->trans("NewPropal"), 1, $user->rights->propale->creer);
906 906
 				$newmenu->add("/comm/propal/list.php?leftmenu=propals", $langs->trans("List"), 1, $user->rights->propale->lire);
907 907
 				if ($usemenuhider || empty($leftmenu) || $leftmenu == "propals") {
908
-                    $newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=0", $langs->trans("PropalsDraft"), 2, $user->rights->propale->lire);
909
-				    $newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=1", $langs->trans("PropalsOpened"), 2, $user->rights->propale->lire);
910
-				    $newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=2", $langs->trans("PropalStatusSigned"), 2, $user->rights->propale->lire);
911
-				    $newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=3", $langs->trans("PropalStatusNotSigned"), 2, $user->rights->propale->lire);
912
-				    $newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=4", $langs->trans("PropalStatusBilled"), 2, $user->rights->propale->lire);
913
-                    //$newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=2,3,4", $langs->trans("PropalStatusClosedShort"), 2, $user->rights->propale->lire);
914
-                }
908
+					$newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=0", $langs->trans("PropalsDraft"), 2, $user->rights->propale->lire);
909
+					$newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=1", $langs->trans("PropalsOpened"), 2, $user->rights->propale->lire);
910
+					$newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=2", $langs->trans("PropalStatusSigned"), 2, $user->rights->propale->lire);
911
+					$newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=3", $langs->trans("PropalStatusNotSigned"), 2, $user->rights->propale->lire);
912
+					$newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=4", $langs->trans("PropalStatusBilled"), 2, $user->rights->propale->lire);
913
+					//$newmenu->add("/comm/propal/list.php?leftmenu=propals&search_status=2,3,4", $langs->trans("PropalStatusClosedShort"), 2, $user->rights->propale->lire);
914
+				}
915 915
 				$newmenu->add("/comm/propal/stats/index.php?leftmenu=propals", $langs->trans("Statistics"), 1, $user->rights->propale->lire);
916 916
 			}
917 917
 
918
-            // Customers orders
919
-            if (!empty($conf->commande->enabled))
920
-            {
921
-                $langs->load("orders");
922
-                $newmenu->add("/commande/index.php?leftmenu=orders", $langs->trans("CustomersOrders"), 0, $user->rights->commande->lire, '', $mainmenu, 'orders', 200);
923
-                $newmenu->add("/commande/card.php?action=create&amp;leftmenu=orders", $langs->trans("NewOrder"), 1, $user->rights->commande->creer);
924
-                $newmenu->add("/commande/list.php?leftmenu=orders", $langs->trans("List"), 1, $user->rights->commande->lire);
925
-                if ($usemenuhider || empty($leftmenu) || $leftmenu == "orders") {
926
-                    $newmenu->add("/commande/list.php?leftmenu=orders&search_status=0", $langs->trans("StatusOrderDraftShort"), 2, $user->rights->commande->lire);
927
-                    $newmenu->add("/commande/list.php?leftmenu=orders&search_status=1", $langs->trans("StatusOrderValidated"), 2, $user->rights->commande->lire);
928
-                    if (!empty($conf->expedition->enabled)) $newmenu->add("/commande/list.php?leftmenu=orders&search_status=2", $langs->trans("StatusOrderSentShort"), 2, $user->rights->commande->lire);
929
-                    $newmenu->add("/commande/list.php?leftmenu=orders&search_status=3", $langs->trans("StatusOrderDelivered"), 2, $user->rights->commande->lire);
930
-                    //$newmenu->add("/commande/list.php?leftmenu=orders&search_status=4", $langs->trans("StatusOrderProcessed"), 2, $user->rights->commande->lire);
931
-                    $newmenu->add("/commande/list.php?leftmenu=orders&search_status=-1", $langs->trans("StatusOrderCanceledShort"), 2, $user->rights->commande->lire);
932
-                }
933
-                $newmenu->add("/commande/stats/index.php?leftmenu=orders", $langs->trans("Statistics"), 1, $user->rights->commande->lire);
934
-            }
918
+			// Customers orders
919
+			if (!empty($conf->commande->enabled))
920
+			{
921
+				$langs->load("orders");
922
+				$newmenu->add("/commande/index.php?leftmenu=orders", $langs->trans("CustomersOrders"), 0, $user->rights->commande->lire, '', $mainmenu, 'orders', 200);
923
+				$newmenu->add("/commande/card.php?action=create&amp;leftmenu=orders", $langs->trans("NewOrder"), 1, $user->rights->commande->creer);
924
+				$newmenu->add("/commande/list.php?leftmenu=orders", $langs->trans("List"), 1, $user->rights->commande->lire);
925
+				if ($usemenuhider || empty($leftmenu) || $leftmenu == "orders") {
926
+					$newmenu->add("/commande/list.php?leftmenu=orders&search_status=0", $langs->trans("StatusOrderDraftShort"), 2, $user->rights->commande->lire);
927
+					$newmenu->add("/commande/list.php?leftmenu=orders&search_status=1", $langs->trans("StatusOrderValidated"), 2, $user->rights->commande->lire);
928
+					if (!empty($conf->expedition->enabled)) $newmenu->add("/commande/list.php?leftmenu=orders&search_status=2", $langs->trans("StatusOrderSentShort"), 2, $user->rights->commande->lire);
929
+					$newmenu->add("/commande/list.php?leftmenu=orders&search_status=3", $langs->trans("StatusOrderDelivered"), 2, $user->rights->commande->lire);
930
+					//$newmenu->add("/commande/list.php?leftmenu=orders&search_status=4", $langs->trans("StatusOrderProcessed"), 2, $user->rights->commande->lire);
931
+					$newmenu->add("/commande/list.php?leftmenu=orders&search_status=-1", $langs->trans("StatusOrderCanceledShort"), 2, $user->rights->commande->lire);
932
+				}
933
+				$newmenu->add("/commande/stats/index.php?leftmenu=orders", $langs->trans("Statistics"), 1, $user->rights->commande->lire);
934
+			}
935 935
 
936 936
 			// Supplier proposal
937 937
 			if (!empty($conf->supplier_proposal->enabled))
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
 			}
945 945
 
946 946
 			// Suppliers orders
947
-            if (!empty($conf->supplier_order->enabled))
947
+			if (!empty($conf->supplier_order->enabled))
948 948
 			{
949 949
 				$langs->load("orders");
950 950
 				$newmenu->add("/fourn/commande/index.php?leftmenu=orders_suppliers", $langs->trans("SuppliersOrders"), 0, $user->rights->fournisseur->commande->lire, '', $mainmenu, 'orders_suppliers', 400);
@@ -952,16 +952,16 @@  discard block
 block discarded – undo
952 952
 				$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers", $langs->trans("List"), 1, $user->rights->fournisseur->commande->lire);
953 953
 
954 954
 				if ($usemenuhider || empty($leftmenu) || $leftmenu == "orders_suppliers") {
955
-                    $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=0", $langs->trans("StatusSupplierOrderDraftShort"), 2, $user->rights->fournisseur->commande->lire);
956
-                    if (empty($conf->global->SUPPLIER_ORDER_HIDE_VALIDATED)) $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=1", $langs->trans("StatusSupplierOrderValidated"), 2, $user->rights->fournisseur->commande->lire);
957
-                    $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=2", $langs->trans("StatusSupplierOrderApprovedShort"), 2, $user->rights->fournisseur->commande->lire);
958
-                    $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=3", $langs->trans("StatusSupplierOrderOnProcessShort"), 2, $user->rights->fournisseur->commande->lire);
959
-                    $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=4", $langs->trans("StatusSupplierOrderReceivedPartiallyShort"), 2, $user->rights->fournisseur->commande->lire);
960
-                    $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=5", $langs->trans("StatusSupplierOrderReceivedAll"), 2, $user->rights->fournisseur->commande->lire);
961
-                    $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=6,7", $langs->trans("StatusSupplierOrderCanceled"), 2, $user->rights->fournisseur->commande->lire);
962
-                    $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=9", $langs->trans("StatusSupplierOrderRefused"), 2, $user->rights->fournisseur->commande->lire);
963
-                }
964
-                // Billed is another field. We should add instead a dedicated filter on list. if ($usemenuhider || empty($leftmenu) || $leftmenu=="orders_suppliers") $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&billed=1", $langs->trans("Billed"), 2, $user->rights->fournisseur->commande->lire);
955
+					$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=0", $langs->trans("StatusSupplierOrderDraftShort"), 2, $user->rights->fournisseur->commande->lire);
956
+					if (empty($conf->global->SUPPLIER_ORDER_HIDE_VALIDATED)) $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=1", $langs->trans("StatusSupplierOrderValidated"), 2, $user->rights->fournisseur->commande->lire);
957
+					$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=2", $langs->trans("StatusSupplierOrderApprovedShort"), 2, $user->rights->fournisseur->commande->lire);
958
+					$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=3", $langs->trans("StatusSupplierOrderOnProcessShort"), 2, $user->rights->fournisseur->commande->lire);
959
+					$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=4", $langs->trans("StatusSupplierOrderReceivedPartiallyShort"), 2, $user->rights->fournisseur->commande->lire);
960
+					$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=5", $langs->trans("StatusSupplierOrderReceivedAll"), 2, $user->rights->fournisseur->commande->lire);
961
+					$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=6,7", $langs->trans("StatusSupplierOrderCanceled"), 2, $user->rights->fournisseur->commande->lire);
962
+					$newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=9", $langs->trans("StatusSupplierOrderRefused"), 2, $user->rights->fournisseur->commande->lire);
963
+				}
964
+				// Billed is another field. We should add instead a dedicated filter on list. if ($usemenuhider || empty($leftmenu) || $leftmenu=="orders_suppliers") $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&billed=1", $langs->trans("Billed"), 2, $user->rights->fournisseur->commande->lire);
965 965
 
966 966
 
967 967
 				$newmenu->add("/commande/stats/index.php?leftmenu=orders_suppliers&amp;mode=supplier", $langs->trans("Statistics"), 1, $user->rights->fournisseur->commande->lire);
@@ -976,11 +976,11 @@  discard block
 block discarded – undo
976 976
 				$newmenu->add("/contrat/list.php?leftmenu=contracts", $langs->trans("List"), 1, $user->rights->contrat->lire);
977 977
 				$newmenu->add("/contrat/services_list.php?leftmenu=contracts", $langs->trans("MenuServices"), 1, $user->rights->contrat->lire);
978 978
 				if ($usemenuhider || empty($leftmenu) || $leftmenu == "contracts") {
979
-                    $newmenu->add("/contrat/services_list.php?leftmenu=contracts&amp;mode=0", $langs->trans("MenuInactiveServices"), 2, $user->rights->contrat->lire);
980
-				    $newmenu->add("/contrat/services_list.php?leftmenu=contracts&amp;mode=4", $langs->trans("MenuRunningServices"), 2, $user->rights->contrat->lire);
981
-				    $newmenu->add("/contrat/services_list.php?leftmenu=contracts&amp;mode=4&amp;filter=expired", $langs->trans("MenuExpiredServices"), 2, $user->rights->contrat->lire);
982
-                    $newmenu->add("/contrat/services_list.php?leftmenu=contracts&amp;mode=5", $langs->trans("MenuClosedServices"), 2, $user->rights->contrat->lire);
983
-                }
979
+					$newmenu->add("/contrat/services_list.php?leftmenu=contracts&amp;mode=0", $langs->trans("MenuInactiveServices"), 2, $user->rights->contrat->lire);
980
+					$newmenu->add("/contrat/services_list.php?leftmenu=contracts&amp;mode=4", $langs->trans("MenuRunningServices"), 2, $user->rights->contrat->lire);
981
+					$newmenu->add("/contrat/services_list.php?leftmenu=contracts&amp;mode=4&amp;filter=expired", $langs->trans("MenuExpiredServices"), 2, $user->rights->contrat->lire);
982
+					$newmenu->add("/contrat/services_list.php?leftmenu=contracts&amp;mode=5", $langs->trans("MenuClosedServices"), 2, $user->rights->contrat->lire);
983
+				}
984 984
 			}
985 985
 
986 986
 			// Interventions
@@ -1078,9 +1078,9 @@  discard block
 block discarded – undo
1078 1078
 				$langs->load("donations");
1079 1079
 				$newmenu->add("/don/index.php?leftmenu=donations&amp;mainmenu=billing", $langs->trans("Donations"), 0, $user->rights->don->lire, '', $mainmenu, 'donations');
1080 1080
 				if ($usemenuhider || empty($leftmenu) || $leftmenu == "donations") {
1081
-                    $newmenu->add("/don/card.php?leftmenu=donations&amp;action=create", $langs->trans("NewDonation"), 1, $user->rights->don->creer);
1082
-                    $newmenu->add("/don/list.php?leftmenu=donations", $langs->trans("List"), 1, $user->rights->don->lire);
1083
-                }
1081
+					$newmenu->add("/don/card.php?leftmenu=donations&amp;action=create", $langs->trans("NewDonation"), 1, $user->rights->don->creer);
1082
+					$newmenu->add("/don/list.php?leftmenu=donations", $langs->trans("List"), 1, $user->rights->don->lire);
1083
+				}
1084 1084
 				// if ($leftmenu=="donations") $newmenu->add("/don/stats/index.php",$langs->trans("Statistics"), 1, $user->rights->don->lire);
1085 1085
 			}
1086 1086
 
@@ -1097,21 +1097,21 @@  discard block
 block discarded – undo
1097 1097
 				{
1098 1098
 					$newmenu->add("/compta/sociales/list.php?leftmenu=tax_social", $langs->trans("MenuSocialContributions"), 1, $user->rights->tax->charges->lire);
1099 1099
 					if ($usemenuhider || empty($leftmenu) || preg_match('/^tax_social/i', $leftmenu)) {
1100
-                        $newmenu->add("/compta/sociales/card.php?leftmenu=tax_social&action=create", $langs->trans("MenuNewSocialContribution"), 2, $user->rights->tax->charges->creer);
1101
-					    $newmenu->add("/compta/sociales/list.php?leftmenu=tax_social", $langs->trans("List"), 2, $user->rights->tax->charges->lire);
1102
-                        $newmenu->add("/compta/sociales/payments.php?leftmenu=tax_social&amp;mainmenu=billing&amp;mode=sconly", $langs->trans("Payments"), 2, $user->rights->tax->charges->lire);
1103
-                    }
1100
+						$newmenu->add("/compta/sociales/card.php?leftmenu=tax_social&action=create", $langs->trans("MenuNewSocialContribution"), 2, $user->rights->tax->charges->creer);
1101
+						$newmenu->add("/compta/sociales/list.php?leftmenu=tax_social", $langs->trans("List"), 2, $user->rights->tax->charges->lire);
1102
+						$newmenu->add("/compta/sociales/payments.php?leftmenu=tax_social&amp;mainmenu=billing&amp;mode=sconly", $langs->trans("Payments"), 2, $user->rights->tax->charges->lire);
1103
+					}
1104 1104
 					// VAT
1105 1105
 					if (empty($conf->global->TAX_DISABLE_VAT_MENUS))
1106 1106
 					{
1107 1107
 						$newmenu->add("/compta/tva/list.php?leftmenu=tax_vat&amp;mainmenu=billing", $langs->transcountry("VAT", $mysoc->country_code), 1, $user->rights->tax->charges->lire, '', $mainmenu, 'tax_vat');
1108 1108
 						if ($usemenuhider || empty($leftmenu) || preg_match('/^tax_vat/i', $leftmenu)) {
1109
-                            $newmenu->add("/compta/tva/card.php?leftmenu=tax_vat&action=create", $langs->trans("New"), 2, $user->rights->tax->charges->creer);
1110
-						    $newmenu->add("/compta/tva/list.php?leftmenu=tax_vat", $langs->trans("List"), 2, $user->rights->tax->charges->lire);
1111
-						    $newmenu->add("/compta/tva/index.php?leftmenu=tax_vat", $langs->trans("ReportByMonth"), 2, $user->rights->tax->charges->lire);
1112
-						    $newmenu->add("/compta/tva/clients.php?leftmenu=tax_vat", $langs->trans("ReportByCustomers"), 2, $user->rights->tax->charges->lire);
1113
-                            $newmenu->add("/compta/tva/quadri_detail.php?leftmenu=tax_vat", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire);
1114
-                        }
1109
+							$newmenu->add("/compta/tva/card.php?leftmenu=tax_vat&action=create", $langs->trans("New"), 2, $user->rights->tax->charges->creer);
1110
+							$newmenu->add("/compta/tva/list.php?leftmenu=tax_vat", $langs->trans("List"), 2, $user->rights->tax->charges->lire);
1111
+							$newmenu->add("/compta/tva/index.php?leftmenu=tax_vat", $langs->trans("ReportByMonth"), 2, $user->rights->tax->charges->lire);
1112
+							$newmenu->add("/compta/tva/clients.php?leftmenu=tax_vat", $langs->trans("ReportByCustomers"), 2, $user->rights->tax->charges->lire);
1113
+							$newmenu->add("/compta/tva/quadri_detail.php?leftmenu=tax_vat", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire);
1114
+						}
1115 1115
 						global $mysoc;
1116 1116
 
1117 1117
 						//Local Taxes 1
@@ -1119,24 +1119,24 @@  discard block
 block discarded – undo
1119 1119
 						{
1120 1120
 							$newmenu->add("/compta/localtax/list.php?leftmenu=tax_1_vat&amp;mainmenu=billing&amp;localTaxType=1", $langs->transcountry("LT1", $mysoc->country_code), 1, $user->rights->tax->charges->lire);
1121 1121
 							if ($usemenuhider || empty($leftmenu) || preg_match('/^tax_1_vat/i', $leftmenu)) {
1122
-                                $newmenu->add("/compta/localtax/card.php?leftmenu=tax_1_vat&action=create&amp;localTaxType=1", $langs->trans("New"), 2, $user->rights->tax->charges->creer);
1123
-							    $newmenu->add("/compta/localtax/list.php?leftmenu=tax_1_vat&amp;localTaxType=1", $langs->trans("List"), 2, $user->rights->tax->charges->lire);
1124
-							    $newmenu->add("/compta/localtax/index.php?leftmenu=tax_1_vat&amp;localTaxType=1", $langs->trans("ReportByMonth"), 2, $user->rights->tax->charges->lire);
1125
-							    $newmenu->add("/compta/localtax/clients.php?leftmenu=tax_1_vat&amp;localTaxType=1", $langs->trans("ReportByCustomers"), 2, $user->rights->tax->charges->lire);
1126
-                                $newmenu->add("/compta/localtax/quadri_detail.php?leftmenu=tax_1_vat&amp;localTaxType=1", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire);
1127
-                            }
1122
+								$newmenu->add("/compta/localtax/card.php?leftmenu=tax_1_vat&action=create&amp;localTaxType=1", $langs->trans("New"), 2, $user->rights->tax->charges->creer);
1123
+								$newmenu->add("/compta/localtax/list.php?leftmenu=tax_1_vat&amp;localTaxType=1", $langs->trans("List"), 2, $user->rights->tax->charges->lire);
1124
+								$newmenu->add("/compta/localtax/index.php?leftmenu=tax_1_vat&amp;localTaxType=1", $langs->trans("ReportByMonth"), 2, $user->rights->tax->charges->lire);
1125
+								$newmenu->add("/compta/localtax/clients.php?leftmenu=tax_1_vat&amp;localTaxType=1", $langs->trans("ReportByCustomers"), 2, $user->rights->tax->charges->lire);
1126
+								$newmenu->add("/compta/localtax/quadri_detail.php?leftmenu=tax_1_vat&amp;localTaxType=1", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire);
1127
+							}
1128 1128
 						}
1129 1129
 						//Local Taxes 2
1130 1130
 						if ($mysoc->useLocalTax(2) && (isset($mysoc->localtax2_assuj) && $mysoc->localtax2_assuj == "1"))
1131 1131
 						{
1132 1132
 							$newmenu->add("/compta/localtax/list.php?leftmenu=tax_2_vat&amp;mainmenu=billing&amp;localTaxType=2", $langs->transcountry("LT2", $mysoc->country_code), 1, $user->rights->tax->charges->lire);
1133 1133
 							if ($usemenuhider || empty($leftmenu) || preg_match('/^tax_2_vat/i', $leftmenu)) {
1134
-                                $newmenu->add("/compta/localtax/card.php?leftmenu=tax_2_vat&action=create&amp;localTaxType=2", $langs->trans("New"), 2, $user->rights->tax->charges->creer);
1135
-							    $newmenu->add("/compta/localtax/list.php?leftmenu=tax_2_vat&amp;localTaxType=2", $langs->trans("List"), 2, $user->rights->tax->charges->lire);
1136
-							    $newmenu->add("/compta/localtax/index.php?leftmenu=tax_2_vat&amp;localTaxType=2", $langs->trans("ReportByMonth"), 2, $user->rights->tax->charges->lire);
1137
-							    $newmenu->add("/compta/localtax/clients.php?leftmenu=tax_2_vat&amp;localTaxType=2", $langs->trans("ReportByCustomers"), 2, $user->rights->tax->charges->lire);
1138
-                                $newmenu->add("/compta/localtax/quadri_detail.php?leftmenu=tax_2_vat&amp;localTaxType=2", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire);
1139
-                            }
1134
+								$newmenu->add("/compta/localtax/card.php?leftmenu=tax_2_vat&action=create&amp;localTaxType=2", $langs->trans("New"), 2, $user->rights->tax->charges->creer);
1135
+								$newmenu->add("/compta/localtax/list.php?leftmenu=tax_2_vat&amp;localTaxType=2", $langs->trans("List"), 2, $user->rights->tax->charges->lire);
1136
+								$newmenu->add("/compta/localtax/index.php?leftmenu=tax_2_vat&amp;localTaxType=2", $langs->trans("ReportByMonth"), 2, $user->rights->tax->charges->lire);
1137
+								$newmenu->add("/compta/localtax/clients.php?leftmenu=tax_2_vat&amp;localTaxType=2", $langs->trans("ReportByCustomers"), 2, $user->rights->tax->charges->lire);
1138
+								$newmenu->add("/compta/localtax/quadri_detail.php?leftmenu=tax_2_vat&amp;localTaxType=2", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire);
1139
+							}
1140 1140
 						}
1141 1141
 					}
1142 1142
 				}
@@ -1147,10 +1147,10 @@  discard block
 block discarded – undo
1147 1147
 					$langs->load("salaries");
1148 1148
 					$newmenu->add("/salaries/list.php?leftmenu=tax_salary&amp;mainmenu=billing", $langs->trans("Salaries"), 0, $user->rights->salaries->read, '', $mainmenu, 'tax_salary');
1149 1149
 					if ($usemenuhider || empty($leftmenu) || preg_match('/^tax_salary/i', $leftmenu)) {
1150
-                        $newmenu->add("/salaries/card.php?leftmenu=tax_salary&action=create", $langs->trans("NewPayment"), 1, $user->rights->salaries->write);
1151
-					    $newmenu->add("/salaries/list.php?leftmenu=tax_salary", $langs->trans("Payments"), 1, $user->rights->salaries->read);
1152
-                        $newmenu->add("/salaries/stats/index.php?leftmenu=tax_salary", $langs->trans("Statistics"), 1, $user->rights->salaries->read);
1153
-                    }
1150
+						$newmenu->add("/salaries/card.php?leftmenu=tax_salary&action=create", $langs->trans("NewPayment"), 1, $user->rights->salaries->write);
1151
+						$newmenu->add("/salaries/list.php?leftmenu=tax_salary", $langs->trans("Payments"), 1, $user->rights->salaries->read);
1152
+						$newmenu->add("/salaries/stats/index.php?leftmenu=tax_salary", $langs->trans("Statistics"), 1, $user->rights->salaries->read);
1153
+					}
1154 1154
 				}
1155 1155
 
1156 1156
 				// Loan
@@ -1159,9 +1159,9 @@  discard block
 block discarded – undo
1159 1159
 					$langs->load("loan");
1160 1160
 					$newmenu->add("/loan/list.php?leftmenu=tax_loan&amp;mainmenu=billing", $langs->trans("Loans"), 0, $user->rights->loan->read, '', $mainmenu, 'tax_loan');
1161 1161
 					if ($usemenuhider || empty($leftmenu) || preg_match('/^tax_loan/i', $leftmenu)) {
1162
-                        $newmenu->add("/loan/card.php?leftmenu=tax_loan&action=create", $langs->trans("NewLoan"), 1, $user->rights->loan->write);
1163
-                        //$newmenu->add("/loan/payment/list.php?leftmenu=tax_loan",$langs->trans("Payments"),2,$user->rights->loan->read);
1164
-                    }
1162
+						$newmenu->add("/loan/card.php?leftmenu=tax_loan&action=create", $langs->trans("NewLoan"), 1, $user->rights->loan->write);
1163
+						//$newmenu->add("/loan/payment/list.php?leftmenu=tax_loan",$langs->trans("Payments"),2,$user->rights->loan->read);
1164
+					}
1165 1165
 				}
1166 1166
 
1167 1167
 				// Various payment
@@ -1170,9 +1170,9 @@  discard block
 block discarded – undo
1170 1170
 					$langs->load("banks");
1171 1171
 					$newmenu->add("/compta/bank/various_payment/list.php?leftmenu=tax_various&amp;mainmenu=billing", $langs->trans("MenuVariousPayment"), 0, $user->rights->banque->lire, '', $mainmenu, 'tax_various');
1172 1172
 					if ($usemenuhider || empty($leftmenu) || preg_match('/^tax_various/i', $leftmenu)) {
1173
-                        $newmenu->add("/compta/bank/various_payment/card.php?leftmenu=tax_various&action=create", $langs->trans("New"), 1, $user->rights->banque->modifier);
1174
-                        $newmenu->add("/compta/bank/various_payment/list.php?leftmenu=tax_various", $langs->trans("List"), 1, $user->rights->banque->lire);
1175
-                    }
1173
+						$newmenu->add("/compta/bank/various_payment/card.php?leftmenu=tax_various&action=create", $langs->trans("New"), 1, $user->rights->banque->modifier);
1174
+						$newmenu->add("/compta/bank/various_payment/list.php?leftmenu=tax_various", $langs->trans("List"), 1, $user->rights->banque->lire);
1175
+					}
1176 1176
 				}
1177 1177
 			}
1178 1178
 		}
@@ -1224,35 +1224,35 @@  discard block
 block discarded – undo
1224 1224
 					$newmenu->add("/accountancy/admin/export.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("ExportOptions"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_export', 130);
1225 1225
 				}
1226 1226
 
1227
-                // Transfer in accounting
1228
-                $newmenu->add("/accountancy/index.php?leftmenu=accountancy_transfer", $langs->trans("TransferInAccounting"), 0, $user->rights->accounting->bind->write, '', $mainmenu, 'transfer', 1);
1229
-
1230
-                // Binding
1231
-                // $newmenu->add("", $langs->trans("Binding"), 0, $user->rights->accounting->bind->write, '', $mainmenu, 'dispatch');
1232
-                if (!empty($conf->facture->enabled))
1233
-                {
1234
-                	$newmenu->add("/accountancy/customer/index.php?leftmenu=accountancy_dispatch_customer&amp;mainmenu=accountancy", $langs->trans("CustomersVentilation"), 1, $user->rights->accounting->bind->write, '', $mainmenu, 'dispatch_customer');
1235
-                	if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_dispatch_customer/', $leftmenu)) {
1236
-                		$newmenu->add("/accountancy/customer/list.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_customer", $langs->trans("ToBind"), 2, $user->rights->accounting->bind->write);
1237
-                		$newmenu->add("/accountancy/customer/lines.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_customer", $langs->trans("Binded"), 2, $user->rights->accounting->bind->write);
1238
-                	}
1239
-                }
1240
-                if (!empty($conf->supplier_invoice->enabled))
1241
-                {
1242
-                	$newmenu->add("/accountancy/supplier/index.php?leftmenu=accountancy_dispatch_supplier&amp;mainmenu=accountancy", $langs->trans("SuppliersVentilation"), 1, $user->rights->accounting->bind->write, '', $mainmenu, 'dispatch_supplier');
1243
-                	if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_dispatch_supplier/', $leftmenu)) {
1244
-                		$newmenu->add("/accountancy/supplier/list.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_supplier", $langs->trans("ToBind"), 2, $user->rights->accounting->bind->write);
1245
-                		$newmenu->add("/accountancy/supplier/lines.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_supplier", $langs->trans("Binded"), 2, $user->rights->accounting->bind->write);
1246
-                	}
1247
-                }
1248
-                if (!empty($conf->expensereport->enabled))
1249
-                {
1250
-                	$newmenu->add("/accountancy/expensereport/index.php?leftmenu=accountancy_dispatch_expensereport&amp;mainmenu=accountancy", $langs->trans("ExpenseReportsVentilation"), 1, $user->rights->accounting->bind->write, '', $mainmenu, 'dispatch_expensereport');
1251
-                	if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_dispatch_expensereport/', $leftmenu)) {
1252
-                		$newmenu->add("/accountancy/expensereport/list.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_expensereport", $langs->trans("ToBind"), 2, $user->rights->accounting->bind->write);
1253
-                		$newmenu->add("/accountancy/expensereport/lines.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_expensereport", $langs->trans("Binded"), 2, $user->rights->accounting->bind->write);
1254
-                	}
1255
-                }
1227
+				// Transfer in accounting
1228
+				$newmenu->add("/accountancy/index.php?leftmenu=accountancy_transfer", $langs->trans("TransferInAccounting"), 0, $user->rights->accounting->bind->write, '', $mainmenu, 'transfer', 1);
1229
+
1230
+				// Binding
1231
+				// $newmenu->add("", $langs->trans("Binding"), 0, $user->rights->accounting->bind->write, '', $mainmenu, 'dispatch');
1232
+				if (!empty($conf->facture->enabled))
1233
+				{
1234
+					$newmenu->add("/accountancy/customer/index.php?leftmenu=accountancy_dispatch_customer&amp;mainmenu=accountancy", $langs->trans("CustomersVentilation"), 1, $user->rights->accounting->bind->write, '', $mainmenu, 'dispatch_customer');
1235
+					if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_dispatch_customer/', $leftmenu)) {
1236
+						$newmenu->add("/accountancy/customer/list.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_customer", $langs->trans("ToBind"), 2, $user->rights->accounting->bind->write);
1237
+						$newmenu->add("/accountancy/customer/lines.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_customer", $langs->trans("Binded"), 2, $user->rights->accounting->bind->write);
1238
+					}
1239
+				}
1240
+				if (!empty($conf->supplier_invoice->enabled))
1241
+				{
1242
+					$newmenu->add("/accountancy/supplier/index.php?leftmenu=accountancy_dispatch_supplier&amp;mainmenu=accountancy", $langs->trans("SuppliersVentilation"), 1, $user->rights->accounting->bind->write, '', $mainmenu, 'dispatch_supplier');
1243
+					if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_dispatch_supplier/', $leftmenu)) {
1244
+						$newmenu->add("/accountancy/supplier/list.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_supplier", $langs->trans("ToBind"), 2, $user->rights->accounting->bind->write);
1245
+						$newmenu->add("/accountancy/supplier/lines.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_supplier", $langs->trans("Binded"), 2, $user->rights->accounting->bind->write);
1246
+					}
1247
+				}
1248
+				if (!empty($conf->expensereport->enabled))
1249
+				{
1250
+					$newmenu->add("/accountancy/expensereport/index.php?leftmenu=accountancy_dispatch_expensereport&amp;mainmenu=accountancy", $langs->trans("ExpenseReportsVentilation"), 1, $user->rights->accounting->bind->write, '', $mainmenu, 'dispatch_expensereport');
1251
+					if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_dispatch_expensereport/', $leftmenu)) {
1252
+						$newmenu->add("/accountancy/expensereport/list.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_expensereport", $langs->trans("ToBind"), 2, $user->rights->accounting->bind->write);
1253
+						$newmenu->add("/accountancy/expensereport/lines.php?mainmenu=accountancy&amp;leftmenu=accountancy_dispatch_expensereport", $langs->trans("Binded"), 2, $user->rights->accounting->bind->write);
1254
+					}
1255
+				}
1256 1256
 
1257 1257
 				// Journals
1258 1258
 				if (!empty($conf->accounting->enabled) && !empty($user->rights->accounting->comptarapport->lire) && $mainmenu == 'accountancy')
@@ -1311,24 +1311,24 @@  discard block
 block discarded – undo
1311 1311
 					$db->free($resql);
1312 1312
 				}
1313 1313
 
1314
-                // Accounting
1315
-                $newmenu->add("/accountancy/index.php?leftmenu=accountancy_accountancy", $langs->trans("MenuAccountancy"), 0, $user->rights->accounting->mouvements->lire, '', $mainmenu, 'accountancy', 1);
1314
+				// Accounting
1315
+				$newmenu->add("/accountancy/index.php?leftmenu=accountancy_accountancy", $langs->trans("MenuAccountancy"), 0, $user->rights->accounting->mouvements->lire, '', $mainmenu, 'accountancy', 1);
1316 1316
 
1317 1317
 
1318
-                // General Ledger
1318
+				// General Ledger
1319 1319
 				$newmenu->add("/accountancy/bookkeeping/list.php?mainmenu=accountancy&amp;leftmenu=accountancy_accountancy", $langs->trans("Bookkeeping"), 1, $user->rights->accounting->mouvements->lire);
1320 1320
 
1321 1321
 				// Balance
1322 1322
 				$newmenu->add("/accountancy/bookkeeping/balance.php?mainmenu=accountancy&amp;leftmenu=accountancy_accountancy", $langs->trans("AccountBalance"), 1, $user->rights->accounting->mouvements->lire);
1323 1323
 
1324
-                // Closure
1325
-                if (!empty($conf->global->MAIN_FEATURES_LEVEL) && $conf->global->MAIN_FEATURES_LEVEL >= 2) {
1326
-                    $newmenu->add("/accountancy/closure/index.php?mainmenu=accountancy&amp;leftmenu=accountancy_closure", $langs->trans("MenuAccountancyClosure"), 1, $user->rights->accounting->fiscalyear->write, '', $mainmenu, 'closure');
1324
+				// Closure
1325
+				if (!empty($conf->global->MAIN_FEATURES_LEVEL) && $conf->global->MAIN_FEATURES_LEVEL >= 2) {
1326
+					$newmenu->add("/accountancy/closure/index.php?mainmenu=accountancy&amp;leftmenu=accountancy_closure", $langs->trans("MenuAccountancyClosure"), 1, $user->rights->accounting->fiscalyear->write, '', $mainmenu, 'closure');
1327 1327
 
1328
-                    if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_closure/', $leftmenu)) {
1329
-                        $newmenu->add("/accountancy/closure/validate.php?leftmenu=accountancy_closure", $langs->trans("MenuAccountancyValidationMovements"), 2, $user->rights->accounting->fiscalyear->write);
1330
-                    }
1331
-                }
1328
+					if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_closure/', $leftmenu)) {
1329
+						$newmenu->add("/accountancy/closure/validate.php?leftmenu=accountancy_closure", $langs->trans("MenuAccountancyValidationMovements"), 2, $user->rights->accounting->fiscalyear->write);
1330
+					}
1331
+				}
1332 1332
 
1333 1333
 				// Files
1334 1334
 				if (empty($conf->global->ACCOUNTANCY_HIDE_EXPORT_FILES_MENU))
@@ -1339,23 +1339,23 @@  discard block
 block discarded – undo
1339 1339
 				// Reports
1340 1340
 				$newmenu->add("/compta/resultat/index.php?mainmenu=accountancy&amp;leftmenu=accountancy_report", $langs->trans("Reportings"), 1, $user->rights->accounting->comptarapport->lire, '', $mainmenu, 'ca');
1341 1341
 
1342
-                if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/', $leftmenu)) {
1343
-                    $newmenu->add("/compta/resultat/index.php?leftmenu=accountancy_report", $langs->trans("MenuReportInOut"), 2, $user->rights->accounting->comptarapport->lire);
1344
-                    $newmenu->add("/compta/resultat/clientfourn.php?leftmenu=accountancy_report", $langs->trans("ByPredefinedAccountGroups"), 3, $user->rights->accounting->comptarapport->lire);
1345
-                    $newmenu->add("/compta/resultat/result.php?leftmenu=accountancy_report", $langs->trans("ByPersonalizedAccountGroups"), 3, $user->rights->accounting->comptarapport->lire);
1346
-                }
1342
+				if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/', $leftmenu)) {
1343
+					$newmenu->add("/compta/resultat/index.php?leftmenu=accountancy_report", $langs->trans("MenuReportInOut"), 2, $user->rights->accounting->comptarapport->lire);
1344
+					$newmenu->add("/compta/resultat/clientfourn.php?leftmenu=accountancy_report", $langs->trans("ByPredefinedAccountGroups"), 3, $user->rights->accounting->comptarapport->lire);
1345
+					$newmenu->add("/compta/resultat/result.php?leftmenu=accountancy_report", $langs->trans("ByPersonalizedAccountGroups"), 3, $user->rights->accounting->comptarapport->lire);
1346
+				}
1347 1347
 
1348 1348
 				$modecompta = 'CREANCES-DETTES';
1349 1349
 				if (!empty($conf->accounting->enabled) && !empty($user->rights->accounting->comptarapport->lire) && $mainmenu == 'accountancy') $modecompta = 'BOOKKEEPING'; // Not yet implemented. Should be BOOKKEEPINGCOLLECTED
1350 1350
 				if ($modecompta)
1351 1351
 				{
1352 1352
 					if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/', $leftmenu)) {
1353
-                        $newmenu->add("/compta/stats/index.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ReportTurnover"), 2, $user->rights->accounting->comptarapport->lire);
1354
-					    $newmenu->add("/compta/stats/casoc.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByCompanies"), 3, $user->rights->accounting->comptarapport->lire);
1355
-					    $newmenu->add("/compta/stats/cabyuser.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByUsers"), 3, $user->rights->accounting->comptarapport->lire);
1356
-					    $newmenu->add("/compta/stats/cabyprodserv.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByProductsAndServices"), 3, $user->rights->accounting->comptarapport->lire);
1357
-                        $newmenu->add("/compta/stats/byratecountry.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByVatRate"), 3, $user->rights->accounting->comptarapport->lire);
1358
-                    }
1353
+						$newmenu->add("/compta/stats/index.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ReportTurnover"), 2, $user->rights->accounting->comptarapport->lire);
1354
+						$newmenu->add("/compta/stats/casoc.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByCompanies"), 3, $user->rights->accounting->comptarapport->lire);
1355
+						$newmenu->add("/compta/stats/cabyuser.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByUsers"), 3, $user->rights->accounting->comptarapport->lire);
1356
+						$newmenu->add("/compta/stats/cabyprodserv.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByProductsAndServices"), 3, $user->rights->accounting->comptarapport->lire);
1357
+						$newmenu->add("/compta/stats/byratecountry.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByVatRate"), 3, $user->rights->accounting->comptarapport->lire);
1358
+					}
1359 1359
 				}
1360 1360
 
1361 1361
 				$modecompta = 'RECETTES-DEPENSES';
@@ -1363,12 +1363,12 @@  discard block
 block discarded – undo
1363 1363
 				if ($modecompta)
1364 1364
 				{
1365 1365
 					if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/', $leftmenu)) {
1366
-					    $newmenu->add("/compta/stats/index.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ReportTurnoverCollected"), 2, $user->rights->accounting->comptarapport->lire);
1367
-					    $newmenu->add("/compta/stats/casoc.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByCompanies"), 3, $user->rights->accounting->comptarapport->lire);
1368
-					    $newmenu->add("/compta/stats/cabyuser.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByUsers"), 3, $user->rights->accounting->comptarapport->lire);
1369
-					    //$newmenu->add("/compta/stats/cabyprodserv.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByProductsAndServices"),3,$user->rights->accounting->comptarapport->lire);
1370
-                        //$newmenu->add("/compta/stats/byratecountry.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByVatRate"),3,$user->rights->accounting->comptarapport->lire);
1371
-                    }
1366
+						$newmenu->add("/compta/stats/index.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ReportTurnoverCollected"), 2, $user->rights->accounting->comptarapport->lire);
1367
+						$newmenu->add("/compta/stats/casoc.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByCompanies"), 3, $user->rights->accounting->comptarapport->lire);
1368
+						$newmenu->add("/compta/stats/cabyuser.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByUsers"), 3, $user->rights->accounting->comptarapport->lire);
1369
+						//$newmenu->add("/compta/stats/cabyprodserv.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByProductsAndServices"),3,$user->rights->accounting->comptarapport->lire);
1370
+						//$newmenu->add("/compta/stats/byratecountry.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByVatRate"),3,$user->rights->accounting->comptarapport->lire);
1371
+					}
1372 1372
 				}
1373 1373
 
1374 1374
 				$modecompta = 'CREANCES-DETTES';
@@ -1391,50 +1391,50 @@  discard block
 block discarded – undo
1391 1391
 						$newmenu->add("/compta/stats/supplier_turnover_by_thirdparty.php?leftmenu=accountancy_report&modecompta=".$modecompta, $langs->trans("ByCompanies"), 3, $user->rights->accounting->comptarapport->lire);
1392 1392
 					}
1393 1393
 				}
1394
-            }
1394
+			}
1395 1395
 
1396 1396
 			// Accountancy (simple)
1397
-            if (!empty($conf->comptabilite->enabled))
1398
-            {
1399
-            	// Files
1400
-            	if (empty($conf->global->ACCOUNTANCY_HIDE_EXPORT_FILES_MENU))
1401
-            	{
1402
-            		$newmenu->add("/compta/accounting-files.php?mainmenu=accountancy&amp;leftmenu=accountancy_files", $langs->trans("AccountantFiles"), 0, $user->rights->compta->resultat->lire, '', $mainmenu, 'files');
1403
-            	}
1404
-
1405
-                // Bilan, resultats
1406
-                $newmenu->add("/compta/resultat/index.php?leftmenu=report&amp;mainmenu=accountancy", $langs->trans("Reportings"), 0, $user->rights->compta->resultat->lire, '', $mainmenu, 'ca');
1407
-
1408
-                if ($usemenuhider || empty($leftmenu) || preg_match('/report/', $leftmenu)) {
1409
-                    $newmenu->add("/compta/resultat/index.php?leftmenu=report", $langs->trans("MenuReportInOut"), 1, $user->rights->compta->resultat->lire);
1410
-                    $newmenu->add("/compta/resultat/clientfourn.php?leftmenu=report", $langs->trans("ByCompanies"), 2, $user->rights->compta->resultat->lire);
1411
-                    /* On verra ca avec module compabilite expert
1397
+			if (!empty($conf->comptabilite->enabled))
1398
+			{
1399
+				// Files
1400
+				if (empty($conf->global->ACCOUNTANCY_HIDE_EXPORT_FILES_MENU))
1401
+				{
1402
+					$newmenu->add("/compta/accounting-files.php?mainmenu=accountancy&amp;leftmenu=accountancy_files", $langs->trans("AccountantFiles"), 0, $user->rights->compta->resultat->lire, '', $mainmenu, 'files');
1403
+				}
1404
+
1405
+				// Bilan, resultats
1406
+				$newmenu->add("/compta/resultat/index.php?leftmenu=report&amp;mainmenu=accountancy", $langs->trans("Reportings"), 0, $user->rights->compta->resultat->lire, '', $mainmenu, 'ca');
1407
+
1408
+				if ($usemenuhider || empty($leftmenu) || preg_match('/report/', $leftmenu)) {
1409
+					$newmenu->add("/compta/resultat/index.php?leftmenu=report", $langs->trans("MenuReportInOut"), 1, $user->rights->compta->resultat->lire);
1410
+					$newmenu->add("/compta/resultat/clientfourn.php?leftmenu=report", $langs->trans("ByCompanies"), 2, $user->rights->compta->resultat->lire);
1411
+					/* On verra ca avec module compabilite expert
1412 1412
                     $newmenu->add("/compta/resultat/compteres.php?leftmenu=report","Compte de resultat",2,$user->rights->compta->resultat->lire);
1413 1413
                     $newmenu->add("/compta/resultat/bilan.php?leftmenu=report","Bilan",2,$user->rights->compta->resultat->lire);
1414 1414
                     */
1415
-                    $newmenu->add("/compta/stats/index.php?leftmenu=report", $langs->trans("ReportTurnover"), 1, $user->rights->compta->resultat->lire);
1415
+					$newmenu->add("/compta/stats/index.php?leftmenu=report", $langs->trans("ReportTurnover"), 1, $user->rights->compta->resultat->lire);
1416 1416
 
1417
-                    /*
1417
+					/*
1418 1418
                     $newmenu->add("/compta/stats/cumul.php?leftmenu=report","Cumule",2,$user->rights->compta->resultat->lire);
1419 1419
                     if (! empty($conf->propal->enabled)) {
1420 1420
                         $newmenu->add("/compta/stats/prev.php?leftmenu=report","Previsionnel",2,$user->rights->compta->resultat->lire);
1421 1421
                         $newmenu->add("/compta/stats/comp.php?leftmenu=report","Transforme",2,$user->rights->compta->resultat->lire);
1422 1422
                     }
1423 1423
                     */
1424
-                    $newmenu->add("/compta/stats/casoc.php?leftmenu=report", $langs->trans("ByCompanies"), 2, $user->rights->compta->resultat->lire);
1425
-                    $newmenu->add("/compta/stats/cabyuser.php?leftmenu=report", $langs->trans("ByUsers"), 2, $user->rights->compta->resultat->lire);
1426
-                    $newmenu->add("/compta/stats/cabyprodserv.php?leftmenu=report", $langs->trans("ByProductsAndServices"), 2, $user->rights->compta->resultat->lire);
1427
-                    $newmenu->add("/compta/stats/byratecountry.php?leftmenu=report", $langs->trans("ByVatRate"), 2, $user->rights->compta->resultat->lire);
1424
+					$newmenu->add("/compta/stats/casoc.php?leftmenu=report", $langs->trans("ByCompanies"), 2, $user->rights->compta->resultat->lire);
1425
+					$newmenu->add("/compta/stats/cabyuser.php?leftmenu=report", $langs->trans("ByUsers"), 2, $user->rights->compta->resultat->lire);
1426
+					$newmenu->add("/compta/stats/cabyprodserv.php?leftmenu=report", $langs->trans("ByProductsAndServices"), 2, $user->rights->compta->resultat->lire);
1427
+					$newmenu->add("/compta/stats/byratecountry.php?leftmenu=report", $langs->trans("ByVatRate"), 2, $user->rights->compta->resultat->lire);
1428 1428
 					//Achats
1429 1429
 					$newmenu->add("/compta/stats/supplier_turnover.php?leftmenu=accountancy_report", $langs->trans("ReportPurchaseTurnover"), 1, $user->rights->compta->resultat->lire);
1430 1430
 					$newmenu->add("/compta/stats/supplier_turnover_by_thirdparty.php?leftmenu=accountancy_report", $langs->trans("ByCompanies"), 2, $user->rights->compta->resultat->lire);
1431 1431
 					$newmenu->add("/compta/stats/supplier_turnover_by_prodserv.php?leftmenu=accountancy_report", $langs->trans("ByProductsAndServices"), 2, $user->rights->compta->resultat->lire);
1432
-                    // Journaux
1433
-                    $newmenu->add("/compta/journal/sellsjournal.php?leftmenu=report", $langs->trans("SellsJournal"), 1, $user->rights->compta->resultat->lire, '', '', '', 50);
1434
-                    $newmenu->add("/compta/journal/purchasesjournal.php?leftmenu=report", $langs->trans("PurchasesJournal"), 1, $user->rights->compta->resultat->lire, '', '', '', 51);
1435
-                }
1436
-                //if ($leftmenu=="ca") $newmenu->add("/compta/journaux/index.php?leftmenu=ca",$langs->trans("Journaux"),1,$user->rights->compta->resultat->lire||$user->rights->accounting->comptarapport->lire);
1437
-            }
1432
+					// Journaux
1433
+					$newmenu->add("/compta/journal/sellsjournal.php?leftmenu=report", $langs->trans("SellsJournal"), 1, $user->rights->compta->resultat->lire, '', '', '', 50);
1434
+					$newmenu->add("/compta/journal/purchasesjournal.php?leftmenu=report", $langs->trans("PurchasesJournal"), 1, $user->rights->compta->resultat->lire, '', '', '', 51);
1435
+				}
1436
+				//if ($leftmenu=="ca") $newmenu->add("/compta/journaux/index.php?leftmenu=ca",$langs->trans("Journaux"),1,$user->rights->compta->resultat->lire||$user->rights->accounting->comptarapport->lire);
1437
+			}
1438 1438
 
1439 1439
 			// Assets
1440 1440
 			if (!empty($conf->asset->enabled))
@@ -1445,8 +1445,8 @@  discard block
 block discarded – undo
1445 1445
 				$newmenu->add("/asset/type.php?leftmenu=asset_type", $langs->trans("MenuTypeAssets"), 1, $user->rights->asset->read, '', $mainmenu, 'asset_type');
1446 1446
 				if ($usemenuhider || empty($leftmenu) || preg_match('/asset_type/', $leftmenu)) {
1447 1447
 					$newmenu->add("/asset/type.php?leftmenu=asset_type&amp;action=create", $langs->trans("MenuNewTypeAssets"), 2, (empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->write) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->asset->setup_advance));
1448
-                    $newmenu->add("/asset/type.php?leftmenu=asset_type", $langs->trans("MenuListTypeAssets"), 2, $user->rights->asset->read);
1449
-                }
1448
+					$newmenu->add("/asset/type.php?leftmenu=asset_type", $langs->trans("MenuListTypeAssets"), 2, $user->rights->asset->read);
1449
+				}
1450 1450
 			}
1451 1451
 		}
1452 1452
 
@@ -1485,13 +1485,13 @@  discard block
 block discarded – undo
1485 1485
 				$newmenu->add("/compta/prelevement/index.php?leftmenu=withdraw&amp;mainmenu=bank", $langs->trans("PaymentByDirectDebit"), 0, $user->rights->prelevement->bons->lire, '', $mainmenu, 'withdraw');
1486 1486
 
1487 1487
 				if ($usemenuhider || empty($leftmenu) || $leftmenu == "withdraw") {
1488
-				    $newmenu->add("/compta/prelevement/create.php?mainmenu=bank", $langs->trans("NewStandingOrder"), 1, $user->rights->prelevement->bons->creer);
1488
+					$newmenu->add("/compta/prelevement/create.php?mainmenu=bank", $langs->trans("NewStandingOrder"), 1, $user->rights->prelevement->bons->creer);
1489 1489
 
1490
-				    $newmenu->add("/compta/prelevement/bons.php?mainmenu=bank", $langs->trans("WithdrawalsReceipts"), 1, $user->rights->prelevement->bons->lire);
1491
-				    $newmenu->add("/compta/prelevement/list.php?mainmenu=bank", $langs->trans("WithdrawalsLines"), 1, $user->rights->prelevement->bons->lire);
1492
-				    $newmenu->add("/compta/prelevement/rejets.php?mainmenu=bank", $langs->trans("Rejects"), 1, $user->rights->prelevement->bons->lire);
1493
-				    $newmenu->add("/compta/prelevement/stats.php?mainmenu=bank", $langs->trans("Statistics"), 1, $user->rights->prelevement->bons->lire);
1494
-                }
1490
+					$newmenu->add("/compta/prelevement/bons.php?mainmenu=bank", $langs->trans("WithdrawalsReceipts"), 1, $user->rights->prelevement->bons->lire);
1491
+					$newmenu->add("/compta/prelevement/list.php?mainmenu=bank", $langs->trans("WithdrawalsLines"), 1, $user->rights->prelevement->bons->lire);
1492
+					$newmenu->add("/compta/prelevement/rejets.php?mainmenu=bank", $langs->trans("Rejects"), 1, $user->rights->prelevement->bons->lire);
1493
+					$newmenu->add("/compta/prelevement/stats.php?mainmenu=bank", $langs->trans("Statistics"), 1, $user->rights->prelevement->bons->lire);
1494
+				}
1495 1495
 			}
1496 1496
 
1497 1497
 			// Bank transfer order
@@ -1514,9 +1514,9 @@  discard block
 block discarded – undo
1514 1514
 			{
1515 1515
 				$newmenu->add("/compta/paiement/cheque/index.php?leftmenu=checks&amp;mainmenu=bank", $langs->trans("MenuChequeDeposits"), 0, $user->rights->banque->cheque, '', $mainmenu, 'checks');
1516 1516
 				if (preg_match('/checks/', $leftmenu)) {
1517
-                    $newmenu->add("/compta/paiement/cheque/card.php?leftmenu=checks_bis&amp;action=new&amp;mainmenu=bank", $langs->trans("NewChequeDeposit"), 1, $user->rights->banque->cheque);
1518
-                    $newmenu->add("/compta/paiement/cheque/list.php?leftmenu=checks_bis&amp;mainmenu=bank", $langs->trans("List"), 1, $user->rights->banque->cheque);
1519
-                }
1517
+					$newmenu->add("/compta/paiement/cheque/card.php?leftmenu=checks_bis&amp;action=new&amp;mainmenu=bank", $langs->trans("NewChequeDeposit"), 1, $user->rights->banque->cheque);
1518
+					$newmenu->add("/compta/paiement/cheque/list.php?leftmenu=checks_bis&amp;mainmenu=bank", $langs->trans("List"), 1, $user->rights->banque->cheque);
1519
+				}
1520 1520
 			}
1521 1521
 
1522 1522
 			// Cash Control
@@ -1596,23 +1596,23 @@  discard block
 block discarded – undo
1596 1596
 				$newmenu->add("/product/stock/list.php", $langs->trans("List"), 1, $user->rights->stock->lire);
1597 1597
 				$newmenu->add("/product/stock/movement_list.php", $langs->trans("Movements"), 1, $user->rights->stock->mouvement->lire);
1598 1598
 
1599
-                $newmenu->add("/product/stock/massstockmove.php", $langs->trans("MassStockTransferShort"), 1, $user->rights->stock->mouvement->creer);
1600
-                if ($conf->supplier_order->enabled) $newmenu->add("/product/stock/replenish.php", $langs->trans("Replenishment"), 1, $user->rights->stock->mouvement->creer && $user->rights->fournisseur->lire);
1601
-                $newmenu->add("/product/stock/stockatdate.php", $langs->trans("StockAtDate"), 1, $user->rights->produit->lire && $user->rights->stock->lire && $conf->global->MAIN_FEATURES_LEVEL >= 2);
1599
+				$newmenu->add("/product/stock/massstockmove.php", $langs->trans("MassStockTransferShort"), 1, $user->rights->stock->mouvement->creer);
1600
+				if ($conf->supplier_order->enabled) $newmenu->add("/product/stock/replenish.php", $langs->trans("Replenishment"), 1, $user->rights->stock->mouvement->creer && $user->rights->fournisseur->lire);
1601
+				$newmenu->add("/product/stock/stockatdate.php", $langs->trans("StockAtDate"), 1, $user->rights->produit->lire && $user->rights->stock->lire && $conf->global->MAIN_FEATURES_LEVEL >= 2);
1602 1602
 
1603
-                // Categories for warehouses
1604
-                if (!empty($conf->categorie->enabled))
1605
-                {
1606
-                	$newmenu->add("/categories/index.php?leftmenu=stock&amp;type=9", $langs->trans("Categories"), 1, $user->rights->categorie->lire, '', $mainmenu, 'cat');
1607
-                }
1603
+				// Categories for warehouses
1604
+				if (!empty($conf->categorie->enabled))
1605
+				{
1606
+					$newmenu->add("/categories/index.php?leftmenu=stock&amp;type=9", $langs->trans("Categories"), 1, $user->rights->categorie->lire, '', $mainmenu, 'cat');
1607
+				}
1608 1608
 			}
1609 1609
 
1610 1610
 			// Inventory
1611 1611
 			if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
1612 1612
 			{
1613
-    			if (!empty($conf->stock->enabled))
1614
-    			{
1615
-    				$langs->load("stocks");
1613
+				if (!empty($conf->stock->enabled))
1614
+				{
1615
+					$langs->load("stocks");
1616 1616
 					if (empty($conf->global->MAIN_USE_ADVANCED_PERMS))
1617 1617
 					{
1618 1618
 						$newmenu->add("/product/inventory/list.php?leftmenu=stock", $langs->trans("Inventory"), 0, $user->rights->stock->lire, '', $mainmenu, 'stock');
@@ -1623,7 +1623,7 @@  discard block
 block discarded – undo
1623 1623
 						$newmenu->add("/product/inventory/card.php?action=create", $langs->trans("NewInventory"), 1, $user->rights->stock->inventory_advance->write);
1624 1624
 						$newmenu->add("/product/inventory/list.php", $langs->trans("List"), 1, $user->rights->stock->inventory_advance->read);
1625 1625
 					}
1626
-    			}
1626
+				}
1627 1627
 			}
1628 1628
 
1629 1629
 			// Shipments
@@ -1634,14 +1634,14 @@  discard block
 block discarded – undo
1634 1634
 				$newmenu->add("/expedition/card.php?action=create2&amp;leftmenu=sendings", $langs->trans("NewSending"), 1, $user->rights->expedition->creer);
1635 1635
 				$newmenu->add("/expedition/list.php?leftmenu=sendings", $langs->trans("List"), 1, $user->rights->expedition->lire);
1636 1636
 				if ($usemenuhider || empty($leftmenu) || $leftmenu == "sendings") {
1637
-                    $newmenu->add("/expedition/list.php?leftmenu=sendings&search_status=0", $langs->trans("StatusSendingDraftShort"), 2, $user->rights->expedition->lire);
1638
-				    $newmenu->add("/expedition/list.php?leftmenu=sendings&search_status=1", $langs->trans("StatusSendingValidatedShort"), 2, $user->rights->expedition->lire);
1639
-                    $newmenu->add("/expedition/list.php?leftmenu=sendings&search_status=2", $langs->trans("StatusSendingProcessedShort"), 2, $user->rights->expedition->lire);
1640
-                }
1637
+					$newmenu->add("/expedition/list.php?leftmenu=sendings&search_status=0", $langs->trans("StatusSendingDraftShort"), 2, $user->rights->expedition->lire);
1638
+					$newmenu->add("/expedition/list.php?leftmenu=sendings&search_status=1", $langs->trans("StatusSendingValidatedShort"), 2, $user->rights->expedition->lire);
1639
+					$newmenu->add("/expedition/list.php?leftmenu=sendings&search_status=2", $langs->trans("StatusSendingProcessedShort"), 2, $user->rights->expedition->lire);
1640
+				}
1641 1641
 				$newmenu->add("/expedition/stats/index.php?leftmenu=sendings", $langs->trans("Statistics"), 1, $user->rights->expedition->lire);
1642 1642
 			}
1643 1643
 
1644
-            // Receptions
1644
+			// Receptions
1645 1645
 			if (!empty($conf->reception->enabled))
1646 1646
 			{
1647 1647
 				$langs->load("receptions");
@@ -1660,24 +1660,24 @@  discard block
 block discarded – undo
1660 1660
 		 */
1661 1661
 		if ($mainmenu == 'mrp')
1662 1662
 		{
1663
-		    // BOM
1664
-		    if (!empty($conf->bom->enabled) || !empty($conf->mrp->enabled))
1665
-		    {
1666
-		        $langs->load("mrp");
1667
-
1668
-		        $newmenu->add("", $langs->trans("MenuBOM"), 0, $user->rights->bom->read, '', $mainmenu, 'bom');
1669
-		        $newmenu->add("/bom/bom_card.php?leftmenu=bom&amp;action=create", $langs->trans("NewBOM"), 1, $user->rights->bom->write, '', $mainmenu, 'bom');
1670
-		        $newmenu->add("/bom/bom_list.php?leftmenu=bom", $langs->trans("List"), 1, $user->rights->bom->read, '', $mainmenu, 'bom');
1671
-		    }
1672
-
1673
-		    if (!empty($conf->mrp->enabled))
1674
-		    {
1675
-		    	$langs->load("mrp");
1676
-
1677
-		    	$newmenu->add("", $langs->trans("MenuMRP"), 0, $user->rights->mrp->read, '', $mainmenu, 'mo');
1678
-		    	$newmenu->add("/mrp/mo_card.php?leftmenu=mo&amp;action=create", $langs->trans("NewMO"), 1, $user->rights->mrp->write, '', $mainmenu, 'mo');
1679
-		    	$newmenu->add("/mrp/mo_list.php?leftmenu=mo", $langs->trans("List"), 1, $user->rights->mrp->read, '', $mainmenu, 'mo');
1680
-		    }
1663
+			// BOM
1664
+			if (!empty($conf->bom->enabled) || !empty($conf->mrp->enabled))
1665
+			{
1666
+				$langs->load("mrp");
1667
+
1668
+				$newmenu->add("", $langs->trans("MenuBOM"), 0, $user->rights->bom->read, '', $mainmenu, 'bom');
1669
+				$newmenu->add("/bom/bom_card.php?leftmenu=bom&amp;action=create", $langs->trans("NewBOM"), 1, $user->rights->bom->write, '', $mainmenu, 'bom');
1670
+				$newmenu->add("/bom/bom_list.php?leftmenu=bom", $langs->trans("List"), 1, $user->rights->bom->read, '', $mainmenu, 'bom');
1671
+			}
1672
+
1673
+			if (!empty($conf->mrp->enabled))
1674
+			{
1675
+				$langs->load("mrp");
1676
+
1677
+				$newmenu->add("", $langs->trans("MenuMRP"), 0, $user->rights->mrp->read, '', $mainmenu, 'mo');
1678
+				$newmenu->add("/mrp/mo_card.php?leftmenu=mo&amp;action=create", $langs->trans("NewMO"), 1, $user->rights->mrp->write, '', $mainmenu, 'mo');
1679
+				$newmenu->add("/mrp/mo_list.php?leftmenu=mo", $langs->trans("List"), 1, $user->rights->mrp->read, '', $mainmenu, 'mo');
1680
+			}
1681 1681
 		}
1682 1682
 
1683 1683
 		/*
@@ -1692,10 +1692,10 @@  discard block
 block discarded – undo
1692 1692
 				$search_project_user = GETPOST('search_project_user', 'int');
1693 1693
 
1694 1694
 				$tmpentry = array(
1695
-                    'enabled'=>(!empty($conf->projet->enabled)),
1696
-				    'perms'=>(!empty($user->rights->projet->lire)),
1697
-                    'module'=>'projet'
1698
-                );
1695
+					'enabled'=>(!empty($conf->projet->enabled)),
1696
+					'perms'=>(!empty($user->rights->projet->lire)),
1697
+					'module'=>'projet'
1698
+				);
1699 1699
 				$showmode = isVisibleToUserType($type_user, $tmpentry, $listofmodulesforexternal);
1700 1700
 
1701 1701
 				$titleboth = $langs->trans("LeadsOrProjects");
@@ -1741,9 +1741,9 @@  discard block
 block discarded – undo
1741 1741
 					$newmenu->add("/projet/activity/index.php?leftmenu=tasks".($search_project_user ? '&search_project_user='.$search_project_user : ''), $langs->trans("Activities"), 0, $user->rights->projet->lire);
1742 1742
 					$newmenu->add("/projet/tasks.php?leftmenu=tasks&action=create", $langs->trans("NewTask"), 1, $user->rights->projet->creer);
1743 1743
 					$newmenu->add("/projet/tasks/list.php?leftmenu=tasks".($search_project_user ? '&search_project_user='.$search_project_user : ''), $langs->trans("List"), 1, $user->rights->projet->lire);
1744
-				    $newmenu->add("/projet/tasks/stats/index.php?leftmenu=projects", $langs->trans("Statistics"), 1, $user->rights->projet->lire);
1744
+					$newmenu->add("/projet/tasks/stats/index.php?leftmenu=projects", $langs->trans("Statistics"), 1, $user->rights->projet->lire);
1745 1745
 
1746
-				    $newmenu->add("/projet/activity/perweek.php?leftmenu=tasks".($search_project_user ? '&search_project_user='.$search_project_user : ''), $langs->trans("NewTimeSpent"), 0, $user->rights->projet->lire);
1746
+					$newmenu->add("/projet/activity/perweek.php?leftmenu=tasks".($search_project_user ? '&search_project_user='.$search_project_user : ''), $langs->trans("NewTimeSpent"), 0, $user->rights->projet->lire);
1747 1747
 				}
1748 1748
 			}
1749 1749
 		}
@@ -1766,19 +1766,19 @@  discard block
 block discarded – undo
1766 1766
 			// Leave/Holiday/Vacation module
1767 1767
 			if (!empty($conf->holiday->enabled))
1768 1768
 			{
1769
-			    // Load translation files required by the page
1770
-                $langs->loadLangs(array("holiday", "trips"));
1769
+				// Load translation files required by the page
1770
+				$langs->loadLangs(array("holiday", "trips"));
1771 1771
 
1772 1772
 				$newmenu->add("/holiday/list.php?mainmenu=hrm&leftmenu=hrm", $langs->trans("CPTitreMenu"), 0, $user->rights->holiday->read, '', $mainmenu, 'hrm');
1773 1773
 				$newmenu->add("/holiday/card.php?mainmenu=hrm&leftmenu=holiday&action=request", $langs->trans("New"), 1, $user->rights->holiday->write);
1774 1774
 				$newmenu->add("/holiday/list.php?mainmenu=hrm&leftmenu=hrm", $langs->trans("List"), 1, $user->rights->holiday->read);
1775 1775
 				if ($usemenuhider || empty($leftmenu) || $leftmenu == "hrm") {
1776
-                    $newmenu->add("/holiday/list.php?search_statut=1&mainmenu=hrm&leftmenu=hrm", $langs->trans("DraftCP"), 2, $user->rights->holiday->read);
1777
-				    $newmenu->add("/holiday/list.php?search_statut=2&mainmenu=hrm&leftmenu=hrm", $langs->trans("ToReviewCP"), 2, $user->rights->holiday->read);
1778
-				    $newmenu->add("/holiday/list.php?search_statut=3&mainmenu=hrm&leftmenu=hrm", $langs->trans("ApprovedCP"), 2, $user->rights->holiday->read);
1779
-				    $newmenu->add("/holiday/list.php?search_statut=4&mainmenu=hrm&leftmenu=hrm", $langs->trans("CancelCP"), 2, $user->rights->holiday->read);
1780
-                    $newmenu->add("/holiday/list.php?search_statut=5&mainmenu=hrm&leftmenu=hrm", $langs->trans("RefuseCP"), 2, $user->rights->holiday->read);
1781
-                }
1776
+					$newmenu->add("/holiday/list.php?search_statut=1&mainmenu=hrm&leftmenu=hrm", $langs->trans("DraftCP"), 2, $user->rights->holiday->read);
1777
+					$newmenu->add("/holiday/list.php?search_statut=2&mainmenu=hrm&leftmenu=hrm", $langs->trans("ToReviewCP"), 2, $user->rights->holiday->read);
1778
+					$newmenu->add("/holiday/list.php?search_statut=3&mainmenu=hrm&leftmenu=hrm", $langs->trans("ApprovedCP"), 2, $user->rights->holiday->read);
1779
+					$newmenu->add("/holiday/list.php?search_statut=4&mainmenu=hrm&leftmenu=hrm", $langs->trans("CancelCP"), 2, $user->rights->holiday->read);
1780
+					$newmenu->add("/holiday/list.php?search_statut=5&mainmenu=hrm&leftmenu=hrm", $langs->trans("RefuseCP"), 2, $user->rights->holiday->read);
1781
+				}
1782 1782
 				$newmenu->add("/holiday/define_holiday.php?mainmenu=hrm&action=request", $langs->trans("MenuConfCP"), 1, $user->rights->holiday->read);
1783 1783
 				$newmenu->add("/holiday/month_report.php?mainmenu=hrm&leftmenu=holiday", $langs->trans("MenuReportMonth"), 1, $user->rights->holiday->read_all);
1784 1784
 				$newmenu->add("/holiday/view_log.php?mainmenu=hrm&leftmenu=holiday&action=request", $langs->trans("MenuLogCP"), 1, $user->rights->holiday->define_holiday);
@@ -1802,13 +1802,13 @@  discard block
 block discarded – undo
1802 1802
 				$newmenu->add("/expensereport/card.php?action=create&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("New"), 1, $user->rights->expensereport->creer);
1803 1803
 				$newmenu->add("/expensereport/list.php?leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("List"), 1, $user->rights->expensereport->lire);
1804 1804
 				if ($usemenuhider || empty($leftmenu) || $leftmenu == "expensereport") {
1805
-                    $newmenu->add("/expensereport/list.php?search_status=0&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Draft"), 2, $user->rights->expensereport->lire);
1806
-				    $newmenu->add("/expensereport/list.php?search_status=2&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Validated"), 2, $user->rights->expensereport->lire);
1807
-				    $newmenu->add("/expensereport/list.php?search_status=5&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Approved"), 2, $user->rights->expensereport->lire);
1808
-				    $newmenu->add("/expensereport/list.php?search_status=6&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Paid"), 2, $user->rights->expensereport->lire);
1809
-				    $newmenu->add("/expensereport/list.php?search_status=4&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Canceled"), 2, $user->rights->expensereport->lire);
1810
-                    $newmenu->add("/expensereport/list.php?search_status=99&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Refused"), 2, $user->rights->expensereport->lire);
1811
-                }
1805
+					$newmenu->add("/expensereport/list.php?search_status=0&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Draft"), 2, $user->rights->expensereport->lire);
1806
+					$newmenu->add("/expensereport/list.php?search_status=2&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Validated"), 2, $user->rights->expensereport->lire);
1807
+					$newmenu->add("/expensereport/list.php?search_status=5&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Approved"), 2, $user->rights->expensereport->lire);
1808
+					$newmenu->add("/expensereport/list.php?search_status=6&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Paid"), 2, $user->rights->expensereport->lire);
1809
+					$newmenu->add("/expensereport/list.php?search_status=4&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Canceled"), 2, $user->rights->expensereport->lire);
1810
+					$newmenu->add("/expensereport/list.php?search_status=99&amp;leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Refused"), 2, $user->rights->expensereport->lire);
1811
+				}
1812 1812
 				$newmenu->add("/expensereport/stats/index.php?leftmenu=expensereport&amp;mainmenu=hrm", $langs->trans("Statistics"), 1, $user->rights->expensereport->lire);
1813 1813
 			}
1814 1814
 
@@ -1868,7 +1868,7 @@  discard block
 block discarded – undo
1868 1868
 			if (!empty($conf->adherent->enabled))
1869 1869
 			{
1870 1870
 				// Load translation files required by the page
1871
-                $langs->loadLangs(array("members", "compta"));
1871
+				$langs->loadLangs(array("members", "compta"));
1872 1872
 
1873 1873
 				$newmenu->add("/adherents/index.php?leftmenu=members&amp;mainmenu=members", $langs->trans("Members"), 0, $user->rights->adherent->lire, '', $mainmenu, 'members');
1874 1874
 				$newmenu->add("/adherents/card.php?leftmenu=members&amp;action=create", $langs->trans("NewMember"), 1, $user->rights->adherent->creer);
@@ -1971,7 +1971,7 @@  discard block
 block discarded – undo
1971 1971
 				$lastopened = true;
1972 1972
 				for ($j = ($i + 1); $j < $num; $j++)
1973 1973
 				{
1974
-				    if (empty($menu_array[$j]['level'])) $lastopened = false;
1974
+					if (empty($menu_array[$j]['level'])) $lastopened = false;
1975 1975
 				}
1976 1976
 				if ($altok % 2 == 0)
1977 1977
 				{
@@ -1999,23 +1999,23 @@  discard block
 block discarded – undo
1999 1999
 			$url = $shorturl = $shorturlwithoutparam = $menu_array[$i]['url'];
2000 2000
 			if (!preg_match("/^(http:\/\/|https:\/\/)/i", $menu_array[$i]['url']))
2001 2001
 			{
2002
-			    $tmp = explode('?', $menu_array[$i]['url'], 2);
2003
-			    $url = $shorturl = $tmp[0];
2004
-			    $param = (isset($tmp[1]) ? $tmp[1] : ''); // params in url of the menu link
2005
-
2006
-			    // Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined.
2007
-			    if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && !empty($menu_array[$i]['mainmenu']))
2008
-			    {
2009
-			        $param .= ($param ? '&' : '').'mainmenu='.$menu_array[$i]['mainmenu'].'&leftmenu=';
2010
-			    }
2011
-			    if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && empty($menu_array[$i]['mainmenu']))
2012
-			    {
2013
-			        $param .= ($param ? '&' : '').'leftmenu=';
2014
-			    }
2015
-			    //$url.="idmenu=".$menu_array[$i]['rowid'];    // Already done by menuLoad
2016
-			    $url = dol_buildpath($url, 1).($param ? '?'.$param : '');
2017
-			    $shorturlwithoutparam = $shorturl;
2018
-			    $shorturl = $shorturl.($param ? '?'.$param : '');
2002
+				$tmp = explode('?', $menu_array[$i]['url'], 2);
2003
+				$url = $shorturl = $tmp[0];
2004
+				$param = (isset($tmp[1]) ? $tmp[1] : ''); // params in url of the menu link
2005
+
2006
+				// Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined.
2007
+				if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && !empty($menu_array[$i]['mainmenu']))
2008
+				{
2009
+					$param .= ($param ? '&' : '').'mainmenu='.$menu_array[$i]['mainmenu'].'&leftmenu=';
2010
+				}
2011
+				if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && empty($menu_array[$i]['mainmenu']))
2012
+				{
2013
+					$param .= ($param ? '&' : '').'leftmenu=';
2014
+				}
2015
+				//$url.="idmenu=".$menu_array[$i]['rowid'];    // Already done by menuLoad
2016
+				$url = dol_buildpath($url, 1).($param ? '?'.$param : '');
2017
+				$shorturlwithoutparam = $shorturl;
2018
+				$shorturl = $shorturl.($param ? '?'.$param : '');
2019 2019
 			}
2020 2020
 
2021 2021
 
@@ -2039,7 +2039,7 @@  discard block
 block discarded – undo
2039 2039
 					print '<div class="menu_titre">'.$tabstring.'<font class="vmenudisabled">'.$menu_array[$i]['titre'].'</font></div>'."\n";
2040 2040
 					$lastlevel0 = 'greyed';
2041 2041
 				} else {
2042
-				    $lastlevel0 = 'hidden';
2042
+					$lastlevel0 = 'hidden';
2043 2043
 				}
2044 2044
 				if ($showmenu)
2045 2045
 				{
Please login to merge, or discard this patch.