Passed
Push — master ( 284492...2c3033 )
by Alxarafe
27:10
created
Base/AlixarModel.php 1 patch
Braces   +1153 added lines, -407 removed lines patch added patch discarded remove patch
@@ -342,22 +342,30 @@  discard block
 block discarded – undo
342 342
         $sql .= " FROM " . MAIN_DB_PREFIX . $element;
343 343
         $sql .= " WHERE entity IN (" . getEntity($element) . ")";
344 344
 
345
-        if ($id > 0) $sql .= " AND rowid = " . $db->escape($id);
346
-        else if ($ref) $sql .= " AND ref = '" . $db->escape($ref) . "'";
347
-        else if ($ref_ext) $sql .= " AND ref_ext = '" . $db->escape($ref_ext) . "'";
348
-        else {
345
+        if ($id > 0) {
346
+            $sql .= " AND rowid = " . $db->escape($id);
347
+        } else if ($ref) {
348
+            $sql .= " AND ref = '" . $db->escape($ref) . "'";
349
+        } else if ($ref_ext) {
350
+            $sql .= " AND ref_ext = '" . $db->escape($ref_ext) . "'";
351
+        } else {
349 352
             $error = 'ErrorWrongParameters';
350 353
             dol_print_error(get_class() . "::isExistingObject " . $error, LOG_ERR);
351 354
             return -1;
352 355
         }
353
-        if ($ref || $ref_ext) $sql .= " AND entity = " . $conf->entity;
356
+        if ($ref || $ref_ext) {
357
+            $sql .= " AND entity = " . $conf->entity;
358
+        }
354 359
 
355 360
         dol_syslog(get_class() . "::isExistingObject", LOG_DEBUG);
356 361
         $resql = $db->query($sql);
357 362
         if ($resql) {
358 363
             $num = $db->num_rows($resql);
359
-            if ($num > 0) return 1;
360
-            else return 0;
364
+            if ($num > 0) {
365
+                return 1;
366
+            } else {
367
+                return 0;
368
+            }
361 369
         }
362 370
         return -1;
363 371
     }
@@ -380,7 +388,10 @@  discard block
 block discarded – undo
380 388
             $sql = 'UPDATE ' . MAIN_DB_PREFIX . $table . ' SET fk_soc = ' . $dest_id . ' WHERE fk_soc = ' . $origin_id;
381 389
 
382 390
             if (!$db->query($sql)) {
383
-                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.
391
+                if ($ignoreerrors) {
392
+                    return true;
393
+                }
394
+                // 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.
384 395
                 //$this->errors = $db->lasterror();
385 396
                 return false;
386 397
             }
@@ -453,7 +464,9 @@  discard block
 block discarded – undo
453 464
             $outdone++;
454 465
         }
455 466
 
456
-        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>' : '');
467
+        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)) {
468
+            $out .= ($outdone ? '<br>' : '');
469
+        }
457 470
         if (!empty($this->phone) && empty($this->phone_pro)) {        // For objects that store pro phone into ->phone
458 471
             $out .= dol_print_phone($this->phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', '&nbsp;', 'phone', $langs->trans("PhonePro"));
459 472
             $outdone++;
@@ -499,13 +512,21 @@  discard block
 block discarded – undo
499 512
         }
500 513
         $out .= '<div style="clear: both;">';
501 514
         if (!empty($conf->socialnetworks->enabled)) {
502
-            if ($this->skype) $out .= dol_print_socialnetworks($this->skype, $this->id, $object->id, 'skype');
515
+            if ($this->skype) {
516
+                $out .= dol_print_socialnetworks($this->skype, $this->id, $object->id, 'skype');
517
+            }
503 518
             $outdone++;
504
-            if ($this->jabberid) $out .= dol_print_socialnetworks($this->jabberid, $this->id, $object->id, 'jabber');
519
+            if ($this->jabberid) {
520
+                $out .= dol_print_socialnetworks($this->jabberid, $this->id, $object->id, 'jabber');
521
+            }
505 522
             $outdone++;
506
-            if ($this->twitter) $out .= dol_print_socialnetworks($this->twitter, $this->id, $object->id, 'twitter');
523
+            if ($this->twitter) {
524
+                $out .= dol_print_socialnetworks($this->twitter, $this->id, $object->id, 'twitter');
525
+            }
507 526
             $outdone++;
508
-            if ($this->facebook) $out .= dol_print_socialnetworks($this->facebook, $this->id, $object->id, 'facebook');
527
+            if ($this->facebook) {
528
+                $out .= dol_print_socialnetworks($this->facebook, $this->id, $object->id, 'facebook');
529
+            }
509 530
             $outdone++;
510 531
         }
511 532
         $out .= '</div>';
@@ -558,12 +579,17 @@  discard block
 block discarded – undo
558 579
         //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n";
559 580
         $lastname = $this->lastname;
560 581
         $firstname = $this->firstname;
561
-        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 : '')))));
582
+        if (empty($lastname)) {
583
+            $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 : '')))));
584
+        }
562 585
 
563 586
         $ret = '';
564 587
         if ($option && $this->civility_id) {
565
-            if ($langs->transnoentitiesnoconv("Civility" . $this->civility_id) != "Civility" . $this->civility_id) $ret .= $langs->transnoentitiesnoconv("Civility" . $this->civility_id) . ' ';
566
-            else $ret .= $this->civility_id . ' ';
588
+            if ($langs->transnoentitiesnoconv("Civility" . $this->civility_id) != "Civility" . $this->civility_id) {
589
+                $ret .= $langs->transnoentitiesnoconv("Civility" . $this->civility_id) . ' ';
590
+            } else {
591
+                $ret .= $this->civility_id . ' ';
592
+            }
567 593
         }
568 594
 
569 595
         $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder);
@@ -620,14 +646,18 @@  discard block
 block discarded – undo
620 646
 					$this->errors = $ecmfile->errors;
621 647
 				}
622 648
 				*/
623
-            } else return '';
649
+            } else {
650
+                return '';
651
+            }
624 652
         } elseif (empty($ecmfile->share)) {
625 653
             // Add entry into index
626 654
             if ($initsharekey) {
627 655
                 require_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php';
628 656
                 $ecmfile->share = getRandomPassword(true);
629 657
                 $ecmfile->update($user);
630
-            } else return '';
658
+            } else {
659
+                return '';
660
+            }
631 661
         }
632 662
 
633 663
         // Define $urlwithroot
@@ -641,8 +671,13 @@  discard block
 block discarded – undo
641 671
         //if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart;		// For sharing with hash (so public files), modulepart is not required.
642 672
         //if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; 					// For sharing with hash (so public files), entity is not required.
643 673
         //$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath);								// No need of name of file for public link, we will use the hash
644
-        if (!empty($ecmfile->share)) $paramlink .= ($paramlink ? '&' : '') . 'hashp=' . $ecmfile->share;            // Hash for public share
645
-        if ($forcedownload) $paramlink .= ($paramlink ? '&' : '') . 'attachment=1';
674
+        if (!empty($ecmfile->share)) {
675
+            $paramlink .= ($paramlink ? '&' : '') . 'hashp=' . $ecmfile->share;
676
+        }
677
+        // Hash for public share
678
+        if ($forcedownload) {
679
+            $paramlink .= ($paramlink ? '&' : '') . 'attachment=1';
680
+        }
646 681
 
647 682
         if ($relativelink) {
648 683
             $linktoreturn = 'document.php' . ($paramlink ? '?' . $paramlink : '');
@@ -723,7 +758,9 @@  discard block
 block discarded – undo
723 758
             $resql = $this->db->query($sql);
724 759
             if ($resql) {
725 760
                 $obj = $this->db->fetch_object($resql);
726
-                if ($obj) $id_type_contact = $obj->rowid;
761
+                if ($obj) {
762
+                    $id_type_contact = $obj->rowid;
763
+                }
727 764
             }
728 765
         }
729 766
 
@@ -783,7 +820,9 @@  discard block
 block discarded – undo
783 820
                     return -1;
784 821
                 }
785 822
             }
786
-        } else return 0;
823
+        } else {
824
+            return 0;
825
+        }
787 826
     }
788 827
 
789 828
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -805,22 +844,38 @@  discard block
 block discarded – undo
805 844
         $tab = array();
806 845
 
807 846
         $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
808
-        if ($source == 'internal') $sql .= ", '-1' as socid, t.statut as statuscontact, t.login, t.photo";
809
-        if ($source == 'external' || $source == 'thirdparty') $sql .= ", t.fk_soc as socid, t.statut as statuscontact";
847
+        if ($source == 'internal') {
848
+            $sql .= ", '-1' as socid, t.statut as statuscontact, t.login, t.photo";
849
+        }
850
+        if ($source == 'external' || $source == 'thirdparty') {
851
+            $sql .= ", t.fk_soc as socid, t.statut as statuscontact";
852
+        }
810 853
         $sql .= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email";
811 854
         $sql .= ", tc.source, tc.element, tc.code, tc.libelle";
812 855
         $sql .= " FROM " . MAIN_DB_PREFIX . "c_type_contact tc";
813 856
         $sql .= ", " . MAIN_DB_PREFIX . "element_contact ec";
814
-        if ($source == 'internal') $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user t on ec.fk_socpeople = t.rowid";
815
-        if ($source == 'external' || $source == 'thirdparty') $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople t on ec.fk_socpeople = t.rowid";
857
+        if ($source == 'internal') {
858
+            $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user t on ec.fk_socpeople = t.rowid";
859
+        }
860
+        if ($source == 'external' || $source == 'thirdparty') {
861
+            $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople t on ec.fk_socpeople = t.rowid";
862
+        }
816 863
         $sql .= " WHERE ec.element_id =" . $this->id;
817 864
         $sql .= " AND ec.fk_c_type_contact=tc.rowid";
818 865
         $sql .= " AND tc.element='" . $this->db->escape($this->element) . "'";
819
-        if ($code) $sql .= " AND tc.code = '" . $this->db->escape($code) . "'";
820
-        if ($source == 'internal') $sql .= " AND tc.source = 'internal'";
821
-        if ($source == 'external' || $source == 'thirdparty') $sql .= " AND tc.source = 'external'";
866
+        if ($code) {
867
+            $sql .= " AND tc.code = '" . $this->db->escape($code) . "'";
868
+        }
869
+        if ($source == 'internal') {
870
+            $sql .= " AND tc.source = 'internal'";
871
+        }
872
+        if ($source == 'external' || $source == 'thirdparty') {
873
+            $sql .= " AND tc.source = 'external'";
874
+        }
822 875
         $sql .= " AND tc.active=1";
823
-        if ($statut >= 0) $sql .= " AND ec.statut = '" . $statut . "'";
876
+        if ($statut >= 0) {
877
+            $sql .= " AND ec.statut = '" . $statut . "'";
878
+        }
824 879
         $sql .= " ORDER BY t.lastname ASC";
825 880
 
826 881
         dol_syslog(get_class($this) . "::liste_contact", LOG_DEBUG);
@@ -943,8 +998,9 @@  discard block
 block discarded – undo
943 998
 
944 999
         $sql = "DELETE FROM " . MAIN_DB_PREFIX . "element_contact";
945 1000
         $sql .= " WHERE element_id = " . $this->id;
946
-        if ($listId)
947
-            $sql .= " AND fk_c_type_contact IN (" . $listId . ")";
1001
+        if ($listId) {
1002
+                    $sql .= " AND fk_c_type_contact IN (" . $listId . ")";
1003
+        }
948 1004
 
949 1005
         dol_syslog(get_class($this) . "::delete_linked_contact", LOG_DEBUG);
950 1006
         if ($this->db->query($sql)) {
@@ -972,16 +1028,27 @@  discard block
 block discarded – undo
972 1028
         // phpcs:enable
973 1029
         global $langs;
974 1030
 
975
-        if (empty($order)) $order = 'position';
976
-        if ($order == 'position') $order .= ',code';
1031
+        if (empty($order)) {
1032
+            $order = 'position';
1033
+        }
1034
+        if ($order == 'position') {
1035
+            $order .= ',code';
1036
+        }
977 1037
 
978 1038
         $tab = array();
979 1039
         $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position";
980 1040
         $sql .= " FROM " . MAIN_DB_PREFIX . "c_type_contact as tc";
981 1041
         $sql .= " WHERE tc.element='" . $this->db->escape($this->element) . "'";
982
-        if ($activeonly == 1) $sql .= " AND tc.active=1"; // only the active types
983
-        if (!empty($source) && $source != 'all') $sql .= " AND tc.source='" . $this->db->escape($source) . "'";
984
-        if (!empty($code)) $sql .= " AND tc.code='" . $this->db->escape($code) . "'";
1042
+        if ($activeonly == 1) {
1043
+            $sql .= " AND tc.active=1";
1044
+        }
1045
+        // only the active types
1046
+        if (!empty($source) && $source != 'all') {
1047
+            $sql .= " AND tc.source='" . $this->db->escape($source) . "'";
1048
+        }
1049
+        if (!empty($code)) {
1050
+            $sql .= " AND tc.code='" . $this->db->escape($code) . "'";
1051
+        }
985 1052
         $sql .= $this->db->order($order, 'ASC');
986 1053
 
987 1054
         //print "sql=".$sql;
@@ -994,8 +1061,11 @@  discard block
 block discarded – undo
994 1061
 
995 1062
                 $transkey = "TypeContact_" . $this->element . "_" . $source . "_" . $obj->code;
996 1063
                 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle);
997
-                if (empty($option)) $tab[$obj->rowid] = $libelle_type;
998
-                else $tab[$obj->code] = $libelle_type;
1064
+                if (empty($option)) {
1065
+                    $tab[$obj->rowid] = $libelle_type;
1066
+                } else {
1067
+                    $tab[$obj->code] = $libelle_type;
1068
+                }
999 1069
                 $i++;
1000 1070
             }
1001 1071
             return $tab;
@@ -1055,8 +1125,12 @@  discard block
 block discarded – undo
1055 1125
         // Insert into database
1056 1126
         $sql = "UPDATE " . MAIN_DB_PREFIX . "element_contact set";
1057 1127
         $sql .= " statut = " . $statut;
1058
-        if ($type_contact_id) $sql .= ", fk_c_type_contact = '" . $type_contact_id . "'";
1059
-        if ($fk_socpeople) $sql .= ", fk_socpeople = '" . $fk_socpeople . "'";
1128
+        if ($type_contact_id) {
1129
+            $sql .= ", fk_c_type_contact = '" . $type_contact_id . "'";
1130
+        }
1131
+        if ($fk_socpeople) {
1132
+            $sql .= ", fk_socpeople = '" . $fk_socpeople . "'";
1133
+        }
1060 1134
         $sql .= " where rowid = " . $rowid;
1061 1135
         $resql = $this->db->query($sql);
1062 1136
         if ($resql) {
@@ -1100,19 +1174,29 @@  discard block
 block discarded – undo
1100 1174
 
1101 1175
         $sql = "SELECT ec.fk_socpeople";
1102 1176
         $sql .= " FROM " . MAIN_DB_PREFIX . "element_contact as ec,";
1103
-        if ($source == 'internal') $sql .= " " . MAIN_DB_PREFIX . "user as c,";
1104
-        if ($source == 'external') $sql .= " " . MAIN_DB_PREFIX . "socpeople as c,";
1177
+        if ($source == 'internal') {
1178
+            $sql .= " " . MAIN_DB_PREFIX . "user as c,";
1179
+        }
1180
+        if ($source == 'external') {
1181
+            $sql .= " " . MAIN_DB_PREFIX . "socpeople as c,";
1182
+        }
1105 1183
         $sql .= " " . MAIN_DB_PREFIX . "c_type_contact as tc";
1106 1184
         $sql .= " WHERE ec.element_id = " . $id;
1107 1185
         $sql .= " AND ec.fk_socpeople = c.rowid";
1108
-        if ($source == 'internal') $sql .= " AND c.entity IN (" . getEntity('user') . ")";
1109
-        if ($source == 'external') $sql .= " AND c.entity IN (" . getEntity('societe') . ")";
1186
+        if ($source == 'internal') {
1187
+            $sql .= " AND c.entity IN (" . getEntity('user') . ")";
1188
+        }
1189
+        if ($source == 'external') {
1190
+            $sql .= " AND c.entity IN (" . getEntity('societe') . ")";
1191
+        }
1110 1192
         $sql .= " AND ec.fk_c_type_contact = tc.rowid";
1111 1193
         $sql .= " AND tc.element = '" . $element . "'";
1112 1194
         $sql .= " AND tc.source = '" . $source . "'";
1113 1195
         $sql .= " AND tc.code = '" . $code . "'";
1114 1196
         $sql .= " AND tc.active = 1";
1115
-        if ($status) $sql .= " AND ec.statut = " . $status;
1197
+        if ($status) {
1198
+            $sql .= " AND ec.statut = " . $status;
1199
+        }
1116 1200
 
1117 1201
         dol_syslog(get_class($this) . "::getIdContact", LOG_DEBUG);
1118 1202
         $resql = $this->db->query($sql);
@@ -1138,9 +1222,13 @@  discard block
 block discarded – undo
1138 1222
     function fetch_contact($contactid = null)
1139 1223
     {
1140 1224
         // phpcs:enable
1141
-        if (empty($contactid)) $contactid = $this->contactid;
1225
+        if (empty($contactid)) {
1226
+            $contactid = $this->contactid;
1227
+        }
1142 1228
 
1143
-        if (empty($contactid)) return 0;
1229
+        if (empty($contactid)) {
1230
+            return 0;
1231
+        }
1144 1232
 
1145 1233
         require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
1146 1234
         $contact = new Contact($this->db);
@@ -1162,14 +1250,16 @@  discard block
 block discarded – undo
1162 1250
         // phpcs:enable
1163 1251
         global $conf;
1164 1252
 
1165
-        if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id))
1166
-            return 0;
1253
+        if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) {
1254
+                    return 0;
1255
+        }
1167 1256
 
1168 1257
         require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
1169 1258
 
1170 1259
         $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty);
1171
-        if ($force_thirdparty_id)
1172
-            $idtofetch = $force_thirdparty_id;
1260
+        if ($force_thirdparty_id) {
1261
+                    $idtofetch = $force_thirdparty_id;
1262
+        }
1173 1263
 
1174 1264
         if ($idtofetch) {
1175 1265
             $thirdparty = new Societe($this->db);
@@ -1182,8 +1272,9 @@  discard block
 block discarded – undo
1182 1272
             }
1183 1273
 
1184 1274
             return $result;
1185
-        } else
1186
-            return -1;
1275
+        } else {
1276
+                    return -1;
1277
+        }
1187 1278
     }
1188 1279
 
1189 1280
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -1231,17 +1322,23 @@  discard block
 block discarded – undo
1231 1322
         dol_syslog(get_class($this) . '::fetch_barcode this->element=' . $this->element . ' this->barcode_type=' . $this->barcode_type);
1232 1323
 
1233 1324
         $idtype = $this->barcode_type;
1234
-        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
1325
+        if (empty($idtype) && $idtype != '0') {
1326
+            // If type of barcode no set, we try to guess. If set to '0' it means we forced to have type remain not defined
1235 1327
         {
1236 1328
             if ($this->element == 'product') $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
1237
-            else if ($this->element == 'societe') $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY;
1238
-            else dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING);
1329
+        } else if ($this->element == 'societe') {
1330
+                $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY;
1331
+            } else {
1332
+                dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING);
1333
+            }
1239 1334
         }
1240 1335
 
1241 1336
         if ($idtype > 0) {
1242
-            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
1337
+            if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) {
1338
+                // If data not already loaded
1243 1339
             {
1244 1340
                 $sql = "SELECT rowid, code, libelle as label, coder";
1341
+            }
1245 1342
                 $sql .= " FROM " . MAIN_DB_PREFIX . "c_barcode_type";
1246 1343
                 $sql .= " WHERE rowid = " . $idtype;
1247 1344
                 dol_syslog(get_class($this) . '::fetch_barcode', LOG_DEBUG);
@@ -1274,8 +1371,13 @@  discard block
 block discarded – undo
1274 1371
         // phpcs:enable
1275 1372
         include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
1276 1373
 
1277
-        if (empty($this->fk_project) && !empty($this->fk_projet)) $this->fk_project = $this->fk_projet;    // For backward compatibility
1278
-        if (empty($this->fk_project)) return 0;
1374
+        if (empty($this->fk_project) && !empty($this->fk_projet)) {
1375
+            $this->fk_project = $this->fk_projet;
1376
+        }
1377
+        // For backward compatibility
1378
+        if (empty($this->fk_project)) {
1379
+            return 0;
1380
+        }
1279 1381
 
1280 1382
         $project = new Project($this->db);
1281 1383
         $result = $project->fetch($this->fk_project);
@@ -1297,7 +1399,9 @@  discard block
 block discarded – undo
1297 1399
         // phpcs:enable
1298 1400
         include_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
1299 1401
 
1300
-        if (empty($this->fk_product)) return 0;
1402
+        if (empty($this->fk_product)) {
1403
+            return 0;
1404
+        }
1301 1405
 
1302 1406
         $product = new Product($this->db);
1303 1407
         $result = $product->fetch($this->fk_product);
@@ -1329,9 +1433,15 @@  discard block
 block discarded – undo
1329 1433
     function fetch_origin()
1330 1434
     {
1331 1435
         // phpcs:enable
1332
-        if ($this->origin == 'shipping') $this->origin = 'expedition';
1333
-        if ($this->origin == 'delivery') $this->origin = 'livraison';
1334
-        if ($this->origin == 'order_supplier') $this->origin = 'commandeFournisseur';
1436
+        if ($this->origin == 'shipping') {
1437
+            $this->origin = 'expedition';
1438
+        }
1439
+        if ($this->origin == 'delivery') {
1440
+            $this->origin = 'livraison';
1441
+        }
1442
+        if ($this->origin == 'order_supplier') {
1443
+            $this->origin = 'commandeFournisseur';
1444
+        }
1335 1445
 
1336 1446
         $origin = $this->origin;
1337 1447
 
@@ -1423,28 +1533,47 @@  discard block
 block discarded – undo
1423 1533
     {
1424 1534
         global $user, $langs, $conf;
1425 1535
 
1426
-        if (empty($table)) $table = $this->table_element;
1427
-        if (empty($id)) $id = $this->id;
1428
-        if (empty($format)) $format = 'text';
1429
-        if (empty($id_field)) $id_field = 'rowid';
1536
+        if (empty($table)) {
1537
+            $table = $this->table_element;
1538
+        }
1539
+        if (empty($id)) {
1540
+            $id = $this->id;
1541
+        }
1542
+        if (empty($format)) {
1543
+            $format = 'text';
1544
+        }
1545
+        if (empty($id_field)) {
1546
+            $id_field = 'rowid';
1547
+        }
1430 1548
 
1431 1549
         $error = 0;
1432 1550
 
1433 1551
         $this->db->begin();
1434 1552
 
1435 1553
         // Special case
1436
-        if ($table == 'product' && $field == 'note_private') $field = 'note';
1437
-        if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod';
1554
+        if ($table == 'product' && $field == 'note_private') {
1555
+            $field = 'note';
1556
+        }
1557
+        if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) {
1558
+            $fk_user_field = 'fk_user_mod';
1559
+        }
1438 1560
 
1439 1561
         $sql = "UPDATE " . MAIN_DB_PREFIX . $table . " SET ";
1440 1562
 
1441
-        if ($format == 'text') $sql .= $field . " = '" . $this->db->escape($value) . "'";
1442
-        else if ($format == 'int') $sql .= $field . " = " . $this->db->escape($value);
1443
-        else if ($format == 'date') $sql .= $field . " = " . ($value ? "'" . $this->db->idate($value) . "'" : "null");
1563
+        if ($format == 'text') {
1564
+            $sql .= $field . " = '" . $this->db->escape($value) . "'";
1565
+        } else if ($format == 'int') {
1566
+            $sql .= $field . " = " . $this->db->escape($value);
1567
+        } else if ($format == 'date') {
1568
+            $sql .= $field . " = " . ($value ? "'" . $this->db->idate($value) . "'" : "null");
1569
+        }
1444 1570
 
1445 1571
         if ($fk_user_field) {
1446
-            if (!empty($fuser) && is_object($fuser)) $sql .= ", " . $fk_user_field . " = " . $fuser->id;
1447
-            elseif (empty($fuser) || $fuser != 'none') $sql .= ", " . $fk_user_field . " = " . $user->id;
1572
+            if (!empty($fuser) && is_object($fuser)) {
1573
+                $sql .= ", " . $fk_user_field . " = " . $fuser->id;
1574
+            } elseif (empty($fuser) || $fuser != 'none') {
1575
+                $sql .= ", " . $fk_user_field . " = " . $user->id;
1576
+            }
1448 1577
         }
1449 1578
 
1450 1579
         $sql .= " WHERE " . $id_field . " = " . $id;
@@ -1459,12 +1588,19 @@  discard block
 block discarded – undo
1459 1588
                 } else {
1460 1589
                     $result = $this->fetchCommon($id);
1461 1590
                 }
1462
-                if ($result >= 0) $result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user);   // This may set this->errors
1463
-                if ($result < 0) $error++;
1591
+                if ($result >= 0) {
1592
+                    $result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user);
1593
+                }
1594
+                // This may set this->errors
1595
+                if ($result < 0) {
1596
+                    $error++;
1597
+                }
1464 1598
             }
1465 1599
 
1466 1600
             if (!$error) {
1467
-                if (property_exists($this, $field)) $this->$field = $value;
1601
+                if (property_exists($this, $field)) {
1602
+                    $this->$field = $value;
1603
+                }
1468 1604
                 $this->db->commit();
1469 1605
                 return 1;
1470 1606
             } else {
@@ -1488,15 +1624,24 @@  discard block
 block discarded – undo
1488 1624
      */
1489 1625
     public function fetchCommon($id, $ref = null, $morewhere = '')
1490 1626
     {
1491
-        if (empty($id) && empty($ref) && empty($morewhere)) return -1;
1627
+        if (empty($id) && empty($ref) && empty($morewhere)) {
1628
+            return -1;
1629
+        }
1492 1630
 
1493 1631
         $sql = 'SELECT ' . $this->getFieldList();
1494 1632
         $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element;
1495 1633
 
1496
-        if (!empty($id)) $sql .= ' WHERE rowid = ' . $id;
1497
-        elseif (!empty($ref)) $sql .= " WHERE ref = " . $this->quote($ref, $this->fields['ref']);
1498
-        else $sql .= ' WHERE 1 = 1';    // usage with empty id and empty ref is very rare
1499
-        if ($morewhere) $sql .= $morewhere;
1634
+        if (!empty($id)) {
1635
+            $sql .= ' WHERE rowid = ' . $id;
1636
+        } elseif (!empty($ref)) {
1637
+            $sql .= " WHERE ref = " . $this->quote($ref, $this->fields['ref']);
1638
+        } else {
1639
+            $sql .= ' WHERE 1 = 1';
1640
+        }
1641
+        // usage with empty id and empty ref is very rare
1642
+        if ($morewhere) {
1643
+            $sql .= $morewhere;
1644
+        }
1500 1645
         $sql .= ' LIMIT 1';    // This is a fetch, to be sure to get only one record
1501 1646
 
1502 1647
         $res = $this->db->query($sql);
@@ -1535,9 +1680,13 @@  discard block
 block discarded – undo
1535 1680
      */
1536 1681
     protected function quote($value, $fieldsentry)
1537 1682
     {
1538
-        if (is_null($value)) return 'NULL';
1539
-        else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) return $this->db->escape("$value");
1540
-        else return "'" . $this->db->escape($value) . "'";
1683
+        if (is_null($value)) {
1684
+            return 'NULL';
1685
+        } else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) {
1686
+            return $this->db->escape("$value");
1687
+        } else {
1688
+            return "'" . $this->db->escape($value) . "'";
1689
+        }
1541 1690
     }
1542 1691
 
1543 1692
     /**
@@ -1550,19 +1699,27 @@  discard block
 block discarded – undo
1550 1699
     {
1551 1700
         foreach ($this->fields as $field => $info) {
1552 1701
             if ($this->isDate($info)) {
1553
-                if (empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0;
1554
-                else $this->{$field} = strtotime($obj->{$field});
1702
+                if (empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') {
1703
+                    $this->{$field} = 0;
1704
+                } else {
1705
+                    $this->{$field} = strtotime($obj->{$field});
1706
+                }
1555 1707
             } elseif ($this->isArray($info)) {
1556 1708
                 if (!empty($obj->{$field})) {
1557 1709
                     $this->{$field} = @unserialize($obj->{$field});
1558 1710
                     // Hack for data not in UTF8
1559
-                    if ($this->{$field} === false) @unserialize(utf8_decode($obj->{$field}));
1711
+                    if ($this->{$field} === false) {
1712
+                        @unserialize(utf8_decode($obj->{$field}));
1713
+                    }
1560 1714
                 } else {
1561 1715
                     $this->{$field} = array();
1562 1716
                 }
1563 1717
             } elseif ($this->isInt($info)) {
1564
-                if ($field == 'rowid') $this->id = (int)$obj->{$field};
1565
-                else $this->{$field} = (int)$obj->{$field};
1718
+                if ($field == 'rowid') {
1719
+                    $this->id = (int)$obj->{$field};
1720
+                } else {
1721
+                    $this->{$field} = (int)$obj->{$field};
1722
+                }
1566 1723
             } elseif ($this->isFloat($info)) {
1567 1724
                 $this->{$field} = (double)$obj->{$field};
1568 1725
             } elseif ($this->isNull($info)) {
@@ -1575,7 +1732,9 @@  discard block
 block discarded – undo
1575 1732
         }
1576 1733
 
1577 1734
         // If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions.
1578
-        if (!isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id;
1735
+        if (!isset($this->fields['ref']) && isset($this->id)) {
1736
+            $this->ref = $this->id;
1737
+        }
1579 1738
     }
1580 1739
 
1581 1740
     /**
@@ -1586,8 +1745,11 @@  discard block
 block discarded – undo
1586 1745
      */
1587 1746
     public function isDate($info)
1588 1747
     {
1589
-        if (isset($info['type']) && ($info['type'] == 'date' || $info['type'] == 'datetime' || $info['type'] == 'timestamp')) return true;
1590
-        else return false;
1748
+        if (isset($info['type']) && ($info['type'] == 'date' || $info['type'] == 'datetime' || $info['type'] == 'timestamp')) {
1749
+            return true;
1750
+        } else {
1751
+            return false;
1752
+        }
1591 1753
     }
1592 1754
 
1593 1755
     /**
@@ -1599,9 +1761,14 @@  discard block
 block discarded – undo
1599 1761
     protected function isArray($info)
1600 1762
     {
1601 1763
         if (is_array($info)) {
1602
-            if (isset($info['type']) && $info['type'] == 'array') return true;
1603
-            else return false;
1604
-        } else return false;
1764
+            if (isset($info['type']) && $info['type'] == 'array') {
1765
+                return true;
1766
+            } else {
1767
+                return false;
1768
+            }
1769
+        } else {
1770
+            return false;
1771
+        }
1605 1772
     }
1606 1773
 
1607 1774
     /**
@@ -1613,9 +1780,14 @@  discard block
 block discarded – undo
1613 1780
     public function isInt($info)
1614 1781
     {
1615 1782
         if (is_array($info)) {
1616
-            if (isset($info['type']) && ($info['type'] == 'int' || preg_match('/^integer/i', $info['type']))) return true;
1617
-            else return false;
1618
-        } else return false;
1783
+            if (isset($info['type']) && ($info['type'] == 'int' || preg_match('/^integer/i', $info['type']))) {
1784
+                return true;
1785
+            } else {
1786
+                return false;
1787
+            }
1788
+        } else {
1789
+            return false;
1790
+        }
1619 1791
     }
1620 1792
 
1621 1793
     /**
@@ -1627,9 +1799,14 @@  discard block
 block discarded – undo
1627 1799
     public function isFloat($info)
1628 1800
     {
1629 1801
         if (is_array($info)) {
1630
-            if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) return true;
1631
-            else return false;
1632
-        } else return false;
1802
+            if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) {
1803
+                return true;
1804
+            } else {
1805
+                return false;
1806
+            }
1807
+        } else {
1808
+            return false;
1809
+        }
1633 1810
     }
1634 1811
 
1635 1812
     /**
@@ -1641,9 +1818,14 @@  discard block
 block discarded – undo
1641 1818
     protected function isNull($info)
1642 1819
     {
1643 1820
         if (is_array($info)) {
1644
-            if (isset($info['type']) && $info['type'] == 'null') return true;
1645
-            else return false;
1646
-        } else return false;
1821
+            if (isset($info['type']) && $info['type'] == 'null') {
1822
+                return true;
1823
+            } else {
1824
+                return false;
1825
+            }
1826
+        } else {
1827
+            return false;
1828
+        }
1647 1829
     }
1648 1830
 
1649 1831
     /**
@@ -1663,35 +1845,65 @@  discard block
 block discarded – undo
1663 1845
             dol_print_error('', get_class($this) . "::load_previous_next_ref was called on objet with property table_element not defined");
1664 1846
             return -1;
1665 1847
         }
1666
-        if ($fieldid == 'none') return 1;
1848
+        if ($fieldid == 'none') {
1849
+            return 1;
1850
+        }
1667 1851
 
1668 1852
         // Security on socid
1669 1853
         $socid = 0;
1670
-        if ($user->societe_id > 0) $socid = $user->societe_id;
1854
+        if ($user->societe_id > 0) {
1855
+            $socid = $user->societe_id;
1856
+        }
1671 1857
 
1672 1858
         // this->ismultientitymanaged contains
1673 1859
         // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
1674 1860
         $alias = 's';
1675
-        if ($this->element == 'societe') $alias = 'te';
1861
+        if ($this->element == 'societe') {
1862
+            $alias = 'te';
1863
+        }
1676 1864
 
1677 1865
         $sql = "SELECT MAX(te." . $fieldid . ")";
1678 1866
         $sql .= " FROM " . (empty($nodbprefix) ? MAIN_DB_PREFIX : '') . $this->table_element . " as te";
1679 1867
         if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1680 1868
             $sql .= "," . MAIN_DB_PREFIX . "usergroup_user as ug";
1681 1869
         }
1682
-        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
1683
-        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
1684
-        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
1685
-        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";
1870
+        if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) {
1871
+            $sql .= ", " . MAIN_DB_PREFIX . "societe as s";
1872
+        }
1873
+        // If we need to link to societe to limit select to entity
1874
+        else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
1875
+            $sql .= ", " . MAIN_DB_PREFIX . "societe as s";
1876
+        }
1877
+        // If we need to link to societe to limit select to socid
1878
+        else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
1879
+            $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON te.fk_soc = s.rowid";
1880
+        }
1881
+        // If we need to link to societe to limit select to socid
1882
+        if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) {
1883
+            $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON " . $alias . ".rowid = sc.fk_soc";
1884
+        }
1686 1885
         $sql .= " WHERE te." . $fieldid . " < '" . $this->db->escape($this->ref) . "'";  // ->ref must always be defined (set to id if field does not exists)
1687
-        if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = " . $user->id;
1688
-        if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = " . $user->id . ' OR te.fk_soc IS NULL)';
1886
+        if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) {
1887
+            $sql .= " AND sc.fk_user = " . $user->id;
1888
+        }
1889
+        if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) {
1890
+            $sql .= " AND (sc.fk_user = " . $user->id . ' OR te.fk_soc IS NULL)';
1891
+        }
1689 1892
         if (!empty($filter)) {
1690
-            if (!preg_match('/^\s*AND/i', $filter)) $sql .= " AND ";   // For backward compatibility
1893
+            if (!preg_match('/^\s*AND/i', $filter)) {
1894
+                $sql .= " AND ";
1895
+            }
1896
+            // For backward compatibility
1691 1897
             $sql .= $filter;
1692 1898
         }
1693
-        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
1694
-        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
1899
+        if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) {
1900
+            $sql .= ' AND te.fk_soc = s.rowid';
1901
+        }
1902
+        // If we need to link to societe to limit select to entity
1903
+        else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
1904
+            $sql .= ' AND te.fk_soc = s.rowid';
1905
+        }
1906
+        // If we need to link to societe to limit select to socid
1695 1907
         if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
1696 1908
             if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1697 1909
                 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
@@ -1704,9 +1916,15 @@  discard block
 block discarded – undo
1704 1916
                 $sql .= ' AND te.entity IN (' . getEntity($this->element) . ')';
1705 1917
             }
1706 1918
         }
1707
-        if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql .= ' AND te.fk_soc = ' . $socid;
1708
-        if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql .= ' AND (te.fk_soc = ' . $socid . ' OR te.fk_soc IS NULL)';
1709
-        if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql .= ' AND te.rowid = ' . $socid;
1919
+        if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') {
1920
+            $sql .= ' AND te.fk_soc = ' . $socid;
1921
+        }
1922
+        if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') {
1923
+            $sql .= ' AND (te.fk_soc = ' . $socid . ' OR te.fk_soc IS NULL)';
1924
+        }
1925
+        if ($this->restrictiononfksoc && $socid && $this->element == 'societe') {
1926
+            $sql .= ' AND te.rowid = ' . $socid;
1927
+        }
1710 1928
         //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>";
1711 1929
 
1712 1930
         $result = $this->db->query($sql);
@@ -1723,19 +1941,43 @@  discard block
 block discarded – undo
1723 1941
         if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1724 1942
             $sql .= "," . MAIN_DB_PREFIX . "usergroup_user as ug";
1725 1943
         }
1726
-        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
1727
-        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
1728
-        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
1729
-        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";
1944
+        if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) {
1945
+            $sql .= ", " . MAIN_DB_PREFIX . "societe as s";
1946
+        }
1947
+        // If we need to link to societe to limit select to entity
1948
+        else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
1949
+            $sql .= ", " . MAIN_DB_PREFIX . "societe as s";
1950
+        }
1951
+        // If we need to link to societe to limit select to socid
1952
+        else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
1953
+            $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON te.fk_soc = s.rowid";
1954
+        }
1955
+        // If we need to link to societe to limit select to socid
1956
+        if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) {
1957
+            $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON " . $alias . ".rowid = sc.fk_soc";
1958
+        }
1730 1959
         $sql .= " WHERE te." . $fieldid . " > '" . $this->db->escape($this->ref) . "'";  // ->ref must always be defined (set to id if field does not exists)
1731
-        if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = " . $user->id;
1732
-        if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = " . $user->id . ' OR te.fk_soc IS NULL)';
1960
+        if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) {
1961
+            $sql .= " AND sc.fk_user = " . $user->id;
1962
+        }
1963
+        if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) {
1964
+            $sql .= " AND (sc.fk_user = " . $user->id . ' OR te.fk_soc IS NULL)';
1965
+        }
1733 1966
         if (!empty($filter)) {
1734
-            if (!preg_match('/^\s*AND/i', $filter)) $sql .= " AND ";   // For backward compatibility
1967
+            if (!preg_match('/^\s*AND/i', $filter)) {
1968
+                $sql .= " AND ";
1969
+            }
1970
+            // For backward compatibility
1735 1971
             $sql .= $filter;
1736 1972
         }
1737
-        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
1738
-        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
1973
+        if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) {
1974
+            $sql .= ' AND te.fk_soc = s.rowid';
1975
+        }
1976
+        // If we need to link to societe to limit select to entity
1977
+        else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) {
1978
+            $sql .= ' AND te.fk_soc = s.rowid';
1979
+        }
1980
+        // If we need to link to societe to limit select to socid
1739 1981
         if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
1740 1982
             if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1741 1983
                 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
@@ -1748,9 +1990,15 @@  discard block
 block discarded – undo
1748 1990
                 $sql .= ' AND te.entity IN (' . getEntity($this->element) . ')';
1749 1991
             }
1750 1992
         }
1751
-        if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql .= ' AND te.fk_soc = ' . $socid;
1752
-        if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql .= ' AND (te.fk_soc = ' . $socid . ' OR te.fk_soc IS NULL)';
1753
-        if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql .= ' AND te.rowid = ' . $socid;
1993
+        if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') {
1994
+            $sql .= ' AND te.fk_soc = ' . $socid;
1995
+        }
1996
+        if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') {
1997
+            $sql .= ' AND (te.fk_soc = ' . $socid . ' OR te.fk_soc IS NULL)';
1998
+        }
1999
+        if ($this->restrictiononfksoc && $socid && $this->element == 'societe') {
2000
+            $sql .= ' AND te.rowid = ' . $socid;
2001
+        }
1754 2002
         //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>";
1755 2003
         // 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
1756 2004
 
@@ -1784,8 +2032,11 @@  discard block
 block discarded – undo
1784 2032
         $num = count($tab);
1785 2033
         $i = 0;
1786 2034
         while ($i < $num) {
1787
-            if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid'];
1788
-            else  $contactAlreadySelected[$i] = $tab[$i]['id'];
2035
+            if ($source == 'thirdparty') {
2036
+                $contactAlreadySelected[$i] = $tab[$i]['socid'];
2037
+            } else {
2038
+                $contactAlreadySelected[$i] = $tab[$i]['id'];
2039
+            }
1789 2040
             $i++;
1790 2041
         }
1791 2042
         return $contactAlreadySelected;
@@ -1806,12 +2057,18 @@  discard block
 block discarded – undo
1806 2057
 
1807 2058
         $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element;
1808 2059
         if ($this->table_element == 'actioncomm') {
1809
-            if ($projectid) $sql .= ' SET fk_project = ' . $projectid;
1810
-            else $sql .= ' SET fk_project = NULL';
2060
+            if ($projectid) {
2061
+                $sql .= ' SET fk_project = ' . $projectid;
2062
+            } else {
2063
+                $sql .= ' SET fk_project = NULL';
2064
+            }
1811 2065
             $sql .= ' WHERE id = ' . $this->id;
1812 2066
         } else {
1813
-            if ($projectid) $sql .= ' SET fk_projet = ' . $projectid;
1814
-            else $sql .= ' SET fk_projet = NULL';
2067
+            if ($projectid) {
2068
+                $sql .= ' SET fk_projet = ' . $projectid;
2069
+            } else {
2070
+                $sql .= ' SET fk_projet = NULL';
2071
+            }
1815 2072
             $sql .= ' WHERE rowid = ' . $this->id;
1816 2073
         }
1817 2074
 
@@ -1839,8 +2096,12 @@  discard block
 block discarded – undo
1839 2096
         if ($this->statut >= 0 || $this->element == 'societe') {
1840 2097
             // TODO uniformize field name
1841 2098
             $fieldname = 'fk_mode_reglement';
1842
-            if ($this->element == 'societe') $fieldname = 'mode_reglement';
1843
-            if (get_class($this) == 'Fournisseur') $fieldname = 'mode_reglement_supplier';
2099
+            if ($this->element == 'societe') {
2100
+                $fieldname = 'mode_reglement';
2101
+            }
2102
+            if (get_class($this) == 'Fournisseur') {
2103
+                $fieldname = 'mode_reglement_supplier';
2104
+            }
1844 2105
 
1845 2106
             $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element;
1846 2107
             $sql .= ' SET ' . $fieldname . ' = ' . $id;
@@ -1849,7 +2110,9 @@  discard block
 block discarded – undo
1849 2110
             if ($this->db->query($sql)) {
1850 2111
                 $this->mode_reglement_id = $id;
1851 2112
                 // for supplier
1852
-                if (get_class($this) == 'Fournisseur') $this->mode_reglement_supplier_id = $id;
2113
+                if (get_class($this) == 'Fournisseur') {
2114
+                    $this->mode_reglement_supplier_id = $id;
2115
+                }
1853 2116
                 return 1;
1854 2117
             } else {
1855 2118
                 dol_syslog(get_class($this) . '::setPaymentMethods Erreur ' . $sql . ' - ' . $this->db->error());
@@ -1885,7 +2148,9 @@  discard block
 block discarded – undo
1885 2148
                 $this->multicurrency_code = $code;
1886 2149
 
1887 2150
                 list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code);
1888
-                if ($rate) $this->setMulticurrencyRate($rate, 2);
2151
+                if ($rate) {
2152
+                    $this->setMulticurrencyRate($rate, 2);
2153
+                }
1889 2154
 
1890 2155
                 return 1;
1891 2156
             } else {
@@ -2008,8 +2273,12 @@  discard block
 block discarded – undo
2008 2273
         if ($this->statut >= 0 || $this->element == 'societe') {
2009 2274
             // TODO uniformize field name
2010 2275
             $fieldname = 'fk_cond_reglement';
2011
-            if ($this->element == 'societe') $fieldname = 'cond_reglement';
2012
-            if (get_class($this) == 'Fournisseur') $fieldname = 'cond_reglement_supplier';
2276
+            if ($this->element == 'societe') {
2277
+                $fieldname = 'cond_reglement';
2278
+            }
2279
+            if (get_class($this) == 'Fournisseur') {
2280
+                $fieldname = 'cond_reglement_supplier';
2281
+            }
2013 2282
 
2014 2283
             $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element;
2015 2284
             $sql .= ' SET ' . $fieldname . ' = ' . $id;
@@ -2018,7 +2287,9 @@  discard block
 block discarded – undo
2018 2287
             if ($this->db->query($sql)) {
2019 2288
                 $this->cond_reglement_id = $id;
2020 2289
                 // for supplier
2021
-                if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id;
2290
+                if (get_class($this) == 'Fournisseur') {
2291
+                    $this->cond_reglement_supplier_id = $id;
2292
+                }
2022 2293
                 $this->cond_reglement = $id;    // for compatibility
2023 2294
                 return 1;
2024 2295
             } else {
@@ -2043,7 +2314,9 @@  discard block
 block discarded – undo
2043 2314
     function setDeliveryAddress($id)
2044 2315
     {
2045 2316
         $fieldname = 'fk_delivery_address';
2046
-        if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address';
2317
+        if ($this->element == 'delivery' || $this->element == 'shipping') {
2318
+            $fieldname = 'fk_address';
2319
+        }
2047 2320
 
2048 2321
         $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element . " SET " . $fieldname . " = " . $id;
2049 2322
         $sql .= " WHERE rowid = " . $this->id . " AND fk_statut = 0";
@@ -2071,7 +2344,9 @@  discard block
 block discarded – undo
2071 2344
     {
2072 2345
         global $user;
2073 2346
 
2074
-        if (empty($userused)) $userused = $user;
2347
+        if (empty($userused)) {
2348
+            $userused = $user;
2349
+        }
2075 2350
 
2076 2351
         $error = 0;
2077 2352
 
@@ -2082,7 +2357,9 @@  discard block
 block discarded – undo
2082 2357
 
2083 2358
         $this->db->begin();
2084 2359
 
2085
-        if ($shipping_method_id < 0) $shipping_method_id = 'NULL';
2360
+        if ($shipping_method_id < 0) {
2361
+            $shipping_method_id = 'NULL';
2362
+        }
2086 2363
         dol_syslog(get_class($this) . '::setShippingMethod(' . $shipping_method_id . ')');
2087 2364
 
2088 2365
         $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element;
@@ -2098,7 +2375,9 @@  discard block
 block discarded – undo
2098 2375
                 // Call trigger
2099 2376
                 $this->context = array('shippingmethodupdate' => 1);
2100 2377
                 $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused);
2101
-                if ($result < 0) $error++;
2378
+                if ($result < 0) {
2379
+                    $error++;
2380
+                }
2102 2381
                 // End call trigger
2103 2382
             }
2104 2383
         }
@@ -2124,7 +2403,9 @@  discard block
 block discarded – undo
2124 2403
             dol_syslog(get_class($this) . "::setWarehouse was called on objet with property table_element not defined", LOG_ERR);
2125 2404
             return -1;
2126 2405
         }
2127
-        if ($warehouse_id < 0) $warehouse_id = 'NULL';
2406
+        if ($warehouse_id < 0) {
2407
+            $warehouse_id = 'NULL';
2408
+        }
2128 2409
         dol_syslog(get_class($this) . '::setWarehouse(' . $warehouse_id . ')');
2129 2410
 
2130 2411
         $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element;
@@ -2188,7 +2469,9 @@  discard block
 block discarded – undo
2188 2469
     {
2189 2470
         global $user;
2190 2471
 
2191
-        if (empty($userused)) $userused = $user;
2472
+        if (empty($userused)) {
2473
+            $userused = $user;
2474
+        }
2192 2475
 
2193 2476
         $error = 0;
2194 2477
 
@@ -2198,7 +2481,9 @@  discard block
 block discarded – undo
2198 2481
         }
2199 2482
         $this->db->begin();
2200 2483
 
2201
-        if ($fk_account < 0) $fk_account = 'NULL';
2484
+        if ($fk_account < 0) {
2485
+            $fk_account = 'NULL';
2486
+        }
2202 2487
         dol_syslog(get_class($this) . '::setBankAccount(' . $fk_account . ')');
2203 2488
 
2204 2489
         $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element;
@@ -2215,7 +2500,9 @@  discard block
 block discarded – undo
2215 2500
                 // Call trigger
2216 2501
                 $this->context = array('bankaccountupdate' => 1);
2217 2502
                 $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused);
2218
-                if ($result < 0) $error++;
2503
+                if ($result < 0) {
2504
+                    $error++;
2505
+                }
2219 2506
                 // End call trigger
2220 2507
             }
2221 2508
         }
@@ -2277,15 +2564,21 @@  discard block
 block discarded – undo
2277 2564
         $nl = 0;
2278 2565
         $sql = 'SELECT count(rowid) FROM ' . MAIN_DB_PREFIX . $this->table_element_line;
2279 2566
         $sql .= ' WHERE ' . $this->fk_element . '=' . $this->id;
2280
-        if (!$renum) $sql .= ' AND rang = 0';
2281
-        if ($renum) $sql .= ' AND rang <> 0';
2567
+        if (!$renum) {
2568
+            $sql .= ' AND rang = 0';
2569
+        }
2570
+        if ($renum) {
2571
+            $sql .= ' AND rang <> 0';
2572
+        }
2282 2573
 
2283 2574
         dol_syslog(get_class($this) . "::line_order", LOG_DEBUG);
2284 2575
         $resql = $this->db->query($sql);
2285 2576
         if ($resql) {
2286 2577
             $row = $this->db->fetch_row($resql);
2287 2578
             $nl = $row[0];
2288
-        } else dol_print_error($this->db);
2579
+        } else {
2580
+            dol_print_error($this->db);
2581
+        }
2289 2582
         if ($nl > 0) {
2290 2583
             // The goal of this part is to reorder all lines, with all children lines sharing the same
2291 2584
             // counter that parents.
@@ -2294,7 +2587,9 @@  discard block
 block discarded – undo
2294 2587
             // We first search all lines that are parent lines (for multilevel details lines)
2295 2588
             $sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . $this->table_element_line;
2296 2589
             $sql .= ' WHERE ' . $this->fk_element . ' = ' . $this->id;
2297
-            if ($fk_parent_line) $sql .= ' AND fk_parent_line IS NULL';
2590
+            if ($fk_parent_line) {
2591
+                $sql .= ' AND fk_parent_line IS NULL';
2592
+            }
2298 2593
             $sql .= ' ORDER BY rang ASC, rowid ' . $rowidorder;
2299 2594
 
2300 2595
             dol_syslog(get_class($this) . "::line_order search all parent lines", LOG_DEBUG);
@@ -2371,7 +2666,9 @@  discard block
 block discarded – undo
2371 2666
     function updateRangOfLine($rowid, $rang)
2372 2667
     {
2373 2668
         $fieldposition = 'rang';
2374
-        if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
2669
+        if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) {
2670
+            $fieldposition = 'position';
2671
+        }
2375 2672
 
2376 2673
         $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element_line . ' SET ' . $fieldposition . ' = ' . $rang;
2377 2674
         $sql .= ' WHERE rowid = ' . $rowid;
@@ -2414,7 +2711,9 @@  discard block
 block discarded – undo
2414 2711
     {
2415 2712
         if ($rang > 1) {
2416 2713
             $fieldposition = 'rang';
2417
-            if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
2714
+            if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) {
2715
+                $fieldposition = 'position';
2716
+            }
2418 2717
 
2419 2718
             $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element_line . ' SET ' . $fieldposition . ' = ' . $rang;
2420 2719
             $sql .= ' WHERE ' . $this->fk_element . ' = ' . $this->id;
@@ -2504,7 +2803,9 @@  discard block
 block discarded – undo
2504 2803
     {
2505 2804
         if ($rang < $max) {
2506 2805
             $fieldposition = 'rang';
2507
-            if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
2806
+            if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) {
2807
+                $fieldposition = 'position';
2808
+            }
2508 2809
 
2509 2810
             $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element_line . ' SET ' . $fieldposition . ' = ' . $rang;
2510 2811
             $sql .= ' WHERE ' . $this->fk_element . ' = ' . $this->id;
@@ -2620,7 +2921,9 @@  discard block
 block discarded – undo
2620 2921
         }
2621 2922
         // Special cas
2622 2923
         //var_dump($this->table_element);exit;
2623
-        if ($this->table_element == 'product') $suffix = '';
2924
+        if ($this->table_element == 'product') {
2925
+            $suffix = '';
2926
+        }
2624 2927
 
2625 2928
         $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element;
2626 2929
         $sql .= " SET note" . $suffix . " = " . (!empty($note) ? ("'" . $this->db->escape($note) . "'") : "NULL");
@@ -2629,9 +2932,11 @@  discard block
 block discarded – undo
2629 2932
 
2630 2933
         dol_syslog(get_class($this) . "::update_note", LOG_DEBUG);
2631 2934
         if ($this->db->query($sql)) {
2632
-            if ($suffix == '_public') $this->note_public = $note;
2633
-            else if ($suffix == '_private') $this->note_private = $note;
2634
-            else {
2935
+            if ($suffix == '_public') {
2936
+                $this->note_public = $note;
2937
+            } else if ($suffix == '_private') {
2938
+                $this->note_private = $note;
2939
+            } else {
2635 2940
                 $this->note = $note;      // deprecated
2636 2941
                 $this->note_private = $note;
2637 2942
             }
@@ -2659,36 +2964,45 @@  discard block
 block discarded – undo
2659 2964
 
2660 2965
         // Some external module want no update price after a trigger because they have another method to calculate the total (ex: with an extrafield)
2661 2966
         $MODULE = "";
2662
-        if ($this->element == 'propal')
2663
-            $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL";
2664
-        elseif ($this->element == 'order')
2665
-            $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER";
2666
-        elseif ($this->element == 'facture')
2667
-            $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE";
2668
-        elseif ($this->element == 'facture_fourn')
2669
-            $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE";
2670
-        elseif ($this->element == 'order_supplier')
2671
-            $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER";
2672
-        elseif ($this->element == 'supplier_proposal')
2673
-            $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL";
2967
+        if ($this->element == 'propal') {
2968
+                    $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL";
2969
+        } elseif ($this->element == 'order') {
2970
+                    $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER";
2971
+        } elseif ($this->element == 'facture') {
2972
+                    $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE";
2973
+        } elseif ($this->element == 'facture_fourn') {
2974
+                    $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE";
2975
+        } elseif ($this->element == 'order_supplier') {
2976
+                    $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER";
2977
+        } elseif ($this->element == 'supplier_proposal') {
2978
+                    $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL";
2979
+        }
2674 2980
 
2675 2981
         if (!empty($MODULE)) {
2676 2982
             if (!empty($conf->global->$MODULE)) {
2677 2983
                 $modsactivated = explode(',', $conf->global->$MODULE);
2678 2984
                 foreach ($modsactivated as $mod) {
2679
-                    if ($conf->$mod->enabled)
2680
-                        return 1; // update was disabled by specific setup
2985
+                    if ($conf->$mod->enabled) {
2986
+                                            return 1;
2987
+                    }
2988
+                    // update was disabled by specific setup
2681 2989
                 }
2682 2990
             }
2683 2991
         }
2684 2992
 
2685 2993
         include_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php';
2686 2994
 
2687
-        if ($roundingadjust == '-1') $roundingadjust = 'auto';    // For backward compatibility
2995
+        if ($roundingadjust == '-1') {
2996
+            $roundingadjust = 'auto';
2997
+        }
2998
+        // For backward compatibility
2688 2999
 
2689 3000
         $forcedroundingmode = $roundingadjust;
2690
-        if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode = $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND;
2691
-        elseif ($forcedroundingmode == 'auto') $forcedroundingmode = '0';
3001
+        if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) {
3002
+            $forcedroundingmode = $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND;
3003
+        } elseif ($forcedroundingmode == 'auto') {
3004
+            $forcedroundingmode = '0';
3005
+        }
2692 3006
 
2693 3007
         $error = 0;
2694 3008
 
@@ -2709,14 +3023,21 @@  discard block
 block discarded – undo
2709 3023
 
2710 3024
         $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,';
2711 3025
         $sql .= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type';
2712
-        if ($this->table_element_line == 'facturedet') $sql .= ', situation_percent';
3026
+        if ($this->table_element_line == 'facturedet') {
3027
+            $sql .= ', situation_percent';
3028
+        }
2713 3029
         $sql .= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
2714 3030
         $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element_line;
2715 3031
         $sql .= ' WHERE ' . $this->fk_element . ' = ' . $this->id;
2716 3032
         if ($exclspec) {
2717 3033
             $product_field = 'product_type';
2718
-            if ($this->table_element_line == 'contratdet') $product_field = '';    // contratdet table has no product_type field
2719
-            if ($product_field) $sql .= ' AND ' . $product_field . ' <> 9';
3034
+            if ($this->table_element_line == 'contratdet') {
3035
+                $product_field = '';
3036
+            }
3037
+            // contratdet table has no product_type field
3038
+            if ($product_field) {
3039
+                $sql .= ' AND ' . $product_field . ' <> 9';
3040
+            }
2720 3041
         }
2721 3042
         $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
2722 3043
 
@@ -2744,16 +3065,20 @@  discard block
 block discarded – undo
2744 3065
                 $parameters = array('fk_element' => $obj->rowid);
2745 3066
                 $reshook = $hookmanager->executeHooks('changeRoundingMode', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2746 3067
 
2747
-                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'
3068
+                if (empty($reshook) && $forcedroundingmode == '0') {
3069
+                    // Check if data on line are consistent. This may solve lines that were not consistent because set with $forcedroundingmode='auto'
2748 3070
                 {
2749 3071
                     $localtax_array = array($obj->localtax1_type, $obj->localtax1_tx, $obj->localtax2_type, $obj->localtax2_tx);
3072
+                }
2750 3073
                     $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);
2751 3074
                     $diff = price2num($tmpcal[1] - $obj->total_tva, 'MT', 1);
2752 3075
                     if ($diff) {
2753 3076
                         $sqlfix = "UPDATE " . MAIN_DB_PREFIX . $this->table_element_line . " SET " . $fieldtva . " = " . $tmpcal[1] . ", total_ttc = " . $tmpcal[2] . " WHERE rowid = " . $obj->rowid;
2754 3077
                         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);
2755 3078
                         $resqlfix = $this->db->query($sqlfix);
2756
-                        if (!$resqlfix) dol_print_error($this->db, 'Failed to update line');
3079
+                        if (!$resqlfix) {
3080
+                            dol_print_error($this->db, 'Failed to update line');
3081
+                        }
2757 3082
                         $obj->total_tva = $tmpcal[1];
2758 3083
                         $obj->total_ttc = $tmpcal[2];
2759 3084
                         //
@@ -2769,16 +3094,24 @@  discard block
 block discarded – undo
2769 3094
                 $this->multicurrency_total_tva += $obj->multicurrency_total_tva;
2770 3095
                 $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc;
2771 3096
 
2772
-                if (!isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate] = 0;
2773
-                if (!isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate] = 0;
2774
-                if (!isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate] = 0;
3097
+                if (!isset($total_ht_by_vats[$obj->vatrate])) {
3098
+                    $total_ht_by_vats[$obj->vatrate] = 0;
3099
+                }
3100
+                if (!isset($total_tva_by_vats[$obj->vatrate])) {
3101
+                    $total_tva_by_vats[$obj->vatrate] = 0;
3102
+                }
3103
+                if (!isset($total_ttc_by_vats[$obj->vatrate])) {
3104
+                    $total_ttc_by_vats[$obj->vatrate] = 0;
3105
+                }
2775 3106
                 $total_ht_by_vats[$obj->vatrate] += $obj->total_ht;
2776 3107
                 $total_tva_by_vats[$obj->vatrate] += $obj->total_tva;
2777 3108
                 $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc;
2778 3109
 
2779
-                if ($forcedroundingmode == '1')    // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency
3110
+                if ($forcedroundingmode == '1') {
3111
+                    // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency
2780 3112
                 {
2781 3113
                     $tmpvat = price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1);
3114
+                }
2782 3115
                     $diff = price2num($total_tva_by_vats[$obj->vatrate] - $tmpvat, 'MT', 1);
2783 3116
                     //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";
2784 3117
                     if ($diff) {
@@ -2789,7 +3122,9 @@  discard block
 block discarded – undo
2789 3122
                         $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;
2790 3123
                         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);
2791 3124
                         $resqlfix = $this->db->query($sqlfix);
2792
-                        if (!$resqlfix) dol_print_error($this->db, 'Failed to update line');
3125
+                        if (!$resqlfix) {
3126
+                            dol_print_error($this->db, 'Failed to update line');
3127
+                        }
2793 3128
                         $this->total_tva -= $diff;
2794 3129
                         $this->total_ttc -= $diff;
2795 3130
                         $total_tva_by_vats[$obj->vatrate] -= $diff;
@@ -2829,11 +3164,21 @@  discard block
 block discarded – undo
2829 3164
             $fieldlocaltax2 = 'localtax2';
2830 3165
             $fieldttc = 'total_ttc';
2831 3166
             // Specific code for backward compatibility with old field names
2832
-            if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht = 'total';
2833
-            if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva = 'total_tva';
2834
-            if ($this->element == 'propal') $fieldttc = 'total';
2835
-            if ($this->element == 'expensereport') $fieldtva = 'total_tva';
2836
-            if ($this->element == 'supplier_proposal') $fieldttc = 'total';
3167
+            if ($this->element == 'facture' || $this->element == 'facturerec') {
3168
+                $fieldht = 'total';
3169
+            }
3170
+            if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') {
3171
+                $fieldtva = 'total_tva';
3172
+            }
3173
+            if ($this->element == 'propal') {
3174
+                $fieldttc = 'total';
3175
+            }
3176
+            if ($this->element == 'expensereport') {
3177
+                $fieldtva = 'total_tva';
3178
+            }
3179
+            if ($this->element == 'supplier_proposal') {
3180
+                $fieldttc = 'total';
3181
+            }
2837 3182
 
2838 3183
             if (empty($nodatabaseupdate)) {
2839 3184
                 $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
@@ -2883,10 +3228,18 @@  discard block
 block discarded – undo
2883 3228
         $origin_id = (!empty($origin_id) ? $origin_id : $this->origin_id);
2884 3229
 
2885 3230
         // Special case
2886
-        if ($origin == 'order') $origin = 'commande';
2887
-        if ($origin == 'invoice') $origin = 'facture';
2888
-        if ($origin == 'invoice_template') $origin = 'facturerec';
2889
-        if ($origin == 'supplierorder') $origin = 'order_supplier';
3231
+        if ($origin == 'order') {
3232
+            $origin = 'commande';
3233
+        }
3234
+        if ($origin == 'invoice') {
3235
+            $origin = 'facture';
3236
+        }
3237
+        if ($origin == 'invoice_template') {
3238
+            $origin = 'facturerec';
3239
+        }
3240
+        if ($origin == 'supplierorder') {
3241
+            $origin = 'order_supplier';
3242
+        }
2890 3243
         $this->db->begin();
2891 3244
 
2892 3245
         $sql = "INSERT INTO " . MAIN_DB_PREFIX . "element_element (";
@@ -2951,11 +3304,15 @@  discard block
 block discarded – undo
2951 3304
 
2952 3305
         if (!empty($sourceid) && !empty($sourcetype) && empty($targetid)) {
2953 3306
             $justsource = true;  // the source (id and type) is a search criteria
2954
-            if (!empty($targettype)) $withtargettype = true;
3307
+            if (!empty($targettype)) {
3308
+                $withtargettype = true;
3309
+            }
2955 3310
         }
2956 3311
         if (!empty($targetid) && !empty($targettype) && empty($sourceid)) {
2957 3312
             $justtarget = true;  // the target (id and type) is a search criteria
2958
-            if (!empty($sourcetype)) $withsourcetype = true;
3313
+            if (!empty($sourcetype)) {
3314
+                $withsourcetype = true;
3315
+            }
2959 3316
         }
2960 3317
 
2961 3318
         $sourceid = (!empty($sourceid) ? $sourceid : $this->id);
@@ -2976,10 +3333,14 @@  discard block
 block discarded – undo
2976 3333
         if ($justsource || $justtarget) {
2977 3334
             if ($justsource) {
2978 3335
                 $sql .= "fk_source = " . $sourceid . " AND sourcetype = '" . $sourcetype . "'";
2979
-                if ($withtargettype) $sql .= " AND targettype = '" . $targettype . "'";
3336
+                if ($withtargettype) {
3337
+                    $sql .= " AND targettype = '" . $targettype . "'";
3338
+                }
2980 3339
             } else if ($justtarget) {
2981 3340
                 $sql .= "fk_target = " . $targetid . " AND targettype = '" . $targettype . "'";
2982
-                if ($withsourcetype) $sql .= " AND sourcetype = '" . $sourcetype . "'";
3341
+                if ($withsourcetype) {
3342
+                    $sql .= " AND sourcetype = '" . $sourcetype . "'";
3343
+                }
2983 3344
             }
2984 3345
         } else {
2985 3346
             $sql .= "(fk_source = " . $sourceid . " AND sourcetype = '" . $sourcetype . "')";
@@ -3013,10 +3374,12 @@  discard block
 block discarded – undo
3013 3374
 
3014 3375
             if (!empty($this->linkedObjectsIds)) {
3015 3376
                 $tmparray = $this->linkedObjectsIds;
3016
-                foreach ($tmparray as $objecttype => $objectids)       // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...)
3377
+                foreach ($tmparray as $objecttype => $objectids) {
3378
+                    // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...)
3017 3379
                 {
3018 3380
                     // Parse element/subelement (ex: project_task, cabinetmed_consultation, ...)
3019 3381
                     $module = $element = $subelement = $objecttype;
3382
+                }
3020 3383
                     if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier'
3021 3384
                         && preg_match('/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
3022 3385
                         $module = $element = $regs[1];
@@ -3084,9 +3447,11 @@  discard block
 block discarded – undo
3084 3447
                             dol_include_once('/' . $classpath . '/' . $classfile . '.class.php');
3085 3448
                             //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname);
3086 3449
                             if (class_exists($classname)) {
3087
-                                foreach ($objectids as $i => $objectid)    // $i is rowid into llx_element_element
3450
+                                foreach ($objectids as $i => $objectid) {
3451
+                                    // $i is rowid into llx_element_element
3088 3452
                                 {
3089 3453
                                     $object = new $classname($this->db);
3454
+                                }
3090 3455
                                     $ret = $object->fetch($objectid);
3091 3456
                                     if ($ret >= 0) {
3092 3457
                                         $this->linkedObjects[$objecttype][$i] = $object;
@@ -3121,8 +3486,11 @@  discard block
 block discarded – undo
3121 3486
         $updatesource = false;
3122 3487
         $updatetarget = false;
3123 3488
 
3124
-        if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource = true;
3125
-        else if (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) $updatetarget = true;
3489
+        if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) {
3490
+            $updatesource = true;
3491
+        } else if (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) {
3492
+            $updatetarget = true;
3493
+        }
3126 3494
 
3127 3495
         $sql = "UPDATE " . MAIN_DB_PREFIX . "element_element SET ";
3128 3496
         if ($updatesource) {
@@ -3162,8 +3530,11 @@  discard block
 block discarded – undo
3162 3530
         $deletesource = false;
3163 3531
         $deletetarget = false;
3164 3532
 
3165
-        if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource = true;
3166
-        else if (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) $deletetarget = true;
3533
+        if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) {
3534
+            $deletesource = true;
3535
+        } else if (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) {
3536
+            $deletetarget = true;
3537
+        }
3167 3538
 
3168 3539
         $sourceid = (!empty($sourceid) ? $sourceid : $this->id);
3169 3540
         $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element);
@@ -3226,17 +3597,31 @@  discard block
 block discarded – undo
3226 3597
         $this->db->begin();
3227 3598
 
3228 3599
         $fieldstatus = "fk_statut";
3229
-        if ($elementTable == 'facture_rec') $fieldstatus = "suspended";
3230
-        if ($elementTable == 'mailing') $fieldstatus = "statut";
3231
-        if ($elementTable == 'cronjob') $fieldstatus = "status";
3232
-        if ($elementTable == 'user') $fieldstatus = "statut";
3233
-        if ($elementTable == 'expensereport') $fieldstatus = "fk_statut";
3234
-        if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus = "status";
3600
+        if ($elementTable == 'facture_rec') {
3601
+            $fieldstatus = "suspended";
3602
+        }
3603
+        if ($elementTable == 'mailing') {
3604
+            $fieldstatus = "statut";
3605
+        }
3606
+        if ($elementTable == 'cronjob') {
3607
+            $fieldstatus = "status";
3608
+        }
3609
+        if ($elementTable == 'user') {
3610
+            $fieldstatus = "statut";
3611
+        }
3612
+        if ($elementTable == 'expensereport') {
3613
+            $fieldstatus = "fk_statut";
3614
+        }
3615
+        if ($elementTable == 'commande_fournisseur_dispatch') {
3616
+            $fieldstatus = "status";
3617
+        }
3235 3618
 
3236 3619
         $sql = "UPDATE " . MAIN_DB_PREFIX . $elementTable;
3237 3620
         $sql .= " SET " . $fieldstatus . " = " . $status;
3238 3621
         // If status = 1 = validated, update also fk_user_valid
3239
-        if ($status == 1 && $elementTable == 'expensereport') $sql .= ", fk_user_valid = " . $user->id;
3622
+        if ($status == 1 && $elementTable == 'expensereport') {
3623
+            $sql .= ", fk_user_valid = " . $user->id;
3624
+        }
3240 3625
         $sql .= " WHERE rowid=" . $elementId;
3241 3626
 
3242 3627
         dol_syslog(get_class($this) . "::setStatut", LOG_DEBUG);
@@ -3245,12 +3630,27 @@  discard block
 block discarded – undo
3245 3630
 
3246 3631
             // Try autoset of trigkey
3247 3632
             if (empty($trigkey)) {
3248
-                if ($this->element == 'supplier_proposal' && $status == 2) $trigkey = 'SUPPLIER_PROPOSAL_SIGN';   // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class
3249
-                if ($this->element == 'supplier_proposal' && $status == 3) $trigkey = 'SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class
3250
-                if ($this->element == 'supplier_proposal' && $status == 4) $trigkey = 'SUPPLIER_PROPOSAL_CLOSE';  // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class
3251
-                if ($this->element == 'fichinter' && $status == 3) $trigkey = 'FICHINTER_CLASSIFY_DONE';
3252
-                if ($this->element == 'fichinter' && $status == 2) $trigkey = 'FICHINTER_CLASSIFY_BILLED';
3253
-                if ($this->element == 'fichinter' && $status == 1) $trigkey = 'FICHINTER_CLASSIFY_UNBILLED';
3633
+                if ($this->element == 'supplier_proposal' && $status == 2) {
3634
+                    $trigkey = 'SUPPLIER_PROPOSAL_SIGN';
3635
+                }
3636
+                // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class
3637
+                if ($this->element == 'supplier_proposal' && $status == 3) {
3638
+                    $trigkey = 'SUPPLIER_PROPOSAL_REFUSE';
3639
+                }
3640
+                // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class
3641
+                if ($this->element == 'supplier_proposal' && $status == 4) {
3642
+                    $trigkey = 'SUPPLIER_PROPOSAL_CLOSE';
3643
+                }
3644
+                // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class
3645
+                if ($this->element == 'fichinter' && $status == 3) {
3646
+                    $trigkey = 'FICHINTER_CLASSIFY_DONE';
3647
+                }
3648
+                if ($this->element == 'fichinter' && $status == 2) {
3649
+                    $trigkey = 'FICHINTER_CLASSIFY_BILLED';
3650
+                }
3651
+                if ($this->element == 'fichinter' && $status == 1) {
3652
+                    $trigkey = 'FICHINTER_CLASSIFY_UNBILLED';
3653
+                }
3254 3654
             }
3255 3655
 
3256 3656
             if ($trigkey) {
@@ -3268,9 +3668,11 @@  discard block
 block discarded – undo
3268 3668
             if (!$error) {
3269 3669
                 $this->db->commit();
3270 3670
 
3271
-                if (empty($savElementId))    // If the element we update was $this (so $elementId is null)
3671
+                if (empty($savElementId)) {
3672
+                    // If the element we update was $this (so $elementId is null)
3272 3673
                 {
3273 3674
                     $this->statut = $status;
3675
+                }
3274 3676
                     $this->status = $status;
3275 3677
                 }
3276 3678
 
@@ -3302,8 +3704,13 @@  discard block
 block discarded – undo
3302 3704
     {
3303 3705
         global $conf;
3304 3706
 
3305
-        if (empty($id) && empty($ref)) return 0;
3306
-        if (!empty($conf->global->MAIN_DISABLE_CANVAS)) return 0;    // To increase speed. Not enabled by default.
3707
+        if (empty($id) && empty($ref)) {
3708
+            return 0;
3709
+        }
3710
+        if (!empty($conf->global->MAIN_DISABLE_CANVAS)) {
3711
+            return 0;
3712
+        }
3713
+        // To increase speed. Not enabled by default.
3307 3714
 
3308 3715
         // Clean parameters
3309 3716
         $ref = trim($ref);
@@ -3311,8 +3718,12 @@  discard block
 block discarded – undo
3311 3718
         $sql = "SELECT rowid, canvas";
3312 3719
         $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
3313 3720
         $sql .= " WHERE entity IN (" . getEntity($this->element) . ")";
3314
-        if (!empty($id)) $sql .= " AND rowid = " . $id;
3315
-        if (!empty($ref)) $sql .= " AND ref = '" . $this->db->escape($ref) . "'";
3721
+        if (!empty($id)) {
3722
+            $sql .= " AND rowid = " . $id;
3723
+        }
3724
+        if (!empty($ref)) {
3725
+            $sql .= " AND ref = '" . $this->db->escape($ref) . "'";
3726
+        }
3316 3727
 
3317 3728
         $resql = $this->db->query($sql);
3318 3729
         if ($resql) {
@@ -3320,7 +3731,9 @@  discard block
 block discarded – undo
3320 3731
             if ($obj) {
3321 3732
                 $this->canvas = $obj->canvas;
3322 3733
                 return 1;
3323
-            } else return 0;
3734
+            } else {
3735
+                return 0;
3736
+            }
3324 3737
         } else {
3325 3738
             dol_print_error($this->db);
3326 3739
             return -1;
@@ -3359,12 +3772,24 @@  discard block
 block discarded – undo
3359 3772
 
3360 3773
         foreach ($this->lines as $key => $val) {
3361 3774
             $qualified = 0;
3362
-            if ($predefined == -1) $qualified = 1;
3363
-            if ($predefined == 1 && $val->fk_product > 0) $qualified = 1;
3364
-            if ($predefined == 0 && $val->fk_product <= 0) $qualified = 1;
3365
-            if ($predefined == 2 && $val->fk_product > 0 && $val->product_type == 0) $qualified = 1;
3366
-            if ($predefined == 3 && $val->fk_product > 0 && $val->product_type == 1) $qualified = 1;
3367
-            if ($qualified) $nb++;
3775
+            if ($predefined == -1) {
3776
+                $qualified = 1;
3777
+            }
3778
+            if ($predefined == 1 && $val->fk_product > 0) {
3779
+                $qualified = 1;
3780
+            }
3781
+            if ($predefined == 0 && $val->fk_product <= 0) {
3782
+                $qualified = 1;
3783
+            }
3784
+            if ($predefined == 2 && $val->fk_product > 0 && $val->product_type == 0) {
3785
+                $qualified = 1;
3786
+            }
3787
+            if ($predefined == 3 && $val->fk_product > 0 && $val->product_type == 1) {
3788
+                $qualified = 1;
3789
+            }
3790
+            if ($qualified) {
3791
+                $nb++;
3792
+            }
3368 3793
         }
3369 3794
         dol_syslog(get_class($this) . '::hasProductsOrServices we found ' . $nb . ' qualified lines of products/servcies');
3370 3795
         return $nb;
@@ -3426,14 +3851,22 @@  discard block
 block discarded – undo
3426 3851
 
3427 3852
         foreach ($this->lines as $line) {
3428 3853
             if (isset($line->qty_asked)) {
3429
-                if (empty($totalOrdered)) $totalOrdered = 0;  // Avoid warning because $totalOrdered is ''
3854
+                if (empty($totalOrdered)) {
3855
+                    $totalOrdered = 0;
3856
+                }
3857
+                // Avoid warning because $totalOrdered is ''
3430 3858
                 $totalOrdered += $line->qty_asked;    // defined for shipment only
3431 3859
             }
3432 3860
             if (isset($line->qty_shipped)) {
3433
-                if (empty($totalToShip)) $totalToShip = 0;    // Avoid warning because $totalToShip is ''
3861
+                if (empty($totalToShip)) {
3862
+                    $totalToShip = 0;
3863
+                }
3864
+                // Avoid warning because $totalToShip is ''
3434 3865
                 $totalToShip += $line->qty_shipped;   // defined for shipment only
3435 3866
             } else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) {
3436
-                if (empty($totalToShip)) $totalToShip = 0;
3867
+                if (empty($totalToShip)) {
3868
+                    $totalToShip = 0;
3869
+                }
3437 3870
                 $totalToShip += $line->qty;   // defined for reception only
3438 3871
             }
3439 3872
 
@@ -3457,16 +3890,28 @@  discard block
 block discarded – undo
3457 3890
 
3458 3891
             $weightUnit = 0;
3459 3892
             $volumeUnit = 0;
3460
-            if (!empty($weight_units)) $weightUnit = $weight_units;
3461
-            if (!empty($volume_units)) $volumeUnit = $volume_units;
3893
+            if (!empty($weight_units)) {
3894
+                $weightUnit = $weight_units;
3895
+            }
3896
+            if (!empty($volume_units)) {
3897
+                $volumeUnit = $volume_units;
3898
+            }
3462 3899
 
3463
-            if (empty($totalWeight)) $totalWeight = 0;  // Avoid warning because $totalWeight is ''
3464
-            if (empty($totalVolume)) $totalVolume = 0;  // Avoid warning because $totalVolume is ''
3900
+            if (empty($totalWeight)) {
3901
+                $totalWeight = 0;
3902
+            }
3903
+            // Avoid warning because $totalWeight is ''
3904
+            if (empty($totalVolume)) {
3905
+                $totalVolume = 0;
3906
+            }
3907
+            // Avoid warning because $totalVolume is ''
3465 3908
 
3466 3909
             //var_dump($line->volume_units);
3467
-            if ($weight_units < 50)   // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch)
3910
+            if ($weight_units < 50) {
3911
+                // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch)
3468 3912
             {
3469 3913
                 $trueWeightUnit = pow(10, $weightUnit);
3914
+            }
3470 3915
                 $totalWeight += $weight * $qty * $trueWeightUnit;
3471 3916
             } else {
3472 3917
                 if ($weight_units == 99) {
@@ -3477,13 +3922,17 @@  discard block
 block discarded – undo
3477 3922
                     // conversion 1 Ounce = 0.0283495 KG
3478 3923
                     $trueWeightUnit = 0.0283495;
3479 3924
                     $totalWeight += $weight * $qty * $trueWeightUnit;
3480
-                } else
3481
-                    $totalWeight += $weight * $qty;   // This may be wrong if we mix different units
3925
+                } else {
3926
+                                    $totalWeight += $weight * $qty;
3927
+                }
3928
+                // This may be wrong if we mix different units
3482 3929
             }
3483
-            if ($volume_units < 50)   // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch)
3930
+            if ($volume_units < 50) {
3931
+                // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch)
3484 3932
             {
3485 3933
                 //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit;
3486 3934
                 $trueVolumeUnit = pow(10, $volumeUnit);
3935
+            }
3487 3936
                 //print $line->volume;
3488 3937
                 $totalVolume += $volume * $qty * $trueVolumeUnit;
3489 3938
             } else {
@@ -3602,7 +4051,9 @@  discard block
 block discarded – undo
3602 4051
                 $this->errors[] = $this->db->lasterror();
3603 4052
                 return -1;
3604 4053
             }
3605
-        } else return -1;
4054
+        } else {
4055
+            return -1;
4056
+        }
3606 4057
     }
3607 4058
 
3608 4059
 
@@ -3638,7 +4089,9 @@  discard block
 block discarded – undo
3638 4089
             } else {
3639 4090
                 $res = include $tpl; // for debug
3640 4091
             }
3641
-            if ($res) break;
4092
+            if ($res) {
4093
+                break;
4094
+            }
3642 4095
         }
3643 4096
     }
3644 4097
 
@@ -3669,7 +4122,9 @@  discard block
 block discarded – undo
3669 4122
 
3670 4123
         // Define usemargins
3671 4124
         $usemargins = 0;
3672
-        if (!empty($conf->margin->enabled) && !empty($this->element) && in_array($this->element, array('facture', 'propal', 'commande'))) $usemargins = 1;
4125
+        if (!empty($conf->margin->enabled) && !empty($this->element) && in_array($this->element, array('facture', 'propal', 'commande'))) {
4126
+            $usemargins = 1;
4127
+        }
3673 4128
 
3674 4129
         $num = count($this->lines);
3675 4130
 
@@ -3687,7 +4142,9 @@  discard block
 block discarded – undo
3687 4142
             print '<tr class="liste_titre nodrag nodrop">';
3688 4143
 
3689 4144
             // Adds a line numbering column
3690
-            if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5">&nbsp;</td>';
4145
+            if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
4146
+                print '<td class="linecolnum" align="center" width="5">&nbsp;</td>';
4147
+            }
3691 4148
 
3692 4149
             // Description
3693 4150
             print '<td class="linecoldescription">' . $langs->trans('Description') . '</td>';
@@ -3703,9 +4160,13 @@  discard block
 block discarded – undo
3703 4160
             print '<td class="linecoluht" align="right" width="80">' . $langs->trans('PriceUHT') . '</td>';
3704 4161
 
3705 4162
             // Multicurrency
3706
-            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>';
4163
+            if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) {
4164
+                print '<td class="linecoluht_currency" align="right" width="80">' . $langs->trans('PriceUHTCurrency', $this->multicurrency_code) . '</td>';
4165
+            }
3707 4166
 
3708
-            if ($inputalsopricewithtax) print '<td align="right" width="80">' . $langs->trans('PriceUTTC') . '</td>';
4167
+            if ($inputalsopricewithtax) {
4168
+                print '<td align="right" width="80">' . $langs->trans('PriceUTTC') . '</td>';
4169
+            }
3709 4170
 
3710 4171
             // Qty
3711 4172
             print '<td class="linecolqty" align="right">' . $langs->trans('Qty') . '</td>';
@@ -3723,25 +4184,32 @@  discard block
 block discarded – undo
3723 4184
 
3724 4185
             if ($usemargins && !empty($conf->margin->enabled) && empty($user->societe_id)) {
3725 4186
                 if (!empty($user->rights->margins->creer)) {
3726
-                    if ($conf->global->MARGIN_TYPE == "1")
3727
-                        print '<td class="linecolmargin1 margininfos" align="right" width="80">' . $langs->trans('BuyingPrice') . '</td>';
3728
-                    else
3729
-                        print '<td class="linecolmargin1 margininfos" align="right" width="80">' . $langs->trans('CostPrice') . '</td>';
4187
+                    if ($conf->global->MARGIN_TYPE == "1") {
4188
+                                            print '<td class="linecolmargin1 margininfos" align="right" width="80">' . $langs->trans('BuyingPrice') . '</td>';
4189
+                    } else {
4190
+                                            print '<td class="linecolmargin1 margininfos" align="right" width="80">' . $langs->trans('CostPrice') . '</td>';
4191
+                    }
3730 4192
                 }
3731 4193
 
3732
-                if (!empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous)
3733
-                    print '<td class="linecolmargin2 margininfos" align="right" width="50">' . $langs->trans('MarginRate') . '</td>';
3734
-                if (!empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous)
3735
-                    print '<td class="linecolmargin2 margininfos" align="right" width="50">' . $langs->trans('MarkRate') . '</td>';
4194
+                if (!empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) {
4195
+                                    print '<td class="linecolmargin2 margininfos" align="right" width="50">' . $langs->trans('MarginRate') . '</td>';
4196
+                }
4197
+                if (!empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) {
4198
+                                    print '<td class="linecolmargin2 margininfos" align="right" width="50">' . $langs->trans('MarkRate') . '</td>';
4199
+                }
3736 4200
             }
3737 4201
 
3738 4202
             // Total HT
3739 4203
             print '<td class="linecolht" align="right">' . $langs->trans('TotalHTShort') . '</td>';
3740 4204
 
3741 4205
             // Multicurrency
3742
-            if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoltotalht_currency" align="right">' . $langs->trans('TotalHTShortCurrency', $this->multicurrency_code) . '</td>';
4206
+            if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) {
4207
+                print '<td class="linecoltotalht_currency" align="right">' . $langs->trans('TotalHTShortCurrency', $this->multicurrency_code) . '</td>';
4208
+            }
3743 4209
 
3744
-            if ($outputalsopricetotalwithtax) print '<td align="right" width="80">' . $langs->trans('TotalTTCShort') . '</td>';
4210
+            if ($outputalsopricetotalwithtax) {
4211
+                print '<td align="right" width="80">' . $langs->trans('TotalTTCShort') . '</td>';
4212
+            }
3745 4213
 
3746 4214
             print '<td class="linecoledit"></td>';  // No width to allow autodim
3747 4215
 
@@ -3769,10 +4237,12 @@  discard block
 block discarded – undo
3769 4237
             $line->fetch_optionals();
3770 4238
 
3771 4239
             //if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line)))
3772
-            if (is_object($hookmanager))   // Old code is commented on preceding line.
4240
+            if (is_object($hookmanager)) {
4241
+                // Old code is commented on preceding line.
3773 4242
             {
3774 4243
                 if (empty($line->fk_parent_line)) {
3775 4244
                     $parameters = array('line' => $line, 'var' => $var, 'num' => $num, 'i' => $i, 'dateSelector' => $dateSelector, 'seller' => $seller, 'buyer' => $buyer, 'selected' => $selected, 'extrafieldsline' => $extrafieldsline);
4245
+            }
3776 4246
                     $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action);    // Note that $action and $object may have been modified by some hooks
3777 4247
                 } else {
3778 4248
                     $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);
@@ -3827,8 +4297,14 @@  discard block
 block discarded – undo
3827 4297
         // Show product and description
3828 4298
         $type = (!empty($line->product_type) ? $line->product_type : $line->fk_product_type);
3829 4299
         // Try to enhance type detection using date_start and date_end for free lines where type was not saved.
3830
-        if (!empty($line->date_start)) $type = 1; // deprecated
3831
-        if (!empty($line->date_end)) $type = 1; // deprecated
4300
+        if (!empty($line->date_start)) {
4301
+            $type = 1;
4302
+        }
4303
+        // deprecated
4304
+        if (!empty($line->date_end)) {
4305
+            $type = 1;
4306
+        }
4307
+        // deprecated
3832 4308
 
3833 4309
         // Ligne en mode visu
3834 4310
         if ($action != 'editline' || $selected != $line->id) {
@@ -3853,8 +4329,13 @@  discard block
 block discarded – undo
3853 4329
 
3854 4330
                     $outputlangs = $langs;
3855 4331
                     $newlang = '';
3856
-                    if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
3857
-                    if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang = $this->thirdparty->default_lang;        // For language to language of customer
4332
+                    if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
4333
+                        $newlang = GETPOST('lang_id', 'aZ09');
4334
+                    }
4335
+                    if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) {
4336
+                        $newlang = $this->thirdparty->default_lang;
4337
+                    }
4338
+                    // For language to language of customer
3858 4339
                     if (!empty($newlang)) {
3859 4340
                         $outputlangs = new Translate("", $conf);
3860 4341
                         $outputlangs->setDefaultLang($newlang);
@@ -3881,7 +4362,9 @@  discard block
 block discarded – undo
3881 4362
                 } else {
3882 4363
                     $res = include $tpl; // for debug
3883 4364
                 }
3884
-                if ($res) break;
4365
+                if ($res) {
4366
+                    break;
4367
+                }
3885 4368
             }
3886 4369
         }
3887 4370
 
@@ -3902,7 +4385,9 @@  discard block
 block discarded – undo
3902 4385
                 } else {
3903 4386
                     $res = include $tpl; // for debug
3904 4387
                 }
3905
-                if ($res) break;
4388
+                if ($res) {
4389
+                    break;
4390
+                }
3906 4391
             }
3907 4392
         }
3908 4393
     }
@@ -3916,7 +4401,9 @@  discard block
 block discarded – undo
3916 4401
         global $user;
3917 4402
 
3918 4403
         $element = $this->element;
3919
-        if ($element == 'facturerec') $element = 'facture';
4404
+        if ($element == 'facturerec') {
4405
+            $element = 'facture';
4406
+        }
3920 4407
 
3921 4408
         return $user->rights->{$element};
3922 4409
     }
@@ -3939,7 +4426,9 @@  discard block
 block discarded – undo
3939 4426
         print '<td>' . $langs->trans('Description') . '</td>';
3940 4427
         print '<td align="right">' . $langs->trans('VATRate') . '</td>';
3941 4428
         print '<td align="right">' . $langs->trans('PriceUHT') . '</td>';
3942
-        if (!empty($conf->multicurrency->enabled)) print '<td align="right">' . $langs->trans('PriceUHTCurrency') . '</td>';
4429
+        if (!empty($conf->multicurrency->enabled)) {
4430
+            print '<td align="right">' . $langs->trans('PriceUHTCurrency') . '</td>';
4431
+        }
3943 4432
         print '<td align="right">' . $langs->trans('Qty') . '</td>';
3944 4433
         if ($conf->global->PRODUCT_USE_UNITS) {
3945 4434
             print '<td align="left">' . $langs->trans('Unit') . '</td>';
@@ -3986,21 +4475,29 @@  discard block
 block discarded – undo
3986 4475
             $date_start = $line->date_start;
3987 4476
         } else {
3988 4477
             $date_start = $line->date_debut_prevue;
3989
-            if ($line->date_debut_reel) $date_start = $line->date_debut_reel;
4478
+            if ($line->date_debut_reel) {
4479
+                $date_start = $line->date_debut_reel;
4480
+            }
3990 4481
         }
3991 4482
         if (!empty($line->date_end)) {
3992 4483
             $date_end = $line->date_end;
3993 4484
         } else {
3994 4485
             $date_end = $line->date_fin_prevue;
3995
-            if ($line->date_fin_reel) $date_end = $line->date_fin_reel;
4486
+            if ($line->date_fin_reel) {
4487
+                $date_end = $line->date_fin_reel;
4488
+            }
3996 4489
         }
3997 4490
 
3998 4491
         $this->tpl['label'] = '';
3999
-        if (!empty($line->fk_parent_line)) $this->tpl['label'] .= img_picto('', 'rightarrow');
4492
+        if (!empty($line->fk_parent_line)) {
4493
+            $this->tpl['label'] .= img_picto('', 'rightarrow');
4494
+        }
4000 4495
 
4001
-        if (($line->info_bits & 2) == 2)  // TODO Not sure this is used for source object
4496
+        if (($line->info_bits & 2) == 2) {
4497
+            // TODO Not sure this is used for source object
4002 4498
         {
4003 4499
             $discount = new DiscountAbsolute($this->db);
4500
+        }
4004 4501
             $discount->fk_soc = $this->socid;
4005 4502
             $this->tpl['label'] .= $discount->getNomUrl(0, 'discount');
4006 4503
         } else if (!empty($line->fk_product)) {
@@ -4034,14 +4531,18 @@  discard block
 block discarded – undo
4034 4531
         }
4035 4532
 
4036 4533
         if (!empty($line->desc)) {
4037
-            if ($line->desc == '(CREDIT_NOTE)')  // TODO Not sure this is used for source object
4534
+            if ($line->desc == '(CREDIT_NOTE)') {
4535
+                // TODO Not sure this is used for source object
4038 4536
             {
4039 4537
                 $discount = new DiscountAbsolute($this->db);
4538
+            }
4040 4539
                 $discount->fetch($line->fk_remise_except);
4041 4540
                 $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0));
4042
-            } elseif ($line->desc == '(DEPOSIT)')  // TODO Not sure this is used for source object
4541
+            } elseif ($line->desc == '(DEPOSIT)') {
4542
+                // TODO Not sure this is used for source object
4043 4543
             {
4044 4544
                 $discount = new DiscountAbsolute($this->db);
4545
+            }
4045 4546
                 $discount->fetch($line->fk_remise_except);
4046 4547
                 $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0));
4047 4548
             } elseif ($line->desc == '(EXCESS RECEIVED)') {
@@ -4062,17 +4563,23 @@  discard block
 block discarded – undo
4062 4563
         // VAT Rate
4063 4564
         $this->tpl['vat_rate'] = vatrate($line->tva_tx, true);
4064 4565
         $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : '';
4065
-        if (!empty($line->vat_src_code) && !preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'] .= ' (' . $line->vat_src_code . ')';
4566
+        if (!empty($line->vat_src_code) && !preg_match('/\(/', $this->tpl['vat_rate'])) {
4567
+            $this->tpl['vat_rate'] .= ' (' . $line->vat_src_code . ')';
4568
+        }
4066 4569
 
4067 4570
         $this->tpl['price'] = price($line->subprice);
4068 4571
         $this->tpl['multicurrency_price'] = price($line->multicurrency_subprice);
4069 4572
         $this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : '&nbsp;';
4070
-        if ($conf->global->PRODUCT_USE_UNITS) $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long'));
4573
+        if ($conf->global->PRODUCT_USE_UNITS) {
4574
+            $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long'));
4575
+        }
4071 4576
         $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : '&nbsp;';
4072 4577
 
4073 4578
         // Is the line strike or not
4074 4579
         $this->tpl['strike'] = 0;
4075
-        if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike'] = 1;
4580
+        if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) {
4581
+            $this->tpl['strike'] = 1;
4582
+        }
4076 4583
 
4077 4584
         // Output template part (modules that overwrite templates must declare this into descriptor)
4078 4585
         // Use global variables + $dateSelector + $seller and $buyer
@@ -4084,7 +4591,9 @@  discard block
 block discarded – undo
4084 4591
             } else {
4085 4592
                 $res = include $tpl; // for debug
4086 4593
             }
4087
-            if ($res) break;
4594
+            if ($res) {
4595
+                break;
4596
+            }
4088 4597
         }
4089 4598
     }
4090 4599
 
@@ -4226,13 +4735,21 @@  discard block
 block discarded – undo
4226 4735
         global $conf, $_POST;
4227 4736
 
4228 4737
         // If param here has been posted, we use this value first.
4229
-        if (isset($_POST[$fieldname])) return GETPOST($fieldname, 2);
4738
+        if (isset($_POST[$fieldname])) {
4739
+            return GETPOST($fieldname, 2);
4740
+        }
4230 4741
 
4231
-        if (isset($alternatevalue)) return $alternatevalue;
4742
+        if (isset($alternatevalue)) {
4743
+            return $alternatevalue;
4744
+        }
4232 4745
 
4233 4746
         $newelement = $this->element;
4234
-        if ($newelement == 'facture') $newelement = 'invoice';
4235
-        if ($newelement == 'commande') $newelement = 'order';
4747
+        if ($newelement == 'facture') {
4748
+            $newelement = 'invoice';
4749
+        }
4750
+        if ($newelement == 'commande') {
4751
+            $newelement = 'order';
4752
+        }
4236 4753
         if (empty($newelement)) {
4237 4754
             dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
4238 4755
             return '';
@@ -4240,7 +4757,9 @@  discard block
 block discarded – undo
4240 4757
 
4241 4758
         $keyforfieldname = strtoupper($newelement . '_DEFAULT_' . $fieldname);
4242 4759
         //var_dump($keyforfieldname);
4243
-        if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname;
4760
+        if (isset($conf->global->$keyforfieldname)) {
4761
+            return $conf->global->$keyforfieldname;
4762
+        }
4244 4763
 
4245 4764
         // TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname
4246 4765
     }
@@ -4256,7 +4775,9 @@  discard block
 block discarded – undo
4256 4775
     function fetch_optionals($rowid = null, $optionsArray = null)
4257 4776
     {
4258 4777
         // phpcs:enable
4259
-        if (empty($rowid)) $rowid = $this->id;
4778
+        if (empty($rowid)) {
4779
+            $rowid = $this->id;
4780
+        }
4260 4781
 
4261 4782
         // To avoid SQL errors. Probably not the better solution though
4262 4783
         if (!$this->table_element) {
@@ -4286,7 +4807,10 @@  discard block
 block discarded – undo
4286 4807
         }
4287 4808
 
4288 4809
         $table_element = $this->table_element;
4289
-        if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility
4810
+        if ($table_element == 'categorie') {
4811
+            $table_element = 'categories';
4812
+        }
4813
+        // For compatibility
4290 4814
 
4291 4815
         // Request to get complementary values
4292 4816
         if (is_array($optionsArray) && count($optionsArray) > 0) {
@@ -4325,8 +4849,11 @@  discard block
 block discarded – undo
4325 4849
 
4326 4850
                 $this->db->free($resql);
4327 4851
 
4328
-                if ($numrows) return $numrows;
4329
-                else return 0;
4852
+                if ($numrows) {
4853
+                    return $numrows;
4854
+                } else {
4855
+                    return 0;
4856
+                }
4330 4857
             } else {
4331 4858
                 dol_print_error($this->db);
4332 4859
                 return -1;
@@ -4347,7 +4874,10 @@  discard block
 block discarded – undo
4347 4874
         $this->db->begin();
4348 4875
 
4349 4876
         $table_element = $this->table_element;
4350
-        if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility
4877
+        if ($table_element == 'categorie') {
4878
+            $table_element = 'categories';
4879
+        }
4880
+        // For compatibility
4351 4881
 
4352 4882
         $sql_del = "DELETE FROM " . MAIN_DB_PREFIX . $table_element . "_extrafields WHERE fk_object = " . $this->id;
4353 4883
         dol_syslog(get_class($this) . "::deleteExtraFields delete", LOG_DEBUG);
@@ -4376,11 +4906,16 @@  discard block
 block discarded – undo
4376 4906
     {
4377 4907
         global $conf, $langs, $user;
4378 4908
 
4379
-        if (empty($userused)) $userused = $user;
4909
+        if (empty($userused)) {
4910
+            $userused = $user;
4911
+        }
4380 4912
 
4381 4913
         $error = 0;
4382 4914
 
4383
-        if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0;    // For avoid conflicts if trigger used
4915
+        if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
4916
+            return 0;
4917
+        }
4918
+        // For avoid conflicts if trigger used
4384 4919
 
4385 4920
         if (!empty($this->array_options) && isset($this->array_options["options_" . $key])) {
4386 4921
             // Check parameters
@@ -4462,7 +4997,9 @@  discard block
 block discarded – undo
4462 4997
                 // Call trigger
4463 4998
                 $this->context = array('extrafieldupdate' => 1);
4464 4999
                 $result = $this->call_trigger($trigger, $userused);
4465
-                if ($result < 0) $error++;
5000
+                if ($result < 0) {
5001
+                    $error++;
5002
+                }
4466 5003
                 // End call trigger
4467 5004
             }
4468 5005
 
@@ -4474,7 +5011,9 @@  discard block
 block discarded – undo
4474 5011
                 $this->db->commit();
4475 5012
                 return 1;
4476 5013
             }
4477
-        } else return 0;
5014
+        } else {
5015
+            return 0;
5016
+        }
4478 5017
     }
4479 5018
 
4480 5019
     /**
@@ -4546,8 +5085,11 @@  discard block
 block discarded – undo
4546 5085
 
4547 5086
 
4548 5087
         if ($computed) {
4549
-            if (!preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">' . $langs->trans("AutomaticallyCalculated") . '</span>';
4550
-            else return '';
5088
+            if (!preg_match('/^search_/', $keyprefix)) {
5089
+                return '<span class="opacitymedium">' . $langs->trans("AutomaticallyCalculated") . '</span>';
5090
+            } else {
5091
+                return '';
5092
+            }
4551 5093
         }
4552 5094
 
4553 5095
 
@@ -4584,7 +5126,9 @@  discard block
 block discarded – undo
4584 5126
             $showtime = in_array($type, array('datetime')) ? 1 : 0;
4585 5127
 
4586 5128
             // Do not show current date when field not required (see selectDate() method)
4587
-            if (!$required && $value == '') $value = '-1';
5129
+            if (!$required && $value == '') {
5130
+                $value = '-1';
5131
+            }
4588 5132
 
4589 5133
             // TODO Must also support $moreparam
4590 5134
             $out = $form->selectDate($value, $keyprefix . $key . $keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1);
@@ -4597,18 +5141,22 @@  discard block
 block discarded – undo
4597 5141
         } elseif (in_array($type, array('mail', 'phone', 'url'))) {
4598 5142
             $out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . dol_escape_htmltag($value) . '" ' . ($moreparam ? $moreparam : '') . '>';
4599 5143
         } elseif ($type == 'text') {
4600
-            if (!preg_match('/search_/', $keyprefix))        // If keyprefix is search_ or search_options_, we must just use a simple text field
5144
+            if (!preg_match('/search_/', $keyprefix)) {
5145
+                // If keyprefix is search_ or search_options_, we must just use a simple text field
4601 5146
             {
4602 5147
                 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
5148
+            }
4603 5149
                 $doleditor = new DolEditor($keyprefix . $key . $keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, false, ROWS_5, '90%');
4604 5150
                 $out = $doleditor->Create(1);
4605 5151
             } else {
4606 5152
                 $out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . dol_escape_htmltag($value) . '" ' . ($moreparam ? $moreparam : '') . '>';
4607 5153
             }
4608 5154
         } elseif ($type == 'html') {
4609
-            if (!preg_match('/search_/', $keyprefix))        // If keyprefix is search_ or search_options_, we must just use a simple text field
5155
+            if (!preg_match('/search_/', $keyprefix)) {
5156
+                // If keyprefix is search_ or search_options_, we must just use a simple text field
4610 5157
             {
4611 5158
                 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
5159
+            }
4612 5160
                 $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%');
4613 5161
                 $out = $doleditor->Create(1);
4614 5162
             } else {
@@ -4640,9 +5188,13 @@  discard block
 block discarded – undo
4640 5188
             }
4641 5189
 
4642 5190
             $out .= '<select class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" ' . ($moreparam ? $moreparam : '') . '>';
4643
-            if ((!isset($this->fields[$key]['default'])) || ($this->fields[$key]['notnull'] != 1)) $out .= '<option value="0">&nbsp;</option>';
5191
+            if ((!isset($this->fields[$key]['default'])) || ($this->fields[$key]['notnull'] != 1)) {
5192
+                $out .= '<option value="0">&nbsp;</option>';
5193
+            }
4644 5194
             foreach ($param['options'] as $key => $val) {
4645
-                if ((string)$key == '') continue;
5195
+                if ((string)$key == '') {
5196
+                    continue;
5197
+                }
4646 5198
                 list($val, $parent) = explode('|', $val);
4647 5199
                 $out .= '<option value="' . $key . '"';
4648 5200
                 $out .= (((string)$value == (string)$key) ? ' selected' : '');
@@ -4765,7 +5317,9 @@  discard block
 block discarded – undo
4765 5317
                                     $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
4766 5318
                                 }
4767 5319
                             }
4768
-                            if (empty($labeltoshow)) $labeltoshow = '(not defined)';
5320
+                            if (empty($labeltoshow)) {
5321
+                                $labeltoshow = '(not defined)';
5322
+                            }
4769 5323
                             if ($value == $obj->rowid) {
4770 5324
                                 $out .= '<option value="' . $obj->rowid . '" selected>' . $labeltoshow . '</option>';
4771 5325
                             }
@@ -4917,8 +5471,9 @@  discard block
 block discarded – undo
4917 5471
                                     $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
4918 5472
                                 }
4919 5473
                             }
4920
-                            if (empty($labeltoshow))
4921
-                                $labeltoshow = '(not defined)';
5474
+                            if (empty($labeltoshow)) {
5475
+                                                            $labeltoshow = '(not defined)';
5476
+                            }
4922 5477
 
4923 5478
                             if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
4924 5479
                                 $data[$obj->rowid] = $labeltoshow;
@@ -4946,8 +5501,11 @@  discard block
 block discarded – undo
4946 5501
             $out = $form->selectForForms($param_list[0], $keyprefix . $key . $keysuffix, $value, $showempty);
4947 5502
             if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
4948 5503
                 list($class, $classfile) = explode(':', $param_list[0]);
4949
-                if (file_exists(dol_buildpath(dirname(dirname($classfile)) . '/card.php'))) $url_path = dol_buildpath(dirname(dirname($classfile)) . '/card.php', 1);
4950
-                else $url_path = dol_buildpath(dirname(dirname($classfile)) . '/' . $class . '_card.php', 1);
5504
+                if (file_exists(dol_buildpath(dirname(dirname($classfile)) . '/card.php'))) {
5505
+                    $url_path = dol_buildpath(dirname(dirname($classfile)) . '/card.php', 1);
5506
+                } else {
5507
+                    $url_path = dol_buildpath(dirname(dirname($classfile)) . '/' . $class . '_card.php', 1);
5508
+                }
4951 5509
                 $out .= '<a class="butActionNew" href="' . $url_path . '?action=create&backtopage=' . $_SERVER['PHP_SELF'] . '"><span class="fa fa-plus-circle valignmiddle"></span></a>';
4952 5510
                 // TODO Add Javascript code to add input fields contents to new elements urls
4953 5511
             }
@@ -5029,16 +5587,25 @@  discard block
 block discarded – undo
5029 5587
         if (preg_match('/varchar\((\d+)\)/', $type, $reg)) {
5030 5588
             $type = 'varchar';        // convert varchar(xx) int varchar
5031 5589
             $size = $reg[1];
5032
-        } elseif (preg_match('/varchar/', $type)) $type = 'varchar';        // convert varchar(xx) int varchar
5033
-        if (is_array($val['arrayofkeyval'])) $type = 'select';
5034
-        if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type = 'link';
5590
+        } elseif (preg_match('/varchar/', $type)) {
5591
+            $type = 'varchar';
5592
+        }
5593
+        // convert varchar(xx) int varchar
5594
+        if (is_array($val['arrayofkeyval'])) {
5595
+            $type = 'select';
5596
+        }
5597
+        if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) {
5598
+            $type = 'link';
5599
+        }
5035 5600
 
5036 5601
         $default = $val['default'];
5037 5602
         $computed = $val['computed'];
5038 5603
         $unique = $val['unique'];
5039 5604
         $required = $val['required'];
5040 5605
         $param = $val['param'];
5041
-        if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval'];
5606
+        if (is_array($val['arrayofkeyval'])) {
5607
+            $param['options'] = $val['arrayofkeyval'];
5608
+        }
5042 5609
         if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) {
5043 5610
             $type = 'link';
5044 5611
             $param['options'] = array($reg[1] . ':' . $reg[2] => $reg[1] . ':' . $reg[2]);
@@ -5048,7 +5615,9 @@  discard block
 block discarded – undo
5048 5615
         $help = $val['help'];
5049 5616
         $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)
5050 5617
 
5051
-        if ($hidden) return '';
5618
+        if ($hidden) {
5619
+            return '';
5620
+        }
5052 5621
 
5053 5622
         // If field is a computed field, value must become result of compute
5054 5623
         if ($computed) {
@@ -5084,9 +5653,11 @@  discard block
 block discarded – undo
5084 5653
         }
5085 5654
 
5086 5655
         // Format output value differently according to properties of field
5087
-        if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value = $this->getNomUrl(1, '', 0, '', 1);
5088
-        elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value = $this->getLibStatut(3);
5089
-        elseif ($type == 'date') {
5656
+        if ($key == 'ref' && method_exists($this, 'getNomUrl')) {
5657
+            $value = $this->getNomUrl(1, '', 0, '', 1);
5658
+        } elseif ($key == 'status' && method_exists($this, 'getLibStatut')) {
5659
+            $value = $this->getLibStatut(3);
5660
+        } elseif ($type == 'date') {
5090 5661
             if (!empty($value)) {
5091 5662
                 $value = dol_print_date($value, 'day');
5092 5663
             } else {
@@ -5184,7 +5755,9 @@  discard block
 block discarded – undo
5184 5755
                         $value = $obj->{$InfoFieldList[1]};
5185 5756
                     }
5186 5757
                 }
5187
-            } else dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING);
5758
+            } else {
5759
+                dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING);
5760
+            }
5188 5761
         } elseif ($type == 'radio') {
5189 5762
             $value = $param['options'][$value];
5190 5763
         } elseif ($type == 'checkbox') {
@@ -5285,7 +5858,9 @@  discard block
 block discarded – undo
5285 5858
                     dol_syslog('Error bad setup of extrafield', LOG_WARNING);
5286 5859
                     return 'Error bad setup of extrafield';
5287 5860
                 }
5288
-            } else $value = '';
5861
+            } else {
5862
+                $value = '';
5863
+            }
5289 5864
         } elseif ($type == 'text' || $type == 'html') {
5290 5865
             $value = dol_htmlentitiesbr($value);
5291 5866
         } elseif ($type == 'password') {
@@ -5315,7 +5890,9 @@  discard block
 block discarded – undo
5315 5890
     {
5316 5891
         global $db, $conf, $langs, $action, $form;
5317 5892
 
5318
-        if (!is_object($form)) $form = new Form($db);
5893
+        if (!is_object($form)) {
5894
+            $form = new Form($db);
5895
+        }
5319 5896
 
5320 5897
         $out = '';
5321 5898
 
@@ -5327,7 +5904,9 @@  discard block
 block discarded – undo
5327 5904
             $e = 0;
5328 5905
             foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $label) {
5329 5906
                 // Show only the key field in params
5330
-                if (is_array($params) && array_key_exists('onlykey', $params) && $key != $params['onlykey']) continue;
5907
+                if (is_array($params) && array_key_exists('onlykey', $params) && $key != $params['onlykey']) {
5908
+                    continue;
5909
+                }
5331 5910
 
5332 5911
                 $enabled = 1;
5333 5912
                 if ($enabled && isset($extrafields->attributes[$this->table_element]['list'][$key])) {
@@ -5339,11 +5918,18 @@  discard block
 block discarded – undo
5339 5918
                     $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1);
5340 5919
                 }
5341 5920
 
5342
-                if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) continue;    // <> -1 and <> 1 and <> 3 = not visible on forms, only on list
5343
-                if (empty($perms)) continue;
5921
+                if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) {
5922
+                    continue;
5923
+                }
5924
+                // <> -1 and <> 1 and <> 3 = not visible on forms, only on list
5925
+                if (empty($perms)) {
5926
+                    continue;
5927
+                }
5344 5928
 
5345 5929
                 // Load language if required
5346
-                if (!empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]);
5930
+                if (!empty($extrafields->attributes[$this->table_element]['langfile'][$key])) {
5931
+                    $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]);
5932
+                }
5347 5933
 
5348 5934
                 $colspan = '3';
5349 5935
                 if (is_array($params) && count($params) > 0) {
@@ -5406,10 +5992,12 @@  discard block
 block discarded – undo
5406 5992
                     // Convert date into timestamp format (value in memory must be a timestamp)
5407 5993
                     if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date', 'datetime'))) {
5408 5994
                         $datenotinstring = $this->array_options['options_' . $key];
5409
-                        if (!is_numeric($this->array_options['options_' . $key]))    // For backward compatibility
5995
+                        if (!is_numeric($this->array_options['options_' . $key])) {
5996
+                            // For backward compatibility
5410 5997
                         {
5411 5998
                             $datenotinstring = $this->db->jdate($datenotinstring);
5412 5999
                         }
6000
+                        }
5413 6001
                         $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;
5414 6002
                     }
5415 6003
                     // Convert float submited string into real php numeric (value in memory must be a php numeric)
@@ -5420,11 +6008,18 @@  discard block
 block discarded – undo
5420 6008
                     $labeltoshow = $langs->trans($label);
5421 6009
 
5422 6010
                     $out .= '<td class="titlefield';
5423
-                    if (GETPOST('action', 'none') == 'create') $out .= 'create';
5424
-                    if ($mode != 'view' && !empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired';
6011
+                    if (GETPOST('action', 'none') == 'create') {
6012
+                        $out .= 'create';
6013
+                    }
6014
+                    if ($mode != 'view' && !empty($extrafields->attributes[$this->table_element]['required'][$key])) {
6015
+                        $out .= ' fieldrequired';
6016
+                    }
5425 6017
                     $out .= '">';
5426
-                    if (!empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]);
5427
-                    else $out .= $labeltoshow;
6018
+                    if (!empty($extrafields->attributes[$object->table_element]['help'][$key])) {
6019
+                        $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]);
6020
+                    } else {
6021
+                        $out .= $labeltoshow;
6022
+                    }
5428 6023
                     $out .= '</td>';
5429 6024
 
5430 6025
                     $html_id = !empty($this->id) ? $this->element . '_extras_' . $key . '_' . $this->id : '';
@@ -5441,8 +6036,11 @@  discard block
 block discarded – undo
5441 6036
 
5442 6037
                     $out .= '</td>';
5443 6038
 
5444
-                    if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>';
5445
-                    else $out .= '</tr>';
6039
+                    if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) {
6040
+                        $out .= '</tr>';
6041
+                    } else {
6042
+                        $out .= '</tr>';
6043
+                    }
5446 6044
                     $e++;
5447 6045
                 }
5448 6046
             }
@@ -5502,9 +6100,11 @@  discard block
 block discarded – undo
5502 6100
 
5503 6101
         $buyPrice = 0;
5504 6102
 
5505
-        if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) // In most cases, test here is false
6103
+        if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) {
6104
+            // In most cases, test here is false
5506 6105
         {
5507 6106
             $buyPrice = $unitPrice * (1 - $discountPercent / 100);
6107
+        }
5508 6108
         } else {
5509 6109
             // Get cost price for margin calculation
5510 6110
             if (!empty($fk_product)) {
@@ -5638,32 +6238,45 @@  discard block
 block discarded – undo
5638 6238
 
5639 6239
                         // Find name of thumb file
5640 6240
                         $photo_vignette = basename(getImageFileNameForSize($dir . $file, '_small'));
5641
-                        if (!dol_is_file($dirthumb . $photo_vignette)) $photo_vignette = '';
6241
+                        if (!dol_is_file($dirthumb . $photo_vignette)) {
6242
+                            $photo_vignette = '';
6243
+                        }
5642 6244
 
5643 6245
                         // Get filesize of original file
5644 6246
                         $imgarray = dol_getImageSize($dir . $photo);
5645 6247
 
5646 6248
                         if ($nbbyrow > 0) {
5647
-                            if ($nbphoto == 1) $return .= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';
6249
+                            if ($nbphoto == 1) {
6250
+                                $return .= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';
6251
+                            }
5648 6252
 
5649
-                            if ($nbphoto % $nbbyrow == 1) $return .= '<tr align=center valign=middle border=1>';
6253
+                            if ($nbphoto % $nbbyrow == 1) {
6254
+                                $return .= '<tr align=center valign=middle border=1>';
6255
+                            }
5650 6256
                             $return .= '<td width="' . ceil(100 / $nbbyrow) . '%" class="photo">';
5651
-                        } else if ($nbbyrow < 0) $return .= '<div class="inline-block">';
6257
+                        } else if ($nbbyrow < 0) {
6258
+                            $return .= '<div class="inline-block">';
6259
+                        }
5652 6260
 
5653 6261
                         $return .= "\n";
5654 6262
 
5655 6263
                         $relativefile = preg_replace('/^\//', '', $pdir . $photo);
5656 6264
                         if (empty($nolink)) {
5657 6265
                             $urladvanced = getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity=' . $this->entity);
5658
-                            if ($urladvanced) $return .= '<a href="' . $urladvanced . '">';
5659
-                            else $return .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $this->entity . '&file=' . urlencode($pdir . $photo) . '" class="aphoto" target="_blank">';
6266
+                            if ($urladvanced) {
6267
+                                $return .= '<a href="' . $urladvanced . '">';
6268
+                            } else {
6269
+                                $return .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $this->entity . '&file=' . urlencode($pdir . $photo) . '" class="aphoto" target="_blank">';
6270
+                            }
5660 6271
                         }
5661 6272
 
5662 6273
                         // Show image (width height=$maxHeight)
5663 6274
                         // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine
5664 6275
                         $alt = $langs->transnoentitiesnoconv('File') . ': ' . $relativefile;
5665 6276
                         $alt .= ' - ' . $langs->transnoentitiesnoconv('Size') . ': ' . $imgarray['width'] . 'x' . $imgarray['height'];
5666
-                        if ($notitle) $alt = '';
6277
+                        if ($notitle) {
6278
+                            $alt = '';
6279
+                        }
5667 6280
 
5668 6281
                         if ($usesharelink) {
5669 6282
                             if ($val['share']) {
@@ -5688,10 +6301,14 @@  discard block
 block discarded – undo
5688 6301
                             }
5689 6302
                         }
5690 6303
 
5691
-                        if (empty($nolink)) $return .= '</a>';
6304
+                        if (empty($nolink)) {
6305
+                            $return .= '</a>';
6306
+                        }
5692 6307
                         $return .= "\n";
5693 6308
 
5694
-                        if ($showfilename) $return .= '<br>' . $viewfilename;
6309
+                        if ($showfilename) {
6310
+                            $return .= '<br>' . $viewfilename;
6311
+                        }
5695 6312
                         if ($showaction) {
5696 6313
                             $return .= '<br>';
5697 6314
                             // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
@@ -5712,14 +6329,20 @@  discard block
 block discarded – undo
5712 6329
 
5713 6330
                         if ($nbbyrow > 0) {
5714 6331
                             $return .= '</td>';
5715
-                            if (($nbphoto % $nbbyrow) == 0) $return .= '</tr>';
5716
-                        } else if ($nbbyrow < 0) $return .= '</div>';
6332
+                            if (($nbphoto % $nbbyrow) == 0) {
6333
+                                $return .= '</tr>';
6334
+                            }
6335
+                        } else if ($nbbyrow < 0) {
6336
+                            $return .= '</div>';
6337
+                        }
5717 6338
                     }
5718 6339
 
5719 6340
                     if (empty($size)) {     // Format origine
5720 6341
                         $return .= '<img class="photo photowithmargin" border="0" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $this->entity . '&file=' . urlencode($pdir . $photo) . '">';
5721 6342
 
5722
-                        if ($showfilename) $return .= '<br>' . $viewfilename;
6343
+                        if ($showfilename) {
6344
+                            $return .= '<br>' . $viewfilename;
6345
+                        }
5723 6346
                         if ($showaction) {
5724 6347
                             // Special case for product
5725 6348
                             if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) {
@@ -5734,7 +6357,9 @@  discard block
 block discarded – undo
5734 6357
                     }
5735 6358
 
5736 6359
                     // On continue ou on arrete de boucler ?
5737
-                    if ($nbmax && $nbphoto >= $nbmax) break;
6360
+                    if ($nbmax && $nbphoto >= $nbmax) {
6361
+                        break;
6362
+                    }
5738 6363
                 }
5739 6364
             }
5740 6365
 
@@ -5746,7 +6371,9 @@  discard block
 block discarded – undo
5746 6371
                         $nbphoto++;
5747 6372
                     }
5748 6373
 
5749
-                    if ($nbphoto) $return .= '</table>';
6374
+                    if ($nbphoto) {
6375
+                        $return .= '</table>';
6376
+                    }
5750 6377
                 }
5751 6378
             }
5752 6379
         }
@@ -5765,9 +6392,14 @@  discard block
 block discarded – undo
5765 6392
     public function isText($info)
5766 6393
     {
5767 6394
         if (is_array($info)) {
5768
-            if (isset($info['type']) && $info['type'] == 'text') return true;
5769
-            else return false;
5770
-        } else return false;
6395
+            if (isset($info['type']) && $info['type'] == 'text') {
6396
+                return true;
6397
+            } else {
6398
+                return false;
6399
+            }
6400
+        } else {
6401
+            return false;
6402
+        }
5771 6403
     }
5772 6404
 
5773 6405
     /**
@@ -5786,8 +6418,12 @@  discard block
 block discarded – undo
5786 6418
         $now = dol_now();
5787 6419
 
5788 6420
         $fieldvalues = $this->setSaveQuery();
5789
-        if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation'] = $this->db->idate($now);
5790
-        if (array_key_exists('fk_user_creat', $fieldvalues) && !($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat'] = $user->id;
6421
+        if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) {
6422
+            $fieldvalues['date_creation'] = $this->db->idate($now);
6423
+        }
6424
+        if (array_key_exists('fk_user_creat', $fieldvalues) && !($fieldvalues['fk_user_creat'] > 0)) {
6425
+            $fieldvalues['fk_user_creat'] = $user->id;
6426
+        }
5791 6427
         unset($fieldvalues['rowid']);    // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert.
5792 6428
 
5793 6429
         $keys = array();
@@ -5801,8 +6437,12 @@  discard block
 block discarded – undo
5801 6437
         // Clean and check mandatory
5802 6438
         foreach ($keys as $key) {
5803 6439
             // If field is an implicit foreign key field
5804
-            if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key] = '';
5805
-            if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key] = '';
6440
+            if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') {
6441
+                $values[$key] = '';
6442
+            }
6443
+            if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') {
6444
+                $values[$key] = '';
6445
+            }
5806 6446
 
5807 6447
             //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1));
5808 6448
             if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && !isset($values[$key]) && is_null($val['default'])) {
@@ -5811,11 +6451,17 @@  discard block
 block discarded – undo
5811 6451
             }
5812 6452
 
5813 6453
             // If field is an implicit foreign key field
5814
-            if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key] = 'null';
5815
-            if (!empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key] = 'null';
6454
+            if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) {
6455
+                $values[$key] = 'null';
6456
+            }
6457
+            if (!empty($this->fields[$key]['foreignkey']) && empty($values[$key])) {
6458
+                $values[$key] = 'null';
6459
+            }
5816 6460
         }
5817 6461
 
5818
-        if ($error) return -1;
6462
+        if ($error) {
6463
+            return -1;
6464
+        }
5819 6465
 
5820 6466
         $this->db->begin();
5821 6467
 
@@ -5838,7 +6484,9 @@  discard block
 block discarded – undo
5838 6484
         // Create extrafields
5839 6485
         if (!$error) {
5840 6486
             $result = $this->insertExtraFields();
5841
-            if ($result < 0) $error++;
6487
+            if ($result < 0) {
6488
+                $error++;
6489
+            }
5842 6490
         }
5843 6491
 
5844 6492
         // Triggers
@@ -5872,12 +6520,14 @@  discard block
 block discarded – undo
5872 6520
         global $conf;
5873 6521
 
5874 6522
         $queryarray = array();
5875
-        foreach ($this->fields as $field => $info)    // Loop on definition of fields
6523
+        foreach ($this->fields as $field => $info) {
6524
+            // Loop on definition of fields
5876 6525
         {
5877 6526
             // Depending on field type ('datetime', ...)
5878 6527
             if ($this->isDate($info)) {
5879 6528
                 if (empty($this->{$field})) {
5880 6529
                     $queryarray[$field] = null;
6530
+        }
5881 6531
                 } else {
5882 6532
                     $queryarray[$field] = $this->db->idate($this->{$field});
5883 6533
                 }
@@ -5891,20 +6541,30 @@  discard block
 block discarded – undo
5891 6541
                     $queryarray[$field] = null;
5892 6542
                 }
5893 6543
             } else if ($this->isInt($info)) {
5894
-                if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field] = $conf->entity;
5895
-                else {
6544
+                if ($field == 'entity' && is_null($this->{$field})) {
6545
+                    $queryarray[$field] = $conf->entity;
6546
+                } else {
5896 6547
                     $queryarray[$field] = (int)price2num($this->{$field});
5897
-                    if (empty($queryarray[$field])) $queryarray[$field] = 0;        // May be reset to null later if property 'notnull' is -1 for this field.
6548
+                    if (empty($queryarray[$field])) {
6549
+                        $queryarray[$field] = 0;
6550
+                    }
6551
+                    // May be reset to null later if property 'notnull' is -1 for this field.
5898 6552
                 }
5899 6553
             } else if ($this->isFloat($info)) {
5900 6554
                 $queryarray[$field] = (double)price2num($this->{$field});
5901
-                if (empty($queryarray[$field])) $queryarray[$field] = 0;
6555
+                if (empty($queryarray[$field])) {
6556
+                    $queryarray[$field] = 0;
6557
+                }
5902 6558
             } else {
5903 6559
                 $queryarray[$field] = $this->{$field};
5904 6560
             }
5905 6561
 
5906
-            if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]);
5907
-            if (!empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null;
6562
+            if ($info['type'] == 'timestamp' && empty($queryarray[$field])) {
6563
+                unset($queryarray[$field]);
6564
+            }
6565
+            if (!empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) {
6566
+                $queryarray[$field] = null;
6567
+            }
5908 6568
         }
5909 6569
 
5910 6570
         return $queryarray;
@@ -5924,11 +6584,16 @@  discard block
 block discarded – undo
5924 6584
     {
5925 6585
         global $conf, $langs, $user;
5926 6586
 
5927
-        if (empty($userused)) $userused = $user;
6587
+        if (empty($userused)) {
6588
+            $userused = $user;
6589
+        }
5928 6590
 
5929 6591
         $error = 0;
5930 6592
 
5931
-        if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0;    // For avoid conflicts if trigger used
6593
+        if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
6594
+            return 0;
6595
+        }
6596
+        // For avoid conflicts if trigger used
5932 6597
 
5933 6598
         if (!empty($this->array_options)) {
5934 6599
             // Check parameters
@@ -5940,10 +6605,13 @@  discard block
 block discarded – undo
5940 6605
             //Eliminate copied source object extra_fields that do not exist in target object
5941 6606
             $new_array_options = array();
5942 6607
             foreach ($this->array_options as $key => $value) {
5943
-                if (in_array(substr($key, 8), array_keys($target_extrafields)))    // We remove the 'options_' from $key for test
6608
+                if (in_array(substr($key, 8), array_keys($target_extrafields))) {
6609
+                    // We remove the 'options_' from $key for test
5944 6610
                     $new_array_options[$key] = $value;
5945
-                elseif (in_array($key, array_keys($target_extrafields)))        // We test on $key that does not contains the 'options_' prefix
6611
+                } elseif (in_array($key, array_keys($target_extrafields))) {
6612
+                    // We test on $key that does not contains the 'options_' prefix
5946 6613
                     $new_array_options['options_' . $key] = $value;
6614
+                }
5947 6615
             }
5948 6616
 
5949 6617
             foreach ($new_array_options as $key => $value) {
@@ -5955,8 +6623,12 @@  discard block
 block discarded – undo
5955 6623
 
5956 6624
                 if ($attributeRequired) {
5957 6625
                     $mandatorypb = false;
5958
-                    if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb = true;
5959
-                    if ($this->array_options[$key] === '') $mandatorypb = true;
6626
+                    if ($attributeType == 'link' && $this->array_options[$key] == '-1') {
6627
+                        $mandatorypb = true;
6628
+                    }
6629
+                    if ($this->array_options[$key] === '') {
6630
+                        $mandatorypb = true;
6631
+                    }
5960 6632
                     if ($mandatorypb) {
5961 6633
                         dol_syslog($this->error);
5962 6634
                         $this->errors[] = $langs->trans('ErrorFieldRequired', $attributeLabel);
@@ -6004,12 +6676,15 @@  discard block
 block discarded – undo
6004 6676
                                 //global $action;		// $action may be 'create', 'update', 'update_extras'...
6005 6677
                                 //var_dump($action);
6006 6678
                                 //var_dump($this->oldcopy);exit;
6007
-                                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
6679
+                                if (is_object($this->oldcopy)) {
6680
+                                    // If this->oldcopy is not defined, we can't know if we change attribute or not, so we must keep value
6008 6681
                                 {
6009 6682
                                     //var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]);
6010 6683
                                     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.
6011 6684
                                     {
6012
-                                        $new_array_options[$key] = $this->array_options[$key];    // Value is kept
6685
+                                        $new_array_options[$key] = $this->array_options[$key];
6686
+                                }
6687
+                                // Value is kept
6013 6688
                                     } else {
6014 6689
                                         // var_dump($algo);
6015 6690
                                         $newvalue = dol_hash($this->array_options[$key], $algo);
@@ -6044,16 +6719,22 @@  discard block
 block discarded – undo
6044 6719
                         $InfoFieldList = explode(":", $param_list[0]);
6045 6720
                         dol_include_once($InfoFieldList[1]);
6046 6721
                         if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) {
6047
-                            if ($value == '-1')    // -1 is key for no defined in combo list of objects
6722
+                            if ($value == '-1') {
6723
+                                // -1 is key for no defined in combo list of objects
6048 6724
                             {
6049 6725
                                 $new_array_options[$key] = '';
6726
+                            }
6050 6727
                             } elseif ($value) {
6051 6728
                                 $object = new $InfoFieldList[0]($this->db);
6052
-                                if (is_numeric($value)) $res = $object->fetch($value);
6053
-                                else $res = $object->fetch('', $value);
6729
+                                if (is_numeric($value)) {
6730
+                                    $res = $object->fetch($value);
6731
+                                } else {
6732
+                                    $res = $object->fetch('', $value);
6733
+                                }
6054 6734
 
6055
-                                if ($res > 0) $new_array_options[$key] = $object->id;
6056
-                                else {
6735
+                                if ($res > 0) {
6736
+                                    $new_array_options[$key] = $object->id;
6737
+                                } else {
6057 6738
                                     $this->error = "Id/Ref '" . $value . "' for object '" . $object->element . "' not found";
6058 6739
                                     $this->db->rollback();
6059 6740
                                     return -1;
@@ -6069,7 +6750,10 @@  discard block
 block discarded – undo
6069 6750
             $this->db->begin();
6070 6751
 
6071 6752
             $table_element = $this->table_element;
6072
-            if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility
6753
+            if ($table_element == 'categorie') {
6754
+                $table_element = 'categories';
6755
+            }
6756
+            // For compatibility
6073 6757
 
6074 6758
             $sql_del = "DELETE FROM " . MAIN_DB_PREFIX . $table_element . "_extrafields WHERE fk_object = " . $this->id;
6075 6759
             dol_syslog(get_class($this) . "::insertExtraFields delete", LOG_DEBUG);
@@ -6079,18 +6763,22 @@  discard block
 block discarded – undo
6079 6763
             foreach ($new_array_options as $key => $value) {
6080 6764
                 $attributeKey = substr($key, 8);   // Remove 'options_' prefix
6081 6765
                 // Add field of attribut
6082
-                if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator
6766
+                if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') {
6767
+                    // Only for other type than separator
6083 6768
                     $sql .= "," . $attributeKey;
6769
+                }
6084 6770
             }
6085 6771
             $sql .= ") VALUES (" . $this->id;
6086 6772
 
6087 6773
             foreach ($new_array_options as $key => $value) {
6088 6774
                 $attributeKey = substr($key, 8);   // Remove 'options_' prefix
6089 6775
                 // Add field of attribute
6090
-                if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator)
6776
+                if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') {
6777
+                    // Only for other type than separator)
6091 6778
                 {
6092 6779
                     if ($new_array_options[$key] != '') {
6093 6780
                         $sql .= ",'" . $this->db->escape($new_array_options[$key]) . "'";
6781
+                }
6094 6782
                     } else {
6095 6783
                         $sql .= ",null";
6096 6784
                     }
@@ -6109,7 +6797,9 @@  discard block
 block discarded – undo
6109 6797
                 // Call trigger
6110 6798
                 $this->context = array('extrafieldaddupdate' => 1);
6111 6799
                 $result = $this->call_trigger($trigger, $userused);
6112
-                if ($result < 0) $error++;
6800
+                if ($result < 0) {
6801
+                    $error++;
6802
+                }
6113 6803
                 // End call trigger
6114 6804
             }
6115 6805
 
@@ -6120,7 +6810,9 @@  discard block
 block discarded – undo
6120 6810
                 $this->db->commit();
6121 6811
                 return 1;
6122 6812
             }
6123
-        } else return 0;
6813
+        } else {
6814
+            return 0;
6815
+        }
6124 6816
     }
6125 6817
 
6126 6818
     /**
@@ -6139,8 +6831,12 @@  discard block
 block discarded – undo
6139 6831
         $now = dol_now();
6140 6832
 
6141 6833
         $fieldvalues = $this->setSaveQuery();
6142
-        if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification'] = $this->db->idate($now);
6143
-        if (array_key_exists('fk_user_modif', $fieldvalues) && !($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif'] = $user->id;
6834
+        if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) {
6835
+            $fieldvalues['date_modification'] = $this->db->idate($now);
6836
+        }
6837
+        if (array_key_exists('fk_user_modif', $fieldvalues) && !($fieldvalues['fk_user_modif'] > 0)) {
6838
+            $fieldvalues['fk_user_modif'] = $user->id;
6839
+        }
6144 6840
         unset($fieldvalues['rowid']);    // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update.
6145 6841
 
6146 6842
         $keys = array();
@@ -6154,8 +6850,14 @@  discard block
 block discarded – undo
6154 6850
 
6155 6851
         // Clean and check mandatory
6156 6852
         foreach ($keys as $key) {
6157
-            if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key] = '';        // This is an implicit foreign key field
6158
-            if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key] = '';                    // This is an explicit foreign key field
6853
+            if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') {
6854
+                $values[$key] = '';
6855
+            }
6856
+            // This is an implicit foreign key field
6857
+            if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') {
6858
+                $values[$key] = '';
6859
+            }
6860
+            // This is an explicit foreign key field
6159 6861
 
6160 6862
             //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1));
6161 6863
             /*
@@ -6230,9 +6932,11 @@  discard block
 block discarded – undo
6230 6932
                     return -1;
6231 6933
                 }
6232 6934
             }
6233
-        } elseif (!empty($this->fk_element) && !empty($this->childtables))    // If object has childs linked with a foreign key field, we check all child tables.
6935
+        } elseif (!empty($this->fk_element) && !empty($this->childtables)) {
6936
+            // If object has childs linked with a foreign key field, we check all child tables.
6234 6937
         {
6235 6938
             $objectisused = $this->isObjectUsed($this->id);
6939
+        }
6236 6940
             if (!empty($objectisused)) {
6237 6941
                 dol_syslog(get_class($this) . "::deleteCommon Can't delete record as it has some child", LOG_WARNING);
6238 6942
                 $this->error = 'ErrorRecordHasChildren';
@@ -6295,7 +6999,9 @@  discard block
 block discarded – undo
6295 6999
     {
6296 7000
         global $langs;
6297 7001
 
6298
-        if (empty($id)) $id = $this->id;
7002
+        if (empty($id)) {
7003
+            $id = $this->id;
7004
+        }
6299 7005
 
6300 7006
         // Check parameters
6301 7007
         if (!isset($this->childtables) || !is_array($this->childtables) || count($this->childtables) == 0) {
@@ -6324,9 +7030,11 @@  discard block
 block discarded – undo
6324 7030
                     $langs->load("errors");
6325 7031
                     //print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild;
6326 7032
                     $haschild += $obj->nb;
6327
-                    if (is_numeric($elementname))    // old usage
7033
+                    if (is_numeric($elementname)) {
7034
+                        // old usage
6328 7035
                     {
6329 7036
                         $this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table);
7037
+                    }
6330 7038
                     } else    // new usage: $elementname=Translation key
6331 7039
                     {
6332 7040
                         $this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname));
@@ -6341,7 +7049,9 @@  discard block
 block discarded – undo
6341 7049
         if ($haschild > 0) {
6342 7050
             $this->errors[] = "ErrorRecordHasChildren";
6343 7051
             return $haschild;
6344
-        } else return 0;
7052
+        } else {
7053
+            return 0;
7054
+        }
6345 7055
     }
6346 7056
 
6347 7057
     /**
@@ -6397,7 +7107,9 @@  discard block
 block discarded – undo
6397 7107
      */
6398 7108
     public function trimParameters($parameters)
6399 7109
     {
6400
-        if (!is_array($parameters)) return;
7110
+        if (!is_array($parameters)) {
7111
+            return;
7112
+        }
6401 7113
         foreach ($parameters as $parameter) {
6402 7114
             if (isset($this->$parameter)) {
6403 7115
                 $this->$parameter = trim($this->$parameter);
@@ -6442,11 +7154,18 @@  discard block
 block discarded – undo
6442 7154
         $classname = '';
6443 7155
         $filefound = 0;
6444 7156
         $dirmodels = array('/');
6445
-        if (is_array($conf->modules_parts['models'])) $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
7157
+        if (is_array($conf->modules_parts['models'])) {
7158
+            $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']);
7159
+        }
6446 7160
         foreach ($dirmodels as $reldir) {
6447 7161
             foreach (array('doc', 'pdf') as $prefix) {
6448
-                if (in_array(get_class($this), array('Adherent'))) $file = $prefix . "_" . $modele . ".class.php";     // Member module use prefix_module.class.php
6449
-                else $file = $prefix . "_" . $modele . ".modules.php";
7162
+                if (in_array(get_class($this), array('Adherent'))) {
7163
+                    $file = $prefix . "_" . $modele . ".class.php";
7164
+                }
7165
+                // Member module use prefix_module.class.php
7166
+                else {
7167
+                    $file = $prefix . "_" . $modele . ".modules.php";
7168
+                }
6450 7169
 
6451 7170
                 // On verifie l'emplacement du modele
6452 7171
                 $file = dol_buildpath($reldir . $modelspath . $file, 0);
@@ -6456,7 +7175,9 @@  discard block
 block discarded – undo
6456 7175
                     break;
6457 7176
                 }
6458 7177
             }
6459
-            if ($filefound) break;
7178
+            if ($filefound) {
7179
+                break;
7180
+            }
6460 7181
         }
6461 7182
 
6462 7183
         // If generator was found
@@ -6486,7 +7207,9 @@  discard block
 block discarded – undo
6486 7207
                         }
6487 7208
                         if (is_dir($tmpdir)) {
6488 7209
                             $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.od(s|t)$', '', 'name', SORT_ASC, 0);
6489
-                            if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles);
7210
+                            if (count($tmpfiles)) {
7211
+                                $listoffiles = array_merge($listoffiles, $tmpfiles);
7212
+                            }
6490 7213
                         }
6491 7214
                     }
6492 7215
 
@@ -6537,9 +7260,11 @@  discard block
 block discarded – undo
6537 7260
                     $destfile = basename($destfull);
6538 7261
                     $rel_dir = preg_replace('/^' . preg_quote(DOL_DATA_ROOT, '/') . '/', '', $upload_dir);
6539 7262
 
6540
-                    if (!preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir))     // If not a tmp dir
7263
+                    if (!preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
7264
+                        // If not a tmp dir
6541 7265
                     {
6542 7266
                         $filename = basename($destfile);
7267
+                    }
6543 7268
                         $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
6544 7269
                         $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
6545 7270
 
@@ -6551,17 +7276,29 @@  discard block
 block discarded – undo
6551 7276
                         $setsharekey = false;
6552 7277
                         if ($this->element == 'propal') {
6553 7278
                             $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL;    // Replace this with 1 when feature to make online signature is ok
6554
-                            if ($useonlinesignature) $setsharekey = true;
6555
-                            if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true;
7279
+                            if ($useonlinesignature) {
7280
+                                $setsharekey = true;
7281
+                            }
7282
+                            if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) {
7283
+                                $setsharekey = true;
7284
+                            }
7285
+                        }
7286
+                        if ($this->element == 'commande' && !empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) {
7287
+                            $setsharekey = true;
7288
+                        }
7289
+                        if ($this->element == 'facture' && !empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) {
7290
+                            $setsharekey = true;
7291
+                        }
7292
+                        if ($this->element == 'bank_account' && !empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) {
7293
+                            $setsharekey = true;
6556 7294
                         }
6557
-                        if ($this->element == 'commande' && !empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true;
6558
-                        if ($this->element == 'facture' && !empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true;
6559
-                        if ($this->element == 'bank_account' && !empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true;
6560 7295
 
6561 7296
                         if ($setsharekey) {
6562
-                            if (empty($ecmfile->share))    // Because object not found or share not set yet
7297
+                            if (empty($ecmfile->share)) {
7298
+                                // Because object not found or share not set yet
6563 7299
                             {
6564 7300
                                 require_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php';
7301
+                            }
6565 7302
                                 $ecmfile->share = getRandomPassword(true);
6566 7303
                             }
6567 7304
                         }
@@ -6601,12 +7338,16 @@  discard block
 block discarded – undo
6601 7338
 
6602 7339
                         // Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set)
6603 7340
                         $update_main_doc_field = 0;
6604
-                        if (!empty($obj->update_main_doc_field)) $update_main_doc_field = 1;
7341
+                        if (!empty($obj->update_main_doc_field)) {
7342
+                            $update_main_doc_field = 1;
7343
+                        }
6605 7344
                         if ($update_main_doc_field && !empty($this->table_element)) {
6606 7345
                             $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . " SET last_main_doc = '" . ($ecmfile->filepath . '/' . $ecmfile->filename) . "'";
6607 7346
                             $sql .= ' WHERE rowid = ' . $this->id;
6608 7347
                             $resql = $this->db->query($sql);
6609
-                            if (!$resql) dol_print_error($this->db);
7348
+                            if (!$resql) {
7349
+                                dol_print_error($this->db);
7350
+                            }
6610 7351
                         }
6611 7352
                     }
6612 7353
                 } else {
@@ -6638,8 +7379,13 @@  discard block
 block discarded – undo
6638 7379
     protected function isIndex($info)
6639 7380
     {
6640 7381
         if (is_array($info)) {
6641
-            if (isset($info['index']) && $info['index'] == true) return true;
6642
-            else return false;
6643
-        } else return false;
7382
+            if (isset($info['index']) && $info['index'] == true) {
7383
+                return true;
7384
+            } else {
7385
+                return false;
7386
+            }
7387
+        } else {
7388
+            return false;
7389
+        }
6644 7390
     }
6645 7391
 }
6646 7392
\ No newline at end of file
Please login to merge, or discard this patch.
Base/Translate.php 1 patch
Braces   +171 added lines, -108 removed lines patch added patch discarded remove patch
@@ -30,12 +30,15 @@  discard block
 block discarded – undo
30 30
     {
31 31
         Debug::addMessage('Deprecated', 'Unnecessary definition of first parameter ($dir) in Translate');
32 32
         $dir = DOL_BASE_PATH;
33
-        if (!empty($conf->file->character_set_client))
34
-            $this->charset_output = $conf->file->character_set_client; // If charset output is forced
35
-        if ($dir)
36
-            $this->dir = array($dir);
37
-        else
38
-            $this->dir = $conf->file->dol_document_root;
33
+        if (!empty($conf->file->character_set_client)) {
34
+                    $this->charset_output = $conf->file->character_set_client;
35
+        }
36
+        // If charset output is forced
37
+        if ($dir) {
38
+                    $this->dir = array($dir);
39
+        } else {
40
+                    $this->dir = $conf->file->dol_document_root;
41
+        }
39 42
     }
40 43
 
41 44
     /**
@@ -47,10 +50,11 @@  discard block
 block discarded – undo
47 50
      */
48 51
     function getDefaultLang($mode = 0)
49 52
     {
50
-        if (empty($mode))
51
-            return $this->defaultlang;
52
-        else
53
-            return substr($this->defaultlang, 0, 2);
53
+        if (empty($mode)) {
54
+                    return $this->defaultlang;
55
+        } else {
56
+                    return substr($this->defaultlang, 0, 2);
57
+        }
54 58
     }
55 59
 
56 60
     /**
@@ -86,8 +90,9 @@  discard block
 block discarded – undo
86 90
             $langpref = str_replace("-", "_", $langpref);
87 91
             $langlist = preg_split("/[;,]/", $langpref);
88 92
             $codetouse = $langlist[0];
89
-        } else
90
-            $codetouse = $srclang;
93
+        } else {
94
+                    $codetouse = $srclang;
95
+        }
91 96
 
92 97
         // We redefine $srclang
93 98
         $langpart = explode("_", $codetouse);
@@ -96,24 +101,27 @@  discard block
 block discarded – undo
96 101
             // Array force long code from first part, even if long code is defined
97 102
             $longforshort = array('ar' => 'ar_SA');
98 103
             $longforshortexcep = array('ar_EG');
99
-            if (isset($longforshort[strtolower($langpart[0])]) && !in_array($codetouse, $longforshortexcep))
100
-                $srclang = $longforshort[strtolower($langpart[0])];
101
-            else if (!is_numeric($langpart[1])) {  // Second part YY may be a numeric with some Chrome browser
104
+            if (isset($longforshort[strtolower($langpart[0])]) && !in_array($codetouse, $longforshortexcep)) {
105
+                            $srclang = $longforshort[strtolower($langpart[0])];
106
+            } else if (!is_numeric($langpart[1])) {  // Second part YY may be a numeric with some Chrome browser
102 107
                 $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[1]);
103 108
                 $longforlong = array('no_nb' => 'nb_NO');
104
-                if (isset($longforlong[strtolower($srclang)]))
105
-                    $srclang = $longforlong[strtolower($srclang)];
106
-            } else
107
-                $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[0]);
109
+                if (isset($longforlong[strtolower($srclang)])) {
110
+                                    $srclang = $longforlong[strtolower($srclang)];
111
+                }
112
+            } else {
113
+                            $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[0]);
114
+            }
108 115
         } else {      // If it's for a codetouse that is a short code xx
109 116
             // Array to convert short lang code into long code.
110 117
             $longforshort = array('ar' => 'ar_SA', 'el' => 'el_GR', 'ca' => 'ca_ES', 'en' => 'en_US', 'nb' => 'nb_NO', 'no' => 'nb_NO');
111
-            if (isset($longforshort[strtolower($langpart[0])]))
112
-                $srclang = $longforshort[strtolower($langpart[0])];
113
-            else if (!empty($langpart[0]))
114
-                $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[0]);
115
-            else
116
-                $srclang = 'en_US';
118
+            if (isset($longforshort[strtolower($langpart[0])])) {
119
+                            $srclang = $longforshort[strtolower($langpart[0])];
120
+            } else if (!empty($langpart[0])) {
121
+                            $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[0]);
122
+            } else {
123
+                            $srclang = 'en_US';
124
+            }
117 125
         }
118 126
 
119 127
         $this->defaultlang = $srclang;
@@ -163,13 +171,17 @@  discard block
 block discarded – undo
163 171
             dol_print_error('', get_class($this) . "::Load ErrorWrongParameters");
164 172
             return -1;
165 173
         }
166
-        if ($this->defaultlang == 'none_NONE')
167
-            return 0;    // Special language code to not translate keys
174
+        if ($this->defaultlang == 'none_NONE') {
175
+                    return 0;
176
+        }
177
+        // Special language code to not translate keys
168 178
 
169 179
 
170 180
 // Load $this->tab_translate[] from database
171
-        if (empty($loadfromfileonly) && count($this->tab_translate) == 0)
172
-            $this->loadFromDatabase($db);      // No translation was never loaded yet, so we load database.
181
+        if (empty($loadfromfileonly) && count($this->tab_translate) == 0) {
182
+                    $this->loadFromDatabase($db);
183
+        }
184
+        // No translation was never loaded yet, so we load database.
173 185
 
174 186
 
175 187
         $newdomain = $domain;
@@ -192,10 +204,12 @@  discard block
 block discarded – undo
192 204
 
193 205
         // Redefine alt
194 206
         $langarray = explode('_', $langofdir);
195
-        if ($alt < 1 && isset($langarray[1]) && (strtolower($langarray[0]) == strtolower($langarray[1]) || in_array(strtolower($langofdir), array('el_gr'))))
196
-            $alt = 1;
197
-        if ($alt < 2 && strtolower($langofdir) == 'en_us')
198
-            $alt = 2;
207
+        if ($alt < 1 && isset($langarray[1]) && (strtolower($langarray[0]) == strtolower($langarray[1]) || in_array(strtolower($langofdir), array('el_gr')))) {
208
+                    $alt = 1;
209
+        }
210
+        if ($alt < 2 && strtolower($langofdir) == 'en_us') {
211
+                    $alt = 2;
212
+        }
199 213
 
200 214
         if (empty($langofdir)) { // This may occurs when load is called without setting the language and without providing a value for forcelangdir
201 215
             dol_syslog("Error: " . get_class($this) . "::Load was called but language was not set yet with langs->setDefaultLang(). Nothing will be loaded.", LOG_WARNING);
@@ -236,16 +250,19 @@  discard block
 block discarded – undo
236 250
                         $this->tab_translate += $tmparray; // Faster than array_merge($tmparray,$this->tab_translate). Note: If a value already exists into tab_translate, value into tmparaay is not added.
237 251
                         //print $newdomain."\n";
238 252
                         //var_dump($this->tab_translate);
239
-                        if ($alt == 2)
240
-                            $fileread = 1;
253
+                        if ($alt == 2) {
254
+                                                    $fileread = 1;
255
+                        }
241 256
                         $found = true;      // Found in dolibarr PHP cache
242 257
                     }
243 258
                 }
244 259
 
245 260
                 if (!$found) {
246 261
                     if ($fp = @fopen($file_lang, "rt")) {
247
-                        if ($usecachekey)
248
-                            $tabtranslatedomain = array(); // To save lang content in cache
262
+                        if ($usecachekey) {
263
+                                                    $tabtranslatedomain = array();
264
+                        }
265
+                        // To save lang content in cache
249 266
 
250 267
                         /**
251 268
                          * Read each lines until a '=' (with any combination of spaces around it)
@@ -293,8 +310,10 @@  discard block
 block discarded – undo
293 310
                             }
294 311
                         }
295 312
 
296
-                        if (empty($conf->global->MAIN_FORCELANGDIR))
297
-                            break;  // Break loop on each root dir. If a module has forced dir, we do not stop loop.
313
+                        if (empty($conf->global->MAIN_FORCELANGDIR)) {
314
+                                                    break;
315
+                        }
316
+                        // Break loop on each root dir. If a module has forced dir, we do not stop loop.
298 317
                     }
299 318
                 }
300 319
             }
@@ -305,10 +324,14 @@  discard block
 block discarded – undo
305 324
             // This function MUST NOT contains call to syslog
306 325
             //dol_syslog("Translate::Load loading alternate translation file (to complete ".$this->defaultlang."/".$newdomain.".lang file)", LOG_DEBUG);
307 326
             $langofdir = strtolower($langarray[0]) . '_' . strtoupper($langarray[0]);
308
-            if ($langofdir == 'el_EL')
309
-                $langofdir = 'el_GR';                     // main parent for el_CY is not 'el_EL' but 'el_GR'
310
-            if ($langofdir == 'ar_AR')
311
-                $langofdir = 'ar_SA';                     // main parent for ar_EG is not 'ar_AR' but 'ar_SA'
327
+            if ($langofdir == 'el_EL') {
328
+                            $langofdir = 'el_GR';
329
+            }
330
+            // main parent for el_CY is not 'el_EL' but 'el_GR'
331
+            if ($langofdir == 'ar_AR') {
332
+                            $langofdir = 'ar_SA';
333
+            }
334
+            // main parent for ar_EG is not 'ar_AR' but 'ar_SA'
312 335
             $this->load($domain, $alt + 1, $stopafterdirection, $langofdir);
313 336
         }
314 337
 
@@ -322,11 +345,15 @@  discard block
 block discarded – undo
322 345
 
323 346
         // We are in the pass of the reference file. No more files to scan to complete.
324 347
         if ($alt == 2) {
325
-            if ($fileread)
326
-                $this->_tab_loaded[$newdomain] = 1;        // Set domain file as found so loaded
348
+            if ($fileread) {
349
+                            $this->_tab_loaded[$newdomain] = 1;
350
+            }
351
+            // Set domain file as found so loaded
327 352
 
328
-            if (empty($this->_tab_loaded[$newdomain]))
329
-                $this->_tab_loaded[$newdomain] = 2; // Set this file as not found
353
+            if (empty($this->_tab_loaded[$newdomain])) {
354
+                            $this->_tab_loaded[$newdomain] = 2;
355
+            }
356
+            // Set this file as not found
330 357
         }
331 358
 
332 359
         // This part is deprecated and replaced with table llx_overwrite_trans
@@ -338,15 +365,17 @@  discard block
 block discarded – undo
338 365
                 $tmparray = explode(',', $conf->global->$overwritekey);
339 366
                 foreach ($tmparray as $tmp) {
340 367
                     $tmparray2 = explode(':', $tmp);
341
-                    if (!empty($tmparray2[1]))
342
-                        $this->tab_translate[$tmparray2[0]] = $tmparray2[1];
368
+                    if (!empty($tmparray2[1])) {
369
+                                            $this->tab_translate[$tmparray2[0]] = $tmparray2[1];
370
+                    }
343 371
                 }
344 372
             }
345 373
         }
346 374
 
347 375
         // Check to be sure that SeparatorDecimal differs from SeparatorThousand
348
-        if (!empty($this->tab_translate["SeparatorDecimal"]) && !empty($this->tab_translate["SeparatorThousand"]) && $this->tab_translate["SeparatorDecimal"] == $this->tab_translate["SeparatorThousand"])
349
-            $this->tab_translate["SeparatorThousand"] = '';
376
+        if (!empty($this->tab_translate["SeparatorDecimal"]) && !empty($this->tab_translate["SeparatorThousand"]) && $this->tab_translate["SeparatorDecimal"] == $this->tab_translate["SeparatorThousand"]) {
377
+                    $this->tab_translate["SeparatorThousand"] = '';
378
+        }
350 379
 
351 380
         return 1;
352 381
     }
@@ -370,8 +399,10 @@  discard block
 block discarded – undo
370 399
         $domain = 'database';
371 400
 
372 401
         // Check parameters
373
-        if (empty($db))
374
-            return 0;    // Database handler can't be used
402
+        if (empty($db)) {
403
+                    return 0;
404
+        }
405
+        // Database handler can't be used
375 406
 
376 407
 
377 408
 //dol_syslog("Translate::Load Start domain=".$domain." alt=".$alt." forcelangdir=".$forcelangdir." this->defaultlang=".$this->defaultlang);
@@ -430,8 +461,10 @@  discard block
 block discarded – undo
430 461
             if ($resql) {
431 462
                 $num = $db->num_rows($resql);
432 463
                 if ($num) {
433
-                    if ($usecachekey)
434
-                        $tabtranslatedomain = array(); // To save lang content in cache
464
+                    if ($usecachekey) {
465
+                                            $tabtranslatedomain = array();
466
+                    }
467
+                    // To save lang content in cache
435 468
 
436 469
                     $i = 0;
437 470
                     while ($i < $num) { // Ex: Need 225ms for all fgets on all lang file for Third party page. Same speed than file_get_contents
@@ -445,8 +478,10 @@  discard block
 block discarded – undo
445 478
                             $value = trim(preg_replace('/\\n/', "\n", $value));
446 479
 
447 480
                             $this->tab_translate[$key] = $value;
448
-                            if ($usecachekey)
449
-                                $tabtranslatedomain[$key] = $value; // To save lang content in cache
481
+                            if ($usecachekey) {
482
+                                                            $tabtranslatedomain[$key] = $value;
483
+                            }
484
+                            // To save lang content in cache
450 485
                         }
451 486
 
452 487
                         $i++;
@@ -469,11 +504,15 @@  discard block
 block discarded – undo
469 504
             }
470 505
         }
471 506
 
472
-        if ($fileread)
473
-            $this->_tab_loaded[$newdomain] = 1; // Set domain file as loaded
507
+        if ($fileread) {
508
+                    $this->_tab_loaded[$newdomain] = 1;
509
+        }
510
+        // Set domain file as loaded
474 511
 
475
-        if (empty($this->_tab_loaded[$newdomain]))
476
-            $this->_tab_loaded[$newdomain] = 2;           // Marque ce cas comme non trouve (no lines found for language)
512
+        if (empty($this->_tab_loaded[$newdomain])) {
513
+                    $this->_tab_loaded[$newdomain] = 2;
514
+        }
515
+        // Marque ce cas comme non trouve (no lines found for language)
477 516
 
478 517
         return 1;
479 518
     }
@@ -487,10 +526,11 @@  discard block
 block discarded – undo
487 526
      */
488 527
     function transcountry($str, $countrycode)
489 528
     {
490
-        if ($this->tab_translate["$str$countrycode"])
491
-            return $this->trans("$str$countrycode");
492
-        else
493
-            return $this->trans($str);
529
+        if ($this->tab_translate["$str$countrycode"]) {
530
+                    return $this->trans("$str$countrycode");
531
+        } else {
532
+                    return $this->trans($str);
533
+        }
494 534
     }
495 535
 
496 536
     /**
@@ -529,8 +569,9 @@  discard block
 block discarded – undo
529 569
                 $str = sprintf($str, $param1, $param2, $param3, $param4); // Replace %s and %d except for FormatXXX strings.
530 570
             }
531 571
 
532
-            if ($maxsize)
533
-                $str = dol_trunc($str, $maxsize);
572
+            if ($maxsize) {
573
+                            $str = dol_trunc($str, $maxsize);
574
+            }
534 575
 
535 576
             // We replace some HTML tags by __xx__ to avoid having them encoded by htmlentities
536 577
             $str = str_replace(array('<', '>', '"',), array('__lt__', '__gt__', '__quot__'), $str);
@@ -562,8 +603,10 @@  discard block
 block discarded – undo
562 603
     {
563 604
         global $conf, $db;
564 605
 
565
-        if (!is_string($key))
566
-            return 'ErrorBadValueForParamNotAString'; // Avoid multiple errors with code not using function correctly.
606
+        if (!is_string($key)) {
607
+                    return 'ErrorBadValueForParamNotAString';
608
+        }
609
+        // Avoid multiple errors with code not using function correctly.
567 610
 
568 611
         $newstr = $key;
569 612
         if (preg_match('/^Civility([0-9A-Z]+)$/i', $key, $reg)) {
@@ -608,8 +651,9 @@  discard block
 block discarded – undo
608 651
     function getLabelFromKey($db, $key, $tablename, $fieldkey, $fieldlabel, $keyforselect = '', $filteronentity = 0)
609 652
     {
610 653
         // If key empty
611
-        if ($key == '')
612
-            return '';
654
+        if ($key == '') {
655
+                    return '';
656
+        }
613 657
 
614 658
         //print 'param: '.$key.'-'.$keydatabase.'-'.$this->trans($key); exit;
615 659
         // Check if a translation is available (this can call getTradFromKey)
@@ -626,16 +670,18 @@  discard block
 block discarded – undo
626 670
         $sql = "SELECT " . $fieldlabel . " as label";
627 671
         $sql .= " FROM " . MAIN_DB_PREFIX . $tablename;
628 672
         $sql .= " WHERE " . $fieldkey . " = '" . $db->escape($keyforselect ? $keyforselect : $key) . "'";
629
-        if ($filteronentity)
630
-            $sql .= " AND entity IN (" . getEntity($tablename) . ')';
673
+        if ($filteronentity) {
674
+                    $sql .= " AND entity IN (" . getEntity($tablename) . ')';
675
+        }
631 676
         dol_syslog(get_class($this) . '::getLabelFromKey', LOG_DEBUG);
632 677
         $resql = $db->query($sql);
633 678
         if ($resql) {
634 679
             $obj = $db->fetch_object($resql);
635
-            if ($obj)
636
-                $this->cache_labels[$tablename][$key] = $obj->label;
637
-            else
638
-                $this->cache_labels[$tablename][$key] = $key;
680
+            if ($obj) {
681
+                            $this->cache_labels[$tablename][$key] = $obj->label;
682
+            } else {
683
+                            $this->cache_labels[$tablename][$key] = $key;
684
+            }
639 685
 
640 686
             $db->free($resql);
641 687
             return $this->cache_labels[$tablename][$key];
@@ -700,10 +746,11 @@  discard block
 block discarded – undo
700 746
      */
701 747
     function transcountrynoentities($str, $countrycode)
702 748
     {
703
-        if ($this->tab_translate["$str$countrycode"])
704
-            return $this->transnoentities("$str$countrycode");
705
-        else
706
-            return $this->transnoentities($str);
749
+        if ($this->tab_translate["$str$countrycode"]) {
750
+                    return $this->transnoentities("$str$countrycode");
751
+        } else {
752
+                    return $this->transnoentities($str);
753
+        }
707 754
     }
708 755
 
709 756
     /**
@@ -736,10 +783,12 @@  discard block
 block discarded – undo
736 783
      */
737 784
     function convToOutputCharset($str, $pagecodefrom = 'UTF-8')
738 785
     {
739
-        if ($pagecodefrom == 'ISO-8859-1' && $this->charset_output == 'UTF-8')
740
-            $str = utf8_encode($str);
741
-        if ($pagecodefrom == 'UTF-8' && $this->charset_output == 'ISO-8859-1')
742
-            $str = utf8_decode(str_replace('€', chr(128), $str));
786
+        if ($pagecodefrom == 'ISO-8859-1' && $this->charset_output == 'UTF-8') {
787
+                    $str = utf8_encode($str);
788
+        }
789
+        if ($pagecodefrom == 'UTF-8' && $this->charset_output == 'ISO-8859-1') {
790
+                    $str = utf8_decode(str_replace('€', chr(128), $str));
791
+        }
743 792
         return $str;
744 793
     }
745 794
 
@@ -794,16 +843,19 @@  discard block
 block discarded – undo
794 843
         // phpcs:enable
795 844
         // Test si fichier dans repertoire de la langue
796 845
         foreach ($this->dir as $searchdir) {
797
-            if (is_readable(dol_osencode($searchdir . "/langs/" . $this->defaultlang . "/" . $filename)))
798
-                return true;
846
+            if (is_readable(dol_osencode($searchdir . "/langs/" . $this->defaultlang . "/" . $filename))) {
847
+                            return true;
848
+            }
799 849
 
800 850
             if ($searchalt) {
801 851
                 // Test si fichier dans repertoire de la langue alternative
802
-                if ($this->defaultlang != "en_US")
803
-                    $filenamealt = $searchdir . "/langs/en_US/" . $filename;
852
+                if ($this->defaultlang != "en_US") {
853
+                                    $filenamealt = $searchdir . "/langs/en_US/" . $filename;
854
+                }
804 855
                 //else $filenamealt = $searchdir."/langs/fr_FR/".$filename;
805
-                if (is_readable(dol_osencode($filenamealt)))
806
-                    return true;
856
+                if (is_readable(dol_osencode($filenamealt))) {
857
+                                    return true;
858
+                }
807 859
             }
808 860
         }
809 861
 
@@ -833,8 +885,10 @@  discard block
 block discarded – undo
833 885
             $newdir = dol_osencode($dir);
834 886
 
835 887
             // Check if directory exists
836
-            if (!is_dir($newdir))
837
-                continue; // We must not use dol_is_dir here, function may not be loaded
888
+            if (!is_dir($newdir)) {
889
+                            continue;
890
+            }
891
+            // We must not use dol_is_dir here, function may not be loaded
838 892
 
839 893
             $fonc = 'numberwords';
840 894
             if (file_exists($newdir . '/functions_' . $fonc . '.lib.php')) {
@@ -860,10 +914,11 @@  discard block
 block discarded – undo
860 914
     {
861 915
         $symbol = $this->getCurrencySymbol($currency_code);
862 916
 
863
-        if (in_array($currency_code, array('USD')))
864
-            return $symbol . $amount;
865
-        else
866
-            return $amount . $symbol;
917
+        if (in_array($currency_code, array('USD'))) {
918
+                    return $symbol . $amount;
919
+        } else {
920
+                    return $amount . $symbol;
921
+        }
867 922
     }
868 923
 
869 924
     /**
@@ -901,16 +956,21 @@  discard block
 block discarded – undo
901 956
     {
902 957
         global $db;
903 958
 
904
-        if ($this->cache_currencies_all_loaded)
905
-            return 0;                                           // Cache already loaded for all
906
-        if (!empty($currency_code) && isset($this->cache_currencies[$currency_code]))
907
-            return 0;    // Cache already loaded for the currency
959
+        if ($this->cache_currencies_all_loaded) {
960
+                    return 0;
961
+        }
962
+        // Cache already loaded for all
963
+        if (!empty($currency_code) && isset($this->cache_currencies[$currency_code])) {
964
+                    return 0;
965
+        }
966
+        // Cache already loaded for the currency
908 967
 
909 968
         $sql = "SELECT code_iso, label, unicode";
910 969
         $sql .= " FROM " . MAIN_DB_PREFIX . "c_currencies";
911 970
         $sql .= " WHERE active = 1";
912
-        if (!empty($currency_code))
913
-            $sql .= " AND code_iso = '" . $db->escape($currency_code) . "'";
971
+        if (!empty($currency_code)) {
972
+                    $sql .= " AND code_iso = '" . $db->escape($currency_code) . "'";
973
+        }
914 974
         //$sql.= " ORDER BY code_iso ASC"; // Not required, a sort is done later
915 975
 
916 976
         dol_syslog(get_class($this) . '::loadCacheCurrencies', LOG_DEBUG);
@@ -918,9 +978,11 @@  discard block
 block discarded – undo
918 978
         if ($resql) {
919 979
             $this->load("dict");
920 980
             $label = array();
921
-            if (!empty($currency_code))
922
-                foreach ($this->cache_currencies as $key => $val)
923
-                    $label[$key] = $val['label']; // Label in already loaded cache
981
+            if (!empty($currency_code)) {
982
+                            foreach ($this->cache_currencies as $key => $val)
983
+                    $label[$key] = $val['label'];
984
+            }
985
+            // Label in already loaded cache
924 986
 
925 987
             $num = $db->num_rows($resql);
926 988
             $i = 0;
@@ -933,8 +995,9 @@  discard block
 block discarded – undo
933 995
                 $label[$obj->code_iso] = $this->cache_currencies[$obj->code_iso]['label'];
934 996
                 $i++;
935 997
             }
936
-            if (empty($currency_code))
937
-                $this->cache_currencies_all_loaded = true;
998
+            if (empty($currency_code)) {
999
+                            $this->cache_currencies_all_loaded = true;
1000
+            }
938 1001
             //print count($label).' '.count($this->cache_currencies);
939 1002
             // Resort cache
940 1003
             array_multisort($label, SORT_ASC, $this->cache_currencies);
Please login to merge, or discard this patch.
dolibarr/htdocs/main.inc.php 1 patch
Braces   +341 added lines, -224 removed lines patch added patch discarded remove patch
@@ -217,16 +217,18 @@  discard block
 block discarded – undo
217 217
     foreach ($tmplist as $tmpkey) {
218 218
         $postkey = $tmpautoset[0] . '_' . $tmpkey;
219 219
         //var_dump('tmpkey='.$tmpkey.' postkey='.$postkey.' value='.$_POST[$postkey]);
220
-        if (!empty($_POST[$postkey]))
221
-            $cookiearrayvalue[$tmpkey] = $_POST[$postkey];
220
+        if (!empty($_POST[$postkey])) {
221
+                    $cookiearrayvalue[$tmpkey] = $_POST[$postkey];
222
+        }
222 223
     }
223 224
     $cookiename = $tmpautoset[0];
224 225
     $cookievalue = json_encode($cookiearrayvalue);
225 226
     //var_dump('setcookie cookiename='.$cookiename.' cookievalue='.$cookievalue);
226 227
     setcookie($cookiename, empty($cookievalue) ? '' : $cookievalue, empty($cookievalue) ? 0 : (time() + (86400 * 354)), '/', null, false, true); // keep cookie 1 year and add tag httponly
227
-    if (empty($cookievalue))
228
-        unset($_COOKIE[$cookiename]);
229
-}
228
+    if (empty($cookievalue)) {
229
+            unset($_COOKIE[$cookiename]);
230
+    }
231
+    }
230 232
 
231 233
 
232 234
 // Init session. Name of session is specific to Dolibarr instance.
@@ -235,8 +237,9 @@  discard block
 block discarded – undo
235 237
 
236 238
 $sessionname = 'DOLSESSID_' . $prefix;
237 239
 $sessiontimeout = 'DOLSESSTIMEOUT_' . $prefix;
238
-if (!empty($_COOKIE[$sessiontimeout]))
240
+if (!empty($_COOKIE[$sessiontimeout])) {
239 241
     ini_set('session.gc_maxlifetime', $_COOKIE[$sessiontimeout]);
242
+}
240 243
 session_name($sessionname);
241 244
 session_set_cookie_params(0, '/', null, false, true);   // Add tag httponly on session cookie (same as setting session.cookie_httponly into php.ini). Must be called before the session_start.
242 245
 // This create lock, released when session_write_close() or end of page.
@@ -267,11 +270,13 @@  discard block
 block discarded – undo
267 270
     $conf->browser->layout = $tmp['layout'];     // 'classic', 'phone', 'tablet'
268 271
     //var_dump($conf->browser);
269 272
 
270
-    if ($conf->browser->layout == 'phone')
271
-        $conf->dol_no_mouse_hover = 1;
272
-    if ($conf->browser->layout == 'phone')
273
-        $conf->global->MAIN_TESTMENUHIDER = 1;
274
-}
273
+    if ($conf->browser->layout == 'phone') {
274
+            $conf->dol_no_mouse_hover = 1;
275
+    }
276
+    if ($conf->browser->layout == 'phone') {
277
+            $conf->global->MAIN_TESTMENUHIDER = 1;
278
+    }
279
+    }
275 280
 
276 281
 // Force HTTPS if required ($conf->file->main_force_https is 0/1 or https dolibarr root url)
277 282
 // $_SERVER["HTTPS"] is 'on' when link is https, otherwise $_SERVER["HTTPS"] is empty or 'off'
@@ -316,10 +321,14 @@  discard block
 block discarded – undo
316 321
 }
317 322
 
318 323
 // Loading of additional presentation includes
319
-if (!defined('NOREQUIREHTML'))
320
-    require_once DOL_BASE_PATH . '/core/class/html.form.class.php';     // Need 660ko memory (800ko in 2.2)
321
-if (!defined('NOREQUIREAJAX') && $conf->use_javascript_ajax)
322
-    require_once DOL_BASE_PATH . '/core/lib/ajax.lib.php'; // Need 22ko memory
324
+if (!defined('NOREQUIREHTML')) {
325
+    require_once DOL_BASE_PATH . '/core/class/html.form.class.php';
326
+}
327
+// Need 660ko memory (800ko in 2.2)
328
+if (!defined('NOREQUIREAJAX') && $conf->use_javascript_ajax) {
329
+    require_once DOL_BASE_PATH . '/core/lib/ajax.lib.php';
330
+}
331
+// Need 22ko memory
323 332
 
324 333
 
325 334
 // If install or upgrade process not done or not completely finished, we call the install page.
@@ -345,8 +354,9 @@  discard block
 block discarded – undo
345 354
 // Creation of a token against CSRF vulnerabilities
346 355
 if (!defined('NOTOKENRENEWAL')) {
347 356
     // roulement des jetons car cree a chaque appel
348
-    if (isset($_SESSION['newtoken']))
349
-        $_SESSION['token'] = $_SESSION['newtoken'];
357
+    if (isset($_SESSION['newtoken'])) {
358
+            $_SESSION['token'] = $_SESSION['newtoken'];
359
+    }
350 360
 
351 361
     // Save in $_SESSION['newtoken'] what will be next token. Into forms, we will add param token = $_SESSION['newtoken']
352 362
     $token = dol_hash(uniqid(mt_rand(), true)); // Generates a hash of a random number
@@ -368,14 +378,16 @@  discard block
 block discarded – undo
368 378
 }
369 379
 
370 380
 // Disable modules (this must be after session_start and after conf has been loaded)
371
-if (GETPOST('disablemodules', 'alpha'))
381
+if (GETPOST('disablemodules', 'alpha')) {
372 382
     $_SESSION["disablemodules"] = GETPOST('disablemodules', 'alpha');
383
+}
373 384
 if (!empty($_SESSION["disablemodules"])) {
374 385
     $disabled_modules = explode(',', $_SESSION["disablemodules"]);
375 386
     foreach ($disabled_modules as $module) {
376 387
         if ($module) {
377
-            if (empty($conf->$module))
378
-                $conf->$module = new stdClass();
388
+            if (empty($conf->$module)) {
389
+                            $conf->$module = new stdClass();
390
+            }
379 391
             $conf->$module->enabled = false;
380 392
             if ($module == 'fournisseur') {  // Special case
381 393
                 $conf->supplier_order->enabled = 0;
@@ -397,11 +409,13 @@  discard block
 block discarded – undo
397 409
         $dolibarr_main_authentication = constant('MAIN_AUTHENTICATION_MODE');
398 410
     } else {
399 411
         // Authentication mode
400
-        if (empty($dolibarr_main_authentication))
401
-            $dolibarr_main_authentication = 'http,dolibarr';
412
+        if (empty($dolibarr_main_authentication)) {
413
+                    $dolibarr_main_authentication = 'http,dolibarr';
414
+        }
402 415
         // Authentication mode: forceuser
403
-        if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user))
404
-            $dolibarr_auto_user = 'auto';
416
+        if ($dolibarr_main_authentication == 'forceuser' && empty($dolibarr_auto_user)) {
417
+                    $dolibarr_auto_user = 'auto';
418
+        }
405 419
     }
406 420
     // Set authmode
407 421
     $authmode = explode(',', $dolibarr_main_authentication);
@@ -478,35 +492,41 @@  discard block
 block discarded – undo
478 492
                 $hookmanager->initHooks(array('login'));
479 493
                 $parameters = array('dol_authmode' => $dol_authmode, 'dol_loginmesg' => $_SESSION["dol_loginmesg"]);
480 494
                 $reshook = $hookmanager->executeHooks('afterLoginFailed', $parameters, $user, $action);    // Note that $action and $object may have been modified by some hooks
481
-                if ($reshook < 0)
482
-                    $error++;
495
+                if ($reshook < 0) {
496
+                                    $error++;
497
+                }
483 498
 
484 499
                 // Note: exit is done later
485 500
             }
486 501
         }
487 502
 
488 503
         $allowedmethodtopostusername = 2;
489
-        if (defined('MAIN_AUTHENTICATION_POST_METHOD'))
490
-            $allowedmethodtopostusername = constant('MAIN_AUTHENTICATION_POST_METHOD');
504
+        if (defined('MAIN_AUTHENTICATION_POST_METHOD')) {
505
+                    $allowedmethodtopostusername = constant('MAIN_AUTHENTICATION_POST_METHOD');
506
+        }
491 507
         $usertotest = (!empty($_COOKIE['login_dolibarr']) ? $_COOKIE['login_dolibarr'] : GETPOST("username", "alpha", $allowedmethodtopostusername));
492 508
         $passwordtotest = GETPOST('password', 'none', $allowedmethodtopostusername);
493 509
         $entitytotest = (GETPOST('entity', 'int') ? GETPOST('entity', 'int') : (!empty($conf->entity) ? $conf->entity : 1));
494 510
 
495 511
         // Define if we received data to test the login.
496 512
         $goontestloop = false;
497
-        if (isset($_SERVER["REMOTE_USER"]) && in_array('http', $authmode))
498
-            $goontestloop = true;
499
-        if ($dolibarr_main_authentication == 'forceuser' && !empty($dolibarr_auto_user))
500
-            $goontestloop = true;
501
-        if (GETPOST("username", "alpha", $allowedmethodtopostusername) || !empty($_COOKIE['login_dolibarr']) || GETPOST('openid_mode', 'alpha', 1))
502
-            $goontestloop = true;
513
+        if (isset($_SERVER["REMOTE_USER"]) && in_array('http', $authmode)) {
514
+                    $goontestloop = true;
515
+        }
516
+        if ($dolibarr_main_authentication == 'forceuser' && !empty($dolibarr_auto_user)) {
517
+                    $goontestloop = true;
518
+        }
519
+        if (GETPOST("username", "alpha", $allowedmethodtopostusername) || !empty($_COOKIE['login_dolibarr']) || GETPOST('openid_mode', 'alpha', 1)) {
520
+                    $goontestloop = true;
521
+        }
503 522
 
504 523
         if (!is_object($langs)) { // This can occurs when calling page with NOREQUIRETRAN defined, however we need langs for error messages.
505 524
             include_once DOL_BASE_PATH . '/core/class/translate.class.php';
506 525
             $langs = new Translate("", $conf);
507 526
             $langcode = (GETPOST('lang', 'aZ09', 1) ? GETPOST('lang', 'aZ09', 1) : (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT));
508
-            if (defined('MAIN_LANG_DEFAULT'))
509
-                $langcode = constant('MAIN_LANG_DEFAULT');
527
+            if (defined('MAIN_LANG_DEFAULT')) {
528
+                            $langcode = constant('MAIN_LANG_DEFAULT');
529
+            }
510 530
             $langs->setDefaultLang($langcode);
511 531
         }
512 532
 
@@ -528,8 +548,9 @@  discard block
 block discarded – undo
528 548
                     $datenow = dol_now();
529 549
                     $datefirst = dol_stringtotime($_POST["dst_first"]);
530 550
                     $datesecond = dol_stringtotime($_POST["dst_second"]);
531
-                    if ($datenow >= $datefirst && $datenow < $datesecond)
532
-                        $dol_dst = 1;
551
+                    if ($datenow >= $datefirst && $datenow < $datesecond) {
552
+                                            $dol_dst = 1;
553
+                    }
533 554
                 }
534 555
                 //print $datefirst.'-'.$datesecond.'-'.$datenow.'-'.$dol_tz.'-'.$dol_tzstring.'-'.$dol_dst; exit;
535 556
             }
@@ -541,8 +562,9 @@  discard block
 block discarded – undo
541 562
 
542 563
                 // Bad password. No authmode has found a good password.
543 564
                 // We set a generic message if not defined inside function checkLoginPassEntity or subfunctions
544
-                if (empty($_SESSION["dol_loginmesg"]))
545
-                    $_SESSION["dol_loginmesg"] = $langs->trans("ErrorBadLoginPassword");
565
+                if (empty($_SESSION["dol_loginmesg"])) {
566
+                                    $_SESSION["dol_loginmesg"] = $langs->trans("ErrorBadLoginPassword");
567
+                }
546 568
 
547 569
                 // Call trigger for the "security events" log
548 570
                 $user->trigger_mesg = $langs->trans("ErrorBadLoginPassword") . ' - login=' . GETPOST("username", "alpha", 2);
@@ -559,8 +581,9 @@  discard block
 block discarded – undo
559 581
                 $hookmanager->initHooks(array('login'));
560 582
                 $parameters = array('dol_authmode' => $dol_authmode, 'dol_loginmesg' => $_SESSION["dol_loginmesg"]);
561 583
                 $reshook = $hookmanager->executeHooks('afterLoginFailed', $parameters, $user, $action);    // Note that $action and $object may have been modified by some hooks
562
-                if ($reshook < 0)
563
-                    $error++;
584
+                if ($reshook < 0) {
585
+                                    $error++;
586
+                }
564 587
 
565 588
                 // Note: exit is done in next chapter
566 589
             }
@@ -570,10 +593,11 @@  discard block
 block discarded – undo
570 593
         if (!$login || (in_array('ldap', $authmode) && empty($passwordtotest))) { // With LDAP we refused empty password because some LDAP are "opened" for anonymous access so connexion is a success.
571 594
             // No data to test login, so we show the login page
572 595
             dol_syslog("--- Access to " . $_SERVER["PHP_SELF"] . " showing the login form and exit");
573
-            if (defined('NOREDIRECTBYMAINTOLOGIN'))
574
-                return 'ERROR_NOT_LOGGED';
575
-            else
576
-                dol_loginfunction($langs, $conf, (!empty($mysoc) ? $mysoc : ''));
596
+            if (defined('NOREDIRECTBYMAINTOLOGIN')) {
597
+                            return 'ERROR_NOT_LOGGED';
598
+            } else {
599
+                            dol_loginfunction($langs, $conf, (!empty($mysoc) ? $mysoc : ''));
600
+            }
577 601
             exit;
578 602
         }
579 603
 
@@ -612,21 +636,24 @@  discard block
 block discarded – undo
612 636
             $hookmanager->initHooks(array('login'));
613 637
             $parameters = array('dol_authmode' => $dol_authmode, 'dol_loginmesg' => $_SESSION["dol_loginmesg"]);
614 638
             $reshook = $hookmanager->executeHooks('afterLoginFailed', $parameters, $user, $action);    // Note that $action and $object may have been modified by some hooks
615
-            if ($reshook < 0)
616
-                $error++;
639
+            if ($reshook < 0) {
640
+                            $error++;
641
+            }
617 642
 
618 643
             $paramsurl = array();
619
-            if (GETPOST('textbrowser', 'int'))
620
-                $paramsurl[] = 'textbrowser=' . GETPOST('textbrowser', 'int');
621
-            if (GETPOST('nojs', 'int'))
622
-                $paramsurl[] = 'nojs=' . GETPOST('nojs', 'int');
623
-            if (GETPOST('lang', 'aZ09'))
624
-                $paramsurl[] = 'lang=' . GETPOST('lang', 'aZ09');
644
+            if (GETPOST('textbrowser', 'int')) {
645
+                            $paramsurl[] = 'textbrowser=' . GETPOST('textbrowser', 'int');
646
+            }
647
+            if (GETPOST('nojs', 'int')) {
648
+                            $paramsurl[] = 'nojs=' . GETPOST('nojs', 'int');
649
+            }
650
+            if (GETPOST('lang', 'aZ09')) {
651
+                            $paramsurl[] = 'lang=' . GETPOST('lang', 'aZ09');
652
+            }
625 653
             header('Location: ' . DOL_BASE_URI . '/index.php' . (count($paramsurl) ? '?' . implode('&', $paramsurl) : ''));
626 654
             exit;
627 655
         }
628
-    }
629
-    else {
656
+    } else {
630 657
         // We are already into an authenticated session
631 658
         $login = $_SESSION["dol_login"];
632 659
         $entity = $_SESSION["dol_entity"];
@@ -668,20 +695,23 @@  discard block
 block discarded – undo
668 695
             $hookmanager->initHooks(array('login'));
669 696
             $parameters = array('dol_authmode' => $dol_authmode, 'dol_loginmesg' => $_SESSION["dol_loginmesg"]);
670 697
             $reshook = $hookmanager->executeHooks('afterLoginFailed', $parameters, $user, $action);    // Note that $action and $object may have been modified by some hooks
671
-            if ($reshook < 0)
672
-                $error++;
698
+            if ($reshook < 0) {
699
+                            $error++;
700
+            }
673 701
 
674 702
             $paramsurl = array();
675
-            if (GETPOST('textbrowser', 'int'))
676
-                $paramsurl[] = 'textbrowser=' . GETPOST('textbrowser', 'int');
677
-            if (GETPOST('nojs', 'int'))
678
-                $paramsurl[] = 'nojs=' . GETPOST('nojs', 'int');
679
-            if (GETPOST('lang', 'aZ09'))
680
-                $paramsurl[] = 'lang=' . GETPOST('lang', 'aZ09');
703
+            if (GETPOST('textbrowser', 'int')) {
704
+                            $paramsurl[] = 'textbrowser=' . GETPOST('textbrowser', 'int');
705
+            }
706
+            if (GETPOST('nojs', 'int')) {
707
+                            $paramsurl[] = 'nojs=' . GETPOST('nojs', 'int');
708
+            }
709
+            if (GETPOST('lang', 'aZ09')) {
710
+                            $paramsurl[] = 'lang=' . GETPOST('lang', 'aZ09');
711
+            }
681 712
             header('Location: ' . DOL_BASE_URI . '/index.php' . (count($paramsurl) ? '?' . implode('&', $paramsurl) : ''));
682 713
             exit;
683
-        }
684
-        else {
714
+        } else {
685 715
             // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
686 716
             $hookmanager->initHooks(array('main'));
687 717
 
@@ -690,8 +720,9 @@  discard block
 block discarded – undo
690 720
                 $relativepathstring = preg_replace('/\?.*$/', '', $_SERVER["HTTP_REFERER"]);
691 721
                 $relativepathstring = preg_replace('/^https?:\/\/[^\/]*/', '', $relativepathstring);     // Get full path except host server
692 722
                 // Clean $relativepathstring
693
-                if (constant('DOL_BASE_URI'))
694
-                    $relativepathstring = preg_replace('/^' . preg_quote(constant('DOL_BASE_URI'), '/') . '/', '', $relativepathstring);
723
+                if (constant('DOL_BASE_URI')) {
724
+                                    $relativepathstring = preg_replace('/^' . preg_quote(constant('DOL_BASE_URI'), '/') . '/', '', $relativepathstring);
725
+                }
695 726
                 $relativepathstring = preg_replace('/^\//', '', $relativepathstring);
696 727
                 $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
697 728
                 //var_dump($relativepathstring);
@@ -742,16 +773,21 @@  discard block
 block discarded – undo
742 773
         $_SESSION["dol_company"] = $conf->global->MAIN_INFO_SOCIETE_NOM;
743 774
         $_SESSION["dol_entity"] = $conf->entity;
744 775
         // Store value into session (values stored only if defined)
745
-        if (!empty($dol_hide_topmenu))
746
-            $_SESSION['dol_hide_topmenu'] = $dol_hide_topmenu;
747
-        if (!empty($dol_hide_leftmenu))
748
-            $_SESSION['dol_hide_leftmenu'] = $dol_hide_leftmenu;
749
-        if (!empty($dol_optimize_smallscreen))
750
-            $_SESSION['dol_optimize_smallscreen'] = $dol_optimize_smallscreen;
751
-        if (!empty($dol_no_mouse_hover))
752
-            $_SESSION['dol_no_mouse_hover'] = $dol_no_mouse_hover;
753
-        if (!empty($dol_use_jmobile))
754
-            $_SESSION['dol_use_jmobile'] = $dol_use_jmobile;
776
+        if (!empty($dol_hide_topmenu)) {
777
+                    $_SESSION['dol_hide_topmenu'] = $dol_hide_topmenu;
778
+        }
779
+        if (!empty($dol_hide_leftmenu)) {
780
+                    $_SESSION['dol_hide_leftmenu'] = $dol_hide_leftmenu;
781
+        }
782
+        if (!empty($dol_optimize_smallscreen)) {
783
+                    $_SESSION['dol_optimize_smallscreen'] = $dol_optimize_smallscreen;
784
+        }
785
+        if (!empty($dol_no_mouse_hover)) {
786
+                    $_SESSION['dol_no_mouse_hover'] = $dol_no_mouse_hover;
787
+        }
788
+        if (!empty($dol_use_jmobile)) {
789
+                    $_SESSION['dol_use_jmobile'] = $dol_use_jmobile;
790
+        }
755 791
 
756 792
         dol_syslog("This is a new started user session. _SESSION['dol_login']=" . $_SESSION["dol_login"] . " Session id=" . session_id());
757 793
 
@@ -776,8 +812,9 @@  discard block
 block discarded – undo
776 812
         $hookmanager->initHooks(array('login'));
777 813
         $parameters = array('dol_authmode' => $dol_authmode, 'dol_loginfo' => $loginfo);
778 814
         $reshook = $hookmanager->executeHooks('afterLogin', $parameters, $user, $action);    // Note that $action and $object may have been modified by some hooks
779
-        if ($reshook < 0)
780
-            $error++;
815
+        if ($reshook < 0) {
816
+                    $error++;
817
+        }
781 818
 
782 819
         if ($error) {
783 820
             $db->rollback();
@@ -815,10 +852,14 @@  discard block
 block discarded – undo
815 852
      */
816 853
 
817 854
     // Set liste_limit
818
-    if (isset($user->conf->MAIN_SIZE_LISTE_LIMIT))
819
-        $conf->liste_limit = $user->conf->MAIN_SIZE_LISTE_LIMIT; // Can be 0
820
-    if (isset($user->conf->PRODUIT_LIMIT_SIZE))
821
-        $conf->product->limit_size = $user->conf->PRODUIT_LIMIT_SIZE; // Can be 0
855
+    if (isset($user->conf->MAIN_SIZE_LISTE_LIMIT)) {
856
+            $conf->liste_limit = $user->conf->MAIN_SIZE_LISTE_LIMIT;
857
+    }
858
+    // Can be 0
859
+    if (isset($user->conf->PRODUIT_LIMIT_SIZE)) {
860
+            $conf->product->limit_size = $user->conf->PRODUIT_LIMIT_SIZE;
861
+    }
862
+    // Can be 0
822 863
 
823 864
 
824 865
 
@@ -859,8 +900,9 @@  discard block
 block discarded – undo
859 900
     if (!empty($user->conf->MAIN_DISABLE_JAVASCRIPT)) {
860 901
         $conf->use_javascript_ajax = !$user->conf->MAIN_DISABLE_JAVASCRIPT;
861 902
     }
862
-} else
903
+} else {
863 904
     $conf->use_javascript_ajax = 0;
905
+}
864 906
 // Set MAIN_OPTIMIZEFORTEXTBROWSER
865 907
 if (GETPOST('textbrowser', 'int') || (!empty($conf->browser->name) && $conf->browser->name == 'lynxlinks') || !empty($user->conf->MAIN_OPTIMIZEFORTEXTBROWSER)) {   // If we must enable text browser
866 908
     $conf->global->MAIN_OPTIMIZEFORTEXTBROWSER = 1;
@@ -869,25 +911,32 @@  discard block
 block discarded – undo
869 911
 }
870 912
 
871 913
 // Set terminal output option according to conf->browser.
872
-if (GETPOST('dol_hide_leftmenu', 'int') || !empty($_SESSION['dol_hide_leftmenu']))
914
+if (GETPOST('dol_hide_leftmenu', 'int') || !empty($_SESSION['dol_hide_leftmenu'])) {
873 915
     $conf->dol_hide_leftmenu = 1;
874
-if (GETPOST('dol_hide_topmenu', 'int') || !empty($_SESSION['dol_hide_topmenu']))
916
+}
917
+if (GETPOST('dol_hide_topmenu', 'int') || !empty($_SESSION['dol_hide_topmenu'])) {
875 918
     $conf->dol_hide_topmenu = 1;
876
-if (GETPOST('dol_optimize_smallscreen', 'int') || !empty($_SESSION['dol_optimize_smallscreen']))
919
+}
920
+if (GETPOST('dol_optimize_smallscreen', 'int') || !empty($_SESSION['dol_optimize_smallscreen'])) {
877 921
     $conf->dol_optimize_smallscreen = 1;
878
-if (GETPOST('dol_no_mouse_hover', 'int') || !empty($_SESSION['dol_no_mouse_hover']))
922
+}
923
+if (GETPOST('dol_no_mouse_hover', 'int') || !empty($_SESSION['dol_no_mouse_hover'])) {
879 924
     $conf->dol_no_mouse_hover = 1;
880
-if (GETPOST('dol_use_jmobile', 'int') || !empty($_SESSION['dol_use_jmobile']))
925
+}
926
+if (GETPOST('dol_use_jmobile', 'int') || !empty($_SESSION['dol_use_jmobile'])) {
881 927
     $conf->dol_use_jmobile = 1;
882
-if (!empty($conf->browser->layout) && $conf->browser->layout != 'classic')
928
+}
929
+if (!empty($conf->browser->layout) && $conf->browser->layout != 'classic') {
883 930
     $conf->dol_no_mouse_hover = 1;
931
+}
884 932
 if ((!empty($conf->browser->layout) && $conf->browser->layout == 'phone') || (!empty($_SESSION['dol_screenwidth']) && $_SESSION['dol_screenwidth'] < 400) || (!empty($_SESSION['dol_screenheight']) && $_SESSION['dol_screenheight'] < 400)
885 933
 ) {
886 934
     $conf->dol_optimize_smallscreen = 1;
887 935
 }
888 936
 // If we force to use jmobile, then we reenable javascript
889
-if (!empty($conf->dol_use_jmobile))
937
+if (!empty($conf->dol_use_jmobile)) {
890 938
     $conf->use_javascript_ajax = 1;
939
+}
891 940
 // Replace themes bugged with jmobile with eldy
892 941
 if (!empty($conf->dol_use_jmobile) && in_array($conf->theme, array('bureau2crea', 'cameleo', 'amarok'))) {
893 942
     $conf->theme = 'eldy';
@@ -911,8 +960,9 @@  discard block
 block discarded – undo
911 960
 if (!defined('NOLOGIN')) {
912 961
     // If the login is not recovered, it is identified with an account that does not exist.
913 962
     // Hacking attempt?
914
-    if (!$user->login)
915
-        accessforbidden();
963
+    if (!$user->login) {
964
+            accessforbidden();
965
+    }
916 966
 
917 967
     // Check if user is active
918 968
     if ($user->statut < 1) {
@@ -987,15 +1037,18 @@  discard block
 block discarded – undo
987 1037
 
988 1038
     // Load the menu manager (only if not already done)
989 1039
     $file_menu = $conf->standard_menu;
990
-    if (GETPOST('menu', 'alpha'))
991
-        $file_menu = GETPOST('menu', 'alpha');     // example: menu=eldy_menu.php
1040
+    if (GETPOST('menu', 'alpha')) {
1041
+            $file_menu = GETPOST('menu', 'alpha');
1042
+    }
1043
+    // example: menu=eldy_menu.php
992 1044
     if (!class_exists('MenuManager')) {
993 1045
         $menufound = 0;
994 1046
         $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
995 1047
         foreach ($dirmenus as $dirmenu) {
996 1048
             $menufound = dol_include_once($dirmenu . "standard/" . $file_menu);
997
-            if (class_exists('MenuManager'))
998
-                break;
1049
+            if (class_exists('MenuManager')) {
1050
+                            break;
1051
+            }
999 1052
         }
1000 1053
         if (!class_exists('MenuManager')) { // If failed to include, we try with standard eldy_menu.php
1001 1054
             dol_syslog("You define a menu manager '" . $file_menu . "' that can not be loaded.", LOG_WARNING);
@@ -1145,18 +1198,20 @@  discard block
 block discarded – undo
1145 1198
     }
1146 1199
     print '<!doctype html>' . "\n";
1147 1200
 
1148
-    if (!empty($conf->global->MAIN_USE_CACHE_MANIFEST))
1149
-        print '<html lang="' . substr($langs->defaultlang, 0, 2) . '" manifest="' . DOL_BASE_URI . '/cache.manifest">' . "\n";
1150
-    else
1151
-        print '<html lang="' . substr($langs->defaultlang, 0, 2) . '">' . "\n";
1201
+    if (!empty($conf->global->MAIN_USE_CACHE_MANIFEST)) {
1202
+            print '<html lang="' . substr($langs->defaultlang, 0, 2) . '" manifest="' . DOL_BASE_URI . '/cache.manifest">' . "\n";
1203
+    } else {
1204
+            print '<html lang="' . substr($langs->defaultlang, 0, 2) . '">' . "\n";
1205
+    }
1152 1206
     //print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">'."\n";
1153 1207
     if (empty($disablehead)) {
1154 1208
         $ext = 'layout=' . $conf->browser->layout . '&version=' . urlencode(DOL_VERSION);
1155 1209
 
1156 1210
         print "<head>\n";
1157 1211
 
1158
-        if (GETPOST('dol_basehref', 'alpha'))
1159
-            print '<base href="' . dol_escape_htmltag(GETPOST('dol_basehref', 'alpha')) . '">' . "\n";
1212
+        if (GETPOST('dol_basehref', 'alpha')) {
1213
+                    print '<base href="' . dol_escape_htmltag(GETPOST('dol_basehref', 'alpha')) . '">' . "\n";
1214
+        }
1160 1215
 
1161 1216
         // Displays meta
1162 1217
         print '<meta charset="UTF-8">' . "\n";
@@ -1166,10 +1221,13 @@  discard block
 block discarded – undo
1166 1221
 
1167 1222
         // Favicon
1168 1223
         $favicon = dol_buildpath('/theme/' . $conf->theme . '/img/favicon.ico', 1);
1169
-        if (!empty($conf->global->MAIN_FAVICON_URL))
1170
-            $favicon = $conf->global->MAIN_FAVICON_URL;
1171
-        if (empty($conf->dol_use_jmobile))
1172
-            print '<link rel="shortcut icon" type="image/x-icon" href="' . $favicon . '"/>' . "\n"; // Not required into an Android webview
1224
+        if (!empty($conf->global->MAIN_FAVICON_URL)) {
1225
+                    $favicon = $conf->global->MAIN_FAVICON_URL;
1226
+        }
1227
+        if (empty($conf->dol_use_jmobile)) {
1228
+                    print '<link rel="shortcut icon" type="image/x-icon" href="' . $favicon . '"/>' . "\n";
1229
+        }
1230
+        // Not required into an Android webview
1173 1231
 
1174 1232
 
1175 1233
 
@@ -1193,32 +1251,40 @@  discard block
 block discarded – undo
1193 1251
         //if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="copyright" title="GNU General Public License" href="http://www.gnu.org/copyleft/gpl.html#SEC1">'."\n";
1194 1252
         //if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="author" title="Dolibarr Development Team" href="https://www.dolibarr.org">'."\n";
1195 1253
         // Auto refresh page
1196
-        if (GETPOST('autorefresh', 'int') > 0)
1197
-            print '<meta http-equiv="refresh" content="' . GETPOST('autorefresh', 'int') . '">';
1254
+        if (GETPOST('autorefresh', 'int') > 0) {
1255
+                    print '<meta http-equiv="refresh" content="' . GETPOST('autorefresh', 'int') . '">';
1256
+        }
1198 1257
 
1199 1258
         // Displays title
1200 1259
         $appli = constant('DOL_APPLICATION_TITLE');
1201
-        if (!empty($conf->global->MAIN_APPLICATION_TITLE))
1202
-            $appli = $conf->global->MAIN_APPLICATION_TITLE;
1260
+        if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
1261
+                    $appli = $conf->global->MAIN_APPLICATION_TITLE;
1262
+        }
1203 1263
 
1204 1264
         print '<title>';
1205 1265
         $titletoshow = '';
1206
-        if ($title && !empty($conf->global->MAIN_HTML_TITLE) && preg_match('/noapp/', $conf->global->MAIN_HTML_TITLE))
1207
-            $titletoshow = dol_htmlentities($title);
1208
-        else if ($title)
1209
-            $titletoshow = dol_htmlentities($appli . ' - ' . $title);
1210
-        else
1211
-            $titletoshow = dol_htmlentities($appli);
1212
-
1213
-        if (!is_object($hookmanager))
1214
-            $hookmanager = new HookManager($db);
1266
+        if ($title && !empty($conf->global->MAIN_HTML_TITLE) && preg_match('/noapp/', $conf->global->MAIN_HTML_TITLE)) {
1267
+                    $titletoshow = dol_htmlentities($title);
1268
+        } else if ($title) {
1269
+                    $titletoshow = dol_htmlentities($appli . ' - ' . $title);
1270
+        } else {
1271
+                    $titletoshow = dol_htmlentities($appli);
1272
+        }
1273
+
1274
+        if (!is_object($hookmanager)) {
1275
+                    $hookmanager = new HookManager($db);
1276
+        }
1215 1277
         $hookmanager->initHooks("main");
1216 1278
         $parameters = array('title' => $titletoshow);
1217 1279
         $result = $hookmanager->executeHooks('setHtmlTitle', $parameters);  // Note that $action and $object may have been modified by some hooks
1218
-        if ($result > 0)
1219
-            $titletoshow = $hookmanager->resPrint;    // Replace Title to show
1220
-        else
1221
-            $titletoshow .= $hookmanager->resPrint;      // Concat to Title to show
1280
+        if ($result > 0) {
1281
+                    $titletoshow = $hookmanager->resPrint;
1282
+        }
1283
+        // Replace Title to show
1284
+        else {
1285
+                    $titletoshow .= $hookmanager->resPrint;
1286
+        }
1287
+        // Concat to Title to show
1222 1288
 
1223 1289
         print $titletoshow;
1224 1290
         print '</title>';
@@ -1308,8 +1374,9 @@  discard block
 block discarded – undo
1308 1374
 
1309 1375
         //print 'themepath='.$themepath.' themeparam='.$themeparam;exit;
1310 1376
         print '<link rel="stylesheet" type="text/css" href="' . $themepath . $themeparam . '">' . "\n";
1311
-        if (!empty($conf->global->MAIN_FIX_FLASH_ON_CHROME))
1312
-            print '<!-- Includes CSS that does not exists as a workaround of flash bug of chrome -->' . "\n" . '<link rel="stylesheet" type="text/css" href="filethatdoesnotexiststosolvechromeflashbug">' . "\n";
1377
+        if (!empty($conf->global->MAIN_FIX_FLASH_ON_CHROME)) {
1378
+                    print '<!-- Includes CSS that does not exists as a workaround of flash bug of chrome -->' . "\n" . '<link rel="stylesheet" type="text/css" href="filethatdoesnotexiststosolvechromeflashbug">' . "\n";
1379
+        }
1313 1380
 
1314 1381
         // CSS forced by modules (relative url starting with /)
1315 1382
         if (!empty($conf->modules_parts['css'])) {
@@ -1317,13 +1384,15 @@  discard block
 block discarded – undo
1317 1384
             foreach ($arraycss as $modcss => $filescss) {
1318 1385
                 $filescss = (array) $filescss; // To be sure filecss is an array
1319 1386
                 foreach ($filescss as $cssfile) {
1320
-                    if (empty($cssfile))
1321
-                        dol_syslog("Warning: module " . $modcss . " declared a css path file into its descriptor that is empty.", LOG_WARNING);
1387
+                    if (empty($cssfile)) {
1388
+                                            dol_syslog("Warning: module " . $modcss . " declared a css path file into its descriptor that is empty.", LOG_WARNING);
1389
+                    }
1322 1390
                     // cssfile is a relative path
1323 1391
                     print '<!-- Includes CSS added by module ' . $modcss . ' -->' . "\n" . '<link rel="stylesheet" type="text/css" href="' . dol_buildpath($cssfile, 1);
1324 1392
                     // We add params only if page is not static, because some web server setup does not return content type text/css if url has parameters, so browser cache is not used.
1325
-                    if (!preg_match('/\.css$/i', $cssfile))
1326
-                        print $themeparam;
1393
+                    if (!preg_match('/\.css$/i', $cssfile)) {
1394
+                                            print $themeparam;
1395
+                    }
1327 1396
                     print '">' . "\n";
1328 1397
                 }
1329 1398
             }
@@ -1333,8 +1402,9 @@  discard block
 block discarded – undo
1333 1402
             foreach ($arrayofcss as $cssfile) {
1334 1403
                 print '<!-- Includes CSS added by page -->' . "\n" . '<link rel="stylesheet" type="text/css" title="default" href="' . dol_buildpath($cssfile, 1);
1335 1404
                 // We add params only if page is not static, because some web server setup does not return content type text/css if url has parameters and browser cache is not used.
1336
-                if (!preg_match('/\.css$/i', $cssfile))
1337
-                    print $themeparam;
1405
+                if (!preg_match('/\.css$/i', $cssfile)) {
1406
+                                    print $themeparam;
1407
+                }
1338 1408
                 print '">' . "\n";
1339 1409
             }
1340 1410
         }
@@ -1439,10 +1509,12 @@  discard block
 block discarded – undo
1439 1509
             // Browser notifications
1440 1510
             if (!defined('DISABLE_BROWSER_NOTIF')) {
1441 1511
                 $enablebrowsernotif = false;
1442
-                if (!empty($conf->agenda->enabled) && !empty($conf->global->AGENDA_REMINDER_BROWSER))
1443
-                    $enablebrowsernotif = true;
1444
-                if ($conf->browser->layout == 'phone')
1445
-                    $enablebrowsernotif = false;
1512
+                if (!empty($conf->agenda->enabled) && !empty($conf->global->AGENDA_REMINDER_BROWSER)) {
1513
+                                    $enablebrowsernotif = true;
1514
+                }
1515
+                if ($conf->browser->layout == 'phone') {
1516
+                                    $enablebrowsernotif = false;
1517
+                }
1446 1518
                 if ($enablebrowsernotif) {
1447 1519
                     print '<!-- Includes JS of Dolibarr (brwoser layout = ' . $conf->browser->layout . ')-->' . "\n";
1448 1520
                     //print '<script type="text/javascript" src="' . DOL_BASE_URI . '/core/js/lib_notification.js.php' . ($ext ? '?' . $ext : '') . '"></script>' . "\n";
@@ -1479,10 +1551,12 @@  discard block
 block discarded – undo
1479 1551
             }
1480 1552
         }
1481 1553
 
1482
-        if (!empty($head))
1483
-            print $head . "\n";
1484
-        if (!empty($conf->global->MAIN_HTML_HEADER))
1485
-            print $conf->global->MAIN_HTML_HEADER . "\n";
1554
+        if (!empty($head)) {
1555
+                    print $head . "\n";
1556
+        }
1557
+        if (!empty($conf->global->MAIN_HTML_HEADER)) {
1558
+                    print $conf->global->MAIN_HTML_HEADER . "\n";
1559
+        }
1486 1560
 
1487 1561
         print "<!-- Alixar debugBar header -->";
1488 1562
         print Debug::getRenderHeader(); // Includes Alixar debugBar header
@@ -1547,15 +1621,20 @@  discard block
 block discarded – undo
1547 1621
         if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
1548 1622
             $appli = $conf->global->MAIN_APPLICATION_TITLE;
1549 1623
             if (preg_match('/\d\.\d/', $appli)) {
1550
-                if (!preg_match('/' . preg_quote(DOL_VERSION) . '/', $appli))
1551
-                    $appli .= " (" . DOL_VERSION . ")"; // If new title contains a version that is different than core
1552
-            } else
1553
-                $appli .= " " . DOL_VERSION;
1554
-        } else
1555
-            $appli .= " " . DOL_VERSION;
1624
+                if (!preg_match('/' . preg_quote(DOL_VERSION) . '/', $appli)) {
1625
+                                    $appli .= " (" . DOL_VERSION . ")";
1626
+                }
1627
+                // If new title contains a version that is different than core
1628
+            } else {
1629
+                            $appli .= " " . DOL_VERSION;
1630
+            }
1631
+        } else {
1632
+                    $appli .= " " . DOL_VERSION;
1633
+        }
1556 1634
 
1557
-        if (!empty($conf->global->MAIN_FEATURES_LEVEL))
1558
-            $appli .= "<br>" . $langs->trans("LevelOfFeature") . ': ' . $conf->global->MAIN_FEATURES_LEVEL;
1635
+        if (!empty($conf->global->MAIN_FEATURES_LEVEL)) {
1636
+                    $appli .= "<br>" . $langs->trans("LevelOfFeature") . ': ' . $conf->global->MAIN_FEATURES_LEVEL;
1637
+        }
1559 1638
 
1560 1639
         $logouttext = '';
1561 1640
         if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
@@ -1593,12 +1672,15 @@  discard block
 block discarded – undo
1593 1672
         $parameters = array();
1594 1673
         $result = $hookmanager->executeHooks('printTopRightMenu', $parameters);    // Note that $action and $object may have been modified by some hooks
1595 1674
         if (is_numeric($result)) {
1596
-            if ($result == 0)
1597
-                $toprightmenu .= $hookmanager->resPrint;  // add
1598
-            else
1599
-                $toprightmenu = $hookmanager->resPrint;      // replace
1600
-        }
1601
-        else {
1675
+            if ($result == 0) {
1676
+                            $toprightmenu .= $hookmanager->resPrint;
1677
+            }
1678
+            // add
1679
+            else {
1680
+                            $toprightmenu = $hookmanager->resPrint;
1681
+            }
1682
+            // replace
1683
+        } else {
1602 1684
             $toprightmenu .= $result; // For backward compatibility
1603 1685
         }
1604 1686
 
@@ -1692,9 +1774,10 @@  discard block
 block discarded – undo
1692 1774
         print "<!-- End top horizontal menu -->\n\n";
1693 1775
     }
1694 1776
 
1695
-    if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile))
1696
-        print '<!-- Begin div id-container --><div id="id-container" class="id-container' . ($morecss ? ' ' . $morecss : '') . '">';
1697
-}
1777
+    if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile)) {
1778
+            print '<!-- Begin div id-container --><div id="id-container" class="id-container' . ($morecss ? ' ' . $morecss : '') . '">';
1779
+    }
1780
+    }
1698 1781
 
1699 1782
 /**
1700 1783
  *  Show left menu bar
@@ -1718,8 +1801,9 @@  discard block
 block discarded – undo
1718 1801
     $searchform = '';
1719 1802
     $bookmarks = '';
1720 1803
 
1721
-    if (!empty($menu_array_before))
1722
-        dol_syslog("Deprecated parameter menu_array_before was used when calling main::left_menu function. Menu entries of module should now be defined into module descriptor and not provided when calling left_menu.", LOG_WARNING);
1804
+    if (!empty($menu_array_before)) {
1805
+            dol_syslog("Deprecated parameter menu_array_before was used when calling main::left_menu function. Menu entries of module should now be defined into module descriptor and not provided when calling left_menu.", LOG_WARNING);
1806
+    }
1723 1807
 
1724 1808
     if (empty($conf->dol_hide_leftmenu) && (!defined('NOREQUIREMENU') || !constant('NOREQUIREMENU'))) {
1725 1809
         // Instantiate hooks of thirdparty module
@@ -1727,8 +1811,10 @@  discard block
 block discarded – undo
1727 1811
 
1728 1812
         print "\n" . '<!-- Begin side-nav id-left -->' . "\n" . '<div class="side-nav"><div id="id-left">' . "\n";
1729 1813
 
1730
-        if ($conf->browser->layout == 'phone')
1731
-            $conf->global->MAIN_USE_OLD_SEARCH_FORM = 1; // Select into select2 is awfull on smartphone. TODO Is this still true with select2 v4 ?
1814
+        if ($conf->browser->layout == 'phone') {
1815
+                    $conf->global->MAIN_USE_OLD_SEARCH_FORM = 1;
1816
+        }
1817
+        // Select into select2 is awfull on smartphone. TODO Is this still true with select2 v4 ?
1732 1818
 
1733 1819
         print "\n";
1734 1820
 
@@ -1755,8 +1841,9 @@  discard block
 block discarded – undo
1755 1841
         $reshook = $hookmanager->executeHooks('printSearchForm', $parameters);    // Note that $action and $object may have been modified by some hooks
1756 1842
         if (empty($reshook)) {
1757 1843
             $searchform .= $hookmanager->resPrint;
1758
-        } else
1759
-            $searchform = $hookmanager->resPrint;
1844
+        } else {
1845
+                    $searchform = $hookmanager->resPrint;
1846
+        }
1760 1847
 
1761 1848
         // Force special value for $searchform
1762 1849
         if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) || empty($conf->use_javascript_ajax)) {
@@ -1800,38 +1887,49 @@  discard block
 block discarded – undo
1800 1887
         if (empty($conf->global->MAIN_HIDE_VERSION)) {    // Version is already on help picto and on login page.
1801 1888
             $doliurl = 'https://www.dolibarr.org';
1802 1889
             //local communities
1803
-            if (preg_match('/fr/i', $langs->defaultlang))
1804
-                $doliurl = 'https://www.dolibarr.fr';
1805
-            if (preg_match('/es/i', $langs->defaultlang))
1806
-                $doliurl = 'https://www.dolibarr.es';
1807
-            if (preg_match('/de/i', $langs->defaultlang))
1808
-                $doliurl = 'https://www.dolibarr.de';
1809
-            if (preg_match('/it/i', $langs->defaultlang))
1810
-                $doliurl = 'https://www.dolibarr.it';
1811
-            if (preg_match('/gr/i', $langs->defaultlang))
1812
-                $doliurl = 'https://www.dolibarr.gr';
1890
+            if (preg_match('/fr/i', $langs->defaultlang)) {
1891
+                            $doliurl = 'https://www.dolibarr.fr';
1892
+            }
1893
+            if (preg_match('/es/i', $langs->defaultlang)) {
1894
+                            $doliurl = 'https://www.dolibarr.es';
1895
+            }
1896
+            if (preg_match('/de/i', $langs->defaultlang)) {
1897
+                            $doliurl = 'https://www.dolibarr.de';
1898
+            }
1899
+            if (preg_match('/it/i', $langs->defaultlang)) {
1900
+                            $doliurl = 'https://www.dolibarr.it';
1901
+            }
1902
+            if (preg_match('/gr/i', $langs->defaultlang)) {
1903
+                            $doliurl = 'https://www.dolibarr.gr';
1904
+            }
1813 1905
 
1814 1906
             $appli = constant('DOL_APPLICATION_TITLE');
1815 1907
             if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
1816 1908
                 $appli = $conf->global->MAIN_APPLICATION_TITLE;
1817 1909
                 $doliurl = '';
1818 1910
                 if (preg_match('/\d\.\d/', $appli)) {
1819
-                    if (!preg_match('/' . preg_quote(DOL_VERSION) . '/', $appli))
1820
-                        $appli .= " (" . DOL_VERSION . ")"; // If new title contains a version that is different than core
1821
-                } else
1822
-                    $appli .= " " . DOL_VERSION;
1823
-            } else
1824
-                $appli .= " " . DOL_VERSION;
1911
+                    if (!preg_match('/' . preg_quote(DOL_VERSION) . '/', $appli)) {
1912
+                                            $appli .= " (" . DOL_VERSION . ")";
1913
+                    }
1914
+                    // If new title contains a version that is different than core
1915
+                } else {
1916
+                                    $appli .= " " . DOL_VERSION;
1917
+                }
1918
+            } else {
1919
+                            $appli .= " " . DOL_VERSION;
1920
+            }
1825 1921
             print '<div id="blockvmenuhelpapp" class="blockvmenuhelp">';
1826
-            if ($doliurl)
1827
-                print '<a class="help" target="_blank" rel="noopener" href="' . $doliurl . '">';
1828
-            else
1829
-                print '<span class="help">';
1922
+            if ($doliurl) {
1923
+                            print '<a class="help" target="_blank" rel="noopener" href="' . $doliurl . '">';
1924
+            } else {
1925
+                            print '<span class="help">';
1926
+            }
1830 1927
             print $appli;
1831
-            if ($doliurl)
1832
-                print '</a>';
1833
-            else
1834
-                print '</span>';
1928
+            if ($doliurl) {
1929
+                            print '</a>';
1930
+            } else {
1931
+                            print '</span>';
1932
+            }
1835 1933
             print '</div>' . "\n";
1836 1934
         }
1837 1935
 
@@ -1878,9 +1976,10 @@  discard block
 block discarded – undo
1878 1976
     print "\n";
1879 1977
     print '<!-- Begin right area -->' . "\n";
1880 1978
 
1881
-    if (empty($leftmenuwithoutmainarea))
1882
-        main_area($title);
1883
-}
1979
+    if (empty($leftmenuwithoutmainarea)) {
1980
+            main_area($title);
1981
+    }
1982
+    }
1884 1983
 
1885 1984
 /**
1886 1985
  *  Begin main area
@@ -1892,16 +1991,18 @@  discard block
 block discarded – undo
1892 1991
 {
1893 1992
     global $conf, $langs;
1894 1993
 
1895
-    if (empty($conf->dol_hide_leftmenu))
1896
-        print '<div id="id-right">';
1994
+    if (empty($conf->dol_hide_leftmenu)) {
1995
+            print '<div id="id-right">';
1996
+    }
1897 1997
 
1898 1998
     print "\n";
1899 1999
 
1900 2000
     print '<!-- Begin div class="fiche" -->' . "\n" . '<div class="fiche">' . "\n";
1901 2001
 
1902
-    if (!empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED))
1903
-        print info_admin($langs->trans("WarningYouAreInMaintenanceMode", $conf->global->MAIN_ONLY_LOGIN_ALLOWED));
1904
-}
2002
+    if (!empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) {
2003
+            print info_admin($langs->trans("WarningYouAreInMaintenanceMode", $conf->global->MAIN_ONLY_LOGIN_ALLOWED));
2004
+    }
2005
+    }
1905 2006
 
1906 2007
 /**
1907 2008
  *  Return helpbaseurl, helppage and mode
@@ -1925,18 +2026,21 @@  discard block
 block discarded – undo
1925 2026
         // If WIKI URL
1926 2027
         if (preg_match('/^es/i', $langs->defaultlang)) {
1927 2028
             $helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s';
1928
-            if (preg_match('/ES:([^|]+)/i', $helppagename, $reg))
1929
-                $helppage = $reg[1];
2029
+            if (preg_match('/ES:([^|]+)/i', $helppagename, $reg)) {
2030
+                            $helppage = $reg[1];
2031
+            }
1930 2032
         }
1931 2033
         if (preg_match('/^fr/i', $langs->defaultlang)) {
1932 2034
             $helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s';
1933
-            if (preg_match('/FR:([^|]+)/i', $helppagename, $reg))
1934
-                $helppage = $reg[1];
2035
+            if (preg_match('/FR:([^|]+)/i', $helppagename, $reg)) {
2036
+                            $helppage = $reg[1];
2037
+            }
1935 2038
         }
1936 2039
         if (empty($helppage)) { // If help page not already found
1937 2040
             $helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s';
1938
-            if (preg_match('/EN:([^|]+)/i', $helppagename, $reg))
1939
-                $helppage = $reg[1];
2041
+            if (preg_match('/EN:([^|]+)/i', $helppagename, $reg)) {
2042
+                            $helppage = $reg[1];
2043
+            }
1940 2044
         }
1941 2045
         $mode = 'wiki';
1942 2046
     }
@@ -1967,8 +2071,9 @@  discard block
 block discarded – undo
1967 2071
     $ret .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
1968 2072
     $ret .= '<input type="hidden" name="mode" value="search">';
1969 2073
     $ret .= '<input type="hidden" name="savelogin" value="' . dol_escape_htmltag($user->login) . '">';
1970
-    if ($showtitlebefore)
1971
-        $ret .= $title . ' ';
2074
+    if ($showtitlebefore) {
2075
+            $ret .= $title . ' ';
2076
+    }
1972 2077
     $ret .= '<input type="text" class="flat ' . $htmlmorecss . '"';
1973 2078
     $ret .= ' style="text-indent: 22px; background-image: url(\'' . $img . '\'); background-repeat: no-repeat; background-position: 3px;"';
1974 2079
     $ret .= ($accesskey ? ' accesskey="' . $accesskey . '"' : '');
@@ -2013,10 +2118,12 @@  discard block
 block discarded – undo
2013 2118
             foreach ($user->lastsearch_values_tmp as $key => $val) {
2014 2119
                 unset($_SESSION['lastsearch_values_tmp_' . $key]);   // Clean array to rebuild it just after
2015 2120
                 if (count($val) && empty($_POST['button_removefilter'])) { // If there is search criteria to save and we did not click on 'Clear filter' button
2016
-                    if (empty($val['sortfield']))
2017
-                        unset($val['sortfield']);
2018
-                    if (empty($val['sortorder']))
2019
-                        unset($val['sortorder']);
2121
+                    if (empty($val['sortfield'])) {
2122
+                                            unset($val['sortfield']);
2123
+                    }
2124
+                    if (empty($val['sortorder'])) {
2125
+                                            unset($val['sortorder']);
2126
+                    }
2020 2127
                     dol_syslog('Save lastsearch_values_tmp_' . $key . '=' . json_encode($val, 0) . " (systematic recording of last search criterias)");
2021 2128
                     $_SESSION['lastsearch_values_tmp_' . $key] = json_encode($val);
2022 2129
                     unset($_SESSION['lastsearch_values_' . $key]);
@@ -2027,8 +2134,9 @@  discard block
 block discarded – undo
2027 2134
 
2028 2135
         $relativepathstring = $_SERVER["PHP_SELF"];
2029 2136
         // Clean $relativepathstring
2030
-        if (constant('DOL_BASE_URI'))
2031
-            $relativepathstring = preg_replace('/^' . preg_quote(constant('DOL_BASE_URI'), '/') . '/', '', $relativepathstring);
2137
+        if (constant('DOL_BASE_URI')) {
2138
+                    $relativepathstring = preg_replace('/^' . preg_quote(constant('DOL_BASE_URI'), '/') . '/', '', $relativepathstring);
2139
+        }
2032 2140
         $relativepathstring = preg_replace('/^\//', '', $relativepathstring);
2033 2141
         $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
2034 2142
         if (preg_match('/list\.php$/', $relativepathstring)) {
@@ -2036,12 +2144,15 @@  discard block
 block discarded – undo
2036 2144
             unset($_SESSION['lastsearch_page_tmp_' . $relativepathstring]);
2037 2145
             unset($_SESSION['lastsearch_limit_tmp_' . $relativepathstring]);
2038 2146
 
2039
-            if (!empty($contextpage))
2040
-                $_SESSION['lastsearch_contextpage_tmp_' . $relativepathstring] = $contextpage;
2041
-            if (!empty($page) && $page > 1)
2042
-                $_SESSION['lastsearch_page_tmp_' . $relativepathstring] = $page;
2043
-            if (!empty($limit) && $limit != $conf->limit)
2044
-                $_SESSION['lastsearch_limit_tmp_' . $relativepathstring] = $limit;
2147
+            if (!empty($contextpage)) {
2148
+                            $_SESSION['lastsearch_contextpage_tmp_' . $relativepathstring] = $contextpage;
2149
+            }
2150
+            if (!empty($page) && $page > 1) {
2151
+                            $_SESSION['lastsearch_page_tmp_' . $relativepathstring] = $page;
2152
+            }
2153
+            if (!empty($limit) && $limit != $conf->limit) {
2154
+                            $_SESSION['lastsearch_limit_tmp_' . $relativepathstring] = $limit;
2155
+            }
2045 2156
 
2046 2157
             unset($_SESSION['lastsearch_contextpage_' . $relativepathstring]);
2047 2158
             unset($_SESSION['lastsearch_page_' . $relativepathstring]);
@@ -2068,20 +2179,26 @@  discard block
 block discarded – undo
2068 2179
 
2069 2180
         print '</div> <!-- End div class="fiche" -->' . "\n"; // End div fiche
2070 2181
 
2071
-        if (empty($conf->dol_hide_leftmenu))
2072
-            print '</div> <!-- End div id-right -->' . "\n"; // End div id-right
2182
+        if (empty($conf->dol_hide_leftmenu)) {
2183
+                    print '</div> <!-- End div id-right -->' . "\n";
2184
+        }
2185
+        // End div id-right
2073 2186
 
2074
-        if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile))
2075
-            print '</div> <!-- End div id-container -->' . "\n"; // End div container
2187
+        if (empty($conf->dol_hide_leftmenu) && empty($conf->dol_use_jmobile)) {
2188
+                    print '</div> <!-- End div id-container -->' . "\n";
2189
+        }
2190
+        // End div container
2076 2191
 
2077 2192
         print "\n";
2078
-        if ($comment)
2079
-            print '<!-- ' . $comment . ' -->' . "\n";
2193
+        if ($comment) {
2194
+                    print '<!-- ' . $comment . ' -->' . "\n";
2195
+        }
2080 2196
 
2081 2197
         printCommonFooter($zone);
2082 2198
 
2083
-        if (!empty($delayedhtmlcontent))
2084
-            print $delayedhtmlcontent;
2199
+        if (!empty($delayedhtmlcontent)) {
2200
+                    print $delayedhtmlcontent;
2201
+        }
2085 2202
 
2086 2203
         if (!empty($conf->use_javascript_ajax)) {
2087 2204
             print "\n" . '<!-- Includes JS Footer of Dolibarr -->' . "\n";
Please login to merge, or discard this patch.
Models/Company.php 1 patch
Braces   +485 added lines, -347 removed lines patch added patch discarded remove patch
@@ -488,8 +488,9 @@  discard block
 block discarded – undo
488 488
         global $langs;
489 489
         global $conf;
490 490
 
491
-        if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email))
492
-            return -1;
491
+        if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) {
492
+                    return -1;
493
+        }
493 494
 
494 495
         $sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.ref_int, s.address, s.datec as date_creation, s.prefix_comm';
495 496
         $sql .= ', s.status';
@@ -526,30 +527,42 @@  discard block
 block discarded – undo
526 527
         $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_incoterms as i ON s.fk_incoterms = i.rowid';
527 528
 
528 529
         $sql .= ' WHERE s.entity IN (' . getEntity($this->element) . ')';
529
-        if ($rowid)
530
-            $sql .= ' AND s.rowid = ' . $rowid;
531
-        if ($ref)
532
-            $sql .= " AND s.nom = '" . $this->db->escape($ref) . "'";
533
-        if ($ref_alias)
534
-            $sql .= " AND s.nom_alias = '" . $this->db->escape($ref_alias) . "'";
535
-        if ($ref_ext)
536
-            $sql .= " AND s.ref_ext = '" . $this->db->escape($ref_ext) . "'";
537
-        if ($ref_int)
538
-            $sql .= " AND s.ref_int = '" . $this->db->escape($ref_int) . "'";
539
-        if ($idprof1)
540
-            $sql .= " AND s.siren = '" . $this->db->escape($idprof1) . "'";
541
-        if ($idprof2)
542
-            $sql .= " AND s.siret = '" . $this->db->escape($idprof2) . "'";
543
-        if ($idprof3)
544
-            $sql .= " AND s.ape = '" . $this->db->escape($idprof3) . "'";
545
-        if ($idprof4)
546
-            $sql .= " AND s.idprof4 = '" . $this->db->escape($idprof4) . "'";
547
-        if ($idprof5)
548
-            $sql .= " AND s.idprof5 = '" . $this->db->escape($idprof5) . "'";
549
-        if ($idprof6)
550
-            $sql .= " AND s.idprof6 = '" . $this->db->escape($idprof6) . "'";
551
-        if ($email)
552
-            $sql .= " AND s.email = '" . $this->db->escape($email) . "'";
530
+        if ($rowid) {
531
+                    $sql .= ' AND s.rowid = ' . $rowid;
532
+        }
533
+        if ($ref) {
534
+                    $sql .= " AND s.nom = '" . $this->db->escape($ref) . "'";
535
+        }
536
+        if ($ref_alias) {
537
+                    $sql .= " AND s.nom_alias = '" . $this->db->escape($ref_alias) . "'";
538
+        }
539
+        if ($ref_ext) {
540
+                    $sql .= " AND s.ref_ext = '" . $this->db->escape($ref_ext) . "'";
541
+        }
542
+        if ($ref_int) {
543
+                    $sql .= " AND s.ref_int = '" . $this->db->escape($ref_int) . "'";
544
+        }
545
+        if ($idprof1) {
546
+                    $sql .= " AND s.siren = '" . $this->db->escape($idprof1) . "'";
547
+        }
548
+        if ($idprof2) {
549
+                    $sql .= " AND s.siret = '" . $this->db->escape($idprof2) . "'";
550
+        }
551
+        if ($idprof3) {
552
+                    $sql .= " AND s.ape = '" . $this->db->escape($idprof3) . "'";
553
+        }
554
+        if ($idprof4) {
555
+                    $sql .= " AND s.idprof4 = '" . $this->db->escape($idprof4) . "'";
556
+        }
557
+        if ($idprof5) {
558
+                    $sql .= " AND s.idprof5 = '" . $this->db->escape($idprof5) . "'";
559
+        }
560
+        if ($idprof6) {
561
+                    $sql .= " AND s.idprof6 = '" . $this->db->escape($idprof6) . "'";
562
+        }
563
+        if ($email) {
564
+                    $sql .= " AND s.email = '" . $this->db->escape($email) . "'";
565
+        }
553 566
 
554 567
         $resql = $this->db->query($sql);
555 568
         if ($resql) {
@@ -700,8 +713,9 @@  discard block
 block discarded – undo
700 713
         }
701 714
 
702 715
         // Use first price level if level not defined for third party
703
-        if (!empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level))
704
-            $this->price_level = 1;
716
+        if (!empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) {
717
+                    $this->price_level = 1;
718
+        }
705 719
 
706 720
         return $result;
707 721
     }
@@ -718,8 +732,9 @@  discard block
 block discarded – undo
718 732
     {
719 733
         global $langs, $conf, $user;
720 734
 
721
-        if (empty($fuser))
722
-            $fuser = $user;
735
+        if (empty($fuser)) {
736
+                    $fuser = $user;
737
+        }
723 738
 
724 739
         require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
725 740
 
@@ -737,8 +752,9 @@  discard block
 block discarded – undo
737 752
             if (!$error && $call_trigger) {
738 753
                 // Call trigger
739 754
                 $result = $this->call_trigger('COMPANY_DELETE', $fuser);
740
-                if ($result < 0)
741
-                    $error++;
755
+                if ($result < 0) {
756
+                                    $error++;
757
+                }
742 758
                 // End call triggers
743 759
             }
744 760
 
@@ -821,8 +837,9 @@  discard block
 block discarded – undo
821 837
                 $this->db->rollback();
822 838
                 return -1;
823 839
             }
824
-        } else
825
-            dol_syslog("Can't remove thirdparty with id " . $id . ". There is " . $objectisused . " childs", LOG_WARNING);
840
+        } else {
841
+                    dol_syslog("Can't remove thirdparty with id " . $id . ". There is " . $objectisused . " childs", LOG_WARNING);
842
+        }
826 843
         return 0;
827 844
     }
828 845
 
@@ -836,8 +853,10 @@  discard block
 block discarded – undo
836 853
         // phpcs:enable
837 854
         if ($this->id) {
838 855
             $newclient = 1;
839
-            if ($this->client == 2 || $this->client == 3)
840
-                $newclient = 3; //If prospect, we keep prospect tag
856
+            if ($this->client == 2 || $this->client == 3) {
857
+                            $newclient = 3;
858
+            }
859
+            //If prospect, we keep prospect tag
841 860
             $sql = "UPDATE " . MAIN_DB_PREFIX . "societe";
842 861
             $sql .= " SET client = " . $newclient;
843 862
             $sql .= " WHERE rowid = " . $this->id;
@@ -846,8 +865,9 @@  discard block
 block discarded – undo
846 865
             if ($resql) {
847 866
                 $this->client = $newclient;
848 867
                 return 1;
849
-            } else
850
-                return -1;
868
+            } else {
869
+                            return -1;
870
+            }
851 871
         }
852 872
         return 0;
853 873
     }
@@ -1023,8 +1043,9 @@  discard block
 block discarded – undo
1023 1043
                 $this->error = $discount->error;
1024 1044
                 return -3;
1025 1045
             }
1026
-        } else
1027
-            return 0;
1046
+        } else {
1047
+                    return 0;
1048
+        }
1028 1049
     }
1029 1050
 
1030 1051
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -1103,17 +1124,21 @@  discard block
 block discarded – undo
1103 1124
     {
1104 1125
         global $conf, $langs, $hookmanager;
1105 1126
 
1106
-        if (!empty($conf->dol_no_mouse_hover))
1107
-            $notooltip = 1;   // Force disable tooltips
1127
+        if (!empty($conf->dol_no_mouse_hover)) {
1128
+                    $notooltip = 1;
1129
+        }
1130
+        // Force disable tooltips
1108 1131
 
1109 1132
         $name = $this->name ? $this->name : $this->nom;
1110 1133
 
1111 1134
         if (!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)) {
1112 1135
 
1113
-            if (empty($option) && $this->client > 0)
1114
-                $option = 'customer';
1115
-            if (empty($option) && $this->fournisseur > 0)
1116
-                $option = 'supplier';
1136
+            if (empty($option) && $this->client > 0) {
1137
+                            $option = 'customer';
1138
+            }
1139
+            if (empty($option) && $this->fournisseur > 0) {
1140
+                            $option = 'supplier';
1141
+            }
1117 1142
         }
1118 1143
 
1119 1144
 
@@ -1138,8 +1163,9 @@  discard block
 block discarded – undo
1138 1163
             }
1139 1164
         }
1140 1165
 
1141
-        if (!empty($this->name_alias))
1142
-            $name .= ' (' . $this->name_alias . ')';
1166
+        if (!empty($this->name_alias)) {
1167
+                    $name .= ' (' . $this->name_alias . ')';
1168
+        }
1143 1169
 
1144 1170
         $result = '';
1145 1171
         $label = '';
@@ -1197,36 +1223,49 @@  discard block
 block discarded – undo
1197 1223
 
1198 1224
         if (!empty($this->name)) {
1199 1225
             $label .= '<br><b>' . $langs->trans('Name') . ':</b> ' . $this->name;
1200
-            if (!empty($this->name_alias))
1201
-                $label .= ' (' . $this->name_alias . ')';
1226
+            if (!empty($this->name_alias)) {
1227
+                            $label .= ' (' . $this->name_alias . ')';
1228
+            }
1202 1229
             $label .= '<br><b>' . $langs->trans('Email') . ':</b> ' . $this->email;
1203 1230
         }
1204
-        if (!empty($this->country_code))
1205
-            $label .= '<br><b>' . $langs->trans('Country') . ':</b> ' . $this->country_code;
1206
-        if (!empty($this->tva_intra) || (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false))
1207
-            $label .= '<br><b>' . $langs->trans('VATIntra') . ':</b> ' . $this->tva_intra;
1231
+        if (!empty($this->country_code)) {
1232
+                    $label .= '<br><b>' . $langs->trans('Country') . ':</b> ' . $this->country_code;
1233
+        }
1234
+        if (!empty($this->tva_intra) || (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false)) {
1235
+                    $label .= '<br><b>' . $langs->trans('VATIntra') . ':</b> ' . $this->tva_intra;
1236
+        }
1208 1237
         if (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP)) {
1209
-            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false)
1210
-                $label .= '<br><b>' . $langs->trans('ProfId1' . $this->country_code) . ':</b> ' . $this->idprof1;
1211
-            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false)
1212
-                $label .= '<br><b>' . $langs->trans('ProfId2' . $this->country_code) . ':</b> ' . $this->idprof2;
1213
-            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false)
1214
-                $label .= '<br><b>' . $langs->trans('ProfId3' . $this->country_code) . ':</b> ' . $this->idprof3;
1215
-            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false)
1216
-                $label .= '<br><b>' . $langs->trans('ProfId4' . $this->country_code) . ':</b> ' . $this->idprof4;
1217
-            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false)
1218
-                $label .= '<br><b>' . $langs->trans('ProfId5' . $this->country_code) . ':</b> ' . $this->idprof5;
1219
-            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false)
1220
-                $label .= '<br><b>' . $langs->trans('ProfId6' . $this->country_code) . ':</b> ' . $this->idprof6;
1221
-        }
1222
-        if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3))
1223
-            $label .= '<br><b>' . $langs->trans('CustomerCode') . ':</b> ' . $this->code_client;
1224
-        if (!empty($this->code_fournisseur) && $this->fournisseur)
1225
-            $label .= '<br><b>' . $langs->trans('SupplierCode') . ':</b> ' . $this->code_fournisseur;
1226
-        if (!empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3))
1227
-            $label .= '<br><b>' . $langs->trans('CustomerAccountancyCode') . ':</b> ' . ($this->code_compta ? $this->code_compta : $this->code_compta_client);
1228
-        if (!empty($conf->accounting->enabled) && $this->fournisseur)
1229
-            $label .= '<br><b>' . $langs->trans('SupplierAccountancyCode') . ':</b> ' . $this->code_compta_fournisseur;
1238
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) {
1239
+                            $label .= '<br><b>' . $langs->trans('ProfId1' . $this->country_code) . ':</b> ' . $this->idprof1;
1240
+            }
1241
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) {
1242
+                            $label .= '<br><b>' . $langs->trans('ProfId2' . $this->country_code) . ':</b> ' . $this->idprof2;
1243
+            }
1244
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) {
1245
+                            $label .= '<br><b>' . $langs->trans('ProfId3' . $this->country_code) . ':</b> ' . $this->idprof3;
1246
+            }
1247
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) {
1248
+                            $label .= '<br><b>' . $langs->trans('ProfId4' . $this->country_code) . ':</b> ' . $this->idprof4;
1249
+            }
1250
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) {
1251
+                            $label .= '<br><b>' . $langs->trans('ProfId5' . $this->country_code) . ':</b> ' . $this->idprof5;
1252
+            }
1253
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) {
1254
+                            $label .= '<br><b>' . $langs->trans('ProfId6' . $this->country_code) . ':</b> ' . $this->idprof6;
1255
+            }
1256
+        }
1257
+        if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) {
1258
+                    $label .= '<br><b>' . $langs->trans('CustomerCode') . ':</b> ' . $this->code_client;
1259
+        }
1260
+        if (!empty($this->code_fournisseur) && $this->fournisseur) {
1261
+                    $label .= '<br><b>' . $langs->trans('SupplierCode') . ':</b> ' . $this->code_fournisseur;
1262
+        }
1263
+        if (!empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3)) {
1264
+                    $label .= '<br><b>' . $langs->trans('CustomerAccountancyCode') . ':</b> ' . ($this->code_compta ? $this->code_compta : $this->code_compta_client);
1265
+        }
1266
+        if (!empty($conf->accounting->enabled) && $this->fournisseur) {
1267
+                    $label .= '<br><b>' . $langs->trans('SupplierAccountancyCode') . ':</b> ' . $this->code_compta_fournisseur;
1268
+        }
1230 1269
 
1231 1270
         $label .= '</div>';
1232 1271
 
@@ -1234,10 +1273,12 @@  discard block
 block discarded – undo
1234 1273
         $linkstart .= (!empty($this->canvas) ? '&canvas=' . $this->canvas : '');
1235 1274
         // Add param to save lastsearch_values or not
1236 1275
         $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1237
-        if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"]))
1238
-            $add_save_lastsearch_values = 1;
1239
-        if ($add_save_lastsearch_values)
1240
-            $linkstart .= '&save_lastsearch_values=1';
1276
+        if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1277
+                    $add_save_lastsearch_values = 1;
1278
+        }
1279
+        if ($add_save_lastsearch_values) {
1280
+                    $linkstart .= '&save_lastsearch_values=1';
1281
+        }
1241 1282
         $linkstart .= '"';
1242 1283
 
1243 1284
         $linkclose = '';
@@ -1266,20 +1307,23 @@  discard block
 block discarded – undo
1266 1307
         }
1267 1308
 
1268 1309
         $result .= $linkstart;
1269
-        if ($withpicto)
1270
-            $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="' . (($withpicto != 2) ? 'paddingright ' : '') . 'classfortooltip valigntextbottom"'), 0, 0, $notooltip ? 0 : 1);
1271
-        if ($withpicto != 2)
1272
-            $result .= ($maxlen ? dol_trunc($name, $maxlen) : $name);
1310
+        if ($withpicto) {
1311
+                    $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="' . (($withpicto != 2) ? 'paddingright ' : '') . 'classfortooltip valigntextbottom"'), 0, 0, $notooltip ? 0 : 1);
1312
+        }
1313
+        if ($withpicto != 2) {
1314
+                    $result .= ($maxlen ? dol_trunc($name, $maxlen) : $name);
1315
+        }
1273 1316
         $result .= $linkend;
1274 1317
 
1275 1318
         global $action;
1276 1319
         $hookmanager->initHooks(array('thirdpartydao'));
1277 1320
         $parameters = array('id' => $this->id, 'getnomurl' => $result);
1278 1321
         $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action);    // Note that $action and $object may have been modified by some hooks
1279
-        if ($reshook > 0)
1280
-            $result = $hookmanager->resPrint;
1281
-        else
1282
-            $result .= $hookmanager->resPrint;
1322
+        if ($reshook > 0) {
1323
+                    $result = $hookmanager->resPrint;
1324
+        } else {
1325
+                    $result .= $hookmanager->resPrint;
1326
+        }
1283 1327
 
1284 1328
         return $result;
1285 1329
     }
@@ -1311,40 +1355,47 @@  discard block
 block discarded – undo
1311 1355
         $langs->load('companies');
1312 1356
 
1313 1357
         if ($mode == 0) {
1314
-            if ($statut == 0)
1315
-                return $langs->trans("ActivityCeased");
1316
-            elseif ($statut == 1)
1317
-                return $langs->trans("InActivity");
1358
+            if ($statut == 0) {
1359
+                            return $langs->trans("ActivityCeased");
1360
+            } elseif ($statut == 1) {
1361
+                            return $langs->trans("InActivity");
1362
+            }
1318 1363
         } elseif ($mode == 1) {
1319
-            if ($statut == 0)
1320
-                return $langs->trans("ActivityCeased");
1321
-            elseif ($statut == 1)
1322
-                return $langs->trans("InActivity");
1364
+            if ($statut == 0) {
1365
+                            return $langs->trans("ActivityCeased");
1366
+            } elseif ($statut == 1) {
1367
+                            return $langs->trans("InActivity");
1368
+            }
1323 1369
         } elseif ($mode == 2) {
1324
-            if ($statut == 0)
1325
-                return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"') . ' ' . $langs->trans("ActivityCeased");
1326
-            elseif ($statut == 1)
1327
-                return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"') . ' ' . $langs->trans("InActivity");
1370
+            if ($statut == 0) {
1371
+                            return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"') . ' ' . $langs->trans("ActivityCeased");
1372
+            } elseif ($statut == 1) {
1373
+                            return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"') . ' ' . $langs->trans("InActivity");
1374
+            }
1328 1375
         } elseif ($mode == 3) {
1329
-            if ($statut == 0)
1330
-                return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"');
1331
-            elseif ($statut == 1)
1332
-                return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"');
1376
+            if ($statut == 0) {
1377
+                            return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"');
1378
+            } elseif ($statut == 1) {
1379
+                            return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"');
1380
+            }
1333 1381
         } elseif ($mode == 4) {
1334
-            if ($statut == 0)
1335
-                return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"') . ' ' . $langs->trans("ActivityCeased");
1336
-            elseif ($statut == 1)
1337
-                return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"') . ' ' . $langs->trans("InActivity");
1382
+            if ($statut == 0) {
1383
+                            return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"') . ' ' . $langs->trans("ActivityCeased");
1384
+            } elseif ($statut == 1) {
1385
+                            return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"') . ' ' . $langs->trans("InActivity");
1386
+            }
1338 1387
         } elseif ($mode == 5) {
1339
-            if ($statut == 0)
1340
-                return '<span class="hideonsmartphone">' . $langs->trans("ActivityCeased") . '</span> ' . img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"');
1341
-            elseif ($statut == 1)
1342
-                return '<span class="hideonsmartphone">' . $langs->trans("InActivity") . '</span> ' . img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"');
1388
+            if ($statut == 0) {
1389
+                            return '<span class="hideonsmartphone">' . $langs->trans("ActivityCeased") . '</span> ' . img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"');
1390
+            } elseif ($statut == 1) {
1391
+                            return '<span class="hideonsmartphone">' . $langs->trans("InActivity") . '</span> ' . img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"');
1392
+            }
1343 1393
         } elseif ($mode == 6) {
1344
-            if ($statut == 0)
1345
-                return '<span class="hideonsmartphone">' . $langs->trans("ActivityCeased") . '</span> ' . img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"');
1346
-            elseif ($statut == 1)
1347
-                return '<span class="hideonsmartphone">' . $langs->trans("InActivity") . '</span> ' . img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"');
1394
+            if ($statut == 0) {
1395
+                            return '<span class="hideonsmartphone">' . $langs->trans("ActivityCeased") . '</span> ' . img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"');
1396
+            } elseif ($statut == 1) {
1397
+                            return '<span class="hideonsmartphone">' . $langs->trans("InActivity") . '</span> ' . img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"');
1398
+            }
1348 1399
         }
1349 1400
     }
1350 1401
 
@@ -1363,8 +1414,9 @@  discard block
 block discarded – undo
1363 1414
 
1364 1415
         $contact_emails = $this->contact_property_array('email', 1);
1365 1416
         if ($this->email && $addthirdparty) {
1366
-            if (empty($this->name))
1367
-                $this->name = $this->nom;
1417
+            if (empty($this->name)) {
1418
+                            $this->name = $this->nom;
1419
+            }
1368 1420
             $contact_emails['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty") . ': ' . dol_trunc($this->name, 16) . " <" . $this->email . ">";
1369 1421
         }
1370 1422
         //var_dump($contact_emails)
@@ -1406,20 +1458,22 @@  discard block
 block discarded – undo
1406 1458
                 $i = 0;
1407 1459
                 while ($i < $nump) {
1408 1460
                     $obj = $this->db->fetch_object($resql);
1409
-                    if ($mode == 'email')
1410
-                        $property = $obj->email;
1411
-                    else if ($mode == 'mobile')
1412
-                        $property = $obj->phone_mobile;
1413
-                    else
1414
-                        $property = $obj->$mode;
1461
+                    if ($mode == 'email') {
1462
+                                            $property = $obj->email;
1463
+                    } else if ($mode == 'mobile') {
1464
+                                            $property = $obj->phone_mobile;
1465
+                    } else {
1466
+                                            $property = $obj->$mode;
1467
+                    }
1415 1468
 
1416 1469
                     // Show all contact. If hidedisabled is 1, showonly contacts with status = 1
1417 1470
                     if ($obj->statut == 1 || empty($hidedisabled)) {
1418 1471
                         if (empty($property)) {
1419
-                            if ($mode == 'email')
1420
-                                $property = $langs->transnoentitiesnoconv("NoEMail");
1421
-                            else if ($mode == 'mobile')
1422
-                                $property = $langs->transnoentitiesnoconv("NoMobilePhone");
1472
+                            if ($mode == 'email') {
1473
+                                                            $property = $langs->transnoentitiesnoconv("NoEMail");
1474
+                            } else if ($mode == 'mobile') {
1475
+                                                            $property = $langs->transnoentitiesnoconv("NoMobilePhone");
1476
+                            }
1423 1477
                         }
1424 1478
 
1425 1479
                         if (!empty($obj->poste)) {
@@ -1450,8 +1504,9 @@  discard block
 block discarded – undo
1450 1504
         $contact_phone = $this->contact_property_array('mobile');
1451 1505
 
1452 1506
         if (!empty($this->phone)) { // If a phone of thirdparty is defined, we add it ot mobile of contacts
1453
-            if (empty($this->name))
1454
-                $this->name = $this->nom;
1507
+            if (empty($this->name)) {
1508
+                            $this->name = $this->nom;
1509
+            }
1455 1510
             // TODO: Tester si tel non deja present dans tableau contact
1456 1511
             $contact_phone['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty") . ': ' . dol_trunc($this->name, 16) . " <" . $this->phone . ">";
1457 1512
         }
@@ -1533,8 +1588,9 @@  discard block
 block discarded – undo
1533 1588
         // phpcs:enable
1534 1589
         $contact_property = '';
1535 1590
 
1536
-        if (empty($rowid))
1537
-            return '';
1591
+        if (empty($rowid)) {
1592
+                    return '';
1593
+        }
1538 1594
 
1539 1595
         $sql = "SELECT rowid, email, phone_mobile, lastname, firstname";
1540 1596
         $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople";
@@ -1547,10 +1603,11 @@  discard block
 block discarded – undo
1547 1603
             if ($nump) {
1548 1604
                 $obj = $this->db->fetch_object($resql);
1549 1605
 
1550
-                if ($mode == 'email')
1551
-                    $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(",")) . " <" . $obj->email . ">";
1552
-                else if ($mode == 'mobile')
1553
-                    $contact_property = $obj->phone_mobile;
1606
+                if ($mode == 'email') {
1607
+                                    $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(",")) . " <" . $obj->email . ">";
1608
+                } else if ($mode == 'mobile') {
1609
+                                    $contact_property = $obj->phone_mobile;
1610
+                }
1554 1611
             }
1555 1612
             return $contact_property;
1556 1613
         } else {
@@ -1640,19 +1697,24 @@  discard block
 block discarded – undo
1640 1697
             $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1641 1698
             foreach ($dirsociete as $dirroot) {
1642 1699
                 $res = dol_include_once($dirroot . $module . '.php');
1643
-                if ($res)
1644
-                    break;
1700
+                if ($res) {
1701
+                                    break;
1702
+                }
1645 1703
             }
1646 1704
 
1647 1705
             $mod = new $module();
1648 1706
 
1649 1707
             dol_syslog(get_class($this) . "::codeclient_modifiable code_client=" . $this->code_client . " module=" . $module);
1650
-            if ($mod->code_modifiable_null && !$this->code_client)
1651
-                return 1;
1652
-            if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0)
1653
-                return 1;
1654
-            if ($mod->code_modifiable)
1655
-                return 1; // A mettre en dernier
1708
+            if ($mod->code_modifiable_null && !$this->code_client) {
1709
+                            return 1;
1710
+            }
1711
+            if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) {
1712
+                            return 1;
1713
+            }
1714
+            if ($mod->code_modifiable) {
1715
+                            return 1;
1716
+            }
1717
+            // A mettre en dernier
1656 1718
             return 0;
1657 1719
         } else {
1658 1720
             return 0;
@@ -1680,8 +1742,9 @@  discard block
 block discarded – undo
1680 1742
             $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1681 1743
             foreach ($dirsociete as $dirroot) {
1682 1744
                 $res = dol_include_once($dirroot . $module . '.php');
1683
-                if ($res)
1684
-                    break;
1745
+                if ($res) {
1746
+                                    break;
1747
+                }
1685 1748
             }
1686 1749
 
1687 1750
             $mod = new $module();
@@ -1711,19 +1774,24 @@  discard block
 block discarded – undo
1711 1774
             $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1712 1775
             foreach ($dirsociete as $dirroot) {
1713 1776
                 $res = dol_include_once($dirroot . $module . '.php');
1714
-                if ($res)
1715
-                    break;
1777
+                if ($res) {
1778
+                                    break;
1779
+                }
1716 1780
             }
1717 1781
 
1718 1782
             $mod = new $module();
1719 1783
 
1720 1784
             dol_syslog(get_class($this) . "::codefournisseur_modifiable code_founisseur=" . $this->code_fournisseur . " module=" . $module);
1721
-            if ($mod->code_modifiable_null && !$this->code_fournisseur)
1722
-                return 1;
1723
-            if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0)
1724
-                return 1;
1725
-            if ($mod->code_modifiable)
1726
-                return 1; // A mettre en dernier
1785
+            if ($mod->code_modifiable_null && !$this->code_fournisseur) {
1786
+                            return 1;
1787
+            }
1788
+            if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) {
1789
+                            return 1;
1790
+            }
1791
+            if ($mod->code_modifiable) {
1792
+                            return 1;
1793
+            }
1794
+            // A mettre en dernier
1727 1795
             return 0;
1728 1796
         } else {
1729 1797
             return 0;
@@ -1751,8 +1819,9 @@  discard block
 block discarded – undo
1751 1819
             $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
1752 1820
             foreach ($dirsociete as $dirroot) {
1753 1821
                 $res = dol_include_once($dirroot . $module . '.php');
1754
-                if ($res)
1755
-                    break;
1822
+                if ($res) {
1823
+                                    break;
1824
+                }
1756 1825
             }
1757 1826
 
1758 1827
             $mod = new $module();
@@ -1788,8 +1857,9 @@  discard block
 block discarded – undo
1788 1857
             } else {
1789 1858
                 return -1;
1790 1859
             }
1791
-        } else
1792
-            return -1;
1860
+        } else {
1861
+                    return -1;
1862
+        }
1793 1863
     }
1794 1864
 
1795 1865
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -1809,18 +1879,21 @@  discard block
 block discarded – undo
1809 1879
 
1810 1880
         $ok = 1;
1811 1881
 
1812
-        if (!empty($conf->global->MAIN_DISABLEPROFIDRULES))
1813
-            return 1;
1882
+        if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
1883
+                    return 1;
1884
+        }
1814 1885
 
1815 1886
         // Verifie SIREN si pays FR
1816 1887
         if ($idprof == 1 && $soc->country_code == 'FR') {
1817 1888
             $chaine = trim($this->idprof1);
1818 1889
             $chaine = preg_replace('/(\s)/', '', $chaine);
1819 1890
 
1820
-            if (!is_numeric($chaine))
1821
-                return -1;
1822
-            if (dol_strlen($chaine) != 9)
1823
-                return -1;
1891
+            if (!is_numeric($chaine)) {
1892
+                            return -1;
1893
+            }
1894
+            if (dol_strlen($chaine) != 9) {
1895
+                            return -1;
1896
+            }
1824 1897
 
1825 1898
             // on prend chaque chiffre un par un
1826 1899
             // si son index (position dans la chaîne en commence à 0 au premier caractère) est impair
@@ -1830,15 +1903,17 @@  discard block
 block discarded – undo
1830 1903
             for ($index = 0; $index < 9; $index++) {
1831 1904
                 $number = (int)$siren[$index];
1832 1905
                 if (($index % 2) != 0) {
1833
-                    if (($number *= 2) > 9)
1834
-                        $number -= 9;
1906
+                    if (($number *= 2) > 9) {
1907
+                                            $number -= 9;
1908
+                    }
1835 1909
                 }
1836 1910
                 $sum += $number;
1837 1911
             }
1838 1912
 
1839 1913
             // le numéro est valide si la somme des chiffres est multiple de 10
1840
-            if (($sum % 10) != 0)
1841
-                return -1;
1914
+            if (($sum % 10) != 0) {
1915
+                            return -1;
1916
+            }
1842 1917
         }
1843 1918
 
1844 1919
         // Verifie SIRET si pays FR
@@ -1846,10 +1921,12 @@  discard block
 block discarded – undo
1846 1921
             $chaine = trim($this->idprof2);
1847 1922
             $chaine = preg_replace('/(\s)/', '', $chaine);
1848 1923
 
1849
-            if (!is_numeric($chaine))
1850
-                return -1;
1851
-            if (dol_strlen($chaine) != 14)
1852
-                return -1;
1924
+            if (!is_numeric($chaine)) {
1925
+                            return -1;
1926
+            }
1927
+            if (dol_strlen($chaine) != 14) {
1928
+                            return -1;
1929
+            }
1853 1930
 
1854 1931
             // on prend chaque chiffre un par un
1855 1932
             // si son index (position dans la chaîne en commence à 0 au premier caractère) est pair
@@ -1859,15 +1936,17 @@  discard block
 block discarded – undo
1859 1936
             for ($index = 0; $index < 14; $index++) {
1860 1937
                 $number = (int)$chaine[$index];
1861 1938
                 if (($index % 2) == 0) {
1862
-                    if (($number *= 2) > 9)
1863
-                        $number -= 9;
1939
+                    if (($number *= 2) > 9) {
1940
+                                            $number -= 9;
1941
+                    }
1864 1942
                 }
1865 1943
                 $sum += $number;
1866 1944
             }
1867 1945
 
1868 1946
             // le numéro est valide si la somme des chiffres est multiple de 10
1869
-            if (($sum % 10) != 0)
1870
-                return -1;
1947
+            if (($sum % 10) != 0) {
1948
+                            return -1;
1949
+            }
1871 1950
         }
1872 1951
 
1873 1952
         //Verify CIF/NIF/NIE if pays ES
@@ -1877,53 +1956,61 @@  discard block
 block discarded – undo
1877 1956
             $string = preg_replace('/(\s)/', '', $string);
1878 1957
             $string = strtoupper($string);
1879 1958
 
1880
-            for ($i = 0; $i < 9; $i++)
1881
-                $num[$i] = substr($string, $i, 1);
1959
+            for ($i = 0; $i < 9; $i++) {
1960
+                            $num[$i] = substr($string, $i, 1);
1961
+            }
1882 1962
 
1883 1963
             //Check format
1884
-            if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string))
1885
-                return 0;
1964
+            if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string)) {
1965
+                            return 0;
1966
+            }
1886 1967
 
1887 1968
             //Check NIF
1888
-            if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string))
1889
-                if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1))
1969
+            if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string)) {
1970
+                            if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1))
1890 1971
                     return 1;
1891
-                else
1892
-                    return -1;
1972
+            } else {
1973
+                                    return -1;
1974
+                }
1893 1975
 
1894 1976
             //algorithm checking type code CIF
1895 1977
             $sum = $num[2] + $num[4] + $num[6];
1896
-            for ($i = 1; $i < 8; $i += 2)
1897
-                $sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1));
1978
+            for ($i = 1; $i < 8; $i += 2) {
1979
+                            $sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1));
1980
+            }
1898 1981
             $n = 10 - substr($sum, strlen($sum) - 1, 1);
1899 1982
 
1900 1983
             //Chek special NIF
1901
-            if (preg_match('/^[KLM]{1}/', $string))
1902
-                if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1))
1984
+            if (preg_match('/^[KLM]{1}/', $string)) {
1985
+                            if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1))
1903 1986
                     return 1;
1904
-                else
1905
-                    return -1;
1987
+            } else {
1988
+                                    return -1;
1989
+                }
1906 1990
 
1907 1991
             //Check CIF
1908
-            if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string))
1909
-                if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1))
1992
+            if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) {
1993
+                            if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1))
1910 1994
                     return 2;
1911
-                else
1912
-                    return -2;
1995
+            } else {
1996
+                                    return -2;
1997
+                }
1913 1998
 
1914 1999
             //Check NIE T
1915
-            if (preg_match('/^[T]{1}/', $string))
1916
-                if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string))
2000
+            if (preg_match('/^[T]{1}/', $string)) {
2001
+                            if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string))
1917 2002
                     return 3;
1918
-                else
1919
-                    return -3;
2003
+            } else {
2004
+                                    return -3;
2005
+                }
1920 2006
 
1921 2007
             //Check NIE XYZ
1922
-            if (preg_match('/^[XYZ]{1}/', $string))
1923
-                if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X', 'Y', 'Z'), array('0', '1', '2'), $string), 0, 8) % 23, 1))
2008
+            if (preg_match('/^[XYZ]{1}/', $string)) {
2009
+                            if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X', 'Y', 'Z'), array('0', '1', '2'), $string), 0, 8) % 23, 1))
1924 2010
                     return 3;
1925
-                else
1926
-                    return -3;
2011
+            } else {
2012
+                                    return -3;
2013
+                }
1927 2014
 
1928 2015
             //Can not be verified
1929 2016
             return -4;
@@ -2126,8 +2213,9 @@  discard block
 block discarded – undo
2126 2213
             $sql = "INSERT INTO " . MAIN_DB_PREFIX . "categorie_fournisseur (fk_categorie, fk_soc) ";
2127 2214
             $sql .= " VALUES (" . $categorie_id . ", " . $this->id . ")";
2128 2215
 
2129
-            if ($resql = $this->db->query($sql))
2130
-                return 0;
2216
+            if ($resql = $this->db->query($sql)) {
2217
+                            return 0;
2218
+            }
2131 2219
         } else {
2132 2220
             return 0;
2133 2221
         }
@@ -2153,8 +2241,9 @@  discard block
 block discarded – undo
2153 2241
         dol_syslog(get_class($this) . "::create_from_member", LOG_DEBUG);
2154 2242
 
2155 2243
         $name = $socname ? $socname : $member->societe;
2156
-        if (empty($name))
2157
-            $name = $member->getFullName($langs);
2244
+        if (empty($name)) {
2245
+                    $name = $member->getFullName($langs);
2246
+        }
2158 2247
 
2159 2248
         $alias = $socalias ? $socalias : '';
2160 2249
 
@@ -2300,11 +2389,13 @@  discard block
 block discarded – undo
2300 2389
                 if ($ret >= 0) {
2301 2390
                     // Call trigger
2302 2391
                     $result = $this->call_trigger('COMPANY_CREATE', $user);
2303
-                    if ($result < 0)
2304
-                        $error++;
2392
+                    if ($result < 0) {
2393
+                                            $error++;
2394
+                    }
2305 2395
                     // End call triggers
2306
-                } else
2307
-                    $error++;
2396
+                } else {
2397
+                                    $error++;
2398
+                }
2308 2399
 
2309 2400
                 if (!$error) {
2310 2401
                     dol_syslog(get_class($this) . "::Create success id=" . $this->id);
@@ -2353,8 +2444,9 @@  discard block
 block discarded – undo
2353 2444
             $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2354 2445
             foreach ($dirsociete as $dirroot) {
2355 2446
                 $res = dol_include_once($dirroot . $module . '.php');
2356
-                if ($res)
2357
-                    break;
2447
+                if ($res) {
2448
+                                    break;
2449
+                }
2358 2450
             }
2359 2451
             $mod = new $module();
2360 2452
 
@@ -2385,8 +2477,9 @@  discard block
 block discarded – undo
2385 2477
             $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2386 2478
             foreach ($dirsociete as $dirroot) {
2387 2479
                 $res = dol_include_once($dirroot . $module . '.php');
2388
-                if ($res)
2389
-                    break;
2480
+                if ($res) {
2481
+                                    break;
2482
+                }
2390 2483
             }
2391 2484
             $mod = new $module();
2392 2485
 
@@ -2503,8 +2596,9 @@  discard block
 block discarded – undo
2503 2596
             }
2504 2597
         }
2505 2598
 
2506
-        if ($error)
2507
-            $result = -4;
2599
+        if ($error) {
2600
+                    $result = -4;
2601
+        }
2508 2602
 
2509 2603
         return $result;
2510 2604
     }
@@ -2522,14 +2616,15 @@  discard block
 block discarded – undo
2522 2616
 
2523 2617
         // Define if third party is treated as company (or not) when nature is unknown
2524 2618
         $isacompany = empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES) ? 0 : 1; // 0 by default
2525
-        if (!empty($this->tva_intra))
2526
-            $isacompany = 1;
2527
-        else if (!empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN') {
2619
+        if (!empty($this->tva_intra)) {
2620
+                    $isacompany = 1;
2621
+        } else if (!empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN') {
2528 2622
             // TODO Add a field is_a_company into dictionary
2529
-            if (preg_match('/^TE_PRIVATE/', $this->typent_code))
2530
-                $isacompany = 0;
2531
-            else
2532
-                $isacompany = 1;
2623
+            if (preg_match('/^TE_PRIVATE/', $this->typent_code)) {
2624
+                            $isacompany = 0;
2625
+            } else {
2626
+                            $isacompany = 1;
2627
+            }
2533 2628
         }
2534 2629
 
2535 2630
         return $isacompany;
@@ -2612,8 +2707,9 @@  discard block
 block discarded – undo
2612 2707
 
2613 2708
         //Verify duplicate entries
2614 2709
         $sql = "SELECT COUNT(*) as idprof FROM " . MAIN_DB_PREFIX . "societe WHERE " . $field . " = '" . $value . "' AND entity IN (" . getEntity('societe') . ")";
2615
-        if ($socid)
2616
-            $sql .= " AND rowid <> " . $socid;
2710
+        if ($socid) {
2711
+                    $sql .= " AND rowid <> " . $socid;
2712
+        }
2617 2713
         $resql = $this->db->query($sql);
2618 2714
         if ($resql) {
2619 2715
             $obj = $this->db->fetch_object($resql);
@@ -2624,10 +2720,11 @@  discard block
 block discarded – undo
2624 2720
         }
2625 2721
         $this->db->free($resql);
2626 2722
 
2627
-        if ($count > 0)
2628
-            return true;
2629
-        else
2630
-            return false;
2723
+        if ($count > 0) {
2724
+                    return true;
2725
+        } else {
2726
+                    return false;
2727
+        }
2631 2728
     }
2632 2729
 
2633 2730
     /**
@@ -2648,8 +2745,9 @@  discard block
 block discarded – undo
2648 2745
 
2649 2746
         require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
2650 2747
 
2651
-        if (empty($id))
2652
-            $id = $this->id;
2748
+        if (empty($id)) {
2749
+                    $id = $this->id;
2750
+        }
2653 2751
 
2654 2752
         $error = 0;
2655 2753
 
@@ -2695,11 +2793,13 @@  discard block
 block discarded – undo
2695 2793
 
2696 2794
         $this->tva_assuj = trim($this->tva_assuj);
2697 2795
         $this->tva_intra = dol_sanitizeFileName($this->tva_intra, '');
2698
-        if (empty($this->status))
2699
-            $this->status = 0;
2796
+        if (empty($this->status)) {
2797
+                    $this->status = 0;
2798
+        }
2700 2799
 
2701
-        if (!empty($this->multicurrency_code))
2702
-            $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
2800
+        if (!empty($this->multicurrency_code)) {
2801
+                    $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
2802
+        }
2703 2803
         if (empty($this->fk_multicurrency)) {
2704 2804
             $this->multicurrency_code = '';
2705 2805
             $this->fk_multicurrency = 0;
@@ -2712,10 +2812,13 @@  discard block
 block discarded – undo
2712 2812
         $this->localtax1_value = trim($this->localtax1_value);
2713 2813
         $this->localtax2_value = trim($this->localtax2_value);
2714 2814
 
2715
-        if ($this->capital != '')
2716
-            $this->capital = price2num(trim($this->capital));
2717
-        if (!is_numeric($this->capital))
2718
-            $this->capital = '';     // '' = undef
2815
+        if ($this->capital != '') {
2816
+                    $this->capital = price2num(trim($this->capital));
2817
+        }
2818
+        if (!is_numeric($this->capital)) {
2819
+                    $this->capital = '';
2820
+        }
2821
+        // '' = undef
2719 2822
 
2720 2823
         $this->effectif_id = trim($this->effectif_id);
2721 2824
         $this->forme_juridique_code = trim($this->forme_juridique_code);
@@ -2724,10 +2827,12 @@  discard block
 block discarded – undo
2724 2827
         $this->barcode = trim($this->barcode);
2725 2828
 
2726 2829
         // For automatic creation
2727
-        if ($this->code_client == -1 || $this->code_client === 'auto')
2728
-            $this->get_codeclient($this, 0);
2729
-        if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto')
2730
-            $this->get_codefournisseur($this, 1);
2830
+        if ($this->code_client == -1 || $this->code_client === 'auto') {
2831
+                    $this->get_codeclient($this, 0);
2832
+        }
2833
+        if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') {
2834
+                    $this->get_codefournisseur($this, 1);
2835
+        }
2731 2836
 
2732 2837
         $this->code_compta = trim($this->code_compta);
2733 2838
         $this->code_compta_fournisseur = trim($this->code_compta_fournisseur);
@@ -2744,8 +2849,9 @@  discard block
 block discarded – undo
2744 2849
             // Attention get_codecompta peut modifier le code suivant le module utilise
2745 2850
             if (empty($this->code_compta)) {
2746 2851
                 $ret = $this->get_codecompta('customer');
2747
-                if ($ret < 0)
2748
-                    return -1;
2852
+                if ($ret < 0) {
2853
+                                    return -1;
2854
+                }
2749 2855
             }
2750 2856
 
2751 2857
             $customer = true;
@@ -2756,8 +2862,9 @@  discard block
 block discarded – undo
2756 2862
             // Attention get_codecompta peut modifier le code suivant le module utilise
2757 2863
             if (empty($this->code_compta_fournisseur)) {
2758 2864
                 $ret = $this->get_codecompta('supplier');
2759
-                if ($ret < 0)
2760
-                    return -1;
2865
+                if ($ret < 0) {
2866
+                                    return -1;
2867
+                }
2761 2868
             }
2762 2869
 
2763 2870
             $supplier = true;
@@ -2785,12 +2892,16 @@  discard block
 block discarded – undo
2785 2892
             // So we can update record that were using and old numbering rule.
2786 2893
             if (is_array($this->errors)) {
2787 2894
                 if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) {
2788
-                    if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false)
2789
-                        unset($this->errors[$key]); // Remove error message
2895
+                    if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) {
2896
+                                            unset($this->errors[$key]);
2897
+                    }
2898
+                    // Remove error message
2790 2899
                 }
2791 2900
                 if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) {
2792
-                    if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false)
2793
-                        unset($this->errors[$key]); // Remove error message
2901
+                    if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) {
2902
+                                            unset($this->errors[$key]);
2903
+                    }
2904
+                    // Remove error message
2794 2905
                 }
2795 2906
                 if (empty($this->errors)) { // If there is no more error, we can make like if there is no error at all
2796 2907
                     $result = 0;
@@ -2844,18 +2955,22 @@  discard block
 block discarded – undo
2844 2955
             if ($this->localtax1_assuj == 1) {
2845 2956
                 if ($this->localtax1_value != '') {
2846 2957
                     $sql .= ",localtax1_value =" . $this->localtax1_value;
2847
-                } else
2848
-                    $sql .= ",localtax1_value =0.000";
2849
-            } else
2850
-                $sql .= ",localtax1_value =0.000";
2958
+                } else {
2959
+                                    $sql .= ",localtax1_value =0.000";
2960
+                }
2961
+            } else {
2962
+                            $sql .= ",localtax1_value =0.000";
2963
+            }
2851 2964
 
2852 2965
             if ($this->localtax2_assuj == 1) {
2853 2966
                 if ($this->localtax2_value != '') {
2854 2967
                     $sql .= ",localtax2_value =" . $this->localtax2_value;
2855
-                } else
2856
-                    $sql .= ",localtax2_value =0.000";
2857
-            } else
2858
-                $sql .= ",localtax2_value =0.000";
2968
+                } else {
2969
+                                    $sql .= ",localtax2_value =0.000";
2970
+                }
2971
+            } else {
2972
+                            $sql .= ",localtax2_value =0.000";
2973
+            }
2859 2974
 
2860 2975
             $sql .= ",capital = " . ($this->capital == '' ? "null" : $this->capital);
2861 2976
 
@@ -2973,8 +3088,9 @@  discard block
 block discarded – undo
2973 3088
                 if (!$error && $call_trigger) {
2974 3089
                     // Call trigger
2975 3090
                     $result = $this->call_trigger('COMPANY_MODIFY', $user);
2976
-                    if ($result < 0)
2977
-                        $error++;
3091
+                    if ($result < 0) {
3092
+                                            $error++;
3093
+                    }
2978 3094
                     // End call triggers
2979 3095
                 }
2980 3096
 
@@ -3025,8 +3141,9 @@  discard block
 block discarded – undo
3025 3141
             $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
3026 3142
             foreach ($dirsociete as $dirroot) {
3027 3143
                 $res = dol_include_once($dirroot . $conf->global->SOCIETE_CODECOMPTA_ADDON . '.php');
3028
-                if ($res)
3029
-                    break;
3144
+                if ($res) {
3145
+                                    break;
3146
+                }
3030 3147
             }
3031 3148
 
3032 3149
             if ($res) {
@@ -3036,10 +3153,11 @@  discard block
 block discarded – undo
3036 3153
                 // Defini code compta dans $mod->code
3037 3154
                 $result = $mod->get_code($this->db, $this, $type);
3038 3155
 
3039
-                if ($type == 'customer')
3040
-                    $this->code_compta = $mod->code;
3041
-                else if ($type == 'supplier')
3042
-                    $this->code_compta_fournisseur = $mod->code;
3156
+                if ($type == 'customer') {
3157
+                                    $this->code_compta = $mod->code;
3158
+                } else if ($type == 'supplier') {
3159
+                                    $this->code_compta_fournisseur = $mod->code;
3160
+                }
3043 3161
 
3044 3162
                 return $result;
3045 3163
             } else {
@@ -3047,10 +3165,11 @@  discard block
 block discarded – undo
3047 3165
                 return -1;
3048 3166
             }
3049 3167
         } else {
3050
-            if ($type == 'customer')
3051
-                $this->code_compta = '';
3052
-            else if ($type == 'supplier')
3053
-                $this->code_compta_fournisseur = '';
3168
+            if ($type == 'customer') {
3169
+                            $this->code_compta = '';
3170
+            } else if ($type == 'supplier') {
3171
+                            $this->code_compta_fournisseur = '';
3172
+            }
3054 3173
 
3055 3174
             return 0;
3056 3175
         }
@@ -3087,8 +3206,9 @@  discard block
 block discarded – undo
3087 3206
                 $this->context = array('commercial_modified' => $commid);
3088 3207
 
3089 3208
                 $result = $this->call_trigger('COMPANY_LINK_SALE_REPRESENTATIVE', $user);
3090
-                if ($result < 0)
3091
-                    $error++;
3209
+                if ($result < 0) {
3210
+                                    $error++;
3211
+                }
3092 3212
             }
3093 3213
         }
3094 3214
     }
@@ -3135,8 +3255,9 @@  discard block
 block discarded – undo
3135 3255
         $this->country_id = $country_id;
3136 3256
         $this->country_code = $country_code;
3137 3257
         $this->country = $country_label;
3138
-        if (is_object($langs))
3139
-            $this->country = ($langs->trans('Country' . $country_code) != 'Country' . $country_code) ? $langs->trans('Country' . $country_code) : $country_label;
3258
+        if (is_object($langs)) {
3259
+                    $this->country = ($langs->trans('Country' . $country_code) != 'Country' . $country_code) ? $langs->trans('Country' . $country_code) : $country_label;
3260
+        }
3140 3261
 
3141 3262
         $this->phone = empty($conf->global->MAIN_INFO_SOCIETE_TEL) ? '' : $conf->global->MAIN_INFO_SOCIETE_TEL;
3142 3263
         $this->fax = empty($conf->global->MAIN_INFO_SOCIETE_FAX) ? '' : $conf->global->MAIN_INFO_SOCIETE_FAX;
@@ -3230,19 +3351,21 @@  discard block
 block discarded – undo
3230 3351
         $sql .= " FROM " . MAIN_DB_PREFIX . "c_tva as t, " . MAIN_DB_PREFIX . "c_country as c";
3231 3352
         $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '" . $this->db->escape($this->country_code) . "'";
3232 3353
         $sql .= " AND t.active = 1";
3233
-        if (empty($localTaxNum))
3234
-            $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
3235
-        elseif ($localTaxNum == 1)
3236
-            $sql .= " AND t.localtax1_type <> '0'";
3237
-        elseif ($localTaxNum == 2)
3238
-            $sql .= " AND t.localtax2_type <> '0'";
3354
+        if (empty($localTaxNum)) {
3355
+                    $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
3356
+        } elseif ($localTaxNum == 1) {
3357
+                    $sql .= " AND t.localtax1_type <> '0'";
3358
+        } elseif ($localTaxNum == 2) {
3359
+                    $sql .= " AND t.localtax2_type <> '0'";
3360
+        }
3239 3361
 
3240 3362
         dol_syslog("useLocalTax", LOG_DEBUG);
3241 3363
         $resql = $this->db->query($sql);
3242 3364
         if ($resql) {
3243 3365
             return ($this->db->num_rows($resql) > 0);
3244
-        } else
3245
-            return false;
3366
+        } else {
3367
+                    return false;
3368
+        }
3246 3369
     }
3247 3370
 
3248 3371
     /**
@@ -3261,8 +3384,9 @@  discard block
 block discarded – undo
3261 3384
         $resql = $this->db->query($sql);
3262 3385
         if ($resql) {
3263 3386
             return ($this->db->num_rows($resql) > 0);
3264
-        } else
3265
-            return false;
3387
+        } else {
3388
+                    return false;
3389
+        }
3266 3390
     }
3267 3391
 
3268 3392
     /**
@@ -3361,47 +3485,47 @@  discard block
 block discarded – undo
3361 3485
         $langs->load('customers');
3362 3486
 
3363 3487
         if ($mode == 2) {
3364
-            if ($statut == '-1' || $statut == 'ST_NO')
3365
-                return img_action($langs->trans("StatusProspect-1"), -1) . ' ' . $langs->trans("StatusProspect-1");
3366
-            elseif ($statut == '0' || $statut == 'ST_NEVER')
3367
-                return img_action($langs->trans("StatusProspect0"), 0) . ' ' . $langs->trans("StatusProspect0");
3368
-            elseif ($statut == '1' || $statut == 'ST_TODO')
3369
-                return img_action($langs->trans("StatusProspect1"), 1) . ' ' . $langs->trans("StatusProspect1");
3370
-            elseif ($statut == '2' || $statut == 'ST_PEND')
3371
-                return img_action($langs->trans("StatusProspect2"), 2) . ' ' . $langs->trans("StatusProspect2");
3372
-            elseif ($statut == '3' || $statut == 'ST_DONE')
3373
-                return img_action($langs->trans("StatusProspect3"), 3) . ' ' . $langs->trans("StatusProspect3");
3374
-            else {
3488
+            if ($statut == '-1' || $statut == 'ST_NO') {
3489
+                            return img_action($langs->trans("StatusProspect-1"), -1) . ' ' . $langs->trans("StatusProspect-1");
3490
+            } elseif ($statut == '0' || $statut == 'ST_NEVER') {
3491
+                            return img_action($langs->trans("StatusProspect0"), 0) . ' ' . $langs->trans("StatusProspect0");
3492
+            } elseif ($statut == '1' || $statut == 'ST_TODO') {
3493
+                            return img_action($langs->trans("StatusProspect1"), 1) . ' ' . $langs->trans("StatusProspect1");
3494
+            } elseif ($statut == '2' || $statut == 'ST_PEND') {
3495
+                            return img_action($langs->trans("StatusProspect2"), 2) . ' ' . $langs->trans("StatusProspect2");
3496
+            } elseif ($statut == '3' || $statut == 'ST_DONE') {
3497
+                            return img_action($langs->trans("StatusProspect3"), 3) . ' ' . $langs->trans("StatusProspect3");
3498
+            } else {
3375 3499
                 return img_action(($langs->trans("StatusProspect" . $statut) != "StatusProspect" . $statut) ? $langs->trans("StatusProspect" . $statut) : $label, 0) . ' ' . (($langs->trans("StatusProspect" . $statut) != "StatusProspect" . $statut) ? $langs->trans("StatusProspect" . $statut) : $label);
3376 3500
             }
3377 3501
         }
3378 3502
         if ($mode == 3) {
3379
-            if ($statut == '-1' || $statut == 'ST_NO')
3380
-                return img_action($langs->trans("StatusProspect-1"), -1);
3381
-            elseif ($statut == '0' || $statut == 'ST_NEVER')
3382
-                return img_action($langs->trans("StatusProspect0"), 0);
3383
-            elseif ($statut == '1' || $statut == 'ST_TODO')
3384
-                return img_action($langs->trans("StatusProspect1"), 1);
3385
-            elseif ($statut == '2' || $statut == 'ST_PEND')
3386
-                return img_action($langs->trans("StatusProspect2"), 2);
3387
-            elseif ($statut == '3' || $statut == 'ST_DONE')
3388
-                return img_action($langs->trans("StatusProspect3"), 3);
3389
-            else {
3503
+            if ($statut == '-1' || $statut == 'ST_NO') {
3504
+                            return img_action($langs->trans("StatusProspect-1"), -1);
3505
+            } elseif ($statut == '0' || $statut == 'ST_NEVER') {
3506
+                            return img_action($langs->trans("StatusProspect0"), 0);
3507
+            } elseif ($statut == '1' || $statut == 'ST_TODO') {
3508
+                            return img_action($langs->trans("StatusProspect1"), 1);
3509
+            } elseif ($statut == '2' || $statut == 'ST_PEND') {
3510
+                            return img_action($langs->trans("StatusProspect2"), 2);
3511
+            } elseif ($statut == '3' || $statut == 'ST_DONE') {
3512
+                            return img_action($langs->trans("StatusProspect3"), 3);
3513
+            } else {
3390 3514
                 return img_action(($langs->trans("StatusProspect" . $statut) != "StatusProspect" . $statut) ? $langs->trans("StatusProspect" . $statut) : $label, 0);
3391 3515
             }
3392 3516
         }
3393 3517
         if ($mode == 4) {
3394
-            if ($statut == '-1' || $statut == 'ST_NO')
3395
-                return img_action($langs->trans("StatusProspect-1"), -1) . ' ' . $langs->trans("StatusProspect-1");
3396
-            elseif ($statut == '0' || $statut == 'ST_NEVER')
3397
-                return img_action($langs->trans("StatusProspect0"), 0) . ' ' . $langs->trans("StatusProspect0");
3398
-            elseif ($statut == '1' || $statut == 'ST_TODO')
3399
-                return img_action($langs->trans("StatusProspect1"), 1) . ' ' . $langs->trans("StatusProspect1");
3400
-            elseif ($statut == '2' || $statut == 'ST_PEND')
3401
-                return img_action($langs->trans("StatusProspect2"), 2) . ' ' . $langs->trans("StatusProspect2");
3402
-            elseif ($statut == '3' || $statut == 'ST_DONE')
3403
-                return img_action($langs->trans("StatusProspect3"), 3) . ' ' . $langs->trans("StatusProspect3");
3404
-            else {
3518
+            if ($statut == '-1' || $statut == 'ST_NO') {
3519
+                            return img_action($langs->trans("StatusProspect-1"), -1) . ' ' . $langs->trans("StatusProspect-1");
3520
+            } elseif ($statut == '0' || $statut == 'ST_NEVER') {
3521
+                            return img_action($langs->trans("StatusProspect0"), 0) . ' ' . $langs->trans("StatusProspect0");
3522
+            } elseif ($statut == '1' || $statut == 'ST_TODO') {
3523
+                            return img_action($langs->trans("StatusProspect1"), 1) . ' ' . $langs->trans("StatusProspect1");
3524
+            } elseif ($statut == '2' || $statut == 'ST_PEND') {
3525
+                            return img_action($langs->trans("StatusProspect2"), 2) . ' ' . $langs->trans("StatusProspect2");
3526
+            } elseif ($statut == '3' || $statut == 'ST_DONE') {
3527
+                            return img_action($langs->trans("StatusProspect3"), 3) . ' ' . $langs->trans("StatusProspect3");
3528
+            } else {
3405 3529
                 return img_action(($langs->trans("StatusProspect" . $statut) != "StatusProspect" . $statut) ? $langs->trans("StatusProspect" . $statut) : $label, 0) . ' ' . (($langs->trans("StatusProspect" . $statut) != "StatusProspect" . $statut) ? $langs->trans("StatusProspect" . $statut) : $label);
3406 3530
             }
3407 3531
         }
@@ -3435,8 +3559,9 @@  discard block
 block discarded – undo
3435 3559
     function getOutstandingProposals($mode = 'customer')
3436 3560
     {
3437 3561
         $table = 'propal';
3438
-        if ($mode == 'supplier')
3439
-            $table = 'supplier_proposal';
3562
+        if ($mode == 'supplier') {
3563
+                    $table = 'supplier_proposal';
3564
+        }
3440 3565
 
3441 3566
         $sql = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM " . MAIN_DB_PREFIX . $table . " as f";
3442 3567
         $sql .= " WHERE fk_soc = " . $this->id;
@@ -3460,8 +3585,9 @@  discard block
 block discarded – undo
3460 3585
                 }
3461 3586
             }
3462 3587
             return array('opened' => $outstandingOpened, 'total_ht' => $outstandingTotal, 'total_ttc' => $outstandingTotalIncTax); // 'opened' is 'incl taxes'
3463
-        } else
3464
-            return array();
3588
+        } else {
3589
+                    return array();
3590
+        }
3465 3591
     }
3466 3592
 
3467 3593
     /**
@@ -3473,8 +3599,9 @@  discard block
 block discarded – undo
3473 3599
     function getOutstandingOrders($mode = 'customer')
3474 3600
     {
3475 3601
         $table = 'commande';
3476
-        if ($mode == 'supplier')
3477
-            $table = 'commande_fournisseur';
3602
+        if ($mode == 'supplier') {
3603
+                    $table = 'commande_fournisseur';
3604
+        }
3478 3605
 
3479 3606
         $sql = "SELECT rowid, total_ht, total_ttc, fk_statut FROM " . MAIN_DB_PREFIX . $table . " as f";
3480 3607
         $sql .= " WHERE fk_soc = " . $this->id;
@@ -3498,8 +3625,9 @@  discard block
 block discarded – undo
3498 3625
                 }
3499 3626
             }
3500 3627
             return array('opened' => $outstandingOpened, 'total_ht' => $outstandingTotal, 'total_ttc' => $outstandingTotalIncTax); // 'opened' is 'incl taxes'
3501
-        } else
3502
-            return array();
3628
+        } else {
3629
+                    return array();
3630
+        }
3503 3631
     }
3504 3632
 
3505 3633
     /**
@@ -3511,8 +3639,9 @@  discard block
 block discarded – undo
3511 3639
     function getOutstandingBills($mode = 'customer')
3512 3640
     {
3513 3641
         $table = 'facture';
3514
-        if ($mode == 'supplier')
3515
-            $table = 'facture_fourn';
3642
+        if ($mode == 'supplier') {
3643
+                    $table = 'facture_fourn';
3644
+        }
3516 3645
 
3517 3646
         /* Accurate value of remain to pay is to sum remaintopay for each invoice
3518 3647
           $paiement = $invoice->getSommePaiement();
@@ -3521,10 +3650,11 @@  discard block
 block discarded – undo
3521 3650
           $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
3522 3651
           $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
3523 3652
          */
3524
-        if ($mode == 'supplier')
3525
-            $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM " . MAIN_DB_PREFIX . $table . " as f";
3526
-        else
3527
-            $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM " . MAIN_DB_PREFIX . $table . " as f";
3653
+        if ($mode == 'supplier') {
3654
+                    $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM " . MAIN_DB_PREFIX . $table . " as f";
3655
+        } else {
3656
+                    $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM " . MAIN_DB_PREFIX . $table . " as f";
3657
+        }
3528 3658
         $sql .= " WHERE fk_soc = " . $this->id;
3529 3659
         if ($mode == 'supplier') {
3530 3660
             $sql .= " AND entity IN (" . getEntity('facture_fourn') . ")";
@@ -3608,8 +3738,9 @@  discard block
 block discarded – undo
3608 3738
                 $outstandingAmount += $obj->total_ttc - $paiement - $creditnotes - $deposits;
3609 3739
             }
3610 3740
             return $outstandingAmount;
3611
-        } else
3612
-            return 0;
3741
+        } else {
3742
+                    return 0;
3743
+        }
3613 3744
     }
3614 3745
 
3615 3746
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -3636,14 +3767,18 @@  discard block
 block discarded – undo
3636 3767
         global $langs;
3637 3768
         $langs->load('companies');
3638 3769
 
3639
-        if ($statut == 0)
3640
-            return $langs->trans("NorProspectNorCustomer");
3641
-        if ($statut == 1)
3642
-            return $langs->trans("Customer");
3643
-        if ($statut == 2)
3644
-            return $langs->trans("Prospect");
3645
-        if ($statut == 3)
3646
-            return $langs->trans("ProspectCustomer");
3770
+        if ($statut == 0) {
3771
+                    return $langs->trans("NorProspectNorCustomer");
3772
+        }
3773
+        if ($statut == 1) {
3774
+                    return $langs->trans("Customer");
3775
+        }
3776
+        if ($statut == 2) {
3777
+                    return $langs->trans("Prospect");
3778
+        }
3779
+        if ($statut == 3) {
3780
+                    return $langs->trans("ProspectCustomer");
3781
+        }
3647 3782
     }
3648 3783
 
3649 3784
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -3669,8 +3804,9 @@  discard block
 block discarded – undo
3669 3804
             include_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
3670 3805
             $companybankaccount = new CompanyBankAccount($this->db);
3671 3806
             $result = $companybankaccount->fetch($moreparams['use_companybankid']);
3672
-            if (!$result)
3673
-                dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
3807
+            if (!$result) {
3808
+                            dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
3809
+            }
3674 3810
             $result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3675 3811
         } else {
3676 3812
             // Positionne le modele sur le nom du modele a utiliser
@@ -3825,8 +3961,9 @@  discard block
 block discarded – undo
3825 3961
             $sql .= " WHERE ((ug.fk_user = sc.fk_user";
3826 3962
             $sql .= " AND ug.entity = " . $conf->entity . ")";
3827 3963
             $sql .= " OR u.admin = 1)";
3828
-        } else
3829
-            $sql .= " WHERE entity in (0, " . $conf->entity . ")";
3964
+        } else {
3965
+                    $sql .= " WHERE entity in (0, " . $conf->entity . ")";
3966
+        }
3830 3967
 
3831 3968
         $sql .= " AND u.rowid = sc.fk_user AND sc.fk_soc = " . $this->id;
3832 3969
 
@@ -3872,8 +4009,9 @@  discard block
 block discarded – undo
3872 4009
         $this->context = array('commercial_modified' => $commid);
3873 4010
 
3874 4011
         $result = $this->call_trigger('COMPANY_UNLINK_SALE_REPRESENTATIVE', $user);
3875
-        if ($result < 0)
3876
-            $error++;
4012
+        if ($result < 0) {
4013
+                    $error++;
4014
+        }
3877 4015
 
3878 4016
         if ($this->id > 0 && $commid > 0) {
3879 4017
             $sql = "DELETE FROM  " . MAIN_DB_PREFIX . "societe_commerciaux ";
Please login to merge, or discard this patch.
Controllers/ThirdParty.php 1 patch
Braces   +64 added lines, -21 removed lines patch added patch discarded remove patch
@@ -20,7 +20,9 @@  discard block
 block discarded – undo
20 20
         $langs->load("companies");
21 21
 
22 22
         $socid = GETPOST('socid', 'int');
23
-        if ($user->societe_id) $socid = $user->societe_id;
23
+        if ($user->societe_id) {
24
+            $socid = $user->societe_id;
25
+        }
24 26
 
25 27
 // Security check
26 28
         $result = restrictedArea($user, 'societe', 0, '', '', '', '');
@@ -45,11 +47,13 @@  discard block
 block discarded – undo
45 47
         print '<div class="fichecenter"><div class="fichethirdleft">';
46 48
 
47 49
 
48
-        if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))     // This is useless due to the global search combo
50
+        if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) {
51
+            // This is useless due to the global search combo
49 52
         {
50 53
             // Search thirdparty
51 54
             if (!empty($conf->societe->enabled) && $user->rights->societe->lire) {
52 55
                 $listofsearchfields['search_thirdparty'] = array('text' => 'ThirdParty');
56
+        }
53 57
             }
54 58
             // Search contact/address
55 59
             if (!empty($conf->societe->enabled) && $user->rights->societe->lire) {
@@ -63,10 +67,14 @@  discard block
 block discarded – undo
63 67
                 print '<table class="noborder nohover centpercent">';
64 68
                 $i = 0;
65 69
                 foreach ($listofsearchfields as $key => $value) {
66
-                    if ($i == 0) print '<tr class="liste_titre"><th colspan="3">' . $langs->trans("Search") . '</th></tr>';
70
+                    if ($i == 0) {
71
+                        print '<tr class="liste_titre"><th colspan="3">' . $langs->trans("Search") . '</th></tr>';
72
+                    }
67 73
                     print '<tr ' . $bc[false] . '>';
68 74
                     print '<td class="nowrap"><label for="' . $key . '">' . $langs->trans($value["text"]) . '</label></td><td><input type="text" class="flat inputsearch" name="' . $key . '" id="' . $key . '" size="18"></td>';
69
-                    if ($i == 0) print '<td rowspan="' . count($listofsearchfields) . '"><input type="submit" value="' . $langs->trans("Search") . '" class="button"></td>';
75
+                    if ($i == 0) {
76
+                        print '<td rowspan="' . count($listofsearchfields) . '"><input type="submit" value="' . $langs->trans("Search") . '" class="button"></td>';
77
+                    }
70 78
                     print '</tr>';
71 79
                     $i++;
72 80
                 }
@@ -91,11 +99,20 @@  discard block
 block discarded – undo
91 99
 
92 100
         $sql = "SELECT s.rowid, s.client, s.fournisseur";
93 101
         $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
94
-        if (!$user->rights->societe->client->voir && !$socid) $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
102
+        if (!$user->rights->societe->client->voir && !$socid) {
103
+            $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
104
+        }
95 105
         $sql .= ' WHERE s.entity IN (' . getEntity('societe') . ')';
96
-        if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id;
97
-        if ($socid) $sql .= " AND s.rowid = " . $socid;
98
-        if (!$user->rights->fournisseur->lire) $sql .= " AND (s.fournisseur <> 1 OR s.client <> 0)";    // client=0, fournisseur=0 must be visible
106
+        if (!$user->rights->societe->client->voir && !$socid) {
107
+            $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id;
108
+        }
109
+        if ($socid) {
110
+            $sql .= " AND s.rowid = " . $socid;
111
+        }
112
+        if (!$user->rights->fournisseur->lire) {
113
+            $sql .= " AND (s.fournisseur <> 1 OR s.client <> 0)";
114
+        }
115
+        // client=0, fournisseur=0 must be visible
99 116
 //print $sql;
100 117
         $result = $db->query($sql);
101 118
         if ($result) {
@@ -117,9 +134,13 @@  discard block
 block discarded – undo
117 134
                     $found = 1;
118 135
                     $third['other']++;
119 136
                 }
120
-                if ($found) $total++;
137
+                if ($found) {
138
+                    $total++;
139
+                }
121 140
             }
122
-        } else dol_print_error($db);
141
+        } else {
142
+            dol_print_error($db);
143
+        }
123 144
 
124 145
         print '<div class="div-table-responsive-no-min">';
125 146
         print '<table class="noborder nohover" width="100%">' . "\n";
@@ -127,10 +148,18 @@  discard block
 block discarded – undo
127 148
         if (!empty($conf->use_javascript_ajax) && ((round($third['prospect']) ? 1 : 0) + (round($third['customer']) ? 1 : 0) + (round($third['supplier']) ? 1 : 0) + (round($third['other']) ? 1 : 0) >= 2)) {
128 149
             print '<tr><td align="center" colspan="2">';
129 150
             $dataseries = array();
130
-            if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) $dataseries[] = array($langs->trans("Prospects"), round($third['prospect']));
131
-            if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) $dataseries[] = array($langs->trans("Customers"), round($third['customer']));
132
-            if (!empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) $dataseries[] = array($langs->trans("Suppliers"), round($third['supplier']));
133
-            if (!empty($conf->societe->enabled)) $dataseries[] = array($langs->trans("Others"), round($third['other']));
151
+            if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) {
152
+                $dataseries[] = array($langs->trans("Prospects"), round($third['prospect']));
153
+            }
154
+            if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) {
155
+                $dataseries[] = array($langs->trans("Customers"), round($third['customer']));
156
+            }
157
+            if (!empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) {
158
+                $dataseries[] = array($langs->trans("Suppliers"), round($third['supplier']));
159
+            }
160
+            if (!empty($conf->societe->enabled)) {
161
+                $dataseries[] = array($langs->trans("Others"), round($third['other']));
162
+            }
134 163
             include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php';
135 164
             $dolgraph = new DolGraph();
136 165
             $dolgraph->SetData($dataseries);
@@ -183,7 +212,9 @@  discard block
 block discarded – undo
183 212
             $sql .= " FROM " . MAIN_DB_PREFIX . "categorie_societe as cs";
184 213
             $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "categorie as c ON cs.fk_categorie = c.rowid";
185 214
             $sql .= " WHERE c.type = 2";
186
-            if (!is_numeric($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) $sql .= " AND c.label like '" . $db->escape($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES) . "'";
215
+            if (!is_numeric($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) {
216
+                $sql .= " AND c.label like '" . $db->escape($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES) . "'";
217
+            }
187 218
             $sql .= " AND c.entity IN (" . getEntity('category') . ")";
188 219
             $sql .= " GROUP BY c.label";
189 220
             $total = 0;
@@ -250,11 +281,19 @@  discard block
 block discarded – undo
250 281
         $sql .= ", s.logo";
251 282
         $sql .= ", s.canvas, s.tms as datem, s.status as status";
252 283
         $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
253
-        if (!$user->rights->societe->client->voir && !$socid) $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
284
+        if (!$user->rights->societe->client->voir && !$socid) {
285
+            $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
286
+        }
254 287
         $sql .= ' WHERE s.entity IN (' . getEntity('societe') . ')';
255
-        if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id;
256
-        if ($socid) $sql .= " AND s.rowid = " . $socid;
257
-        if (!$user->rights->fournisseur->lire) $sql .= " AND (s.fournisseur != 1 OR s.client != 0)";
288
+        if (!$user->rights->societe->client->voir && !$socid) {
289
+            $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id;
290
+        }
291
+        if ($socid) {
292
+            $sql .= " AND s.rowid = " . $socid;
293
+        }
294
+        if (!$user->rights->fournisseur->lire) {
295
+            $sql .= " AND (s.fournisseur != 1 OR s.client != 0)";
296
+        }
258 297
         $sql .= $db->order("s.tms", "DESC");
259 298
         $sql .= $db->plimit($max, 0);
260 299
 
@@ -304,13 +343,17 @@  discard block
 block discarded – undo
304 343
                         $thirdparty_static->name = $langs->trans("Customer");
305 344
                         print $thirdparty_static->getNomUrl(0, 'customer', 0, 1);
306 345
                     }
307
-                    if ($thirdparty_static->client == 3 && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print " / ";
346
+                    if ($thirdparty_static->client == 3 && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
347
+                        print " / ";
348
+                    }
308 349
                     if (($thirdparty_static->client == 2 || $thirdparty_static->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
309 350
                         $thirdparty_static->name = $langs->trans("Prospect");
310 351
                         print $thirdparty_static->getNomUrl(0, 'prospect', 0, 1);
311 352
                     }
312 353
                     if (!empty($conf->fournisseur->enabled) && $thirdparty_static->fournisseur) {
313
-                        if ($thirdparty_static->client) print " / ";
354
+                        if ($thirdparty_static->client) {
355
+                            print " / ";
356
+                        }
314 357
                         $thirdparty_static->name = $langs->trans("Supplier");
315 358
                         print $thirdparty_static->getNomUrl(0, 'supplier', 0, 1);
316 359
                     }
Please login to merge, or discard this patch.