Passed
Push — master ( 49af33...3cffbe )
by Alxarafe
21:21
created
dolibarr/htdocs/core/class/antivir.class.php 1 patch
Braces   +13 added lines, -5 removed lines patch added patch discarded remove patch
@@ -129,15 +129,19 @@  discard block
 block discarded – undo
129 129
 		dol_syslog("AntiVir::dol_avscan_file Result return_var=".$return_var." output=".join(',',$output));
130 130
 
131 131
 		$returncodevirus=1;
132
-		if ($return_var == $returncodevirus)	// Virus found
132
+		if ($return_var == $returncodevirus) {
133
+		    // Virus found
133 134
 		{
134 135
 			$this->errors=$output;
136
+		}
135 137
 			return -99;
136 138
 		}
137 139
 
138
-		if ($return_var > 0)					// If other error
140
+		if ($return_var > 0) {
141
+		    // If other error
139 142
 		{
140 143
 			$this->errors=$output;
144
+		}
141 145
 			return -98;
142 146
 		}
143 147
 
@@ -173,10 +177,14 @@  discard block
 block discarded – undo
173 177
 		$param=preg_replace('/%maxfilesize/',$maxfilesize,$param);
174 178
 		$param=preg_replace('/%file/',trim($file),$param);
175 179
 
176
-		if (! preg_match('/%file/',$conf->global->MAIN_ANTIVIRUS_PARAM))
177
-			$param=$param." ".escapeshellarg(trim($file));
180
+		if (! preg_match('/%file/',$conf->global->MAIN_ANTIVIRUS_PARAM)) {
181
+					$param=$param." ".escapeshellarg(trim($file));
182
+		}
178 183
 
179
-		if (preg_match("/\s/",$command)) $command=escapeshellarg($command);	// Use quotes on command. Using escapeshellcmd fails.
184
+		if (preg_match("/\s/",$command)) {
185
+		    $command=escapeshellarg($command);
186
+		}
187
+		// Use quotes on command. Using escapeshellcmd fails.
180 188
 
181 189
 		$ret=$command.' '.$param;
182 190
 		//$ret=$command.' '.$param.' 2>&1';
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/commonobject.class.php 1 patch
Braces   +1328 added lines, -795 removed lines patch added patch discarded remove patch
@@ -426,23 +426,31 @@  discard block
 block discarded – undo
426 426
 		$sql.= " FROM ".MAIN_DB_PREFIX.$element;
427 427
 		$sql.= " WHERE entity IN (".getEntity($element).")" ;
428 428
 
429
-		if ($id > 0) $sql.= " AND rowid = ".$db->escape($id);
430
-		else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'";
431
-		else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'";
432
-		else {
429
+		if ($id > 0) {
430
+		    $sql.= " AND rowid = ".$db->escape($id);
431
+		} else if ($ref) {
432
+		    $sql.= " AND ref = '".$db->escape($ref)."'";
433
+		} else if ($ref_ext) {
434
+		    $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'";
435
+		} else {
433 436
 			$error='ErrorWrongParameters';
434 437
 			dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR);
435 438
 			return -1;
436 439
 		}
437
-		if ($ref || $ref_ext) $sql.= " AND entity = ".$conf->entity;
440
+		if ($ref || $ref_ext) {
441
+		    $sql.= " AND entity = ".$conf->entity;
442
+		}
438 443
 
439 444
 		dol_syslog(get_class()."::isExistingObject", LOG_DEBUG);
440 445
 		$resql = $db->query($sql);
441 446
 		if ($resql)
442 447
 		{
443 448
 			$num=$db->num_rows($resql);
444
-			if ($num > 0) return 1;
445
-			else return 0;
449
+			if ($num > 0) {
450
+			    return 1;
451
+			} else {
452
+			    return 0;
453
+			}
446 454
 		}
447 455
 		return -1;
448 456
 	}
@@ -471,13 +479,18 @@  discard block
 block discarded – undo
471 479
 		//print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n";
472 480
 		$lastname=$this->lastname;
473 481
 		$firstname=$this->firstname;
474
-		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:'')))));
482
+		if (empty($lastname)) {
483
+		    $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:'')))));
484
+		}
475 485
 
476 486
 		$ret='';
477 487
 		if ($option && $this->civility_id)
478 488
 		{
479
-			if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' ';
480
-			else $ret.=$this->civility_id.' ';
489
+			if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) {
490
+			    $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' ';
491
+			} else {
492
+			    $ret.=$this->civility_id.' ';
493
+			}
481 494
 		}
482 495
 
483 496
 		$ret.=dolGetFirstLastname($firstname, $lastname, $nameorder);
@@ -570,14 +583,15 @@  discard block
 block discarded – undo
570 583
 		{
571 584
             if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) {
572 585
                 $out.=($outdone?' - ':'').$this->region.' - '.$this->state;
573
-            }
574
-            else {
586
+            } else {
575 587
                 $out.=($outdone?' - ':'').$this->state;
576 588
             }
577 589
 			$outdone++;
578 590
 		}
579 591
 
580
-		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>':'');
592
+		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)) {
593
+		    $out.=($outdone?'<br>':'');
594
+		}
581 595
 		if (! empty($this->phone) && empty($this->phone_pro)) {		// For objects that store pro phone into ->phone
582 596
 			$out.=dol_print_phone($this->phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL','&nbsp;','phone',$langs->trans("PhonePro")); $outdone++;
583 597
 		}
@@ -618,13 +632,21 @@  discard block
 block discarded – undo
618 632
 		$out.='<div style="clear: both;">';
619 633
 		if (! empty($conf->socialnetworks->enabled))
620 634
 		{
621
-			if ($this->skype) $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype');
635
+			if ($this->skype) {
636
+			    $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype');
637
+			}
622 638
 			$outdone++;
623
-			if ($this->jabberid) $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber');
639
+			if ($this->jabberid) {
640
+			    $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber');
641
+			}
624 642
 			$outdone++;
625
-			if ($this->twitter) $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter');
643
+			if ($this->twitter) {
644
+			    $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter');
645
+			}
626 646
 			$outdone++;
627
-			if ($this->facebook) $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook');
647
+			if ($this->facebook) {
648
+			    $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook');
649
+			}
628 650
 			$outdone++;
629 651
 		}
630 652
 		$out.='</div>';
@@ -684,10 +706,10 @@  discard block
 block discarded – undo
684 706
 					$this->errors = $ecmfile->errors;
685 707
 				}
686 708
 				*/
709
+			} else {
710
+			    return '';
687 711
 			}
688
-			else return '';
689
-		}
690
-		elseif (empty($ecmfile->share))
712
+		} elseif (empty($ecmfile->share))
691 713
 		{
692 714
 			// Add entry into index
693 715
 			if ($initsharekey)
@@ -695,8 +717,9 @@  discard block
 block discarded – undo
695 717
 				require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
696 718
 				$ecmfile->share = getRandomPassword(true);
697 719
 				$ecmfile->update($user);
720
+			} else {
721
+			    return '';
698 722
 			}
699
-			else return '';
700 723
 		}
701 724
 
702 725
 		// Define $urlwithroot
@@ -710,14 +733,18 @@  discard block
 block discarded – undo
710 733
 		//if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart;		// For sharing with hash (so public files), modulepart is not required.
711 734
 		//if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; 					// For sharing with hash (so public files), entity is not required.
712 735
 		//$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath);								// No need of name of file for public link, we will use the hash
713
-		if (! empty($ecmfile->share)) $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share;			// Hash for public share
714
-		if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1';
736
+		if (! empty($ecmfile->share)) {
737
+		    $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share;
738
+		}
739
+		// Hash for public share
740
+		if ($forcedownload) {
741
+		    $paramlink.=($paramlink?'&':'').'attachment=1';
742
+		}
715 743
 
716 744
 		if ($relativelink)
717 745
 		{
718 746
 			$linktoreturn='document.php'.($paramlink?'?'.$paramlink:'');
719
-		}
720
-		else
747
+		} else
721 748
 		{
722 749
 			$linktoreturn=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:'');
723 750
 		}
@@ -765,8 +792,7 @@  discard block
 block discarded – undo
765 792
 		if (is_numeric($type_contact))
766 793
 		{
767 794
 			$id_type_contact=$type_contact;
768
-		}
769
-		else
795
+		} else
770 796
 		{
771 797
 			// We look for id type_contact
772 798
 			$sql = "SELECT tc.rowid";
@@ -779,7 +805,9 @@  discard block
 block discarded – undo
779 805
 			if ($resql)
780 806
 			{
781 807
 				$obj = $this->db->fetch_object($resql);
782
-				if ($obj) $id_type_contact=$obj->rowid;
808
+				if ($obj) {
809
+				    $id_type_contact=$obj->rowid;
810
+				}
783 811
 			}
784 812
 		}
785 813
 
@@ -831,8 +859,7 @@  discard block
 block discarded – undo
831 859
 
832 860
 				$this->db->commit();
833 861
 				return 1;
834
-			}
835
-			else
862
+			} else
836 863
 			{
837 864
 				if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
838 865
 				{
@@ -840,15 +867,16 @@  discard block
 block discarded – undo
840 867
 					$this->db->rollback();
841 868
 					echo 'err rollback';
842 869
 					return -2;
843
-				}
844
-				else
870
+				} else
845 871
 				{
846 872
 					$this->error=$this->db->error();
847 873
 					$this->db->rollback();
848 874
 					return -1;
849 875
 				}
850 876
 			}
851
-		} else return 0;
877
+		} else {
878
+		    return 0;
879
+		}
852 880
 	}
853 881
 
854 882
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -890,15 +918,18 @@  discard block
 block discarded – undo
890 918
 		// Insert into database
891 919
 		$sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set";
892 920
 		$sql.= " statut = ".$statut;
893
-		if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'";
894
-		if ($fk_socpeople) $sql.= ", fk_socpeople = '".$fk_socpeople ."'";
921
+		if ($type_contact_id) {
922
+		    $sql.= ", fk_c_type_contact = '".$type_contact_id ."'";
923
+		}
924
+		if ($fk_socpeople) {
925
+		    $sql.= ", fk_socpeople = '".$fk_socpeople ."'";
926
+		}
895 927
 		$sql.= " where rowid = ".$rowid;
896 928
 		$resql=$this->db->query($sql);
897 929
 		if ($resql)
898 930
 		{
899 931
 			return 0;
900
-		}
901
-		else
932
+		} else
902 933
 		{
903 934
 			$this->error=$this->db->lasterror();
904 935
 			return -1;
@@ -935,8 +966,7 @@  discard block
 block discarded – undo
935 966
 
936 967
 			$this->db->commit();
937 968
 			return 1;
938
-		}
939
-		else
969
+		} else
940 970
 		{
941 971
 			$this->error=$this->db->lasterror();
942 972
 			$this->db->rollback();
@@ -966,15 +996,15 @@  discard block
 block discarded – undo
966 996
 
967 997
 		$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact";
968 998
 		$sql.= " WHERE element_id = ".$this->id;
969
-		if ($listId)
970
-			$sql.= " AND fk_c_type_contact IN (".$listId.")";
999
+		if ($listId) {
1000
+					$sql.= " AND fk_c_type_contact IN (".$listId.")";
1001
+		}
971 1002
 
972 1003
 		dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG);
973 1004
 		if ($this->db->query($sql))
974 1005
 		{
975 1006
 			return 1;
976
-		}
977
-		else
1007
+		} else
978 1008
 		{
979 1009
 			$this->error=$this->db->lasterror();
980 1010
 			return -1;
@@ -999,22 +1029,38 @@  discard block
 block discarded – undo
999 1029
 		$tab=array();
1000 1030
 
1001 1031
 		$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
1002
-		if ($source == 'internal') $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo";
1003
-		if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid, t.statut as statuscontact";
1032
+		if ($source == 'internal') {
1033
+		    $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo";
1034
+		}
1035
+		if ($source == 'external' || $source == 'thirdparty') {
1036
+		    $sql.=", t.fk_soc as socid, t.statut as statuscontact";
1037
+		}
1004 1038
 		$sql.= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email";
1005 1039
 		$sql.= ", tc.source, tc.element, tc.code, tc.libelle";
1006 1040
 		$sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc";
1007 1041
 		$sql.= ", ".MAIN_DB_PREFIX."element_contact ec";
1008
-		if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid";
1009
-		if ($source == 'external'|| $source == 'thirdparty') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid";
1042
+		if ($source == 'internal') {
1043
+		    $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid";
1044
+		}
1045
+		if ($source == 'external'|| $source == 'thirdparty') {
1046
+		    $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid";
1047
+		}
1010 1048
 		$sql.= " WHERE ec.element_id =".$this->id;
1011 1049
 		$sql.= " AND ec.fk_c_type_contact=tc.rowid";
1012 1050
 		$sql.= " AND tc.element='".$this->db->escape($this->element)."'";
1013
-		if ($code) $sql.= " AND tc.code = '".$this->db->escape($code)."'";
1014
-		if ($source == 'internal') $sql.= " AND tc.source = 'internal'";
1015
-		if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'";
1051
+		if ($code) {
1052
+		    $sql.= " AND tc.code = '".$this->db->escape($code)."'";
1053
+		}
1054
+		if ($source == 'internal') {
1055
+		    $sql.= " AND tc.source = 'internal'";
1056
+		}
1057
+		if ($source == 'external' || $source == 'thirdparty') {
1058
+		    $sql.= " AND tc.source = 'external'";
1059
+		}
1016 1060
 		$sql.= " AND tc.active=1";
1017
-		if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'";
1061
+		if ($statut >= 0) {
1062
+		    $sql.= " AND ec.statut = '".$statut."'";
1063
+		}
1018 1064
 		$sql.=" ORDER BY t.lastname ASC";
1019 1065
 
1020 1066
 		dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG);
@@ -1035,8 +1081,7 @@  discard block
 block discarded – undo
1035 1081
 								   'nom'=>$obj->lastname,      // For backward compatibility
1036 1082
 								   'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact,
1037 1083
 								   'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact);
1038
-				}
1039
-				else
1084
+				} else
1040 1085
 				{
1041 1086
 					$tab[$i]=$obj->id;
1042 1087
 				}
@@ -1045,8 +1090,7 @@  discard block
 block discarded – undo
1045 1090
 			}
1046 1091
 
1047 1092
 			return $tab;
1048
-		}
1049
-		else
1093
+		} else
1050 1094
 		{
1051 1095
 			$this->error=$this->db->lasterror();
1052 1096
 			dol_print_error($this->db);
@@ -1081,8 +1125,7 @@  discard block
 block discarded – undo
1081 1125
 			$result = $this->update_contact($rowid, $newstatut);
1082 1126
 			$this->db->free($resql);
1083 1127
 			return $result;
1084
-		}
1085
-		else
1128
+		} else
1086 1129
 		{
1087 1130
 			$this->error=$this->db->error();
1088 1131
 			dol_print_error($this->db);
@@ -1106,16 +1149,27 @@  discard block
 block discarded – undo
1106 1149
         // phpcs:enable
1107 1150
 		global $langs;
1108 1151
 
1109
-		if (empty($order)) $order='position';
1110
-		if ($order == 'position') $order.=',code';
1152
+		if (empty($order)) {
1153
+		    $order='position';
1154
+		}
1155
+		if ($order == 'position') {
1156
+		    $order.=',code';
1157
+		}
1111 1158
 
1112 1159
 		$tab = array();
1113 1160
 		$sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position";
1114 1161
 		$sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";
1115 1162
 		$sql.= " WHERE tc.element='".$this->db->escape($this->element)."'";
1116
-		if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active types
1117
-		if (! empty($source) && $source != 'all') $sql.= " AND tc.source='".$this->db->escape($source)."'";
1118
-		if (! empty($code)) $sql.= " AND tc.code='".$this->db->escape($code)."'";
1163
+		if ($activeonly == 1) {
1164
+		    $sql.= " AND tc.active=1";
1165
+		}
1166
+		// only the active types
1167
+		if (! empty($source) && $source != 'all') {
1168
+		    $sql.= " AND tc.source='".$this->db->escape($source)."'";
1169
+		}
1170
+		if (! empty($code)) {
1171
+		    $sql.= " AND tc.code='".$this->db->escape($code)."'";
1172
+		}
1119 1173
 		$sql.= $this->db->order($order,'ASC');
1120 1174
 
1121 1175
 		//print "sql=".$sql;
@@ -1130,13 +1184,15 @@  discard block
 block discarded – undo
1130 1184
 
1131 1185
 				$transkey="TypeContact_".$this->element."_".$source."_".$obj->code;
1132 1186
 				$libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle);
1133
-				if (empty($option)) $tab[$obj->rowid]=$libelle_type;
1134
-				else $tab[$obj->code]=$libelle_type;
1187
+				if (empty($option)) {
1188
+				    $tab[$obj->rowid]=$libelle_type;
1189
+				} else {
1190
+				    $tab[$obj->code]=$libelle_type;
1191
+				}
1135 1192
 				$i++;
1136 1193
 			}
1137 1194
 			return $tab;
1138
-		}
1139
-		else
1195
+		} else
1140 1196
 		{
1141 1197
 			$this->error=$this->db->lasterror();
1142 1198
 			//dol_print_error($this->db);
@@ -1175,19 +1231,29 @@  discard block
 block discarded – undo
1175 1231
 
1176 1232
 		$sql = "SELECT ec.fk_socpeople";
1177 1233
 		$sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec,";
1178
-		if ($source == 'internal') $sql.= " ".MAIN_DB_PREFIX."user as c,";
1179
-		if ($source == 'external') $sql.= " ".MAIN_DB_PREFIX."socpeople as c,";
1234
+		if ($source == 'internal') {
1235
+		    $sql.= " ".MAIN_DB_PREFIX."user as c,";
1236
+		}
1237
+		if ($source == 'external') {
1238
+		    $sql.= " ".MAIN_DB_PREFIX."socpeople as c,";
1239
+		}
1180 1240
 		$sql.= " ".MAIN_DB_PREFIX."c_type_contact as tc";
1181 1241
 		$sql.= " WHERE ec.element_id = ".$id;
1182 1242
 		$sql.= " AND ec.fk_socpeople = c.rowid";
1183
-		if ($source == 'internal') $sql.= " AND c.entity IN (".getEntity('user').")";
1184
-		if ($source == 'external') $sql.= " AND c.entity IN (".getEntity('societe').")";
1243
+		if ($source == 'internal') {
1244
+		    $sql.= " AND c.entity IN (".getEntity('user').")";
1245
+		}
1246
+		if ($source == 'external') {
1247
+		    $sql.= " AND c.entity IN (".getEntity('societe').")";
1248
+		}
1185 1249
 		$sql.= " AND ec.fk_c_type_contact = tc.rowid";
1186 1250
 		$sql.= " AND tc.element = '".$element."'";
1187 1251
 		$sql.= " AND tc.source = '".$source."'";
1188 1252
 		$sql.= " AND tc.code = '".$code."'";
1189 1253
 		$sql.= " AND tc.active = 1";
1190
-		if ($status) $sql.= " AND ec.statut = ".$status;
1254
+		if ($status) {
1255
+		    $sql.= " AND ec.statut = ".$status;
1256
+		}
1191 1257
 
1192 1258
 		dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG);
1193 1259
 		$resql=$this->db->query($sql);
@@ -1198,8 +1264,7 @@  discard block
 block discarded – undo
1198 1264
 				$result[$i]=$obj->fk_socpeople;
1199 1265
 				$i++;
1200 1266
 			}
1201
-		}
1202
-		else
1267
+		} else
1203 1268
 		{
1204 1269
 			$this->error=$this->db->error();
1205 1270
 			return null;
@@ -1218,9 +1283,13 @@  discard block
 block discarded – undo
1218 1283
 	function fetch_contact($contactid=null)
1219 1284
 	{
1220 1285
         // phpcs:enable
1221
-		if (empty($contactid)) $contactid=$this->contactid;
1286
+		if (empty($contactid)) {
1287
+		    $contactid=$this->contactid;
1288
+		}
1222 1289
 
1223
-		if (empty($contactid)) return 0;
1290
+		if (empty($contactid)) {
1291
+		    return 0;
1292
+		}
1224 1293
 
1225 1294
 		require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
1226 1295
 		$contact = new Contact($this->db);
@@ -1241,14 +1310,16 @@  discard block
 block discarded – undo
1241 1310
         // phpcs:enable
1242 1311
 		global $conf;
1243 1312
 
1244
-		if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id))
1245
-			return 0;
1313
+		if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) {
1314
+					return 0;
1315
+		}
1246 1316
 
1247 1317
 		require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
1248 1318
 
1249 1319
 		$idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty);
1250
-		if ($force_thirdparty_id)
1251
-			$idtofetch = $force_thirdparty_id;
1320
+		if ($force_thirdparty_id) {
1321
+					$idtofetch = $force_thirdparty_id;
1322
+		}
1252 1323
 
1253 1324
 		if ($idtofetch) {
1254 1325
 			$thirdparty = new Societe($this->db);
@@ -1261,8 +1332,9 @@  discard block
 block discarded – undo
1261 1332
 			}
1262 1333
 
1263 1334
 			return $result;
1264
-		} else
1265
-			return -1;
1335
+		} else {
1336
+					return -1;
1337
+		}
1266 1338
 	}
1267 1339
 
1268 1340
 
@@ -1308,18 +1380,24 @@  discard block
 block discarded – undo
1308 1380
 		dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type);
1309 1381
 
1310 1382
 		$idtype=$this->barcode_type;
1311
-		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
1383
+		if (empty($idtype) && $idtype != '0') {
1384
+		    // If type of barcode no set, we try to guess. If set to '0' it means we forced to have type remain not defined
1312 1385
 		{
1313 1386
 			if ($this->element == 'product')      $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
1314
-			else if ($this->element == 'societe') $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY;
1315
-			else dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING);
1387
+		} else if ($this->element == 'societe') {
1388
+			    $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY;
1389
+			} else {
1390
+			    dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING);
1391
+			}
1316 1392
 		}
1317 1393
 
1318 1394
 		if ($idtype > 0)
1319 1395
 		{
1320
-			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
1396
+			if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) {
1397
+			    // If data not already loaded
1321 1398
 			{
1322 1399
 				$sql = "SELECT rowid, code, libelle as label, coder";
1400
+			}
1323 1401
 				$sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
1324 1402
 				$sql.= " WHERE rowid = ".$idtype;
1325 1403
 				dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG);
@@ -1332,8 +1410,7 @@  discard block
 block discarded – undo
1332 1410
 					$this->barcode_type_label = $obj->label;
1333 1411
 					$this->barcode_type_coder = $obj->coder;
1334 1412
 					return 1;
1335
-				}
1336
-				else
1413
+				} else
1337 1414
 				{
1338 1415
 					dol_print_error($this->db);
1339 1416
 					return -1;
@@ -1354,8 +1431,13 @@  discard block
 block discarded – undo
1354 1431
         // phpcs:enable
1355 1432
 		include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1356 1433
 
1357
-		if (empty($this->fk_project) && ! empty($this->fk_projet)) $this->fk_project = $this->fk_projet;	// For backward compatibility
1358
-		if (empty($this->fk_project)) return 0;
1434
+		if (empty($this->fk_project) && ! empty($this->fk_projet)) {
1435
+		    $this->fk_project = $this->fk_projet;
1436
+		}
1437
+		// For backward compatibility
1438
+		if (empty($this->fk_project)) {
1439
+		    return 0;
1440
+		}
1359 1441
 
1360 1442
 		$project = new Project($this->db);
1361 1443
 		$result = $project->fetch($this->fk_project);
@@ -1376,7 +1458,9 @@  discard block
 block discarded – undo
1376 1458
         // phpcs:enable
1377 1459
 		include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
1378 1460
 
1379
-		if (empty($this->fk_product)) return 0;
1461
+		if (empty($this->fk_product)) {
1462
+		    return 0;
1463
+		}
1380 1464
 
1381 1465
 		$product = new Product($this->db);
1382 1466
 		$result = $product->fetch($this->fk_product);
@@ -1410,9 +1494,15 @@  discard block
 block discarded – undo
1410 1494
 	function fetch_origin()
1411 1495
 	{
1412 1496
         // phpcs:enable
1413
-		if ($this->origin == 'shipping') $this->origin = 'expedition';
1414
-		if ($this->origin == 'delivery') $this->origin = 'livraison';
1415
-        if ($this->origin == 'order_supplier') $this->origin = 'commandeFournisseur';
1497
+		if ($this->origin == 'shipping') {
1498
+		    $this->origin = 'expedition';
1499
+		}
1500
+		if ($this->origin == 'delivery') {
1501
+		    $this->origin = 'livraison';
1502
+		}
1503
+        if ($this->origin == 'order_supplier') {
1504
+            $this->origin = 'commandeFournisseur';
1505
+        }
1416 1506
 
1417 1507
 		$origin = $this->origin;
1418 1508
 
@@ -1504,29 +1594,48 @@  discard block
 block discarded – undo
1504 1594
 	{
1505 1595
 		global $user,$langs,$conf;
1506 1596
 
1507
-		if (empty($table)) 	  $table=$this->table_element;
1508
-		if (empty($id))    	  $id=$this->id;
1509
-		if (empty($format))   $format='text';
1510
-		if (empty($id_field)) $id_field='rowid';
1597
+		if (empty($table)) {
1598
+		    $table=$this->table_element;
1599
+		}
1600
+		if (empty($id)) {
1601
+		    $id=$this->id;
1602
+		}
1603
+		if (empty($format)) {
1604
+		    $format='text';
1605
+		}
1606
+		if (empty($id_field)) {
1607
+		    $id_field='rowid';
1608
+		}
1511 1609
 
1512 1610
 		$error=0;
1513 1611
 
1514 1612
 		$this->db->begin();
1515 1613
 
1516 1614
 		// Special case
1517
-		if ($table == 'product' && $field == 'note_private') $field='note';
1518
-		if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod';
1615
+		if ($table == 'product' && $field == 'note_private') {
1616
+		    $field='note';
1617
+		}
1618
+		if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) {
1619
+		    $fk_user_field = 'fk_user_mod';
1620
+		}
1519 1621
 
1520 1622
 		$sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET ";
1521 1623
 
1522
-		if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'";
1523
-		else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value);
1524
-		else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null");
1624
+		if ($format == 'text') {
1625
+		    $sql.= $field." = '".$this->db->escape($value)."'";
1626
+		} else if ($format == 'int') {
1627
+		    $sql.= $field." = ".$this->db->escape($value);
1628
+		} else if ($format == 'date') {
1629
+		    $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null");
1630
+		}
1525 1631
 
1526 1632
 		if ($fk_user_field)
1527 1633
 		{
1528
-			if (! empty($fuser) && is_object($fuser)) $sql.=", ".$fk_user_field." = ".$fuser->id;
1529
-			elseif (empty($fuser) || $fuser != 'none') $sql.=", ".$fk_user_field." = ".$user->id;
1634
+			if (! empty($fuser) && is_object($fuser)) {
1635
+			    $sql.=", ".$fk_user_field." = ".$fuser->id;
1636
+			} elseif (empty($fuser) || $fuser != 'none') {
1637
+			    $sql.=", ".$fk_user_field." = ".$user->id;
1638
+			}
1530 1639
 		}
1531 1640
 
1532 1641
 		$sql.= " WHERE ".$id_field." = ".$id;
@@ -1541,28 +1650,32 @@  discard block
 block discarded – undo
1541 1650
 				if (empty($this->fields) && method_exists($this, 'fetch'))
1542 1651
 				{
1543 1652
 					$result = $this->fetch($id);
1544
-				}
1545
-				else
1653
+				} else
1546 1654
 				{
1547 1655
 					$result = $this->fetchCommon($id);
1548 1656
 				}
1549
-				if ($result >= 0) $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user);   // This may set this->errors
1550
-				if ($result < 0) $error++;
1657
+				if ($result >= 0) {
1658
+				    $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user);
1659
+				}
1660
+				// This may set this->errors
1661
+				if ($result < 0) {
1662
+				    $error++;
1663
+				}
1551 1664
 			}
1552 1665
 
1553 1666
 			if (! $error)
1554 1667
 			{
1555
-				if (property_exists($this, $field)) $this->$field = $value;
1668
+				if (property_exists($this, $field)) {
1669
+				    $this->$field = $value;
1670
+				}
1556 1671
 				$this->db->commit();
1557 1672
 				return 1;
1558
-			}
1559
-			else
1673
+			} else
1560 1674
 			{
1561 1675
 				$this->db->rollback();
1562 1676
 				return -2;
1563 1677
 			}
1564
-		}
1565
-		else
1678
+		} else
1566 1679
 		{
1567 1680
 			$this->error=$this->db->lasterror();
1568 1681
 			$this->db->rollback();
@@ -1589,36 +1702,66 @@  discard block
 block discarded – undo
1589 1702
 			dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined");
1590 1703
 			return -1;
1591 1704
 		}
1592
-		if ($fieldid == 'none') return 1;
1705
+		if ($fieldid == 'none') {
1706
+		    return 1;
1707
+		}
1593 1708
 
1594 1709
 		// Security on socid
1595 1710
 		$socid = 0;
1596
-		if ($user->societe_id > 0) $socid = $user->societe_id;
1711
+		if ($user->societe_id > 0) {
1712
+		    $socid = $user->societe_id;
1713
+		}
1597 1714
 
1598 1715
 		// this->ismultientitymanaged contains
1599 1716
 		// 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
1600 1717
 		$alias = 's';
1601
-		if ($this->element == 'societe') $alias = 'te';
1718
+		if ($this->element == 'societe') {
1719
+		    $alias = 'te';
1720
+		}
1602 1721
 
1603 1722
 		$sql = "SELECT MAX(te.".$fieldid.")";
1604 1723
 		$sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te";
1605 1724
 		if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1606 1725
 			$sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug";
1607 1726
 		}
1608
-		if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ", ".MAIN_DB_PREFIX."societe as s";	// If we need to link to societe to limit select to entity
1609
-		else if ($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
1610
-		else if ($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
1611
-		if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid)  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc";
1727
+		if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) {
1728
+		    $sql.= ", ".MAIN_DB_PREFIX."societe as s";
1729
+		}
1730
+		// If we need to link to societe to limit select to entity
1731
+		else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
1732
+		    $sql.= ", ".MAIN_DB_PREFIX."societe as s";
1733
+		}
1734
+		// If we need to link to societe to limit select to socid
1735
+		else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
1736
+		    $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid";
1737
+		}
1738
+		// If we need to link to societe to limit select to socid
1739
+		if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) {
1740
+		    $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc";
1741
+		}
1612 1742
 		$sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'";  // ->ref must always be defined (set to id if field does not exists)
1613
-		if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id;
1614
-		if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)';
1743
+		if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) {
1744
+		    $sql.= " AND sc.fk_user = " .$user->id;
1745
+		}
1746
+		if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) {
1747
+		    $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)';
1748
+		}
1615 1749
 		if (! empty($filter))
1616 1750
 		{
1617
-			if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND ";   // For backward compatibility
1751
+			if (! preg_match('/^\s*AND/i', $filter)) {
1752
+			    $sql.=" AND ";
1753
+			}
1754
+			// For backward compatibility
1618 1755
 			$sql.=$filter;
1619 1756
 		}
1620
-		if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ' AND te.fk_soc = s.rowid';			// If we need to link to societe to limit select to entity
1621
-		else if ($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
1757
+		if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) {
1758
+		    $sql.= ' AND te.fk_soc = s.rowid';
1759
+		}
1760
+		// If we need to link to societe to limit select to entity
1761
+		else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
1762
+		    $sql.= ' AND te.fk_soc = s.rowid';
1763
+		}
1764
+		// If we need to link to societe to limit select to socid
1622 1765
 		if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
1623 1766
 			if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1624 1767
 				if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
@@ -1631,9 +1774,15 @@  discard block
 block discarded – undo
1631 1774
 				$sql.= ' AND te.entity IN ('.getEntity($this->element).')';
1632 1775
 			}
1633 1776
 		}
1634
-		if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid;
1635
-		if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)';
1636
-		if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid;
1777
+		if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') {
1778
+		    $sql.= ' AND te.fk_soc = ' . $socid;
1779
+		}
1780
+		if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') {
1781
+		    $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)';
1782
+		}
1783
+		if ($this->restrictiononfksoc && $socid && $this->element == 'societe') {
1784
+		    $sql.= ' AND te.rowid = ' . $socid;
1785
+		}
1637 1786
 		//print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>";
1638 1787
 
1639 1788
 		$result = $this->db->query($sql);
@@ -1651,20 +1800,44 @@  discard block
 block discarded – undo
1651 1800
 		if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1652 1801
 			$sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug";
1653 1802
 		}
1654
-		if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ", ".MAIN_DB_PREFIX."societe as s";	// If we need to link to societe to limit select to entity
1655
-		else if ($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
1656
-		else if ($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
1657
-		if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc";
1803
+		if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) {
1804
+		    $sql.= ", ".MAIN_DB_PREFIX."societe as s";
1805
+		}
1806
+		// If we need to link to societe to limit select to entity
1807
+		else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
1808
+		    $sql.= ", ".MAIN_DB_PREFIX."societe as s";
1809
+		}
1810
+		// If we need to link to societe to limit select to socid
1811
+		else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
1812
+		    $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid";
1813
+		}
1814
+		// If we need to link to societe to limit select to socid
1815
+		if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) {
1816
+		    $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc";
1817
+		}
1658 1818
 		$sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'";  // ->ref must always be defined (set to id if field does not exists)
1659
-		if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id;
1660
-		if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)';
1819
+		if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) {
1820
+		    $sql.= " AND sc.fk_user = " .$user->id;
1821
+		}
1822
+		if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) {
1823
+		    $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)';
1824
+		}
1661 1825
 		if (! empty($filter))
1662 1826
 		{
1663
-			if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND ";   // For backward compatibility
1827
+			if (! preg_match('/^\s*AND/i', $filter)) {
1828
+			    $sql.=" AND ";
1829
+			}
1830
+			// For backward compatibility
1664 1831
 			$sql.=$filter;
1665 1832
 		}
1666
-		if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ' AND te.fk_soc = s.rowid';			// If we need to link to societe to limit select to entity
1667
-		else if ($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
1833
+		if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) {
1834
+		    $sql.= ' AND te.fk_soc = s.rowid';
1835
+		}
1836
+		// If we need to link to societe to limit select to entity
1837
+		else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
1838
+		    $sql.= ' AND te.fk_soc = s.rowid';
1839
+		}
1840
+		// If we need to link to societe to limit select to socid
1668 1841
 		if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
1669 1842
 			if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1670 1843
 				if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
@@ -1677,9 +1850,15 @@  discard block
 block discarded – undo
1677 1850
 				$sql.= ' AND te.entity IN ('.getEntity($this->element).')';
1678 1851
 			}
1679 1852
 		}
1680
-		if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid;
1681
-		if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)';
1682
-		if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid;
1853
+		if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') {
1854
+		    $sql.= ' AND te.fk_soc = ' . $socid;
1855
+		}
1856
+		if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') {
1857
+		    $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)';
1858
+		}
1859
+		if ($this->restrictiononfksoc && $socid && $this->element == 'societe') {
1860
+		    $sql.= ' AND te.rowid = ' . $socid;
1861
+		}
1683 1862
 		//print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>";
1684 1863
 		// 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
1685 1864
 
@@ -1711,8 +1890,11 @@  discard block
 block discarded – undo
1711 1890
 		$i = 0;
1712 1891
 		while ($i < $num)
1713 1892
 		{
1714
-			if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid'];
1715
-			else  $contactAlreadySelected[$i] = $tab[$i]['id'];
1893
+			if ($source == 'thirdparty') {
1894
+			    $contactAlreadySelected[$i] = $tab[$i]['socid'];
1895
+			} else {
1896
+			    $contactAlreadySelected[$i] = $tab[$i]['id'];
1897
+			}
1716 1898
 			$i++;
1717 1899
 		}
1718 1900
 		return $contactAlreadySelected;
@@ -1736,14 +1918,19 @@  discard block
 block discarded – undo
1736 1918
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1737 1919
 		if ($this->table_element == 'actioncomm')
1738 1920
 		{
1739
-			if ($projectid) $sql.= ' SET fk_project = '.$projectid;
1740
-			else $sql.= ' SET fk_project = NULL';
1921
+			if ($projectid) {
1922
+			    $sql.= ' SET fk_project = '.$projectid;
1923
+			} else {
1924
+			    $sql.= ' SET fk_project = NULL';
1925
+			}
1741 1926
 			$sql.= ' WHERE id = '.$this->id;
1742
-		}
1743
-		else
1927
+		} else
1744 1928
 		{
1745
-			if ($projectid) $sql.= ' SET fk_projet = '.$projectid;
1746
-			else $sql.= ' SET fk_projet = NULL';
1929
+			if ($projectid) {
1930
+			    $sql.= ' SET fk_projet = '.$projectid;
1931
+			} else {
1932
+			    $sql.= ' SET fk_projet = NULL';
1933
+			}
1747 1934
 			$sql.= ' WHERE rowid = '.$this->id;
1748 1935
 		}
1749 1936
 
@@ -1752,8 +1939,7 @@  discard block
 block discarded – undo
1752 1939
 		{
1753 1940
 			$this->fk_project = $projectid;
1754 1941
 			return 1;
1755
-		}
1756
-		else
1942
+		} else
1757 1943
 		{
1758 1944
 			dol_print_error($this->db);
1759 1945
 			return -1;
@@ -1773,8 +1959,12 @@  discard block
 block discarded – undo
1773 1959
 		{
1774 1960
 			// TODO uniformize field name
1775 1961
 			$fieldname = 'fk_mode_reglement';
1776
-			if ($this->element == 'societe') $fieldname = 'mode_reglement';
1777
-			if (get_class($this) == 'Fournisseur') $fieldname = 'mode_reglement_supplier';
1962
+			if ($this->element == 'societe') {
1963
+			    $fieldname = 'mode_reglement';
1964
+			}
1965
+			if (get_class($this) == 'Fournisseur') {
1966
+			    $fieldname = 'mode_reglement_supplier';
1967
+			}
1778 1968
 
1779 1969
 			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1780 1970
 			$sql .= ' SET '.$fieldname.' = '.$id;
@@ -1784,17 +1974,17 @@  discard block
 block discarded – undo
1784 1974
 			{
1785 1975
 				$this->mode_reglement_id = $id;
1786 1976
 				// for supplier
1787
-				if (get_class($this) == 'Fournisseur') $this->mode_reglement_supplier_id = $id;
1977
+				if (get_class($this) == 'Fournisseur') {
1978
+				    $this->mode_reglement_supplier_id = $id;
1979
+				}
1788 1980
 				return 1;
1789
-			}
1790
-			else
1981
+			} else
1791 1982
 			{
1792 1983
 				dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error());
1793 1984
 				$this->error=$this->db->error();
1794 1985
 				return -1;
1795 1986
 			}
1796
-		}
1797
-		else
1987
+		} else
1798 1988
 		{
1799 1989
 			dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible');
1800 1990
 			$this->error='Status of the object is incompatible '.$this->statut;
@@ -1824,18 +2014,18 @@  discard block
 block discarded – undo
1824 2014
 				$this->multicurrency_code = $code;
1825 2015
 
1826 2016
 				list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code);
1827
-				if ($rate) $this->setMulticurrencyRate($rate,2);
2017
+				if ($rate) {
2018
+				    $this->setMulticurrencyRate($rate,2);
2019
+				}
1828 2020
 
1829 2021
 				return 1;
1830
-			}
1831
-			else
2022
+			} else
1832 2023
 			{
1833 2024
 				dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error());
1834 2025
 				$this->error=$this->db->error();
1835 2026
 				return -1;
1836 2027
 			}
1837
-		}
1838
-		else
2028
+		} else
1839 2029
 		{
1840 2030
 			dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible');
1841 2031
 			$this->error='Status of the object is incompatible '.$this->statut;
@@ -1929,15 +2119,13 @@  discard block
 block discarded – undo
1929 2119
 				}
1930 2120
 
1931 2121
 				return 1;
1932
-			}
1933
-			else
2122
+			} else
1934 2123
 			{
1935 2124
 				dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error());
1936 2125
 				$this->error=$this->db->error();
1937 2126
 				return -1;
1938 2127
 			}
1939
-		}
1940
-		else
2128
+		} else
1941 2129
 		{
1942 2130
 			dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible');
1943 2131
 			$this->error='Status of the object is incompatible '.$this->statut;
@@ -1958,8 +2146,12 @@  discard block
 block discarded – undo
1958 2146
 		{
1959 2147
 			// TODO uniformize field name
1960 2148
 			$fieldname = 'fk_cond_reglement';
1961
-			if ($this->element == 'societe') $fieldname = 'cond_reglement';
1962
-			if (get_class($this) == 'Fournisseur') $fieldname = 'cond_reglement_supplier';
2149
+			if ($this->element == 'societe') {
2150
+			    $fieldname = 'cond_reglement';
2151
+			}
2152
+			if (get_class($this) == 'Fournisseur') {
2153
+			    $fieldname = 'cond_reglement_supplier';
2154
+			}
1963 2155
 
1964 2156
 			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1965 2157
 			$sql .= ' SET '.$fieldname.' = '.$id;
@@ -1969,18 +2161,18 @@  discard block
 block discarded – undo
1969 2161
 			{
1970 2162
 				$this->cond_reglement_id = $id;
1971 2163
 				// for supplier
1972
-				if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id;
2164
+				if (get_class($this) == 'Fournisseur') {
2165
+				    $this->cond_reglement_supplier_id = $id;
2166
+				}
1973 2167
 				$this->cond_reglement = $id;	// for compatibility
1974 2168
 				return 1;
1975
-			}
1976
-			else
2169
+			} else
1977 2170
 			{
1978 2171
 				dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error());
1979 2172
 				$this->error=$this->db->error();
1980 2173
 				return -1;
1981 2174
 			}
1982
-		}
1983
-		else
2175
+		} else
1984 2176
 		{
1985 2177
 			dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible');
1986 2178
 			$this->error='Status of the object is incompatible '.$this->statut;
@@ -1998,7 +2190,9 @@  discard block
 block discarded – undo
1998 2190
 	function setDeliveryAddress($id)
1999 2191
 	{
2000 2192
 		$fieldname = 'fk_delivery_address';
2001
-		if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address';
2193
+		if ($this->element == 'delivery' || $this->element == 'shipping') {
2194
+		    $fieldname = 'fk_address';
2195
+		}
2002 2196
 
2003 2197
 		$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id;
2004 2198
 		$sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
@@ -2007,8 +2201,7 @@  discard block
 block discarded – undo
2007 2201
 		{
2008 2202
 			$this->fk_delivery_address = $id;
2009 2203
 			return 1;
2010
-		}
2011
-		else
2204
+		} else
2012 2205
 		{
2013 2206
 			$this->error=$this->db->error();
2014 2207
 			dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error);
@@ -2030,7 +2223,9 @@  discard block
 block discarded – undo
2030 2223
 	{
2031 2224
         global $user;
2032 2225
 
2033
-        if (empty($userused)) $userused=$user;
2226
+        if (empty($userused)) {
2227
+            $userused=$user;
2228
+        }
2034 2229
 
2035 2230
         $error = 0;
2036 2231
 
@@ -2041,7 +2236,9 @@  discard block
 block discarded – undo
2041 2236
 
2042 2237
         $this->db->begin();
2043 2238
 
2044
-		if ($shipping_method_id<0) $shipping_method_id='NULL';
2239
+		if ($shipping_method_id<0) {
2240
+		    $shipping_method_id='NULL';
2241
+		}
2045 2242
 		dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')');
2046 2243
 
2047 2244
 		$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
@@ -2058,7 +2255,9 @@  discard block
 block discarded – undo
2058 2255
                 // Call trigger
2059 2256
                 $this->context=array('shippingmethodupdate'=>1);
2060 2257
                 $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused);
2061
-                if ($result < 0) $error++;
2258
+                if ($result < 0) {
2259
+                    $error++;
2260
+                }
2062 2261
                 // End call trigger
2063 2262
             }
2064 2263
         }
@@ -2086,7 +2285,9 @@  discard block
 block discarded – undo
2086 2285
 			dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined",LOG_ERR);
2087 2286
 			return -1;
2088 2287
 		}
2089
-		if ($warehouse_id<0) $warehouse_id='NULL';
2288
+		if ($warehouse_id<0) {
2289
+		    $warehouse_id='NULL';
2290
+		}
2090 2291
 		dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')');
2091 2292
 
2092 2293
 		$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
@@ -2133,8 +2334,7 @@  discard block
 block discarded – undo
2133 2334
 		{
2134 2335
 			$this->modelpdf=$modelpdf;
2135 2336
 			return 1;
2136
-		}
2137
-		else
2337
+		} else
2138 2338
 		{
2139 2339
 			dol_print_error($this->db);
2140 2340
 			return 0;
@@ -2154,7 +2354,9 @@  discard block
 block discarded – undo
2154 2354
 	{
2155 2355
         global $user;
2156 2356
 
2157
-        if (empty($userused)) $userused=$user;
2357
+        if (empty($userused)) {
2358
+            $userused=$user;
2359
+        }
2158 2360
 
2159 2361
         $error = 0;
2160 2362
 
@@ -2164,7 +2366,9 @@  discard block
 block discarded – undo
2164 2366
 		}
2165 2367
         $this->db->begin();
2166 2368
 
2167
-		if ($fk_account<0) $fk_account='NULL';
2369
+		if ($fk_account<0) {
2370
+		    $fk_account='NULL';
2371
+		}
2168 2372
 		dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')');
2169 2373
 
2170 2374
 		$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
@@ -2177,15 +2381,16 @@  discard block
 block discarded – undo
2177 2381
             dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error());
2178 2382
             $this->error = $this->db->lasterror();
2179 2383
             $error++;
2180
-        }
2181
-        else
2384
+        } else
2182 2385
         {
2183 2386
             if (!$notrigger)
2184 2387
             {
2185 2388
                 // Call trigger
2186 2389
                 $this->context=array('bankaccountupdate'=>1);
2187 2390
                 $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused);
2188
-                if ($result < 0) $error++;
2391
+                if ($result < 0) {
2392
+                    $error++;
2393
+                }
2189 2394
                 // End call trigger
2190 2395
             }
2191 2396
         }
@@ -2193,8 +2398,7 @@  discard block
 block discarded – undo
2193 2398
         {
2194 2399
             $this->db->rollback();
2195 2400
             return -1;
2196
-        }
2197
-        else
2401
+        } else
2198 2402
         {
2199 2403
             $this->fk_account = ($fk_account=='NULL')?null:$fk_account;
2200 2404
             $this->db->commit();
@@ -2233,8 +2437,12 @@  discard block
 block discarded – undo
2233 2437
 		$nl=0;
2234 2438
 		$sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line;
2235 2439
 		$sql.= ' WHERE '.$this->fk_element.'='.$this->id;
2236
-		if (! $renum) $sql.= ' AND rang = 0';
2237
-		if ($renum) $sql.= ' AND rang <> 0';
2440
+		if (! $renum) {
2441
+		    $sql.= ' AND rang = 0';
2442
+		}
2443
+		if ($renum) {
2444
+		    $sql.= ' AND rang <> 0';
2445
+		}
2238 2446
 
2239 2447
 		dol_syslog(get_class($this)."::line_order", LOG_DEBUG);
2240 2448
 		$resql = $this->db->query($sql);
@@ -2242,8 +2450,9 @@  discard block
 block discarded – undo
2242 2450
 		{
2243 2451
 			$row = $this->db->fetch_row($resql);
2244 2452
 			$nl = $row[0];
2453
+		} else {
2454
+		    dol_print_error($this->db);
2245 2455
 		}
2246
-		else dol_print_error($this->db);
2247 2456
 		if ($nl > 0)
2248 2457
 		{
2249 2458
 			// The goal of this part is to reorder all lines, with all children lines sharing the same
@@ -2253,7 +2462,9 @@  discard block
 block discarded – undo
2253 2462
 			// We first search all lines that are parent lines (for multilevel details lines)
2254 2463
 			$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line;
2255 2464
 			$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
2256
-			if ($fk_parent_line) $sql.= ' AND fk_parent_line IS NULL';
2465
+			if ($fk_parent_line) {
2466
+			    $sql.= ' AND fk_parent_line IS NULL';
2467
+			}
2257 2468
 			$sql.= ' ORDER BY rang ASC, rowid '.$rowidorder;
2258 2469
 
2259 2470
 			dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG);
@@ -2285,8 +2496,7 @@  discard block
 block discarded – undo
2285 2496
 						$this->updateRangOfLine($row, ($key+1));
2286 2497
 					}
2287 2498
 				}
2288
-			}
2289
-			else
2499
+			} else
2290 2500
 			{
2291 2501
 				dol_print_error($this->db);
2292 2502
 			}
@@ -2379,7 +2589,9 @@  discard block
 block discarded – undo
2379 2589
 	function updateRangOfLine($rowid,$rang)
2380 2590
 	{
2381 2591
 		$fieldposition = 'rang';
2382
-		if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
2592
+		if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) {
2593
+		    $fieldposition = 'position';
2594
+		}
2383 2595
 
2384 2596
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang;
2385 2597
 		$sql.= ' WHERE rowid = '.$rowid;
@@ -2420,7 +2632,9 @@  discard block
 block discarded – undo
2420 2632
 		if ($rang > 1)
2421 2633
 		{
2422 2634
 			$fieldposition = 'rang';
2423
-			if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
2635
+			if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) {
2636
+			    $fieldposition = 'position';
2637
+			}
2424 2638
 
2425 2639
 			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang ;
2426 2640
 			$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
@@ -2433,8 +2647,7 @@  discard block
 block discarded – undo
2433 2647
 				{
2434 2648
 					dol_print_error($this->db);
2435 2649
 				}
2436
-			}
2437
-			else
2650
+			} else
2438 2651
 			{
2439 2652
 				dol_print_error($this->db);
2440 2653
 			}
@@ -2454,7 +2667,9 @@  discard block
 block discarded – undo
2454 2667
 		if ($rang < $max)
2455 2668
 		{
2456 2669
 			$fieldposition = 'rang';
2457
-			if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
2670
+			if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) {
2671
+			    $fieldposition = 'position';
2672
+			}
2458 2673
 
2459 2674
 			$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang;
2460 2675
 			$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
@@ -2467,8 +2682,7 @@  discard block
 block discarded – undo
2467 2682
 				{
2468 2683
 					dol_print_error($this->db);
2469 2684
 				}
2470
-			}
2471
-			else
2685
+			} else
2472 2686
 			{
2473 2687
 				dol_print_error($this->db);
2474 2688
 			}
@@ -2539,8 +2753,7 @@  discard block
 block discarded – undo
2539 2753
 				if (! empty($row[0]))
2540 2754
 				{
2541 2755
 					return $row[0];
2542
-				}
2543
-				else
2756
+				} else
2544 2757
 				{
2545 2758
 					return $this->getRangOfLine($fk_parent_line);
2546 2759
 				}
@@ -2587,8 +2800,7 @@  discard block
 block discarded – undo
2587 2800
 		{
2588 2801
 			$this->ref_ext = $ref_ext;
2589 2802
 			return 1;
2590
-		}
2591
-		else
2803
+		} else
2592 2804
 		{
2593 2805
 			$this->error=$this->db->error();
2594 2806
 			return -1;
@@ -2622,7 +2834,9 @@  discard block
 block discarded – undo
2622 2834
 		}
2623 2835
 		// Special cas
2624 2836
 		//var_dump($this->table_element);exit;
2625
-		if ($this->table_element == 'product') $suffix='';
2837
+		if ($this->table_element == 'product') {
2838
+		    $suffix='';
2839
+		}
2626 2840
 
2627 2841
 		$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2628 2842
 		$sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL");
@@ -2632,16 +2846,17 @@  discard block
 block discarded – undo
2632 2846
 		dol_syslog(get_class($this)."::update_note", LOG_DEBUG);
2633 2847
 		if ($this->db->query($sql))
2634 2848
 		{
2635
-			if ($suffix == '_public') $this->note_public = $note;
2636
-			else if ($suffix == '_private') $this->note_private = $note;
2637
-			else
2849
+			if ($suffix == '_public') {
2850
+			    $this->note_public = $note;
2851
+			} else if ($suffix == '_private') {
2852
+			    $this->note_private = $note;
2853
+			} else
2638 2854
 			{
2639 2855
 				$this->note = $note;      // deprecated
2640 2856
 				$this->note_private = $note;
2641 2857
 			}
2642 2858
 			return 1;
2643
-		}
2644
-		else
2859
+		} else
2645 2860
 		{
2646 2861
 			$this->error=$this->db->lasterror();
2647 2862
 			return -1;
@@ -2681,36 +2896,45 @@  discard block
 block discarded – undo
2681 2896
 
2682 2897
 		// Some external module want no update price after a trigger because they have another method to calculate the total (ex: with an extrafield)
2683 2898
 		$MODULE = "";
2684
-		if ($this->element == 'propal')
2685
-			$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL";
2686
-		elseif ($this->element == 'order')
2687
-			$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER";
2688
-		elseif ($this->element == 'facture')
2689
-			$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE";
2690
-		elseif ($this->element == 'facture_fourn')
2691
-			$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE";
2692
-		elseif ($this->element == 'order_supplier')
2693
-			$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER";
2694
-		elseif ($this->element == 'supplier_proposal')
2695
-			$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL";
2899
+		if ($this->element == 'propal') {
2900
+					$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL";
2901
+		} elseif ($this->element == 'order') {
2902
+					$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER";
2903
+		} elseif ($this->element == 'facture') {
2904
+					$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE";
2905
+		} elseif ($this->element == 'facture_fourn') {
2906
+					$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE";
2907
+		} elseif ($this->element == 'order_supplier') {
2908
+					$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER";
2909
+		} elseif ($this->element == 'supplier_proposal') {
2910
+					$MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL";
2911
+		}
2696 2912
 
2697 2913
 		if (! empty($MODULE)) {
2698 2914
 			if (! empty($conf->global->$MODULE)) {
2699 2915
 				$modsactivated = explode(',', $conf->global->$MODULE);
2700 2916
 				foreach ($modsactivated as $mod) {
2701
-					if ($conf->$mod->enabled)
2702
-						return 1; // update was disabled by specific setup
2917
+					if ($conf->$mod->enabled) {
2918
+											return 1;
2919
+					}
2920
+					// update was disabled by specific setup
2703 2921
 				}
2704 2922
 			}
2705 2923
 		}
2706 2924
 
2707 2925
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
2708 2926
 
2709
-		if ($roundingadjust == '-1') $roundingadjust='auto';	// For backward compatibility
2927
+		if ($roundingadjust == '-1') {
2928
+		    $roundingadjust='auto';
2929
+		}
2930
+		// For backward compatibility
2710 2931
 
2711 2932
 		$forcedroundingmode=$roundingadjust;
2712
-		if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode=$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND;
2713
-		elseif ($forcedroundingmode == 'auto') $forcedroundingmode='0';
2933
+		if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) {
2934
+		    $forcedroundingmode=$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND;
2935
+		} elseif ($forcedroundingmode == 'auto') {
2936
+		    $forcedroundingmode='0';
2937
+		}
2714 2938
 
2715 2939
 		$error=0;
2716 2940
 
@@ -2733,15 +2957,22 @@  discard block
 block discarded – undo
2733 2957
 
2734 2958
 		$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,';
2735 2959
 		$sql.= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type';
2736
-			if ($this->table_element_line == 'facturedet') $sql.= ', situation_percent';
2960
+			if ($this->table_element_line == 'facturedet') {
2961
+			    $sql.= ', situation_percent';
2962
+			}
2737 2963
 			$sql.= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
2738 2964
 		$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line;
2739 2965
 		$sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
2740 2966
 		if ($exclspec)
2741 2967
 		{
2742 2968
 			$product_field='product_type';
2743
-			if ($this->table_element_line == 'contratdet') $product_field='';    // contratdet table has no product_type field
2744
-			if ($product_field) $sql.= ' AND '.$product_field.' <> 9';
2969
+			if ($this->table_element_line == 'contratdet') {
2970
+			    $product_field='';
2971
+			}
2972
+			// contratdet table has no product_type field
2973
+			if ($product_field) {
2974
+			    $sql.= ' AND '.$product_field.' <> 9';
2975
+			}
2745 2976
 		}
2746 2977
 		$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
2747 2978
 
@@ -2771,9 +3002,11 @@  discard block
 block discarded – undo
2771 3002
 				$parameters=array('fk_element' => $obj->rowid);
2772 3003
 				$reshook = $hookmanager->executeHooks('changeRoundingMode', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2773 3004
 
2774
-				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'
3005
+				if (empty($reshook) && $forcedroundingmode == '0') {
3006
+				    // Check if data on line are consistent. This may solve lines that were not consistent because set with $forcedroundingmode='auto'
2775 3007
 				{
2776 3008
 					$localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx);
3009
+				}
2777 3010
 					$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);
2778 3011
 					$diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1);
2779 3012
 					if ($diff)
@@ -2781,7 +3014,9 @@  discard block
 block discarded – undo
2781 3014
 						$sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid;
2782 3015
 						dol_syslog('We found unconsistent data into detailed line (difference of '.$diff.') 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);
2783 3016
 								$resqlfix=$this->db->query($sqlfix);
2784
-								if (! $resqlfix) dol_print_error($this->db,'Failed to update line');
3017
+								if (! $resqlfix) {
3018
+								    dol_print_error($this->db,'Failed to update line');
3019
+								}
2785 3020
 								$obj->total_tva = $tmpcal[1];
2786 3021
 								$obj->total_ttc = $tmpcal[2];
2787 3022
 						//
@@ -2797,16 +3032,24 @@  discard block
 block discarded – undo
2797 3032
 				$this->multicurrency_total_tva       += $obj->multicurrency_total_tva;
2798 3033
 				$this->multicurrency_total_ttc       += $obj->multicurrency_total_ttc;
2799 3034
 
2800
-				if (! isset($total_ht_by_vats[$obj->vatrate]))  $total_ht_by_vats[$obj->vatrate]=0;
2801
-				if (! isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate]=0;
2802
-				if (! isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate]=0;
3035
+				if (! isset($total_ht_by_vats[$obj->vatrate])) {
3036
+				    $total_ht_by_vats[$obj->vatrate]=0;
3037
+				}
3038
+				if (! isset($total_tva_by_vats[$obj->vatrate])) {
3039
+				    $total_tva_by_vats[$obj->vatrate]=0;
3040
+				}
3041
+				if (! isset($total_ttc_by_vats[$obj->vatrate])) {
3042
+				    $total_ttc_by_vats[$obj->vatrate]=0;
3043
+				}
2803 3044
 				$total_ht_by_vats[$obj->vatrate]  += $obj->total_ht;
2804 3045
 				$total_tva_by_vats[$obj->vatrate] += $obj->total_tva;
2805 3046
 				$total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc;
2806 3047
 
2807
-				if ($forcedroundingmode == '1')	// Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency
3048
+				if ($forcedroundingmode == '1') {
3049
+				    // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency
2808 3050
 				{
2809 3051
 					$tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1);
3052
+				}
2810 3053
 					$diff=price2num($total_tva_by_vats[$obj->vatrate]-$tmpvat, 'MT', 1);
2811 3054
 					//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";
2812 3055
 					if ($diff)
@@ -2815,7 +3058,9 @@  discard block
 block discarded – undo
2815 3058
 						$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;
2816 3059
 						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);
2817 3060
 								$resqlfix=$this->db->query($sqlfix);
2818
-								if (! $resqlfix) dol_print_error($this->db,'Failed to update line');
3061
+								if (! $resqlfix) {
3062
+								    dol_print_error($this->db,'Failed to update line');
3063
+								}
2819 3064
 								$this->total_tva -= $diff;
2820 3065
 								$this->total_ttc -= $diff;
2821 3066
 								$total_tva_by_vats[$obj->vatrate] -= $diff;
@@ -2856,11 +3101,21 @@  discard block
 block discarded – undo
2856 3101
 			$fieldlocaltax2='localtax2';
2857 3102
 			$fieldttc='total_ttc';
2858 3103
 			// Specific code for backward compatibility with old field names
2859
-			if ($this->element == 'facture' || $this->element == 'facturerec')             $fieldht='total';
2860
-			if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva='total_tva';
2861
-			if ($this->element == 'propal')                                                $fieldttc='total';
2862
-			if ($this->element == 'expensereport')                                         $fieldtva='total_tva';
2863
-			if ($this->element == 'supplier_proposal')                                     $fieldttc='total';
3104
+			if ($this->element == 'facture' || $this->element == 'facturerec') {
3105
+			    $fieldht='total';
3106
+			}
3107
+			if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') {
3108
+			    $fieldtva='total_tva';
3109
+			}
3110
+			if ($this->element == 'propal') {
3111
+			    $fieldttc='total';
3112
+			}
3113
+			if ($this->element == 'expensereport') {
3114
+			    $fieldtva='total_tva';
3115
+			}
3116
+			if ($this->element == 'supplier_proposal') {
3117
+			    $fieldttc='total';
3118
+			}
2864 3119
 
2865 3120
 			if (empty($nodatabaseupdate))
2866 3121
 			{
@@ -2889,13 +3144,11 @@  discard block
 block discarded – undo
2889 3144
 			if (! $error)
2890 3145
 			{
2891 3146
 				return 1;
2892
-			}
2893
-			else
3147
+			} else
2894 3148
 			{
2895 3149
 				return -1;
2896 3150
 			}
2897
-		}
2898
-		else
3151
+		} else
2899 3152
 		{
2900 3153
 			dol_print_error($this->db,'Bad request in update_price');
2901 3154
 			return -1;
@@ -2918,10 +3171,18 @@  discard block
 block discarded – undo
2918 3171
 		$origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id);
2919 3172
 
2920 3173
 		// Special case
2921
-		if ($origin == 'order') $origin='commande';
2922
-		if ($origin == 'invoice') $origin='facture';
2923
-		if ($origin == 'invoice_template') $origin='facturerec';
2924
-    	if ($origin == 'supplierorder') $origin='order_supplier';
3174
+		if ($origin == 'order') {
3175
+		    $origin='commande';
3176
+		}
3177
+		if ($origin == 'invoice') {
3178
+		    $origin='facture';
3179
+		}
3180
+		if ($origin == 'invoice_template') {
3181
+		    $origin='facturerec';
3182
+		}
3183
+    	if ($origin == 'supplierorder') {
3184
+    	    $origin='order_supplier';
3185
+    	}
2925 3186
 		$this->db->begin();
2926 3187
 
2927 3188
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
@@ -2941,8 +3202,7 @@  discard block
 block discarded – undo
2941 3202
 	  	{
2942 3203
 	  		$this->db->commit();
2943 3204
 	  		return 1;
2944
-	  	}
2945
-	  	else
3205
+	  	} else
2946 3206
 	  	{
2947 3207
 	  		$this->error=$this->db->lasterror();
2948 3208
 	  		$this->db->rollback();
@@ -2987,12 +3247,16 @@  discard block
 block discarded – undo
2987 3247
 		if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid))
2988 3248
 		{
2989 3249
 			$justsource=true;  // the source (id and type) is a search criteria
2990
-			if (! empty($targettype)) $withtargettype=true;
3250
+			if (! empty($targettype)) {
3251
+			    $withtargettype=true;
3252
+			}
2991 3253
 		}
2992 3254
 		if (! empty($targetid) && ! empty($targettype) && empty($sourceid))
2993 3255
 		{
2994 3256
 			$justtarget=true;  // the target (id and type) is a search criteria
2995
-			if (! empty($sourcetype)) $withsourcetype=true;
3257
+			if (! empty($sourcetype)) {
3258
+			    $withsourcetype=true;
3259
+			}
2996 3260
 		}
2997 3261
 
2998 3262
 		$sourceid = (! empty($sourceid) ? $sourceid : $this->id);
@@ -3015,15 +3279,17 @@  discard block
 block discarded – undo
3015 3279
 			if ($justsource)
3016 3280
 			{
3017 3281
 				$sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'";
3018
-				if ($withtargettype) $sql.= " AND targettype = '".$targettype."'";
3019
-			}
3020
-			else if ($justtarget)
3282
+				if ($withtargettype) {
3283
+				    $sql.= " AND targettype = '".$targettype."'";
3284
+				}
3285
+			} else if ($justtarget)
3021 3286
 			{
3022 3287
 				$sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'";
3023
-				if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'";
3288
+				if ($withsourcetype) {
3289
+				    $sql.= " AND sourcetype = '".$sourcetype."'";
3290
+				}
3024 3291
 			}
3025
-		}
3026
-		else
3292
+		} else
3027 3293
 		{
3028 3294
 			$sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')";
3029 3295
 			$sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')";
@@ -3044,13 +3310,11 @@  discard block
 block discarded – undo
3044 3310
 					if ($justsource)
3045 3311
 					{
3046 3312
 						$this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target;
3047
-					}
3048
-					else if ($justtarget)
3313
+					} else if ($justtarget)
3049 3314
 					{
3050 3315
 						$this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source;
3051 3316
 					}
3052
-				}
3053
-				else
3317
+				} else
3054 3318
 				{
3055 3319
 					if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype)
3056 3320
 					{
@@ -3067,10 +3331,12 @@  discard block
 block discarded – undo
3067 3331
 			if (! empty($this->linkedObjectsIds))
3068 3332
 			{
3069 3333
 				$tmparray = $this->linkedObjectsIds;
3070
-				foreach($tmparray as $objecttype => $objectids)       // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...)
3334
+				foreach($tmparray as $objecttype => $objectids) {
3335
+				    // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...)
3071 3336
 				{
3072 3337
 					// Parse element/subelement (ex: project_task, cabinetmed_consultation, ...)
3073 3338
 					$module = $element = $subelement = $objecttype;
3339
+				}
3074 3340
 					if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier'
3075 3341
 						&& preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
3076 3342
 					{
@@ -3082,29 +3348,21 @@  discard block
 block discarded – undo
3082 3348
 					// To work with non standard classpath or module name
3083 3349
 					if ($objecttype == 'facture')			{
3084 3350
 						$classpath = 'compta/facture/class';
3085
-					}
3086
-					else if ($objecttype == 'facturerec')			{
3351
+					} else if ($objecttype == 'facturerec')			{
3087 3352
 						$classpath = 'compta/facture/class'; $module = 'facture';
3088
-					}
3089
-					else if ($objecttype == 'propal')			{
3353
+					} else if ($objecttype == 'propal')			{
3090 3354
 						$classpath = 'comm/propal/class';
3091
-					}
3092
-					else if ($objecttype == 'supplier_proposal')			{
3355
+					} else if ($objecttype == 'supplier_proposal')			{
3093 3356
 						$classpath = 'supplier_proposal/class';
3094
-					}
3095
-					else if ($objecttype == 'shipping')			{
3357
+					} else if ($objecttype == 'shipping')			{
3096 3358
 						$classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon';
3097
-					}
3098
-					else if ($objecttype == 'delivery')			{
3359
+					} else if ($objecttype == 'delivery')			{
3099 3360
 						$classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon';
3100
-					}
3101
-					else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier')	{
3361
+					} else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier')	{
3102 3362
 						$classpath = 'fourn/class'; $module = 'fournisseur';
3103
-					}
3104
-					else if ($objecttype == 'fichinter')			{
3363
+					} else if ($objecttype == 'fichinter')			{
3105 3364
 						$classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter';
3106
-					}
3107
-					else if ($objecttype == 'subscription')			{
3365
+					} else if ($objecttype == 'subscription')			{
3108 3366
 						$classpath = 'adherents/class'; $module = 'adherent';
3109 3367
 					}
3110 3368
 
@@ -3113,20 +3371,15 @@  discard block
 block discarded – undo
3113 3371
 
3114 3372
 					if ($objecttype == 'order') {
3115 3373
 						$classfile = 'commande'; $classname = 'Commande';
3116
-					}
3117
-					else if ($objecttype == 'invoice_supplier') {
3374
+					} else if ($objecttype == 'invoice_supplier') {
3118 3375
 						$classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur';
3119
-					}
3120
-					else if ($objecttype == 'order_supplier')   {
3376
+					} else if ($objecttype == 'order_supplier')   {
3121 3377
 						$classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur';
3122
-					}
3123
-					else if ($objecttype == 'supplier_proposal')   {
3378
+					} else if ($objecttype == 'supplier_proposal')   {
3124 3379
 						$classfile = 'supplier_proposal'; $classname = 'SupplierProposal';
3125
-					}
3126
-					else if ($objecttype == 'facturerec')   {
3380
+					} else if ($objecttype == 'facturerec')   {
3127 3381
 						$classfile = 'facture-rec'; $classname = 'FactureRec';
3128
-					}
3129
-					else if ($objecttype == 'subscription')   {
3382
+					} else if ($objecttype == 'subscription')   {
3130 3383
 						$classfile = 'subscription'; $classname = 'Subscription';
3131 3384
 					}
3132 3385
 
@@ -3139,9 +3392,11 @@  discard block
 block discarded – undo
3139 3392
 							//print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname);
3140 3393
 							if (class_exists($classname))
3141 3394
 							{
3142
-								foreach($objectids as $i => $objectid)	// $i is rowid into llx_element_element
3395
+								foreach($objectids as $i => $objectid) {
3396
+								    // $i is rowid into llx_element_element
3143 3397
 								{
3144 3398
 									$object = new $classname($this->db);
3399
+								}
3145 3400
 									$ret = $object->fetch($objectid);
3146 3401
 									if ($ret >= 0)
3147 3402
 									{
@@ -3150,16 +3405,14 @@  discard block
 block discarded – undo
3150 3405
 								}
3151 3406
 							}
3152 3407
 						}
3153
-					}
3154
-					else
3408
+					} else
3155 3409
 					{
3156 3410
 						unset($this->linkedObjectsIds[$objecttype]);
3157 3411
 					}
3158 3412
 				}
3159 3413
 			}
3160 3414
 			return 1;
3161
-		}
3162
-		else
3415
+		} else
3163 3416
 		{
3164 3417
 			dol_print_error($this->db);
3165 3418
 			return -1;
@@ -3181,8 +3434,11 @@  discard block
 block discarded – undo
3181 3434
 		$updatesource=false;
3182 3435
 		$updatetarget=false;
3183 3436
 
3184
-		if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource=true;
3185
-		else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $updatetarget=true;
3437
+		if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) {
3438
+		    $updatesource=true;
3439
+		} else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) {
3440
+		    $updatetarget=true;
3441
+		}
3186 3442
 
3187 3443
 		$sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET ";
3188 3444
 		if ($updatesource)
@@ -3191,8 +3447,7 @@  discard block
 block discarded – undo
3191 3447
 			$sql.= ", sourcetype = '".$this->db->escape($sourcetype)."'";
3192 3448
 			$sql.= " WHERE fk_target = ".$this->id;
3193 3449
 			$sql.= " AND targettype = '".$this->db->escape($this->element)."'";
3194
-		}
3195
-		else if ($updatetarget)
3450
+		} else if ($updatetarget)
3196 3451
 		{
3197 3452
 			$sql.= "fk_target = ".$targetid;
3198 3453
 			$sql.= ", targettype = '".$this->db->escape($targettype)."'";
@@ -3204,8 +3459,7 @@  discard block
 block discarded – undo
3204 3459
 		if ($this->db->query($sql))
3205 3460
 		{
3206 3461
 			return 1;
3207
-		}
3208
-		else
3462
+		} else
3209 3463
 		{
3210 3464
 			$this->error=$this->db->lasterror();
3211 3465
 			return -1;
@@ -3228,8 +3482,11 @@  discard block
 block discarded – undo
3228 3482
 		$deletesource=false;
3229 3483
 		$deletetarget=false;
3230 3484
 
3231
-		if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource=true;
3232
-		else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $deletetarget=true;
3485
+		if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) {
3486
+		    $deletesource=true;
3487
+		} else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) {
3488
+		    $deletetarget=true;
3489
+		}
3233 3490
 
3234 3491
 		$sourceid = (! empty($sourceid) ? $sourceid : $this->id);
3235 3492
 		$sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element);
@@ -3241,20 +3498,17 @@  discard block
 block discarded – undo
3241 3498
 		if ($rowid > 0)
3242 3499
 		{
3243 3500
 			$sql.=" rowid = ".$rowid;
3244
-		}
3245
-		else
3501
+		} else
3246 3502
 		{
3247 3503
 			if ($deletesource)
3248 3504
 			{
3249 3505
 				$sql.= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'";
3250 3506
 				$sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'";
3251
-			}
3252
-			else if ($deletetarget)
3507
+			} else if ($deletetarget)
3253 3508
 			{
3254 3509
 				$sql.= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'";
3255 3510
 				$sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'";
3256
-			}
3257
-			else
3511
+			} else
3258 3512
 			{
3259 3513
 				$sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')";
3260 3514
 				$sql.= " OR";
@@ -3266,8 +3520,7 @@  discard block
 block discarded – undo
3266 3520
 		if ($this->db->query($sql))
3267 3521
 		{
3268 3522
 			return 1;
3269
-		}
3270
-		else
3523
+		} else
3271 3524
 		{
3272 3525
 			$this->error=$this->db->lasterror();
3273 3526
 			$this->errors[]=$this->error;
@@ -3296,17 +3549,31 @@  discard block
 block discarded – undo
3296 3549
 		$this->db->begin();
3297 3550
 
3298 3551
 		$fieldstatus="fk_statut";
3299
-		if ($elementTable == 'facture_rec') $fieldstatus="suspended";
3300
-		if ($elementTable == 'mailing') $fieldstatus="statut";
3301
-		if ($elementTable == 'cronjob') $fieldstatus="status";
3302
-		if ($elementTable == 'user') $fieldstatus="statut";
3303
-		if ($elementTable == 'expensereport') $fieldstatus="fk_statut";
3304
-		if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus="status";
3552
+		if ($elementTable == 'facture_rec') {
3553
+		    $fieldstatus="suspended";
3554
+		}
3555
+		if ($elementTable == 'mailing') {
3556
+		    $fieldstatus="statut";
3557
+		}
3558
+		if ($elementTable == 'cronjob') {
3559
+		    $fieldstatus="status";
3560
+		}
3561
+		if ($elementTable == 'user') {
3562
+		    $fieldstatus="statut";
3563
+		}
3564
+		if ($elementTable == 'expensereport') {
3565
+		    $fieldstatus="fk_statut";
3566
+		}
3567
+		if ($elementTable == 'commande_fournisseur_dispatch') {
3568
+		    $fieldstatus="status";
3569
+		}
3305 3570
 
3306 3571
 		$sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable;
3307 3572
 		$sql.= " SET ".$fieldstatus." = ".$status;
3308 3573
 		// If status = 1 = validated, update also fk_user_valid
3309
-		if ($status == 1 && $elementTable == 'expensereport') $sql.=", fk_user_valid = ".$user->id;
3574
+		if ($status == 1 && $elementTable == 'expensereport') {
3575
+		    $sql.=", fk_user_valid = ".$user->id;
3576
+		}
3310 3577
 		$sql.= " WHERE rowid=".$elementId;
3311 3578
 
3312 3579
 		dol_syslog(get_class($this)."::setStatut", LOG_DEBUG);
@@ -3317,12 +3584,27 @@  discard block
 block discarded – undo
3317 3584
 			// Try autoset of trigkey
3318 3585
 			if (empty($trigkey))
3319 3586
 			{
3320
-				if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_SIGN';   // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class
3321
-				if ($this->element == 'supplier_proposal' && $status == 3) $trigkey='SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class
3322
-				if ($this->element == 'supplier_proposal' && $status == 4) $trigkey='SUPPLIER_PROPOSAL_CLOSE';  // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class
3323
-				if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE';
3324
-				if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED';
3325
-				if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED';
3587
+				if ($this->element == 'supplier_proposal' && $status == 2) {
3588
+				    $trigkey='SUPPLIER_PROPOSAL_SIGN';
3589
+				}
3590
+				// 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class
3591
+				if ($this->element == 'supplier_proposal' && $status == 3) {
3592
+				    $trigkey='SUPPLIER_PROPOSAL_REFUSE';
3593
+				}
3594
+				// 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class
3595
+				if ($this->element == 'supplier_proposal' && $status == 4) {
3596
+				    $trigkey='SUPPLIER_PROPOSAL_CLOSE';
3597
+				}
3598
+				// 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class
3599
+				if ($this->element == 'fichinter' && $status == 3) {
3600
+				    $trigkey='FICHINTER_CLASSIFY_DONE';
3601
+				}
3602
+				if ($this->element == 'fichinter' && $status == 2) {
3603
+				    $trigkey='FICHINTER_CLASSIFY_BILLED';
3604
+				}
3605
+				if ($this->element == 'fichinter' && $status == 1) {
3606
+				    $trigkey='FICHINTER_CLASSIFY_UNBILLED';
3607
+				}
3326 3608
 			}
3327 3609
 
3328 3610
 			if ($trigkey)
@@ -3341,22 +3623,22 @@  discard block
 block discarded – undo
3341 3623
 			{
3342 3624
 				$this->db->commit();
3343 3625
 
3344
-				if (empty($savElementId))    // If the element we update was $this (so $elementId is null)
3626
+				if (empty($savElementId)) {
3627
+				    // If the element we update was $this (so $elementId is null)
3345 3628
 				{
3346 3629
 					$this->statut = $status;
3630
+				}
3347 3631
 					$this->status = $status;
3348 3632
 				}
3349 3633
 
3350 3634
 				return 1;
3351
-			}
3352
-			else
3635
+			} else
3353 3636
 			{
3354 3637
 				$this->db->rollback();
3355 3638
 				dol_syslog(get_class($this)."::setStatus ".$this->error,LOG_ERR);
3356 3639
 				return -1;
3357 3640
 			}
3358
-		}
3359
-		else
3641
+		} else
3360 3642
 		{
3361 3643
 			$this->error=$this->db->lasterror();
3362 3644
 			$this->db->rollback();
@@ -3376,8 +3658,13 @@  discard block
 block discarded – undo
3376 3658
 	{
3377 3659
 		global $conf;
3378 3660
 
3379
-		if (empty($id) && empty($ref)) return 0;
3380
-		if (! empty($conf->global->MAIN_DISABLE_CANVAS)) return 0;    // To increase speed. Not enabled by default.
3661
+		if (empty($id) && empty($ref)) {
3662
+		    return 0;
3663
+		}
3664
+		if (! empty($conf->global->MAIN_DISABLE_CANVAS)) {
3665
+		    return 0;
3666
+		}
3667
+		// To increase speed. Not enabled by default.
3381 3668
 
3382 3669
 		// Clean parameters
3383 3670
 		$ref = trim($ref);
@@ -3385,8 +3672,12 @@  discard block
 block discarded – undo
3385 3672
 		$sql = "SELECT rowid, canvas";
3386 3673
 		$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element;
3387 3674
 		$sql.= " WHERE entity IN (".getEntity($this->element).")";
3388
-		if (! empty($id))  $sql.= " AND rowid = ".$id;
3389
-		if (! empty($ref)) $sql.= " AND ref = '".$this->db->escape($ref)."'";
3675
+		if (! empty($id)) {
3676
+		    $sql.= " AND rowid = ".$id;
3677
+		}
3678
+		if (! empty($ref)) {
3679
+		    $sql.= " AND ref = '".$this->db->escape($ref)."'";
3680
+		}
3390 3681
 
3391 3682
 		$resql = $this->db->query($sql);
3392 3683
 		if ($resql)
@@ -3396,10 +3687,10 @@  discard block
 block discarded – undo
3396 3687
 			{
3397 3688
 				$this->canvas   = $obj->canvas;
3398 3689
 				return 1;
3690
+			} else {
3691
+			    return 0;
3399 3692
 			}
3400
-			else return 0;
3401
-		}
3402
-		else
3693
+		} else
3403 3694
 		{
3404 3695
 			dol_print_error($this->db);
3405 3696
 			return -1;
@@ -3436,7 +3727,9 @@  discard block
 block discarded – undo
3436 3727
 	{
3437 3728
 		global $langs;
3438 3729
 
3439
-		if (empty($id)) $id=$this->id;
3730
+		if (empty($id)) {
3731
+		    $id=$this->id;
3732
+		}
3440 3733
 
3441 3734
 		// Check parameters
3442 3735
 		if (! isset($this->childtables) || ! is_array($this->childtables) || count($this->childtables) == 0)
@@ -3470,18 +3763,18 @@  discard block
 block discarded – undo
3470 3763
 					$langs->load("errors");
3471 3764
 					//print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild;
3472 3765
 					$haschild += $obj->nb;
3473
-					if (is_numeric($elementname))	// old usage
3766
+					if (is_numeric($elementname)) {
3767
+					    // old usage
3474 3768
 					{
3475 3769
 						$this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table);
3476 3770
 					}
3477
-					else	// new usage: $elementname=Translation key
3771
+					} else	// new usage: $elementname=Translation key
3478 3772
 					{
3479 3773
 						$this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname));
3480 3774
 					}
3481 3775
 					break;    // We found at least one, we stop here
3482 3776
 				}
3483
-			}
3484
-			else
3777
+			} else
3485 3778
 			{
3486 3779
 				$this->errors[]=$this->db->lasterror();
3487 3780
 				return -1;
@@ -3491,8 +3784,9 @@  discard block
 block discarded – undo
3491 3784
 		{
3492 3785
 			$this->errors[]="ErrorRecordHasChildren";
3493 3786
 			return $haschild;
3787
+		} else {
3788
+		    return 0;
3494 3789
 		}
3495
-		else return 0;
3496 3790
 	}
3497 3791
 
3498 3792
 	/**
@@ -3508,12 +3802,24 @@  discard block
 block discarded – undo
3508 3802
 		foreach($this->lines as $key => $val)
3509 3803
 		{
3510 3804
 			$qualified=0;
3511
-			if ($predefined == -1) $qualified=1;
3512
-			if ($predefined == 1 && $val->fk_product > 0) $qualified=1;
3513
-			if ($predefined == 0 && $val->fk_product <= 0) $qualified=1;
3514
-			if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) $qualified=1;
3515
-			if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) $qualified=1;
3516
-			if ($qualified) $nb++;
3805
+			if ($predefined == -1) {
3806
+			    $qualified=1;
3807
+			}
3808
+			if ($predefined == 1 && $val->fk_product > 0) {
3809
+			    $qualified=1;
3810
+			}
3811
+			if ($predefined == 0 && $val->fk_product <= 0) {
3812
+			    $qualified=1;
3813
+			}
3814
+			if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) {
3815
+			    $qualified=1;
3816
+			}
3817
+			if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) {
3818
+			    $qualified=1;
3819
+			}
3820
+			if ($qualified) {
3821
+			    $nb++;
3822
+			}
3517 3823
 		}
3518 3824
 		dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies');
3519 3825
 		return $nb;
@@ -3577,16 +3883,24 @@  discard block
 block discarded – undo
3577 3883
 		{
3578 3884
 			if (isset($line->qty_asked))
3579 3885
 			{
3580
-				if (empty($totalOrdered)) $totalOrdered=0;  // Avoid warning because $totalOrdered is ''
3886
+				if (empty($totalOrdered)) {
3887
+				    $totalOrdered=0;
3888
+				}
3889
+				// Avoid warning because $totalOrdered is ''
3581 3890
 				$totalOrdered+=$line->qty_asked;    // defined for shipment only
3582 3891
 			}
3583 3892
 			if (isset($line->qty_shipped))
3584 3893
 			{
3585
-				if (empty($totalToShip)) $totalToShip=0;    // Avoid warning because $totalToShip is ''
3894
+				if (empty($totalToShip)) {
3895
+				    $totalToShip=0;
3896
+				}
3897
+				// Avoid warning because $totalToShip is ''
3586 3898
 				$totalToShip+=$line->qty_shipped;   // defined for shipment only
3587
-            }else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty))
3899
+            } else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty))
3588 3900
             {
3589
-                if (empty($totalToShip)) $totalToShip=0;
3901
+                if (empty($totalToShip)) {
3902
+                    $totalToShip=0;
3903
+                }
3590 3904
                 $totalToShip+=$line->qty;   // defined for reception only
3591 3905
 			}
3592 3906
 
@@ -3594,8 +3908,7 @@  discard block
 block discarded – undo
3594 3908
 			if ($this->element == 'shipping') {
3595 3909
 				// for shipments
3596 3910
 				$qty = $line->qty_shipped ? $line->qty_shipped : 0;
3597
-			}
3598
-			else {
3911
+			} else {
3599 3912
 				$qty = $line->qty ? $line->qty : 0;
3600 3913
 			}
3601 3914
 
@@ -3611,19 +3924,30 @@  discard block
 block discarded – undo
3611 3924
 
3612 3925
 			$weightUnit=0;
3613 3926
 			$volumeUnit=0;
3614
-			if (! empty($weight_units)) $weightUnit = $weight_units;
3615
-			if (! empty($volume_units)) $volumeUnit = $volume_units;
3927
+			if (! empty($weight_units)) {
3928
+			    $weightUnit = $weight_units;
3929
+			}
3930
+			if (! empty($volume_units)) {
3931
+			    $volumeUnit = $volume_units;
3932
+			}
3616 3933
 
3617
-			if (empty($totalWeight)) $totalWeight=0;  // Avoid warning because $totalWeight is ''
3618
-			if (empty($totalVolume)) $totalVolume=0;  // Avoid warning because $totalVolume is ''
3934
+			if (empty($totalWeight)) {
3935
+			    $totalWeight=0;
3936
+			}
3937
+			// Avoid warning because $totalWeight is ''
3938
+			if (empty($totalVolume)) {
3939
+			    $totalVolume=0;
3940
+			}
3941
+			// Avoid warning because $totalVolume is ''
3619 3942
 
3620 3943
 			//var_dump($line->volume_units);
3621
-			if ($weight_units < 50)   // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch)
3944
+			if ($weight_units < 50) {
3945
+			    // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch)
3622 3946
 			{
3623 3947
 				$trueWeightUnit=pow(10, $weightUnit);
3624
-				$totalWeight += $weight * $qty * $trueWeightUnit;
3625 3948
 			}
3626
-			else {
3949
+				$totalWeight += $weight * $qty * $trueWeightUnit;
3950
+			} else {
3627 3951
 		if ($weight_units == 99) {
3628 3952
 			// conversion 1 Pound = 0.45359237 KG
3629 3953
 			$trueWeightUnit = 0.45359237;
@@ -3632,18 +3956,20 @@  discard block
 block discarded – undo
3632 3956
 			// conversion 1 Ounce = 0.0283495 KG
3633 3957
 			$trueWeightUnit = 0.0283495;
3634 3958
 			$totalWeight += $weight * $qty * $trueWeightUnit;
3959
+		} else {
3960
+							$totalWeight += $weight * $qty;
3635 3961
 		}
3636
-		else
3637
-					$totalWeight += $weight * $qty;   // This may be wrong if we mix different units
3962
+		// This may be wrong if we mix different units
3638 3963
 			}
3639
-			if ($volume_units < 50)   // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch)
3964
+			if ($volume_units < 50) {
3965
+			    // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch)
3640 3966
 			{
3641 3967
 				//print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit;
3642 3968
 				$trueVolumeUnit=pow(10, $volumeUnit);
3969
+			}
3643 3970
 				//print $line->volume;
3644 3971
 				$totalVolume += $volume * $qty * $trueVolumeUnit;
3645
-			}
3646
-			else
3972
+			} else
3647 3973
 			{
3648 3974
 				$totalVolume += $volume * $qty;   // This may be wrong if we mix different units
3649 3975
 			}
@@ -3675,8 +4001,7 @@  discard block
 block discarded – undo
3675 4001
 			$this->error=$this->db->lasterror();
3676 4002
 			$this->db->rollback();
3677 4003
 			return -1;
3678
-		}
3679
-		else
4004
+		} else
3680 4005
 		{
3681 4006
 			$this->db->commit();
3682 4007
 			return 1;
@@ -3728,13 +4053,11 @@  discard block
 block discarded – undo
3728 4053
 			{
3729 4054
 				$res = $this->db->fetch_object($resql);
3730 4055
 				return 'Incoterm : '.$res->code.' - '.$this->location_incoterms;
3731
-			}
3732
-			else
4056
+			} else
3733 4057
 			{
3734 4058
 				return '';
3735 4059
 			}
3736
-		}
3737
-		else
4060
+		} else
3738 4061
 		{
3739 4062
 			$this->errors[] = $this->db->lasterror();
3740 4063
 			return false;
@@ -3771,14 +4094,14 @@  discard block
 block discarded – undo
3771 4094
 					$this->libelle_incoterms = $obj->libelle;
3772 4095
 				}
3773 4096
 				return 1;
3774
-			}
3775
-			else
4097
+			} else
3776 4098
 			{
3777 4099
 				$this->errors[] = $this->db->lasterror();
3778 4100
 				return -1;
3779 4101
 			}
4102
+		} else {
4103
+		    return -1;
3780 4104
 		}
3781
-		else return -1;
3782 4105
 	}
3783 4106
 
3784 4107
 
@@ -3817,7 +4140,9 @@  discard block
 block discarded – undo
3817 4140
 			} else {
3818 4141
 				$res=include $tpl; // for debug
3819 4142
 			}
3820
-			if ($res) break;
4143
+			if ($res) {
4144
+			    break;
4145
+			}
3821 4146
 		}
3822 4147
 	}
3823 4148
 
@@ -3847,7 +4172,9 @@  discard block
 block discarded – undo
3847 4172
 
3848 4173
 		// Define usemargins
3849 4174
 		$usemargins=0;
3850
-		if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) $usemargins=1;
4175
+		if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) {
4176
+		    $usemargins=1;
4177
+		}
3851 4178
 
3852 4179
 		$num = count($this->lines);
3853 4180
 
@@ -3866,7 +4193,9 @@  discard block
 block discarded – undo
3866 4193
 			print '<tr class="liste_titre nodrag nodrop">';
3867 4194
 
3868 4195
 			// Adds a line numbering column
3869
-			if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5">&nbsp;</td>';
4196
+			if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
4197
+			    print '<td class="linecolnum" align="center" width="5">&nbsp;</td>';
4198
+			}
3870 4199
 
3871 4200
 			// Description
3872 4201
 			print '<td class="linecoldescription">'.$langs->trans('Description').'</td>';
@@ -3883,9 +4212,13 @@  discard block
 block discarded – undo
3883 4212
 			print '<td class="linecoluht" align="right" width="80">'.$langs->trans('PriceUHT').'</td>';
3884 4213
 
3885 4214
 			// Multicurrency
3886
-			if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoluht_currency" align="right" width="80">'.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).'</td>';
4215
+			if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) {
4216
+			    print '<td class="linecoluht_currency" align="right" width="80">'.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).'</td>';
4217
+			}
3887 4218
 
3888
-			if ($inputalsopricewithtax) print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>';
4219
+			if ($inputalsopricewithtax) {
4220
+			    print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>';
4221
+			}
3889 4222
 
3890 4223
 			// Qty
3891 4224
 			print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>';
@@ -3906,25 +4239,32 @@  discard block
 block discarded – undo
3906 4239
 			{
3907 4240
 				if (!empty($user->rights->margins->creer))
3908 4241
 				{
3909
-					if ($conf->global->MARGIN_TYPE == "1")
3910
-						print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>';
3911
-					else
3912
-						print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>';
4242
+					if ($conf->global->MARGIN_TYPE == "1") {
4243
+											print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>';
4244
+					} else {
4245
+											print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>';
4246
+					}
3913 4247
 				}
3914 4248
 
3915
-				if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous)
3916
-					print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>';
3917
-				if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous)
3918
-					print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>';
4249
+				if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) {
4250
+									print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>';
4251
+				}
4252
+				if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) {
4253
+									print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>';
4254
+				}
3919 4255
 			}
3920 4256
 
3921 4257
 			// Total HT
3922 4258
 			print '<td class="linecolht" align="right">'.$langs->trans('TotalHTShort').'</td>';
3923 4259
 
3924 4260
 			// Multicurrency
3925
-			if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoltotalht_currency" align="right">'.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).'</td>';
4261
+			if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) {
4262
+			    print '<td class="linecoltotalht_currency" align="right">'.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).'</td>';
4263
+			}
3926 4264
 
3927
-			if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>';
4265
+			if ($outputalsopricetotalwithtax) {
4266
+			    print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>';
4267
+			}
3928 4268
 
3929 4269
 			print '<td class="linecoledit"></td>';  // No width to allow autodim
3930 4270
 
@@ -3954,14 +4294,15 @@  discard block
 block discarded – undo
3954 4294
 			$line->fetch_optionals();
3955 4295
 
3956 4296
 			//if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line)))
3957
-			if (is_object($hookmanager))   // Old code is commented on preceding line.
4297
+			if (is_object($hookmanager)) {
4298
+			    // Old code is commented on preceding line.
3958 4299
 			{
3959 4300
 				if (empty($line->fk_parent_line))
3960 4301
 				{
3961 4302
 					$parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
4303
+			}
3962 4304
 					$reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action);    // Note that $action and $object may have been modified by some hooks
3963
-				}
3964
-				else
4305
+				} else
3965 4306
 				{
3966 4307
 					$parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline, 'fk_parent_line'=>$line->fk_parent_line);
3967 4308
 					$reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action);    // Note that $action and $object may have been modified by some hooks
@@ -4008,8 +4349,14 @@  discard block
 block discarded – undo
4008 4349
 		// Show product and description
4009 4350
 		$type=(! empty($line->product_type)?$line->product_type:$line->fk_product_type);
4010 4351
 		// Try to enhance type detection using date_start and date_end for free lines where type was not saved.
4011
-		if (! empty($line->date_start)) $type=1; // deprecated
4012
-		if (! empty($line->date_end)) $type=1; // deprecated
4352
+		if (! empty($line->date_start)) {
4353
+		    $type=1;
4354
+		}
4355
+		// deprecated
4356
+		if (! empty($line->date_end)) {
4357
+		    $type=1;
4358
+		}
4359
+		// deprecated
4013 4360
 
4014 4361
 		// Ligne en mode visu
4015 4362
 		if ($action != 'editline' || $selected != $line->id)
@@ -4038,8 +4385,13 @@  discard block
 block discarded – undo
4038 4385
 
4039 4386
 					$outputlangs = $langs;
4040 4387
 					$newlang='';
4041
-					if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
4042
-					if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang=$this->thirdparty->default_lang;		// For language to language of customer
4388
+					if (empty($newlang) && GETPOST('lang_id','aZ09')) {
4389
+					    $newlang=GETPOST('lang_id','aZ09');
4390
+					}
4391
+					if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) {
4392
+					    $newlang=$this->thirdparty->default_lang;
4393
+					}
4394
+					// For language to language of customer
4043 4395
 					if (! empty($newlang))
4044 4396
 					{
4045 4397
 						$outputlangs = new Translate("",$conf);
@@ -4047,8 +4399,7 @@  discard block
 block discarded – undo
4047 4399
 					}
4048 4400
 
4049 4401
 					$label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label;
4050
-				}
4051
-				else
4402
+				} else
4052 4403
 				{
4053 4404
 					$label = $line->product_label;
4054 4405
 				}
@@ -4070,7 +4421,9 @@  discard block
 block discarded – undo
4070 4421
 				} else {
4071 4422
 					$res=include $tpl; // for debug
4072 4423
 				}
4073
-				if ($res) break;
4424
+				if ($res) {
4425
+				    break;
4426
+				}
4074 4427
 			}
4075 4428
 		}
4076 4429
 
@@ -4093,7 +4446,9 @@  discard block
 block discarded – undo
4093 4446
 				} else {
4094 4447
 					$res=include $tpl; // for debug
4095 4448
 				}
4096
-				if ($res) break;
4449
+				if ($res) {
4450
+				    break;
4451
+				}
4097 4452
 			}
4098 4453
 		}
4099 4454
 	}
@@ -4120,7 +4475,9 @@  discard block
 block discarded – undo
4120 4475
 		print '<td>'.$langs->trans('Description').'</td>';
4121 4476
 		print '<td align="right">'.$langs->trans('VATRate').'</td>';
4122 4477
 		print '<td align="right">'.$langs->trans('PriceUHT').'</td>';
4123
-		if (!empty($conf->multicurrency->enabled)) print '<td align="right">'.$langs->trans('PriceUHTCurrency').'</td>';
4478
+		if (!empty($conf->multicurrency->enabled)) {
4479
+		    print '<td align="right">'.$langs->trans('PriceUHTCurrency').'</td>';
4480
+		}
4124 4481
 		print '<td align="right">'.$langs->trans('Qty').'</td>';
4125 4482
 		if($conf->global->PRODUCT_USE_UNITS)
4126 4483
 		{
@@ -4143,8 +4500,7 @@  discard block
 block discarded – undo
4143 4500
 						$action='';
4144 4501
 						$hookmanager->executeHooks('printOriginObjectLine',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
4145 4502
 					}
4146
-				}
4147
-				else
4503
+				} else
4148 4504
 				{
4149 4505
 					$this->printOriginLine($line, $var, $restrictlist);
4150 4506
 				}
@@ -4173,32 +4529,37 @@  discard block
 block discarded – undo
4173 4529
 		if (!empty($line->date_start))
4174 4530
 		{
4175 4531
 			$date_start=$line->date_start;
4176
-		}
4177
-		else
4532
+		} else
4178 4533
 		{
4179 4534
 			$date_start=$line->date_debut_prevue;
4180
-			if ($line->date_debut_reel) $date_start=$line->date_debut_reel;
4535
+			if ($line->date_debut_reel) {
4536
+			    $date_start=$line->date_debut_reel;
4537
+			}
4181 4538
 		}
4182 4539
 		if (!empty($line->date_end))
4183 4540
 		{
4184 4541
 			$date_end=$line->date_end;
4185
-		}
4186
-		else
4542
+		} else
4187 4543
 		{
4188 4544
 			$date_end=$line->date_fin_prevue;
4189
-			if ($line->date_fin_reel) $date_end=$line->date_fin_reel;
4545
+			if ($line->date_fin_reel) {
4546
+			    $date_end=$line->date_fin_reel;
4547
+			}
4190 4548
 		}
4191 4549
 
4192 4550
 		$this->tpl['label'] = '';
4193
-		if (! empty($line->fk_parent_line)) $this->tpl['label'].= img_picto('', 'rightarrow');
4551
+		if (! empty($line->fk_parent_line)) {
4552
+		    $this->tpl['label'].= img_picto('', 'rightarrow');
4553
+		}
4194 4554
 
4195
-		if (($line->info_bits & 2) == 2)  // TODO Not sure this is used for source object
4555
+		if (($line->info_bits & 2) == 2) {
4556
+		    // TODO Not sure this is used for source object
4196 4557
 		{
4197 4558
 			$discount=new DiscountAbsolute($this->db);
4559
+		}
4198 4560
 			$discount->fk_soc = $this->socid;
4199 4561
 			$this->tpl['label'].= $discount->getNomUrl(0,'discount');
4200
-		}
4201
-		else if (! empty($line->fk_product))
4562
+		} else if (! empty($line->fk_product))
4202 4563
 		{
4203 4564
 			$productstatic = new Product($this->db);
4204 4565
 			$productstatic->id = $line->fk_product;
@@ -4216,13 +4577,12 @@  discard block
 block discarded – undo
4216 4577
 			{
4217 4578
 				$this->tpl['label'].= get_date_range($date_start,$date_end);
4218 4579
 			}
4219
-		}
4220
-		else
4580
+		} else
4221 4581
 		{
4222 4582
 			$this->tpl['label'].= ($line->product_type == -1 ? '&nbsp;' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product')));
4223 4583
 			if (!empty($line->desc)) {
4224 4584
 				$this->tpl['label'].=$line->desc;
4225
-			}else {
4585
+			} else {
4226 4586
 				$this->tpl['label'].= ($line->label ? '&nbsp;'.$line->label : '');
4227 4587
 			}
4228 4588
 			
@@ -4235,36 +4595,35 @@  discard block
 block discarded – undo
4235 4595
 
4236 4596
 		if (! empty($line->desc))
4237 4597
 		{
4238
-			if ($line->desc == '(CREDIT_NOTE)')  // TODO Not sure this is used for source object
4598
+			if ($line->desc == '(CREDIT_NOTE)') {
4599
+			    // TODO Not sure this is used for source object
4239 4600
 			{
4240 4601
 				$discount=new DiscountAbsolute($this->db);
4602
+			}
4241 4603
 				$discount->fetch($line->fk_remise_except);
4242 4604
 				$this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
4243
-			}
4244
-			elseif ($line->desc == '(DEPOSIT)')  // TODO Not sure this is used for source object
4605
+			} elseif ($line->desc == '(DEPOSIT)') {
4606
+			    // TODO Not sure this is used for source object
4245 4607
 			{
4246 4608
 				$discount=new DiscountAbsolute($this->db);
4609
+			}
4247 4610
 				$discount->fetch($line->fk_remise_except);
4248 4611
 				$this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0));
4249
-			}
4250
-			elseif ($line->desc == '(EXCESS RECEIVED)')
4612
+			} elseif ($line->desc == '(EXCESS RECEIVED)')
4251 4613
 			{
4252 4614
 				$discount=new DiscountAbsolute($this->db);
4253 4615
 				$discount->fetch($line->fk_remise_except);
4254 4616
 				$this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0));
4255
-			}
4256
-			elseif ($line->desc == '(EXCESS PAID)')
4617
+			} elseif ($line->desc == '(EXCESS PAID)')
4257 4618
 			{
4258 4619
 				$discount=new DiscountAbsolute($this->db);
4259 4620
 				$discount->fetch($line->fk_remise_except);
4260 4621
 				$this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0));
4261
-			}
4262
-			else
4622
+			} else
4263 4623
 			{
4264 4624
 				$this->tpl['description'] = dol_trunc($line->desc,60);
4265 4625
 			}
4266
-		}
4267
-		else
4626
+		} else
4268 4627
 		{
4269 4628
 			$this->tpl['description'] = '&nbsp;';
4270 4629
 		}
@@ -4272,17 +4631,23 @@  discard block
 block discarded – undo
4272 4631
         // VAT Rate
4273 4632
         $this->tpl['vat_rate'] = vatrate($line->tva_tx, true);
4274 4633
         $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : '';
4275
-        if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')';
4634
+        if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) {
4635
+            $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')';
4636
+        }
4276 4637
 
4277 4638
 		$this->tpl['price'] = price($line->subprice);
4278 4639
 		$this->tpl['multicurrency_price'] = price($line->multicurrency_subprice);
4279 4640
 		$this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : '&nbsp;';
4280
-		if ($conf->global->PRODUCT_USE_UNITS) $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long'));
4641
+		if ($conf->global->PRODUCT_USE_UNITS) {
4642
+		    $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long'));
4643
+		}
4281 4644
 		$this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : '&nbsp;';
4282 4645
 
4283 4646
 		// Is the line strike or not
4284 4647
 		$this->tpl['strike']=0;
4285
-		if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike']=1;
4648
+		if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) {
4649
+		    $this->tpl['strike']=1;
4650
+		}
4286 4651
 
4287 4652
 		// Output template part (modules that overwrite templates must declare this into descriptor)
4288 4653
 		// Use global variables + $dateSelector + $seller and $buyer
@@ -4295,7 +4660,9 @@  discard block
 block discarded – undo
4295 4660
 			} else {
4296 4661
 				$res=include $tpl; // for debug
4297 4662
 			}
4298
-			if ($res) break;
4663
+			if ($res) {
4664
+			    break;
4665
+			}
4299 4666
 		}
4300 4667
 	}
4301 4668
 
@@ -4337,8 +4704,7 @@  discard block
 block discarded – undo
4337 4704
 		{
4338 4705
 			$this->db->commit();
4339 4706
 			return 1;
4340
-		}
4341
-		else
4707
+		} else
4342 4708
 		{
4343 4709
 			$this->error=$this->db->lasterror();
4344 4710
 			$this->db->rollback();
@@ -4373,8 +4739,7 @@  discard block
 block discarded – undo
4373 4739
 			$this->error=$this->db->lasterror();
4374 4740
 			$this->db->rollback();
4375 4741
 			return -1;
4376
-		}
4377
-		else
4742
+		} else
4378 4743
 		{
4379 4744
 			if (! $notrigger)
4380 4745
 			{
@@ -4441,13 +4806,20 @@  discard block
 block discarded – undo
4441 4806
 		// Search template files
4442 4807
 		$file=''; $classname=''; $filefound=0;
4443 4808
 		$dirmodels=array('/');
4444
-		if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
4809
+		if (is_array($conf->modules_parts['models'])) {
4810
+		    $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
4811
+		}
4445 4812
 		foreach($dirmodels as $reldir)
4446 4813
 		{
4447 4814
 			foreach(array('doc','pdf') as $prefix)
4448 4815
 			{
4449
-				if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php";     // Member module use prefix_module.class.php
4450
-				else $file = $prefix."_".$modele.".modules.php";
4816
+				if (in_array(get_class($this), array('Adherent'))) {
4817
+				    $file = $prefix."_".$modele.".class.php";
4818
+				}
4819
+				// Member module use prefix_module.class.php
4820
+				else {
4821
+				    $file = $prefix."_".$modele.".modules.php";
4822
+				}
4451 4823
 
4452 4824
 				// On verifie l'emplacement du modele
4453 4825
 				$file=dol_buildpath($reldir.$modelspath.$file,0);
@@ -4458,7 +4830,9 @@  discard block
 block discarded – undo
4458 4830
 					break;
4459 4831
 				}
4460 4832
 			}
4461
-			if ($filefound) break;
4833
+			if ($filefound) {
4834
+			    break;
4835
+			}
4462 4836
 		}
4463 4837
 
4464 4838
 		// If generator was found
@@ -4490,7 +4864,9 @@  discard block
 block discarded – undo
4490 4864
 						if (is_dir($tmpdir))
4491 4865
 						{
4492 4866
 							$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0);
4493
-							if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
4867
+							if (count($tmpfiles)) {
4868
+							    $listoffiles=array_merge($listoffiles,$tmpfiles);
4869
+							}
4494 4870
 						}
4495 4871
 					}
4496 4872
 
@@ -4528,8 +4904,7 @@  discard block
 block discarded – undo
4528 4904
 			{
4529 4905
 				$arrayofrecords = array();   // The write_file of templates of adherent class need this var
4530 4906
 				$resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams);
4531
-			}
4532
-			else
4907
+			} else
4533 4908
 			{
4534 4909
 				$resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams);
4535 4910
 			}
@@ -4551,9 +4926,11 @@  discard block
 block discarded – undo
4551 4926
 					$destfile = basename($destfull);
4552 4927
 					$rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir);
4553 4928
 
4554
-					if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir))     // If not a tmp dir
4929
+					if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
4930
+					    // If not a tmp dir
4555 4931
 					{
4556 4932
 						$filename = basename($destfile);
4933
+					}
4557 4934
 						$rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
4558 4935
 						$rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
4559 4936
 
@@ -4566,18 +4943,30 @@  discard block
 block discarded – undo
4566 4943
 						if ($this->element == 'propal')
4567 4944
 						{
4568 4945
 							$useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL;	// Replace this with 1 when feature to make online signature is ok
4569
-							if ($useonlinesignature) $setsharekey=true;
4570
-							if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true;
4946
+							if ($useonlinesignature) {
4947
+							    $setsharekey=true;
4948
+							}
4949
+							if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) {
4950
+							    $setsharekey=true;
4951
+							}
4952
+						}
4953
+						if ($this->element == 'commande'     && ! empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) {
4954
+						    $setsharekey=true;
4955
+						}
4956
+						if ($this->element == 'facture'      && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) {
4957
+						    $setsharekey=true;
4958
+						}
4959
+						if ($this->element == 'bank_account' && ! empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) {
4960
+						    $setsharekey=true;
4571 4961
 						}
4572
-						if ($this->element == 'commande'     && ! empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD))        $setsharekey=true;
4573
-						if ($this->element == 'facture'      && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD))      $setsharekey=true;
4574
-						if ($this->element == 'bank_account' && ! empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true;
4575 4962
 
4576 4963
 						if ($setsharekey)
4577 4964
 						{
4578
-							if (empty($ecmfile->share))	// Because object not found or share not set yet
4965
+							if (empty($ecmfile->share)) {
4966
+							    // Because object not found or share not set yet
4579 4967
 							{
4580 4968
 								require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
4969
+							}
4581 4970
 								$ecmfile->share = getRandomPassword(true);
4582 4971
 							}
4583 4972
 						}
@@ -4594,8 +4983,7 @@  discard block
 block discarded – undo
4594 4983
 							{
4595 4984
 								setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
4596 4985
 							}
4597
-						}
4598
-						else
4986
+						} else
4599 4987
 						{
4600 4988
 							$ecmfile->entity = $conf->entity;
4601 4989
 							$ecmfile->filepath = $rel_dir;
@@ -4622,17 +5010,20 @@  discard block
 block discarded – undo
4622 5010
 
4623 5011
 						// Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set)
4624 5012
 						$update_main_doc_field=0;
4625
-						if (! empty($obj->update_main_doc_field)) $update_main_doc_field=1;
5013
+						if (! empty($obj->update_main_doc_field)) {
5014
+						    $update_main_doc_field=1;
5015
+						}
4626 5016
 						if ($update_main_doc_field && ! empty($this->table_element))
4627 5017
 						{
4628 5018
 							$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'";
4629 5019
 							$sql.= ' WHERE rowid = '.$this->id;
4630 5020
 							$resql = $this->db->query($sql);
4631
-							if (! $resql) dol_print_error($this->db);
5021
+							if (! $resql) {
5022
+							    dol_print_error($this->db);
5023
+							}
4632 5024
 						}
4633 5025
 					}
4634
-				}
4635
-				else
5026
+				} else
4636 5027
 				{
4637 5028
 					dol_syslog('Method ->write_file was called on object '.get_class($obj).' and return a success but the return array ->result["fullpath"] was not set.', LOG_WARNING);
4638 5029
 				}
@@ -4641,15 +5032,13 @@  discard block
 block discarded – undo
4641 5032
 				dol_meta_create($this);
4642 5033
 
4643 5034
 				return 1;
4644
-			}
4645
-			else
5035
+			} else
4646 5036
 			{
4647 5037
 				$outputlangs->charset_output=$sav_charset_output;
4648 5038
 				dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors);
4649 5039
 				return -1;
4650 5040
 			}
4651
-		}
4652
-		else
5041
+		} else
4653 5042
 		{
4654 5043
 			$this->error=$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
4655 5044
 			dol_print_error('',$this->error);
@@ -4705,13 +5094,21 @@  discard block
 block discarded – undo
4705 5094
 		global $conf, $_POST;
4706 5095
 
4707 5096
 		// If param here has been posted, we use this value first.
4708
-		if (isset($_POST[$fieldname])) return GETPOST($fieldname, 2);
5097
+		if (isset($_POST[$fieldname])) {
5098
+		    return GETPOST($fieldname, 2);
5099
+		}
4709 5100
 
4710
-		if (isset($alternatevalue)) return $alternatevalue;
5101
+		if (isset($alternatevalue)) {
5102
+		    return $alternatevalue;
5103
+		}
4711 5104
 
4712 5105
 		$newelement=$this->element;
4713
-		if ($newelement == 'facture') $newelement='invoice';
4714
-		if ($newelement == 'commande') $newelement='order';
5106
+		if ($newelement == 'facture') {
5107
+		    $newelement='invoice';
5108
+		}
5109
+		if ($newelement == 'commande') {
5110
+		    $newelement='order';
5111
+		}
4715 5112
 		if (empty($newelement))
4716 5113
 		{
4717 5114
 			dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
@@ -4720,7 +5117,9 @@  discard block
 block discarded – undo
4720 5117
 
4721 5118
 		$keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname);
4722 5119
 		//var_dump($keyforfieldname);
4723
-		if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname;
5120
+		if (isset($conf->global->$keyforfieldname)) {
5121
+		    return $conf->global->$keyforfieldname;
5122
+		}
4724 5123
 
4725 5124
 		// TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname
4726 5125
 	}
@@ -4754,8 +5153,7 @@  discard block
 block discarded – undo
4754 5153
 			if (!empty($this->errors))
4755 5154
 			{
4756 5155
 				$this->errors=array_unique(array_merge($this->errors,$interface->errors));   // We use array_unique because when a trigger call another trigger on same object, this->errors is added twice.
4757
-			}
4758
-			else
5156
+			} else
4759 5157
 			{
4760 5158
 				$this->errors=$interface->errors;
4761 5159
 			}
@@ -4779,7 +5177,9 @@  discard block
 block discarded – undo
4779 5177
 	function fetch_optionals($rowid=null, $optionsArray=null)
4780 5178
 	{
4781 5179
         // phpcs:enable
4782
-		if (empty($rowid)) $rowid=$this->id;
5180
+		if (empty($rowid)) {
5181
+		    $rowid=$this->id;
5182
+		}
4783 5183
 
4784 5184
 		// To avoid SQL errors. Probably not the better solution though
4785 5185
 		if (!$this->table_element) {
@@ -4805,15 +5205,17 @@  discard block
 block discarded – undo
4805 5205
 				$extrafields->fetch_name_optionals_label($this->table_element);
4806 5206
 			}
4807 5207
 			$optionsArray = (! empty($extrafields->attributes[$this->table_element]['label'])?$extrafields->attributes[$this->table_element]['label']:null);
4808
-		}
4809
-		else
5208
+		} else
4810 5209
 		{
4811 5210
 			global $extrafields;
4812 5211
 			dol_syslog("Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING);
4813 5212
 		}
4814 5213
 
4815 5214
 		$table_element = $this->table_element;
4816
-		if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility
5215
+		if ($table_element == 'categorie') {
5216
+		    $table_element = 'categories';
5217
+		}
5218
+		// For compatibility
4817 5219
 
4818 5220
 		// Request to get complementary values
4819 5221
 		if (is_array($optionsArray) && count($optionsArray) > 0)
@@ -4849,8 +5251,7 @@  discard block
 block discarded – undo
4849 5251
 							{
4850 5252
 								//var_dump($extrafields->attributes[$this->table_element]['type'][$key]);
4851 5253
 								$this->array_options["options_".$key]=$this->db->jdate($value);
4852
-							}
4853
-							else
5254
+							} else
4854 5255
 							{
4855 5256
 								$this->array_options["options_".$key]=$value;
4856 5257
 							}
@@ -4862,10 +5263,12 @@  discard block
 block discarded – undo
4862 5263
 
4863 5264
 				$this->db->free($resql);
4864 5265
 
4865
-				if ($numrows) return $numrows;
4866
-				else return 0;
4867
-			}
4868
-			else
5266
+				if ($numrows) {
5267
+				    return $numrows;
5268
+				} else {
5269
+				    return 0;
5270
+				}
5271
+			} else
4869 5272
 			{
4870 5273
 				dol_print_error($this->db);
4871 5274
 				return -1;
@@ -4884,7 +5287,10 @@  discard block
 block discarded – undo
4884 5287
 		$this->db->begin();
4885 5288
 
4886 5289
 		$table_element = $this->table_element;
4887
-		if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility
5290
+		if ($table_element == 'categorie') {
5291
+		    $table_element = 'categories';
5292
+		}
5293
+		// For compatibility
4888 5294
 
4889 5295
 		$sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id;
4890 5296
 		dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG);
@@ -4894,8 +5300,7 @@  discard block
 block discarded – undo
4894 5300
 			$this->error=$this->db->lasterror();
4895 5301
 			$this->db->rollback();
4896 5302
 			return -1;
4897
-		}
4898
-		else
5303
+		} else
4899 5304
 		{
4900 5305
 			$this->db->commit();
4901 5306
 			return 1;
@@ -4916,11 +5321,16 @@  discard block
 block discarded – undo
4916 5321
 	{
4917 5322
 		global $conf,$langs,$user;
4918 5323
 
4919
-		if (empty($userused)) $userused=$user;
5324
+		if (empty($userused)) {
5325
+		    $userused=$user;
5326
+		}
4920 5327
 
4921 5328
 		$error=0;
4922 5329
 
4923
-		if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0;	// For avoid conflicts if trigger used
5330
+		if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
5331
+		    return 0;
5332
+		}
5333
+		// For avoid conflicts if trigger used
4924 5334
 
4925 5335
 		if (! empty($this->array_options))
4926 5336
 		{
@@ -4933,10 +5343,13 @@  discard block
 block discarded – undo
4933 5343
 			//Eliminate copied source object extra_fields that do not exist in target object
4934 5344
 			$new_array_options=array();
4935 5345
 			foreach ($this->array_options as $key => $value) {
4936
-				if (in_array(substr($key,8), array_keys($target_extrafields)))	// We remove the 'options_' from $key for test
5346
+				if (in_array(substr($key,8), array_keys($target_extrafields))) {
5347
+				    // We remove the 'options_' from $key for test
4937 5348
 					$new_array_options[$key] = $value;
4938
-				elseif (in_array($key, array_keys($target_extrafields)))		// We test on $key that does not contains the 'options_' prefix
5349
+				} elseif (in_array($key, array_keys($target_extrafields))) {
5350
+				    // We test on $key that does not contains the 'options_' prefix
4939 5351
 					$new_array_options['options_'.$key] = $value;
5352
+				}
4940 5353
 			}
4941 5354
 
4942 5355
 			foreach($new_array_options as $key => $value)
@@ -4950,8 +5363,12 @@  discard block
 block discarded – undo
4950 5363
 			   	if ($attributeRequired)
4951 5364
 			   	{
4952 5365
 			   		$mandatorypb=false;
4953
-			   		if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb=true;
4954
-			   		if ($this->array_options[$key] === '') $mandatorypb=true;
5366
+			   		if ($attributeType == 'link' && $this->array_options[$key] == '-1') {
5367
+			   		    $mandatorypb=true;
5368
+			   		}
5369
+			   		if ($this->array_options[$key] === '') {
5370
+			   		    $mandatorypb=true;
5371
+			   		}
4955 5372
 			   		if ($mandatorypb)
4956 5373
 			   		{
4957 5374
 			   			dol_syslog($this->error);
@@ -4970,8 +5387,7 @@  discard block
 block discarded – undo
4970 5387
 			   			{
4971 5388
 			   				$this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
4972 5389
 			   				return -1;
4973
-			  			}
4974
-			   			elseif ($value=='')
5390
+			  			} elseif ($value=='')
4975 5391
 			   			{
4976 5392
 			   				$new_array_options[$key] = null;
4977 5393
 			   			}
@@ -4983,8 +5399,7 @@  discard block
 block discarded – undo
4983 5399
 							dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
4984 5400
 							$this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
4985 5401
 							return -1;
4986
-						}
4987
-						elseif ($value=='')
5402
+						} elseif ($value=='')
4988 5403
 						{
4989 5404
 							$new_array_options[$key] = null;
4990 5405
 						}
@@ -5009,27 +5424,27 @@  discard block
 block discarded – undo
5009 5424
 			   					//global $action;		// $action may be 'create', 'update', 'update_extras'...
5010 5425
 			   					//var_dump($action);
5011 5426
 			   					//var_dump($this->oldcopy);exit;
5012
-			   					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
5427
+			   					if (is_object($this->oldcopy)) {
5428
+			   					    // If this->oldcopy is not defined, we can't know if we change attribute or not, so we must keep value
5013 5429
 			   					{
5014 5430
 			   						//var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]);
5015 5431
 				   					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.
5016 5432
 				   					{
5017
-				   						$new_array_options[$key] = $this->array_options[$key];	// Value is kept
5018
-				   					}
5019
-									else
5433
+				   						$new_array_options[$key] = $this->array_options[$key];
5434
+			   					}
5435
+			   					// Value is kept
5436
+				   					} else
5020 5437
 									{
5021 5438
 										// var_dump($algo);
5022 5439
 										$newvalue = dol_hash($this->array_options[$key], $algo);
5023 5440
 										$new_array_options[$key] = $newvalue;
5024 5441
 									}
5025
-			   					}
5026
-			   					else
5442
+			   					} else
5027 5443
 			   					{
5028 5444
 			   						$new_array_options[$key] = $this->array_options[$key];	// Value is kept
5029 5445
 			   					}
5030 5446
 			   				}
5031
-			   			}
5032
-			   			else	// Common usage
5447
+			   			} else	// Common usage
5033 5448
 			   			{
5034 5449
 			   				$new_array_options[$key] = $this->array_options[$key];
5035 5450
 			   			}
@@ -5055,26 +5470,30 @@  discard block
 block discarded – undo
5055 5470
 						dol_include_once($InfoFieldList[1]);
5056 5471
 						if ($InfoFieldList[0] && class_exists($InfoFieldList[0]))
5057 5472
 						{
5058
-							if ($value == '-1')	// -1 is key for no defined in combo list of objects
5473
+							if ($value == '-1') {
5474
+							    // -1 is key for no defined in combo list of objects
5059 5475
 							{
5060 5476
 								$new_array_options[$key]='';
5061 5477
 							}
5062
-							elseif ($value)
5478
+							} elseif ($value)
5063 5479
 							{
5064 5480
 								$object = new $InfoFieldList[0]($this->db);
5065
-								if (is_numeric($value)) $res=$object->fetch($value);
5066
-								else $res=$object->fetch('',$value);
5481
+								if (is_numeric($value)) {
5482
+								    $res=$object->fetch($value);
5483
+								} else {
5484
+								    $res=$object->fetch('',$value);
5485
+								}
5067 5486
 
5068
-								if ($res > 0) $new_array_options[$key]=$object->id;
5069
-								else
5487
+								if ($res > 0) {
5488
+								    $new_array_options[$key]=$object->id;
5489
+								} else
5070 5490
 								{
5071 5491
 									$this->error="Id/Ref '".$value."' for object '".$object->element."' not found";
5072 5492
 									$this->db->rollback();
5073 5493
 									return -1;
5074 5494
 								}
5075 5495
 							}
5076
-						}
5077
-						else
5496
+						} else
5078 5497
 						{
5079 5498
 							dol_syslog('Error bad setup of extrafield', LOG_WARNING);
5080 5499
 						}
@@ -5085,7 +5504,10 @@  discard block
 block discarded – undo
5085 5504
 			$this->db->begin();
5086 5505
 
5087 5506
 			$table_element = $this->table_element;
5088
-			if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility
5507
+			if ($table_element == 'categorie') {
5508
+			    $table_element = 'categories';
5509
+			}
5510
+			// For compatibility
5089 5511
 
5090 5512
 			$sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id;
5091 5513
 			dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG);
@@ -5096,8 +5518,10 @@  discard block
 block discarded – undo
5096 5518
 			{
5097 5519
 				$attributeKey = substr($key,8);   // Remove 'options_' prefix
5098 5520
 				// Add field of attribut
5099
-				if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator
5521
+				if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') {
5522
+				    // Only for other type than separator
5100 5523
 					$sql.=",".$attributeKey;
5524
+				}
5101 5525
 			}
5102 5526
 			$sql .= ") VALUES (".$this->id;
5103 5527
 
@@ -5105,13 +5529,14 @@  discard block
 block discarded – undo
5105 5529
 			{
5106 5530
 				$attributeKey = substr($key,8);   // Remove 'options_' prefix
5107 5531
 				// Add field of attribute
5108
-				if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator)
5532
+				if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') {
5533
+				    // Only for other type than separator)
5109 5534
 				{
5110 5535
 					if ($new_array_options[$key] != '')
5111 5536
 					{
5112 5537
 						$sql.=",'".$this->db->escape($new_array_options[$key])."'";
5113
-					}
5114
-					else
5538
+				}
5539
+					} else
5115 5540
 					{
5116 5541
 						$sql.=",null";
5117 5542
 					}
@@ -5132,7 +5557,9 @@  discard block
 block discarded – undo
5132 5557
 				// Call trigger
5133 5558
 				$this->context=array('extrafieldaddupdate'=>1);
5134 5559
 				$result=$this->call_trigger($trigger, $userused);
5135
-				if ($result < 0) $error++;
5560
+				if ($result < 0) {
5561
+				    $error++;
5562
+				}
5136 5563
 				// End call trigger
5137 5564
 			}
5138 5565
 
@@ -5140,14 +5567,14 @@  discard block
 block discarded – undo
5140 5567
 			{
5141 5568
 				$this->db->rollback();
5142 5569
 				return -1;
5143
-			}
5144
-			else
5570
+			} else
5145 5571
 			{
5146 5572
 				$this->db->commit();
5147 5573
 				return 1;
5148 5574
 			}
5575
+		} else {
5576
+		    return 0;
5149 5577
 		}
5150
-		else return 0;
5151 5578
 	}
5152 5579
 
5153 5580
 	/**
@@ -5164,11 +5591,16 @@  discard block
 block discarded – undo
5164 5591
 	{
5165 5592
 		global $conf,$langs,$user;
5166 5593
 
5167
-		if (empty($userused)) $userused=$user;
5594
+		if (empty($userused)) {
5595
+		    $userused=$user;
5596
+		}
5168 5597
 
5169 5598
 		$error=0;
5170 5599
 
5171
-		if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0;	// For avoid conflicts if trigger used
5600
+		if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
5601
+		    return 0;
5602
+		}
5603
+		// For avoid conflicts if trigger used
5172 5604
 
5173 5605
 		if (! empty($this->array_options) && isset($this->array_options["options_".$key]))
5174 5606
 		{
@@ -5195,8 +5627,7 @@  discard block
 block discarded – undo
5195 5627
 					{
5196 5628
 						$this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel);
5197 5629
 						return -1;
5198
-					}
5199
-					elseif ($value=='')
5630
+					} elseif ($value=='')
5200 5631
 					{
5201 5632
 						$this->array_options["options_".$key] = null;
5202 5633
 					}
@@ -5208,8 +5639,7 @@  discard block
 block discarded – undo
5208 5639
 						dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
5209 5640
 						$this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
5210 5641
 						return -1;
5211
-					}
5212
-					elseif ($value=='')
5642
+					} elseif ($value=='')
5213 5643
 					{
5214 5644
 						$this->array_options["options_".$key] = null;
5215 5645
 					}
@@ -5261,7 +5691,9 @@  discard block
 block discarded – undo
5261 5691
 				// Call trigger
5262 5692
 				$this->context=array('extrafieldupdate'=>1);
5263 5693
 				$result=$this->call_trigger($trigger, $userused);
5264
-				if ($result < 0) $error++;
5694
+				if ($result < 0) {
5695
+				    $error++;
5696
+				}
5265 5697
 				// End call trigger
5266 5698
 			}
5267 5699
 
@@ -5270,14 +5702,14 @@  discard block
 block discarded – undo
5270 5702
 				dol_syslog(get_class($this) . "::".__METHOD__ . $this->error, LOG_ERR);
5271 5703
 				$this->db->rollback();
5272 5704
 				return -1;
5273
-			}
5274
-			else
5705
+			} else
5275 5706
 			{
5276 5707
 				$this->db->commit();
5277 5708
 				return 1;
5278 5709
 			}
5710
+		} else {
5711
+		    return 0;
5279 5712
 		}
5280
-		else return 0;
5281 5713
 	}
5282 5714
 
5283 5715
 
@@ -5352,8 +5784,11 @@  discard block
 block discarded – undo
5352 5784
 
5353 5785
 		if ($computed)
5354 5786
 		{
5355
-			if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
5356
-			else return '';
5787
+			if (! preg_match('/^search_/', $keyprefix)) {
5788
+			    return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
5789
+			} else {
5790
+			    return '';
5791
+			}
5357 5792
 		}
5358 5793
 
5359 5794
 
@@ -5367,33 +5802,27 @@  discard block
 block discarded – undo
5367 5802
 			if ($type == 'date')
5368 5803
 			{
5369 5804
 				$morecss = 'minwidth100imp';
5370
-			}
5371
-			elseif ($type == 'datetime')
5805
+			} elseif ($type == 'datetime')
5372 5806
 			{
5373 5807
 				$morecss = 'minwidth200imp';
5374
-			}
5375
-			elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
5808
+			} elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
5376 5809
 			{
5377 5810
 				$morecss = 'maxwidth75';
5378
-                        }elseif ($type == 'url')
5811
+                        } elseif ($type == 'url')
5379 5812
 			{
5380 5813
 				$morecss='minwidth400';
5381
-			}
5382
-			elseif ($type == 'boolean')
5814
+			} elseif ($type == 'boolean')
5383 5815
 			{
5384 5816
 				$morecss='';
5385
-			}
5386
-			else
5817
+			} else
5387 5818
 			{
5388 5819
 				if (round($size) < 12)
5389 5820
 				{
5390 5821
 					$morecss = 'minwidth100';
5391
-				}
5392
-				else if (round($size) <= 48)
5822
+				} else if (round($size) <= 48)
5393 5823
 				{
5394 5824
 					$morecss = 'minwidth200';
5395
-				}
5396
-				else
5825
+				} else
5397 5826
 				{
5398 5827
 					$morecss = 'minwidth400';
5399 5828
 				}
@@ -5408,52 +5837,50 @@  discard block
 block discarded – undo
5408 5837
 			$showtime = in_array($type,array('datetime')) ? 1 : 0;
5409 5838
 
5410 5839
 			// Do not show current date when field not required (see selectDate() method)
5411
-			if (!$required && $value == '') $value = '-1';
5840
+			if (!$required && $value == '') {
5841
+			    $value = '-1';
5842
+			}
5412 5843
 
5413 5844
 			// TODO Must also support $moreparam
5414 5845
 			$out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1);
5415
-		}
5416
-		elseif (in_array($type,array('int','integer')))
5846
+		} elseif (in_array($type,array('int','integer')))
5417 5847
 		{
5418 5848
 			$tmp=explode(',',$size);
5419 5849
 			$newsize=$tmp[0];
5420 5850
 			$out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>';
5421
-		}
5422
-		elseif (preg_match('/varchar/', $type))
5851
+		} elseif (preg_match('/varchar/', $type))
5423 5852
 		{
5424 5853
 			$out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>';
5425
-		}
5426
-		elseif (in_array($type, array('mail', 'phone', 'url')))
5854
+		} elseif (in_array($type, array('mail', 'phone', 'url')))
5427 5855
 		{
5428 5856
 			$out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>';
5429
-		}
5430
-		elseif ($type == 'text')
5857
+		} elseif ($type == 'text')
5431 5858
 		{
5432
-			if (! preg_match('/search_/', $keyprefix))		// If keyprefix is search_ or search_options_, we must just use a simple text field
5859
+			if (! preg_match('/search_/', $keyprefix)) {
5860
+			    // If keyprefix is search_ or search_options_, we must just use a simple text field
5433 5861
 			{
5434 5862
 				require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
5863
+			}
5435 5864
 				$doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%');
5436 5865
 				$out=$doleditor->Create(1);
5437
-			}
5438
-			else
5866
+			} else
5439 5867
 			{
5440 5868
 				$out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>';
5441 5869
 			}
5442
-		}
5443
-		elseif ($type == 'html')
5870
+		} elseif ($type == 'html')
5444 5871
 		{
5445
-			if (! preg_match('/search_/', $keyprefix))		// If keyprefix is search_ or search_options_, we must just use a simple text field
5872
+			if (! preg_match('/search_/', $keyprefix)) {
5873
+			    // If keyprefix is search_ or search_options_, we must just use a simple text field
5446 5874
 			{
5447 5875
 				require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
5876
+			}
5448 5877
 				$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%');
5449 5878
 				$out=$doleditor->Create(1);
5450
-			}
5451
-			else
5879
+			} else
5452 5880
 			{
5453 5881
 				$out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>';
5454 5882
 			}
5455
-		}
5456
-		elseif ($type == 'boolean')
5883
+		} elseif ($type == 'boolean')
5457 5884
 		{
5458 5885
 			$checked='';
5459 5886
 			if (!empty($value)) {
@@ -5462,22 +5889,19 @@  discard block
 block discarded – undo
5462 5889
 				$checked=' value="1" ';
5463 5890
 			}
5464 5891
 			$out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>';
5465
-		}
5466
-		elseif ($type == 'price')
5892
+		} elseif ($type == 'price')
5467 5893
 		{
5468 5894
 			if (!empty($value)) {		// $value in memory is a php numeric, we format it into user number format.
5469 5895
 				$value=price($value);
5470 5896
 			}
5471 5897
 			$out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency);
5472
-		}
5473
-		elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
5898
+		} elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
5474 5899
 		{
5475 5900
 			if (!empty($value)) {		// $value in memory is a php numeric, we format it into user number format.
5476 5901
 				$value=price($value);
5477 5902
 			}
5478 5903
 			$out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> ';
5479
-		}
5480
-		elseif ($type == 'select')
5904
+		} elseif ($type == 'select')
5481 5905
 		{
5482 5906
 			$out = '';
5483 5907
 			if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2))
@@ -5487,10 +5911,14 @@  discard block
 block discarded – undo
5487 5911
 			}
5488 5912
 
5489 5913
 			$out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>';
5490
-                if((! isset($this->fields[$key]['default'])) ||($this->fields[$key]['notnull']!=1))$out.='<option value="0">&nbsp;</option>';
5914
+                if((! isset($this->fields[$key]['default'])) ||($this->fields[$key]['notnull']!=1)) {
5915
+                    $out.='<option value="0">&nbsp;</option>';
5916
+                }
5491 5917
 			foreach ($param['options'] as $key => $val)
5492 5918
 			{
5493
-				if ((string) $key == '') continue;
5919
+				if ((string) $key == '') {
5920
+				    continue;
5921
+				}
5494 5922
 				list($val, $parent) = explode('|', $val);
5495 5923
 				$out.='<option value="'.$key.'"';
5496 5924
 				$out.= (((string) $value == (string) $key)?' selected':'');
@@ -5498,8 +5926,7 @@  discard block
 block discarded – undo
5498 5926
 				$out.='>'.$val.'</option>';
5499 5927
 			}
5500 5928
 			$out.='</select>';
5501
-		}
5502
-		elseif ($type == 'sellist')
5929
+		} elseif ($type == 'sellist')
5503 5930
 		{
5504 5931
 			$out = '';
5505 5932
 			if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2))
@@ -5566,13 +5993,11 @@  discard block
 block discarded – undo
5566 5993
 					{
5567 5994
 						$sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra';
5568 5995
 						$sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4];
5569
-					}
5570
-					else
5996
+					} else
5571 5997
 					{
5572 5998
 						$sqlwhere.= ' WHERE '.$InfoFieldList[4];
5573 5999
 					}
5574
-				}
5575
-				else
6000
+				} else
5576 6001
 				{
5577 6002
 					$sqlwhere.= ' WHERE 1=1';
5578 6003
 				}
@@ -5608,8 +6033,7 @@  discard block
 block discarded – undo
5608 6033
 							{
5609 6034
 								$labeltoshow.= $obj->$field_toshow.' ';
5610 6035
 							}
5611
-						}
5612
-						else
6036
+						} else
5613 6037
 						{
5614 6038
 							$labeltoshow=$obj->{$InfoFieldList[1]};
5615 6039
 						}
@@ -5622,25 +6046,25 @@  discard block
 block discarded – undo
5622 6046
 								$translabel=$langs->trans($obj->$field_toshow);
5623 6047
 								if ($translabel!=$obj->$field_toshow) {
5624 6048
 									$labeltoshow=dol_trunc($translabel,18).' ';
5625
-								}else {
6049
+								} else {
5626 6050
 									$labeltoshow=dol_trunc($obj->$field_toshow,18).' ';
5627 6051
 								}
5628 6052
 							}
5629 6053
 							$out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
5630
-						}
5631
-						else
6054
+						} else
5632 6055
 						{
5633 6056
 							if (! $notrans)
5634 6057
 							{
5635 6058
 								$translabel=$langs->trans($obj->{$InfoFieldList[1]});
5636 6059
 								if ($translabel!=$obj->{$InfoFieldList[1]}) {
5637 6060
 									$labeltoshow=dol_trunc($translabel,18);
5638
-								}
5639
-								else {
6061
+								} else {
5640 6062
 									$labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18);
5641 6063
 								}
5642 6064
 							}
5643
-							if (empty($labeltoshow)) $labeltoshow='(not defined)';
6065
+							if (empty($labeltoshow)) {
6066
+							    $labeltoshow='(not defined)';
6067
+							}
5644 6068
 							if ($value==$obj->rowid)
5645 6069
 							{
5646 6070
 								$out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
@@ -5660,19 +6084,16 @@  discard block
 block discarded – undo
5660 6084
 						$i++;
5661 6085
 					}
5662 6086
 					$this->db->free($resql);
5663
-				}
5664
-				else {
6087
+				} else {
5665 6088
 					print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>';
5666 6089
 				}
5667 6090
 			}
5668 6091
 			$out.='</select>';
5669
-		}
5670
-		elseif ($type == 'checkbox')
6092
+		} elseif ($type == 'checkbox')
5671 6093
 		{
5672 6094
 			$value_arr=explode(',',$value);
5673 6095
 			$out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%');
5674
-		}
5675
-		elseif ($type == 'radio')
6096
+		} elseif ($type == 'radio')
5676 6097
 		{
5677 6098
 			$out='';
5678 6099
 			foreach ($param['options'] as $keyopt => $val)
@@ -5683,13 +6104,11 @@  discard block
 block discarded – undo
5683 6104
 				$out.= ($value==$keyopt?'checked':'');
5684 6105
 				$out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>';
5685 6106
 			}
5686
-		}
5687
-		elseif ($type == 'chkbxlst')
6107
+		} elseif ($type == 'chkbxlst')
5688 6108
 		{
5689 6109
 			if (is_array($value)) {
5690 6110
 				$value_arr = $value;
5691
-			}
5692
-			else {
6111
+			} else {
5693 6112
 				$value_arr = explode(',', $value);
5694 6113
 			}
5695 6114
 
@@ -5804,8 +6223,9 @@  discard block
 block discarded – undo
5804 6223
 									$labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
5805 6224
 								}
5806 6225
 							}
5807
-							if (empty($labeltoshow))
5808
-								$labeltoshow = '(not defined)';
6226
+							if (empty($labeltoshow)) {
6227
+															$labeltoshow = '(not defined)';
6228
+							}
5809 6229
 
5810 6230
 								if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
5811 6231
 									$data[$obj->rowid]=$labeltoshow;
@@ -5827,8 +6247,7 @@  discard block
 block discarded – undo
5827 6247
 					print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>';
5828 6248
 				}
5829 6249
 			}
5830
-		}
5831
-		elseif ($type == 'link')
6250
+		} elseif ($type == 'link')
5832 6251
 		{
5833 6252
 			$param_list=array_keys($param['options']);				// $param_list='ObjectName:classPath'
5834 6253
 			$showempty=(($required && $default != '')?0:1);
@@ -5836,18 +6255,19 @@  discard block
 block discarded – undo
5836 6255
 			if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
5837 6256
 			{
5838 6257
             			list($class,$classfile)=explode(':',$param_list[0]);
5839
-            			if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php',1);
5840
-            			else $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php',1);
6258
+            			if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) {
6259
+            			    $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php',1);
6260
+            			} else {
6261
+            			    $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php',1);
6262
+            			}
5841 6263
             			$out.='<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>';
5842 6264
             			// TODO Add Javascript code to add input fields contents to new elements urls
5843 6265
 			}
5844
-		}
5845
-		elseif ($type == 'password')
6266
+		} elseif ($type == 'password')
5846 6267
 		{
5847 6268
 			// If prefix is 'search_', field is used as a filter, we use a common text field.
5848 6269
 			$out='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>';
5849
-		}
5850
-		elseif ($type == 'array')
6270
+		} elseif ($type == 'array')
5851 6271
 		{
5852 6272
 			$newval = $val;
5853 6273
 			$newval['type'] = 'varchar(256)';
@@ -5925,17 +6345,25 @@  discard block
 block discarded – undo
5925 6345
 		{
5926 6346
 			$type = 'varchar';		// convert varchar(xx) int varchar
5927 6347
 			$size = $reg[1];
6348
+		} elseif (preg_match('/varchar/', $type)) {
6349
+		    $type = 'varchar';
6350
+		}
6351
+		// convert varchar(xx) int varchar
6352
+		if (is_array($val['arrayofkeyval'])) {
6353
+		    $type='select';
6354
+		}
6355
+		if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) {
6356
+		    $type='link';
5928 6357
 		}
5929
-		elseif (preg_match('/varchar/', $type)) $type = 'varchar';		// convert varchar(xx) int varchar
5930
-		if (is_array($val['arrayofkeyval'])) $type='select';
5931
-		if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link';
5932 6358
 
5933 6359
 		$default=$val['default'];
5934 6360
 		$computed=$val['computed'];
5935 6361
 		$unique=$val['unique'];
5936 6362
 		$required=$val['required'];
5937 6363
 		$param=$val['param'];
5938
-		if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval'];
6364
+		if (is_array($val['arrayofkeyval'])) {
6365
+		    $param['options'] = $val['arrayofkeyval'];
6366
+		}
5939 6367
 		if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg))
5940 6368
 		{
5941 6369
 			$type='link';
@@ -5946,7 +6374,9 @@  discard block
 block discarded – undo
5946 6374
 		$help=$val['help'];
5947 6375
 		$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)
5948 6376
 
5949
-		if ($hidden) return '';
6377
+		if ($hidden) {
6378
+		    return '';
6379
+		}
5950 6380
 
5951 6381
 		// If field is a computed field, value must become result of compute
5952 6382
 		if ($computed)
@@ -5962,36 +6392,29 @@  discard block
 block discarded – undo
5962 6392
 			{
5963 6393
 				//$showsize=10;
5964 6394
 				$showsize = 'minwidth100imp';
5965
-			}
5966
-			elseif ($type == 'datetime')
6395
+			} elseif ($type == 'datetime')
5967 6396
 			{
5968 6397
 				//$showsize=19;
5969 6398
 				$showsize = 'minwidth200imp';
5970
-			}
5971
-			elseif (in_array($type,array('int','double','price')))
6399
+			} elseif (in_array($type,array('int','double','price')))
5972 6400
 			{
5973 6401
 				//$showsize=10;
5974 6402
 				$showsize = 'maxwidth75';
5975
-			}
5976
-			elseif ($type == 'url')
6403
+			} elseif ($type == 'url')
5977 6404
 			{
5978 6405
 				$showsize='minwidth400';
5979
-			}
5980
-			elseif ($type == 'boolean')
6406
+			} elseif ($type == 'boolean')
5981 6407
 			{
5982 6408
 				$showsize='';
5983
-			}
5984
-			else
6409
+			} else
5985 6410
 			{
5986 6411
 				if (round($size) < 12)
5987 6412
 				{
5988 6413
 					$showsize = 'minwidth100';
5989
-				}
5990
-				else if (round($size) <= 48)
6414
+				} else if (round($size) <= 48)
5991 6415
 				{
5992 6416
 					$showsize = 'minwidth200';
5993
-				}
5994
-				else
6417
+				} else
5995 6418
 				{
5996 6419
 					//$showsize=48;
5997 6420
 					$showsize = 'minwidth400';
@@ -6000,59 +6423,52 @@  discard block
 block discarded – undo
6000 6423
 		}
6001 6424
 
6002 6425
 		// Format output value differently according to properties of field
6003
-		if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value=$this->getNomUrl(1, '', 0, '', 1);
6004
-		elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value=$this->getLibStatut(3);
6005
-		elseif ($type == 'date')
6426
+		if ($key == 'ref' && method_exists($this, 'getNomUrl')) {
6427
+		    $value=$this->getNomUrl(1, '', 0, '', 1);
6428
+		} elseif ($key == 'status' && method_exists($this, 'getLibStatut')) {
6429
+		    $value=$this->getLibStatut(3);
6430
+		} elseif ($type == 'date')
6006 6431
 		{
6007 6432
 			if(! empty($value)) {
6008 6433
 				$value=dol_print_date($value,'day');
6009 6434
 			} else {
6010 6435
 				$value='';
6011 6436
 			}
6012
-		}
6013
-		elseif ($type == 'datetime')
6437
+		} elseif ($type == 'datetime')
6014 6438
 		{
6015 6439
 			if(! empty($value)) {
6016 6440
 				$value=dol_print_date($value,'dayhour');
6017 6441
 			} else {
6018 6442
 				$value='';
6019 6443
 			}
6020
-		}
6021
-		elseif ($type == 'double')
6444
+		} elseif ($type == 'double')
6022 6445
 		{
6023 6446
 			if (!empty($value)) {
6024 6447
 				$value=price($value);
6025 6448
 			}
6026
-		}
6027
-		elseif ($type == 'boolean')
6449
+		} elseif ($type == 'boolean')
6028 6450
 		{
6029 6451
 			$checked='';
6030 6452
 			if (!empty($value)) {
6031 6453
 				$checked=' checked ';
6032 6454
 			}
6033 6455
 			$value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>';
6034
-		}
6035
-		elseif ($type == 'mail')
6456
+		} elseif ($type == 'mail')
6036 6457
 		{
6037 6458
 			$value=dol_print_email($value,0,0,0,64,1,1);
6038
-		}
6039
-		elseif ($type == 'url')
6459
+		} elseif ($type == 'url')
6040 6460
 		{
6041 6461
 			$value=dol_print_url($value,'_blank',32,1);
6042
-		}
6043
-		elseif ($type == 'phone')
6462
+		} elseif ($type == 'phone')
6044 6463
 		{
6045 6464
 			$value=dol_print_phone($value, '', 0, 0, '', '&nbsp;', 1);
6046
-		}
6047
-		elseif ($type == 'price')
6465
+		} elseif ($type == 'price')
6048 6466
 		{
6049 6467
 			$value=price($value,0,$langs,0,0,-1,$conf->currency);
6050
-		}
6051
-		elseif ($type == 'select')
6468
+		} elseif ($type == 'select')
6052 6469
 		{
6053 6470
 			$value=$param['options'][$value];
6054
-		}
6055
-		elseif ($type == 'sellist')
6471
+		} elseif ($type == 'sellist')
6056 6472
 		{
6057 6473
 			$param_list=array_keys($param['options']);
6058 6474
 			$InfoFieldList = explode(":", $param_list[0]);
@@ -6082,7 +6498,7 @@  discard block
 block discarded – undo
6082 6498
 				$sql.= " WHERE ".$selectkey."=0";
6083 6499
 			} elseif ($selectkey=='rowid') {
6084 6500
 				$sql.= " WHERE ".$selectkey."=".$this->db->escape($value);
6085
-			}else {
6501
+			} else {
6086 6502
 				$sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'";
6087 6503
 			}
6088 6504
 
@@ -6109,12 +6525,11 @@  discard block
 block discarded – undo
6109 6525
 						}
6110 6526
 						if ($translabel!=$field_toshow) {
6111 6527
 							$value.=dol_trunc($translabel,18).' ';
6112
-						}else {
6528
+						} else {
6113 6529
 							$value.=$obj->$field_toshow.' ';
6114 6530
 						}
6115 6531
 					}
6116
-				}
6117
-				else
6532
+				} else
6118 6533
 				{
6119 6534
 					$translabel='';
6120 6535
 					if (!empty($obj->{$InfoFieldList[1]})) {
@@ -6122,18 +6537,17 @@  discard block
 block discarded – undo
6122 6537
 					}
6123 6538
 					if ($translabel!=$obj->{$InfoFieldList[1]}) {
6124 6539
 						$value=dol_trunc($translabel,18);
6125
-					}else {
6540
+					} else {
6126 6541
 						$value=$obj->{$InfoFieldList[1]};
6127 6542
 					}
6128 6543
 				}
6544
+			} else {
6545
+			    dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
6129 6546
 			}
6130
-			else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
6131
-		}
6132
-		elseif ($type == 'radio')
6547
+		} elseif ($type == 'radio')
6133 6548
 		{
6134 6549
 			$value=$param['options'][$value];
6135
-		}
6136
-		elseif ($type == 'checkbox')
6550
+		} elseif ($type == 'checkbox')
6137 6551
 		{
6138 6552
 			$value_arr=explode(',',$value);
6139 6553
 			$value='';
@@ -6144,8 +6558,7 @@  discard block
 block discarded – undo
6144 6558
 				}
6145 6559
 				$value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
6146 6560
 			}
6147
-		}
6148
-		elseif ($type == 'chkbxlst')
6561
+		} elseif ($type == 'chkbxlst')
6149 6562
 		{
6150 6563
 			$value_arr = explode(',', $value);
6151 6564
 
@@ -6213,8 +6626,7 @@  discard block
 block discarded – undo
6213 6626
 			} else {
6214 6627
 				dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING);
6215 6628
 			}
6216
-		}
6217
-		elseif ($type == 'link')
6629
+		} elseif ($type == 'link')
6218 6630
 		{
6219 6631
 			$out='';
6220 6632
 
@@ -6236,24 +6648,21 @@  discard block
 block discarded – undo
6236 6648
 						$object->fetch($value);
6237 6649
 						$value=$object->getNomUrl($getnomurlparam);
6238 6650
 					}
6239
-				}
6240
-				else
6651
+				} else
6241 6652
 				{
6242 6653
 					dol_syslog('Error bad setup of extrafield', LOG_WARNING);
6243 6654
 					return 'Error bad setup of extrafield';
6244 6655
 				}
6656
+			} else {
6657
+			    $value='';
6245 6658
 			}
6246
-			else $value='';
6247
-		}
6248
-		elseif ($type == 'text' || $type == 'html')
6659
+		} elseif ($type == 'text' || $type == 'html')
6249 6660
 		{
6250 6661
 			$value=dol_htmlentitiesbr($value);
6251
-		}
6252
-		elseif ($type == 'password')
6662
+		} elseif ($type == 'password')
6253 6663
 		{
6254 6664
 			$value=preg_replace('/./i','*',$value);
6255
-		}
6256
-		elseif ($type == 'array')
6665
+		} elseif ($type == 'array')
6257 6666
 		{
6258 6667
 			$value = implode('<br>', $value);
6259 6668
 		}
@@ -6280,7 +6689,9 @@  discard block
 block discarded – undo
6280 6689
 	{
6281 6690
 		global $db, $conf, $langs, $action, $form;
6282 6691
 
6283
-		if (! is_object($form)) $form=new Form($db);
6692
+		if (! is_object($form)) {
6693
+		    $form=new Form($db);
6694
+		}
6284 6695
 
6285 6696
 		$out = '';
6286 6697
 
@@ -6294,7 +6705,9 @@  discard block
 block discarded – undo
6294 6705
 			foreach($extrafields->attributes[$this->table_element]['label'] as $key=>$label)
6295 6706
 			{
6296 6707
 				// Show only the key field in params
6297
-				if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) continue;
6708
+				if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) {
6709
+				    continue;
6710
+				}
6298 6711
 
6299 6712
 				$enabled = 1;
6300 6713
 				if ($enabled && isset($extrafields->attributes[$this->table_element]['list'][$key]))
@@ -6308,11 +6721,18 @@  discard block
 block discarded – undo
6308 6721
 					$perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1);
6309 6722
 				}
6310 6723
 
6311
-				if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) continue;	// <> -1 and <> 1 and <> 3 = not visible on forms, only on list
6312
-				if (empty($perms)) continue;
6724
+				if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) {
6725
+				    continue;
6726
+				}
6727
+				// <> -1 and <> 1 and <> 3 = not visible on forms, only on list
6728
+				if (empty($perms)) {
6729
+				    continue;
6730
+				}
6313 6731
 
6314 6732
 				// Load language if required
6315
-				if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]);
6733
+				if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) {
6734
+				    $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]);
6735
+				}
6316 6736
 
6317 6737
 				$colspan='3';
6318 6738
 				if (is_array($params) && count($params)>0) {
@@ -6346,8 +6766,7 @@  discard block
 block discarded – undo
6346 6766
 				if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate')
6347 6767
 				{
6348 6768
 					$out .= $extrafields->showSeparator($key, $this);
6349
-				}
6350
-				else
6769
+				} else
6351 6770
 				{
6352 6771
 					$csstyle='';
6353 6772
 					$class=(!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : '');
@@ -6377,10 +6796,12 @@  discard block
 block discarded – undo
6377 6796
 					if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('date','datetime')))
6378 6797
 					{
6379 6798
 						$datenotinstring = $this->array_options['options_' . $key];
6380
-						if (! is_numeric($this->array_options['options_' . $key]))	// For backward compatibility
6799
+						if (! is_numeric($this->array_options['options_' . $key])) {
6800
+						    // For backward compatibility
6381 6801
 						{
6382 6802
 							$datenotinstring = $this->db->jdate($datenotinstring);
6383 6803
 						}
6804
+						}
6384 6805
 						$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;
6385 6806
 					}
6386 6807
 					// Convert float submited string into real php numeric (value in memory must be a php numeric)
@@ -6392,11 +6813,18 @@  discard block
 block discarded – undo
6392 6813
 					$labeltoshow = $langs->trans($label);
6393 6814
 
6394 6815
 					$out .= '<td class="titlefield';
6395
-					if (GETPOST('action','none') == 'create') $out.='create';
6396
-					if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired';
6816
+					if (GETPOST('action','none') == 'create') {
6817
+					    $out.='create';
6818
+					}
6819
+					if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) {
6820
+					    $out .= ' fieldrequired';
6821
+					}
6397 6822
 					$out .= '">';
6398
-					if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]);
6399
-					else $out .= $labeltoshow;
6823
+					if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) {
6824
+					    $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]);
6825
+					} else {
6826
+					    $out .= $labeltoshow;
6827
+					}
6400 6828
 					$out .= '</td>';
6401 6829
 
6402 6830
 					$html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : '';
@@ -6413,8 +6841,11 @@  discard block
 block discarded – undo
6413 6841
 
6414 6842
 					$out .= '</td>';
6415 6843
 
6416
-					if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>';
6417
-					else $out .= '</tr>';
6844
+					if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) {
6845
+					    $out .= '</tr>';
6846
+					} else {
6847
+					    $out .= '</tr>';
6848
+					}
6418 6849
 					$e++;
6419 6850
 				}
6420 6851
 			}
@@ -6466,7 +6897,9 @@  discard block
 block discarded – undo
6466 6897
 		global $user;
6467 6898
 
6468 6899
 		$element = $this->element;
6469
-		if ($element == 'facturerec') $element='facture';
6900
+		if ($element == 'facturerec') {
6901
+		    $element='facture';
6902
+		}
6470 6903
 
6471 6904
 		return $user->rights->{$element};
6472 6905
 	}
@@ -6491,7 +6924,10 @@  discard block
 block discarded – undo
6491 6924
 
6492 6925
 			if (! $db->query($sql))
6493 6926
 			{
6494
-				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.
6927
+				if ($ignoreerrors) {
6928
+				    return true;
6929
+				}
6930
+				// 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.
6495 6931
 				//$this->errors = $db->lasterror();
6496 6932
 				return false;
6497 6933
 			}
@@ -6518,11 +6954,12 @@  discard block
 block discarded – undo
6518 6954
 
6519 6955
 		$buyPrice = 0;
6520 6956
 
6521
-		if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) // In most cases, test here is false
6957
+		if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) {
6958
+		    // In most cases, test here is false
6522 6959
 		{
6523 6960
 			$buyPrice = $unitPrice * (1 - $discountPercent / 100);
6524 6961
 		}
6525
-		else
6962
+		} else
6526 6963
 		{
6527 6964
 			// Get cost price for margin calculation
6528 6965
 			if (! empty($fk_product))
@@ -6540,13 +6977,11 @@  discard block
 block discarded – undo
6540 6977
 					if ($product->cost_price > 0)
6541 6978
 					{
6542 6979
 						$buyPrice = $product->cost_price;
6543
-					}
6544
-					else if ($product->pmp > 0)
6980
+					} else if ($product->pmp > 0)
6545 6981
 					{
6546 6982
 						$buyPrice = $product->pmp;
6547 6983
 					}
6548
-				}
6549
-				else if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp')
6984
+				} else if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp')
6550 6985
 				{
6551 6986
 					require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
6552 6987
 					$product = new Product($this->db);
@@ -6569,8 +7004,7 @@  discard block
 block discarded – undo
6569 7004
 					if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0)
6570 7005
 					{
6571 7006
 						$buyPrice = $productFournisseur->fourn_unitprice;
6572
-					}
6573
-					else if ($result < 0)
7007
+					} else if ($result < 0)
6574 7008
 					{
6575 7009
 						$this->errors[] = $productFournisseur->error;
6576 7010
 						return -2;
@@ -6616,8 +7050,7 @@  discard block
 block discarded – undo
6616 7050
 		{
6617 7051
 			$dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/';
6618 7052
 			$pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/';
6619
-		}
6620
-		else
7053
+		} else
6621 7054
 		{
6622 7055
 			$dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/';
6623 7056
 			$pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/';
@@ -6680,19 +7113,26 @@  discard block
 block discarded – undo
6680 7113
 
6681 7114
 						// Find name of thumb file
6682 7115
 						$photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small'));
6683
-						if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette='';
7116
+						if (! dol_is_file($dirthumb.$photo_vignette)) {
7117
+						    $photo_vignette='';
7118
+						}
6684 7119
 
6685 7120
 						// Get filesize of original file
6686 7121
 						$imgarray=dol_getImageSize($dir.$photo);
6687 7122
 
6688 7123
 						if ($nbbyrow > 0)
6689 7124
 						{
6690
-							if ($nbphoto == 1) $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';
7125
+							if ($nbphoto == 1) {
7126
+							    $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';
7127
+							}
6691 7128
 
6692
-							if ($nbphoto % $nbbyrow == 1) $return.= '<tr align=center valign=middle border=1>';
7129
+							if ($nbphoto % $nbbyrow == 1) {
7130
+							    $return.= '<tr align=center valign=middle border=1>';
7131
+							}
6693 7132
 							$return.= '<td width="'.ceil(100/$nbbyrow).'%" class="photo">';
7133
+						} else if ($nbbyrow < 0) {
7134
+						    $return .= '<div class="inline-block">';
6694 7135
 						}
6695
-						else if ($nbbyrow < 0) $return .= '<div class="inline-block">';
6696 7136
 
6697 7137
 						$return.= "\n";
6698 7138
 
@@ -6700,15 +7140,20 @@  discard block
 block discarded – undo
6700 7140
 						if (empty($nolink))
6701 7141
 						{
6702 7142
 							$urladvanced=getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity='.$this->entity);
6703
-							if ($urladvanced) $return.='<a href="'.$urladvanced.'">';
6704
-							else $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">';
7143
+							if ($urladvanced) {
7144
+							    $return.='<a href="'.$urladvanced.'">';
7145
+							} else {
7146
+							    $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">';
7147
+							}
6705 7148
 						}
6706 7149
 
6707 7150
 						// Show image (width height=$maxHeight)
6708 7151
 						// Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine
6709 7152
 						$alt=$langs->transnoentitiesnoconv('File').': '.$relativefile;
6710 7153
 						$alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height'];
6711
-						if ($notitle) $alt='';
7154
+						if ($notitle) {
7155
+						    $alt='';
7156
+						}
6712 7157
 
6713 7158
 						if ($usesharelink)
6714 7159
 						{
@@ -6718,35 +7163,35 @@  discard block
 block discarded – undo
6718 7163
 								{
6719 7164
 									$return.= '<!-- Show original file (thumb not yet available with shared links) -->';
6720 7165
 									$return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">';
6721
-								}
6722
-								else {
7166
+								} else {
6723 7167
 									$return.= '<!-- Show original file -->';
6724 7168
 									$return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">';
6725 7169
 								}
6726
-							}
6727
-							else
7170
+							} else
6728 7171
 							{
6729 7172
 								$return.= '<!-- Show nophoto file (because file is not shared) -->';
6730 7173
 								$return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">';
6731 7174
 							}
6732
-						}
6733
-						else
7175
+						} else
6734 7176
 						{
6735 7177
 							if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight)
6736 7178
 							{
6737 7179
 								$return.= '<!-- Show thumb -->';
6738 7180
 								$return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdirthumb.$photo_vignette).'" title="'.dol_escape_htmltag($alt).'">';
6739
-							}
6740
-							else {
7181
+							} else {
6741 7182
 								$return.= '<!-- Show original file -->';
6742 7183
 								$return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" title="'.dol_escape_htmltag($alt).'">';
6743 7184
 							}
6744 7185
 						}
6745 7186
 
6746
-						if (empty($nolink)) $return.= '</a>';
7187
+						if (empty($nolink)) {
7188
+						    $return.= '</a>';
7189
+						}
6747 7190
 						$return.="\n";
6748 7191
 
6749
-						if ($showfilename) $return.= '<br>'.$viewfilename;
7192
+						if ($showfilename) {
7193
+						    $return.= '<br>'.$viewfilename;
7194
+						}
6750 7195
 						if ($showaction)
6751 7196
 						{
6752 7197
 							$return.= '<br>';
@@ -6771,15 +7216,20 @@  discard block
 block discarded – undo
6771 7216
 						if ($nbbyrow > 0)
6772 7217
 						{
6773 7218
 							$return.= '</td>';
6774
-							if (($nbphoto % $nbbyrow) == 0) $return.= '</tr>';
7219
+							if (($nbphoto % $nbbyrow) == 0) {
7220
+							    $return.= '</tr>';
7221
+							}
7222
+						} else if ($nbbyrow < 0) {
7223
+						    $return.='</div>';
6775 7224
 						}
6776
-						else if ($nbbyrow < 0) $return.='</div>';
6777 7225
 					}
6778 7226
 
6779 7227
 					if (empty($size)) {     // Format origine
6780 7228
 						$return.= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">';
6781 7229
 
6782
-						if ($showfilename) $return.= '<br>'.$viewfilename;
7230
+						if ($showfilename) {
7231
+						    $return.= '<br>'.$viewfilename;
7232
+						}
6783 7233
 						if ($showaction)
6784 7234
 						{
6785 7235
 							// Special case for product
@@ -6796,7 +7246,9 @@  discard block
 block discarded – undo
6796 7246
 					}
6797 7247
 
6798 7248
 					// On continue ou on arrete de boucler ?
6799
-					if ($nbmax && $nbphoto >= $nbmax) break;
7249
+					if ($nbmax && $nbphoto >= $nbmax) {
7250
+					    break;
7251
+					}
6800 7252
 				}
6801 7253
 			}
6802 7254
 
@@ -6811,7 +7263,9 @@  discard block
 block discarded – undo
6811 7263
 						$nbphoto++;
6812 7264
 					}
6813 7265
 
6814
-					if ($nbphoto) $return.= '</table>';
7266
+					if ($nbphoto) {
7267
+					    $return.= '</table>';
7268
+					}
6815 7269
 				}
6816 7270
 			}
6817 7271
 		}
@@ -6832,10 +7286,14 @@  discard block
 block discarded – undo
6832 7286
 	{
6833 7287
 		if(is_array($info))
6834 7288
 		{
6835
-			if(isset($info['type']) && $info['type']=='array') return true;
6836
-			else return false;
7289
+			if(isset($info['type']) && $info['type']=='array') {
7290
+			    return true;
7291
+			} else {
7292
+			    return false;
7293
+			}
7294
+		} else {
7295
+		    return false;
6837 7296
 		}
6838
-		else return false;
6839 7297
 	}
6840 7298
 
6841 7299
 	/**
@@ -6848,10 +7306,14 @@  discard block
 block discarded – undo
6848 7306
 	{
6849 7307
 		if(is_array($info))
6850 7308
 		{
6851
-			if(isset($info['type']) && $info['type']=='null') return true;
6852
-			else return false;
7309
+			if(isset($info['type']) && $info['type']=='null') {
7310
+			    return true;
7311
+			} else {
7312
+			    return false;
7313
+			}
7314
+		} else {
7315
+		    return false;
6853 7316
 		}
6854
-		else return false;
6855 7317
 	}
6856 7318
 
6857 7319
 	/**
@@ -6862,8 +7324,11 @@  discard block
 block discarded – undo
6862 7324
 	 */
6863 7325
 	public function isDate($info)
6864 7326
 	{
6865
-		if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true;
6866
-		else return false;
7327
+		if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) {
7328
+		    return true;
7329
+		} else {
7330
+		    return false;
7331
+		}
6867 7332
 	}
6868 7333
 
6869 7334
 	/**
@@ -6876,10 +7341,14 @@  discard block
 block discarded – undo
6876 7341
 	{
6877 7342
 		if(is_array($info))
6878 7343
 		{
6879
-			if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) return true;
6880
-			else return false;
7344
+			if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) {
7345
+			    return true;
7346
+			} else {
7347
+			    return false;
7348
+			}
7349
+		} else {
7350
+		    return false;
6881 7351
 		}
6882
-		else return false;
6883 7352
 	}
6884 7353
 
6885 7354
 	/**
@@ -6892,10 +7361,14 @@  discard block
 block discarded – undo
6892 7361
 	{
6893 7362
 		if(is_array($info))
6894 7363
 		{
6895
-			if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) return true;
6896
-			else return false;
7364
+			if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) {
7365
+			    return true;
7366
+			} else {
7367
+			    return false;
7368
+			}
7369
+		} else {
7370
+		    return false;
6897 7371
 		}
6898
-		else return false;
6899 7372
 	}
6900 7373
 
6901 7374
 	/**
@@ -6908,10 +7381,14 @@  discard block
 block discarded – undo
6908 7381
 	{
6909 7382
 		if(is_array($info))
6910 7383
 		{
6911
-			if(isset($info['type']) && $info['type']=='text') return true;
6912
-			else return false;
7384
+			if(isset($info['type']) && $info['type']=='text') {
7385
+			    return true;
7386
+			} else {
7387
+			    return false;
7388
+			}
7389
+		} else {
7390
+		    return false;
6913 7391
 		}
6914
-		else return false;
6915 7392
 	}
6916 7393
 
6917 7394
 	/**
@@ -6924,10 +7401,14 @@  discard block
 block discarded – undo
6924 7401
 	{
6925 7402
 		if(is_array($info))
6926 7403
 		{
6927
-			if(isset($info['index']) && $info['index']==true) return true;
6928
-			else return false;
7404
+			if(isset($info['index']) && $info['index']==true) {
7405
+			    return true;
7406
+			} else {
7407
+			    return false;
7408
+			}
7409
+		} else {
7410
+		    return false;
6929 7411
 		}
6930
-		else return false;
6931 7412
 	}
6932 7413
 
6933 7414
 	/**
@@ -6941,7 +7422,8 @@  discard block
 block discarded – undo
6941 7422
 		global $conf;
6942 7423
 
6943 7424
 		$queryarray=array();
6944
-		foreach ($this->fields as $field=>$info)	// Loop on definition of fields
7425
+		foreach ($this->fields as $field=>$info) {
7426
+		    // Loop on definition of fields
6945 7427
 		{
6946 7428
 			// Depending on field type ('datetime', ...)
6947 7429
 			if($this->isDate($info))
@@ -6949,13 +7431,12 @@  discard block
 block discarded – undo
6949 7431
 				if(empty($this->{$field}))
6950 7432
 				{
6951 7433
 					$queryarray[$field] = null;
6952
-				}
6953
-				else
7434
+		}
7435
+				} else
6954 7436
 				{
6955 7437
 					$queryarray[$field] = $this->db->idate($this->{$field});
6956 7438
 				}
6957
-			}
6958
-			else if($this->isArray($info))
7439
+			} else if($this->isArray($info))
6959 7440
 			{
6960 7441
 				if(! empty($this->{$field})) {
6961 7442
 					if(! is_array($this->{$field})) {
@@ -6965,28 +7446,35 @@  discard block
 block discarded – undo
6965 7446
 				} else {
6966 7447
 					$queryarray[$field] = null;
6967 7448
 				}
6968
-			}
6969
-			else if($this->isInt($info))
7449
+			} else if($this->isInt($info))
6970 7450
 			{
6971
-				if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field]=$conf->entity;
6972
-				else
7451
+				if ($field == 'entity' && is_null($this->{$field})) {
7452
+				    $queryarray[$field]=$conf->entity;
7453
+				} else
6973 7454
 				{
6974 7455
 					$queryarray[$field] = (int) price2num($this->{$field});
6975
-					if (empty($queryarray[$field])) $queryarray[$field]=0;		// May be reset to null later if property 'notnull' is -1 for this field.
7456
+					if (empty($queryarray[$field])) {
7457
+					    $queryarray[$field]=0;
7458
+					}
7459
+					// May be reset to null later if property 'notnull' is -1 for this field.
6976 7460
 				}
6977
-			}
6978
-			else if($this->isFloat($info))
7461
+			} else if($this->isFloat($info))
6979 7462
 			{
6980 7463
 				$queryarray[$field] = (double) price2num($this->{$field});
6981
-				if (empty($queryarray[$field])) $queryarray[$field]=0;
6982
-			}
6983
-			else
7464
+				if (empty($queryarray[$field])) {
7465
+				    $queryarray[$field]=0;
7466
+				}
7467
+			} else
6984 7468
 			{
6985 7469
 				$queryarray[$field] = $this->{$field};
6986 7470
 			}
6987 7471
 
6988
-			if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]);
6989
-			if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null;
7472
+			if ($info['type'] == 'timestamp' && empty($queryarray[$field])) {
7473
+			    unset($queryarray[$field]);
7474
+			}
7475
+			if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) {
7476
+			    $queryarray[$field] = null;
7477
+			}
6990 7478
 		}
6991 7479
 
6992 7480
 		return $queryarray;
@@ -7004,42 +7492,47 @@  discard block
 block discarded – undo
7004 7492
 		{
7005 7493
 			if($this->isDate($info))
7006 7494
 			{
7007
-				if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0;
7008
-				else $this->{$field} = strtotime($obj->{$field});
7009
-			}
7010
-			elseif($this->isArray($info))
7495
+				if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') {
7496
+				    $this->{$field} = 0;
7497
+				} else {
7498
+				    $this->{$field} = strtotime($obj->{$field});
7499
+				}
7500
+			} elseif($this->isArray($info))
7011 7501
 			{
7012 7502
 				if(! empty($obj->{$field})) {
7013 7503
 					$this->{$field} = @unserialize($obj->{$field});
7014 7504
 					// Hack for data not in UTF8
7015
-					if($this->{$field } === false) @unserialize(utf8_decode($obj->{$field}));
7505
+					if($this->{$field } === false) {
7506
+					    @unserialize(utf8_decode($obj->{$field}));
7507
+					}
7016 7508
 				} else {
7017 7509
 					$this->{$field} = array();
7018 7510
 				}
7019
-			}
7020
-			elseif($this->isInt($info))
7511
+			} elseif($this->isInt($info))
7021 7512
 			{
7022
-				if ($field == 'rowid') $this->id = (int) $obj->{$field};
7023
-				else $this->{$field} = (int) $obj->{$field};
7024
-			}
7025
-			elseif($this->isFloat($info))
7513
+				if ($field == 'rowid') {
7514
+				    $this->id = (int) $obj->{$field};
7515
+				} else {
7516
+				    $this->{$field} = (int) $obj->{$field};
7517
+				}
7518
+			} elseif($this->isFloat($info))
7026 7519
 			{
7027 7520
 				$this->{$field} = (double) $obj->{$field};
7028
-			}
7029
-			elseif($this->isNull($info))
7521
+			} elseif($this->isNull($info))
7030 7522
 			{
7031 7523
 				$val = $obj->{$field};
7032 7524
 				// zero is not null
7033 7525
 				$this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val);
7034
-			}
7035
-			else
7526
+			} else
7036 7527
 			{
7037 7528
 				$this->{$field} = $obj->{$field};
7038 7529
 			}
7039 7530
 		}
7040 7531
 
7041 7532
 		// If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions.
7042
-		if (! isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id;
7533
+		if (! isset($this->fields['ref']) && isset($this->id)) {
7534
+		    $this->ref = $this->id;
7535
+		}
7043 7536
 	}
7044 7537
 
7045 7538
 	/**
@@ -7062,9 +7555,13 @@  discard block
 block discarded – undo
7062 7555
 	 */
7063 7556
     protected function quote($value, $fieldsentry)
7064 7557
     {
7065
-		if (is_null($value)) return 'NULL';
7066
-		else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) return $this->db->escape("$value");
7067
-		else return "'".$this->db->escape($value)."'";
7558
+		if (is_null($value)) {
7559
+		    return 'NULL';
7560
+		} else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) {
7561
+		    return $this->db->escape("$value");
7562
+		} else {
7563
+		    return "'".$this->db->escape($value)."'";
7564
+		}
7068 7565
 	}
7069 7566
 
7070 7567
 
@@ -7084,8 +7581,12 @@  discard block
 block discarded – undo
7084 7581
 		$now=dol_now();
7085 7582
 
7086 7583
 		$fieldvalues = $this->setSaveQuery();
7087
-		if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now);
7088
-		if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id;
7584
+		if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) {
7585
+		    $fieldvalues['date_creation']=$this->db->idate($now);
7586
+		}
7587
+		if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) {
7588
+		    $fieldvalues['fk_user_creat']=$user->id;
7589
+		}
7089 7590
 		unset($fieldvalues['rowid']);	// The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert.
7090 7591
 
7091 7592
 		$keys=array();
@@ -7100,8 +7601,12 @@  discard block
 block discarded – undo
7100 7601
 		foreach($keys as $key)
7101 7602
 		{
7102 7603
 			// If field is an implicit foreign key field
7103
-			if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]='';
7104
-			if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]='';
7604
+			if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') {
7605
+			    $values[$key]='';
7606
+			}
7607
+			if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') {
7608
+			    $values[$key]='';
7609
+			}
7105 7610
 
7106 7611
 			//var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1));
7107 7612
 			if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && ! isset($values[$key]) && is_null($val['default']))
@@ -7111,11 +7616,17 @@  discard block
 block discarded – undo
7111 7616
 			}
7112 7617
 
7113 7618
 			// If field is an implicit foreign key field
7114
-			if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key]='null';
7115
-			if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key]='null';
7619
+			if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) {
7620
+			    $values[$key]='null';
7621
+			}
7622
+			if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) {
7623
+			    $values[$key]='null';
7624
+			}
7116 7625
 		}
7117 7626
 
7118
-		if ($error) return -1;
7627
+		if ($error) {
7628
+		    return -1;
7629
+		}
7119 7630
 
7120 7631
 		$this->db->begin();
7121 7632
 
@@ -7141,7 +7652,9 @@  discard block
 block discarded – undo
7141 7652
 		if (! $error)
7142 7653
 		{
7143 7654
 			$result=$this->insertExtraFields();
7144
-			if ($result < 0) $error++;
7655
+			if ($result < 0) {
7656
+			    $error++;
7657
+			}
7145 7658
 		}
7146 7659
 
7147 7660
 		// Triggers
@@ -7174,15 +7687,24 @@  discard block
 block discarded – undo
7174 7687
 	 */
7175 7688
 	public function fetchCommon($id, $ref = null, $morewhere = '')
7176 7689
 	{
7177
-		if (empty($id) && empty($ref) && empty($morewhere)) return -1;
7690
+		if (empty($id) && empty($ref) && empty($morewhere)) {
7691
+		    return -1;
7692
+		}
7178 7693
 
7179 7694
 		$sql = 'SELECT '.$this->getFieldList();
7180 7695
 		$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
7181 7696
 
7182
-		if (!empty($id))  $sql.= ' WHERE rowid = '.$id;
7183
-		elseif (!empty($ref)) $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']);
7184
-		else $sql.=' WHERE 1 = 1';	// usage with empty id and empty ref is very rare
7185
-		if ($morewhere)   $sql.= $morewhere;
7697
+		if (!empty($id)) {
7698
+		    $sql.= ' WHERE rowid = '.$id;
7699
+		} elseif (!empty($ref)) {
7700
+		    $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']);
7701
+		} else {
7702
+		    $sql.=' WHERE 1 = 1';
7703
+		}
7704
+		// usage with empty id and empty ref is very rare
7705
+		if ($morewhere) {
7706
+		    $sql.= $morewhere;
7707
+		}
7186 7708
 		$sql.=' LIMIT 1';	// This is a fetch, to be sure to get only one record
7187 7709
 
7188 7710
 		$res = $this->db->query($sql);
@@ -7193,13 +7715,11 @@  discard block
 block discarded – undo
7193 7715
 			{
7194 7716
 				$this->setVarsFromFetchObj($obj);
7195 7717
 				return $this->id;
7196
-			}
7197
-			else
7718
+			} else
7198 7719
 			{
7199 7720
 				return 0;
7200 7721
 			}
7201
-		}
7202
-		else
7722
+		} else
7203 7723
 		{
7204 7724
 			$this->error = $this->db->lasterror();
7205 7725
 			$this->errors[] = $this->error;
@@ -7223,8 +7743,12 @@  discard block
 block discarded – undo
7223 7743
 		$now=dol_now();
7224 7744
 
7225 7745
 		$fieldvalues = $this->setSaveQuery();
7226
-		if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification']=$this->db->idate($now);
7227
-		if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif']=$user->id;
7746
+		if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) {
7747
+		    $fieldvalues['date_modification']=$this->db->idate($now);
7748
+		}
7749
+		if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) {
7750
+		    $fieldvalues['fk_user_modif']=$user->id;
7751
+		}
7228 7752
 		unset($fieldvalues['rowid']);	// The field 'rowid' is reserved field name for autoincrement field so we don't need it into update.
7229 7753
 
7230 7754
 		$keys=array();
@@ -7239,8 +7763,14 @@  discard block
 block discarded – undo
7239 7763
 		// Clean and check mandatory
7240 7764
 		foreach($keys as $key)
7241 7765
 		{
7242
-			if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]='';		// This is an implicit foreign key field
7243
-			if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]='';					// This is an explicit foreign key field
7766
+			if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') {
7767
+			    $values[$key]='';
7768
+			}
7769
+			// This is an implicit foreign key field
7770
+			if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') {
7771
+			    $values[$key]='';
7772
+			}
7773
+			// This is an explicit foreign key field
7244 7774
 
7245 7775
 			//var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1));
7246 7776
 			/*
@@ -7321,10 +7851,11 @@  discard block
 block discarded – undo
7321 7851
 					return -1;
7322 7852
 				}
7323 7853
 			}
7324
-		}
7325
-		elseif (! empty($this->fk_element) && ! empty($this->childtables))	// If object has childs linked with a foreign key field, we check all child tables.
7854
+		} elseif (! empty($this->fk_element) && ! empty($this->childtables)) {
7855
+		    // If object has childs linked with a foreign key field, we check all child tables.
7326 7856
 		{
7327 7857
 			$objectisused = $this->isObjectUsed($this->id);
7858
+		}
7328 7859
 			if (! empty($objectisused))
7329 7860
 			{
7330 7861
 				dol_syslog(get_class($this)."::deleteCommon Can't delete record as it has some child", LOG_WARNING);
@@ -7431,7 +7962,9 @@  discard block
 block discarded – undo
7431 7962
      */
7432 7963
     public function trimParameters($parameters)
7433 7964
     {
7434
-        if (!is_array($parameters)) return;
7965
+        if (!is_array($parameters)) {
7966
+            return;
7967
+        }
7435 7968
         foreach ($parameters as $parameter) {
7436 7969
             if (isset($this->$parameter)) {
7437 7970
                 $this->$parameter = trim($this->$parameter);
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/dolgraph.class.php 1 patch
Braces   +143 added lines, -59 removed lines patch added patch discarded remove patch
@@ -103,7 +103,9 @@  discard block
 block discarded – undo
103 103
 			$isgdinstalled=0;
104 104
 			foreach ($modules_list as $module)
105 105
 			{
106
-				if ($module == 'gd') $isgdinstalled=1;
106
+				if ($module == 'gd') {
107
+				    $isgdinstalled=1;
108
+				}
107 109
 			}
108 110
 			if (! $isgdinstalled)
109 111
 			{
@@ -120,9 +122,15 @@  discard block
 block discarded – undo
120 122
 		if (is_readable($color_file))
121 123
 		{
122 124
 			include_once $color_file;
123
-			if (isset($theme_bordercolor)) $this->bordercolor = $theme_bordercolor;
124
-			if (isset($theme_datacolor))   $this->datacolor   = $theme_datacolor;
125
-			if (isset($theme_bgcolor))     $this->bgcolor     = $theme_bgcolor;
125
+			if (isset($theme_bordercolor)) {
126
+			    $this->bordercolor = $theme_bordercolor;
127
+			}
128
+			if (isset($theme_datacolor)) {
129
+			    $this->datacolor   = $theme_datacolor;
130
+			}
131
+			if (isset($theme_bgcolor)) {
132
+			    $this->bgcolor     = $theme_bgcolor;
133
+			}
126 134
 		}
127 135
 		//print 'bgcolor: '.join(',',$this->bgcolor).'<br>';
128 136
 	}
@@ -493,13 +501,11 @@  discard block
 block discarded – undo
493 501
 			{
494 502
 				//print 'ee'.join(',',$theme_bgcoloronglet);
495 503
 				$this->bgcolor = $theme_bgcoloronglet;
496
-			}
497
-			else
504
+			} else
498 505
 			{
499 506
 				$this->bgcolor = $theme_bgcolor;
500 507
 			}
501
-		}
502
-		else
508
+		} else
503 509
 		{
504 510
 			$this->bgcolor = $bg_color;
505 511
 		}
@@ -523,13 +529,11 @@  discard block
 block discarded – undo
523 529
 			{
524 530
 				//print 'ee'.join(',',$theme_bgcoloronglet);
525 531
 				$this->bgcolorgrid = $theme_bgcoloronglet;
526
-			}
527
-			else
532
+			} else
528 533
 			{
529 534
 				$this->bgcolorgrid = $theme_bgcolor;
530 535
 			}
531
-		}
532
-		else
536
+		} else
533 537
 		{
534 538
 			$this->bgcolorgrid = $bg_colorgrid;
535 539
 		}
@@ -611,7 +615,9 @@  discard block
 block discarded – undo
611 615
 	{
612 616
         // phpcs:enable
613 617
 		$max = $this->GetMaxValueInData();
614
-		if ($max != 0) $max++;
618
+		if ($max != 0) {
619
+		    $max++;
620
+		}
615 621
 		$size=dol_strlen(abs(ceil($max)));
616 622
 		$factor=1;
617 623
 		for ($i=0; $i < ($size-1); $i++)
@@ -620,7 +626,9 @@  discard block
 block discarded – undo
620 626
 		}
621 627
 
622 628
 		$res=0;
623
-		if (is_numeric($max)) $res=ceil($max/$factor)*$factor;
629
+		if (is_numeric($max)) {
630
+		    $res=ceil($max/$factor)*$factor;
631
+		}
624 632
 
625 633
 		//print "max=".$max." res=".$res;
626 634
 		return $res;
@@ -636,8 +644,12 @@  discard block
 block discarded – undo
636 644
 	{
637 645
         // phpcs:enable
638 646
 		$min = $this->GetMinValueInData();
639
-		if ($min == '') $min=0;
640
-		if ($min != 0) $min--;
647
+		if ($min == '') {
648
+		    $min=0;
649
+		}
650
+		if ($min != 0) {
651
+		    $min--;
652
+		}
641 653
 		$size=dol_strlen(abs(floor($min)));
642 654
 		$factor=1;
643 655
 		for ($i=0; $i < ($size-1); $i++)
@@ -697,15 +709,27 @@  discard block
 block discarded – undo
697 709
 
698 710
 		dol_syslog(get_class($this)."::draw_artichow this->type=".join(',',$this->type));
699 711
 
700
-		if (! defined('SHADOW_RIGHT_TOP'))  define('SHADOW_RIGHT_TOP',3);
701
-		if (! defined('LEGEND_BACKGROUND')) define('LEGEND_BACKGROUND',2);
702
-		if (! defined('LEGEND_LINE'))       define('LEGEND_LINE',1);
712
+		if (! defined('SHADOW_RIGHT_TOP')) {
713
+		    define('SHADOW_RIGHT_TOP',3);
714
+		}
715
+		if (! defined('LEGEND_BACKGROUND')) {
716
+		    define('LEGEND_BACKGROUND',2);
717
+		}
718
+		if (! defined('LEGEND_LINE')) {
719
+		    define('LEGEND_LINE',1);
720
+		}
703 721
 
704 722
 		// Create graph
705 723
 		$classname='';
706
-		if (! isset($this->type[0]) || $this->type[0] == 'bars')  $classname='BarPlot';    // Only one type (first one) is supported by artichow
707
-		else if ($this->type[0] == 'lines' || $this->type[0] == 'linesnopoint') $classname='LinePlot';
708
-		else $classname='TypeUnknown';
724
+		if (! isset($this->type[0]) || $this->type[0] == 'bars') {
725
+		    $classname='BarPlot';
726
+		}
727
+		// Only one type (first one) is supported by artichow
728
+		else if ($this->type[0] == 'lines' || $this->type[0] == 'linesnopoint') {
729
+		    $classname='LinePlot';
730
+		} else {
731
+		    $classname='TypeUnknown';
732
+		}
709 733
 		include_once ARTICHOW_PATH.$classname.'.class.php';
710 734
 
711 735
 		// Definition de couleurs
@@ -727,8 +751,11 @@  discard block
 block discarded – undo
727 751
 			$graph->title->setFont(new $artichow_defaultfont(10));
728 752
 		}
729 753
 
730
-		if (is_array($this->bgcolor)) $graph->setBackgroundColor($bgcolor);
731
-		else $graph->setBackgroundGradient($colorgradient);
754
+		if (is_array($this->bgcolor)) {
755
+		    $graph->setBackgroundColor($bgcolor);
756
+		} else {
757
+		    $graph->setBackgroundGradient($colorgradient);
758
+		}
732 759
 
733 760
 		$group = new PlotGroup;
734 761
 		//$group->setSpace(5, 5, 0, 0);
@@ -736,18 +763,27 @@  discard block
 block discarded – undo
736 763
 		$paddleft=50;
737 764
 		$paddright=10;
738 765
 		$strl=dol_strlen(max(abs($this->MaxValue),abs($this->MinValue)));
739
-		if ($strl > 6) $paddleft += ($strl * 4);
766
+		if ($strl > 6) {
767
+		    $paddleft += ($strl * 4);
768
+		}
740 769
 		$group->setPadding($paddleft, $paddright);		// Width on left and right for Y axis values
741 770
 		$group->legend->setSpace(0);
742 771
 		$group->legend->setPadding(2,2,2,2);
743 772
 		$group->legend->setPosition(null, 0.1);
744 773
 		$group->legend->setBackgroundColor($colorsemitrans);
745 774
 
746
-		if (is_array($this->bgcolorgrid)) $group->grid->setBackgroundColor($bgcolorgrid);
747
-		else $group->grid->setBackgroundColor($colortrans);
775
+		if (is_array($this->bgcolorgrid)) {
776
+		    $group->grid->setBackgroundColor($bgcolorgrid);
777
+		} else {
778
+		    $group->grid->setBackgroundColor($colortrans);
779
+		}
748 780
 
749
-		if ($this->hideXGrid)	$group->grid->hideVertical(true);
750
-		if ($this->hideYGrid)	$group->grid->hideHorizontal(true);
781
+		if ($this->hideXGrid) {
782
+		    $group->grid->hideVertical(true);
783
+		}
784
+		if ($this->hideYGrid) {
785
+		    $group->grid->hideHorizontal(true);
786
+		}
751 787
 
752 788
 		// On boucle sur chaque lot de donnees
753 789
 		$legends=array();
@@ -785,17 +821,29 @@  discard block
 block discarded – undo
785 821
 				$colorgrey=new Color(100,100,100);
786 822
 				$colorborder=new Color($this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2]);
787 823
 
788
-				if ($this->mode == 'side')  $plot = new BarPlot($newvalues, $i+1, $nblot);
789
-				if ($this->mode == 'depth') $plot = new BarPlot($newvalues, 1, 1, ($nblot-$i-1)*5);
824
+				if ($this->mode == 'side') {
825
+				    $plot = new BarPlot($newvalues, $i+1, $nblot);
826
+				}
827
+				if ($this->mode == 'depth') {
828
+				    $plot = new BarPlot($newvalues, 1, 1, ($nblot-$i-1)*5);
829
+				}
790 830
 
791 831
 				$plot->barBorder->setColor($colorgrey);
792 832
 				//$plot->setBarColor($color);
793 833
 				$plot->setBarGradient(new LinearGradient($colorbis, $color, 90));
794 834
 
795
-				if ($this->mode == 'side')  $plot->setBarPadding(0.1, 0.1);
796
-				if ($this->mode == 'depth') $plot->setBarPadding(0.1, 0.4);
797
-				if ($this->mode == 'side')  $plot->setBarSpace(5);
798
-				if ($this->mode == 'depth') $plot->setBarSpace(2);
835
+				if ($this->mode == 'side') {
836
+				    $plot->setBarPadding(0.1, 0.1);
837
+				}
838
+				if ($this->mode == 'depth') {
839
+				    $plot->setBarPadding(0.1, 0.4);
840
+				}
841
+				if ($this->mode == 'side') {
842
+				    $plot->setBarSpace(5);
843
+				}
844
+				if ($this->mode == 'depth') {
845
+				    $plot->setBarSpace(2);
846
+				}
799 847
 
800 848
 				$plot->barShadow->setSize($this->SetShading);
801 849
 				$plot->barShadow->setPosition(SHADOW_RIGHT_TOP);
@@ -840,8 +888,12 @@  discard block
 block discarded – undo
840 888
 			// solve a bug in Artichow with UTF8
841 889
 			if (count($this->Legend))
842 890
 			{
843
-				if ($this->type[0] == 'bars')  										$group->legend->add($plot, $this->Legend[$i], LEGEND_BACKGROUND);
844
-				if ($this->type[0] == 'lines' || $this->type[0] == 'linesnopoint')	$group->legend->add($plot, $this->Legend[$i], LEGEND_LINE);
891
+				if ($this->type[0] == 'bars') {
892
+				    $group->legend->add($plot, $this->Legend[$i], LEGEND_BACKGROUND);
893
+				}
894
+				if ($this->type[0] == 'lines' || $this->type[0] == 'linesnopoint') {
895
+				    $group->legend->add($plot, $this->Legend[$i], LEGEND_LINE);
896
+				}
845 897
 			}
846 898
 			$group->add($plot);
847 899
 
@@ -852,7 +904,9 @@  discard block
 block discarded – undo
852 904
 		$group->axis->bottom->label->setFont(new $artichow_defaultfont(7));
853 905
 
854 906
 		//print $group->axis->bottom->getLabelNumber();
855
-		if ($this->labelInterval > 0) $group->axis->bottom->setLabelInterval($this->labelInterval);
907
+		if ($this->labelInterval > 0) {
908
+		    $group->axis->bottom->setLabelInterval($this->labelInterval);
909
+		}
856 910
 
857 911
 		$graph->add($group);
858 912
 
@@ -895,23 +949,30 @@  discard block
 block discarded – undo
895 949
 
896 950
 		$legends=array();
897 951
 		$nblot=count($this->data[0])-1;    // -1 to remove legend
898
-		if ($nblot < 0) dol_syslog('Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw', LOG_WARNING);
952
+		if ($nblot < 0) {
953
+		    dol_syslog('Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw', LOG_WARNING);
954
+		}
899 955
 		$firstlot=0;
900 956
 		// Works with line but not with bars
901 957
 		//if ($nblot > 2) $firstlot = ($nblot - 2);        // We limit nblot to 2 because jflot can't manage more than 2 bars on same x
902 958
 
903 959
 		$i=$firstlot;
904 960
 		$serie=array();
905
-		while ($i < $nblot)	// Loop on each serie
961
+		while ($i < $nblot) {
962
+		    // Loop on each serie
906 963
 		{
907
-			$values=array();	// Array with horizontal y values (specific values of a serie) for each abscisse x
964
+			$values=array();
965
+		}
966
+		// Array with horizontal y values (specific values of a serie) for each abscisse x
908 967
 			$serie[$i]="var d".$i." = [];\n";
909 968
 
910 969
 			// Fill array $values
911 970
 			$x=0;
912
-			foreach($this->data as $valarray)	// Loop on each x
971
+			foreach($this->data as $valarray) {
972
+			    // Loop on each x
913 973
 			{
914 974
 				$legends[$x] = $valarray[0];
975
+			}
915 976
 				$values[$x]  = (is_numeric($valarray[$i+1]) ? $valarray[$i+1] : null);
916 977
 				$x++;
917 978
 			}
@@ -920,13 +981,16 @@  discard block
 block discarded – undo
920 981
 			if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'pie')
921 982
 			{
922 983
 				foreach($values as $x => $y) {
923
-					if (isset($y)) $serie[$i].='d'.$i.'.push({"label":"'.dol_escape_js($legends[$x]).'", "data":'.$y.'});'."\n";
984
+					if (isset($y)) {
985
+					    $serie[$i].='d'.$i.'.push({"label":"'.dol_escape_js($legends[$x]).'", "data":'.$y.'});'."\n";
986
+					}
924 987
 				}
925
-			}
926
-			else
988
+			} else
927 989
 			{
928 990
 				foreach($values as $x => $y) {
929
-					if (isset($y)) $serie[$i].='d'.$i.'.push(['.$x.', '.$y.']);'."\n";
991
+					if (isset($y)) {
992
+					    $serie[$i].='d'.$i.'.push(['.$x.', '.$y.']);'."\n";
993
+					}
930 994
 				}
931 995
 			}
932 996
 
@@ -936,7 +1000,9 @@  discard block
 block discarded – undo
936 1000
 		$tag=dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file),'_',array('-','.'))));
937 1001
 
938 1002
 		$this->stringtoshow ='<!-- Build using '.$this->_library.' -->'."\n";
939
-		if (! empty($this->title)) $this->stringtoshow.='<div align="center" class="dolgraphtitle'.(empty($this->cssprefix)?'':' dolgraphtitle'.$this->cssprefix).'">'.$this->title.'</div>';
1003
+		if (! empty($this->title)) {
1004
+		    $this->stringtoshow.='<div align="center" class="dolgraphtitle'.(empty($this->cssprefix)?'':' dolgraphtitle'.$this->cssprefix).'">'.$this->title.'</div>';
1005
+		}
940 1006
 		if (! empty($this->shownographyet))
941 1007
 		{
942 1008
 		  $this->stringtoshow.='<div style="width:'.$this->width.'px;height:'.$this->height.'px;" class="nographyet"></div>';
@@ -951,8 +1017,7 @@  discard block
 block discarded – undo
951 1017
 		if ($nblot < 0)
952 1018
 		{
953 1019
 			$this->stringtoshow.='<!-- No series of data -->';
954
-		}
955
-		else
1020
+		} else
956 1021
 		{
957 1022
 			while ($i < $nblot)
958 1023
 			{
@@ -966,7 +1031,9 @@  discard block
 block discarded – undo
966 1031
 		if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'pie')
967 1032
 		{
968 1033
 			$datacolor=array();
969
-			foreach($this->datacolor as $val) $datacolor[]="#".sprintf("%02x%02x%02x",$val[0],$val[1],$val[2]);
1034
+			foreach($this->datacolor as $val) {
1035
+			    $datacolor[]="#".sprintf("%02x%02x%02x",$val[0],$val[1],$val[2]);
1036
+			}
970 1037
 
971 1038
 			$urltemp='';	// TODO Add support for url link into labels
972 1039
 			$showlegend=$this->showlegend;
@@ -993,13 +1060,17 @@  discard block
 block discarded – undo
993 1060
 								var number=series.data[0][1];
994 1061
 								return \'';
995 1062
 								$this->stringtoshow.='<span style="font-size:8pt;text-align:center;padding:2px;color:black;">';
996
-								if ($urltemp) $this->stringtoshow.='<a style="color: #FFFFFF;" border="0" href="'.$urltemp.'">';
1063
+								if ($urltemp) {
1064
+								    $this->stringtoshow.='<a style="color: #FFFFFF;" border="0" href="'.$urltemp.'">';
1065
+								}
997 1066
 								$this->stringtoshow.='\'+';
998 1067
 								$this->stringtoshow.=($showlegend?'':'label+\' \'+');	// Hide label if already shown in legend
999 1068
 								$this->stringtoshow.=($showpointvalue?'number+':'');
1000 1069
 								$this->stringtoshow.=($showpercent?'\'<br/>\'+percent+\'%\'+':'');
1001 1070
 								$this->stringtoshow.='\'';
1002
-								if ($urltemp) $this->stringtoshow.='</a>';
1071
+								if ($urltemp) {
1072
+								    $this->stringtoshow.='</a>';
1073
+								}
1003 1074
 								$this->stringtoshow.='</span>\';
1004 1075
 							},
1005 1076
 							background: {
@@ -1060,9 +1131,11 @@  discard block
 block discarded – undo
1060 1131
 						var y = item.datapoint[1].toFixed(2);
1061 1132
 						var z = item.series.xaxis.ticks[item.dataIndex].label;
1062 1133
 						';
1063
-						if ($this->showpointvalue > 0) $this->stringtoshow.='
1134
+						if ($this->showpointvalue > 0) {
1135
+						    $this->stringtoshow.='
1064 1136
 							showTooltip_'.$tag.'(item.pageX, item.pageY, item.series.label + "<br>" + z + " => " + y);
1065 1137
 						';
1138
+						}
1066 1139
 						$this->stringtoshow.='
1067 1140
 					}
1068 1141
 				}
@@ -1080,11 +1153,17 @@  discard block
 block discarded – undo
1080 1153
 			$i=$firstlot;
1081 1154
 			while ($i < $nblot)
1082 1155
 			{
1083
-				if ($i > $firstlot) $this->stringtoshow.=', '."\n";
1156
+				if ($i > $firstlot) {
1157
+				    $this->stringtoshow.=', '."\n";
1158
+				}
1084 1159
 				$color=sprintf("%02x%02x%02x",$this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2]);
1085 1160
 				$this->stringtoshow.='{ ';
1086
-				if (! isset($this->type[$i]) || $this->type[$i] == 'bars') $this->stringtoshow.='bars: { lineWidth: 1, show: true, align: "'.($i==$firstlot?'center':'left').'", barWidth: 0.5 }, ';
1087
-				if (isset($this->type[$i]) && ($this->type[$i] == 'lines' || $this->type[$i] == 'linesnopoint')) $this->stringtoshow.='lines: { show: true, fill: false }, points: { show: '.($this->type[$i] == 'linesnopoint' ? 'false' : 'true').' }, ';
1161
+				if (! isset($this->type[$i]) || $this->type[$i] == 'bars') {
1162
+				    $this->stringtoshow.='bars: { lineWidth: 1, show: true, align: "'.($i==$firstlot?'center':'left').'", barWidth: 0.5 }, ';
1163
+				}
1164
+				if (isset($this->type[$i]) && ($this->type[$i] == 'lines' || $this->type[$i] == 'linesnopoint')) {
1165
+				    $this->stringtoshow.='lines: { show: true, fill: false }, points: { show: '.($this->type[$i] == 'linesnopoint' ? 'false' : 'true').' }, ';
1166
+				}
1088 1167
 				$this->stringtoshow.='color: "#'.$color.'", label: "'.(isset($this->Legend[$i]) ? dol_escape_js($this->Legend[$i]) : '').'", data: d'.$i.' }';
1089 1168
 				$i++;
1090 1169
 			}
@@ -1096,7 +1175,9 @@  discard block
 block discarded – undo
1096 1175
 			$x=0;
1097 1176
 			foreach($this->data as $key => $valarray)
1098 1177
 			{
1099
-				if ($x > 0) $this->stringtoshow.=', '."\n";
1178
+				if ($x > 0) {
1179
+				    $this->stringtoshow.=', '."\n";
1180
+				}
1100 1181
 				$this->stringtoshow.= ' ['.$x.', "'.$valarray[0].'"]';
1101 1182
 				$x++;
1102 1183
 			}
@@ -1155,8 +1236,11 @@  discard block
 block discarded – undo
1155 1236
 
1156 1237
 		if ($direction == 'width')
1157 1238
 		{
1158
-			if (empty($conf->dol_optimize_smallscreen)) return ($defaultsize ? $defaultsize : '500');
1159
-			else return (empty($_SESSION['dol_screen_width']) ? '280' : ($_SESSION['dol_screen_width']-40));
1239
+			if (empty($conf->dol_optimize_smallscreen)) {
1240
+			    return ($defaultsize ? $defaultsize : '500');
1241
+			} else {
1242
+			    return (empty($_SESSION['dol_screen_width']) ? '280' : ($_SESSION['dol_screen_width']-40));
1243
+			}
1160 1244
 		}
1161 1245
 		if ($direction == 'height')
1162 1246
 		{
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/extrafields.class.php 1 patch
Braces   +287 added lines, -258 removed lines patch added patch discarded remove patch
@@ -173,11 +173,19 @@  discard block
 block discarded – undo
173 173
 	 */
174 174
 	function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param='', $alwayseditable=0, $perms='', $list='-1', $help='', $computed='', $entity='', $langfile='', $enabled='1')
175 175
 	{
176
-		if (empty($attrname)) return -1;
177
-		if (empty($label)) return -1;
176
+		if (empty($attrname)) {
177
+		    return -1;
178
+		}
179
+		if (empty($label)) {
180
+		    return -1;
181
+		}
178 182
 
179
-		if ($elementtype == 'thirdparty') $elementtype='societe';
180
-		if ($elementtype == 'contact') $elementtype='socpeople';
183
+		if ($elementtype == 'thirdparty') {
184
+		    $elementtype='societe';
185
+		}
186
+		if ($elementtype == 'contact') {
187
+		    $elementtype='socpeople';
188
+		}
181 189
 
182 190
 		// Create field into database except for separator type which is not stored in database
183 191
 		if ($type != 'separate')
@@ -195,10 +203,10 @@  discard block
 block discarded – undo
195 203
 				$this->error='';
196 204
 				$this->errno=0;
197 205
 				return 1;
206
+			} else {
207
+			    return -2;
198 208
 			}
199
-			else return -2;
200
-		}
201
-		else
209
+		} else
202 210
 		{
203 211
 			return -1;
204 212
 		}
@@ -223,11 +231,17 @@  discard block
 block discarded – undo
223 231
 	 */
224 232
 	private function create($attrname, $type='varchar', $length=255, $elementtype='member', $unique=0, $required=0, $default_value='',$param='', $perms='', $list='0', $computed='')
225 233
 	{
226
-		if ($elementtype == 'thirdparty') $elementtype='societe';
227
-		if ($elementtype == 'contact') $elementtype='socpeople';
234
+		if ($elementtype == 'thirdparty') {
235
+		    $elementtype='societe';
236
+		}
237
+		if ($elementtype == 'contact') {
238
+		    $elementtype='socpeople';
239
+		}
228 240
 
229 241
 		$table=$elementtype.'_extrafields';
230
-		if ($elementtype == 'categorie') $table='categories_extrafields';
242
+		if ($elementtype == 'categorie') {
243
+		    $table='categories_extrafields';
244
+		}
231 245
 
232 246
 		if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9_]*$/",$attrname) && ! is_numeric($attrname))
233 247
 		{
@@ -261,7 +275,9 @@  discard block
 block discarded – undo
261 275
 			} else {
262 276
 				$typedb=$type;
263 277
 				$lengthdb=$length;
264
-				if ($type == 'varchar' && empty($lengthdb)) $lengthdb='255';
278
+				if ($type == 'varchar' && empty($lengthdb)) {
279
+				    $lengthdb='255';
280
+				}
265 281
 			}
266 282
 			$field_desc = array(
267 283
 				'type'=>$typedb,
@@ -279,15 +295,13 @@  discard block
 block discarded – undo
279 295
 					$resql=$this->db->query($sql,1,'dml');
280 296
 				}
281 297
 				return 1;
282
-			}
283
-			else
298
+			} else
284 299
 			{
285 300
 				$this->error=$this->db->lasterror();
286 301
 				$this->errno=$this->db->lasterrno();
287 302
 				return -1;
288 303
 			}
289
-		}
290
-		else
304
+		} else
291 305
 		{
292 306
 			return 0;
293 307
 		}
@@ -322,27 +336,39 @@  discard block
 block discarded – undo
322 336
         // phpcs:enable
323 337
 		global $conf,$user;
324 338
 
325
-		if ($elementtype == 'thirdparty') $elementtype='societe';
326
-		if ($elementtype == 'contact') $elementtype='socpeople';
339
+		if ($elementtype == 'thirdparty') {
340
+		    $elementtype='societe';
341
+		}
342
+		if ($elementtype == 'contact') {
343
+		    $elementtype='socpeople';
344
+		}
327 345
 
328 346
 		// Clean parameters
329
-		if (empty($pos)) $pos=0;
330
-		if (empty($list)) $list='0';
331
-		if (empty($required)) $required=0;
332
-		if (empty($unique)) $unique=0;
333
-		if (empty($alwayseditable)) $alwayseditable=0;
347
+		if (empty($pos)) {
348
+		    $pos=0;
349
+		}
350
+		if (empty($list)) {
351
+		    $list='0';
352
+		}
353
+		if (empty($required)) {
354
+		    $required=0;
355
+		}
356
+		if (empty($unique)) {
357
+		    $unique=0;
358
+		}
359
+		if (empty($alwayseditable)) {
360
+		    $alwayseditable=0;
361
+		}
334 362
 
335 363
 		if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname) && ! is_numeric($attrname))
336 364
 		{
337 365
 			if (is_array($param) && count($param) > 0)
338 366
 			{
339 367
 				$params = serialize($param);
340
-			}
341
-			elseif (strlen($param) > 0)
368
+			} elseif (strlen($param) > 0)
342 369
 			{
343 370
 				$params = trim($param);
344
-			}
345
-			else
371
+			} else
346 372
 			{
347 373
 				$params='';
348 374
 			}
@@ -397,8 +423,7 @@  discard block
 block discarded – undo
397 423
 			if ($this->db->query($sql))
398 424
 			{
399 425
 				return 1;
400
-			}
401
-			else
426
+			} else
402 427
 			{
403 428
 				$this->error=$this->db->lasterror();
404 429
 				$this->errno=$this->db->lasterrno();
@@ -416,11 +441,17 @@  discard block
 block discarded – undo
416 441
 	 */
417 442
 	function delete($attrname, $elementtype='member')
418 443
 	{
419
-		if ($elementtype == 'thirdparty') $elementtype='societe';
420
-		if ($elementtype == 'contact') $elementtype='socpeople';
444
+		if ($elementtype == 'thirdparty') {
445
+		    $elementtype='societe';
446
+		}
447
+		if ($elementtype == 'contact') {
448
+		    $elementtype='socpeople';
449
+		}
421 450
 
422 451
 		$table=$elementtype.'_extrafields';
423
-		if ($elementtype == 'categorie') $table='categories_extrafields';
452
+		if ($elementtype == 'categorie') {
453
+		    $table='categories_extrafields';
454
+		}
424 455
 
425 456
 		$error=0;
426 457
 
@@ -457,8 +488,7 @@  discard block
 block discarded – undo
457 488
 			}
458 489
 
459 490
 			return $result;
460
-		}
461
-		else
491
+		} else
462 492
 		{
463 493
 			return 0;
464 494
 		}
@@ -477,8 +507,12 @@  discard block
 block discarded – undo
477 507
         // phpcs:enable
478 508
 		global $conf;
479 509
 
480
-		if ($elementtype == 'thirdparty') $elementtype='societe';
481
-		if ($elementtype == 'contact') $elementtype='socpeople';
510
+		if ($elementtype == 'thirdparty') {
511
+		    $elementtype='societe';
512
+		}
513
+		if ($elementtype == 'contact') {
514
+		    $elementtype='socpeople';
515
+		}
482 516
 
483 517
 		if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
484 518
 		{
@@ -492,14 +526,12 @@  discard block
 block discarded – undo
492 526
 			if ($resql)
493 527
 			{
494 528
 				return 1;
495
-			}
496
-			else
529
+			} else
497 530
 			{
498 531
 				print dol_print_error($this->db);
499 532
 				return -1;
500 533
 			}
501
-		}
502
-		else
534
+		} else
503 535
 		{
504 536
 			return 0;
505 537
 		}
@@ -531,11 +563,17 @@  discard block
 block discarded – undo
531 563
 	 */
532 564
 	function update($attrname, $label, $type, $length, $elementtype, $unique=0, $required=0, $pos=0, $param='', $alwayseditable=0, $perms='', $list='', $help='', $default='', $computed='', $entity='', $langfile='', $enabled='1', $totalizable=0)
533 565
 	{
534
-		if ($elementtype == 'thirdparty') $elementtype='societe';
535
-		if ($elementtype == 'contact') $elementtype='socpeople';
566
+		if ($elementtype == 'thirdparty') {
567
+		    $elementtype='societe';
568
+		}
569
+		if ($elementtype == 'contact') {
570
+		    $elementtype='socpeople';
571
+		}
536 572
 
537 573
         $table=$elementtype.'_extrafields';
538
-		if ($elementtype == 'categorie') $table='categories_extrafields';
574
+		if ($elementtype == 'categorie') {
575
+		    $table='categories_extrafields';
576
+		}
539 577
 
540 578
 		if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
541 579
 		{
@@ -571,10 +609,12 @@  discard block
 block discarded – undo
571 609
 			}
572 610
 			$field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required?'NOT NULL':'NULL'), 'default'=>$default);
573 611
 
574
-			if ($type != 'separate') // No table update when separate type
612
+			if ($type != 'separate') {
613
+			    // No table update when separate type
575 614
 			{
576 615
 				$result=$this->db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc);
577 616
 			}
617
+			}
578 618
 			if ($result > 0 || $type == 'separate')
579 619
 			{
580 620
 				if ($label)
@@ -587,28 +627,24 @@  discard block
 block discarded – undo
587 627
 					if ($unique)
588 628
 					{
589 629
 						$sql="ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")";
590
-					}
591
-					else
630
+					} else
592 631
 					{
593 632
 						$sql="ALTER TABLE ".MAIN_DB_PREFIX.$table." DROP INDEX uk_".$table."_".$attrname;
594 633
 					}
595 634
 					dol_syslog(get_class($this).'::update', LOG_DEBUG);
596 635
 					$resql=$this->db->query($sql,1,'dml');
597 636
 					return 1;
598
-				}
599
-				else
637
+				} else
600 638
 				{
601 639
 					$this->error=$this->db->lasterror();
602 640
 					return -1;
603 641
 				}
604
-			}
605
-			else
642
+			} else
606 643
 			{
607 644
 				$this->error=$this->db->lasterror();
608 645
 				return -1;
609 646
 			}
610
-		}
611
-		else
647
+		} else
612 648
 		{
613 649
 			return 0;
614 650
 		}
@@ -646,17 +682,31 @@  discard block
 block discarded – undo
646 682
 		dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$default.", ".$computed.", ".$entity.", ".$langfile.", ".$enabled.", ".$totalizable);
647 683
 
648 684
 		// Clean parameters
649
-		if ($elementtype == 'thirdparty') $elementtype='societe';
650
-		if ($elementtype == 'contact') $elementtype='socpeople';
685
+		if ($elementtype == 'thirdparty') {
686
+		    $elementtype='societe';
687
+		}
688
+		if ($elementtype == 'contact') {
689
+		    $elementtype='socpeople';
690
+		}
651 691
 
652
-		if (empty($pos)) $pos=0;
653
-		if (empty($list)) $list='0';
692
+		if (empty($pos)) {
693
+		    $pos=0;
694
+		}
695
+		if (empty($list)) {
696
+		    $list='0';
697
+		}
654 698
         if (empty($totalizable)) {
655 699
             $totalizable = 0;
656 700
         }
657
-		if (empty($required)) $required=0;
658
-		if (empty($unique)) $unique=0;
659
-		if (empty($alwayseditable)) $alwayseditable=0;
701
+		if (empty($required)) {
702
+		    $required=0;
703
+		}
704
+		if (empty($unique)) {
705
+		    $unique=0;
706
+		}
707
+		if (empty($alwayseditable)) {
708
+		    $alwayseditable=0;
709
+		}
660 710
 
661 711
 		if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
662 712
 		{
@@ -665,12 +715,10 @@  discard block
 block discarded – undo
665 715
 			if (is_array($param) && count($param) > 0)
666 716
 			{
667 717
 				$params = serialize($param);
668
-			}
669
-			elseif (strlen($param) > 0)
718
+			} elseif (strlen($param) > 0)
670 719
 			{
671 720
 				$params = trim($param);
672
-			}
673
-			else
721
+			} else
674 722
 			{
675 723
 				$params='';
676 724
 			}
@@ -682,8 +730,7 @@  discard block
 block discarded – undo
682 730
 				$sql_del.= " WHERE name = '".$attrname."'";
683 731
 				$sql_del.= " AND entity IN (0, ".($entity===''?$conf->entity:$entity).")";
684 732
 				$sql_del.= " AND elementtype = '".$elementtype."'";
685
-			}
686
-			else
733
+			} else
687 734
 			{
688 735
 				// We want on all entities ($entities = '0'), we delete on all only (we keep setup specific to each entity)
689 736
 				$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields";
@@ -747,15 +794,13 @@  discard block
 block discarded – undo
747 794
 			{
748 795
 				$this->db->commit();
749 796
 				return 1;
750
-			}
751
-			else
797
+			} else
752 798
 			{
753 799
 				$this->db->rollback();
754 800
 				print dol_print_error($this->db);
755 801
 				return -1;
756 802
 			}
757
-		}
758
-		else
803
+		} else
759 804
 		{
760 805
 			return 0;
761 806
 		}
@@ -775,16 +820,26 @@  discard block
 block discarded – undo
775 820
         // phpcs:enable
776 821
 		global $conf;
777 822
 
778
-		if (empty($elementtype)) return array();
823
+		if (empty($elementtype)) {
824
+		    return array();
825
+		}
779 826
 
780
-		if ($elementtype == 'thirdparty') $elementtype='societe';
781
-		if ($elementtype == 'contact') $elementtype='socpeople';
782
-		if ($elementtype == 'order_supplier') $elementtype='commande_fournisseur';
827
+		if ($elementtype == 'thirdparty') {
828
+		    $elementtype='societe';
829
+		}
830
+		if ($elementtype == 'contact') {
831
+		    $elementtype='socpeople';
832
+		}
833
+		if ($elementtype == 'order_supplier') {
834
+		    $elementtype='commande_fournisseur';
835
+		}
783 836
 
784 837
 		$array_name_label=array();
785 838
 
786 839
 		// To avoid conflicts with external modules. TODO Remove this.
787
-		if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return $array_name_label;
840
+		if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
841
+		    return $array_name_label;
842
+		}
788 843
 
789 844
 		// Set array of label of entity
790 845
 		// TODO Remove completely loading of label. This should be done by presentation.
@@ -808,7 +863,10 @@  discard block
 block discarded – undo
808 863
 		$sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,totalizable,fielddefault,fieldcomputed,entity,enabled,help";
809 864
 		$sql.= " FROM ".MAIN_DB_PREFIX."extrafields";
810 865
 		$sql.= " WHERE entity IN (0,".$conf->entity.")";
811
-		if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'";	// Filed with object->table_element
866
+		if ($elementtype) {
867
+		    $sql.= " AND elementtype = '".$elementtype."'";
868
+		}
869
+		// Filed with object->table_element
812 870
 		$sql.= " ORDER BY pos";
813 871
 
814 872
 		$resql=$this->db->query($sql);
@@ -867,9 +925,11 @@  discard block
 block discarded – undo
867 925
 					$this->attributes[$tab->elementtype]['loaded']=1;
868 926
 				}
869 927
 			}
870
-			if ($elementtype) $this->attributes[$elementtype]['loaded']=1;	// If nothing found, we also save tag 'loaded'
871
-		}
872
-		else
928
+			if ($elementtype) {
929
+			    $this->attributes[$elementtype]['loaded']=1;
930
+			}
931
+			// If nothing found, we also save tag 'loaded'
932
+		} else
873 933
 		{
874 934
 			$this->error=$this->db->lasterror();
875 935
 			dol_syslog(get_class($this)."::fetch_name_optionals_label ".$this->error, LOG_ERR);
@@ -923,8 +983,7 @@  discard block
 block discarded – undo
923 983
 			$totalizable=$this->attributes[$extrafieldsobjectkey]['totalizable'][$key];
924 984
 			$help=$this->attributes[$extrafieldsobjectkey]['help'][$key];
925 985
 			$hidden=(empty($list) ? 1 : 0);		// If empty, 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)
926
-		}
927
-		else	// Old usage
986
+		} else	// Old usage
928 987
 		{
929 988
 			$label=$this->attribute_label[$key];
930 989
 			$type =$this->attribute_type[$key];
@@ -943,8 +1002,11 @@  discard block
 block discarded – undo
943 1002
 
944 1003
 		if ($computed)
945 1004
 		{
946
-			if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
947
-			else return '';
1005
+			if (! preg_match('/^search_/', $keyprefix)) {
1006
+			    return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
1007
+			} else {
1008
+			    return '';
1009
+			}
948 1010
 		}
949 1011
 
950 1012
 		if (empty($morecss))
@@ -952,38 +1014,30 @@  discard block
 block discarded – undo
952 1014
 			if ($type == 'date')
953 1015
 			{
954 1016
 				$morecss = 'minwidth100imp';
955
-			}
956
-			elseif ($type == 'datetime')
1017
+			} elseif ($type == 'datetime')
957 1018
 			{
958 1019
 				$morecss = 'minwidth200imp';
959
-			}
960
-			elseif (in_array($type,array('int','integer','double','price')))
1020
+			} elseif (in_array($type,array('int','integer','double','price')))
961 1021
 			{
962 1022
 				$morecss = 'maxwidth75';
963
-			}
964
-			elseif ($type == 'password')
1023
+			} elseif ($type == 'password')
965 1024
 			{
966 1025
 				$morecss='maxwidth100';
967
-			}
968
-			elseif ($type == 'url')
1026
+			} elseif ($type == 'url')
969 1027
 			{
970 1028
 				$morecss='minwidth400';
971
-			}
972
-			elseif ($type == 'boolean')
1029
+			} elseif ($type == 'boolean')
973 1030
 			{
974 1031
 				$morecss='';
975
-			}
976
-			else
1032
+			} else
977 1033
 			{
978 1034
 				if (round($size) < 12)
979 1035
 				{
980 1036
 					$morecss = 'minwidth100';
981
-				}
982
-				else if (round($size) <= 48)
1037
+				} else if (round($size) <= 48)
983 1038
 				{
984 1039
 					$morecss = 'minwidth200';
985
-				}
986
-				else
1040
+				} else
987 1041
 				{
988 1042
 					$morecss = 'minwidth400';
989 1043
 				}
@@ -998,52 +1052,50 @@  discard block
 block discarded – undo
998 1052
 			$showtime = in_array($type,array('datetime')) ? 1 : 0;
999 1053
 
1000 1054
 			// Do not show current date when field not required (see selectDate() method)
1001
-			if (!$required && $value == '') $value = '-1';
1055
+			if (!$required && $value == '') {
1056
+			    $value = '-1';
1057
+			}
1002 1058
 
1003 1059
 			// TODO Must also support $moreparam
1004 1060
 			$out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1);
1005
-		}
1006
-		elseif (in_array($type,array('int','integer')))
1061
+		} elseif (in_array($type,array('int','integer')))
1007 1062
 		{
1008 1063
 			$tmp=explode(',',$size);
1009 1064
 			$newsize=$tmp[0];
1010 1065
 			$out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>';
1011
-		}
1012
-		elseif (preg_match('/varchar/', $type))
1066
+		} elseif (preg_match('/varchar/', $type))
1013 1067
 		{
1014 1068
 			$out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>';
1015
-		}
1016
-		elseif (in_array($type, array('mail', 'phone', 'url')))
1069
+		} elseif (in_array($type, array('mail', 'phone', 'url')))
1017 1070
 		{
1018 1071
 			$out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>';
1019
-		}
1020
-		elseif ($type == 'text')
1072
+		} elseif ($type == 'text')
1021 1073
 		{
1022
-			if (! preg_match('/search_/', $keyprefix))		// If keyprefix is search_ or search_options_, we must just use a simple text field
1074
+			if (! preg_match('/search_/', $keyprefix)) {
1075
+			    // If keyprefix is search_ or search_options_, we must just use a simple text field
1023 1076
 			{
1024 1077
 				require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1078
+			}
1025 1079
 				$doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%');
1026 1080
 				$out=$doleditor->Create(1);
1027
-			}
1028
-			else
1081
+			} else
1029 1082
 			{
1030 1083
 				$out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>';
1031 1084
 			}
1032
-		}
1033
-		elseif ($type == 'html')
1085
+		} elseif ($type == 'html')
1034 1086
 		{
1035
-			if (! preg_match('/search_/', $keyprefix))		// If keyprefix is search_ or search_options_, we must just use a simple text field
1087
+			if (! preg_match('/search_/', $keyprefix)) {
1088
+			    // If keyprefix is search_ or search_options_, we must just use a simple text field
1036 1089
 			{
1037 1090
 				require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1091
+			}
1038 1092
 				$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%');
1039 1093
 				$out=$doleditor->Create(1);
1040
-			}
1041
-			else
1094
+			} else
1042 1095
 			{
1043 1096
 				$out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>';
1044 1097
 			}
1045
-		}
1046
-		elseif ($type == 'boolean')
1098
+		} elseif ($type == 'boolean')
1047 1099
 		{
1048 1100
 			$checked='';
1049 1101
 			if (!empty($value)) {
@@ -1052,22 +1104,19 @@  discard block
 block discarded – undo
1052 1104
 				$checked=' value="1" ';
1053 1105
 			}
1054 1106
 			$out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>';
1055
-		}
1056
-		elseif ($type == 'price')
1107
+		} elseif ($type == 'price')
1057 1108
 		{
1058 1109
 			if (!empty($value)) {		// $value in memory is a php numeric, we format it into user number format.
1059 1110
 				$value=price($value);
1060 1111
 			}
1061 1112
 			$out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency);
1062
-		}
1063
-		elseif ($type == 'double')
1113
+		} elseif ($type == 'double')
1064 1114
 		{
1065 1115
 			if (!empty($value)) {		// $value in memory is a php numeric, we format it into user number format.
1066 1116
 				$value=price($value);
1067 1117
 			}
1068 1118
 			$out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> ';
1069
-		}
1070
-		elseif ($type == 'select')
1119
+		} elseif ($type == 'select')
1071 1120
 		{
1072 1121
 			$out = '';
1073 1122
 			if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2))
@@ -1080,19 +1129,23 @@  discard block
 block discarded – undo
1080 1129
 			$out.='<option value="0">&nbsp;</option>';
1081 1130
 			foreach ($param['options'] as $key => $val)
1082 1131
 			{
1083
-				if ((string) $key == '') continue;
1132
+				if ((string) $key == '') {
1133
+				    continue;
1134
+				}
1084 1135
 				list($val, $parent) = explode('|', $val);
1085 1136
 				$out.='<option value="'.$key.'"';
1086 1137
 				$out.= (((string) $value == (string) $key)?' selected':'');
1087 1138
 				$out.= (!empty($parent)?' parent="'.$parent.'"':'');
1088 1139
 				$out.='>';
1089
-				if ($langfile && $val) $out.=$langs->trans($val);
1090
-				else $out.=$val;
1140
+				if ($langfile && $val) {
1141
+				    $out.=$langs->trans($val);
1142
+				} else {
1143
+				    $out.=$val;
1144
+				}
1091 1145
 				$out.='</option>';
1092 1146
 			}
1093 1147
 			$out.='</select>';
1094
-		}
1095
-		elseif ($type == 'sellist')
1148
+		} elseif ($type == 'sellist')
1096 1149
 		{
1097 1150
 			$out = '';
1098 1151
 			if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2))
@@ -1163,13 +1216,11 @@  discard block
 block discarded – undo
1163 1216
 					{
1164 1217
 						$sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra';
1165 1218
 						$sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4];
1166
-					}
1167
-					else
1219
+					} else
1168 1220
 					{
1169 1221
 						$sqlwhere.= ' WHERE '.$InfoFieldList[4];
1170 1222
 					}
1171
-				}
1172
-				else
1223
+				} else
1173 1224
 				{
1174 1225
 					$sqlwhere.= ' WHERE 1=1';
1175 1226
 				}
@@ -1205,8 +1256,7 @@  discard block
 block discarded – undo
1205 1256
 							{
1206 1257
 								$labeltoshow.= $obj->$field_toshow.' ';
1207 1258
 							}
1208
-						}
1209
-						else
1259
+						} else
1210 1260
 						{
1211 1261
 							$labeltoshow=$obj->{$InfoFieldList[1]};
1212 1262
 						}
@@ -1219,25 +1269,25 @@  discard block
 block discarded – undo
1219 1269
 								$translabel=$langs->trans($obj->$field_toshow);
1220 1270
 								if ($translabel!=$obj->$field_toshow) {
1221 1271
 									$labeltoshow=dol_trunc($translabel,18).' ';
1222
-								}else {
1272
+								} else {
1223 1273
 									$labeltoshow=dol_trunc($obj->$field_toshow,18).' ';
1224 1274
 								}
1225 1275
 							}
1226 1276
 							$out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
1227
-						}
1228
-						else
1277
+						} else
1229 1278
 						{
1230 1279
 							if (! $notrans)
1231 1280
 							{
1232 1281
 								$translabel=$langs->trans($obj->{$InfoFieldList[1]});
1233 1282
 								if ($translabel!=$obj->{$InfoFieldList[1]}) {
1234 1283
 									$labeltoshow=dol_trunc($translabel,18);
1235
-								}
1236
-								else {
1284
+								} else {
1237 1285
 									$labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18);
1238 1286
 								}
1239 1287
 							}
1240
-							if (empty($labeltoshow)) $labeltoshow='(not defined)';
1288
+							if (empty($labeltoshow)) {
1289
+							    $labeltoshow='(not defined)';
1290
+							}
1241 1291
 							if ($value==$obj->rowid)
1242 1292
 							{
1243 1293
 								$out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
@@ -1257,19 +1307,16 @@  discard block
 block discarded – undo
1257 1307
 						$i++;
1258 1308
 					}
1259 1309
 					$this->db->free($resql);
1260
-				}
1261
-				else {
1310
+				} else {
1262 1311
 					print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>';
1263 1312
 				}
1264 1313
 			}
1265 1314
 			$out.='</select>';
1266
-		}
1267
-		elseif ($type == 'checkbox')
1315
+		} elseif ($type == 'checkbox')
1268 1316
 		{
1269 1317
 			$value_arr=explode(',',$value);
1270 1318
 			$out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%');
1271
-		}
1272
-		elseif ($type == 'radio')
1319
+		} elseif ($type == 'radio')
1273 1320
 		{
1274 1321
 			$out='';
1275 1322
 			foreach ($param['options'] as $keyopt => $val)
@@ -1280,13 +1327,11 @@  discard block
 block discarded – undo
1280 1327
 				$out.= ($value==$keyopt?'checked':'');
1281 1328
 				$out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>';
1282 1329
 			}
1283
-		}
1284
-		elseif ($type == 'chkbxlst')
1330
+		} elseif ($type == 'chkbxlst')
1285 1331
 		{
1286 1332
 			if (is_array($value)) {
1287 1333
 				$value_arr = $value;
1288
-			}
1289
-			else {
1334
+			} else {
1290 1335
 				$value_arr = explode(',', $value);
1291 1336
 			}
1292 1337
 
@@ -1365,17 +1410,14 @@  discard block
 block discarded – undo
1365 1410
 							if (! empty($matchCondition[1]) && ! empty($matchCondition[3]) && $matchCondition[1] != $matchCondition[3] ) {
1366 1411
 								// Nobody sain would do that without parentheses
1367 1412
 								$InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]);
1368
-							}
1369
-							else {
1413
+							} else {
1370 1414
 								if (! empty($matchCondition[1])) {
1371 1415
 									$boolCond =(( $matchCondition[1] == "AND" )?' AND 1 ':' OR 0 ');
1372 1416
 									$InfoFieldList[4]=str_replace($matchCondition[0],$boolCond.$matchCondition[3],$InfoFieldList[4]);
1373
-								}
1374
-								else if (! empty($matchCondition[3])) {
1417
+								} else if (! empty($matchCondition[3])) {
1375 1418
 									$boolCond =(( $matchCondition[3] == "AND" )?' 1 AND ':' 0 OR');
1376 1419
 									$InfoFieldList[4]=str_replace($matchCondition[0],$boolCond,$InfoFieldList[4]);
1377
-								}
1378
-								else {
1420
+								} else {
1379 1421
 									$InfoFieldList[4] = 1;
1380 1422
 								}
1381 1423
 							}
@@ -1383,8 +1425,7 @@  discard block
 block discarded – undo
1383 1425
 							// Si l'on a un AND ou un OR, avant ou après
1384 1426
 							preg_match('#(AND|OR|) *('.$word.') *(AND|OR|)#',$InfoFieldList[4],$matchCondition);
1385 1427
 						}
1386
-					}
1387
-					else {
1428
+					} else {
1388 1429
 						$InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]);
1389 1430
 					}
1390 1431
 
@@ -1452,8 +1493,9 @@  discard block
 block discarded – undo
1452 1493
 									$labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
1453 1494
 								}
1454 1495
 							}
1455
-							if (empty($labeltoshow))
1456
-								$labeltoshow = '(not defined)';
1496
+							if (empty($labeltoshow)) {
1497
+															$labeltoshow = '(not defined)';
1498
+							}
1457 1499
 
1458 1500
 								if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1459 1501
 									$data[$obj->rowid]=$labeltoshow;
@@ -1475,14 +1517,12 @@  discard block
 block discarded – undo
1475 1517
 					print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>';
1476 1518
 				}
1477 1519
 			}
1478
-		}
1479
-		elseif ($type == 'link')
1520
+		} elseif ($type == 'link')
1480 1521
 		{
1481 1522
 			$param_list=array_keys($param['options']);				// $param_list='ObjectName:classPath'
1482 1523
 			$showempty=(($required && $default != '')?0:1);
1483 1524
 			$out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty);
1484
-		}
1485
-		elseif ($type == 'password')
1525
+		} elseif ($type == 'password')
1486 1526
 		{
1487 1527
 			// If prefix is 'search_', field is used as a filter, we use a common text field.
1488 1528
 			$out='<input style="display:none" type="text" name="fakeusernameremembered">';	// Hidden field to reduce impact of evil Google Chrome autopopulate bug.
@@ -1527,8 +1567,7 @@  discard block
 block discarded – undo
1527 1567
 			$list=dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1);
1528 1568
 			$help=$this->attributes[$extrafieldsobjectkey]['help'][$key];
1529 1569
 			$hidden=(empty($list) ? 1 : 0);		// If $list empty, 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)
1530
-		}
1531
-		else	// Old usage
1570
+		} else	// Old usage
1532 1571
 		{
1533 1572
 			$label=$this->attribute_label[$key];
1534 1573
 			$type=$this->attribute_type[$key];
@@ -1545,7 +1584,10 @@  discard block
 block discarded – undo
1545 1584
 			$hidden=(empty($list) ? 1 : 0);		// If $list empty, 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)
1546 1585
 		}
1547 1586
 
1548
-		if ($hidden) return '';		// This is a protection. If field is hidden, we should just not call this method.
1587
+		if ($hidden) {
1588
+		    return '';
1589
+		}
1590
+		// This is a protection. If field is hidden, we should just not call this method.
1549 1591
 
1550 1592
 		// If field is a computed field, value must become result of compute
1551 1593
 		if ($computed)
@@ -1560,52 +1602,45 @@  discard block
 block discarded – undo
1560 1602
 		{
1561 1603
 			$showsize=10;
1562 1604
 			$value=dol_print_date($value, 'day');
1563
-		}
1564
-		elseif ($type == 'datetime')
1605
+		} elseif ($type == 'datetime')
1565 1606
 		{
1566 1607
 			$showsize=19;
1567 1608
 			$value=dol_print_date($value, 'dayhour');
1568
-		}
1569
-		elseif ($type == 'int')
1609
+		} elseif ($type == 'int')
1570 1610
 		{
1571 1611
 			$showsize=10;
1572
-		}
1573
-		elseif ($type == 'double')
1612
+		} elseif ($type == 'double')
1574 1613
 		{
1575 1614
 			if (!empty($value)) {
1576 1615
 				$value=price($value);
1577 1616
 			}
1578
-		}
1579
-		elseif ($type == 'boolean')
1617
+		} elseif ($type == 'boolean')
1580 1618
 		{
1581 1619
 			$checked='';
1582 1620
 			if (!empty($value)) {
1583 1621
 				$checked=' checked ';
1584 1622
 			}
1585 1623
 			$value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>';
1586
-		}
1587
-		elseif ($type == 'mail')
1624
+		} elseif ($type == 'mail')
1588 1625
 		{
1589 1626
 			$value=dol_print_email($value, 0, 0, 0, 64, 1, 1);
1590
-		}
1591
-		elseif ($type == 'url')
1627
+		} elseif ($type == 'url')
1592 1628
 		{
1593 1629
 			$value=dol_print_url($value,'_blank',32,1);
1594
-		}
1595
-		elseif ($type == 'phone')
1630
+		} elseif ($type == 'phone')
1596 1631
 		{
1597 1632
 			$value=dol_print_phone($value, '', 0, 0, '', '&nbsp;', 1);
1598
-		}
1599
-		elseif ($type == 'price')
1633
+		} elseif ($type == 'price')
1600 1634
 		{
1601 1635
 			$value=price($value, 0, $langs, 0, 0, -1, $conf->currency);
1602
-		}
1603
-		elseif ($type == 'select')
1636
+		} elseif ($type == 'select')
1604 1637
 		{
1605
-			if ($langfile && $param['options'][$value]) $value=$langs->trans($param['options'][$value]);
1606
-			else $value=$param['options'][$value];
1607
-		}
1608
-		elseif ($type == 'sellist')
1638
+			if ($langfile && $param['options'][$value]) {
1639
+			    $value=$langs->trans($param['options'][$value]);
1640
+			} else {
1641
+			    $value=$param['options'][$value];
1642
+			}
1643
+		} elseif ($type == 'sellist')
1609 1644
 		{
1610 1645
 			$param_list=array_keys($param['options']);
1611 1646
 			$InfoFieldList = explode(":", $param_list[0]);
@@ -1635,7 +1670,7 @@  discard block
 block discarded – undo
1635 1670
 				$sql.= " WHERE ".$selectkey."=0";
1636 1671
 			} elseif ($selectkey=='rowid') {
1637 1672
 				$sql.= " WHERE ".$selectkey."=".$this->db->escape($value);
1638
-			}else {
1673
+			} else {
1639 1674
 				$sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'";
1640 1675
 			}
1641 1676
 
@@ -1662,12 +1697,11 @@  discard block
 block discarded – undo
1662 1697
 						}
1663 1698
 						if ($translabel!=$field_toshow) {
1664 1699
 							$value.=dol_trunc($translabel,18).' ';
1665
-						}else {
1700
+						} else {
1666 1701
 							$value.=$obj->$field_toshow.' ';
1667 1702
 						}
1668 1703
 					}
1669
-				}
1670
-				else
1704
+				} else
1671 1705
 				{
1672 1706
 					$translabel='';
1673 1707
 					if (!empty($obj->{$InfoFieldList[1]})) {
@@ -1675,18 +1709,17 @@  discard block
 block discarded – undo
1675 1709
 					}
1676 1710
 					if ($translabel!=$obj->{$InfoFieldList[1]}) {
1677 1711
 						$value=dol_trunc($translabel,18);
1678
-					}else {
1712
+					} else {
1679 1713
 						$value=$obj->{$InfoFieldList[1]};
1680 1714
 					}
1681 1715
 				}
1716
+			} else {
1717
+			    dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
1682 1718
 			}
1683
-			else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
1684
-		}
1685
-		elseif ($type == 'radio')
1719
+		} elseif ($type == 'radio')
1686 1720
 		{
1687 1721
 			$value=$param['options'][$value];
1688
-		}
1689
-		elseif ($type == 'checkbox')
1722
+		} elseif ($type == 'checkbox')
1690 1723
 		{
1691 1724
 			$value_arr=explode(',',$value);
1692 1725
 			$value='';
@@ -1698,8 +1731,7 @@  discard block
 block discarded – undo
1698 1731
 				}
1699 1732
 			}
1700 1733
 			$value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
1701
-		}
1702
-		elseif ($type == 'chkbxlst')
1734
+		} elseif ($type == 'chkbxlst')
1703 1735
 		{
1704 1736
 			$value_arr = explode(',', $value);
1705 1737
 
@@ -1767,15 +1799,17 @@  discard block
 block discarded – undo
1767 1799
 			} else {
1768 1800
 				dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING);
1769 1801
 			}
1770
-		}
1771
-		elseif ($type == 'link')
1802
+		} elseif ($type == 'link')
1772 1803
 		{
1773 1804
 			$out='';
1774 1805
 
1775 1806
 			// Only if something to display (perf)
1776
-			if ($value)		// If we have -1 here, pb is into sert, not into ouptu
1807
+			if ($value) {
1808
+			    // If we have -1 here, pb is into sert, not into ouptu
1777 1809
 			{
1778
-				$param_list=array_keys($param['options']);				// $param_list='ObjectName:classPath'
1810
+				$param_list=array_keys($param['options']);
1811
+			}
1812
+			// $param_list='ObjectName:classPath'
1779 1813
 
1780 1814
 				$InfoFieldList = explode(":", $param_list[0]);
1781 1815
 				$classname=$InfoFieldList[0];
@@ -1789,30 +1823,27 @@  discard block
 block discarded – undo
1789 1823
 						$object->fetch($value);
1790 1824
 						$value=$object->getNomUrl(3);
1791 1825
 					}
1792
-				}
1793
-				else
1826
+				} else
1794 1827
 				{
1795 1828
 					dol_syslog('Error bad setup of extrafield', LOG_WARNING);
1796 1829
 					return 'Error bad setup of extrafield';
1797 1830
 				}
1798 1831
 			}
1799
-		}
1800
-		elseif ($type == 'text')
1832
+		} elseif ($type == 'text')
1801 1833
 		{
1802 1834
 			$value=dol_htmlentitiesbr($value);
1803
-		}
1804
-		elseif ($type == 'html')
1835
+		} elseif ($type == 'html')
1805 1836
 		{
1806 1837
 			$value=dol_htmlentitiesbr($value);
1807
-		}
1808
-		elseif ($type == 'password')
1838
+		} elseif ($type == 'password')
1809 1839
 		{
1810 1840
 			$value=dol_trunc(preg_replace('/./i','*',$value), 8, 'right', 'UTF-8', 1);
1811
-		}
1812
-		else
1841
+		} else
1813 1842
 		{
1814 1843
 			$showsize=round($size);
1815
-			if ($showsize > 48) $showsize=48;
1844
+			if ($showsize > 48) {
1845
+			    $showsize=48;
1846
+			}
1816 1847
 		}
1817 1848
 
1818 1849
 		//print $type.'-'.$size;
@@ -1832,40 +1863,36 @@  discard block
 block discarded – undo
1832 1863
 	{
1833 1864
 		global $conf,$langs;
1834 1865
 
1835
-		if (! empty($extrafieldsobjectkey)) $type=$this->attributes[$extrafieldsobjectkey]['type'][$key];
1836
-		else $type=$this->attribute_type[$key];
1866
+		if (! empty($extrafieldsobjectkey)) {
1867
+		    $type=$this->attributes[$extrafieldsobjectkey]['type'][$key];
1868
+		} else {
1869
+		    $type=$this->attribute_type[$key];
1870
+		}
1837 1871
 
1838 1872
 		$align='';
1839 1873
 
1840 1874
         if ($type == 'date')
1841 1875
 		{
1842 1876
 			$align="center";
1843
-		}
1844
-		elseif ($type == 'datetime')
1877
+		} elseif ($type == 'datetime')
1845 1878
 		{
1846 1879
 			$align="center";
1847
-		}
1848
-		elseif ($type == 'int')
1880
+		} elseif ($type == 'int')
1849 1881
 		{
1850 1882
 			$align="right";
1851
-		}
1852
-		elseif ($type == 'double')
1883
+		} elseif ($type == 'double')
1853 1884
 		{
1854 1885
 			$align="right";
1855
-		}
1856
-		elseif ($type == 'boolean')
1886
+		} elseif ($type == 'boolean')
1857 1887
 		{
1858 1888
 			$align="center";
1859
-		}
1860
-		elseif ($type == 'radio')
1889
+		} elseif ($type == 'radio')
1861 1890
 		{
1862 1891
 			$align="center";
1863
-		}
1864
-		elseif ($type == 'checkbox')
1892
+		} elseif ($type == 'checkbox')
1865 1893
 		{
1866 1894
 			$align="center";
1867
-		}
1868
-		elseif ($type == 'price')
1895
+		} elseif ($type == 'price')
1869 1896
 		{
1870 1897
 			$align="right";
1871 1898
 		}
@@ -1904,17 +1931,23 @@  discard block
 block discarded – undo
1904 1931
 		$nofillrequired='';// For error when required field left blank
1905 1932
 		$error_field_required = array();
1906 1933
 
1907
-		if (is_array($this->attributes[$object->table_element]['label'])) $extralabels=$this->attributes[$object->table_element]['label'];
1934
+		if (is_array($this->attributes[$object->table_element]['label'])) {
1935
+		    $extralabels=$this->attributes[$object->table_element]['label'];
1936
+		}
1908 1937
 
1909 1938
 		if (is_array($extralabels))
1910 1939
 		{
1911 1940
 			// Get extra fields
1912 1941
 			foreach ($extralabels as $key => $value)
1913 1942
 			{
1914
-				if (! empty($onlykey) && $key != $onlykey) continue;
1943
+				if (! empty($onlykey) && $key != $onlykey) {
1944
+				    continue;
1945
+				}
1915 1946
 
1916 1947
 				$key_type = $this->attributes[$object->table_element]['type'][$key];
1917
-				if ($key_type == 'separate') continue;
1948
+				if ($key_type == 'separate') {
1949
+				    continue;
1950
+				}
1918 1951
 
1919 1952
 				$enabled = 1;
1920 1953
 				if (isset($this->attributes[$object->table_element]['list'][$key]))
@@ -1926,10 +1959,15 @@  discard block
 block discarded – undo
1926 1959
 				{
1927 1960
 					$perms = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1);
1928 1961
 				}
1929
-				if (empty($enabled)) continue;
1930
-				if (empty($perms)) continue;
1962
+				if (empty($enabled)) {
1963
+				    continue;
1964
+				}
1965
+				if (empty($perms)) {
1966
+				    continue;
1967
+				}
1931 1968
 
1932
-				if ($this->attributes[$object->table_element]['required'][$key])	// Value is required
1969
+				if ($this->attributes[$object->table_element]['required'][$key]) {
1970
+				    // Value is required
1933 1971
 				{
1934 1972
 					// Check if empty without using GETPOST, value can be alpha, int, array, etc...
1935 1973
 					if ((! is_array($_POST["options_".$key]) && empty($_POST["options_".$key]) && $_POST["options_".$key] != '0')
@@ -1937,6 +1975,7 @@  discard block
 block discarded – undo
1937 1975
 					{
1938 1976
 						//print 'ccc'.$value.'-'.$this->attributes[$object->table_element]['required'][$key];
1939 1977
 						$nofillrequired++;
1978
+				}
1940 1979
 						$error_field_required[] = $langs->transnoentitiesnoconv($value);
1941 1980
 					}
1942 1981
 				}
@@ -1946,28 +1985,24 @@  discard block
 block discarded – undo
1946 1985
 					// Clean parameters
1947 1986
 					// TODO GMT date in memory must be GMT so we should add gm=true in parameters
1948 1987
 					$value_key=dol_mktime(0, 0, 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]);
1949
-				}
1950
-				elseif (in_array($key_type,array('datetime')))
1988
+				} elseif (in_array($key_type,array('datetime')))
1951 1989
 				{
1952 1990
 					// Clean parameters
1953 1991
 					// TODO GMT date in memory must be GMT so we should add gm=true in parameters
1954 1992
 					$value_key=dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]);
1955
-				}
1956
-				else if (in_array($key_type,array('checkbox','chkbxlst')))
1993
+				} else if (in_array($key_type,array('checkbox','chkbxlst')))
1957 1994
 				{
1958 1995
 					$value_arr=GETPOST("options_".$key, 'array'); // check if an array
1959 1996
 					if (!empty($value_arr)) {
1960 1997
 						$value_key=implode($value_arr,',');
1961
-					}else {
1998
+					} else {
1962 1999
 						$value_key='';
1963 2000
 					}
1964
-				}
1965
-				else if (in_array($key_type,array('price','double')))
2001
+				} else if (in_array($key_type,array('price','double')))
1966 2002
 				{
1967 2003
 					$value_arr=GETPOST("options_".$key, 'alpha');
1968 2004
 					$value_key=price2num($value_arr);
1969
-				}
1970
-				else
2005
+				} else
1971 2006
 				{
1972 2007
 					$value_key=GETPOST("options_".$key);
1973 2008
 				}
@@ -1979,12 +2014,10 @@  discard block
 block discarded – undo
1979 2014
 				$langs->load('errors');
1980 2015
 				setEventMessages($langs->trans('ErrorFieldsRequired').' : '.implode(', ',$error_field_required), null, 'errors');
1981 2016
 				return -1;
1982
-			}
1983
-			else {
2017
+			} else {
1984 2018
 				return 1;
1985 2019
 			}
1986
-		}
1987
-		else {
2020
+		} else {
1988 2021
 			return 0;
1989 2022
 		}
1990 2023
 	}
@@ -2004,8 +2037,7 @@  discard block
 block discarded – undo
2004 2037
 		if (is_string($extrafieldsobjectkey) && is_array($this->attributes[$extrafieldsobjectkey]['label']))
2005 2038
 		{
2006 2039
 			$extralabels = $this->attributes[$extrafieldsobjectkey]['label'];
2007
-		}
2008
-		else
2040
+		} else
2009 2041
 		{
2010 2042
 			$extralabels = $extrafieldsobjectkey;
2011 2043
 		}
@@ -2027,20 +2059,17 @@  discard block
 block discarded – undo
2027 2059
 				{
2028 2060
 					// Clean parameters
2029 2061
 					$value_key=dol_mktime($_POST[$keysuffix."options_".$key.$keyprefix."hour"], $_POST[$keysuffix."options_".$key.$keyprefix."min"], 0, $_POST[$keysuffix."options_".$key.$keyprefix."month"], $_POST[$keysuffix."options_".$key.$keyprefix."day"], $_POST[$keysuffix."options_".$key.$keyprefix."year"]);
2030
-				}
2031
-				else if (in_array($key_type,array('checkbox', 'chkbxlst')))
2062
+				} else if (in_array($key_type,array('checkbox', 'chkbxlst')))
2032 2063
 				{
2033 2064
 					$value_arr=GETPOST($keysuffix."options_".$key.$keyprefix);
2034 2065
 					// Make sure we get an array even if there's only one checkbox
2035 2066
 					$value_arr=(array) $value_arr;
2036 2067
 					$value_key=implode(',', $value_arr);
2037
-				}
2038
-				else if (in_array($key_type,array('price','double')))
2068
+				} else if (in_array($key_type,array('price','double')))
2039 2069
 				{
2040 2070
 					$value_arr=GETPOST($keysuffix."options_".$key.$keyprefix);
2041 2071
 					$value_key=price2num($value_arr);
2042
-				}
2043
-				else
2072
+				} else
2044 2073
 				{
2045 2074
 					$value_key=GETPOST($keysuffix."options_".$key.$keyprefix);
2046 2075
 				}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/events.class.php 1 patch
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -137,7 +137,9 @@  discard block
 block discarded – undo
137 137
 
138 138
 		// Clean parameters
139 139
 		$this->description=trim($this->description);
140
-		if (empty($this->user_agent) && !empty($_SERVER['HTTP_USER_AGENT'])) $this->user_agent=$_SERVER['HTTP_USER_AGENT'];
140
+		if (empty($this->user_agent) && !empty($_SERVER['HTTP_USER_AGENT'])) {
141
+		    $this->user_agent=$_SERVER['HTTP_USER_AGENT'];
142
+		}
141 143
 
142 144
 		// Check parameters
143 145
 		if (empty($this->description)) { $this->error='ErrorBadValueForParameterCreateEventDesc'; return -1; }
@@ -167,8 +169,7 @@  discard block
 block discarded – undo
167 169
 		{
168 170
 			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."events");
169 171
 			return $this->id;
170
-		}
171
-		else
172
+		} else
172 173
 		{
173 174
 			$this->error="Error ".$this->db->lasterror();
174 175
 			return -1;
@@ -256,8 +257,7 @@  discard block
 block discarded – undo
256 257
 			$this->db->free($resql);
257 258
 
258 259
 			return 1;
259
-		}
260
-		else
260
+		} else
261 261
 		{
262 262
 			$this->error="Error ".$this->db->lasterror();
263 263
 			return -1;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/ctyperesource.class.php 1 patch
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -172,9 +172,13 @@
 block discarded – undo
172 172
 
173 173
 
174 174
 		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
175
-		if ($id)   $sql.= " WHERE t.id = ".$id;
176
-		elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
177
-		elseif ($label) $sql.= " WHERE t.label = '".$this->db->escape($label)."'";
175
+		if ($id) {
176
+		    $sql.= " WHERE t.id = ".$id;
177
+		} elseif ($code) {
178
+		    $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
179
+		} elseif ($label) {
180
+		    $sql.= " WHERE t.label = '".$this->db->escape($label)."'";
181
+		}
178 182
 
179 183
 
180 184
 		$resql = $this->db->query($sql);
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formsms.class.php 1 patch
Braces   +31 added lines, -28 removed lines patch added patch discarded remove patch
@@ -105,7 +105,9 @@  discard block
 block discarded – undo
105 105
      // phpcs:enable
106 106
         global $conf, $langs, $user, $form;
107 107
 
108
-        if (! is_object($form)) $form=new Form($this->db);
108
+        if (! is_object($form)) {
109
+            $form=new Form($this->db);
110
+        }
109 111
 
110 112
         // Load translation files required by the page
111 113
         $langs->loadLangs(array('other', 'mails', 'sms'));
@@ -131,7 +133,9 @@  discard block
 block discarded – undo
131 133
 }
132 134
 </script>';
133 135
 
134
-        if ($showform) print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n";
136
+        if ($showform) {
137
+            print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n";
138
+        }
135 139
 
136 140
         print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
137 141
         foreach ($this->param as $key=>$value)
@@ -141,9 +145,11 @@  discard block
 block discarded – undo
141 145
         print "<table class=\"border centpercent\">\n";
142 146
 
143 147
         // Substitution array
144
-        if (! empty($this->withsubstit))		// Unset or set ->withsubstit=0 to disable this.
148
+        if (! empty($this->withsubstit)) {
149
+            // Unset or set ->withsubstit=0 to disable this.
145 150
         {
146 151
             print "<tr><td colspan=\"2\">";
152
+        }
147 153
             $help="";
148 154
             foreach($this->substit as $key => $val)
149 155
             {
@@ -172,8 +178,7 @@  discard block
 block discarded – undo
172 178
                 if ($this->fromsms)
173 179
                 {
174 180
                     print $this->fromsms;
175
-                }
176
-                else
181
+                } else
177 182
                 {
178 183
                     if ($this->fromtype)
179 184
                     {
@@ -183,34 +188,34 @@  discard block
 block discarded – undo
183 188
                 }
184 189
                 print "</td></tr>\n";
185 190
                 print "</td></tr>\n";
186
-            }
187
-            else
191
+            } else
188 192
             {
189 193
                 print '<tr><td class="'.$morecss.'">'.$langs->trans("SmsFrom")."</td><td>";
190 194
                 //print '<input type="text" name="fromname" size="30" value="'.$this->fromsms.'">';
191
-                if ($conf->global->MAIN_SMS_SENDMODE == 'ovh')        // For backward compatibility        @deprecated
195
+                if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') {
196
+                    // For backward compatibility        @deprecated
192 197
                 {
193 198
                     dol_include_once('/ovh/class/ovhsms.class.php');
199
+                }
194 200
                     try
195 201
                     {
196 202
                         $sms = new OvhSms($this->db);
197 203
                         if (empty($conf->global->OVHSMS_ACCOUNT))
198 204
                         {
199 205
                             $resultsender = 'ErrorOVHSMS_ACCOUNT not defined';
200
-                        }
201
-                        else
206
+                        } else
202 207
                         {
203 208
                             $resultsender = $sms->SmsSenderList();
204 209
                         }
205
-                    }
206
-                    catch(Exception $e)
210
+                    } catch(Exception $e)
207 211
                     {
208 212
                         dol_print_error('','Error to get list of senders: '.$e->getMessage());
209 213
                     }
210
-                }
211
-                else if (!empty($conf->global->MAIN_SMS_SENDMODE))    // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
214
+                } else if (!empty($conf->global->MAIN_SMS_SENDMODE)) {
215
+                    // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
212 216
                 {
213 217
                     $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE);
218
+                }
214 219
                     $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]);
215 220
                     dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
216 221
                     try
@@ -220,20 +225,17 @@  discard block
 block discarded – undo
220 225
                         {
221 226
                         	$sms = new $classname($this->db);
222 227
                         	$resultsender = $sms->SmsSenderList();
223
-                        }
224
-                        else
228
+                        } else
225 229
                         {
226 230
                         	$sms = new stdClass();
227 231
                         	$sms->error='The SMS manager "'.$classfile.'" defined into SMS setup MAIN_SMS_SENDMODE is not found';
228 232
                         }
229
-                    }
230
-                    catch(Exception $e)
233
+                    } catch(Exception $e)
231 234
                     {
232 235
                         dol_print_error('','Error to get list of senders: '.$e->getMessage());
233 236
                         exit;
234 237
                     }
235
-                }
236
-                else
238
+                } else
237 239
                 {
238 240
                     dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING);
239 241
 	                $resultsender=array();
@@ -248,11 +250,12 @@  discard block
 block discarded – undo
248 250
                         print '<option value="'.$obj->number.'">'.$obj->number.'</option>';
249 251
                     }
250 252
                     print '</select>';
251
-                }
252
-                else
253
+                } else
253 254
                 {
254 255
                     print '<span class="error">'.$langs->trans("SmsNoPossibleSenderFound");
255
-                    if (is_object($sms) && ! empty($sms->error)) print ' '.$sms->error;
256
+                    if (is_object($sms) && ! empty($sms->error)) {
257
+                        print ' '.$sms->error;
258
+                    }
256 259
                     print '</span>';
257 260
                 }
258 261
                 print '</td>';
@@ -271,8 +274,7 @@  discard block
 block discarded – undo
271 274
             if ($this->withtoreadonly)
272 275
             {
273 276
                 print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
274
-            }
275
-            else
277
+            } else
276 278
             {
277 279
                 print "<input size=\"16\" id=\"sendto\" name=\"sendto\" value=\"".dol_escape_htmltag(! is_array($this->withto) && $this->withto != '1'? (isset($_REQUEST["sendto"])?GETPOST("sendto"):$this->withto):"+")."\">";
278 280
                 if (! empty($this->withtosocid) && $this->withtosocid > 0)
@@ -300,7 +302,9 @@  discard block
 block discarded – undo
300 302
                 $defaultmessage=$this->withbody;
301 303
             }
302 304
             $defaultmessage=make_substitutions($defaultmessage,$this->substit);
303
-            if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
305
+            if (isset($_POST["message"])) {
306
+                $defaultmessage=$_POST["message"];
307
+            }
304 308
             $defaultmessage=str_replace('\n',"\n",$defaultmessage);
305 309
 
306 310
             print "<tr>";
@@ -310,8 +314,7 @@  discard block
 block discarded – undo
310 314
             {
311 315
                 print nl2br($defaultmessage);
312 316
                 print '<input type="hidden" name="message" value="'.dol_escape_htmltag($defaultmessage).'">';
313
-            }
314
-            else
317
+            } else
315 318
             {
316 319
                 print '<textarea class="quatrevingtpercent" name="message" id="message" rows="'.ROWS_4.'" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">'.$defaultmessage.'</textarea>';
317 320
                 print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160-dol_strlen($defaultmessage)).'</span></div></td>';
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/rssparser.class.php 1 patch
Braces   +148 added lines, -107 removed lines patch added patch discarded remove patch
@@ -218,19 +218,19 @@  discard block
 block discarded – undo
218 218
                 $foundintocache=1;
219 219
 
220 220
                 $this->_lastfetchdate=$filedate;
221
-            }
222
-            else
221
+            } else
223 222
             {
224 223
                 dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it.");
225 224
             }
226 225
         }
227 226
 
228 227
         // Load file into $str
229
-        if ($foundintocache)    // Cache file found and is not too old
228
+        if ($foundintocache) {
229
+            // Cache file found and is not too old
230 230
         {
231 231
             $str = file_get_contents($newpathofdestfile);
232 232
         }
233
-        else
233
+        } else
234 234
         {
235 235
             try {
236 236
                 ini_set("user_agent","Dolibarr ERP-CRM RSS reader");
@@ -238,14 +238,17 @@  discard block
 block discarded – undo
238 238
                 ini_set("default_socket_timeout", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
239 239
 
240 240
                 $opts = array('http'=>array('method'=>"GET"));
241
-                if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT;
242
-                if (! empty($conf->global->MAIN_PROXY_USE))           $opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
241
+                if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) {
242
+                    $opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT;
243
+                }
244
+                if (! empty($conf->global->MAIN_PROXY_USE)) {
245
+                    $opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
246
+                }
243 247
                 //var_dump($opts);exit;
244 248
                 $context = stream_context_create($opts);
245 249
 
246 250
                 $str = file_get_contents($this->_urlRSS, false, $context);
247
-            }
248
-            catch (Exception $e) {
251
+            } catch (Exception $e) {
249 252
                 print 'Error retrieving URL '.$this->urlRSS.' - '.$e->getMessage();
250 253
             }
251 254
         }
@@ -258,8 +261,7 @@  discard block
 block discarded – undo
258 261
 	            //print 'xx'.LIBXML_NOCDATA;
259 262
 	            libxml_use_internal_errors(false);
260 263
 	            $rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA);
261
-	        }
262
-	        else
264
+	        } else
263 265
 	        {
264 266
 	            $xmlparser=xml_parser_create('');
265 267
 	            if (!is_resource($xmlparser)) {
@@ -283,18 +285,21 @@  discard block
 block discarded – undo
283 285
             if (empty($foundintocache) && $cachedir)
284 286
             {
285 287
                 dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is saved onto disk.");
286
-                if (! dol_is_dir($cachedir)) dol_mkdir($cachedir);
288
+                if (! dol_is_dir($cachedir)) {
289
+                    dol_mkdir($cachedir);
290
+                }
287 291
                 $fp = fopen($newpathofdestfile, 'w');
288 292
                 if ($fp)
289 293
                 {
290 294
                 	fwrite($fp, $str);
291 295
                 	fclose($fp);
292
-                	if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
296
+                	if (! empty($conf->global->MAIN_UMASK)) {
297
+                	    $newmask=$conf->global->MAIN_UMASK;
298
+                	}
293 299
                 	@chmod($newpathofdestfile, octdec($newmask));
294 300
 
295 301
 	                $this->_lastfetchdate=$nowgmt;
296
-                }
297
-                else
302
+                } else
298 303
                 {
299 304
                 	print 'Error, failed to open file '.$newpathofdestfile.' for write';
300 305
                 }
@@ -302,10 +307,14 @@  discard block
 block discarded – undo
302 307
 
303 308
             unset($str);    // Free memory
304 309
 
305
-            if (empty($rss->_format))    // If format not detected automatically
310
+            if (empty($rss->_format)) {
311
+                // If format not detected automatically
306 312
             {
307 313
                 $rss->_format='rss';
308
-                if (empty($rss->channel)) $rss->_format='atom';
314
+            }
315
+                if (empty($rss->channel)) {
316
+                    $rss->_format='atom';
317
+                }
309 318
             }
310 319
 
311 320
             $items=array();
@@ -316,58 +325,114 @@  discard block
 block discarded – undo
316 325
                 //var_dump($rss);
317 326
                 if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
318 327
                 {
319
-                    if (!empty($rss->channel->language))      $this->_language = (string) $rss->channel->language;
320
-                    if (!empty($rss->channel->generator))     $this->_generator = (string) $rss->channel->generator;
321
-                    if (!empty($rss->channel->copyright))     $this->_copyright = (string) $rss->channel->copyright;
322
-                    if (!empty($rss->channel->lastbuilddate)) $this->_lastbuilddate = (string) $rss->channel->lastbuilddate;
323
-                    if (!empty($rss->channel->image->url[0])) $this->_imageurl = (string) $rss->channel->image->url[0];
324
-                    if (!empty($rss->channel->link))		  $this->_link = (string) $rss->channel->link;
325
-                    if (!empty($rss->channel->title))         $this->_title = (string) $rss->channel->title;
326
-                    if (!empty($rss->channel->description))	  $this->_description = (string) $rss->channel->description;
327
-                }
328
-                else
328
+                    if (!empty($rss->channel->language)) {
329
+                        $this->_language = (string) $rss->channel->language;
330
+                    }
331
+                    if (!empty($rss->channel->generator)) {
332
+                        $this->_generator = (string) $rss->channel->generator;
333
+                    }
334
+                    if (!empty($rss->channel->copyright)) {
335
+                        $this->_copyright = (string) $rss->channel->copyright;
336
+                    }
337
+                    if (!empty($rss->channel->lastbuilddate)) {
338
+                        $this->_lastbuilddate = (string) $rss->channel->lastbuilddate;
339
+                    }
340
+                    if (!empty($rss->channel->image->url[0])) {
341
+                        $this->_imageurl = (string) $rss->channel->image->url[0];
342
+                    }
343
+                    if (!empty($rss->channel->link)) {
344
+                        $this->_link = (string) $rss->channel->link;
345
+                    }
346
+                    if (!empty($rss->channel->title)) {
347
+                        $this->_title = (string) $rss->channel->title;
348
+                    }
349
+                    if (!empty($rss->channel->description)) {
350
+                        $this->_description = (string) $rss->channel->description;
351
+                    }
352
+                } else
329 353
                 {
330 354
                     //var_dump($rss->channel);
331
-                    if (!empty($rss->channel['language']))      $this->_language = (string) $rss->channel['language'];
332
-                    if (!empty($rss->channel['generator']))     $this->_generator = (string) $rss->channel['generator'];
333
-                    if (!empty($rss->channel['copyright']))     $this->_copyright = (string) $rss->channel['copyright'];
334
-                    if (!empty($rss->channel['lastbuilddate'])) $this->_lastbuilddate = (string) $rss->channel['lastbuilddate'];
335
-                    if (!empty($rss->image['url']))             $this->_imageurl = (string) $rss->image['url'];
336
-                    if (!empty($rss->channel['link']))		    $this->_link = (string) $rss->channel['link'];
337
-                    if (!empty($rss->channel['title']))         $this->_title = (string) $rss->channel['title'];
338
-                    if (!empty($rss->channel['description']))   $this->_description = (string) $rss->channel['description'];
355
+                    if (!empty($rss->channel['language'])) {
356
+                        $this->_language = (string) $rss->channel['language'];
357
+                    }
358
+                    if (!empty($rss->channel['generator'])) {
359
+                        $this->_generator = (string) $rss->channel['generator'];
360
+                    }
361
+                    if (!empty($rss->channel['copyright'])) {
362
+                        $this->_copyright = (string) $rss->channel['copyright'];
363
+                    }
364
+                    if (!empty($rss->channel['lastbuilddate'])) {
365
+                        $this->_lastbuilddate = (string) $rss->channel['lastbuilddate'];
366
+                    }
367
+                    if (!empty($rss->image['url'])) {
368
+                        $this->_imageurl = (string) $rss->image['url'];
369
+                    }
370
+                    if (!empty($rss->channel['link'])) {
371
+                        $this->_link = (string) $rss->channel['link'];
372
+                    }
373
+                    if (!empty($rss->channel['title'])) {
374
+                        $this->_title = (string) $rss->channel['title'];
375
+                    }
376
+                    if (!empty($rss->channel['description'])) {
377
+                        $this->_description = (string) $rss->channel['description'];
378
+                    }
339 379
                 }
340 380
 
341
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) $items=$rss->channel->item;    // With simplexml
342
-                else $items=$rss->items;                                                              // With xmlparse
381
+                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) {
382
+                    $items=$rss->channel->item;
383
+                }
384
+                // With simplexml
385
+                else {
386
+                    $items=$rss->items;
387
+                }
388
+                // With xmlparse
343 389
                 //var_dump($items);exit;
344
-            }
345
-            else if ($rss->_format == 'atom')
390
+            } else if ($rss->_format == 'atom')
346 391
             {
347 392
                 //var_dump($rss);
348 393
                 if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
349 394
                 {
350
-                    if (!empty($rss->generator))     $this->_generator = (string) $rss->generator;
351
-                    if (!empty($rss->lastbuilddate)) $this->_lastbuilddate = (string) $rss->modified;
352
-                    if (!empty($rss->link->href))    $this->_link = (string) $rss->link->href;
353
-                    if (!empty($rss->title))         $this->_title = (string) $rss->title;
354
-                    if (!empty($rss->description))	 $this->_description = (string) $rss->description;
355
-                }
356
-                else
395
+                    if (!empty($rss->generator)) {
396
+                        $this->_generator = (string) $rss->generator;
397
+                    }
398
+                    if (!empty($rss->lastbuilddate)) {
399
+                        $this->_lastbuilddate = (string) $rss->modified;
400
+                    }
401
+                    if (!empty($rss->link->href)) {
402
+                        $this->_link = (string) $rss->link->href;
403
+                    }
404
+                    if (!empty($rss->title)) {
405
+                        $this->_title = (string) $rss->title;
406
+                    }
407
+                    if (!empty($rss->description)) {
408
+                        $this->_description = (string) $rss->description;
409
+                    }
410
+                } else
357 411
                 {
358 412
                     //if (!empty($rss->channel['rss_language']))      $this->_language = (string) $rss->channel['rss_language'];
359
-                    if (!empty($rss->channel['generator']))     $this->_generator = (string) $rss->channel['generator'];
413
+                    if (!empty($rss->channel['generator'])) {
414
+                        $this->_generator = (string) $rss->channel['generator'];
415
+                    }
360 416
                     //if (!empty($rss->channel['rss_copyright']))     $this->_copyright = (string) $rss->channel['rss_copyright'];
361
-                    if (!empty($rss->channel['modified'])) $this->_lastbuilddate = (string) $rss->channel['modified'];
417
+                    if (!empty($rss->channel['modified'])) {
418
+                        $this->_lastbuilddate = (string) $rss->channel['modified'];
419
+                    }
362 420
                     //if (!empty($rss->image['rss_url']))             $this->_imageurl = (string) $rss->image['rss_url'];
363
-                    if (!empty($rss->channel['link']))		    $this->_link = (string) $rss->channel['link'];
364
-                    if (!empty($rss->channel['title']))         $this->_title = (string) $rss->channel['title'];
421
+                    if (!empty($rss->channel['link'])) {
422
+                        $this->_link = (string) $rss->channel['link'];
423
+                    }
424
+                    if (!empty($rss->channel['title'])) {
425
+                        $this->_title = (string) $rss->channel['title'];
426
+                    }
365 427
                     //if (!empty($rss->channel['rss_description']))   $this->_description = (string) $rss->channel['rss_description'];
366 428
                 }
367 429
                 if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))  {
368 430
                     $tmprss=xml2php($rss); $items=$tmprss['entry'];
369 431
                 } // With simplexml
370
-                else $items=$rss->items;                                                              // With xmlparse
432
+                else {
433
+                    $items=$rss->items;
434
+                }
435
+                // With xmlparse
371 436
                 //var_dump($items);exit;
372 437
             }
373 438
 
@@ -389,8 +454,7 @@  discard block
 block discarded – undo
389 454
                             $itemPubDate = (string) $item->pubDate;
390 455
                             $itemId = '';
391 456
                             $itemAuthor = '';
392
-                        }
393
-                        else
457
+                        } else
394 458
                         {
395 459
                             $itemLink = (string) $item['link'];
396 460
                             $itemTitle = (string) $item['title'];
@@ -409,8 +473,7 @@  discard block
 block discarded – undo
409 473
                                 $itemCategory[] = (string) $cat;
410 474
                             }
411 475
                         }
412
-                    }
413
-                    else if ($rss->_format == 'atom')
476
+                    } else if ($rss->_format == 'atom')
414 477
                     {
415 478
                         if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
416 479
                         {
@@ -420,8 +483,7 @@  discard block
 block discarded – undo
420 483
                             $itemPubDate = (string) $item['created'];
421 484
                             $itemId = (string) $item['id'];
422 485
                             $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
423
-                        }
424
-                        else
486
+                        } else
425 487
                         {
426 488
                             $itemLink = (isset($item['link']['href']) ? (string) $item['link']['href'] : '');
427 489
                             $itemTitle = (string) $item['title'];
@@ -430,8 +492,9 @@  discard block
 block discarded – undo
430 492
                             $itemId = (string) $item['id'];
431 493
                             $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
432 494
                         }
495
+                    } else {
496
+                        print 'ErrorBadFeedFormat';
433 497
                     }
434
-                    else print 'ErrorBadFeedFormat';
435 498
 
436 499
                     // Add record to result array
437 500
                     $this->_rssarray[$i] = array(
@@ -446,13 +509,15 @@  discard block
 block discarded – undo
446 509
 
447 510
                     $i++;
448 511
 
449
-                    if ($i > $maxNb)    break;    // We get all records we want
512
+                    if ($i > $maxNb) {
513
+                        break;
514
+                    }
515
+                    // We get all records we want
450 516
                 }
451 517
             }
452 518
 
453 519
             return 1;
454
-        }
455
-        else
520
+        } else
456 521
         {
457 522
             $this->error='ErrorFailedToLoadRSSFile';
458 523
             return -1;
@@ -493,12 +558,10 @@  discard block
 block discarded – undo
493 558
             if ( $el == 'rdf' ) {
494 559
                 $this->_format = 'rss';
495 560
                 $this->feed_version = '1.0';
496
-            }
497
-            elseif ( $el == 'rss' ) {
561
+            } elseif ( $el == 'rss' ) {
498 562
                 $this->_format = 'rss';
499 563
                 $this->feed_version = $attrs['version'];
500
-            }
501
-            elseif ( $el == 'feed' ) {
564
+            } elseif ( $el == 'feed' ) {
502 565
                 $this->_format = 'atom';
503 566
                 $this->feed_version = $attrs['version'];
504 567
                 $this->inchannel = true;
@@ -509,8 +572,7 @@  discard block
 block discarded – undo
509 572
         if ( $el == 'channel' )
510 573
         {
511 574
             $this->inchannel = true;
512
-        }
513
-        elseif ($el == 'item' or $el == 'entry' )
575
+        } elseif ($el == 'item' or $el == 'entry' )
514 576
         {
515 577
             $this->initem = true;
516 578
             if ( isset($attrs['rdf:about']) ) {
@@ -526,9 +588,7 @@  discard block
 block discarded – undo
526 588
         $el == 'textinput' )
527 589
         {
528 590
             $this->intextinput = true;
529
-        }
530
-
531
-        elseif (
591
+        } elseif (
532 592
         $this->_format == 'rss' and
533 593
         $this->current_namespace == '' and
534 594
         $el == 'image' )
@@ -567,8 +627,7 @@  discard block
 block discarded – undo
567 627
             if ( isset($attrs['rel']) && $attrs['rel'] == 'alternate' )
568 628
             {
569 629
                 $link_el = 'link';
570
-            }
571
-            else {
630
+            } else {
572 631
                 $link_el = 'link_' . $attrs['rel'];
573 632
             }
574 633
 
@@ -595,8 +654,7 @@  discard block
 block discarded – undo
595 654
         if ($this->_format == 'atom' and $this->incontent)
596 655
         {
597 656
             $this->append_content($text);
598
-        }
599
-        else
657
+        } else
600 658
         {
601 659
             $current_el = join('_', array_reverse($this->stack));
602 660
             $this->append($current_el, $text);
@@ -621,37 +679,30 @@  discard block
 block discarded – undo
621 679
             $this->items[] = $this->current_item;
622 680
             $this->current_item = array();
623 681
             $this->initem = false;
624
-        }
625
-        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' )
682
+        } elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' )
626 683
         {
627 684
             $this->intextinput = false;
628
-        }
629
-        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' )
685
+        } elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' )
630 686
         {
631 687
             $this->inimage = false;
632
-        }
633
-        elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
688
+        } elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
634 689
         {
635 690
             $this->incontent = false;
636
-        }
637
-        elseif ($el == 'channel' or $el == 'feed' )
691
+        } elseif ($el == 'channel' or $el == 'feed' )
638 692
         {
639 693
             $this->inchannel = false;
640
-        }
641
-        elseif ($this->_format == 'atom' and $this->incontent  ) {
694
+        } elseif ($this->_format == 'atom' and $this->incontent  ) {
642 695
             // balance tags properly
643 696
             // note:  i don't think this is actually neccessary
644 697
             if ( $this->stack[0] == $el )
645 698
             {
646 699
                 $this->append_content("</$el>");
647
-            }
648
-            else {
700
+            } else {
649 701
                 $this->append_content("<$el />");
650 702
             }
651 703
 
652 704
             array_shift($this->stack);
653
-        }
654
-        else {
705
+        } else {
655 706
             array_shift($this->stack);
656 707
         }
657 708
 
@@ -686,8 +737,7 @@  discard block
 block discarded – undo
686 737
         // phpcs:enable
687 738
         if ( $this->initem ) {
688 739
             $this->concat($this->current_item[ $this->incontent ], $text);
689
-        }
690
-        elseif ( $this->inchannel ) {
740
+        } elseif ( $this->inchannel ) {
691 741
             $this->concat($this->channel[ $this->incontent ], $text);
692 742
         }
693 743
     }
@@ -708,28 +758,21 @@  discard block
 block discarded – undo
708 758
         {
709 759
             if ( $this->initem ) {
710 760
                 $this->concat($this->current_item[ $this->current_namespace ][ $el ], $text);
711
-            }
712
-            elseif ($this->inchannel) {
761
+            } elseif ($this->inchannel) {
713 762
                 $this->concat($this->channel[ $this->current_namespace][ $el ], $text);
714
-            }
715
-            elseif ($this->intextinput) {
763
+            } elseif ($this->intextinput) {
716 764
                 $this->concat($this->textinput[ $this->current_namespace][ $el ], $text);
717
-            }
718
-            elseif ($this->inimage) {
765
+            } elseif ($this->inimage) {
719 766
                 $this->concat($this->image[ $this->current_namespace ][ $el ], $text);
720 767
             }
721
-        }
722
-        else {
768
+        } else {
723 769
             if ( $this->initem ) {
724 770
                 $this->concat($this->current_item[ $el ], $text);
725
-            }
726
-            elseif ($this->intextinput) {
771
+            } elseif ($this->intextinput) {
727 772
                 $this->concat($this->textinput[ $el ], $text);
728
-            }
729
-            elseif ($this->inimage) {
773
+            } elseif ($this->inimage) {
730 774
                 $this->concat($this->image[ $el ], $text);
731
-            }
732
-            elseif ($this->inchannel) {
775
+            } elseif ($this->inchannel) {
733 776
                 $this->concat($this->channel[ $el ], $text);
734 777
             }
735 778
         }
@@ -767,13 +810,11 @@  discard block
 block discarded – undo
767 810
             $array[$key][] = $tmp;
768 811
             $array[$key][] = $child;
769 812
             $tab = true;
770
-        }
771
-        elseif($tab === true)
813
+        } elseif($tab === true)
772 814
         {
773 815
             //Add an element in an existing array
774 816
             $array[$key][] = $child;
775
-        }
776
-        else
817
+        } else
777 818
         {
778 819
             //Add a simple element
779 820
             $array[$key] = $child;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/menu.class.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -120,7 +120,9 @@
 block discarded – undo
120 120
         $nb=0;
121 121
         foreach($this->liste as $val)
122 122
         {
123
-            if (! empty($val['enabled'])) $nb++;
123
+            if (! empty($val['enabled'])) {
124
+                $nb++;
125
+            }
124 126
         }
125 127
         return $nb;
126 128
     }
Please login to merge, or discard this patch.