Test Failed
Push — master ( ed0f4f...3aebc2 )
by Alxarafe
43:14
created
dolibarr/scripts/emailings/mailing-send.php 1 patch
Indentation   +297 added lines, -297 removed lines patch added patch discarded remove patch
@@ -32,13 +32,13 @@  discard block
 block discarded – undo
32 32
 
33 33
 // Test if batch mode
34 34
 if (substr($sapi_type, 0, 3) == 'cgi') {
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);
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);
37 37
 }
38 38
 
39 39
 if (! isset($argv[1]) || ! $argv[1]) {
40
-	print "Usage: ".$script_file." (ID_MAILING|all)\n";
41
-	exit(-1);
40
+    print "Usage: ".$script_file." (ID_MAILING|all)\n";
41
+    exit(-1);
42 42
 }
43 43
 $id=$argv[1];
44 44
 if (isset($argv[2]) || !empty($argv[2])) $login = $argv[2];
@@ -76,206 +76,206 @@  discard block
 block discarded – undo
76 76
 $sql.= " WHERE m.statut IN (1,2)";
77 77
 if ($id != 'all')
78 78
 {
79
-	$sql.= " AND m.rowid= ".$id;
80
-	$sql.= " LIMIT 1";
79
+    $sql.= " AND m.rowid= ".$id;
80
+    $sql.= " LIMIT 1";
81 81
 }
82 82
 
83 83
 $resql=$db->query($sql);
84 84
 if ($resql)
85 85
 {
86
-	$num = $db->num_rows($resql);
87
-	$j = 0;
88
-
89
-	if ($num)
90
-	{
91
-		for ($j=0; $j<$num; $j++)
92
-		{
93
-			$obj = $db->fetch_object($resql);
94
-
95
-			dol_syslog("Process mailing with id ".$obj->rowid);
96
-			print "Process mailing with id ".$obj->rowid."\n";
97
-
98
-			$emailing = new Mailing($db);
99
-			$emailing->fetch($obj->rowid);
100
-
101
-			$id       = $emailing->id;
102
-			$subject  = $emailing->sujet;
103
-			$message  = $emailing->body;
104
-			$from     = $emailing->email_from;
105
-			$replyto  = $emailing->email_replyto;
106
-			$errorsto = $emailing->email_errorsto;
107
-			// Le message est-il en html
108
-			$msgishtml=-1;  // Unknown by default
109
-			if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1;
110
-
111
-			$nbok=0; $nbko=0;
112
-
113
-			// On choisit les mails non deja envoyes pour ce mailing (statut=0)
114
-			// ou envoyes en erreur (statut=-1)
115
-			$sql2 = "SELECT mc.rowid, mc.fk_mailing, mc.lastname, mc.firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag";
116
-			$sql2.= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
117
-			$sql2.= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$id;
118
-			if ($conf->global->MAILING_LIMIT_SENDBYCLI > 0)
119
-			{
120
-				$sql2.= " LIMIT ".$conf->global->MAILING_LIMIT_SENDBYCLI;
121
-			}
122
-
123
-			$resql2=$db->query($sql2);
124
-			if ($resql2)
125
-			{
126
-				$num2 = $db->num_rows($resql2);
127
-				dol_syslog("Nb of targets = ".$num2, LOG_DEBUG);
128
-				print "Nb of targets = ".$num2."\n";
129
-
130
-				if ($num2)
131
-				{
132
-					$now=dol_now();
133
-
134
-					// Positionne date debut envoi
135
-					$sqlstartdate="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".$id;
136
-					$resqlstartdate=$db->query($sqlstartdate);
137
-					if (! $resqlstartdate)
138
-					{
139
-						dol_print_error($db);
140
-						$error++;
141
-					}
142
-
143
-					// Look on each email and sent message
144
-					$i = 0;
145
-					while ($i < $num2)
146
-					{
147
-						// Here code is common with same loop ino card.php
148
-						$res=1;
149
-						$now=dol_now();
150
-
151
-						$obj = $db->fetch_object($resql2);
152
-
153
-						// sendto en RFC2822
154
-						$sendto = str_replace(',',' ',dolGetFirstLastname($obj->firstname, $obj->lastname) ." <".$obj->email.">");
155
-
156
-						// Make subtsitutions on topic and body
157
-						$other=explode(';',$obj->other);
158
-						$tmpfield=explode('=',$other[0],2); $other1=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
159
-						$tmpfield=explode('=',$other[1],2); $other2=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
160
-						$tmpfield=explode('=',$other[2],2); $other3=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
161
-						$tmpfield=explode('=',$other[3],2); $other4=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
162
-						$tmpfield=explode('=',$other[4],2); $other5=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
163
-						$signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$user->signature:'');
164
-
165
-						$object = null;		// Not defined with mass emailing
166
-						$parameters=array('mode'=>'emailing');
167
-						$substitutionarray=getCommonSubstitutionArray($langs, 0, array('object','objectamount'), $object);			// Note: On mass emailing, this is null because we don't know object
168
-
169
-						// Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
170
-						$substitutionarray['__ID__'] = $obj->source_id;
171
-						$substitutionarray['__EMAIL__'] = $obj->email;
172
-						$substitutionarray['__LASTNAME__'] = $obj->lastname;
173
-						$substitutionarray['__FIRSTNAME__'] = $obj->firstname;
174
-						$substitutionarray['__MAILTOEMAIL__'] = '<a href="mailto:'.$obj->email.'">'.$obj->email.'</a>';
175
-						$substitutionarray['__OTHER1__'] = $other1;
176
-						$substitutionarray['__OTHER2__'] = $other2;
177
-						$substitutionarray['__OTHER3__'] = $other3;
178
-						$substitutionarray['__OTHER4__'] = $other4;
179
-						$substitutionarray['__OTHER5__'] = $other5;
180
-						$substitutionarray['__USER_SIGNATURE__'] = $signature;	// Signature is empty when ran from command line or taken from user in parameter)
181
-						$substitutionarray['__SIGNATURE__'] = $signature;	// For backward compatibility
182
-						$substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
183
-						$substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>';
184
-
185
-						$onlinepaymentenabled = 0;
186
-						if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
187
-						if (! empty($conf->paybox->enabled)) $onlinepaymentenabled++;
188
-						if (! empty($conf->stripe->enabled)) $onlinepaymentenabled++;
189
-						if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
190
-						{
191
-							$substitutionarray['__SECUREKEYPAYMENT__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
192
-							if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
193
-							{
194
-								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
195
-								$substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
196
-								$substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
197
-								$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
198
-							}
199
-							else
200
-							{
201
-								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
202
-								$substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
203
-								$substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
204
-								$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
205
-							}
206
-						}
207
-						/* For backward compatibility */
208
-						if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN))
209
-						{
210
-							$substitutionarray['__SECUREKEYPAYPAL__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
211
-
212
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
213
-							else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
214
-
215
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
216
-							else $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
217
-
218
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
219
-							else $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
220
-
221
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
222
-							else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
223
-						}
224
-
225
-						complete_substitutions_array($substitutionarray,$langs);
226
-						$newsubject=make_substitutions($subject,$substitutionarray);
227
-						$newmessage=make_substitutions($message,$substitutionarray);
228
-
229
-						$substitutionisok=true;
230
-
231
-						// Fabrication du mail
232
-						$trackid='emailing-'.$obj->fk_mailing.'-'.$obj->rowid;
233
-						$mail = new CMailFile(
234
-							$newsubject,
235
-							$sendto,
236
-							$from,
237
-							$newmessage,
238
-							array(),
239
-							array(),
240
-							array(),
241
-							'',
242
-							'',
243
-							0,
244
-							$msgishtml,
245
-							$errorsto,
246
-							'',
247
-							$trackid,
248
-							'',
249
-							'emailing'
250
-						);
251
-
252
-						if ($mail->error)
253
-						{
254
-							$res=0;
255
-						}
256
-						if (! $substitutionisok)
257
-						{
258
-							$mail->error='Some substitution failed';
259
-							$res=0;
260
-						}
261
-
262
-						// Send Email
263
-						if ($res)
264
-						{
265
-							$res=$mail->sendfile();
266
-						}
267
-
268
-						if ($res)
269
-						{
270
-							// Mail successful
271
-							$nbok++;
272
-
273
-							dol_syslog("ok for emailing id ".$id." #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
274
-
275
-							// Note: If emailing is 100 000 targets, 100 000 entries are added, so we don't enter events for each target here
276
-							// We must union table llx_mailing_taget for event tab OR enter 1 event with a special table link (id of email in event)
277
-							// Run trigger
278
-							/*
86
+    $num = $db->num_rows($resql);
87
+    $j = 0;
88
+
89
+    if ($num)
90
+    {
91
+        for ($j=0; $j<$num; $j++)
92
+        {
93
+            $obj = $db->fetch_object($resql);
94
+
95
+            dol_syslog("Process mailing with id ".$obj->rowid);
96
+            print "Process mailing with id ".$obj->rowid."\n";
97
+
98
+            $emailing = new Mailing($db);
99
+            $emailing->fetch($obj->rowid);
100
+
101
+            $id       = $emailing->id;
102
+            $subject  = $emailing->sujet;
103
+            $message  = $emailing->body;
104
+            $from     = $emailing->email_from;
105
+            $replyto  = $emailing->email_replyto;
106
+            $errorsto = $emailing->email_errorsto;
107
+            // Le message est-il en html
108
+            $msgishtml=-1;  // Unknown by default
109
+            if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1;
110
+
111
+            $nbok=0; $nbko=0;
112
+
113
+            // On choisit les mails non deja envoyes pour ce mailing (statut=0)
114
+            // ou envoyes en erreur (statut=-1)
115
+            $sql2 = "SELECT mc.rowid, mc.fk_mailing, mc.lastname, mc.firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag";
116
+            $sql2.= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
117
+            $sql2.= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$id;
118
+            if ($conf->global->MAILING_LIMIT_SENDBYCLI > 0)
119
+            {
120
+                $sql2.= " LIMIT ".$conf->global->MAILING_LIMIT_SENDBYCLI;
121
+            }
122
+
123
+            $resql2=$db->query($sql2);
124
+            if ($resql2)
125
+            {
126
+                $num2 = $db->num_rows($resql2);
127
+                dol_syslog("Nb of targets = ".$num2, LOG_DEBUG);
128
+                print "Nb of targets = ".$num2."\n";
129
+
130
+                if ($num2)
131
+                {
132
+                    $now=dol_now();
133
+
134
+                    // Positionne date debut envoi
135
+                    $sqlstartdate="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".$id;
136
+                    $resqlstartdate=$db->query($sqlstartdate);
137
+                    if (! $resqlstartdate)
138
+                    {
139
+                        dol_print_error($db);
140
+                        $error++;
141
+                    }
142
+
143
+                    // Look on each email and sent message
144
+                    $i = 0;
145
+                    while ($i < $num2)
146
+                    {
147
+                        // Here code is common with same loop ino card.php
148
+                        $res=1;
149
+                        $now=dol_now();
150
+
151
+                        $obj = $db->fetch_object($resql2);
152
+
153
+                        // sendto en RFC2822
154
+                        $sendto = str_replace(',',' ',dolGetFirstLastname($obj->firstname, $obj->lastname) ." <".$obj->email.">");
155
+
156
+                        // Make subtsitutions on topic and body
157
+                        $other=explode(';',$obj->other);
158
+                        $tmpfield=explode('=',$other[0],2); $other1=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
159
+                        $tmpfield=explode('=',$other[1],2); $other2=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
160
+                        $tmpfield=explode('=',$other[2],2); $other3=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
161
+                        $tmpfield=explode('=',$other[3],2); $other4=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
162
+                        $tmpfield=explode('=',$other[4],2); $other5=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
163
+                        $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$user->signature:'');
164
+
165
+                        $object = null;		// Not defined with mass emailing
166
+                        $parameters=array('mode'=>'emailing');
167
+                        $substitutionarray=getCommonSubstitutionArray($langs, 0, array('object','objectamount'), $object);			// Note: On mass emailing, this is null because we don't know object
168
+
169
+                        // Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
170
+                        $substitutionarray['__ID__'] = $obj->source_id;
171
+                        $substitutionarray['__EMAIL__'] = $obj->email;
172
+                        $substitutionarray['__LASTNAME__'] = $obj->lastname;
173
+                        $substitutionarray['__FIRSTNAME__'] = $obj->firstname;
174
+                        $substitutionarray['__MAILTOEMAIL__'] = '<a href="mailto:'.$obj->email.'">'.$obj->email.'</a>';
175
+                        $substitutionarray['__OTHER1__'] = $other1;
176
+                        $substitutionarray['__OTHER2__'] = $other2;
177
+                        $substitutionarray['__OTHER3__'] = $other3;
178
+                        $substitutionarray['__OTHER4__'] = $other4;
179
+                        $substitutionarray['__OTHER5__'] = $other5;
180
+                        $substitutionarray['__USER_SIGNATURE__'] = $signature;	// Signature is empty when ran from command line or taken from user in parameter)
181
+                        $substitutionarray['__SIGNATURE__'] = $signature;	// For backward compatibility
182
+                        $substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
183
+                        $substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>';
184
+
185
+                        $onlinepaymentenabled = 0;
186
+                        if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
187
+                        if (! empty($conf->paybox->enabled)) $onlinepaymentenabled++;
188
+                        if (! empty($conf->stripe->enabled)) $onlinepaymentenabled++;
189
+                        if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
190
+                        {
191
+                            $substitutionarray['__SECUREKEYPAYMENT__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
192
+                            if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
193
+                            {
194
+                                $substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
195
+                                $substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
196
+                                $substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
197
+                                $substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
198
+                            }
199
+                            else
200
+                            {
201
+                                $substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
202
+                                $substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
203
+                                $substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
204
+                                $substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
205
+                            }
206
+                        }
207
+                        /* For backward compatibility */
208
+                        if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN))
209
+                        {
210
+                            $substitutionarray['__SECUREKEYPAYPAL__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
211
+
212
+                            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
213
+                            else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
214
+
215
+                            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
216
+                            else $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
217
+
218
+                            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
219
+                            else $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
220
+
221
+                            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
222
+                            else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
223
+                        }
224
+
225
+                        complete_substitutions_array($substitutionarray,$langs);
226
+                        $newsubject=make_substitutions($subject,$substitutionarray);
227
+                        $newmessage=make_substitutions($message,$substitutionarray);
228
+
229
+                        $substitutionisok=true;
230
+
231
+                        // Fabrication du mail
232
+                        $trackid='emailing-'.$obj->fk_mailing.'-'.$obj->rowid;
233
+                        $mail = new CMailFile(
234
+                            $newsubject,
235
+                            $sendto,
236
+                            $from,
237
+                            $newmessage,
238
+                            array(),
239
+                            array(),
240
+                            array(),
241
+                            '',
242
+                            '',
243
+                            0,
244
+                            $msgishtml,
245
+                            $errorsto,
246
+                            '',
247
+                            $trackid,
248
+                            '',
249
+                            'emailing'
250
+                        );
251
+
252
+                        if ($mail->error)
253
+                        {
254
+                            $res=0;
255
+                        }
256
+                        if (! $substitutionisok)
257
+                        {
258
+                            $mail->error='Some substitution failed';
259
+                            $res=0;
260
+                        }
261
+
262
+                        // Send Email
263
+                        if ($res)
264
+                        {
265
+                            $res=$mail->sendfile();
266
+                        }
267
+
268
+                        if ($res)
269
+                        {
270
+                            // Mail successful
271
+                            $nbok++;
272
+
273
+                            dol_syslog("ok for emailing id ".$id." #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
274
+
275
+                            // Note: If emailing is 100 000 targets, 100 000 entries are added, so we don't enter events for each target here
276
+                            // We must union table llx_mailing_taget for event tab OR enter 1 event with a special table link (id of email in event)
277
+                            // Run trigger
278
+                            /*
279 279
 							if ($obj->source_type == 'contact')
280 280
 							{
281 281
 							    $emailing->sendtoid = $obj->source_id;
@@ -290,107 +290,107 @@  discard block
 block discarded – undo
290 290
                             // End call triggers
291 291
 						    */
292 292
 
293
-							$sqlok ="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
294
-							$sqlok.=" SET statut=1, date_envoi='".$db->idate($now)."' WHERE rowid=".$obj->rowid;
295
-							$resqlok=$db->query($sqlok);
296
-							if (! $resqlok)
297
-							{
298
-								dol_print_error($db);
299
-								$error++;
300
-							}
301
-							else
302
-							{
303
-								//if cheack read is use then update prospect contact status
304
-								if (strpos($message, '__CHECK_READ__') !== false)
305
-								{
306
-									//Update status communication of thirdparty prospect
307
-									$sqlx = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$obj->rowid.")";
308
-									dol_syslog("card.php: set prospect thirdparty status", LOG_DEBUG);
309
-									$resqlx=$db->query($sqlx);
310
-									if (! $resqlx)
311
-									{
312
-										dol_print_error($db);
313
-										$error++;
314
-									}
315
-
316
-									//Update status communication of contact prospect
317
-									$sqlx = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX."mailing_cibles AS mc ON mc.rowid=".$obj->rowid." AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)";
318
-									dol_syslog("card.php: set prospect contact status", LOG_DEBUG);
319
-
320
-									$resqlx=$db->query($sqlx);
321
-									if (! $resqlx)
322
-									{
323
-										dol_print_error($db);
324
-										$error++;
325
-									}
326
-								}
327
-
328
-								if (!empty($conf->global->MAILING_DELAY)) {
329
-									sleep($conf->global->MAILING_DELAY);
330
-								}
331
-							}
332
-						}
333
-						else
334
-						{
335
-							// Mail failed
336
-							$nbko++;
337
-
338
-							dol_syslog("error for emailing id ".$id." #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
339
-
340
-							$sqlerror="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
341
-							$sqlerror.=" SET statut=-1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj->rowid;
342
-							$resqlerror=$db->query($sqlerror);
343
-							if (! $resqlerror)
344
-							{
345
-								dol_print_error($db);
346
-								$error++;
347
-							}
348
-						}
349
-
350
-						$i++;
351
-					}
352
-				}
353
-				else
354
-				{
355
-					$mesg="Emailing id ".$id." has no recipient to target";
356
-					print $mesg."\n";
357
-					dol_syslog($mesg,LOG_ERR);
358
-				}
359
-
360
-				// Loop finished, set global statut of mail
361
-				$statut=2;
362
-				if (! $nbko) $statut=3;
363
-
364
-				$sqlenddate="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$id;
365
-
366
-				dol_syslog("update global status", LOG_DEBUG);
367
-				print "Update status of emailing id ".$id." to ".$statut."\n";
368
-				$resqlenddate=$db->query($sqlenddate);
369
-				if (! $resqlenddate)
370
-				{
371
-					dol_print_error($db);
372
-					$error++;
373
-				}
374
-			}
375
-			else
376
-			{
377
-				dol_print_error($db);
378
-				$error++;
379
-			}
380
-		}
381
-	}
382
-	else
383
-	{
384
-		$mesg="No validated emailing id to send found.";
385
-		print $mesg."\n";
386
-		dol_syslog($mesg,LOG_ERR);
387
-		$error++;
388
-	}
293
+                            $sqlok ="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
294
+                            $sqlok.=" SET statut=1, date_envoi='".$db->idate($now)."' WHERE rowid=".$obj->rowid;
295
+                            $resqlok=$db->query($sqlok);
296
+                            if (! $resqlok)
297
+                            {
298
+                                dol_print_error($db);
299
+                                $error++;
300
+                            }
301
+                            else
302
+                            {
303
+                                //if cheack read is use then update prospect contact status
304
+                                if (strpos($message, '__CHECK_READ__') !== false)
305
+                                {
306
+                                    //Update status communication of thirdparty prospect
307
+                                    $sqlx = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$obj->rowid.")";
308
+                                    dol_syslog("card.php: set prospect thirdparty status", LOG_DEBUG);
309
+                                    $resqlx=$db->query($sqlx);
310
+                                    if (! $resqlx)
311
+                                    {
312
+                                        dol_print_error($db);
313
+                                        $error++;
314
+                                    }
315
+
316
+                                    //Update status communication of contact prospect
317
+                                    $sqlx = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX."mailing_cibles AS mc ON mc.rowid=".$obj->rowid." AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)";
318
+                                    dol_syslog("card.php: set prospect contact status", LOG_DEBUG);
319
+
320
+                                    $resqlx=$db->query($sqlx);
321
+                                    if (! $resqlx)
322
+                                    {
323
+                                        dol_print_error($db);
324
+                                        $error++;
325
+                                    }
326
+                                }
327
+
328
+                                if (!empty($conf->global->MAILING_DELAY)) {
329
+                                    sleep($conf->global->MAILING_DELAY);
330
+                                }
331
+                            }
332
+                        }
333
+                        else
334
+                        {
335
+                            // Mail failed
336
+                            $nbko++;
337
+
338
+                            dol_syslog("error for emailing id ".$id." #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
339
+
340
+                            $sqlerror="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
341
+                            $sqlerror.=" SET statut=-1, date_envoi=".$db->idate($now)." WHERE rowid=".$obj->rowid;
342
+                            $resqlerror=$db->query($sqlerror);
343
+                            if (! $resqlerror)
344
+                            {
345
+                                dol_print_error($db);
346
+                                $error++;
347
+                            }
348
+                        }
349
+
350
+                        $i++;
351
+                    }
352
+                }
353
+                else
354
+                {
355
+                    $mesg="Emailing id ".$id." has no recipient to target";
356
+                    print $mesg."\n";
357
+                    dol_syslog($mesg,LOG_ERR);
358
+                }
359
+
360
+                // Loop finished, set global statut of mail
361
+                $statut=2;
362
+                if (! $nbko) $statut=3;
363
+
364
+                $sqlenddate="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$id;
365
+
366
+                dol_syslog("update global status", LOG_DEBUG);
367
+                print "Update status of emailing id ".$id." to ".$statut."\n";
368
+                $resqlenddate=$db->query($sqlenddate);
369
+                if (! $resqlenddate)
370
+                {
371
+                    dol_print_error($db);
372
+                    $error++;
373
+                }
374
+            }
375
+            else
376
+            {
377
+                dol_print_error($db);
378
+                $error++;
379
+            }
380
+        }
381
+    }
382
+    else
383
+    {
384
+        $mesg="No validated emailing id to send found.";
385
+        print $mesg."\n";
386
+        dol_syslog($mesg,LOG_ERR);
387
+        $error++;
388
+    }
389 389
 }
390 390
 else
391 391
 {
392
-	dol_print_error($db);
393
-	$error++;
392
+    dol_print_error($db);
393
+    $error++;
394 394
 }
395 395
 
396 396
 
Please login to merge, or discard this patch.
dolibarr/scripts/accountancy/export-thirdpartyaccount.php 1 patch
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -38,13 +38,13 @@  discard block
 block discarded – undo
38 38
 // Date range
39 39
 $year = GETPOST("year");
40 40
 if (empty($year)) {
41
-	$year_current = strftime("%Y", dol_now());
42
-	$month_current = strftime("%m", dol_now());
43
-	$year_start = $year_current;
41
+    $year_current = strftime("%Y", dol_now());
42
+    $month_current = strftime("%m", dol_now());
43
+    $year_start = $year_current;
44 44
 } else {
45
-	$year_current = $year;
46
-	$month_current = strftime("%m", dol_now());
47
-	$year_start = $year;
45
+    $year_current = $year;
46
+    $month_current = strftime("%m", dol_now());
47
+    $year_start = $year;
48 48
 }
49 49
 $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
50 50
 $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
@@ -52,42 +52,42 @@  discard block
 block discarded – undo
52 52
 // Quarter
53 53
 if (empty($date_start) || empty($date_end)) // We define date_start and date_end
54 54
 {
55
-	$q = GETPOST("q") ? GETPOST("q") : 0;
56
-	if ($q == 0) {
57
-		// We define date_start and date_end
58
-		$year_end = $year_start;
59
-		$month_start = GETPOST("month") ? GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
60
-		if (! GETPOST('month')) {
61
-			if (! GETPOST("year") && $month_start > $month_current) {
62
-				$year_start --;
63
-				$year_end --;
64
-			}
65
-			$month_end = $month_start - 1;
66
-			if ($month_end < 1)
67
-				$month_end = 12;
68
-			else
69
-				$year_end ++;
70
-		} else
71
-			$month_end = $month_start;
72
-		$date_start = dol_get_first_day($year_start, $month_start, false);
73
-		$date_end = dol_get_last_day($year_end, $month_end, false);
74
-	}
75
-	if ($q == 1) {
76
-		$date_start = dol_get_first_day($year_start, 1, false);
77
-		$date_end = dol_get_last_day($year_start, 3, false);
78
-	}
79
-	if ($q == 2) {
80
-		$date_start = dol_get_first_day($year_start, 4, false);
81
-		$date_end = dol_get_last_day($year_start, 6, false);
82
-	}
83
-	if ($q == 3) {
84
-		$date_start = dol_get_first_day($year_start, 7, false);
85
-		$date_end = dol_get_last_day($year_start, 9, false);
86
-	}
87
-	if ($q == 4) {
88
-		$date_start = dol_get_first_day($year_start, 10, false);
89
-		$date_end = dol_get_last_day($year_start, 12, false);
90
-	}
55
+    $q = GETPOST("q") ? GETPOST("q") : 0;
56
+    if ($q == 0) {
57
+        // We define date_start and date_end
58
+        $year_end = $year_start;
59
+        $month_start = GETPOST("month") ? GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
60
+        if (! GETPOST('month')) {
61
+            if (! GETPOST("year") && $month_start > $month_current) {
62
+                $year_start --;
63
+                $year_end --;
64
+            }
65
+            $month_end = $month_start - 1;
66
+            if ($month_end < 1)
67
+                $month_end = 12;
68
+            else
69
+                $year_end ++;
70
+        } else
71
+            $month_end = $month_start;
72
+        $date_start = dol_get_first_day($year_start, $month_start, false);
73
+        $date_end = dol_get_last_day($year_end, $month_end, false);
74
+    }
75
+    if ($q == 1) {
76
+        $date_start = dol_get_first_day($year_start, 1, false);
77
+        $date_end = dol_get_last_day($year_start, 3, false);
78
+    }
79
+    if ($q == 2) {
80
+        $date_start = dol_get_first_day($year_start, 4, false);
81
+        $date_end = dol_get_last_day($year_start, 6, false);
82
+    }
83
+    if ($q == 3) {
84
+        $date_start = dol_get_first_day($year_start, 7, false);
85
+        $date_end = dol_get_last_day($year_start, 9, false);
86
+    }
87
+    if ($q == 4) {
88
+        $date_start = dol_get_first_day($year_start, 10, false);
89
+        $date_end = dol_get_last_day($year_start, 12, false);
90
+    }
91 91
 } else {
92 92
 }
93 93
 
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
 $sql .= " WHERE f.fk_soc = s.rowid";
128 128
 $sql .= " AND s.fk_pays = cp.rowid";
129 129
 if (! empty($date_start) && ! empty($date_end))
130
-	$sql .= " AND f.datec >= '" . $db->idate($date_start) . "' AND f.datec <= '" . $db->idate($date_end) . "'";
130
+    $sql .= " AND f.datec >= '" . $db->idate($date_start) . "' AND f.datec <= '" . $db->idate($date_end) . "'";
131 131
 $sql .= " AND f.entity = " . $conf->entity;
132 132
 if ($socid)
133
-	$sql .= " AND f.fk_soc = " . $socid;
133
+    $sql .= " AND f.fk_soc = " . $socid;
134 134
 $sql .= " GROUP BY name";
135 135
 $sql .= ")";
136 136
 $sql .= "UNION (SELECT s.rowid, s.nom as name , s.address, s.zip , s.town, s.code_compta_fournisseur as compta , ";
@@ -141,10 +141,10 @@  discard block
 block discarded – undo
141 141
 $sql .= " WHERE ff.fk_soc = s.rowid";
142 142
 $sql .= " AND s.fk_pays = cp.rowid";
143 143
 if (! empty($date_start) && ! empty($date_end))
144
-	$sql .= " AND ff.datec >= '" . $db->idate($date_start) . "' AND ff.datec <= '" . $db->idate($date_end) . "'";
144
+    $sql .= " AND ff.datec >= '" . $db->idate($date_start) . "' AND ff.datec <= '" . $db->idate($date_end) . "'";
145 145
 $sql .= " AND ff.entity = " . $conf->entity;
146 146
 if ($socid)
147
-	$sql .= " AND f.fk_soc = " . $socid;
147
+    $sql .= " AND f.fk_soc = " . $socid;
148 148
 $sql .= " GROUP BY name";
149 149
 $sql .= ")";
150 150
 
@@ -153,81 +153,81 @@  discard block
 block discarded – undo
153 153
 dol_syslog('accountancy/admin/thirdpartyaccount.php:: $sql=' . $sql);
154 154
 $resql = $db->query($sql);
155 155
 if ($resql) {
156
-	$num = $db->num_rows($resql);
157
-	$i = 0;
156
+    $num = $db->num_rows($resql);
157
+    $i = 0;
158 158
 
159
-	// export csv
160
-	if (GETPOST('action','aZ09') == 'export_csv') {
159
+    // export csv
160
+    if (GETPOST('action','aZ09') == 'export_csv') {
161 161
 
162
-		header('Content-Type: text/csv');
163
-		header('Content-Disposition: attachment;filename=export_csv.csv');
162
+        header('Content-Type: text/csv');
163
+        header('Content-Disposition: attachment;filename=export_csv.csv');
164 164
 
165
-		$obj = $db->fetch_object($resql);
165
+        $obj = $db->fetch_object($resql);
166 166
 
167
-		print '"' . $obj->compta . '",';
168
-		print '"' . $obj->address . '",';
169
-		print '"' . $obj->zip . '",';
170
-		print '"' . $obj->town . '",';
171
-		print '"' . $obj->country . '",';
172
-		print '"' . $obj->phone . '",';
173
-		print '"' . $obj->fax . '",';
174
-		print "\n";
175
-		$i ++;
176
-	}
167
+        print '"' . $obj->compta . '",';
168
+        print '"' . $obj->address . '",';
169
+        print '"' . $obj->zip . '",';
170
+        print '"' . $obj->town . '",';
171
+        print '"' . $obj->country . '",';
172
+        print '"' . $obj->phone . '",';
173
+        print '"' . $obj->fax . '",';
174
+        print "\n";
175
+        $i ++;
176
+    }
177 177
 
178
-	/*
178
+    /*
179 179
 	 * View
180 180
 	 */
181 181
 
182
-	$thirdpartystatic = new Societe($db);
183
-
184
-	print '<br><br>';
185
-
186
-	print '<table class="noborder" width="100%">';
187
-	print "</table>\n";
188
-	print '</td><td valign="top" width="70%" class="notopnoleftnoright"></td>';
189
-	print '</tr><tr><td colspan=2>';
190
-	print '<table class="noborder" width="100%">';
191
-	print '<tr class="liste_titre"><td align="left">' . $langs->trans("ThirdParties") . '</td>';
192
-	print '<td align="left">' . $langs->trans("AccountNumber") . '</td>';
193
-	print '<td align="left">' . $langs->trans("RaisonSociale") . '</td>';
194
-	print '<td align="left">' . $langs->trans("Address") . '</td>';
195
-	print '<td align="left">' . $langs->trans("Zip") . '</td>';
196
-	print '<td align="left">' . $langs->trans("Town") . '</td>';
197
-	print '<td align="left">' . $langs->trans("Country") . '</td>';
198
-	print '<td align="left">' . $langs->trans("Contact") . '</td>';
199
-	print '<td align="left">' . $langs->trans("Phone") . '</td>';
200
-	print '<td align="left">' . $langs->trans("Fax") . '</td></tr>';
201
-
202
-	while ($obj = $db->fetch_object($resql))
203
-	{
204
-		print '<tr class="oddeven">';
205
-		print '<td>';
206
-		$thirdpartystatic->id = $obj->rowid;
207
-		$thirdpartystatic->name = $obj->name;
208
-		$thirdpartystatic->client = $obj->client;
209
-		$thirdpartystatic->canvas = $obj->canvas;
210
-		$thirdpartystatic->status = $obj->status;
211
-		print $thirdpartystatic->getNomUrl(1);
212
-		print '</td>';
213
-		print '<td align="left">' . $obj->compta . '</td>' . "\n";
214
-		print '<td align="left"></td>';
215
-		print '<td align="left">' . $obj->address . '</td>';
216
-		print '<td align="left">' . $obj->zip . '</td>';
217
-		print '<td align="left">' . $obj->town . '</td>';
218
-		print '<td align="left">' . $obj->country . '</td>';
219
-		print '<td align="left"></td>';
220
-		print '<td align="left">' . $obj->phone . '</td>';
221
-		print '<td align="left">' . $obj->fax . '</td>';
222
-		print "</tr>\n";
223
-
224
-		$i ++;
225
-	}
226
-
227
-	print "</table>";
228
-	$db->free($resql);
182
+    $thirdpartystatic = new Societe($db);
183
+
184
+    print '<br><br>';
185
+
186
+    print '<table class="noborder" width="100%">';
187
+    print "</table>\n";
188
+    print '</td><td valign="top" width="70%" class="notopnoleftnoright"></td>';
189
+    print '</tr><tr><td colspan=2>';
190
+    print '<table class="noborder" width="100%">';
191
+    print '<tr class="liste_titre"><td align="left">' . $langs->trans("ThirdParties") . '</td>';
192
+    print '<td align="left">' . $langs->trans("AccountNumber") . '</td>';
193
+    print '<td align="left">' . $langs->trans("RaisonSociale") . '</td>';
194
+    print '<td align="left">' . $langs->trans("Address") . '</td>';
195
+    print '<td align="left">' . $langs->trans("Zip") . '</td>';
196
+    print '<td align="left">' . $langs->trans("Town") . '</td>';
197
+    print '<td align="left">' . $langs->trans("Country") . '</td>';
198
+    print '<td align="left">' . $langs->trans("Contact") . '</td>';
199
+    print '<td align="left">' . $langs->trans("Phone") . '</td>';
200
+    print '<td align="left">' . $langs->trans("Fax") . '</td></tr>';
201
+
202
+    while ($obj = $db->fetch_object($resql))
203
+    {
204
+        print '<tr class="oddeven">';
205
+        print '<td>';
206
+        $thirdpartystatic->id = $obj->rowid;
207
+        $thirdpartystatic->name = $obj->name;
208
+        $thirdpartystatic->client = $obj->client;
209
+        $thirdpartystatic->canvas = $obj->canvas;
210
+        $thirdpartystatic->status = $obj->status;
211
+        print $thirdpartystatic->getNomUrl(1);
212
+        print '</td>';
213
+        print '<td align="left">' . $obj->compta . '</td>' . "\n";
214
+        print '<td align="left"></td>';
215
+        print '<td align="left">' . $obj->address . '</td>';
216
+        print '<td align="left">' . $obj->zip . '</td>';
217
+        print '<td align="left">' . $obj->town . '</td>';
218
+        print '<td align="left">' . $obj->country . '</td>';
219
+        print '<td align="left"></td>';
220
+        print '<td align="left">' . $obj->phone . '</td>';
221
+        print '<td align="left">' . $obj->fax . '</td>';
222
+        print "</tr>\n";
223
+
224
+        $i ++;
225
+    }
226
+
227
+    print "</table>";
228
+    $db->free($resql);
229 229
 } else {
230
-	dol_print_error($db);
230
+    dol_print_error($db);
231 231
 }
232 232
 
233 233
 llxFooter();
Please login to merge, or discard this patch.
dolibarr/scripts/withdrawals/build_withdrawal_file.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
 
31 31
 // Test if batch mode
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
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);
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);
35 35
 }
36 36
 
37 37
 require_once $path."../../htdocs/master.inc.php";
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 if (! isset($argv[1])) {	// Check parameters
65 65
     print "This script check invoices with a withdrawal request and\n";
66 66
     print "then create payment and build a withdraw file.\n";
67
-	print "Usage: ".$script_file." simu|real\n";
67
+    print "Usage: ".$script_file." simu|real\n";
68 68
     exit(-1);
69 69
 }
70 70
 
Please login to merge, or discard this patch.
dolibarr/scripts/cron/cron_run_jobs.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 
38 38
 // Test if batch mode
39 39
 if (substr($sapi_type, 0, 3) == 'cgi') {
40
-	echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
41
-	exit(-1);
40
+    echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
41
+    exit(-1);
42 42
 }
43 43
 
44 44
 require_once $path."../../htdocs/master.inc.php";
@@ -47,14 +47,14 @@  discard block
 block discarded – undo
47 47
 
48 48
 // Check parameters
49 49
 if (! isset($argv[1]) || ! $argv[1]) {
50
-	usage($path,$script_file);
51
-	exit(-1);
50
+    usage($path,$script_file);
51
+    exit(-1);
52 52
 }
53 53
 $key=$argv[1];
54 54
 
55 55
 if (! isset($argv[2]) || ! $argv[2]) {
56
-	usage($path,$script_file);
57
-	exit(-1);
56
+    usage($path,$script_file);
57
+    exit(-1);
58 58
 }
59 59
 
60 60
 $userlogin=$argv[2];
@@ -78,22 +78,22 @@  discard block
 block discarded – undo
78 78
 // Check module cron is activated
79 79
 if (empty($conf->cron->enabled))
80 80
 {
81
-	print "Error: module Scheduled jobs (cron) not activated\n";
82
-	exit(-1);
81
+    print "Error: module Scheduled jobs (cron) not activated\n";
82
+    exit(-1);
83 83
 }
84 84
 
85 85
 // Check module cron is activated
86 86
 if (empty($conf->cron->enabled))
87 87
 {
88
-	print "Error: module Scheduled jobs (cron) not activated\n";
89
-	exit(-1);
88
+    print "Error: module Scheduled jobs (cron) not activated\n";
89
+    exit(-1);
90 90
 }
91 91
 
92 92
 // Check security key
93 93
 if ($key != $conf->global->CRON_KEY)
94 94
 {
95
-	print "Error: securitykey is wrong\n";
96
-	exit(-1);
95
+    print "Error: securitykey is wrong\n";
96
+    exit(-1);
97 97
 }
98 98
 
99 99
 // If param userlogin is reserved word 'firstadmin'
@@ -118,24 +118,24 @@  discard block
 block discarded – undo
118 118
 $result=$user->fetch('',$userlogin);
119 119
 if ($result < 0)
120 120
 {
121
-	echo "User Error: ".$user->error;
122
-	dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
123
-	exit(-1);
121
+    echo "User Error: ".$user->error;
122
+    dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
123
+    exit(-1);
124 124
 }
125 125
 else
126 126
 {
127
-	if (empty($user->id))
128
-	{
129
-		echo "User login: ".$userlogin." does not exists";
130
-		dol_syslog("User login:".$userlogin." does not exists", LOG_ERR);
131
-		exit(-1);
132
-	}
127
+    if (empty($user->id))
128
+    {
129
+        echo "User login: ".$userlogin." does not exists";
130
+        dol_syslog("User login:".$userlogin." does not exists", LOG_ERR);
131
+        exit(-1);
132
+    }
133 133
 }
134 134
 $user->getrights();
135 135
 
136 136
 if (isset($argv[3]) || $argv[3])
137 137
 {
138
-	$id = $argv[3];
138
+    $id = $argv[3];
139 139
 }
140 140
 
141 141
 // create a jobs object
@@ -143,29 +143,29 @@  discard block
 block discarded – undo
143 143
 
144 144
 $filter=array();
145 145
 if (! empty($id)) {
146
-	if (! is_numeric($id))
147
-	{
148
-		echo "Error: Bad value for parameter job id";
149
-		dol_syslog("cron_run_jobs.php Bad value for parameter job id", LOG_WARNING);
150
-		exit;
151
-	}
152
-	$filter['t.rowid']=$id;
146
+    if (! is_numeric($id))
147
+    {
148
+        echo "Error: Bad value for parameter job id";
149
+        dol_syslog("cron_run_jobs.php Bad value for parameter job id", LOG_WARNING);
150
+        exit;
151
+    }
152
+    $filter['t.rowid']=$id;
153 153
 }
154 154
 
155 155
 $result = $object->fetch_all('ASC,ASC,ASC','t.priority,t.entity,t.rowid', 0, 0, 1, $filter, 0);
156 156
 if ($result<0)
157 157
 {
158
-	echo "Error: ".$object->error;
159
-	dol_syslog("cron_run_jobs.php:: fetch Error ".$object->error, LOG_ERR);
160
-	exit(-1);
158
+    echo "Error: ".$object->error;
159
+    dol_syslog("cron_run_jobs.php:: fetch Error ".$object->error, LOG_ERR);
160
+    exit(-1);
161 161
 }
162 162
 
163 163
 
164 164
 $qualifiedjobs = array();
165 165
 foreach($object->lines as $val)
166 166
 {
167
-	if (! verifCond($val->test)) continue;
168
-	$qualifiedjobs[] = $val;
167
+    if (! verifCond($val->test)) continue;
168
+    $qualifiedjobs[] = $val;
169 169
 }
170 170
 
171 171
 // TODO Duplicate. This sequence of code must be shared with code into public/cron/cron_run_jobs.php php page.
@@ -176,69 +176,69 @@  discard block
 block discarded – undo
176 176
 
177 177
 if (is_array($qualifiedjobs) && (count($qualifiedjobs)>0))
178 178
 {
179
-	// Loop over job
180
-	foreach($qualifiedjobs as $line)
181
-	{
182
-		dol_syslog("cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label, LOG_DEBUG);
183
-
184
-		echo "cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label;
185
-
186
-		//If date_next_jobs is less of current date, execute the program, and store the execution time of the next execution in database
187
-		if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now))
188
-		{
189
-			echo " - qualified";
190
-
191
-			dol_syslog("cron_run_jobs.php line->datenextrun:".dol_print_date($line->datenextrun,'dayhourrfc')." line->datestart:".dol_print_date($line->datestart,'dayhourrfc')." line->dateend:".dol_print_date($line->dateend,'dayhourrfc')." now:".dol_print_date($now,'dayhourrfc'));
192
-
193
-			$cronjob=new Cronjob($db);
194
-			$result=$cronjob->fetch($line->id);
195
-			if ($result < 0)
196
-			{
197
-				echo "Error cronjobid: ".$line->id." cronjob->fetch: ".$cronjob->error."\n";
198
-				echo "Failed to fetch job ".$line->id."\n";
199
-				dol_syslog("cron_run_jobs.php::fetch Error ".$cronjob->error, LOG_ERR);
200
-				exit(-1);
201
-			}
202
-			// Execute job
203
-			$result=$cronjob->run_jobs($userlogin);
204
-			if ($result < 0)
205
-			{
206
-				echo "Error cronjobid: ".$line->id." cronjob->run_job: ".$cronjob->error."\n";
207
-				echo "At least one job failed. Go on menu Home-Setup-Admin tools to see result for each job.\n";
208
-				echo "You can also enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
209
-				dol_syslog("cron_run_jobs.php::run_jobs Error ".$cronjob->error, LOG_ERR);
210
-				$nbofjobslaunchedko++;
211
-			}
212
-			else
213
-			{
214
-				$nbofjobslaunchedok++;
215
-			}
216
-
217
-			echo " - result of run_jobs = ".$result;
218
-
219
-			// we re-program the next execution and stores the last execution time for this job
220
-			$result=$cronjob->reprogram_jobs($userlogin, $now);
221
-			if ($result<0)
222
-			{
223
-				echo "Error cronjobid: ".$line->id." cronjob->reprogram_job: ".$cronjob->error."\n";
224
-				echo "Enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
225
-				dol_syslog("cron_run_jobs.php::reprogram_jobs Error ".$cronjob->error, LOG_ERR);
226
-				exit(-1);
227
-			}
228
-
229
-			echo " - reprogrammed\n";
230
-		}
231
-		else
232
-		{
233
-			echo " - not qualified\n";
234
-
235
-			dol_syslog("cron_run_jobs.php job not qualified line->datenextrun:".dol_print_date($line->datenextrun,'dayhourrfc')." line->datestart:".dol_print_date($line->datestart,'dayhourrfc')." line->dateend:".dol_print_date($line->dateend,'dayhourrfc')." now:".dol_print_date($now,'dayhourrfc'));
236
-		}
237
-	}
179
+    // Loop over job
180
+    foreach($qualifiedjobs as $line)
181
+    {
182
+        dol_syslog("cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label, LOG_DEBUG);
183
+
184
+        echo "cron_run_jobs.php cronjobid: ".$line->id." priority=".$line->priority." entity=".$line->entity." label=".$line->label;
185
+
186
+        //If date_next_jobs is less of current date, execute the program, and store the execution time of the next execution in database
187
+        if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now))
188
+        {
189
+            echo " - qualified";
190
+
191
+            dol_syslog("cron_run_jobs.php line->datenextrun:".dol_print_date($line->datenextrun,'dayhourrfc')." line->datestart:".dol_print_date($line->datestart,'dayhourrfc')." line->dateend:".dol_print_date($line->dateend,'dayhourrfc')." now:".dol_print_date($now,'dayhourrfc'));
192
+
193
+            $cronjob=new Cronjob($db);
194
+            $result=$cronjob->fetch($line->id);
195
+            if ($result < 0)
196
+            {
197
+                echo "Error cronjobid: ".$line->id." cronjob->fetch: ".$cronjob->error."\n";
198
+                echo "Failed to fetch job ".$line->id."\n";
199
+                dol_syslog("cron_run_jobs.php::fetch Error ".$cronjob->error, LOG_ERR);
200
+                exit(-1);
201
+            }
202
+            // Execute job
203
+            $result=$cronjob->run_jobs($userlogin);
204
+            if ($result < 0)
205
+            {
206
+                echo "Error cronjobid: ".$line->id." cronjob->run_job: ".$cronjob->error."\n";
207
+                echo "At least one job failed. Go on menu Home-Setup-Admin tools to see result for each job.\n";
208
+                echo "You can also enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
209
+                dol_syslog("cron_run_jobs.php::run_jobs Error ".$cronjob->error, LOG_ERR);
210
+                $nbofjobslaunchedko++;
211
+            }
212
+            else
213
+            {
214
+                $nbofjobslaunchedok++;
215
+            }
216
+
217
+            echo " - result of run_jobs = ".$result;
218
+
219
+            // we re-program the next execution and stores the last execution time for this job
220
+            $result=$cronjob->reprogram_jobs($userlogin, $now);
221
+            if ($result<0)
222
+            {
223
+                echo "Error cronjobid: ".$line->id." cronjob->reprogram_job: ".$cronjob->error."\n";
224
+                echo "Enable module Log if not yet enabled, run again and take a look into dolibarr.log file\n";
225
+                dol_syslog("cron_run_jobs.php::reprogram_jobs Error ".$cronjob->error, LOG_ERR);
226
+                exit(-1);
227
+            }
228
+
229
+            echo " - reprogrammed\n";
230
+        }
231
+        else
232
+        {
233
+            echo " - not qualified\n";
234
+
235
+            dol_syslog("cron_run_jobs.php job not qualified line->datenextrun:".dol_print_date($line->datenextrun,'dayhourrfc')." line->datestart:".dol_print_date($line->datestart,'dayhourrfc')." line->dateend:".dol_print_date($line->dateend,'dayhourrfc')." now:".dol_print_date($now,'dayhourrfc'));
236
+        }
237
+    }
238 238
 }
239 239
 else
240 240
 {
241
-	echo "cron_run_jobs.php no qualified job found\n";
241
+    echo "cron_run_jobs.php no qualified job found\n";
242 242
 }
243 243
 
244 244
 $db->close();
@@ -257,14 +257,14 @@  discard block
 block discarded – undo
257 257
  */
258 258
 function usage($path,$script_file)
259 259
 {
260
-	global $conf;
261
-
262
-	print "Usage: ".$script_file." securitykey userlogin|'firstadmin' [cronjobid]\n";
263
-	print "The script return 0 when everything worked successfully.\n";
264
-	print "\n";
265
-	print "On Linux system, you can have cron jobs ran automatically by adding an entry into cron.\n";
266
-	print "For example, to run pending tasks each day at 3:30, you can add this line:\n";
267
-	print "30 3 * * * ".$path.$script_file." securitykey userlogin > ".DOL_DATA_ROOT."/".$script_file.".log\n";
268
-	print "For example, to run pending tasks every 5mn, you can add this line:\n";
269
-	print "*/5 * * * * ".$path.$script_file." securitykey userlogin > ".DOL_DATA_ROOT."/".$script_file.".log\n";
260
+    global $conf;
261
+
262
+    print "Usage: ".$script_file." securitykey userlogin|'firstadmin' [cronjobid]\n";
263
+    print "The script return 0 when everything worked successfully.\n";
264
+    print "\n";
265
+    print "On Linux system, you can have cron jobs ran automatically by adding an entry into cron.\n";
266
+    print "For example, to run pending tasks each day at 3:30, you can add this line:\n";
267
+    print "30 3 * * * ".$path.$script_file." securitykey userlogin > ".DOL_DATA_ROOT."/".$script_file.".log\n";
268
+    print "For example, to run pending tasks every 5mn, you can add this line:\n";
269
+    print "*/5 * * * * ".$path.$script_file." securitykey userlogin > ".DOL_DATA_ROOT."/".$script_file.".log\n";
270 270
 }
Please login to merge, or discard this patch.
dolibarr/scripts/company/sync_contacts_dolibarr2ldap.php 1 patch
Indentation   +43 added lines, -43 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
 
@@ -56,12 +56,12 @@  discard block
 block discarded – undo
56 56
 
57 57
 if (! isset($argv[1]) || ! $argv[1]) {
58 58
     print "Usage: $script_file now [-y]\n";
59
-	exit(-1);
59
+    exit(-1);
60 60
 }
61 61
 
62 62
 foreach($argv as $key => $val)
63 63
 {
64
-	if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
64
+    if (preg_match('/-y$/',$val,$reg)) $confirmed=1;
65 65
 }
66 66
 
67 67
 $now=$argv[1];
@@ -87,12 +87,12 @@  discard block
 block discarded – undo
87 87
 
88 88
 if (! $confirmed)
89 89
 {
90
-	print "Press a key to confirm...\n";
91
-	$input = trim(fgets(STDIN));
92
-	print "Warning, this operation may result in data loss if it failed.\n";
93
-	print "Be sure to have a backup of your LDAP database (With OpenLDAP: slapcat > save.ldif).\n";
94
-	print "Hit Enter to continue or CTRL+C to stop...\n";
95
-	$input = trim(fgets(STDIN));
90
+    print "Press a key to confirm...\n";
91
+    $input = trim(fgets(STDIN));
92
+    print "Warning, this operation may result in data loss if it failed.\n";
93
+    print "Be sure to have a backup of your LDAP database (With OpenLDAP: slapcat > save.ldif).\n";
94
+    print "Hit Enter to continue or CTRL+C to stop...\n";
95
+    $input = trim(fgets(STDIN));
96 96
 }
97 97
 
98 98
 /*
@@ -109,54 +109,54 @@  discard block
 block discarded – undo
109 109
 $resql = $db->query($sql);
110 110
 if ($resql)
111 111
 {
112
-	$num = $db->num_rows($resql);
113
-	$i = 0;
112
+    $num = $db->num_rows($resql);
113
+    $i = 0;
114 114
 
115
-	$ldap=new Ldap();
116
-	$ldap->connect_bind();
115
+    $ldap=new Ldap();
116
+    $ldap->connect_bind();
117 117
 
118
-	while ($i < $num)
119
-	{
120
-		$ldap->error="";
118
+    while ($i < $num)
119
+    {
120
+        $ldap->error="";
121 121
 
122
-		$obj = $db->fetch_object($resql);
122
+        $obj = $db->fetch_object($resql);
123 123
 
124
-		$contact = new Contact($db);
125
-		$contact->id = $obj->rowid;
126
-		$contact->fetch($contact->id);
124
+        $contact = new Contact($db);
125
+        $contact->id = $obj->rowid;
126
+        $contact->fetch($contact->id);
127 127
 
128
-		print $langs->trans("UpdateContact")." rowid=".$contact->id." ".$contact->getFullName($langs);
128
+        print $langs->trans("UpdateContact")." rowid=".$contact->id." ".$contact->getFullName($langs);
129 129
 
130
-		$oldobject=$contact;
130
+        $oldobject=$contact;
131 131
 
132
-	    $oldinfo=$oldobject->_load_ldap_info();
133
-	    $olddn=$oldobject->_load_ldap_dn($oldinfo);
132
+        $oldinfo=$oldobject->_load_ldap_info();
133
+        $olddn=$oldobject->_load_ldap_dn($oldinfo);
134 134
 
135
-		$info=$contact->_load_ldap_info();
136
-		$dn=$contact->_load_ldap_dn($info);
135
+        $info=$contact->_load_ldap_info();
136
+        $dn=$contact->_load_ldap_dn($info);
137 137
 
138
-		$result=$ldap->add($dn,$info,$user);	// Wil fail if already exists
139
-		$result=$ldap->update($dn,$info,$user,$olddn);
140
-		if ($result > 0)
141
-		{
142
-			print " - ".$langs->trans("OK");
143
-		}
144
-		else
145
-		{
146
-			$error++;
147
-			print " - ".$langs->trans("KO").' - '.$ldap->error;
148
-		}
149
-		print "\n";
138
+        $result=$ldap->add($dn,$info,$user);	// Wil fail if already exists
139
+        $result=$ldap->update($dn,$info,$user,$olddn);
140
+        if ($result > 0)
141
+        {
142
+            print " - ".$langs->trans("OK");
143
+        }
144
+        else
145
+        {
146
+            $error++;
147
+            print " - ".$langs->trans("KO").' - '.$ldap->error;
148
+        }
149
+        print "\n";
150 150
 
151
-		$i++;
152
-	}
151
+        $i++;
152
+    }
153 153
 
154
-	$ldap->unbind();
155
-	$ldap->close();
154
+    $ldap->unbind();
155
+    $ldap->close();
156 156
 }
157 157
 else
158 158
 {
159
-	dol_print_error($db);
159
+    dol_print_error($db);
160 160
 }
161 161
 
162 162
 exit($error);
Please login to merge, or discard this patch.
dolibarr/scripts/company/export-contacts-xls-example.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -30,13 +30,13 @@  discard block
 block discarded – undo
30 30
 
31 31
 // Test if batch mode
32 32
 if (substr($sapi_type, 0, 3) == 'cgi') {
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);
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);
35 35
 }
36 36
 
37 37
 if (! isset($argv[1]) || ! $argv[1]) {
38
-	print "Usage: $script_file now\n";
39
-	exit(-1);
38
+    print "Usage: $script_file now\n";
39
+    exit(-1);
40 40
 }
41 41
 $now=$argv[1];
42 42
 
@@ -86,30 +86,30 @@  discard block
 block discarded – undo
86 86
 $resql=$db->query($sql);
87 87
 if ($resql)
88 88
 {
89
-	$num = $db->num_rows($resql);
89
+    $num = $db->num_rows($resql);
90 90
 
91
-	print "Lines ".$num."\n";
91
+    print "Lines ".$num."\n";
92 92
 
93
-	$i = 0;
94
-	$j = 1;
93
+    $i = 0;
94
+    $j = 1;
95 95
 
96
-	$objPHPExcel->getActiveSheet()->SetCellValue('A1', $langs->trans("Firstname"));
97
-	$objPHPExcel->getActiveSheet()->SetCellValue('B1', $langs->trans("Lastname"));
98
-	$objPHPExcel->getActiveSheet()->SetCellValue('C1', $langs->trans("Email"));
99
-	$objPHPExcel->getActiveSheet()->SetCellValue('D1', $langs->trans("ThirdPart"));
96
+    $objPHPExcel->getActiveSheet()->SetCellValue('A1', $langs->trans("Firstname"));
97
+    $objPHPExcel->getActiveSheet()->SetCellValue('B1', $langs->trans("Lastname"));
98
+    $objPHPExcel->getActiveSheet()->SetCellValue('C1', $langs->trans("Email"));
99
+    $objPHPExcel->getActiveSheet()->SetCellValue('D1', $langs->trans("ThirdPart"));
100 100
 
101
-	while ($i < $num)
102
-	{
103
-		$obj = $db->fetch_object($resql);
101
+    while ($i < $num)
102
+    {
103
+        $obj = $db->fetch_object($resql);
104 104
 
105
-    	$objPHPExcel->getActiveSheet()->SetCellValue('A'.($i+2), $obj->firstname);
106
-    	$objPHPExcel->getActiveSheet()->SetCellValue('B'.($i+2), $obj->lastname);
107
-    	$objPHPExcel->getActiveSheet()->SetCellValue('C'.($i+2), $obj->email);
108
-    	$objPHPExcel->getActiveSheet()->SetCellValue('D'.($i+2), $obj->name);
105
+        $objPHPExcel->getActiveSheet()->SetCellValue('A'.($i+2), $obj->firstname);
106
+        $objPHPExcel->getActiveSheet()->SetCellValue('B'.($i+2), $obj->lastname);
107
+        $objPHPExcel->getActiveSheet()->SetCellValue('C'.($i+2), $obj->email);
108
+        $objPHPExcel->getActiveSheet()->SetCellValue('D'.($i+2), $obj->name);
109 109
 
110
-		$j++;
111
-		$i++;
112
-	}
110
+        $j++;
111
+        $i++;
112
+    }
113 113
 }
114 114
 
115 115
 
Please login to merge, or discard this patch.
dolibarr/scripts/modulebuilder/builddoc.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -35,13 +35,13 @@  discard block
 block discarded – undo
35 35
 
36 36
 // Test if batch mode
37 37
 if (substr($sapi_type, 0, 3) == 'cgi') {
38
-	echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
39
-	exit(-1);
38
+    echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
39
+    exit(-1);
40 40
 }
41 41
 
42 42
 if (! isset($argv[1]) || ! $argv[1]) {
43
-	print "Usage: ".$script_file." ModuleName\n";
44
-	exit(-1);
43
+    print "Usage: ".$script_file." ModuleName\n";
44
+    exit(-1);
45 45
 }
46 46
 $modulename=$argv[1];
47 47
 
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
 $tmpdir = explode('@', $module);
70 70
 if (! empty($tmpdir[1]))
71 71
 {
72
-	$module=$tmpdir[0];
73
-	$dirread=$tmpdir[1];
74
-	$forceddirread=1;
72
+    $module=$tmpdir[0];
73
+    $dirread=$tmpdir[1];
74
+    $forceddirread=1;
75 75
 }
76 76
 
77 77
 $FILEFLAG='modulebuilder.txt';
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
82 82
 if (empty($newmask))	// This should no happen
83 83
 {
84
-	$newmask='0664';
84
+    $newmask='0664';
85 85
 }
86 86
 
87 87
 
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 
104 104
 if ($result <= 0)
105 105
 {
106
-	print $util->errors;
107
-	exit(1);
106
+    print $util->errors;
107
+    exit(1);
108 108
 }
109 109
 
110 110
 print $langs->trans("DocFileGeneratedInto", $outputfiledoc);
Please login to merge, or discard this patch.
dolibarr/scripts/modulebuilder/initmodule.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -31,13 +31,13 @@  discard block
 block discarded – undo
31 31
 
32 32
 // Test if batch mode
33 33
 if (substr($sapi_type, 0, 3) == 'cgi') {
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);
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);
36 36
 }
37 37
 
38 38
 if (! isset($argv[1]) || ! $argv[1]) {
39
-	print "Usage: ".$script_file." ModuleName\n";
40
-	exit(-1);
39
+    print "Usage: ".$script_file." ModuleName\n";
40
+    exit(-1);
41 41
 }
42 42
 $modulename=$argv[1];
43 43
 
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 $tmpdir = explode('@', $module);
65 65
 if (! empty($tmpdir[1]))
66 66
 {
67
-	$module=$tmpdir[0];
68
-	$dirread=$tmpdir[1];
69
-	$forceddirread=1;
67
+    $module=$tmpdir[0];
68
+    $dirread=$tmpdir[1];
69
+    $forceddirread=1;
70 70
 }
71 71
 
72 72
 $FILEFLAG='modulebuilder.txt';
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
77 77
 if (empty($newmask))	// This should no happen
78 78
 {
79
-	$newmask='0664';
79
+    $newmask='0664';
80 80
 }
81 81
 
82 82
 
@@ -91,83 +91,83 @@  discard block
 block discarded – undo
91 91
 
92 92
 if (preg_match('/[^a-z0-9_]/i', $modulename))
93 93
 {
94
-	$error++;
95
-	print 'Error '.$langs->trans("SpaceOrSpecialCharAreNotAllowed")."\n";
96
-	exit(1);
94
+    $error++;
95
+    print 'Error '.$langs->trans("SpaceOrSpecialCharAreNotAllowed")."\n";
96
+    exit(1);
97 97
 }
98 98
 
99 99
 if (! $error)
100 100
 {
101
-	$srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
102
-	$destdir = $dirins.'/'.strtolower($modulename);
103
-
104
-	$arrayreplacement=array(
105
-	'mymodule'=>strtolower($modulename),
106
-	'MyModule'=>$modulename
107
-	);
108
-
109
-	$result = dolCopyDir($srcdir, $destdir, 0, 0, $arrayreplacement);
110
-	//dol_mkdir($destfile);
111
-	if ($result <= 0)
112
-	{
113
-		if ($result < 0)
114
-		{
115
-			$error++;
116
-			$langs->load("errors");
117
-			print $langs->trans("ErrorFailToCopyDir", $srcdir, $destdir)."\n";
118
-			exit(2);
119
-		}
120
-		else	// $result == 0
121
-		{
122
-			print $langs->trans("AllFilesDidAlreadyExist", $srcdir, $destdir)."\n";
123
-		}
124
-	}
125
-
126
-	// Delete some files
127
-	dol_delete_file($destdir.'/myobject_card.php');
128
-	dol_delete_file($destdir.'/myobject_note.php');
129
-	dol_delete_file($destdir.'/myobject_document.php');
130
-	dol_delete_file($destdir.'/myobject_agenda.php');
131
-	dol_delete_file($destdir.'/myobject_list.php');
132
-	dol_delete_file($destdir.'/lib/myobject.lib.php');
133
-	dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php');
134
-	dol_delete_file($destdir.'/sql/llx_mymodule_myobject.sql');
135
-	dol_delete_file($destdir.'/sql/llx_mymodule_myobject_extrafields.sql');
136
-	dol_delete_file($destdir.'/sql/llx_mymodule_myobject.key.sql');
137
-	dol_delete_file($destdir.'/scripts/myobject.php');
138
-	dol_delete_file($destdir.'/img/object_myobject.png');
139
-	dol_delete_file($destdir.'/class/myobject.class.php');
140
-	dol_delete_file($destdir.'/class/api_mymodule.class.php');
101
+    $srcdir = DOL_DOCUMENT_ROOT.'/modulebuilder/template';
102
+    $destdir = $dirins.'/'.strtolower($modulename);
103
+
104
+    $arrayreplacement=array(
105
+    'mymodule'=>strtolower($modulename),
106
+    'MyModule'=>$modulename
107
+    );
108
+
109
+    $result = dolCopyDir($srcdir, $destdir, 0, 0, $arrayreplacement);
110
+    //dol_mkdir($destfile);
111
+    if ($result <= 0)
112
+    {
113
+        if ($result < 0)
114
+        {
115
+            $error++;
116
+            $langs->load("errors");
117
+            print $langs->trans("ErrorFailToCopyDir", $srcdir, $destdir)."\n";
118
+            exit(2);
119
+        }
120
+        else	// $result == 0
121
+        {
122
+            print $langs->trans("AllFilesDidAlreadyExist", $srcdir, $destdir)."\n";
123
+        }
124
+    }
125
+
126
+    // Delete some files
127
+    dol_delete_file($destdir.'/myobject_card.php');
128
+    dol_delete_file($destdir.'/myobject_note.php');
129
+    dol_delete_file($destdir.'/myobject_document.php');
130
+    dol_delete_file($destdir.'/myobject_agenda.php');
131
+    dol_delete_file($destdir.'/myobject_list.php');
132
+    dol_delete_file($destdir.'/lib/myobject.lib.php');
133
+    dol_delete_file($destdir.'/test/phpunit/MyObjectTest.php');
134
+    dol_delete_file($destdir.'/sql/llx_mymodule_myobject.sql');
135
+    dol_delete_file($destdir.'/sql/llx_mymodule_myobject_extrafields.sql');
136
+    dol_delete_file($destdir.'/sql/llx_mymodule_myobject.key.sql');
137
+    dol_delete_file($destdir.'/scripts/myobject.php');
138
+    dol_delete_file($destdir.'/img/object_myobject.png');
139
+    dol_delete_file($destdir.'/class/myobject.class.php');
140
+    dol_delete_file($destdir.'/class/api_mymodule.class.php');
141 141
 }
142 142
 
143 143
 // Edit PHP files
144 144
 if (! $error)
145 145
 {
146
-	$listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1);
147
-	foreach($listofphpfilestoedit as $phpfileval)
148
-	{
149
-		//var_dump($phpfileval['fullname']);
150
-		$arrayreplacement=array(
151
-		'mymodule'=>strtolower($modulename),
152
-		'MyModule'=>$modulename,
153
-		'MYMODULE'=>strtoupper($modulename),
154
-		'My module'=>$modulename,
155
-		'my module'=>$modulename,
156
-		'Mon module'=>$modulename,
157
-		'mon module'=>$modulename,
158
-		'htdocs/modulebuilder/template'=>strtolower($modulename),
159
-		'---Put here your own copyright and developer email---'=>dol_print_date($now,'%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'')
160
-		);
161
-
162
-
163
-		$result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
164
-		//var_dump($result);
165
-		if ($result < 0)
166
-		{
167
-			print $langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname'])."\n";
168
-			exit(3);
169
-		}
170
-	}
146
+    $listofphpfilestoedit = dol_dir_list($destdir, 'files', 1, '\.(php|MD|js|sql|txt|xml|lang)$', '', 'fullname', SORT_ASC, 0, 1);
147
+    foreach($listofphpfilestoedit as $phpfileval)
148
+    {
149
+        //var_dump($phpfileval['fullname']);
150
+        $arrayreplacement=array(
151
+        'mymodule'=>strtolower($modulename),
152
+        'MyModule'=>$modulename,
153
+        'MYMODULE'=>strtoupper($modulename),
154
+        'My module'=>$modulename,
155
+        'my module'=>$modulename,
156
+        'Mon module'=>$modulename,
157
+        'mon module'=>$modulename,
158
+        'htdocs/modulebuilder/template'=>strtolower($modulename),
159
+        '---Put here your own copyright and developer email---'=>dol_print_date($now,'%Y').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':'')
160
+        );
161
+
162
+
163
+        $result=dolReplaceInFile($phpfileval['fullname'], $arrayreplacement);
164
+        //var_dump($result);
165
+        if ($result < 0)
166
+        {
167
+            print $langs->trans("ErrorFailToMakeReplacementInto", $phpfileval['fullname'])."\n";
168
+            exit(3);
169
+        }
170
+    }
171 171
 }
172 172
 
173 173
 print 'Module initialized'."\n";
Please login to merge, or discard this patch.
dolibarr/scripts/bank/export-bank-receipts.php 1 patch
Indentation   +256 added lines, -256 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
 
30 30
 // Test if batch mode
31 31
 if (substr($sapi_type, 0, 3) == 'cgi') {
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);
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);
34 34
 }
35 35
 
36 36
 require_once $path."../../htdocs/master.inc.php";
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 dol_syslog($script_file." launched with arg ".join(',',$argv));
64 64
 
65 65
 if (! isset($argv[3]) || ! $argv[3]) {
66
-	print "Usage: ".$script_file." bank_ref [bank_receipt_number|all] (csv|tsv|excel|excel2007) [lang=xx_XX]\n";
67
-	exit(-1);
66
+    print "Usage: ".$script_file." bank_ref [bank_receipt_number|all] (csv|tsv|excel|excel2007) [lang=xx_XX]\n";
67
+    exit(-1);
68 68
 }
69 69
 $bankref=$argv[1];
70 70
 $num=$argv[2];
@@ -88,25 +88,25 @@  discard block
 block discarded – undo
88 88
 // Parse parameters
89 89
 foreach ($argv as $key => $value)
90 90
 {
91
-	$found=false;
92
-
93
-	// Define options
94
-	if (preg_match('/^lang=/i',$value))
95
-	{
96
-		$found=true;
97
-		$valarray=explode('=',$value);
98
-		$newlangid=$valarray[1];
99
-		print 'Use language '.$newlangid.".\n";
100
-	}
91
+    $found=false;
92
+
93
+    // Define options
94
+    if (preg_match('/^lang=/i',$value))
95
+    {
96
+        $found=true;
97
+        $valarray=explode('=',$value);
98
+        $newlangid=$valarray[1];
99
+        print 'Use language '.$newlangid.".\n";
100
+    }
101 101
 }
102 102
 $outputlangs = $langs;
103 103
 if (! empty($newlangid))
104 104
 {
105
-	if ($outputlangs->defaultlang != $newlangid)
106
-	{
107
-		$outputlangs = new Translate("",$conf);
108
-		$outputlangs->setDefaultLang($newlangid);
109
-	}
105
+    if ($outputlangs->defaultlang != $newlangid)
106
+    {
107
+        $outputlangs = new Translate("",$conf);
108
+        $outputlangs->setDefaultLang($newlangid);
109
+    }
110 110
 }
111 111
 
112 112
 // Load translation files required by the page
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
 $result=$acct->fetch('',$bankref);
117 117
 if ($result <= 0)
118 118
 {
119
-	print "Failed to find bank account with ref ".$bankref.".\n";
120
-	exit(-1);
119
+    print "Failed to find bank account with ref ".$bankref.".\n";
120
+    exit(-1);
121 121
 }
122 122
 else
123 123
 {
124
-	print "Export for bank account ".$acct->ref." (".$acct->label.").\n";
124
+    print "Export for bank account ".$acct->ref." (".$acct->label.").\n";
125 125
 }
126 126
 
127 127
 
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 $classname = "Export".$model;
132 132
 if (! dol_is_file($dir.$file))
133 133
 {
134
-	print "No driver to export with format ".$model."\n";
135
-	exit(-1);
134
+    print "No driver to export with format ".$model."\n";
135
+    exit(-1);
136 136
 }
137 137
 require_once $dir.$file;
138 138
 $objmodel = new $classname($db);
@@ -173,14 +173,14 @@  discard block
 block discarded – undo
173 173
 $listofnum="";
174 174
 if (! empty($num) && $num != "all")
175 175
 {
176
-	$listofnum.="'";
177
-	$arraynum=explode(',',$num);
178
-	foreach($arraynum as $val)
179
-	{
180
-		if ($listofnum != "'") $listofnum.="','";
181
-		$listofnum.=$val;
182
-	}
183
-	$listofnum.="'";
176
+    $listofnum.="'";
177
+    $arraynum=explode(',',$num);
178
+    foreach($arraynum as $val)
179
+    {
180
+        if ($listofnum != "'") $listofnum.="','";
181
+        $listofnum.=$val;
182
+    }
183
+    $listofnum.="'";
184 184
 }
185 185
 $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv,";
186 186
 $sql.= " b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,";
@@ -197,175 +197,175 @@  discard block
 block discarded – undo
197 197
 $resql=$db->query($sql);
198 198
 if ($resql)
199 199
 {
200
-	$balancebefore=array();
201
-
202
-	$numrows = $db->num_rows($resql);
203
-
204
-	if ($numrows > 0)
205
-	{
206
-		// Open file
207
-		print 'Open file '.$filename.' into directory '.$dirname."\n";
208
-		dol_mkdir($dirname);
209
-		$result=$objmodel->open_file($dirname."/".$filename, $outputlangs);
210
-
211
-		if ($result < 0)
212
-		{
213
-			print 'Failed to create file '.$filename.' into dir '.$dirname.'.'."\n";
214
-			return -1;
215
-		}
216
-
217
-		// Genere en-tete
218
-		$objmodel->write_header($outputlangs);
219
-
220
-		// Genere ligne de titre
221
-		$objmodel->write_title($array_fields,$array_selected,$outputlangs,$array_export_TypeFields);
222
-	}
223
-
224
-	$i=0;
225
-	while ($i < $numrows)
226
-	{
227
-		$thirdparty='';
228
-		$accountelem='';
229
-		$comment='';
230
-
231
-		$objp = $db->fetch_object($resql);
232
-
233
-		// Calculate start balance
234
-		if (! isset($balancebefore[$objp->num_releve]))
235
-		{
236
-			print 'Calculate start balance for receipt '.$objp->num_releve."\n";
237
-
238
-			$sql2 = "SELECT sum(b.amount) as amount";
239
-			$sql2.= " FROM ".MAIN_DB_PREFIX."bank as b";
240
-			$sql2.= " WHERE b.num_releve < '".$db->escape($objp->num_releve)."'";
241
-			$sql2.= " AND b.fk_account = ".$objp->bankid;
242
-			$resql2=$db->query($sql2);
243
-			if ($resql2)
244
-			{
245
-				$obj2=$db->fetch_object($resql2);
246
-				$balancebefore[$objp->num_releve] = ($obj2->amount?$obj2->amount:0);
247
-				$db->free($resql2);
248
-			}
249
-			else
250
-			{
251
-				dol_print_error($db);
252
-				exit(-1);
253
-			}
254
-
255
-			$total = $balancebefore[$objp->num_releve];
256
-		}
257
-
258
-		$totalbefore = $total;
259
-		$total = $total + $objp->amount;
260
-
261
-
262
-
263
-		// Date operation
264
-		$dateop=$db->jdate($objp->do);
265
-
266
-		// Date de valeur
267
-		$datevalue=$db->jdate($objp->dv);
268
-
269
-		// Num cheque
270
-		$numchq=($objp->num_chq?$objp->num_chq:'');
271
-
272
-		// Libelle
273
-		$reg=array();
274
-		preg_match('/\((.+)\)/i',$objp->label,$reg);	// Si texte entoure de parenthese on tente recherche de traduction
275
-		if ($reg[1] && $langs->transnoentitiesnoconv($reg[1])!=$reg[1]) $description=$langs->transnoentitiesnoconv($reg[1]);
276
-		else $description=$objp->label;
277
-
278
-		/*
200
+    $balancebefore=array();
201
+
202
+    $numrows = $db->num_rows($resql);
203
+
204
+    if ($numrows > 0)
205
+    {
206
+        // Open file
207
+        print 'Open file '.$filename.' into directory '.$dirname."\n";
208
+        dol_mkdir($dirname);
209
+        $result=$objmodel->open_file($dirname."/".$filename, $outputlangs);
210
+
211
+        if ($result < 0)
212
+        {
213
+            print 'Failed to create file '.$filename.' into dir '.$dirname.'.'."\n";
214
+            return -1;
215
+        }
216
+
217
+        // Genere en-tete
218
+        $objmodel->write_header($outputlangs);
219
+
220
+        // Genere ligne de titre
221
+        $objmodel->write_title($array_fields,$array_selected,$outputlangs,$array_export_TypeFields);
222
+    }
223
+
224
+    $i=0;
225
+    while ($i < $numrows)
226
+    {
227
+        $thirdparty='';
228
+        $accountelem='';
229
+        $comment='';
230
+
231
+        $objp = $db->fetch_object($resql);
232
+
233
+        // Calculate start balance
234
+        if (! isset($balancebefore[$objp->num_releve]))
235
+        {
236
+            print 'Calculate start balance for receipt '.$objp->num_releve."\n";
237
+
238
+            $sql2 = "SELECT sum(b.amount) as amount";
239
+            $sql2.= " FROM ".MAIN_DB_PREFIX."bank as b";
240
+            $sql2.= " WHERE b.num_releve < '".$db->escape($objp->num_releve)."'";
241
+            $sql2.= " AND b.fk_account = ".$objp->bankid;
242
+            $resql2=$db->query($sql2);
243
+            if ($resql2)
244
+            {
245
+                $obj2=$db->fetch_object($resql2);
246
+                $balancebefore[$objp->num_releve] = ($obj2->amount?$obj2->amount:0);
247
+                $db->free($resql2);
248
+            }
249
+            else
250
+            {
251
+                dol_print_error($db);
252
+                exit(-1);
253
+            }
254
+
255
+            $total = $balancebefore[$objp->num_releve];
256
+        }
257
+
258
+        $totalbefore = $total;
259
+        $total = $total + $objp->amount;
260
+
261
+
262
+
263
+        // Date operation
264
+        $dateop=$db->jdate($objp->do);
265
+
266
+        // Date de valeur
267
+        $datevalue=$db->jdate($objp->dv);
268
+
269
+        // Num cheque
270
+        $numchq=($objp->num_chq?$objp->num_chq:'');
271
+
272
+        // Libelle
273
+        $reg=array();
274
+        preg_match('/\((.+)\)/i',$objp->label,$reg);	// Si texte entoure de parenthese on tente recherche de traduction
275
+        if ($reg[1] && $langs->transnoentitiesnoconv($reg[1])!=$reg[1]) $description=$langs->transnoentitiesnoconv($reg[1]);
276
+        else $description=$objp->label;
277
+
278
+        /*
279 279
 		 * Ajout les liens (societe, company...)
280 280
 		 */
281
-		$links = $acct->get_url($objp->rowid);
282
-		foreach($links as $key=>$val)
283
-		{
284
-			if ($links[$key]['type']=='payment')
285
-			{
286
-				$paymentstatic->fetch($links[$key]['url_id']);
287
-				$tmparray=$paymentstatic->getBillsArray('');
288
-				if (is_array($tmparray))
289
-				{
290
-					foreach($tmparray as $key => $val)
291
-					{
292
-						$invoicestatic->fetch($val);
293
-						if ($accountelem) $accountelem.= ', ';
294
-						$accountelem.=$invoicestatic->ref;
295
-					}
296
-				}
297
-			}
298
-			elseif ($links[$key]['type']=='payment_supplier')
299
-			{
300
-				$paymentsupplierstatic->fetch($links[$key]['url_id']);
301
-				$tmparray=$paymentsupplierstatic->getBillsArray('');
302
-				if (is_array($tmparray))
303
-				{
304
-					foreach($tmparray as $key => $val)
305
-					{
306
-						$invoicesupplierstatic->fetch($val);
307
-						if ($accountelem) $accountelem.= ', ';
308
-						$accountelem.=$invoicesupplierstatic->ref;
309
-					}
310
-				}
311
-			}
312
-			elseif ($links[$key]['type']=='payment_sc')
313
-			{
314
-				$paymentsocialcontributionstatic->fetch($links[$key]['url_id']);
315
-				if ($accountelem) $accountelem.= ', ';
316
-				$accountelem.=$langs->transnoentitiesnoconv("SocialContribution").' '.$paymentsocialcontributionstatic->ref;
317
-			}
318
-			elseif ($links[$key]['type']=='payment_vat')
319
-			{
320
-				$paymentvatstatic->fetch($links[$key]['url_id']);
321
-				if ($accountelem) $accountelem.= ', ';
322
-				$accountelem.=$langs->transnoentitiesnoconv("VATPayments").' '.$paymentvatstatic->ref;
323
-			}
324
-			elseif ($links[$key]['type']=='banktransfert')
325
-			{
326
-				$comment=$outputlangs->transnoentitiesnoconv("Transfer");
327
-				if ($objp->amount > 0)
328
-				{
329
-					if ($comment) $comment.= ' ';
330
-					$banklinestatic->fetch($links[$key]['url_id']);
331
-					$bankstatic->id=$banklinestatic->fk_account;
332
-					$bankstatic->label=$banklinestatic->bank_account_label;
333
-					$comment.= ' ('.$langs->transnoentitiesnoconv("from").' ';
334
-					$comment.= $bankstatic->getNomUrl(1,'transactions');
335
-					$comment.= ' '.$langs->transnoentitiesnoconv("toward").' ';
336
-					$bankstatic->id=$objp->bankid;
337
-					$bankstatic->label=$objp->bankref;
338
-					$comment.= $bankstatic->getNomUrl(1,'');
339
-					$comment.= ')';
340
-				}
341
-				else
342
-				{
343
-					if ($comment) $comment.= ' ';
344
-					$bankstatic->id=$objp->bankid;
345
-					$bankstatic->label=$objp->bankref;
346
-					$comment.= ' ('.$langs->transnoentitiesnoconv("from").' ';
347
-					$comment.= $bankstatic->getNomUrl(1,'');
348
-					$comment.= ' '.$langs->transnoentitiesnoconv("toward").' ';
349
-					$banklinestatic->fetch($links[$key]['url_id']);
350
-					$bankstatic->id=$banklinestatic->fk_account;
351
-					$bankstatic->label=$banklinestatic->bank_account_label;
352
-					$comment.= $bankstatic->getNomUrl(1,'transactions');
353
-					$comment.= ')';
354
-				}
355
-			}
356
-			elseif ($links[$key]['type']=='company')
357
-			{
358
-				if ($thirdparty) $thirdparty.= ', ';
359
-				$thirdparty.= dol_trunc($links[$key]['label'],24);
360
-				$newline=0;
361
-			}
362
-			elseif ($links[$key]['type']=='member')
363
-			{
364
-				if ($thirdparty) $accountelem.= ', ';
365
-				$thirdparty.= $links[$key]['label'];
366
-				$newline=0;
367
-			}
368
-			/*elseif ($links[$key]['type']=='sc')
281
+        $links = $acct->get_url($objp->rowid);
282
+        foreach($links as $key=>$val)
283
+        {
284
+            if ($links[$key]['type']=='payment')
285
+            {
286
+                $paymentstatic->fetch($links[$key]['url_id']);
287
+                $tmparray=$paymentstatic->getBillsArray('');
288
+                if (is_array($tmparray))
289
+                {
290
+                    foreach($tmparray as $key => $val)
291
+                    {
292
+                        $invoicestatic->fetch($val);
293
+                        if ($accountelem) $accountelem.= ', ';
294
+                        $accountelem.=$invoicestatic->ref;
295
+                    }
296
+                }
297
+            }
298
+            elseif ($links[$key]['type']=='payment_supplier')
299
+            {
300
+                $paymentsupplierstatic->fetch($links[$key]['url_id']);
301
+                $tmparray=$paymentsupplierstatic->getBillsArray('');
302
+                if (is_array($tmparray))
303
+                {
304
+                    foreach($tmparray as $key => $val)
305
+                    {
306
+                        $invoicesupplierstatic->fetch($val);
307
+                        if ($accountelem) $accountelem.= ', ';
308
+                        $accountelem.=$invoicesupplierstatic->ref;
309
+                    }
310
+                }
311
+            }
312
+            elseif ($links[$key]['type']=='payment_sc')
313
+            {
314
+                $paymentsocialcontributionstatic->fetch($links[$key]['url_id']);
315
+                if ($accountelem) $accountelem.= ', ';
316
+                $accountelem.=$langs->transnoentitiesnoconv("SocialContribution").' '.$paymentsocialcontributionstatic->ref;
317
+            }
318
+            elseif ($links[$key]['type']=='payment_vat')
319
+            {
320
+                $paymentvatstatic->fetch($links[$key]['url_id']);
321
+                if ($accountelem) $accountelem.= ', ';
322
+                $accountelem.=$langs->transnoentitiesnoconv("VATPayments").' '.$paymentvatstatic->ref;
323
+            }
324
+            elseif ($links[$key]['type']=='banktransfert')
325
+            {
326
+                $comment=$outputlangs->transnoentitiesnoconv("Transfer");
327
+                if ($objp->amount > 0)
328
+                {
329
+                    if ($comment) $comment.= ' ';
330
+                    $banklinestatic->fetch($links[$key]['url_id']);
331
+                    $bankstatic->id=$banklinestatic->fk_account;
332
+                    $bankstatic->label=$banklinestatic->bank_account_label;
333
+                    $comment.= ' ('.$langs->transnoentitiesnoconv("from").' ';
334
+                    $comment.= $bankstatic->getNomUrl(1,'transactions');
335
+                    $comment.= ' '.$langs->transnoentitiesnoconv("toward").' ';
336
+                    $bankstatic->id=$objp->bankid;
337
+                    $bankstatic->label=$objp->bankref;
338
+                    $comment.= $bankstatic->getNomUrl(1,'');
339
+                    $comment.= ')';
340
+                }
341
+                else
342
+                {
343
+                    if ($comment) $comment.= ' ';
344
+                    $bankstatic->id=$objp->bankid;
345
+                    $bankstatic->label=$objp->bankref;
346
+                    $comment.= ' ('.$langs->transnoentitiesnoconv("from").' ';
347
+                    $comment.= $bankstatic->getNomUrl(1,'');
348
+                    $comment.= ' '.$langs->transnoentitiesnoconv("toward").' ';
349
+                    $banklinestatic->fetch($links[$key]['url_id']);
350
+                    $bankstatic->id=$banklinestatic->fk_account;
351
+                    $bankstatic->label=$banklinestatic->bank_account_label;
352
+                    $comment.= $bankstatic->getNomUrl(1,'transactions');
353
+                    $comment.= ')';
354
+                }
355
+            }
356
+            elseif ($links[$key]['type']=='company')
357
+            {
358
+                if ($thirdparty) $thirdparty.= ', ';
359
+                $thirdparty.= dol_trunc($links[$key]['label'],24);
360
+                $newline=0;
361
+            }
362
+            elseif ($links[$key]['type']=='member')
363
+            {
364
+                if ($thirdparty) $accountelem.= ', ';
365
+                $thirdparty.= $links[$key]['label'];
366
+                $newline=0;
367
+            }
368
+            /*elseif ($links[$key]['type']=='sc')
369 369
 				{
370 370
 			if ($accountelem) $accountelem.= ', ';
371 371
 			//$accountelem.= '<a href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$links[$key]['url_id'].'">';
@@ -382,66 +382,66 @@  discard block
 block discarded – undo
382 382
 			//$accountelem.= '</a>';
383 383
 			$newline=0;
384 384
 			}*/
385
-		}
386
-
387
-		$debit=$credit='';
388
-		if ($objp->amount < 0)
389
-		{
390
-			$totald = $totald + abs($objp->amount);
391
-			$debit=price2num($objp->amount * -1);
392
-		}
393
-		else
394
-		{
395
-			$totalc = $totalc + abs($objp->amount);
396
-			$credit=price2num($objp->amount);
397
-		}
398
-
399
-		$i++;
400
-
401
-		$rec=new stdClass();
402
-		$rec->bankreceipt=$objp->num_releve;
403
-		$rec->bankaccount=$objp->banklabel;
404
-		$rec->dateop=dol_print_date($dateop,'dayrfc');
405
-		$rec->dateval=dol_print_date($datevalue,'dayrfc');
406
-		$rec->type=$objp->fk_type.' '.($objp->num_chq?$objp->num_chq:'');
407
-		$rec->description=$description;
408
-		$rec->thirdparty=$thirdparty;
409
-		$rec->accountelem=$accountelem;
410
-		$rec->debit=$debit;
411
-		$rec->credit=$credit;
412
-		$rec->comment=$comment;
413
-		$rec->soldbefore=price2num($totalbefore);
414
-		$rec->soldafter=price2num($total);
415
-
416
-		// end of special operation processing
417
-		$objmodel->write_record($array_selected,$rec,$outputlangs,$array_export_TypeFields);
418
-	}
419
-
420
-	if ($numrows > 0)
421
-	{
422
-		print "Found ".$numrows." records for receipt ".$num."\n";
423
-
424
-		// Genere en-tete
425
-		$objmodel->write_footer($outputlangs);
426
-
427
-		// Close file
428
-		$objmodel->close_file();
429
-
430
-		print 'File '.$filename.' was generated into dir '.$dirname.'.'."\n";
431
-
432
-		$ret=0;
433
-	}
434
-	else
435
-	{
436
-		print "No records found for receipt ".$num."\n";
437
-
438
-		$ret=0;
439
-	}
385
+        }
386
+
387
+        $debit=$credit='';
388
+        if ($objp->amount < 0)
389
+        {
390
+            $totald = $totald + abs($objp->amount);
391
+            $debit=price2num($objp->amount * -1);
392
+        }
393
+        else
394
+        {
395
+            $totalc = $totalc + abs($objp->amount);
396
+            $credit=price2num($objp->amount);
397
+        }
398
+
399
+        $i++;
400
+
401
+        $rec=new stdClass();
402
+        $rec->bankreceipt=$objp->num_releve;
403
+        $rec->bankaccount=$objp->banklabel;
404
+        $rec->dateop=dol_print_date($dateop,'dayrfc');
405
+        $rec->dateval=dol_print_date($datevalue,'dayrfc');
406
+        $rec->type=$objp->fk_type.' '.($objp->num_chq?$objp->num_chq:'');
407
+        $rec->description=$description;
408
+        $rec->thirdparty=$thirdparty;
409
+        $rec->accountelem=$accountelem;
410
+        $rec->debit=$debit;
411
+        $rec->credit=$credit;
412
+        $rec->comment=$comment;
413
+        $rec->soldbefore=price2num($totalbefore);
414
+        $rec->soldafter=price2num($total);
415
+
416
+        // end of special operation processing
417
+        $objmodel->write_record($array_selected,$rec,$outputlangs,$array_export_TypeFields);
418
+    }
419
+
420
+    if ($numrows > 0)
421
+    {
422
+        print "Found ".$numrows." records for receipt ".$num."\n";
423
+
424
+        // Genere en-tete
425
+        $objmodel->write_footer($outputlangs);
426
+
427
+        // Close file
428
+        $objmodel->close_file();
429
+
430
+        print 'File '.$filename.' was generated into dir '.$dirname.'.'."\n";
431
+
432
+        $ret=0;
433
+    }
434
+    else
435
+    {
436
+        print "No records found for receipt ".$num."\n";
437
+
438
+        $ret=0;
439
+    }
440 440
 }
441 441
 else
442 442
 {
443
-	dol_print_error($db);
444
-	$ret=-1;
443
+    dol_print_error($db);
444
+    $ret=-1;
445 445
 }
446 446
 
447 447
 $db->close();
Please login to merge, or discard this patch.