Passed
Push — master ( 3cffbe...0f9140 )
by Alxarafe
23:50
created
Base/AlExtraFields.php 1 patch
Braces   +176 added lines, -126 removed lines patch added patch discarded remove patch
@@ -172,15 +172,19 @@  discard block
 block discarded – undo
172 172
      */
173 173
     function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique = 0, $required = 0, $default_value = '', $param = '', $alwayseditable = 0, $perms = '', $list = '-1', $help = '', $computed = '', $entity = '', $langfile = '', $enabled = '1')
174 174
     {
175
-        if (empty($attrname))
176
-            return -1;
177
-        if (empty($label))
178
-            return -1;
179
-
180
-        if ($elementtype == 'thirdparty')
181
-            $elementtype = 'societe';
182
-        if ($elementtype == 'contact')
183
-            $elementtype = 'socpeople';
175
+        if (empty($attrname)) {
176
+                    return -1;
177
+        }
178
+        if (empty($label)) {
179
+                    return -1;
180
+        }
181
+
182
+        if ($elementtype == 'thirdparty') {
183
+                    $elementtype = 'societe';
184
+        }
185
+        if ($elementtype == 'contact') {
186
+                    $elementtype = 'socpeople';
187
+        }
184 188
 
185 189
         // Create field into database except for separator type which is not stored in database
186 190
         if ($type != 'separate') {
@@ -195,10 +199,10 @@  discard block
 block discarded – undo
195 199
                 $this->error = '';
196 200
                 $this->errno = 0;
197 201
                 return 1;
198
-            } else
199
-                return -2;
200
-        }
201
-        else {
202
+            } else {
203
+                            return -2;
204
+            }
205
+        } else {
202 206
             return -1;
203 207
         }
204 208
     }
@@ -222,14 +226,17 @@  discard block
 block discarded – undo
222 226
      */
223 227
     private function create($attrname, $type = 'varchar', $length = 255, $elementtype = 'member', $unique = 0, $required = 0, $default_value = '', $param = '', $perms = '', $list = '0', $computed = '')
224 228
     {
225
-        if ($elementtype == 'thirdparty')
226
-            $elementtype = 'societe';
227
-        if ($elementtype == 'contact')
228
-            $elementtype = 'socpeople';
229
+        if ($elementtype == 'thirdparty') {
230
+                    $elementtype = 'societe';
231
+        }
232
+        if ($elementtype == 'contact') {
233
+                    $elementtype = 'socpeople';
234
+        }
229 235
 
230 236
         $table = $elementtype . '_extrafields';
231
-        if ($elementtype == 'categorie')
232
-            $table = 'categories_extrafields';
237
+        if ($elementtype == 'categorie') {
238
+                    $table = 'categories_extrafields';
239
+        }
233 240
 
234 241
         if (!empty($attrname) && preg_match("/^\w[a-zA-Z0-9_]*$/", $attrname) && !is_numeric($attrname)) {
235 242
             if ($type == 'boolean') {
@@ -262,8 +269,9 @@  discard block
 block discarded – undo
262 269
             } else {
263 270
                 $typedb = $type;
264 271
                 $lengthdb = $length;
265
-                if ($type == 'varchar' && empty($lengthdb))
266
-                    $lengthdb = '255';
272
+                if ($type == 'varchar' && empty($lengthdb)) {
273
+                                    $lengthdb = '255';
274
+                }
267 275
             }
268 276
             $field_desc = array(
269 277
                 'type' => $typedb,
@@ -318,22 +326,29 @@  discard block
 block discarded – undo
318 326
         // phpcs:enable
319 327
         // global $conf, $user;
320 328
 
321
-        if ($elementtype == 'thirdparty')
322
-            $elementtype = 'societe';
323
-        if ($elementtype == 'contact')
324
-            $elementtype = 'socpeople';
329
+        if ($elementtype == 'thirdparty') {
330
+                    $elementtype = 'societe';
331
+        }
332
+        if ($elementtype == 'contact') {
333
+                    $elementtype = 'socpeople';
334
+        }
325 335
 
326 336
         // Clean parameters
327
-        if (empty($pos))
328
-            $pos = 0;
329
-        if (empty($list))
330
-            $list = '0';
331
-        if (empty($required))
332
-            $required = 0;
333
-        if (empty($unique))
334
-            $unique = 0;
335
-        if (empty($alwayseditable))
336
-            $alwayseditable = 0;
337
+        if (empty($pos)) {
338
+                    $pos = 0;
339
+        }
340
+        if (empty($list)) {
341
+                    $list = '0';
342
+        }
343
+        if (empty($required)) {
344
+                    $required = 0;
345
+        }
346
+        if (empty($unique)) {
347
+                    $unique = 0;
348
+        }
349
+        if (empty($alwayseditable)) {
350
+                    $alwayseditable = 0;
351
+        }
337 352
 
338 353
         if (!empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname) && !is_numeric($attrname)) {
339 354
             if (is_array($param) && count($param) > 0) {
@@ -410,14 +425,17 @@  discard block
 block discarded – undo
410 425
      */
411 426
     function delete($attrname, $elementtype = 'member')
412 427
     {
413
-        if ($elementtype == 'thirdparty')
414
-            $elementtype = 'societe';
415
-        if ($elementtype == 'contact')
416
-            $elementtype = 'socpeople';
428
+        if ($elementtype == 'thirdparty') {
429
+                    $elementtype = 'societe';
430
+        }
431
+        if ($elementtype == 'contact') {
432
+                    $elementtype = 'socpeople';
433
+        }
417 434
 
418 435
         $table = $elementtype . '_extrafields';
419
-        if ($elementtype == 'categorie')
420
-            $table = 'categories_extrafields';
436
+        if ($elementtype == 'categorie') {
437
+                    $table = 'categories_extrafields';
438
+        }
421 439
 
422 440
         $error = 0;
423 441
 
@@ -466,10 +484,12 @@  discard block
 block discarded – undo
466 484
         // phpcs:enable
467 485
         // global $conf;
468 486
 
469
-        if ($elementtype == 'thirdparty')
470
-            $elementtype = 'societe';
471
-        if ($elementtype == 'contact')
472
-            $elementtype = 'socpeople';
487
+        if ($elementtype == 'thirdparty') {
488
+                    $elementtype = 'societe';
489
+        }
490
+        if ($elementtype == 'contact') {
491
+                    $elementtype = 'socpeople';
492
+        }
473 493
 
474 494
         if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
475 495
             $sql = "DELETE FROM " . MAIN_DB_PREFIX . "extrafields";
@@ -516,14 +536,17 @@  discard block
 block discarded – undo
516 536
      */
517 537
     function update($attrname, $label, $type, $length, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0)
518 538
     {
519
-        if ($elementtype == 'thirdparty')
520
-            $elementtype = 'societe';
521
-        if ($elementtype == 'contact')
522
-            $elementtype = 'socpeople';
539
+        if ($elementtype == 'thirdparty') {
540
+                    $elementtype = 'societe';
541
+        }
542
+        if ($elementtype == 'contact') {
543
+                    $elementtype = 'socpeople';
544
+        }
523 545
 
524 546
         $table = $elementtype . '_extrafields';
525
-        if ($elementtype == 'categorie')
526
-            $table = 'categories_extrafields';
547
+        if ($elementtype == 'categorie') {
548
+                    $table = 'categories_extrafields';
549
+        }
527 550
 
528 551
         if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
529 552
             if ($type == 'boolean') {
@@ -620,24 +643,31 @@  discard block
 block discarded – undo
620 643
         AlDolUtils::dol_syslog(get_class($this) . "::update_label " . $attrname . ", " . $label . ", " . $type . ", " . $size . ", " . $elementtype . ", " . $unique . ", " . $required . ", " . $pos . ", " . $alwayseditable . ", " . $perms . ", " . $list . ", " . $default . ", " . $computed . ", " . $entity . ", " . $langfile . ", " . $enabled . ", " . $totalizable);
621 644
 
622 645
         // Clean parameters
623
-        if ($elementtype == 'thirdparty')
624
-            $elementtype = 'societe';
625
-        if ($elementtype == 'contact')
626
-            $elementtype = 'socpeople';
627
-
628
-        if (empty($pos))
629
-            $pos = 0;
630
-        if (empty($list))
631
-            $list = '0';
646
+        if ($elementtype == 'thirdparty') {
647
+                    $elementtype = 'societe';
648
+        }
649
+        if ($elementtype == 'contact') {
650
+                    $elementtype = 'socpeople';
651
+        }
652
+
653
+        if (empty($pos)) {
654
+                    $pos = 0;
655
+        }
656
+        if (empty($list)) {
657
+                    $list = '0';
658
+        }
632 659
         if (empty($totalizable)) {
633 660
             $totalizable = 0;
634 661
         }
635
-        if (empty($required))
636
-            $required = 0;
637
-        if (empty($unique))
638
-            $unique = 0;
639
-        if (empty($alwayseditable))
640
-            $alwayseditable = 0;
662
+        if (empty($required)) {
663
+                    $required = 0;
664
+        }
665
+        if (empty($unique)) {
666
+                    $unique = 0;
667
+        }
668
+        if (empty($alwayseditable)) {
669
+                    $alwayseditable = 0;
670
+        }
641 671
 
642 672
         if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
643 673
             Config::$dbEngine->begin();
@@ -741,21 +771,26 @@  discard block
 block discarded – undo
741 771
         // phpcs:enable
742 772
         // global $conf;
743 773
 
744
-        if (empty($elementtype))
745
-            return array();
774
+        if (empty($elementtype)) {
775
+                    return array();
776
+        }
746 777
 
747
-        if ($elementtype == 'thirdparty')
748
-            $elementtype = 'societe';
749
-        if ($elementtype == 'contact')
750
-            $elementtype = 'socpeople';
751
-        if ($elementtype == 'order_supplier')
752
-            $elementtype = 'commande_fournisseur';
778
+        if ($elementtype == 'thirdparty') {
779
+                    $elementtype = 'societe';
780
+        }
781
+        if ($elementtype == 'contact') {
782
+                    $elementtype = 'socpeople';
783
+        }
784
+        if ($elementtype == 'order_supplier') {
785
+                    $elementtype = 'commande_fournisseur';
786
+        }
753 787
 
754 788
         $array_name_label = array();
755 789
 
756 790
         // To avoid conflicts with external modules. TODO Remove this.
757
-        if (!$forceload &&!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_DISABLED))
758
-        return $array_name_label;
791
+        if (!$forceload &&!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
792
+                return $array_name_label;
793
+        }
759 794
 
760 795
         // Set array of label of entity
761 796
         // TODO Remove completely loading of label. This should be done by presentation.
@@ -776,8 +811,10 @@  discard block
 block discarded – undo
776 811
         $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,totalizable,fielddefault,fieldcomputed,entity,enabled,help";
777 812
         $sql .= " FROM " . MAIN_DB_PREFIX . "extrafields";
778 813
         $sql .= " WHERE entity IN (0," . Globals::$conf->entity . ")";
779
-        if ($elementtype)
780
-            $sql .= " AND elementtype = '" . $elementtype . "'"; // Filed with object->table_element
814
+        if ($elementtype) {
815
+                    $sql .= " AND elementtype = '" . $elementtype . "'";
816
+        }
817
+        // Filed with object->table_element
781 818
         $sql .= " ORDER BY pos";
782 819
 
783 820
         $resql = Config::$dbEngine->select($sql);
@@ -901,10 +938,11 @@  discard block
 block discarded – undo
901 938
         }
902 939
 
903 940
         if ($computed) {
904
-            if (!preg_match('/^search_/', $keyprefix))
905
-                return '<span class="opacitymedium">' . Globals::$langs->trans("AutomaticallyCalculated") . '</span>';
906
-            else
907
-                return '';
941
+            if (!preg_match('/^search_/', $keyprefix)) {
942
+                            return '<span class="opacitymedium">' . Globals::$langs->trans("AutomaticallyCalculated") . '</span>';
943
+            } else {
944
+                            return '';
945
+            }
908 946
         }
909 947
 
910 948
         if (empty($morecss)) {
@@ -938,13 +976,13 @@  discard block
 block discarded – undo
938 976
             $showtime = in_array($type, array('datetime')) ? 1 : 0;
939 977
 
940 978
             // Do not show current date when field not required (see selectDate() method)
941
-            if (!$required && $value == '')
942
-                $value = '-1';
979
+            if (!$required && $value == '') {
980
+                            $value = '-1';
981
+            }
943 982
 
944 983
             // TODO Must also support $moreparam
945 984
             $out = $form->selectDate($value, $keyprefix . $key . $keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1);
946
-        }
947
-        elseif (in_array($type, array('int', 'integer'))) {
985
+        } elseif (in_array($type, array('int', 'integer'))) {
948 986
             $tmp = explode(',', $size);
949 987
             $newsize = $tmp[0];
950 988
             $out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" maxlength="' . $newsize . '" value="' . dol_escape_htmltag($value) . '"' . ($moreparam ? $moreparam : '') . '>';
@@ -996,22 +1034,23 @@  discard block
 block discarded – undo
996 1034
             $out .= '<select class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" ' . ($moreparam ? $moreparam : '') . '>';
997 1035
             $out .= '<option value="0">&nbsp;</option>';
998 1036
             foreach ($param['options'] as $key => $val) {
999
-                if ((string) $key == '')
1000
-                    continue;
1037
+                if ((string) $key == '') {
1038
+                                    continue;
1039
+                }
1001 1040
                 list($val, $parent) = explode('|', $val);
1002 1041
                 $out .= '<option value="' . $key . '"';
1003 1042
                 $out .= (((string) $value == (string) $key) ? ' selected' : '');
1004 1043
                 $out .= (!empty($parent) ? ' parent="' . $parent . '"' : '');
1005 1044
                 $out .= '>';
1006
-                if ($langfile && $val)
1007
-                    $out .= Globals::$langs->trans($val);
1008
-                else
1009
-                    $out .= $val;
1045
+                if ($langfile && $val) {
1046
+                                    $out .= Globals::$langs->trans($val);
1047
+                } else {
1048
+                                    $out .= $val;
1049
+                }
1010 1050
                 $out .= '</option>';
1011 1051
             }
1012 1052
             $out .= '</select>';
1013
-        }
1014
-        elseif ($type == 'sellist') {
1053
+        } elseif ($type == 'sellist') {
1015 1054
             $out = '';
1016 1055
             if (!empty(Globals::$conf->use_javascript_ajax) &&!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) {
1017 1056
                 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
@@ -1130,8 +1169,9 @@  discard block
 block discarded – undo
1130 1169
                                     $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
1131 1170
                                 }
1132 1171
                             }
1133
-                            if (empty($labeltoshow))
1134
-                                $labeltoshow = '(not defined)';
1172
+                            if (empty($labeltoshow)) {
1173
+                                                            $labeltoshow = '(not defined)';
1174
+                            }
1135 1175
                             if ($value == $obj->rowid) {
1136 1176
                                 $out .= '<option value="' . $obj->rowid . '" selected>' . $labeltoshow . '</option>';
1137 1177
                             }
@@ -1330,8 +1370,9 @@  discard block
 block discarded – undo
1330 1370
                                     $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
1331 1371
                                 }
1332 1372
                             }
1333
-                            if (empty($labeltoshow))
1334
-                                $labeltoshow = '(not defined)';
1373
+                            if (empty($labeltoshow)) {
1374
+                                                            $labeltoshow = '(not defined)';
1375
+                            }
1335 1376
 
1336 1377
                             if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1337 1378
                                 $data[$obj->rowid] = $labeltoshow;
@@ -1415,8 +1456,10 @@  discard block
 block discarded – undo
1415 1456
             $hidden = (empty($list) ? 1 : 0);  // If $list empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller)
1416 1457
         }
1417 1458
 
1418
-        if ($hidden)
1419
-            return '';  // This is a protection. If field is hidden, we should just not call this method.
1459
+        if ($hidden) {
1460
+                    return '';
1461
+        }
1462
+        // This is a protection. If field is hidden, we should just not call this method.
1420 1463
 
1421 1464
 
1422 1465
 
@@ -1457,12 +1500,12 @@  discard block
 block discarded – undo
1457 1500
         } elseif ($type == 'price') {
1458 1501
             $value = price($value, 0, Globals::$langs, 0, 0, -1, Globals::$conf->currency);
1459 1502
         } elseif ($type == 'select') {
1460
-            if ($langfile && $param['options'][$value])
1461
-                $value = Globals::$langs->trans($param['options'][$value]);
1462
-            else
1463
-                $value = $param['options'][$value];
1464
-        }
1465
-        elseif ($type == 'sellist') {
1503
+            if ($langfile && $param['options'][$value]) {
1504
+                            $value = Globals::$langs->trans($param['options'][$value]);
1505
+            } else {
1506
+                            $value = $param['options'][$value];
1507
+            }
1508
+        } elseif ($type == 'sellist') {
1466 1509
             $param_list = array_keys($param['options']);
1467 1510
             $InfoFieldList = explode(":", $param_list[0]);
1468 1511
 
@@ -1528,10 +1571,10 @@  discard block
 block discarded – undo
1528 1571
                         $value = $obj->{$InfoFieldList[1]};
1529 1572
                     }
1530 1573
                 }
1531
-            } else
1532
-                AlDolUtils::dol_syslog(get_class($this) . '::showOutputField error ' . Config::$dbEngine->lasterror(), LOG_WARNING);
1533
-        }
1534
-        elseif ($type == 'radio') {
1574
+            } else {
1575
+                            AlDolUtils::dol_syslog(get_class($this) . '::showOutputField error ' . Config::$dbEngine->lasterror(), LOG_WARNING);
1576
+            }
1577
+        } elseif ($type == 'radio') {
1535 1578
             $value = $param['options'][$value];
1536 1579
         } elseif ($type == 'checkbox') {
1537 1580
             $value_arr = explode(',', $value);
@@ -1640,8 +1683,9 @@  discard block
 block discarded – undo
1640 1683
             $value = dol_trunc(preg_replace('/./i', '*', $value), 8, 'right', 'UTF-8', 1);
1641 1684
         } else {
1642 1685
             $showsize = round($size);
1643
-            if ($showsize > 48)
1644
-                $showsize = 48;
1686
+            if ($showsize > 48) {
1687
+                            $showsize = 48;
1688
+            }
1645 1689
         }
1646 1690
 
1647 1691
         //print $type.'-'.$size;
@@ -1661,10 +1705,11 @@  discard block
 block discarded – undo
1661 1705
     {
1662 1706
         // global $conf, $langs;
1663 1707
 
1664
-        if (!empty($extrafieldsobjectkey))
1665
-            $type = $this->attributes[$extrafieldsobjectkey]['type'][$key];
1666
-        else
1667
-            $type = $this->attribute_type[$key];
1708
+        if (!empty($extrafieldsobjectkey)) {
1709
+                    $type = $this->attributes[$extrafieldsobjectkey]['type'][$key];
1710
+        } else {
1711
+                    $type = $this->attribute_type[$key];
1712
+        }
1668 1713
 
1669 1714
         $align = '';
1670 1715
 
@@ -1720,18 +1765,21 @@  discard block
 block discarded – undo
1720 1765
         $nofillrequired = ''; // For error when required field left blank
1721 1766
         $error_field_required = array();
1722 1767
 
1723
-        if (is_array($this->attributes[$object->table_element]['label']))
1724
-            $extralabels = $this->attributes[$object->table_element]['label'];
1768
+        if (is_array($this->attributes[$object->table_element]['label'])) {
1769
+                    $extralabels = $this->attributes[$object->table_element]['label'];
1770
+        }
1725 1771
 
1726 1772
         if (is_array($extralabels)) {
1727 1773
             // Get extra fields
1728 1774
             foreach ($extralabels as $key => $value) {
1729
-                if (!empty($onlykey) && $key != $onlykey)
1730
-                    continue;
1775
+                if (!empty($onlykey) && $key != $onlykey) {
1776
+                                    continue;
1777
+                }
1731 1778
 
1732 1779
                 $key_type = $this->attributes[$object->table_element]['type'][$key];
1733
-                if ($key_type == 'separate')
1734
-                    continue;
1780
+                if ($key_type == 'separate') {
1781
+                                    continue;
1782
+                }
1735 1783
 
1736 1784
                 $enabled = 1;
1737 1785
                 if (isset($this->attributes[$object->table_element]['list'][$key])) {
@@ -1741,10 +1789,12 @@  discard block
 block discarded – undo
1741 1789
                 if (isset($this->attributes[$object->table_element]['perms'][$key])) {
1742 1790
                     $perms = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1);
1743 1791
                 }
1744
-                if (empty($enabled))
1745
-                    continue;
1746
-                if (empty($perms))
1747
-                    continue;
1792
+                if (empty($enabled)) {
1793
+                                    continue;
1794
+                }
1795
+                if (empty($perms)) {
1796
+                                    continue;
1797
+                }
1748 1798
 
1749 1799
                 if ($this->attributes[$object->table_element]['required'][$key]) { // Value is required
1750 1800
                     // Check if empty without using GETPOST, value can be alpha, int, array, etc...
Please login to merge, or discard this patch.
Base/AlCommonObject.php 1 patch
Braces   +1373 added lines, -865 removed lines patch added patch discarded remove patch
@@ -401,24 +401,31 @@  discard block
 block discarded – undo
401 401
 		$sql.= " FROM ".MAIN_DB_PREFIX.$element;
402 402
 		$sql.= " WHERE entity IN (".getEntity($element).")" ;
403 403
 
404
-		if ($id > 0) $sql.= " AND rowid = ".$db->escape($id);
405
-		else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'";
406
-		else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'";
407
-		else {
404
+		if ($id > 0) {
405
+		    $sql.= " AND rowid = ".$db->escape($id);
406
+		} else if ($ref) {
407
+		    $sql.= " AND ref = '".$db->escape($ref)."'";
408
+		} else if ($ref_ext) {
409
+		    $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'";
410
+		} else {
408 411
 			$error='ErrorWrongParameters';
409 412
 			dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR);
410 413
 			return -1;
411 414
 		}
412
-		if ($ref || $ref_ext)
413
-            $sql .= " AND entity = " . Globals::$conf->entity;
415
+		if ($ref || $ref_ext) {
416
+		            $sql .= " AND entity = " . Globals::$conf->entity;
417
+		}
414 418
 
415 419
         dol_syslog(get_class()."::isExistingObject", LOG_DEBUG);
416 420
 		$resql = $db->query($sql);
417 421
 		if ($resql)
418 422
 		{
419 423
 			$num=$db->num_rows($resql);
420
-			if ($num > 0) return 1;
421
-			else return 0;
424
+			if ($num > 0) {
425
+			    return 1;
426
+			} else {
427
+			    return 0;
428
+			}
422 429
 		}
423 430
 		return -1;
424 431
 	}
@@ -447,13 +454,18 @@  discard block
 block discarded – undo
447 454
 		//print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n";
448 455
 		$lastname=$this->lastname;
449 456
 		$firstname=$this->firstname;
450
-		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:'')))));
457
+		if (empty($lastname)) {
458
+		    $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:'')))));
459
+		}
451 460
 
452 461
 		$ret='';
453 462
 		if ($option && $this->civility_id)
454 463
 		{
455
-			if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' ';
456
-			else $ret.=$this->civility_id.' ';
464
+			if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) {
465
+			    $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' ';
466
+			} else {
467
+			    $ret.=$this->civility_id.' ';
468
+			}
457 469
 		}
458 470
 
459 471
 		$ret .= AlDolUtils::dolGetFirstLastname($firstname, $lastname, $nameorder);
@@ -544,14 +556,15 @@  discard block
 block discarded – undo
544 556
             && empty(Globals::$conf->global->SOCIETE_DISABLE_STATE) && $this->state) {
545 557
             if (!empty(Globals::$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && Globals::$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) {
546 558
                 $out.=($outdone?' - ':'').$this->region.' - '.$this->state;
547
-            }
548
-            else {
559
+            } else {
549 560
                 $out.=($outdone?' - ':'').$this->state;
550 561
             }
551 562
 			$outdone++;
552 563
 		}
553 564
 
554
-		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>':'');
565
+		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)) {
566
+		    $out.=($outdone?'<br>':'');
567
+		}
555 568
 		if (! empty($this->phone) && empty($this->phone_pro)) {		// For objects that store pro phone into ->phone
556 569
 			$out.=dol_print_phone($this->phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL','&nbsp;','phone',$langs->trans("PhonePro")); $outdone++;
557 570
 		}
@@ -591,13 +604,21 @@  discard block
 block discarded – undo
591 604
 		}
592 605
 		$out.='<div style="clear: both;">';
593 606
 		if (!empty(Globals::$conf->socialnetworks->enabled)) {
594
-			if ($this->skype) $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype');
607
+			if ($this->skype) {
608
+			    $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype');
609
+			}
595 610
 			$outdone++;
596
-			if ($this->jabberid) $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber');
611
+			if ($this->jabberid) {
612
+			    $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber');
613
+			}
597 614
 			$outdone++;
598
-			if ($this->twitter) $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter');
615
+			if ($this->twitter) {
616
+			    $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter');
617
+			}
599 618
 			$outdone++;
600
-			if ($this->facebook) $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook');
619
+			if ($this->facebook) {
620
+			    $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook');
621
+			}
601 622
 			$outdone++;
602 623
 		}
603 624
 		$out.='</div>';
@@ -657,10 +678,10 @@  discard block
 block discarded – undo
657 678
 					$this->errors = $ecmfile->errors;
658 679
 				}
659 680
 				*/
660
-			}
661
-			else return '';
662
-		}
663
-		elseif (empty($ecmfile->share))
681
+			} else {
682
+			    return '';
683
+			}
684
+		} elseif (empty($ecmfile->share))
664 685
 		{
665 686
 			// Add entry into index
666 687
 			if ($initsharekey)
@@ -668,8 +689,9 @@  discard block
 block discarded – undo
668 689
 				require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
669 690
 				$ecmfile->share = getRandomPassword(true);
670 691
 				$ecmfile->update($user);
671
-			}
672
-			else return '';
692
+			} else {
693
+			    return '';
694
+			}
673 695
 		}
674 696
 
675 697
 		// Define $urlwithroot
@@ -683,14 +705,18 @@  discard block
 block discarded – undo
683 705
 		//if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart;		// For sharing with hash (so public files), modulepart is not required.
684 706
 		//if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; 					// For sharing with hash (so public files), entity is not required.
685 707
 		//$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath);								// No need of name of file for public link, we will use the hash
686
-		if (! empty($ecmfile->share)) $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share;			// Hash for public share
687
-		if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1';
708
+		if (! empty($ecmfile->share)) {
709
+		    $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share;
710
+		}
711
+		// Hash for public share
712
+		if ($forcedownload) {
713
+		    $paramlink.=($paramlink?'&':'').'attachment=1';
714
+		}
688 715
 
689 716
 		if ($relativelink)
690 717
 		{
691 718
 			$linktoreturn='document.php'.($paramlink?'?'.$paramlink:'');
692
-		}
693
-		else
719
+		} else
694 720
 		{
695 721
 			$linktoreturn=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:'');
696 722
 		}
@@ -738,8 +764,7 @@  discard block
 block discarded – undo
738 764
 		if (is_numeric($type_contact))
739 765
 		{
740 766
 			$id_type_contact=$type_contact;
741
-		}
742
-		else
767
+		} else
743 768
 		{
744 769
 			// We look for id type_contact
745 770
 			$sql = "SELECT tc.rowid";
@@ -752,7 +777,9 @@  discard block
 block discarded – undo
752 777
 			if ($resql)
753 778
 			{
754 779
 				$obj = $this->db->fetch_object($resql);
755
-				if ($obj) $id_type_contact=$obj->rowid;
780
+				if ($obj) {
781
+				    $id_type_contact=$obj->rowid;
782
+				}
756 783
 			}
757 784
 		}
758 785
 
@@ -804,8 +831,7 @@  discard block
 block discarded – undo
804 831
 
805 832
 				$this->db->commit();
806 833
 				return 1;
807
-			}
808
-			else
834
+			} else
809 835
 			{
810 836
 				if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
811 837
 				{
@@ -813,15 +839,16 @@  discard block
 block discarded – undo
813 839
 					$this->db->rollback();
814 840
 					echo 'err rollback';
815 841
 					return -2;
816
-				}
817
-				else
842
+				} else
818 843
 				{
819 844
 					$this->error=$this->db->error();
820 845
 					$this->db->rollback();
821 846
 					return -1;
822 847
 				}
823 848
 			}
824
-		} else return 0;
849
+		} else {
850
+		    return 0;
851
+		}
825 852
 	}
826 853
 
827 854
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -863,15 +890,18 @@  discard block
 block discarded – undo
863 890
 		// Insert into database
864 891
 		$sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set";
865 892
 		$sql.= " statut = ".$statut;
866
-		if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'";
867
-		if ($fk_socpeople) $sql.= ", fk_socpeople = '".$fk_socpeople ."'";
893
+		if ($type_contact_id) {
894
+		    $sql.= ", fk_c_type_contact = '".$type_contact_id ."'";
895
+		}
896
+		if ($fk_socpeople) {
897
+		    $sql.= ", fk_socpeople = '".$fk_socpeople ."'";
898
+		}
868 899
 		$sql.= " where rowid = ".$rowid;
869 900
 		$resql=$this->db->query($sql);
870 901
 		if ($resql)
871 902
 		{
872 903
 			return 0;
873
-		}
874
-		else
904
+		} else
875 905
 		{
876 906
 			$this->error=$this->db->lasterror();
877 907
 			return -1;
@@ -908,8 +938,7 @@  discard block
 block discarded – undo
908 938
 
909 939
 			$this->db->commit();
910 940
 			return 1;
911
-		}
912
-		else
941
+		} else
913 942
 		{
914 943
 			$this->error=$this->db->lasterror();
915 944
 			$this->db->rollback();
@@ -939,15 +968,15 @@  discard block
 block discarded – undo
939 968
 
940 969
 		$sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact";
941 970
 		$sql.= " WHERE element_id = ".$this->id;
942
-		if ($listId)
943
-			$sql.= " AND fk_c_type_contact IN (".$listId.")";
971
+		if ($listId) {
972
+					$sql.= " AND fk_c_type_contact IN (".$listId.")";
973
+		}
944 974
 
945 975
 		dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG);
946 976
 		if ($this->db->query($sql))
947 977
 		{
948 978
 			return 1;
949
-		}
950
-		else
979
+		} else
951 980
 		{
952 981
 			$this->error=$this->db->lasterror();
953 982
 			return -1;
@@ -972,22 +1001,38 @@  discard block
 block discarded – undo
972 1001
 		$tab=array();
973 1002
 
974 1003
 		$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
975
-		if ($source == 'internal') $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo";
976
-		if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid, t.statut as statuscontact";
1004
+		if ($source == 'internal') {
1005
+		    $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo";
1006
+		}
1007
+		if ($source == 'external' || $source == 'thirdparty') {
1008
+		    $sql.=", t.fk_soc as socid, t.statut as statuscontact";
1009
+		}
977 1010
 		$sql.= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email";
978 1011
 		$sql.= ", tc.source, tc.element, tc.code, tc.libelle";
979 1012
 		$sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc";
980 1013
 		$sql.= ", ".MAIN_DB_PREFIX."element_contact ec";
981
-		if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid";
982
-		if ($source == 'external'|| $source == 'thirdparty') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid";
1014
+		if ($source == 'internal') {
1015
+		    $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid";
1016
+		}
1017
+		if ($source == 'external'|| $source == 'thirdparty') {
1018
+		    $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid";
1019
+		}
983 1020
 		$sql.= " WHERE ec.element_id =".$this->id;
984 1021
 		$sql.= " AND ec.fk_c_type_contact=tc.rowid";
985 1022
 		$sql.= " AND tc.element='".$this->db->escape($this->element)."'";
986
-		if ($code) $sql.= " AND tc.code = '".$this->db->escape($code)."'";
987
-		if ($source == 'internal') $sql.= " AND tc.source = 'internal'";
988
-		if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'";
1023
+		if ($code) {
1024
+		    $sql.= " AND tc.code = '".$this->db->escape($code)."'";
1025
+		}
1026
+		if ($source == 'internal') {
1027
+		    $sql.= " AND tc.source = 'internal'";
1028
+		}
1029
+		if ($source == 'external' || $source == 'thirdparty') {
1030
+		    $sql.= " AND tc.source = 'external'";
1031
+		}
989 1032
 		$sql.= " AND tc.active=1";
990
-		if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'";
1033
+		if ($statut >= 0) {
1034
+		    $sql.= " AND ec.statut = '".$statut."'";
1035
+		}
991 1036
 		$sql.=" ORDER BY t.lastname ASC";
992 1037
 
993 1038
 		dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG);
@@ -1008,8 +1053,7 @@  discard block
 block discarded – undo
1008 1053
 								   'nom'=>$obj->lastname,      // For backward compatibility
1009 1054
 								   'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact,
1010 1055
 								   'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact);
1011
-				}
1012
-				else
1056
+				} else
1013 1057
 				{
1014 1058
 					$tab[$i]=$obj->id;
1015 1059
 				}
@@ -1018,8 +1062,7 @@  discard block
 block discarded – undo
1018 1062
 			}
1019 1063
 
1020 1064
 			return $tab;
1021
-		}
1022
-		else
1065
+		} else
1023 1066
 		{
1024 1067
 			$this->error=$this->db->lasterror();
1025 1068
 			dol_print_error($this->db);
@@ -1054,8 +1097,7 @@  discard block
 block discarded – undo
1054 1097
 			$result = $this->update_contact($rowid, $newstatut);
1055 1098
 			$this->db->free($resql);
1056 1099
 			return $result;
1057
-		}
1058
-		else
1100
+		} else
1059 1101
 		{
1060 1102
 			$this->error=$this->db->error();
1061 1103
 			dol_print_error($this->db);
@@ -1079,16 +1121,27 @@  discard block
 block discarded – undo
1079 1121
         // phpcs:enable
1080 1122
 		global $langs;
1081 1123
 
1082
-		if (empty($order)) $order='position';
1083
-		if ($order == 'position') $order.=',code';
1124
+		if (empty($order)) {
1125
+		    $order='position';
1126
+		}
1127
+		if ($order == 'position') {
1128
+		    $order.=',code';
1129
+		}
1084 1130
 
1085 1131
 		$tab = array();
1086 1132
 		$sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position";
1087 1133
 		$sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";
1088