Passed
Push — master ( 65bdac...4e88da )
by Alxarafe
32:38
created
Controllers/Categories.php 1 patch
Braces   +30 added lines, -20 removed lines patch added patch discarded remove patch
@@ -50,8 +50,9 @@  discard block
 block discarded – undo
50 50
 
51 51
 // Security check
52 52
         $socid = DolUtils::GETPOST('socid', 'int');
53
-        if (!Globals::$user->rights->categorie->lire)
54
-            accessforbidden();
53
+        if (!Globals::$user->rights->categorie->lire) {
54
+                    accessforbidden();
55
+        }
55 56
 
56 57
         $action = DolUtils::GETPOST('action', 'alpha');
57 58
         $cancel = DolUtils::GETPOST('cancel', 'alpha');
@@ -69,22 +70,29 @@  discard block
 block discarded – undo
69 70
         $parent = DolUtils::GETPOST('parent');
70 71
 
71 72
         if ($origin) {
72
-            if ($type == Categorie::TYPE_PRODUCT)
73
-                $idProdOrigin = $origin;
74
-            if ($type == Categorie::TYPE_SUPPLIER)
75
-                $idSupplierOrigin = $origin;
76
-            if ($type == Categorie::TYPE_CUSTOMER)
77
-                $idCompanyOrigin = $origin;
78
-            if ($type == Categorie::TYPE_MEMBER)
79
-                $idMemberOrigin = $origin;
80
-            if ($type == Categorie::TYPE_CONTACT)
81
-                $idContactOrigin = $origin;
82
-            if ($type == Categorie::TYPE_PROJECT)
83
-                $idProjectOrigin = $origin;
73
+            if ($type == Categorie::TYPE_PRODUCT) {
74
+                            $idProdOrigin = $origin;
75
+            }
76
+            if ($type == Categorie::TYPE_SUPPLIER) {
77
+                            $idSupplierOrigin = $origin;
78
+            }
79
+            if ($type == Categorie::TYPE_CUSTOMER) {
80
+                            $idCompanyOrigin = $origin;
81
+            }
82
+            if ($type == Categorie::TYPE_MEMBER) {
83
+                            $idMemberOrigin = $origin;
84
+            }
85
+            if ($type == Categorie::TYPE_CONTACT) {
86
+                            $idContactOrigin = $origin;
87
+            }
88
+            if ($type == Categorie::TYPE_PROJECT) {
89
+                            $idProjectOrigin = $origin;
90
+            }
84 91
         }
85 92
 
86
-        if ($catorigin && $type == Categorie::TYPE_PRODUCT)
87
-            $idCatOrigin = $catorigin;
93
+        if ($catorigin && $type == Categorie::TYPE_PRODUCT) {
94
+                    $idCatOrigin = $catorigin;
95
+        }
88 96
 
89 97
         $object = new Categorie();
90 98
 
@@ -139,12 +147,14 @@  discard block
 block discarded – undo
139 147
             $object->visible = $visible;
140 148
             $object->type = $type;
141 149
 
142
-            if ($parent != "-1")
143
-                $object->fk_parent = $parent;
150
+            if ($parent != "-1") {
151
+                            $object->fk_parent = $parent;
152
+            }
144 153
 
145 154
             $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
146
-            if ($ret < 0)
147
-                $error++;
155
+            if ($ret < 0) {
156
+                            $error++;
157
+            }
148 158
 
149 159
             if (!$object->label) {
150 160
                 $error++;
Please login to merge, or discard this patch.
dolibarr/htdocs/install/inc.php 1 patch
Braces   +101 added lines, -65 removed lines patch added patch discarded remove patch
@@ -31,8 +31,9 @@  discard block
 block discarded – undo
31 31
  * 	\brief      File that define environment for support pages
32 32
  */
33 33
 // Just to define version DOL_VERSION
34
-if (!defined('DOL_INC_FOR_VERSION_ERROR'))
34
+if (!defined('DOL_INC_FOR_VERSION_ERROR')) {
35 35
     define('DOL_INC_FOR_VERSION_ERROR', '1');
36
+}
36 37
 require_once DOL_BASE_PATH . '/filefunc.inc.php';
37 38
 
38 39
 require_once DOL_BASE_PATH . '/core/class/translate.class.php';
@@ -151,23 +152,31 @@  discard block
 block discarded – undo
151 152
 define('DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root) ? $dolibarr_main_url_root : ''));           // URL relative root
152 153
 $uri = preg_replace('/^http(s?):\/\//i', '', constant('DOL_MAIN_URL_ROOT'));  // $uri contains url without http*
153 154
 $suburi = strstr($uri, '/');       // $suburi contains url without domain
154
-if ($suburi == '/')
155
-    $suburi = '';   // If $suburi is /, it is now ''
155
+if ($suburi == '/') {
156
+    $suburi = '';
157
+}
158
+// If $suburi is /, it is now ''
156 159
 define('DOL_URL_ROOT', $suburi);    // URL relative root ('', '/dolibarr', ...)
157 160
 
158 161
 
159
-if (empty($conf->file->character_set_client))
162
+if (empty($conf->file->character_set_client)) {
160 163
     $conf->file->character_set_client = "utf-8";
161
-if (empty($conf->db->character_set))
164
+}
165
+if (empty($conf->db->character_set)) {
162 166
     $conf->db->character_set = 'utf8';
163
-if (empty($conf->db->dolibarr_main_db_collation))
167
+}
168
+if (empty($conf->db->dolibarr_main_db_collation)) {
164 169
     $conf->db->dolibarr_main_db_collation = 'utf8_unicode_ci';
165
-if (empty($conf->db->dolibarr_main_db_encryption))
170
+}
171
+if (empty($conf->db->dolibarr_main_db_encryption)) {
166 172
     $conf->db->dolibarr_main_db_encryption = 0;
167
-if (empty($conf->db->dolibarr_main_db_cryptkey))
173
+}
174
+if (empty($conf->db->dolibarr_main_db_cryptkey)) {
168 175
     $conf->db->dolibarr_main_db_cryptkey = '';
169
-if (empty($conf->db->user))
176
+}
177
+if (empty($conf->db->user)) {
170 178
     $conf->db->user = '';
179
+}
171 180
 
172 181
 // Define array of document root directories
173 182
 $conf->file->dol_document_root = array(DOL_DOCUMENT_ROOT);
@@ -224,19 +233,24 @@  discard block
 block discarded – undo
224 233
 // Force usage of log file for install and upgrades
225 234
 $conf->syslog->enabled = 1;
226 235
 $conf->global->SYSLOG_LEVEL = constant('LOG_DEBUG');
227
-if (!defined('SYSLOG_HANDLERS'))
236
+if (!defined('SYSLOG_HANDLERS')) {
228 237
     define('SYSLOG_HANDLERS', '["mod_syslog_file"]');
238
+}
229 239
 if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined
230
-    if (@is_writable('/tmp'))
231
-        define('SYSLOG_FILE', '/tmp/dolibarr_install.log');
232
-    else if (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"]))
233
-        define('SYSLOG_FILE', $_ENV["TMP"] . '/dolibarr_install.log');
234
-    else if (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"]))
235
-        define('SYSLOG_FILE', $_ENV["TEMP"] . '/dolibarr_install.log');
236
-    else if (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat'))
237
-        define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp
238
-    else if (@is_writable('../../'))
239
-        define('SYSLOG_FILE', '../../dolibarr_install.log');    // For others
240
+    if (@is_writable('/tmp')) {
241
+            define('SYSLOG_FILE', '/tmp/dolibarr_install.log');
242
+    } else if (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) {
243
+            define('SYSLOG_FILE', $_ENV["TMP"] . '/dolibarr_install.log');
244
+    } else if (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) {
245
+            define('SYSLOG_FILE', $_ENV["TEMP"] . '/dolibarr_install.log');
246
+    } else if (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) {
247
+            define('SYSLOG_FILE', '../../../../dolibarr_install.log');
248
+    }
249
+    // For DoliWamp
250
+    else if (@is_writable('../../')) {
251
+            define('SYSLOG_FILE', '../../dolibarr_install.log');
252
+    }
253
+    // For others
240 254
 
241 255
 
242 256
 
@@ -251,10 +265,12 @@  discard block
 block discarded – undo
251 265
         
252 266
 //print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
253 267
 }
254
-if (defined('SYSLOG_FILE'))
268
+if (defined('SYSLOG_FILE')) {
255 269
     $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
256
-if (!defined('SYSLOG_FILE_NO_ERROR'))
270
+}
271
+if (!defined('SYSLOG_FILE_NO_ERROR')) {
257 272
     define('SYSLOG_FILE_NO_ERROR', 1);
273
+}
258 274
 // We init log handler for install
259 275
 $handlers = array('mod_syslog_file');
260 276
 foreach ($handlers as $handler) {
@@ -269,9 +285,10 @@  discard block
 block discarded – undo
269 285
         throw new Exception('Log handler does not extend LogHandlerInterface');
270 286
     }
271 287
 
272
-    if (empty($conf->loghandlers[$handler]))
273
-        $conf->loghandlers[$handler] = $loghandlerinstance;
274
-}
288
+    if (empty($conf->loghandlers[$handler])) {
289
+            $conf->loghandlers[$handler] = $loghandlerinstance;
290
+    }
291
+    }
275 292
 
276 293
 // Removed magic_quotes
277 294
 if (function_exists('get_magic_quotes_gpc')) { // magic_quotes_* removed in PHP 5.4
@@ -295,10 +312,11 @@  discard block
 block discarded – undo
295 312
 
296 313
 // Defini objet langs
297 314
 $langs = new Translate('..', $conf);
298
-if (GETPOST('lang', 'aZ09'))
315
+if (GETPOST('lang', 'aZ09')) {
299 316
     $langs->setDefaultLang(GETPOST('lang', 'aZ09'));
300
-else
317
+} else {
301 318
     $langs->setDefaultLang('auto');
319
+}
302 320
 
303 321
 $bc[false] = ' class="bg1"';
304 322
 $bc[true] = ' class="bg2"';
@@ -321,8 +339,9 @@  discard block
 block discarded – undo
321 339
     global $character_set_client;
322 340
 
323 341
     $return = include_once $dolibarr_main_document_root . '/core/class/conf.class.php';
324
-    if (!$return)
325
-        return -1;
342
+    if (!$return) {
343
+            return -1;
344
+    }
326 345
 
327 346
     $conf = new Conf();
328 347
     $conf->db->type = trim($dolibarr_main_db_type);
@@ -333,40 +352,51 @@  discard block
 block discarded – undo
333 352
     $conf->db->pass = trim($dolibarr_main_db_pass);
334 353
 
335 354
     // Mysql driver support has been removed in favor of mysqli
336
-    if ($conf->db->type == 'mysql')
337
-        $conf->db->type = 'mysqli';
338
-    if (empty($character_set_client))
339
-        $character_set_client = "UTF-8";
355
+    if ($conf->db->type == 'mysql') {
356
+            $conf->db->type = 'mysqli';
357
+    }
358
+    if (empty($character_set_client)) {
359
+            $character_set_client = "UTF-8";
360
+    }
340 361
     $conf->file->character_set_client = strtoupper($character_set_client);
341
-    if (empty($dolibarr_main_db_character_set))
342
-        $dolibarr_main_db_character_set = ($conf->db->type == 'mysqli' ? 'utf8' : '');
362
+    if (empty($dolibarr_main_db_character_set)) {
363
+            $dolibarr_main_db_character_set = ($conf->db->type == 'mysqli' ? 'utf8' : '');
364
+    }
343 365
     $conf->db->character_set = $dolibarr_main_db_character_set;
344
-    if (empty($dolibarr_main_db_collation))
345
-        $dolibarr_main_db_collation = ($conf->db->type == 'mysqli' ? 'utf8_unicode_ci' : '');
366
+    if (empty($dolibarr_main_db_collation)) {
367
+            $dolibarr_main_db_collation = ($conf->db->type == 'mysqli' ? 'utf8_unicode_ci' : '');
368
+    }
346 369
     $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
347
-    if (empty($dolibarr_main_db_encryption))
348
-        $dolibarr_main_db_encryption = 0;
370
+    if (empty($dolibarr_main_db_encryption)) {
371
+            $dolibarr_main_db_encryption = 0;
372
+    }
349 373
     $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
350
-    if (empty($dolibarr_main_db_cryptkey))
351
-        $dolibarr_main_db_cryptkey = '';
374
+    if (empty($dolibarr_main_db_cryptkey)) {
375
+            $dolibarr_main_db_cryptkey = '';
376
+    }
352 377
     $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
353 378
 
354 379
     // Force usage of log file for install and upgrades
355 380
     $conf->syslog->enabled = 1;
356 381
     $conf->global->SYSLOG_LEVEL = constant('LOG_DEBUG');
357
-    if (!defined('SYSLOG_HANDLERS'))
358
-        define('SYSLOG_HANDLERS', '["mod_syslog_file"]');
382
+    if (!defined('SYSLOG_HANDLERS')) {
383
+            define('SYSLOG_HANDLERS', '["mod_syslog_file"]');
384
+    }
359 385
     if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined
360
-        if (@is_writable('/tmp'))
361
-            define('SYSLOG_FILE', '/tmp/dolibarr_install.log');
362
-        else if (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"]))
363
-            define('SYSLOG_FILE', $_ENV["TMP"] . '/dolibarr_install.log');
364
-        else if (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"]))
365
-            define('SYSLOG_FILE', $_ENV["TEMP"] . '/dolibarr_install.log');
366
-        else if (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat'))
367
-            define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp
368
-        else if (@is_writable('../../'))
369
-            define('SYSLOG_FILE', '../../dolibarr_install.log');    // For others
386
+        if (@is_writable('/tmp')) {
387
+                    define('SYSLOG_FILE', '/tmp/dolibarr_install.log');
388
+        } else if (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) {
389
+                    define('SYSLOG_FILE', $_ENV["TMP"] . '/dolibarr_install.log');
390
+        } else if (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) {
391
+                    define('SYSLOG_FILE', $_ENV["TEMP"] . '/dolibarr_install.log');
392
+        } else if (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) {
393
+                    define('SYSLOG_FILE', '../../../../dolibarr_install.log');
394
+        }
395
+        // For DoliWamp
396
+        else if (@is_writable('../../')) {
397
+                    define('SYSLOG_FILE', '../../dolibarr_install.log');
398
+        }
399
+        // For others
370 400
 
371 401
 
372 402
 
@@ -381,10 +411,12 @@  discard block
 block discarded – undo
381 411
             
382 412
 //print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
383 413
     }
384
-    if (defined('SYSLOG_FILE'))
385
-        $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
386
-    if (!defined('SYSLOG_FILE_NO_ERROR'))
387
-        define('SYSLOG_FILE_NO_ERROR', 1);
414
+    if (defined('SYSLOG_FILE')) {
415
+            $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
416
+    }
417
+    if (!defined('SYSLOG_FILE_NO_ERROR')) {
418
+            define('SYSLOG_FILE_NO_ERROR', 1);
419
+    }
388 420
     // We init log handler for install
389 421
     $handlers = array('mod_syslog_file');
390 422
     foreach ($handlers as $handler) {
@@ -399,8 +431,9 @@  discard block
 block discarded – undo
399 431
             throw new Exception('Log handler does not extend LogHandlerInterface');
400 432
         }
401 433
 
402
-        if (empty($conf->loghandlers[$handler]))
403
-            $conf->loghandlers[$handler] = $loghandlerinstance;
434
+        if (empty($conf->loghandlers[$handler])) {
435
+                    $conf->loghandlers[$handler] = $loghandlerinstance;
436
+        }
404 437
     }
405 438
 
406 439
     return 1;
@@ -522,11 +555,13 @@  discard block
 block discarded – undo
522 555
         }
523 556
 
524 557
         print '<input type="submit" ' . ($nonext == '2' ? 'disabled="disabled" ' : '') . 'value="' . $langs->trans("NextStep") . ' ->"';
525
-        if ($jscheckfunction)
526
-            print ' onClick="return ' . $jscheckfunction . '();"';
558
+        if ($jscheckfunction) {
559
+                    print ' onClick="return ' . $jscheckfunction . '();"';
560
+        }
527 561
         print '></div>';
528
-        if ($withpleasewait)
529
-            print '<div style="visibility: hidden;" class="pleasewait" id="pleasewait"><br>' . $langs->trans("NextStepMightLastALongTime") . '<br><br><div class="blinkwait">' . $langs->trans("PleaseBePatient") . '</div></div>';
562
+        if ($withpleasewait) {
563
+                    print '<div style="visibility: hidden;" class="pleasewait" id="pleasewait"><br>' . $langs->trans("NextStepMightLastALongTime") . '<br><br><div class="blinkwait">' . $langs->trans("PleaseBePatient") . '</div></div>';
564
+        }
530 565
     }
531 566
     if ($setuplang) {
532 567
         print '<input type="hidden" name="selectlang" value="' . $setuplang . '">';
@@ -562,8 +597,9 @@  discard block
 block discarded – undo
562 597
  */
563 598
 function dolibarr_install_syslog($message, $level = LOG_DEBUG)
564 599
 {
565
-    if (!defined('LOG_DEBUG'))
566
-        define('LOG_DEBUG', 6);
600
+    if (!defined('LOG_DEBUG')) {
601
+            define('LOG_DEBUG', 6);
602
+    }
567 603
     dol_syslog($message, $level);
568 604
 }
569 605
 
Please login to merge, or discard this patch.
Helpers/DolUtils2.php 1 patch
Braces   +726 added lines, -379 removed lines patch added patch discarded remove patch
@@ -59,8 +59,7 @@  discard block
 block discarded – undo
59 59
                 $entity = "&#". $unicode . ';';
60 60
                 $decodedStr .= utf8_encode($entity);
61 61
                 $pos += 4;
62
-            }
63
-            else {
62
+            } else {
64 63
                 // we have an escaped ascii character
65 64
                 $hexVal = substr($source, $pos, 2);
66 65
                 $decodedStr .= chr(hexdec($hexVal));
@@ -101,7 +100,10 @@  discard block
 block discarded – undo
101 100
         {
102 101
             while (($file = readdir($handle))!==false)
103 102
             {
104
-                if (preg_match('/disabled/',$file)) continue;   // We discard module if it contains disabled into name.
103
+                if (preg_match('/disabled/',$file)) {
104
+                    continue;
105
+                }
106
+                // We discard module if it contains disabled into name.
105 107
 
106 108
                 if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes')
107 109
                 {
@@ -133,8 +135,14 @@  discard block
 block discarded – undo
133 135
     	$outputlangs=$langs;
134 136
     }
135 137
 
136
-    if ($outputlangs->defaultlang == 'ca_CA') $selected='CAP4';        // Canada
137
-    if ($outputlangs->defaultlang == 'en_US') $selected='USLetter';    // US
138
+    if ($outputlangs->defaultlang == 'ca_CA') {
139
+        $selected='CAP4';
140
+    }
141
+    // Canada
142
+    if ($outputlangs->defaultlang == 'en_US') {
143
+        $selected='USLetter';
144
+    }
145
+    // US
138 146
     return $selected;
139 147
 }
140 148
 
@@ -159,29 +167,42 @@  discard block
 block discarded – undo
159 167
         {
160 168
             $content=file_get_contents($formfile);
161 169
             $isutf8=utf8_check($content);
162
-            if (! $isutf8 && $conf->file->character_set_client == 'UTF-8') print utf8_encode($content);
163
-            elseif ($isutf8 && $conf->file->character_set_client == 'ISO-8859-1') print utf8_decode($content);
164
-            else print $content;
170
+            if (! $isutf8 && $conf->file->character_set_client == 'UTF-8') {
171
+                print utf8_encode($content);
172
+            } elseif ($isutf8 && $conf->file->character_set_client == 'ISO-8859-1') {
173
+                print utf8_decode($content);
174
+            } else {
175
+                print $content;
176
+            }
165 177
             return true;
166
-        }
167
-        else dol_syslog('functions2::dol_print_file not found', LOG_DEBUG);
178
+        } else {
179
+            dol_syslog('functions2::dol_print_file not found', LOG_DEBUG);
180
+        }
168 181
 
169 182
         if ($searchalt) {
170 183
             // Test si fichier dans repertoire de la langue alternative
171
-            if ($langs->defaultlang != "en_US") $formfilealt = $searchdir."/langs/en_US/".$filename;
172
-            else $formfilealt = $searchdir."/langs/fr_FR/".$filename;
184
+            if ($langs->defaultlang != "en_US") {
185
+                $formfilealt = $searchdir."/langs/en_US/".$filename;
186
+            } else {
187
+                $formfilealt = $searchdir."/langs/fr_FR/".$filename;
188
+            }
173 189
             dol_syslog('functions2::dol_print_file search alt file '.$formfilealt, LOG_DEBUG);
174 190
             //print 'getcwd='.getcwd().' htmlfilealt='.$formfilealt.' X '.file_exists(getcwd().'/'.$formfilealt);
175 191
             if (is_readable($formfilealt))
176 192
             {
177 193
                 $content=file_get_contents($formfilealt);
178 194
                 $isutf8=utf8_check($content);
179
-                if (! $isutf8 && $conf->file->character_set_client == 'UTF-8') print utf8_encode($content);
180
-                elseif ($isutf8 && $conf->file->character_set_client == 'ISO-8859-1') print utf8_decode($content);
181
-                else print $content;
195
+                if (! $isutf8 && $conf->file->character_set_client == 'UTF-8') {
196
+                    print utf8_encode($content);
197
+                } elseif ($isutf8 && $conf->file->character_set_client == 'ISO-8859-1') {
198
+                    print utf8_decode($content);
199
+                } else {
200
+                    print $content;
201
+                }
182 202
                 return true;
183
-            }
184
-            else dol_syslog('functions2::dol_print_file not found', LOG_DEBUG);
203
+            } else {
204
+                dol_syslog('functions2::dol_print_file not found', LOG_DEBUG);
205
+            }
185 206
         }
186 207
     }
187 208
 
@@ -211,279 +232,460 @@  discard block
 block discarded – undo
211 232
     $deltadateforuser=round($deltadateforclient-$deltadateforserver);
212 233
     //print "x".$deltadateforserver." - ".$deltadateforclient." - ".$deltadateforuser;
213 234
 
214
-    if ($usetable) print '<table class="border centpercent">';
235
+    if ($usetable) {
236
+        print '<table class="border centpercent">';
237
+    }
215 238
 
216 239
     // Import key
217 240
     if (! empty($object->import_key))
218 241
     {
219
-        if ($usetable) print '<tr><td class="titlefield">';
242
+        if ($usetable) {
243
+            print '<tr><td class="titlefield">';
244
+        }
220 245
         print $langs->trans("ImportedWithSet");
221
-        if ($usetable) print '</td><td>';
222
-        else print ': ';
246
+        if ($usetable) {
247
+            print '</td><td>';
248
+        } else {
249
+            print ': ';
250
+        }
223 251
         print $object->import_key;
224
-        if ($usetable) print '</td></tr>';
225
-        else print '<br>';
252
+        if ($usetable) {
253
+            print '</td></tr>';
254
+        } else {
255
+            print '<br>';
256
+        }
226 257
     }
227 258
 
228 259
     // User creation (old method using already loaded object and not id is kept for backward compatibility)
229 260
     if (! empty($object->user_creation) || ! empty($object->user_creation_id))
230 261
     {
231
-        if ($usetable) print '<tr><td class="titlefield">';
262
+        if ($usetable) {
263
+            print '<tr><td class="titlefield">';
264
+        }
232 265
         print $langs->trans("CreatedBy");
233
-        if ($usetable) print '</td><td>';
234
-        else print ': ';
266
+        if ($usetable) {
267
+            print '</td><td>';
268
+        } else {
269
+            print ': ';
270
+        }
235 271
         if (is_object($object->user_creation))
236 272
         {
237
-        	if ($object->user_creation->id) print $object->user_creation->getNomUrl(1, '', 0, 0, 0);
238
-        	else print $langs->trans("Unknown");
239
-        }
240
-        else
273
+        	if ($object->user_creation->id) {
274
+        	    print $object->user_creation->getNomUrl(1, '', 0, 0, 0);
275
+        	} else {
276
+        	    print $langs->trans("Unknown");
277
+        	}
278
+        } else
241 279
         {
242 280
             $userstatic=new User($db);
243 281
             $userstatic->fetch($object->user_creation_id ? $object->user_creation_id : $object->user_creation);
244
-            if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
245
-        	else print $langs->trans("Unknown");
282
+            if ($userstatic->id) {
283
+                print $userstatic->getNomUrl(1, '', 0, 0, 0);
284
+            } else {
285
+        	    print $langs->trans("Unknown");
286
+        	}
246 287
         }
247
-        if ($usetable) print '</td></tr>';
248
-        else print '<br>';
288
+        if ($usetable) {
289
+            print '</td></tr>';
290
+        } else {
291
+            print '<br>';
292
+        }
249 293
     }
250 294
 
251 295
     // Date creation
252 296
     if (! empty($object->date_creation))
253 297
     {
254
-        if ($usetable) print '<tr><td class="titlefield">';
298
+        if ($usetable) {
299
+            print '<tr><td class="titlefield">';
300
+        }
255 301
         print $langs->trans("DateCreation");
256
-        if ($usetable) print '</td><td>';
257
-        else print ': ';
302
+        if ($usetable) {
303
+            print '</td><td>';
304
+        } else {
305
+            print ': ';
306
+        }
258 307
         print dol_print_date($object->date_creation, 'dayhour');
259
-        if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' &nbsp; / &nbsp; '.dol_print_date($object->date_creation+($deltadateforuser*3600),"dayhour").' &nbsp;'.$langs->trans("ClientHour");
260
-        if ($usetable) print '</td></tr>';
261
-        else print '<br>';
308
+        if ($deltadateforuser) {
309
+            print ' '.$langs->trans("CurrentHour").' &nbsp; / &nbsp; '.dol_print_date($object->date_creation+($deltadateforuser*3600),"dayhour").' &nbsp;'.$langs->trans("ClientHour");
310
+        }
311
+        if ($usetable) {
312
+            print '</td></tr>';
313
+        } else {
314
+            print '<br>';
315
+        }
262 316
     }
263 317
 
264 318
     // User change (old method using already loaded object and not id is kept for backward compatibility)
265 319
     if (! empty($object->user_modification) || ! empty($object->user_modification_id))
266 320
     {
267
-        if ($usetable) print '<tr><td class="titlefield">';
321
+        if ($usetable) {
322
+            print '<tr><td class="titlefield">';
323
+        }
268 324
         print $langs->trans("ModifiedBy");
269
-        if ($usetable) print '</td><td>';
270
-        else print ': ';
325
+        if ($usetable) {
326
+            print '</td><td>';
327
+        } else {
328
+            print ': ';
329
+        }
271 330
         if (is_object($object->user_modification))
272 331
         {
273
-        	if ($object->user_modification->id) print $object->user_modification->getNomUrl(1, '', 0, 0, 0);
274
-        	else print $langs->trans("Unknown");
275
-        }
276
-        else
332
+        	if ($object->user_modification->id) {
333
+        	    print $object->user_modification->getNomUrl(1, '', 0, 0, 0);
334
+        	} else {
335
+        	    print $langs->trans("Unknown");
336
+        	}
337
+        } else
277 338
         {
278 339
             $userstatic=new User($db);
279 340
             $userstatic->fetch($object->user_modification_id ? $object->user_modification_id : $object->user_modification);
280
-            if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
281
-        	else print $langs->trans("Unknown");
341
+            if ($userstatic->id) {
342
+                print $userstatic->getNomUrl(1, '', 0, 0, 0);
343
+            } else {
344
+        	    print $langs->trans("Unknown");
345
+        	}
282 346
         }
283
-        if ($usetable) print '</td></tr>';
284
-        else print '<br>';
347
+        if ($usetable) {
348
+            print '</td></tr>';
349
+        } else {
350
+            print '<br>';
351
+        }
285 352
     }
286 353
 
287 354
     // Date change
288 355
     if (! empty($object->date_modification))
289 356
     {
290
-        if ($usetable) print '<tr><td class="titlefield">';
357
+        if ($usetable) {
358
+            print '<tr><td class="titlefield">';
359
+        }
291 360
         print $langs->trans("DateLastModification");
292
-        if ($usetable) print '</td><td>';
293
-        else print ': ';
361
+        if ($usetable) {
362
+            print '</td><td>';
363
+        } else {
364
+            print ': ';
365
+        }
294 366
         print dol_print_date($object->date_modification, 'dayhour');
295
-        if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' &nbsp; / &nbsp; '.dol_print_date($object->date_modification+($deltadateforuser*3600),"dayhour").' &nbsp;'.$langs->trans("ClientHour");
296
-        if ($usetable) print '</td></tr>';
297
-        else print '<br>';
367
+        if ($deltadateforuser) {
368
+            print ' '.$langs->trans("CurrentHour").' &nbsp; / &nbsp; '.dol_print_date($object->date_modification+($deltadateforuser*3600),"dayhour").' &nbsp;'.$langs->trans("ClientHour");
369
+        }
370
+        if ($usetable) {
371
+            print '</td></tr>';
372
+        } else {
373
+            print '<br>';
374
+        }
298 375
     }
299 376
 
300 377
     // User validation (old method using already loaded object and not id is kept for backward compatibility)
301 378
     if (! empty($object->user_validation) || ! empty($object->user_validation_id))
302 379
     {
303
-        if ($usetable) print '<tr><td class="titlefield">';
380
+        if ($usetable) {
381
+            print '<tr><td class="titlefield">';
382
+        }
304 383
         print $langs->trans("ValidatedBy");
305
-        if ($usetable) print '</td><td>';
306
-        else print ': ';
384
+        if ($usetable) {
385
+            print '</td><td>';
386
+        } else {
387
+            print ': ';
388
+        }
307 389
         if (is_object($object->user_validation))
308 390
         {
309
-            if ($object->user_validation->id) print $object->user_validation->getNomUrl(1, '', 0, 0, 0);
310
-        	else print $langs->trans("Unknown");
311
-        }
312
-        else
391
+            if ($object->user_validation->id) {
392
+                print $object->user_validation->getNomUrl(1, '', 0, 0, 0);
393
+            } else {
394
+        	    print $langs->trans("Unknown");
395
+        	}
396
+        } else
313 397
         {
314 398
             $userstatic=new User($db);
315 399
             $userstatic->fetch($object->user_validation_id ? $object->user_validation_id : $object->user_validation);
316
-			if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
317
-        	else print $langs->trans("Unknown");
400
+			if ($userstatic->id) {
401
+			    print $userstatic->getNomUrl(1, '', 0, 0, 0);
402
+			} else {
403
+        	    print $langs->trans("Unknown");
404
+        	}
318 405
         }
319
-        if ($usetable) print '</td></tr>';
320
-        else print '<br>';
406
+        if ($usetable) {
407
+            print '</td></tr>';
408
+        } else {
409
+            print '<br>';
410
+        }
321 411
     }
322 412
 
323 413
     // Date validation
324 414
     if (! empty($object->date_validation))
325 415
     {
326
-        if ($usetable) print '<tr><td class="titlefield">';
416
+        if ($usetable) {
417
+            print '<tr><td class="titlefield">';
418
+        }
327 419
         print $langs->trans("DateValidation");
328
-        if ($usetable) print '</td><td>';
329
-        else print ': ';
420
+        if ($usetable) {
421
+            print '</td><td>';
422
+        } else {
423
+            print ': ';
424
+        }
330 425
         print dol_print_date($object->date_validation, 'dayhour');
331
-        if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' &nbsp; / &nbsp; '.dol_print_date($object->date_validation+($deltadateforuser*3600),"dayhour").' &nbsp;'.$langs->trans("ClientHour");
332
-        if ($usetable) print '</td></tr>';
333
-        else print '<br>';
426
+        if ($deltadateforuser) {
427
+            print ' '.$langs->trans("CurrentHour").' &nbsp; / &nbsp; '.dol_print_date($object->date_validation+($deltadateforuser*3600),"dayhour").' &nbsp;'.$langs->trans("ClientHour");
428
+        }
429
+        if ($usetable) {
430
+            print '</td></tr>';
431
+        } else {
432
+            print '<br>';
433
+        }
334 434
     }
335 435
 
336 436
     // User approve (old method using already loaded object and not id is kept for backward compatibility)
337 437
     if (! empty($object->user_approve) || ! empty($object->user_approve_id))
338 438
     {
339
-        if ($usetable) print '<tr><td class="titlefield">';
439
+        if ($usetable) {
440
+            print '<tr><td class="titlefield">';
441
+        }
340 442
         print $langs->trans("ApprovedBy");
341
-        if ($usetable) print '</td><td>';
342
-        else print ': ';
443
+        if ($usetable) {
444
+            print '</td><td>';
445
+        } else {
446
+            print ': ';
447
+        }
343 448
         if (is_object($object->user_approve))
344 449
         {
345
-            if ($object->user_approve->id) print $object->user_approve->getNomUrl(1, '', 0, 0, 0);
346
-        	else print $langs->trans("Unknown");
347
-        }
348
-        else
450
+            if ($object->user_approve->id) {
451
+                print $object->user_approve->getNomUrl(1, '', 0, 0, 0);
452
+            } else {
453
+        	    print $langs->trans("Unknown");
454
+        	}
455
+        } else
349 456
         {
350 457
             $userstatic=new User($db);
351 458
             $userstatic->fetch($object->user_approve_id ? $object->user_approve_id : $object->user_approve);
352
-			if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
353
-        	else print $langs->trans("Unknown");
459
+			if ($userstatic->id) {
460
+			    print $userstatic->getNomUrl(1, '', 0, 0, 0);
461
+			} else {
462
+        	    print $langs->trans("Unknown");
463
+        	}
354 464
         }
355
-        if ($usetable) print '</td></tr>';
356
-        else print '<br>';
465
+        if ($usetable) {
466
+            print '</td></tr>';
467
+        } else {
468
+            print '<br>';
469
+        }
357 470
     }
358 471
 
359 472
     // Date approve
360 473
     if (! empty($object->date_approve))
361 474
     {
362
-        if ($usetable) print '<tr><td class="titlefield">';
475
+        if ($usetable) {
476
+            print '<tr><td class="titlefield">';
477
+        }
363 478
         print $langs->trans("DateApprove");
364
-        if ($usetable) print '</td><td>';
365
-        else print ': ';
479
+        if ($usetable) {
480
+            print '</td><td>';
481
+        } else {
482
+            print ': ';
483
+        }
366 484
         print dol_print_date($object->date_approve, 'dayhour');
367
-        if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' &nbsp; / &nbsp; '.dol_print_date($object->date_approve+($deltadateforuser*3600),"dayhour").' &nbsp;'.$langs->trans("ClientHour");
368
-        if ($usetable) print '</td></tr>';
369
-        else print '<br>';
485
+        if ($deltadateforuser) {
486
+            print ' '.$langs->trans("CurrentHour").' &nbsp; / &nbsp; '.dol_print_date($object->date_approve+($deltadateforuser*3600),"dayhour").' &nbsp;'.$langs->trans("ClientHour");
487
+        }
488
+        if ($usetable) {
489
+            print '</td></tr>';
490
+        } else {
491
+            print '<br>';
492
+        }
370 493
     }
371 494
 
372 495
     // User approve
373 496
     if (! empty($object->user_approve_id2))
374 497
     {
375
-        if ($usetable) print '<tr><td class="titlefield">';
498
+        if ($usetable) {
499
+            print '<tr><td class="titlefield">';
500
+        }
376 501
         print $langs->trans("ApprovedBy");
377
-        if ($usetable) print '</td><td>';
378
-        else print ': ';
502
+        if ($usetable) {
503
+            print '</td><td>';
504
+        } else {
505
+            print ': ';
506
+        }
379 507
         $userstatic=new User($db);
380 508
         $userstatic->fetch($object->user_approve_id2);
381
-        if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
382
-        else print $langs->trans("Unknown");
383
-        if ($usetable) print '</td></tr>';
384
-        else print '<br>';
509
+        if ($userstatic->id) {
510
+            print $userstatic->getNomUrl(1, '', 0, 0, 0);
511
+        } else {
512
+            print $langs->trans("Unknown");
513
+        }
514
+        if ($usetable) {
515
+            print '</td></tr>';
516
+        } else {
517
+            print '<br>';
518
+        }
385 519
     }
386 520
 
387 521
     // Date approve
388 522
     if (! empty($object->date_approve2))
389 523
     {
390
-        if ($usetable) print '<tr><td class="titlefield">';
524
+        if ($usetable) {
525
+            print '<tr><td class="titlefield">';
526
+        }
391 527
         print $langs->trans("DateApprove2");
392
-        if ($usetable) print '</td><td>';
393
-        else print ': ';
528
+        if ($usetable) {
529
+            print '</td><td>';
530
+        } else {
531
+            print ': ';
532
+        }
394 533
         print dol_print_date($object->date_approve2, 'dayhour');
395
-        if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' &nbsp; / &nbsp; '.dol_print_date($object->date_approve2+($deltadateforuser*3600),"dayhour").' &nbsp;'.$langs->trans("ClientHour");
396
-        if ($usetable) print '</td></tr>';
397
-        else print '<br>';
534
+        if ($deltadateforuser) {
535
+            print ' '.$langs->trans("CurrentHour").' &nbsp; / &nbsp; '.dol_print_date($object->date_approve2+($deltadateforuser*3600),"dayhour").' &nbsp;'.$langs->trans("ClientHour");
536
+        }
537
+        if ($usetable) {
538
+            print '</td></tr>';
539
+        } else {
540
+            print '<br>';
541
+        }
398 542
     }
399 543
 
400 544
     // User close
401 545
     if (! empty($object->user_cloture))
402 546
     {
403
-        if ($usetable) print '<tr><td class="titlefield">';
547
+        if ($usetable) {
548
+            print '<tr><td class="titlefield">';
549
+        }
404 550
         print $langs->trans("ClosedBy");
405
-        if ($usetable) print '</td><td>';
406
-        else print ': ';
551
+        if ($usetable) {
552
+            print '</td><td>';
553
+        } else {
554
+            print ': ';
555
+        }
407 556
         if (is_object($object->user_cloture))
408 557
         {
409
-			if ($object->user_cloture->id) print $object->user_cloture->getNomUrl(1, '', 0, 0, 0);
410
-        	else print $langs->trans("Unknown");
411
-        }
412
-        else
558
+			if ($object->user_cloture->id) {
559
+			    print $object->user_cloture->getNomUrl(1, '', 0, 0, 0);
560
+			} else {
561
+        	    print $langs->trans("Unknown");
562
+        	}
563
+        } else
413 564
         {
414 565
             $userstatic=new User($db);
415 566
             $userstatic->fetch($object->user_cloture);
416
-			if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
417
-        	else print $langs->trans("Unknown");
567
+			if ($userstatic->id) {
568
+			    print $userstatic->getNomUrl(1, '', 0, 0, 0);
569
+			} else {
570
+        	    print $langs->trans("Unknown");
571
+        	}
418 572
         }
419
-        if ($usetable) print '</td></tr>';
420
-        else print '<br>';
573
+        if ($usetable) {
574
+            print '</td></tr>';
575
+        } else {
576
+            print '<br>';
577
+        }
421 578
     }
422 579
 
423 580
     // Date close
424 581
     if (! empty($object->date_cloture))
425 582
     {
426
-        if ($usetable) print '<tr><td class="titlefield">';
583
+        if ($usetable) {
584
+            print '<tr><td class="titlefield">';
585
+        }
427 586
         print $langs->trans("DateClosing");
428
-        if ($usetable) print '</td><td>';
429
-        else print ': ';
587
+        if ($usetable) {
588
+            print '</td><td>';
589
+        } else {
590
+            print ': ';
591
+        }
430 592
         print dol_print_date($object->date_cloture, 'dayhour');
431
-        if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' &nbsp; / &nbsp; '.dol_print_date($object->date_cloture+($deltadateforuser*3600),"dayhour").' &nbsp;'.$langs->trans("ClientHour");
432
-        if ($usetable) print '</td></tr>';
433
-        else print '<br>';
593
+        if ($deltadateforuser) {
594
+            print ' '.$langs->trans("CurrentHour").' &nbsp; / &nbsp; '.dol_print_date($object->date_cloture+($deltadateforuser*3600),"dayhour").' &nbsp;'.$langs->trans("ClientHour");
595
+        }
596
+        if ($usetable) {
597
+            print '</td></tr>';
598
+        } else {
599
+            print '<br>';
600
+        }
434 601
     }
435 602
 
436 603
     // User conciliate
437 604
     if (! empty($object->user_rappro))
438 605
     {
439
-        if ($usetable) print '<tr><td class="titlefield">';
606
+        if ($usetable) {
607
+            print '<tr><td class="titlefield">';
608
+        }
440 609
         print $langs->trans("ConciliatedBy");
441
-        if ($usetable) print '</td><td>';
442
-        else print ': ';
610
+        if ($usetable) {
611
+            print '</td><td>';
612
+        } else {
613
+            print ': ';
614
+        }
443 615
         if (is_object($object->user_rappro))
444 616
         {
445
-			if ($object->user_rappro->id) print $object->user_rappro->getNomUrl(1, '', 0, 0, 0);
446
-        	else print $langs->trans("Unknown");
447
-        }
448
-        else
617
+			if ($object->user_rappro->id) {
618
+			    print $object->user_rappro->getNomUrl(1, '', 0, 0, 0);
619
+			} else {
620
+        	    print $langs->trans("Unknown");
621
+        	}
622
+        } else
449 623
         {
450 624
             $userstatic=new User($db);
451 625
             $userstatic->fetch($object->user_rappro);
452
-			if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
453
-        	else print $langs->trans("Unknown");
626
+			if ($userstatic->id) {
627
+			    print $userstatic->getNomUrl(1, '', 0, 0, 0);
628
+			} else {
629
+        	    print $langs->trans("Unknown");
630
+        	}
454 631
         }
455
-        if ($usetable) print '</td></tr>';
456
-        else print '<br>';
632
+        if ($usetable) {
633
+            print '</td></tr>';
634
+        } else {
635
+            print '<br>';
636
+        }
457 637
     }
458 638
 
459 639
     // Date conciliate
460 640
     if (! empty($object->date_rappro))
461 641
     {
462
-        if ($usetable) print '<tr><td class="titlefield">';
642
+        if ($usetable) {
643
+            print '<tr><td class="titlefield">';
644
+        }
463 645
         print $langs->trans("DateConciliating");
464
-        if ($usetable) print '</td><td>';
465
-        else print ': ';
646
+        if ($usetable) {
647
+            print '</td><td>';
648
+        } else {
649
+            print ': ';
650
+        }
466 651
         print dol_print_date($object->date_rappro, 'dayhour');
467
-        if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' &nbsp; / &nbsp; '.dol_print_date($object->date_rappro+($deltadateforuser*3600),"dayhour").' &nbsp;'.$langs->trans("ClientHour");
468
-        if ($usetable) print '</td></tr>';
469
-        else print '<br>';
652
+        if ($deltadateforuser) {
653
+            print ' '.$langs->trans("CurrentHour").' &nbsp; / &nbsp; '.dol_print_date($object->date_rappro+($deltadateforuser*3600),"dayhour").' &nbsp;'.$langs->trans("ClientHour");
654
+        }
655
+        if ($usetable) {
656
+            print '</td></tr>';
657
+        } else {
658
+            print '<br>';
659
+        }
470 660
     }
471 661
 
472 662
     // Date send
473 663
     if (! empty($object->date_envoi))
474 664
     {
475
-        if ($usetable) print '<tr><td class="titlefield">';
665
+        if ($usetable) {
666
+            print '<tr><td class="titlefield">';
667
+        }
476 668
         print $langs->trans("DateLastSend");
477
-        if ($usetable) print '</td><td>';
478
-        else print ': ';
669
+        if ($usetable) {
670
+            print '</td><td>';
671
+        } else {
672
+            print ': ';
673
+        }
479 674
         print dol_print_date($object->date_envoi, 'dayhour');
480
-        if ($deltadateforuser) print ' '.$langs->trans("CurrentHour").' &nbsp; / &nbsp; '.dol_print_date($object->date_envoi+($deltadateforuser*3600),"dayhour").' &nbsp;'.$langs->trans("ClientHour");
481
-        if ($usetable) print '</td></tr>';
482
-        else print '<br>';
675
+        if ($deltadateforuser) {
676
+            print ' '.$langs->trans("CurrentHour").' &nbsp; / &nbsp; '.dol_print_date($object->date_envoi+($deltadateforuser*3600),"dayhour").' &nbsp;'.$langs->trans("ClientHour");
677
+        }
678
+        if ($usetable) {
679
+            print '</td></tr>';
680
+        } else {
681
+            print '<br>';
682
+        }
483 683
     }
484 684
 
485
-    if ($usetable) print '</table>';
486
-}
685
+    if ($usetable) {
686
+        print '</table>';
687
+    }
688
+    }
487 689
 
488 690
 
489 691
 /**
@@ -512,8 +714,7 @@  discard block
 block discarded – undo
512 714
     if (checkdnsrr($domain, "MX"))
513 715
     {
514 716
         return true;
515
-    }
516
-    else
717
+    } else
517 718
     {
518 719
         return false;
519 720
     }
@@ -538,10 +739,14 @@  discard block
 block discarded – undo
538 739
     $urlregex = '';
539 740
 
540 741
     // SCHEME
541
-    if ($http) $urlregex .= "^(http:\/\/|https:\/\/)";
742
+    if ($http) {
743
+        $urlregex .= "^(http:\/\/|https:\/\/)";
744
+    }
542 745
 
543 746
     // USER AND PASS
544
-    if ($pass) $urlregex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)";
747
+    if ($pass) {
748
+        $urlregex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)";
749
+    }
545 750
 
546 751
     // HOSTNAME OR IP
547 752
     //$urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*";  // x allowed (ex. http://localhost, http://routerlogin)
@@ -550,13 +755,21 @@  discard block
 block discarded – undo
550 755
     //use only one of the above
551 756
 
552 757
     // PORT
553
-    if ($port) $urlregex .= "(\:[0-9]{2,5})";
758
+    if ($port) {
759
+        $urlregex .= "(\:[0-9]{2,5})";
760
+    }
554 761
     // PATH
555
-    if ($path) $urlregex .= "(\/([a-z0-9+\$_-]\.?)+)*\/";
762
+    if ($path) {
763
+        $urlregex .= "(\/([a-z0-9+\$_-]\.?)+)*\/";
764
+    }
556 765
     // GET Query
557
-    if ($query) $urlregex .= "(\?[a-z+&\$_.-][a-z0-9;:@\/&%=+\$_.-]*)";
766
+    if ($query) {
767
+        $urlregex .= "(\?[a-z+&\$_.-][a-z0-9;:@\/&%=+\$_.-]*)";
768
+    }
558 769
     // ANCHOR
559
-    if ($anchor) $urlregex .= "(#[a-z_.-][a-z0-9+\$_.-]*)$";
770
+    if ($anchor) {
771
+        $urlregex .= "(#[a-z_.-][a-z0-9+\$_.-]*)$";
772
+    }
560 773
 
561 774
     // check
562 775
     if (preg_match('/'.$urlregex.'/i', $url))
@@ -604,9 +817,10 @@  discard block
 block discarded – undo
604 817
         $CleanUrl = preg_replace('/^'.preg_quote($proto.$domain,'/').'/i', $newproto.strtolower($domain), $url);
605 818
 
606 819
         return $CleanUrl;
820
+    } else {
821
+        return $url;
822
+    }
607 823
     }
608
-    else return $url;
609
-}
610 824
 
611 825
 
612 826
 
@@ -623,7 +837,9 @@  discard block
 block discarded – undo
623 837
  */
624 838
 function dolObfuscateEmail($mail, $replace="*", $nbreplace=8, $nbdisplaymail=4, $nbdisplaydomain=3, $displaytld=true)
625 839
 {
626
-	if(!isValidEmail($mail))return '';
840
+	if(!isValidEmail($mail)) {
841
+	    return '';
842
+	}
627 843
 	$tab = explode('@', $mail);
628 844
 	$tab2 = explode('.',$tab[1]);
629 845
 	$string_replace = '';
@@ -685,7 +901,9 @@  discard block
 block discarded – undo
685 901
 function array2table($data,$tableMarkup=1,$tableoptions='',$troptions='',$tdoptions='')
686 902
 {
687 903
     $text='' ;
688
-    if($tableMarkup) $text = '<table '.$tableoptions.'>' ;
904
+    if($tableMarkup) {
905
+        $text = '<table '.$tableoptions.'>' ;
906
+    }
689 907
     foreach($data as $key => $item){
690 908
         if(is_array($item)){
691 909
             $text.=array2tr($item,$troptions,$tdoptions);
@@ -696,7 +914,9 @@  discard block
 block discarded – undo
696 914
             $text.= '</tr>' ;
697 915
         }
698 916
     }
699
-    if($tableMarkup) $text.= '</table>' ;
917
+    if($tableMarkup) {
918
+        $text.= '</table>' ;
919
+    }
700 920
     return $text ;
701 921
 }
702 922
 
@@ -720,15 +940,25 @@  discard block
 block discarded – undo
720 940
 {
721 941
     global $conf,$user;
722 942
 
723
-    if (! is_object($objsoc)) $valueforccc=$objsoc;
724
-    else if ($table == "commande_fournisseur" || $table == "facture_fourn" ) $valueforccc=$objsoc->code_fournisseur;
725
-    else $valueforccc=$objsoc->code_client;
943
+    if (! is_object($objsoc)) {
944
+        $valueforccc=$objsoc;
945
+    } else if ($table == "commande_fournisseur" || $table == "facture_fourn" ) {
946
+        $valueforccc=$objsoc->code_fournisseur;
947
+    } else {
948
+        $valueforccc=$objsoc->code_client;
949
+    }
726 950
 
727 951
     $sharetable = $table;
728
-    if ($table == 'facture' || $table == 'invoice') $sharetable = 'invoicenumber'; // for getEntity function
952
+    if ($table == 'facture' || $table == 'invoice') {
953
+        $sharetable = 'invoicenumber';
954
+    }
955
+    // for getEntity function
729 956
 
730 957
     // Clean parameters
731
-    if ($date == '') $date=dol_now();	// We use local year and month of PHP server to search numbers
958
+    if ($date == '') {
959
+        $date=dol_now();
960
+    }
961
+    // We use local year and month of PHP server to search numbers
732 962
     // but we should use local year and month of user
733 963
 
734 964
     // For debugging
@@ -745,8 +975,7 @@  discard block
 block discarded – undo
745 975
         $masktri=$reg[1].(! empty($reg[2])?$reg[2]:'').(! empty($reg[3])?$reg[3]:'');
746 976
         $maskcounter=$reg[1];
747 977
         $hasglobalcounter=true;
748
-    }
749
-    else
978
+    } else
750 979
     {
751 980
         // setting some defaults so the rest of the code won't fail if there is a third party counter
752 981
         $masktri='00000';
@@ -756,7 +985,9 @@  discard block
 block discarded – undo
756 985
     $maskraz=-1;
757 986
     $maskoffset=0;
758 987
     $resetEveryMonth=false;
759
-    if (dol_strlen($maskcounter) < 3 && empty($conf->global->MAIN_COUNTER_WITH_LESS_3_DIGITS)) return 'ErrorCounterMustHaveMoreThan3Digits';
988
+    if (dol_strlen($maskcounter) < 3 && empty($conf->global->MAIN_COUNTER_WITH_LESS_3_DIGITS)) {
989
+        return 'ErrorCounterMustHaveMoreThan3Digits';
990
+    }
760 991
 
761 992
     // Extract value for third party mask counter
762 993
     if (preg_match('/\{(c+)(0*)\}/i',$mask,$regClientRef))
@@ -768,9 +999,12 @@  discard block
 block discarded – undo
768 999
         $maskrefclient_clientcode=substr($valueforccc,0,dol_strlen($maskrefclient_maskclientcode));//get n first characters of client code where n is length in mask
769 1000
         $maskrefclient_clientcode=str_pad($maskrefclient_clientcode,dol_strlen($maskrefclient_maskclientcode),"#",STR_PAD_RIGHT);//padding maskrefclient_clientcode for having exactly n characters in maskrefclient_clientcode
770 1001
         $maskrefclient_clientcode=dol_string_nospecial($maskrefclient_clientcode);//sanitize maskrefclient_clientcode for sql insert and sql select like
771
-        if (dol_strlen($maskrefclient_maskcounter) > 0 && dol_strlen($maskrefclient_maskcounter) < 3) return 'ErrorCounterMustHaveMoreThan3Digits';
772
-    }
773
-    else $maskrefclient='';
1002
+        if (dol_strlen($maskrefclient_maskcounter) > 0 && dol_strlen($maskrefclient_maskcounter) < 3) {
1003
+            return 'ErrorCounterMustHaveMoreThan3Digits';
1004
+        }
1005
+    } else {
1006
+        $maskrefclient='';
1007
+    }
774 1008
 
775 1009
     // fail if there is neither a global nor a third party counter
776 1010
     if (! $hasglobalcounter && ($maskrefclient_maskcounter == ''))
@@ -784,8 +1018,7 @@  discard block
 block discarded – undo
784 1018
         $masktype=$regType[1];
785 1019
         $masktype_value=substr(preg_replace('/^TE_/','',$objsoc->typent_code),0,dol_strlen($regType[1]));// get n first characters of thirdpaty typent_code (where n is length in mask)
786 1020
         $masktype_value=str_pad($masktype_value,dol_strlen($regType[1]),"#",STR_PAD_RIGHT);				 // we fill on right with # to have same number of char than into mask
787
-    }
788
-    else
1021
+    } else
789 1022
     {
790 1023
     	$masktype='';
791 1024
     	$masktype_value='';
@@ -795,13 +1028,14 @@  discard block
 block discarded – undo
795 1028
     if (preg_match('/\{(u+)\}/i',$mask,$regType))
796 1029
     {
797 1030
     	$lastname = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
798
-    	if (is_object($objuser)) $lastname = $objuser->lastname;
1031
+    	if (is_object($objuser)) {
1032
+    	    $lastname = $objuser->lastname;
1033
+    	}
799 1034
 
800 1035
     	$maskuser=$regType[1];
801 1036
     	$maskuser_value=substr($lastname,0,dol_strlen($regType[1]));// get n first characters of user firstname (where n is length in mask)
802 1037
     	$maskuser_value=str_pad($maskuser_value,dol_strlen($regType[1]),"#",STR_PAD_RIGHT);				 // we fill on right with # to have same number of char than into mask
803
-    }
804
-    else
1038
+    } else
805 1039
     {
806 1040
     	$maskuser='';
807 1041
     	$maskuser_value='';
@@ -848,8 +1082,12 @@  discard block
 block discarded – undo
848 1082
     //var_dump($reg);
849 1083
 
850 1084
     // If an offset is asked
851
-    if (! empty($reg[2]) && preg_match('/^\+/',$reg[2])) $maskoffset=preg_replace('/^\+/','',$reg[2]);
852
-    if (! empty($reg[3]) && preg_match('/^\+/',$reg[3])) $maskoffset=preg_replace('/^\+/','',$reg[3]);
1085
+    if (! empty($reg[2]) && preg_match('/^\+/',$reg[2])) {
1086
+        $maskoffset=preg_replace('/^\+/','',$reg[2]);
1087
+    }
1088
+    if (! empty($reg[3]) && preg_match('/^\+/',$reg[3])) {
1089
+        $maskoffset=preg_replace('/^\+/','',$reg[3]);
1090
+    }
853 1091
 
854 1092
     // Define $sqlwhere
855 1093
     $sqlwhere='';
@@ -857,14 +1095,21 @@  discard block
 block discarded – undo
857 1095
     $yearoffsettype=false;		// false: no reset, 0,-,=,+: reset at offset SOCIETE_FISCAL_MONTH_START, x=reset at offset x
858 1096
 
859 1097
     // If a restore to zero after a month is asked we check if there is already a value for this year.
860
-    if (! empty($reg[2]) && preg_match('/^@/',$reg[2]))	$yearoffsettype = preg_replace('/^@/','',$reg[2]);
861
-    if (! empty($reg[3]) && preg_match('/^@/',$reg[3]))	$yearoffsettype = preg_replace('/^@/','',$reg[3]);
1098
+    if (! empty($reg[2]) && preg_match('/^@/',$reg[2])) {
1099
+        $yearoffsettype = preg_replace('/^@/','',$reg[2]);
1100
+    }
1101
+    if (! empty($reg[3]) && preg_match('/^@/',$reg[3])) {
1102
+        $yearoffsettype = preg_replace('/^@/','',$reg[3]);
1103
+    }
862 1104
 
863 1105
     //print "yearoffset=".$yearoffset." yearoffsettype=".$yearoffsettype;
864
-    if (is_numeric($yearoffsettype) && $yearoffsettype >= 1)
865
-        $maskraz=$yearoffsettype; // For backward compatibility
866
-    else if ($yearoffsettype === '0' || (! empty($yearoffsettype) && ! is_numeric($yearoffsettype) && $conf->global->SOCIETE_FISCAL_MONTH_START > 1))
867
-        $maskraz = $conf->global->SOCIETE_FISCAL_MONTH_START;
1106
+    if (is_numeric($yearoffsettype) && $yearoffsettype >= 1) {
1107
+            $maskraz=$yearoffsettype;
1108
+    }
1109
+    // For backward compatibility
1110
+    else if ($yearoffsettype === '0' || (! empty($yearoffsettype) && ! is_numeric($yearoffsettype) && $conf->global->SOCIETE_FISCAL_MONTH_START > 1)) {
1111
+            $maskraz = $conf->global->SOCIETE_FISCAL_MONTH_START;
1112
+    }
868 1113
     //print "maskraz=".$maskraz;	// -1=no reset
869 1114
 
870 1115
     if ($maskraz > 0) {   // A reset is required
@@ -872,23 +1117,28 @@  discard block
 block discarded – undo
872 1117
             $maskraz = date('m', $date);
873 1118
             $resetEveryMonth = true;
874 1119
         }
875
-        if ($maskraz > 12) return 'ErrorBadMaskBadRazMonth';
1120
+        if ($maskraz > 12) {
1121
+            return 'ErrorBadMaskBadRazMonth';
1122
+        }
876 1123
 
877 1124
         // Define posy, posm and reg
878
-        if ($maskraz > 1)	// if reset is not first month, we need month and year into mask
1125
+        if ($maskraz > 1) {
1126
+            // if reset is not first month, we need month and year into mask
879 1127
         {
880
-            if (preg_match('/^(.*)\{(y+)\}\{(m+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2; $posm=3; }
881
-            elseif (preg_match('/^(.*)\{(m+)\}\{(y+)\}/i',$maskwithonlyymcode,$reg)) { $posy=3; $posm=2; }
882
-            else return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
883
-
884
-            if (dol_strlen($reg[$posy]) < 2) return 'ErrorCantUseRazWithYearOnOneDigit';
885
-        }
886
-        else // if reset is for a specific month in year, we need year
1128
+            if (preg_match('/^(.*)\{(y+)\}\{(m+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2;
1129
+        }
1130
+        $posm=3; } elseif (preg_match('/^(.*)\{(m+)\}\{(y+)\}/i',$maskwithonlyymcode,$reg)) { $posy=3; $posm=2; } else {
1131
+                return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
1132
+            }
1133
+
1134
+            if (dol_strlen($reg[$posy]) < 2) {
1135
+                return 'ErrorCantUseRazWithYearOnOneDigit';
1136
+            }
1137
+        } else // if reset is for a specific month in year, we need year
887 1138
         {
888
-            if (preg_match('/^(.*)\{(m+)\}\{(y+)\}/i',$maskwithonlyymcode,$reg)) { $posy=3; $posm=2; }
889
-        	else if (preg_match('/^(.*)\{(y+)\}\{(m+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2; $posm=3; }
890
-            else if (preg_match('/^(.*)\{(y+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2; $posm=0; }
891
-            else return 'ErrorCantUseRazIfNoYearInMask';
1139
+            if (preg_match('/^(.*)\{(m+)\}\{(y+)\}/i',$maskwithonlyymcode,$reg)) { $posy=3; $posm=2; } else if (preg_match('/^(.*)\{(y+)\}\{(m+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2; $posm=3; } else if (preg_match('/^(.*)\{(y+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2; $posm=0; } else {
1140
+                return 'ErrorCantUseRazIfNoYearInMask';
1141
+            }
892 1142
         }
893 1143
         // Define length
894 1144
         $yearlen = $posy?dol_strlen($reg[$posy]):0;
@@ -906,9 +1156,11 @@  discard block
 block discarded – undo
906 1156
         $monthcomp=$maskraz;
907 1157
         $yearcomp=0;
908 1158
 
909
-        if (! empty($yearoffsettype) && ! is_numeric($yearoffsettype) && $yearoffsettype != '=')	// $yearoffsettype is - or +
1159
+        if (! empty($yearoffsettype) && ! is_numeric($yearoffsettype) && $yearoffsettype != '=') {
1160
+            // $yearoffsettype is - or +
910 1161
         {
911
-        	$currentyear=date("Y", $date);
1162
+        	$currentyear=date("Y", $date);
1163
+        }
912 1164
         	$fiscaldate=dol_mktime('0','0','0',$maskraz,'1',$currentyear);
913 1165
         	$newyeardate=dol_mktime('0','0','0','1','1',$currentyear);
914 1166
         	$nextnewyeardate=dol_mktime('0','0','0','1','1',$currentyear+1);
@@ -918,21 +1170,32 @@  discard block
 block discarded – undo
918 1170
         	if ($date >= $fiscaldate)
919 1171
         	{
920 1172
         		// If before of next new year date
921
-        		if ($date < $nextnewyeardate && $yearoffsettype == '+') $yearoffset=1;
1173
+        		if ($date < $nextnewyeardate && $yearoffsettype == '+') {
1174
+        		    $yearoffset=1;
1175
+        		}
922 1176
         	}
923 1177
         	// If after or equal of current new year date
924
-        	else if ($date >= $newyeardate && $yearoffsettype == '-') $yearoffset=-1;
1178
+        	else if ($date >= $newyeardate && $yearoffsettype == '-') {
1179
+        	    $yearoffset=-1;
1180
+        	}
925 1181
         }
926 1182
         // For backward compatibility
927 1183
         else if (date("m",$date) < $maskraz && empty($resetEveryMonth)) { $yearoffset=-1; }	// If current month lower that month of return to zero, year is previous year
928 1184
 
929
-        if ($yearlen == 4) $yearcomp=sprintf("%04d",date("Y",$date)+$yearoffset);
930
-        elseif ($yearlen == 2) $yearcomp=sprintf("%02d",date("y",$date)+$yearoffset);
931
-        elseif ($yearlen == 1) $yearcomp=substr(date("y",$date),2,1)+$yearoffset;
932
-        if ($monthcomp > 1 && empty($resetEveryMonth))	// Test with month is useless if monthcomp = 0 or 1 (0 is same as 1) (regis: $monthcomp can't equal 0)
1185
+        if ($yearlen == 4) {
1186
+            $yearcomp=sprintf("%04d",date("Y",$date)+$yearoffset);
1187
+        } elseif ($yearlen == 2) {
1188
+            $yearcomp=sprintf("%02d",date("y",$date)+$yearoffset);
1189
+        } elseif ($yearlen == 1) {
1190
+            $yearcomp=substr(date("y",$date),2,1)+$yearoffset;
1191
+        }
1192
+        if ($monthcomp > 1 && empty($resetEveryMonth)) {
1193
+            // Test with month is useless if monthcomp = 0 or 1 (0 is same as 1) (regis: $monthcomp can't equal 0)
933 1194
         {
934
-            if ($yearlen == 4) $yearcomp1=sprintf("%04d",date("Y",$date)+$yearoffset+1);
935
-            elseif ($yearlen == 2) $yearcomp1=sprintf("%02d",date("y",$date)+$yearoffset+1);
1195
+            if ($yearlen == 4) $yearcomp1=sprintf("%04d",date("Y",$date)+$yearoffset+1);
1196
+        } elseif ($yearlen == 2) {
1197
+                $yearcomp1=sprintf("%02d",date("y",$date)+$yearoffset+1);
1198
+            }
936 1199
 
937 1200
             $sqlwhere.="(";
938 1201
             $sqlwhere.=" (SUBSTRING(".$field.", ".$yearpos.", ".$yearlen.") = '".$yearcomp."'";
@@ -941,13 +1204,11 @@  discard block
 block discarded – undo
941 1204
             $sqlwhere.=" (SUBSTRING(".$field.", ".$yearpos.", ".$yearlen.") = '".$yearcomp1."'";
942 1205
             $sqlwhere.=" AND SUBSTRING(".$field.", ".$monthpos.", ".$monthlen.") < '".str_pad($monthcomp, $monthlen, '0', STR_PAD_LEFT)."') ";
943 1206
             $sqlwhere.=')';
944
-        }
945
-		else if ($resetEveryMonth)
1207
+        } else if ($resetEveryMonth)
946 1208
 		{
947 1209
 			$sqlwhere.="(SUBSTRING(".$field.", ".$yearpos.", ".$yearlen.") = '".$yearcomp."'";
948 1210
             $sqlwhere.=" AND SUBSTRING(".$field.", ".$monthpos.", ".$monthlen.") = '".str_pad($monthcomp, $monthlen, '0', STR_PAD_LEFT)."')";
949
-		}
950
-        else   // reset is done on january
1211
+		} else   // reset is done on january
951 1212
         {
952 1213
             $sqlwhere.='(SUBSTRING('.$field.', '.$yearpos.', '.$yearlen.") = '".$yearcomp."')";
953 1214
         }
@@ -959,12 +1220,13 @@  discard block
 block discarded – undo
959 1220
     if (function_exists('mb_strrpos'))
960 1221
     	{
961 1222
     	$posnumstart=mb_strrpos($maskwithnocode,$maskcounter, 'UTF-8');
962
-	}
963
-	else
1223
+	} else
964 1224
 	{
965 1225
     	$posnumstart=strrpos($maskwithnocode,$maskcounter);
966 1226
 	}	// Pos of counter in final string (from 0 to ...)
967
-    if ($posnumstart < 0) return 'ErrorBadMaskFailedToLocatePosOfSequence';
1227
+    if ($posnumstart < 0) {
1228
+        return 'ErrorBadMaskFailedToLocatePosOfSequence';
1229
+    }
968 1230
     $sqlstring='SUBSTRING('.$field.', '.($posnumstart+1).', '.dol_strlen($maskcounter).')';
969 1231
 
970 1232
     // Define $maskLike
@@ -977,9 +1239,15 @@  discard block
 block discarded – undo
977 1239
     $maskLike = preg_replace('/\{mm\}/i','__',$maskLike);
978 1240
     $maskLike = preg_replace('/\{dd\}/i','__',$maskLike);
979 1241
     $maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),str_pad("",dol_strlen($maskcounter),"_"),$maskLike);
980
-    if ($maskrefclient) $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",dol_strlen($maskrefclient),"_"),$maskLike);
981
-    if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),$masktype_value,$maskLike);
982
-    if ($maskuser) $maskLike = str_replace(dol_string_nospecial('{'.$maskuser.'}'),$maskuser_value,$maskLike);
1242
+    if ($maskrefclient) {
1243
+        $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",dol_strlen($maskrefclient),"_"),$maskLike);
1244
+    }
1245
+    if ($masktype) {
1246
+        $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),$masktype_value,$maskLike);
1247
+    }
1248
+    if ($maskuser) {
1249
+        $maskLike = str_replace(dol_string_nospecial('{'.$maskuser.'}'),$maskuser_value,$maskLike);
1250
+    }
983 1251
     foreach($maskperso as $key => $val)
984 1252
     {
985 1253
     	$maskLike = str_replace(dol_string_nospecial($maskperso[$key]),$maskpersonew[$key],$maskLike);
@@ -991,12 +1259,18 @@  discard block
 block discarded – undo
991 1259
     $sql.= " FROM ".MAIN_DB_PREFIX.$table;
992 1260
     $sql.= " WHERE ".$field." LIKE '".$maskLike."'";
993 1261
 	$sql.= " AND ".$field." NOT LIKE '(PROV%)'";
994
-    if ($bentityon) // only if entity enable
995
-    	$sql.= " AND entity IN (".getEntity($sharetable).")";
996
-    else if (! empty($forceentity))
997
-    	$sql.= " AND entity IN (".$forceentity.")";
998
-    if ($where) $sql.=$where;
999
-    if ($sqlwhere) $sql.=' AND '.$sqlwhere;
1262
+    if ($bentityon) {
1263
+        // only if entity enable
1264
+    	$sql.= " AND entity IN (".getEntity($sharetable).")";
1265
+    } else if (! empty($forceentity)) {
1266
+        	$sql.= " AND entity IN (".$forceentity.")";
1267
+    }
1268
+    if ($where) {
1269
+        $sql.=$where;
1270
+    }
1271
+    if ($sqlwhere) {
1272
+        $sql.=' AND '.$sqlwhere;
1273
+    }
1000 1274
 
1001 1275
     //print $sql.'<br>';
1002 1276
     dol_syslog("functions2::get_next_value mode=".$mode."", LOG_DEBUG);
@@ -1005,21 +1279,26 @@  discard block
 block discarded – undo
1005 1279
     {
1006 1280
         $obj = $db->fetch_object($resql);
1007 1281
         $counter = $obj->val;
1008
-    }
1009
-    else dol_print_error($db);
1282
+    } else {
1283
+        dol_print_error($db);
1284
+    }
1010 1285
 
1011 1286
     // Check if we must force counter to maskoffset
1012
-    if (empty($counter)) $counter=$maskoffset;
1013
-    else if (preg_match('/[^0-9]/i',$counter))
1287
+    if (empty($counter)) {
1288
+        $counter=$maskoffset;
1289
+    } else if (preg_match('/[^0-9]/i',$counter))
1014 1290
     {
1015 1291
     	$counter=0;
1016 1292
     	dol_syslog("Error, the last counter found is '".$counter."' so is not a numeric value. We will restart to 1.", LOG_ERR);
1017
-    }
1018
-    else if ($counter < $maskoffset && empty($conf->global->MAIN_NUMBERING_OFFSET_ONLY_FOR_FIRST)) $counter=$maskoffset;
1293
+    } else if ($counter < $maskoffset && empty($conf->global->MAIN_NUMBERING_OFFSET_ONLY_FOR_FIRST)) {
1294
+        $counter=$maskoffset;
1295
+    }
1019 1296
 
1020
-    if ($mode == 'last')	// We found value for counter = last counter value. Now need to get corresponding ref of invoice.
1297
+    if ($mode == 'last') {
1298
+        // We found value for counter = last counter value. Now need to get corresponding ref of invoice.
1021 1299
     {
1022
-        $counterpadded=str_pad($counter,dol_strlen($maskcounter),"0",STR_PAD_LEFT);
1300
+        $counterpadded=str_pad($counter,dol_strlen($maskcounter),"0",STR_PAD_LEFT);
1301
+    }
1023 1302
 
1024 1303
         // Define $maskLike
1025 1304
         $maskLike = dol_string_nospecial($mask);
@@ -1031,34 +1310,48 @@  discard block
 block discarded – undo
1031 1310
         $maskLike = preg_replace('/\{mm\}/i','__',$maskLike);
1032 1311
         $maskLike = preg_replace('/\{dd\}/i','__',$maskLike);
1033 1312
         $maskLike = str_replace(dol_string_nospecial('{'.$masktri.'}'),$counterpadded,$maskLike);
1034
-        if ($maskrefclient) $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",dol_strlen($maskrefclient),"_"),$maskLike);
1035
-        if ($masktype) $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),$masktype_value,$maskLike);
1036
-        if ($maskuser) $maskLike = str_replace(dol_string_nospecial('{'.$maskuser.'}'),$maskuser_value,$maskLike);
1313
+        if ($maskrefclient) {
1314
+            $maskLike = str_replace(dol_string_nospecial('{'.$maskrefclient.'}'),str_pad("",dol_strlen($maskrefclient),"_"),$maskLike);
1315
+        }
1316
+        if ($masktype) {
1317
+            $maskLike = str_replace(dol_string_nospecial('{'.$masktype.'}'),$masktype_value,$maskLike);
1318
+        }
1319
+        if ($maskuser) {
1320
+            $maskLike = str_replace(dol_string_nospecial('{'.$maskuser.'}'),$maskuser_value,$maskLike);
1321
+        }
1037 1322
 
1038 1323
         $ref='';
1039 1324
         $sql = "SELECT ".$field." as ref";
1040 1325
         $sql.= " FROM ".MAIN_DB_PREFIX.$table;
1041 1326
         $sql.= " WHERE ".$field." LIKE '".$maskLike."'";
1042 1327
     	$sql.= " AND ".$field." NOT LIKE '%PROV%'";
1043
-    	if ($bentityon) // only if entity enable
1044
-        	$sql.= " AND entity IN (".getEntity($sharetable).")";
1045
-        else if (! empty($forceentity))
1046
-        	$sql.= " AND entity IN (".$forceentity.")";
1047
-        if ($where) $sql.=$where;
1048
-        if ($sqlwhere) $sql.=' AND '.$sqlwhere;
1328
+    	if ($bentityon) {
1329
+    	    // only if entity enable
1330
+        	$sql.= " AND entity IN (".getEntity($sharetable).")";
1331
+    	} else if (! empty($forceentity)) {
1332
+                	$sql.= " AND entity IN (".$forceentity.")";
1333
+        }
1334
+        if ($where) {
1335
+            $sql.=$where;
1336
+        }
1337
+        if ($sqlwhere) {
1338
+            $sql.=' AND '.$sqlwhere;
1339
+        }
1049 1340
 
1050 1341
         dol_syslog("functions2::get_next_value mode=".$mode."", LOG_DEBUG);
1051 1342
         $resql=$db->query($sql);
1052 1343
         if ($resql)
1053 1344
         {
1054 1345
             $obj = $db->fetch_object($resql);
1055
-            if ($obj) $ref = $obj->ref;
1056
-        }
1057
-        else dol_print_error($db);
1346
+            if ($obj) {
1347
+                $ref = $obj->ref;
1348
+            }
1349
+        } else {
1350
+            dol_print_error($db);
1351
+        }
1058 1352
 
1059 1353
         $numFinal=$ref;
1060
-    }
1061
-    else if ($mode == 'next')
1354
+    } else if ($mode == 'next')
1062 1355
     {
1063 1356
         $counter++;
1064 1357
 
@@ -1074,7 +1367,9 @@  discard block
 block discarded – undo
1074 1367
 
1075 1368
             // Define $sqlstring
1076 1369
             $maskrefclient_posnumstart=strpos($maskwithnocode,$maskrefclient_maskcounter,strpos($maskwithnocode,$maskrefclient));	// Pos of counter in final string (from 0 to ...)
1077
-            if ($maskrefclient_posnumstart <= 0) return 'ErrorBadMask';
1370
+            if ($maskrefclient_posnumstart <= 0) {
1371
+                return 'ErrorBadMask';
1372
+            }
1078 1373
             $maskrefclient_sqlstring='SUBSTRING('.$field.', '.($maskrefclient_posnumstart+1).', '.dol_strlen($maskrefclient_maskcounter).')';
1079 1374
             //print "x".$sqlstring;
1080 1375
 
@@ -1096,12 +1391,20 @@  discard block
 block discarded – undo
1096 1391
             $maskrefclient_sql.= " FROM ".MAIN_DB_PREFIX.$table;
1097 1392
             //$sql.= " WHERE ".$field." not like '(%'";
1098 1393
             $maskrefclient_sql.= " WHERE ".$field." LIKE '".$maskrefclient_maskLike."'";
1099
-            if ($bentityon) // only if entity enable
1100
-            	$maskrefclient_sql.= " AND entity IN (".getEntity($sharetable).")";
1101
-            else if (! empty($forceentity))
1102
-            	$sql.= " AND entity IN (".$forceentity.")";
1103
-            if ($where) $maskrefclient_sql.=$where; //use the same optional where as general mask
1104
-            if ($sqlwhere) $maskrefclient_sql.=' AND '.$sqlwhere; //use the same sqlwhere as general mask
1394
+            if ($bentityon) {
1395
+                // only if entity enable
1396
+            	$maskrefclient_sql.= " AND entity IN (".getEntity($sharetable).")";
1397
+            } else if (! empty($forceentity)) {
1398
+                        	$sql.= " AND entity IN (".$forceentity.")";
1399
+            }
1400
+            if ($where) {
1401
+                $maskrefclient_sql.=$where;
1402
+            }
1403
+            //use the same optional where as general mask
1404
+            if ($sqlwhere) {
1405
+                $maskrefclient_sql.=' AND '.$sqlwhere;
1406
+            }
1407
+            //use the same sqlwhere as general mask
1105 1408
             $maskrefclient_sql.=' AND (SUBSTRING('.$field.', '.(strpos($maskwithnocode,$maskrefclient)+1).', '.dol_strlen($maskrefclient_maskclientcode).")='".$maskrefclient_clientcode."')";
1106 1409
 
1107 1410
             dol_syslog("functions2::get_next_value maskrefclient", LOG_DEBUG);
@@ -1110,10 +1413,13 @@  discard block
 block discarded – undo
1110 1413
             {
1111 1414
                 $maskrefclient_obj = $db->fetch_object($maskrefclient_resql);
1112 1415
                 $maskrefclient_counter = $maskrefclient_obj->val;
1113
-            }
1114
-            else dol_print_error($db);
1416
+            } else {
1417
+                dol_print_error($db);
1418
+            }
1115 1419
 
1116
-            if (empty($maskrefclient_counter) || preg_match('/[^0-9]/i',$maskrefclient_counter)) $maskrefclient_counter=$maskrefclient_maskoffset;
1420
+            if (empty($maskrefclient_counter) || preg_match('/[^0-9]/i',$maskrefclient_counter)) {
1421
+                $maskrefclient_counter=$maskrefclient_maskoffset;
1422
+            }
1117 1423
 			$maskrefclient_counter++;
1118 1424
         }
1119 1425
 
@@ -1121,13 +1427,14 @@  discard block
 block discarded – undo
1121 1427
         $numFinal = $mask;
1122 1428
 
1123 1429
         // We replace special codes except refclient
1124
-		if (! empty($yearoffsettype) && ! is_numeric($yearoffsettype) && $yearoffsettype != '=')	// yearoffsettype is - or +, so we don't want current year
1430
+		if (! empty($yearoffsettype) && ! is_numeric($yearoffsettype) && $yearoffsettype != '=') {
1431
+		    // yearoffsettype is - or +, so we don't want current year
1125 1432
 		{
1126
-	        $numFinal = preg_replace('/\{yyyy\}/i',date("Y",$date)+$yearoffset, $numFinal);
1433
+	        $numFinal = preg_replace('/\{yyyy\}/i',date("Y",$date)+$yearoffset, $numFinal);
1434
+		}
1127 1435
         	$numFinal = preg_replace('/\{yy\}/i',  date("y",$date)+$yearoffset, $numFinal);
1128 1436
         	$numFinal = preg_replace('/\{y\}/i',   substr(date("y",$date),1,1)+$yearoffset, $numFinal);
1129
-		}
1130
-		else	// we want yyyy to be current year
1437
+		} else	// we want yyyy to be current year
1131 1438
 		{
1132 1439
         	$numFinal = preg_replace('/\{yyyy\}/i',date("Y",$date), $numFinal);
1133 1440
         	$numFinal = preg_replace('/\{yy\}/i',  date("y",$date), $numFinal);
@@ -1184,7 +1491,9 @@  discard block
 block discarded – undo
1184 1491
 {
1185 1492
     $string = " ".$string;
1186 1493
      $ini = strpos($string,$start);
1187
-     if ($ini == 0) return "";
1494
+     if ($ini == 0) {
1495
+         return "";
1496
+     }
1188 1497
      $ini += strlen($start);
1189 1498
      $len = strpos($string,$end,$ini) - $ini;
1190 1499
      return substr($string,$ini,$len);
@@ -1208,8 +1517,7 @@  discard block
 block discarded – undo
1208 1517
         $masktri=$reg[1].(isset($reg[2])?$reg[2]:'').(isset($reg[3])?$reg[3]:'');
1209 1518
         $maskcounter=$reg[1];
1210 1519
         $hasglobalcounter=true;
1211
-    }
1212
-    else
1520
+    } else
1213 1521
     {
1214 1522
         // setting some defaults so the rest of the code won't fail if there is a third party counter
1215 1523
         $masktri='00000';
@@ -1218,7 +1526,9 @@  discard block
 block discarded – undo
1218 1526
 
1219 1527
     $maskraz=-1;
1220 1528
     $maskoffset=0;
1221
-    if (dol_strlen($maskcounter) < 3) return 'ErrorCounterMustHaveMoreThan3Digits';
1529
+    if (dol_strlen($maskcounter) < 3) {
1530
+        return 'ErrorCounterMustHaveMoreThan3Digits';
1531
+    }
1222 1532
 
1223 1533
     // Extract value for third party mask counter
1224 1534
     if (preg_match('/\{(c+)(0*)\}/i',$mask,$regClientRef))
@@ -1230,9 +1540,12 @@  discard block
 block discarded – undo
1230 1540
         $maskrefclient_clientcode=substr('',0,dol_strlen($maskrefclient_maskclientcode));//get n first characters of client code to form maskrefclient_clientcode
1231 1541
         $maskrefclient_clientcode=str_pad($maskrefclient_clientcode,dol_strlen($maskrefclient_maskclientcode),"#",STR_PAD_RIGHT);//padding maskrefclient_clientcode for having exactly n characters in maskrefclient_clientcode
1232 1542
         $maskrefclient_clientcode=dol_string_nospecial($maskrefclient_clientcode);//sanitize maskrefclient_clientcode for sql insert and sql select like
1233
-        if (dol_strlen($maskrefclient_maskcounter) > 0 && dol_strlen($maskrefclient_maskcounter) < 3) return 'ErrorCounterMustHaveMoreThan3Digits';
1234
-    }
1235
-    else $maskrefclient='';
1543
+        if (dol_strlen($maskrefclient_maskcounter) > 0 && dol_strlen($maskrefclient_maskcounter) < 3) {
1544
+            return 'ErrorCounterMustHaveMoreThan3Digits';
1545
+        }
1546
+    } else {
1547
+        $maskrefclient='';
1548
+    }
1236 1549
 
1237 1550
     // fail if there is neither a global nor a third party counter
1238 1551
     if (! $hasglobalcounter && ($maskrefclient_maskcounter == ''))
@@ -1254,21 +1567,35 @@  discard block
 block discarded – undo
1254 1567
     //print "maskwithonlyymcode=".$maskwithonlyymcode." maskwithnocode=".$maskwithnocode."\n<br>";
1255 1568
 
1256 1569
     // If an offset is asked
1257
-    if (! empty($reg[2]) && preg_match('/^\+/',$reg[2])) $maskoffset=preg_replace('/^\+/','',$reg[2]);
1258
-    if (! empty($reg[3]) && preg_match('/^\+/',$reg[3])) $maskoffset=preg_replace('/^\+/','',$reg[3]);
1570
+    if (! empty($reg[2]) && preg_match('/^\+/',$reg[2])) {
1571
+        $maskoffset=preg_replace('/^\+/','',$reg[2]);
1572
+    }
1573
+    if (! empty($reg[3]) && preg_match('/^\+/',$reg[3])) {
1574
+        $maskoffset=preg_replace('/^\+/','',$reg[3]);
1575
+    }
1259 1576
 
1260 1577
     // Define $sqlwhere
1261 1578
 
1262 1579
     // If a restore to zero after a month is asked we check if there is already a value for this year.
1263
-    if (! empty($reg[2]) && preg_match('/^@/',$reg[2]))  $maskraz=preg_replace('/^@/','',$reg[2]);
1264
-    if (! empty($reg[3]) && preg_match('/^@/',$reg[3]))  $maskraz=preg_replace('/^@/','',$reg[3]);
1580
+    if (! empty($reg[2]) && preg_match('/^@/',$reg[2])) {
1581
+        $maskraz=preg_replace('/^@/','',$reg[2]);
1582
+    }
1583
+    if (! empty($reg[3]) && preg_match('/^@/',$reg[3])) {
1584
+        $maskraz=preg_replace('/^@/','',$reg[3]);
1585
+    }
1265 1586
     if ($maskraz >= 0)
1266 1587
     {
1267
-        if ($maskraz > 12) return 'ErrorBadMaskBadRazMonth';
1588
+        if ($maskraz > 12) {
1589
+            return 'ErrorBadMaskBadRazMonth';
1590
+        }
1268 1591
 
1269 1592
         // Define reg
1270
-        if ($maskraz > 1 && ! preg_match('/^(.*)\{(y+)\}\{(m+)\}/i',$maskwithonlyymcode,$reg)) return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
1271
-        if ($maskraz <= 1 && ! preg_match('/^(.*)\{(y+)\}/i',$maskwithonlyymcode,$reg)) return 'ErrorCantUseRazIfNoYearInMask';
1593
+        if ($maskraz > 1 && ! preg_match('/^(.*)\{(y+)\}\{(m+)\}/i',$maskwithonlyymcode,$reg)) {
1594
+            return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
1595
+        }
1596
+        if ($maskraz <= 1 && ! preg_match('/^(.*)\{(y+)\}/i',$maskwithonlyymcode,$reg)) {
1597
+            return 'ErrorCantUseRazIfNoYearInMask';
1598
+        }
1272 1599
         //print "x".$maskwithonlyymcode." ".$maskraz;
1273 1600
     }
1274 1601
     //print "masktri=".$masktri." maskcounter=".$maskcounter." maskraz=".$maskraz." maskoffset=".$maskoffset."<br>\n";
@@ -1278,7 +1605,9 @@  discard block
 block discarded – undo
1278 1605
 
1279 1606
     // Check length
1280 1607
     $len=dol_strlen($maskwithnocode);
1281
-    if (dol_strlen($value) != $len) $result=-1;
1608
+    if (dol_strlen($value) != $len) {
1609
+        $result=-1;
1610
+    }
1282 1611
 
1283 1612
     // Define $maskLike
1284 1613
     /* seems not used
@@ -1359,29 +1688,37 @@  discard block
 block discarded – undo
1359 1688
      */
1360 1689
 
1361 1690
     // Definition du Jeudi de la semaine
1362
-    if (date("w",mktime(12,0,0,$mois,$jour,$annee))==0) // Dimanche
1363
-    $jeudiSemaine = mktime(12,0,0,$mois,$jour,$annee)-3*24*60*60;
1364
-    else if (date("w",mktime(12,0,0,$mois,$jour,$annee))<4) // du Lundi au Mercredi
1365
-    $jeudiSemaine = mktime(12,0,0,$mois,$jour,$annee)+(4-date("w",mktime(12,0,0,$mois,$jour,$annee)))*24*60*60;
1366
-    else if (date("w",mktime(12,0,0,$mois,$jour,$annee))>4) // du Vendredi au Samedi
1367
-    $jeudiSemaine = mktime(12,0,0,$mois,$jour,$annee)-(date("w",mktime(12,0,0,$mois,$jour,$annee))-4)*24*60*60;
1368
-    else // Jeudi
1369
-    $jeudiSemaine = mktime(12,0,0,$mois,$jour,$annee);
1691
+    if (date("w",mktime(12,0,0,$mois,$jour,$annee))==0) {
1692
+        // Dimanche
1693
+    $jeudiSemaine = mktime(12,0,0,$mois,$jour,$annee)-3*24*60*60;
1694
+    } else if (date("w",mktime(12,0,0,$mois,$jour,$annee))<4) {
1695
+        // du Lundi au Mercredi
1696
+    $jeudiSemaine = mktime(12,0,0,$mois,$jour,$annee)+(4-date("w",mktime(12,0,0,$mois,$jour,$annee)))*24*60*60;
1697
+    } else if (date("w",mktime(12,0,0,$mois,$jour,$annee))>4) {
1698
+        // du Vendredi au Samedi
1699
+    $jeudiSemaine = mktime(12,0,0,$mois,$jour,$annee)-(date("w",mktime(12,0,0,$mois,$jour,$annee))-4)*24*60*60;
1700
+    } else {
1701
+        // Jeudi
1702
+    $jeudiSemaine = mktime(12,0,0,$mois,$jour,$annee);
1703
+    }
1370 1704
 
1371 1705
     // Definition du premier Jeudi de l'annee
1372
-    if (date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine)))==0) // Dimanche
1706
+    if (date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine)))==0) {
1707
+        // Dimanche
1373 1708
     {
1374
-        $premierJeudiAnnee = mktime(12,0,0,1,1,date("Y",$jeudiSemaine))+4*24*60*60;
1375
-    }
1376
-    else if (date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine)))<4) // du Lundi au Mercredi
1709
+        $premierJeudiAnnee = mktime(12,0,0,1,1,date("Y",$jeudiSemaine))+4*24*60*60;
1710
+    }
1711
+    } else if (date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine)))<4) {
1712
+        // du Lundi au Mercredi
1377 1713
     {
1378
-        $premierJeudiAnnee = mktime(12,0,0,1,1,date("Y",$jeudiSemaine))+(4-date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine))))*24*60*60;
1379
-    }
1380
-    else if (date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine)))>4) // du Vendredi au Samedi
1714
+        $premierJeudiAnnee = mktime(12,0,0,1,1,date("Y",$jeudiSemaine))+(4-date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine))))*24*60*60;
1715
+    }
1716
+    } else if (date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine)))>4) {
1717
+        // du Vendredi au Samedi
1381 1718
     {
1382
-        $premierJeudiAnnee = mktime(12,0,0,1,1,date("Y",$jeudiSemaine))+(7-(date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine)))-4))*24*60*60;
1383
-    }
1384
-    else // Jeudi
1719
+        $premierJeudiAnnee = mktime(12,0,0,1,1,date("Y",$jeudiSemaine))+(7-(date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine)))-4))*24*60*60;
1720
+    }
1721
+    } else // Jeudi
1385 1722
     {
1386 1723
         $premierJeudiAnnee = mktime(12,0,0,1,1,date("Y",$jeudiSemaine));
1387 1724
     }
@@ -1402,8 +1739,7 @@  discard block
 block discarded – undo
1402 1739
         if (date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine)))==4 || (date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine)))==3 && date("z",mktime(12,0,0,12,31,date("Y",$jeudiSemaine)))==365))
1403 1740
         {
1404 1741
             $numeroSemaine = 53;
1405
-        }
1406
-        else
1742
+        } else
1407 1743
         {
1408 1744
             $numeroSemaine = 1;
1409 1745
         }
@@ -1462,7 +1798,9 @@  discard block
 block discarded – undo
1462 1798
 function dol_set_user_param($db, $conf, &$user, $tab)
1463 1799
 {
1464 1800
     // Verification parametres
1465
-    if (count($tab) < 1) return -1;
1801
+    if (count($tab) < 1) {
1802
+        return -1;
1803
+    }
1466 1804
 
1467 1805
     $db->begin();
1468 1806
 
@@ -1474,7 +1812,9 @@  discard block
 block discarded – undo
1474 1812
     $i=0;
1475 1813
     foreach ($tab as $key => $value)
1476 1814
     {
1477
-        if ($i > 0) $sql.=',';
1815
+        if ($i > 0) {
1816
+            $sql.=',';
1817
+        }
1478 1818
         $sql.="'".$db->escape($key)."'";
1479 1819
         $i++;
1480 1820
     }
@@ -1508,8 +1848,7 @@  discard block
 block discarded – undo
1508 1848
             }
1509 1849
             $user->conf->$key = $value;
1510 1850
             //print "key=".$key." user->conf->key=".$user->conf->$key;
1511
-        }
1512
-        else
1851
+        } else
1513 1852
         {
1514 1853
             unset($user->conf->$key);
1515 1854
         }
@@ -1532,8 +1871,7 @@  discard block
 block discarded – undo
1532 1871
     if ($reduction == 100)
1533 1872
     {
1534 1873
         $string = $langs->transnoentities("Offered");
1535
-    }
1536
-    else
1874
+    } else
1537 1875
     {
1538 1876
     	$string = vatrate($reduction,true);
1539 1877
     }
@@ -1620,9 +1958,11 @@  discard block
 block discarded – undo
1620 1958
 
1621 1959
             // If this generation module needs to scan a directory, then description field is filled
1622 1960
             // with the constant that contains list of directories to scan (COMPANY_ADDON_PDF_ODT_PATH, ...).
1623
-            if (! empty($obj->description))	// A list of directories to scan is defined
1961
+            if (! empty($obj->description)) {
1962
+                // A list of directories to scan is defined
1624 1963
             {
1625
-                include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1964
+                include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1965
+            }
1626 1966
 
1627 1967
                 $const=$obj->description;
1628 1968
                 //irtoscan.=($dirtoscan?',':'').preg_replace('/[\r\n]+/',',',trim($conf->global->$const));
@@ -1641,7 +1981,9 @@  discard block
 block discarded – undo
1641 1981
                     {
1642 1982
 			// all type of template is allowed
1643 1983
 			$tmpfiles=dol_dir_list($tmpdir, 'files', 0, '', '', 'name', SORT_ASC, 0);
1644
-                        if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
1984
+                        if (count($tmpfiles)) {
1985
+                            $listoffiles=array_merge($listoffiles,$tmpfiles);
1986
+                        }
1645 1987
                     }
1646 1988
                 }
1647 1989
 
@@ -1652,40 +1994,41 @@  discard block
 block discarded – undo
1652 1994
                         $max=($maxfilenamelength?$maxfilenamelength:28);
1653 1995
                         $liste[$obj->id.':'.$record['fullname']]=dol_trunc($record['name'],$max,'middle');
1654 1996
                     }
1655
-                }
1656
-                else
1997
+                } else
1657 1998
                 {
1658 1999
                     $liste[0]=$obj->label.': '.$langs->trans("None");
1659 2000
                 }
1660
-            }
1661
-            else
2001
+            } else
1662 2002
             {
1663
-                if ($type == 'member' && $obj->lib == 'standard')   // Special case, if member template, we add variant per format
2003
+                if ($type == 'member' && $obj->lib == 'standard') {
2004
+                    // Special case, if member template, we add variant per format
1664 2005
                 {
1665
-                    global $_Avery_Labels;
2006
+                    global $_Avery_Labels;
2007
+                }
1666 2008
                     include_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php';
1667 2009
                     foreach($_Avery_Labels as $key => $val)
1668 2010
                     {
1669 2011
                         $liste[$obj->id.':'.$key]=($obj->label?$obj->label:$obj->lib).' '.$val['name'];
1670 2012
                     }
1671
-                }
1672
-                else    // Common usage
2013
+                } else    // Common usage
1673 2014
                 {
1674 2015
                     $liste[$obj->id]=$obj->label?$obj->label:$obj->lib;
1675 2016
                 }
1676 2017
             }
1677 2018
             $i++;
1678 2019
         }
1679
-    }
1680
-    else
2020
+    } else
1681 2021
     {
1682 2022
         dol_print_error($db);
1683 2023
         return -1;
1684 2024
     }
1685 2025
 
1686
-    if ($found) return $liste;
1687
-    else return 0;
1688
-}
2026
+    if ($found) {
2027
+        return $liste;
2028
+    } else {
2029
+        return 0;
2030
+    }
2031
+    }
1689 2032
 
1690 2033
 /**
1691 2034
  * This function evaluates a string that should be a valid IPv4
@@ -1700,10 +2043,14 @@  discard block
 block discarded – undo
1700 2043
 	if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
1701 2044
 
1702 2045
 		// Then we test if it is a private range
1703
-		if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE)) return 2;
2046
+		if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE)) {
2047
+		    return 2;
2048
+		}
1704 2049
 
1705 2050
 		// Then we test if it is a reserved range
1706
-		if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)) return 0;
2051
+		if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)) {
2052
+		    return 0;
2053
+		}
1707 2054
 
1708 2055
 		return 1;
1709 2056
 	}
@@ -1756,8 +2103,7 @@  discard block
 block discarded – undo
1756 2103
                       'proxy_password' => $proxypass,
1757 2104
                       'trace'		   => 1
1758 2105
         );
1759
-    }
1760
-    else
2106
+    } else
1761 2107
     {
1762 2108
         $params=array('connection_timeout'=>$timeout,
1763 2109
                       'response_timeout'=>$response_timeout,
@@ -1864,14 +2210,12 @@  discard block
 block discarded – undo
1864 2210
 		$classname='FactureFournisseur';
1865 2211
 		$classpath = 'fourn/class';
1866 2212
 		$module='fournisseur';
1867
-	}
1868
-	elseif ($objecttype == 'order_supplier')   {
2213
+	} elseif ($objecttype == 'order_supplier')   {
1869 2214
 		$classfile = 'fournisseur.commande';
1870 2215
 		$classname='CommandeFournisseur';
1871 2216
 		$classpath = 'fourn/class';
1872 2217
 		$module='fournisseur';
1873
-	}
1874
-	elseif ($objecttype == 'stock')   {
2218
+	} elseif ($objecttype == 'stock')   {
1875 2219
 		$classpath = 'product/stock/class';
1876 2220
 		$classfile='entrepot';
1877 2221
 		$classname='Entrepot';
@@ -1891,8 +2235,9 @@  discard block
 block discarded – undo
1891 2235
 					$ret=$langs->trans('Deleted');
1892 2236
 				}
1893 2237
 				unset($object);
1894
-			}
1895
-			else dol_syslog("Class with classname ".$classname." is unknown even after the include", LOG_ERR);
2238
+			} else {
2239
+			    dol_syslog("Class with classname ".$classname." is unknown even after the include", LOG_ERR);
2240
+			}
1896 2241
 		}
1897 2242
 	}
1898 2243
 	return $ret;
@@ -1924,11 +2269,12 @@  discard block
 block discarded – undo
1924 2269
 		{
1925 2270
 			$obj = $db->fetch_object($resql);
1926 2271
 			$listofid[]=$obj->rowid;
1927
-			if ($obj->parent_id > 0) $listofparentid[$obj->rowid]=$obj->parent_id;
2272
+			if ($obj->parent_id > 0) {
2273
+			    $listofparentid[$obj->rowid]=$obj->parent_id;
2274
+			}
1928 2275
 			$i++;
1929 2276
 		}
1930
-	}
1931
-	else
2277
+	} else
1932 2278
 	{
1933 2279
 		dol_print_error($db);
1934 2280
 	}
@@ -1963,9 +2309,11 @@  discard block
 block discarded – undo
1963 2309
 			while ($cursor > 0)
1964 2310
 			{
1965 2311
 				$arrayidparsed[$cursor]=1;
1966
-				if ($arrayidparsed[$listofparentid[$cursor]])	// We detect a loop. A record with a parent that was already into child
2312
+				if ($arrayidparsed[$listofparentid[$cursor]]) {
2313
+				    // We detect a loop. A record with a parent that was already into child
1967 2314
 				{
1968
-					print 'Found a loop between id '.$id.' - '.$cursor.'<br>';
2315
+					print 'Found a loop between id '.$id.' - '.$cursor.'<br>';
2316
+				}
1969 2317
 					unset($arrayidparsed);
1970 2318
 					$listofidtoclean[$cursor]=$id;
1971 2319
 					break;
@@ -1973,7 +2321,9 @@  discard block
 block discarded – undo
1973 2321
 				$cursor=$listofparentid[$cursor];
1974 2322
 			}
1975 2323
 
1976
-			if (count($listofidtoclean)) break;
2324
+			if (count($listofidtoclean)) {
2325
+			    break;
2326
+			}
1977 2327
 		}
1978 2328
 
1979 2329
 		$sql = "UPDATE ".MAIN_DB_PREFIX.$tabletocleantree;
@@ -2120,9 +2470,15 @@  discard block
 block discarded – undo
2120 2470
         $classfile='fournisseur.facture';
2121 2471
     }
2122 2472
 
2123
-    if (!isset($classfile)) $classfile = strtolower($subelement);
2124
-    if (!isset($classname)) $classname = ucfirst($subelement);
2125
-    if (!isset($classpath)) $classpath = $module.'/class';
2473
+    if (!isset($classfile)) {
2474
+        $classfile = strtolower($subelement);
2475
+    }
2476
+    if (!isset($classname)) {
2477
+        $classname = ucfirst($subelement);
2478
+    }
2479
+    if (!isset($classpath)) {
2480
+        $classpath = $module.'/class';
2481
+    }
2126 2482
 
2127 2483
     $element_properties = array(
2128 2484
         'module' => $module,
@@ -2176,8 +2532,12 @@  discard block
 block discarded – undo
2176 2532
  */
2177 2533
 function colorArrayToHex($arraycolor,$colorifnotfound='888888')
2178 2534
 {
2179
-	if (! is_array($arraycolor)) return $colorifnotfound;
2180
-	if (empty($arraycolor)) return $colorifnotfound;
2535
+	if (! is_array($arraycolor)) {
2536
+	    return $colorifnotfound;
2537
+	}
2538
+	if (empty($arraycolor)) {
2539
+	    return $colorifnotfound;
2540
+	}
2181 2541
 	return sprintf("%02s",dechex($arraycolor[0])).sprintf("%02s",dechex($arraycolor[1])).sprintf("%02s",dechex($arraycolor[2]));
2182 2542
 }
2183 2543
 
@@ -2193,12 +2553,17 @@  discard block
 block discarded – undo
2193 2553
  */
2194 2554
 static function colorStringToArray($stringcolor, $colorifnotfound = array(88, 88, 88))
2195 2555
     {
2196
-	if (is_array($stringcolor)) return $stringcolor;	// If already into correct output format, we return as is
2556
+	if (is_array($stringcolor)) {
2557
+	    return $stringcolor;
2558
+	}
2559
+	// If already into correct output format, we return as is
2197 2560
 	$tmp=preg_match('/^#?([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])$/',$stringcolor,$reg);
2198 2561
 	if (! $tmp)
2199 2562
 	{
2200 2563
 		$tmp=explode(',',$stringcolor);
2201
-		if (count($tmp) < 3) return $colorifnotfound;
2564
+		if (count($tmp) < 3) {
2565
+		    return $colorifnotfound;
2566
+		}
2202 2567
 		return $tmp;
2203 2568
 	}
2204 2569
 	return array(hexdec($reg[1]),hexdec($reg[2]),hexdec($reg[3]));
@@ -2244,69 +2609,51 @@  discard block
 block discarded – undo
2244 2609
 function getModuleDirForApiClass($module)
2245 2610
 {
2246 2611
     $moduledirforclass=$module;
2247
-    if ($moduledirforclass != 'api') $moduledirforclass = preg_replace('/api$/i','',$moduledirforclass);
2612
+    if ($moduledirforclass != 'api') {
2613
+        $moduledirforclass = preg_replace('/api$/i','',$moduledirforclass);
2614
+    }
2248 2615
 
2249 2616
     if ($module == 'contracts') {
2250 2617
     	$moduledirforclass = 'contrat';
2251
-    }
2252
-    elseif (in_array($module, array('admin', 'login', 'setup', 'access', 'status', 'tools', 'documents'))) {
2618
+    } elseif (in_array($module, array('admin', 'login', 'setup', 'access', 'status', 'tools', 'documents'))) {
2253 2619
         $moduledirforclass = 'api';
2254
-    }
2255
-    elseif ($module == 'contact' || $module == 'contacts' || $module == 'customer' || $module == 'thirdparty' || $module == 'thirdparties') {
2620
+    } elseif ($module == 'contact' || $module == 'contacts' || $module == 'customer' || $module == 'thirdparty' || $module == 'thirdparties') {
2256 2621
         $moduledirforclass = 'societe';
2257
-    }
2258
-    elseif ($module == 'propale' || $module == 'proposals') {
2622
+    } elseif ($module == 'propale' || $module == 'proposals') {
2259 2623
         $moduledirforclass = 'comm/propal';
2260
-    }
2261
-    elseif ($module == 'agenda' || $module == 'agendaevents') {
2624
+    } elseif ($module == 'agenda' || $module == 'agendaevents') {
2262 2625
         $moduledirforclass = 'comm/action';
2263
-    }
2264
-    elseif ($module == 'adherent' || $module == 'members' || $module == 'memberstypes' || $module == 'subscriptions') {
2626
+    } elseif ($module == 'adherent' || $module == 'members' || $module == 'memberstypes' || $module == 'subscriptions') {
2265 2627
         $moduledirforclass = 'adherents';
2266
-    }
2267
-    elseif ($module == 'banque' || $module == 'bankaccounts') {
2628
+    } elseif ($module == 'banque' || $module == 'bankaccounts') {
2268 2629
         $moduledirforclass = 'compta/bank';
2269
-    }
2270
-    elseif ($module == 'category' || $module == 'categorie') {
2630
+    } elseif ($module == 'category' || $module == 'categorie') {
2271 2631
         $moduledirforclass = 'categories';
2272
-    }
2273
-    elseif ($module == 'order' || $module == 'orders') {
2632
+    } elseif ($module == 'order' || $module == 'orders') {
2274 2633
         $moduledirforclass = 'commande';
2275
-    }
2276
-    elseif ($module == 'shipments') {
2634
+    } elseif ($module == 'shipments') {
2277 2635
     	$moduledirforclass = 'expedition';
2278
-    }
2279
-    elseif ($module == 'facture' || $module == 'invoice' || $module == 'invoices') {
2636
+    } elseif ($module == 'facture' || $module == 'invoice' || $module == 'invoices') {
2280 2637
         $moduledirforclass = 'compta/facture';
2281
-    }
2282
-    elseif ($module == 'products') {
2638
+    } elseif ($module == 'products') {
2283 2639
         $moduledirforclass = 'product';
2284
-    }
2285
-    elseif ($module == 'project' || $module == 'projects' || $module == 'tasks') {
2640
+    } elseif ($module == 'project' || $module == 'projects' || $module == 'tasks') {
2286 2641
         $moduledirforclass = 'projet';
2287
-    }
2288
-    elseif ($module == 'task') {
2642
+    } elseif ($module == 'task') {
2289 2643
         $moduledirforclass = 'projet';
2290
-    }
2291
-    elseif ($module == 'stock' || $module == 'stockmovements' || $module == 'warehouses') {
2644
+    } elseif ($module == 'stock' || $module == 'stockmovements' || $module == 'warehouses') {
2292 2645
         $moduledirforclass = 'product/stock';
2293
-    }
2294
-    elseif ($module == 'supplierproposals' || $module == 'supplierproposal' || $module == 'supplier_proposal') {
2646
+    } elseif ($module == 'supplierproposals' || $module == 'supplierproposal' || $module == 'supplier_proposal') {
2295 2647
     	$moduledirforclass = 'supplier_proposal';
2296
-    }
2297
-    elseif ($module == 'fournisseur' || $module == 'supplierinvoices' || $module == 'supplierorders') {
2648
+    } elseif ($module == 'fournisseur' || $module == 'supplierinvoices' || $module == 'supplierorders') {
2298 2649
         $moduledirforclass = 'fourn';
2299
-    }
2300
-    elseif ($module == 'expensereports') {
2650
+    } elseif ($module == 'expensereports') {
2301 2651
         $moduledirforclass = 'expensereport';
2302
-    }
2303
-    elseif ($module == 'users') {
2652
+    } elseif ($module == 'users') {
2304 2653
         $moduledirforclass = 'user';
2305
-    }
2306
-    elseif ($module == 'ficheinter' || $module == 'interventions') {
2654
+    } elseif ($module == 'ficheinter' || $module == 'interventions') {
2307 2655
     	$moduledirforclass = 'fichinter';
2308
-    }
2309
-    elseif ($module == 'tickets') {
2656
+    } elseif ($module == 'tickets') {
2310 2657
     	$moduledirforclass = 'ticket';
2311 2658
     }
2312 2659
 
Please login to merge, or discard this patch.
Helpers/NoValeConfig.php 1 patch
Braces   +60 added lines, -26 removed lines patch added patch discarded remove patch
@@ -44,9 +44,16 @@  discard block
 block discarded – undo
44 44
 
45 45
 
46 46
 // Chargement des includes principaux de librairies communes
47
-if (! defined('NOREQUIREUSER')) require_once DOL_DOCUMENT_ROOT .'/user/class/user.class.php';		// Need 500ko memory
48
-if (! defined('NOREQUIRETRAN')) require_once DOL_DOCUMENT_ROOT .'/core/class/translate.class.php';
49
-if (! defined('NOREQUIRESOC'))  require_once DOL_DOCUMENT_ROOT .'/societe/class/societe.class.php';
47
+if (! defined('NOREQUIREUSER')) {
48
+    require_once DOL_DOCUMENT_ROOT .'/user/class/user.class.php';
49
+}
50
+// Need 500ko memory
51
+if (! defined('NOREQUIRETRAN')) {
52
+    require_once DOL_DOCUMENT_ROOT .'/core/class/translate.class.php';
53
+}
54
+if (! defined('NOREQUIRESOC')) {
55
+    require_once DOL_DOCUMENT_ROOT .'/societe/class/societe.class.php';
56
+}
50 57
 
51 58
 
52 59
 
@@ -78,25 +85,32 @@  discard block
 block discarded – undo
78 85
  */
79 86
 
80 87
 // By default conf->entity is 1, but we change this if we ask another value.
81
-if (session_id() && ! empty($_SESSION["dol_entity"]))			// Entity inside an opened session
88
+if (session_id() && ! empty($_SESSION["dol_entity"])) {
89
+    // Entity inside an opened session
82 90
 {
83
-	$conf->entity = $_SESSION["dol_entity"];
84
-}
85
-else if (! empty($_ENV["dol_entity"]))							// Entity inside a CLI script
91
+	$conf->entity = $_SESSION["dol_entity"];
92
+}
93
+} else if (! empty($_ENV["dol_entity"])) {
94
+    // Entity inside a CLI script
86 95
 {
87
-	$conf->entity = $_ENV["dol_entity"];
88
-}
89
-else if (isset($_POST["loginfunction"]) && GETPOST("entity",'int'))	// Just after a login page
96
+	$conf->entity = $_ENV["dol_entity"];
97
+}
98
+} else if (isset($_POST["loginfunction"]) && GETPOST("entity",'int')) {
99
+    // Just after a login page
90 100
 {
91
-	$conf->entity = GETPOST("entity",'int');
92
-}
93
-else if (defined('DOLENTITY') && is_numeric(DOLENTITY))			// For public page with MultiCompany module
101
+	$conf->entity = GETPOST("entity",'int');
102
+}
103
+} else if (defined('DOLENTITY') && is_numeric(DOLENTITY)) {
104
+    // For public page with MultiCompany module
94 105
 {
95
-	$conf->entity = DOLENTITY;
106
+	$conf->entity = DOLENTITY;
107
+}
96 108
 }
97 109
 
98 110
 // Sanitize entity
99
-if (! is_numeric($conf->entity)) $conf->entity=1;
111
+if (! is_numeric($conf->entity)) {
112
+    $conf->entity=1;
113
+}
100 114
 
101 115
 if (! defined('NOREQUIREDB'))
102 116
 {
@@ -128,11 +142,26 @@  discard block
 block discarded – undo
128 142
 if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED))
129 143
 {
130 144
 	$ok=0;
131
-	if ((! session_id() || ! isset($_SESSION["dol_login"])) && ! isset($_POST["username"]) && ! empty($_SERVER["GATEWAY_INTERFACE"])) $ok=1;	// We let working pages if not logged and inside a web browser (login form, to allow login by admin)
132
-	elseif (isset($_POST["username"]) && $_POST["username"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) $ok=1;				// We let working pages that is a login submission (login submit, to allow login by admin)
133
-	elseif (defined('NOREQUIREDB'))   $ok=1;				// We let working pages that don't need database access (xxx.css.php)
134
-	elseif (defined('EVEN_IF_ONLY_LOGIN_ALLOWED')) $ok=1;	// We let working pages that ask to work even if only login enabled (logout.php)
135
-	elseif (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) $ok=1;	// We let working if user is allowed admin
145
+	if ((! session_id() || ! isset($_SESSION["dol_login"])) && ! isset($_POST["username"]) && ! empty($_SERVER["GATEWAY_INTERFACE"])) {
146
+	    $ok=1;
147
+	}
148
+	// We let working pages if not logged and inside a web browser (login form, to allow login by admin)
149
+	elseif (isset($_POST["username"]) && $_POST["username"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) {
150
+	    $ok=1;
151
+	}
152
+	// We let working pages that is a login submission (login submit, to allow login by admin)
153
+	elseif (defined('NOREQUIREDB')) {
154
+	    $ok=1;
155
+	}
156
+	// We let working pages that don't need database access (xxx.css.php)
157
+	elseif (defined('EVEN_IF_ONLY_LOGIN_ALLOWED')) {
158
+	    $ok=1;
159
+	}
160
+	// We let working pages that ask to work even if only login enabled (logout.php)
161
+	elseif (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) {
162
+	    $ok=1;
163
+	}
164
+	// We let working if user is allowed admin
136 165
 	if (! $ok)
137 166
 	{
138 167
 		if (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] != $conf->global->MAIN_ONLY_LOGIN_ALLOWED)
@@ -141,8 +170,7 @@  discard block
 block discarded – undo
141 170
 			print 'You are logged with user "'.$_SESSION["dol_login"].'" and only administrator user "'.$conf->global->MAIN_ONLY_LOGIN_ALLOWED.'" is allowed to connect for the moment.'."\n";
142 171
 			$nexturl=DOL_URL_ROOT.'/user/logout.php';
143 172
 			print 'Please try later or <a href="'.$nexturl.'">click here to disconnect and change login user</a>...'."\n";
144
-		}
145
-		else
173
+		} else
146 174
 		{
147 175
 			print 'Sorry, your application is offline. Only administrator user "'.$conf->global->MAIN_ONLY_LOGIN_ALLOWED.'" is allowed to connect for the moment.'."\n";
148 176
 			$nexturl=DOL_URL_ROOT.'/';
@@ -161,20 +189,26 @@  discard block
 block discarded – undo
161 189
 	$mysoc->setMysoc($conf);
162 190
 
163 191
 	// For some countries, we need to invert our address with customer address
164
-	if ($mysoc->country_code == 'DE' && ! isset($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $conf->global->MAIN_INVERT_SENDER_RECIPIENT=1;
165
-}
192
+	if ($mysoc->country_code == 'DE' && ! isset($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
193
+	    $conf->global->MAIN_INVERT_SENDER_RECIPIENT=1;
194
+	}
195
+	}
166 196
 
167 197
 
168 198
 // Set default language (must be after the setValues setting global $conf->global->MAIN_LANG_DEFAULT. Page main.inc.php will overwrite langs->defaultlang with user value later)
169 199
 if (! defined('NOREQUIRETRAN'))
170 200
 {
171 201
     $langcode=(GETPOST('lang','aZ09')?GETPOST('lang','aZ09',1):(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT));
172
-    if (defined('MAIN_LANG_DEFAULT')) $langcode=constant('MAIN_LANG_DEFAULT');
202
+    if (defined('MAIN_LANG_DEFAULT')) {
203
+        $langcode=constant('MAIN_LANG_DEFAULT');
204
+    }
173 205
     $langs->setDefaultLang($langcode);
174 206
 }
175 207
 
176 208
 
177 209
 
178 210
 
179
-if (! defined('MAIN_LABEL_MENTION_NPR') ) define('MAIN_LABEL_MENTION_NPR','NPR');
211
+if (! defined('MAIN_LABEL_MENTION_NPR') ) {
212
+    define('MAIN_LABEL_MENTION_NPR','NPR');
213
+}
180 214
 
Please login to merge, or discard this patch.
Helpers/login/functions_ldap.php 1 patch
Braces   +52 added lines, -24 removed lines patch added patch discarded remove patch
@@ -45,7 +45,9 @@  discard block
 block discarded – undo
45 45
 
46 46
 	// Force master entity in transversal mode
47 47
 	$entity=$entitytotest;
48
-	if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $entity=1;
48
+	if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
49
+	    $entity=1;
50
+	}
49 51
 
50 52
 	$login='';
51 53
 	$resultFetchUser='';
@@ -78,7 +80,9 @@  discard block
 block discarded – undo
78 80
 		$ldapadminpass=$dolibarr_main_auth_ldap_admin_pass;
79 81
 		$ldapdebug=(empty($dolibarr_main_auth_ldap_debug) || $dolibarr_main_auth_ldap_debug=="false" ? false : true);
80 82
 
81
-		if ($ldapdebug) print "DEBUG: Logging LDAP steps<br>\n";
83
+		if ($ldapdebug) {
84
+		    print "DEBUG: Logging LDAP steps<br>\n";
85
+		}
82 86
 
83 87
 		require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
84 88
 		$ldap=new Ldap();
@@ -116,20 +120,25 @@  discard block
 block discarded – undo
116 120
 			{
117 121
 				$resultFetchLdapUser = $ldap->fetch($usertotest,$userSearchFilter);
118 122
 				//dol_syslog('functions_ldap::check_user_password_ldap resultFetchLdapUser='.$resultFetchLdapUser);
119
-				if ($resultFetchLdapUser > 0 && $ldap->pwdlastset == 0) // If ok but password need to be reset
123
+				if ($resultFetchLdapUser > 0 && $ldap->pwdlastset == 0) {
124
+				    // If ok but password need to be reset
120 125
 				{
121
-					dol_syslog('functions_ldap::check_user_password_ldap '.$usertotest.' must change password next logon');
122
-					if ($ldapdebug) print "DEBUG: User ".$usertotest." must change password<br>\n";
126
+					dol_syslog('functions_ldap::check_user_password_ldap '.$usertotest.' must change password next logon');
127
+				}
128
+					if ($ldapdebug) {
129
+					    print "DEBUG: User ".$usertotest." must change password<br>\n";
130
+					}
123 131
 					$ldap->close();
124 132
 					sleep(1);
125 133
 					$langs->load('ldap');
126 134
 					$_SESSION["dol_loginmesg"]=$langs->trans("YouMustChangePassNextLogon",$usertotest,$ldap->domainFQDN);
127 135
 					return '';
128 136
 				}
129
-			}
130
-			else
137
+			} else
131 138
 			{
132
-				 if ($ldapdebug) print "DEBUG: ".$ldap->error."<br>\n";
139
+				 if ($ldapdebug) {
140
+				     print "DEBUG: ".$ldap->error."<br>\n";
141
+				 }
133 142
 			}
134 143
 			$ldap->close();
135 144
 		}
@@ -140,7 +149,9 @@  discard block
 block discarded – undo
140 149
 		$ldap->searchUser=$ldapuserattr."=".$usertotest.",".$ldapdn;  // Default dn (will work if LDAP accept a dn with login value inside)
141 150
 		// But if LDAP need a dn with name like "cn=Jhon Bloggs,ou=People,dc=foo,dc=com", previous part must have been executed to have
142 151
 		// dn detected into ldapUserDN.
143
-		if ($resultFetchLdapUser && !empty($ldap->ldapUserDN)) $ldap->searchUser = $ldap->ldapUserDN;
152
+		if ($resultFetchLdapUser && !empty($ldap->ldapUserDN)) {
153
+		    $ldap->searchUser = $ldap->ldapUserDN;
154
+		}
144 155
 		$ldap->searchPassword=$passwordtotest;
145 156
 
146 157
 		// Test with this->seachUser and this->searchPassword
@@ -148,27 +159,41 @@  discard block
 block discarded – undo
148 159
 		$result=$ldap->connect_bind();
149 160
 		if ($result > 0)
150 161
 		{
151
-			if ($result == 2)	// Connection is ok for user/pass into LDAP
162
+			if ($result == 2) {
163
+			    // Connection is ok for user/pass into LDAP
152 164
 			{
153
-				dol_syslog("functions_ldap::check_user_password_ldap Authentification ok");
165
+				dol_syslog("functions_ldap::check_user_password_ldap Authentification ok");
166
+			}
154 167
 				$login=$usertotest;
155 168
 
156 169
 				// ldap2dolibarr synchronisation
157
-				if ($login && ! empty($conf->ldap->enabled) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr')	// ldap2dolibarr synchronisation
170
+				if ($login && ! empty($conf->ldap->enabled) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr') {
171
+				    // ldap2dolibarr synchronisation
158 172
 				{
159
-						dol_syslog("functions_ldap::check_user_password_ldap Sync ldap2dolibarr");
173
+						dol_syslog("functions_ldap::check_user_password_ldap Sync ldap2dolibarr");
174
+				}
160 175
 
161 176
 						// On charge les attributs du user ldap
162
-						if ($ldapdebug) print "DEBUG: login ldap = ".$login."<br>\n";
177
+						if ($ldapdebug) {
178
+						    print "DEBUG: login ldap = ".$login."<br>\n";
179
+						}
163 180
 						$resultFetchLdapUser = $ldap->fetch($login,$userSearchFilter);
164 181
 
165
-						if ($ldapdebug) print "DEBUG: UACF = ".join(',',$ldap->uacf)."<br>\n";
166
-						if ($ldapdebug) print "DEBUG: pwdLastSet = ".dol_print_date($ldap->pwdlastset,'day')."<br>\n";
167
-						if ($ldapdebug) print "DEBUG: badPasswordTime = ".dol_print_date($ldap->badpwdtime,'day')."<br>\n";
182
+						if ($ldapdebug) {
183
+						    print "DEBUG: UACF = ".join(',',$ldap->uacf)."<br>\n";
184
+						}
185
+						if ($ldapdebug) {
186
+						    print "DEBUG: pwdLastSet = ".dol_print_date($ldap->pwdlastset,'day')."<br>\n";
187
+						}
188
+						if ($ldapdebug) {
189
+						    print "DEBUG: badPasswordTime = ".dol_print_date($ldap->badpwdtime,'day')."<br>\n";
190
+						}
168 191
 
169 192
 						// On recherche le user dolibarr en fonction de son SID ldap
170 193
 						$sid = $ldap->getObjectSid($login);
171
-						if ($ldapdebug) print "DEBUG: sid = ".$sid."<br>\n";
194
+						if ($ldapdebug) {
195
+						    print "DEBUG: sid = ".$sid."<br>\n";
196
+						}
172 197
 
173 198
 						$usertmp=new User($db);
174 199
 						$resultFetchUser=$usertmp->fetch('',$login,$sid);
@@ -189,9 +214,11 @@  discard block
 block discarded – undo
189 214
 						unset($usertmp);
190 215
 				}
191 216
 
192
-				if (! empty($conf->multicompany->enabled))	// We must check entity (even if sync is not active)
217
+				if (! empty($conf->multicompany->enabled)) {
218
+				    // We must check entity (even if sync is not active)
193 219
 				{
194
-					global $mc;
220
+					global $mc;
221
+				}
195 222
 
196 223
 					$usertmp=new User($db);
197 224
 					$usertmp->fetch('',$login);
@@ -214,8 +241,7 @@  discard block
 block discarded – undo
214 241
 
215 242
 				$_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword");
216 243
 			}
217
-		}
218
-		else
244
+		} else
219 245
 		{
220 246
 			/* Login failed. Return false, together with the error code and text from
221 247
              ** the LDAP server. The common error codes and reasons are listed below :
@@ -226,9 +252,11 @@  discard block
 block discarded – undo
226 252
              ** 53 - Account inactive (manually locked out by administrator)
227 253
              */
228 254
 			dol_syslog("functions_ldap::check_user_password_ldap Authentification ko failed to connect to LDAP for '".$usertotest."'");
229
-			if (is_resource($ldap->connection))    // If connection ok but bind ko
255
+			if (is_resource($ldap->connection)) {
256
+			    // If connection ok but bind ko
230 257
 			{
231
-				$ldap->ldapErrorCode = ldap_errno($ldap->connection);
258
+				$ldap->ldapErrorCode = ldap_errno($ldap->connection);
259
+			}
232 260
 				$ldap->ldapErrorText = ldap_error($ldap->connection);
233 261
 				dol_syslog("functions_ldap::check_user_password_ldap ".$ldap->ldapErrorCode." ".$ldap->ldapErrorText);
234 262
 			}
Please login to merge, or discard this patch.
Helpers/login/functions_forceuser.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,9 +40,13 @@
 block discarded – undo
40 40
 	dol_syslog("functions_forceuser::check_user_password_forceuser");
41 41
 
42 42
 	$login=$dolibarr_auto_user;
43
-	if (empty($login)) $login='auto';
43
+	if (empty($login)) {
44
+	    $login='auto';
45
+	}
44 46
 
45
-	if ($_SESSION["dol_loginmesg"]) $login='';
47
+	if ($_SESSION["dol_loginmesg"]) {
48
+	    $login='';
49
+	}
46 50
 
47 51
 	dol_syslog("functions_forceuser::check_user_password_forceuser ok. forced user = ".$login);
48 52
 	return $login;
Please login to merge, or discard this patch.
Helpers/login/functions_openid.php 1 patch
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -56,8 +56,7 @@  discard block
 block discarded – undo
56 56
         {
57 57
             $openid->SetApprovedURL($protocol . $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"]);      // Send Response from OpenID server to this script
58 58
             $openid->Redirect();     // This will redirect user to OpenID Server
59
-        }
60
-        else
59
+        } else
61 60
         {
62 61
             $error = $openid->GetError();
63 62
             return false;
@@ -89,21 +88,18 @@  discard block
 block discarded – undo
89 88
                     $login=$obj->login;
90 89
                 }
91 90
             }
92
-        }
93
-        else if($openid->IsError() === true)
91
+        } else if($openid->IsError() === true)
94 92
         {
95 93
             // ON THE WAY, WE GOT SOME ERROR
96 94
             $error = $openid->GetError();
97 95
             return false;
98
-        }
99
-        else
96
+        } else
100 97
         {
101 98
             // Signature Verification Failed
102 99
             //echo "INVALID AUTHORIZATION";
103 100
             return false;
104 101
         }
105
-    }
106
-    else if ($_GET['openid_mode'] == 'cancel')
102
+    } else if ($_GET['openid_mode'] == 'cancel')
107 103
     {
108 104
         // User Canceled your Request
109 105
         //echo "USER CANCELED REQUEST";
Please login to merge, or discard this patch.
Helpers/DolUtils.php 1 patch
Braces   +1453 added lines, -1047 removed lines patch added patch discarded remove patch
@@ -75,8 +75,9 @@  discard block
 block discarded – undo
75 75
           if ($found) return $result;
76 76
           } */
77 77
 
78
-        if (isset($class::$member))
79
-            return $class::$member;
78
+        if (isset($class::$member)) {
79
+                    return $class::$member;
80
+        }
80 81
         dol_print_error('', 'Try to get a static member "' . $member . '" in class "' . $class . '" that does not exists or is not static.');
81 82
         return null;
82 83
     }
@@ -127,8 +128,9 @@  discard block
 block discarded – undo
127 128
         } else {
128 129
             $out = '';
129 130
             $addzero = array('user', 'usergroup', 'c_email_templates', 'email_template', 'default_values');
130
-            if (in_array($element, $addzero))
131
-                $out .= '0,';
131
+            if (in_array($element, $addzero)) {
132
+                            $out .= '0,';
133
+            }
132 134
             $out .= Globals::$conf->entity;
133 135
             return $out;
134 136
         }
@@ -307,32 +309,35 @@  discard block
 block discarded – undo
307 309
     {
308 310
        // global $mysoc, $user, Globals::$conf;
309 311
 
310
-        if (empty($paramname))
311
-            return 'BadFirstParameterForDolUtils::GETPOST';
312
+        if (empty($paramname)) {
313
+                    return 'BadFirstParameterForDolUtils::GETPOST';
314
+        }
312 315
         if (empty($check)) {
313 316
             dol_syslog("Deprecated use of DolUtils::GETPOST, called with 1st param = " . $paramname . " and 2nd param is '', when calling page " . $_SERVER["PHP_SELF"], LOG_WARNING);
314 317
         // Enable this line to know who call the DolUtils::GETPOST with '' $check parameter.
315 318
         //var_dump(debug_backtrace()[0]);
316 319
         }
317 320
 
318
-        if (empty($method))
319
-            $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] : '');
320
-        elseif ($method == 1)
321
-            $out = isset($_GET[$paramname]) ? $_GET[$paramname] : '';
322
-        elseif ($method == 2)
323
-            $out = isset($_POST[$paramname]) ? $_POST[$paramname] : '';
324
-        elseif ($method == 3)
325
-            $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] : '');
326
-        elseif ($method == 4)
327
-            $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_COOKIE[$paramname]) ? $_COOKIE[$paramname] : ''));
328
-        else
329
-            return 'BadThirdParameterForDolUtils::GETPOST';
321
+        if (empty($method)) {
322
+                    $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] : '');
323
+        } elseif ($method == 1) {
324
+                    $out = isset($_GET[$paramname]) ? $_GET[$paramname] : '';
325
+        } elseif ($method == 2) {
326
+                    $out = isset($_POST[$paramname]) ? $_POST[$paramname] : '';
327
+        } elseif ($method == 3) {
328
+                    $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] : '');
329
+        } elseif ($method == 4) {
330
+                    $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_COOKIE[$paramname]) ? $_COOKIE[$paramname] : ''));
331
+        } else {
332
+                    return 'BadThirdParameterForDolUtils::GETPOST';
333
+        }
330 334
 
331 335
         if (empty($method) || $method == 3 || $method == 4) {
332 336
             $relativepathstring = $_SERVER["PHP_SELF"];
333 337
             // Clean $relativepathstring
334
-            if (constant('DOL_BASE_URI'))
335
-                $relativepathstring = preg_replace('/^' . preg_quote(constant('DOL_BASE_URI'), '/') . '/', '', $relativepathstring);
338
+            if (constant('DOL_BASE_URI')) {
339
+                            $relativepathstring = preg_replace('/^' . preg_quote(constant('DOL_BASE_URI'), '/') . '/', '', $relativepathstring);
340
+            }
336 341
             $relativepathstring = preg_replace('/^\//', '', $relativepathstring);
337 342
             $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
338 343
             //var_dump($relativepathstring);
@@ -381,14 +386,17 @@  discard block
 block discarded – undo
381 386
                                         $tmpqueryarraywehave = explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
382 387
                                         $foundintru = 0;
383 388
                                         foreach ($tmpqueryarraytohave as $tmpquerytohave) {
384
-                                            if (!in_array($tmpquerytohave, $tmpqueryarraywehave))
385
-                                                $foundintru = 1;
389
+                                            if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
390
+                                                                                            $foundintru = 1;
391
+                                            }
386 392
                                         }
387
-                                        if (!$foundintru)
388
-                                            $qualified = 1;
393
+                                        if (!$foundintru) {
394
+                                                                                    $qualified = 1;
395
+                                        }
389 396
                                         //var_dump($defkey.'-'.$qualified);
390
-                                    } else
391
-                                        $qualified = 1;
397
+                                    } else {
398
+                                                                            $qualified = 1;
399
+                                    }
392 400
 
393 401
                                     if ($qualified) {
394 402
                                         //var_dump($user->default_values[$relativepathstring][$defkey]['createform']);
@@ -415,20 +423,24 @@  discard block
 block discarded – undo
415 423
                                             $tmpqueryarraywehave = explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
416 424
                                             $foundintru = 0;
417 425
                                             foreach ($tmpqueryarraytohave as $tmpquerytohave) {
418
-                                                if (!in_array($tmpquerytohave, $tmpqueryarraywehave))
419
-                                                    $foundintru = 1;
426
+                                                if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
427
+                                                                                                    $foundintru = 1;
428
+                                                }
420 429
                                             }
421
-                                            if (!$foundintru)
422
-                                                $qualified = 1;
430
+                                            if (!$foundintru) {
431
+                                                                                            $qualified = 1;
432
+                                            }
423 433
                                             //var_dump($defkey.'-'.$qualified);
424
-                                        } else
425
-                                            $qualified = 1;
434
+                                        } else {
435
+                                                                                    $qualified = 1;
436
+                                        }
426 437
 
427 438
                                         if ($qualified) {
428 439
                                             $forbidden_chars_to_replace = array(" ", "'", "/", "\\", ":", "*", "?", "\"", "<", ">", "|", "[", "]", ";", "=");  // we accept _, -, . and ,
429 440
                                             foreach ($user->default_values[$relativepathstring]['sortorder'][$defkey] as $key => $val) {
430
-                                                if ($out)
431
-                                                    $out .= ', ';
441
+                                                if ($out) {
442
+                                                                                                    $out .= ', ';
443
+                                                }
432 444
                                                 if ($paramname == 'sortfield') {
433 445
                                                     $out .= dol_string_nospecial($key, '', $forbidden_chars_to_replace);
434 446
                                                 }
@@ -448,14 +460,17 @@  discard block
 block discarded – undo
448 460
                                         $tmpqueryarraywehave = explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
449 461
                                         $foundintru = 0;
450 462
                                         foreach ($tmpqueryarraytohave as $tmpquerytohave) {
451
-                                            if (!in_array($tmpquerytohave, $tmpqueryarraywehave))
452
-                                                $foundintru = 1;
463
+                                            if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
464
+                                                                                            $foundintru = 1;
465
+                                            }
453 466
                                         }
454
-                                        if (!$foundintru)
455
-                                            $qualified = 1;
467
+                                        if (!$foundintru) {
468
+                                                                                    $qualified = 1;
469
+                                        }
456 470
                                         //var_dump($defkey.'-'.$qualified);
457
-                                    } else
458
-                                        $qualified = 1;
471
+                                    } else {
472
+                                                                            $qualified = 1;
473
+                                    }
459 474
 
460 475
                                     if ($qualified) {
461 476
                                         if (isset($_POST['sall']) || isset($_POST['search_all']) || isset($_GET['sall']) || isset($_GET['search_all'])) {
@@ -527,8 +542,10 @@  discard block
 block discarded – undo
527 542
                     $newout = $user->fk_user;
528 543
                 } elseif ($reg[1] == 'ENTITY_ID' || $reg[1] == 'ENTITYID') {
529 544
                     $newout = Globals::$conf->entity;
530
-                } else
531
-                    $newout = '';     // Key not found, we replace with empty string
545
+                } else {
546
+                                    $newout = '';
547
+                }
548
+                // Key not found, we replace with empty string
532 549
 
533 550
 
534 551
 
@@ -577,18 +594,20 @@  discard block
 block discarded – undo
577 594
                 }
578 595
                 break;
579 596
             case 'intcomma':
580
-                if (preg_match('/[^0-9,-]+/i', $out))
581
-                    $out = '';
597
+                if (preg_match('/[^0-9,-]+/i', $out)) {
598
+                                    $out = '';
599
+                }
582 600
                 break;
583 601
             case 'alpha':
584 602
                 if (!is_array($out)) {
585 603
                     $out = trim($out);
586 604
                     // '"' is dangerous because param in url can close the href= or src= and add javascript functions.
587 605
                     // '../' is dangerous because it allows dir transversals
588
-                    if (preg_match('/"/', $out))
589
-                        $out = '';
590
-                    else if (preg_match('/\.\.\//', $out))
591
-                        $out = '';
606
+                    if (preg_match('/"/', $out)) {
607
+                                            $out = '';
608
+                    } else if (preg_match('/\.\.\//', $out)) {
609
+                                            $out = '';
610
+                    }
592 611
                 }
593 612
                 break;
594 613
             case 'san_alpha':
@@ -597,27 +616,31 @@  discard block
 block discarded – undo
597 616
             case 'aZ':
598 617
                 if (!is_array($out)) {
599 618
                     $out = trim($out);
600
-                    if (preg_match('/[^a-z]+/i', $out))
601
-                        $out = '';
619
+                    if (preg_match('/[^a-z]+/i', $out)) {
620
+                                            $out = '';
621
+                    }
602 622
                 }
603 623
                 break;
604 624
             case 'aZ09':
605 625
                 if (!is_array($out)) {
606 626
                     $out = trim($out);
607
-                    if (preg_match('/[^a-z0-9_\-\.]+/i', $out))
608
-                        $out = '';
627
+                    if (preg_match('/[^a-z0-9_\-\.]+/i', $out)) {
628
+                                            $out = '';
629
+                    }
609 630
                 }
610 631
                 break;
611 632
             case 'aZ09comma':  // great to sanitize sortfield or sortorder params that can be t.abc,t.def_gh
612 633
                 if (!is_array($out)) {
613 634
                     $out = trim($out);
614
-                    if (preg_match('/[^a-z0-9_\-\.,]+/i', $out))
615
-                        $out = '';
635
+                    if (preg_match('/[^a-z0-9_\-\.,]+/i', $out)) {
636
+                                            $out = '';
637
+                    }
616 638
                 }
617 639
                 break;
618 640
             case 'array':
619
-                if (!is_array($out) || empty($out))
620
-                    $out = array();
641
+                if (!is_array($out) || empty($out)) {
642
+                                    $out = array();
643
+                }
621 644
                 break;
622 645
             case 'nohtml':  // Recommended for most scalar parameters
623 646
                 $out = dol_string_nohtmltag($out, 0);
@@ -627,16 +650,18 @@  discard block
 block discarded – undo
627 650
                     $out = trim($out);
628 651
                     // '"' is dangerous because param in url can close the href= or src= and add javascript functions.
629 652
                     // '../' is dangerous because it allows dir transversals
630
-                    if (preg_match('/"/', $out))
631
-                        $out = '';
632
-                    else if (preg_match('/\.\.\//', $out))
633
-                        $out = '';
653
+                    if (preg_match('/"/', $out)) {
654
+                                            $out = '';
655
+                    } else if (preg_match('/\.\.\//', $out)) {
656
+                                            $out = '';
657
+                    }
634 658
                     $out = dol_string_nohtmltag($out);
635 659
                 }
636 660
                 break;
637 661
             case 'custom':
638
-                if (empty($filter))
639
-                    return 'BadFourthParameterForDolUtils::GETPOST';
662
+                if (empty($filter)) {
663
+                                    return 'BadFourthParameterForDolUtils::GETPOST';
664
+                }
640 665
                 $out = filter_var($out, $filter, $options);
641 666
                 break;
642 667
         }
@@ -754,11 +779,11 @@  discard block
 block discarded – undo
754 779
                 }
755 780
             }
756 781
             if ($returnemptyifnotfound) {        // Not found into alternate dir
757
-                if ($returnemptyifnotfound == 1 || !file_exists($res))
758
-                    return '';
782
+                if ($returnemptyifnotfound == 1 || !file_exists($res)) {
783
+                                    return '';
784
+                }
759 785
             }
760
-        }
761
-        else {    // For an url path
786
+        } else {    // For an url path
762 787
 // We try to get local path of file on filesystem from url
763 788
 // Note that trying to know if a file on disk exist by forging path on disk from url
764 789
 // works only for some web server and some setup. This is bugged when
@@ -853,12 +878,14 @@  discard block
 block discarded – undo
853 878
     static function dol_size($size, $type = '')
854 879
     {
855 880
         //global Globals::$conf;
856
-        if (empty(Globals::$conf->dol_optimize_smallscreen))
857
-            return $size;
858
-        if ($type == 'width' && $size > 250)
859
-            return 250;
860
-        else
861
-            return 10;
881
+        if (empty(Globals::$conf->dol_optimize_smallscreen)) {
882
+                    return $size;
883
+        }
884
+        if ($type == 'width' && $size > 250) {
885
+                    return 250;
886
+        } else {
887
+                    return 10;
888
+        }
862 889
     }
863 890
 
864 891
     /**
@@ -958,9 +985,10 @@  discard block
 block discarded – undo
958 985
     {
959 986
         $forbidden_chars_to_replace = array(" ", "'", "/", "\\", ":", "*", "?", "\"", "<", ">", "|", "[", "]", ",", ";", "=", '°');  // more complete than dol_sanitizeFileName
960 987
         $forbidden_chars_to_remove = array();
961
-        if (is_array($badcharstoreplace))
962
-            $forbidden_chars_to_replace = $badcharstoreplace;
963
-//$forbidden_chars_to_remove=array("(",")");
988
+        if (is_array($badcharstoreplace)) {
989
+                    $forbidden_chars_to_replace = $badcharstoreplace;
990
+        }
991
+        //$forbidden_chars_to_remove=array("(",")");
964 992
 
965 993
         return str_replace($forbidden_chars_to_replace, $newstr, str_replace($forbidden_chars_to_remove, "", $str));
966 994
     }
@@ -996,9 +1024,9 @@  discard block
 block discarded – undo
996 1024
         if (empty($mode)) {
997 1025
             $substitjs["'"] = "\\'";
998 1026
             $substitjs['"'] = "\\'";
999
-        } else if ($mode == 1)
1000
-            $substitjs["'"] = "\\'";
1001
-        else if ($mode == 2) {
1027
+        } else if ($mode == 1) {
1028
+                    $substitjs["'"] = "\\'";
1029
+        } else if ($mode == 2) {
1002 1030
             $substitjs['"'] = '\\"';
1003 1031
         } else if ($mode == 3) {
1004 1032
             $substitjs["'"] = "\\'";
@@ -1020,10 +1048,12 @@  discard block
 block discarded – undo
1020 1048
     {
1021 1049
 // escape quotes and backslashes, newlines, etc.
1022 1050
         $tmp = html_entity_decode($stringtoescape, ENT_COMPAT, 'UTF-8');  // TODO Use htmlspecialchars_decode instead, that make only required change for html tags
1023
-        if (!$keepb)
1024
-            $tmp = strtr($tmp, array("<b>" => '', '</b>' => ''));
1025
-        if (!$keepn)
1026
-            $tmp = strtr($tmp, array("\r" => '\\r', "\n" => '\\n'));
1051
+        if (!$keepb) {
1052
+                    $tmp = strtr($tmp, array("<b>" => '', '</b>' => ''));
1053
+        }
1054
+        if (!$keepn) {
1055
+                    $tmp = strtr($tmp, array("\r" => '\\r', "\n" => '\\n'));
1056
+        }
1027 1057
         return htmlentities($tmp, ENT_COMPAT, 'UTF-8');      // TODO Use htmlspecialchars instead, that make only required change for html tags
1028 1058
     }
1029 1059
 
@@ -1073,8 +1103,9 @@  discard block
 block discarded – undo
1073 1103
     {
1074 1104
        // global Globals::$conf, $user;
1075 1105
 // If syslog module enabled
1076
-        if (empty(Globals::$conf->syslog->enabled))
1077
-            return;
1106
+        if (empty(Globals::$conf->syslog->enabled)) {
1107
+                    return;
1108
+        }
1078 1109
 
1079 1110
         if ($ident < 0) {
1080 1111
             foreach (Globals::$conf->loghandlers as $loghandlerinstance) {
@@ -1088,8 +1119,9 @@  discard block
 block discarded – undo
1088 1119
             if (!in_array($level, $logLevels, true)) {
1089 1120
                 throw new Exception('Incorrect log level');
1090 1121
             }
1091
-            if ($level > Globals::$conf->global->SYSLOG_LEVEL)
1092
-                return;
1122
+            if ($level > Globals::$conf->global->SYSLOG_LEVEL) {
1123
+                            return;
1124
+            }
1093 1125
 
1094 1126
             $message = preg_replace('/password=\'[^\']*\'/', 'password=\'hidden\'', $message); // protection to avoid to have value of password in log
1095 1127
 // If adding log inside HTML page is required
@@ -1114,24 +1146,30 @@  discard block
 block discarded – undo
1114 1146
             );
1115 1147
 
1116 1148
 // This is when server run behind a reverse proxy
1117
-            if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
1118
-                $data['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'] . (empty($_SERVER["REMOTE_ADDR"]) ? '' : '->' . $_SERVER['REMOTE_ADDR']);
1119
-// This is when server run normally on a server
1120
-            else if (!empty($_SERVER["REMOTE_ADDR"]))
1121
-                $data['ip'] = $_SERVER['REMOTE_ADDR'];
1122
-// This is when PHP session is ran inside a web server but not inside a client request (example: init code of apache)
1123
-            else if (!empty($_SERVER['SERVER_ADDR']))
1124
-                $data['ip'] = $_SERVER['SERVER_ADDR'];
1125
-// 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).
1126
-            else if (!empty($_SERVER['COMPUTERNAME']))
1127
-                $data['ip'] = $_SERVER['COMPUTERNAME'] . (empty($_SERVER['USERNAME']) ? '' : '@' . $_SERVER['USERNAME']);
1128
-// 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).
1129
-            else if (!empty($_SERVER['LOGNAME']))
1130
-                $data['ip'] = '???@' . $_SERVER['LOGNAME'];
1131
-// Loop on each log handler and send output
1149
+            if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
1150
+                            $data['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'] . (empty($_SERVER["REMOTE_ADDR"]) ? '' : '->' . $_SERVER['REMOTE_ADDR']);
1151
+            }
1152
+            // This is when server run normally on a server
1153
+            else if (!empty($_SERVER["REMOTE_ADDR"])) {
1154
+                            $data['ip'] = $_SERVER['REMOTE_ADDR'];
1155
+            }
1156
+            // This is when PHP session is ran inside a web server but not inside a client request (example: init code of apache)
1157
+            else if (!empty($_SERVER['SERVER_ADDR'])) {
1158
+                            $data['ip'] = $_SERVER['SERVER_ADDR'];
1159
+            }
1160
+            // 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).
1161
+            else if (!empty($_SERVER['COMPUTERNAME'])) {
1162
+                            $data['ip'] = $_SERVER['COMPUTERNAME'] . (empty($_SERVER['USERNAME']) ? '' : '@' . $_SERVER['USERNAME']);
1163
+            }
1164
+            // 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).
1165
+            else if (!empty($_SERVER['LOGNAME'])) {
1166
+                            $data['ip'] = '???@' . $_SERVER['LOGNAME'];
1167
+            }
1168
+            // Loop on each log handler and send output
1132 1169
             foreach (Globals::$conf->loghandlers as $loghandlerinstance) {
1133
-                if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler)
1134
-                    continue;
1170
+                if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
1171
+                                    continue;
1172
+                }
1135 1173
                 $loghandlerinstance->export($data, $suffixinfilename);
1136 1174
             }
1137 1175
             unset($data);
@@ -1187,13 +1225,15 @@  discard block
 block discarded – undo
1187 1225
 
1188 1226
 // Show title
1189 1227
         $showtitle = 1;
1190
-        if (!empty(Globals::$conf->dol_optimize_smallscreen))
1191
-            $showtitle = 0;
1228
+        if (!empty(Globals::$conf->dol_optimize_smallscreen)) {
1229
+                    $showtitle = 0;
1230
+        }
1192 1231
         if (!empty($title) && $showtitle) {
1193 1232
             $limittitle = 30;
1194 1233
             $out .= '<a class="tabTitle">';
1195
-            if ($picto)
1196
-                $out .= img_picto($title, ($pictoisfullpath ? '' : 'object_') . $picto, '', $pictoisfullpath) . ' ';
1234
+            if ($picto) {
1235
+                            $out .= img_picto($title, ($pictoisfullpath ? '' : 'object_') . $picto, '', $pictoisfullpath) . ' ';
1236
+            }
1197 1237
             $out .= '<span class="tabTitleText">' . dol_trunc($title, $limittitle) . '</span>';
1198 1238
             $out .= '</a>';
1199 1239
         }
@@ -1202,12 +1242,14 @@  discard block
 block discarded – undo
1202 1242
         $maxkey = -1;
1203 1243
         if (is_array($links) && !empty($links)) {
1204 1244
             $keys = array_keys($links);
1205
-            if (count($keys))
1206
-                $maxkey = max($keys);
1245
+            if (count($keys)) {
1246
+                            $maxkey = max($keys);
1247
+            }
1207 1248
         }
1208 1249
 
1209
-        if (!empty(Globals::$conf->dol_optimize_smallscreen))
1210
-            Globals::$conf->global->MAIN_MAXTABS_IN_CARD = 2;
1250
+        if (!empty(Globals::$conf->dol_optimize_smallscreen)) {
1251
+                    Globals::$conf->global->MAIN_MAXTABS_IN_CARD = 2;
1252
+        }
1211 1253
 
1212 1254
 // Show tabs
1213 1255
         $bactive = false;
@@ -1220,8 +1262,9 @@  discard block
 block discarded – undo
1220 1262
         for ($i = 0; $i <= $maxkey; $i++) {
1221 1263
             if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
1222 1264
 // If active tab is already present
1223
-                if ($i >= $limittoshow)
1224
-                    $limittoshow--;
1265
+                if ($i >= $limittoshow) {
1266
+                                    $limittoshow--;
1267
+                }
1225 1268
             }
1226 1269
         }
1227 1270
 
@@ -1262,12 +1305,12 @@  discard block
 block discarded – undo
1262 1305
                 }
1263 1306
                 $outmore .= '<div class="popuptab wordwrap" style="display:inherit;">';
1264 1307
                 if (isset($links[$i][2]) && $links[$i][2] == 'image') {
1265
-                    if (!empty($links[$i][0]))
1266
-                        $outmore .= '<a class="tabimage' . ($morecss ? ' ' . $morecss : '') . '" href="' . $links[$i][0] . '">' . $links[$i][1] . '</a>' . "\n";
1267
-                    else
1268
-                        $outmore .= '<span class="tabspan">' . $links[$i][1] . '</span>' . "\n";
1269
-                }
1270
-                else if (!empty($links[$i][1])) {
1308
+                    if (!empty($links[$i][0])) {
1309
+                                            $outmore .= '<a class="tabimage' . ($morecss ? ' ' . $morecss : '') . '" href="' . $links[$i][0] . '">' . $links[$i][1] . '</a>' . "\n";
1310
+                    } else {
1311
+                                            $outmore .= '<span class="tabspan">' . $links[$i][1] . '</span>' . "\n";
1312
+                    }
1313
+                } else if (!empty($links[$i][1])) {
1271 1314
                     $outmore .= '<a' . (!empty($links[$i][2]) ? ' id="' . $links[$i][2] . '"' : '') . ' class="wordwrap inline-block' . ($morecss ? ' ' . $morecss : '') . '" href="' . $links[$i][0] . '">';
1272 1315
                     $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.
1273 1316
                     $outmore .= '</a>' . "\n";
@@ -1278,8 +1321,9 @@  discard block
 block discarded – undo
1278 1321
             }
1279 1322
             $displaytab = $i;
1280 1323
         }
1281
-        if ($popuptab)
1282
-            $outmore .= '</div>';
1324
+        if ($popuptab) {
1325
+                    $outmore .= '</div>';
1326
+        }
1283 1327
 
1284 1328
         if ($displaytab > $limittoshow) {
1285 1329
             $left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');
@@ -1302,8 +1346,9 @@  discard block
 block discarded – undo
1302 1346
 
1303 1347
         $out .= "</div>\n";
1304 1348
 
1305
-        if (!$notab || $notab == -1)
1306
-            $out .= "\n" . '<div class="tabBar' . ($notab == -1 ? '' : ' tabBarWithBottom') . '">' . "\n";
1349
+        if (!$notab || $notab == -1) {
1350
+                    $out .= "\n" . '<div class="tabBar' . ($notab == -1 ? '' : ' tabBarWithBottom') . '">' . "\n";
1351
+        }
1307 1352
 
1308 1353
         $parameters = array('tabname' => $active, 'out' => $out);
1309 1354
         $reshook = $hookmanager->executeHooks('printTabsHead', $parameters); // This hook usage is called just before output the head of tabs. Take also a look at "completeTabsHead"
@@ -1333,10 +1378,11 @@  discard block
 block discarded – undo
1333 1378
      */
1334 1379
     static function dol_get_fiche_end($notab = 0)
1335 1380
     {
1336
-        if (!$notab || $notab == -1)
1337
-            return "\n</div>\n";
1338
-        else
1339
-            return '';
1381
+        if (!$notab || $notab == -1) {
1382
+                    return "\n</div>\n";
1383
+        } else {
1384
+                    return '';
1385
+        }
1340 1386
     }
1341 1387
 
1342 1388
     /**
@@ -1368,40 +1414,55 @@  discard block
 block discarded – undo
1368 1414
         $showimage = 1;
1369 1415
         $entity = (empty($object->entity) ? Globals::$conf->entity : $object->entity);
1370 1416
         $showbarcode = empty(Globals::$conf->barcode->enabled) ? 0 : ($object->barcode ? 1 : 0);
1371
-        if (!empty(Globals::$conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance))
1372
-            $showbarcode = 0;
1417
+        if (!empty(Globals::$conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
1418
+                    $showbarcode = 0;
1419
+        }
1373 1420
         $modulepart = 'unknown';
1374 1421
 
1375
-        if ($object->element == 'societe')
1376
-            $modulepart = 'societe';
1377
-        if ($object->element == 'contact')
1378
-            $modulepart = 'contact';
1379
-        if ($object->element == 'member')
1380
-            $modulepart = 'memberphoto';
1381
-        if ($object->element == 'user')
1382
-            $modulepart = 'userphoto';
1383
-        if ($object->element == 'product')
1384
-            $modulepart = 'product';
1422
+        if ($object->element == 'societe') {
1423
+                    $modulepart = 'societe';
1424
+        }
1425
+        if ($object->element == 'contact') {
1426
+                    $modulepart = 'contact';
1427
+        }
1428
+        if ($object->element == 'member') {
1429
+                    $modulepart = 'memberphoto';
1430
+        }
1431
+        if ($object->element == 'user') {
1432
+                    $modulepart = 'userphoto';
1433
+        }
1434
+        if ($object->element == 'product') {
1435
+                    $modulepart = 'product';
1436
+        }
1385 1437
 
1386 1438
         if (class_exists("Imagick")) {
1387
-            if ($object->element == 'propal')
1388
-                $modulepart = 'propal';
1389
-            if ($object->element == 'commande')
1390
-                $modulepart = 'commande';
1391
-            if ($object->element == 'facture')
1392
-                $modulepart = 'facture';
1393
-            if ($object->element == 'fichinter')
1394
-                $modulepart = 'ficheinter';
1395
-            if ($object->element == 'contrat')
1396
-                $modulepart = 'contract';
1397
-            if ($object->element == 'supplier_proposal')
1398
-                $modulepart = 'supplier_proposal';
1399
-            if ($object->element == 'order_supplier')
1400
-                $modulepart = 'supplier_order';
1401
-            if ($object->element == 'invoice_supplier')
1402
-                $modulepart = 'supplier_invoice';
1403
-            if ($object->element == 'expensereport')
1404
-                $modulepart = 'expensereport';
1439
+            if ($object->element == 'propal') {
1440
+                            $modulepart = 'propal';
1441
+            }
1442
+            if ($object->element == 'commande') {
1443
+                            $modulepart = 'commande';
1444
+            }
1445
+            if ($object->element == 'facture') {
1446
+                            $modulepart = 'facture';
1447
+            }
1448
+            if ($object->element == 'fichinter') {
1449
+                            $modulepart = 'ficheinter';
1450
+            }
1451
+            if ($object->element == 'contrat') {
1452
+                            $modulepart = 'contract';
1453
+            }
1454
+            if ($object->element == 'supplier_proposal') {
1455
+                            $modulepart = 'supplier_proposal';
1456
+            }
1457
+            if ($object->element == 'order_supplier') {
1458
+                            $modulepart = 'supplier_order';
1459
+            }
1460
+            if ($object->element == 'invoice_supplier') {
1461
+                            $modulepart = 'supplier_invoice';
1462
+            }
1463
+            if ($object->element == 'expensereport') {
1464
+                            $modulepart = 'expensereport';
1465
+            }
1405 1466
         }
1406 1467
 
1407 1468
         if ($object->element == 'product') {
@@ -1409,11 +1470,12 @@  discard block
 block discarded – undo
1409 1470
             $cssclass = 'photoref';
1410 1471
             $showimage = $object->is_photo_available(Globals::$conf->product->multidir_output[$entity]);
1411 1472
             $maxvisiblephotos = (isset(Globals::$conf->global->PRODUCT_MAX_VISIBLE_PHOTO) ? Globals::$conf->global->PRODUCT_MAX_VISIBLE_PHOTO : 5);
1412
-            if (Globals::$conf->browser->layout == 'phone')
1413
-                $maxvisiblephotos = 1;
1414
-            if ($showimage)
1415
-                $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $object->show_photos('product', Globals::$conf->product->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, $width, 0) . '</div>';
1416
-            else {
1473
+            if (Globals::$conf->browser->layout == 'phone') {
1474
+                            $maxvisiblephotos = 1;
1475
+            }
1476
+            if ($showimage) {
1477
+                            $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $object->show_photos('product', Globals::$conf->product->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, $width, 0) . '</div>';
1478
+            } else {
1417 1479
                 if (!empty(Globals::$conf->global->PRODUCT_NODISPLAYIFNOPHOTO)) {
1418 1480
                     $nophoto = '';
1419 1481
                     $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"></div>';
@@ -1429,11 +1491,12 @@  discard block
 block discarded – undo
1429 1491
             $cssclass = 'photoref';
1430 1492
             $showimage = $object->is_photo_available(Globals::$conf->ticket->multidir_output[$entity] . '/' . $object->track_id);
1431 1493
             $maxvisiblephotos = (isset(Globals::$conf->global->TICKETSUP_MAX_VISIBLE_PHOTO) ? Globals::$conf->global->TICKETSUP_MAX_VISIBLE_PHOTO : 2);
1432
-            if (Globals::$conf->browser->layout == 'phone')
1433
-                $maxvisiblephotos = 1;
1434
-            if ($showimage)
1435
-                $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $object->show_photos('ticket', Globals::$conf->ticket->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, $width, 0) . '</div>';
1436
-            else {
1494
+            if (Globals::$conf->browser->layout == 'phone') {
1495
+                            $maxvisiblephotos = 1;
1496
+            }
1497
+            if ($showimage) {
1498
+                            $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $object->show_photos('ticket', Globals::$conf->ticket->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, $width, 0) . '</div>';
1499
+            } else {
1437 1500
                 if (!empty(Globals::$conf->global->TICKETSUP_NODISPLAYIFNOPHOTO)) {
1438 1501
                     $nophoto = '';
1439 1502
                     $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref"></div>';
@@ -1458,8 +1521,10 @@  discard block
 block discarded – undo
1458 1521
                         } else {
1459 1522
                             $subdir = get_exdir($object->id, 0, 0, 1, $object, $modulepart);
1460 1523
                         }
1461
-                        if (empty($subdir))
1462
-                            $subdir = 'errorgettingsubdirofobject'; // Protection to avoid to return empty path
1524
+                        if (empty($subdir)) {
1525
+                                                    $subdir = 'errorgettingsubdirofobject';
1526
+                        }
1527
+                        // Protection to avoid to return empty path
1463 1528
 
1464 1529
                         $filepath = $dir_output . $subdir . "/";
1465 1530
 
@@ -1480,14 +1545,16 @@  discard block
 block discarded – undo
1480 1545
                                 if (empty(Globals::$conf->global->MAIN_DISABLE_PDF_THUMBS)) {  // If you experienc trouble with pdf thumb generation and imagick, you can disable here.
1481 1546
                                     include_once DOL_BASE_PATH . '/core/lib/files.lib.php';
1482 1547
                                     $ret = dol_convert_file($file, 'png', $fileimage);
1483
-                                    if ($ret < 0)
1484
-                                        $error++;
1548
+                                    if ($ret < 0) {
1549
+                                                                            $error++;
1550
+                                    }
1485 1551
                                 }
1486 1552
                             }
1487 1553
 
1488 1554
                             $heightforphotref = 70;
1489
-                            if (!empty(Globals::$conf->dol_optimize_smallscreen))
1490
-                                $heightforphotref = 60;
1555
+                            if (!empty(Globals::$conf->dol_optimize_smallscreen)) {
1556
+                                                            $heightforphotref = 60;
1557
+                            }
1491 1558
                             // Si fichier png PDF d'1 page trouve
1492 1559
                             if (file_exists($fileimage)) {
1493 1560
                                 $phototoshow = '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
@@ -1523,8 +1590,10 @@  discard block
 block discarded – undo
1523 1590
                         $width = 14;
1524 1591
                         $cssclass = 'photorefcenter';
1525 1592
                         $picto = $object->picto;
1526
-                        if ($object->element == 'project' && !$object->public)
1527
-                            $picto = 'project'; // instead of projectpub
1593
+                        if ($object->element == 'project' && !$object->public) {
1594
+                                                    $picto = 'project';
1595
+                        }
1596
+                        // instead of projectpub
1528 1597
                         $nophoto = img_picto('', 'object_' . $picto, '', false, 1);
1529 1598
                     }
1530 1599
                     $morehtmlleft .= '<!-- No photo to show -->';
@@ -1535,8 +1604,9 @@  discard block
 block discarded – undo
1535 1604
             }
1536 1605
         }
1537 1606
 
1538
-        if ($showbarcode)
1539
-            $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $form->showbarcode($object) . '</div>';
1607
+        if ($showbarcode) {
1608
+                    $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">' . $form->showbarcode($object) . '</div>';
1609
+        }
1540 1610
 
1541 1611
         if ($object->element == 'societe') {
1542 1612
             if (!empty(Globals::$conf->use_javascript_ajax) && $user->rights->societe->creer && !empty(Globals::$conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
@@ -1560,35 +1630,37 @@  discard block
 block discarded – undo
1560 1630
             }
1561 1631
         } elseif (in_array($object->element, array('facture', 'invoice', 'invoice_supplier', 'chargesociales', 'loan'))) {
1562 1632
             $tmptxt = $object->getLibStatut(6, $object->totalpaye);
1563
-            if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || Globals::$conf->browser->layout == 'phone')
1564
-                $tmptxt = $object->getLibStatut(5, $object->totalpaye);
1633
+            if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || Globals::$conf->browser->layout == 'phone') {
1634
+                            $tmptxt = $object->getLibStatut(5, $object->totalpaye);
1635
+            }
1565 1636
             $morehtmlstatus .= $tmptxt;
1566
-        }
1567
-        elseif ($object->element == 'contrat' || $object->element == 'contract') {
1568
-            if ($object->statut == 0)
1569
-                $morehtmlstatus .= $object->getLibStatut(5);
1570
-            else
1571
-                $morehtmlstatus .= $object->getLibStatut(4);
1572
-        }
1573
-        elseif ($object->element == 'facturerec') {
1574
-            if ($object->frequency == 0)
1575
-                $morehtmlstatus .= $object->getLibStatut(2);
1576
-            else
1577
-                $morehtmlstatus .= $object->getLibStatut(5);
1578
-        }
1579
-        elseif ($object->element == 'project_task') {
1637
+        } elseif ($object->element == 'contrat' || $object->element == 'contract') {
1638
+            if ($object->statut == 0) {
1639
+                            $morehtmlstatus .= $object->getLibStatut(5);
1640
+            } else {
1641
+                            $morehtmlstatus .= $object->getLibStatut(4);
1642
+            }
1643
+        } elseif ($object->element == 'facturerec') {
1644
+            if ($object->frequency == 0) {
1645
+                            $morehtmlstatus .= $object->getLibStatut(2);
1646
+            } else {
1647
+                            $morehtmlstatus .= $object->getLibStatut(5);
1648
+            }
1649
+        } elseif ($object->element == 'project_task') {
1580 1650
             $object->fk_statut = 1;
1581
-            if ($object->progress > 0)
1582
-                $object->fk_statut = 2;
1583
-            if ($object->progress >= 100)
1584
-                $object->fk_statut = 3;
1651
+            if ($object->progress > 0) {
1652
+                            $object->fk_statut = 2;
1653
+            }
1654
+            if ($object->progress >= 100) {
1655
+                            $object->fk_statut = 3;
1656
+            }
1585 1657
             $tmptxt = $object->getLibStatut(5);
1586 1658
             $morehtmlstatus .= $tmptxt;  // No status on task
1587
-        }
1588
-        else { // Generic case
1659
+        } else { // Generic case
1589 1660
             $tmptxt = $object->getLibStatut(6);
1590
-            if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || Globals::$conf->browser->layout == 'phone')
1591
-                $tmptxt = $object->getLibStatut(5);
1661
+            if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3) || Globals::$conf->browser->layout == 'phone') {
1662
+                            $tmptxt = $object->getLibStatut(5);
1663
+            }
1592 1664
             $morehtmlstatus .= $tmptxt;
1593 1665
         }
1594 1666
 
@@ -1602,13 +1674,15 @@  discard block
 block discarded – undo
1602 1674
         }
1603 1675
 
1604 1676
 // Add alias for thirdparty
1605
-        if (!empty($object->name_alias))
1606
-            $morehtmlref .= '<div class="refidno">' . $object->name_alias . '</div>';
1677
+        if (!empty($object->name_alias)) {
1678
+                    $morehtmlref .= '<div class="refidno">' . $object->name_alias . '</div>';
1679
+        }
1607 1680
 
1608 1681
 // Add label
1609 1682
         if ($object->element == 'product' || $object->element == 'bank_account' || $object->element == 'project_task') {
1610
-            if (!empty($object->label))
1611
-                $morehtmlref .= '<div class="refidno">' . $object->label . '</div>';
1683
+            if (!empty($object->label)) {
1684
+                            $morehtmlref .= '<div class="refidno">' . $object->label . '</div>';
1685
+            }
1612 1686
         }
1613 1687
 
1614 1688
         if (method_exists($object, 'getBannerAddress') && $object->element != 'product' && $object->element != 'bookmark' && $object->element != 'ecm_directories' && $object->element != 'ecm_files') {
@@ -1641,15 +1715,19 @@  discard block
 block discarded – undo
1641 1715
     {
1642 1716
        // global Globals::$conf, $langs;
1643 1717
         $ret = '';
1644
-        if ($fieldrequired)
1645
-            $ret .= '<span class="fieldrequired">';
1646
-        if ((Globals::$conf->dol_use_jmobile != 4))
1647
-            $ret .= '<label for="' . $fieldkey . '">';
1718
+        if ($fieldrequired) {
1719
+                    $ret .= '<span class="fieldrequired">';
1720
+        }
1721
+        if ((Globals::$conf->dol_use_jmobile != 4)) {
1722
+                    $ret .= '<label for="' . $fieldkey . '">';
1723
+        }
1648 1724
         $ret .= $langs->trans($langkey);
1649
-        if ((Globals::$conf->dol_use_jmobile != 4))
1650
-            $ret .= '</label>';
1651
-        if ($fieldrequired)
1652
-            $ret .= '</span>';
1725
+        if ((Globals::$conf->dol_use_jmobile != 4)) {
1726
+                    $ret .= '</label>';
1727
+        }
1728
+        if ($fieldrequired) {
1729
+                    $ret .= '</span>';
1730
+        }
1653 1731
         return $ret;
1654 1732
     }
1655 1733
 
@@ -1664,8 +1742,9 @@  discard block
 block discarded – undo
1664 1742
     {
1665 1743
        // global $bc;
1666 1744
         $ret = ' ' . $bc[$var];
1667
-        if ($moreclass)
1668
-            $ret = preg_replace('/class=\"/', 'class="' . $moreclass . ' ', $ret);
1745
+        if ($moreclass) {
1746
+                    $ret = preg_replace('/class=\"/', 'class="' . $moreclass . ' ', $ret);
1747
+        }
1669 1748
         return $ret;
1670 1749
     }
1671 1750
 
@@ -1696,18 +1775,18 @@  discard block
 block discarded – undo
1696 1775
             if ($object->state) {
1697 1776
                 $ret .= ($ret ? ", " : '') . $object->state;
1698 1777
             }
1699
-            if ($object->zip)
1700
-                $ret .= ($ret ? ", " : '') . $object->zip;
1701
-        }
1702
-        else if (in_array($object->country_code, array('GB', 'UK'))) { // UK: title firstname name \n address lines \n town state \n zip \n country
1778
+            if ($object->zip) {
1779
+                            $ret .= ($ret ? ", " : '') . $object->zip;
1780
+            }
1781
+        } else if (in_array($object->country_code, array('GB', 'UK'))) { // UK: title firstname name \n address lines \n town state \n zip \n country
1703 1782
             $ret .= ($ret ? $sep : '' ) . $object->town;
1704 1783
             if ($object->state) {
1705 1784
                 $ret .= ($ret ? ", " : '') . $object->state;
1706 1785
             }
1707
-            if ($object->zip)
1708
-                $ret .= ($ret ? $sep : '' ) . $object->zip;
1709
-        }
1710
-        else if (in_array($object->country_code, array('ES', 'TR'))) { // ES: title firstname name \n address lines \n zip town \n state \n country
1786
+            if ($object->zip) {
1787
+                            $ret .= ($ret ? $sep : '' ) . $object->zip;
1788
+            }
1789
+        } else if (in_array($object->country_code, array('ES', 'TR'))) { // ES: title firstname name \n address lines \n zip town \n state \n country
1711 1790
             $ret .= ($ret ? $sep : '' ) . $object->zip;
1712 1791
             $ret .= ($object->town ? (($object->zip ? ' ' : '') . $object->town) : '');
1713 1792
             if ($object->state) {
@@ -1724,8 +1803,9 @@  discard block
 block discarded – undo
1724 1803
                 $ret .= ($ret ? ", " : '') . $object->state;
1725 1804
             }
1726 1805
         }
1727
-        if (!is_object($outputlangs))
1728
-            $outputlangs = $langs;
1806
+        if (!is_object($outputlangs)) {
1807
+                    $outputlangs = $langs;
1808
+        }
1729 1809
         if ($withcountry) {
1730 1810
             $langs->load("dict");
1731 1811
             $ret .= ($object->country_code ? ($ret ? $sep : '') . $outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country" . $object->country_code)) : '');
@@ -1746,8 +1826,9 @@  discard block
 block discarded – undo
1746 1826
     {
1747 1827
         if ((abs($ts) <= 0x7FFFFFFF)) { // check if number in 32-bit signed range
1748 1828
             return ($is_gmt) ? @gmstrftime($fmt, $ts) : @strftime($fmt, $ts);
1749
-        } else
1750
-            return 'Error date into a not supported range';
1829
+        } else {
1830
+                    return 'Error date into a not supported range';
1831
+        }
1751 1832
     }
1752 1833
 
1753 1834
     /**
@@ -1793,10 +1874,12 @@  discard block
 block discarded – undo
1793 1874
                 }
1794 1875
             }
1795 1876
         }
1796
-        if (!is_object($outputlangs))
1797
-            $outputlangs = $langs;
1798
-        if (!$format)
1799
-            $format = 'daytextshort';
1877
+        if (!is_object($outputlangs)) {
1878
+                    $outputlangs = $langs;
1879
+        }
1880
+        if (!$format) {
1881
+                    $format = 'daytextshort';
1882
+        }
1800 1883
         $reduceformat = (!empty(Globals::$conf->dol_optimize_smallscreen) && in_array($format, array('day', 'dayhour'))) ? 1 : 0;
1801 1884
         $formatwithoutreduce = preg_replace('/reduceformat/', '', $format);
1802 1885
         if ($formatwithoutreduce != $format) {
@@ -1805,40 +1888,46 @@  discard block
 block discarded – undo
1805 1888
         }  // so format 'dayreduceformat' is processed like day
1806 1889
 // Change predefined format into computer format. If found translation in lang file we use it, otherwise we use default.
1807 1890
 // TODO Add format daysmallyear and dayhoursmallyear
1808
-        if ($format == 'day')
1809
-            $format = ($outputlangs->trans("FormatDateShort") != "FormatDateShort" ? $outputlangs->trans("FormatDateShort") : Globals::$conf->format_date_short);
1810
-        else if ($format == 'hour')
1811
-            $format = ($outputlangs->trans("FormatHourShort") != "FormatHourShort" ? $outputlangs->trans("FormatHourShort") : Globals::$conf->format_hour_short);
1812
-        else if ($format == 'hourduration')
1813
-            $format = ($outputlangs->trans("FormatHourShortDuration") != "FormatHourShortDuration" ? $outputlangs->trans("FormatHourShortDuration") : Globals::$conf->format_hour_short_duration);
1814
-        else if ($format == 'daytext')
1815
-            $format = ($outputlangs->trans("FormatDateText") != "FormatDateText" ? $outputlangs->trans("FormatDateText") : Globals::$conf->format_date_text);
1816
-        else if ($format == 'daytextshort')
1817
-// Notice: Undefined property: stdClass::$format_date_text_short in \alixar\dolibarr\htdocs\core\lib\functions.lib.php on line 1781
1818
-            $format = ($outputlangs->trans("FormatDateTextShort") != "FormatDateTextShort" ? $outputlangs->trans("FormatDateTextShort") : Globals::$conf->format_date_text_short);
1819
-        else if ($format == 'dayhour')
1820
-            $format = ($outputlangs->trans("FormatDateHourShort") != "FormatDateHourShort" ? $outputlangs->trans("FormatDateHourShort") : Globals::$conf->format_date_hour_short);
1821
-        else if ($format == 'dayhoursec')
1822
-            $format = ($outputlangs->trans("FormatDateHourSecShort") != "FormatDateHourSecShort" ? $outputlangs->trans("FormatDateHourSecShort") : Globals::$conf->format_date_hour_sec_short);
1823
-        else if ($format == 'dayhourtext')
1824
-            $format = ($outputlangs->trans("FormatDateHourText") != "FormatDateHourText" ? $outputlangs->trans("FormatDateHourText") : Globals::$conf->format_date_hour_text);
1825
-        else if ($format == 'dayhourtextshort')
1826
-            $format = ($outputlangs->trans("FormatDateHourTextShort") != "FormatDateHourTextShort" ? $outputlangs->trans("FormatDateHourTextShort") : Globals::$conf->format_date_hour_text_short);
1827
-// Format not sensitive to language
1828
-        else if ($format == 'dayhourlog')
1829
-            $format = '%Y%m%d%H%M%S';
1830
-        else if ($format == 'dayhourldap')
1831
-            $format = '%Y%m%d%H%M%SZ';
1832
-        else if ($format == 'dayhourxcard')
1833
-            $format = '%Y%m%dT%H%M%SZ';
1834
-        else if ($format == 'dayxcard')
1835
-            $format = '%Y%m%d';
1836
-        else if ($format == 'dayrfc')
1837
-            $format = '%Y-%m-%d';             // DATE_RFC3339
1838
-        else if ($format == 'dayhourrfc')
1839
-            $format = '%Y-%m-%dT%H:%M:%SZ';   // DATETIME RFC3339
1840
-        else if ($format == 'standard')
1841
-            $format = '%Y-%m-%d %H:%M:%S';
1891
+        if ($format == 'day') {
1892
+                    $format = ($outputlangs->trans("FormatDateShort") != "FormatDateShort" ? $outputlangs->trans("FormatDateShort") : Globals::$conf->format_date_short);
1893
+        } else if ($format == 'hour') {
1894
+                    $format = ($outputlangs->trans("FormatHourShort") != "FormatHourShort" ? $outputlangs->trans("FormatHourShort") : Globals::$conf->format_hour_short);
1895
+        } else if ($format == 'hourduration') {
1896
+                    $format = ($outputlangs->trans("FormatHourShortDuration") != "FormatHourShortDuration" ? $outputlangs->trans("FormatHourShortDuration") : Globals::$conf->format_hour_short_duration);
1897
+        } else if ($format == 'daytext') {
1898
+                    $format = ($outputlangs->trans("FormatDateText") != "FormatDateText" ? $outputlangs->trans("FormatDateText") : Globals::$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
1901
+            $format = ($outputlangs->trans("FormatDateTextShort") != "FormatDateTextShort" ? $outputlangs->trans("FormatDateTextShort") : Globals::$conf->format_date_text_short);
1902
+        } else if ($format == 'dayhour') {
1903
+                    $format = ($outputlangs->trans("FormatDateHourShort") != "FormatDateHourShort" ? $outputlangs->trans("FormatDateHourShort") : Globals::$conf->format_date_hour_short);
1904
+        } else if ($format == 'dayhoursec') {
1905
+                    $format = ($outputlangs->trans("FormatDateHourSecShort") != "FormatDateHourSecShort" ? $outputlangs->trans("FormatDateHourSecShort") : Globals::$conf->format_date_hour_sec_short);
1906
+        } else if ($format == 'dayhourtext') {
1907
+                    $format = ($outputlangs->trans("FormatDateHourText") != "FormatDateHourText" ? $outputlangs->trans("FormatDateHourText") : Globals::$conf->format_date_hour_text);
1908
+        } else if ($format == 'dayhourtextshort') {
1909
+                    $format = ($outputlangs->trans("FormatDateHourTextShort") != "FormatDateHourTextShort" ? $outputlangs->trans("FormatDateHourTextShort") : Globals::$conf->format_date_hour_text_short);
1910
+        }
1911
+        // Format not sensitive to language
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
+        }
1842 1931
 
1843 1932
         if ($reduceformat) {
1844 1933
             $format = str_replace('%Y', '%y', $format);
@@ -1846,8 +1935,10 @@  discard block
 block discarded – undo
1846 1935
         }
1847 1936
 
1848 1937
 // If date undefined or "", we return ""
1849
-        if (dol_strlen($time) == 0)
1850
-            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)
1851 1942
 
1852 1943
 
1853 1944
 
@@ -1915,8 +2006,9 @@  discard block
 block discarded – undo
1915 2006
                 $timetouse = $time + $offsettz + $offsetdst; // TODO Replace this with static function Date PHP. We also should not use anymore offsettz and offsetdst but only offsettzstring.
1916 2007
 
1917 2008
                 $ret = adodb_strftime($format, $timetouse, $to_gmt);
1918
-            } else
1919
-                $ret = 'Bad value ' . $time . ' for date';
2009
+            } else {
2010
+                            $ret = 'Bad value ' . $time . ' for date';
2011
+            }
1920 2012
         }
1921 2013
 
1922 2014
         if (preg_match('/__b__/i', $format)) {
@@ -1987,10 +2079,14 @@  discard block
 block discarded – undo
1987 2079
        // global Globals::$conf;
1988 2080
 
1989 2081
         $usealternatemethod = false;
1990
-        if ($timestamp <= 0)
1991
-            $usealternatemethod = true;    // <= 1970
1992
-        if ($timestamp >= 2145913200)
1993
-            $usealternatemethod = true;  // >= 2038
2082
+        if ($timestamp <= 0) {
2083
+                    $usealternatemethod = true;
2084
+        }
2085
+        // <= 1970
2086
+        if ($timestamp >= 2145913200) {
2087
+                    $usealternatemethod = true;
2088
+        }
2089
+        // >= 2038
1994 2090
 
1995 2091
         if ($usealternatemethod) {
1996 2092
             $arrayinfo = adodb_getdate($timestamp, $fast);
@@ -2025,27 +2121,36 @@  discard block
 block discarded – undo
2025 2121
        // global Globals::$conf;
2026 2122
 //print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -";
2027 2123
 // Clean parameters
2028
-        if ($hour == -1 || empty($hour))
2029
-            $hour = 0;
2030
-        if ($minute == -1 || empty($minute))
2031
-            $minute = 0;
2032
-        if ($second == -1 || empty($second))
2033
-            $second = 0;
2124
+        if ($hour == -1 || empty($hour)) {
2125
+                    $hour = 0;
2126
+        }
2127
+        if ($minute == -1 || empty($minute)) {
2128
+                    $minute = 0;
2129
+        }
2130
+        if ($second == -1 || empty($second)) {
2131
+                    $second = 0;
2132
+        }
2034 2133
 
2035 2134
 // Check parameters
2036 2135
         if ($check) {
2037
-            if (!$month || !$day)
2038
-                return '';
2039
-            if ($day > 31)
2040
-                return '';
2041
-            if ($month > 12)
2042
-                return '';
2043
-            if ($hour < 0 || $hour > 24)
2044
-                return '';
2045
-            if ($minute < 0 || $minute > 60)
2046
-                return '';
2047
-            if ($second < 0 || $second > 60)
2048
-                return '';
2136
+            if (!$month || !$day) {
2137
+                            return '';
2138
+            }
2139
+            if ($day > 31) {
2140
+                            return '';
2141
+            }
2142
+            if ($month > 12) {
2143
+                            return '';
2144
+            }
2145
+            if ($hour < 0 || $hour > 24) {
2146
+                            return '';
2147
+            }
2148
+            if ($minute < 0 || $minute > 60) {
2149
+                            return '';
2150
+            }
2151
+            if ($second < 0 || $second > 60) {
2152
+                            return '';
2153
+            }
2049 2154
         }
2050 2155
 
2051 2156
         if (method_exists('DateTime', 'getTimestamp')) {
@@ -2102,8 +2207,10 @@  discard block
 block discarded – undo
2102 2207
 
2103 2208
 // Note that gmmktime and mktime return same value (GMT) when used without parameters
2104 2209
 //if ($mode == 'gmt') $ret=gmmktime(); // Strict Standards: gmmktime(): You should be using the time() static function instead
2105
-        if ($mode == 'gmt')
2106
-            $ret = time(); // Time for now at greenwich.
2210
+        if ($mode == 'gmt') {
2211
+                    $ret = time();
2212
+        }
2213
+        // Time for now at greenwich.
2107 2214
         else if ($mode == 'tzserver') {  // Time for now with PHP server timezone added
2108 2215
             require_once DOL_BASE_PATH . '/core/lib/date.lib.php';
2109 2216
             $tzsecond = getServerTimeZoneInt('now');    // Contains tz+dayling saving time
@@ -2137,8 +2244,9 @@  discard block
 block discarded – undo
2137 2244
        // global Globals::$conf, $langs;
2138 2245
         $level = 1024;
2139 2246
 
2140
-        if (!empty(Globals::$conf->dol_optimize_smallscreen))
2141
-            $shortunit = 1;
2247
+        if (!empty(Globals::$conf->dol_optimize_smallscreen)) {
2248
+                    $shortunit = 1;
2249
+        }
2142 2250
 
2143 2251
 // Set value text
2144 2252
         if (empty($shortvalue) || $size < ($level * 10)) {
@@ -2173,19 +2281,23 @@  discard block
 block discarded – undo
2173 2281
     {
2174 2282
        // global $langs;
2175 2283
 
2176
-        if (empty($url))
2177
-            return '';
2284
+        if (empty($url)) {
2285
+                    return '';
2286
+        }
2178 2287
 
2179 2288
         $link = '<a href="';
2180
-        if (!preg_match('/^http/i', $url))
2181
-            $link .= 'http://';
2289
+        if (!preg_match('/^http/i', $url)) {
2290
+                    $link .= 'http://';
2291
+        }
2182 2292
         $link .= $url;
2183 2293
         $link .= '"';
2184
-        if ($target)
2185
-            $link .= ' target="' . $target . '"';
2294
+        if ($target) {
2295
+                    $link .= ' target="' . $target . '"';
2296
+        }
2186 2297
         $link .= '>';
2187
-        if (!preg_match('/^http/i', $url))
2188
-            $link .= 'http://';
2298
+        if (!preg_match('/^http/i', $url)) {
2299
+                    $link .= 'http://';
2300
+        }
2189 2301
         $link .= dol_trunc($url, $max);
2190 2302
         $link .= '</a>';
2191 2303
         return '<div class="nospan float" style="margin-right: 10px">' . ($withpicto ? img_picto($langs->trans("Url"), 'object_globe.png') . ' ' : '') . $link . '</div>';
@@ -2209,13 +2321,15 @@  discard block
 block discarded – undo
2209 2321
 
2210 2322
         $newemail = $email;
2211 2323
 
2212
-        if (empty($email))
2213
-            return '&nbsp;';
2324
+        if (empty($email)) {
2325
+                    return '&nbsp;';
2326
+        }
2214 2327
 
2215 2328
         if (!empty($addlink)) {
2216 2329
             $newemail = '<a style="text-overflow: ellipsis;" href="';
2217
-            if (!preg_match('/^mailto:/i', $email))
2218
-                $newemail .= 'mailto:';
2330
+            if (!preg_match('/^mailto:/i', $email)) {
2331
+                            $newemail .= 'mailto:';
2332
+            }
2219 2333
             $newemail .= $email;
2220 2334
             $newemail .= '">';
2221 2335
             $newemail .= dol_trunc($email, $max);
@@ -2228,13 +2342,14 @@  discard block
 block discarded – undo
2228 2342
             if (($cid || $socid) && !empty(Globals::$conf->agenda->enabled) && $user->rights->agenda->myactions->create) {
2229 2343
                 $type = 'AC_EMAIL';
2230 2344
                 $link = '';
2231
-                if (!empty(Globals::$conf->global->AGENDA_ADDACTIONFOREMAIL))
2232
-                    $link = '<a href="' . DOL_BASE_URI . '/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>';
2233
-                if ($link)
2234
-                    $newemail = '<div>' . $newemail . ' ' . $link . '</div>';
2345
+                if (!empty(Globals::$conf->global->AGENDA_ADDACTIONFOREMAIL)) {
2346
+                                    $link = '<a href="' . DOL_BASE_URI . '/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>';
2347
+                }
2348
+                if ($link) {
2349
+                                    $newemail = '<div>' . $newemail . ' ' . $link . '</div>';
2350
+                }
2235 2351
             }
2236
-        }
2237
-        else {
2352
+        } else {
2238 2353
             if ($showinvalid && !isValidEmail($email)) {
2239 2354
                 $langs->load("errors");
2240 2355
                 $newemail .= img_warning($langs->trans("ErrorBadEMail", $email));
@@ -2266,8 +2381,9 @@  discard block
 block discarded – undo
2266 2381
 
2267 2382
         $newskype = $value;
2268 2383
 
2269
-        if (empty($value))
2270
-            return '&nbsp;';
2384
+        if (empty($value)) {
2385
+                    return '&nbsp;';
2386
+        }
2271 2387
 
2272 2388
         if (!empty($type)) {
2273 2389
             $newskype = '<div class="divsocialnetwork inline-block valignmiddle">';
@@ -2288,13 +2404,13 @@  discard block
 block discarded – undo
2288 2404
             if (($cid || $socid) && !empty(Globals::$conf->agenda->enabled) && $user->rights->agenda->myactions->create && $type == 'skype') {
2289 2405
                 $addlink = 'AC_SKYPE';
2290 2406
                 $link = '';
2291
-                if (!empty(Globals::$conf->global->AGENDA_ADDACTIONFORSKYPE))
2292
-                    $link = '<a href="' . DOL_BASE_URI . '/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode=' . $addlink . '&amp;contactid=' . $cid . '&amp;socid=' . $socid . '">' . img_object($langs->trans("AddAction"), "calendar") . '</a>';
2407
+                if (!empty(Globals::$conf->global->AGENDA_ADDACTIONFORSKYPE)) {
2408
+                                    $link = '<a href="' . DOL_BASE_URI . '/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode=' . $addlink . '&amp;contactid=' . $cid . '&amp;socid=' . $socid . '">' . img_object($langs->trans("AddAction"), "calendar") . '</a>';
2409
+                }
2293 2410
                 $newskype .= ($link ? ' ' . $link : '');
2294 2411
             }
2295 2412
             $newskype .= '</div>';
2296
-        }
2297
-        else {
2413
+        } else {
2298 2414
             $langs->load("errors");
2299 2415
             $newskype .= img_warning($langs->trans("ErrorBadSocialNetworkValue", $value));
2300 2416
         }
@@ -2323,12 +2439,14 @@  discard block
 block discarded – undo
2323 2439
         if (empty($phone)) {
2324 2440
             return '';
2325 2441
         }
2326
-        if (empty($countrycode))
2327
-            $countrycode = $mysoc->country_code;
2442
+        if (empty($countrycode)) {
2443
+                    $countrycode = $mysoc->country_code;
2444
+        }
2328 2445
 
2329 2446
 // Short format for small screens
2330
-        if (Globals::$conf->dol_optimize_smallscreen)
2331
-            $separ = '';
2447
+        if (Globals::$conf->dol_optimize_smallscreen) {
2448
+                    $separ = '';
2449
+        }
2332 2450
 
2333 2451
         $newphone = $phone;
2334 2452
         if (strtoupper($countrycode) == "FR") {
@@ -2494,15 +2612,18 @@  discard block
 block discarded – undo
2494 2612
                 $newphone = '<a href="tel:' . $phone . '"';
2495 2613
                 $newphone .= '>' . $phone . '</a>';
2496 2614
             } else if (!empty(Globals::$conf->clicktodial->enabled) && $addlink == 'AC_TEL') {  // If click to dial, we use click to dial url
2497
-                if (empty($user->clicktodial_loaded))
2498
-                    $user->fetch_clicktodial();
2615
+                if (empty($user->clicktodial_loaded)) {
2616
+                                    $user->fetch_clicktodial();
2617
+                }
2499 2618
 
2500 2619
 // Define urlmask
2501 2620
                 $urlmask = 'ErrorClickToDialModuleNotConfigured';
2502
-                if (!empty(Globals::$conf->global->CLICKTODIAL_URL))
2503
-                    $urlmask = Globals::$conf->global->CLICKTODIAL_URL;
2504
-                if (!empty($user->clicktodial_url))
2505
-                    $urlmask = $user->clicktodial_url;
2621
+                if (!empty(Globals::$conf->global->CLICKTODIAL_URL)) {
2622
+                                    $urlmask = Globals::$conf->global->CLICKTODIAL_URL;
2623
+                }
2624
+                if (!empty($user->clicktodial_url)) {
2625
+                                    $urlmask = $user->clicktodial_url;
2626
+                }
2506 2627
 
2507 2628
                 $clicktodial_poste = (!empty($user->clicktodial_poste) ? urlencode($user->clicktodial_poste) : '');
2508 2629
                 $clicktodial_login = (!empty($user->clicktodial_login) ? urlencode($user->clicktodial_login) : '');
@@ -2517,8 +2638,9 @@  discard block
 block discarded – undo
2517 2638
                 $url = make_substitutions($url, $substitarray);
2518 2639
                 $newphonesav = $newphone;
2519 2640
                 $newphone = '<a href="' . $url . '"';
2520
-                if (!empty(Globals::$conf->global->CLICKTODIAL_FORCENEWTARGET))
2521
-                    $newphone .= ' target="_blank"';
2641
+                if (!empty(Globals::$conf->global->CLICKTODIAL_FORCENEWTARGET)) {
2642
+                                    $newphone .= ' target="_blank"';
2643
+                }
2522 2644
                 $newphone .= '>' . $newphonesav . '</a>';
2523 2645
             }
2524 2646
 
@@ -2526,12 +2648,15 @@  discard block
 block discarded – undo
2526 2648
             if (!empty(Globals::$conf->agenda->enabled) && $user->rights->agenda->myactions->create) {
2527 2649
                 $type = 'AC_TEL';
2528 2650
                 $link = '';
2529
-                if ($addlink == 'AC_FAX')
2530
-                    $type = 'AC_FAX';
2531
-                if (!empty(Globals::$conf->global->AGENDA_ADDACTIONFORPHONE))
2532
-                    $link = '<a href="' . DOL_BASE_URI . '/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode=' . $type . ($cid ? '&amp;contactid=' . $cid : '') . ($socid ? '&amp;socid=' . $socid : '') . '">' . img_object($langs->trans("AddAction"), "calendar") . '</a>';
2533
-                if ($link)
2534
-                    $newphone = '<div>' . $newphone . ' ' . $link . '</div>';
2651
+                if ($addlink == 'AC_FAX') {
2652
+                                    $type = 'AC_FAX';
2653
+                }
2654
+                if (!empty(Globals::$conf->global->AGENDA_ADDACTIONFORPHONE)) {
2655
+                                    $link = '<a href="' . DOL_BASE_URI . '/comm/action/card.php?action=create&amp;backtopage=1&amp;actioncode=' . $type . ($cid ? '&amp;contactid=' . $cid : '') . ($socid ? '&amp;socid=' . $socid : '') . '">' . img_object($langs->trans("AddAction"), "calendar") . '</a>';
2656
+                }
2657
+                if ($link) {
2658
+                                    $newphone = '<div>' . $newphone . ' ' . $link . '</div>';
2659
+                }
2535 2660
             }
2536 2661
         }
2537 2662
 
@@ -2558,15 +2683,17 @@  discard block
 block discarded – undo
2558 2683
                     $picto = '';
2559 2684
                 }
2560 2685
             }
2561
-            if ($adddivfloat)
2562
-                $rep .= '<div class="nospan float" style="margin-right: 10px">';
2563
-            else
2564
-                $rep .= '<span style="margin-right: 10px;">';
2686
+            if ($adddivfloat) {
2687
+                            $rep .= '<div class="nospan float" style="margin-right: 10px">';
2688
+            } else {
2689
+                            $rep .= '<span style="margin-right: 10px;">';
2690
+            }
2565 2691
             $rep .= ($withpicto ? img_picto($titlealt, 'object_' . $picto . '.png') . ' ' : '') . $newphone;
2566
-            if ($adddivfloat)
2567
-                $rep .= '</div>';
2568
-            else
2569
-                $rep .= '</span>';
2692
+            if ($adddivfloat) {
2693
+                            $rep .= '</div>';
2694
+            } else {
2695
+                            $rep .= '</span>';
2696
+            }
2570 2697
         }
2571 2698
 
2572 2699
         return $rep;
@@ -2596,8 +2723,9 @@  discard block
 block discarded – undo
2596 2723
             if ($countrycode) { // If success, countrycode is us, fr, ...
2597 2724
                 if (file_exists(DOL_BASE_PATH . '/theme/common/flags/' . $countrycode . '.png')) {
2598 2725
                     $ret .= ' ' . img_picto($countrycode . ' ' . $langs->trans("AccordingToGeoIPDatabase"), DOL_BASE_URI . '/theme/common/flags/' . $countrycode . '.png', '', 1);
2599
-                } else
2600
-                    $ret .= ' (' . $countrycode . ')';
2726
+                } else {
2727
+                                    $ret .= ' (' . $countrycode . ')';
2728
+                }
2601 2729
             }
2602 2730
         }
2603 2731
 
@@ -2694,26 +2822,33 @@  discard block
 block discarded – undo
2694 2822
                 $out .= $hookmanager->resPrint;
2695 2823
             }
2696 2824
             if (empty($reshook)) {
2697
-                if (empty($charfornl))
2698
-                    $out .= nl2br($address);
2699
-                else
2700
-                    $out .= preg_replace('/[\r\n]+/', $charfornl, $address);
2825
+                if (empty($charfornl)) {
2826
+                                    $out .= nl2br($address);
2827
+                } else {
2828
+                                    $out .= preg_replace('/[\r\n]+/', $charfornl, $address);
2829
+                }
2701 2830
 
2702 2831
                 $showgmap = $showomap = 0;
2703 2832
 
2704 2833
 // TODO Add a hook here
2705
-                if (($mode == 'thirdparty' || $mode == 'societe') && !empty(Globals::$conf->google->enabled) && !empty(Globals::$conf->global->GOOGLE_ENABLE_GMAPS))
2706
-                    $showgmap = 1;
2707
-                if ($mode == 'contact' && !empty(Globals::$conf->google->enabled) && !empty(Globals::$conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS))
2708
-                    $showgmap = 1;
2709
-                if ($mode == 'member' && !empty(Globals::$conf->google->enabled) && !empty(Globals::$conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS))
2710
-                    $showgmap = 1;
2711
-                if (($mode == 'thirdparty' || $mode == 'societe') && !empty(Globals::$conf->openstreetmap->enabled) && !empty(Globals::$conf->global->OPENSTREETMAP_ENABLE_MAPS))
2712
-                    $showomap = 1;
2713
-                if ($mode == 'contact' && !empty(Globals::$conf->openstreetmap->enabled) && !empty(Globals::$conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS))
2714
-                    $showomap = 1;
2715
-                if ($mode == 'member' && !empty(Globals::$conf->openstreetmap->enabled) && !empty(Globals::$conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS))
2716
-                    $showomap = 1;
2834
+                if (($mode == 'thirdparty' || $mode == 'societe') && !empty(Globals::$conf->google->enabled) && !empty(Globals::$conf->global->GOOGLE_ENABLE_GMAPS)) {
2835
+                                    $showgmap = 1;
2836
+                }
2837
+                if ($mode == 'contact' && !empty(Globals::$conf->google->enabled) && !empty(Globals::$conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS)) {
2838
+                                    $showgmap = 1;
2839
+                }
2840
+                if ($mode == 'member' && !empty(Globals::$conf->google->enabled) && !empty(Globals::$conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS)) {
2841
+                                    $showgmap = 1;
2842
+                }
2843
+                if (($mode == 'thirdparty' || $mode == 'societe') && !empty(Globals::$conf->openstreetmap->enabled) && !empty(Globals::$conf->global->OPENSTREETMAP_ENABLE_MAPS)) {
2844
+                                    $showomap = 1;
2845
+                }
2846
+                if ($mode == 'contact' && !empty(Globals::$conf->openstreetmap->enabled) && !empty(Globals::$conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS)) {
2847
+                                    $showomap = 1;
2848
+                }
2849
+                if ($mode == 'member' && !empty(Globals::$conf->openstreetmap->enabled) && !empty(Globals::$conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS)) {
2850
+                                    $showomap = 1;
2851
+                }
2717 2852
 
2718 2853
                 if ($showgmap) {
2719 2854
                     $url = dol_buildpath('/google/gmaps.php?mode=' . $mode . '&id=' . $id, 1);
@@ -2725,10 +2860,11 @@  discard block
 block discarded – undo
2725 2860
                 }
2726 2861
             }
2727 2862
         }
2728
-        if ($noprint)
2729
-            return $out;
2730
-        else
2731
-            print $out;
2863
+        if ($noprint) {
2864
+                    return $out;
2865
+        } else {
2866
+                    print $out;
2867
+        }
2732 2868
     }
2733 2869
 
2734 2870
     /**
@@ -2740,10 +2876,12 @@  discard block
 block discarded – undo
2740 2876
      */
2741 2877
     static function isValidEmail($address, $acceptsupervisorkey = 0)
2742 2878
     {
2743
-        if ($acceptsupervisorkey && $address == '__SUPERVISOREMAIL__')
2744
-            return true;
2745
-        if (filter_var($address, FILTER_VALIDATE_EMAIL))
2746
-            return true;
2879
+        if ($acceptsupervisorkey && $address == '__SUPERVISOREMAIL__') {
2880
+                    return true;
2881
+        }
2882
+        if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
2883
+                    return true;
2884
+        }
2747 2885
 
2748 2886
         return false;
2749 2887
     }
@@ -2765,10 +2903,12 @@  discard block
 block discarded – undo
2765 2903
                 $mxhosts = array();
2766 2904
                 $weight = array();
2767 2905
                 getmxrr(idn_to_ascii($domain), $mxhosts, $weight);
2768
-                if (count($mxhosts) > 1)
2769
-                    return 1;
2770
-                if (count($mxhosts) == 1 && !empty($mxhosts[0]))
2771
-                    return 1;
2906
+                if (count($mxhosts) > 1) {
2907
+                                    return 1;
2908
+                }
2909
+                if (count($mxhosts) == 1 && !empty($mxhosts[0])) {
2910
+                                    return 1;
2911
+                }
2772 2912
 
2773 2913
                 return 0;
2774 2914
             }
@@ -2797,10 +2937,11 @@  discard block
 block discarded – undo
2797 2937
      */
2798 2938
     static function dol_strlen($string, $stringencoding = 'UTF-8')
2799 2939
     {
2800
-        if (function_exists('mb_strlen'))
2801
-            return mb_strlen($string, $stringencoding);
2802
-        else
2803
-            return strlen($string);
2940
+        if (function_exists('mb_strlen')) {
2941
+                    return mb_strlen($string, $stringencoding);
2942
+        } else {
2943
+                    return strlen($string);
2944
+        }
2804 2945
     }
2805 2946
 
2806 2947
     /**
@@ -2817,8 +2958,9 @@  discard block
 block discarded – undo
2817 2958
     {
2818 2959
        // global $langs;
2819 2960
 
2820
-        if (empty($stringencoding))
2821
-            $stringencoding = $langs->charset_output;
2961
+        if (empty($stringencoding)) {
2962
+                    $stringencoding = $langs->charset_output;
2963
+        }
2822 2964
 
2823 2965
         $ret = '';
2824 2966
         if (empty($trunconbytes)) {
@@ -2854,48 +2996,55 @@  discard block
 block discarded – undo
2854 2996
     {
2855 2997
        // global Globals::$conf;
2856 2998
 
2857
-        if ($size == 0 || !empty(Globals::$conf->global->MAIN_DISABLE_TRUNC))
2858
-            return $string;
2999
+        if ($size == 0 || !empty(Globals::$conf->global->MAIN_DISABLE_TRUNC)) {
3000
+                    return $string;
3001
+        }
2859 3002
 
2860
-        if (empty($stringencoding))
2861
-            $stringencoding = 'UTF-8';
2862
-// reduce for small screen
2863
-        if (Globals::$conf->dol_optimize_smallscreen == 1 && $display == 1)
2864
-            $size = round($size / 3);
3003
+        if (empty($stringencoding)) {
3004
+                    $stringencoding = 'UTF-8';
3005
+        }
3006
+        // reduce for small screen
3007
+        if (Globals::$conf->dol_optimize_smallscreen == 1 && $display == 1) {
3008
+                    $size = round($size / 3);
3009
+        }
2865 3010
 
2866 3011
 // We go always here
2867 3012
         if ($trunc == 'right') {
2868 3013
             $newstring = dol_textishtml($string) ? dol_string_nohtmltag($string, 1) : $string;
2869
-            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 ...
2870
-                return dol_substr($newstring, 0, $size, $stringencoding) . ($nodot ? '' : '...');
2871
-            else
2872
-//return 'u'.$size.'-'.$newstring.'-'.dol_strlen($newstring,$stringencoding).'-'.$string;
2873
-                return $string;
2874
-        }
2875
-        elseif ($trunc == 'middle') {
3014
+            if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 3))) {
3015
+                // If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ...
3016
+                return dol_substr($newstring, 0, $size, $stringencoding) . ($nodot ? '' : '...');
3017
+            } else {
3018
+                //return 'u'.$size.'-'.$newstring.'-'.dol_strlen($newstring,$stringencoding).'-'.$string;
3019
+                return $string;
3020
+            }
3021
+        } elseif ($trunc == 'middle') {
2876 3022
             $newstring = dol_textishtml($string) ? dol_string_nohtmltag($string, 1) : $string;
2877 3023
             if (dol_strlen($newstring, $stringencoding) > 2 && dol_strlen($newstring, $stringencoding) > ($size + 1)) {
2878 3024
                 $size1 = round($size / 2);
2879 3025
                 $size2 = round($size / 2);
2880 3026
                 return dol_substr($newstring, 0, $size1, $stringencoding) . '...' . dol_substr($newstring, dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
2881
-            } else
2882
-                return $string;
2883
-        }
2884
-        elseif ($trunc == 'left') {
3027
+            } else {
3028
+                            return $string;
3029
+            }
3030
+        } elseif ($trunc == 'left') {
2885 3031
             $newstring = dol_textishtml($string) ? dol_string_nohtmltag($string, 1) : $string;
2886
-            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 ...
2887
-                return '...' . dol_substr($newstring, dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
2888
-            else
2889
-                return $string;
2890
-        }
2891
-        elseif ($trunc == 'wrap') {
3032
+            if (dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 3))) {
3033
+                // If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ...
3034
+                return '...' . dol_substr($newstring, dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
3035
+            } else {
3036
+                            return $string;
3037
+            }
3038
+        } elseif ($trunc == 'wrap') {
2892 3039
             $newstring = dol_textishtml($string) ? dol_string_nohtmltag($string, 1) : $string;
2893
-            if (dol_strlen($newstring, $stringencoding) > ($size + 1))
2894
-                return dol_substr($newstring, 0, $size, $stringencoding) . "\n" . dol_trunc(dol_substr($newstring, $size, dol_strlen($newstring, $stringencoding) - $size, $stringencoding), $size, $trunc);
2895
-            else
2896
-                return $string;
2897
-        } else
2898
-            return 'BadParam3CallingDolTrunc';
3040
+            if (dol_strlen($newstring, $stringencoding) > ($size + 1)) {
3041
+                            return dol_substr($newstring, 0, $size, $stringencoding) . "\n" . dol_trunc(dol_substr($newstring, $size, dol_strlen($newstring, $stringencoding) - $size, $stringencoding), $size, $trunc);
3042
+            } else {
3043
+                            return $string;
3044
+            }
3045
+        } else {
3046
+                    return 'BadParam3CallingDolTrunc';
3047
+        }
2899 3048
     }
2900 3049
 
2901 3050
     /**
@@ -3105,8 +3254,9 @@  discard block
 block discarded – undo
3105 3254
     {
3106 3255
        // global Globals::$conf;
3107 3256
 
3108
-        if (!preg_match('/(\.png|\.gif)$/i', $picto))
3109
-            $picto .= '.png';
3257
+        if (!preg_match('/(\.png|\.gif)$/i', $picto)) {
3258
+                    $picto .= '.png';
3259
+        }
3110 3260
 
3111 3261
 //$path = DOL_BASE_URI . '/theme/' . Globals::$conf->theme . '/img/weather/' . $picto;
3112 3262
         $path = DOL_BASE_URI . '/theme/' . Globals::$conf->theme . '/img/weather/' . $picto;
@@ -3128,20 +3278,22 @@  discard block
 block discarded – undo
3128 3278
     {
3129 3279
        // global Globals::$conf;
3130 3280
 
3131
-        if (!preg_match('/(\.png|\.gif)$/i', $picto))
3132
-            $picto .= '.png';
3281
+        if (!preg_match('/(\.png|\.gif)$/i', $picto)) {
3282
+                    $picto .= '.png';
3283
+        }
3133 3284
 
3134
-        if ($pictoisfullpath)
3135
-            $path = $picto;
3136
-        else {
3285
+        if ($pictoisfullpath) {
3286
+                    $path = $picto;
3287
+        } else {
3137 3288
 //$path = DOL_BASE_URI . '/theme/common/' . $picto;
3138 3289
             $path = DOL_BASE_URI . '/theme/common/' . $picto;
3139 3290
 
3140 3291
             if (!empty(Globals::$conf->global->MAIN_MODULE_CAN_OVERWRITE_COMMONICONS)) {
3141 3292
                 $themepath = DOL_BASE_PATH . 'theme/' . Globals::$conf->theme . '/img/' . $picto;
3142 3293
 
3143
-                if (file_exists($themepath))
3144
-                    $path = $themepath;
3294
+                if (file_exists($themepath)) {
3295
+                                    $path = $themepath;
3296
+                }
3145 3297
             }
3146 3298
         }
3147 3299
 
@@ -3180,8 +3332,9 @@  discard block
 block discarded – undo
3180 3332
                 $numaction = 0;
3181 3333
             }
3182 3334
         }
3183
-        if (!is_numeric($numaction))
3184
-            $numaction = 0;
3335
+        if (!is_numeric($numaction)) {
3336
+                    $numaction = 0;
3337
+        }
3185 3338
 
3186 3339
         return img_picto($titlealt, 'stcomm' . $numaction . '.png');
3187 3340
     }
@@ -3197,8 +3350,9 @@  discard block
 block discarded – undo
3197 3350
     {
3198 3351
        // global Globals::$conf, $langs;
3199 3352
 
3200
-        if ($titlealt == 'default')
3201
-            $titlealt = $langs->trans('Show');
3353
+        if ($titlealt == 'default') {
3354
+                    $titlealt = $langs->trans('Show');
3355
+        }
3202 3356
 
3203 3357
         return img_picto($titlealt, 'pdf' . $size . '.png');
3204 3358
     }
@@ -3214,8 +3368,9 @@  discard block
 block discarded – undo
3214 3368
     {
3215 3369
        // global Globals::$conf, $langs;
3216 3370
 
3217
-        if ($titlealt == 'default')
3218
-            $titlealt = $langs->trans('Add');
3371
+        if ($titlealt == 'default') {
3372
+                    $titlealt = $langs->trans('Add');
3373
+        }
3219 3374
 
3220 3375
         return img_picto($titlealt, 'edit_add.png', $other);
3221 3376
     }
@@ -3231,8 +3386,9 @@  discard block
 block discarded – undo
3231 3386
     {
3232 3387
        // global Globals::$conf, $langs;
3233 3388
 
3234
-        if ($titlealt == 'default')
3235
-            $titlealt = $langs->trans('Remove');
3389
+        if ($titlealt == 'default') {
3390
+                    $titlealt = $langs->trans('Remove');
3391
+        }
3236 3392
 
3237 3393
         return img_picto($titlealt, 'edit_remove.png', $other);
3238 3394
     }
@@ -3249,8 +3405,9 @@  discard block
 block discarded – undo
3249 3405
     {
3250 3406
        // global Globals::$conf, $langs;
3251 3407
 
3252
-        if ($titlealt == 'default')
3253
-            $titlealt = $langs->trans('Modify');
3408
+        if ($titlealt == 'default') {
3409
+                    $titlealt = $langs->trans('Modify');
3410
+        }
3254 3411
 
3255 3412
         return img_picto($titlealt, 'edit.png', ($float ? 'style="float: ' . ($langs->tab_translate["DIRECTION"] == 'rtl' ? 'left' : 'right') . '"' : "") . ($other ? ' ' . $other : ''));
3256 3413
     }
@@ -3267,8 +3424,9 @@  discard block
 block discarded – undo
3267 3424
     {
3268 3425
        // global Globals::$conf, $langs;
3269 3426
 
3270
-        if ($titlealt == 'default')
3271
-            $titlealt = $langs->trans('View');
3427
+        if ($titlealt == 'default') {
3428
+                    $titlealt = $langs->trans('View');
3429
+        }
3272 3430
 
3273 3431
         $moreatt = ($float ? 'style="float: right" ' : '') . $other;
3274 3432
 
@@ -3286,8 +3444,9 @@  discard block
 block discarded – undo
3286 3444
     {
3287 3445
        // global Globals::$conf, $langs;
3288 3446
 
3289
-        if ($titlealt == 'default')
3290
-            $titlealt = $langs->trans('Delete');
3447
+        if ($titlealt == 'default') {
3448
+                    $titlealt = $langs->trans('Delete');
3449
+        }
3291 3450
 
3292 3451
         return img_picto($titlealt, 'delete.png', $other);
3293 3452
 //return '<span class="fa fa-trash fa-2x fa-fw" style="font-size: 1.7em;" title="'.$titlealt.'"></span>';
@@ -3303,8 +3462,9 @@  discard block
 block discarded – undo
3303 3462
     static function img_printer($titlealt = "default", $other = '')
3304 3463
     {
3305 3464
        // global Globals::$conf, $langs;
3306
-        if ($titlealt == "default")
3307
-            $titlealt = $langs->trans("Print");
3465
+        if ($titlealt == "default") {
3466
+                    $titlealt = $langs->trans("Print");
3467
+        }
3308 3468
         return img_picto($titlealt, 'printer.png', $other);
3309 3469
     }
3310 3470
 
@@ -3319,8 +3479,9 @@  discard block
 block discarded – undo
3319 3479
     {
3320 3480
        // global Globals::$conf, $langs;
3321 3481
 
3322
-        if ($titlealt == 'default')
3323
-            $titlealt = $langs->trans('Split');
3482
+        if ($titlealt == 'default') {
3483
+                    $titlealt = $langs->trans('Split');
3484
+        }
3324 3485
 
3325 3486
         return img_picto($titlealt, 'split.png', $other);
3326 3487
     }
@@ -3337,10 +3498,11 @@  discard block
 block discarded – undo
3337 3498
        // global Globals::$conf, $langs;
3338 3499
 
3339 3500
         if ($usealttitle) {
3340
-            if (is_string($usealttitle))
3341
-                $usealttitle = dol_escape_htmltag($usealttitle);
3342
-            else
3343
-                $usealttitle = $langs->trans('Info');
3501
+            if (is_string($usealttitle)) {
3502
+                            $usealttitle = dol_escape_htmltag($usealttitle);
3503
+            } else {
3504
+                            $usealttitle = $langs->trans('Info');
3505
+            }
3344 3506
         }
3345 3507
 
3346 3508
         return img_picto($usealttitle, 'info.png', 'style="vertical-align: middle;' . ($usehelpcursor == 1 ? ' cursor: help' : ($usehelpcursor == 2 ? ' cursor: pointer' : '')) . '"');
@@ -3356,8 +3518,9 @@  discard block
 block discarded – undo
3356 3518
     {
3357 3519
        // global Globals::$conf, $langs;
3358 3520
 
3359
-        if ($titlealt == 'default')
3360
-            $titlealt = $langs->trans('Informations');
3521
+        if ($titlealt == 'default') {
3522
+                    $titlealt = $langs->trans('Informations');
3523
+        }
3361 3524
 
3362 3525
         return img_picto($titlealt, 'info.png', 'style="vertical-align: middle;"');
3363 3526
     }
@@ -3373,8 +3536,9 @@  discard block
 block discarded – undo
3373 3536
     {
3374 3537
        // global Globals::$conf, $langs;
3375 3538
 
3376
-        if ($titlealt == 'default')
3377
-            $titlealt = $langs->trans('Warning');
3539
+        if ($titlealt == 'default') {
3540
+                    $titlealt = $langs->trans('Warning');
3541
+        }
3378 3542
 
3379 3543
 //return '<div class="imglatecoin">'.img_picto($titlealt, 'warning_white.png', 'class="pictowarning valignmiddle"'.($moreatt ? ($moreatt == '1' ? ' style="float: right"' : ' '.$moreatt): '')).'</div>';
3380 3544
         return img_picto($titlealt, 'warning.png', 'class="pictowarning valignmiddle"' . ($moreatt ? ($moreatt == '1' ? ' style="float: right"' : ' ' . $moreatt) : ''));
@@ -3390,8 +3554,9 @@  discard block
 block discarded – undo
3390 3554
     {
3391 3555
        // global Globals::$conf, $langs;
3392 3556
 
3393
-        if ($titlealt == 'default')
3394
-            $titlealt = $langs->trans('Error');
3557
+        if ($titlealt == 'default') {
3558
+                    $titlealt = $langs->trans('Error');
3559
+        }
3395 3560
 
3396 3561
         return img_picto($titlealt, 'error.png', 'class="valigntextbottom"');
3397 3562
     }
@@ -3407,8 +3572,9 @@  discard block
 block discarded – undo
3407 3572
     {
3408 3573
        // global Globals::$conf, $langs;
3409 3574
 
3410
-        if ($titlealt == 'default')
3411
-            $titlealt = $langs->trans('Next');
3575
+        if ($titlealt == 'default') {
3576
+                    $titlealt = $langs->trans('Next');
3577
+        }
3412 3578
 
3413 3579
 //return img_picto($titlealt, 'next.png', $moreatt);
3414 3580
         return '<span class="fa fa-chevron-right paddingright paddingleft" title="' . dol_escape_htmltag($titlealt) . '"></span>';
@@ -3425,8 +3591,9 @@  discard block
 block discarded – undo
3425 3591
     {
3426 3592
        // global Globals::$conf, $langs;
3427 3593
 
3428
-        if ($titlealt == 'default')
3429
-            $titlealt = $langs->trans('Previous');
3594
+        if ($titlealt == 'default') {
3595
+                    $titlealt = $langs->trans('Previous');
3596
+        }
3430 3597
 
3431 3598
 //return img_picto($titlealt, 'previous.png', $moreatt);
3432 3599
         return '<span class="fa fa-chevron-left paddingright paddingleft" title="' . dol_escape_htmltag($titlealt) . '"></span>';
@@ -3444,8 +3611,9 @@  discard block
 block discarded – undo
3444 3611
     {
3445 3612
        // global Globals::$conf, $langs;
3446 3613
 
3447
-        if ($titlealt == 'default')
3448
-            $titlealt = $langs->trans('Down');
3614
+        if ($titlealt == 'default') {
3615
+                    $titlealt = $langs->trans('Down');
3616
+        }
3449 3617
 
3450 3618
         return img_picto($titlealt, ($selected ? '1downarrow_selected.png' : '1downarrow.png'), 'class="imgdown' . ($moreclass ? " " . $moreclass : "") . '"');
3451 3619
     }
@@ -3462,8 +3630,9 @@  discard block
 block discarded – undo
3462 3630
     {
3463 3631
        // global Globals::$conf, $langs;
3464 3632
 
3465
-        if ($titlealt == 'default')
3466
-            $titlealt = $langs->trans('Up');
3633
+        if ($titlealt == 'default') {
3634
+                    $titlealt = $langs->trans('Up');
3635
+        }
3467 3636
 
3468 3637
         return img_picto($titlealt, ($selected ? '1uparrow_selected.png' : '1uparrow.png'), 'class="imgup' . ($moreclass ? " " . $moreclass : "") . '"');
3469 3638
     }
@@ -3480,8 +3649,9 @@  discard block
 block discarded – undo
3480 3649
     {
3481 3650
        // global Globals::$conf, $langs;
3482 3651
 
3483
-        if ($titlealt == 'default')
3484
-            $titlealt = $langs->trans('Left');
3652
+        if ($titlealt == 'default') {
3653
+                    $titlealt = $langs->trans('Left');
3654
+        }
3485 3655
 
3486 3656
         return img_picto($titlealt, ($selected ? '1leftarrow_selected.png' : '1leftarrow.png'), $moreatt);
3487 3657
     }
@@ -3498,8 +3668,9 @@  discard block
 block discarded – undo
3498 3668
     {
3499 3669
        // global Globals::$conf, $langs;
3500 3670
 
3501
-        if ($titlealt == 'default')
3502
-            $titlealt = $langs->trans('Right');
3671
+        if ($titlealt == 'default') {
3672
+                    $titlealt = $langs->trans('Right');
3673
+        }
3503 3674
 
3504 3675
         return img_picto($titlealt, ($selected ? '1rightarrow_selected.png' : '1rightarrow.png'), $moreatt);
3505 3676
     }
@@ -3515,11 +3686,13 @@  discard block
 block discarded – undo
3515 3686
     {
3516 3687
        // global Globals::$conf, $langs;
3517 3688
 
3518
-        if ($titlealt == 'default')
3519
-            $titlealt = $langs->trans('Active');
3689
+        if ($titlealt == 'default') {
3690
+                    $titlealt = $langs->trans('Active');
3691
+        }
3520 3692
 
3521
-        if ($allow == 1)
3522
-            return img_picto($titlealt, 'tick.png');
3693
+        if ($allow == 1) {
3694
+                    return img_picto($titlealt, 'tick.png');
3695
+        }
3523 3696
 
3524 3697
         return '-';
3525 3698
     }
@@ -3567,8 +3740,9 @@  discard block
 block discarded – undo
3567 3740
         $mimeimg = dol_mimetype($file, '', 2);
3568 3741
         $mimefa = dol_mimetype($file, '', 4);
3569 3742
 
3570
-        if (empty($titlealt))
3571
-            $titlealt = 'Mime type: ' . $mimetype;
3743
+        if (empty($titlealt)) {
3744
+                    $titlealt = 'Mime type: ' . $mimetype;
3745
+        }
3572 3746
 
3573 3747
 //return img_picto_common($titlealt, 'mime/'.$mimeimg, 'class="'.$morecss.'"');
3574 3748
         return '<i class="fa fa-' . $mimefa . ' paddingright"></i>';
@@ -3590,13 +3764,15 @@  discard block
 block discarded – undo
3590 3764
 
3591 3765
        // global Globals::$conf, $langs;
3592 3766
 
3593
-        if ($titlealt == 'default')
3594
-            $titlealt = $langs->trans('Call');
3767
+        if ($titlealt == 'default') {
3768
+                    $titlealt = $langs->trans('Call');
3769
+        }
3595 3770
 
3596
-        if ($option == 1)
3597
-            $img = 'call';
3598
-        else
3599
-            $img = 'call_out';
3771
+        if ($option == 1) {
3772
+                    $img = 'call';
3773
+        } else {
3774
+                    $img = 'call_out';
3775
+        }
3600 3776
 
3601 3777
         return img_picto($titlealt, $img);
3602 3778
     }
@@ -3612,8 +3788,9 @@  discard block
 block discarded – undo
3612 3788
     {
3613 3789
        // global Globals::$conf, $langs;
3614 3790
 
3615
-        if ($titlealt == 'default')
3616
-            $titlealt = $langs->trans('Search');
3791
+        if ($titlealt == 'default') {
3792
+                    $titlealt = $langs->trans('Search');
3793
+        }
3617 3794
 
3618 3795
         $img = img_picto($titlealt, 'search.png', $other, false, 1);
3619 3796
 
@@ -3634,8 +3811,9 @@  discard block
 block discarded – undo
3634 3811
     {
3635 3812
        // global Globals::$conf, $langs;
3636 3813
 
3637
-        if ($titlealt == 'default')
3638
-            $titlealt = $langs->trans('Search');
3814
+        if ($titlealt == 'default') {
3815
+                    $titlealt = $langs->trans('Search');
3816
+        }
3639 3817
 
3640 3818
         $img = img_picto($titlealt, 'searchclear.png', $other, false, 1);
3641 3819
 
@@ -3697,14 +3875,16 @@  discard block
 block discarded – undo
3697 3875
 
3698 3876
         if ($_SERVER['DOCUMENT_ROOT']) {    // Mode web
3699 3877
             $out .= $langs->trans("DolibarrHasDetectedError") . ".<br>\n";
3700
-            if (!empty(Globals::$conf->global->MAIN_FEATURES_LEVEL))
3701
-                $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";
3878
+            if (!empty(Globals::$conf->global->MAIN_FEATURES_LEVEL)) {
3879
+                            $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";
3880
+            }
3702 3881
             $out .= $langs->trans("InformationToHelpDiagnose") . ":<br>\n";
3703 3882
 
3704 3883
             $out .= "<b>" . $langs->trans("Date") . ":</b> " . dol_print_date(time(), 'dayhourlog') . "<br>\n";
3705 3884
             $out .= "<b>" . $langs->trans("Dolibarr") . ":</b> " . DOL_VERSION . "<br>\n";
3706
-            if (isset(Globals::$conf->global->MAIN_FEATURES_LEVEL))
3707
-                $out .= "<b>" . $langs->trans("LevelOfFeature") . ":</b> " . Globals::$conf->global->MAIN_FEATURES_LEVEL . "<br>\n";
3885
+            if (isset(Globals::$conf->global->MAIN_FEATURES_LEVEL)) {
3886
+                            $out .= "<b>" . $langs->trans("LevelOfFeature") . ":</b> " . Globals::$conf->global->MAIN_FEATURES_LEVEL . "<br>\n";
3887
+            }
3708 3888
             if (function_exists("phpversion")) {
3709 3889
                 $out .= "<b>" . $langs->trans("PHP") . ":</b> " . phpversion() . "<br>\n";
3710 3890
             }
@@ -3747,18 +3927,20 @@  discard block
 block discarded – undo
3747 3927
             $langs->load("errors");
3748 3928
 
3749 3929
 // Merge all into $errors array
3750
-            if (is_array($error) && is_array($errors))
3751
-                $errors = array_merge($error, $errors);
3752
-            elseif (is_array($error))
3753
-                $errors = $error;
3754
-            elseif (is_array($errors))
3755
-                $errors = array_merge(array($error), $errors);
3756
-            else
3757
-                $errors = array_merge(array($error));
3930
+            if (is_array($error) && is_array($errors)) {
3931
+                            $errors = array_merge($error, $errors);
3932
+            } elseif (is_array($error)) {
3933
+                            $errors = $error;
3934
+            } elseif (is_array($errors)) {
3935
+                            $errors = array_merge(array($error), $errors);
3936
+            } else {
3937
+                            $errors = array_merge(array($error));
3938
+            }
3758 3939
 
3759 3940
             foreach ($errors as $msg) {
3760
-                if (empty($msg))
3761
-                    continue;
3941
+                if (empty($msg)) {
3942
+                                    continue;
3943
+                }
3762 3944
                 if ($_SERVER['DOCUMENT_ROOT']) {  // Mode web
3763 3945
                     $out .= "<b>" . $langs->trans("Message") . ":</b> " . dol_escape_htmltag($msg) . "<br>\n";
3764 3946
                 } else {                        // Mode CLI
@@ -3776,9 +3958,9 @@  discard block
 block discarded – undo
3776 3958
             $out .= "<br>\n";
3777 3959
         }
3778 3960
 
3779
-        if (empty($dolibarr_main_prod))
3780
-            print $out;
3781
-        else {
3961
+        if (empty($dolibarr_main_prod)) {
3962
+                    print $out;
3963
+        } else {
3782 3964
             print $langs->trans("DolibarrHasDetectedError") . '. ';
3783 3965
             print $langs->trans("YouCanSetOptionDolibarrMainProdToZero");
3784 3966
             define("MAIN_CORE_ERROR", 1);
@@ -3801,16 +3983,18 @@  discard block
 block discarded – undo
3801 3983
     {
3802 3984
        // global $langs, Globals::$conf;
3803 3985
 
3804
-        if (empty($email))
3805
-            $email = Globals::$conf->global->MAIN_INFO_SOCIETE_MAIL;
3986
+        if (empty($email)) {
3987
+                    $email = Globals::$conf->global->MAIN_INFO_SOCIETE_MAIL;
3988
+        }
3806 3989
 
3807 3990
         $langs->load("errors");
3808 3991
         $now = dol_now();
3809 3992
 
3810 3993
         print '<br><div class="center login_main_message"><div class="' . $morecss . '">';
3811 3994
         print $langs->trans("ErrorContactEMail", $email, $prefixcode . dol_print_date($now, '%Y%m%d'));
3812
-        if ($errormessage)
3813
-            print '<br><br>' . $errormessage;
3995
+        if ($errormessage) {
3996
+                    print '<br><br>' . $errormessage;
3997
+        }
3814 3998
         if (is_array($errormessages) && count($errormessages)) {
3815 3999
             foreach ($errormessages as $mesgtoshow) {
3816 4000
                 print '<br><br>' . $mesgtoshow;
@@ -4053,12 +4237,15 @@  discard block
 block discarded – undo
4053 4237
         $savtotalnboflines = $totalnboflines;
4054 4238
         $totalnboflines = abs($totalnboflines);
4055 4239
 
4056
-        if ($picto == 'setup')
4057
-            $picto = 'title_setup.png';
4058
-        if ((Globals::$conf->browser->name == 'ie') && $picto == 'title_generic.png')
4059
-            $picto = 'title.gif';
4060
-        if ($limit < 0)
4061
-            $limit = Globals::$conf->liste_limit;
4240
+        if ($picto == 'setup') {
4241
+                    $picto = 'title_setup.png';
4242
+        }
4243
+        if ((Globals::$conf->browser->name == 'ie') && $picto == 'title_generic.png') {
4244
+                    $picto = 'title.gif';
4245
+        }
4246
+        if ($limit < 0) {
4247
+                    $limit = Globals::$conf->liste_limit;
4248
+        }
4062 4249
         if ($savlimit != 0 && (($num > $limit) || ($num == -1) || ($limit == 0))) {
4063 4250
             $nextpage = 1;
4064 4251
         } else {
@@ -4072,11 +4259,13 @@  discard block
 block discarded – undo
4072 4259
 // Left
4073 4260
 //if ($picto && $titre) print '<td class="nobordernopadding hideonsmartphone" width="40" align="left" valign="middle">'.img_picto('', $picto, 'id="pictotitle"', $pictoisfullpath).'</td>';
4074 4261
         print '<td class="nobordernopadding valignmiddle">';
4075
-        if ($picto && $titre)
4076
-            print img_picto('', $picto, 'class="hideonsmartphone valignmiddle opacityhigh pictotitle widthpictotitle"', $pictoisfullpath);
4262
+        if ($picto && $titre) {
4263
+                    print img_picto('', $picto, 'class="hideonsmartphone valignmiddle opacityhigh pictotitle widthpictotitle"', $pictoisfullpath);
4264
+        }
4077 4265
         print '<div class="titre inline-block">' . $titre;
4078
-        if (!empty($titre) && $savtotalnboflines >= 0 && (string) $savtotalnboflines != '')
4079
-            print ' (' . $totalnboflines . ')';
4266
+        if (!empty($titre) && $savtotalnboflines >= 0 && (string) $savtotalnboflines != '') {
4267
+                    print ' (' . $totalnboflines . ')';
4268
+        }
4080 4269
         print '</div></td>';
4081 4270
 
4082 4271
 // Center
@@ -4086,21 +4275,24 @@  discard block
 block discarded – undo
4086 4275
 
4087 4276
 // Right
4088 4277
         print '<td class="nobordernopadding valignmiddle" align="right">';
4089
-        if ($sortfield)
4090
-            $options .= "&sortfield=" . urlencode($sortfield);
4091
-        if ($sortorder)
4092
-            $options .= "&sortorder=" . urlencode($sortorder);
4093
-// Show navigation bar
4278
+        if ($sortfield) {
4279
+                    $options .= "&sortfield=" . urlencode($sortfield);
4280
+        }
4281
+        if ($sortorder) {
4282
+                    $options .= "&sortorder=" . urlencode($sortorder);
4283
+        }
4284
+        // Show navigation bar
4094 4285
         $pagelist = '';
4095 4286
         if ($savlimit != 0 && ($page > 0 || $num > $limit)) {
4096 4287
             if ($totalnboflines) { // If we know total nb of lines
4097 4288
 // Define nb of extra page links before and after selected page + ... + first or last
4098 4289
                 $maxnbofpage = (empty(Globals::$conf->dol_optimize_smallscreen) ? 4 : 1);
4099 4290
 
4100
-                if ($limit > 0)
4101
-                    $nbpages = ceil($totalnboflines / $limit);
4102
-                else
4103
-                    $nbpages = 1;
4291
+                if ($limit > 0) {
4292
+                                    $nbpages = ceil($totalnboflines / $limit);
4293
+                } else {
4294
+                                    $nbpages = 1;
4295
+                }
4104 4296
                 $cpt = ($page - $maxnbofpage);
4105 4297
                 if ($cpt < 0) {
4106 4298
                     $cpt = 0;
@@ -4108,10 +4300,11 @@  discard block
 block discarded – undo
4108 4300
 
4109 4301
                 if ($cpt >= 1) {
4110 4302
                     $pagelist .= '<li' . ((Globals::$conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><a href="' . $file . '?page=0' . $options . '">1</a></li>';
4111
-                    if ($cpt > 2)
4112
-                        $pagelist .= '<li' . ((Globals::$conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><span ' . ((Globals::$conf->dol_use_jmobile != 4) ? 'class="inactive"' : '') . '>...</span></li>';
4113
-                    else if ($cpt == 2)
4114
-                        $pagelist .= '<li' . ((Globals::$conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><a href="' . $file . '?page=1' . $options . '">2</a></li>';
4303
+                    if ($cpt > 2) {
4304
+                                            $pagelist .= '<li' . ((Globals::$conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><span ' . ((Globals::$conf->dol_use_jmobile != 4) ? 'class="inactive"' : '') . '>...</span></li>';
4305
+                    } else if ($cpt == 2) {
4306
+                                            $pagelist .= '<li' . ((Globals::$conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><a href="' . $file . '?page=1' . $options . '">2</a></li>';
4307
+                    }
4115 4308
                 }
4116 4309
 
4117 4310
                 do {
@@ -4124,14 +4317,14 @@  discard block
 block discarded – undo
4124 4317
                 } while ($cpt < $nbpages && $cpt <= $page + $maxnbofpage);
4125 4318
 
4126 4319
                 if ($cpt < $nbpages) {
4127
-                    if ($cpt < $nbpages - 2)
4128
-                        $pagelist .= '<li' . ((Globals::$conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><span ' . ((Globals::$conf->dol_use_jmobile != 4) ? 'class="inactive"' : '') . '>...</span></li>';
4129
-                    else if ($cpt == $nbpages - 2)
4130
-                        $pagelist .= '<li' . ((Globals::$conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><a href="' . $file . '?page=' . ($nbpages - 2) . $options . '">' . ($nbpages - 1) . '</a></li>';
4320
+                    if ($cpt < $nbpages - 2) {
4321
+                                            $pagelist .= '<li' . ((Globals::$conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><span ' . ((Globals::$conf->dol_use_jmobile != 4) ? 'class="inactive"' : '') . '>...</span></li>';
4322
+                    } else if ($cpt == $nbpages - 2) {
4323
+                                            $pagelist .= '<li' . ((Globals::$conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><a href="' . $file . '?page=' . ($nbpages - 2) . $options . '">' . ($nbpages - 1) . '</a></li>';
4324
+                    }
4131 4325
                     $pagelist .= '<li' . ((Globals::$conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><a href="' . $file . '?page=' . ($nbpages - 1) . $options . '">' . $nbpages . '</a></li>';
4132 4326
                 }
4133
-            }
4134
-            else {
4327
+            } else {
4135 4328
                 $pagelist .= '<li' . ((Globals::$conf->dol_use_jmobile != 4) ? ' class="pagination"' : '') . '><span ' . ((Globals::$conf->dol_use_jmobile != 4) ? 'class="active"' : '') . '>' . ($page + 1) . "</li>";
4136 4329
             }
4137 4330
         }
@@ -4167,18 +4360,21 @@  discard block
 block discarded – undo
4167 4360
             $pagesizechoices = '10:10,15:15,20:20,30:30,40:40,50:50,100:100,250:250,500:500,1000:1000,5000:5000';
4168 4361
 //$pagesizechoices.=',0:'.$langs->trans("All");     // Not yet supported
4169 4362
 //$pagesizechoices.=',2:2';
4170
-            if (!empty(Globals::$conf->global->MAIN_PAGESIZE_CHOICES))
4171
-                $pagesizechoices = Globals::$conf->global->MAIN_PAGESIZE_CHOICES;
4363
+            if (!empty(Globals::$conf->global->MAIN_PAGESIZE_CHOICES)) {
4364
+                            $pagesizechoices = Globals::$conf->global->MAIN_PAGESIZE_CHOICES;
4365
+            }
4172 4366
 
4173 4367
             print '<li class="pagination">';
4174 4368
             print '<select class="flat selectlimit" name="limit" title="' . dol_escape_htmltag($langs->trans("MaxNbOfRecordPerPage")) . '">';
4175 4369
             $tmpchoice = explode(',', $pagesizechoices);
4176 4370
             $tmpkey = $limit . ':' . $limit;
4177
-            if (!in_array($tmpkey, $tmpchoice))
4178
-                $tmpchoice[] = $tmpkey;
4371
+            if (!in_array($tmpkey, $tmpchoice)) {
4372
+                            $tmpchoice[] = $tmpkey;
4373
+            }
4179 4374
             $tmpkey = Globals::$conf->liste_limit . ':' . Globals::$conf->liste_limit;
4180
-            if (!in_array($tmpkey, $tmpchoice))
4181
-                $tmpchoice[] = $tmpkey;
4375
+            if (!in_array($tmpkey, $tmpchoice)) {
4376
+                            $tmpchoice[] = $tmpkey;
4377
+            }
4182 4378
             asort($tmpchoice, SORT_NUMERIC);
4183 4379
             $found = false;
4184 4380
             foreach ($tmpchoice as $val) {
@@ -4254,14 +4450,15 @@  discard block
 block discarded – undo
4254 4450
         }
4255 4451
 
4256 4452
 // If rate is '9/9/9' we don't change it.  If rate is '9.000' we apply price()
4257
-        if (!preg_match('/\//', $rate))
4258
-            $ret = price($rate, 0, '', 0, 0) . ($addpercent ? '%' : '');
4259
-        else {
4453
+        if (!preg_match('/\//', $rate)) {
4454
+                    $ret = price($rate, 0, '', 0, 0) . ($addpercent ? '%' : '');
4455
+        } else {
4260 4456
 // TODO Split on / and output with a price2num to have clean numbers without ton of 000.
4261 4457
             $ret = $rate . ($addpercent ? '%' : '');
4262 4458
         }
4263
-        if (($info_bits & 1) && $usestarfornpr >= 0)
4264
-            $ret .= ' *';
4459
+        if (($info_bits & 1) && $usestarfornpr >= 0) {
4460
+                    $ret .= ' *';
4461
+        }
4265 4462
         $ret .= $morelabel;
4266 4463
         return $ret;
4267 4464
     }
@@ -4285,11 +4482,14 @@  discard block
 block discarded – undo
4285 4482
     {
4286 4483
        // global $langs, Globals::$conf;
4287 4484
 // Clean parameters
4288
-        if (empty($amount))
4289
-            $amount = 0; // To have a numeric value if amount not defined or = ''
4485
+        if (empty($amount)) {
4486
+                    $amount = 0;
4487
+        }
4488
+        // To have a numeric value if amount not defined or = ''
4290 4489
         $amount = (is_numeric($amount) ? $amount : 0); // Check if amount is numeric, for example, an error occured when amount value = o (letter) instead 0 (number)
4291
-        if ($rounding < 0)
4292
-            $rounding = min(Globals::$conf->global->MAIN_MAX_DECIMALS_UNIT, Globals::$conf->global->MAIN_MAX_DECIMALS_TOT);
4490
+        if ($rounding < 0) {
4491
+                    $rounding = min(Globals::$conf->global->MAIN_MAX_DECIMALS_UNIT, Globals::$conf->global->MAIN_MAX_DECIMALS_TOT);
4492
+        }
4293 4493
         $nbdecimal = $rounding;
4294 4494
 
4295 4495
 // Output separators by default (french)
@@ -4297,18 +4497,22 @@  discard block
 block discarded – undo
4297 4497
         $thousand = ' ';
4298 4498
 
4299 4499
 // If $outlangs not forced, we use use language
4300
-        if (!is_object($outlangs))
4301
-            $outlangs = $langs;
4302
-
4303
-        if ($outlangs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal")
4304
-            $dec = $outlangs->transnoentitiesnoconv("SeparatorDecimal");
4305
-        if ($outlangs->transnoentitiesnoconv("SeparatorThousand") != "SeparatorThousand")
4306
-            $thousand = $outlangs->transnoentitiesnoconv("SeparatorThousand");
4307
-        if ($thousand == 'None')
4308
-            $thousand = '';
4309
-        else if ($thousand == 'Space')
4310
-            $thousand = ' ';
4311
-//print "outlangs=".$outlangs->defaultlang." amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'<br>";
4500
+        if (!is_object($outlangs)) {
4501
+                    $outlangs = $langs;
4502
+        }
4503
+
4504
+        if ($outlangs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal") {
4505
+                    $dec = $outlangs->transnoentitiesnoconv("SeparatorDecimal");
4506
+        }
4507
+        if ($outlangs->transnoentitiesnoconv("SeparatorThousand") != "SeparatorThousand") {
4508
+                    $thousand = $outlangs->transnoentitiesnoconv("SeparatorThousand");
4509
+        }
4510
+        if ($thousand == 'None') {
4511
+                    $thousand = '';
4512
+        } else if ($thousand == 'Space') {
4513
+                    $thousand = ' ';
4514
+        }
4515
+        //print "outlangs=".$outlangs->defaultlang." amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'<br>";
4312 4516
 //print "amount=".$amount."-";
4313 4517
         $amount = str_replace(',', '.', $amount); // should be useless
4314 4518
 //print $amount."-";
@@ -4319,9 +4523,10 @@  discard block
 block discarded – undo
4319 4523
         $end = '';
4320 4524
 
4321 4525
 // We increase nbdecimal if there is more decimal than asked (to not loose information)
4322
-        if (dol_strlen($decpart) > $nbdecimal)
4323
-            $nbdecimal = dol_strlen($decpart);
4324
-// Si on depasse max
4526
+        if (dol_strlen($decpart) > $nbdecimal) {
4527
+                    $nbdecimal = dol_strlen($decpart);
4528
+        }
4529
+        // Si on depasse max
4325 4530
         if ($trunc && $nbdecimal > Globals::$conf->global->MAIN_MAX_DECIMALS_SHOWN) {
4326 4531
             $nbdecimal = Globals::$conf->global->MAIN_MAX_DECIMALS_SHOWN;
4327 4532
             if (preg_match('/\.\.\./i', Globals::$conf->global->MAIN_MAX_DECIMALS_SHOWN)) {
@@ -4331,8 +4536,9 @@  discard block
 block discarded – undo
4331 4536
         }
4332 4537
 
4333 4538
 // If force rounding
4334
-        if ($forcerounding >= 0)
4335
-            $nbdecimal = $forcerounding;
4539
+        if ($forcerounding >= 0) {
4540
+                    $nbdecimal = $forcerounding;
4541
+        }
4336 4542
 
4337 4543
 // Format number
4338 4544
         $output = number_format($amount, $nbdecimal, $dec, $thousand);
@@ -4343,13 +4549,14 @@  discard block
 block discarded – undo
4343 4549
 // Add symbol of currency if requested
4344 4550
         $cursymbolbefore = $cursymbolafter = '';
4345 4551
         if ($currency_code) {
4346
-            if ($currency_code == 'auto')
4347
-                $currency_code = Globals::$conf->currency;
4552
+            if ($currency_code == 'auto') {
4553
+                            $currency_code = Globals::$conf->currency;
4554
+            }
4348 4555
 
4349 4556
             $listofcurrenciesbefore = array('USD', 'GBP', 'AUD', 'MXN', 'PEN', 'CNY');
4350
-            if (in_array($currency_code, $listofcurrenciesbefore))
4351
-                $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
4352
-            else {
4557
+            if (in_array($currency_code, $listofcurrenciesbefore)) {
4558
+                            $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
4559
+            } else {
4353 4560
                 $tmpcur = $outlangs->getCurrencySymbol($currency_code);
4354 4561
                 $cursymbolafter .= ($tmpcur == $currency_code ? ' ' . $tmpcur : $tmpcur);
4355 4562
             }
@@ -4382,15 +4589,18 @@  discard block
 block discarded – undo
4382 4589
 // Decimal delimiter for PHP and database SQL requests must be '.'
4383 4590
         $dec = ',';
4384 4591
         $thousand = ' ';
4385
-        if ($langs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal")
4386
-            $dec = $langs->transnoentitiesnoconv("SeparatorDecimal");
4387
-        if ($langs->transnoentitiesnoconv("SeparatorThousand") != "SeparatorThousand")
4388
-            $thousand = $langs->transnoentitiesnoconv("SeparatorThousand");
4389
-        if ($thousand == 'None')
4390
-            $thousand = '';
4391
-        elseif ($thousand == 'Space')
4392
-            $thousand = ' ';
4393
-//print "amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'<br>";
4592
+        if ($langs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal") {
4593
+                    $dec = $langs->transnoentitiesnoconv("SeparatorDecimal");
4594
+        }
4595
+        if ($langs->transnoentitiesnoconv("SeparatorThousand") != "SeparatorThousand") {
4596
+                    $thousand = $langs->transnoentitiesnoconv("SeparatorThousand");
4597
+        }
4598
+        if ($thousand == 'None') {
4599
+                    $thousand = '';
4600
+        } elseif ($thousand == 'Space') {
4601
+                    $thousand = ' ';
4602
+        }
4603
+        //print "amount=".$amount." html=".$form." trunc=".$trunc." nbdecimal=".$nbdecimal." dec='".$dec."' thousand='".$thousand."'<br>";
4394 4604
 // Convert value to universal number format (no thousand separator, '.' as decimal separator)
4395 4605
         if ($alreadysqlnb != 1) { // If not a PHP number or unknown, we change format
4396 4606
 //print 'PP'.$amount.' - '.$dec.' - '.$thousand.' - '.intval($amount).'<br>';
@@ -4405,8 +4615,10 @@  discard block
 block discarded – undo
4405 4615
             }
4406 4616
 //print "QQ".$amount.'<br>';
4407 4617
 // Now make replace (the main goal of function)
4408
-            if ($thousand != ',' && $thousand != '.')
4409
-                $amount = str_replace(',', '.', $amount); // To accept 2 notations for french users
4618
+            if ($thousand != ',' && $thousand != '.') {
4619
+                            $amount = str_replace(',', '.', $amount);
4620
+            }
4621
+            // To accept 2 notations for french users
4410 4622
             $amount = str_replace(' ', '', $amount);  // To avoid spaces
4411 4623
             $amount = str_replace($thousand, '', $amount); // Replace of thousand before replace of dec to avoid pb if thousand is .
4412 4624
             $amount = str_replace($dec, '.', $amount);
@@ -4415,20 +4627,24 @@  discard block
 block discarded – undo
4415 4627
 // Now, make a rounding if required
4416 4628
         if ($rounding) {
4417 4629
             $nbofdectoround = '';
4418
-            if ($rounding == 'MU')
4419
-                $nbofdectoround = Globals::$conf->global->MAIN_MAX_DECIMALS_UNIT;
4420
-            elseif ($rounding == 'MT')
4421
-                $nbofdectoround = Globals::$conf->global->MAIN_MAX_DECIMALS_TOT;
4422
-            elseif ($rounding == 'MS')
4423
-                $nbofdectoround = empty(Globals::$conf->global->MAIN_MAX_DECIMALS_STOCK) ? 5 : Globals::$conf->global->MAIN_MAX_DECIMALS_STOCK;
4424
-            elseif (is_numeric($rounding))
4425
-                $nbofdectoround = $rounding;
4426
-//print "RR".$amount.' - '.$nbofdectoround.'<br>';
4427
-            if (dol_strlen($nbofdectoround))
4428
-                $amount = round($amount, $nbofdectoround); // $nbofdectoround can be 0.
4429
-            else
4430
-                return 'ErrorBadParameterProvidedToFunction';
4431
-//print 'SS'.$amount.' - '.$nbofdec.' - '.$dec.' - '.$thousand.' - '.$nbofdectoround.'<br>';
4630
+            if ($rounding == 'MU') {
4631
+                            $nbofdectoround = Globals::$conf->global->MAIN_MAX_DECIMALS_UNIT;
4632
+            } elseif ($rounding == 'MT') {
4633
+                            $nbofdectoround = Globals::$conf->global->MAIN_MAX_DECIMALS_TOT;
4634
+            } elseif ($rounding == 'MS') {
4635
+                            $nbofdectoround = empty(Globals::$conf->global->MAIN_MAX_DECIMALS_STOCK) ? 5 : Globals::$conf->global->MAIN_MAX_DECIMALS_STOCK;
4636
+            } elseif (is_numeric($rounding)) {
4637
+                            $nbofdectoround = $rounding;
4638
+            }
4639
+            //print "RR".$amount.' - '.$nbofdectoround.'<br>';
4640
+            if (dol_strlen($nbofdectoround)) {
4641
+                            $amount = round($amount, $nbofdectoround);
4642
+            }
4643
+            // $nbofdectoround can be 0.
4644
+            else {
4645
+                            return 'ErrorBadParameterProvidedToFunction';
4646
+            }
4647
+            //print 'SS'.$amount.' - '.$nbofdec.' - '.$dec.' - '.$thousand.' - '.$nbofdectoround.'<br>';
4432 4648
 // Convert amount to format with dolibarr dec and thousand (this is because PHP convert a number
4433 4649
 // to format defined by LC_NUMERIC after a calculation and we want source format to be defined by Dolibarr setup.
4434 4650
             if (is_numeric($amount)) {
@@ -4441,8 +4657,10 @@  discard block
 block discarded – undo
4441 4657
 //print "TT".$amount.'<br>';
4442 4658
 // Always make replace because each math static function (like round) replace
4443 4659
 // with local values and we want a number that has a SQL string format x.y
4444
-            if ($thousand != ',' && $thousand != '.')
4445
-                $amount = str_replace(',', '.', $amount); // To accept 2 notations for french users
4660
+            if ($thousand != ',' && $thousand != '.') {
4661
+                            $amount = str_replace(',', '.', $amount);
4662
+            }
4663
+            // To accept 2 notations for french users
4446 4664
             $amount = str_replace(' ', '', $amount);  // To avoid spaces
4447 4665
             $amount = str_replace($thousand, '', $amount); // Replace of thousand before replace of dec to avoid pb if thousand is .
4448 4666
             $amount = str_replace($dec, '.', $amount);
@@ -4501,8 +4719,9 @@  discard block
 block discarded – undo
4501 4719
     {
4502 4720
        // global $db, Globals::$conf, $mysoc;
4503 4721
 
4504
-        if (empty($thirdparty_seller) || !is_object($thirdparty_seller))
4505
-            $thirdparty_seller = $mysoc;
4722
+        if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) {
4723
+                    $thirdparty_seller = $mysoc;
4724
+        }
4506 4725
 
4507 4726
         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);
4508 4727
 
@@ -4520,37 +4739,43 @@  discard block
 block discarded – undo
4520 4739
 // Some test to guess with no need to make database access
4521 4740
         if ($mysoc->country_code == 'ES') { // For spain localtaxes 1 and 2, tax is qualified if buyer use local tax
4522 4741
             if ($local == 1) {
4523
-                if (!$mysoc->localtax1_assuj || (string) $vatratecleaned == "0")
4524
-                    return 0;
4742
+                if (!$mysoc->localtax1_assuj || (string) $vatratecleaned == "0") {
4743
+                                    return 0;
4744
+                }
4525 4745
                 if ($thirdparty_seller->id == $mysoc->id) {
4526
-                    if (!$thirdparty_buyer->localtax1_assuj)
4527
-                        return 0;
4528
-                }
4529
-                else {
4530
-                    if (!$thirdparty_seller->localtax1_assuj)
4531
-                        return 0;
4746
+                    if (!$thirdparty_buyer->localtax1_assuj) {
4747
+                                            return 0;
4748
+                    }
4749
+                } else {
4750
+                    if (!$thirdparty_seller->localtax1_assuj) {
4751
+                                            return 0;
4752
+                    }
4532 4753
                 }
4533 4754
             }
4534 4755
 
4535 4756
             if ($local == 2) {
4536 4757
 //if (! $mysoc->localtax2_assuj || (string) $vatratecleaned == "0") return 0;
4537
-                if (!$mysoc->localtax2_assuj)
4538
-                    return 0;  // If main vat is 0, IRPF may be different than 0.
4758
+                if (!$mysoc->localtax2_assuj) {
4759
+                                    return 0;
4760
+                }
4761
+                // If main vat is 0, IRPF may be different than 0.
4539 4762
                 if ($thirdparty_seller->id == $mysoc->id) {
4540
-                    if (!$thirdparty_buyer->localtax2_assuj)
4541
-                        return 0;
4542
-                }
4543
-                else {
4544
-                    if (!$thirdparty_seller->localtax2_assuj)
4545
-                        return 0;
4763
+                    if (!$thirdparty_buyer->localtax2_assuj) {
4764
+                                            return 0;
4765
+                    }
4766
+                } else {
4767
+                    if (!$thirdparty_seller->localtax2_assuj) {
4768
+                                            return 0;
4769
+                    }
4546 4770
                 }
4547 4771
             }
4548
-        }
4549
-        else {
4550
-            if ($local == 1 && !$thirdparty_seller->localtax1_assuj)
4551
-                return 0;
4552
-            if ($local == 2 && !$thirdparty_seller->localtax2_assuj)
4553
-                return 0;
4772
+        } else {
4773
+            if ($local == 1 && !$thirdparty_seller->localtax1_assuj) {
4774
+                            return 0;
4775
+            }
4776
+            if ($local == 2 && !$thirdparty_seller->localtax2_assuj) {
4777
+                            return 0;
4778
+            }
4554 4779
         }
4555 4780
 
4556 4781
 // For some country MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY is forced to on.
@@ -4592,19 +4817,23 @@  discard block
 block discarded – undo
4592 4817
         $sql .= " FROM " . MAIN_DB_PREFIX . "c_tva as t, " . MAIN_DB_PREFIX . "c_country as c";
4593 4818
         $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '" . $thirdparty_seller->country_code . "'";
4594 4819
         $sql .= " AND t.taux = " . ((float) $vatratecleaned) . " AND t.active = 1";
4595
-        if ($vatratecode)
4596
-            $sql .= " AND t.code ='" . $vatratecode . "'";  // If we have the code, we use it in priority
4597
-        else
4598
-            $sql .= " AND t.recuperableonly ='" . $vatnpr . "'";
4820
+        if ($vatratecode) {
4821
+                    $sql .= " AND t.code ='" . $vatratecode . "'";
4822
+        }
4823
+        // If we have the code, we use it in priority
4824
+        else {
4825
+                    $sql .= " AND t.recuperableonly ='" . $vatnpr . "'";
4826
+        }
4599 4827
         dol_syslog("get_localtax", LOG_DEBUG);
4600 4828
         $resql = $db->query($sql);
4601 4829
 
4602 4830
         if ($resql) {
4603 4831
             $obj = $db->fetch_object($resql);
4604
-            if ($local == 1)
4605
-                return $obj->localtax1;
4606
-            elseif ($local == 2)
4607
-                return $obj->localtax2;
4832
+            if ($local == 1) {
4833
+                            return $obj->localtax1;
4834
+            } elseif ($local == 2) {
4835
+                            return $obj->localtax2;
4836
+            }
4608 4837
         }
4609 4838
 
4610 4839
         return 0;
@@ -4650,10 +4879,11 @@  discard block
 block discarded – undo
4650 4879
         $resql = $db->query($sql);
4651 4880
         if ($resql) {
4652 4881
             $obj = $db->fetch_object($resql);
4653
-            if ($local == 1)
4654
-                return $obj->localtax1;
4655
-            elseif ($local == 2)
4656
-                return $obj->localtax2;
4882
+            if ($local == 1) {
4883
+                            return $obj->localtax1;
4884
+            } elseif ($local == 2) {
4885
+                            return $obj->localtax2;
4886
+            }
4657 4887
         }
4658 4888
 
4659 4889
         return 0;
@@ -4679,9 +4909,9 @@  discard block
 block discarded – undo
4679 4909
 // Search local taxes
4680 4910
         $sql = "SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy";
4681 4911
         $sql .= " FROM " . MAIN_DB_PREFIX . "c_tva as t";
4682
-        if ($firstparamisid)
4683
-            $sql .= " WHERE t.rowid = " . (int) $vatrate;
4684
-        else {
4912
+        if ($firstparamisid) {
4913
+                    $sql .= " WHERE t.rowid = " . (int) $vatrate;
4914
+        } else {
4685 4915
             $vatratecleaned = $vatrate;
4686 4916
             $vatratecode = '';
4687 4917
             if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {      // If vat is "xx (yy)"
@@ -4694,19 +4924,22 @@  discard block
 block discarded – undo
4694 4924
               else $sql.= " WHERE t.fk_pays = c.rowid AND c.code = '".$seller->country_code."'"; */
4695 4925
             $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '" . $seller->country_code . "'";
4696 4926
             $sql .= " AND t.taux = " . ((float) $vatratecleaned) . " AND t.active = 1";
4697
-            if ($vatratecode)
4698
-                $sql .= " AND t.code = '" . $vatratecode . "'";
4927
+            if ($vatratecode) {
4928
+                            $sql .= " AND t.code = '" . $vatratecode . "'";
4929
+            }
4699 4930
         }
4700 4931
 
4701 4932
         $resql = $db->query($sql);
4702 4933
         if ($resql) {
4703 4934
             $obj = $db->fetch_object($resql);
4704
-            if ($obj)
4705
-                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);
4706
-            else
4707
-                return array();
4708
-        } else
4709
-            dol_print_error($db);
4935
+            if ($obj) {
4936
+                            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);
4937
+            } else {
4938
+                            return array();
4939
+            }
4940
+        } else {
4941
+                    dol_print_error($db);
4942
+        }
4710 4943
 
4711 4944
         return array();
4712 4945
     }
@@ -4736,9 +4969,9 @@  discard block
 block discarded – undo
4736 4969
 // Search local taxes
4737 4970
         $sql = "SELECT t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.accountancy_code_sell, t.accountancy_code_buy";
4738 4971
         $sql .= " FROM " . MAIN_DB_PREFIX . "c_tva as t";
4739
-        if ($firstparamisid)
4740
-            $sql .= " WHERE t.rowid = " . (int) $vatrate;
4741
-        else {
4972
+        if ($firstparamisid) {
4973
+                    $sql .= " WHERE t.rowid = " . (int) $vatrate;
4974
+        } else {
4742 4975
             $vatratecleaned = $vatrate;
4743 4976
             $vatratecode = '';
4744 4977
             if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {      // If vat is "x.x (yy)"
@@ -4747,13 +4980,17 @@  discard block
 block discarded – undo
4747 4980
             }
4748 4981
 
4749 4982
             $sql .= ", " . MAIN_DB_PREFIX . "c_country as c";
4750
-            if ($mysoc->country_code == 'ES')
4751
-                $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '" . $buyer->country_code . "'";    // local tax in spain use the buyer country ??
4752
-            else
4753
-                $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '" . $seller->country_code . "'";
4983
+            if ($mysoc->country_code == 'ES') {
4984
+                            $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '" . $buyer->country_code . "'";
4985
+            }
4986
+            // local tax in spain use the buyer country ??
4987
+            else {
4988
+                            $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '" . $seller->country_code . "'";
4989
+            }
4754 4990
             $sql .= " AND t.taux = " . ((float) $vatratecleaned) . " AND t.active = 1";
4755
-            if ($vatratecode)
4756
-                $sql .= " AND t.code = '" . $vatratecode . "'";
4991
+            if ($vatratecode) {
4992
+                            $sql .= " AND t.code = '" . $vatratecode . "'";
4993
+            }
4757 4994
         }
4758 4995
 
4759 4996
         $resql = $db->query($sql);
@@ -4799,17 +5036,17 @@  discard block
 block discarded – undo
4799 5036
                 if ($idprodfournprice > 0) {     // We want vat for product for a "supplier" object
4800 5037
                     $product->get_buyprice($idprodfournprice, 0, 0, 0);
4801 5038
                     $ret = $product->vatrate_supplier;
4802
-                    if ($product->default_vat_code)
4803
-                        $ret .= ' (' . $product->default_vat_code . ')';
4804
-                }
4805
-                else {
5039
+                    if ($product->default_vat_code) {
5040
+                                            $ret .= ' (' . $product->default_vat_code . ')';
5041
+                    }
5042
+                } else {
4806 5043
                     $ret = $product->tva_tx;    // Default vat of product we defined
4807
-                    if ($product->default_vat_code)
4808
-                        $ret .= ' (' . $product->default_vat_code . ')';
5044
+                    if ($product->default_vat_code) {
5045
+                                            $ret .= ' (' . $product->default_vat_code . ')';
5046
+                    }
4809 5047
                 }
4810 5048
                 $found = 1;
4811
-            }
4812
-            else {
5049
+            } else {
4813 5050
 // TODO Read default product vat according to countrycode and product. Vat for couple countrycode/product is a feature not implemeted yet.
4814 5051
 // May be usefull/required if hidden option SERVICE_ARE_ECOMMERCE_200238EC is on
4815 5052
             }
@@ -4829,14 +5066,18 @@  discard block
 block discarded – undo
4829 5066
                     $obj = $db->fetch_object($resql);
4830 5067
                     if ($obj) {
4831 5068
                         $ret = $obj->vat_rate;
4832
-                        if ($obj->default_vat_code)
4833
-                            $ret .= ' (' . $obj->default_vat_code . ')';
5069
+                        if ($obj->default_vat_code) {
5070
+                                                    $ret .= ' (' . $obj->default_vat_code . ')';
5071
+                        }
4834 5072
                     }
4835 5073
                     $db->free($sql);
4836
-                } else
4837
-                    dol_print_error($db);
4838
-            } else
4839
-                $ret = Globals::$conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;    // Forced value if autodetect fails
5074
+                } else {
5075
+                                    dol_print_error($db);
5076
+                }
5077
+            } else {
5078
+                            $ret = Globals::$conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;
5079
+            }
5080
+            // Forced value if autodetect fails
4840 5081
         }
4841 5082
 
4842 5083
         dol_syslog("get_product_vat_for_country: ret=" . $ret);
@@ -4891,13 +5132,15 @@  discard block
 block discarded – undo
4891 5132
             if ($resql) {
4892 5133
                 $obj = $db->fetch_object($resql);
4893 5134
                 if ($obj) {
4894
-                    if ($local == 1)
4895
-                        $ret = $obj->localtax1;
4896
-                    elseif ($local == 2)
4897
-                        $ret = $obj->localtax2;
5135
+                    if ($local == 1) {
5136
+                                            $ret = $obj->localtax1;
5137
+                    } elseif ($local == 2) {
5138
+                                            $ret = $obj->localtax2;
5139
+                    }
4898 5140
                 }
4899
-            } else
4900
-                dol_print_error($db);
5141
+            } else {
5142
+                            dol_print_error($db);
5143
+            }
4901 5144
         }
4902 5145
 
4903 5146
         dol_syslog("get_product_localtax_for_country: ret=" . $ret);
@@ -5000,15 +5243,16 @@  discard block
 block discarded – undo
5000 5243
        // global $db;
5001 5244
 
5002 5245
         if ($idprodfournprice > 0) {
5003
-            if (!class_exists('ProductFournisseur'))
5004
-                require_once DOL_BASE_PATH . '/fourn/class/fournisseur.product.class.php';
5246
+            if (!class_exists('ProductFournisseur')) {
5247
+                            require_once DOL_BASE_PATH . '/fourn/class/fournisseur.product.class.php';
5248
+            }
5005 5249
             $prodprice = new ProductFournisseur($db);
5006 5250
             $prodprice->fetch_product_fournisseur_price($idprodfournprice);
5007 5251
             return $prodprice->fourn_tva_npr;
5008
-        }
5009
-        elseif ($idprod > 0) {
5010
-            if (!class_exists('Product'))
5011
-                require_once DOL_BASE_PATH . 'product/class/product.class.php';
5252
+        } elseif ($idprod > 0) {
5253
+            if (!class_exists('Product')) {
5254
+                            require_once DOL_BASE_PATH . 'product/class/product.class.php';
5255
+            }
5012 5256
             $prod = new Product($db);
5013 5257
             $prod->fetch($idprod);
5014 5258
             return $prod->tva_npr;
@@ -5034,30 +5278,35 @@  discard block
 block discarded – undo
5034 5278
     {
5035 5279
        // global $mysoc;
5036 5280
 
5037
-        if (!is_object($thirdparty_seller))
5038
-            return -1;
5039
-        if (!is_object($thirdparty_buyer))
5040
-            return -1;
5281
+        if (!is_object($thirdparty_seller)) {
5282
+                    return -1;
5283
+        }
5284
+        if (!is_object($thirdparty_buyer)) {
5285
+                    return -1;
5286
+        }
5041 5287
 
5042 5288
         if ($local == 1) { // Localtax 1
5043 5289
             if ($mysoc->country_code == 'ES') {
5044
-                if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj)
5045
-                    return 0;
5046
-            }
5047
-            else {
5290
+                if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) {
5291
+                                    return 0;
5292
+                }
5293
+            } else {
5048 5294
 // Si vendeur non assujeti a Localtax1, localtax1 par default=0
5049
-                if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj)
5050
-                    return 0;
5051
-                if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj == 'localtax1off')
5052
-                    return 0;
5053
-            }
5054
-        }
5055
-        elseif ($local == 2) { //I Localtax 2
5295
+                if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) {
5296
+                                    return 0;
5297
+                }
5298
+                if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj == 'localtax1off') {
5299
+                                    return 0;
5300
+                }
5301
+            }
5302
+        } elseif ($local == 2) { //I Localtax 2
5056 5303
 // Si vendeur non assujeti a Localtax2, localtax2 par default=0
5057
-            if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj)
5058
-                return 0;
5059
-            if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj == 'localtax2off')
5060
-                return 0;
5304
+            if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) {
5305
+                            return 0;
5306
+            }
5307
+            if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj == 'localtax2off') {
5308
+                            return 0;
5309
+            }
5061 5310
         }
5062 5311
 
5063 5312
         if ($thirdparty_seller->country_code == $thirdparty_buyer->country_code) {
@@ -5082,31 +5331,38 @@  discard block
 block discarded – undo
5082 5331
         $classname = '';
5083 5332
         if ($yesno == 1 || strtolower($yesno) == 'yes' || strtolower($yesno) == 'true') {  // A mettre avant test sur no a cause du == 0
5084 5333
             $result = $langs->trans('yes');
5085
-            if ($case == 1 || $case == 3)
5086
-                $result = $langs->trans("Yes");
5087
-            if ($case == 2)
5088
-                $result = '<input type="checkbox" value="1" checked disabled>';
5089
-            if ($case == 3)
5090
-                $result = '<input type="checkbox" value="1" checked disabled> ' . $result;
5334
+            if ($case == 1 || $case == 3) {
5335
+                            $result = $langs->trans("Yes");
5336
+            }
5337
+            if ($case == 2) {
5338
+                            $result = '<input type="checkbox" value="1" checked disabled>';
5339
+            }
5340
+            if ($case == 3) {
5341
+                            $result = '<input type="checkbox" value="1" checked disabled> ' . $result;
5342
+            }
5091 5343
 
5092 5344
             $classname = 'ok';
5093
-        }
5094
-        elseif ($yesno == 0 || strtolower($yesno) == 'no' || strtolower($yesno) == 'false') {
5345
+        } elseif ($yesno == 0 || strtolower($yesno) == 'no' || strtolower($yesno) == 'false') {
5095 5346
             $result = $langs->trans("no");
5096
-            if ($case == 1 || $case == 3)
5097
-                $result = $langs->trans("No");
5098
-            if ($case == 2)
5099
-                $result = '<input type="checkbox" value="0" disabled>';
5100
-            if ($case == 3)
5101
-                $result = '<input type="checkbox" value="0" disabled> ' . $result;
5102
-
5103
-            if ($color == 2)
5104
-                $classname = 'ok';
5105
-            else
5106
-                $classname = 'error';
5107
-        }
5108
-        if ($color)
5109
-            return '<font class="' . $classname . '">' . $result . '</font>';
5347
+            if ($case == 1 || $case == 3) {
5348
+                            $result = $langs->trans("No");
5349
+            }
5350
+            if ($case == 2) {
5351
+                            $result = '<input type="checkbox" value="0" disabled>';
5352
+            }
5353
+            if ($case == 3) {
5354
+                            $result = '<input type="checkbox" value="0" disabled> ' . $result;
5355
+            }
5356
+
5357
+            if ($color == 2) {
5358
+                            $classname = 'ok';
5359
+            } else {
5360
+                            $classname = 'error';
5361
+            }
5362
+        }
5363
+        if ($color) {
5364
+                    return '<font class="' . $classname . '">' . $result . '</font>';
5365
+        }
5110 5366
         return $result;
5111 5367
     }
5112 5368
 
@@ -5132,23 +5388,27 @@  discard block
 block discarded – undo
5132 5388
         $path = '';
5133 5389
 
5134 5390
         $arrayforoldpath = array('cheque', 'user', 'category', 'holiday', 'supplier_invoice', 'invoice_supplier', 'mailing', 'supplier_payment');
5135
-        if (!empty(Globals::$conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
5136
-            $arrayforoldpath[] = 'product';
5391
+        if (!empty(Globals::$conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
5392
+                    $arrayforoldpath[] = 'product';
5393
+        }
5137 5394
         if (!empty($level) && in_array($modulepart, $arrayforoldpath)) {
5138 5395
 // This part should be removed once all code is using "get_exdir" to forge path, with all parameters provided.
5139
-            if (empty($alpha))
5140
-                $num = preg_replace('/([^0-9])/i', '', $num);
5141
-            else
5142
-                $num = preg_replace('/^.*\-/i', '', $num);
5396
+            if (empty($alpha)) {
5397
+                            $num = preg_replace('/([^0-9])/i', '', $num);
5398
+            } else {
5399
+                            $num = preg_replace('/^.*\-/i', '', $num);
5400
+            }
5143 5401
             $num = substr("000" . $num, -$level);
5144
-            if ($level == 1)
5145
-                $path = substr($num, 0, 1);
5146
-            if ($level == 2)
5147
-                $path = substr($num, 1, 1) . '/' . substr($num, 0, 1);
5148
-            if ($level == 3)
5149
-                $path = substr($num, 2, 1) . '/' . substr($num, 1, 1) . '/' . substr($num, 0, 1);
5150
-        }
5151
-        else {
5402
+            if ($level == 1) {
5403
+                            $path = substr($num, 0, 1);
5404
+            }
5405
+            if ($level == 2) {
5406
+                            $path = substr($num, 1, 1) . '/' . substr($num, 0, 1);
5407
+            }
5408
+            if ($level == 3) {
5409
+                            $path = substr($num, 2, 1) . '/' . substr($num, 1, 1) . '/' . substr($num, 0, 1);
5410
+            }
5411
+        } else {
5152 5412
 // TODO
5153 5413
 // We will enhance here a common way of forging path for document storage
5154 5414
 // Here, object->id, object->ref and modulepart are required.
@@ -5159,8 +5419,9 @@  discard block
 block discarded – undo
5159 5419
             }
5160 5420
         }
5161 5421
 
5162
-        if (empty($withoutslash) && !empty($path))
5163
-            $path .= '/';
5422
+        if (empty($withoutslash) && !empty($path)) {
5423
+                    $path .= '/';
5424
+        }
5164 5425
 
5165 5426
         return $path;
5166 5427
     }
@@ -5180,8 +5441,9 @@  discard block
 block discarded – undo
5180 5441
         dol_syslog("functions.lib::dol_mkdir: dir=" . $dir, LOG_INFO);
5181 5442
 
5182 5443
         $dir_osencoded = dol_osencode($dir);
5183
-        if (@is_dir($dir_osencoded))
5184
-            return 0;
5444
+        if (@is_dir($dir_osencoded)) {
5445
+                    return 0;
5446
+        }
5185 5447
 
5186 5448
         $nberr = 0;
5187 5449
         $nbcreated = 0;
@@ -5196,12 +5458,15 @@  discard block
 block discarded – undo
5196 5458
         $cdir = explode("/", $dir);
5197 5459
         $num = count($cdir);
5198 5460
         for ($i = 0; $i < $num; $i++) {
5199
-            if ($i > 0)
5200
-                $ccdir .= '/' . $cdir[$i];
5201
-            else
5202
-                $ccdir .= $cdir[$i];
5203
-            if (preg_match("/^.:$/", $ccdir, $regs))
5204
-                continue; // Si chemin Windows incomplet, on poursuit par rep suivant
5461
+            if ($i > 0) {
5462
+                            $ccdir .= '/' . $cdir[$i];
5463
+            } else {
5464
+                            $ccdir .= $cdir[$i];
5465
+            }
5466
+            if (preg_match("/^.:$/", $ccdir, $regs)) {
5467
+                            continue;
5468
+            }
5469
+            // Si chemin Windows incomplet, on poursuit par rep suivant
5205 5470
 
5206 5471
 
5207 5472
 
@@ -5293,8 +5558,9 @@  discard block
 block discarded – undo
5293 5558
      */
5294 5559
     static function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto = 'UTF-8', $strip_tags = 0)
5295 5560
     {
5296
-        if ($removelinefeed == 2)
5297
-            $stringtoclean = preg_replace('/<br[^>]*>\n+/ims', '<br>', $stringtoclean);
5561
+        if ($removelinefeed == 2) {
5562
+                    $stringtoclean = preg_replace('/<br[^>]*>\n+/ims', '<br>', $stringtoclean);
5563
+        }
5298 5564
         $temp = preg_replace('/<br[^>]*>/i', "\n", $stringtoclean);
5299 5565
 
5300 5566
         if ($strip_tags) {
@@ -5311,8 +5577,9 @@  discard block
 block discarded – undo
5311 5577
         $temp = dol_html_entity_decode($temp, ENT_COMPAT, $pagecodeto);
5312 5578
 
5313 5579
 // Supprime aussi les retours
5314
-        if ($removelinefeed == 1)
5315
-            $temp = str_replace(array("\r\n", "\r", "\n"), " ", $temp);
5580
+        if ($removelinefeed == 1) {
5581
+                    $temp = str_replace(array("\r\n", "\r", "\n"), " ", $temp);
5582
+        }
5316 5583
 
5317 5584
 // et les espaces doubles
5318 5585
         while (strpos($temp, "  ")) {
@@ -5398,18 +5665,21 @@  discard block
 block discarded – undo
5398 5665
             if ($charset == 'UTF-8') {
5399 5666
                 $pattern = '/(<br[^>]*>)/Uu';
5400 5667
             } // /U is to have UNGREEDY regex to limit to one html tag. /u is for UTF8 support
5401
-            else
5402
-                $pattern = '/(<br[^>]*>)/U';       // /U is to have UNGREEDY regex to limit to one html tag.
5668
+            else {
5669
+                            $pattern = '/(<br[^>]*>)/U';
5670
+            }
5671
+            // /U is to have UNGREEDY regex to limit to one html tag.
5403 5672
             $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
5404 5673
 
5405 5674
             $firstline = '';
5406 5675
             $i = 0;
5407 5676
             $nba = count($a); // 2x nb of lines in $a because $a contains also a line for each new line separator
5408 5677
             while (($i < $nba) && ($i < ($nboflines * 2))) {
5409
-                if ($i % 2 == 0)
5410
-                    $firstline .= $a[$i];
5411
-                elseif (($i < (($nboflines * 2) - 1)) && ($i < ($nba - 1)))
5412
-                    $firstline .= ($ishtml ? "<br>\n" : "\n");
5678
+                if ($i % 2 == 0) {
5679
+                                    $firstline .= $a[$i];
5680
+                } elseif (($i < (($nboflines * 2) - 1)) && ($i < ($nba - 1))) {
5681
+                                    $firstline .= ($ishtml ? "<br>\n" : "\n");
5682
+                }
5413 5683
                 $i++;
5414 5684
             }
5415 5685
             unset($a);
@@ -5458,15 +5728,18 @@  discard block
 block discarded – undo
5458 5728
         $newstring = $stringtoencode;
5459 5729
         if (dol_textishtml($stringtoencode)) { // Check if text is already HTML or not
5460 5730
             $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.
5461
-            if ($removelasteolbr)
5462
-                $newstring = preg_replace('/<br>$/i', '', $newstring); // Remove last <br> (remove only last one)
5731
+            if ($removelasteolbr) {
5732
+                            $newstring = preg_replace('/<br>$/i', '', $newstring);
5733
+            }
5734
+            // Remove last <br> (remove only last one)
5463 5735
             $newstring = strtr($newstring, array('&' => '__and__', '<' => '__lt__', '>' => '__gt__', '"' => '__dquot__'));
5464 5736
             $newstring = dol_htmlentities($newstring, ENT_COMPAT, $pagecodefrom); // Make entity encoding
5465 5737
             $newstring = strtr($newstring, array('__and__' => '&', '__lt__' => '<', '__gt__' => '>', '__dquot__' => '"'));
5466
-        }
5467
-        else {
5468
-            if ($removelasteolbr)
5469
-                $newstring = preg_replace('/(\r\n|\r|\n)$/i', '', $newstring); // Remove last \n (may remove several)
5738
+        } else {
5739
+            if ($removelasteolbr) {
5740
+                            $newstring = preg_replace('/(\r\n|\r|\n)$/i', '', $newstring);
5741
+            }
5742
+            // Remove last \n (may remove several)
5470 5743
             $newstring = dol_nl2br(dol_htmlentities($newstring, ENT_COMPAT, $pagecodefrom), $nl2brmode);
5471 5744
         }
5472 5745
 // Other substitutions that htmlentities does not do
@@ -5568,8 +5841,9 @@  discard block
 block discarded – undo
5568 5841
      */
5569 5842
     static function dol_nboflines($s, $maxchar = 0)
5570 5843
     {
5571
-        if ($s == '')
5572
-            return 0;
5844
+        if ($s == '') {
5845
+                    return 0;
5846
+        }
5573 5847
         $arraystring = explode("\n", $s);
5574 5848
         $nb = count($arraystring);
5575 5849
 
@@ -5588,15 +5862,18 @@  discard block
 block discarded – undo
5588 5862
     static function dol_nboflines_bis($text, $maxlinesize = 0, $charset = 'UTF-8')
5589 5863
     {
5590 5864
         $repTable = array("\t" => " ", "\n" => "<br>", "\r" => " ", "\0" => " ", "\x0B" => " ");
5591
-        if (dol_textishtml($text))
5592
-            $repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
5865
+        if (dol_textishtml($text)) {
5866
+                    $repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
5867
+        }
5593 5868
 
5594 5869
         $text = strtr($text, $repTable);
5595 5870
         if ($charset == 'UTF-8') {
5596 5871
             $pattern = '/(<br[^>]*>)/Uu';
5597 5872
         } // /U is to have UNGREEDY regex to limit to one html tag. /u is for UTF8 support
5598
-        else
5599
-            $pattern = '/(<br[^>]*>)/U';       // /U is to have UNGREEDY regex to limit to one html tag.
5873
+        else {
5874
+                    $pattern = '/(<br[^>]*>)/U';
5875
+        }
5876
+        // /U is to have UNGREEDY regex to limit to one html tag.
5600 5877
         $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
5601 5878
 
5602 5879
         $nblines = (int) floor((count($a) + 1) / 2);
@@ -5643,39 +5920,47 @@  discard block
 block discarded – undo
5643 5920
     static function dol_textishtml($msg, $option = 0)
5644 5921
     {
5645 5922
         if ($option == 1) {
5646
-            if (preg_match('/<html/i', $msg))
5647
-                return true;
5648
-            elseif (preg_match('/<body/i', $msg))
5649
-                return true;
5650
-            elseif (preg_match('/<br/i', $msg))
5651
-                return true;
5923
+            if (preg_match('/<html/i', $msg)) {
5924
+                            return true;
5925
+            } elseif (preg_match('/<body/i', $msg)) {
5926
+                            return true;
5927
+            } elseif (preg_match('/<br/i', $msg)) {
5928
+                            return true;
5929
+            }
5652 5930
             return false;
5653
-        }
5654
-        else {
5655
-            if (preg_match('/<html/i', $msg))
5656
-                return true;
5657
-            elseif (preg_match('/<body/i', $msg))
5658
-                return true;
5659
-            elseif (preg_match('/<(b|em|i|u)>/i', $msg))
5660
-                return true;
5661
-            elseif (preg_match('/<br\/>/i', $msg))
5662
-                return true;
5663
-            elseif (preg_match('/<(br|div|font|li|p|span|strong|table)>/i', $msg))
5664
-                return true;
5665
-            elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*>/i', $msg))
5666
-                return true;
5667
-            elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*\/>/i', $msg))
5668
-                return true;
5669
-            elseif (preg_match('/<img\s+[^<>]*src[^<>]*>/i', $msg))
5670
-                return true; // must accept <img src="http://example.com/aaa.png" />
5671
-            elseif (preg_match('/<a\s+[^<>]*href[^<>]*>/i', $msg))
5672
-                return true; // must accept <a href="http://example.com/aaa.png" />
5673
-            elseif (preg_match('/<h[0-9]>/i', $msg))
5674
-                return true;
5675
-            elseif (preg_match('/&[A-Z0-9]{1,6};/i', $msg))
5676
-                return true;    // Html entities names (http://www.w3schools.com/tags/ref_entities.asp)
5677
-            elseif (preg_match('/&#[0-9]{2,3};/i', $msg))
5678
-                return true;    // Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp)
5931
+        } else {
5932
+            if (preg_match('/<html/i', $msg)) {
5933
+                            return true;
5934
+            } elseif (preg_match('/<body/i', $msg)) {
5935
+                            return true;
5936
+            } elseif (preg_match('/<(b|em|i|u)>/i', $msg)) {
5937
+                            return true;
5938
+            } elseif (preg_match('/<br\/>/i', $msg)) {
5939
+                            return true;
5940
+            } elseif (preg_match('/<(br|div|font|li|p|span|strong|table)>/i', $msg)) {
5941
+                            return true;
5942
+            } elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*>/i', $msg)) {
5943
+                            return true;
5944
+            } elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*\/>/i', $msg)) {
5945
+                            return true;
5946
+            } elseif (preg_match('/<img\s+[^<>]*src[^<>]*>/i', $msg)) {
5947
+                            return true;
5948
+            }
5949
+            // must accept <img src="http://example.com/aaa.png" />
5950
+            elseif (preg_match('/<a\s+[^<>]*href[^<>]*>/i', $msg)) {
5951
+                            return true;
5952
+            }
5953
+            // must accept <a href="http://example.com/aaa.png" />
5954
+            elseif (preg_match('/<h[0-9]>/i', $msg)) {
5955
+                            return true;
5956
+            } elseif (preg_match('/&[A-Z0-9]{1,6};/i', $msg)) {
5957
+                            return true;
5958
+            }
5959
+            // Html entities names (http://www.w3schools.com/tags/ref_entities.asp)
5960
+            elseif (preg_match('/&#[0-9]{2,3};/i', $msg)) {
5961
+                            return true;
5962
+            }
5963
+            // Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp)
5679 5964
 
5680 5965
             return false;
5681 5966
         }
@@ -5827,12 +6112,14 @@  discard block
 block discarded – undo
5827 6112
                 $birthday = dol_print_date($object->birth, 'day');
5828 6113
 
5829 6114
                 $substitutionarray['__MEMBER_ID__'] = $object->id;
5830
-                if (method_exists($object, 'getCivilityLabel'))
5831
-                    $substitutionarray['__MEMBER_CIVILITY__'] = $object->getCivilityLabel();
6115
+                if (method_exists($object, 'getCivilityLabel')) {
6116
+                                    $substitutionarray['__MEMBER_CIVILITY__'] = $object->getCivilityLabel();
6117
+                }
5832 6118
                 $substitutionarray['__MEMBER_FIRSTNAME__'] = $msgishtml ? dol_htmlentitiesbr($object->firstname) : $object->firstname;
5833 6119
                 $substitutionarray['__MEMBER_LASTNAME__'] = $msgishtml ? dol_htmlentitiesbr($object->lastname) : $object->lastname;
5834
-                if (method_exists($object, 'getFullName'))
5835
-                    $substitutionarray['__MEMBER_FULLNAME__'] = $msgishtml ? dol_htmlentitiesbr($object->getFullName($outputlangs)) : $object->getFullName($outputlangs);
6120
+                if (method_exists($object, 'getFullName')) {
6121
+                                    $substitutionarray['__MEMBER_FULLNAME__'] = $msgishtml ? dol_htmlentitiesbr($object->getFullName($outputlangs)) : $object->getFullName($outputlangs);
6122
+                }
5836 6123
                 $substitutionarray['__MEMBER_COMPANY__'] = $msgishtml ? dol_htmlentitiesbr($object->societe) : $object->societe;
5837 6124
                 $substitutionarray['__MEMBER_ADDRESS__'] = $msgishtml ? dol_htmlentitiesbr($object->address) : $object->address;
5838 6125
                 $substitutionarray['__MEMBER_ZIP__'] = $msgishtml ? dol_htmlentitiesbr($object->zip) : $object->zip;
@@ -5880,10 +6167,12 @@  discard block
 block discarded – undo
5880 6167
                     $dateplannedstart = '';
5881 6168
                     $datenextexpiration = '';
5882 6169
                     foreach ($object->lines as $line) {
5883
-                        if ($line->date_ouverture_prevue > $dateplannedstart)
5884
-                            $dateplannedstart = $line->date_ouverture_prevue;
5885
-                        if ($line->statut == 4 && $line->date_fin_prevue && (!$datenextexpiration || $line->date_fin_prevue < $datenextexpiration))
5886
-                            $datenextexpiration = $line->date_fin_prevue;
6170
+                        if ($line->date_ouverture_prevue > $dateplannedstart) {
6171
+                                                    $dateplannedstart = $line->date_ouverture_prevue;
6172
+                        }
6173
+                        if ($line->statut == 4 && $line->date_fin_prevue && (!$datenextexpiration || $line->date_fin_prevue < $datenextexpiration)) {
6174
+                                                    $datenextexpiration = $line->date_fin_prevue;
6175
+                        }
5887 6176
                     }
5888 6177
                     $substitutionarray['__CONTRACT_HIGHEST_PLANNED_START_DATE__'] = dol_print_date($dateplannedstart, 'dayrfc');
5889 6178
                     $substitutionarray['__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] = dol_print_date($dateplannedstart, 'standard');
@@ -5893,8 +6182,9 @@  discard block
 block discarded – undo
5893 6182
 
5894 6183
 // Create dynamic tags for __EXTRAFIELD_FIELD__
5895 6184
                 if ($object->table_element && $object->id > 0) {
5896
-                    if (!is_object($extrafields))
5897
-                        $extrafields = new ExtraFields($db);
6185
+                    if (!is_object($extrafields)) {
6186
+                                            $extrafields = new ExtraFields($db);
6187
+                    }
5898 6188
                     $extrafields->fetch_name_optionals_label($object->table_element, true);
5899 6189
 
5900 6190
                     if ($object->fetch_optionals() > 0) {
@@ -5915,12 +6205,15 @@  discard block
 block discarded – undo
5915 6205
                     require_once DOL_BASE_PATH . '/core/lib/payments.lib.php';
5916 6206
                     $outputlangs->loadLangs(array('paypal', 'other'));
5917 6207
                     $typeforonlinepayment = 'free';
5918
-                    if (is_object($object) && $object->element == 'commande')
5919
-                        $typeforonlinepayment = 'order';
5920
-                    if (is_object($object) && $object->element == 'facture')
5921
-                        $typeforonlinepayment = 'invoice';
5922
-                    if (is_object($object) && $object->element == 'member')
5923
-                        $typeforonlinepayment = 'member';
6208
+                    if (is_object($object) && $object->element == 'commande') {
6209
+                                            $typeforonlinepayment = 'order';
6210
+                    }
6211
+                    if (is_object($object) && $object->element == 'facture') {
6212
+                                            $typeforonlinepayment = 'invoice';
6213
+                    }
6214
+                    if (is_object($object) && $object->element == 'member') {
6215
+                                            $typeforonlinepayment = 'member';
6216
+                    }
5924 6217
                     $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $substitutionarray['__REF__']);
5925 6218
                     $paymenturl = $url;
5926 6219
                 }
@@ -5930,16 +6223,19 @@  discard block
 block discarded – undo
5930 6223
 
5931 6224
                 if (!empty(Globals::$conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD) && is_object($object) && $object->element == 'propal') {
5932 6225
                     $substitutionarray['__DIRECTDOWNLOAD_URL_PROPOSAL__'] = $object->getLastMainDocLink($object->element);
5933
-                } else
5934
-                    $substitutionarray['__DIRECTDOWNLOAD_URL_PROPOSAL__'] = '';
6226
+                } else {
6227
+                                    $substitutionarray['__DIRECTDOWNLOAD_URL_PROPOSAL__'] = '';
6228
+                }
5935 6229
                 if (!empty(Globals::$conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD) && is_object($object) && $object->element == 'commande') {
5936 6230
                     $substitutionarray['__DIRECTDOWNLOAD_URL_ORDER__'] = $object->getLastMainDocLink($object->element);
5937
-                } else
5938
-                    $substitutionarray['__DIRECTDOWNLOAD_URL_ORDER__'] = '';
6231
+                } else {
6232
+                                    $substitutionarray['__DIRECTDOWNLOAD_URL_ORDER__'] = '';
6233
+                }
5939 6234
                 if (!empty(Globals::$conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD) && is_object($object) && $object->element == 'facture') {
5940 6235
                     $substitutionarray['__DIRECTDOWNLOAD_URL_INVOICE__'] = $object->getLastMainDocLink($object->element);
5941
-                } else
5942
-                    $substitutionarray['__DIRECTDOWNLOAD_URL_INVOICE__'] = '';
6236
+                } else {
6237
+                                    $substitutionarray['__DIRECTDOWNLOAD_URL_INVOICE__'] = '';
6238
+                }
5943 6239
             }
5944 6240
         }
5945 6241
         if (empty($exclude) || !in_array('objectamount', $exclude)) {
@@ -5949,18 +6245,22 @@  discard block
 block discarded – undo
5949 6245
             $substitutionarray['__AMOUNT__'] = is_object($object) ? $object->total_ttc : '';
5950 6246
             $substitutionarray['__AMOUNT_EXCL_TAX__'] = is_object($object) ? $object->total_ht : '';
5951 6247
             $substitutionarray['__AMOUNT_VAT__'] = is_object($object) ? ($object->total_vat ? $object->total_vat : $object->total_tva) : '';
5952
-            if ($onlykey != 2 || $mysoc->useLocalTax(1))
5953
-                $substitutionarray['__AMOUNT_TAX2__'] = is_object($object) ? $object->total_localtax1 : '';
5954
-            if ($onlykey != 2 || $mysoc->useLocalTax(2))
5955
-                $substitutionarray['__AMOUNT_TAX3__'] = is_object($object) ? $object->total_localtax2 : '';
6248
+            if ($onlykey != 2 || $mysoc->useLocalTax(1)) {
6249
+                            $substitutionarray['__AMOUNT_TAX2__'] = is_object($object) ? $object->total_localtax1 : '';
6250
+            }
6251
+            if ($onlykey != 2 || $mysoc->useLocalTax(2)) {
6252
+                            $substitutionarray['__AMOUNT_TAX3__'] = is_object($object) ? $object->total_localtax2 : '';
6253
+            }
5956 6254
 
5957 6255
             $substitutionarray['__AMOUNT_FORMATED__'] = is_object($object) ? price($object->total_ttc, 0, $outputlangs, 0, 0, -1, Globals::$conf->currency) : '';
5958 6256
             $substitutionarray['__AMOUNT_EXCL_TAX_FORMATED__'] = is_object($object) ? price($object->total_ht, 0, $outputlangs, 0, 0, -1, Globals::$conf->currency) : '';
5959 6257
             $substitutionarray['__AMOUNT_VAT_FORMATED__'] = is_object($object) ? ($object->total_vat ? price($object->total_vat, 0, $outputlangs, 0, 0, -1, Globals::$conf->currency) : price($object->total_tva, 0, $outputlangs, 0, 0, -1, Globals::$conf->currency)) : '';
5960
-            if ($onlykey != 2 || $mysoc->useLocalTax(1))
5961
-                $substitutionarray['__AMOUNT_TAX2_FORMATED__'] = is_object($object) ? price($object->total_localtax1, 0, $outputlangs, 0, 0, -1, Globals::$conf->currency) : '';
5962
-            if ($onlykey != 2 || $mysoc->useLocalTax(2))
5963
-                $substitutionarray['__AMOUNT_TAX3_FORMATED__'] = is_object($object) ? price($object->total_localtax2, 0, $outputlangs, 0, 0, -1, Globals::$conf->currency) : '';
6258
+            if ($onlykey != 2 || $mysoc->useLocalTax(1)) {
6259
+                            $substitutionarray['__AMOUNT_TAX2_FORMATED__'] = is_object($object) ? price($object->total_localtax1, 0, $outputlangs, 0, 0, -1, Globals::$conf->currency) : '';
6260
+            }
6261
+            if ($onlykey != 2 || $mysoc->useLocalTax(2)) {
6262
+                            $substitutionarray['__AMOUNT_TAX3_FORMATED__'] = is_object($object) ? price($object->total_localtax2, 0, $outputlangs, 0, 0, -1, Globals::$conf->currency) : '';
6263
+            }
5964 6264
 
5965 6265
 // TODO Add keys for foreign multicurrency
5966 6266
 // For backward compatibility
@@ -6030,23 +6330,27 @@  discard block
 block discarded – undo
6030 6330
     {
6031 6331
        // global Globals::$conf, $langs;
6032 6332
 
6033
-        if (!is_array($substitutionarray))
6034
-            return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
6333
+        if (!is_array($substitutionarray)) {
6334
+                    return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
6335
+        }
6035 6336
 
6036
-        if (empty($outputlangs))
6037
-            $outputlangs = Globals::$langs;
6337
+        if (empty($outputlangs)) {
6338
+                    $outputlangs = Globals::$langs;
6339
+        }
6038 6340
 
6039 6341
 // Make substitution for language keys
6040 6342
         if (is_object($outputlangs)) {
6041 6343
             while (preg_match('/__\(([^\)]+)\)__/', $text, $reg)) {
6042 6344
                 $msgishtml = 0;
6043
-                if (DolUtils::dol_textishtml($text, 1))
6044
-                    $msgishtml = 1;
6345
+                if (DolUtils::dol_textishtml($text, 1)) {
6346
+                                    $msgishtml = 1;
6347
+                }
6045 6348
 
6046 6349
 // If key is __(TranslationKey|langfile)__, then force load of langfile.lang
6047 6350
                 $tmp = explode('|', $reg[1]);
6048
-                if (!empty($tmp[1]))
6049
-                    $outputlangs->load($tmp[1]);
6351
+                if (!empty($tmp[1])) {
6352
+                                    $outputlangs->load($tmp[1]);
6353
+                }
6050 6354
 
6051 6355
                 $text = preg_replace('/__\(' . preg_quote($reg[1], '/') . '\)__/', $msgishtml ? dol_htmlentitiesbr($outputlangs->transnoentitiesnoconv($reg[1])) : $outputlangs->transnoentitiesnoconv($reg[1]), $text);
6052 6356
             }
@@ -6056,23 +6360,29 @@  discard block
 block discarded – undo
6056 6360
 // it is also converted.
6057 6361
         while (preg_match('/__\[([^\]]+)\]__/', $text, $reg)) {
6058 6362
             $msgishtml = 0;
6059
-            if (DolUtils::dol_textishtml($text, 1))
6060
-                $msgishtml = 1;
6363
+            if (DolUtils::dol_textishtml($text, 1)) {
6364
+                            $msgishtml = 1;
6365
+            }
6061 6366
 
6062 6367
             $keyfound = $reg[1];
6063
-            if (preg_match('/(_pass|password|secret|_key|key$)/i', $keyfound))
6064
-                $newval = '*****forbidden*****';
6065
-            else
6066
-                $newval = empty(Globals::$conf->global->$keyfound) ? '' : Globals::$conf->global->$keyfound;
6368
+            if (preg_match('/(_pass|password|secret|_key|key$)/i', $keyfound)) {
6369
+                            $newval = '*****forbidden*****';
6370
+            } else {
6371
+                            $newval = empty(Globals::$conf->global->$keyfound) ? '' : Globals::$conf->global->$keyfound;
6372
+            }
6067 6373
             $text = preg_replace('/__\[' . preg_quote($keyfound, '/') . '\]__/', $msgishtml ? dol_htmlentitiesbr($newval) : $newval, $text);
6068 6374
         }
6069 6375
 
6070 6376
 // Make substitition for array $substitutionarray
6071 6377
         foreach ($substitutionarray as $key => $value) {
6072
-            if ($key == '__SIGNATURE__' && (!empty(Globals::$conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)))
6073
-                $value = '';  // Protection
6074
-            if ($key == '__USER_SIGNATURE__' && (!empty(Globals::$conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)))
6075
-                $value = ''; // Protection
6378
+            if ($key == '__SIGNATURE__' && (!empty(Globals::$conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) {
6379
+                            $value = '';
6380
+            }
6381
+            // Protection
6382
+            if ($key == '__USER_SIGNATURE__' && (!empty(Globals::$conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) {
6383
+                            $value = '';
6384
+            }
6385
+            // Protection
6076 6386
 
6077 6387
             $text = str_replace("$key", "$value", $text); // We must keep the " to work when value is 123.5 for example
6078 6388
         }
@@ -6118,8 +6428,9 @@  discard block
 block discarded – undo
6118 6428
             $dir = dol_buildpath($reldir, 0);
6119 6429
 
6120 6430
 // Check if directory exists
6121
-            if (!dol_is_dir($dir))
6122
-                continue;
6431
+            if (!dol_is_dir($dir)) {
6432
+                            continue;
6433
+            }
6123 6434
 
6124 6435
             $substitfiles = dol_dir_list($dir, 'files', 0, 'functions_');
6125 6436
             foreach ($substitfiles as $substitfile) {
@@ -6131,8 +6442,9 @@  discard block
 block discarded – undo
6131 6442
                     require_once $dir . $substitfile['name'];
6132 6443
                     // Call the user's function, and only if it is defined
6133 6444
                     $function_name = $module . "_" . $callfunc;
6134
-                    if (function_exists($function_name))
6135
-                        $function_name($substitutionarray, $outputlangs, $object, $parameters);
6445
+                    if (function_exists($function_name)) {
6446
+                                            $function_name($substitutionarray, $outputlangs, $object, $parameters);
6447
+                    }
6136 6448
                 }
6137 6449
             }
6138 6450
         }
@@ -6168,8 +6480,9 @@  discard block
 block discarded – undo
6168 6480
 
6169 6481
         $out = '';
6170 6482
 
6171
-        if (!is_object($outputlangs))
6172
-            $outputlangs = $langs;
6483
+        if (!is_object($outputlangs)) {
6484
+                    $outputlangs = $langs;
6485
+        }
6173 6486
 
6174 6487
         if ($date_start && $date_end) {
6175 6488
             $out .= ($withparenthesis ? ' (' : '') . $outputlangs->transnoentitiesnoconv('DateFromTo', dol_print_date($date_start, $format, false, $outputlangs), dol_print_date($date_end, $format, false, $outputlangs)) . ($withparenthesis ? ')' : '');
@@ -6198,20 +6511,22 @@  discard block
 block discarded – undo
6198 6511
 
6199 6512
         $ret = '';
6200 6513
 // If order not defined, we use the setup
6201
-        if ($nameorder < 0)
6202
-            $nameorder = (empty(Globals::$conf->global->MAIN_FIRSTNAME_NAME_POSITION) ? 1 : 0);
6514
+        if ($nameorder < 0) {
6515
+                    $nameorder = (empty(Globals::$conf->global->MAIN_FIRSTNAME_NAME_POSITION) ? 1 : 0);
6516
+        }
6203 6517
         if ($nameorder && ((string) $nameorder != '2')) {
6204 6518
             $ret .= $firstname;
6205
-            if ($firstname && $lastname)
6206
-                $ret .= ' ';
6519
+            if ($firstname && $lastname) {
6520
+                            $ret .= ' ';
6521
+            }
6207 6522
             $ret .= $lastname;
6208
-        }
6209
-        else if ($nameorder == 2) {
6523
+        } else if ($nameorder == 2) {
6210 6524
             $ret .= $firstname;
6211 6525
         } else {
6212 6526
             $ret .= $lastname;
6213
-            if ($firstname && $lastname)
6214
-                $ret .= ' ';
6527
+            if ($firstname && $lastname) {
6528
+                            $ret .= ' ';
6529
+            }
6215 6530
             $ret .= $firstname;
6216 6531
         }
6217 6532
         return $ret;
@@ -6231,13 +6546,14 @@  discard block
 block discarded – undo
6231 6546
     {
6232 6547
 //dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);		This is not deprecated, it is used by setEventMessages function
6233 6548
         if (!is_array($mesgs)) {  // If mesgs is a string
6234
-            if ($mesgs)
6235
-                $_SESSION['dol_events'][$style][] = $mesgs;
6236
-        }
6237
-        else {      // If mesgs is an array
6549
+            if ($mesgs) {
6550
+                            $_SESSION['dol_events'][$style][] = $mesgs;
6551
+            }
6552
+        } else {      // If mesgs is an array
6238 6553
             foreach ($mesgs as $mesg) {
6239
-                if ($mesg)
6240
-                    $_SESSION['dol_events'][$style][] = $mesg;
6554
+                if ($mesg) {
6555
+                                    $_SESSION['dol_events'][$style][] = $mesg;
6556
+                }
6241 6557
             }
6242 6558
         }
6243 6559
     }
@@ -6257,13 +6573,16 @@  discard block
 block discarded – undo
6257 6573
         if (empty($mesg) && empty($mesgs)) {
6258 6574
             dol_syslog("Try to add a message in stack with empty message", LOG_WARNING);
6259 6575
         } else {
6260
-            if (!in_array((string) $style, array('mesgs', 'warnings', 'errors')))
6261
-                dol_print_error('', 'Bad parameter style=' . $style . ' for setEventMessages');
6262
-            if (empty($mesgs))
6263
-                setEventMessage($mesg, $style);
6264
-            else {
6265
-                if (!empty($mesg) && !in_array($mesg, $mesgs))
6266
-                    setEventMessage($mesg, $style); // Add message string if not already into array
6576
+            if (!in_array((string) $style, array('mesgs', 'warnings', 'errors'))) {
6577
+                            dol_print_error('', 'Bad parameter style=' . $style . ' for setEventMessages');
6578
+            }
6579
+            if (empty($mesgs)) {
6580
+                            setEventMessage($mesg, $style);
6581
+            } else {
6582
+                if (!empty($mesg) && !in_array($mesg, $mesgs)) {
6583
+                                    setEventMessage($mesg, $style);
6584
+                }
6585
+                // Add message string if not already into array
6267 6586
                 setEventMessage($mesgs, $style);
6268 6587
             }
6269 6588
         }
@@ -6282,22 +6601,25 @@  discard block
 block discarded – undo
6282 6601
     {
6283 6602
 // Show mesgs
6284 6603
         if (isset($_SESSION['dol_events']['mesgs'])) {
6285
-            if (empty($disabledoutputofmessages))
6286
-                dol_htmloutput_mesg('', $_SESSION['dol_events']['mesgs']);
6604
+            if (empty($disabledoutputofmessages)) {
6605
+                            dol_htmloutput_mesg('', $_SESSION['dol_events']['mesgs']);
6606
+            }
6287 6607
             unset($_SESSION['dol_events']['mesgs']);
6288 6608
         }
6289 6609
 
6290 6610
 // Show errors
6291 6611
         if (isset($_SESSION['dol_events']['errors'])) {
6292
-            if (empty($disabledoutputofmessages))
6293
-                dol_htmloutput_mesg('', $_SESSION['dol_events']['errors'], 'error');
6612
+            if (empty($disabledoutputofmessages)) {
6613
+                            dol_htmloutput_mesg('', $_SESSION['dol_events']['errors'], 'error');
6614
+            }
6294 6615
             unset($_SESSION['dol_events']['errors']);
6295 6616
         }
6296 6617
 
6297 6618
 // Show warnings
6298 6619
         if (isset($_SESSION['dol_events']['warnings'])) {
6299
-            if (empty($disabledoutputofmessages))
6300
-                dol_htmloutput_mesg('', $_SESSION['dol_events']['warnings'], 'warning');
6620
+            if (empty($disabledoutputofmessages)) {
6621
+                            dol_htmloutput_mesg('', $_SESSION['dol_events']['warnings'], 'warning');
6622
+            }
6301 6623
             unset($_SESSION['dol_events']['warnings']);
6302 6624
         }
6303 6625
     }
@@ -6338,8 +6660,9 @@  discard block
 block discarded – undo
6338 6660
                 foreach ($mesgarray as $message) {
6339 6661
                     $ret++;
6340 6662
                     $out .= $langs->trans($message);
6341
-                    if ($ret < count($mesgarray))
6342
-                        $out .= "<br>\n";
6663
+                    if ($ret < count($mesgarray)) {
6664
+                                            $out .= "<br>\n";
6665
+                    }
6343 6666
                 }
6344 6667
             }
6345 6668
             if ($mesgstring) {
@@ -6405,8 +6728,9 @@  discard block
 block discarded – undo
6405 6728
      */
6406 6729
     static function dol_htmloutput_mesg($mesgstring = '', $mesgarray = array(), $style = 'ok', $keepembedded = 0)
6407 6730
     {
6408
-        if (empty($mesgstring) && (!is_array($mesgarray) || count($mesgarray) == 0))
6409
-            return;
6731
+        if (empty($mesgstring) && (!is_array($mesgarray) || count($mesgarray) == 0)) {
6732
+                    return;
6733
+        }
6410 6734
 
6411 6735
         $iserror = 0;
6412 6736
         $iswarning = 0;
@@ -6421,14 +6745,17 @@  discard block
 block discarded – undo
6421 6745
                     break;
6422 6746
                 }
6423 6747
             }
6424
-        } else if ($mesgstring && preg_match('/class="error"/i', $mesgstring))
6425
-            $iserror++;
6426
-        else if ($mesgstring && preg_match('/class="warning"/i', $mesgstring))
6427
-            $iswarning++;
6428
-        if ($style == 'error')
6429
-            $iserror++;
6430
-        if ($style == 'warning')
6431
-            $iswarning++;
6748
+        } else if ($mesgstring && preg_match('/class="error"/i', $mesgstring)) {
6749
+                    $iserror++;
6750
+        } else if ($mesgstring && preg_match('/class="warning"/i', $mesgstring)) {
6751
+                    $iswarning++;
6752
+        }
6753
+        if ($style == 'error') {
6754
+                    $iserror++;
6755
+        }
6756
+        if ($style == 'warning') {
6757
+                    $iswarning++;
6758
+        }
6432 6759
 
6433 6760
         if ($iserror || $iswarning) {
6434 6761
 // Remove div from texts
@@ -6447,8 +6774,9 @@  discard block
 block discarded – undo
6447 6774
                 $mesgarray = $newmesgarray;
6448 6775
             }
6449 6776
             print get_htmloutput_mesg($mesgstring, $mesgarray, ($iserror ? 'error' : 'warning'), $keepembedded);
6450
-        } else
6451
-            print get_htmloutput_mesg($mesgstring, $mesgarray, 'ok', $keepembedded);
6777
+        } else {
6778
+                    print get_htmloutput_mesg($mesgstring, $mesgarray, 'ok', $keepembedded);
6779
+        }
6452 6780
     }
6453 6781
 
6454 6782
     /**
@@ -6489,15 +6817,17 @@  discard block
 block discarded – undo
6489 6817
             $sizearray = count($array);
6490 6818
             if ($sizearray > 0) {
6491 6819
                 $temp = array();
6492
-                foreach (array_keys($array) as $key)
6493
-                    $temp[$key] = $array[$key][$index];
6820
+                foreach (array_keys($array) as $key) {
6821
+                                    $temp[$key] = $array[$key][$index];
6822
+                }
6494 6823
 
6495
-                if (!$natsort)
6496
-                    ($order == 'asc') ? asort($temp) : arsort($temp);
6497
-                else {
6824
+                if (!$natsort) {
6825
+                                    ($order == 'asc') ? asort($temp) : arsort($temp);
6826
+                } else {
6498 6827
                     ($case_sensitive) ? natsort($temp) : natcasesort($temp);
6499
-                    if ($order != 'asc')
6500
-                        $temp = array_reverse($temp, true);
6828
+                    if ($order != 'asc') {
6829
+                                            $temp = array_reverse($temp, true);
6830
+                    }
6501 6831
                 }
6502 6832
 
6503 6833
                 $sorted = array();
@@ -6523,23 +6853,38 @@  discard block
 block discarded – undo
6523 6853
 // We must use here a binary strlen static function (so not dol_strlen)
6524 6854
         $strLength = dol_strlen($str);
6525 6855
         for ($i = 0; $i < $strLength; $i++) {
6526
-            if (ord($str[$i]) < 0x80)
6527
-                continue; // 0bbbbbbb
6528
-            elseif ((ord($str[$i]) & 0xE0) == 0xC0)
6529
-                $n = 1; // 110bbbbb
6530
-            elseif ((ord($str[$i]) & 0xF0) == 0xE0)
6531
-                $n = 2; // 1110bbbb
6532
-            elseif ((ord($str[$i]) & 0xF8) == 0xF0)
6533
-                $n = 3; // 11110bbb
6534
-            elseif ((ord($str[$i]) & 0xFC) == 0xF8)
6535
-                $n = 4; // 111110bb
6536
-            elseif ((ord($str[$i]) & 0xFE) == 0xFC)
6537
-                $n = 5; // 1111110b
6538
-            else
6539
-                return false; // Does not match any model
6856
+            if (ord($str[$i]) < 0x80) {
6857
+                            continue;
6858
+            }
6859
+            // 0bbbbbbb
6860
+            elseif ((ord($str[$i]) & 0xE0) == 0xC0) {
6861
+                            $n = 1;
6862
+            }
6863
+            // 110bbbbb
6864
+            elseif ((ord($str[$i]) & 0xF0) == 0xE0) {
6865
+                            $n = 2;
6866
+            }
6867
+            // 1110bbbb
6868
+            elseif ((ord($str[$i]) & 0xF8) == 0xF0) {
6869
+                            $n = 3;
6870
+            }
6871
+            // 11110bbb
6872
+            elseif ((ord($str[$i]) & 0xFC) == 0xF8) {
6873
+                            $n = 4;
6874
+            }
6875
+            // 111110bb
6876
+            elseif ((ord($str[$i]) & 0xFE) == 0xFC) {
6877
+                            $n = 5;
6878
+            }
6879
+            // 1111110b
6880
+            else {
6881
+                            return false;
6882
+            }
6883
+            // Does not match any model
6540 6884
             for ($j = 0; $j < $n; $j++) { // n bytes matching 10bbbbbb follow ?
6541
-                if (( ++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80))
6542
-                    return false;
6885
+                if (( ++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80)) {
6886
+                                    return false;
6887
+                }
6543 6888
             }
6544 6889
         }
6545 6890
         return true;
@@ -6557,15 +6902,21 @@  discard block
 block discarded – undo
6557 6902
        // global Globals::$conf;
6558 6903
 
6559 6904
         $tmp = ini_get("unicode.filesystem_encoding");      // Disponible avec PHP 6.0
6560
-        if (empty($tmp) && !empty($_SERVER["WINDIR"]))
6561
-            $tmp = 'iso-8859-1'; // By default for windows
6562
-        if (empty($tmp))
6563
-            $tmp = 'utf-8';          // By default for other
6564
-        if (!empty(Globals::$conf->global->MAIN_FILESYSTEM_ENCODING))
6565
-            $tmp = Globals::$conf->global->MAIN_FILESYSTEM_ENCODING;
6566
-
6567
-        if ($tmp == 'iso-8859-1')
6568
-            return utf8_decode($str);
6905
+        if (empty($tmp) && !empty($_SERVER["WINDIR"])) {
6906
+                    $tmp = 'iso-8859-1';
6907
+        }
6908
+        // By default for windows
6909
+        if (empty($tmp)) {
6910
+                    $tmp = 'utf-8';
6911
+        }
6912
+        // By default for other
6913
+        if (!empty(Globals::$conf->global->MAIN_FILESYSTEM_ENCODING)) {
6914
+                    $tmp = Globals::$conf->global->MAIN_FILESYSTEM_ENCODING;
6915
+        }
6916
+
6917
+        if ($tmp == 'iso-8859-1') {
6918
+                    return utf8_decode($str);
6919
+        }
6569 6920
         return $str;
6570 6921
     }
6571 6922
 
@@ -6586,8 +6937,9 @@  discard block
 block discarded – undo
6586 6937
     {
6587 6938
        // global $cache_codes;
6588 6939
 // If key empty
6589
-        if ($key == '')
6590
-            return '';
6940
+        if ($key == '') {
6941
+                    return '';
6942
+        }
6591 6943
 
6592 6944
 // Check in cache
6593 6945
         if (isset($cache_codes[$tablename][$key][$fieldid])) { // Can be defined to 0 or ''
@@ -6599,20 +6951,21 @@  discard block
 block discarded – undo
6599 6951
         $sql = "SELECT " . $fieldid . " as valuetoget";
6600 6952
         $sql .= " FROM " . MAIN_DB_PREFIX . $tablename;
6601 6953
         $sql .= " WHERE " . $fieldkey . " = '" . $db->escape($key) . "'";
6602
-        if (!empty($entityfilter))
6603
-            $sql .= " AND entity IN (" . getEntity($tablename) . ")";
6954
+        if (!empty($entityfilter)) {
6955
+                    $sql .= " AND entity IN (" . getEntity($tablename) . ")";
6956
+        }
6604 6957
 
6605 6958
         $resql = $db->query($sql);
6606 6959
         if ($resql) {
6607 6960
             $obj = $db->fetch_object($resql);
6608
-            if ($obj)
6609
-                $cache_codes[$tablename][$key][$fieldid] = $obj->valuetoget;
6610
-            else
6611
-                $cache_codes[$tablename][$key][$fieldid] = '';
6961
+            if ($obj) {
6962
+                            $cache_codes[$tablename][$key][$fieldid] = $obj->valuetoget;
6963
+            } else {
6964
+                            $cache_codes[$tablename][$key][$fieldid] = '';
6965
+            }
6612 6966
             $db->free($resql);
6613 6967
             return $cache_codes[$tablename][$key][$fieldid];
6614
-        }
6615
-        else {
6968
+        } else {
6616 6969
             return -1;
6617 6970
         }
6618 6971
     }
@@ -6658,16 +7011,17 @@  discard block
 block discarded – undo
6658 7011
         // global $soc;       // For backward compatibility
6659 7012
 //print $s."<br>\n";
6660 7013
         if ($returnvalue) {
6661
-            if ($hideerrors)
6662
-                return @eval('return ' . $s . ';');
6663
-            else
6664
-                return eval('return ' . $s . ';');
6665
-        }
6666
-        else {
6667
-            if ($hideerrors)
6668
-                @eval($s);
6669
-            else
6670
-                eval($s);
7014
+            if ($hideerrors) {
7015
+                            return @eval('return ' . $s . ';');
7016
+            } else {
7017
+                            return eval('return ' . $s . ';');
7018
+            }
7019
+        } else {
7020
+            if ($hideerrors) {
7021
+                            @eval($s);
7022
+            } else {
7023
+                            eval($s);
7024
+            }
6671 7025
         }
6672 7026
     }
6673 7027
 
@@ -6693,8 +7047,9 @@  discard block
 block discarded – undo
6693 7047
     {
6694 7048
        // global $langs;
6695 7049
 
6696
-        if (empty($codelang))
6697
-            return '';
7050
+        if (empty($codelang)) {
7051
+                    return '';
7052
+        }
6698 7053
 
6699 7054
         if ($codelang == 'auto') {
6700 7055
             return '<span class="fa fa-globe"></span>';
@@ -6708,9 +7063,9 @@  discard block
 block discarded – undo
6708 7063
             'sv_SV' => 'se'
6709 7064
         );
6710 7065
 
6711
-        if (isset($langtocountryflag[$codelang]))
6712
-            $flagImage = $langtocountryflag[$codelang];
6713
-        else {
7066
+        if (isset($langtocountryflag[$codelang])) {
7067
+                    $flagImage = $langtocountryflag[$codelang];
7068
+        } else {
6714 7069
             $tmparray = explode('_', $codelang);
6715 7070
             $flagImage = empty($tmparray[1]) ? $tmparray[0] : $tmparray[1];
6716 7071
         }
@@ -6728,15 +7083,20 @@  discard block
 block discarded – undo
6728 7083
     {
6729 7084
        // global $mysoc;
6730 7085
 
6731
-        if (strtoupper($countrycode) == 'MQ')
6732
-            return 'fr_CA';
6733
-        if (strtoupper($countrycode) == 'SE')
6734
-            return 'sv_SE'; // se_SE is Sami/Sweden, and we want in priority sv_SE for SE country
7086
+        if (strtoupper($countrycode) == 'MQ') {
7087
+                    return 'fr_CA';
7088
+        }
7089
+        if (strtoupper($countrycode) == 'SE') {
7090
+                    return 'sv_SE';
7091
+        }
7092
+        // se_SE is Sami/Sweden, and we want in priority sv_SE for SE country
6735 7093
         if (strtoupper($countrycode) == 'CH') {
6736
-            if ($mysoc->country_code == 'FR')
6737
-                return 'fr_CH';
6738
-            if ($mysoc->country_code == 'DE')
6739
-                return 'de_CH';
7094
+            if ($mysoc->country_code == 'FR') {
7095
+                            return 'fr_CH';
7096
+            }
7097
+            if ($mysoc->country_code == 'DE') {
7098
+                            return 'de_CH';
7099
+            }
6740 7100
         }
6741 7101
 
6742 7102
 // Locale list taken from:
@@ -6914,8 +7274,9 @@  discard block
 block discarded – undo
6914 7274
         );
6915 7275
 
6916 7276
         $buildprimarykeytotest = strtolower($countrycode) . '-' . strtoupper($countrycode);
6917
-        if (in_array($buildprimarykeytotest, $locales))
6918
-            return strtolower($countrycode) . '_' . strtoupper($countrycode);
7277
+        if (in_array($buildprimarykeytotest, $locales)) {
7278
+                    return strtolower($countrycode) . '_' . strtoupper($countrycode);
7279
+        }
6919 7280
 
6920 7281
         foreach ($locales as $locale) {
6921 7282
             $locale_language = locale_get_primary_language($locale);
@@ -6969,18 +7330,21 @@  discard block
 block discarded – undo
6969 7330
 
6970 7331
                 if ($mode == 'add' && !preg_match('/^\-/', $values[1])) {
6971 7332
                     if (count($values) == 6) {       // new declaration with permissions:  $value='objecttype:+tabname1:Title1:langfile@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__'
6972
-                        if ($values[0] != $type)
6973
-                            continue;
7333
+                        if ($values[0] != $type) {
7334
+                                                    continue;
7335
+                        }
6974 7336
 
6975 7337
                         if (verifCond($values[4])) {
6976
-                            if ($values[3])
6977
-                                $langs->load($values[3]);
7338
+                            if ($values[3]) {
7339
+                                                            $langs->load($values[3]);
7340
+                            }
6978 7341
                             if (preg_match('/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
6979 7342
                                 $substitutionarray = array();
6980 7343
                                 complete_substitutions_array($substitutionarray, $langs, $object, array('needforkey' => $values[2]));
6981 7344
                                 $label = make_substitutions($reg[1], $substitutionarray);
6982
-                            } else
6983
-                                $label = $langs->trans($values[2]);
7345
+                            } else {
7346
+                                                            $label = $langs->trans($values[2]);
7347
+                            }
6984 7348
 
6985 7349
                             //$head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[5]), 1);
6986 7350
                             $head[$h][0] = BASE_URI . preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[5]);
@@ -6988,30 +7352,32 @@  discard block
 block discarded – undo
6988 7352
                             $head[$h][2] = str_replace('+', '', $values[1]);
6989 7353
                             $h++;
6990 7354
                         }
6991
-                    }
6992
-                    else if (count($values) == 5) {       // deprecated
7355
+                    } else if (count($values) == 5) {       // deprecated
6993 7356
                         dol_syslog('Passing 5 values in tabs module_parts is deprecated. Please update to 6 with permissions.', LOG_WARNING);
6994 7357
 
6995
-                        if ($values[0] != $type)
6996
-                            continue;
6997
-                        if ($values[3])
6998
-                            $langs->load($values[3]);
7358
+                        if ($values[0] != $type) {
7359
+                                                    continue;
7360
+                        }
7361
+                        if ($values[3]) {
7362
+                                                    $langs->load($values[3]);
7363
+                        }
6999 7364
                         if (preg_match('/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
7000 7365
                             $substitutionarray = array();
7001 7366
                             complete_substitutions_array($substitutionarray, $langs, $object, array('needforkey' => $values[2]));
7002 7367
                             $label = make_substitutions($reg[1], $substitutionarray);
7003
-                        } else
7004
-                            $label = $langs->trans($values[2]);
7368
+                        } else {
7369
+                                                    $label = $langs->trans($values[2]);
7370
+                        }
7005 7371
 
7006 7372
                         $head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[4]), 1);
7007 7373
                         $head[$h][1] = $label;
7008 7374
                         $head[$h][2] = str_replace('+', '', $values[1]);
7009 7375
                         $h++;
7010 7376
                     }
7011
-                }
7012
-                else if ($mode == 'remove' && preg_match('/^\-/', $values[1])) {
7013
-                    if ($values[0] != $type)
7014
-                        continue;
7377
+                } else if ($mode == 'remove' && preg_match('/^\-/', $values[1])) {
7378
+                    if ($values[0] != $type) {
7379
+                                            continue;
7380
+                    }
7015 7381
                     $tabname = str_replace('-', '', $values[1]);
7016 7382
                     foreach ($head as $key => $val) {
7017 7383
                         $condition = (!empty($values[3]) ? verifCond($values[3]) : 1);
@@ -7053,10 +7419,11 @@  discard block
 block discarded – undo
7053 7419
         // global $action;
7054 7420
         // global $micro_start_time;
7055 7421
 
7056
-        if ($zone == 'private')
7057
-            print "\n" . '<!-- Common footer for private page -->' . "\n";
7058
-        else
7059
-            print "\n" . '<!-- Common footer for public page -->' . "\n";
7422
+        if ($zone == 'private') {
7423
+                    print "\n" . '<!-- Common footer for private page -->' . "\n";
7424
+        } else {
7425
+                    print "\n" . '<!-- Common footer for public page -->' . "\n";
7426
+        }
7060 7427
 
7061 7428
 // A div to store page_y POST parameter so we can read it using javascript
7062 7429
         print "\n<!-- A div to store page_y POST paramater -->\n";
@@ -7065,8 +7432,9 @@  discard block
 block discarded – undo
7065 7432
         $parameters = array();
7066 7433
         $reshook = $hookmanager->executeHooks('printCommonFooter', $parameters);    // Note that $action and $object may have been modified by some hooks
7067 7434
         if (empty($reshook)) {
7068
-            if (!empty(Globals::$conf->global->MAIN_HTML_FOOTER))
7069
-                print Globals::$conf->global->MAIN_HTML_FOOTER . "\n";
7435
+            if (!empty(Globals::$conf->global->MAIN_HTML_FOOTER)) {
7436
+                            print Globals::$conf->global->MAIN_HTML_FOOTER . "\n";
7437
+            }
7070 7438
 
7071 7439
             print "\n";
7072 7440
             if (!empty(Globals::$conf->use_javascript_ajax)) {
@@ -7089,8 +7457,9 @@  discard block
 block discarded – undo
7089 7457
                     print '/* JS CODE TO ENABLE to manage focus and mandatory form fields */' . "\n";
7090 7458
                     $relativepathstring = $_SERVER["PHP_SELF"];
7091 7459
                     // Clean $relativepathstring
7092
-                    if (constant('DOL_BASE_URI'))
7093
-                        $relativepathstring = preg_replace('/^' . preg_quote(constant('DOL_BASE_URI'), '/') . '/', '', $relativepathstring);
7460
+                    if (constant('DOL_BASE_URI')) {
7461
+                                            $relativepathstring = preg_replace('/^' . preg_quote(constant('DOL_BASE_URI'), '/') . '/', '', $relativepathstring);
7462
+                    }
7094 7463
                     $relativepathstring = preg_replace('/^\//', '', $relativepathstring);
7095 7464
                     $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring);
7096 7465
                     $tmpqueryarraywehave = explode('&', dol_string_nohtmltag($_SERVER['QUERY_STRING']));
@@ -7101,14 +7470,17 @@  discard block
 block discarded – undo
7101 7470
                                 $tmpqueryarraytohave = explode('&', $defkey);
7102 7471
                                 $foundintru = 0;
7103 7472
                                 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
7104
-                                    if (!in_array($tmpquerytohave, $tmpqueryarraywehave))
7105
-                                        $foundintru = 1;
7473
+                                    if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
7474
+                                                                            $foundintru = 1;
7475
+                                    }
7106 7476
                                 }
7107
-                                if (!$foundintru)
7108
-                                    $qualified = 1;
7477
+                                if (!$foundintru) {
7478
+                                                                    $qualified = 1;
7479
+                                }
7109 7480
                                 //var_dump($defkey.'-'.$qualified);
7110
-                            } else
7111
-                                $qualified = 1;
7481
+                            } else {
7482
+                                                            $qualified = 1;
7483
+                            }
7112 7484
 
7113 7485
                             if ($qualified) {
7114 7486
                                 foreach ($defval as $paramkey => $paramval) {
@@ -7127,14 +7499,17 @@  discard block
 block discarded – undo
7127 7499
                                 $tmpqueryarraytohave = explode('&', $defkey);
7128 7500
                                 $foundintru = 0;
7129 7501
                                 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
7130
-                                    if (!in_array($tmpquerytohave, $tmpqueryarraywehave))
7131
-                                        $foundintru = 1;
7502
+                                    if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
7503
+                                                                            $foundintru = 1;
7504
+                                    }
7132 7505
                                 }
7133
-                                if (!$foundintru)
7134
-                                    $qualified = 1;
7506
+                                if (!$foundintru) {
7507
+                                                                    $qualified = 1;
7508
+                                }
7135 7509
                                 //var_dump($defkey.'-'.$qualified);
7136
-                            } else
7137
-                                $qualified = 1;
7510
+                            } else {
7511
+                                                            $qualified = 1;
7512
+                            }
7138 7513
 
7139 7514
                             if ($qualified) {
7140 7515
                                 foreach ($defval as $paramkey => $paramval) {
@@ -7173,8 +7548,9 @@  discard block
 block discarded – undo
7173 7548
                     print "\n";
7174 7549
                     print "/* JS CODE TO ENABLE to add memory info */\n";
7175 7550
                     print 'window.console && console.log("';
7176
-                    if (!empty(Globals::$conf->global->MEMCACHED_SERVER))
7177
-                        print 'MEMCACHED_SERVER=' . Globals::$conf->global->MEMCACHED_SERVER . ' - ';
7551
+                    if (!empty(Globals::$conf->global->MEMCACHED_SERVER)) {
7552
+                                            print 'MEMCACHED_SERVER=' . Globals::$conf->global->MEMCACHED_SERVER . ' - ';
7553
+                    }
7178 7554
                     print 'MAIN_OPTIMIZE_SPEED=' . (isset(Globals::$conf->global->MAIN_OPTIMIZE_SPEED) ? Globals::$conf->global->MAIN_OPTIMIZE_SPEED : 'off');
7179 7555
                     if (!empty($micro_start_time)) {   // Works only if MAIN_SHOW_TUNING_INFO is defined at $_SERVER level. Not in// global variable.
7180 7556
                         $micro_end_time = microtime(true);
@@ -7304,8 +7680,9 @@  discard block
 block discarded – undo
7304 7680
 
7305 7681
         $crits = explode(' ', $value);
7306 7682
         $res = '';
7307
-        if (!is_array($fields))
7308
-            $fields = array($fields);
7683
+        if (!is_array($fields)) {
7684
+                    $fields = array($fields);
7685
+        }
7309 7686
 
7310 7687
         $nboffields = count($fields);
7311 7688
         $end2 = count($crits);
@@ -7368,8 +7745,9 @@  discard block
 block discarded – undo
7368 7745
                     $tmpcrits = explode('|', $crit);
7369 7746
                     $i3 = 0;
7370 7747
                     foreach ($tmpcrits as $tmpcrit) {
7371
-                        if (empty($tmpcrit))
7372
-                            continue;
7748
+                        if (empty($tmpcrit)) {
7749
+                                                    continue;
7750
+                        }
7373 7751
 
7374 7752
                         $newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
7375 7753
 
@@ -7405,8 +7783,9 @@  discard block
 block discarded – undo
7405 7783
                 }
7406 7784
                 $i++;
7407 7785
             }
7408
-            if ($newres)
7409
-                $res = $res . ($res ? ' AND ' : '') . ($i2 > 1 ? '(' : '') . $newres . ($i2 > 1 ? ')' : '');
7786
+            if ($newres) {
7787
+                            $res = $res . ($res ? ' AND ' : '') . ($i2 > 1 ? '(' : '') . $newres . ($i2 > 1 ? ')' : '');
7788
+            }
7410 7789
             $j++;
7411 7790
         }
7412 7791
         $res = ($nofirstand ? "" : " AND ") . "(" . $res . ")";
@@ -7446,29 +7825,37 @@  discard block
 block discarded – undo
7446 7825
     static function getImageFileNameForSize($file, $extName, $extImgTarget = '')
7447 7826
     {
7448 7827
         $dirName = dirname($file);
7449
-        if ($dirName == '.')
7450
-            $dirName = '';
7828
+        if ($dirName == '.') {
7829
+                    $dirName = '';
7830
+        }
7451 7831
 
7452 7832
         $fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$/i', '', $file); // We remove extension, whatever is its case
7453 7833
         $fileName = basename($fileName);
7454 7834
 
7455
-        if (empty($extImgTarget))
7456
-            $extImgTarget = (preg_match('/\.jpg$/i', $file) ? '.jpg' : '');
7457
-        if (empty($extImgTarget))
7458
-            $extImgTarget = (preg_match('/\.jpeg$/i', $file) ? '.jpeg' : '');
7459
-        if (empty($extImgTarget))
7460
-            $extImgTarget = (preg_match('/\.gif$/i', $file) ? '.gif' : '');
7461
-        if (empty($extImgTarget))
7462
-            $extImgTarget = (preg_match('/\.png$/i', $file) ? '.png' : '');
7463
-        if (empty($extImgTarget))
7464
-            $extImgTarget = (preg_match('/\.bmp$/i', $file) ? '.bmp' : '');
7465
-
7466
-        if (!$extImgTarget)
7467
-            return $file;
7835
+        if (empty($extImgTarget)) {
7836
+                    $extImgTarget = (preg_match('/\.jpg$/i', $file) ? '.jpg' : '');
7837
+        }
7838
+        if (empty($extImgTarget)) {
7839
+                    $extImgTarget = (preg_match('/\.jpeg$/i', $file) ? '.jpeg' : '');
7840
+        }
7841
+        if (empty($extImgTarget)) {
7842
+                    $extImgTarget = (preg_match('/\.gif$/i', $file) ? '.gif' : '');
7843
+        }
7844
+        if (empty($extImgTarget)) {
7845
+                    $extImgTarget = (preg_match('/\.png$/i', $file) ? '.png' : '');
7846
+        }
7847
+        if (empty($extImgTarget)) {
7848
+                    $extImgTarget = (preg_match('/\.bmp$/i', $file) ? '.bmp' : '');
7849
+        }
7850
+
7851
+        if (!$extImgTarget) {
7852
+                    return $file;
7853
+        }
7468 7854
 
7469 7855
         $subdir = '';
7470
-        if ($extName)
7471
-            $subdir = 'thumbs/';
7856
+        if ($extName) {
7857
+                    $subdir = 'thumbs/';
7858
+        }
7472 7859
 
7473 7860
         return ($dirName ? $dirName . '/' : '') . $subdir . $fileName . $extName . $extImgTarget; // New filename for thumb
7474 7861
     }
@@ -7486,8 +7873,9 @@  discard block
 block discarded – undo
7486 7873
     {
7487 7874
        // global Globals::$conf, $langs;
7488 7875
 
7489
-        if (empty(Globals::$conf->use_javascript_ajax))
7490
-            return '';
7876
+        if (empty(Globals::$conf->use_javascript_ajax)) {
7877
+                    return '';
7878
+        }
7491 7879
 
7492 7880
         $mime_preview = array('bmp', 'jpeg', 'png', 'gif', 'tiff', 'pdf', 'plain', 'css', 'svg+xml');
7493 7881
 //$mime_preview[]='vnd.oasis.opendocument.presentation';
@@ -7495,17 +7883,19 @@  discard block
 block discarded – undo
7495 7883
         $num_mime = array_search(dol_mimetype($relativepath, '', 1), $mime_preview);
7496 7884
 
7497 7885
         if ($alldata == 1) {
7498
-            if ($num_mime !== false)
7499
-                return array('target' => '_blank', 'css' => 'documentpreview', 'url' => DOL_BASE_URI . '/document.php?modulepart=' . $modulepart . '&attachment=0&file=' . urlencode($relativepath) . ($param ? '&' . $param : ''), 'mime' => dol_mimetype($relativepath),);
7500
-            else
7501
-                return array();
7886
+            if ($num_mime !== false) {
7887
+                            return array('target' => '_blank', 'css' => 'documentpreview', 'url' => DOL_BASE_URI . '/document.php?modulepart=' . $modulepart . '&attachment=0&file=' . urlencode($relativepath) . ($param ? '&' . $param : ''), 'mime' => dol_mimetype($relativepath),);
7888
+            } else {
7889
+                            return array();
7890
+            }
7502 7891
         }
7503 7892
 
7504 7893
 // old behavior
7505
-        if ($num_mime !== false)
7506
-            return 'javascript:document_preview(\'' . dol_escape_js(DOL_BASE_URI . '/document.php?modulepart=' . $modulepart . '&attachment=0&file=' . urlencode($relativepath) . ($param ? '&' . $param : '')) . '\', \'' . dol_mimetype($relativepath) . '\', \'' . dol_escape_js($langs->trans('Preview')) . '\')';
7507
-        else
7508
-            return '';
7894
+        if ($num_mime !== false) {
7895
+                    return 'javascript:document_preview(\'' . dol_escape_js(DOL_BASE_URI . '/document.php?modulepart=' . $modulepart . '&attachment=0&file=' . urlencode($relativepath) . ($param ? '&' . $param : '')) . '\', \'' . dol_mimetype($relativepath) . '\', \'' . dol_escape_js($langs->trans('Preview')) . '\')';
7896
+        } else {
7897
+                    return '';
7898
+        }
7509 7899
     }
7510 7900
 
7511 7901
     /**
@@ -7523,8 +7913,9 @@  discard block
 block discarded – undo
7523 7913
 				    jQuery("#' . $htmlname . '").click(function() { jQuery(this).select(); } );
7524 7914
 				});
7525 7915
 		    </script>';
7526
-        if ($addlink)
7527
-            $out .= ' <a href="' . $addlink . '" target="_blank">' . $langs->trans("Link") . '</a>';
7916
+        if ($addlink) {
7917
+                    $out .= ' <a href="' . $addlink . '" target="_blank">' . $langs->trans("Link") . '</a>';
7918
+        }
7528 7919
         return $out;
7529 7920
     }
7530 7921
 
@@ -7906,8 +8297,9 @@  discard block
 block discarded – undo
7906 8297
         if (!isset($dictvalues[$tablename])) {
7907 8298
             $dictvalues[$tablename] = array();
7908 8299
             $sql = 'SELECT * FROM ' . $tablename . ' WHERE 1';
7909
-            if ($checkentity)
7910
-                $sql .= ' AND entity IN (0,' . getEntity($tablename) . ')';
8300
+            if ($checkentity) {
8301
+                            $sql .= ' AND entity IN (0,' . getEntity($tablename) . ')';
8302
+            }
7911 8303
 
7912 8304
             $resql = $db->query($sql);
7913 8305
             if ($resql) {
@@ -7919,11 +8311,14 @@  discard block
 block discarded – undo
7919 8311
             }
7920 8312
         }
7921 8313
 
7922
-        if (!empty($dictvalues[$tablename][$id]))
7923
-            return $dictvalues[$tablename][$id]->{$field}; // Found
8314
+        if (!empty($dictvalues[$tablename][$id])) {
8315
+                    return $dictvalues[$tablename][$id]->{$field};
8316
+        }
8317
+        // Found
7924 8318
         else { // Not found
7925
-            if ($id > 0)
7926
-                return $id;
8319
+            if ($id > 0) {
8320
+                            return $id;
8321
+            }
7927 8322
             return '';
7928 8323
         }
7929 8324
     }
@@ -7953,8 +8348,9 @@  discard block
 block discarded – undo
7953 8348
                 $b = hexdec($hexb);
7954 8349
             }
7955 8350
             $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0;    // HSL algorithm
7956
-            if ($bright > 0.6)
7957
-                $res = 1;
8351
+            if ($bright > 0.6) {
8352
+                            $res = 1;
8353
+            }
7958 8354
         }
7959 8355
         return $res;
7960 8356
     }
@@ -7972,8 +8368,10 @@  discard block
 block discarded – undo
7972 8368
        // global Globals::$conf;
7973 8369
 //print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
7974 8370
 //print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
7975
-        if (empty($menuentry['enabled']))
7976
-            return 0; // Entry disabled by condition
8371
+        if (empty($menuentry['enabled'])) {
8372
+                    return 0;
8373
+        }
8374
+        // Entry disabled by condition
7977 8375
         if ($type_user && $menuentry['module']) {
7978 8376
             $tmploops = explode('|', $menuentry['module']);
7979 8377
             $found = 0;
@@ -7983,15 +8381,23 @@  discard block
 block discarded – undo
7983 8381
                     break;
7984 8382
                 }
7985 8383
             }
7986
-            if (!$found)
7987
-                return 0; // Entry is for menus all excluded to external users
7988
-        }
7989
-        if (!$menuentry['perms'] && $type_user)
7990
-            return 0;            // No permissions and user is external
7991
-        if (!$menuentry['perms'] && !empty(Globals::$conf->global->MAIN_MENU_HIDE_UNAUTHORIZED))
7992
-            return 0; // No permissions and option to hide when not allowed, even for internal user, is on
7993
-        if (!$menuentry['perms'])
7994
-            return 2;               // No permissions and user is external
8384
+            if (!$found) {
8385
+                            return 0;
8386
+            }
8387
+            // Entry is for menus all excluded to external users
8388
+        }
8389
+        if (!$menuentry['perms'] && $type_user) {
8390
+                    return 0;
8391
+        }
8392
+        // No permissions and user is external
8393
+        if (!$menuentry['perms'] && !empty(Globals::$conf->global->MAIN_MENU_HIDE_UNAUTHORIZED)) {
8394
+                    return 0;
8395
+        }
8396
+        // No permissions and option to hide when not allowed, even for internal user, is on
8397
+        if (!$menuentry['perms']) {
8398
+                    return 2;
8399
+        }
8400
+        // No permissions and user is external
7995 8401
         return 1;
7996 8402
     }
7997 8403
 
Please login to merge, or discard this patch.
Helpers/Security2.php 1 patch
Braces   +10 added lines, -6 removed lines patch added patch discarded remove patch
@@ -39,10 +39,13 @@  discard block
 block discarded – undo
39 39
     function dol_getwebuser($mode)
40 40
     {
41 41
         $t = '?';
42
-        if ($mode == 'user')
43
-            $t = getenv('APACHE_RUN_USER');   // $_ENV['APACHE_RUN_USER'] is empty
44
-        if ($mode == 'group')
45
-            $t = getenv('APACHE_RUN_GROUP');
42
+        if ($mode == 'user') {
43
+                    $t = getenv('APACHE_RUN_USER');
44
+        }
45
+        // $_ENV['APACHE_RUN_USER'] is empty
46
+        if ($mode == 'group') {
47
+                    $t = getenv('APACHE_RUN_GROUP');
48
+        }
46 49
         return $t;
47 50
     }
48 51
 
@@ -342,8 +345,9 @@  discard block
 block discarded – undo
342 345
                 break;
343 346
         }
344 347
         $salt = '';
345
-        while (dol_strlen($salt) < $saltlen)
346
-            $salt .= chr(mt_rand(64, 126));
348
+        while (dol_strlen($salt) < $saltlen) {
349
+                    $salt .= chr(mt_rand(64, 126));
350
+        }
347 351
 
348 352
         $result = $saltprefix . $salt . $saltsuffix;
349 353
         DolUtils::dol_syslog("makesalt return=" . $result);
Please login to merge, or discard this patch.