Test Failed
Push — master ( e0c20c...b8c830 )
by Alxarafe
39:29
created
dolibarr/htdocs/api/class/api_setup.class.php 3 patches
Indentation   +495 added lines, -495 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
             {
77 77
                 throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters);
78 78
             }
79
-	          $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
79
+                $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
80 80
             $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
81 81
         }
82 82
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
             {
144 144
                 throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
145 145
             }
146
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
146
+            $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
147 147
             $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
148 148
         }
149 149
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
             {
243 243
                 throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters);
244 244
             }
245
-                  $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
245
+                    $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
246 246
             $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
247 247
         }
248 248
 
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
             {
350 350
                 throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
351 351
             }
352
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
352
+            $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
353 353
             $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
354 354
         }
355 355
 
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
             {
411 411
                 throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
412 412
             }
413
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
413
+            $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
414 414
             $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
415 415
         }
416 416
 
@@ -468,12 +468,12 @@  discard block
 block discarded – undo
468 468
         // Add sql filters
469 469
         if ($sqlfilters)
470 470
         {
471
-        	if (! DolibarrApi::_checkFilters($sqlfilters))
472
-        	{
473
-        		throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
474
-        	}
475
-        	$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
476
-        	$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
471
+            if (! DolibarrApi::_checkFilters($sqlfilters))
472
+            {
473
+                throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
474
+            }
475
+            $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
476
+            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
477 477
         }
478 478
 
479 479
         $sql.= $this->db->order($sortfield, $sortorder);
@@ -481,26 +481,26 @@  discard block
 block discarded – undo
481 481
         $resql=$this->db->query($sql);
482 482
         if ($resql)
483 483
         {
484
-        	if ($this->db->num_rows($resql))
485
-        	{
486
-        		while ($tab = $this->db->fetch_object($resql))
487
-        		{
488
-        			// New usage
489
-        			$list[$tab->elementtype][$tab->name]['type']=$tab->type;
490
-        			$list[$tab->elementtype][$tab->name]['label']=$tab->label;
491
-        			$list[$tab->elementtype][$tab->name]['size']=$tab->size;
492
-        			$list[$tab->elementtype][$tab->name]['elementtype']=$tab->elementtype;
493
-        			$list[$tab->elementtype][$tab->name]['default']=$tab->fielddefault;
494
-        			$list[$tab->elementtype][$tab->name]['computed']=$tab->fieldcomputed;
495
-        			$list[$tab->elementtype][$tab->name]['unique']=$tab->fieldunique;
496
-        			$list[$tab->elementtype][$tab->name]['required']=$tab->fieldrequired;
497
-        			$list[$tab->elementtype][$tab->name]['param']=($tab->param ? unserialize($tab->param) : '');
498
-        			$list[$tab->elementtype][$tab->name]['pos']=$tab->pos;
499
-        			$list[$tab->elementtype][$tab->name]['alwayseditable']=$tab->alwayseditable;
500
-        			$list[$tab->elementtype][$tab->name]['perms']=$tab->perms;
501
-        			$list[$tab->elementtype][$tab->name]['list']=$tab->list;
502
-        		}
503
-        	}
484
+            if ($this->db->num_rows($resql))
485
+            {
486
+                while ($tab = $this->db->fetch_object($resql))
487
+                {
488
+                    // New usage
489
+                    $list[$tab->elementtype][$tab->name]['type']=$tab->type;
490
+                    $list[$tab->elementtype][$tab->name]['label']=$tab->label;
491
+                    $list[$tab->elementtype][$tab->name]['size']=$tab->size;
492
+                    $list[$tab->elementtype][$tab->name]['elementtype']=$tab->elementtype;
493
+                    $list[$tab->elementtype][$tab->name]['default']=$tab->fielddefault;
494
+                    $list[$tab->elementtype][$tab->name]['computed']=$tab->fieldcomputed;
495
+                    $list[$tab->elementtype][$tab->name]['unique']=$tab->fieldunique;
496
+                    $list[$tab->elementtype][$tab->name]['required']=$tab->fieldrequired;
497
+                    $list[$tab->elementtype][$tab->name]['param']=($tab->param ? unserialize($tab->param) : '');
498
+                    $list[$tab->elementtype][$tab->name]['pos']=$tab->pos;
499
+                    $list[$tab->elementtype][$tab->name]['alwayseditable']=$tab->alwayseditable;
500
+                    $list[$tab->elementtype][$tab->name]['perms']=$tab->perms;
501
+                    $list[$tab->elementtype][$tab->name]['list']=$tab->list;
502
+                }
503
+            }
504 504
         }
505 505
         else
506 506
         {
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 
510 510
         if (! count($list))
511 511
         {
512
-        	throw new RestException(404, 'No extrafield found');
512
+            throw new RestException(404, 'No extrafield found');
513 513
         }
514 514
 
515 515
         return $list;
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
             {
549 549
                 throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
550 550
             }
551
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
551
+            $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
552 552
             $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
553 553
         }
554 554
 
@@ -642,63 +642,63 @@  discard block
 block discarded – undo
642 642
         return $list;
643 643
     }
644 644
 
645
-     /**
646
-     * Get the list of tickets categories.
647
-     *
648
-     * @param string    $sortfield  Sort field
649
-     * @param string    $sortorder  Sort order
650
-     * @param int       $limit      Number of items per page
651
-     * @param int       $page       Page number (starting from zero)
652
-     * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
653
-     * @return List of events types
654
-     *
655
-     * @url     GET dictionary/ticket_categories
656
-     *
657
-     * @throws RestException
658
-     */
645
+        /**
646
+         * Get the list of tickets categories.
647
+         *
648
+         * @param string    $sortfield  Sort field
649
+         * @param string    $sortorder  Sort order
650
+         * @param int       $limit      Number of items per page
651
+         * @param int       $page       Page number (starting from zero)
652
+         * @param string    $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
653
+         * @return List of events types
654
+         *
655
+         * @url     GET dictionary/ticket_categories
656
+         *
657
+         * @throws RestException
658
+         */
659 659
     function getTicketsCategories($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '')
660 660
     {
661
-    	$list = array();
662
-
663
-    	$sql = "SELECT rowid, code, pos,  label, use_default, description";
664
-    	$sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t";
665
-    	$sql.= " WHERE t.active = 1";
666
-    	// Add sql filters
667
-    	if ($sqlfilters)
668
-    	{
669
-    		if (! DolibarrApi::_checkFilters($sqlfilters))
670
-    		{
671
-    			throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
672
-    		}
673
-    		$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
674
-    		$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
675
-    	}
676
-
677
-
678
-    	$sql.= $this->db->order($sortfield, $sortorder);
679
-
680
-    	if ($limit) {
681
-    		if ($page < 0) {
682
-    			$page = 0;
683
-    		}
684
-    		$offset = $limit * $page;
685
-
686
-    		$sql .= $this->db->plimit($limit, $offset);
687
-    	}
688
-
689
-    	$result = $this->db->query($sql);
690
-
691
-    	if ($result) {
692
-    		$num = $this->db->num_rows($result);
693
-    		$min = min($num, ($limit <= 0 ? $num : $limit));
694
-    		for ($i = 0; $i < $min; $i++) {
695
-    			$list[] = $this->db->fetch_object($result);
696
-    		}
697
-    	} else {
698
-    		throw new RestException(503, 'Error when retrieving list of ticket categories : '.$this->db->lasterror());
699
-    	}
700
-
701
-    	return $list;
661
+        $list = array();
662
+
663
+        $sql = "SELECT rowid, code, pos,  label, use_default, description";
664
+        $sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t";
665
+        $sql.= " WHERE t.active = 1";
666
+        // Add sql filters
667
+        if ($sqlfilters)
668
+        {
669
+            if (! DolibarrApi::_checkFilters($sqlfilters))
670
+            {
671
+                throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
672
+            }
673
+            $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
674
+            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
675
+        }
676
+
677
+
678
+        $sql.= $this->db->order($sortfield, $sortorder);
679
+
680
+        if ($limit) {
681
+            if ($page < 0) {
682
+                $page = 0;
683
+            }
684
+            $offset = $limit * $page;
685
+
686
+            $sql .= $this->db->plimit($limit, $offset);
687
+        }
688
+
689
+        $result = $this->db->query($sql);
690
+
691
+        if ($result) {
692
+            $num = $this->db->num_rows($result);
693
+            $min = min($num, ($limit <= 0 ? $num : $limit));
694
+            for ($i = 0; $i < $min; $i++) {
695
+                $list[] = $this->db->fetch_object($result);
696
+            }
697
+        } else {
698
+            throw new RestException(503, 'Error when retrieving list of ticket categories : '.$this->db->lasterror());
699
+        }
700
+
701
+        return $list;
702 702
     }
703 703
 
704 704
     /**
@@ -717,47 +717,47 @@  discard block
 block discarded – undo
717 717
      */
718 718
     function getTicketsSeverities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '')
719 719
     {
720
-    	$list = array();
721
-
722
-    	$sql = "SELECT rowid, code, pos,  label, use_default, color, description";
723
-    	$sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t";
724
-    	$sql.= " WHERE t.active = 1";
725
-    	// Add sql filters
726
-    	if ($sqlfilters)
727
-    	{
728
-    		if (! DolibarrApi::_checkFilters($sqlfilters))
729
-    		{
730
-    			throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
731
-    		}
732
-    		$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
733
-    		$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
734
-    	}
735
-
736
-
737
-    	$sql.= $this->db->order($sortfield, $sortorder);
738
-
739
-    	if ($limit) {
740
-    		if ($page < 0) {
741
-    			$page = 0;
742
-    		}
743
-    		$offset = $limit * $page;
744
-
745
-    		$sql .= $this->db->plimit($limit, $offset);
746
-    	}
747
-
748
-    	$result = $this->db->query($sql);
749
-
750
-    	if ($result) {
751
-    		$num = $this->db->num_rows($result);
752
-    		$min = min($num, ($limit <= 0 ? $num : $limit));
753
-    		for ($i = 0; $i < $min; $i++) {
754
-    			$list[] = $this->db->fetch_object($result);
755
-    		}
756
-    	} else {
757
-    		throw new RestException(503, 'Error when retrieving list of ticket severities : '.$this->db->lasterror());
758
-    	}
759
-
760
-    	return $list;
720
+        $list = array();
721
+
722
+        $sql = "SELECT rowid, code, pos,  label, use_default, color, description";
723
+        $sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t";
724
+        $sql.= " WHERE t.active = 1";
725
+        // Add sql filters
726
+        if ($sqlfilters)
727
+        {
728
+            if (! DolibarrApi::_checkFilters($sqlfilters))
729
+            {
730
+                throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
731
+            }
732
+            $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
733
+            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
734
+        }
735
+
736
+
737
+        $sql.= $this->db->order($sortfield, $sortorder);
738
+
739
+        if ($limit) {
740
+            if ($page < 0) {
741
+                $page = 0;
742
+            }
743
+            $offset = $limit * $page;
744
+
745
+            $sql .= $this->db->plimit($limit, $offset);
746
+        }
747
+
748
+        $result = $this->db->query($sql);
749
+
750
+        if ($result) {
751
+            $num = $this->db->num_rows($result);
752
+            $min = min($num, ($limit <= 0 ? $num : $limit));
753
+            for ($i = 0; $i < $min; $i++) {
754
+                $list[] = $this->db->fetch_object($result);
755
+            }
756
+        } else {
757
+            throw new RestException(503, 'Error when retrieving list of ticket severities : '.$this->db->lasterror());
758
+        }
759
+
760
+        return $list;
761 761
     }
762 762
 
763 763
     /**
@@ -776,49 +776,49 @@  discard block
 block discarded – undo
776 776
      */
777 777
     function getTicketsTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '')
778 778
     {
779
-    	$list = array();
780
-
781
-    	$sql = "SELECT rowid, code, pos,  label, use_default, description";
782
-    	$sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_type as t";
783
-    	$sql.= " WHERE t.active = 1";
784
-    	if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'";
785
-    	if ($module)    $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'";
786
-    	// Add sql filters
787
-    	if ($sqlfilters)
788
-    	{
789
-    		if (! DolibarrApi::_checkFilters($sqlfilters))
790
-    		{
791
-    			throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
792
-    		}
793
-    		$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
794
-    		$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
795
-    	}
796
-
797
-
798
-    	$sql.= $this->db->order($sortfield, $sortorder);
799
-
800
-    	if ($limit) {
801
-    		if ($page < 0) {
802
-    			$page = 0;
803
-    		}
804
-    		$offset = $limit * $page;
805
-
806
-    		$sql .= $this->db->plimit($limit, $offset);
807
-    	}
808
-
809
-    	$result = $this->db->query($sql);
810
-
811
-    	if ($result) {
812
-    		$num = $this->db->num_rows($result);
813
-    		$min = min($num, ($limit <= 0 ? $num : $limit));
814
-    		for ($i = 0; $i < $min; $i++) {
815
-    			$list[] = $this->db->fetch_object($result);
816
-    		}
817
-    	} else {
818
-    		throw new RestException(503, 'Error when retrieving list of ticket types : '.$this->db->lasterror());
819
-    	}
820
-
821
-    	return $list;
779
+        $list = array();
780
+
781
+        $sql = "SELECT rowid, code, pos,  label, use_default, description";
782
+        $sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_type as t";
783
+        $sql.= " WHERE t.active = 1";
784
+        if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'";
785
+        if ($module)    $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'";
786
+        // Add sql filters
787
+        if ($sqlfilters)
788
+        {
789
+            if (! DolibarrApi::_checkFilters($sqlfilters))
790
+            {
791
+                throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
792
+            }
793
+            $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
794
+            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
795
+        }
796
+
797
+
798
+        $sql.= $this->db->order($sortfield, $sortorder);
799
+
800
+        if ($limit) {
801
+            if ($page < 0) {
802
+                $page = 0;
803
+            }
804
+            $offset = $limit * $page;
805
+
806
+            $sql .= $this->db->plimit($limit, $offset);
807
+        }
808
+
809
+        $result = $this->db->query($sql);
810
+
811
+        if ($result) {
812
+            $num = $this->db->num_rows($result);
813
+            $min = min($num, ($limit <= 0 ? $num : $limit));
814
+            for ($i = 0; $i < $min; $i++) {
815
+                $list[] = $this->db->fetch_object($result);
816
+            }
817
+        } else {
818
+            throw new RestException(503, 'Error when retrieving list of ticket types : '.$this->db->lasterror());
819
+        }
820
+
821
+        return $list;
822 822
     }
823 823
 
824 824
 
@@ -834,328 +834,328 @@  discard block
 block discarded – undo
834 834
      */
835 835
     function getCheckIntegrity($target)
836 836
     {
837
-    	global $langs, $conf;
838
-
839
-    	if (! DolibarrApiAccess::$user->admin
840
-    		&& (empty($conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK) || DolibarrApiAccess::$user->login != $conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK))
841
-    	{
842
-    		throw new RestException(503, 'Error API open to admin users only or to login user defined with constant API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK');
843
-    	}
844
-
845
-    	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
846
-    	require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
847
-
848
-    	$langs->load("admin");
849
-
850
-    	$outexpectedchecksum = '';
851
-    	$outcurrentchecksum = '';
852
-
853
-    	// Modified or missing files
854
-    	$file_list = array('missing' => array(), 'updated' => array());
855
-
856
-    	// Local file to compare to
857
-    	$xmlshortfile = GETPOST('xmlshortfile')?GETPOST('xmlshortfile'):'/install/filelist-'.DOL_VERSION.'.xml';
858
-    	$xmlfile = DOL_DOCUMENT_ROOT.$xmlshortfile;
859
-    	// Remote file to compare to
860
-    	$xmlremote = ($target == 'default' ? '' : $target);
861
-    	if (empty($xmlremote) && ! empty($conf->global->MAIN_FILECHECK_URL)) $xmlremote = $conf->global->MAIN_FILECHECK_URL;
862
-    	$param='MAIN_FILECHECK_URL_'.DOL_VERSION;
863
-    	if (empty($xmlremote) && ! empty($conf->global->$param)) $xmlremote = $conf->global->$param;
864
-    	if (empty($xmlremote)) $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml';
865
-
866
-    	if ($target == 'local')
867
-    	{
868
-    		if (dol_is_file($xmlfile))
869
-    		{
870
-    			$xml = simplexml_load_file($xmlfile);
871
-    		}
872
-    		else
873
-    		{
874
-    			throw new RestException(500, $langs->trans('XmlNotFound') . ': ' . $xmlfile);
875
-    		}
876
-    	}
877
-    	else
878
-    	{
879
-    		$xmlarray = getURLContent($xmlremote);
880
-
881
-    		// Return array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...)
882
-    		if (! $xmlarray['curl_error_no'] && $xmlarray['http_code'] != '404')
883
-    		{
884
-    			$xmlfile = $xmlarray['content'];
885
-    			//print "xmlfilestart".$xmlfile."endxmlfile";
886
-    			$xml = simplexml_load_string($xmlfile);
887
-    		}
888
-    		else
889
-    		{
890
-    			$errormsg=$langs->trans('XmlNotFound') . ': ' . $xmlremote.' - '.$xmlarray['http_code'].' '.$xmlarray['curl_error_no'].' '.$xmlarray['curl_error_msg'];
891
-    			throw new RestException(500, $errormsg);
892
-    		}
893
-    	}
894
-
895
-
896
-
897
-    	if ($xml)
898
-    	{
899
-    		$checksumconcat = array();
900
-    		$file_list = array();
901
-    		$out = '';
902
-
903
-    		// Forced constants
904
-    		if (is_object($xml->dolibarr_constants[0]))
905
-    		{
906
-    			$out.=load_fiche_titre($langs->trans("ForcedConstants"));
907
-
908
-    			$out.='<div class="div-table-responsive-no-min">';
909
-    			$out.='<table class="noborder">';
910
-    			$out.='<tr class="liste_titre">';
911
-    			$out.='<td>#</td>';
912
-    			$out.='<td>' . $langs->trans("Constant") . '</td>';
913
-    			$out.='<td align="center">' . $langs->trans("ExpectedValue") . '</td>';
914
-    			$out.='<td align="center">' . $langs->trans("Value") . '</td>';
915
-    			$out.='</tr>'."\n";
916
-
917
-    			$i = 0;
918
-    			foreach ($xml->dolibarr_constants[0]->constant as $constant)    // $constant is a simpleXMLElement
919
-    			{
920
-    				$constname=$constant['name'];
921
-    				$constvalue=(string) $constant;
922
-    				$constvalue = (empty($constvalue)?'0':$constvalue);
923
-    				// Value found
924
-    				$value='';
925
-    				if ($constname && $conf->global->$constname != '') $value=$conf->global->$constname;
926
-    				$valueforchecksum=(empty($value)?'0':$value);
927
-
928
-    				$checksumconcat[]=$valueforchecksum;
929
-
930
-    				$i++;
931
-    				$out.='<tr class="oddeven">';
932
-    				$out.='<td>'.$i.'</td>' . "\n";
933
-    				$out.='<td>'.$constname.'</td>' . "\n";
934
-    				$out.='<td align="center">'.$constvalue.'</td>' . "\n";
935
-    				$out.='<td align="center">'.$valueforchecksum.'</td>' . "\n";
936
-    				$out.="</tr>\n";
937
-    			}
938
-
939
-    			if ($i==0)
940
-    			{
941
-    				$out.='<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
942
-    			}
943
-    			$out.='</table>';
944
-    			$out.='</div>';
945
-
946
-    			$out.='<br>';
947
-    		}
948
-
949
-    		// Scan htdocs
950
-    		if (is_object($xml->dolibarr_htdocs_dir[0]))
951
-    		{
952
-    			//var_dump($xml->dolibarr_htdocs_dir[0]['includecustom']);exit;
953
-    			$includecustom=(empty($xml->dolibarr_htdocs_dir[0]['includecustom'])?0:$xml->dolibarr_htdocs_dir[0]['includecustom']);
954
-
955
-    			// Defined qualified files (must be same than into generate_filelist_xml.php)
956
-    			$regextoinclude='\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$';
957
-    			$regextoexclude='('.($includecustom?'':'custom|').'documents|conf|install|public\/test|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$';  // Exclude dirs
958
-    			$scanfiles = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude);
959
-
960
-    			// Fill file_list with files in signature, new files, modified files
961
-    			$ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat, $scanfiles);		// Fill array $file_list
962
-    			// Complete with list of new files
963
-    			foreach ($scanfiles as $keyfile => $valfile)
964
-    			{
965
-    				$tmprelativefilename=preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT,'/').'/','', $valfile['fullname']);
966
-    				if (! in_array($tmprelativefilename, $file_list['insignature']))
967
-    				{
968
-    					$md5newfile=@md5_file($valfile['fullname']);    // Can fails if we don't have permission to open/read file
969
-    					$file_list['added'][]=array('filename'=>$tmprelativefilename, 'md5'=>$md5newfile);
970
-    				}
971
-    			}
972
-
973
-    			// Files missings
974
-    			$out.=load_fiche_titre($langs->trans("FilesMissing"));
975
-
976
-    			$out.='<div class="div-table-responsive-no-min">';
977
-    			$out.='<table class="noborder">';
978
-    			$out.='<tr class="liste_titre">';
979
-    			$out.='<td>#</td>';
980
-    			$out.='<td>' . $langs->trans("Filename") . '</td>';
981
-    			$out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>';
982
-    			$out.='</tr>'."\n";
983
-    			$tmpfilelist = dol_sort_array($file_list['missing'], 'filename');
984
-    			if (is_array($tmpfilelist) && count($tmpfilelist))
985
-    			{
986
-    				$i = 0;
987
-    				foreach ($tmpfilelist as $file)
988
-    				{
989
-    					$i++;
990
-    					$out.='<tr class="oddeven">';
991
-    					$out.='<td>'.$i.'</td>' . "\n";
992
-    					$out.='<td>'.$file['filename'].'</td>' . "\n";
993
-    					$out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n";
994
-    					$out.="</tr>\n";
995
-    				}
996
-    			}
997
-    			else
998
-    			{
999
-    				$out.='<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1000
-    			}
1001
-    			$out.='</table>';
1002
-    			$out.='</div>';
1003
-
1004
-    			$out.='<br>';
1005
-
1006
-    			// Files modified
1007
-    			$out.=load_fiche_titre($langs->trans("FilesModified"));
1008
-
1009
-    			$totalsize=0;
1010
-    			$out.='<div class="div-table-responsive-no-min">';
1011
-    			$out.='<table class="noborder">';
1012
-    			$out.='<tr class="liste_titre">';
1013
-    			$out.='<td>#</td>';
1014
-    			$out.='<td>' . $langs->trans("Filename") . '</td>';
1015
-    			$out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>';
1016
-    			$out.='<td align="center">' . $langs->trans("CurrentChecksum") . '</td>';
1017
-    			$out.='<td align="right">' . $langs->trans("Size") . '</td>';
1018
-    			$out.='<td align="right">' . $langs->trans("DateModification") . '</td>';
1019
-    			$out.='</tr>'."\n";
1020
-    			$tmpfilelist2 = dol_sort_array($file_list['updated'], 'filename');
1021
-    			if (is_array($tmpfilelist2) && count($tmpfilelist2))
1022
-    			{
1023
-    				$i = 0;
1024
-    				foreach ($tmpfilelist2 as $file)
1025
-    				{
1026
-    					$i++;
1027
-    					$out.='<tr class="oddeven">';
1028
-    					$out.='<td>'.$i.'</td>' . "\n";
1029
-    					$out.='<td>'.$file['filename'].'</td>' . "\n";
1030
-    					$out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n";
1031
-    					$out.='<td align="center">'.$file['md5'].'</td>' . "\n";
1032
-    					$size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
1033
-    					$totalsize += $size;
1034
-    					$out.='<td align="right">'.dol_print_size($size).'</td>' . "\n";
1035
-    					$out.='<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']),'dayhour').'</td>' . "\n";
1036
-    					$out.="</tr>\n";
1037
-    				}
1038
-    				$out.='<tr class="liste_total">';
1039
-    				$out.='<td></td>' . "\n";
1040
-    				$out.='<td>'.$langs->trans("Total").'</td>' . "\n";
1041
-    				$out.='<td align="center"></td>' . "\n";
1042
-    				$out.='<td align="center"></td>' . "\n";
1043
-    				$out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n";
1044
-    				$out.='<td align="right"></td>' . "\n";
1045
-    				$out.="</tr>\n";
1046
-    			}
1047
-    			else
1048
-    			{
1049
-    				$out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1050
-    			}
1051
-    			$out.='</table>';
1052
-    			$out.='</div>';
1053
-
1054
-    			$out.='<br>';
1055
-
1056
-    			// Files added
1057
-    			$out.=load_fiche_titre($langs->trans("FilesAdded"));
1058
-
1059
-    			$totalsize = 0;
1060
-    			$out.='<div class="div-table-responsive-no-min">';
1061
-    			$out.='<table class="noborder">';
1062
-    			$out.='<tr class="liste_titre">';
1063
-    			$out.='<td>#</td>';
1064
-    			$out.='<td>' . $langs->trans("Filename") . '</td>';
1065
-    			$out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>';
1066
-    			$out.='<td align="center">' . $langs->trans("CurrentChecksum") . '</td>';
1067
-    			$out.='<td align="right">' . $langs->trans("Size") . '</td>';
1068
-    			$out.='<td align="right">' . $langs->trans("DateModification") . '</td>';
1069
-    			$out.='</tr>'."\n";
1070
-    			$tmpfilelist3 = dol_sort_array($file_list['added'], 'filename');
1071
-    			if (is_array($tmpfilelist3) && count($tmpfilelist3))
1072
-    			{
1073
-    				$i = 0;
1074
-    				foreach ($tmpfilelist3 as $file)
1075
-    				{
1076
-    					$i++;
1077
-    					$out.='<tr class="oddeven">';
1078
-    					$out.='<td>'.$i.'</td>' . "\n";
1079
-    					$out.='<td>'.$file['filename'].'</td>' . "\n";
1080
-    					$out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n";
1081
-    					$out.='<td align="center">'.$file['md5'].'</td>' . "\n";
1082
-    					$size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
1083
-    					$totalsize += $size;
1084
-    					$out.='<td align="right">'.dol_print_size($size).'</td>' . "\n";
1085
-    					$out.='<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']),'dayhour').'</td>' . "\n";
1086
-    					$out.="</tr>\n";
1087
-    				}
1088
-    				$out.='<tr class="liste_total">';
1089
-    				$out.='<td></td>' . "\n";
1090
-    				$out.='<td>'.$langs->trans("Total").'</td>' . "\n";
1091
-    				$out.='<td align="center"></td>' . "\n";
1092
-    				$out.='<td align="center"></td>' . "\n";
1093
-    				$out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n";
1094
-    				$out.='<td align="right"></td>' . "\n";
1095
-    				$out.="</tr>\n";
1096
-    			}
1097
-    			else
1098
-    			{
1099
-    				$out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1100
-    			}
1101
-    			$out.='</table>';
1102
-    			$out.='</div>';
1103
-
1104
-
1105
-    			// Show warning
1106
-    			if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3))
1107
-    			{
1108
-    				//setEventMessages($langs->trans("FileIntegrityIsStrictlyConformedWithReference"), null, 'mesgs');
1109
-    			}
1110
-    			else
1111
-    			{
1112
-    				//setEventMessages($langs->trans("FileIntegritySomeFilesWereRemovedOrModified"), null, 'warnings');
1113
-    			}
1114
-    		}
1115
-    		else
1116
-    		{
1117
-    			throw new RestException(500, 'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile);
1118
-    		}
1119
-
1120
-
1121
-    		// Scan scripts
1122
-
1123
-
1124
-    		asort($checksumconcat); // Sort list of checksum
1125
-    		//var_dump($checksumconcat);
1126
-    		$checksumget = md5(join(',',$checksumconcat));
1127
-    		$checksumtoget = trim((string) $xml->dolibarr_htdocs_dir_checksum);
1128
-
1129
-    		$outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans("Unknown"));
1130
-    		if ($checksumget == $checksumtoget)
1131
-    		{
1132
-    			if (count($file_list['added']))
1133
-    			{
1134
-    				$resultcode = 'warning';
1135
-    				$resultcomment='FileIntegrityIsOkButFilesWereAdded';
1136
-    				//$outcurrentchecksum =  $checksumget.' - <span class="'.$resultcode.'">'.$langs->trans("FileIntegrityIsOkButFilesWereAdded").'</span>';
1137
-    				$outcurrentchecksum =  $checksumget;
1138
-    			}
1139
-    			else
1140
-    			{
1141
-    				$resultcode = 'ok';
1142
-    				$resultcomment='Success';
1143
-    				//$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
1144
-    				$outcurrentchecksum =  $checksumget;
1145
-    			}
1146
-    		}
1147
-    		else
1148
-    		{
1149
-    			$resultcode = 'error';
1150
-    			$resultcomment='Error';
1151
-    			//$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
1152
-    			$outcurrentchecksum =  $checksumget;
1153
-    		}
1154
-    	}
1155
-    	else {
1156
-    		throw new RestException(404, 'No signature file known');
1157
-    	}
1158
-
1159
-    	return array('resultcode'=>$resultcode, 'resultcomment'=>$resultcomment, 'expectedchecksum'=> $outexpectedchecksum, 'currentchecksum'=> $outcurrentchecksum, 'out'=>$out);
837
+        global $langs, $conf;
838
+
839
+        if (! DolibarrApiAccess::$user->admin
840
+            && (empty($conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK) || DolibarrApiAccess::$user->login != $conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK))
841
+        {
842
+            throw new RestException(503, 'Error API open to admin users only or to login user defined with constant API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK');
843
+        }
844
+
845
+        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
846
+        require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
847
+
848
+        $langs->load("admin");
849
+
850
+        $outexpectedchecksum = '';
851
+        $outcurrentchecksum = '';
852
+
853
+        // Modified or missing files
854
+        $file_list = array('missing' => array(), 'updated' => array());
855
+
856
+        // Local file to compare to
857
+        $xmlshortfile = GETPOST('xmlshortfile')?GETPOST('xmlshortfile'):'/install/filelist-'.DOL_VERSION.'.xml';
858
+        $xmlfile = DOL_DOCUMENT_ROOT.$xmlshortfile;
859
+        // Remote file to compare to
860
+        $xmlremote = ($target == 'default' ? '' : $target);
861
+        if (empty($xmlremote) && ! empty($conf->global->MAIN_FILECHECK_URL)) $xmlremote = $conf->global->MAIN_FILECHECK_URL;
862
+        $param='MAIN_FILECHECK_URL_'.DOL_VERSION;
863
+        if (empty($xmlremote) && ! empty($conf->global->$param)) $xmlremote = $conf->global->$param;
864
+        if (empty($xmlremote)) $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml';
865
+
866
+        if ($target == 'local')
867
+        {
868
+            if (dol_is_file($xmlfile))
869
+            {
870
+                $xml = simplexml_load_file($xmlfile);
871
+            }
872
+            else
873
+            {
874
+                throw new RestException(500, $langs->trans('XmlNotFound') . ': ' . $xmlfile);
875
+            }
876
+        }
877
+        else
878
+        {
879
+            $xmlarray = getURLContent($xmlremote);
880
+
881
+            // Return array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...)
882
+            if (! $xmlarray['curl_error_no'] && $xmlarray['http_code'] != '404')
883
+            {
884
+                $xmlfile = $xmlarray['content'];
885
+                //print "xmlfilestart".$xmlfile."endxmlfile";
886
+                $xml = simplexml_load_string($xmlfile);
887
+            }
888
+            else
889
+            {
890
+                $errormsg=$langs->trans('XmlNotFound') . ': ' . $xmlremote.' - '.$xmlarray['http_code'].' '.$xmlarray['curl_error_no'].' '.$xmlarray['curl_error_msg'];
891
+                throw new RestException(500, $errormsg);
892
+            }
893
+        }
894
+
895
+
896
+
897
+        if ($xml)
898
+        {
899
+            $checksumconcat = array();
900
+            $file_list = array();
901
+            $out = '';
902
+
903
+            // Forced constants
904
+            if (is_object($xml->dolibarr_constants[0]))
905
+            {
906
+                $out.=load_fiche_titre($langs->trans("ForcedConstants"));
907
+
908
+                $out.='<div class="div-table-responsive-no-min">';
909
+                $out.='<table class="noborder">';
910
+                $out.='<tr class="liste_titre">';
911
+                $out.='<td>#</td>';
912
+                $out.='<td>' . $langs->trans("Constant") . '</td>';
913
+                $out.='<td align="center">' . $langs->trans("ExpectedValue") . '</td>';
914
+                $out.='<td align="center">' . $langs->trans("Value") . '</td>';
915
+                $out.='</tr>'."\n";
916
+
917
+                $i = 0;
918
+                foreach ($xml->dolibarr_constants[0]->constant as $constant)    // $constant is a simpleXMLElement
919
+                {
920
+                    $constname=$constant['name'];
921
+                    $constvalue=(string) $constant;
922
+                    $constvalue = (empty($constvalue)?'0':$constvalue);
923
+                    // Value found
924
+                    $value='';
925
+                    if ($constname && $conf->global->$constname != '') $value=$conf->global->$constname;
926
+                    $valueforchecksum=(empty($value)?'0':$value);
927
+
928
+                    $checksumconcat[]=$valueforchecksum;
929
+
930
+                    $i++;
931
+                    $out.='<tr class="oddeven">';
932
+                    $out.='<td>'.$i.'</td>' . "\n";
933
+                    $out.='<td>'.$constname.'</td>' . "\n";
934
+                    $out.='<td align="center">'.$constvalue.'</td>' . "\n";
935
+                    $out.='<td align="center">'.$valueforchecksum.'</td>' . "\n";
936
+                    $out.="</tr>\n";
937
+                }
938
+
939
+                if ($i==0)
940
+                {
941
+                    $out.='<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
942
+                }
943
+                $out.='</table>';
944
+                $out.='</div>';
945
+
946
+                $out.='<br>';
947
+            }
948
+
949
+            // Scan htdocs
950
+            if (is_object($xml->dolibarr_htdocs_dir[0]))
951
+            {
952
+                //var_dump($xml->dolibarr_htdocs_dir[0]['includecustom']);exit;
953
+                $includecustom=(empty($xml->dolibarr_htdocs_dir[0]['includecustom'])?0:$xml->dolibarr_htdocs_dir[0]['includecustom']);
954
+
955
+                // Defined qualified files (must be same than into generate_filelist_xml.php)
956
+                $regextoinclude='\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$';
957
+                $regextoexclude='('.($includecustom?'':'custom|').'documents|conf|install|public\/test|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$';  // Exclude dirs
958
+                $scanfiles = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude);
959
+
960
+                // Fill file_list with files in signature, new files, modified files
961
+                $ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat, $scanfiles);		// Fill array $file_list
962
+                // Complete with list of new files
963
+                foreach ($scanfiles as $keyfile => $valfile)
964
+                {
965
+                    $tmprelativefilename=preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT,'/').'/','', $valfile['fullname']);
966
+                    if (! in_array($tmprelativefilename, $file_list['insignature']))
967
+                    {
968
+                        $md5newfile=@md5_file($valfile['fullname']);    // Can fails if we don't have permission to open/read file
969
+                        $file_list['added'][]=array('filename'=>$tmprelativefilename, 'md5'=>$md5newfile);
970
+                    }
971
+                }
972
+
973
+                // Files missings
974
+                $out.=load_fiche_titre($langs->trans("FilesMissing"));
975
+
976
+                $out.='<div class="div-table-responsive-no-min">';
977
+                $out.='<table class="noborder">';
978
+                $out.='<tr class="liste_titre">';
979
+                $out.='<td>#</td>';
980
+                $out.='<td>' . $langs->trans("Filename") . '</td>';
981
+                $out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>';
982
+                $out.='</tr>'."\n";
983
+                $tmpfilelist = dol_sort_array($file_list['missing'], 'filename');
984
+                if (is_array($tmpfilelist) && count($tmpfilelist))
985
+                {
986
+                    $i = 0;
987
+                    foreach ($tmpfilelist as $file)
988
+                    {
989
+                        $i++;
990
+                        $out.='<tr class="oddeven">';
991
+                        $out.='<td>'.$i.'</td>' . "\n";
992
+                        $out.='<td>'.$file['filename'].'</td>' . "\n";
993
+                        $out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n";
994
+                        $out.="</tr>\n";
995
+                    }
996
+                }
997
+                else
998
+                {
999
+                    $out.='<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1000
+                }
1001
+                $out.='</table>';
1002
+                $out.='</div>';
1003
+
1004
+                $out.='<br>';
1005
+
1006
+                // Files modified
1007
+                $out.=load_fiche_titre($langs->trans("FilesModified"));
1008
+
1009
+                $totalsize=0;
1010
+                $out.='<div class="div-table-responsive-no-min">';
1011
+                $out.='<table class="noborder">';
1012
+                $out.='<tr class="liste_titre">';
1013
+                $out.='<td>#</td>';
1014
+                $out.='<td>' . $langs->trans("Filename") . '</td>';
1015
+                $out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>';
1016
+                $out.='<td align="center">' . $langs->trans("CurrentChecksum") . '</td>';
1017
+                $out.='<td align="right">' . $langs->trans("Size") . '</td>';
1018
+                $out.='<td align="right">' . $langs->trans("DateModification") . '</td>';
1019
+                $out.='</tr>'."\n";
1020
+                $tmpfilelist2 = dol_sort_array($file_list['updated'], 'filename');
1021
+                if (is_array($tmpfilelist2) && count($tmpfilelist2))
1022
+                {
1023
+                    $i = 0;
1024
+                    foreach ($tmpfilelist2 as $file)
1025
+                    {
1026
+                        $i++;
1027
+                        $out.='<tr class="oddeven">';
1028
+                        $out.='<td>'.$i.'</td>' . "\n";
1029
+                        $out.='<td>'.$file['filename'].'</td>' . "\n";
1030
+                        $out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n";
1031
+                        $out.='<td align="center">'.$file['md5'].'</td>' . "\n";
1032
+                        $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
1033
+                        $totalsize += $size;
1034
+                        $out.='<td align="right">'.dol_print_size($size).'</td>' . "\n";
1035
+                        $out.='<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']),'dayhour').'</td>' . "\n";
1036
+                        $out.="</tr>\n";
1037
+                    }
1038
+                    $out.='<tr class="liste_total">';
1039
+                    $out.='<td></td>' . "\n";
1040
+                    $out.='<td>'.$langs->trans("Total").'</td>' . "\n";
1041
+                    $out.='<td align="center"></td>' . "\n";
1042
+                    $out.='<td align="center"></td>' . "\n";
1043
+                    $out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n";
1044
+                    $out.='<td align="right"></td>' . "\n";
1045
+                    $out.="</tr>\n";
1046
+                }
1047
+                else
1048
+                {
1049
+                    $out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1050
+                }
1051
+                $out.='</table>';
1052
+                $out.='</div>';
1053
+
1054
+                $out.='<br>';
1055
+
1056
+                // Files added
1057
+                $out.=load_fiche_titre($langs->trans("FilesAdded"));
1058
+
1059
+                $totalsize = 0;
1060
+                $out.='<div class="div-table-responsive-no-min">';
1061
+                $out.='<table class="noborder">';
1062
+                $out.='<tr class="liste_titre">';
1063
+                $out.='<td>#</td>';
1064
+                $out.='<td>' . $langs->trans("Filename") . '</td>';
1065
+                $out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>';
1066
+                $out.='<td align="center">' . $langs->trans("CurrentChecksum") . '</td>';
1067
+                $out.='<td align="right">' . $langs->trans("Size") . '</td>';
1068
+                $out.='<td align="right">' . $langs->trans("DateModification") . '</td>';
1069
+                $out.='</tr>'."\n";
1070
+                $tmpfilelist3 = dol_sort_array($file_list['added'], 'filename');
1071
+                if (is_array($tmpfilelist3) && count($tmpfilelist3))
1072
+                {
1073
+                    $i = 0;
1074
+                    foreach ($tmpfilelist3 as $file)
1075
+                    {
1076
+                        $i++;
1077
+                        $out.='<tr class="oddeven">';
1078
+                        $out.='<td>'.$i.'</td>' . "\n";
1079
+                        $out.='<td>'.$file['filename'].'</td>' . "\n";
1080
+                        $out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n";
1081
+                        $out.='<td align="center">'.$file['md5'].'</td>' . "\n";
1082
+                        $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
1083
+                        $totalsize += $size;
1084
+                        $out.='<td align="right">'.dol_print_size($size).'</td>' . "\n";
1085
+                        $out.='<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']),'dayhour').'</td>' . "\n";
1086
+                        $out.="</tr>\n";
1087
+                    }
1088
+                    $out.='<tr class="liste_total">';
1089
+                    $out.='<td></td>' . "\n";
1090
+                    $out.='<td>'.$langs->trans("Total").'</td>' . "\n";
1091
+                    $out.='<td align="center"></td>' . "\n";
1092
+                    $out.='<td align="center"></td>' . "\n";
1093
+                    $out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n";
1094
+                    $out.='<td align="right"></td>' . "\n";
1095
+                    $out.="</tr>\n";
1096
+                }
1097
+                else
1098
+                {
1099
+                    $out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1100
+                }
1101
+                $out.='</table>';
1102
+                $out.='</div>';
1103
+
1104
+
1105
+                // Show warning
1106
+                if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3))
1107
+                {
1108
+                    //setEventMessages($langs->trans("FileIntegrityIsStrictlyConformedWithReference"), null, 'mesgs');
1109
+                }
1110
+                else
1111
+                {
1112
+                    //setEventMessages($langs->trans("FileIntegritySomeFilesWereRemovedOrModified"), null, 'warnings');
1113
+                }
1114
+            }
1115
+            else
1116
+            {
1117
+                throw new RestException(500, 'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile);
1118
+            }
1119
+
1120
+
1121
+            // Scan scripts
1122
+
1123
+
1124
+            asort($checksumconcat); // Sort list of checksum
1125
+            //var_dump($checksumconcat);
1126
+            $checksumget = md5(join(',',$checksumconcat));
1127
+            $checksumtoget = trim((string) $xml->dolibarr_htdocs_dir_checksum);
1128
+
1129
+            $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans("Unknown"));
1130
+            if ($checksumget == $checksumtoget)
1131
+            {
1132
+                if (count($file_list['added']))
1133
+                {
1134
+                    $resultcode = 'warning';
1135
+                    $resultcomment='FileIntegrityIsOkButFilesWereAdded';
1136
+                    //$outcurrentchecksum =  $checksumget.' - <span class="'.$resultcode.'">'.$langs->trans("FileIntegrityIsOkButFilesWereAdded").'</span>';
1137
+                    $outcurrentchecksum =  $checksumget;
1138
+                }
1139
+                else
1140
+                {
1141
+                    $resultcode = 'ok';
1142
+                    $resultcomment='Success';
1143
+                    //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
1144
+                    $outcurrentchecksum =  $checksumget;
1145
+                }
1146
+            }
1147
+            else
1148
+            {
1149
+                $resultcode = 'error';
1150
+                $resultcomment='Error';
1151
+                //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
1152
+                $outcurrentchecksum =  $checksumget;
1153
+            }
1154
+        }
1155
+        else {
1156
+            throw new RestException(404, 'No signature file known');
1157
+        }
1158
+
1159
+        return array('resultcode'=>$resultcode, 'resultcomment'=>$resultcomment, 'expectedchecksum'=> $outexpectedchecksum, 'currentchecksum'=> $outcurrentchecksum, 'out'=>$out);
1160 1160
     }
1161 1161
 }
Please login to merge, or discard this patch.
Spacing   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -66,22 +66,22 @@  discard block
 block discarded – undo
66 66
         $list = array();
67 67
 
68 68
         $sql = "SELECT id, code, type, libelle as label, module";
69
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement as t";
70
-        $sql.= " WHERE t.entity IN (".getEntity('c_paiement').")";
71
-        $sql.= " AND t.active = ".$active;
69
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_paiement as t";
70
+        $sql .= " WHERE t.entity IN (".getEntity('c_paiement').")";
71
+        $sql .= " AND t.active = ".$active;
72 72
         // Add sql filters
73 73
         if ($sqlfilters)
74 74
         {
75
-            if (! DolibarrApi::_checkFilters($sqlfilters))
75
+            if (!DolibarrApi::_checkFilters($sqlfilters))
76 76
             {
77 77
                 throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters);
78 78
             }
79
-	          $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
80
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
79
+	          $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
80
+            $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
81 81
         }
82 82
 
83 83
 
84
-        $sql.= $this->db->order($sortfield, $sortorder);
84
+        $sql .= $this->db->order($sortfield, $sortorder);
85 85
 
86 86
         if ($limit) {
87 87
             if ($page < 0) {
@@ -135,19 +135,19 @@  discard block
 block discarded – undo
135 135
         // Note: The filter is not applied in the SQL request because it must
136 136
         // be applied to the translated names, not to the names in database.
137 137
         $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_country as t";
138
-        $sql.=" WHERE 1 = 1";
138
+        $sql .= " WHERE 1 = 1";
139 139
         // Add sql filters
140 140
         if ($sqlfilters)
141 141
         {
142
-            if (! DolibarrApi::_checkFilters($sqlfilters))
142
+            if (!DolibarrApi::_checkFilters($sqlfilters))
143 143
             {
144 144
                 throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
145 145
             }
146
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
147
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
146
+	        $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
147
+            $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
148 148
         }
149 149
 
150
-        $sql.= $this->db->order($sortfield, $sortorder);
150
+        $sql .= $this->db->order($sortfield, $sortorder);
151 151
 
152 152
         if ($limit) {
153 153
             if ($page < 0) {
@@ -233,21 +233,21 @@  discard block
 block discarded – undo
233 233
         $list = array();
234 234
 
235 235
         $sql = "SELECT rowid, code, label";
236
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_availability as t";
237
-        $sql.= " WHERE t.active = ".$active;
236
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_availability as t";
237
+        $sql .= " WHERE t.active = ".$active;
238 238
         // Add sql filters
239 239
         if ($sqlfilters)
240 240
         {
241
-            if (! DolibarrApi::_checkFilters($sqlfilters))
241
+            if (!DolibarrApi::_checkFilters($sqlfilters))
242 242
             {
243 243
                 throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters);
244 244
             }
245
-                  $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
246
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
245
+                  $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
246
+            $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
247 247
         }
248 248
 
249 249
 
250
-        $sql.= $this->db->order($sortfield, $sortorder);
250
+        $sql .= $this->db->order($sortfield, $sortorder);
251 251
 
252 252
         if ($limit) {
253 253
             if ($page < 0) {
@@ -338,23 +338,23 @@  discard block
 block discarded – undo
338 338
         $list = array();
339 339
 
340 340
         $sql = "SELECT id, code, type, libelle as label, module";
341
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t";
342
-        $sql.= " WHERE t.active = 1";
343
-        if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'";
344
-        if ($module)    $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'";
341
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t";
342
+        $sql .= " WHERE t.active = 1";
343
+        if ($type) $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'";
344
+        if ($module)    $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
345 345
         // Add sql filters
346 346
         if ($sqlfilters)
347 347
         {
348
-            if (! DolibarrApi::_checkFilters($sqlfilters))
348
+            if (!DolibarrApi::_checkFilters($sqlfilters))
349 349
             {
350 350
                 throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
351 351
             }
352
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
353
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
352
+	        $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
353
+            $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
354 354
         }
355 355
 
356 356
 
357
-        $sql.= $this->db->order($sortfield, $sortorder);
357
+        $sql .= $this->db->order($sortfield, $sortorder);
358 358
 
359 359
         if ($limit) {
360 360
             if ($page < 0) {
@@ -400,22 +400,22 @@  discard block
 block discarded – undo
400 400
         $list = array();
401 401
 
402 402
         $sql = "SELECT rowid, code, label, module";
403
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_civility as t";
404
-        $sql.= " WHERE t.active = 1";
405
-        if ($module)    $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'";
403
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_civility as t";
404
+        $sql .= " WHERE t.active = 1";
405
+        if ($module)    $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
406 406
         // Add sql filters
407 407
         if ($sqlfilters)
408 408
         {
409
-            if (! DolibarrApi::_checkFilters($sqlfilters))
409
+            if (!DolibarrApi::_checkFilters($sqlfilters))
410 410
             {
411 411
                 throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
412 412
             }
413
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
414
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
413
+	        $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
414
+            $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
415 415
         }
416 416
 
417 417
 
418
-        $sql.= $this->db->order($sortfield, $sortorder);
418
+        $sql .= $this->db->order($sortfield, $sortorder);
419 419
 
420 420
         if ($limit) {
421 421
             if ($page < 0) {
@@ -458,27 +458,27 @@  discard block
 block discarded – undo
458 458
     {
459 459
         $list = array();
460 460
 
461
-        if ($type == 'thirdparty') $type='societe';
462
-        if ($type == 'contact') $type='socpeople';
461
+        if ($type == 'thirdparty') $type = 'societe';
462
+        if ($type == 'contact') $type = 'socpeople';
463 463
 
464 464
         $sql = "SELECT t.rowid, t.name, t.label, t.type, t.size, t.elementtype, t.fieldunique, t.fieldrequired, t.param, t.pos, t.alwayseditable, t.perms, t.list, t.fielddefault, t.fieldcomputed";
465
-        $sql.= " FROM ".MAIN_DB_PREFIX."extrafields as t";
466
-        $sql.= " WHERE t.entity IN (".getEntity('extrafields').")";
467
-        if (! empty($type)) $sql.= " AND t.elementtype = '".$this->db->escape($type)."'";
465
+        $sql .= " FROM ".MAIN_DB_PREFIX."extrafields as t";
466
+        $sql .= " WHERE t.entity IN (".getEntity('extrafields').")";
467
+        if (!empty($type)) $sql .= " AND t.elementtype = '".$this->db->escape($type)."'";
468 468
         // Add sql filters
469 469
         if ($sqlfilters)
470 470
         {
471
-        	if (! DolibarrApi::_checkFilters($sqlfilters))
471
+        	if (!DolibarrApi::_checkFilters($sqlfilters))
472 472
         	{
473 473
         		throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
474 474
         	}
475
-        	$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
476
-        	$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
475
+        	$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
476
+        	$sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
477 477
         }
478 478
 
479
-        $sql.= $this->db->order($sortfield, $sortorder);
479
+        $sql .= $this->db->order($sortfield, $sortorder);
480 480
 
481
-        $resql=$this->db->query($sql);
481
+        $resql = $this->db->query($sql);
482 482
         if ($resql)
483 483
         {
484 484
         	if ($this->db->num_rows($resql))
@@ -486,19 +486,19 @@  discard block
 block discarded – undo
486 486
         		while ($tab = $this->db->fetch_object($resql))
487 487
         		{
488 488
         			// New usage
489
-        			$list[$tab->elementtype][$tab->name]['type']=$tab->type;
490
-        			$list[$tab->elementtype][$tab->name]['label']=$tab->label;
491
-        			$list[$tab->elementtype][$tab->name]['size']=$tab->size;
492
-        			$list[$tab->elementtype][$tab->name]['elementtype']=$tab->elementtype;
493
-        			$list[$tab->elementtype][$tab->name]['default']=$tab->fielddefault;
494
-        			$list[$tab->elementtype][$tab->name]['computed']=$tab->fieldcomputed;
495
-        			$list[$tab->elementtype][$tab->name]['unique']=$tab->fieldunique;
496
-        			$list[$tab->elementtype][$tab->name]['required']=$tab->fieldrequired;
497
-        			$list[$tab->elementtype][$tab->name]['param']=($tab->param ? unserialize($tab->param) : '');
498
-        			$list[$tab->elementtype][$tab->name]['pos']=$tab->pos;
499
-        			$list[$tab->elementtype][$tab->name]['alwayseditable']=$tab->alwayseditable;
500
-        			$list[$tab->elementtype][$tab->name]['perms']=$tab->perms;
501
-        			$list[$tab->elementtype][$tab->name]['list']=$tab->list;
489
+        			$list[$tab->elementtype][$tab->name]['type'] = $tab->type;
490
+        			$list[$tab->elementtype][$tab->name]['label'] = $tab->label;
491
+        			$list[$tab->elementtype][$tab->name]['size'] = $tab->size;
492
+        			$list[$tab->elementtype][$tab->name]['elementtype'] = $tab->elementtype;
493
+        			$list[$tab->elementtype][$tab->name]['default'] = $tab->fielddefault;
494
+        			$list[$tab->elementtype][$tab->name]['computed'] = $tab->fieldcomputed;
495
+        			$list[$tab->elementtype][$tab->name]['unique'] = $tab->fieldunique;
496
+        			$list[$tab->elementtype][$tab->name]['required'] = $tab->fieldrequired;
497
+        			$list[$tab->elementtype][$tab->name]['param'] = ($tab->param ? unserialize($tab->param) : '');
498
+        			$list[$tab->elementtype][$tab->name]['pos'] = $tab->pos;
499
+        			$list[$tab->elementtype][$tab->name]['alwayseditable'] = $tab->alwayseditable;
500
+        			$list[$tab->elementtype][$tab->name]['perms'] = $tab->perms;
501
+        			$list[$tab->elementtype][$tab->name]['list'] = $tab->list;
502 502
         		}
503 503
         	}
504 504
         }
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
             throw new RestException(503, 'Error when retrieving list of extra fields : '.$this->db->lasterror());
508 508
         }
509 509
 
510
-        if (! count($list))
510
+        if (!count($list))
511 511
         {
512 512
         	throw new RestException(404, 'No extrafield found');
513 513
         }
@@ -537,23 +537,23 @@  discard block
 block discarded – undo
537 537
         $list = array();
538 538
 
539 539
         $sql = "SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
540
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_ziptown as t";
541
-        $sql.= " WHERE t.active = 1";
542
-        if ($zipcode) $sql.=" AND t.zip LIKE '%" . $this->db->escape($zipcode) . "%'";
543
-        if ($town)    $sql.=" AND t.town LIKE '%" . $this->db->escape($town) . "%'";
540
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_ziptown as t";
541
+        $sql .= " WHERE t.active = 1";
542
+        if ($zipcode) $sql .= " AND t.zip LIKE '%".$this->db->escape($zipcode)."%'";
543
+        if ($town)    $sql .= " AND t.town LIKE '%".$this->db->escape($town)."%'";
544 544
         // Add sql filters
545 545
         if ($sqlfilters)
546 546
         {
547
-            if (! DolibarrApi::_checkFilters($sqlfilters))
547
+            if (!DolibarrApi::_checkFilters($sqlfilters))
548 548
             {
549 549
                 throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
550 550
             }
551
-	        $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
552
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
551
+	        $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
552
+            $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
553 553
         }
554 554
 
555 555
 
556
-        $sql.= $this->db->order($sortfield, $sortorder);
556
+        $sql .= $this->db->order($sortfield, $sortorder);
557 557
 
558 558
         if ($limit) {
559 559
             if ($page < 0) {
@@ -601,22 +601,22 @@  discard block
 block discarded – undo
601 601
         $list = array();
602 602
 
603 603
         $sql = "SELECT rowid as id, code, sortorder, libelle as label, libelle_facture as descr, type_cdr, nbjour, decalage, module";
604
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_payment_term as t";
605
-        $sql.= " WHERE t.entity IN (".getEntity('c_payment_term').")";
606
-        $sql.= " AND t.active = ".$active;
604
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_payment_term as t";
605
+        $sql .= " WHERE t.entity IN (".getEntity('c_payment_term').")";
606
+        $sql .= " AND t.active = ".$active;
607 607
         // Add sql filters
608 608
         if ($sqlfilters)
609 609
         {
610
-            if (! DolibarrApi::_checkFilters($sqlfilters))
610
+            if (!DolibarrApi::_checkFilters($sqlfilters))
611 611
             {
612 612
                 throw new RestException(400, 'Error when validating parameter sqlfilters '.$sqlfilters);
613 613
             }
614
-                $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
615
-            $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
614
+                $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
615
+            $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
616 616
         }
617 617
 
618 618
 
619
-        $sql.= $this->db->order($sortfield, $sortorder);
619
+        $sql .= $this->db->order($sortfield, $sortorder);
620 620
 
621 621
         if ($limit) {
622 622
             if ($page < 0) {
@@ -661,21 +661,21 @@  discard block
 block discarded – undo
661 661
     	$list = array();
662 662
 
663 663
     	$sql = "SELECT rowid, code, pos,  label, use_default, description";
664
-    	$sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t";
665
-    	$sql.= " WHERE t.active = 1";
664
+    	$sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t";
665
+    	$sql .= " WHERE t.active = 1";
666 666
     	// Add sql filters
667 667
     	if ($sqlfilters)
668 668
     	{
669
-    		if (! DolibarrApi::_checkFilters($sqlfilters))
669
+    		if (!DolibarrApi::_checkFilters($sqlfilters))
670 670
     		{
671 671
     			throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
672 672
     		}
673
-    		$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
674
-    		$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
673
+    		$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
674
+    		$sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
675 675
     	}
676 676
 
677 677
 
678
-    	$sql.= $this->db->order($sortfield, $sortorder);
678
+    	$sql .= $this->db->order($sortfield, $sortorder);
679 679
 
680 680
     	if ($limit) {
681 681
     		if ($page < 0) {
@@ -720,21 +720,21 @@  discard block
 block discarded – undo
720 720
     	$list = array();
721 721
 
722 722
     	$sql = "SELECT rowid, code, pos,  label, use_default, color, description";
723
-    	$sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t";
724
-    	$sql.= " WHERE t.active = 1";
723
+    	$sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t";
724
+    	$sql .= " WHERE t.active = 1";
725 725
     	// Add sql filters
726 726
     	if ($sqlfilters)
727 727
     	{
728
-    		if (! DolibarrApi::_checkFilters($sqlfilters))
728
+    		if (!DolibarrApi::_checkFilters($sqlfilters))
729 729
     		{
730 730
     			throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
731 731
     		}
732
-    		$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
733
-    		$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
732
+    		$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
733
+    		$sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
734 734
     	}
735 735
 
736 736
 
737
-    	$sql.= $this->db->order($sortfield, $sortorder);
737
+    	$sql .= $this->db->order($sortfield, $sortorder);
738 738
 
739 739
     	if ($limit) {
740 740
     		if ($page < 0) {
@@ -779,23 +779,23 @@  discard block
 block discarded – undo
779 779
     	$list = array();
780 780
 
781 781
     	$sql = "SELECT rowid, code, pos,  label, use_default, description";
782
-    	$sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_type as t";
783
-    	$sql.= " WHERE t.active = 1";
784
-    	if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'";
785
-    	if ($module)    $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'";
782
+    	$sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_type as t";
783
+    	$sql .= " WHERE t.active = 1";
784
+    	if ($type) $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'";
785
+    	if ($module)    $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
786 786
     	// Add sql filters
787 787
     	if ($sqlfilters)
788 788
     	{
789
-    		if (! DolibarrApi::_checkFilters($sqlfilters))
789
+    		if (!DolibarrApi::_checkFilters($sqlfilters))
790 790
     		{
791 791
     			throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
792 792
     		}
793
-    		$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
794
-    		$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
793
+    		$regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
794
+    		$sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
795 795
     	}
796 796
 
797 797
 
798
-    	$sql.= $this->db->order($sortfield, $sortorder);
798
+    	$sql .= $this->db->order($sortfield, $sortorder);
799 799
 
800 800
     	if ($limit) {
801 801
     		if ($page < 0) {
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
     {
837 837
     	global $langs, $conf;
838 838
 
839
-    	if (! DolibarrApiAccess::$user->admin
839
+    	if (!DolibarrApiAccess::$user->admin
840 840
     		&& (empty($conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK) || DolibarrApiAccess::$user->login != $conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK))
841 841
     	{
842 842
     		throw new RestException(503, 'Error API open to admin users only or to login user defined with constant API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK');
@@ -854,13 +854,13 @@  discard block
 block discarded – undo
854 854
     	$file_list = array('missing' => array(), 'updated' => array());
855 855
 
856 856
     	// Local file to compare to
857
-    	$xmlshortfile = GETPOST('xmlshortfile')?GETPOST('xmlshortfile'):'/install/filelist-'.DOL_VERSION.'.xml';
857
+    	$xmlshortfile = GETPOST('xmlshortfile') ?GETPOST('xmlshortfile') : '/install/filelist-'.DOL_VERSION.'.xml';
858 858
     	$xmlfile = DOL_DOCUMENT_ROOT.$xmlshortfile;
859 859
     	// Remote file to compare to
860 860
     	$xmlremote = ($target == 'default' ? '' : $target);
861
-    	if (empty($xmlremote) && ! empty($conf->global->MAIN_FILECHECK_URL)) $xmlremote = $conf->global->MAIN_FILECHECK_URL;
862
-    	$param='MAIN_FILECHECK_URL_'.DOL_VERSION;
863
-    	if (empty($xmlremote) && ! empty($conf->global->$param)) $xmlremote = $conf->global->$param;
861
+    	if (empty($xmlremote) && !empty($conf->global->MAIN_FILECHECK_URL)) $xmlremote = $conf->global->MAIN_FILECHECK_URL;
862
+    	$param = 'MAIN_FILECHECK_URL_'.DOL_VERSION;
863
+    	if (empty($xmlremote) && !empty($conf->global->$param)) $xmlremote = $conf->global->$param;
864 864
     	if (empty($xmlremote)) $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml';
865 865
 
866 866
     	if ($target == 'local')
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
     		}
872 872
     		else
873 873
     		{
874
-    			throw new RestException(500, $langs->trans('XmlNotFound') . ': ' . $xmlfile);
874
+    			throw new RestException(500, $langs->trans('XmlNotFound').': '.$xmlfile);
875 875
     		}
876 876
     	}
877 877
     	else
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
     		$xmlarray = getURLContent($xmlremote);
880 880
 
881 881
     		// Return array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...)
882
-    		if (! $xmlarray['curl_error_no'] && $xmlarray['http_code'] != '404')
882
+    		if (!$xmlarray['curl_error_no'] && $xmlarray['http_code'] != '404')
883 883
     		{
884 884
     			$xmlfile = $xmlarray['content'];
885 885
     			//print "xmlfilestart".$xmlfile."endxmlfile";
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
     		}
888 888
     		else
889 889
     		{
890
-    			$errormsg=$langs->trans('XmlNotFound') . ': ' . $xmlremote.' - '.$xmlarray['http_code'].' '.$xmlarray['curl_error_no'].' '.$xmlarray['curl_error_msg'];
890
+    			$errormsg = $langs->trans('XmlNotFound').': '.$xmlremote.' - '.$xmlarray['http_code'].' '.$xmlarray['curl_error_no'].' '.$xmlarray['curl_error_msg'];
891 891
     			throw new RestException(500, $errormsg);
892 892
     		}
893 893
     	}
@@ -903,83 +903,83 @@  discard block
 block discarded – undo
903 903
     		// Forced constants
904 904
     		if (is_object($xml->dolibarr_constants[0]))
905 905
     		{
906
-    			$out.=load_fiche_titre($langs->trans("ForcedConstants"));
906
+    			$out .= load_fiche_titre($langs->trans("ForcedConstants"));
907 907
 
908
-    			$out.='<div class="div-table-responsive-no-min">';
909
-    			$out.='<table class="noborder">';
910
-    			$out.='<tr class="liste_titre">';
911
-    			$out.='<td>#</td>';
912
-    			$out.='<td>' . $langs->trans("Constant") . '</td>';
913
-    			$out.='<td align="center">' . $langs->trans("ExpectedValue") . '</td>';
914
-    			$out.='<td align="center">' . $langs->trans("Value") . '</td>';
915
-    			$out.='</tr>'."\n";
908
+    			$out .= '<div class="div-table-responsive-no-min">';
909
+    			$out .= '<table class="noborder">';
910
+    			$out .= '<tr class="liste_titre">';
911
+    			$out .= '<td>#</td>';
912
+    			$out .= '<td>'.$langs->trans("Constant").'</td>';
913
+    			$out .= '<td align="center">'.$langs->trans("ExpectedValue").'</td>';
914
+    			$out .= '<td align="center">'.$langs->trans("Value").'</td>';
915
+    			$out .= '</tr>'."\n";
916 916
 
917 917
     			$i = 0;
918 918
     			foreach ($xml->dolibarr_constants[0]->constant as $constant)    // $constant is a simpleXMLElement
919 919
     			{
920
-    				$constname=$constant['name'];
921
-    				$constvalue=(string) $constant;
922
-    				$constvalue = (empty($constvalue)?'0':$constvalue);
920
+    				$constname = $constant['name'];
921
+    				$constvalue = (string) $constant;
922
+    				$constvalue = (empty($constvalue) ? '0' : $constvalue);
923 923
     				// Value found
924
-    				$value='';
925
-    				if ($constname && $conf->global->$constname != '') $value=$conf->global->$constname;
926
-    				$valueforchecksum=(empty($value)?'0':$value);
924
+    				$value = '';
925
+    				if ($constname && $conf->global->$constname != '') $value = $conf->global->$constname;
926
+    				$valueforchecksum = (empty($value) ? '0' : $value);
927 927
 
928
-    				$checksumconcat[]=$valueforchecksum;
928
+    				$checksumconcat[] = $valueforchecksum;
929 929
 
930 930
     				$i++;
931
-    				$out.='<tr class="oddeven">';
932
-    				$out.='<td>'.$i.'</td>' . "\n";
933
-    				$out.='<td>'.$constname.'</td>' . "\n";
934
-    				$out.='<td align="center">'.$constvalue.'</td>' . "\n";
935
-    				$out.='<td align="center">'.$valueforchecksum.'</td>' . "\n";
936
-    				$out.="</tr>\n";
931
+    				$out .= '<tr class="oddeven">';
932
+    				$out .= '<td>'.$i.'</td>'."\n";
933
+    				$out .= '<td>'.$constname.'</td>'."\n";
934
+    				$out .= '<td align="center">'.$constvalue.'</td>'."\n";
935
+    				$out .= '<td align="center">'.$valueforchecksum.'</td>'."\n";
936
+    				$out .= "</tr>\n";
937 937
     			}
938 938
 
939
-    			if ($i==0)
939
+    			if ($i == 0)
940 940
     			{
941
-    				$out.='<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
941
+    				$out .= '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
942 942
     			}
943
-    			$out.='</table>';
944
-    			$out.='</div>';
943
+    			$out .= '</table>';
944
+    			$out .= '</div>';
945 945
 
946
-    			$out.='<br>';
946
+    			$out .= '<br>';
947 947
     		}
948 948
 
949 949
     		// Scan htdocs
950 950
     		if (is_object($xml->dolibarr_htdocs_dir[0]))
951 951
     		{
952 952
     			//var_dump($xml->dolibarr_htdocs_dir[0]['includecustom']);exit;
953
-    			$includecustom=(empty($xml->dolibarr_htdocs_dir[0]['includecustom'])?0:$xml->dolibarr_htdocs_dir[0]['includecustom']);
953
+    			$includecustom = (empty($xml->dolibarr_htdocs_dir[0]['includecustom']) ? 0 : $xml->dolibarr_htdocs_dir[0]['includecustom']);
954 954
 
955 955
     			// Defined qualified files (must be same than into generate_filelist_xml.php)
956
-    			$regextoinclude='\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$';
957
-    			$regextoexclude='('.($includecustom?'':'custom|').'documents|conf|install|public\/test|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$';  // Exclude dirs
956
+    			$regextoinclude = '\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$';
957
+    			$regextoexclude = '('.($includecustom ? '' : 'custom|').'documents|conf|install|public\/test|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs
958 958
     			$scanfiles = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude);
959 959
 
960 960
     			// Fill file_list with files in signature, new files, modified files
961
-    			$ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat, $scanfiles);		// Fill array $file_list
961
+    			$ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat, $scanfiles); // Fill array $file_list
962 962
     			// Complete with list of new files
963 963
     			foreach ($scanfiles as $keyfile => $valfile)
964 964
     			{
965
-    				$tmprelativefilename=preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT,'/').'/','', $valfile['fullname']);
966
-    				if (! in_array($tmprelativefilename, $file_list['insignature']))
965
+    				$tmprelativefilename = preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT, '/').'/', '', $valfile['fullname']);
966
+    				if (!in_array($tmprelativefilename, $file_list['insignature']))
967 967
     				{
968
-    					$md5newfile=@md5_file($valfile['fullname']);    // Can fails if we don't have permission to open/read file
969
-    					$file_list['added'][]=array('filename'=>$tmprelativefilename, 'md5'=>$md5newfile);
968
+    					$md5newfile = @md5_file($valfile['fullname']); // Can fails if we don't have permission to open/read file
969
+    					$file_list['added'][] = array('filename'=>$tmprelativefilename, 'md5'=>$md5newfile);
970 970
     				}
971 971
     			}
972 972
 
973 973
     			// Files missings
974
-    			$out.=load_fiche_titre($langs->trans("FilesMissing"));
975
-
976
-    			$out.='<div class="div-table-responsive-no-min">';
977
-    			$out.='<table class="noborder">';
978
-    			$out.='<tr class="liste_titre">';
979
-    			$out.='<td>#</td>';
980
-    			$out.='<td>' . $langs->trans("Filename") . '</td>';
981
-    			$out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>';
982
-    			$out.='</tr>'."\n";
974
+    			$out .= load_fiche_titre($langs->trans("FilesMissing"));
975
+
976
+    			$out .= '<div class="div-table-responsive-no-min">';
977
+    			$out .= '<table class="noborder">';
978
+    			$out .= '<tr class="liste_titre">';
979
+    			$out .= '<td>#</td>';
980
+    			$out .= '<td>'.$langs->trans("Filename").'</td>';
981
+    			$out .= '<td align="center">'.$langs->trans("ExpectedChecksum").'</td>';
982
+    			$out .= '</tr>'."\n";
983 983
     			$tmpfilelist = dol_sort_array($file_list['missing'], 'filename');
984 984
     			if (is_array($tmpfilelist) && count($tmpfilelist))
985 985
     			{
@@ -987,36 +987,36 @@  discard block
 block discarded – undo
987 987
     				foreach ($tmpfilelist as $file)
988 988
     				{
989 989
     					$i++;
990
-    					$out.='<tr class="oddeven">';
991
-    					$out.='<td>'.$i.'</td>' . "\n";
992
-    					$out.='<td>'.$file['filename'].'</td>' . "\n";
993
-    					$out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n";
994
-    					$out.="</tr>\n";
990
+    					$out .= '<tr class="oddeven">';
991
+    					$out .= '<td>'.$i.'</td>'."\n";
992
+    					$out .= '<td>'.$file['filename'].'</td>'."\n";
993
+    					$out .= '<td align="center">'.$file['expectedmd5'].'</td>'."\n";
994
+    					$out .= "</tr>\n";
995 995
     				}
996 996
     			}
997 997
     			else
998 998
     			{
999
-    				$out.='<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
999
+    				$out .= '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1000 1000
     			}
1001
-    			$out.='</table>';
1002
-    			$out.='</div>';
1001
+    			$out .= '</table>';
1002
+    			$out .= '</div>';
1003 1003
 
1004
-    			$out.='<br>';
1004
+    			$out .= '<br>';
1005 1005
 
1006 1006
     			// Files modified
1007
-    			$out.=load_fiche_titre($langs->trans("FilesModified"));
1008
-
1009
-    			$totalsize=0;
1010
-    			$out.='<div class="div-table-responsive-no-min">';
1011
-    			$out.='<table class="noborder">';
1012
-    			$out.='<tr class="liste_titre">';
1013
-    			$out.='<td>#</td>';
1014
-    			$out.='<td>' . $langs->trans("Filename") . '</td>';
1015
-    			$out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>';
1016
-    			$out.='<td align="center">' . $langs->trans("CurrentChecksum") . '</td>';
1017
-    			$out.='<td align="right">' . $langs->trans("Size") . '</td>';
1018
-    			$out.='<td align="right">' . $langs->trans("DateModification") . '</td>';
1019
-    			$out.='</tr>'."\n";
1007
+    			$out .= load_fiche_titre($langs->trans("FilesModified"));
1008
+
1009
+    			$totalsize = 0;
1010
+    			$out .= '<div class="div-table-responsive-no-min">';
1011
+    			$out .= '<table class="noborder">';
1012
+    			$out .= '<tr class="liste_titre">';
1013
+    			$out .= '<td>#</td>';
1014
+    			$out .= '<td>'.$langs->trans("Filename").'</td>';
1015
+    			$out .= '<td align="center">'.$langs->trans("ExpectedChecksum").'</td>';
1016
+    			$out .= '<td align="center">'.$langs->trans("CurrentChecksum").'</td>';
1017
+    			$out .= '<td align="right">'.$langs->trans("Size").'</td>';
1018
+    			$out .= '<td align="right">'.$langs->trans("DateModification").'</td>';
1019
+    			$out .= '</tr>'."\n";
1020 1020
     			$tmpfilelist2 = dol_sort_array($file_list['updated'], 'filename');
1021 1021
     			if (is_array($tmpfilelist2) && count($tmpfilelist2))
1022 1022
     			{
@@ -1024,49 +1024,49 @@  discard block
 block discarded – undo
1024 1024
     				foreach ($tmpfilelist2 as $file)
1025 1025
     				{
1026 1026
     					$i++;
1027
-    					$out.='<tr class="oddeven">';
1028
-    					$out.='<td>'.$i.'</td>' . "\n";
1029
-    					$out.='<td>'.$file['filename'].'</td>' . "\n";
1030
-    					$out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n";
1031
-    					$out.='<td align="center">'.$file['md5'].'</td>' . "\n";
1027
+    					$out .= '<tr class="oddeven">';
1028
+    					$out .= '<td>'.$i.'</td>'."\n";
1029
+    					$out .= '<td>'.$file['filename'].'</td>'."\n";
1030
+    					$out .= '<td align="center">'.$file['expectedmd5'].'</td>'."\n";
1031
+    					$out .= '<td align="center">'.$file['md5'].'</td>'."\n";
1032 1032
     					$size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
1033 1033
     					$totalsize += $size;
1034
-    					$out.='<td align="right">'.dol_print_size($size).'</td>' . "\n";
1035
-    					$out.='<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']),'dayhour').'</td>' . "\n";
1036
-    					$out.="</tr>\n";
1034
+    					$out .= '<td align="right">'.dol_print_size($size).'</td>'."\n";
1035
+    					$out .= '<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']), 'dayhour').'</td>'."\n";
1036
+    					$out .= "</tr>\n";
1037 1037
     				}
1038
-    				$out.='<tr class="liste_total">';
1039
-    				$out.='<td></td>' . "\n";
1040
-    				$out.='<td>'.$langs->trans("Total").'</td>' . "\n";
1041
-    				$out.='<td align="center"></td>' . "\n";
1042
-    				$out.='<td align="center"></td>' . "\n";
1043
-    				$out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n";
1044
-    				$out.='<td align="right"></td>' . "\n";
1045
-    				$out.="</tr>\n";
1038
+    				$out .= '<tr class="liste_total">';
1039
+    				$out .= '<td></td>'."\n";
1040
+    				$out .= '<td>'.$langs->trans("Total").'</td>'."\n";
1041
+    				$out .= '<td align="center"></td>'."\n";
1042
+    				$out .= '<td align="center"></td>'."\n";
1043
+    				$out .= '<td align="right">'.dol_print_size($totalsize).'</td>'."\n";
1044
+    				$out .= '<td align="right"></td>'."\n";
1045
+    				$out .= "</tr>\n";
1046 1046
     			}
1047 1047
     			else
1048 1048
     			{
1049
-    				$out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1049
+    				$out .= '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1050 1050
     			}
1051
-    			$out.='</table>';
1052
-    			$out.='</div>';
1051
+    			$out .= '</table>';
1052
+    			$out .= '</div>';
1053 1053
 
1054
-    			$out.='<br>';
1054
+    			$out .= '<br>';
1055 1055
 
1056 1056
     			// Files added
1057
-    			$out.=load_fiche_titre($langs->trans("FilesAdded"));
1057
+    			$out .= load_fiche_titre($langs->trans("FilesAdded"));
1058 1058
 
1059 1059
     			$totalsize = 0;
1060
-    			$out.='<div class="div-table-responsive-no-min">';
1061
-    			$out.='<table class="noborder">';
1062
-    			$out.='<tr class="liste_titre">';
1063
-    			$out.='<td>#</td>';
1064
-    			$out.='<td>' . $langs->trans("Filename") . '</td>';
1065
-    			$out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>';
1066
-    			$out.='<td align="center">' . $langs->trans("CurrentChecksum") . '</td>';
1067
-    			$out.='<td align="right">' . $langs->trans("Size") . '</td>';
1068
-    			$out.='<td align="right">' . $langs->trans("DateModification") . '</td>';
1069
-    			$out.='</tr>'."\n";
1060
+    			$out .= '<div class="div-table-responsive-no-min">';
1061
+    			$out .= '<table class="noborder">';
1062
+    			$out .= '<tr class="liste_titre">';
1063
+    			$out .= '<td>#</td>';
1064
+    			$out .= '<td>'.$langs->trans("Filename").'</td>';
1065
+    			$out .= '<td align="center">'.$langs->trans("ExpectedChecksum").'</td>';
1066
+    			$out .= '<td align="center">'.$langs->trans("CurrentChecksum").'</td>';
1067
+    			$out .= '<td align="right">'.$langs->trans("Size").'</td>';
1068
+    			$out .= '<td align="right">'.$langs->trans("DateModification").'</td>';
1069
+    			$out .= '</tr>'."\n";
1070 1070
     			$tmpfilelist3 = dol_sort_array($file_list['added'], 'filename');
1071 1071
     			if (is_array($tmpfilelist3) && count($tmpfilelist3))
1072 1072
     			{
@@ -1074,32 +1074,32 @@  discard block
 block discarded – undo
1074 1074
     				foreach ($tmpfilelist3 as $file)
1075 1075
     				{
1076 1076
     					$i++;
1077
-    					$out.='<tr class="oddeven">';
1078
-    					$out.='<td>'.$i.'</td>' . "\n";
1079
-    					$out.='<td>'.$file['filename'].'</td>' . "\n";
1080
-    					$out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n";
1081
-    					$out.='<td align="center">'.$file['md5'].'</td>' . "\n";
1077
+    					$out .= '<tr class="oddeven">';
1078
+    					$out .= '<td>'.$i.'</td>'."\n";
1079
+    					$out .= '<td>'.$file['filename'].'</td>'."\n";
1080
+    					$out .= '<td align="center">'.$file['expectedmd5'].'</td>'."\n";
1081
+    					$out .= '<td align="center">'.$file['md5'].'</td>'."\n";
1082 1082
     					$size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
1083 1083
     					$totalsize += $size;
1084
-    					$out.='<td align="right">'.dol_print_size($size).'</td>' . "\n";
1085
-    					$out.='<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']),'dayhour').'</td>' . "\n";
1086
-    					$out.="</tr>\n";
1084
+    					$out .= '<td align="right">'.dol_print_size($size).'</td>'."\n";
1085
+    					$out .= '<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']), 'dayhour').'</td>'."\n";
1086
+    					$out .= "</tr>\n";
1087 1087
     				}
1088
-    				$out.='<tr class="liste_total">';
1089
-    				$out.='<td></td>' . "\n";
1090
-    				$out.='<td>'.$langs->trans("Total").'</td>' . "\n";
1091
-    				$out.='<td align="center"></td>' . "\n";
1092
-    				$out.='<td align="center"></td>' . "\n";
1093
-    				$out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n";
1094
-    				$out.='<td align="right"></td>' . "\n";
1095
-    				$out.="</tr>\n";
1088
+    				$out .= '<tr class="liste_total">';
1089
+    				$out .= '<td></td>'."\n";
1090
+    				$out .= '<td>'.$langs->trans("Total").'</td>'."\n";
1091
+    				$out .= '<td align="center"></td>'."\n";
1092
+    				$out .= '<td align="center"></td>'."\n";
1093
+    				$out .= '<td align="right">'.dol_print_size($totalsize).'</td>'."\n";
1094
+    				$out .= '<td align="right"></td>'."\n";
1095
+    				$out .= "</tr>\n";
1096 1096
     			}
1097 1097
     			else
1098 1098
     			{
1099
-    				$out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1099
+    				$out .= '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1100 1100
     			}
1101
-    			$out.='</table>';
1102
-    			$out.='</div>';
1101
+    			$out .= '</table>';
1102
+    			$out .= '</div>';
1103 1103
 
1104 1104
 
1105 1105
     			// Show warning
@@ -1123,7 +1123,7 @@  discard block
 block discarded – undo
1123 1123
 
1124 1124
     		asort($checksumconcat); // Sort list of checksum
1125 1125
     		//var_dump($checksumconcat);
1126
-    		$checksumget = md5(join(',',$checksumconcat));
1126
+    		$checksumget = md5(join(',', $checksumconcat));
1127 1127
     		$checksumtoget = trim((string) $xml->dolibarr_htdocs_dir_checksum);
1128 1128
 
1129 1129
     		$outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans("Unknown"));
@@ -1132,24 +1132,24 @@  discard block
 block discarded – undo
1132 1132
     			if (count($file_list['added']))
1133 1133
     			{
1134 1134
     				$resultcode = 'warning';
1135
-    				$resultcomment='FileIntegrityIsOkButFilesWereAdded';
1135
+    				$resultcomment = 'FileIntegrityIsOkButFilesWereAdded';
1136 1136
     				//$outcurrentchecksum =  $checksumget.' - <span class="'.$resultcode.'">'.$langs->trans("FileIntegrityIsOkButFilesWereAdded").'</span>';
1137
-    				$outcurrentchecksum =  $checksumget;
1137
+    				$outcurrentchecksum = $checksumget;
1138 1138
     			}
1139 1139
     			else
1140 1140
     			{
1141 1141
     				$resultcode = 'ok';
1142
-    				$resultcomment='Success';
1142
+    				$resultcomment = 'Success';
1143 1143
     				//$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
1144
-    				$outcurrentchecksum =  $checksumget;
1144
+    				$outcurrentchecksum = $checksumget;
1145 1145
     			}
1146 1146
     		}
1147 1147
     		else
1148 1148
     		{
1149 1149
     			$resultcode = 'error';
1150
-    			$resultcomment='Error';
1150
+    			$resultcomment = 'Error';
1151 1151
     			//$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
1152
-    			$outcurrentchecksum =  $checksumget;
1152
+    			$outcurrentchecksum = $checksumget;
1153 1153
     		}
1154 1154
     	}
1155 1155
     	else {
Please login to merge, or discard this patch.
Braces   +58 added lines, -41 removed lines patch added patch discarded remove patch
@@ -201,8 +201,7 @@  discard block
 block discarded – undo
201 201
 
202 202
         if ($country->fetch($id) < 0) {
203 203
             throw new RestException(503, 'Error when retrieving country : '.$country->error);
204
-        }
205
-        else if ($country->fetch($id) == 0) {
204
+        } else if ($country->fetch($id) == 0) {
206 205
             throw new RestException(404, 'country not found');
207 206
         }
208 207
 
@@ -340,8 +339,12 @@  discard block
 block discarded – undo
340 339
         $sql = "SELECT id, code, type, libelle as label, module";
341 340
         $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t";
342 341
         $sql.= " WHERE t.active = 1";
343
-        if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'";
344
-        if ($module)    $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'";
342
+        if ($type) {
343
+            $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'";
344
+        }
345
+        if ($module) {
346
+            $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'";
347
+        }
345 348
         // Add sql filters
346 349
         if ($sqlfilters)
347 350
         {
@@ -402,7 +405,9 @@  discard block
 block discarded – undo
402 405
         $sql = "SELECT rowid, code, label, module";
403 406
         $sql.= " FROM ".MAIN_DB_PREFIX."c_civility as t";
404 407
         $sql.= " WHERE t.active = 1";
405
-        if ($module)    $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'";
408
+        if ($module) {
409
+            $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'";
410
+        }
406 411
         // Add sql filters
407 412
         if ($sqlfilters)
408 413
         {
@@ -458,13 +463,19 @@  discard block
 block discarded – undo
458 463
     {
459 464
         $list = array();
460 465
 
461
-        if ($type == 'thirdparty') $type='societe';
462
-        if ($type == 'contact') $type='socpeople';
466
+        if ($type == 'thirdparty') {
467
+            $type='societe';
468
+        }
469
+        if ($type == 'contact') {
470
+            $type='socpeople';
471
+        }
463 472
 
464 473
         $sql = "SELECT t.rowid, t.name, t.label, t.type, t.size, t.elementtype, t.fieldunique, t.fieldrequired, t.param, t.pos, t.alwayseditable, t.perms, t.list, t.fielddefault, t.fieldcomputed";
465 474
         $sql.= " FROM ".MAIN_DB_PREFIX."extrafields as t";
466 475
         $sql.= " WHERE t.entity IN (".getEntity('extrafields').")";
467
-        if (! empty($type)) $sql.= " AND t.elementtype = '".$this->db->escape($type)."'";
476
+        if (! empty($type)) {
477
+            $sql.= " AND t.elementtype = '".$this->db->escape($type)."'";
478
+        }
468 479
         // Add sql filters
469 480
         if ($sqlfilters)
470 481
         {
@@ -501,8 +512,7 @@  discard block
 block discarded – undo
501 512
         			$list[$tab->elementtype][$tab->name]['list']=$tab->list;
502 513
         		}
503 514
         	}
504
-        }
505
-        else
515
+        } else
506 516
         {
507 517
             throw new RestException(503, 'Error when retrieving list of extra fields : '.$this->db->lasterror());
508 518
         }
@@ -539,8 +549,12 @@  discard block
 block discarded – undo
539 549
         $sql = "SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
540 550
         $sql.= " FROM ".MAIN_DB_PREFIX."c_ziptown as t";
541 551
         $sql.= " WHERE t.active = 1";
542
-        if ($zipcode) $sql.=" AND t.zip LIKE '%" . $this->db->escape($zipcode) . "%'";
543
-        if ($town)    $sql.=" AND t.town LIKE '%" . $this->db->escape($town) . "%'";
552
+        if ($zipcode) {
553
+            $sql.=" AND t.zip LIKE '%" . $this->db->escape($zipcode) . "%'";
554
+        }
555
+        if ($town) {
556
+            $sql.=" AND t.town LIKE '%" . $this->db->escape($town) . "%'";
557
+        }
544 558
         // Add sql filters
545 559
         if ($sqlfilters)
546 560
         {
@@ -781,8 +795,12 @@  discard block
 block discarded – undo
781 795
     	$sql = "SELECT rowid, code, pos,  label, use_default, description";
782 796
     	$sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_type as t";
783 797
     	$sql.= " WHERE t.active = 1";
784
-    	if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'";
785
-    	if ($module)    $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'";
798
+    	if ($type) {
799
+    	    $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'";
800
+    	}
801
+    	if ($module) {
802
+    	    $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'";
803
+    	}
786 804
     	// Add sql filters
787 805
     	if ($sqlfilters)
788 806
     	{
@@ -858,23 +876,27 @@  discard block
 block discarded – undo
858 876
     	$xmlfile = DOL_DOCUMENT_ROOT.$xmlshortfile;
859 877
     	// Remote file to compare to
860 878
     	$xmlremote = ($target == 'default' ? '' : $target);
861
-    	if (empty($xmlremote) && ! empty($conf->global->MAIN_FILECHECK_URL)) $xmlremote = $conf->global->MAIN_FILECHECK_URL;
879
+    	if (empty($xmlremote) && ! empty($conf->global->MAIN_FILECHECK_URL)) {
880
+    	    $xmlremote = $conf->global->MAIN_FILECHECK_URL;
881
+    	}
862 882
     	$param='MAIN_FILECHECK_URL_'.DOL_VERSION;
863
-    	if (empty($xmlremote) && ! empty($conf->global->$param)) $xmlremote = $conf->global->$param;
864
-    	if (empty($xmlremote)) $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml';
883
+    	if (empty($xmlremote) && ! empty($conf->global->$param)) {
884
+    	    $xmlremote = $conf->global->$param;
885
+    	}
886
+    	if (empty($xmlremote)) {
887
+    	    $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml';
888
+    	}
865 889
 
866 890
     	if ($target == 'local')
867 891
     	{
868 892
     		if (dol_is_file($xmlfile))
869 893
     		{
870 894
     			$xml = simplexml_load_file($xmlfile);
871
-    		}
872
-    		else
895
+    		} else
873 896
     		{
874 897
     			throw new RestException(500, $langs->trans('XmlNotFound') . ': ' . $xmlfile);
875 898
     		}
876
-    	}
877
-    	else
899
+    	} else
878 900
     	{
879 901
     		$xmlarray = getURLContent($xmlremote);
880 902
 
@@ -884,8 +906,7 @@  discard block
 block discarded – undo
884 906
     			$xmlfile = $xmlarray['content'];
885 907
     			//print "xmlfilestart".$xmlfile."endxmlfile";
886 908
     			$xml = simplexml_load_string($xmlfile);
887
-    		}
888
-    		else
909
+    		} else
889 910
     		{
890 911
     			$errormsg=$langs->trans('XmlNotFound') . ': ' . $xmlremote.' - '.$xmlarray['http_code'].' '.$xmlarray['curl_error_no'].' '.$xmlarray['curl_error_msg'];
891 912
     			throw new RestException(500, $errormsg);
@@ -915,14 +936,18 @@  discard block
 block discarded – undo
915 936
     			$out.='</tr>'."\n";
916 937
 
917 938
     			$i = 0;
918
-    			foreach ($xml->dolibarr_constants[0]->constant as $constant)    // $constant is a simpleXMLElement
939
+    			foreach ($xml->dolibarr_constants[0]->constant as $constant) {
940
+    			    // $constant is a simpleXMLElement
919 941
     			{
920 942
     				$constname=$constant['name'];
943
+    			}
921 944
     				$constvalue=(string) $constant;
922 945
     				$constvalue = (empty($constvalue)?'0':$constvalue);
923 946
     				// Value found
924 947
     				$value='';
925
-    				if ($constname && $conf->global->$constname != '') $value=$conf->global->$constname;
948
+    				if ($constname && $conf->global->$constname != '') {
949
+    				    $value=$conf->global->$constname;
950
+    				}
926 951
     				$valueforchecksum=(empty($value)?'0':$value);
927 952
 
928 953
     				$checksumconcat[]=$valueforchecksum;
@@ -993,8 +1018,7 @@  discard block
 block discarded – undo
993 1018
     					$out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n";
994 1019
     					$out.="</tr>\n";
995 1020
     				}
996
-    			}
997
-    			else
1021
+    			} else
998 1022
     			{
999 1023
     				$out.='<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1000 1024
     			}
@@ -1043,8 +1067,7 @@  discard block
 block discarded – undo
1043 1067
     				$out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n";
1044 1068
     				$out.='<td align="right"></td>' . "\n";
1045 1069
     				$out.="</tr>\n";
1046
-    			}
1047
-    			else
1070
+    			} else
1048 1071
     			{
1049 1072
     				$out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1050 1073
     			}
@@ -1093,8 +1116,7 @@  discard block
 block discarded – undo
1093 1116
     				$out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n";
1094 1117
     				$out.='<td align="right"></td>' . "\n";
1095 1118
     				$out.="</tr>\n";
1096
-    			}
1097
-    			else
1119
+    			} else
1098 1120
     			{
1099 1121
     				$out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1100 1122
     			}
@@ -1106,13 +1128,11 @@  discard block
 block discarded – undo
1106 1128
     			if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3))
1107 1129
     			{
1108 1130
     				//setEventMessages($langs->trans("FileIntegrityIsStrictlyConformedWithReference"), null, 'mesgs');
1109
-    			}
1110
-    			else
1131
+    			} else
1111 1132
     			{
1112 1133
     				//setEventMessages($langs->trans("FileIntegritySomeFilesWereRemovedOrModified"), null, 'warnings');
1113 1134
     			}
1114
-    		}
1115
-    		else
1135
+    		} else
1116 1136
     		{
1117 1137
     			throw new RestException(500, 'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile);
1118 1138
     		}
@@ -1135,24 +1155,21 @@  discard block
 block discarded – undo
1135 1155
     				$resultcomment='FileIntegrityIsOkButFilesWereAdded';
1136 1156
     				//$outcurrentchecksum =  $checksumget.' - <span class="'.$resultcode.'">'.$langs->trans("FileIntegrityIsOkButFilesWereAdded").'</span>';
1137 1157
     				$outcurrentchecksum =  $checksumget;
1138
-    			}
1139
-    			else
1158
+    			} else
1140 1159
     			{
1141 1160
     				$resultcode = 'ok';
1142 1161
     				$resultcomment='Success';
1143 1162
     				//$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
1144 1163
     				$outcurrentchecksum =  $checksumget;
1145 1164
     			}
1146
-    		}
1147
-    		else
1165
+    		} else
1148 1166
     		{
1149 1167
     			$resultcode = 'error';
1150 1168
     			$resultcomment='Error';
1151 1169
     			//$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
1152 1170
     			$outcurrentchecksum =  $checksumget;
1153 1171
     		}
1154
-    	}
1155
-    	else {
1172
+    	} else {
1156 1173
     		throw new RestException(404, 'No signature file known');
1157 1174
     	}
1158 1175
 
Please login to merge, or discard this patch.
dolibarr/htdocs/api/class/api_status.class.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16
  */
17 17
 
18
-require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
18
+require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
19 19
 
20 20
 
21 21
 /**
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
             'success' => array(
40 40
                 'code' => 200,
41 41
                 'dolibarr_version' => DOL_VERSION,
42
-                'access_locked' => (empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)?'0':$conf->global->MAIN_ONLY_LOGIN_ALLOWED),
42
+                'access_locked' => (empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED) ? '0' : $conf->global->MAIN_ONLY_LOGIN_ALLOWED),
43 43
             ),
44 44
         );
45 45
     }
Please login to merge, or discard this patch.
dolibarr/htdocs/api/class/api_documents.class.php 3 patches
Indentation   +550 added lines, -550 removed lines patch added patch discarded remove patch
@@ -33,563 +33,563 @@
 block discarded – undo
33 33
 class Documents extends DolibarrApi
34 34
 {
35 35
 
36
-	/**
37
-	 * @var array   $DOCUMENT_FIELDS     Mandatory fields, checked when create and update object
38
-	 */
39
-	static $DOCUMENT_FIELDS = array(
40
-		'modulepart'
41
-	);
42
-
43
-	/**
44
-	 * Constructor
45
-	 */
46
-	function __construct()
47
-	{
48
-		global $db;
49
-		$this->db = $db;
50
-	}
51
-
52
-
53
-	/**
54
-	 * Download a document.
55
-	 *
56
-	 * Note that, this API is similar to using the wrapper link "documents.php" to download a file (used for
57
-	 * internal HTML links of documents into application), but with no need to have a session cookie (the token is used instead).
58
-	 *
59
-	 * @param   string  $module_part    Name of module or area concerned by file download ('facture', ...)
60
-	 * @param   string  $original_file  Relative path with filename, relative to modulepart (for example: IN201701-999/IN201701-999.pdf)
61
-	 * @return  array                   List of documents
62
-	 *
63
-	 * @throws 400
64
-	 * @throws 401
65
-	 * @throws 404
66
-	 * @throws 200
67
-	 *
68
-	 * @url GET /download
69
-	 */
70
-	public function index($module_part, $original_file='')
71
-	{
72
-		global $conf, $langs;
73
-
74
-		if (empty($module_part)) {
75
-				throw new RestException(400, 'bad value for parameter modulepart');
76
-		}
77
-		if (empty($original_file)) {
78
-			throw new RestException(400, 'bad value for parameter original_file');
79
-		}
80
-
81
-		//--- Finds and returns the document
82
-		$entity=$conf->entity;
83
-
84
-		$check_access = dol_check_secure_access_document($module_part, $original_file, $entity, DolibarrApiAccess::$user, '', 'read');
85
-		$accessallowed              = $check_access['accessallowed'];
86
-		$sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals'];
87
-		$original_file              = $check_access['original_file'];
88
-
89
-		if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file))
90
-		{
91
-			throw new RestException(401);
92
-		}
93
-		if (!$accessallowed) {
94
-			throw new RestException(401);
95
-		}
96
-
97
-		$filename = basename($original_file);
98
-		$original_file_osencoded=dol_osencode($original_file);	// New file name encoded in OS encoding charset
99
-
100
-		if (! file_exists($original_file_osencoded))
101
-		{
102
-			throw new RestException(404, 'File not found');
103
-		}
104
-
105
-		$file_content=file_get_contents($original_file_osencoded);
106
-		return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'encoding'=>'base64' );
107
-	}
108
-
109
-
110
-	/**
111
-	 * Build a document.
112
-	 *
113
-	 * Test sample 1: { "module_part": "invoice", "original_file": "FA1701-001/FA1701-001.pdf", "doctemplate": "crabe", "langcode": "fr_FR" }.
114
-	 *
115
-	 * @param   string  $module_part    Name of module or area concerned by file download ('invoice', 'order', ...).
116
-	 * @param   string  $original_file  Relative path with filename, relative to modulepart (for example: IN201701-999/IN201701-999.pdf).
117
-	 * @param	string	$doctemplate	Set here the doc template to use for document generation (If not set, use the default template).
118
-	 * @param	string	$langcode		Language code like 'en_US', 'fr_FR', 'es_ES', ... (If not set, use the default language).
119
-	 * @return  array                   List of documents
120
-	 *
121
-	 * @throws 500
122
-	 * @throws 501
123
-	 * @throws 400
124
-	 * @throws 401
125
-	 * @throws 404
126
-	 * @throws 200
127
-	 *
128
-	 * @url PUT /builddoc
129
-	 */
130
-	public function builddoc($module_part, $original_file='', $doctemplate='', $langcode='')
131
-	{
132
-		global $conf, $langs;
133
-
134
-		if (empty($module_part)) {
135
-			throw new RestException(400, 'bad value for parameter modulepart');
136
-		}
137
-		if (empty($original_file)) {
138
-			throw new RestException(400, 'bad value for parameter original_file');
139
-		}
140
-
141
-		$outputlangs = $langs;
142
-		if ($langcode && $langs->defaultlang != $langcode)
143
-		{
144
-			$outputlangs=new Translate('', $conf);
145
-			$outputlangs->setDefaultLang($langcode);
146
-		}
147
-
148
-		//--- Finds and returns the document
149
-		$entity=$conf->entity;
150
-
151
-		$check_access = dol_check_secure_access_document($module_part, $original_file, $entity, DolibarrApiAccess::$user, '', 'write');
152
-		$accessallowed              = $check_access['accessallowed'];
153
-		$sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals'];
154
-		$original_file              = $check_access['original_file'];
155
-
156
-		if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file)) {
157
-			throw new RestException(401);
158
-		}
159
-		if (!$accessallowed) {
160
-			throw new RestException(401);
161
-		}
162
-
163
-		// --- Generates the document
164
-		$hidedetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 0 : 1;
165
-		$hidedesc = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 0 : 1;
166
-		$hideref = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 0 : 1;
167
-
168
-		$templateused='';
169
-
170
-		if ($module_part == 'facture' || $module_part == 'invoice')
171
-		{
172
-			require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
173
-			$this->invoice = new Facture($this->db);
174
-			$result = $this->invoice->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
175
-			if( ! $result ) {
176
-				throw new RestException(404, 'Invoice not found');
177
-			}
178
-
179
-			$templateused = $doctemplate?$doctemplate:$this->invoice->modelpdf;
180
-			$result = $this->invoice->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
181
-			if( $result <= 0 ) {
182
-				throw new RestException(500, 'Error generating document');
183
-			}
184
-		}
185
-		elseif ($module_part == 'commande' || $module_part == 'order')
186
-		{
187
-			require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
188
-			$this->order = new Commande($this->db);
189
-			$result = $this->order->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
190
-			if( ! $result ) {
191
-				throw new RestException(404, 'Order not found');
192
-			}
193
-			$templateused = $doctemplate?$doctemplate:$this->order->modelpdf;
194
-			$result = $this->order->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
195
-			if( $result <= 0 ) {
196
-				throw new RestException(500, 'Error generating document');
197
-			}
198
-		}
199
-		elseif ($module_part == 'propal' || $module_part == 'proposal')
200
-		{
201
-			require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
202
-			$this->propal = new Propal($this->db);
203
-			$result = $this->propal->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
204
-			if( ! $result ) {
205
-				throw new RestException(404, 'Proposal not found');
206
-			}
207
-			$templateused = $doctemplate?$doctemplate:$this->propal->modelpdf;
208
-			$result = $this->propal->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
209
-			if( $result <= 0 ) {
210
-				throw new RestException(500, 'Error generating document');
211
-			}
212
-		}
213
-		else
214
-		{
215
-			throw new RestException(403, 'Generation not available for this modulepart');
216
-		}
217
-
218
-		$filename = basename($original_file);
219
-		$original_file_osencoded=dol_osencode($original_file);	// New file name encoded in OS encoding charset
220
-
221
-		if (! file_exists($original_file_osencoded))
222
-		{
223
-			throw new RestException(404, 'File not found');
224
-		}
225
-
226
-		$file_content=file_get_contents($original_file_osencoded);
227
-		return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'langcode'=>$outputlangs->defaultlang, 'template'=>$templateused, 'encoding'=>'base64' );
228
-	}
229
-
230
-	/**
231
-	 * Return the list of documents of a dedicated element (from its ID or Ref)
232
-	 *
233
-	 * @param   string 	$modulepart		Name of module or area concerned ('thirdparty', 'member', 'proposal', 'order', 'invoice', 'shipment', 'project',  ...)
234
-	 * @param	int		$id				ID of element
235
-	 * @param	string	$ref			Ref of element
236
-	 * @param	string	$sortfield		Sort criteria ('','fullname','relativename','name','date','size')
237
-	 * @param	string	$sortorder		Sort order ('asc' or 'desc')
238
-	 * @return	array					Array of documents with path
239
-	 *
240
-	 * @throws 200
241
-	 * @throws 400
242
-	 * @throws 401
243
-	 * @throws 404
244
-	 * @throws 500
245
-	 *
246
-	 * @url GET /
247
-	 */
248
-	function getDocumentsListByElement($modulepart, $id=0, $ref='', $sortfield='', $sortorder='')
249
-	{
250
-		global $conf;
251
-
252
-		if (empty($modulepart)) {
253
-			throw new RestException(400, 'bad value for parameter modulepart');
254
-		}
255
-
256
-		if (empty($id) && empty($ref)) {
257
-			throw new RestException(400, 'bad value for parameter id or ref');
258
-		}
259
-
260
-		$id = (empty($id)?0:$id);
261
-
262
-		if ($modulepart == 'societe' || $modulepart == 'thirdparty')
263
-		{
264
-			require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
265
-
266
-			if (!DolibarrApiAccess::$user->rights->societe->lire) {
267
-				throw new RestException(401);
268
-			}
269
-
270
-			$object = new Societe($this->db);
271
-			$result=$object->fetch($id, $ref);
272
-			if ( ! $result ) {
273
-				throw new RestException(404, 'Thirdparty not found');
274
-			}
275
-
276
-			$upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id;
277
-		}
278
-		else if ($modulepart == 'adherent' || $modulepart == 'member')
279
-		{
280
-			require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
281
-
282
-			if (!DolibarrApiAccess::$user->rights->adherent->lire) {
283
-				throw new RestException(401);
284
-			}
285
-
286
-			$object = new Adherent($this->db);
287
-			$result=$object->fetch($id, $ref);
288
-			if ( ! $result ) {
289
-				throw new RestException(404, 'Member not found');
290
-			}
291
-
292
-			$upload_dir = $conf->adherent->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'member');
293
-		}
294
-		else if ($modulepart == 'propal' || $modulepart == 'proposal')
295
-		{
296
-			require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
297
-
298
-			if (!DolibarrApiAccess::$user->rights->propal->lire) {
299
-				throw new RestException(401);
300
-			}
301
-
302
-			$object = new Propal($this->db);
303
-			$result=$object->fetch($id, $ref);
304
-			if ( ! $result ) {
305
-				throw new RestException(404, 'Proposal not found');
306
-			}
307
-
308
-			$upload_dir = $conf->propal->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object, 'propal');
309
-		}
310
-		else if ($modulepart == 'commande' || $modulepart == 'order')
311
-		{
312
-			require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
313
-
314
-			if (!DolibarrApiAccess::$user->rights->commande->lire) {
315
-				throw new RestException(401);
316
-			}
317
-
318
-			$object = new Commande($this->db);
319
-			$result=$object->fetch($id, $ref);
320
-			if ( ! $result ) {
321
-				throw new RestException(404, 'Order not found');
322
-			}
323
-
324
-			$upload_dir = $conf->commande->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'commande');
325
-		}
326
-		else if ($modulepart == 'shipment' || $modulepart == 'expedition')
327
-		{
328
-			require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
329
-
330
-			if (!DolibarrApiAccess::$user->rights->expedition->lire) {
331
-				throw new RestException(401);
332
-			}
333
-
334
-			$object = new Expedition($this->db);
335
-			$result=$object->fetch($id, $ref);
336
-			if ( ! $result ) {
337
-				throw new RestException(404, 'Shipment not found');
338
-			}
339
-
340
-			$upload_dir = $conf->expedition->dir_output . "/sending/" . get_exdir(0, 0, 0, 1, $object, 'shipment');
341
-		}
342
-		else if ($modulepart == 'facture' || $modulepart == 'invoice')
343
-		{
344
-			require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
345
-
346
-			if (!DolibarrApiAccess::$user->rights->facture->lire) {
347
-				throw new RestException(401);
348
-			}
349
-
350
-			$object = new Facture($this->db);
351
-			$result=$object->fetch($id, $ref);
352
-			if ( ! $result ) {
353
-				throw new RestException(404, 'Invoice not found');
354
-			}
355
-
356
-			$upload_dir = $conf->facture->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice');
357
-		}
358
-		else if ($modulepart == 'agenda' || $modulepart == 'action' || $modulepart == 'event')
359
-		{
360
-			require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
361
-
362
-			if (!DolibarrApiAccess::$user->rights->agenda->myactions->read && !DolibarrApiAccess::$user->rights->agenda->allactions->read) {
363
-				throw new RestException(401);
364
-			}
365
-
366
-			$object = new ActionComm($this->db);
367
-			$result=$object->fetch($id, $ref);
368
-			if ( ! $result ) {
369
-				throw new RestException(404, 'Event not found');
370
-			}
371
-
372
-			$upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($object->ref);
373
-		}
374
-		else
375
-		{
376
-			throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.');
377
-		}
378
-
379
-		$filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
380
-		if (empty($filearray)) {
381
-			throw new RestException(404, 'Search for modulepart '.$modulepart.' with Id '.$object->id.(! empty($object->Ref)?' or Ref '.$object->ref:'').' does not return any document.');
382
-		}
383
-
384
-		return $filearray;
385
-	}
386
-
387
-
388
-	/**
389
-	 * Return a document.
390
-	 *
391
-	 * @param   int         $id          ID of document
392
-	 * @return  array                    Array with data of file
393
-	 *
394
-	 * @throws RestException
395
-	 */
396
-	/*
36
+    /**
37
+     * @var array   $DOCUMENT_FIELDS     Mandatory fields, checked when create and update object
38
+     */
39
+    static $DOCUMENT_FIELDS = array(
40
+        'modulepart'
41
+    );
42
+
43
+    /**
44
+     * Constructor
45
+     */
46
+    function __construct()
47
+    {
48
+        global $db;
49
+        $this->db = $db;
50
+    }
51
+
52
+
53
+    /**
54
+     * Download a document.
55
+     *
56
+     * Note that, this API is similar to using the wrapper link "documents.php" to download a file (used for
57
+     * internal HTML links of documents into application), but with no need to have a session cookie (the token is used instead).
58
+     *
59
+     * @param   string  $module_part    Name of module or area concerned by file download ('facture', ...)
60
+     * @param   string  $original_file  Relative path with filename, relative to modulepart (for example: IN201701-999/IN201701-999.pdf)
61
+     * @return  array                   List of documents
62
+     *
63
+     * @throws 400
64
+     * @throws 401
65
+     * @throws 404
66
+     * @throws 200
67
+     *
68
+     * @url GET /download
69
+     */
70
+    public function index($module_part, $original_file='')
71
+    {
72
+        global $conf, $langs;
73
+
74
+        if (empty($module_part)) {
75
+                throw new RestException(400, 'bad value for parameter modulepart');
76
+        }
77
+        if (empty($original_file)) {
78
+            throw new RestException(400, 'bad value for parameter original_file');
79
+        }
80
+
81
+        //--- Finds and returns the document
82
+        $entity=$conf->entity;
83
+
84
+        $check_access = dol_check_secure_access_document($module_part, $original_file, $entity, DolibarrApiAccess::$user, '', 'read');
85
+        $accessallowed              = $check_access['accessallowed'];
86
+        $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals'];
87
+        $original_file              = $check_access['original_file'];
88
+
89
+        if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file))
90
+        {
91
+            throw new RestException(401);
92
+        }
93
+        if (!$accessallowed) {
94
+            throw new RestException(401);
95
+        }
96
+
97
+        $filename = basename($original_file);
98
+        $original_file_osencoded=dol_osencode($original_file);	// New file name encoded in OS encoding charset
99
+
100
+        if (! file_exists($original_file_osencoded))
101
+        {
102
+            throw new RestException(404, 'File not found');
103
+        }
104
+
105
+        $file_content=file_get_contents($original_file_osencoded);
106
+        return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'encoding'=>'base64' );
107
+    }
108
+
109
+
110
+    /**
111
+     * Build a document.
112
+     *
113
+     * Test sample 1: { "module_part": "invoice", "original_file": "FA1701-001/FA1701-001.pdf", "doctemplate": "crabe", "langcode": "fr_FR" }.
114
+     *
115
+     * @param   string  $module_part    Name of module or area concerned by file download ('invoice', 'order', ...).
116
+     * @param   string  $original_file  Relative path with filename, relative to modulepart (for example: IN201701-999/IN201701-999.pdf).
117
+     * @param	string	$doctemplate	Set here the doc template to use for document generation (If not set, use the default template).
118
+     * @param	string	$langcode		Language code like 'en_US', 'fr_FR', 'es_ES', ... (If not set, use the default language).
119
+     * @return  array                   List of documents
120
+     *
121
+     * @throws 500
122
+     * @throws 501
123
+     * @throws 400
124
+     * @throws 401
125
+     * @throws 404
126
+     * @throws 200
127
+     *
128
+     * @url PUT /builddoc
129
+     */
130
+    public function builddoc($module_part, $original_file='', $doctemplate='', $langcode='')
131
+    {
132
+        global $conf, $langs;
133
+
134
+        if (empty($module_part)) {
135
+            throw new RestException(400, 'bad value for parameter modulepart');
136
+        }
137
+        if (empty($original_file)) {
138
+            throw new RestException(400, 'bad value for parameter original_file');
139
+        }
140
+
141
+        $outputlangs = $langs;
142
+        if ($langcode && $langs->defaultlang != $langcode)
143
+        {
144
+            $outputlangs=new Translate('', $conf);
145
+            $outputlangs->setDefaultLang($langcode);
146
+        }
147
+
148
+        //--- Finds and returns the document
149
+        $entity=$conf->entity;
150
+
151
+        $check_access = dol_check_secure_access_document($module_part, $original_file, $entity, DolibarrApiAccess::$user, '', 'write');
152
+        $accessallowed              = $check_access['accessallowed'];
153
+        $sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals'];
154
+        $original_file              = $check_access['original_file'];
155
+
156
+        if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file)) {
157
+            throw new RestException(401);
158
+        }
159
+        if (!$accessallowed) {
160
+            throw new RestException(401);
161
+        }
162
+
163
+        // --- Generates the document
164
+        $hidedetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 0 : 1;
165
+        $hidedesc = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 0 : 1;
166
+        $hideref = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 0 : 1;
167
+
168
+        $templateused='';
169
+
170
+        if ($module_part == 'facture' || $module_part == 'invoice')
171
+        {
172
+            require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
173
+            $this->invoice = new Facture($this->db);
174
+            $result = $this->invoice->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
175
+            if( ! $result ) {
176
+                throw new RestException(404, 'Invoice not found');
177
+            }
178
+
179
+            $templateused = $doctemplate?$doctemplate:$this->invoice->modelpdf;
180
+            $result = $this->invoice->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
181
+            if( $result <= 0 ) {
182
+                throw new RestException(500, 'Error generating document');
183
+            }
184
+        }
185
+        elseif ($module_part == 'commande' || $module_part == 'order')
186
+        {
187
+            require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
188
+            $this->order = new Commande($this->db);
189
+            $result = $this->order->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
190
+            if( ! $result ) {
191
+                throw new RestException(404, 'Order not found');
192
+            }
193
+            $templateused = $doctemplate?$doctemplate:$this->order->modelpdf;
194
+            $result = $this->order->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
195
+            if( $result <= 0 ) {
196
+                throw new RestException(500, 'Error generating document');
197
+            }
198
+        }
199
+        elseif ($module_part == 'propal' || $module_part == 'proposal')
200
+        {
201
+            require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
202
+            $this->propal = new Propal($this->db);
203
+            $result = $this->propal->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
204
+            if( ! $result ) {
205
+                throw new RestException(404, 'Proposal not found');
206
+            }
207
+            $templateused = $doctemplate?$doctemplate:$this->propal->modelpdf;
208
+            $result = $this->propal->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
209
+            if( $result <= 0 ) {
210
+                throw new RestException(500, 'Error generating document');
211
+            }
212
+        }
213
+        else
214
+        {
215
+            throw new RestException(403, 'Generation not available for this modulepart');
216
+        }
217
+
218
+        $filename = basename($original_file);
219
+        $original_file_osencoded=dol_osencode($original_file);	// New file name encoded in OS encoding charset
220
+
221
+        if (! file_exists($original_file_osencoded))
222
+        {
223
+            throw new RestException(404, 'File not found');
224
+        }
225
+
226
+        $file_content=file_get_contents($original_file_osencoded);
227
+        return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'langcode'=>$outputlangs->defaultlang, 'template'=>$templateused, 'encoding'=>'base64' );
228
+    }
229
+
230
+    /**
231
+     * Return the list of documents of a dedicated element (from its ID or Ref)
232
+     *
233
+     * @param   string 	$modulepart		Name of module or area concerned ('thirdparty', 'member', 'proposal', 'order', 'invoice', 'shipment', 'project',  ...)
234
+     * @param	int		$id				ID of element
235
+     * @param	string	$ref			Ref of element
236
+     * @param	string	$sortfield		Sort criteria ('','fullname','relativename','name','date','size')
237
+     * @param	string	$sortorder		Sort order ('asc' or 'desc')
238
+     * @return	array					Array of documents with path
239
+     *
240
+     * @throws 200
241
+     * @throws 400
242
+     * @throws 401
243
+     * @throws 404
244
+     * @throws 500
245
+     *
246
+     * @url GET /
247
+     */
248
+    function getDocumentsListByElement($modulepart, $id=0, $ref='', $sortfield='', $sortorder='')
249
+    {
250
+        global $conf;
251
+
252
+        if (empty($modulepart)) {
253
+            throw new RestException(400, 'bad value for parameter modulepart');
254
+        }
255
+
256
+        if (empty($id) && empty($ref)) {
257
+            throw new RestException(400, 'bad value for parameter id or ref');
258
+        }
259
+
260
+        $id = (empty($id)?0:$id);
261
+
262
+        if ($modulepart == 'societe' || $modulepart == 'thirdparty')
263
+        {
264
+            require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
265
+
266
+            if (!DolibarrApiAccess::$user->rights->societe->lire) {
267
+                throw new RestException(401);
268
+            }
269
+
270
+            $object = new Societe($this->db);
271
+            $result=$object->fetch($id, $ref);
272
+            if ( ! $result ) {
273
+                throw new RestException(404, 'Thirdparty not found');
274
+            }
275
+
276
+            $upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id;
277
+        }
278
+        else if ($modulepart == 'adherent' || $modulepart == 'member')
279
+        {
280
+            require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
281
+
282
+            if (!DolibarrApiAccess::$user->rights->adherent->lire) {
283
+                throw new RestException(401);
284
+            }
285
+
286
+            $object = new Adherent($this->db);
287
+            $result=$object->fetch($id, $ref);
288
+            if ( ! $result ) {
289
+                throw new RestException(404, 'Member not found');
290
+            }
291
+
292
+            $upload_dir = $conf->adherent->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'member');
293
+        }
294
+        else if ($modulepart == 'propal' || $modulepart == 'proposal')
295
+        {
296
+            require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
297
+
298
+            if (!DolibarrApiAccess::$user->rights->propal->lire) {
299
+                throw new RestException(401);
300
+            }
301
+
302
+            $object = new Propal($this->db);
303
+            $result=$object->fetch($id, $ref);
304
+            if ( ! $result ) {
305
+                throw new RestException(404, 'Proposal not found');
306
+            }
307
+
308
+            $upload_dir = $conf->propal->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object, 'propal');
309
+        }
310
+        else if ($modulepart == 'commande' || $modulepart == 'order')
311
+        {
312
+            require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
313
+
314
+            if (!DolibarrApiAccess::$user->rights->commande->lire) {
315
+                throw new RestException(401);
316
+            }
317
+
318
+            $object = new Commande($this->db);
319
+            $result=$object->fetch($id, $ref);
320
+            if ( ! $result ) {
321
+                throw new RestException(404, 'Order not found');
322
+            }
323
+
324
+            $upload_dir = $conf->commande->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'commande');
325
+        }
326
+        else if ($modulepart == 'shipment' || $modulepart == 'expedition')
327
+        {
328
+            require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
329
+
330
+            if (!DolibarrApiAccess::$user->rights->expedition->lire) {
331
+                throw new RestException(401);
332
+            }
333
+
334
+            $object = new Expedition($this->db);
335
+            $result=$object->fetch($id, $ref);
336
+            if ( ! $result ) {
337
+                throw new RestException(404, 'Shipment not found');
338
+            }
339
+
340
+            $upload_dir = $conf->expedition->dir_output . "/sending/" . get_exdir(0, 0, 0, 1, $object, 'shipment');
341
+        }
342
+        else if ($modulepart == 'facture' || $modulepart == 'invoice')
343
+        {
344
+            require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
345
+
346
+            if (!DolibarrApiAccess::$user->rights->facture->lire) {
347
+                throw new RestException(401);
348
+            }
349
+
350
+            $object = new Facture($this->db);
351
+            $result=$object->fetch($id, $ref);
352
+            if ( ! $result ) {
353
+                throw new RestException(404, 'Invoice not found');
354
+            }
355
+
356
+            $upload_dir = $conf->facture->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice');
357
+        }
358
+        else if ($modulepart == 'agenda' || $modulepart == 'action' || $modulepart == 'event')
359
+        {
360
+            require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
361
+
362
+            if (!DolibarrApiAccess::$user->rights->agenda->myactions->read && !DolibarrApiAccess::$user->rights->agenda->allactions->read) {
363
+                throw new RestException(401);
364
+            }
365
+
366
+            $object = new ActionComm($this->db);
367
+            $result=$object->fetch($id, $ref);
368
+            if ( ! $result ) {
369
+                throw new RestException(404, 'Event not found');
370
+            }
371
+
372
+            $upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($object->ref);
373
+        }
374
+        else
375
+        {
376
+            throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.');
377
+        }
378
+
379
+        $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
380
+        if (empty($filearray)) {
381
+            throw new RestException(404, 'Search for modulepart '.$modulepart.' with Id '.$object->id.(! empty($object->Ref)?' or Ref '.$object->ref:'').' does not return any document.');
382
+        }
383
+
384
+        return $filearray;
385
+    }
386
+
387
+
388
+    /**
389
+     * Return a document.
390
+     *
391
+     * @param   int         $id          ID of document
392
+     * @return  array                    Array with data of file
393
+     *
394
+     * @throws RestException
395
+     */
396
+    /*
397 397
     public function get($id) {
398 398
         return array('note'=>'xxx');
399 399
     }*/
400 400
 
401 401
 
402
-	/**
403
-	 * Upload a file.
404
-	 *
405
-	 * Test sample 1: { "filename": "mynewfile.txt", "modulepart": "facture", "ref": "FA1701-001", "subdir": "", "filecontent": "content text", "fileencoding": "", "overwriteifexists": "0" }.
406
-	 * Test sample 2: { "filename": "mynewfile.txt", "modulepart": "medias", "ref": "", "subdir": "image/mywebsite", "filecontent": "Y29udGVudCB0ZXh0Cg==", "fileencoding": "base64", "overwriteifexists": "0" }.
407
-	 *
408
-	 * @param   string  $filename           Name of file to create ('FA1705-0123.txt')
409
-	 * @param   string  $modulepart         Name of module or area concerned by file upload ('facture', 'project', 'project_task', ...)
410
-	 * @param   string  $ref                Reference of object (This will define subdir automatically and store submited file into it)
411
-	 * @param   string  $subdir       		Subdirectory (Only if ref not provided)
412
-	 * @param   string  $filecontent        File content (string with file content. An empty file will be created if this parameter is not provided)
413
-	 * @param   string  $fileencoding       File encoding (''=no encoding, 'base64'=Base 64) {@example '' or 'base64'}
414
-	 * @param   int 	$overwriteifexists  Overwrite file if exists (1 by default)
415
-	 *
416
-	 * @throws 200
417
-	 * @throws 400
418
-	 * @throws 401
419
-	 * @throws 404
420
-	 * @throws 500
421
-	 *
422
-	 * @url POST /upload
423
-	 */
424
-	public function post($filename, $modulepart, $ref='', $subdir='', $filecontent='', $fileencoding='', $overwriteifexists=0)
425
-	{
426
-		global $db, $conf;
427
-
428
-		/*var_dump($modulepart);
402
+    /**
403
+     * Upload a file.
404
+     *
405
+     * Test sample 1: { "filename": "mynewfile.txt", "modulepart": "facture", "ref": "FA1701-001", "subdir": "", "filecontent": "content text", "fileencoding": "", "overwriteifexists": "0" }.
406
+     * Test sample 2: { "filename": "mynewfile.txt", "modulepart": "medias", "ref": "", "subdir": "image/mywebsite", "filecontent": "Y29udGVudCB0ZXh0Cg==", "fileencoding": "base64", "overwriteifexists": "0" }.
407
+     *
408
+     * @param   string  $filename           Name of file to create ('FA1705-0123.txt')
409
+     * @param   string  $modulepart         Name of module or area concerned by file upload ('facture', 'project', 'project_task', ...)
410
+     * @param   string  $ref                Reference of object (This will define subdir automatically and store submited file into it)
411
+     * @param   string  $subdir       		Subdirectory (Only if ref not provided)
412
+     * @param   string  $filecontent        File content (string with file content. An empty file will be created if this parameter is not provided)
413
+     * @param   string  $fileencoding       File encoding (''=no encoding, 'base64'=Base 64) {@example '' or 'base64'}
414
+     * @param   int 	$overwriteifexists  Overwrite file if exists (1 by default)
415
+     *
416
+     * @throws 200
417
+     * @throws 400
418
+     * @throws 401
419
+     * @throws 404
420
+     * @throws 500
421
+     *
422
+     * @url POST /upload
423
+     */
424
+    public function post($filename, $modulepart, $ref='', $subdir='', $filecontent='', $fileencoding='', $overwriteifexists=0)
425
+    {
426
+        global $db, $conf;
427
+
428
+        /*var_dump($modulepart);
429 429
         var_dump($filename);
430 430
         var_dump($filecontent);
431 431
         exit;*/
432 432
 
433
-		if(empty($modulepart))
434
-		{
435
-			throw new RestException(400, 'Modulepart not provided.');
436
-		}
437
-
438
-		if (!DolibarrApiAccess::$user->rights->ecm->upload) {
439
-			throw new RestException(401);
440
-		}
441
-
442
-		$newfilecontent = '';
443
-		if (empty($fileencoding)) $newfilecontent = $filecontent;
444
-		if ($fileencoding == 'base64') $newfilecontent = base64_decode($filecontent);
445
-
446
-		$original_file = dol_sanitizeFileName($filename);
447
-
448
-		// Define $uploadir
449
-		$object = null;
450
-		$entity = DolibarrApiAccess::$user->entity;
451
-		if ($ref)
452
-		{
453
-			$tmpreldir='';
454
-
455
-			if ($modulepart == 'facture' || $modulepart == 'invoice')
456
-			{
457
-				$modulepart='facture';
458
-
459
-				require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
460
-				$object = new Facture($this->db);
461
-			}
462
-			elseif ($modulepart == 'project')
463
-			{
464
-				require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
465
-				$object = new Project($this->db);
466
-			}
467
-			elseif ($modulepart == 'task' || $modulepart == 'project_task')
468
-			{
469
-				$modulepart = 'project_task';
470
-
471
-				require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
472
-				$object = new Task($this->db);
473
-
474
-				$task_result = $object->fetch('', $ref);
475
-
476
-				// Fetching the tasks project is required because its out_dir might be a sub-directory of the project
477
-				if($task_result > 0)
478
-				{
479
-					$project_result = $object->fetch_projet();
480
-
481
-					if($project_result >= 0)
482
-					{
483
-						$tmpreldir = dol_sanitizeFileName($object->project->ref).'/';
484
-					}
485
-				}
486
-				else
487
-				{
488
-					throw new RestException(500, 'Error while fetching Task '.$ref);
489
-				}
490
-			}
491
-			// TODO Implement additional moduleparts
492
-			else
493
-			{
494
-				throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.');
495
-			}
496
-
497
-			if(is_object($object))
498
-			{
499
-				$result = $object->fetch('', $ref);
500
-
501
-				if($result == 0)
502
-				{
503
-					throw new RestException(404, "Object with ref '".$ref."' was not found.");
504
-			}
505
-				elseif ($result < 0)
506
-				{
507
-					throw new RestException(500, 'Error while fetching object.');
508
-				}
509
-			}
510
-
511
-			if (! ($object->id > 0))
512
-			{
513
-   				throw new RestException(404, 'The object '.$modulepart." with ref '".$ref."' was not found.");
514
-			}
515
-
516
-			$relativefile = $tmpreldir.dol_sanitizeFileName($object->ref);
517
-
518
-			$tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, $ref, 'write');
519
-			$upload_dir = $tmp['original_file'];	// No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir
520
-
521
-			if (empty($upload_dir) || $upload_dir == '/')
522
-			{
523
-				throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.');
524
-			}
525
-		}
526
-		else
527
-		{
528
-			if ($modulepart == 'invoice') $modulepart ='facture';
529
-
530
-			$relativefile = $subdir;
531
-
532
-			$tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, '', 'write');
533
-			$upload_dir = $tmp['original_file'];	// No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir
534
-
535
-			if (empty($upload_dir) || $upload_dir == '/')
536
-			{
537
-				throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.');
538
-			}
539
-		}
540
-		// $original_file here is still value of filename without any dir.
541
-
542
-		$upload_dir = dol_sanitizePathName($upload_dir);
543
-
544
-		$destfile = $upload_dir . '/' . $original_file;
545
-		$destfiletmp = DOL_DATA_ROOT.'/admin/temp/' . $original_file;
546
-		dol_delete_file($destfiletmp);
547
-		//var_dump($original_file);exit;
548
-
549
-		if (!dol_is_dir(dirname($destfile))) {
550
-			throw new RestException(401, 'Directory not exists : '.dirname($destfile));
551
-		}
552
-
553
-		if (! $overwriteifexists && dol_is_file($destfile))
554
-		{
555
-			throw new RestException(500, "File with name '".$original_file."' already exists.");
556
-		}
557
-
558
-		$fhandle = @fopen($destfiletmp, 'w');
559
-		if ($fhandle)
560
-		{
561
-			$nbofbyteswrote = fwrite($fhandle, $newfilecontent);
562
-			fclose($fhandle);
563
-			@chmod($destfiletmp, octdec($conf->global->MAIN_UMASK));
564
-		}
565
-		else
566
-		{
567
-			throw new RestException(500, "Failed to open file '".$destfiletmp."' for write");
568
-		}
569
-
570
-		$result = dol_move($destfiletmp, $destfile, 0, $overwriteifexists, 1);
571
-		if (! $result)
572
-		{
573
-			throw new RestException(500, "Failed to move file into '".$destfile."'");
574
-		}
575
-
576
-		return dol_basename($destfile);
577
-	}
578
-
579
-	/**
580
-	 * Validate fields before create or update object
581
-	 *
582
-	 * @param   array           $data   Array with data to verify
583
-	 * @return  array
584
-	 * @throws  RestException
585
-	 */
586
-	function _validate_file($data) {
587
-		$result = array();
588
-		foreach (Documents::$DOCUMENT_FIELDS as $field) {
589
-			if (!isset($data[$field]))
590
-				throw new RestException(400, "$field field missing");
591
-			$result[$field] = $data[$field];
592
-		}
593
-		return $result;
594
-	}
433
+        if(empty($modulepart))
434
+        {
435
+            throw new RestException(400, 'Modulepart not provided.');
436
+        }
437
+
438
+        if (!DolibarrApiAccess::$user->rights->ecm->upload) {
439
+            throw new RestException(401);
440
+        }
441
+
442
+        $newfilecontent = '';
443
+        if (empty($fileencoding)) $newfilecontent = $filecontent;
444
+        if ($fileencoding == 'base64') $newfilecontent = base64_decode($filecontent);
445
+
446
+        $original_file = dol_sanitizeFileName($filename);
447
+
448
+        // Define $uploadir
449
+        $object = null;
450
+        $entity = DolibarrApiAccess::$user->entity;
451
+        if ($ref)
452
+        {
453
+            $tmpreldir='';
454
+
455
+            if ($modulepart == 'facture' || $modulepart == 'invoice')
456
+            {
457
+                $modulepart='facture';
458
+
459
+                require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
460
+                $object = new Facture($this->db);
461
+            }
462
+            elseif ($modulepart == 'project')
463
+            {
464
+                require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
465
+                $object = new Project($this->db);
466
+            }
467
+            elseif ($modulepart == 'task' || $modulepart == 'project_task')
468
+            {
469
+                $modulepart = 'project_task';
470
+
471
+                require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
472
+                $object = new Task($this->db);
473
+
474
+                $task_result = $object->fetch('', $ref);
475
+
476
+                // Fetching the tasks project is required because its out_dir might be a sub-directory of the project
477
+                if($task_result > 0)
478
+                {
479
+                    $project_result = $object->fetch_projet();
480
+
481
+                    if($project_result >= 0)
482
+                    {
483
+                        $tmpreldir = dol_sanitizeFileName($object->project->ref).'/';
484
+                    }
485
+                }
486
+                else
487
+                {
488
+                    throw new RestException(500, 'Error while fetching Task '.$ref);
489
+                }
490
+            }
491
+            // TODO Implement additional moduleparts
492
+            else
493
+            {
494
+                throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.');
495
+            }
496
+
497
+            if(is_object($object))
498
+            {
499
+                $result = $object->fetch('', $ref);
500
+
501
+                if($result == 0)
502
+                {
503
+                    throw new RestException(404, "Object with ref '".$ref."' was not found.");
504
+            }
505
+                elseif ($result < 0)
506
+                {
507
+                    throw new RestException(500, 'Error while fetching object.');
508
+                }
509
+            }
510
+
511
+            if (! ($object->id > 0))
512
+            {
513
+                    throw new RestException(404, 'The object '.$modulepart." with ref '".$ref."' was not found.");
514
+            }
515
+
516
+            $relativefile = $tmpreldir.dol_sanitizeFileName($object->ref);
517
+
518
+            $tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, $ref, 'write');
519
+            $upload_dir = $tmp['original_file'];	// No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir
520
+
521
+            if (empty($upload_dir) || $upload_dir == '/')
522
+            {
523
+                throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.');
524
+            }
525
+        }
526
+        else
527
+        {
528
+            if ($modulepart == 'invoice') $modulepart ='facture';
529
+
530
+            $relativefile = $subdir;
531
+
532
+            $tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, '', 'write');
533
+            $upload_dir = $tmp['original_file'];	// No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir
534
+
535
+            if (empty($upload_dir) || $upload_dir == '/')
536
+            {
537
+                throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.');
538
+            }
539
+        }
540
+        // $original_file here is still value of filename without any dir.
541
+
542
+        $upload_dir = dol_sanitizePathName($upload_dir);
543
+
544
+        $destfile = $upload_dir . '/' . $original_file;
545
+        $destfiletmp = DOL_DATA_ROOT.'/admin/temp/' . $original_file;
546
+        dol_delete_file($destfiletmp);
547
+        //var_dump($original_file);exit;
548
+
549
+        if (!dol_is_dir(dirname($destfile))) {
550
+            throw new RestException(401, 'Directory not exists : '.dirname($destfile));
551
+        }
552
+
553
+        if (! $overwriteifexists && dol_is_file($destfile))
554
+        {
555
+            throw new RestException(500, "File with name '".$original_file."' already exists.");
556
+        }
557
+
558
+        $fhandle = @fopen($destfiletmp, 'w');
559
+        if ($fhandle)
560
+        {
561
+            $nbofbyteswrote = fwrite($fhandle, $newfilecontent);
562
+            fclose($fhandle);
563
+            @chmod($destfiletmp, octdec($conf->global->MAIN_UMASK));
564
+        }
565
+        else
566
+        {
567
+            throw new RestException(500, "Failed to open file '".$destfiletmp."' for write");
568
+        }
569
+
570
+        $result = dol_move($destfiletmp, $destfile, 0, $overwriteifexists, 1);
571
+        if (! $result)
572
+        {
573
+            throw new RestException(500, "Failed to move file into '".$destfile."'");
574
+        }
575
+
576
+        return dol_basename($destfile);
577
+    }
578
+
579
+    /**
580
+     * Validate fields before create or update object
581
+     *
582
+     * @param   array           $data   Array with data to verify
583
+     * @return  array
584
+     * @throws  RestException
585
+     */
586
+    function _validate_file($data) {
587
+        $result = array();
588
+        foreach (Documents::$DOCUMENT_FIELDS as $field) {
589
+            if (!isset($data[$field]))
590
+                throw new RestException(400, "$field field missing");
591
+            $result[$field] = $data[$field];
592
+        }
593
+        return $result;
594
+    }
595 595
 }
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 *
68 68
 	 * @url GET /download
69 69
 	 */
70
-	public function index($module_part, $original_file='')
70
+	public function index($module_part, $original_file = '')
71 71
 	{
72 72
 		global $conf, $langs;
73 73
 
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
 		}
80 80
 
81 81
 		//--- Finds and returns the document
82
-		$entity=$conf->entity;
82
+		$entity = $conf->entity;
83 83
 
84 84
 		$check_access = dol_check_secure_access_document($module_part, $original_file, $entity, DolibarrApiAccess::$user, '', 'read');
85 85
 		$accessallowed              = $check_access['accessallowed'];
86 86
 		$sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals'];
87 87
 		$original_file              = $check_access['original_file'];
88 88
 
89
-		if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file))
89
+		if (preg_match('/\.\./', $original_file) || preg_match('/[<>|]/', $original_file))
90 90
 		{
91 91
 			throw new RestException(401);
92 92
 		}
@@ -95,15 +95,15 @@  discard block
 block discarded – undo
95 95
 		}
96 96
 
97 97
 		$filename = basename($original_file);
98
-		$original_file_osencoded=dol_osencode($original_file);	// New file name encoded in OS encoding charset
98
+		$original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset
99 99
 
100
-		if (! file_exists($original_file_osencoded))
100
+		if (!file_exists($original_file_osencoded))
101 101
 		{
102 102
 			throw new RestException(404, 'File not found');
103 103
 		}
104 104
 
105
-		$file_content=file_get_contents($original_file_osencoded);
106
-		return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'encoding'=>'base64' );
105
+		$file_content = file_get_contents($original_file_osencoded);
106
+		return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'encoding'=>'base64');
107 107
 	}
108 108
 
109 109
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 	 *
128 128
 	 * @url PUT /builddoc
129 129
 	 */
130
-	public function builddoc($module_part, $original_file='', $doctemplate='', $langcode='')
130
+	public function builddoc($module_part, $original_file = '', $doctemplate = '', $langcode = '')
131 131
 	{
132 132
 		global $conf, $langs;
133 133
 
@@ -141,19 +141,19 @@  discard block
 block discarded – undo
141 141
 		$outputlangs = $langs;
142 142
 		if ($langcode && $langs->defaultlang != $langcode)
143 143
 		{
144
-			$outputlangs=new Translate('', $conf);
144
+			$outputlangs = new Translate('', $conf);
145 145
 			$outputlangs->setDefaultLang($langcode);
146 146
 		}
147 147
 
148 148
 		//--- Finds and returns the document
149
-		$entity=$conf->entity;
149
+		$entity = $conf->entity;
150 150
 
151 151
 		$check_access = dol_check_secure_access_document($module_part, $original_file, $entity, DolibarrApiAccess::$user, '', 'write');
152 152
 		$accessallowed              = $check_access['accessallowed'];
153 153
 		$sqlprotectagainstexternals = $check_access['sqlprotectagainstexternals'];
154 154
 		$original_file              = $check_access['original_file'];
155 155
 
156
-		if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file)) {
156
+		if (preg_match('/\.\./', $original_file) || preg_match('/[<>|]/', $original_file)) {
157 157
 			throw new RestException(401);
158 158
 		}
159 159
 		if (!$accessallowed) {
@@ -165,20 +165,20 @@  discard block
 block discarded – undo
165 165
 		$hidedesc = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 0 : 1;
166 166
 		$hideref = empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 0 : 1;
167 167
 
168
-		$templateused='';
168
+		$templateused = '';
169 169
 
170 170
 		if ($module_part == 'facture' || $module_part == 'invoice')
171 171
 		{
172 172
 			require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
173 173
 			$this->invoice = new Facture($this->db);
174 174
 			$result = $this->invoice->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
175
-			if( ! $result ) {
175
+			if (!$result) {
176 176
 				throw new RestException(404, 'Invoice not found');
177 177
 			}
178 178
 
179
-			$templateused = $doctemplate?$doctemplate:$this->invoice->modelpdf;
179
+			$templateused = $doctemplate ? $doctemplate : $this->invoice->modelpdf;
180 180
 			$result = $this->invoice->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
181
-			if( $result <= 0 ) {
181
+			if ($result <= 0) {
182 182
 				throw new RestException(500, 'Error generating document');
183 183
 			}
184 184
 		}
@@ -187,12 +187,12 @@  discard block
 block discarded – undo
187 187
 			require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
188 188
 			$this->order = new Commande($this->db);
189 189
 			$result = $this->order->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
190
-			if( ! $result ) {
190
+			if (!$result) {
191 191
 				throw new RestException(404, 'Order not found');
192 192
 			}
193
-			$templateused = $doctemplate?$doctemplate:$this->order->modelpdf;
193
+			$templateused = $doctemplate ? $doctemplate : $this->order->modelpdf;
194 194
 			$result = $this->order->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
195
-			if( $result <= 0 ) {
195
+			if ($result <= 0) {
196 196
 				throw new RestException(500, 'Error generating document');
197 197
 			}
198 198
 		}
@@ -201,12 +201,12 @@  discard block
 block discarded – undo
201 201
 			require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
202 202
 			$this->propal = new Propal($this->db);
203 203
 			$result = $this->propal->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file)));
204
-			if( ! $result ) {
204
+			if (!$result) {
205 205
 				throw new RestException(404, 'Proposal not found');
206 206
 			}
207
-			$templateused = $doctemplate?$doctemplate:$this->propal->modelpdf;
207
+			$templateused = $doctemplate ? $doctemplate : $this->propal->modelpdf;
208 208
 			$result = $this->propal->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref);
209
-			if( $result <= 0 ) {
209
+			if ($result <= 0) {
210 210
 				throw new RestException(500, 'Error generating document');
211 211
 			}
212 212
 		}
@@ -216,15 +216,15 @@  discard block
 block discarded – undo
216 216
 		}
217 217
 
218 218
 		$filename = basename($original_file);
219
-		$original_file_osencoded=dol_osencode($original_file);	// New file name encoded in OS encoding charset
219
+		$original_file_osencoded = dol_osencode($original_file); // New file name encoded in OS encoding charset
220 220
 
221
-		if (! file_exists($original_file_osencoded))
221
+		if (!file_exists($original_file_osencoded))
222 222
 		{
223 223
 			throw new RestException(404, 'File not found');
224 224
 		}
225 225
 
226
-		$file_content=file_get_contents($original_file_osencoded);
227
-		return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'langcode'=>$outputlangs->defaultlang, 'template'=>$templateused, 'encoding'=>'base64' );
226
+		$file_content = file_get_contents($original_file_osencoded);
227
+		return array('filename'=>$filename, 'content-type' => dol_mimetype($filename), 'filesize'=>filesize($original_file), 'content'=>base64_encode($file_content), 'langcode'=>$outputlangs->defaultlang, 'template'=>$templateused, 'encoding'=>'base64');
228 228
 	}
229 229
 
230 230
 	/**
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 	 *
246 246
 	 * @url GET /
247 247
 	 */
248
-	function getDocumentsListByElement($modulepart, $id=0, $ref='', $sortfield='', $sortorder='')
248
+	function getDocumentsListByElement($modulepart, $id = 0, $ref = '', $sortfield = '', $sortorder = '')
249 249
 	{
250 250
 		global $conf;
251 251
 
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 			throw new RestException(400, 'bad value for parameter id or ref');
258 258
 		}
259 259
 
260
-		$id = (empty($id)?0:$id);
260
+		$id = (empty($id) ? 0 : $id);
261 261
 
262 262
 		if ($modulepart == 'societe' || $modulepart == 'thirdparty')
263 263
 		{
@@ -268,12 +268,12 @@  discard block
 block discarded – undo
268 268
 			}
269 269
 
270 270
 			$object = new Societe($this->db);
271
-			$result=$object->fetch($id, $ref);
272
-			if ( ! $result ) {
271
+			$result = $object->fetch($id, $ref);
272
+			if (!$result) {
273 273
 				throw new RestException(404, 'Thirdparty not found');
274 274
 			}
275 275
 
276
-			$upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id;
276
+			$upload_dir = $conf->societe->multidir_output[$object->entity]."/".$object->id;
277 277
 		}
278 278
 		else if ($modulepart == 'adherent' || $modulepart == 'member')
279 279
 		{
@@ -284,12 +284,12 @@  discard block
 block discarded – undo
284 284
 			}
285 285
 
286 286
 			$object = new Adherent($this->db);
287
-			$result=$object->fetch($id, $ref);
288
-			if ( ! $result ) {
287
+			$result = $object->fetch($id, $ref);
288
+			if (!$result) {
289 289
 				throw new RestException(404, 'Member not found');
290 290
 			}
291 291
 
292
-			$upload_dir = $conf->adherent->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'member');
292
+			$upload_dir = $conf->adherent->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'member');
293 293
 		}
294 294
 		else if ($modulepart == 'propal' || $modulepart == 'proposal')
295 295
 		{
@@ -300,12 +300,12 @@  discard block
 block discarded – undo
300 300
 			}
301 301
 
302 302
 			$object = new Propal($this->db);
303
-			$result=$object->fetch($id, $ref);
304
-			if ( ! $result ) {
303
+			$result = $object->fetch($id, $ref);
304
+			if (!$result) {
305 305
 				throw new RestException(404, 'Proposal not found');
306 306
 			}
307 307
 
308
-			$upload_dir = $conf->propal->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object, 'propal');
308
+			$upload_dir = $conf->propal->multidir_output[$object->entity]."/".get_exdir(0, 0, 0, 1, $object, 'propal');
309 309
 		}
310 310
 		else if ($modulepart == 'commande' || $modulepart == 'order')
311 311
 		{
@@ -316,12 +316,12 @@  discard block
 block discarded – undo
316 316
 			}
317 317
 
318 318
 			$object = new Commande($this->db);
319
-			$result=$object->fetch($id, $ref);
320
-			if ( ! $result ) {
319
+			$result = $object->fetch($id, $ref);
320
+			if (!$result) {
321 321
 				throw new RestException(404, 'Order not found');
322 322
 			}
323 323
 
324
-			$upload_dir = $conf->commande->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'commande');
324
+			$upload_dir = $conf->commande->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'commande');
325 325
 		}
326 326
 		else if ($modulepart == 'shipment' || $modulepart == 'expedition')
327 327
 		{
@@ -332,12 +332,12 @@  discard block
 block discarded – undo
332 332
 			}
333 333
 
334 334
 			$object = new Expedition($this->db);
335
-			$result=$object->fetch($id, $ref);
336
-			if ( ! $result ) {
335
+			$result = $object->fetch($id, $ref);
336
+			if (!$result) {
337 337
 				throw new RestException(404, 'Shipment not found');
338 338
 			}
339 339
 
340
-			$upload_dir = $conf->expedition->dir_output . "/sending/" . get_exdir(0, 0, 0, 1, $object, 'shipment');
340
+			$upload_dir = $conf->expedition->dir_output."/sending/".get_exdir(0, 0, 0, 1, $object, 'shipment');
341 341
 		}
342 342
 		else if ($modulepart == 'facture' || $modulepart == 'invoice')
343 343
 		{
@@ -348,12 +348,12 @@  discard block
 block discarded – undo
348 348
 			}
349 349
 
350 350
 			$object = new Facture($this->db);
351
-			$result=$object->fetch($id, $ref);
352
-			if ( ! $result ) {
351
+			$result = $object->fetch($id, $ref);
352
+			if (!$result) {
353 353
 				throw new RestException(404, 'Invoice not found');
354 354
 			}
355 355
 
356
-			$upload_dir = $conf->facture->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice');
356
+			$upload_dir = $conf->facture->dir_output."/".get_exdir(0, 0, 0, 1, $object, 'invoice');
357 357
 		}
358 358
 		else if ($modulepart == 'agenda' || $modulepart == 'action' || $modulepart == 'event')
359 359
 		{
@@ -364,8 +364,8 @@  discard block
 block discarded – undo
364 364
 			}
365 365
 
366 366
 			$object = new ActionComm($this->db);
367
-			$result=$object->fetch($id, $ref);
368
-			if ( ! $result ) {
367
+			$result = $object->fetch($id, $ref);
368
+			if (!$result) {
369 369
 				throw new RestException(404, 'Event not found');
370 370
 			}
371 371
 
@@ -376,9 +376,9 @@  discard block
 block discarded – undo
376 376
 			throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.');
377 377
 		}
378 378
 
379
-		$filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
379
+		$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
380 380
 		if (empty($filearray)) {
381
-			throw new RestException(404, 'Search for modulepart '.$modulepart.' with Id '.$object->id.(! empty($object->Ref)?' or Ref '.$object->ref:'').' does not return any document.');
381
+			throw new RestException(404, 'Search for modulepart '.$modulepart.' with Id '.$object->id.(!empty($object->Ref) ? ' or Ref '.$object->ref : '').' does not return any document.');
382 382
 		}
383 383
 
384 384
 		return $filearray;
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 	 *
422 422
 	 * @url POST /upload
423 423
 	 */
424
-	public function post($filename, $modulepart, $ref='', $subdir='', $filecontent='', $fileencoding='', $overwriteifexists=0)
424
+	public function post($filename, $modulepart, $ref = '', $subdir = '', $filecontent = '', $fileencoding = '', $overwriteifexists = 0)
425 425
 	{
426 426
 		global $db, $conf;
427 427
 
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
         var_dump($filecontent);
431 431
         exit;*/
432 432
 
433
-		if(empty($modulepart))
433
+		if (empty($modulepart))
434 434
 		{
435 435
 			throw new RestException(400, 'Modulepart not provided.');
436 436
 		}
@@ -450,11 +450,11 @@  discard block
 block discarded – undo
450 450
 		$entity = DolibarrApiAccess::$user->entity;
451 451
 		if ($ref)
452 452
 		{
453
-			$tmpreldir='';
453
+			$tmpreldir = '';
454 454
 
455 455
 			if ($modulepart == 'facture' || $modulepart == 'invoice')
456 456
 			{
457
-				$modulepart='facture';
457
+				$modulepart = 'facture';
458 458
 
459 459
 				require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
460 460
 				$object = new Facture($this->db);
@@ -474,11 +474,11 @@  discard block
 block discarded – undo
474 474
 				$task_result = $object->fetch('', $ref);
475 475
 
476 476
 				// Fetching the tasks project is required because its out_dir might be a sub-directory of the project
477
-				if($task_result > 0)
477
+				if ($task_result > 0)
478 478
 				{
479 479
 					$project_result = $object->fetch_projet();
480 480
 
481
-					if($project_result >= 0)
481
+					if ($project_result >= 0)
482 482
 					{
483 483
 						$tmpreldir = dol_sanitizeFileName($object->project->ref).'/';
484 484
 					}
@@ -494,11 +494,11 @@  discard block
 block discarded – undo
494 494
 				throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.');
495 495
 			}
496 496
 
497
-			if(is_object($object))
497
+			if (is_object($object))
498 498
 			{
499 499
 				$result = $object->fetch('', $ref);
500 500
 
501
-				if($result == 0)
501
+				if ($result == 0)
502 502
 				{
503 503
 					throw new RestException(404, "Object with ref '".$ref."' was not found.");
504 504
 			}
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
 				}
509 509
 			}
510 510
 
511
-			if (! ($object->id > 0))
511
+			if (!($object->id > 0))
512 512
 			{
513 513
    				throw new RestException(404, 'The object '.$modulepart." with ref '".$ref."' was not found.");
514 514
 			}
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
 			$relativefile = $tmpreldir.dol_sanitizeFileName($object->ref);
517 517
 
518 518
 			$tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, $ref, 'write');
519
-			$upload_dir = $tmp['original_file'];	// No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir
519
+			$upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir
520 520
 
521 521
 			if (empty($upload_dir) || $upload_dir == '/')
522 522
 			{
@@ -525,12 +525,12 @@  discard block
 block discarded – undo
525 525
 		}
526 526
 		else
527 527
 		{
528
-			if ($modulepart == 'invoice') $modulepart ='facture';
528
+			if ($modulepart == 'invoice') $modulepart = 'facture';
529 529
 
530 530
 			$relativefile = $subdir;
531 531
 
532 532
 			$tmp = dol_check_secure_access_document($modulepart, $relativefile, $entity, DolibarrApiAccess::$user, '', 'write');
533
-			$upload_dir = $tmp['original_file'];	// No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir
533
+			$upload_dir = $tmp['original_file']; // No dirname here, tmp['original_file'] is already the dir because dol_check_secure_access_document was called with param original_file that is only the dir
534 534
 
535 535
 			if (empty($upload_dir) || $upload_dir == '/')
536 536
 			{
@@ -541,8 +541,8 @@  discard block
 block discarded – undo
541 541
 
542 542
 		$upload_dir = dol_sanitizePathName($upload_dir);
543 543
 
544
-		$destfile = $upload_dir . '/' . $original_file;
545
-		$destfiletmp = DOL_DATA_ROOT.'/admin/temp/' . $original_file;
544
+		$destfile = $upload_dir.'/'.$original_file;
545
+		$destfiletmp = DOL_DATA_ROOT.'/admin/temp/'.$original_file;
546 546
 		dol_delete_file($destfiletmp);
547 547
 		//var_dump($original_file);exit;
548 548
 
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 			throw new RestException(401, 'Directory not exists : '.dirname($destfile));
551 551
 		}
552 552
 
553
-		if (! $overwriteifexists && dol_is_file($destfile))
553
+		if (!$overwriteifexists && dol_is_file($destfile))
554 554
 		{
555 555
 			throw new RestException(500, "File with name '".$original_file."' already exists.");
556 556
 		}
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
 		}
569 569
 
570 570
 		$result = dol_move($destfiletmp, $destfile, 0, $overwriteifexists, 1);
571
-		if (! $result)
571
+		if (!$result)
572 572
 		{
573 573
 			throw new RestException(500, "Failed to move file into '".$destfile."'");
574 574
 		}
Please login to merge, or discard this patch.
Braces   +28 added lines, -37 removed lines patch added patch discarded remove patch
@@ -181,8 +181,7 @@  discard block
 block discarded – undo
181 181
 			if( $result <= 0 ) {
182 182
 				throw new RestException(500, 'Error generating document');
183 183
 			}
184
-		}
185
-		elseif ($module_part == 'commande' || $module_part == 'order')
184
+		} elseif ($module_part == 'commande' || $module_part == 'order')
186 185
 		{
187 186
 			require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
188 187
 			$this->order = new Commande($this->db);
@@ -195,8 +194,7 @@  discard block
 block discarded – undo
195 194
 			if( $result <= 0 ) {
196 195
 				throw new RestException(500, 'Error generating document');
197 196
 			}
198
-		}
199
-		elseif ($module_part == 'propal' || $module_part == 'proposal')
197
+		} elseif ($module_part == 'propal' || $module_part == 'proposal')
200 198
 		{
201 199
 			require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
202 200
 			$this->propal = new Propal($this->db);
@@ -209,8 +207,7 @@  discard block
 block discarded – undo
209 207
 			if( $result <= 0 ) {
210 208
 				throw new RestException(500, 'Error generating document');
211 209
 			}
212
-		}
213
-		else
210
+		} else
214 211
 		{
215 212
 			throw new RestException(403, 'Generation not available for this modulepart');
216 213
 		}
@@ -274,8 +271,7 @@  discard block
 block discarded – undo
274 271
 			}
275 272
 
276 273
 			$upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id;
277
-		}
278
-		else if ($modulepart == 'adherent' || $modulepart == 'member')
274
+		} else if ($modulepart == 'adherent' || $modulepart == 'member')
279 275
 		{
280 276
 			require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
281 277
 
@@ -290,8 +286,7 @@  discard block
 block discarded – undo
290 286
 			}
291 287
 
292 288
 			$upload_dir = $conf->adherent->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'member');
293
-		}
294
-		else if ($modulepart == 'propal' || $modulepart == 'proposal')
289
+		} else if ($modulepart == 'propal' || $modulepart == 'proposal')
295 290
 		{
296 291
 			require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
297 292
 
@@ -306,8 +301,7 @@  discard block
 block discarded – undo
306 301
 			}
307 302
 
308 303
 			$upload_dir = $conf->propal->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object, 'propal');
309
-		}
310
-		else if ($modulepart == 'commande' || $modulepart == 'order')
304
+		} else if ($modulepart == 'commande' || $modulepart == 'order')
311 305
 		{
312 306
 			require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
313 307
 
@@ -322,8 +316,7 @@  discard block
 block discarded – undo
322 316
 			}
323 317
 
324 318
 			$upload_dir = $conf->commande->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'commande');
325
-		}
326
-		else if ($modulepart == 'shipment' || $modulepart == 'expedition')
319
+		} else if ($modulepart == 'shipment' || $modulepart == 'expedition')
327 320
 		{
328 321
 			require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
329 322
 
@@ -338,8 +331,7 @@  discard block
 block discarded – undo
338 331
 			}
339 332
 
340 333
 			$upload_dir = $conf->expedition->dir_output . "/sending/" . get_exdir(0, 0, 0, 1, $object, 'shipment');
341
-		}
342
-		else if ($modulepart == 'facture' || $modulepart == 'invoice')
334
+		} else if ($modulepart == 'facture' || $modulepart == 'invoice')
343 335
 		{
344 336
 			require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
345 337
 
@@ -354,8 +346,7 @@  discard block
 block discarded – undo
354 346
 			}
355 347
 
356 348
 			$upload_dir = $conf->facture->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice');
357
-		}
358
-		else if ($modulepart == 'agenda' || $modulepart == 'action' || $modulepart == 'event')
349
+		} else if ($modulepart == 'agenda' || $modulepart == 'action' || $modulepart == 'event')
359 350
 		{
360 351
 			require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
361 352
 
@@ -370,8 +361,7 @@  discard block
 block discarded – undo
370 361
 			}
371 362
 
372 363
 			$upload_dir = $conf->agenda->dir_output.'/'.dol_sanitizeFileName($object->ref);
373
-		}
374
-		else
364
+		} else
375 365
 		{
376 366
 			throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.');
377 367
 		}
@@ -440,8 +430,12 @@  discard block
 block discarded – undo
440 430
 		}
441 431
 
442 432
 		$newfilecontent = '';
443
-		if (empty($fileencoding)) $newfilecontent = $filecontent;
444
-		if ($fileencoding == 'base64') $newfilecontent = base64_decode($filecontent);
433
+		if (empty($fileencoding)) {
434
+		    $newfilecontent = $filecontent;
435
+		}
436
+		if ($fileencoding == 'base64') {
437
+		    $newfilecontent = base64_decode($filecontent);
438
+		}
445 439
 
446 440
 		$original_file = dol_sanitizeFileName($filename);
447 441
 
@@ -458,13 +452,11 @@  discard block
 block discarded – undo
458 452
 
459 453
 				require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
460 454
 				$object = new Facture($this->db);
461
-			}
462
-			elseif ($modulepart == 'project')
455
+			} elseif ($modulepart == 'project')
463 456
 			{
464 457
 				require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
465 458
 				$object = new Project($this->db);
466
-			}
467
-			elseif ($modulepart == 'task' || $modulepart == 'project_task')
459
+			} elseif ($modulepart == 'task' || $modulepart == 'project_task')
468 460
 			{
469 461
 				$modulepart = 'project_task';
470 462
 
@@ -482,8 +474,7 @@  discard block
 block discarded – undo
482 474
 					{
483 475
 						$tmpreldir = dol_sanitizeFileName($object->project->ref).'/';
484 476
 					}
485
-				}
486
-				else
477
+				} else
487 478
 				{
488 479
 					throw new RestException(500, 'Error while fetching Task '.$ref);
489 480
 				}
@@ -501,8 +492,7 @@  discard block
 block discarded – undo
501 492
 				if($result == 0)
502 493
 				{
503 494
 					throw new RestException(404, "Object with ref '".$ref."' was not found.");
504
-			}
505
-				elseif ($result < 0)
495
+			} elseif ($result < 0)
506 496
 				{
507 497
 					throw new RestException(500, 'Error while fetching object.');
508 498
 				}
@@ -522,10 +512,11 @@  discard block
 block discarded – undo
522 512
 			{
523 513
 				throw new RestException(500, 'This value of modulepart does not support yet usage of ref. Check modulepart parameter or try to use subdir parameter instead of ref.');
524 514
 			}
525
-		}
526
-		else
515
+		} else
527 516
 		{
528
-			if ($modulepart == 'invoice') $modulepart ='facture';
517
+			if ($modulepart == 'invoice') {
518
+			    $modulepart ='facture';
519
+			}
529 520
 
530 521
 			$relativefile = $subdir;
531 522
 
@@ -561,8 +552,7 @@  discard block
 block discarded – undo
561 552
 			$nbofbyteswrote = fwrite($fhandle, $newfilecontent);
562 553
 			fclose($fhandle);
563 554
 			@chmod($destfiletmp, octdec($conf->global->MAIN_UMASK));
564
-		}
565
-		else
555
+		} else
566 556
 		{
567 557
 			throw new RestException(500, "Failed to open file '".$destfiletmp."' for write");
568 558
 		}
@@ -586,8 +576,9 @@  discard block
 block discarded – undo
586 576
 	function _validate_file($data) {
587 577
 		$result = array();
588 578
 		foreach (Documents::$DOCUMENT_FIELDS as $field) {
589
-			if (!isset($data[$field]))
590
-				throw new RestException(400, "$field field missing");
579
+			if (!isset($data[$field])) {
580
+							throw new RestException(400, "$field field missing");
581
+			}
591 582
 			$result[$field] = $data[$field];
592 583
 		}
593 584
 		return $result;
Please login to merge, or discard this patch.
dolibarr/htdocs/api/admin/index.php 3 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -33,49 +33,49 @@
 block discarded – undo
33 33
 $langs->load("admin");
34 34
 
35 35
 if (! $user->admin)
36
-	accessforbidden();
36
+    accessforbidden();
37 37
 
38 38
 $action=GETPOST('action','aZ09');
39 39
 
40 40
 //Activate ProfId
41 41
 if ($action == 'setproductionmode')
42 42
 {
43
-	$status = GETPOST('status','alpha');
44
-
45
-	if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', 0) > 0)
46
-	{
47
-		$error=0;
48
-
49
-		if ($status == 1)
50
-		{
51
-			$result = dol_mkdir($conf->api->dir_temp);
52
-			if ($result < 0)
53
-			{
54
-				setEventMessages($langs->trans("ErrorFailedToCreateDir", $conf->api->dir_temp), null, 'errors');
55
-				$error++;
56
-			}
57
-		}
58
-		else
59
-		{
60
-			// Delete the cache file otherwise it does not update
61
-			$result = dol_delete_file($conf->api->dir_temp.'/routes.php');
62
-			if ($result < 0)
63
-			{
64
-				setEventMessages($langs->trans("ErrorFailedToDeleteFile", $conf->api->dir_temp.'/routes.php'), null, 'errors');
65
-				$error++;
66
-			}
67
-		}
68
-
69
-	    if (!$error)
70
-	    {
71
-    		header("Location: ".$_SERVER["PHP_SELF"]);
72
-	   	    exit;
73
-	    }
74
-	}
75
-	else
76
-	{
77
-		dol_print_error($db);
78
-	}
43
+    $status = GETPOST('status','alpha');
44
+
45
+    if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', 0) > 0)
46
+    {
47
+        $error=0;
48
+
49
+        if ($status == 1)
50
+        {
51
+            $result = dol_mkdir($conf->api->dir_temp);
52
+            if ($result < 0)
53
+            {
54
+                setEventMessages($langs->trans("ErrorFailedToCreateDir", $conf->api->dir_temp), null, 'errors');
55
+                $error++;
56
+            }
57
+        }
58
+        else
59
+        {
60
+            // Delete the cache file otherwise it does not update
61
+            $result = dol_delete_file($conf->api->dir_temp.'/routes.php');
62
+            if ($result < 0)
63
+            {
64
+                setEventMessages($langs->trans("ErrorFailedToDeleteFile", $conf->api->dir_temp.'/routes.php'), null, 'errors');
65
+                $error++;
66
+            }
67
+        }
68
+
69
+        if (!$error)
70
+        {
71
+            header("Location: ".$_SERVER["PHP_SELF"]);
72
+                exit;
73
+        }
74
+    }
75
+    else
76
+    {
77
+        dol_print_error($db);
78
+    }
79 79
 }
80 80
 
81 81
 dol_mkdir(DOL_DATA_ROOT.'/api/temp');		// May have been deleted by a purge
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -32,19 +32,19 @@  discard block
 block discarded – undo
32 32
 // Load translation files required by the page
33 33
 $langs->load("admin");
34 34
 
35
-if (! $user->admin)
35
+if (!$user->admin)
36 36
 	accessforbidden();
37 37
 
38
-$action=GETPOST('action','aZ09');
38
+$action = GETPOST('action', 'aZ09');
39 39
 
40 40
 //Activate ProfId
41 41
 if ($action == 'setproductionmode')
42 42
 {
43
-	$status = GETPOST('status','alpha');
43
+	$status = GETPOST('status', 'alpha');
44 44
 
45 45
 	if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', 0) > 0)
46 46
 	{
47
-		$error=0;
47
+		$error = 0;
48 48
 
49 49
 		if ($status == 1)
50 50
 		{
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	}
79 79
 }
80 80
 
81
-dol_mkdir(DOL_DATA_ROOT.'/api/temp');		// May have been deleted by a purge
81
+dol_mkdir(DOL_DATA_ROOT.'/api/temp'); // May have been deleted by a purge
82 82
 
83 83
 
84 84
 /*
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 
88 88
 llxHeader();
89 89
 
90
-$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
91
-print load_fiche_titre($langs->trans("ApiSetup"),$linkback,'title_setup');
90
+$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
91
+print load_fiche_titre($langs->trans("ApiSetup"), $linkback, 'title_setup');
92 92
 
93 93
 print $langs->trans("ApiDesc")."<br>\n";
94 94
 print "<br>\n";
@@ -105,17 +105,17 @@  discard block
 block discarded – undo
105 105
 
106 106
 print '<tr class="impair">';
107 107
 print '<td>'.$langs->trans("ApiProductionMode").'</td>';
108
-$production_mode=(empty($conf->global->API_PRODUCTION_MODE)?false:true);
108
+$production_mode = (empty($conf->global->API_PRODUCTION_MODE) ?false:true);
109 109
 if ($production_mode)
110 110
 {
111
-    print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i+1).'&status=0">';
112
-    print img_picto($langs->trans("Activated"),'switch_on');
111
+    print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i + 1).'&status=0">';
112
+    print img_picto($langs->trans("Activated"), 'switch_on');
113 113
     print '</a></td>';
114 114
 }
115 115
 else
116 116
 {
117
-    print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i+1).'&status=1">';
118
-    print img_picto($langs->trans("Disabled"),'switch_off');
117
+    print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i + 1).'&status=1">';
118
+    print img_picto($langs->trans("Disabled"), 'switch_off');
119 119
     print '</a></td>';
120 120
 }
121 121
 print '<td>&nbsp;</td>';
@@ -125,15 +125,15 @@  discard block
 block discarded – undo
125 125
 print '<br><br>';
126 126
 
127 127
 // Define $urlwithroot
128
-$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
129
-$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
128
+$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
129
+$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
130 130
 //$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
131 131
 
132 132
 // Show message
133
-$message='';
134
-$url=$urlwithroot.'/api/index.php/login?login=<strong>auserlogin</strong>&password=<strong>thepassword</strong>[&reset=1]';
135
-$message.=$langs->trans("UrlToGetKeyToUseAPIs").':<br>';
136
-$message.=img_picto('','object_globe.png').' '.$url;
133
+$message = '';
134
+$url = $urlwithroot.'/api/index.php/login?login=<strong>auserlogin</strong>&password=<strong>thepassword</strong>[&reset=1]';
135
+$message .= $langs->trans("UrlToGetKeyToUseAPIs").':<br>';
136
+$message .= img_picto('', 'object_globe.png').' '.$url;
137 137
 print $message;
138 138
 print '<br>';
139 139
 print '<br>';
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
 print '<u>'.$langs->trans("ApiExporerIs").':</u><br>';
143 143
 if (dol_is_dir(DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/explorer'))
144 144
 {
145
-    $url=DOL_MAIN_URL_ROOT.'/api/index.php/explorer';
146
-    print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
145
+    $url = DOL_MAIN_URL_ROOT.'/api/index.php/explorer';
146
+    print img_picto('', 'object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
147 147
 }
148 148
 else
149 149
 {
Please login to merge, or discard this patch.
Braces   +6 added lines, -9 removed lines patch added patch discarded remove patch
@@ -32,8 +32,9 @@  discard block
 block discarded – undo
32 32
 // Load translation files required by the page
33 33
 $langs->load("admin");
34 34
 
35
-if (! $user->admin)
35
+if (! $user->admin) {
36 36
 	accessforbidden();
37
+}
37 38
 
38 39
 $action=GETPOST('action','aZ09');
39 40
 
@@ -54,8 +55,7 @@  discard block
 block discarded – undo
54 55
 				setEventMessages($langs->trans("ErrorFailedToCreateDir", $conf->api->dir_temp), null, 'errors');
55 56
 				$error++;
56 57
 			}
57
-		}
58
-		else
58
+		} else
59 59
 		{
60 60
 			// Delete the cache file otherwise it does not update
61 61
 			$result = dol_delete_file($conf->api->dir_temp.'/routes.php');
@@ -71,8 +71,7 @@  discard block
 block discarded – undo
71 71
     		header("Location: ".$_SERVER["PHP_SELF"]);
72 72
 	   	    exit;
73 73
 	    }
74
-	}
75
-	else
74
+	} else
76 75
 	{
77 76
 		dol_print_error($db);
78 77
 	}
@@ -111,8 +110,7 @@  discard block
 block discarded – undo
111 110
     print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i+1).'&status=0">';
112 111
     print img_picto($langs->trans("Activated"),'switch_on');
113 112
     print '</a></td>';
114
-}
115
-else
113
+} else
116 114
 {
117 115
     print '<td align="center"><a href="'.$_SERVER['PHP_SELF'].'?action=setproductionmode&value='.($i+1).'&status=1">';
118 116
     print img_picto($langs->trans("Disabled"),'switch_off');
@@ -144,8 +142,7 @@  discard block
 block discarded – undo
144 142
 {
145 143
     $url=DOL_MAIN_URL_ROOT.'/api/index.php/explorer';
146 144
     print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
147
-}
148
-else
145
+} else
149 146
 {
150 147
     print $langs->trans("NotAvailableWithThisDistribution");
151 148
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/api/admin/explorer.php 3 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -78,23 +78,23 @@  discard block
 block discarded – undo
78 78
                 $module=$part=$obj=strtolower(preg_replace('/^mod/i','',$modulename));
79 79
                 //if ($part == 'propale') $part='propal';
80 80
                 if ($module == 'societe') {
81
-					$obj = 'thirdparty';
82
-				}
81
+                    $obj = 'thirdparty';
82
+                }
83 83
                 if ($module == 'categorie') {
84 84
                     $part = 'categories';
85
-					$obj = 'category';
86
-				}
85
+                    $obj = 'category';
86
+                }
87 87
                 if ($module == 'facture') {
88 88
                     $part = 'compta/facture';
89
-					$obj = 'facture';
90
-				}
89
+                    $obj = 'facture';
90
+                }
91 91
                 if ($module == 'ficheinter') {
92
-                                       $obj = 'fichinter';
93
-                                       $part = 'fichinter';
94
-                                       $module='fichinter';
95
-                               }
92
+                                        $obj = 'fichinter';
93
+                                        $part = 'fichinter';
94
+                                        $module='fichinter';
95
+                                }
96 96
 
97
-		if (empty($conf->$module->enabled)) $enabled=false;
97
+        if (empty($conf->$module->enabled)) $enabled=false;
98 98
 
99 99
                 if ($enabled)
100 100
                 {
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
                                     }*/
150 150
 
151 151
                                     //$listofapis[]=array('classname'=>$classname, 'fullpath'=>$file_searched);
152
-                           /*     }
152
+                            /*     }
153 153
 
154 154
                             }*/
155 155
                         }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 if (empty($conf->global->MAIN_MODULE_API))
43 43
 {
44 44
     dol_syslog("Call Dolibarr API interfaces with module REST disabled");
45
-    print $langs->trans("WarningModuleNotActive",'Api').'.<br><br>';
45
+    print $langs->trans("WarningModuleNotActive", 'Api').'.<br><br>';
46 46
     print $langs->trans("ToActivateModule");
47 47
     exit;
48 48
 }
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 
53 53
 $api->r->addAPIClass('Luracast\\Restler\\Resources'); //this creates resources.json at API Root
54 54
 $api->r->setSupportedFormats('JsonFormat', 'XmlFormat');
55
-$api->r->addAuthenticationClass('DolibarrApiAccess','');
55
+$api->r->addAuthenticationClass('DolibarrApiAccess', '');
56 56
 
57 57
 $listofapis = array();
58 58
 
@@ -64,18 +64,18 @@  discard block
 block discarded – undo
64 64
      */
65 65
     //dol_syslog("Scan directory ".$dir." for API modules");
66 66
 
67
-    $handle=@opendir(dol_osencode($dir));
67
+    $handle = @opendir(dol_osencode($dir));
68 68
     if (is_resource($handle))
69 69
     {
70
-        while (($file = readdir($handle))!==false)
70
+        while (($file = readdir($handle)) !== false)
71 71
         {
72
-            if (is_readable($dir.$file) && preg_match("/^(mod.*)\.class\.php$/i",$file,$reg))
72
+            if (is_readable($dir.$file) && preg_match("/^(mod.*)\.class\.php$/i", $file, $reg))
73 73
             {
74
-                $modulename=$reg[1];
74
+                $modulename = $reg[1];
75 75
 
76 76
                 // Defined if module is enabled
77
-                $enabled=true;
78
-                $module=$part=$obj=strtolower(preg_replace('/^mod/i','',$modulename));
77
+                $enabled = true;
78
+                $module = $part = $obj = strtolower(preg_replace('/^mod/i', '', $modulename));
79 79
                 //if ($part == 'propale') $part='propal';
80 80
                 if ($module == 'societe') {
81 81
 					$obj = 'thirdparty';
@@ -91,10 +91,10 @@  discard block
 block discarded – undo
91 91
                 if ($module == 'ficheinter') {
92 92
                                        $obj = 'fichinter';
93 93
                                        $part = 'fichinter';
94
-                                       $module='fichinter';
94
+                                       $module = 'fichinter';
95 95
                                }
96 96
 
97
-		if (empty($conf->$module->enabled)) $enabled=false;
97
+		if (empty($conf->$module->enabled)) $enabled = false;
98 98
 
99 99
                 if ($enabled)
100 100
                 {
@@ -108,12 +108,12 @@  discard block
 block discarded – undo
108 108
                      */
109 109
                     $dir_part = DOL_DOCUMENT_ROOT.'/'.$part.'/class/';
110 110
 
111
-                    $handle_part=@opendir(dol_osencode($dir_part));
111
+                    $handle_part = @opendir(dol_osencode($dir_part));
112 112
                     if (is_resource($handle_part))
113 113
                     {
114
-                        while (($file_searched = readdir($handle_part))!==false)
114
+                        while (($file_searched = readdir($handle_part)) !== false)
115 115
                         {
116
-                            if (is_readable($dir_part.$file_searched) && preg_match("/^api_(.*)\.class\.php$/i",$file_searched,$reg))
116
+                            if (is_readable($dir_part.$file_searched) && preg_match("/^api_(.*)\.class\.php$/i", $file_searched, $reg))
117 117
                             {
118 118
                                 $classname = ucwords($reg[1]);
119 119
                                 require_once $dir_part.$file_searched;
@@ -161,43 +161,43 @@  discard block
 block discarded – undo
161 161
 }
162 162
 
163 163
 //var_dump($listofapis);
164
-$listofapis=Routes::toArray();          // TODO api for "status" is lost here
164
+$listofapis = Routes::toArray(); // TODO api for "status" is lost here
165 165
 //var_dump($listofapis);
166 166
 
167 167
 
168 168
 llxHeader();
169 169
 
170
-$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
171
-print load_fiche_titre($langs->trans("ApiSetup"),$linkback,'title_setup');
170
+$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
171
+print load_fiche_titre($langs->trans("ApiSetup"), $linkback, 'title_setup');
172 172
 
173 173
 // Define $urlwithroot
174
-$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
175
-$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
174
+$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
175
+$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
176 176
 //$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
177 177
 
178 178
 // Show message
179 179
 print '<br>';
180
-$message='';
181
-$url='<a href="'.$urlwithroot.'/api/index.php/login?login='.urlencode($user->login).'&password=yourpassword" target="_blank">'.$urlwithroot.'/api/index.php/login?login='.urlencode($user->login).'&password=yourpassword[&reset=1]</a>';
182
-$message.=$langs->trans("UrlToGetKeyToUseAPIs").':<br>';
183
-$message.=img_picto('','object_globe.png').' '.$url;
180
+$message = '';
181
+$url = '<a href="'.$urlwithroot.'/api/index.php/login?login='.urlencode($user->login).'&password=yourpassword" target="_blank">'.$urlwithroot.'/api/index.php/login?login='.urlencode($user->login).'&password=yourpassword[&reset=1]</a>';
182
+$message .= $langs->trans("UrlToGetKeyToUseAPIs").':<br>';
183
+$message .= img_picto('', 'object_globe.png').' '.$url;
184 184
 print $message;
185 185
 print '<br>';
186 186
 print '<br>';
187 187
 
188
-$oldclass='';
188
+$oldclass = '';
189 189
 
190 190
 print $langs->trans("ListOfAvailableAPIs").':<br>';
191
-foreach($listofapis['v1'] as $key => $val)
191
+foreach ($listofapis['v1'] as $key => $val)
192 192
 {
193 193
     if ($key == 'login') continue;
194 194
     if ($key == 'index') continue;
195 195
 
196 196
     if ($key)
197 197
     {
198
-        foreach($val as $method => $val2)
198
+        foreach ($val as $method => $val2)
199 199
         {
200
-            $newclass=$val2['className'];
200
+            $newclass = $val2['className'];
201 201
 
202 202
             if (preg_match('/restler/i', $newclass)) continue;
203 203
 
@@ -207,9 +207,9 @@  discard block
 block discarded – undo
207 207
                 $oldclass = $newclass;
208 208
             }
209 209
             //print $key.' - '.$val['classname'].' - '.$val['fullpath']." - ".DOL_MAIN_URL_ROOT.'/api/index.php/'.strtolower(preg_replace('/Api$/','',$val['classname']))."/xxx<br>\n";
210
-            $url=$urlwithroot.'/api/index.php/'.$key;
211
-            $url.='?api_key=token';
212
-            print img_picto('','object_globe.png').' '.$method.' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
210
+            $url = $urlwithroot.'/api/index.php/'.$key;
211
+            $url .= '?api_key=token';
212
+            print img_picto('', 'object_globe.png').' '.$method.' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
213 213
         }
214 214
     }
215 215
 }
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -94,7 +94,9 @@  discard block
 block discarded – undo
94 94
                                        $module='fichinter';
95 95
                                }
96 96
 
97
-		if (empty($conf->$module->enabled)) $enabled=false;
97
+		if (empty($conf->$module->enabled)) {
98
+		    $enabled=false;
99
+		}
98 100
 
99 101
                 if ($enabled)
100 102
                 {
@@ -190,8 +192,12 @@  discard block
 block discarded – undo
190 192
 print $langs->trans("ListOfAvailableAPIs").':<br>';
191 193
 foreach($listofapis['v1'] as $key => $val)
192 194
 {
193
-    if ($key == 'login') continue;
194
-    if ($key == 'index') continue;
195
+    if ($key == 'login') {
196
+        continue;
197
+    }
198
+    if ($key == 'index') {
199
+        continue;
200
+    }
195 201
 
196 202
     if ($key)
197 203
     {
@@ -199,7 +205,9 @@  discard block
 block discarded – undo
199 205
         {
200 206
             $newclass=$val2['className'];
201 207
 
202
-            if (preg_match('/restler/i', $newclass)) continue;
208
+            if (preg_match('/restler/i', $newclass)) {
209
+                continue;
210
+            }
203 211
 
204 212
             if ($oldclass != $newclass)
205 213
             {
Please login to merge, or discard this patch.
dolibarr/htdocs/api/index.php 3 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -215,38 +215,38 @@
 block discarded – undo
215 215
     // Load a dedicated API file
216 216
     dol_syslog("Load a dedicated API file module=".$module." moduledirforclass=".$moduledirforclass);
217 217
 
218
-	$tmpmodule = $module;
219
-	if ($tmpmodule != 'api')
220
-		$tmpmodule = preg_replace('/api$/i', '', $tmpmodule);
221
-	$classfile = str_replace('_', '', $tmpmodule);
222
-	if ($module == 'supplierproposals')
223
-		$classfile = 'supplier_proposals';
224
-	if ($module == 'supplierorders')
225
-		$classfile = 'supplier_orders';
226
-	if ($module == 'supplierinvoices')
227
-		$classfile = 'supplier_invoices';
228
-	if ($module == 'ficheinter')
229
-		$classfile = 'interventions';
230
-	if ($module == 'interventions')
231
-		$classfile = 'interventions';
232
-
233
-	$dir_part_file = dol_buildpath('/' . $moduledirforclass . '/class/api_' . $classfile . '.class.php', 0, 2);
234
-
235
-	$classname = ucwords($module);
236
-
237
-	dol_syslog('Search /' . $moduledirforclass . '/class/api_' . $classfile . '.class.php => dir_part_file=' . $dir_part_file . ' classname=' . $classname);
238
-
239
-	$res = false;
240
-	if ($dir_part_file)
241
-		$res = include_once $dir_part_file;
242
-	if (! $res) {
243
-		print 'API not found (failed to include API file)';
244
-		header('HTTP/1.1 501 API not found (failed to include API file)');
245
-		exit(0);
246
-	}
247
-
248
-	if (class_exists($classname))
249
-		$api->r->addAPIClass($classname);
218
+    $tmpmodule = $module;
219
+    if ($tmpmodule != 'api')
220
+        $tmpmodule = preg_replace('/api$/i', '', $tmpmodule);
221
+    $classfile = str_replace('_', '', $tmpmodule);
222
+    if ($module == 'supplierproposals')
223
+        $classfile = 'supplier_proposals';
224
+    if ($module == 'supplierorders')
225
+        $classfile = 'supplier_orders';
226
+    if ($module == 'supplierinvoices')
227
+        $classfile = 'supplier_invoices';
228
+    if ($module == 'ficheinter')
229
+        $classfile = 'interventions';
230
+    if ($module == 'interventions')
231
+        $classfile = 'interventions';
232
+
233
+    $dir_part_file = dol_buildpath('/' . $moduledirforclass . '/class/api_' . $classfile . '.class.php', 0, 2);
234
+
235
+    $classname = ucwords($module);
236
+
237
+    dol_syslog('Search /' . $moduledirforclass . '/class/api_' . $classfile . '.class.php => dir_part_file=' . $dir_part_file . ' classname=' . $classname);
238
+
239
+    $res = false;
240
+    if ($dir_part_file)
241
+        $res = include_once $dir_part_file;
242
+    if (! $res) {
243
+        print 'API not found (failed to include API file)';
244
+        header('HTTP/1.1 501 API not found (failed to include API file)');
245
+        exit(0);
246
+    }
247
+
248
+    if (class_exists($classname))
249
+        $api->r->addAPIClass($classname);
250 250
 }
251 251
 
252 252
 // TODO If not found, redirect to explorer
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -24,25 +24,25 @@  discard block
 block discarded – undo
24 24
  *  \file       htdocs/api/index.php
25 25
  */
26 26
 
27
-if (! defined('NOCSRFCHECK'))    define('NOCSRFCHECK','1');			// Do not check anti CSRF attack test
28
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');		// Do not check anti POST attack test
29
-if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1');		// If there is no need to load and show top and left menu
30
-if (! defined('NOREQUIREHTML'))  define('NOREQUIREHTML','1');		// If we don't need to load the html.form.class.php
31
-if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');       // Do not load ajax.lib.php library
32
-if (! defined("NOLOGIN"))        define("NOLOGIN",'1');				// If this page is public (can be called outside logged session)
27
+if (!defined('NOCSRFCHECK'))    define('NOCSRFCHECK', '1'); // Do not check anti CSRF attack test
28
+if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not check anti POST attack test
29
+if (!defined('NOREQUIREMENU'))  define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
30
+if (!defined('NOREQUIREHTML'))  define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
31
+if (!defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
32
+if (!defined("NOLOGIN"))        define("NOLOGIN", '1'); // If this page is public (can be called outside logged session)
33 33
 
34 34
 
35 35
 // Force entity if a value is provided into HTTP header. Otherwise, will use the entity of user of token used.
36
-if (! empty($_SERVER['HTTP_DOLAPIENTITY'])) define("DOLENTITY", (int) $_SERVER['HTTP_DOLAPIENTITY']);
36
+if (!empty($_SERVER['HTTP_DOLAPIENTITY'])) define("DOLENTITY", (int) $_SERVER['HTTP_DOLAPIENTITY']);
37 37
 
38 38
 
39
-$res=0;
40
-if (! $res && file_exists("../main.inc.php")) $res=include '../main.inc.php';
41
-if (! $res) die("Include of main fails");
39
+$res = 0;
40
+if (!$res && file_exists("../main.inc.php")) $res = include '../main.inc.php';
41
+if (!$res) die("Include of main fails");
42 42
 
43 43
 require_once DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/AutoLoader.php';
44 44
 
45
-call_user_func(function () {
45
+call_user_func(function() {
46 46
     $loader = Luracast\Restler\AutoLoader::instance();
47 47
     spl_autoload_register($loader);
48 48
     return $loader;
@@ -59,13 +59,13 @@  discard block
 block discarded – undo
59 59
 {
60 60
     $langs->load("admin");
61 61
     dol_syslog("Call Dolibarr API interfaces with module REST disabled");
62
-    print $langs->trans("WarningModuleNotActive",'Api').'.<br><br>';
62
+    print $langs->trans("WarningModuleNotActive", 'Api').'.<br><br>';
63 63
     print $langs->trans("ToActivateModule");
64 64
     exit;
65 65
 }
66 66
 
67 67
 // Test if explorer is not disabled
68
-if (preg_match('/api\/index\.php\/explorer/', $_SERVER["PHP_SELF"]) && ! empty($conf->global->API_EXPLORER_DISABLED))
68
+if (preg_match('/api\/index\.php\/explorer/', $_SERVER["PHP_SELF"]) && !empty($conf->global->API_EXPLORER_DISABLED))
69 69
 {
70 70
     $langs->load("admin");
71 71
     dol_syslog("Call Dolibarr API interfaces with module REST disabled");
@@ -93,10 +93,10 @@  discard block
 block discarded – undo
93 93
 
94 94
 
95 95
 // Set the flag to say to refresh (when we reload the explorer, production must be for API call only)
96
-$refreshcache=false;
97
-if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root'))
96
+$refreshcache = false;
97
+if (!empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root'))
98 98
 {
99
-    $refreshcache=true;
99
+    $refreshcache = true;
100 100
 }
101 101
 
102 102
 
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 // See https://github.com/Luracast/Restler-API-Explorer for more info.
108 108
 $api->r->addAPIClass('Luracast\\Restler\\Explorer');
109 109
 
110
-$api->r->setSupportedFormats('JsonFormat', 'XmlFormat', 'UploadFormat');	// 'YamlFormat'
111
-$api->r->addAuthenticationClass('DolibarrApiAccess','');
110
+$api->r->setSupportedFormats('JsonFormat', 'XmlFormat', 'UploadFormat'); // 'YamlFormat'
111
+$api->r->addAuthenticationClass('DolibarrApiAccess', '');
112 112
 
113 113
 // Define accepted mime types
114 114
 UploadFormat::$allowedMimeTypes = array('image/jpeg', 'image/png', 'text/plain', 'application/octet-stream');
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 
117 117
 
118 118
 // Call Explorer file for all APIs definitions
119
-if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root'))
119
+if (!empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root'))
120 120
 {
121 121
     // Scan all API files to load them
122 122
 
@@ -128,25 +128,25 @@  discard block
 block discarded – undo
128 128
         // Search available module
129 129
         dol_syslog("Scan directory ".$dir." for module descriptor files, then search for API files");
130 130
 
131
-        $handle=@opendir(dol_osencode($dir));
131
+        $handle = @opendir(dol_osencode($dir));
132 132
         if (is_resource($handle))
133 133
         {
134
-            while (($file = readdir($handle))!==false)
134
+            while (($file = readdir($handle)) !== false)
135 135
             {
136
-                if (is_readable($dir.$file) && preg_match("/^mod(.*)\.class\.php$/i",$file,$regmod))
136
+                if (is_readable($dir.$file) && preg_match("/^mod(.*)\.class\.php$/i", $file, $regmod))
137 137
                 {
138 138
                     $module = strtolower($regmod[1]);
139 139
                     $moduledirforclass = getModuleDirForApiClass($module);
140 140
                     $modulenameforenabled = $module;
141
-                    if ($module == 'propale') { $modulenameforenabled='propal'; }
142
-                    if ($module == 'supplierproposal') { $modulenameforenabled='supplier_proposal'; }
143
-                    if ($module == 'ficheinter') { $modulenameforenabled='ficheinter'; }
141
+                    if ($module == 'propale') { $modulenameforenabled = 'propal'; }
142
+                    if ($module == 'supplierproposal') { $modulenameforenabled = 'supplier_proposal'; }
143
+                    if ($module == 'ficheinter') { $modulenameforenabled = 'ficheinter'; }
144 144
 
145 145
                     dol_syslog("Found module file ".$file." - module=".$module." - modulenameforenabled=".$modulenameforenabled." - moduledirforclass=".$moduledirforclass);
146 146
 
147 147
                     // Defined if module is enabled
148
-                    $enabled=true;
149
-                    if (empty($conf->$modulenameforenabled->enabled)) $enabled=false;
148
+                    $enabled = true;
149
+                    if (empty($conf->$modulenameforenabled->enabled)) $enabled = false;
150 150
 
151 151
                     if ($enabled)
152 152
                     {
@@ -155,14 +155,14 @@  discard block
 block discarded – undo
155 155
                         // @todo : use getElementProperties() function ?
156 156
                         $dir_part = dol_buildpath('/'.$moduledirforclass.'/class/');
157 157
 
158
-                        $handle_part=@opendir(dol_osencode($dir_part));
158
+                        $handle_part = @opendir(dol_osencode($dir_part));
159 159
                         if (is_resource($handle_part))
160 160
                         {
161
-                            while (($file_searched = readdir($handle_part))!==false)
161
+                            while (($file_searched = readdir($handle_part)) !== false)
162 162
                             {
163 163
                                 if ($file_searched == 'api_access.class.php') continue;
164 164
 
165
-                                if (is_readable($dir_part.$file_searched) && preg_match("/^api_(.*)\.class\.php$/i",$file_searched,$regapi))
165
+                                if (is_readable($dir_part.$file_searched) && preg_match("/^api_(.*)\.class\.php$/i", $file_searched, $regapi))
166 166
                                 {
167 167
                                     $classname = ucwords($regapi[1]);
168 168
                                     $classname = str_replace('_', '', $classname);
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 }
202 202
 
203 203
 // Call one APIs or one definition of an API
204
-if (! empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' && $reg[2] != '/resources.json' && preg_match('/^\/(swagger|resources)\.json\/(.+)$/', $reg[2], $regbis) && $regbis[2] != 'root')))
204
+if (!empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' && $reg[2] != '/resources.json' && preg_match('/^\/(swagger|resources)\.json\/(.+)$/', $reg[2], $regbis) && $regbis[2] != 'root')))
205 205
 {
206 206
     $module = $reg[1];
207 207
     if ($module == 'explorer')  // If we call page to explore details of a service
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
         $module = $regbis[2];
210 210
     }
211 211
 
212
-    $module=strtolower($module);
212
+    $module = strtolower($module);
213 213
     $moduledirforclass = getModuleDirForApiClass($module);
214 214
 
215 215
     // Load a dedicated API file
@@ -230,16 +230,16 @@  discard block
 block discarded – undo
230 230
 	if ($module == 'interventions')
231 231
 		$classfile = 'interventions';
232 232
 
233
-	$dir_part_file = dol_buildpath('/' . $moduledirforclass . '/class/api_' . $classfile . '.class.php', 0, 2);
233
+	$dir_part_file = dol_buildpath('/'.$moduledirforclass.'/class/api_'.$classfile.'.class.php', 0, 2);
234 234
 
235 235
 	$classname = ucwords($module);
236 236
 
237
-	dol_syslog('Search /' . $moduledirforclass . '/class/api_' . $classfile . '.class.php => dir_part_file=' . $dir_part_file . ' classname=' . $classname);
237
+	dol_syslog('Search /'.$moduledirforclass.'/class/api_'.$classfile.'.class.php => dir_part_file='.$dir_part_file.' classname='.$classname);
238 238
 
239 239
 	$res = false;
240 240
 	if ($dir_part_file)
241 241
 		$res = include_once $dir_part_file;
242
-	if (! $res) {
242
+	if (!$res) {
243 243
 		print 'API not found (failed to include API file)';
244 244
 		header('HTTP/1.1 501 API not found (failed to include API file)');
245 245
 		exit(0);
Please login to merge, or discard this patch.
Braces   +69 added lines, -33 removed lines patch added patch discarded remove patch
@@ -24,21 +24,45 @@  discard block
 block discarded – undo
24 24
  *  \file       htdocs/api/index.php
25 25
  */
26 26
 
27
-if (! defined('NOCSRFCHECK'))    define('NOCSRFCHECK','1');			// Do not check anti CSRF attack test
28
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');		// Do not check anti POST attack test
29
-if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1');		// If there is no need to load and show top and left menu
30
-if (! defined('NOREQUIREHTML'))  define('NOREQUIREHTML','1');		// If we don't need to load the html.form.class.php
31
-if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');       // Do not load ajax.lib.php library
32
-if (! defined("NOLOGIN"))        define("NOLOGIN",'1');				// If this page is public (can be called outside logged session)
27
+if (! defined('NOCSRFCHECK')) {
28
+    define('NOCSRFCHECK','1');
29
+}
30
+// Do not check anti CSRF attack test
31
+if (! defined('NOTOKENRENEWAL')) {
32
+    define('NOTOKENRENEWAL','1');
33
+}
34
+// Do not check anti POST attack test
35
+if (! defined('NOREQUIREMENU')) {
36
+    define('NOREQUIREMENU','1');
37
+}
38
+// If there is no need to load and show top and left menu
39
+if (! defined('NOREQUIREHTML')) {
40
+    define('NOREQUIREHTML','1');
41
+}
42
+// If we don't need to load the html.form.class.php
43
+if (! defined('NOREQUIREAJAX')) {
44
+    define('NOREQUIREAJAX','1');
45
+}
46
+// Do not load ajax.lib.php library
47
+if (! defined("NOLOGIN")) {
48
+    define("NOLOGIN",'1');
49
+}
50
+// If this page is public (can be called outside logged session)
33 51
 
34 52
 
35 53
 // Force entity if a value is provided into HTTP header. Otherwise, will use the entity of user of token used.
36
-if (! empty($_SERVER['HTTP_DOLAPIENTITY'])) define("DOLENTITY", (int) $_SERVER['HTTP_DOLAPIENTITY']);
54
+if (! empty($_SERVER['HTTP_DOLAPIENTITY'])) {
55
+    define("DOLENTITY", (int) $_SERVER['HTTP_DOLAPIENTITY']);
56
+}
37 57
 
38 58
 
39 59
 $res=0;
40
-if (! $res && file_exists("../main.inc.php")) $res=include '../main.inc.php';
41
-if (! $res) die("Include of main fails");
60
+if (! $res && file_exists("../main.inc.php")) {
61
+    $res=include '../main.inc.php';
62
+}
63
+if (! $res) {
64
+    die("Include of main fails");
65
+}
42 66
 
43 67
 require_once DOL_DOCUMENT_ROOT.'/includes/restler/framework/Luracast/Restler/AutoLoader.php';
44 68
 
@@ -146,7 +170,9 @@  discard block
 block discarded – undo
146 170
 
147 171
                     // Defined if module is enabled
148 172
                     $enabled=true;
149
-                    if (empty($conf->$modulenameforenabled->enabled)) $enabled=false;
173
+                    if (empty($conf->$modulenameforenabled->enabled)) {
174
+                        $enabled=false;
175
+                    }
150 176
 
151 177
                     if ($enabled)
152 178
                     {
@@ -160,7 +186,9 @@  discard block
 block discarded – undo
160 186
                         {
161 187
                             while (($file_searched = readdir($handle_part))!==false)
162 188
                             {
163
-                                if ($file_searched == 'api_access.class.php') continue;
189
+                                if ($file_searched == 'api_access.class.php') {
190
+                                    continue;
191
+                                }
164 192
 
165 193
                                 if (is_readable($dir_part.$file_searched) && preg_match("/^api_(.*)\.class\.php$/i",$file_searched,$regapi))
166 194
                                 {
@@ -171,13 +199,11 @@  discard block
 block discarded – undo
171 199
                                     {
172 200
                                         //dol_syslog("Found API by index.php: classname=".$classname."Api for module ".$dir." into ".$dir_part.$file_searched);
173 201
                                         $listofapis[strtolower($classname.'Api')] = $classname.'Api';
174
-                                    }
175
-                                    elseif (class_exists($classname))
202
+                                    } elseif (class_exists($classname))
176 203
                                     {
177 204
                                         //dol_syslog("Found API by index.php: classname=".$classname." for module ".$dir." into ".$dir_part.$file_searched);
178 205
                                         $listofapis[strtolower($classname)] = $classname;
179
-                                    }
180
-                                    else
206
+                                    } else
181 207
                                     {
182 208
                                         dol_syslog("We found an api_xxx file (".$file_searched.") but class ".$classname." does not exists after loading file", LOG_WARNING);
183 209
                                     }
@@ -204,10 +230,12 @@  discard block
 block discarded – undo
204 230
 if (! empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/swagger.json' && $reg[2] != '/resources.json' && preg_match('/^\/(swagger|resources)\.json\/(.+)$/', $reg[2], $regbis) && $regbis[2] != 'root')))
205 231
 {
206 232
     $module = $reg[1];
207
-    if ($module == 'explorer')  // If we call page to explore details of a service
233
+    if ($module == 'explorer') {
234
+        // If we call page to explore details of a service
208 235
     {
209 236
         $module = $regbis[2];
210 237
     }
238
+    }
211 239
 
212 240
     $module=strtolower($module);
213 241
     $moduledirforclass = getModuleDirForApiClass($module);
@@ -216,19 +244,25 @@  discard block
 block discarded – undo
216 244
     dol_syslog("Load a dedicated API file module=".$module." moduledirforclass=".$moduledirforclass);
217 245
 
218 246
 	$tmpmodule = $module;
219
-	if ($tmpmodule != 'api')
220
-		$tmpmodule = preg_replace('/api$/i', '', $tmpmodule);
247
+	if ($tmpmodule != 'api') {
248
+			$tmpmodule = preg_replace('/api$/i', '', $tmpmodule);
249
+	}
221 250
 	$classfile = str_replace('_', '', $tmpmodule);
222
-	if ($module == 'supplierproposals')
223
-		$classfile = 'supplier_proposals';
224
-	if ($module == 'supplierorders')
225
-		$classfile = 'supplier_orders';
226
-	if ($module == 'supplierinvoices')
227
-		$classfile = 'supplier_invoices';
228
-	if ($module == 'ficheinter')
229
-		$classfile = 'interventions';
230
-	if ($module == 'interventions')
231
-		$classfile = 'interventions';
251
+	if ($module == 'supplierproposals') {
252
+			$classfile = 'supplier_proposals';
253
+	}
254
+	if ($module == 'supplierorders') {
255
+			$classfile = 'supplier_orders';
256
+	}
257
+	if ($module == 'supplierinvoices') {
258
+			$classfile = 'supplier_invoices';
259
+	}
260
+	if ($module == 'ficheinter') {
261
+			$classfile = 'interventions';
262
+	}
263
+	if ($module == 'interventions') {
264
+			$classfile = 'interventions';
265
+	}
232 266
 
233 267
 	$dir_part_file = dol_buildpath('/' . $moduledirforclass . '/class/api_' . $classfile . '.class.php', 0, 2);
234 268
 
@@ -237,17 +271,19 @@  discard block
 block discarded – undo
237 271
 	dol_syslog('Search /' . $moduledirforclass . '/class/api_' . $classfile . '.class.php => dir_part_file=' . $dir_part_file . ' classname=' . $classname);
238 272
 
239 273
 	$res = false;
240
-	if ($dir_part_file)
241
-		$res = include_once $dir_part_file;
274
+	if ($dir_part_file) {
275
+			$res = include_once $dir_part_file;
276
+	}
242 277
 	if (! $res) {
243 278
 		print 'API not found (failed to include API file)';
244 279
 		header('HTTP/1.1 501 API not found (failed to include API file)');
245 280
 		exit(0);
246 281
 	}
247 282
 
248
-	if (class_exists($classname))
249
-		$api->r->addAPIClass($classname);
250
-}
283
+	if (class_exists($classname)) {
284
+			$api->r->addAPIClass($classname);
285
+	}
286
+	}
251 287
 
252 288
 // TODO If not found, redirect to explorer
253 289
 //var_dump($api->r->apiVersionMap);
Please login to merge, or discard this patch.
dolibarr/htdocs/paypal/lib/paypalfunctions.lib.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 // PayPal Express Checkout Module
39 39
 // ==================================
40 40
 
41
-$API_version="56";
41
+$API_version = "56";
42 42
 
43 43
 /*
44 44
  ' Define the PayPal Redirect URLs.
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
  ' For the sandbox, the URL is       https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=
49 49
  ' For the live site, the URL is        https://www.paypal.com/webscr&cmd=_express-checkout&token=
50 50
  */
51
-if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))		// We can force sand box with param 'forcesandbox'
51
+if (!empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox', 'alpha'))		// We can force sand box with param 'forcesandbox'
52 52
 {
53 53
     $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
54 54
     $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
@@ -60,19 +60,19 @@  discard block
 block discarded – undo
60 60
 }
61 61
 
62 62
 // Clean parameters
63
-$PAYPAL_API_USER="";
64
-if (! empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
65
-$PAYPAL_API_PASSWORD="";
66
-if (! empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
67
-$PAYPAL_API_SIGNATURE="";
68
-if (! empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
69
-$PAYPAL_API_SANDBOX="";
70
-if (! empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
63
+$PAYPAL_API_USER = "";
64
+if (!empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER = $conf->global->PAYPAL_API_USER;
65
+$PAYPAL_API_PASSWORD = "";
66
+if (!empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD = $conf->global->PAYPAL_API_PASSWORD;
67
+$PAYPAL_API_SIGNATURE = "";
68
+if (!empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE = $conf->global->PAYPAL_API_SIGNATURE;
69
+$PAYPAL_API_SANDBOX = "";
70
+if (!empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX = $conf->global->PAYPAL_API_SANDBOX;
71 71
 
72 72
 // Proxy
73 73
 $PROXY_HOST = $conf->global->MAIN_PROXY_HOST;
74 74
 $PROXY_PORT = $conf->global->MAIN_PROXY_PORT;
75 75
 $PROXY_USER = $conf->global->MAIN_PROXY_USER;
76 76
 $PROXY_PASS = $conf->global->MAIN_PROXY_PASS;
77
-$USE_PROXY = empty($conf->global->MAIN_PROXY_USE)?false:true;
77
+$USE_PROXY = empty($conf->global->MAIN_PROXY_USE) ?false:true;
78 78
 
Please login to merge, or discard this patch.
Braces   +19 added lines, -8 removed lines patch added patch discarded remove patch
@@ -25,11 +25,13 @@  discard block
 block discarded – undo
25 25
 if (session_id() == "")
26 26
 {
27 27
     session_start();
28
-    if (ini_get('register_globals'))    // To solve bug in using $_SESSION
28
+    if (ini_get('register_globals')) {
29
+        // To solve bug in using $_SESSION
29 30
     {
30 31
         foreach ($_SESSION as $key=>$value)
31 32
         {
32 33
             if (isset($GLOBALS[$key])) unset($GLOBALS[$key]);
34
+    }
33 35
         }
34 36
     }
35 37
 }
@@ -48,12 +50,13 @@  discard block
 block discarded – undo
48 50
  ' For the sandbox, the URL is       https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=
49 51
  ' For the live site, the URL is        https://www.paypal.com/webscr&cmd=_express-checkout&token=
50 52
  */
51
-if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))		// We can force sand box with param 'forcesandbox'
53
+if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha')) {
54
+    // We can force sand box with param 'forcesandbox'
52 55
 {
53 56
     $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
54
-    $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
55 57
 }
56
-else
58
+    $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
59
+} else
57 60
 {
58 61
     $API_Endpoint = "https://api-3t.paypal.com/nvp";
59 62
     $API_Url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
@@ -61,13 +64,21 @@  discard block
 block discarded – undo
61 64
 
62 65
 // Clean parameters
63 66
 $PAYPAL_API_USER="";
64
-if (! empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
67
+if (! empty($conf->global->PAYPAL_API_USER)) {
68
+    $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
69
+}
65 70
 $PAYPAL_API_PASSWORD="";
66
-if (! empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
71
+if (! empty($conf->global->PAYPAL_API_PASSWORD)) {
72
+    $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
73
+}
67 74
 $PAYPAL_API_SIGNATURE="";
68
-if (! empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
75
+if (! empty($conf->global->PAYPAL_API_SIGNATURE)) {
76
+    $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
77
+}
69 78
 $PAYPAL_API_SANDBOX="";
70
-if (! empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
79
+if (! empty($conf->global->PAYPAL_API_SANDBOX)) {
80
+    $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
81
+}
71 82
 
72 83
 // Proxy
73 84
 $PROXY_HOST = $conf->global->MAIN_PROXY_HOST;
Please login to merge, or discard this patch.
dolibarr/htdocs/paypal/lib/paypal.lib.php 3 patches
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -30,25 +30,25 @@  discard block
 block discarded – undo
30 30
  */
31 31
 function paypaladmin_prepare_head()
32 32
 {
33
-	global $langs, $conf;
33
+    global $langs, $conf;
34 34
 
35
-	$h = 0;
36
-	$head = array();
35
+    $h = 0;
36
+    $head = array();
37 37
 
38
-	$head[$h][0] = DOL_URL_ROOT."/paypal/admin/paypal.php";
39
-	$head[$h][1] = $langs->trans("PayPal");
40
-	$head[$h][2] = 'paypalaccount';
41
-	$h++;
38
+    $head[$h][0] = DOL_URL_ROOT."/paypal/admin/paypal.php";
39
+    $head[$h][1] = $langs->trans("PayPal");
40
+    $head[$h][2] = 'paypalaccount';
41
+    $h++;
42 42
 
43
-	$object=new stdClass();
43
+    $object=new stdClass();
44 44
 
45 45
     // Show more tabs from modules
46 46
     // Entries must be declared in modules descriptor with line
47 47
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
48 48
     // $this->tabs = array('entity:-tabname);   												to remove a tab
49
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'paypaladmin');
49
+    complete_head_from_modules($conf,$langs,$object,$head,$h,'paypaladmin');
50 50
 
51
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'paypaladmin','remove');
51
+    complete_head_from_modules($conf,$langs,$object,$head,$h,'paypaladmin','remove');
52 52
 
53 53
     return $head;
54 54
 }
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
  */
65 65
 function showPaypalPaymentUrl($type,$ref)
66 66
 {
67
-	global $conf, $langs;
67
+    global $conf, $langs;
68 68
 
69
-	$langs->load("paypal");
69
+    $langs->load("paypal");
70 70
     $langs->load("paybox");
71 71
     $servicename='PayPal';
72 72
     $out='<br><br>';
@@ -90,28 +90,28 @@  discard block
 block discarded – undo
90 90
  */
91 91
 function getPaypalPaymentUrl($mode,$type,$ref='',$amount='9.99',$freetag='your_free_tag')
92 92
 {
93
-	global $conf;
93
+    global $conf;
94 94
 
95
-	$ref=str_replace(' ','',$ref);
95
+    $ref=str_replace(' ','',$ref);
96 96
 
97 97
     if ($type == 'free')
98 98
     {
99
-	    $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':'');
100
-	    if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
101
-	    {
102
-	    	if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
103
-	    	else $out.='&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
104
-	    }
99
+        $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':'');
100
+        if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
101
+        {
102
+            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
103
+            else $out.='&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
104
+        }
105 105
     }
106 106
     if ($type == 'order')
107 107
     {
108 108
         $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=order&ref='.($mode?'<font color="#666666">':'');
109 109
         if ($mode == 1) $out.='order_ref';
110 110
         if ($mode == 0) $out.=urlencode($ref);
111
-	    $out.=($mode?'</font>':'');
111
+        $out.=($mode?'</font>':'');
112 112
         if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
113 113
         {
114
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
114
+            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
115 115
             else
116 116
             {
117 117
                 $out.='&securekey='.($mode?'<font color="#666666">':'');
@@ -126,10 +126,10 @@  discard block
 block discarded – undo
126 126
         $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=invoice&ref='.($mode?'<font color="#666666">':'');
127 127
         if ($mode == 1) $out.='invoice_ref';
128 128
         if ($mode == 0) $out.=urlencode($ref);
129
-	    $out.=($mode?'</font>':'');
129
+        $out.=($mode?'</font>':'');
130 130
         if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
131 131
         {
132
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
132
+            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
133 133
             else
134 134
             {
135 135
                 $out.='&securekey='.($mode?'<font color="#666666">':'');
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
         $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=contractline&ref='.($mode?'<font color="#666666">':'');
145 145
         if ($mode == 1) $out.='contractline_ref';
146 146
         if ($mode == 0) $out.=urlencode($ref);
147
-	    $out.=($mode?'</font>':'');
147
+        $out.=($mode?'</font>':'');
148 148
         if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
149 149
         {
150
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
150
+            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
151 151
             else
152 152
             {
153 153
                 $out.='&securekey='.($mode?'<font color="#666666">':'');
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
         $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=membersubscription&ref='.($mode?'<font color="#666666">':'');
163 163
         if ($mode == 1) $out.='member_ref';
164 164
         if ($mode == 0) $out.=urlencode($ref);
165
-	    $out.=($mode?'</font>':'');
165
+        $out.=($mode?'</font>':'');
166 166
         if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
167 167
         {
168
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
168
+            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
169 169
             else
170 170
             {
171 171
                 $out.='&securekey='.($mode?'<font color="#666666">':'');
@@ -274,15 +274,15 @@  discard block
 block discarded – undo
274 274
 
275 275
         if ($ErrorCode == 10729)
276 276
         {
277
-        	$mesg.= "PayPal can't accept payments for this thirdparty. An address is defined but is not complete (missing State).<br>Ask system administrator to fix address or to setup Paypal module to accept payments even on not complete addresses (remove option PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS).<br>\n";
277
+            $mesg.= "PayPal can't accept payments for this thirdparty. An address is defined but is not complete (missing State).<br>Ask system administrator to fix address or to setup Paypal module to accept payments even on not complete addresses (remove option PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS).<br>\n";
278 278
         }
279 279
         else
280 280
         {
281
-        	$mesg = $langs->trans('SetExpressCheckoutAPICallFailed') . "<br>\n";
282
-        	$mesg.= $langs->trans('DetailedErrorMessage') . ": " . $ErrorLongMsg."<br>\n";
283
-        	$mesg.= $langs->trans('ShortErrorMessage') . ": " . $ErrorShortMsg."<br>\n";
284
-        	$mesg.= $langs->trans('ErrorCode') . ": " . $ErrorCode."<br>\n";
285
-        	$mesg.= $langs->trans('ErrorSeverityCode') . ": " . $ErrorSeverityCode."<br>\n";
281
+            $mesg = $langs->trans('SetExpressCheckoutAPICallFailed') . "<br>\n";
282
+            $mesg.= $langs->trans('DetailedErrorMessage') . ": " . $ErrorLongMsg."<br>\n";
283
+            $mesg.= $langs->trans('ShortErrorMessage') . ": " . $ErrorShortMsg."<br>\n";
284
+            $mesg.= $langs->trans('ErrorCode') . ": " . $ErrorCode."<br>\n";
285
+            $mesg.= $langs->trans('ErrorSeverityCode') . ": " . $ErrorSeverityCode."<br>\n";
286 286
         }
287 287
 
288 288
         return $mesg;
@@ -346,28 +346,28 @@  discard block
 block discarded – undo
346 346
     $nvpstr = $nvpstr . "&CANCELURL=" . urlencode($cancelURL);
347 347
     if (! empty($conf->global->PAYPAL_ALLOW_NOTES))
348 348
     {
349
-    	$nvpstr = $nvpstr . "&ALLOWNOTE=0";
349
+        $nvpstr = $nvpstr . "&ALLOWNOTE=0";
350 350
     }
351 351
     if (empty($conf->global->PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS))
352 352
     {
353
-    	$nvpstr = $nvpstr . "&NOSHIPPING=1";	// An empty or not complete shipping address will be accepted
353
+        $nvpstr = $nvpstr . "&NOSHIPPING=1";	// An empty or not complete shipping address will be accepted
354 354
     }
355 355
     else
356 356
     {
357
-    	$nvpstr = $nvpstr . "&NOSHIPPING=0";	// A valid shipping address is required (full required fields mandatory)
357
+        $nvpstr = $nvpstr . "&NOSHIPPING=0";	// A valid shipping address is required (full required fields mandatory)
358 358
     }
359 359
     $nvpstr = $nvpstr . "&SOLUTIONTYPE=" . urlencode($solutionType);
360 360
     $nvpstr = $nvpstr . "&LANDINGPAGE=" . urlencode($landingPage);
361 361
     if (! empty($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER))
362 362
     {
363
-    	$nvpstr = $nvpstr . "&CUSTOMERSERVICENUMBER=" . urlencode($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER);    // Hotline phone number
363
+        $nvpstr = $nvpstr . "&CUSTOMERSERVICENUMBER=" . urlencode($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER);    // Hotline phone number
364 364
     }
365 365
 
366 366
     $paypalprefix = 'PAYMENTREQUEST_0_';
367 367
     //$paypalprefix = '';
368
-	if (! empty($paypalprefix) && $paymentType == 'Sole') $paymentType='Sale';
368
+    if (! empty($paypalprefix) && $paymentType == 'Sole') $paymentType='Sale';
369 369
 
370
-	$nvpstr = $nvpstr . "&AMT=". urlencode($paymentAmount);									// Total for all elements
370
+    $nvpstr = $nvpstr . "&AMT=". urlencode($paymentAmount);									// Total for all elements
371 371
 
372 372
     $nvpstr = $nvpstr . "&".$paypalprefix."INVNUM=" . urlencode($tag);
373 373
     $nvpstr = $nvpstr . "&".$paypalprefix."AMT=". urlencode($paymentAmount);                 // AMT deprecated by paypal -> PAYMENTREQUEST_n_AMT
@@ -393,26 +393,26 @@  discard block
 block discarded – undo
393 393
 
394 394
     if (! empty($conf->global->PAYPAL_LOGOIMG) && $mysoc->logo)
395 395
     {
396
-    	global $dolibarr_main_url_root;
396
+        global $dolibarr_main_url_root;
397 397
 
398
-	    // Define $urlwithroot
399
-	    $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
400
-	    $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
401
-	    //$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
398
+        // Define $urlwithroot
399
+        $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
400
+        $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
401
+        //$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
402 402
 
403
-	    $urllogo=$urlwithroot."/viewimage.php?modulepart=mycompany&file=".urlencode('logos/'.$mysoc->logo);
404
-	    $nvpstr = $nvpstr . "&LOGOIMG=" . urlencode($urllogo);
403
+        $urllogo=$urlwithroot."/viewimage.php?modulepart=mycompany&file=".urlencode('logos/'.$mysoc->logo);
404
+        $nvpstr = $nvpstr . "&LOGOIMG=" . urlencode($urllogo);
405 405
     }
406 406
     if (! empty($conf->global->PAYPAL_BRANDNAME))
407 407
     {
408
-    	$nvpstr = $nvpstr . "&BRANDNAME=" . urlencode($conf->global->PAYPAL_BRANDNAME);    // BRANDNAME
408
+        $nvpstr = $nvpstr . "&BRANDNAME=" . urlencode($conf->global->PAYPAL_BRANDNAME);    // BRANDNAME
409 409
     }
410 410
     if (! empty($conf->global->PAYPAL_NOTETOBUYER))
411 411
     {
412
-    	$nvpstr = $nvpstr . "&NOTETOBUYER=" . urlencode($conf->global->PAYPAL_NOTETOBUYER);  // PAYPAL_NOTETOBUYER
412
+        $nvpstr = $nvpstr . "&NOTETOBUYER=" . urlencode($conf->global->PAYPAL_NOTETOBUYER);  // PAYPAL_NOTETOBUYER
413 413
     }
414 414
 
415
-	$_SESSION["FinalPaymentAmt"] = $paymentAmount;
415
+    $_SESSION["FinalPaymentAmt"] = $paymentAmount;
416 416
     $_SESSION["currencyCodeType"] = $currencyCodeType;
417 417
     $_SESSION["PaymentType"] = $paymentType;			// 'Mark', 'Sole'
418 418
     $_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR'];   // Payer ip
@@ -592,27 +592,27 @@  discard block
 block discarded – undo
592 592
 
593 593
     // TODO problem with triggers
594 594
     $API_version="98.0";
595
-	if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))		// We can force sand box with param 'forcesandbox'
596
-	{
597
-	    $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
598
-	    $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
599
-	}
600
-	else
601
-	{
602
-	    $API_Endpoint = "https://api-3t.paypal.com/nvp";
603
-	    $API_Url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
604
-	}
605
-
606
-	// Clean parameters
607
-	$PAYPAL_API_USER="";
608
-	if (! empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
609
-	$PAYPAL_API_PASSWORD="";
610
-	if (! empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
611
-	$PAYPAL_API_SIGNATURE="";
612
-	if (! empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
613
-	$PAYPAL_API_SANDBOX="";
614
-	if (! empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
615
-	// TODO END problem with triggers
595
+    if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))		// We can force sand box with param 'forcesandbox'
596
+    {
597
+        $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
598
+        $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
599
+    }
600
+    else
601
+    {
602
+        $API_Endpoint = "https://api-3t.paypal.com/nvp";
603
+        $API_Url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
604
+    }
605
+
606
+    // Clean parameters
607
+    $PAYPAL_API_USER="";
608
+    if (! empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
609
+    $PAYPAL_API_PASSWORD="";
610
+    if (! empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
611
+    $PAYPAL_API_SIGNATURE="";
612
+    if (! empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
613
+    $PAYPAL_API_SANDBOX="";
614
+    if (! empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
615
+    // TODO END problem with triggers
616 616
 
617 617
     dol_syslog("Paypal API endpoint ".$API_Endpoint);
618 618
 
@@ -723,20 +723,20 @@  discard block
 block discarded – undo
723 723
  */
724 724
 function getApiError()
725 725
 {
726
-	$errors=array();
726
+    $errors=array();
727 727
 
728
-	$resArray=$_SESSION['reshash'];
728
+    $resArray=$_SESSION['reshash'];
729 729
 
730
-	if(isset($_SESSION['curl_error_no']))
731
-	{
732
-		$errors[] = $_SESSION['curl_error_no'].'-'.$_SESSION['curl_error_msg'];
733
-	}
730
+    if(isset($_SESSION['curl_error_no']))
731
+    {
732
+        $errors[] = $_SESSION['curl_error_no'].'-'.$_SESSION['curl_error_msg'];
733
+    }
734 734
 
735
-	foreach($resArray as $key => $value)
736
-	{
737
-		$errors[] = $key.'-'.$value;
738
-	}
735
+    foreach($resArray as $key => $value)
736
+    {
737
+        $errors[] = $key.'-'.$value;
738
+    }
739 739
 
740
-	return $errors;
740
+    return $errors;
741 741
 }
742 742
 
Please login to merge, or discard this patch.
Spacing   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -40,15 +40,15 @@  discard block
 block discarded – undo
40 40
 	$head[$h][2] = 'paypalaccount';
41 41
 	$h++;
42 42
 
43
-	$object=new stdClass();
43
+	$object = new stdClass();
44 44
 
45 45
     // Show more tabs from modules
46 46
     // Entries must be declared in modules descriptor with line
47 47
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
48 48
     // $this->tabs = array('entity:-tabname);   												to remove a tab
49
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'paypaladmin');
49
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'paypaladmin');
50 50
 
51
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'paypaladmin','remove');
51
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'paypaladmin', 'remove');
52 52
 
53 53
     return $head;
54 54
 }
@@ -62,18 +62,18 @@  discard block
 block discarded – undo
62 62
  * @param	string	$ref		Ref of object
63 63
  * @return	string				Url string
64 64
  */
65
-function showPaypalPaymentUrl($type,$ref)
65
+function showPaypalPaymentUrl($type, $ref)
66 66
 {
67 67
 	global $conf, $langs;
68 68
 
69 69
 	$langs->load("paypal");
70 70
     $langs->load("paybox");
71
-    $servicename='PayPal';
72
-    $out='<br><br>';
73
-    $out.=img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePayment",$servicename).'<br>';
74
-    $url=getPaypalPaymentUrl(0,$type,$ref);
75
-    $out.='<input type="text" id="paypalurl" class="quatrevingtpercent" value="'.$url.'">';
76
-    $out.=ajax_autoselect("paypalurl", 0);
71
+    $servicename = 'PayPal';
72
+    $out = '<br><br>';
73
+    $out .= img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePayment", $servicename).'<br>';
74
+    $url = getPaypalPaymentUrl(0, $type, $ref);
75
+    $out .= '<input type="text" id="paypalurl" class="quatrevingtpercent" value="'.$url.'">';
76
+    $out .= ajax_autoselect("paypalurl", 0);
77 77
     return $out;
78 78
 }
79 79
 
@@ -88,96 +88,96 @@  discard block
 block discarded – undo
88 88
  * @param	string	$freetag	Free tag
89 89
  * @return	string				Url string
90 90
  */
91
-function getPaypalPaymentUrl($mode,$type,$ref='',$amount='9.99',$freetag='your_free_tag')
91
+function getPaypalPaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_free_tag')
92 92
 {
93 93
 	global $conf;
94 94
 
95
-	$ref=str_replace(' ','',$ref);
95
+	$ref = str_replace(' ', '', $ref);
96 96
 
97 97
     if ($type == 'free')
98 98
     {
99
-	    $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':'');
100
-	    if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
99
+	    $out = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?amount='.($mode ? '<font color="#666666">' : '').$amount.($mode ? '</font>' : '').'&tag='.($mode ? '<font color="#666666">' : '').$freetag.($mode ? '</font>' : '');
100
+	    if (!empty($conf->global->PAYPAL_SECURITY_TOKEN))
101 101
 	    {
102
-	    	if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
103
-	    	else $out.='&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
102
+	    	if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
103
+	    	else $out .= '&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
104 104
 	    }
105 105
     }
106 106
     if ($type == 'order')
107 107
     {
108
-        $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=order&ref='.($mode?'<font color="#666666">':'');
109
-        if ($mode == 1) $out.='order_ref';
110
-        if ($mode == 0) $out.=urlencode($ref);
111
-	    $out.=($mode?'</font>':'');
112
-        if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
108
+        $out = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=order&ref='.($mode ? '<font color="#666666">' : '');
109
+        if ($mode == 1) $out .= 'order_ref';
110
+        if ($mode == 0) $out .= urlencode($ref);
111
+	    $out .= ($mode ? '</font>' : '');
112
+        if (!empty($conf->global->PAYPAL_SECURITY_TOKEN))
113 113
         {
114
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
114
+    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
115 115
             else
116 116
             {
117
-                $out.='&securekey='.($mode?'<font color="#666666">':'');
118
-                if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + order_ref)";
119
-                if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
120
-                $out.=($mode?'</font>':'');
117
+                $out .= '&securekey='.($mode ? '<font color="#666666">' : '');
118
+                if ($mode == 1) $out .= "hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + order_ref)";
119
+                if ($mode == 0) $out .= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.$type.$ref, 2);
120
+                $out .= ($mode ? '</font>' : '');
121 121
             }
122 122
         }
123 123
     }
124 124
     if ($type == 'invoice')
125 125
     {
126
-        $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=invoice&ref='.($mode?'<font color="#666666">':'');
127
-        if ($mode == 1) $out.='invoice_ref';
128
-        if ($mode == 0) $out.=urlencode($ref);
129
-	    $out.=($mode?'</font>':'');
130
-        if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
126
+        $out = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=invoice&ref='.($mode ? '<font color="#666666">' : '');
127
+        if ($mode == 1) $out .= 'invoice_ref';
128
+        if ($mode == 0) $out .= urlencode($ref);
129
+	    $out .= ($mode ? '</font>' : '');
130
+        if (!empty($conf->global->PAYPAL_SECURITY_TOKEN))
131 131
         {
132
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
132
+    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
133 133
             else
134 134
             {
135
-                $out.='&securekey='.($mode?'<font color="#666666">':'');
136
-                if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
137
-                if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
138
-                $out.=($mode?'</font>':'');
135
+                $out .= '&securekey='.($mode ? '<font color="#666666">' : '');
136
+                if ($mode == 1) $out .= "hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
137
+                if ($mode == 0) $out .= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.$type.$ref, 2);
138
+                $out .= ($mode ? '</font>' : '');
139 139
             }
140 140
         }
141 141
     }
142 142
     if ($type == 'contractline')
143 143
     {
144
-        $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=contractline&ref='.($mode?'<font color="#666666">':'');
145
-        if ($mode == 1) $out.='contractline_ref';
146
-        if ($mode == 0) $out.=urlencode($ref);
147
-	    $out.=($mode?'</font>':'');
148
-        if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
144
+        $out = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=contractline&ref='.($mode ? '<font color="#666666">' : '');
145
+        if ($mode == 1) $out .= 'contractline_ref';
146
+        if ($mode == 0) $out .= urlencode($ref);
147
+	    $out .= ($mode ? '</font>' : '');
148
+        if (!empty($conf->global->PAYPAL_SECURITY_TOKEN))
149 149
         {
150
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
150
+    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
151 151
             else
152 152
             {
153
-                $out.='&securekey='.($mode?'<font color="#666666">':'');
154
-                if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + contractline_ref)";
155
-                if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
156
-                $out.=($mode?'</font>':'');
153
+                $out .= '&securekey='.($mode ? '<font color="#666666">' : '');
154
+                if ($mode == 1) $out .= "hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + contractline_ref)";
155
+                if ($mode == 0) $out .= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.$type.$ref, 2);
156
+                $out .= ($mode ? '</font>' : '');
157 157
             }
158 158
         }
159 159
     }
160 160
     if ($type == 'membersubscription')
161 161
     {
162
-        $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=membersubscription&ref='.($mode?'<font color="#666666">':'');
163
-        if ($mode == 1) $out.='member_ref';
164
-        if ($mode == 0) $out.=urlencode($ref);
165
-	    $out.=($mode?'</font>':'');
166
-        if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
162
+        $out = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=membersubscription&ref='.($mode ? '<font color="#666666">' : '');
163
+        if ($mode == 1) $out .= 'member_ref';
164
+        if ($mode == 0) $out .= urlencode($ref);
165
+	    $out .= ($mode ? '</font>' : '');
166
+        if (!empty($conf->global->PAYPAL_SECURITY_TOKEN))
167 167
         {
168
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
168
+    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
169 169
             else
170 170
             {
171
-                $out.='&securekey='.($mode?'<font color="#666666">':'');
172
-                if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + member_ref)";
173
-                if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
174
-                $out.=($mode?'</font>':'');
171
+                $out .= '&securekey='.($mode ? '<font color="#666666">' : '');
172
+                if ($mode == 1) $out .= "hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + member_ref)";
173
+                if ($mode == 0) $out .= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.$type.$ref, 2);
174
+                $out .= ($mode ? '</font>' : '');
175 175
             }
176 176
         }
177 177
     }
178 178
 
179 179
     // For multicompany
180
-    $out.="&entity=".$conf->entity; // Check the entity because He may be the same reference in several entities
180
+    $out .= "&entity=".$conf->entity; // Check the entity because He may be the same reference in several entities
181 181
 
182 182
     return $out;
183 183
 }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
  * @param   string	$tag				Full tag
195 195
  * @return	string						No return (a redirect is done) if OK, or Error message if KO
196 196
  */
197
-function print_paypal_redirect($paymentAmount,$currencyCodeType,$paymentType,$returnURL,$cancelURL,$tag)
197
+function print_paypal_redirect($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag)
198 198
 {
199 199
     //declaring of global variables
200 200
     global $conf, $langs;
@@ -209,27 +209,27 @@  discard block
 block discarded – undo
209 209
     //'
210 210
     //'-------------------------------------------------
211 211
 
212
-    if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY='integral';
212
+    if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY = 'integral';
213 213
 
214
-    $solutionType='Sole';
215
-    $landingPage='Billing';
214
+    $solutionType = 'Sole';
215
+    $landingPage = 'Billing';
216 216
     // For payment with Paypal only
217 217
     if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'paypalonly')
218 218
     {
219
-        $solutionType='Mark';
220
-        $landingPage='Login';
219
+        $solutionType = 'Mark';
220
+        $landingPage = 'Login';
221 221
     }
222 222
     // For payment with Credit card or Paypal
223 223
     if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'integral')
224 224
     {
225
-        $solutionType='Sole';
226
-        $landingPage='Billing';
225
+        $solutionType = 'Sole';
226
+        $landingPage = 'Billing';
227 227
     }
228 228
     // For payment with Credit card
229 229
     if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'cconly')
230 230
     {
231
-        $solutionType='Sole';
232
-        $landingPage='Billing';
231
+        $solutionType = 'Sole';
232
+        $landingPage = 'Billing';
233 233
     }
234 234
 
235 235
     dol_syslog("expresscheckout redirect with callSetExpressCheckout $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage, $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum");
@@ -255,12 +255,12 @@  discard block
 block discarded – undo
255 255
     );
256 256
 
257 257
     $ack = strtoupper($resArray["ACK"]);
258
-    if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
258
+    if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING")
259 259
     {
260
-        $token=$resArray["TOKEN"];
260
+        $token = $resArray["TOKEN"];
261 261
 
262 262
         // Redirect to paypal.com here
263
-        $payPalURL = $API_Url . $token;
263
+        $payPalURL = $API_Url.$token;
264 264
         header("Location: ".$payPalURL);
265 265
         exit;
266 266
     }
@@ -274,15 +274,15 @@  discard block
 block discarded – undo
274 274
 
275 275
         if ($ErrorCode == 10729)
276 276
         {
277
-        	$mesg.= "PayPal can't accept payments for this thirdparty. An address is defined but is not complete (missing State).<br>Ask system administrator to fix address or to setup Paypal module to accept payments even on not complete addresses (remove option PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS).<br>\n";
277
+        	$mesg .= "PayPal can't accept payments for this thirdparty. An address is defined but is not complete (missing State).<br>Ask system administrator to fix address or to setup Paypal module to accept payments even on not complete addresses (remove option PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS).<br>\n";
278 278
         }
279 279
         else
280 280
         {
281
-        	$mesg = $langs->trans('SetExpressCheckoutAPICallFailed') . "<br>\n";
282
-        	$mesg.= $langs->trans('DetailedErrorMessage') . ": " . $ErrorLongMsg."<br>\n";
283
-        	$mesg.= $langs->trans('ShortErrorMessage') . ": " . $ErrorShortMsg."<br>\n";
284
-        	$mesg.= $langs->trans('ErrorCode') . ": " . $ErrorCode."<br>\n";
285
-        	$mesg.= $langs->trans('ErrorSeverityCode') . ": " . $ErrorSeverityCode."<br>\n";
281
+        	$mesg = $langs->trans('SetExpressCheckoutAPICallFailed')."<br>\n";
282
+        	$mesg .= $langs->trans('DetailedErrorMessage').": ".$ErrorLongMsg."<br>\n";
283
+        	$mesg .= $langs->trans('ShortErrorMessage').": ".$ErrorShortMsg."<br>\n";
284
+        	$mesg .= $langs->trans('ErrorCode').": ".$ErrorCode."<br>\n";
285
+        	$mesg .= $langs->trans('ErrorSeverityCode').": ".$ErrorSeverityCode."<br>\n";
286 286
         }
287 287
 
288 288
         return $mesg;
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
  * @param	string			$desc				Description
331 331
  * @return	array								Array
332 332
  */
333
-function callSetExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage, $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum, $email='', $desc='')
333
+function callSetExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage, $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum, $email = '', $desc = '')
334 334
 {
335 335
     //------------------------------------------------------------------------------------------------------------------------------------
336 336
     // Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
@@ -342,92 +342,92 @@  discard block
 block discarded – undo
342 342
 
343 343
     $nvpstr = '';
344 344
     //$nvpstr = $nvpstr . "&VERSION=".$API_version;				// Already added by hash_call
345
-    $nvpstr = $nvpstr . "&RETURNURL=" . urlencode($returnURL);
346
-    $nvpstr = $nvpstr . "&CANCELURL=" . urlencode($cancelURL);
347
-    if (! empty($conf->global->PAYPAL_ALLOW_NOTES))
345
+    $nvpstr = $nvpstr."&RETURNURL=".urlencode($returnURL);
346
+    $nvpstr = $nvpstr."&CANCELURL=".urlencode($cancelURL);
347
+    if (!empty($conf->global->PAYPAL_ALLOW_NOTES))
348 348
     {
349
-    	$nvpstr = $nvpstr . "&ALLOWNOTE=0";
349
+    	$nvpstr = $nvpstr."&ALLOWNOTE=0";
350 350
     }
351 351
     if (empty($conf->global->PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS))
352 352
     {
353
-    	$nvpstr = $nvpstr . "&NOSHIPPING=1";	// An empty or not complete shipping address will be accepted
353
+    	$nvpstr = $nvpstr."&NOSHIPPING=1"; // An empty or not complete shipping address will be accepted
354 354
     }
355 355
     else
356 356
     {
357
-    	$nvpstr = $nvpstr . "&NOSHIPPING=0";	// A valid shipping address is required (full required fields mandatory)
357
+    	$nvpstr = $nvpstr."&NOSHIPPING=0"; // A valid shipping address is required (full required fields mandatory)
358 358
     }
359
-    $nvpstr = $nvpstr . "&SOLUTIONTYPE=" . urlencode($solutionType);
360
-    $nvpstr = $nvpstr . "&LANDINGPAGE=" . urlencode($landingPage);
361
-    if (! empty($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER))
359
+    $nvpstr = $nvpstr."&SOLUTIONTYPE=".urlencode($solutionType);
360
+    $nvpstr = $nvpstr."&LANDINGPAGE=".urlencode($landingPage);
361
+    if (!empty($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER))
362 362
     {
363
-    	$nvpstr = $nvpstr . "&CUSTOMERSERVICENUMBER=" . urlencode($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER);    // Hotline phone number
363
+    	$nvpstr = $nvpstr."&CUSTOMERSERVICENUMBER=".urlencode($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER); // Hotline phone number
364 364
     }
365 365
 
366 366
     $paypalprefix = 'PAYMENTREQUEST_0_';
367 367
     //$paypalprefix = '';
368
-	if (! empty($paypalprefix) && $paymentType == 'Sole') $paymentType='Sale';
369
-
370
-	$nvpstr = $nvpstr . "&AMT=". urlencode($paymentAmount);									// Total for all elements
371
-
372
-    $nvpstr = $nvpstr . "&".$paypalprefix."INVNUM=" . urlencode($tag);
373
-    $nvpstr = $nvpstr . "&".$paypalprefix."AMT=". urlencode($paymentAmount);                 // AMT deprecated by paypal -> PAYMENTREQUEST_n_AMT
374
-    $nvpstr = $nvpstr . "&".$paypalprefix."ITEMAMT=". urlencode($paymentAmount);             // AMT deprecated by paypal -> PAYMENTREQUEST_n_AMT
375
-    $nvpstr = $nvpstr . "&".$paypalprefix."PAYMENTACTION=" . urlencode($paymentType);        // PAYMENTACTION deprecated by paypal -> PAYMENTREQUEST_n_PAYMENTACTION
376
-    $nvpstr = $nvpstr . "&".$paypalprefix."CURRENCYCODE=" . urlencode($currencyCodeType);    // CURRENCYCODE deprecated by paypal -> PAYMENTREQUEST_n_CURRENCYCODE
377
-
378
-    $nvpstr = $nvpstr . "&".$paypalprefix."L_PAYMENTREQUEST_0_QTY0=1";
379
-    $nvpstr = $nvpstr . "&".$paypalprefix."L_PAYMENTREQUEST_0_AMT0=".urlencode($paymentAmount);
380
-    $nvpstr = $nvpstr . "&".$paypalprefix."L_PAYMENTREQUEST_0_NAME0=".urlencode($desc);
381
-    $nvpstr = $nvpstr . "&".$paypalprefix."L_PAYMENTREQUEST_0_NUMBER0=0";
382
-
383
-    $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTONAME=" . urlencode($shipToName);            // SHIPTONAME deprecated by paypal -> PAYMENTREQUEST_n_SHIPTONAME
384
-    $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOSTREET=" . urlencode($shipToStreet);        //
385
-    $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOSTREET2=" . urlencode($shipToStreet2);
386
-    $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOCITY=" . urlencode($shipToCity);
387
-    $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOSTATE=" . urlencode($shipToState);
388
-    $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOCOUNTRYCODE=" . urlencode($shipToCountryCode);
389
-    $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOZIP=" . urlencode($shipToZip);
390
-    $nvpstr = $nvpstr . "&".$paypalprefix."PHONENUM=" . urlencode($phoneNum);
391
-    if (! empty($email)) $nvpstr = $nvpstr . "&".$paypalprefix."EMAIL=" . urlencode($email);      // EMAIL deprecated by paypal -> PAYMENTREQUEST_n_EMAIL
392
-    if (! empty($desc))  $nvpstr = $nvpstr . "&".$paypalprefix."DESC=" . urlencode($desc);        // DESC deprecated by paypal -> PAYMENTREQUEST_n_DESC
393
-
394
-    if (! empty($conf->global->PAYPAL_LOGOIMG) && $mysoc->logo)
368
+	if (!empty($paypalprefix) && $paymentType == 'Sole') $paymentType = 'Sale';
369
+
370
+	$nvpstr = $nvpstr."&AMT=".urlencode($paymentAmount); // Total for all elements
371
+
372
+    $nvpstr = $nvpstr."&".$paypalprefix."INVNUM=".urlencode($tag);
373
+    $nvpstr = $nvpstr."&".$paypalprefix."AMT=".urlencode($paymentAmount); // AMT deprecated by paypal -> PAYMENTREQUEST_n_AMT
374
+    $nvpstr = $nvpstr."&".$paypalprefix."ITEMAMT=".urlencode($paymentAmount); // AMT deprecated by paypal -> PAYMENTREQUEST_n_AMT
375
+    $nvpstr = $nvpstr."&".$paypalprefix."PAYMENTACTION=".urlencode($paymentType); // PAYMENTACTION deprecated by paypal -> PAYMENTREQUEST_n_PAYMENTACTION
376
+    $nvpstr = $nvpstr."&".$paypalprefix."CURRENCYCODE=".urlencode($currencyCodeType); // CURRENCYCODE deprecated by paypal -> PAYMENTREQUEST_n_CURRENCYCODE
377
+
378
+    $nvpstr = $nvpstr."&".$paypalprefix."L_PAYMENTREQUEST_0_QTY0=1";
379
+    $nvpstr = $nvpstr."&".$paypalprefix."L_PAYMENTREQUEST_0_AMT0=".urlencode($paymentAmount);
380
+    $nvpstr = $nvpstr."&".$paypalprefix."L_PAYMENTREQUEST_0_NAME0=".urlencode($desc);
381
+    $nvpstr = $nvpstr."&".$paypalprefix."L_PAYMENTREQUEST_0_NUMBER0=0";
382
+
383
+    $nvpstr = $nvpstr."&".$paypalprefix."SHIPTONAME=".urlencode($shipToName); // SHIPTONAME deprecated by paypal -> PAYMENTREQUEST_n_SHIPTONAME
384
+    $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOSTREET=".urlencode($shipToStreet); //
385
+    $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOSTREET2=".urlencode($shipToStreet2);
386
+    $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOCITY=".urlencode($shipToCity);
387
+    $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOSTATE=".urlencode($shipToState);
388
+    $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOCOUNTRYCODE=".urlencode($shipToCountryCode);
389
+    $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOZIP=".urlencode($shipToZip);
390
+    $nvpstr = $nvpstr."&".$paypalprefix."PHONENUM=".urlencode($phoneNum);
391
+    if (!empty($email)) $nvpstr = $nvpstr."&".$paypalprefix."EMAIL=".urlencode($email); // EMAIL deprecated by paypal -> PAYMENTREQUEST_n_EMAIL
392
+    if (!empty($desc))  $nvpstr = $nvpstr."&".$paypalprefix."DESC=".urlencode($desc); // DESC deprecated by paypal -> PAYMENTREQUEST_n_DESC
393
+
394
+    if (!empty($conf->global->PAYPAL_LOGOIMG) && $mysoc->logo)
395 395
     {
396 396
     	global $dolibarr_main_url_root;
397 397
 
398 398
 	    // Define $urlwithroot
399
-	    $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
400
-	    $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
399
+	    $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
400
+	    $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
401 401
 	    //$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
402 402
 
403
-	    $urllogo=$urlwithroot."/viewimage.php?modulepart=mycompany&file=".urlencode('logos/'.$mysoc->logo);
404
-	    $nvpstr = $nvpstr . "&LOGOIMG=" . urlencode($urllogo);
403
+	    $urllogo = $urlwithroot."/viewimage.php?modulepart=mycompany&file=".urlencode('logos/'.$mysoc->logo);
404
+	    $nvpstr = $nvpstr."&LOGOIMG=".urlencode($urllogo);
405 405
     }
406
-    if (! empty($conf->global->PAYPAL_BRANDNAME))
406
+    if (!empty($conf->global->PAYPAL_BRANDNAME))
407 407
     {
408
-    	$nvpstr = $nvpstr . "&BRANDNAME=" . urlencode($conf->global->PAYPAL_BRANDNAME);    // BRANDNAME
408
+    	$nvpstr = $nvpstr."&BRANDNAME=".urlencode($conf->global->PAYPAL_BRANDNAME); // BRANDNAME
409 409
     }
410
-    if (! empty($conf->global->PAYPAL_NOTETOBUYER))
410
+    if (!empty($conf->global->PAYPAL_NOTETOBUYER))
411 411
     {
412
-    	$nvpstr = $nvpstr . "&NOTETOBUYER=" . urlencode($conf->global->PAYPAL_NOTETOBUYER);  // PAYPAL_NOTETOBUYER
412
+    	$nvpstr = $nvpstr."&NOTETOBUYER=".urlencode($conf->global->PAYPAL_NOTETOBUYER); // PAYPAL_NOTETOBUYER
413 413
     }
414 414
 
415 415
 	$_SESSION["FinalPaymentAmt"] = $paymentAmount;
416 416
     $_SESSION["currencyCodeType"] = $currencyCodeType;
417
-    $_SESSION["PaymentType"] = $paymentType;			// 'Mark', 'Sole'
418
-    $_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR'];   // Payer ip
417
+    $_SESSION["PaymentType"] = $paymentType; // 'Mark', 'Sole'
418
+    $_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR']; // Payer ip
419 419
 
420 420
     //'---------------------------------------------------------------------------------------------------------------
421 421
     //' Make the API call to PayPal
422 422
     //' If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment.
423 423
     //' If an error occured, show the resulting errors
424 424
     //'---------------------------------------------------------------------------------------------------------------
425
-    $resArray=hash_call("SetExpressCheckout", $nvpstr);
425
+    $resArray = hash_call("SetExpressCheckout", $nvpstr);
426 426
     $ack = strtoupper($resArray["ACK"]);
427
-    if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
427
+    if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING")
428 428
     {
429 429
         $token = urldecode($resArray["TOKEN"]);
430
-        $_SESSION['TOKEN']=$token;
430
+        $_SESSION['TOKEN'] = $token;
431 431
     }
432 432
 
433 433
     return $resArray;
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
     //' Build a second API request to PayPal, using the token as the
460 460
     //'  ID to get the details on the payment authorization
461 461
     //'---------------------------------------------------------------------------
462
-    $nvpstr="&TOKEN=" . $token;
462
+    $nvpstr = "&TOKEN=".$token;
463 463
 
464 464
     //'---------------------------------------------------------------------------
465 465
     //' Make the API call and store the results in an array.
@@ -467,9 +467,9 @@  discard block
 block discarded – undo
467 467
     //'     an action to complete the payment.
468 468
     //' If failed, show the error
469 469
     //'---------------------------------------------------------------------------
470
-    $resArray=hash_call("GetExpressCheckoutDetails",$nvpstr);
470
+    $resArray = hash_call("GetExpressCheckoutDetails", $nvpstr);
471 471
     $ack = strtoupper($resArray["ACK"]);
472
-    if($ack == "SUCCESS" || $ack=="SUCCESSWITHWARNING")
472
+    if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING")
473 473
     {
474 474
         $_SESSION['payer_id'] = $resArray['PAYERID'];
475 475
     }
@@ -502,18 +502,18 @@  discard block
 block discarded – undo
502 502
     global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
503 503
 
504 504
     $nvpstr = '';
505
-    $nvpstr .= '&TOKEN=' . urlencode($token);
506
-    $nvpstr .= '&PAYERID=' . urlencode($payerID);
507
-    $nvpstr .= '&PAYMENTACTION=' . urlencode($paymentType);
508
-    $nvpstr .= '&AMT=' . urlencode($FinalPaymentAmt);
509
-    $nvpstr .= '&CURRENCYCODE=' . urlencode($currencyCodeType);
510
-    $nvpstr .= '&IPADDRESS=' . urlencode($ipaddress);
511
-    $nvpstr .= '&INVNUM=' . urlencode($tag);
505
+    $nvpstr .= '&TOKEN='.urlencode($token);
506
+    $nvpstr .= '&PAYERID='.urlencode($payerID);
507
+    $nvpstr .= '&PAYMENTACTION='.urlencode($paymentType);
508
+    $nvpstr .= '&AMT='.urlencode($FinalPaymentAmt);
509
+    $nvpstr .= '&CURRENCYCODE='.urlencode($currencyCodeType);
510
+    $nvpstr .= '&IPADDRESS='.urlencode($ipaddress);
511
+    $nvpstr .= '&INVNUM='.urlencode($tag);
512 512
 
513 513
     /* Make the call to PayPal to finalize payment
514 514
      If an error occured, show the resulting errors
515 515
      */
516
-    $resArray=hash_call("DoExpressCheckoutPayment",$nvpstr);
516
+    $resArray = hash_call("DoExpressCheckoutPayment", $nvpstr);
517 517
 
518 518
     /* Display the API response back to the browser.
519 519
      If the response from PayPal was a success, display the response parameters'
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
  * @param	string	$nvpStr 		is nvp string.
584 584
  * @return	array					returns an associtive array containing the response from the server.
585 585
  */
586
-function hash_call($methodName,$nvpStr)
586
+function hash_call($methodName, $nvpStr)
587 587
 {
588 588
     //declaring of global variables
589 589
     global $conf, $langs;
@@ -591,8 +591,8 @@  discard block
 block discarded – undo
591 591
     global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
592 592
 
593 593
     // TODO problem with triggers
594
-    $API_version="98.0";
595
-	if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))		// We can force sand box with param 'forcesandbox'
594
+    $API_version = "98.0";
595
+	if (!empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox', 'alpha'))		// We can force sand box with param 'forcesandbox'
596 596
 	{
597 597
 	    $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
598 598
 	    $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
@@ -604,14 +604,14 @@  discard block
 block discarded – undo
604 604
 	}
605 605
 
606 606
 	// Clean parameters
607
-	$PAYPAL_API_USER="";
608
-	if (! empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
609
-	$PAYPAL_API_PASSWORD="";
610
-	if (! empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
611
-	$PAYPAL_API_SIGNATURE="";
612
-	if (! empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
613
-	$PAYPAL_API_SANDBOX="";
614
-	if (! empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
607
+	$PAYPAL_API_USER = "";
608
+	if (!empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER = $conf->global->PAYPAL_API_USER;
609
+	$PAYPAL_API_PASSWORD = "";
610
+	if (!empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD = $conf->global->PAYPAL_API_PASSWORD;
611
+	$PAYPAL_API_SIGNATURE = "";
612
+	if (!empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE = $conf->global->PAYPAL_API_SIGNATURE;
613
+	$PAYPAL_API_SANDBOX = "";
614
+	if (!empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX = $conf->global->PAYPAL_API_SANDBOX;
615 615
 	// TODO END problem with triggers
616 616
 
617 617
     dol_syslog("Paypal API endpoint ".$API_Endpoint);
@@ -626,30 +626,30 @@  discard block
 block discarded – undo
626 626
     curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
627 627
     curl_setopt($ch, CURLOPT_VERBOSE, 1);
628 628
     // TLSv1 by default or change to TLSv1.2 in module configuration
629
-    curl_setopt($ch, CURLOPT_SSLVERSION, (empty($conf->global->PAYPAL_SSLVERSION)?1:$conf->global->PAYPAL_SSLVERSION));
629
+    curl_setopt($ch, CURLOPT_SSLVERSION, (empty($conf->global->PAYPAL_SSLVERSION) ? 1 : $conf->global->PAYPAL_SSLVERSION));
630 630
 
631 631
     //turning off the server and peer verification(TrustManager Concept).
632 632
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
633 633
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
634 634
 
635
-    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)?5:$conf->global->MAIN_USE_CONNECT_TIMEOUT);
636
-    curl_setopt($ch, CURLOPT_TIMEOUT, empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT)?30:$conf->global->MAIN_USE_RESPONSE_TIMEOUT);
635
+    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, empty($conf->global->MAIN_USE_CONNECT_TIMEOUT) ? 5 : $conf->global->MAIN_USE_CONNECT_TIMEOUT);
636
+    curl_setopt($ch, CURLOPT_TIMEOUT, empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT) ? 30 : $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
637 637
 
638
-    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
638
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
639 639
     curl_setopt($ch, CURLOPT_POST, 1);
640 640
 
641 641
     //if USE_PROXY constant set to true in Constants.php, then only proxy will be enabled.
642 642
     if ($USE_PROXY)
643 643
     {
644
-        dol_syslog("Paypal API hash_call set proxy to ".$PROXY_HOST. ":" . $PROXY_PORT." - ".$PROXY_USER. ":" . $PROXY_PASS);
644
+        dol_syslog("Paypal API hash_call set proxy to ".$PROXY_HOST.":".$PROXY_PORT." - ".$PROXY_USER.":".$PROXY_PASS);
645 645
         //curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); // Curl 7.10
646
-        curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST. ":" . $PROXY_PORT);
647
-        if ($PROXY_USER) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER. ":" . $PROXY_PASS);
646
+        curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST.":".$PROXY_PORT);
647
+        if ($PROXY_USER) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER.":".$PROXY_PASS);
648 648
     }
649 649
 
650 650
     //NVPRequest for submitting to server
651
-    $nvpreq ="METHOD=" . urlencode($methodName) . "&VERSION=" . urlencode($API_version) . "&PWD=" . urlencode($PAYPAL_API_PASSWORD) . "&USER=" . urlencode($PAYPAL_API_USER) . "&SIGNATURE=" . urlencode($PAYPAL_API_SIGNATURE) . $nvpStr;
652
-    $nvpreq.="&LOCALECODE=".strtoupper($langs->getDefaultLang(1));
651
+    $nvpreq = "METHOD=".urlencode($methodName)."&VERSION=".urlencode($API_version)."&PWD=".urlencode($PAYPAL_API_PASSWORD)."&USER=".urlencode($PAYPAL_API_USER)."&SIGNATURE=".urlencode($PAYPAL_API_SIGNATURE).$nvpStr;
652
+    $nvpreq .= "&LOCALECODE=".strtoupper($langs->getDefaultLang(1));
653 653
     //$nvpreq.="&BRANDNAME=".urlencode();       // Override merchant name
654 654
     //$nvpreq.="&NOTIFYURL=".urlencode();       // For Instant Payment Notification url
655 655
 
@@ -662,18 +662,18 @@  discard block
 block discarded – undo
662 662
     //getting response from server
663 663
     $response = curl_exec($ch);
664 664
 
665
-    $nvpReqArray=deformatNVP($nvpreq);
666
-    $_SESSION['nvpReqArray']=$nvpReqArray;
665
+    $nvpReqArray = deformatNVP($nvpreq);
666
+    $_SESSION['nvpReqArray'] = $nvpReqArray;
667 667
 
668 668
     //convrting NVPResponse to an Associative Array
669 669
     dol_syslog("Paypal API hash_call Response nvpresp=".$response);
670
-    $nvpResArray=deformatNVP($response);
670
+    $nvpResArray = deformatNVP($response);
671 671
 
672 672
     if (curl_errno($ch))
673 673
     {
674 674
         // moving to display page to display curl errors
675
-        $_SESSION['curl_error_no']=curl_errno($ch);
676
-        $_SESSION['curl_error_msg']=curl_error($ch);
675
+        $_SESSION['curl_error_no'] = curl_errno($ch);
676
+        $_SESSION['curl_error_msg'] = curl_error($ch);
677 677
 
678 678
         //Execute the Error handling module to display errors.
679 679
     }
@@ -696,22 +696,22 @@  discard block
 block discarded – undo
696 696
  */
697 697
 function deformatNVP($nvpstr)
698 698
 {
699
-    $intial=0;
699
+    $intial = 0;
700 700
     $nvpArray = array();
701 701
 
702
-    while(strlen($nvpstr))
702
+    while (strlen($nvpstr))
703 703
     {
704 704
         //postion of Key
705
-        $keypos= strpos($nvpstr,'=');
705
+        $keypos = strpos($nvpstr, '=');
706 706
         //position of value
707
-        $valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): strlen($nvpstr);
707
+        $valuepos = strpos($nvpstr, '&') ? strpos($nvpstr, '&') : strlen($nvpstr);
708 708
 
709 709
         /*getting the Key and Value values and storing in a Associative Array*/
710
-        $keyval=substr($nvpstr,$intial,$keypos);
711
-        $valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1);
710
+        $keyval = substr($nvpstr, $intial, $keypos);
711
+        $valval = substr($nvpstr, $keypos + 1, $valuepos - $keypos - 1);
712 712
         //decoding the respose
713
-        $nvpArray[urldecode($keyval)] =urldecode($valval);
714
-        $nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr));
713
+        $nvpArray[urldecode($keyval)] = urldecode($valval);
714
+        $nvpstr = substr($nvpstr, $valuepos + 1, strlen($nvpstr));
715 715
     }
716 716
     return $nvpArray;
717 717
 }
@@ -723,16 +723,16 @@  discard block
 block discarded – undo
723 723
  */
724 724
 function getApiError()
725 725
 {
726
-	$errors=array();
726
+	$errors = array();
727 727
 
728
-	$resArray=$_SESSION['reshash'];
728
+	$resArray = $_SESSION['reshash'];
729 729
 
730
-	if(isset($_SESSION['curl_error_no']))
730
+	if (isset($_SESSION['curl_error_no']))
731 731
 	{
732 732
 		$errors[] = $_SESSION['curl_error_no'].'-'.$_SESSION['curl_error_msg'];
733 733
 	}
734 734
 
735
-	foreach($resArray as $key => $value)
735
+	foreach ($resArray as $key => $value)
736 736
 	{
737 737
 		$errors[] = $key.'-'.$value;
738 738
 	}
Please login to merge, or discard this patch.
Braces   +102 added lines, -46 removed lines patch added patch discarded remove patch
@@ -99,24 +99,36 @@  discard block
 block discarded – undo
99 99
 	    $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':'');
100 100
 	    if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
101 101
 	    {
102
-	    	if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
103
-	    	else $out.='&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
102
+	    	if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
103
+	    	    $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
104
+	    	} else {
105
+	    	    $out.='&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
106
+	    	}
104 107
 	    }
105 108
     }
106 109
     if ($type == 'order')
107 110
     {
108 111
         $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=order&ref='.($mode?'<font color="#666666">':'');
109
-        if ($mode == 1) $out.='order_ref';
110
-        if ($mode == 0) $out.=urlencode($ref);
112
+        if ($mode == 1) {
113
+            $out.='order_ref';
114
+        }
115
+        if ($mode == 0) {
116
+            $out.=urlencode($ref);
117
+        }
111 118
 	    $out.=($mode?'</font>':'');
112 119
         if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
113 120
         {
114
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
115
-            else
121
+    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
122
+    	        $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
123
+    	    } else
116 124
             {
117 125
                 $out.='&securekey='.($mode?'<font color="#666666">':'');
118
-                if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + order_ref)";
119
-                if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
126
+                if ($mode == 1) {
127
+                    $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + order_ref)";
128
+                }
129
+                if ($mode == 0) {
130
+                    $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
131
+                }
120 132
                 $out.=($mode?'</font>':'');
121 133
             }
122 134
         }
@@ -124,17 +136,26 @@  discard block
 block discarded – undo
124 136
     if ($type == 'invoice')
125 137
     {
126 138
         $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=invoice&ref='.($mode?'<font color="#666666">':'');
127
-        if ($mode == 1) $out.='invoice_ref';
128
-        if ($mode == 0) $out.=urlencode($ref);
139
+        if ($mode == 1) {
140
+            $out.='invoice_ref';
141
+        }
142
+        if ($mode == 0) {
143
+            $out.=urlencode($ref);
144
+        }
129 145
 	    $out.=($mode?'</font>':'');
130 146
         if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
131 147
         {
132
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
133
-            else
148
+    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
149
+    	        $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
150
+    	    } else
134 151
             {
135 152
                 $out.='&securekey='.($mode?'<font color="#666666">':'');
136
-                if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
137
-                if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
153
+                if ($mode == 1) {
154
+                    $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
155
+                }
156
+                if ($mode == 0) {
157
+                    $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
158
+                }
138 159
                 $out.=($mode?'</font>':'');
139 160
             }
140 161
         }
@@ -142,17 +163,26 @@  discard block
 block discarded – undo
142 163
     if ($type == 'contractline')
143 164
     {
144 165
         $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=contractline&ref='.($mode?'<font color="#666666">':'');
145
-        if ($mode == 1) $out.='contractline_ref';
146
-        if ($mode == 0) $out.=urlencode($ref);
166
+        if ($mode == 1) {
167
+            $out.='contractline_ref';
168
+        }
169
+        if ($mode == 0) {
170
+            $out.=urlencode($ref);
171
+        }
147 172
 	    $out.=($mode?'</font>':'');
148 173
         if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
149 174
         {
150
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
151
-            else
175
+    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
176
+    	        $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
177
+    	    } else
152 178
             {
153 179
                 $out.='&securekey='.($mode?'<font color="#666666">':'');
154
-                if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + contractline_ref)";
155
-                if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
180
+                if ($mode == 1) {
181
+                    $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + contractline_ref)";
182
+                }
183
+                if ($mode == 0) {
184
+                    $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
185
+                }
156 186
                 $out.=($mode?'</font>':'');
157 187
             }
158 188
         }
@@ -160,17 +190,26 @@  discard block
 block discarded – undo
160 190
     if ($type == 'membersubscription')
161 191
     {
162 192
         $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=membersubscription&ref='.($mode?'<font color="#666666">':'');
163
-        if ($mode == 1) $out.='member_ref';
164
-        if ($mode == 0) $out.=urlencode($ref);
193
+        if ($mode == 1) {
194
+            $out.='member_ref';
195
+        }
196
+        if ($mode == 0) {
197
+            $out.=urlencode($ref);
198
+        }
165 199
 	    $out.=($mode?'</font>':'');
166 200
         if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
167 201
         {
168
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
169
-            else
202
+    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
203
+    	        $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
204
+    	    } else
170 205
             {
171 206
                 $out.='&securekey='.($mode?'<font color="#666666">':'');
172
-                if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + member_ref)";
173
-                if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
207
+                if ($mode == 1) {
208
+                    $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + member_ref)";
209
+                }
210
+                if ($mode == 0) {
211
+                    $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
212
+                }
174 213
                 $out.=($mode?'</font>':'');
175 214
             }
176 215
         }
@@ -209,7 +248,9 @@  discard block
 block discarded – undo
209 248
     //'
210 249
     //'-------------------------------------------------
211 250
 
212
-    if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY='integral';
251
+    if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) {
252
+        $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY='integral';
253
+    }
213 254
 
214 255
     $solutionType='Sole';
215 256
     $landingPage='Billing';
@@ -263,8 +304,7 @@  discard block
 block discarded – undo
263 304
         $payPalURL = $API_Url . $token;
264 305
         header("Location: ".$payPalURL);
265 306
         exit;
266
-    }
267
-    else
307
+    } else
268 308
     {
269 309
         //Display a user friendly Error on the page using any of the following error information returned by PayPal
270 310
         $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
@@ -275,8 +315,7 @@  discard block
 block discarded – undo
275 315
         if ($ErrorCode == 10729)
276 316
         {
277 317
         	$mesg.= "PayPal can't accept payments for this thirdparty. An address is defined but is not complete (missing State).<br>Ask system administrator to fix address or to setup Paypal module to accept payments even on not complete addresses (remove option PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS).<br>\n";
278
-        }
279
-        else
318
+        } else
280 319
         {
281 320
         	$mesg = $langs->trans('SetExpressCheckoutAPICallFailed') . "<br>\n";
282 321
         	$mesg.= $langs->trans('DetailedErrorMessage') . ": " . $ErrorLongMsg."<br>\n";
@@ -351,8 +390,7 @@  discard block
 block discarded – undo
351 390
     if (empty($conf->global->PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS))
352 391
     {
353 392
     	$nvpstr = $nvpstr . "&NOSHIPPING=1";	// An empty or not complete shipping address will be accepted
354
-    }
355
-    else
393
+    } else
356 394
     {
357 395
     	$nvpstr = $nvpstr . "&NOSHIPPING=0";	// A valid shipping address is required (full required fields mandatory)
358 396
     }
@@ -365,7 +403,9 @@  discard block
 block discarded – undo
365 403
 
366 404
     $paypalprefix = 'PAYMENTREQUEST_0_';
367 405
     //$paypalprefix = '';
368
-	if (! empty($paypalprefix) && $paymentType == 'Sole') $paymentType='Sale';
406
+	if (! empty($paypalprefix) && $paymentType == 'Sole') {
407
+	    $paymentType='Sale';
408
+	}
369 409
 
370 410
 	$nvpstr = $nvpstr . "&AMT=". urlencode($paymentAmount);									// Total for all elements
371 411
 
@@ -388,8 +428,14 @@  discard block
 block discarded – undo
388 428
     $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOCOUNTRYCODE=" . urlencode($shipToCountryCode);
389 429
     $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOZIP=" . urlencode($shipToZip);
390 430
     $nvpstr = $nvpstr . "&".$paypalprefix."PHONENUM=" . urlencode($phoneNum);
391
-    if (! empty($email)) $nvpstr = $nvpstr . "&".$paypalprefix."EMAIL=" . urlencode($email);      // EMAIL deprecated by paypal -> PAYMENTREQUEST_n_EMAIL
392
-    if (! empty($desc))  $nvpstr = $nvpstr . "&".$paypalprefix."DESC=" . urlencode($desc);        // DESC deprecated by paypal -> PAYMENTREQUEST_n_DESC
431
+    if (! empty($email)) {
432
+        $nvpstr = $nvpstr . "&".$paypalprefix."EMAIL=" . urlencode($email);
433
+    }
434
+    // EMAIL deprecated by paypal -> PAYMENTREQUEST_n_EMAIL
435
+    if (! empty($desc)) {
436
+        $nvpstr = $nvpstr . "&".$paypalprefix."DESC=" . urlencode($desc);
437
+    }
438
+    // DESC deprecated by paypal -> PAYMENTREQUEST_n_DESC
393 439
 
394 440
     if (! empty($conf->global->PAYPAL_LOGOIMG) && $mysoc->logo)
395 441
     {
@@ -592,12 +638,13 @@  discard block
 block discarded – undo
592 638
 
593 639
     // TODO problem with triggers
594 640
     $API_version="98.0";
595
-	if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))		// We can force sand box with param 'forcesandbox'
641
+	if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha')) {
642
+	    // We can force sand box with param 'forcesandbox'
596 643
 	{
597 644
 	    $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
598
-	    $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
599 645
 	}
600
-	else
646
+	    $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
647
+	} else
601 648
 	{
602 649
 	    $API_Endpoint = "https://api-3t.paypal.com/nvp";
603 650
 	    $API_Url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
@@ -605,13 +652,21 @@  discard block
 block discarded – undo
605 652
 
606 653
 	// Clean parameters
607 654
 	$PAYPAL_API_USER="";
608
-	if (! empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
655
+	if (! empty($conf->global->PAYPAL_API_USER)) {
656
+	    $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
657
+	}
609 658
 	$PAYPAL_API_PASSWORD="";
610
-	if (! empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
659
+	if (! empty($conf->global->PAYPAL_API_PASSWORD)) {
660
+	    $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
661
+	}
611 662
 	$PAYPAL_API_SIGNATURE="";
612
-	if (! empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
663
+	if (! empty($conf->global->PAYPAL_API_SIGNATURE)) {
664
+	    $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
665
+	}
613 666
 	$PAYPAL_API_SANDBOX="";
614
-	if (! empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
667
+	if (! empty($conf->global->PAYPAL_API_SANDBOX)) {
668
+	    $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
669
+	}
615 670
 	// TODO END problem with triggers
616 671
 
617 672
     dol_syslog("Paypal API endpoint ".$API_Endpoint);
@@ -644,7 +699,9 @@  discard block
 block discarded – undo
644 699
         dol_syslog("Paypal API hash_call set proxy to ".$PROXY_HOST. ":" . $PROXY_PORT." - ".$PROXY_USER. ":" . $PROXY_PASS);
645 700
         //curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); // Curl 7.10
646 701
         curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST. ":" . $PROXY_PORT);
647
-        if ($PROXY_USER) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER. ":" . $PROXY_PASS);
702
+        if ($PROXY_USER) {
703
+            curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER. ":" . $PROXY_PASS);
704
+        }
648 705
     }
649 706
 
650 707
     //NVPRequest for submitting to server
@@ -676,8 +733,7 @@  discard block
 block discarded – undo
676 733
         $_SESSION['curl_error_msg']=curl_error($ch);
677 734
 
678 735
         //Execute the Error handling module to display errors.
679
-    }
680
-    else
736
+    } else
681 737
     {
682 738
         //closing the curl
683 739
         curl_close($ch);
Please login to merge, or discard this patch.
dolibarr/htdocs/paypal/admin/paypal.php 3 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 
42 42
 if ($action == 'setvalue' && $user->admin)
43 43
 {
44
-	$db->begin();
44
+    $db->begin();
45 45
 
46 46
     $result=dolibarr_set_const($db, "PAYPAL_API_USER",GETPOST('PAYPAL_API_USER','alpha'),'chaine',0,'',$conf->entity);
47 47
     if (! $result > 0) $error++;
@@ -66,24 +66,24 @@  discard block
 block discarded – undo
66 66
     $result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK",GETPOST('ONLINE_PAYMENT_MESSAGE_OK'),'chaine',0,'',$conf->entity);
67 67
     if (! $result > 0) $error++;
68 68
     $result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO",GETPOST('ONLINE_PAYMENT_MESSAGE_KO'),'chaine',0,'',$conf->entity);
69
-	if (! $result > 0) $error++;
70
-	$result=dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL",GETPOST('ONLINE_PAYMENT_SENDEMAIL'),'chaine',0,'',$conf->entity);
71
-	if (! $result > 0) $error++;
72
-	// Payment token for URL
73
-	$result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN",GETPOST('PAYMENT_SECURITY_TOKEN','alpha'),'chaine',0,'',$conf->entity);
74
-	if (! $result > 0) $error++;
75
-	$result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE",GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE','alpha'),'chaine',0,'',$conf->entity);
76
-	if (! $result > 0) $error++;
77
-
78
-	if (! $error)
79
-  	{
80
-  		$db->commit();
81
-  		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
82
-  	}
83
-  	else
84
-  	{
85
-  		$db->rollback();
86
-		dol_print_error($db);
69
+    if (! $result > 0) $error++;
70
+    $result=dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL",GETPOST('ONLINE_PAYMENT_SENDEMAIL'),'chaine',0,'',$conf->entity);
71
+    if (! $result > 0) $error++;
72
+    // Payment token for URL
73
+    $result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN",GETPOST('PAYMENT_SECURITY_TOKEN','alpha'),'chaine',0,'',$conf->entity);
74
+    if (! $result > 0) $error++;
75
+    $result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE",GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE','alpha'),'chaine',0,'',$conf->entity);
76
+    if (! $result > 0) $error++;
77
+
78
+    if (! $error)
79
+        {
80
+            $db->commit();
81
+            setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
82
+        }
83
+        else
84
+        {
85
+            $db->rollback();
86
+        dol_print_error($db);
87 87
     }
88 88
 }
89 89
 
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
 // Test if php curl exist
130 130
 if (! function_exists('curl_version'))
131 131
 {
132
-	$langs->load("errors");
133
-	setEventMessages($langs->trans("ErrorPhpCurlNotInstalled"), null, 'errors');
132
+    $langs->load("errors");
133
+    setEventMessages($langs->trans("ErrorPhpCurlNotInstalled"), null, 'errors');
134 134
 }
135 135
 
136 136
 
@@ -212,10 +212,10 @@  discard block
 block discarded – undo
212 212
 
213 213
 if (! empty($conf->banque->enabled))
214 214
 {
215
-	print '<tr class="oddeven"><td>';
216
-	print $langs->trans("BankAccount").'</td><td>';
217
-	print $form->select_comptes($conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS, 'PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
218
-	print '</td></tr>';
215
+    print '<tr class="oddeven"><td>';
216
+    print $langs->trans("BankAccount").'</td><td>';
217
+    print $form->select_comptes($conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS, 'PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
218
+    print '</td></tr>';
219 219
 }
220 220
 
221 221
 print '<tr class="oddeven"><td>';
@@ -268,13 +268,13 @@  discard block
 block discarded – undo
268 268
 print $langs->trans("SecurityToken").'</td><td>';
269 269
 print '<input size="48" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.$conf->global->PAYMENT_SECURITY_TOKEN.'">';
270 270
 if (! empty($conf->use_javascript_ajax))
271
-	print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
272
-	print '</td></tr>';
271
+    print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
272
+    print '</td></tr>';
273 273
 
274
-	print '<tr class="oddeven"><td>';
275
-	print $langs->trans("SecurityTokenIsUnique").'</td><td>';
276
-	print $form->selectyesno("PAYMENT_SECURITY_TOKEN_UNIQUE",(empty($conf->global->PAYMENT_SECURITY_TOKEN)?0:$conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE),1);
277
-	print '</td></tr>';
274
+    print '<tr class="oddeven"><td>';
275
+    print $langs->trans("SecurityTokenIsUnique").'</td><td>';
276
+    print $form->selectyesno("PAYMENT_SECURITY_TOKEN_UNIQUE",(empty($conf->global->PAYMENT_SECURITY_TOKEN)?0:$conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE),1);
277
+    print '</td></tr>';
278 278
 
279 279
 print '</table>';
280 280
 
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 // Help doc
290 290
 print '<u>'.$langs->trans("InformationToFindParameters","Paypal").'</u>:<br>';
291 291
 if (! empty($conf->use_javascript_ajax))
292
-	print '<a href="#" class="reposition" id="apidoca">'.$langs->trans("ClickHere").'...</a>';
292
+    print '<a href="#" class="reposition" id="apidoca">'.$langs->trans("ClickHere").'...</a>';
293 293
 
294 294
 $realpaypalurl='www.paypal.com';
295 295
 $sandboxpaypalurl='developer.paypal.com';
@@ -309,15 +309,15 @@  discard block
 block discarded – undo
309 309
 
310 310
 if (! empty($conf->use_javascript_ajax))
311 311
 {
312
-	print "\n".'<script type="text/javascript">';
313
-	print '$(document).ready(function () {
312
+    print "\n".'<script type="text/javascript">';
313
+    print '$(document).ready(function () {
314 314
             $("#apidoc").hide();
315 315
             $("#apidoca").click(function() {
316 316
                 $("#apidoc").show();
317 317
             	$("#apidoca").hide();
318 318
             })
319 319
 			});';
320
-	print '</script>';
320
+    print '</script>';
321 321
 }
322 322
 
323 323
 print '<br><br>';
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -30,52 +30,52 @@  discard block
 block discarded – undo
30 30
 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
31 31
 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
32 32
 
33
-$servicename='PayPal';
33
+$servicename = 'PayPal';
34 34
 
35 35
 // Load translation files required by the page
36 36
 $langs->loadLangs(array('admin', 'other', 'paypal', 'paybox'));
37 37
 
38
-if (! $user->admin) accessforbidden();
38
+if (!$user->admin) accessforbidden();
39 39
 
40
-$action = GETPOST('action','alpha');
40
+$action = GETPOST('action', 'alpha');
41 41
 
42 42
 if ($action == 'setvalue' && $user->admin)
43 43
 {
44 44
 	$db->begin();
45 45
 
46
-    $result=dolibarr_set_const($db, "PAYPAL_API_USER",GETPOST('PAYPAL_API_USER','alpha'),'chaine',0,'',$conf->entity);
47
-    if (! $result > 0) $error++;
48
-    $result=dolibarr_set_const($db, "PAYPAL_API_PASSWORD",GETPOST('PAYPAL_API_PASSWORD','alpha'),'chaine',0,'',$conf->entity);
49
-    if (! $result > 0) $error++;
50
-    $result=dolibarr_set_const($db, "PAYPAL_API_SIGNATURE",GETPOST('PAYPAL_API_SIGNATURE','alpha'),'chaine',0,'',$conf->entity);
51
-    if (! $result > 0) $error++;
52
-    $result=dolibarr_set_const($db, "PAYPAL_SSLVERSION",GETPOST('PAYPAL_SSLVERSION','alpha'),'chaine',0,'',$conf->entity);
53
-    if (! $result > 0) $error++;
54
-    $result=dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR",GETPOST('ONLINE_PAYMENT_CREDITOR','alpha'),'chaine',0,'',$conf->entity);
55
-    if (! $result > 0) $error++;
56
-    $result=dolibarr_set_const($db, "PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS",GETPOST('PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS','int'),'chaine',0,'',$conf->entity);
57
-    if (! $result > 0) $error++;
58
-    $result=dolibarr_set_const($db, "PAYPAL_API_INTEGRAL_OR_PAYPALONLY",GETPOST('PAYPAL_API_INTEGRAL_OR_PAYPALONLY','alpha'),'chaine',0,'',$conf->entity);
59
-    if (! $result > 0) $error++;
60
-    $result=dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL",GETPOST('ONLINE_PAYMENT_CSS_URL','alpha'),'chaine',0,'',$conf->entity);
61
-    if (! $result > 0) $error++;
62
-    $result=dolibarr_set_const($db, "PAYPAL_ADD_PAYMENT_URL",GETPOST('PAYPAL_ADD_PAYMENT_URL','alpha'),'chaine',0,'',$conf->entity);
63
-    if (! $result > 0) $error++;
64
-    $result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM",GETPOST('ONLINE_PAYMENT_MESSAGE_FORM'),'chaine',0,'',$conf->entity);
65
-    if (! $result > 0) $error++;
66
-    $result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK",GETPOST('ONLINE_PAYMENT_MESSAGE_OK'),'chaine',0,'',$conf->entity);
67
-    if (! $result > 0) $error++;
68
-    $result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO",GETPOST('ONLINE_PAYMENT_MESSAGE_KO'),'chaine',0,'',$conf->entity);
69
-	if (! $result > 0) $error++;
70
-	$result=dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL",GETPOST('ONLINE_PAYMENT_SENDEMAIL'),'chaine',0,'',$conf->entity);
71
-	if (! $result > 0) $error++;
46
+    $result = dolibarr_set_const($db, "PAYPAL_API_USER", GETPOST('PAYPAL_API_USER', 'alpha'), 'chaine', 0, '', $conf->entity);
47
+    if (!$result > 0) $error++;
48
+    $result = dolibarr_set_const($db, "PAYPAL_API_PASSWORD", GETPOST('PAYPAL_API_PASSWORD', 'alpha'), 'chaine', 0, '', $conf->entity);
49
+    if (!$result > 0) $error++;
50
+    $result = dolibarr_set_const($db, "PAYPAL_API_SIGNATURE", GETPOST('PAYPAL_API_SIGNATURE', 'alpha'), 'chaine', 0, '', $conf->entity);
51
+    if (!$result > 0) $error++;
52
+    $result = dolibarr_set_const($db, "PAYPAL_SSLVERSION", GETPOST('PAYPAL_SSLVERSION', 'alpha'), 'chaine', 0, '', $conf->entity);
53
+    if (!$result > 0) $error++;
54
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR", GETPOST('ONLINE_PAYMENT_CREDITOR', 'alpha'), 'chaine', 0, '', $conf->entity);
55
+    if (!$result > 0) $error++;
56
+    $result = dolibarr_set_const($db, "PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS", GETPOST('PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS', 'int'), 'chaine', 0, '', $conf->entity);
57
+    if (!$result > 0) $error++;
58
+    $result = dolibarr_set_const($db, "PAYPAL_API_INTEGRAL_OR_PAYPALONLY", GETPOST('PAYPAL_API_INTEGRAL_OR_PAYPALONLY', 'alpha'), 'chaine', 0, '', $conf->entity);
59
+    if (!$result > 0) $error++;
60
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
61
+    if (!$result > 0) $error++;
62
+    $result = dolibarr_set_const($db, "PAYPAL_ADD_PAYMENT_URL", GETPOST('PAYPAL_ADD_PAYMENT_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
63
+    if (!$result > 0) $error++;
64
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM", GETPOST('ONLINE_PAYMENT_MESSAGE_FORM'), 'chaine', 0, '', $conf->entity);
65
+    if (!$result > 0) $error++;
66
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK", GETPOST('ONLINE_PAYMENT_MESSAGE_OK'), 'chaine', 0, '', $conf->entity);
67
+    if (!$result > 0) $error++;
68
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO", GETPOST('ONLINE_PAYMENT_MESSAGE_KO'), 'chaine', 0, '', $conf->entity);
69
+	if (!$result > 0) $error++;
70
+	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL", GETPOST('ONLINE_PAYMENT_SENDEMAIL'), 'chaine', 0, '', $conf->entity);
71
+	if (!$result > 0) $error++;
72 72
 	// Payment token for URL
73
-	$result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN",GETPOST('PAYMENT_SECURITY_TOKEN','alpha'),'chaine',0,'',$conf->entity);
74
-	if (! $result > 0) $error++;
75
-	$result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE",GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE','alpha'),'chaine',0,'',$conf->entity);
76
-	if (! $result > 0) $error++;
73
+	$result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN", GETPOST('PAYMENT_SECURITY_TOKEN', 'alpha'), 'chaine', 0, '', $conf->entity);
74
+	if (!$result > 0) $error++;
75
+	$result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE", GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE', 'alpha'), 'chaine', 0, '', $conf->entity);
76
+	if (!$result > 0) $error++;
77 77
 
78
-	if (! $error)
78
+	if (!$error)
79 79
   	{
80 80
   		$db->commit();
81 81
   		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
@@ -87,12 +87,12 @@  discard block
 block discarded – undo
87 87
     }
88 88
 }
89 89
 
90
-if ($action=="setlive")
90
+if ($action == "setlive")
91 91
 {
92
-    $liveenable = GETPOST('value','int')?0:1;
93
-    $res = dolibarr_set_const($db, "PAYPAL_API_SANDBOX", $liveenable,'yesno',0,'',$conf->entity);
94
-    if (! $res > 0) $error++;
95
-    if (! $error)
92
+    $liveenable = GETPOST('value', 'int') ? 0 : 1;
93
+    $res = dolibarr_set_const($db, "PAYPAL_API_SANDBOX", $liveenable, 'yesno', 0, '', $conf->entity);
94
+    if (!$res > 0) $error++;
95
+    if (!$error)
96 96
     {
97 97
         setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
98 98
     }
@@ -107,15 +107,15 @@  discard block
 block discarded – undo
107 107
  *	View
108 108
  */
109 109
 
110
-$form=new Form($db);
110
+$form = new Form($db);
111 111
 
112
-llxHeader('',$langs->trans("PaypalSetup"));
112
+llxHeader('', $langs->trans("PaypalSetup"));
113 113
 
114 114
 
115
-$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
116
-print load_fiche_titre($langs->trans("ModuleSetup").' PayPal',$linkback);
115
+$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
116
+print load_fiche_titre($langs->trans("ModuleSetup").' PayPal', $linkback);
117 117
 
118
-$head=paypaladmin_prepare_head();
118
+$head = paypaladmin_prepare_head();
119 119
 
120 120
 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
121 121
 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 print $langs->trans("PaypalDesc")."<br>\n";
128 128
 
129 129
 // Test if php curl exist
130
-if (! function_exists('curl_version'))
130
+if (!function_exists('curl_version'))
131 131
 {
132 132
 	$langs->load("errors");
133 133
 	setEventMessages($langs->trans("ErrorPhpCurlNotInstalled"), null, 'errors');
@@ -150,12 +150,12 @@  discard block
 block discarded – undo
150 150
 if (empty($conf->global->PAYPAL_API_SANDBOX))
151 151
 {
152 152
     print '<a href="'.$_SERVER['PHP_SELF'].'?action=setlive&value=0">';
153
-    print img_picto($langs->trans("Activated"),'switch_on');
153
+    print img_picto($langs->trans("Activated"), 'switch_on');
154 154
 }
155 155
 else
156 156
 {
157 157
     print '<a href="'.$_SERVER['PHP_SELF'].'?action=setlive&value=1">';
158
-    print img_picto($langs->trans("Disabled"),'switch_off');
158
+    print img_picto($langs->trans("Disabled"), 'switch_off');
159 159
 }
160 160
 print '</td></tr>';
161 161
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 
182 182
 print '<tr class="oddeven"><td>';
183 183
 print $langs->trans("PAYPAL_SSLVERSION").'</td><td>';
184
-print $form->selectarray("PAYPAL_SSLVERSION",array('1'=> $langs->trans('TLSv1'),'6'=> $langs->trans('TLSv1.2')),$conf->global->PAYPAL_SSLVERSION);
184
+print $form->selectarray("PAYPAL_SSLVERSION", array('1'=> $langs->trans('TLSv1'), '6'=> $langs->trans('TLSv1.2')), $conf->global->PAYPAL_SSLVERSION);
185 185
 print '</td></tr>';
186 186
 
187 187
 // Usage Parameters
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 
194 194
 print '<tr class="oddeven"><td>';
195 195
 print $langs->trans("PAYPAL_API_INTEGRAL_OR_PAYPALONLY").'</td><td>';
196
-print $form->selectarray("PAYPAL_API_INTEGRAL_OR_PAYPALONLY",array('integral'=> $langs->trans('PaypalModeIntegral'),'paypalonly'=> $langs->trans('PaypalModeOnlyPaypal')),$conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY);
196
+print $form->selectarray("PAYPAL_API_INTEGRAL_OR_PAYPALONLY", array('integral'=> $langs->trans('PaypalModeIntegral'), 'paypalonly'=> $langs->trans('PaypalModeOnlyPaypal')), $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY);
197 197
 print '</td></tr>';
198 198
 
199 199
 /*
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 print ' &nbsp; '.$langs->trans("Example").': '.$mysoc->name;
211 211
 print '</td></tr>';
212 212
 
213
-if (! empty($conf->banque->enabled))
213
+if (!empty($conf->banque->enabled))
214 214
 {
215 215
 	print '<tr class="oddeven"><td>';
216 216
 	print $langs->trans("BankAccount").'</td><td>';
@@ -227,27 +227,27 @@  discard block
 block discarded – undo
227 227
 
228 228
 print '<tr class="oddeven"><td>';
229 229
 print $langs->trans("PAYPAL_ADD_PAYMENT_URL").'</td><td>';
230
-print $form->selectyesno("PAYPAL_ADD_PAYMENT_URL",$conf->global->PAYPAL_ADD_PAYMENT_URL,1);
230
+print $form->selectyesno("PAYPAL_ADD_PAYMENT_URL", $conf->global->PAYPAL_ADD_PAYMENT_URL, 1);
231 231
 print '</td></tr>';
232 232
 
233 233
 
234 234
 print '<tr class="oddeven"><td>';
235 235
 print $langs->trans("MessageForm").'</td><td>';
236
-$doleditor=new DolEditor('ONLINE_PAYMENT_MESSAGE_FORM',$conf->global->ONLINE_PAYMENT_MESSAGE_FORM,'',100,'dolibarr_details','In',false,true,true,ROWS_4,'90%');
236
+$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_FORM', $conf->global->ONLINE_PAYMENT_MESSAGE_FORM, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
237 237
 $doleditor->Create();
238 238
 print '</td></tr>';
239 239
 
240 240
 
241 241
 print '<tr class="oddeven"><td>';
242 242
 print $langs->trans("MessageOK").'</td><td>';
243
-$doleditor=new DolEditor('ONLINE_PAYMENT_MESSAGE_OK',$conf->global->ONLINE_PAYMENT_MESSAGE_OK,'',100,'dolibarr_details','In',false,true,true,ROWS_4,'90%');
243
+$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_OK', $conf->global->ONLINE_PAYMENT_MESSAGE_OK, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
244 244
 $doleditor->Create();
245 245
 print '</td></tr>';
246 246
 
247 247
 
248 248
 print '<tr class="oddeven"><td>';
249 249
 print $langs->trans("MessageKO").'</td><td>';
250
-$doleditor=new DolEditor('ONLINE_PAYMENT_MESSAGE_KO',$conf->global->ONLINE_PAYMENT_MESSAGE_KO,'',100,'dolibarr_details','In',false,true,true,ROWS_4,'90%');
250
+$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_KO', $conf->global->ONLINE_PAYMENT_MESSAGE_KO, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
251 251
 $doleditor->Create();
252 252
 print '</td></tr>';
253 253
 
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
 print '<tr class="oddeven"><td>';
268 268
 print $langs->trans("SecurityToken").'</td><td>';
269 269
 print '<input size="48" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.$conf->global->PAYMENT_SECURITY_TOKEN.'">';
270
-if (! empty($conf->use_javascript_ajax))
270
+if (!empty($conf->use_javascript_ajax))
271 271
 	print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
272 272
 	print '</td></tr>';
273 273
 
274 274
 	print '<tr class="oddeven"><td>';
275 275
 	print $langs->trans("SecurityTokenIsUnique").'</td><td>';
276
-	print $form->selectyesno("PAYMENT_SECURITY_TOKEN_UNIQUE",(empty($conf->global->PAYMENT_SECURITY_TOKEN)?0:$conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE),1);
276
+	print $form->selectyesno("PAYMENT_SECURITY_TOKEN_UNIQUE", (empty($conf->global->PAYMENT_SECURITY_TOKEN) ? 0 : $conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE), 1);
277 277
 	print '</td></tr>';
278 278
 
279 279
 print '</table>';
@@ -287,12 +287,12 @@  discard block
 block discarded – undo
287 287
 print '<br><br>';
288 288
 
289 289
 // Help doc
290
-print '<u>'.$langs->trans("InformationToFindParameters","Paypal").'</u>:<br>';
291
-if (! empty($conf->use_javascript_ajax))
290
+print '<u>'.$langs->trans("InformationToFindParameters", "Paypal").'</u>:<br>';
291
+if (!empty($conf->use_javascript_ajax))
292 292
 	print '<a href="#" class="reposition" id="apidoca">'.$langs->trans("ClickHere").'...</a>';
293 293
 
294
-$realpaypalurl='www.paypal.com';
295
-$sandboxpaypalurl='developer.paypal.com';
294
+$realpaypalurl = 'www.paypal.com';
295
+$sandboxpaypalurl = 'developer.paypal.com';
296 296
 
297 297
 print '<div id="apidoc">';
298 298
 print 'Your API authentication information can be found with following steps. We recommend that you open a separate Web browser session when carrying out this procedure.<br>
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 ';
308 308
 print '</div>';
309 309
 
310
-if (! empty($conf->use_javascript_ajax))
310
+if (!empty($conf->use_javascript_ajax))
311 311
 {
312 312
 	print "\n".'<script type="text/javascript">';
313 313
 	print '$(document).ready(function () {
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 
323 323
 print '<br><br>';
324 324
 
325
-$token='';
325
+$token = '';
326 326
 
327 327
 include DOL_DOCUMENT_ROOT.'/core/tpl/onlinepaymentlinks.tpl.php';
328 328
 
Please login to merge, or discard this patch.
Braces   +58 added lines, -25 removed lines patch added patch discarded remove patch
@@ -35,7 +35,9 @@  discard block
 block discarded – undo
35 35
 // Load translation files required by the page
36 36
 $langs->loadLangs(array('admin', 'other', 'paypal', 'paybox'));
37 37
 
38
-if (! $user->admin) accessforbidden();
38
+if (! $user->admin) {
39
+    accessforbidden();
40
+}
39 41
 
40 42
 $action = GETPOST('action','alpha');
41 43
 
@@ -44,43 +46,72 @@  discard block
 block discarded – undo
44 46
 	$db->begin();
45 47
 
46 48
     $result=dolibarr_set_const($db, "PAYPAL_API_USER",GETPOST('PAYPAL_API_USER','alpha'),'chaine',0,'',$conf->entity);
47
-    if (! $result > 0) $error++;
49
+    if (! $result > 0) {
50
+        $error++;
51
+    }
48 52
     $result=dolibarr_set_const($db, "PAYPAL_API_PASSWORD",GETPOST('PAYPAL_API_PASSWORD','alpha'),'chaine',0,'',$conf->entity);
49
-    if (! $result > 0) $error++;
53
+    if (! $result > 0) {
54
+        $error++;
55
+    }
50 56
     $result=dolibarr_set_const($db, "PAYPAL_API_SIGNATURE",GETPOST('PAYPAL_API_SIGNATURE','alpha'),'chaine',0,'',$conf->entity);
51
-    if (! $result > 0) $error++;
57
+    if (! $result > 0) {
58
+        $error++;
59
+    }
52 60
     $result=dolibarr_set_const($db, "PAYPAL_SSLVERSION",GETPOST('PAYPAL_SSLVERSION','alpha'),'chaine',0,'',$conf->entity);
53
-    if (! $result > 0) $error++;
61
+    if (! $result > 0) {
62
+        $error++;
63
+    }
54 64
     $result=dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR",GETPOST('ONLINE_PAYMENT_CREDITOR','alpha'),'chaine',0,'',$conf->entity);
55
-    if (! $result > 0) $error++;
65
+    if (! $result > 0) {
66
+        $error++;
67
+    }
56 68
     $result=dolibarr_set_const($db, "PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS",GETPOST('PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS','int'),'chaine',0,'',$conf->entity);
57
-    if (! $result > 0) $error++;
69
+    if (! $result > 0) {
70
+        $error++;
71
+    }
58 72
     $result=dolibarr_set_const($db, "PAYPAL_API_INTEGRAL_OR_PAYPALONLY",GETPOST('PAYPAL_API_INTEGRAL_OR_PAYPALONLY','alpha'),'chaine',0,'',$conf->entity);
59
-    if (! $result > 0) $error++;
73
+    if (! $result > 0) {
74
+        $error++;
75
+    }
60 76
     $result=dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL",GETPOST('ONLINE_PAYMENT_CSS_URL','alpha'),'chaine',0,'',$conf->entity);
61
-    if (! $result > 0) $error++;
77
+    if (! $result > 0) {
78
+        $error++;
79
+    }
62 80
     $result=dolibarr_set_const($db, "PAYPAL_ADD_PAYMENT_URL",GETPOST('PAYPAL_ADD_PAYMENT_URL','alpha'),'chaine',0,'',$conf->entity);
63
-    if (! $result > 0) $error++;
81
+    if (! $result > 0) {
82
+        $error++;
83
+    }
64 84
     $result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM",GETPOST('ONLINE_PAYMENT_MESSAGE_FORM'),'chaine',0,'',$conf->entity);
65
-    if (! $result > 0) $error++;
85
+    if (! $result > 0) {
86
+        $error++;
87
+    }
66 88
     $result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK",GETPOST('ONLINE_PAYMENT_MESSAGE_OK'),'chaine',0,'',$conf->entity);
67
-    if (! $result > 0) $error++;
89
+    if (! $result > 0) {
90
+        $error++;
91
+    }
68 92
     $result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO",GETPOST('ONLINE_PAYMENT_MESSAGE_KO'),'chaine',0,'',$conf->entity);
69
-	if (! $result > 0) $error++;
93
+	if (! $result > 0) {
94
+	    $error++;
95
+	}
70 96
 	$result=dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL",GETPOST('ONLINE_PAYMENT_SENDEMAIL'),'chaine',0,'',$conf->entity);
71
-	if (! $result > 0) $error++;
97
+	if (! $result > 0) {
98
+	    $error++;
99
+	}
72 100
 	// Payment token for URL
73 101
 	$result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN",GETPOST('PAYMENT_SECURITY_TOKEN','alpha'),'chaine',0,'',$conf->entity);
74
-	if (! $result > 0) $error++;
102
+	if (! $result > 0) {
103
+	    $error++;
104
+	}
75 105
 	$result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE",GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE','alpha'),'chaine',0,'',$conf->entity);
76
-	if (! $result > 0) $error++;
106
+	if (! $result > 0) {
107
+	    $error++;
108
+	}
77 109
 
78 110
 	if (! $error)
79 111
   	{
80 112
   		$db->commit();
81 113
   		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
82
-  	}
83
-  	else
114
+  	} else
84 115
   	{
85 116
   		$db->rollback();
86 117
 		dol_print_error($db);
@@ -91,12 +122,13 @@  discard block
 block discarded – undo
91 122
 {
92 123
     $liveenable = GETPOST('value','int')?0:1;
93 124
     $res = dolibarr_set_const($db, "PAYPAL_API_SANDBOX", $liveenable,'yesno',0,'',$conf->entity);
94
-    if (! $res > 0) $error++;
125
+    if (! $res > 0) {
126
+        $error++;
127
+    }
95 128
     if (! $error)
96 129
     {
97 130
         setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
98
-    }
99
-    else
131
+    } else
100 132
     {
101 133
         setEventMessages($langs->trans("Error"), null, 'errors');
102 134
     }
@@ -151,8 +183,7 @@  discard block
 block discarded – undo
151 183
 {
152 184
     print '<a href="'.$_SERVER['PHP_SELF'].'?action=setlive&value=0">';
153 185
     print img_picto($langs->trans("Activated"),'switch_on');
154
-}
155
-else
186
+} else
156 187
 {
157 188
     print '<a href="'.$_SERVER['PHP_SELF'].'?action=setlive&value=1">';
158 189
     print img_picto($langs->trans("Disabled"),'switch_off');
@@ -267,8 +298,9 @@  discard block
 block discarded – undo
267 298
 print '<tr class="oddeven"><td>';
268 299
 print $langs->trans("SecurityToken").'</td><td>';
269 300
 print '<input size="48" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.$conf->global->PAYMENT_SECURITY_TOKEN.'">';
270
-if (! empty($conf->use_javascript_ajax))
301
+if (! empty($conf->use_javascript_ajax)) {
271 302
 	print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
303
+}
272 304
 	print '</td></tr>';
273 305
 
274 306
 	print '<tr class="oddeven"><td>';
@@ -288,8 +320,9 @@  discard block
 block discarded – undo
288 320
 
289 321
 // Help doc
290 322
 print '<u>'.$langs->trans("InformationToFindParameters","Paypal").'</u>:<br>';
291
-if (! empty($conf->use_javascript_ajax))
323
+if (! empty($conf->use_javascript_ajax)) {
292 324
 	print '<a href="#" class="reposition" id="apidoca">'.$langs->trans("ClickHere").'...</a>';
325
+}
293 326
 
294 327
 $realpaypalurl='www.paypal.com';
295 328
 $sandboxpaypalurl='developer.paypal.com';
Please login to merge, or discard this patch.