Test Failed
Push — master ( ed0f4f...3aebc2 )
by Alxarafe
43:14
created
dolibarr/scripts/contracts/email_expire_services_to_representatives.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -33,17 +33,17 @@  discard block
 block discarded – undo
33 33
 $sapi_type = php_sapi_name();
34 34
 if (substr($sapi_type, 0, 3) == 'cgi') {
35 35
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
36
-	exit(-1);
36
+    exit(-1);
37 37
 }
38 38
 
39 39
 if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')))
40 40
 {
41
-	print "Usage: $script_file (test|confirm) [delay]\n";
42
-	print "\n";
43
-	print "Send an email to remind all contracts services to expire, to users that are sale representative for.\n";
44
-	print "If you choose 'test' mode, no emails are sent.\n";
45
-	print "If you add a delay (nb of days), only services with expired date < today + delay are included.\n";
46
-	exit(-1);
41
+    print "Usage: $script_file (test|confirm) [delay]\n";
42
+    print "\n";
43
+    print "Send an email to remind all contracts services to expire, to users that are sale representative for.\n";
44
+    print "If you choose 'test' mode, no emails are sent.\n";
45
+    print "If you add a delay (nb of days), only services with expired date < today + delay are included.\n";
46
+    exit(-1);
47 47
 }
48 48
 $mode=$argv[1];
49 49
 
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
     $i = 0;
91 91
     $oldemail = 'none'; $olduid = 0; $oldlang='';
92 92
     $total = 0; $foundtoprocess = 0;
93
-	print "We found ".$num." couples (services to expire - sale representative) qualified\n";
93
+    print "We found ".$num." couples (services to expire - sale representative) qualified\n";
94 94
     dol_syslog("We found ".$num." couples (services to expire - sale representative) qualified");
95
-	$message='';
95
+    $message='';
96 96
 
97 97
     if ($num)
98 98
     {
@@ -105,11 +105,11 @@  discard block
 block discarded – undo
105 105
                 // Break onto sales representative (new email or uid)
106 106
                 if (dol_strlen($oldemail) && $oldemail != 'none')
107 107
                 {
108
-                   	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative,$duration_value);
108
+                        envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative,$duration_value);
109 109
                 }
110 110
                 else
111
-				{
112
-					if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
111
+                {
112
+                    if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
113 113
                 }
114 114
                 $oldemail = $obj->email;
115 115
                 $olduid = $obj->uid;
@@ -131,18 +131,18 @@  discard block
 block discarded – undo
131 131
 
132 132
             if (dol_strlen($obj->email))
133 133
             {
134
-            	$message .= $outputlangs->trans("Contract")." ".$obj->ref.": ".$langs->trans("Service")." ".dol_concatdesc($obj->plabel,$obj->description)." (".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency).") ".$obj->name.", ".$outputlangs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite),'day')."\n\n";
135
-            	dol_syslog("email_expire_services_to_representatives.php: ".$obj->email);
136
-            	$foundtoprocess++;
134
+                $message .= $outputlangs->trans("Contract")." ".$obj->ref.": ".$langs->trans("Service")." ".dol_concatdesc($obj->plabel,$obj->description)." (".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency).") ".$obj->name.", ".$outputlangs->trans("DateEndPlannedShort")." ".dol_print_date($db->jdate($obj->date_fin_validite),'day')."\n\n";
135
+                dol_syslog("email_expire_services_to_representatives.php: ".$obj->email);
136
+                $foundtoprocess++;
137 137
             }
138 138
             print "Service to expire ".$obj->ref.", label ".dol_concatdesc($obj->plabel,$obj->description).", due date ".dol_print_date($db->jdate($obj->date_fin_validite),'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email."): ";
139 139
             if (dol_strlen($obj->email)) print "qualified.";
140 140
             else print "disqualified (no email).";
141
-			print "\n";
141
+            print "\n";
142 142
 
143
-			unset($outputlangs);
143
+            unset($outputlangs);
144 144
 
145
-			$total += $obj->total_ttc;
145
+            $total += $obj->total_ttc;
146 146
             $i++;
147 147
         }
148 148
 
@@ -151,16 +151,16 @@  discard block
 block discarded – undo
151 151
         {
152 152
             if (dol_strlen($oldemail) && $oldemail != 'none')	// Break onto email (new email)
153 153
             {
154
-       			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative,$duration_value);
154
+                    envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative,$duration_value);
155 155
             }
156 156
             else
157
-			{
158
-            	if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
157
+            {
158
+                if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
159 159
             }
160 160
         }
161 161
     }
162 162
     else
163
-	{
163
+    {
164 164
         print "No services to expire (for companies linked to a particular commercial dolibarr user) found\n";
165 165
     }
166 166
 
@@ -194,23 +194,23 @@  discard block
 block discarded – undo
194 194
     if (getenv('DOL_FORCE_EMAIL_TO')) $oldemail=getenv('DOL_FORCE_EMAIL_TO');
195 195
 
196 196
     $newlangs=new Translate('',$conf);
197
-	$newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
197
+    $newlangs->setDefaultLang(empty($userlang)?(empty($conf->global->MAIN_LANG_DEFAULT)?'auto':$conf->global->MAIN_LANG_DEFAULT):$userlang);
198 198
     $newlangs->load("main");
199 199
     $newlangs->load("contracts");
200 200
 
201 201
     if ($duration_value)
202 202
     {
203
-    	if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value);
204
-    	else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value);
203
+        if ($duration_value > 0) $title=$newlangs->transnoentities("ListOfServicesToExpireWithDuration",$duration_value);
204
+        else $title=$newlangs->transnoentities("ListOfServicesToExpireWithDurationNeg",$duration_value);
205 205
     }
206 206
     else
207
-    	$title= $newlangs->transnoentities("ListOfServicesToExpire");
207
+        $title= $newlangs->transnoentities("ListOfServicesToExpire");
208 208
 
209 209
     $subject = (empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT)?$title:$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_SUBJECT);
210 210
     $sendto = $oldemail;
211 211
     $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
212 212
     $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
213
-	$msgishtml = -1;
213
+    $msgishtml = -1;
214 214
 
215 215
     print "- Send email for ".$oldsalerepresentative." (".$oldemail."), total: ".$total."\n";
216 216
     dol_syslog("email_expire_services_to_representatives.php: send mail to ".$oldemail);
@@ -222,19 +222,19 @@  discard block
 block discarded – undo
222 222
     $allmessage='';
223 223
     if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER))
224 224
     {
225
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER;
225
+        $allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_HEADER;
226 226
     }
227 227
     else
228 228
     {
229
-    	$allmessage.= $title.($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
230
-    	$allmessage.= $newlangs->transnoentities("NoteListOfYourExpiredServices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
229
+        $allmessage.= $title.($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
230
+        $allmessage.= $newlangs->transnoentities("NoteListOfYourExpiredServices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
231 231
     }
232 232
     $allmessage.= $message.($usehtml?"<br>\n":"\n");
233 233
     $allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
234 234
     if (! empty($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER))
235 235
     {
236
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER;
237
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
236
+        $allmessage.=$conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER;
237
+        if (dol_textishtml($conf->global->SCRIPT_EMAIL_EXPIRE_SERVICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
238 238
     }
239 239
 
240 240
     $mail = new CMailFile(
@@ -256,19 +256,19 @@  discard block
 block discarded – undo
256 256
     // Send or not email
257 257
     if ($mode == 'confirm')
258 258
     {
259
-    	$result=$mail->sendfile();
260
-    	if (! $result)
261
-    	{
262
-    		print "Error sending email ".$mail->error."\n";
263
-    		dol_syslog("Error sending email ".$mail->error."\n");
264
-    	}
259
+        $result=$mail->sendfile();
260
+        if (! $result)
261
+        {
262
+            print "Error sending email ".$mail->error."\n";
263
+            dol_syslog("Error sending email ".$mail->error."\n");
264
+        }
265 265
     }
266 266
     else
267 267
     {
268
-    	print "No email sent (test mode)\n";
269
-    	dol_syslog("No email sent (test mode)");
270
-    	$mail->dump_mail();
271
-    	$result=1;
268
+        print "No email sent (test mode)\n";
269
+        dol_syslog("No email sent (test mode)");
270
+        $mail->dump_mail();
271
+        $result=1;
272 272
     }
273 273
 
274 274
     if ($result)
Please login to merge, or discard this patch.
dolibarr/scripts/invoices/rebuild_merge_pdf.php 1 patch
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 // Test if batch mode
31 31
 if (substr($sapi_type, 0, 3) == 'cgi') {
32 32
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
33
-	exit(-1);
33
+    exit(-1);
34 34
 }
35 35
 
36 36
 // Include Dolibarr environment
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 // Check parameters
63 63
 if (! isset($argv[1]))
64 64
 {
65
-	usage();
66
-	exit(-1);
65
+    usage();
66
+    exit(-1);
67 67
 }
68 68
 
69 69
 $diroutputpdf=$conf->facture->dir_output . '/temp';
@@ -75,98 +75,98 @@  discard block
 block discarded – undo
75 75
 
76 76
 foreach ($argv as $key => $value)
77 77
 {
78
-	$found=false;
79
-
80
-	// Define options
81
-	if (preg_match('/^lang=/i',$value))
82
-	{
83
-		$found=true;
84
-		$valarray=explode('=',$value);
85
-		$newlangid=$valarray[1];
86
-		print 'Use language '.$newlangid.".\n";
87
-	}
88
-	if (preg_match('/^prefix=/i',$value))
89
-	{
90
-		$found=true;
91
-		$valarray=explode('=',$value);
92
-		$fileprefix=$valarray[1];
93
-		print 'Use prefix for filename '.$fileprefix.".\n";
94
-	}
95
-
96
-	if (preg_match('/^regenerate=(.*)/i',$value,$reg))
97
-	{
98
-	    if (! in_array($reg[1],array('','0','no')))
99
-	    {
100
-		    $found=true;
101
-		    $regenerate=$reg[1];
102
-		    print 'Regeneration of PDF is requested with template '.$regenerate."\n";
103
-	    }
104
-	}
105
-
106
-	if ($value == 'filter=all')
107
-	{
108
-		$found=true;
109
-		$option.=(empty($option)?'':'_').'all';
110
-		$filter[]='all';
111
-
112
-		print 'Rebuild PDF for all invoices'."\n";
113
-	}
114
-
115
-	if ($value == 'filter=date')
116
-	{
117
-		$found=true;
118
-		$option.=(empty($option)?'':'_').'date_'.$argv[$key+1].'_'.$argv[$key+2];
119
-		$filter[]='date';
120
-
121
-		$dateafterdate=dol_stringtotime($argv[$key+1]);
122
-		$datebeforedate=dol_stringtotime($argv[$key+2]);
123
-		print 'Rebuild PDF for invoices validated between '.dol_print_date($dateafterdate,'day','gmt')." and ".dol_print_date($datebeforedate,'day','gmt').".\n";
124
-	}
125
-
126
-	if ($value == 'filter=payments')
127
-	{
128
-		$found=true;
129
-		$option.=(empty($option)?'':'_').'payments_'.$argv[$key+1].'_'.$argv[$key+2];
130
-		$filter[]='payments';
131
-
132
-		$paymentdateafter=dol_stringtotime($argv[$key+1].'000000');
133
-		$paymentdatebefore=dol_stringtotime($argv[$key+2].'235959');
134
-		if (empty($paymentdateafter) || empty($paymentdatebefore))
135
-		{
136
-			print 'Error: Bad date format or value'."\n";
137
-			exit(-1);
138
-		}
139
-		print 'Rebuild PDF for invoices with at least one payment between '.dol_print_date($paymentdateafter,'day','gmt')." and ".dol_print_date($paymentdatebefore,'day','gmt').".\n";
140
-	}
141
-
142
-	if ($value == 'filter=nopayment')
143
-	{
144
-		$found=true;
145
-		$option.=(empty($option)?'':'_').'nopayment';
146
-		$filter[]='nopayment';
147
-
148
-		print 'Rebuild PDF for invoices with no payment done yet.'."\n";
149
-	}
150
-
151
-	if ($value == 'filter=bank')
152
-	{
153
-		$found=true;
154
-		$option.=(empty($option)?'':'_').'bank_'.$argv[$key+1];
155
-		$filter[]='bank';
156
-
157
-		$paymentonbankref=$argv[$key+1];
158
-		$bankaccount=new Account($db);
159
-		$result=$bankaccount->fetch(0,$paymentonbankref);
160
-		if ($result <= 0)
161
-		{
162
-			print 'Error: Bank account with ref "'.$paymentonbankref.'" not found'."\n";
163
-			exit(-1);
164
-		}
165
-		$paymentonbankid=$bankaccount->id;
166
-		print 'Rebuild PDF for invoices with at least one payment on financial account '.$bankaccount->ref."\n";
167
-	}
168
-
169
-	if ($value == 'filter=nodeposit')
78
+    $found=false;
79
+
80
+    // Define options
81
+    if (preg_match('/^lang=/i',$value))
82
+    {
83
+        $found=true;
84
+        $valarray=explode('=',$value);
85
+        $newlangid=$valarray[1];
86
+        print 'Use language '.$newlangid.".\n";
87
+    }
88
+    if (preg_match('/^prefix=/i',$value))
89
+    {
90
+        $found=true;
91
+        $valarray=explode('=',$value);
92
+        $fileprefix=$valarray[1];
93
+        print 'Use prefix for filename '.$fileprefix.".\n";
94
+    }
95
+
96
+    if (preg_match('/^regenerate=(.*)/i',$value,$reg))
97
+    {
98
+        if (! in_array($reg[1],array('','0','no')))
99
+        {
100
+            $found=true;
101
+            $regenerate=$reg[1];
102
+            print 'Regeneration of PDF is requested with template '.$regenerate."\n";
103
+        }
104
+    }
105
+
106
+    if ($value == 'filter=all')
107
+    {
108
+        $found=true;
109
+        $option.=(empty($option)?'':'_').'all';
110
+        $filter[]='all';
111
+
112
+        print 'Rebuild PDF for all invoices'."\n";
113
+    }
114
+
115
+    if ($value == 'filter=date')
116
+    {
117
+        $found=true;
118
+        $option.=(empty($option)?'':'_').'date_'.$argv[$key+1].'_'.$argv[$key+2];
119
+        $filter[]='date';
120
+
121
+        $dateafterdate=dol_stringtotime($argv[$key+1]);
122
+        $datebeforedate=dol_stringtotime($argv[$key+2]);
123
+        print 'Rebuild PDF for invoices validated between '.dol_print_date($dateafterdate,'day','gmt')." and ".dol_print_date($datebeforedate,'day','gmt').".\n";
124
+    }
125
+
126
+    if ($value == 'filter=payments')
127
+    {
128
+        $found=true;
129
+        $option.=(empty($option)?'':'_').'payments_'.$argv[$key+1].'_'.$argv[$key+2];
130
+        $filter[]='payments';
131
+
132
+        $paymentdateafter=dol_stringtotime($argv[$key+1].'000000');
133
+        $paymentdatebefore=dol_stringtotime($argv[$key+2].'235959');
134
+        if (empty($paymentdateafter) || empty($paymentdatebefore))
135
+        {
136
+            print 'Error: Bad date format or value'."\n";
137
+            exit(-1);
138
+        }
139
+        print 'Rebuild PDF for invoices with at least one payment between '.dol_print_date($paymentdateafter,'day','gmt')." and ".dol_print_date($paymentdatebefore,'day','gmt').".\n";
140
+    }
141
+
142
+    if ($value == 'filter=nopayment')
143
+    {
144
+        $found=true;
145
+        $option.=(empty($option)?'':'_').'nopayment';
146
+        $filter[]='nopayment';
147
+
148
+        print 'Rebuild PDF for invoices with no payment done yet.'."\n";
149
+    }
150
+
151
+    if ($value == 'filter=bank')
152
+    {
153
+        $found=true;
154
+        $option.=(empty($option)?'':'_').'bank_'.$argv[$key+1];
155
+        $filter[]='bank';
156
+
157
+        $paymentonbankref=$argv[$key+1];
158
+        $bankaccount=new Account($db);
159
+        $result=$bankaccount->fetch(0,$paymentonbankref);
160
+        if ($result <= 0)
161
+        {
162
+            print 'Error: Bank account with ref "'.$paymentonbankref.'" not found'."\n";
163
+            exit(-1);
164
+        }
165
+        $paymentonbankid=$bankaccount->id;
166
+        print 'Rebuild PDF for invoices with at least one payment on financial account '.$bankaccount->ref."\n";
167
+    }
168
+
169
+    if ($value == 'filter=nodeposit')
170 170
     {
171 171
         $found=true;
172 172
         $option.=(empty($option)?'':'_').'nodeposit';
@@ -193,48 +193,48 @@  discard block
 block discarded – undo
193 193
 
194 194
     if ($value == 'filter=excludethirdparties')
195 195
     {
196
-    	$found=true;
197
-    	$filter[]='excludethirdparties';
196
+        $found=true;
197
+        $filter[]='excludethirdparties';
198 198
 
199
-    	$thirdpartiesid=explode(',',$argv[$key+1]);
200
-    	print 'Exclude thirdparties with id in list ('.join(',',$thirdpartiesid).").\n";
199
+        $thirdpartiesid=explode(',',$argv[$key+1]);
200
+        print 'Exclude thirdparties with id in list ('.join(',',$thirdpartiesid).").\n";
201 201
 
202
-    	$option.=(empty($option)?'':'_').'excludethirdparties'.join('-',$thirdpartiesid);
202
+        $option.=(empty($option)?'':'_').'excludethirdparties'.join('-',$thirdpartiesid);
203 203
     }
204 204
     if ($value == 'filter=onlythirdparties')
205 205
     {
206
-    	$found=true;
207
-    	$filter[]='onlythirdparties';
206
+        $found=true;
207
+        $filter[]='onlythirdparties';
208 208
 
209
-    	$thirdpartiesid=explode(',',$argv[$key+1]);
210
-    	print 'Only thirdparties with id in list ('.join(',',$thirdpartiesid).").\n";
209
+        $thirdpartiesid=explode(',',$argv[$key+1]);
210
+        print 'Only thirdparties with id in list ('.join(',',$thirdpartiesid).").\n";
211 211
 
212
-    	$option.=(empty($option)?'':'_').'onlythirdparty'.join('-',$thirdpartiesid);
212
+        $option.=(empty($option)?'':'_').'onlythirdparty'.join('-',$thirdpartiesid);
213 213
     }
214 214
 
215
-	if (! $found && preg_match('/filter=/i',$value))
216
-	{
217
-		usage();
218
-		exit(-1);
219
-	}
215
+    if (! $found && preg_match('/filter=/i',$value))
216
+    {
217
+        usage();
218
+        exit(-1);
219
+    }
220 220
 }
221 221
 
222 222
 // Check if an option and a filter has been provided
223 223
 if (empty($option) && count($filter) <= 0)
224 224
 {
225
-	usage();
226
-	exit(-1);
225
+    usage();
226
+    exit(-1);
227 227
 }
228 228
 // Check if there is no uncompatible choice
229 229
 if (in_array('payments',$filter) && in_array('nopayment',$filter))
230 230
 {
231
-	usage();
232
-	exit(-1);
231
+    usage();
232
+    exit(-1);
233 233
 }
234 234
 if (in_array('bank',$filter) && in_array('nopayment',$filter))
235 235
 {
236
-	usage();
237
-	exit(-1);
236
+    usage();
237
+    exit(-1);
238 238
 }
239 239
 
240 240
 
@@ -248,13 +248,13 @@  discard block
 block discarded – undo
248 248
 
249 249
 if ($result >= 0)
250 250
 {
251
-	$error=0;
252
-	print '--- end ok'."\n";
251
+    $error=0;
252
+    print '--- end ok'."\n";
253 253
 }
254 254
 else
255 255
 {
256
-	$error=$result;
257
-	print '--- end error code='.$error."\n";
256
+    $error=$result;
257
+    print '--- end error code='.$error."\n";
258 258
 }
259 259
 
260 260
 $db->close();
@@ -270,20 +270,20 @@  discard block
 block discarded – undo
270 270
  */
271 271
 function usage()
272 272
 {
273
-	global $script_file;
273
+    global $script_file;
274 274
 
275 275
     print "Rebuild PDF files for some invoices and merge PDF files into one.\n";
276
-	print "\n";
277
-	print "To build/merge PDF for invoices in a date range:\n";
278
-	print "Usage:   ".$script_file." filter=date dateafter datebefore\n";
279
-	print "To build/merge PDF for invoices with at least one payment in a date range:\n";
280
-	print "Usage:   ".$script_file." filter=payments dateafter datebefore\n";
281
-	print "To build/merge PDF for invoices with at least one payment onto a bank account:\n";
282
-	print "Usage:   ".$script_file." filter=bank bankref\n";
283
-	print "To build/merge PDF for all invoices, use filter=all\n";
284
-	print "Usage:   ".$script_file." filter=all\n";
285
-	print "To build/merge PDF for invoices with no payments, use filter=nopayment\n";
286
-	print "Usage:   ".$script_file." filter=nopayment\n";
276
+    print "\n";
277
+    print "To build/merge PDF for invoices in a date range:\n";
278
+    print "Usage:   ".$script_file." filter=date dateafter datebefore\n";
279
+    print "To build/merge PDF for invoices with at least one payment in a date range:\n";
280
+    print "Usage:   ".$script_file." filter=payments dateafter datebefore\n";
281
+    print "To build/merge PDF for invoices with at least one payment onto a bank account:\n";
282
+    print "Usage:   ".$script_file." filter=bank bankref\n";
283
+    print "To build/merge PDF for all invoices, use filter=all\n";
284
+    print "Usage:   ".$script_file." filter=all\n";
285
+    print "To build/merge PDF for invoices with no payments, use filter=nopayment\n";
286
+    print "Usage:   ".$script_file." filter=nopayment\n";
287 287
     print "To exclude credit notes, use filter=nocreditnote\n";
288 288
     print "To exclude replacement invoices, use filter=noreplacement\n";
289 289
     print "To exclude deposit invoices, use filter=nodeposit\n";
@@ -293,8 +293,8 @@  discard block
 block discarded – undo
293 293
     print "To generate invoices in a language, use lang=xx_XX\n";
294 294
     print "To set prefix of generated file name, use prefix=myfileprefix\n";
295 295
     print "\n";
296
-	print "Example: ".$script_file." filter=payments 20080101 20081231 lang=fr_FR regenerate=crabe\n";
297
-	print "Example: ".$script_file." filter=all lang=en_US\n";
298
-	print "\n";
299
-	print "Note that some filters can be cumulated.\n";
296
+    print "Example: ".$script_file." filter=payments 20080101 20081231 lang=fr_FR regenerate=crabe\n";
297
+    print "Example: ".$script_file." filter=all lang=en_US\n";
298
+    print "\n";
299
+    print "Note that some filters can be cumulated.\n";
300 300
 }
Please login to merge, or discard this patch.
dolibarr/scripts/invoices/email_unpaid_invoices_to_representatives.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -33,17 +33,17 @@  discard block
 block discarded – undo
33 33
 $sapi_type = php_sapi_name();
34 34
 if (substr($sapi_type, 0, 3) == 'cgi') {
35 35
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
36
-	exit(-1);
36
+    exit(-1);
37 37
 }
38 38
 
39 39
 if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')))
40 40
 {
41
-	print "Usage: $script_file (test|confirm) [delay]\n";
42
-	print "\n";
43
-	print "Send an email to users to remind all unpaid customer invoices user is sale representative for.\n";
44
-	print "If you choose 'test' mode, no emails are sent.\n";
45
-	print "If you add a delay (nb of days), only invoice with due date < today + delay are included.\n";
46
-	exit(-1);
41
+    print "Usage: $script_file (test|confirm) [delay]\n";
42
+    print "\n";
43
+    print "Send an email to users to remind all unpaid customer invoices user is sale representative for.\n";
44
+    print "If you choose 'test' mode, no emails are sent.\n";
45
+    print "If you add a delay (nb of days), only invoice with due date < today + delay are included.\n";
46
+    exit(-1);
47 47
 }
48 48
 $mode=$argv[1];
49 49
 
@@ -96,9 +96,9 @@  discard block
 block discarded – undo
96 96
     $i = 0;
97 97
     $oldemail = 'none'; $olduid = 0; $oldlang='';
98 98
     $total = 0; $foundtoprocess = 0;
99
-	print "We found ".$num." couples (unpayed validated invoice - sale representative) qualified\n";
99
+    print "We found ".$num." couples (unpayed validated invoice - sale representative) qualified\n";
100 100
     dol_syslog("We found ".$num." couples (unpayed validated invoice - sale representative) qualified");
101
-	$message='';
101
+    $message='';
102 102
 
103 103
     if ($num)
104 104
     {
@@ -111,11 +111,11 @@  discard block
 block discarded – undo
111 111
                 // Break onto sales representative (new email or uid)
112 112
                 if (dol_strlen($oldemail) && $oldemail != 'none')
113 113
                 {
114
-                   	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative);
114
+                        envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative);
115 115
                 }
116 116
                 else
117
-				{
118
-					if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
117
+                {
118
+                    if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
119 119
                 }
120 120
                 $oldemail = $obj->email;
121 121
                 $olduid = $obj->uid;
@@ -137,16 +137,16 @@  discard block
 block discarded – undo
137 137
 
138 138
             if (dol_strlen($obj->email))
139 139
             {
140
-            	$message .= $outputlangs->trans("Invoice")." ".$obj->ref." : ".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)." : ".$obj->name."\n";
141
-            	dol_syslog("email_unpaid_invoices_to_representatives.php: ".$obj->email);
142
-            	$foundtoprocess++;
140
+                $message .= $outputlangs->trans("Invoice")." ".$obj->ref." : ".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)." : ".$obj->name."\n";
141
+                dol_syslog("email_unpaid_invoices_to_representatives.php: ".$obj->email);
142
+                $foundtoprocess++;
143 143
             }
144 144
             print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date),'day')." (linked to company ".$obj->name.", sale representative ".dolGetFirstLastname($obj->firstname, $obj->lastname).", email ".$obj->email.", lang ".$outputlangs->defaultlang."): ";
145 145
             if (dol_strlen($obj->email)) print "qualified.";
146 146
             else print "disqualified (no email).";
147
-			print "\n";
147
+            print "\n";
148 148
 
149
-			unset($outputlangs);
149
+            unset($outputlangs);
150 150
 
151 151
             $total += $obj->total_ttc;
152 152
             $i++;
@@ -157,16 +157,16 @@  discard block
 block discarded – undo
157 157
         {
158 158
             if (dol_strlen($oldemail) && $oldemail != 'none')	// Break onto email (new email)
159 159
             {
160
-       			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative);
160
+                    envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldsalerepresentative);
161 161
             }
162 162
             else
163
-			{
164
-            	if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
163
+            {
164
+                if ($oldemail != 'none') print "- No email sent for ".$oldsalerepresentative.", total: ".$total."\n";
165 165
             }
166 166
         }
167 167
     }
168 168
     else
169
-	{
169
+    {
170 170
         print "No unpaid invoices (for companies linked to a particular commercial dolibarr user) found\n";
171 171
     }
172 172
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
     $sendto = $oldemail;
208 208
     $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
209 209
     $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
210
-	$msgishtml = -1;
210
+    $msgishtml = -1;
211 211
 
212 212
     print "- Send email for ".$oldsalerepresentative." (".$oldemail."), total: ".$total."\n";
213 213
     dol_syslog("email_unpaid_invoices_to_representatives.php: send mail to ".$oldemail);
@@ -219,19 +219,19 @@  discard block
 block discarded – undo
219 219
     $allmessage='';
220 220
     if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER))
221 221
     {
222
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
222
+        $allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
223 223
     }
224 224
     else
225 225
     {
226
-    	$allmessage.= $newlangs->transnoentities("ListOfYourUnpaidInvoices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
227
-    	$allmessage.= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices").($usehtml?"<br>\n":"\n");
226
+        $allmessage.= $newlangs->transnoentities("ListOfYourUnpaidInvoices").($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
227
+        $allmessage.= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices").($usehtml?"<br>\n":"\n");
228 228
     }
229 229
     $allmessage.= $message.($usehtml?"<br>\n":"\n");
230 230
     $allmessage.= $langs->trans("Total")." = ".price($total,0,$newlangs,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
231 231
     if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER))
232 232
     {
233
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER;
234
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
233
+        $allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER;
234
+        if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) $usehtml+=1;
235 235
     }
236 236
 
237 237
     $mail = new CMailFile(
@@ -253,19 +253,19 @@  discard block
 block discarded – undo
253 253
     // Send or not email
254 254
     if ($mode == 'confirm')
255 255
     {
256
-    	$result=$mail->sendfile();
257
-    	if (! $result)
258
-    	{
259
-    		print "Error sending email ".$mail->error."\n";
260
-    		dol_syslog("Error sending email ".$mail->error."\n");
261
-    	}
256
+        $result=$mail->sendfile();
257
+        if (! $result)
258
+        {
259
+            print "Error sending email ".$mail->error."\n";
260
+            dol_syslog("Error sending email ".$mail->error."\n");
261
+        }
262 262
     }
263 263
     else
264 264
     {
265
-    	print "No email sent (test mode)\n";
266
-    	dol_syslog("No email sent (test mode)");
267
-    	$mail->dump_mail();
268
-    	$result=1;
265
+        print "No email sent (test mode)\n";
266
+        dol_syslog("No email sent (test mode)");
267
+        $mail->dump_mail();
268
+        $result=1;
269 269
     }
270 270
 
271 271
     if ($result)
Please login to merge, or discard this patch.
dolibarr/scripts/invoices/email_unpaid_invoices_to_customers.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -33,18 +33,18 @@  discard block
 block discarded – undo
33 33
 $sapi_type = php_sapi_name();
34 34
 if (substr($sapi_type, 0, 3) == 'cgi') {
35 35
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
36
-	exit(-1);
36
+    exit(-1);
37 37
 }
38 38
 
39 39
 if (! isset($argv[2]) || ! $argv[2] || ! in_array($argv[1],array('test','confirm')) || ! in_array($argv[2],array('thirdparties','contacts')))
40 40
 {
41
-	print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay] [after]\n";
42
-	print "\n";
43
-	print "Send an email to customers to remind all unpaid customer invoices.\n";
44
-	print "If you choose 'test' mode, no emails are sent.\n";
45
-	print "If you add param delay (nb of days), only invoice with due date < today + delay are included.\n";
46
-	print "If you add param after (nb of days), only invoice with due date >= today + delay are included.\n";
47
-	exit(-1);
41
+    print "Usage: $script_file (test|confirm) (thirdparties|contacts) [delay] [after]\n";
42
+    print "\n";
43
+    print "Send an email to customers to remind all unpaid customer invoices.\n";
44
+    print "If you choose 'test' mode, no emails are sent.\n";
45
+    print "If you add param delay (nb of days), only invoice with due date < today + delay are included.\n";
46
+    print "If you add param after (nb of days), only invoice with due date >= today + delay are included.\n";
47
+    exit(-1);
48 48
 }
49 49
 $mode=$argv[1];
50 50
 $targettype=$argv[2];
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
     $total = 0; $foundtoprocess = 0;
103 103
     $trackthirdpartiessent = array();
104 104
 
105
-	print "We found ".$num." couples (unpayed validated invoices-".$targettype.") qualified\n";
105
+    print "We found ".$num." couples (unpayed validated invoices-".$targettype.") qualified\n";
106 106
     dol_syslog("We found ".$num." couples (unpayed validated invoices-".$targettype.") qualified");
107
-	$message='';
107
+    $message='';
108 108
 
109 109
     if ($num)
110 110
     {
@@ -116,25 +116,25 @@  discard block
 block discarded – undo
116 116
 
117 117
             // Check if this record is a break after previous one
118 118
             $startbreak=false;
119
-			if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true;
120
-			if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true;
121
-			if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true;
119
+            if ($newemail <> $oldemail || $oldemail == 'none') $startbreak=true;
120
+            if ($obj->sid && $obj->sid <> $oldsid) $startbreak=true;
121
+            if ($obj->cid && $obj->cid <> $oldcid) $startbreak=true;
122 122
 
123 123
             if ($startbreak)
124 124
             {
125 125
                 // Break onto sales representative (new email or cid)
126 126
                 if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))
127 127
                 {
128
-                   	envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget);
129
-                   	$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
128
+                        envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget);
129
+                        $trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
130 130
                 }
131 131
                 else
132
-				{
133
-                	if ($oldemail != 'none')
134
-                	{
135
-                		if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n";
136
-                		else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
137
-                	}
132
+                {
133
+                    if ($oldemail != 'none')
134
+                    {
135
+                        if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n";
136
+                        else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
137
+                    }
138 138
                 }
139 139
                 $oldemail = $newemail;
140 140
                 $oldsid  = $obj->sid;
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 
158 158
             if (dol_strlen($newemail))
159 159
             {
160
-            	$message .= $outputlangs->trans("Invoice")." ".$obj->ref." : ".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)."\n";
161
-            	dol_syslog("email_unpaid_invoices_to_customers.php: ".$newemail." ".$message);
162
-            	$foundtoprocess++;
160
+                $message .= $outputlangs->trans("Invoice")." ".$obj->ref." : ".price($obj->total_ttc,0,$outputlangs,0,0,-1,$conf->currency)."\n";
161
+                dol_syslog("email_unpaid_invoices_to_customers.php: ".$newemail." ".$message);
162
+                $foundtoprocess++;
163 163
             }
164 164
             print "Unpaid invoice ".$obj->ref.", price ".price2num($obj->total_ttc).", due date ".dol_print_date($db->jdate($obj->due_date),'day').", customer id ".$obj->sid." ".$obj->name.", ".($obj->cid?"contact id ".$obj->cid." ".$obj->clastname." ".$obj->cfirstname.", ":"")."email ".$newemail.", lang ".$outputlangs->defaultlang.": ";
165 165
             if (dol_strlen($newemail)) print "qualified.";
@@ -178,21 +178,21 @@  discard block
 block discarded – undo
178 178
         {
179 179
             if (dol_strlen($oldemail) && $oldemail != 'none' && empty($trackthirdpartiessent[$oldsid.'|'.$oldemail]))	// Break onto email (new email)
180 180
             {
181
-       			envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget);
182
-       			$trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
181
+                    envoi_mail($mode,$oldemail,$message,$total,$oldlang,$oldtarget);
182
+                    $trackthirdpartiessent[$oldsid.'|'.$oldemail]='contact id '.$oldcid;
183 183
             }
184 184
             else
185
-			{
186
-            	if ($oldemail != 'none')
187
-            	{
188
-            		if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n";
189
-            		else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
190
-            	}
185
+            {
186
+                if ($oldemail != 'none')
187
+                {
188
+                    if (empty($trackthirdpartiessent[$oldsid.'|'.$oldemail])) print "- No email sent for '".$oldtarget."', total: ".$total."\n";
189
+                    else print "- No email sent for '".$oldtarget."', total: ".$total." (already sent to ".$trackthirdpartiessent[$oldsid.'|'.$oldemail].")\n";
190
+                }
191 191
             }
192 192
         }
193 193
     }
194 194
     else
195
-	{
195
+    {
196 196
         print "No unpaid invoices found\n";
197 197
     }
198 198
 
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
     $sendto = $oldemail;
234 234
     $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
235 235
     $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
236
-	$msgishtml = -1;
236
+    $msgishtml = -1;
237 237
 
238 238
     print "- Send email to '".$oldtarget."' (".$oldemail."), total: ".$total."\n";
239 239
     dol_syslog("email_unpaid_invoices_to_customers.php: send mail to ".$oldemail);
@@ -245,20 +245,20 @@  discard block
 block discarded – undo
245 245
     $allmessage='';
246 246
     if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER))
247 247
     {
248
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER;
248
+        $allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER;
249 249
     }
250 250
     else
251 251
     {
252
-    	$allmessage.= "Dear customer".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
253
-    	$allmessage.= "Please, find a summary of the bills with pending payments from you.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
254
-    	$allmessage.= "Note: This list contains only unpaid invoices.".($usehtml?"<br>\n":"\n");
252
+        $allmessage.= "Dear customer".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
253
+        $allmessage.= "Please, find a summary of the bills with pending payments from you.".($usehtml?"<br>\n":"\n").($usehtml?"<br>\n":"\n");
254
+        $allmessage.= "Note: This list contains only unpaid invoices.".($usehtml?"<br>\n":"\n");
255 255
     }
256 256
     $allmessage.= $message.($usehtml?"<br>\n":"\n");
257 257
     $allmessage.= $langs->trans("Total")." = ".price($total,0,$userlang,0,0,-1,$conf->currency).($usehtml?"<br>\n":"\n");
258 258
     if (! empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER))
259 259
     {
260
-    	$allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER;
261
-    	if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml+=1;
260
+        $allmessage.=$conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER;
261
+        if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER)) $usehtml+=1;
262 262
     }
263 263
 
264 264
     $mail = new CMailFile(
@@ -280,19 +280,19 @@  discard block
 block discarded – undo
280 280
     // Send or not email
281 281
     if ($mode == 'confirm')
282 282
     {
283
-    	$result=$mail->sendfile();
284
-    	if (! $result)
285
-    	{
286
-    		print "Error sending email ".$mail->error."\n";
287
-    		dol_syslog("Error sending email ".$mail->error."\n");
288
-    	}
283
+        $result=$mail->sendfile();
284
+        if (! $result)
285
+        {
286
+            print "Error sending email ".$mail->error."\n";
287
+            dol_syslog("Error sending email ".$mail->error."\n");
288
+        }
289 289
     }
290 290
     else
291 291
     {
292
-    	print "No email sent (test mode)\n";
293
-    	dol_syslog("No email sent (test mode)");
294
-    	$mail->dump_mail();
295
-    	$result=1;
292
+        print "No email sent (test mode)\n";
293
+        dol_syslog("No email sent (test mode)");
294
+        $mail->dump_mail();
295
+        $result=1;
296 296
     }
297 297
 
298 298
     unset($newlangs);
Please login to merge, or discard this patch.
dolibarr/scripts/user/sync_users_dolibarr2ldap.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -31,12 +31,12 @@  discard block
 block discarded – undo
31 31
 // Test if batch mode
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
33 33
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
34
-	exit(-1);
34
+    exit(-1);
35 35
 }
36 36
 
37 37
 if (! isset($argv[1]) || ! $argv[1]) {
38 38
     print "Usage: $script_file now\n";
39
-	exit(-1);
39
+    exit(-1);
40 40
 }
41 41
 $now=$argv[1];
42 42
 
@@ -71,53 +71,53 @@  discard block
 block discarded – undo
71 71
 $resql = $db->query($sql);
72 72
 if ($resql)
73 73
 {
74
-	$num = $db->num_rows($resql);
75
-	$i = 0;
74
+    $num = $db->num_rows($resql);
75
+    $i = 0;
76 76
 
77
-	$ldap=new Ldap();
78
-	$ldap->connect_bind();
77
+    $ldap=new Ldap();
78
+    $ldap->connect_bind();
79 79
 
80
-	while ($i < $num)
81
-	{
82
-		$ldap->error="";
80
+    while ($i < $num)
81
+    {
82
+        $ldap->error="";
83 83
 
84
-		$obj = $db->fetch_object($resql);
84
+        $obj = $db->fetch_object($resql);
85 85
 
86
-		$fuser = new User($db);
87
-		$fuser->fetch($obj->rowid);
86
+        $fuser = new User($db);
87
+        $fuser->fetch($obj->rowid);
88 88
 
89
-		print $langs->trans("UpdateUser")." rowid=".$fuser->id." ".$fuser->getFullName($langs);
89
+        print $langs->trans("UpdateUser")." rowid=".$fuser->id." ".$fuser->getFullName($langs);
90 90
 
91
-		$oldobject=$fuser;
91
+        $oldobject=$fuser;
92 92
 
93
-	    $oldinfo=$oldobject->_load_ldap_info();
94
-	    $olddn=$oldobject->_load_ldap_dn($oldinfo);
93
+        $oldinfo=$oldobject->_load_ldap_info();
94
+        $olddn=$oldobject->_load_ldap_dn($oldinfo);
95 95
 
96
-	    $info=$fuser->_load_ldap_info();
97
-		$dn=$fuser->_load_ldap_dn($info);
96
+        $info=$fuser->_load_ldap_info();
97
+        $dn=$fuser->_load_ldap_dn($info);
98 98
 
99
-		$result=$ldap->add($dn,$info,$user);	// Wil fail if already exists
100
-		$result=$ldap->update($dn,$info,$user,$olddn);
101
-		if ($result > 0)
102
-		{
103
-			print " - ".$langs->trans("OK");
104
-		}
105
-		else
106
-		{
107
-			$error++;
108
-			print " - ".$langs->trans("KO").' - '.$ldap->error;
109
-		}
110
-		print "\n";
99
+        $result=$ldap->add($dn,$info,$user);	// Wil fail if already exists
100
+        $result=$ldap->update($dn,$info,$user,$olddn);
101
+        if ($result > 0)
102
+        {
103
+            print " - ".$langs->trans("OK");
104
+        }
105
+        else
106
+        {
107
+            $error++;
108
+            print " - ".$langs->trans("KO").' - '.$ldap->error;
109
+        }
110
+        print "\n";
111 111
 
112
-		$i++;
113
-	}
112
+        $i++;
113
+    }
114 114
 
115
-	$ldap->unbind();
116
-	$ldap->close();
115
+    $ldap->unbind();
116
+    $ldap->close();
117 117
 }
118 118
 else
119 119
 {
120
-	dol_print_error($db);
120
+    dol_print_error($db);
121 121
 }
122 122
 
123 123
 exit($error);
Please login to merge, or discard this patch.
dolibarr/scripts/user/sync_users_ldap2dolibarr.php 1 patch
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 // Test if batch mode
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
33 33
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
34
-	exit(-1);
34
+    exit(-1);
35 35
 }
36 36
 
37 37
 require_once $path."../../htdocs/master.inc.php";
@@ -58,41 +58,41 @@  discard block
 block discarded – undo
58 58
 
59 59
 // List of fields to get from LDAP
60 60
 $required_fields = array(
61
-	$conf->global->LDAP_KEY_USERS,
62
-	$conf->global->LDAP_FIELD_FULLNAME,
63
-	$conf->global->LDAP_FIELD_NAME,
64
-	$conf->global->LDAP_FIELD_FIRSTNAME,
65
-	$conf->global->LDAP_FIELD_LOGIN,
66
-	$conf->global->LDAP_FIELD_LOGIN_SAMBA,
67
-	$conf->global->LDAP_FIELD_PASSWORD,
68
-	$conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
69
-	$conf->global->LDAP_FIELD_PHONE,
70
-	$conf->global->LDAP_FIELD_FAX,
71
-	$conf->global->LDAP_FIELD_MOBILE,
72
-	//$conf->global->LDAP_FIELD_ADDRESS,
73
-	//$conf->global->LDAP_FIELD_ZIP,
74
-	//$conf->global->LDAP_FIELD_TOWN,
75
-	//$conf->global->LDAP_FIELD_COUNTRY,
76
-	$conf->global->LDAP_FIELD_MAIL,
77
-	$conf->global->LDAP_FIELD_TITLE,
78
-	$conf->global->LDAP_FIELD_DESCRIPTION,
79
-	$conf->global->LDAP_FIELD_SID
61
+    $conf->global->LDAP_KEY_USERS,
62
+    $conf->global->LDAP_FIELD_FULLNAME,
63
+    $conf->global->LDAP_FIELD_NAME,
64
+    $conf->global->LDAP_FIELD_FIRSTNAME,
65
+    $conf->global->LDAP_FIELD_LOGIN,
66
+    $conf->global->LDAP_FIELD_LOGIN_SAMBA,
67
+    $conf->global->LDAP_FIELD_PASSWORD,
68
+    $conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
69
+    $conf->global->LDAP_FIELD_PHONE,
70
+    $conf->global->LDAP_FIELD_FAX,
71
+    $conf->global->LDAP_FIELD_MOBILE,
72
+    //$conf->global->LDAP_FIELD_ADDRESS,
73
+    //$conf->global->LDAP_FIELD_ZIP,
74
+    //$conf->global->LDAP_FIELD_TOWN,
75
+    //$conf->global->LDAP_FIELD_COUNTRY,
76
+    $conf->global->LDAP_FIELD_MAIL,
77
+    $conf->global->LDAP_FIELD_TITLE,
78
+    $conf->global->LDAP_FIELD_DESCRIPTION,
79
+    $conf->global->LDAP_FIELD_SID
80 80
 );
81 81
 
82 82
 // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
83 83
 $required_fields=array_unique(array_values(array_filter($required_fields, "dolValidElement")));
84 84
 
85 85
 if (! isset($argv[1])) {
86
-	print "Usage:  $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n";
86
+    print "Usage:  $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n";
87 87
     exit(-1);
88 88
 }
89 89
 
90 90
 foreach($argv as $key => $val)
91 91
 {
92
-	if ($val == 'commitiferror') $forcecommit=1;
93
-	if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
94
-	if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]);
95
-	if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
92
+    if ($val == 'commitiferror') $forcecommit=1;
93
+    if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
94
+    if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]);
95
+    if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
96 96
 }
97 97
 
98 98
 print "Mails sending disabled (useless in batch mode)\n";
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
 
121 121
 if (! $confirmed)
122 122
 {
123
-	print "Hit Enter to continue or CTRL+C to stop...\n";
124
-	$input = trim(fgets(STDIN));
123
+    print "Hit Enter to continue or CTRL+C to stop...\n";
124
+    $input = trim(fgets(STDIN));
125 125
 }
126 126
 
127 127
 if (empty($conf->global->LDAP_USER_DN))
128 128
 {
129
-	print $langs->trans("Error").': '.$langs->trans("LDAP setup for users not defined inside Dolibarr");
130
-	exit(-1);
129
+    print $langs->trans("Error").': '.$langs->trans("LDAP setup for users not defined inside Dolibarr");
130
+    exit(-1);
131 131
 }
132 132
 
133 133
 
@@ -141,27 +141,27 @@  discard block
 block discarded – undo
141 141
 $resql=$db->query($sql);
142 142
 if ($resql)
143 143
 {
144
-	$num = $db->num_rows($resql);
145
-	$i = 0;
146
-	if ($num)
147
-	{
148
-		while ($i < $num)
149
-		{
150
-			$obj = $db->fetch_object($resql);
151
-			if ($obj)
152
-			{
153
-				//print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n";
154
-				$hashlib2rowid[strtolower($obj->label)]=$obj->rowid;
155
-				$countries[$obj->rowid]=array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code);
156
-			}
157
-			$i++;
158
-		}
159
-	}
144
+    $num = $db->num_rows($resql);
145
+    $i = 0;
146
+    if ($num)
147
+    {
148
+        while ($i < $num)
149
+        {
150
+            $obj = $db->fetch_object($resql);
151
+            if ($obj)
152
+            {
153
+                //print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n";
154
+                $hashlib2rowid[strtolower($obj->label)]=$obj->rowid;
155
+                $countries[$obj->rowid]=array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code);
156
+            }
157
+            $i++;
158
+        }
159
+    }
160 160
 }
161 161
 else
162 162
 {
163
-	dol_print_error($db);
164
-	exit(-1);
163
+    dol_print_error($db);
164
+    exit(-1);
165 165
 }
166 166
 
167 167
 
@@ -170,44 +170,44 @@  discard block
 block discarded – undo
170 170
 $result = $ldap->connect_bind();
171 171
 if ($result >= 0)
172 172
 {
173
-	$justthese=array();
174
-
175
-
176
-	// We disable synchro Dolibarr-LDAP
177
-	$conf->global->LDAP_SYNCHRO_ACTIVE=0;
178
-
179
-	$ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 'user');	// Fiter on 'user' filter param
180
-	if (is_array($ldaprecords))
181
-	{
182
-		$db->begin();
183
-
184
-		// Warning $ldapuser has a key in lowercase
185
-		foreach ($ldaprecords as $key => $ldapuser)
186
-		{
187
-			// If login into exclude list, we discard record
188
-			if (in_array($ldapuser[$conf->global->LDAP_FIELD_LOGIN],$excludeuser))
189
-			{
190
-				print $langs->transnoentities("UserDiscarded").' # '.$key.': login='.$ldapuser[$conf->global->LDAP_FIELD_LOGIN].' --> Discarded'."\n";
191
-				continue;
192
-			}
193
-
194
-			$fuser = new User($db);
195
-
196
-			if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) {
197
-				$fuser->fetch('','',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le SID
198
-			} else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) {
199
-				$fuser->fetch('',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le login
200
-			}
201
-
202
-			// Propriete membre
203
-			$fuser->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME];
204
-			$fuser->lastname=$ldapuser[$conf->global->LDAP_FIELD_NAME];
205
-			$fuser->login=$ldapuser[$conf->global->LDAP_FIELD_LOGIN];
206
-			$fuser->pass=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD];
207
-			$fuser->pass_indatabase_crypted=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED];
208
-
209
-			//$user->societe;
210
-			/*
173
+    $justthese=array();
174
+
175
+
176
+    // We disable synchro Dolibarr-LDAP
177
+    $conf->global->LDAP_SYNCHRO_ACTIVE=0;
178
+
179
+    $ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 'user');	// Fiter on 'user' filter param
180
+    if (is_array($ldaprecords))
181
+    {
182
+        $db->begin();
183
+
184
+        // Warning $ldapuser has a key in lowercase
185
+        foreach ($ldaprecords as $key => $ldapuser)
186
+        {
187
+            // If login into exclude list, we discard record
188
+            if (in_array($ldapuser[$conf->global->LDAP_FIELD_LOGIN],$excludeuser))
189
+            {
190
+                print $langs->transnoentities("UserDiscarded").' # '.$key.': login='.$ldapuser[$conf->global->LDAP_FIELD_LOGIN].' --> Discarded'."\n";
191
+                continue;
192
+            }
193
+
194
+            $fuser = new User($db);
195
+
196
+            if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) {
197
+                $fuser->fetch('','',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le SID
198
+            } else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) {
199
+                $fuser->fetch('',$ldapuser[$conf->global->LDAP_KEY_USERS]); // Chargement du user concerné par le login
200
+            }
201
+
202
+            // Propriete membre
203
+            $fuser->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME];
204
+            $fuser->lastname=$ldapuser[$conf->global->LDAP_FIELD_NAME];
205
+            $fuser->login=$ldapuser[$conf->global->LDAP_FIELD_LOGIN];
206
+            $fuser->pass=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD];
207
+            $fuser->pass_indatabase_crypted=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED];
208
+
209
+            //$user->societe;
210
+            /*
211 211
 			$fuser->address=$ldapuser[$conf->global->LDAP_FIELD_ADDRESS];
212 212
 			$fuser->zip=$ldapuser[$conf->global->LDAP_FIELD_ZIP];
213 213
 			$fuser->town=$ldapuser[$conf->global->LDAP_FIELD_TOWN];
@@ -216,93 +216,93 @@  discard block
 block discarded – undo
216 216
 			$fuser->country_code=$countries[$hashlib2rowid[strtolower($fuser->country)]]['code'];
217 217
 			*/
218 218
 
219
-			$fuser->office_phone=$ldapuser[$conf->global->LDAP_FIELD_PHONE];
220
-			$fuser->user_mobile=$ldapuser[$conf->global->LDAP_FIELD_MOBILE];
221
-			$fuser->office_fax=$ldapuser[$conf->global->LDAP_FIELD_FAX];
222
-			$fuser->email=$ldapuser[$conf->global->LDAP_FIELD_MAIL];
223
-			$fuser->ldap_sid=$ldapuser[$conf->global->LDAP_FIELD_SID];
224
-
225
-			$fuser->job=$ldapuser[$conf->global->LDAP_FIELD_TITLE];
226
-			$fuser->note=$ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION];
227
-			$fuser->admin=0;
228
-			$fuser->societe_id=0;
229
-			$fuser->contact_id=0;
230
-			$fuser->fk_member=0;
231
-
232
-			$fuser->statut=1;
233
-			// TODO : revoir la gestion du status
234
-			/*if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]))
219
+            $fuser->office_phone=$ldapuser[$conf->global->LDAP_FIELD_PHONE];
220
+            $fuser->user_mobile=$ldapuser[$conf->global->LDAP_FIELD_MOBILE];
221
+            $fuser->office_fax=$ldapuser[$conf->global->LDAP_FIELD_FAX];
222
+            $fuser->email=$ldapuser[$conf->global->LDAP_FIELD_MAIL];
223
+            $fuser->ldap_sid=$ldapuser[$conf->global->LDAP_FIELD_SID];
224
+
225
+            $fuser->job=$ldapuser[$conf->global->LDAP_FIELD_TITLE];
226
+            $fuser->note=$ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION];
227
+            $fuser->admin=0;
228
+            $fuser->societe_id=0;
229
+            $fuser->contact_id=0;
230
+            $fuser->fk_member=0;
231
+
232
+            $fuser->statut=1;
233
+            // TODO : revoir la gestion du status
234
+            /*if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]))
235 235
 			{
236 236
 				$fuser->datec=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
237 237
 				$fuser->datevalid=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
238 238
 				$fuser->statut=$ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS];
239 239
 			}*/
240
-			//if ($fuser->statut > 1) $fuser->statut=1;
241
-
242
-			//print_r($ldapuser);
243
-
244
-			if($fuser->id > 0) { // User update
245
-				print $langs->transnoentities("UserUpdate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
246
-				$res=$fuser->update($user);
247
-
248
-				if ($res < 0)
249
-				{
250
-					$error++;
251
-					print ' --> '.$res.' '.$fuser->error;
252
-				}
253
-				else
254
-				{
255
-					print ' --> Updated user id='.$fuser->id.' login='.$fuser->login;
256
-				}
257
-			} else { // User creation
258
-				print $langs->transnoentities("UserCreate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
259
-				$res=$fuser->create($user);
260
-
261
-				if ($res > 0)
262
-				{
263
-					print ' --> Created user id='.$fuser->id.' login='.$fuser->login;
264
-				}
265
-				else
266
-				{
267
-					$error++;
268
-					print ' --> '.$res.' '.$fuser->error;
269
-				}
270
-			}
271
-			print "\n";
272
-			//print_r($fuser);
273
-
274
-			// Gestion des groupes
275
-			// TODO : revoir la gestion des groupes (ou script de sync groupes)
276
-			/*if(!$error) {
240
+            //if ($fuser->statut > 1) $fuser->statut=1;
241
+
242
+            //print_r($ldapuser);
243
+
244
+            if($fuser->id > 0) { // User update
245
+                print $langs->transnoentities("UserUpdate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
246
+                $res=$fuser->update($user);
247
+
248
+                if ($res < 0)
249
+                {
250
+                    $error++;
251
+                    print ' --> '.$res.' '.$fuser->error;
252
+                }
253
+                else
254
+                {
255
+                    print ' --> Updated user id='.$fuser->id.' login='.$fuser->login;
256
+                }
257
+            } else { // User creation
258
+                print $langs->transnoentities("UserCreate").' # '.$key.': login='.$fuser->login.', fullname='.$fuser->getFullName($langs);
259
+                $res=$fuser->create($user);
260
+
261
+                if ($res > 0)
262
+                {
263
+                    print ' --> Created user id='.$fuser->id.' login='.$fuser->login;
264
+                }
265
+                else
266
+                {
267
+                    $error++;
268
+                    print ' --> '.$res.' '.$fuser->error;
269
+                }
270
+            }
271
+            print "\n";
272
+            //print_r($fuser);
273
+
274
+            // Gestion des groupes
275
+            // TODO : revoir la gestion des groupes (ou script de sync groupes)
276
+            /*if(!$error) {
277 277
 				foreach ($ldapuser[$conf->global->LDAP_FIELD_USERGROUPS] as $groupdn) {
278 278
 					$groupdn;
279 279
 				}
280 280
 			}*/
281
-		}
282
-
283
-		if (! $error || $forcecommit)
284
-		{
285
-			if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n";
286
-			else print $langs->transnoentities("ErrorButCommitIsDone")."\n";
287
-			$db->commit();
288
-		}
289
-		else
290
-		{
291
-			print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n";
292
-			$db->rollback();
293
-		}
294
-		print "\n";
295
-	}
296
-	else
297
-	{
298
-		dol_print_error('',$ldap->error);
299
-		$error++;
300
-	}
281
+        }
282
+
283
+        if (! $error || $forcecommit)
284
+        {
285
+            if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n";
286
+            else print $langs->transnoentities("ErrorButCommitIsDone")."\n";
287
+            $db->commit();
288
+        }
289
+        else
290
+        {
291
+            print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n";
292
+            $db->rollback();
293
+        }
294
+        print "\n";
295
+    }
296
+    else
297
+    {
298
+        dol_print_error('',$ldap->error);
299
+        $error++;
300
+    }
301 301
 }
302 302
 else
303 303
 {
304
-	dol_print_error('',$ldap->error);
305
-	$error++;
304
+    dol_print_error('',$ldap->error);
305
+    $error++;
306 306
 }
307 307
 
308 308
 
@@ -317,6 +317,6 @@  discard block
 block discarded – undo
317 317
  */
318 318
 function dolValidElement($element)
319 319
 {
320
-	return (trim($element) != '');
320
+    return (trim($element) != '');
321 321
 }
322 322
 
Please login to merge, or discard this patch.
dolibarr/scripts/user/sync_groups_dolibarr2ldap.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -31,12 +31,12 @@  discard block
 block discarded – undo
31 31
 // Test if batch mode
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
33 33
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
34
-	exit(-1);
34
+    exit(-1);
35 35
 }
36 36
 
37 37
 if (! isset($argv[1]) || ! $argv[1]) {
38 38
     print "Usage: ".$script_file." now\n";
39
-	exit(-1);
39
+    exit(-1);
40 40
 }
41 41
 $now=$argv[1];
42 42
 
@@ -71,54 +71,54 @@  discard block
 block discarded – undo
71 71
 $resql = $db->query($sql);
72 72
 if ($resql)
73 73
 {
74
-	$num = $db->num_rows($resql);
75
-	$i = 0;
74
+    $num = $db->num_rows($resql);
75
+    $i = 0;
76 76
 
77
-	$ldap=new Ldap();
78
-	$ldap->connect_bind();
77
+    $ldap=new Ldap();
78
+    $ldap->connect_bind();
79 79
 
80
-	while ($i < $num)
81
-	{
82
-		$ldap->error="";
80
+    while ($i < $num)
81
+    {
82
+        $ldap->error="";
83 83
 
84
-		$obj = $db->fetch_object($resql);
84
+        $obj = $db->fetch_object($resql);
85 85
 
86
-		$fgroup = new UserGroup($db);
87
-		$fgroup->id = $obj->rowid;
88
-		$fgroup->fetch($fgroup->id);
86
+        $fgroup = new UserGroup($db);
87
+        $fgroup->id = $obj->rowid;
88
+        $fgroup->fetch($fgroup->id);
89 89
 
90
-		print $langs->trans("UpdateGroup")." rowid=".$fgroup->id." ".$fgroup->name;
90
+        print $langs->trans("UpdateGroup")." rowid=".$fgroup->id." ".$fgroup->name;
91 91
 
92
-		$oldobject=$fgroup;
92
+        $oldobject=$fgroup;
93 93
 
94
-	    $oldinfo=$oldobject->_load_ldap_info();
95
-	    $olddn=$oldobject->_load_ldap_dn($oldinfo);
94
+        $oldinfo=$oldobject->_load_ldap_info();
95
+        $olddn=$oldobject->_load_ldap_dn($oldinfo);
96 96
 
97
-	    $info=$fgroup->_load_ldap_info();
98
-		$dn=$fgroup->_load_ldap_dn($info);
97
+        $info=$fgroup->_load_ldap_info();
98
+        $dn=$fgroup->_load_ldap_dn($info);
99 99
 
100
-		$result=$ldap->add($dn,$info,$user);	// Wil fail if already exists
101
-		$result=$ldap->update($dn,$info,$user,$olddn);
102
-		if ($result > 0)
103
-		{
104
-			print " - ".$langs->trans("OK");
105
-		}
106
-		else
107
-		{
108
-			$error++;
109
-			print " - ".$langs->trans("KO").' - '.$ldap->error;
110
-		}
111
-		print "\n";
100
+        $result=$ldap->add($dn,$info,$user);	// Wil fail if already exists
101
+        $result=$ldap->update($dn,$info,$user,$olddn);
102
+        if ($result > 0)
103
+        {
104
+            print " - ".$langs->trans("OK");
105
+        }
106
+        else
107
+        {
108
+            $error++;
109
+            print " - ".$langs->trans("KO").' - '.$ldap->error;
110
+        }
111
+        print "\n";
112 112
 
113
-		$i++;
114
-	}
113
+        $i++;
114
+    }
115 115
 
116
-	$ldap->unbind();
117
-	$ldap->close();
116
+    $ldap->unbind();
117
+    $ldap->close();
118 118
 }
119 119
 else
120 120
 {
121
-	dol_print_error($db);
121
+    dol_print_error($db);
122 122
 }
123 123
 
124 124
 exit($error);
Please login to merge, or discard this patch.
dolibarr/scripts/user/sync_groups_ldap2dolibarr.php 1 patch
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 // Test if batch mode
33 33
 if (substr($sapi_type, 0, 3) == 'cgi') {
34 34
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
35
-	exit(-1);
35
+    exit(-1);
36 36
 }
37 37
 
38 38
 require_once $path."../../htdocs/master.inc.php";
@@ -60,10 +60,10 @@  discard block
 block discarded – undo
60 60
 
61 61
 // List of fields to get from LDAP
62 62
 $required_fields = array(
63
-	$conf->global->LDAP_KEY_GROUPS,
64
-	$conf->global->LDAP_GROUP_FIELD_FULLNAME,
65
-	$conf->global->LDAP_GROUP_FIELD_DESCRIPTION,
66
-	$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS
63
+    $conf->global->LDAP_KEY_GROUPS,
64
+    $conf->global->LDAP_GROUP_FIELD_FULLNAME,
65
+    $conf->global->LDAP_GROUP_FIELD_DESCRIPTION,
66
+    $conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS
67 67
 );
68 68
 
69 69
 // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
@@ -71,17 +71,17 @@  discard block
 block discarded – undo
71 71
 
72 72
 
73 73
 if (! isset($argv[1])) {
74
-	//print "Usage:  $script_file (nocommitiferror|commitiferror) [id_group]\n";
75
-	print "Usage:  $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n";
76
-	exit(-1);
74
+    //print "Usage:  $script_file (nocommitiferror|commitiferror) [id_group]\n";
75
+    print "Usage:  $script_file (nocommitiferror|commitiferror) [--server=ldapserverhost] [--excludeuser=user1,user2...] [-y]\n";
76
+    exit(-1);
77 77
 }
78 78
 
79 79
 foreach($argv as $key => $val)
80 80
 {
81
-	if ($val == 'commitiferror') $forcecommit=1;
82
-	if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
83
-	if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]);
84
-	if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
81
+    if ($val == 'commitiferror') $forcecommit=1;
82
+    if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
83
+    if (preg_match('/--excludeuser=([^\s]+)$/',$val,$reg)) $excludeuser=explode(',',$reg[1]);
84
+    if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
85 85
 }
86 86
 
87 87
 print "Mails sending disabled (useless in batch mode)\n";
@@ -107,14 +107,14 @@  discard block
 block discarded – undo
107 107
 
108 108
 if (! $confirmed)
109 109
 {
110
-	print "Hit Enter to continue or CTRL+C to stop...\n";
111
-	$input = trim(fgets(STDIN));
110
+    print "Hit Enter to continue or CTRL+C to stop...\n";
111
+    $input = trim(fgets(STDIN));
112 112
 }
113 113
 
114 114
 if (empty($conf->global->LDAP_GROUP_DN))
115 115
 {
116
-	print $langs->trans("Error").': '.$langs->trans("LDAP setup for groups not defined inside Dolibarr");
117
-	exit(-1);
116
+    print $langs->trans("Error").': '.$langs->trans("LDAP setup for groups not defined inside Dolibarr");
117
+    exit(-1);
118 118
 }
119 119
 
120 120
 
@@ -122,131 +122,131 @@  discard block
 block discarded – undo
122 122
 $result = $ldap->connect_bind();
123 123
 if ($result >= 0)
124 124
 {
125
-	$justthese=array();
126
-
127
-
128
-	// We disable synchro Dolibarr-LDAP
129
-	$conf->global->LDAP_SYNCHRO_ACTIVE=0;
130
-
131
-	$ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_GROUP_DN, $conf->global->LDAP_KEY_GROUPS, $required_fields, 0, array($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS));
132
-	if (is_array($ldaprecords))
133
-	{
134
-		$db->begin();
135
-
136
-		// Warning $ldapuser has a key in lowercase
137
-		foreach ($ldaprecords as $key => $ldapgroup)
138
-		{
139
-			$group = new UserGroup($db);
140
-			$group->fetch('', $ldapgroup[$conf->global->LDAP_KEY_GROUPS]);
141
-			$group->name = $ldapgroup[$conf->global->LDAP_GROUP_FIELD_FULLNAME];
142
-			$group->nom = $group->name;		// For backward compatibility
143
-			$group->note = $ldapgroup[$conf->global->LDAP_GROUP_FIELD_DESCRIPTION];
144
-			$group->entity = $conf->entity;
145
-
146
-			//print_r($ldapgroup);
147
-
148
-			if($group->id > 0) { // Group update
149
-				print $langs->transnoentities("GroupUpdate").' # '.$key.': name='.$group->name;
150
-				$res=$group->update();
151
-
152
-				if ($res > 0)
153
-				{
154
-					print ' --> Updated group id='.$group->id.' name='.$group->name;
155
-				}
156
-				else
157
-				{
158
-					$error++;
159
-					print ' --> '.$res.' '.$group->error;
160
-				}
161
-				print "\n";
162
-			} else { // Group creation
163
-				print $langs->transnoentities("GroupCreate").' # '.$key.': name='.$group->name;
164
-				$res=$group->create();
165
-
166
-				if ($res > 0)
167
-				{
168
-					print ' --> Created group id='.$group->id.' name='.$group->name;
169
-				}
170
-				else
171
-				{
172
-					$error++;
173
-					print ' --> '.$res.' '.$group->error;
174
-				}
175
-				print "\n";
176
-			}
177
-
178
-			//print_r($group);
179
-
180
-			// Gestion des utilisateurs associés au groupe
181
-			// 1 - Association des utilisateurs du groupe LDAP au groupe Dolibarr
182
-			$userList = array();
183
-			$userIdList = array();
184
-			foreach($ldapgroup[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] as $key => $userdn) {
185
-				if($key === 'count') continue;
186
-				if(empty($userList[$userdn])) { // Récupération de l'utilisateur
187
-					// Schéma rfc2307: les membres sont listés dans l'attribut memberUid sous form de login uniquement
188
-					if ($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS === 'memberUid'){
189
-						$userKey = array($userdn);
190
-					} else { // Pour les autres schémas, les membres sont listés sous forme de DN complets
191
-						$userFilter = explode(',', $userdn);
192
-						$userKey = $ldap->getAttributeValues('('.$userFilter[0].')', $conf->global->LDAP_KEY_USERS);
193
-					}
194
-					if(!is_array($userKey)) continue;
195
-
196
-					$fuser = new User($db);
197
-
198
-					if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) {
199
-						$fuser->fetch('','',$userKey[0]); // Chargement du user concerné par le SID
200
-					} else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) {
201
-						$fuser->fetch('',$userKey[0]); // Chargement du user concerné par le login
202
-					}
203
-
204
-					$userList[$userdn] = $fuser;
205
-				} else {
206
-					$fuser = &$userList[$userdn];
207
-				}
208
-
209
-				$userIdList[$userdn] = $fuser->id;
210
-
211
-				// Ajout de l'utilisateur dans le groupe
212
-				if(!in_array($fuser->id, array_keys($group->members))) {
213
-					$fuser->SetInGroup($group->id, $group->entity);
214
-					echo $fuser->login.' added'."\n";
215
-				}
216
-			}
217
-
218
-			// 2 - Suppression des utilisateurs du groupe Dolibarr qui ne sont plus dans le groupe LDAP
219
-			foreach ($group->members as $guser) {
220
-				if(!in_array($guser->id, $userIdList)) {
221
-					$guser->RemoveFromGroup($group->id, $group->entity);
222
-					echo $guser->login.' removed'."\n";
223
-				}
224
-			}
225
-		}
226
-
227
-		if (! $error || $forcecommit)
228
-		{
229
-			if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n";
230
-			else print $langs->transnoentities("ErrorButCommitIsDone")."\n";
231
-			$db->commit();
232
-		}
233
-		else
234
-		{
235
-			print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n";
236
-			$db->rollback();
237
-		}
238
-		print "\n";
239
-	}
240
-	else
241
-	{
242
-		dol_print_error('',$ldap->error);
243
-		$error++;
244
-	}
125
+    $justthese=array();
126
+
127
+
128
+    // We disable synchro Dolibarr-LDAP
129
+    $conf->global->LDAP_SYNCHRO_ACTIVE=0;
130
+
131
+    $ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_GROUP_DN, $conf->global->LDAP_KEY_GROUPS, $required_fields, 0, array($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS));
132
+    if (is_array($ldaprecords))
133
+    {
134
+        $db->begin();
135
+
136
+        // Warning $ldapuser has a key in lowercase
137
+        foreach ($ldaprecords as $key => $ldapgroup)
138
+        {
139
+            $group = new UserGroup($db);
140
+            $group->fetch('', $ldapgroup[$conf->global->LDAP_KEY_GROUPS]);
141
+            $group->name = $ldapgroup[$conf->global->LDAP_GROUP_FIELD_FULLNAME];
142
+            $group->nom = $group->name;		// For backward compatibility
143
+            $group->note = $ldapgroup[$conf->global->LDAP_GROUP_FIELD_DESCRIPTION];
144
+            $group->entity = $conf->entity;
145
+
146
+            //print_r($ldapgroup);
147
+
148
+            if($group->id > 0) { // Group update
149
+                print $langs->transnoentities("GroupUpdate").' # '.$key.': name='.$group->name;
150
+                $res=$group->update();
151
+
152
+                if ($res > 0)
153
+                {
154
+                    print ' --> Updated group id='.$group->id.' name='.$group->name;
155
+                }
156
+                else
157
+                {
158
+                    $error++;
159
+                    print ' --> '.$res.' '.$group->error;
160
+                }
161
+                print "\n";
162
+            } else { // Group creation
163
+                print $langs->transnoentities("GroupCreate").' # '.$key.': name='.$group->name;
164
+                $res=$group->create();
165
+
166
+                if ($res > 0)
167
+                {
168
+                    print ' --> Created group id='.$group->id.' name='.$group->name;
169
+                }
170
+                else
171
+                {
172
+                    $error++;
173
+                    print ' --> '.$res.' '.$group->error;
174
+                }
175
+                print "\n";
176
+            }
177
+
178
+            //print_r($group);
179
+
180
+            // Gestion des utilisateurs associés au groupe
181
+            // 1 - Association des utilisateurs du groupe LDAP au groupe Dolibarr
182
+            $userList = array();
183
+            $userIdList = array();
184
+            foreach($ldapgroup[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] as $key => $userdn) {
185
+                if($key === 'count') continue;
186
+                if(empty($userList[$userdn])) { // Récupération de l'utilisateur
187
+                    // Schéma rfc2307: les membres sont listés dans l'attribut memberUid sous form de login uniquement
188
+                    if ($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS === 'memberUid'){
189
+                        $userKey = array($userdn);
190
+                    } else { // Pour les autres schémas, les membres sont listés sous forme de DN complets
191
+                        $userFilter = explode(',', $userdn);
192
+                        $userKey = $ldap->getAttributeValues('('.$userFilter[0].')', $conf->global->LDAP_KEY_USERS);
193
+                    }
194
+                    if(!is_array($userKey)) continue;
195
+
196
+                    $fuser = new User($db);
197
+
198
+                    if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_SID) {
199
+                        $fuser->fetch('','',$userKey[0]); // Chargement du user concerné par le SID
200
+                    } else if($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) {
201
+                        $fuser->fetch('',$userKey[0]); // Chargement du user concerné par le login
202
+                    }
203
+
204
+                    $userList[$userdn] = $fuser;
205
+                } else {
206
+                    $fuser = &$userList[$userdn];
207
+                }
208
+
209
+                $userIdList[$userdn] = $fuser->id;
210
+
211
+                // Ajout de l'utilisateur dans le groupe
212
+                if(!in_array($fuser->id, array_keys($group->members))) {
213
+                    $fuser->SetInGroup($group->id, $group->entity);
214
+                    echo $fuser->login.' added'."\n";
215
+                }
216
+            }
217
+
218
+            // 2 - Suppression des utilisateurs du groupe Dolibarr qui ne sont plus dans le groupe LDAP
219
+            foreach ($group->members as $guser) {
220
+                if(!in_array($guser->id, $userIdList)) {
221
+                    $guser->RemoveFromGroup($group->id, $group->entity);
222
+                    echo $guser->login.' removed'."\n";
223
+                }
224
+            }
225
+        }
226
+
227
+        if (! $error || $forcecommit)
228
+        {
229
+            if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n";
230
+            else print $langs->transnoentities("ErrorButCommitIsDone")."\n";
231
+            $db->commit();
232
+        }
233
+        else
234
+        {
235
+            print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n";
236
+            $db->rollback();
237
+        }
238
+        print "\n";
239
+    }
240
+    else
241
+    {
242
+        dol_print_error('',$ldap->error);
243
+        $error++;
244
+    }
245 245
 }
246 246
 else
247 247
 {
248
-	dol_print_error('',$ldap->error);
249
-	$error++;
248
+    dol_print_error('',$ldap->error);
249
+    $error++;
250 250
 }
251 251
 
252 252
 
@@ -261,6 +261,6 @@  discard block
 block discarded – undo
261 261
  */
262 262
 function dolValidElement($element)
263 263
 {
264
-	return (trim($element) != '');
264
+    return (trim($element) != '');
265 265
 }
266 266
 
Please login to merge, or discard this patch.
dolibarr/scripts/members/sync_members_ldap2dolibarr.php 1 patch
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 // Test if batch mode
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
33 33
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
34
-	exit(-1);
34
+    exit(-1);
35 35
 }
36 36
 
37 37
 require_once $path."../../htdocs/master.inc.php";
@@ -59,32 +59,32 @@  discard block
 block discarded – undo
59 59
 
60 60
 // List of fields to get from LDAP
61 61
 $required_fields = array(
62
-	$conf->global->LDAP_KEY_MEMBERS,
63
-	$conf->global->LDAP_FIELD_FULLNAME,
64
-	$conf->global->LDAP_FIELD_LOGIN,
65
-	$conf->global->LDAP_FIELD_LOGIN_SAMBA,
66
-	$conf->global->LDAP_FIELD_PASSWORD,
67
-	$conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
68
-	$conf->global->LDAP_FIELD_NAME,
69
-	$conf->global->LDAP_FIELD_FIRSTNAME,
70
-	$conf->global->LDAP_FIELD_MAIL,
71
-	$conf->global->LDAP_FIELD_PHONE,
72
-	$conf->global->LDAP_FIELD_PHONE_PERSO,
73
-	$conf->global->LDAP_FIELD_MOBILE,
74
-	$conf->global->LDAP_FIELD_FAX,
75
-	$conf->global->LDAP_FIELD_ADDRESS,
76
-	$conf->global->LDAP_FIELD_ZIP,
77
-	$conf->global->LDAP_FIELD_TOWN,
78
-	$conf->global->LDAP_FIELD_COUNTRY,
79
-	$conf->global->LDAP_FIELD_DESCRIPTION,
80
-	$conf->global->LDAP_FIELD_BIRTHDATE,
81
-	$conf->global->LDAP_FIELD_MEMBER_STATUS,
82
-	$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION,
83
-	// Subscriptions
84
-	$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE,
85
-	$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT,
86
-	$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE,
87
-	$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT
62
+    $conf->global->LDAP_KEY_MEMBERS,
63
+    $conf->global->LDAP_FIELD_FULLNAME,
64
+    $conf->global->LDAP_FIELD_LOGIN,
65
+    $conf->global->LDAP_FIELD_LOGIN_SAMBA,
66
+    $conf->global->LDAP_FIELD_PASSWORD,
67
+    $conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
68
+    $conf->global->LDAP_FIELD_NAME,
69
+    $conf->global->LDAP_FIELD_FIRSTNAME,
70
+    $conf->global->LDAP_FIELD_MAIL,
71
+    $conf->global->LDAP_FIELD_PHONE,
72
+    $conf->global->LDAP_FIELD_PHONE_PERSO,
73
+    $conf->global->LDAP_FIELD_MOBILE,
74
+    $conf->global->LDAP_FIELD_FAX,
75
+    $conf->global->LDAP_FIELD_ADDRESS,
76
+    $conf->global->LDAP_FIELD_ZIP,
77
+    $conf->global->LDAP_FIELD_TOWN,
78
+    $conf->global->LDAP_FIELD_COUNTRY,
79
+    $conf->global->LDAP_FIELD_DESCRIPTION,
80
+    $conf->global->LDAP_FIELD_BIRTHDATE,
81
+    $conf->global->LDAP_FIELD_MEMBER_STATUS,
82
+    $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION,
83
+    // Subscriptions
84
+    $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE,
85
+    $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT,
86
+    $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE,
87
+    $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT
88 88
 );
89 89
 
90 90
 // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
@@ -93,15 +93,15 @@  discard block
 block discarded – undo
93 93
 
94 94
 if (! isset($argv[2]) || ! is_numeric($argv[2])) {
95 95
     print "Usage:  $script_file (nocommitiferror|commitiferror) id_member_type  [--server=ldapserverhost] [-y]\n";
96
-	exit(-1);
96
+    exit(-1);
97 97
 }
98 98
 
99 99
 $typeid=$argv[2];
100 100
 foreach($argv as $key => $val)
101 101
 {
102
-	if ($val == 'commitiferror') $forcecommit=1;
103
-	if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
104
-	if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
102
+    if ($val == 'commitiferror') $forcecommit=1;
103
+    if (preg_match('/--server=([^\s]+)$/',$val,$reg)) $conf->global->LDAP_SERVER_HOST=$reg[1];
104
+    if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
105 105
 }
106 106
 
107 107
 print "Mails sending disabled (useless in batch mode)\n";
@@ -129,20 +129,20 @@  discard block
 block discarded – undo
129 129
 // Check parameters
130 130
 if (empty($conf->global->LDAP_MEMBER_DN))
131 131
 {
132
-	print $langs->trans("Error").': '.$langs->trans("LDAP setup for members not defined inside Dolibarr")."\n";
133
-	exit(-1);
132
+    print $langs->trans("Error").': '.$langs->trans("LDAP setup for members not defined inside Dolibarr")."\n";
133
+    exit(-1);
134 134
 }
135 135
 if ($typeid <= 0)
136 136
 {
137
-	print $langs->trans("Error").': Parameter id_member_type is not a valid ref of an existing member type'."\n";
138
-	exit(-2);
137
+    print $langs->trans("Error").': Parameter id_member_type is not a valid ref of an existing member type'."\n";
138
+    exit(-2);
139 139
 }
140 140
 
141 141
 
142 142
 if (! $confirmed)
143 143
 {
144
-	print "Hit Enter to continue or CTRL+C to stop...\n";
145
-	$input = trim(fgets(STDIN));
144
+    print "Hit Enter to continue or CTRL+C to stop...\n";
145
+    $input = trim(fgets(STDIN));
146 146
 }
147 147
 
148 148
 // Load table of correspondence of countries
@@ -155,27 +155,27 @@  discard block
 block discarded – undo
155 155
 $resql=$db->query($sql);
156 156
 if ($resql)
157 157
 {
158
-	$num = $db->num_rows($resql);
159
-	$i = 0;
160
-	if ($num)
161
-	{
162
-		while ($i < $num)
163
-		{
164
-			$obj = $db->fetch_object($resql);
165
-			if ($obj)
166
-			{
167
-				//print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n";
168
-				$hashlib2rowid[strtolower($obj->label)]=$obj->rowid;
169
-				$countries[$obj->rowid]=array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code);
170
-			}
171
-			$i++;
172
-		}
173
-	}
158
+    $num = $db->num_rows($resql);
159
+    $i = 0;
160
+    if ($num)
161
+    {
162
+        while ($i < $num)
163
+        {
164
+            $obj = $db->fetch_object($resql);
165
+            if ($obj)
166
+            {
167
+                //print 'Load cache for country '.strtolower($obj->label).' rowid='.$obj->rowid."\n";
168
+                $hashlib2rowid[strtolower($obj->label)]=$obj->rowid;
169
+                $countries[$obj->rowid]=array('rowid' => $obj->rowid, 'label' => $obj->label, 'code' => $obj->code);
170
+            }
171
+            $i++;
172
+        }
173
+    }
174 174
 }
175 175
 else
176 176
 {
177
-	dol_print_error($db);
178
-	exit(-1);
177
+    dol_print_error($db);
178
+    exit(-1);
179 179
 }
180 180
 
181 181
 
@@ -184,146 +184,146 @@  discard block
 block discarded – undo
184 184
 $result = $ldap->connect_bind();
185 185
 if ($result >= 0)
186 186
 {
187
-	$justthese=array();
188
-
189
-
190
-	// We disable synchro Dolibarr-LDAP
191
-	$conf->global->LDAP_MEMBER_ACTIVE=0;
192
-
193
-	$ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_MEMBER_DN, $conf->global->LDAP_KEY_MEMBERS, $required_fields, 'member');	// Fiter on 'member' filter param
194
-	if (is_array($ldaprecords))
195
-	{
196
-		$db->begin();
197
-
198
-		// Warning $ldapuser has a key in lowercase
199
-		foreach ($ldaprecords as $key => $ldapuser)
200
-		{
201
-			$member = new Adherent($db);
202
-
203
-			// Propriete membre
204
-			$member->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME];
205
-			$member->lastname=$ldapuser[$conf->global->LDAP_FIELD_NAME];
206
-			$member->login=$ldapuser[$conf->global->LDAP_FIELD_LOGIN];
207
-			$member->pass=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD];
208
-
209
-			//$member->societe;
210
-			$member->address=$ldapuser[$conf->global->LDAP_FIELD_ADDRESS];
211
-			$member->zip=$ldapuser[$conf->global->LDAP_FIELD_ZIP];
212
-			$member->town=$ldapuser[$conf->global->LDAP_FIELD_TOWN];
213
-			$member->country=$ldapuser[$conf->global->LDAP_FIELD_COUNTRY];
214
-			$member->country_id=$countries[$hashlib2rowid[strtolower($member->country)]]['rowid'];
215
-			$member->country_code=$countries[$hashlib2rowid[strtolower($member->country)]]['code'];
216
-
217
-			$member->phone=$ldapuser[$conf->global->LDAP_FIELD_PHONE];
218
-			$member->phone_perso=$ldapuser[$conf->global->LDAP_FIELD_PHONE_PERSO];
219
-			$member->phone_mobile=$ldapuser[$conf->global->LDAP_FIELD_MOBILE];
220
-			$member->email=$ldapuser[$conf->global->LDAP_FIELD_MAIL];
221
-
222
-			$member->note=$ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION];
223
-			$member->morphy='phy';
224
-			$member->photo='';
225
-			$member->public=1;
226
-			$member->birth=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_BIRTHDATE]);
227
-
228
-			$member->statut=-1;
229
-			if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]))
230
-			{
231
-				$member->datec=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
232
-				$member->datevalid=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
233
-				$member->statut=$ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS];
234
-			}
235
-			//if ($member->statut > 1) $member->statut=1;
236
-
237
-			//print_r($ldapuser);
238
-
239
-			// Propriete type membre
240
-			$member->typeid=$typeid;
241
-
242
-			// Creation membre
243
-			print $langs->transnoentities("MemberCreate").' # '.$key.': login='.$member->login.', fullname='.$member->getFullName($langs);
244
-			print ', datec='.$member->datec;
245
-			$member_id=$member->create($user);
246
-			if ($member_id > 0)
247
-			{
248
-				print ' --> Created member id='.$member_id.' login='.$member->login;
249
-			}
250
-			else
251
-			{
252
-				$error++;
253
-				print ' --> '.$member->error;
254
-			}
255
-			print "\n";
256
-
257
-			//print_r($member);
258
-
259
-			$datefirst='';
260
-			if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE)
261
-			{
262
-				$datefirst=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
263
-				$pricefirst=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT]);
264
-			}
265
-
266
-			$datelast='';
267
-			if ($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE)
268
-			{
269
-				$datelast=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE]);
270
-				$pricelast=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]);
271
-			}
272
-			elseif ($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)
273
-			{
274
-				$datelast=dol_time_plus_duree(dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION]),-1,'y')+60*60*24;
275
-				$pricelast=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]);
276
-
277
-				// Cas special ou date derniere <= date premiere
278
-				if ($datefirst && $datelast && $datelast <= $datefirst)
279
-				{
280
-					// On ne va inserer que la premiere
281
-					$datelast=0;
282
-					if (! $pricefirst && $pricelast) $pricefirst = $pricelast;
283
-				}
284
-			}
285
-
286
-
287
-			// Insert first subscription
288
-			if ($datefirst)
289
-			{
290
-				// Cree premiere cotisation et met a jour datefin dans adherent
291
-				//print "xx".$datefirst."\n";
292
-				$crowid=$member->subscription($datefirst, $pricefirst, 0);
293
-			}
294
-
295
-			// Insert last subscription
296
-			if ($datelast)
297
-			{
298
-				// Cree derniere cotisation et met a jour datefin dans adherent
299
-				//print "yy".dol_print_date($datelast)."\n";
300
-				$crowid=$member->subscription($datelast, $pricelast, 0);
301
-			}
302
-		}
303
-
304
-		if (! $error || $forcecommit)
305
-		{
306
-			if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n";
307
-			else print $langs->transnoentities("ErrorButCommitIsDone")."\n";
308
-			$db->commit();
309
-		}
310
-		else
311
-		{
312
-			print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n";
313
-			$db->rollback();
314
-		}
315
-		print "\n";
316
-	}
317
-	else
318
-	{
319
-		dol_print_error('',$ldap->error);
320
-		$error++;
321
-	}
187
+    $justthese=array();
188
+
189
+
190
+    // We disable synchro Dolibarr-LDAP
191
+    $conf->global->LDAP_MEMBER_ACTIVE=0;
192
+
193
+    $ldaprecords = $ldap->getRecords('*',$conf->global->LDAP_MEMBER_DN, $conf->global->LDAP_KEY_MEMBERS, $required_fields, 'member');	// Fiter on 'member' filter param
194
+    if (is_array($ldaprecords))
195
+    {
196
+        $db->begin();
197
+
198
+        // Warning $ldapuser has a key in lowercase
199
+        foreach ($ldaprecords as $key => $ldapuser)
200
+        {
201
+            $member = new Adherent($db);
202
+
203
+            // Propriete membre
204
+            $member->firstname=$ldapuser[$conf->global->LDAP_FIELD_FIRSTNAME];
205
+            $member->lastname=$ldapuser[$conf->global->LDAP_FIELD_NAME];
206
+            $member->login=$ldapuser[$conf->global->LDAP_FIELD_LOGIN];
207
+            $member->pass=$ldapuser[$conf->global->LDAP_FIELD_PASSWORD];
208
+
209
+            //$member->societe;
210
+            $member->address=$ldapuser[$conf->global->LDAP_FIELD_ADDRESS];
211
+            $member->zip=$ldapuser[$conf->global->LDAP_FIELD_ZIP];
212
+            $member->town=$ldapuser[$conf->global->LDAP_FIELD_TOWN];
213
+            $member->country=$ldapuser[$conf->global->LDAP_FIELD_COUNTRY];
214
+            $member->country_id=$countries[$hashlib2rowid[strtolower($member->country)]]['rowid'];
215
+            $member->country_code=$countries[$hashlib2rowid[strtolower($member->country)]]['code'];
216
+
217
+            $member->phone=$ldapuser[$conf->global->LDAP_FIELD_PHONE];
218
+            $member->phone_perso=$ldapuser[$conf->global->LDAP_FIELD_PHONE_PERSO];
219
+            $member->phone_mobile=$ldapuser[$conf->global->LDAP_FIELD_MOBILE];
220
+            $member->email=$ldapuser[$conf->global->LDAP_FIELD_MAIL];
221
+
222
+            $member->note=$ldapuser[$conf->global->LDAP_FIELD_DESCRIPTION];
223
+            $member->morphy='phy';
224
+            $member->photo='';
225
+            $member->public=1;
226
+            $member->birth=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_BIRTHDATE]);
227
+
228
+            $member->statut=-1;
229
+            if (isset($ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS]))
230
+            {
231
+                $member->datec=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
232
+                $member->datevalid=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
233
+                $member->statut=$ldapuser[$conf->global->LDAP_FIELD_MEMBER_STATUS];
234
+            }
235
+            //if ($member->statut > 1) $member->statut=1;
236
+
237
+            //print_r($ldapuser);
238
+
239
+            // Propriete type membre
240
+            $member->typeid=$typeid;
241
+
242
+            // Creation membre
243
+            print $langs->transnoentities("MemberCreate").' # '.$key.': login='.$member->login.', fullname='.$member->getFullName($langs);
244
+            print ', datec='.$member->datec;
245
+            $member_id=$member->create($user);
246
+            if ($member_id > 0)
247
+            {
248
+                print ' --> Created member id='.$member_id.' login='.$member->login;
249
+            }
250
+            else
251
+            {
252
+                $error++;
253
+                print ' --> '.$member->error;
254
+            }
255
+            print "\n";
256
+
257
+            //print_r($member);
258
+
259
+            $datefirst='';
260
+            if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE)
261
+            {
262
+                $datefirst=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
263
+                $pricefirst=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT]);
264
+            }
265
+
266
+            $datelast='';
267
+            if ($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE)
268
+            {
269
+                $datelast=dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE]);
270
+                $pricelast=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]);
271
+            }
272
+            elseif ($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)
273
+            {
274
+                $datelast=dol_time_plus_duree(dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION]),-1,'y')+60*60*24;
275
+                $pricelast=price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]);
276
+
277
+                // Cas special ou date derniere <= date premiere
278
+                if ($datefirst && $datelast && $datelast <= $datefirst)
279
+                {
280
+                    // On ne va inserer que la premiere
281
+                    $datelast=0;
282
+                    if (! $pricefirst && $pricelast) $pricefirst = $pricelast;
283
+                }
284
+            }
285
+
286
+
287
+            // Insert first subscription
288
+            if ($datefirst)
289
+            {
290
+                // Cree premiere cotisation et met a jour datefin dans adherent
291
+                //print "xx".$datefirst."\n";
292
+                $crowid=$member->subscription($datefirst, $pricefirst, 0);
293
+            }
294
+
295
+            // Insert last subscription
296
+            if ($datelast)
297
+            {
298
+                // Cree derniere cotisation et met a jour datefin dans adherent
299
+                //print "yy".dol_print_date($datelast)."\n";
300
+                $crowid=$member->subscription($datelast, $pricelast, 0);
301
+            }
302
+        }
303
+
304
+        if (! $error || $forcecommit)
305
+        {
306
+            if (! $error) print $langs->transnoentities("NoErrorCommitIsDone")."\n";
307
+            else print $langs->transnoentities("ErrorButCommitIsDone")."\n";
308
+            $db->commit();
309
+        }
310
+        else
311
+        {
312
+            print $langs->transnoentities("ErrorSomeErrorWereFoundRollbackIsDone",$error)."\n";
313
+            $db->rollback();
314
+        }
315
+        print "\n";
316
+    }
317
+    else
318
+    {
319
+        dol_print_error('',$ldap->error);
320
+        $error++;
321
+    }
322 322
 }
323 323
 else
324 324
 {
325
-	dol_print_error('',$ldap->error);
326
-	$error++;
325
+    dol_print_error('',$ldap->error);
326
+    $error++;
327 327
 }
328 328
 
329 329
 
@@ -338,6 +338,6 @@  discard block
 block discarded – undo
338 338
  */
339 339
 function dolValidElement($element)
340 340
 {
341
-	return (trim($element) != '');
341
+    return (trim($element) != '');
342 342
 }
343 343
 
Please login to merge, or discard this patch.