Test Failed
Push — master ( ed0f4f...3aebc2 )
by Alxarafe
43:14
created
dolibarr/htdocs/paypal/lib/paypalfunctions.lib.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 // PayPal Express Checkout Module
39 39
 // ==================================
40 40
 
41
-$API_version="56";
41
+$API_version = "56";
42 42
 
43 43
 /*
44 44
  ' Define the PayPal Redirect URLs.
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
  ' For the sandbox, the URL is       https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=
49 49
  ' For the live site, the URL is        https://www.paypal.com/webscr&cmd=_express-checkout&token=
50 50
  */
51
-if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))		// We can force sand box with param 'forcesandbox'
51
+if (!empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox', 'alpha'))		// We can force sand box with param 'forcesandbox'
52 52
 {
53 53
     $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
54 54
     $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
@@ -60,19 +60,19 @@  discard block
 block discarded – undo
60 60
 }
61 61
 
62 62
 // Clean parameters
63
-$PAYPAL_API_USER="";
64
-if (! empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
65
-$PAYPAL_API_PASSWORD="";
66
-if (! empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
67
-$PAYPAL_API_SIGNATURE="";
68
-if (! empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
69
-$PAYPAL_API_SANDBOX="";
70
-if (! empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
63
+$PAYPAL_API_USER = "";
64
+if (!empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER = $conf->global->PAYPAL_API_USER;
65
+$PAYPAL_API_PASSWORD = "";
66
+if (!empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD = $conf->global->PAYPAL_API_PASSWORD;
67
+$PAYPAL_API_SIGNATURE = "";
68
+if (!empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE = $conf->global->PAYPAL_API_SIGNATURE;
69
+$PAYPAL_API_SANDBOX = "";
70
+if (!empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX = $conf->global->PAYPAL_API_SANDBOX;
71 71
 
72 72
 // Proxy
73 73
 $PROXY_HOST = $conf->global->MAIN_PROXY_HOST;
74 74
 $PROXY_PORT = $conf->global->MAIN_PROXY_PORT;
75 75
 $PROXY_USER = $conf->global->MAIN_PROXY_USER;
76 76
 $PROXY_PASS = $conf->global->MAIN_PROXY_PASS;
77
-$USE_PROXY = empty($conf->global->MAIN_PROXY_USE)?false:true;
77
+$USE_PROXY = empty($conf->global->MAIN_PROXY_USE) ?false:true;
78 78
 
Please login to merge, or discard this patch.
Braces   +19 added lines, -8 removed lines patch added patch discarded remove patch
@@ -25,11 +25,13 @@  discard block
 block discarded – undo
25 25
 if (session_id() == "")
26 26
 {
27 27
     session_start();
28
-    if (ini_get('register_globals'))    // To solve bug in using $_SESSION
28
+    if (ini_get('register_globals')) {
29
+        // To solve bug in using $_SESSION
29 30
     {
30 31
         foreach ($_SESSION as $key=>$value)
31 32
         {
32 33
             if (isset($GLOBALS[$key])) unset($GLOBALS[$key]);
34
+    }
33 35
         }
34 36
     }
35 37
 }
@@ -48,12 +50,13 @@  discard block
 block discarded – undo
48 50
  ' For the sandbox, the URL is       https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=
49 51
  ' For the live site, the URL is        https://www.paypal.com/webscr&cmd=_express-checkout&token=
50 52
  */
51
-if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))		// We can force sand box with param 'forcesandbox'
53
+if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha')) {
54
+    // We can force sand box with param 'forcesandbox'
52 55
 {
53 56
     $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
54
-    $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
55 57
 }
56
-else
58
+    $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
59
+} else
57 60
 {
58 61
     $API_Endpoint = "https://api-3t.paypal.com/nvp";
59 62
     $API_Url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
@@ -61,13 +64,21 @@  discard block
 block discarded – undo
61 64
 
62 65
 // Clean parameters
63 66
 $PAYPAL_API_USER="";
64
-if (! empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
67
+if (! empty($conf->global->PAYPAL_API_USER)) {
68
+    $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
69
+}
65 70
 $PAYPAL_API_PASSWORD="";
66
-if (! empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
71
+if (! empty($conf->global->PAYPAL_API_PASSWORD)) {
72
+    $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
73
+}
67 74
 $PAYPAL_API_SIGNATURE="";
68
-if (! empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
75
+if (! empty($conf->global->PAYPAL_API_SIGNATURE)) {
76
+    $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
77
+}
69 78
 $PAYPAL_API_SANDBOX="";
70
-if (! empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
79
+if (! empty($conf->global->PAYPAL_API_SANDBOX)) {
80
+    $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
81
+}
71 82
 
72 83
 // Proxy
73 84
 $PROXY_HOST = $conf->global->MAIN_PROXY_HOST;
Please login to merge, or discard this patch.
dolibarr/htdocs/paypal/lib/paypal.lib.php 3 patches
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -30,25 +30,25 @@  discard block
 block discarded – undo
30 30
  */
31 31
 function paypaladmin_prepare_head()
32 32
 {
33
-	global $langs, $conf;
33
+    global $langs, $conf;
34 34
 
35
-	$h = 0;
36
-	$head = array();
35
+    $h = 0;
36
+    $head = array();
37 37
 
38
-	$head[$h][0] = DOL_URL_ROOT."/paypal/admin/paypal.php";
39
-	$head[$h][1] = $langs->trans("PayPal");
40
-	$head[$h][2] = 'paypalaccount';
41
-	$h++;
38
+    $head[$h][0] = DOL_URL_ROOT."/paypal/admin/paypal.php";
39
+    $head[$h][1] = $langs->trans("PayPal");
40
+    $head[$h][2] = 'paypalaccount';
41
+    $h++;
42 42
 
43
-	$object=new stdClass();
43
+    $object=new stdClass();
44 44
 
45 45
     // Show more tabs from modules
46 46
     // Entries must be declared in modules descriptor with line
47 47
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
48 48
     // $this->tabs = array('entity:-tabname);   												to remove a tab
49
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'paypaladmin');
49
+    complete_head_from_modules($conf,$langs,$object,$head,$h,'paypaladmin');
50 50
 
51
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'paypaladmin','remove');
51
+    complete_head_from_modules($conf,$langs,$object,$head,$h,'paypaladmin','remove');
52 52
 
53 53
     return $head;
54 54
 }
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
  */
65 65
 function showPaypalPaymentUrl($type,$ref)
66 66
 {
67
-	global $conf, $langs;
67
+    global $conf, $langs;
68 68
 
69
-	$langs->load("paypal");
69
+    $langs->load("paypal");
70 70
     $langs->load("paybox");
71 71
     $servicename='PayPal';
72 72
     $out='<br><br>';
@@ -90,28 +90,28 @@  discard block
 block discarded – undo
90 90
  */
91 91
 function getPaypalPaymentUrl($mode,$type,$ref='',$amount='9.99',$freetag='your_free_tag')
92 92
 {
93
-	global $conf;
93
+    global $conf;
94 94
 
95
-	$ref=str_replace(' ','',$ref);
95
+    $ref=str_replace(' ','',$ref);
96 96
 
97 97
     if ($type == 'free')
98 98
     {
99
-	    $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':'');
100
-	    if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
101
-	    {
102
-	    	if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
103
-	    	else $out.='&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
104
-	    }
99
+        $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':'');
100
+        if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
101
+        {
102
+            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
103
+            else $out.='&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
104
+        }
105 105
     }
106 106
     if ($type == 'order')
107 107
     {
108 108
         $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=order&ref='.($mode?'<font color="#666666">':'');
109 109
         if ($mode == 1) $out.='order_ref';
110 110
         if ($mode == 0) $out.=urlencode($ref);
111
-	    $out.=($mode?'</font>':'');
111
+        $out.=($mode?'</font>':'');
112 112
         if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
113 113
         {
114
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
114
+            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
115 115
             else
116 116
             {
117 117
                 $out.='&securekey='.($mode?'<font color="#666666">':'');
@@ -126,10 +126,10 @@  discard block
 block discarded – undo
126 126
         $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=invoice&ref='.($mode?'<font color="#666666">':'');
127 127
         if ($mode == 1) $out.='invoice_ref';
128 128
         if ($mode == 0) $out.=urlencode($ref);
129
-	    $out.=($mode?'</font>':'');
129
+        $out.=($mode?'</font>':'');
130 130
         if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
131 131
         {
132
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
132
+            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
133 133
             else
134 134
             {
135 135
                 $out.='&securekey='.($mode?'<font color="#666666">':'');
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
         $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=contractline&ref='.($mode?'<font color="#666666">':'');
145 145
         if ($mode == 1) $out.='contractline_ref';
146 146
         if ($mode == 0) $out.=urlencode($ref);
147
-	    $out.=($mode?'</font>':'');
147
+        $out.=($mode?'</font>':'');
148 148
         if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
149 149
         {
150
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
150
+            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
151 151
             else
152 152
             {
153 153
                 $out.='&securekey='.($mode?'<font color="#666666">':'');
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
         $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=membersubscription&ref='.($mode?'<font color="#666666">':'');
163 163
         if ($mode == 1) $out.='member_ref';
164 164
         if ($mode == 0) $out.=urlencode($ref);
165
-	    $out.=($mode?'</font>':'');
165
+        $out.=($mode?'</font>':'');
166 166
         if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
167 167
         {
168
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
168
+            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
169 169
             else
170 170
             {
171 171
                 $out.='&securekey='.($mode?'<font color="#666666">':'');
@@ -274,15 +274,15 @@  discard block
 block discarded – undo
274 274
 
275 275
         if ($ErrorCode == 10729)
276 276
         {
277
-        	$mesg.= "PayPal can't accept payments for this thirdparty. An address is defined but is not complete (missing State).<br>Ask system administrator to fix address or to setup Paypal module to accept payments even on not complete addresses (remove option PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS).<br>\n";
277
+            $mesg.= "PayPal can't accept payments for this thirdparty. An address is defined but is not complete (missing State).<br>Ask system administrator to fix address or to setup Paypal module to accept payments even on not complete addresses (remove option PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS).<br>\n";
278 278
         }
279 279
         else
280 280
         {
281
-        	$mesg = $langs->trans('SetExpressCheckoutAPICallFailed') . "<br>\n";
282
-        	$mesg.= $langs->trans('DetailedErrorMessage') . ": " . $ErrorLongMsg."<br>\n";
283
-        	$mesg.= $langs->trans('ShortErrorMessage') . ": " . $ErrorShortMsg."<br>\n";
284
-        	$mesg.= $langs->trans('ErrorCode') . ": " . $ErrorCode."<br>\n";
285
-        	$mesg.= $langs->trans('ErrorSeverityCode') . ": " . $ErrorSeverityCode."<br>\n";
281
+            $mesg = $langs->trans('SetExpressCheckoutAPICallFailed') . "<br>\n";
282
+            $mesg.= $langs->trans('DetailedErrorMessage') . ": " . $ErrorLongMsg."<br>\n";
283
+            $mesg.= $langs->trans('ShortErrorMessage') . ": " . $ErrorShortMsg."<br>\n";
284
+            $mesg.= $langs->trans('ErrorCode') . ": " . $ErrorCode."<br>\n";
285
+            $mesg.= $langs->trans('ErrorSeverityCode') . ": " . $ErrorSeverityCode."<br>\n";
286 286
         }
287 287
 
288 288
         return $mesg;
@@ -346,28 +346,28 @@  discard block
 block discarded – undo
346 346
     $nvpstr = $nvpstr . "&CANCELURL=" . urlencode($cancelURL);
347 347
     if (! empty($conf->global->PAYPAL_ALLOW_NOTES))
348 348
     {
349
-    	$nvpstr = $nvpstr . "&ALLOWNOTE=0";
349
+        $nvpstr = $nvpstr . "&ALLOWNOTE=0";
350 350
     }
351 351
     if (empty($conf->global->PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS))
352 352
     {
353
-    	$nvpstr = $nvpstr . "&NOSHIPPING=1";	// An empty or not complete shipping address will be accepted
353
+        $nvpstr = $nvpstr . "&NOSHIPPING=1";	// An empty or not complete shipping address will be accepted
354 354
     }
355 355
     else
356 356
     {
357
-    	$nvpstr = $nvpstr . "&NOSHIPPING=0";	// A valid shipping address is required (full required fields mandatory)
357
+        $nvpstr = $nvpstr . "&NOSHIPPING=0";	// A valid shipping address is required (full required fields mandatory)
358 358
     }
359 359
     $nvpstr = $nvpstr . "&SOLUTIONTYPE=" . urlencode($solutionType);
360 360
     $nvpstr = $nvpstr . "&LANDINGPAGE=" . urlencode($landingPage);
361 361
     if (! empty($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER))
362 362
     {
363
-    	$nvpstr = $nvpstr . "&CUSTOMERSERVICENUMBER=" . urlencode($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER);    // Hotline phone number
363
+        $nvpstr = $nvpstr . "&CUSTOMERSERVICENUMBER=" . urlencode($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER);    // Hotline phone number
364 364
     }
365 365
 
366 366
     $paypalprefix = 'PAYMENTREQUEST_0_';
367 367
     //$paypalprefix = '';
368
-	if (! empty($paypalprefix) && $paymentType == 'Sole') $paymentType='Sale';
368
+    if (! empty($paypalprefix) && $paymentType == 'Sole') $paymentType='Sale';
369 369
 
370
-	$nvpstr = $nvpstr . "&AMT=". urlencode($paymentAmount);									// Total for all elements
370
+    $nvpstr = $nvpstr . "&AMT=". urlencode($paymentAmount);									// Total for all elements
371 371
 
372 372
     $nvpstr = $nvpstr . "&".$paypalprefix."INVNUM=" . urlencode($tag);
373 373
     $nvpstr = $nvpstr . "&".$paypalprefix."AMT=". urlencode($paymentAmount);                 // AMT deprecated by paypal -> PAYMENTREQUEST_n_AMT
@@ -393,26 +393,26 @@  discard block
 block discarded – undo
393 393
 
394 394
     if (! empty($conf->global->PAYPAL_LOGOIMG) && $mysoc->logo)
395 395
     {
396
-    	global $dolibarr_main_url_root;
396
+        global $dolibarr_main_url_root;
397 397
 
398
-	    // Define $urlwithroot
399
-	    $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
400
-	    $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
401
-	    //$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
398
+        // Define $urlwithroot
399
+        $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
400
+        $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
401
+        //$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
402 402
 
403
-	    $urllogo=$urlwithroot."/viewimage.php?modulepart=mycompany&file=".urlencode('logos/'.$mysoc->logo);
404
-	    $nvpstr = $nvpstr . "&LOGOIMG=" . urlencode($urllogo);
403
+        $urllogo=$urlwithroot."/viewimage.php?modulepart=mycompany&file=".urlencode('logos/'.$mysoc->logo);
404
+        $nvpstr = $nvpstr . "&LOGOIMG=" . urlencode($urllogo);
405 405
     }
406 406
     if (! empty($conf->global->PAYPAL_BRANDNAME))
407 407
     {
408
-    	$nvpstr = $nvpstr . "&BRANDNAME=" . urlencode($conf->global->PAYPAL_BRANDNAME);    // BRANDNAME
408
+        $nvpstr = $nvpstr . "&BRANDNAME=" . urlencode($conf->global->PAYPAL_BRANDNAME);    // BRANDNAME
409 409
     }
410 410
     if (! empty($conf->global->PAYPAL_NOTETOBUYER))
411 411
     {
412
-    	$nvpstr = $nvpstr . "&NOTETOBUYER=" . urlencode($conf->global->PAYPAL_NOTETOBUYER);  // PAYPAL_NOTETOBUYER
412
+        $nvpstr = $nvpstr . "&NOTETOBUYER=" . urlencode($conf->global->PAYPAL_NOTETOBUYER);  // PAYPAL_NOTETOBUYER
413 413
     }
414 414
 
415
-	$_SESSION["FinalPaymentAmt"] = $paymentAmount;
415
+    $_SESSION["FinalPaymentAmt"] = $paymentAmount;
416 416
     $_SESSION["currencyCodeType"] = $currencyCodeType;
417 417
     $_SESSION["PaymentType"] = $paymentType;			// 'Mark', 'Sole'
418 418
     $_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR'];   // Payer ip
@@ -592,27 +592,27 @@  discard block
 block discarded – undo
592 592
 
593 593
     // TODO problem with triggers
594 594
     $API_version="98.0";
595
-	if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))		// We can force sand box with param 'forcesandbox'
596
-	{
597
-	    $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
598
-	    $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
599
-	}
600
-	else
601
-	{
602
-	    $API_Endpoint = "https://api-3t.paypal.com/nvp";
603
-	    $API_Url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
604
-	}
605
-
606
-	// Clean parameters
607
-	$PAYPAL_API_USER="";
608
-	if (! empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
609
-	$PAYPAL_API_PASSWORD="";
610
-	if (! empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
611
-	$PAYPAL_API_SIGNATURE="";
612
-	if (! empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
613
-	$PAYPAL_API_SANDBOX="";
614
-	if (! empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
615
-	// TODO END problem with triggers
595
+    if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))		// We can force sand box with param 'forcesandbox'
596
+    {
597
+        $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
598
+        $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
599
+    }
600
+    else
601
+    {
602
+        $API_Endpoint = "https://api-3t.paypal.com/nvp";
603
+        $API_Url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
604
+    }
605
+
606
+    // Clean parameters
607
+    $PAYPAL_API_USER="";
608
+    if (! empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
609
+    $PAYPAL_API_PASSWORD="";
610
+    if (! empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
611
+    $PAYPAL_API_SIGNATURE="";
612
+    if (! empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
613
+    $PAYPAL_API_SANDBOX="";
614
+    if (! empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
615
+    // TODO END problem with triggers
616 616
 
617 617
     dol_syslog("Paypal API endpoint ".$API_Endpoint);
618 618
 
@@ -723,20 +723,20 @@  discard block
 block discarded – undo
723 723
  */
724 724
 function getApiError()
725 725
 {
726
-	$errors=array();
726
+    $errors=array();
727 727
 
728
-	$resArray=$_SESSION['reshash'];
728
+    $resArray=$_SESSION['reshash'];
729 729
 
730
-	if(isset($_SESSION['curl_error_no']))
731
-	{
732
-		$errors[] = $_SESSION['curl_error_no'].'-'.$_SESSION['curl_error_msg'];
733
-	}
730
+    if(isset($_SESSION['curl_error_no']))
731
+    {
732
+        $errors[] = $_SESSION['curl_error_no'].'-'.$_SESSION['curl_error_msg'];
733
+    }
734 734
 
735
-	foreach($resArray as $key => $value)
736
-	{
737
-		$errors[] = $key.'-'.$value;
738
-	}
735
+    foreach($resArray as $key => $value)
736
+    {
737
+        $errors[] = $key.'-'.$value;
738
+    }
739 739
 
740
-	return $errors;
740
+    return $errors;
741 741
 }
742 742
 
Please login to merge, or discard this patch.
Spacing   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -40,15 +40,15 @@  discard block
 block discarded – undo
40 40
 	$head[$h][2] = 'paypalaccount';
41 41
 	$h++;
42 42
 
43
-	$object=new stdClass();
43
+	$object = new stdClass();
44 44
 
45 45
     // Show more tabs from modules
46 46
     // Entries must be declared in modules descriptor with line
47 47
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
48 48
     // $this->tabs = array('entity:-tabname);   												to remove a tab
49
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'paypaladmin');
49
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'paypaladmin');
50 50
 
51
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'paypaladmin','remove');
51
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'paypaladmin', 'remove');
52 52
 
53 53
     return $head;
54 54
 }
@@ -62,18 +62,18 @@  discard block
 block discarded – undo
62 62
  * @param	string	$ref		Ref of object
63 63
  * @return	string				Url string
64 64
  */
65
-function showPaypalPaymentUrl($type,$ref)
65
+function showPaypalPaymentUrl($type, $ref)
66 66
 {
67 67
 	global $conf, $langs;
68 68
 
69 69
 	$langs->load("paypal");
70 70
     $langs->load("paybox");
71
-    $servicename='PayPal';
72
-    $out='<br><br>';
73
-    $out.=img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePayment",$servicename).'<br>';
74
-    $url=getPaypalPaymentUrl(0,$type,$ref);
75
-    $out.='<input type="text" id="paypalurl" class="quatrevingtpercent" value="'.$url.'">';
76
-    $out.=ajax_autoselect("paypalurl", 0);
71
+    $servicename = 'PayPal';
72
+    $out = '<br><br>';
73
+    $out .= img_picto('', 'object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePayment", $servicename).'<br>';
74
+    $url = getPaypalPaymentUrl(0, $type, $ref);
75
+    $out .= '<input type="text" id="paypalurl" class="quatrevingtpercent" value="'.$url.'">';
76
+    $out .= ajax_autoselect("paypalurl", 0);
77 77
     return $out;
78 78
 }
79 79
 
@@ -88,96 +88,96 @@  discard block
 block discarded – undo
88 88
  * @param	string	$freetag	Free tag
89 89
  * @return	string				Url string
90 90
  */
91
-function getPaypalPaymentUrl($mode,$type,$ref='',$amount='9.99',$freetag='your_free_tag')
91
+function getPaypalPaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_free_tag')
92 92
 {
93 93
 	global $conf;
94 94
 
95
-	$ref=str_replace(' ','',$ref);
95
+	$ref = str_replace(' ', '', $ref);
96 96
 
97 97
     if ($type == 'free')
98 98
     {
99
-	    $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':'');
100
-	    if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
99
+	    $out = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?amount='.($mode ? '<font color="#666666">' : '').$amount.($mode ? '</font>' : '').'&tag='.($mode ? '<font color="#666666">' : '').$freetag.($mode ? '</font>' : '');
100
+	    if (!empty($conf->global->PAYPAL_SECURITY_TOKEN))
101 101
 	    {
102
-	    	if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
103
-	    	else $out.='&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
102
+	    	if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
103
+	    	else $out .= '&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
104 104
 	    }
105 105
     }
106 106
     if ($type == 'order')
107 107
     {
108
-        $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=order&ref='.($mode?'<font color="#666666">':'');
109
-        if ($mode == 1) $out.='order_ref';
110
-        if ($mode == 0) $out.=urlencode($ref);
111
-	    $out.=($mode?'</font>':'');
112
-        if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
108
+        $out = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=order&ref='.($mode ? '<font color="#666666">' : '');
109
+        if ($mode == 1) $out .= 'order_ref';
110
+        if ($mode == 0) $out .= urlencode($ref);
111
+	    $out .= ($mode ? '</font>' : '');
112
+        if (!empty($conf->global->PAYPAL_SECURITY_TOKEN))
113 113
         {
114
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
114
+    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
115 115
             else
116 116
             {
117
-                $out.='&securekey='.($mode?'<font color="#666666">':'');
118
-                if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + order_ref)";
119
-                if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
120
-                $out.=($mode?'</font>':'');
117
+                $out .= '&securekey='.($mode ? '<font color="#666666">' : '');
118
+                if ($mode == 1) $out .= "hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + order_ref)";
119
+                if ($mode == 0) $out .= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.$type.$ref, 2);
120
+                $out .= ($mode ? '</font>' : '');
121 121
             }
122 122
         }
123 123
     }
124 124
     if ($type == 'invoice')
125 125
     {
126
-        $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=invoice&ref='.($mode?'<font color="#666666">':'');
127
-        if ($mode == 1) $out.='invoice_ref';
128
-        if ($mode == 0) $out.=urlencode($ref);
129
-	    $out.=($mode?'</font>':'');
130
-        if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
126
+        $out = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=invoice&ref='.($mode ? '<font color="#666666">' : '');
127
+        if ($mode == 1) $out .= 'invoice_ref';
128
+        if ($mode == 0) $out .= urlencode($ref);
129
+	    $out .= ($mode ? '</font>' : '');
130
+        if (!empty($conf->global->PAYPAL_SECURITY_TOKEN))
131 131
         {
132
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
132
+    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
133 133
             else
134 134
             {
135
-                $out.='&securekey='.($mode?'<font color="#666666">':'');
136
-                if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
137
-                if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
138
-                $out.=($mode?'</font>':'');
135
+                $out .= '&securekey='.($mode ? '<font color="#666666">' : '');
136
+                if ($mode == 1) $out .= "hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
137
+                if ($mode == 0) $out .= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.$type.$ref, 2);
138
+                $out .= ($mode ? '</font>' : '');
139 139
             }
140 140
         }
141 141
     }
142 142
     if ($type == 'contractline')
143 143
     {
144
-        $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=contractline&ref='.($mode?'<font color="#666666">':'');
145
-        if ($mode == 1) $out.='contractline_ref';
146
-        if ($mode == 0) $out.=urlencode($ref);
147
-	    $out.=($mode?'</font>':'');
148
-        if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
144
+        $out = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=contractline&ref='.($mode ? '<font color="#666666">' : '');
145
+        if ($mode == 1) $out .= 'contractline_ref';
146
+        if ($mode == 0) $out .= urlencode($ref);
147
+	    $out .= ($mode ? '</font>' : '');
148
+        if (!empty($conf->global->PAYPAL_SECURITY_TOKEN))
149 149
         {
150
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
150
+    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
151 151
             else
152 152
             {
153
-                $out.='&securekey='.($mode?'<font color="#666666">':'');
154
-                if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + contractline_ref)";
155
-                if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
156
-                $out.=($mode?'</font>':'');
153
+                $out .= '&securekey='.($mode ? '<font color="#666666">' : '');
154
+                if ($mode == 1) $out .= "hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + contractline_ref)";
155
+                if ($mode == 0) $out .= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.$type.$ref, 2);
156
+                $out .= ($mode ? '</font>' : '');
157 157
             }
158 158
         }
159 159
     }
160 160
     if ($type == 'membersubscription')
161 161
     {
162
-        $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=membersubscription&ref='.($mode?'<font color="#666666">':'');
163
-        if ($mode == 1) $out.='member_ref';
164
-        if ($mode == 0) $out.=urlencode($ref);
165
-	    $out.=($mode?'</font>':'');
166
-        if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
162
+        $out = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=membersubscription&ref='.($mode ? '<font color="#666666">' : '');
163
+        if ($mode == 1) $out .= 'member_ref';
164
+        if ($mode == 0) $out .= urlencode($ref);
165
+	    $out .= ($mode ? '</font>' : '');
166
+        if (!empty($conf->global->PAYPAL_SECURITY_TOKEN))
167 167
         {
168
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
168
+    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out .= '&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
169 169
             else
170 170
             {
171
-                $out.='&securekey='.($mode?'<font color="#666666">':'');
172
-                if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + member_ref)";
173
-                if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
174
-                $out.=($mode?'</font>':'');
171
+                $out .= '&securekey='.($mode ? '<font color="#666666">' : '');
172
+                if ($mode == 1) $out .= "hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + member_ref)";
173
+                if ($mode == 0) $out .= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.$type.$ref, 2);
174
+                $out .= ($mode ? '</font>' : '');
175 175
             }
176 176
         }
177 177
     }
178 178
 
179 179
     // For multicompany
180
-    $out.="&entity=".$conf->entity; // Check the entity because He may be the same reference in several entities
180
+    $out .= "&entity=".$conf->entity; // Check the entity because He may be the same reference in several entities
181 181
 
182 182
     return $out;
183 183
 }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
  * @param   string	$tag				Full tag
195 195
  * @return	string						No return (a redirect is done) if OK, or Error message if KO
196 196
  */
197
-function print_paypal_redirect($paymentAmount,$currencyCodeType,$paymentType,$returnURL,$cancelURL,$tag)
197
+function print_paypal_redirect($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag)
198 198
 {
199 199
     //declaring of global variables
200 200
     global $conf, $langs;
@@ -209,27 +209,27 @@  discard block
 block discarded – undo
209 209
     //'
210 210
     //'-------------------------------------------------
211 211
 
212
-    if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY='integral';
212
+    if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY = 'integral';
213 213
 
214
-    $solutionType='Sole';
215
-    $landingPage='Billing';
214
+    $solutionType = 'Sole';
215
+    $landingPage = 'Billing';
216 216
     // For payment with Paypal only
217 217
     if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'paypalonly')
218 218
     {
219
-        $solutionType='Mark';
220
-        $landingPage='Login';
219
+        $solutionType = 'Mark';
220
+        $landingPage = 'Login';
221 221
     }
222 222
     // For payment with Credit card or Paypal
223 223
     if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'integral')
224 224
     {
225
-        $solutionType='Sole';
226
-        $landingPage='Billing';
225
+        $solutionType = 'Sole';
226
+        $landingPage = 'Billing';
227 227
     }
228 228
     // For payment with Credit card
229 229
     if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'cconly')
230 230
     {
231
-        $solutionType='Sole';
232
-        $landingPage='Billing';
231
+        $solutionType = 'Sole';
232
+        $landingPage = 'Billing';
233 233
     }
234 234
 
235 235
     dol_syslog("expresscheckout redirect with callSetExpressCheckout $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage, $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum");
@@ -255,12 +255,12 @@  discard block
 block discarded – undo
255 255
     );
256 256
 
257 257
     $ack = strtoupper($resArray["ACK"]);
258
-    if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
258
+    if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING")
259 259
     {
260
-        $token=$resArray["TOKEN"];
260
+        $token = $resArray["TOKEN"];
261 261
 
262 262
         // Redirect to paypal.com here
263
-        $payPalURL = $API_Url . $token;
263
+        $payPalURL = $API_Url.$token;
264 264
         header("Location: ".$payPalURL);
265 265
         exit;
266 266
     }
@@ -274,15 +274,15 @@  discard block
 block discarded – undo
274 274
 
275 275
         if ($ErrorCode == 10729)
276 276
         {
277
-        	$mesg.= "PayPal can't accept payments for this thirdparty. An address is defined but is not complete (missing State).<br>Ask system administrator to fix address or to setup Paypal module to accept payments even on not complete addresses (remove option PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS).<br>\n";
277
+        	$mesg .= "PayPal can't accept payments for this thirdparty. An address is defined but is not complete (missing State).<br>Ask system administrator to fix address or to setup Paypal module to accept payments even on not complete addresses (remove option PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS).<br>\n";
278 278
         }
279 279
         else
280 280
         {
281
-        	$mesg = $langs->trans('SetExpressCheckoutAPICallFailed') . "<br>\n";
282
-        	$mesg.= $langs->trans('DetailedErrorMessage') . ": " . $ErrorLongMsg."<br>\n";
283
-        	$mesg.= $langs->trans('ShortErrorMessage') . ": " . $ErrorShortMsg."<br>\n";
284
-        	$mesg.= $langs->trans('ErrorCode') . ": " . $ErrorCode."<br>\n";
285
-        	$mesg.= $langs->trans('ErrorSeverityCode') . ": " . $ErrorSeverityCode."<br>\n";
281
+        	$mesg = $langs->trans('SetExpressCheckoutAPICallFailed')."<br>\n";
282
+        	$mesg .= $langs->trans('DetailedErrorMessage').": ".$ErrorLongMsg."<br>\n";
283
+        	$mesg .= $langs->trans('ShortErrorMessage').": ".$ErrorShortMsg."<br>\n";
284
+        	$mesg .= $langs->trans('ErrorCode').": ".$ErrorCode."<br>\n";
285
+        	$mesg .= $langs->trans('ErrorSeverityCode').": ".$ErrorSeverityCode."<br>\n";
286 286
         }
287 287
 
288 288
         return $mesg;
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
  * @param	string			$desc				Description
331 331
  * @return	array								Array
332 332
  */
333
-function callSetExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage, $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum, $email='', $desc='')
333
+function callSetExpressCheckout($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage, $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum, $email = '', $desc = '')
334 334
 {
335 335
     //------------------------------------------------------------------------------------------------------------------------------------
336 336
     // Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
@@ -342,92 +342,92 @@  discard block
 block discarded – undo
342 342
 
343 343
     $nvpstr = '';
344 344
     //$nvpstr = $nvpstr . "&VERSION=".$API_version;				// Already added by hash_call
345
-    $nvpstr = $nvpstr . "&RETURNURL=" . urlencode($returnURL);
346
-    $nvpstr = $nvpstr . "&CANCELURL=" . urlencode($cancelURL);
347
-    if (! empty($conf->global->PAYPAL_ALLOW_NOTES))
345
+    $nvpstr = $nvpstr."&RETURNURL=".urlencode($returnURL);
346
+    $nvpstr = $nvpstr."&CANCELURL=".urlencode($cancelURL);
347
+    if (!empty($conf->global->PAYPAL_ALLOW_NOTES))
348 348
     {
349
-    	$nvpstr = $nvpstr . "&ALLOWNOTE=0";
349
+    	$nvpstr = $nvpstr."&ALLOWNOTE=0";
350 350
     }
351 351
     if (empty($conf->global->PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS))
352 352
     {
353
-    	$nvpstr = $nvpstr . "&NOSHIPPING=1";	// An empty or not complete shipping address will be accepted
353
+    	$nvpstr = $nvpstr."&NOSHIPPING=1"; // An empty or not complete shipping address will be accepted
354 354
     }
355 355
     else
356 356
     {
357
-    	$nvpstr = $nvpstr . "&NOSHIPPING=0";	// A valid shipping address is required (full required fields mandatory)
357
+    	$nvpstr = $nvpstr."&NOSHIPPING=0"; // A valid shipping address is required (full required fields mandatory)
358 358
     }
359
-    $nvpstr = $nvpstr . "&SOLUTIONTYPE=" . urlencode($solutionType);
360
-    $nvpstr = $nvpstr . "&LANDINGPAGE=" . urlencode($landingPage);
361
-    if (! empty($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER))
359
+    $nvpstr = $nvpstr."&SOLUTIONTYPE=".urlencode($solutionType);
360
+    $nvpstr = $nvpstr."&LANDINGPAGE=".urlencode($landingPage);
361
+    if (!empty($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER))
362 362
     {
363
-    	$nvpstr = $nvpstr . "&CUSTOMERSERVICENUMBER=" . urlencode($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER);    // Hotline phone number
363
+    	$nvpstr = $nvpstr."&CUSTOMERSERVICENUMBER=".urlencode($conf->global->PAYPAL_CUSTOMER_SERVICE_NUMBER); // Hotline phone number
364 364
     }
365 365
 
366 366
     $paypalprefix = 'PAYMENTREQUEST_0_';
367 367
     //$paypalprefix = '';
368
-	if (! empty($paypalprefix) && $paymentType == 'Sole') $paymentType='Sale';
369
-
370
-	$nvpstr = $nvpstr . "&AMT=". urlencode($paymentAmount);									// Total for all elements
371
-
372
-    $nvpstr = $nvpstr . "&".$paypalprefix."INVNUM=" . urlencode($tag);
373
-    $nvpstr = $nvpstr . "&".$paypalprefix."AMT=". urlencode($paymentAmount);                 // AMT deprecated by paypal -> PAYMENTREQUEST_n_AMT
374
-    $nvpstr = $nvpstr . "&".$paypalprefix."ITEMAMT=". urlencode($paymentAmount);             // AMT deprecated by paypal -> PAYMENTREQUEST_n_AMT
375
-    $nvpstr = $nvpstr . "&".$paypalprefix."PAYMENTACTION=" . urlencode($paymentType);        // PAYMENTACTION deprecated by paypal -> PAYMENTREQUEST_n_PAYMENTACTION
376
-    $nvpstr = $nvpstr . "&".$paypalprefix."CURRENCYCODE=" . urlencode($currencyCodeType);    // CURRENCYCODE deprecated by paypal -> PAYMENTREQUEST_n_CURRENCYCODE
377
-
378
-    $nvpstr = $nvpstr . "&".$paypalprefix."L_PAYMENTREQUEST_0_QTY0=1";
379
-    $nvpstr = $nvpstr . "&".$paypalprefix."L_PAYMENTREQUEST_0_AMT0=".urlencode($paymentAmount);
380
-    $nvpstr = $nvpstr . "&".$paypalprefix."L_PAYMENTREQUEST_0_NAME0=".urlencode($desc);
381
-    $nvpstr = $nvpstr . "&".$paypalprefix."L_PAYMENTREQUEST_0_NUMBER0=0";
382
-
383
-    $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTONAME=" . urlencode($shipToName);            // SHIPTONAME deprecated by paypal -> PAYMENTREQUEST_n_SHIPTONAME
384
-    $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOSTREET=" . urlencode($shipToStreet);        //
385
-    $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOSTREET2=" . urlencode($shipToStreet2);
386
-    $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOCITY=" . urlencode($shipToCity);
387
-    $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOSTATE=" . urlencode($shipToState);
388
-    $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOCOUNTRYCODE=" . urlencode($shipToCountryCode);
389
-    $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOZIP=" . urlencode($shipToZip);
390
-    $nvpstr = $nvpstr . "&".$paypalprefix."PHONENUM=" . urlencode($phoneNum);
391
-    if (! empty($email)) $nvpstr = $nvpstr . "&".$paypalprefix."EMAIL=" . urlencode($email);      // EMAIL deprecated by paypal -> PAYMENTREQUEST_n_EMAIL
392
-    if (! empty($desc))  $nvpstr = $nvpstr . "&".$paypalprefix."DESC=" . urlencode($desc);        // DESC deprecated by paypal -> PAYMENTREQUEST_n_DESC
393
-
394
-    if (! empty($conf->global->PAYPAL_LOGOIMG) && $mysoc->logo)
368
+	if (!empty($paypalprefix) && $paymentType == 'Sole') $paymentType = 'Sale';
369
+
370
+	$nvpstr = $nvpstr."&AMT=".urlencode($paymentAmount); // Total for all elements
371
+
372
+    $nvpstr = $nvpstr."&".$paypalprefix."INVNUM=".urlencode($tag);
373
+    $nvpstr = $nvpstr."&".$paypalprefix."AMT=".urlencode($paymentAmount); // AMT deprecated by paypal -> PAYMENTREQUEST_n_AMT
374
+    $nvpstr = $nvpstr."&".$paypalprefix."ITEMAMT=".urlencode($paymentAmount); // AMT deprecated by paypal -> PAYMENTREQUEST_n_AMT
375
+    $nvpstr = $nvpstr."&".$paypalprefix."PAYMENTACTION=".urlencode($paymentType); // PAYMENTACTION deprecated by paypal -> PAYMENTREQUEST_n_PAYMENTACTION
376
+    $nvpstr = $nvpstr."&".$paypalprefix."CURRENCYCODE=".urlencode($currencyCodeType); // CURRENCYCODE deprecated by paypal -> PAYMENTREQUEST_n_CURRENCYCODE
377
+
378
+    $nvpstr = $nvpstr."&".$paypalprefix."L_PAYMENTREQUEST_0_QTY0=1";
379
+    $nvpstr = $nvpstr."&".$paypalprefix."L_PAYMENTREQUEST_0_AMT0=".urlencode($paymentAmount);
380
+    $nvpstr = $nvpstr."&".$paypalprefix."L_PAYMENTREQUEST_0_NAME0=".urlencode($desc);
381
+    $nvpstr = $nvpstr."&".$paypalprefix."L_PAYMENTREQUEST_0_NUMBER0=0";
382
+
383
+    $nvpstr = $nvpstr."&".$paypalprefix."SHIPTONAME=".urlencode($shipToName); // SHIPTONAME deprecated by paypal -> PAYMENTREQUEST_n_SHIPTONAME
384
+    $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOSTREET=".urlencode($shipToStreet); //
385
+    $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOSTREET2=".urlencode($shipToStreet2);
386
+    $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOCITY=".urlencode($shipToCity);
387
+    $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOSTATE=".urlencode($shipToState);
388
+    $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOCOUNTRYCODE=".urlencode($shipToCountryCode);
389
+    $nvpstr = $nvpstr."&".$paypalprefix."SHIPTOZIP=".urlencode($shipToZip);
390
+    $nvpstr = $nvpstr."&".$paypalprefix."PHONENUM=".urlencode($phoneNum);
391
+    if (!empty($email)) $nvpstr = $nvpstr."&".$paypalprefix."EMAIL=".urlencode($email); // EMAIL deprecated by paypal -> PAYMENTREQUEST_n_EMAIL
392
+    if (!empty($desc))  $nvpstr = $nvpstr."&".$paypalprefix."DESC=".urlencode($desc); // DESC deprecated by paypal -> PAYMENTREQUEST_n_DESC
393
+
394
+    if (!empty($conf->global->PAYPAL_LOGOIMG) && $mysoc->logo)
395 395
     {
396 396
     	global $dolibarr_main_url_root;
397 397
 
398 398
 	    // Define $urlwithroot
399
-	    $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
400
-	    $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
399
+	    $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
400
+	    $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
401 401
 	    //$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
402 402
 
403
-	    $urllogo=$urlwithroot."/viewimage.php?modulepart=mycompany&file=".urlencode('logos/'.$mysoc->logo);
404
-	    $nvpstr = $nvpstr . "&LOGOIMG=" . urlencode($urllogo);
403
+	    $urllogo = $urlwithroot."/viewimage.php?modulepart=mycompany&file=".urlencode('logos/'.$mysoc->logo);
404
+	    $nvpstr = $nvpstr."&LOGOIMG=".urlencode($urllogo);
405 405
     }
406
-    if (! empty($conf->global->PAYPAL_BRANDNAME))
406
+    if (!empty($conf->global->PAYPAL_BRANDNAME))
407 407
     {
408
-    	$nvpstr = $nvpstr . "&BRANDNAME=" . urlencode($conf->global->PAYPAL_BRANDNAME);    // BRANDNAME
408
+    	$nvpstr = $nvpstr."&BRANDNAME=".urlencode($conf->global->PAYPAL_BRANDNAME); // BRANDNAME
409 409
     }
410
-    if (! empty($conf->global->PAYPAL_NOTETOBUYER))
410
+    if (!empty($conf->global->PAYPAL_NOTETOBUYER))
411 411
     {
412
-    	$nvpstr = $nvpstr . "&NOTETOBUYER=" . urlencode($conf->global->PAYPAL_NOTETOBUYER);  // PAYPAL_NOTETOBUYER
412
+    	$nvpstr = $nvpstr."&NOTETOBUYER=".urlencode($conf->global->PAYPAL_NOTETOBUYER); // PAYPAL_NOTETOBUYER
413 413
     }
414 414
 
415 415
 	$_SESSION["FinalPaymentAmt"] = $paymentAmount;
416 416
     $_SESSION["currencyCodeType"] = $currencyCodeType;
417
-    $_SESSION["PaymentType"] = $paymentType;			// 'Mark', 'Sole'
418
-    $_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR'];   // Payer ip
417
+    $_SESSION["PaymentType"] = $paymentType; // 'Mark', 'Sole'
418
+    $_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR']; // Payer ip
419 419
 
420 420
     //'---------------------------------------------------------------------------------------------------------------
421 421
     //' Make the API call to PayPal
422 422
     //' If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment.
423 423
     //' If an error occured, show the resulting errors
424 424
     //'---------------------------------------------------------------------------------------------------------------
425
-    $resArray=hash_call("SetExpressCheckout", $nvpstr);
425
+    $resArray = hash_call("SetExpressCheckout", $nvpstr);
426 426
     $ack = strtoupper($resArray["ACK"]);
427
-    if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
427
+    if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING")
428 428
     {
429 429
         $token = urldecode($resArray["TOKEN"]);
430
-        $_SESSION['TOKEN']=$token;
430
+        $_SESSION['TOKEN'] = $token;
431 431
     }
432 432
 
433 433
     return $resArray;
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
     //' Build a second API request to PayPal, using the token as the
460 460
     //'  ID to get the details on the payment authorization
461 461
     //'---------------------------------------------------------------------------
462
-    $nvpstr="&TOKEN=" . $token;
462
+    $nvpstr = "&TOKEN=".$token;
463 463
 
464 464
     //'---------------------------------------------------------------------------
465 465
     //' Make the API call and store the results in an array.
@@ -467,9 +467,9 @@  discard block
 block discarded – undo
467 467
     //'     an action to complete the payment.
468 468
     //' If failed, show the error
469 469
     //'---------------------------------------------------------------------------
470
-    $resArray=hash_call("GetExpressCheckoutDetails",$nvpstr);
470
+    $resArray = hash_call("GetExpressCheckoutDetails", $nvpstr);
471 471
     $ack = strtoupper($resArray["ACK"]);
472
-    if($ack == "SUCCESS" || $ack=="SUCCESSWITHWARNING")
472
+    if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING")
473 473
     {
474 474
         $_SESSION['payer_id'] = $resArray['PAYERID'];
475 475
     }
@@ -502,18 +502,18 @@  discard block
 block discarded – undo
502 502
     global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
503 503
 
504 504
     $nvpstr = '';
505
-    $nvpstr .= '&TOKEN=' . urlencode($token);
506
-    $nvpstr .= '&PAYERID=' . urlencode($payerID);
507
-    $nvpstr .= '&PAYMENTACTION=' . urlencode($paymentType);
508
-    $nvpstr .= '&AMT=' . urlencode($FinalPaymentAmt);
509
-    $nvpstr .= '&CURRENCYCODE=' . urlencode($currencyCodeType);
510
-    $nvpstr .= '&IPADDRESS=' . urlencode($ipaddress);
511
-    $nvpstr .= '&INVNUM=' . urlencode($tag);
505
+    $nvpstr .= '&TOKEN='.urlencode($token);
506
+    $nvpstr .= '&PAYERID='.urlencode($payerID);
507
+    $nvpstr .= '&PAYMENTACTION='.urlencode($paymentType);
508
+    $nvpstr .= '&AMT='.urlencode($FinalPaymentAmt);
509
+    $nvpstr .= '&CURRENCYCODE='.urlencode($currencyCodeType);
510
+    $nvpstr .= '&IPADDRESS='.urlencode($ipaddress);
511
+    $nvpstr .= '&INVNUM='.urlencode($tag);
512 512
 
513 513
     /* Make the call to PayPal to finalize payment
514 514
      If an error occured, show the resulting errors
515 515
      */
516
-    $resArray=hash_call("DoExpressCheckoutPayment",$nvpstr);
516
+    $resArray = hash_call("DoExpressCheckoutPayment", $nvpstr);
517 517
 
518 518
     /* Display the API response back to the browser.
519 519
      If the response from PayPal was a success, display the response parameters'
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
  * @param	string	$nvpStr 		is nvp string.
584 584
  * @return	array					returns an associtive array containing the response from the server.
585 585
  */
586
-function hash_call($methodName,$nvpStr)
586
+function hash_call($methodName, $nvpStr)
587 587
 {
588 588
     //declaring of global variables
589 589
     global $conf, $langs;
@@ -591,8 +591,8 @@  discard block
 block discarded – undo
591 591
     global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
592 592
 
593 593
     // TODO problem with triggers
594
-    $API_version="98.0";
595
-	if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))		// We can force sand box with param 'forcesandbox'
594
+    $API_version = "98.0";
595
+	if (!empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox', 'alpha'))		// We can force sand box with param 'forcesandbox'
596 596
 	{
597 597
 	    $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
598 598
 	    $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
@@ -604,14 +604,14 @@  discard block
 block discarded – undo
604 604
 	}
605 605
 
606 606
 	// Clean parameters
607
-	$PAYPAL_API_USER="";
608
-	if (! empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
609
-	$PAYPAL_API_PASSWORD="";
610
-	if (! empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
611
-	$PAYPAL_API_SIGNATURE="";
612
-	if (! empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
613
-	$PAYPAL_API_SANDBOX="";
614
-	if (! empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
607
+	$PAYPAL_API_USER = "";
608
+	if (!empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER = $conf->global->PAYPAL_API_USER;
609
+	$PAYPAL_API_PASSWORD = "";
610
+	if (!empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD = $conf->global->PAYPAL_API_PASSWORD;
611
+	$PAYPAL_API_SIGNATURE = "";
612
+	if (!empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE = $conf->global->PAYPAL_API_SIGNATURE;
613
+	$PAYPAL_API_SANDBOX = "";
614
+	if (!empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX = $conf->global->PAYPAL_API_SANDBOX;
615 615
 	// TODO END problem with triggers
616 616
 
617 617
     dol_syslog("Paypal API endpoint ".$API_Endpoint);
@@ -626,30 +626,30 @@  discard block
 block discarded – undo
626 626
     curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
627 627
     curl_setopt($ch, CURLOPT_VERBOSE, 1);
628 628
     // TLSv1 by default or change to TLSv1.2 in module configuration
629
-    curl_setopt($ch, CURLOPT_SSLVERSION, (empty($conf->global->PAYPAL_SSLVERSION)?1:$conf->global->PAYPAL_SSLVERSION));
629
+    curl_setopt($ch, CURLOPT_SSLVERSION, (empty($conf->global->PAYPAL_SSLVERSION) ? 1 : $conf->global->PAYPAL_SSLVERSION));
630 630
 
631 631
     //turning off the server and peer verification(TrustManager Concept).
632 632
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
633 633
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
634 634
 
635
-    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)?5:$conf->global->MAIN_USE_CONNECT_TIMEOUT);
636
-    curl_setopt($ch, CURLOPT_TIMEOUT, empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT)?30:$conf->global->MAIN_USE_RESPONSE_TIMEOUT);
635
+    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, empty($conf->global->MAIN_USE_CONNECT_TIMEOUT) ? 5 : $conf->global->MAIN_USE_CONNECT_TIMEOUT);
636
+    curl_setopt($ch, CURLOPT_TIMEOUT, empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT) ? 30 : $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
637 637
 
638
-    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
638
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
639 639
     curl_setopt($ch, CURLOPT_POST, 1);
640 640
 
641 641
     //if USE_PROXY constant set to true in Constants.php, then only proxy will be enabled.
642 642
     if ($USE_PROXY)
643 643
     {
644
-        dol_syslog("Paypal API hash_call set proxy to ".$PROXY_HOST. ":" . $PROXY_PORT." - ".$PROXY_USER. ":" . $PROXY_PASS);
644
+        dol_syslog("Paypal API hash_call set proxy to ".$PROXY_HOST.":".$PROXY_PORT." - ".$PROXY_USER.":".$PROXY_PASS);
645 645
         //curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); // Curl 7.10
646
-        curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST. ":" . $PROXY_PORT);
647
-        if ($PROXY_USER) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER. ":" . $PROXY_PASS);
646
+        curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST.":".$PROXY_PORT);
647
+        if ($PROXY_USER) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER.":".$PROXY_PASS);
648 648
     }
649 649
 
650 650
     //NVPRequest for submitting to server
651
-    $nvpreq ="METHOD=" . urlencode($methodName) . "&VERSION=" . urlencode($API_version) . "&PWD=" . urlencode($PAYPAL_API_PASSWORD) . "&USER=" . urlencode($PAYPAL_API_USER) . "&SIGNATURE=" . urlencode($PAYPAL_API_SIGNATURE) . $nvpStr;
652
-    $nvpreq.="&LOCALECODE=".strtoupper($langs->getDefaultLang(1));
651
+    $nvpreq = "METHOD=".urlencode($methodName)."&VERSION=".urlencode($API_version)."&PWD=".urlencode($PAYPAL_API_PASSWORD)."&USER=".urlencode($PAYPAL_API_USER)."&SIGNATURE=".urlencode($PAYPAL_API_SIGNATURE).$nvpStr;
652
+    $nvpreq .= "&LOCALECODE=".strtoupper($langs->getDefaultLang(1));
653 653
     //$nvpreq.="&BRANDNAME=".urlencode();       // Override merchant name
654 654
     //$nvpreq.="&NOTIFYURL=".urlencode();       // For Instant Payment Notification url
655 655
 
@@ -662,18 +662,18 @@  discard block
 block discarded – undo
662 662
     //getting response from server
663 663
     $response = curl_exec($ch);
664 664
 
665
-    $nvpReqArray=deformatNVP($nvpreq);
666
-    $_SESSION['nvpReqArray']=$nvpReqArray;
665
+    $nvpReqArray = deformatNVP($nvpreq);
666
+    $_SESSION['nvpReqArray'] = $nvpReqArray;
667 667
 
668 668
     //convrting NVPResponse to an Associative Array
669 669
     dol_syslog("Paypal API hash_call Response nvpresp=".$response);
670
-    $nvpResArray=deformatNVP($response);
670
+    $nvpResArray = deformatNVP($response);
671 671
 
672 672
     if (curl_errno($ch))
673 673
     {
674 674
         // moving to display page to display curl errors
675
-        $_SESSION['curl_error_no']=curl_errno($ch);
676
-        $_SESSION['curl_error_msg']=curl_error($ch);
675
+        $_SESSION['curl_error_no'] = curl_errno($ch);
676
+        $_SESSION['curl_error_msg'] = curl_error($ch);
677 677
 
678 678
         //Execute the Error handling module to display errors.
679 679
     }
@@ -696,22 +696,22 @@  discard block
 block discarded – undo
696 696
  */
697 697
 function deformatNVP($nvpstr)
698 698
 {
699
-    $intial=0;
699
+    $intial = 0;
700 700
     $nvpArray = array();
701 701
 
702
-    while(strlen($nvpstr))
702
+    while (strlen($nvpstr))
703 703
     {
704 704
         //postion of Key
705
-        $keypos= strpos($nvpstr,'=');
705
+        $keypos = strpos($nvpstr, '=');
706 706
         //position of value
707
-        $valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): strlen($nvpstr);
707
+        $valuepos = strpos($nvpstr, '&') ? strpos($nvpstr, '&') : strlen($nvpstr);
708 708
 
709 709
         /*getting the Key and Value values and storing in a Associative Array*/
710
-        $keyval=substr($nvpstr,$intial,$keypos);
711
-        $valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1);
710
+        $keyval = substr($nvpstr, $intial, $keypos);
711
+        $valval = substr($nvpstr, $keypos + 1, $valuepos - $keypos - 1);
712 712
         //decoding the respose
713
-        $nvpArray[urldecode($keyval)] =urldecode($valval);
714
-        $nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr));
713
+        $nvpArray[urldecode($keyval)] = urldecode($valval);
714
+        $nvpstr = substr($nvpstr, $valuepos + 1, strlen($nvpstr));
715 715
     }
716 716
     return $nvpArray;
717 717
 }
@@ -723,16 +723,16 @@  discard block
 block discarded – undo
723 723
  */
724 724
 function getApiError()
725 725
 {
726
-	$errors=array();
726
+	$errors = array();
727 727
 
728
-	$resArray=$_SESSION['reshash'];
728
+	$resArray = $_SESSION['reshash'];
729 729
 
730
-	if(isset($_SESSION['curl_error_no']))
730
+	if (isset($_SESSION['curl_error_no']))
731 731
 	{
732 732
 		$errors[] = $_SESSION['curl_error_no'].'-'.$_SESSION['curl_error_msg'];
733 733
 	}
734 734
 
735
-	foreach($resArray as $key => $value)
735
+	foreach ($resArray as $key => $value)
736 736
 	{
737 737
 		$errors[] = $key.'-'.$value;
738 738
 	}
Please login to merge, or discard this patch.
Braces   +102 added lines, -46 removed lines patch added patch discarded remove patch
@@ -99,24 +99,36 @@  discard block
 block discarded – undo
99 99
 	    $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':'');
100 100
 	    if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
101 101
 	    {
102
-	    	if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
103
-	    	else $out.='&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
102
+	    	if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
103
+	    	    $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
104
+	    	} else {
105
+	    	    $out.='&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
106
+	    	}
104 107
 	    }
105 108
     }
106 109
     if ($type == 'order')
107 110
     {
108 111
         $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=order&ref='.($mode?'<font color="#666666">':'');
109
-        if ($mode == 1) $out.='order_ref';
110
-        if ($mode == 0) $out.=urlencode($ref);
112
+        if ($mode == 1) {
113
+            $out.='order_ref';
114
+        }
115
+        if ($mode == 0) {
116
+            $out.=urlencode($ref);
117
+        }
111 118
 	    $out.=($mode?'</font>':'');
112 119
         if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
113 120
         {
114
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
115
-            else
121
+    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
122
+    	        $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
123
+    	    } else
116 124
             {
117 125
                 $out.='&securekey='.($mode?'<font color="#666666">':'');
118
-                if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + order_ref)";
119
-                if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
126
+                if ($mode == 1) {
127
+                    $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + order_ref)";
128
+                }
129
+                if ($mode == 0) {
130
+                    $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
131
+                }
120 132
                 $out.=($mode?'</font>':'');
121 133
             }
122 134
         }
@@ -124,17 +136,26 @@  discard block
 block discarded – undo
124 136
     if ($type == 'invoice')
125 137
     {
126 138
         $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=invoice&ref='.($mode?'<font color="#666666">':'');
127
-        if ($mode == 1) $out.='invoice_ref';
128
-        if ($mode == 0) $out.=urlencode($ref);
139
+        if ($mode == 1) {
140
+            $out.='invoice_ref';
141
+        }
142
+        if ($mode == 0) {
143
+            $out.=urlencode($ref);
144
+        }
129 145
 	    $out.=($mode?'</font>':'');
130 146
         if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
131 147
         {
132
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
133
-            else
148
+    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
149
+    	        $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
150
+    	    } else
134 151
             {
135 152
                 $out.='&securekey='.($mode?'<font color="#666666">':'');
136
-                if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
137
-                if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
153
+                if ($mode == 1) {
154
+                    $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + invoice_ref)";
155
+                }
156
+                if ($mode == 0) {
157
+                    $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
158
+                }
138 159
                 $out.=($mode?'</font>':'');
139 160
             }
140 161
         }
@@ -142,17 +163,26 @@  discard block
 block discarded – undo
142 163
     if ($type == 'contractline')
143 164
     {
144 165
         $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=contractline&ref='.($mode?'<font color="#666666">':'');
145
-        if ($mode == 1) $out.='contractline_ref';
146
-        if ($mode == 0) $out.=urlencode($ref);
166
+        if ($mode == 1) {
167
+            $out.='contractline_ref';
168
+        }
169
+        if ($mode == 0) {
170
+            $out.=urlencode($ref);
171
+        }
147 172
 	    $out.=($mode?'</font>':'');
148 173
         if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
149 174
         {
150
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
151
-            else
175
+    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
176
+    	        $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
177
+    	    } else
152 178
             {
153 179
                 $out.='&securekey='.($mode?'<font color="#666666">':'');
154
-                if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + contractline_ref)";
155
-                if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
180
+                if ($mode == 1) {
181
+                    $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + contractline_ref)";
182
+                }
183
+                if ($mode == 0) {
184
+                    $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
185
+                }
156 186
                 $out.=($mode?'</font>':'');
157 187
             }
158 188
         }
@@ -160,17 +190,26 @@  discard block
 block discarded – undo
160 190
     if ($type == 'membersubscription')
161 191
     {
162 192
         $out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=membersubscription&ref='.($mode?'<font color="#666666">':'');
163
-        if ($mode == 1) $out.='member_ref';
164
-        if ($mode == 0) $out.=urlencode($ref);
193
+        if ($mode == 1) {
194
+            $out.='member_ref';
195
+        }
196
+        if ($mode == 0) {
197
+            $out.=urlencode($ref);
198
+        }
165 199
 	    $out.=($mode?'</font>':'');
166 200
         if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
167 201
         {
168
-    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
169
-            else
202
+    	    if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
203
+    	        $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
204
+    	    } else
170 205
             {
171 206
                 $out.='&securekey='.($mode?'<font color="#666666">':'');
172
-                if ($mode == 1) $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + member_ref)";
173
-                if ($mode == 0) $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
207
+                if ($mode == 1) {
208
+                    $out.="hash('".$conf->global->PAYPAL_SECURITY_TOKEN."' + '".$type."' + member_ref)";
209
+                }
210
+                if ($mode == 0) {
211
+                    $out.= dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . $type . $ref, 2);
212
+                }
174 213
                 $out.=($mode?'</font>':'');
175 214
             }
176 215
         }
@@ -209,7 +248,9 @@  discard block
 block discarded – undo
209 248
     //'
210 249
     //'-------------------------------------------------
211 250
 
212
-    if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY='integral';
251
+    if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) {
252
+        $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY='integral';
253
+    }
213 254
 
214 255
     $solutionType='Sole';
215 256
     $landingPage='Billing';
@@ -263,8 +304,7 @@  discard block
 block discarded – undo
263 304
         $payPalURL = $API_Url . $token;
264 305
         header("Location: ".$payPalURL);
265 306
         exit;
266
-    }
267
-    else
307
+    } else
268 308
     {
269 309
         //Display a user friendly Error on the page using any of the following error information returned by PayPal
270 310
         $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
@@ -275,8 +315,7 @@  discard block
 block discarded – undo
275 315
         if ($ErrorCode == 10729)
276 316
         {
277 317
         	$mesg.= "PayPal can't accept payments for this thirdparty. An address is defined but is not complete (missing State).<br>Ask system administrator to fix address or to setup Paypal module to accept payments even on not complete addresses (remove option PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS).<br>\n";
278
-        }
279
-        else
318
+        } else
280 319
         {
281 320
         	$mesg = $langs->trans('SetExpressCheckoutAPICallFailed') . "<br>\n";
282 321
         	$mesg.= $langs->trans('DetailedErrorMessage') . ": " . $ErrorLongMsg."<br>\n";
@@ -351,8 +390,7 @@  discard block
 block discarded – undo
351 390
     if (empty($conf->global->PAYPAL_REQUIRE_VALID_SHIPPING_ADDRESS))
352 391
     {
353 392
     	$nvpstr = $nvpstr . "&NOSHIPPING=1";	// An empty or not complete shipping address will be accepted
354
-    }
355
-    else
393
+    } else
356 394
     {
357 395
     	$nvpstr = $nvpstr . "&NOSHIPPING=0";	// A valid shipping address is required (full required fields mandatory)
358 396
     }
@@ -365,7 +403,9 @@  discard block
 block discarded – undo
365 403
 
366 404
     $paypalprefix = 'PAYMENTREQUEST_0_';
367 405
     //$paypalprefix = '';
368
-	if (! empty($paypalprefix) && $paymentType == 'Sole') $paymentType='Sale';
406
+	if (! empty($paypalprefix) && $paymentType == 'Sole') {
407
+	    $paymentType='Sale';
408
+	}
369 409
 
370 410
 	$nvpstr = $nvpstr . "&AMT=". urlencode($paymentAmount);									// Total for all elements
371 411
 
@@ -388,8 +428,14 @@  discard block
 block discarded – undo
388 428
     $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOCOUNTRYCODE=" . urlencode($shipToCountryCode);
389 429
     $nvpstr = $nvpstr . "&".$paypalprefix."SHIPTOZIP=" . urlencode($shipToZip);
390 430
     $nvpstr = $nvpstr . "&".$paypalprefix."PHONENUM=" . urlencode($phoneNum);
391
-    if (! empty($email)) $nvpstr = $nvpstr . "&".$paypalprefix."EMAIL=" . urlencode($email);      // EMAIL deprecated by paypal -> PAYMENTREQUEST_n_EMAIL
392
-    if (! empty($desc))  $nvpstr = $nvpstr . "&".$paypalprefix."DESC=" . urlencode($desc);        // DESC deprecated by paypal -> PAYMENTREQUEST_n_DESC
431
+    if (! empty($email)) {
432
+        $nvpstr = $nvpstr . "&".$paypalprefix."EMAIL=" . urlencode($email);
433
+    }
434
+    // EMAIL deprecated by paypal -> PAYMENTREQUEST_n_EMAIL
435
+    if (! empty($desc)) {
436
+        $nvpstr = $nvpstr . "&".$paypalprefix."DESC=" . urlencode($desc);
437
+    }
438
+    // DESC deprecated by paypal -> PAYMENTREQUEST_n_DESC
393 439
 
394 440
     if (! empty($conf->global->PAYPAL_LOGOIMG) && $mysoc->logo)
395 441
     {
@@ -592,12 +638,13 @@  discard block
 block discarded – undo
592 638
 
593 639
     // TODO problem with triggers
594 640
     $API_version="98.0";
595
-	if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha'))		// We can force sand box with param 'forcesandbox'
641
+	if (! empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox','alpha')) {
642
+	    // We can force sand box with param 'forcesandbox'
596 643
 	{
597 644
 	    $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
598
-	    $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
599 645
 	}
600
-	else
646
+	    $API_Url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
647
+	} else
601 648
 	{
602 649
 	    $API_Endpoint = "https://api-3t.paypal.com/nvp";
603 650
 	    $API_Url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
@@ -605,13 +652,21 @@  discard block
 block discarded – undo
605 652
 
606 653
 	// Clean parameters
607 654
 	$PAYPAL_API_USER="";
608
-	if (! empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
655
+	if (! empty($conf->global->PAYPAL_API_USER)) {
656
+	    $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
657
+	}
609 658
 	$PAYPAL_API_PASSWORD="";
610
-	if (! empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
659
+	if (! empty($conf->global->PAYPAL_API_PASSWORD)) {
660
+	    $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
661
+	}
611 662
 	$PAYPAL_API_SIGNATURE="";
612
-	if (! empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
663
+	if (! empty($conf->global->PAYPAL_API_SIGNATURE)) {
664
+	    $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
665
+	}
613 666
 	$PAYPAL_API_SANDBOX="";
614
-	if (! empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
667
+	if (! empty($conf->global->PAYPAL_API_SANDBOX)) {
668
+	    $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
669
+	}
615 670
 	// TODO END problem with triggers
616 671
 
617 672
     dol_syslog("Paypal API endpoint ".$API_Endpoint);
@@ -644,7 +699,9 @@  discard block
 block discarded – undo
644 699
         dol_syslog("Paypal API hash_call set proxy to ".$PROXY_HOST. ":" . $PROXY_PORT." - ".$PROXY_USER. ":" . $PROXY_PASS);
645 700
         //curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); // Curl 7.10
646 701
         curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST. ":" . $PROXY_PORT);
647
-        if ($PROXY_USER) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER. ":" . $PROXY_PASS);
702
+        if ($PROXY_USER) {
703
+            curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER. ":" . $PROXY_PASS);
704
+        }
648 705
     }
649 706
 
650 707
     //NVPRequest for submitting to server
@@ -676,8 +733,7 @@  discard block
 block discarded – undo
676 733
         $_SESSION['curl_error_msg']=curl_error($ch);
677 734
 
678 735
         //Execute the Error handling module to display errors.
679
-    }
680
-    else
736
+    } else
681 737
     {
682 738
         //closing the curl
683 739
         curl_close($ch);
Please login to merge, or discard this patch.
dolibarr/htdocs/paypal/admin/paypal.php 3 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 
42 42
 if ($action == 'setvalue' && $user->admin)
43 43
 {
44
-	$db->begin();
44
+    $db->begin();
45 45
 
46 46
     $result=dolibarr_set_const($db, "PAYPAL_API_USER",GETPOST('PAYPAL_API_USER','alpha'),'chaine',0,'',$conf->entity);
47 47
     if (! $result > 0) $error++;
@@ -66,24 +66,24 @@  discard block
 block discarded – undo
66 66
     $result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK",GETPOST('ONLINE_PAYMENT_MESSAGE_OK'),'chaine',0,'',$conf->entity);
67 67
     if (! $result > 0) $error++;
68 68
     $result=dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO",GETPOST('ONLINE_PAYMENT_MESSAGE_KO'),'chaine',0,'',$conf->entity);
69
-	if (! $result > 0) $error++;
70
-	$result=dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL",GETPOST('ONLINE_PAYMENT_SENDEMAIL'),'chaine',0,'',$conf->entity);
71
-	if (! $result > 0) $error++;
72
-	// Payment token for URL
73
-	$result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN",GETPOST('PAYMENT_SECURITY_TOKEN','alpha'),'chaine',0,'',$conf->entity);
74
-	if (! $result > 0) $error++;
75
-	$result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE",GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE','alpha'),'chaine',0,'',$conf->entity);
76
-	if (! $result > 0) $error++;
77
-
78
-	if (! $error)
79
-  	{
80
-  		$db->commit();
81
-  		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
82
-  	}
83
-  	else
84
-  	{
85
-  		$db->rollback();
86
-		dol_print_error($db);
69
+    if (! $result > 0) $error++;
70
+    $result=dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL",GETPOST('ONLINE_PAYMENT_SENDEMAIL'),'chaine',0,'',$conf->entity);
71
+    if (! $result > 0) $error++;
72
+    // Payment token for URL
73
+    $result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN",GETPOST('PAYMENT_SECURITY_TOKEN','alpha'),'chaine',0,'',$conf->entity);
74
+    if (! $result > 0) $error++;
75
+    $result=dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE",GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE','alpha'),'chaine',0,'',$conf->entity);
76
+    if (! $result > 0) $error++;
77
+
78
+    if (! $error)
79
+        {
80
+            $db->commit();
81
+            setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
82
+        }
83
+        else
84
+        {
85
+            $db->rollback();
86
+        dol_print_error($db);
87 87
     }
88 88
 }
89 89
 
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
 // Test if php curl exist
130 130
 if (! function_exists('curl_version'))
131 131
 {
132
-	$langs->load("errors");
133
-	setEventMessages($langs->trans("ErrorPhpCurlNotInstalled"), null, 'errors');
132
+    $langs->load("errors");
133
+    setEventMessages($langs->trans("ErrorPhpCurlNotInstalled"), null, 'errors');
134 134
 }
135 135
 
136 136
 
@@ -212,10 +212,10 @@  discard block
 block discarded – undo
212 212
 
213 213
 if (! empty($conf->banque->enabled))
214 214
 {
215
-	print '<tr class="oddeven"><td>';
216
-	print $langs->trans("BankAccount").'</td><td>';
217
-	print $form->select_comptes($conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS, 'PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
218
-	print '</td></tr>';
215
+    print '<tr class="oddeven"><td>';
216
+    print $langs->trans("BankAccount").'</td><td>';
217
+    print $form->select_comptes($conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS, 'PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
218
+    print '</td></tr>';
219 219
 }
220 220
 
221 221
 print '<tr class="oddeven"><td>';
@@ -268,13 +268,13 @@  discard block
 block discarded – undo
268 268
 print $langs->trans("SecurityToken").'</td><td>';
269 269
 print '<input size="48" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.$conf->global->PAYMENT_SECURITY_TOKEN.'">';
270 270
 if (! empty($conf->use_javascript_ajax))
271
-	print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
272
-	print '</td></tr>';
271
+    print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
272
+    print '</td></tr>';
273 273
 
274
-	print '<tr class="oddeven"><td>';
275
-	print $langs->trans("SecurityTokenIsUnique").'</td><td>';
276
-	print $form->selectyesno("PAYMENT_SECURITY_TOKEN_UNIQUE",(empty($conf->global->PAYMENT_SECURITY_TOKEN)?0:$conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE),1);
277
-	print '</td></tr>';
274
+    print '<tr class="oddeven"><td>';
275
+    print $langs->trans("SecurityTokenIsUnique").'</td><td>';
276
+    print $form->selectyesno("PAYMENT_SECURITY_TOKEN_UNIQUE",(empty($conf->global->PAYMENT_SECURITY_TOKEN)?0:$conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE),1);
277
+    print '</td></tr>';
278 278
 
279 279
 print '</table>';
280 280
 
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 // Help doc
290 290
 print '<u>'.$langs->trans("InformationToFindParameters","Paypal").'</u>:<br>';
291 291
 if (! empty($conf->use_javascript_ajax))
292
-	print '<a href="#" class="reposition" id="apidoca">'.$langs->trans("ClickHere").'...</a>';
292
+    print '<a href="#" class="reposition" id="apidoca">'.$langs->trans("ClickHere").'...</a>';
293 293
 
294 294
 $realpaypalurl='www.paypal.com';
295 295
 $sandboxpaypalurl='developer.paypal.com';
@@ -309,15 +309,15 @@  discard block
 block discarded – undo
309 309
 
310 310
 if (! empty($conf->use_javascript_ajax))
311 311
 {
312
-	print "\n".'<script type="text/javascript">';
313
-	print '$(document).ready(function () {
312
+    print "\n".'<script type="text/javascript">';
313
+    print '$(document).ready(function () {
314 314
             $("#apidoc").hide();
315 315
             $("#apidoca").click(function() {
316 316
                 $("#apidoc").show();
317 317
             	$("#apidoca").hide();
318 318
             })
319 319
 			});';
320
-	print '</script>';
320
+    print '</script>';
321 321
 }
322 322
 
323 323
 print '<br><br>';
Please login to merge, or discard this patch.
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.