Passed
Push — master ( 49af33...3cffbe )
by Alxarafe
21:21
created
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.
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.
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -27,58 +27,58 @@  discard block
 block discarded – undo
27 27
 
28 28
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
29 29
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
30
-require DOL_BASE_PATH . '/main.inc.php';
30
+require DOL_BASE_PATH.'/main.inc.php';
31 31
 require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
32 32
 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
33 33
 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
34 34
 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
35 35
 
36
-$servicename='PayPal';
36
+$servicename = 'PayPal';
37 37
 
38 38
 // Load translation files required by the page
39 39
 $langs->loadLangs(array('admin', 'other', 'paypal', 'paybox'));
40 40
 
41
-if (! $user->admin) accessforbidden();
41
+if (!$user->admin) accessforbidden();
42 42
 
43
-$action = GETPOST('action','alpha');
43
+$action = GETPOST('action', 'alpha');
44 44
 
45 45
 if ($action == 'setvalue' && $user->admin)
46 46
 {
47 47
 	$db->begin();
48 48
 
49
-    $result=dolibarr_set_const($db, "PAYPAL_API_USER",GETPOST('PAYPAL_API_USER','alpha'),'chaine',0,'',$conf->entity);
50
-    if (! $result > 0) $error++;
51
-    $result=dolibarr_set_const($db, "PAYPAL_API_PASSWORD",GETPOST('PAYPAL_API_PASSWORD','alpha'),'chaine',0,'',$conf->entity);
52
-    if (! $result > 0) $error++;
53
-    $result=dolibarr_set_const($db, "PAYPAL_API_SIGNATURE",GETPOST('PAYPAL_API_SIGNATURE','alpha'),'chaine',0,'',$conf->entity);
54
-    if (! $result > 0) $error++;
55
-    $result=dolibarr_set_const($db, "PAYPAL_SSLVERSION",GETPOST('PAYPAL_SSLVERSION','alpha'),'chaine',0,'',$conf->entity);
56
-    if (! $result > 0) $error++;
57
-    $result=dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR",GETPOST('ONLINE_PAYMENT_CREDITOR','alpha'),'chaine',0,'',$conf->entity);
58
-    if (! $result > 0) $error++;
59
-    $result=dolibarr_set_const($db, "PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS",GETPOST('PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS','int'),'chaine',0,'',$conf->entity);
60
-    if (! $result > 0) $error++;
61
-    $result=dolibarr_set_const($db, "PAYPAL_API_INTEGRAL_OR_PAYPALONLY",GETPOST('PAYPAL_API_INTEGRAL_OR_PAYPALONLY','alpha'),'chaine',0,'',$conf->entity);
62
-    if (! $result > 0) $error++;
63
-    $result=dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL",GETPOST('ONLINE_PAYMENT_CSS_URL','alpha'),'chaine',0,'',$conf->entity);
64
-    if (! $result > 0) $error++;
65
-    $result=dolibarr_set_const($db, "PAYPAL_ADD_PAYMENT_URL",GETPOST('PAYPAL_ADD_PAYMENT_URL','alpha'),'chaine',0,'',$conf->entity);
66
-    if (! $result > 0) $error++;
67
-    $result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM",GETPOST('ONLINE_PAYMENT_MESSAGE_FORM'),'chaine',0,'',$conf->entity);
68
-    if (! $result > 0) $error++;
69
-    $result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK",GETPOST('ONLINE_PAYMENT_MESSAGE_OK'),'chaine',0,'',$conf->entity);
70
-    if (! $result > 0) $error++;
71
-    $result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO",GETPOST('ONLINE_PAYMENT_MESSAGE_KO'),'chaine',0,'',$conf->entity);
72
-	if (! $result > 0) $error++;
73
-	$result=dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL",GETPOST('ONLINE_PAYMENT_SENDEMAIL'),'chaine',0,'',$conf->entity);
74
-	if (! $result > 0) $error++;
49
+    $result = dolibarr_set_const($db, "PAYPAL_API_USER", GETPOST('PAYPAL_API_USER', 'alpha'), 'chaine', 0, '', $conf->entity);
50
+    if (!$result > 0) $error++;
51
+    $result = dolibarr_set_const($db, "PAYPAL_API_PASSWORD", GETPOST('PAYPAL_API_PASSWORD', 'alpha'), 'chaine', 0, '', $conf->entity);
52
+    if (!$result > 0) $error++;
53
+    $result = dolibarr_set_const($db, "PAYPAL_API_SIGNATURE", GETPOST('PAYPAL_API_SIGNATURE', 'alpha'), 'chaine', 0, '', $conf->entity);
54
+    if (!$result > 0) $error++;
55
+    $result = dolibarr_set_const($db, "PAYPAL_SSLVERSION", GETPOST('PAYPAL_SSLVERSION', 'alpha'), 'chaine', 0, '', $conf->entity);
56
+    if (!$result > 0) $error++;
57
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR", GETPOST('ONLINE_PAYMENT_CREDITOR', 'alpha'), 'chaine', 0, '', $conf->entity);
58
+    if (!$result > 0) $error++;
59
+    $result = dolibarr_set_const($db, "PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS", GETPOST('PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS', 'int'), 'chaine', 0, '', $conf->entity);
60
+    if (!$result > 0) $error++;
61
+    $result = dolibarr_set_const($db, "PAYPAL_API_INTEGRAL_OR_PAYPALONLY", GETPOST('PAYPAL_API_INTEGRAL_OR_PAYPALONLY', 'alpha'), 'chaine', 0, '', $conf->entity);
62
+    if (!$result > 0) $error++;
63
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
64
+    if (!$result > 0) $error++;
65
+    $result = dolibarr_set_const($db, "PAYPAL_ADD_PAYMENT_URL", GETPOST('PAYPAL_ADD_PAYMENT_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
66
+    if (!$result > 0) $error++;
67
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM", GETPOST('ONLINE_PAYMENT_MESSAGE_FORM'), 'chaine', 0, '', $conf->entity);
68
+    if (!$result > 0) $error++;
69
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK", GETPOST('ONLINE_PAYMENT_MESSAGE_OK'), 'chaine', 0, '', $conf->entity);
70
+    if (!$result > 0) $error++;
71
+    $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO", GETPOST('ONLINE_PAYMENT_MESSAGE_KO'), 'chaine', 0, '', $conf->entity);
72
+	if (!$result > 0) $error++;
73
+	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL", GETPOST('ONLINE_PAYMENT_SENDEMAIL'), 'chaine', 0, '', $conf->entity);
74
+	if (!$result > 0) $error++;
75 75
 	// Payment token for URL
76
-	$result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN",GETPOST('PAYMENT_SECURITY_TOKEN','alpha'),'chaine',0,'',$conf->entity);
77
-	if (! $result > 0) $error++;
78
-	$result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE",GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE','alpha'),'chaine',0,'',$conf->entity);
79
-	if (! $result > 0) $error++;
76
+	$result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN", GETPOST('PAYMENT_SECURITY_TOKEN', 'alpha'), 'chaine', 0, '', $conf->entity);
77
+	if (!$result > 0) $error++;
78
+	$result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE", GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE', 'alpha'), 'chaine', 0, '', $conf->entity);
79
+	if (!$result > 0) $error++;
80 80
 
81
-	if (! $error)
81
+	if (!$error)
82 82
   	{
83 83
   		$db->commit();
84 84
   		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
@@ -90,12 +90,12 @@  discard block
 block discarded – undo
90 90
     }
91 91
 }
92 92
 
93
-if ($action=="setlive")
93
+if ($action == "setlive")
94 94
 {
95
-    $liveenable = GETPOST('value','int')?0:1;
96
-    $res = dolibarr_set_const($db, "PAYPAL_API_SANDBOX", $liveenable,'yesno',0,'',$conf->entity);
97
-    if (! $res > 0) $error++;
98
-    if (! $error)
95
+    $liveenable = GETPOST('value', 'int') ? 0 : 1;
96
+    $res = dolibarr_set_const($db, "PAYPAL_API_SANDBOX", $liveenable, 'yesno', 0, '', $conf->entity);
97
+    if (!$res > 0) $error++;
98
+    if (!$error)
99 99
     {
100 100
         setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
101 101
     }
@@ -110,15 +110,15 @@  discard block
 block discarded – undo
110 110
  *	View
111 111
  */
112 112
 
113
-$form=new Form($db);
113
+$form = new Form($db);
114 114
 
115
-llxHeader('',$langs->trans("PaypalSetup"));
115
+llxHeader('', $langs->trans("PaypalSetup"));
116 116
 
117 117
 
118
-$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
119
-print load_fiche_titre($langs->trans("ModuleSetup").' PayPal',$linkback);
118
+$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
119
+print load_fiche_titre($langs->trans("ModuleSetup").' PayPal', $linkback);
120 120
 
121
-$head=paypaladmin_prepare_head();
121
+$head = paypaladmin_prepare_head();
122 122
 
123 123
 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
124 124
 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 print $langs->trans("PaypalDesc")."<br>\n";
131 131
 
132 132
 // Test if php curl exist
133
-if (! function_exists('curl_version'))
133
+if (!function_exists('curl_version'))
134 134
 {
135 135
 	$langs->load("errors");
136 136
 	setEventMessages($langs->trans("ErrorPhpCurlNotInstalled"), null, 'errors');
@@ -153,12 +153,12 @@  discard block
 block discarded – undo
153 153
 if (empty($conf->global->PAYPAL_API_SANDBOX))
154 154
 {
155 155
     print '<a href="'.$_SERVER['PHP_SELF'].'?action=setlive&value=0">';
156
-    print img_picto($langs->trans("Activated"),'switch_on');
156
+    print img_picto($langs->trans("Activated"), 'switch_on');
157 157
 }
158 158
 else
159 159
 {
160 160
     print '<a href="'.$_SERVER['PHP_SELF'].'?action=setlive&value=1">';
161
-    print img_picto($langs->trans("Disabled"),'switch_off');
161
+    print img_picto($langs->trans("Disabled"), 'switch_off');
162 162
 }
163 163
 print '</td></tr>';
164 164
 
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 
185 185
 print '<tr class="oddeven"><td>';
186 186
 print $langs->trans("PAYPAL_SSLVERSION").'</td><td>';
187
-print $form->selectarray("PAYPAL_SSLVERSION",array('1'=> $langs->trans('TLSv1'),'6'=> $langs->trans('TLSv1.2')),$conf->global->PAYPAL_SSLVERSION);
187
+print $form->selectarray("PAYPAL_SSLVERSION", array('1'=> $langs->trans('TLSv1'), '6'=> $langs->trans('TLSv1.2')), $conf->global->PAYPAL_SSLVERSION);
188 188
 print '</td></tr>';
189 189
 
190 190
 // Usage Parameters
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 
197 197
 print '<tr class="oddeven"><td>';
198 198
 print $langs->trans("PAYPAL_API_INTEGRAL_OR_PAYPALONLY").'</td><td>';
199
-print $form->selectarray("PAYPAL_API_INTEGRAL_OR_PAYPALONLY",array('integral'=> $langs->trans('PaypalModeIntegral'),'paypalonly'=> $langs->trans('PaypalModeOnlyPaypal')),$conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY);
199
+print $form->selectarray("PAYPAL_API_INTEGRAL_OR_PAYPALONLY", array('integral'=> $langs->trans('PaypalModeIntegral'), 'paypalonly'=> $langs->trans('PaypalModeOnlyPaypal')), $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY);
200 200
 print '</td></tr>';
201 201
 
202 202
 /*
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 print ' &nbsp; '.$langs->trans("Example").': '.$mysoc->name;
214 214
 print '</td></tr>';
215 215
 
216
-if (! empty($conf->banque->enabled))
216
+if (!empty($conf->banque->enabled))
217 217
 {
218 218
 	print '<tr class="oddeven"><td>';
219 219
 	print $langs->trans("BankAccount").'</td><td>';
@@ -230,27 +230,27 @@  discard block
 block discarded – undo
230 230
 
231 231
 print '<tr class="oddeven"><td>';
232 232
 print $langs->trans("PAYPAL_ADD_PAYMENT_URL").'</td><td>';
233
-print $form->selectyesno("PAYPAL_ADD_PAYMENT_URL",$conf->global->PAYPAL_ADD_PAYMENT_URL,1);
233
+print $form->selectyesno("PAYPAL_ADD_PAYMENT_URL", $conf->global->PAYPAL_ADD_PAYMENT_URL, 1);
234 234
 print '</td></tr>';
235 235
 
236 236
 
237 237
 print '<tr class="oddeven"><td>';
238 238
 print $langs->trans("MessageForm").'</td><td>';
239
-$doleditor=new DolEditor('ONLINE_PAYMENT_MESSAGE_FORM',$conf->global->ONLINE_PAYMENT_MESSAGE_FORM,'',100,'dolibarr_details','In',false,true,true,ROWS_4,'90%');
239
+$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_FORM', $conf->global->ONLINE_PAYMENT_MESSAGE_FORM, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
240 240
 $doleditor->Create();
241 241
 print '</td></tr>';
242 242
 
243 243
 
244 244
 print '<tr class="oddeven"><td>';
245 245
 print $langs->trans("MessageOK").'</td><td>';
246
-$doleditor=new DolEditor('ONLINE_PAYMENT_MESSAGE_OK',$conf->global->ONLINE_PAYMENT_MESSAGE_OK,'',100,'dolibarr_details','In',false,true,true,ROWS_4,'90%');
246
+$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_OK', $conf->global->ONLINE_PAYMENT_MESSAGE_OK, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
247 247
 $doleditor->Create();
248 248
 print '</td></tr>';
249 249
 
250 250
 
251 251
 print '<tr class="oddeven"><td>';
252 252
 print $langs->trans("MessageKO").'</td><td>';
253
-$doleditor=new DolEditor('ONLINE_PAYMENT_MESSAGE_KO',$conf->global->ONLINE_PAYMENT_MESSAGE_KO,'',100,'dolibarr_details','In',false,true,true,ROWS_4,'90%');
253
+$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_KO', $conf->global->ONLINE_PAYMENT_MESSAGE_KO, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
254 254
 $doleditor->Create();
255 255
 print '</td></tr>';
256 256
 
@@ -270,13 +270,13 @@  discard block
 block discarded – undo
270 270
 print '<tr class="oddeven"><td>';
271 271
 print $langs->trans("SecurityToken").'</td><td>';
272 272
 print '<input size="48" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.$conf->global->PAYMENT_SECURITY_TOKEN.'">';
273
-if (! empty($conf->use_javascript_ajax))
273
+if (!empty($conf->use_javascript_ajax))
274 274
 	print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
275 275
 	print '</td></tr>';
276 276
 
277 277
 	print '<tr class="oddeven"><td>';
278 278
 	print $langs->trans("SecurityTokenIsUnique").'</td><td>';
279
-	print $form->selectyesno("PAYMENT_SECURITY_TOKEN_UNIQUE",(empty($conf->global->PAYMENT_SECURITY_TOKEN)?0:$conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE),1);
279
+	print $form->selectyesno("PAYMENT_SECURITY_TOKEN_UNIQUE", (empty($conf->global->PAYMENT_SECURITY_TOKEN) ? 0 : $conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE), 1);
280 280
 	print '</td></tr>';
281 281
 
282 282
 print '</table>';
@@ -290,12 +290,12 @@  discard block
 block discarded – undo
290 290
 print '<br><br>';
291 291
 
292 292
 // Help doc
293
-print '<u>'.$langs->trans("InformationToFindParameters","Paypal").'</u>:<br>';
294
-if (! empty($conf->use_javascript_ajax))
293
+print '<u>'.$langs->trans("InformationToFindParameters", "Paypal").'</u>:<br>';
294
+if (!empty($conf->use_javascript_ajax))
295 295
 	print '<a href="#" class="reposition" id="apidoca">'.$langs->trans("ClickHere").'...</a>';
296 296
 
297
-$realpaypalurl='www.paypal.com';
298
-$sandboxpaypalurl='developer.paypal.com';
297
+$realpaypalurl = 'www.paypal.com';
298
+$sandboxpaypalurl = 'developer.paypal.com';
299 299
 
300 300
 print '<div id="apidoc">';
301 301
 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>
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 ';
311 311
 print '</div>';
312 312
 
313
-if (! empty($conf->use_javascript_ajax))
313
+if (!empty($conf->use_javascript_ajax))
314 314
 {
315 315
 	print "\n".'<script type="text/javascript">';
316 316
 	print '$(document).ready(function () {
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 
326 326
 print '<br><br>';
327 327
 
328
-$token='';
328
+$token = '';
329 329
 
330 330
 include DOL_DOCUMENT_ROOT.'/core/tpl/onlinepaymentlinks.tpl.php';
331 331
 
Please login to merge, or discard this patch.
dolibarr/htdocs/ftp/admin/ftpclient.php 3 patches
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 {
50 50
     $obj = $db->fetch_object($result);
51 51
     preg_match('/([0-9]+)$/i',$obj->name,$reg);
52
-	if ($reg[1]) $lastftpentry = $reg[1];
52
+    if ($reg[1]) $lastftpentry = $reg[1];
53 53
 }
54 54
 else
55 55
 {
@@ -59,37 +59,37 @@  discard block
 block discarded – undo
59 59
 if ($action == 'add' || GETPOST('modify','alpha'))
60 60
 {
61 61
     $ftp_name = "FTP_NAME_" . $entry;// $_POST["numero_entry"];
62
-	$ftp_server = "FTP_SERVER_" . $entry; //$_POST["numero_entry"];
62
+    $ftp_server = "FTP_SERVER_" . $entry; //$_POST["numero_entry"];
63 63
 
64
-	$error=0;
64
+    $error=0;
65 65
 
66
-	if (! GETPOST("$ftp_name",'alpha'))
67
-	{
68
-		$error=1;
69
-		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
70
-	}
66
+    if (! GETPOST("$ftp_name",'alpha'))
67
+    {
68
+        $error=1;
69
+        setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
70
+    }
71 71
 
72
-	if (! GETPOST("$ftp_server",'alpha'))
73
-	{
74
-		$error=1;
75
-		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Server")), null, 'errors');
76
-	}
72
+    if (! GETPOST("$ftp_server",'alpha'))
73
+    {
74
+        $error=1;
75
+        setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Server")), null, 'errors');
76
+    }
77 77
 
78 78
     if (! $error)
79 79
     {
80
-    	$ftp_port = "FTP_PORT_" . $entry;
80
+        $ftp_port = "FTP_PORT_" . $entry;
81 81
         $ftp_user = "FTP_USER_" . $entry;
82 82
         $ftp_password = "FTP_PASSWORD_" . $entry;
83 83
         $ftp_passive = "FTP_PASSIVE_" . $entry;
84 84
 
85 85
         $db->begin();
86 86
 
87
-		$result1=dolibarr_set_const($db, "FTP_PORT_" . $entry,GETPOST($ftp_port,'alpha'),'chaine',0,'',$conf->entity);
88
-		if ($result1) $result2=dolibarr_set_const($db, "FTP_SERVER_" . $entry, GETPOST($ftp_server,'alpha'),'chaine',0,'',$conf->entity);
89
-		if ($result2) $result3=dolibarr_set_const($db, "FTP_USER_" . $entry,GETPOST($ftp_user,'alpha'),'chaine',0,'',$conf->entity);
90
-		if ($result3) $result4=dolibarr_set_const($db, "FTP_PASSWORD_" . $entry,GETPOST($ftp_password,'alpha'),'chaine',0,'',$conf->entity);
91
-		if ($result4) $result5=dolibarr_set_const($db, "FTP_NAME_" . $entry,GETPOST($ftp_name,'alpha'),'chaine',0,'',$conf->entity);
92
-		if ($result5) $result6=dolibarr_set_const($db, "FTP_PASSIVE_" . $entry,GETPOST($ftp_passive,'alpha'),'chaine',0,'',$conf->entity);
87
+        $result1=dolibarr_set_const($db, "FTP_PORT_" . $entry,GETPOST($ftp_port,'alpha'),'chaine',0,'',$conf->entity);
88
+        if ($result1) $result2=dolibarr_set_const($db, "FTP_SERVER_" . $entry, GETPOST($ftp_server,'alpha'),'chaine',0,'',$conf->entity);
89
+        if ($result2) $result3=dolibarr_set_const($db, "FTP_USER_" . $entry,GETPOST($ftp_user,'alpha'),'chaine',0,'',$conf->entity);
90
+        if ($result3) $result4=dolibarr_set_const($db, "FTP_PASSWORD_" . $entry,GETPOST($ftp_password,'alpha'),'chaine',0,'',$conf->entity);
91
+        if ($result4) $result5=dolibarr_set_const($db, "FTP_NAME_" . $entry,GETPOST($ftp_name,'alpha'),'chaine',0,'',$conf->entity);
92
+        if ($result5) $result6=dolibarr_set_const($db, "FTP_PASSIVE_" . $entry,GETPOST($ftp_passive,'alpha'),'chaine',0,'',$conf->entity);
93 93
 
94 94
         if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6)
95 95
         {
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
     {
112 112
         $db->begin();
113 113
 
114
-		$result1=dolibarr_del_const($db,"FTP_PORT_" . $entry,$conf->entity);
115
-		if ($result1) $result2=dolibarr_del_const($db,"FTP_SERVER_" . $entry,$conf->entity);
116
-		if ($result2) $result3=dolibarr_del_const($db,"FTP_USER_" . $entry,$conf->entity);
117
-		if ($result3) $result4=dolibarr_del_const($db,"FTP_PASSWORD_" . $entry,$conf->entity);
118
-		if ($result4) $result5=dolibarr_del_const($db,"FTP_NAME_" . $entry,$conf->entity);
119
-		if ($result4) $result6=dolibarr_del_const($db,"FTP_PASSIVE_" . $entry,$conf->entity);
114
+        $result1=dolibarr_del_const($db,"FTP_PORT_" . $entry,$conf->entity);
115
+        if ($result1) $result2=dolibarr_del_const($db,"FTP_SERVER_" . $entry,$conf->entity);
116
+        if ($result2) $result3=dolibarr_del_const($db,"FTP_USER_" . $entry,$conf->entity);
117
+        if ($result3) $result4=dolibarr_del_const($db,"FTP_PASSWORD_" . $entry,$conf->entity);
118
+        if ($result4) $result5=dolibarr_del_const($db,"FTP_NAME_" . $entry,$conf->entity);
119
+        if ($result4) $result6=dolibarr_del_const($db,"FTP_PASSIVE_" . $entry,$conf->entity);
120 120
 		
121 121
         if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6)
122 122
         {
@@ -147,165 +147,165 @@  discard block
 block discarded – undo
147 147
 
148 148
 if (! function_exists('ftp_connect'))
149 149
 {
150
-	print $langs->trans("FTPFeatureNotSupportedByYourPHP");
150
+    print $langs->trans("FTPFeatureNotSupportedByYourPHP");
151 151
 }
152 152
 else
153 153
 {
154 154
 
155
-	// Formulaire ajout
156
-	print '<form name="ftpconfig" action="ftpclient.php" method="post">';
157
-	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
158
-
159
-	print '<table class="noborder" width="100%">';
160
-	print '<tr class="liste_titre">';
161
-	print '<td colspan="2">'.$langs->trans("NewFTPClient").'</td>';
162
-	print '<td>'.$langs->trans("Example").'</td>';
163
-	print '</tr>';
164
-
165
-	print '<tr class="pair">';
166
-	print '<td>'.$langs->trans("Label").'</td>';
167
-	print '<td><input type="text" name="FTP_NAME_'.($lastftpentry+1).'" value="'.GETPOST("FTP_NAME_" . ($lastftpentry+1)).'" size="64"></td>';
168
-	print '<td>My FTP access</td>';
169
-	print '</tr>';
170
-
171
-	print '<tr class="impair">';
172
-	print '<td>'.$langs->trans("Server").'</td>';
173
-	print '<td><input type="text" name="FTP_SERVER_'.($lastftpentry+1).'" value="'.GETPOST("FTP_SERVER_" . ($lastftpentry+1)).'" size="64"></td>';
174
-	print '<td>localhost</td>';
175
-	print '</tr>';
176
-
177
-	print '<tr class="pair">';
178
-	print '<td width="100">'.$langs->trans("Port").'</td>';
179
-	print '<td><input type="text" name="FTP_PORT_'.($lastftpentry+1).'" value="'.GETPOST("FTP_PORT_" . ($lastftpentry+1)).'" size="64"></td>';
180
-	print '<td>21 for pure non crypted FTP or if option FTP_CONNECT_WITH_SSL (See Home-Setup-Other) is on (FTPS)<br>22 if option FTP_CONNECT_WITH_SFTP (See Home-Setup-Other) is on (SFTP)</td>';
181
-	print '</tr>';
182
-
183
-	print '<tr class="impair">';
184
-	print '<td>'.$langs->trans("User").'</td>';
185
-	print '<td><input type="text" name="FTP_USER_'.($lastftpentry+1).'" value="'.GETPOST("FTP_USER_" . ($lastftpentry+1)).'" size="24"></td>';
186
-	print '<td>myftplogin</td>';
187
-	print '</tr>';
188
-
189
-	print '<tr class="pair">';
190
-	print '<td>'.$langs->trans("Password").'</td>';
191
-	print '<td><input type="password" name="FTP_PASSWORD_'.($lastftpentry+1).'" value="'.GETPOST("FTP_PASSWORD_" . ($lastftpentry+1)).'" size="24"></td>';
192
-	print '<td>myftppassword</td>';
193
-	print '</tr>';
194
-
195
-	print '<tr class="impair">';
196
-	print '<td>'.$langs->trans("FTPPassiveMode").'</td>';
197
-	$defaultpassive=GETPOST("FTP_PASSIVE_" . ($lastftpentry+1));
198
-	if (! isset($_POST["FTP_PASSIVE_" . ($lastftpentry+1)])) $defaultpassive=empty($conf->global->FTP_SUGGEST_PASSIVE_BYDEFAULT)?0:1;
199
-	print '<td>'.$form->selectyesno('FTP_PASSIVE_'.($lastftpentry+1), $defaultpassive, 2).'</td>';
200
-	print '<td>'.$langs->trans("No").'</td>';
201
-	print '</tr>';
155
+    // Formulaire ajout
156
+    print '<form name="ftpconfig" action="ftpclient.php" method="post">';
157
+    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
158
+
159
+    print '<table class="noborder" width="100%">';
160
+    print '<tr class="liste_titre">';
161
+    print '<td colspan="2">'.$langs->trans("NewFTPClient").'</td>';
162
+    print '<td>'.$langs->trans("Example").'</td>';
163
+    print '</tr>';
164
+
165
+    print '<tr class="pair">';
166
+    print '<td>'.$langs->trans("Label").'</td>';
167
+    print '<td><input type="text" name="FTP_NAME_'.($lastftpentry+1).'" value="'.GETPOST("FTP_NAME_" . ($lastftpentry+1)).'" size="64"></td>';
168
+    print '<td>My FTP access</td>';
169
+    print '</tr>';
170
+
171
+    print '<tr class="impair">';
172
+    print '<td>'.$langs->trans("Server").'</td>';
173
+    print '<td><input type="text" name="FTP_SERVER_'.($lastftpentry+1).'" value="'.GETPOST("FTP_SERVER_" . ($lastftpentry+1)).'" size="64"></td>';
174
+    print '<td>localhost</td>';
175
+    print '</tr>';
176
+
177
+    print '<tr class="pair">';
178
+    print '<td width="100">'.$langs->trans("Port").'</td>';
179
+    print '<td><input type="text" name="FTP_PORT_'.($lastftpentry+1).'" value="'.GETPOST("FTP_PORT_" . ($lastftpentry+1)).'" size="64"></td>';
180
+    print '<td>21 for pure non crypted FTP or if option FTP_CONNECT_WITH_SSL (See Home-Setup-Other) is on (FTPS)<br>22 if option FTP_CONNECT_WITH_SFTP (See Home-Setup-Other) is on (SFTP)</td>';
181
+    print '</tr>';
182
+
183
+    print '<tr class="impair">';
184
+    print '<td>'.$langs->trans("User").'</td>';
185
+    print '<td><input type="text" name="FTP_USER_'.($lastftpentry+1).'" value="'.GETPOST("FTP_USER_" . ($lastftpentry+1)).'" size="24"></td>';
186
+    print '<td>myftplogin</td>';
187
+    print '</tr>';
188
+
189
+    print '<tr class="pair">';
190
+    print '<td>'.$langs->trans("Password").'</td>';
191
+    print '<td><input type="password" name="FTP_PASSWORD_'.($lastftpentry+1).'" value="'.GETPOST("FTP_PASSWORD_" . ($lastftpentry+1)).'" size="24"></td>';
192
+    print '<td>myftppassword</td>';
193
+    print '</tr>';
194
+
195
+    print '<tr class="impair">';
196
+    print '<td>'.$langs->trans("FTPPassiveMode").'</td>';
197
+    $defaultpassive=GETPOST("FTP_PASSIVE_" . ($lastftpentry+1));
198
+    if (! isset($_POST["FTP_PASSIVE_" . ($lastftpentry+1)])) $defaultpassive=empty($conf->global->FTP_SUGGEST_PASSIVE_BYDEFAULT)?0:1;
199
+    print '<td>'.$form->selectyesno('FTP_PASSIVE_'.($lastftpentry+1), $defaultpassive, 2).'</td>';
200
+    print '<td>'.$langs->trans("No").'</td>';
201
+    print '</tr>';
202 202
 	
203
-	print '</table>';
203
+    print '</table>';
204 204
 	
205
-	?>
205
+    ?>
206 206
 	<br><div class="center"><input type="submit" class="button" value="<?php echo $langs->trans("Add") ?>"></div>
207 207
 	<input type="hidden" name="action" value="add">
208 208
 	<input type="hidden" name="numero_entry" value="<?php echo ($lastftpentry+1) ?>">
209 209
 	<?php
210
-	print '</form>';
211
-	?>
210
+    print '</form>';
211
+    ?>
212 212
 
213 213
 	<br>
214 214
 
215 215
 	<?php
216 216
 
217
-	$sql ="select name, value, note from ".MAIN_DB_PREFIX."const";
218
-	$sql.=" WHERE name like 'FTP_SERVER_%'";
219
-	$sql.=" ORDER BY name";
217
+    $sql ="select name, value, note from ".MAIN_DB_PREFIX."const";
218
+    $sql.=" WHERE name like 'FTP_SERVER_%'";
219
+    $sql.=" ORDER BY name";
220 220
 
221
-	dol_syslog("ftpclient select ftp setup", LOG_DEBUG);
222
-	$resql=$db->query($sql);
223
-	if ($resql)
224
-	{
225
-		$num =$db->num_rows($resql);
226
-		$i=0;
221
+    dol_syslog("ftpclient select ftp setup", LOG_DEBUG);
222
+    $resql=$db->query($sql);
223
+    if ($resql)
224
+    {
225
+        $num =$db->num_rows($resql);
226
+        $i=0;
227 227
 
228
-		while ($i < $num)
229
-		{
230
-			$obj = $db->fetch_object($resql);
228
+        while ($i < $num)
229
+        {
230
+            $obj = $db->fetch_object($resql);
231 231
 
232
-		    preg_match('/([0-9]+)$/i',$obj->name,$reg);
233
-			$idrss = $reg[0];
234
-			//print "x".join(',',$reg)."=".$obj->name."=".$idrss;
232
+            preg_match('/([0-9]+)$/i',$obj->name,$reg);
233
+            $idrss = $reg[0];
234
+            //print "x".join(',',$reg)."=".$obj->name."=".$idrss;
235 235
 
236
-			print "<form name=\"externalrssconfig\" action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\">";
237
-			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
238
-			print '<input type="hidden" name="numero_entry" value="'.$idrss.'">';
236
+            print "<form name=\"externalrssconfig\" action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\">";
237
+            print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
238
+            print '<input type="hidden" name="numero_entry" value="'.$idrss.'">';
239 239
 			
240
-			print '<table class="noborder" width="100%">'."\n";
241
-
242
-			print '<tr class="liste_titre">';
243
-			print '<td class="fieldtitle">'.$langs->trans("FTP")." ".($idrss)."</td>";
244
-			print '<td></td>';
245
-			print "</tr>";
246
-
247
-			$keyforname="FTP_NAME_" . $idrss;
248
-			$keyforserver="FTP_SERVER_" . $idrss;
249
-			$keyforport="FTP_PORT_" . $idrss;
250
-			$keyforuser="FTP_USER_" . $idrss;
251
-			$keyforpassword="FTP_PASSWORD_" . $idrss;
252
-			$keyforpassive="FTP_PASSIVE_" . $idrss;
240
+            print '<table class="noborder" width="100%">'."\n";
241
+
242
+            print '<tr class="liste_titre">';
243
+            print '<td class="fieldtitle">'.$langs->trans("FTP")." ".($idrss)."</td>";
244
+            print '<td></td>';
245
+            print "</tr>";
246
+
247
+            $keyforname="FTP_NAME_" . $idrss;
248
+            $keyforserver="FTP_SERVER_" . $idrss;
249
+            $keyforport="FTP_PORT_" . $idrss;
250
+            $keyforuser="FTP_USER_" . $idrss;
251
+            $keyforpassword="FTP_PASSWORD_" . $idrss;
252
+            $keyforpassive="FTP_PASSIVE_" . $idrss;
253 253
 				
254
-			print '<tr class="oddeven">';
255
-			print "<td>".$langs->trans("Name")."</td>";
256
-			print "<td><input type=\"text\" class=\"flat\" name=\"FTP_NAME_" . $idrss . "\" value=\"" . $conf->global->$keyforname . "\" size=\"64\"></td>";
257
-			print "</tr>";
254
+            print '<tr class="oddeven">';
255
+            print "<td>".$langs->trans("Name")."</td>";
256
+            print "<td><input type=\"text\" class=\"flat\" name=\"FTP_NAME_" . $idrss . "\" value=\"" . $conf->global->$keyforname . "\" size=\"64\"></td>";
257
+            print "</tr>";
258 258
 
259 259
 			
260
-			print '<tr class="oddeven">';
261
-			print "<td>".$langs->trans("Server")."</td>";
262
-			print "<td><input type=\"text\" class=\"flat\" name=\"FTP_SERVER_" . $idrss . "\" value=\"" . $conf->global->$keyforserver . "\" size=\"64\"></td>";
263
-			print "</tr>";
260
+            print '<tr class="oddeven">';
261
+            print "<td>".$langs->trans("Server")."</td>";
262
+            print "<td><input type=\"text\" class=\"flat\" name=\"FTP_SERVER_" . $idrss . "\" value=\"" . $conf->global->$keyforserver . "\" size=\"64\"></td>";
263
+            print "</tr>";
264 264
 
265 265
 			
266
-			print '<tr class="oddeven">';
267
-			print "<td width=\"100\">".$langs->trans("Port")."</td>";
268
-			print "<td><input type=\"text\" class=\"flat\" name=\"FTP_PORT_" . $idrss . "\" value=\"" . $conf->global->$keyforport . "\" size=\"64\"></td>";
269
-			print "</tr>";
266
+            print '<tr class="oddeven">';
267
+            print "<td width=\"100\">".$langs->trans("Port")."</td>";
268
+            print "<td><input type=\"text\" class=\"flat\" name=\"FTP_PORT_" . $idrss . "\" value=\"" . $conf->global->$keyforport . "\" size=\"64\"></td>";
269
+            print "</tr>";
270 270
 
271 271
 			
272
-			print '<tr class="oddeven">';
273
-			print "<td width=\"100\">".$langs->trans("User")."</td>";
274
-			print "<td><input type=\"text\" class=\"flat\" name=\"FTP_USER_" . $idrss . "\" value=\"" . $conf->global->$keyforuser . "\" size=\"24\"></td>";
275
-			print "</tr>";
272
+            print '<tr class="oddeven">';
273
+            print "<td width=\"100\">".$langs->trans("User")."</td>";
274
+            print "<td><input type=\"text\" class=\"flat\" name=\"FTP_USER_" . $idrss . "\" value=\"" . $conf->global->$keyforuser . "\" size=\"24\"></td>";
275
+            print "</tr>";
276 276
 
277 277
 			
278
-			print '<tr class="oddeven">';
279
-			print "<td width=\"100\">".$langs->trans("Password")."</td>";
280
-			print "<td><input type=\"password\" class=\"flat\" name=\"FTP_PASSWORD_" . $idrss . "\" value=\"" . $conf->global->$keyforpassword . "\" size=\"24\"></td>";
281
-			print "</tr>";
278
+            print '<tr class="oddeven">';
279
+            print "<td width=\"100\">".$langs->trans("Password")."</td>";
280
+            print "<td><input type=\"password\" class=\"flat\" name=\"FTP_PASSWORD_" . $idrss . "\" value=\"" . $conf->global->$keyforpassword . "\" size=\"24\"></td>";
281
+            print "</tr>";
282 282
 
283 283
 			
284
-			print '<tr class="oddeven">';
285
-			print "<td width=\"100\">".$langs->trans("FTPPassiveMode")."</td>";
286
-			print '<td>'.$form->selectyesno('FTP_PASSIVE_'.$idrss, $conf->global->$keyforpassive, 1).'</td>';
287
-			print "</tr>";
288
-
289
-			print "<tr>";
290
-			print "<td colspan=\"2\" align=\"center\">";
291
-			print "<input type=\"submit\" class=\"button\" name=\"modify\" value=\"".$langs->trans("Modify")."\">";
292
-			print " &nbsp; ";
293
-			print "<input type=\"submit\" class=\"button\" name=\"delete\" value=\"".$langs->trans("Delete")."\">";
294
-			print "</td>";
295
-			print "</tr>";
296
-
297
-			print '</table>';
284
+            print '<tr class="oddeven">';
285
+            print "<td width=\"100\">".$langs->trans("FTPPassiveMode")."</td>";
286
+            print '<td>'.$form->selectyesno('FTP_PASSIVE_'.$idrss, $conf->global->$keyforpassive, 1).'</td>';
287
+            print "</tr>";
288
+
289
+            print "<tr>";
290
+            print "<td colspan=\"2\" align=\"center\">";
291
+            print "<input type=\"submit\" class=\"button\" name=\"modify\" value=\"".$langs->trans("Modify")."\">";
292
+            print " &nbsp; ";
293
+            print "<input type=\"submit\" class=\"button\" name=\"delete\" value=\"".$langs->trans("Delete")."\">";
294
+            print "</td>";
295
+            print "</tr>";
296
+
297
+            print '</table>';
298 298
 			
299
-			print "</form>";
300
-			print '<br>';
299
+            print "</form>";
300
+            print '<br>';
301 301
 			
302
-			$i++;
303
-		}
304
-	}
305
-	else
306
-	{
307
-		dol_print_error($db);
308
-	}
302
+            $i++;
303
+        }
304
+    }
305
+    else
306
+    {
307
+        dol_print_error($db);
308
+    }
309 309
 }
310 310
 
311 311
 // End of page
Please login to merge, or discard this patch.
Braces   +44 added lines, -23 removed lines patch added patch discarded remove patch
@@ -28,7 +28,9 @@  discard block
 block discarded – undo
28 28
 $langs->loadLangs(array("admin", "ftp"));
29 29
 
30 30
 // Security check
31
-if (!$user->admin) accessforbidden();
31
+if (!$user->admin) {
32
+    accessforbidden();
33
+}
32 34
 
33 35
 $def = array();
34 36
 $lastftpentry=0;
@@ -49,9 +51,10 @@  discard block
 block discarded – undo
49 51
 {
50 52
     $obj = $db->fetch_object($result);
51 53
     preg_match('/([0-9]+)$/i',$obj->name,$reg);
52
-	if ($reg[1]) $lastftpentry = $reg[1];
53
-}
54
-else
54
+	if ($reg[1]) {
55
+	    $lastftpentry = $reg[1];
56
+	}
57
+	} else
55 58
 {
56 59
     dol_print_error($db);
57 60
 }
@@ -85,19 +88,28 @@  discard block
 block discarded – undo
85 88
         $db->begin();
86 89
 
87 90
 		$result1=dolibarr_set_const($db, "FTP_PORT_" . $entry,GETPOST($ftp_port,'alpha'),'chaine',0,'',$conf->entity);
88
-		if ($result1) $result2=dolibarr_set_const($db, "FTP_SERVER_" . $entry, GETPOST($ftp_server,'alpha'),'chaine',0,'',$conf->entity);
89
-		if ($result2) $result3=dolibarr_set_const($db, "FTP_USER_" . $entry,GETPOST($ftp_user,'alpha'),'chaine',0,'',$conf->entity);
90
-		if ($result3) $result4=dolibarr_set_const($db, "FTP_PASSWORD_" . $entry,GETPOST($ftp_password,'alpha'),'chaine',0,'',$conf->entity);
91
-		if ($result4) $result5=dolibarr_set_const($db, "FTP_NAME_" . $entry,GETPOST($ftp_name,'alpha'),'chaine',0,'',$conf->entity);
92
-		if ($result5) $result6=dolibarr_set_const($db, "FTP_PASSIVE_" . $entry,GETPOST($ftp_passive,'alpha'),'chaine',0,'',$conf->entity);
91
+		if ($result1) {
92
+		    $result2=dolibarr_set_const($db, "FTP_SERVER_" . $entry, GETPOST($ftp_server,'alpha'),'chaine',0,'',$conf->entity);
93
+		}
94
+		if ($result2) {
95
+		    $result3=dolibarr_set_const($db, "FTP_USER_" . $entry,GETPOST($ftp_user,'alpha'),'chaine',0,'',$conf->entity);
96
+		}
97
+		if ($result3) {
98
+		    $result4=dolibarr_set_const($db, "FTP_PASSWORD_" . $entry,GETPOST($ftp_password,'alpha'),'chaine',0,'',$conf->entity);
99
+		}
100
+		if ($result4) {
101
+		    $result5=dolibarr_set_const($db, "FTP_NAME_" . $entry,GETPOST($ftp_name,'alpha'),'chaine',0,'',$conf->entity);
102
+		}
103
+		if ($result5) {
104
+		    $result6=dolibarr_set_const($db, "FTP_PASSIVE_" . $entry,GETPOST($ftp_passive,'alpha'),'chaine',0,'',$conf->entity);
105
+		}
93 106
 
94 107
         if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6)
95 108
         {
96 109
             $db->commit();
97 110
             header("Location: ".$_SERVER["PHP_SELF"]);
98 111
             exit;
99
-        }
100
-        else
112
+        } else
101 113
         {
102 114
             $db->rollback();
103 115
             dol_print_error($db);
@@ -112,19 +124,28 @@  discard block
 block discarded – undo
112 124
         $db->begin();
113 125
 
114 126
 		$result1=dolibarr_del_const($db,"FTP_PORT_" . $entry,$conf->entity);
115
-		if ($result1) $result2=dolibarr_del_const($db,"FTP_SERVER_" . $entry,$conf->entity);
116
-		if ($result2) $result3=dolibarr_del_const($db,"FTP_USER_" . $entry,$conf->entity);
117
-		if ($result3) $result4=dolibarr_del_const($db,"FTP_PASSWORD_" . $entry,$conf->entity);
118
-		if ($result4) $result5=dolibarr_del_const($db,"FTP_NAME_" . $entry,$conf->entity);
119
-		if ($result4) $result6=dolibarr_del_const($db,"FTP_PASSIVE_" . $entry,$conf->entity);
127
+		if ($result1) {
128
+		    $result2=dolibarr_del_const($db,"FTP_SERVER_" . $entry,$conf->entity);
129
+		}
130
+		if ($result2) {
131
+		    $result3=dolibarr_del_const($db,"FTP_USER_" . $entry,$conf->entity);
132
+		}
133
+		if ($result3) {
134
+		    $result4=dolibarr_del_const($db,"FTP_PASSWORD_" . $entry,$conf->entity);
135
+		}
136
+		if ($result4) {
137
+		    $result5=dolibarr_del_const($db,"FTP_NAME_" . $entry,$conf->entity);
138
+		}
139
+		if ($result4) {
140
+		    $result6=dolibarr_del_const($db,"FTP_PASSIVE_" . $entry,$conf->entity);
141
+		}
120 142
 		
121 143
         if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6)
122 144
         {
123 145
             $db->commit();
124 146
             header("Location: ".$_SERVER["PHP_SELF"]);
125 147
             exit;
126
-        }
127
-        else
148
+        } else
128 149
         {
129 150
             $db->rollback();
130 151
             dol_print_error($db);
@@ -148,8 +169,7 @@  discard block
 block discarded – undo
148 169
 if (! function_exists('ftp_connect'))
149 170
 {
150 171
 	print $langs->trans("FTPFeatureNotSupportedByYourPHP");
151
-}
152
-else
172
+} else
153 173
 {
154 174
 
155 175
 	// Formulaire ajout
@@ -195,7 +215,9 @@  discard block
 block discarded – undo
195 215
 	print '<tr class="impair">';
196 216
 	print '<td>'.$langs->trans("FTPPassiveMode").'</td>';
197 217
 	$defaultpassive=GETPOST("FTP_PASSIVE_" . ($lastftpentry+1));
198
-	if (! isset($_POST["FTP_PASSIVE_" . ($lastftpentry+1)])) $defaultpassive=empty($conf->global->FTP_SUGGEST_PASSIVE_BYDEFAULT)?0:1;
218
+	if (! isset($_POST["FTP_PASSIVE_" . ($lastftpentry+1)])) {
219
+	    $defaultpassive=empty($conf->global->FTP_SUGGEST_PASSIVE_BYDEFAULT)?0:1;
220
+	}
199 221
 	print '<td>'.$form->selectyesno('FTP_PASSIVE_'.($lastftpentry+1), $defaultpassive, 2).'</td>';
200 222
 	print '<td>'.$langs->trans("No").'</td>';
201 223
 	print '</tr>';
@@ -301,8 +323,7 @@  discard block
 block discarded – undo
301 323
 			
302 324
 			$i++;
303 325
 		}
304
-	}
305
-	else
326
+	} else
306 327
 	{
307 328
 		dol_print_error($db);
308 329
 	}
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -24,8 +24,8 @@  discard block
 block discarded – undo
24 24
 
25 25
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
26 26
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
27
-require DOL_BASE_PATH . '/main.inc.php';
28
-require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
27
+require DOL_BASE_PATH.'/main.inc.php';
28
+require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29 29
 
30 30
 $langs->loadLangs(array("admin", "ftp"));
31 31
 
@@ -33,10 +33,10 @@  discard block
 block discarded – undo
33 33
 if (!$user->admin) accessforbidden();
34 34
 
35 35
 $def = array();
36
-$lastftpentry=0;
36
+$lastftpentry = 0;
37 37
 
38
-$action = GETPOST('action','alpha');
39
-$entry = GETPOST('numero_entry','alpha');
38
+$action = GETPOST('action', 'alpha');
39
+$entry = GETPOST('numero_entry', 'alpha');
40 40
 
41 41
 
42 42
 /*
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
  */
45 45
 
46 46
 // Get value for $lastftpentry
47
-$sql ="select MAX(name) as name from ".MAIN_DB_PREFIX."const";
48
-$sql.=" WHERE name like 'FTP_SERVER_%'";
49
-$result=$db->query($sql);
47
+$sql = "select MAX(name) as name from ".MAIN_DB_PREFIX."const";
48
+$sql .= " WHERE name like 'FTP_SERVER_%'";
49
+$result = $db->query($sql);
50 50
 if ($result)
51 51
 {
52 52
     $obj = $db->fetch_object($result);
53
-    preg_match('/([0-9]+)$/i',$obj->name,$reg);
53
+    preg_match('/([0-9]+)$/i', $obj->name, $reg);
54 54
 	if ($reg[1]) $lastftpentry = $reg[1];
55 55
 }
56 56
 else
@@ -58,40 +58,40 @@  discard block
 block discarded – undo
58 58
     dol_print_error($db);
59 59
 }
60 60
 
61
-if ($action == 'add' || GETPOST('modify','alpha'))
61
+if ($action == 'add' || GETPOST('modify', 'alpha'))
62 62
 {
63
-    $ftp_name = "FTP_NAME_" . $entry;// $_POST["numero_entry"];
64
-	$ftp_server = "FTP_SERVER_" . $entry; //$_POST["numero_entry"];
63
+    $ftp_name = "FTP_NAME_".$entry; // $_POST["numero_entry"];
64
+	$ftp_server = "FTP_SERVER_".$entry; //$_POST["numero_entry"];
65 65
 
66
-	$error=0;
66
+	$error = 0;
67 67
 
68
-	if (! GETPOST("$ftp_name",'alpha'))
68
+	if (!GETPOST("$ftp_name", 'alpha'))
69 69
 	{
70
-		$error=1;
70
+		$error = 1;
71 71
 		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
72 72
 	}
73 73
 
74
-	if (! GETPOST("$ftp_server",'alpha'))
74
+	if (!GETPOST("$ftp_server", 'alpha'))
75 75
 	{
76
-		$error=1;
76
+		$error = 1;
77 77
 		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Server")), null, 'errors');
78 78
 	}
79 79
 
80
-    if (! $error)
80
+    if (!$error)
81 81
     {
82
-    	$ftp_port = "FTP_PORT_" . $entry;
83
-        $ftp_user = "FTP_USER_" . $entry;
84
-        $ftp_password = "FTP_PASSWORD_" . $entry;
85
-        $ftp_passive = "FTP_PASSIVE_" . $entry;
82
+    	$ftp_port = "FTP_PORT_".$entry;
83
+        $ftp_user = "FTP_USER_".$entry;
84
+        $ftp_password = "FTP_PASSWORD_".$entry;
85
+        $ftp_passive = "FTP_PASSIVE_".$entry;
86 86
 
87 87
         $db->begin();
88 88
 
89
-		$result1=dolibarr_set_const($db, "FTP_PORT_" . $entry,GETPOST($ftp_port,'alpha'),'chaine',0,'',$conf->entity);
90
-		if ($result1) $result2=dolibarr_set_const($db, "FTP_SERVER_" . $entry, GETPOST($ftp_server,'alpha'),'chaine',0,'',$conf->entity);
91
-		if ($result2) $result3=dolibarr_set_const($db, "FTP_USER_" . $entry,GETPOST($ftp_user,'alpha'),'chaine',0,'',$conf->entity);
92
-		if ($result3) $result4=dolibarr_set_const($db, "FTP_PASSWORD_" . $entry,GETPOST($ftp_password,'alpha'),'chaine',0,'',$conf->entity);
93
-		if ($result4) $result5=dolibarr_set_const($db, "FTP_NAME_" . $entry,GETPOST($ftp_name,'alpha'),'chaine',0,'',$conf->entity);
94
-		if ($result5) $result6=dolibarr_set_const($db, "FTP_PASSIVE_" . $entry,GETPOST($ftp_passive,'alpha'),'chaine',0,'',$conf->entity);
89
+		$result1 = dolibarr_set_const($db, "FTP_PORT_".$entry, GETPOST($ftp_port, 'alpha'), 'chaine', 0, '', $conf->entity);
90
+		if ($result1) $result2 = dolibarr_set_const($db, "FTP_SERVER_".$entry, GETPOST($ftp_server, 'alpha'), 'chaine', 0, '', $conf->entity);
91
+		if ($result2) $result3 = dolibarr_set_const($db, "FTP_USER_".$entry, GETPOST($ftp_user, 'alpha'), 'chaine', 0, '', $conf->entity);
92
+		if ($result3) $result4 = dolibarr_set_const($db, "FTP_PASSWORD_".$entry, GETPOST($ftp_password, 'alpha'), 'chaine', 0, '', $conf->entity);
93
+		if ($result4) $result5 = dolibarr_set_const($db, "FTP_NAME_".$entry, GETPOST($ftp_name, 'alpha'), 'chaine', 0, '', $conf->entity);
94
+		if ($result5) $result6 = dolibarr_set_const($db, "FTP_PASSIVE_".$entry, GETPOST($ftp_passive, 'alpha'), 'chaine', 0, '', $conf->entity);
95 95
 
96 96
         if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6)
97 97
         {
@@ -107,18 +107,18 @@  discard block
 block discarded – undo
107 107
     }
108 108
 }
109 109
 
110
-if (GETPOST('delete','alpha'))
110
+if (GETPOST('delete', 'alpha'))
111 111
 {
112
-    if($entry)
112
+    if ($entry)
113 113
     {
114 114
         $db->begin();
115 115
 
116
-		$result1=dolibarr_del_const($db,"FTP_PORT_" . $entry,$conf->entity);
117
-		if ($result1) $result2=dolibarr_del_const($db,"FTP_SERVER_" . $entry,$conf->entity);
118
-		if ($result2) $result3=dolibarr_del_const($db,"FTP_USER_" . $entry,$conf->entity);
119
-		if ($result3) $result4=dolibarr_del_const($db,"FTP_PASSWORD_" . $entry,$conf->entity);
120
-		if ($result4) $result5=dolibarr_del_const($db,"FTP_NAME_" . $entry,$conf->entity);
121
-		if ($result4) $result6=dolibarr_del_const($db,"FTP_PASSIVE_" . $entry,$conf->entity);
116
+		$result1 = dolibarr_del_const($db, "FTP_PORT_".$entry, $conf->entity);
117
+		if ($result1) $result2 = dolibarr_del_const($db, "FTP_SERVER_".$entry, $conf->entity);
118
+		if ($result2) $result3 = dolibarr_del_const($db, "FTP_USER_".$entry, $conf->entity);
119
+		if ($result3) $result4 = dolibarr_del_const($db, "FTP_PASSWORD_".$entry, $conf->entity);
120
+		if ($result4) $result5 = dolibarr_del_const($db, "FTP_NAME_".$entry, $conf->entity);
121
+		if ($result4) $result6 = dolibarr_del_const($db, "FTP_PASSIVE_".$entry, $conf->entity);
122 122
 		
123 123
         if ($result1 && $result2 && $result3 && $result4 && $result5 && $result6)
124 124
         {
@@ -139,15 +139,15 @@  discard block
 block discarded – undo
139 139
  * View
140 140
  */
141 141
 
142
-$form=new Form($db);
142
+$form = new Form($db);
143 143
 
144 144
 llxHeader();
145 145
 
146
-$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
146
+$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
147 147
 print load_fiche_titre($langs->trans("FTPClientSetup"), $linkback, 'title_setup');
148 148
 print '<br>';
149 149
 
150
-if (! function_exists('ftp_connect'))
150
+if (!function_exists('ftp_connect'))
151 151
 {
152 152
 	print $langs->trans("FTPFeatureNotSupportedByYourPHP");
153 153
 }
@@ -166,39 +166,39 @@  discard block
 block discarded – undo
166 166
 
167 167
 	print '<tr class="pair">';
168 168
 	print '<td>'.$langs->trans("Label").'</td>';
169
-	print '<td><input type="text" name="FTP_NAME_'.($lastftpentry+1).'" value="'.GETPOST("FTP_NAME_" . ($lastftpentry+1)).'" size="64"></td>';
169
+	print '<td><input type="text" name="FTP_NAME_'.($lastftpentry + 1).'" value="'.GETPOST("FTP_NAME_".($lastftpentry + 1)).'" size="64"></td>';
170 170
 	print '<td>My FTP access</td>';
171 171
 	print '</tr>';
172 172
 
173 173
 	print '<tr class="impair">';
174 174
 	print '<td>'.$langs->trans("Server").'</td>';
175
-	print '<td><input type="text" name="FTP_SERVER_'.($lastftpentry+1).'" value="'.GETPOST("FTP_SERVER_" . ($lastftpentry+1)).'" size="64"></td>';
175
+	print '<td><input type="text" name="FTP_SERVER_'.($lastftpentry + 1).'" value="'.GETPOST("FTP_SERVER_".($lastftpentry + 1)).'" size="64"></td>';
176 176
 	print '<td>localhost</td>';
177 177
 	print '</tr>';
178 178
 
179 179
 	print '<tr class="pair">';
180 180
 	print '<td width="100">'.$langs->trans("Port").'</td>';
181
-	print '<td><input type="text" name="FTP_PORT_'.($lastftpentry+1).'" value="'.GETPOST("FTP_PORT_" . ($lastftpentry+1)).'" size="64"></td>';
181
+	print '<td><input type="text" name="FTP_PORT_'.($lastftpentry + 1).'" value="'.GETPOST("FTP_PORT_".($lastftpentry + 1)).'" size="64"></td>';
182 182
 	print '<td>21 for pure non crypted FTP or if option FTP_CONNECT_WITH_SSL (See Home-Setup-Other) is on (FTPS)<br>22 if option FTP_CONNECT_WITH_SFTP (See Home-Setup-Other) is on (SFTP)</td>';
183 183
 	print '</tr>';
184 184
 
185 185
 	print '<tr class="impair">';
186 186
 	print '<td>'.$langs->trans("User").'</td>';
187
-	print '<td><input type="text" name="FTP_USER_'.($lastftpentry+1).'" value="'.GETPOST("FTP_USER_" . ($lastftpentry+1)).'" size="24"></td>';
187
+	print '<td><input type="text" name="FTP_USER_'.($lastftpentry + 1).'" value="'.GETPOST("FTP_USER_".($lastftpentry + 1)).'" size="24"></td>';
188 188
 	print '<td>myftplogin</td>';
189 189
 	print '</tr>';
190 190
 
191 191
 	print '<tr class="pair">';
192 192
 	print '<td>'.$langs->trans("Password").'</td>';
193
-	print '<td><input type="password" name="FTP_PASSWORD_'.($lastftpentry+1).'" value="'.GETPOST("FTP_PASSWORD_" . ($lastftpentry+1)).'" size="24"></td>';
193
+	print '<td><input type="password" name="FTP_PASSWORD_'.($lastftpentry + 1).'" value="'.GETPOST("FTP_PASSWORD_".($lastftpentry + 1)).'" size="24"></td>';
194 194
 	print '<td>myftppassword</td>';
195 195
 	print '</tr>';
196 196
 
197 197
 	print '<tr class="impair">';
198 198
 	print '<td>'.$langs->trans("FTPPassiveMode").'</td>';
199
-	$defaultpassive=GETPOST("FTP_PASSIVE_" . ($lastftpentry+1));
200
-	if (! isset($_POST["FTP_PASSIVE_" . ($lastftpentry+1)])) $defaultpassive=empty($conf->global->FTP_SUGGEST_PASSIVE_BYDEFAULT)?0:1;
201
-	print '<td>'.$form->selectyesno('FTP_PASSIVE_'.($lastftpentry+1), $defaultpassive, 2).'</td>';
199
+	$defaultpassive = GETPOST("FTP_PASSIVE_".($lastftpentry + 1));
200
+	if (!isset($_POST["FTP_PASSIVE_".($lastftpentry + 1)])) $defaultpassive = empty($conf->global->FTP_SUGGEST_PASSIVE_BYDEFAULT) ? 0 : 1;
201
+	print '<td>'.$form->selectyesno('FTP_PASSIVE_'.($lastftpentry + 1), $defaultpassive, 2).'</td>';
202 202
 	print '<td>'.$langs->trans("No").'</td>';
203 203
 	print '</tr>';
204 204
 	
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	?>
208 208
 	<br><div class="center"><input type="submit" class="button" value="<?php echo $langs->trans("Add") ?>"></div>
209 209
 	<input type="hidden" name="action" value="add">
210
-	<input type="hidden" name="numero_entry" value="<?php echo ($lastftpentry+1) ?>">
210
+	<input type="hidden" name="numero_entry" value="<?php echo ($lastftpentry + 1) ?>">
211 211
 	<?php
212 212
 	print '</form>';
213 213
 	?>
@@ -216,22 +216,22 @@  discard block
 block discarded – undo
216 216
 
217 217
 	<?php
218 218
 
219
-	$sql ="select name, value, note from ".MAIN_DB_PREFIX."const";
220
-	$sql.=" WHERE name like 'FTP_SERVER_%'";
221
-	$sql.=" ORDER BY name";
219
+	$sql = "select name, value, note from ".MAIN_DB_PREFIX."const";
220
+	$sql .= " WHERE name like 'FTP_SERVER_%'";
221
+	$sql .= " ORDER BY name";
222 222
 
223 223
 	dol_syslog("ftpclient select ftp setup", LOG_DEBUG);
224
-	$resql=$db->query($sql);
224
+	$resql = $db->query($sql);
225 225
 	if ($resql)
226 226
 	{
227
-		$num =$db->num_rows($resql);
228
-		$i=0;
227
+		$num = $db->num_rows($resql);
228
+		$i = 0;
229 229
 
230 230
 		while ($i < $num)
231 231
 		{
232 232
 			$obj = $db->fetch_object($resql);
233 233
 
234
-		    preg_match('/([0-9]+)$/i',$obj->name,$reg);
234
+		    preg_match('/([0-9]+)$/i', $obj->name, $reg);
235 235
 			$idrss = $reg[0];
236 236
 			//print "x".join(',',$reg)."=".$obj->name."=".$idrss;
237 237
 
@@ -246,40 +246,40 @@  discard block
 block discarded – undo
246 246
 			print '<td></td>';
247 247
 			print "</tr>";
248 248
 
249
-			$keyforname="FTP_NAME_" . $idrss;
250
-			$keyforserver="FTP_SERVER_" . $idrss;
251
-			$keyforport="FTP_PORT_" . $idrss;
252
-			$keyforuser="FTP_USER_" . $idrss;
253
-			$keyforpassword="FTP_PASSWORD_" . $idrss;
254
-			$keyforpassive="FTP_PASSIVE_" . $idrss;
249
+			$keyforname = "FTP_NAME_".$idrss;
250
+			$keyforserver = "FTP_SERVER_".$idrss;
251
+			$keyforport = "FTP_PORT_".$idrss;
252
+			$keyforuser = "FTP_USER_".$idrss;
253
+			$keyforpassword = "FTP_PASSWORD_".$idrss;
254
+			$keyforpassive = "FTP_PASSIVE_".$idrss;
255 255
 				
256 256
 			print '<tr class="oddeven">';
257 257
 			print "<td>".$langs->trans("Name")."</td>";
258
-			print "<td><input type=\"text\" class=\"flat\" name=\"FTP_NAME_" . $idrss . "\" value=\"" . $conf->global->$keyforname . "\" size=\"64\"></td>";
258
+			print "<td><input type=\"text\" class=\"flat\" name=\"FTP_NAME_".$idrss."\" value=\"".$conf->global->$keyforname."\" size=\"64\"></td>";
259 259
 			print "</tr>";
260 260
 
261 261
 			
262 262
 			print '<tr class="oddeven">';
263 263
 			print "<td>".$langs->trans("Server")."</td>";
264
-			print "<td><input type=\"text\" class=\"flat\" name=\"FTP_SERVER_" . $idrss . "\" value=\"" . $conf->global->$keyforserver . "\" size=\"64\"></td>";
264
+			print "<td><input type=\"text\" class=\"flat\" name=\"FTP_SERVER_".$idrss."\" value=\"".$conf->global->$keyforserver."\" size=\"64\"></td>";
265 265
 			print "</tr>";
266 266
 
267 267
 			
268 268
 			print '<tr class="oddeven">';
269 269
 			print "<td width=\"100\">".$langs->trans("Port")."</td>";
270
-			print "<td><input type=\"text\" class=\"flat\" name=\"FTP_PORT_" . $idrss . "\" value=\"" . $conf->global->$keyforport . "\" size=\"64\"></td>";
270
+			print "<td><input type=\"text\" class=\"flat\" name=\"FTP_PORT_".$idrss."\" value=\"".$conf->global->$keyforport."\" size=\"64\"></td>";
271 271
 			print "</tr>";
272 272
 
273 273
 			
274 274
 			print '<tr class="oddeven">';
275 275
 			print "<td width=\"100\">".$langs->trans("User")."</td>";
276
-			print "<td><input type=\"text\" class=\"flat\" name=\"FTP_USER_" . $idrss . "\" value=\"" . $conf->global->$keyforuser . "\" size=\"24\"></td>";
276
+			print "<td><input type=\"text\" class=\"flat\" name=\"FTP_USER_".$idrss."\" value=\"".$conf->global->$keyforuser."\" size=\"24\"></td>";
277 277
 			print "</tr>";
278 278
 
279 279
 			
280 280
 			print '<tr class="oddeven">';
281 281
 			print "<td width=\"100\">".$langs->trans("Password")."</td>";
282
-			print "<td><input type=\"password\" class=\"flat\" name=\"FTP_PASSWORD_" . $idrss . "\" value=\"" . $conf->global->$keyforpassword . "\" size=\"24\"></td>";
282
+			print "<td><input type=\"password\" class=\"flat\" name=\"FTP_PASSWORD_".$idrss."\" value=\"".$conf->global->$keyforpassword."\" size=\"24\"></td>";
283 283
 			print "</tr>";
284 284
 
285 285
 			
Please login to merge, or discard this patch.
dolibarr/htdocs/ftp/index.php 3 patches
Indentation   +560 added lines, -560 removed lines patch added patch discarded remove patch
@@ -83,268 +83,268 @@  discard block
 block discarded – undo
83 83
 // Submit file
84 84
 if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC))
85 85
 {
86
-	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
87
-
88
-	$result=$ecmdir->fetch($_REQUEST["section"]);
89
-	if (! $result > 0)
90
-	{
91
-		dol_print_error($db,$ecmdir->error);
92
-		exit;
93
-	}
94
-	$relativepath=$ecmdir->getRelativePath();
95
-	$upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
96
-
97
-	if (dol_mkdir($upload_dir) >= 0)
98
-	{
99
-		$resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0);
100
-		if (is_numeric($resupload) && $resupload > 0)
101
-		{
102
-			$result=$ecmdir->changeNbOfFiles('+');
103
-		}
104
-		else {
105
-			$langs->load("errors");
106
-			if ($resupload < 0)	// Unknown error
107
-			{
108
-				setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors');
109
-			}
110
-			else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload))	// Files infected by a virus
111
-			{
112
-				setEventMessages($langs->trans("ErrorFileIsInfectedWithAVirus"), null, 'errors');
113
-			}
114
-			else	// Known error
115
-			{
116
-				setEventMessages($langs->trans($resupload), null, 'errors');
117
-			}
118
-		}
119
-	}
120
-	else
121
-	{
122
-		// Echec transfert (fichier depassant la limite ?)
123
-		$langs->load("errors");
124
-		setEventMessages($langs->trans("ErrorFailToCreateDir",$upload_dir), null, 'errors');
125
-	}
86
+    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
87
+
88
+    $result=$ecmdir->fetch($_REQUEST["section"]);
89
+    if (! $result > 0)
90
+    {
91
+        dol_print_error($db,$ecmdir->error);
92
+        exit;
93
+    }
94
+    $relativepath=$ecmdir->getRelativePath();
95
+    $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
96
+
97
+    if (dol_mkdir($upload_dir) >= 0)
98
+    {
99
+        $resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0);
100
+        if (is_numeric($resupload) && $resupload > 0)
101
+        {
102
+            $result=$ecmdir->changeNbOfFiles('+');
103
+        }
104
+        else {
105
+            $langs->load("errors");
106
+            if ($resupload < 0)	// Unknown error
107
+            {
108
+                setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors');
109
+            }
110
+            else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload))	// Files infected by a virus
111
+            {
112
+                setEventMessages($langs->trans("ErrorFileIsInfectedWithAVirus"), null, 'errors');
113
+            }
114
+            else	// Known error
115
+            {
116
+                setEventMessages($langs->trans($resupload), null, 'errors');
117
+            }
118
+        }
119
+    }
120
+    else
121
+    {
122
+        // Echec transfert (fichier depassant la limite ?)
123
+        $langs->load("errors");
124
+        setEventMessages($langs->trans("ErrorFailToCreateDir",$upload_dir), null, 'errors');
125
+    }
126 126
 }
127 127
 
128 128
 // Action ajout d'un rep
129 129
 if ($action == 'add' && $user->rights->ftp->setup)
130 130
 {
131
-	$ecmdir->ref                = $_POST["ref"];
132
-	$ecmdir->label              = $_POST["label"];
133
-	$ecmdir->description        = $_POST["desc"];
134
-
135
-	$id = $ecmdir->create($user);
136
-	if ($id > 0)
137
-	{
138
-		header("Location: ".$_SERVER["PHP_SELF"]);
139
-		exit;
140
-	}
141
-	else
142
-	{
143
-		setEventMessages($langs->trans("ErrorFailToCreateDir"), null, 'errors');
144
-		$action = "create";
145
-	}
131
+    $ecmdir->ref                = $_POST["ref"];
132
+    $ecmdir->label              = $_POST["label"];
133
+    $ecmdir->description        = $_POST["desc"];
134
+
135
+    $id = $ecmdir->create($user);
136
+    if ($id > 0)
137
+    {
138
+        header("Location: ".$_SERVER["PHP_SELF"]);
139
+        exit;
140
+    }
141
+    else
142
+    {
143
+        setEventMessages($langs->trans("ErrorFailToCreateDir"), null, 'errors');
144
+        $action = "create";
145
+    }
146 146
 }
147 147
 
148 148
 // Remove file
149 149
 if ($action == 'confirm_deletefile' && $_REQUEST['confirm'] == 'yes')
150 150
 {
151
-	// set up a connection or die
152
-	if (! $conn_id)
153
-	{
154
-		$newsectioniso=utf8_decode($section);
155
-		$resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
156
-		$conn_id=$resultarray['conn_id'];
157
-		$ok=$resultarray['ok'];
158
-		$mesg=$resultarray['mesg'];
159
-	}
160
-
161
-	if ($conn_id && $ok && ! $mesg)
162
-	{
163
-	    $langs->load("other");
164
-
165
-		// Remote file
166
-		$filename=$file;
167
-		$remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
168
-		$newremotefileiso=utf8_decode($remotefile);
169
-
170
-		//print "x".$newremotefileiso;
171
-		dol_syslog("ftp/index.php ftp_delete ".$newremotefileiso);
172
-		$result=@ftp_delete($conn_id, $newremotefileiso);
173
-		if ($result)
174
-		{
175
-			setEventMessages($langs->trans("FileWasRemoved",$file), null, 'mesgs');
176
-		}
177
-		else
178
-		{
179
-			dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
180
-			setEventMessages($langs->trans("FTPFailedToRemoveFile",$file), null, 'errors');
181
-		}
182
-
183
-		//ftp_close($conn_id);	Close later
151
+    // set up a connection or die
152
+    if (! $conn_id)
153
+    {
154
+        $newsectioniso=utf8_decode($section);
155
+        $resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
156
+        $conn_id=$resultarray['conn_id'];
157
+        $ok=$resultarray['ok'];
158
+        $mesg=$resultarray['mesg'];
159
+    }
184 160
 
185
-		$action='';
186
-	}
187
-	else
188
-	{
189
-		dol_print_error('',$mesg);
190
-	}
161
+    if ($conn_id && $ok && ! $mesg)
162
+    {
163
+        $langs->load("other");
164
+
165
+        // Remote file
166
+        $filename=$file;
167
+        $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
168
+        $newremotefileiso=utf8_decode($remotefile);
169
+
170
+        //print "x".$newremotefileiso;
171
+        dol_syslog("ftp/index.php ftp_delete ".$newremotefileiso);
172
+        $result=@ftp_delete($conn_id, $newremotefileiso);
173
+        if ($result)
174
+        {
175
+            setEventMessages($langs->trans("FileWasRemoved",$file), null, 'mesgs');
176
+        }
177
+        else
178
+        {
179
+            dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
180
+            setEventMessages($langs->trans("FTPFailedToRemoveFile",$file), null, 'errors');
181
+        }
182
+
183
+        //ftp_close($conn_id);	Close later
184
+
185
+        $action='';
186
+    }
187
+    else
188
+    {
189
+        dol_print_error('',$mesg);
190
+    }
191 191
 }
192 192
 
193 193
 // Delete several lines at once
194 194
 if ($_POST["const"] && $_POST["delete"] && $_POST["delete"] == $langs->trans("Delete"))
195 195
 {
196
-	// set up a connection or die
197
-	if (! $conn_id)
198
-	{
199
-		$newsectioniso=utf8_decode($section);
200
-		$resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
201
-		$conn_id=$resultarray['conn_id'];
202
-		$ok=$resultarray['ok'];
203
-		$mesg=$resultarray['mesg'];
204
-	}
205
-
206
-	if ($conn_id && $ok && ! $mesg)
207
-	{
208
-		foreach($_POST["const"] as $const)
209
-		{
210
-			if ($const["check"])	// Is checkbox checked
211
-			{
212
-			    $langs->load("other");
213
-
214
-				// Remote file
215
-				$file=$const["file"];
216
-				$section=$const["section"];
217
-				$remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
218
-				$newremotefileiso=utf8_decode($remotefile);
219
-
220
-				//print "x".$newremotefileiso;
221
-				dol_syslog("ftp/index.php ftp_delete ".$newremotefileiso);
222
-				$result=@ftp_delete($conn_id, $newremotefileiso);
223
-				if ($result)
224
-				{
225
-					setEventMessages($langs->trans("FileWasRemoved",$file), null, 'mesgs');
226
-				}
227
-				else
228
-				{
229
-					dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
230
-					setEventMessages($langs->trans("FTPFailedToRemoveFile",$file), null, 'errors');
231
-				}
232
-
233
-				//ftp_close($conn_id);	Close later
234
-
235
-				$action='';
236
-			}
237
-		}
238
-	}
239
-	else
240
-	{
241
-		dol_print_error('',$mesg);
242
-	}
196
+    // set up a connection or die
197
+    if (! $conn_id)
198
+    {
199
+        $newsectioniso=utf8_decode($section);
200
+        $resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
201
+        $conn_id=$resultarray['conn_id'];
202
+        $ok=$resultarray['ok'];
203
+        $mesg=$resultarray['mesg'];
204
+    }
205
+
206
+    if ($conn_id && $ok && ! $mesg)
207
+    {
208
+        foreach($_POST["const"] as $const)
209
+        {
210
+            if ($const["check"])	// Is checkbox checked
211
+            {
212
+                $langs->load("other");
213
+
214
+                // Remote file
215
+                $file=$const["file"];
216
+                $section=$const["section"];
217
+                $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
218
+                $newremotefileiso=utf8_decode($remotefile);
219
+
220
+                //print "x".$newremotefileiso;
221
+                dol_syslog("ftp/index.php ftp_delete ".$newremotefileiso);
222
+                $result=@ftp_delete($conn_id, $newremotefileiso);
223
+                if ($result)
224
+                {
225
+                    setEventMessages($langs->trans("FileWasRemoved",$file), null, 'mesgs');
226
+                }
227
+                else
228
+                {
229
+                    dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
230
+                    setEventMessages($langs->trans("FTPFailedToRemoveFile",$file), null, 'errors');
231
+                }
232
+
233
+                //ftp_close($conn_id);	Close later
234
+
235
+                $action='';
236
+            }
237
+        }
238
+    }
239
+    else
240
+    {
241
+        dol_print_error('',$mesg);
242
+    }
243 243
 }
244 244
 
245 245
 // Remove directory
246 246
 if ($action == 'confirm_deletesection' && $confirm == 'yes')
247 247
 {
248
-	// set up a connection or die
249
-	if (! $conn_id)
250
-	{
251
-		$newsectioniso=utf8_decode($section);
252
-		$resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
253
-		$conn_id=$resultarray['conn_id'];
254
-		$ok=$resultarray['ok'];
255
-		$mesg=$resultarray['mesg'];
256
-	}
257
-
258
-	if ($conn_id && $ok && ! $mesg)
259
-	{
260
-		// Remote file
261
-		$filename=$file;
262
-		$remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
263
-		$newremotefileiso=utf8_decode($remotefile);
264
-
265
-		$result=@ftp_rmdir($conn_id, $newremotefileiso);
266
-		if ($result)
267
-		{
268
-			setEventMessages($langs->trans("DirWasRemoved",$file), null, 'mesgs');
269
-		}
270
-		else
271
-		{
272
-			setEventMessages($langs->trans("FTPFailedToRemoveDir",$file), null, 'errors');
273
-		}
274
-
275
-		//ftp_close($conn_id);	Close later
248
+    // set up a connection or die
249
+    if (! $conn_id)
250
+    {
251
+        $newsectioniso=utf8_decode($section);
252
+        $resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
253
+        $conn_id=$resultarray['conn_id'];
254
+        $ok=$resultarray['ok'];
255
+        $mesg=$resultarray['mesg'];
256
+    }
276 257
 
277
-		$action='';
278
-	}
279
-	else
280
-	{
281
-		dol_print_error('',$mesg);
282
-	}
258
+    if ($conn_id && $ok && ! $mesg)
259
+    {
260
+        // Remote file
261
+        $filename=$file;
262
+        $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
263
+        $newremotefileiso=utf8_decode($remotefile);
264
+
265
+        $result=@ftp_rmdir($conn_id, $newremotefileiso);
266
+        if ($result)
267
+        {
268
+            setEventMessages($langs->trans("DirWasRemoved",$file), null, 'mesgs');
269
+        }
270
+        else
271
+        {
272
+            setEventMessages($langs->trans("FTPFailedToRemoveDir",$file), null, 'errors');
273
+        }
274
+
275
+        //ftp_close($conn_id);	Close later
276
+
277
+        $action='';
278
+    }
279
+    else
280
+    {
281
+        dol_print_error('',$mesg);
282
+    }
283 283
 }
284 284
 
285 285
 // Download directory
286 286
 if ($action == 'download')
287 287
 {
288
-	// set up a connection or die
289
-	if (! $conn_id)
290
-	{
291
-		$newsectioniso=utf8_decode($section);
292
-		$resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
293
-		$conn_id=$resultarray['conn_id'];
294
-		$ok=$resultarray['ok'];
295
-		$mesg=$resultarray['mesg'];
296
-	}
297
-
298
-	if ($conn_id && $ok && ! $mesg)
299
-	{
300
-		// Local file
301
-		$localfile=tempnam($download_dir,'dol_');
302
-
303
-		// Remote file
304
-		$filename=$file;
305
-		$remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
306
-		$newremotefileiso=utf8_decode($remotefile);
307
-
308
-		$result=ftp_get($conn_id,$localfile,$newremotefileiso,FTP_BINARY);
309
-		if ($result)
310
-		{
311
-			if (! empty($conf->global->MAIN_UMASK))
312
-			@chmod($localfile, octdec($conf->global->MAIN_UMASK));
313
-
314
-			// Define mime type
315
-			$type = 'application/octet-stream';
316
-			if (! empty($_GET["type"])) $type=$_GET["type"];
317
-			else $type=dol_mimetype($original_file);
318
-
319
-			// Define attachment (attachment=true to force choice popup 'open'/'save as')
320
-			$attachment = true;
321
-
322
-			if ($encoding)   header('Content-Encoding: '.$encoding);
323
-			if ($type)       header('Content-Type: '.$type);
324
-			if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
325
-			else header('Content-Disposition: inline; filename="'.$filename.'"');
326
-
327
-			// Ajout directives pour resoudre bug IE
328
-			header('Cache-Control: Public, must-revalidate');
329
-			header('Pragma: public');
330
-
331
-			readfile($localfile);
332
-
333
-			ftp_close($conn_id);
288
+    // set up a connection or die
289
+    if (! $conn_id)
290
+    {
291
+        $newsectioniso=utf8_decode($section);
292
+        $resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
293
+        $conn_id=$resultarray['conn_id'];
294
+        $ok=$resultarray['ok'];
295
+        $mesg=$resultarray['mesg'];
296
+    }
334 297
 
335
-			exit;
336
-		}
337
-		else
338
-		{
339
-			setEventMessages($langs->transnoentitiesnoconv('FailedToGetFile',$remotefile), null, 'errors');
340
-		}
341
-	}
342
-	else
343
-	{
344
-		dol_print_error('',$mesg);
345
-	}
298
+    if ($conn_id && $ok && ! $mesg)
299
+    {
300
+        // Local file
301
+        $localfile=tempnam($download_dir,'dol_');
302
+
303
+        // Remote file
304
+        $filename=$file;
305
+        $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
306
+        $newremotefileiso=utf8_decode($remotefile);
307
+
308
+        $result=ftp_get($conn_id,$localfile,$newremotefileiso,FTP_BINARY);
309
+        if ($result)
310
+        {
311
+            if (! empty($conf->global->MAIN_UMASK))
312
+            @chmod($localfile, octdec($conf->global->MAIN_UMASK));
313
+
314
+            // Define mime type
315
+            $type = 'application/octet-stream';
316
+            if (! empty($_GET["type"])) $type=$_GET["type"];
317
+            else $type=dol_mimetype($original_file);
318
+
319
+            // Define attachment (attachment=true to force choice popup 'open'/'save as')
320
+            $attachment = true;
321
+
322
+            if ($encoding)   header('Content-Encoding: '.$encoding);
323
+            if ($type)       header('Content-Type: '.$type);
324
+            if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
325
+            else header('Content-Disposition: inline; filename="'.$filename.'"');
326
+
327
+            // Ajout directives pour resoudre bug IE
328
+            header('Cache-Control: Public, must-revalidate');
329
+            header('Pragma: public');
330
+
331
+            readfile($localfile);
332
+
333
+            ftp_close($conn_id);
334
+
335
+            exit;
336
+        }
337
+        else
338
+        {
339
+            setEventMessages($langs->transnoentitiesnoconv('FailedToGetFile',$remotefile), null, 'errors');
340
+        }
341
+    }
342
+    else
343
+    {
344
+        dol_print_error('',$mesg);
345
+    }
346 346
 
347
-	//ftp_close($conn_id);	Close later
347
+    //ftp_close($conn_id);	Close later
348 348
 }
349 349
 
350 350
 
@@ -396,231 +396,231 @@  discard block
 block discarded – undo
396 396
 
397 397
 if (! function_exists('ftp_connect'))
398 398
 {
399
-	print $langs->trans("FTPFeatureNotSupportedByYourPHP");
399
+    print $langs->trans("FTPFeatureNotSupportedByYourPHP");
400 400
 }
401 401
 else
402 402
 {
403 403
     if (! empty($ftp_server))
404
-	{
405
-		// Confirm remove file
406
-		if ($action == 'delete')
407
-		{
408
-			print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode($_REQUEST["section"]).'&file='.urlencode($_GET["file"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1);
409
-		}
410
-
411
-		// Confirmation de la suppression d'une ligne categorie
412
-		if ($action == 'delete_section')
413
-		{
414
-			print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode($_REQUEST["section"]).'&file='.urlencode($_GET["file"]), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection','','',1);
415
-		}
416
-
417
-		print $langs->trans("Server").': <b>'.$ftp_server.'</b><br>';
418
-		print $langs->trans("Port").': <b>'.$ftp_port.'</b> '.($ftp_passive?"(Passive)":"(Active)").'<br>';
419
-		print $langs->trans("User").': <b>'.$ftp_user.'</b><br>';
404
+    {
405
+        // Confirm remove file
406
+        if ($action == 'delete')
407
+        {
408
+            print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode($_REQUEST["section"]).'&file='.urlencode($_GET["file"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1);
409
+        }
410
+
411
+        // Confirmation de la suppression d'une ligne categorie
412
+        if ($action == 'delete_section')
413
+        {
414
+            print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode($_REQUEST["section"]).'&file='.urlencode($_GET["file"]), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection','','',1);
415
+        }
416
+
417
+        print $langs->trans("Server").': <b>'.$ftp_server.'</b><br>';
418
+        print $langs->trans("Port").': <b>'.$ftp_port.'</b> '.($ftp_passive?"(Passive)":"(Active)").'<br>';
419
+        print $langs->trans("User").': <b>'.$ftp_user.'</b><br>';
420 420
         print $langs->trans("FTPs (FTP over SSH)").': <b>'.yn($conf->global->FTP_CONNECT_WITH_SSL).'</b><br>';
421 421
         print $langs->trans("SFTP (FTP as a subsytem of SSH)").': <b>'.yn($conf->global->FTP_CONNECT_WITH_SFTP).'</b><br>';
422 422
         print $langs->trans("Directory").': ';
423
-		$sectionarray=preg_split('|[\/]|',$section);
424
-		// For /
425
-		$newsection='/';
426
-		print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection?'&section='.urlencode($newsection):'').'">';
427
-		print '/';
428
-		print '</a> ';
429
-		// For other directories
430
-		$i=0;
431
-		foreach($sectionarray as $val)
432
-		{
433
-			if (empty($val)) continue;	// Discard first and last entry that should be empty as section start/end with /
434
-			if ($i > 0)
435
-			{
436
-				print ' / ';
437
-				$newsection.='/';
438
-			}
439
-			$newsection.=$val;
440
-			print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection?'&section='.urlencode($newsection):'').'">';
441
-			print $val;
442
-			print '</a>';
443
-			$i++;
444
-		}
445
-		print '<br>';
446
-		print "<br>\n";
447
-
448
-		print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
423
+        $sectionarray=preg_split('|[\/]|',$section);
424
+        // For /
425
+        $newsection='/';
426
+        print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection?'&section='.urlencode($newsection):'').'">';
427
+        print '/';
428
+        print '</a> ';
429
+        // For other directories
430
+        $i=0;
431
+        foreach($sectionarray as $val)
432
+        {
433
+            if (empty($val)) continue;	// Discard first and last entry that should be empty as section start/end with /
434
+            if ($i > 0)
435
+            {
436
+                print ' / ';
437
+                $newsection.='/';
438
+            }
439
+            $newsection.=$val;
440
+            print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection?'&section='.urlencode($newsection):'').'">';
441
+            print $val;
442
+            print '</a>';
443
+            $i++;
444
+        }
445
+        print '<br>';
446
+        print "<br>\n";
447
+
448
+        print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
449 449
         print '<input type="hidden" name="numero_ftp" value="'.$numero_ftp.'">';
450
-		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
451
-
452
-
453
-		// Construit liste des repertoires
454
-		print '<table width="100%" class="noborder">'."\n";
455
-
456
-		print '<tr class="liste_titre">'."\n";
457
-		print '<td class="liste_titre" align="left">'.$langs->trans("Content").'</td>'."\n";
458
-		print '<td class="liste_titre" align="center">'.$langs->trans("Size").'</td>'."\n";
459
-		print '<td class="liste_titre" align="center">'.$langs->trans("Date").'</td>'."\n";
460
-		print '<td class="liste_titre" align="center">'.$langs->trans("Owner").'</td>'."\n";
461
-		print '<td class="liste_titre" align="center">'.$langs->trans("Group").'</td>'."\n";
462
-		print '<td class="liste_titre" align="center">'.$langs->trans("Permissions").'</td>'."\n";
463
-		print '<td class="liste_titre nowrap" align="right">';
464
-		if ($conf->use_javascript_ajax) print '<a href="#" id="checkall">'.$langs->trans("All").'</a> / <a href="#" id="checknone">'.$langs->trans("None").'</a> ';
465
-		print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($section?'&section='.urlencode($section):'').'">'.img_picto($langs->trans("Refresh"),'refresh').'</a>&nbsp;';
466
-		print '</td>'."\n";
467
-		print '</tr>'."\n";
468
-
469
-		// set up a connection or die
470
-		if (empty($conn_id))
471
-		{
472
-			$resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive);
473
-
474
-			$conn_id=$resultarray['conn_id'];
475
-			$ok=$resultarray['ok'];
476
-			$mesg=$resultarray['mesg'];
477
-		}
478
-
479
-		if ($ok)
480
-		{
481
-			//$type = ftp_systype($conn_id);
482
-
483
-			$newsection=$section;
484
-		    $newsectioniso=utf8_decode($section);
485
-			//$newsection='/home';
486
-
487
-			// List content of directory ($newsection = '/', '/home', ...)
488
-			if (! empty($conf->global->FTP_CONNECT_WITH_SFTP))
489
-			{
490
-			    if ($newsection == '/') $newsection='/./';  // workaround for bug https://bugs.php.net/bug.php?id=64169
491
-			    //$dirHandle = opendir("ssh2.sftp://$conn_id".$newsection);
492
-			    //var_dump($dirHandle);
450
+        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
451
+
452
+
453
+        // Construit liste des repertoires
454
+        print '<table width="100%" class="noborder">'."\n";
455
+
456
+        print '<tr class="liste_titre">'."\n";
457
+        print '<td class="liste_titre" align="left">'.$langs->trans("Content").'</td>'."\n";
458
+        print '<td class="liste_titre" align="center">'.$langs->trans("Size").'</td>'."\n";
459
+        print '<td class="liste_titre" align="center">'.$langs->trans("Date").'</td>'."\n";
460
+        print '<td class="liste_titre" align="center">'.$langs->trans("Owner").'</td>'."\n";
461
+        print '<td class="liste_titre" align="center">'.$langs->trans("Group").'</td>'."\n";
462
+        print '<td class="liste_titre" align="center">'.$langs->trans("Permissions").'</td>'."\n";
463
+        print '<td class="liste_titre nowrap" align="right">';
464
+        if ($conf->use_javascript_ajax) print '<a href="#" id="checkall">'.$langs->trans("All").'</a> / <a href="#" id="checknone">'.$langs->trans("None").'</a> ';
465
+        print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($section?'&section='.urlencode($section):'').'">'.img_picto($langs->trans("Refresh"),'refresh').'</a>&nbsp;';
466
+        print '</td>'."\n";
467
+        print '</tr>'."\n";
468
+
469
+        // set up a connection or die
470
+        if (empty($conn_id))
471
+        {
472
+            $resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive);
473
+
474
+            $conn_id=$resultarray['conn_id'];
475
+            $ok=$resultarray['ok'];
476
+            $mesg=$resultarray['mesg'];
477
+        }
478
+
479
+        if ($ok)
480
+        {
481
+            //$type = ftp_systype($conn_id);
482
+
483
+            $newsection=$section;
484
+            $newsectioniso=utf8_decode($section);
485
+            //$newsection='/home';
486
+
487
+            // List content of directory ($newsection = '/', '/home', ...)
488
+            if (! empty($conf->global->FTP_CONNECT_WITH_SFTP))
489
+            {
490
+                if ($newsection == '/') $newsection='/./';  // workaround for bug https://bugs.php.net/bug.php?id=64169
491
+                //$dirHandle = opendir("ssh2.sftp://$conn_id".$newsection);
492
+                //var_dump($dirHandle);
493 493
                 $contents = scandir('ssh2.sftp://' . $conn_id . $newsection);
494 494
                 $buff=array();
495 495
                 foreach($contents as $i => $key)
496 496
                 {
497 497
                     $buff[$i]="---------- - root root 1234 Aug 01 2000 ".$key;
498 498
                 }
499
-    		}
500
-    		else
501
-    		{
499
+            }
500
+            else
501
+            {
502 502
                 $buff = ftp_rawlist($conn_id, $newsectioniso);
503 503
                 $contents = ftp_nlist($conn_id, $newsectioniso);	// Sometimes rawlist fails but never nlist
504
-        		//var_dump($contents);
505
-		        //var_dump($buff);
506
-    		}
507
-
508
-			$nboflines=count($contents);
509
-			$rawlisthasfailed=false;
510
-			$i=0;
511
-			while ($i < $nboflines && $i < 1000)
512
-			{
513
-				$vals=preg_split('@ +@',utf8_encode($buff[$i]),9);
514
-				//$vals=preg_split('@ +@','drwxr-xr-x 2 root root 4096 Aug 30 2008 backup_apollon1',9);
515
-				//var_dump($vals);
516
-				$file=$vals[8];
517
-				if (empty($file))
518
-				{
519
-					$rawlisthasfailed=true;
520
-					$file=utf8_encode($contents[$i]);
521
-				}
522
-
523
-				if ($file == '.' || ($file == '..' && $section == '/'))
524
-				{
525
-					$i++;
526
-					continue;
527
-				}
528
-
529
-				// Is it a directory ?
530
-				$is_directory=0;
531
-				if ($file == '..') $is_directory=1;
532
-				else if (! $rawlisthasfailed)
533
-				{
534
-					if (preg_match('/^d/',$vals[0])) $is_directory=1;
535
-					if (preg_match('/^l/',$vals[0])) $is_link=1;
536
-				}
537
-				else
538
-				{
539
-					// Remote file
540
-					$filename=$file;
541
-					//print "section=".$section.' file='.$file.'X';
542
-					//print preg_match('@[\/]$@','aaa/').'Y';
543
-					//print preg_match('@[\\\/]$@',"aaa\\").'Y';
544
-					$remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').preg_replace('@^[\\\/]@','',$file);
545
-					//print 'A'.$remotefile.'A';
546
-					$newremotefileiso=utf8_decode($remotefile);
547
-					//print 'Z'.$newremotefileiso.'Z';
548
-					$is_directory=ftp_isdir($conn_id, $newremotefileiso);
549
-				}
550
-
551
-
552
-				print '<tr class="oddeven" height="18">';
553
-				// Name
554
-				print '<td>';
555
-				$newsection=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
556
-				$newsection=preg_replace('@[\\\/][^\\\/]+[\\\/]\.\.$@','/',$newsection);	// Change aaa/xxx/.. to new aaa
557
-				if ($is_directory) print '<a href="'.$_SERVER["PHP_SELF"].'?section='.urlencode($newsection).'&numero_ftp='.$numero_ftp.'">';
558
-				print $file;
559
-				if ($is_directory) print '</a>';
560
-				print '</td>';
561
-				// Size
562
-				print '<td align="center" class="nowrap">';
563
-				if (! $is_directory && ! $is_link) print $vals[4];
564
-				else print '&nbsp;';
565
-				print '</td>';
566
-				// Date
567
-				print '<td align="center" class="nowrap">';
568
-				print $vals[5].' '.$vals[6].' '.$vals[7];
569
-				print '</td>';
570
-				// User
571
-				print '<td align="center" class="nowrap">';
572
-				print $vals[2];
573
-				print '</td>';
574
-				// Group
575
-				print '<td align="center" class="nowrap">';
576
-				print $vals[3];
577
-				print '</td>';
578
-				// Permissions
579
-				print '<td align="center" class="nowrap">';
580
-				print $vals[0];
581
-				print '</td>';
582
-				// Action
583
-				print '<td align="right" width="64" class="nowrap">';
584
-				if ($is_directory)
585
-				{
586
-					if ($file != '..') print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete_section&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
587
-					else print '&nbsp;';
588
-				}
589
-				else if ($is_link)
590
-				{
591
-					$newfile=$file;
592
-					$newfile=preg_replace('/ ->.*/','',$newfile);
593
-					print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($newfile).'">'.img_delete().'</a>';
594
-				}
595
-				else
596
-				{
597
-					print '<a href="'.$_SERVER["PHP_SELF"].'?action=download&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_picto('','file').'</a>';
598
-					print ' &nbsp; ';
599
-					print '<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.'" name="const['.$i.'][check]" value="1">';
600
-					print ' &nbsp; ';
601
-					print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
602
-					print '<input type="hidden" name="const['.$i.'][section]" value="'.$section.'">';
603
-					print '<input type="hidden" name="const['.$i.'][file]" value="'.$file.'">';
604
-				}
605
-				print '</td>';
606
-				print '</tr>'."\n";
607
-				$i++;
608
-				$nbofentries++;
609
-			}
610
-		}
504
+                //var_dump($contents);
505
+                //var_dump($buff);
506
+            }
507
+
508
+            $nboflines=count($contents);
509
+            $rawlisthasfailed=false;
510
+            $i=0;
511
+            while ($i < $nboflines && $i < 1000)
512
+            {
513
+                $vals=preg_split('@ +@',utf8_encode($buff[$i]),9);
514
+                //$vals=preg_split('@ +@','drwxr-xr-x 2 root root 4096 Aug 30 2008 backup_apollon1',9);
515
+                //var_dump($vals);
516
+                $file=$vals[8];
517
+                if (empty($file))
518
+                {
519
+                    $rawlisthasfailed=true;
520
+                    $file=utf8_encode($contents[$i]);
521
+                }
611 522
 
612
-		print "</table>";
523
+                if ($file == '.' || ($file == '..' && $section == '/'))
524
+                {
525
+                    $i++;
526
+                    continue;
527
+                }
613 528
 
529
+                // Is it a directory ?
530
+                $is_directory=0;
531
+                if ($file == '..') $is_directory=1;
532
+                else if (! $rawlisthasfailed)
533
+                {
534
+                    if (preg_match('/^d/',$vals[0])) $is_directory=1;
535
+                    if (preg_match('/^l/',$vals[0])) $is_link=1;
536
+                }
537
+                else
538
+                {
539
+                    // Remote file
540
+                    $filename=$file;
541
+                    //print "section=".$section.' file='.$file.'X';
542
+                    //print preg_match('@[\/]$@','aaa/').'Y';
543
+                    //print preg_match('@[\\\/]$@',"aaa\\").'Y';
544
+                    $remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').preg_replace('@^[\\\/]@','',$file);
545
+                    //print 'A'.$remotefile.'A';
546
+                    $newremotefileiso=utf8_decode($remotefile);
547
+                    //print 'Z'.$newremotefileiso.'Z';
548
+                    $is_directory=ftp_isdir($conn_id, $newremotefileiso);
549
+                }
614 550
 
615
-		if (! $ok)
616
-		{
617
-		      print $mesg.'<br>'."\n";
618
-		      setEventMessages($mesg, null, 'errors');
619
-		}
551
+
552
+                print '<tr class="oddeven" height="18">';
553
+                // Name
554
+                print '<td>';
555
+                $newsection=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
556
+                $newsection=preg_replace('@[\\\/][^\\\/]+[\\\/]\.\.$@','/',$newsection);	// Change aaa/xxx/.. to new aaa
557
+                if ($is_directory) print '<a href="'.$_SERVER["PHP_SELF"].'?section='.urlencode($newsection).'&numero_ftp='.$numero_ftp.'">';
558
+                print $file;
559
+                if ($is_directory) print '</a>';
560
+                print '</td>';
561
+                // Size
562
+                print '<td align="center" class="nowrap">';
563
+                if (! $is_directory && ! $is_link) print $vals[4];
564
+                else print '&nbsp;';
565
+                print '</td>';
566
+                // Date
567
+                print '<td align="center" class="nowrap">';
568
+                print $vals[5].' '.$vals[6].' '.$vals[7];
569
+                print '</td>';
570
+                // User
571
+                print '<td align="center" class="nowrap">';
572
+                print $vals[2];
573
+                print '</td>';
574
+                // Group
575
+                print '<td align="center" class="nowrap">';
576
+                print $vals[3];
577
+                print '</td>';
578
+                // Permissions
579
+                print '<td align="center" class="nowrap">';
580
+                print $vals[0];
581
+                print '</td>';
582
+                // Action
583
+                print '<td align="right" width="64" class="nowrap">';
584
+                if ($is_directory)
585
+                {
586
+                    if ($file != '..') print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete_section&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
587
+                    else print '&nbsp;';
588
+                }
589
+                else if ($is_link)
590
+                {
591
+                    $newfile=$file;
592
+                    $newfile=preg_replace('/ ->.*/','',$newfile);
593
+                    print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($newfile).'">'.img_delete().'</a>';
594
+                }
595
+                else
596
+                {
597
+                    print '<a href="'.$_SERVER["PHP_SELF"].'?action=download&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_picto('','file').'</a>';
598
+                    print ' &nbsp; ';
599
+                    print '<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.'" name="const['.$i.'][check]" value="1">';
600
+                    print ' &nbsp; ';
601
+                    print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
602
+                    print '<input type="hidden" name="const['.$i.'][section]" value="'.$section.'">';
603
+                    print '<input type="hidden" name="const['.$i.'][file]" value="'.$file.'">';
604
+                }
605
+                print '</td>';
606
+                print '</tr>'."\n";
607
+                $i++;
608
+                $nbofentries++;
609
+            }
610
+        }
611
+
612
+        print "</table>";
613
+
614
+
615
+        if (! $ok)
616
+        {
617
+                print $mesg.'<br>'."\n";
618
+                setEventMessages($mesg, null, 'errors');
619
+        }
620 620
 
621 621
 
622
-		// Actions
623
-		/*
622
+        // Actions
623
+        /*
624 624
 		if ($user->rights->ftp->write && ! empty($section))
625 625
 		{
626 626
 		$formfile->form_attach_new_file(DOL_URL_ROOT.'/ftp/index.php','',0,$section,1);
@@ -628,38 +628,38 @@  discard block
 block discarded – undo
628 628
 		else print '&nbsp;';
629 629
 		*/
630 630
 
631
-		print '<br>';
632
-		print '<div id="delconst" align="right">';
633
-		print '<input type="submit" name="delete" class="button" value="'.$langs->trans("Delete").'">';
634
-		print '</div>';
635
-
636
-		print "</form>";
637
-	}
638
-	else
639
-	{
640
-		$foundsetup=false;
641
-		$MAXFTP=20;
642
-		$i=1;
643
-		while ($i <= $MAXFTP)
644
-		{
645
-			$paramkey='FTP_NAME_'.$i;
646
-			//print $paramkey;
647
-			if (! empty($conf->global->$paramkey))
648
-			{
649
-				$foundsetup=true;
650
-				break;
651
-			}
652
-			$i++;
653
-		}
654
-	    if (! $foundsetup)
655
-	    {
631
+        print '<br>';
632
+        print '<div id="delconst" align="right">';
633
+        print '<input type="submit" name="delete" class="button" value="'.$langs->trans("Delete").'">';
634
+        print '</div>';
635
+
636
+        print "</form>";
637
+    }
638
+    else
639
+    {
640
+        $foundsetup=false;
641
+        $MAXFTP=20;
642
+        $i=1;
643
+        while ($i <= $MAXFTP)
644
+        {
645
+            $paramkey='FTP_NAME_'.$i;
646
+            //print $paramkey;
647
+            if (! empty($conf->global->$paramkey))
648
+            {
649
+                $foundsetup=true;
650
+                break;
651
+            }
652
+            $i++;
653
+        }
654
+        if (! $foundsetup)
655
+        {
656 656
             print $langs->trans("SetupOfFTPClientModuleNotComplete");
657
-	    }
658
-	    else
659
-	    {
660
-	        print $langs->trans("ChooseAFTPEntryIntoMenu");
661
-	    }
662
-	}
657
+        }
658
+        else
659
+        {
660
+            print $langs->trans("ChooseAFTPEntryIntoMenu");
661
+        }
662
+    }
663 663
 }
664 664
 
665 665
 print '<br>';
@@ -700,94 +700,94 @@  discard block
 block discarded – undo
700 700
  */
701 701
 function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive=0)
702 702
 {
703
-	global $langs, $conf;
703
+    global $langs, $conf;
704 704
 
705
-	$ok=1;
705
+    $ok=1;
706 706
     $conn_id=null;
707 707
 
708
-	if (! is_numeric($ftp_port))
709
-	{
710
-		$mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServer",$ftp_server,$ftp_port);
711
-		$ok=0;
712
-	}
708
+    if (! is_numeric($ftp_port))
709
+    {
710
+        $mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServer",$ftp_server,$ftp_port);
711
+        $ok=0;
712
+    }
713 713
 
714
-	if ($ok)
715
-	{
716
-		$connecttimeout=(empty($conf->global->FTP_CONNECT_TIMEOUT)?40:$conf->global->FTP_CONNECT_TIMEOUT);
717
-		if (! empty($conf->global->FTP_CONNECT_WITH_SFTP))
718
-		{
719
-		    dol_syslog('Try to connect with ssh2_ftp');
720
-		    $tmp_conn_id = ssh2_connect($ftp_server, $ftp_port);
721
-		}
722
-		else if (! empty($conf->global->FTP_CONNECT_WITH_SSL))
723
-		{
724
-		    dol_syslog('Try to connect with ftp_ssl_connect');
725
-		    $conn_id = ftp_ssl_connect($ftp_server, $ftp_port, $connecttimeout);
726
-		}
727
-		else
728
-		{
729
-		    dol_syslog('Try to connect with ftp_connect');
730
-		    $conn_id = ftp_connect($ftp_server, $ftp_port, $connecttimeout);
731
-		}
732
-		if ($conn_id || $tmp_conn_id)
733
-		{
734
-			if ($ftp_user)
735
-			{
736
-				if (! empty($conf->global->FTP_CONNECT_WITH_SFTP))
737
-				{
738
-				    if (ssh2_auth_password($tmp_conn_id, $ftp_user, $ftp_password))
739
-    				{
740
-    					// Turn on passive mode transfers (must be after a successful login
741
-    					//if ($ftp_passive) ftp_pasv($conn_id, true);
742
-
743
-    					// Change the dir
744
-    					$newsectioniso=utf8_decode($section);
745
-    					//ftp_chdir($conn_id, $newsectioniso);
746
-		                $conn_id = ssh2_sftp($tmp_conn_id);
747
-		                if (! $conn_id)
748
-		                {
749
-        					$mesg=$langs->transnoentitiesnoconv("FailedToConnectToSFTPAfterSSHAuthentication");
750
-    	   				    $ok=0;
751
-        				    $error++;
752
-		                }
753
-    				}
754
-    				else
755
-    				{
756
-    					$mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials");
757
-	   				    $ok=0;
758
-    				    $error++;
759
-    				}
760
-				}
761
-				else
762
-				{
763
-				    if (ftp_login($conn_id, $ftp_user, $ftp_password))
764
-    				{
765
-    					// Turn on passive mode transfers (must be after a successful login
766
-    					if ($ftp_passive) ftp_pasv($conn_id, true);
767
-
768
-    					// Change the dir
769
-    					$newsectioniso=utf8_decode($section);
770
-    					ftp_chdir($conn_id, $newsectioniso);
771
-    				}
772
-    				else
773
-    				{
774
-    					$mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials");
775
-	   				    $ok=0;
776
-    				    $error++;
777
-    				}
778
-				}
779
-			}
780
-		}
781
-		else
782
-		{
783
-		    dol_syslog('FailedToConnectToFTPServer '.$ftp_server.' '.$ftp_port, LOG_ERR);
784
-			$mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServer",$ftp_server,$ftp_port);
785
-			$ok=0;
786
-		}
787
-	}
714
+    if ($ok)
715
+    {
716
+        $connecttimeout=(empty($conf->global->FTP_CONNECT_TIMEOUT)?40:$conf->global->FTP_CONNECT_TIMEOUT);
717
+        if (! empty($conf->global->FTP_CONNECT_WITH_SFTP))
718
+        {
719
+            dol_syslog('Try to connect with ssh2_ftp');
720
+            $tmp_conn_id = ssh2_connect($ftp_server, $ftp_port);
721
+        }
722
+        else if (! empty($conf->global->FTP_CONNECT_WITH_SSL))
723
+        {
724
+            dol_syslog('Try to connect with ftp_ssl_connect');
725
+            $conn_id = ftp_ssl_connect($ftp_server, $ftp_port, $connecttimeout);
726
+        }
727
+        else
728
+        {
729
+            dol_syslog('Try to connect with ftp_connect');
730
+            $conn_id = ftp_connect($ftp_server, $ftp_port, $connecttimeout);
731
+        }
732
+        if ($conn_id || $tmp_conn_id)
733
+        {
734
+            if ($ftp_user)
735
+            {
736
+                if (! empty($conf->global->FTP_CONNECT_WITH_SFTP))
737
+                {
738
+                    if (ssh2_auth_password($tmp_conn_id, $ftp_user, $ftp_password))
739
+                    {
740
+                        // Turn on passive mode transfers (must be after a successful login
741
+                        //if ($ftp_passive) ftp_pasv($conn_id, true);
742
+
743
+                        // Change the dir
744
+                        $newsectioniso=utf8_decode($section);
745
+                        //ftp_chdir($conn_id, $newsectioniso);
746
+                        $conn_id = ssh2_sftp($tmp_conn_id);
747
+                        if (! $conn_id)
748
+                        {
749
+                            $mesg=$langs->transnoentitiesnoconv("FailedToConnectToSFTPAfterSSHAuthentication");
750
+                                $ok=0;
751
+                            $error++;
752
+                        }
753
+                    }
754
+                    else
755
+                    {
756
+                        $mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials");
757
+                            $ok=0;
758
+                        $error++;
759
+                    }
760
+                }
761
+                else
762
+                {
763
+                    if (ftp_login($conn_id, $ftp_user, $ftp_password))
764
+                    {
765
+                        // Turn on passive mode transfers (must be after a successful login
766
+                        if ($ftp_passive) ftp_pasv($conn_id, true);
767
+
768
+                        // Change the dir
769
+                        $newsectioniso=utf8_decode($section);
770
+                        ftp_chdir($conn_id, $newsectioniso);
771
+                    }
772
+                    else
773
+                    {
774
+                        $mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials");
775
+                            $ok=0;
776
+                        $error++;
777
+                    }
778
+                }
779
+            }
780
+        }
781
+        else
782
+        {
783
+            dol_syslog('FailedToConnectToFTPServer '.$ftp_server.' '.$ftp_port, LOG_ERR);
784
+            $mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServer",$ftp_server,$ftp_port);
785
+            $ok=0;
786
+        }
787
+    }
788 788
 
789
-	$arrayresult=array('conn_id'=>$conn_id, 'ok'=>$ok, 'mesg'=>$mesg, 'curdir'=>$section, 'curdiriso'=>$newsectioniso);
790
-	return $arrayresult;
789
+    $arrayresult=array('conn_id'=>$conn_id, 'ok'=>$ok, 'mesg'=>$mesg, 'curdir'=>$section, 'curdiriso'=>$newsectioniso);
790
+    return $arrayresult;
791 791
 }
792 792
 
793 793
 
@@ -800,14 +800,14 @@  discard block
 block discarded – undo
800 800
  */
801 801
 function ftp_isdir($connect_id,$dir)
802 802
 {
803
-	if (@ftp_chdir($connect_id,$dir))
804
-	{
805
-		ftp_cdup($connect_id);
806
-		return 1;
807
-	}
808
-	else
809
-	{
810
-		return 0;
811
-	}
803
+    if (@ftp_chdir($connect_id,$dir))
804
+    {
805
+        ftp_cdup($connect_id);
806
+        return 1;
807
+    }
808
+    else
809
+    {
810
+        return 0;
811
+    }
812 812
 }
813 813
 
Please login to merge, or discard this patch.
Braces   +108 added lines, -85 removed lines patch added patch discarded remove patch
@@ -31,13 +31,17 @@  discard block
 block discarded – undo
31 31
 $langs->loadLangs(array('ftp', 'companies', 'other'));
32 32
 
33 33
 // Security check
34
-if ($user->societe_id) $socid=$user->societe_id;
34
+if ($user->societe_id) {
35
+    $socid=$user->societe_id;
36
+}
35 37
 $result = restrictedArea($user, 'ftp','');
36 38
 
37 39
 // Get parameters
38 40
 $action=GETPOST('action','aZ09');
39 41
 $section=GETPOST('section');
40
-if (! $section) $section='/';
42
+if (! $section) {
43
+    $section='/';
44
+}
41 45
 $numero_ftp = GETPOST("numero_ftp");
42 46
 /* if (! $numero_ftp) $numero_ftp=1; */
43 47
 $file=GETPOST("file");
@@ -53,8 +57,12 @@  discard block
 block discarded – undo
53 57
 $offset = $conf->liste_limit * $page;
54 58
 $pageprev = $page - 1;
55 59
 $pagenext = $page + 1;
56
-if (! $sortorder) $sortorder="ASC";
57
-if (! $sortfield) $sortfield="label";
60
+if (! $sortorder) {
61
+    $sortorder="ASC";
62
+}
63
+if (! $sortfield) {
64
+    $sortfield="label";
65
+}
58 66
 
59 67
 $s_ftp_name='FTP_NAME_'.$numero_ftp;
60 68
 $s_ftp_server='FTP_SERVER_'.$numero_ftp;
@@ -64,7 +72,9 @@  discard block
 block discarded – undo
64 72
 $s_ftp_passive='FTP_PASSIVE_'.$numero_ftp;
65 73
 $ftp_name=$conf->global->$s_ftp_name;
66 74
 $ftp_server=$conf->global->$s_ftp_server;
67
-$ftp_port=$conf->global->$s_ftp_port; if (empty($ftp_port)) $ftp_port=21;
75
+$ftp_port=$conf->global->$s_ftp_port; if (empty($ftp_port)) {
76
+    $ftp_port=21;
77
+}
68 78
 $ftp_user=$conf->global->$s_ftp_user;
69 79
 $ftp_password=$conf->global->$s_ftp_password;
70 80
 $ftp_passive=$conf->global->$s_ftp_passive;
@@ -100,24 +110,24 @@  discard block
 block discarded – undo
100 110
 		if (is_numeric($resupload) && $resupload > 0)
101 111
 		{
102 112
 			$result=$ecmdir->changeNbOfFiles('+');
103
-		}
104
-		else {
113
+		} else {
105 114
 			$langs->load("errors");
106
-			if ($resupload < 0)	// Unknown error
115
+			if ($resupload < 0) {
116
+			    // Unknown error
107 117
 			{
108 118
 				setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors');
109 119
 			}
110
-			else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload))	// Files infected by a virus
120
+			} else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) {
121
+			    // Files infected by a virus
111 122
 			{
112 123
 				setEventMessages($langs->trans("ErrorFileIsInfectedWithAVirus"), null, 'errors');
113 124
 			}
114
-			else	// Known error
125
+			} else	// Known error
115 126
 			{
116 127
 				setEventMessages($langs->trans($resupload), null, 'errors');
117 128
 			}
118 129
 		}
119
-	}
120
-	else
130
+	} else
121 131
 	{
122 132
 		// Echec transfert (fichier depassant la limite ?)
123 133
 		$langs->load("errors");
@@ -137,8 +147,7 @@  discard block
 block discarded – undo
137 147
 	{
138 148
 		header("Location: ".$_SERVER["PHP_SELF"]);
139 149
 		exit;
140
-	}
141
-	else
150
+	} else
142 151
 	{
143 152
 		setEventMessages($langs->trans("ErrorFailToCreateDir"), null, 'errors');
144 153
 		$action = "create";
@@ -173,8 +182,7 @@  discard block
 block discarded – undo
173 182
 		if ($result)
174 183
 		{
175 184
 			setEventMessages($langs->trans("FileWasRemoved",$file), null, 'mesgs');
176
-		}
177
-		else
185
+		} else
178 186
 		{
179 187
 			dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
180 188
 			setEventMessages($langs->trans("FTPFailedToRemoveFile",$file), null, 'errors');
@@ -183,8 +191,7 @@  discard block
 block discarded – undo
183 191
 		//ftp_close($conn_id);	Close later
184 192
 
185 193
 		$action='';
186
-	}
187
-	else
194
+	} else
188 195
 	{
189 196
 		dol_print_error('',$mesg);
190 197
 	}
@@ -207,9 +214,11 @@  discard block
 block discarded – undo
207 214
 	{
208 215
 		foreach($_POST["const"] as $const)
209 216
 		{
210
-			if ($const["check"])	// Is checkbox checked
217
+			if ($const["check"]) {
218
+			    // Is checkbox checked
211 219
 			{
212 220
 			    $langs->load("other");
221
+			}
213 222
 
214 223
 				// Remote file
215 224
 				$file=$const["file"];
@@ -223,8 +232,7 @@  discard block
 block discarded – undo
223 232
 				if ($result)
224 233
 				{
225 234
 					setEventMessages($langs->trans("FileWasRemoved",$file), null, 'mesgs');
226
-				}
227
-				else
235
+				} else
228 236
 				{
229 237
 					dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
230 238
 					setEventMessages($langs->trans("FTPFailedToRemoveFile",$file), null, 'errors');
@@ -235,8 +243,7 @@  discard block
 block discarded – undo
235 243
 				$action='';
236 244
 			}
237 245
 		}
238
-	}
239
-	else
246
+	} else
240 247
 	{
241 248
 		dol_print_error('',$mesg);
242 249
 	}
@@ -266,8 +273,7 @@  discard block
 block discarded – undo
266 273
 		if ($result)
267 274
 		{
268 275
 			setEventMessages($langs->trans("DirWasRemoved",$file), null, 'mesgs');
269
-		}
270
-		else
276
+		} else
271 277
 		{
272 278
 			setEventMessages($langs->trans("FTPFailedToRemoveDir",$file), null, 'errors');
273 279
 		}
@@ -275,8 +281,7 @@  discard block
 block discarded – undo
275 281
 		//ftp_close($conn_id);	Close later
276 282
 
277 283
 		$action='';
278
-	}
279
-	else
284
+	} else
280 285
 	{
281 286
 		dol_print_error('',$mesg);
282 287
 	}
@@ -308,21 +313,32 @@  discard block
 block discarded – undo
308 313
 		$result=ftp_get($conn_id,$localfile,$newremotefileiso,FTP_BINARY);
309 314
 		if ($result)
310 315
 		{
311
-			if (! empty($conf->global->MAIN_UMASK))
312
-			@chmod($localfile, octdec($conf->global->MAIN_UMASK));
316
+			if (! empty($conf->global->MAIN_UMASK)) {
317
+						@chmod($localfile, octdec($conf->global->MAIN_UMASK));
318
+			}
313 319
 
314 320
 			// Define mime type
315 321
 			$type = 'application/octet-stream';
316
-			if (! empty($_GET["type"])) $type=$_GET["type"];
317
-			else $type=dol_mimetype($original_file);
322
+			if (! empty($_GET["type"])) {
323
+			    $type=$_GET["type"];
324
+			} else {
325
+			    $type=dol_mimetype($original_file);
326
+			}
318 327
 
319 328
 			// Define attachment (attachment=true to force choice popup 'open'/'save as')
320 329
 			$attachment = true;
321 330
 
322
-			if ($encoding)   header('Content-Encoding: '.$encoding);
323
-			if ($type)       header('Content-Type: '.$type);
324
-			if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
325
-			else header('Content-Disposition: inline; filename="'.$filename.'"');
331
+			if ($encoding) {
332
+			    header('Content-Encoding: '.$encoding);
333
+			}
334
+			if ($type) {
335
+			    header('Content-Type: '.$type);
336
+			}
337
+			if ($attachment) {
338
+			    header('Content-Disposition: attachment; filename="'.$filename.'"');
339
+			} else {
340
+			    header('Content-Disposition: inline; filename="'.$filename.'"');
341
+			}
326 342
 
327 343
 			// Ajout directives pour resoudre bug IE
328 344
 			header('Cache-Control: Public, must-revalidate');
@@ -333,13 +349,11 @@  discard block
 block discarded – undo
333 349
 			ftp_close($conn_id);
334 350
 
335 351
 			exit;
336
-		}
337
-		else
352
+		} else
338 353
 		{
339 354
 			setEventMessages($langs->transnoentitiesnoconv('FailedToGetFile',$remotefile), null, 'errors');
340 355
 		}
341
-	}
342
-	else
356
+	} else
343 357
 	{
344 358
 		dol_print_error('',$mesg);
345 359
 	}
@@ -397,8 +411,7 @@  discard block
 block discarded – undo
397 411
 if (! function_exists('ftp_connect'))
398 412
 {
399 413
 	print $langs->trans("FTPFeatureNotSupportedByYourPHP");
400
-}
401
-else
414
+} else
402 415
 {
403 416
     if (! empty($ftp_server))
404 417
 	{
@@ -430,7 +443,10 @@  discard block
 block discarded – undo
430 443
 		$i=0;
431 444
 		foreach($sectionarray as $val)
432 445
 		{
433
-			if (empty($val)) continue;	// Discard first and last entry that should be empty as section start/end with /
446
+			if (empty($val)) {
447
+			    continue;
448
+			}
449
+			// Discard first and last entry that should be empty as section start/end with /
434 450
 			if ($i > 0)
435 451
 			{
436 452
 				print ' / ';
@@ -461,7 +477,9 @@  discard block
 block discarded – undo
461 477
 		print '<td class="liste_titre" align="center">'.$langs->trans("Group").'</td>'."\n";
462 478
 		print '<td class="liste_titre" align="center">'.$langs->trans("Permissions").'</td>'."\n";
463 479
 		print '<td class="liste_titre nowrap" align="right">';
464
-		if ($conf->use_javascript_ajax) print '<a href="#" id="checkall">'.$langs->trans("All").'</a> / <a href="#" id="checknone">'.$langs->trans("None").'</a> ';
480
+		if ($conf->use_javascript_ajax) {
481
+		    print '<a href="#" id="checkall">'.$langs->trans("All").'</a> / <a href="#" id="checknone">'.$langs->trans("None").'</a> ';
482
+		}
465 483
 		print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($section?'&section='.urlencode($section):'').'">'.img_picto($langs->trans("Refresh"),'refresh').'</a>&nbsp;';
466 484
 		print '</td>'."\n";
467 485
 		print '</tr>'."\n";
@@ -487,7 +505,10 @@  discard block
 block discarded – undo
487 505
 			// List content of directory ($newsection = '/', '/home', ...)
488 506
 			if (! empty($conf->global->FTP_CONNECT_WITH_SFTP))
489 507
 			{
490
-			    if ($newsection == '/') $newsection='/./';  // workaround for bug https://bugs.php.net/bug.php?id=64169
508
+			    if ($newsection == '/') {
509
+			        $newsection='/./';
510
+			    }
511
+			    // workaround for bug https://bugs.php.net/bug.php?id=64169
491 512
 			    //$dirHandle = opendir("ssh2.sftp://$conn_id".$newsection);
492 513
 			    //var_dump($dirHandle);
493 514
                 $contents = scandir('ssh2.sftp://' . $conn_id . $newsection);
@@ -496,8 +517,7 @@  discard block
 block discarded – undo
496 517
                 {
497 518
                     $buff[$i]="---------- - root root 1234 Aug 01 2000 ".$key;
498 519
                 }
499
-    		}
500
-    		else
520
+    		} else
501 521
     		{
502 522
                 $buff = ftp_rawlist($conn_id, $newsectioniso);
503 523
                 $contents = ftp_nlist($conn_id, $newsectioniso);	// Sometimes rawlist fails but never nlist
@@ -528,13 +548,17 @@  discard block
 block discarded – undo
528 548
 
529 549
 				// Is it a directory ?
530 550
 				$is_directory=0;
531
-				if ($file == '..') $is_directory=1;
532
-				else if (! $rawlisthasfailed)
551
+				if ($file == '..') {
552
+				    $is_directory=1;
553
+				} else if (! $rawlisthasfailed)
533 554
 				{
534
-					if (preg_match('/^d/',$vals[0])) $is_directory=1;
535
-					if (preg_match('/^l/',$vals[0])) $is_link=1;
536
-				}
537
-				else
555
+					if (preg_match('/^d/',$vals[0])) {
556
+					    $is_directory=1;
557
+					}
558
+					if (preg_match('/^l/',$vals[0])) {
559
+					    $is_link=1;
560
+					}
561
+				} else
538 562
 				{
539 563
 					// Remote file
540 564
 					$filename=$file;
@@ -554,14 +578,21 @@  discard block
 block discarded – undo
554 578
 				print '<td>';
555 579
 				$newsection=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
556 580
 				$newsection=preg_replace('@[\\\/][^\\\/]+[\\\/]\.\.$@','/',$newsection);	// Change aaa/xxx/.. to new aaa
557
-				if ($is_directory) print '<a href="'.$_SERVER["PHP_SELF"].'?section='.urlencode($newsection).'&numero_ftp='.$numero_ftp.'">';
581
+				if ($is_directory) {
582
+				    print '<a href="'.$_SERVER["PHP_SELF"].'?section='.urlencode($newsection).'&numero_ftp='.$numero_ftp.'">';
583
+				}
558 584
 				print $file;
559
-				if ($is_directory) print '</a>';
585
+				if ($is_directory) {
586
+				    print '</a>';
587
+				}
560 588
 				print '</td>';
561 589
 				// Size
562 590
 				print '<td align="center" class="nowrap">';
563
-				if (! $is_directory && ! $is_link) print $vals[4];
564
-				else print '&nbsp;';
591
+				if (! $is_directory && ! $is_link) {
592
+				    print $vals[4];
593
+				} else {
594
+				    print '&nbsp;';
595
+				}
565 596
 				print '</td>';
566 597
 				// Date
567 598
 				print '<td align="center" class="nowrap">';
@@ -583,16 +614,17 @@  discard block
 block discarded – undo
583 614
 				print '<td align="right" width="64" class="nowrap">';
584 615
 				if ($is_directory)
585 616
 				{
586
-					if ($file != '..') print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete_section&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
587
-					else print '&nbsp;';
588
-				}
589
-				else if ($is_link)
617
+					if ($file != '..') {
618
+					    print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete_section&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_delete().'</a>';
619
+					} else {
620
+					    print '&nbsp;';
621
+					}
622
+				} else if ($is_link)
590 623
 				{
591 624
 					$newfile=$file;
592 625
 					$newfile=preg_replace('/ ->.*/','',$newfile);
593 626
 					print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($newfile).'">'.img_delete().'</a>';
594
-				}
595
-				else
627
+				} else
596 628
 				{
597 629
 					print '<a href="'.$_SERVER["PHP_SELF"].'?action=download&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_picto('','file').'</a>';
598 630
 					print ' &nbsp; ';
@@ -634,8 +666,7 @@  discard block
 block discarded – undo
634 666
 		print '</div>';
635 667
 
636 668
 		print "</form>";
637
-	}
638
-	else
669
+	} else
639 670
 	{
640 671
 		$foundsetup=false;
641 672
 		$MAXFTP=20;
@@ -654,8 +685,7 @@  discard block
 block discarded – undo
654 685
 	    if (! $foundsetup)
655 686
 	    {
656 687
             print $langs->trans("SetupOfFTPClientModuleNotComplete");
657
-	    }
658
-	    else
688
+	    } else
659 689
 	    {
660 690
 	        print $langs->trans("ChooseAFTPEntryIntoMenu");
661 691
 	    }
@@ -670,12 +700,10 @@  discard block
 block discarded – undo
670 700
     if (! empty($conf->global->FTP_CONNECT_WITH_SFTP))
671 701
     {
672 702
 
673
-    }
674
-    else if (! empty($conf->global->FTP_CONNECT_WITH_SSL))
703
+    } else if (! empty($conf->global->FTP_CONNECT_WITH_SSL))
675 704
     {
676 705
         ftp_close($conn_id);
677
-    }
678
-    else
706
+    } else
679 707
     {
680 708
         ftp_close($conn_id);
681 709
     }
@@ -718,13 +746,11 @@  discard block
 block discarded – undo
718 746
 		{
719 747
 		    dol_syslog('Try to connect with ssh2_ftp');
720 748
 		    $tmp_conn_id = ssh2_connect($ftp_server, $ftp_port);
721
-		}
722
-		else if (! empty($conf->global->FTP_CONNECT_WITH_SSL))
749
+		} else if (! empty($conf->global->FTP_CONNECT_WITH_SSL))
723 750
 		{
724 751
 		    dol_syslog('Try to connect with ftp_ssl_connect');
725 752
 		    $conn_id = ftp_ssl_connect($ftp_server, $ftp_port, $connecttimeout);
726
-		}
727
-		else
753
+		} else
728 754
 		{
729 755
 		    dol_syslog('Try to connect with ftp_connect');
730 756
 		    $conn_id = ftp_connect($ftp_server, $ftp_port, $connecttimeout);
@@ -750,26 +776,25 @@  discard block
 block discarded – undo
750 776
     	   				    $ok=0;
751 777
         				    $error++;
752 778
 		                }
753
-    				}
754
-    				else
779
+    				} else
755 780
     				{
756 781
     					$mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials");
757 782
 	   				    $ok=0;
758 783
     				    $error++;
759 784
     				}
760
-				}
761
-				else
785
+				} else
762 786
 				{
763 787
 				    if (ftp_login($conn_id, $ftp_user, $ftp_password))
764 788
     				{
765 789
     					// Turn on passive mode transfers (must be after a successful login
766
-    					if ($ftp_passive) ftp_pasv($conn_id, true);
790
+    					if ($ftp_passive) {
791
+    					    ftp_pasv($conn_id, true);
792
+    					}
767 793
 
768 794
     					// Change the dir
769 795
     					$newsectioniso=utf8_decode($section);
770 796
     					ftp_chdir($conn_id, $newsectioniso);
771
-    				}
772
-    				else
797
+    				} else
773 798
     				{
774 799
     					$mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials");
775 800
 	   				    $ok=0;
@@ -777,8 +802,7 @@  discard block
 block discarded – undo
777 802
     				}
778 803
 				}
779 804
 			}
780
-		}
781
-		else
805
+		} else
782 806
 		{
783 807
 		    dol_syslog('FailedToConnectToFTPServer '.$ftp_server.' '.$ftp_port, LOG_ERR);
784 808
 			$mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServer",$ftp_server,$ftp_port);
@@ -804,8 +828,7 @@  discard block
 block discarded – undo
804 828
 	{
805 829
 		ftp_cdup($connect_id);
806 830
 		return 1;
807
-	}
808
-	else
831
+	} else
809 832
 	{
810 833
 		return 0;
811 834
 	}
Please login to merge, or discard this patch.
Spacing   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -24,8 +24,8 @@  discard block
 block discarded – undo
24 24
 
25 25
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
26 26
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
27
-require DOL_BASE_PATH . '/main.inc.php';
28
-require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
27
+require DOL_BASE_PATH.'/main.inc.php';
28
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
29 29
 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
30 30
 require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
31 31
 
@@ -33,48 +33,48 @@  discard block
 block discarded – undo
33 33
 $langs->loadLangs(array('ftp', 'companies', 'other'));
34 34
 
35 35
 // Security check
36
-if ($user->societe_id) $socid=$user->societe_id;
37
-$result = restrictedArea($user, 'ftp','');
36
+if ($user->societe_id) $socid = $user->societe_id;
37
+$result = restrictedArea($user, 'ftp', '');
38 38
 
39 39
 // Get parameters
40
-$action=GETPOST('action','aZ09');
41
-$section=GETPOST('section');
42
-if (! $section) $section='/';
40
+$action = GETPOST('action', 'aZ09');
41
+$section = GETPOST('section');
42
+if (!$section) $section = '/';
43 43
 $numero_ftp = GETPOST("numero_ftp");
44 44
 /* if (! $numero_ftp) $numero_ftp=1; */
45
-$file=GETPOST("file");
46
-$confirm=GETPOST('confirm');
45
+$file = GETPOST("file");
46
+$confirm = GETPOST('confirm');
47 47
 
48 48
 $upload_dir = $conf->ftp->dir_temp;
49 49
 $download_dir = $conf->ftp->dir_temp;
50 50
 
51
-$sortfield = GETPOST("sortfield",'alpha');
52
-$sortorder = GETPOST("sortorder",'alpha');
53
-$page = GETPOST("page",'int');
51
+$sortfield = GETPOST("sortfield", 'alpha');
52
+$sortorder = GETPOST("sortorder", 'alpha');
53
+$page = GETPOST("page", 'int');
54 54
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
55 55
 $offset = $conf->liste_limit * $page;
56 56
 $pageprev = $page - 1;
57 57
 $pagenext = $page + 1;
58
-if (! $sortorder) $sortorder="ASC";
59
-if (! $sortfield) $sortfield="label";
60
-
61
-$s_ftp_name='FTP_NAME_'.$numero_ftp;
62
-$s_ftp_server='FTP_SERVER_'.$numero_ftp;
63
-$s_ftp_port='FTP_PORT_'.$numero_ftp;
64
-$s_ftp_user='FTP_USER_'.$numero_ftp;
65
-$s_ftp_password='FTP_PASSWORD_'.$numero_ftp;
66
-$s_ftp_passive='FTP_PASSIVE_'.$numero_ftp;
67
-$ftp_name=$conf->global->$s_ftp_name;
68
-$ftp_server=$conf->global->$s_ftp_server;
69
-$ftp_port=$conf->global->$s_ftp_port; if (empty($ftp_port)) $ftp_port=21;
70
-$ftp_user=$conf->global->$s_ftp_user;
71
-$ftp_password=$conf->global->$s_ftp_password;
72
-$ftp_passive=$conf->global->$s_ftp_passive;
58
+if (!$sortorder) $sortorder = "ASC";
59
+if (!$sortfield) $sortfield = "label";
60
+
61
+$s_ftp_name = 'FTP_NAME_'.$numero_ftp;
62
+$s_ftp_server = 'FTP_SERVER_'.$numero_ftp;
63
+$s_ftp_port = 'FTP_PORT_'.$numero_ftp;
64
+$s_ftp_user = 'FTP_USER_'.$numero_ftp;
65
+$s_ftp_password = 'FTP_PASSWORD_'.$numero_ftp;
66
+$s_ftp_passive = 'FTP_PASSIVE_'.$numero_ftp;
67
+$ftp_name = $conf->global->$s_ftp_name;
68
+$ftp_server = $conf->global->$s_ftp_server;
69
+$ftp_port = $conf->global->$s_ftp_port; if (empty($ftp_port)) $ftp_port = 21;
70
+$ftp_user = $conf->global->$s_ftp_user;
71
+$ftp_password = $conf->global->$s_ftp_password;
72
+$ftp_passive = $conf->global->$s_ftp_passive;
73 73
 
74 74
 // For result on connection
75
-$ok=0;
76
-$conn_id=null;	// FTP connection ID
77
-$mesg='';
75
+$ok = 0;
76
+$conn_id = null; // FTP connection ID
77
+$mesg = '';
78 78
 
79 79
 
80 80
 
@@ -83,25 +83,25 @@  discard block
 block discarded – undo
83 83
  */
84 84
 
85 85
 // Submit file
86
-if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC))
86
+if (GETPOST("sendit") && !empty($conf->global->MAIN_UPLOAD_DOC))
87 87
 {
88 88
 	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
89 89
 
90
-	$result=$ecmdir->fetch($_REQUEST["section"]);
91
-	if (! $result > 0)
90
+	$result = $ecmdir->fetch($_REQUEST["section"]);
91
+	if (!$result > 0)
92 92
 	{
93
-		dol_print_error($db,$ecmdir->error);
93
+		dol_print_error($db, $ecmdir->error);
94 94
 		exit;
95 95
 	}
96
-	$relativepath=$ecmdir->getRelativePath();
96
+	$relativepath = $ecmdir->getRelativePath();
97 97
 	$upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
98 98
 
99 99
 	if (dol_mkdir($upload_dir) >= 0)
100 100
 	{
101
-		$resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0);
101
+		$resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir."/".dol_unescapefile($_FILES['userfile']['name']), 0);
102 102
 		if (is_numeric($resupload) && $resupload > 0)
103 103
 		{
104
-			$result=$ecmdir->changeNbOfFiles('+');
104
+			$result = $ecmdir->changeNbOfFiles('+');
105 105
 		}
106 106
 		else {
107 107
 			$langs->load("errors");
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 			{
110 110
 				setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors');
111 111
 			}
112
-			else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload))	// Files infected by a virus
112
+			else if (preg_match('/ErrorFileIsInfectedWithAVirus/', $resupload))	// Files infected by a virus
113 113
 			{
114 114
 				setEventMessages($langs->trans("ErrorFileIsInfectedWithAVirus"), null, 'errors');
115 115
 			}
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	{
124 124
 		// Echec transfert (fichier depassant la limite ?)
125 125
 		$langs->load("errors");
126
-		setEventMessages($langs->trans("ErrorFailToCreateDir",$upload_dir), null, 'errors');
126
+		setEventMessages($langs->trans("ErrorFailToCreateDir", $upload_dir), null, 'errors');
127 127
 	}
128 128
 }
129 129
 
@@ -151,44 +151,44 @@  discard block
 block discarded – undo
151 151
 if ($action == 'confirm_deletefile' && $_REQUEST['confirm'] == 'yes')
152 152
 {
153 153
 	// set up a connection or die
154
-	if (! $conn_id)
154
+	if (!$conn_id)
155 155
 	{
156
-		$newsectioniso=utf8_decode($section);
157
-		$resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
158
-		$conn_id=$resultarray['conn_id'];
159
-		$ok=$resultarray['ok'];
160
-		$mesg=$resultarray['mesg'];
156
+		$newsectioniso = utf8_decode($section);
157
+		$resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
158
+		$conn_id = $resultarray['conn_id'];
159
+		$ok = $resultarray['ok'];
160
+		$mesg = $resultarray['mesg'];
161 161
 	}
162 162
 
163
-	if ($conn_id && $ok && ! $mesg)
163
+	if ($conn_id && $ok && !$mesg)
164 164
 	{
165 165
 	    $langs->load("other");
166 166
 
167 167
 		// Remote file
168
-		$filename=$file;
169
-		$remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
170
-		$newremotefileiso=utf8_decode($remotefile);
168
+		$filename = $file;
169
+		$remotefile = $section.(preg_match('@[\\\/]$@', $section) ? '' : '/').$file;
170
+		$newremotefileiso = utf8_decode($remotefile);
171 171
 
172 172
 		//print "x".$newremotefileiso;
173 173
 		dol_syslog("ftp/index.php ftp_delete ".$newremotefileiso);
174
-		$result=@ftp_delete($conn_id, $newremotefileiso);
174
+		$result = @ftp_delete($conn_id, $newremotefileiso);
175 175
 		if ($result)
176 176
 		{
177
-			setEventMessages($langs->trans("FileWasRemoved",$file), null, 'mesgs');
177
+			setEventMessages($langs->trans("FileWasRemoved", $file), null, 'mesgs');
178 178
 		}
179 179
 		else
180 180
 		{
181 181
 			dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
182
-			setEventMessages($langs->trans("FTPFailedToRemoveFile",$file), null, 'errors');
182
+			setEventMessages($langs->trans("FTPFailedToRemoveFile", $file), null, 'errors');
183 183
 		}
184 184
 
185 185
 		//ftp_close($conn_id);	Close later
186 186
 
187
-		$action='';
187
+		$action = '';
188 188
 	}
189 189
 	else
190 190
 	{
191
-		dol_print_error('',$mesg);
191
+		dol_print_error('', $mesg);
192 192
 	}
193 193
 }
194 194
 
@@ -196,51 +196,51 @@  discard block
 block discarded – undo
196 196
 if ($_POST["const"] && $_POST["delete"] && $_POST["delete"] == $langs->trans("Delete"))
197 197
 {
198 198
 	// set up a connection or die
199
-	if (! $conn_id)
199
+	if (!$conn_id)
200 200
 	{
201
-		$newsectioniso=utf8_decode($section);
202
-		$resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
203
-		$conn_id=$resultarray['conn_id'];
204
-		$ok=$resultarray['ok'];
205
-		$mesg=$resultarray['mesg'];
201
+		$newsectioniso = utf8_decode($section);
202
+		$resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
203
+		$conn_id = $resultarray['conn_id'];
204
+		$ok = $resultarray['ok'];
205
+		$mesg = $resultarray['mesg'];
206 206
 	}
207 207
 
208
-	if ($conn_id && $ok && ! $mesg)
208
+	if ($conn_id && $ok && !$mesg)
209 209
 	{
210
-		foreach($_POST["const"] as $const)
210
+		foreach ($_POST["const"] as $const)
211 211
 		{
212 212
 			if ($const["check"])	// Is checkbox checked
213 213
 			{
214 214
 			    $langs->load("other");
215 215
 
216 216
 				// Remote file
217
-				$file=$const["file"];
218
-				$section=$const["section"];
219
-				$remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
220
-				$newremotefileiso=utf8_decode($remotefile);
217
+				$file = $const["file"];
218
+				$section = $const["section"];
219
+				$remotefile = $section.(preg_match('@[\\\/]$@', $section) ? '' : '/').$file;
220
+				$newremotefileiso = utf8_decode($remotefile);
221 221
 
222 222
 				//print "x".$newremotefileiso;
223 223
 				dol_syslog("ftp/index.php ftp_delete ".$newremotefileiso);
224
-				$result=@ftp_delete($conn_id, $newremotefileiso);
224
+				$result = @ftp_delete($conn_id, $newremotefileiso);
225 225
 				if ($result)
226 226
 				{
227
-					setEventMessages($langs->trans("FileWasRemoved",$file), null, 'mesgs');
227
+					setEventMessages($langs->trans("FileWasRemoved", $file), null, 'mesgs');
228 228
 				}
229 229
 				else
230 230
 				{
231 231
 					dol_syslog("ftp/index.php ftp_delete", LOG_ERR);
232
-					setEventMessages($langs->trans("FTPFailedToRemoveFile",$file), null, 'errors');
232
+					setEventMessages($langs->trans("FTPFailedToRemoveFile", $file), null, 'errors');
233 233
 				}
234 234
 
235 235
 				//ftp_close($conn_id);	Close later
236 236
 
237
-				$action='';
237
+				$action = '';
238 238
 			}
239 239
 		}
240 240
 	}
241 241
 	else
242 242
 	{
243
-		dol_print_error('',$mesg);
243
+		dol_print_error('', $mesg);
244 244
 	}
245 245
 }
246 246
 
@@ -248,39 +248,39 @@  discard block
 block discarded – undo
248 248
 if ($action == 'confirm_deletesection' && $confirm == 'yes')
249 249
 {
250 250
 	// set up a connection or die
251
-	if (! $conn_id)
251
+	if (!$conn_id)
252 252
 	{
253
-		$newsectioniso=utf8_decode($section);
254
-		$resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
255
-		$conn_id=$resultarray['conn_id'];
256
-		$ok=$resultarray['ok'];
257
-		$mesg=$resultarray['mesg'];
253
+		$newsectioniso = utf8_decode($section);
254
+		$resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
255
+		$conn_id = $resultarray['conn_id'];
256
+		$ok = $resultarray['ok'];
257
+		$mesg = $resultarray['mesg'];
258 258
 	}
259 259
 
260
-	if ($conn_id && $ok && ! $mesg)
260
+	if ($conn_id && $ok && !$mesg)
261 261
 	{
262 262
 		// Remote file
263
-		$filename=$file;
264
-		$remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
265
-		$newremotefileiso=utf8_decode($remotefile);
263
+		$filename = $file;
264
+		$remotefile = $section.(preg_match('@[\\\/]$@', $section) ? '' : '/').$file;
265
+		$newremotefileiso = utf8_decode($remotefile);
266 266
 
267
-		$result=@ftp_rmdir($conn_id, $newremotefileiso);
267
+		$result = @ftp_rmdir($conn_id, $newremotefileiso);
268 268
 		if ($result)
269 269
 		{
270
-			setEventMessages($langs->trans("DirWasRemoved",$file), null, 'mesgs');
270
+			setEventMessages($langs->trans("DirWasRemoved", $file), null, 'mesgs');
271 271
 		}
272 272
 		else
273 273
 		{
274
-			setEventMessages($langs->trans("FTPFailedToRemoveDir",$file), null, 'errors');
274
+			setEventMessages($langs->trans("FTPFailedToRemoveDir", $file), null, 'errors');
275 275
 		}
276 276
 
277 277
 		//ftp_close($conn_id);	Close later
278 278
 
279
-		$action='';
279
+		$action = '';
280 280
 	}
281 281
 	else
282 282
 	{
283
-		dol_print_error('',$mesg);
283
+		dol_print_error('', $mesg);
284 284
 	}
285 285
 }
286 286
 
@@ -288,35 +288,35 @@  discard block
 block discarded – undo
288 288
 if ($action == 'download')
289 289
 {
290 290
 	// set up a connection or die
291
-	if (! $conn_id)
291
+	if (!$conn_id)
292 292
 	{
293
-		$newsectioniso=utf8_decode($section);
294
-		$resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
295
-		$conn_id=$resultarray['conn_id'];
296
-		$ok=$resultarray['ok'];
297
-		$mesg=$resultarray['mesg'];
293
+		$newsectioniso = utf8_decode($section);
294
+		$resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $newsectioniso, $ftp_passive);
295
+		$conn_id = $resultarray['conn_id'];
296
+		$ok = $resultarray['ok'];
297
+		$mesg = $resultarray['mesg'];
298 298
 	}
299 299
 
300
-	if ($conn_id && $ok && ! $mesg)
300
+	if ($conn_id && $ok && !$mesg)
301 301
 	{
302 302
 		// Local file
303
-		$localfile=tempnam($download_dir,'dol_');
303
+		$localfile = tempnam($download_dir, 'dol_');
304 304
 
305 305
 		// Remote file
306
-		$filename=$file;
307
-		$remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
308
-		$newremotefileiso=utf8_decode($remotefile);
306
+		$filename = $file;
307
+		$remotefile = $section.(preg_match('@[\\\/]$@', $section) ? '' : '/').$file;
308
+		$newremotefileiso = utf8_decode($remotefile);
309 309
 
310
-		$result=ftp_get($conn_id,$localfile,$newremotefileiso,FTP_BINARY);
310
+		$result = ftp_get($conn_id, $localfile, $newremotefileiso, FTP_BINARY);
311 311
 		if ($result)
312 312
 		{
313
-			if (! empty($conf->global->MAIN_UMASK))
313
+			if (!empty($conf->global->MAIN_UMASK))
314 314
 			@chmod($localfile, octdec($conf->global->MAIN_UMASK));
315 315
 
316 316
 			// Define mime type
317 317
 			$type = 'application/octet-stream';
318
-			if (! empty($_GET["type"])) $type=$_GET["type"];
319
-			else $type=dol_mimetype($original_file);
318
+			if (!empty($_GET["type"])) $type = $_GET["type"];
319
+			else $type = dol_mimetype($original_file);
320 320
 
321 321
 			// Define attachment (attachment=true to force choice popup 'open'/'save as')
322 322
 			$attachment = true;
@@ -338,12 +338,12 @@  discard block
 block discarded – undo
338 338
 		}
339 339
 		else
340 340
 		{
341
-			setEventMessages($langs->transnoentitiesnoconv('FailedToGetFile',$remotefile), null, 'errors');
341
+			setEventMessages($langs->transnoentitiesnoconv('FailedToGetFile', $remotefile), null, 'errors');
342 342
 		}
343 343
 	}
344 344
 	else
345 345
 	{
346
-		dol_print_error('',$mesg);
346
+		dol_print_error('', $mesg);
347 347
 	}
348 348
 
349 349
 	//ftp_close($conn_id);	Close later
@@ -386,8 +386,8 @@  discard block
 block discarded – undo
386 386
 <?php
387 387
 }
388 388
 
389
-$form=new Form($db);
390
-$formfile=new FormFile($db);
389
+$form = new Form($db);
390
+$formfile = new FormFile($db);
391 391
 $userstatic = new User($db);
392 392
 
393 393
 
@@ -396,50 +396,50 @@  discard block
 block discarded – undo
396 396
 
397 397
 print $langs->trans("FTPAreaDesc")."<br>";
398 398
 
399
-if (! function_exists('ftp_connect'))
399
+if (!function_exists('ftp_connect'))
400 400
 {
401 401
 	print $langs->trans("FTPFeatureNotSupportedByYourPHP");
402 402
 }
403 403
 else
404 404
 {
405
-    if (! empty($ftp_server))
405
+    if (!empty($ftp_server))
406 406
 	{
407 407
 		// Confirm remove file
408 408
 		if ($action == 'delete')
409 409
 		{
410
-			print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode($_REQUEST["section"]).'&file='.urlencode($_GET["file"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1);
410
+			print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode($_REQUEST["section"]).'&file='.urlencode($_GET["file"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', '', 1);
411 411
 		}
412 412
 
413 413
 		// Confirmation de la suppression d'une ligne categorie
414 414
 		if ($action == 'delete_section')
415 415
 		{
416
-			print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode($_REQUEST["section"]).'&file='.urlencode($_GET["file"]), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection','','',1);
416
+			print $form->formconfirm($_SERVER["PHP_SELF"].'?numero_ftp='.$numero_ftp.'&section='.urlencode($_REQUEST["section"]).'&file='.urlencode($_GET["file"]), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection', $ecmdir->label), 'confirm_deletesection', '', '', 1);
417 417
 		}
418 418
 
419 419
 		print $langs->trans("Server").': <b>'.$ftp_server.'</b><br>';
420
-		print $langs->trans("Port").': <b>'.$ftp_port.'</b> '.($ftp_passive?"(Passive)":"(Active)").'<br>';
420
+		print $langs->trans("Port").': <b>'.$ftp_port.'</b> '.($ftp_passive ? "(Passive)" : "(Active)").'<br>';
421 421
 		print $langs->trans("User").': <b>'.$ftp_user.'</b><br>';
422 422
         print $langs->trans("FTPs (FTP over SSH)").': <b>'.yn($conf->global->FTP_CONNECT_WITH_SSL).'</b><br>';
423 423
         print $langs->trans("SFTP (FTP as a subsytem of SSH)").': <b>'.yn($conf->global->FTP_CONNECT_WITH_SFTP).'</b><br>';
424 424
         print $langs->trans("Directory").': ';
425
-		$sectionarray=preg_split('|[\/]|',$section);
425
+		$sectionarray = preg_split('|[\/]|', $section);
426 426
 		// For /
427
-		$newsection='/';
428
-		print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection?'&section='.urlencode($newsection):'').'">';
427
+		$newsection = '/';
428
+		print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ? '&section='.urlencode($newsection) : '').'">';
429 429
 		print '/';
430 430
 		print '</a> ';
431 431
 		// For other directories
432
-		$i=0;
433
-		foreach($sectionarray as $val)
432
+		$i = 0;
433
+		foreach ($sectionarray as $val)
434 434
 		{
435
-			if (empty($val)) continue;	// Discard first and last entry that should be empty as section start/end with /
435
+			if (empty($val)) continue; // Discard first and last entry that should be empty as section start/end with /
436 436
 			if ($i > 0)
437 437
 			{
438 438
 				print ' / ';
439
-				$newsection.='/';
439
+				$newsection .= '/';
440 440
 			}
441
-			$newsection.=$val;
442
-			print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection?'&section='.urlencode($newsection):'').'">';
441
+			$newsection .= $val;
442
+			print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($newsection ? '&section='.urlencode($newsection) : '').'">';
443 443
 			print $val;
444 444
 			print '</a>';
445 445
 			$i++;
@@ -464,62 +464,62 @@  discard block
 block discarded – undo
464 464
 		print '<td class="liste_titre" align="center">'.$langs->trans("Permissions").'</td>'."\n";
465 465
 		print '<td class="liste_titre nowrap" align="right">';
466 466
 		if ($conf->use_javascript_ajax) print '<a href="#" id="checkall">'.$langs->trans("All").'</a> / <a href="#" id="checknone">'.$langs->trans("None").'</a> ';
467
-		print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($section?'&section='.urlencode($section):'').'">'.img_picto($langs->trans("Refresh"),'refresh').'</a>&nbsp;';
467
+		print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual&numero_ftp='.$numero_ftp.($section ? '&section='.urlencode($section) : '').'">'.img_picto($langs->trans("Refresh"), 'refresh').'</a>&nbsp;';
468 468
 		print '</td>'."\n";
469 469
 		print '</tr>'."\n";
470 470
 
471 471
 		// set up a connection or die
472 472
 		if (empty($conn_id))
473 473
 		{
474
-			$resultarray=dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive);
474
+			$resultarray = dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive);
475 475
 
476
-			$conn_id=$resultarray['conn_id'];
477
-			$ok=$resultarray['ok'];
478
-			$mesg=$resultarray['mesg'];
476
+			$conn_id = $resultarray['conn_id'];
477
+			$ok = $resultarray['ok'];
478
+			$mesg = $resultarray['mesg'];
479 479
 		}
480 480
 
481 481
 		if ($ok)
482 482
 		{
483 483
 			//$type = ftp_systype($conn_id);
484 484
 
485
-			$newsection=$section;
486
-		    $newsectioniso=utf8_decode($section);
485
+			$newsection = $section;
486
+		    $newsectioniso = utf8_decode($section);
487 487
 			//$newsection='/home';
488 488
 
489 489
 			// List content of directory ($newsection = '/', '/home', ...)
490
-			if (! empty($conf->global->FTP_CONNECT_WITH_SFTP))
490
+			if (!empty($conf->global->FTP_CONNECT_WITH_SFTP))
491 491
 			{
492
-			    if ($newsection == '/') $newsection='/./';  // workaround for bug https://bugs.php.net/bug.php?id=64169
492
+			    if ($newsection == '/') $newsection = '/./'; // workaround for bug https://bugs.php.net/bug.php?id=64169
493 493
 			    //$dirHandle = opendir("ssh2.sftp://$conn_id".$newsection);
494 494
 			    //var_dump($dirHandle);
495
-                $contents = scandir('ssh2.sftp://' . $conn_id . $newsection);
496
-                $buff=array();
497
-                foreach($contents as $i => $key)
495
+                $contents = scandir('ssh2.sftp://'.$conn_id.$newsection);
496
+                $buff = array();
497
+                foreach ($contents as $i => $key)
498 498
                 {
499
-                    $buff[$i]="---------- - root root 1234 Aug 01 2000 ".$key;
499
+                    $buff[$i] = "---------- - root root 1234 Aug 01 2000 ".$key;
500 500
                 }
501 501
     		}
502 502
     		else
503 503
     		{
504 504
                 $buff = ftp_rawlist($conn_id, $newsectioniso);
505
-                $contents = ftp_nlist($conn_id, $newsectioniso);	// Sometimes rawlist fails but never nlist
505
+                $contents = ftp_nlist($conn_id, $newsectioniso); // Sometimes rawlist fails but never nlist
506 506
         		//var_dump($contents);
507 507
 		        //var_dump($buff);
508 508
     		}
509 509
 
510
-			$nboflines=count($contents);
511
-			$rawlisthasfailed=false;
512
-			$i=0;
510
+			$nboflines = count($contents);
511
+			$rawlisthasfailed = false;
512
+			$i = 0;
513 513
 			while ($i < $nboflines && $i < 1000)
514 514
 			{
515
-				$vals=preg_split('@ +@',utf8_encode($buff[$i]),9);
515
+				$vals = preg_split('@ +@', utf8_encode($buff[$i]), 9);
516 516
 				//$vals=preg_split('@ +@','drwxr-xr-x 2 root root 4096 Aug 30 2008 backup_apollon1',9);
517 517
 				//var_dump($vals);
518
-				$file=$vals[8];
518
+				$file = $vals[8];
519 519
 				if (empty($file))
520 520
 				{
521
-					$rawlisthasfailed=true;
522
-					$file=utf8_encode($contents[$i]);
521
+					$rawlisthasfailed = true;
522
+					$file = utf8_encode($contents[$i]);
523 523
 				}
524 524
 
525 525
 				if ($file == '.' || ($file == '..' && $section == '/'))
@@ -529,40 +529,40 @@  discard block
 block discarded – undo
529 529
 				}
530 530
 
531 531
 				// Is it a directory ?
532
-				$is_directory=0;
533
-				if ($file == '..') $is_directory=1;
534
-				else if (! $rawlisthasfailed)
532
+				$is_directory = 0;
533
+				if ($file == '..') $is_directory = 1;
534
+				else if (!$rawlisthasfailed)
535 535
 				{
536
-					if (preg_match('/^d/',$vals[0])) $is_directory=1;
537
-					if (preg_match('/^l/',$vals[0])) $is_link=1;
536
+					if (preg_match('/^d/', $vals[0])) $is_directory = 1;
537
+					if (preg_match('/^l/', $vals[0])) $is_link = 1;
538 538
 				}
539 539
 				else
540 540
 				{
541 541
 					// Remote file
542
-					$filename=$file;
542
+					$filename = $file;
543 543
 					//print "section=".$section.' file='.$file.'X';
544 544
 					//print preg_match('@[\/]$@','aaa/').'Y';
545 545
 					//print preg_match('@[\\\/]$@',"aaa\\").'Y';
546
-					$remotefile=$section.(preg_match('@[\\\/]$@',$section)?'':'/').preg_replace('@^[\\\/]@','',$file);
546
+					$remotefile = $section.(preg_match('@[\\\/]$@', $section) ? '' : '/').preg_replace('@^[\\\/]@', '', $file);
547 547
 					//print 'A'.$remotefile.'A';
548
-					$newremotefileiso=utf8_decode($remotefile);
548
+					$newremotefileiso = utf8_decode($remotefile);
549 549
 					//print 'Z'.$newremotefileiso.'Z';
550
-					$is_directory=ftp_isdir($conn_id, $newremotefileiso);
550
+					$is_directory = ftp_isdir($conn_id, $newremotefileiso);
551 551
 				}
552 552
 
553 553
 
554 554
 				print '<tr class="oddeven" height="18">';
555 555
 				// Name
556 556
 				print '<td>';
557
-				$newsection=$section.(preg_match('@[\\\/]$@',$section)?'':'/').$file;
558
-				$newsection=preg_replace('@[\\\/][^\\\/]+[\\\/]\.\.$@','/',$newsection);	// Change aaa/xxx/.. to new aaa
557
+				$newsection = $section.(preg_match('@[\\\/]$@', $section) ? '' : '/').$file;
558
+				$newsection = preg_replace('@[\\\/][^\\\/]+[\\\/]\.\.$@', '/', $newsection); // Change aaa/xxx/.. to new aaa
559 559
 				if ($is_directory) print '<a href="'.$_SERVER["PHP_SELF"].'?section='.urlencode($newsection).'&numero_ftp='.$numero_ftp.'">';
560 560
 				print $file;
561 561
 				if ($is_directory) print '</a>';
562 562
 				print '</td>';
563 563
 				// Size
564 564
 				print '<td align="center" class="nowrap">';
565
-				if (! $is_directory && ! $is_link) print $vals[4];
565
+				if (!$is_directory && !$is_link) print $vals[4];
566 566
 				else print '&nbsp;';
567 567
 				print '</td>';
568 568
 				// Date
@@ -590,13 +590,13 @@  discard block
 block discarded – undo
590 590
 				}
591 591
 				else if ($is_link)
592 592
 				{
593
-					$newfile=$file;
594
-					$newfile=preg_replace('/ ->.*/','',$newfile);
593
+					$newfile = $file;
594
+					$newfile = preg_replace('/ ->.*/', '', $newfile);
595 595
 					print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($newfile).'">'.img_delete().'</a>';
596 596
 				}
597 597
 				else
598 598
 				{
599
-					print '<a href="'.$_SERVER["PHP_SELF"].'?action=download&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_picto('','file').'</a>';
599
+					print '<a href="'.$_SERVER["PHP_SELF"].'?action=download&numero_ftp='.$numero_ftp.'&section='.urlencode($section).'&file='.urlencode($file).'">'.img_picto('', 'file').'</a>';
600 600
 					print ' &nbsp; ';
601 601
 					print '<input type="checkbox" class="flat checkboxfordelete" id="check_'.$i.'" name="const['.$i.'][check]" value="1">';
602 602
 					print ' &nbsp; ';
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
 		print "</table>";
615 615
 
616 616
 
617
-		if (! $ok)
617
+		if (!$ok)
618 618
 		{
619 619
 		      print $mesg.'<br>'."\n";
620 620
 		      setEventMessages($mesg, null, 'errors');
@@ -639,21 +639,21 @@  discard block
 block discarded – undo
639 639
 	}
640 640
 	else
641 641
 	{
642
-		$foundsetup=false;
643
-		$MAXFTP=20;
644
-		$i=1;
642
+		$foundsetup = false;
643
+		$MAXFTP = 20;
644
+		$i = 1;
645 645
 		while ($i <= $MAXFTP)
646 646
 		{
647
-			$paramkey='FTP_NAME_'.$i;
647
+			$paramkey = 'FTP_NAME_'.$i;
648 648
 			//print $paramkey;
649
-			if (! empty($conf->global->$paramkey))
649
+			if (!empty($conf->global->$paramkey))
650 650
 			{
651
-				$foundsetup=true;
651
+				$foundsetup = true;
652 652
 				break;
653 653
 			}
654 654
 			$i++;
655 655
 		}
656
-	    if (! $foundsetup)
656
+	    if (!$foundsetup)
657 657
 	    {
658 658
             print $langs->trans("SetupOfFTPClientModuleNotComplete");
659 659
 	    }
@@ -669,11 +669,11 @@  discard block
 block discarded – undo
669 669
 // Close FTP connection
670 670
 if ($conn_id)
671 671
 {
672
-    if (! empty($conf->global->FTP_CONNECT_WITH_SFTP))
672
+    if (!empty($conf->global->FTP_CONNECT_WITH_SFTP))
673 673
     {
674 674
 
675 675
     }
676
-    else if (! empty($conf->global->FTP_CONNECT_WITH_SSL))
676
+    else if (!empty($conf->global->FTP_CONNECT_WITH_SSL))
677 677
     {
678 678
         ftp_close($conn_id);
679 679
     }
@@ -700,28 +700,28 @@  discard block
 block discarded – undo
700 700
  * @param	integer	$ftp_passive	Use a passive mode
701 701
  * @return	int 	<0 if OK, >0 if KO
702 702
  */
703
-function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive=0)
703
+function dol_ftp_connect($ftp_server, $ftp_port, $ftp_user, $ftp_password, $section, $ftp_passive = 0)
704 704
 {
705 705
 	global $langs, $conf;
706 706
 
707
-	$ok=1;
708
-    $conn_id=null;
707
+	$ok = 1;
708
+    $conn_id = null;
709 709
 
710
-	if (! is_numeric($ftp_port))
710
+	if (!is_numeric($ftp_port))
711 711
 	{
712
-		$mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServer",$ftp_server,$ftp_port);
713
-		$ok=0;
712
+		$mesg = $langs->transnoentitiesnoconv("FailedToConnectToFTPServer", $ftp_server, $ftp_port);
713
+		$ok = 0;
714 714
 	}
715 715
 
716 716
 	if ($ok)
717 717
 	{
718
-		$connecttimeout=(empty($conf->global->FTP_CONNECT_TIMEOUT)?40:$conf->global->FTP_CONNECT_TIMEOUT);
719
-		if (! empty($conf->global->FTP_CONNECT_WITH_SFTP))
718
+		$connecttimeout = (empty($conf->global->FTP_CONNECT_TIMEOUT) ? 40 : $conf->global->FTP_CONNECT_TIMEOUT);
719
+		if (!empty($conf->global->FTP_CONNECT_WITH_SFTP))
720 720
 		{
721 721
 		    dol_syslog('Try to connect with ssh2_ftp');
722 722
 		    $tmp_conn_id = ssh2_connect($ftp_server, $ftp_port);
723 723
 		}
724
-		else if (! empty($conf->global->FTP_CONNECT_WITH_SSL))
724
+		else if (!empty($conf->global->FTP_CONNECT_WITH_SSL))
725 725
 		{
726 726
 		    dol_syslog('Try to connect with ftp_ssl_connect');
727 727
 		    $conn_id = ftp_ssl_connect($ftp_server, $ftp_port, $connecttimeout);
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
 		{
736 736
 			if ($ftp_user)
737 737
 			{
738
-				if (! empty($conf->global->FTP_CONNECT_WITH_SFTP))
738
+				if (!empty($conf->global->FTP_CONNECT_WITH_SFTP))
739 739
 				{
740 740
 				    if (ssh2_auth_password($tmp_conn_id, $ftp_user, $ftp_password))
741 741
     				{
@@ -743,20 +743,20 @@  discard block
 block discarded – undo
743 743
     					//if ($ftp_passive) ftp_pasv($conn_id, true);
744 744
 
745 745
     					// Change the dir
746
-    					$newsectioniso=utf8_decode($section);
746
+    					$newsectioniso = utf8_decode($section);
747 747
     					//ftp_chdir($conn_id, $newsectioniso);
748 748
 		                $conn_id = ssh2_sftp($tmp_conn_id);
749
-		                if (! $conn_id)
749
+		                if (!$conn_id)
750 750
 		                {
751
-        					$mesg=$langs->transnoentitiesnoconv("FailedToConnectToSFTPAfterSSHAuthentication");
752
-    	   				    $ok=0;
751
+        					$mesg = $langs->transnoentitiesnoconv("FailedToConnectToSFTPAfterSSHAuthentication");
752
+    	   				    $ok = 0;
753 753
         				    $error++;
754 754
 		                }
755 755
     				}
756 756
     				else
757 757
     				{
758
-    					$mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials");
759
-	   				    $ok=0;
758
+    					$mesg = $langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials");
759
+	   				    $ok = 0;
760 760
     				    $error++;
761 761
     				}
762 762
 				}
@@ -768,13 +768,13 @@  discard block
 block discarded – undo
768 768
     					if ($ftp_passive) ftp_pasv($conn_id, true);
769 769
 
770 770
     					// Change the dir
771
-    					$newsectioniso=utf8_decode($section);
771
+    					$newsectioniso = utf8_decode($section);
772 772
     					ftp_chdir($conn_id, $newsectioniso);
773 773
     				}
774 774
     				else
775 775
     				{
776
-    					$mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials");
777
-	   				    $ok=0;
776
+    					$mesg = $langs->transnoentitiesnoconv("FailedToConnectToFTPServerWithCredentials");
777
+	   				    $ok = 0;
778 778
     				    $error++;
779 779
     				}
780 780
 				}
@@ -783,12 +783,12 @@  discard block
 block discarded – undo
783 783
 		else
784 784
 		{
785 785
 		    dol_syslog('FailedToConnectToFTPServer '.$ftp_server.' '.$ftp_port, LOG_ERR);
786
-			$mesg=$langs->transnoentitiesnoconv("FailedToConnectToFTPServer",$ftp_server,$ftp_port);
787
-			$ok=0;
786
+			$mesg = $langs->transnoentitiesnoconv("FailedToConnectToFTPServer", $ftp_server, $ftp_port);
787
+			$ok = 0;
788 788
 		}
789 789
 	}
790 790
 
791
-	$arrayresult=array('conn_id'=>$conn_id, 'ok'=>$ok, 'mesg'=>$mesg, 'curdir'=>$section, 'curdiriso'=>$newsectioniso);
791
+	$arrayresult = array('conn_id'=>$conn_id, 'ok'=>$ok, 'mesg'=>$mesg, 'curdir'=>$section, 'curdiriso'=>$newsectioniso);
792 792
 	return $arrayresult;
793 793
 }
794 794
 
@@ -800,9 +800,9 @@  discard block
 block discarded – undo
800 800
  * @param 		string		$dir			Directory
801 801
  * @return		int			1=directory, 0=not a directory
802 802
  */
803
-function ftp_isdir($connect_id,$dir)
803
+function ftp_isdir($connect_id, $dir)
804 804
 {
805
-	if (@ftp_chdir($connect_id,$dir))
805
+	if (@ftp_chdir($connect_id, $dir))
806 806
 	{
807 807
 		ftp_cdup($connect_id);
808 808
 		return 1;
Please login to merge, or discard this patch.
dolibarr/htdocs/dav/dav.class.php 3 patches
Indentation   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -28,11 +28,11 @@  discard block
 block discarded – undo
28 28
 class CdavLib
29 29
 {
30 30
 
31
-	private $db;
31
+    private $db;
32 32
 
33
-	private $user;
33
+    private $user;
34 34
 
35
-	private $langs;
35
+    private $langs;
36 36
 
37 37
     /**
38 38
      * Constructor
@@ -41,25 +41,25 @@  discard block
 block discarded – undo
41 41
      * @param   DoliDB      $db     Database handler
42 42
      * @param   Translate   $langs  translation
43 43
      */
44
-	function __construct($user, $db, $langs)
45
-	{
46
-		$this->user = $user;
47
-		$this->db = $db;
48
-		$this->langs = $langs;
49
-	}
44
+    function __construct($user, $db, $langs)
45
+    {
46
+        $this->user = $user;
47
+        $this->db = $db;
48
+        $this->langs = $langs;
49
+    }
50 50
 
51
-	/**
52
-	 * Base sql request for calendar events
53
-	 *
54
-	 * @param 	int 		$calid 			Calendard id
55
-	 * @param 	int|boolean	$oid			Oid
56
-	 * @param	int|boolean	$ouri			Ouri
57
-	 * @return string
58
-	 */
59
-	public function getSqlCalEvents($calid, $oid=false, $ouri=false)
60
-	{
61
-		// TODO : replace GROUP_CONCAT by
62
-		$sql = 'SELECT
51
+    /**
52
+     * Base sql request for calendar events
53
+     *
54
+     * @param 	int 		$calid 			Calendard id
55
+     * @param 	int|boolean	$oid			Oid
56
+     * @param	int|boolean	$ouri			Ouri
57
+     * @return string
58
+     */
59
+    public function getSqlCalEvents($calid, $oid=false, $ouri=false)
60
+    {
61
+        // TODO : replace GROUP_CONCAT by
62
+        $sql = 'SELECT
63 63
 					a.tms AS lastupd,
64 64
 					a.*,
65 65
 					sp.firstname,
@@ -82,223 +82,223 @@  discard block
 block discarded – undo
82 82
 						LEFT OUTER JOIN '.MAIN_DB_PREFIX.'user AS u ON (u.rowid=fk_element)
83 83
 						WHERE ar.element_type=\'user\' AND fk_actioncomm=a.id) AS other_users
84 84
 				FROM '.MAIN_DB_PREFIX.'actioncomm AS a';
85
-		if (! $this->user->rights->societe->client->voir )//FIXME si 'voir' on voit plus de chose ?
86
-		{
87
-			$sql.=' LEFT OUTER JOIN '.MAIN_DB_PREFIX.'societe_commerciaux AS sc ON (a.fk_soc = sc.fk_soc AND sc.fk_user='.$this->user->id.')
85
+        if (! $this->user->rights->societe->client->voir )//FIXME si 'voir' on voit plus de chose ?
86
+        {
87
+            $sql.=' LEFT OUTER JOIN '.MAIN_DB_PREFIX.'societe_commerciaux AS sc ON (a.fk_soc = sc.fk_soc AND sc.fk_user='.$this->user->id.')
88 88
 					LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON (s.rowid = sc.fk_soc)
89 89
 					LEFT JOIN '.MAIN_DB_PREFIX.'socpeople AS sp ON (sp.fk_soc = sc.fk_soc AND sp.rowid = a.fk_contact)
90 90
 					LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_cdav AS ac ON (a.id = ac.fk_object)';
91
-		}
92
-		else
93
-		{
94
-			$sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON (s.rowid = a.fk_soc)
91
+        }
92
+        else
93
+        {
94
+            $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON (s.rowid = a.fk_soc)
95 95
 					LEFT JOIN '.MAIN_DB_PREFIX.'socpeople AS sp ON (sp.rowid = a.fk_contact)
96 96
 					LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_cdav AS ac ON (a.id = ac.fk_object)';
97
-		}
97
+        }
98 98
 
99
-		$sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON co.rowid = sp.fk_pays
99
+        $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON co.rowid = sp.fk_pays
100 100
 				LEFT JOIN '.MAIN_DB_PREFIX.'c_country as cos ON cos.rowid = s.fk_pays
101 101
 				WHERE 	a.id IN (SELECT ar.fk_actioncomm FROM '.MAIN_DB_PREFIX.'actioncomm_resources ar WHERE ar.element_type=\'user\' AND ar.fk_element='.intval($calid).')
102 102
 						AND a.code IN (SELECT cac.code FROM '.MAIN_DB_PREFIX.'c_actioncomm cac WHERE cac.type<>\'systemauto\')
103 103
 						AND a.entity IN ('.getEntity('societe', 1).')';
104
-		if($oid!==false) {
105
-			if($ouri===false)
106
-			{
107
-				$sql.=' AND a.id = '.intval($oid);
108
-			}
109
-			else
110
-			{
111
-				$sql.=' AND (a.id = '.intval($oid).' OR ac.uuidext = \''.$this->db->escape($ouri).'\')';
112
-			}
113
-		}
104
+        if($oid!==false) {
105
+            if($ouri===false)
106
+            {
107
+                $sql.=' AND a.id = '.intval($oid);
108
+            }
109
+            else
110
+            {
111
+                $sql.=' AND (a.id = '.intval($oid).' OR ac.uuidext = \''.$this->db->escape($ouri).'\')';
112
+            }
113
+        }
114 114
 
115
-		return $sql;
116
-	}
115
+        return $sql;
116
+    }
117 117
 
118
-	/**
119
-	 * Convert calendar row to VCalendar string
120
-	 *
121
-	 * @param 	int		$calid		Calendar id
122
-	 * @param	Object	$obj		Object id
123
-	 * @return string
124
-	 */
125
-	public function toVCalendar($calid, $obj)
126
-	{
127
-		/*$categ = array();
118
+    /**
119
+     * Convert calendar row to VCalendar string
120
+     *
121
+     * @param 	int		$calid		Calendar id
122
+     * @param	Object	$obj		Object id
123
+     * @return string
124
+     */
125
+    public function toVCalendar($calid, $obj)
126
+    {
127
+        /*$categ = array();
128 128
 		if($obj->soc_client)
129 129
 		{
130 130
 			$nick[] = $obj->soc_code_client;
131 131
 			$categ[] = $this->langs->transnoentitiesnoconv('Customer');
132 132
 		}*/
133 133
 
134
-		$location=$obj->location;
134
+        $location=$obj->location;
135 135
 
136
-		// contact address
137
-		if(empty($location) && !empty($obj->address))
138
-		{
139
-			$location = trim(str_replace(array("\r","\t","\n"),' ', $obj->address));
140
-			$location = trim($location.', '.$obj->zip);
141
-			$location = trim($location.' '.$obj->town);
142
-			$location = trim($location.', '.$obj->country_label);
143
-		}
136
+        // contact address
137
+        if(empty($location) && !empty($obj->address))
138
+        {
139
+            $location = trim(str_replace(array("\r","\t","\n"),' ', $obj->address));
140
+            $location = trim($location.', '.$obj->zip);
141
+            $location = trim($location.' '.$obj->town);
142
+            $location = trim($location.', '.$obj->country_label);
143
+        }
144 144
 
145
-		// contact address
146
-		if(empty($location) && !empty($obj->soc_address))
147
-		{
148
-			$location = trim(str_replace(array("\r","\t","\n"),' ', $obj->soc_address));
149
-			$location = trim($location.', '.$obj->soc_zip);
150
-			$location = trim($location.' '.$obj->soc_town);
151
-			$location = trim($location.', '.$obj->soc_country_label);
152
-		}
145
+        // contact address
146
+        if(empty($location) && !empty($obj->soc_address))
147
+        {
148
+            $location = trim(str_replace(array("\r","\t","\n"),' ', $obj->soc_address));
149
+            $location = trim($location.', '.$obj->soc_zip);
150
+            $location = trim($location.' '.$obj->soc_town);
151
+            $location = trim($location.', '.$obj->soc_country_label);
152
+        }
153 153
 
154
-		$address=explode("\n",$obj->address,2);
155
-		foreach($address as $kAddr => $vAddr)
156
-		{
157
-			$address[$kAddr] = trim(str_replace(array("\r","\t"),' ', str_replace("\n",' | ', trim($vAddr))));
158
-		}
159
-		$address[]='';
160
-		$address[]='';
154
+        $address=explode("\n",$obj->address,2);
155
+        foreach($address as $kAddr => $vAddr)
156
+        {
157
+            $address[$kAddr] = trim(str_replace(array("\r","\t"),' ', str_replace("\n",' | ', trim($vAddr))));
158
+        }
159
+        $address[]='';
160
+        $address[]='';
161 161
 
162
-		if($obj->percent==-1 && trim($obj->datep)!='')
163
-			$type='VEVENT';
164
-		else
165
-			$type='VTODO';
162
+        if($obj->percent==-1 && trim($obj->datep)!='')
163
+            $type='VEVENT';
164
+        else
165
+            $type='VTODO';
166 166
 
167
-		$timezone = date_default_timezone_get();
167
+        $timezone = date_default_timezone_get();
168 168
 
169
-		$caldata ="BEGIN:VCALENDAR\n";
170
-		$caldata.="VERSION:2.0\n";
171
-		$caldata.="METHOD:PUBLISH\n";
172
-		$caldata.="PRODID:-//Dolibarr CDav//FR\n";
173
-		$caldata.="BEGIN:".$type."\n";
174
-		$caldata.="CREATED:".gmdate('Ymd\THis', strtotime($obj->datec))."Z\n";
175
-		$caldata.="LAST-MODIFIED:".gmdate('Ymd\THis', strtotime($obj->lastupd))."Z\n";
176
-		$caldata.="DTSTAMP:".gmdate('Ymd\THis', strtotime($obj->lastupd))."Z\n";
177
-		if($obj->sourceuid=='')
178
-			$caldata.="UID:".$obj->id.'-ev-'.$calid.'-cal-'.CDAV_URI_KEY."\n";
179
-		else
180
-			$caldata.="UID:".$obj->sourceuid."\n";
181
-		$caldata.="SUMMARY:".$obj->label."\n";
182
-		$caldata.="LOCATION:".$location."\n";
183
-		$caldata.="PRIORITY:".$obj->priority."\n";
184
-		if($obj->fulldayevent)
185
-		{
186
-			$caldata.="DTSTART;VALUE=DATE:".date('Ymd', strtotime($obj->datep))."\n";
187
-			if($type=='VEVENT')
188
-			{
189
-				if(trim($obj->datep2)!='')
190
-					$caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n";
191
-				else
192
-					$caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep)+(25*3600))."\n";
193
-			}
194
-			elseif(trim($obj->datep2)!='')
195
-				$caldata.="DUE;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n";
196
-		}
197
-		else
198
-		{
199
-			$caldata.="DTSTART;TZID=".$timezone.":".strtr($obj->datep,array(" "=>"T", ":"=>"", "-"=>""))."\n";
200
-			if($type=='VEVENT')
201
-			{
202
-				if(trim($obj->datep2)!='')
203
-					$caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n";
204
-				else
205
-					$caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep,array(" "=>"T", ":"=>"", "-"=>""))."\n";
206
-			}
207
-			elseif(trim($obj->datep2)!='')
208
-				$caldata.="DUE;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n";
209
-		}
210
-		$caldata.="CLASS:PUBLIC\n";
211
-		if($obj->transparency==1)
212
-			$caldata.="TRANSP:TRANSPARENT\n";
213
-		else
214
-			$caldata.="TRANSP:OPAQUE\n";
169
+        $caldata ="BEGIN:VCALENDAR\n";
170
+        $caldata.="VERSION:2.0\n";
171
+        $caldata.="METHOD:PUBLISH\n";
172
+        $caldata.="PRODID:-//Dolibarr CDav//FR\n";
173
+        $caldata.="BEGIN:".$type."\n";
174
+        $caldata.="CREATED:".gmdate('Ymd\THis', strtotime($obj->datec))."Z\n";
175
+        $caldata.="LAST-MODIFIED:".gmdate('Ymd\THis', strtotime($obj->lastupd))."Z\n";
176
+        $caldata.="DTSTAMP:".gmdate('Ymd\THis', strtotime($obj->lastupd))."Z\n";
177
+        if($obj->sourceuid=='')
178
+            $caldata.="UID:".$obj->id.'-ev-'.$calid.'-cal-'.CDAV_URI_KEY."\n";
179
+        else
180
+            $caldata.="UID:".$obj->sourceuid."\n";
181
+        $caldata.="SUMMARY:".$obj->label."\n";
182
+        $caldata.="LOCATION:".$location."\n";
183
+        $caldata.="PRIORITY:".$obj->priority."\n";
184
+        if($obj->fulldayevent)
185
+        {
186
+            $caldata.="DTSTART;VALUE=DATE:".date('Ymd', strtotime($obj->datep))."\n";
187
+            if($type=='VEVENT')
188
+            {
189
+                if(trim($obj->datep2)!='')
190
+                    $caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n";
191
+                else
192
+                    $caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep)+(25*3600))."\n";
193
+            }
194
+            elseif(trim($obj->datep2)!='')
195
+                $caldata.="DUE;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n";
196
+        }
197
+        else
198
+        {
199
+            $caldata.="DTSTART;TZID=".$timezone.":".strtr($obj->datep,array(" "=>"T", ":"=>"", "-"=>""))."\n";
200
+            if($type=='VEVENT')
201
+            {
202
+                if(trim($obj->datep2)!='')
203
+                    $caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n";
204
+                else
205
+                    $caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep,array(" "=>"T", ":"=>"", "-"=>""))."\n";
206
+            }
207
+            elseif(trim($obj->datep2)!='')
208
+                $caldata.="DUE;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n";
209
+        }
210
+        $caldata.="CLASS:PUBLIC\n";
211
+        if($obj->transparency==1)
212
+            $caldata.="TRANSP:TRANSPARENT\n";
213
+        else
214
+            $caldata.="TRANSP:OPAQUE\n";
215 215
 
216
-		if($type=='VEVENT')
217
-			$caldata.="STATUS:CONFIRMED\n";
218
-		elseif($obj->percent==0)
219
-			$caldata.="STATUS:NEEDS-ACTION\n";
220
-		elseif($obj->percent==100)
221
-			$caldata.="STATUS:COMPLETED\n";
222
-		else
223
-		{
224
-			$caldata.="STATUS:IN-PROCESS\n";
225
-			$caldata.="PERCENT-COMPLETE:".$obj->percent."\n";
226
-		}
216
+        if($type=='VEVENT')
217
+            $caldata.="STATUS:CONFIRMED\n";
218
+        elseif($obj->percent==0)
219
+            $caldata.="STATUS:NEEDS-ACTION\n";
220
+        elseif($obj->percent==100)
221
+            $caldata.="STATUS:COMPLETED\n";
222
+        else
223
+        {
224
+            $caldata.="STATUS:IN-PROCESS\n";
225
+            $caldata.="PERCENT-COMPLETE:".$obj->percent."\n";
226
+        }
227 227
 
228
-		$caldata.="DESCRIPTION:";
229
-		$caldata.=strtr($obj->note, array("\n"=>"\\n", "\r"=>""));
230
-		if(!empty($obj->soc_nom))
231
-			$caldata.="\\n*DOLIBARR-SOC: ".$obj->soc_nom;
232
-		if(!empty($obj->soc_phone))
233
-			$caldata.="\\n*DOLIBARR-SOC-TEL: ".$obj->soc_phone;
234
-		if(!empty($obj->firstname) || !empty($obj->lastname))
235
-			$caldata.="\\n*DOLIBARR-CTC: ".trim($obj->firstname.' '.$obj->lastname);
236
-		if(!empty($obj->phone) || !empty($obj->phone_perso) || !empty($obj->phone_mobile))
237
-			$caldata.="\\n*DOLIBARR-CTC-TEL: ".trim($obj->phone.' '.$obj->phone_perso.' '.$obj->phone_mobile);
238
-		if(strpos($obj->other_users,',')) // several
239
-			$caldata.="\\n*DOLIBARR-USR: ".$obj->other_users;
240
-		$caldata.="\n";
228
+        $caldata.="DESCRIPTION:";
229
+        $caldata.=strtr($obj->note, array("\n"=>"\\n", "\r"=>""));
230
+        if(!empty($obj->soc_nom))
231
+            $caldata.="\\n*DOLIBARR-SOC: ".$obj->soc_nom;
232
+        if(!empty($obj->soc_phone))
233
+            $caldata.="\\n*DOLIBARR-SOC-TEL: ".$obj->soc_phone;
234
+        if(!empty($obj->firstname) || !empty($obj->lastname))
235
+            $caldata.="\\n*DOLIBARR-CTC: ".trim($obj->firstname.' '.$obj->lastname);
236
+        if(!empty($obj->phone) || !empty($obj->phone_perso) || !empty($obj->phone_mobile))
237
+            $caldata.="\\n*DOLIBARR-CTC-TEL: ".trim($obj->phone.' '.$obj->phone_perso.' '.$obj->phone_mobile);
238
+        if(strpos($obj->other_users,',')) // several
239
+            $caldata.="\\n*DOLIBARR-USR: ".$obj->other_users;
240
+        $caldata.="\n";
241 241
 
242
-		$caldata.="END:".$type."\n";
243
-		$caldata.="END:VCALENDAR\n";
242
+        $caldata.="END:".$type."\n";
243
+        $caldata.="END:VCALENDAR\n";
244 244
 
245
-		return $caldata;
246
-	}
245
+        return $caldata;
246
+    }
247 247
 
248
-	/**
249
-	 * getFullCalendarObjects
250
-	 *
251
-	 * @param int	 	$calendarId			Calendar id
252
-	 * @param int		$bCalendarData		Add calendar data
253
-	 * @return array|string[][]
254
-	 */
255
-	public function getFullCalendarObjects($calendarId, $bCalendarData)
256
-	{
257
-		$calid = ($calendarId*1);
258
-		$calevents = array();
248
+    /**
249
+     * getFullCalendarObjects
250
+     *
251
+     * @param int	 	$calendarId			Calendar id
252
+     * @param int		$bCalendarData		Add calendar data
253
+     * @return array|string[][]
254
+     */
255
+    public function getFullCalendarObjects($calendarId, $bCalendarData)
256
+    {
257
+        $calid = ($calendarId*1);
258
+        $calevents = array();
259 259
 
260
-		if(! $this->user->rights->agenda->myactions->read)
261
-			return $calevents;
260
+        if(! $this->user->rights->agenda->myactions->read)
261
+            return $calevents;
262 262
 
263
-		if($calid!=$this->user->id && (!isset($this->user->rights->agenda->allactions->read) || !$this->user->rights->agenda->allactions->read))
264
-			return $calevents;
263
+        if($calid!=$this->user->id && (!isset($this->user->rights->agenda->allactions->read) || !$this->user->rights->agenda->allactions->read))
264
+            return $calevents;
265 265
 
266
-		$sql = $this->getSqlCalEvents($calid);
266
+        $sql = $this->getSqlCalEvents($calid);
267 267
 
268
-		$result = $this->db->query($sql);
268
+        $result = $this->db->query($sql);
269 269
 
270
-		if ($result)
271
-		{
272
-			while ($obj = $this->db->fetch_object($result))
273
-			{
274
-				$calendardata = $this->toVCalendar($calid, $obj);
270
+        if ($result)
271
+        {
272
+            while ($obj = $this->db->fetch_object($result))
273
+            {
274
+                $calendardata = $this->toVCalendar($calid, $obj);
275 275
 
276
-				if($bCalendarData)
277
-				{
278
-					$calevents[] = array(
279
-						'calendardata' => $calendardata,
280
-						'uri' => $obj->id.'-ev-'.CDAV_URI_KEY,
281
-						'lastmodified' => strtotime($obj->lastupd),
282
-						'etag' => '"'.md5($calendardata).'"',
283
-						'calendarid'   => $calendarId,
284
-						'size' => strlen($calendardata),
285
-						'component' => strpos($calendardata, 'BEGIN:VEVENT')>0 ? 'vevent' : 'vtodo',
286
-					);
287
-				}
288
-				else
289
-				{
290
-					$calevents[] = array(
291
-						// 'calendardata' => $calendardata,  not necessary because etag+size are present
292
-						'uri' => $obj->id.'-ev-'.CDAV_URI_KEY,
293
-						'lastmodified' => strtotime($obj->lastupd),
294
-						'etag' => '"'.md5($calendardata).'"',
295
-						'calendarid'   => $calendarId,
296
-						'size' => strlen($calendardata),
297
-						'component' => strpos($calendardata, 'BEGIN:VEVENT')>0 ? 'vevent' : 'vtodo',
298
-					);
299
-				}
300
-			}
301
-		}
302
-		return $calevents;
303
-	}
276
+                if($bCalendarData)
277
+                {
278
+                    $calevents[] = array(
279
+                        'calendardata' => $calendardata,
280
+                        'uri' => $obj->id.'-ev-'.CDAV_URI_KEY,
281
+                        'lastmodified' => strtotime($obj->lastupd),
282
+                        'etag' => '"'.md5($calendardata).'"',
283
+                        'calendarid'   => $calendarId,
284
+                        'size' => strlen($calendardata),
285
+                        'component' => strpos($calendardata, 'BEGIN:VEVENT')>0 ? 'vevent' : 'vtodo',
286
+                    );
287
+                }
288
+                else
289
+                {
290
+                    $calevents[] = array(
291
+                        // 'calendardata' => $calendardata,  not necessary because etag+size are present
292
+                        'uri' => $obj->id.'-ev-'.CDAV_URI_KEY,
293
+                        'lastmodified' => strtotime($obj->lastupd),
294
+                        'etag' => '"'.md5($calendardata).'"',
295
+                        'calendarid'   => $calendarId,
296
+                        'size' => strlen($calendardata),
297
+                        'component' => strpos($calendardata, 'BEGIN:VEVENT')>0 ? 'vevent' : 'vtodo',
298
+                    );
299
+                }
300
+            }
301
+        }
302
+        return $calevents;
303
+    }
304 304
 }
Please login to merge, or discard this patch.
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	 * @param	int|boolean	$ouri			Ouri
57 57
 	 * @return string
58 58
 	 */
59
-	public function getSqlCalEvents($calid, $oid=false, $ouri=false)
59
+	public function getSqlCalEvents($calid, $oid = false, $ouri = false)
60 60
 	{
61 61
 		// TODO : replace GROUP_CONCAT by
62 62
 		$sql = 'SELECT
@@ -82,33 +82,33 @@  discard block
 block discarded – undo
82 82
 						LEFT OUTER JOIN '.MAIN_DB_PREFIX.'user AS u ON (u.rowid=fk_element)
83 83
 						WHERE ar.element_type=\'user\' AND fk_actioncomm=a.id) AS other_users
84 84
 				FROM '.MAIN_DB_PREFIX.'actioncomm AS a';
85
-		if (! $this->user->rights->societe->client->voir )//FIXME si 'voir' on voit plus de chose ?
85
+		if (!$this->user->rights->societe->client->voir)//FIXME si 'voir' on voit plus de chose ?
86 86
 		{
87
-			$sql.=' LEFT OUTER JOIN '.MAIN_DB_PREFIX.'societe_commerciaux AS sc ON (a.fk_soc = sc.fk_soc AND sc.fk_user='.$this->user->id.')
87
+			$sql .= ' LEFT OUTER JOIN '.MAIN_DB_PREFIX.'societe_commerciaux AS sc ON (a.fk_soc = sc.fk_soc AND sc.fk_user='.$this->user->id.')
88 88
 					LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON (s.rowid = sc.fk_soc)
89 89
 					LEFT JOIN '.MAIN_DB_PREFIX.'socpeople AS sp ON (sp.fk_soc = sc.fk_soc AND sp.rowid = a.fk_contact)
90 90
 					LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_cdav AS ac ON (a.id = ac.fk_object)';
91 91
 		}
92 92
 		else
93 93
 		{
94
-			$sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON (s.rowid = a.fk_soc)
94
+			$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON (s.rowid = a.fk_soc)
95 95
 					LEFT JOIN '.MAIN_DB_PREFIX.'socpeople AS sp ON (sp.rowid = a.fk_contact)
96 96
 					LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_cdav AS ac ON (a.id = ac.fk_object)';
97 97
 		}
98 98
 
99
-		$sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON co.rowid = sp.fk_pays
99
+		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON co.rowid = sp.fk_pays
100 100
 				LEFT JOIN '.MAIN_DB_PREFIX.'c_country as cos ON cos.rowid = s.fk_pays
101 101
 				WHERE 	a.id IN (SELECT ar.fk_actioncomm FROM '.MAIN_DB_PREFIX.'actioncomm_resources ar WHERE ar.element_type=\'user\' AND ar.fk_element='.intval($calid).')
102 102
 						AND a.code IN (SELECT cac.code FROM '.MAIN_DB_PREFIX.'c_actioncomm cac WHERE cac.type<>\'systemauto\')
103 103
 						AND a.entity IN ('.getEntity('societe', 1).')';
104
-		if($oid!==false) {
105
-			if($ouri===false)
104
+		if ($oid !== false) {
105
+			if ($ouri === false)
106 106
 			{
107
-				$sql.=' AND a.id = '.intval($oid);
107
+				$sql .= ' AND a.id = '.intval($oid);
108 108
 			}
109 109
 			else
110 110
 			{
111
-				$sql.=' AND (a.id = '.intval($oid).' OR ac.uuidext = \''.$this->db->escape($ouri).'\')';
111
+				$sql .= ' AND (a.id = '.intval($oid).' OR ac.uuidext = \''.$this->db->escape($ouri).'\')';
112 112
 			}
113 113
 		}
114 114
 
@@ -131,116 +131,116 @@  discard block
 block discarded – undo
131 131
 			$categ[] = $this->langs->transnoentitiesnoconv('Customer');
132 132
 		}*/
133 133
 
134
-		$location=$obj->location;
134
+		$location = $obj->location;
135 135
 
136 136
 		// contact address
137
-		if(empty($location) && !empty($obj->address))
137
+		if (empty($location) && !empty($obj->address))
138 138
 		{
139
-			$location = trim(str_replace(array("\r","\t","\n"),' ', $obj->address));
139
+			$location = trim(str_replace(array("\r", "\t", "\n"), ' ', $obj->address));
140 140
 			$location = trim($location.', '.$obj->zip);
141 141
 			$location = trim($location.' '.$obj->town);
142 142
 			$location = trim($location.', '.$obj->country_label);
143 143
 		}
144 144
 
145 145
 		// contact address
146
-		if(empty($location) && !empty($obj->soc_address))
146
+		if (empty($location) && !empty($obj->soc_address))
147 147
 		{
148
-			$location = trim(str_replace(array("\r","\t","\n"),' ', $obj->soc_address));
148
+			$location = trim(str_replace(array("\r", "\t", "\n"), ' ', $obj->soc_address));
149 149
 			$location = trim($location.', '.$obj->soc_zip);
150 150
 			$location = trim($location.' '.$obj->soc_town);
151 151
 			$location = trim($location.', '.$obj->soc_country_label);
152 152
 		}
153 153
 
154
-		$address=explode("\n",$obj->address,2);
155
-		foreach($address as $kAddr => $vAddr)
154
+		$address = explode("\n", $obj->address, 2);
155
+		foreach ($address as $kAddr => $vAddr)
156 156
 		{
157
-			$address[$kAddr] = trim(str_replace(array("\r","\t"),' ', str_replace("\n",' | ', trim($vAddr))));
157
+			$address[$kAddr] = trim(str_replace(array("\r", "\t"), ' ', str_replace("\n", ' | ', trim($vAddr))));
158 158
 		}
159
-		$address[]='';
160
-		$address[]='';
159
+		$address[] = '';
160
+		$address[] = '';
161 161
 
162
-		if($obj->percent==-1 && trim($obj->datep)!='')
163
-			$type='VEVENT';
162
+		if ($obj->percent == -1 && trim($obj->datep) != '')
163
+			$type = 'VEVENT';
164 164
 		else
165
-			$type='VTODO';
165
+			$type = 'VTODO';
166 166
 
167 167
 		$timezone = date_default_timezone_get();
168 168
 
169
-		$caldata ="BEGIN:VCALENDAR\n";
170
-		$caldata.="VERSION:2.0\n";
171
-		$caldata.="METHOD:PUBLISH\n";
172
-		$caldata.="PRODID:-//Dolibarr CDav//FR\n";
173
-		$caldata.="BEGIN:".$type."\n";
174
-		$caldata.="CREATED:".gmdate('Ymd\THis', strtotime($obj->datec))."Z\n";
175
-		$caldata.="LAST-MODIFIED:".gmdate('Ymd\THis', strtotime($obj->lastupd))."Z\n";
176
-		$caldata.="DTSTAMP:".gmdate('Ymd\THis', strtotime($obj->lastupd))."Z\n";
177
-		if($obj->sourceuid=='')
178
-			$caldata.="UID:".$obj->id.'-ev-'.$calid.'-cal-'.CDAV_URI_KEY."\n";
169
+		$caldata = "BEGIN:VCALENDAR\n";
170
+		$caldata .= "VERSION:2.0\n";
171
+		$caldata .= "METHOD:PUBLISH\n";
172
+		$caldata .= "PRODID:-//Dolibarr CDav//FR\n";
173
+		$caldata .= "BEGIN:".$type."\n";
174
+		$caldata .= "CREATED:".gmdate('Ymd\THis', strtotime($obj->datec))."Z\n";
175
+		$caldata .= "LAST-MODIFIED:".gmdate('Ymd\THis', strtotime($obj->lastupd))."Z\n";
176
+		$caldata .= "DTSTAMP:".gmdate('Ymd\THis', strtotime($obj->lastupd))."Z\n";
177
+		if ($obj->sourceuid == '')
178
+			$caldata .= "UID:".$obj->id.'-ev-'.$calid.'-cal-'.CDAV_URI_KEY."\n";
179 179
 		else
180
-			$caldata.="UID:".$obj->sourceuid."\n";
181
-		$caldata.="SUMMARY:".$obj->label."\n";
182
-		$caldata.="LOCATION:".$location."\n";
183
-		$caldata.="PRIORITY:".$obj->priority."\n";
184
-		if($obj->fulldayevent)
180
+			$caldata .= "UID:".$obj->sourceuid."\n";
181
+		$caldata .= "SUMMARY:".$obj->label."\n";
182
+		$caldata .= "LOCATION:".$location."\n";
183
+		$caldata .= "PRIORITY:".$obj->priority."\n";
184
+		if ($obj->fulldayevent)
185 185
 		{
186
-			$caldata.="DTSTART;VALUE=DATE:".date('Ymd', strtotime($obj->datep))."\n";
187
-			if($type=='VEVENT')
186
+			$caldata .= "DTSTART;VALUE=DATE:".date('Ymd', strtotime($obj->datep))."\n";
187
+			if ($type == 'VEVENT')
188 188
 			{
189
-				if(trim($obj->datep2)!='')
190
-					$caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n";
189
+				if (trim($obj->datep2) != '')
190
+					$caldata .= "DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep2) + 1)."\n";
191 191
 				else
192
-					$caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep)+(25*3600))."\n";
192
+					$caldata .= "DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep) + (25 * 3600))."\n";
193 193
 			}
194
-			elseif(trim($obj->datep2)!='')
195
-				$caldata.="DUE;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n";
194
+			elseif (trim($obj->datep2) != '')
195
+				$caldata .= "DUE;VALUE=DATE:".date('Ymd', strtotime($obj->datep2) + 1)."\n";
196 196
 		}
197 197
 		else
198 198
 		{
199
-			$caldata.="DTSTART;TZID=".$timezone.":".strtr($obj->datep,array(" "=>"T", ":"=>"", "-"=>""))."\n";
200
-			if($type=='VEVENT')
199
+			$caldata .= "DTSTART;TZID=".$timezone.":".strtr($obj->datep, array(" "=>"T", ":"=>"", "-"=>""))."\n";
200
+			if ($type == 'VEVENT')
201 201
 			{
202
-				if(trim($obj->datep2)!='')
203
-					$caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n";
202
+				if (trim($obj->datep2) != '')
203
+					$caldata .= "DTEND;TZID=".$timezone.":".strtr($obj->datep2, array(" "=>"T", ":"=>"", "-"=>""))."\n";
204 204
 				else
205
-					$caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep,array(" "=>"T", ":"=>"", "-"=>""))."\n";
205
+					$caldata .= "DTEND;TZID=".$timezone.":".strtr($obj->datep, array(" "=>"T", ":"=>"", "-"=>""))."\n";
206 206
 			}
207
-			elseif(trim($obj->datep2)!='')
208
-				$caldata.="DUE;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n";
207
+			elseif (trim($obj->datep2) != '')
208
+				$caldata .= "DUE;TZID=".$timezone.":".strtr($obj->datep2, array(" "=>"T", ":"=>"", "-"=>""))."\n";
209 209
 		}
210
-		$caldata.="CLASS:PUBLIC\n";
211
-		if($obj->transparency==1)
212
-			$caldata.="TRANSP:TRANSPARENT\n";
210
+		$caldata .= "CLASS:PUBLIC\n";
211
+		if ($obj->transparency == 1)
212
+			$caldata .= "TRANSP:TRANSPARENT\n";
213 213
 		else
214
-			$caldata.="TRANSP:OPAQUE\n";
214
+			$caldata .= "TRANSP:OPAQUE\n";
215 215
 
216
-		if($type=='VEVENT')
217
-			$caldata.="STATUS:CONFIRMED\n";
218
-		elseif($obj->percent==0)
219
-			$caldata.="STATUS:NEEDS-ACTION\n";
220
-		elseif($obj->percent==100)
221
-			$caldata.="STATUS:COMPLETED\n";
216
+		if ($type == 'VEVENT')
217
+			$caldata .= "STATUS:CONFIRMED\n";
218
+		elseif ($obj->percent == 0)
219
+			$caldata .= "STATUS:NEEDS-ACTION\n";
220
+		elseif ($obj->percent == 100)
221
+			$caldata .= "STATUS:COMPLETED\n";
222 222
 		else
223 223
 		{
224
-			$caldata.="STATUS:IN-PROCESS\n";
225
-			$caldata.="PERCENT-COMPLETE:".$obj->percent."\n";
224
+			$caldata .= "STATUS:IN-PROCESS\n";
225
+			$caldata .= "PERCENT-COMPLETE:".$obj->percent."\n";
226 226
 		}
227 227
 
228
-		$caldata.="DESCRIPTION:";
229
-		$caldata.=strtr($obj->note, array("\n"=>"\\n", "\r"=>""));
230
-		if(!empty($obj->soc_nom))
231
-			$caldata.="\\n*DOLIBARR-SOC: ".$obj->soc_nom;
232
-		if(!empty($obj->soc_phone))
233
-			$caldata.="\\n*DOLIBARR-SOC-TEL: ".$obj->soc_phone;
234
-		if(!empty($obj->firstname) || !empty($obj->lastname))
235
-			$caldata.="\\n*DOLIBARR-CTC: ".trim($obj->firstname.' '.$obj->lastname);
236
-		if(!empty($obj->phone) || !empty($obj->phone_perso) || !empty($obj->phone_mobile))
237
-			$caldata.="\\n*DOLIBARR-CTC-TEL: ".trim($obj->phone.' '.$obj->phone_perso.' '.$obj->phone_mobile);
238
-		if(strpos($obj->other_users,',')) // several
239
-			$caldata.="\\n*DOLIBARR-USR: ".$obj->other_users;
240
-		$caldata.="\n";
228
+		$caldata .= "DESCRIPTION:";
229
+		$caldata .= strtr($obj->note, array("\n"=>"\\n", "\r"=>""));
230
+		if (!empty($obj->soc_nom))
231
+			$caldata .= "\\n*DOLIBARR-SOC: ".$obj->soc_nom;
232
+		if (!empty($obj->soc_phone))
233
+			$caldata .= "\\n*DOLIBARR-SOC-TEL: ".$obj->soc_phone;
234
+		if (!empty($obj->firstname) || !empty($obj->lastname))
235
+			$caldata .= "\\n*DOLIBARR-CTC: ".trim($obj->firstname.' '.$obj->lastname);
236
+		if (!empty($obj->phone) || !empty($obj->phone_perso) || !empty($obj->phone_mobile))
237
+			$caldata .= "\\n*DOLIBARR-CTC-TEL: ".trim($obj->phone.' '.$obj->phone_perso.' '.$obj->phone_mobile);
238
+		if (strpos($obj->other_users, ',')) // several
239
+			$caldata .= "\\n*DOLIBARR-USR: ".$obj->other_users;
240
+		$caldata .= "\n";
241 241
 
242
-		$caldata.="END:".$type."\n";
243
-		$caldata.="END:VCALENDAR\n";
242
+		$caldata .= "END:".$type."\n";
243
+		$caldata .= "END:VCALENDAR\n";
244 244
 
245 245
 		return $caldata;
246 246
 	}
@@ -254,13 +254,13 @@  discard block
 block discarded – undo
254 254
 	 */
255 255
 	public function getFullCalendarObjects($calendarId, $bCalendarData)
256 256
 	{
257
-		$calid = ($calendarId*1);
257
+		$calid = ($calendarId * 1);
258 258
 		$calevents = array();
259 259
 
260
-		if(! $this->user->rights->agenda->myactions->read)
260
+		if (!$this->user->rights->agenda->myactions->read)
261 261
 			return $calevents;
262 262
 
263
-		if($calid!=$this->user->id && (!isset($this->user->rights->agenda->allactions->read) || !$this->user->rights->agenda->allactions->read))
263
+		if ($calid != $this->user->id && (!isset($this->user->rights->agenda->allactions->read) || !$this->user->rights->agenda->allactions->read))
264 264
 			return $calevents;
265 265
 
266 266
 		$sql = $this->getSqlCalEvents($calid);
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 			{
274 274
 				$calendardata = $this->toVCalendar($calid, $obj);
275 275
 
276
-				if($bCalendarData)
276
+				if ($bCalendarData)
277 277
 				{
278 278
 					$calevents[] = array(
279 279
 						'calendardata' => $calendardata,
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 						'etag' => '"'.md5($calendardata).'"',
283 283
 						'calendarid'   => $calendarId,
284 284
 						'size' => strlen($calendardata),
285
-						'component' => strpos($calendardata, 'BEGIN:VEVENT')>0 ? 'vevent' : 'vtodo',
285
+						'component' => strpos($calendardata, 'BEGIN:VEVENT') > 0 ? 'vevent' : 'vtodo',
286 286
 					);
287 287
 				}
288 288
 				else
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 						'etag' => '"'.md5($calendardata).'"',
295 295
 						'calendarid'   => $calendarId,
296 296
 						'size' => strlen($calendardata),
297
-						'component' => strpos($calendardata, 'BEGIN:VEVENT')>0 ? 'vevent' : 'vtodo',
297
+						'component' => strpos($calendardata, 'BEGIN:VEVENT') > 0 ? 'vevent' : 'vtodo',
298 298
 					);
299 299
 				}
300 300
 			}
Please login to merge, or discard this patch.
Braces   +63 added lines, -52 removed lines patch added patch discarded remove patch
@@ -82,14 +82,15 @@  discard block
 block discarded – undo
82 82
 						LEFT OUTER JOIN '.MAIN_DB_PREFIX.'user AS u ON (u.rowid=fk_element)
83 83
 						WHERE ar.element_type=\'user\' AND fk_actioncomm=a.id) AS other_users
84 84
 				FROM '.MAIN_DB_PREFIX.'actioncomm AS a';
85
-		if (! $this->user->rights->societe->client->voir )//FIXME si 'voir' on voit plus de chose ?
85
+		if (! $this->user->rights->societe->client->voir ) {
86
+		    //FIXME si 'voir' on voit plus de chose ?
86 87
 		{
87 88
 			$sql.=' LEFT OUTER JOIN '.MAIN_DB_PREFIX.'societe_commerciaux AS sc ON (a.fk_soc = sc.fk_soc AND sc.fk_user='.$this->user->id.')
88 89
 					LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON (s.rowid = sc.fk_soc)
89 90
 					LEFT JOIN '.MAIN_DB_PREFIX.'socpeople AS sp ON (sp.fk_soc = sc.fk_soc AND sp.rowid = a.fk_contact)
90 91
 					LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_cdav AS ac ON (a.id = ac.fk_object)';
91 92
 		}
92
-		else
93
+		} else
93 94
 		{
94 95
 			$sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON (s.rowid = a.fk_soc)
95 96
 					LEFT JOIN '.MAIN_DB_PREFIX.'socpeople AS sp ON (sp.rowid = a.fk_contact)
@@ -105,8 +106,7 @@  discard block
 block discarded – undo
105 106
 			if($ouri===false)
106 107
 			{
107 108
 				$sql.=' AND a.id = '.intval($oid);
108
-			}
109
-			else
109
+			} else
110 110
 			{
111 111
 				$sql.=' AND (a.id = '.intval($oid).' OR ac.uuidext = \''.$this->db->escape($ouri).'\')';
112 112
 			}
@@ -159,10 +159,11 @@  discard block
 block discarded – undo
159 159
 		$address[]='';
160 160
 		$address[]='';
161 161
 
162
-		if($obj->percent==-1 && trim($obj->datep)!='')
163
-			$type='VEVENT';
164
-		else
165
-			$type='VTODO';
162
+		if($obj->percent==-1 && trim($obj->datep)!='') {
163
+					$type='VEVENT';
164
+		} else {
165
+					$type='VTODO';
166
+		}
166 167
 
167 168
 		$timezone = date_default_timezone_get();
168 169
 
@@ -174,10 +175,11 @@  discard block
 block discarded – undo
174 175
 		$caldata.="CREATED:".gmdate('Ymd\THis', strtotime($obj->datec))."Z\n";
175 176
 		$caldata.="LAST-MODIFIED:".gmdate('Ymd\THis', strtotime($obj->lastupd))."Z\n";
176 177
 		$caldata.="DTSTAMP:".gmdate('Ymd\THis', strtotime($obj->lastupd))."Z\n";
177
-		if($obj->sourceuid=='')
178
-			$caldata.="UID:".$obj->id.'-ev-'.$calid.'-cal-'.CDAV_URI_KEY."\n";
179
-		else
180
-			$caldata.="UID:".$obj->sourceuid."\n";
178
+		if($obj->sourceuid=='') {
179
+					$caldata.="UID:".$obj->id.'-ev-'.$calid.'-cal-'.CDAV_URI_KEY."\n";
180
+		} else {
181
+					$caldata.="UID:".$obj->sourceuid."\n";
182
+		}
181 183
 		$caldata.="SUMMARY:".$obj->label."\n";
182 184
 		$caldata.="LOCATION:".$location."\n";
183 185
 		$caldata.="PRIORITY:".$obj->priority."\n";
@@ -186,40 +188,42 @@  discard block
 block discarded – undo
186 188
 			$caldata.="DTSTART;VALUE=DATE:".date('Ymd', strtotime($obj->datep))."\n";
187 189
 			if($type=='VEVENT')
188 190
 			{
189
-				if(trim($obj->datep2)!='')
190
-					$caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n";
191
-				else
192
-					$caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep)+(25*3600))."\n";
191
+				if(trim($obj->datep2)!='') {
192
+									$caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n";
193
+				} else {
194
+									$caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep)+(25*3600))."\n";
195
+				}
196
+			} elseif(trim($obj->datep2)!='') {
197
+							$caldata.="DUE;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n";
193 198
 			}
194
-			elseif(trim($obj->datep2)!='')
195
-				$caldata.="DUE;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n";
196
-		}
197
-		else
199
+		} else
198 200
 		{
199 201
 			$caldata.="DTSTART;TZID=".$timezone.":".strtr($obj->datep,array(" "=>"T", ":"=>"", "-"=>""))."\n";
200 202
 			if($type=='VEVENT')
201 203
 			{
202
-				if(trim($obj->datep2)!='')
203
-					$caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n";
204
-				else
205
-					$caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep,array(" "=>"T", ":"=>"", "-"=>""))."\n";
204
+				if(trim($obj->datep2)!='') {
205
+									$caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n";
206
+				} else {
207
+									$caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep,array(" "=>"T", ":"=>"", "-"=>""))."\n";
208
+				}
209
+			} elseif(trim($obj->datep2)!='') {
210
+							$caldata.="DUE;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n";
206 211
 			}
207
-			elseif(trim($obj->datep2)!='')
208
-				$caldata.="DUE;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n";
209 212
 		}
210 213
 		$caldata.="CLASS:PUBLIC\n";
211
-		if($obj->transparency==1)
212
-			$caldata.="TRANSP:TRANSPARENT\n";
213
-		else
214
-			$caldata.="TRANSP:OPAQUE\n";
214
+		if($obj->transparency==1) {
215
+					$caldata.="TRANSP:TRANSPARENT\n";
216
+		} else {
217
+					$caldata.="TRANSP:OPAQUE\n";
218
+		}
215 219
 
216
-		if($type=='VEVENT')
217
-			$caldata.="STATUS:CONFIRMED\n";
218
-		elseif($obj->percent==0)
219
-			$caldata.="STATUS:NEEDS-ACTION\n";
220
-		elseif($obj->percent==100)
221
-			$caldata.="STATUS:COMPLETED\n";
222
-		else
220
+		if($type=='VEVENT') {
221
+					$caldata.="STATUS:CONFIRMED\n";
222
+		} elseif($obj->percent==0) {
223
+					$caldata.="STATUS:NEEDS-ACTION\n";
224
+		} elseif($obj->percent==100) {
225
+					$caldata.="STATUS:COMPLETED\n";
226
+		} else
223 227
 		{
224 228
 			$caldata.="STATUS:IN-PROCESS\n";
225 229
 			$caldata.="PERCENT-COMPLETE:".$obj->percent."\n";
@@ -227,16 +231,22 @@  discard block
 block discarded – undo
227 231
 
228 232
 		$caldata.="DESCRIPTION:";
229 233
 		$caldata.=strtr($obj->note, array("\n"=>"\\n", "\r"=>""));
230
-		if(!empty($obj->soc_nom))
231
-			$caldata.="\\n*DOLIBARR-SOC: ".$obj->soc_nom;
232
-		if(!empty($obj->soc_phone))
233
-			$caldata.="\\n*DOLIBARR-SOC-TEL: ".$obj->soc_phone;
234
-		if(!empty($obj->firstname) || !empty($obj->lastname))
235
-			$caldata.="\\n*DOLIBARR-CTC: ".trim($obj->firstname.' '.$obj->lastname);
236
-		if(!empty($obj->phone) || !empty($obj->phone_perso) || !empty($obj->phone_mobile))
237
-			$caldata.="\\n*DOLIBARR-CTC-TEL: ".trim($obj->phone.' '.$obj->phone_perso.' '.$obj->phone_mobile);
238
-		if(strpos($obj->other_users,',')) // several
234
+		if(!empty($obj->soc_nom)) {
235
+					$caldata.="\\n*DOLIBARR-SOC: ".$obj->soc_nom;
236
+		}
237
+		if(!empty($obj->soc_phone)) {
238
+					$caldata.="\\n*DOLIBARR-SOC-TEL: ".$obj->soc_phone;
239
+		}
240
+		if(!empty($obj->firstname) || !empty($obj->lastname)) {
241
+					$caldata.="\\n*DOLIBARR-CTC: ".trim($obj->firstname.' '.$obj->lastname);
242
+		}
243
+		if(!empty($obj->phone) || !empty($obj->phone_perso) || !empty($obj->phone_mobile)) {
244
+					$caldata.="\\n*DOLIBARR-CTC-TEL: ".trim($obj->phone.' '.$obj->phone_perso.' '.$obj->phone_mobile);
245
+		}
246
+		if(strpos($obj->other_users,',')) {
247
+		    // several
239 248
 			$caldata.="\\n*DOLIBARR-USR: ".$obj->other_users;
249
+		}
240 250
 		$caldata.="\n";
241 251
 
242 252
 		$caldata.="END:".$type."\n";
@@ -257,11 +267,13 @@  discard block
 block discarded – undo
257 267
 		$calid = ($calendarId*1);
258 268
 		$calevents = array();
259 269
 
260
-		if(! $this->user->rights->agenda->myactions->read)
261
-			return $calevents;
270
+		if(! $this->user->rights->agenda->myactions->read) {
271
+					return $calevents;
272
+		}
262 273
 
263
-		if($calid!=$this->user->id && (!isset($this->user->rights->agenda->allactions->read) || !$this->user->rights->agenda->allactions->read))
264
-			return $calevents;
274
+		if($calid!=$this->user->id && (!isset($this->user->rights->agenda->allactions->read) || !$this->user->rights->agenda->allactions->read)) {
275
+					return $calevents;
276
+		}
265 277
 
266 278
 		$sql = $this->getSqlCalEvents($calid);
267 279
 
@@ -284,8 +296,7 @@  discard block
 block discarded – undo
284 296
 						'size' => strlen($calendardata),
285 297
 						'component' => strpos($calendardata, 'BEGIN:VEVENT')>0 ? 'vevent' : 'vtodo',
286 298
 					);
287
-				}
288
-				else
299
+				} else
289 300
 				{
290 301
 					$calevents[] = array(
291 302
 						// 'calendardata' => $calendardata,  not necessary because etag+size are present
Please login to merge, or discard this patch.
dolibarr/htdocs/dav/dav.lib.php 3 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -24,19 +24,19 @@  discard block
 block discarded – undo
24 24
 // define CDAV_CONTACT_TAG if not
25 25
 if(!defined('CDAV_CONTACT_TAG'))
26 26
 {
27
-	if(isset($conf->global->CDAV_CONTACT_TAG))
28
-		define('CDAV_CONTACT_TAG', $conf->global->CDAV_CONTACT_TAG);
29
-		else
30
-			define('CDAV_CONTACT_TAG', '');
27
+    if(isset($conf->global->CDAV_CONTACT_TAG))
28
+        define('CDAV_CONTACT_TAG', $conf->global->CDAV_CONTACT_TAG);
29
+        else
30
+            define('CDAV_CONTACT_TAG', '');
31 31
 }
32 32
 
33 33
 // define CDAV_URI_KEY if not
34 34
 if(!defined('CDAV_URI_KEY'))
35 35
 {
36
-	if(isset($conf->global->CDAV_URI_KEY))
37
-		define('CDAV_URI_KEY', $conf->global->CDAV_URI_KEY);
38
-		else
39
-			define('CDAV_URI_KEY', substr(md5($_SERVER['HTTP_HOST']),0,8));
36
+    if(isset($conf->global->CDAV_URI_KEY))
37
+        define('CDAV_URI_KEY', $conf->global->CDAV_URI_KEY);
38
+        else
39
+            define('CDAV_URI_KEY', substr(md5($_SERVER['HTTP_HOST']),0,8));
40 40
 }
41 41
 
42 42
 
@@ -49,24 +49,24 @@  discard block
 block discarded – undo
49 49
  */
50 50
 function dav_admin_prepare_head()
51 51
 {
52
-	global $db, $langs, $conf;
52
+    global $db, $langs, $conf;
53 53
 
54
-	$h = 0;
55
-	$head = array();
54
+    $h = 0;
55
+    $head = array();
56 56
 
57
-	$head[$h][0] = DOL_URL_ROOT.'/admin/dav.php?id='.$object->id;
58
-	$head[$h][1] = $langs->trans("WebDAV");
59
-	$head[$h][2] = 'webdav';
60
-	$h++;
57
+    $head[$h][0] = DOL_URL_ROOT.'/admin/dav.php?id='.$object->id;
58
+    $head[$h][1] = $langs->trans("WebDAV");
59
+    $head[$h][2] = 'webdav';
60
+    $h++;
61 61
 
62
-	// Show more tabs from modules
63
-	// Entries must be declared in modules descriptor with line
64
-	// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
65
-	// $this->tabs = array('entity:-tabname);   												to remove a tab
66
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'admindav');
62
+    // Show more tabs from modules
63
+    // Entries must be declared in modules descriptor with line
64
+    // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
65
+    // $this->tabs = array('entity:-tabname);   												to remove a tab
66
+    complete_head_from_modules($conf,$langs,$object,$head,$h,'admindav');
67 67
 
68
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'admindav','remove');
68
+    complete_head_from_modules($conf,$langs,$object,$head,$h,'admindav','remove');
69 69
 
70
-	return $head;
70
+    return $head;
71 71
 }
72 72
 
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -22,21 +22,21 @@  discard block
 block discarded – undo
22 22
  */
23 23
 
24 24
 // define CDAV_CONTACT_TAG if not
25
-if(!defined('CDAV_CONTACT_TAG'))
25
+if (!defined('CDAV_CONTACT_TAG'))
26 26
 {
27
-	if(isset($conf->global->CDAV_CONTACT_TAG))
27
+	if (isset($conf->global->CDAV_CONTACT_TAG))
28 28
 		define('CDAV_CONTACT_TAG', $conf->global->CDAV_CONTACT_TAG);
29 29
 		else
30 30
 			define('CDAV_CONTACT_TAG', '');
31 31
 }
32 32
 
33 33
 // define CDAV_URI_KEY if not
34
-if(!defined('CDAV_URI_KEY'))
34
+if (!defined('CDAV_URI_KEY'))
35 35
 {
36
-	if(isset($conf->global->CDAV_URI_KEY))
36
+	if (isset($conf->global->CDAV_URI_KEY))
37 37
 		define('CDAV_URI_KEY', $conf->global->CDAV_URI_KEY);
38 38
 		else
39
-			define('CDAV_URI_KEY', substr(md5($_SERVER['HTTP_HOST']),0,8));
39
+			define('CDAV_URI_KEY', substr(md5($_SERVER['HTTP_HOST']), 0, 8));
40 40
 }
41 41
 
42 42
 
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
 	// Entries must be declared in modules descriptor with line
64 64
 	// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
65 65
 	// $this->tabs = array('entity:-tabname);   												to remove a tab
66
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'admindav');
66
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'admindav');
67 67
 
68
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'admindav','remove');
68
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'admindav', 'remove');
69 69
 
70 70
 	return $head;
71 71
 }
Please login to merge, or discard this patch.
Braces   +12 added lines, -10 removed lines patch added patch discarded remove patch
@@ -24,20 +24,22 @@
 block discarded – undo
24 24
 // define CDAV_CONTACT_TAG if not
25 25
 if(!defined('CDAV_CONTACT_TAG'))
26 26
 {
27
-	if(isset($conf->global->CDAV_CONTACT_TAG))
28
-		define('CDAV_CONTACT_TAG', $conf->global->CDAV_CONTACT_TAG);
29
-		else
30
-			define('CDAV_CONTACT_TAG', '');
31
-}
27
+	if(isset($conf->global->CDAV_CONTACT_TAG)) {
28
+			define('CDAV_CONTACT_TAG', $conf->global->CDAV_CONTACT_TAG);
29
+	} else {
30
+					define('CDAV_CONTACT_TAG', '');
31
+		}
32
+		}
32 33
 
33 34
 // define CDAV_URI_KEY if not
34 35
 if(!defined('CDAV_URI_KEY'))
35 36
 {
36
-	if(isset($conf->global->CDAV_URI_KEY))
37
-		define('CDAV_URI_KEY', $conf->global->CDAV_URI_KEY);
38
-		else
39
-			define('CDAV_URI_KEY', substr(md5($_SERVER['HTTP_HOST']),0,8));
40
-}
37
+	if(isset($conf->global->CDAV_URI_KEY)) {
38
+			define('CDAV_URI_KEY', $conf->global->CDAV_URI_KEY);
39
+	} else {
40
+					define('CDAV_URI_KEY', substr(md5($_SERVER['HTTP_HOST']),0,8));
41
+		}
42
+		}
41 43
 
42 44
 
43 45
 
Please login to merge, or discard this patch.
dolibarr/htdocs/dav/fileserver.php 3 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -39,8 +39,8 @@  discard block
 block discarded – undo
39 39
 $user = new User($db);
40 40
 if(isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_USER']!='')
41 41
 {
42
-	$user->fetch('',$_SERVER['PHP_AUTH_USER']);
43
-	$user->getrights();
42
+    $user->fetch('',$_SERVER['PHP_AUTH_USER']);
43
+    $user->getrights();
44 44
 }
45 45
 
46 46
 // Load translation files required by the page
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 
49 49
 
50 50
 if(empty($conf->dav->enabled))
51
-	accessforbidden();
51
+    accessforbidden();
52 52
 
53 53
 
54 54
 // settings
@@ -59,27 +59,27 @@  discard block
 block discarded – undo
59 59
 
60 60
 // Authentication callback function
61 61
 $authBackend = new \Sabre\DAV\Auth\Backend\BasicCallBack(function ($username, $password) {
62
-	global $user;
63
-	global $conf;
64
-	global $dolibarr_main_authentication;
65
-
66
-	if (empty($user->login))
67
-		return false;
68
-	if ($user->socid > 0)
69
-		return false;
70
-	if ($user->login != $username)
71
-		return false;
72
-
73
-	// Authentication mode
74
-	if (empty($dolibarr_main_authentication))
75
-		$dolibarr_main_authentication='http,dolibarr';
76
-	$authmode = explode(',',$dolibarr_main_authentication);
77
-	$entity = (GETPOST('entity','int') ? GETPOST('entity','int') : (!empty($conf->entity) ? $conf->entity : 1));
78
-
79
-	if (checkLoginPassEntity($username,$password,$entity,$authmode) != $username)
80
-		return false;
81
-
82
-	return true;
62
+    global $user;
63
+    global $conf;
64
+    global $dolibarr_main_authentication;
65
+
66
+    if (empty($user->login))
67
+        return false;
68
+    if ($user->socid > 0)
69
+        return false;
70
+    if ($user->login != $username)
71
+        return false;
72
+
73
+    // Authentication mode
74
+    if (empty($dolibarr_main_authentication))
75
+        $dolibarr_main_authentication='http,dolibarr';
76
+    $authmode = explode(',',$dolibarr_main_authentication);
77
+    $entity = (GETPOST('entity','int') ? GETPOST('entity','int') : (!empty($conf->entity) ? $conf->entity : 1));
78
+
79
+    if (checkLoginPassEntity($username,$password,$entity,$authmode) != $username)
80
+        return false;
81
+
82
+    return true;
83 83
 });
84 84
 
85 85
 $authBackend->setRealm(constant('DOL_APPLICATION_TITLE'));
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
 // Public dir
101 101
 if (!empty($conf->global->DAV_ALLOW_PUBLIC_DIR))
102 102
 {
103
-	$nodes[] = new \Sabre\DAV\FS\Directory($dolibarr_main_data_root. '/dav/public');
103
+    $nodes[] = new \Sabre\DAV\FS\Directory($dolibarr_main_data_root. '/dav/public');
104 104
 }
105 105
 // Private dir
106 106
 $nodes[] = new \Sabre\DAV\FS\Directory($dolibarr_main_data_root. '/dav/private');
107 107
 // ECM dir
108 108
 if (! empty($conf->ecm->enabled) && ! empty($conf->global->DAV_ALLOW_ECM_DIR))
109 109
 {
110
-	$nodes[] = new \Sabre\DAV\FS\Directory($dolibarr_main_data_root. '/ecm');
110
+    $nodes[] = new \Sabre\DAV\FS\Directory($dolibarr_main_data_root. '/ecm');
111 111
 }
112 112
 
113 113
 
@@ -135,12 +135,12 @@  discard block
 block discarded – undo
135 135
 
136 136
 // Add authentication function
137 137
 if ((empty($conf->global->DAV_ALLOW_PUBLIC_DIR)
138
-	|| ! preg_match('/'.preg_quote(DOL_URL_ROOT.'/dav/fileserver.php/public','/').'/', $_SERVER["PHP_SELF"]))
139
-	&& ! preg_match('/^sabreAction=asset&assetName=[a-zA-Z0-9%\-\/]+\.(png|css|woff|ico|ttf)$/', $_SERVER["QUERY_STRING"])	// URL for Sabre browser resources
140
-	)
138
+    || ! preg_match('/'.preg_quote(DOL_URL_ROOT.'/dav/fileserver.php/public','/').'/', $_SERVER["PHP_SELF"]))
139
+    && ! preg_match('/^sabreAction=asset&assetName=[a-zA-Z0-9%\-\/]+\.(png|css|woff|ico|ttf)$/', $_SERVER["QUERY_STRING"])	// URL for Sabre browser resources
140
+    )
141 141
 {
142
-	//var_dump($_SERVER["QUERY_STRING"]);exit;
143
-	$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend));
142
+    //var_dump($_SERVER["QUERY_STRING"]);exit;
143
+    $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend));
144 144
 }
145 145
 // Support for LOCK and UNLOCK
146 146
 $lockBackend = new \Sabre\DAV\Locks\Backend\File($tmpDir . '/.locksdb');
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -21,12 +21,12 @@  discard block
 block discarded – undo
21 21
  *      \brief      Server DAV
22 22
  */
23 23
 
24
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
25
-if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1'); // If there is no menu to show
26
-if (! defined('NOREQUIREHTML'))  define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
27
-if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
28
-if (! defined('NOLOGIN'))  		 define("NOLOGIN",1);		// This means this output page does not require to be logged.
29
-if (! defined('NOCSRFCHECK'))  	 define("NOCSRFCHECK",1);	// We accept to go on this page from external web site.
24
+if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
25
+if (!defined('NOREQUIREMENU'))  define('NOREQUIREMENU', '1'); // If there is no menu to show
26
+if (!defined('NOREQUIREHTML'))  define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
27
+if (!defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX', '1');
28
+if (!defined('NOLOGIN'))  		 define("NOLOGIN", 1); // This means this output page does not require to be logged.
29
+if (!defined('NOCSRFCHECK'))  	 define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
30 30
 
31 31
 require "../main.inc.php";
32 32
 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
@@ -37,17 +37,17 @@  discard block
 block discarded – undo
37 37
 
38 38
 
39 39
 $user = new User($db);
40
-if(isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_USER']!='')
40
+if (isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_USER'] != '')
41 41
 {
42
-	$user->fetch('',$_SERVER['PHP_AUTH_USER']);
42
+	$user->fetch('', $_SERVER['PHP_AUTH_USER']);
43 43
 	$user->getrights();
44 44
 }
45 45
 
46 46
 // Load translation files required by the page
47
-$langs->loadLangs(array("main","other"));
47
+$langs->loadLangs(array("main", "other"));
48 48
 
49 49
 
50
-if(empty($conf->dav->enabled))
50
+if (empty($conf->dav->enabled))
51 51
 	accessforbidden();
52 52
 
53 53
 
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 //var_dump($tmpDir);exit;
59 59
 
60 60
 // Authentication callback function
61
-$authBackend = new \Sabre\DAV\Auth\Backend\BasicCallBack(function ($username, $password) {
61
+$authBackend = new \Sabre\DAV\Auth\Backend\BasicCallBack(function($username, $password) {
62 62
 	global $user;
63 63
 	global $conf;
64 64
 	global $dolibarr_main_authentication;
@@ -72,11 +72,11 @@  discard block
 block discarded – undo
72 72
 
73 73
 	// Authentication mode
74 74
 	if (empty($dolibarr_main_authentication))
75
-		$dolibarr_main_authentication='http,dolibarr';
76
-	$authmode = explode(',',$dolibarr_main_authentication);
77
-	$entity = (GETPOST('entity','int') ? GETPOST('entity','int') : (!empty($conf->entity) ? $conf->entity : 1));
75
+		$dolibarr_main_authentication = 'http,dolibarr';
76
+	$authmode = explode(',', $dolibarr_main_authentication);
77
+	$entity = (GETPOST('entity', 'int') ? GETPOST('entity', 'int') : (!empty($conf->entity) ? $conf->entity : 1));
78 78
 
79
-	if (checkLoginPassEntity($username,$password,$entity,$authmode) != $username)
79
+	if (checkLoginPassEntity($username, $password, $entity, $authmode) != $username)
80 80
 		return false;
81 81
 
82 82
 	return true;
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
 // Public dir
101 101
 if (!empty($conf->global->DAV_ALLOW_PUBLIC_DIR))
102 102
 {
103
-	$nodes[] = new \Sabre\DAV\FS\Directory($dolibarr_main_data_root. '/dav/public');
103
+	$nodes[] = new \Sabre\DAV\FS\Directory($dolibarr_main_data_root.'/dav/public');
104 104
 }
105 105
 // Private dir
106
-$nodes[] = new \Sabre\DAV\FS\Directory($dolibarr_main_data_root. '/dav/private');
106
+$nodes[] = new \Sabre\DAV\FS\Directory($dolibarr_main_data_root.'/dav/private');
107 107
 // ECM dir
108
-if (! empty($conf->ecm->enabled) && ! empty($conf->global->DAV_ALLOW_ECM_DIR))
108
+if (!empty($conf->ecm->enabled) && !empty($conf->global->DAV_ALLOW_ECM_DIR))
109 109
 {
110
-	$nodes[] = new \Sabre\DAV\FS\Directory($dolibarr_main_data_root. '/ecm');
110
+	$nodes[] = new \Sabre\DAV\FS\Directory($dolibarr_main_data_root.'/ecm');
111 111
 }
112 112
 
113 113
 
@@ -135,15 +135,15 @@  discard block
 block discarded – undo
135 135
 
136 136
 // Add authentication function
137 137
 if ((empty($conf->global->DAV_ALLOW_PUBLIC_DIR)
138
-	|| ! preg_match('/'.preg_quote(DOL_URL_ROOT.'/dav/fileserver.php/public','/').'/', $_SERVER["PHP_SELF"]))
139
-	&& ! preg_match('/^sabreAction=asset&assetName=[a-zA-Z0-9%\-\/]+\.(png|css|woff|ico|ttf)$/', $_SERVER["QUERY_STRING"])	// URL for Sabre browser resources
138
+	|| !preg_match('/'.preg_quote(DOL_URL_ROOT.'/dav/fileserver.php/public', '/').'/', $_SERVER["PHP_SELF"]))
139
+	&& !preg_match('/^sabreAction=asset&assetName=[a-zA-Z0-9%\-\/]+\.(png|css|woff|ico|ttf)$/', $_SERVER["QUERY_STRING"])	// URL for Sabre browser resources
140 140
 	)
141 141
 {
142 142
 	//var_dump($_SERVER["QUERY_STRING"]);exit;
143 143
 	$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend));
144 144
 }
145 145
 // Support for LOCK and UNLOCK
146
-$lockBackend = new \Sabre\DAV\Locks\Backend\File($tmpDir . '/.locksdb');
146
+$lockBackend = new \Sabre\DAV\Locks\Backend\File($tmpDir.'/.locksdb');
147 147
 $lockPlugin = new \Sabre\DAV\Locks\Plugin($lockBackend);
148 148
 $server->addPlugin($lockPlugin);
149 149
 
Please login to merge, or discard this patch.
Braces   +45 added lines, -19 removed lines patch added patch discarded remove patch
@@ -21,12 +21,28 @@  discard block
 block discarded – undo
21 21
  *      \brief      Server DAV
22 22
  */
23 23
 
24
-if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
25
-if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1'); // If there is no menu to show
26
-if (! defined('NOREQUIREHTML'))  define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
27
-if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
28
-if (! defined('NOLOGIN'))  		 define("NOLOGIN",1);		// This means this output page does not require to be logged.
29
-if (! defined('NOCSRFCHECK'))  	 define("NOCSRFCHECK",1);	// We accept to go on this page from external web site.
24
+if (! defined('NOTOKENRENEWAL')) {
25
+    define('NOTOKENRENEWAL','1');
26
+}
27
+if (! defined('NOREQUIREMENU')) {
28
+    define('NOREQUIREMENU','1');
29
+}
30
+// If there is no menu to show
31
+if (! defined('NOREQUIREHTML')) {
32
+    define('NOREQUIREHTML','1');
33
+}
34
+// If we don't need to load the html.form.class.php
35
+if (! defined('NOREQUIREAJAX')) {
36
+    define('NOREQUIREAJAX','1');
37
+}
38
+if (! defined('NOLOGIN')) {
39
+    define("NOLOGIN",1);
40
+}
41
+// This means this output page does not require to be logged.
42
+if (! defined('NOCSRFCHECK')) {
43
+    define("NOCSRFCHECK",1);
44
+}
45
+// We accept to go on this page from external web site.
30 46
 
31 47
 require "../main.inc.php";
32 48
 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
@@ -47,8 +63,9 @@  discard block
 block discarded – undo
47 63
 $langs->loadLangs(array("main","other"));
48 64
 
49 65
 
50
-if(empty($conf->dav->enabled))
66
+if(empty($conf->dav->enabled)) {
51 67
 	accessforbidden();
68
+}
52 69
 
53 70
 
54 71
 // settings
@@ -63,21 +80,26 @@  discard block
 block discarded – undo
63 80
 	global $conf;
64 81
 	global $dolibarr_main_authentication;
65 82
 
66
-	if (empty($user->login))
67
-		return false;
68
-	if ($user->socid > 0)
69
-		return false;
70
-	if ($user->login != $username)
71
-		return false;
83
+	if (empty($user->login)) {
84
+			return false;
85
+	}
86
+	if ($user->socid > 0) {
87
+			return false;
88
+	}
89
+	if ($user->login != $username) {
90
+			return false;
91
+	}
72 92
 
73 93
 	// Authentication mode
74
-	if (empty($dolibarr_main_authentication))
75
-		$dolibarr_main_authentication='http,dolibarr';
94
+	if (empty($dolibarr_main_authentication)) {
95
+			$dolibarr_main_authentication='http,dolibarr';
96
+	}
76 97
 	$authmode = explode(',',$dolibarr_main_authentication);
77 98
 	$entity = (GETPOST('entity','int') ? GETPOST('entity','int') : (!empty($conf->entity) ? $conf->entity : 1));
78 99
 
79
-	if (checkLoginPassEntity($username,$password,$entity,$authmode) != $username)
80
-		return false;
100
+	if (checkLoginPassEntity($username,$password,$entity,$authmode) != $username) {
101
+			return false;
102
+	}
81 103
 
82 104
 	return true;
83 105
 });
@@ -131,7 +153,9 @@  discard block
 block discarded – undo
131 153
 // If you want to run the SabreDAV server in a custom location (using mod_rewrite for instance)
132 154
 // You can override the baseUri here.
133 155
 $baseUri = DOL_URL_ROOT.'/dav/fileserver.php/';
134
-if (isset($baseUri)) $server->setBaseUri($baseUri);
156
+if (isset($baseUri)) {
157
+    $server->setBaseUri($baseUri);
158
+}
135 159
 
136 160
 // Add authentication function
137 161
 if ((empty($conf->global->DAV_ALLOW_PUBLIC_DIR)
@@ -166,4 +190,6 @@  discard block
 block discarded – undo
166 190
 // And off we go!
167 191
 $server->exec();
168 192
 
169
-if (is_object($db)) $db->close();
193
+if (is_object($db)) {
194
+    $db->close();
195
+}
Please login to merge, or discard this patch.
dolibarr/htdocs/exports/class/export.class.php 3 patches
Indentation   +796 added lines, -796 removed lines patch added patch discarded remove patch
@@ -30,60 +30,60 @@  discard block
 block discarded – undo
30 30
  */
31 31
 class Export
32 32
 {
33
-	/**
33
+    /**
34 34
      * @var DoliDB Database handler.
35 35
      */
36 36
     public $db;
37 37
 
38
-	var $array_export_code=array();             // Tableau de "idmodule_numlot"
39
-	var $array_export_module=array();           // Tableau de "nom de modules"
40
-	var $array_export_label=array();            // Tableau de "libelle de lots"
41
-	var $array_export_sql_start=array();        // Tableau des "requetes sql"
42
-	var $array_export_sql_end=array();          // Tableau des "requetes sql"
43
-	var $array_export_sql_order=array();        // Tableau des "requetes sql"
44
-
45
-	var $array_export_fields=array();           // Tableau des listes de champ+libelle a exporter
46
-	var $array_export_TypeFields=array();		// Tableau des listes de champ+Type de filtre
47
-	var $array_export_FilterValue=array();		// Tableau des listes de champ+Valeur a filtrer
48
-	var $array_export_entities=array();         // Tableau des listes de champ+alias a exporter
49
-	var $array_export_dependencies=array();     // array of list of entities that must take care of the DISTINCT if a field is added into export
50
-	var $array_export_special=array();          // Tableau des operations speciales sur champ
38
+    var $array_export_code=array();             // Tableau de "idmodule_numlot"
39
+    var $array_export_module=array();           // Tableau de "nom de modules"
40
+    var $array_export_label=array();            // Tableau de "libelle de lots"
41
+    var $array_export_sql_start=array();        // Tableau des "requetes sql"
42
+    var $array_export_sql_end=array();          // Tableau des "requetes sql"
43
+    var $array_export_sql_order=array();        // Tableau des "requetes sql"
44
+
45
+    var $array_export_fields=array();           // Tableau des listes de champ+libelle a exporter
46
+    var $array_export_TypeFields=array();		// Tableau des listes de champ+Type de filtre
47
+    var $array_export_FilterValue=array();		// Tableau des listes de champ+Valeur a filtrer
48
+    var $array_export_entities=array();         // Tableau des listes de champ+alias a exporter
49
+    var $array_export_dependencies=array();     // array of list of entities that must take care of the DISTINCT if a field is added into export
50
+    var $array_export_special=array();          // Tableau des operations speciales sur champ
51 51
     var $array_export_examplevalues=array();    // array with examples
52 52
 
53
-	// To store export modules
54
-	var $hexa;
55
-	var $hexafiltervalue;
56
-	var $datatoexport;
57
-	var $model_name;
53
+    // To store export modules
54
+    var $hexa;
55
+    var $hexafiltervalue;
56
+    var $datatoexport;
57
+    var $model_name;
58 58
 
59
-	var $sqlusedforexport;
59
+    var $sqlusedforexport;
60 60
 
61 61
 
62
-	/**
63
-	 *    Constructor
64
-	 *
65
-	 *    @param  	DoliDB		$db		Database handler
66
-	 */
67
-	function __construct($db)
68
-	{
69
-		$this->db=$db;
70
-	}
62
+    /**
63
+     *    Constructor
64
+     *
65
+     *    @param  	DoliDB		$db		Database handler
66
+     */
67
+    function __construct($db)
68
+    {
69
+        $this->db=$db;
70
+    }
71 71
 
72 72
 
73 73
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
74
-	/**
75
-	 *    Load an exportable dataset
76
-	 *
77
-	 *    @param  	User		$user      	Object user making export
78
-	 *    @param  	string		$filter    	Load a particular dataset only
79
-	 *    @return	int						<0 if KO, >0 if OK
80
-	 */
81
-	function load_arrays($user,$filter='')
82
-	{
74
+    /**
75
+     *    Load an exportable dataset
76
+     *
77
+     *    @param  	User		$user      	Object user making export
78
+     *    @param  	string		$filter    	Load a particular dataset only
79
+     *    @return	int						<0 if KO, >0 if OK
80
+     */
81
+    function load_arrays($user,$filter='')
82
+    {
83 83
         // phpcs:enable
84
-		global $langs,$conf,$mysoc;
84
+        global $langs,$conf,$mysoc;
85 85
 
86
-		dol_syslog(get_class($this)."::load_arrays user=".$user->id." filter=".$filter);
86
+        dol_syslog(get_class($this)."::load_arrays user=".$user->id." filter=".$filter);
87 87
 
88 88
         $i=0;
89 89
 
@@ -92,798 +92,798 @@  discard block
 block discarded – undo
92 92
 
93 93
         $modulesdir = dolGetModulesDirs();
94 94
 
95
-		foreach($modulesdir as $dir)
96
-		{
97
-			// Search available exports
98
-			$handle=@opendir(dol_osencode($dir));
99
-			if (is_resource($handle))
100
-			{
95
+        foreach($modulesdir as $dir)
96
+        {
97
+            // Search available exports
98
+            $handle=@opendir(dol_osencode($dir));
99
+            if (is_resource($handle))
100
+            {
101 101
                 // Search module files
102
-			    while (($file = readdir($handle))!==false)
103
-				{
104
-					if (is_readable($dir.$file) && preg_match("/^(mod.*)\.class\.php$/i",$file,$reg))
105
-					{
106
-						$modulename=$reg[1];
107
-
108
-						// Defined if module is enabled
109
-						$enabled=true;
110
-						$part=strtolower(preg_replace('/^mod/i','',$modulename));
111
-						if ($part == 'propale') $part='propal';
112
-						if (empty($conf->$part->enabled)) $enabled=false;
113
-
114
-						if ($enabled)
115
-						{
116
-							// Loading Class
117
-							$file = $dir.$modulename.".class.php";
118
-							$classname = $modulename;
119
-							require_once $file;
120
-							$module = new $classname($this->db);
121
-
122
-							if (isset($module->export_code) && is_array($module->export_code))
123
-							{
124
-							    foreach($module->export_code as $r => $value)
125
-								{
102
+                while (($file = readdir($handle))!==false)
103
+                {
104
+                    if (is_readable($dir.$file) && preg_match("/^(mod.*)\.class\.php$/i",$file,$reg))
105
+                    {
106
+                        $modulename=$reg[1];
107
+
108
+                        // Defined if module is enabled
109
+                        $enabled=true;
110
+                        $part=strtolower(preg_replace('/^mod/i','',$modulename));
111
+                        if ($part == 'propale') $part='propal';
112
+                        if (empty($conf->$part->enabled)) $enabled=false;
113
+
114
+                        if ($enabled)
115
+                        {
116
+                            // Loading Class
117
+                            $file = $dir.$modulename.".class.php";
118
+                            $classname = $modulename;
119
+                            require_once $file;
120
+                            $module = new $classname($this->db);
121
+
122
+                            if (isset($module->export_code) && is_array($module->export_code))
123
+                            {
124
+                                foreach($module->export_code as $r => $value)
125
+                                {
126 126
                                     //print $i.'-'.$filter.'-'.$modulename.'-'.join(',',$module->export_code).'<br>';
127
-								    if ($filter && ($filter != $module->export_code[$r])) continue;
127
+                                    if ($filter && ($filter != $module->export_code[$r])) continue;
128 128
 
129 129
                                     // Test if condition to show are ok
130 130
                                     if (! empty($module->export_enabled[$r]) && ! verifCond($module->export_enabled[$r])) continue;
131 131
 
132 132
                                     // Test if permissions are ok
133
-									$bool=true;
134
-									if (isset($module->export_permission))
135
-									{
136
-										foreach($module->export_permission[$r] as $val)
137
-										{
138
-	    									$perm=$val;
139
-	    									//print_r("$perm[0]-$perm[1]-$perm[2]<br>");
140
-	    									if (! empty($perm[2]))
141
-	    									{
142
-	    										$bool=$user->rights->{$perm[0]}->{$perm[1]}->{$perm[2]};
143
-	    									}
144
-	    									else
145
-	    									{
146
-	    										$bool=$user->rights->{$perm[0]}->{$perm[1]};
147
-	    									}
148
-	    									if ($perm[0]=='user' && $user->admin) $bool=true;
149
-	    									if (! $bool) break;
150
-										}
151
-									}
152
-									//print $bool." $perm[0]"."<br>";
153
-
154
-									// Permissions ok
155
-									//	          if ($bool)
156
-									//	          {
157
-									// Charge fichier lang en rapport
158
-									$langtoload=$module->getLangFilesArray();
159
-									if (is_array($langtoload))
160
-									{
161
-										foreach($langtoload as $key)
162
-										{
163
-											$langs->load($key);
164
-										}
165
-									}
166
-
167
-									// Module
168
-									$this->array_export_module[$i]=$module;
169
-									// Permission
170
-									$this->array_export_perms[$i]=$bool;
171
-									// Icon
172
-									$this->array_export_icon[$i]=(isset($module->export_icon[$r])?$module->export_icon[$r]:$module->picto);
173
-									// Code du dataset export
174
-									$this->array_export_code[$i]=$module->export_code[$r];
175
-									// Libelle du dataset export
176
-									$this->array_export_label[$i]=$module->getExportDatasetLabel($r);
177
-									// Tableau des champ a exporter (cle=champ, valeur=libelle)
178
-									$this->array_export_fields[$i]=$module->export_fields_array[$r];
179
-									// Tableau des champs a filtrer (cle=champ, valeur1=type de donnees) on verifie que le module a des filtres
180
-									$this->array_export_TypeFields[$i]=(isset($module->export_TypeFields_array[$r])?$module->export_TypeFields_array[$r]:'');
181
-									// Tableau des entites a exporter (cle=champ, valeur=entite)
182
-									$this->array_export_entities[$i]=$module->export_entities_array[$r];
183
-									// Tableau des entites qui requiert abandon du DISTINCT (cle=entite, valeur=champ id child records)
184
-									$this->array_export_dependencies[$i]=(! empty($module->export_dependencies_array[$r])?$module->export_dependencies_array[$r]:'');
185
-									// Tableau des operations speciales sur champ
186
-									$this->array_export_special[$i]=(! empty($module->export_special_array[$r])?$module->export_special_array[$r]:'');
187
-            						// Array of examples
188
-            						$this->array_export_examplevalues[$i]=$module->export_examplevalues_array[$r];
189
-
190
-									// Requete sql du dataset
191
-									$this->array_export_sql_start[$i]=$module->export_sql_start[$r];
192
-									$this->array_export_sql_end[$i]=$module->export_sql_end[$r];
193
-									$this->array_export_sql_order[$i]=$module->export_sql_order[$r];
194
-									//$this->array_export_sql[$i]=$module->export_sql[$r];
195
-
196
-									dol_syslog(get_class($this)."::load_arrays loaded for module ".$modulename." with index ".$i.", dataset=".$module->export_code[$r].", nb of fields=".(! empty($module->export_fields_code[$r])?count($module->export_fields_code[$r]):''));
197
-									$i++;
198
-									//	          }
199
-								}
200
-							}
201
-						}
202
-					}
203
-				}
133
+                                    $bool=true;
134
+                                    if (isset($module->export_permission))
135
+                                    {
136
+                                        foreach($module->export_permission[$r] as $val)
137
+                                        {
138
+                                            $perm=$val;
139
+                                            //print_r("$perm[0]-$perm[1]-$perm[2]<br>");
140
+                                            if (! empty($perm[2]))
141
+                                            {
142
+                                                $bool=$user->rights->{$perm[0]}->{$perm[1]}->{$perm[2]};
143
+                                            }
144
+                                            else
145
+                                            {
146
+                                                $bool=$user->rights->{$perm[0]}->{$perm[1]};
147
+                                            }
148
+                                            if ($perm[0]=='user' && $user->admin) $bool=true;
149
+                                            if (! $bool) break;
150
+                                        }
151
+                                    }
152
+                                    //print $bool." $perm[0]"."<br>";
153
+
154
+                                    // Permissions ok
155
+                                    //	          if ($bool)
156
+                                    //	          {
157
+                                    // Charge fichier lang en rapport
158
+                                    $langtoload=$module->getLangFilesArray();
159
+                                    if (is_array($langtoload))
160
+                                    {
161
+                                        foreach($langtoload as $key)
162
+                                        {
163
+                                            $langs->load($key);
164
+                                        }
165
+                                    }
166
+
167
+                                    // Module
168
+                                    $this->array_export_module[$i]=$module;
169
+                                    // Permission
170
+                                    $this->array_export_perms[$i]=$bool;
171
+                                    // Icon
172
+                                    $this->array_export_icon[$i]=(isset($module->export_icon[$r])?$module->export_icon[$r]:$module->picto);
173
+                                    // Code du dataset export
174
+                                    $this->array_export_code[$i]=$module->export_code[$r];
175
+                                    // Libelle du dataset export
176
+                                    $this->array_export_label[$i]=$module->getExportDatasetLabel($r);
177
+                                    // Tableau des champ a exporter (cle=champ, valeur=libelle)
178
+                                    $this->array_export_fields[$i]=$module->export_fields_array[$r];
179
+                                    // Tableau des champs a filtrer (cle=champ, valeur1=type de donnees) on verifie que le module a des filtres
180
+                                    $this->array_export_TypeFields[$i]=(isset($module->export_TypeFields_array[$r])?$module->export_TypeFields_array[$r]:'');
181
+                                    // Tableau des entites a exporter (cle=champ, valeur=entite)
182
+                                    $this->array_export_entities[$i]=$module->export_entities_array[$r];
183
+                                    // Tableau des entites qui requiert abandon du DISTINCT (cle=entite, valeur=champ id child records)
184
+                                    $this->array_export_dependencies[$i]=(! empty($module->export_dependencies_array[$r])?$module->export_dependencies_array[$r]:'');
185
+                                    // Tableau des operations speciales sur champ
186
+                                    $this->array_export_special[$i]=(! empty($module->export_special_array[$r])?$module->export_special_array[$r]:'');
187
+                                    // Array of examples
188
+                                    $this->array_export_examplevalues[$i]=$module->export_examplevalues_array[$r];
189
+
190
+                                    // Requete sql du dataset
191
+                                    $this->array_export_sql_start[$i]=$module->export_sql_start[$r];
192
+                                    $this->array_export_sql_end[$i]=$module->export_sql_end[$r];
193
+                                    $this->array_export_sql_order[$i]=$module->export_sql_order[$r];
194
+                                    //$this->array_export_sql[$i]=$module->export_sql[$r];
195
+
196
+                                    dol_syslog(get_class($this)."::load_arrays loaded for module ".$modulename." with index ".$i.", dataset=".$module->export_code[$r].", nb of fields=".(! empty($module->export_fields_code[$r])?count($module->export_fields_code[$r]):''));
197
+                                    $i++;
198
+                                    //	          }
199
+                                }
200
+                            }
201
+                        }
202
+                    }
203
+                }
204 204
                 closedir($handle);
205
-			}
206
-		}
205
+            }
206
+        }
207 207
 
208
-		return 1;
209
-	}
208
+        return 1;
209
+    }
210 210
 
211 211
 
212 212
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
213
-	/**
214
-	 *      Build the sql export request.
215
-	 *      Arrays this->array_export_xxx are already loaded for required datatoexport
216
-	 *
217
-	 *      @param      int		$indice				Indice of export
218
-	 *      @param      array	$array_selected     Filter fields on array of fields to export
219
-	 *      @param      array	$array_filterValue  Filter records on array of value for fields
220
-	 *      @return		string						SQL String. Example "select s.rowid as r_rowid, s.status as s_status from ..."
221
-	 */
222
-	function build_sql($indice, $array_selected, $array_filterValue)
223
-	{
213
+    /**
214
+     *      Build the sql export request.
215
+     *      Arrays this->array_export_xxx are already loaded for required datatoexport
216
+     *
217
+     *      @param      int		$indice				Indice of export
218
+     *      @param      array	$array_selected     Filter fields on array of fields to export
219
+     *      @param      array	$array_filterValue  Filter records on array of value for fields
220
+     *      @return		string						SQL String. Example "select s.rowid as r_rowid, s.status as s_status from ..."
221
+     */
222
+    function build_sql($indice, $array_selected, $array_filterValue)
223
+    {
224 224
         // phpcs:enable
225
-		// Build the sql request
226
-		$sql=$this->array_export_sql_start[$indice];
227
-		$i=0;
228
-
229
-		//print_r($array_selected);
230
-		foreach ($this->array_export_fields[$indice] as $key => $value)
231
-		{
232
-			if (! array_key_exists($key, $array_selected)) continue;		// Field not selected
225
+        // Build the sql request
226
+        $sql=$this->array_export_sql_start[$indice];
227
+        $i=0;
228
+
229
+        //print_r($array_selected);
230
+        foreach ($this->array_export_fields[$indice] as $key => $value)
231
+        {
232
+            if (! array_key_exists($key, $array_selected)) continue;		// Field not selected
233 233
             if (preg_match('/^none\./', $key)) continue;                    // A field that must not appears into SQL
234
-			if ($i > 0) $sql.=', ';
235
-			else $i++;
236
-
237
-			if (strpos($key, ' as ')===false) {
238
-				$newfield=$key.' as '.str_replace(array('.', '-','(',')'),'_',$key);
239
-			} else {
240
-				$newfield=$key;
241
-			}
242
-
243
-			$sql.=$newfield;
244
-		}
245
-		$sql.=$this->array_export_sql_end[$indice];
246
-
247
-		// Add the WHERE part. Filtering into sql if a filtering array is provided
248
-		if (is_array($array_filterValue) && !empty($array_filterValue))
249
-		{
250
-			$sqlWhere='';
251
-			// Loop on each condition to add
252
-			foreach ($array_filterValue as $key => $value)
253
-			{
254
-			    if (preg_match('/GROUP_CONCAT/i', $key)) continue;
255
-				if ($value != '') $sqlWhere.=" and ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
256
-			}
257
-			$sql.=$sqlWhere;
258
-		}
259
-
260
-		// Add the order
261
-		$sql.=$this->array_export_sql_order[$indice];
262
-
263
-		// Add the HAVING part.
264
-		if (is_array($array_filterValue) && !empty($array_filterValue))
265
-		{
266
-		    // Loop on each condition to add
267
-		    foreach ($array_filterValue as $key => $value)
268
-		    {
269
-		        if (preg_match('/GROUP_CONCAT/i', $key) and $value != '') $sql.=" HAVING ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
270
-		    }
271
-		}
272
-
273
-		return $sql;
274
-	}
234
+            if ($i > 0) $sql.=', ';
235
+            else $i++;
236
+
237
+            if (strpos($key, ' as ')===false) {
238
+                $newfield=$key.' as '.str_replace(array('.', '-','(',')'),'_',$key);
239
+            } else {
240
+                $newfield=$key;
241
+            }
242
+
243
+            $sql.=$newfield;
244
+        }
245
+        $sql.=$this->array_export_sql_end[$indice];
246
+
247
+        // Add the WHERE part. Filtering into sql if a filtering array is provided
248
+        if (is_array($array_filterValue) && !empty($array_filterValue))
249
+        {
250
+            $sqlWhere='';
251
+            // Loop on each condition to add
252
+            foreach ($array_filterValue as $key => $value)
253
+            {
254
+                if (preg_match('/GROUP_CONCAT/i', $key)) continue;
255
+                if ($value != '') $sqlWhere.=" and ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
256
+            }
257
+            $sql.=$sqlWhere;
258
+        }
259
+
260
+        // Add the order
261
+        $sql.=$this->array_export_sql_order[$indice];
262
+
263
+        // Add the HAVING part.
264
+        if (is_array($array_filterValue) && !empty($array_filterValue))
265
+        {
266
+            // Loop on each condition to add
267
+            foreach ($array_filterValue as $key => $value)
268
+            {
269
+                if (preg_match('/GROUP_CONCAT/i', $key) and $value != '') $sql.=" HAVING ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
270
+            }
271
+        }
272
+
273
+        return $sql;
274
+    }
275 275
 
276 276
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
277
-	/**
278
-	 *      Build the conditionnal string from filter the query
279
-	 *
280
-	 *      @param		string	$TypeField		Type of Field to filter
281
-	 *      @param		string	$NameField		Name of the field to filter
282
-	 *      @param		string	$ValueField		Value of the field for filter. Must not be ''
283
-	 *      @return		string					sql string of then field ex : "field='xxx'>"
284
-	 */
285
-	function build_filterQuery($TypeField, $NameField, $ValueField)
286
-	{
277
+    /**
278
+     *      Build the conditionnal string from filter the query
279
+     *
280
+     *      @param		string	$TypeField		Type of Field to filter
281
+     *      @param		string	$NameField		Name of the field to filter
282
+     *      @param		string	$ValueField		Value of the field for filter. Must not be ''
283
+     *      @return		string					sql string of then field ex : "field='xxx'>"
284
+     */
285
+    function build_filterQuery($TypeField, $NameField, $ValueField)
286
+    {
287 287
         // phpcs:enable
288
-		//print $TypeField." ".$NameField." ".$ValueField;
289
-		$InfoFieldList = explode(":", $TypeField);
290
-		// build the input field on depend of the type of file
291
-		switch ($InfoFieldList[0]) {
292
-			case 'Text':
293
-				if (! (strpos($ValueField, '%') === false))
294
-					$szFilterQuery.=" ".$NameField." LIKE '".$ValueField."'";
295
-				else
296
-					$szFilterQuery.=" ".$NameField." = '".$ValueField."'";
297
-				break;
298
-			case 'Date':
299
-				if (strpos($ValueField, "+") > 0)
300
-				{
301
-					// mode plage
302
-					$ValueArray = explode("+", $ValueField);
303
-					$szFilterQuery ="(".$this->conditionDate($NameField,trim($ValueArray[0]),">=");
304
-					$szFilterQuery.=" AND ".$this->conditionDate($NameField,trim($ValueArray[1]),"<=").")";
305
-				}
306
-				else
307
-				{
308
-					if (is_numeric(substr($ValueField,0,1)))
309
-						$szFilterQuery=$this->conditionDate($NameField,trim($ValueField),"=");
310
-					else
311
-						$szFilterQuery=$this->conditionDate($NameField,trim(substr($ValueField,1)),substr($ValueField,0,1));
312
-				}
313
-				break;
314
-			case 'Duree':
315
-				break;
316
-			case 'Numeric':
317
-				// si le signe -
318
-				if (strpos($ValueField, "+") > 0)
319
-				{
320
-					// mode plage
321
-					$ValueArray = explode("+", $ValueField);
322
-					$szFilterQuery ="(".$NameField.">=".$ValueArray[0];
323
-					$szFilterQuery.=" AND ".$NameField."<=".$ValueArray[1].")";
324
-				}
325
-				else
326
-				{
327
-					if (is_numeric(substr($ValueField,0,1)))
328
-						$szFilterQuery=" ".$NameField."=".$ValueField;
329
-					else
330
-						$szFilterQuery=" ".$NameField.substr($ValueField,0,1).substr($ValueField,1);
331
-				}
332
-				break;
333
-			case 'Boolean':
334
-				$szFilterQuery=" ".$NameField."=".(is_numeric($ValueField) ? $ValueField : ($ValueField =='yes' ? 1: 0) );
335
-				break;
336
-			case 'Status':
337
-			case 'List':
338
-				if (is_numeric($ValueField))
339
-					$szFilterQuery=" ".$NameField."=".$ValueField;
340
-				else {
288
+        //print $TypeField." ".$NameField." ".$ValueField;
289
+        $InfoFieldList = explode(":", $TypeField);
290
+        // build the input field on depend of the type of file
291
+        switch ($InfoFieldList[0]) {
292
+            case 'Text':
293
+                if (! (strpos($ValueField, '%') === false))
294
+                    $szFilterQuery.=" ".$NameField." LIKE '".$ValueField."'";
295
+                else
296
+                    $szFilterQuery.=" ".$NameField." = '".$ValueField."'";
297
+                break;
298
+            case 'Date':
299
+                if (strpos($ValueField, "+") > 0)
300
+                {
301
+                    // mode plage
302
+                    $ValueArray = explode("+", $ValueField);
303
+                    $szFilterQuery ="(".$this->conditionDate($NameField,trim($ValueArray[0]),">=");
304
+                    $szFilterQuery.=" AND ".$this->conditionDate($NameField,trim($ValueArray[1]),"<=").")";
305
+                }
306
+                else
307
+                {
308
+                    if (is_numeric(substr($ValueField,0,1)))
309
+                        $szFilterQuery=$this->conditionDate($NameField,trim($ValueField),"=");
310
+                    else
311
+                        $szFilterQuery=$this->conditionDate($NameField,trim(substr($ValueField,1)),substr($ValueField,0,1));
312
+                }
313
+                break;
314
+            case 'Duree':
315
+                break;
316
+            case 'Numeric':
317
+                // si le signe -
318
+                if (strpos($ValueField, "+") > 0)
319
+                {
320
+                    // mode plage
321
+                    $ValueArray = explode("+", $ValueField);
322
+                    $szFilterQuery ="(".$NameField.">=".$ValueArray[0];
323
+                    $szFilterQuery.=" AND ".$NameField."<=".$ValueArray[1].")";
324
+                }
325
+                else
326
+                {
327
+                    if (is_numeric(substr($ValueField,0,1)))
328
+                        $szFilterQuery=" ".$NameField."=".$ValueField;
329
+                    else
330
+                        $szFilterQuery=" ".$NameField.substr($ValueField,0,1).substr($ValueField,1);
331
+                }
332
+                break;
333
+            case 'Boolean':
334
+                $szFilterQuery=" ".$NameField."=".(is_numeric($ValueField) ? $ValueField : ($ValueField =='yes' ? 1: 0) );
335
+                break;
336
+            case 'Status':
337
+            case 'List':
338
+                if (is_numeric($ValueField))
339
+                    $szFilterQuery=" ".$NameField."=".$ValueField;
340
+                else {
341 341
                     if (! (strpos($ValueField, '%') === false))
342 342
                         $szFilterQuery=" ".$NameField." LIKE '".$ValueField."'";
343 343
                     else
344 344
                         $szFilterQuery=" ".$NameField." = '".$ValueField."'";
345
-				}
346
-				break;
347
-			default:
348
-			    dol_syslog("Error we try to forge an sql export request with a condition on a field with type '".$InfoFieldList[0]."' (defined into module descriptor) but this type is unknown/not supported. It looks like a bug into module descriptor.", LOG_ERR);
349
-		}
350
-
351
-		return $szFilterQuery;
352
-	}
353
-
354
-	/**
355
-	 *	conditionDate
356
-	 *
357
-	 *  @param 	string	$Field		Field operand 1
358
-	 *  @param 	string	$Value		Value operand 2
359
-	 *  @param 	string	$Sens		Comparison operator
360
-	 *  @return string
361
-	 */
362
-	function conditionDate($Field, $Value, $Sens)
363
-	{
364
-		// TODO date_format is forbidden, not performant and not portable. Use instead BETWEEN
365
-		if (strlen($Value)==4) $Condition=" date_format(".$Field.",'%Y') ".$Sens." '".$Value."'";
366
-		elseif (strlen($Value)==6) $Condition=" date_format(".$Field.",'%Y%m') ".$Sens." '".$Value."'";
367
-		else  $Condition=" date_format(".$Field.",'%Y%m%d') ".$Sens." ".$Value;
368
-		return $Condition;
369
-	}
345
+                }
346
+                break;
347
+            default:
348
+                dol_syslog("Error we try to forge an sql export request with a condition on a field with type '".$InfoFieldList[0]."' (defined into module descriptor) but this type is unknown/not supported. It looks like a bug into module descriptor.", LOG_ERR);
349
+        }
350
+
351
+        return $szFilterQuery;
352
+    }
353
+
354
+    /**
355
+     *	conditionDate
356
+     *
357
+     *  @param 	string	$Field		Field operand 1
358
+     *  @param 	string	$Value		Value operand 2
359
+     *  @param 	string	$Sens		Comparison operator
360
+     *  @return string
361
+     */
362
+    function conditionDate($Field, $Value, $Sens)
363
+    {
364
+        // TODO date_format is forbidden, not performant and not portable. Use instead BETWEEN
365
+        if (strlen($Value)==4) $Condition=" date_format(".$Field.",'%Y') ".$Sens." '".$Value."'";
366
+        elseif (strlen($Value)==6) $Condition=" date_format(".$Field.",'%Y%m') ".$Sens." '".$Value."'";
367
+        else  $Condition=" date_format(".$Field.",'%Y%m%d') ".$Sens." ".$Value;
368
+        return $Condition;
369
+    }
370 370
 
371 371
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
372
-	/**
373
-	 *      Build an input field used to filter the query
374
-	 *
375
-	 *      @param		string	$TypeField		Type of Field to filter. Example: Text, Date, List:c_country:label:rowid, List:c_stcom:label:code, Numeric or Number, Boolean
376
-	 *      @param		string	$NameField		Name of the field to filter
377
-	 *      @param		string	$ValueField		Initial value of the field to filter
378
-	 *      @return		string					html string of the input field ex : "<input type=text name=... value=...>"
379
-	 */
380
-	function build_filterField($TypeField, $NameField, $ValueField)
381
-	{
372
+    /**
373
+     *      Build an input field used to filter the query
374
+     *
375
+     *      @param		string	$TypeField		Type of Field to filter. Example: Text, Date, List:c_country:label:rowid, List:c_stcom:label:code, Numeric or Number, Boolean
376
+     *      @param		string	$NameField		Name of the field to filter
377
+     *      @param		string	$ValueField		Initial value of the field to filter
378
+     *      @return		string					html string of the input field ex : "<input type=text name=... value=...>"
379
+     */
380
+    function build_filterField($TypeField, $NameField, $ValueField)
381
+    {
382 382
         // phpcs:enable
383
-		global $conf,$langs;
384
-
385
-		$szFilterField='';
386
-		$InfoFieldList = explode(":", $TypeField);
387
-
388
-		// build the input field on depend of the type of file
389
-		switch ($InfoFieldList[0])
390
-		{
391
-			case 'Text':
392
-			case 'Date':
393
-				$szFilterField='<input type="text" name="'.$NameField.'" value="'.$ValueField.'">';
394
-				break;
395
-			case 'Duree':
396
-			case 'Numeric':
397
-			case 'Number':
398
-				// Must be a string text to allow to use comparison strings like "<= 999"
399
-			    $szFilterField='<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
400
-				break;
401
-			case 'Status':
402
-				if (! empty($conf->global->MAIN_ACTIVATE_HTML5)) $szFilterField='<input type="number" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
403
-				else $szFilterField='<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
404
-				break;
405
-			case 'Boolean':
406
-				$szFilterField='<select name="'.$NameField.'" class="flat">';
407
-				$szFilterField.='<option ';
408
-				if ($ValueField=='') $szFilterField.=' selected ';
409
-				$szFilterField.=' value="">&nbsp;</option>';
410
-
411
-				$szFilterField.='<option ';
412
-				if ($ValueField=='yes' || $ValueField == '1') $szFilterField.=' selected ';
413
-				$szFilterField.=' value="1">'.yn(1).'</option>';
414
-
415
-				$szFilterField.='<option ';
416
-				if ($ValueField=='no' || $ValueField=='0') $szFilterField.=' selected ';
417
-				$szFilterField.=' value="0">'.yn(0).'</option>';
418
-				$szFilterField.="</select>";
419
-				break;
420
-			case 'List':
421
-				// 0 : Type du champ
422
-				// 1 : Nom de la table
423
-				// 2 : Nom du champ contenant le libelle
424
-				// 3 : Name of field with key (if it is not "rowid"). Used this field as key for combo list.
425
-				if (count($InfoFieldList)==4)
426
-					$keyList=$InfoFieldList[3];
427
-				else
428
-					$keyList='rowid';
429
-				$sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3])?'':', '.$InfoFieldList[3].' as code');
430
-				if ($InfoFieldList[1] == 'c_stcomm') $sql = 'SELECT id as id, '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3])?'':', '.$InfoFieldList[3].' as code');
431
-				if ($InfoFieldList[1] == 'c_country') $sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label, code as code';
432
-				$sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[1];
433
-
434
-				$resql = $this->db->query($sql);
435
-				if ($resql)
436
-				{
437
-					$szFilterField='<select class="flat" name="'.$NameField.'">';
438
-					$szFilterField.='<option value="0">&nbsp;</option>';
439
-					$num = $this->db->num_rows($resql);
440
-
441
-					$i = 0;
442
-					if ($num)
443
-					{
444
-						while ($i < $num)
445
-						{
446
-							$obj = $this->db->fetch_object($resql);
447
-							if ($obj->label == '-')
448
-							{
449
-								// Discard entry '-'
450
-								$i++;
451
-								continue;
452
-							}
453
-							//var_dump($InfoFieldList[1]);
454
-							$labeltoshow=dol_trunc($obj->label,18);
455
-							if ($InfoFieldList[1] == 'c_stcomm')
456
-							{
457
-								$langs->load("companies");
458
-								$labeltoshow=(($langs->trans("StatusProspect".$obj->id) != "StatusProspect".$obj->id)?$langs->trans("StatusProspect".$obj->id):$obj->label);
459
-							}
460
-							if ($InfoFieldList[1] == 'c_country')
461
-							{
462
-								//var_dump($sql);
463
-								$langs->load("dict");
464
-								$labeltoshow=(($langs->trans("Country".$obj->code) != "Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->label);
465
-							}
466
-							if (!empty($ValueField) && $ValueField == $obj->rowid)
467
-							{
468
-								$szFilterField.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
469
-							}
470
-							else
471
-							{
472
-								$szFilterField.='<option value="'.$obj->rowid.'" >'.$labeltoshow.'</option>';
473
-							}
474
-							$i++;
475
-						}
476
-					}
477
-					$szFilterField.="</select>";
478
-
479
-					$this->db->free($resql);
480
-				}
481
-				else dol_print_error($this->db);
482
-				break;
483
-		}
484
-
485
-		return $szFilterField;
486
-	}
487
-
488
-	/**
489
-	 *      Build an input field used to filter the query
490
-	 *
491
-	 *      @param		string	$TypeField		Type of Field to filter
492
-	 *      @return		string					html string of the input field ex : "<input type=text name=... value=...>"
493
-	 */
494
-	function genDocFilter($TypeField)
495
-	{
383
+        global $conf,$langs;
384
+
385
+        $szFilterField='';
386
+        $InfoFieldList = explode(":", $TypeField);
387
+
388
+        // build the input field on depend of the type of file
389
+        switch ($InfoFieldList[0])
390
+        {
391
+            case 'Text':
392
+            case 'Date':
393
+                $szFilterField='<input type="text" name="'.$NameField.'" value="'.$ValueField.'">';
394
+                break;
395
+            case 'Duree':
396
+            case 'Numeric':
397
+            case 'Number':
398
+                // Must be a string text to allow to use comparison strings like "<= 999"
399
+                $szFilterField='<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
400
+                break;
401
+            case 'Status':
402
+                if (! empty($conf->global->MAIN_ACTIVATE_HTML5)) $szFilterField='<input type="number" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
403
+                else $szFilterField='<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
404
+                break;
405
+            case 'Boolean':
406
+                $szFilterField='<select name="'.$NameField.'" class="flat">';
407
+                $szFilterField.='<option ';
408
+                if ($ValueField=='') $szFilterField.=' selected ';
409
+                $szFilterField.=' value="">&nbsp;</option>';
410
+
411
+                $szFilterField.='<option ';
412
+                if ($ValueField=='yes' || $ValueField == '1') $szFilterField.=' selected ';
413
+                $szFilterField.=' value="1">'.yn(1).'</option>';
414
+
415
+                $szFilterField.='<option ';
416
+                if ($ValueField=='no' || $ValueField=='0') $szFilterField.=' selected ';
417
+                $szFilterField.=' value="0">'.yn(0).'</option>';
418
+                $szFilterField.="</select>";
419
+                break;
420
+            case 'List':
421
+                // 0 : Type du champ
422
+                // 1 : Nom de la table
423
+                // 2 : Nom du champ contenant le libelle
424
+                // 3 : Name of field with key (if it is not "rowid"). Used this field as key for combo list.
425
+                if (count($InfoFieldList)==4)
426
+                    $keyList=$InfoFieldList[3];
427
+                else
428
+                    $keyList='rowid';
429
+                $sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3])?'':', '.$InfoFieldList[3].' as code');
430
+                if ($InfoFieldList[1] == 'c_stcomm') $sql = 'SELECT id as id, '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3])?'':', '.$InfoFieldList[3].' as code');
431
+                if ($InfoFieldList[1] == 'c_country') $sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label, code as code';
432
+                $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[1];
433
+
434
+                $resql = $this->db->query($sql);
435
+                if ($resql)
436
+                {
437
+                    $szFilterField='<select class="flat" name="'.$NameField.'">';
438
+                    $szFilterField.='<option value="0">&nbsp;</option>';
439
+                    $num = $this->db->num_rows($resql);
440
+
441
+                    $i = 0;
442
+                    if ($num)
443
+                    {
444
+                        while ($i < $num)
445
+                        {
446
+                            $obj = $this->db->fetch_object($resql);
447
+                            if ($obj->label == '-')
448
+                            {
449
+                                // Discard entry '-'
450
+                                $i++;
451
+                                continue;
452
+                            }
453
+                            //var_dump($InfoFieldList[1]);
454
+                            $labeltoshow=dol_trunc($obj->label,18);
455
+                            if ($InfoFieldList[1] == 'c_stcomm')
456
+                            {
457
+                                $langs->load("companies");
458
+                                $labeltoshow=(($langs->trans("StatusProspect".$obj->id) != "StatusProspect".$obj->id)?$langs->trans("StatusProspect".$obj->id):$obj->label);
459
+                            }
460
+                            if ($InfoFieldList[1] == 'c_country')
461
+                            {
462
+                                //var_dump($sql);
463
+                                $langs->load("dict");
464
+                                $labeltoshow=(($langs->trans("Country".$obj->code) != "Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->label);
465
+                            }
466
+                            if (!empty($ValueField) && $ValueField == $obj->rowid)
467
+                            {
468
+                                $szFilterField.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
469
+                            }
470
+                            else
471
+                            {
472
+                                $szFilterField.='<option value="'.$obj->rowid.'" >'.$labeltoshow.'</option>';
473
+                            }
474
+                            $i++;
475
+                        }
476
+                    }
477
+                    $szFilterField.="</select>";
478
+
479
+                    $this->db->free($resql);
480
+                }
481
+                else dol_print_error($this->db);
482
+                break;
483
+        }
484
+
485
+        return $szFilterField;
486
+    }
487
+
488
+    /**
489
+     *      Build an input field used to filter the query
490
+     *
491
+     *      @param		string	$TypeField		Type of Field to filter
492
+     *      @return		string					html string of the input field ex : "<input type=text name=... value=...>"
493
+     */
494
+    function genDocFilter($TypeField)
495
+    {
496 496
         global $langs;
497 497
 
498
-		$szMsg='';
499
-		$InfoFieldList = explode(":", $TypeField);
500
-		// build the input field on depend of the type of file
501
-		switch ($InfoFieldList[0]) {
502
-			case 'Text':
503
-				$szMsg= $langs->trans('ExportStringFilter');
504
-				break;
505
-			case 'Date':
506
-				$szMsg = $langs->trans('ExportDateFilter');
507
-				break;
508
-			case 'Duree':
509
-				break;
510
-			case 'Numeric':
511
-				$szMsg = $langs->trans('ExportNumericFilter');
512
-				break;
513
-			case 'Boolean':
514
-				break;
515
-			case 'List':
516
-				break;
517
-		}
518
-		return $szMsg;
519
-	}
498
+        $szMsg='';
499
+        $InfoFieldList = explode(":", $TypeField);
500
+        // build the input field on depend of the type of file
501
+        switch ($InfoFieldList[0]) {
502
+            case 'Text':
503
+                $szMsg= $langs->trans('ExportStringFilter');
504
+                break;
505
+            case 'Date':
506
+                $szMsg = $langs->trans('ExportDateFilter');
507
+                break;
508
+            case 'Duree':
509
+                break;
510
+            case 'Numeric':
511
+                $szMsg = $langs->trans('ExportNumericFilter');
512
+                break;
513
+            case 'Boolean':
514
+                break;
515
+            case 'List':
516
+                break;
517
+        }
518
+        return $szMsg;
519
+    }
520 520
 
521 521
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
522
-	/**
523
-	 *      Build export file.
524
-	 *      File is built into directory $conf->export->dir_temp.'/'.$user->id
525
-	 *      Arrays this->array_export_xxx are already loaded for required datatoexport
526
-	 *
527
-	 *      @param      User		$user               User that export
528
-	 *      @param      string		$model              Export format
529
-	 *      @param      string		$datatoexport       Name of dataset to export
530
-	 *      @param      array		$array_selected     Filter on array of fields to export
531
-	 *      @param      array		$array_filterValue  Filter on array of fields with a filter
532
-	 *      @param		string		$sqlquery			If set, transmit the sql request for select (otherwise, sql request is generated from arrays)
533
-	 *      @return		int								<0 if KO, >0 if OK
534
-	 */
535
-	function build_file($user, $model, $datatoexport, $array_selected, $array_filterValue, $sqlquery = '')
536
- 	{
522
+    /**
523
+     *      Build export file.
524
+     *      File is built into directory $conf->export->dir_temp.'/'.$user->id
525
+     *      Arrays this->array_export_xxx are already loaded for required datatoexport
526
+     *
527
+     *      @param      User		$user               User that export
528
+     *      @param      string		$model              Export format
529
+     *      @param      string		$datatoexport       Name of dataset to export
530
+     *      @param      array		$array_selected     Filter on array of fields to export
531
+     *      @param      array		$array_filterValue  Filter on array of fields with a filter
532
+     *      @param		string		$sqlquery			If set, transmit the sql request for select (otherwise, sql request is generated from arrays)
533
+     *      @return		int								<0 if KO, >0 if OK
534
+     */
535
+    function build_file($user, $model, $datatoexport, $array_selected, $array_filterValue, $sqlquery = '')
536
+        {
537 537
         // phpcs:enable
538
-		global $conf,$langs;
538
+        global $conf,$langs;
539 539
 
540
-		$indice=0;
541
-		asort($array_selected);
540
+        $indice=0;
541
+        asort($array_selected);
542 542
 
543
-		dol_syslog(get_class($this)."::".__FUNCTION__." ".$model.", ".$datatoexport.", ".implode(",", $array_selected));
543
+        dol_syslog(get_class($this)."::".__FUNCTION__." ".$model.", ".$datatoexport.", ".implode(",", $array_selected));
544 544
 
545
-		// Check parameters or context properties
546
-		if (empty($this->array_export_fields) || ! is_array($this->array_export_fields))
547
-		{
548
-			$this->error="ErrorBadParameter";
549
-			return -1;
550
-		}
545
+        // Check parameters or context properties
546
+        if (empty($this->array_export_fields) || ! is_array($this->array_export_fields))
547
+        {
548
+            $this->error="ErrorBadParameter";
549
+            return -1;
550
+        }
551 551
 
552
-		// Creation of class to export using model ExportXXX
553
-		$dir = DOL_DOCUMENT_ROOT . "/core/modules/export/";
554
-		$file = "export_".$model.".modules.php";
555
-		$classname = "Export".$model;
556
-		require_once $dir.$file;
557
-		$objmodel = new $classname($this->db);
552
+        // Creation of class to export using model ExportXXX
553
+        $dir = DOL_DOCUMENT_ROOT . "/core/modules/export/";
554
+        $file = "export_".$model.".modules.php";
555
+        $classname = "Export".$model;
556
+        require_once $dir.$file;
557
+        $objmodel = new $classname($this->db);
558 558
 
559
-		if (! empty($sqlquery)) $sql = $sqlquery;
559
+        if (! empty($sqlquery)) $sql = $sqlquery;
560
+        else
561
+        {
562
+            // Define value for indice from $datatoexport
563
+            $foundindice=0;
564
+            foreach($this->array_export_code as $key => $dataset)
565
+            {
566
+                if ($datatoexport == $dataset)
567
+                {
568
+                    $indice=$key;
569
+                    $foundindice++;
570
+                    //print "Found indice = ".$indice." for dataset=".$datatoexport."\n";
571
+                    break;
572
+                }
573
+            }
574
+            if (empty($foundindice))
575
+            {
576
+                $this->error="ErrorBadParameter can't find dataset ".$datatoexport." into preload arrays this->array_export_code";
577
+                return -1;
578
+            }
579
+            $sql=$this->build_sql($indice, $array_selected, $array_filterValue);
580
+        }
581
+
582
+        // Run the sql
583
+        $this->sqlusedforexport=$sql;
584
+        dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG);
585
+        $resql = $this->db->query($sql);
586
+        if ($resql)
587
+        {
588
+            //$this->array_export_label[$indice]
589
+            if ($conf->global->EXPORT_PREFIX_SPEC)
590
+                $filename=$conf->global->EXPORT_PREFIX_SPEC."_".$datatoexport;
591
+            else
592
+                $filename="export_".$datatoexport;
593
+            $filename.='.'.$objmodel->getDriverExtension();
594
+            $dirname=$conf->export->dir_temp.'/'.$user->id;
595
+
596
+            $outputlangs = clone $langs; // We clone to have an object we can modify (for example to change output charset by csv handler) without changing original value
597
+
598
+            // Open file
599
+            dol_mkdir($dirname);
600
+            $result=$objmodel->open_file($dirname."/".$filename, $outputlangs);
601
+
602
+            if ($result >= 0)
603
+            {
604
+                // Genere en-tete
605
+                $objmodel->write_header($outputlangs);
606
+
607
+                // Genere ligne de titre
608
+                $objmodel->write_title($this->array_export_fields[$indice],$array_selected,$outputlangs,$this->array_export_TypeFields[$indice]);
609
+
610
+                while ($obj = $this->db->fetch_object($resql))
611
+                {
612
+                    // Process special operations
613
+                    if (! empty($this->array_export_special[$indice]))
614
+                    {
615
+                        foreach ($this->array_export_special[$indice] as $key => $value)
616
+                        {
617
+                            if (! array_key_exists($key, $array_selected)) continue;		// Field not selected
618
+                            // Operation NULLIFNEG
619
+                            if ($this->array_export_special[$indice][$key]=='NULLIFNEG')
620
+                            {
621
+                                //$alias=$this->array_export_alias[$indice][$key];
622
+                                $alias=str_replace(array('.', '-','(',')'),'_',$key);
623
+                                if ($obj->$alias < 0) $obj->$alias='';
624
+                            }
625
+                            // Operation ZEROIFNEG
626
+                            elseif ($this->array_export_special[$indice][$key]=='ZEROIFNEG')
627
+                            {
628
+                                //$alias=$this->array_export_alias[$indice][$key];
629
+                                $alias=str_replace(array('.', '-','(',')'),'_',$key);
630
+                                if ($obj->$alias < 0) $obj->$alias='0';
631
+                            }
632
+                            // Operation INVOICEREMAINTOPAY
633
+                            elseif ($this->array_export_special[$indice][$key]=='getRemainToPay')
634
+                            {
635
+                                //$alias=$this->array_export_alias[$indice][$key];
636
+                                $alias=str_replace(array('.', '-','(',')'),'_',$key);
637
+                                $remaintopay='';
638
+                                if ($obj->f_rowid > 0)
639
+                                {
640
+                                    global $tmpobjforcomputecall;
641
+                                    if (! is_object($tmpobjforcomputecall))
642
+                                    {
643
+                                        include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
644
+                                        $tmpobjforcomputecall=new Facture($this->db);
645
+                                    }
646
+                                    $tmpobjforcomputecall->id = $obj->f_rowid;
647
+                                    $tmpobjforcomputecall->total_ttc = $obj->f_total_ttc;
648
+                                    $remaintopay=$tmpobjforcomputecall->getRemainToPay();
649
+                                }
650
+                                $obj->$alias=$remaintopay;
651
+                            }
652
+                            else
653
+                            {
654
+                                // TODO FIXME Export of compute field does not work. $obj containt $obj->alias_field and formulat will contains $obj->field
655
+                                $computestring=$this->array_export_special[$indice][$key];
656
+                                $tmp=dol_eval($computestring, 1, 0);
657
+                                $obj->$alias=$tmp;
658
+
659
+                                $this->error="ERROPNOTSUPPORTED. Operation ".$this->array_export_special[$indice][$key]." not supported. Export of 'computed' extrafields is not yet supported, please remove field.";
660
+                                return -1;
661
+                            }
662
+                        }
663
+                    }
664
+                    // end of special operation processing
665
+                    $objmodel->write_record($array_selected,$obj,$outputlangs,$this->array_export_TypeFields[$indice]);
666
+                }
667
+
668
+                // Genere en-tete
669
+                $objmodel->write_footer($outputlangs);
670
+
671
+                // Close file
672
+                $objmodel->close_file();
673
+
674
+                return 1;
675
+            }
676
+            else
677
+            {
678
+                $this->error=$objmodel->error;
679
+                dol_syslog("Export::build_file Error: ".$this->error, LOG_ERR);
680
+                return -1;
681
+            }
682
+        }
683
+        else
684
+        {
685
+            $this->error=$this->db->error()." - sql=".$sql;
686
+            return -1;
687
+        }
688
+    }
689
+
690
+    /**
691
+     *  Save an export model in database
692
+     *
693
+     *  @param		User	$user 	Object user that save
694
+     *  @return		int				<0 if KO, >0 if OK
695
+     */
696
+    function create($user)
697
+    {
698
+        global $conf;
699
+
700
+        dol_syslog("Export.class.php::create");
701
+
702
+        $this->db->begin();
703
+
704
+        $filter='';
705
+
706
+        $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'export_model (';
707
+        $sql.= 'label,';
708
+        $sql.= 'type,';
709
+        $sql.= 'field,';
710
+        $sql.= 'fk_user,';
711
+        $sql.= 'filter';
712
+        $sql.= ') VALUES (';
713
+        $sql.= "'".$this->db->escape($this->model_name)."',";
714
+        $sql.= "'".$this->db->escape($this->datatoexport)."',";
715
+        $sql.= "'".$this->db->escape($this->hexa)."',";
716
+        $sql.= "'".$user->id."',";
717
+        $sql.= "'".$this->db->escape($this->hexafiltervalue)."'";
718
+        $sql.= ")";
719
+
720
+        dol_syslog(get_class($this)."::create", LOG_DEBUG);
721
+        $resql=$this->db->query($sql);
722
+        if ($resql)
723
+        {
724
+            $this->db->commit();
725
+            return 1;
726
+        }
560 727
         else
561
-		{
562
-			// Define value for indice from $datatoexport
563
-			$foundindice=0;
564
-			foreach($this->array_export_code as $key => $dataset)
565
-			{
566
-				if ($datatoexport == $dataset)
567
-				{
568
-					$indice=$key;
569
-					$foundindice++;
570
-					//print "Found indice = ".$indice." for dataset=".$datatoexport."\n";
571
-					break;
572
-				}
573
-			}
574
-			if (empty($foundindice))
575
-			{
576
-				$this->error="ErrorBadParameter can't find dataset ".$datatoexport." into preload arrays this->array_export_code";
577
-				return -1;
578
-			}
579
-        	$sql=$this->build_sql($indice, $array_selected, $array_filterValue);
580
-		}
581
-
582
-		// Run the sql
583
-		$this->sqlusedforexport=$sql;
584
-		dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG);
585
-		$resql = $this->db->query($sql);
586
-		if ($resql)
587
-		{
588
-			//$this->array_export_label[$indice]
589
-			if ($conf->global->EXPORT_PREFIX_SPEC)
590
-				$filename=$conf->global->EXPORT_PREFIX_SPEC."_".$datatoexport;
591
-			else
592
-				$filename="export_".$datatoexport;
593
-			$filename.='.'.$objmodel->getDriverExtension();
594
-			$dirname=$conf->export->dir_temp.'/'.$user->id;
595
-
596
-			$outputlangs = clone $langs; // We clone to have an object we can modify (for example to change output charset by csv handler) without changing original value
597
-
598
-			// Open file
599
-			dol_mkdir($dirname);
600
-			$result=$objmodel->open_file($dirname."/".$filename, $outputlangs);
601
-
602
-			if ($result >= 0)
603
-			{
604
-				// Genere en-tete
605
-				$objmodel->write_header($outputlangs);
606
-
607
-				// Genere ligne de titre
608
-				$objmodel->write_title($this->array_export_fields[$indice],$array_selected,$outputlangs,$this->array_export_TypeFields[$indice]);
609
-
610
-				while ($obj = $this->db->fetch_object($resql))
611
-				{
612
-					// Process special operations
613
-					if (! empty($this->array_export_special[$indice]))
614
-					{
615
-						foreach ($this->array_export_special[$indice] as $key => $value)
616
-						{
617
-							if (! array_key_exists($key, $array_selected)) continue;		// Field not selected
618
-							// Operation NULLIFNEG
619
-							if ($this->array_export_special[$indice][$key]=='NULLIFNEG')
620
-							{
621
-								//$alias=$this->array_export_alias[$indice][$key];
622
-								$alias=str_replace(array('.', '-','(',')'),'_',$key);
623
-								if ($obj->$alias < 0) $obj->$alias='';
624
-							}
625
-							// Operation ZEROIFNEG
626
-							elseif ($this->array_export_special[$indice][$key]=='ZEROIFNEG')
627
-							{
628
-								//$alias=$this->array_export_alias[$indice][$key];
629
-								$alias=str_replace(array('.', '-','(',')'),'_',$key);
630
-								if ($obj->$alias < 0) $obj->$alias='0';
631
-							}
632
-							// Operation INVOICEREMAINTOPAY
633
-							elseif ($this->array_export_special[$indice][$key]=='getRemainToPay')
634
-							{
635
-								//$alias=$this->array_export_alias[$indice][$key];
636
-								$alias=str_replace(array('.', '-','(',')'),'_',$key);
637
-								$remaintopay='';
638
-								if ($obj->f_rowid > 0)
639
-								{
640
-								    global $tmpobjforcomputecall;
641
-								    if (! is_object($tmpobjforcomputecall))
642
-								    {
643
-								        include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
644
-								        $tmpobjforcomputecall=new Facture($this->db);
645
-								    }
646
-								    $tmpobjforcomputecall->id = $obj->f_rowid;
647
-								    $tmpobjforcomputecall->total_ttc = $obj->f_total_ttc;
648
-								    $remaintopay=$tmpobjforcomputecall->getRemainToPay();
649
-								}
650
-								$obj->$alias=$remaintopay;
651
-							}
652
-							else
653
-							{
654
-							    // TODO FIXME Export of compute field does not work. $obj containt $obj->alias_field and formulat will contains $obj->field
655
-							    $computestring=$this->array_export_special[$indice][$key];
656
-							    $tmp=dol_eval($computestring, 1, 0);
657
-							    $obj->$alias=$tmp;
658
-
659
-							    $this->error="ERROPNOTSUPPORTED. Operation ".$this->array_export_special[$indice][$key]." not supported. Export of 'computed' extrafields is not yet supported, please remove field.";
660
-							    return -1;
661
-							}
662
-						}
663
-					}
664
-					// end of special operation processing
665
-					$objmodel->write_record($array_selected,$obj,$outputlangs,$this->array_export_TypeFields[$indice]);
666
-				}
667
-
668
-				// Genere en-tete
669
-				$objmodel->write_footer($outputlangs);
670
-
671
-				// Close file
672
-				$objmodel->close_file();
673
-
674
-        		return 1;
675
-			}
676
-			else
677
-			{
678
-				$this->error=$objmodel->error;
679
-				dol_syslog("Export::build_file Error: ".$this->error, LOG_ERR);
680
-				return -1;
681
-			}
682
-		}
683
-		else
684
-		{
685
-			$this->error=$this->db->error()." - sql=".$sql;
686
-			return -1;
687
-		}
688
-	}
689
-
690
-	/**
691
-	 *  Save an export model in database
692
-	 *
693
-	 *  @param		User	$user 	Object user that save
694
-	 *  @return		int				<0 if KO, >0 if OK
695
-	 */
696
-	function create($user)
697
-	{
698
-		global $conf;
699
-
700
-		dol_syslog("Export.class.php::create");
701
-
702
-		$this->db->begin();
703
-
704
-		$filter='';
705
-
706
-		$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'export_model (';
707
-		$sql.= 'label,';
708
-		$sql.= 'type,';
709
-		$sql.= 'field,';
710
-		$sql.= 'fk_user,';
711
-		$sql.= 'filter';
712
-		$sql.= ') VALUES (';
713
-		$sql.= "'".$this->db->escape($this->model_name)."',";
714
-		$sql.= "'".$this->db->escape($this->datatoexport)."',";
715
-		$sql.= "'".$this->db->escape($this->hexa)."',";
716
-		$sql.= "'".$user->id."',";
717
-		$sql.= "'".$this->db->escape($this->hexafiltervalue)."'";
718
-		$sql.= ")";
719
-
720
-		dol_syslog(get_class($this)."::create", LOG_DEBUG);
721
-		$resql=$this->db->query($sql);
722
-		if ($resql)
723
-		{
724
-			$this->db->commit();
725
-			return 1;
726
-		}
727
-		else
728
-		{
729
-			$this->error=$this->db->lasterror();
730
-			$this->errno=$this->db->lasterrno();
731
-			$this->db->rollback();
732
-			return -1;
733
-		}
734
-	}
735
-
736
-	/**
737
-	 *  Load an export profil from database
738
-	 *
739
-	 *  @param		int		$id		Id of profil to load
740
-	 *  @return		int				<0 if KO, >0 if OK
741
-	 */
742
-	function fetch($id)
743
-	{
744
-		$sql = 'SELECT em.rowid, em.label, em.type, em.field, em.filter';
745
-		$sql.= ' FROM '.MAIN_DB_PREFIX.'export_model as em';
746
-		$sql.= ' WHERE em.rowid = '.$id;
747
-
748
-		dol_syslog("Export::fetch", LOG_DEBUG);
749
-		$result = $this->db->query($sql);
750
-		if ($result)
751
-		{
752
-			$obj = $this->db->fetch_object($result);
753
-			if ($obj)
754
-			{
755
-				$this->id				= $obj->rowid;
756
-				$this->model_name		= $obj->label;
757
-				$this->datatoexport		= $obj->type;
758
-
759
-				$this->hexa				= $obj->field;
760
-				$this->hexafiltervalue	= $obj->filter;
761
-
762
-				return 1;
763
-			}
764
-			else
765
-			{
766
-				$this->error="ModelNotFound";
767
-				return -2;
768
-			}
769
-		}
770
-		else
771
-		{
772
-			dol_print_error($this->db);
773
-			return -3;
774
-		}
775
-	}
776
-
777
-
778
-	/**
779
-	 *	Delete object in database
780
-	 *
781
-	 *	@param      User		$user        	User that delete
782
-	 *  @param      int			$notrigger	    0=launch triggers after, 1=disable triggers
783
-	 *	@return		int							<0 if KO, >0 if OK
784
-	 */
785
-	function delete($user, $notrigger=0)
786
-	{
787
-		global $conf, $langs;
788
-		$error=0;
789
-
790
-		$sql = "DELETE FROM ".MAIN_DB_PREFIX."export_model";
791
-		$sql.= " WHERE rowid=".$this->id;
792
-
793
-		$this->db->begin();
794
-
795
-		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
796
-		$resql = $this->db->query($sql);
797
-		if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
798
-
799
-		if (! $error)
800
-		{
801
-			if (! $notrigger)
802
-			{
803
-				// Uncomment this and change MYOBJECT to your own tag if you
804
-				// want this action call a trigger.
805
-
806
-				//// Call triggers
807
-				//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
808
-				//$interface=new Interfaces($this->db);
809
-				//$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
810
-				//if ($result < 0) { $error++; $this->errors=$interface->errors; }
811
-				//// End call triggers
812
-			}
813
-		}
814
-
815
-		// Commit or rollback
816
-		if ($error)
817
-		{
818
-			foreach($this->errors as $errmsg)
819
-			{
820
-				dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
821
-				$this->error.=($this->error?', '.$errmsg:$errmsg);
822
-			}
823
-			$this->db->rollback();
824
-			return -1*$error;
825
-		}
826
-		else
827
-		{
828
-			$this->db->commit();
829
-			return 1;
830
-		}
831
-	}
728
+        {
729
+            $this->error=$this->db->lasterror();
730
+            $this->errno=$this->db->lasterrno();
731
+            $this->db->rollback();
732
+            return -1;
733
+        }
734
+    }
735
+
736
+    /**
737
+     *  Load an export profil from database
738
+     *
739
+     *  @param		int		$id		Id of profil to load
740
+     *  @return		int				<0 if KO, >0 if OK
741
+     */
742
+    function fetch($id)
743
+    {
744
+        $sql = 'SELECT em.rowid, em.label, em.type, em.field, em.filter';
745
+        $sql.= ' FROM '.MAIN_DB_PREFIX.'export_model as em';
746
+        $sql.= ' WHERE em.rowid = '.$id;
747
+
748
+        dol_syslog("Export::fetch", LOG_DEBUG);
749
+        $result = $this->db->query($sql);
750
+        if ($result)
751
+        {
752
+            $obj = $this->db->fetch_object($result);
753
+            if ($obj)
754
+            {
755
+                $this->id				= $obj->rowid;
756
+                $this->model_name		= $obj->label;
757
+                $this->datatoexport		= $obj->type;
758
+
759
+                $this->hexa				= $obj->field;
760
+                $this->hexafiltervalue	= $obj->filter;
761
+
762
+                return 1;
763
+            }
764
+            else
765
+            {
766
+                $this->error="ModelNotFound";
767
+                return -2;
768
+            }
769
+        }
770
+        else
771
+        {
772
+            dol_print_error($this->db);
773
+            return -3;
774
+        }
775
+    }
776
+
777
+
778
+    /**
779
+     *	Delete object in database
780
+     *
781
+     *	@param      User		$user        	User that delete
782
+     *  @param      int			$notrigger	    0=launch triggers after, 1=disable triggers
783
+     *	@return		int							<0 if KO, >0 if OK
784
+     */
785
+    function delete($user, $notrigger=0)
786
+    {
787
+        global $conf, $langs;
788
+        $error=0;
789
+
790
+        $sql = "DELETE FROM ".MAIN_DB_PREFIX."export_model";
791
+        $sql.= " WHERE rowid=".$this->id;
792
+
793
+        $this->db->begin();
794
+
795
+        dol_syslog(get_class($this)."::delete", LOG_DEBUG);
796
+        $resql = $this->db->query($sql);
797
+        if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
798
+
799
+        if (! $error)
800
+        {
801
+            if (! $notrigger)
802
+            {
803
+                // Uncomment this and change MYOBJECT to your own tag if you
804
+                // want this action call a trigger.
805
+
806
+                //// Call triggers
807
+                //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
808
+                //$interface=new Interfaces($this->db);
809
+                //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
810
+                //if ($result < 0) { $error++; $this->errors=$interface->errors; }
811
+                //// End call triggers
812
+            }
813
+        }
814
+
815
+        // Commit or rollback
816
+        if ($error)
817
+        {
818
+            foreach($this->errors as $errmsg)
819
+            {
820
+                dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
821
+                $this->error.=($this->error?', '.$errmsg:$errmsg);
822
+            }
823
+            $this->db->rollback();
824
+            return -1*$error;
825
+        }
826
+        else
827
+        {
828
+            $this->db->commit();
829
+            return 1;
830
+        }
831
+    }
832 832
 
833 833
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
834
-	/**
835
-	 *	Output list all export models
836
-	 *  TODO Move this into a class htmlxxx.class.php
837
-	 *
838
-	 *	@return	void
839
-	 */
840
-	function list_export_model()
841
-	{
834
+    /**
835
+     *	Output list all export models
836
+     *  TODO Move this into a class htmlxxx.class.php
837
+     *
838
+     *	@return	void
839
+     */
840
+    function list_export_model()
841
+    {
842 842
         // phpcs:enable
843
-		global $conf, $langs;
844
-
845
-		$sql = "SELECT em.rowid, em.field, em.label, em.type, em.filter";
846
-		$sql.= " FROM ".MAIN_DB_PREFIX."export_model as em";
847
-		$sql.= " ORDER BY rowid";
848
-
849
-		$result = $this->db->query($sql);
850
-		if ($result)
851
-		{
852
-			$num = $this->db->num_rows($result);
853
-			$i = 0;
854
-			while ($i < $num)
855
-			{
856
-				$obj = $this->db->fetch_object($result);
857
-				$keyModel = array_search($obj->type, $this->array_export_code);
858
-				print "<tr>";
859
-				print '<td><a href=export.php?step=2&action=select_model&exportmodelid='.$obj->rowid.'&datatoexport='.$obj->type.'>'.$obj->label.'</a></td>';
860
-				print '<td>';
861
-				print img_object($this->array_export_module[$keyModel]->getName(),$this->array_export_icon[$keyModel]).' ';
862
-				print $this->array_export_module[$keyModel]->getName().' - ';
863
-				// recuperation du nom de l'export
864
-
865
-				$string=$langs->trans($this->array_export_label[$keyModel]);
866
-				print ($string!=$this->array_export_label[$keyModel]?$string:$this->array_export_label[$keyModel]);
867
-				print '</td>';
868
-				//print '<td>'.$obj->type.$keyModel.'</td>';
869
-				print '<td>'.str_replace(',',' , ',$obj->field).'</td>';
870
-				if (! empty($obj->filter)) {
871
-					$filter = json_decode($obj->filter, true);
872
-					print '<td>'.str_replace(',',' , ',$filter['field']).'</td>';
873
-					print '<td>'.str_replace(',',' , ',$filter['value']).'</td>';
874
-				}
875
-				// suppression de l'export
876
-				print '<td align="right">';
877
-				print '<a href="'.$_SERVER["PHP_SELF"].'?action=deleteprof&id='.$obj->rowid.'">';
878
-				print img_delete();
879
-				print '</a>';
880
-				print "</tr>";
881
-
882
-				$i++;
883
-			}
884
-		}
885
-		else {
886
-			dol_print_error($this->db);
887
-		}
888
-	}
843
+        global $conf, $langs;
844
+
845
+        $sql = "SELECT em.rowid, em.field, em.label, em.type, em.filter";
846
+        $sql.= " FROM ".MAIN_DB_PREFIX."export_model as em";
847
+        $sql.= " ORDER BY rowid";
848
+
849
+        $result = $this->db->query($sql);
850
+        if ($result)
851
+        {
852
+            $num = $this->db->num_rows($result);
853
+            $i = 0;
854
+            while ($i < $num)
855
+            {
856
+                $obj = $this->db->fetch_object($result);
857
+                $keyModel = array_search($obj->type, $this->array_export_code);
858
+                print "<tr>";
859
+                print '<td><a href=export.php?step=2&action=select_model&exportmodelid='.$obj->rowid.'&datatoexport='.$obj->type.'>'.$obj->label.'</a></td>';
860
+                print '<td>';
861
+                print img_object($this->array_export_module[$keyModel]->getName(),$this->array_export_icon[$keyModel]).' ';
862
+                print $this->array_export_module[$keyModel]->getName().' - ';
863
+                // recuperation du nom de l'export
864
+
865
+                $string=$langs->trans($this->array_export_label[$keyModel]);
866
+                print ($string!=$this->array_export_label[$keyModel]?$string:$this->array_export_label[$keyModel]);
867
+                print '</td>';
868
+                //print '<td>'.$obj->type.$keyModel.'</td>';
869
+                print '<td>'.str_replace(',',' , ',$obj->field).'</td>';
870
+                if (! empty($obj->filter)) {
871
+                    $filter = json_decode($obj->filter, true);
872
+                    print '<td>'.str_replace(',',' , ',$filter['field']).'</td>';
873
+                    print '<td>'.str_replace(',',' , ',$filter['value']).'</td>';
874
+                }
875
+                // suppression de l'export
876
+                print '<td align="right">';
877
+                print '<a href="'.$_SERVER["PHP_SELF"].'?action=deleteprof&id='.$obj->rowid.'">';
878
+                print img_delete();
879
+                print '</a>';
880
+                print "</tr>";
881
+
882
+                $i++;
883
+            }
884
+        }
885
+        else {
886
+            dol_print_error($this->db);
887
+        }
888
+    }
889 889
 }
Please login to merge, or discard this patch.
Spacing   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -35,20 +35,20 @@  discard block
 block discarded – undo
35 35
      */
36 36
     public $db;
37 37
 
38
-	var $array_export_code=array();             // Tableau de "idmodule_numlot"
39
-	var $array_export_module=array();           // Tableau de "nom de modules"
40
-	var $array_export_label=array();            // Tableau de "libelle de lots"
41
-	var $array_export_sql_start=array();        // Tableau des "requetes sql"
42
-	var $array_export_sql_end=array();          // Tableau des "requetes sql"
43
-	var $array_export_sql_order=array();        // Tableau des "requetes sql"
44
-
45
-	var $array_export_fields=array();           // Tableau des listes de champ+libelle a exporter
46
-	var $array_export_TypeFields=array();		// Tableau des listes de champ+Type de filtre
47
-	var $array_export_FilterValue=array();		// Tableau des listes de champ+Valeur a filtrer
48
-	var $array_export_entities=array();         // Tableau des listes de champ+alias a exporter
49
-	var $array_export_dependencies=array();     // array of list of entities that must take care of the DISTINCT if a field is added into export
50
-	var $array_export_special=array();          // Tableau des operations speciales sur champ
51
-    var $array_export_examplevalues=array();    // array with examples
38
+	var $array_export_code = array(); // Tableau de "idmodule_numlot"
39
+	var $array_export_module = array(); // Tableau de "nom de modules"
40
+	var $array_export_label = array(); // Tableau de "libelle de lots"
41
+	var $array_export_sql_start = array(); // Tableau des "requetes sql"
42
+	var $array_export_sql_end = array(); // Tableau des "requetes sql"
43
+	var $array_export_sql_order = array(); // Tableau des "requetes sql"
44
+
45
+	var $array_export_fields = array(); // Tableau des listes de champ+libelle a exporter
46
+	var $array_export_TypeFields = array(); // Tableau des listes de champ+Type de filtre
47
+	var $array_export_FilterValue = array(); // Tableau des listes de champ+Valeur a filtrer
48
+	var $array_export_entities = array(); // Tableau des listes de champ+alias a exporter
49
+	var $array_export_dependencies = array(); // array of list of entities that must take care of the DISTINCT if a field is added into export
50
+	var $array_export_special = array(); // Tableau des operations speciales sur champ
51
+    var $array_export_examplevalues = array(); // array with examples
52 52
 
53 53
 	// To store export modules
54 54
 	var $hexa;
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	function __construct($db)
68 68
 	{
69
-		$this->db=$db;
69
+		$this->db = $db;
70 70
 	}
71 71
 
72 72
 
@@ -78,38 +78,38 @@  discard block
 block discarded – undo
78 78
 	 *    @param  	string		$filter    	Load a particular dataset only
79 79
 	 *    @return	int						<0 if KO, >0 if OK
80 80
 	 */
81
-	function load_arrays($user,$filter='')
81
+	function load_arrays($user, $filter = '')
82 82
 	{
83 83
         // phpcs:enable
84
-		global $langs,$conf,$mysoc;
84
+		global $langs, $conf, $mysoc;
85 85
 
86 86
 		dol_syslog(get_class($this)."::load_arrays user=".$user->id." filter=".$filter);
87 87
 
88
-        $i=0;
88
+        $i = 0;
89 89
 
90 90
         // Define list of modules directories into modulesdir
91 91
         require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
92 92
 
93 93
         $modulesdir = dolGetModulesDirs();
94 94
 
95
-		foreach($modulesdir as $dir)
95
+		foreach ($modulesdir as $dir)
96 96
 		{
97 97
 			// Search available exports
98
-			$handle=@opendir(dol_osencode($dir));
98
+			$handle = @opendir(dol_osencode($dir));
99 99
 			if (is_resource($handle))
100 100
 			{
101 101
                 // Search module files
102
-			    while (($file = readdir($handle))!==false)
102
+			    while (($file = readdir($handle)) !== false)
103 103
 				{
104
-					if (is_readable($dir.$file) && preg_match("/^(mod.*)\.class\.php$/i",$file,$reg))
104
+					if (is_readable($dir.$file) && preg_match("/^(mod.*)\.class\.php$/i", $file, $reg))
105 105
 					{
106
-						$modulename=$reg[1];
106
+						$modulename = $reg[1];
107 107
 
108 108
 						// Defined if module is enabled
109
-						$enabled=true;
110
-						$part=strtolower(preg_replace('/^mod/i','',$modulename));
111
-						if ($part == 'propale') $part='propal';
112
-						if (empty($conf->$part->enabled)) $enabled=false;
109
+						$enabled = true;
110
+						$part = strtolower(preg_replace('/^mod/i', '', $modulename));
111
+						if ($part == 'propale') $part = 'propal';
112
+						if (empty($conf->$part->enabled)) $enabled = false;
113 113
 
114 114
 						if ($enabled)
115 115
 						{
@@ -121,32 +121,32 @@  discard block
 block discarded – undo
121 121
 
122 122
 							if (isset($module->export_code) && is_array($module->export_code))
123 123
 							{
124
-							    foreach($module->export_code as $r => $value)
124
+							    foreach ($module->export_code as $r => $value)
125 125
 								{
126 126
                                     //print $i.'-'.$filter.'-'.$modulename.'-'.join(',',$module->export_code).'<br>';
127 127
 								    if ($filter && ($filter != $module->export_code[$r])) continue;
128 128
 
129 129
                                     // Test if condition to show are ok
130
-                                    if (! empty($module->export_enabled[$r]) && ! verifCond($module->export_enabled[$r])) continue;
130
+                                    if (!empty($module->export_enabled[$r]) && !verifCond($module->export_enabled[$r])) continue;
131 131
 
132 132
                                     // Test if permissions are ok
133
-									$bool=true;
133
+									$bool = true;
134 134
 									if (isset($module->export_permission))
135 135
 									{
136
-										foreach($module->export_permission[$r] as $val)
136
+										foreach ($module->export_permission[$r] as $val)
137 137
 										{
138
-	    									$perm=$val;
138
+	    									$perm = $val;
139 139
 	    									//print_r("$perm[0]-$perm[1]-$perm[2]<br>");
140
-	    									if (! empty($perm[2]))
140
+	    									if (!empty($perm[2]))
141 141
 	    									{
142
-	    										$bool=$user->rights->{$perm[0]}->{$perm[1]}->{$perm[2]};
142
+	    										$bool = $user->rights->{$perm[0]}->{$perm[1]}->{$perm[2]};
143 143
 	    									}
144 144
 	    									else
145 145
 	    									{
146
-	    										$bool=$user->rights->{$perm[0]}->{$perm[1]};
146
+	    										$bool = $user->rights->{$perm[0]}->{$perm[1]};
147 147
 	    									}
148
-	    									if ($perm[0]=='user' && $user->admin) $bool=true;
149
-	    									if (! $bool) break;
148
+	    									if ($perm[0] == 'user' && $user->admin) $bool = true;
149
+	    									if (!$bool) break;
150 150
 										}
151 151
 									}
152 152
 									//print $bool." $perm[0]"."<br>";
@@ -155,45 +155,45 @@  discard block
 block discarded – undo
155 155
 									//	          if ($bool)
156 156
 									//	          {
157 157
 									// Charge fichier lang en rapport
158
-									$langtoload=$module->getLangFilesArray();
158
+									$langtoload = $module->getLangFilesArray();
159 159
 									if (is_array($langtoload))
160 160
 									{
161
-										foreach($langtoload as $key)
161
+										foreach ($langtoload as $key)
162 162
 										{
163 163
 											$langs->load($key);
164 164
 										}
165 165
 									}
166 166
 
167 167
 									// Module
168
-									$this->array_export_module[$i]=$module;
168
+									$this->array_export_module[$i] = $module;
169 169
 									// Permission
170
-									$this->array_export_perms[$i]=$bool;
170
+									$this->array_export_perms[$i] = $bool;
171 171
 									// Icon
172
-									$this->array_export_icon[$i]=(isset($module->export_icon[$r])?$module->export_icon[$r]:$module->picto);
172
+									$this->array_export_icon[$i] = (isset($module->export_icon[$r]) ? $module->export_icon[$r] : $module->picto);
173 173
 									// Code du dataset export
174
-									$this->array_export_code[$i]=$module->export_code[$r];
174
+									$this->array_export_code[$i] = $module->export_code[$r];
175 175
 									// Libelle du dataset export
176
-									$this->array_export_label[$i]=$module->getExportDatasetLabel($r);
176
+									$this->array_export_label[$i] = $module->getExportDatasetLabel($r);
177 177
 									// Tableau des champ a exporter (cle=champ, valeur=libelle)
178
-									$this->array_export_fields[$i]=$module->export_fields_array[$r];
178
+									$this->array_export_fields[$i] = $module->export_fields_array[$r];
179 179
 									// Tableau des champs a filtrer (cle=champ, valeur1=type de donnees) on verifie que le module a des filtres
180
-									$this->array_export_TypeFields[$i]=(isset($module->export_TypeFields_array[$r])?$module->export_TypeFields_array[$r]:'');
180
+									$this->array_export_TypeFields[$i] = (isset($module->export_TypeFields_array[$r]) ? $module->export_TypeFields_array[$r] : '');
181 181
 									// Tableau des entites a exporter (cle=champ, valeur=entite)
182
-									$this->array_export_entities[$i]=$module->export_entities_array[$r];
182
+									$this->array_export_entities[$i] = $module->export_entities_array[$r];
183 183
 									// Tableau des entites qui requiert abandon du DISTINCT (cle=entite, valeur=champ id child records)
184
-									$this->array_export_dependencies[$i]=(! empty($module->export_dependencies_array[$r])?$module->export_dependencies_array[$r]:'');
184
+									$this->array_export_dependencies[$i] = (!empty($module->export_dependencies_array[$r]) ? $module->export_dependencies_array[$r] : '');
185 185
 									// Tableau des operations speciales sur champ
186
-									$this->array_export_special[$i]=(! empty($module->export_special_array[$r])?$module->export_special_array[$r]:'');
186
+									$this->array_export_special[$i] = (!empty($module->export_special_array[$r]) ? $module->export_special_array[$r] : '');
187 187
             						// Array of examples
188
-            						$this->array_export_examplevalues[$i]=$module->export_examplevalues_array[$r];
188
+            						$this->array_export_examplevalues[$i] = $module->export_examplevalues_array[$r];
189 189
 
190 190
 									// Requete sql du dataset
191
-									$this->array_export_sql_start[$i]=$module->export_sql_start[$r];
192
-									$this->array_export_sql_end[$i]=$module->export_sql_end[$r];
193
-									$this->array_export_sql_order[$i]=$module->export_sql_order[$r];
191
+									$this->array_export_sql_start[$i] = $module->export_sql_start[$r];
192
+									$this->array_export_sql_end[$i] = $module->export_sql_end[$r];
193
+									$this->array_export_sql_order[$i] = $module->export_sql_order[$r];
194 194
 									//$this->array_export_sql[$i]=$module->export_sql[$r];
195 195
 
196
-									dol_syslog(get_class($this)."::load_arrays loaded for module ".$modulename." with index ".$i.", dataset=".$module->export_code[$r].", nb of fields=".(! empty($module->export_fields_code[$r])?count($module->export_fields_code[$r]):''));
196
+									dol_syslog(get_class($this)."::load_arrays loaded for module ".$modulename." with index ".$i.", dataset=".$module->export_code[$r].", nb of fields=".(!empty($module->export_fields_code[$r]) ?count($module->export_fields_code[$r]) : ''));
197 197
 									$i++;
198 198
 									//	          }
199 199
 								}
@@ -223,42 +223,42 @@  discard block
 block discarded – undo
223 223
 	{
224 224
         // phpcs:enable
225 225
 		// Build the sql request
226
-		$sql=$this->array_export_sql_start[$indice];
227
-		$i=0;
226
+		$sql = $this->array_export_sql_start[$indice];
227
+		$i = 0;
228 228
 
229 229
 		//print_r($array_selected);
230 230
 		foreach ($this->array_export_fields[$indice] as $key => $value)
231 231
 		{
232
-			if (! array_key_exists($key, $array_selected)) continue;		// Field not selected
233
-            if (preg_match('/^none\./', $key)) continue;                    // A field that must not appears into SQL
234
-			if ($i > 0) $sql.=', ';
232
+			if (!array_key_exists($key, $array_selected)) continue; // Field not selected
233
+            if (preg_match('/^none\./', $key)) continue; // A field that must not appears into SQL
234
+			if ($i > 0) $sql .= ', ';
235 235
 			else $i++;
236 236
 
237
-			if (strpos($key, ' as ')===false) {
238
-				$newfield=$key.' as '.str_replace(array('.', '-','(',')'),'_',$key);
237
+			if (strpos($key, ' as ') === false) {
238
+				$newfield = $key.' as '.str_replace(array('.', '-', '(', ')'), '_', $key);
239 239
 			} else {
240
-				$newfield=$key;
240
+				$newfield = $key;
241 241
 			}
242 242
 
243
-			$sql.=$newfield;
243
+			$sql .= $newfield;
244 244
 		}
245
-		$sql.=$this->array_export_sql_end[$indice];
245
+		$sql .= $this->array_export_sql_end[$indice];
246 246
 
247 247
 		// Add the WHERE part. Filtering into sql if a filtering array is provided
248 248
 		if (is_array($array_filterValue) && !empty($array_filterValue))
249 249
 		{
250
-			$sqlWhere='';
250
+			$sqlWhere = '';
251 251
 			// Loop on each condition to add
252 252
 			foreach ($array_filterValue as $key => $value)
253 253
 			{
254 254
 			    if (preg_match('/GROUP_CONCAT/i', $key)) continue;
255
-				if ($value != '') $sqlWhere.=" and ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
255
+				if ($value != '') $sqlWhere .= " and ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
256 256
 			}
257
-			$sql.=$sqlWhere;
257
+			$sql .= $sqlWhere;
258 258
 		}
259 259
 
260 260
 		// Add the order
261
-		$sql.=$this->array_export_sql_order[$indice];
261
+		$sql .= $this->array_export_sql_order[$indice];
262 262
 
263 263
 		// Add the HAVING part.
264 264
 		if (is_array($array_filterValue) && !empty($array_filterValue))
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 		    // Loop on each condition to add
267 267
 		    foreach ($array_filterValue as $key => $value)
268 268
 		    {
269
-		        if (preg_match('/GROUP_CONCAT/i', $key) and $value != '') $sql.=" HAVING ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
269
+		        if (preg_match('/GROUP_CONCAT/i', $key) and $value != '') $sql .= " HAVING ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
270 270
 		    }
271 271
 		}
272 272
 
@@ -290,25 +290,25 @@  discard block
 block discarded – undo
290 290
 		// build the input field on depend of the type of file
291 291
 		switch ($InfoFieldList[0]) {
292 292
 			case 'Text':
293
-				if (! (strpos($ValueField, '%') === false))
294
-					$szFilterQuery.=" ".$NameField." LIKE '".$ValueField."'";
293
+				if (!(strpos($ValueField, '%') === false))
294
+					$szFilterQuery .= " ".$NameField." LIKE '".$ValueField."'";
295 295
 				else
296
-					$szFilterQuery.=" ".$NameField." = '".$ValueField."'";
296
+					$szFilterQuery .= " ".$NameField." = '".$ValueField."'";
297 297
 				break;
298 298
 			case 'Date':
299 299
 				if (strpos($ValueField, "+") > 0)
300 300
 				{
301 301
 					// mode plage
302 302
 					$ValueArray = explode("+", $ValueField);
303
-					$szFilterQuery ="(".$this->conditionDate($NameField,trim($ValueArray[0]),">=");
304
-					$szFilterQuery.=" AND ".$this->conditionDate($NameField,trim($ValueArray[1]),"<=").")";
303
+					$szFilterQuery = "(".$this->conditionDate($NameField, trim($ValueArray[0]), ">=");
304
+					$szFilterQuery .= " AND ".$this->conditionDate($NameField, trim($ValueArray[1]), "<=").")";
305 305
 				}
306 306
 				else
307 307
 				{
308
-					if (is_numeric(substr($ValueField,0,1)))
309
-						$szFilterQuery=$this->conditionDate($NameField,trim($ValueField),"=");
308
+					if (is_numeric(substr($ValueField, 0, 1)))
309
+						$szFilterQuery = $this->conditionDate($NameField, trim($ValueField), "=");
310 310
 					else
311
-						$szFilterQuery=$this->conditionDate($NameField,trim(substr($ValueField,1)),substr($ValueField,0,1));
311
+						$szFilterQuery = $this->conditionDate($NameField, trim(substr($ValueField, 1)), substr($ValueField, 0, 1));
312 312
 				}
313 313
 				break;
314 314
 			case 'Duree':
@@ -319,29 +319,29 @@  discard block
 block discarded – undo
319 319
 				{
320 320
 					// mode plage
321 321
 					$ValueArray = explode("+", $ValueField);
322
-					$szFilterQuery ="(".$NameField.">=".$ValueArray[0];
323
-					$szFilterQuery.=" AND ".$NameField."<=".$ValueArray[1].")";
322
+					$szFilterQuery = "(".$NameField.">=".$ValueArray[0];
323
+					$szFilterQuery .= " AND ".$NameField."<=".$ValueArray[1].")";
324 324
 				}
325 325
 				else
326 326
 				{
327
-					if (is_numeric(substr($ValueField,0,1)))
328
-						$szFilterQuery=" ".$NameField."=".$ValueField;
327
+					if (is_numeric(substr($ValueField, 0, 1)))
328
+						$szFilterQuery = " ".$NameField."=".$ValueField;
329 329
 					else
330
-						$szFilterQuery=" ".$NameField.substr($ValueField,0,1).substr($ValueField,1);
330
+						$szFilterQuery = " ".$NameField.substr($ValueField, 0, 1).substr($ValueField, 1);
331 331
 				}
332 332
 				break;
333 333
 			case 'Boolean':
334
-				$szFilterQuery=" ".$NameField."=".(is_numeric($ValueField) ? $ValueField : ($ValueField =='yes' ? 1: 0) );
334
+				$szFilterQuery = " ".$NameField."=".(is_numeric($ValueField) ? $ValueField : ($ValueField == 'yes' ? 1 : 0));
335 335
 				break;
336 336
 			case 'Status':
337 337
 			case 'List':
338 338
 				if (is_numeric($ValueField))
339
-					$szFilterQuery=" ".$NameField."=".$ValueField;
339
+					$szFilterQuery = " ".$NameField."=".$ValueField;
340 340
 				else {
341
-                    if (! (strpos($ValueField, '%') === false))
342
-                        $szFilterQuery=" ".$NameField." LIKE '".$ValueField."'";
341
+                    if (!(strpos($ValueField, '%') === false))
342
+                        $szFilterQuery = " ".$NameField." LIKE '".$ValueField."'";
343 343
                     else
344
-                        $szFilterQuery=" ".$NameField." = '".$ValueField."'";
344
+                        $szFilterQuery = " ".$NameField." = '".$ValueField."'";
345 345
 				}
346 346
 				break;
347 347
 			default:
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
 	function conditionDate($Field, $Value, $Sens)
363 363
 	{
364 364
 		// TODO date_format is forbidden, not performant and not portable. Use instead BETWEEN
365
-		if (strlen($Value)==4) $Condition=" date_format(".$Field.",'%Y') ".$Sens." '".$Value."'";
366
-		elseif (strlen($Value)==6) $Condition=" date_format(".$Field.",'%Y%m') ".$Sens." '".$Value."'";
367
-		else  $Condition=" date_format(".$Field.",'%Y%m%d') ".$Sens." ".$Value;
365
+		if (strlen($Value) == 4) $Condition = " date_format(".$Field.",'%Y') ".$Sens." '".$Value."'";
366
+		elseif (strlen($Value) == 6) $Condition = " date_format(".$Field.",'%Y%m') ".$Sens." '".$Value."'";
367
+		else  $Condition = " date_format(".$Field.",'%Y%m%d') ".$Sens." ".$Value;
368 368
 		return $Condition;
369 369
 	}
370 370
 
@@ -380,9 +380,9 @@  discard block
 block discarded – undo
380 380
 	function build_filterField($TypeField, $NameField, $ValueField)
381 381
 	{
382 382
         // phpcs:enable
383
-		global $conf,$langs;
383
+		global $conf, $langs;
384 384
 
385
-		$szFilterField='';
385
+		$szFilterField = '';
386 386
 		$InfoFieldList = explode(":", $TypeField);
387 387
 
388 388
 		// build the input field on depend of the type of file
@@ -390,52 +390,52 @@  discard block
 block discarded – undo
390 390
 		{
391 391
 			case 'Text':
392 392
 			case 'Date':
393
-				$szFilterField='<input type="text" name="'.$NameField.'" value="'.$ValueField.'">';
393
+				$szFilterField = '<input type="text" name="'.$NameField.'" value="'.$ValueField.'">';
394 394
 				break;
395 395
 			case 'Duree':
396 396
 			case 'Numeric':
397 397
 			case 'Number':
398 398
 				// Must be a string text to allow to use comparison strings like "<= 999"
399
-			    $szFilterField='<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
399
+			    $szFilterField = '<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
400 400
 				break;
401 401
 			case 'Status':
402
-				if (! empty($conf->global->MAIN_ACTIVATE_HTML5)) $szFilterField='<input type="number" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
403
-				else $szFilterField='<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
402
+				if (!empty($conf->global->MAIN_ACTIVATE_HTML5)) $szFilterField = '<input type="number" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
403
+				else $szFilterField = '<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
404 404
 				break;
405 405
 			case 'Boolean':
406
-				$szFilterField='<select name="'.$NameField.'" class="flat">';
407
-				$szFilterField.='<option ';
408
-				if ($ValueField=='') $szFilterField.=' selected ';
409
-				$szFilterField.=' value="">&nbsp;</option>';
410
-
411
-				$szFilterField.='<option ';
412
-				if ($ValueField=='yes' || $ValueField == '1') $szFilterField.=' selected ';
413
-				$szFilterField.=' value="1">'.yn(1).'</option>';
414
-
415
-				$szFilterField.='<option ';
416
-				if ($ValueField=='no' || $ValueField=='0') $szFilterField.=' selected ';
417
-				$szFilterField.=' value="0">'.yn(0).'</option>';
418
-				$szFilterField.="</select>";
406
+				$szFilterField = '<select name="'.$NameField.'" class="flat">';
407
+				$szFilterField .= '<option ';
408
+				if ($ValueField == '') $szFilterField .= ' selected ';
409
+				$szFilterField .= ' value="">&nbsp;</option>';
410
+
411
+				$szFilterField .= '<option ';
412
+				if ($ValueField == 'yes' || $ValueField == '1') $szFilterField .= ' selected ';
413
+				$szFilterField .= ' value="1">'.yn(1).'</option>';
414
+
415
+				$szFilterField .= '<option ';
416
+				if ($ValueField == 'no' || $ValueField == '0') $szFilterField .= ' selected ';
417
+				$szFilterField .= ' value="0">'.yn(0).'</option>';
418
+				$szFilterField .= "</select>";
419 419
 				break;
420 420
 			case 'List':
421 421
 				// 0 : Type du champ
422 422
 				// 1 : Nom de la table
423 423
 				// 2 : Nom du champ contenant le libelle
424 424
 				// 3 : Name of field with key (if it is not "rowid"). Used this field as key for combo list.
425
-				if (count($InfoFieldList)==4)
426
-					$keyList=$InfoFieldList[3];
425
+				if (count($InfoFieldList) == 4)
426
+					$keyList = $InfoFieldList[3];
427 427
 				else
428
-					$keyList='rowid';
429
-				$sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3])?'':', '.$InfoFieldList[3].' as code');
430
-				if ($InfoFieldList[1] == 'c_stcomm') $sql = 'SELECT id as id, '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3])?'':', '.$InfoFieldList[3].' as code');
428
+					$keyList = 'rowid';
429
+				$sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3]) ? '' : ', '.$InfoFieldList[3].' as code');
430
+				if ($InfoFieldList[1] == 'c_stcomm') $sql = 'SELECT id as id, '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3]) ? '' : ', '.$InfoFieldList[3].' as code');
431 431
 				if ($InfoFieldList[1] == 'c_country') $sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label, code as code';
432
-				$sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[1];
432
+				$sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[1];
433 433
 
434 434
 				$resql = $this->db->query($sql);
435 435
 				if ($resql)
436 436
 				{
437
-					$szFilterField='<select class="flat" name="'.$NameField.'">';
438
-					$szFilterField.='<option value="0">&nbsp;</option>';
437
+					$szFilterField = '<select class="flat" name="'.$NameField.'">';
438
+					$szFilterField .= '<option value="0">&nbsp;</option>';
439 439
 					$num = $this->db->num_rows($resql);
440 440
 
441 441
 					$i = 0;
@@ -451,30 +451,30 @@  discard block
 block discarded – undo
451 451
 								continue;
452 452
 							}
453 453
 							//var_dump($InfoFieldList[1]);
454
-							$labeltoshow=dol_trunc($obj->label,18);
454
+							$labeltoshow = dol_trunc($obj->label, 18);
455 455
 							if ($InfoFieldList[1] == 'c_stcomm')
456 456
 							{
457 457
 								$langs->load("companies");
458
-								$labeltoshow=(($langs->trans("StatusProspect".$obj->id) != "StatusProspect".$obj->id)?$langs->trans("StatusProspect".$obj->id):$obj->label);
458
+								$labeltoshow = (($langs->trans("StatusProspect".$obj->id) != "StatusProspect".$obj->id) ? $langs->trans("StatusProspect".$obj->id) : $obj->label);
459 459
 							}
460 460
 							if ($InfoFieldList[1] == 'c_country')
461 461
 							{
462 462
 								//var_dump($sql);
463 463
 								$langs->load("dict");
464
-								$labeltoshow=(($langs->trans("Country".$obj->code) != "Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->label);
464
+								$labeltoshow = (($langs->trans("Country".$obj->code) != "Country".$obj->code) ? $langs->trans("Country".$obj->code) : $obj->label);
465 465
 							}
466 466
 							if (!empty($ValueField) && $ValueField == $obj->rowid)
467 467
 							{
468
-								$szFilterField.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
468
+								$szFilterField .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
469 469
 							}
470 470
 							else
471 471
 							{
472
-								$szFilterField.='<option value="'.$obj->rowid.'" >'.$labeltoshow.'</option>';
472
+								$szFilterField .= '<option value="'.$obj->rowid.'" >'.$labeltoshow.'</option>';
473 473
 							}
474 474
 							$i++;
475 475
 						}
476 476
 					}
477
-					$szFilterField.="</select>";
477
+					$szFilterField .= "</select>";
478 478
 
479 479
 					$this->db->free($resql);
480 480
 				}
@@ -495,12 +495,12 @@  discard block
 block discarded – undo
495 495
 	{
496 496
         global $langs;
497 497
 
498
-		$szMsg='';
498
+		$szMsg = '';
499 499
 		$InfoFieldList = explode(":", $TypeField);
500 500
 		// build the input field on depend of the type of file
501 501
 		switch ($InfoFieldList[0]) {
502 502
 			case 'Text':
503
-				$szMsg= $langs->trans('ExportStringFilter');
503
+				$szMsg = $langs->trans('ExportStringFilter');
504 504
 				break;
505 505
 			case 'Date':
506 506
 				$szMsg = $langs->trans('ExportDateFilter');
@@ -535,37 +535,37 @@  discard block
 block discarded – undo
535 535
 	function build_file($user, $model, $datatoexport, $array_selected, $array_filterValue, $sqlquery = '')
536 536
  	{
537 537
         // phpcs:enable
538
-		global $conf,$langs;
538
+		global $conf, $langs;
539 539
 
540
-		$indice=0;
540
+		$indice = 0;
541 541
 		asort($array_selected);
542 542
 
543 543
 		dol_syslog(get_class($this)."::".__FUNCTION__." ".$model.", ".$datatoexport.", ".implode(",", $array_selected));
544 544
 
545 545
 		// Check parameters or context properties
546
-		if (empty($this->array_export_fields) || ! is_array($this->array_export_fields))
546
+		if (empty($this->array_export_fields) || !is_array($this->array_export_fields))
547 547
 		{
548
-			$this->error="ErrorBadParameter";
548
+			$this->error = "ErrorBadParameter";
549 549
 			return -1;
550 550
 		}
551 551
 
552 552
 		// Creation of class to export using model ExportXXX
553
-		$dir = DOL_DOCUMENT_ROOT . "/core/modules/export/";
553
+		$dir = DOL_DOCUMENT_ROOT."/core/modules/export/";
554 554
 		$file = "export_".$model.".modules.php";
555 555
 		$classname = "Export".$model;
556 556
 		require_once $dir.$file;
557 557
 		$objmodel = new $classname($this->db);
558 558
 
559
-		if (! empty($sqlquery)) $sql = $sqlquery;
559
+		if (!empty($sqlquery)) $sql = $sqlquery;
560 560
         else
561 561
 		{
562 562
 			// Define value for indice from $datatoexport
563
-			$foundindice=0;
564
-			foreach($this->array_export_code as $key => $dataset)
563
+			$foundindice = 0;
564
+			foreach ($this->array_export_code as $key => $dataset)
565 565
 			{
566 566
 				if ($datatoexport == $dataset)
567 567
 				{
568
-					$indice=$key;
568
+					$indice = $key;
569 569
 					$foundindice++;
570 570
 					//print "Found indice = ".$indice." for dataset=".$datatoexport."\n";
571 571
 					break;
@@ -573,31 +573,31 @@  discard block
 block discarded – undo
573 573
 			}
574 574
 			if (empty($foundindice))
575 575
 			{
576
-				$this->error="ErrorBadParameter can't find dataset ".$datatoexport." into preload arrays this->array_export_code";
576
+				$this->error = "ErrorBadParameter can't find dataset ".$datatoexport." into preload arrays this->array_export_code";
577 577
 				return -1;
578 578
 			}
579
-        	$sql=$this->build_sql($indice, $array_selected, $array_filterValue);
579
+        	$sql = $this->build_sql($indice, $array_selected, $array_filterValue);
580 580
 		}
581 581
 
582 582
 		// Run the sql
583
-		$this->sqlusedforexport=$sql;
583
+		$this->sqlusedforexport = $sql;
584 584
 		dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG);
585 585
 		$resql = $this->db->query($sql);
586 586
 		if ($resql)
587 587
 		{
588 588
 			//$this->array_export_label[$indice]
589 589
 			if ($conf->global->EXPORT_PREFIX_SPEC)
590
-				$filename=$conf->global->EXPORT_PREFIX_SPEC."_".$datatoexport;
590
+				$filename = $conf->global->EXPORT_PREFIX_SPEC."_".$datatoexport;
591 591
 			else
592
-				$filename="export_".$datatoexport;
593
-			$filename.='.'.$objmodel->getDriverExtension();
594
-			$dirname=$conf->export->dir_temp.'/'.$user->id;
592
+				$filename = "export_".$datatoexport;
593
+			$filename .= '.'.$objmodel->getDriverExtension();
594
+			$dirname = $conf->export->dir_temp.'/'.$user->id;
595 595
 
596 596
 			$outputlangs = clone $langs; // We clone to have an object we can modify (for example to change output charset by csv handler) without changing original value
597 597
 
598 598
 			// Open file
599 599
 			dol_mkdir($dirname);
600
-			$result=$objmodel->open_file($dirname."/".$filename, $outputlangs);
600
+			$result = $objmodel->open_file($dirname."/".$filename, $outputlangs);
601 601
 
602 602
 			if ($result >= 0)
603 603
 			{
@@ -605,64 +605,64 @@  discard block
 block discarded – undo
605 605
 				$objmodel->write_header($outputlangs);
606 606
 
607 607
 				// Genere ligne de titre
608
-				$objmodel->write_title($this->array_export_fields[$indice],$array_selected,$outputlangs,$this->array_export_TypeFields[$indice]);
608
+				$objmodel->write_title($this->array_export_fields[$indice], $array_selected, $outputlangs, $this->array_export_TypeFields[$indice]);
609 609
 
610 610
 				while ($obj = $this->db->fetch_object($resql))
611 611
 				{
612 612
 					// Process special operations
613
-					if (! empty($this->array_export_special[$indice]))
613
+					if (!empty($this->array_export_special[$indice]))
614 614
 					{
615 615
 						foreach ($this->array_export_special[$indice] as $key => $value)
616 616
 						{
617
-							if (! array_key_exists($key, $array_selected)) continue;		// Field not selected
617
+							if (!array_key_exists($key, $array_selected)) continue; // Field not selected
618 618
 							// Operation NULLIFNEG
619
-							if ($this->array_export_special[$indice][$key]=='NULLIFNEG')
619
+							if ($this->array_export_special[$indice][$key] == 'NULLIFNEG')
620 620
 							{
621 621
 								//$alias=$this->array_export_alias[$indice][$key];
622
-								$alias=str_replace(array('.', '-','(',')'),'_',$key);
623
-								if ($obj->$alias < 0) $obj->$alias='';
622
+								$alias = str_replace(array('.', '-', '(', ')'), '_', $key);
623
+								if ($obj->$alias < 0) $obj->$alias = '';
624 624
 							}
625 625
 							// Operation ZEROIFNEG
626
-							elseif ($this->array_export_special[$indice][$key]=='ZEROIFNEG')
626
+							elseif ($this->array_export_special[$indice][$key] == 'ZEROIFNEG')
627 627
 							{
628 628
 								//$alias=$this->array_export_alias[$indice][$key];
629
-								$alias=str_replace(array('.', '-','(',')'),'_',$key);
630
-								if ($obj->$alias < 0) $obj->$alias='0';
629
+								$alias = str_replace(array('.', '-', '(', ')'), '_', $key);
630
+								if ($obj->$alias < 0) $obj->$alias = '0';
631 631
 							}
632 632
 							// Operation INVOICEREMAINTOPAY
633
-							elseif ($this->array_export_special[$indice][$key]=='getRemainToPay')
633
+							elseif ($this->array_export_special[$indice][$key] == 'getRemainToPay')
634 634
 							{
635 635
 								//$alias=$this->array_export_alias[$indice][$key];
636
-								$alias=str_replace(array('.', '-','(',')'),'_',$key);
637
-								$remaintopay='';
636
+								$alias = str_replace(array('.', '-', '(', ')'), '_', $key);
637
+								$remaintopay = '';
638 638
 								if ($obj->f_rowid > 0)
639 639
 								{
640 640
 								    global $tmpobjforcomputecall;
641
-								    if (! is_object($tmpobjforcomputecall))
641
+								    if (!is_object($tmpobjforcomputecall))
642 642
 								    {
643 643
 								        include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
644
-								        $tmpobjforcomputecall=new Facture($this->db);
644
+								        $tmpobjforcomputecall = new Facture($this->db);
645 645
 								    }
646 646
 								    $tmpobjforcomputecall->id = $obj->f_rowid;
647 647
 								    $tmpobjforcomputecall->total_ttc = $obj->f_total_ttc;
648
-								    $remaintopay=$tmpobjforcomputecall->getRemainToPay();
648
+								    $remaintopay = $tmpobjforcomputecall->getRemainToPay();
649 649
 								}
650
-								$obj->$alias=$remaintopay;
650
+								$obj->$alias = $remaintopay;
651 651
 							}
652 652
 							else
653 653
 							{
654 654
 							    // TODO FIXME Export of compute field does not work. $obj containt $obj->alias_field and formulat will contains $obj->field
655
-							    $computestring=$this->array_export_special[$indice][$key];
656
-							    $tmp=dol_eval($computestring, 1, 0);
657
-							    $obj->$alias=$tmp;
655
+							    $computestring = $this->array_export_special[$indice][$key];
656
+							    $tmp = dol_eval($computestring, 1, 0);
657
+							    $obj->$alias = $tmp;
658 658
 
659
-							    $this->error="ERROPNOTSUPPORTED. Operation ".$this->array_export_special[$indice][$key]." not supported. Export of 'computed' extrafields is not yet supported, please remove field.";
659
+							    $this->error = "ERROPNOTSUPPORTED. Operation ".$this->array_export_special[$indice][$key]." not supported. Export of 'computed' extrafields is not yet supported, please remove field.";
660 660
 							    return -1;
661 661
 							}
662 662
 						}
663 663
 					}
664 664
 					// end of special operation processing
665
-					$objmodel->write_record($array_selected,$obj,$outputlangs,$this->array_export_TypeFields[$indice]);
665
+					$objmodel->write_record($array_selected, $obj, $outputlangs, $this->array_export_TypeFields[$indice]);
666 666
 				}
667 667
 
668 668
 				// Genere en-tete
@@ -675,14 +675,14 @@  discard block
 block discarded – undo
675 675
 			}
676 676
 			else
677 677
 			{
678
-				$this->error=$objmodel->error;
678
+				$this->error = $objmodel->error;
679 679
 				dol_syslog("Export::build_file Error: ".$this->error, LOG_ERR);
680 680
 				return -1;
681 681
 			}
682 682
 		}
683 683
 		else
684 684
 		{
685
-			$this->error=$this->db->error()." - sql=".$sql;
685
+			$this->error = $this->db->error()." - sql=".$sql;
686 686
 			return -1;
687 687
 		}
688 688
 	}
@@ -701,24 +701,24 @@  discard block
 block discarded – undo
701 701
 
702 702
 		$this->db->begin();
703 703
 
704
-		$filter='';
704
+		$filter = '';
705 705
 
706 706
 		$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'export_model (';
707
-		$sql.= 'label,';
708
-		$sql.= 'type,';
709
-		$sql.= 'field,';
710
-		$sql.= 'fk_user,';
711
-		$sql.= 'filter';
712
-		$sql.= ') VALUES (';
713
-		$sql.= "'".$this->db->escape($this->model_name)."',";
714
-		$sql.= "'".$this->db->escape($this->datatoexport)."',";
715
-		$sql.= "'".$this->db->escape($this->hexa)."',";
716
-		$sql.= "'".$user->id."',";
717
-		$sql.= "'".$this->db->escape($this->hexafiltervalue)."'";
718
-		$sql.= ")";
707
+		$sql .= 'label,';
708
+		$sql .= 'type,';
709
+		$sql .= 'field,';
710
+		$sql .= 'fk_user,';
711
+		$sql .= 'filter';
712
+		$sql .= ') VALUES (';
713
+		$sql .= "'".$this->db->escape($this->model_name)."',";
714
+		$sql .= "'".$this->db->escape($this->datatoexport)."',";
715
+		$sql .= "'".$this->db->escape($this->hexa)."',";
716
+		$sql .= "'".$user->id."',";
717
+		$sql .= "'".$this->db->escape($this->hexafiltervalue)."'";
718
+		$sql .= ")";
719 719
 
720 720
 		dol_syslog(get_class($this)."::create", LOG_DEBUG);
721
-		$resql=$this->db->query($sql);
721
+		$resql = $this->db->query($sql);
722 722
 		if ($resql)
723 723
 		{
724 724
 			$this->db->commit();
@@ -726,8 +726,8 @@  discard block
 block discarded – undo
726 726
 		}
727 727
 		else
728 728
 		{
729
-			$this->error=$this->db->lasterror();
730
-			$this->errno=$this->db->lasterrno();
729
+			$this->error = $this->db->lasterror();
730
+			$this->errno = $this->db->lasterrno();
731 731
 			$this->db->rollback();
732 732
 			return -1;
733 733
 		}
@@ -742,8 +742,8 @@  discard block
 block discarded – undo
742 742
 	function fetch($id)
743 743
 	{
744 744
 		$sql = 'SELECT em.rowid, em.label, em.type, em.field, em.filter';
745
-		$sql.= ' FROM '.MAIN_DB_PREFIX.'export_model as em';
746
-		$sql.= ' WHERE em.rowid = '.$id;
745
+		$sql .= ' FROM '.MAIN_DB_PREFIX.'export_model as em';
746
+		$sql .= ' WHERE em.rowid = '.$id;
747 747
 
748 748
 		dol_syslog("Export::fetch", LOG_DEBUG);
749 749
 		$result = $this->db->query($sql);
@@ -752,18 +752,18 @@  discard block
 block discarded – undo
752 752
 			$obj = $this->db->fetch_object($result);
753 753
 			if ($obj)
754 754
 			{
755
-				$this->id				= $obj->rowid;
756
-				$this->model_name		= $obj->label;
757
-				$this->datatoexport		= $obj->type;
755
+				$this->id = $obj->rowid;
756
+				$this->model_name = $obj->label;
757
+				$this->datatoexport = $obj->type;
758 758
 
759
-				$this->hexa				= $obj->field;
760
-				$this->hexafiltervalue	= $obj->filter;
759
+				$this->hexa = $obj->field;
760
+				$this->hexafiltervalue = $obj->filter;
761 761
 
762 762
 				return 1;
763 763
 			}
764 764
 			else
765 765
 			{
766
-				$this->error="ModelNotFound";
766
+				$this->error = "ModelNotFound";
767 767
 				return -2;
768 768
 			}
769 769
 		}
@@ -782,23 +782,23 @@  discard block
 block discarded – undo
782 782
 	 *  @param      int			$notrigger	    0=launch triggers after, 1=disable triggers
783 783
 	 *	@return		int							<0 if KO, >0 if OK
784 784
 	 */
785
-	function delete($user, $notrigger=0)
785
+	function delete($user, $notrigger = 0)
786 786
 	{
787 787
 		global $conf, $langs;
788
-		$error=0;
788
+		$error = 0;
789 789
 
790 790
 		$sql = "DELETE FROM ".MAIN_DB_PREFIX."export_model";
791
-		$sql.= " WHERE rowid=".$this->id;
791
+		$sql .= " WHERE rowid=".$this->id;
792 792
 
793 793
 		$this->db->begin();
794 794
 
795 795
 		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
796 796
 		$resql = $this->db->query($sql);
797
-		if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
797
+		if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
798 798
 
799
-		if (! $error)
799
+		if (!$error)
800 800
 		{
801
-			if (! $notrigger)
801
+			if (!$notrigger)
802 802
 			{
803 803
 				// Uncomment this and change MYOBJECT to your own tag if you
804 804
 				// want this action call a trigger.
@@ -815,13 +815,13 @@  discard block
 block discarded – undo
815 815
 		// Commit or rollback
816 816
 		if ($error)
817 817
 		{
818
-			foreach($this->errors as $errmsg)
818
+			foreach ($this->errors as $errmsg)
819 819
 			{
820 820
 				dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
821
-				$this->error.=($this->error?', '.$errmsg:$errmsg);
821
+				$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
822 822
 			}
823 823
 			$this->db->rollback();
824
-			return -1*$error;
824
+			return -1 * $error;
825 825
 		}
826 826
 		else
827 827
 		{
@@ -843,8 +843,8 @@  discard block
 block discarded – undo
843 843
 		global $conf, $langs;
844 844
 
845 845
 		$sql = "SELECT em.rowid, em.field, em.label, em.type, em.filter";
846
-		$sql.= " FROM ".MAIN_DB_PREFIX."export_model as em";
847
-		$sql.= " ORDER BY rowid";
846
+		$sql .= " FROM ".MAIN_DB_PREFIX."export_model as em";
847
+		$sql .= " ORDER BY rowid";
848 848
 
849 849
 		$result = $this->db->query($sql);
850 850
 		if ($result)
@@ -858,19 +858,19 @@  discard block
 block discarded – undo
858 858
 				print "<tr>";
859 859
 				print '<td><a href=export.php?step=2&action=select_model&exportmodelid='.$obj->rowid.'&datatoexport='.$obj->type.'>'.$obj->label.'</a></td>';
860 860
 				print '<td>';
861
-				print img_object($this->array_export_module[$keyModel]->getName(),$this->array_export_icon[$keyModel]).' ';
861
+				print img_object($this->array_export_module[$keyModel]->getName(), $this->array_export_icon[$keyModel]).' ';
862 862
 				print $this->array_export_module[$keyModel]->getName().' - ';
863 863
 				// recuperation du nom de l'export
864 864
 
865
-				$string=$langs->trans($this->array_export_label[$keyModel]);
866
-				print ($string!=$this->array_export_label[$keyModel]?$string:$this->array_export_label[$keyModel]);
865
+				$string = $langs->trans($this->array_export_label[$keyModel]);
866
+				print ($string != $this->array_export_label[$keyModel] ? $string : $this->array_export_label[$keyModel]);
867 867
 				print '</td>';
868 868
 				//print '<td>'.$obj->type.$keyModel.'</td>';
869
-				print '<td>'.str_replace(',',' , ',$obj->field).'</td>';
870
-				if (! empty($obj->filter)) {
869
+				print '<td>'.str_replace(',', ' , ', $obj->field).'</td>';
870
+				if (!empty($obj->filter)) {
871 871
 					$filter = json_decode($obj->filter, true);
872
-					print '<td>'.str_replace(',',' , ',$filter['field']).'</td>';
873
-					print '<td>'.str_replace(',',' , ',$filter['value']).'</td>';
872
+					print '<td>'.str_replace(',', ' , ', $filter['field']).'</td>';
873
+					print '<td>'.str_replace(',', ' , ', $filter['value']).'</td>';
874 874
 				}
875 875
 				// suppression de l'export
876 876
 				print '<td align="right">';
Please login to merge, or discard this patch.
Braces   +127 added lines, -80 removed lines patch added patch discarded remove patch
@@ -108,8 +108,12 @@  discard block
 block discarded – undo
108 108
 						// Defined if module is enabled
109 109
 						$enabled=true;
110 110
 						$part=strtolower(preg_replace('/^mod/i','',$modulename));
111
-						if ($part == 'propale') $part='propal';
112
-						if (empty($conf->$part->enabled)) $enabled=false;
111
+						if ($part == 'propale') {
112
+						    $part='propal';
113
+						}
114
+						if (empty($conf->$part->enabled)) {
115
+						    $enabled=false;
116
+						}
113 117
 
114 118
 						if ($enabled)
115 119
 						{
@@ -124,10 +128,14 @@  discard block
 block discarded – undo
124 128
 							    foreach($module->export_code as $r => $value)
125 129
 								{
126 130
                                     //print $i.'-'.$filter.'-'.$modulename.'-'.join(',',$module->export_code).'<br>';
127
-								    if ($filter && ($filter != $module->export_code[$r])) continue;
131
+								    if ($filter && ($filter != $module->export_code[$r])) {
132
+								        continue;
133
+								    }
128 134
 
129 135
                                     // Test if condition to show are ok
130
-                                    if (! empty($module->export_enabled[$r]) && ! verifCond($module->export_enabled[$r])) continue;
136
+                                    if (! empty($module->export_enabled[$r]) && ! verifCond($module->export_enabled[$r])) {
137
+                                        continue;
138
+                                    }
131 139
 
132 140
                                     // Test if permissions are ok
133 141
 									$bool=true;
@@ -140,13 +148,16 @@  discard block
 block discarded – undo
140 148
 	    									if (! empty($perm[2]))
141 149
 	    									{
142 150
 	    										$bool=$user->rights->{$perm[0]}->{$perm[1]}->{$perm[2]};
143
-	    									}
144
-	    									else
151
+	    									} else
145 152
 	    									{
146 153
 	    										$bool=$user->rights->{$perm[0]}->{$perm[1]};
147 154
 	    									}
148
-	    									if ($perm[0]=='user' && $user->admin) $bool=true;
149
-	    									if (! $bool) break;
155
+	    									if ($perm[0]=='user' && $user->admin) {
156
+	    									    $bool=true;
157
+	    									}
158
+	    									if (! $bool) {
159
+	    									    break;
160
+	    									}
150 161
 										}
151 162
 									}
152 163
 									//print $bool." $perm[0]"."<br>";
@@ -229,10 +240,19 @@  discard block
 block discarded – undo
229 240
 		//print_r($array_selected);
230 241
 		foreach ($this->array_export_fields[$indice] as $key => $value)
231 242
 		{
232
-			if (! array_key_exists($key, $array_selected)) continue;		// Field not selected
233
-            if (preg_match('/^none\./', $key)) continue;                    // A field that must not appears into SQL
234
-			if ($i > 0) $sql.=', ';
235
-			else $i++;
243
+			if (! array_key_exists($key, $array_selected)) {
244
+			    continue;
245
+			}
246
+			// Field not selected
247
+            if (preg_match('/^none\./', $key)) {
248
+                continue;
249
+            }
250
+            // A field that must not appears into SQL
251
+			if ($i > 0) {
252
+			    $sql.=', ';
253
+			} else {
254
+			    $i++;
255
+			}
236 256
 
237 257
 			if (strpos($key, ' as ')===false) {
238 258
 				$newfield=$key.' as '.str_replace(array('.', '-','(',')'),'_',$key);
@@ -251,8 +271,12 @@  discard block
 block discarded – undo
251 271
 			// Loop on each condition to add
252 272
 			foreach ($array_filterValue as $key => $value)
253 273
 			{
254
-			    if (preg_match('/GROUP_CONCAT/i', $key)) continue;
255
-				if ($value != '') $sqlWhere.=" and ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
274
+			    if (preg_match('/GROUP_CONCAT/i', $key)) {
275
+			        continue;
276
+			    }
277
+				if ($value != '') {
278
+				    $sqlWhere.=" and ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
279
+				}
256 280
 			}
257 281
 			$sql.=$sqlWhere;
258 282
 		}
@@ -266,7 +290,9 @@  discard block
 block discarded – undo
266 290
 		    // Loop on each condition to add
267 291
 		    foreach ($array_filterValue as $key => $value)
268 292
 		    {
269
-		        if (preg_match('/GROUP_CONCAT/i', $key) and $value != '') $sql.=" HAVING ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
293
+		        if (preg_match('/GROUP_CONCAT/i', $key) and $value != '') {
294
+		            $sql.=" HAVING ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]);
295
+		        }
270 296
 		    }
271 297
 		}
272 298
 
@@ -290,10 +316,11 @@  discard block
 block discarded – undo
290 316
 		// build the input field on depend of the type of file
291 317
 		switch ($InfoFieldList[0]) {
292 318
 			case 'Text':
293
-				if (! (strpos($ValueField, '%') === false))
294
-					$szFilterQuery.=" ".$NameField." LIKE '".$ValueField."'";
295
-				else
296
-					$szFilterQuery.=" ".$NameField." = '".$ValueField."'";
319
+				if (! (strpos($ValueField, '%') === false)) {
320
+									$szFilterQuery.=" ".$NameField." LIKE '".$ValueField."'";
321
+				} else {
322
+									$szFilterQuery.=" ".$NameField." = '".$ValueField."'";
323
+				}
297 324
 				break;
298 325
 			case 'Date':
299 326
 				if (strpos($ValueField, "+") > 0)
@@ -302,13 +329,13 @@  discard block
 block discarded – undo
302 329
 					$ValueArray = explode("+", $ValueField);
303 330
 					$szFilterQuery ="(".$this->conditionDate($NameField,trim($ValueArray[0]),">=");
304 331
 					$szFilterQuery.=" AND ".$this->conditionDate($NameField,trim($ValueArray[1]),"<=").")";
305
-				}
306
-				else
332
+				} else
307 333
 				{
308
-					if (is_numeric(substr($ValueField,0,1)))
309
-						$szFilterQuery=$this->conditionDate($NameField,trim($ValueField),"=");
310
-					else
311
-						$szFilterQuery=$this->conditionDate($NameField,trim(substr($ValueField,1)),substr($ValueField,0,1));
334
+					if (is_numeric(substr($ValueField,0,1))) {
335
+											$szFilterQuery=$this->conditionDate($NameField,trim($ValueField),"=");
336
+					} else {
337
+											$szFilterQuery=$this->conditionDate($NameField,trim(substr($ValueField,1)),substr($ValueField,0,1));
338
+					}
312 339
 				}
313 340
 				break;
314 341
 			case 'Duree':
@@ -321,13 +348,13 @@  discard block
 block discarded – undo
321 348
 					$ValueArray = explode("+", $ValueField);
322 349
 					$szFilterQuery ="(".$NameField.">=".$ValueArray[0];
323 350
 					$szFilterQuery.=" AND ".$NameField."<=".$ValueArray[1].")";
324
-				}
325
-				else
351
+				} else
326 352
 				{
327
-					if (is_numeric(substr($ValueField,0,1)))
328
-						$szFilterQuery=" ".$NameField."=".$ValueField;
329
-					else
330
-						$szFilterQuery=" ".$NameField.substr($ValueField,0,1).substr($ValueField,1);
353
+					if (is_numeric(substr($ValueField,0,1))) {
354
+											$szFilterQuery=" ".$NameField."=".$ValueField;
355
+					} else {
356
+											$szFilterQuery=" ".$NameField.substr($ValueField,0,1).substr($ValueField,1);
357
+					}
331 358
 				}
332 359
 				break;
333 360
 			case 'Boolean':
@@ -335,13 +362,14 @@  discard block
 block discarded – undo
335 362
 				break;
336 363
 			case 'Status':
337 364
 			case 'List':
338
-				if (is_numeric($ValueField))
339
-					$szFilterQuery=" ".$NameField."=".$ValueField;
340
-				else {
341
-                    if (! (strpos($ValueField, '%') === false))
342
-                        $szFilterQuery=" ".$NameField." LIKE '".$ValueField."'";
343
-                    else
344
-                        $szFilterQuery=" ".$NameField." = '".$ValueField."'";
365
+				if (is_numeric($ValueField)) {
366
+									$szFilterQuery=" ".$NameField."=".$ValueField;
367
+				} else {
368
+                    if (! (strpos($ValueField, '%') === false)) {
369
+                                            $szFilterQuery=" ".$NameField." LIKE '".$ValueField."'";
370
+                    } else {
371
+                                            $szFilterQuery=" ".$NameField." = '".$ValueField."'";
372
+                    }
345 373
 				}
346 374
 				break;
347 375
 			default:
@@ -362,9 +390,13 @@  discard block
 block discarded – undo
362 390
 	function conditionDate($Field, $Value, $Sens)
363 391
 	{
364 392
 		// TODO date_format is forbidden, not performant and not portable. Use instead BETWEEN
365
-		if (strlen($Value)==4) $Condition=" date_format(".$Field.",'%Y') ".$Sens." '".$Value."'";
366
-		elseif (strlen($Value)==6) $Condition=" date_format(".$Field.",'%Y%m') ".$Sens." '".$Value."'";
367
-		else  $Condition=" date_format(".$Field.",'%Y%m%d') ".$Sens." ".$Value;
393
+		if (strlen($Value)==4) {
394
+		    $Condition=" date_format(".$Field.",'%Y') ".$Sens." '".$Value."'";
395
+		} elseif (strlen($Value)==6) {
396
+		    $Condition=" date_format(".$Field.",'%Y%m') ".$Sens." '".$Value."'";
397
+		} else {
398
+		    $Condition=" date_format(".$Field.",'%Y%m%d') ".$Sens." ".$Value;
399
+		}
368 400
 		return $Condition;
369 401
 	}
370 402
 
@@ -399,21 +431,30 @@  discard block
 block discarded – undo
399 431
 			    $szFilterField='<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
400 432
 				break;
401 433
 			case 'Status':
402
-				if (! empty($conf->global->MAIN_ACTIVATE_HTML5)) $szFilterField='<input type="number" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
403
-				else $szFilterField='<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
434
+				if (! empty($conf->global->MAIN_ACTIVATE_HTML5)) {
435
+				    $szFilterField='<input type="number" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
436
+				} else {
437
+				    $szFilterField='<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">';
438
+				}
404 439
 				break;
405 440
 			case 'Boolean':
406 441
 				$szFilterField='<select name="'.$NameField.'" class="flat">';
407 442
 				$szFilterField.='<option ';
408
-				if ($ValueField=='') $szFilterField.=' selected ';
443
+				if ($ValueField=='') {
444
+				    $szFilterField.=' selected ';
445
+				}
409 446
 				$szFilterField.=' value="">&nbsp;</option>';
410 447
 
411 448
 				$szFilterField.='<option ';
412
-				if ($ValueField=='yes' || $ValueField == '1') $szFilterField.=' selected ';
449
+				if ($ValueField=='yes' || $ValueField == '1') {
450
+				    $szFilterField.=' selected ';
451
+				}
413 452
 				$szFilterField.=' value="1">'.yn(1).'</option>';
414 453
 
415 454
 				$szFilterField.='<option ';
416
-				if ($ValueField=='no' || $ValueField=='0') $szFilterField.=' selected ';
455
+				if ($ValueField=='no' || $ValueField=='0') {
456
+				    $szFilterField.=' selected ';
457
+				}
417 458
 				$szFilterField.=' value="0">'.yn(0).'</option>';
418 459
 				$szFilterField.="</select>";
419 460
 				break;
@@ -422,13 +463,18 @@  discard block
 block discarded – undo
422 463
 				// 1 : Nom de la table
423 464
 				// 2 : Nom du champ contenant le libelle
424 465
 				// 3 : Name of field with key (if it is not "rowid"). Used this field as key for combo list.
425
-				if (count($InfoFieldList)==4)
426
-					$keyList=$InfoFieldList[3];
427
-				else
428
-					$keyList='rowid';
466
+				if (count($InfoFieldList)==4) {
467
+									$keyList=$InfoFieldList[3];
468
+				} else {
469
+									$keyList='rowid';
470
+				}
429 471
 				$sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3])?'':', '.$InfoFieldList[3].' as code');
430
-				if ($InfoFieldList[1] == 'c_stcomm') $sql = 'SELECT id as id, '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3])?'':', '.$InfoFieldList[3].' as code');
431
-				if ($InfoFieldList[1] == 'c_country') $sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label, code as code';
472
+				if ($InfoFieldList[1] == 'c_stcomm') {
473
+				    $sql = 'SELECT id as id, '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3])?'':', '.$InfoFieldList[3].' as code');
474
+				}
475
+				if ($InfoFieldList[1] == 'c_country') {
476
+				    $sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label, code as code';
477
+				}
432 478
 				$sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[1];
433 479
 
434 480
 				$resql = $this->db->query($sql);
@@ -466,8 +512,7 @@  discard block
 block discarded – undo
466 512
 							if (!empty($ValueField) && $ValueField == $obj->rowid)
467 513
 							{
468 514
 								$szFilterField.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
469
-							}
470
-							else
515
+							} else
471 516
 							{
472 517
 								$szFilterField.='<option value="'.$obj->rowid.'" >'.$labeltoshow.'</option>';
473 518
 							}
@@ -477,8 +522,9 @@  discard block
 block discarded – undo
477 522
 					$szFilterField.="</select>";
478 523
 
479 524
 					$this->db->free($resql);
525
+				} else {
526
+				    dol_print_error($this->db);
480 527
 				}
481
-				else dol_print_error($this->db);
482 528
 				break;
483 529
 		}
484 530
 
@@ -556,8 +602,9 @@  discard block
 block discarded – undo
556 602
 		require_once $dir.$file;
557 603
 		$objmodel = new $classname($this->db);
558 604
 
559
-		if (! empty($sqlquery)) $sql = $sqlquery;
560
-        else
605
+		if (! empty($sqlquery)) {
606
+		    $sql = $sqlquery;
607
+		} else
561 608
 		{
562 609
 			// Define value for indice from $datatoexport
563 610
 			$foundindice=0;
@@ -586,10 +633,11 @@  discard block
 block discarded – undo
586 633
 		if ($resql)
587 634
 		{
588 635
 			//$this->array_export_label[$indice]
589
-			if ($conf->global->EXPORT_PREFIX_SPEC)
590
-				$filename=$conf->global->EXPORT_PREFIX_SPEC."_".$datatoexport;
591
-			else
592
-				$filename="export_".$datatoexport;
636
+			if ($conf->global->EXPORT_PREFIX_SPEC) {
637
+							$filename=$conf->global->EXPORT_PREFIX_SPEC."_".$datatoexport;
638
+			} else {
639
+							$filename="export_".$datatoexport;
640
+			}
593 641
 			$filename.='.'.$objmodel->getDriverExtension();
594 642
 			$dirname=$conf->export->dir_temp.'/'.$user->id;
595 643
 
@@ -614,20 +662,27 @@  discard block
 block discarded – undo
614 662
 					{
615 663
 						foreach ($this->array_export_special[$indice] as $key => $value)
616 664
 						{
617
-							if (! array_key_exists($key, $array_selected)) continue;		// Field not selected
665
+							if (! array_key_exists($key, $array_selected)) {
666
+							    continue;
667
+							}
668
+							// Field not selected
618 669
 							// Operation NULLIFNEG
619 670
 							if ($this->array_export_special[$indice][$key]=='NULLIFNEG')
620 671
 							{
621 672
 								//$alias=$this->array_export_alias[$indice][$key];
622 673
 								$alias=str_replace(array('.', '-','(',')'),'_',$key);
623
-								if ($obj->$alias < 0) $obj->$alias='';
674
+								if ($obj->$alias < 0) {
675
+								    $obj->$alias='';
676
+								}
624 677
 							}
625 678
 							// Operation ZEROIFNEG
626 679
 							elseif ($this->array_export_special[$indice][$key]=='ZEROIFNEG')
627 680
 							{
628 681
 								//$alias=$this->array_export_alias[$indice][$key];
629 682
 								$alias=str_replace(array('.', '-','(',')'),'_',$key);
630
-								if ($obj->$alias < 0) $obj->$alias='0';
683
+								if ($obj->$alias < 0) {
684
+								    $obj->$alias='0';
685
+								}
631 686
 							}
632 687
 							// Operation INVOICEREMAINTOPAY
633 688
 							elseif ($this->array_export_special[$indice][$key]=='getRemainToPay')
@@ -648,8 +703,7 @@  discard block
 block discarded – undo
648 703
 								    $remaintopay=$tmpobjforcomputecall->getRemainToPay();
649 704
 								}
650 705
 								$obj->$alias=$remaintopay;
651
-							}
652
-							else
706
+							} else
653 707
 							{
654 708
 							    // TODO FIXME Export of compute field does not work. $obj containt $obj->alias_field and formulat will contains $obj->field
655 709
 							    $computestring=$this->array_export_special[$indice][$key];
@@ -672,15 +726,13 @@  discard block
 block discarded – undo
672 726
 				$objmodel->close_file();
673 727
 
674 728
         		return 1;
675
-			}
676
-			else
729
+			} else
677 730
 			{
678 731
 				$this->error=$objmodel->error;
679 732
 				dol_syslog("Export::build_file Error: ".$this->error, LOG_ERR);
680 733
 				return -1;
681 734
 			}
682
-		}
683
-		else
735
+		} else
684 736
 		{
685 737
 			$this->error=$this->db->error()." - sql=".$sql;
686 738
 			return -1;
@@ -723,8 +775,7 @@  discard block
 block discarded – undo
723 775
 		{
724 776
 			$this->db->commit();
725 777
 			return 1;
726
-		}
727
-		else
778
+		} else
728 779
 		{
729 780
 			$this->error=$this->db->lasterror();
730 781
 			$this->errno=$this->db->lasterrno();
@@ -760,14 +811,12 @@  discard block
 block discarded – undo
760 811
 				$this->hexafiltervalue	= $obj->filter;
761 812
 
762 813
 				return 1;
763
-			}
764
-			else
814
+			} else
765 815
 			{
766 816
 				$this->error="ModelNotFound";
767 817
 				return -2;
768 818
 			}
769
-		}
770
-		else
819
+		} else
771 820
 		{
772 821
 			dol_print_error($this->db);
773 822
 			return -3;
@@ -822,8 +871,7 @@  discard block
 block discarded – undo
822 871
 			}
823 872
 			$this->db->rollback();
824 873
 			return -1*$error;
825
-		}
826
-		else
874
+		} else
827 875
 		{
828 876
 			$this->db->commit();
829 877
 			return 1;
@@ -881,8 +929,7 @@  discard block
 block discarded – undo
881 929
 
882 930
 				$i++;
883 931
 			}
884
-		}
885
-		else {
932
+		} else {
886 933
 			dol_print_error($this->db);
887 934
 		}
888 935
 	}
Please login to merge, or discard this patch.
dolibarr/htdocs/exports/export.php 3 patches
Indentation   +477 added lines, -477 removed lines patch added patch discarded remove patch
@@ -40,85 +40,85 @@  discard block
 block discarded – undo
40 40
 //  accessforbidden();
41 41
 
42 42
 $entitytoicon = array(
43
-	'invoice'      => 'bill',
43
+    'invoice'      => 'bill',
44 44
     'invoice_line' => 'bill',
45
-	'order'        => 'order',
45
+    'order'        => 'order',
46 46
     'order_line'   => 'order',
47
-	'propal'       => 'propal',
47
+    'propal'       => 'propal',
48 48
     'propal_line'  => 'propal',
49
-	'intervention' => 'intervention',
49
+    'intervention' => 'intervention',
50 50
     'inter_line'   => 'intervention',
51
-	'member'       => 'user',
51
+    'member'       => 'user',
52 52
     'member_type'  => 'group',
53 53
     'subscription' => 'payment',
54 54
     'payment'      => 'payment',
55
-	'tax'          => 'generic',
55
+    'tax'          => 'generic',
56 56
     'tax_type'     => 'generic',
57 57
     'stock'        => 'generic',
58 58
     'other'        => 'generic',
59
-	'account'      => 'account',
60
-	'product'      => 'product',
59
+    'account'      => 'account',
60
+    'product'      => 'product',
61 61
     'virtualproduct'=>'product',
62
-	'subproduct'   => 'product',
63
-	'product_supplier_ref'      => 'product',
64
-	'warehouse'    => 'stock',
65
-	'batch'        => 'stock',
66
-	'stockbatch'   => 'stock',
67
-	'category'     => 'category',
68
-	'shipment'     => 'sending',
62
+    'subproduct'   => 'product',
63
+    'product_supplier_ref'      => 'product',
64
+    'warehouse'    => 'stock',
65
+    'batch'        => 'stock',
66
+    'stockbatch'   => 'stock',
67
+    'category'     => 'category',
68
+    'shipment'     => 'sending',
69 69
     'shipment_line'=> 'sending',
70 70
     'reception'=> 'sending',
71 71
     'reception_line'=> 'sending',
72
-	'expensereport'=> 'trip',
72
+    'expensereport'=> 'trip',
73 73
     'expensereport_line'=> 'trip',
74
-	'holiday'      => 'holiday',
74
+    'holiday'      => 'holiday',
75 75
     'contract_line' => 'contract',
76 76
     'translation'  => 'generic'
77 77
 );
78 78
 
79 79
 // Translation code
80 80
 $entitytolang = array(
81
-	'user'         => 'User',
82
-	'company'      => 'Company',
81
+    'user'         => 'User',
82
+    'company'      => 'Company',
83 83
     'contact'      => 'Contact',
84
-	'invoice'      => 'Bill',
84
+    'invoice'      => 'Bill',
85 85
     'invoice_line' => 'InvoiceLine',
86
-	'order'        => 'Order',
86
+    'order'        => 'Order',
87 87
     'order_line'   => 'OrderLine',
88 88
     'propal'       => 'Proposal',
89 89
     'propal_line'  => 'ProposalLine',
90
-	'intervention' => 'Intervention',
90
+    'intervention' => 'Intervention',
91 91
     'inter_line'   => 'InterLine',
92
-	'member'       => 'Member',
92
+    'member'       => 'Member',
93 93
     'member_type'  => 'MemberType',
94 94
     'subscription' => 'Subscription',
95
-	'tax'          => 'SocialContribution',
95
+    'tax'          => 'SocialContribution',
96 96
     'tax_type'     => 'DictionarySocialContributions',
97
-	'account'      => 'BankTransactions',
98
-	'payment'      => 'Payment',
99
-	'product'      => 'Product',
100
-	'virtualproduct'  => 'AssociatedProducts',
101
-	'subproduct'      => 'SubProduct',
102
-	'product_supplier_ref'      => 'SupplierPrices',
103
-	'service'      => 'Service',
97
+    'account'      => 'BankTransactions',
98
+    'payment'      => 'Payment',
99
+    'product'      => 'Product',
100
+    'virtualproduct'  => 'AssociatedProducts',
101
+    'subproduct'      => 'SubProduct',
102
+    'product_supplier_ref'      => 'SupplierPrices',
103
+    'service'      => 'Service',
104 104
     'stock'        => 'Stock',
105
-	'movement'	   => 'StockMovement',
106
-	'batch'        => 'Batch',
107
-	'stockbatch'   => 'StockDetailPerBatch',
108
-	'warehouse'    => 'Warehouse',
109
-	'category'     => 'Category',
110
-	'other'        => 'Other',
105
+    'movement'	   => 'StockMovement',
106
+    'batch'        => 'Batch',
107
+    'stockbatch'   => 'StockDetailPerBatch',
108
+    'warehouse'    => 'Warehouse',
109
+    'category'     => 'Category',
110
+    'other'        => 'Other',
111 111
     'trip'         => 'TripsAndExpenses',
112 112
     'shipment'     => 'Shipments',
113 113
     'shipment_line'=> 'ShipmentLine',
114 114
     'project'      => 'Projects',
115 115
     'projecttask'  => 'Tasks',
116 116
     'task_time'    => 'TaskTimeSpent',
117
-	'action'       => 'Event',
118
-	'expensereport'=> 'ExpenseReport',
119
-	'expensereport_line'=> 'ExpenseReportLine',
120
-	'holiday'      => 'TitreRequestCP',
121
-	'contract'     => 'Contract',
117
+    'action'       => 'Event',
118
+    'expensereport'=> 'ExpenseReport',
119
+    'expensereport_line'=> 'ExpenseReportLine',
120
+    'holiday'      => 'TitreRequestCP',
121
+    'contract'     => 'Contract',
122 122
     'contract_line'=> 'ContractLine',
123 123
     'translation'  => 'Translation'
124 124
 );
@@ -155,19 +155,19 @@  discard block
 block discarded – undo
155 155
 
156 156
 if ($action=='selectfield')     // Selection of field at step 2
157 157
 {
158
-	$fieldsarray=$objexport->array_export_fields[0];
159
-	$fieldsentitiesarray=$objexport->array_export_entities[0];
158
+    $fieldsarray=$objexport->array_export_fields[0];
159
+    $fieldsentitiesarray=$objexport->array_export_entities[0];
160 160
     $fieldsdependenciesarray=$objexport->array_export_dependencies[0];
161 161
 
162 162
     if ($field=='all')
163 163
     {
164
-		foreach($fieldsarray as $key=>$val)
165
-		{
166
-			if (! empty($array_selected[$key])) continue;		// If already selected, check next
167
-			$array_selected[$key]=count($array_selected)+1;
168
-		    //print_r($array_selected);
169
-		    $_SESSION["export_selected_fields"]=$array_selected;
170
-		}
164
+        foreach($fieldsarray as $key=>$val)
165
+        {
166
+            if (! empty($array_selected[$key])) continue;		// If already selected, check next
167
+            $array_selected[$key]=count($array_selected)+1;
168
+            //print_r($array_selected);
169
+            $_SESSION["export_selected_fields"]=$array_selected;
170
+        }
171 171
     }
172 172
     else
173 173
     {
@@ -205,33 +205,33 @@  discard block
 block discarded – undo
205 205
                 }
206 206
             }
207 207
         }
208
-	    //print_r($array_selected);
209
-	    $_SESSION["export_selected_fields"]=$array_selected;
208
+        //print_r($array_selected);
209
+        $_SESSION["export_selected_fields"]=$array_selected;
210 210
 
211
-	    setEventMessages($warnings, null, 'warnings');
211
+        setEventMessages($warnings, null, 'warnings');
212 212
     }
213 213
 }
214 214
 if ($action=='unselectfield')
215 215
 {
216 216
     if ($_GET["field"]=='all')
217 217
     {
218
-		$array_selected=array();
219
-		$_SESSION["export_selected_fields"]=$array_selected;
218
+        $array_selected=array();
219
+        $_SESSION["export_selected_fields"]=$array_selected;
220 220
     }
221 221
     else
222 222
     {
223
-	    unset($array_selected[$_GET["field"]]);
224
-	    // Renumber fields of array_selected (from 1 to nb_elements)
225
-	    asort($array_selected);
226
-	    $i=0;
227
-	    $array_selected_save=$array_selected;
228
-	    foreach($array_selected as $code=>$value)
229
-	    {
230
-	        $i++;
231
-	        $array_selected[$code]=$i;
232
-	        //print "x $code x $i y<br>";
233
-	    }
234
-	    $_SESSION["export_selected_fields"]=$array_selected;
223
+        unset($array_selected[$_GET["field"]]);
224
+        // Renumber fields of array_selected (from 1 to nb_elements)
225
+        asort($array_selected);
226
+        $i=0;
227
+        $array_selected_save=$array_selected;
228
+        foreach($array_selected as $code=>$value)
229
+        {
230
+            $i++;
231
+            $array_selected[$code]=$i;
232
+            //print "x $code x $i y<br>";
233
+        }
234
+        $_SESSION["export_selected_fields"]=$array_selected;
235 235
     }
236 236
 }
237 237
 
@@ -277,88 +277,88 @@  discard block
 block discarded – undo
277 277
     }
278 278
 
279 279
     // Build export file
280
-	$result=$objexport->build_file($user, GETPOST('model','alpha'), $datatoexport, $array_selected, $array_filtervalue);
281
-	if ($result < 0)
282
-	{
283
-		setEventMessages($objexport->error, $objexport->errors, 'errors');
284
-		$sqlusedforexport=$objexport->sqlusedforexport;
285
-	}
286
-	else
287
-	{
288
-		setEventMessages($langs->trans("FileSuccessfullyBuilt"), null, 'mesgs');
289
-	    $sqlusedforexport=$objexport->sqlusedforexport;
280
+    $result=$objexport->build_file($user, GETPOST('model','alpha'), $datatoexport, $array_selected, $array_filtervalue);
281
+    if ($result < 0)
282
+    {
283
+        setEventMessages($objexport->error, $objexport->errors, 'errors');
284
+        $sqlusedforexport=$objexport->sqlusedforexport;
285
+    }
286
+    else
287
+    {
288
+        setEventMessages($langs->trans("FileSuccessfullyBuilt"), null, 'mesgs');
289
+        $sqlusedforexport=$objexport->sqlusedforexport;
290 290
     }
291 291
 }
292 292
 
293 293
 // Delete file
294 294
 if ($step == 5 && $action == 'confirm_deletefile' && $confirm == 'yes')
295 295
 {
296
-	$file = $upload_dir . "/" . GETPOST('file');	// Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
296
+    $file = $upload_dir . "/" . GETPOST('file');	// Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
297 297
 
298
-	$ret=dol_delete_file($file);
299
-	if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
300
-	else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
301
-	header('Location: '.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport);
302
-	exit;
298
+    $ret=dol_delete_file($file);
299
+    if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
300
+    else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
301
+    header('Location: '.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport);
302
+    exit;
303 303
 }
304 304
 
305 305
 if ($action == 'deleteprof')
306 306
 {
307
-	if ($_GET["id"])
308
-	{
309
-		$objexport->fetch($_GET["id"]);
310
-		$result=$objexport->delete($user);
311
-	}
307
+    if ($_GET["id"])
308
+    {
309
+        $objexport->fetch($_GET["id"]);
310
+        $result=$objexport->delete($user);
311
+    }
312 312
 }
313 313
 
314 314
 // TODO The export for filter is not yet implemented (old code created conflicts with step 2). We must use same way of working and same combo list of predefined export than step 2.
315 315
 if ($action == 'add_export_model')
316 316
 {
317
-	if ($export_name)
318
-	{
319
-		asort($array_selected);
320
-
321
-		// Set save string
322
-		$hexa='';
323
-		foreach($array_selected as $key=>$val)
324
-		{
325
-			if ($hexa) $hexa.=',';
326
-			$hexa.=$key;
327
-		}
328
-
329
-		$hexafiltervalue='';
330
-		if (! empty($array_filtervalue) && is_array($array_filtervalue))
331
-		{
332
-			foreach($array_filtervalue as $key=>$val)
333
-			{
334
-				if ($hexafiltervalue) $hexafiltervalue.=',';
335
-				$hexafiltervalue.=$key.'='.$val;
336
-			}
337
-		}
338
-
339
-	    $objexport->model_name = $export_name;
340
-	    $objexport->datatoexport = $datatoexport;
341
-	    $objexport->hexa = $hexa;
342
-	    $objexport->hexafiltervalue = $hexafiltervalue;
343
-
344
-	    $result = $objexport->create($user);
345
-		if ($result >= 0)
346
-		{
347
-			setEventMessages($langs->trans("ExportModelSaved",$objexport->model_name), null, 'mesgs');
348
-		}
349
-		else
350
-		{
351
-			$langs->load("errors");
352
-			if ($objexport->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS')
353
-				setEventMessages($langs->trans("ErrorExportDuplicateProfil"), null, 'errors');
354
-			else
355
-				setEventMessages($objexport->error, $objexport->errors, 'errors');
356
-		}
357
-	}
358
-	else
359
-	{
360
-		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ExportModelName")), null, 'errors');
361
-	}
317
+    if ($export_name)
318
+    {
319
+        asort($array_selected);
320
+
321
+        // Set save string
322
+        $hexa='';
323
+        foreach($array_selected as $key=>$val)
324
+        {
325
+            if ($hexa) $hexa.=',';
326
+            $hexa.=$key;
327
+        }
328
+
329
+        $hexafiltervalue='';
330
+        if (! empty($array_filtervalue) && is_array($array_filtervalue))
331
+        {
332
+            foreach($array_filtervalue as $key=>$val)
333
+            {
334
+                if ($hexafiltervalue) $hexafiltervalue.=',';
335
+                $hexafiltervalue.=$key.'='.$val;
336
+            }
337
+        }
338
+
339
+        $objexport->model_name = $export_name;
340
+        $objexport->datatoexport = $datatoexport;
341
+        $objexport->hexa = $hexa;
342
+        $objexport->hexafiltervalue = $hexafiltervalue;
343
+
344
+        $result = $objexport->create($user);
345
+        if ($result >= 0)
346
+        {
347
+            setEventMessages($langs->trans("ExportModelSaved",$objexport->model_name), null, 'mesgs');
348
+        }
349
+        else
350
+        {
351
+            $langs->load("errors");
352
+            if ($objexport->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS')
353
+                setEventMessages($langs->trans("ErrorExportDuplicateProfil"), null, 'errors');
354
+            else
355
+                setEventMessages($objexport->error, $objexport->errors, 'errors');
356
+        }
357
+    }
358
+    else
359
+    {
360
+        setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ExportModelName")), null, 'errors');
361
+    }
362 362
 }
363 363
 
364 364
 // Reload an predefined export model
@@ -373,50 +373,50 @@  discard block
 block discarded – undo
373 373
     $result = $objexport->fetch($exportmodelid);
374 374
     if ($result > 0)
375 375
     {
376
-		$fieldsarray=explode(',',$objexport->hexa);
377
-		$i=1;
378
-		foreach($fieldsarray as $val)
379
-		{
380
-			$array_selected[$val]=$i;
381
-			$i++;
382
-		}
383
-		$_SESSION["export_selected_fields"]=$array_selected;
384
-
385
-		$fieldsarrayvalue=explode(',',$objexport->hexafiltervalue);
386
-		$i=1;
387
-		foreach($fieldsarrayvalue as $val)
388
-		{
389
-			$tmp=explode('=',$val);
390
-			$array_filtervalue[$tmp[0]]=$tmp[1];
391
-			$i++;
392
-		}
393
-		$_SESSION["export_filtered_fields"]=$array_filtervalue;
376
+        $fieldsarray=explode(',',$objexport->hexa);
377
+        $i=1;
378
+        foreach($fieldsarray as $val)
379
+        {
380
+            $array_selected[$val]=$i;
381
+            $i++;
382
+        }
383
+        $_SESSION["export_selected_fields"]=$array_selected;
384
+
385
+        $fieldsarrayvalue=explode(',',$objexport->hexafiltervalue);
386
+        $i=1;
387
+        foreach($fieldsarrayvalue as $val)
388
+        {
389
+            $tmp=explode('=',$val);
390
+            $array_filtervalue[$tmp[0]]=$tmp[1];
391
+            $i++;
392
+        }
393
+        $_SESSION["export_filtered_fields"]=$array_filtervalue;
394 394
     }
395 395
 }
396 396
 
397 397
 // Get form with filters
398 398
 if ($step == 4 && $action == 'submitFormField')
399 399
 {
400
-	// on boucle sur les champs selectionne pour recuperer la valeur
401
-	if (is_array($objexport->array_export_TypeFields[0]))
402
-	{
403
-		$_SESSION["export_filtered_fields"]=array();
404
-		foreach($objexport->array_export_TypeFields[0] as $code => $type)	// $code: s.fieldname $value: Text|Boolean|List:ccc
405
-		{
406
-			$newcode=(string) preg_replace('/\./','_',$code);
407
-			//print 'xxx'.$code."=".$newcode."=".$type."=".$_POST[$newcode]."\n<br>";
408
-			$filterqualified=1;
409
-			if (! isset($_POST[$newcode]) || $_POST[$newcode] == '') $filterqualified=0;
410
-			elseif (preg_match('/^List/',$type) && (is_numeric($_POST[$newcode]) && $_POST[$newcode] <= 0)) $filterqualified=0;
411
-			if ($filterqualified)
412
-			{
413
-				//print 'Filter on '.$newcode.' type='.$type.' value='.$_POST[$newcode]."\n";
414
-				$objexport->array_export_FilterValue[0][$code] = $_POST[$newcode];
415
-			}
416
-		}
417
-		$array_filtervalue=(! empty($objexport->array_export_FilterValue[0])?$objexport->array_export_FilterValue[0]:'');
418
-		$_SESSION["export_filtered_fields"]=$array_filtervalue;
419
-	}
400
+    // on boucle sur les champs selectionne pour recuperer la valeur
401
+    if (is_array($objexport->array_export_TypeFields[0]))
402
+    {
403
+        $_SESSION["export_filtered_fields"]=array();
404
+        foreach($objexport->array_export_TypeFields[0] as $code => $type)	// $code: s.fieldname $value: Text|Boolean|List:ccc
405
+        {
406
+            $newcode=(string) preg_replace('/\./','_',$code);
407
+            //print 'xxx'.$code."=".$newcode."=".$type."=".$_POST[$newcode]."\n<br>";
408
+            $filterqualified=1;
409
+            if (! isset($_POST[$newcode]) || $_POST[$newcode] == '') $filterqualified=0;
410
+            elseif (preg_match('/^List/',$type) && (is_numeric($_POST[$newcode]) && $_POST[$newcode] <= 0)) $filterqualified=0;
411
+            if ($filterqualified)
412
+            {
413
+                //print 'Filter on '.$newcode.' type='.$type.' value='.$_POST[$newcode]."\n";
414
+                $objexport->array_export_FilterValue[0][$code] = $_POST[$newcode];
415
+            }
416
+        }
417
+        $array_filtervalue=(! empty($objexport->array_export_FilterValue[0])?$objexport->array_export_FilterValue[0]:'');
418
+        $_SESSION["export_filtered_fields"]=$array_filtervalue;
419
+    }
420 420
 }
421 421
 
422 422
 
@@ -465,24 +465,24 @@  discard block
 block discarded – undo
465 465
         {
466 466
             $val=!$val;
467 467
             print '<tr '.$bc[$val].'><td nospan="nospan">';
468
-	        //print img_object($objexport->array_export_module[$key]->getName(),$export->array_export_module[$key]->picto).' ';
468
+            //print img_object($objexport->array_export_module[$key]->getName(),$export->array_export_module[$key]->picto).' ';
469 469
             print $objexport->array_export_module[$key]->getName();
470 470
             print '</td><td>';
471
-			$icon=preg_replace('/:.*$/','',$objexport->array_export_icon[$key]);
472
-			$label=$objexport->array_export_label[$key];
471
+            $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[$key]);
472
+            $label=$objexport->array_export_label[$key];
473 473
             //print $value.'-'.$icon.'-'.$label."<br>";
474
-			print img_object($objexport->array_export_module[$key]->getName(), $icon).' ';
474
+            print img_object($objexport->array_export_module[$key]->getName(), $icon).' ';
475 475
             print $label;
476 476
             print '</td><td align="right">';
477 477
             if ($objexport->array_export_perms[$key])
478 478
             {
479
-            	print '<a href="'.DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$objexport->array_export_code[$key].'">'.img_picto($langs->trans("NewExport"),'filenew').'</a>';
479
+                print '<a href="'.DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$objexport->array_export_code[$key].'">'.img_picto($langs->trans("NewExport"),'filenew').'</a>';
480 480
             }
481 481
             else
482 482
             {
483
-            	print $langs->trans("NotEnoughPermissions");
483
+                print $langs->trans("NotEnoughPermissions");
484 484
             }
485
-           	print '</td></tr>';
485
+                print '</td></tr>';
486 486
         }
487 487
     }
488 488
     else
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
     // Lot de donnees a exporter
532 532
     print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
533 533
     print '<td>';
534
-	$icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
534
+    $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
535 535
     $label=$objexport->array_export_label[0];
536 536
     //print $value.'-'.$icon.'-'.$label."<br>";
537 537
     print img_object($objexport->array_export_module[0]->getName(), $icon).' ';
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
     print '<table><tr><td colspan="2">';
555 555
     print $langs->trans("SelectExportFields").' ';
556 556
     if(empty($conf->global->EXPORTS_SHARE_MODELS))$htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1,$user->id);
557
-	else $htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1);
557
+    else $htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1);
558 558
     print ' ';
559 559
     print '<input type="submit" class="button" value="'.$langs->trans("Select").'">';
560 560
     print '</td></tr></table>';
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 
564 564
     print '<table class="noborder" width="100%">';
565 565
     print '<tr class="liste_titre">';
566
-	print '<td>'.$langs->trans("Entities").'</td>';
566
+    print '<td>'.$langs->trans("Entities").'</td>';
567 567
     print '<td>'.$langs->trans("ExportableFields").'</td>';
568 568
     print '<td width="100" align="center">';
569 569
     print '<a class="liste_titre" title='.$langs->trans("All").' alt='.$langs->trans("All").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field=all">'.$langs->trans("All")."</a>";
@@ -578,13 +578,13 @@  discard block
 block discarded – undo
578 578
     // Select request if all fields are selected
579 579
     $sqlmaxforexport=$objexport->build_sql(0, array(), array());
580 580
 
581
-	//    $this->array_export_module[0]=$module;
582
-	//    $this->array_export_code[0]=$module->export_code[$r];
583
-	//    $this->array_export_label[0]=$module->export_label[$r];
584
-	//    $this->array_export_sql[0]=$module->export_sql[$r];
585
-	//    $this->array_export_fields[0]=$module->export_fields_array[$r];
586
-	//    $this->array_export_entities[0]=$module->export_fields_entities[$r];
587
-	//    $this->array_export_alias[0]=$module->export_fields_alias[$r];
581
+    //    $this->array_export_module[0]=$module;
582
+    //    $this->array_export_code[0]=$module->export_code[$r];
583
+    //    $this->array_export_label[0]=$module->export_label[$r];
584
+    //    $this->array_export_sql[0]=$module->export_sql[$r];
585
+    //    $this->array_export_fields[0]=$module->export_fields_array[$r];
586
+    //    $this->array_export_entities[0]=$module->export_fields_entities[$r];
587
+    //    $this->array_export_alias[0]=$module->export_fields_alias[$r];
588 588
 
589 589
     $i = 0;
590 590
 
@@ -623,16 +623,16 @@  discard block
 block discarded – undo
623 623
         {
624 624
             $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
625 625
         }
626
-   		if (! empty($objexport->array_export_examplevalues[0][$code]))
627
-		{
628
-		    $htmltext.='<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>';
629
-		}
630
-    	if (! empty($objexport->array_export_TypeFields[0][$code]))
631
-		{
632
-		    $htmltext.='<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>';
633
-		}
634
-
635
-		if (isset($array_selected[$code]) && $array_selected[$code])
626
+            if (! empty($objexport->array_export_examplevalues[0][$code]))
627
+        {
628
+            $htmltext.='<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>';
629
+        }
630
+        if (! empty($objexport->array_export_TypeFields[0][$code]))
631
+        {
632
+            $htmltext.='<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>';
633
+        }
634
+
635
+        if (isset($array_selected[$code]) && $array_selected[$code])
636 636
         {
637 637
             // Selected fields
638 638
             print '<td>&nbsp;</td>';
@@ -640,16 +640,16 @@  discard block
 block discarded – undo
640 640
             print '<td>';
641 641
             //print $text.'-'.$htmltext."<br>";
642 642
             print $form->textwithpicto($text,$htmltext);
643
-			//print ' ('.$code.')';
643
+            //print ' ('.$code.')';
644 644
             print '</td>';
645 645
         }
646 646
         else
647 647
         {
648
-        	// Fields not selected
648
+            // Fields not selected
649 649
             print '<td>';
650
-			//print $text.'-'.$htmltext."<br>";
651
-			print $form->textwithpicto($text,$htmltext);
652
-			//print ' ('.$code.')';
650
+            //print $text.'-'.$htmltext."<br>";
651
+            print $form->textwithpicto($text,$htmltext);
652
+            //print ' ('.$code.')';
653 653
             print '</td>';
654 654
             print '<td align="center"><a class="reposition" href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field='.$code.'">'.img_right('default', 0, 'style="max-width: 20px"').'</a></td>';
655 655
             print '<td>&nbsp;</td>';
@@ -667,21 +667,21 @@  discard block
 block discarded – undo
667 667
     print '<div class="tabsAction tabsActionNoBottom">';
668 668
 
669 669
     if (count($array_selected))
670
-	{
671
-		// If filters exist
672
-		if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
673
-		{
674
-			print '<a class="butAction" href="export.php?step=3&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
675
-		}
676
-		else
677
-		{
678
-			print '<a class="butAction" href="export.php?step=4&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
679
-		}
680
-	}
681
-	else
682
-	{
683
-		print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("SelectAtLeastOneField")).'">'.$langs->trans("NextStep").'</a>';
684
-	}
670
+    {
671
+        // If filters exist
672
+        if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
673
+        {
674
+            print '<a class="butAction" href="export.php?step=3&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
675
+        }
676
+        else
677
+        {
678
+            print '<a class="butAction" href="export.php?step=4&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
679
+        }
680
+    }
681
+    else
682
+    {
683
+        print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("SelectAtLeastOneField")).'">'.$langs->trans("NextStep").'</a>';
684
+    }
685 685
 
686 686
     print '</div>';
687 687
 }
@@ -697,167 +697,167 @@  discard block
 block discarded – undo
697 697
 
698 698
     llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
699 699
 
700
-	/*
700
+    /*
701 701
 	 * Affichage onglets
702 702
 	*/
703
-	$h = 0;
703
+    $h = 0;
704 704
 
705
-	$head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
706
-	$head[$h][1] = $langs->trans("Step")." 1";
707
-	$h++;
705
+    $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
706
+    $head[$h][1] = $langs->trans("Step")." 1";
707
+    $h++;
708 708
 
709
-	$head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
710
-	$head[$h][1] = $langs->trans("Step")." 2";
711
-	$h++;
709
+    $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
710
+    $head[$h][1] = $langs->trans("Step")." 2";
711
+    $h++;
712 712
 
713
-	$head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
714
-	$head[$h][1] = $langs->trans("Step")." 3";
715
-	$hselected=$h;
716
-	$h++;
713
+    $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
714
+    $head[$h][1] = $langs->trans("Step")." 3";
715
+    $hselected=$h;
716
+    $h++;
717 717
 
718
-	dol_fiche_head($head, $hselected, $langs->trans("NewExport"), -1);
718
+    dol_fiche_head($head, $hselected, $langs->trans("NewExport"), -1);
719 719
 
720 720
     print '<div class="fichecenter">';
721 721
     print '<div class="underbanner clearboth"></div>';
722
-	print '<table width="100%" class="border">';
723
-
724
-	// Module
725
-	print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>';
726
-	print '<td>';
727
-	//print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
728
-	print $objexport->array_export_module[0]->getName();
729
-	print '</td></tr>';
730
-
731
-	// Lot de donnees a exporter
732
-	print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
733
-	print '<td>';
734
-	$icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
735
-	$label=$objexport->array_export_label[0];
736
-	//print $value.'-'.$icon.'-'.$label."<br>";
737
-	print img_object($objexport->array_export_module[0]->getName(), $icon).' ';
738
-	print $label;
739
-	print '</td></tr>';
740
-
741
-	// Nbre champs exportes
742
-	print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
743
-	$list='';
744
-	foreach($array_selected as $code=>$value)
745
-	{
746
-		$list.=(! empty($list)?', ':'');
747
-		$list.=(isset($objexport->array_export_fields[0][$code])?$langs->trans($objexport->array_export_fields[0][$code]):'');
748
-	}
749
-	print '<td>'.$list.'</td></tr>';
750
-
751
-	print '</table>';
752
-	print '</div>';
753
-
754
-	print '<br>';
755
-
756
-	// Combo list of export models
757
-	print $langs->trans("SelectFilterFields").'<br>';
758
-
759
-
760
-	// un formulaire en plus pour recuperer les filtres
761
-	print '<form action="'.$_SERVER["PHP_SELF"].'?step=4&action=submitFormField&datatoexport='.$datatoexport.'" name="FilterField" method="post">';
762
-	print '<table class="noborder" width="100%">';
763
-	print '<tr class="liste_titre">';
764
-	print '<td>'.$langs->trans("Entities").'</td>';
765
-	//print '<td>'.$langs->trans("ExportableFields").'</td>';
766
-	//print '<td align="center"></td>';
767
-	print '<td>'.$langs->trans("ExportableFields").'</td>';
768
-	print '<td width="25%">'.$langs->trans("FilteredFieldsValues").'</td>';
769
-	print '</tr>';
770
-
771
-	// Champs exportables
772
-	$fieldsarray=$objexport->array_export_fields[0];
773
-	// Champs filtrable
774
-	$Typefieldsarray=$objexport->array_export_TypeFields[0];
775
-	// valeur des filtres
776
-	$ValueFiltersarray=(! empty($objexport->array_export_FilterValue[0])?$objexport->array_export_FilterValue[0]:'');
777
-	// Select request if all fields are selected
778
-	$sqlmaxforexport=$objexport->build_sql(0, array(), array());
779
-
780
-	$i = 0;
781
-	// on boucle sur les champs
782
-	foreach($fieldsarray as $code => $label)
783
-	{
784
-		print '<tr class="oddeven">';
785
-
786
-		$i++;
787
-		$entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]);
788
-		$entityicon=strtolower(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
789
-		$entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity);
790
-
791
-		print '<td class="nowrap">';
792
-		// If value of entityicon=entitylang='icon:Label'
793
-		$tmparray=explode(':',$entityicon);
794
-		if (count($tmparray) >=2)
795
-		{
796
-			$entityicon=$tmparray[0];
797
-			$entitylang=$tmparray[1];
798
-		}
799
-		print img_object('',$entityicon).' '.$langs->trans($entitylang);
800
-		print '</td>';
801
-
802
-		// Field name
803
-		$labelName=(! empty($fieldsarray[$code])?$fieldsarray[$code]:'');
804
-		$ValueFilter=(! empty($array_filtervalue[$code])?$array_filtervalue[$code]:'');
805
-		$text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code])?'':'</i>');
806
-
807
-		$tablename=getablenamefromfield($code,$sqlmaxforexport);
808
-		$htmltext ='<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
809
-			if (! empty($objexport->array_export_special[0][$code]))
810
-		{
811
-		    $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
812
-		}
813
-		else
814
-		{
815
-		    $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
816
-		}
817
-		if (! empty($objexport->array_export_examplevalues[0][$code]))
818
-		{
819
-		    $htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
820
-		}
821
-		if (! empty($objexport->array_export_TypeFields[0][$code]))
822
-		{
823
-		    $htmltext.=$langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>';
824
-		}
825
-
826
-		print '<td>';
827
-		print $form->textwithpicto($text,$htmltext);
828
-		print '</td>';
829
-
830
-		// Filter value
831
-		print '<td>';
832
-		if (! empty($Typefieldsarray[$code]))	// Example: Text, List:c_country:label:rowid, Number, Boolean
833
-		{
834
-			$szInfoFiltre=$objexport->genDocFilter($Typefieldsarray[$code]);
835
-			if ($szInfoFiltre)	// Is there an info help for this filter ?
836
-			{
837
-				$tmp=$objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
838
-				print $form->textwithpicto($tmp, $szInfoFiltre);
839
-			}
840
-			else
841
-			{
842
-				print $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
843
-			}
844
-		}
845
-		print '</td>';
846
-
847
-		print '</tr>';
848
-	}
849
-
850
-	print '</table>';
851
-
852
-	print '</div>';
853
-
854
-	/*
722
+    print '<table width="100%" class="border">';
723
+
724
+    // Module
725
+    print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>';
726
+    print '<td>';
727
+    //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' ';
728
+    print $objexport->array_export_module[0]->getName();
729
+    print '</td></tr>';
730
+
731
+    // Lot de donnees a exporter
732
+    print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
733
+    print '<td>';
734
+    $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
735
+    $label=$objexport->array_export_label[0];
736
+    //print $value.'-'.$icon.'-'.$label."<br>";
737
+    print img_object($objexport->array_export_module[0]->getName(), $icon).' ';
738
+    print $label;
739
+    print '</td></tr>';
740
+
741
+    // Nbre champs exportes
742
+    print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
743
+    $list='';
744
+    foreach($array_selected as $code=>$value)
745
+    {
746
+        $list.=(! empty($list)?', ':'');
747
+        $list.=(isset($objexport->array_export_fields[0][$code])?$langs->trans($objexport->array_export_fields[0][$code]):'');
748
+    }
749
+    print '<td>'.$list.'</td></tr>';
750
+
751
+    print '</table>';
752
+    print '</div>';
753
+
754
+    print '<br>';
755
+
756
+    // Combo list of export models
757
+    print $langs->trans("SelectFilterFields").'<br>';
758
+
759
+
760
+    // un formulaire en plus pour recuperer les filtres
761
+    print '<form action="'.$_SERVER["PHP_SELF"].'?step=4&action=submitFormField&datatoexport='.$datatoexport.'" name="FilterField" method="post">';
762
+    print '<table class="noborder" width="100%">';
763
+    print '<tr class="liste_titre">';
764
+    print '<td>'.$langs->trans("Entities").'</td>';
765
+    //print '<td>'.$langs->trans("ExportableFields").'</td>';
766
+    //print '<td align="center"></td>';
767
+    print '<td>'.$langs->trans("ExportableFields").'</td>';
768
+    print '<td width="25%">'.$langs->trans("FilteredFieldsValues").'</td>';
769
+    print '</tr>';
770
+
771
+    // Champs exportables
772
+    $fieldsarray=$objexport->array_export_fields[0];
773
+    // Champs filtrable
774
+    $Typefieldsarray=$objexport->array_export_TypeFields[0];
775
+    // valeur des filtres
776
+    $ValueFiltersarray=(! empty($objexport->array_export_FilterValue[0])?$objexport->array_export_FilterValue[0]:'');
777
+    // Select request if all fields are selected
778
+    $sqlmaxforexport=$objexport->build_sql(0, array(), array());
779
+
780
+    $i = 0;
781
+    // on boucle sur les champs
782
+    foreach($fieldsarray as $code => $label)
783
+    {
784
+        print '<tr class="oddeven">';
785
+
786
+        $i++;
787
+        $entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]);
788
+        $entityicon=strtolower(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
789
+        $entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity);
790
+
791
+        print '<td class="nowrap">';
792
+        // If value of entityicon=entitylang='icon:Label'
793
+        $tmparray=explode(':',$entityicon);
794
+        if (count($tmparray) >=2)
795
+        {
796
+            $entityicon=$tmparray[0];
797
+            $entitylang=$tmparray[1];
798
+        }
799
+        print img_object('',$entityicon).' '.$langs->trans($entitylang);
800
+        print '</td>';
801
+
802
+        // Field name
803
+        $labelName=(! empty($fieldsarray[$code])?$fieldsarray[$code]:'');
804
+        $ValueFilter=(! empty($array_filtervalue[$code])?$array_filtervalue[$code]:'');
805
+        $text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code])?'':'</i>');
806
+
807
+        $tablename=getablenamefromfield($code,$sqlmaxforexport);
808
+        $htmltext ='<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
809
+            if (! empty($objexport->array_export_special[0][$code]))
810
+        {
811
+            $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
812
+        }
813
+        else
814
+        {
815
+            $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
816
+        }
817
+        if (! empty($objexport->array_export_examplevalues[0][$code]))
818
+        {
819
+            $htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
820
+        }
821
+        if (! empty($objexport->array_export_TypeFields[0][$code]))
822
+        {
823
+            $htmltext.=$langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>';
824
+        }
825
+
826
+        print '<td>';
827
+        print $form->textwithpicto($text,$htmltext);
828
+        print '</td>';
829
+
830
+        // Filter value
831
+        print '<td>';
832
+        if (! empty($Typefieldsarray[$code]))	// Example: Text, List:c_country:label:rowid, Number, Boolean
833
+        {
834
+            $szInfoFiltre=$objexport->genDocFilter($Typefieldsarray[$code]);
835
+            if ($szInfoFiltre)	// Is there an info help for this filter ?
836
+            {
837
+                $tmp=$objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
838
+                print $form->textwithpicto($tmp, $szInfoFiltre);
839
+            }
840
+            else
841
+            {
842
+                print $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
843
+            }
844
+        }
845
+        print '</td>';
846
+
847
+        print '</tr>';
848
+    }
849
+
850
+    print '</table>';
851
+
852
+    print '</div>';
853
+
854
+    /*
855 855
 	 * Barre d'action
856 856
 	 */
857
-	print '<div class="tabsAction tabsActionNoBottom">';
858
-	// il n'est pas obligatoire de filtrer les champs
859
-	print '<a class="butAction" href="javascript:FilterField.submit();">'.$langs->trans("NextStep").'</a>';
860
-	print '</div>';
857
+    print '<div class="tabsAction tabsActionNoBottom">';
858
+    // il n'est pas obligatoire de filtrer les champs
859
+    print '<a class="butAction" href="javascript:FilterField.submit();">'.$langs->trans("NextStep").'</a>';
860
+    print '</div>';
861 861
 }
862 862
 
863 863
 if ($step == 4 && $datatoexport)
@@ -890,10 +890,10 @@  discard block
 block discarded – undo
890 890
     // If filters exist
891 891
     if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
892 892
     {
893
-    	$head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
894
-    	$head[$h][1] = $langs->trans("Step")." 3";
895
-    	$h++;
896
-    	$stepoffset++;
893
+        $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
894
+        $head[$h][1] = $langs->trans("Step")." 3";
895
+        $h++;
896
+        $stepoffset++;
897 897
     }
898 898
 
899 899
     $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
     // Lot de donnees a exporter
918 918
     print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
919 919
     print '<td>';
920
-	$icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
920
+    $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
921 921
     print img_object($objexport->array_export_module[0]->getName(), $icon).' ';
922 922
     print $objexport->array_export_label[0];
923 923
     print '</td></tr>';
@@ -936,22 +936,22 @@  discard block
 block discarded – undo
936 936
     // List of filtered fiels
937 937
     if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
938 938
     {
939
-    	print '<tr><td width="25%">'.$langs->trans("FilteredFields").'</td>';
940
-    	$list='';
941
-    	if (! empty($array_filtervalue))
942
-    	{
943
-    		foreach($array_filtervalue as $code=>$value)
944
-    		{
945
-    			if (isset($objexport->array_export_fields[0][$code]))
946
-    			{
947
-    				$list.=($list?', ':'');
948
-    				if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'');
949
-    				else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
950
-    			}
951
-    		}
952
-    	}
953
-    	print '<td>'.(! empty($list)?$list:$langs->trans("None")).'</td>';
954
-    	print '</tr>';
939
+        print '<tr><td width="25%">'.$langs->trans("FilteredFields").'</td>';
940
+        $list='';
941
+        if (! empty($array_filtervalue))
942
+        {
943
+            foreach($array_filtervalue as $code=>$value)
944
+            {
945
+                if (isset($objexport->array_export_fields[0][$code]))
946
+                {
947
+                    $list.=($list?', ':'');
948
+                    if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'');
949
+                    else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
950
+                }
951
+            }
952
+        }
953
+        print '<td>'.(! empty($list)?$list:$langs->trans("None")).'</td>';
954
+        print '</tr>';
955 955
     }
956 956
 
957 957
     print '</table>';
@@ -994,7 +994,7 @@  discard block
 block discarded – undo
994 994
 
995 995
         $labelName=$objexport->array_export_fields[0][$code];
996 996
 
997
-		$text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code])?'':'</i>');
997
+        $text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code])?'':'</i>');
998 998
 
999 999
         $tablename=getablenamefromfield($code,$sqlmaxforexport);
1000 1000
         $htmltext ='<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
 
1018 1018
         print '<td>';
1019 1019
         print $form->textwithpicto($text,$htmltext);
1020
-		//print ' ('.$code.')';
1020
+        //print ' ('.$code.')';
1021 1021
         print '</td>';
1022 1022
 
1023 1023
         print '<td align="right" width="100">';
@@ -1051,57 +1051,57 @@  discard block
 block discarded – undo
1051 1051
     print '</div>';
1052 1052
 
1053 1053
 
1054
-	// Area for profils export
1055
-	if (count($array_selected))
1054
+    // Area for profils export
1055
+    if (count($array_selected))
1056 1056
     {
1057
-		print '<br>';
1057
+        print '<br>';
1058 1058
         print $langs->trans("SaveExportModel");
1059 1059
 
1060
-		print '<form class="nocellnopadd" action="export.php" method="post">';
1061
-		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1060
+        print '<form class="nocellnopadd" action="export.php" method="post">';
1061
+        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1062 1062
         print '<input type="hidden" name="action" value="add_export_model">';
1063 1063
         print '<input type="hidden" name="step" value="'.$step.'">';
1064 1064
         print '<input type="hidden" name="datatoexport" value="'.$datatoexport.'">';
1065 1065
         print '<input type="hidden" name="hexa" value="'.$hexa.'">';
1066 1066
 
1067 1067
         print '<table class="noborder" width="100%">';
1068
-		print '<tr class="liste_titre">';
1069
-		print '<td>'.$langs->trans("ExportModelName").'</td>';
1070
-		print '<td>&nbsp;</td>';
1071
-		print '</tr>';
1068
+        print '<tr class="liste_titre">';
1069
+        print '<td>'.$langs->trans("ExportModelName").'</td>';
1070
+        print '<td>&nbsp;</td>';
1071
+        print '</tr>';
1072 1072
 
1073
-		print '<tr class="oddeven">';
1074
-		print '<td><input name="export_name" size="32" value=""></td><td align="right">';
1073
+        print '<tr class="oddeven">';
1074
+        print '<td><input name="export_name" size="32" value=""></td><td align="right">';
1075 1075
         print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
1076 1076
         print '</td></tr>';
1077 1077
 
1078 1078
         // List of existing export profils
1079
-    	$sql = "SELECT rowid, label";
1080
-		$sql.= " FROM ".MAIN_DB_PREFIX."export_model";
1081
-		$sql.= " WHERE type = '".$datatoexport."'";
1082
-		if(empty($conf->global->EXPORTS_SHARE_MODELS))$sql.=" AND fk_user=".$user->id;
1083
-		$sql.= " ORDER BY rowid";
1084
-		$resql = $db->query($sql);
1085
-		if ($resql)
1086
-		{
1087
-			$num = $db->num_rows($resql);
1088
-			$i = 0;
1089
-			while ($i < $num)
1090
-			{
1091
-				$obj = $db->fetch_object($resql);
1092
-				print '<tr class="oddeven"><td>';
1093
-				print $obj->label;
1094
-				print '</td><td align="right">';
1095
-				print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=deleteprof&id='.$obj->rowid.'">';
1096
-				print img_delete();
1097
-				print '</a>';
1098
-				print '</tr>';
1099
-				$i++;
1100
-			}
1101
-		}
1102
-		else {
1103
-			dol_print_error($this->db);
1104
-		}
1079
+        $sql = "SELECT rowid, label";
1080
+        $sql.= " FROM ".MAIN_DB_PREFIX."export_model";
1081
+        $sql.= " WHERE type = '".$datatoexport."'";
1082
+        if(empty($conf->global->EXPORTS_SHARE_MODELS))$sql.=" AND fk_user=".$user->id;
1083
+        $sql.= " ORDER BY rowid";
1084
+        $resql = $db->query($sql);
1085
+        if ($resql)
1086
+        {
1087
+            $num = $db->num_rows($resql);
1088
+            $i = 0;
1089
+            while ($i < $num)
1090
+            {
1091
+                $obj = $db->fetch_object($resql);
1092
+                print '<tr class="oddeven"><td>';
1093
+                print $obj->label;
1094
+                print '</td><td align="right">';
1095
+                print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=deleteprof&id='.$obj->rowid.'">';
1096
+                print img_delete();
1097
+                print '</a>';
1098
+                print '</tr>';
1099
+                $i++;
1100
+            }
1101
+        }
1102
+        else {
1103
+            dol_print_error($this->db);
1104
+        }
1105 1105
 
1106 1106
         print '</table>';
1107 1107
         print '</form>';
@@ -1117,7 +1117,7 @@  discard block
 block discarded – undo
1117 1117
         exit;
1118 1118
     }
1119 1119
 
1120
-	asort($array_selected);
1120
+    asort($array_selected);
1121 1121
 
1122 1122
     llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
1123 1123
 
@@ -1138,10 +1138,10 @@  discard block
 block discarded – undo
1138 1138
     // si le filtrage est parametre pour l'export ou pas
1139 1139
     if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
1140 1140
     {
1141
-    	$head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
1142
-    	$head[$h][1] = $langs->trans("Step")." 3";
1143
-    	$h++;
1144
-    	$stepoffset++;
1141
+        $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
1142
+        $head[$h][1] = $langs->trans("Step")." 3";
1143
+        $h++;
1144
+        $stepoffset++;
1145 1145
     }
1146 1146
 
1147 1147
     $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
@@ -1160,7 +1160,7 @@  discard block
 block discarded – undo
1160 1160
      */
1161 1161
     if ($action == 'remove_file')
1162 1162
     {
1163
-    	print $form->formconfirm($_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport.'&file='.urlencode(GETPOST("file")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
1163
+        print $form->formconfirm($_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport.'&file='.urlencode(GETPOST("file")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
1164 1164
     }
1165 1165
 
1166 1166
     print '<div class="fichecenter">';
@@ -1178,7 +1178,7 @@  discard block
 block discarded – undo
1178 1178
     // Lot de donnees a exporter
1179 1179
     print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
1180 1180
     print '<td>';
1181
-	$icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
1181
+    $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
1182 1182
     print img_object($objexport->array_export_module[0]->getName(), $icon).' ';
1183 1183
     print $objexport->array_export_label[0];
1184 1184
     print '</td></tr>';
@@ -1196,22 +1196,22 @@  discard block
 block discarded – undo
1196 1196
     // List of filtered fiels
1197 1197
     if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
1198 1198
     {
1199
-    	print '<tr><td>'.$langs->trans("FilteredFields").'</td>';
1200
-    	$list='';
1201
-    	if (! empty($array_filtervalue))
1202
-    	{
1203
-    		foreach($array_filtervalue as $code=>$value)
1204
-    		{
1205
-    			if (isset($objexport->array_export_fields[0][$code]))
1206
-    			{
1207
-    				$list.=($list?', ':'');
1208
-    				if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'');
1209
-    				else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
1210
-    			}
1211
-    		}
1212
-    	}
1213
-    	print '<td>'.(! empty($list)?$list:$langs->trans("None")).'</td>';
1214
-    	print '</tr>';
1199
+        print '<tr><td>'.$langs->trans("FilteredFields").'</td>';
1200
+        $list='';
1201
+        if (! empty($array_filtervalue))
1202
+        {
1203
+            foreach($array_filtervalue as $code=>$value)
1204
+            {
1205
+                if (isset($objexport->array_export_fields[0][$code]))
1206
+                {
1207
+                    $list.=($list?', ':'');
1208
+                    if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'');
1209
+                    else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
1210
+                }
1211
+            }
1212
+        }
1213
+        print '<td>'.(! empty($list)?$list:$langs->trans("None")).'</td>';
1214
+        print '</tr>';
1215 1215
     }
1216 1216
 
1217 1217
     print '</table>';
@@ -1233,17 +1233,17 @@  discard block
 block discarded – undo
1233 1233
     $listeall=$liste;
1234 1234
     foreach($listeall as $key => $val)
1235 1235
     {
1236
-    	if (preg_match('/__\(Disabled\)__/',$listeall[$key]))
1237
-    	{
1238
-    		$listeall[$key]=preg_replace('/__\(Disabled\)__/','('.$langs->transnoentitiesnoconv("Disabled").')',$listeall[$key]);
1239
-    		unset($liste[$key]);
1240
-    	}
1236
+        if (preg_match('/__\(Disabled\)__/',$listeall[$key]))
1237
+        {
1238
+            $listeall[$key]=preg_replace('/__\(Disabled\)__/','('.$langs->transnoentitiesnoconv("Disabled").')',$listeall[$key]);
1239
+            unset($liste[$key]);
1240
+        }
1241 1241
 
1242 1242
         print '<tr class="oddeven">';
1243 1243
         print '<td width="16">'.img_picto_common($key,$objmodelexport->getPictoForKey($key)).' ';
1244
-	    $text=$objmodelexport->getDriverDescForKey($key);
1245
-	    $label=$listeall[$key];
1246
-	    print $form->textwithpicto($label,$text).'</td>';
1244
+        $text=$objmodelexport->getDriverDescForKey($key);
1245
+        $label=$listeall[$key];
1246
+        print $form->textwithpicto($label,$text).'</td>';
1247 1247
         print '<td>'.$objmodelexport->getLibLabelForKey($key).'</td>';
1248 1248
         print '<td align="right">'.$objmodelexport->getLibVersionForKey($key).'</td>';
1249 1249
         print '</tr>'."\n";
@@ -1257,14 +1257,14 @@  discard block
 block discarded – undo
1257 1257
 
1258 1258
     if ($sqlusedforexport && $user->admin)
1259 1259
     {
1260
-    	print '<tr><td>';
1261
-    	print info_admin($langs->trans("SQLUsedForExport").':<br> '.$sqlusedforexport);
1262
-    	print '</td></tr>';
1260
+        print '<tr><td>';
1261
+        print info_admin($langs->trans("SQLUsedForExport").':<br> '.$sqlusedforexport);
1262
+        print '</td></tr>';
1263 1263
     }
1264
-	print '</table>';
1264
+    print '</table>';
1265 1265
 
1266 1266
 
1267
-	print '<div class="fichecenter"><div class="fichehalfleft">';
1267
+    print '<div class="fichecenter"><div class="fichehalfleft">';
1268 1268
 
1269 1269
     if (! is_dir($conf->export->dir_temp)) dol_mkdir($conf->export->dir_temp);
1270 1270
 
@@ -1293,16 +1293,16 @@  discard block
 block discarded – undo
1293 1293
  */
1294 1294
 function getablenamefromfield($code,$sqlmaxforexport)
1295 1295
 {
1296
-	$alias=preg_replace('/\.(.*)$/i','',$code);         // Keep only 'Alias' and remove '.Fieldname'
1297
-	$regexstring='/([a-zA-Z_]+) as '.preg_quote($alias).'[, \)]/i';
1298
-
1299
-	$newsql=$sqlmaxforexport;
1300
-	$newsql=preg_replace('/^(.*) FROM /i','',$newsql);  // Remove part before the FROM
1301
-	$newsql=preg_replace('/WHERE (.*)$/i','',$newsql);	// Remove part after the WHERE so we have now only list of table aliases in a string. We must keep the ' ' before WHERE
1302
-
1303
-	if (preg_match($regexstring,$newsql,$reg))
1304
-	{
1305
-		return $reg[1];   // The tablename
1306
-	}
1307
-	else return '';
1296
+    $alias=preg_replace('/\.(.*)$/i','',$code);         // Keep only 'Alias' and remove '.Fieldname'
1297
+    $regexstring='/([a-zA-Z_]+) as '.preg_quote($alias).'[, \)]/i';
1298
+
1299
+    $newsql=$sqlmaxforexport;
1300
+    $newsql=preg_replace('/^(.*) FROM /i','',$newsql);  // Remove part before the FROM
1301
+    $newsql=preg_replace('/WHERE (.*)$/i','',$newsql);	// Remove part after the WHERE so we have now only list of table aliases in a string. We must keep the ' ' before WHERE
1302
+
1303
+    if (preg_match($regexstring,$newsql,$reg))
1304
+    {
1305
+        return $reg[1];   // The tablename
1306
+    }
1307
+    else return '';
1308 1308
 }
Please login to merge, or discard this patch.
Braces   +111 added lines, -69 removed lines patch added patch discarded remove patch
@@ -153,9 +153,11 @@  discard block
 block discarded – undo
153 153
  * Actions
154 154
  */
155 155
 
156
-if ($action=='selectfield')     // Selection of field at step 2
156
+if ($action=='selectfield') {
157
+    // Selection of field at step 2
157 158
 {
158 159
 	$fieldsarray=$objexport->array_export_fields[0];
160
+}
159 161
 	$fieldsentitiesarray=$objexport->array_export_entities[0];
160 162
     $fieldsdependenciesarray=$objexport->array_export_dependencies[0];
161 163
 
@@ -163,13 +165,15 @@  discard block
 block discarded – undo
163 165
     {
164 166
 		foreach($fieldsarray as $key=>$val)
165 167
 		{
166
-			if (! empty($array_selected[$key])) continue;		// If already selected, check next
168
+			if (! empty($array_selected[$key])) {
169
+			    continue;
170
+			}
171
+			// If already selected, check next
167 172
 			$array_selected[$key]=count($array_selected)+1;
168 173
 		    //print_r($array_selected);
169 174
 		    $_SESSION["export_selected_fields"]=$array_selected;
170 175
 		}
171
-    }
172
-    else
176
+    } else
173 177
     {
174 178
         $warnings=array();
175 179
 
@@ -183,15 +187,20 @@  discard block
 block discarded – undo
183 187
         {
184 188
             // We found a dependency on the type of field
185 189
             $tmp=$fieldsdependenciesarray[$fieldsentitiesarray[$field]]; // $fieldsdependenciesarray=array('element'=>'fd.rowid') or array('element'=>array('fd.rowid','ab.rowid'))
186
-            if (is_array($tmp)) $listofdependencies=$tmp;
187
-            else $listofdependencies=array($tmp);
188
-        }
189
-        else if (! empty($field) && ! empty($fieldsdependenciesarray[$field]))
190
+            if (is_array($tmp)) {
191
+                $listofdependencies=$tmp;
192
+            } else {
193
+                $listofdependencies=array($tmp);
194
+            }
195
+        } else if (! empty($field) && ! empty($fieldsdependenciesarray[$field]))
190 196
         {
191 197
             // We found a dependency on a dedicated field
192 198
             $tmp=$fieldsdependenciesarray[$field]; // $fieldsdependenciesarray=array('fd.fieldx'=>'fd.rowid') or array('fd.fieldx'=>array('fd.rowid','ab.rowid'))
193
-            if (is_array($tmp)) $listofdependencies=$tmp;
194
-            else $listofdependencies=array($tmp);
199
+            if (is_array($tmp)) {
200
+                $listofdependencies=$tmp;
201
+            } else {
202
+                $listofdependencies=array($tmp);
203
+            }
195 204
         }
196 205
 
197 206
         if (count($listofdependencies))
@@ -217,8 +226,7 @@  discard block
 block discarded – undo
217 226
     {
218 227
 		$array_selected=array();
219 228
 		$_SESSION["export_selected_fields"]=$array_selected;
220
-    }
221
-    else
229
+    } else
222 230
     {
223 231
 	    unset($array_selected[$_GET["field"]]);
224 232
 	    // Renumber fields of array_selected (from 1 to nb_elements)
@@ -238,8 +246,12 @@  discard block
 block discarded – undo
238 246
 if ($action=='downfield' || $action=='upfield')
239 247
 {
240 248
     $pos=$array_selected[$_GET["field"]];
241
-    if ($action=='downfield') $newpos=$pos+1;
242
-    if ($action=='upfield') $newpos=$pos-1;
249
+    if ($action=='downfield') {
250
+        $newpos=$pos+1;
251
+    }
252
+    if ($action=='upfield') {
253
+        $newpos=$pos-1;
254
+    }
243 255
     // Recherche code avec qui switcher
244 256
     $newcode="";
245 257
     foreach($array_selected as $code=>$value)
@@ -251,9 +263,11 @@  discard block
 block discarded – undo
251 263
         }
252 264
     }
253 265
     //print("Switch pos=$pos (code=".$_GET["field"].") and newpos=$newpos (code=$newcode)");
254
-    if ($newcode)   // Si newcode trouve (protection contre resoumission de page)
266
+    if ($newcode) {
267
+        // Si newcode trouve (protection contre resoumission de page)
255 268
     {
256 269
         $array_selected[$_GET["field"]]=$newpos;
270
+    }
257 271
         $array_selected[$newcode]=$pos;
258 272
         $_SESSION["export_selected_fields"]=$array_selected;
259 273
     }
@@ -282,8 +296,7 @@  discard block
 block discarded – undo
282 296
 	{
283 297
 		setEventMessages($objexport->error, $objexport->errors, 'errors');
284 298
 		$sqlusedforexport=$objexport->sqlusedforexport;
285
-	}
286
-	else
299
+	} else
287 300
 	{
288 301
 		setEventMessages($langs->trans("FileSuccessfullyBuilt"), null, 'mesgs');
289 302
 	    $sqlusedforexport=$objexport->sqlusedforexport;
@@ -296,8 +309,11 @@  discard block
 block discarded – undo
296 309
 	$file = $upload_dir . "/" . GETPOST('file');	// Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
297 310
 
298 311
 	$ret=dol_delete_file($file);
299
-	if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
300
-	else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
312
+	if ($ret) {
313
+	    setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
314
+	} else {
315
+	    setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
316
+	}
301 317
 	header('Location: '.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport);
302 318
 	exit;
303 319
 }
@@ -322,7 +338,9 @@  discard block
 block discarded – undo
322 338
 		$hexa='';
323 339
 		foreach($array_selected as $key=>$val)
324 340
 		{
325
-			if ($hexa) $hexa.=',';
341
+			if ($hexa) {
342
+			    $hexa.=',';
343
+			}
326 344
 			$hexa.=$key;
327 345
 		}
328 346
 
@@ -331,7 +349,9 @@  discard block
 block discarded – undo
331 349
 		{
332 350
 			foreach($array_filtervalue as $key=>$val)
333 351
 			{
334
-				if ($hexafiltervalue) $hexafiltervalue.=',';
352
+				if ($hexafiltervalue) {
353
+				    $hexafiltervalue.=',';
354
+				}
335 355
 				$hexafiltervalue.=$key.'='.$val;
336 356
 			}
337 357
 		}
@@ -345,17 +365,16 @@  discard block
 block discarded – undo
345 365
 		if ($result >= 0)
346 366
 		{
347 367
 			setEventMessages($langs->trans("ExportModelSaved",$objexport->model_name), null, 'mesgs');
348
-		}
349
-		else
368
+		} else
350 369
 		{
351 370
 			$langs->load("errors");
352
-			if ($objexport->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS')
353
-				setEventMessages($langs->trans("ErrorExportDuplicateProfil"), null, 'errors');
354
-			else
355
-				setEventMessages($objexport->error, $objexport->errors, 'errors');
371
+			if ($objexport->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
372
+							setEventMessages($langs->trans("ErrorExportDuplicateProfil"), null, 'errors');
373
+			} else {
374
+							setEventMessages($objexport->error, $objexport->errors, 'errors');
375
+			}
356 376
 		}
357
-	}
358
-	else
377
+	} else
359 378
 	{
360 379
 		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ExportModelName")), null, 'errors');
361 380
 	}
@@ -401,13 +420,18 @@  discard block
 block discarded – undo
401 420
 	if (is_array($objexport->array_export_TypeFields[0]))
402 421
 	{
403 422
 		$_SESSION["export_filtered_fields"]=array();
404
-		foreach($objexport->array_export_TypeFields[0] as $code => $type)	// $code: s.fieldname $value: Text|Boolean|List:ccc
423
+		foreach($objexport->array_export_TypeFields[0] as $code => $type) {
424
+		    // $code: s.fieldname $value: Text|Boolean|List:ccc
405 425
 		{
406 426
 			$newcode=(string) preg_replace('/\./','_',$code);
427
+		}
407 428
 			//print 'xxx'.$code."=".$newcode."=".$type."=".$_POST[$newcode]."\n<br>";
408 429
 			$filterqualified=1;
409
-			if (! isset($_POST[$newcode]) || $_POST[$newcode] == '') $filterqualified=0;
410
-			elseif (preg_match('/^List/',$type) && (is_numeric($_POST[$newcode]) && $_POST[$newcode] <= 0)) $filterqualified=0;
430
+			if (! isset($_POST[$newcode]) || $_POST[$newcode] == '') {
431
+			    $filterqualified=0;
432
+			} elseif (preg_match('/^List/',$type) && (is_numeric($_POST[$newcode]) && $_POST[$newcode] <= 0)) {
433
+			    $filterqualified=0;
434
+			}
411 435
 			if ($filterqualified)
412 436
 			{
413 437
 				//print 'Filter on '.$newcode.' type='.$type.' value='.$_POST[$newcode]."\n";
@@ -477,15 +501,13 @@  discard block
 block discarded – undo
477 501
             if ($objexport->array_export_perms[$key])
478 502
             {
479 503
             	print '<a href="'.DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$objexport->array_export_code[$key].'">'.img_picto($langs->trans("NewExport"),'filenew').'</a>';
480
-            }
481
-            else
504
+            } else
482 505
             {
483 506
             	print $langs->trans("NotEnoughPermissions");
484 507
             }
485 508
            	print '</td></tr>';
486 509
         }
487
-    }
488
-    else
510
+    } else
489 511
     {
490 512
         print '<tr><td '.$bc[false].' colspan="3">'.$langs->trans("NoExportableData").'</td></tr>';
491 513
     }
@@ -553,8 +575,11 @@  discard block
 block discarded – undo
553 575
     print '<input type="hidden" name="datatoexport" value="'.$datatoexport.'">';
554 576
     print '<table><tr><td colspan="2">';
555 577
     print $langs->trans("SelectExportFields").' ';
556
-    if(empty($conf->global->EXPORTS_SHARE_MODELS))$htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1,$user->id);
557
-	else $htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1);
578
+    if(empty($conf->global->EXPORTS_SHARE_MODELS)) {
579
+        $htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1,$user->id);
580
+    } else {
581
+	    $htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1);
582
+	}
558 583
     print ' ';
559 584
     print '<input type="submit" class="button" value="'.$langs->trans("Select").'">';
560 585
     print '</td></tr></table>';
@@ -618,8 +643,7 @@  discard block
 block discarded – undo
618 643
         if (! empty($objexport->array_export_special[0][$code]))
619 644
         {
620 645
             $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
621
-        }
622
-        else
646
+        } else
623 647
         {
624 648
             $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
625 649
         }
@@ -642,8 +666,7 @@  discard block
 block discarded – undo
642 666
             print $form->textwithpicto($text,$htmltext);
643 667
 			//print ' ('.$code.')';
644 668
             print '</td>';
645
-        }
646
-        else
669
+        } else
647 670
         {
648 671
         	// Fields not selected
649 672
             print '<td>';
@@ -672,13 +695,11 @@  discard block
 block discarded – undo
672 695
 		if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
673 696
 		{
674 697
 			print '<a class="butAction" href="export.php?step=3&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
675
-		}
676
-		else
698
+		} else
677 699
 		{
678 700
 			print '<a class="butAction" href="export.php?step=4&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>';
679 701
 		}
680
-	}
681
-	else
702
+	} else
682 703
 	{
683 704
 		print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("SelectAtLeastOneField")).'">'.$langs->trans("NextStep").'</a>';
684 705
 	}
@@ -688,10 +709,12 @@  discard block
 block discarded – undo
688 709
 
689 710
 if ($step == 3 && $datatoexport)
690 711
 {
691
-    if (count($array_selected) < 1)      // This occurs when going back to page after sessecion expired
712
+    if (count($array_selected) < 1) {
713
+        // This occurs when going back to page after sessecion expired
692 714
     {
693 715
         // Switch to step 2
694 716
         header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
717
+    }
695 718
         exit;
696 719
     }
697 720
 
@@ -809,8 +832,7 @@  discard block
 block discarded – undo
809 832
 			if (! empty($objexport->array_export_special[0][$code]))
810 833
 		{
811 834
 		    $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
812
-		}
813
-		else
835
+		} else
814 836
 		{
815 837
 		    $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
816 838
 		}
@@ -829,15 +851,18 @@  discard block
 block discarded – undo
829 851
 
830 852
 		// Filter value
831 853
 		print '<td>';
832
-		if (! empty($Typefieldsarray[$code]))	// Example: Text, List:c_country:label:rowid, Number, Boolean
854
+		if (! empty($Typefieldsarray[$code])) {
855
+		    // Example: Text, List:c_country:label:rowid, Number, Boolean
833 856
 		{
834 857
 			$szInfoFiltre=$objexport->genDocFilter($Typefieldsarray[$code]);
835
-			if ($szInfoFiltre)	// Is there an info help for this filter ?
858
+		}
859
+			if ($szInfoFiltre) {
860
+			    // Is there an info help for this filter ?
836 861
 			{
837 862
 				$tmp=$objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
838
-				print $form->textwithpicto($tmp, $szInfoFiltre);
839 863
 			}
840
-			else
864
+				print $form->textwithpicto($tmp, $szInfoFiltre);
865
+			} else
841 866
 			{
842 867
 				print $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
843 868
 			}
@@ -862,10 +887,12 @@  discard block
 block discarded – undo
862 887
 
863 888
 if ($step == 4 && $datatoexport)
864 889
 {
865
-    if (count($array_selected) < 1)     // This occurs when going back to page after sessecion expired
890
+    if (count($array_selected) < 1) {
891
+        // This occurs when going back to page after sessecion expired
866 892
     {
867 893
         // Switch to step 2
868 894
         header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
895
+    }
869 896
         exit;
870 897
     }
871 898
 
@@ -945,8 +972,11 @@  discard block
 block discarded – undo
945 972
     			if (isset($objexport->array_export_fields[0][$code]))
946 973
     			{
947 974
     				$list.=($list?', ':'');
948
-    				if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'');
949
-    				else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
975
+    				if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) {
976
+    				    $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'');
977
+    				} else {
978
+    				    $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
979
+    				}
950 980
     			}
951 981
     		}
952 982
     	}
@@ -1001,8 +1031,7 @@  discard block
 block discarded – undo
1001 1031
         if (! empty($objexport->array_export_special[0][$code]))
1002 1032
         {
1003 1033
             $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
1004
-        }
1005
-        else
1034
+        } else
1006 1035
         {
1007 1036
             $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
1008 1037
         }
@@ -1023,8 +1052,12 @@  discard block
 block discarded – undo
1023 1052
         print '<td align="right" width="100">';
1024 1053
         print $value.' ';
1025 1054
         print '</td><td align="center" width="20">';
1026
-        if ($value < count($array_selected)) print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=downfield&field='.$code.'">'.img_down().'</a>';
1027
-        if ($value > 1) print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=upfield&field='.$code.'">'.img_up().'</a>';
1055
+        if ($value < count($array_selected)) {
1056
+            print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=downfield&field='.$code.'">'.img_down().'</a>';
1057
+        }
1058
+        if ($value > 1) {
1059
+            print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=upfield&field='.$code.'">'.img_up().'</a>';
1060
+        }
1028 1061
         print '</td>';
1029 1062
 
1030 1063
         //print '<td>&nbsp;</td>';
@@ -1079,7 +1112,9 @@  discard block
 block discarded – undo
1079 1112
     	$sql = "SELECT rowid, label";
1080 1113
 		$sql.= " FROM ".MAIN_DB_PREFIX."export_model";
1081 1114
 		$sql.= " WHERE type = '".$datatoexport."'";
1082
-		if(empty($conf->global->EXPORTS_SHARE_MODELS))$sql.=" AND fk_user=".$user->id;
1115
+		if(empty($conf->global->EXPORTS_SHARE_MODELS)) {
1116
+		    $sql.=" AND fk_user=".$user->id;
1117
+		}
1083 1118
 		$sql.= " ORDER BY rowid";
1084 1119
 		$resql = $db->query($sql);
1085 1120
 		if ($resql)
@@ -1098,8 +1133,7 @@  discard block
 block discarded – undo
1098 1133
 				print '</tr>';
1099 1134
 				$i++;
1100 1135
 			}
1101
-		}
1102
-		else {
1136
+		} else {
1103 1137
 			dol_print_error($this->db);
1104 1138
 		}
1105 1139
 
@@ -1110,10 +1144,12 @@  discard block
 block discarded – undo
1110 1144
 
1111 1145
 if ($step == 5 && $datatoexport)
1112 1146
 {
1113
-    if (count($array_selected) < 1)      // This occurs when going back to page after sessecion expired
1147
+    if (count($array_selected) < 1) {
1148
+        // This occurs when going back to page after sessecion expired
1114 1149
     {
1115 1150
         // Switch to step 2
1116 1151
         header("Location: ".DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport);
1152
+    }
1117 1153
         exit;
1118 1154
     }
1119 1155
 
@@ -1205,8 +1241,11 @@  discard block
 block discarded – undo
1205 1241
     			if (isset($objexport->array_export_fields[0][$code]))
1206 1242
     			{
1207 1243
     				$list.=($list?', ':'');
1208
-    				if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'');
1209
-    				else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
1244
+    				if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) {
1245
+    				    $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'');
1246
+    				} else {
1247
+    				    $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
1248
+    				}
1210 1249
     			}
1211 1250
     		}
1212 1251
     	}
@@ -1266,7 +1305,9 @@  discard block
 block discarded – undo
1266 1305
 
1267 1306
 	print '<div class="fichecenter"><div class="fichehalfleft">';
1268 1307
 
1269
-    if (! is_dir($conf->export->dir_temp)) dol_mkdir($conf->export->dir_temp);
1308
+    if (! is_dir($conf->export->dir_temp)) {
1309
+        dol_mkdir($conf->export->dir_temp);
1310
+    }
1270 1311
 
1271 1312
     // Affiche liste des documents
1272 1313
     // NB: La fonction show_documents rescanne les modules qd genallowed=1, sinon prend $liste
@@ -1303,6 +1344,7 @@  discard block
 block discarded – undo
1303 1344
 	if (preg_match($regexstring,$newsql,$reg))
1304 1345
 	{
1305 1346
 		return $reg[1];   // The tablename
1347
+	} else {
1348
+	    return '';
1349
+	}
1306 1350
 	}
1307
-	else return '';
1308
-}
Please login to merge, or discard this patch.
Spacing   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -27,8 +27,8 @@  discard block
 block discarded – undo
27 27
 
28 28
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
29 29
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
30
-require DOL_BASE_PATH . '/main.inc.php';
31
-require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
30
+require DOL_BASE_PATH.'/main.inc.php';
31
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32 32
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33 33
 require_once DOL_DOCUMENT_ROOT.'/exports/class/export.class.php';
34 34
 require_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php';
@@ -125,153 +125,153 @@  discard block
 block discarded – undo
125 125
     'translation'  => 'Translation'
126 126
 );
127 127
 
128
-$array_selected=isset($_SESSION["export_selected_fields"])?$_SESSION["export_selected_fields"]:array();
129
-$array_filtervalue=isset($_SESSION["export_filtered_fields"])?$_SESSION["export_filtered_fields"]:array();
130
-$datatoexport=GETPOST("datatoexport","aZ09");
131
-$action=GETPOST('action','alpha');
132
-$confirm=GETPOST('confirm','alpha');
133
-$step=GETPOST("step","int")?GETPOST("step","int"):1;
134
-$export_name=GETPOST("export_name","alphanohtml");
135
-$hexa=GETPOST("hexa","alpha");
136
-$exportmodelid=GETPOST("exportmodelid","int");
137
-$field=GETPOST("field","alpa");
138
-
139
-$objexport=new Export($db);
140
-$objexport->load_arrays($user,$datatoexport);
141
-
142
-$objmodelexport=new ModeleExports($db);
128
+$array_selected = isset($_SESSION["export_selected_fields"]) ? $_SESSION["export_selected_fields"] : array();
129
+$array_filtervalue = isset($_SESSION["export_filtered_fields"]) ? $_SESSION["export_filtered_fields"] : array();
130
+$datatoexport = GETPOST("datatoexport", "aZ09");
131
+$action = GETPOST('action', 'alpha');
132
+$confirm = GETPOST('confirm', 'alpha');
133
+$step = GETPOST("step", "int") ?GETPOST("step", "int") : 1;
134
+$export_name = GETPOST("export_name", "alphanohtml");
135
+$hexa = GETPOST("hexa", "alpha");
136
+$exportmodelid = GETPOST("exportmodelid", "int");
137
+$field = GETPOST("field", "alpa");
138
+
139
+$objexport = new Export($db);
140
+$objexport->load_arrays($user, $datatoexport);
141
+
142
+$objmodelexport = new ModeleExports($db);
143 143
 $form = new Form($db);
144 144
 $htmlother = new FormOther($db);
145 145
 $formfile = new FormFile($db);
146
-$sqlusedforexport='';
146
+$sqlusedforexport = '';
147 147
 
148 148
 $upload_dir = $conf->export->dir_temp.'/'.$user->id;
149 149
 
150 150
 //$usefilters=($conf->global->MAIN_FEATURES_LEVEL > 1);
151
-$usefilters=1;
151
+$usefilters = 1;
152 152
 
153 153
 
154 154
 /*
155 155
  * Actions
156 156
  */
157 157
 
158
-if ($action=='selectfield')     // Selection of field at step 2
158
+if ($action == 'selectfield')     // Selection of field at step 2
159 159
 {
160
-	$fieldsarray=$objexport->array_export_fields[0];
161
-	$fieldsentitiesarray=$objexport->array_export_entities[0];
162
-    $fieldsdependenciesarray=$objexport->array_export_dependencies[0];
160
+	$fieldsarray = $objexport->array_export_fields[0];
161
+	$fieldsentitiesarray = $objexport->array_export_entities[0];
162
+    $fieldsdependenciesarray = $objexport->array_export_dependencies[0];
163 163
 
164
-    if ($field=='all')
164
+    if ($field == 'all')
165 165
     {
166
-		foreach($fieldsarray as $key=>$val)
166
+		foreach ($fieldsarray as $key=>$val)
167 167
 		{
168
-			if (! empty($array_selected[$key])) continue;		// If already selected, check next
169
-			$array_selected[$key]=count($array_selected)+1;
168
+			if (!empty($array_selected[$key])) continue; // If already selected, check next
169
+			$array_selected[$key] = count($array_selected) + 1;
170 170
 		    //print_r($array_selected);
171
-		    $_SESSION["export_selected_fields"]=$array_selected;
171
+		    $_SESSION["export_selected_fields"] = $array_selected;
172 172
 		}
173 173
     }
174 174
     else
175 175
     {
176
-        $warnings=array();
176
+        $warnings = array();
177 177
 
178
-        $array_selected[$field]=count($array_selected)+1;    // We tag the key $field as "selected"
178
+        $array_selected[$field] = count($array_selected) + 1; // We tag the key $field as "selected"
179 179
         // We check if there is a dependency to activate
180 180
         /*var_dump($field);
181 181
         var_dump($fieldsentitiesarray[$field]);
182 182
         var_dump($fieldsdependenciesarray);*/
183
-        $listofdependencies=array();
184
-        if (! empty($fieldsentitiesarray[$field]) && ! empty($fieldsdependenciesarray[$fieldsentitiesarray[$field]]))
183
+        $listofdependencies = array();
184
+        if (!empty($fieldsentitiesarray[$field]) && !empty($fieldsdependenciesarray[$fieldsentitiesarray[$field]]))
185 185
         {
186 186
             // We found a dependency on the type of field
187
-            $tmp=$fieldsdependenciesarray[$fieldsentitiesarray[$field]]; // $fieldsdependenciesarray=array('element'=>'fd.rowid') or array('element'=>array('fd.rowid','ab.rowid'))
188
-            if (is_array($tmp)) $listofdependencies=$tmp;
189
-            else $listofdependencies=array($tmp);
187
+            $tmp = $fieldsdependenciesarray[$fieldsentitiesarray[$field]]; // $fieldsdependenciesarray=array('element'=>'fd.rowid') or array('element'=>array('fd.rowid','ab.rowid'))
188
+            if (is_array($tmp)) $listofdependencies = $tmp;
189
+            else $listofdependencies = array($tmp);
190 190
         }
191
-        else if (! empty($field) && ! empty($fieldsdependenciesarray[$field]))
191
+        else if (!empty($field) && !empty($fieldsdependenciesarray[$field]))
192 192
         {
193 193
             // We found a dependency on a dedicated field
194
-            $tmp=$fieldsdependenciesarray[$field]; // $fieldsdependenciesarray=array('fd.fieldx'=>'fd.rowid') or array('fd.fieldx'=>array('fd.rowid','ab.rowid'))
195
-            if (is_array($tmp)) $listofdependencies=$tmp;
196
-            else $listofdependencies=array($tmp);
194
+            $tmp = $fieldsdependenciesarray[$field]; // $fieldsdependenciesarray=array('fd.fieldx'=>'fd.rowid') or array('fd.fieldx'=>array('fd.rowid','ab.rowid'))
195
+            if (is_array($tmp)) $listofdependencies = $tmp;
196
+            else $listofdependencies = array($tmp);
197 197
         }
198 198
 
199 199
         if (count($listofdependencies))
200 200
         {
201
-            foreach($listofdependencies as $fieldid)
201
+            foreach ($listofdependencies as $fieldid)
202 202
             {
203 203
                 if (empty($array_selected[$fieldid]))
204 204
                 {
205
-                    $array_selected[$fieldid]=count($array_selected)+1;    // We tag the key $fieldid as "selected"
206
-                    $warnings[]=$langs->trans("ExportFieldAutomaticallyAdded",$langs->transnoentitiesnoconv($fieldsarray[$fieldid]));
205
+                    $array_selected[$fieldid] = count($array_selected) + 1; // We tag the key $fieldid as "selected"
206
+                    $warnings[] = $langs->trans("ExportFieldAutomaticallyAdded", $langs->transnoentitiesnoconv($fieldsarray[$fieldid]));
207 207
                 }
208 208
             }
209 209
         }
210 210
 	    //print_r($array_selected);
211
-	    $_SESSION["export_selected_fields"]=$array_selected;
211
+	    $_SESSION["export_selected_fields"] = $array_selected;
212 212
 
213 213
 	    setEventMessages($warnings, null, 'warnings');
214 214
     }
215 215
 }
216
-if ($action=='unselectfield')
216
+if ($action == 'unselectfield')
217 217
 {
218
-    if ($_GET["field"]=='all')
218
+    if ($_GET["field"] == 'all')
219 219
     {
220
-		$array_selected=array();
221
-		$_SESSION["export_selected_fields"]=$array_selected;
220
+		$array_selected = array();
221
+		$_SESSION["export_selected_fields"] = $array_selected;
222 222
     }
223 223
     else
224 224
     {
225 225
 	    unset($array_selected[$_GET["field"]]);
226 226
 	    // Renumber fields of array_selected (from 1 to nb_elements)
227 227
 	    asort($array_selected);
228
-	    $i=0;
229
-	    $array_selected_save=$array_selected;
230
-	    foreach($array_selected as $code=>$value)
228
+	    $i = 0;
229
+	    $array_selected_save = $array_selected;
230
+	    foreach ($array_selected as $code=>$value)
231 231
 	    {
232 232
 	        $i++;
233
-	        $array_selected[$code]=$i;
233
+	        $array_selected[$code] = $i;
234 234
 	        //print "x $code x $i y<br>";
235 235
 	    }
236
-	    $_SESSION["export_selected_fields"]=$array_selected;
236
+	    $_SESSION["export_selected_fields"] = $array_selected;
237 237
     }
238 238
 }
239 239
 
240
-if ($action=='downfield' || $action=='upfield')
240
+if ($action == 'downfield' || $action == 'upfield')
241 241
 {
242
-    $pos=$array_selected[$_GET["field"]];
243
-    if ($action=='downfield') $newpos=$pos+1;
244
-    if ($action=='upfield') $newpos=$pos-1;
242
+    $pos = $array_selected[$_GET["field"]];
243
+    if ($action == 'downfield') $newpos = $pos + 1;
244
+    if ($action == 'upfield') $newpos = $pos - 1;
245 245
     // Recherche code avec qui switcher
246
-    $newcode="";
247
-    foreach($array_selected as $code=>$value)
246
+    $newcode = "";
247
+    foreach ($array_selected as $code=>$value)
248 248
     {
249 249
         if ($value == $newpos)
250 250
         {
251
-            $newcode=$code;
251
+            $newcode = $code;
252 252
             break;
253 253
         }
254 254
     }
255 255
     //print("Switch pos=$pos (code=".$_GET["field"].") and newpos=$newpos (code=$newcode)");
256 256
     if ($newcode)   // Si newcode trouve (protection contre resoumission de page)
257 257
     {
258
-        $array_selected[$_GET["field"]]=$newpos;
259
-        $array_selected[$newcode]=$pos;
260
-        $_SESSION["export_selected_fields"]=$array_selected;
258
+        $array_selected[$_GET["field"]] = $newpos;
259
+        $array_selected[$newcode] = $pos;
260
+        $_SESSION["export_selected_fields"] = $array_selected;
261 261
     }
262 262
 }
263 263
 
264 264
 if ($step == 1 || $action == 'cleanselect')
265 265
 {
266
-    $_SESSION["export_selected_fields"]=array();
267
-    $_SESSION["export_filtered_fields"]=array();
268
-    $array_selected=array();
269
-    $array_filtervalue=array();
266
+    $_SESSION["export_selected_fields"] = array();
267
+    $_SESSION["export_filtered_fields"] = array();
268
+    $array_selected = array();
269
+    $array_filtervalue = array();
270 270
 }
271 271
 
272 272
 if ($action == 'builddoc')
273 273
 {
274
-    $max_execution_time_for_export = (empty($conf->global->EXPORT_MAX_EXECUTION_TIME)?300:$conf->global->EXPORT_MAX_EXECUTION_TIME);    // 5mn if not defined
274
+    $max_execution_time_for_export = (empty($conf->global->EXPORT_MAX_EXECUTION_TIME) ? 300 : $conf->global->EXPORT_MAX_EXECUTION_TIME); // 5mn if not defined
275 275
     $max_time = @ini_get("max_execution_time");
276 276
     if ($max_time && $max_time < $max_execution_time_for_export)
277 277
     {
@@ -279,25 +279,25 @@  discard block
 block discarded – undo
279 279
     }
280 280
 
281 281
     // Build export file
282
-	$result=$objexport->build_file($user, GETPOST('model','alpha'), $datatoexport, $array_selected, $array_filtervalue);
282
+	$result = $objexport->build_file($user, GETPOST('model', 'alpha'), $datatoexport, $array_selected, $array_filtervalue);
283 283
 	if ($result < 0)
284 284
 	{
285 285
 		setEventMessages($objexport->error, $objexport->errors, 'errors');
286
-		$sqlusedforexport=$objexport->sqlusedforexport;
286
+		$sqlusedforexport = $objexport->sqlusedforexport;
287 287
 	}
288 288
 	else
289 289
 	{
290 290
 		setEventMessages($langs->trans("FileSuccessfullyBuilt"), null, 'mesgs');
291
-	    $sqlusedforexport=$objexport->sqlusedforexport;
291
+	    $sqlusedforexport = $objexport->sqlusedforexport;
292 292
     }
293 293
 }
294 294
 
295 295
 // Delete file
296 296
 if ($step == 5 && $action == 'confirm_deletefile' && $confirm == 'yes')
297 297
 {
298
-	$file = $upload_dir . "/" . GETPOST('file');	// Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
298
+	$file = $upload_dir."/".GETPOST('file'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
299 299
 
300
-	$ret=dol_delete_file($file);
300
+	$ret = dol_delete_file($file);
301 301
 	if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
302 302
 	else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
303 303
 	header('Location: '.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport);
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 	if ($_GET["id"])
310 310
 	{
311 311
 		$objexport->fetch($_GET["id"]);
312
-		$result=$objexport->delete($user);
312
+		$result = $objexport->delete($user);
313 313
 	}
314 314
 }
315 315
 
@@ -321,20 +321,20 @@  discard block
 block discarded – undo
321 321
 		asort($array_selected);
322 322
 
323 323
 		// Set save string
324
-		$hexa='';
325
-		foreach($array_selected as $key=>$val)
324
+		$hexa = '';
325
+		foreach ($array_selected as $key=>$val)
326 326
 		{
327
-			if ($hexa) $hexa.=',';
328
-			$hexa.=$key;
327
+			if ($hexa) $hexa .= ',';
328
+			$hexa .= $key;
329 329
 		}
330 330
 
331
-		$hexafiltervalue='';
332
-		if (! empty($array_filtervalue) && is_array($array_filtervalue))
331
+		$hexafiltervalue = '';
332
+		if (!empty($array_filtervalue) && is_array($array_filtervalue))
333 333
 		{
334
-			foreach($array_filtervalue as $key=>$val)
334
+			foreach ($array_filtervalue as $key=>$val)
335 335
 			{
336
-				if ($hexafiltervalue) $hexafiltervalue.=',';
337
-				$hexafiltervalue.=$key.'='.$val;
336
+				if ($hexafiltervalue) $hexafiltervalue .= ',';
337
+				$hexafiltervalue .= $key.'='.$val;
338 338
 			}
339 339
 		}
340 340
 
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 	    $result = $objexport->create($user);
347 347
 		if ($result >= 0)
348 348
 		{
349
-			setEventMessages($langs->trans("ExportModelSaved",$objexport->model_name), null, 'mesgs');
349
+			setEventMessages($langs->trans("ExportModelSaved", $objexport->model_name), null, 'mesgs');
350 350
 		}
351 351
 		else
352 352
 		{
@@ -366,33 +366,33 @@  discard block
 block discarded – undo
366 366
 // Reload an predefined export model
367 367
 if ($step == 2 && $action == 'select_model')
368 368
 {
369
-    $_SESSION["export_selected_fields"]=array();
370
-    $_SESSION["export_filtered_fields"]=array();
369
+    $_SESSION["export_selected_fields"] = array();
370
+    $_SESSION["export_filtered_fields"] = array();
371 371
 
372
-    $array_selected=array();
373
-    $array_filtervalue=array();
372
+    $array_selected = array();
373
+    $array_filtervalue = array();
374 374
 
375 375
     $result = $objexport->fetch($exportmodelid);
376 376
     if ($result > 0)
377 377
     {
378
-		$fieldsarray=explode(',',$objexport->hexa);
379
-		$i=1;
380
-		foreach($fieldsarray as $val)
378
+		$fieldsarray = explode(',', $objexport->hexa);
379
+		$i = 1;
380
+		foreach ($fieldsarray as $val)
381 381
 		{
382
-			$array_selected[$val]=$i;
382
+			$array_selected[$val] = $i;
383 383
 			$i++;
384 384
 		}
385
-		$_SESSION["export_selected_fields"]=$array_selected;
385
+		$_SESSION["export_selected_fields"] = $array_selected;
386 386
 
387
-		$fieldsarrayvalue=explode(',',$objexport->hexafiltervalue);
388
-		$i=1;
389
-		foreach($fieldsarrayvalue as $val)
387
+		$fieldsarrayvalue = explode(',', $objexport->hexafiltervalue);
388
+		$i = 1;
389
+		foreach ($fieldsarrayvalue as $val)
390 390
 		{
391
-			$tmp=explode('=',$val);
392
-			$array_filtervalue[$tmp[0]]=$tmp[1];
391
+			$tmp = explode('=', $val);
392
+			$array_filtervalue[$tmp[0]] = $tmp[1];
393 393
 			$i++;
394 394
 		}
395
-		$_SESSION["export_filtered_fields"]=$array_filtervalue;
395
+		$_SESSION["export_filtered_fields"] = $array_filtervalue;
396 396
     }
397 397
 }
398 398
 
@@ -402,22 +402,22 @@  discard block
 block discarded – undo
402 402
 	// on boucle sur les champs selectionne pour recuperer la valeur
403 403
 	if (is_array($objexport->array_export_TypeFields[0]))
404 404
 	{
405
-		$_SESSION["export_filtered_fields"]=array();
406
-		foreach($objexport->array_export_TypeFields[0] as $code => $type)	// $code: s.fieldname $value: Text|Boolean|List:ccc
405
+		$_SESSION["export_filtered_fields"] = array();
406
+		foreach ($objexport->array_export_TypeFields[0] as $code => $type)	// $code: s.fieldname $value: Text|Boolean|List:ccc
407 407
 		{
408
-			$newcode=(string) preg_replace('/\./','_',$code);
408
+			$newcode = (string) preg_replace('/\./', '_', $code);
409 409
 			//print 'xxx'.$code."=".$newcode."=".$type."=".$_POST[$newcode]."\n<br>";
410
-			$filterqualified=1;
411
-			if (! isset($_POST[$newcode]) || $_POST[$newcode] == '') $filterqualified=0;
412
-			elseif (preg_match('/^List/',$type) && (is_numeric($_POST[$newcode]) && $_POST[$newcode] <= 0)) $filterqualified=0;
410
+			$filterqualified = 1;
411
+			if (!isset($_POST[$newcode]) || $_POST[$newcode] == '') $filterqualified = 0;
412
+			elseif (preg_match('/^List/', $type) && (is_numeric($_POST[$newcode]) && $_POST[$newcode] <= 0)) $filterqualified = 0;
413 413
 			if ($filterqualified)
414 414
 			{
415 415
 				//print 'Filter on '.$newcode.' type='.$type.' value='.$_POST[$newcode]."\n";
416 416
 				$objexport->array_export_FilterValue[0][$code] = $_POST[$newcode];
417 417
 			}
418 418
 		}
419
-		$array_filtervalue=(! empty($objexport->array_export_FilterValue[0])?$objexport->array_export_FilterValue[0]:'');
420
-		$_SESSION["export_filtered_fields"]=$array_filtervalue;
419
+		$array_filtervalue = (!empty($objexport->array_export_FilterValue[0]) ? $objexport->array_export_FilterValue[0] : '');
420
+		$_SESSION["export_filtered_fields"] = $array_filtervalue;
421 421
 	}
422 422
 }
423 423
 
@@ -426,9 +426,9 @@  discard block
 block discarded – undo
426 426
  * View
427 427
  */
428 428
 
429
-if ($step == 1 || ! $datatoexport)
429
+if ($step == 1 || !$datatoexport)
430 430
 {
431
-    llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
431
+    llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
432 432
 
433 433
     /*
434 434
      * Affichage onglets
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 
438 438
     $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
439 439
     $head[$h][1] = $langs->trans("Step")." 1";
440
-    $hselected=$h;
440
+    $hselected = $h;
441 441
     $h++;
442 442
 
443 443
     /*
@@ -460,25 +460,25 @@  discard block
 block discarded – undo
460 460
     print '<td>'.$langs->trans("ExportableDatas").'</td>';
461 461
     print '<td>&nbsp;</td>';
462 462
     print '</tr>';
463
-    $val=true;
463
+    $val = true;
464 464
     if (count($objexport->array_export_code))
465 465
     {
466 466
         foreach ($objexport->array_export_code as $key => $value)
467 467
         {
468
-            $val=!$val;
468
+            $val = !$val;
469 469
             print '<tr '.$bc[$val].'><td nospan="nospan">';
470 470
 	        //print img_object($objexport->array_export_module[$key]->getName(),$export->array_export_module[$key]->picto).' ';
471 471
             print $objexport->array_export_module[$key]->getName();
472 472
             print '</td><td>';
473
-			$icon=preg_replace('/:.*$/','',$objexport->array_export_icon[$key]);
474
-			$label=$objexport->array_export_label[$key];
473
+			$icon = preg_replace('/:.*$/', '', $objexport->array_export_icon[$key]);
474
+			$label = $objexport->array_export_label[$key];
475 475
             //print $value.'-'.$icon.'-'.$label."<br>";
476 476
 			print img_object($objexport->array_export_module[$key]->getName(), $icon).' ';
477 477
             print $label;
478 478
             print '</td><td align="right">';
479 479
             if ($objexport->array_export_perms[$key])
480 480
             {
481
-            	print '<a href="'.DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$objexport->array_export_code[$key].'">'.img_picto($langs->trans("NewExport"),'filenew').'</a>';
481
+            	print '<a href="'.DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$objexport->array_export_code[$key].'">'.img_picto($langs->trans("NewExport"), 'filenew').'</a>';
482 482
             }
483 483
             else
484 484
             {
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 
501 501
 if ($step == 2 && $datatoexport)
502 502
 {
503
-    llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
503
+    llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
504 504
 
505 505
 
506 506
     /*
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 
515 515
     $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport;
516 516
     $head[$h][1] = $langs->trans("Step")." 2";
517
-    $hselected=$h;
517
+    $hselected = $h;
518 518
     $h++;
519 519
 
520 520
     dol_fiche_head($head, $hselected, $langs->trans("NewExport"), -1);
@@ -533,8 +533,8 @@  discard block
 block discarded – undo
533 533
     // Lot de donnees a exporter
534 534
     print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
535 535
     print '<td>';
536
-	$icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
537
-    $label=$objexport->array_export_label[0];
536
+	$icon = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
537
+    $label = $objexport->array_export_label[0];
538 538
     //print $value.'-'.$icon.'-'.$label."<br>";
539 539
     print img_object($objexport->array_export_module[0]->getName(), $icon).' ';
540 540
     print $label;
@@ -555,8 +555,8 @@  discard block
 block discarded – undo
555 555
     print '<input type="hidden" name="datatoexport" value="'.$datatoexport.'">';
556 556
     print '<table><tr><td colspan="2">';
557 557
     print $langs->trans("SelectExportFields").' ';
558
-    if(empty($conf->global->EXPORTS_SHARE_MODELS))$htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1,$user->id);
559
-	else $htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1);
558
+    if (empty($conf->global->EXPORTS_SHARE_MODELS))$htmlother->select_export_model($exportmodelid, 'exportmodelid', $datatoexport, 1, $user->id);
559
+	else $htmlother->select_export_model($exportmodelid, 'exportmodelid', $datatoexport, 1);
560 560
     print ' ';
561 561
     print '<input type="submit" class="button" value="'.$langs->trans("Select").'">';
562 562
     print '</td></tr></table>';
@@ -576,9 +576,9 @@  discard block
 block discarded – undo
576 576
     print '</tr>';
577 577
 
578 578
     // Champs exportables
579
-    $fieldsarray=$objexport->array_export_fields[0];
579
+    $fieldsarray = $objexport->array_export_fields[0];
580 580
     // Select request if all fields are selected
581
-    $sqlmaxforexport=$objexport->build_sql(0, array(), array());
581
+    $sqlmaxforexport = $objexport->build_sql(0, array(), array());
582 582
 
583 583
 	//    $this->array_export_module[0]=$module;
584 584
 	//    $this->array_export_code[0]=$module->export_code[$r];
@@ -590,48 +590,48 @@  discard block
 block discarded – undo
590 590
 
591 591
     $i = 0;
592 592
 
593
-    foreach($fieldsarray as $code=>$label)
593
+    foreach ($fieldsarray as $code=>$label)
594 594
     {
595 595
         print '<tr class="oddeven">';
596 596
 
597 597
         $i++;
598 598
 
599
-        $entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]);
600
-        $entityicon=strtolower(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
601
-        $entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity);
599
+        $entity = (!empty($objexport->array_export_entities[0][$code]) ? $objexport->array_export_entities[0][$code] : $objexport->array_export_icon[0]);
600
+        $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
601
+        $entitylang = (!empty($entitytolang[$entity]) ? $entitytolang[$entity] : $entity);
602 602
 
603 603
         print '<td class="nowrap">';
604 604
         // If value of entityicon=entitylang='icon:Label'
605 605
         //print $code.'-'.$label.'-'.$entity;
606 606
 
607
-        $tmparray=explode(':',$entityicon);
608
-        if (count($tmparray) >=2)
607
+        $tmparray = explode(':', $entityicon);
608
+        if (count($tmparray) >= 2)
609 609
         {
610
-            $entityicon=$tmparray[0];
611
-            $entitylang=$tmparray[1];
610
+            $entityicon = $tmparray[0];
611
+            $entitylang = $tmparray[1];
612 612
         }
613
-        print img_object('',$entityicon).' '.$langs->trans($entitylang);
613
+        print img_object('', $entityicon).' '.$langs->trans($entitylang);
614 614
         print '</td>';
615 615
 
616
-        $text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($label).(empty($objexport->array_export_special[0][$code])?'':'</i>');
616
+        $text = (empty($objexport->array_export_special[0][$code]) ? '' : '<i>').$langs->trans($label).(empty($objexport->array_export_special[0][$code]) ? '' : '</i>');
617 617
 
618
-        $tablename=getablenamefromfield($code,$sqlmaxforexport);
619
-        $htmltext ='<b>'.$langs->trans("Name").":</b> ".$text.'<br>';
620
-        if (! empty($objexport->array_export_special[0][$code]))
618
+        $tablename = getablenamefromfield($code, $sqlmaxforexport);
619
+        $htmltext = '<b>'.$langs->trans("Name").":</b> ".$text.'<br>';
620
+        if (!empty($objexport->array_export_special[0][$code]))
621 621
         {
622
-            $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
622
+            $htmltext .= '<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
623 623
         }
624 624
         else
625 625
         {
626
-            $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
626
+            $htmltext .= '<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./', '', $code)."<br>";
627 627
         }
628
-   		if (! empty($objexport->array_export_examplevalues[0][$code]))
628
+   		if (!empty($objexport->array_export_examplevalues[0][$code]))
629 629
 		{
630
-		    $htmltext.='<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>';
630
+		    $htmltext .= '<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>';
631 631
 		}
632
-    	if (! empty($objexport->array_export_TypeFields[0][$code]))
632
+    	if (!empty($objexport->array_export_TypeFields[0][$code]))
633 633
 		{
634
-		    $htmltext.='<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>';
634
+		    $htmltext .= '<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>';
635 635
 		}
636 636
 
637 637
 		if (isset($array_selected[$code]) && $array_selected[$code])
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
             print '<td align="center"><a class="reposition" href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=unselectfield&field='.$code.'">'.img_left('default', 0, 'style="max-width: 20px"').'</a></td>';
642 642
             print '<td>';
643 643
             //print $text.'-'.$htmltext."<br>";
644
-            print $form->textwithpicto($text,$htmltext);
644
+            print $form->textwithpicto($text, $htmltext);
645 645
 			//print ' ('.$code.')';
646 646
             print '</td>';
647 647
         }
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
         	// Fields not selected
651 651
             print '<td>';
652 652
 			//print $text.'-'.$htmltext."<br>";
653
-			print $form->textwithpicto($text,$htmltext);
653
+			print $form->textwithpicto($text, $htmltext);
654 654
 			//print ' ('.$code.')';
655 655
             print '</td>';
656 656
             print '<td align="center"><a class="reposition" href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field='.$code.'">'.img_right('default', 0, 'style="max-width: 20px"').'</a></td>';
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
         exit;
698 698
     }
699 699
 
700
-    llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
700
+    llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
701 701
 
702 702
 	/*
703 703
 	 * Affichage onglets
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
 
715 715
 	$head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport;
716 716
 	$head[$h][1] = $langs->trans("Step")." 3";
717
-	$hselected=$h;
717
+	$hselected = $h;
718 718
 	$h++;
719 719
 
720 720
 	dol_fiche_head($head, $hselected, $langs->trans("NewExport"), -1);
@@ -733,8 +733,8 @@  discard block
 block discarded – undo
733 733
 	// Lot de donnees a exporter
734 734
 	print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
735 735
 	print '<td>';
736
-	$icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
737
-	$label=$objexport->array_export_label[0];
736
+	$icon = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
737
+	$label = $objexport->array_export_label[0];
738 738
 	//print $value.'-'.$icon.'-'.$label."<br>";
739 739
 	print img_object($objexport->array_export_module[0]->getName(), $icon).' ';
740 740
 	print $label;
@@ -742,11 +742,11 @@  discard block
 block discarded – undo
742 742
 
743 743
 	// Nbre champs exportes
744 744
 	print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
745
-	$list='';
746
-	foreach($array_selected as $code=>$value)
745
+	$list = '';
746
+	foreach ($array_selected as $code=>$value)
747 747
 	{
748
-		$list.=(! empty($list)?', ':'');
749
-		$list.=(isset($objexport->array_export_fields[0][$code])?$langs->trans($objexport->array_export_fields[0][$code]):'');
748
+		$list .= (!empty($list) ? ', ' : '');
749
+		$list .= (isset($objexport->array_export_fields[0][$code]) ? $langs->trans($objexport->array_export_fields[0][$code]) : '');
750 750
 	}
751 751
 	print '<td>'.$list.'</td></tr>';
752 752
 
@@ -771,72 +771,72 @@  discard block
 block discarded – undo
771 771
 	print '</tr>';
772 772
 
773 773
 	// Champs exportables
774
-	$fieldsarray=$objexport->array_export_fields[0];
774
+	$fieldsarray = $objexport->array_export_fields[0];
775 775
 	// Champs filtrable
776
-	$Typefieldsarray=$objexport->array_export_TypeFields[0];
776
+	$Typefieldsarray = $objexport->array_export_TypeFields[0];
777 777
 	// valeur des filtres
778
-	$ValueFiltersarray=(! empty($objexport->array_export_FilterValue[0])?$objexport->array_export_FilterValue[0]:'');
778
+	$ValueFiltersarray = (!empty($objexport->array_export_FilterValue[0]) ? $objexport->array_export_FilterValue[0] : '');
779 779
 	// Select request if all fields are selected
780
-	$sqlmaxforexport=$objexport->build_sql(0, array(), array());
780
+	$sqlmaxforexport = $objexport->build_sql(0, array(), array());
781 781
 
782 782
 	$i = 0;
783 783
 	// on boucle sur les champs
784
-	foreach($fieldsarray as $code => $label)
784
+	foreach ($fieldsarray as $code => $label)
785 785
 	{
786 786
 		print '<tr class="oddeven">';
787 787
 
788 788
 		$i++;
789
-		$entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]);
790
-		$entityicon=strtolower(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
791
-		$entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity);
789
+		$entity = (!empty($objexport->array_export_entities[0][$code]) ? $objexport->array_export_entities[0][$code] : $objexport->array_export_icon[0]);
790
+		$entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
791
+		$entitylang = (!empty($entitytolang[$entity]) ? $entitytolang[$entity] : $entity);
792 792
 
793 793
 		print '<td class="nowrap">';
794 794
 		// If value of entityicon=entitylang='icon:Label'
795
-		$tmparray=explode(':',$entityicon);
796
-		if (count($tmparray) >=2)
795
+		$tmparray = explode(':', $entityicon);
796
+		if (count($tmparray) >= 2)
797 797
 		{
798
-			$entityicon=$tmparray[0];
799
-			$entitylang=$tmparray[1];
798
+			$entityicon = $tmparray[0];
799
+			$entitylang = $tmparray[1];
800 800
 		}
801
-		print img_object('',$entityicon).' '.$langs->trans($entitylang);
801
+		print img_object('', $entityicon).' '.$langs->trans($entitylang);
802 802
 		print '</td>';
803 803
 
804 804
 		// Field name
805
-		$labelName=(! empty($fieldsarray[$code])?$fieldsarray[$code]:'');
806
-		$ValueFilter=(! empty($array_filtervalue[$code])?$array_filtervalue[$code]:'');
807
-		$text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code])?'':'</i>');
805
+		$labelName = (!empty($fieldsarray[$code]) ? $fieldsarray[$code] : '');
806
+		$ValueFilter = (!empty($array_filtervalue[$code]) ? $array_filtervalue[$code] : '');
807
+		$text = (empty($objexport->array_export_special[0][$code]) ? '' : '<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code]) ? '' : '</i>');
808 808
 
809
-		$tablename=getablenamefromfield($code,$sqlmaxforexport);
810
-		$htmltext ='<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
811
-			if (! empty($objexport->array_export_special[0][$code]))
809
+		$tablename = getablenamefromfield($code, $sqlmaxforexport);
810
+		$htmltext = '<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
811
+			if (!empty($objexport->array_export_special[0][$code]))
812 812
 		{
813
-		    $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
813
+		    $htmltext .= '<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
814 814
 		}
815 815
 		else
816 816
 		{
817
-		    $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
817
+		    $htmltext .= '<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./', '', $code)."<br>";
818 818
 		}
819
-		if (! empty($objexport->array_export_examplevalues[0][$code]))
819
+		if (!empty($objexport->array_export_examplevalues[0][$code]))
820 820
 		{
821
-		    $htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
821
+		    $htmltext .= $langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
822 822
 		}
823
-		if (! empty($objexport->array_export_TypeFields[0][$code]))
823
+		if (!empty($objexport->array_export_TypeFields[0][$code]))
824 824
 		{
825
-		    $htmltext.=$langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>';
825
+		    $htmltext .= $langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>';
826 826
 		}
827 827
 
828 828
 		print '<td>';
829
-		print $form->textwithpicto($text,$htmltext);
829
+		print $form->textwithpicto($text, $htmltext);
830 830
 		print '</td>';
831 831
 
832 832
 		// Filter value
833 833
 		print '<td>';
834
-		if (! empty($Typefieldsarray[$code]))	// Example: Text, List:c_country:label:rowid, Number, Boolean
834
+		if (!empty($Typefieldsarray[$code]))	// Example: Text, List:c_country:label:rowid, Number, Boolean
835 835
 		{
836
-			$szInfoFiltre=$objexport->genDocFilter($Typefieldsarray[$code]);
836
+			$szInfoFiltre = $objexport->genDocFilter($Typefieldsarray[$code]);
837 837
 			if ($szInfoFiltre)	// Is there an info help for this filter ?
838 838
 			{
839
-				$tmp=$objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
839
+				$tmp = $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter);
840 840
 				print $form->textwithpicto($tmp, $szInfoFiltre);
841 841
 			}
842 842
 			else
@@ -873,12 +873,12 @@  discard block
 block discarded – undo
873 873
 
874 874
     asort($array_selected);
875 875
 
876
-    llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
876
+    llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
877 877
 
878 878
     /*
879 879
      * Affichage onglets
880 880
      */
881
-    $stepoffset=0;
881
+    $stepoffset = 0;
882 882
     $h = 0;
883 883
 
884 884
     $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
@@ -899,8 +899,8 @@  discard block
 block discarded – undo
899 899
     }
900 900
 
901 901
     $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
902
-    $head[$h][1] = $langs->trans("Step")." ".(3+$stepoffset);
903
-    $hselected=$h;
902
+    $head[$h][1] = $langs->trans("Step")." ".(3 + $stepoffset);
903
+    $hselected = $h;
904 904
     $h++;
905 905
 
906 906
     dol_fiche_head($head, $hselected, $langs->trans("NewExport"), -1);
@@ -919,18 +919,18 @@  discard block
 block discarded – undo
919 919
     // Lot de donnees a exporter
920 920
     print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
921 921
     print '<td>';
922
-	$icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
922
+	$icon = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
923 923
     print img_object($objexport->array_export_module[0]->getName(), $icon).' ';
924 924
     print $objexport->array_export_label[0];
925 925
     print '</td></tr>';
926 926
 
927 927
     // List of exported fields
928 928
     print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
929
-    $list='';
930
-    foreach($array_selected as $code=>$value)
929
+    $list = '';
930
+    foreach ($array_selected as $code=>$value)
931 931
     {
932
-        $list.=(! empty($list)?', ':'');
933
-        $list.=$langs->trans($objexport->array_export_fields[0][$code]);
932
+        $list .= (!empty($list) ? ', ' : '');
933
+        $list .= $langs->trans($objexport->array_export_fields[0][$code]);
934 934
     }
935 935
     print '<td>'.$list.'</td>';
936 936
     print '</tr>';
@@ -939,20 +939,20 @@  discard block
 block discarded – undo
939 939
     if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
940 940
     {
941 941
     	print '<tr><td width="25%">'.$langs->trans("FilteredFields").'</td>';
942
-    	$list='';
943
-    	if (! empty($array_filtervalue))
942
+    	$list = '';
943
+    	if (!empty($array_filtervalue))
944 944
     	{
945
-    		foreach($array_filtervalue as $code=>$value)
945
+    		foreach ($array_filtervalue as $code=>$value)
946 946
     		{
947 947
     			if (isset($objexport->array_export_fields[0][$code]))
948 948
     			{
949
-    				$list.=($list?', ':'');
950
-    				if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'');
951
-    				else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
949
+    				$list .= ($list ? ', ' : '');
950
+    				if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/', $array_filtervalue[$code])) $list .= $langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '');
951
+    				else $list .= $langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '')."'";
952 952
     			}
953 953
     		}
954 954
     	}
955
-    	print '<td>'.(! empty($list)?$list:$langs->trans("None")).'</td>';
955
+    	print '<td>'.(!empty($list) ? $list : $langs->trans("None")).'</td>';
956 956
     	print '</tr>';
957 957
     }
958 958
 
@@ -962,7 +962,7 @@  discard block
 block discarded – undo
962 962
     print '<br>';
963 963
 
964 964
     // Select request if all fields are selected
965
-    $sqlmaxforexport=$objexport->build_sql(0, array(), array());
965
+    $sqlmaxforexport = $objexport->build_sql(0, array(), array());
966 966
 
967 967
     print $langs->trans("ChooseFieldsOrdersAndTitle").'<br>';
968 968
 
@@ -975,50 +975,50 @@  discard block
 block discarded – undo
975 975
     //print '<td>'.$langs->trans("FieldsTitle").'</td>';
976 976
     print '</tr>';
977 977
 
978
-    foreach($array_selected as $code=>$value)
978
+    foreach ($array_selected as $code=>$value)
979 979
     {
980 980
         print '<tr class="oddeven">';
981 981
 
982
-        $entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]);
983
-        $entityicon=strtolower(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity);
984
-        $entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity);
982
+        $entity = (!empty($objexport->array_export_entities[0][$code]) ? $objexport->array_export_entities[0][$code] : $objexport->array_export_icon[0]);
983
+        $entityicon = strtolower(!empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity);
984
+        $entitylang = (!empty($entitytolang[$entity]) ? $entitytolang[$entity] : $entity);
985 985
 
986 986
         print '<td class="nowrap">';
987 987
         // If value of entityicon=entitylang='icon:Label'
988
-        $tmparray=explode(':',$entityicon);
989
-        if (count($tmparray) >=2)
988
+        $tmparray = explode(':', $entityicon);
989
+        if (count($tmparray) >= 2)
990 990
         {
991
-            $entityicon=$tmparray[0];
992
-            $entitylang=$tmparray[1];
991
+            $entityicon = $tmparray[0];
992
+            $entitylang = $tmparray[1];
993 993
         }
994
-        print img_object('',$entityicon).' '.$langs->trans($entitylang);
994
+        print img_object('', $entityicon).' '.$langs->trans($entitylang);
995 995
         print '</td>';
996 996
 
997
-        $labelName=$objexport->array_export_fields[0][$code];
997
+        $labelName = $objexport->array_export_fields[0][$code];
998 998
 
999
-		$text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code])?'':'</i>');
999
+		$text = (empty($objexport->array_export_special[0][$code]) ? '' : '<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code]) ? '' : '</i>');
1000 1000
 
1001
-        $tablename=getablenamefromfield($code,$sqlmaxforexport);
1002
-        $htmltext ='<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
1003
-        if (! empty($objexport->array_export_special[0][$code]))
1001
+        $tablename = getablenamefromfield($code, $sqlmaxforexport);
1002
+        $htmltext = '<b>'.$langs->trans("Name").':</b> '.$text.'<br>';
1003
+        if (!empty($objexport->array_export_special[0][$code]))
1004 1004
         {
1005
-            $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
1005
+            $htmltext .= '<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>";
1006 1006
         }
1007 1007
         else
1008 1008
         {
1009
-            $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>";
1009
+            $htmltext .= '<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./', '', $code)."<br>";
1010 1010
         }
1011
-        if (! empty($objexport->array_export_examplevalues[0][$code]))
1011
+        if (!empty($objexport->array_export_examplevalues[0][$code]))
1012 1012
         {
1013
-            $htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
1013
+            $htmltext .= $langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>';
1014 1014
         }
1015
-        if (! empty($objexport->array_export_TypeFields[0][$code]))
1015
+        if (!empty($objexport->array_export_TypeFields[0][$code]))
1016 1016
         {
1017
-            $htmltext.=$langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>';
1017
+            $htmltext .= $langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>';
1018 1018
         }
1019 1019
 
1020 1020
         print '<td>';
1021
-        print $form->textwithpicto($text,$htmltext);
1021
+        print $form->textwithpicto($text, $htmltext);
1022 1022
 		//print ' ('.$code.')';
1023 1023
         print '</td>';
1024 1024
 
@@ -1079,10 +1079,10 @@  discard block
 block discarded – undo
1079 1079
 
1080 1080
         // List of existing export profils
1081 1081
     	$sql = "SELECT rowid, label";
1082
-		$sql.= " FROM ".MAIN_DB_PREFIX."export_model";
1083
-		$sql.= " WHERE type = '".$datatoexport."'";
1084
-		if(empty($conf->global->EXPORTS_SHARE_MODELS))$sql.=" AND fk_user=".$user->id;
1085
-		$sql.= " ORDER BY rowid";
1082
+		$sql .= " FROM ".MAIN_DB_PREFIX."export_model";
1083
+		$sql .= " WHERE type = '".$datatoexport."'";
1084
+		if (empty($conf->global->EXPORTS_SHARE_MODELS))$sql .= " AND fk_user=".$user->id;
1085
+		$sql .= " ORDER BY rowid";
1086 1086
 		$resql = $db->query($sql);
1087 1087
 		if ($resql)
1088 1088
 		{
@@ -1121,13 +1121,13 @@  discard block
 block discarded – undo
1121 1121
 
1122 1122
 	asort($array_selected);
1123 1123
 
1124
-    llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
1124
+    llxHeader('', $langs->trans("NewExport"), 'EN:Module_Exports_En|FR:Module_Exports|ES:M&oacute;dulo_Exportaciones');
1125 1125
 
1126 1126
     /*
1127 1127
      * Affichage onglets
1128 1128
      */
1129 1129
     $h = 0;
1130
-    $stepoffset=0;
1130
+    $stepoffset = 0;
1131 1131
 
1132 1132
     $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1';
1133 1133
     $head[$h][1] = $langs->trans("Step")." 1";
@@ -1147,12 +1147,12 @@  discard block
 block discarded – undo
1147 1147
     }
1148 1148
 
1149 1149
     $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport;
1150
-    $head[$h][1] = $langs->trans("Step")." ".(3+$stepoffset);
1150
+    $head[$h][1] = $langs->trans("Step")." ".(3 + $stepoffset);
1151 1151
     $h++;
1152 1152
 
1153 1153
     $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=5&datatoexport='.$datatoexport;
1154
-    $head[$h][1] = $langs->trans("Step")." ".(4+$stepoffset);
1155
-    $hselected=$h;
1154
+    $head[$h][1] = $langs->trans("Step")." ".(4 + $stepoffset);
1155
+    $hselected = $h;
1156 1156
     $h++;
1157 1157
 
1158 1158
     dol_fiche_head($head, $hselected, $langs->trans("NewExport"), -1);
@@ -1180,18 +1180,18 @@  discard block
 block discarded – undo
1180 1180
     // Lot de donnees a exporter
1181 1181
     print '<tr><td>'.$langs->trans("DatasetToExport").'</td>';
1182 1182
     print '<td>';
1183
-	$icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]);
1183
+	$icon = preg_replace('/:.*$/', '', $objexport->array_export_icon[0]);
1184 1184
     print img_object($objexport->array_export_module[0]->getName(), $icon).' ';
1185 1185
     print $objexport->array_export_label[0];
1186 1186
     print '</td></tr>';
1187 1187
 
1188 1188
     // List of exported fields
1189 1189
     print '<tr><td>'.$langs->trans("ExportedFields").'</td>';
1190
-    $list='';
1191
-    foreach($array_selected as $code=>$label)
1190
+    $list = '';
1191
+    foreach ($array_selected as $code=>$label)
1192 1192
     {
1193
-        $list.=(! empty($list)?', ':'');
1194
-        $list.=$langs->trans($objexport->array_export_fields[0][$code]);
1193
+        $list .= (!empty($list) ? ', ' : '');
1194
+        $list .= $langs->trans($objexport->array_export_fields[0][$code]);
1195 1195
     }
1196 1196
     print '<td>'.$list.'</td></tr>';
1197 1197
 
@@ -1199,20 +1199,20 @@  discard block
 block discarded – undo
1199 1199
     if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0]))
1200 1200
     {
1201 1201
     	print '<tr><td>'.$langs->trans("FilteredFields").'</td>';
1202
-    	$list='';
1203
-    	if (! empty($array_filtervalue))
1202
+    	$list = '';
1203
+    	if (!empty($array_filtervalue))
1204 1204
     	{
1205
-    		foreach($array_filtervalue as $code=>$value)
1205
+    		foreach ($array_filtervalue as $code=>$value)
1206 1206
     		{
1207 1207
     			if (isset($objexport->array_export_fields[0][$code]))
1208 1208
     			{
1209
-    				$list.=($list?', ':'');
1210
-    				if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'');
1211
-    				else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'";
1209
+    				$list .= ($list ? ', ' : '');
1210
+    				if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/', $array_filtervalue[$code])) $list .= $langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '');
1211
+    				else $list .= $langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code]) ? $array_filtervalue[$code] : '')."'";
1212 1212
     			}
1213 1213
     		}
1214 1214
     	}
1215
-    	print '<td>'.(! empty($list)?$list:$langs->trans("None")).'</td>';
1215
+    	print '<td>'.(!empty($list) ? $list : $langs->trans("None")).'</td>';
1216 1216
     	print '</tr>';
1217 1217
     }
1218 1218
 
@@ -1231,21 +1231,21 @@  discard block
 block discarded – undo
1231 1231
     print '<td align="right">'.$langs->trans("LibraryVersion").'</td>';
1232 1232
     print '</tr>'."\n";
1233 1233
 
1234
-    $liste=$objmodelexport->liste_modeles($db);
1235
-    $listeall=$liste;
1236
-    foreach($listeall as $key => $val)
1234
+    $liste = $objmodelexport->liste_modeles($db);
1235
+    $listeall = $liste;
1236
+    foreach ($listeall as $key => $val)
1237 1237
     {
1238
-    	if (preg_match('/__\(Disabled\)__/',$listeall[$key]))
1238
+    	if (preg_match('/__\(Disabled\)__/', $listeall[$key]))
1239 1239
     	{
1240
-    		$listeall[$key]=preg_replace('/__\(Disabled\)__/','('.$langs->transnoentitiesnoconv("Disabled").')',$listeall[$key]);
1240
+    		$listeall[$key] = preg_replace('/__\(Disabled\)__/', '('.$langs->transnoentitiesnoconv("Disabled").')', $listeall[$key]);
1241 1241
     		unset($liste[$key]);
1242 1242
     	}
1243 1243
 
1244 1244
         print '<tr class="oddeven">';
1245
-        print '<td width="16">'.img_picto_common($key,$objmodelexport->getPictoForKey($key)).' ';
1246
-	    $text=$objmodelexport->getDriverDescForKey($key);
1247
-	    $label=$listeall[$key];
1248
-	    print $form->textwithpicto($label,$text).'</td>';
1245
+        print '<td width="16">'.img_picto_common($key, $objmodelexport->getPictoForKey($key)).' ';
1246
+	    $text = $objmodelexport->getDriverDescForKey($key);
1247
+	    $label = $listeall[$key];
1248
+	    print $form->textwithpicto($label, $text).'</td>';
1249 1249
         print '<td>'.$objmodelexport->getLibLabelForKey($key).'</td>';
1250 1250
         print '<td align="right">'.$objmodelexport->getLibVersionForKey($key).'</td>';
1251 1251
         print '</tr>'."\n";
@@ -1268,11 +1268,11 @@  discard block
 block discarded – undo
1268 1268
 
1269 1269
 	print '<div class="fichecenter"><div class="fichehalfleft">';
1270 1270
 
1271
-    if (! is_dir($conf->export->dir_temp)) dol_mkdir($conf->export->dir_temp);
1271
+    if (!is_dir($conf->export->dir_temp)) dol_mkdir($conf->export->dir_temp);
1272 1272
 
1273 1273
     // Affiche liste des documents
1274 1274
     // NB: La fonction show_documents rescanne les modules qd genallowed=1, sinon prend $liste
1275
-    print $formfile->showdocuments('export','',$upload_dir,$_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport,$liste,1,(! empty($_POST['model'])?$_POST['model']:'csv'),1,1);
1275
+    print $formfile->showdocuments('export', '', $upload_dir, $_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport, $liste, 1, (!empty($_POST['model']) ? $_POST['model'] : 'csv'), 1, 1);
1276 1276
 
1277 1277
     print '</div><div class="fichehalfright"><div class="ficheaddleft">';
1278 1278
 
@@ -1283,7 +1283,7 @@  discard block
 block discarded – undo
1283 1283
 
1284 1284
 $db->close();
1285 1285
 
1286
-exit;	// don't know why but apache hangs with php 5.3.10-1ubuntu3.12 and apache 2.2.2 if i remove this exit or replace with return
1286
+exit; // don't know why but apache hangs with php 5.3.10-1ubuntu3.12 and apache 2.2.2 if i remove this exit or replace with return
1287 1287
 
1288 1288
 
1289 1289
 /**
@@ -1293,18 +1293,18 @@  discard block
 block discarded – undo
1293 1293
  * 	@param	string	$sqlmaxforexport	SQL request to parse
1294 1294
  * 	@return	string						Table name of field
1295 1295
  */
1296
-function getablenamefromfield($code,$sqlmaxforexport)
1296
+function getablenamefromfield($code, $sqlmaxforexport)
1297 1297
 {
1298
-	$alias=preg_replace('/\.(.*)$/i','',$code);         // Keep only 'Alias' and remove '.Fieldname'
1299
-	$regexstring='/([a-zA-Z_]+) as '.preg_quote($alias).'[, \)]/i';
1298
+	$alias = preg_replace('/\.(.*)$/i', '', $code); // Keep only 'Alias' and remove '.Fieldname'
1299
+	$regexstring = '/([a-zA-Z_]+) as '.preg_quote($alias).'[, \)]/i';
1300 1300
 
1301
-	$newsql=$sqlmaxforexport;
1302
-	$newsql=preg_replace('/^(.*) FROM /i','',$newsql);  // Remove part before the FROM
1303
-	$newsql=preg_replace('/WHERE (.*)$/i','',$newsql);	// Remove part after the WHERE so we have now only list of table aliases in a string. We must keep the ' ' before WHERE
1301
+	$newsql = $sqlmaxforexport;
1302
+	$newsql = preg_replace('/^(.*) FROM /i', '', $newsql); // Remove part before the FROM
1303
+	$newsql = preg_replace('/WHERE (.*)$/i', '', $newsql); // Remove part after the WHERE so we have now only list of table aliases in a string. We must keep the ' ' before WHERE
1304 1304
 
1305
-	if (preg_match($regexstring,$newsql,$reg))
1305
+	if (preg_match($regexstring, $newsql, $reg))
1306 1306
 	{
1307
-		return $reg[1];   // The tablename
1307
+		return $reg[1]; // The tablename
1308 1308
 	}
1309 1309
 	else return '';
1310 1310
 }
Please login to merge, or discard this patch.