Passed
Push — master ( 7e4a07...284492 )
by Alxarafe
19:58
created
dolibarr/htdocs/comm/action/index.php 1 patch
Braces   +319 added lines, -220 removed lines patch added patch discarded remove patch
@@ -43,11 +43,13 @@  discard block
 block discarded – undo
43 43
     require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
44 44
 }
45 45
 
46
-if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW))
46
+if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) {
47 47
     $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3;
48
+}
48 49
 
49
-if (empty($conf->global->AGENDA_EXT_NB))
50
+if (empty($conf->global->AGENDA_EXT_NB)) {
50 51
     $conf->global->AGENDA_EXT_NB = 5;
52
+}
51 53
 $MAXAGENDA = $conf->global->AGENDA_EXT_NB;
52 54
 
53 55
 $filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
@@ -68,24 +70,30 @@  discard block
 block discarded – undo
68 70
 }     // If $page is not defined, or '' or -1
69 71
 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
70 72
 $offset = $limit * $page;
71
-if (!$sortorder)
73
+if (!$sortorder) {
72 74
     $sortorder = "ASC";
73
-if (!$sortfield)
75
+}
76
+if (!$sortfield) {
74 77
     $sortfield = "a.datec";
78
+}
75 79
 
76 80
 // Security check
77 81
 $socid = GETPOST("search_socid", "int") ? GETPOST("search_socid", "int") : GETPOST("socid", "int");
78
-if ($user->societe_id)
82
+if ($user->societe_id) {
79 83
     $socid = $user->societe_id;
84
+}
80 85
 $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
81
-if ($socid < 0)
86
+if ($socid < 0) {
82 87
     $socid = '';
88
+}
83 89
 
84 90
 $canedit = 1;
85
-if (!$user->rights->agenda->myactions->read)
91
+if (!$user->rights->agenda->myactions->read) {
86 92
     accessforbidden();
87
-if (!$user->rights->agenda->allactions->read)
93
+}
94
+if (!$user->rights->agenda->allactions->read) {
88 95
     $canedit = 0;
96
+}
89 97
 if (!$user->rights->agenda->allactions->read || $filter == 'mine') {  // If no permission to see all, we show only affected to me
90 98
     $filtert = $user->id;
91 99
 }
@@ -103,22 +111,25 @@  discard block
 block discarded – undo
103 111
 // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
104 112
 if (GETPOST('search_actioncode', 'array')) {
105 113
     $actioncode = GETPOST('search_actioncode', 'array', 3);
106
-    if (!count($actioncode))
107
-        $actioncode = '0';
108
-}
109
-else {
114
+    if (!count($actioncode)) {
115
+            $actioncode = '0';
116
+    }
117
+    } else {
110 118
     $actioncode = GETPOST("search_actioncode", "alpha", 3) ? GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE));
111 119
 }
112
-if ($actioncode == '' && empty($actioncodearray))
120
+if ($actioncode == '' && empty($actioncodearray)) {
113 121
     $actioncode = (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE);
122
+}
114 123
 
115
-if ($status == '' && !GETPOSTISSET('search_status'))
124
+if ($status == '' && !GETPOSTISSET('search_status')) {
116 125
     $status = (empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
126
+}
117 127
 
118 128
 $defaultview = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
119 129
 $defaultview = (empty($user->conf->AGENDA_DEFAULT_VIEW) ? $defaultview : $user->conf->AGENDA_DEFAULT_VIEW);
120
-if (empty($action) && !GETPOSTISSET('action'))
130
+if (empty($action) && !GETPOSTISSET('action')) {
121 131
     $action = $defaultview;
132
+}
122 133
 if ($action == 'default') { // When action is default, we want a calendar view and not the list
123 134
     $action = (($defaultview != 'show_list') ? $defaultview : 'show_month');
124 135
 }
@@ -150,8 +161,9 @@  discard block
 block discarded – undo
150 161
     $param = '';
151 162
     if (is_array($_POST)) {
152 163
         foreach ($_POST as $key => $val) {
153
-            if ($key == 'token')
154
-                continue;
164
+            if ($key == 'token') {
165
+                            continue;
166
+            }
155 167
             $param .= '&' . $key . '=' . urlencode($val);
156 168
         }
157 169
     }
@@ -164,8 +176,9 @@  discard block
 block discarded – undo
164 176
     $param = '';
165 177
     if (is_array($_POST)) {
166 178
         foreach ($_POST as $key => $val) {
167
-            if ($key == 'token')
168
-                continue;
179
+            if ($key == 'token') {
180
+                            continue;
181
+            }
169 182
             $param .= '&' . $key . '=' . urlencode($val);
170 183
         }
171 184
     }
@@ -247,15 +260,18 @@  discard block
 block discarded – undo
247 260
     // tmpday is a negative or null cursor to know how many days before the 1st to show on month view (if tmpday=0, 1st is monday)
248 261
     $tmpday = -date("w", dol_mktime(12, 0, 0, $month, 1, $year, true)) + 2;  // date('w') is 0 fo sunday
249 262
     $tmpday += ((isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1) - 1);
250
-    if ($tmpday >= 1)
251
-        $tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
263
+    if ($tmpday >= 1) {
264
+            $tmpday -= 7;
265
+    }
266
+    // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
252 267
 
253 268
         
254 269
 // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
255 270
     $firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $max_day_in_prev_month + $tmpday, $prev_year);
256 271
     $next_day = 7 - ($max_day_in_month + 1 - $tmpday) % 7;
257
-    if ($next_day < 6)
258
-        $next_day += 7;
272
+    if ($next_day < 6) {
273
+            $next_day += 7;
274
+    }
259 275
     $lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year);
260 276
 }
261 277
 if ($action == 'show_week') {
@@ -303,39 +319,53 @@  discard block
 block discarded – undo
303 319
 //print dol_print_date($lastdaytoshow,'day');
304 320
 
305 321
 $title = $langs->trans("DoneAndToDoActions");
306
-if ($status == 'done')
322
+if ($status == 'done') {
307 323
     $title = $langs->trans("DoneActions");
308
-if ($status == 'todo')
324
+}
325
+if ($status == 'todo') {
309 326
     $title = $langs->trans("ToDoActions");
327
+}
310 328
 
311 329
 $param = '';
312 330
 if ($actioncode || isset($_GET['search_actioncode']) || isset($_POST['search_actioncode'])) {
313 331
     if (is_array($actioncode)) {
314
-        foreach ($actioncode as $str_action)
315
-            $param .= "&search_actioncode[]=" . urlencode($str_action);
316
-    } else
317
-        $param .= "&search_actioncode=" . urlencode($actioncode);
318
-}
319
-if ($resourceid > 0)
332
+        foreach ($actioncode as $str_action) {
333
+                    $param .= "&search_actioncode[]=" . urlencode($str_action);
334
+        }
335
+    } else {
336
+            $param .= "&search_actioncode=" . urlencode($actioncode);
337
+    }
338
+    }
339
+if ($resourceid > 0) {
320 340
     $param .= "&search_resourceid=" . urlencode($resourceid);
321
-if ($status || isset($_GET['status']) || isset($_POST['status']))
341
+}
342
+if ($status || isset($_GET['status']) || isset($_POST['status'])) {
322 343
     $param .= "&search_status=" . urlencode($status);
323
-if ($filter)
344
+}
345
+if ($filter) {
324 346
     $param .= "&search_filter=" . urlencode($filter);
325
-if ($filtert)
347
+}
348
+if ($filtert) {
326 349
     $param .= "&search_filtert=" . urlencode($filtert);
327
-if ($usergroup)
350
+}
351
+if ($usergroup) {
328 352
     $param .= "&search_usergroup=" . urlencode($usergroup);
329
-if ($socid)
353
+}
354
+if ($socid) {
330 355
     $param .= "&search_socid=" . urlencode($socid);
331
-if ($showbirthday)
356
+}
357
+if ($showbirthday) {
332 358
     $param .= "&search_showbirthday=1";
333
-if ($pid)
359
+}
360
+if ($pid) {
334 361
     $param .= "&search_projectid=" . urlencode($pid);
335
-if ($type)
362
+}
363
+if ($type) {
336 364
     $param .= "&search_type=" . urlencode($type);
337
-if ($action == 'show_day' || $action == 'show_week' || $action == 'show_month')
365
+}
366
+if ($action == 'show_day' || $action == 'show_week' || $action == 'show_month') {
338 367
     $param .= '&action=' . urlencode($action);
368
+}
339 369
 $param .= "&maxprint=" . urlencode($maxprint);
340 370
 
341 371
 // Show navigation bar
@@ -372,22 +402,27 @@  discard block
 block discarded – undo
372 402
 
373 403
 
374 404
 $tabactive = '';
375
-if ($action == 'show_month')
405
+if ($action == 'show_month') {
376 406
     $tabactive = 'cardmonth';
377
-if ($action == 'show_week')
407
+}
408
+if ($action == 'show_week') {
378 409
     $tabactive = 'cardweek';
379
-if ($action == 'show_day')
410
+}
411
+if ($action == 'show_day') {
380 412
     $tabactive = 'cardday';
381
-if ($action == 'show_list')
413
+}
414
+if ($action == 'show_list') {
382 415
     $tabactive = 'cardlist';
416
+}
383 417
 
384 418
 $paramnoaction = preg_replace('/action=[a-z_]+/', '', $param);
385 419
 
386 420
 $head = calendars_prepare_head($paramnoaction);
387 421
 
388 422
 print '<form method="POST" id="searchFormList" class="listactionsfilter" action="' . $_SERVER["PHP_SELF"] . '">' . "\n";
389
-if ($optioncss != '')
423
+if ($optioncss != '') {
390 424
     print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
425
+}
391 426
 print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
392 427
 
393 428
 dol_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action');
@@ -459,15 +494,17 @@  discard block
 block discarded – undo
459 494
 } else {          // If javascript off
460 495
     $newparam = $param;   // newparam is for birthday links
461 496
     $newparam = preg_replace('/showbirthday=[0-1]/i', 'showbirthday=' . (empty($showbirthday) ? 1 : 0), $newparam);
462
-    if (!preg_match('/showbirthday=/i', $newparam))
463
-        $newparam .= '&showbirthday=1';
497
+    if (!preg_match('/showbirthday=/i', $newparam)) {
498
+            $newparam .= '&showbirthday=1';
499
+    }
464 500
     $link = '<a href="' . dol_escape_htmltag($_SERVER['PHP_SELF']);
465 501
     $link .= '?' . dol_escape_htmltag($newparam);
466 502
     $link .= '">';
467
-    if (empty($showbirthday))
468
-        $link .= $langs->trans("AgendaShowBirthdayEvents");
469
-    else
470
-        $link .= $langs->trans("AgendaHideBirthdayEvents");
503
+    if (empty($showbirthday)) {
504
+            $link .= $langs->trans("AgendaShowBirthdayEvents");
505
+    } else {
506
+            $link .= $langs->trans("AgendaHideBirthdayEvents");
507
+    }
471 508
     $link .= '</a>';
472 509
 }
473 510
 
@@ -478,8 +515,9 @@  discard block
 block discarded – undo
478 515
 $eventarray = array();
479 516
 
480 517
 $sql = 'SELECT ';
481
-if ($usergroup > 0)
518
+if ($usergroup > 0) {
482 519
     $sql .= " DISTINCT";
520
+}
483 521
 $sql .= ' a.id, a.label,';
484 522
 $sql .= ' a.datep,';
485 523
 $sql .= ' a.datep2,';
@@ -490,38 +528,43 @@  discard block
 block discarded – undo
490 528
 $sql .= ' a.fk_element, a.elementtype,';
491 529
 $sql .= ' ca.code as type_code, ca.libelle as type_label, ca.color as type_color';
492 530
 $sql .= ' FROM ' . MAIN_DB_PREFIX . 'c_actioncomm as ca, ' . MAIN_DB_PREFIX . "actioncomm as a";
493
-if (!$user->rights->societe->client->voir && !$socid)
531
+if (!$user->rights->societe->client->voir && !$socid) {
494 532
     $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
533
+}
495 534
 // We must filter on resource table
496
-if ($resourceid > 0)
535
+if ($resourceid > 0) {
497 536
     $sql .= ", " . MAIN_DB_PREFIX . "element_resources as r";
537
+}
498 538
 // We must filter on assignement table
499
-if ($filtert > 0 || $usergroup > 0)
539
+if ($filtert > 0 || $usergroup > 0) {
500 540
     $sql .= ", " . MAIN_DB_PREFIX . "actioncomm_resources as ar";
501
-if ($usergroup > 0)
541
+}
542
+if ($usergroup > 0) {
502 543
     $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
544
+}
503 545
 $sql .= ' WHERE a.fk_action = ca.id';
504 546
 $sql .= ' AND a.entity IN (' . getEntity('agenda') . ')';
505 547
 // Condition on actioncode
506 548
 if (!empty($actioncode)) {
507 549
     if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
508
-        if ($actioncode == 'AC_NON_AUTO')
509
-            $sql .= " AND ca.type != 'systemauto'";
510
-        elseif ($actioncode == 'AC_ALL_AUTO')
511
-            $sql .= " AND ca.type = 'systemauto'";
512
-        else {
513
-            if ($actioncode == 'AC_OTH')
514
-                $sql .= " AND ca.type != 'systemauto'";
515
-            if ($actioncode == 'AC_OTH_AUTO')
516
-                $sql .= " AND ca.type = 'systemauto'";
550
+        if ($actioncode == 'AC_NON_AUTO') {
551
+                    $sql .= " AND ca.type != 'systemauto'";
552
+        } elseif ($actioncode == 'AC_ALL_AUTO') {
553
+                    $sql .= " AND ca.type = 'systemauto'";
554
+        } else {
555
+            if ($actioncode == 'AC_OTH') {
556
+                            $sql .= " AND ca.type != 'systemauto'";
557
+            }
558
+            if ($actioncode == 'AC_OTH_AUTO') {
559
+                            $sql .= " AND ca.type = 'systemauto'";
560
+            }
517 561
         }
518
-    }
519
-    else {
520
-        if ($actioncode == 'AC_NON_AUTO')
521
-            $sql .= " AND ca.type != 'systemauto'";
522
-        elseif ($actioncode == 'AC_ALL_AUTO')
523
-            $sql .= " AND ca.type = 'systemauto'";
524
-        else {
562
+    } else {
563
+        if ($actioncode == 'AC_NON_AUTO') {
564
+                    $sql .= " AND ca.type != 'systemauto'";
565
+        } elseif ($actioncode == 'AC_ALL_AUTO') {
566
+                    $sql .= " AND ca.type = 'systemauto'";
567
+        } else {
525 568
             if (is_array($actioncode)) {
526 569
                 $sql .= " AND ca.code IN ('" . implode("','", $actioncode) . "')";
527 570
             } else {
@@ -530,17 +573,22 @@  discard block
 block discarded – undo
530 573
         }
531 574
     }
532 575
 }
533
-if ($resourceid > 0)
576
+if ($resourceid > 0) {
534 577
     $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = " . $db->escape($resourceid);
535
-if ($pid)
578
+}
579
+if ($pid) {
536 580
     $sql .= " AND a.fk_project=" . $db->escape($pid);
537
-if (!$user->rights->societe->client->voir && !$socid)
581
+}
582
+if (!$user->rights->societe->client->voir && !$socid) {
538 583
     $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = " . $user->id . ")";
539
-if ($socid > 0)
584
+}
585
+if ($socid > 0) {
540 586
     $sql .= ' AND a.fk_soc = ' . $socid;
587
+}
541 588
 // We must filter on assignement table
542
-if ($filtert > 0 || $usergroup > 0)
589
+if ($filtert > 0 || $usergroup > 0) {
543 590
     $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
591
+}
544 592
 if ($action == 'show_day') {
545 593
     $sql .= " AND (";
546 594
     $sql .= " (a.datep BETWEEN '" . $db->idate(dol_mktime(0, 0, 0, $month, $day, $year)) . "'";
@@ -565,8 +613,9 @@  discard block
 block discarded – undo
565 613
     $sql .= " AND a.datep2 > '" . $db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10)) . "')";
566 614
     $sql .= ')';
567 615
 }
568
-if ($type)
616
+if ($type) {
569 617
     $sql .= " AND ca.id = " . $type;
618
+}
570 619
 if ($status == '0') {
571 620
     $sql .= " AND a.percent = 0";
572 621
 }
@@ -585,10 +634,12 @@  discard block
 block discarded – undo
585 634
 // We must filter on assignement table
586 635
 if ($filtert > 0 || $usergroup > 0) {
587 636
     $sql .= " AND (";
588
-    if ($filtert > 0)
589
-        $sql .= "ar.fk_element = " . $filtert;
590
-    if ($usergroup > 0)
591
-        $sql .= ($filtert > 0 ? " OR " : "") . " ugu.fk_usergroup = " . $usergroup;
637
+    if ($filtert > 0) {
638
+            $sql .= "ar.fk_element = " . $filtert;
639
+    }
640
+    if ($usergroup > 0) {
641
+            $sql .= ($filtert > 0 ? " OR " : "") . " ugu.fk_usergroup = " . $usergroup;
642
+    }
592 643
     $sql .= ")";
593 644
 }
594 645
 // Sort on date
@@ -647,17 +698,18 @@  discard block
 block discarded – undo
647 698
         // They are date start and end of action but modified to not be outside calendar view.
648 699
         if ($event->percentage <= 0) {
649 700
             $event->date_start_in_calendar = $event->datep;
650
-            if ($event->datef != '' && $event->datef >= $event->datep)
651
-                $event->date_end_in_calendar = $event->datef;
652
-            else
653
-                $event->date_end_in_calendar = $event->datep;
654
-        }
655
-        else {
701
+            if ($event->datef != '' && $event->datef >= $event->datep) {
702
+                            $event->date_end_in_calendar = $event->datef;
703
+            } else {
704
+                            $event->date_end_in_calendar = $event->datep;
705
+            }
706
+        } else {
656 707
             $event->date_start_in_calendar = $event->datep;
657
-            if ($event->datef != '' && $event->datef >= $event->datep)
658
-                $event->date_end_in_calendar = $event->datef;
659
-            else
660
-                $event->date_end_in_calendar = $event->datep;
708
+            if ($event->datef != '' && $event->datef >= $event->datep) {
709
+                            $event->date_end_in_calendar = $event->datef;
710
+            } else {
711
+                            $event->date_end_in_calendar = $event->datep;
712
+            }
661 713
         }
662 714
         // Define ponctual property
663 715
         if ($event->date_start_in_calendar == $event->date_end_in_calendar) {
@@ -669,10 +721,12 @@  discard block
 block discarded – undo
669 721
             $event->date_start_in_calendar >= $lastdaytoshow) {
670 722
             // This record is out of visible range
671 723
         } else {
672
-            if ($event->date_start_in_calendar < $firstdaytoshow)
673
-                $event->date_start_in_calendar = $firstdaytoshow;
674
-            if ($event->date_end_in_calendar >= $lastdaytoshow)
675
-                $event->date_end_in_calendar = ($lastdaytoshow - 1);
724
+            if ($event->date_start_in_calendar < $firstdaytoshow) {
725
+                            $event->date_start_in_calendar = $firstdaytoshow;
726
+            }
727
+            if ($event->date_end_in_calendar >= $lastdaytoshow) {
728
+                            $event->date_end_in_calendar = ($lastdaytoshow - 1);
729
+            }
676 730
 
677 731
             // Add an entry in actionarray for each day
678 732
             $daycursor = $event->date_start_in_calendar;
@@ -691,8 +745,9 @@  discard block
 block discarded – undo
691 745
                 $j++;
692 746
 
693 747
                 $daykey += 60 * 60 * 24;
694
-                if ($daykey > $event->date_end_in_calendar)
695
-                    $loop = false;
748
+                if ($daykey > $event->date_end_in_calendar) {
749
+                                    $loop = false;
750
+                }
696 751
             }
697 752
             while ($loop);
698 753
 
@@ -701,8 +756,7 @@  discard block
 block discarded – undo
701 756
         }
702 757
         $i++;
703 758
     }
704
-}
705
-else {
759
+} else {
706 760
     dol_print_error($db);
707 761
 }
708 762
 
@@ -755,14 +809,14 @@  discard block
 block discarded – undo
755 809
             do {
756 810
                 $eventarray[$daykey][] = $event;
757 811
                 $daykey += 60 * 60 * 24;
758
-                if ($daykey > $event->date_end_in_calendar)
759
-                    $loop = false;
812
+                if ($daykey > $event->date_end_in_calendar) {
813
+                                    $loop = false;
814
+                }
760 815
             }
761 816
             while ($loop);
762 817
             $i++;
763 818
         }
764
-    }
765
-    else {
819
+    } else {
766 820
         dol_print_error($db);
767 821
     }
768 822
 }
@@ -783,10 +837,14 @@  discard block
 block discarded – undo
783 837
         // After this $ical->cal['VEVENT'] contains array of events, $ical->cal['DAYLIGHT'] contains daylight info, $ical->cal['STANDARD'] contains non daylight info, ...
784 838
         //var_dump($ical->cal); exit;
785 839
         $icalevents = array();
786
-        if (is_array($ical->get_event_list()))
787
-            $icalevents = array_merge($icalevents, $ical->get_event_list());        // Add $ical->cal['VEVENT']
788
-        if (is_array($ical->get_freebusy_list()))
789
-            $icalevents = array_merge($icalevents, $ical->get_freebusy_list());  // Add $ical->cal['VFREEBUSY']
840
+        if (is_array($ical->get_event_list())) {
841
+                    $icalevents = array_merge($icalevents, $ical->get_event_list());
842
+        }
843
+        // Add $ical->cal['VEVENT']
844
+        if (is_array($ical->get_freebusy_list())) {
845
+                    $icalevents = array_merge($icalevents, $ical->get_freebusy_list());
846
+        }
847
+        // Add $ical->cal['VFREEBUSY']
790 848
 
791 849
         if (count($icalevents) > 0) {
792 850
             // Duplicate all repeatable events into new entries
@@ -809,19 +867,20 @@  discard block
 block discarded – undo
809 867
                             $tmpdaylightend = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['STANDARD']['DTSTART'];
810 868
                             //var_dump($tmpcurstart);var_dump($tmpcurend); var_dump($ical->cal['DAYLIGHT']['DTSTART']);var_dump($ical->cal['STANDARD']['DTSTART']);
811 869
                             // Edit datecurstart and datecurend
812
-                            if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend)
813
-                                $datecurstart -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
814
-                            else
815
-                                $datecurstart -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
816
-                            if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend)
817
-                                $datecurend -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
818
-                            else
819
-                                $datecurend -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
870
+                            if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
871
+                                                            $datecurstart -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
872
+                            } else {
873
+                                                            $datecurstart -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
874
+                            }
875
+                            if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
876
+                                                            $datecurend -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
877
+                            } else {
878
+                                                            $datecurend -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
879
+                            }
820 880
                         }
821 881
                         // datecurstart and datecurend are now GMT date
822 882
                         //var_dump($datecurstart); var_dump($datecurend); exit;
823
-                    }
824
-                    else {
883
+                    } else {
825 884
                         // Not a recongized record
826 885
                         dol_syslog("Found a not recognized repeatable record with unknown date start", LOG_ERR);
827 886
                         continue;
@@ -831,10 +890,14 @@  discard block
 block discarded – undo
831 890
                     $interval = (empty($icalevent['RRULE']['INTERVAL']) ? 1 : $icalevent['RRULE']['INTERVAL']);
832 891
                     $until = empty($icalevent['RRULE']['UNTIL']) ? 0 : dol_stringtotime($icalevent['RRULE']['UNTIL'], 1);
833 892
                     $maxrepeat = empty($icalevent['RRULE']['COUNT']) ? 0 : $icalevent['RRULE']['COUNT'];
834
-                    if ($until && ($until + ($datecurend - $datecurstart)) < $firstdaytoshow)
835
-                        continue;  // We discard repeatable event that end before start date to show
836
-                    if ($datecurstart >= $lastdaytoshow)
837
-                        continue;                                   // We discard repeatable event that start after end date to show
893
+                    if ($until && ($until + ($datecurend - $datecurstart)) < $firstdaytoshow) {
894
+                                            continue;
895
+                    }
896
+                    // We discard repeatable event that end before start date to show
897
+                    if ($datecurstart >= $lastdaytoshow) {
898
+                                            continue;
899
+                    }
900
+                    // We discard repeatable event that start after end date to show
838 901
 
839 902
                     $numofevent = 0;
840 903
                     while (($datecurstart < $lastdaytoshow) && (empty($maxrepeat) || ($numofevent < $maxrepeat))) {
@@ -882,8 +945,10 @@  discard block
 block discarded – undo
882 945
             foreach ($icalevents as $icalevent) {
883 946
                 //var_dump($icalevent);
884 947
                 //print $icalevent['SUMMARY'].'->'.var_dump($icalevent).'<br>';exit;
885
-                if (!empty($icalevent['RRULE']))
886
-                    continue;    // We found a repeatable event. It was already split into unitary events, so we discard general rule.
948
+                if (!empty($icalevent['RRULE'])) {
949
+                                    continue;
950
+                }
951
+                // We found a repeatable event. It was already split into unitary events, so we discard general rule.
887 952
 
888 953
 
889 954
                     
@@ -943,19 +1008,21 @@  discard block
 block discarded – undo
943 1008
                     $event->datef = $dateend + $usertime;
944 1009
                     $event->type_code = "ICALEVENT";
945 1010
 
946
-                    if ($icalevent['SUMMARY'])
947
-                        $event->libelle = $icalevent['SUMMARY'];
948
-                    elseif ($icalevent['DESCRIPTION'])
949
-                        $event->libelle = dol_nl2br($icalevent['DESCRIPTION'], 1);
950
-                    else
951
-                        $event->libelle = $langs->trans("ExtSiteNoLabel");
1011
+                    if ($icalevent['SUMMARY']) {
1012
+                                            $event->libelle = $icalevent['SUMMARY'];
1013
+                    } elseif ($icalevent['DESCRIPTION']) {
1014
+                                            $event->libelle = dol_nl2br($icalevent['DESCRIPTION'], 1);
1015
+                    } else {
1016
+                                            $event->libelle = $langs->trans("ExtSiteNoLabel");
1017
+                    }
952 1018
 
953 1019
                     $event->date_start_in_calendar = $event->datep;
954 1020
 
955
-                    if ($event->datef != '' && $event->datef >= $event->datep)
956
-                        $event->date_end_in_calendar = $event->datef;
957
-                    else
958
-                        $event->date_end_in_calendar = $event->datep;
1021
+                    if ($event->datef != '' && $event->datef >= $event->datep) {
1022
+                                            $event->date_end_in_calendar = $event->datef;
1023
+                    } else {
1024
+                                            $event->date_end_in_calendar = $event->datep;
1025
+                    }
959 1026
 
960 1027
                     // Define ponctual property
961 1028
                     if ($event->date_start_in_calendar == $event->date_end_in_calendar) {
@@ -970,10 +1037,12 @@  discard block
 block discarded – undo
970 1037
                         //print 'x'.$datestart.'-'.$dateend;exit;
971 1038
                         // This record is out of visible range
972 1039
                     } else {
973
-                        if ($event->date_start_in_calendar < $firstdaytoshow)
974
-                            $event->date_start_in_calendar = $firstdaytoshow;
975
-                        if ($event->date_end_in_calendar >= $lastdaytoshow)
976
-                            $event->date_end_in_calendar = ($lastdaytoshow - 1);
1040
+                        if ($event->date_start_in_calendar < $firstdaytoshow) {
1041
+                                                    $event->date_start_in_calendar = $firstdaytoshow;
1042
+                        }
1043
+                        if ($event->date_end_in_calendar >= $lastdaytoshow) {
1044
+                                                    $event->date_end_in_calendar = ($lastdaytoshow - 1);
1045
+                        }
977 1046
 
978 1047
                         // Add an entry in actionarray for each day
979 1048
                         $daycursor = $event->date_start_in_calendar;
@@ -992,8 +1061,9 @@  discard block
 block discarded – undo
992 1061
                             $eventarray[$daykey][] = $event;
993 1062
                             $daykey += 60 * 60 * 24;
994 1063
                             $daykeygmt += 60 * 60 * 24;   // Add one day
995
-                            if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar)
996
-                                $loop = false;
1064
+                            if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar) {
1065
+                                                            $loop = false;
1066
+                            }
997 1067
                         }
998 1068
                         while ($loop);
999 1069
                     }
@@ -1030,8 +1100,9 @@  discard block
 block discarded – undo
1030 1100
 if (is_readable($color_file)) {
1031 1101
     include_once $color_file;
1032 1102
 }
1033
-if (!is_array($theme_datacolor))
1103
+if (!is_array($theme_datacolor)) {
1034 1104
     $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
1105
+}
1035 1106
 
1036 1107
 
1037 1108
 if (empty($action) || $action == 'show_month') {      // View by month
@@ -1057,8 +1128,9 @@  discard block
 block discarded – undo
1057 1128
         if (!empty($conf->dol_optimize_smallscreen)) {
1058 1129
             $labelshort = array(0 => 'SundayMin', 1 => 'MondayMin', 2 => 'TuesdayMin', 3 => 'WednesdayMin', 4 => 'ThursdayMin', 5 => 'FridayMin', 6 => 'SaturdayMin');
1059 1130
             print $langs->trans($labelshort[$numdayinweek]);
1060
-        } else
1061
-            print $langs->trans("Day" . $numdayinweek);
1131
+        } else {
1132
+                    print $langs->trans("Day" . $numdayinweek);
1133
+        }
1062 1134
         print '  </td>' . "\n";
1063 1135
         $i++;
1064 1136
     }
@@ -1075,8 +1147,9 @@  discard block
 block discarded – undo
1075 1147
             /* Show days before the beginning of the current month (previous month)  */
1076 1148
             if ($tmpday <= 0) {
1077 1149
                 $style = 'cal_other_month cal_past';
1078
-                if ($iter_day == 6)
1079
-                    $style .= ' cal_other_month_right';
1150
+                if ($iter_day == 6) {
1151
+                                    $style .= ' cal_other_month_right';
1152
+                }
1080 1153
                 echo '  <td class="' . $style . ' nowrap" width="14%" valign="top">';
1081 1154
                 show_day_events($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1082 1155
                 echo "  </td>\n";
@@ -1085,15 +1158,19 @@  discard block
 block discarded – undo
1085 1158
             elseif ($tmpday <= $max_day_in_month) {
1086 1159
                 $curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
1087 1160
                 $style = 'cal_current_month';
1088
-                if ($iter_day == 6)
1089
-                    $style .= ' cal_current_month_right';
1161
+                if ($iter_day == 6) {
1162
+                                    $style .= ' cal_current_month_right';
1163
+                }
1090 1164
                 $today = 0;
1091
-                if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $month && $todayarray['year'] == $year)
1092
-                    $today = 1;
1093
-                if ($today)
1094
-                    $style = 'cal_today';
1095
-                if ($curtime < $todaytms)
1096
-                    $style .= ' cal_past';
1165
+                if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
1166
+                                    $today = 1;
1167
+                }
1168
+                if ($today) {
1169
+                                    $style = 'cal_today';
1170
+                }
1171
+                if ($curtime < $todaytms) {
1172
+                                    $style .= ' cal_past';
1173
+                }
1097 1174
                 //var_dump($todayarray['mday']."==".$tmpday." && ".$todayarray['mon']."==".$month." && ".$todayarray['year']."==".$year.' -> '.$style);
1098 1175
                 echo '  <td class="' . $style . ' nowrap" width="14%" valign="top">';
1099 1176
                 show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
@@ -1102,8 +1179,9 @@  discard block
 block discarded – undo
1102 1179
             /* Show days after the current month (next month) */
1103 1180
             else {
1104 1181
                 $style = 'cal_other_month';
1105
-                if ($iter_day == 6)
1106
-                    $style .= ' cal_other_month_right';
1182
+                if ($iter_day == 6) {
1183
+                                    $style .= ' cal_other_month_right';
1184
+                }
1107 1185
                 echo '  <td class="' . $style . ' nowrap" width="14%" valign="top">';
1108 1186
                 show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1109 1187
                 echo "</td>\n";
@@ -1118,8 +1196,7 @@  discard block
 block discarded – undo
1118 1196
     print '<input type="hidden" name="actionmove" value="mupdate">';
1119 1197
     print '<input type="hidden" name="backtopage" value="' . dol_escape_htmltag($_SERVER['PHP_SELF']) . '?' . dol_escape_htmltag($_SERVER['QUERY_STRING']) . '">';
1120 1198
     print '<input type="hidden" name="newdate" id="newdate">';
1121
-}
1122
-elseif ($action == 'show_week') { // View by week
1199
+} elseif ($action == 'show_week') { // View by week
1123 1200
     $newparam = $param;   // newparam is for birthday links
1124 1201
     $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
1125 1202
     $newparam = preg_replace('/action=show_month&?/i', '', $newparam);
@@ -1152,14 +1229,17 @@  discard block
 block discarded – undo
1152 1229
         $tmpyear = $tmparray['year'];
1153 1230
 
1154 1231
         $style = 'cal_current_month';
1155
-        if ($iter_day == 6)
1156
-            $style .= ' cal_other_month_right';
1232
+        if ($iter_day == 6) {
1233
+                    $style .= ' cal_other_month_right';
1234
+        }
1157 1235
         $today = 0;
1158 1236
         $todayarray = dol_getdate($now, 'fast');
1159
-        if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear)
1160
-            $today = 1;
1161
-        if ($today)
1162
-            $style = 'cal_today';
1237
+        if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) {
1238
+                    $today = 1;
1239
+        }
1240
+        if ($today) {
1241
+                    $style = 'cal_today';
1242
+        }
1163 1243
 
1164 1244
         echo '  <td class="' . $style . '" width="14%" valign="top">';
1165 1245
         show_day_events($db, $tmpday, $tmpmonth, $tmpyear, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
@@ -1173,8 +1253,7 @@  discard block
 block discarded – undo
1173 1253
     echo '<input type="hidden" name="actionmove" value="mupdate">';
1174 1254
     echo '<input type="hidden" name="backtopage" value="' . dol_escape_htmltag($_SERVER['PHP_SELF']) . '?' . dol_escape_htmltag($_SERVER['QUERY_STRING']) . '">';
1175 1255
     echo '<input type="hidden" name="newdate" id="newdate">';
1176
-}
1177
-else {    // View by day
1256
+} else {    // View by day
1178 1257
     $newparam = $param;   // newparam is for birthday links
1179 1258
     $newparam = preg_replace('/action=show_month&?/i', '', $newparam);
1180 1259
     $newparam = preg_replace('/action=show_week&?/i', '', $newparam);
@@ -1184,8 +1263,9 @@  discard block
 block discarded – undo
1184 1263
     $style = 'cal_current_month cal_current_month_oneday';
1185 1264
     $today = 0;
1186 1265
     $todayarray = dol_getdate($now, 'fast');
1187
-    if ($todayarray['mday'] == $day && $todayarray['mon'] == $month && $todayarray['year'] == $year)
1188
-        $today = 1;
1266
+    if ($todayarray['mday'] == $day && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
1267
+            $today = 1;
1268
+    }
1189 1269
     //if ($today) $style='cal_today';
1190 1270
 
1191 1271
     $timestamp = dol_mktime(12, 0, 0, $month, $day, $year);
@@ -1225,10 +1305,12 @@  discard block
 block discarded – undo
1225 1305
         $tmp = explode('-', $conf->global->MAIN_DEFAULT_WORKING_HOURS);
1226 1306
         $minhour = round($tmp[0], 0);
1227 1307
         $maxhour = round($tmp[1], 0);
1228
-        if ($minhour > 23)
1229
-            $minhour = 23;
1230
-        if ($maxhour < 1)
1231
-            $maxhour = 1;
1308
+        if ($minhour > 23) {
1309
+                    $minhour = 23;
1310
+        }
1311
+        if ($maxhour < 1) {
1312
+                    $maxhour = 1;
1313
+        }
1232 1314
         if ($maxhour <= $minhour) {
1233 1315
             $maxhour = $minhour + 1;
1234 1316
         }
@@ -1304,10 +1386,11 @@  discard block
 block discarded – undo
1304 1386
         print 'action=show_day&day=' . str_pad($day, 2, "0", STR_PAD_LEFT) . '&month=' . str_pad($month, 2, "0", STR_PAD_LEFT) . '&year=' . $year;
1305 1387
         print $newparam;
1306 1388
         print '">';
1307
-        if ($showinfo)
1308
-            print dol_print_date($curtime, 'daytextshort');
1309
-        else
1310
-            print dol_print_date($curtime, '%d');
1389
+        if ($showinfo) {
1390
+                    print dol_print_date($curtime, 'daytextshort');
1391
+        } else {
1392
+                    print dol_print_date($curtime, '%d');
1393
+        }
1311 1394
         print '</a>';
1312 1395
         print '</div><div class="floatright nowrap">';
1313 1396
         if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
@@ -1367,10 +1450,10 @@  discard block
 block discarded – undo
1367 1450
                         }
1368 1451
                         //var_dump($cacheusers[$event->userownerid]->color);
1369 1452
                         // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
1370
-                        if (!empty($cacheusers[$event->userownerid]->color))
1371
-                            $color = $cacheusers[$event->userownerid]->color;
1372
-                    }
1373
-                    else if ($event->type_code == 'ICALEVENT') {      // Event come from external ical file
1453
+                        if (!empty($cacheusers[$event->userownerid]->color)) {
1454
+                                                    $color = $cacheusers[$event->userownerid]->color;
1455
+                        }
1456
+                    } else if ($event->type_code == 'ICALEVENT') {      // Event come from external ical file
1374 1457
                         $numical++;
1375 1458
                         if (!empty($event->icalname)) {
1376 1459
                             if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
@@ -1398,8 +1481,9 @@  discard block
 block discarded – undo
1398 1481
                         }
1399 1482
                         //var_dump($cacheusers[$event->userownerid]->color);
1400 1483
                         // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
1401
-                        if (!empty($cacheusers[$event->userownerid]->color))
1402
-                            $color = $cacheusers[$event->userownerid]->color;
1484
+                        if (!empty($cacheusers[$event->userownerid]->color)) {
1485
+                                                    $color = $cacheusers[$event->userownerid]->color;
1486
+                        }
1403 1487
                     }
1404 1488
 
1405 1489
                     if ($color < 0) { // Color was not set on user card. Set color according to color index.
@@ -1410,8 +1494,10 @@  discard block
 block discarded – undo
1410 1494
                         } else {
1411 1495
                             $colorindex = $nextindextouse;
1412 1496
                             $colorindexused[$idusertouse] = $colorindex;
1413
-                            if (!empty($theme_datacolor[$nextindextouse + 1]))
1414
-                                $nextindextouse++; // Prepare to use next color
1497
+                            if (!empty($theme_datacolor[$nextindextouse + 1])) {
1498
+                                                            $nextindextouse++;
1499
+                            }
1500
+                            // Prepare to use next color
1415 1501
                         }
1416 1502
                         //print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'<br>';
1417 1503
                         // Define color
@@ -1501,8 +1587,9 @@  discard block
 block discarded – undo
1501 1587
                             if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour) {
1502 1588
                                 $daterange .= dol_print_date($event->date_start_in_calendar, '%H:%M'); // Il faudrait utiliser ici tzuser, mais si on ne peut pas car qd on rentre un date dans fiche action, en input la conversion local->gmt se base sur le TZ server et non user
1503 1589
                                 if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
1504
-                                    if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend)
1505
-                                        $daterange .= '-';
1590
+                                    if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend) {
1591
+                                                                            $daterange .= '-';
1592
+                                    }
1506 1593
                                     //else
1507 1594
                                     //print '...';
1508 1595
                                 }
@@ -1514,11 +1601,12 @@  discard block
 block discarded – undo
1514 1601
                             }
1515 1602
                             // Hour end
1516 1603
                             if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
1517
-                                if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour)
1518
-                                    $daterange .= dol_print_date($event->date_end_in_calendar, '%H:%M'); // Il faudrait utiliser ici tzuser, mais si on ne peut pas car qd on rentre un date dans fiche action, en input la conversion local->gmt se base sur le TZ server et non user
1604
+                                if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour) {
1605
+                                                                    $daterange .= dol_print_date($event->date_end_in_calendar, '%H:%M');
1606
+                                }
1607
+                                // Il faudrait utiliser ici tzuser, mais si on ne peut pas car qd on rentre un date dans fiche action, en input la conversion local->gmt se base sur le TZ server et non user
1519 1608
                             }
1520
-                        }
1521
-                        else {
1609
+                        } else {
1522 1610
                             if ($showinfo) {
1523 1611
                                 print $langs->trans("EventOnFullDay") . "<br>\n";
1524 1612
                             }
@@ -1528,9 +1616,9 @@  discard block
 block discarded – undo
1528 1616
                         $titletoshow = $daterange;
1529 1617
                         $titletoshow .= ($titletoshow ? ' ' : '') . $event->libelle;
1530 1618
 
1531
-                        if ($event->type_code == 'ICALEVENT')
1532
-                            print $titletoshow;
1533
-                        else {
1619
+                        if ($event->type_code == 'ICALEVENT') {
1620
+                                                    print $titletoshow;
1621
+                        } else {
1534 1622
                             $savlabel = $event->label ? $event->label : $event->libelle;
1535 1623
                             $event->label = $titletoshow;
1536 1624
                             $event->libelle = $titletoshow;
@@ -1543,8 +1631,9 @@  discard block
 block discarded – undo
1543 1631
                         $listofusertoshow = '';
1544 1632
                         $posuserassigned = 0;
1545 1633
                         foreach ($event->userassigned as $tmpid => $tmpdata) {
1546
-                            if (!$posuserassigned && $titletoshow)
1547
-                                $listofusertoshow .= '<br>';
1634
+                            if (!$posuserassigned && $titletoshow) {
1635
+                                                            $listofusertoshow .= '<br>';
1636
+                            }
1548 1637
                             $posuserassigned++;
1549 1638
                             if (empty($cacheusers[$tmpid])) {
1550 1639
                                 $newuser = new User($db);
@@ -1556,8 +1645,9 @@  discard block
 block discarded – undo
1556 1645
                         }
1557 1646
                         print $listofusertoshow;
1558 1647
 
1559
-                        if ($event->type_code == 'ICALEVENT')
1560
-                            print '<br>(' . dol_trunc($event->icalname, $maxnbofchar) . ')';
1648
+                        if ($event->type_code == 'ICALEVENT') {
1649
+                                                    print '<br>(' . dol_trunc($event->icalname, $maxnbofchar) . ')';
1650
+                        }
1561 1651
 
1562 1652
                         // If action related to company / contact
1563 1653
                         $linerelatedto = '';
@@ -1566,31 +1656,38 @@  discard block
 block discarded – undo
1566 1656
                                 $thirdparty = new Societe($db);
1567 1657
                                 $thirdparty->fetch($event->societe->id);
1568 1658
                                 $cachethirdparties[$event->societe->id] = $thirdparty;
1569
-                            } else
1570
-                                $thirdparty = $cachethirdparties[$event->societe->id];
1571
-                            if (!empty($thirdparty->id))
1572
-                                $linerelatedto .= $thirdparty->getNomUrl(1, '', 0);
1659
+                            } else {
1660
+                                                            $thirdparty = $cachethirdparties[$event->societe->id];
1661
+                            }
1662
+                            if (!empty($thirdparty->id)) {
1663
+                                                            $linerelatedto .= $thirdparty->getNomUrl(1, '', 0);
1664
+                            }
1573 1665
                         }
1574 1666
                         if (!empty($event->contact->id) && $event->contact->id > 0) {
1575 1667
                             if (!is_object($cachecontacts[$event->contact->id])) {
1576 1668
                                 $contact = new Contact($db);
1577 1669
                                 $contact->fetch($event->contact->id);
1578 1670
                                 $cachecontacts[$event->contact->id] = $contact;
1579
-                            } else
1580
-                                $contact = $cachecontacts[$event->contact->id];
1581
-                            if ($linerelatedto)
1582
-                                $linerelatedto .= '&nbsp;';
1583
-                            if (!empty($contact->id))
1584
-                                $linerelatedto .= $contact->getNomUrl(1, '', 0);
1671
+                            } else {
1672
+                                                            $contact = $cachecontacts[$event->contact->id];
1673
+                            }
1674
+                            if ($linerelatedto) {
1675
+                                                            $linerelatedto .= '&nbsp;';
1676
+                            }
1677
+                            if (!empty($contact->id)) {
1678
+                                                            $linerelatedto .= $contact->getNomUrl(1, '', 0);
1679
+                            }
1585 1680
                         }
1586 1681
                         if (!empty($event->fk_element) && $event->fk_element > 0 && !empty($event->elementtype) && !empty($conf->global->AGENDA_SHOW_LINKED_OBJECT)) {
1587 1682
                             include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
1588
-                            if ($linerelatedto)
1589
-                                $linerelatedto .= '<br>';
1683
+                            if ($linerelatedto) {
1684
+                                                            $linerelatedto .= '<br>';
1685
+                            }
1590 1686
                             $linerelatedto .= dolGetElementUrl($event->fk_element, $event->elementtype, 1);
1591 1687
                         }
1592
-                        if ($linerelatedto)
1593
-                            print '<br>' . $linerelatedto;
1688
+                        if ($linerelatedto) {
1689
+                                                    print '<br>' . $linerelatedto;
1690
+                        }
1594 1691
                     }
1595 1692
 
1596 1693
                     // Show location
@@ -1606,19 +1703,20 @@  discard block
 block discarded – undo
1606 1703
                     $withstatus = 0;
1607 1704
                     if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT') {
1608 1705
                         $withstatus = 1;
1609
-                        if ($event->percentage >= 0)
1610
-                            $withstatus = 2;
1706
+                        if ($event->percentage >= 0) {
1707
+                                                    $withstatus = 2;
1708
+                        }
1611 1709
                     }
1612 1710
                     print '<td class="nobottom right nowrap cal_event_right' . ($withstatus >= 2 ? ' cal_event_right_status' : '') . '">';
1613
-                    if ($withstatus)
1614
-                        print $event->getLibStatut(3, 1);
1615
-                    else
1616
-                        print '&nbsp;';
1711
+                    if ($withstatus) {
1712
+                                            print $event->getLibStatut(3, 1);
1713
+                    } else {
1714
+                                            print '&nbsp;';
1715
+                    }
1617 1716
                     print '</td></tr></table>';
1618 1717
                     print '</div><!-- end event ' . $i . ' -->' . "\n";
1619 1718
                     $i++;
1620
-                }
1621
-                else {
1719
+                } else {
1622 1720
                     print '<a href="' . BASE_URI . '?controller=comm/action&method=index&action=' . $action . '&maxprint=0&month=' . $monthshown . '&year=' . $year;
1623 1721
                     print ($status ? '&status=' . $status : '') . ($filter ? '&filter=' . $filter : '');
1624 1722
                     print ($filtert ? '&filtert=' . $filtert : '');
@@ -1635,8 +1733,9 @@  discard block
 block discarded – undo
1635 1733
             break;
1636 1734
         }
1637 1735
     }
1638
-    if (!$i)
1639
-        print '&nbsp;';
1736
+    if (!$i) {
1737
+            print '&nbsp;';
1738
+    }
1640 1739
 
1641 1740
     if (!empty($conf->global->MAIN_JS_SWITCH_AGENDA) && $i > $maxprint && $maxprint) {
1642 1741
         print '<div id="more_' . $ymd . '">' . img_picto("all", "1downarrow_selected.png") . ' +' . $langs->trans("More") . '...</div>';
Please login to merge, or discard this patch.
dolibarr/htdocs/comm/action/list.php 1 patch
Braces   +243 added lines, -158 removed lines patch added patch discarded remove patch
@@ -58,10 +58,10 @@  discard block
 block discarded – undo
58 58
 // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
59 59
 if (GETPOST('search_actioncode', 'array')) {
60 60
     $actioncode = GETPOST('search_actioncode', 'array', 3);
61
-    if (!count($actioncode))
62
-        $actioncode = '0';
63
-}
64
-else {
61
+    if (!count($actioncode)) {
62
+            $actioncode = '0';
63
+    }
64
+    } else {
65 65
     $actioncode = GETPOST("search_actioncode", "alpha", 3) ? GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE));
66 66
 }
67 67
 if ($actioncode == '' && empty($actioncodearray)) {
@@ -108,30 +108,36 @@  discard block
 block discarded – undo
108 108
 $offset = $limit * $page;
109 109
 if (!$sortorder) {
110 110
     $sortorder = "DESC";
111
-    if ($status == 'todo')
112
-        $sortorder = "DESC";
111
+    if ($status == 'todo') {
112
+            $sortorder = "DESC";
113
+    }
113 114
     //if ($status == 'done') $sortorder="DESC";
114 115
 }
115 116
 if (!$sortfield) {
116 117
     $sortfield = "a.datep";
117
-    if ($status == 'todo')
118
-        $sortfield = "a.datep";
118
+    if ($status == 'todo') {
119
+            $sortfield = "a.datep";
120
+    }
119 121
     //if ($status == 'done') $sortfield="a.datep2";
120 122
 }
121 123
 
122 124
 // Security check
123 125
 $socid = GETPOST("search_socid", 'int') ? GETPOST("search_socid", 'int') : GETPOST("socid", 'int');
124
-if ($user->societe_id)
126
+if ($user->societe_id) {
125 127
     $socid = $user->societe_id;
128
+}
126 129
 $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
127
-if ($socid < 0)
130
+if ($socid < 0) {
128 131
     $socid = '';
132
+}
129 133
 
130 134
 $canedit = 1;
131
-if (!$user->rights->agenda->myactions->read)
135
+if (!$user->rights->agenda->myactions->read) {
132 136
     accessforbidden();
133
-if (!$user->rights->agenda->allactions->read)
137
+}
138
+if (!$user->rights->agenda->allactions->read) {
134 139
     $canedit = 0;
140
+}
135 141
 if (!$user->rights->agenda->allactions->read || $filter == 'mine') { // If no permission to see all, we show only affected to me
136 142
     $filtert = $user->id;
137 143
 }
@@ -153,8 +159,9 @@  discard block
 block discarded – undo
153 159
 // Extra fields
154 160
 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) {
155 161
     foreach ($extrafields->attribute_label as $key => $val) {
156
-        if (!empty($extrafields->attribute_list[$key]))
157
-            $arrayfields["ef." . $key] = array('label' => $extrafields->attribute_label[$key], 'checked' => $extrafields->attribute_list[$key], 'position' => $extrafields->attribute_pos[$key], 'enabled' => $extrafields->attribute_perms[$key]);
162
+        if (!empty($extrafields->attribute_list[$key])) {
163
+                    $arrayfields["ef." . $key] = array('label' => $extrafields->attribute_label[$key], 'checked' => $extrafields->attribute_list[$key], 'position' => $extrafields->attribute_pos[$key], 'enabled' => $extrafields->attribute_perms[$key]);
164
+        }
158 165
     }
159 166
 }
160 167
 
@@ -177,8 +184,9 @@  discard block
 block discarded – undo
177 184
 
178 185
 $parameters = array('id' => $socid);
179 186
 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);    // Note that $action and $object may have been modified by some hooks
180
-if ($reshook < 0)
187
+if ($reshook < 0) {
181 188
     setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
189
+}
182 190
 
183 191
 // Selection of new fields
184 192
 include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php';
@@ -215,59 +223,82 @@  discard block
 block discarded – undo
215 223
 $listofextcals = array();
216 224
 
217 225
 $param = '';
218
-if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"])
226
+if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
219 227
     $param .= '&contextpage=' . urlencode($contextpage);
220
-if ($limit > 0 && $limit != $conf->liste_limit)
228
+}
229
+if ($limit > 0 && $limit != $conf->liste_limit) {
221 230
     $param .= '&limit=' . urlencode($limit);
231
+}
222 232
 if ($actioncode != '') {
223 233
     if (is_array($actioncode)) {
224
-        foreach ($actioncode as $str_action)
225
-            $param .= "&search_actioncode[]=" . urlencode($str_action);
226
-    } else
227
-        $param .= "&search_actioncode=" . urlencode($actioncode);
228
-}
229
-if ($resourceid > 0)
234
+        foreach ($actioncode as $str_action) {
235
+                    $param .= "&search_actioncode[]=" . urlencode($str_action);
236
+        }
237
+    } else {
238
+            $param .= "&search_actioncode=" . urlencode($actioncode);
239
+    }
240
+    }
241
+if ($resourceid > 0) {
230 242
     $param .= "&search_resourceid=" . urlencode($resourceid);
231
-if ($status != '' && $status > -1)
243
+}
244
+if ($status != '' && $status > -1) {
232 245
     $param .= "&search_status=" . urlencode($status);
233
-if ($filter)
246
+}
247
+if ($filter) {
234 248
     $param .= "&search_filter=" . urlencode($filter);
235
-if ($filtert)
249
+}
250
+if ($filtert) {
236 251
     $param .= "&search_filtert=" . urlencode($filtert);
237
-if ($socid)
252
+}
253
+if ($socid) {
238 254
     $param .= "&search_socid=" . urlencode($socid);
239
-if ($showbirthday)
255
+}
256
+if ($showbirthday) {
240 257
     $param .= "&search_showbirthday=1";
241
-if ($pid)
258
+}
259
+if ($pid) {
242 260
     $param .= "&search_projectid=" . urlencode($pid);
243
-if ($type)
261
+}
262
+if ($type) {
244 263
     $param .= "&search_type=" . urlencode($type);
245
-if ($usergroup)
264
+}
265
+if ($usergroup) {
246 266
     $param .= "&search_usergroup=" . urlencode($usergroup);
247
-if ($search_id != '')
267
+}
268
+if ($search_id != '') {
248 269
     $param .= '&search_title=' . urlencode($search_id);
249
-if ($search_title != '')
270
+}
271
+if ($search_title != '') {
250 272
     $param .= '&search_title=' . urlencode($search_title);
251
-if (GETPOST('datestartday', 'int'))
273
+}
274
+if (GETPOST('datestartday', 'int')) {
252 275
     $param .= '&datestartday=' . GETPOST('datestartday', 'int');
253
-if (GETPOST('datestartmonth', 'int'))
276
+}
277
+if (GETPOST('datestartmonth', 'int')) {
254 278
     $param .= '&datestartmonth=' . GETPOST('datestartmonth', 'int');
255
-if (GETPOST('datestartyear', 'int'))
279
+}
280
+if (GETPOST('datestartyear', 'int')) {
256 281
     $param .= '&datestartyear=' . GETPOST('datestartyear', 'int');
257
-if (GETPOST('dateendday', 'int'))
282
+}
283
+if (GETPOST('dateendday', 'int')) {
258 284
     $param .= '&dateendday=' . GETPOST('dateendday', 'int');
259
-if (GETPOST('dateendmonth', 'int'))
285
+}
286
+if (GETPOST('dateendmonth', 'int')) {
260 287
     $param .= '&dateendmonth=' . GETPOST('dateendmonth', 'int');
261
-if (GETPOST('dateendyear', 'int'))
288
+}
289
+if (GETPOST('dateendyear', 'int')) {
262 290
     $param .= '&dateendyear=' . GETPOST('dateendyear', 'int');
263
-if ($optioncss != '')
291
+}
292
+if ($optioncss != '') {
264 293
     $param .= '&optioncss=' . urlencode($optioncss);
294
+}
265 295
 // Add $param from extra fields
266 296
 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php';
267 297
 
268 298
 $sql = "SELECT";
269
-if ($usergroup > 0)
299
+if ($usergroup > 0) {
270 300
     $sql .= " DISTINCT";
301
+}
271 302
 $sql .= " s.nom as societe, s.rowid as socid, s.client, s.email as socemail,";
272 303
 $sql .= " a.id, a.label, a.datep as dp, a.datep2 as dp2,";
273 304
 $sql .= ' a.fk_user_author,a.fk_user_action,';
@@ -276,45 +307,51 @@  discard block
 block discarded – undo
276 307
 $sql .= " c.code as type_code, c.libelle as type_label,";
277 308
 $sql .= " sp.lastname, sp.firstname, sp.email, sp.phone, sp.address, sp.phone as phone_pro, sp.phone_mobile, sp.phone_perso, sp.fk_pays as country_id";
278 309
 // Add fields from extrafields
279
-foreach ($extrafields->attribute_label as $key => $val)
310
+foreach ($extrafields->attribute_label as $key => $val) {
280 311
     $sql .= ($extrafields->attribute_type[$key] != 'separate' ? ",ef." . $key . ' as options_' . $key : '');
312
+}
281 313
 $sql .= " FROM " . MAIN_DB_PREFIX . "actioncomm as a";
282 314
 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "actioncomm_extrafields as ef ON (a.id = ef.fk_object) ";
283
-if (!$user->rights->societe->client->voir && !$socid)
315
+if (!$user->rights->societe->client->voir && !$socid) {
284 316
     $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
317
+}
285 318
 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON a.fk_soc = s.rowid";
286 319
 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople as sp ON a.fk_contact = sp.rowid";
287 320
 $sql .= " ," . MAIN_DB_PREFIX . "c_actioncomm as c";
288 321
 // We must filter on resource table
289
-if ($resourceid > 0)
322
+if ($resourceid > 0) {
290 323
     $sql .= ", " . MAIN_DB_PREFIX . "element_resources as r";
324
+}
291 325
 // We must filter on assignement table
292
-if ($filtert > 0 || $usergroup > 0)
326
+if ($filtert > 0 || $usergroup > 0) {
293 327
     $sql .= ", " . MAIN_DB_PREFIX . "actioncomm_resources as ar";
294
-if ($usergroup > 0)
328
+}
329
+if ($usergroup > 0) {
295 330
     $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
331
+}
296 332
 $sql .= " WHERE c.id = a.fk_action";
297 333
 $sql .= ' AND a.entity IN (' . getEntity('agenda') . ')';
298 334
 // Condition on actioncode
299 335
 if (!empty($actioncode)) {
300 336
     if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
301
-        if ($actioncode == 'AC_NON_AUTO')
302
-            $sql .= " AND c.type != 'systemauto'";
303
-        elseif ($actioncode == 'AC_ALL_AUTO')
304
-            $sql .= " AND c.type = 'systemauto'";
305
-        else {
306
-            if ($actioncode == 'AC_OTH')
307
-                $sql .= " AND c.type != 'systemauto'";
308
-            if ($actioncode == 'AC_OTH_AUTO')
309
-                $sql .= " AND c.type = 'systemauto'";
337
+        if ($actioncode == 'AC_NON_AUTO') {
338
+                    $sql .= " AND c.type != 'systemauto'";
339
+        } elseif ($actioncode == 'AC_ALL_AUTO') {
340
+                    $sql .= " AND c.type = 'systemauto'";
341
+        } else {
342
+            if ($actioncode == 'AC_OTH') {
343
+                            $sql .= " AND c.type != 'systemauto'";
344
+            }
345
+            if ($actioncode == 'AC_OTH_AUTO') {
346
+                            $sql .= " AND c.type = 'systemauto'";
347
+            }
310 348
         }
311
-    }
312
-    else {
313
-        if ($actioncode == 'AC_NON_AUTO')
314
-            $sql .= " AND c.type != 'systemauto'";
315
-        elseif ($actioncode == 'AC_ALL_AUTO')
316
-            $sql .= " AND c.type = 'systemauto'";
317
-        else {
349
+    } else {
350
+        if ($actioncode == 'AC_NON_AUTO') {
351
+                    $sql .= " AND c.type != 'systemauto'";
352
+        } elseif ($actioncode == 'AC_ALL_AUTO') {
353
+                    $sql .= " AND c.type = 'systemauto'";
354
+        } else {
318 355
             if (is_array($actioncode)) {
319 356
                 $sql .= " AND c.code IN ('" . implode("','", $actioncode) . "')";
320 357
             } else {
@@ -323,19 +360,25 @@  discard block
 block discarded – undo
323 360
         }
324 361
     }
325 362
 }
326
-if ($resourceid > 0)
363
+if ($resourceid > 0) {
327 364
     $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = " . $db->escape($resourceid);
328
-if ($pid)
365
+}
366
+if ($pid) {
329 367
     $sql .= " AND a.fk_project=" . $db->escape($pid);
330
-if (!$user->rights->societe->client->voir && !$socid)
368
+}
369
+if (!$user->rights->societe->client->voir && !$socid) {
331 370
     $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = " . $user->id . ")";
332
-if ($socid > 0)
371
+}
372
+if ($socid > 0) {
333 373
     $sql .= " AND s.rowid = " . $socid;
374
+}
334 375
 // We must filter on assignement table
335
-if ($filtert > 0 || $usergroup > 0)
376
+if ($filtert > 0 || $usergroup > 0) {
336 377
     $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
337
-if ($type)
378
+}
379
+if ($type) {
338 380
     $sql .= " AND c.id = " . $type;
381
+}
339 382
 if ($status == '0') {
340 383
     $sql .= " AND a.percent = 0";
341 384
 }
@@ -354,27 +397,35 @@  discard block
 block discarded – undo
354 397
 if ($status == 'todo') {
355 398
     $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
356 399
 }
357
-if ($search_id)
400
+if ($search_id) {
358 401
     $sql .= natural_search("a.id", $search_id, 1);
359
-if ($search_title)
402
+}
403
+if ($search_title) {
360 404
     $sql .= natural_search("a.label", $search_title);
405
+}
361 406
 // We must filter on assignement table
362 407
 if ($filtert > 0 || $usergroup > 0) {
363 408
     $sql .= " AND (";
364
-    if ($filtert > 0)
365
-        $sql .= "(ar.fk_element = " . $filtert . " OR (ar.fk_element IS NULL AND a.fk_user_action=" . $filtert . "))"; // The OR is for backward compatibility
366
-    if ($usergroup > 0)
367
-        $sql .= ($filtert > 0 ? " OR " : "") . " ugu.fk_usergroup = " . $usergroup;
409
+    if ($filtert > 0) {
410
+            $sql .= "(ar.fk_element = " . $filtert . " OR (ar.fk_element IS NULL AND a.fk_user_action=" . $filtert . "))";
411
+    }
412
+    // The OR is for backward compatibility
413
+    if ($usergroup > 0) {
414
+            $sql .= ($filtert > 0 ? " OR " : "") . " ugu.fk_usergroup = " . $usergroup;
415
+    }
368 416
     $sql .= ")";
369 417
 }
370 418
 
371 419
 // The second or of next test is to take event with no end date (we suppose duration is 1 hour in such case)
372
-if ($dateselect > 0)
420
+if ($dateselect > 0) {
373 421
     $sql .= " AND ((a.datep2 >= '" . $db->idate($dateselect) . "' AND a.datep <= '" . $db->idate($dateselect + 3600 * 24 - 1) . "') OR (a.datep2 IS NULL AND a.datep > '" . $db->idate($dateselect - 3600) . "' AND a.datep <= '" . $db->idate($dateselect + 3600 * 24 - 1) . "'))";
374
-if ($datestart > 0)
422
+}
423
+if ($datestart > 0) {
375 424
     $sql .= " AND a.datep BETWEEN '" . $db->idate($datestart) . "' AND '" . $db->idate($datestart + 3600 * 24 - 1) . "'";
376
-if ($dateend > 0)
425
+}
426
+if ($dateend > 0) {
377 427
     $sql .= " AND a.datep2 BETWEEN '" . $db->idate($dateend) . "' AND '" . $db->idate($dateend + 3600 * 24 - 1) . "'";
428
+}
378 429
 // Add where from extra fields
379 430
 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php';
380 431
 
@@ -411,8 +462,9 @@  discard block
 block discarded – undo
411 462
 
412 463
     print '<form method="POST" id="searchFormList" class="listactionsfilter" action="' . $_SERVER["PHP_SELF"] . '">' . "\n";
413 464
 
414
-    if ($optioncss != '')
415
-        print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
465
+    if ($optioncss != '') {
466
+            print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
467
+    }
416 468
     print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
417 469
     print '<input type="hidden" name="action" value="list">';
418 470
     print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
@@ -424,12 +476,14 @@  discard block
 block discarded – undo
424 476
 
425 477
     //if ($actioncode)    $nav.='<input type="hidden" name="actioncode" value="'.$actioncode.'">';
426 478
     //if ($resourceid)      $nav.='<input type="hidden" name="resourceid" value="'.$resourceid.'">';
427
-    if ($filter)
428
-        $nav .= '<input type="hidden" name="search_filter" value="' . $filter . '">';
479
+    if ($filter) {
480
+            $nav .= '<input type="hidden" name="search_filter" value="' . $filter . '">';
481
+    }
429 482
     //if ($filtert)         $nav.='<input type="hidden" name="filtert" value="'.$filtert.'">';
430 483
     //if ($socid)           $nav.='<input type="hidden" name="socid" value="'.$socid.'">';
431
-    if ($showbirthday)
432
-        $nav .= '<input type="hidden" name="search_showbirthday" value="1">';
484
+    if ($showbirthday) {
485
+            $nav .= '<input type="hidden" name="search_showbirthday" value="1">';
486
+    }
433 487
     //if ($pid)             $nav.='<input type="hidden" name="projectid" value="'.$pid.'">';
434 488
     //if ($usergroup)       $nav.='<input type="hidden" name="usergroup" value="'.$usergroup.'">';
435 489
     print $nav;
@@ -486,21 +540,26 @@  discard block
 block discarded – undo
486 540
 
487 541
     $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
488 542
     $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
489
-    if ($massactionbutton)
490
-        $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
543
+    if ($massactionbutton) {
544
+            $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
545
+    }
491 546
     $i = 0;
492 547
     print '<div class="div-table-responsive">';
493 548
     print '<table class="tagtable liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n";
494 549
 
495 550
     print '<tr class="liste_titre_filter">';
496
-    if (!empty($arrayfields['a.id']['checked']))
497
-        print '<td class="liste_titre"><input type="text" class="maxwidth50" name="search_id" value="' . $search_id . '"></td>';
498
-    if (!empty($arrayfields['owner']['checked']))
499
-        print '<td class="liste_titre"></td>';
500
-    if (!empty($arrayfields['c.libelle']['checked']))
501
-        print '<td class="liste_titre"></td>';
502
-    if (!empty($arrayfields['a.label']['checked']))
503
-        print '<td class="liste_titre"><input type="text" class="maxwidth75" name="search_title" value="' . $search_title . '"></td>';
551
+    if (!empty($arrayfields['a.id']['checked'])) {
552
+            print '<td class="liste_titre"><input type="text" class="maxwidth50" name="search_id" value="' . $search_id . '"></td>';
553
+    }
554
+    if (!empty($arrayfields['owner']['checked'])) {
555
+            print '<td class="liste_titre"></td>';
556
+    }
557
+    if (!empty($arrayfields['c.libelle']['checked'])) {
558
+            print '<td class="liste_titre"></td>';
559
+    }
560
+    if (!empty($arrayfields['a.label']['checked'])) {
561
+            print '<td class="liste_titre"><input type="text" class="maxwidth75" name="search_title" value="' . $search_title . '"></td>';
562
+    }
504 563
     if (!empty($arrayfields['a.datep']['checked'])) {
505 564
         print '<td class="liste_titre nowraponall" align="center">';
506 565
         print $form->selectDate($datestart, 'datestart', 0, 0, 1, '', 1, 0);
@@ -514,10 +573,12 @@  discard block
 block discarded – undo
514 573
     if (!empty($arrayfields['s.nom']['checked'])) {
515 574
         print '<td class="liste_titre"></td>';
516 575
     }
517
-    if (!empty($arrayfields['a.fk_contact']['checked']))
518
-        print '<td class="liste_titre"></td>';
519
-    if (!empty($arrayfields['a.fk_element']['checked']))
520
-        print '<td class="liste_titre"></td>';
576
+    if (!empty($arrayfields['a.fk_contact']['checked'])) {
577
+            print '<td class="liste_titre"></td>';
578
+    }
579
+    if (!empty($arrayfields['a.fk_element']['checked'])) {
580
+            print '<td class="liste_titre"></td>';
581
+    }
521 582
 
522 583
     // Extra fields
523 584
     include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php';
@@ -527,10 +588,12 @@  discard block
 block discarded – undo
527 588
     $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters);    // Note that $action and $object may have been modified by hook
528 589
     print $hookmanager->resPrint;
529 590
 
530
-    if (!empty($arrayfields['a.datec']['checked']))
531
-        print '<td class="liste_titre"></td>';
532
-    if (!empty($arrayfields['a.tms']['checked']))
533
-        print '<td class="liste_titre"></td>';
591
+    if (!empty($arrayfields['a.datec']['checked'])) {
592
+            print '<td class="liste_titre"></td>';
593
+    }
594
+    if (!empty($arrayfields['a.tms']['checked'])) {
595
+            print '<td class="liste_titre"></td>';
596
+    }
534 597
     if (!empty($arrayfields['a.percent']['checked'])) {
535 598
         print '<td class="liste_titre center">';
536 599
         print $formactions->form_select_status_action('formaction', $status, 1, 'status', 1, 2);
@@ -545,25 +608,34 @@  discard block
 block discarded – undo
545 608
     print "</tr>\n";
546 609
 
547 610
     print '<tr class="liste_titre">';
548
-    if (!empty($arrayfields['a.id']['checked']))
549
-        print_liste_field_titre($arrayfields['a.id']['label'], $_SERVER["PHP_SELF"], "a.id", $param, "", "", $sortfield, $sortorder);
550
-    if (!empty($arrayfields['owner']['checked']))
551
-        print_liste_field_titre($arrayfields['owner']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder);
552
-    if (!empty($arrayfields['c.libelle']['checked']))
553
-        print_liste_field_titre($arrayfields['c.libelle']['label'], $_SERVER["PHP_SELF"], "c.libelle", $param, "", "", $sortfield, $sortorder);
554
-    if (!empty($arrayfields['a.label']['checked']))
555
-        print_liste_field_titre($arrayfields['a.label']['label'], $_SERVER["PHP_SELF"], "a.label", $param, "", "", $sortfield, $sortorder);
611
+    if (!empty($arrayfields['a.id']['checked'])) {
612
+            print_liste_field_titre($arrayfields['a.id']['label'], $_SERVER["PHP_SELF"], "a.id", $param, "", "", $sortfield, $sortorder);
613
+    }
614
+    if (!empty($arrayfields['owner']['checked'])) {
615
+            print_liste_field_titre($arrayfields['owner']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder);
616
+    }
617
+    if (!empty($arrayfields['c.libelle']['checked'])) {
618
+            print_liste_field_titre($arrayfields['c.libelle']['label'], $_SERVER["PHP_SELF"], "c.libelle", $param, "", "", $sortfield, $sortorder);
619
+    }
620
+    if (!empty($arrayfields['a.label']['checked'])) {
621
+            print_liste_field_titre($arrayfields['a.label']['label'], $_SERVER["PHP_SELF"], "a.label", $param, "", "", $sortfield, $sortorder);
622
+    }
556 623
     //if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
557
-    if (!empty($arrayfields['a.datep']['checked']))
558
-        print_liste_field_titre($arrayfields['a.datep']['label'], $_SERVER["PHP_SELF"], "a.datep", $param, '', 'align="center"', $sortfield, $sortorder);
559
-    if (!empty($arrayfields['a.datep2']['checked']))
560
-        print_liste_field_titre($arrayfields['a.datep2']['label'], $_SERVER["PHP_SELF"], "a.datep2", $param, '', 'align="center"', $sortfield, $sortorder);
561
-    if (!empty($arrayfields['s.nom']['checked']))
562
-        print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", $param, "", "", $sortfield, $sortorder);
563
-    if (!empty($arrayfields['a.fk_contact']['checked']))
564
-        print_liste_field_titre($arrayfields['a.fk_contact']['label'], $_SERVER["PHP_SELF"], "a.fk_contact", $param, "", "", $sortfield, $sortorder);
565
-    if (!empty($arrayfields['a.fk_element']['checked']))
566
-        print_liste_field_titre($arrayfields['a.fk_element']['label'], $_SERVER["PHP_SELF"], "a.fk_element", $param, "", "", $sortfield, $sortorder);
624
+    if (!empty($arrayfields['a.datep']['checked'])) {
625
+            print_liste_field_titre($arrayfields['a.datep']['label'], $_SERVER["PHP_SELF"], "a.datep", $param, '', 'align="center"', $sortfield, $sortorder);
626
+    }
627
+    if (!empty($arrayfields['a.datep2']['checked'])) {
628
+            print_liste_field_titre($arrayfields['a.datep2']['label'], $_SERVER["PHP_SELF"], "a.datep2", $param, '', 'align="center"', $sortfield, $sortorder);
629
+    }
630
+    if (!empty($arrayfields['s.nom']['checked'])) {
631
+            print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", $param, "", "", $sortfield, $sortorder);
632
+    }
633
+    if (!empty($arrayfields['a.fk_contact']['checked'])) {
634
+            print_liste_field_titre($arrayfields['a.fk_contact']['label'], $_SERVER["PHP_SELF"], "a.fk_contact", $param, "", "", $sortfield, $sortorder);
635
+    }
636
+    if (!empty($arrayfields['a.fk_element']['checked'])) {
637
+            print_liste_field_titre($arrayfields['a.fk_element']['label'], $_SERVER["PHP_SELF"], "a.fk_element", $param, "", "", $sortfield, $sortorder);
638
+    }
567 639
 
568 640
     // Extra fields
569 641
     include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php';
@@ -573,13 +645,16 @@  discard block
 block discarded – undo
573 645
     $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters);    // Note that $action and $object may have been modified by hook
574 646
     print $hookmanager->resPrint;
575 647
 
576
-    if (!empty($arrayfields['a.datec']['checked']))
577
-        print_liste_field_titre($arrayfields['a.datec']['label'], $_SERVER["PHP_SELF"], "a.datec,a.id", $param, "", 'align="center"', $sortfield, $sortorder);
578
-    if (!empty($arrayfields['a.tms']['checked']))
579
-        print_liste_field_titre($arrayfields['a.tms']['label'], $_SERVER["PHP_SELF"], "a.tms,a.id", $param, "", 'align="center"', $sortfield, $sortorder);
648
+    if (!empty($arrayfields['a.datec']['checked'])) {
649
+            print_liste_field_titre($arrayfields['a.datec']['label'], $_SERVER["PHP_SELF"], "a.datec,a.id", $param, "", 'align="center"', $sortfield, $sortorder);
650
+    }
651
+    if (!empty($arrayfields['a.tms']['checked'])) {
652
+            print_liste_field_titre($arrayfields['a.tms']['label'], $_SERVER["PHP_SELF"], "a.tms,a.id", $param, "", 'align="center"', $sortfield, $sortorder);
653
+    }
580 654
 
581
-    if (!empty($arrayfields['a.percent']['checked']))
582
-        print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "a.percent", $param, "", 'align="center"', $sortfield, $sortorder);
655
+    if (!empty($arrayfields['a.percent']['checked'])) {
656
+            print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "a.percent", $param, "", 'align="center"', $sortfield, $sortorder);
657
+    }
583 658
     print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
584 659
     print "</tr>\n";
585 660
 
@@ -622,8 +697,9 @@  discard block
 block discarded – undo
622 697
             if ($obj->fk_user_action > 0) {
623 698
                 $userstatic->fetch($obj->fk_user_action);
624 699
                 print $userstatic->getNomUrl(-1);
625
-            } else
626
-                print '&nbsp;';
700
+            } else {
701
+                            print '&nbsp;';
702
+            }
627 703
             print '</td>';
628 704
         }
629 705
 
@@ -631,28 +707,31 @@  discard block
 block discarded – undo
631 707
         if (!empty($arrayfields['c.libelle']['checked'])) {
632 708
             print '<td>';
633 709
             if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
634
-                if ($actionstatic->type_picto)
635
-                    print img_picto('', $actionstatic->type_picto);
636
-                else {
637
-                    if ($actionstatic->type_code == 'AC_RDV')
638
-                        print img_picto('', 'object_group', '', false, 0, 0, '', 'paddingright') . ' ';
639
-                    elseif ($actionstatic->type_code == 'AC_TEL')
640
-                        print img_picto('', 'object_phoning', '', false, 0, 0, '', 'paddingright') . ' ';
641
-                    elseif ($actionstatic->type_code == 'AC_FAX')
642
-                        print img_picto('', 'object_phoning_fax', '', false, 0, 0, '', 'paddingright') . ' ';
643
-                    elseif ($actionstatic->type_code == 'AC_EMAIL')
644
-                        print img_picto('', 'object_email', '', false, 0, 0, '', 'paddingright') . ' ';
645
-                    elseif ($actionstatic->type_code == 'AC_INT')
646
-                        print img_picto('', 'object_intervention', '', false, 0, 0, '', 'paddingright') . ' ';
647
-                    elseif (!preg_match('/_AUTO/', $actionstatic->type_code))
648
-                        print img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright') . ' ';
710
+                if ($actionstatic->type_picto) {
711
+                                    print img_picto('', $actionstatic->type_picto);
712
+                } else {
713
+                    if ($actionstatic->type_code == 'AC_RDV') {
714
+                                            print img_picto('', 'object_group', '', false, 0, 0, '', 'paddingright') . ' ';
715
+                    } elseif ($actionstatic->type_code == 'AC_TEL') {
716
+                                            print img_picto('', 'object_phoning', '', false, 0, 0, '', 'paddingright') . ' ';
717
+                    } elseif ($actionstatic->type_code == 'AC_FAX') {
718
+                                            print img_picto('', 'object_phoning_fax', '', false, 0, 0, '', 'paddingright') . ' ';
719
+                    } elseif ($actionstatic->type_code == 'AC_EMAIL') {
720
+                                            print img_picto('', 'object_email', '', false, 0, 0, '', 'paddingright') . ' ';
721
+                    } elseif ($actionstatic->type_code == 'AC_INT') {
722
+                                            print img_picto('', 'object_intervention', '', false, 0, 0, '', 'paddingright') . ' ';
723
+                    } elseif (!preg_match('/_AUTO/', $actionstatic->type_code)) {
724
+                                            print img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright') . ' ';
725
+                    }
649 726
                 }
650 727
             }
651 728
             $labeltype = $obj->type_code;
652
-            if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($arraylist[$labeltype]))
653
-                $labeltype = 'AC_OTH';
654
-            if (!empty($arraylist[$labeltype]))
655
-                $labeltype = $arraylist[$labeltype];
729
+            if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($arraylist[$labeltype])) {
730
+                            $labeltype = 'AC_OTH';
731
+            }
732
+            if (!empty($arraylist[$labeltype])) {
733
+                            $labeltype = $arraylist[$labeltype];
734
+            }
656 735
             print dol_trunc($labeltype, 28);
657 736
             print '</td>';
658 737
         }
@@ -669,16 +748,21 @@  discard block
 block discarded – undo
669 748
             print '<td align="center">';
670 749
             print dol_print_date($db->jdate($obj->dp), "dayhour");
671 750
             $late = 0;
672
-            if ($obj->percent == 0 && $obj->dp && $db->jdate($obj->dp) < ($now - $delay_warning))
673
-                $late = 1;
674
-            if ($obj->percent == 0 && !$obj->dp && $obj->dp2 && $db->jdate($obj->dp) < ($now - $delay_warning))
675
-                $late = 1;
676
-            if ($obj->percent > 0 && $obj->percent < 100 && $obj->dp2 && $db->jdate($obj->dp2) < ($now - $delay_warning))
677
-                $late = 1;
678
-            if ($obj->percent > 0 && $obj->percent < 100 && !$obj->dp2 && $obj->dp && $db->jdate($obj->dp) < ($now - $delay_warning))
679
-                $late = 1;
680
-            if ($late)
681
-                print img_warning($langs->trans("Late")) . ' ';
751
+            if ($obj->percent == 0 && $obj->dp && $db->jdate($obj->dp) < ($now - $delay_warning)) {
752
+                            $late = 1;
753
+            }
754
+            if ($obj->percent == 0 && !$obj->dp && $obj->dp2 && $db->jdate($obj->dp) < ($now - $delay_warning)) {
755
+                            $late = 1;
756
+            }
757
+            if ($obj->percent > 0 && $obj->percent < 100 && $obj->dp2 && $db->jdate($obj->dp2) < ($now - $delay_warning)) {
758
+                            $late = 1;
759
+            }
760
+            if ($obj->percent > 0 && $obj->percent < 100 && !$obj->dp2 && $obj->dp && $db->jdate($obj->dp) < ($now - $delay_warning)) {
761
+                            $late = 1;
762
+            }
763
+            if ($late) {
764
+                            print img_warning($langs->trans("Late")) . ' ';
765
+            }
682 766
             print '</td>';
683 767
         }
684 768
 
@@ -699,8 +783,9 @@  discard block
 block discarded – undo
699 783
                 $societestatic->email = $obj->socemail;
700 784
 
701 785
                 print $societestatic->getNomUrl(1, '', 28);
702
-            } else
703
-                print '&nbsp;';
786
+            } else {
787
+                            print '&nbsp;';
788
+            }
704 789
             print '</td>';
705 790
         }
706 791
 
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/functions.lib.php 1 patch
Braces   +1455 added lines, -1043 removed lines patch added patch discarded remove patch
@@ -79,8 +79,9 @@  discard block
 block discarded – undo
79 79
       if ($found) return $result;
80 80
       } */
81 81
 
82
-    if (isset($class::$member))
83
-        return $class::$member;
82
+    if (isset($class::$member)) {
83
+            return $class::$member;
84
+    }
84 85
     dol_print_error('', 'Try to get a static member "' . $member . '" in class "' . $class . '" that does not exists or is not static.');
85 86
     return null;
86 87
 }
@@ -131,8 +132,9 @@  discard block
 block discarded – undo
131 132
     } else {
132 133
         $out = '';
133 134
         $addzero = array('user', 'usergroup', 'c_email_templates', 'email_template', 'default_values');
134
-        if (in_array($element, $addzero))
135
-            $out .= '0,';
135
+        if (in_array($element, $addzero)) {
136
+                    $out .= '0,';
137
+        }
136 138
         $out .= $conf->entity;
137 139
         return $out;
138 140
     }
@@ -313,32 +315,35 @@  discard block
 block discarded – undo
313 315
 
314 316
     Debug::addMessage('Deprecated', 'Using GETPOST of functions.lib.php instead of Request library');
315 317
 
316
-    if (empty($paramname))
317
-        return 'BadFirstParameterForGETPOST';
318
+    if (empty($paramname)) {
319
+            return 'BadFirstParameterForGETPOST';
320
+    }
318 321
     if (empty($check)) {
319 322
         dol_syslog("Deprecated use of GETPOST, called with 1st param = " . $paramname . " and 2nd param is '', when calling page " . $_SERVER["PHP_SELF"], LOG_WARNING);
320 323
         // Enable this line to know who call the GETPOST with '' $check parameter.
321 324
         //var_dump(debug_backtrace()[0]);
322 325
     }
323 326
 
324
-    if (empty($method))
325
-        $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] : '');
326
-    elseif ($method == 1)
327
-        $out = isset($_GET[$paramname]) ? $_GET[$paramname] : '';
328
-    elseif ($method == 2)
329
-        $out = isset($_POST[$paramname]) ? $_POST[$paramname] : '';
330
-    elseif ($method == 3)
331
-        $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] : '');
332
-    elseif ($method == 4)
333
-        $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_COOKIE[$paramname]) ? $_COOKIE[$paramname] : ''));
334
-    else
335
-        return 'BadThirdParameterForGETPOST';
327
+    if (empty($method)) {
328
+            $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] : '');
329
+    } elseif ($method == 1) {
330
+            $out = isset($_GET[$paramname]) ? $_GET[$paramname] : '';
331
+    } elseif ($method == 2) {
332
+            $out = isset($_POST[$paramname]) ? $_POST[$paramname] : '';
333
+    } elseif ($method == 3) {
334
+            $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] : '');
335
+    } elseif ($method == 4) {
336
+            $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_COOKIE[$paramname]) ? $_COOKIE[$paramname] : ''));
337
+    } else {
338
+            return 'BadThirdParameterForGETPOST';
339
+    }
336 340
 
337 341
     if (empty($method) || $method == 3 || $method == 4) {
338 342
         $relativepathstring = $_SERVER["PHP_SELF"];
339 343
         // Clean $relativepathstring
340
-        if (constant('DOL_URL_ROOT'))
341
-            $relativepathstring = preg_replace('/^' . preg_quote(constant('DOL_URL_ROOT'), '/') . '/', '', $relativepathstring);
344
+        if (constant('DOL_URL_ROOT')) {
345
+                    $relativepathstring = preg_replace('/^' . preg_quote(constant('DOL_URL_ROOT'), '/') . '/', '', $relativepathstring);
346
+        }
342 347
         $relativepathstring = preg_replace('/^\//', '', $relativepathstring);
343 348
         $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
344 349
         //var_dump($relativepathstring);
@@ -387,14 +392,17 @@  discard block
 block discarded – undo
387 392
                                     $tmpqueryarraywehave = explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
388 393
                                     $foundintru = 0;
389 394
                                     foreach ($tmpqueryarraytohave as $tmpquerytohave) {
390
-                                        if (!in_array($tmpquerytohave, $tmpqueryarraywehave))
391
-                                            $foundintru = 1;
395
+                                        if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
396
+                                                                                    $foundintru = 1;
397
+                                        }
398
+                                    }
399
+                                    if (!$foundintru) {
400
+                                                                            $qualified = 1;
392 401
                                     }
393
-                                    if (!$foundintru)
394
-                                        $qualified = 1;
395 402
                                     //var_dump($defkey.'-'.$qualified);
396
-                                } else
397
-                                    $qualified = 1;
403
+                                } else {
404
+                                                                    $qualified = 1;
405
+                                }
398 406
 
399 407
                                 if ($qualified) {
400 408
                                     //var_dump($user->default_values[$relativepathstring][$defkey]['createform']);
@@ -421,20 +429,24 @@  discard block
 block discarded – undo
421 429
                                         $tmpqueryarraywehave = explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
422 430
                                         $foundintru = 0;
423 431
                                         foreach ($tmpqueryarraytohave as $tmpquerytohave) {
424
-                                            if (!in_array($tmpquerytohave, $tmpqueryarraywehave))
425
-                                                $foundintru = 1;
432
+                                            if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
433
+                                                                                            $foundintru = 1;
434
+                                            }
435
+                                        }
436
+                                        if (!$foundintru) {
437
+                                                                                    $qualified = 1;
426 438
                                         }
427
-                                        if (!$foundintru)
428
-                                            $qualified = 1;
429 439
                                         //var_dump($defkey.'-'.$qualified);
430
-                                    } else
431
-                                        $qualified = 1;
440
+                                    } else {
441
+                                                                            $qualified = 1;
442
+                                    }
432 443
 
433 444
                                     if ($qualified) {
434 445
                                         $forbidden_chars_to_replace = array(" ", "'", "/", "\\", ":", "*", "?", "\"", "<", ">", "|", "[", "]", ";", "=");  // we accept _, -, . and ,
435 446
                                         foreach ($user->default_values[$relativepathstring]['sortorder'][$defkey] as $key => $val) {
436
-                                            if ($out)
437
-                                                $out .= ', ';
447
+                                            if ($out) {
448
+                                                                                            $out .= ', ';
449
+                                            }
438 450
                                             if ($paramname == 'sortfield') {
439 451
                                                 $out .= dol_string_nospecial($key, '', $forbidden_chars_to_replace);
440 452
                                             }
@@ -454,14 +466,17 @@  discard block
 block discarded – undo
454 466
                                     $tmpqueryarraywehave = explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
455 467
                                     $foundintru = 0;
456 468
                                     foreach ($tmpqueryarraytohave as $tmpquerytohave) {
457
-                                        if (!in_array($tmpquerytohave, $tmpqueryarraywehave))
458
-                                            $foundintru = 1;
469
+                                        if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
470
+                                                                                    $foundintru = 1;
471
+                                        }
472
+                                    }
473
+                                    if (!$foundintru) {
474
+                                                                            $qualified = 1;
459 475
                                     }
460
-                                    if (!$foundintru)
461
-                                        $qualified = 1;
462 476
                                     //var_dump($defkey.'-'.$qualified);
463
-                                } else
464
-                                    $qualified = 1;
477
+                                } else {
478
+                                                                    $qualified = 1;
479
+                                }
465 480
 
466 481
                                 if ($qualified) {
467 482
                                     if (isset($_POST['sall']) || isset($_POST['search_all']) || isset($_GET['sall']) || isset($_GET['search_all'])) {
@@ -533,8 +548,10 @@  discard block
 block discarded – undo
533 548
                 $newout = $user->fk_user;
534 549
             } elseif ($reg[1] == 'ENTITY_ID' || $reg[1] == 'ENTITYID') {
535 550
                 $newout = $conf->entity;
536
-            } else
537
-                $newout = '';     // Key not found, we replace with empty string
551
+            } else {
552
+                            $newout = '';
553
+            }
554
+            // Key not found, we replace with empty string
538 555
 
539 556
 
540 557
 
@@ -575,18 +592,20 @@  discard block
 block discarded – undo
575 592
             }
576 593
             break;
577 594
         case 'intcomma':
578
-            if (preg_match('/[^0-9,-]+/i', $out))
579
-                $out = '';
595
+            if (preg_match('/[^0-9,-]+/i', $out)) {
596
+                            $out = '';
597
+            }
580 598
             break;
581 599
         case 'alpha':
582 600
             if (!is_array($out)) {
583 601
                 $out = trim($out);
584 602
                 // '"' is dangerous because param in url can close the href= or src= and add javascript functions.
585 603
                 // '../' is dangerous because it allows dir transversals
586
-                if (preg_match('/"/', $out))
587
-                    $out = '';
588
-                else if (preg_match('/\.\.\//', $out))
589
-                    $out = '';
604
+                if (preg_match('/"/', $out)) {
605
+                                    $out = '';
606
+                } else if (preg_match('/\.\.\//', $out)) {
607
+                                    $out = '';
608
+                }
590 609
             }
591 610
             break;
592 611
         case 'san_alpha':
@@ -595,27 +614,31 @@  discard block
 block discarded – undo
595 614
         case 'aZ':
596 615
             if (!is_array($out)) {
597 616
                 $out = trim($out);
598
-                if (preg_match('/[^a-z]+/i', $out))
599
-                    $out = '';
617
+                if (preg_match('/[^a-z]+/i', $out)) {
618
+                                    $out = '';
619
+                }
600 620
             }
601 621
             break;
602 622
         case 'aZ09':
603 623
             if (!is_array($out)) {
604 624
                 $out = trim($out);
605
-                if (preg_match('/[^a-z0-9_\-\.]+/i', $out))
606
-                    $out = '';
625
+                if (preg_match('/[^a-z0-9_\-\.]+/i', $out)) {
626
+                                    $out = '';
627
+                }
607 628
             }
608 629
             break;
609 630
         case 'aZ09comma':  // great to sanitize sortfield or sortorder params that can be t.abc,t.def_gh
610 631
             if (!is_array($out)) {
611 632
                 $out = trim($out);
612
-                if (preg_match('/[^a-z0-9_\-\.,]+/i', $out))
613
-                    $out = '';
633
+                if (preg_match('/[^a-z0-9_\-\.,]+/i', $out)) {
634
+                                    $out = '';
635
+                }
614 636
             }
615 637
             break;
616 638
         case 'array':
617
-            if (!is_array($out) || empty($out))
618
-                $out = array();
639
+            if (!is_array($out) || empty($out)) {
640
+                            $out = array();
641
+            }
619 642
             break;
620 643
         case 'nohtml':  // Recommended for most scalar parameters
621 644
             $out = dol_string_nohtmltag($out, 0);
@@ -625,16 +648,18 @@  discard block
 block discarded – undo
625 648
                 $out = trim($out);
626 649
                 // '"' is dangerous because param in url can close the href= or src= and add javascript functions.
627 650
                 // '../' is dangerous because it allows dir transversals
628
-                if (preg_match('/"/', $out))
629
-                    $out = '';
630
-                else if (preg_match('/\.\.\//', $out))
631
-                    $out = '';
651
+                if (preg_match('/"/', $out)) {
652
+                                    $out = '';
653
+                } else if (preg_match('/\.\.\//', $out)) {
654
+                                    $out = '';
655
+                }
632 656
                 $out = dol_string_nohtmltag($out);
633 657
             }
634 658
             break;
635 659
         case 'custom':
636
-            if (empty($filter))
637
-                return 'BadFourthParameterForGETPOST';
660
+            if (empty($filter)) {
661
+                            return 'BadFourthParameterForGETPOST';
662
+            }
638 663
             $out = filter_var($out, $filter, $options);
639 664
             break;
640 665
     }
@@ -674,10 +699,11 @@  discard block
 block discarded – undo
674 699
         // If prefix is for email
675 700
         if ($mode == 'email') {
676 701
             if (!empty($conf->global->MAIL_PREFIX_FOR_EMAIL_ID)) { // If MAIL_PREFIX_FOR_EMAIL_ID is set (a value initialized with a random value is recommended)
677
-                if ($conf->global->MAIL_PREFIX_FOR_EMAIL_ID != 'SERVER_NAME')
678
-                    return $conf->global->MAIL_PREFIX_FOR_EMAIL_ID;
679
-                else if (isset($_SERVER["SERVER_NAME"]))
680
-                    return $_SERVER["SERVER_NAME"];
702
+                if ($conf->global->MAIL_PREFIX_FOR_EMAIL_ID != 'SERVER_NAME') {
703
+                                    return $conf->global->MAIL_PREFIX_FOR_EMAIL_ID;
704
+                } else if (isset($_SERVER["SERVER_NAME"])) {
705
+                                    return $_SERVER["SERVER_NAME"];
706
+                }
681 707
             }
682 708
             return dol_hash(DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
683 709
         }
@@ -750,22 +776,27 @@  discard block
 block discarded – undo
750 776
             }
751 777
         }
752 778
         if ($returnemptyifnotfound) {        // Not found into alternate dir
753
-            if ($returnemptyifnotfound == 1 || !file_exists($res))
754
-                return '';
779
+            if ($returnemptyifnotfound == 1 || !file_exists($res)) {
780
+                            return '';
781
+            }
755 782
         }
756
-    }
757
-    else {    // For an url path
783
+    } else {    // For an url path
758 784
         // We try to get local path of file on filesystem from url
759 785
         // Note that trying to know if a file on disk exist by forging path on disk from url
760 786
         // works only for some web server and some setup. This is bugged when
761 787
         // using proxy, rewriting, virtual path, etc...
762 788
         $res = '';
763
-        if ($type == 1)
764
-            $res = /* DOL_URL_ROOT */ DOL_BASE_URI . '/' . $path;   // Standard value
765
-        if ($type == 2)
766
-            $res = /* DOL_MAIN_URL_ROOT */ DOL_BASE_PATH . '/' . $path;  // Standard value
767
-        if ($type == 3)
768
-            $res = DOL_URL_ROOT . '/' . $path;
789
+        if ($type == 1) {
790
+                    $res = /* DOL_URL_ROOT */ DOL_BASE_URI . '/' . $path;
791
+        }
792
+        // Standard value
793
+        if ($type == 2) {
794
+                    $res = /* DOL_MAIN_URL_ROOT */ DOL_BASE_PATH . '/' . $path;
795
+        }
796
+        // Standard value
797
+        if ($type == 3) {
798
+                    $res = DOL_URL_ROOT . '/' . $path;
799
+        }
769 800
 
770 801
         foreach ($conf->file->dol_document_root as $key => $dirroot) { // ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
771 802
             if ($key == 'main') {
@@ -845,13 +876,15 @@  discard block
 block discarded – undo
845 876
 function dol_size($size, $type = '')
846 877
 {
847 878
     global $conf;
848
-    if (empty($conf->dol_optimize_smallscreen))
849
-        return $size;
850
-    if ($type == 'width' && $size > 250)
851
-        return 250;
852
-    else
853
-        return 10;
854
-}
879
+    if (empty($conf->dol_optimize_smallscreen)) {
880
+            return $size;
881
+    }
882
+    if ($type == 'width' && $size > 250) {
883
+            return 250;
884
+    } else {
885
+            return 10;
886
+    }
887
+    }
855 888
 
856 889
 /**
857 890
  * 	Clean a string to use it as a file name
@@ -950,8 +983,9 @@  discard block
 block discarded – undo
950 983
 {
951 984
     $forbidden_chars_to_replace = array(" ", "'", "/", "\\", ":", "*", "?", "\"", "<", ">", "|", "[", "]", ",", ";", "=", '°');  // more complete than dol_sanitizeFileName
952 985
     $forbidden_chars_to_remove = array();
953
-    if (is_array($badcharstoreplace))
954
-        $forbidden_chars_to_replace = $badcharstoreplace;
986
+    if (is_array($badcharstoreplace)) {
987
+            $forbidden_chars_to_replace = $badcharstoreplace;
988
+    }
955 989
     //$forbidden_chars_to_remove=array("(",")");
956 990
 
957 991
     return str_replace($forbidden_chars_to_replace, $newstr, str_replace($forbidden_chars_to_remove, "", $str));
@@ -988,9 +1022,9 @@  discard block
 block discarded – undo
988 1022
     if (empty($mode)) {
989 1023
         $substitjs["'"] = "\\'";
990 1024
         $substitjs['"'] = "\\'";
991
-    } else if ($mode == 1)
992
-        $substitjs["'"] = "\\'";
993
-    else if ($mode == 2) {
1025
+    } else if ($mode == 1) {
1026
+            $substitjs["'"] = "\\'";
1027
+    } else if ($mode == 2) {
994 1028
         $substitjs['"'] = '\\"';
995 1029
     } else if ($mode == 3) {
996 1030
         $substitjs["'"] = "\\'";
@@ -1012,10 +1046,12 @@  discard block
 block discarded – undo
1012 1046
 {
1013 1047
     // escape quotes and backslashes, newlines, etc.
1014 1048
     $tmp = html_entity_decode($stringtoescape, ENT_COMPAT, 'UTF-8');  // TODO Use htmlspecialchars_decode instead, that make only required change for html tags
1015
-    if (!$keepb)
1016
-        $tmp = strtr($tmp, array("<b>" => '', '</b>' => ''));
1017
-    if (!$keepn)
1018
-        $tmp = strtr($tmp, array("\r" => '\\r', "\n" => '\\n'));
1049
+    if (!$keepb) {
1050
+            $tmp = strtr($tmp, array("<b>" => '', '</b>' => ''));
1051
+    }
1052
+    if (!$keepn) {
1053
+            $tmp = strtr($tmp, array("\r" => '\\r', "\n" => '\\n'));
1054
+    }
1019 1055
     return htmlentities($tmp, ENT_COMPAT, 'UTF-8');      // TODO Use htmlspecialchars instead, that make only required change for html tags
1020 1056
 }
1021 1057
 
@@ -1066,8 +1102,9 @@  discard block
 block discarded – undo
1066 1102
     global $conf, $user;
1067 1103
 
1068 1104
     // If syslog module enabled
1069
-    if (empty($conf->syslog->enabled))
1070
-        return;
1105
+    if (empty($conf->syslog->enabled)) {
1106
+            return;
1107
+    }
1071 1108
 
1072 1109
     if ($ident < 0) {
1073 1110
         foreach ($conf->loghandlers as $loghandlerinstance) {
@@ -1081,8 +1118,9 @@  discard block
 block discarded – undo
1081 1118
         if (!in_array($level, $logLevels, true)) {
1082 1119
             throw new Exception('Incorrect log level');
1083 1120
         }
1084
-        if ($level > $conf->global->SYSLOG_LEVEL)
1085
-            return;
1121
+        if ($level > $conf->global->SYSLOG_LEVEL) {
1122
+                    return;
1123
+        }
1086 1124
 
1087 1125
         $message = preg_replace('/password=\'[^\']*\'/', 'password=\'hidden\'', $message); // protection to avoid to have value of password in log
1088 1126
         // If adding log inside HTML page is required
@@ -1107,24 +1145,30 @@  discard block
 block discarded – undo
1107 1145
         );
1108 1146
 
1109 1147
         // This is when server run behind a reverse proxy
1110
-        if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
1111
-            $data['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'] . (empty($_SERVER["REMOTE_ADDR"]) ? '' : '->' . $_SERVER['REMOTE_ADDR']);
1148
+        if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
1149
+                    $data['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'] . (empty($_SERVER["REMOTE_ADDR"]) ? '' : '->' . $_SERVER['REMOTE_ADDR']);
1150
+        }
1112 1151
         // This is when server run normally on a server
1113
-        else if (!empty($_SERVER["REMOTE_ADDR"]))
1114
-            $data['ip'] = $_SERVER['REMOTE_ADDR'];
1152
+        else if (!empty($_SERVER["REMOTE_ADDR"])) {
1153
+                    $data['ip'] = $_SERVER['REMOTE_ADDR'];
1154
+        }
1115 1155
         // This is when PHP session is ran inside a web server but not inside a client request (example: init code of apache)
1116
-        else if (!empty($_SERVER['SERVER_ADDR']))
1117
-            $data['ip'] = $_SERVER['SERVER_ADDR'];
1156
+        else if (!empty($_SERVER['SERVER_ADDR'])) {
1157
+                    $data['ip'] = $_SERVER['SERVER_ADDR'];
1158
+        }
1118 1159
         // This is when PHP session is ran outside a web server, like from Windows command line (Not always defined, but useful if OS defined it).
1119
-        else if (!empty($_SERVER['COMPUTERNAME']))
1120
-            $data['ip'] = $_SERVER['COMPUTERNAME'] . (empty($_SERVER['USERNAME']) ? '' : '@' . $_SERVER['USERNAME']);
1160
+        else if (!empty($_SERVER['COMPUTERNAME'])) {
1161
+                    $data['ip'] = $_SERVER['COMPUTERNAME'] . (empty($_SERVER['USERNAME']) ? '' : '@' . $_SERVER['USERNAME']);
1162
+        }
1121 1163
         // This is when PHP session is ran outside a web server, like from Linux command line (Not always defined, but usefull if OS defined it).
1122
-        else if (!empty($_SERVER['LOGNAME']))
1123
-            $data['ip'] = '???@' . $_SERVER['LOGNAME'];
1164
+        else if (!empty($_SERVER['LOGNAME'])) {
1165
+                    $data['ip'] = '???@' . $_SERVER['LOGNAME'];
1166
+        }
1124 1167
         // Loop on each log handler and send output
1125 1168
         foreach ($conf->loghandlers as $loghandlerinstance) {
1126
-            if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler)
1127
-                continue;
1169
+            if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
1170
+                            continue;
1171
+            }
1128 1172
             $loghandlerinstance->export($data, $suffixinfilename);
1129 1173
         }
1130 1174
         unset($data);
@@ -1180,13 +1224,15 @@  discard block
 block discarded – undo
1180 1224
 
1181 1225
     // Show title
1182 1226
     $showtitle = 1;
1183
-    if (!empty($conf->dol_optimize_smallscreen))
1184
-        $showtitle = 0;
1227
+    if (!empty($conf->dol_optimize_smallscreen)) {
1228
+            $showtitle = 0;
1229
+    }
1185 1230
     if (!empty($title) && $showtitle) {
1186 1231
         $limittitle = 30;
1187 1232
         $out .= '<a class="tabTitle">';
1188
-        if ($picto)
1189
-            $out .= img_picto($title, ($pictoisfullpath ? '' : 'object_') . $picto, '', $pictoisfullpath) . ' ';
1233
+        if ($picto) {
1234
+                    $out .= img_picto($title, ($pictoisfullpath ? '' : 'object_') . $picto, '', $pictoisfullpath) . ' ';
1235
+        }
1190 1236
         $out .= '<span class="tabTitleText">' . dol_trunc($title, $limittitle) . '</span>';
1191 1237
         $out .= '</a>';
1192 1238
     }
@@ -1195,12 +1241,14 @@  discard block
 block discarded – undo
1195 1241
     $maxkey = -1;
1196 1242
     if (is_array($links) && !empty($links)) {
1197 1243
         $keys = array_keys($links);
1198
-        if (count($keys))
1199
-            $maxkey = max($keys);
1244
+        if (count($keys)) {
1245
+                    $maxkey = max($keys);
1246
+        }
1200 1247
     }
1201 1248
 
1202
-    if (!empty($conf->dol_optimize_smallscreen))
1203
-        $conf->global->MAIN_MAXTABS_IN_CARD = 2;
1249
+    if (!empty($conf->dol_optimize_smallscreen)) {
1250
+            $conf->global->MAIN_MAXTABS_IN_CARD = 2;
1251
+    }
1204 1252
 
1205 1253
     // Show tabs
1206 1254
     $bactive = false;
@@ -1213,8 +1261,9 @@  discard block
 block discarded – undo
1213 1261
     for ($i = 0; $i <= $maxkey; $i++) {
1214 1262
         if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
1215 1263
             // If active tab is already present
1216
-            if ($i >= $limittoshow)
1217
-                $limittoshow--;
1264
+            if ($i >= $limittoshow) {
1265
+                            $limittoshow--;
1266
+            }
1218 1267
         }
1219 1268
     }
1220 1269
 
@@ -1255,12 +1304,12 @@  discard block
 block discarded – undo
1255 1304
             }
1256 1305
             $outmore .= '<div class="popuptab wordwrap" style="display:inherit;">';
1257 1306
             if (isset($links[$i][2]) && $links[$i][2] == 'image') {
1258
-                if (!empty($links[$i][0]))
1259
-                    $outmore .= '<a class="tabimage' . ($morecss ? ' ' . $morecss : '') . '" href="' . $links[$i][0] . '">' . $links[$i][1] . '</a>' . "\n";
1260
-                else
1261
-                    $outmore .= '<span class="tabspan">' . $links[$i][1] . '</span>' . "\n";
1262
-            }
1263
-            else if (!empty($links[$i][1])) {
1307
+                if (!empty($links[$i][0])) {
1308
+                                    $outmore .= '<a class="tabimage' . ($morecss ? ' ' . $morecss : '') . '" href="' . $links[$i][0] . '">' . $links[$i][1] . '</a>' . "\n";
1309
+                } else {
1310
+                                    $outmore .= '<span class="tabspan">' . $links[$i][1] . '</span>' . "\n";
1311
+                }
1312
+            } else if (!empty($links[$i][1])) {
1264 1313
                 $outmore .= '<a' . (!empty($links[$i][2]) ? ' id="' . $links[$i][2] . '"' : '') . ' class="wordwrap inline-block' . ($morecss ? ' ' . $morecss : '') . '" href="' . $links[$i][0] . '">';
1265 1314
                 $outmore .= preg_replace('/([a-z])\/([a-z])/i', '\\1 / \\2', $links[$i][1]); // Replace x/y with x / y to allow wrap on long composed texts.
1266 1315
                 $outmore .= '</a>' . "\n";
@@ -1271,8 +1320,9 @@  discard block
 block discarded – undo
1271 1320
         }
1272 1321
         $displaytab = $i;
1273 1322
     }
1274
-    if ($popuptab)
1275
-        $outmore .= '</div>';
1323
+    if ($popuptab) {
1324
+            $outmore .= '</div>';
1325
+    }
1276 1326
 
1277 1327
     if ($displaytab > $limittoshow) {
1278 1328
         $left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');
@@ -1295,8 +1345,9 @@  discard block
 block discarded – undo
1295 1345
 
1296 1346
     $out .= "</div>\n";
1297 1347
 
1298
-    if (!$notab || $notab == -1)
1299
-        $out .= "\n" . '<div class="tabBar' . ($notab == -1 ? '' : ' tabBarWithBottom') . '">' . "\n";
1348
+    if (!$notab || $notab == -1) {
1349
+            $out .= "\n" . '<div class="tabBar' . ($notab == -1 ? '' : ' tabBarWithBottom') . '">' . "\n";
1350
+    }
1300 1351
 
1301 1352
     $parameters = array('tabname' => $active, 'out' => $out);
1302 1353
     $reshook = $hookmanager->executeHooks('printTabsHead', $parameters); // This hook usage is called just before output the head of tabs. Take also a look at "completeTabsHead"
@@ -1326,11 +1377,12 @@  discard block
 block discarded – undo
1326 1377
  */
1327 1378
 function dol_get_fiche_end($notab = 0)
1328 1379
 {
1329
-    if (!$notab || $notab == -1)
1330
-        return "\n</div>\n";
1331
-    else
1332
-        return '';
1333
-}
1380
+    if (!$notab || $notab == -1) {
1381
+            return "\n</div>\n";
1382
+    } else {
1383
+            return '';
1384
+    }
1385
+    }
1334 1386
 
1335 1387
 /**
1336 1388
  *  Show tab footer of a card.
@@ -1361,40 +1413,55 @@  discard block
 block discarded – undo
1361 1413
     $showimage = 1;
1362 1414
     $entity = (empty($object->entity) ? $conf->entity : $object->entity);
1363 1415
     $showbarcode = empty($conf->barcode->enabled) ? 0 : ($object->barcode ? 1 : 0);
1364
-    if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance))
1365
-        $showbarcode = 0;
1416
+    if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
1417
+            $showbarcode = 0;
1418
+    }
1366 1419
     $modulepart = 'unknown';
1367 1420
 
1368
-    if ($object->element == 'societe')
1369
-        $modulepart = 'societe';
1370
-    if ($object->element == 'contact')
1371
-        $modulepart = 'contact';
1372
-    if ($object->element == 'member')
1373
-        $modulepart = 'memberphoto';
1374
-    if ($object->element == 'user')
1375
-        $modulepart = 'userphoto';
1376
-    if ($object->element == 'product')
1377
-        $modulepart = 'product';
1421
+    if ($object->element == 'societe') {
1422
+            $modulepart = 'societe';
1423
+    }
1424
+    if ($object->element == 'contact') {
1425
+            $modulepart = 'contact';
1426
+    }
1427
+    if ($object->element == 'member') {
1428
+            $modulepart = 'memberphoto';
1429
+    }
1430
+    if ($object->element == 'user') {
1431
+            $modulepart = 'userphoto';
1432
+    }
1433
+    if ($object->element == 'product') {
1434
+            $modulepart = 'product';
1435
+    }
1378 1436
 
1379 1437
     if (class_exists("Imagick")) {
1380
-        if ($object->element == 'propal')
1381
-            $modulepart = 'propal';
1382
-        if ($object->element == 'commande')
1383
-            $modulepart = 'commande';
1384
-        if ($object->element == 'facture')
1385
-            $modulepart = 'facture';
1386
-        if ($object->element == 'fichinter')
1387
-            $modulepart = 'ficheinter';
1388
-        if ($object->element == 'contrat')
1389
-            $modulepart = 'contract';
1390
-        if ($object->element == 'supplier_proposal')
1391
-            $modulepart = 'supplier_proposal';
1392
-        if ($object->element == 'order_supplier')
1393
-            $modulepart = 'supplier_order';
1394
-        if ($object->element == 'invoice_supplier')
1395
-            $modulepart = 'supplier_invoice';
1396
-        if ($object->element == 'expensereport')
1397
-            $modulepart = 'expensereport';
1438
+        if ($object->element == 'propal') {
1439
+                    $modulepart = 'propal';
1440
+        }
1441
+        if ($object->element == 'commande') {
1442
+                    $modulepart = 'commande';
1443
+        }
1444
+        if ($object->element == 'facture') {
1445
+                    $modulepart = 'facture';
1446
+        }
1447
+        if ($object->element == 'fichinter') {
1448
+                    $modulepart = 'ficheinter';
1449
+        }
1450
+        if ($object->element == 'contrat') {
1451
+                    $modulepart = 'contract';
1452
+        }
1453
+        if ($object->element == 'supplier_proposal') {
1454
+                    $modulepart = 'supplier_proposal';
1455
+        }
1456
+        if ($object->element == 'order_supplier') {
1457
+                    $modulepart = 'supplier_order';
1458
+        }
1459
+        if ($object->element == 'invoice_supplier') {
1460
+                    $modulepart = 'supplier_invoice';
1461
+        }
1462
+        if ($object->element == 'expensereport') {
1463
+                    $modulepart = 'expensereport';
1464
+        }
1398 1465
     }
1399 1466
 
1400 1467
     if ($object->element == 'product') {
@@ -1402,11 +1469,12 @@  discard block
 block discarded – undo
1402 1469
         $cssclass = 'photoref';
1403 1470
         $showimage = $object->is_photo_available($conf->product->multidir_output[$entity]);
1404 1471
         $maxvisiblephotos = (isset($conf->global->PRODUCT_MAX_VISIBLE_PHOTO) ? $conf->global->PRODUCT_MAX_VISIBLE_PHOTO : 5);
1405
-        if ($conf->browser->layout == 'phone')
1406
-            $maxvisiblephotos = 1;
1407
-        if ($showimage)
1408
-            $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $object->show_photos('product', $conf->product->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, $width, 0) . '</div>';
1409
-        else {
1472
+        if ($conf->browser->layout == 'phone') {
1473
+                    $maxvisiblephotos = 1;
1474
+        }
1475
+        if ($showimage) {
1476
+                    $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $object->show_photos('product', $conf->product->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, $width, 0) . '</div>';
1477
+        } else {
1410 1478
             if (!empty($conf->global->PRODUCT_NODISPLAYIFNOPHOTO)) {
1411 1479
                 $nophoto = '';
1412 1480
                 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"></div>';
@@ -1422,11 +1490,12 @@  discard block
 block discarded – undo
1422 1490
         $cssclass = 'photoref';
1423 1491
         $showimage = $object->is_photo_available($conf->ticket->multidir_output[$entity] . '/' . $object->track_id);
1424 1492
         $maxvisiblephotos = (isset($conf->global->TICKETSUP_MAX_VISIBLE_PHOTO) ? $conf->global->TICKETSUP_MAX_VISIBLE_PHOTO : 2);
1425
-        if ($conf->browser->layout == 'phone')
1426
-            $maxvisiblephotos = 1;
1427
-        if ($showimage)
1428
-            $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $object->show_photos('ticket', $conf->ticket->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, $width, 0) . '</div>';
1429
-        else {
1493
+        if ($conf->browser->layout == 'phone') {
1494
+                    $maxvisiblephotos = 1;
1495
+        }
1496
+        if ($showimage) {
1497
+                    $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $object->show_photos('ticket', $conf->ticket->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, $width, 0) . '</div>';
1498
+        } else {
1430 1499
             if (!empty($conf->global->TICKETSUP_NODISPLAYIFNOPHOTO)) {
1431 1500
                 $nophoto = '';
1432 1501
                 $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"></div>';
@@ -1451,8 +1520,10 @@  discard block
 block discarded – undo
1451 1520
                     } else {
1452 1521
                         $subdir = get_exdir($object->id, 0, 0, 1, $object, $modulepart);
1453 1522
                     }
1454
-                    if (empty($subdir))
1455
-                        $subdir = 'errorgettingsubdirofobject'; // Protection to avoid to return empty path
1523
+                    if (empty($subdir)) {
1524
+                                            $subdir = 'errorgettingsubdirofobject';
1525
+                    }
1526
+                    // Protection to avoid to return empty path
1456 1527
 
1457 1528
                     $filepath = $dir_output . $subdir . "/";
1458 1529
 
@@ -1473,14 +1544,16 @@  discard block
 block discarded – undo
1473 1544
                             if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) {  // If you experienc trouble with pdf thumb generation and imagick, you can disable here.
1474 1545
                                 include_once DOL_BASE_PATH . '/core/lib/files.lib.php';
1475 1546
                                 $ret = dol_convert_file($file, 'png', $fileimage);
1476
-                                if ($ret < 0)
1477
-                                    $error++;
1547
+                                if ($ret < 0) {
1548
+                                                                    $error++;
1549
+                                }
1478 1550
                             }
1479 1551
                         }
1480 1552
 
1481 1553
                         $heightforphotref = 70;
1482
-                        if (!empty($conf->dol_optimize_smallscreen))
1483
-                            $heightforphotref = 60;
1554
+                        if (!empty($conf->dol_optimize_smallscreen)) {
1555
+                                                    $heightforphotref = 60;
1556
+                        }
1484 1557
                         // Si fichier png PDF d'1 page trouve
1485 1558
                         if (file_exists($fileimage)) {
1486 1559
                             $phototoshow = '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
@@ -1516,8 +1589,10 @@  discard block
 block discarded – undo
1516 1589
                     $width = 14;
1517 1590
                     $cssclass = 'photorefcenter';
1518 1591
                     $picto = $object->picto;
1519
-                    if ($object->element == 'project' && !$object->public)
1520
-                        $picto = 'project'; // instead of projectpub
1592
+                    if ($object->element == 'project' && !$object->public) {
1593
+                                            $picto = 'project';
1594
+                    }
1595
+                    // instead of projectpub
1521 1596
                     $nophoto = img_picto('', 'object_' . $picto, '', false, 1);
1522 1597
                 }
1523 1598
                 $morehtmlleft .= '<!-- No photo to show -->';
@@ -1528,8 +1603,9 @@  discard block
 block discarded – undo
1528 1603
         }
1529 1604
     }
1530 1605
 
1531
-    if ($showbarcode)
1532
-        $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $form->showbarcode($object) . '</div>';
1606
+    if ($showbarcode) {
1607
+            $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $form->showbarcode($object) . '</div>';
1608
+    }
1533 1609
 
1534 1610
     if ($object->element == 'societe') {
1535 1611
         if (!empty($conf->use_javascript_ajax) && $user->rights->societe->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
@@ -1553,35 +1629,37 @@  discard block
 block discarded – undo
1553 1629
         }
1554 1630
     } elseif (in_array($object->element, array('facture', 'invoice', 'invoice_supplier', 'chargesociales', 'loan'))) {
1555 1631
         $tmptxt = $object->getLibStatut(6, $object->totalpaye);
1556
-        if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout == 'phone')
1557
-            $tmptxt = $object->getLibStatut(5, $object->totalpaye);
1632
+        if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout == 'phone') {
1633
+                    $tmptxt = $object->getLibStatut(5, $object->totalpaye);
1634
+        }
1558 1635
         $morehtmlstatus .= $tmptxt;
1559
-    }
1560
-    elseif ($object->element == 'contrat' || $object->element == 'contract') {
1561
-        if ($object->statut == 0)
1562
-            $morehtmlstatus .= $object->getLibStatut(5);
1563
-        else
1564
-            $morehtmlstatus .= $object->getLibStatut(4);
1565
-    }
1566
-    elseif ($object->element == 'facturerec') {
1567
-        if ($object->frequency == 0)
1568
-            $morehtmlstatus .= $object->getLibStatut(2);
1569
-        else
1570
-            $morehtmlstatus .= $object->getLibStatut(5);
1571
-    }
1572
-    elseif ($object->element == 'project_task') {
1636
+    } elseif ($object->element == 'contrat' || $object->element == 'contract') {
1637
+        if ($object->statut == 0) {
1638
+                    $morehtmlstatus .= $object->getLibStatut(5);
1639
+        } else {
1640
+                    $morehtmlstatus .= $object->getLibStatut(4);
1641
+        }
1642
+    } elseif ($object->element == 'facturerec') {
1643
+        if ($object->frequency == 0) {
1644
+                    $morehtmlstatus .= $object->getLibStatut(2);
1645
+        } else {
1646
+                    $morehtmlstatus .= $object->getLibStatut(5);
1647
+        }
1648
+    } elseif ($object->element == 'project_task') {
1573 1649
         $object->fk_statut = 1;
1574
-        if ($object->progress > 0)
1575
-            $object->fk_statut = 2;
1576
-        if ($object->progress >= 100)
1577
-            $object->fk_statut = 3;
1650
+        if ($object->progress > 0) {
1651
+                    $object->fk_statut = 2;
1652
+        }
1653
+        if ($object->progress >= 100) {
1654
+                    $object->fk_statut = 3;
1655
+        }
1578 1656
         $tmptxt = $object->getLibStatut(5);
1579 1657
         $morehtmlstatus .= $tmptxt;  // No status on task
1580
-    }
1581
-    else { // Generic case
1658
+    } else { // Generic case
1582 1659
         $tmptxt = $object->getLibStatut(6);
1583
-        if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout == 'phone')
1584
-            $tmptxt = $object->getLibStatut(5);
1660
+        if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || $conf->browser->layout == 'phone') {
1661
+                    $tmptxt = $object->getLibStatut(5);
1662
+        }
1585 1663
         $morehtmlstatus .= $tmptxt;
1586 1664
     }
1587 1665
 
@@ -1595,13 +1673,15 @@  discard block
 block discarded – undo
1595 1673
     }
1596 1674
 
1597 1675
     // Add alias for thirdparty
1598
-    if (!empty($object->name_alias))
1599
-        $morehtmlref .= '<div class="refidno">' . $object->name_alias . '</div>';
1676
+    if (!empty($object->name_alias)) {
1677
+            $morehtmlref .= '<div class="refidno">' . $object->name_alias . '</div>';
1678
+    }
1600 1679
 
1601 1680
     // Add label
1602 1681
     if ($object->element == 'product' || $object->element == 'bank_account' || $object->element == 'project_task') {
1603
-        if (!empty($object->label))
1604
-            $morehtmlref .= '<div class="refidno">' . $object->label . '</div>';
1682
+        if (!empty($object->label)) {
1683
+                    $morehtmlref .= '<div class="refidno">' . $object->label . '</div>';
1684
+        }
1605 1685
     }
1606 1686
 
1607 1687
     if (method_exists($object, 'getBannerAddress') && $object->element != 'product' && $object->element != 'bookmark' && $object->element != 'ecm_directories' && $object->element != 'ecm_files') {
@@ -1634,15 +1714,19 @@  discard block
 block discarded – undo
1634 1714
 {
1635 1715
     global $conf, $langs;
1636 1716
     $ret = '';
1637
-    if ($fieldrequired)
1638
-        $ret .= '<span class="fieldrequired">';
1639
-    if (($conf->dol_use_jmobile != 4))
1640
-        $ret .= '<label for="' . $fieldkey . '">';
1717
+    if ($fieldrequired) {
1718
+            $ret .= '<span class="fieldrequired">';
1719
+    }
1720
+    if (($conf->dol_use_jmobile != 4)) {
1721
+            $ret .= '<label for="' . $fieldkey . '">';
1722
+    }
1641 1723
     $ret .= $langs->trans($langkey);
1642
-    if (($conf->dol_use_jmobile != 4))
1643
-        $ret .= '</label>';
1644
-    if ($fieldrequired)
1645
-        $ret .= '</span>';
1724
+    if (($conf->dol_use_jmobile != 4)) {
1725
+            $ret .= '</label>';
1726
+    }
1727
+    if ($fieldrequired) {
1728
+            $ret .= '</span>';
1729
+    }
1646 1730
     return $ret;
1647 1731
 }
1648 1732
 
@@ -1657,8 +1741,9 @@  discard block
 block discarded – undo
1657 1741
 {
1658 1742
     global $bc;
1659 1743
     $ret = ' ' . $bc[$var];
1660
-    if ($moreclass)
1661
-        $ret = preg_replace('/class=\"/', 'class="' . $moreclass . ' ', $ret);
1744
+    if ($moreclass) {
1745
+            $ret = preg_replace('/class=\"/', 'class="' . $moreclass . ' ', $ret);
1746
+    }
1662 1747
     return $ret;
1663 1748
 }
1664 1749
 
@@ -1689,18 +1774,18 @@  discard block
 block discarded – undo
1689 1774
         if ($object->state) {
1690 1775
             $ret .= ($ret ? ", " : '') . $object->state;
1691 1776
         }
1692
-        if ($object->zip)
1693
-            $ret .= ($ret ? ", " : '') . $object->zip;
1694
-    }
1695
-    else if (in_array($object->country_code, array('GB', 'UK'))) { // UK: title firstname name \n address lines \n town state \n zip \n country
1777
+        if ($object->zip) {
1778
+                    $ret .= ($ret ? ", " : '') . $object->zip;
1779
+        }
1780
+    } else if (in_array($object->country_code, array('GB', 'UK'))) { // UK: title firstname name \n address lines \n town state \n zip \n country
1696 1781
         $ret .= ($ret ? $sep : '' ) . $object->town;
1697 1782
         if ($object->state) {
1698 1783
             $ret .= ($ret ? ", " : '') . $object->state;
1699 1784
         }
1700
-        if ($object->zip)
1701
-            $ret .= ($ret ? $sep : '' ) . $object->zip;
1702
-    }
1703
-    else if (in_array($object->country_code, array('ES', 'TR'))) { // ES: title firstname name \n address lines \n zip town \n state \n country
1785
+        if ($object->zip) {
1786
+                    $ret .= ($ret ? $sep : '' ) . $object->zip;
1787
+        }
1788
+    } else if (in_array($object->country_code, array('ES', 'TR'))) { // ES: title firstname name \n address lines \n zip town \n state \n country
1704 1789
         $ret .= ($ret ? $sep : '' ) . $object->zip;
1705 1790
         $ret .= ($object->town ? (($object->zip ? ' ' : '') . $object->town) : '');
1706 1791
         if ($object->state) {
@@ -1717,8 +1802,9 @@  discard block
 block discarded – undo
1717 1802
             $ret .= ($ret ? ", " : '') . $object->state;
1718 1803
         }
1719 1804
     }
1720
-    if (!is_object($outputlangs))
1721
-        $outputlangs = $langs;
1805
+    if (!is_object($outputlangs)) {
1806
+            $outputlangs = $langs;
1807
+    }
1722 1808
     if ($withcountry) {
1723 1809
         $langs->load("dict");
1724 1810
         $ret .= ($object->country_code ? ($ret ? $sep : '') . $outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country" . $object->country_code)) : '');
@@ -1739,9 +1825,10 @@  discard block
 block discarded – undo
1739 1825
 {
1740 1826
     if ((abs($ts) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range
1741 1827
         return ($is_gmt) ? @gmstrftime($fmt, $ts) : @strftime($fmt, $ts);
1742
-    } else
1743
-        return 'Error date into a not supported range';
1744
-}
1828
+    } else {
1829
+            return 'Error date into a not supported range';
1830
+    }
1831
+    }
1745 1832
 
1746 1833
 /**
1747 1834
  * 	Output date in a string format according to outputlangs (or langs if not defined).
@@ -1787,10 +1874,12 @@  discard block
 block discarded – undo
1787 1874
             }
1788 1875
         }
1789 1876
     }
1790
-    if (!is_object($outputlangs))
1791
-        $outputlangs = $langs;
1792
-    if (!$format)
1793
-        $format = 'daytextshort';
1877
+    if (!is_object($outputlangs)) {
1878
+            $outputlangs = $langs;
1879
+    }
1880
+    if (!$format) {
1881
+            $format = 'daytextshort';
1882
+    }
1794 1883
     $reduceformat = (!empty($conf->dol_optimize_smallscreen) && in_array($format, array('day', 'dayhour'))) ? 1 : 0;
1795 1884
     $formatwithoutreduce = preg_replace('/reduceformat/', '', $format);
1796 1885
     if ($formatwithoutreduce != $format) {
@@ -1799,40 +1888,46 @@  discard block
 block discarded – undo
1799 1888
     }  // so format 'dayreduceformat' is processed like day
1800 1889
     // Change predefined format into computer format. If found translation in lang file we use it, otherwise we use default.
1801 1890
     // TODO Add format daysmallyear and dayhoursmallyear
1802
-    if ($format == 'day')
1803
-        $format = ($outputlangs->trans("FormatDateShort") != "FormatDateShort" ? $outputlangs->trans("FormatDateShort") : $conf->format_date_short);
1804
-    else if ($format == 'hour')
1805
-        $format = ($outputlangs->trans("FormatHourShort") != "FormatHourShort" ? $outputlangs->trans("FormatHourShort") : $conf->format_hour_short);
1806
-    else if ($format == 'hourduration')
1807
-        $format = ($outputlangs->trans("FormatHourShortDuration") != "FormatHourShortDuration" ? $outputlangs->trans("FormatHourShortDuration") : $conf->format_hour_short_duration);
1808
-    else if ($format == 'daytext')
1809
-        $format = ($outputlangs->trans("FormatDateText") != "FormatDateText" ? $outputlangs->trans("FormatDateText") : $conf->format_date_text);
1810
-    else if ($format == 'daytextshort')
1811
-    // Notice: Undefined property: stdClass::$format_date_text_short in \alixar\dolibarr\htdocs\core\lib\functions.lib.php on line 1781
1891
+    if ($format == 'day') {
1892
+            $format = ($outputlangs->trans("FormatDateShort") != "FormatDateShort" ? $outputlangs->trans("FormatDateShort") : $conf->format_date_short);
1893
+    } else if ($format == 'hour') {
1894
+            $format = ($outputlangs->trans("FormatHourShort") != "FormatHourShort" ? $outputlangs->trans("FormatHourShort") : $conf->format_hour_short);
1895
+    } else if ($format == 'hourduration') {
1896
+            $format = ($outputlangs->trans("FormatHourShortDuration") != "FormatHourShortDuration" ? $outputlangs->trans("FormatHourShortDuration") : $conf->format_hour_short_duration);
1897
+    } else if ($format == 'daytext') {
1898
+            $format = ($outputlangs->trans("FormatDateText") != "FormatDateText" ? $outputlangs->trans("FormatDateText") : $conf->format_date_text);
1899
+    } else if ($format == 'daytextshort') {
1900
+        // Notice: Undefined property: stdClass::$format_date_text_short in \alixar\dolibarr\htdocs\core\lib\functions.lib.php on line 1781
1812 1901
         $format = ($outputlangs->trans("FormatDateTextShort") != "FormatDateTextShort" ? $outputlangs->trans("FormatDateTextShort") : $conf->format_date_text_short);
1813
-    else if ($format == 'dayhour')
1814
-        $format = ($outputlangs->trans("FormatDateHourShort") != "FormatDateHourShort" ? $outputlangs->trans("FormatDateHourShort") : $conf->format_date_hour_short);
1815
-    else if ($format == 'dayhoursec')
1816
-        $format = ($outputlangs->trans("FormatDateHourSecShort") != "FormatDateHourSecShort" ? $outputlangs->trans("FormatDateHourSecShort") : $conf->format_date_hour_sec_short);
1817
-    else if ($format == 'dayhourtext')
1818
-        $format = ($outputlangs->trans("FormatDateHourText") != "FormatDateHourText" ? $outputlangs->trans("FormatDateHourText") : $conf->format_date_hour_text);
1819
-    else if ($format == 'dayhourtextshort')
1820
-        $format = ($outputlangs->trans("FormatDateHourTextShort") != "FormatDateHourTextShort" ? $outputlangs->trans("FormatDateHourTextShort") : $conf->format_date_hour_text_short);
1902
+    } else if ($format == 'dayhour') {
1903
+            $format = ($outputlangs->trans("FormatDateHourShort") != "FormatDateHourShort" ? $outputlangs->trans("FormatDateHourShort") : $conf->format_date_hour_short);
1904
+    } else if ($format == 'dayhoursec') {
1905
+            $format = ($outputlangs->trans("FormatDateHourSecShort") != "FormatDateHourSecShort" ? $outputlangs->trans("FormatDateHourSecShort") : $conf->format_date_hour_sec_short);
1906
+    } else if ($format == 'dayhourtext') {
1907
+            $format = ($outputlangs->trans("FormatDateHourText") != "FormatDateHourText" ? $outputlangs->trans("FormatDateHourText") : $conf->format_date_hour_text);
1908
+    } else if ($format == 'dayhourtextshort') {
1909
+            $format = ($outputlangs->trans("FormatDateHourTextShort") != "FormatDateHourTextShort" ? $outputlangs->trans("FormatDateHourTextShort") : $conf->format_date_hour_text_short);
1910
+    }
1821 1911
     // Format not sensitive to language
1822
-    else if ($format == 'dayhourlog')
1823
-        $format = '%Y%m%d%H%M%S';
1824
-    else if ($format == 'dayhourldap')
1825
-        $format = '%Y%m%d%H%M%SZ';
1826
-    else if ($format == 'dayhourxcard')
1827
-        $format = '%Y%m%dT%H%M%SZ';
1828
-    else if ($format == 'dayxcard')
1829
-        $format = '%Y%m%d';
1830
-    else if ($format == 'dayrfc')
1831
-        $format = '%Y-%m-%d';             // DATE_RFC3339
1832
-    else if ($format == 'dayhourrfc')
1833
-        $format = '%Y-%m-%dT%H:%M:%SZ';   // DATETIME RFC3339
1834
-    else if ($format == 'standard')
1835
-        $format = '%Y-%m-%d %H:%M:%S';
1912
+    else if ($format == 'dayhourlog') {
1913
+            $format = '%Y%m%d%H%M%S';
1914
+    } else if ($format == 'dayhourldap') {
1915
+            $format = '%Y%m%d%H%M%SZ';
1916
+    } else if ($format == 'dayhourxcard') {
1917
+            $format = '%Y%m%dT%H%M%SZ';
1918
+    } else if ($format == 'dayxcard') {
1919
+            $format = '%Y%m%d';
1920
+    } else if ($format == 'dayrfc') {
1921
+            $format = '%Y-%m-%d';
1922
+    }
1923
+    // DATE_RFC3339
1924
+    else if ($format == 'dayhourrfc') {
1925
+            $format = '%Y-%m-%dT%H:%M:%SZ';
1926
+    }
1927
+    // DATETIME RFC3339
1928
+    else if ($format == 'standard') {
1929
+            $format = '%Y-%m-%d %H:%M:%S';
1930
+    }
1836 1931
 
1837 1932
     if ($reduceformat) {
1838 1933
         $format = str_replace('%Y', '%y', $format);
@@ -1840,8 +1935,10 @@  discard block
 block discarded – undo
1840 1935
     }
1841 1936
 
1842 1937
     // If date undefined or "", we return ""
1843
-    if (dol_strlen($time) == 0)
1844
-        return '';  // $time=0 allowed (it means 01/01/1970 00:00:00)
1938
+    if (dol_strlen($time) == 0) {
1939
+            return '';
1940
+    }
1941
+    // $time=0 allowed (it means 01/01/1970 00:00:00)
1845 1942
 
1846 1943
 
1847 1944
 
@@ -1901,8 +1998,9 @@  discard block
 block discarded – undo
1901 1998
             $timetouse = $time + $offsettz + $offsetdst; // TODO Replace this with function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
1902 1999
 
1903 2000
             $ret = adodb_strftime($format, $timetouse, $to_gmt);
1904
-        } else
1905
-            $ret = 'Bad value ' . $time . ' for date';
2001
+        } else {
2002
+                    $ret = 'Bad value ' . $time . ' for date';
2003
+        }
1906 2004
     }
1907 2005
 
1908 2006
     if (preg_match('/__b__/i', $format)) {
@@ -1973,10 +2071,14 @@  discard block
 block discarded – undo
1973 2071
     global $conf;
1974 2072
 
1975 2073
     $usealternatemethod = false;
1976
-    if ($timestamp <= 0)
1977
-        $usealternatemethod = true;    // <= 1970
1978
-    if ($timestamp >= 2145913200)
1979
-        $usealternatemethod = true;  // >= 2038
2074
+    if ($timestamp <= 0) {
2075
+            $usealternatemethod = true;
2076
+    }
2077
+    // <= 1970
2078
+    if ($timestamp >= 2145913200) {
2079
+            $usealternatemethod = true;
2080
+    }
2081
+    // >= 2038
1980 2082
 
1981 2083
     if ($usealternatemethod) {
1982 2084
         $arrayinfo = adodb_getdate($timestamp, $fast);
@@ -2011,27 +2113,36 @@  discard block
 block discarded – undo
2011 2113
     global $conf;
2012 2114
     //print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -";
2013 2115
     // Clean parameters
2014
-    if ($hour == -1 || empty($hour))
2015
-        $hour = 0;
2016
-    if ($minute == -1 || empty($minute))
2017
-        $minute = 0;
2018
-    if ($second == -1 || empty($second))
2019
-        $second = 0;
2116
+    if ($hour == -1 || empty($hour)) {
2117
+            $hour = 0;
2118
+    }
2119
+    if ($minute == -1 || empty($minute)) {
2120
+            $minute = 0;
2121
+    }
2122
+    if ($second == -1 || empty($second)) {
2123
+            $second = 0;
2124
+    }
2020 2125
 
2021 2126
     // Check parameters
2022 2127
     if ($check) {
2023
-        if (!$month || !$day)
2024
-            return '';
2025
-        if ($day > 31)
2026
-            return '';
2027
-        if ($month > 12)
2028
-            return '';
2029
-        if ($hour < 0 || $hour > 24)
2030
-            return '';
2031
-        if ($minute < 0 || $minute > 60)
2032
-            return '';
2033
-        if ($second < 0 || $second > 60)
2034
-            return '';
2128
+        if (!$month || !$day) {
2129
+                    return '';
2130
+        }
2131
+        if ($day > 31) {
2132
+                    return '';
2133
+        }
2134
+        if ($month > 12) {
2135
+                    return '';
2136
+        }
2137
+        if ($hour < 0 || $hour > 24) {
2138
+                    return '';
2139
+        }
2140
+        if ($minute < 0 || $minute > 60) {
2141
+                    return '';
2142
+        }
2143
+        if ($second < 0 || $second > 60) {
2144
+                    return '';
2145
+        }
2035 2146
     }
2036 2147
 
2037 2148
     if (method_exists('DateTime', 'getTimestamp')) {
@@ -2088,8 +2199,10 @@  discard block
 block discarded – undo
2088 2199
 
2089 2200
     // Note that gmmktime and mktime return same value (GMT) when used without parameters
2090 2201
     //if ($mode == 'gmt') $ret=gmmktime(); // Strict Standards: gmmktime(): You should be using the time() function instead
2091
-    if ($mode == 'gmt')
2092
-        $ret = time(); // Time for now at greenwich.
2202
+    if ($mode == 'gmt') {
2203
+            $ret = time();
2204
+    }
2205
+    // Time for now at greenwich.
2093 2206
     else if ($mode == 'tzserver') {  // Time for now with PHP server timezone added
2094 2207
         require_once DOL_BASE_PATH . '/core/lib/date.lib.php';
2095 2208
         $tzsecond = getServerTimeZoneInt('now');    // Contains tz+dayling saving time
@@ -2123,8 +2236,9 @@  discard block
 block discarded – undo
2123 2236
     global $conf, $langs;
2124 2237
     $level = 1024;
2125 2238
 
2126
-    if (!empty($conf->dol_optimize_smallscreen))
2127
-        $shortunit = 1;
2239
+    if (!empty($conf->dol_optimize_smallscreen)) {
2240
+            $shortunit = 1;
2241
+    }
2128 2242
 
2129 2243
     // Set value text
2130 2244
     if (empty($shortvalue) || $size < ($level * 10)) {
@@ -2159,19 +2273,23 @@  discard block
 block discarded – undo
2159 2273
 {
2160 2274
     global $langs;
2161 2275
 
2162
-    if (empty($url))
2163
-        return '';
2276
+    if (empty($url)) {
2277
+            return '';
2278
+    }
2164 2279
 
2165 2280
     $link = '<a href="';
2166
-    if (!preg_match('/^http/i', $url))
2167
-        $link .= 'http://';
2281
+    if (!preg_match('/^http/i', $url)) {
2282
+            $link .= 'http://';
2283
+    }
2168 2284
     $link .= $url;
2169 2285
     $link .= '"';
2170
-    if ($target)
2171
-        $link .= ' target="' . $target . '"';
2286
+    if ($target) {
2287
+            $link .= ' target="' . $target . '"';
2288
+    }
2172 2289
     $link .= '>';
2173
-    if (!preg_match('/^http/i', $url))
2174
-        $link .= 'http://';
2290
+    if (!preg_match('/^http/i', $url)) {
2291
+            $link .= 'http://';
2292
+    }
2175 2293
     $link .= dol_trunc($url, $max);
2176 2294
     $link .= '</a>';
2177 2295
     return '<div class="nospan float" style="margin-right: 10px">' . ($withpicto ? img_picto($langs->trans("Url"), 'object_globe.png') . ' ' : '') . $link . '</div>';
@@ -2195,13 +2313,15 @@  discard block
 block discarded – undo
2195 2313
 
2196 2314
     $newemail = $email;
2197 2315
 
2198
-    if (empty($email))
2199
-        return '&nbsp;';
2316
+    if (empty($email)) {
2317
+            return '&nbsp;';
2318
+    }
2200 2319
 
2201 2320
     if (!empty($addlink)) {
2202 2321
         $newemail = '<a style="text-overflow: ellipsis;" href="';
2203
-        if (!preg_match('/^mailto:/i', $email))
2204
-            $newemail .= 'mailto:';
2322
+        if (!preg_match('/^mailto:/i', $email)) {
2323
+                    $newemail .= 'mailto:';
2324
+        }
2205 2325
         $newemail .= $email;
2206 2326
         $newemail .= '">';
2207 2327
         $newemail .= dol_trunc($email, $max);
@@ -2214,13 +2334,14 @@  discard block
 block discarded – undo
2214 2334
         if (($cid || $socid) && !empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create) {
2215 2335
             $type = 'AC_EMAIL';
2216 2336
             $link = '';
2217
-            if (!empty($conf->global->AGENDA_ADDACTIONFOREMAIL))
2218
-                $link = '<a href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode=' . $type . '&amp;contactid=' . $cid . '&amp;socid=' . $socid . '">' . img_object($langs->trans("AddAction"), "calendar") . '</a>';
2219
-            if ($link)
2220
-                $newemail = '<div>' . $newemail . ' ' . $link . '</div>';
2337
+            if (!empty($conf->global->AGENDA_ADDACTIONFOREMAIL)) {
2338
+                            $link = '<a href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode=' . $type . '&amp;contactid=' . $cid . '&amp;socid=' . $socid . '">' . img_object($langs->trans("AddAction"), "calendar") . '</a>';
2339
+            }
2340
+            if ($link) {
2341
+                            $newemail = '<div>' . $newemail . ' ' . $link . '</div>';
2342
+            }
2221 2343
         }
2222
-    }
2223
-    else {
2344
+    } else {
2224 2345
         if ($showinvalid && !isValidEmail($email)) {
2225 2346
             $langs->load("errors");
2226 2347
             $newemail .= img_warning($langs->trans("ErrorBadEMail", $email));
@@ -2252,8 +2373,9 @@  discard block
 block discarded – undo
2252 2373
 
2253 2374
     $newskype = $value;
2254 2375
 
2255
-    if (empty($value))
2256
-        return '&nbsp;';
2376
+    if (empty($value)) {
2377
+            return '&nbsp;';
2378
+    }
2257 2379
 
2258 2380
     if (!empty($type)) {
2259 2381
         $newskype = '<div class="divsocialnetwork inline-block valignmiddle">';
@@ -2274,13 +2396,13 @@  discard block
 block discarded – undo
2274 2396
         if (($cid || $socid) && !empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create && $type == 'skype') {
2275 2397
             $addlink = 'AC_SKYPE';
2276 2398
             $link = '';
2277
-            if (!empty($conf->global->AGENDA_ADDACTIONFORSKYPE))
2278
-                $link = '<a href="' . BASE_URI . '?controller=comm/action&method=card&action=create&amp;backtopage=1&amp;actioncode=' . $addlink . '&amp;contactid=' . $cid . '&amp;socid=' . $socid . '">' . img_object($langs->trans("AddAction"), "calendar") . '</a>';
2399
+            if (!empty($conf->global->AGENDA_ADDACTIONFORSKYPE)) {
2400
+                            $link = '<a href="' . BASE_URI . '?controller=comm/action&method=card&action=create&amp;backtopage=1&amp;actioncode=' . $addlink . '&amp;contactid=' . $cid . '&amp;socid=' . $socid . '">' . img_object($langs->trans("AddAction"), "calendar") . '</a>';
2401
+            }
2279 2402
             $newskype .= ($link ? ' ' . $link : '');
2280 2403
         }
2281 2404
         $newskype .= '</div>';
2282
-    }
2283
-    else {
2405
+    } else {
2284 2406
         $langs->load("errors");
2285 2407
         $newskype .= img_warning($langs->trans("ErrorBadSocialNetworkValue", $value));
2286 2408
     }
@@ -2310,12 +2432,14 @@  discard block
 block discarded – undo
2310 2432
     if (empty($phone)) {
2311 2433
         return '';
2312 2434
     }
2313
-    if (empty($countrycode))
2314
-        $countrycode = $mysoc->country_code;
2435
+    if (empty($countrycode)) {
2436
+            $countrycode = $mysoc->country_code;
2437
+    }
2315 2438
 
2316 2439
     // Short format for small screens
2317
-    if ($conf->dol_optimize_smallscreen)
2318
-        $separ = '';
2440
+    if ($conf->dol_optimize_smallscreen) {
2441
+            $separ = '';
2442
+    }
2319 2443
 
2320 2444
     $newphone = $phone;
2321 2445
     if (strtoupper($countrycode) == "FR") {
@@ -2481,15 +2605,18 @@  discard block
 block discarded – undo
2481 2605
             $newphone = '<a href="tel:' . $phone . '"';
2482 2606
             $newphone .= '>' . $phone . '</a>';
2483 2607
         } else if (!empty($conf->clicktodial->enabled) && $addlink == 'AC_TEL') {  // If click to dial, we use click to dial url
2484
-            if (empty($user->clicktodial_loaded))
2485
-                $user->fetch_clicktodial();
2608
+            if (empty($user->clicktodial_loaded)) {
2609
+                            $user->fetch_clicktodial();
2610
+            }
2486 2611
 
2487 2612
             // Define urlmask
2488 2613
             $urlmask = 'ErrorClickToDialModuleNotConfigured';
2489
-            if (!empty($conf->global->CLICKTODIAL_URL))
2490
-                $urlmask = $conf->global->CLICKTODIAL_URL;
2491
-            if (!empty($user->clicktodial_url))
2492
-                $urlmask = $user->clicktodial_url;
2614
+            if (!empty($conf->global->CLICKTODIAL_URL)) {
2615
+                            $urlmask = $conf->global->CLICKTODIAL_URL;
2616
+            }
2617
+            if (!empty($user->clicktodial_url)) {
2618
+                            $urlmask = $user->clicktodial_url;
2619
+            }
2493 2620
 
2494 2621
             $clicktodial_poste = (!empty($user->clicktodial_poste) ? urlencode($user->clicktodial_poste) : '');
2495 2622
             $clicktodial_login = (!empty($user->clicktodial_login) ? urlencode($user->clicktodial_login) : '');
@@ -2504,8 +2631,9 @@  discard block
 block discarded – undo
2504 2631
             $url = make_substitutions($url, $substitarray);
2505 2632
             $newphonesav = $newphone;
2506 2633
             $newphone = '<a href="' . $url . '"';
2507
-            if (!empty($conf->global->CLICKTODIAL_FORCENEWTARGET))
2508
-                $newphone .= ' target="_blank"';
2634
+            if (!empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) {
2635
+                            $newphone .= ' target="_blank"';
2636
+            }
2509 2637
             $newphone .= '>' . $newphonesav . '</a>';
2510 2638
         }
2511 2639
 
@@ -2513,12 +2641,15 @@  discard block
 block discarded – undo
2513 2641
         if (!empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create) {
2514 2642
             $type = 'AC_TEL';
2515 2643
             $link = '';
2516
-            if ($addlink == 'AC_FAX')
2517
-                $type = 'AC_FAX';
2518
-            if (!empty($conf->global->AGENDA_ADDACTIONFORPHONE))
2519
-                $link = '<a href="' . BASE_URI . '?controller=comm/action&method=card&action=create&amp;backtopage=1&amp;actioncode=' . $type . ($cid ? '&amp;contactid=' . $cid : '') . ($socid ? '&amp;socid=' . $socid : '') . '">' . img_object($langs->trans("AddAction"), "calendar") . '</a>';
2520
-            if ($link)
2521
-                $newphone = '<div>' . $newphone . ' ' . $link . '</div>';
2644
+            if ($addlink == 'AC_FAX') {
2645
+                            $type = 'AC_FAX';
2646
+            }
2647
+            if (!empty($conf->global->AGENDA_ADDACTIONFORPHONE)) {
2648
+                            $link = '<a href="' . BASE_URI . '?controller=comm/action&method=card&action=create&amp;backtopage=1&amp;actioncode=' . $type . ($cid ? '&amp;contactid=' . $cid : '') . ($socid ? '&amp;socid=' . $socid : '') . '">' . img_object($langs->trans("AddAction"), "calendar") . '</a>';
2649
+            }
2650
+            if ($link) {
2651
+                            $newphone = '<div>' . $newphone . ' ' . $link . '</div>';
2652
+            }
2522 2653
         }
2523 2654
     }
2524 2655
 
@@ -2545,15 +2676,17 @@  discard block
 block discarded – undo
2545 2676
                 $picto = '';
2546 2677
             }
2547 2678
         }
2548
-        if ($adddivfloat)
2549
-            $rep .= '<div class="nospan float" style="margin-right: 10px">';
2550
-        else
2551
-            $rep .= '<span style="margin-right: 10px;">';
2679
+        if ($adddivfloat) {
2680
+                    $rep .= '<div class="nospan float" style="margin-right: 10px">';
2681
+        } else {
2682
+                    $rep .= '<span style="margin-right: 10px;">';
2683
+        }
2552 2684
         $rep .= ($withpicto ? img_picto($titlealt, 'object_' . $picto . '.png') . ' ' : '') . $newphone;
2553
-        if ($adddivfloat)
2554
-            $rep .= '</div>';
2555
-        else
2556
-            $rep .= '</span>';
2685
+        if ($adddivfloat) {
2686
+                    $rep .= '</div>';
2687
+        } else {
2688
+                    $rep .= '</span>';
2689
+        }
2557 2690
     }
2558 2691
 
2559 2692
     return $rep;
@@ -2583,8 +2716,9 @@  discard block
 block discarded – undo
2583 2716
         if ($countrycode) { // If success, countrycode is us, fr, ...
2584 2717
             if (file_exists(DOL_BASE_PATH . '/theme/common/flags/' . $countrycode . '.png')) {
2585 2718
                 $ret .= ' ' . img_picto($countrycode . ' ' . $langs->trans("AccordingToGeoIPDatabase"), DOL_BASE_URI . '/theme/common/flags/' . $countrycode . '.png', '', 1);
2586
-            } else
2587
-                $ret .= ' (' . $countrycode . ')';
2719
+            } else {
2720
+                            $ret .= ' (' . $countrycode . ')';
2721
+            }
2588 2722
         }
2589 2723
     }
2590 2724
 
@@ -2682,26 +2816,33 @@  discard block
 block discarded – undo
2682 2816
             $out .= $hookmanager->resPrint;
2683 2817
         }
2684 2818
         if (empty($reshook)) {
2685
-            if (empty($charfornl))
2686
-                $out .= nl2br($address);
2687
-            else
2688
-                $out .= preg_replace('/[\r\n]+/', $charfornl, $address);
2819
+            if (empty($charfornl)) {
2820
+                            $out .= nl2br($address);
2821
+            } else {
2822
+                            $out .= preg_replace('/[\r\n]+/', $charfornl, $address);
2823
+            }
2689 2824
 
2690 2825
             $showgmap = $showomap = 0;
2691 2826
 
2692 2827
             // TODO Add a hook here
2693
-            if (($mode == 'thirdparty' || $mode == 'societe') && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS))
2694
-                $showgmap = 1;
2695
-            if ($mode == 'contact' && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS))
2696
-                $showgmap = 1;
2697
-            if ($mode == 'member' && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS))
2698
-                $showgmap = 1;
2699
-            if (($mode == 'thirdparty' || $mode == 'societe') && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS))
2700
-                $showomap = 1;
2701
-            if ($mode == 'contact' && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS))
2702
-                $showomap = 1;
2703
-            if ($mode == 'member' && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS))
2704
-                $showomap = 1;
2828
+            if (($mode == 'thirdparty' || $mode == 'societe') && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS)) {
2829
+                            $showgmap = 1;
2830
+            }
2831
+            if ($mode == 'contact' && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS)) {
2832
+                            $showgmap = 1;
2833
+            }
2834
+            if ($mode == 'member' && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS)) {
2835
+                            $showgmap = 1;
2836
+            }
2837
+            if (($mode == 'thirdparty' || $mode == 'societe') && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS)) {
2838
+                            $showomap = 1;
2839
+            }
2840
+            if ($mode == 'contact' && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS)) {
2841
+                            $showomap = 1;
2842
+            }
2843
+            if ($mode == 'member' && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS)) {
2844
+                            $showomap = 1;
2845
+            }
2705 2846
 
2706 2847
             if ($showgmap) {
2707 2848
                 $url = dol_buildpath('/google/gmaps.php?mode=' . $mode . '&id=' . $id, 1);
@@ -2713,11 +2854,12 @@  discard block
 block discarded – undo
2713 2854
             }
2714 2855
         }
2715 2856
     }
2716
-    if ($noprint)
2717
-        return $out;
2718
-    else
2719
-        print $out;
2720
-}
2857
+    if ($noprint) {
2858
+            return $out;
2859
+    } else {
2860
+            print $out;
2861
+    }
2862
+    }
2721 2863
 
2722 2864
 /**
2723 2865
  * 	Return true if email syntax is ok
@@ -2728,10 +2870,12 @@  discard block
 block discarded – undo
2728 2870
  */
2729 2871
 function isValidEmail($address, $acceptsupervisorkey = 0)
2730 2872
 {
2731
-    if ($acceptsupervisorkey && $address == '__SUPERVISOREMAIL__')
2732
-        return true;
2733
-    if (filter_var($address, FILTER_VALIDATE_EMAIL))
2734
-        return true;
2873
+    if ($acceptsupervisorkey && $address == '__SUPERVISOREMAIL__') {
2874
+            return true;
2875
+    }
2876
+    if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
2877
+            return true;
2878
+    }
2735 2879
 
2736 2880
     return false;
2737 2881
 }
@@ -2753,10 +2897,12 @@  discard block
 block discarded – undo
2753 2897
             $mxhosts = array();
2754 2898
             $weight = array();
2755 2899
             getmxrr(idn_to_ascii($domain), $mxhosts, $weight);
2756
-            if (count($mxhosts) > 1)
2757
-                return 1;
2758
-            if (count($mxhosts) == 1 && !empty($mxhosts[0]))
2759
-                return 1;
2900
+            if (count($mxhosts) > 1) {
2901
+                            return 1;
2902
+            }
2903
+            if (count($mxhosts) == 1 && !empty($mxhosts[0])) {
2904
+                            return 1;
2905
+            }
2760 2906
 
2761 2907
             return 0;
2762 2908
         }
@@ -2785,11 +2931,12 @@  discard block
 block discarded – undo
2785 2931
  */
2786 2932
 function dol_strlen($string, $stringencoding = 'UTF-8')
2787 2933
 {
2788
-    if (function_exists('mb_strlen'))
2789
-        return mb_strlen($string, $stringencoding);
2790
-    else
2791
-        return strlen($string);
2792
-}
2934
+    if (function_exists('mb_strlen')) {
2935
+            return mb_strlen($string, $stringencoding);
2936
+    } else {
2937
+            return strlen($string);
2938
+    }
2939
+    }
2793 2940
 
2794 2941
 /**
2795 2942
  * Make a substring. Works even if mbstring module is not enabled for better compatibility.
@@ -2805,8 +2952,9 @@  discard block
 block discarded – undo
2805 2952
 {
2806 2953
     global $langs;
2807 2954
 
2808
-    if (empty($stringencoding))
2809
-        $stringencoding = $langs->charset_output;
2955
+    if (empty($stringencoding)) {
2956
+            $stringencoding = $langs->charset_output;
2957
+    }
2810 2958
 
2811 2959
     $ret = '';
2812 2960
     if (empty($trunconbytes)) {
@@ -2842,49 +2990,56 @@  discard block
 block discarded – undo
2842 2990
 {
2843 2991
     global $conf;
2844 2992
 
2845
-    if ($size == 0 || !empty($conf->global->MAIN_DISABLE_TRUNC))
2846
-        return $string;
2993
+    if ($size == 0 || !empty($conf->global->MAIN_DISABLE_TRUNC)) {
2994
+            return $string;
2995
+    }
2847 2996
 
2848
-    if (empty($stringencoding))
2849
-        $stringencoding = 'UTF-8';
2997
+    if (empty($stringencoding)) {
2998
+            $stringencoding = 'UTF-8';
2999
+    }
2850 3000
     // reduce for small screen
2851
-    if ($conf->dol_optimize_smallscreen == 1 && $display == 1)
2852
-        $size = round($size / 3);
3001
+    if ($conf->dol_optimize_smallscreen == 1 && $display == 1) {
3002
+            $size = round($size / 3);
3003
+    }
2853 3004
 
2854 3005
     // We go always here
2855 3006
     if ($trunc == 'right') {
2856 3007
         $newstring = dol_textishtml($string) ? dol_string_nohtmltag($string, 1) : $string;
2857
-        if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 3)))    // If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ...
3008
+        if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 3))) {
3009
+            // If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ...
2858 3010
             return dol_substr($newstring, 0, $size, $stringencoding) . ($nodot ? '' : '...');
2859
-        else
2860
-        //return 'u'.$size.'-'.$newstring.'-'.dol_strlen($newstring,$stringencoding).'-'.$string;
3011
+        } else {
3012
+                //return 'u'.$size.'-'.$newstring.'-'.dol_strlen($newstring,$stringencoding).'-'.$string;
2861 3013
             return $string;
2862
-    }
2863
-    elseif ($trunc == 'middle') {
3014
+        }
3015
+    } elseif ($trunc == 'middle') {
2864 3016
         $newstring = dol_textishtml($string) ? dol_string_nohtmltag($string, 1) : $string;
2865 3017
         if (dol_strlen($newstring, $stringencoding) > 2 && dol_strlen($newstring, $stringencoding) > ($size + 1)) {
2866 3018
             $size1 = round($size / 2);
2867 3019
             $size2 = round($size / 2);
2868 3020
             return dol_substr($newstring, 0, $size1, $stringencoding) . '...' . dol_substr($newstring, dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
2869
-        } else
2870
-            return $string;
2871
-    }
2872
-    elseif ($trunc == 'left') {
3021
+        } else {
3022
+                    return $string;
3023
+        }
3024
+    } elseif ($trunc == 'left') {
2873 3025
         $newstring = dol_textishtml($string) ? dol_string_nohtmltag($string, 1) : $string;
2874
-        if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 3)))    // If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ...
3026
+        if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 3))) {
3027
+            // If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ...
2875 3028
             return '...' . dol_substr($newstring, dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
2876
-        else
2877
-            return $string;
2878
-    }
2879
-    elseif ($trunc == 'wrap') {
3029
+        } else {
3030
+                    return $string;
3031
+        }
3032
+    } elseif ($trunc == 'wrap') {
2880 3033
         $newstring = dol_textishtml($string) ? dol_string_nohtmltag($string, 1) : $string;
2881
-        if (dol_strlen($newstring, $stringencoding) > ($size + 1))
2882
-            return dol_substr($newstring, 0, $size, $stringencoding) . "\n" . dol_trunc(dol_substr($newstring, $size, dol_strlen($newstring, $stringencoding) - $size, $stringencoding), $size, $trunc);
2883
-        else
2884
-            return $string;
2885
-    } else
2886
-        return 'BadParam3CallingDolTrunc';
2887
-}
3034
+        if (dol_strlen($newstring, $stringencoding) > ($size + 1)) {
3035
+                    return dol_substr($newstring, 0, $size, $stringencoding) . "\n" . dol_trunc(dol_substr($newstring, $size, dol_strlen($newstring, $stringencoding) - $size, $stringencoding), $size, $trunc);
3036
+        } else {
3037
+                    return $string;
3038
+        }
3039
+    } else {
3040
+            return 'BadParam3CallingDolTrunc';
3041
+    }
3042
+    }
2888 3043
 
2889 3044
 /**
2890 3045
  * 	Show picto whatever it's its name (generic function)
@@ -3095,8 +3250,9 @@  discard block
 block discarded – undo
3095 3250
 {
3096 3251
     global $conf;
3097 3252
 
3098
-    if (!preg_match('/(\.png|\.gif)$/i', $picto))
3099
-        $picto .= '.png';
3253
+    if (!preg_match('/(\.png|\.gif)$/i', $picto)) {
3254
+            $picto .= '.png';
3255
+    }
3100 3256
 
3101 3257
     //$path = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/weather/' . $picto;
3102 3258
     $path = DOL_BASE_URI . '/theme/' . $conf->theme . '/img/weather/' . $picto;
@@ -3118,20 +3274,22 @@  discard block
 block discarded – undo
3118 3274
 {
3119 3275
     global $conf;
3120 3276
 
3121
-    if (!preg_match('/(\.png|\.gif)$/i', $picto))
3122
-        $picto .= '.png';
3277
+    if (!preg_match('/(\.png|\.gif)$/i', $picto)) {
3278
+            $picto .= '.png';
3279
+    }
3123 3280
 
3124
-    if ($pictoisfullpath)
3125
-        $path = $picto;
3126
-    else {
3281
+    if ($pictoisfullpath) {
3282
+            $path = $picto;
3283
+    } else {
3127 3284
         //$path = DOL_URL_ROOT . '/theme/common/' . $picto;
3128 3285
         $path = DOL_BASE_URI . '/theme/common/' . $picto;
3129 3286
 
3130 3287
         if (!empty($conf->global->MAIN_MODULE_CAN_OVERWRITE_COMMONICONS)) {
3131 3288
             $themepath = DOL_BASE_PATH . 'theme/' . $conf->theme . '/img/' . $picto;
3132 3289
 
3133
-            if (file_exists($themepath))
3134
-                $path = $themepath;
3290
+            if (file_exists($themepath)) {
3291
+                            $path = $themepath;
3292
+            }
3135 3293
         }
3136 3294
     }
3137 3295
 
@@ -3170,8 +3328,9 @@  discard block
 block discarded – undo
3170 3328
             $numaction = 0;
3171 3329
         }
3172 3330
     }
3173
-    if (!is_numeric($numaction))
3174
-        $numaction = 0;
3331
+    if (!is_numeric($numaction)) {
3332
+            $numaction = 0;
3333
+    }
3175 3334
 
3176 3335
     return img_picto($titlealt, 'stcomm' . $numaction . '.png');
3177 3336
 }
@@ -3187,8 +3346,9 @@  discard block
 block discarded – undo
3187 3346
 {
3188 3347
     global $conf, $langs;
3189 3348
 
3190
-    if ($titlealt == 'default')
3191
-        $titlealt = $langs->trans('Show');
3349
+    if ($titlealt == 'default') {
3350
+            $titlealt = $langs->trans('Show');
3351
+    }
3192 3352
 
3193 3353
     return img_picto($titlealt, 'pdf' . $size . '.png');
3194 3354
 }
@@ -3204,8 +3364,9 @@  discard block
 block discarded – undo
3204 3364
 {
3205 3365
     global $conf, $langs;
3206 3366
 
3207
-    if ($titlealt == 'default')
3208
-        $titlealt = $langs->trans('Add');
3367
+    if ($titlealt == 'default') {
3368
+            $titlealt = $langs->trans('Add');
3369
+    }
3209 3370
 
3210 3371
     return img_picto($titlealt, 'edit_add.png', $other);
3211 3372
 }
@@ -3221,8 +3382,9 @@  discard block
 block discarded – undo
3221 3382
 {
3222 3383
     global $conf, $langs;
3223 3384
 
3224
-    if ($titlealt == 'default')
3225
-        $titlealt = $langs->trans('Remove');
3385
+    if ($titlealt == 'default') {
3386
+            $titlealt = $langs->trans('Remove');
3387
+    }
3226 3388
 
3227 3389
     return img_picto($titlealt, 'edit_remove.png', $other);
3228 3390
 }
@@ -3239,8 +3401,9 @@  discard block
 block discarded – undo
3239 3401
 {
3240 3402
     global $conf, $langs;
3241 3403
 
3242
-    if ($titlealt == 'default')
3243
-        $titlealt = $langs->trans('Modify');
3404
+    if ($titlealt == 'default') {
3405
+            $titlealt = $langs->trans('Modify');
3406
+    }
3244 3407
 
3245 3408
     return img_picto($titlealt, 'edit.png', ($float ? 'style="float: ' . ($langs->tab_translate["DIRECTION"] == 'rtl' ? 'left' : 'right') . '"' : "") . ($other ? ' ' . $other : ''));
3246 3409
 }
@@ -3257,8 +3420,9 @@  discard block
 block discarded – undo
3257 3420
 {
3258 3421
     global $conf, $langs;
3259 3422
 
3260
-    if ($titlealt == 'default')
3261
-        $titlealt = $langs->trans('View');
3423
+    if ($titlealt == 'default') {
3424
+            $titlealt = $langs->trans('View');
3425
+    }
3262 3426
 
3263 3427
     $moreatt = ($float ? 'style="float: right" ' : '') . $other;
3264 3428
 
@@ -3276,8 +3440,9 @@  discard block
 block discarded – undo
3276 3440
 {
3277 3441
     global $conf, $langs;
3278 3442
 
3279
-    if ($titlealt == 'default')
3280
-        $titlealt = $langs->trans('Delete');
3443
+    if ($titlealt == 'default') {
3444
+            $titlealt = $langs->trans('Delete');
3445
+    }
3281 3446
 
3282 3447
     return img_picto($titlealt, 'delete.png', $other);
3283 3448
     //return '<span class="fa fa-trash fa-2x fa-fw" style="font-size: 1.7em;" title="'.$titlealt.'"></span>';
@@ -3293,8 +3458,9 @@  discard block
 block discarded – undo
3293 3458
 function img_printer($titlealt = "default", $other = '')
3294 3459
 {
3295 3460
     global $conf, $langs;
3296
-    if ($titlealt == "default")
3297
-        $titlealt = $langs->trans("Print");
3461
+    if ($titlealt == "default") {
3462
+            $titlealt = $langs->trans("Print");
3463
+    }
3298 3464
     return img_picto($titlealt, 'printer.png', $other);
3299 3465
 }
3300 3466
 
@@ -3309,8 +3475,9 @@  discard block
 block discarded – undo
3309 3475
 {
3310 3476
     global $conf, $langs;
3311 3477
 
3312
-    if ($titlealt == 'default')
3313
-        $titlealt = $langs->trans('Split');
3478
+    if ($titlealt == 'default') {
3479
+            $titlealt = $langs->trans('Split');
3480
+    }
3314 3481
 
3315 3482
     return img_picto($titlealt, 'split.png', $other);
3316 3483
 }
@@ -3327,10 +3494,11 @@  discard block
 block discarded – undo
3327 3494
     global $conf, $langs;
3328 3495
 
3329 3496
     if ($usealttitle) {
3330
-        if (is_string($usealttitle))
3331
-            $usealttitle = dol_escape_htmltag($usealttitle);
3332
-        else
3333
-            $usealttitle = $langs->trans('Info');
3497
+        if (is_string($usealttitle)) {
3498
+                    $usealttitle = dol_escape_htmltag($usealttitle);
3499
+        } else {
3500
+                    $usealttitle = $langs->trans('Info');
3501
+        }
3334 3502
     }
3335 3503
 
3336 3504
     return img_picto($usealttitle, 'info.png', 'style="vertical-align: middle;' . ($usehelpcursor == 1 ? ' cursor: help' : ($usehelpcursor == 2 ? ' cursor: pointer' : '')) . '"');
@@ -3346,8 +3514,9 @@  discard block
 block discarded – undo
3346 3514
 {
3347 3515
     global $conf, $langs;
3348 3516
 
3349
-    if ($titlealt == 'default')
3350
-        $titlealt = $langs->trans('Informations');
3517
+    if ($titlealt == 'default') {
3518
+            $titlealt = $langs->trans('Informations');
3519
+    }
3351 3520
 
3352 3521
     return img_picto($titlealt, 'info.png', 'style="vertical-align: middle;"');
3353 3522
 }
@@ -3363,8 +3532,9 @@  discard block
 block discarded – undo
3363 3532
 {
3364 3533
     global $conf, $langs;
3365 3534
 
3366
-    if ($titlealt == 'default')
3367
-        $titlealt = $langs->trans('Warning');
3535
+    if ($titlealt == 'default') {
3536
+            $titlealt = $langs->trans('Warning');
3537
+    }
3368 3538
 
3369 3539
     //return '<div class="imglatecoin">'.img_picto($titlealt, 'warning_white.png', 'class="pictowarning valignmiddle"'.($moreatt ? ($moreatt == '1' ? ' style="float: right"' : ' '.$moreatt): '')).'</div>';
3370 3540
     return img_picto($titlealt, 'warning.png', 'class="pictowarning valignmiddle"' . ($moreatt ? ($moreatt == '1' ? ' style="float: right"' : ' ' . $moreatt) : ''));
@@ -3380,8 +3550,9 @@  discard block
 block discarded – undo
3380 3550
 {
3381 3551
     global $conf, $langs;
3382 3552
 
3383
-    if ($titlealt == 'default')
3384
-        $titlealt = $langs->trans('Error');
3553
+    if ($titlealt == 'default') {
3554
+            $titlealt = $langs->trans('Error');
3555
+    }
3385 3556
 
3386 3557
     return img_picto($titlealt, 'error.png', 'class="valigntextbottom"');
3387 3558
 }
@@ -3397,8 +3568,9 @@  discard block
 block discarded – undo
3397 3568
 {
3398 3569
     global $conf, $langs;
3399 3570
 
3400
-    if ($titlealt == 'default')
3401
-        $titlealt = $langs->trans('Next');
3571
+    if ($titlealt == 'default') {
3572
+            $titlealt = $langs->trans('Next');
3573
+    }
3402 3574
 
3403 3575
     //return img_picto($titlealt, 'next.png', $moreatt);
3404 3576
     return '<span class="fa fa-chevron-right paddingright paddingleft" title="' . dol_escape_htmltag($titlealt) . '"></span>';
@@ -3415,8 +3587,9 @@  discard block
 block discarded – undo
3415 3587
 {
3416 3588
     global $conf, $langs;
3417 3589
 
3418
-    if ($titlealt == 'default')
3419
-        $titlealt = $langs->trans('Previous');
3590
+    if ($titlealt == 'default') {
3591
+            $titlealt = $langs->trans('Previous');
3592
+    }
3420 3593
 
3421 3594
     //return img_picto($titlealt, 'previous.png', $moreatt);
3422 3595
     return '<span class="fa fa-chevron-left paddingright paddingleft" title="' . dol_escape_htmltag($titlealt) . '"></span>';
@@ -3434,8 +3607,9 @@  discard block
 block discarded – undo
3434 3607
 {
3435 3608
     global $conf, $langs;
3436 3609
 
3437
-    if ($titlealt == 'default')
3438
-        $titlealt = $langs->trans('Down');
3610
+    if ($titlealt == 'default') {
3611
+            $titlealt = $langs->trans('Down');
3612
+    }
3439 3613
 
3440 3614
     return img_picto($titlealt, ($selected ? '1downarrow_selected.png' : '1downarrow.png'), 'class="imgdown' . ($moreclass ? " " . $moreclass : "") . '"');
3441 3615
 }
@@ -3452,8 +3626,9 @@  discard block
 block discarded – undo
3452 3626
 {
3453 3627
     global $conf, $langs;
3454 3628
 
3455
-    if ($titlealt == 'default')
3456
-        $titlealt = $langs->trans('Up');
3629
+    if ($titlealt == 'default') {
3630
+            $titlealt = $langs->trans('Up');
3631
+    }
3457 3632
 
3458 3633
     return img_picto($titlealt, ($selected ? '1uparrow_selected.png' : '1uparrow.png'), 'class="imgup' . ($moreclass ? " " . $moreclass : "") . '"');
3459 3634
 }
@@ -3470,8 +3645,9 @@  discard block
 block discarded – undo
3470 3645
 {
3471 3646
     global $conf, $langs;
3472 3647
 
3473
-    if ($titlealt == 'default')
3474
-        $titlealt = $langs->trans('Left');
3648
+    if ($titlealt == 'default') {
3649
+            $titlealt = $langs->trans('Left');
3650
+    }
3475 3651
 
3476 3652
     return img_picto($titlealt, ($selected ? '1leftarrow_selected.png' : '1leftarrow.png'), $moreatt);
3477 3653
 }
@@ -3488,8 +3664,9 @@  discard block
 block discarded – undo
3488 3664
 {
3489 3665
     global $conf, $langs;
3490 3666
 
3491
-    if ($titlealt == 'default')
3492
-        $titlealt = $langs->trans('Right');
3667
+    if ($titlealt == 'default') {
3668
+            $titlealt = $langs->trans('Right');
3669
+    }
3493 3670
 
3494 3671
     return img_picto($titlealt, ($selected ? '1rightarrow_selected.png' : '1rightarrow.png'), $moreatt);
3495 3672
 }
@@ -3505,11 +3682,13 @@  discard block
 block discarded – undo
3505 3682
 {
3506 3683
     global $conf, $langs;
3507 3684
 
3508
-    if ($titlealt == 'default')
3509
-        $titlealt = $langs->trans('Active');
3685
+    if ($titlealt == 'default') {
3686
+            $titlealt = $langs->trans('Active');
3687
+    }
3510 3688
 
3511
-    if ($allow == 1)
3512
-        return img_picto($titlealt, 'tick.png');
3689
+    if ($allow == 1) {
3690
+            return img_picto($titlealt, 'tick.png');
3691
+    }
3513 3692
 
3514 3693
     return '-';
3515 3694
 }
@@ -3557,8 +3736,9 @@  discard block
 block discarded – undo
3557 3736
     $mimeimg = dol_mimetype($file, '', 2);
3558 3737
     $mimefa = dol_mimetype($file, '', 4);
3559 3738
 
3560
-    if (empty($titlealt))
3561
-        $titlealt = 'Mime type: ' . $mimetype;
3739
+    if (empty($titlealt)) {
3740
+            $titlealt = 'Mime type: ' . $mimetype;
3741
+    }
3562 3742
 
3563 3743
     //return img_picto_common($titlealt, 'mime/'.$mimeimg, 'class="'.$morecss.'"');
3564 3744
     return '<i class="fa fa-' . $mimefa . ' paddingright"></i>';
@@ -3580,13 +3760,15 @@  discard block
 block discarded – undo
3580 3760
 
3581 3761
     global $conf, $langs;
3582 3762
 
3583
-    if ($titlealt == 'default')
3584
-        $titlealt = $langs->trans('Call');
3763
+    if ($titlealt == 'default') {
3764
+            $titlealt = $langs->trans('Call');
3765
+    }
3585 3766
 
3586
-    if ($option == 1)
3587
-        $img = 'call';
3588
-    else
3589
-        $img = 'call_out';
3767
+    if ($option == 1) {
3768
+            $img = 'call';
3769
+    } else {
3770
+            $img = 'call_out';
3771
+    }
3590 3772
 
3591 3773
     return img_picto($titlealt, $img);
3592 3774
 }
@@ -3602,8 +3784,9 @@  discard block
 block discarded – undo
3602 3784
 {
3603 3785
     global $conf, $langs;
3604 3786
 
3605
-    if ($titlealt == 'default')
3606
-        $titlealt = $langs->trans('Search');
3787
+    if ($titlealt == 'default') {
3788
+            $titlealt = $langs->trans('Search');
3789
+    }
3607 3790
 
3608 3791
     $img = img_picto($titlealt, 'search.png', $other, false, 1);
3609 3792
 
@@ -3624,8 +3807,9 @@  discard block
 block discarded – undo
3624 3807
 {
3625 3808
     global $conf, $langs;
3626 3809
 
3627
-    if ($titlealt == 'default')
3628
-        $titlealt = $langs->trans('Search');
3810
+    if ($titlealt == 'default') {
3811
+            $titlealt = $langs->trans('Search');
3812
+    }
3629 3813
 
3630 3814
     $img = img_picto($titlealt, 'searchclear.png', $other, false, 1);
3631 3815
 
@@ -3687,14 +3871,16 @@  discard block
 block discarded – undo
3687 3871
 
3688 3872
     if ($_SERVER['DOCUMENT_ROOT']) {    // Mode web
3689 3873
         $out .= $langs->trans("DolibarrHasDetectedError") . ".<br>\n";
3690
-        if (!empty($conf->global->MAIN_FEATURES_LEVEL))
3691
-            $out .= "You use an experimental or develop level of features, so please do NOT report any bugs, except if problem is confirmed moving option MAIN_FEATURES_LEVEL back to 0.<br>\n";
3874
+        if (!empty($conf->global->MAIN_FEATURES_LEVEL)) {
3875
+                    $out .= "You use an experimental or develop level of features, so please do NOT report any bugs, except if problem is confirmed moving option MAIN_FEATURES_LEVEL back to 0.<br>\n";
3876
+        }
3692 3877
         $out .= $langs->trans("InformationToHelpDiagnose") . ":<br>\n";
3693 3878
 
3694 3879
         $out .= "<b>" . $langs->trans("Date") . ":</b> " . dol_print_date(time(), 'dayhourlog') . "<br>\n";
3695 3880
         $out .= "<b>" . $langs->trans("Dolibarr") . ":</b> " . DOL_VERSION . "<br>\n";
3696
-        if (isset($conf->global->MAIN_FEATURES_LEVEL))
3697
-            $out .= "<b>" . $langs->trans("LevelOfFeature") . ":</b> " . $conf->global->MAIN_FEATURES_LEVEL . "<br>\n";
3881
+        if (isset($conf->global->MAIN_FEATURES_LEVEL)) {
3882
+                    $out .= "<b>" . $langs->trans("LevelOfFeature") . ":</b> " . $conf->global->MAIN_FEATURES_LEVEL . "<br>\n";
3883
+        }
3698 3884
         if (function_exists("phpversion")) {
3699 3885
             $out .= "<b>" . $langs->trans("PHP") . ":</b> " . phpversion() . "<br>\n";
3700 3886
         }
@@ -3737,18 +3923,20 @@  discard block
 block discarded – undo
3737 3923
         $langs->load("errors");
3738 3924
 
3739 3925
         // Merge all into $errors array
3740
-        if (is_array($error) && is_array($errors))
3741
-            $errors = array_merge($error, $errors);
3742
-        elseif (is_array($error))
3743
-            $errors = $error;
3744
-        elseif (is_array($errors))
3745
-            $errors = array_merge(array($error), $errors);
3746
-        else
3747
-            $errors = array_merge(array($error));
3926
+        if (is_array($error) && is_array($errors)) {
3927
+                    $errors = array_merge($error, $errors);
3928
+        } elseif (is_array($error)) {
3929
+                    $errors = $error;
3930
+        } elseif (is_array($errors)) {
3931
+                    $errors = array_merge(array($error), $errors);
3932
+        } else {
3933
+                    $errors = array_merge(array($error));
3934
+        }
3748 3935
 
3749 3936
         foreach ($errors as $msg) {
3750
-            if (empty($msg))
3751
-                continue;
3937
+            if (empty($msg)) {
3938
+                            continue;
3939
+            }
3752 3940
             if ($_SERVER['DOCUMENT_ROOT']) {  // Mode web
3753 3941
                 $out .= "<b>" . $langs->trans("Message") . ":</b> " . dol_escape_htmltag($msg) . "<br>\n";
3754 3942
             } else {                        // Mode CLI
@@ -3766,9 +3954,9 @@  discard block
 block discarded – undo
3766 3954
         $out .= "<br>\n";
3767 3955
     }
3768 3956
 
3769
-    if (empty($dolibarr_main_prod))
3770
-        print $out;
3771
-    else {
3957
+    if (empty($dolibarr_main_prod)) {
3958
+            print $out;
3959
+    } else {
3772 3960
         print $langs->trans("DolibarrHasDetectedError") . '. ';
3773 3961
         print $langs->trans("YouCanSetOptionDolibarrMainProdToZero");
3774 3962
         define("MAIN_CORE_ERROR", 1);
@@ -3791,16 +3979,18 @@  discard block
 block discarded – undo
3791 3979
 {
3792 3980
     global $langs, $conf;
3793 3981
 
3794
-    if (empty($email))
3795
-        $email = $conf->global->MAIN_INFO_SOCIETE_MAIL;
3982
+    if (empty($email)) {
3983
+            $email = $conf->global->MAIN_INFO_SOCIETE_MAIL;
3984
+    }
3796 3985
 
3797 3986
     $langs->load("errors");
3798 3987
     $now = dol_now();
3799 3988
 
3800 3989
     print '<br><div class="center login_main_message"><div class="' . $morecss . '">';
3801 3990
     print $langs->trans("ErrorContactEMail", $email, $prefixcode . dol_print_date($now, '%Y%m%d'));
3802
-    if ($errormessage)
3803
-        print '<br><br>' . $errormessage;
3991
+    if ($errormessage) {
3992
+            print '<br><br>' . $errormessage;
3993
+    }
3804 3994
     if (is_array($errormessages) && count($errormessages)) {
3805 3995
         foreach ($errormessages as $mesgtoshow) {
3806 3996
             print '<br><br>' . $mesgtoshow;
@@ -4043,12 +4233,15 @@  discard block
 block discarded – undo
4043 4233
     $savtotalnboflines = $totalnboflines;
4044 4234
     $totalnboflines = abs($totalnboflines);
4045 4235
 
4046
-    if ($picto == 'setup')
4047
-        $picto = 'title_setup.png';
4048
-    if (($conf->browser->name == 'ie') && $picto == 'title_generic.png')
4049
-        $picto = 'title.gif';
4050
-    if ($limit < 0)
4051
-        $limit = $conf->liste_limit;
4236
+    if ($picto == 'setup') {
4237
+            $picto = 'title_setup.png';
4238
+    }
4239
+    if (($conf->browser->name == 'ie') && $picto == 'title_generic.png') {
4240
+            $picto = 'title.gif';
4241
+    }
4242
+    if ($limit < 0) {
4243
+            $limit = $conf->liste_limit;
4244
+    }
4052 4245
     if ($savlimit != 0 && (($num > $limit) || ($num == -1) || ($limit == 0))) {
4053 4246
         $nextpage = 1;
4054 4247
     } else {
@@ -4062,11 +4255,13 @@  discard block
 block discarded – undo
4062 4255
     // Left
4063 4256
     //if ($picto && $titre) print '<td class="nobordernopadding hideonsmartphone" width="40" align="left" valign="middle">'.img_picto('', $picto, 'id="pictotitle"', $pictoisfullpath).'</td>';
4064 4257
     print '<td class="nobordernopadding valignmiddle">';
4065
-    if ($picto && $titre)
4066
-        print img_picto('', $picto, 'class="hideonsmartphone valignmiddle opacityhigh pictotitle widthpictotitle"', $pictoisfullpath);
4258
+    if ($picto && $titre) {
4259
+            print img_picto('', $picto, 'class="hideonsmartphone valignmiddle opacityhigh pictotitle widthpictotitle"', $pictoisfullpath);
4260
+    }
4067 4261
     print '<div class="titre inline-block">' . $titre;
4068
-    if (!empty($titre) && $savtotalnboflines >= 0 && (string) $savtotalnboflines != '')
4069
-        print ' (' . $totalnboflines . ')';
4262
+    if (!empty($titre) && $savtotalnboflines >= 0 && (string) $savtotalnboflines != '') {
4263
+            print ' (' . $totalnboflines . ')';
4264
+    }
4070 4265
     print '</div></td>';
4071 4266
 
4072 4267
     // Center
@@ -4076,10 +4271,12 @@  discard block
 block discarded – undo
4076 4271
 
4077 4272
     // Right
4078 4273
     print '<td class="nobordernopadding valignmiddle" align="right">';
4079
-    if ($sortfield)
4080
-        $options .= "&sortfield=" . urlencode($sortfield);
4081
-    if ($sortorder)
4082
-        $options .= "&sortorder=" . urlencode($sortorder);
4274
+    if ($sortfield) {
4275
+            $options .= "&sortfield=" . urlencode($sortfield);
4276
+    }
4277
+    if ($sortorder) {
4278
+            $options .= "&sortorder=" . urlencode($sortorder);
4279
+    }
4083 4280
     // Show navigation bar
4084 4281
     $pagelist = '';
4085 4282
     if ($savlimit != 0 && ($page > 0 || $num > $limit)) {
@@ -4087,10 +4284,11 @@  discard block
 block discarded – undo
4087 4284
             // Define nb of extra page links before and after selected page + ... + first or last
4088 4285
             $maxnbofpage = (empty($conf->dol_optimize_smallscreen) ? 4 : 1);
4089 4286
 
4090
-            if ($limit > 0)
4091
-                $nbpages = ceil($totalnboflines / $limit);
4092
-            else
4093
-                $nbpages = 1;
4287
+            if ($limit > 0) {
4288
+                            $nbpages = ceil($totalnboflines / $limit);
4289
+            } else {
4290
+                            $nbpages = 1;
4291
+            }
4094 4292
             $cpt = ($page - $maxnbofpage);
4095 4293
             if ($cpt < 0) {
4096 4294
                 $cpt = 0;
@@ -4098,10 +4296,11 @@  discard block
 block discarded – undo
4098 4296
 
4099 4297
             if ($cpt >= 1) {
4100 4298
                 $pagelist .= '<li' . (($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><a href="' . $file . '?page=0' . $options . '">1</a></li>';
4101
-                if ($cpt > 2)
4102
-                    $pagelist .= '<li' . (($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><span ' . (($conf->dol_use_jmobile != 4) ? 'class="inactive"' : '') . '>...</span></li>';
4103
-                else if ($cpt == 2)
4104
-                    $pagelist .= '<li' . (($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><a href="' . $file . '?page=1' . $options . '">2</a></li>';
4299
+                if ($cpt > 2) {
4300
+                                    $pagelist .= '<li' . (($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><span ' . (($conf->dol_use_jmobile != 4) ? 'class="inactive"' : '') . '>...</span></li>';
4301
+                } else if ($cpt == 2) {
4302
+                                    $pagelist .= '<li' . (($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><a href="' . $file . '?page=1' . $options . '">2</a></li>';
4303
+                }
4105 4304
             }
4106 4305
 
4107 4306
             do {
@@ -4114,14 +4313,14 @@  discard block
 block discarded – undo
4114 4313
             } while ($cpt < $nbpages && $cpt <= $page + $maxnbofpage);
4115 4314
 
4116 4315
             if ($cpt < $nbpages) {
4117
-                if ($cpt < $nbpages - 2)
4118
-                    $pagelist .= '<li' . (($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><span ' . (($conf->dol_use_jmobile != 4) ? 'class="inactive"' : '') . '>...</span></li>';
4119
-                else if ($cpt == $nbpages - 2)
4120
-                    $pagelist .= '<li' . (($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><a href="' . $file . '?page=' . ($nbpages - 2) . $options . '">' . ($nbpages - 1) . '</a></li>';
4316
+                if ($cpt < $nbpages - 2) {
4317
+                                    $pagelist .= '<li' . (($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><span ' . (($conf->dol_use_jmobile != 4) ? 'class="inactive"' : '') . '>...</span></li>';
4318
+                } else if ($cpt == $nbpages - 2) {
4319
+                                    $pagelist .= '<li' . (($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><a href="' . $file . '?page=' . ($nbpages - 2) . $options . '">' . ($nbpages - 1) . '</a></li>';
4320
+                }
4121 4321
                 $pagelist .= '<li' . (($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><a href="' . $file . '?page=' . ($nbpages - 1) . $options . '">' . $nbpages . '</a></li>';
4122 4322
             }
4123
-        }
4124
-        else {
4323
+        } else {
4125 4324
             $pagelist .= '<li' . (($conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><span ' . (($conf->dol_use_jmobile != 4) ? 'class="active"' : '') . '>' . ($page + 1) . "</li>";
4126 4325
         }
4127 4326
     }
@@ -4157,18 +4356,21 @@  discard block
 block discarded – undo
4157 4356
         $pagesizechoices = '10:10,15:15,20:20,30:30,40:40,50:50,100:100,250:250,500:500,1000:1000,5000:5000';
4158 4357
         //$pagesizechoices.=',0:'.$langs->trans("All");     // Not yet supported
4159 4358
         //$pagesizechoices.=',2:2';
4160
-        if (!empty($conf->global->MAIN_PAGESIZE_CHOICES))
4161
-            $pagesizechoices = $conf->global->MAIN_PAGESIZE_CHOICES;
4359
+        if (!empty($conf->global->MAIN_PAGESIZE_CHOICES)) {
4360
+                    $pagesizechoices = $conf->global->MAIN_PAGESIZE_CHOICES;
4361
+        }
4162 4362
 
4163 4363
         print '<li class="pagination">';
4164 4364
         print '<select class="flat selectlimit" name="limit" title="' . dol_escape_htmltag($langs->trans("MaxNbOfRecordPerPage")) . '">';
4165 4365
         $tmpchoice = explode(',', $pagesizechoices);
4166 4366
         $tmpkey = $limit . ':' . $limit;
4167
-        if (!in_array($tmpkey, $tmpchoice))
4168
-            $tmpchoice[] = $tmpkey;
4367
+        if (!in_array($tmpkey, $tmpchoice)) {
4368
+                    $tmpchoice[] = $tmpkey;
4369
+        }
4169 4370
         $tmpkey = $conf->liste_limit . ':' . $conf->liste_limit;
4170
-        if (!in_array($tmpkey, $tmpchoice))
4171
-            $tmpchoice[] = $tmpkey;
4371
+        if (!in_array($tmpkey, $tmpchoice)) {
4372
+                    $tmpchoice[] = $tmpkey;
4373
+        }
4172 4374
         asort($tmpchoice, SORT_NUMERIC);
4173 4375
         $found = false;
4174 4376
         foreach ($tmpchoice as $val) {
@@ -4244,14 +4446,15 @@  discard block
 block discarded – undo
4244 4446
     }
4245 4447
 
4246 4448
     // If rate is '9/9/9' we don't change it.  If rate is '9.000' we apply price()
4247
-    if (!preg_match('/\//', $rate))
4248
-        $ret = price($rate, 0, '', 0, 0) . ($addpercent ? '%' : '');
4249
-    else {
4449
+    if (!preg_match('/\//', $rate)) {
4450
+            $ret = price($rate, 0, '', 0, 0) . ($addpercent ? '%' : '');
4451
+    } else {
4250 4452
         // TODO Split on / and output with a price2num to have clean numbers without ton of 000.
4251 4453
         $ret = $rate . ($addpercent ? '%' : '');
4252 4454
     }
4253
-    if (($info_bits & 1) && $usestarfornpr >= 0)
4254
-        $ret .= ' *';
4455
+    if (($info_bits & 1) && $usestarfornpr >= 0) {
4456
+            $ret .= ' *';
4457
+    }
4255 4458
     $ret .= $morelabel;
4256 4459
     return $ret;
4257 4460
 }
@@ -4276,11 +4479,14 @@  discard block
 block discarded – undo
4276 4479
     global $langs, $conf;
4277 4480
 
4278 4481
     // Clean parameters
4279
-    if (empty($amount))
4280
-        $amount = 0; // To have a numeric value if amount not defined or = ''
4482
+    if (empty($amount)) {
4483
+            $amount = 0;
4484
+    }
4485
+    // To have a numeric value if amount not defined or = ''
4281 4486
     $amount = (is_numeric($amount) ? $amount : 0); // Check if amount is numeric, for example, an error occured when amount value = o (letter) instead 0 (number)
4282
-    if ($rounding < 0)
4283
-        $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
4487
+    if ($rounding < 0) {
4488
+            $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
4489
+    }
4284 4490
     $nbdecimal = $rounding;
4285 4491
 
4286 4492
     // Output separators by default (french)
@@ -4288,17 +4494,21 @@  discard block
 block discarded – undo
4288 4494
     $thousand = ' ';
4289 4495
 
4290 4496
     // If $outlangs not forced, we use use language
4291
-    if (!is_object($outlangs))
4292
-        $outlangs = $langs;
4293
-
4294
-    if ($outlangs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal")
4295
-        $dec = $outlangs->transnoentitiesnoconv("SeparatorDecimal");
4296
-    if ($outlangs->transnoentitiesnoconv("SeparatorThousand") != "SeparatorThousand")
4297
-        $thousand = $outlangs->transnoentitiesnoconv("SeparatorThousand");
4298
-    if ($thousand == 'None')
4299
-        $thousand = '';
4300
-    else if ($thousand == 'Space')
4301
-        $thousand = ' ';
4497
+    if (!is_object($outlangs)) {
4498
+            $outlangs = $langs;
4499
+    }
4500
+
4501
+    if ($outlangs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal") {
4502
+            $dec = $outlangs->transnoentitiesnoconv("SeparatorDecimal");
4503
+    }
4504
+    if ($outlangs->transnoentitiesnoconv("SeparatorThousand") != "SeparatorThousand") {
4505
+            $thousand = $outlangs->transnoentitiesnoconv("SeparatorThousand");
4506
+    }
4507
+    if ($thousand == 'None') {
4508
+            $thousand = '';
4509
+    } else if ($thousand == 'Space') {
4510
+            $thousand = ' ';
4511
+    }
4302 4512
     //print "outlangs=".$outlangs->defaultlang." amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'<br>";
4303 4513
     //print "amount=".$amount."-";
4304 4514
     $amount = str_replace(',', '.', $amount); // should be useless
@@ -4310,8 +4520,9 @@  discard block
 block discarded – undo
4310 4520
     $end = '';
4311 4521
 
4312 4522
     // We increase nbdecimal if there is more decimal than asked (to not loose information)
4313
-    if (dol_strlen($decpart) > $nbdecimal)
4314
-        $nbdecimal = dol_strlen($decpart);
4523
+    if (dol_strlen($decpart) > $nbdecimal) {
4524
+            $nbdecimal = dol_strlen($decpart);
4525
+    }
4315 4526
     // Si on depasse max
4316 4527
     if ($trunc && $nbdecimal > $conf->global->MAIN_MAX_DECIMALS_SHOWN) {
4317 4528
         $nbdecimal = $conf->global->MAIN_MAX_DECIMALS_SHOWN;
@@ -4322,8 +4533,9 @@  discard block
 block discarded – undo
4322 4533
     }
4323 4534
 
4324 4535
     // If force rounding
4325
-    if ($forcerounding >= 0)
4326
-        $nbdecimal = $forcerounding;
4536
+    if ($forcerounding >= 0) {
4537
+            $nbdecimal = $forcerounding;
4538
+    }
4327 4539
 
4328 4540
     // Format number
4329 4541
     $output = number_format($amount, $nbdecimal, $dec, $thousand);
@@ -4334,13 +4546,14 @@  discard block
 block discarded – undo
4334 4546
     // Add symbol of currency if requested
4335 4547
     $cursymbolbefore = $cursymbolafter = '';
4336 4548
     if ($currency_code) {
4337
-        if ($currency_code == 'auto')
4338
-            $currency_code = $conf->currency;
4549
+        if ($currency_code == 'auto') {
4550
+                    $currency_code = $conf->currency;
4551
+        }
4339 4552
 
4340 4553
         $listofcurrenciesbefore = array('USD', 'GBP', 'AUD', 'MXN', 'PEN', 'CNY');
4341
-        if (in_array($currency_code, $listofcurrenciesbefore))
4342
-            $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
4343
-        else {
4554
+        if (in_array($currency_code, $listofcurrenciesbefore)) {
4555
+                    $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
4556
+        } else {
4344 4557
             $tmpcur = $outlangs->getCurrencySymbol($currency_code);
4345 4558
             $cursymbolafter .= ($tmpcur == $currency_code ? ' ' . $tmpcur : $tmpcur);
4346 4559
         }
@@ -4374,14 +4587,17 @@  discard block
 block discarded – undo
4374 4587
     // Decimal delimiter for PHP and database SQL requests must be '.'
4375 4588
     $dec = ',';
4376 4589
     $thousand = ' ';
4377
-    if ($langs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal")
4378
-        $dec = $langs->transnoentitiesnoconv("SeparatorDecimal");
4379
-    if ($langs->transnoentitiesnoconv("SeparatorThousand") != "SeparatorThousand")
4380
-        $thousand = $langs->transnoentitiesnoconv("SeparatorThousand");
4381
-    if ($thousand == 'None')
4382
-        $thousand = '';
4383
-    elseif ($thousand == 'Space')
4384
-        $thousand = ' ';
4590
+    if ($langs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal") {
4591
+            $dec = $langs->transnoentitiesnoconv("SeparatorDecimal");
4592
+    }
4593
+    if ($langs->transnoentitiesnoconv("SeparatorThousand") != "SeparatorThousand") {
4594
+            $thousand = $langs->transnoentitiesnoconv("SeparatorThousand");
4595
+    }
4596
+    if ($thousand == 'None') {
4597
+            $thousand = '';
4598
+    } elseif ($thousand == 'Space') {
4599
+            $thousand = ' ';
4600
+    }
4385 4601
     //print "amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'<br>";
4386 4602
     // Convert value to universal number format (no thousand separator, '.' as decimal separator)
4387 4603
     if ($alreadysqlnb != 1) { // If not a PHP number or unknown, we change format
@@ -4397,8 +4613,10 @@  discard block
 block discarded – undo
4397 4613
         }
4398 4614
         //print "QQ".$amount.'<br>';
4399 4615
         // Now make replace (the main goal of function)
4400
-        if ($thousand != ',' && $thousand != '.')
4401
-            $amount = str_replace(',', '.', $amount); // To accept 2 notations for french users
4616
+        if ($thousand != ',' && $thousand != '.') {
4617
+                    $amount = str_replace(',', '.', $amount);
4618
+        }
4619
+        // To accept 2 notations for french users
4402 4620
         $amount = str_replace(' ', '', $amount);  // To avoid spaces
4403 4621
         $amount = str_replace($thousand, '', $amount); // Replace of thousand before replace of dec to avoid pb if thousand is .
4404 4622
         $amount = str_replace($dec, '.', $amount);
@@ -4407,19 +4625,23 @@  discard block
 block discarded – undo
4407 4625
     // Now, make a rounding if required
4408 4626
     if ($rounding) {
4409 4627
         $nbofdectoround = '';
4410
-        if ($rounding == 'MU')
4411
-            $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_UNIT;
4412
-        elseif ($rounding == 'MT')
4413
-            $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_TOT;
4414
-        elseif ($rounding == 'MS')
4415
-            $nbofdectoround = empty($conf->global->MAIN_MAX_DECIMALS_STOCK) ? 5 : $conf->global->MAIN_MAX_DECIMALS_STOCK;
4416
-        elseif (is_numeric($rounding))
4417
-            $nbofdectoround = $rounding;
4628
+        if ($rounding == 'MU') {
4629
+                    $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_UNIT;
4630
+        } elseif ($rounding == 'MT') {
4631
+                    $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_TOT;
4632
+        } elseif ($rounding == 'MS') {
4633
+                    $nbofdectoround = empty($conf->global->MAIN_MAX_DECIMALS_STOCK) ? 5 : $conf->global->MAIN_MAX_DECIMALS_STOCK;
4634
+        } elseif (is_numeric($rounding)) {
4635
+                    $nbofdectoround = $rounding;
4636
+        }
4418 4637
         //print "RR".$amount.' - '.$nbofdectoround.'<br>';
4419
-        if (dol_strlen($nbofdectoround))
4420
-            $amount = round($amount, $nbofdectoround); // $nbofdectoround can be 0.
4421
-        else
4422
-            return 'ErrorBadParameterProvidedToFunction';
4638
+        if (dol_strlen($nbofdectoround)) {
4639
+                    $amount = round($amount, $nbofdectoround);
4640
+        }
4641
+        // $nbofdectoround can be 0.
4642
+        else {
4643
+                    return 'ErrorBadParameterProvidedToFunction';
4644
+        }
4423 4645
         //print 'SS'.$amount.' - '.$nbofdec.' - '.$dec.' - '.$thousand.' - '.$nbofdectoround.'<br>';
4424 4646
         // Convert amount to format with dolibarr dec and thousand (this is because PHP convert a number
4425 4647
         // to format defined by LC_NUMERIC after a calculation and we want source format to be defined by Dolibarr setup.
@@ -4433,8 +4655,10 @@  discard block
 block discarded – undo
4433 4655
         //print "TT".$amount.'<br>';
4434 4656
         // Always make replace because each math function (like round) replace
4435 4657
         // with local values and we want a number that has a SQL string format x.y
4436
-        if ($thousand != ',' && $thousand != '.')
4437
-            $amount = str_replace(',', '.', $amount); // To accept 2 notations for french users
4658
+        if ($thousand != ',' && $thousand != '.') {
4659
+                    $amount = str_replace(',', '.', $amount);
4660
+        }
4661
+        // To accept 2 notations for french users
4438 4662
         $amount = str_replace(' ', '', $amount);  // To avoid spaces
4439 4663
         $amount = str_replace($thousand, '', $amount); // Replace of thousand before replace of dec to avoid pb if thousand is .
4440 4664
         $amount = str_replace($dec, '.', $amount);
@@ -4493,8 +4717,9 @@  discard block
 block discarded – undo
4493 4717
 {
4494 4718
     global $db, $conf, $mysoc;
4495 4719
 
4496
-    if (empty($thirdparty_seller) || !is_object($thirdparty_seller))
4497
-        $thirdparty_seller = $mysoc;
4720
+    if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) {
4721
+            $thirdparty_seller = $mysoc;
4722
+    }
4498 4723
 
4499 4724
     dol_syslog("get_localtax tva=" . $vatrate . " local=" . $local . " thirdparty_buyer id=" . (is_object($thirdparty_buyer) ? $thirdparty_buyer->id : '') . "/country_code=" . (is_object($thirdparty_buyer) ? $thirdparty_buyer->country_code : '') . " thirdparty_seller id=" . $thirdparty_seller->id . "/country_code=" . $thirdparty_seller->country_code . " thirdparty_seller localtax1_assuj=" . $thirdparty_seller->localtax1_assuj . "  thirdparty_seller localtax2_assuj=" . $thirdparty_seller->localtax2_assuj);
4500 4725
 
@@ -4512,37 +4737,43 @@  discard block
 block discarded – undo
4512 4737
     // Some test to guess with no need to make database access
4513 4738
     if ($mysoc->country_code == 'ES') { // For spain localtaxes 1 and 2, tax is qualified if buyer use local tax
4514 4739
         if ($local == 1) {
4515
-            if (!$mysoc->localtax1_assuj || (string) $vatratecleaned == "0")
4516
-                return 0;
4517
-            if ($thirdparty_seller->id == $mysoc->id) {
4518
-                if (!$thirdparty_buyer->localtax1_assuj)
4519
-                    return 0;
4740
+            if (!$mysoc->localtax1_assuj || (string) $vatratecleaned == "0") {
4741
+                            return 0;
4520 4742
             }
4521
-            else {
4522
-                if (!$thirdparty_seller->localtax1_assuj)
4523
-                    return 0;
4743
+            if ($thirdparty_seller->id == $mysoc->id) {
4744
+                if (!$thirdparty_buyer->localtax1_assuj) {
4745
+                                    return 0;
4746
+                }
4747
+            } else {
4748
+                if (!$thirdparty_seller->localtax1_assuj) {
4749
+                                    return 0;
4750
+                }
4524 4751
             }
4525 4752
         }
4526 4753
 
4527 4754
         if ($local == 2) {
4528 4755
             //if (! $mysoc->localtax2_assuj || (string) $vatratecleaned == "0") return 0;
4529
-            if (!$mysoc->localtax2_assuj)
4530
-                return 0;  // If main vat is 0, IRPF may be different than 0.
4756
+            if (!$mysoc->localtax2_assuj) {
4757
+                            return 0;
4758
+            }
4759
+            // If main vat is 0, IRPF may be different than 0.
4531 4760
             if ($thirdparty_seller->id == $mysoc->id) {
4532
-                if (!$thirdparty_buyer->localtax2_assuj)
4533
-                    return 0;
4761
+                if (!$thirdparty_buyer->localtax2_assuj) {
4762
+                                    return 0;
4763
+                }
4764
+            } else {
4765
+                if (!$thirdparty_seller->localtax2_assuj) {
4766
+                                    return 0;
4767
+                }
4534 4768
             }
4535
-            else {
4536
-                if (!$thirdparty_seller->localtax2_assuj)
4769
+        }
4770
+    } else {
4771
+        if ($local == 1 && !$thirdparty_seller->localtax1_assuj) {
4772
+                    return 0;
4773
+        }
4774
+        if ($local == 2 && !$thirdparty_seller->localtax2_assuj) {
4537 4775
                     return 0;
4538
-            }
4539 4776
         }
4540
-    }
4541
-    else {
4542
-        if ($local == 1 && !$thirdparty_seller->localtax1_assuj)
4543
-            return 0;
4544
-        if ($local == 2 && !$thirdparty_seller->localtax2_assuj)
4545
-            return 0;
4546 4777
     }
4547 4778
 
4548 4779
     // For some country MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY is forced to on.
@@ -4584,19 +4815,23 @@  discard block
 block discarded – undo
4584 4815
     $sql .= " FROM " . MAIN_DB_PREFIX . "c_tva as t, " . MAIN_DB_PREFIX . "c_country as c";
4585 4816
     $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '" . $thirdparty_seller->country_code . "'";
4586 4817
     $sql .= " AND t.taux = " . ((float) $vatratecleaned) . " AND t.active = 1";
4587
-    if ($vatratecode)
4588
-        $sql .= " AND t.code ='" . $vatratecode . "'";  // If we have the code, we use it in priority
4589
-    else
4590
-        $sql .= " AND t.recuperableonly ='" . $vatnpr . "'";
4818
+    if ($vatratecode) {
4819
+            $sql .= " AND t.code ='" . $vatratecode . "'";
4820
+    }
4821
+    // If we have the code, we use it in priority
4822
+    else {
4823
+            $sql .= " AND t.recuperableonly ='" . $vatnpr . "'";
4824
+    }
4591 4825
     dol_syslog("get_localtax", LOG_DEBUG);
4592 4826
     $resql = $db->query($sql);
4593 4827
 
4594 4828
     if ($resql) {
4595 4829
         $obj = $db->fetch_object($resql);
4596
-        if ($local == 1)
4597
-            return $obj->localtax1;
4598
-        elseif ($local == 2)
4599
-            return $obj->localtax2;
4830
+        if ($local == 1) {
4831
+                    return $obj->localtax1;
4832
+        } elseif ($local == 2) {
4833
+                    return $obj->localtax2;
4834
+        }
4600 4835
     }
4601 4836
 
4602 4837
     return 0;
@@ -4642,10 +4877,11 @@  discard block
 block discarded – undo
4642 4877
     $resql = $db->query($sql);
4643 4878
     if ($resql) {
4644 4879
         $obj = $db->fetch_object($resql);
4645
-        if ($local == 1)
4646
-            return $obj->localtax1;
4647
-        elseif ($local == 2)
4648
-            return $obj->localtax2;
4880
+        if ($local == 1) {
4881
+                    return $obj->localtax1;
4882
+        } elseif ($local == 2) {
4883
+                    return $obj->localtax2;
4884
+        }
4649 4885
     }
4650 4886
 
4651 4887
     return 0;
@@ -4671,9 +4907,9 @@  discard block
 block discarded – undo
4671 4907
     // Search local taxes
4672 4908
     $sql = "SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy";
4673 4909
     $sql .= " FROM " . MAIN_DB_PREFIX . "c_tva as t";
4674
-    if ($firstparamisid)
4675
-        $sql .= " WHERE t.rowid = " . (int) $vatrate;
4676
-    else {
4910
+    if ($firstparamisid) {
4911
+            $sql .= " WHERE t.rowid = " . (int) $vatrate;
4912
+    } else {
4677 4913
         $vatratecleaned = $vatrate;
4678 4914
         $vatratecode = '';
4679 4915
         if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {      // If vat is "xx (yy)"
@@ -4686,19 +4922,22 @@  discard block
 block discarded – undo
4686 4922
           else $sql.= " WHERE t.fk_pays = c.rowid AND c.code = '".$seller->country_code."'"; */
4687 4923
         $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '" . $seller->country_code . "'";
4688 4924
         $sql .= " AND t.taux = " . ((float) $vatratecleaned) . " AND t.active = 1";
4689
-        if ($vatratecode)
4690
-            $sql .= " AND t.code = '" . $vatratecode . "'";
4925
+        if ($vatratecode) {
4926
+                    $sql .= " AND t.code = '" . $vatratecode . "'";
4927
+        }
4691 4928
     }
4692 4929
 
4693 4930
     $resql = $db->query($sql);
4694 4931
     if ($resql) {
4695 4932
         $obj = $db->fetch_object($resql);
4696
-        if ($obj)
4697
-            return array('rowid' => $obj->rowid, 'code' => $obj->code, 'rate' => $obj->rate, 'npr' => $obj->npr, 'accountancy_code_sell' => $obj->accountancy_code_sell, 'accountancy_code_buy' => $obj->accountancy_code_buy);
4698
-        else
4699
-            return array();
4700
-    } else
4701
-        dol_print_error($db);
4933
+        if ($obj) {
4934
+                    return array('rowid' => $obj->rowid, 'code' => $obj->code, 'rate' => $obj->rate, 'npr' => $obj->npr, 'accountancy_code_sell' => $obj->accountancy_code_sell, 'accountancy_code_buy' => $obj->accountancy_code_buy);
4935
+        } else {
4936
+                    return array();
4937
+        }
4938
+    } else {
4939
+            dol_print_error($db);
4940
+    }
4702 4941
 
4703 4942
     return array();
4704 4943
 }
@@ -4728,9 +4967,9 @@  discard block
 block discarded – undo
4728 4967
     // Search local taxes
4729 4968
     $sql = "SELECT t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.accountancy_code_sell, t.accountancy_code_buy";
4730 4969
     $sql .= " FROM " . MAIN_DB_PREFIX . "c_tva as t";
4731
-    if ($firstparamisid)
4732
-        $sql .= " WHERE t.rowid = " . (int) $vatrate;
4733
-    else {
4970
+    if ($firstparamisid) {
4971
+            $sql .= " WHERE t.rowid = " . (int) $vatrate;
4972
+    } else {
4734 4973
         $vatratecleaned = $vatrate;
4735 4974
         $vatratecode = '';
4736 4975
         if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {      // If vat is "x.x (yy)"
@@ -4739,13 +4978,17 @@  discard block
 block discarded – undo
4739 4978
         }
4740 4979
 
4741 4980
         $sql .= ", " . MAIN_DB_PREFIX . "c_country as c";
4742
-        if ($mysoc->country_code == 'ES')
4743
-            $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '" . $buyer->country_code . "'";    // local tax in spain use the buyer country ??
4744
-        else
4745
-            $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '" . $seller->country_code . "'";
4981
+        if ($mysoc->country_code == 'ES') {
4982
+                    $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '" . $buyer->country_code . "'";
4983
+        }
4984
+        // local tax in spain use the buyer country ??
4985
+        else {
4986
+                    $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '" . $seller->country_code . "'";
4987
+        }
4746 4988
         $sql .= " AND t.taux = " . ((float) $vatratecleaned) . " AND t.active = 1";
4747
-        if ($vatratecode)
4748
-            $sql .= " AND t.code = '" . $vatratecode . "'";
4989
+        if ($vatratecode) {
4990
+                    $sql .= " AND t.code = '" . $vatratecode . "'";
4991
+        }
4749 4992
     }
4750 4993
 
4751 4994
     $resql = $db->query($sql);
@@ -4791,17 +5034,17 @@  discard block
 block discarded – undo
4791 5034
             if ($idprodfournprice > 0) {     // We want vat for product for a "supplier" object
4792 5035
                 $product->get_buyprice($idprodfournprice, 0, 0, 0);
4793 5036
                 $ret = $product->vatrate_supplier;
4794
-                if ($product->default_vat_code)
4795
-                    $ret .= ' (' . $product->default_vat_code . ')';
4796
-            }
4797
-            else {
5037
+                if ($product->default_vat_code) {
5038
+                                    $ret .= ' (' . $product->default_vat_code . ')';
5039
+                }
5040
+            } else {
4798 5041
                 $ret = $product->tva_tx;    // Default vat of product we defined
4799
-                if ($product->default_vat_code)
4800
-                    $ret .= ' (' . $product->default_vat_code . ')';
5042
+                if ($product->default_vat_code) {
5043
+                                    $ret .= ' (' . $product->default_vat_code . ')';
5044
+                }
4801 5045
             }
4802 5046
             $found = 1;
4803
-        }
4804
-        else {
5047
+        } else {
4805 5048
             // TODO Read default product vat according to countrycode and product. Vat for couple countrycode/product is a feature not implemeted yet.
4806 5049
             // May be usefull/required if hidden option SERVICE_ARE_ECOMMERCE_200238EC is on
4807 5050
         }
@@ -4821,14 +5064,18 @@  discard block
 block discarded – undo
4821 5064
                 $obj = $db->fetch_object($resql);
4822 5065
                 if ($obj) {
4823 5066
                     $ret = $obj->vat_rate;
4824
-                    if ($obj->default_vat_code)
4825
-                        $ret .= ' (' . $obj->default_vat_code . ')';
5067
+                    if ($obj->default_vat_code) {
5068
+                                            $ret .= ' (' . $obj->default_vat_code . ')';
5069
+                    }
4826 5070
                 }
4827 5071
                 $db->free($sql);
4828
-            } else
4829
-                dol_print_error($db);
4830
-        } else
4831
-            $ret = $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;    // Forced value if autodetect fails
5072
+            } else {
5073
+                            dol_print_error($db);
5074
+            }
5075
+        } else {
5076
+                    $ret = $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;
5077
+        }
5078
+        // Forced value if autodetect fails
4832 5079
     }
4833 5080
 
4834 5081
     dol_syslog("get_product_vat_for_country: ret=" . $ret);
@@ -4883,13 +5130,15 @@  discard block
 block discarded – undo
4883 5130
         if ($resql) {
4884 5131
             $obj = $db->fetch_object($resql);
4885 5132
             if ($obj) {
4886
-                if ($local == 1)
4887
-                    $ret = $obj->localtax1;
4888
-                elseif ($local == 2)
4889
-                    $ret = $obj->localtax2;
5133
+                if ($local == 1) {
5134
+                                    $ret = $obj->localtax1;
5135
+                } elseif ($local == 2) {
5136
+                                    $ret = $obj->localtax2;
5137
+                }
4890 5138
             }
4891
-        } else
4892
-            dol_print_error($db);
5139
+        } else {
5140
+                    dol_print_error($db);
5141
+        }
4893 5142
     }
4894 5143
 
4895 5144
     dol_syslog("get_product_localtax_for_country: ret=" . $ret);
@@ -4992,15 +5241,16 @@  discard block
 block discarded – undo
4992 5241
     global $db;
4993 5242
 
4994 5243
     if ($idprodfournprice > 0) {
4995
-        if (!class_exists('ProductFournisseur'))
4996
-            require_once DOL_BASE_PATH . '/fourn/class/fournisseur.product.class.php';
5244
+        if (!class_exists('ProductFournisseur')) {
5245
+                    require_once DOL_BASE_PATH . '/fourn/class/fournisseur.product.class.php';
5246
+        }
4997 5247
         $prodprice = new ProductFournisseur($db);
4998 5248
         $prodprice->fetch_product_fournisseur_price($idprodfournprice);
4999 5249
         return $prodprice->fourn_tva_npr;
5000
-    }
5001
-    elseif ($idprod > 0) {
5002
-        if (!class_exists('Product'))
5003
-            require_once DOL_BASE_PATH . 'product/class/product.class.php';
5250
+    } elseif ($idprod > 0) {
5251
+        if (!class_exists('Product')) {
5252
+                    require_once DOL_BASE_PATH . 'product/class/product.class.php';
5253
+        }
5004 5254
         $prod = new Product($db);
5005 5255
         $prod->fetch($idprod);
5006 5256
         return $prod->tva_npr;
@@ -5026,30 +5276,35 @@  discard block
 block discarded – undo
5026 5276
 {
5027 5277
     global $mysoc;
5028 5278
 
5029
-    if (!is_object($thirdparty_seller))
5030
-        return -1;
5031
-    if (!is_object($thirdparty_buyer))
5032
-        return -1;
5279
+    if (!is_object($thirdparty_seller)) {
5280
+            return -1;
5281
+    }
5282
+    if (!is_object($thirdparty_buyer)) {
5283
+            return -1;
5284
+    }
5033 5285
 
5034 5286
     if ($local == 1) { // Localtax 1
5035 5287
         if ($mysoc->country_code == 'ES') {
5036
-            if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj)
5037
-                return 0;
5038
-        }
5039
-        else {
5288
+            if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) {
5289
+                            return 0;
5290
+            }
5291
+        } else {
5040 5292
             // Si vendeur non assujeti a Localtax1, localtax1 par default=0
5041
-            if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj)
5042
-                return 0;
5043
-            if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj == 'localtax1off')
5044
-                return 0;
5293
+            if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) {
5294
+                            return 0;
5295
+            }
5296
+            if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj == 'localtax1off') {
5297
+                            return 0;
5298
+            }
5045 5299
         }
5046
-    }
5047
-    elseif ($local == 2) { //I Localtax 2
5300
+    } elseif ($local == 2) { //I Localtax 2
5048 5301
         // Si vendeur non assujeti a Localtax2, localtax2 par default=0
5049
-        if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj)
5050
-            return 0;
5051
-        if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj == 'localtax2off')
5052
-            return 0;
5302
+        if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) {
5303
+                    return 0;
5304
+        }
5305
+        if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj == 'localtax2off') {
5306
+                    return 0;
5307
+        }
5053 5308
     }
5054 5309
 
5055 5310
     if ($thirdparty_seller->country_code == $thirdparty_buyer->country_code) {
@@ -5074,31 +5329,38 @@  discard block
 block discarded – undo
5074 5329
     $classname = '';
5075 5330
     if ($yesno == 1 || strtolower($yesno) == 'yes' || strtolower($yesno) == 'true') {  // A mettre avant test sur no a cause du == 0
5076 5331
         $result = $langs->trans('yes');
5077
-        if ($case == 1 || $case == 3)
5078
-            $result = $langs->trans("Yes");
5079
-        if ($case == 2)
5080
-            $result = '<input type="checkbox" value="1" checked disabled>';
5081
-        if ($case == 3)
5082
-            $result = '<input type="checkbox" value="1" checked disabled> ' . $result;
5332
+        if ($case == 1 || $case == 3) {
5333
+                    $result = $langs->trans("Yes");
5334
+        }
5335
+        if ($case == 2) {
5336
+                    $result = '<input type="checkbox" value="1" checked disabled>';
5337
+        }
5338
+        if ($case == 3) {
5339
+                    $result = '<input type="checkbox" value="1" checked disabled> ' . $result;
5340
+        }
5083 5341
 
5084 5342
         $classname = 'ok';
5085
-    }
5086
-    elseif ($yesno == 0 || strtolower($yesno) == 'no' || strtolower($yesno) == 'false') {
5343
+    } elseif ($yesno == 0 || strtolower($yesno) == 'no' || strtolower($yesno) == 'false') {
5087 5344
         $result = $langs->trans("no");
5088
-        if ($case == 1 || $case == 3)
5089
-            $result = $langs->trans("No");
5090
-        if ($case == 2)
5091
-            $result = '<input type="checkbox" value="0" disabled>';
5092
-        if ($case == 3)
5093
-            $result = '<input type="checkbox" value="0" disabled> ' . $result;
5094
-
5095
-        if ($color == 2)
5096
-            $classname = 'ok';
5097
-        else
5098
-            $classname = 'error';
5099
-    }
5100
-    if ($color)
5101
-        return '<font class="' . $classname . '">' . $result . '</font>';
5345
+        if ($case == 1 || $case == 3) {
5346
+                    $result = $langs->trans("No");
5347
+        }
5348
+        if ($case == 2) {
5349
+                    $result = '<input type="checkbox" value="0" disabled>';
5350
+        }
5351
+        if ($case == 3) {
5352
+                    $result = '<input type="checkbox" value="0" disabled> ' . $result;
5353
+        }
5354
+
5355
+        if ($color == 2) {
5356
+                    $classname = 'ok';
5357
+        } else {
5358
+                    $classname = 'error';
5359
+        }
5360
+    }
5361
+    if ($color) {
5362
+            return '<font class="' . $classname . '">' . $result . '</font>';
5363
+    }
5102 5364
     return $result;
5103 5365
 }
5104 5366
 
@@ -5124,23 +5386,27 @@  discard block
 block discarded – undo
5124 5386
     $path = '';
5125 5387
 
5126 5388
     $arrayforoldpath = array('cheque', 'user', 'category', 'holiday', 'supplier_invoice', 'invoice_supplier', 'mailing', 'supplier_payment');
5127
-    if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
5128
-        $arrayforoldpath[] = 'product';
5389
+    if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
5390
+            $arrayforoldpath[] = 'product';
5391
+    }
5129 5392
     if (!empty($level) && in_array($modulepart, $arrayforoldpath)) {
5130 5393
         // This part should be removed once all code is using "get_exdir" to forge path, with all parameters provided.
5131
-        if (empty($alpha))
5132
-            $num = preg_replace('/([^0-9])/i', '', $num);
5133
-        else
5134
-            $num = preg_replace('/^.*\-/i', '', $num);
5394
+        if (empty($alpha)) {
5395
+                    $num = preg_replace('/([^0-9])/i', '', $num);
5396
+        } else {
5397
+                    $num = preg_replace('/^.*\-/i', '', $num);
5398
+        }
5135 5399
         $num = substr("000" . $num, -$level);
5136
-        if ($level == 1)
5137
-            $path = substr($num, 0, 1);
5138
-        if ($level == 2)
5139
-            $path = substr($num, 1, 1) . '/' . substr($num, 0, 1);
5140
-        if ($level == 3)
5141
-            $path = substr($num, 2, 1) . '/' . substr($num, 1, 1) . '/' . substr($num, 0, 1);
5142
-    }
5143
-    else {
5400
+        if ($level == 1) {
5401
+                    $path = substr($num, 0, 1);
5402
+        }
5403
+        if ($level == 2) {
5404
+                    $path = substr($num, 1, 1) . '/' . substr($num, 0, 1);
5405
+        }
5406
+        if ($level == 3) {
5407
+                    $path = substr($num, 2, 1) . '/' . substr($num, 1, 1) . '/' . substr($num, 0, 1);
5408
+        }
5409
+    } else {
5144 5410
         // TODO
5145 5411
         // We will enhance here a common way of forging path for document storage
5146 5412
         // Here, object->id, object->ref and modulepart are required.
@@ -5151,8 +5417,9 @@  discard block
 block discarded – undo
5151 5417
         }
5152 5418
     }
5153 5419
 
5154
-    if (empty($withoutslash) && !empty($path))
5155
-        $path .= '/';
5420
+    if (empty($withoutslash) && !empty($path)) {
5421
+            $path .= '/';
5422
+    }
5156 5423
 
5157 5424
     return $path;
5158 5425
 }
@@ -5172,8 +5439,9 @@  discard block
 block discarded – undo
5172 5439
     dol_syslog("functions.lib::dol_mkdir: dir=" . $dir, LOG_INFO);
5173 5440
 
5174 5441
     $dir_osencoded = dol_osencode($dir);
5175
-    if (@is_dir($dir_osencoded))
5176
-        return 0;
5442
+    if (@is_dir($dir_osencoded)) {
5443
+            return 0;
5444
+    }
5177 5445
 
5178 5446
     $nberr = 0;
5179 5447
     $nbcreated = 0;
@@ -5188,12 +5456,15 @@  discard block
 block discarded – undo
5188 5456
     $cdir = explode("/", $dir);
5189 5457
     $num = count($cdir);
5190 5458
     for ($i = 0; $i < $num; $i++) {
5191
-        if ($i > 0)
5192
-            $ccdir .= '/' . $cdir[$i];
5193
-        else
5194
-            $ccdir .= $cdir[$i];
5195
-        if (preg_match("/^.:$/", $ccdir, $regs))
5196
-            continue; // Si chemin Windows incomplet, on poursuit par rep suivant
5459
+        if ($i > 0) {
5460
+                    $ccdir .= '/' . $cdir[$i];
5461
+        } else {
5462
+                    $ccdir .= $cdir[$i];
5463
+        }
5464
+        if (preg_match("/^.:$/", $ccdir, $regs)) {
5465
+                    continue;
5466
+        }
5467
+        // Si chemin Windows incomplet, on poursuit par rep suivant
5197 5468
 
5198 5469
 
5199 5470
 
@@ -5277,8 +5548,9 @@  discard block
 block discarded – undo
5277 5548
  */
5278 5549
 function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto = 'UTF-8', $strip_tags = 0)
5279 5550
 {
5280
-    if ($removelinefeed == 2)
5281
-        $stringtoclean = preg_replace('/<br[^>]*>\n+/ims', '<br>', $stringtoclean);
5551
+    if ($removelinefeed == 2) {
5552
+            $stringtoclean = preg_replace('/<br[^>]*>\n+/ims', '<br>', $stringtoclean);
5553
+    }
5282 5554
     $temp = preg_replace('/<br[^>]*>/i', "\n", $stringtoclean);
5283 5555
 
5284 5556
     if ($strip_tags) {
@@ -5295,8 +5567,9 @@  discard block
 block discarded – undo
5295 5567
     $temp = dol_html_entity_decode($temp, ENT_COMPAT, $pagecodeto);
5296 5568
 
5297 5569
     // Supprime aussi les retours
5298
-    if ($removelinefeed == 1)
5299
-        $temp = str_replace(array("\r\n", "\r", "\n"), " ", $temp);
5570
+    if ($removelinefeed == 1) {
5571
+            $temp = str_replace(array("\r\n", "\r", "\n"), " ", $temp);
5572
+    }
5300 5573
 
5301 5574
     // et les espaces doubles
5302 5575
     while (strpos($temp, "  ")) {
@@ -5382,18 +5655,21 @@  discard block
 block discarded – undo
5382 5655
         if ($charset == 'UTF-8') {
5383 5656
             $pattern = '/(<br[^>]*>)/Uu';
5384 5657
         } // /U is to have UNGREEDY regex to limit to one html tag. /u is for UTF8 support
5385
-        else
5386
-            $pattern = '/(<br[^>]*>)/U';       // /U is to have UNGREEDY regex to limit to one html tag.
5658
+        else {
5659
+                    $pattern = '/(<br[^>]*>)/U';
5660
+        }
5661
+        // /U is to have UNGREEDY regex to limit to one html tag.
5387 5662
         $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
5388 5663
 
5389 5664
         $firstline = '';
5390 5665
         $i = 0;
5391 5666
         $nba = count($a); // 2x nb of lines in $a because $a contains also a line for each new line separator
5392 5667
         while (($i < $nba) && ($i < ($nboflines * 2))) {
5393
-            if ($i % 2 == 0)
5394
-                $firstline .= $a[$i];
5395
-            elseif (($i < (($nboflines * 2) - 1)) && ($i < ($nba - 1)))
5396
-                $firstline .= ($ishtml ? "<br>\n" : "\n");
5668
+            if ($i % 2 == 0) {
5669
+                            $firstline .= $a[$i];
5670
+            } elseif (($i < (($nboflines * 2) - 1)) && ($i < ($nba - 1))) {
5671
+                            $firstline .= ($ishtml ? "<br>\n" : "\n");
5672
+            }
5397 5673
             $i++;
5398 5674
         }
5399 5675
         unset($a);
@@ -5442,15 +5718,18 @@  discard block
 block discarded – undo
5442 5718
     $newstring = $stringtoencode;
5443 5719
     if (dol_textishtml($stringtoencode)) { // Check if text is already HTML or not
5444 5720
         $newstring = preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>/i', '<br>', $newstring); // Replace "<br type="_moz" />" by "<br>". It's same and avoid pb with FPDF.
5445
-        if ($removelasteolbr)
5446
-            $newstring = preg_replace('/<br>$/i', '', $newstring); // Remove last <br> (remove only last one)
5721
+        if ($removelasteolbr) {
5722
+                    $newstring = preg_replace('/<br>$/i', '', $newstring);
5723
+        }
5724
+        // Remove last <br> (remove only last one)
5447 5725
         $newstring = strtr($newstring, array('&' => '__and__', '<' => '__lt__', '>' => '__gt__', '"' => '__dquot__'));
5448 5726
         $newstring = dol_htmlentities($newstring, ENT_COMPAT, $pagecodefrom); // Make entity encoding
5449 5727
         $newstring = strtr($newstring, array('__and__' => '&', '__lt__' => '<', '__gt__' => '>', '__dquot__' => '"'));
5450
-    }
5451
-    else {
5452
-        if ($removelasteolbr)
5453
-            $newstring = preg_replace('/(\r\n|\r|\n)$/i', '', $newstring); // Remove last \n (may remove several)
5728
+    } else {
5729
+        if ($removelasteolbr) {
5730
+                    $newstring = preg_replace('/(\r\n|\r|\n)$/i', '', $newstring);
5731
+        }
5732
+        // Remove last \n (may remove several)
5454 5733
         $newstring = dol_nl2br(dol_htmlentities($newstring, ENT_COMPAT, $pagecodefrom), $nl2brmode);
5455 5734
     }
5456 5735
     // Other substitutions that htmlentities does not do
@@ -5552,8 +5831,9 @@  discard block
 block discarded – undo
5552 5831
  */
5553 5832
 function dol_nboflines($s, $maxchar = 0)
5554 5833
 {
5555
-    if ($s == '')
5556
-        return 0;
5834
+    if ($s == '') {
5835
+            return 0;
5836
+    }
5557 5837
     $arraystring = explode("\n", $s);
5558 5838
     $nb = count($arraystring);
5559 5839
 
@@ -5572,15 +5852,18 @@  discard block
 block discarded – undo
5572 5852
 function dol_nboflines_bis($text, $maxlinesize = 0, $charset = 'UTF-8')
5573 5853
 {
5574 5854
     $repTable = array("\t" => " ", "\n" => "<br>", "\r" => " ", "\0" => " ", "\x0B" => " ");
5575
-    if (dol_textishtml($text))
5576
-        $repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
5855
+    if (dol_textishtml($text)) {
5856
+            $repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
5857
+    }
5577 5858
 
5578 5859
     $text = strtr($text, $repTable);
5579 5860
     if ($charset == 'UTF-8') {
5580 5861
         $pattern = '/(<br[^>]*>)/Uu';
5581 5862
     } // /U is to have UNGREEDY regex to limit to one html tag. /u is for UTF8 support
5582
-    else
5583
-        $pattern = '/(<br[^>]*>)/U';       // /U is to have UNGREEDY regex to limit to one html tag.
5863
+    else {
5864
+            $pattern = '/(<br[^>]*>)/U';
5865
+    }
5866
+    // /U is to have UNGREEDY regex to limit to one html tag.
5584 5867
     $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
5585 5868
 
5586 5869
     $nblines = (int) floor((count($a) + 1) / 2);
@@ -5627,39 +5910,47 @@  discard block
 block discarded – undo
5627 5910
 function dol_textishtml($msg, $option = 0)
5628 5911
 {
5629 5912
     if ($option == 1) {
5630
-        if (preg_match('/<html/i', $msg))
5631
-            return true;
5632
-        elseif (preg_match('/<body/i', $msg))
5633
-            return true;
5634
-        elseif (preg_match('/<br/i', $msg))
5635
-            return true;
5913
+        if (preg_match('/<html/i', $msg)) {
5914
+                    return true;
5915
+        } elseif (preg_match('/<body/i', $msg)) {
5916
+                    return true;
5917
+        } elseif (preg_match('/<br/i', $msg)) {
5918
+                    return true;
5919
+        }
5636 5920
         return false;
5637
-    }
5638
-    else {
5639
-        if (preg_match('/<html/i', $msg))
5640
-            return true;
5641
-        elseif (preg_match('/<body/i', $msg))
5642
-            return true;
5643
-        elseif (preg_match('/<(b|em|i|u)>/i', $msg))
5644
-            return true;
5645
-        elseif (preg_match('/<br\/>/i', $msg))
5646
-            return true;
5647
-        elseif (preg_match('/<(br|div|font|li|p|span|strong|table)>/i', $msg))
5648
-            return true;
5649
-        elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*>/i', $msg))
5650
-            return true;
5651
-        elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*\/>/i', $msg))
5652
-            return true;
5653
-        elseif (preg_match('/<img\s+[^<>]*src[^<>]*>/i', $msg))
5654
-            return true; // must accept <img src="http://example.com/aaa.png" />
5655
-        elseif (preg_match('/<a\s+[^<>]*href[^<>]*>/i', $msg))
5656
-            return true; // must accept <a href="http://example.com/aaa.png" />
5657
-        elseif (preg_match('/<h[0-9]>/i', $msg))
5658
-            return true;
5659
-        elseif (preg_match('/&[A-Z0-9]{1,6};/i', $msg))
5660
-            return true;    // Html entities names (http://www.w3schools.com/tags/ref_entities.asp)
5661
-        elseif (preg_match('/&#[0-9]{2,3};/i', $msg))
5662
-            return true;    // Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp)
5921
+    } else {
5922
+        if (preg_match('/<html/i', $msg)) {
5923
+                    return true;
5924
+        } elseif (preg_match('/<body/i', $msg)) {
5925
+                    return true;
5926
+        } elseif (preg_match('/<(b|em|i|u)>/i', $msg)) {
5927
+                    return true;
5928
+        } elseif (preg_match('/<br\/>/i', $msg)) {
5929
+                    return true;
5930
+        } elseif (preg_match('/<(br|div|font|li|p|span|strong|table)>/i', $msg)) {
5931
+                    return true;
5932
+        } elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*>/i', $msg)) {
5933
+                    return true;
5934
+        } elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*\/>/i', $msg)) {
5935
+                    return true;
5936
+        } elseif (preg_match('/<img\s+[^<>]*src[^<>]*>/i', $msg)) {
5937
+                    return true;
5938
+        }
5939
+        // must accept <img src="http://example.com/aaa.png" />
5940
+        elseif (preg_match('/<a\s+[^<>]*href[^<>]*>/i', $msg)) {
5941
+                    return true;
5942
+        }
5943
+        // must accept <a href="http://example.com/aaa.png" />
5944
+        elseif (preg_match('/<h[0-9]>/i', $msg)) {
5945
+                    return true;
5946
+        } elseif (preg_match('/&[A-Z0-9]{1,6};/i', $msg)) {
5947
+                    return true;
5948
+        }
5949
+        // Html entities names (http://www.w3schools.com/tags/ref_entities.asp)
5950
+        elseif (preg_match('/&#[0-9]{2,3};/i', $msg)) {
5951
+                    return true;
5952
+        }
5953
+        // Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp)
5663 5954
 
5664 5955
         return false;
5665 5956
     }
@@ -5811,12 +6102,14 @@  discard block
 block discarded – undo
5811 6102
             $birthday = dol_print_date($object->birth, 'day');
5812 6103
 
5813 6104
             $substitutionarray['__MEMBER_ID__'] = $object->id;
5814
-            if (method_exists($object, 'getCivilityLabel'))
5815
-                $substitutionarray['__MEMBER_CIVILITY__'] = $object->getCivilityLabel();
6105
+            if (method_exists($object, 'getCivilityLabel')) {
6106
+                            $substitutionarray['__MEMBER_CIVILITY__'] = $object->getCivilityLabel();
6107
+            }
5816 6108
             $substitutionarray['__MEMBER_FIRSTNAME__'] = $msgishtml ? dol_htmlentitiesbr($object->firstname) : $object->firstname;
5817 6109
             $substitutionarray['__MEMBER_LASTNAME__'] = $msgishtml ? dol_htmlentitiesbr($object->lastname) : $object->lastname;
5818
-            if (method_exists($object, 'getFullName'))
5819
-                $substitutionarray['__MEMBER_FULLNAME__'] = $msgishtml ? dol_htmlentitiesbr($object->getFullName($outputlangs)) : $object->getFullName($outputlangs);
6110
+            if (method_exists($object, 'getFullName')) {
6111
+                            $substitutionarray['__MEMBER_FULLNAME__'] = $msgishtml ? dol_htmlentitiesbr($object->getFullName($outputlangs)) : $object->getFullName($outputlangs);
6112
+            }
5820 6113
             $substitutionarray['__MEMBER_COMPANY__'] = $msgishtml ? dol_htmlentitiesbr($object->societe) : $object->societe;
5821 6114
             $substitutionarray['__MEMBER_ADDRESS__'] = $msgishtml ? dol_htmlentitiesbr($object->address) : $object->address;
5822 6115
             $substitutionarray['__MEMBER_ZIP__'] = $msgishtml ? dol_htmlentitiesbr($object->zip) : $object->zip;
@@ -5864,10 +6157,12 @@  discard block
 block discarded – undo
5864 6157
                 $dateplannedstart = '';
5865 6158
                 $datenextexpiration = '';
5866 6159
                 foreach ($object->lines as $line) {
5867
-                    if ($line->date_ouverture_prevue > $dateplannedstart)
5868
-                        $dateplannedstart = $line->date_ouverture_prevue;
5869
-                    if ($line->statut == 4 && $line->date_fin_prevue && (!$datenextexpiration || $line->date_fin_prevue < $datenextexpiration))
5870
-                        $datenextexpiration = $line->date_fin_prevue;
6160
+                    if ($line->date_ouverture_prevue > $dateplannedstart) {
6161
+                                            $dateplannedstart = $line->date_ouverture_prevue;
6162
+                    }
6163
+                    if ($line->statut == 4 && $line->date_fin_prevue && (!$datenextexpiration || $line->date_fin_prevue < $datenextexpiration)) {
6164
+                                            $datenextexpiration = $line->date_fin_prevue;
6165
+                    }
5871 6166
                 }
5872 6167
                 $substitutionarray['__CONTRACT_HIGHEST_PLANNED_START_DATE__'] = dol_print_date($dateplannedstart, 'dayrfc');
5873 6168
                 $substitutionarray['__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] = dol_print_date($dateplannedstart, 'standard');
@@ -5877,8 +6172,9 @@  discard block
 block discarded – undo
5877 6172
 
5878 6173
             // Create dynamic tags for __EXTRAFIELD_FIELD__
5879 6174
             if ($object->table_element && $object->id > 0) {
5880
-                if (!is_object($extrafields))
5881
-                    $extrafields = new ExtraFields($db);
6175
+                if (!is_object($extrafields)) {
6176
+                                    $extrafields = new ExtraFields($db);
6177
+                }
5882 6178
                 $extrafields->fetch_name_optionals_label($object->table_element, true);
5883 6179
 
5884 6180
                 if ($object->fetch_optionals() > 0) {
@@ -5899,12 +6195,15 @@  discard block
 block discarded – undo
5899 6195
                 require_once DOL_BASE_PATH . '/core/lib/payments.lib.php';
5900 6196
                 $outputlangs->loadLangs(array('paypal', 'other'));
5901 6197
                 $typeforonlinepayment = 'free';
5902
-                if (is_object($object) && $object->element == 'commande')
5903
-                    $typeforonlinepayment = 'order';
5904
-                if (is_object($object) && $object->element == 'facture')
5905
-                    $typeforonlinepayment = 'invoice';
5906
-                if (is_object($object) && $object->element == 'member')
5907
-                    $typeforonlinepayment = 'member';
6198
+                if (is_object($object) && $object->element == 'commande') {
6199
+                                    $typeforonlinepayment = 'order';
6200
+                }
6201
+                if (is_object($object) && $object->element == 'facture') {
6202
+                                    $typeforonlinepayment = 'invoice';
6203
+                }
6204
+                if (is_object($object) && $object->element == 'member') {
6205
+                                    $typeforonlinepayment = 'member';
6206
+                }
5908 6207
                 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $substitutionarray['__REF__']);
5909 6208
                 $paymenturl = $url;
5910 6209
             }
@@ -5914,16 +6213,19 @@  discard block
 block discarded – undo
5914 6213
 
5915 6214
             if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD) && is_object($object) && $object->element == 'propal') {
5916 6215
                 $substitutionarray['__DIRECTDOWNLOAD_URL_PROPOSAL__'] = $object->getLastMainDocLink($object->element);
5917
-            } else
5918
-                $substitutionarray['__DIRECTDOWNLOAD_URL_PROPOSAL__'] = '';
6216
+            } else {
6217
+                            $substitutionarray['__DIRECTDOWNLOAD_URL_PROPOSAL__'] = '';
6218
+            }
5919 6219
             if (!empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD) && is_object($object) && $object->element == 'commande') {
5920 6220
                 $substitutionarray['__DIRECTDOWNLOAD_URL_ORDER__'] = $object->getLastMainDocLink($object->element);
5921
-            } else
5922
-                $substitutionarray['__DIRECTDOWNLOAD_URL_ORDER__'] = '';
6221
+            } else {
6222
+                            $substitutionarray['__DIRECTDOWNLOAD_URL_ORDER__'] = '';
6223
+            }
5923 6224
             if (!empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD) && is_object($object) && $object->element == 'facture') {
5924 6225
                 $substitutionarray['__DIRECTDOWNLOAD_URL_INVOICE__'] = $object->getLastMainDocLink($object->element);
5925
-            } else
5926
-                $substitutionarray['__DIRECTDOWNLOAD_URL_INVOICE__'] = '';
6226
+            } else {
6227
+                            $substitutionarray['__DIRECTDOWNLOAD_URL_INVOICE__'] = '';
6228
+            }
5927 6229
         }
5928 6230
     }
5929 6231
     if (empty($exclude) || !in_array('objectamount', $exclude)) {
@@ -5933,18 +6235,22 @@  discard block
 block discarded – undo
5933 6235
         $substitutionarray['__AMOUNT__'] = is_object($object) ? $object->total_ttc : '';
5934 6236
         $substitutionarray['__AMOUNT_EXCL_TAX__'] = is_object($object) ? $object->total_ht : '';
5935 6237
         $substitutionarray['__AMOUNT_VAT__'] = is_object($object) ? ($object->total_vat ? $object->total_vat : $object->total_tva) : '';
5936
-        if ($onlykey != 2 || $mysoc->useLocalTax(1))
5937
-            $substitutionarray['__AMOUNT_TAX2__'] = is_object($object) ? $object->total_localtax1 : '';
5938
-        if ($onlykey != 2 || $mysoc->useLocalTax(2))
5939
-            $substitutionarray['__AMOUNT_TAX3__'] = is_object($object) ? $object->total_localtax2 : '';
6238
+        if ($onlykey != 2 || $mysoc->useLocalTax(1)) {
6239
+                    $substitutionarray['__AMOUNT_TAX2__'] = is_object($object) ? $object->total_localtax1 : '';
6240
+        }
6241
+        if ($onlykey != 2 || $mysoc->useLocalTax(2)) {
6242
+                    $substitutionarray['__AMOUNT_TAX3__'] = is_object($object) ? $object->total_localtax2 : '';
6243
+        }
5940 6244
 
5941 6245
         $substitutionarray['__AMOUNT_FORMATED__'] = is_object($object) ? price($object->total_ttc, 0, $outputlangs, 0, 0, -1, $conf->currency) : '';
5942 6246
         $substitutionarray['__AMOUNT_EXCL_TAX_FORMATED__'] = is_object($object) ? price($object->total_ht, 0, $outputlangs, 0, 0, -1, $conf->currency) : '';
5943 6247
         $substitutionarray['__AMOUNT_VAT_FORMATED__'] = is_object($object) ? ($object->total_vat ? price($object->total_vat, 0, $outputlangs, 0, 0, -1, $conf->currency) : price($object->total_tva, 0, $outputlangs, 0, 0, -1, $conf->currency)) : '';
5944
-        if ($onlykey != 2 || $mysoc->useLocalTax(1))
5945
-            $substitutionarray['__AMOUNT_TAX2_FORMATED__'] = is_object($object) ? price($object->total_localtax1, 0, $outputlangs, 0, 0, -1, $conf->currency) : '';
5946
-        if ($onlykey != 2 || $mysoc->useLocalTax(2))
5947
-            $substitutionarray['__AMOUNT_TAX3_FORMATED__'] = is_object($object) ? price($object->total_localtax2, 0, $outputlangs, 0, 0, -1, $conf->currency) : '';
6248
+        if ($onlykey != 2 || $mysoc->useLocalTax(1)) {
6249
+                    $substitutionarray['__AMOUNT_TAX2_FORMATED__'] = is_object($object) ? price($object->total_localtax1, 0, $outputlangs, 0, 0, -1, $conf->currency) : '';
6250
+        }
6251
+        if ($onlykey != 2 || $mysoc->useLocalTax(2)) {
6252
+                    $substitutionarray['__AMOUNT_TAX3_FORMATED__'] = is_object($object) ? price($object->total_localtax2, 0, $outputlangs, 0, 0, -1, $conf->currency) : '';
6253
+        }
5948 6254
 
5949 6255
         // TODO Add keys for foreign multicurrency
5950 6256
         // For backward compatibility
@@ -6014,23 +6320,27 @@  discard block
 block discarded – undo
6014 6320
 {
6015 6321
     global $conf, $langs;
6016 6322
 
6017
-    if (!is_array($substitutionarray))
6018
-        return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
6323
+    if (!is_array($substitutionarray)) {
6324
+            return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
6325
+    }
6019 6326
 
6020
-    if (empty($outputlangs))
6021
-        $outputlangs = $langs;
6327
+    if (empty($outputlangs)) {
6328
+            $outputlangs = $langs;
6329
+    }
6022 6330
 
6023 6331
     // Make substitution for language keys
6024 6332
     if (is_object($outputlangs)) {
6025 6333
         while (preg_match('/__\(([^\)]+)\)__/', $text, $reg)) {
6026 6334
             $msgishtml = 0;
6027
-            if (dol_textishtml($text, 1))
6028
-                $msgishtml = 1;
6335
+            if (dol_textishtml($text, 1)) {
6336
+                            $msgishtml = 1;
6337
+            }
6029 6338
 
6030 6339
             // If key is __(TranslationKey|langfile)__, then force load of langfile.lang
6031 6340
             $tmp = explode('|', $reg[1]);
6032
-            if (!empty($tmp[1]))
6033
-                $outputlangs->load($tmp[1]);
6341
+            if (!empty($tmp[1])) {
6342
+                            $outputlangs->load($tmp[1]);
6343
+            }
6034 6344
 
6035 6345
             $text = preg_replace('/__\(' . preg_quote($reg[1], '/') . '\)__/', $msgishtml ? dol_htmlentitiesbr($outputlangs->transnoentitiesnoconv($reg[1])) : $outputlangs->transnoentitiesnoconv($reg[1]), $text);
6036 6346
         }
@@ -6040,23 +6350,29 @@  discard block
 block discarded – undo
6040 6350
     // it is also converted.
6041 6351
     while (preg_match('/__\[([^\]]+)\]__/', $text, $reg)) {
6042 6352
         $msgishtml = 0;
6043
-        if (dol_textishtml($text, 1))
6044
-            $msgishtml = 1;
6353
+        if (dol_textishtml($text, 1)) {
6354
+                    $msgishtml = 1;
6355
+        }
6045 6356
 
6046 6357
         $keyfound = $reg[1];
6047
-        if (preg_match('/(_pass|password|secret|_key|key$)/i', $keyfound))
6048
-            $newval = '*****forbidden*****';
6049
-        else
6050
-            $newval = empty($conf->global->$keyfound) ? '' : $conf->global->$keyfound;
6358
+        if (preg_match('/(_pass|password|secret|_key|key$)/i', $keyfound)) {
6359
+                    $newval = '*****forbidden*****';
6360
+        } else {
6361
+                    $newval = empty($conf->global->$keyfound) ? '' : $conf->global->$keyfound;
6362
+        }
6051 6363
         $text = preg_replace('/__\[' . preg_quote($keyfound, '/') . '\]__/', $msgishtml ? dol_htmlentitiesbr($newval) : $newval, $text);
6052 6364
     }
6053 6365
 
6054 6366
     // Make substitition for array $substitutionarray
6055 6367
     foreach ($substitutionarray as $key => $value) {
6056
-        if ($key == '__SIGNATURE__' && (!empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)))
6057
-            $value = '';  // Protection
6058
-        if ($key == '__USER_SIGNATURE__' && (!empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)))
6059
-            $value = ''; // Protection
6368
+        if ($key == '__SIGNATURE__' && (!empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) {
6369
+                    $value = '';
6370
+        }
6371
+        // Protection
6372
+        if ($key == '__USER_SIGNATURE__' && (!empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) {
6373
+                    $value = '';
6374
+        }
6375
+        // Protection
6060 6376
 
6061 6377
         $text = str_replace("$key", "$value", $text); // We must keep the " to work when value is 123.5 for example
6062 6378
     }
@@ -6102,8 +6418,9 @@  discard block
 block discarded – undo
6102 6418
         $dir = dol_buildpath($reldir, 0);
6103 6419
 
6104 6420
         // Check if directory exists
6105
-        if (!dol_is_dir($dir))
6106
-            continue;
6421
+        if (!dol_is_dir($dir)) {
6422
+                    continue;
6423
+        }
6107 6424
 
6108 6425
         $substitfiles = dol_dir_list($dir, 'files', 0, 'functions_');
6109 6426
         foreach ($substitfiles as $substitfile) {
@@ -6115,8 +6432,9 @@  discard block
 block discarded – undo
6115 6432
                 require_once $dir . $substitfile['name'];
6116 6433
                 // Call the user's function, and only if it is defined
6117 6434
                 $function_name = $module . "_" . $callfunc;
6118
-                if (function_exists($function_name))
6119
-                    $function_name($substitutionarray, $outputlangs, $object, $parameters);
6435
+                if (function_exists($function_name)) {
6436
+                                    $function_name($substitutionarray, $outputlangs, $object, $parameters);
6437
+                }
6120 6438
             }
6121 6439
         }
6122 6440
     }
@@ -6152,8 +6470,9 @@  discard block
 block discarded – undo
6152 6470
 
6153 6471
     $out = '';
6154 6472
 
6155
-    if (!is_object($outputlangs))
6156
-        $outputlangs = $langs;
6473
+    if (!is_object($outputlangs)) {
6474
+            $outputlangs = $langs;
6475
+    }
6157 6476
 
6158 6477
     if ($date_start && $date_end) {
6159 6478
         $out .= ($withparenthesis ? ' (' : '') . $outputlangs->transnoentitiesnoconv('DateFromTo', dol_print_date($date_start, $format, false, $outputlangs), dol_print_date($date_end, $format, false, $outputlangs)) . ($withparenthesis ? ')' : '');
@@ -6182,20 +6501,22 @@  discard block
 block discarded – undo
6182 6501
 
6183 6502
     $ret = '';
6184 6503
     // If order not defined, we use the setup
6185
-    if ($nameorder < 0)
6186
-        $nameorder = (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION) ? 1 : 0);
6504
+    if ($nameorder < 0) {
6505
+            $nameorder = (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION) ? 1 : 0);
6506
+    }
6187 6507
     if ($nameorder && ((string) $nameorder != '2')) {
6188 6508
         $ret .= $firstname;
6189
-        if ($firstname && $lastname)
6190
-            $ret .= ' ';
6509
+        if ($firstname && $lastname) {
6510
+                    $ret .= ' ';
6511
+        }
6191 6512
         $ret .= $lastname;
6192
-    }
6193
-    else if ($nameorder == 2) {
6513
+    } else if ($nameorder == 2) {
6194 6514
         $ret .= $firstname;
6195 6515
     } else {
6196 6516
         $ret .= $lastname;
6197
-        if ($firstname && $lastname)
6198
-            $ret .= ' ';
6517
+        if ($firstname && $lastname) {
6518
+                    $ret .= ' ';
6519
+        }
6199 6520
         $ret .= $firstname;
6200 6521
     }
6201 6522
     return $ret;
@@ -6215,13 +6536,14 @@  discard block
 block discarded – undo
6215 6536
 {
6216 6537
     //dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);		This is not deprecated, it is used by setEventMessages function
6217 6538
     if (!is_array($mesgs)) {  // If mesgs is a string
6218
-        if ($mesgs)
6219
-            $_SESSION['dol_events'][$style][] = $mesgs;
6220
-    }
6221
-    else {      // If mesgs is an array
6539
+        if ($mesgs) {
6540
+                    $_SESSION['dol_events'][$style][] = $mesgs;
6541
+        }
6542
+    } else {      // If mesgs is an array
6222 6543
         foreach ($mesgs as $mesg) {
6223
-            if ($mesg)
6224
-                $_SESSION['dol_events'][$style][] = $mesg;
6544
+            if ($mesg) {
6545
+                            $_SESSION['dol_events'][$style][] = $mesg;
6546
+            }
6225 6547
         }
6226 6548
     }
6227 6549
 }
@@ -6241,13 +6563,16 @@  discard block
 block discarded – undo
6241 6563
     if (empty($mesg) && empty($mesgs)) {
6242 6564
         dol_syslog("Try to add a message in stack with empty message", LOG_WARNING);
6243 6565
     } else {
6244
-        if (!in_array((string) $style, array('mesgs', 'warnings', 'errors')))
6245
-            dol_print_error('', 'Bad parameter style=' . $style . ' for setEventMessages');
6246
-        if (empty($mesgs))
6247
-            setEventMessage($mesg, $style);
6248
-        else {
6249
-            if (!empty($mesg) && !in_array($mesg, $mesgs))
6250
-                setEventMessage($mesg, $style); // Add message string if not already into array
6566
+        if (!in_array((string) $style, array('mesgs', 'warnings', 'errors'))) {
6567
+                    dol_print_error('', 'Bad parameter style=' . $style . ' for setEventMessages');
6568
+        }
6569
+        if (empty($mesgs)) {
6570
+                    setEventMessage($mesg, $style);
6571
+        } else {
6572
+            if (!empty($mesg) && !in_array($mesg, $mesgs)) {
6573
+                            setEventMessage($mesg, $style);
6574
+            }
6575
+            // Add message string if not already into array
6251 6576
             setEventMessage($mesgs, $style);
6252 6577
         }
6253 6578
     }
@@ -6266,22 +6591,25 @@  discard block
 block discarded – undo
6266 6591
 {
6267 6592
     // Show mesgs
6268 6593
     if (isset($_SESSION['dol_events']['mesgs'])) {
6269
-        if (empty($disabledoutputofmessages))
6270
-            dol_htmloutput_mesg('', $_SESSION['dol_events']['mesgs']);
6594
+        if (empty($disabledoutputofmessages)) {
6595
+                    dol_htmloutput_mesg('', $_SESSION['dol_events']['mesgs']);
6596
+        }
6271 6597
         unset($_SESSION['dol_events']['mesgs']);
6272 6598
     }
6273 6599
 
6274 6600
     // Show errors
6275 6601
     if (isset($_SESSION['dol_events']['errors'])) {
6276
-        if (empty($disabledoutputofmessages))
6277
-            dol_htmloutput_mesg('', $_SESSION['dol_events']['errors'], 'error');
6602
+        if (empty($disabledoutputofmessages)) {
6603
+                    dol_htmloutput_mesg('', $_SESSION['dol_events']['errors'], 'error');
6604
+        }
6278 6605
         unset($_SESSION['dol_events']['errors']);
6279 6606
     }
6280 6607
 
6281 6608
     // Show warnings
6282 6609
     if (isset($_SESSION['dol_events']['warnings'])) {
6283
-        if (empty($disabledoutputofmessages))
6284
-            dol_htmloutput_mesg('', $_SESSION['dol_events']['warnings'], 'warning');
6610
+        if (empty($disabledoutputofmessages)) {
6611
+                    dol_htmloutput_mesg('', $_SESSION['dol_events']['warnings'], 'warning');
6612
+        }
6285 6613
         unset($_SESSION['dol_events']['warnings']);
6286 6614
     }
6287 6615
 }
@@ -6322,8 +6650,9 @@  discard block
 block discarded – undo
6322 6650
             foreach ($mesgarray as $message) {
6323 6651
                 $ret++;
6324 6652
                 $out .= $langs->trans($message);
6325
-                if ($ret < count($mesgarray))
6326
-                    $out .= "<br>\n";
6653
+                if ($ret < count($mesgarray)) {
6654
+                                    $out .= "<br>\n";
6655
+                }
6327 6656
             }
6328 6657
         }
6329 6658
         if ($mesgstring) {
@@ -6389,8 +6718,9 @@  discard block
 block discarded – undo
6389 6718
  */
6390 6719
 function dol_htmloutput_mesg($mesgstring = '', $mesgarray = array(), $style = 'ok', $keepembedded = 0)
6391 6720
 {
6392
-    if (empty($mesgstring) && (!is_array($mesgarray) || count($mesgarray) == 0))
6393
-        return;
6721
+    if (empty($mesgstring) && (!is_array($mesgarray) || count($mesgarray) == 0)) {
6722
+            return;
6723
+    }
6394 6724
 
6395 6725
     $iserror = 0;
6396 6726
     $iswarning = 0;
@@ -6405,14 +6735,17 @@  discard block
 block discarded – undo
6405 6735
                 break;
6406 6736
             }
6407 6737
         }
6408
-    } else if ($mesgstring && preg_match('/class="error"/i', $mesgstring))
6409
-        $iserror++;
6410
-    else if ($mesgstring && preg_match('/class="warning"/i', $mesgstring))
6411
-        $iswarning++;
6412
-    if ($style == 'error')
6413
-        $iserror++;
6414
-    if ($style == 'warning')
6415
-        $iswarning++;
6738
+    } else if ($mesgstring && preg_match('/class="error"/i', $mesgstring)) {
6739
+            $iserror++;
6740
+    } else if ($mesgstring && preg_match('/class="warning"/i', $mesgstring)) {
6741
+            $iswarning++;
6742
+    }
6743
+    if ($style == 'error') {
6744
+            $iserror++;
6745
+    }
6746
+    if ($style == 'warning') {
6747
+            $iswarning++;
6748
+    }
6416 6749
 
6417 6750
     if ($iserror || $iswarning) {
6418 6751
         // Remove div from texts
@@ -6431,9 +6764,10 @@  discard block
 block discarded – undo
6431 6764
             $mesgarray = $newmesgarray;
6432 6765
         }
6433 6766
         print get_htmloutput_mesg($mesgstring, $mesgarray, ($iserror ? 'error' : 'warning'), $keepembedded);
6434
-    } else
6435
-        print get_htmloutput_mesg($mesgstring, $mesgarray, 'ok', $keepembedded);
6436
-}
6767
+    } else {
6768
+            print get_htmloutput_mesg($mesgstring, $mesgarray, 'ok', $keepembedded);
6769
+    }
6770
+    }
6437 6771
 
6438 6772
 /**
6439 6773
  *  Print formated error messages to output (Used to show messages on html output).
@@ -6473,15 +6807,17 @@  discard block
 block discarded – undo
6473 6807
         $sizearray = count($array);
6474 6808
         if ($sizearray > 0) {
6475 6809
             $temp = array();
6476
-            foreach (array_keys($array) as $key)
6477
-                $temp[$key] = $array[$key][$index];
6810
+            foreach (array_keys($array) as $key) {
6811
+                            $temp[$key] = $array[$key][$index];
6812
+            }
6478 6813
 
6479
-            if (!$natsort)
6480
-                ($order == 'asc') ? asort($temp) : arsort($temp);
6481
-            else {
6814
+            if (!$natsort) {
6815
+                            ($order == 'asc') ? asort($temp) : arsort($temp);
6816
+            } else {
6482 6817
                 ($case_sensitive) ? natsort($temp) : natcasesort($temp);
6483
-                if ($order != 'asc')
6484
-                    $temp = array_reverse($temp, true);
6818
+                if ($order != 'asc') {
6819
+                                    $temp = array_reverse($temp, true);
6820
+                }
6485 6821
             }
6486 6822
 
6487 6823
             $sorted = array();
@@ -6507,23 +6843,38 @@  discard block
 block discarded – undo
6507 6843
     // We must use here a binary strlen function (so not dol_strlen)
6508 6844
     $strLength = dol_strlen($str);
6509 6845
     for ($i = 0; $i < $strLength; $i++) {
6510
-        if (ord($str[$i]) < 0x80)
6511
-            continue; // 0bbbbbbb
6512
-        elseif ((ord($str[$i]) & 0xE0) == 0xC0)
6513
-            $n = 1; // 110bbbbb
6514
-        elseif ((ord($str[$i]) & 0xF0) == 0xE0)
6515
-            $n = 2; // 1110bbbb
6516
-        elseif ((ord($str[$i]) & 0xF8) == 0xF0)
6517
-            $n = 3; // 11110bbb
6518
-        elseif ((ord($str[$i]) & 0xFC) == 0xF8)
6519
-            $n = 4; // 111110bb
6520
-        elseif ((ord($str[$i]) & 0xFE) == 0xFC)
6521
-            $n = 5; // 1111110b
6522
-        else
6523
-            return false; // Does not match any model
6846
+        if (ord($str[$i]) < 0x80) {
6847
+                    continue;
6848
+        }
6849
+        // 0bbbbbbb
6850
+        elseif ((ord($str[$i]) & 0xE0) == 0xC0) {
6851
+                    $n = 1;
6852
+        }
6853
+        // 110bbbbb
6854
+        elseif ((ord($str[$i]) & 0xF0) == 0xE0) {
6855
+                    $n = 2;
6856
+        }
6857
+        // 1110bbbb
6858
+        elseif ((ord($str[$i]) & 0xF8) == 0xF0) {
6859
+                    $n = 3;
6860
+        }
6861
+        // 11110bbb
6862
+        elseif ((ord($str[$i]) & 0xFC) == 0xF8) {
6863
+                    $n = 4;
6864
+        }
6865
+        // 111110bb
6866
+        elseif ((ord($str[$i]) & 0xFE) == 0xFC) {
6867
+                    $n = 5;
6868
+        }
6869
+        // 1111110b
6870
+        else {
6871
+                    return false;
6872
+        }
6873
+        // Does not match any model
6524 6874
         for ($j = 0; $j < $n; $j++) { // n bytes matching 10bbbbbb follow ?
6525
-            if (( ++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80))
6526
-                return false;
6875
+            if (( ++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80)) {
6876
+                            return false;
6877
+            }
6527 6878
         }
6528 6879
     }
6529 6880
     return true;
@@ -6541,15 +6892,21 @@  discard block
 block discarded – undo
6541 6892
     global $conf;
6542 6893
 
6543 6894
     $tmp = ini_get("unicode.filesystem_encoding");      // Disponible avec PHP 6.0
6544
-    if (empty($tmp) && !empty($_SERVER["WINDIR"]))
6545
-        $tmp = 'iso-8859-1'; // By default for windows
6546
-    if (empty($tmp))
6547
-        $tmp = 'utf-8';          // By default for other
6548
-    if (!empty($conf->global->MAIN_FILESYSTEM_ENCODING))
6549
-        $tmp = $conf->global->MAIN_FILESYSTEM_ENCODING;
6550
-
6551
-    if ($tmp == 'iso-8859-1')
6552
-        return utf8_decode($str);
6895
+    if (empty($tmp) && !empty($_SERVER["WINDIR"])) {
6896
+            $tmp = 'iso-8859-1';
6897
+    }
6898
+    // By default for windows
6899
+    if (empty($tmp)) {
6900
+            $tmp = 'utf-8';
6901
+    }
6902
+    // By default for other
6903
+    if (!empty($conf->global->MAIN_FILESYSTEM_ENCODING)) {
6904
+            $tmp = $conf->global->MAIN_FILESYSTEM_ENCODING;
6905
+    }
6906
+
6907
+    if ($tmp == 'iso-8859-1') {
6908
+            return utf8_decode($str);
6909
+    }
6553 6910
     return $str;
6554 6911
 }
6555 6912
 
@@ -6571,8 +6928,9 @@  discard block
 block discarded – undo
6571 6928
     global $cache_codes;
6572 6929
 
6573 6930
     // If key empty
6574
-    if ($key == '')
6575
-        return '';
6931
+    if ($key == '') {
6932
+            return '';
6933
+    }
6576 6934
 
6577 6935
     // Check in cache
6578 6936
     if (isset($cache_codes[$tablename][$key][$fieldid])) { // Can be defined to 0 or ''
@@ -6584,20 +6942,21 @@  discard block
 block discarded – undo
6584 6942
     $sql = "SELECT " . $fieldid . " as valuetoget";
6585 6943
     $sql .= " FROM " . MAIN_DB_PREFIX . $tablename;
6586 6944
     $sql .= " WHERE " . $fieldkey . " = '" . $db->escape($key) . "'";
6587
-    if (!empty($entityfilter))
6588
-        $sql .= " AND entity IN (" . getEntity($tablename) . ")";
6945
+    if (!empty($entityfilter)) {
6946
+            $sql .= " AND entity IN (" . getEntity($tablename) . ")";
6947
+    }
6589 6948
 
6590 6949
     $resql = $db->query($sql);
6591 6950
     if ($resql) {
6592 6951
         $obj = $db->fetch_object($resql);
6593
-        if ($obj)
6594
-            $cache_codes[$tablename][$key][$fieldid] = $obj->valuetoget;
6595
-        else
6596
-            $cache_codes[$tablename][$key][$fieldid] = '';
6952
+        if ($obj) {
6953
+                    $cache_codes[$tablename][$key][$fieldid] = $obj->valuetoget;
6954
+        } else {
6955
+                    $cache_codes[$tablename][$key][$fieldid] = '';
6956
+        }
6597 6957
         $db->free($resql);
6598 6958
         return $cache_codes[$tablename][$key][$fieldid];
6599
-    }
6600
-    else {
6959
+    } else {
6601 6960
         return -1;
6602 6961
     }
6603 6962
 }
@@ -6644,16 +7003,17 @@  discard block
 block discarded – undo
6644 7003
     global $soc;       // For backward compatibility
6645 7004
     //print $s."<br>\n";
6646 7005
     if ($returnvalue) {
6647
-        if ($hideerrors)
6648
-            return @eval('return ' . $s . ';');
6649
-        else
6650
-            return eval('return ' . $s . ';');
6651
-    }
6652
-    else {
6653
-        if ($hideerrors)
6654
-            @eval($s);
6655
-        else
6656
-            eval($s);
7006
+        if ($hideerrors) {
7007
+                    return @eval('return ' . $s . ';');
7008
+        } else {
7009
+                    return eval('return ' . $s . ';');
7010
+        }
7011
+    } else {
7012
+        if ($hideerrors) {
7013
+                    @eval($s);
7014
+        } else {
7015
+                    eval($s);
7016
+        }
6657 7017
     }
6658 7018
 }
6659 7019
 
@@ -6679,8 +7039,9 @@  discard block
 block discarded – undo
6679 7039
 {
6680 7040
     global $langs;
6681 7041
 
6682
-    if (empty($codelang))
6683
-        return '';
7042
+    if (empty($codelang)) {
7043
+            return '';
7044
+    }
6684 7045
 
6685 7046
     if ($codelang == 'auto') {
6686 7047
         return '<span class="fa fa-globe"></span>';
@@ -6694,9 +7055,9 @@  discard block
 block discarded – undo
6694 7055
         'sv_SV' => 'se'
6695 7056
     );
6696 7057
 
6697
-    if (isset($langtocountryflag[$codelang]))
6698
-        $flagImage = $langtocountryflag[$codelang];
6699
-    else {
7058
+    if (isset($langtocountryflag[$codelang])) {
7059
+            $flagImage = $langtocountryflag[$codelang];
7060
+    } else {
6700 7061
         $tmparray = explode('_', $codelang);
6701 7062
         $flagImage = empty($tmparray[1]) ? $tmparray[0] : $tmparray[1];
6702 7063
     }
@@ -6714,15 +7075,20 @@  discard block
 block discarded – undo
6714 7075
 {
6715 7076
     global $mysoc;
6716 7077
 
6717
-    if (strtoupper($countrycode) == 'MQ')
6718
-        return 'fr_CA';
6719
-    if (strtoupper($countrycode) == 'SE')
6720
-        return 'sv_SE'; // se_SE is Sami/Sweden, and we want in priority sv_SE for SE country
7078
+    if (strtoupper($countrycode) == 'MQ') {
7079
+            return 'fr_CA';
7080
+    }
7081
+    if (strtoupper($countrycode) == 'SE') {
7082
+            return 'sv_SE';
7083
+    }
7084
+    // se_SE is Sami/Sweden, and we want in priority sv_SE for SE country
6721 7085
     if (strtoupper($countrycode) == 'CH') {
6722
-        if ($mysoc->country_code == 'FR')
6723
-            return 'fr_CH';
6724
-        if ($mysoc->country_code == 'DE')
6725
-            return 'de_CH';
7086
+        if ($mysoc->country_code == 'FR') {
7087
+                    return 'fr_CH';
7088
+        }
7089
+        if ($mysoc->country_code == 'DE') {
7090
+                    return 'de_CH';
7091
+        }
6726 7092
     }
6727 7093
 
6728 7094
     // Locale list taken from:
@@ -6900,8 +7266,9 @@  discard block
 block discarded – undo
6900 7266
     );
6901 7267
 
6902 7268
     $buildprimarykeytotest = strtolower($countrycode) . '-' . strtoupper($countrycode);
6903
-    if (in_array($buildprimarykeytotest, $locales))
6904
-        return strtolower($countrycode) . '_' . strtoupper($countrycode);
7269
+    if (in_array($buildprimarykeytotest, $locales)) {
7270
+            return strtolower($countrycode) . '_' . strtoupper($countrycode);
7271
+    }
6905 7272
 
6906 7273
     foreach ($locales as $locale) {
6907 7274
         $locale_language = locale_get_primary_language($locale);
@@ -6955,18 +7322,21 @@  discard block
 block discarded – undo
6955 7322
 
6956 7323
             if ($mode == 'add' && !preg_match('/^\-/', $values[1])) {
6957 7324
                 if (count($values) == 6) {       // new declaration with permissions:  $value='objecttype:+tabname1:Title1:langfile@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__'
6958
-                    if ($values[0] != $type)
6959
-                        continue;
7325
+                    if ($values[0] != $type) {
7326
+                                            continue;
7327
+                    }
6960 7328
 
6961 7329
                     if (verifCond($values[4])) {
6962
-                        if ($values[3])
6963
-                            $langs->load($values[3]);
7330
+                        if ($values[3]) {
7331
+                                                    $langs->load($values[3]);
7332
+                        }
6964 7333
                         if (preg_match('/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
6965 7334
                             $substitutionarray = array();
6966 7335
                             complete_substitutions_array($substitutionarray, $langs, $object, array('needforkey' => $values[2]));
6967 7336
                             $label = make_substitutions($reg[1], $substitutionarray);
6968
-                        } else
6969
-                            $label = $langs->trans($values[2]);
7337
+                        } else {
7338
+                                                    $label = $langs->trans($values[2]);
7339
+                        }
6970 7340
 
6971 7341
                         //$head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[5]), 1);
6972 7342
                         $head[$h][0] = BASE_URI . preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[5]);
@@ -6974,30 +7344,32 @@  discard block
 block discarded – undo
6974 7344
                         $head[$h][2] = str_replace('+', '', $values[1]);
6975 7345
                         $h++;
6976 7346
                     }
6977
-                }
6978
-                else if (count($values) == 5) {       // deprecated
7347
+                } else if (count($values) == 5) {       // deprecated
6979 7348
                     dol_syslog('Passing 5 values in tabs module_parts is deprecated. Please update to 6 with permissions.', LOG_WARNING);
6980 7349
 
6981
-                    if ($values[0] != $type)
6982
-                        continue;
6983
-                    if ($values[3])
6984
-                        $langs->load($values[3]);
7350
+                    if ($values[0] != $type) {
7351
+                                            continue;
7352
+                    }
7353
+                    if ($values[3]) {
7354
+                                            $langs->load($values[3]);
7355
+                    }
6985 7356
                     if (preg_match('/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
6986 7357
                         $substitutionarray = array();
6987 7358
                         complete_substitutions_array($substitutionarray, $langs, $object, array('needforkey' => $values[2]));
6988 7359
                         $label = make_substitutions($reg[1], $substitutionarray);
6989
-                    } else
6990
-                        $label = $langs->trans($values[2]);
7360
+                    } else {
7361
+                                            $label = $langs->trans($values[2]);
7362
+                    }
6991 7363
 
6992 7364
                     $head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[4]), 1);
6993 7365
                     $head[$h][1] = $label;
6994 7366
                     $head[$h][2] = str_replace('+', '', $values[1]);
6995 7367
                     $h++;
6996 7368
                 }
6997
-            }
6998
-            else if ($mode == 'remove' && preg_match('/^\-/', $values[1])) {
6999
-                if ($values[0] != $type)
7000
-                    continue;
7369
+            } else if ($mode == 'remove' && preg_match('/^\-/', $values[1])) {
7370
+                if ($values[0] != $type) {
7371
+                                    continue;
7372
+                }
7001 7373
                 $tabname = str_replace('-', '', $values[1]);
7002 7374
                 foreach ($head as $key => $val) {
7003 7375
                     $condition = (!empty($values[3]) ? verifCond($values[3]) : 1);
@@ -7039,10 +7411,11 @@  discard block
 block discarded – undo
7039 7411
     global $action;
7040 7412
     global $micro_start_time;
7041 7413
 
7042
-    if ($zone == 'private')
7043
-        print "\n" . '<!-- Common footer for private page -->' . "\n";
7044
-    else
7045
-        print "\n" . '<!-- Common footer for public page -->' . "\n";
7414
+    if ($zone == 'private') {
7415
+            print "\n" . '<!-- Common footer for private page -->' . "\n";
7416
+    } else {
7417
+            print "\n" . '<!-- Common footer for public page -->' . "\n";
7418
+    }
7046 7419
 
7047 7420
     // A div to store page_y POST parameter so we can read it using javascript
7048 7421
     print "\n<!-- A div to store page_y POST paramater -->\n";
@@ -7051,8 +7424,9 @@  discard block
 block discarded – undo
7051 7424
     $parameters = array();
7052 7425
     $reshook = $hookmanager->executeHooks('printCommonFooter', $parameters);    // Note that $action and $object may have been modified by some hooks
7053 7426
     if (empty($reshook)) {
7054
-        if (!empty($conf->global->MAIN_HTML_FOOTER))
7055
-            print $conf->global->MAIN_HTML_FOOTER . "\n";
7427
+        if (!empty($conf->global->MAIN_HTML_FOOTER)) {
7428
+                    print $conf->global->MAIN_HTML_FOOTER . "\n";
7429
+        }
7056 7430
 
7057 7431
         print "\n";
7058 7432
         if (!empty($conf->use_javascript_ajax)) {
@@ -7075,8 +7449,9 @@  discard block
 block discarded – undo
7075 7449
                 print '/* JS CODE TO ENABLE to manage focus and mandatory form fields */' . "\n";
7076 7450
                 $relativepathstring = $_SERVER["PHP_SELF"];
7077 7451
                 // Clean $relativepathstring
7078
-                if (constant('DOL_URL_ROOT'))
7079
-                    $relativepathstring = preg_replace('/^' . preg_quote(constant('DOL_URL_ROOT'), '/') . '/', '', $relativepathstring);
7452
+                if (constant('DOL_URL_ROOT')) {
7453
+                                    $relativepathstring = preg_replace('/^' . preg_quote(constant('DOL_URL_ROOT'), '/') . '/', '', $relativepathstring);
7454
+                }
7080 7455
                 $relativepathstring = preg_replace('/^\//', '', $relativepathstring);
7081 7456
                 $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
7082 7457
                 $tmpqueryarraywehave = explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
@@ -7087,14 +7462,17 @@  discard block
 block discarded – undo
7087 7462
                             $tmpqueryarraytohave = explode('&', $defkey);
7088 7463
                             $foundintru = 0;
7089 7464
                             foreach ($tmpqueryarraytohave as $tmpquerytohave) {
7090
-                                if (!in_array($tmpquerytohave, $tmpqueryarraywehave))
7091
-                                    $foundintru = 1;
7465
+                                if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
7466
+                                                                    $foundintru = 1;
7467
+                                }
7468
+                            }
7469
+                            if (!$foundintru) {
7470
+                                                            $qualified = 1;
7092 7471
                             }
7093
-                            if (!$foundintru)
7094
-                                $qualified = 1;
7095 7472
                             //var_dump($defkey.'-'.$qualified);
7096
-                        } else
7097
-                            $qualified = 1;
7473
+                        } else {
7474
+                                                    $qualified = 1;
7475
+                        }
7098 7476
 
7099 7477
                         if ($qualified) {
7100 7478
                             foreach ($defval as $paramkey => $paramval) {
@@ -7113,14 +7491,17 @@  discard block
 block discarded – undo
7113 7491
                             $tmpqueryarraytohave = explode('&', $defkey);
7114 7492
                             $foundintru = 0;
7115 7493
                             foreach ($tmpqueryarraytohave as $tmpquerytohave) {
7116
-                                if (!in_array($tmpquerytohave, $tmpqueryarraywehave))
7117
-                                    $foundintru = 1;
7494
+                                if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
7495
+                                                                    $foundintru = 1;
7496
+                                }
7497
+                            }
7498
+                            if (!$foundintru) {
7499
+                                                            $qualified = 1;
7118 7500
                             }
7119
-                            if (!$foundintru)
7120
-                                $qualified = 1;
7121 7501
                             //var_dump($defkey.'-'.$qualified);
7122
-                        } else
7123
-                            $qualified = 1;
7502
+                        } else {
7503
+                                                    $qualified = 1;
7504
+                        }
7124 7505
 
7125 7506
                         if ($qualified) {
7126 7507
                             foreach ($defval as $paramkey => $paramval) {
@@ -7159,8 +7540,9 @@  discard block
 block discarded – undo
7159 7540
                 print "\n";
7160 7541
                 print "/* JS CODE TO ENABLE to add memory info */\n";
7161 7542
                 print 'window.console && console.log("';
7162
-                if (!empty($conf->global->MEMCACHED_SERVER))
7163
-                    print 'MEMCACHED_SERVER=' . $conf->global->MEMCACHED_SERVER . ' - ';
7543
+                if (!empty($conf->global->MEMCACHED_SERVER)) {
7544
+                                    print 'MEMCACHED_SERVER=' . $conf->global->MEMCACHED_SERVER . ' - ';
7545
+                }
7164 7546
                 print 'MAIN_OPTIMIZE_SPEED=' . (isset($conf->global->MAIN_OPTIMIZE_SPEED) ? $conf->global->MAIN_OPTIMIZE_SPEED : 'off');
7165 7547
                 if (!empty($micro_start_time)) {   // Works only if MAIN_SHOW_TUNING_INFO is defined at $_SERVER level. Not in global variable.
7166 7548
                     $micro_end_time = microtime(true);
@@ -7290,8 +7672,9 @@  discard block
 block discarded – undo
7290 7672
 
7291 7673
     $crits = explode(' ', $value);
7292 7674
     $res = '';
7293
-    if (!is_array($fields))
7294
-        $fields = array($fields);
7675
+    if (!is_array($fields)) {
7676
+            $fields = array($fields);
7677
+    }
7295 7678
 
7296 7679
     $nboffields = count($fields);
7297 7680
     $end2 = count($crits);
@@ -7354,8 +7737,9 @@  discard block
 block discarded – undo
7354 7737
                 $tmpcrits = explode('|', $crit);
7355 7738
                 $i3 = 0;
7356 7739
                 foreach ($tmpcrits as $tmpcrit) {
7357
-                    if (empty($tmpcrit))
7358
-                        continue;
7740
+                    if (empty($tmpcrit)) {
7741
+                                            continue;
7742
+                    }
7359 7743
 
7360 7744
                     $newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
7361 7745
 
@@ -7391,8 +7775,9 @@  discard block
 block discarded – undo
7391 7775
             }
7392 7776
             $i++;
7393 7777
         }
7394
-        if ($newres)
7395
-            $res = $res . ($res ? ' AND ' : '') . ($i2 > 1 ? '(' : '') . $newres . ($i2 > 1 ? ')' : '');
7778
+        if ($newres) {
7779
+                    $res = $res . ($res ? ' AND ' : '') . ($i2 > 1 ? '(' : '') . $newres . ($i2 > 1 ? ')' : '');
7780
+        }
7396 7781
         $j++;
7397 7782
     }
7398 7783
     $res = ($nofirstand ? "" : " AND ") . "(" . $res . ")";
@@ -7432,29 +7817,37 @@  discard block
 block discarded – undo
7432 7817
 function getImageFileNameForSize($file, $extName, $extImgTarget = '')
7433 7818
 {
7434 7819
     $dirName = dirname($file);
7435
-    if ($dirName == '.')
7436
-        $dirName = '';
7820
+    if ($dirName == '.') {
7821
+            $dirName = '';
7822
+    }
7437 7823
 
7438 7824
     $fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i', '', $file); // We remove extension, whatever is its case
7439 7825
     $fileName = basename($fileName);
7440 7826
 
7441
-    if (empty($extImgTarget))
7442
-        $extImgTarget = (preg_match('/\.jpg$/i', $file) ? '.jpg' : '');
7443
-    if (empty($extImgTarget))
7444
-        $extImgTarget = (preg_match('/\.jpeg$/i', $file) ? '.jpeg' : '');
7445
-    if (empty($extImgTarget))
7446
-        $extImgTarget = (preg_match('/\.gif$/i', $file) ? '.gif' : '');
7447
-    if (empty($extImgTarget))
7448
-        $extImgTarget = (preg_match('/\.png$/i', $file) ? '.png' : '');
7449
-    if (empty($extImgTarget))
7450
-        $extImgTarget = (preg_match('/\.bmp$/i', $file) ? '.bmp' : '');
7827
+    if (empty($extImgTarget)) {
7828
+            $extImgTarget = (preg_match('/\.jpg$/i', $file) ? '.jpg' : '');
7829
+    }
7830
+    if (empty($extImgTarget)) {
7831
+            $extImgTarget = (preg_match('/\.jpeg$/i', $file) ? '.jpeg' : '');
7832
+    }
7833
+    if (empty($extImgTarget)) {
7834
+            $extImgTarget = (preg_match('/\.gif$/i', $file) ? '.gif' : '');
7835
+    }
7836
+    if (empty($extImgTarget)) {
7837
+            $extImgTarget = (preg_match('/\.png$/i', $file) ? '.png' : '');
7838
+    }
7839
+    if (empty($extImgTarget)) {
7840
+            $extImgTarget = (preg_match('/\.bmp$/i', $file) ? '.bmp' : '');
7841
+    }
7451 7842
 
7452
-    if (!$extImgTarget)
7453
-        return $file;
7843
+    if (!$extImgTarget) {
7844
+            return $file;
7845
+    }
7454 7846
 
7455 7847
     $subdir = '';
7456
-    if ($extName)
7457
-        $subdir = 'thumbs/';
7848
+    if ($extName) {
7849
+            $subdir = 'thumbs/';
7850
+    }
7458 7851
 
7459 7852
     return ($dirName ? $dirName . '/' : '') . $subdir . $fileName . $extName . $extImgTarget; // New filename for thumb
7460 7853
 }
@@ -7472,8 +7865,9 @@  discard block
 block discarded – undo
7472 7865
 {
7473 7866
     global $conf, $langs;
7474 7867
 
7475
-    if (empty($conf->use_javascript_ajax))
7476
-        return '';
7868
+    if (empty($conf->use_javascript_ajax)) {
7869
+            return '';
7870
+    }
7477 7871
 
7478 7872
     $mime_preview = array('bmp', 'jpeg', 'png', 'gif', 'tiff', 'pdf', 'plain', 'css', 'svg+xml');
7479 7873
     //$mime_preview[]='vnd.oasis.opendocument.presentation';
@@ -7481,18 +7875,20 @@  discard block
 block discarded – undo
7481 7875
     $num_mime = array_search(dol_mimetype($relativepath, '', 1), $mime_preview);
7482 7876
 
7483 7877
     if ($alldata == 1) {
7484
-        if ($num_mime !== false)
7485
-            return array('target' => '_blank', 'css' => 'documentpreview', 'url' => DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&attachment=0&file=' . urlencode($relativepath) . ($param ? '&' . $param : ''), 'mime' => dol_mimetype($relativepath),);
7486
-        else
7487
-            return array();
7878
+        if ($num_mime !== false) {
7879
+                    return array('target' => '_blank', 'css' => 'documentpreview', 'url' => DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&attachment=0&file=' . urlencode($relativepath) . ($param ? '&' . $param : ''), 'mime' => dol_mimetype($relativepath),);
7880
+        } else {
7881
+                    return array();
7882
+        }
7488 7883
     }
7489 7884
 
7490 7885
     // old behavior
7491
-    if ($num_mime !== false)
7492
-        return 'javascript:document_preview(\'' . dol_escape_js(DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&attachment=0&file=' . urlencode($relativepath) . ($param ? '&' . $param : '')) . '\', \'' . dol_mimetype($relativepath) . '\', \'' . dol_escape_js($langs->trans('Preview')) . '\')';
7493
-    else
7494
-        return '';
7495
-}
7886
+    if ($num_mime !== false) {
7887
+            return 'javascript:document_preview(\'' . dol_escape_js(DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart . '&attachment=0&file=' . urlencode($relativepath) . ($param ? '&' . $param : '')) . '\', \'' . dol_mimetype($relativepath) . '\', \'' . dol_escape_js($langs->trans('Preview')) . '\')';
7888
+    } else {
7889
+            return '';
7890
+    }
7891
+    }
7496 7892
 
7497 7893
 /**
7498 7894
  * Make content of an input box selected when we click into input field.
@@ -7509,8 +7905,9 @@  discard block
 block discarded – undo
7509 7905
 				    jQuery("#' . $htmlname . '").click(function() { jQuery(this).select(); } );
7510 7906
 				});
7511 7907
 		    </script>';
7512
-    if ($addlink)
7513
-        $out .= ' <a href="' . $addlink . '" target="_blank">' . $langs->trans("Link") . '</a>';
7908
+    if ($addlink) {
7909
+            $out .= ' <a href="' . $addlink . '" target="_blank">' . $langs->trans("Link") . '</a>';
7910
+    }
7514 7911
     return $out;
7515 7912
 }
7516 7913
 
@@ -7892,8 +8289,9 @@  discard block
 block discarded – undo
7892 8289
     if (!isset($dictvalues[$tablename])) {
7893 8290
         $dictvalues[$tablename] = array();
7894 8291
         $sql = 'SELECT * FROM ' . $tablename . ' WHERE 1';
7895
-        if ($checkentity)
7896
-            $sql .= ' AND entity IN (0,' . getEntity($tablename) . ')';
8292
+        if ($checkentity) {
8293
+                    $sql .= ' AND entity IN (0,' . getEntity($tablename) . ')';
8294
+        }
7897 8295
 
7898 8296
         $resql = $db->query($sql);
7899 8297
         if ($resql) {
@@ -7905,11 +8303,14 @@  discard block
 block discarded – undo
7905 8303
         }
7906 8304
     }
7907 8305
 
7908
-    if (!empty($dictvalues[$tablename][$id]))
7909
-        return $dictvalues[$tablename][$id]->{$field}; // Found
8306
+    if (!empty($dictvalues[$tablename][$id])) {
8307
+            return $dictvalues[$tablename][$id]->{$field};
8308
+    }
8309
+    // Found
7910 8310
     else { // Not found
7911
-        if ($id > 0)
7912
-            return $id;
8311
+        if ($id > 0) {
8312
+                    return $id;
8313
+        }
7913 8314
         return '';
7914 8315
     }
7915 8316
 }
@@ -7939,8 +8340,9 @@  discard block
 block discarded – undo
7939 8340
             $b = hexdec($hexb);
7940 8341
         }
7941 8342
         $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0;    // HSL algorithm
7942
-        if ($bright > 0.6)
7943
-            $res = 1;
8343
+        if ($bright > 0.6) {
8344
+                    $res = 1;
8345
+        }
7944 8346
     }
7945 8347
     return $res;
7946 8348
 }
@@ -7959,8 +8361,10 @@  discard block
 block discarded – undo
7959 8361
 
7960 8362
     //print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
7961 8363
     //print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
7962
-    if (empty($menuentry['enabled']))
7963
-        return 0; // Entry disabled by condition
8364
+    if (empty($menuentry['enabled'])) {
8365
+            return 0;
8366
+    }
8367
+    // Entry disabled by condition
7964 8368
     if ($type_user && $menuentry['module']) {
7965 8369
         $tmploops = explode('|', $menuentry['module']);
7966 8370
         $found = 0;
@@ -7970,15 +8374,23 @@  discard block
 block discarded – undo
7970 8374
                 break;
7971 8375
             }
7972 8376
         }
7973
-        if (!$found)
7974
-            return 0; // Entry is for menus all excluded to external users
8377
+        if (!$found) {
8378
+                    return 0;
8379
+        }
8380
+        // Entry is for menus all excluded to external users
8381
+    }
8382
+    if (!$menuentry['perms'] && $type_user) {
8383
+            return 0;
8384
+    }
8385
+    // No permissions and user is external
8386
+    if (!$menuentry['perms'] && !empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED)) {
8387
+            return 0;
8388
+    }
8389
+    // No permissions and option to hide when not allowed, even for internal user, is on
8390
+    if (!$menuentry['perms']) {
8391
+            return 2;
7975 8392
     }
7976
-    if (!$menuentry['perms'] && $type_user)
7977
-        return 0;            // No permissions and user is external
7978
-    if (!$menuentry['perms'] && !empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED))
7979
-        return 0; // No permissions and option to hide when not allowed, even for internal user, is on
7980
-    if (!$menuentry['perms'])
7981
-        return 2;               // No permissions and user is external
8393
+    // No permissions and user is external
7982 8394
     return 1;
7983 8395
 }
7984 8396
 
Please login to merge, or discard this patch.