Passed
Pull Request — master (#2)
by
unknown
26:19
created
dolibarr/htdocs/core/class/rssparser.class.php 1 patch
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -34,9 +34,9 @@  discard block
 block discarded – undo
34 34
     /**
35 35
 	 * @var string Error code (or message)
36 36
 	 */
37
-	public $error='';
37
+	public $error = '';
38 38
 
39
-    private $_format='';
39
+    private $_format = '';
40 40
     private $_urlRSS;
41 41
     private $_language;
42 42
     private $_generator;
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
     private $_link;
47 47
     private $_title;
48 48
     private $_description;
49
-    private $_lastfetchdate;    // Last successful fetch
50
-    private $_rssarray=array();
49
+    private $_lastfetchdate; // Last successful fetch
50
+    private $_rssarray = array();
51 51
 
52 52
     // For parsing with xmlparser
53 53
     var $stack               = array(); // parser stack
@@ -184,40 +184,40 @@  discard block
 block discarded – undo
184 184
      * 	@param	string	$cachedir	Directory where to save cache file
185 185
      *	@return	int					<0 if KO, >0 if OK
186 186
      */
187
-    public function parser($urlRSS, $maxNb=0, $cachedelay=60, $cachedir='')
187
+    public function parser($urlRSS, $maxNb = 0, $cachedelay = 60, $cachedir = '')
188 188
     {
189 189
         global $conf;
190 190
 
191 191
         include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
192 192
 
193
-        $rss='';
194
-        $str='';    // This will contain content of feed
193
+        $rss = '';
194
+        $str = ''; // This will contain content of feed
195 195
 
196 196
         // Check parameters
197
-        if (! dol_is_url($urlRSS))
197
+        if (!dol_is_url($urlRSS))
198 198
         {
199
-            $this->error="ErrorBadUrl";
199
+            $this->error = "ErrorBadUrl";
200 200
             return -1;
201 201
         }
202 202
 
203 203
         $this->_urlRSS = $urlRSS;
204
-        $newpathofdestfile=$cachedir.'/'.dol_hash($this->_urlRSS,3);	// Force md5 hash (does not contains special chars)
205
-        $newmask='0644';
204
+        $newpathofdestfile = $cachedir.'/'.dol_hash($this->_urlRSS, 3); // Force md5 hash (does not contains special chars)
205
+        $newmask = '0644';
206 206
 
207 207
         //dol_syslog("RssPArser::parser parse url=".$urlRSS." => cache file=".$newpathofdestfile);
208 208
         $nowgmt = dol_now();
209 209
 
210 210
         // Search into cache
211
-        $foundintocache=0;
211
+        $foundintocache = 0;
212 212
         if ($cachedelay > 0 && $cachedir)
213 213
         {
214
-            $filedate=dol_filemtime($newpathofdestfile);
214
+            $filedate = dol_filemtime($newpathofdestfile);
215 215
             if ($filedate >= ($nowgmt - $cachedelay))
216 216
             {
217 217
                 //dol_syslog("RssParser::parser cache file ".$newpathofdestfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we use it.");
218
-                $foundintocache=1;
218
+                $foundintocache = 1;
219 219
 
220
-                $this->_lastfetchdate=$filedate;
220
+                $this->_lastfetchdate = $filedate;
221 221
             }
222 222
             else
223 223
             {
@@ -233,13 +233,13 @@  discard block
 block discarded – undo
233 233
         else
234 234
         {
235 235
             try {
236
-                ini_set("user_agent","Dolibarr ERP-CRM RSS reader");
236
+                ini_set("user_agent", "Dolibarr ERP-CRM RSS reader");
237 237
                 ini_set("max_execution_time", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
238 238
                 ini_set("default_socket_timeout", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
239 239
 
240 240
                 $opts = array('http'=>array('method'=>"GET"));
241
-                if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT;
242
-                if (! empty($conf->global->MAIN_PROXY_USE))           $opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
241
+                if (!empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout'] = $conf->global->MAIN_USE_CONNECT_TIMEOUT;
242
+                if (!empty($conf->global->MAIN_PROXY_USE))           $opts['http']['proxy'] = 'tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
243 243
                 //var_dump($opts);exit;
244 244
                 $context = stream_context_create($opts);
245 245
 
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
         if ($str !== false)
254 254
         {
255 255
 	        // Convert $str into xml
256
-	        if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
256
+	        if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
257 257
 	        {
258 258
 	            //print 'xx'.LIBXML_NOCDATA;
259 259
 	            libxml_use_internal_errors(false);
@@ -261,9 +261,9 @@  discard block
 block discarded – undo
261 261
 	        }
262 262
 	        else
263 263
 	        {
264
-	            $xmlparser=xml_parser_create('');
264
+	            $xmlparser = xml_parser_create('');
265 265
 	            if (!is_resource($xmlparser)) {
266
-	                $this->error="ErrorFailedToCreateParser"; return -1;
266
+	                $this->error = "ErrorFailedToCreateParser"; return -1;
267 267
 	            }
268 268
 
269 269
 	            xml_set_object($xmlparser, $this);
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 	            xml_set_character_data_handler($xmlparser, 'feed_cdata');
272 272
 	            $status = xml_parse($xmlparser, $str);
273 273
 	            xml_parser_free($xmlparser);
274
-	            $rss=$this;
274
+	            $rss = $this;
275 275
 	            //var_dump($rss->_format);exit;
276 276
 	        }
277 277
         }
@@ -283,16 +283,16 @@  discard block
 block discarded – undo
283 283
             if (empty($foundintocache) && $cachedir)
284 284
             {
285 285
                 dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is saved onto disk.");
286
-                if (! dol_is_dir($cachedir)) dol_mkdir($cachedir);
286
+                if (!dol_is_dir($cachedir)) dol_mkdir($cachedir);
287 287
                 $fp = fopen($newpathofdestfile, 'w');
288 288
                 if ($fp)
289 289
                 {
290 290
                 	fwrite($fp, $str);
291 291
                 	fclose($fp);
292
-                	if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
292
+                	if (!empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK;
293 293
                 	@chmod($newpathofdestfile, octdec($newmask));
294 294
 
295
-	                $this->_lastfetchdate=$nowgmt;
295
+	                $this->_lastfetchdate = $nowgmt;
296 296
                 }
297 297
                 else
298 298
                 {
@@ -300,21 +300,21 @@  discard block
 block discarded – undo
300 300
                 }
301 301
             }
302 302
 
303
-            unset($str);    // Free memory
303
+            unset($str); // Free memory
304 304
 
305 305
             if (empty($rss->_format))    // If format not detected automatically
306 306
             {
307
-                $rss->_format='rss';
308
-                if (empty($rss->channel)) $rss->_format='atom';
307
+                $rss->_format = 'rss';
308
+                if (empty($rss->channel)) $rss->_format = 'atom';
309 309
             }
310 310
 
311
-            $items=array();
311
+            $items = array();
312 312
 
313 313
             // Save description entries
314 314
             if ($rss->_format == 'rss')
315 315
             {
316 316
                 //var_dump($rss);
317
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
317
+                if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
318 318
                 {
319 319
                     if (!empty($rss->channel->language))      $this->_language = (string) $rss->channel->language;
320 320
                     if (!empty($rss->channel->generator))     $this->_generator = (string) $rss->channel->generator;
@@ -338,14 +338,14 @@  discard block
 block discarded – undo
338 338
                     if (!empty($rss->channel['description']))   $this->_description = (string) $rss->channel['description'];
339 339
                 }
340 340
 
341
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) $items=$rss->channel->item;    // With simplexml
342
-                else $items=$rss->items;                                                              // With xmlparse
341
+                if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) $items = $rss->channel->item; // With simplexml
342
+                else $items = $rss->items; // With xmlparse
343 343
                 //var_dump($items);exit;
344 344
             }
345 345
             else if ($rss->_format == 'atom')
346 346
             {
347 347
                 //var_dump($rss);
348
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
348
+                if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
349 349
                 {
350 350
                     if (!empty($rss->generator))     $this->_generator = (string) $rss->generator;
351 351
                     if (!empty($rss->lastbuilddate)) $this->_lastbuilddate = (string) $rss->modified;
@@ -364,10 +364,10 @@  discard block
 block discarded – undo
364 364
                     if (!empty($rss->channel['title']))         $this->_title = (string) $rss->channel['title'];
365 365
                     //if (!empty($rss->channel['rss_description']))   $this->_description = (string) $rss->channel['rss_description'];
366 366
                 }
367
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))  {
368
-                    $tmprss=xml2php($rss); $items=$tmprss['entry'];
367
+                if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) {
368
+                    $tmprss = xml2php($rss); $items = $tmprss['entry'];
369 369
                 } // With simplexml
370
-                else $items=$rss->items;                                                              // With xmlparse
370
+                else $items = $rss->items; // With xmlparse
371 371
                 //var_dump($items);exit;
372 372
             }
373 373
 
@@ -376,12 +376,12 @@  discard block
 block discarded – undo
376 376
             // Loop on each record
377 377
             if (is_array($items))
378 378
             {
379
-                foreach($items as $item)
379
+                foreach ($items as $item)
380 380
                 {
381 381
                     //var_dump($item);exit;
382 382
                     if ($rss->_format == 'rss')
383 383
                     {
384
-                        if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
384
+                        if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
385 385
                         {
386 386
                             $itemLink = (string) $item->link;
387 387
                             $itemTitle = (string) $item->title;
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
                         }
402 402
 
403 403
                         // Loop on each category
404
-                        $itemCategory=array();
404
+                        $itemCategory = array();
405 405
                         if (is_array($item->category))
406 406
                         {
407 407
                             foreach ($item->category as $cat)
@@ -412,14 +412,14 @@  discard block
 block discarded – undo
412 412
                     }
413 413
                     else if ($rss->_format == 'atom')
414 414
                     {
415
-                        if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
415
+                        if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
416 416
                         {
417 417
                             $itemLink = (isset($item['link']['href']) ? (string) $item['link']['href'] : '');
418 418
                             $itemTitle = (string) $item['title'];
419 419
                             $itemDescription = (string) $item['summary'];
420 420
                             $itemPubDate = (string) $item['created'];
421 421
                             $itemId = (string) $item['id'];
422
-                            $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
422
+                            $itemAuthor = (string) ($item['author'] ? $item['author'] : $item['author_name']);
423 423
                         }
424 424
                         else
425 425
                         {
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
                             $itemDescription = (string) $item['summary'];
429 429
                             $itemPubDate = (string) $item['created'];
430 430
                             $itemId = (string) $item['id'];
431
-                            $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
431
+                            $itemAuthor = (string) ($item['author'] ? $item['author'] : $item['author_name']);
432 432
                         }
433 433
                     }
434 434
                     else print 'ErrorBadFeedFormat';
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 
447 447
                     $i++;
448 448
 
449
-                    if ($i > $maxNb)    break;    // We get all records we want
449
+                    if ($i > $maxNb)    break; // We get all records we want
450 450
                 }
451 451
             }
452 452
 
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
         }
455 455
         else
456 456
         {
457
-            $this->error='ErrorFailedToLoadRSSFile';
457
+            $this->error = 'ErrorFailedToLoadRSSFile';
458 458
             return -1;
459 459
         }
460 460
     }
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
         {
483 483
             list($ns, $el) = explode(':', $element, 2);
484 484
         }
485
-        if ( $ns and $ns != 'rdf' )
485
+        if ($ns and $ns != 'rdf')
486 486
         {
487 487
             $this->current_namespace = $ns;
488 488
         }
@@ -490,15 +490,15 @@  discard block
 block discarded – undo
490 490
         // if feed type isn't set, then this is first element of feed identify feed from root element
491 491
         if (empty($this->_format))
492 492
         {
493
-            if ( $el == 'rdf' ) {
493
+            if ($el == 'rdf') {
494 494
                 $this->_format = 'rss';
495 495
                 $this->feed_version = '1.0';
496 496
             }
497
-            elseif ( $el == 'rss' ) {
497
+            elseif ($el == 'rss') {
498 498
                 $this->_format = 'rss';
499 499
                 $this->feed_version = $attrs['version'];
500 500
             }
501
-            elseif ( $el == 'feed' ) {
501
+            elseif ($el == 'feed') {
502 502
                 $this->_format = 'atom';
503 503
                 $this->feed_version = $attrs['version'];
504 504
                 $this->inchannel = true;
@@ -506,14 +506,14 @@  discard block
 block discarded – undo
506 506
             return;
507 507
         }
508 508
 
509
-        if ( $el == 'channel' )
509
+        if ($el == 'channel')
510 510
         {
511 511
             $this->inchannel = true;
512 512
         }
513
-        elseif ($el == 'item' or $el == 'entry' )
513
+        elseif ($el == 'item' or $el == 'entry')
514 514
         {
515 515
             $this->initem = true;
516
-            if ( isset($attrs['rdf:about']) ) {
516
+            if (isset($attrs['rdf:about'])) {
517 517
                 $this->current_item['about'] = $attrs['rdf:about'];
518 518
             }
519 519
         }
@@ -537,10 +537,10 @@  discard block
 block discarded – undo
537 537
         }
538 538
 
539 539
         // handle atom content constructs
540
-        elseif ( $this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
540
+        elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS))
541 541
         {
542 542
             // avoid clashing w/ RSS mod_content
543
-            if ($el == 'content' ) {
543
+            if ($el == 'content') {
544 544
                 $el = 'atom_content';
545 545
             }
546 546
 
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
         }
549 549
 
550 550
         // if inside an Atom content construct (e.g. content or summary) field treat tags as text
551
-        elseif ($this->_format == 'atom' and $this->incontent )
551
+        elseif ($this->_format == 'atom' and $this->incontent)
552 552
         {
553 553
             // if tags are inlined, then flatten
554 554
             $attrs_str = join(' ', array_map('map_attrs', array_keys($attrs), array_values($attrs)));
@@ -562,14 +562,14 @@  discard block
 block discarded – undo
562 562
         // Magpie treats link elements of type rel='alternate'
563 563
         // as being equivalent to RSS's simple link element.
564 564
         //
565
-        elseif ($this->_format == 'atom' and $el == 'link' )
565
+        elseif ($this->_format == 'atom' and $el == 'link')
566 566
         {
567
-            if ( isset($attrs['rel']) && $attrs['rel'] == 'alternate' )
567
+            if (isset($attrs['rel']) && $attrs['rel'] == 'alternate')
568 568
             {
569 569
                 $link_el = 'link';
570 570
             }
571 571
             else {
572
-                $link_el = 'link_' . $attrs['rel'];
572
+                $link_el = 'link_'.$attrs['rel'];
573 573
             }
574 574
 
575 575
             $this->append($link_el, $attrs['href']);
@@ -622,26 +622,26 @@  discard block
 block discarded – undo
622 622
             $this->current_item = array();
623 623
             $this->initem = false;
624 624
         }
625
-        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' )
625
+        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput')
626 626
         {
627 627
             $this->intextinput = false;
628 628
         }
629
-        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' )
629
+        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image')
630 630
         {
631 631
             $this->inimage = false;
632 632
         }
633
-        elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
633
+        elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS))
634 634
         {
635 635
             $this->incontent = false;
636 636
         }
637
-        elseif ($el == 'channel' or $el == 'feed' )
637
+        elseif ($el == 'channel' or $el == 'feed')
638 638
         {
639 639
             $this->inchannel = false;
640 640
         }
641
-        elseif ($this->_format == 'atom' and $this->incontent  ) {
641
+        elseif ($this->_format == 'atom' and $this->incontent) {
642 642
             // balance tags properly
643 643
             // note:  i don't think this is actually neccessary
644
-            if ( $this->stack[0] == $el )
644
+            if ($this->stack[0] == $el)
645 645
             {
646 646
                 $this->append_content("</$el>");
647 647
             }
@@ -666,10 +666,10 @@  discard block
 block discarded – undo
666 666
      *  @param	string	$str2		Str2
667 667
      *  @return	string				String cancatenated
668 668
      */
669
-    function concat(&$str1, $str2="")
669
+    function concat(&$str1, $str2 = "")
670 670
     {
671
-        if (!isset($str1) ) {
672
-            $str1="";
671
+        if (!isset($str1)) {
672
+            $str1 = "";
673 673
         }
674 674
         $str1 .= $str2;
675 675
     }
@@ -684,11 +684,11 @@  discard block
 block discarded – undo
684 684
     function append_content($text)
685 685
     {
686 686
         // phpcs:enable
687
-        if ( $this->initem ) {
688
-            $this->concat($this->current_item[ $this->incontent ], $text);
687
+        if ($this->initem) {
688
+            $this->concat($this->current_item[$this->incontent], $text);
689 689
         }
690
-        elseif ( $this->inchannel ) {
691
-            $this->concat($this->channel[ $this->incontent ], $text);
690
+        elseif ($this->inchannel) {
691
+            $this->concat($this->channel[$this->incontent], $text);
692 692
         }
693 693
     }
694 694
 
@@ -704,33 +704,33 @@  discard block
 block discarded – undo
704 704
         if (!$el) {
705 705
             return;
706 706
         }
707
-        if ( $this->current_namespace )
707
+        if ($this->current_namespace)
708 708
         {
709
-            if ( $this->initem ) {
710
-                $this->concat($this->current_item[ $this->current_namespace ][ $el ], $text);
709
+            if ($this->initem) {
710
+                $this->concat($this->current_item[$this->current_namespace][$el], $text);
711 711
             }
712 712
             elseif ($this->inchannel) {
713
-                $this->concat($this->channel[ $this->current_namespace][ $el ], $text);
713
+                $this->concat($this->channel[$this->current_namespace][$el], $text);
714 714
             }
715 715
             elseif ($this->intextinput) {
716
-                $this->concat($this->textinput[ $this->current_namespace][ $el ], $text);
716
+                $this->concat($this->textinput[$this->current_namespace][$el], $text);
717 717
             }
718 718
             elseif ($this->inimage) {
719
-                $this->concat($this->image[ $this->current_namespace ][ $el ], $text);
719
+                $this->concat($this->image[$this->current_namespace][$el], $text);
720 720
             }
721 721
         }
722 722
         else {
723
-            if ( $this->initem ) {
724
-                $this->concat($this->current_item[ $el ], $text);
723
+            if ($this->initem) {
724
+                $this->concat($this->current_item[$el], $text);
725 725
             }
726 726
             elseif ($this->intextinput) {
727
-                $this->concat($this->textinput[ $el ], $text);
727
+                $this->concat($this->textinput[$el], $text);
728 728
             }
729 729
             elseif ($this->inimage) {
730
-                $this->concat($this->image[ $el ], $text);
730
+                $this->concat($this->image[$el], $text);
731 731
             }
732 732
             elseif ($this->inchannel) {
733
-                $this->concat($this->channel[ $el ], $text);
733
+                $this->concat($this->channel[$el], $text);
734 734
             }
735 735
         }
736 736
     }
@@ -748,18 +748,18 @@  discard block
 block discarded – undo
748 748
     $fils = 0;
749 749
     $tab = false;
750 750
     $array = array();
751
-    foreach($xml->children() as $key => $value)
751
+    foreach ($xml->children() as $key => $value)
752 752
     {
753 753
         $child = xml2php($value);
754 754
 
755 755
         //To deal with the attributes
756
-        foreach($value->attributes() as $ak=>$av)
756
+        foreach ($value->attributes() as $ak=>$av)
757 757
         {
758 758
             $child[$ak] = (string) $av;
759 759
         }
760 760
 
761 761
         //Let see if the new child is not in the array
762
-        if ($tab === false && in_array($key,array_keys($array)))
762
+        if ($tab === false && in_array($key, array_keys($array)))
763 763
         {
764 764
             //If this element is already in the array we will create an indexed array
765 765
             $tmp = $array[$key];
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
             $array[$key][] = $child;
769 769
             $tab = true;
770 770
         }
771
-        elseif($tab === true)
771
+        elseif ($tab === true)
772 772
         {
773 773
             //Add an element in an existing array
774 774
             $array[$key][] = $child;
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
     }
784 784
 
785 785
 
786
-    if ($fils==0)
786
+    if ($fils == 0)
787 787
     {
788 788
         return (string) $xml;
789 789
     }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/genericobject.class.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  *	\ingroup    core
21 21
  *	\brief      File of class of generic business class
22 22
  */
23
-require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
23
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
24 24
 
25 25
 
26 26
 /**
@@ -36,6 +36,6 @@  discard block
 block discarded – undo
36 36
      */
37 37
     function __construct($db)
38 38
     {
39
-        $this->db=$db;
39
+        $this->db = $db;
40 40
     }
41 41
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/menu.class.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
      * @param	string	$prefix		Prefix to title (image or picto)
66 66
      * @return	void
67 67
      */
68
-    function add($url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0, $id='', $idsel='', $classname='', $prefix='')
68
+    function add($url, $titre, $level = 0, $enabled = 1, $target = '', $mainmenu = '', $leftmenu = '', $position = 0, $id = '', $idsel = '', $classname = '', $prefix = '')
69 69
     {
70
-    	$this->liste[]=array('url'=>$url,'titre'=>$titre,'level'=>$level,'enabled'=>$enabled,'target'=>$target,'mainmenu'=>$mainmenu,'leftmenu'=>$leftmenu, 'position'=>$position, 'id'=>$id, 'idsel'=>$idsel, 'classname'=>$classname, 'prefix'=>$prefix);
70
+    	$this->liste[] = array('url'=>$url, 'titre'=>$titre, 'level'=>$level, 'enabled'=>$enabled, 'target'=>$target, 'mainmenu'=>$mainmenu, 'leftmenu'=>$leftmenu, 'position'=>$position, 'id'=>$id, 'idsel'=>$idsel, 'classname'=>$classname, 'prefix'=>$prefix);
71 71
     }
72 72
 
73 73
     /**
@@ -88,12 +88,12 @@  discard block
 block discarded – undo
88 88
      * @param	string	$prefix		Prefix to title (image or picto)
89 89
      * @return	void
90 90
      */
91
-    function insert($idafter, $url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0, $id='', $idsel='', $classname='', $prefix='')
91
+    function insert($idafter, $url, $titre, $level = 0, $enabled = 1, $target = '', $mainmenu = '', $leftmenu = '', $position = 0, $id = '', $idsel = '', $classname = '', $prefix = '')
92 92
     {
93
-        $array_start = array_slice($this->liste,0,($idafter+1));
94
-        $array_new   = array(0=>array('url'=>$url,'titre'=>$titre,'level'=>$level,'enabled'=>$enabled,'target'=>$target,'mainmenu'=>$mainmenu,'leftmenu'=>$leftmenu,'position'=>$position, 'id'=>$id, 'idsel'=>$idsel, 'classname'=>$classname, 'prefix'=>$prefix));
95
-        $array_end   = array_slice($this->liste,($idafter+1));
96
-        $this->liste=array_merge($array_start,$array_new,$array_end);
93
+        $array_start = array_slice($this->liste, 0, ($idafter + 1));
94
+        $array_new   = array(0=>array('url'=>$url, 'titre'=>$titre, 'level'=>$level, 'enabled'=>$enabled, 'target'=>$target, 'mainmenu'=>$mainmenu, 'leftmenu'=>$leftmenu, 'position'=>$position, 'id'=>$id, 'idsel'=>$idsel, 'classname'=>$classname, 'prefix'=>$prefix));
95
+        $array_end   = array_slice($this->liste, ($idafter + 1));
96
+        $this->liste = array_merge($array_start, $array_new, $array_end);
97 97
     }
98 98
 
99 99
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
      */
118 118
     function getNbOfVisibleMenuEntries()
119 119
     {
120
-        $nb=0;
121
-        foreach($this->liste as $val)
120
+        $nb = 0;
121
+        foreach ($this->liste as $val)
122 122
         {
123
-            if (! empty($val['enabled'])) $nb++;
123
+            if (!empty($val['enabled'])) $nb++;
124 124
         }
125 125
         return $nb;
126 126
     }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/CMailFile.class.php 1 patch
Spacing   +329 added lines, -329 removed lines patch added patch discarded remove patch
@@ -40,13 +40,13 @@  discard block
 block discarded – undo
40 40
 	public $sendmode;
41 41
 	public $sendsetup;
42 42
 
43
-	var $subject;      	// Topic:       Subject of email
44
-	var $addr_from;    	// From:		Label and EMail of sender (must include '<>'). For example '<[email protected]>' or 'John Doe <[email protected]>' or '<[email protected]>'). Note that with gmail smtps, value here is forced by google to account (but not the reply-to).
43
+	var $subject; // Topic:       Subject of email
44
+	var $addr_from; // From:		Label and EMail of sender (must include '<>'). For example '<[email protected]>' or 'John Doe <[email protected]>' or '<[email protected]>'). Note that with gmail smtps, value here is forced by google to account (but not the reply-to).
45 45
 	// Sender:      Who send the email ("Sender" has sent emails on behalf of "From").
46 46
 	//              Use it when the "From" is an email of a domain that is a SPF protected domain, and sending smtp server is not this domain. In such case, add Sender field with an email of the protected domain.
47 47
 	// Return-Path: Email where to send bounds.
48
-	var $reply_to;		// Reply-To:	Email where to send replies from mailer software (mailer use From if reply-to not defined, Gmail use gmail account if reply-to not defined)
49
-	var $errors_to;		// Errors-To:	Email where to send errors.
48
+	var $reply_to; // Reply-To:	Email where to send replies from mailer software (mailer use From if reply-to not defined, Gmail use gmail account if reply-to not defined)
49
+	var $errors_to; // Errors-To:	Email where to send errors.
50 50
 	var $addr_to;
51 51
 	var $addr_cc;
52 52
 	var $addr_bcc;
@@ -63,10 +63,10 @@  discard block
 block discarded – undo
63 63
 	/**
64 64
 	 * @var string Error code (or message)
65 65
 	 */
66
-	public $error='';
66
+	public $error = '';
67 67
 
68
-	var $smtps;			// Contains SMTPs object (if this method is used)
69
-	var $phpmailer;		// Contains PHPMailer object (if this method is used)
68
+	var $smtps; // Contains SMTPs object (if this method is used)
69
+	var $phpmailer; // Contains PHPMailer object (if this method is used)
70 70
 
71 71
 	/**
72 72
 	 * @var string CSS
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
 	// Image
84 84
 	var $html;
85 85
 	var $image_boundary;
86
-	var $atleastoneimage=0;    // at least one image file with file=xxx.ext into content (TODO Debug this. How can this case be tested. Remove if not used).
87
-	var $html_images=array();
88
-	var $images_encoded=array();
86
+	var $atleastoneimage = 0; // at least one image file with file=xxx.ext into content (TODO Debug this. How can this case be tested. Remove if not used).
87
+	var $html_images = array();
88
+	var $images_encoded = array();
89 89
 	var $image_types = array(
90 90
         'gif'  => 'image/gif',
91 91
 		'jpg'  => 'image/jpeg',
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
 	 *  @param  string  $sendcontext      	 'standard', 'emailing', ... (used to define with sending mode and parameters to use)
120 120
 	 *  @param	string	$replyto			 Reply-to email (will be set to same value than From by default if not provided)
121 121
 	 */
122
-	function __construct($subject, $to, $from, $msg, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=0, $errors_to='', $css='', $trackid='', $moreinheader='', $sendcontext='standard', $replyto='')
122
+	function __construct($subject, $to, $from, $msg, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $addr_cc = "", $addr_bcc = "", $deliveryreceipt = 0, $msgishtml = 0, $errors_to = '', $css = '', $trackid = '', $moreinheader = '', $sendcontext = 'standard', $replyto = '')
123 123
 	{
124 124
 		global $conf, $dolibarr_main_data_root;
125 125
 
126 126
 		$this->sendcontext = $sendcontext;
127 127
 
128
-		if (empty($replyto)) $replyto=$from;
128
+		if (empty($replyto)) $replyto = $from;
129 129
 
130 130
 		// Define this->sendmode
131 131
 		$this->sendmode = '';
@@ -133,28 +133,28 @@  discard block
 block discarded – undo
133 133
 		{
134 134
 			$this->sendmode = $conf->global->MAIN_MAIL_SENDMODE_EMAILING;
135 135
 		}
136
-		if (empty($this->sendmode)) $this->sendmode=$conf->global->MAIN_MAIL_SENDMODE;
137
-		if (empty($this->sendmode)) $this->sendmode='mail';
136
+		if (empty($this->sendmode)) $this->sendmode = $conf->global->MAIN_MAIL_SENDMODE;
137
+		if (empty($this->sendmode)) $this->sendmode = 'mail';
138 138
 
139 139
 		// We define end of line (RFC 821).
140
-		$this->eol="\r\n";
140
+		$this->eol = "\r\n";
141 141
 		// We define end of line for header fields (RFC 822bis section 2.3 says header must contains \r\n).
142
-		$this->eol2="\r\n";
143
-		if (! empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
142
+		$this->eol2 = "\r\n";
143
+		if (!empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
144 144
 		{
145
-			$this->eol="\n";
146
-			$this->eol2="\n";
147
-			$moreinheader = str_replace("\r\n","\n",$moreinheader);
145
+			$this->eol = "\n";
146
+			$this->eol2 = "\n";
147
+			$moreinheader = str_replace("\r\n", "\n", $moreinheader);
148 148
 		}
149 149
 
150 150
 		// On defini mixed_boundary
151
-		$this->mixed_boundary = "multipart_x." . time() . ".x_boundary";
151
+		$this->mixed_boundary = "multipart_x.".time().".x_boundary";
152 152
 
153 153
 		// On defini related_boundary
154
-		$this->related_boundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3);	// Force md5 hash (does not contains special chars)
154
+		$this->related_boundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3); // Force md5 hash (does not contains special chars)
155 155
 
156 156
 		// On defini alternative_boundary
157
-		$this->alternative_boundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3);	// Force md5 hash (does not contains special chars)
157
+		$this->alternative_boundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3); // Force md5 hash (does not contains special chars)
158 158
 
159 159
 		dol_syslog("CMailFile::CMailfile: sendmode=".$this->sendmode." charset=".$conf->file->character_set_client." from=$from, to=$to, addr_cc=$addr_cc, addr_bcc=$addr_bcc, errors_to=$errors_to, trackid=$trackid sendcontext=$sendcontext", LOG_DEBUG);
160 160
 		dol_syslog("CMailFile::CMailfile: subject=".$subject.", deliveryreceipt=".$deliveryreceipt.", msgishtml=".$msgishtml, LOG_DEBUG);
@@ -162,13 +162,13 @@  discard block
 block discarded – undo
162 162
 		if (empty($subject))
163 163
 		{
164 164
 			dol_syslog("CMailFile::CMailfile: Try to send an email with empty subject");
165
-			$this->error='ErrorSubjectIsRequired';
165
+			$this->error = 'ErrorSubjectIsRequired';
166 166
 			return;
167 167
 		}
168 168
 		if (empty($msg))
169 169
 		{
170 170
 		    dol_syslog("CMailFile::CMailfile: Try to send an email with empty body");
171
-		    $msg='.';     // Avoid empty message (with empty message conten show a multipart structure)
171
+		    $msg = '.'; // Avoid empty message (with empty message conten show a multipart structure)
172 172
 		}
173 173
 
174 174
 		// Detect if message is HTML (use fast method)
@@ -185,21 +185,21 @@  discard block
 block discarded – undo
185 185
 		global $dolibarr_main_url_root;
186 186
 
187 187
 		// Define $urlwithroot
188
-		$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
189
-		$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
188
+		$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
189
+		$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
190 190
 		//$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
191 191
 
192 192
 		// Replace relative /viewimage to absolute path
193
-		$msg = preg_replace('/src="'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage\.php/ims', 'src="'.$urlwithroot.'/viewimage.php', $msg, -1, $nbrep);
193
+		$msg = preg_replace('/src="'.preg_quote(DOL_URL_ROOT, '/').'\/viewimage\.php/ims', 'src="'.$urlwithroot.'/viewimage.php', $msg, -1, $nbrep);
194 194
 
195
-		if (! empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) $this->msgishtml=1; // To force to send everything with content type html.
195
+		if (!empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) $this->msgishtml = 1; // To force to send everything with content type html.
196 196
 
197 197
 		// Detect images
198 198
 		if ($this->msgishtml)
199 199
 		{
200 200
 			$this->html = $msg;
201 201
 
202
-			if (! empty($conf->global->MAIN_MAIL_ADD_INLINE_IMAGES_IF_IN_MEDIAS))
202
+			if (!empty($conf->global->MAIN_MAIL_ADD_INLINE_IMAGES_IF_IN_MEDIAS))
203 203
 			{
204 204
 				$findimg = $this->findHtmlImages($dolibarr_main_data_root.'/medias');
205 205
 			}
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 				{
212 212
 					if ($this->html_images[$i])
213 213
 					{
214
-						$this->atleastoneimage=1;
214
+						$this->atleastoneimage = 1;
215 215
 						dol_syslog("CMailFile::CMailfile: html_images[$i]['name']=".$this->html_images[$i]['name'], LOG_DEBUG);
216 216
 					}
217 217
 				}
@@ -225,14 +225,14 @@  discard block
 block discarded – undo
225 225
 			{
226 226
 				if ($filename_list[$i])
227 227
 				{
228
-					$this->atleastonefile=1;
228
+					$this->atleastonefile = 1;
229 229
 					dol_syslog("CMailFile::CMailfile: filename_list[$i]=".$filename_list[$i].", mimetype_list[$i]=".$mimetype_list[$i]." mimefilename_list[$i]=".$mimefilename_list[$i], LOG_DEBUG);
230 230
 				}
231 231
 			}
232 232
 		}
233 233
 
234 234
 		// Add autocopy to (Note: Adding bcc for specific modules are also done from pages)
235
-		if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) $addr_bcc.=($addr_bcc?', ':'').$conf->global->MAIN_MAIL_AUTOCOPY_TO;
235
+		if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) $addr_bcc .= ($addr_bcc ? ', ' : '').$conf->global->MAIN_MAIL_AUTOCOPY_TO;
236 236
 
237 237
 		// Action according to choosed sending method
238 238
 		if ($this->sendmode == 'mail')
@@ -257,17 +257,17 @@  discard block
 block discarded – undo
257 257
 			$this->trackid = $trackid;
258 258
 
259 259
 			$smtp_headers = $this->write_smtpheaders();
260
-			if (! empty($moreinheader)) $smtp_headers.=$moreinheader;   // $moreinheader contains the \r\n
260
+			if (!empty($moreinheader)) $smtp_headers .= $moreinheader; // $moreinheader contains the \r\n
261 261
 
262 262
 			// Define mime_headers
263 263
 			$mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list);
264 264
 
265
-			if (! empty($this->html))
265
+			if (!empty($this->html))
266 266
 			{
267 267
 				if (!empty($css))
268 268
 				{
269 269
 					$this->css = $css;
270
-					$this->buildCSS();    // Build a css style (mode = all) into this->styleCSS and this->bodyCSS
270
+					$this->buildCSS(); // Build a css style (mode = all) into this->styleCSS and this->bodyCSS
271 271
 				}
272 272
 
273 273
 				$msg = $this->html;
@@ -279,20 +279,20 @@  discard block
 block discarded – undo
279 279
 			// Add attachments to text_encoded
280 280
 			if ($this->atleastonefile)
281 281
 			{
282
-				$files_encoded = $this->write_files($filename_list,$mimetype_list,$mimefilename_list);
282
+				$files_encoded = $this->write_files($filename_list, $mimetype_list, $mimefilename_list);
283 283
 			}
284 284
 
285 285
 			// We now define $this->headers and $this->message
286
-			$this->headers = $smtp_headers . $mime_headers;
286
+			$this->headers = $smtp_headers.$mime_headers;
287 287
 			// On nettoie le header pour qu'il ne se termine pas par un retour chariot.
288 288
 			// Ceci evite aussi les lignes vides en fin qui peuvent etre interpretees
289 289
 			// comme des injections mail par les serveurs de messagerie.
290
-			$this->headers = preg_replace("/([\r\n]+)$/i","",$this->headers);
290
+			$this->headers = preg_replace("/([\r\n]+)$/i", "", $this->headers);
291 291
 
292 292
 			//$this->message = $this->eol.'This is a message with multiple parts in MIME format.'.$this->eol;
293 293
 			$this->message = 'This is a message with multiple parts in MIME format.'.$this->eol;
294
-			$this->message.= $text_body . $files_encoded;
295
-			$this->message.= "--" . $this->mixed_boundary . "--" . $this->eol;
294
+			$this->message .= $text_body.$files_encoded;
295
+			$this->message .= "--".$this->mixed_boundary."--".$this->eol;
296 296
 		}
297 297
 		else if ($this->sendmode == 'smtps')
298 298
 		{
@@ -304,14 +304,14 @@  discard block
 block discarded – undo
304 304
 			$smtps->setCharSet($conf->file->character_set_client);
305 305
 
306 306
 			$smtps->setSubject($this->encodetorfc2822($subject));
307
-			$smtps->setTO($this->getValidAddress($to,0,1));
308
-			$smtps->setFrom($this->getValidAddress($from,0,1));
307
+			$smtps->setTO($this->getValidAddress($to, 0, 1));
308
+			$smtps->setFrom($this->getValidAddress($from, 0, 1));
309 309
 			$smtps->setTrackId($trackid);
310
-			$smtps->setReplyTo($this->getValidAddress($replyto,0,1));
310
+			$smtps->setReplyTo($this->getValidAddress($replyto, 0, 1));
311 311
 
312
-			if (! empty($moreinheader)) $smtps->setMoreInHeader($moreinheader);
312
+			if (!empty($moreinheader)) $smtps->setMoreInHeader($moreinheader);
313 313
 
314
-			if (! empty($this->html))
314
+			if (!empty($this->html))
315 315
 			{
316 316
 				if (!empty($css))
317 317
 				{
@@ -322,14 +322,14 @@  discard block
 block discarded – undo
322 322
 				$msg = $this->checkIfHTML($msg);
323 323
 			}
324 324
 
325
-			if ($this->msgishtml) $smtps->setBodyContent($msg,'html');
326
-			else $smtps->setBodyContent($msg,'plain');
325
+			if ($this->msgishtml) $smtps->setBodyContent($msg, 'html');
326
+			else $smtps->setBodyContent($msg, 'plain');
327 327
 
328 328
 			if ($this->atleastoneimage)
329 329
 			{
330 330
 				foreach ($this->images_encoded as $img)
331 331
 				{
332
-					$smtps->setImageInline($img['image_encoded'],$img['name'],$img['content_type'],$img['cid']);
332
+					$smtps->setImageInline($img['image_encoded'], $img['name'], $img['content_type'], $img['cid']);
333 333
 				}
334 334
 			}
335 335
 
@@ -337,8 +337,8 @@  discard block
 block discarded – undo
337 337
 			{
338 338
 				foreach ($filename_list as $i => $val)
339 339
 				{
340
-					$content=file_get_contents($filename_list[$i]);
341
-					$smtps->setAttachment($content,$mimefilename_list[$i],$mimetype_list[$i]);
340
+					$content = file_get_contents($filename_list[$i]);
341
+					$smtps->setAttachment($content, $mimefilename_list[$i], $mimetype_list[$i]);
342 342
 				}
343 343
 			}
344 344
 
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 			$smtps->setErrorsTo($errors_to);
348 348
 			$smtps->setDeliveryReceipt($deliveryreceipt);
349 349
 
350
-			$this->smtps=$smtps;
350
+			$this->smtps = $smtps;
351 351
 		}
352 352
 		else if ($this->sendmode == 'swiftmailer')
353 353
 		{
@@ -383,8 +383,8 @@  discard block
 block discarded – undo
383 383
             //$this->message = new Swift_SignedMessage();
384 384
             // Adding a trackid header to a message
385 385
 			$headers = $this->message->getHeaders();
386
-			$headers->addTextHeader('X-Dolibarr-TRACKID', $trackid . '@' . $host);
387
-			$headerID = time() . '.swiftmailer-dolibarr-' . $trackid . '@' . $host;
386
+			$headers->addTextHeader('X-Dolibarr-TRACKID', $trackid.'@'.$host);
387
+			$headerID = time().'.swiftmailer-dolibarr-'.$trackid.'@'.$host;
388 388
 			$msgid = $headers->get('Message-ID');
389 389
 			$msgid->setId($headerID);
390 390
 			$headers->addIdHeader('References', $headerID);
@@ -394,12 +394,12 @@  discard block
 block discarded – undo
394 394
 			try {
395 395
 				$result = $this->message->setSubject($subject);
396 396
 			} catch (Exception $e) {
397
-				$this->errors[] =  $e->getMessage();
397
+				$this->errors[] = $e->getMessage();
398 398
 			}
399 399
 
400 400
 			// Set the From address with an associative array
401 401
 			//$this->message->setFrom(array('[email protected]' => 'John Doe'));
402
-			if (! empty($from)) {
402
+			if (!empty($from)) {
403 403
                 try {
404 404
                 	$result = $this->message->setFrom($this->getArrayAddress($from));
405 405
                 } catch (Exception $e) {
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
             }
409 409
 
410 410
 			// Set the To addresses with an associative array
411
-			if (! empty($to)) {
411
+			if (!empty($to)) {
412 412
                 try {
413 413
                 	$result = $this->message->setTo($this->getArrayAddress($to));
414 414
                 } catch (Exception $e) {
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
                 }
417 417
             }
418 418
 
419
-			if (! empty($replyto)) {
419
+			if (!empty($replyto)) {
420 420
                 try {
421 421
                 	$result = $this->message->SetReplyTo($this->getArrayAddress($replyto));
422 422
                 } catch (Exception $e) {
@@ -427,10 +427,10 @@  discard block
 block discarded – undo
427 427
 			try {
428 428
 				$result = $this->message->setCharSet($conf->file->character_set_client);
429 429
 			} catch (Exception $e) {
430
-				$this->errors[] =  $e->getMessage();
430
+				$this->errors[] = $e->getMessage();
431 431
 			}
432 432
 
433
-			if (! empty($this->html))
433
+			if (!empty($this->html))
434 434
 			{
435 435
 				if (!empty($css))
436 436
 				{
@@ -455,11 +455,11 @@  discard block
 block discarded – undo
455 455
 			}
456 456
 
457 457
 			if ($this->msgishtml) {
458
-				$this->message->setBody($msg,'text/html');
458
+				$this->message->setBody($msg, 'text/html');
459 459
 				// And optionally an alternative body
460 460
 				$this->message->addPart(html_entity_decode(strip_tags($msg)), 'text/plain');
461 461
 			} else {
462
-				$this->message->setBody($msg,'text/plain');
462
+				$this->message->setBody($msg, 'text/plain');
463 463
 				// And optionally an alternative body
464 464
 				$this->message->addPart($msg, 'text/html');
465 465
 			}
@@ -469,13 +469,13 @@  discard block
 block discarded – undo
469 469
 				foreach ($filename_list as $i => $val)
470 470
 				{
471 471
 					//$this->message->attach(Swift_Attachment::fromPath($filename_list[$i],$mimetype_list[$i]));
472
-					$attachment = Swift_Attachment::fromPath($filename_list[$i],$mimetype_list[$i]);
472
+					$attachment = Swift_Attachment::fromPath($filename_list[$i], $mimetype_list[$i]);
473 473
 					$this->message->attach($attachment);
474 474
 				}
475 475
 			}
476 476
 
477
-			if (! empty($addr_cc)) $this->message->setCc($this->getArrayAddress($addr_cc));
478
-			if (! empty($addr_bcc)) $this->message->setBcc($this->getArrayAddress($addr_bcc));
477
+			if (!empty($addr_cc)) $this->message->setCc($this->getArrayAddress($addr_cc));
478
+			if (!empty($addr_bcc)) $this->message->setBcc($this->getArrayAddress($addr_bcc));
479 479
 			//if (! empty($errors_to)) $this->message->setErrorsTo($this->getArrayAddress($errors_to);
480 480
 			if (isset($deliveryreceipt) && $deliveryreceipt == 1) $this->message->setReadReceiptTo($this->getArrayAddress($from));
481 481
 		}
@@ -495,25 +495,25 @@  discard block
 block discarded – undo
495 495
 	 */
496 496
 	function sendfile()
497 497
 	{
498
-		global $conf,$db,$langs;
498
+		global $conf, $db, $langs;
499 499
 
500
-		$errorlevel=error_reporting();
500
+		$errorlevel = error_reporting();
501 501
 		//error_reporting($errorlevel ^ E_WARNING);   // Desactive warnings
502 502
 
503
-		$res=false;
503
+		$res = false;
504 504
 
505 505
 		if (empty($conf->global->MAIN_DISABLE_ALL_MAILS) || !empty($conf->global->MAIN_MAIL_FORCE_SENDTO))
506 506
 		{
507
-			require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
507
+			require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
508 508
 			$hookmanager = new HookManager($db);
509 509
 			$hookmanager->initHooks(array('mail'));
510 510
 
511
-			$parameters=array(); $action='';
511
+			$parameters = array(); $action = '';
512 512
 			$reshook = $hookmanager->executeHooks('sendMail', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
513 513
 			if ($reshook < 0)
514 514
 			{
515
-				$this->error = "Error in hook maildao sendMail " . $reshook;
516
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_ERR);
515
+				$this->error = "Error in hook maildao sendMail ".$reshook;
516
+				dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
517 517
 
518 518
 				return $reshook;
519 519
 			}
@@ -523,52 +523,52 @@  discard block
 block discarded – undo
523 523
 			}
524 524
 
525 525
 			// Check number of recipient is lower or equal than MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL
526
-			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL=10;
526
+			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL = 10;
527 527
 			$tmparray1 = explode(',', $this->addr_to);
528 528
 			if (count($tmparray1) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)
529 529
 			{
530 530
 				$this->error = 'Too much recipients in to:';
531
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
531
+				dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING);
532 532
 				return false;
533 533
 			}
534
-			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL=10;
534
+			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL = 10;
535 535
 			$tmparray2 = explode(',', $this->addr_cc);
536 536
 			if (count($tmparray2) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)
537 537
 			{
538 538
 				$this->error = 'Too much recipients in cc:';
539
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
539
+				dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING);
540 540
 				return false;
541 541
 			}
542
-			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL=10;
542
+			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL = 10;
543 543
 			$tmparray3 = explode(',', $this->addr_bcc);
544 544
 			if (count($tmparray3) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)
545 545
 			{
546 546
 				$this->error = 'Too much recipients in bcc:';
547
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
547
+				dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING);
548 548
 				return false;
549 549
 			}
550
-			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL=10;
551
-			if ((count($tmparray1)+count($tmparray2)+count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)
550
+			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL = 10;
551
+			if ((count($tmparray1) + count($tmparray2) + count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)
552 552
 			{
553 553
 				$this->error = 'Too much recipients in to:, cc:, bcc:';
554
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
554
+				dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING);
555 555
 				return false;
556 556
 			}
557 557
 
558
-			$keyforsmtpserver='MAIN_MAIL_SMTP_SERVER';
559
-			$keyforsmtpport  ='MAIN_MAIL_SMTP_PORT';
560
-			$keyforsmtpid    ='MAIN_MAIL_SMTPS_ID';
561
-			$keyforsmtppw    ='MAIN_MAIL_SMTPS_PW';
562
-			$keyfortls       ='MAIN_MAIL_EMAIL_TLS';
563
-			$keyforstarttls  ='MAIN_MAIL_EMAIL_STARTTLS';
558
+			$keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER';
559
+			$keyforsmtpport  = 'MAIN_MAIL_SMTP_PORT';
560
+			$keyforsmtpid    = 'MAIN_MAIL_SMTPS_ID';
561
+			$keyforsmtppw    = 'MAIN_MAIL_SMTPS_PW';
562
+			$keyfortls       = 'MAIN_MAIL_EMAIL_TLS';
563
+			$keyforstarttls  = 'MAIN_MAIL_EMAIL_STARTTLS';
564 564
 			if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default')
565 565
 			{
566
-				$keyforsmtpserver='MAIN_MAIL_SMTP_SERVER_EMAILING';
567
-				$keyforsmtpport  ='MAIN_MAIL_SMTP_PORT_EMAILING';
568
-				$keyforsmtpid    ='MAIN_MAIL_SMTPS_ID_EMAILING';
569
-				$keyforsmtppw    ='MAIN_MAIL_SMTPS_PW_EMAILING';
570
-				$keyfortls       ='MAIN_MAIL_EMAIL_TLS_EMAILING';
571
-				$keyforstarttls  ='MAIN_MAIL_EMAIL_STARTTLS_EMAILING';
566
+				$keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER_EMAILING';
567
+				$keyforsmtpport  = 'MAIN_MAIL_SMTP_PORT_EMAILING';
568
+				$keyforsmtpid    = 'MAIN_MAIL_SMTPS_ID_EMAILING';
569
+				$keyforsmtppw    = 'MAIN_MAIL_SMTPS_PW_EMAILING';
570
+				$keyfortls       = 'MAIN_MAIL_EMAIL_TLS_EMAILING';
571
+				$keyforstarttls  = 'MAIN_MAIL_EMAIL_STARTTLS_EMAILING';
572 572
 			}
573 573
 
574 574
 			if (!empty($conf->global->MAIN_MAIL_FORCE_SENDTO))
@@ -591,68 +591,68 @@  discard block
 block discarded – undo
591 591
 				if (isset($_SERVER["WINDIR"]))
592 592
 				{
593 593
 					if (empty($this->addr_from)) $this->addr_from = '[email protected]';
594
-					@ini_set('sendmail_from',$this->getValidAddress($this->addr_from,2));
594
+					@ini_set('sendmail_from', $this->getValidAddress($this->addr_from, 2));
595 595
 				}
596 596
 
597 597
 				// Force parameters
598
-				if (! empty($conf->global->$keyforsmtpserver)) ini_set('SMTP',$conf->global->$keyforsmtpserver);
599
-				if (! empty($conf->global->$keyforsmtpport))   ini_set('smtp_port',$conf->global->$keyforsmtpport);
598
+				if (!empty($conf->global->$keyforsmtpserver)) ini_set('SMTP', $conf->global->$keyforsmtpserver);
599
+				if (!empty($conf->global->$keyforsmtpport))   ini_set('smtp_port', $conf->global->$keyforsmtpport);
600 600
 
601
-				$res=true;
602
-				if ($res && ! $this->subject)
601
+				$res = true;
602
+				if ($res && !$this->subject)
603 603
 				{
604
-					$this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Subject is empty";
604
+					$this->error = "Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Subject is empty";
605 605
 					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
606
-					$res=false;
606
+					$res = false;
607 607
 				}
608
-				$dest=$this->getValidAddress($this->addr_to,2);
609
-				if ($res && ! $dest)
608
+				$dest = $this->getValidAddress($this->addr_to, 2);
609
+				if ($res && !$dest)
610 610
 				{
611
-					$this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid";
611
+					$this->error = "Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid";
612 612
 					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
613
-					$res=false;
613
+					$res = false;
614 614
 				}
615 615
 
616 616
 				if ($res)
617 617
 				{
618
-					$additionnalparam = '';	// By default
619
-					if (! empty($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F))
618
+					$additionnalparam = ''; // By default
619
+					if (!empty($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F))
620 620
 					{
621 621
 						// le "Return-Path" (retour des messages bounced) dans les header ne fonctionne pas avec tous les MTA
622 622
 						// Le forcage de la valeur grace à l'option -f de sendmail est donc possible si la constante MAIN_MAIL_ALLOW_SENDMAIL_F est definie.
623 623
 						// Having this variable defined may create problems with some sendmail (option -f refused)
624 624
 						// Having this variable not defined may create problems with some other sendmail (option -f required)
625
-						$additionnalparam .= ($additionnalparam?' ':'').(! empty($conf->global->MAIN_MAIL_ERRORS_TO) ? '-f' . $this->getValidAddress($conf->global->MAIN_MAIL_ERRORS_TO,2) : ($this->addr_from != '' ? '-f' . $this->getValidAddress($this->addr_from,2) : '') );
625
+						$additionnalparam .= ($additionnalparam ? ' ' : '').(!empty($conf->global->MAIN_MAIL_ERRORS_TO) ? '-f'.$this->getValidAddress($conf->global->MAIN_MAIL_ERRORS_TO, 2) : ($this->addr_from != '' ? '-f'.$this->getValidAddress($this->addr_from, 2) : ''));
626 626
 					}
627
-					if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA))    // To force usage of -ba option. This option tells sendmail to read From: or Sender: to setup sender
627
+					if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA))    // To force usage of -ba option. This option tells sendmail to read From: or Sender: to setup sender
628 628
 					{
629
-						$additionnalparam .= ($additionnalparam?' ':'').'-ba';
629
+						$additionnalparam .= ($additionnalparam ? ' ' : '').'-ba';
630 630
 					}
631 631
 
632
-					if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) $additionnalparam .= ($additionnalparam?' ':'').'-U '.$additionnalparam; // Use -U to add additionnal params
632
+					if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) $additionnalparam .= ($additionnalparam ? ' ' : '').'-U '.$additionnalparam; // Use -U to add additionnal params
633 633
 
634 634
 					dol_syslog("CMailFile::sendfile: mail start HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port').", additionnal_parameters=".$additionnalparam, LOG_DEBUG);
635 635
 
636
-					$this->message=stripslashes($this->message);
636
+					$this->message = stripslashes($this->message);
637 637
 
638
-					if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
638
+					if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
639 639
 
640
-					if (! empty($additionnalparam)) $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers, $additionnalparam);
640
+					if (!empty($additionnalparam)) $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers, $additionnalparam);
641 641
 					else $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers);
642 642
 
643
-					if (! $res)
643
+					if (!$res)
644 644
 					{
645 645
 						$langs->load("errors");
646
-						$this->error="Failed to send mail with php mail";
647
-						$linuxlike=1;
648
-						if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
649
-						if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
650
-						if (! $linuxlike)
646
+						$this->error = "Failed to send mail with php mail";
647
+						$linuxlike = 1;
648
+						if (preg_match('/^win/i', PHP_OS)) $linuxlike = 0;
649
+						if (preg_match('/^mac/i', PHP_OS)) $linuxlike = 0;
650
+						if (!$linuxlike)
651 651
 						{
652
-							$this->error.=" to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port');	// This values are value used only for non linuxlike systems
652
+							$this->error .= " to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port'); // This values are value used only for non linuxlike systems
653 653
 						}
654
-						$this->error.=".<br>";
655
-						$this->error.=$langs->trans("ErrorPhpMailDelivery");
654
+						$this->error .= ".<br>";
655
+						$this->error .= $langs->trans("ErrorPhpMailDelivery");
656 656
 						dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
657 657
 					}
658 658
 					else
@@ -667,86 +667,86 @@  discard block
 block discarded – undo
667 667
 				}
668 668
 
669 669
 				// Restore parameters
670
-				if (! empty($conf->global->$keyforsmtpserver))	ini_restore('SMTP');
671
-				if (! empty($conf->global->$keyforsmtpport)) 	ini_restore('smtp_port');
670
+				if (!empty($conf->global->$keyforsmtpserver))	ini_restore('SMTP');
671
+				if (!empty($conf->global->$keyforsmtpport)) 	ini_restore('smtp_port');
672 672
 			}
673 673
 			else if ($this->sendmode == 'smtps')
674 674
 			{
675
-				if (! is_object($this->smtps))
675
+				if (!is_object($this->smtps))
676 676
 				{
677
-					$this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Constructor of object CMailFile was not initialized without errors.";
677
+					$this->error = "Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Constructor of object CMailFile was not initialized without errors.";
678 678
 					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
679 679
 					return false;
680 680
 				}
681 681
 
682 682
 				// Use SMTPS library
683 683
 				// ------------------------------------------
684
-				$this->smtps->setTransportType(0);	// Only this method is coded in SMTPs library
684
+				$this->smtps->setTransportType(0); // Only this method is coded in SMTPs library
685 685
 
686 686
 				// Clean parameters
687
-				if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver=ini_get('SMTP');
688
-				if (empty($conf->global->$keyforsmtpport))   $conf->global->$keyforsmtpport=ini_get('smtp_port');
687
+				if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver = ini_get('SMTP');
688
+				if (empty($conf->global->$keyforsmtpport))   $conf->global->$keyforsmtpport = ini_get('smtp_port');
689 689
 
690 690
 				// If we use SSL/TLS
691
-				$server=$conf->global->$keyforsmtpserver;
692
-				$secure='';
693
-				if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl';
694
-				if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls';
695
-				$server=($secure?$secure.'://':'').$server;
691
+				$server = $conf->global->$keyforsmtpserver;
692
+				$secure = '';
693
+				if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure = 'ssl';
694
+				if (!empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure = 'tls';
695
+				$server = ($secure ? $secure.'://' : '').$server;
696 696
 
697
-				$port=$conf->global->$keyforsmtpport;
697
+				$port = $conf->global->$keyforsmtpport;
698 698
 
699 699
 				$this->smtps->setHost($server);
700 700
 				$this->smtps->setPort($port); // 25, 465...;
701 701
 
702
-				$loginid=''; $loginpass='';
703
-				if (! empty($conf->global->$keyforsmtpid))
702
+				$loginid = ''; $loginpass = '';
703
+				if (!empty($conf->global->$keyforsmtpid))
704 704
 				{
705 705
 					$loginid = $conf->global->$keyforsmtpid;
706 706
 					$this->smtps->setID($loginid);
707 707
 				}
708
-				if (! empty($conf->global->$keyforsmtppw))
708
+				if (!empty($conf->global->$keyforsmtppw))
709 709
 				{
710 710
 					$loginpass = $conf->global->$keyforsmtppw;
711 711
 					$this->smtps->setPW($loginpass);
712 712
 				}
713 713
 
714
-				$res=true;
715
-				$from=$this->smtps->getFrom('org');
716
-				if ($res && ! $from)
714
+				$res = true;
715
+				$from = $this->smtps->getFrom('org');
716
+				if ($res && !$from)
717 717
 				{
718
-					$this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Sender address '$from' invalid";
718
+					$this->error = "Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Sender address '$from' invalid";
719 719
 					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
720
-					$res=false;
720
+					$res = false;
721 721
 				}
722
-				$dest=$this->smtps->getTo();
723
-				if ($res && ! $dest)
722
+				$dest = $this->smtps->getTo();
723
+				if ($res && !$dest)
724 724
 				{
725
-					$this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Recipient address '$dest' invalid";
725
+					$this->error = "Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Recipient address '$dest' invalid";
726 726
 					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
727
-					$res=false;
727
+					$res = false;
728 728
 				}
729 729
 
730 730
 				if ($res)
731 731
 				{
732
-					if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true);
732
+					if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true);
733 733
 
734
-					$result=$this->smtps->sendMsg();
734
+					$result = $this->smtps->sendMsg();
735 735
 					//print $result;
736 736
 
737
-					if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
737
+					if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
738 738
 
739
-					$result=$this->smtps->getErrors();
739
+					$result = $this->smtps->getErrors();
740 740
 					if (empty($this->error) && empty($result))
741 741
 					{
742 742
 						dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG);
743
-						$res=true;
743
+						$res = true;
744 744
 					}
745 745
 					else
746 746
 					{
747
-						if (empty($this->error)) $this->error=$result;
747
+						if (empty($this->error)) $this->error = $result;
748 748
 						dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
749
-						$res=false;
749
+						$res = false;
750 750
 					}
751 751
 				}
752 752
 			}
@@ -757,19 +757,19 @@  discard block
 block discarded – undo
757 757
 				require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php';
758 758
 
759 759
 				// Clean parameters
760
-				if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver=ini_get('SMTP');
761
-				if (empty($conf->global->$keyforsmtpport))   $conf->global->$keyforsmtpport=ini_get('smtp_port');
760
+				if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver = ini_get('SMTP');
761
+				if (empty($conf->global->$keyforsmtpport))   $conf->global->$keyforsmtpport = ini_get('smtp_port');
762 762
 
763 763
 				// If we use SSL/TLS
764 764
 				$server = $conf->global->$keyforsmtpserver;
765 765
 				$secure = '';
766
-				if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl';
767
-				if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls';
766
+				if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure = 'ssl';
767
+				if (!empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure = 'tls';
768 768
 
769 769
 				$this->transport = new Swift_SmtpTransport($server, $conf->global->$keyforsmtpport, $secure);
770 770
 
771
-				if (! empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid);
772
-				if (! empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw);
771
+				if (!empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid);
772
+				if (!empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw);
773 773
 				//$smtps->_msgReplyTo  = '[email protected]';
774 774
 
775 775
 				// Create the Mailer using your created Transport
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
                     $this->message->attachSigner($signer->ignoreHeader('Return-Path'));
785 785
                 }
786 786
 
787
-                if (! empty($conf->global->MAIN_MAIL_DEBUG)) {
787
+                if (!empty($conf->global->MAIN_MAIL_DEBUG)) {
788 788
 					// To use the ArrayLogger
789 789
 					$this->logger = new Swift_Plugins_Loggers_ArrayLogger();
790 790
 					// Or to use the Echo Logger
@@ -795,14 +795,14 @@  discard block
 block discarded – undo
795 795
 				try {
796 796
 					$result = $this->mailer->send($this->message);
797 797
 				} catch (Exception $e) {
798
-					$this->error =  $e->getMessage();
798
+					$this->error = $e->getMessage();
799 799
 				}
800
-				if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
800
+				if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
801 801
 
802 802
 				$res = true;
803
-				if (! empty($this->error) || ! $result) {
803
+				if (!empty($this->error) || !$result) {
804 804
 					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
805
-					$res=false;
805
+					$res = false;
806 806
 				}
807 807
 				else
808 808
 				{
@@ -817,23 +817,23 @@  discard block
 block discarded – undo
817 817
 				return 'Bad value for sendmode';
818 818
 			}
819 819
 
820
-			$parameters=array(); $action='';
820
+			$parameters = array(); $action = '';
821 821
 			$reshook = $hookmanager->executeHooks('sendMailAfter', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
822 822
 			if ($reshook < 0)
823 823
 			{
824
-				$this->error = "Error in hook maildao sendMailAfter " . $reshook;
825
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_ERR);
824
+				$this->error = "Error in hook maildao sendMailAfter ".$reshook;
825
+				dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
826 826
 
827 827
 				return $reshook;
828 828
 			}
829 829
 		}
830 830
 		else
831 831
 		{
832
-			$this->error='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
832
+			$this->error = 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
833 833
 			dol_syslog("CMailFile::sendfile: ".$this->error, LOG_WARNING);
834 834
 		}
835 835
 
836
-		error_reporting($errorlevel);              // Reactive niveau erreur origine
836
+		error_reporting($errorlevel); // Reactive niveau erreur origine
837 837
 
838 838
 		return $res;
839 839
 	}
@@ -860,17 +860,17 @@  discard block
 block discarded – undo
860 860
 	function _encode_file($sourcefile)
861 861
 	{
862 862
         // phpcs:enable
863
-		$newsourcefile=dol_osencode($sourcefile);
863
+		$newsourcefile = dol_osencode($sourcefile);
864 864
 
865 865
 		if (is_readable($newsourcefile))
866 866
 		{
867
-			$contents = file_get_contents($newsourcefile);	// Need PHP 4.3
868
-			$encoded = chunk_split(base64_encode($contents), 76, $this->eol);    // 76 max is defined into http://tools.ietf.org/html/rfc2047
867
+			$contents = file_get_contents($newsourcefile); // Need PHP 4.3
868
+			$encoded = chunk_split(base64_encode($contents), 76, $this->eol); // 76 max is defined into http://tools.ietf.org/html/rfc2047
869 869
 			return $encoded;
870 870
 		}
871 871
 		else
872 872
 		{
873
-			$this->error="Error: Can't read file '".$sourcefile."' into _encode_file";
873
+			$this->error = "Error: Can't read file '".$sourcefile."' into _encode_file";
874 874
 			dol_syslog("CMailFile::encode_file: ".$this->error, LOG_ERR);
875 875
 			return -1;
876 876
 		}
@@ -888,30 +888,30 @@  discard block
 block discarded – undo
888 888
 	function dump_mail()
889 889
 	{
890 890
         // phpcs:enable
891
-		global $conf,$dolibarr_main_data_root;
891
+		global $conf, $dolibarr_main_data_root;
892 892
 
893 893
 		if (@is_writeable($dolibarr_main_data_root))	// Avoid fatal error on fopen with open_basedir
894 894
 		{
895
-			$outputfile=$dolibarr_main_data_root."/dolibarr_mail.log";
896
-			$fp = fopen($outputfile,"w");
895
+			$outputfile = $dolibarr_main_data_root."/dolibarr_mail.log";
896
+			$fp = fopen($outputfile, "w");
897 897
 
898 898
 			if ($this->sendmode == 'mail')
899 899
 			{
900 900
 				fputs($fp, $this->headers);
901
-				fputs($fp, $this->eol);			// This eol is added by the mail function, so we add it in log
901
+				fputs($fp, $this->eol); // This eol is added by the mail function, so we add it in log
902 902
 				fputs($fp, $this->message);
903 903
 			}
904 904
 			elseif ($this->sendmode == 'smtps')
905 905
 			{
906
-				fputs($fp, $this->smtps->log);	// this->smtps->log is filled only if MAIN_MAIL_DEBUG was set to on
906
+				fputs($fp, $this->smtps->log); // this->smtps->log is filled only if MAIN_MAIL_DEBUG was set to on
907 907
 			}
908 908
 			elseif ($this->sendmode == 'swiftmailer')
909 909
 			{
910
-				fputs($fp, $this->logger->dump());	// this->logger is filled only if MAIN_MAIL_DEBUG was set to on
910
+				fputs($fp, $this->logger->dump()); // this->logger is filled only if MAIN_MAIL_DEBUG was set to on
911 911
 			}
912 912
 
913 913
 			fclose($fp);
914
-			if (! empty($conf->global->MAIN_UMASK))
914
+			if (!empty($conf->global->MAIN_UMASK))
915 915
 				@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
916 916
 		}
917 917
 	}
@@ -925,15 +925,15 @@  discard block
 block discarded – undo
925 925
 	 */
926 926
 	function checkIfHTML($msg)
927 927
 	{
928
-		if (!preg_match('/^[\s\t]*<html/i',$msg))
928
+		if (!preg_match('/^[\s\t]*<html/i', $msg))
929 929
 		{
930 930
 			$out = "<html><head><title></title>";
931
-			if (!empty($this->styleCSS)) $out.= $this->styleCSS;
932
-			$out.= "</head><body";
933
-			if (!empty($this->bodyCSS)) $out.= $this->bodyCSS;
934
-			$out.= ">";
935
-			$out.= $msg;
936
-			$out.= "</body></html>";
931
+			if (!empty($this->styleCSS)) $out .= $this->styleCSS;
932
+			$out .= "</head><body";
933
+			if (!empty($this->bodyCSS)) $out .= $this->bodyCSS;
934
+			$out .= ">";
935
+			$out .= $msg;
936
+			$out .= "</body></html>";
937 937
 		}
938 938
 		else
939 939
 		{
@@ -950,24 +950,24 @@  discard block
 block discarded – undo
950 950
 	 */
951 951
 	function buildCSS()
952 952
 	{
953
-		if (! empty($this->css))
953
+		if (!empty($this->css))
954 954
 		{
955 955
 			// Style CSS
956 956
 			$this->styleCSS = '<style type="text/css">';
957
-			$this->styleCSS.= 'body {';
957
+			$this->styleCSS .= 'body {';
958 958
 
959 959
 			if ($this->css['bgcolor'])
960 960
 			{
961
-				$this->styleCSS.= '  background-color: '.$this->css['bgcolor'].';';
962
-				$this->bodyCSS.= ' bgcolor="'.$this->css['bgcolor'].'"';
961
+				$this->styleCSS .= '  background-color: '.$this->css['bgcolor'].';';
962
+				$this->bodyCSS .= ' bgcolor="'.$this->css['bgcolor'].'"';
963 963
 			}
964 964
 			if ($this->css['bgimage'])
965 965
 			{
966 966
 				// TODO recuperer cid
967
-				$this->styleCSS.= ' background-image: url("cid:'.$this->css['bgimage_cid'].'");';
967
+				$this->styleCSS .= ' background-image: url("cid:'.$this->css['bgimage_cid'].'");';
968 968
 			}
969
-			$this->styleCSS.= '}';
970
-			$this->styleCSS.= '</style>';
969
+			$this->styleCSS .= '}';
970
+			$this->styleCSS .= '</style>';
971 971
 		}
972 972
 	}
973 973
 
@@ -988,48 +988,48 @@  discard block
 block discarded – undo
988 988
 
989 989
 		// Sender
990 990
 		//$out.= "Sender: ".getValidAddress($this->addr_from,2)).$this->eol2;
991
-		$out.= "From: ".$this->getValidAddress($this->addr_from,3,1).$this->eol2;
992
-		if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA))
991
+		$out .= "From: ".$this->getValidAddress($this->addr_from, 3, 1).$this->eol2;
992
+		if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA))
993 993
 		{
994
-			$out.= "To: ".$this->getValidAddress($this->addr_to,0,1).$this->eol2;
994
+			$out .= "To: ".$this->getValidAddress($this->addr_to, 0, 1).$this->eol2;
995 995
 		}
996 996
 		// Return-Path is important because it is used by SPF. Some MTA does not read Return-Path from header but from command line. See option MAIN_MAIL_ALLOW_SENDMAIL_F for that.
997
-		$out.= "Return-Path: ".$this->getValidAddress($this->addr_from,0,1).$this->eol2;
998
-		if (isset($this->reply_to)  && $this->reply_to)  $out.= "Reply-To: ".$this->getValidAddress($this->reply_to,2).$this->eol2;
999
-		if (isset($this->errors_to) && $this->errors_to) $out.= "Errors-To: ".$this->getValidAddress($this->errors_to,2).$this->eol2;
997
+		$out .= "Return-Path: ".$this->getValidAddress($this->addr_from, 0, 1).$this->eol2;
998
+		if (isset($this->reply_to) && $this->reply_to)  $out .= "Reply-To: ".$this->getValidAddress($this->reply_to, 2).$this->eol2;
999
+		if (isset($this->errors_to) && $this->errors_to) $out .= "Errors-To: ".$this->getValidAddress($this->errors_to, 2).$this->eol2;
1000 1000
 
1001 1001
 		// Receiver
1002
-		if (isset($this->addr_cc)   && $this->addr_cc)   $out.= "Cc: ".$this->getValidAddress($this->addr_cc,2).$this->eol2;
1003
-		if (isset($this->addr_bcc)  && $this->addr_bcc)  $out.= "Bcc: ".$this->getValidAddress($this->addr_bcc,2).$this->eol2;    // TODO Question: bcc must not be into header, only into SMTP command "RCPT TO". Does php mail support this ?
1002
+		if (isset($this->addr_cc) && $this->addr_cc)   $out .= "Cc: ".$this->getValidAddress($this->addr_cc, 2).$this->eol2;
1003
+		if (isset($this->addr_bcc) && $this->addr_bcc)  $out .= "Bcc: ".$this->getValidAddress($this->addr_bcc, 2).$this->eol2; // TODO Question: bcc must not be into header, only into SMTP command "RCPT TO". Does php mail support this ?
1004 1004
 
1005 1005
 		// Delivery receipt
1006
-		if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out.= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from,2).$this->eol2;
1006
+		if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out .= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from, 2).$this->eol2;
1007 1007
 
1008 1008
 		//$out.= "X-Priority: 3".$this->eol2;
1009 1009
 
1010
-		$out.= 'Date: ' . date("r") . $this->eol2;
1010
+		$out .= 'Date: '.date("r").$this->eol2;
1011 1011
 
1012 1012
 		$trackid = $this->trackid;
1013 1013
 		if ($trackid)
1014 1014
 		{
1015 1015
 			// References is kept in response and Message-ID is returned into In-Reply-To:
1016
-			$out.= 'Message-ID: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2;	// Uppercase seems replaced by phpmail
1017
-			$out.= 'References: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2;
1018
-			$out.= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host. $this->eol2;
1016
+			$out .= 'Message-ID: <'.time().'.phpmail-dolibarr-'.$trackid.'@'.$host.">".$this->eol2; // Uppercase seems replaced by phpmail
1017
+			$out .= 'References: <'.time().'.phpmail-dolibarr-'.$trackid.'@'.$host.">".$this->eol2;
1018
+			$out .= 'X-Dolibarr-TRACKID: '.$trackid.'@'.$host.$this->eol2;
1019 1019
 		}
1020 1020
 		else
1021 1021
 		{
1022
-			$out.= 'Message-ID: <' . time() . '.phpmail@' . $host . ">" . $this->eol2;
1022
+			$out .= 'Message-ID: <'.time().'.phpmail@'.$host.">".$this->eol2;
1023 1023
 		}
1024 1024
 
1025
-		if (! empty($_SERVER['REMOTE_ADDR'])) $out.= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. $this->eol2;
1026
-		$out.= "X-Mailer: Dolibarr version " . DOL_VERSION ." (using php mail)".$this->eol2;
1027
-		$out.= "Mime-Version: 1.0".$this->eol2;
1025
+		if (!empty($_SERVER['REMOTE_ADDR'])) $out .= "X-RemoteAddr: ".$_SERVER['REMOTE_ADDR'].$this->eol2;
1026
+		$out .= "X-Mailer: Dolibarr version ".DOL_VERSION." (using php mail)".$this->eol2;
1027
+		$out .= "Mime-Version: 1.0".$this->eol2;
1028 1028
 
1029 1029
 		//$out.= "From: ".$this->getValidAddress($this->addr_from,3,1).$this->eol;
1030 1030
 
1031
-		$out.= "Content-Type: multipart/mixed;".$this->eol2." boundary=\"".$this->mixed_boundary."\"".$this->eol2;
1032
-		$out.= "Content-Transfer-Encoding: 8bit".$this->eol2;		// TODO Seems to be ignored. Header is 7bit once received.
1031
+		$out .= "Content-Type: multipart/mixed;".$this->eol2." boundary=\"".$this->mixed_boundary."\"".$this->eol2;
1032
+		$out .= "Content-Transfer-Encoding: 8bit".$this->eol2; // TODO Seems to be ignored. Header is 7bit once received.
1033 1033
 
1034 1034
 		dol_syslog("CMailFile::write_smtpheaders smtp_header=\n".$out);
1035 1035
 		return $out;
@@ -1047,18 +1047,18 @@  discard block
 block discarded – undo
1047 1047
 	function write_mimeheaders($filename_list, $mimefilename_list)
1048 1048
 	{
1049 1049
         // phpcs:enable
1050
-		$mimedone=0;
1050
+		$mimedone = 0;
1051 1051
 		$out = "";
1052 1052
 
1053 1053
 		if (is_array($filename_list))
1054 1054
 		{
1055
-			$filename_list_size=count($filename_list);
1056
-			for($i=0;$i < $filename_list_size;$i++)
1055
+			$filename_list_size = count($filename_list);
1056
+			for ($i = 0; $i < $filename_list_size; $i++)
1057 1057
 			{
1058 1058
 				if ($filename_list[$i])
1059 1059
 				{
1060 1060
 					if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
1061
-					$out.= "X-attachments: $filename_list[$i]".$this->eol2;
1061
+					$out .= "X-attachments: $filename_list[$i]".$this->eol2;
1062 1062
 				}
1063 1063
 			}
1064 1064
 		}
@@ -1079,31 +1079,31 @@  discard block
 block discarded – undo
1079 1079
         // phpcs:enable
1080 1080
 		global $conf;
1081 1081
 
1082
-		$out='';
1082
+		$out = '';
1083 1083
 
1084
-		$out.= "--" . $this->mixed_boundary . $this->eol;
1084
+		$out .= "--".$this->mixed_boundary.$this->eol;
1085 1085
 
1086 1086
 		if ($this->atleastoneimage)
1087 1087
 		{
1088
-			$out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol;
1089
-			$out.= $this->eol;
1090
-			$out.= "--" . $this->alternative_boundary . $this->eol;
1088
+			$out .= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol;
1089
+			$out .= $this->eol;
1090
+			$out .= "--".$this->alternative_boundary.$this->eol;
1091 1091
 		}
1092 1092
 
1093 1093
 		// Make RFC821 Compliant, replace bare linefeeds
1094
-		$strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $msgtext);	// PCRE modifier /s means new lines are common chars
1095
-		if (! empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
1094
+		$strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $msgtext); // PCRE modifier /s means new lines are common chars
1095
+		if (!empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
1096 1096
 		{
1097
-			$strContent = preg_replace("/\r\n/si", "\n", $strContent);	// PCRE modifier /s means new lines are common chars
1097
+			$strContent = preg_replace("/\r\n/si", "\n", $strContent); // PCRE modifier /s means new lines are common chars
1098 1098
 		}
1099 1099
 
1100 1100
 		$strContentAltText = '';
1101 1101
 		if ($this->msgishtml)
1102 1102
 		{
1103 1103
 			// Similar code to forge a text from html is also in CMailFile.class.php
1104
-			$strContentAltText = preg_replace("/<br\s*[^>]*>/"," ", $strContent);
1104
+			$strContentAltText = preg_replace("/<br\s*[^>]*>/", " ", $strContent);
1105 1105
 			$strContentAltText = html_entity_decode(strip_tags($strContentAltText));
1106
-			$strContentAltText = rtrim(wordwrap($strContentAltText, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)?"\r\n":"\n"));
1106
+			$strContentAltText = rtrim(wordwrap($strContentAltText, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA) ? "\r\n" : "\n"));
1107 1107
 
1108 1108
 			// Check if html header already in message, if not complete the message
1109 1109
 			$strContent = $this->checkIfHTML($strContent);
@@ -1112,57 +1112,57 @@  discard block
 block discarded – undo
1112 1112
 		// Make RFC2045 Compliant, split lines
1113 1113
 		//$strContent = rtrim(chunk_split($strContent));    // Function chunck_split seems ko if not used on a base64 content
1114 1114
 		// TODO Encode main content into base64 and use the chunk_split, or quoted-printable
1115
-		$strContent = rtrim(wordwrap($strContent, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)?"\r\n":"\n"));   // TODO Using this method creates unexpected line break on text/plain content.
1115
+		$strContent = rtrim(wordwrap($strContent, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA) ? "\r\n" : "\n")); // TODO Using this method creates unexpected line break on text/plain content.
1116 1116
 
1117 1117
 		if ($this->msgishtml)
1118 1118
 		{
1119 1119
 			if ($this->atleastoneimage)
1120 1120
 			{
1121
-				$out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1121
+				$out .= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1122 1122
 				//$out.= "Content-Transfer-Encoding: 7bit".$this->eol;
1123
-				$out.= $this->eol.($strContentAltText?$strContentAltText:strip_tags($strContent)).$this->eol; // Add plain text message
1124
-				$out.= "--" . $this->alternative_boundary . $this->eol;
1125
-				$out.= "Content-Type: multipart/related;".$this->eol." boundary=\"".$this->related_boundary."\"".$this->eol;
1126
-				$out.= $this->eol;
1127
-				$out.= "--" . $this->related_boundary . $this->eol;
1123
+				$out .= $this->eol.($strContentAltText ? $strContentAltText : strip_tags($strContent)).$this->eol; // Add plain text message
1124
+				$out .= "--".$this->alternative_boundary.$this->eol;
1125
+				$out .= "Content-Type: multipart/related;".$this->eol." boundary=\"".$this->related_boundary."\"".$this->eol;
1126
+				$out .= $this->eol;
1127
+				$out .= "--".$this->related_boundary.$this->eol;
1128 1128
 			}
1129 1129
 
1130
-			if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))    // Add plain text message part before html part
1130
+			if (!$this->atleastoneimage && $strContentAltText && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART))    // Add plain text message part before html part
1131 1131
 			{
1132
-				$out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol;
1133
-				$out.= $this->eol;
1134
-				$out.= "--" . $this->alternative_boundary . $this->eol;
1135
-				$out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1132
+				$out .= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol;
1133
+				$out .= $this->eol;
1134
+				$out .= "--".$this->alternative_boundary.$this->eol;
1135
+				$out .= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1136 1136
 				//$out.= "Content-Transfer-Encoding: 7bit".$this->eol;
1137
-				$out.= $this->eol.$strContentAltText.$this->eol;
1138
-				$out.= "--" . $this->alternative_boundary . $this->eol;
1137
+				$out .= $this->eol.$strContentAltText.$this->eol;
1138
+				$out .= "--".$this->alternative_boundary.$this->eol;
1139 1139
 			}
1140 1140
 
1141
-			$out.= "Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol;
1141
+			$out .= "Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol;
1142 1142
 			//$out.= "Content-Transfer-Encoding: 7bit".$this->eol;	// TODO Use base64
1143
-			$out.= $this->eol.$strContent.$this->eol;
1143
+			$out .= $this->eol.$strContent.$this->eol;
1144 1144
 
1145
-			if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))    // Add plain text message part after html part
1145
+			if (!$this->atleastoneimage && $strContentAltText && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART))    // Add plain text message part after html part
1146 1146
 			{
1147
-				$out.= "--" . $this->alternative_boundary . "--". $this->eol;
1147
+				$out .= "--".$this->alternative_boundary."--".$this->eol;
1148 1148
 			}
1149 1149
 		}
1150 1150
 		else
1151 1151
 		{
1152
-			$out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1152
+			$out .= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1153 1153
 			//$out.= "Content-Transfer-Encoding: 7bit".$this->eol;
1154
-			$out.= $this->eol.$strContent.$this->eol;
1154
+			$out .= $this->eol.$strContent.$this->eol;
1155 1155
 		}
1156 1156
 
1157
-		$out.= $this->eol;
1157
+		$out .= $this->eol;
1158 1158
 
1159 1159
 		// Encode images
1160 1160
 		if ($this->atleastoneimage)
1161 1161
 		{
1162 1162
 			$out .= $this->write_images($this->images_encoded);
1163 1163
 			// always end related and end alternative after inline images
1164
-			$out .= "--" . $this->related_boundary . "--" . $this->eol;
1165
-			$out .= $this->eol . "--" . $this->alternative_boundary . "--" . $this->eol;
1164
+			$out .= "--".$this->related_boundary."--".$this->eol;
1165
+			$out .= $this->eol."--".$this->alternative_boundary."--".$this->eol;
1166 1166
 			$out .= $this->eol;
1167 1167
 		}
1168 1168
 
@@ -1178,13 +1178,13 @@  discard block
 block discarded – undo
1178 1178
 	 * @param 	array	$mimefilename_list	Tableau
1179 1179
 	 * @return	string						Chaine fichiers encodes
1180 1180
 	 */
1181
-	function write_files($filename_list,$mimetype_list,$mimefilename_list)
1181
+	function write_files($filename_list, $mimetype_list, $mimefilename_list)
1182 1182
 	{
1183 1183
         // phpcs:enable
1184 1184
 		$out = '';
1185 1185
 
1186
-		$filename_list_size=count($filename_list);
1187
-		for($i=0;$i < $filename_list_size;$i++)
1186
+		$filename_list_size = count($filename_list);
1187
+		for ($i = 0; $i < $filename_list_size; $i++)
1188 1188
 		{
1189 1189
 			if ($filename_list[$i])
1190 1190
 			{
@@ -1193,18 +1193,18 @@  discard block
 block discarded – undo
1193 1193
 				if ($encoded >= 0)
1194 1194
 				{
1195 1195
 					if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
1196
-					if (! $mimetype_list[$i]) {
1196
+					if (!$mimetype_list[$i]) {
1197 1197
 						$mimetype_list[$i] = "application/octet-stream";
1198 1198
 					}
1199 1199
 
1200
-					$out.= "--" . $this->mixed_boundary . $this->eol;
1201
-					$out.= "Content-Disposition: attachment; filename=\"".$filename_list[$i]."\"".$this->eol;
1202
-					$out.= "Content-Type: " . $mimetype_list[$i] . "; name=\"".$filename_list[$i]."\"".$this->eol;
1203
-					$out.= "Content-Transfer-Encoding: base64".$this->eol;
1204
-					$out.= "Content-Description: ".$filename_list[$i].$this->eol;
1205
-					$out.= $this->eol;
1206
-					$out.= $encoded;
1207
-					$out.= $this->eol;
1200
+					$out .= "--".$this->mixed_boundary.$this->eol;
1201
+					$out .= "Content-Disposition: attachment; filename=\"".$filename_list[$i]."\"".$this->eol;
1202
+					$out .= "Content-Type: ".$mimetype_list[$i]."; name=\"".$filename_list[$i]."\"".$this->eol;
1203
+					$out .= "Content-Transfer-Encoding: base64".$this->eol;
1204
+					$out .= "Content-Description: ".$filename_list[$i].$this->eol;
1205
+					$out .= $this->eol;
1206
+					$out .= $encoded;
1207
+					$out .= $this->eol;
1208 1208
 					//$out.= $this->eol;
1209 1209
 				}
1210 1210
 				else
@@ -1236,14 +1236,14 @@  discard block
 block discarded – undo
1236 1236
 			{
1237 1237
 				dol_syslog("CMailFile::write_images: ".$img["name"]);
1238 1238
 
1239
-				$out.= "--" . $this->related_boundary . $this->eol; // always related for an inline image
1240
-				$out.= "Content-Type: " . $img["content_type"] . "; name=\"".$img["name"]."\"".$this->eol;
1241
-				$out.= "Content-Transfer-Encoding: base64".$this->eol;
1242
-				$out.= "Content-Disposition: inline; filename=\"".$img["name"]."\"".$this->eol;
1243
-				$out.= "Content-ID: <".$img["cid"].">".$this->eol;
1244
-				$out.= $this->eol;
1245
-				$out.= $img["image_encoded"];
1246
-				$out.= $this->eol;
1239
+				$out .= "--".$this->related_boundary.$this->eol; // always related for an inline image
1240
+				$out .= "Content-Type: ".$img["content_type"]."; name=\"".$img["name"]."\"".$this->eol;
1241
+				$out .= "Content-Transfer-Encoding: base64".$this->eol;
1242
+				$out .= "Content-Disposition: inline; filename=\"".$img["name"]."\"".$this->eol;
1243
+				$out .= "Content-ID: <".$img["cid"].">".$this->eol;
1244
+				$out .= $this->eol;
1245
+				$out .= $img["image_encoded"];
1246
+				$out .= $this->eol;
1247 1247
 			}
1248 1248
 		}
1249 1249
 
@@ -1259,44 +1259,44 @@  discard block
 block discarded – undo
1259 1259
 	 * @param 	int			$port		Example: 25, 465
1260 1260
 	 * @return	int						Socket id if ok, 0 if KO
1261 1261
 	 */
1262
-	function check_server_port($host,$port)
1262
+	function check_server_port($host, $port)
1263 1263
 	{
1264 1264
         // phpcs:enable
1265 1265
 		global $conf;
1266 1266
 
1267
-		$_retVal=0;
1268
-		$timeout=5;	// Timeout in seconds
1267
+		$_retVal = 0;
1268
+		$timeout = 5; // Timeout in seconds
1269 1269
 
1270 1270
 		if (function_exists('fsockopen'))
1271 1271
 		{
1272
-			$keyforsmtpserver='MAIN_MAIL_SMTP_SERVER';
1273
-			$keyforsmtpport  ='MAIN_MAIL_SMTP_PORT';
1274
-			$keyforsmtpid    ='MAIN_MAIL_SMTPS_ID';
1275
-			$keyforsmtppw    ='MAIN_MAIL_SMTPS_PW';
1276
-			$keyfortls       ='MAIN_MAIL_EMAIL_TLS';
1277
-			$keyforstarttls  ='MAIN_MAIL_EMAIL_STARTTLS';
1272
+			$keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER';
1273
+			$keyforsmtpport  = 'MAIN_MAIL_SMTP_PORT';
1274
+			$keyforsmtpid    = 'MAIN_MAIL_SMTPS_ID';
1275
+			$keyforsmtppw    = 'MAIN_MAIL_SMTPS_PW';
1276
+			$keyfortls       = 'MAIN_MAIL_EMAIL_TLS';
1277
+			$keyforstarttls  = 'MAIN_MAIL_EMAIL_STARTTLS';
1278 1278
 			if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default')
1279 1279
 			{
1280
-				$keyforsmtpserver='MAIN_MAIL_SMTP_SERVER_EMAILING';
1281
-				$keyforsmtpport  ='MAIN_MAIL_SMTP_PORT_EMAILING';
1282
-				$keyforsmtpid    ='MAIN_MAIL_SMTPS_ID_EMAILING';
1283
-				$keyforsmtppw    ='MAIN_MAIL_SMTPS_PW_EMAILING';
1284
-				$keyfortls       ='MAIN_MAIL_EMAIL_TLS_EMAILING';
1285
-				$keyforstarttls  ='MAIN_MAIL_EMAIL_STARTTLS_EMAILING';
1280
+				$keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER_EMAILING';
1281
+				$keyforsmtpport  = 'MAIN_MAIL_SMTP_PORT_EMAILING';
1282
+				$keyforsmtpid    = 'MAIN_MAIL_SMTPS_ID_EMAILING';
1283
+				$keyforsmtppw    = 'MAIN_MAIL_SMTPS_PW_EMAILING';
1284
+				$keyfortls       = 'MAIN_MAIL_EMAIL_TLS_EMAILING';
1285
+				$keyforstarttls  = 'MAIN_MAIL_EMAIL_STARTTLS_EMAILING';
1286 1286
 			}
1287 1287
 
1288 1288
 			// If we use SSL/TLS
1289
-			if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $host='ssl://'.$host;
1289
+			if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) $host = 'ssl://'.$host;
1290 1290
 			// tls smtp start with no encryption
1291 1291
 			//if (! empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS) && function_exists('openssl_open')) $host='tls://'.$host;
1292 1292
 
1293 1293
 			dol_syslog("Try socket connection to host=".$host." port=".$port);
1294 1294
 			//See if we can connect to the SMTP server
1295 1295
 			if ($socket = @fsockopen(
1296
-					$host,       // Host to test, IP or domain. Add ssl:// for SSL/TLS.
1297
-					$port,       // which Port number to use
1298
-					$errno,      // actual system level error
1299
-					$errstr,     // and any text that goes with the error
1296
+					$host, // Host to test, IP or domain. Add ssl:// for SSL/TLS.
1297
+					$port, // which Port number to use
1298
+					$errno, // actual system level error
1299
+					$errstr, // and any text that goes with the error
1300 1300
 					$timeout
1301 1301
 			))  // timeout for reading/writing data over the socket
1302 1302
 			{
@@ -1306,11 +1306,11 @@  discard block
 block discarded – undo
1306 1306
 				dol_syslog("Now we wait for answer 220");
1307 1307
 
1308 1308
 				// Check response from Server
1309
-				if ( $_retVal = $this->server_parse($socket, "220") ) $_retVal = $socket;
1309
+				if ($_retVal = $this->server_parse($socket, "220")) $_retVal = $socket;
1310 1310
 			}
1311 1311
 			else
1312 1312
 			{
1313
-				$this->error = utf8_check('Error '.$errno.' - '.$errstr)?'Error '.$errno.' - '.$errstr:utf8_encode('Error '.$errno.' - '.$errstr);
1313
+				$this->error = utf8_check('Error '.$errno.' - '.$errstr) ? 'Error '.$errno.' - '.$errstr : utf8_encode('Error '.$errno.' - '.$errstr);
1314 1314
 			}
1315 1315
 		}
1316 1316
 		return $_retVal;
@@ -1328,21 +1328,21 @@  discard block
 block discarded – undo
1328 1328
 	function server_parse($socket, $response)
1329 1329
 	{
1330 1330
         // phpcs:enable
1331
-		$_retVal = true;	// Indicates if Object was created or not
1331
+		$_retVal = true; // Indicates if Object was created or not
1332 1332
 		$server_response = '';
1333 1333
 
1334
-		while (substr($server_response,3,1) != ' ')
1334
+		while (substr($server_response, 3, 1) != ' ')
1335 1335
 		{
1336
-			if (! ($server_response = fgets($socket, 256)) )
1336
+			if (!($server_response = fgets($socket, 256)))
1337 1337
 			{
1338
-				$this->error="Couldn't get mail server response codes";
1338
+				$this->error = "Couldn't get mail server response codes";
1339 1339
 				return false;
1340 1340
 			}
1341 1341
 		}
1342 1342
 
1343
-		if( !( substr($server_response, 0, 3) == $response ) )
1343
+		if (!(substr($server_response, 0, 3) == $response))
1344 1344
 		{
1345
-			$this->error="Ran into problems sending Mail.\r\nResponse: $server_response";
1345
+			$this->error = "Ran into problems sending Mail.\r\nResponse: $server_response";
1346 1346
 			$_retVal = false;
1347 1347
 		}
1348 1348
 
@@ -1361,22 +1361,22 @@  discard block
 block discarded – undo
1361 1361
 		$extensions = array_keys($this->image_types);
1362 1362
 
1363 1363
 		$matches = array();
1364
-		preg_match_all('/(?:"|\')([^"\']+\.('.implode('|', $extensions).'))(?:"|\')/Ui', $this->html, $matches);  // If "xxx.ext" or 'xxx.ext' found
1364
+		preg_match_all('/(?:"|\')([^"\']+\.('.implode('|', $extensions).'))(?:"|\')/Ui', $this->html, $matches); // If "xxx.ext" or 'xxx.ext' found
1365 1365
 
1366
-		if (! empty($matches))
1366
+		if (!empty($matches))
1367 1367
 		{
1368
-			$i=0;
1368
+			$i = 0;
1369 1369
 			foreach ($matches[1] as $full)
1370 1370
 			{
1371 1371
 
1372
-				if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i',$full,$regs))   // If xxx is 'file=aaa'
1372
+				if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i', $full, $regs))   // If xxx is 'file=aaa'
1373 1373
 				{
1374 1374
 					$img = $regs[1];
1375 1375
 
1376 1376
 					if (file_exists($images_dir.'/'.$img))
1377 1377
 					{
1378 1378
 						// Image path in src
1379
-						$src = preg_quote($full,'/');
1379
+						$src = preg_quote($full, '/');
1380 1380
 
1381 1381
 						// Image full path
1382 1382
 						$this->html_images[$i]["fullpath"] = $images_dir.'/'.$img;
@@ -1387,12 +1387,12 @@  discard block
 block discarded – undo
1387 1387
 						// Content type
1388 1388
 						if (preg_match('/^.+\.(\w{3,4})$/', $img, $reg))
1389 1389
 						{
1390
-							$ext=strtolower($reg[1]);
1390
+							$ext = strtolower($reg[1]);
1391 1391
 							$this->html_images[$i]["content_type"] = $this->image_types[$ext];
1392 1392
 						}
1393 1393
 
1394 1394
 						// cid
1395
-						$this->html_images[$i]["cid"] = dol_hash(uniqid(time()), 3);	// Force md5 hash (does not contains special chars)
1395
+						$this->html_images[$i]["cid"] = dol_hash(uniqid(time()), 3); // Force md5 hash (does not contains special chars)
1396 1396
 						$this->html = preg_replace("/src=\"$src\"|src='$src'/i", "src=\"cid:".$this->html_images[$i]["cid"]."\"", $this->html);
1397 1397
 					}
1398 1398
 					$i++;
@@ -1403,20 +1403,20 @@  discard block
 block discarded – undo
1403 1403
 			{
1404 1404
 				$inline = array();
1405 1405
 
1406
-				$i=0;
1406
+				$i = 0;
1407 1407
 
1408 1408
 				foreach ($this->html_images as $img)
1409 1409
 				{
1410 1410
 					$fullpath = $images_dir.'/'.$img["name"];
1411 1411
 
1412 1412
 					// If duplicate images are embedded, they may show up as attachments, so remove them.
1413
-					if (!in_array($fullpath,$inline))
1413
+					if (!in_array($fullpath, $inline))
1414 1414
 					{
1415 1415
 						// Read image file
1416 1416
 						if ($image = file_get_contents($fullpath))
1417 1417
 						{
1418 1418
 							// On garde que le nom de l'image
1419
-							preg_match('/([A-Za-z0-9_-]+[\.]?[A-Za-z0-9]+)?$/i',$img["name"],$regs);
1419
+							preg_match('/([A-Za-z0-9_-]+[\.]?[A-Za-z0-9]+)?$/i', $img["name"], $regs);
1420 1420
 							$imgName = $regs[1];
1421 1421
 
1422 1422
 							$this->images_encoded[$i]['name'] = $imgName;
@@ -1457,19 +1457,19 @@  discard block
 block discarded – undo
1457 1457
 	 *										     If format 3: '<[email protected]>' or '"John Doe" <[email protected]>' or '"=?UTF-8?B?Sm9obiBEb2U=?=" <[email protected]>'
1458 1458
 	 *                                           If format 4: 'John Doe' or '[email protected]' if no label exists
1459 1459
 	 */
1460
-	static function getValidAddress($address,$format,$encode=0,$maxnumberofemail=0)
1460
+	static function getValidAddress($address, $format, $encode = 0, $maxnumberofemail = 0)
1461 1461
 	{
1462 1462
 		global $conf;
1463 1463
 
1464
-		$ret='';
1464
+		$ret = '';
1465 1465
 
1466
-		$arrayaddress=explode(',',$address);
1466
+		$arrayaddress = explode(',', $address);
1467 1467
 
1468 1468
 		// Boucle sur chaque composant de l'adresse
1469
-		$i=0;
1470
-		foreach($arrayaddress as $val)
1469
+		$i = 0;
1470
+		foreach ($arrayaddress as $val)
1471 1471
 		{
1472
-			if (preg_match('/^(.*)<(.*)>$/i',trim($val),$regs))
1472
+			if (preg_match('/^(.*)<(.*)>$/i', trim($val), $regs))
1473 1473
 			{
1474 1474
 				$name  = trim($regs[1]);
1475 1475
 				$email = trim($regs[2]);
@@ -1484,32 +1484,32 @@  discard block
 block discarded – undo
1484 1484
 			{
1485 1485
 				$i++;
1486 1486
 
1487
-				$newemail='';
1487
+				$newemail = '';
1488 1488
 				if ($format == 4)
1489 1489
 				{
1490
-					$newemail = $name?$name:$email;
1490
+					$newemail = $name ? $name : $email;
1491 1491
 				}
1492 1492
 				if ($format == 2)
1493 1493
 				{
1494
-					$newemail=$email;
1494
+					$newemail = $email;
1495 1495
 				}
1496 1496
 				if ($format == 1 || $format == 3)
1497 1497
 				{
1498
-					$newemail='<'.$email.'>';
1498
+					$newemail = '<'.$email.'>';
1499 1499
 				}
1500 1500
 				if ($format == 0 || $format == 3)
1501 1501
 				{
1502
-					if (! empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) $newemail='<'.$email.'>';
1503
-					elseif (! $name) $newemail='<'.$email.'>';
1504
-					else $newemail=($format==3?'"':'').($encode?self::encodetorfc2822($name):$name).($format==3?'"':'').' <'.$email.'>';
1502
+					if (!empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) $newemail = '<'.$email.'>';
1503
+					elseif (!$name) $newemail = '<'.$email.'>';
1504
+					else $newemail = ($format == 3 ? '"' : '').($encode ?self::encodetorfc2822($name) : $name).($format == 3 ? '"' : '').' <'.$email.'>';
1505 1505
 				}
1506 1506
 
1507
-				$ret=($ret ? $ret.',' : '').$newemail;
1507
+				$ret = ($ret ? $ret.',' : '').$newemail;
1508 1508
 
1509 1509
 				// Stop if we have too much records
1510 1510
 				if ($maxnumberofemail && $i >= $maxnumberofemail)
1511 1511
 				{
1512
-					if (count($arrayaddress) > $maxnumberofemail) $ret.='...';
1512
+					if (count($arrayaddress) > $maxnumberofemail) $ret .= '...';
1513 1513
 					break;
1514 1514
 				}
1515 1515
 			}
@@ -1528,14 +1528,14 @@  discard block
 block discarded – undo
1528 1528
 	{
1529 1529
 		global $conf;
1530 1530
 
1531
-		$ret=array();
1531
+		$ret = array();
1532 1532
 
1533
-		$arrayaddress=explode(',',$address);
1533
+		$arrayaddress = explode(',', $address);
1534 1534
 
1535 1535
 		// Boucle sur chaque composant de l'adresse
1536
-		foreach($arrayaddress as $val)
1536
+		foreach ($arrayaddress as $val)
1537 1537
 		{
1538
-			if (preg_match('/^(.*)<(.*)>$/i',trim($val),$regs))
1538
+			if (preg_match('/^(.*)<(.*)>$/i', trim($val), $regs))
1539 1539
 			{
1540 1540
 				$name  = trim($regs[1]);
1541 1541
 				$email = trim($regs[2]);
@@ -1546,7 +1546,7 @@  discard block
 block discarded – undo
1546 1546
 				$email = trim($val);
1547 1547
 			}
1548 1548
 
1549
-			$ret[$email]=empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)?$name:null;
1549
+			$ret[$email] = empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL) ? $name : null;
1550 1550
 		}
1551 1551
 
1552 1552
 		return $ret;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formbarcode.class.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     /**
38 38
      * @var string Error code (or message)
39 39
      */
40
-    public $error='';
40
+    public $error = '';
41 41
 
42 42
 
43 43
     /**
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      *  @param  int		$idForm			Id du formulaire
61 61
      * 	@return	string					HTML select string
62 62
      */
63
-    function setBarcodeEncoder($selected,$barcodelist,$code_id,$idForm='formbarcode')
63
+    function setBarcodeEncoder($selected, $barcodelist, $code_id, $idForm = 'formbarcode')
64 64
     {
65 65
         global $conf, $langs;
66 66
 
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
         }
82 82
 
83 83
         // We check if barcode is already selected by default
84
-        if (((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE == $code_id) ||
85
-        (! empty($conf->societe->enabled) && $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY == $code_id))
84
+        if (((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE == $code_id) ||
85
+        (!empty($conf->societe->enabled) && $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY == $code_id))
86 86
         {
87 87
             $disable = 'disabled';
88 88
         }
@@ -90,24 +90,24 @@  discard block
 block discarded – undo
90 90
         if (!empty($conf->use_javascript_ajax))
91 91
         {
92 92
             $select_encoder = '<form action="'.DOL_URL_ROOT.'/admin/barcode.php" method="POST" id="form'.$idForm.'">';
93
-            $select_encoder.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
94
-            $select_encoder.= '<input type="hidden" name="action" value="update">';
95
-            $select_encoder.= '<input type="hidden" name="code_id" value="'.$code_id.'">';
93
+            $select_encoder .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
94
+            $select_encoder .= '<input type="hidden" name="action" value="update">';
95
+            $select_encoder .= '<input type="hidden" name="code_id" value="'.$code_id.'">';
96 96
         }
97 97
         
98
-        $selectname=(!empty($conf->use_javascript_ajax)?'coder':'coder'.$code_id);
99
-        $select_encoder.= '<select id="select'.$idForm.'" class="flat" name="'.$selectname.'">';
100
-        $select_encoder.= '<option value="0"'.($selected==0?' selected':'').' '.$disable.'>'.$langs->trans('Disable').'</option>';
101
-        $select_encoder.= '<option value="-1" disabled>--------------------</option>';
102
-        foreach($barcodelist as $key => $value)
98
+        $selectname = (!empty($conf->use_javascript_ajax) ? 'coder' : 'coder'.$code_id);
99
+        $select_encoder .= '<select id="select'.$idForm.'" class="flat" name="'.$selectname.'">';
100
+        $select_encoder .= '<option value="0"'.($selected == 0 ? ' selected' : '').' '.$disable.'>'.$langs->trans('Disable').'</option>';
101
+        $select_encoder .= '<option value="-1" disabled>--------------------</option>';
102
+        foreach ($barcodelist as $key => $value)
103 103
         {
104
-            $select_encoder.= '<option value="'.$key.'"'.($selected==$key?' selected':'').'>'.$value.'</option>';
104
+            $select_encoder .= '<option value="'.$key.'"'.($selected == $key ? ' selected' : '').'>'.$value.'</option>';
105 105
         }
106
-        $select_encoder.= '</select>';
106
+        $select_encoder .= '</select>';
107 107
         
108 108
         if (!empty($conf->use_javascript_ajax))
109 109
         {
110
-            $select_encoder.= '</form>';
110
+            $select_encoder .= '</form>';
111 111
         }
112 112
 
113 113
         return $select_encoder;
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
      *  @return void
124 124
      *  @deprecated
125 125
      */
126
-    function select_barcode_type($selected='', $htmlname='barcodetype_id', $useempty=0)
126
+    function select_barcode_type($selected = '', $htmlname = 'barcodetype_id', $useempty = 0)
127 127
     {
128 128
         // phpcs:enable
129 129
         print $this->selectBarcodeType($selected, $htmlname, $useempty);
@@ -137,17 +137,17 @@  discard block
 block discarded – undo
137 137
      *  @param  int     $useempty          Display empty value in select
138 138
      *  @return string
139 139
      */
140
-    function selectBarcodeType($selected='', $htmlname='barcodetype_id', $useempty=0)
140
+    function selectBarcodeType($selected = '', $htmlname = 'barcodetype_id', $useempty = 0)
141 141
     {
142 142
         global $langs, $conf;
143 143
 
144 144
         $out = '';
145 145
 
146 146
         $sql = "SELECT rowid, code, libelle";
147
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
148
-        $sql.= " WHERE coder <> '0'";
149
-        $sql.= " AND entity = ".$conf->entity;
150
-        $sql.= " ORDER BY code";
147
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
148
+        $sql .= " WHERE coder <> '0'";
149
+        $sql .= " AND entity = ".$conf->entity;
150
+        $sql .= " ORDER BY code";
151 151
 
152 152
         $result = $this->db->query($sql);
153 153
         if ($result) {
@@ -155,20 +155,20 @@  discard block
 block discarded – undo
155 155
             $i = 0;
156 156
 
157 157
             if ($useempty && $num > 0) {
158
-                $out .= '<select class="flat minwidth75imp" name="' . $htmlname . '" id="select_' . $htmlname . '">';
158
+                $out .= '<select class="flat minwidth75imp" name="'.$htmlname.'" id="select_'.$htmlname.'">';
159 159
                 $out .= '<option value="0">&nbsp;</option>';
160 160
             } else {
161 161
                 $langs->load("errors");
162
-                $out .= '<select disabled class="flat minwidth75imp" name="' . $htmlname . '" id="select_' . $htmlname . '">';
163
-                $out .= '<option value="0" selected>' . $langs->trans('ErrorNoActivatedBarcode') . '</option>';
162
+                $out .= '<select disabled class="flat minwidth75imp" name="'.$htmlname.'" id="select_'.$htmlname.'">';
163
+                $out .= '<option value="0" selected>'.$langs->trans('ErrorNoActivatedBarcode').'</option>';
164 164
             }
165 165
 
166 166
             while ($i < $num) {
167 167
                 $obj = $this->db->fetch_object($result);
168 168
                 if ($selected == $obj->rowid) {
169
-                    $out .= '<option value="' . $obj->rowid . '" selected>';
169
+                    $out .= '<option value="'.$obj->rowid.'" selected>';
170 170
                 } else {
171
-                    $out .= '<option value="' . $obj->rowid . '">';
171
+                    $out .= '<option value="'.$obj->rowid.'">';
172 172
                 }
173 173
                 $out .= $obj->libelle;
174 174
                 $out .= '</option>';
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      *  @return	void
194 194
      *  @deprecated
195 195
      */
196
-    function form_barcode_type($page, $selected='', $htmlname='barcodetype_id')
196
+    function form_barcode_type($page, $selected = '', $htmlname = 'barcodetype_id')
197 197
     {
198 198
         // phpcs:enable
199 199
         print $this->formBarcodeType($page, $selected, $htmlname);
@@ -207,19 +207,19 @@  discard block
 block discarded – undo
207 207
      *  @param  string      $htmlname       Nom du formulaire select
208 208
      *  @return string
209 209
      */
210
-    function formBarcodeType($page, $selected='', $htmlname='barcodetype_id')
210
+    function formBarcodeType($page, $selected = '', $htmlname = 'barcodetype_id')
211 211
     {
212 212
         global $langs, $conf;
213 213
         $out = '';
214 214
         if ($htmlname != "none") {
215
-            $out .= '<form method="post" action="' . $page . '">';
216
-            $out .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
215
+            $out .= '<form method="post" action="'.$page.'">';
216
+            $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
217 217
             $out .= '<input type="hidden" name="action" value="set'.$htmlname.'">';
218 218
             $out .= '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
219 219
             $out .= '<tr><td>';
220 220
             $out .= $this->selectBarcodeType($selected, $htmlname, 1);
221 221
             $out .= '</td>';
222
-            $out .= '<td align="left"><input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
222
+            $out .= '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'">';
223 223
             $out .= '</td></tr></table></form>';
224 224
         }
225 225
         return $out;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/CSMSFile.class.php 1 patch
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     /**
38 38
 	 * @var string Error code (or message)
39 39
 	 */
40
-	public $error='';
40
+	public $error = '';
41 41
 
42 42
 	public $addr_from;
43 43
 	public $addr_to;
@@ -59,19 +59,19 @@  discard block
 block discarded – undo
59 59
 	 *	@param 	int		$priority			Priority
60 60
 	 *	@param 	int		$class				Class
61 61
 	 */
62
-	function __construct($to,$from,$msg,$deliveryreceipt=0,$deferred=0,$priority=3,$class=1)
62
+	function __construct($to, $from, $msg, $deliveryreceipt = 0, $deferred = 0, $priority = 3, $class = 1)
63 63
 	{
64 64
 		global $conf;
65 65
 
66 66
 		// On definit fin de ligne
67
-		$this->eol="\n";
68
-		if (preg_match('/^win/i',PHP_OS)) $this->eol="\r\n";
69
-		if (preg_match('/^mac/i',PHP_OS)) $this->eol="\r";
67
+		$this->eol = "\n";
68
+		if (preg_match('/^win/i', PHP_OS)) $this->eol = "\r\n";
69
+		if (preg_match('/^mac/i', PHP_OS)) $this->eol = "\r";
70 70
 
71 71
 		// If ending method not defined
72 72
 		if (empty($conf->global->MAIN_SMS_SENDMODE))
73 73
 		{
74
-		    $this->error='No SMS Engine defined';
74
+		    $this->error = 'No SMS Engine defined';
75 75
 		    return -1;
76 76
 		}
77 77
 
@@ -79,13 +79,13 @@  discard block
 block discarded – undo
79 79
 		dol_syslog("CSMSFile::CSMSFile: deferred=".$deferred." priority=".$priority." class=".$class, LOG_DEBUG);
80 80
 
81 81
 		// Action according to choosed sending method
82
-	    $this->addr_from=$from;
83
-	    $this->addr_to=$to;
84
-        $this->deferred=$deferred;
85
-        $this->priority=$priority;
86
-        $this->class=$class;
87
-        $this->message=$msg;
88
-        $this->nostop=false;
82
+	    $this->addr_from = $from;
83
+	    $this->addr_to = $to;
84
+        $this->deferred = $deferred;
85
+        $this->priority = $priority;
86
+        $this->class = $class;
87
+        $this->message = $msg;
88
+        $this->nostop = false;
89 89
 	}
90 90
 
91 91
 
@@ -98,17 +98,17 @@  discard block
 block discarded – undo
98 98
 	{
99 99
 		global $conf;
100 100
 
101
-		$errorlevel=error_reporting();
102
-		error_reporting($errorlevel ^ E_WARNING);   // Desactive warnings
101
+		$errorlevel = error_reporting();
102
+		error_reporting($errorlevel ^ E_WARNING); // Desactive warnings
103 103
 
104
-		$res=false;
104
+		$res = false;
105 105
 
106 106
         dol_syslog("CSMSFile::sendfile addr_to=".$this->addr_to, LOG_DEBUG);
107 107
         dol_syslog("CSMSFile::sendfile message=\n".$this->message);
108 108
 
109
-        $this->message=stripslashes($this->message);
109
+        $this->message = stripslashes($this->message);
110 110
 
111
-        if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms();
111
+        if (!empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms();
112 112
 
113 113
 		if (empty($conf->global->MAIN_DISABLE_ALL_SMS))
114 114
 		{
@@ -117,46 +117,46 @@  discard block
 block discarded – undo
117 117
 		    if ($conf->global->MAIN_SMS_SENDMODE == 'ovh')    // Backward compatibility    @deprecated
118 118
 			{
119 119
 				dol_include_once('/ovh/class/ovhsms.class.php');
120
-				$sms=new OvhSms($this->db);
121
-				$sms->expe=$this->addr_from;
122
-				$sms->dest=$this->addr_to;
123
-				$sms->message=$this->message;
124
-				$sms->deferred=$this->deferred;
125
-				$sms->priority=$this->priority;
126
-                $sms->class=$this->class;
127
-                $sms->nostop=$this->nostop;
128
-
129
-                $res=$sms->SmsSend();
120
+				$sms = new OvhSms($this->db);
121
+				$sms->expe = $this->addr_from;
122
+				$sms->dest = $this->addr_to;
123
+				$sms->message = $this->message;
124
+				$sms->deferred = $this->deferred;
125
+				$sms->priority = $this->priority;
126
+                $sms->class = $this->class;
127
+                $sms->nostop = $this->nostop;
128
+
129
+                $res = $sms->SmsSend();
130 130
 				if ($res <= 0)
131 131
 				{
132
-					$this->error=$sms->error;
132
+					$this->error = $sms->error;
133 133
 					dol_syslog("CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR);
134 134
 				}
135 135
 				else
136 136
 				{
137 137
 					dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG);
138 138
 					//var_dump($res);        // 1973128
139
-					if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res);
139
+					if (!empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res);
140 140
 				}
141 141
 			}
142
-		    else if (! empty($conf->global->MAIN_SMS_SENDMODE))    // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
142
+		    else if (!empty($conf->global->MAIN_SMS_SENDMODE))    // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
143 143
 		    {
144
-		        $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE);
145
-		        $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]);
144
+		        $tmp = explode('@', $conf->global->MAIN_SMS_SENDMODE);
145
+		        $classfile = $tmp[0]; $module = (empty($tmp[1]) ? $tmp[0] : $tmp[1]);
146 146
 		        dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
147 147
 		        try
148 148
 		        {
149
-		            $classname=ucfirst($classfile);
149
+		            $classname = ucfirst($classfile);
150 150
 		            $sms = new $classname($this->db);
151
-		            $sms->expe=$this->addr_from;
152
-		            $sms->dest=$this->addr_to;
153
-		            $sms->deferred=$this->deferred;
154
-		            $sms->priority=$this->priority;
155
-		            $sms->class=$this->class;
156
-		            $sms->message=$this->message;
157
-		            $sms->nostop=$this->nostop;
158
-
159
-                    $res=$sms->SmsSend();
151
+		            $sms->expe = $this->addr_from;
152
+		            $sms->dest = $this->addr_to;
153
+		            $sms->deferred = $this->deferred;
154
+		            $sms->priority = $this->priority;
155
+		            $sms->class = $this->class;
156
+		            $sms->message = $this->message;
157
+		            $sms->nostop = $this->nostop;
158
+
159
+                    $res = $sms->SmsSend();
160 160
                     $this->error = $sms->error;
161 161
                     $this->errors = $sms->errors;
162 162
     				if ($res <= 0)
@@ -167,12 +167,12 @@  discard block
 block discarded – undo
167 167
     				{
168 168
     					dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG);
169 169
     					//var_dump($res);        // 1973128
170
-    					if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res);
170
+    					if (!empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res);
171 171
     				}
172 172
 		        }
173
-		        catch(Exception $e)
173
+		        catch (Exception $e)
174 174
 		        {
175
-		            dol_print_error('','Error to get list of senders: '.$e->getMessage());
175
+		            dol_print_error('', 'Error to get list of senders: '.$e->getMessage());
176 176
 		        }
177 177
 		    }
178 178
 			else
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
 		}
186 186
 		else
187 187
 		{
188
-			$this->error='No sms sent. Feature is disabled by option MAIN_DISABLE_ALL_SMS';
188
+			$this->error = 'No sms sent. Feature is disabled by option MAIN_DISABLE_ALL_SMS';
189 189
 			dol_syslog("CSMSFile::sendfile: ".$this->error, LOG_WARNING);
190 190
 		}
191 191
 
192
-		error_reporting($errorlevel);              // Reactive niveau erreur origine
192
+		error_reporting($errorlevel); // Reactive niveau erreur origine
193 193
 
194 194
 		return $res;
195 195
 	}
@@ -205,12 +205,12 @@  discard block
 block discarded – undo
205 205
 	function dump_sms()
206 206
 	{
207 207
         // phpcs:enable
208
-		global $conf,$dolibarr_main_data_root;
208
+		global $conf, $dolibarr_main_data_root;
209 209
 
210 210
 		if (@is_writeable($dolibarr_main_data_root))	// Avoid fatal error on fopen with open_basedir
211 211
 		{
212
-			$outputfile=$dolibarr_main_data_root."/dolibarr_sms.log";
213
-			$fp = fopen($outputfile,"w");
212
+			$outputfile = $dolibarr_main_data_root."/dolibarr_sms.log";
213
+			$fp = fopen($outputfile, "w");
214 214
 
215 215
 			fputs($fp, "From: ".$this->addr_from."\n");
216 216
 			fputs($fp, "To: ".$this->addr_to."\n");
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 			fputs($fp, "Message:\n".$this->message);
222 222
 
223 223
 			fclose($fp);
224
-			if (! empty($conf->global->MAIN_UMASK))
224
+			if (!empty($conf->global->MAIN_UMASK))
225 225
 			@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
226 226
 		}
227 227
 	}
@@ -237,17 +237,17 @@  discard block
 block discarded – undo
237 237
     function dump_sms_result($result)
238 238
     {
239 239
         // phpcs:enable
240
-        global $conf,$dolibarr_main_data_root;
240
+        global $conf, $dolibarr_main_data_root;
241 241
 
242 242
         if (@is_writeable($dolibarr_main_data_root))    // Avoid fatal error on fopen with open_basedir
243 243
         {
244
-        	$outputfile=$dolibarr_main_data_root."/dolibarr_sms.log";
245
-            $fp = fopen($outputfile,"a+");
244
+        	$outputfile = $dolibarr_main_data_root."/dolibarr_sms.log";
245
+            $fp = fopen($outputfile, "a+");
246 246
 
247 247
             fputs($fp, "\nResult id=".$result);
248 248
 
249 249
             fclose($fp);
250
-            if (! empty($conf->global->MAIN_UMASK))
250
+            if (!empty($conf->global->MAIN_UMASK))
251 251
             @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
252 252
         }
253 253
     }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/fileupload.class.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -41,16 +41,16 @@  discard block
 block discarded – undo
41 41
 	 * @param int		$fk_element		fk_element
42 42
 	 * @param string	$element		element
43 43
 	 */
44
-	function __construct($options=null,$fk_element=null,$element=null)
44
+	function __construct($options = null, $fk_element = null, $element = null)
45 45
 	{
46 46
 		global $db, $conf;
47 47
 		global $object;
48 48
 
49
-		$this->fk_element=$fk_element;
50
-		$this->element=$element;
49
+		$this->fk_element = $fk_element;
50
+		$this->element = $element;
51 51
 
52
-		$pathname=$filename=$element;
53
-		if (preg_match('/^([^_]+)_([^_]+)/i',$element,$regs))
52
+		$pathname = $filename = $element;
53
+		if (preg_match('/^([^_]+)_([^_]+)/i', $element, $regs))
54 54
 		{
55 55
 			$pathname = $regs[1];
56 56
 			$filename = $regs[2];
@@ -61,35 +61,35 @@  discard block
 block discarded – undo
61 61
 		// For compatibility
62 62
 		if ($element == 'propal') {
63 63
 			$pathname = 'comm/propal';
64
-			$dir_output=$conf->$element->dir_output;
64
+			$dir_output = $conf->$element->dir_output;
65 65
 		}
66 66
 		elseif ($element == 'facture') {
67 67
 			$pathname = 'compta/facture';
68
-			$dir_output=$conf->$element->dir_output;
68
+			$dir_output = $conf->$element->dir_output;
69 69
 		}
70 70
 		elseif ($element == 'project') {
71 71
 			$element = $pathname = 'projet';
72
-			$dir_output=$conf->$element->dir_output;
72
+			$dir_output = $conf->$element->dir_output;
73 73
 		}
74 74
 		elseif ($element == 'project_task') {
75
-			$pathname = 'projet'; $filename='task';
76
-			$dir_output=$conf->projet->dir_output;
75
+			$pathname = 'projet'; $filename = 'task';
76
+			$dir_output = $conf->projet->dir_output;
77 77
 			$parentForeignKey = 'fk_project';
78 78
 			$parentClass = 'Project';
79 79
 			$parentElement = 'projet';
80 80
 			$parentObject = 'project';
81 81
 		}
82 82
 		elseif ($element == 'fichinter') {
83
-			$element='ficheinter';
84
-			$dir_output=$conf->$element->dir_output;
83
+			$element = 'ficheinter';
84
+			$dir_output = $conf->$element->dir_output;
85 85
 		}
86 86
 		elseif ($element == 'order_supplier') {
87
-			$pathname = 'fourn'; $filename='fournisseur.commande';
88
-			$dir_output=$conf->fournisseur->commande->dir_output;
87
+			$pathname = 'fourn'; $filename = 'fournisseur.commande';
88
+			$dir_output = $conf->fournisseur->commande->dir_output;
89 89
 		}
90 90
 		elseif ($element == 'invoice_supplier') {
91
-			$pathname = 'fourn'; $filename='fournisseur.facture';
92
-			$dir_output=$conf->fournisseur->facture->dir_output;
91
+			$pathname = 'fourn'; $filename = 'fournisseur.facture';
92
+			$dir_output = $conf->fournisseur->facture->dir_output;
93 93
 		}
94 94
 		elseif ($element == 'product') {
95 95
 			$dir_output = $conf->product->multidir_output[$conf->entity];
@@ -98,14 +98,14 @@  discard block
 block discarded – undo
98 98
 			$dir_output = $conf->productbatch->multidir_output[$conf->entity];
99 99
 		}
100 100
 		elseif ($element == 'action') {
101
-			$pathname = 'comm/action'; $filename='actioncomm';
102
-			$dir_output=$conf->agenda->dir_output;
101
+			$pathname = 'comm/action'; $filename = 'actioncomm';
102
+			$dir_output = $conf->agenda->dir_output;
103 103
 		}
104 104
 		elseif ($element == 'chargesociales') {
105
-			$pathname = 'compta/sociales'; $filename='chargesociales';
106
-			$dir_output=$conf->tax->dir_output;
105
+			$pathname = 'compta/sociales'; $filename = 'chargesociales';
106
+			$dir_output = $conf->tax->dir_output;
107 107
 		} else {
108
-			$dir_output=$conf->$element->dir_output;
108
+			$dir_output = $conf->$element->dir_output;
109 109
 		}
110 110
 
111 111
 		dol_include_once('/'.$pathname.'/class/'.$filename.'.class.php');
@@ -135,14 +135,14 @@  discard block
 block discarded – undo
135 135
 
136 136
 		$object_ref = dol_sanitizeFileName($object->ref);
137 137
 		if ($element == 'invoice_supplier') {
138
-			$object_ref = get_exdir($object->id,2,0,0,$object,'invoice_supplier') . $object_ref;
138
+			$object_ref = get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$object_ref;
139 139
 		} else if ($element == 'project_task') {
140
-			$object_ref = $object->project->ref . '/' . $object_ref;
140
+			$object_ref = $object->project->ref.'/'.$object_ref;
141 141
 		}
142 142
 
143 143
 		$this->options = array(
144 144
 				'script_url' => $_SERVER['PHP_SELF'],
145
-				'upload_dir' => $dir_output . '/' . $object_ref . '/',
145
+				'upload_dir' => $dir_output.'/'.$object_ref.'/',
146 146
 				'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object_ref.'/',
147 147
 				'param_name' => 'files',
148 148
 				// Set the following option to 'POST', if your server does not support
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 		),
177 177
 		*/
178 178
 						'thumbnail' => array(
179
-								'upload_dir' => $dir_output . '/' . $object_ref . '/thumbs/',
179
+								'upload_dir' => $dir_output.'/'.$object_ref.'/thumbs/',
180 180
 								'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object_ref.'/thumbs/',
181 181
 								'max_width' => 80,
182 182
 								'max_height' => 80
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 		(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ($_SERVER['SERVER_NAME'].
203 203
 				($https && $_SERVER['SERVER_PORT'] === 443 ||
204 204
 						$_SERVER['SERVER_PORT'] === 80 ? '' : ':'.$_SERVER['SERVER_PORT']))).
205
-						substr($_SERVER['SCRIPT_NAME'],0, strrpos($_SERVER['SCRIPT_NAME'], '/'));
205
+						substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/'));
206 206
 	}
207 207
 
208 208
 	/**
@@ -234,12 +234,12 @@  discard block
 block discarded – undo
234 234
 		{
235 235
 			$file = new stdClass();
236 236
 			$file->name = $file_name;
237
-			$file->mime = dol_mimetype($file_name,'',2);
237
+			$file->mime = dol_mimetype($file_name, '', 2);
238 238
 			$file->size = filesize($file_path);
239 239
 			$file->url = $this->options['upload_url'].rawurlencode($file->name);
240
-			foreach($this->options['image_versions'] as $version => $options) {
240
+			foreach ($this->options['image_versions'] as $version => $options) {
241 241
 				if (is_file($options['upload_dir'].$file_name)) {
242
-					$tmp=explode('.',$file->name);
242
+					$tmp = explode('.', $file->name);
243 243
 					$file->{$version.'_url'} = $options['upload_url'].rawurlencode($tmp[0].'_mini.'.$tmp[1]);
244 244
 				}
245 245
 			}
@@ -280,9 +280,9 @@  discard block
 block discarded – undo
280 280
 				return false;
281 281
 			}
282 282
 
283
-			$res=vignette($file_path,$maxwidthmini,$maxheightmini,'_mini');  // We don't use ->addThumbs here because there is no object and we don't need all thumbs, only the "mini".
283
+			$res = vignette($file_path, $maxwidthmini, $maxheightmini, '_mini'); // We don't use ->addThumbs here because there is no object and we don't need all thumbs, only the "mini".
284 284
 
285
-			if (preg_match('/error/i',$res)) return false;
285
+			if (preg_match('/error/i', $res)) return false;
286 286
 			return true;
287 287
 		}
288 288
 		else
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 		}
399 399
 		if ($this->options['discard_aborted_uploads'])
400 400
 		{
401
-			while(is_file($this->options['upload_dir'].$file_name))
401
+			while (is_file($this->options['upload_dir'].$file_name))
402 402
 			{
403 403
 				$file_name = $this->upcountName($file_name);
404 404
 			}
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 	{
422 422
 		$file = new stdClass();
423 423
 		$file->name = $this->trimFileName($name, $type, $index);
424
-		$file->mime = dol_mimetype($file->name,'',2);
424
+		$file->mime = dol_mimetype($file->name, '', 2);
425 425
 		$file->size = intval($size);
426 426
 		$file->type = $type;
427 427
 		if ($this->validate($uploaded_file, $file, $error, $index) && dol_mkdir($this->options['upload_dir']) >= 0)
@@ -447,11 +447,11 @@  discard block
 block discarded – undo
447 447
 			if ($file_size === $file->size)
448 448
 			{
449 449
 				$file->url = $this->options['upload_url'].rawurlencode($file->name);
450
-				foreach($this->options['image_versions'] as $version => $options)
450
+				foreach ($this->options['image_versions'] as $version => $options)
451 451
 				{
452 452
 					if ($this->createScaledImage($file->name, $options))
453 453
 					{
454
-						$tmp=explode('.',$file->name);
454
+						$tmp = explode('.', $file->name);
455 455
 						$file->{$version.'_url'} = $options['upload_url'].rawurlencode($tmp[0].'_mini.'.$tmp[1]);
456 456
 					}
457 457
 				}
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
 		$success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path);
559 559
 		if ($success)
560 560
 		{
561
-			foreach($this->options['image_versions'] as $version => $options)
561
+			foreach ($this->options['image_versions'] as $version => $options)
562 562
 			{
563 563
 				$file = $options['upload_dir'].$file_name;
564 564
 				if (is_file($file))
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/commonorder.class.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@
 block discarded – undo
21 21
  *       \brief      File of the superclass of orders classes (customer and supplier)
22 22
  */
23 23
 
24
-require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
25
-require_once DOL_DOCUMENT_ROOT .'/core/class/commonobjectline.class.php';
24
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
25
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
26 26
 
27 27
 /**
28 28
  *      Superclass for orders classes
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formprojet.class.php 1 patch
Spacing   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	/**
38 38
 	 * @var string Error code (or message)
39 39
 	 */
40
-	public $error='';
40
+	public $error = '';
41 41
 
42 42
 
43 43
 	/**
@@ -71,43 +71,43 @@  discard block
 block discarded – undo
71 71
 	 *	@param  int     $htmlid         Html id to use instead of htmlname
72 72
 	 *	@return string           		Return html content
73 73
 	 */
74
-	function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=16, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode = 0, $filterkey = '', $nooutput=0, $forceaddid=0, $morecss='', $htmlid='')
74
+	function select_projects($socid = -1, $selected = '', $htmlname = 'projectid', $maxlength = 16, $option_only = 0, $show_empty = 1, $discard_closed = 0, $forcefocus = 0, $disabled = 0, $mode = 0, $filterkey = '', $nooutput = 0, $forceaddid = 0, $morecss = '', $htmlid = '')
75 75
 	{
76 76
         // phpcs:enable
77
-		global $langs,$conf,$form;
77
+		global $langs, $conf, $form;
78 78
 
79
-		$out='';
79
+		$out = '';
80 80
 
81
-		if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT))
81
+		if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT))
82 82
 		{
83
-			$placeholder='';
83
+			$placeholder = '';
84 84
 
85 85
 			if ($selected && empty($selected_input_value))
86 86
 			{
87 87
 				require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
88 88
 				$project = new Project($this->db);
89 89
 				$project->fetch($selected);
90
-				$selected_input_value=$project->ref;
90
+				$selected_input_value = $project->ref;
91 91
 			}
92
-			$urloption='socid='.$socid.'&htmlname='.$htmlname.'&discardclosed='.$discard_closed;
93
-			$out.=ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array(
92
+			$urloption = 'socid='.$socid.'&htmlname='.$htmlname.'&discardclosed='.$discard_closed;
93
+			$out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array(
94 94
 //				'update' => array(
95 95
 //					'projectid' => 'id'
96 96
 //				)
97 97
 			));
98 98
 
99
-			$out.='<input type="text" class="minwidth200'.($morecss?' '.$morecss:'').'" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' />';
99
+			$out .= '<input type="text" class="minwidth200'.($morecss ? ' '.$morecss : '').'" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' />';
100 100
 		}
101 101
 		else
102 102
 		{
103
-			$out.=$this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, $discard_closed, $forcefocus, $disabled, 0, $filterkey, 1, $forceaddid, $htmlid, $morecss);
103
+			$out .= $this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, $discard_closed, $forcefocus, $disabled, 0, $filterkey, 1, $forceaddid, $htmlid, $morecss);
104 104
 		}
105 105
 		if ($discard_closed)
106 106
 		{
107 107
 			if (class_exists('Form'))
108 108
 			{
109
-				if (empty($form)) $form=new Form($this->db);
110
-				$out.=$form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
109
+				if (empty($form)) $form = new Form($this->db);
110
+				$out .= $form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
111 111
 			}
112 112
 		}
113 113
 
@@ -140,62 +140,62 @@  discard block
 block discarded – undo
140 140
 	 * @param  string  $morecss            More CSS
141 141
 	 * @return int         			       Nb of project if OK, <0 if KO
142 142
 	 */
143
-	function select_projects_list($socid=-1, $selected='', $htmlname='projectid', $maxlength=24, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode=0, $filterkey = '', $nooutput=0, $forceaddid=0, $htmlid='', $morecss='maxwidth500')
143
+	function select_projects_list($socid = -1, $selected = '', $htmlname = 'projectid', $maxlength = 24, $option_only = 0, $show_empty = 1, $discard_closed = 0, $forcefocus = 0, $disabled = 0, $mode = 0, $filterkey = '', $nooutput = 0, $forceaddid = 0, $htmlid = '', $morecss = 'maxwidth500')
144 144
 	{
145 145
         // phpcs:enable
146
-		global $user,$conf,$langs;
146
+		global $user, $conf, $langs;
147 147
 
148 148
 		require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
149 149
 
150 150
 		if (empty($htmlid)) $htmlid = $htmlname;
151 151
 
152
-		$out='';
153
-		$outarray=array();
152
+		$out = '';
153
+		$outarray = array();
154 154
 
155 155
 		$hideunselectables = false;
156
-		if (! empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) $hideunselectables = true;
156
+		if (!empty($conf->global->CONTRACT_HIDE_UNSELECTABLES)) $hideunselectables = true;
157 157
 
158 158
 		$projectsListId = false;
159 159
 		if (empty($user->rights->projet->all->lire))
160 160
 		{
161
-			$projectstatic=new Project($this->db);
162
-			$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1);
161
+			$projectstatic = new Project($this->db);
162
+			$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
163 163
 		}
164 164
 
165 165
 		// Search all projects
166 166
 		$sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name, s.name_alias';
167
-		$sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p LEFT JOIN '.MAIN_DB_PREFIX .'societe as s ON s.rowid = p.fk_soc';
168
-		$sql.= " WHERE p.entity IN (".getEntity('project').")";
169
-		if ($projectsListId !== false) $sql.= " AND p.rowid IN (".$projectsListId.")";
170
-		if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
167
+		$sql .= ' FROM '.MAIN_DB_PREFIX.'projet as p LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc';
168
+		$sql .= " WHERE p.entity IN (".getEntity('project').")";
169
+		if ($projectsListId !== false) $sql .= " AND p.rowid IN (".$projectsListId.")";
170
+		if ($socid == 0) $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
171 171
 		if ($socid > 0)
172 172
 		{
173
-		    if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY))  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
173
+		    if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY))  $sql .= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
174 174
 		    else if ($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY != 'all')    // PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
175 175
 		    {
176
-		        $sql.= " AND (p.fk_soc IN (".$socid.", ".$conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") OR p.fk_soc IS NULL)";
176
+		        $sql .= " AND (p.fk_soc IN (".$socid.", ".$conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY.") OR p.fk_soc IS NULL)";
177 177
 		    }
178 178
 		}
179 179
 		if (!empty($filterkey)) $sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
180
-		$sql.= " ORDER BY p.ref ASC";
180
+		$sql .= " ORDER BY p.ref ASC";
181 181
 
182
-		$resql=$this->db->query($sql);
182
+		$resql = $this->db->query($sql);
183 183
 		if ($resql)
184 184
 		{
185 185
 			// Use select2 selector
186
-			if (! empty($conf->use_javascript_ajax))
186
+			if (!empty($conf->use_javascript_ajax))
187 187
 			{
188
-				include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
188
+				include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
189 189
 	           	$comboenhancement = ajax_combobox($htmlid, array(), 0, $forcefocus);
190
-            	$out.=$comboenhancement;
191
-            	$morecss.=' minwidth100';
190
+            	$out .= $comboenhancement;
191
+            	$morecss .= ' minwidth100';
192 192
 			}
193 193
 
194 194
 			if (empty($option_only)) {
195
-				$out.= '<select class="flat'.($morecss?' '.$morecss:'').'"'.($disabled?' disabled="disabled"':'').' id="'.$htmlid.'" name="'.$htmlname.'">';
195
+				$out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'"'.($disabled ? ' disabled="disabled"' : '').' id="'.$htmlid.'" name="'.$htmlname.'">';
196 196
 			}
197 197
 			if (!empty($show_empty)) {
198
-				$out.= '<option value="0">&nbsp;</option>';
198
+				$out .= '<option value="0">&nbsp;</option>';
199 199
 			}
200 200
 			$num = $this->db->num_rows($resql);
201 201
 			$i = 0;
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 				{
206 206
 					$obj = $this->db->fetch_object($resql);
207 207
 					// If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
208
-					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
208
+					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->rights->societe->lire)
209 209
 					{
210 210
 						// Do nothing
211 211
 					}
@@ -217,56 +217,56 @@  discard block
 block discarded – undo
217 217
 							continue;
218 218
 						}
219 219
 
220
-						$labeltoshow=dol_trunc($obj->ref,18);
220
+						$labeltoshow = dol_trunc($obj->ref, 18);
221 221
 						//if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
222 222
 						//else $labeltoshow.=' ('.$langs->trans("Private").')';
223
-						$labeltoshow.=', '.dol_trunc($obj->title, $maxlength);
223
+						$labeltoshow .= ', '.dol_trunc($obj->title, $maxlength);
224 224
 						if ($obj->name)
225 225
 						{
226
-						    $labeltoshow.=' - '.$obj->name;
227
-						    if ($obj->name_alias) $labeltoshow.=' ('.$obj->name_alias.')';
226
+						    $labeltoshow .= ' - '.$obj->name;
227
+						    if ($obj->name_alias) $labeltoshow .= ' ('.$obj->name_alias.')';
228 228
 						}
229 229
 
230
-						$disabled=0;
230
+						$disabled = 0;
231 231
 						if ($obj->fk_statut == 0)
232 232
 						{
233
-							$disabled=1;
234
-							$labeltoshow.=' - '.$langs->trans("Draft");
233
+							$disabled = 1;
234
+							$labeltoshow .= ' - '.$langs->trans("Draft");
235 235
 						}
236 236
 						else if ($obj->fk_statut == 2)
237 237
 						{
238
-							if ($discard_closed == 2) $disabled=1;
239
-							$labeltoshow.=' - '.$langs->trans("Closed");
238
+							if ($discard_closed == 2) $disabled = 1;
239
+							$labeltoshow .= ' - '.$langs->trans("Closed");
240 240
 						}
241
-						else if ( empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) &&  $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
241
+						else if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid))
242 242
 						{
243
-							$disabled=1;
244
-							$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
243
+							$disabled = 1;
244
+							$labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
245 245
 						}
246 246
 
247 247
 						if (!empty($selected) && $selected == $obj->rowid)
248 248
 						{
249
-							$out.= '<option value="'.$obj->rowid.'" selected';
249
+							$out .= '<option value="'.$obj->rowid.'" selected';
250 250
 							//if ($disabled) $out.=' disabled';						// with select2, field can't be preselected if disabled
251
-							$out.= '>'.$labeltoshow.'</option>';
251
+							$out .= '>'.$labeltoshow.'</option>';
252 252
 						}
253 253
 						else
254 254
 						{
255 255
 							if ($hideunselectables && $disabled && ($selected != $obj->rowid))
256 256
 							{
257
-								$resultat='';
257
+								$resultat = '';
258 258
 							}
259 259
 							else
260 260
 							{
261
-								$resultat='<option value="'.$obj->rowid.'"';
262
-								if ($disabled) $resultat.=' disabled';
261
+								$resultat = '<option value="'.$obj->rowid.'"';
262
+								if ($disabled) $resultat .= ' disabled';
263 263
 								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
264 264
 								//else $labeltoshow.=' ('.$langs->trans("Private").')';
265
-								$resultat.='>';
266
-								$resultat.=$labeltoshow;
267
-								$resultat.='</option>';
265
+								$resultat .= '>';
266
+								$resultat .= $labeltoshow;
267
+								$resultat .= '</option>';
268 268
 							}
269
-							$out.= $resultat;
269
+							$out .= $resultat;
270 270
 
271 271
 							$outarray[] = array(
272 272
 								'key' => (int) $obj->rowid,
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 			$this->db->free($resql);
285 285
 
286 286
 			if (!$mode) {
287
-				if (empty($option_only)) $out.= '</select>';
287
+				if (empty($option_only)) $out .= '</select>';
288 288
 				if (empty($nooutput))
289 289
 				{
290 290
 				    print $out;
@@ -320,9 +320,9 @@  discard block
 block discarded – undo
320 320
 	 *  @param	User	$usertofilter	User object to use for filtering
321 321
 	 *	@return int         			Nbr of project if OK, <0 if KO
322 322
 	 */
323
-	function selectTasks($socid=-1, $selected='', $htmlname='taskid', $maxlength=24, $option_only=0, $show_empty='1', $discard_closed=0, $forcefocus=0, $disabled=0, $morecss='maxwidth500', $projectsListId='', $showproject='all', $usertofilter=null)
323
+	function selectTasks($socid = -1, $selected = '', $htmlname = 'taskid', $maxlength = 24, $option_only = 0, $show_empty = '1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500', $projectsListId = '', $showproject = 'all', $usertofilter = null)
324 324
 	{
325
-		global $user,$conf,$langs;
325
+		global $user, $conf, $langs;
326 326
 
327 327
 		require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
328 328
 
@@ -331,53 +331,53 @@  discard block
 block discarded – undo
331 331
 			$usertofilter = $user;
332 332
 		}
333 333
 
334
-		$out='';
334
+		$out = '';
335 335
 
336 336
 		$hideunselectables = false;
337
-		if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
337
+		if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
338 338
 
339 339
 		if (empty($projectsListId))
340 340
 		{
341 341
 			if (empty($usertofilter->rights->projet->all->lire))
342 342
 			{
343
-				$projectstatic=new Project($this->db);
344
-				$projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter,0,1);
343
+				$projectstatic = new Project($this->db);
344
+				$projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
345 345
 			}
346 346
 		}
347 347
 
348 348
 		// Search all projects
349 349
 		$sql = 'SELECT t.rowid, t.ref as tref, t.label as tlabel, p.rowid as pid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public,';
350
-		$sql.= ' s.nom as name';
351
-		$sql.= ' FROM '.MAIN_DB_PREFIX .'projet as p';
352
-		$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc,';
353
-		$sql.= ' '.MAIN_DB_PREFIX.'projet_task as t';
354
-		$sql.= " WHERE p.entity IN (".getEntity('project').")";
355
-		$sql.= " AND t.fk_projet = p.rowid";
356
-		if ($projectsListId) $sql.= " AND p.rowid IN (".$projectsListId.")";
357
-		if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
358
-		if ($socid > 0)  $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
359
-		$sql.= " ORDER BY p.ref, t.ref ASC";
360
-
361
-		$resql=$this->db->query($sql);
350
+		$sql .= ' s.nom as name';
351
+		$sql .= ' FROM '.MAIN_DB_PREFIX.'projet as p';
352
+		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc,';
353
+		$sql .= ' '.MAIN_DB_PREFIX.'projet_task as t';
354
+		$sql .= " WHERE p.entity IN (".getEntity('project').")";
355
+		$sql .= " AND t.fk_projet = p.rowid";
356
+		if ($projectsListId) $sql .= " AND p.rowid IN (".$projectsListId.")";
357
+		if ($socid == 0) $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
358
+		if ($socid > 0)  $sql .= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)";
359
+		$sql .= " ORDER BY p.ref, t.ref ASC";
360
+
361
+		$resql = $this->db->query($sql);
362 362
 		if ($resql)
363 363
 		{
364 364
 			// Use select2 selector
365
-			if (! empty($conf->use_javascript_ajax))
365
+			if (!empty($conf->use_javascript_ajax))
366 366
 			{
367
-				include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
367
+				include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
368 368
 	           	$comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus);
369
-            	$out.=$comboenhancement;
370
-            	$morecss='minwidth200 maxwidth500';
369
+            	$out .= $comboenhancement;
370
+            	$morecss = 'minwidth200 maxwidth500';
371 371
 			}
372 372
 
373 373
 			if (empty($option_only)) {
374
-				$out.= '<select class="valignmiddle flat'.($morecss?' '.$morecss:'').'"'.($disabled?' disabled="disabled"':'').' id="'.$htmlname.'" name="'.$htmlname.'">';
374
+				$out .= '<select class="valignmiddle flat'.($morecss ? ' '.$morecss : '').'"'.($disabled ? ' disabled="disabled"' : '').' id="'.$htmlname.'" name="'.$htmlname.'">';
375 375
 			}
376
-			if (! empty($show_empty)) {
377
-				$out.= '<option value="0" class="optiongrey">';
378
-				if (! is_numeric($show_empty)) $out.=$show_empty;
379
-				else $out.='&nbsp;';
380
-				$out.= '</option>';
376
+			if (!empty($show_empty)) {
377
+				$out .= '<option value="0" class="optiongrey">';
378
+				if (!is_numeric($show_empty)) $out .= $show_empty;
379
+				else $out .= '&nbsp;';
380
+				$out .= '</option>';
381 381
 			}
382 382
 			$num = $this->db->num_rows($resql);
383 383
 			$i = 0;
@@ -403,65 +403,65 @@  discard block
 block discarded – undo
403 403
 
404 404
 						if ($showproject == 'all')
405 405
 						{
406
-							$labeltoshow.=dol_trunc($obj->ref,18);     // Project ref
406
+							$labeltoshow .= dol_trunc($obj->ref, 18); // Project ref
407 407
 							//if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
408 408
 							//else $labeltoshow.=' ('.$langs->trans("Private").')';
409
-							$labeltoshow.=' '.dol_trunc($obj->title,$maxlength);
409
+							$labeltoshow .= ' '.dol_trunc($obj->title, $maxlength);
410 410
 
411
-							if ($obj->name) $labeltoshow.=' ('.$obj->name.')';
411
+							if ($obj->name) $labeltoshow .= ' ('.$obj->name.')';
412 412
 
413
-							$disabled=0;
413
+							$disabled = 0;
414 414
 							if ($obj->fk_statut == Project::STATUS_DRAFT)
415 415
 							{
416
-								$disabled=1;
417
-								$labeltoshow.=' - '.$langs->trans("Draft");
416
+								$disabled = 1;
417
+								$labeltoshow .= ' - '.$langs->trans("Draft");
418 418
 							}
419 419
 							else if ($obj->fk_statut == Project::STATUS_CLOSED)
420 420
 							{
421
-								if ($discard_closed == 2) $disabled=1;
422
-								$labeltoshow.=' - '.$langs->trans("Closed");
421
+								if ($discard_closed == 2) $disabled = 1;
422
+								$labeltoshow .= ' - '.$langs->trans("Closed");
423 423
 							}
424
-							else if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
424
+							else if ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid))
425 425
 							{
426
-								$disabled=1;
427
-								$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
426
+								$disabled = 1;
427
+								$labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
428 428
 							}
429
-							$labeltoshow.=' - ';
429
+							$labeltoshow .= ' - ';
430 430
 						}
431 431
 
432 432
 						// Label for task
433
-						$labeltoshow.=$obj->tref.' '.dol_trunc($obj->tlabel,$maxlength);
433
+						$labeltoshow .= $obj->tref.' '.dol_trunc($obj->tlabel, $maxlength);
434 434
 
435 435
 						if (!empty($selected) && $selected == $obj->rowid)
436 436
 						{
437
-							$out.= '<option value="'.$obj->rowid.'" selected';
437
+							$out .= '<option value="'.$obj->rowid.'" selected';
438 438
 							//if ($disabled) $out.=' disabled';						// with select2, field can't be preselected if disabled
439
-							$out.= '>'.$labeltoshow.'</option>';
439
+							$out .= '>'.$labeltoshow.'</option>';
440 440
 						}
441 441
 						else
442 442
 						{
443 443
 							if ($hideunselectables && $disabled && ($selected != $obj->rowid))
444 444
 							{
445
-								$resultat='';
445
+								$resultat = '';
446 446
 							}
447 447
 							else
448 448
 							{
449
-								$resultat='<option value="'.$obj->rowid.'"';
450
-								if ($disabled) $resultat.=' disabled';
449
+								$resultat = '<option value="'.$obj->rowid.'"';
450
+								if ($disabled) $resultat .= ' disabled';
451 451
 								//if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
452 452
 								//else $labeltoshow.=' ('.$langs->trans("Private").')';
453
-								$resultat.='>';
454
-								$resultat.=$labeltoshow;
455
-								$resultat.='</option>';
453
+								$resultat .= '>';
454
+								$resultat .= $labeltoshow;
455
+								$resultat .= '</option>';
456 456
 							}
457
-							$out.= $resultat;
457
+							$out .= $resultat;
458 458
 						}
459 459
 					}
460 460
 					$i++;
461 461
 				}
462 462
 			}
463 463
 			if (empty($option_only)) {
464
-				$out.= '</select>';
464
+				$out .= '</select>';
465 465
 			}
466 466
 
467 467
 			print $out;
@@ -488,17 +488,17 @@  discard block
 block discarded – undo
488 488
 	 *    @param	string		$projectkey			Equivalent key  to fk_projet for actual table_element
489 489
 	 *    @return	int|string						The HTML select list of element or '' if nothing or -1 if KO
490 490
 	 */
491
-	function select_element($table_element, $socid=0, $morecss='', $limitonstatus=-2,$projectkey="fk_projet")
491
+	function select_element($table_element, $socid = 0, $morecss = '', $limitonstatus = -2, $projectkey = "fk_projet")
492 492
 	{
493 493
         // phpcs:enable
494 494
 		global $conf, $langs;
495 495
 
496
-		if ($table_element == 'projet_task') return '';		// Special cas of element we never link to a project (already always done)
496
+		if ($table_element == 'projet_task') return ''; // Special cas of element we never link to a project (already always done)
497 497
 
498
-		$linkedtothirdparty=false;
499
-		if (! in_array($table_element, array('don','expensereport_det','expensereport','loan','stock_mouvement','payment_salary','payment_various','chargesociales'))) $linkedtothirdparty=true;
498
+		$linkedtothirdparty = false;
499
+		if (!in_array($table_element, array('don', 'expensereport_det', 'expensereport', 'loan', 'stock_mouvement', 'payment_salary', 'payment_various', 'chargesociales'))) $linkedtothirdparty = true;
500 500
 
501
-		$sqlfilter='';
501
+		$sqlfilter = '';
502 502
 
503 503
 		//print $table_element;
504 504
 		switch ($table_element)
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 				break;
522 522
 			case "actioncomm":
523 523
 				$sql = "SELECT t.id as rowid, t.label as ref";
524
-				$projectkey="fk_project";
524
+				$projectkey = "fk_project";
525 525
 				break;
526 526
 			case "expensereport":
527 527
 				return '';
@@ -537,10 +537,10 @@  discard block
 block discarded – undo
537 537
 			    break;
538 538
 			case 'stock_mouvement':
539 539
 				$sql = 'SELECT t.rowid, t.label as ref';
540
-				$projectkey='fk_origin';
540
+				$projectkey = 'fk_origin';
541 541
 				break;
542 542
 			case "payment_salary":
543
-				$sql = "SELECT t.rowid, t.num_payment as ref";	// TODO In a future fill and use real ref field
543
+				$sql = "SELECT t.rowid, t.num_payment as ref"; // TODO In a future fill and use real ref field
544 544
 				break;
545 545
 			case "payment_various":
546 546
 				$sql = "SELECT t.rowid, t.num_payment as ref";
@@ -550,40 +550,40 @@  discard block
 block discarded – undo
550 550
 				$sql = "SELECT t.rowid, t.ref";
551 551
 				break;
552 552
 		}
553
-		if ($linkedtothirdparty) $sql.=", s.nom as name";
554
-		$sql.= " FROM ".MAIN_DB_PREFIX.$table_element." as t";
555
-		if ($linkedtothirdparty) $sql.=", ".MAIN_DB_PREFIX."societe as s";
556
-		$sql.= " WHERE ".$projectkey." is null";
557
-		if (! empty($socid) && $linkedtothirdparty)
553
+		if ($linkedtothirdparty) $sql .= ", s.nom as name";
554
+		$sql .= " FROM ".MAIN_DB_PREFIX.$table_element." as t";
555
+		if ($linkedtothirdparty) $sql .= ", ".MAIN_DB_PREFIX."societe as s";
556
+		$sql .= " WHERE ".$projectkey." is null";
557
+		if (!empty($socid) && $linkedtothirdparty)
558 558
 		{
559
-		    if (is_numeric($socid)) $sql.= " AND t.fk_soc=".$socid;
560
-		    else $sql.= " AND t.fk_soc IN (".$socid.")";
559
+		    if (is_numeric($socid)) $sql .= " AND t.fk_soc=".$socid;
560
+		    else $sql .= " AND t.fk_soc IN (".$socid.")";
561 561
 		}
562
-		if (! in_array($table_element, array('expensereport_det','stock_mouvement'))) $sql.= ' AND t.entity IN ('.getEntity('project').')';
563
-		if ($linkedtothirdparty) $sql.=" AND s.rowid = t.fk_soc";
564
-		if ($sqlfilter) $sql.= " AND ".$sqlfilter;
565
-		$sql.= " ORDER BY ref DESC";
562
+		if (!in_array($table_element, array('expensereport_det', 'stock_mouvement'))) $sql .= ' AND t.entity IN ('.getEntity('project').')';
563
+		if ($linkedtothirdparty) $sql .= " AND s.rowid = t.fk_soc";
564
+		if ($sqlfilter) $sql .= " AND ".$sqlfilter;
565
+		$sql .= " ORDER BY ref DESC";
566 566
 
567 567
 		dol_syslog(get_class($this).'::select_element', LOG_DEBUG);
568
-		$resql=$this->db->query($sql);
568
+		$resql = $this->db->query($sql);
569 569
 		if ($resql)
570 570
 		{
571 571
 			$num = $this->db->num_rows($resql);
572 572
 			$i = 0;
573 573
 			if ($num > 0)
574 574
 			{
575
-				$sellist = '<select class="flat elementselect css'.$table_element.($morecss?' '.$morecss:'').'" name="elementselect">';
576
-				$sellist .='<option value="-1"></option>';
575
+				$sellist = '<select class="flat elementselect css'.$table_element.($morecss ? ' '.$morecss : '').'" name="elementselect">';
576
+				$sellist .= '<option value="-1"></option>';
577 577
 				while ($i < $num)
578 578
 				{
579 579
 					$obj = $this->db->fetch_object($resql);
580
-					$ref=$obj->ref?$obj->ref:$obj->rowid;
581
-					if (! empty($obj->ref_supplier)) $ref.=' ('.$obj->ref_supplier.')';
582
-					if (! empty($obj->name)) $ref.=' - '.$obj->name;
583
-					$sellist .='<option value="'.$obj->rowid.'">'.$ref.'</option>';
580
+					$ref = $obj->ref ? $obj->ref : $obj->rowid;
581
+					if (!empty($obj->ref_supplier)) $ref .= ' ('.$obj->ref_supplier.')';
582
+					if (!empty($obj->name)) $ref .= ' - '.$obj->name;
583
+					$sellist .= '<option value="'.$obj->rowid.'">'.$ref.'</option>';
584 584
 					$i++;
585 585
 				}
586
-				$sellist .='</select>';
586
+				$sellist .= '</select>';
587 587
 			}
588 588
 			/*else
589 589
 			{
@@ -598,9 +598,9 @@  discard block
 block discarded – undo
598 598
 		else
599 599
 		{
600 600
 			dol_print_error($this->db);
601
-			$this->error=$this->db->lasterror();
602
-			$this->errors[]=$this->db->lasterror();
603
-			dol_syslog(get_class($this) . "::select_element " . $this->error, LOG_ERR);
601
+			$this->error = $this->db->lasterror();
602
+			$this->errors[] = $this->db->lasterror();
603
+			dol_syslog(get_class($this)."::select_element ".$this->error, LOG_ERR);
604 604
 			return -1;
605 605
 		}
606 606
 	}
@@ -618,38 +618,38 @@  discard block
 block discarded – undo
618 618
 	 *    @param   string      $morecss            Add more css
619 619
 	 *    @return  int|string                      The HTML select list of element or '' if nothing or -1 if KO
620 620
 	 */
621
-	function selectOpportunityStatus($htmlname, $preselected='-1', $showempty=1, $useshortlabel=0, $showallnone=0, $showpercent=0, $morecss='')
621
+	function selectOpportunityStatus($htmlname, $preselected = '-1', $showempty = 1, $useshortlabel = 0, $showallnone = 0, $showpercent = 0, $morecss = '')
622 622
 	{
623 623
 		global $conf, $langs;
624 624
 
625 625
 		$sql = "SELECT rowid, code, label, percent";
626
-		$sql.= " FROM ".MAIN_DB_PREFIX.'c_lead_status';
627
-		$sql.= " WHERE active = 1";
628
-		$sql.= " ORDER BY position";
626
+		$sql .= " FROM ".MAIN_DB_PREFIX.'c_lead_status';
627
+		$sql .= " WHERE active = 1";
628
+		$sql .= " ORDER BY position";
629 629
 
630
-		$resql=$this->db->query($sql);
630
+		$resql = $this->db->query($sql);
631 631
 		if ($resql)
632 632
 		{
633 633
 			$num = $this->db->num_rows($resql);
634 634
 			$i = 0;
635 635
 			if ($num > 0)
636 636
 			{
637
-				$sellist = '<select class="flat oppstatus'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
637
+				$sellist = '<select class="flat oppstatus'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
638 638
 				if ($showempty) {
639 639
                     // Without &nbsp, strange move of screen when switching value
640
-                    $sellist.= '<option value="-1">&nbsp;</option>';
640
+                    $sellist .= '<option value="-1">&nbsp;</option>';
641 641
                 }
642 642
 				if ($showallnone) {
643
-                    $sellist.= '<option value="all"'.($preselected == 'all'?' selected="selected"':'').'>-- '.$langs->trans("OnlyOpportunitiesShort").' --</option>';
644
-				    $sellist.= '<option value="openedopp"'.($preselected == 'openedopp'?' selected="selected"':'').'>-- '.$langs->trans("OpenedOpportunitiesShort").' --</option>';
645
-				    $sellist.= '<option value="notopenedopp"'.($preselected == 'notopenedopp'?' selected="selected"':'').'>-- '.$langs->trans("NotOpenedOpportunitiesShort").' --</option>';
646
-				    $sellist.= '<option value="none"'.($preselected == 'none'?' selected="selected"':'').'>-- '.$langs->trans("NotAnOpportunityShort").' --</option>';
643
+                    $sellist .= '<option value="all"'.($preselected == 'all' ? ' selected="selected"' : '').'>-- '.$langs->trans("OnlyOpportunitiesShort").' --</option>';
644
+				    $sellist .= '<option value="openedopp"'.($preselected == 'openedopp' ? ' selected="selected"' : '').'>-- '.$langs->trans("OpenedOpportunitiesShort").' --</option>';
645
+				    $sellist .= '<option value="notopenedopp"'.($preselected == 'notopenedopp' ? ' selected="selected"' : '').'>-- '.$langs->trans("NotOpenedOpportunitiesShort").' --</option>';
646
+				    $sellist .= '<option value="none"'.($preselected == 'none' ? ' selected="selected"' : '').'>-- '.$langs->trans("NotAnOpportunityShort").' --</option>';
647 647
                 }
648 648
 				while ($i < $num)
649 649
 				{
650 650
 					$obj = $this->db->fetch_object($resql);
651 651
 
652
-					$sellist .='<option value="'.$obj->rowid.'" defaultpercent="'.$obj->percent.'" elemcode="'.$obj->code.'"';
652
+					$sellist .= '<option value="'.$obj->rowid.'" defaultpercent="'.$obj->percent.'" elemcode="'.$obj->code.'"';
653 653
 					if ($obj->rowid == $preselected) $sellist .= ' selected="selected"';
654 654
 					$sellist .= '>';
655 655
 					if ($useshortlabel)
@@ -659,13 +659,13 @@  discard block
 block discarded – undo
659 659
 					else
660 660
 					{
661 661
 						$finallabel = ($langs->transnoentitiesnoconv("OppStatus".$obj->code) != "OppStatus".$obj->code ? $langs->transnoentitiesnoconv("OppStatus".$obj->code) : $obj->label);
662
-						if ($showpercent) $finallabel.= ' ('.$obj->percent.'%)';
662
+						if ($showpercent) $finallabel .= ' ('.$obj->percent.'%)';
663 663
 					}
664 664
 					$sellist .= $finallabel;
665
-					$sellist .='</option>';
665
+					$sellist .= '</option>';
666 666
 					$i++;
667 667
 				}
668
-				$sellist .='</select>';
668
+				$sellist .= '</select>';
669 669
 			}
670 670
 			/*else
671 671
 			{
@@ -679,9 +679,9 @@  discard block
 block discarded – undo
679 679
 		}
680 680
 		else
681 681
 		{
682
-			$this->error=$this->db->lasterror();
683
-			$this->errors[]=$this->db->lasterror();
684
-			dol_syslog(get_class($this) . "::selectOpportunityStatus " . $this->error, LOG_ERR);
682
+			$this->error = $this->db->lasterror();
683
+			$this->errors[] = $this->db->lasterror();
684
+			dol_syslog(get_class($this)."::selectOpportunityStatus ".$this->error, LOG_ERR);
685 685
 			return -1;
686 686
 		}
687 687
 	}
Please login to merge, or discard this patch.