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';