Passed
Pull Request — master (#2)
by
unknown
26:19
created
dolibarr/htdocs/core/actions_massactions.inc.php 1 patch
Indentation   +1097 added lines, -1097 removed lines patch added patch discarded remove patch
@@ -36,8 +36,8 @@  discard block
 block discarded – undo
36 36
 // Protection
37 37
 if (empty($objectclass) || empty($uploaddir))
38 38
 {
39
-	dol_print_error(null, 'include of actions_massactions.inc.php is done but var $massaction or $objectclass or $uploaddir was not defined');
40
-	exit;
39
+    dol_print_error(null, 'include of actions_massactions.inc.php is done but var $massaction or $objectclass or $uploaddir was not defined');
40
+    exit;
41 41
 }
42 42
 
43 43
 
@@ -45,1029 +45,1029 @@  discard block
 block discarded – undo
45 45
 $maxformassaction=(empty($conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS)?1000:$conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS);
46 46
 if (! empty($massaction) && count($toselect) < 1)
47 47
 {
48
-	$error++;
49
-	setEventMessages($langs->trans("NoRecordSelected"), null, "warnings");
48
+    $error++;
49
+    setEventMessages($langs->trans("NoRecordSelected"), null, "warnings");
50 50
 }
51 51
 if (! $error && is_array($toselect) && count($toselect) > $maxformassaction)
52 52
 {
53
-	setEventMessages($langs->trans('TooManyRecordForMassAction',$maxformassaction), null, 'errors');
54
-	$error++;
53
+    setEventMessages($langs->trans('TooManyRecordForMassAction',$maxformassaction), null, 'errors');
54
+    $error++;
55 55
 }
56 56
 
57 57
 if (! $error && $massaction == 'confirm_presend' && ! GETPOST('sendmail'))  // If we do not choose button send (for example when we change template or limit), we must not send email, but keep on send email form
58 58
 {
59
-	$massaction='presend';
59
+    $massaction='presend';
60 60
 }
61 61
 if (! $error && $massaction == 'confirm_presend')
62 62
 {
63
-	$resaction = '';
64
-	$nbsent = 0;
65
-	$nbignored = 0;
66
-	$langs->load("mails");
67
-	include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
68
-
69
-	$listofobjectid=array();
70
-	$listofobjectthirdparties=array();
71
-	$listofobjectref=array();
72
-
73
-	if (! $error)
74
-	{
75
-		$thirdparty=new Societe($db);
76
-		if ($objecttmp->element == 'expensereport') $thirdparty=new User($db);
77
-		if ($objecttmp->element == 'holiday')       $thirdparty=new User($db);
78
-
79
-		$objecttmp=new $objectclass($db);
80
-		foreach($toselect as $toselectid)
81
-		{
82
-			$objecttmp=new $objectclass($db);	// we must create new instance because instance is saved into $listofobjectref array for future use
83
-			$result=$objecttmp->fetch($toselectid);
84
-			if ($result > 0)
85
-			{
86
-				$listofobjectid[$toselectid]=$toselectid;
87
-				$thirdpartyid=($objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid);
88
-				if ($objecttmp->element == 'societe')       $thirdpartyid=$objecttmp->id;
89
-				if ($objecttmp->element == 'expensereport') $thirdpartyid=$objecttmp->fk_user_author;
90
-				if ($objecttmp->element == 'holiday')       $thirdpartyid=$objecttmp->fk_user;
91
-				$listofobjectthirdparties[$thirdpartyid]=$thirdpartyid;
92
-				$listofobjectref[$thirdpartyid][$toselectid]=$objecttmp;
93
-			}
94
-		}
95
-	}
96
-
97
-	// Check mandatory parameters
98
-	if (GETPOST('fromtype','alpha') === 'user' && empty($user->email))
99
-	{
100
-		$error++;
101
-		setEventMessages($langs->trans("NoSenderEmailDefined"), null, 'warnings');
102
-		$massaction='presend';
103
-	}
104
-
105
-	$receiver=$_POST['receiver'];
106
-	if (! is_array($receiver))
107
-	{
108
-		if (empty($receiver) || $receiver == '-1') $receiver=array();
109
-		else $receiver=array($receiver);
110
-	}
111
-	if (! trim($_POST['sendto']) && count($receiver) == 0 && count($listofobjectthirdparties) == 1)	// if only one recipient, receiver is mandatory
112
-	{
113
-	 	$error++;
114
-	   	setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Recipient")), null, 'warnings');
115
-	   	$massaction='presend';
116
-	}
117
-
118
-	if (! GETPOST('subject','none'))
119
-	{
120
-		$error++;
121
-		setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MailTopic")), null, 'warnings');
122
-		$massaction='presend';
123
-	}
124
-
125
-	// Loop on each recipient/thirdparty
126
-	if (! $error)
127
-	{
128
-		foreach ($listofobjectthirdparties as $thirdpartyid)
129
-		{
130
-			$result = $thirdparty->fetch($thirdpartyid);
131
-			if ($result < 0)
132
-			{
133
-				dol_print_error($db);
134
-				exit;
135
-			}
136
-
137
-			$sendto='';
138
-			$sendtocc='';
139
-			$sendtobcc='';
140
-			$sendtoid = array();
141
-
142
-			// Define $sendto
143
-			$tmparray=array();
144
-			if (trim($_POST['sendto']))
145
-			{
146
-				// Recipients are provided into free text
147
-				$tmparray[] = trim($_POST['sendto']);
148
-			}
149
-			if (count($receiver)>0)
150
-			{
151
-				foreach($receiver as $key=>$val)
152
-				{
153
-					// Recipient was provided from combo list
154
-					if ($val == 'thirdparty') // Id of third party or user
155
-					{
156
-						$tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>';
157
-					}
158
-					elseif ($val && method_exists($thirdparty, 'contact_get_property'))		// Id of contact
159
-					{
160
-						$tmparray[] = $thirdparty->contact_get_property((int) $val,'email');
161
-						$sendtoid[] = $val;
162
-					}
163
-				}
164
-			}
165
-			$sendto=implode(',',$tmparray);
166
-
167
-			// Define $sendtocc
168
-			$receivercc=$_POST['receivercc'];
169
-			if (! is_array($receivercc))
170
-			{
171
-				if ($receivercc == '-1') $receivercc=array();
172
-				else $receivercc=array($receivercc);
173
-			}
174
-			$tmparray=array();
175
-			if (trim($_POST['sendtocc']))
176
-			{
177
-				$tmparray[] = trim($_POST['sendtocc']);
178
-			}
179
-			if (count($receivercc) > 0)
180
-			{
181
-				foreach($receivercc as $key=>$val)
182
-				{
183
-					// Recipient was provided from combo list
184
-					if ($val == 'thirdparty') // Id of third party
185
-					{
186
-						$tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>';
187
-					}
188
-					elseif ($val)	// Id du contact
189
-					{
190
-						$tmparray[] = $thirdparty->contact_get_property((int) $val,'email');
191
-						//$sendtoid[] = $val;  TODO Add also id of contact in CC ?
192
-					}
193
-				}
194
-			}
195
-			$sendtocc=implode(',',$tmparray);
196
-
197
-			//var_dump($listofobjectref);exit;
198
-			$attachedfiles=array('paths'=>array(), 'names'=>array(), 'mimes'=>array());
199
-			$listofqualifiedobj=array();
200
-			$listofqualifiedref=array();
201
-			$thirdpartywithoutemail=array();
202
-
203
-			foreach($listofobjectref[$thirdpartyid] as $objectid => $objectobj)
204
-			{
205
-				//var_dump($thirdpartyid.' - '.$objectid.' - '.$objectobj->statut);
206
-				if ($objectclass == 'Propal' && $objectobj->statut == Propal::STATUS_DRAFT)
207
-				{
208
-					$langs->load("errors");
209
-					$nbignored++;
210
-					$resaction.='<div class="error">'.$langs->trans('ErrorOnlyProposalNotDraftCanBeSentInMassAction',$objectobj->ref).'</div><br>';
211
-					continue; // Payment done or started or canceled
212
-				}
213
-				if ($objectclass == 'Commande' && $objectoj->statut == Commande::STATUS_DRAFT)
214
-				{
215
-					$langs->load("errors");
216
-					$nbignored++;
217
-					$resaction.='<div class="error">'.$langs->trans('ErrorOnlyOrderNotDraftCanBeSentInMassAction',$objectobj->ref).'</div><br>';
218
-					continue;
219
-				}
220
-				if ($objectclass == 'Facture' && $objectobj->statut == Facture::STATUS_DRAFT)
221
-				{
222
-					$langs->load("errors");
223
-					$nbignored++;
224
-					$resaction.='<div class="error">'.$langs->trans('ErrorOnlyInvoiceValidatedCanBeSentInMassAction',$objectobj->ref).'</div><br>';
225
-					continue; // Payment done or started or canceled
226
-				}
227
-
228
-				// Test recipient
229
-				if (empty($sendto)) 	// For the case, no recipient were set (multi thirdparties send)
230
-				{
231
-					if ($objectobj->element == 'expensereport')
232
-					{
233
-						$fuser = new User($db);
234
-						$fuser->fetch($objectobj->fk_user_author);
235
-						$sendto = $fuser->email;
236
-					}
237
-					else
238
-					{
239
-						$objectobj->fetch_thirdparty();
240
-						$sendto = $objectobj->thirdparty->email;
241
-					}
242
-				}
243
-
244
-				if (empty($sendto))
245
-				{
246
-				   	//print "No recipient for thirdparty ".$objectobj->thirdparty->name;
247
-				   	$nbignored++;
248
-				   	if (empty($thirdpartywithoutemail[$objectobj->thirdparty->id]))
249
-					{
250
-						$resaction.='<div class="error">'.$langs->trans('NoRecipientEmail',$objectobj->thirdparty->name).'</div><br>';
251
-					}
252
-					dol_syslog('No recipient for thirdparty: '.$objectobj->thirdparty->name, LOG_WARNING);
253
-					$thirdpartywithoutemail[$objectobj->thirdparty->id]=1;
254
-				   	continue;
255
-				}
256
-
257
-				if ($_POST['addmaindocfile'])
258
-				{
259
-					// TODO Use future field $objectobj->fullpathdoc to know where is stored default file
260
-					// TODO If not defined, use $objectobj->modelpdf (or defaut invoice config) to know what is template to use to regenerate doc.
261
-					$filename=dol_sanitizeFileName($objectobj->ref).'.pdf';
262
-					$filedir=$uploaddir . '/' . dol_sanitizeFileName($objectobj->ref);
263
-					$file = $filedir . '/' . $filename;
264
-					$mime = dol_mimetype($file);
265
-
266
-	   				if (dol_is_file($file))
267
-					{
268
-							// Create form object
269
-							$attachedfiles=array(
270
-							'paths'=>array_merge($attachedfiles['paths'],array($file)),
271
-							'names'=>array_merge($attachedfiles['names'],array($filename)),
272
-							'mimes'=>array_merge($attachedfiles['mimes'],array($mime))
273
-							);
274
-					}
275
-					else
276
-					{
277
-							$nbignored++;
278
-							$langs->load("errors");
279
-							$resaction.='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div><br>';
280
-							dol_syslog('Failed to read file: '.$file, LOG_WARNING);
281
-							continue;
282
-					}
283
-				}
284
-
285
-				// Object of thirdparty qualified
286
-				$listofqualifiedobj[$objectid]=$objectobj;
287
-				$listofqualifiedref[$objectid]=$objectobj->ref;
288
-
289
-
290
-				//var_dump($listofqualifiedref);
291
-			}
292
-
293
-			// Send email if there is at least one qualified record
294
-			if (count($listofqualifiedobj) > 0)
295
-			{
296
-				$langs->load("commercial");
297
-
298
-				$fromtype = GETPOST('fromtype');
299
-				if ($fromtype === 'user') {
300
-					$from = $user->getFullName($langs) .' <'.$user->email.'>';
301
-				}
302
-				elseif ($fromtype === 'company') {
303
-					$from = $conf->global->MAIN_INFO_SOCIETE_NOM .' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>';
304
-				}
305
-				elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) {
306
-					$tmp=explode(',', $user->email_aliases);
307
-					$from = trim($tmp[($reg[1] - 1)]);
308
-				}
309
-				elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) {
310
-					$tmp=explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
311
-					$from = trim($tmp[($reg[1] - 1)]);
312
-				}
313
-				elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
314
-					$sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE rowid = '.(int) $reg[1];
315
-					$resql = $db->query($sql);
316
-					$obj = $db->fetch_object($resql);
317
-					if ($obj)
318
-					{
319
-						$from = $obj->label.' <'.$obj->email.'>';
320
-					}
321
-				}
322
-				else {
323
-					$from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
324
-				}
325
-
326
-				$replyto = $from;
327
-				$subject = GETPOST('subject','none');
328
-				$message = GETPOST('message','none');
329
-
330
-				$sendtobcc = GETPOST('sendtoccc');
331
-				if ($objectclass == 'Propal') 				$sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO));
332
-				if ($objectclass == 'Commande') 			$sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO));
333
-				if ($objectclass == 'Facture') 				$sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO));
334
-				if ($objectclass == 'Supplier_Proposal') 	$sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO));
335
-				if ($objectclass == 'CommandeFournisseur')	$sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO));
336
-				if ($objectclass == 'FactureFournisseur')	$sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO));
337
-
338
-				// $listofqualifiedobj is array with key = object id and value is instance of qualified objects, for the current thirdparty (but thirdparty property is not loaded yet)
339
-				$oneemailperrecipient=(GETPOST('oneemailperrecipient')=='on'?1:0);
340
-				$looparray=array();
341
-				if (! $oneemailperrecipient)
342
-				{
343
-					$looparray = $listofqualifiedobj;
344
-					foreach ($looparray as $key => $objecttmp)
345
-					{
346
-						$looparray[$key]->thirdparty = $thirdparty;
347
-					}
348
-				}
349
-				else
350
-				{
351
-					$objectforloop=new $objectclass($db);
352
-					$objectforloop->thirdparty = $thirdparty;
353
-					$looparray[0]=$objectforloop;
354
-				}
355
-				//var_dump($looparray);exit;
356
-
357
-				foreach ($looparray as $objecttmp)		// $objecttmp is a real object or an empty object if we choose to send one email per thirdparty instead of one per record
358
-				{
359
-					// Make substitution in email content
360
-					$substitutionarray=getCommonSubstitutionArray($langs, 0, null, $objecttmp);
361
-					$substitutionarray['__ID__']    = ($oneemailperrecipient ? join(', ',array_keys($listofqualifiedobj)) : $objecttmp->id);
362
-					$substitutionarray['__REF__']   = ($oneemailperrecipient ? join(', ',$listofqualifiedref) : $objecttmp->ref);
363
-					$substitutionarray['__EMAIL__'] = $thirdparty->email;
364
-					$substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$thirdparty->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
365
-
366
-					$parameters=array('mode'=>'formemail');
367
-
368
-					if ( ! empty( $listofobjectthirdparties ) ) {
369
-						$parameters['listofobjectthirdparties'] = $listofobjectthirdparties;
370
-					}
371
-					if ( ! empty( $listofobjectref ) ) {
372
-						$parameters['listofobjectref'] = $listofobjectref;
373
-					}
374
-
375
-					complete_substitutions_array($substitutionarray, $langs, $objecttmp, $parameters);
376
-
377
-					$subject=make_substitutions($subject, $substitutionarray);
378
-					$message=make_substitutions($message, $substitutionarray);
379
-
380
-					$filepath = $attachedfiles['paths'];
381
-					$filename = $attachedfiles['names'];
382
-					$mimetype = $attachedfiles['mimes'];
383
-
384
-					// Define the trackid when emails sent from the mass action
385
-					if ($oneemailperrecipient)
386
-					{
387
-						$trackid='thi'.$thirdparty->id;
388
-						if ($objecttmp->element == 'expensereport') $trackid='use'.$thirdparty->id;
389
-						if ($objecttmp->element == 'holiday') $trackid='use'.$thirdparty->id;
390
-					}
391
-					else
392
-					{
393
-						$trackid=strtolower(get_class($objecttmp));
394
-						if (get_class($objecttmp)=='Contrat')  $trackid='con';
395
-						if (get_class($objecttmp)=='Propal')   $trackid='pro';
396
-						if (get_class($objecttmp)=='Commande') $trackid='ord';
397
-						if (get_class($objecttmp)=='Facture')  $trackid='inv';
398
-						if (get_class($objecttmp)=='Supplier_Proposal')   $trackid='spr';
399
-						if (get_class($objecttmp)=='CommandeFournisseur') $trackid='sor';
400
-						if (get_class($objecttmp)=='FactureFournisseur')  $trackid='sin';
401
-
402
-						$trackid.=$objecttmp->id;
403
-					}
404
-					//var_dump($filepath);
405
-					//var_dump($trackid);exit;
406
-
407
-					// Send mail (substitutionarray must be done just before this)
408
-					require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
409
-					$mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1,'','',$trackid);
410
-					if ($mailfile->error)
411
-					{
412
-						$resaction.='<div class="error">'.$mailfile->error.'</div>';
413
-					}
414
-					else
415
-					{
416
-						$result=$mailfile->sendfile();
417
-						if ($result)
418
-						{
419
-							$resaction.=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)).'<br>';		// Must not contain "
420
-
421
-							$error=0;
422
-
423
-							// Insert logs into agenda
424
-							foreach($listofqualifiedobj as $objid => $objectobj)
425
-							{
426
-								/*if ($objectclass == 'Propale') $actiontypecode='AC_PROP';
63
+    $resaction = '';
64
+    $nbsent = 0;
65
+    $nbignored = 0;
66
+    $langs->load("mails");
67
+    include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
68
+
69
+    $listofobjectid=array();
70
+    $listofobjectthirdparties=array();
71
+    $listofobjectref=array();
72
+
73
+    if (! $error)
74
+    {
75
+        $thirdparty=new Societe($db);
76
+        if ($objecttmp->element == 'expensereport') $thirdparty=new User($db);
77
+        if ($objecttmp->element == 'holiday')       $thirdparty=new User($db);
78
+
79
+        $objecttmp=new $objectclass($db);
80
+        foreach($toselect as $toselectid)
81
+        {
82
+            $objecttmp=new $objectclass($db);	// we must create new instance because instance is saved into $listofobjectref array for future use
83
+            $result=$objecttmp->fetch($toselectid);
84
+            if ($result > 0)
85
+            {
86
+                $listofobjectid[$toselectid]=$toselectid;
87
+                $thirdpartyid=($objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid);
88
+                if ($objecttmp->element == 'societe')       $thirdpartyid=$objecttmp->id;
89
+                if ($objecttmp->element == 'expensereport') $thirdpartyid=$objecttmp->fk_user_author;
90
+                if ($objecttmp->element == 'holiday')       $thirdpartyid=$objecttmp->fk_user;
91
+                $listofobjectthirdparties[$thirdpartyid]=$thirdpartyid;
92
+                $listofobjectref[$thirdpartyid][$toselectid]=$objecttmp;
93
+            }
94
+        }
95
+    }
96
+
97
+    // Check mandatory parameters
98
+    if (GETPOST('fromtype','alpha') === 'user' && empty($user->email))
99
+    {
100
+        $error++;
101
+        setEventMessages($langs->trans("NoSenderEmailDefined"), null, 'warnings');
102
+        $massaction='presend';
103
+    }
104
+
105
+    $receiver=$_POST['receiver'];
106
+    if (! is_array($receiver))
107
+    {
108
+        if (empty($receiver) || $receiver == '-1') $receiver=array();
109
+        else $receiver=array($receiver);
110
+    }
111
+    if (! trim($_POST['sendto']) && count($receiver) == 0 && count($listofobjectthirdparties) == 1)	// if only one recipient, receiver is mandatory
112
+    {
113
+            $error++;
114
+            setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Recipient")), null, 'warnings');
115
+            $massaction='presend';
116
+    }
117
+
118
+    if (! GETPOST('subject','none'))
119
+    {
120
+        $error++;
121
+        setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("MailTopic")), null, 'warnings');
122
+        $massaction='presend';
123
+    }
124
+
125
+    // Loop on each recipient/thirdparty
126
+    if (! $error)
127
+    {
128
+        foreach ($listofobjectthirdparties as $thirdpartyid)
129
+        {
130
+            $result = $thirdparty->fetch($thirdpartyid);
131
+            if ($result < 0)
132
+            {
133
+                dol_print_error($db);
134
+                exit;
135
+            }
136
+
137
+            $sendto='';
138
+            $sendtocc='';
139
+            $sendtobcc='';
140
+            $sendtoid = array();
141
+
142
+            // Define $sendto
143
+            $tmparray=array();
144
+            if (trim($_POST['sendto']))
145
+            {
146
+                // Recipients are provided into free text
147
+                $tmparray[] = trim($_POST['sendto']);
148
+            }
149
+            if (count($receiver)>0)
150
+            {
151
+                foreach($receiver as $key=>$val)
152
+                {
153
+                    // Recipient was provided from combo list
154
+                    if ($val == 'thirdparty') // Id of third party or user
155
+                    {
156
+                        $tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>';
157
+                    }
158
+                    elseif ($val && method_exists($thirdparty, 'contact_get_property'))		// Id of contact
159
+                    {
160
+                        $tmparray[] = $thirdparty->contact_get_property((int) $val,'email');
161
+                        $sendtoid[] = $val;
162
+                    }
163
+                }
164
+            }
165
+            $sendto=implode(',',$tmparray);
166
+
167
+            // Define $sendtocc
168
+            $receivercc=$_POST['receivercc'];
169
+            if (! is_array($receivercc))
170
+            {
171
+                if ($receivercc == '-1') $receivercc=array();
172
+                else $receivercc=array($receivercc);
173
+            }
174
+            $tmparray=array();
175
+            if (trim($_POST['sendtocc']))
176
+            {
177
+                $tmparray[] = trim($_POST['sendtocc']);
178
+            }
179
+            if (count($receivercc) > 0)
180
+            {
181
+                foreach($receivercc as $key=>$val)
182
+                {
183
+                    // Recipient was provided from combo list
184
+                    if ($val == 'thirdparty') // Id of third party
185
+                    {
186
+                        $tmparray[] = $thirdparty->name.' <'.$thirdparty->email.'>';
187
+                    }
188
+                    elseif ($val)	// Id du contact
189
+                    {
190
+                        $tmparray[] = $thirdparty->contact_get_property((int) $val,'email');
191
+                        //$sendtoid[] = $val;  TODO Add also id of contact in CC ?
192
+                    }
193
+                }
194
+            }
195
+            $sendtocc=implode(',',$tmparray);
196
+
197
+            //var_dump($listofobjectref);exit;
198
+            $attachedfiles=array('paths'=>array(), 'names'=>array(), 'mimes'=>array());
199
+            $listofqualifiedobj=array();
200
+            $listofqualifiedref=array();
201
+            $thirdpartywithoutemail=array();
202
+
203
+            foreach($listofobjectref[$thirdpartyid] as $objectid => $objectobj)
204
+            {
205
+                //var_dump($thirdpartyid.' - '.$objectid.' - '.$objectobj->statut);
206
+                if ($objectclass == 'Propal' && $objectobj->statut == Propal::STATUS_DRAFT)
207
+                {
208
+                    $langs->load("errors");
209
+                    $nbignored++;
210
+                    $resaction.='<div class="error">'.$langs->trans('ErrorOnlyProposalNotDraftCanBeSentInMassAction',$objectobj->ref).'</div><br>';
211
+                    continue; // Payment done or started or canceled
212
+                }
213
+                if ($objectclass == 'Commande' && $objectoj->statut == Commande::STATUS_DRAFT)
214
+                {
215
+                    $langs->load("errors");
216
+                    $nbignored++;
217
+                    $resaction.='<div class="error">'.$langs->trans('ErrorOnlyOrderNotDraftCanBeSentInMassAction',$objectobj->ref).'</div><br>';
218
+                    continue;
219
+                }
220
+                if ($objectclass == 'Facture' && $objectobj->statut == Facture::STATUS_DRAFT)
221
+                {
222
+                    $langs->load("errors");
223
+                    $nbignored++;
224
+                    $resaction.='<div class="error">'.$langs->trans('ErrorOnlyInvoiceValidatedCanBeSentInMassAction',$objectobj->ref).'</div><br>';
225
+                    continue; // Payment done or started or canceled
226
+                }
227
+
228
+                // Test recipient
229
+                if (empty($sendto)) 	// For the case, no recipient were set (multi thirdparties send)
230
+                {
231
+                    if ($objectobj->element == 'expensereport')
232
+                    {
233
+                        $fuser = new User($db);
234
+                        $fuser->fetch($objectobj->fk_user_author);
235
+                        $sendto = $fuser->email;
236
+                    }
237
+                    else
238
+                    {
239
+                        $objectobj->fetch_thirdparty();
240
+                        $sendto = $objectobj->thirdparty->email;
241
+                    }
242
+                }
243
+
244
+                if (empty($sendto))
245
+                {
246
+                        //print "No recipient for thirdparty ".$objectobj->thirdparty->name;
247
+                        $nbignored++;
248
+                        if (empty($thirdpartywithoutemail[$objectobj->thirdparty->id]))
249
+                    {
250
+                        $resaction.='<div class="error">'.$langs->trans('NoRecipientEmail',$objectobj->thirdparty->name).'</div><br>';
251
+                    }
252
+                    dol_syslog('No recipient for thirdparty: '.$objectobj->thirdparty->name, LOG_WARNING);
253
+                    $thirdpartywithoutemail[$objectobj->thirdparty->id]=1;
254
+                        continue;
255
+                }
256
+
257
+                if ($_POST['addmaindocfile'])
258
+                {
259
+                    // TODO Use future field $objectobj->fullpathdoc to know where is stored default file
260
+                    // TODO If not defined, use $objectobj->modelpdf (or defaut invoice config) to know what is template to use to regenerate doc.
261
+                    $filename=dol_sanitizeFileName($objectobj->ref).'.pdf';
262
+                    $filedir=$uploaddir . '/' . dol_sanitizeFileName($objectobj->ref);
263
+                    $file = $filedir . '/' . $filename;
264
+                    $mime = dol_mimetype($file);
265
+
266
+                        if (dol_is_file($file))
267
+                    {
268
+                            // Create form object
269
+                            $attachedfiles=array(
270
+                            'paths'=>array_merge($attachedfiles['paths'],array($file)),
271
+                            'names'=>array_merge($attachedfiles['names'],array($filename)),
272
+                            'mimes'=>array_merge($attachedfiles['mimes'],array($mime))
273
+                            );
274
+                    }
275
+                    else
276
+                    {
277
+                            $nbignored++;
278
+                            $langs->load("errors");
279
+                            $resaction.='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div><br>';
280
+                            dol_syslog('Failed to read file: '.$file, LOG_WARNING);
281
+                            continue;
282
+                    }
283
+                }
284
+
285
+                // Object of thirdparty qualified
286
+                $listofqualifiedobj[$objectid]=$objectobj;
287
+                $listofqualifiedref[$objectid]=$objectobj->ref;
288
+
289
+
290
+                //var_dump($listofqualifiedref);
291
+            }
292
+
293
+            // Send email if there is at least one qualified record
294
+            if (count($listofqualifiedobj) > 0)
295
+            {
296
+                $langs->load("commercial");
297
+
298
+                $fromtype = GETPOST('fromtype');
299
+                if ($fromtype === 'user') {
300
+                    $from = $user->getFullName($langs) .' <'.$user->email.'>';
301
+                }
302
+                elseif ($fromtype === 'company') {
303
+                    $from = $conf->global->MAIN_INFO_SOCIETE_NOM .' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>';
304
+                }
305
+                elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) {
306
+                    $tmp=explode(',', $user->email_aliases);
307
+                    $from = trim($tmp[($reg[1] - 1)]);
308
+                }
309
+                elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) {
310
+                    $tmp=explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
311
+                    $from = trim($tmp[($reg[1] - 1)]);
312
+                }
313
+                elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
314
+                    $sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE rowid = '.(int) $reg[1];
315
+                    $resql = $db->query($sql);
316
+                    $obj = $db->fetch_object($resql);
317
+                    if ($obj)
318
+                    {
319
+                        $from = $obj->label.' <'.$obj->email.'>';
320
+                    }
321
+                }
322
+                else {
323
+                    $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
324
+                }
325
+
326
+                $replyto = $from;
327
+                $subject = GETPOST('subject','none');
328
+                $message = GETPOST('message','none');
329
+
330
+                $sendtobcc = GETPOST('sendtoccc');
331
+                if ($objectclass == 'Propal') 				$sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO));
332
+                if ($objectclass == 'Commande') 			$sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO));
333
+                if ($objectclass == 'Facture') 				$sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO));
334
+                if ($objectclass == 'Supplier_Proposal') 	$sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO));
335
+                if ($objectclass == 'CommandeFournisseur')	$sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO));
336
+                if ($objectclass == 'FactureFournisseur')	$sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO));
337
+
338
+                // $listofqualifiedobj is array with key = object id and value is instance of qualified objects, for the current thirdparty (but thirdparty property is not loaded yet)
339
+                $oneemailperrecipient=(GETPOST('oneemailperrecipient')=='on'?1:0);
340
+                $looparray=array();
341
+                if (! $oneemailperrecipient)
342
+                {
343
+                    $looparray = $listofqualifiedobj;
344
+                    foreach ($looparray as $key => $objecttmp)
345
+                    {
346
+                        $looparray[$key]->thirdparty = $thirdparty;
347
+                    }
348
+                }
349
+                else
350
+                {
351
+                    $objectforloop=new $objectclass($db);
352
+                    $objectforloop->thirdparty = $thirdparty;
353
+                    $looparray[0]=$objectforloop;
354
+                }
355
+                //var_dump($looparray);exit;
356
+
357
+                foreach ($looparray as $objecttmp)		// $objecttmp is a real object or an empty object if we choose to send one email per thirdparty instead of one per record
358
+                {
359
+                    // Make substitution in email content
360
+                    $substitutionarray=getCommonSubstitutionArray($langs, 0, null, $objecttmp);
361
+                    $substitutionarray['__ID__']    = ($oneemailperrecipient ? join(', ',array_keys($listofqualifiedobj)) : $objecttmp->id);
362
+                    $substitutionarray['__REF__']   = ($oneemailperrecipient ? join(', ',$listofqualifiedref) : $objecttmp->ref);
363
+                    $substitutionarray['__EMAIL__'] = $thirdparty->email;
364
+                    $substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$thirdparty->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
365
+
366
+                    $parameters=array('mode'=>'formemail');
367
+
368
+                    if ( ! empty( $listofobjectthirdparties ) ) {
369
+                        $parameters['listofobjectthirdparties'] = $listofobjectthirdparties;
370
+                    }
371
+                    if ( ! empty( $listofobjectref ) ) {
372
+                        $parameters['listofobjectref'] = $listofobjectref;
373
+                    }
374
+
375
+                    complete_substitutions_array($substitutionarray, $langs, $objecttmp, $parameters);
376
+
377
+                    $subject=make_substitutions($subject, $substitutionarray);
378
+                    $message=make_substitutions($message, $substitutionarray);
379
+
380
+                    $filepath = $attachedfiles['paths'];
381
+                    $filename = $attachedfiles['names'];
382
+                    $mimetype = $attachedfiles['mimes'];
383
+
384
+                    // Define the trackid when emails sent from the mass action
385
+                    if ($oneemailperrecipient)
386
+                    {
387
+                        $trackid='thi'.$thirdparty->id;
388
+                        if ($objecttmp->element == 'expensereport') $trackid='use'.$thirdparty->id;
389
+                        if ($objecttmp->element == 'holiday') $trackid='use'.$thirdparty->id;
390
+                    }
391
+                    else
392
+                    {
393
+                        $trackid=strtolower(get_class($objecttmp));
394
+                        if (get_class($objecttmp)=='Contrat')  $trackid='con';
395
+                        if (get_class($objecttmp)=='Propal')   $trackid='pro';
396
+                        if (get_class($objecttmp)=='Commande') $trackid='ord';
397
+                        if (get_class($objecttmp)=='Facture')  $trackid='inv';
398
+                        if (get_class($objecttmp)=='Supplier_Proposal')   $trackid='spr';
399
+                        if (get_class($objecttmp)=='CommandeFournisseur') $trackid='sor';
400
+                        if (get_class($objecttmp)=='FactureFournisseur')  $trackid='sin';
401
+
402
+                        $trackid.=$objecttmp->id;
403
+                    }
404
+                    //var_dump($filepath);
405
+                    //var_dump($trackid);exit;
406
+
407
+                    // Send mail (substitutionarray must be done just before this)
408
+                    require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
409
+                    $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1,'','',$trackid);
410
+                    if ($mailfile->error)
411
+                    {
412
+                        $resaction.='<div class="error">'.$mailfile->error.'</div>';
413
+                    }
414
+                    else
415
+                    {
416
+                        $result=$mailfile->sendfile();
417
+                        if ($result)
418
+                        {
419
+                            $resaction.=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)).'<br>';		// Must not contain "
420
+
421
+                            $error=0;
422
+
423
+                            // Insert logs into agenda
424
+                            foreach($listofqualifiedobj as $objid => $objectobj)
425
+                            {
426
+                                /*if ($objectclass == 'Propale') $actiontypecode='AC_PROP';
427 427
 	                            if ($objectclass == 'Commande') $actiontypecode='AC_COM';
428 428
 	                            if ($objectclass == 'Facture') $actiontypecode='AC_FAC';
429 429
 	                            if ($objectclass == 'Supplier_Proposal') $actiontypecode='AC_SUP_PRO';
430 430
 	                            if ($objectclass == 'CommandeFournisseur') $actiontypecode='AC_SUP_ORD';
431 431
 	                            if ($objectclass == 'FactureFournisseur') $actiontypecode='AC_SUP_INV';*/
432 432
 
433
-								$actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
434
-								if ($message)
435
-								{
436
-									if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
437
-									$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
438
-									$actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
439
-									$actionmsg = dol_concatdesc($actionmsg, $message);
440
-								}
441
-								$actionmsg2='';
442
-
443
-								// Initialisation donnees
444
-								$objectobj->sendtoid		= 0;
445
-								$objectobj->actionmsg		= $actionmsg;  // Long text
446
-								$objectobj->actionmsg2		= $actionmsg2; // Short text
447
-								$objectobj->fk_element		= $objid;
448
-								$objectobj->elementtype	= $objectobj->element;
449
-
450
-								$triggername = strtoupper(get_class($objectobj)) .'_SENTBYMAIL';
451
-								if ($triggername == 'SOCIETE_SENTBYMAIL')    $triggername = 'COMPANY_SENTBYEMAIL';
452
-								if ($triggername == 'CONTRAT_SENTBYMAIL')    $triggername = 'CONTRACT_SENTBYEMAIL';
453
-								if ($triggername == 'COMMANDE_SENTBYMAIL')   $triggername = 'ORDER_SENTBYEMAIL';
454
-								if ($triggername == 'FACTURE_SENTBYMAIL')    $triggername = 'BILL_SENTBYMAIL';
455
-								if ($triggername == 'EXPEDITION_SENTBYMAIL') $triggername = 'SHIPPING_SENTBYEMAIL';
456
-								if ($triggername == 'COMMANDEFOURNISSEUR_SENTBYMAIL') $triggername = 'ORDER_SUPPLIER_SENTBYMAIL';
457
-								if ($triggername == 'FACTUREFOURNISSEUR_SENTBYMAIL') $triggername = 'BILL_SUPPLIER_SENTBYEMAIL';
458
-								if ($triggername == 'SUPPLIERPROPOSAL_SENTBYMAIL') $triggername = 'PROPOSAL_SUPPLIER_SENTBYEMAIL';
459
-
460
-								if (! empty($triggername))
461
-								{
462
-									// Appel des triggers
463
-									include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
464
-									$interface=new Interfaces($db);
465
-									$result=$interface->run_triggers($triggername, $objectobj, $user, $langs, $conf);
466
-									if ($result < 0) { $error++; $errors=$interface->errors; }
467
-									// Fin appel triggers
468
-
469
-									if ($error)
470
-									{
471
-										setEventMessages($db->lasterror(), $errors, 'errors');
472
-										dol_syslog("Error in trigger ".$triggername.' '.$db->lasterror(), LOG_ERR);
473
-									}
474
-								}
475
-
476
-								$nbsent++;
477
-							}
478
-						}
479
-						else
480
-						{
481
-							$langs->load("other");
482
-							if ($mailfile->error)
483
-							{
484
-								$resaction.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
485
-								$resaction.='<br><div class="error">'.$mailfile->error.'</div>';
486
-							}
487
-							else
488
-							{
489
-								$resaction.='<div class="warning">No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS</div>';
490
-							}
491
-						}
492
-					}
493
-				}
494
-			}
495
-		}
496
-
497
-		$resaction.=($resaction?'<br>':$resaction);
498
-		$resaction.='<strong>'.$langs->trans("ResultOfMailSending").':</strong><br>'."\n";
499
-		$resaction.=$langs->trans("NbSelected").': '.count($toselect)."\n<br>";
500
-		$resaction.=$langs->trans("NbIgnored").': '.($nbignored?$nbignored:0)."\n<br>";
501
-		$resaction.=$langs->trans("NbSent").': '.($nbsent?$nbsent:0)."\n<br>";
502
-
503
-		if ($nbsent)
504
-		{
505
-			$action='';	// Do not show form post if there was at least one successfull sent
506
-			//setEventMessages($langs->trans("EMailSentToNRecipients", $nbsent.'/'.count($toselect)), null, 'mesgs');
507
-			setEventMessages($langs->trans("EMailSentForNElements", $nbsent.'/'.count($toselect)), null, 'mesgs');
508
-			setEventMessages($resaction, null, 'mesgs');
509
-		}
510
-		else
511
-		{
512
-			//setEventMessages($langs->trans("EMailSentToNRecipients", 0), null, 'warnings');  // May be object has no generated PDF file
513
-			setEventMessages($resaction, null, 'warnings');
514
-		}
515
-
516
-		$action='list';
517
-		$massaction='';
518
-	}
433
+                                $actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
434
+                                if ($message)
435
+                                {
436
+                                    if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
437
+                                    $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
438
+                                    $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
439
+                                    $actionmsg = dol_concatdesc($actionmsg, $message);
440
+                                }
441
+                                $actionmsg2='';
442
+
443
+                                // Initialisation donnees
444
+                                $objectobj->sendtoid		= 0;
445
+                                $objectobj->actionmsg		= $actionmsg;  // Long text
446
+                                $objectobj->actionmsg2		= $actionmsg2; // Short text
447
+                                $objectobj->fk_element		= $objid;
448
+                                $objectobj->elementtype	= $objectobj->element;
449
+
450
+                                $triggername = strtoupper(get_class($objectobj)) .'_SENTBYMAIL';
451
+                                if ($triggername == 'SOCIETE_SENTBYMAIL')    $triggername = 'COMPANY_SENTBYEMAIL';
452
+                                if ($triggername == 'CONTRAT_SENTBYMAIL')    $triggername = 'CONTRACT_SENTBYEMAIL';
453
+                                if ($triggername == 'COMMANDE_SENTBYMAIL')   $triggername = 'ORDER_SENTBYEMAIL';
454
+                                if ($triggername == 'FACTURE_SENTBYMAIL')    $triggername = 'BILL_SENTBYMAIL';
455
+                                if ($triggername == 'EXPEDITION_SENTBYMAIL') $triggername = 'SHIPPING_SENTBYEMAIL';
456
+                                if ($triggername == 'COMMANDEFOURNISSEUR_SENTBYMAIL') $triggername = 'ORDER_SUPPLIER_SENTBYMAIL';
457
+                                if ($triggername == 'FACTUREFOURNISSEUR_SENTBYMAIL') $triggername = 'BILL_SUPPLIER_SENTBYEMAIL';
458
+                                if ($triggername == 'SUPPLIERPROPOSAL_SENTBYMAIL') $triggername = 'PROPOSAL_SUPPLIER_SENTBYEMAIL';
459
+
460
+                                if (! empty($triggername))
461
+                                {
462
+                                    // Appel des triggers
463
+                                    include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
464
+                                    $interface=new Interfaces($db);
465
+                                    $result=$interface->run_triggers($triggername, $objectobj, $user, $langs, $conf);
466
+                                    if ($result < 0) { $error++; $errors=$interface->errors; }
467
+                                    // Fin appel triggers
468
+
469
+                                    if ($error)
470
+                                    {
471
+                                        setEventMessages($db->lasterror(), $errors, 'errors');
472
+                                        dol_syslog("Error in trigger ".$triggername.' '.$db->lasterror(), LOG_ERR);
473
+                                    }
474
+                                }
475
+
476
+                                $nbsent++;
477
+                            }
478
+                        }
479
+                        else
480
+                        {
481
+                            $langs->load("other");
482
+                            if ($mailfile->error)
483
+                            {
484
+                                $resaction.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
485
+                                $resaction.='<br><div class="error">'.$mailfile->error.'</div>';
486
+                            }
487
+                            else
488
+                            {
489
+                                $resaction.='<div class="warning">No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS</div>';
490
+                            }
491
+                        }
492
+                    }
493
+                }
494
+            }
495
+        }
496
+
497
+        $resaction.=($resaction?'<br>':$resaction);
498
+        $resaction.='<strong>'.$langs->trans("ResultOfMailSending").':</strong><br>'."\n";
499
+        $resaction.=$langs->trans("NbSelected").': '.count($toselect)."\n<br>";
500
+        $resaction.=$langs->trans("NbIgnored").': '.($nbignored?$nbignored:0)."\n<br>";
501
+        $resaction.=$langs->trans("NbSent").': '.($nbsent?$nbsent:0)."\n<br>";
502
+
503
+        if ($nbsent)
504
+        {
505
+            $action='';	// Do not show form post if there was at least one successfull sent
506
+            //setEventMessages($langs->trans("EMailSentToNRecipients", $nbsent.'/'.count($toselect)), null, 'mesgs');
507
+            setEventMessages($langs->trans("EMailSentForNElements", $nbsent.'/'.count($toselect)), null, 'mesgs');
508
+            setEventMessages($resaction, null, 'mesgs');
509
+        }
510
+        else
511
+        {
512
+            //setEventMessages($langs->trans("EMailSentToNRecipients", 0), null, 'warnings');  // May be object has no generated PDF file
513
+            setEventMessages($resaction, null, 'warnings');
514
+        }
515
+
516
+        $action='list';
517
+        $massaction='';
518
+    }
519 519
 }
520 520
 
521 521
 if ($massaction == 'confirm_createbills')
522 522
 {
523
-	$orders = GETPOST('toselect','array');
524
-	$createbills_onebythird = GETPOST('createbills_onebythird', 'int');
525
-	$validate_invoices = GETPOST('valdate_invoices', 'int');
526
-
527
-	$TFact = array();
528
-	$TFactThird = array();
529
-
530
-	$nb_bills_created = 0;
531
-
532
-	$db->begin();
533
-
534
-	foreach($orders as $id_order)
535
-	{
536
-		$cmd = new Commande($db);
537
-		if ($cmd->fetch($id_order) <= 0) continue;
538
-
539
-		$objecttmp = new Facture($db);
540
-		if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $objecttmp = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order.
541
-		else {
542
-
543
-			$objecttmp->socid = $cmd->socid;
544
-			$objecttmp->type = Facture::TYPE_STANDARD;
545
-			$objecttmp->cond_reglement_id	= $cmd->cond_reglement_id;
546
-			$objecttmp->mode_reglement_id	= $cmd->mode_reglement_id;
547
-			$objecttmp->fk_project			= $cmd->fk_project;
548
-
549
-			$datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
550
-			if (empty($datefacture))
551
-			{
552
-				$datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y"));
553
-			}
554
-
555
-			$objecttmp->date = $datefacture;
556
-			$objecttmp->origin    = 'commande';
557
-			$objecttmp->origin_id = $id_order;
558
-
559
-			$res = $objecttmp->create($user);
560
-
561
-			if($res > 0) $nb_bills_created++;
562
-		}
563
-
564
-		if ($objecttmp->id > 0)
565
-		{
566
-			$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
567
-			$sql.= "fk_source";
568
-			$sql.= ", sourcetype";
569
-			$sql.= ", fk_target";
570
-			$sql.= ", targettype";
571
-			$sql.= ") VALUES (";
572
-			$sql.= $id_order;
573
-			$sql.= ", '".$objecttmp->origin."'";
574
-			$sql.= ", ".$objecttmp->id;
575
-			$sql.= ", '".$objecttmp->element."'";
576
-			$sql.= ")";
577
-
578
-			if (! $db->query($sql))
579
-			{
580
-				$error++;
581
-			}
582
-
583
-			if (! $error)
584
-			{
585
-				$lines = $cmd->lines;
586
-				if (empty($lines) && method_exists($cmd, 'fetch_lines'))
587
-				{
588
-					$cmd->fetch_lines();
589
-					$lines = $cmd->lines;
590
-				}
591
-
592
-				$fk_parent_line=0;
593
-				$num=count($lines);
594
-
595
-				for ($i=0;$i<$num;$i++)
596
-				{
597
-					$desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle);
598
-					if ($lines[$i]->subprice < 0)
599
-					{
600
-						// Negative line, we create a discount line
601
-						$discount = new DiscountAbsolute($db);
602
-						$discount->fk_soc=$objecttmp->socid;
603
-						$discount->amount_ht=abs($lines[$i]->total_ht);
604
-						$discount->amount_tva=abs($lines[$i]->total_tva);
605
-						$discount->amount_ttc=abs($lines[$i]->total_ttc);
606
-						$discount->tva_tx=$lines[$i]->tva_tx;
607
-						$discount->fk_user=$user->id;
608
-						$discount->description=$desc;
609
-						$discountid=$discount->create($user);
610
-						if ($discountid > 0)
611
-						{
612
-							$result=$objecttmp->insert_discount($discountid);
613
-							//$result=$discount->link_to_invoice($lineid,$id);
614
-						}
615
-						else
616
-						{
617
-							setEventMessages($discount->error, $discount->errors, 'errors');
618
-							$error++;
619
-							break;
620
-						}
621
-					}
622
-					else
623
-					{
624
-						// Positive line
625
-						$product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
626
-						// Date start
627
-						$date_start=false;
628
-						if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue;
629
-						if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel;
630
-						if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start;
631
-						//Date end
632
-						$date_end=false;
633
-						if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue;
634
-						if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
635
-						if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
636
-						// Reset fk_parent_line for no child products and special product
637
-						if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9)
638
-						{
639
-							$fk_parent_line = 0;
640
-						}
641
-
642
-						// Extrafields
643
-						if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines[$i], 'fetch_optionals')) {
644
-							$lines[$i]->fetch_optionals($lines[$i]->rowid);
645
-							$array_options = $lines[$i]->array_options;
646
-						}
647
-
648
-						$result = $objecttmp->addline(
649
-							$desc,
650
-							$lines[$i]->subprice,
651
-							$lines[$i]->qty,
652
-							$lines[$i]->tva_tx,
653
-							$lines[$i]->localtax1_tx,
654
-							$lines[$i]->localtax2_tx,
655
-							$lines[$i]->fk_product,
656
-							$lines[$i]->remise_percent,
657
-							$date_start,
658
-							$date_end,
659
-							0,
660
-							$lines[$i]->info_bits,
661
-							$lines[$i]->fk_remise_except,
662
-							'HT',
663
-							0,
664
-							$product_type,
665
-							$ii,
666
-							$lines[$i]->special_code,
667
-							$objecttmp->origin,
668
-							$lines[$i]->rowid,
669
-							$fk_parent_line,
670
-							$lines[$i]->fk_fournprice,
671
-							$lines[$i]->pa_ht,
672
-							$lines[$i]->label,
673
-							$array_options
674
-							);
675
-						if ($result > 0)
676
-						{
677
-							$lineid=$result;
678
-						}
679
-						else
680
-						{
681
-							$lineid=0;
682
-							$error++;
683
-							break;
684
-						}
685
-						// Defined the new fk_parent_line
686
-						if ($result > 0 && $lines[$i]->product_type == 9)
687
-						{
688
-							$fk_parent_line = $result;
689
-						}
690
-					}
691
-				}
692
-			}
693
-		}
694
-
695
-		//$cmd->classifyBilled($user);        // Disabled. This behavior must be set or not using the workflow module.
696
-
697
-		if(!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) $TFactThird[$cmd->socid] = $objecttmp;
698
-		else $TFact[$objecttmp->id] = $objecttmp;
699
-	}
700
-
701
-	// Build doc with all invoices
702
-	$TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
703
-	$toselect = array();
704
-
705
-	if (! $error && $validate_invoices)
706
-	{
707
-		$massaction = $action = 'builddoc';
708
-		foreach($TAllFact as &$objecttmp)
709
-		{
710
-			$result = $objecttmp->validate($user);
711
-			if ($result <= 0)
712
-			{
713
-				$error++;
714
-				setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
715
-				break;
716
-			}
717
-
718
-			$id = $objecttmp->id; // For builddoc action
719
-
720
-			// Builddoc
721
-			$donotredirect = 1;
722
-			$upload_dir = $conf->facture->dir_output;
723
-			$permissioncreate=$user->rights->facture->creer;
724
-			include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
725
-		}
726
-
727
-		$massaction = $action = 'confirm_createbills';
728
-	}
729
-
730
-	if (! $error)
731
-	{
732
-		$db->commit();
733
-		setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
734
-
735
-		// Make a redirect to avoid to bill twice if we make a refresh or back
736
-		$param='';
737
-		if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
738
-		if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
739
-		if ($sall)					$param.='&sall='.urlencode($sall);
740
-		if ($socid > 0)             $param.='&socid='.urlencode($socid);
741
-		if ($viewstatut != '')      $param.='&viewstatut='.urlencode($viewstatut);
742
-		if ($search_orderday)      		$param.='&search_orderday='.urlencode($search_orderday);
743
-		if ($search_ordermonth)      		$param.='&search_ordermonth='.urlencode($search_ordermonth);
744
-		if ($search_orderyear)       		$param.='&search_orderyear='.urlencode($search_orderyear);
745
-		if ($search_deliveryday)   		$param.='&search_deliveryday='.urlencode($search_deliveryday);
746
-		if ($search_deliverymonth)   		$param.='&search_deliverymonth='.urlencode($search_deliverymonth);
747
-		if ($search_deliveryyear)    		$param.='&search_deliveryyear='.urlencode($search_deliveryyear);
748
-		if ($search_ref)      		$param.='&search_ref='.urlencode($search_ref);
749
-		if ($search_company)  		$param.='&search_company='.urlencode($search_company);
750
-		if ($search_ref_customer)	$param.='&search_ref_customer='.urlencode($search_ref_customer);
751
-		if ($search_user > 0) 		$param.='&search_user='.urlencode($search_user);
752
-		if ($search_sale > 0) 		$param.='&search_sale='.urlencode($search_sale);
753
-		if ($search_total_ht != '') $param.='&search_total_ht='.urlencode($search_total_ht);
754
-		if ($search_total_vat != '') $param.='&search_total_vat='.urlencode($search_total_vat);
755
-		if ($search_total_ttc != '') $param.='&search_total_ttc='.urlencode($search_total_ttc);
756
-		if ($search_project_ref >= 0)  	$param.="&search_project_ref=".urlencode($search_project_ref);
757
-		if ($show_files)            $param.='&show_files=' .urlencode($show_files);
758
-		if ($optioncss != '')       $param.='&optioncss='.urlencode($optioncss);
759
-		if ($billed != '')			$param.='&billed='.urlencode($billed);
760
-
761
-		header("Location: ".$_SERVER['PHP_SELF'].'?'.$param);
762
-		exit;
763
-	}
764
-	else
765
-	{
766
-		$db->rollback();
767
-		$action='create';
768
-		$_GET["origin"]=$_POST["origin"];
769
-		$_GET["originid"]=$_POST["originid"];
770
-		setEventMessages("Error", null, 'errors');
771
-		$error++;
772
-	}
523
+    $orders = GETPOST('toselect','array');
524
+    $createbills_onebythird = GETPOST('createbills_onebythird', 'int');
525
+    $validate_invoices = GETPOST('valdate_invoices', 'int');
526
+
527
+    $TFact = array();
528
+    $TFactThird = array();
529
+
530
+    $nb_bills_created = 0;
531
+
532
+    $db->begin();
533
+
534
+    foreach($orders as $id_order)
535
+    {
536
+        $cmd = new Commande($db);
537
+        if ($cmd->fetch($id_order) <= 0) continue;
538
+
539
+        $objecttmp = new Facture($db);
540
+        if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $objecttmp = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order.
541
+        else {
542
+
543
+            $objecttmp->socid = $cmd->socid;
544
+            $objecttmp->type = Facture::TYPE_STANDARD;
545
+            $objecttmp->cond_reglement_id	= $cmd->cond_reglement_id;
546
+            $objecttmp->mode_reglement_id	= $cmd->mode_reglement_id;
547
+            $objecttmp->fk_project			= $cmd->fk_project;
548
+
549
+            $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
550
+            if (empty($datefacture))
551
+            {
552
+                $datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y"));
553
+            }
554
+
555
+            $objecttmp->date = $datefacture;
556
+            $objecttmp->origin    = 'commande';
557
+            $objecttmp->origin_id = $id_order;
558
+
559
+            $res = $objecttmp->create($user);
560
+
561
+            if($res > 0) $nb_bills_created++;
562
+        }
563
+
564
+        if ($objecttmp->id > 0)
565
+        {
566
+            $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
567
+            $sql.= "fk_source";
568
+            $sql.= ", sourcetype";
569
+            $sql.= ", fk_target";
570
+            $sql.= ", targettype";
571
+            $sql.= ") VALUES (";
572
+            $sql.= $id_order;
573
+            $sql.= ", '".$objecttmp->origin."'";
574
+            $sql.= ", ".$objecttmp->id;
575
+            $sql.= ", '".$objecttmp->element."'";
576
+            $sql.= ")";
577
+
578
+            if (! $db->query($sql))
579
+            {
580
+                $error++;
581
+            }
582
+
583
+            if (! $error)
584
+            {
585
+                $lines = $cmd->lines;
586
+                if (empty($lines) && method_exists($cmd, 'fetch_lines'))
587
+                {
588
+                    $cmd->fetch_lines();
589
+                    $lines = $cmd->lines;
590
+                }
591
+
592
+                $fk_parent_line=0;
593
+                $num=count($lines);
594
+
595
+                for ($i=0;$i<$num;$i++)
596
+                {
597
+                    $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle);
598
+                    if ($lines[$i]->subprice < 0)
599
+                    {
600
+                        // Negative line, we create a discount line
601
+                        $discount = new DiscountAbsolute($db);
602
+                        $discount->fk_soc=$objecttmp->socid;
603
+                        $discount->amount_ht=abs($lines[$i]->total_ht);
604
+                        $discount->amount_tva=abs($lines[$i]->total_tva);
605
+                        $discount->amount_ttc=abs($lines[$i]->total_ttc);
606
+                        $discount->tva_tx=$lines[$i]->tva_tx;
607
+                        $discount->fk_user=$user->id;
608
+                        $discount->description=$desc;
609
+                        $discountid=$discount->create($user);
610
+                        if ($discountid > 0)
611
+                        {
612
+                            $result=$objecttmp->insert_discount($discountid);
613
+                            //$result=$discount->link_to_invoice($lineid,$id);
614
+                        }
615
+                        else
616
+                        {
617
+                            setEventMessages($discount->error, $discount->errors, 'errors');
618
+                            $error++;
619
+                            break;
620
+                        }
621
+                    }
622
+                    else
623
+                    {
624
+                        // Positive line
625
+                        $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
626
+                        // Date start
627
+                        $date_start=false;
628
+                        if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue;
629
+                        if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel;
630
+                        if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start;
631
+                        //Date end
632
+                        $date_end=false;
633
+                        if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue;
634
+                        if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
635
+                        if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
636
+                        // Reset fk_parent_line for no child products and special product
637
+                        if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9)
638
+                        {
639
+                            $fk_parent_line = 0;
640
+                        }
641
+
642
+                        // Extrafields
643
+                        if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines[$i], 'fetch_optionals')) {
644
+                            $lines[$i]->fetch_optionals($lines[$i]->rowid);
645
+                            $array_options = $lines[$i]->array_options;
646
+                        }
647
+
648
+                        $result = $objecttmp->addline(
649
+                            $desc,
650
+                            $lines[$i]->subprice,
651
+                            $lines[$i]->qty,
652
+                            $lines[$i]->tva_tx,
653
+                            $lines[$i]->localtax1_tx,
654
+                            $lines[$i]->localtax2_tx,
655
+                            $lines[$i]->fk_product,
656
+                            $lines[$i]->remise_percent,
657
+                            $date_start,
658
+                            $date_end,
659
+                            0,
660
+                            $lines[$i]->info_bits,
661
+                            $lines[$i]->fk_remise_except,
662
+                            'HT',
663
+                            0,
664
+                            $product_type,
665
+                            $ii,
666
+                            $lines[$i]->special_code,
667
+                            $objecttmp->origin,
668
+                            $lines[$i]->rowid,
669
+                            $fk_parent_line,
670
+                            $lines[$i]->fk_fournprice,
671
+                            $lines[$i]->pa_ht,
672
+                            $lines[$i]->label,
673
+                            $array_options
674
+                            );
675
+                        if ($result > 0)
676
+                        {
677
+                            $lineid=$result;
678
+                        }
679
+                        else
680
+                        {
681
+                            $lineid=0;
682
+                            $error++;
683
+                            break;
684
+                        }
685
+                        // Defined the new fk_parent_line
686
+                        if ($result > 0 && $lines[$i]->product_type == 9)
687
+                        {
688
+                            $fk_parent_line = $result;
689
+                        }
690
+                    }
691
+                }
692
+            }
693
+        }
694
+
695
+        //$cmd->classifyBilled($user);        // Disabled. This behavior must be set or not using the workflow module.
696
+
697
+        if(!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) $TFactThird[$cmd->socid] = $objecttmp;
698
+        else $TFact[$objecttmp->id] = $objecttmp;
699
+    }
700
+
701
+    // Build doc with all invoices
702
+    $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
703
+    $toselect = array();
704
+
705
+    if (! $error && $validate_invoices)
706
+    {
707
+        $massaction = $action = 'builddoc';
708
+        foreach($TAllFact as &$objecttmp)
709
+        {
710
+            $result = $objecttmp->validate($user);
711
+            if ($result <= 0)
712
+            {
713
+                $error++;
714
+                setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
715
+                break;
716
+            }
717
+
718
+            $id = $objecttmp->id; // For builddoc action
719
+
720
+            // Builddoc
721
+            $donotredirect = 1;
722
+            $upload_dir = $conf->facture->dir_output;
723
+            $permissioncreate=$user->rights->facture->creer;
724
+            include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
725
+        }
726
+
727
+        $massaction = $action = 'confirm_createbills';
728
+    }
729
+
730
+    if (! $error)
731
+    {
732
+        $db->commit();
733
+        setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
734
+
735
+        // Make a redirect to avoid to bill twice if we make a refresh or back
736
+        $param='';
737
+        if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
738
+        if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
739
+        if ($sall)					$param.='&sall='.urlencode($sall);
740
+        if ($socid > 0)             $param.='&socid='.urlencode($socid);
741
+        if ($viewstatut != '')      $param.='&viewstatut='.urlencode($viewstatut);
742
+        if ($search_orderday)      		$param.='&search_orderday='.urlencode($search_orderday);
743
+        if ($search_ordermonth)      		$param.='&search_ordermonth='.urlencode($search_ordermonth);
744
+        if ($search_orderyear)       		$param.='&search_orderyear='.urlencode($search_orderyear);
745
+        if ($search_deliveryday)   		$param.='&search_deliveryday='.urlencode($search_deliveryday);
746
+        if ($search_deliverymonth)   		$param.='&search_deliverymonth='.urlencode($search_deliverymonth);
747
+        if ($search_deliveryyear)    		$param.='&search_deliveryyear='.urlencode($search_deliveryyear);
748
+        if ($search_ref)      		$param.='&search_ref='.urlencode($search_ref);
749
+        if ($search_company)  		$param.='&search_company='.urlencode($search_company);
750
+        if ($search_ref_customer)	$param.='&search_ref_customer='.urlencode($search_ref_customer);
751
+        if ($search_user > 0) 		$param.='&search_user='.urlencode($search_user);
752
+        if ($search_sale > 0) 		$param.='&search_sale='.urlencode($search_sale);
753
+        if ($search_total_ht != '') $param.='&search_total_ht='.urlencode($search_total_ht);
754
+        if ($search_total_vat != '') $param.='&search_total_vat='.urlencode($search_total_vat);
755
+        if ($search_total_ttc != '') $param.='&search_total_ttc='.urlencode($search_total_ttc);
756
+        if ($search_project_ref >= 0)  	$param.="&search_project_ref=".urlencode($search_project_ref);
757
+        if ($show_files)            $param.='&show_files=' .urlencode($show_files);
758
+        if ($optioncss != '')       $param.='&optioncss='.urlencode($optioncss);
759
+        if ($billed != '')			$param.='&billed='.urlencode($billed);
760
+
761
+        header("Location: ".$_SERVER['PHP_SELF'].'?'.$param);
762
+        exit;
763
+    }
764
+    else
765
+    {
766
+        $db->rollback();
767
+        $action='create';
768
+        $_GET["origin"]=$_POST["origin"];
769
+        $_GET["originid"]=$_POST["originid"];
770
+        setEventMessages("Error", null, 'errors');
771
+        $error++;
772
+    }
773 773
 }
774 774
 
775 775
 if (!$error && $massaction == 'cancelorders')
776 776
 {
777 777
 
778
-	$db->begin();
779
-
780
-	$nbok = 0;
781
-
782
-
783
-	$orders = GETPOST('toselect', 'array');
784
-	foreach ($orders as $id_order)
785
-	{
786
-
787
-		$cmd = new Commande($db);
788
-		if ($cmd->fetch($id_order) <= 0)
789
-			continue;
790
-
791
-		if ($cmd->statut != Commande::STATUS_VALIDATED)
792
-		{
793
-			$langs->load('errors');
794
-			setEventMessages($langs->trans("ErrorObjectMustHaveStatusValidToBeCanceled", $cmd->ref), null, 'errors');
795
-			$error++;
796
-			break;
797
-		}
798
-		else
799
-			$result = $cmd->cancel();
800
-
801
-		if ($result < 0)
802
-		{
803
-			setEventMessages($cmd->error, $cmd->errors, 'errors');
804
-			$error++;
805
-			break;
806
-		}
807
-		else
808
-			$nbok++;
809
-	}
810
-	if (!$error)
811
-	{
812
-		if ($nbok > 1)
813
-			setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
814
-		else
815
-			setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
816
-		$db->commit();
817
-	}
818
-	else
819
-	{
820
-		$db->rollback();
821
-	}
778
+    $db->begin();
779
+
780
+    $nbok = 0;
781
+
782
+
783
+    $orders = GETPOST('toselect', 'array');
784
+    foreach ($orders as $id_order)
785
+    {
786
+
787
+        $cmd = new Commande($db);
788
+        if ($cmd->fetch($id_order) <= 0)
789
+            continue;
790
+
791
+        if ($cmd->statut != Commande::STATUS_VALIDATED)
792
+        {
793
+            $langs->load('errors');
794
+            setEventMessages($langs->trans("ErrorObjectMustHaveStatusValidToBeCanceled", $cmd->ref), null, 'errors');
795
+            $error++;
796
+            break;
797
+        }
798
+        else
799
+            $result = $cmd->cancel();
800
+
801
+        if ($result < 0)
802
+        {
803
+            setEventMessages($cmd->error, $cmd->errors, 'errors');
804
+            $error++;
805
+            break;
806
+        }
807
+        else
808
+            $nbok++;
809
+    }
810
+    if (!$error)
811
+    {
812
+        if ($nbok > 1)
813
+            setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
814
+        else
815
+            setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
816
+        $db->commit();
817
+    }
818
+    else
819
+    {
820
+        $db->rollback();
821
+    }
822 822
 }
823 823
 
824 824
 
825 825
 if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_search'))
826 826
 {
827
-	if (empty($diroutputmassaction))
828
-	{
829
-		dol_print_error(null, 'include of actions_massactions.inc.php is done but var $diroutputmassaction was not defined');
830
-		exit;
831
-	}
832
-
833
-	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
834
-	require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
835
-	require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
836
-
837
-	$objecttmp=new $objectclass($db);
838
-	$listofobjectid=array();
839
-	$listofobjectthirdparties=array();
840
-	$listofobjectref=array();
841
-	foreach($toselect as $toselectid)
842
-	{
843
-		$objecttmp=new $objectclass($db);	// must create new instance because instance is saved into $listofobjectref array for future use
844
-		$result=$objecttmp->fetch($toselectid);
845
-		if ($result > 0)
846
-		{
847
-			$listofobjectid[$toselectid]=$toselectid;
848
-			$thirdpartyid=$objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid;
849
-			$listofobjectthirdparties[$thirdpartyid]=$thirdpartyid;
850
-			$listofobjectref[$toselectid]=$objecttmp->ref;
851
-		}
852
-	}
853
-
854
-	$arrayofinclusion=array();
855
-	foreach($listofobjectref as $tmppdf) $arrayofinclusion[]='^'.preg_quote(dol_sanitizeFileName($tmppdf),'/').'\.pdf$';
856
-	foreach($listofobjectref as $tmppdf) $arrayofinclusion[]='^'.preg_quote(dol_sanitizeFileName($tmppdf),'/').'_[a-zA-Z0-9-_]+\.pdf$';	// To include PDF generated from ODX files
857
-	$listoffiles = dol_dir_list($uploaddir,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true);
858
-
859
-	// build list of files with full path
860
-	$files = array();
861
-	foreach($listofobjectref as $basename)
862
-	{
863
-		$basename = dol_sanitizeFileName($basename);
864
-		foreach($listoffiles as $filefound)
865
-		{
866
-			if (strstr($filefound["name"],$basename))
867
-			{
868
-				$files[] = $uploaddir.'/'.$basename.'/'.$filefound["name"];
869
-				break;
870
-			}
871
-		}
872
-	}
873
-
874
-	// Define output language (Here it is not used because we do only merging existing PDF)
875
-	$outputlangs = $langs;
876
-	$newlang='';
877
-	if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
878
-	if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$objecttmp->thirdparty->default_lang;
879
-	if (! empty($newlang))
880
-	{
881
-		$outputlangs = new Translate("",$conf);
882
-		$outputlangs->setDefaultLang($newlang);
883
-	}
884
-
885
-	if (!empty($conf->global->USE_PDFTK_FOR_PDF_CONCAT))
886
-	{
887
-		// Create output dir if not exists
888
-		dol_mkdir($diroutputmassaction);
889
-
890
-		// Defined name of merged file
891
-		$filename=strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel)));
892
-		$filename=preg_replace('/\s/','_',$filename);
893
-
894
-		// Save merged file
895
-		if (in_array($objecttmp->element, array('facture', 'facture_fournisseur')) && $search_status == Facture::STATUS_VALIDATED)
896
-		{
897
-			if ($option=='late') $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late")));
898
-			else $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid")));
899
-		}
900
-		if ($year) $filename.='_'.$year;
901
-		if ($month) $filename.='_'.$month;
902
-
903
-		if (count($files)>0)
904
-		{
905
-			$now=dol_now();
906
-			$file=$diroutputmassaction.'/'.$filename.'_'.dol_print_date($now,'dayhourlog').'.pdf';
907
-
908
-			$input_files = '';
909
-			foreach($files as $f) {
910
-				$input_files.=' '.escapeshellarg($f);
911
-			}
912
-
913
-			$cmd = 'pdftk '.escapeshellarg($input_files).' cat output '.escapeshellarg($file);
914
-			exec($cmd);
915
-
916
-			if (! empty($conf->global->MAIN_UMASK))
917
-				@chmod($file, octdec($conf->global->MAIN_UMASK));
918
-
919
-			$langs->load("exports");
920
-			setEventMessages($langs->trans('FileSuccessfullyBuilt',$filename.'_'.dol_print_date($now,'dayhourlog')), null, 'mesgs');
921
-		}
922
-		else
923
-		{
924
-			setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors');
925
-		}
926
-	}
927
-	else {
928
-		// Create empty PDF
929
-		$formatarray=pdf_getFormat();
930
-		$page_largeur = $formatarray['width'];
931
-		$page_hauteur = $formatarray['height'];
932
-		$format = array($page_largeur,$page_hauteur);
933
-
934
-		$pdf=pdf_getInstance($format);
935
-
936
-		if (class_exists('TCPDF'))
937
-		{
938
-			$pdf->setPrintHeader(false);
939
-			$pdf->setPrintFooter(false);
940
-		}
941
-		$pdf->SetFont(pdf_getPDFFont($outputlangs));
942
-
943
-		if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
944
-
945
-		// Add all others
946
-		foreach($files as $file)
947
-		{
948
-			// Charge un document PDF depuis un fichier.
949
-			$pagecount = $pdf->setSourceFile($file);
950
-			for ($i = 1; $i <= $pagecount; $i++)
951
-			{
952
-				$tplidx = $pdf->importPage($i);
953
-				$s = $pdf->getTemplatesize($tplidx);
954
-				$pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
955
-				$pdf->useTemplate($tplidx);
956
-			}
957
-		}
958
-
959
-		// Create output dir if not exists
960
-		dol_mkdir($diroutputmassaction);
961
-
962
-		// Defined name of merged file
963
-		$filename=strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel)));
964
-		$filename=preg_replace('/\s/','_',$filename);
965
-
966
-		// Save merged file
967
-		if (in_array($objecttmp->element, array('facture', 'facture_fournisseur')) && $search_status == Facture::STATUS_VALIDATED)
968
-		{
969
-			if ($option=='late') $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late")));
970
-			else $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid")));
971
-		}
972
-		if ($year) $filename.='_'.$year;
973
-		if ($month) $filename.='_'.$month;
974
-		if ($pagecount)
975
-		{
976
-			$now=dol_now();
977
-			$file=$diroutputmassaction.'/'.$filename.'_'.dol_print_date($now,'dayhourlog').'.pdf';
978
-			$pdf->Output($file,'F');
979
-			if (! empty($conf->global->MAIN_UMASK))
980
-				@chmod($file, octdec($conf->global->MAIN_UMASK));
981
-
982
-			$langs->load("exports");
983
-			setEventMessages($langs->trans('FileSuccessfullyBuilt',$filename.'_'.dol_print_date($now,'dayhourlog')), null, 'mesgs');
984
-		}
985
-		else
986
-		{
987
-		setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors');
988
-		}
989
-	}
827
+    if (empty($diroutputmassaction))
828
+    {
829
+        dol_print_error(null, 'include of actions_massactions.inc.php is done but var $diroutputmassaction was not defined');
830
+        exit;
831
+    }
832
+
833
+    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
834
+    require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
835
+    require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
836
+
837
+    $objecttmp=new $objectclass($db);
838
+    $listofobjectid=array();
839
+    $listofobjectthirdparties=array();
840
+    $listofobjectref=array();
841
+    foreach($toselect as $toselectid)
842
+    {
843
+        $objecttmp=new $objectclass($db);	// must create new instance because instance is saved into $listofobjectref array for future use
844
+        $result=$objecttmp->fetch($toselectid);
845
+        if ($result > 0)
846
+        {
847
+            $listofobjectid[$toselectid]=$toselectid;
848
+            $thirdpartyid=$objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid;
849
+            $listofobjectthirdparties[$thirdpartyid]=$thirdpartyid;
850
+            $listofobjectref[$toselectid]=$objecttmp->ref;
851
+        }
852
+    }
853
+
854
+    $arrayofinclusion=array();
855
+    foreach($listofobjectref as $tmppdf) $arrayofinclusion[]='^'.preg_quote(dol_sanitizeFileName($tmppdf),'/').'\.pdf$';
856
+    foreach($listofobjectref as $tmppdf) $arrayofinclusion[]='^'.preg_quote(dol_sanitizeFileName($tmppdf),'/').'_[a-zA-Z0-9-_]+\.pdf$';	// To include PDF generated from ODX files
857
+    $listoffiles = dol_dir_list($uploaddir,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true);
858
+
859
+    // build list of files with full path
860
+    $files = array();
861
+    foreach($listofobjectref as $basename)
862
+    {
863
+        $basename = dol_sanitizeFileName($basename);
864
+        foreach($listoffiles as $filefound)
865
+        {
866
+            if (strstr($filefound["name"],$basename))
867
+            {
868
+                $files[] = $uploaddir.'/'.$basename.'/'.$filefound["name"];
869
+                break;
870
+            }
871
+        }
872
+    }
873
+
874
+    // Define output language (Here it is not used because we do only merging existing PDF)
875
+    $outputlangs = $langs;
876
+    $newlang='';
877
+    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
878
+    if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$objecttmp->thirdparty->default_lang;
879
+    if (! empty($newlang))
880
+    {
881
+        $outputlangs = new Translate("",$conf);
882
+        $outputlangs->setDefaultLang($newlang);
883
+    }
884
+
885
+    if (!empty($conf->global->USE_PDFTK_FOR_PDF_CONCAT))
886
+    {
887
+        // Create output dir if not exists
888
+        dol_mkdir($diroutputmassaction);
889
+
890
+        // Defined name of merged file
891
+        $filename=strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel)));
892
+        $filename=preg_replace('/\s/','_',$filename);
893
+
894
+        // Save merged file
895
+        if (in_array($objecttmp->element, array('facture', 'facture_fournisseur')) && $search_status == Facture::STATUS_VALIDATED)
896
+        {
897
+            if ($option=='late') $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late")));
898
+            else $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid")));
899
+        }
900
+        if ($year) $filename.='_'.$year;
901
+        if ($month) $filename.='_'.$month;
902
+
903
+        if (count($files)>0)
904
+        {
905
+            $now=dol_now();
906
+            $file=$diroutputmassaction.'/'.$filename.'_'.dol_print_date($now,'dayhourlog').'.pdf';
907
+
908
+            $input_files = '';
909
+            foreach($files as $f) {
910
+                $input_files.=' '.escapeshellarg($f);
911
+            }
912
+
913
+            $cmd = 'pdftk '.escapeshellarg($input_files).' cat output '.escapeshellarg($file);
914
+            exec($cmd);
915
+
916
+            if (! empty($conf->global->MAIN_UMASK))
917
+                @chmod($file, octdec($conf->global->MAIN_UMASK));
918
+
919
+            $langs->load("exports");
920
+            setEventMessages($langs->trans('FileSuccessfullyBuilt',$filename.'_'.dol_print_date($now,'dayhourlog')), null, 'mesgs');
921
+        }
922
+        else
923
+        {
924
+            setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors');
925
+        }
926
+    }
927
+    else {
928
+        // Create empty PDF
929
+        $formatarray=pdf_getFormat();
930
+        $page_largeur = $formatarray['width'];
931
+        $page_hauteur = $formatarray['height'];
932
+        $format = array($page_largeur,$page_hauteur);
933
+
934
+        $pdf=pdf_getInstance($format);
935
+
936
+        if (class_exists('TCPDF'))
937
+        {
938
+            $pdf->setPrintHeader(false);
939
+            $pdf->setPrintFooter(false);
940
+        }
941
+        $pdf->SetFont(pdf_getPDFFont($outputlangs));
942
+
943
+        if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
944
+
945
+        // Add all others
946
+        foreach($files as $file)
947
+        {
948
+            // Charge un document PDF depuis un fichier.
949
+            $pagecount = $pdf->setSourceFile($file);
950
+            for ($i = 1; $i <= $pagecount; $i++)
951
+            {
952
+                $tplidx = $pdf->importPage($i);
953
+                $s = $pdf->getTemplatesize($tplidx);
954
+                $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
955
+                $pdf->useTemplate($tplidx);
956
+            }
957
+        }
958
+
959
+        // Create output dir if not exists
960
+        dol_mkdir($diroutputmassaction);
961
+
962
+        // Defined name of merged file
963
+        $filename=strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel)));
964
+        $filename=preg_replace('/\s/','_',$filename);
965
+
966
+        // Save merged file
967
+        if (in_array($objecttmp->element, array('facture', 'facture_fournisseur')) && $search_status == Facture::STATUS_VALIDATED)
968
+        {
969
+            if ($option=='late') $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late")));
970
+            else $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid")));
971
+        }
972
+        if ($year) $filename.='_'.$year;
973
+        if ($month) $filename.='_'.$month;
974
+        if ($pagecount)
975
+        {
976
+            $now=dol_now();
977
+            $file=$diroutputmassaction.'/'.$filename.'_'.dol_print_date($now,'dayhourlog').'.pdf';
978
+            $pdf->Output($file,'F');
979
+            if (! empty($conf->global->MAIN_UMASK))
980
+                @chmod($file, octdec($conf->global->MAIN_UMASK));
981
+
982
+            $langs->load("exports");
983
+            setEventMessages($langs->trans('FileSuccessfullyBuilt',$filename.'_'.dol_print_date($now,'dayhourlog')), null, 'mesgs');
984
+        }
985
+        else
986
+        {
987
+        setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors');
988
+        }
989
+    }
990 990
 }
991 991
 
992 992
 // Remove a file from massaction area
993 993
 if ($action == 'remove_file')
994 994
 {
995
-	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
996
-
997
-	$langs->load("other");
998
-	$upload_dir = $diroutputmassaction;
999
-	$file = $upload_dir . '/' . GETPOST('file');
1000
-	$ret=dol_delete_file($file);
1001
-	if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
1002
-	else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
1003
-	$action='';
995
+    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
996
+
997
+    $langs->load("other");
998
+    $upload_dir = $diroutputmassaction;
999
+    $file = $upload_dir . '/' . GETPOST('file');
1000
+    $ret=dol_delete_file($file);
1001
+    if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
1002
+    else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
1003
+    $action='';
1004 1004
 }
1005 1005
 
1006 1006
 // Validate records
1007 1007
 if (! $error && $massaction == 'validate' && $permtocreate)
1008 1008
 {
1009
-	$objecttmp=new $objectclass($db);
1010
-
1011
-	if ($objecttmp->element == 'invoice' && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
1012
-	{
1013
-		$langs->load("errors");
1014
-		setEventMessages($langs->trans('ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'), null, 'errors');
1015
-		$error++;
1016
-	}
1017
-	if ($objecttmp->element == 'invoice_supplier' && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL))
1018
-	{
1019
-		$langs->load("errors");
1020
-		setEventMessages($langs->trans('ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'), null, 'errors');
1021
-		$error++;
1022
-	}
1023
-	if (! $error)
1024
-	{
1025
-		$db->begin();
1026
-
1027
-		$nbok = 0;
1028
-		foreach($toselect as $toselectid)
1029
-		{
1030
-			$result=$objecttmp->fetch($toselectid);
1031
-			if ($result > 0)
1032
-			{
1033
-				//if (in_array($objecttmp->element, array('societe','member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1);
1034
-				//else
1035
-				$result = $objecttmp->validate($user);
1036
-				if ($result == 0)
1037
-				{
1038
-					$langs->load("errors");
1039
-					setEventMessages($langs->trans("ErrorObjectMustHaveStatusDraftToBeValidated", $objecttmp->ref), null, 'errors');
1040
-					$error++;
1041
-					break;
1042
-				}
1043
-				elseif ($result < 0)
1044
-				{
1045
-					setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
1046
-					$error++;
1047
-					break;
1048
-				}
1049
-				else $nbok++;
1050
-			}
1051
-			else
1052
-			{
1053
-				setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
1054
-				$error++;
1055
-				break;
1056
-			}
1057
-		}
1058
-
1059
-		if (! $error)
1060
-		{
1061
-			if ($nbok > 1) setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
1062
-			else setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
1063
-			$db->commit();
1064
-		}
1065
-		else
1066
-		{
1067
-			$db->rollback();
1068
-		}
1069
-		//var_dump($listofobjectthirdparties);exit;
1070
-	}
1009
+    $objecttmp=new $objectclass($db);
1010
+
1011
+    if ($objecttmp->element == 'invoice' && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
1012
+    {
1013
+        $langs->load("errors");
1014
+        setEventMessages($langs->trans('ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'), null, 'errors');
1015
+        $error++;
1016
+    }
1017
+    if ($objecttmp->element == 'invoice_supplier' && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL))
1018
+    {
1019
+        $langs->load("errors");
1020
+        setEventMessages($langs->trans('ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'), null, 'errors');
1021
+        $error++;
1022
+    }
1023
+    if (! $error)
1024
+    {
1025
+        $db->begin();
1026
+
1027
+        $nbok = 0;
1028
+        foreach($toselect as $toselectid)
1029
+        {
1030
+            $result=$objecttmp->fetch($toselectid);
1031
+            if ($result > 0)
1032
+            {
1033
+                //if (in_array($objecttmp->element, array('societe','member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1);
1034
+                //else
1035
+                $result = $objecttmp->validate($user);
1036
+                if ($result == 0)
1037
+                {
1038
+                    $langs->load("errors");
1039
+                    setEventMessages($langs->trans("ErrorObjectMustHaveStatusDraftToBeValidated", $objecttmp->ref), null, 'errors');
1040
+                    $error++;
1041
+                    break;
1042
+                }
1043
+                elseif ($result < 0)
1044
+                {
1045
+                    setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
1046
+                    $error++;
1047
+                    break;
1048
+                }
1049
+                else $nbok++;
1050
+            }
1051
+            else
1052
+            {
1053
+                setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
1054
+                $error++;
1055
+                break;
1056
+            }
1057
+        }
1058
+
1059
+        if (! $error)
1060
+        {
1061
+            if ($nbok > 1) setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
1062
+            else setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
1063
+            $db->commit();
1064
+        }
1065
+        else
1066
+        {
1067
+            $db->rollback();
1068
+        }
1069
+        //var_dump($listofobjectthirdparties);exit;
1070
+    }
1071 1071
 }
1072 1072
 // Closed records
1073 1073
 if (!$error && $massaction == 'closed' && $objectclass == "Propal" && $permtoclose) {
@@ -1107,127 +1107,127 @@  discard block
 block discarded – undo
1107 1107
 // Delete record from mass action (massaction = 'delete' for direct delete, action/confirm='delete'/'yes' with a confirmation step before)
1108 1108
 if (! $error && ($massaction == 'delete' || ($action == 'delete' && $confirm == 'yes')) && $permtodelete)
1109 1109
 {
1110
-	$db->begin();
1111
-
1112
-	$objecttmp=new $objectclass($db);
1113
-	$nbok = 0;
1114
-	foreach($toselect as $toselectid)
1115
-	{
1116
-		$result=$objecttmp->fetch($toselectid);
1117
-		if ($result > 0)
1118
-		{
1119
-			// Refuse deletion for some objects/status
1120
-			if ($objectclass == 'Facture' && empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $objecttmp->status != Facture::STATUS_DRAFT)
1121
-			{
1122
-				$langs->load("errors");
1123
-				$nbignored++;
1124
-				$resaction.='<div class="error">'.$langs->trans('ErrorOnlyDraftStatusCanBeDeletedInMassAction',$objecttmp->ref).'</div><br>';
1125
-				continue;
1126
-			}
1127
-
1128
-			if ($objectclass == "Task" && $objecttmp->hasChildren() > 0)
1129
-			{
1130
-				$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET fk_task_parent = 0 WHERE fk_task_parent = ".$objecttmp->id;
1131
-				$res = $db->query($sql);
1132
-
1133
-				if (!$res)
1134
-				{
1135
-					setEventMessage('ErrorRecordParentingNotModified', 'errors');
1136
-					$error++;
1137
-				}
1138
-			}
1139
-
1140
-			if (in_array($objecttmp->element, array('societe', 'member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1);
1141
-			else $result = $objecttmp->delete($user);
1142
-
1143
-			if ($result <= 0)
1144
-			{
1145
-			    setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
1146
-			    $error++;
1147
-			    break;
1148
-			}
1149
-			else $nbok++;
1150
-		}
1151
-		else
1152
-		{
1153
-			setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
1154
-			$error++;
1155
-			break;
1156
-		}
1157
-	}
1158
-
1159
-	if (! $error)
1160
-	{
1161
-		if ($nbok > 1) setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
1162
-		else setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
1163
-		$db->commit();
1164
-	}
1165
-	else
1166
-	{
1167
-		$db->rollback();
1168
-	}
1169
-	//var_dump($listofobjectthirdparties);exit;
1110
+    $db->begin();
1111
+
1112
+    $objecttmp=new $objectclass($db);
1113
+    $nbok = 0;
1114
+    foreach($toselect as $toselectid)
1115
+    {
1116
+        $result=$objecttmp->fetch($toselectid);
1117
+        if ($result > 0)
1118
+        {
1119
+            // Refuse deletion for some objects/status
1120
+            if ($objectclass == 'Facture' && empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $objecttmp->status != Facture::STATUS_DRAFT)
1121
+            {
1122
+                $langs->load("errors");
1123
+                $nbignored++;
1124
+                $resaction.='<div class="error">'.$langs->trans('ErrorOnlyDraftStatusCanBeDeletedInMassAction',$objecttmp->ref).'</div><br>';
1125
+                continue;
1126
+            }
1127
+
1128
+            if ($objectclass == "Task" && $objecttmp->hasChildren() > 0)
1129
+            {
1130
+                $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET fk_task_parent = 0 WHERE fk_task_parent = ".$objecttmp->id;
1131
+                $res = $db->query($sql);
1132
+
1133
+                if (!$res)
1134
+                {
1135
+                    setEventMessage('ErrorRecordParentingNotModified', 'errors');
1136
+                    $error++;
1137
+                }
1138
+            }
1139
+
1140
+            if (in_array($objecttmp->element, array('societe', 'member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1);
1141
+            else $result = $objecttmp->delete($user);
1142
+
1143
+            if ($result <= 0)
1144
+            {
1145
+                setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
1146
+                $error++;
1147
+                break;
1148
+            }
1149
+            else $nbok++;
1150
+        }
1151
+        else
1152
+        {
1153
+            setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
1154
+            $error++;
1155
+            break;
1156
+        }
1157
+    }
1158
+
1159
+    if (! $error)
1160
+    {
1161
+        if ($nbok > 1) setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
1162
+        else setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
1163
+        $db->commit();
1164
+    }
1165
+    else
1166
+    {
1167
+        $db->rollback();
1168
+    }
1169
+    //var_dump($listofobjectthirdparties);exit;
1170 1170
 }
1171 1171
 
1172 1172
 // Generate document foreach object according to model linked to object
1173 1173
 // @TODO : propose model selection
1174 1174
 if (! $error && $massaction == 'generate_doc' && $permtoread)
1175 1175
 {
1176
-	$db->begin();
1177
-
1178
-	$objecttmp=new $objectclass($db);
1179
-	$nbok = 0;
1180
-	foreach($toselect as $toselectid)
1181
-	{
1182
-		$result=$objecttmp->fetch($toselectid);
1183
-		if ($result > 0)
1184
-		{
1185
-			$outputlangs = $langs;
1186
-			$newlang='';
1176
+    $db->begin();
1177
+
1178
+    $objecttmp=new $objectclass($db);
1179
+    $nbok = 0;
1180
+    foreach($toselect as $toselectid)
1181
+    {
1182
+        $result=$objecttmp->fetch($toselectid);
1183
+        if ($result > 0)
1184
+        {
1185
+            $outputlangs = $langs;
1186
+            $newlang='';
1187 1187
 	
1188
-			if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
1189
-			if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) $newlang=$objecttmp->thirdparty->default_lang;  // for proposal, order, invoice, ...
1190
-			if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->default_lang)) $newlang=$objecttmp->default_lang;                  // for thirdparty
1191
-			if (! empty($newlang))
1192
-			{
1193
-				$outputlangs = new Translate("",$conf);
1194
-				$outputlangs->setDefaultLang($newlang);
1195
-			}
1188
+            if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
1189
+            if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) $newlang=$objecttmp->thirdparty->default_lang;  // for proposal, order, invoice, ...
1190
+            if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->default_lang)) $newlang=$objecttmp->default_lang;                  // for thirdparty
1191
+            if (! empty($newlang))
1192
+            {
1193
+                $outputlangs = new Translate("",$conf);
1194
+                $outputlangs->setDefaultLang($newlang);
1195
+            }
1196 1196
 	
1197
-			// To be sure vars is defined
1198
-			if (empty($hidedetails)) $hidedetails=0;
1199
-			if (empty($hidedesc)) $hidedesc=0;
1200
-			if (empty($hideref)) $hideref=0;
1201
-			if (empty($moreparams)) $moreparams=null;
1197
+            // To be sure vars is defined
1198
+            if (empty($hidedetails)) $hidedetails=0;
1199
+            if (empty($hidedesc)) $hidedesc=0;
1200
+            if (empty($hideref)) $hideref=0;
1201
+            if (empty($moreparams)) $moreparams=null;
1202 1202
 			
1203
-			$result= $objecttmp->generateDocument($objecttmp->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1204
-
1205
-			if ($result <= 0)
1206
-			{
1207
-				setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
1208
-				$error++;
1209
-				break;
1210
-			}
1211
-			else $nbok++;
1212
-		}
1213
-		else
1214
-		{
1215
-			setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
1216
-			$error++;
1217
-			break;
1218
-		}
1219
-	}
1220
-
1221
-	if (! $error)
1222
-	{
1223
-		if ($nbok > 1) setEventMessages($langs->trans("RecordsGenerated", $nbok), null, 'mesgs');
1224
-		else setEventMessages($langs->trans("RecordGenerated", $nbok), null, 'mesgs');
1225
-		$db->commit();
1226
-	}
1227
-	else
1228
-	{
1229
-		$db->rollback();
1230
-	}
1203
+            $result= $objecttmp->generateDocument($objecttmp->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1204
+
1205
+            if ($result <= 0)
1206
+            {
1207
+                setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
1208
+                $error++;
1209
+                break;
1210
+            }
1211
+            else $nbok++;
1212
+        }
1213
+        else
1214
+        {
1215
+            setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
1216
+            $error++;
1217
+            break;
1218
+        }
1219
+    }
1220
+
1221
+    if (! $error)
1222
+    {
1223
+        if ($nbok > 1) setEventMessages($langs->trans("RecordsGenerated", $nbok), null, 'mesgs');
1224
+        else setEventMessages($langs->trans("RecordGenerated", $nbok), null, 'mesgs');
1225
+        $db->commit();
1226
+    }
1227
+    else
1228
+    {
1229
+        $db->rollback();
1230
+    }
1231 1231
 }
1232 1232
 
1233 1233
 $parameters['toselect']=$toselect;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/actions_linkedfiles.inc.php 1 patch
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -29,41 +29,41 @@  discard block
 block discarded – undo
29 29
 // Submit file/link
30 30
 if (GETPOST('sendit','alpha') && ! empty($conf->global->MAIN_UPLOAD_DOC))
31 31
 {
32
-	if (! empty($_FILES))
33
-	{
34
-		if (is_array($_FILES['userfile']['tmp_name'])) $userfiles=$_FILES['userfile']['tmp_name'];
35
-		else $userfiles=array($_FILES['userfile']['tmp_name']);
32
+    if (! empty($_FILES))
33
+    {
34
+        if (is_array($_FILES['userfile']['tmp_name'])) $userfiles=$_FILES['userfile']['tmp_name'];
35
+        else $userfiles=array($_FILES['userfile']['tmp_name']);
36 36
 
37
-		foreach($userfiles as $key => $userfile)
38
-		{
39
-			if (empty($_FILES['userfile']['tmp_name'][$key]))
40
-			{
41
-				$error++;
42
-				if ($_FILES['userfile']['error'][$key] == 1 || $_FILES['userfile']['error'][$key] == 2){
43
-					setEventMessages($langs->trans('ErrorFileSizeTooLarge'), null, 'errors');
44
-				}
45
-				else {
46
-					setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
47
-				}
48
-			}
49
-		}
37
+        foreach($userfiles as $key => $userfile)
38
+        {
39
+            if (empty($_FILES['userfile']['tmp_name'][$key]))
40
+            {
41
+                $error++;
42
+                if ($_FILES['userfile']['error'][$key] == 1 || $_FILES['userfile']['error'][$key] == 2){
43
+                    setEventMessages($langs->trans('ErrorFileSizeTooLarge'), null, 'errors');
44
+                }
45
+                else {
46
+                    setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
47
+                }
48
+            }
49
+        }
50 50
 
51
-		if (! $error)
52
-		{
53
-			// Define if we have to generate thumbs or not
54
-			$generatethumbs = 1;
55
-			if (GETPOST('section_dir')) $generatethumbs=0;
51
+        if (! $error)
52
+        {
53
+            // Define if we have to generate thumbs or not
54
+            $generatethumbs = 1;
55
+            if (GETPOST('section_dir')) $generatethumbs=0;
56 56
 
57
-			if (! empty($upload_dirold) && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
58
-			{
59
-				$result = dol_add_file_process($upload_dirold, 0, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs);
60
-			}
61
-			elseif (! empty($upload_dir))
62
-			{
63
-				$result = dol_add_file_process($upload_dir, 0, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs);
64
-			}
65
-		}
66
-	}
57
+            if (! empty($upload_dirold) && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
58
+            {
59
+                $result = dol_add_file_process($upload_dirold, 0, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs);
60
+            }
61
+            elseif (! empty($upload_dir))
62
+            {
63
+                $result = dol_add_file_process($upload_dir, 0, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs);
64
+            }
65
+        }
66
+    }
67 67
 }
68 68
 elseif (GETPOST('linkit','none') && ! empty($conf->global->MAIN_UPLOAD_DOC))
69 69
 {
@@ -84,39 +84,39 @@  discard block
 block discarded – undo
84 84
         $urlfile = GETPOST('urlfile', 'alpha', 0, null, null, 1);				// Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
85 85
         if (GETPOST('section', 'alpha')) 	// For a delete from the ECM module, upload_dir is ECM root dir and urlfile contains relative path from upload_dir
86 86
         {
87
-        	$file = $upload_dir . (preg_match('/\/$/', $upload_dir) ? '' : '/') . $urlfile;
87
+            $file = $upload_dir . (preg_match('/\/$/', $upload_dir) ? '' : '/') . $urlfile;
88 88
         }
89 89
         else								// For a delete from the file manager into another module, or from documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile.
90
-		{
91
-       		$urlfile=basename($urlfile);
92
-       		$file = $upload_dir . (preg_match('/\/$/', $upload_dir) ? '' : '/') . $urlfile;
93
-			if (! empty($upload_dirold)) $fileold = $upload_dirold . "/" . $urlfile;
94
-		}
90
+        {
91
+                $urlfile=basename($urlfile);
92
+                $file = $upload_dir . (preg_match('/\/$/', $upload_dir) ? '' : '/') . $urlfile;
93
+            if (! empty($upload_dirold)) $fileold = $upload_dirold . "/" . $urlfile;
94
+        }
95 95
         $linkid = GETPOST('linkid', 'int');
96 96
 
97 97
         if ($urlfile)		// delete of a file
98 98
         {
99
-	        $dir = dirname($file).'/';		// Chemin du dossier contenant l'image d'origine
100
-	        $dirthumb = $dir.'/thumbs/';	// Chemin du dossier contenant la vignette (if file is an image)
99
+            $dir = dirname($file).'/';		// Chemin du dossier contenant l'image d'origine
100
+            $dirthumb = $dir.'/thumbs/';	// Chemin du dossier contenant la vignette (if file is an image)
101 101
 
102
-	        $ret = dol_delete_file($file, 0, 0, 0, (is_object($object)?$object:null));
102
+            $ret = dol_delete_file($file, 0, 0, 0, (is_object($object)?$object:null));
103 103
             if (! empty($fileold)) dol_delete_file($fileold, 0, 0, 0, (is_object($object)?$object:null));     // Delete file using old path
104 104
 
105
-	        // Si elle existe, on efface la vignette
106
-	        if (preg_match('/(\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff)$/i',$file,$regs))
107
-	        {
108
-		        $photo_vignette=basename(preg_replace('/'.$regs[0].'/i','',$file).'_small'.$regs[0]);
109
-		        if (file_exists(dol_osencode($dirthumb.$photo_vignette)))
110
-		        {
111
-			        dol_delete_file($dirthumb.$photo_vignette);
112
-		        }
105
+            // Si elle existe, on efface la vignette
106
+            if (preg_match('/(\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff)$/i',$file,$regs))
107
+            {
108
+                $photo_vignette=basename(preg_replace('/'.$regs[0].'/i','',$file).'_small'.$regs[0]);
109
+                if (file_exists(dol_osencode($dirthumb.$photo_vignette)))
110
+                {
111
+                    dol_delete_file($dirthumb.$photo_vignette);
112
+                }
113 113
 
114
-		        $photo_vignette=basename(preg_replace('/'.$regs[0].'/i','',$file).'_mini'.$regs[0]);
115
-		        if (file_exists(dol_osencode($dirthumb.$photo_vignette)))
116
-		        {
117
-			        dol_delete_file($dirthumb.$photo_vignette);
118
-		        }
119
-	        }
114
+                $photo_vignette=basename(preg_replace('/'.$regs[0].'/i','',$file).'_mini'.$regs[0]);
115
+                if (file_exists(dol_osencode($dirthumb.$photo_vignette)))
116
+                {
117
+                    dol_delete_file($dirthumb.$photo_vignette);
118
+                }
119
+            }
120 120
 
121 121
             if ($ret) setEventMessages($langs->trans("FileWasRemoved", $urlfile), null, 'mesgs');
122 122
             else setEventMessages($langs->trans("ErrorFailToDeleteFile", $urlfile), null, 'errors');
@@ -143,16 +143,16 @@  discard block
 block discarded – undo
143 143
 
144 144
         if (is_object($object) && $object->id > 0)
145 145
         {
146
-        	if ($backtopage)
147
-        	{
148
-        		header('Location: ' . $backtopage);
149
-        		exit;
150
-        	}
151
-        	else
152
-        	{
153
-        		header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(GETPOST('section_dir','alpha')?'&section_dir='.urlencode(GETPOST('section_dir','alpha')):'').(!empty($withproject)?'&withproject=1':''));
154
-        		exit;
155
-        	}
146
+            if ($backtopage)
147
+            {
148
+                header('Location: ' . $backtopage);
149
+                exit;
150
+            }
151
+            else
152
+            {
153
+                header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(GETPOST('section_dir','alpha')?'&section_dir='.urlencode(GETPOST('section_dir','alpha')):'').(!empty($withproject)?'&withproject=1':''));
154
+                exit;
155
+            }
156 156
         }
157 157
 }
158 158
 elseif ($action == 'confirm_updateline' && GETPOST('save','alpha') && GETPOST('link', 'alpha'))
@@ -183,101 +183,101 @@  discard block
 block discarded – undo
183 183
 }
184 184
 elseif ($action == 'renamefile' && GETPOST('renamefilesave','alpha'))
185 185
 {
186
-	// For documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile.
187
-	if (! empty($upload_dir))
188
-	{
189
-		$filenamefrom=dol_sanitizeFileName(GETPOST('renamefilefrom','alpha'), '_', 0);	// Do not remove accents
190
-		$filenameto=dol_sanitizeFileName(GETPOST('renamefileto','alpha'), '_', 0);		// Do not remove accents
186
+    // For documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile.
187
+    if (! empty($upload_dir))
188
+    {
189
+        $filenamefrom=dol_sanitizeFileName(GETPOST('renamefilefrom','alpha'), '_', 0);	// Do not remove accents
190
+        $filenameto=dol_sanitizeFileName(GETPOST('renamefileto','alpha'), '_', 0);		// Do not remove accents
191 191
 
192 192
         if ($filenamefrom != $filenameto)
193 193
         {
194
-	        // Security:
195
-	        // Disallow file with some extensions. We rename them.
196
-	        // Because if we put the documents directory into a directory inside web root (very bad), this allows to execute on demand arbitrary code.
197
-	        if (preg_match('/(\.htm|\.html|\.php|\.pl|\.cgi)$/i',$filenameto) && empty($conf->global->MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED))
198
-	        {
199
-	            $filenameto.= '.noexe';
200
-	        }
194
+            // Security:
195
+            // Disallow file with some extensions. We rename them.
196
+            // Because if we put the documents directory into a directory inside web root (very bad), this allows to execute on demand arbitrary code.
197
+            if (preg_match('/(\.htm|\.html|\.php|\.pl|\.cgi)$/i',$filenameto) && empty($conf->global->MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED))
198
+            {
199
+                $filenameto.= '.noexe';
200
+            }
201 201
 
202
-	        if ($filenamefrom && $filenameto)
203
-	        {
204
-	            $srcpath = $upload_dir.'/'.$filenamefrom;
205
-	            $destpath = $upload_dir.'/'.$filenameto;
202
+            if ($filenamefrom && $filenameto)
203
+            {
204
+                $srcpath = $upload_dir.'/'.$filenamefrom;
205
+                $destpath = $upload_dir.'/'.$filenameto;
206 206
 
207
-	            $reshook=$hookmanager->initHooks(array('actionlinkedfiles'));
208
-	            $parameters=array('filenamefrom' => $filenamefrom, 'filenameto' => $filenameto, 'upload_dir' => $upload_dir);
209
-	            $reshook=$hookmanager->executeHooks('renameUploadedFile', $parameters, $object);
207
+                $reshook=$hookmanager->initHooks(array('actionlinkedfiles'));
208
+                $parameters=array('filenamefrom' => $filenamefrom, 'filenameto' => $filenameto, 'upload_dir' => $upload_dir);
209
+                $reshook=$hookmanager->executeHooks('renameUploadedFile', $parameters, $object);
210 210
 
211
-	            if (empty($reshook))
212
-	            {
213
-	            	if (! file_exists($destpath))
214
-	            	{
215
-	            		$result = dol_move($srcpath, $destpath);
216
-			            if ($result)
217
-			            {
218
-			            	// Define if we have to generate thumbs or not
219
-			            	$generatethumbs = 1;
220
-			            	// When we rename a file from the file manager in ecm, we must not regenerate thumbs (not a problem, we do pass here)
221
-			            	// When we rename a file from the website module, we must not regenerate thumbs (module = medias in such a case)
222
-			            	// but when we rename from a tab "Documents", we must regenerate thumbs
223
-			            	if (GETPOST('modulepart') == 'medias') $generatethumbs=0;
211
+                if (empty($reshook))
212
+                {
213
+                    if (! file_exists($destpath))
214
+                    {
215
+                        $result = dol_move($srcpath, $destpath);
216
+                        if ($result)
217
+                        {
218
+                            // Define if we have to generate thumbs or not
219
+                            $generatethumbs = 1;
220
+                            // When we rename a file from the file manager in ecm, we must not regenerate thumbs (not a problem, we do pass here)
221
+                            // When we rename a file from the website module, we must not regenerate thumbs (module = medias in such a case)
222
+                            // but when we rename from a tab "Documents", we must regenerate thumbs
223
+                            if (GETPOST('modulepart') == 'medias') $generatethumbs=0;
224 224
 
225
-			            	if ($generatethumbs)
226
-			            	{
227
-			            		if ($object->id)
228
-				            	{
229
-				                	$object->addThumbs($destpath);
230
-				            	}
225
+                            if ($generatethumbs)
226
+                            {
227
+                                if ($object->id)
228
+                                {
229
+                                    $object->addThumbs($destpath);
230
+                                }
231 231
 
232
-				                // TODO Add revert function of addThumbs to remove thumbs with old name
233
-				                //$object->delThumbs($srcpath);
234
-			            	}
232
+                                // TODO Add revert function of addThumbs to remove thumbs with old name
233
+                                //$object->delThumbs($srcpath);
234
+                            }
235 235
 
236
-			                setEventMessages($langs->trans("FileRenamed"), null);
237
-			            }
238
-			            else
239
-			            {
240
-			                $langs->load("errors"); // key must be loaded because we can't rely on loading during output, we need var substitution to be done now.
241
-			                setEventMessages($langs->trans("ErrorFailToRenameFile", $filenamefrom, $filenameto), null, 'errors');
242
-			            }
243
-	            	}
244
-	            	else
245
-	            	{
246
-	            		$langs->load("errors"); // key must be loaded because we can't rely on loading during output, we need var substitution to be done now.
247
-	            		setEventMessages($langs->trans("ErrorDestinationAlreadyExists", $filenameto), null, 'errors');
248
-	            	}
249
-	            }
250
-	        }
236
+                            setEventMessages($langs->trans("FileRenamed"), null);
237
+                        }
238
+                        else
239
+                        {
240
+                            $langs->load("errors"); // key must be loaded because we can't rely on loading during output, we need var substitution to be done now.
241
+                            setEventMessages($langs->trans("ErrorFailToRenameFile", $filenamefrom, $filenameto), null, 'errors');
242
+                        }
243
+                    }
244
+                    else
245
+                    {
246
+                        $langs->load("errors"); // key must be loaded because we can't rely on loading during output, we need var substitution to be done now.
247
+                        setEventMessages($langs->trans("ErrorDestinationAlreadyExists", $filenameto), null, 'errors');
248
+                    }
249
+                }
250
+            }
251 251
         }
252 252
     }
253 253
 
254 254
     // Update properties in ECM table
255 255
     if (GETPOST('ecmfileid', 'int') > 0)
256 256
     {
257
-    	$shareenabled = GETPOST('shareenabled', 'alpha');
257
+        $shareenabled = GETPOST('shareenabled', 'alpha');
258 258
 
259
-    	include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
260
-	    $ecmfile=new EcmFiles($db);
261
-	    $result = $ecmfile->fetch(GETPOST('ecmfileid', 'int'));
262
-	    if ($result > 0)
263
-	    {
264
-	    	if ($shareenabled)
265
-		    {
266
-		    	if (empty($ecmfile->share))
267
-		    	{
268
-		    		require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
269
-		    		$ecmfile->share = getRandomPassword(true);
270
-		    	}
271
-		    }
272
-		    else
273
-		    {
274
-		    	$ecmfile->share = '';
275
-		    }
276
-		    $result = $ecmfile->update($user);
277
-		    if ($result < 0)
278
-		    {
279
-		    	setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
280
-		    }
281
-	    }
259
+        include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
260
+        $ecmfile=new EcmFiles($db);
261
+        $result = $ecmfile->fetch(GETPOST('ecmfileid', 'int'));
262
+        if ($result > 0)
263
+        {
264
+            if ($shareenabled)
265
+            {
266
+                if (empty($ecmfile->share))
267
+                {
268
+                    require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
269
+                    $ecmfile->share = getRandomPassword(true);
270
+                }
271
+            }
272
+            else
273
+            {
274
+                $ecmfile->share = '';
275
+            }
276
+            $result = $ecmfile->update($user);
277
+            if ($result < 0)
278
+            {
279
+                setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
280
+            }
281
+        }
282 282
     }
283 283
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/modFTP.class.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -33,96 +33,96 @@
 block discarded – undo
33 33
 class modFTP extends DolibarrModules
34 34
 {
35 35
 
36
-   /**
37
-	 *   Constructor. Define names, constants, directories, boxes, permissions
38
-	 *
39
-	 *   @param      DoliDB		$db      Database handler
40
-    */
41
-	function __construct($db)
42
-	{
43
-		$this->db = $db;
44
-
45
-		// Id for module (must be unique).
46
-		// Use here a free id.
47
-		$this->numero = 2800;
48
-
49
-		// Family can be 'crm','financial','hr','projects','product','ecm','technic','other'
50
-		// It is used to sort modules in module setup page
51
-		$this->family = "interface";
52
-		// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
53
-		$this->name = preg_replace('/^mod/i','',get_class($this));
54
-		// Module description used if translation string 'ModuleXXXDesc' not found (XXX is id value)
55
-		$this->description = "FTP Client";
56
-		// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
57
-		$this->version = 'dolibarr';
58
-		// Key used in llx_const table to save module status enabled/disabled (XXX is id value)
59
-		$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
60
-		// Name of png file (without png) used for this module
61
-		$this->picto='dir';
62
-
63
-		// Data directories to create when module is enabled
64
-		$this->dirs = array("/ftp/temp");
65
-
66
-		// Langs file within the module
67
-		$this->langfiles = array("ftp");
68
-
69
-		// Config pages. Put here list of php page names stored in admmin directory used to setup module
70
-		$this->config_page_url = array('ftpclient.php@ftp');
71
-
72
-		// Dependencies
73
-		$this->depends = array();		// List of modules id that must be enabled if this module is enabled
74
-		$this->requiredby = array();	// List of modules id to disable if this one is disabled
75
-
76
-		// Constants
77
-		$this->const = array(
78
-		    1=>array('FTP_CONNECT_WITH_SSL','chaine','0','Use FTPS for FTP module', 1, 'current', 1),
79
-		    2=>array('FTP_CONNECT_WITH_SFTP','chaine','0','Use SFTP for FTP module', 1, 'current', 1)
80
-		);			// List of parameters
81
-
82
-		// Boxes
83
-		$this->boxes = array();			// List of boxes
84
-		$r=0;
85
-
86
-		// Add here list of php file(s) stored in core/boxes that contains class to show a box.
87
-		// Example:
36
+    /**
37
+     *   Constructor. Define names, constants, directories, boxes, permissions
38
+     *
39
+     *   @param      DoliDB		$db      Database handler
40
+     */
41
+    function __construct($db)
42
+    {
43
+        $this->db = $db;
44
+
45
+        // Id for module (must be unique).
46
+        // Use here a free id.
47
+        $this->numero = 2800;
48
+
49
+        // Family can be 'crm','financial','hr','projects','product','ecm','technic','other'
50
+        // It is used to sort modules in module setup page
51
+        $this->family = "interface";
52
+        // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
53
+        $this->name = preg_replace('/^mod/i','',get_class($this));
54
+        // Module description used if translation string 'ModuleXXXDesc' not found (XXX is id value)
55
+        $this->description = "FTP Client";
56
+        // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
57
+        $this->version = 'dolibarr';
58
+        // Key used in llx_const table to save module status enabled/disabled (XXX is id value)
59
+        $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
60
+        // Name of png file (without png) used for this module
61
+        $this->picto='dir';
62
+
63
+        // Data directories to create when module is enabled
64
+        $this->dirs = array("/ftp/temp");
65
+
66
+        // Langs file within the module
67
+        $this->langfiles = array("ftp");
68
+
69
+        // Config pages. Put here list of php page names stored in admmin directory used to setup module
70
+        $this->config_page_url = array('ftpclient.php@ftp');
71
+
72
+        // Dependencies
73
+        $this->depends = array();		// List of modules id that must be enabled if this module is enabled
74
+        $this->requiredby = array();	// List of modules id to disable if this one is disabled
75
+
76
+        // Constants
77
+        $this->const = array(
78
+            1=>array('FTP_CONNECT_WITH_SSL','chaine','0','Use FTPS for FTP module', 1, 'current', 1),
79
+            2=>array('FTP_CONNECT_WITH_SFTP','chaine','0','Use SFTP for FTP module', 1, 'current', 1)
80
+        );			// List of parameters
81
+
82
+        // Boxes
83
+        $this->boxes = array();			// List of boxes
84
+        $r=0;
85
+
86
+        // Add here list of php file(s) stored in core/boxes that contains class to show a box.
87
+        // Example:
88 88
         //$this->boxes[$r][1] = "myboxa.php";
89
-    	//$r++;
89
+        //$r++;
90 90
         //$this->boxes[$r][1] = "myboxb.php";
91
-    	//$r++;
92
-
93
-		// Permissions
94
-		$this->rights_class = 'ftp';	// Permission key
95
-		$this->rights = array();		// Permission array used by this module
96
-
97
-		$r++;
98
-		$this->rights[$r][0] = 2801;
99
-		$this->rights[$r][1] = 'Use FTP client in read mode (browse and download only)';
100
-		$this->rights[$r][2] = 'r';
101
-		$this->rights[$r][3] = 0;
102
-		$this->rights[$r][4] = 'read';
103
-
104
-		$r++;
105
-		$this->rights[$r][0] = 2802;
106
-		$this->rights[$r][1] = 'Use FTP client in write mode (delete or upload files)';
107
-		$this->rights[$r][2] = 'w';
108
-		$this->rights[$r][3] = 0;
109
-		$this->rights[$r][4] = 'write';
110
-
111
-
112
-		// Menus
113
-		//-------
114
-		$this->menu[$r]=array('fk_menu'=>0,
115
-							  'type'=>'top',
116
-							  'titre'=>'FTP',
117
-							  'mainmenu'=>'ftp',
118
-							  'url'=>'/ftp/index.php',
119
-							  'langs'=>'ftp',
120
-							  'position'=>100,
121
-                              'enabled'=>'$conf->ftp->enabled',
122
-		                      'perms'=>'$user->rights->ftp->read || $user->rights->ftp->write || $user->rights->ftp->setup',
123
-							  'target'=>'',
124
-							  'user'=>2);			// 0=Menu for internal users, 1=external users, 2=both
125
-		$r++;
126
-	}
91
+        //$r++;
92
+
93
+        // Permissions
94
+        $this->rights_class = 'ftp';	// Permission key
95
+        $this->rights = array();		// Permission array used by this module
96
+
97
+        $r++;
98
+        $this->rights[$r][0] = 2801;
99
+        $this->rights[$r][1] = 'Use FTP client in read mode (browse and download only)';
100
+        $this->rights[$r][2] = 'r';
101
+        $this->rights[$r][3] = 0;
102
+        $this->rights[$r][4] = 'read';
103
+
104
+        $r++;
105
+        $this->rights[$r][0] = 2802;
106
+        $this->rights[$r][1] = 'Use FTP client in write mode (delete or upload files)';
107
+        $this->rights[$r][2] = 'w';
108
+        $this->rights[$r][3] = 0;
109
+        $this->rights[$r][4] = 'write';
110
+
111
+
112
+        // Menus
113
+        //-------
114
+        $this->menu[$r]=array('fk_menu'=>0,
115
+                                'type'=>'top',
116
+                                'titre'=>'FTP',
117
+                                'mainmenu'=>'ftp',
118
+                                'url'=>'/ftp/index.php',
119
+                                'langs'=>'ftp',
120
+                                'position'=>100,
121
+                                'enabled'=>'$conf->ftp->enabled',
122
+                                'perms'=>'$user->rights->ftp->read || $user->rights->ftp->write || $user->rights->ftp->setup',
123
+                                'target'=>'',
124
+                                'user'=>2);			// 0=Menu for internal users, 1=external users, 2=both
125
+        $r++;
126
+    }
127 127
 }
128 128
 
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php 1 patch
Indentation   +910 added lines, -910 removed lines patch added patch discarded remove patch
@@ -51,154 +51,154 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public $description;
53 53
 
54
-	/**
54
+    /**
55 55
      * @var string document type
56 56
      */
57 57
     public $type;
58 58
 
59
-	/**
59
+    /**
60 60
      * @var array() Minimum version of PHP required by module.
61
-	 * e.g.: PHP ≥ 5.4 = array(5, 4)
61
+     * e.g.: PHP ≥ 5.4 = array(5, 4)
62 62
      */
63
-	public $phpmin = array(5, 4);
63
+    public $phpmin = array(5, 4);
64 64
 
65
-	/**
65
+    /**
66 66
      * Dolibarr version of the loaded document
67 67
      * @public string
68 68
      */
69
-	public $version = 'dolibarr';
69
+    public $version = 'dolibarr';
70 70
 
71
-	/**
71
+    /**
72 72
      * @var int page_largeur
73 73
      */
74 74
     public $page_largeur;
75 75
 
76
-	/**
76
+    /**
77 77
      * @var int page_hauteur
78 78
      */
79 79
     public $page_hauteur;
80 80
 
81
-	/**
81
+    /**
82 82
      * @var array format
83 83
      */
84 84
     public $format;
85 85
 
86
-	/**
86
+    /**
87 87
      * @var int marge_gauche
88 88
      */
89
-	public $marge_gauche;
89
+    public $marge_gauche;
90 90
 
91
-	/**
91
+    /**
92 92
      * @var int marge_droite
93 93
      */
94
-	public $marge_droite;
94
+    public $marge_droite;
95 95
 
96
-	/**
96
+    /**
97 97
      * @var int marge_haute
98 98
      */
99
-	public $marge_haute;
99
+    public $marge_haute;
100 100
 
101
-	/**
101
+    /**
102 102
      * @var int marge_basse
103 103
      */
104
-	public $marge_basse;
105
-
106
-	/**
107
-	 * Issuer
108
-	 * @var Company object that emits
109
-	 */
110
-	public $emetteur;
111
-
112
-
113
-	/**
114
-	 *	Constructor
115
-	 *
116
-	 *	@param	DoliDB	$db		Database handler
117
-	 */
118
-	function __construct($db=0)
119
-	{
120
-		global $conf,$langs,$mysoc;
121
-
122
-		$this->db = $db;
123
-		$this->name = "rouget";
124
-		$this->description = $langs->trans("DocumentModelStandardPDF");
125
-
126
-		$this->type = 'pdf';
127
-		$formatarray=pdf_getFormat();
128
-		$this->page_largeur = $formatarray['width'];
129
-		$this->page_hauteur = $formatarray['height'];
130
-		$this->format = array($this->page_largeur,$this->page_hauteur);
131
-		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
132
-		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
133
-		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
134
-		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
135
-
136
-		$this->option_logo = 1;
137
-
138
-		// Get source company
139
-		$this->emetteur=$mysoc;
140
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
141
-
142
-		// Define position of columns
143
-		$this->posxdesc=$this->marge_gauche+1;
144
-		$this->posxweightvol=$this->page_largeur - $this->marge_droite - 78;
145
-		$this->posxqtyordered=$this->page_largeur - $this->marge_droite - 56;
146
-		$this->posxqtytoship=$this->page_largeur - $this->marge_droite - 28;
147
-		$this->posxpuht=$this->page_largeur - $this->marge_droite;
148
-
149
-		if (!empty($conf->global->SHIPPING_PDF_DISPLAY_AMOUNT_HT)) {	// Show also the prices
150
-			$this->posxweightvol=$this->page_largeur - $this->marge_droite - 118;
151
-			$this->posxqtyordered=$this->page_largeur - $this->marge_droite - 96;
152
-			$this->posxqtytoship=$this->page_largeur - $this->marge_droite - 68;
153
-			$this->posxpuht=$this->page_largeur - $this->marge_droite - 40;
154
-			$this->posxtotalht=$this->page_largeur - $this->marge_droite - 20;
155
-		}
156
-
157
-		$this->posxpicture=$this->posxweightvol - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);	// width of images
158
-
159
-		if ($this->page_largeur < 210) // To work with US executive format
160
-		{
161
-		    $this->posxweightvol-=20;
162
-		    $this->posxpicture-=20;
163
-		    $this->posxqtyordered-=20;
164
-		    $this->posxqtytoship-=20;
165
-		}
104
+    public $marge_basse;
166 105
 
167
-		if (! empty($conf->global->SHIPPING_PDF_HIDE_ORDERED))
168
-		{
169
-		    $this->posxweightvol += ($this->posxqtytoship - $this->posxqtyordered);
170
-		    $this->posxpicture += ($this->posxqtytoship - $this->posxqtyordered);
171
-		    $this->posxqtyordered = $this->posxqtytoship;
172
-		}
173
-	}
174
-
175
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
176
-	/**
177
-	 *	Function to build pdf onto disk
178
-	 *
179
-	 *	@param		Object		$object			Object expedition to generate (or id if old method)
180
-	 *	@param		Translate	$outputlangs		Lang output object
106
+    /**
107
+     * Issuer
108
+     * @var Company object that emits
109
+     */
110
+    public $emetteur;
111
+
112
+
113
+    /**
114
+     *	Constructor
115
+     *
116
+     *	@param	DoliDB	$db		Database handler
117
+     */
118
+    function __construct($db=0)
119
+    {
120
+        global $conf,$langs,$mysoc;
121
+
122
+        $this->db = $db;
123
+        $this->name = "rouget";
124
+        $this->description = $langs->trans("DocumentModelStandardPDF");
125
+
126
+        $this->type = 'pdf';
127
+        $formatarray=pdf_getFormat();
128
+        $this->page_largeur = $formatarray['width'];
129
+        $this->page_hauteur = $formatarray['height'];
130
+        $this->format = array($this->page_largeur,$this->page_hauteur);
131
+        $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
132
+        $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
133
+        $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
134
+        $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
135
+
136
+        $this->option_logo = 1;
137
+
138
+        // Get source company
139
+        $this->emetteur=$mysoc;
140
+        if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
141
+
142
+        // Define position of columns
143
+        $this->posxdesc=$this->marge_gauche+1;
144
+        $this->posxweightvol=$this->page_largeur - $this->marge_droite - 78;
145
+        $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 56;
146
+        $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 28;
147
+        $this->posxpuht=$this->page_largeur - $this->marge_droite;
148
+
149
+        if (!empty($conf->global->SHIPPING_PDF_DISPLAY_AMOUNT_HT)) {	// Show also the prices
150
+            $this->posxweightvol=$this->page_largeur - $this->marge_droite - 118;
151
+            $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 96;
152
+            $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 68;
153
+            $this->posxpuht=$this->page_largeur - $this->marge_droite - 40;
154
+            $this->posxtotalht=$this->page_largeur - $this->marge_droite - 20;
155
+        }
156
+
157
+        $this->posxpicture=$this->posxweightvol - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);	// width of images
158
+
159
+        if ($this->page_largeur < 210) // To work with US executive format
160
+        {
161
+            $this->posxweightvol-=20;
162
+            $this->posxpicture-=20;
163
+            $this->posxqtyordered-=20;
164
+            $this->posxqtytoship-=20;
165
+        }
166
+
167
+        if (! empty($conf->global->SHIPPING_PDF_HIDE_ORDERED))
168
+        {
169
+            $this->posxweightvol += ($this->posxqtytoship - $this->posxqtyordered);
170
+            $this->posxpicture += ($this->posxqtytoship - $this->posxqtyordered);
171
+            $this->posxqtyordered = $this->posxqtytoship;
172
+        }
173
+    }
174
+
175
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
176
+    /**
177
+     *	Function to build pdf onto disk
178
+     *
179
+     *	@param		Object		$object			Object expedition to generate (or id if old method)
180
+     *	@param		Translate	$outputlangs		Lang output object
181 181
      *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
182 182
      *  @param		int			$hidedetails		Do not show line details
183 183
      *  @param		int			$hidedesc			Do not show desc
184 184
      *  @param		int			$hideref			Do not show ref
185 185
      *  @return     int         	    			1=OK, 0=KO
186
-	 */
187
-	function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
188
-	{
189
-		// phpcs:enable
190
-		global $user,$conf,$langs,$hookmanager;
186
+     */
187
+    function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
188
+    {
189
+        // phpcs:enable
190
+        global $user,$conf,$langs,$hookmanager;
191 191
 
192
-		$object->fetch_thirdparty();
192
+        $object->fetch_thirdparty();
193 193
 
194
-		if (! is_object($outputlangs)) $outputlangs=$langs;
195
-		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
196
-		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
194
+        if (! is_object($outputlangs)) $outputlangs=$langs;
195
+        // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
196
+        if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
197 197
 
198
-		// Load traductions files requiredby by page
199
-		$outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch"));
198
+        // Load traductions files requiredby by page
199
+        $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch"));
200 200
 
201
-		$nblignes = count($object->lines);
201
+        $nblignes = count($object->lines);
202 202
 
203 203
         // Loop on each lines to detect if there is at least one image to show
204 204
         $realpatharray=array();
@@ -210,13 +210,13 @@  discard block
 block discarded – undo
210 210
             {
211 211
                 if (empty($object->lines[$i]->fk_product)) continue;
212 212
 
213
-				$objphoto = new Product($this->db);
214
-				$objphoto->fetch($object->lines[$i]->fk_product);
213
+                $objphoto = new Product($this->db);
214
+                $objphoto->fetch($object->lines[$i]->fk_product);
215 215
 
216
-				$pdir = get_exdir($object->lines[$i]->fk_product,2,0,0,$objphoto,'product') . $object->lines[$i]->fk_product ."/photos/";
217
-				$dir = $conf->product->dir_output.'/'.$pdir;
216
+                $pdir = get_exdir($object->lines[$i]->fk_product,2,0,0,$objphoto,'product') . $object->lines[$i]->fk_product ."/photos/";
217
+                $dir = $conf->product->dir_output.'/'.$pdir;
218 218
 
219
-				$realpath='';
219
+                $realpath='';
220 220
 
221 221
                 foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
222 222
                         {
@@ -246,52 +246,52 @@  discard block
 block discarded – undo
246 246
 
247 247
         if (count($realpatharray) == 0) $this->posxpicture=$this->posxweightvol;
248 248
 
249
-		if ($conf->expedition->dir_output)
250
-		{
251
-			// Definition de $dir et $file
252
-			if ($object->specimen)
253
-			{
254
-				$dir = $conf->expedition->dir_output."/sending";
255
-				$file = $dir . "/SPECIMEN.pdf";
256
-			}
257
-			else
258
-			{
259
-				$expref = dol_sanitizeFileName($object->ref);
260
-				$dir = $conf->expedition->dir_output."/sending/" . $expref;
261
-				$file = $dir . "/" . $expref . ".pdf";
262
-			}
263
-
264
-			if (! file_exists($dir))
265
-			{
266
-				if (dol_mkdir($dir) < 0)
267
-				{
268
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
269
-					return 0;
270
-				}
271
-			}
272
-
273
-			if (file_exists($dir))
274
-			{
275
-				// Add pdfgeneration hook
276
-				if (! is_object($hookmanager))
277
-				{
278
-					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
279
-					$hookmanager=new HookManager($this->db);
280
-				}
281
-				$hookmanager->initHooks(array('pdfgeneration'));
282
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
283
-				global $action;
284
-				$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
285
-
286
-				// Set nblignes with the new facture lines content after hook
287
-				$nblignes = count($object->lines);
288
-
289
-				$pdf=pdf_getInstance($this->format);
290
-				$default_font_size = pdf_getPDFFontSize($outputlangs);
291
-				$heightforinfotot = 8;	// Height reserved to output the info and total part
292
-		        $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5);	// Height reserved to output the free text on last page
293
-	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
294
-	            if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
249
+        if ($conf->expedition->dir_output)
250
+        {
251
+            // Definition de $dir et $file
252
+            if ($object->specimen)
253
+            {
254
+                $dir = $conf->expedition->dir_output."/sending";
255
+                $file = $dir . "/SPECIMEN.pdf";
256
+            }
257
+            else
258
+            {
259
+                $expref = dol_sanitizeFileName($object->ref);
260
+                $dir = $conf->expedition->dir_output."/sending/" . $expref;
261
+                $file = $dir . "/" . $expref . ".pdf";
262
+            }
263
+
264
+            if (! file_exists($dir))
265
+            {
266
+                if (dol_mkdir($dir) < 0)
267
+                {
268
+                    $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
269
+                    return 0;
270
+                }
271
+            }
272
+
273
+            if (file_exists($dir))
274
+            {
275
+                // Add pdfgeneration hook
276
+                if (! is_object($hookmanager))
277
+                {
278
+                    include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
279
+                    $hookmanager=new HookManager($this->db);
280
+                }
281
+                $hookmanager->initHooks(array('pdfgeneration'));
282
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
283
+                global $action;
284
+                $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
285
+
286
+                // Set nblignes with the new facture lines content after hook
287
+                $nblignes = count($object->lines);
288
+
289
+                $pdf=pdf_getInstance($this->format);
290
+                $default_font_size = pdf_getPDFFontSize($outputlangs);
291
+                $heightforinfotot = 8;	// Height reserved to output the info and total part
292
+                $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5);	// Height reserved to output the free text on last page
293
+                $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
294
+                if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
295 295
                 $pdf->SetAutoPageBreak(1,0);
296 296
 
297 297
                 if (class_exists('TCPDF'))
@@ -307,814 +307,814 @@  discard block
 block discarded – undo
307 307
                     $tplidx = $pdf->importPage(1);
308 308
                 }
309 309
 
310
-				$pdf->Open();
311
-				$pagenb=0;
312
-				$pdf->SetDrawColor(128,128,128);
313
-
314
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
315
-
316
-				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
317
-				$pdf->SetSubject($outputlangs->transnoentities("Shipment"));
318
-				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
319
-				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
320
-				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Shipment"));
321
-				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
322
-
323
-				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
324
-
325
-				// New page
326
-				$pdf->AddPage();
327
-				if (! empty($tplidx)) $pdf->useTemplate($tplidx);
328
-				$pagenb++;
329
-				$this->_pagehead($pdf, $object, 1, $outputlangs);
330
-				$pdf->SetFont('','', $default_font_size - 1);
331
-				$pdf->MultiCell(0, 3, '');		// Set interline to 3
332
-				$pdf->SetTextColor(0,0,0);
333
-
334
-				$tab_top = 90;
335
-				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
336
-				$tab_height = 130;
337
-				$tab_height_newpage = 150;
338
-
339
-				// Incoterm
340
-				$height_incoterms = 0;
341
-				if ($conf->incoterm->enabled)
342
-				{
343
-					$desc_incoterms = $object->getIncotermsForPDF();
344
-					if ($desc_incoterms)
345
-					{
346
-						$tab_top = 88;
347
-
348
-						$pdf->SetFont('','', $default_font_size - 1);
349
-						$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
350
-						$nexY = $pdf->GetY();
351
-						$height_incoterms=$nexY-$tab_top;
352
-
353
-						// Rect prend une longueur en 3eme param
354
-						$pdf->SetDrawColor(192,192,192);
355
-						$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
356
-
357
-						$tab_top = $nexY+6;
358
-						$height_incoterms += 4;
359
-					}
360
-				}
361
-
362
-				if (! empty($object->note_public) || ! empty($object->tracking_number))
363
-				{
364
-					$tab_top = 88 + $height_incoterms;
365
-					$tab_top_alt = $tab_top;
366
-
367
-					$pdf->SetFont('','B', $default_font_size - 2);
368
-					$pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top-1, $outputlangs->transnoentities("TrackingNumber")." : " . $object->tracking_number, 0, 1, false, true, 'L');
369
-
370
-					$tab_top_alt = $pdf->GetY();
371
-					//$tab_top_alt += 1;
372
-
373
-					// Tracking number
374
-					if (! empty($object->tracking_number))
375
-					{
376
-						$object->getUrlTrackingStatus($object->tracking_number);
377
-						if (! empty($object->tracking_url))
378
-						{
379
-							if ($object->shipping_method_id > 0)
380
-							{
381
-								// Get code using getLabelFromKey
382
-								$code=$outputlangs->getLabelFromKey($this->db,$object->shipping_method_id,'c_shipment_mode','rowid','code');
383
-								$label='';
384
-								if ($object->tracking_url != $object->tracking_number) $label.=$outputlangs->trans("LinkToTrackYourPackage")."<br>";
385
-								$label.=$outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code));
386
-								//var_dump($object->tracking_url != $object->tracking_number);exit;
387
-								if ($object->tracking_url != $object->tracking_number)
388
-								{
389
-									$label.=" : ";
390
-									$label.=$object->tracking_url;
391
-								}
392
-								$pdf->SetFont('','B', $default_font_size - 2);
393
-								$pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top_alt, $label, 0, 1, false, true, 'L');
394
-
395
-								$tab_top_alt = $pdf->GetY();
396
-							}
397
-						}
398
-					}
399
-
400
-					// Notes
401
-					if (! empty($object->note_public))
402
-					{
403
-						$pdf->SetFont('','', $default_font_size - 1);   // Dans boucle pour gerer multi-page
404
-						$pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1);
405
-					}
406
-
407
-					$nexY = $pdf->GetY();
408
-					$height_note=$nexY-$tab_top;
409
-
410
-					// Rect prend une longueur en 3eme param
411
-					$pdf->SetDrawColor(192,192,192);
412
-					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
413
-
414
-					$tab_height = $tab_height - $height_note;
415
-					$tab_top = $nexY+6;
416
-				}
417
-				else
418
-				{
419
-					$height_note=0;
420
-				}
421
-
422
-				$iniY = $tab_top + 7;
423
-				$curY = $tab_top + 7;
424
-				$nexY = $tab_top + 7;
425
-
426
-				// Loop on each lines
427
-				for ($i = 0; $i < $nblignes; $i++)
428
-				{
429
-					$curY = $nexY;
430
-					$pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
431
-					$pdf->SetTextColor(0,0,0);
432
-
433
-					// Define size of image if we need it
434
-					$imglinesize=array();
435
-					if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
436
-
437
-					$pdf->setTopMargin($tab_top_newpage);
438
-					$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
439
-					$pageposbefore=$pdf->getPage();
440
-
441
-					$showpricebeforepagebreak=1;
442
-					$posYAfterImage=0;
443
-					$posYAfterDescription=0;
444
-
445
-					// We start with Photo of product line
446
-					if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot)))	// If photo too high, we moved completely on new page
447
-					{
448
-						$pdf->AddPage('','',true);
449
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
450
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
451
-						$pdf->setPage($pageposbefore+1);
452
-
453
-						$curY = $tab_top_newpage;
454
-						$showpricebeforepagebreak=0;
455
-					}
456
-
457
-					if (isset($imglinesize['width']) && isset($imglinesize['height']))
458
-					{
459
-						$curX = $this->posxpicture-1;
460
-						$pdf->Image($realpatharray[$i], $curX + (($this->posxweightvol-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
461
-						// $pdf->Image does not increase value return by getY, so we save it manually
462
-						$posYAfterImage=$curY+$imglinesize['height'];
463
-					}
464
-
465
-					// Description of product line
466
-					$curX = $this->posxdesc-1;
467
-
468
-					$pdf->startTransaction();
469
-					pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc);
470
-
471
-					$pageposafter=$pdf->getPage();
472
-					if ($pageposafter > $pageposbefore)	// There is a pagebreak
473
-					{
474
-						$pdf->rollbackTransaction(true);
475
-						$pageposafter=$pageposbefore;
476
-						//print $pageposafter.'-'.$pageposbefore;exit;
477
-						$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
478
-						pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc);
479
-
480
-						$pageposafter=$pdf->getPage();
481
-						$posyafter=$pdf->GetY();
482
-						//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
483
-						if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
484
-						{
485
-							if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
486
-							{
487
-								$pdf->AddPage('','',true);
488
-								if (! empty($tplidx)) $pdf->useTemplate($tplidx);
489
-								if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
490
-								$pdf->setPage($pageposafter+1);
491
-							}
492
-						}
493
-						else
494
-						{
495
-							// We found a page break
496
-							$showpricebeforepagebreak=0;
497
-						}
498
-					}
499
-					else	// No pagebreak
500
-					{
501
-						$pdf->commitTransaction();
502
-					}
503
-					$posYAfterDescription=$pdf->GetY();
504
-
505
-					$nexY = $pdf->GetY();
506
-					$pageposafter=$pdf->getPage();
507
-
508
-					$pdf->setPage($pageposbefore);
509
-					$pdf->setTopMargin($this->marge_haute);
510
-					$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
511
-
512
-					// We suppose that a too long description or photo were moved completely on next page
513
-					if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
514
-						$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
515
-					}
516
-
517
-					// We suppose that a too long description is moved completely on next page
518
-					if ($pageposafter > $pageposbefore) {
519
-						$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
520
-					}
521
-
522
-					$pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
523
-
524
-					$pdf->SetXY($this->posxweightvol, $curY);
525
-					$weighttxt='';
526
-					if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->weight)
527
-					{
528
-					    $weighttxt=round($object->lines[$i]->weight * $object->lines[$i]->qty_shipped, 5).' '.measuring_units_string($object->lines[$i]->weight_units,"weight");
529
-					}
530
-					$voltxt='';
531
-					if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->volume)
532
-					{
533
-					    $voltxt=round($object->lines[$i]->volume * $object->lines[$i]->qty_shipped, 5).' '.measuring_units_string($object->lines[$i]->volume_units?$object->lines[$i]->volume_units:0,"volume");
534
-					}
535
-
536
-					if (empty($conf->global->SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME))
537
-					{
538
-						$pdf->writeHTMLCell($this->posxqtyordered - $this->posxweightvol + 2, 3, $this->posxweightvol - 1, $curY, $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt, 0, 0, false, true, 'C');
539
-						//$pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 3, $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt,'','C');
540
-					}
541
-
542
-					if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED))
543
-					{
544
-					   $pdf->SetXY($this->posxqtyordered, $curY);
545
-					   $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 3, $object->lines[$i]->qty_asked,'','C');
546
-					}
547
-
548
-					if (empty($conf->global->SHIPPING_PDF_HIDE_QTYTOSHIP))
549
-					{
550
-						$pdf->SetXY($this->posxqtytoship, $curY);
551
-						$pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 3, $object->lines[$i]->qty_shipped,'','C');
552
-					}
553
-
554
-					if(!empty($conf->global->SHIPPING_PDF_DISPLAY_AMOUNT_HT))
555
-					{
556
-						$pdf->SetXY($this->posxpuht, $curY);
557
-						$pdf->MultiCell(($this->posxtotalht - $this->posxpuht-1), 3, price($object->lines[$i]->subprice, 0, $outputlangs),'','R');
558
-
559
-						$pdf->SetXY($this->posxtotalht, $curY);
560
-						$pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 3, price($object->lines[$i]->total_ht, 0, $outputlangs),'','R');
561
-					}
562
-
563
-					$nexY+=3;
564
-					if ($weighttxt && $voltxt) $nexY+=2;
565
-
566
-					// Add line
567
-					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
568
-					{
569
-						$pdf->setPage($pageposafter);
570
-						$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
571
-						//$pdf->SetDrawColor(190,190,200);
572
-						$pdf->line($this->marge_gauche, $nexY-1, $this->page_largeur - $this->marge_droite, $nexY-1);
573
-						$pdf->SetLineStyle(array('dash'=>0));
574
-					}
575
-
576
-					// Detect if some page were added automatically and output _tableau for past pages
577
-					while ($pagenb < $pageposafter)
578
-					{
579
-						$pdf->setPage($pagenb);
580
-						if ($pagenb == 1)
581
-						{
582
-							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
583
-						}
584
-						else
585
-						{
586
-							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
587
-						}
588
-						$this->_pagefoot($pdf,$object,$outputlangs,1);
589
-						$pagenb++;
590
-						$pdf->setPage($pagenb);
591
-						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
592
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
593
-					}
594
-					if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
595
-					{
596
-						if ($pagenb == 1)
597
-						{
598
-							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
599
-						}
600
-						else
601
-						{
602
-							$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
603
-						}
604
-						$this->_pagefoot($pdf,$object,$outputlangs,1);
605
-						// New page
606
-						$pdf->AddPage();
607
-						if (! empty($tplidx)) $pdf->useTemplate($tplidx);
608
-						$pagenb++;
609
-						if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
610
-					}
611
-				}
612
-
613
-				// Show square
614
-				if ($pagenb == 1)
615
-				{
616
-					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
617
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
618
-				}
619
-				else
620
-				{
621
-					$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
622
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
623
-				}
624
-
625
-				// Affiche zone totaux
626
-				$posy=$this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
627
-
628
-				// Pied de page
629
-				$this->_pagefoot($pdf,$object,$outputlangs);
630
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
631
-
632
-				$pdf->Close();
633
-
634
-				$pdf->Output($file,'F');
635
-
636
-				// Add pdfgeneration hook
637
-				$hookmanager->initHooks(array('pdfgeneration'));
638
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
639
-				global $action;
640
-				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
641
-
642
-				if (! empty($conf->global->MAIN_UMASK))
643
-				@chmod($file, octdec($conf->global->MAIN_UMASK));
644
-
645
-				$this->result = array('fullpath'=>$file);
646
-
647
-				return 1;	// No error
648
-			}
649
-			else
650
-			{
651
-				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
652
-				return 0;
653
-			}
654
-		}
655
-		else
656
-		{
657
-			$this->error=$langs->transnoentities("ErrorConstantNotDefined","EXP_OUTPUTDIR");
658
-			return 0;
659
-		}
660
-	}
661
-
662
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
663
-	/**
664
-	 *	Show total to pay
665
-	 *
666
-	 *	@param	PDF			$pdf           Object PDF
667
-	 *	@param  Facture		$object         Object invoice
668
-	 *	@param  int			$deja_regle     Montant deja regle
669
-	 *	@param	int			$posy			Position depart
670
-	 *	@param	Translate	$outputlangs	Objet langs
671
-	 *	@return int							Position pour suite
672
-	 */
673
-	function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
674
-	{
675
-		// phpcs:enable
676
-		global $conf,$mysoc;
310
+                $pdf->Open();
311
+                $pagenb=0;
312
+                $pdf->SetDrawColor(128,128,128);
313
+
314
+                if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
315
+
316
+                $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
317
+                $pdf->SetSubject($outputlangs->transnoentities("Shipment"));
318
+                $pdf->SetCreator("Dolibarr ".DOL_VERSION);
319
+                $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
320
+                $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Shipment"));
321
+                if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
322
+
323
+                $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
324
+
325
+                // New page
326
+                $pdf->AddPage();
327
+                if (! empty($tplidx)) $pdf->useTemplate($tplidx);
328
+                $pagenb++;
329
+                $this->_pagehead($pdf, $object, 1, $outputlangs);
330
+                $pdf->SetFont('','', $default_font_size - 1);
331
+                $pdf->MultiCell(0, 3, '');		// Set interline to 3
332
+                $pdf->SetTextColor(0,0,0);
333
+
334
+                $tab_top = 90;
335
+                $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
336
+                $tab_height = 130;
337
+                $tab_height_newpage = 150;
338
+
339
+                // Incoterm
340
+                $height_incoterms = 0;
341
+                if ($conf->incoterm->enabled)
342
+                {
343
+                    $desc_incoterms = $object->getIncotermsForPDF();
344
+                    if ($desc_incoterms)
345
+                    {
346
+                        $tab_top = 88;
347
+
348
+                        $pdf->SetFont('','', $default_font_size - 1);
349
+                        $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
350
+                        $nexY = $pdf->GetY();
351
+                        $height_incoterms=$nexY-$tab_top;
352
+
353
+                        // Rect prend une longueur en 3eme param
354
+                        $pdf->SetDrawColor(192,192,192);
355
+                        $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
356
+
357
+                        $tab_top = $nexY+6;
358
+                        $height_incoterms += 4;
359
+                    }
360
+                }
361
+
362
+                if (! empty($object->note_public) || ! empty($object->tracking_number))
363
+                {
364
+                    $tab_top = 88 + $height_incoterms;
365
+                    $tab_top_alt = $tab_top;
366
+
367
+                    $pdf->SetFont('','B', $default_font_size - 2);
368
+                    $pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top-1, $outputlangs->transnoentities("TrackingNumber")." : " . $object->tracking_number, 0, 1, false, true, 'L');
369
+
370
+                    $tab_top_alt = $pdf->GetY();
371
+                    //$tab_top_alt += 1;
372
+
373
+                    // Tracking number
374
+                    if (! empty($object->tracking_number))
375
+                    {
376
+                        $object->getUrlTrackingStatus($object->tracking_number);
377
+                        if (! empty($object->tracking_url))
378
+                        {
379
+                            if ($object->shipping_method_id > 0)
380
+                            {
381
+                                // Get code using getLabelFromKey
382
+                                $code=$outputlangs->getLabelFromKey($this->db,$object->shipping_method_id,'c_shipment_mode','rowid','code');
383
+                                $label='';
384
+                                if ($object->tracking_url != $object->tracking_number) $label.=$outputlangs->trans("LinkToTrackYourPackage")."<br>";
385
+                                $label.=$outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code));
386
+                                //var_dump($object->tracking_url != $object->tracking_number);exit;
387
+                                if ($object->tracking_url != $object->tracking_number)
388
+                                {
389
+                                    $label.=" : ";
390
+                                    $label.=$object->tracking_url;
391
+                                }
392
+                                $pdf->SetFont('','B', $default_font_size - 2);
393
+                                $pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top_alt, $label, 0, 1, false, true, 'L');
394
+
395
+                                $tab_top_alt = $pdf->GetY();
396
+                            }
397
+                        }
398
+                    }
399
+
400
+                    // Notes
401
+                    if (! empty($object->note_public))
402
+                    {
403
+                        $pdf->SetFont('','', $default_font_size - 1);   // Dans boucle pour gerer multi-page
404
+                        $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1);
405
+                    }
406
+
407
+                    $nexY = $pdf->GetY();
408
+                    $height_note=$nexY-$tab_top;
409
+
410
+                    // Rect prend une longueur en 3eme param
411
+                    $pdf->SetDrawColor(192,192,192);
412
+                    $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
413
+
414
+                    $tab_height = $tab_height - $height_note;
415
+                    $tab_top = $nexY+6;
416
+                }
417
+                else
418
+                {
419
+                    $height_note=0;
420
+                }
421
+
422
+                $iniY = $tab_top + 7;
423
+                $curY = $tab_top + 7;
424
+                $nexY = $tab_top + 7;
425
+
426
+                // Loop on each lines
427
+                for ($i = 0; $i < $nblignes; $i++)
428
+                {
429
+                    $curY = $nexY;
430
+                    $pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
431
+                    $pdf->SetTextColor(0,0,0);
432
+
433
+                    // Define size of image if we need it
434
+                    $imglinesize=array();
435
+                    if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
436
+
437
+                    $pdf->setTopMargin($tab_top_newpage);
438
+                    $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it.
439
+                    $pageposbefore=$pdf->getPage();
440
+
441
+                    $showpricebeforepagebreak=1;
442
+                    $posYAfterImage=0;
443
+                    $posYAfterDescription=0;
444
+
445
+                    // We start with Photo of product line
446
+                    if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot)))	// If photo too high, we moved completely on new page
447
+                    {
448
+                        $pdf->AddPage('','',true);
449
+                        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
450
+                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
451
+                        $pdf->setPage($pageposbefore+1);
452
+
453
+                        $curY = $tab_top_newpage;
454
+                        $showpricebeforepagebreak=0;
455
+                    }
456
+
457
+                    if (isset($imglinesize['width']) && isset($imglinesize['height']))
458
+                    {
459
+                        $curX = $this->posxpicture-1;
460
+                        $pdf->Image($realpatharray[$i], $curX + (($this->posxweightvol-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);	// Use 300 dpi
461
+                        // $pdf->Image does not increase value return by getY, so we save it manually
462
+                        $posYAfterImage=$curY+$imglinesize['height'];
463
+                    }
464
+
465
+                    // Description of product line
466
+                    $curX = $this->posxdesc-1;
467
+
468
+                    $pdf->startTransaction();
469
+                    pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc);
470
+
471
+                    $pageposafter=$pdf->getPage();
472
+                    if ($pageposafter > $pageposbefore)	// There is a pagebreak
473
+                    {
474
+                        $pdf->rollbackTransaction(true);
475
+                        $pageposafter=$pageposbefore;
476
+                        //print $pageposafter.'-'.$pageposbefore;exit;
477
+                        $pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
478
+                        pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc);
479
+
480
+                        $pageposafter=$pdf->getPage();
481
+                        $posyafter=$pdf->GetY();
482
+                        //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
483
+                        if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))	// There is no space left for total+free text
484
+                        {
485
+                            if ($i == ($nblignes-1))	// No more lines, and no space left to show total, so we create a new page
486
+                            {
487
+                                $pdf->AddPage('','',true);
488
+                                if (! empty($tplidx)) $pdf->useTemplate($tplidx);
489
+                                if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
490
+                                $pdf->setPage($pageposafter+1);
491
+                            }
492
+                        }
493
+                        else
494
+                        {
495
+                            // We found a page break
496
+                            $showpricebeforepagebreak=0;
497
+                        }
498
+                    }
499
+                    else	// No pagebreak
500
+                    {
501
+                        $pdf->commitTransaction();
502
+                    }
503
+                    $posYAfterDescription=$pdf->GetY();
504
+
505
+                    $nexY = $pdf->GetY();
506
+                    $pageposafter=$pdf->getPage();
507
+
508
+                    $pdf->setPage($pageposbefore);
509
+                    $pdf->setTopMargin($this->marge_haute);
510
+                    $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
511
+
512
+                    // We suppose that a too long description or photo were moved completely on next page
513
+                    if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
514
+                        $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
515
+                    }
516
+
517
+                    // We suppose that a too long description is moved completely on next page
518
+                    if ($pageposafter > $pageposbefore) {
519
+                        $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
520
+                    }
521
+
522
+                    $pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
523
+
524
+                    $pdf->SetXY($this->posxweightvol, $curY);
525
+                    $weighttxt='';
526
+                    if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->weight)
527
+                    {
528
+                        $weighttxt=round($object->lines[$i]->weight * $object->lines[$i]->qty_shipped, 5).' '.measuring_units_string($object->lines[$i]->weight_units,"weight");
529
+                    }
530
+                    $voltxt='';
531
+                    if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->volume)
532
+                    {
533
+                        $voltxt=round($object->lines[$i]->volume * $object->lines[$i]->qty_shipped, 5).' '.measuring_units_string($object->lines[$i]->volume_units?$object->lines[$i]->volume_units:0,"volume");
534
+                    }
535
+
536
+                    if (empty($conf->global->SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME))
537
+                    {
538
+                        $pdf->writeHTMLCell($this->posxqtyordered - $this->posxweightvol + 2, 3, $this->posxweightvol - 1, $curY, $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt, 0, 0, false, true, 'C');
539
+                        //$pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 3, $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt,'','C');
540
+                    }
541
+
542
+                    if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED))
543
+                    {
544
+                        $pdf->SetXY($this->posxqtyordered, $curY);
545
+                        $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 3, $object->lines[$i]->qty_asked,'','C');
546
+                    }
547
+
548
+                    if (empty($conf->global->SHIPPING_PDF_HIDE_QTYTOSHIP))
549
+                    {
550
+                        $pdf->SetXY($this->posxqtytoship, $curY);
551
+                        $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 3, $object->lines[$i]->qty_shipped,'','C');
552
+                    }
553
+
554
+                    if(!empty($conf->global->SHIPPING_PDF_DISPLAY_AMOUNT_HT))
555
+                    {
556
+                        $pdf->SetXY($this->posxpuht, $curY);
557
+                        $pdf->MultiCell(($this->posxtotalht - $this->posxpuht-1), 3, price($object->lines[$i]->subprice, 0, $outputlangs),'','R');
558
+
559
+                        $pdf->SetXY($this->posxtotalht, $curY);
560
+                        $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 3, price($object->lines[$i]->total_ht, 0, $outputlangs),'','R');
561
+                    }
562
+
563
+                    $nexY+=3;
564
+                    if ($weighttxt && $voltxt) $nexY+=2;
565
+
566
+                    // Add line
567
+                    if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
568
+                    {
569
+                        $pdf->setPage($pageposafter);
570
+                        $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
571
+                        //$pdf->SetDrawColor(190,190,200);
572
+                        $pdf->line($this->marge_gauche, $nexY-1, $this->page_largeur - $this->marge_droite, $nexY-1);
573
+                        $pdf->SetLineStyle(array('dash'=>0));
574
+                    }
575
+
576
+                    // Detect if some page were added automatically and output _tableau for past pages
577
+                    while ($pagenb < $pageposafter)
578
+                    {
579
+                        $pdf->setPage($pagenb);
580
+                        if ($pagenb == 1)
581
+                        {
582
+                            $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
583
+                        }
584
+                        else
585
+                        {
586
+                            $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
587
+                        }
588
+                        $this->_pagefoot($pdf,$object,$outputlangs,1);
589
+                        $pagenb++;
590
+                        $pdf->setPage($pagenb);
591
+                        $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
592
+                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
593
+                    }
594
+                    if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
595
+                    {
596
+                        if ($pagenb == 1)
597
+                        {
598
+                            $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
599
+                        }
600
+                        else
601
+                        {
602
+                            $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
603
+                        }
604
+                        $this->_pagefoot($pdf,$object,$outputlangs,1);
605
+                        // New page
606
+                        $pdf->AddPage();
607
+                        if (! empty($tplidx)) $pdf->useTemplate($tplidx);
608
+                        $pagenb++;
609
+                        if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
610
+                    }
611
+                }
612
+
613
+                // Show square
614
+                if ($pagenb == 1)
615
+                {
616
+                    $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
617
+                    $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
618
+                }
619
+                else
620
+                {
621
+                    $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
622
+                    $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
623
+                }
624
+
625
+                // Affiche zone totaux
626
+                $posy=$this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
627
+
628
+                // Pied de page
629
+                $this->_pagefoot($pdf,$object,$outputlangs);
630
+                if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
631
+
632
+                $pdf->Close();
633
+
634
+                $pdf->Output($file,'F');
635
+
636
+                // Add pdfgeneration hook
637
+                $hookmanager->initHooks(array('pdfgeneration'));
638
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
639
+                global $action;
640
+                $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
641
+
642
+                if (! empty($conf->global->MAIN_UMASK))
643
+                @chmod($file, octdec($conf->global->MAIN_UMASK));
644
+
645
+                $this->result = array('fullpath'=>$file);
646
+
647
+                return 1;	// No error
648
+            }
649
+            else
650
+            {
651
+                $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
652
+                return 0;
653
+            }
654
+        }
655
+        else
656
+        {
657
+            $this->error=$langs->transnoentities("ErrorConstantNotDefined","EXP_OUTPUTDIR");
658
+            return 0;
659
+        }
660
+    }
661
+
662
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
663
+    /**
664
+     *	Show total to pay
665
+     *
666
+     *	@param	PDF			$pdf           Object PDF
667
+     *	@param  Facture		$object         Object invoice
668
+     *	@param  int			$deja_regle     Montant deja regle
669
+     *	@param	int			$posy			Position depart
670
+     *	@param	Translate	$outputlangs	Objet langs
671
+     *	@return int							Position pour suite
672
+     */
673
+    function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
674
+    {
675
+        // phpcs:enable
676
+        global $conf,$mysoc;
677 677
 
678 678
         $sign=1;
679 679
 
680 680
         $default_font_size = pdf_getPDFFontSize($outputlangs);
681 681
 
682
-		$tab2_top = $posy;
683
-		$tab2_hl = 4;
684
-		$pdf->SetFont('','B', $default_font_size - 1);
682
+        $tab2_top = $posy;
683
+        $tab2_hl = 4;
684
+        $pdf->SetFont('','B', $default_font_size - 1);
685 685
 
686
-		// Tableau total
687
-		$col1x = $this->posxweightvol-50; $col2x = $this->posxweightvol;
688
-		/*if ($this->page_largeur < 210) // To work with US executive format
686
+        // Tableau total
687
+        $col1x = $this->posxweightvol-50; $col2x = $this->posxweightvol;
688
+        /*if ($this->page_largeur < 210) // To work with US executive format
689 689
 		{
690 690
 			$col2x-=20;
691 691
 		}*/
692
-		if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) $largcol2 = ($this->posxqtyordered - $this->posxweightvol);
693
-		else $largcol2 = ($this->posxqtytoship - $this->posxweightvol);
694
-
695
-		$useborder=0;
696
-		$index = 0;
697
-
698
-		$totalWeighttoshow='';
699
-		$totalVolumetoshow='';
700
-
701
-		// Load dim data
702
-		$tmparray=$object->getTotalWeightVolume();
703
-		$totalWeight=$tmparray['weight'];
704
-		$totalVolume=$tmparray['volume'];
705
-		$totalOrdered=$tmparray['ordered'];
706
-		$totalToShip=$tmparray['toship'];
707
-		// Set trueVolume and volume_units not currently stored into database
708
-		if ($object->trueWidth && $object->trueHeight && $object->trueDepth)
709
-		{
710
-		    $object->trueVolume=price(($object->trueWidth * $object->trueHeight * $object->trueDepth), 0, $outputlangs, 0, 0);
711
-		    $object->volume_units=$object->size_units * 3;
712
-		}
692
+        if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) $largcol2 = ($this->posxqtyordered - $this->posxweightvol);
693
+        else $largcol2 = ($this->posxqtytoship - $this->posxweightvol);
694
+
695
+        $useborder=0;
696
+        $index = 0;
697
+
698
+        $totalWeighttoshow='';
699
+        $totalVolumetoshow='';
700
+
701
+        // Load dim data
702
+        $tmparray=$object->getTotalWeightVolume();
703
+        $totalWeight=$tmparray['weight'];
704
+        $totalVolume=$tmparray['volume'];
705
+        $totalOrdered=$tmparray['ordered'];
706
+        $totalToShip=$tmparray['toship'];
707
+        // Set trueVolume and volume_units not currently stored into database
708
+        if ($object->trueWidth && $object->trueHeight && $object->trueDepth)
709
+        {
710
+            $object->trueVolume=price(($object->trueWidth * $object->trueHeight * $object->trueDepth), 0, $outputlangs, 0, 0);
711
+            $object->volume_units=$object->size_units * 3;
712
+        }
713 713
 
714
-		if ($totalWeight!='') $totalWeighttoshow=showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs);
715
-		if ($totalVolume!='') $totalVolumetoshow=showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs);
716
-		if ($object->trueWeight) $totalWeighttoshow=showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs);
717
-		if ($object->trueVolume) $totalVolumetoshow=showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
714
+        if ($totalWeight!='') $totalWeighttoshow=showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs);
715
+        if ($totalVolume!='') $totalVolumetoshow=showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs);
716
+        if ($object->trueWeight) $totalWeighttoshow=showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs);
717
+        if ($object->trueVolume) $totalVolumetoshow=showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
718 718
 
719
-    	$pdf->SetFillColor(255,255,255);
720
-    	$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
721
-    	$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', 1);
719
+        $pdf->SetFillColor(255,255,255);
720
+        $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
721
+        $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', 1);
722 722
 
723 723
         if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED))
724 724
         {
725 725
             $pdf->SetXY($this->posxqtyordered, $tab2_top + $tab2_hl * $index);
726
-        	$pdf->MultiCell($this->posxqtytoship - $this->posxqtyordered, $tab2_hl, $totalOrdered, 0, 'C', 1);
726
+            $pdf->MultiCell($this->posxqtytoship - $this->posxqtyordered, $tab2_hl, $totalOrdered, 0, 'C', 1);
727 727
         }
728 728
 
729 729
         if (empty($conf->global->SHIPPING_PDF_HIDE_QTYTOSHIP))
730 730
         {
731
-        	$pdf->SetXY($this->posxqtytoship, $tab2_top + $tab2_hl * $index);
732
-        	$pdf->MultiCell($this->posxpuht - $this->posxqtytoship, $tab2_hl, $totalToShip, 0, 'C', 1);
731
+            $pdf->SetXY($this->posxqtytoship, $tab2_top + $tab2_hl * $index);
732
+            $pdf->MultiCell($this->posxpuht - $this->posxqtytoship, $tab2_hl, $totalToShip, 0, 'C', 1);
733 733
         }
734 734
 
735
-		if (!empty($conf->global->SHIPPING_PDF_DISPLAY_AMOUNT_HT))
736
-		{
737
-	    	$pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index);
738
-	    	$pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1);
735
+        if (!empty($conf->global->SHIPPING_PDF_DISPLAY_AMOUNT_HT))
736
+        {
737
+            $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index);
738
+            $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1);
739 739
 
740
-	    	$pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index);
741
-	    	$pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1);
742
-		}
740
+            $pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index);
741
+            $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1);
742
+        }
743 743
 
744
-		if (empty($conf->global->SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME))
745
-		{
746
-			// Total Weight
747
-			if ($totalWeighttoshow)
748
-			{
749
-	    		$pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
750
-	    		$pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalWeighttoshow, 0, 'C', 1);
751
-
752
-	    		$index++;
753
-			}
754
-			if ($totalVolumetoshow)
755
-			{
756
-	    		$pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
757
-	    		$pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalVolumetoshow, 0, 'C', 1);
758
-
759
-			    $index++;
760
-			}
761
-			if (! $totalWeighttoshow && ! $totalVolumetoshow) $index++;
762
-		}
763
-
764
-		$pdf->SetTextColor(0,0,0);
765
-
766
-		return ($tab2_top + ($tab2_hl * $index));
767
-	}
768
-
769
-	/**
770
-	 *   Show table for lines
771
-	 *
772
-	 *   @param		PDF			$pdf     		Object PDF
773
-	 *   @param		string		$tab_top		Top position of table
774
-	 *   @param		string		$tab_height		Height of table (rectangle)
775
-	 *   @param		int			$nexY			Y
776
-	 *   @param		Translate	$outputlangs	Langs object
777
-	 *   @param		int			$hidetop		Hide top bar of array
778
-	 *   @param		int			$hidebottom		Hide bottom bar of array
779
-	 *   @return	void
780
-	 */
781
-	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
782
-	{
783
-		global $conf;
784
-
785
-		// Force to disable hidetop and hidebottom
786
-		$hidebottom=0;
787
-		if ($hidetop) $hidetop=-1;
788
-
789
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
790
-
791
-		// Amount in (at tab_top - 1)
792
-		$pdf->SetTextColor(0,0,0);
793
-		$pdf->SetFont('','',$default_font_size - 2);
794
-
795
-		// Output Rect
796
-		$this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
797
-
798
-		$pdf->SetDrawColor(128,128,128);
799
-		$pdf->SetFont('','', $default_font_size - 1);
800
-
801
-		if (empty($hidetop))
802
-		{
803
-			$pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);
744
+        if (empty($conf->global->SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME))
745
+        {
746
+            // Total Weight
747
+            if ($totalWeighttoshow)
748
+            {
749
+                $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
750
+                $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalWeighttoshow, 0, 'C', 1);
804 751
 
805
-			$pdf->SetXY($this->posxdesc-1, $tab_top+1);
806
-			$pdf->MultiCell($this->posxqtyordered - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L');
807
-		}
752
+                $index++;
753
+            }
754
+            if ($totalVolumetoshow)
755
+            {
756
+                $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
757
+                $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalVolumetoshow, 0, 'C', 1);
808 758
 
809
-		if (empty($conf->global->SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME))
810
-		{
811
-			$pdf->line($this->posxweightvol-1, $tab_top, $this->posxweightvol-1, $tab_top + $tab_height);
812
-			if (empty($hidetop))
813
-			{
814
-				$pdf->SetXY($this->posxweightvol-1, $tab_top+1);
815
-				$pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 2, $outputlangs->transnoentities("WeightVolShort"),'','C');
816
-			}
817
-		}
759
+                $index++;
760
+            }
761
+            if (! $totalWeighttoshow && ! $totalVolumetoshow) $index++;
762
+        }
763
+
764
+        $pdf->SetTextColor(0,0,0);
765
+
766
+        return ($tab2_top + ($tab2_hl * $index));
767
+    }
768
+
769
+    /**
770
+     *   Show table for lines
771
+     *
772
+     *   @param		PDF			$pdf     		Object PDF
773
+     *   @param		string		$tab_top		Top position of table
774
+     *   @param		string		$tab_height		Height of table (rectangle)
775
+     *   @param		int			$nexY			Y
776
+     *   @param		Translate	$outputlangs	Langs object
777
+     *   @param		int			$hidetop		Hide top bar of array
778
+     *   @param		int			$hidebottom		Hide bottom bar of array
779
+     *   @return	void
780
+     */
781
+    function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
782
+    {
783
+        global $conf;
784
+
785
+        // Force to disable hidetop and hidebottom
786
+        $hidebottom=0;
787
+        if ($hidetop) $hidetop=-1;
788
+
789
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
790
+
791
+        // Amount in (at tab_top - 1)
792
+        $pdf->SetTextColor(0,0,0);
793
+        $pdf->SetFont('','',$default_font_size - 2);
794
+
795
+        // Output Rect
796
+        $this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);	// Rect prend une longueur en 3eme param et 4eme param
797
+
798
+        $pdf->SetDrawColor(128,128,128);
799
+        $pdf->SetFont('','', $default_font_size - 1);
800
+
801
+        if (empty($hidetop))
802
+        {
803
+            $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);
804
+
805
+            $pdf->SetXY($this->posxdesc-1, $tab_top+1);
806
+            $pdf->MultiCell($this->posxqtyordered - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L');
807
+        }
808
+
809
+        if (empty($conf->global->SHIPPING_PDF_HIDE_WEIGHT_AND_VOLUME))
810
+        {
811
+            $pdf->line($this->posxweightvol-1, $tab_top, $this->posxweightvol-1, $tab_top + $tab_height);
812
+            if (empty($hidetop))
813
+            {
814
+                $pdf->SetXY($this->posxweightvol-1, $tab_top+1);
815
+                $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 2, $outputlangs->transnoentities("WeightVolShort"),'','C');
816
+            }
817
+        }
818 818
 
819 819
         if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED))
820 820
         {
821 821
             $pdf->line($this->posxqtyordered-1, $tab_top, $this->posxqtyordered-1, $tab_top + $tab_height);
822
-    		if (empty($hidetop))
823
-    		{
824
-    			$pdf->SetXY($this->posxqtyordered-1, $tab_top+1);
825
-    			$pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 2, $outputlangs->transnoentities("QtyOrdered"),'','C');
826
-    		}
822
+            if (empty($hidetop))
823
+            {
824
+                $pdf->SetXY($this->posxqtyordered-1, $tab_top+1);
825
+                $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 2, $outputlangs->transnoentities("QtyOrdered"),'','C');
826
+            }
827 827
         }
828 828
 
829 829
         if (empty($conf->global->SHIPPING_PDF_HIDE_QTYTOSHIP))
830 830
         {
831
-			$pdf->line($this->posxqtytoship-1, $tab_top, $this->posxqtytoship-1, $tab_top + $tab_height);
832
-			if (empty($hidetop))
833
-			{
834
-				$pdf->SetXY($this->posxqtytoship, $tab_top+1);
835
-				$pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 2, $outputlangs->transnoentities("QtyToShip"),'','C');
836
-			}
831
+            $pdf->line($this->posxqtytoship-1, $tab_top, $this->posxqtytoship-1, $tab_top + $tab_height);
832
+            if (empty($hidetop))
833
+            {
834
+                $pdf->SetXY($this->posxqtytoship, $tab_top+1);
835
+                $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 2, $outputlangs->transnoentities("QtyToShip"),'','C');
836
+            }
837 837
         }
838 838
 
839
-		if (!empty($conf->global->SHIPPING_PDF_DISPLAY_AMOUNT_HT)) {
840
-
841
-			$pdf->line($this->posxpuht-1, $tab_top, $this->posxpuht-1, $tab_top + $tab_height);
842
-			if (empty($hidetop))
843
-			{
844
-				$pdf->SetXY($this->posxpuht-1, $tab_top+1);
845
-				$pdf->MultiCell(($this->posxtotalht - $this->posxpuht), 2, $outputlangs->transnoentities("PriceUHT"),'','C');
846
-			}
847
-
848
-			$pdf->line($this->posxtotalht-1, $tab_top, $this->posxtotalht-1, $tab_top + $tab_height);
849
-			if (empty($hidetop))
850
-			{
851
-				$pdf->SetXY($this->posxtotalht-1, $tab_top+1);
852
-				$pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 2, $outputlangs->transnoentities("TotalHT"),'','C');
853
-			}
854
-		}
855
-	}
856
-
857
-	/**
858
-	 *  Show top header of page.
859
-	 *
860
-	 *  @param	PDF			$pdf     		Object PDF
861
-	 *  @param  Object		$object     	Object to show
862
-	 *  @param  int	    	$showaddress    0=no, 1=yes
863
-	 *  @param  Translate	$outputlangs	Object lang for output
864
-	 *  @return	void
865
-	 */
866
-	function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
867
-	{
868
-		global $conf,$langs,$mysoc;
869
-
870
-		$langs->load("orders");
871
-
872
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
873
-
874
-		pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
875
-
876
-		// Show Draft Watermark
877
-		if($object->statut==0 && (! empty($conf->global->SHIPPING_DRAFT_WATERMARK)) )
878
-		{
879
-            		pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->SHIPPING_DRAFT_WATERMARK);
880
-		}
839
+        if (!empty($conf->global->SHIPPING_PDF_DISPLAY_AMOUNT_HT)) {
881 840
 
882
-		//Prepare la suite
883
-		$pdf->SetTextColor(0,0,60);
884
-		$pdf->SetFont('','B', $default_font_size + 3);
841
+            $pdf->line($this->posxpuht-1, $tab_top, $this->posxpuht-1, $tab_top + $tab_height);
842
+            if (empty($hidetop))
843
+            {
844
+                $pdf->SetXY($this->posxpuht-1, $tab_top+1);
845
+                $pdf->MultiCell(($this->posxtotalht - $this->posxpuht), 2, $outputlangs->transnoentities("PriceUHT"),'','C');
846
+            }
885 847
 
886
-		$w = 110;
848
+            $pdf->line($this->posxtotalht-1, $tab_top, $this->posxtotalht-1, $tab_top + $tab_height);
849
+            if (empty($hidetop))
850
+            {
851
+                $pdf->SetXY($this->posxtotalht-1, $tab_top+1);
852
+                $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 2, $outputlangs->transnoentities("TotalHT"),'','C');
853
+            }
854
+        }
855
+    }
887 856
 
888
-		$posy=$this->marge_haute;
889
-		$posx=$this->page_largeur-$this->marge_droite-$w;
857
+    /**
858
+     *  Show top header of page.
859
+     *
860
+     *  @param	PDF			$pdf     		Object PDF
861
+     *  @param  Object		$object     	Object to show
862
+     *  @param  int	    	$showaddress    0=no, 1=yes
863
+     *  @param  Translate	$outputlangs	Object lang for output
864
+     *  @return	void
865
+     */
866
+    function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
867
+    {
868
+        global $conf,$langs,$mysoc;
890 869
 
891
-		$pdf->SetXY($this->marge_gauche,$posy);
870
+        $langs->load("orders");
892 871
 
893
-		// Logo
894
-		$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
895
-		if ($this->emetteur->logo)
896
-		{
897
-			if (is_readable($logo))
898
-			{
899
-			    $height=pdf_getHeightForLogo($logo);
900
-			    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
901
-			}
902
-			else
903
-			{
904
-				$pdf->SetTextColor(200,0,0);
905
-				$pdf->SetFont('','B', $default_font_size - 2);
906
-				$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
907
-				$pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
908
-			}
909
-		}
910
-		else
911
-		{
912
-			$text=$this->emetteur->name;
913
-			$pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
914
-		}
872
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
915 873
 
916
-		// Show barcode
917
-		if (! empty($conf->barcode->enabled))
918
-		{
919
-			$posx=105;
920
-		}
921
-		else
922
-		{
923
-			$posx=$this->marge_gauche+3;
924
-		}
925
-		//$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30);
926
-		if (! empty($conf->barcode->enabled))
927
-		{
928
-			// TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
929
-			//$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
930
-			//$pdf->Image($logo,10, 5, 0, 24);
931
-		}
874
+        pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
932 875
 
933
-		$pdf->SetDrawColor(128,128,128);
934
-		if (! empty($conf->barcode->enabled))
935
-		{
936
-			// TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
937
-			//$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
938
-			//$pdf->Image($logo,10, 5, 0, 24);
939
-		}
876
+        // Show Draft Watermark
877
+        if($object->statut==0 && (! empty($conf->global->SHIPPING_DRAFT_WATERMARK)) )
878
+        {
879
+                    pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->SHIPPING_DRAFT_WATERMARK);
880
+        }
881
+
882
+        //Prepare la suite
883
+        $pdf->SetTextColor(0,0,60);
884
+        $pdf->SetFont('','B', $default_font_size + 3);
885
+
886
+        $w = 110;
887
+
888
+        $posy=$this->marge_haute;
889
+        $posx=$this->page_largeur-$this->marge_droite-$w;
940 890
 
891
+        $pdf->SetXY($this->marge_gauche,$posy);
941 892
 
942
-		$posx=$this->page_largeur - $w - $this->marge_droite;
943
-		$posy=$this->marge_haute;
893
+        // Logo
894
+        $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
895
+        if ($this->emetteur->logo)
896
+        {
897
+            if (is_readable($logo))
898
+            {
899
+                $height=pdf_getHeightForLogo($logo);
900
+                $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
901
+            }
902
+            else
903
+            {
904
+                $pdf->SetTextColor(200,0,0);
905
+                $pdf->SetFont('','B', $default_font_size - 2);
906
+                $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
907
+                $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
908
+            }
909
+        }
910
+        else
911
+        {
912
+            $text=$this->emetteur->name;
913
+            $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
914
+        }
944 915
 
945
-		$pdf->SetFont('','B', $default_font_size + 2);
946
-		$pdf->SetXY($posx,$posy);
947
-		$pdf->SetTextColor(0,0,60);
948
-		$title=$outputlangs->transnoentities("SendingSheet");
949
-		$pdf->MultiCell($w, 4, $title, '', 'R');
916
+        // Show barcode
917
+        if (! empty($conf->barcode->enabled))
918
+        {
919
+            $posx=105;
920
+        }
921
+        else
922
+        {
923
+            $posx=$this->marge_gauche+3;
924
+        }
925
+        //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30);
926
+        if (! empty($conf->barcode->enabled))
927
+        {
928
+            // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
929
+            //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
930
+            //$pdf->Image($logo,10, 5, 0, 24);
931
+        }
950 932
 
951
-		$pdf->SetFont('','', $default_font_size + 1);
933
+        $pdf->SetDrawColor(128,128,128);
934
+        if (! empty($conf->barcode->enabled))
935
+        {
936
+            // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
937
+            //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
938
+            //$pdf->Image($logo,10, 5, 0, 24);
939
+        }
952 940
 
953
-		$posy+=5;
954 941
 
955
-		$pdf->SetXY($posx,$posy);
956
-		$pdf->SetTextColor(0,0,60);
957
-		$pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSending") ." : ".$object->ref, '', 'R');
942
+        $posx=$this->page_largeur - $w - $this->marge_droite;
943
+        $posy=$this->marge_haute;
958 944
 
959
-		// Date planned delivery
960
-		if (! empty($object->date_delivery))
961
-		{
962
-    			$posy+=4;
963
-    			$pdf->SetXY($posx,$posy);
964
-    			$pdf->SetTextColor(0,0,60);
965
-    			$pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery,"day",false,$outputlangs,true), '', 'R');
966
-		}
945
+        $pdf->SetFont('','B', $default_font_size + 2);
946
+        $pdf->SetXY($posx,$posy);
947
+        $pdf->SetTextColor(0,0,60);
948
+        $title=$outputlangs->transnoentities("SendingSheet");
949
+        $pdf->MultiCell($w, 4, $title, '', 'R');
967 950
 
968
-		if (! empty($object->thirdparty->code_client))
969
-		{
970
-			$posy+=4;
971
-			$pdf->SetXY($posx,$posy);
972
-			$pdf->SetTextColor(0,0,60);
973
-			$pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
974
-		}
951
+        $pdf->SetFont('','', $default_font_size + 1);
975 952
 
953
+        $posy+=5;
976 954
 
977
-		$pdf->SetFont('','', $default_font_size + 3);
978
-		$Yoff=25;
955
+        $pdf->SetXY($posx,$posy);
956
+        $pdf->SetTextColor(0,0,60);
957
+        $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSending") ." : ".$object->ref, '', 'R');
979 958
 
980
-		// Add list of linked orders
981
-		$origin 	= $object->origin;
982
-		$origin_id 	= $object->origin_id;
959
+        // Date planned delivery
960
+        if (! empty($object->date_delivery))
961
+        {
962
+                $posy+=4;
963
+                $pdf->SetXY($posx,$posy);
964
+                $pdf->SetTextColor(0,0,60);
965
+                $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery,"day",false,$outputlangs,true), '', 'R');
966
+        }
983 967
 
984
-	    // TODO move to external function
985
-		if (! empty($conf->$origin->enabled))     // commonly $origin='commande'
986
-		{
987
-			$outputlangs->load('orders');
988
-
989
-			$classname = ucfirst($origin);
990
-			$linkedobject = new $classname($this->db);
991
-			$result=$linkedobject->fetch($origin_id);
992
-			if ($result >= 0)
993
-			{
994
-			    //$linkedobject->fetchObjectLinked()   Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects
995
-
996
-				$pdf->SetFont('','', $default_font_size - 2);
997
-				$text=$linkedobject->ref;
998
-				if ($linkedobject->ref_client) $text.=' ('.$linkedobject->ref_client.')';
999
-				$Yoff = $Yoff+8;
1000
-				$pdf->SetXY($this->page_largeur - $this->marge_droite - $w,$Yoff);
1001
-				$pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text), 0, 'R');
1002
-				$Yoff = $Yoff+3;
1003
-				$pdf->SetXY($this->page_largeur - $this->marge_droite - $w,$Yoff);
1004
-				$pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date,"day",false,$outputlangs,true), 0, 'R');
1005
-			}
1006
-		}
1007
-
1008
-		if ($showaddress)
1009
-		{
1010
-			// Sender properties
1011
-			$carac_emetteur='';
1012
-		 	// Add internal contact of origin element if defined
1013
-			$arrayidcontact=array();
1014
-			if (! empty($origin) && is_object($object->$origin)) $arrayidcontact=$object->$origin->getIdContact('internal','SALESREPFOLL');
1015
-		 	if (count($arrayidcontact) > 0)
1016
-		 	{
1017
-		 		$object->fetch_user(reset($arrayidcontact));
1018
-		 		$carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1019
-		 	}
1020
-
1021
-		 	$carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1022
-
1023
-			// Show sender
1024
-			$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1025
-			$posx=$this->marge_gauche;
1026
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1027
-
1028
-			$hautcadre=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1029
-			$widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1030
-
1031
-			// Show sender frame
1032
-			$pdf->SetTextColor(0,0,0);
1033
-			$pdf->SetFont('','', $default_font_size - 2);
1034
-			$pdf->SetXY($posx,$posy-5);
1035
-			$pdf->MultiCell(66,5, $outputlangs->transnoentities("Sender").":", 0, 'L');
1036
-			$pdf->SetXY($posx,$posy);
1037
-			$pdf->SetFillColor(230,230,230);
1038
-			$pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
1039
-			$pdf->SetTextColor(0,0,60);
1040
-			$pdf->SetFillColor(255,255,255);
1041
-
1042
-			// Show sender name
1043
-			$pdf->SetXY($posx+2,$posy+3);
1044
-			$pdf->SetFont('','B',$default_font_size);
1045
-			$pdf->MultiCell($widthrecbox-2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1046
-			$posy=$pdf->getY();
1047
-
1048
-			// Show sender information
1049
-			$pdf->SetXY($posx+2,$posy);
1050
-			$pdf->SetFont('','', $default_font_size - 1);
1051
-			$pdf->MultiCell($widthrecbox-2, 4, $carac_emetteur, 0, 'L');
1052
-
1053
-
1054
-			// If SHIPPING contact defined, we use it
1055
-			$usecontact=false;
1056
-			$arrayidcontact=$object->$origin->getIdContact('external','SHIPPING');
1057
-			if (count($arrayidcontact) > 0)
1058
-			{
1059
-				$usecontact=true;
1060
-				$result=$object->fetch_contact($arrayidcontact[0]);
1061
-			}
1062
-
1063
-			//Recipient name
1064
-			// On peut utiliser le nom de la societe du contact
1065
-			if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
1066
-				$thirdparty = $object->contact;
1067
-			} else {
1068
-				$thirdparty = $object->thirdparty;
1069
-			}
1070
-
1071
-			$carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1072
-
1073
-			$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,(!empty($object->contact)?$object->contact:null),$usecontact,'targetwithdetails',$object);
1074
-
1075
-			// Show recipient
1076
-			$widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1077
-			if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1078
-			$posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1079
-			$posx=$this->page_largeur - $this->marge_droite - $widthrecbox;
1080
-			if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1081
-
1082
-			// Show recipient frame
1083
-			$pdf->SetTextColor(0,0,0);
1084
-			$pdf->SetFont('','', $default_font_size - 2);
1085
-			$pdf->SetXY($posx+2,$posy-5);
1086
-			$pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient").":", 0, 'L');
1087
-			$pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1088
-
1089
-			// Show recipient name
1090
-			$pdf->SetXY($posx+2,$posy+3);
1091
-			$pdf->SetFont('','B', $default_font_size);
1092
-			$pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1093
-
1094
-			$posy = $pdf->getY();
1095
-
1096
-			// Show recipient information
1097
-			$pdf->SetFont('','', $default_font_size - 1);
1098
-			$pdf->SetXY($posx+2,$posy);
1099
-			$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1100
-		}
1101
-
1102
-		$pdf->SetTextColor(0,0,0);
1103
-	}
1104
-
1105
-	/**
1106
-	 *   	Show footer of page. Need this->emetteur object
968
+        if (! empty($object->thirdparty->code_client))
969
+        {
970
+            $posy+=4;
971
+            $pdf->SetXY($posx,$posy);
972
+            $pdf->SetTextColor(0,0,60);
973
+            $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
974
+        }
975
+
976
+
977
+        $pdf->SetFont('','', $default_font_size + 3);
978
+        $Yoff=25;
979
+
980
+        // Add list of linked orders
981
+        $origin 	= $object->origin;
982
+        $origin_id 	= $object->origin_id;
983
+
984
+        // TODO move to external function
985
+        if (! empty($conf->$origin->enabled))     // commonly $origin='commande'
986
+        {
987
+            $outputlangs->load('orders');
988
+
989
+            $classname = ucfirst($origin);
990
+            $linkedobject = new $classname($this->db);
991
+            $result=$linkedobject->fetch($origin_id);
992
+            if ($result >= 0)
993
+            {
994
+                //$linkedobject->fetchObjectLinked()   Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects
995
+
996
+                $pdf->SetFont('','', $default_font_size - 2);
997
+                $text=$linkedobject->ref;
998
+                if ($linkedobject->ref_client) $text.=' ('.$linkedobject->ref_client.')';
999
+                $Yoff = $Yoff+8;
1000
+                $pdf->SetXY($this->page_largeur - $this->marge_droite - $w,$Yoff);
1001
+                $pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text), 0, 'R');
1002
+                $Yoff = $Yoff+3;
1003
+                $pdf->SetXY($this->page_largeur - $this->marge_droite - $w,$Yoff);
1004
+                $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date,"day",false,$outputlangs,true), 0, 'R');
1005
+            }
1006
+        }
1007
+
1008
+        if ($showaddress)
1009
+        {
1010
+            // Sender properties
1011
+            $carac_emetteur='';
1012
+                // Add internal contact of origin element if defined
1013
+            $arrayidcontact=array();
1014
+            if (! empty($origin) && is_object($object->$origin)) $arrayidcontact=$object->$origin->getIdContact('internal','SALESREPFOLL');
1015
+                if (count($arrayidcontact) > 0)
1016
+                {
1017
+                    $object->fetch_user(reset($arrayidcontact));
1018
+                    $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
1019
+                }
1020
+
1021
+                $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
1022
+
1023
+            // Show sender
1024
+            $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1025
+            $posx=$this->marge_gauche;
1026
+            if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
1027
+
1028
+            $hautcadre=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
1029
+            $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
1030
+
1031
+            // Show sender frame
1032
+            $pdf->SetTextColor(0,0,0);
1033
+            $pdf->SetFont('','', $default_font_size - 2);
1034
+            $pdf->SetXY($posx,$posy-5);
1035
+            $pdf->MultiCell(66,5, $outputlangs->transnoentities("Sender").":", 0, 'L');
1036
+            $pdf->SetXY($posx,$posy);
1037
+            $pdf->SetFillColor(230,230,230);
1038
+            $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
1039
+            $pdf->SetTextColor(0,0,60);
1040
+            $pdf->SetFillColor(255,255,255);
1041
+
1042
+            // Show sender name
1043
+            $pdf->SetXY($posx+2,$posy+3);
1044
+            $pdf->SetFont('','B',$default_font_size);
1045
+            $pdf->MultiCell($widthrecbox-2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
1046
+            $posy=$pdf->getY();
1047
+
1048
+            // Show sender information
1049
+            $pdf->SetXY($posx+2,$posy);
1050
+            $pdf->SetFont('','', $default_font_size - 1);
1051
+            $pdf->MultiCell($widthrecbox-2, 4, $carac_emetteur, 0, 'L');
1052
+
1053
+
1054
+            // If SHIPPING contact defined, we use it
1055
+            $usecontact=false;
1056
+            $arrayidcontact=$object->$origin->getIdContact('external','SHIPPING');
1057
+            if (count($arrayidcontact) > 0)
1058
+            {
1059
+                $usecontact=true;
1060
+                $result=$object->fetch_contact($arrayidcontact[0]);
1061
+            }
1062
+
1063
+            //Recipient name
1064
+            // On peut utiliser le nom de la societe du contact
1065
+            if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
1066
+                $thirdparty = $object->contact;
1067
+            } else {
1068
+                $thirdparty = $object->thirdparty;
1069
+            }
1070
+
1071
+            $carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
1072
+
1073
+            $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,(!empty($object->contact)?$object->contact:null),$usecontact,'targetwithdetails',$object);
1074
+
1075
+            // Show recipient
1076
+            $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
1077
+            if ($this->page_largeur < 210) $widthrecbox=84;	// To work with US executive format
1078
+            $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
1079
+            $posx=$this->page_largeur - $this->marge_droite - $widthrecbox;
1080
+            if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
1081
+
1082
+            // Show recipient frame
1083
+            $pdf->SetTextColor(0,0,0);
1084
+            $pdf->SetFont('','', $default_font_size - 2);
1085
+            $pdf->SetXY($posx+2,$posy-5);
1086
+            $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient").":", 0, 'L');
1087
+            $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
1088
+
1089
+            // Show recipient name
1090
+            $pdf->SetXY($posx+2,$posy+3);
1091
+            $pdf->SetFont('','B', $default_font_size);
1092
+            $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
1093
+
1094
+            $posy = $pdf->getY();
1095
+
1096
+            // Show recipient information
1097
+            $pdf->SetFont('','', $default_font_size - 1);
1098
+            $pdf->SetXY($posx+2,$posy);
1099
+            $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
1100
+        }
1101
+
1102
+        $pdf->SetTextColor(0,0,0);
1103
+    }
1104
+
1105
+    /**
1106
+     *   	Show footer of page. Need this->emetteur object
1107 1107
      *
1108
-	 *   	@param	PDF			$pdf     			PDF
1109
-	 * 		@param	Object		$object				Object to show
1110
-	 *      @param	Translate	$outputlangs		Object lang for output
1111
-	 *      @param	int			$hidefreetext		1=Hide free text
1112
-	 *      @return	int								Return height of bottom margin including footer text
1113
-	 */
1114
-	function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1115
-	{
1116
-		global $conf;
1117
-		$showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1118
-		return pdf_pagefoot($pdf,$outputlangs,'SHIPPING_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1119
-	}
1108
+     *   	@param	PDF			$pdf     			PDF
1109
+     * 		@param	Object		$object				Object to show
1110
+     *      @param	Translate	$outputlangs		Object lang for output
1111
+     *      @param	int			$hidefreetext		1=Hide free text
1112
+     *      @return	int								Return height of bottom margin including footer text
1113
+     */
1114
+    function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
1115
+    {
1116
+        global $conf;
1117
+        $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
1118
+        return pdf_pagefoot($pdf,$outputlangs,'SHIPPING_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
1119
+    }
1120 1120
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/expedition/doc/pdf_merou.modules.php 1 patch
Indentation   +590 added lines, -590 removed lines patch added patch discarded remove patch
@@ -42,197 +42,197 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public $db;
44 44
 
45
-	/**
45
+    /**
46 46
      * @var string model name
47 47
      */
48 48
     public $name;
49 49
 
50
-	/**
50
+    /**
51 51
      * @var string model description (short text)
52 52
      */
53 53
     public $description;
54 54
 
55
-	/**
55
+    /**
56 56
      * @var string document type
57 57
      */
58 58
     public $type;
59 59
 
60
-	/**
60
+    /**
61 61
      * @var array() Minimum version of PHP required by module.
62
-	 * e.g.: PHP ≥ 5.4 = array(5, 4)
62
+     * e.g.: PHP ≥ 5.4 = array(5, 4)
63 63
      */
64
-	public $phpmin = array(5, 4);
64
+    public $phpmin = array(5, 4);
65 65
 
66
-	/**
66
+    /**
67 67
      * Dolibarr version of the loaded document
68 68
      * @public string
69 69
      */
70
-	public $version = 'dolibarr';
70
+    public $version = 'dolibarr';
71 71
 
72
-	/**
72
+    /**
73 73
      * @var int page_largeur
74 74
      */
75 75
     public $page_largeur;
76 76
 
77
-	/**
77
+    /**
78 78
      * @var int page_hauteur
79 79
      */
80 80
     public $page_hauteur;
81 81
 
82
-	/**
82
+    /**
83 83
      * @var array format
84 84
      */
85 85
     public $format;
86 86
 
87
-	/**
87
+    /**
88 88
      * @var int marge_gauche
89 89
      */
90
-	public $marge_gauche;
90
+    public $marge_gauche;
91 91
 
92
-	/**
92
+    /**
93 93
      * @var int marge_droite
94 94
      */
95
-	public $marge_droite;
95
+    public $marge_droite;
96 96
 
97
-	/**
97
+    /**
98 98
      * @var int marge_haute
99 99
      */
100
-	public $marge_haute;
100
+    public $marge_haute;
101 101
 
102
-	/**
102
+    /**
103 103
      * @var int marge_basse
104 104
      */
105
-	public $marge_basse;
106
-
107
-	/**
108
-	 * Issuer
109
-	 * @var Societe
110
-	 */
111
-	public $emetteur;
112
-
113
-
114
-	/**
115
-	 *	Constructor
116
-	 *
117
-	 *  @param		DoliDB		$db      Database handler
118
-	 */
119
-	function __construct($db=0)
120
-	{
121
-		global $conf,$langs,$mysoc;
122
-
123
-		$this->db = $db;
124
-		$this->name = "merou";
125
-		$this->description = $langs->trans("DocumentModelMerou");
126
-
127
-		$this->type = 'pdf';
128
-		$formatarray=pdf_getFormat();
129
-		$this->page_largeur = $formatarray['width'];
130
-		$this->page_hauteur = round($formatarray['height']/2);
131
-		$this->format = array($this->page_largeur,$this->page_hauteur);
132
-		$this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
133
-		$this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
134
-		$this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
135
-		$this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
136
-
137
-		$this->option_logo = 1;
138
-
139
-		// Get source company
140
-		$this->emetteur=$mysoc;
141
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
142
-	}
105
+    public $marge_basse;
106
+
107
+    /**
108
+     * Issuer
109
+     * @var Societe
110
+     */
111
+    public $emetteur;
112
+
113
+
114
+    /**
115
+     *	Constructor
116
+     *
117
+     *  @param		DoliDB		$db      Database handler
118
+     */
119
+    function __construct($db=0)
120
+    {
121
+        global $conf,$langs,$mysoc;
122
+
123
+        $this->db = $db;
124
+        $this->name = "merou";
125
+        $this->description = $langs->trans("DocumentModelMerou");
126
+
127
+        $this->type = 'pdf';
128
+        $formatarray=pdf_getFormat();
129
+        $this->page_largeur = $formatarray['width'];
130
+        $this->page_hauteur = round($formatarray['height']/2);
131
+        $this->format = array($this->page_largeur,$this->page_hauteur);
132
+        $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
133
+        $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
134
+        $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
135
+        $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
136
+
137
+        $this->option_logo = 1;
138
+
139
+        // Get source company
140
+        $this->emetteur=$mysoc;
141
+        if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
142
+    }
143 143
 
144 144
 
145 145
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
146
-	/**
147
-	 *	Function to build pdf onto disk
148
-	 *
149
-	 *	@param		Object		$object			Object expedition to generate (or id if old method)
150
-	 *	@param		Translate	$outputlangs		Lang output object
146
+    /**
147
+     *	Function to build pdf onto disk
148
+     *
149
+     *	@param		Object		$object			Object expedition to generate (or id if old method)
150
+     *	@param		Translate	$outputlangs		Lang output object
151 151
      *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
152 152
      *  @param		int			$hidedetails		Do not show line details
153 153
      *  @param		int			$hidedesc			Do not show desc
154 154
      *  @param		int			$hideref			Do not show ref
155 155
      *  @return     int         	    			1=OK, 0=KO
156
-	 */
157
-	function write_file(&$object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
158
-	{
156
+     */
157
+    function write_file(&$object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
158
+    {
159 159
         // phpcs:enable
160
-		global $user,$conf,$langs,$mysoc,$hookmanager;
160
+        global $user,$conf,$langs,$mysoc,$hookmanager;
161 161
 
162
-		$object->fetch_thirdparty();
162
+        $object->fetch_thirdparty();
163 163
 
164
-		if (! is_object($outputlangs)) $outputlangs=$langs;
165
-		// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
166
-		if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
164
+        if (! is_object($outputlangs)) $outputlangs=$langs;
165
+        // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
166
+        if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
167 167
 
168
-		// Load traductions files requiredby by page
169
-		$outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch"));
168
+        // Load traductions files requiredby by page
169
+        $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch"));
170 170
 
171
-		if ($conf->expedition->dir_output)
172
-		{
173
-			$object->fetch_thirdparty();
171
+        if ($conf->expedition->dir_output)
172
+        {
173
+            $object->fetch_thirdparty();
174 174
 
175
-			$origin = $object->origin;
175
+            $origin = $object->origin;
176 176
 
177
-			//Creation de l expediteur
178
-			$this->expediteur = $mysoc;
177
+            //Creation de l expediteur
178
+            $this->expediteur = $mysoc;
179 179
 
180
-			//Creation du destinataire
181
-			$idcontact = $object->$origin->getIdContact('external','SHIPPING');
180
+            //Creation du destinataire
181
+            $idcontact = $object->$origin->getIdContact('external','SHIPPING');
182 182
             $this->destinataire = new Contact($this->db);
183
-			if (! empty($idcontact[0])) $this->destinataire->fetch($idcontact[0]);
184
-
185
-			//Creation du livreur
186
-			$idcontact = $object->$origin->getIdContact('internal','LIVREUR');
187
-			$this->livreur = new User($this->db);
188
-			if (! empty($idcontact[0])) $this->livreur->fetch($idcontact[0]);
189
-
190
-			// Definition de $dir et $file
191
-			if ($object->specimen)
192
-			{
193
-				$dir = $conf->expedition->dir_output."/sending";
194
-				$file = $dir . "/SPECIMEN.pdf";
195
-			}
196
-			else
197
-			{
198
-				$expref = dol_sanitizeFileName($object->ref);
199
-				$dir = $conf->expedition->dir_output . "/sending/" . $expref;
200
-				$file = $dir . "/" . $expref . ".pdf";
201
-			}
202
-
203
-			if (! file_exists($dir))
204
-			{
205
-				if (dol_mkdir($dir) < 0)
206
-				{
207
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
208
-					return 0;
209
-				}
210
-			}
211
-
212
-			if (file_exists($dir))
213
-			{
214
-				// Add pdfgeneration hook
215
-				if (! is_object($hookmanager))
216
-				{
217
-					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
218
-					$hookmanager=new HookManager($this->db);
219
-				}
220
-				$hookmanager->initHooks(array('pdfgeneration'));
221
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
222
-				global $action;
223
-				$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
224
-
225
-				$nblignes = count($object->lines);
226
-
227
-				$pdf=pdf_getInstance($this->format,'mm','l');
228
-				$default_font_size = pdf_getPDFFontSize($outputlangs);
229
-				$heightforinfotot = 0;	// Height reserved to output the info and total part
230
-		        $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5);	// Height reserved to output the free text on last page
231
-	            $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
232
-	            if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
183
+            if (! empty($idcontact[0])) $this->destinataire->fetch($idcontact[0]);
184
+
185
+            //Creation du livreur
186
+            $idcontact = $object->$origin->getIdContact('internal','LIVREUR');
187
+            $this->livreur = new User($this->db);
188
+            if (! empty($idcontact[0])) $this->livreur->fetch($idcontact[0]);
189
+
190
+            // Definition de $dir et $file
191
+            if ($object->specimen)
192
+            {
193
+                $dir = $conf->expedition->dir_output."/sending";
194
+                $file = $dir . "/SPECIMEN.pdf";
195
+            }
196
+            else
197
+            {
198
+                $expref = dol_sanitizeFileName($object->ref);
199
+                $dir = $conf->expedition->dir_output . "/sending/" . $expref;
200
+                $file = $dir . "/" . $expref . ".pdf";
201
+            }
202
+
203
+            if (! file_exists($dir))
204
+            {
205
+                if (dol_mkdir($dir) < 0)
206
+                {
207
+                    $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
208
+                    return 0;
209
+                }
210
+            }
211
+
212
+            if (file_exists($dir))
213
+            {
214
+                // Add pdfgeneration hook
215
+                if (! is_object($hookmanager))
216
+                {
217
+                    include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
218
+                    $hookmanager=new HookManager($this->db);
219
+                }
220
+                $hookmanager->initHooks(array('pdfgeneration'));
221
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
222
+                global $action;
223
+                $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
224
+
225
+                $nblignes = count($object->lines);
226
+
227
+                $pdf=pdf_getInstance($this->format,'mm','l');
228
+                $default_font_size = pdf_getPDFFontSize($outputlangs);
229
+                $heightforinfotot = 0;	// Height reserved to output the info and total part
230
+                $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5);	// Height reserved to output the free text on last page
231
+                $heightforfooter = $this->marge_basse + 8;	// Height reserved to output the footer (value include bottom margin)
232
+                if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6;
233 233
                 $pdf->SetAutoPageBreak(1,0);
234 234
 
235
-			    if (class_exists('TCPDF'))
235
+                if (class_exists('TCPDF'))
236 236
                 {
237 237
                     $pdf->setPrintHeader(false);
238 238
                     $pdf->setPrintFooter(false);
@@ -245,483 +245,483 @@  discard block
 block discarded – undo
245 245
                     $tplidx = $pdf->importPage(1);
246 246
                 }
247 247
 
248
-				$pdf->Open();
249
-				$pagenb=0;
250
-				$pdf->SetDrawColor(128,128,128);
251
-
252
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
253
-
254
-				$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
255
-				$pdf->SetSubject($outputlangs->transnoentities("Shipment"));
256
-				$pdf->SetCreator("Dolibarr ".DOL_VERSION);
257
-				$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
258
-				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Shipment"));
259
-				if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
260
-
261
-				$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
262
-
263
-				// New page
264
-				$pdf->AddPage();
265
-				$pagenb++;
266
-				$this->_pagehead($pdf, $object, 1, $outputlangs);
267
-				$pdf->SetFont('','', $default_font_size - 3);
268
-				$pdf->MultiCell(0, 3, '');		// Set interline to 3
269
-				$pdf->SetTextColor(0,0,0);
270
-
271
-				$tab_top = 52;
272
-				$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
273
-				$tab_height = $this->page_hauteur - $tab_top - $heightforfooter;
274
-				$tab_height_newpage = $this->page_hauteur - $tab_top_newpage - $heightforfooter;
275
-
276
-				// Affiche notes
277
-				if (! empty($object->note_public))
278
-				{
279
-					$pdf->SetFont('','', $default_font_size - 1);
280
-					$pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
281
-					$nexY = $pdf->GetY();
282
-					$height_note=$nexY-$tab_top;
283
-
284
-					// Rect prend une longueur en 3eme param
285
-					$pdf->SetDrawColor(192,192,192);
286
-					$pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
287
-
288
-					$tab_height = $tab_height - $height_note;
289
-					$tab_top = $nexY+6;
290
-				}
291
-				else
292
-				{
293
-					$height_note=0;
294
-				}
295
-
296
-
297
-				$pdf->SetFillColor(240,240,240);
298
-				$pdf->SetTextColor(0,0,0);
299
-				$pdf->SetXY(10, $tab_top + 5);
300
-
301
-				$iniY = $tab_top + 7;
302
-				$curY = $tab_top + 7;
303
-				$nexY = $tab_top + 7;
304
-
305
-				$num=count($object->lines);
306
-				// Loop on each lines
307
-				for ($i = 0; $i < $num; $i++)
308
-				{
309
-					$curY = $nexY;
310
-					$pdf->SetFont('','', $default_font_size - 3);
311
-					$pdf->SetTextColor(0,0,0);
312
-
313
-					$pdf->setTopMargin($tab_top_newpage);
314
-					$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
315
-					$pageposbefore=$pdf->getPage();
316
-
317
-					// Description de la ligne produit
318
-					$libelleproduitservice = pdf_writelinedesc($pdf,$object,$i,$outputlangs,90,3,50,$curY,0,1);
319
-
320
-					$nexY = $pdf->GetY();
321
-					$pageposafter=$pdf->getPage();
322
-					$pdf->setPage($pageposbefore);
323
-					$pdf->setTopMargin($this->marge_haute);
324
-					$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
325
-
326
-					// We suppose that a too long description is moved completely on next page
327
-					if ($pageposafter > $pageposbefore) {
328
-						$pdf->setPage($pageposafter); $curY = $tab_top_newpage;
329
-					}
330
-
331
-					$pdf->SetFont('','', $default_font_size - 3);
332
-
333
-					// Check boxes
334
-					$pdf->SetDrawColor(120,120,120);
335
-					$pdf->Rect(10+3, $curY, 3, 3);
336
-					$pdf->Rect(20+3, $curY, 3, 3);
337
-
338
-					//Insertion de la reference du produit
339
-					$pdf->SetXY(30, $curY);
340
-					$pdf->SetFont('','B', $default_font_size - 3);
341
-					$pdf->MultiCell(24, 3, $outputlangs->convToOutputCharset($object->lines[$i]->ref), 0, 'L', 0);
342
-
343
-					$pdf->SetXY(140, $curY);
344
-					$pdf->MultiCell(30, 3, $object->lines[$i]->qty_asked, 0, 'C', 0);
345
-
346
-					$pdf->SetXY(170, $curY);
347
-					$pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped, 0, 'C', 0);
348
-
349
-					// Add line
350
-					if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
351
-					{
352
-						$pdf->setPage($pageposafter);
353
-						$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
354
-						//$pdf->SetDrawColor(190,190,200);
355
-						$pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
356
-						$pdf->SetLineStyle(array('dash'=>0));
357
-					}
358
-
359
-					$nexY+=2;    // Passe espace entre les lignes
360
-
361
-					// Detect if some page were added automatically and output _tableau for past pages
362
-					while ($pagenb < $pageposafter)
363
-					{
364
-						$pdf->setPage($pagenb);
365
-						if ($pagenb == 1)
366
-						{
367
-							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
368
-						}
369
-						else
370
-						{
371
-							$this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
372
-						}
373
-						$this->_pagefoot($pdf,$object,$outputlangs,1);
374
-						$pagenb++;
375
-						$pdf->setPage($pagenb);
376
-						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
377
-					}
378
-					if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
379
-					{
380
-						if ($pagenb == 1)
381
-						{
382
-							$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
383
-						}
384
-						else
385
-						{
386
-							$this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
387
-						}
388
-						$this->_pagefoot($pdf,$object,$outputlangs,1);
389
-						// New page
390
-						$pdf->AddPage();
391
-						$pagenb++;
392
-					}
393
-				}
394
-
395
-				// Show square
396
-				if ($pagenb == 1)
397
-				{
398
-					$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
399
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
400
-				}
401
-				else
402
-				{
403
-					$this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
404
-					$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
405
-				}
406
-
407
-				// Pied de page
408
-				$this->_pagefoot($pdf, $object, $outputlangs);
409
-				if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
410
-
411
-				$pdf->Close();
412
-
413
-				$pdf->Output($file,'F');
414
-
415
-				// Add pdfgeneration hook
416
-				if (! is_object($hookmanager))
417
-				{
418
-					include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
419
-					$hookmanager=new HookManager($this->db);
420
-				}
421
-				$hookmanager->initHooks(array('pdfgeneration'));
422
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
423
-				global $action;
424
-				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
248
+                $pdf->Open();
249
+                $pagenb=0;
250
+                $pdf->SetDrawColor(128,128,128);
251
+
252
+                if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
253
+
254
+                $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
255
+                $pdf->SetSubject($outputlangs->transnoentities("Shipment"));
256
+                $pdf->SetCreator("Dolibarr ".DOL_VERSION);
257
+                $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
258
+                $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Shipment"));
259
+                if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
260
+
261
+                $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
262
+
263
+                // New page
264
+                $pdf->AddPage();
265
+                $pagenb++;
266
+                $this->_pagehead($pdf, $object, 1, $outputlangs);
267
+                $pdf->SetFont('','', $default_font_size - 3);
268
+                $pdf->MultiCell(0, 3, '');		// Set interline to 3
269
+                $pdf->SetTextColor(0,0,0);
270
+
271
+                $tab_top = 52;
272
+                $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
273
+                $tab_height = $this->page_hauteur - $tab_top - $heightforfooter;
274
+                $tab_height_newpage = $this->page_hauteur - $tab_top_newpage - $heightforfooter;
275
+
276
+                // Affiche notes
277
+                if (! empty($object->note_public))
278
+                {
279
+                    $pdf->SetFont('','', $default_font_size - 1);
280
+                    $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
281
+                    $nexY = $pdf->GetY();
282
+                    $height_note=$nexY-$tab_top;
283
+
284
+                    // Rect prend une longueur en 3eme param
285
+                    $pdf->SetDrawColor(192,192,192);
286
+                    $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
287
+
288
+                    $tab_height = $tab_height - $height_note;
289
+                    $tab_top = $nexY+6;
290
+                }
291
+                else
292
+                {
293
+                    $height_note=0;
294
+                }
295
+
296
+
297
+                $pdf->SetFillColor(240,240,240);
298
+                $pdf->SetTextColor(0,0,0);
299
+                $pdf->SetXY(10, $tab_top + 5);
300
+
301
+                $iniY = $tab_top + 7;
302
+                $curY = $tab_top + 7;
303
+                $nexY = $tab_top + 7;
304
+
305
+                $num=count($object->lines);
306
+                // Loop on each lines
307
+                for ($i = 0; $i < $num; $i++)
308
+                {
309
+                    $curY = $nexY;
310
+                    $pdf->SetFont('','', $default_font_size - 3);
311
+                    $pdf->SetTextColor(0,0,0);
312
+
313
+                    $pdf->setTopMargin($tab_top_newpage);
314
+                    $pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it.
315
+                    $pageposbefore=$pdf->getPage();
316
+
317
+                    // Description de la ligne produit
318
+                    $libelleproduitservice = pdf_writelinedesc($pdf,$object,$i,$outputlangs,90,3,50,$curY,0,1);
319
+
320
+                    $nexY = $pdf->GetY();
321
+                    $pageposafter=$pdf->getPage();
322
+                    $pdf->setPage($pageposbefore);
323
+                    $pdf->setTopMargin($this->marge_haute);
324
+                    $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
325
+
326
+                    // We suppose that a too long description is moved completely on next page
327
+                    if ($pageposafter > $pageposbefore) {
328
+                        $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
329
+                    }
330
+
331
+                    $pdf->SetFont('','', $default_font_size - 3);
332
+
333
+                    // Check boxes
334
+                    $pdf->SetDrawColor(120,120,120);
335
+                    $pdf->Rect(10+3, $curY, 3, 3);
336
+                    $pdf->Rect(20+3, $curY, 3, 3);
337
+
338
+                    //Insertion de la reference du produit
339
+                    $pdf->SetXY(30, $curY);
340
+                    $pdf->SetFont('','B', $default_font_size - 3);
341
+                    $pdf->MultiCell(24, 3, $outputlangs->convToOutputCharset($object->lines[$i]->ref), 0, 'L', 0);
342
+
343
+                    $pdf->SetXY(140, $curY);
344
+                    $pdf->MultiCell(30, 3, $object->lines[$i]->qty_asked, 0, 'C', 0);
345
+
346
+                    $pdf->SetXY(170, $curY);
347
+                    $pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped, 0, 'C', 0);
348
+
349
+                    // Add line
350
+                    if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
351
+                    {
352
+                        $pdf->setPage($pageposafter);
353
+                        $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
354
+                        //$pdf->SetDrawColor(190,190,200);
355
+                        $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
356
+                        $pdf->SetLineStyle(array('dash'=>0));
357
+                    }
358
+
359
+                    $nexY+=2;    // Passe espace entre les lignes
360
+
361
+                    // Detect if some page were added automatically and output _tableau for past pages
362
+                    while ($pagenb < $pageposafter)
363
+                    {
364
+                        $pdf->setPage($pagenb);
365
+                        if ($pagenb == 1)
366
+                        {
367
+                            $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
368
+                        }
369
+                        else
370
+                        {
371
+                            $this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
372
+                        }
373
+                        $this->_pagefoot($pdf,$object,$outputlangs,1);
374
+                        $pagenb++;
375
+                        $pdf->setPage($pagenb);
376
+                        $pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it.
377
+                    }
378
+                    if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
379
+                    {
380
+                        if ($pagenb == 1)
381
+                        {
382
+                            $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
383
+                        }
384
+                        else
385
+                        {
386
+                            $this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
387
+                        }
388
+                        $this->_pagefoot($pdf,$object,$outputlangs,1);
389
+                        // New page
390
+                        $pdf->AddPage();
391
+                        $pagenb++;
392
+                    }
393
+                }
394
+
395
+                // Show square
396
+                if ($pagenb == 1)
397
+                {
398
+                    $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
399
+                    $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
400
+                }
401
+                else
402
+                {
403
+                    $this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
404
+                    $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
405
+                }
406
+
407
+                // Pied de page
408
+                $this->_pagefoot($pdf, $object, $outputlangs);
409
+                if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
410
+
411
+                $pdf->Close();
412
+
413
+                $pdf->Output($file,'F');
414
+
415
+                // Add pdfgeneration hook
416
+                if (! is_object($hookmanager))
417
+                {
418
+                    include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
419
+                    $hookmanager=new HookManager($this->db);
420
+                }
421
+                $hookmanager->initHooks(array('pdfgeneration'));
422
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
423
+                global $action;
424
+                $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
425 425
 
426 426
                 if (! empty($conf->global->MAIN_UMASK))
427 427
                     @chmod($file, octdec($conf->global->MAIN_UMASK));
428 428
 
429
-				$this->result = array('fullpath'=>$file);
430
-
431
-				return 1;
432
-			}
433
-			else
434
-			{
435
-				$this->error=$outputlangs->transnoentities("ErrorCanNotCreateDir",$dir);
436
-				return 0;
437
-			}
438
-		}
439
-		else
440
-		{
441
-			$this->error=$outputlangs->transnoentities("ErrorConstantNotDefined","EXP_OUTPUTDIR");
442
-			return 0;
443
-		}
444
-	}
445
-
446
-	/**
447
-	 *   Show table for lines
448
-	 *
449
-	 *   @param		PDF			$pdf     		Object PDF
450
-	 *   @param		string		$tab_top		Top position of table
451
-	 *   @param		string		$tab_height		Height of table (rectangle)
452
-	 *   @param		int			$nexY			Y
453
-	 *   @param		Translate	$outputlangs	Langs object
454
-	 *   @param		int			$hidetop		Hide top bar of array
455
-	 *   @param		int			$hidebottom		Hide bottom bar of array
456
-	 *   @return	void
457
-	 */
458
-	function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
459
-	{
460
-		global $langs;
461
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
462
-
463
-		// Translations
464
-		$langs->loadLangs(array("main", "bills"));
465
-
466
-		if (empty($hidetop))
467
-		{
468
-			$pdf->SetFont('','B', $default_font_size - 2);
469
-			$pdf->SetXY(10,$tab_top);
470
-			$pdf->MultiCell(10,5,"LS",0,'C',1);
471
-			$pdf->line(20, $tab_top, 20, $tab_top + $tab_height);
472
-			$pdf->SetXY(20,$tab_top);
473
-			$pdf->MultiCell(10,5,"LR",0,'C',1);
474
-			$pdf->line(30, $tab_top, 30, $tab_top + $tab_height);
475
-			$pdf->SetXY(30,$tab_top);
476
-			$pdf->MultiCell(20,5,$outputlangs->transnoentities("Ref"),0,'C',1);
477
-			$pdf->SetXY(50,$tab_top);
478
-			$pdf->MultiCell(90,5,$outputlangs->transnoentities("Description"),0,'L',1);
479
-			$pdf->SetXY(140,$tab_top);
480
-			$pdf->MultiCell(30,5,$outputlangs->transnoentities("QtyOrdered"),0,'C',1);
481
-			$pdf->SetXY(170,$tab_top);
482
-			$pdf->MultiCell(30,5,$outputlangs->transnoentities("QtyToShip"),0,'C',1);
483
-		}
484
-		$pdf->Rect(10, $tab_top, 190, $tab_height);
485
-	}
486
-
487
-	/**
488
-	 *   	Show footer of page. Need this->emetteur object
429
+                $this->result = array('fullpath'=>$file);
430
+
431
+                return 1;
432
+            }
433
+            else
434
+            {
435
+                $this->error=$outputlangs->transnoentities("ErrorCanNotCreateDir",$dir);
436
+                return 0;
437
+            }
438
+        }
439
+        else
440
+        {
441
+            $this->error=$outputlangs->transnoentities("ErrorConstantNotDefined","EXP_OUTPUTDIR");
442
+            return 0;
443
+        }
444
+    }
445
+
446
+    /**
447
+     *   Show table for lines
448
+     *
449
+     *   @param		PDF			$pdf     		Object PDF
450
+     *   @param		string		$tab_top		Top position of table
451
+     *   @param		string		$tab_height		Height of table (rectangle)
452
+     *   @param		int			$nexY			Y
453
+     *   @param		Translate	$outputlangs	Langs object
454
+     *   @param		int			$hidetop		Hide top bar of array
455
+     *   @param		int			$hidebottom		Hide bottom bar of array
456
+     *   @return	void
457
+     */
458
+    function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
459
+    {
460
+        global $langs;
461
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
462
+
463
+        // Translations
464
+        $langs->loadLangs(array("main", "bills"));
465
+
466
+        if (empty($hidetop))
467
+        {
468
+            $pdf->SetFont('','B', $default_font_size - 2);
469
+            $pdf->SetXY(10,$tab_top);
470
+            $pdf->MultiCell(10,5,"LS",0,'C',1);
471
+            $pdf->line(20, $tab_top, 20, $tab_top + $tab_height);
472
+            $pdf->SetXY(20,$tab_top);
473
+            $pdf->MultiCell(10,5,"LR",0,'C',1);
474
+            $pdf->line(30, $tab_top, 30, $tab_top + $tab_height);
475
+            $pdf->SetXY(30,$tab_top);
476
+            $pdf->MultiCell(20,5,$outputlangs->transnoentities("Ref"),0,'C',1);
477
+            $pdf->SetXY(50,$tab_top);
478
+            $pdf->MultiCell(90,5,$outputlangs->transnoentities("Description"),0,'L',1);
479
+            $pdf->SetXY(140,$tab_top);
480
+            $pdf->MultiCell(30,5,$outputlangs->transnoentities("QtyOrdered"),0,'C',1);
481
+            $pdf->SetXY(170,$tab_top);
482
+            $pdf->MultiCell(30,5,$outputlangs->transnoentities("QtyToShip"),0,'C',1);
483
+        }
484
+        $pdf->Rect(10, $tab_top, 190, $tab_height);
485
+    }
486
+
487
+    /**
488
+     *   	Show footer of page. Need this->emetteur object
489 489
      *
490
-	 *   	@param	PDF			$pdf     			PDF
491
-	 * 		@param	Object		$object				Object to show
492
-	 *      @param	Translate	$outputlangs		Object lang for output
493
-	 *      @param	int			$hidefreetext		1=Hide free text
494
-	 *      @return	void
495
-	 */
496
-	function _pagefoot(&$pdf, $object, $outputlangs,$hidefreetext=0)
497
-	{
498
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
499
-		$pdf->SetFont('','', $default_font_size - 2);
500
-		$pdf->SetY(-23);
501
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("GoodStatusDeclaration"), 0, 'L');
502
-		$pdf->SetY(-13);
503
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ToAndDate"), 0, 'C');
504
-		$pdf->SetXY(120,-23);
505
-		$pdf->MultiCell(100, 3, $outputlangs->transnoentities("NameAndSignature"), 0, 'C');
506
-
507
-		// Show page nb only on iso languages (so default Helvetica font)
490
+     *   	@param	PDF			$pdf     			PDF
491
+     * 		@param	Object		$object				Object to show
492
+     *      @param	Translate	$outputlangs		Object lang for output
493
+     *      @param	int			$hidefreetext		1=Hide free text
494
+     *      @return	void
495
+     */
496
+    function _pagefoot(&$pdf, $object, $outputlangs,$hidefreetext=0)
497
+    {
498
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
499
+        $pdf->SetFont('','', $default_font_size - 2);
500
+        $pdf->SetY(-23);
501
+        $pdf->MultiCell(100, 3, $outputlangs->transnoentities("GoodStatusDeclaration"), 0, 'L');
502
+        $pdf->SetY(-13);
503
+        $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ToAndDate"), 0, 'C');
504
+        $pdf->SetXY(120,-23);
505
+        $pdf->MultiCell(100, 3, $outputlangs->transnoentities("NameAndSignature"), 0, 'C');
506
+
507
+        // Show page nb only on iso languages (so default Helvetica font)
508 508
         //if (pdf_getPDFFont($outputlangs) == 'Helvetica')
509 509
         //{
510
-    	//    $pdf->SetXY(-10,-10);
510
+        //    $pdf->SetXY(-10,-10);
511 511
         //    $pdf->MultiCell(11, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0);
512 512
         //}
513
-	}
513
+    }
514 514
 
515 515
 
516
-	/**
517
-	 *  Show top header of page.
518
-	 *
519
-	 *  @param	PDF			$pdf     		Object PDF
520
-	 *  @param  Object		$object     	Object to show
521
-	 *  @param  int	    	$showaddress    0=no, 1=yes
522
-	 *  @param  Translate	$outputlangs	Object lang for output
523
-	 *  @return	void
524
-	 */
525
-	function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
526
-	{
527
-		global $conf, $langs,$hookmanager;
516
+    /**
517
+     *  Show top header of page.
518
+     *
519
+     *  @param	PDF			$pdf     		Object PDF
520
+     *  @param  Object		$object     	Object to show
521
+     *  @param  int	    	$showaddress    0=no, 1=yes
522
+     *  @param  Translate	$outputlangs	Object lang for output
523
+     *  @return	void
524
+     */
525
+    function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
526
+    {
527
+        global $conf, $langs,$hookmanager;
528 528
 
529
-		$default_font_size = pdf_getPDFFontSize($outputlangs);
529
+        $default_font_size = pdf_getPDFFontSize($outputlangs);
530 530
 
531
-		pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
531
+        pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
532 532
 
533
-			//Affiche le filigrane brouillon - Print Draft Watermark
534
-		if($object->statut==0 && (! empty($conf->global->SENDING_DRAFT_WATERMARK)) )
535
-		{
533
+            //Affiche le filigrane brouillon - Print Draft Watermark
534
+        if($object->statut==0 && (! empty($conf->global->SENDING_DRAFT_WATERMARK)) )
535
+        {
536 536
             pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->SENDING_DRAFT_WATERMARK);
537
-		}
537
+        }
538 538
 
539 539
         $posy=$this->marge_haute;
540 540
         $posx=$this->page_largeur-$this->marge_droite-100;
541 541
 
542
-		$Xoff = 90;
543
-		$Yoff = 0;
544
-
545
-		$tab4_top = 60;
546
-		$tab4_hl = 6;
547
-		$tab4_sl = 4;
548
-		$line = 2;
549
-
550
-		//*********************LOGO****************************
551
-		$pdf->SetXY(11,7);
552
-		$logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
553
-		if ($this->emetteur->logo)
554
-		{
555
-			if (is_readable($logo))
556
-			{
557
-			    $height=pdf_getHeightForLogo($logo);
558
-			    $pdf->Image($logo,10, 5, 0, $height);	// width=0 (auto)
559
-			}
560
-			else
561
-			{
562
-				$pdf->SetTextColor(200,0,0);
563
-				$pdf->SetFont('','B', $default_font_size - 2);
564
-				$pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
565
-				$pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
566
-			}
567
-		}
568
-		else
569
-		{
570
-			$text=$this->emetteur->name;
571
-			$pdf->MultiCell(70, 3, $outputlangs->convToOutputCharset($text), 0, 'L');
572
-		}
573
-
574
-		//*********************Entete****************************
575
-		//Nom du Document
576
-		$pdf->SetXY($Xoff,7);
577
-		$pdf->SetFont('','B', $default_font_size + 2);
578
-		$pdf->SetTextColor(0,0,0);
579
-		$pdf->MultiCell(0, 3, $outputlangs->transnoentities("SendingSheet"), '', 'L');	// Bordereau expedition
580
-		//Num Expedition
581
-		$Yoff = $Yoff+7;
582
-		$Xoff = 142;
583
-		//$pdf->Rect($Xoff, $Yoff, 85, 8);
584
-		$pdf->SetXY($Xoff,$Yoff);
585
-		$pdf->SetFont('','', $default_font_size - 2);
586
-		$pdf->SetTextColor(0,0,0);
587
-		$pdf->MultiCell(0, 3, $outputlangs->transnoentities("RefSending").': '.$outputlangs->convToOutputCharset($object->ref), '', 'R');
588
-		//$this->Code39($Xoff+43, $Yoff+1, $object->ref,$ext = true, $cks = false, $w = 0.4, $h = 4, $wide = true);
589
-
590
-		$origin 	= $object->origin;
591
-		$origin_id 	= $object->origin_id;
592
-
593
-		// Add list of linked elements
594
-		$posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size - 1, $hookmanager);
595
-
596
-		//$this->Code39($Xoff+43, $Yoff+1, $object->commande->ref,$ext = true, $cks = false, $w = 0.4, $h = 4, $wide = true);
597
-		//Definition Emplacement du bloc Societe
598
-		$Xoff = 110;
599
-		$blSocX=90;
600
-		$blSocY=24;
601
-		$blSocW=50;
602
-		$blSocX2=$blSocW+$blSocX;
603
-
604
-		// Sender name
605
-		$pdf->SetTextColor(0,0,0);
606
-		$pdf->SetFont('','B', $default_font_size - 3);
607
-		$pdf->SetXY($blSocX,$blSocY+1);
608
-		$pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
609
-		$pdf->SetTextColor(0,0,0);
610
-
611
-		// Sender properties
612
-		$carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
613
-
614
-		$pdf->SetFont('','', $default_font_size - 3);
615
-		$pdf->SetXY($blSocX,$blSocY+4);
616
-		$pdf->MultiCell(80, 2, $carac_emetteur, 0, 'L');
617
-
618
-
619
-		if ($object->thirdparty->code_client)
620
-		{
621
-			$Yoff+=3;
622
-			$posy=$Yoff;
623
-			$pdf->SetXY(100,$posy);
624
-			$pdf->SetTextColor(0,0,0);
625
-			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
626
-		}
627
-
628
-		// Date Expedition
629
-		$Yoff = $Yoff+7;
630
-		$pdf->SetXY($blSocX-80,$blSocY+17);
631
-
632
-		$pdf->SetFont('','B', $default_font_size - 3);
633
-		$pdf->SetTextColor(0,0,0);
634
-		$pdf->MultiCell(50, 8, $outputlangs->transnoentities("DateDeliveryPlanned")." : " . dol_print_date($object->date_delivery,'day',false,$outputlangs,true), '', 'L');
635
-
636
-		$pdf->SetXY($blSocX-80,$blSocY+20);
637
-		$pdf->SetFont('','B', $default_font_size - 3);
638
-		$pdf->SetTextColor(0,0,0);
639
-		$pdf->MultiCell(50, 8, $outputlangs->transnoentities("TrackingNumber")." : " . $object->tracking_number, '', 'L');
640
-
641
-		// Deliverer
642
-		$pdf->SetXY($blSocX-80,$blSocY+23);
643
-		$pdf->SetFont('','', $default_font_size - 3);
644
-		$pdf->SetTextColor(0,0,0);
645
-
646
-		if (! empty($object->tracking_number))
647
-		{
648
-			$object->getUrlTrackingStatus($object->tracking_number);
649
-			if (! empty($object->tracking_url))
650
-			{
651
-				if ($object->shipping_method_id > 0)
652
-				{
653
-					// Get code using getLabelFromKey
654
-					$code=$outputlangs->getLabelFromKey($this->db,$object->shipping_method_id,'c_shipment_mode','rowid','code');
655
-
656
-					$label='';
657
-					$label.=$outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code));
658
-					//var_dump($object->tracking_url != $object->tracking_number);exit;
659
-					if ($object->tracking_url != $object->tracking_number)
660
-					{
661
-						$label.=" : ";
662
-						$label.=$object->tracking_url;
663
-					}
664
-					$pdf->SetFont('','B', $default_font_size - 3);
665
-					$pdf->writeHTMLCell(50, 8, '', '', $label, '', 'L');
666
-				}
667
-			}
668
-		}
669
-		else
670
-		{
671
-			$pdf->MultiCell(50, 8, $outputlangs->transnoentities("Deliverer")." ".$outputlangs->convToOutputCharset($this->livreur->getFullName($outputlangs)), '', 'L');
672
-		}
673
-
674
-
675
-		// Shipping company (My Company)
676
-		$Yoff = $blSocY;
677
-		$blExpX=$Xoff-20;
678
-		$blW=52;
679
-		$Ydef = $Yoff;
680
-		$pdf->Rect($blExpX, $Yoff, $blW, 26);
681
-
682
-		$object->fetch_thirdparty();
683
-
684
-		// If SHIPPING contact defined on order, we use it
685
-		$usecontact=false;
686
-		$arrayidcontact=$object->$origin->getIdContact('external','SHIPPING');
687
-		if (count($arrayidcontact) > 0)
688
-		{
689
-			$usecontact=true;
690
-			$result=$object->fetch_contact($arrayidcontact[0]);
691
-		}
692
-
693
-		// Recipient name
694
-		// On peut utiliser le nom de la societe du contact
695
-		if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
696
-			$thirdparty = $object->contact;
697
-		} else {
698
-			$thirdparty = $object->thirdparty;
699
-		}
700
-
701
-		$carac_client_name=pdfBuildThirdpartyName($thirdparty, $outputlangs);
702
-
703
-		$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,((!empty($object->contact))?$object->contact:null),$usecontact,'targetwithdetails',$object);
704
-
705
-		$blDestX=$blExpX+55;
706
-		$blW=54;
707
-		$Yoff = $Ydef +1;
708
-
709
-		// Show Recipient frame
710
-		$pdf->SetFont('','B', $default_font_size - 3);
711
-		$pdf->SetXY($blDestX,$Yoff-4);
712
-		$pdf->MultiCell($blW,3, $outputlangs->transnoentities("Recipient"), 0, 'L');
713
-		$pdf->Rect($blDestX, $Yoff-1, $blW, 26);
714
-
715
-		// Show recipient name
716
-		$pdf->SetFont('','B', $default_font_size - 3);
717
-		$pdf->SetXY($blDestX,$Yoff);
718
-		$pdf->MultiCell($blW,3, $carac_client_name, 0, 'L');
719
-
720
-		$posy = $pdf->getY();
721
-
722
-		// Show recipient information
723
-		$pdf->SetFont('','', $default_font_size - 3);
724
-		$pdf->SetXY($blDestX,$posy);
725
-		$pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
726
-	}
542
+        $Xoff = 90;
543
+        $Yoff = 0;
544
+
545
+        $tab4_top = 60;
546
+        $tab4_hl = 6;
547
+        $tab4_sl = 4;
548
+        $line = 2;
549
+
550
+        //*********************LOGO****************************
551
+        $pdf->SetXY(11,7);
552
+        $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
553
+        if ($this->emetteur->logo)
554
+        {
555
+            if (is_readable($logo))
556
+            {
557
+                $height=pdf_getHeightForLogo($logo);
558
+                $pdf->Image($logo,10, 5, 0, $height);	// width=0 (auto)
559
+            }
560
+            else
561
+            {
562
+                $pdf->SetTextColor(200,0,0);
563
+                $pdf->SetFont('','B', $default_font_size - 2);
564
+                $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
565
+                $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
566
+            }
567
+        }
568
+        else
569
+        {
570
+            $text=$this->emetteur->name;
571
+            $pdf->MultiCell(70, 3, $outputlangs->convToOutputCharset($text), 0, 'L');
572
+        }
573
+
574
+        //*********************Entete****************************
575
+        //Nom du Document
576
+        $pdf->SetXY($Xoff,7);
577
+        $pdf->SetFont('','B', $default_font_size + 2);
578
+        $pdf->SetTextColor(0,0,0);
579
+        $pdf->MultiCell(0, 3, $outputlangs->transnoentities("SendingSheet"), '', 'L');	// Bordereau expedition
580
+        //Num Expedition
581
+        $Yoff = $Yoff+7;
582
+        $Xoff = 142;
583
+        //$pdf->Rect($Xoff, $Yoff, 85, 8);
584
+        $pdf->SetXY($Xoff,$Yoff);
585
+        $pdf->SetFont('','', $default_font_size - 2);
586
+        $pdf->SetTextColor(0,0,0);
587
+        $pdf->MultiCell(0, 3, $outputlangs->transnoentities("RefSending").': '.$outputlangs->convToOutputCharset($object->ref), '', 'R');
588
+        //$this->Code39($Xoff+43, $Yoff+1, $object->ref,$ext = true, $cks = false, $w = 0.4, $h = 4, $wide = true);
589
+
590
+        $origin 	= $object->origin;
591
+        $origin_id 	= $object->origin_id;
592
+
593
+        // Add list of linked elements
594
+        $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size - 1, $hookmanager);
595
+
596
+        //$this->Code39($Xoff+43, $Yoff+1, $object->commande->ref,$ext = true, $cks = false, $w = 0.4, $h = 4, $wide = true);
597
+        //Definition Emplacement du bloc Societe
598
+        $Xoff = 110;
599
+        $blSocX=90;
600
+        $blSocY=24;
601
+        $blSocW=50;
602
+        $blSocX2=$blSocW+$blSocX;
603
+
604
+        // Sender name
605
+        $pdf->SetTextColor(0,0,0);
606
+        $pdf->SetFont('','B', $default_font_size - 3);
607
+        $pdf->SetXY($blSocX,$blSocY+1);
608
+        $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
609
+        $pdf->SetTextColor(0,0,0);
610
+
611
+        // Sender properties
612
+        $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
613
+
614
+        $pdf->SetFont('','', $default_font_size - 3);
615
+        $pdf->SetXY($blSocX,$blSocY+4);
616
+        $pdf->MultiCell(80, 2, $carac_emetteur, 0, 'L');
617
+
618
+
619
+        if ($object->thirdparty->code_client)
620
+        {
621
+            $Yoff+=3;
622
+            $posy=$Yoff;
623
+            $pdf->SetXY(100,$posy);
624
+            $pdf->SetTextColor(0,0,0);
625
+            $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
626
+        }
627
+
628
+        // Date Expedition
629
+        $Yoff = $Yoff+7;
630
+        $pdf->SetXY($blSocX-80,$blSocY+17);
631
+
632
+        $pdf->SetFont('','B', $default_font_size - 3);
633
+        $pdf->SetTextColor(0,0,0);
634
+        $pdf->MultiCell(50, 8, $outputlangs->transnoentities("DateDeliveryPlanned")." : " . dol_print_date($object->date_delivery,'day',false,$outputlangs,true), '', 'L');
635
+
636
+        $pdf->SetXY($blSocX-80,$blSocY+20);
637
+        $pdf->SetFont('','B', $default_font_size - 3);
638
+        $pdf->SetTextColor(0,0,0);
639
+        $pdf->MultiCell(50, 8, $outputlangs->transnoentities("TrackingNumber")." : " . $object->tracking_number, '', 'L');
640
+
641
+        // Deliverer
642
+        $pdf->SetXY($blSocX-80,$blSocY+23);
643
+        $pdf->SetFont('','', $default_font_size - 3);
644
+        $pdf->SetTextColor(0,0,0);
645
+
646
+        if (! empty($object->tracking_number))
647
+        {
648
+            $object->getUrlTrackingStatus($object->tracking_number);
649
+            if (! empty($object->tracking_url))
650
+            {
651
+                if ($object->shipping_method_id > 0)
652
+                {
653
+                    // Get code using getLabelFromKey
654
+                    $code=$outputlangs->getLabelFromKey($this->db,$object->shipping_method_id,'c_shipment_mode','rowid','code');
655
+
656
+                    $label='';
657
+                    $label.=$outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code));
658
+                    //var_dump($object->tracking_url != $object->tracking_number);exit;
659
+                    if ($object->tracking_url != $object->tracking_number)
660
+                    {
661
+                        $label.=" : ";
662
+                        $label.=$object->tracking_url;
663
+                    }
664
+                    $pdf->SetFont('','B', $default_font_size - 3);
665
+                    $pdf->writeHTMLCell(50, 8, '', '', $label, '', 'L');
666
+                }
667
+            }
668
+        }
669
+        else
670
+        {
671
+            $pdf->MultiCell(50, 8, $outputlangs->transnoentities("Deliverer")." ".$outputlangs->convToOutputCharset($this->livreur->getFullName($outputlangs)), '', 'L');
672
+        }
673
+
674
+
675
+        // Shipping company (My Company)
676
+        $Yoff = $blSocY;
677
+        $blExpX=$Xoff-20;
678
+        $blW=52;
679
+        $Ydef = $Yoff;
680
+        $pdf->Rect($blExpX, $Yoff, $blW, 26);
681
+
682
+        $object->fetch_thirdparty();
683
+
684
+        // If SHIPPING contact defined on order, we use it
685
+        $usecontact=false;
686
+        $arrayidcontact=$object->$origin->getIdContact('external','SHIPPING');
687
+        if (count($arrayidcontact) > 0)
688
+        {
689
+            $usecontact=true;
690
+            $result=$object->fetch_contact($arrayidcontact[0]);
691
+        }
692
+
693
+        // Recipient name
694
+        // On peut utiliser le nom de la societe du contact
695
+        if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
696
+            $thirdparty = $object->contact;
697
+        } else {
698
+            $thirdparty = $object->thirdparty;
699
+        }
700
+
701
+        $carac_client_name=pdfBuildThirdpartyName($thirdparty, $outputlangs);
702
+
703
+        $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,((!empty($object->contact))?$object->contact:null),$usecontact,'targetwithdetails',$object);
704
+
705
+        $blDestX=$blExpX+55;
706
+        $blW=54;
707
+        $Yoff = $Ydef +1;
708
+
709
+        // Show Recipient frame
710
+        $pdf->SetFont('','B', $default_font_size - 3);
711
+        $pdf->SetXY($blDestX,$Yoff-4);
712
+        $pdf->MultiCell($blW,3, $outputlangs->transnoentities("Recipient"), 0, 'L');
713
+        $pdf->Rect($blDestX, $Yoff-1, $blW, 26);
714
+
715
+        // Show recipient name
716
+        $pdf->SetFont('','B', $default_font_size - 3);
717
+        $pdf->SetXY($blDestX,$Yoff);
718
+        $pdf->MultiCell($blW,3, $carac_client_name, 0, 'L');
719
+
720
+        $posy = $pdf->getY();
721
+
722
+        // Show recipient information
723
+        $pdf->SetFont('','', $default_font_size - 3);
724
+        $pdf->SetXY($blDestX,$posy);
725
+        $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
726
+    }
727 727
 }
Please login to merge, or discard this patch.
htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php 1 patch
Indentation   +520 added lines, -520 removed lines patch added patch discarded remove patch
@@ -40,550 +40,550 @@
 block discarded – undo
40 40
  */
41 41
 class doc_generic_shipment_odt extends ModelePdfExpedition
42 42
 {
43
-	/**
44
-	 * Issuer
45
-	 * @var Societe
46
-	 */
47
-	public $emetteur;
48
-
49
-	/**
50
-   * @var array() Minimum version of PHP required by module.
51
-	 * e.g.: PHP ≥ 5.4 = array(5, 4)
52
-   */
53
-	public $phpmin = array(5, 4);
54
-
55
-	/**
43
+    /**
44
+     * Issuer
45
+     * @var Societe
46
+     */
47
+    public $emetteur;
48
+
49
+    /**
50
+     * @var array() Minimum version of PHP required by module.
51
+     * e.g.: PHP ≥ 5.4 = array(5, 4)
52
+     */
53
+    public $phpmin = array(5, 4);
54
+
55
+    /**
56 56
      * Dolibarr version of the loaded document
57 57
      * @public string
58 58
      */
59
-	public $version = 'dolibarr';
59
+    public $version = 'dolibarr';
60 60
 
61 61
 
62
-	/**
63
-	 *	Constructor
64
-	 *
65
-	 *  @param		DoliDB		$db      Database handler
66
-	 */
67
-	function __construct($db)
68
-	{
69
-		global $conf, $langs, $mysoc;
62
+    /**
63
+     *	Constructor
64
+     *
65
+     *  @param		DoliDB		$db      Database handler
66
+     */
67
+    function __construct($db)
68
+    {
69
+        global $conf, $langs, $mysoc;
70 70
 
71
-		// Load translation files required by the page
71
+        // Load translation files required by the page
72 72
         $langs->loadLangs(array("main","companies"));
73 73
 
74
-		$this->db = $db;
75
-		$this->name = "ODT templates";
76
-		$this->description = $langs->trans("DocumentModelOdt");
77
-		$this->scandir = 'EXPEDITION_ADDON_PDF_ODT_PATH';	// Name of constant that is used to save list of directories to scan
78
-
79
-		// Dimension page pour format A4
80
-		$this->type = 'odt';
81
-		$this->page_largeur = 0;
82
-		$this->page_hauteur = 0;
83
-		$this->format = array($this->page_largeur,$this->page_hauteur);
84
-		$this->marge_gauche=0;
85
-		$this->marge_droite=0;
86
-		$this->marge_haute=0;
87
-		$this->marge_basse=0;
88
-
89
-		$this->option_logo = 1;                    // Affiche logo
90
-		$this->option_tva = 0;                     // Gere option tva EXPEDITION_TVAOPTION
91
-		$this->option_modereg = 0;                 // Affiche mode reglement
92
-		$this->option_condreg = 0;                 // Affiche conditions reglement
93
-		$this->option_codeproduitservice = 0;      // Affiche code produit-service
94
-		$this->option_multilang = 1;               // Dispo en plusieurs langues
95
-		$this->option_escompte = 0;                // Affiche si il y a eu escompte
96
-		$this->option_credit_note = 0;             // Support credit notes
97
-		$this->option_freetext = 1;				   // Support add of a personalised text
98
-		$this->option_draft_watermark = 0;		   // Support add of a watermark on drafts
99
-
100
-		// Recupere emetteur
101
-		$this->emetteur=$mysoc;
102
-		if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
103
-	}
104
-
105
-
106
-	/**
107
-	 *	Return description of a module
108
-	 *
109
-	 *	@param	Translate	$langs      Lang object to use for output
110
-	 *	@return string       			Description
111
-	 */
112
-	function info($langs)
113
-	{
114
-		global $conf,$langs;
115
-
116
-		// Load translation files required by the page
74
+        $this->db = $db;
75
+        $this->name = "ODT templates";
76
+        $this->description = $langs->trans("DocumentModelOdt");
77
+        $this->scandir = 'EXPEDITION_ADDON_PDF_ODT_PATH';	// Name of constant that is used to save list of directories to scan
78
+
79
+        // Dimension page pour format A4
80
+        $this->type = 'odt';
81
+        $this->page_largeur = 0;
82
+        $this->page_hauteur = 0;
83
+        $this->format = array($this->page_largeur,$this->page_hauteur);
84
+        $this->marge_gauche=0;
85
+        $this->marge_droite=0;
86
+        $this->marge_haute=0;
87
+        $this->marge_basse=0;
88
+
89
+        $this->option_logo = 1;                    // Affiche logo
90
+        $this->option_tva = 0;                     // Gere option tva EXPEDITION_TVAOPTION
91
+        $this->option_modereg = 0;                 // Affiche mode reglement
92
+        $this->option_condreg = 0;                 // Affiche conditions reglement
93
+        $this->option_codeproduitservice = 0;      // Affiche code produit-service
94
+        $this->option_multilang = 1;               // Dispo en plusieurs langues
95
+        $this->option_escompte = 0;                // Affiche si il y a eu escompte
96
+        $this->option_credit_note = 0;             // Support credit notes
97
+        $this->option_freetext = 1;				   // Support add of a personalised text
98
+        $this->option_draft_watermark = 0;		   // Support add of a watermark on drafts
99
+
100
+        // Recupere emetteur
101
+        $this->emetteur=$mysoc;
102
+        if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
103
+    }
104
+
105
+
106
+    /**
107
+     *	Return description of a module
108
+     *
109
+     *	@param	Translate	$langs      Lang object to use for output
110
+     *	@return string       			Description
111
+     */
112
+    function info($langs)
113
+    {
114
+        global $conf,$langs;
115
+
116
+        // Load translation files required by the page
117 117
         $langs->loadLangs(array("errors","companies"));
118 118
 
119
-		$form = new Form($this->db);
120
-
121
-		$texte = $this->description.".<br>\n";
122
-		$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
123
-		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
124
-		$texte.= '<input type="hidden" name="action" value="setModuleOptions">';
125
-		$texte.= '<input type="hidden" name="param1" value="EXPEDITION_ADDON_PDF_ODT_PATH">';
126
-		$texte.= '<table class="nobordernopadding" width="100%">';
127
-
128
-		// List of directories area
129
-		$texte.= '<tr><td>';
130
-		$texttitle=$langs->trans("ListOfDirectories");
131
-		$listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH)));
132
-		$listoffiles=array();
133
-		foreach($listofdir as $key=>$tmpdir)
134
-		{
135
-			$tmpdir=trim($tmpdir);
136
-			$tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
137
-			if (! $tmpdir) {
138
-				unset($listofdir[$key]); continue;
139
-			}
140
-			if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
141
-			else
142
-			{
143
-				$tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
144
-				if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
145
-			}
146
-		}
147
-		$texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
148
-		// Add list of substitution keys
149
-		$texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
150
-		$texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation");    // This contains an url, we don't modify it
151
-
152
-		$texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
153
-		$texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
154
-		$texte.= '<textarea class="flat" cols="60" name="value1">';
155
-		$texte.=$conf->global->EXPEDITION_ADDON_PDF_ODT_PATH;
156
-		$texte.= '</textarea>';
157
-		$texte.= '</div><div style="display: inline-block; vertical-align: middle;">';
158
-		$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
159
-		$texte.= '<br></div></div>';
160
-
161
-		// Scan directories
162
-		$nbofiles=count($listoffiles);
163
-		if (! empty($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH))
164
-		{
165
-			$texte.=$langs->trans("NumberOfModelFilesFound").': <b>';
166
-			//$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':'';
167
-			$texte.=count($listoffiles);
168
-			//$texte.=$nbofiles?'</a>':'';
169
-			$texte.='</b>';
170
-		}
171
-		if ($nbofiles)
172
-		{
173
-   			$texte.='<div id="div_'.get_class($this).'" class="hidden">';
174
-   			foreach($listoffiles as $file)
175
-   			{
119
+        $form = new Form($this->db);
120
+
121
+        $texte = $this->description.".<br>\n";
122
+        $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
123
+        $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
124
+        $texte.= '<input type="hidden" name="action" value="setModuleOptions">';
125
+        $texte.= '<input type="hidden" name="param1" value="EXPEDITION_ADDON_PDF_ODT_PATH">';
126
+        $texte.= '<table class="nobordernopadding" width="100%">';
127
+
128
+        // List of directories area
129
+        $texte.= '<tr><td>';
130
+        $texttitle=$langs->trans("ListOfDirectories");
131
+        $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH)));
132
+        $listoffiles=array();
133
+        foreach($listofdir as $key=>$tmpdir)
134
+        {
135
+            $tmpdir=trim($tmpdir);
136
+            $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
137
+            if (! $tmpdir) {
138
+                unset($listofdir[$key]); continue;
139
+            }
140
+            if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0);
141
+            else
142
+            {
143
+                $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)');
144
+                if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
145
+            }
146
+        }
147
+        $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT");
148
+        // Add list of substitution keys
149
+        $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>';
150
+        $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation");    // This contains an url, we don't modify it
151
+
152
+        $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1);
153
+        $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
154
+        $texte.= '<textarea class="flat" cols="60" name="value1">';
155
+        $texte.=$conf->global->EXPEDITION_ADDON_PDF_ODT_PATH;
156
+        $texte.= '</textarea>';
157
+        $texte.= '</div><div style="display: inline-block; vertical-align: middle;">';
158
+        $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
159
+        $texte.= '<br></div></div>';
160
+
161
+        // Scan directories
162
+        $nbofiles=count($listoffiles);
163
+        if (! empty($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH))
164
+        {
165
+            $texte.=$langs->trans("NumberOfModelFilesFound").': <b>';
166
+            //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':'';
167
+            $texte.=count($listoffiles);
168
+            //$texte.=$nbofiles?'</a>':'';
169
+            $texte.='</b>';
170
+        }
171
+        if ($nbofiles)
172
+        {
173
+                $texte.='<div id="div_'.get_class($this).'" class="hidden">';
174
+                foreach($listoffiles as $file)
175
+                {
176 176
                 $texte.=$file['name'].'<br>';
177
-   			}
178
-   			$texte.='<div id="div_'.get_class($this).'">';
179
-		}
177
+                }
178
+                $texte.='<div id="div_'.get_class($this).'">';
179
+        }
180 180
 
181
-		$texte.= '</td>';
181
+        $texte.= '</td>';
182 182
 
183
-		$texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
184
-		$texte.= $langs->trans("ExampleOfDirectoriesForModelGen");
185
-		$texte.= '</td>';
186
-		$texte.= '</tr>';
183
+        $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">';
184
+        $texte.= $langs->trans("ExampleOfDirectoriesForModelGen");
185
+        $texte.= '</td>';
186
+        $texte.= '</tr>';
187 187
 
188
-		$texte.= '</table>';
189
-		$texte.= '</form>';
188
+        $texte.= '</table>';
189
+        $texte.= '</form>';
190 190
 
191
-		return $texte;
192
-	}
191
+        return $texte;
192
+    }
193 193
 
194 194
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
195
-	/**
196
-	 *	Function to build a document on disk using the generic odt module.
197
-	 *
198
-	 *	@param		Expedition	$object				Object source to build document
199
-	 *	@param		Translate	$outputlangs		Lang output object
200
-	 * 	@param		string		$srctemplatepath	Full path of source filename for generator using a template file
201
-	 *  @param		int			$hidedetails		Do not show line details
202
-	 *  @param		int			$hidedesc			Do not show desc
203
-	 *  @param		int			$hideref			Do not show ref
204
-	 *	@return		int         					1 if OK, <=0 if KO
205
-	 */
206
-	function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
207
-	{
195
+    /**
196
+     *	Function to build a document on disk using the generic odt module.
197
+     *
198
+     *	@param		Expedition	$object				Object source to build document
199
+     *	@param		Translate	$outputlangs		Lang output object
200
+     * 	@param		string		$srctemplatepath	Full path of source filename for generator using a template file
201
+     *  @param		int			$hidedetails		Do not show line details
202
+     *  @param		int			$hidedesc			Do not show desc
203
+     *  @param		int			$hideref			Do not show ref
204
+     *	@return		int         					1 if OK, <=0 if KO
205
+     */
206
+    function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
207
+    {
208 208
         // phpcs:enable
209
-		global $user,$langs,$conf,$mysoc,$hookmanager;
210
-
211
-		if (empty($srctemplatepath))
212
-		{
213
-			dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
214
-			return -1;
215
-		}
216
-
217
-		// Add odtgeneration hook
218
-		if (! is_object($hookmanager))
219
-		{
220
-			include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
221
-			$hookmanager=new HookManager($this->db);
222
-		}
223
-		$hookmanager->initHooks(array('odtgeneration'));
224
-		global $action;
225
-
226
-		if (! is_object($outputlangs)) $outputlangs=$langs;
227
-		$sav_charset_output=$outputlangs->charset_output;
228
-		$outputlangs->charset_output='UTF-8';
229
-
230
-		// Load traductions files requiredby by page
231
-		$outputlangs->loadLangs(array("main", "dict", "companies", "bills"));
232
-
233
-		if ($conf->expedition->dir_output."/sending")
234
-		{
235
-			// If $object is id instead of object
236
-			if (! is_object($object))
237
-			{
238
-				$id = $object;
239
-				$object = new Expedition($this->db);
240
-				$result=$object->fetch($id);
241
-				if ($result < 0)
242
-				{
243
-					dol_print_error($this->db,$object->error);
244
-					return -1;
245
-				}
246
-			}
247
-
248
-			$dir = $conf->expedition->dir_output."/sending";
249
-			$objectref = dol_sanitizeFileName($object->ref);
250
-			if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
251
-			$file = $dir . "/" . $objectref . ".odt";
252
-
253
-			if (! file_exists($dir))
254
-			{
255
-				if (dol_mkdir($dir) < 0)
256
-				{
257
-					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
258
-					return -1;
259
-				}
260
-			}
261
-
262
-			if (file_exists($dir))
263
-			{
264
-				//print "srctemplatepath=".$srctemplatepath;	// Src filename
265
-				$newfile=basename($srctemplatepath);
266
-				$newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile);
267
-				$newfiletmp=preg_replace('/template_/i','',$newfiletmp);
268
-				$newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
269
-				$newfiletmp=$objectref.'_'.$newfiletmp;
270
-				//$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
271
-				// Get extension (ods or odt)
272
-				$newfileformat=substr($newfile, strrpos($newfile, '.')+1);
273
-				if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
274
-				{
275
-				    $format=$conf->global->MAIN_DOC_USE_TIMING;
276
-				    if ($format == '1') $format='%Y%m%d%H%M%S';
277
-					$filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
278
-				}
279
-				else
280
-				{
281
-					$filename=$newfiletmp.'.'.$newfileformat;
282
-				}
283
-				$file=$dir.'/'.$filename;
284
-				//print "newdir=".$dir;
285
-				//print "newfile=".$newfile;
286
-				//print "file=".$file;
287
-				//print "conf->societe->dir_temp=".$conf->societe->dir_temp;
288
-
289
-				dol_mkdir($conf->expedition->dir_temp);
290
-
291
-
292
-				// If SHIPMENT contact defined on invoice, we use it
293
-				$usecontact=false;
294
-				$arrayidcontact=$object->getIdContact('external','SHIPPING');
295
-				if (count($arrayidcontact) > 0)
296
-				{
297
-					$usecontact=true;
298
-					$result=$object->fetch_contact($arrayidcontact[0]);
299
-				}
300
-
301
-				// Recipient name
302
-				$contactobject = null;
303
-				if (! empty($usecontact)) {
304
-					// On peut utiliser le nom de la societe du contact
305
-					if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT))
306
-						$socobject = $object->contact;
307
-					else {
308
-						$socobject = $object->thirdparty;
309
-						// if we have a SHIIPPING contact and we dont use it as recipient we store the contact object for later use
310
-						$contactobject = $object->contact;
311
-					}
312
-				} else {
313
-					$socobject = $object->thirdparty;
314
-				}
315
-
316
-				// Make substitution
317
-				$substitutionarray=array(
318
-					'__FROM_NAME__' => $this->emetteur->name,
319
-					'__FROM_EMAIL__' => $this->emetteur->email,
320
-					'__TOTAL_TTC__' => $object->total_ttc,
321
-					'__TOTAL_HT__' => $object->total_ht,
322
-					'__TOTAL_VAT__' => $object->total_vat
323
-				);
324
-				complete_substitutions_array($substitutionarray, $langs, $object);
325
-				// Call the ODTSubstitution hook
326
-				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
327
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
328
-
329
-				// Line of free text
330
-				$newfreetext='';
331
-				$paramfreetext='EXPEDITION_FREE_TEXT';
332
-				if (! empty($conf->global->$paramfreetext))
333
-				{
334
-					$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
335
-				}
336
-
337
-				// Open and load template
338
-				require_once ODTPHP_PATH.'odf.php';
339
-				try {
340
-					$odfHandler = new odf(
341
-						$srctemplatepath,
342
-						array(
343
-						'PATH_TO_TMP'	  => $conf->expedition->dir_temp,
344
-						'ZIP_PROXY'		  => 'PclZipProxy',	// PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
345
-						'DELIMITER_LEFT'  => '{',
346
-						'DELIMITER_RIGHT' => '}'
347
-						)
348
-					);
349
-				}
350
-				catch(Exception $e)
351
-				{
352
-					$this->error=$e->getMessage();
353
-					dol_syslog($e->getMessage(), LOG_INFO);
354
-					return -1;
355
-				}
356
-				// After construction $odfHandler->contentXml contains content and
357
-				// [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
358
-				// [!-- BEGIN lines --]*[!-- END lines --]
359
-				//print html_entity_decode($odfHandler->__toString());
360
-				//print exit;
361
-
362
-
363
-				// Make substitutions into odt of freetext
364
-				try {
365
-					$odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
366
-				}
367
-				catch(OdfException $e)
368
-				{
369
-					dol_syslog($e->getMessage(), LOG_INFO);
370
-				}
371
-
372
-				// Make substitutions into odt of user info
373
-				$tmparray=$this->get_substitutionarray_user($user,$outputlangs);
374
-				//var_dump($tmparray); exit;
375
-				foreach($tmparray as $key=>$value)
376
-				{
377
-					try {
378
-						if (preg_match('/logo$/',$key)) // Image
379
-						{
380
-							//var_dump($value);exit;
381
-							if (file_exists($value)) $odfHandler->setImage($key, $value);
382
-							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
383
-						}
384
-						else    // Text
385
-						{
386
-							$odfHandler->setVars($key, $value, true, 'UTF-8');
387
-						}
388
-					}
389
-					catch (OdfException $e)
390
-					{
209
+        global $user,$langs,$conf,$mysoc,$hookmanager;
210
+
211
+        if (empty($srctemplatepath))
212
+        {
213
+            dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
214
+            return -1;
215
+        }
216
+
217
+        // Add odtgeneration hook
218
+        if (! is_object($hookmanager))
219
+        {
220
+            include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
221
+            $hookmanager=new HookManager($this->db);
222
+        }
223
+        $hookmanager->initHooks(array('odtgeneration'));
224
+        global $action;
225
+
226
+        if (! is_object($outputlangs)) $outputlangs=$langs;
227
+        $sav_charset_output=$outputlangs->charset_output;
228
+        $outputlangs->charset_output='UTF-8';
229
+
230
+        // Load traductions files requiredby by page
231
+        $outputlangs->loadLangs(array("main", "dict", "companies", "bills"));
232
+
233
+        if ($conf->expedition->dir_output."/sending")
234
+        {
235
+            // If $object is id instead of object
236
+            if (! is_object($object))
237
+            {
238
+                $id = $object;
239
+                $object = new Expedition($this->db);
240
+                $result=$object->fetch($id);
241
+                if ($result < 0)
242
+                {
243
+                    dol_print_error($this->db,$object->error);
244
+                    return -1;
245
+                }
246
+            }
247
+
248
+            $dir = $conf->expedition->dir_output."/sending";
249
+            $objectref = dol_sanitizeFileName($object->ref);
250
+            if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref;
251
+            $file = $dir . "/" . $objectref . ".odt";
252
+
253
+            if (! file_exists($dir))
254
+            {
255
+                if (dol_mkdir($dir) < 0)
256
+                {
257
+                    $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
258
+                    return -1;
259
+                }
260
+            }
261
+
262
+            if (file_exists($dir))
263
+            {
264
+                //print "srctemplatepath=".$srctemplatepath;	// Src filename
265
+                $newfile=basename($srctemplatepath);
266
+                $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile);
267
+                $newfiletmp=preg_replace('/template_/i','',$newfiletmp);
268
+                $newfiletmp=preg_replace('/modele_/i','',$newfiletmp);
269
+                $newfiletmp=$objectref.'_'.$newfiletmp;
270
+                //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt';
271
+                // Get extension (ods or odt)
272
+                $newfileformat=substr($newfile, strrpos($newfile, '.')+1);
273
+                if ( ! empty($conf->global->MAIN_DOC_USE_TIMING))
274
+                {
275
+                    $format=$conf->global->MAIN_DOC_USE_TIMING;
276
+                    if ($format == '1') $format='%Y%m%d%H%M%S';
277
+                    $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat;
278
+                }
279
+                else
280
+                {
281
+                    $filename=$newfiletmp.'.'.$newfileformat;
282
+                }
283
+                $file=$dir.'/'.$filename;
284
+                //print "newdir=".$dir;
285
+                //print "newfile=".$newfile;
286
+                //print "file=".$file;
287
+                //print "conf->societe->dir_temp=".$conf->societe->dir_temp;
288
+
289
+                dol_mkdir($conf->expedition->dir_temp);
290
+
291
+
292
+                // If SHIPMENT contact defined on invoice, we use it
293
+                $usecontact=false;
294
+                $arrayidcontact=$object->getIdContact('external','SHIPPING');
295
+                if (count($arrayidcontact) > 0)
296
+                {
297
+                    $usecontact=true;
298
+                    $result=$object->fetch_contact($arrayidcontact[0]);
299
+                }
300
+
301
+                // Recipient name
302
+                $contactobject = null;
303
+                if (! empty($usecontact)) {
304
+                    // On peut utiliser le nom de la societe du contact
305
+                    if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT))
306
+                        $socobject = $object->contact;
307
+                    else {
308
+                        $socobject = $object->thirdparty;
309
+                        // if we have a SHIIPPING contact and we dont use it as recipient we store the contact object for later use
310
+                        $contactobject = $object->contact;
311
+                    }
312
+                } else {
313
+                    $socobject = $object->thirdparty;
314
+                }
315
+
316
+                // Make substitution
317
+                $substitutionarray=array(
318
+                    '__FROM_NAME__' => $this->emetteur->name,
319
+                    '__FROM_EMAIL__' => $this->emetteur->email,
320
+                    '__TOTAL_TTC__' => $object->total_ttc,
321
+                    '__TOTAL_HT__' => $object->total_ht,
322
+                    '__TOTAL_VAT__' => $object->total_vat
323
+                );
324
+                complete_substitutions_array($substitutionarray, $langs, $object);
325
+                // Call the ODTSubstitution hook
326
+                $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
327
+                $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
328
+
329
+                // Line of free text
330
+                $newfreetext='';
331
+                $paramfreetext='EXPEDITION_FREE_TEXT';
332
+                if (! empty($conf->global->$paramfreetext))
333
+                {
334
+                    $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
335
+                }
336
+
337
+                // Open and load template
338
+                require_once ODTPHP_PATH.'odf.php';
339
+                try {
340
+                    $odfHandler = new odf(
341
+                        $srctemplatepath,
342
+                        array(
343
+                        'PATH_TO_TMP'	  => $conf->expedition->dir_temp,
344
+                        'ZIP_PROXY'		  => 'PclZipProxy',	// PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
345
+                        'DELIMITER_LEFT'  => '{',
346
+                        'DELIMITER_RIGHT' => '}'
347
+                        )
348
+                    );
349
+                }
350
+                catch(Exception $e)
351
+                {
352
+                    $this->error=$e->getMessage();
353
+                    dol_syslog($e->getMessage(), LOG_INFO);
354
+                    return -1;
355
+                }
356
+                // After construction $odfHandler->contentXml contains content and
357
+                // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
358
+                // [!-- BEGIN lines --]*[!-- END lines --]
359
+                //print html_entity_decode($odfHandler->__toString());
360
+                //print exit;
361
+
362
+
363
+                // Make substitutions into odt of freetext
364
+                try {
365
+                    $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
366
+                }
367
+                catch(OdfException $e)
368
+                {
369
+                    dol_syslog($e->getMessage(), LOG_INFO);
370
+                }
371
+
372
+                // Make substitutions into odt of user info
373
+                $tmparray=$this->get_substitutionarray_user($user,$outputlangs);
374
+                //var_dump($tmparray); exit;
375
+                foreach($tmparray as $key=>$value)
376
+                {
377
+                    try {
378
+                        if (preg_match('/logo$/',$key)) // Image
379
+                        {
380
+                            //var_dump($value);exit;
381
+                            if (file_exists($value)) $odfHandler->setImage($key, $value);
382
+                            else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
383
+                        }
384
+                        else    // Text
385
+                        {
386
+                            $odfHandler->setVars($key, $value, true, 'UTF-8');
387
+                        }
388
+                    }
389
+                    catch (OdfException $e)
390
+                    {
391 391
                         dol_syslog($e->getMessage(), LOG_INFO);
392
-					}
393
-				}
394
-				// Make substitutions into odt of mysoc
395
-				$tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
396
-				//var_dump($tmparray); exit;
397
-				foreach($tmparray as $key=>$value)
398
-				{
399
-					try {
400
-						if (preg_match('/logo$/',$key))	// Image
401
-						{
402
-							//var_dump($value);exit;
403
-							if (file_exists($value)) $odfHandler->setImage($key, $value);
404
-							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
405
-						}
406
-						else	// Text
407
-						{
408
-							$odfHandler->setVars($key, $value, true, 'UTF-8');
409
-						}
410
-					}
411
-					catch (OdfException $e)
412
-					{
392
+                    }
393
+                }
394
+                // Make substitutions into odt of mysoc
395
+                $tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
396
+                //var_dump($tmparray); exit;
397
+                foreach($tmparray as $key=>$value)
398
+                {
399
+                    try {
400
+                        if (preg_match('/logo$/',$key))	// Image
401
+                        {
402
+                            //var_dump($value);exit;
403
+                            if (file_exists($value)) $odfHandler->setImage($key, $value);
404
+                            else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
405
+                        }
406
+                        else	// Text
407
+                        {
408
+                            $odfHandler->setVars($key, $value, true, 'UTF-8');
409
+                        }
410
+                    }
411
+                    catch (OdfException $e)
412
+                    {
413 413
                         dol_syslog($e->getMessage(), LOG_INFO);
414
-					}
415
-				}
416
-				// Make substitutions into odt of thirdparty
417
-				$tmparray=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
418
-				foreach($tmparray as $key=>$value)
419
-				{
420
-					try {
421
-						if (preg_match('/logo$/',$key))	// Image
422
-						{
423
-							if (file_exists($value)) $odfHandler->setImage($key, $value);
424
-							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
425
-						}
426
-						else	// Text
427
-						{
428
-							$odfHandler->setVars($key, $value, true, 'UTF-8');
429
-						}
430
-					}
431
-					catch (OdfException $e)
432
-					{
414
+                    }
415
+                }
416
+                // Make substitutions into odt of thirdparty
417
+                $tmparray=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
418
+                foreach($tmparray as $key=>$value)
419
+                {
420
+                    try {
421
+                        if (preg_match('/logo$/',$key))	// Image
422
+                        {
423
+                            if (file_exists($value)) $odfHandler->setImage($key, $value);
424
+                            else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
425
+                        }
426
+                        else	// Text
427
+                        {
428
+                            $odfHandler->setVars($key, $value, true, 'UTF-8');
429
+                        }
430
+                    }
431
+                    catch (OdfException $e)
432
+                    {
433 433
                         dol_syslog($e->getMessage(), LOG_INFO);
434
-					}
435
-				}
436
-
437
-				if ($usecontact && is_object($contactobject)) {
438
-					$tmparray=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
439
-					foreach($tmparray as $key=>$value)
440
-					{
441
-						try {
442
-							if (preg_match('/logo$/',$key))	// Image
443
-							{
444
-								if (file_exists($value)) $odfHandler->setImage($key, $value);
445
-								else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
446
-							}
447
-							else	// Text
448
-							{
449
-								$odfHandler->setVars($key, $value, true, 'UTF-8');
450
-							}
451
-						}
452
-						catch(OdfException $e)
453
-						{
434
+                    }
435
+                }
436
+
437
+                if ($usecontact && is_object($contactobject)) {
438
+                    $tmparray=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
439
+                    foreach($tmparray as $key=>$value)
440
+                    {
441
+                        try {
442
+                            if (preg_match('/logo$/',$key))	// Image
443
+                            {
444
+                                if (file_exists($value)) $odfHandler->setImage($key, $value);
445
+                                else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
446
+                            }
447
+                            else	// Text
448
+                            {
449
+                                $odfHandler->setVars($key, $value, true, 'UTF-8');
450
+                            }
451
+                        }
452
+                        catch(OdfException $e)
453
+                        {
454 454
                             dol_syslog($e->getMessage(), LOG_INFO);
455
-						}
456
-					}
457
-				}
458
-
459
-				// Replace tags of object + external modules
460
-				$tmparray=$this->get_substitutionarray_shipment($object,$outputlangs);
461
-				complete_substitutions_array($tmparray, $outputlangs, $object);
462
-				// Call the ODTSubstitution hook
463
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
464
-				$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
465
-				foreach($tmparray as $key=>$value)
466
-				{
467
-					try {
468
-						if (preg_match('/logo$/',$key)) // Image
469
-						{
470
-							if (file_exists($value)) $odfHandler->setImage($key, $value);
471
-							else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
472
-						}
473
-						else    // Text
474
-						{
475
-							$odfHandler->setVars($key, $value, true, 'UTF-8');
476
-						}
477
-					}
478
-					catch(OdfException $e)
479
-					{
455
+                        }
456
+                    }
457
+                }
458
+
459
+                // Replace tags of object + external modules
460
+                $tmparray=$this->get_substitutionarray_shipment($object,$outputlangs);
461
+                complete_substitutions_array($tmparray, $outputlangs, $object);
462
+                // Call the ODTSubstitution hook
463
+                $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
464
+                $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
465
+                foreach($tmparray as $key=>$value)
466
+                {
467
+                    try {
468
+                        if (preg_match('/logo$/',$key)) // Image
469
+                        {
470
+                            if (file_exists($value)) $odfHandler->setImage($key, $value);
471
+                            else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
472
+                        }
473
+                        else    // Text
474
+                        {
475
+                            $odfHandler->setVars($key, $value, true, 'UTF-8');
476
+                        }
477
+                    }
478
+                    catch(OdfException $e)
479
+                    {
480
+                        dol_syslog($e->getMessage(), LOG_INFO);
481
+                    }
482
+                }
483
+                // Replace tags of lines
484
+                try
485
+                {
486
+                    $foundtagforlines = 1;
487
+                    try {
488
+                        $listlines = $odfHandler->setSegment('lines');
489
+                    }
490
+                    catch(OdfException $e)
491
+                    {
492
+                        // We may arrive here if tags for lines not present into template
493
+                        $foundtagforlines = 0;
480 494
                         dol_syslog($e->getMessage(), LOG_INFO);
481
-					}
482
-				}
483
-				// Replace tags of lines
484
-				try
485
-				{
486
-					$foundtagforlines = 1;
487
-					try {
488
-						$listlines = $odfHandler->setSegment('lines');
489
-					}
490
-					catch(OdfException $e)
491
-					{
492
-						// We may arrive here if tags for lines not present into template
493
-						$foundtagforlines = 0;
494
-						dol_syslog($e->getMessage(), LOG_INFO);
495
-					}
496
-					if ($foundtagforlines)
497
-					{
498
-						foreach ($object->lines as $line)
499
-						{
500
-							$tmparray=$this->get_substitutionarray_shipment_lines($line,$outputlangs);
501
-							complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
502
-							// Call the ODTSubstitutionLine hook
503
-							$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
504
-							$reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
505
-							foreach($tmparray as $key => $val)
506
-							{
507
-								try
508
-								{
509
-									$listlines->setVars($key, $val, true, 'UTF-8');
510
-								}
511
-								catch(OdfException $e)
512
-								{
513
-									dol_syslog($e->getMessage(), LOG_INFO);
514
-								}
515
-								catch(SegmentException $e)
516
-								{
517
-									dol_syslog($e->getMessage(), LOG_INFO);
518
-								}
519
-							}
520
-							$listlines->merge();
521
-						}
522
-						$odfHandler->mergeSegment($listlines);
523
-					}
524
-				}
525
-				catch (OdfException $e)
526
-				{
527
-					$this->error=$e->getMessage();
528
-					dol_syslog($this->error, LOG_WARNING);
529
-					return -1;
530
-				}
531
-
532
-				// Replace labels translated
533
-				$tmparray=$outputlangs->get_translations_for_substitutions();
534
-				foreach($tmparray as $key=>$value)
535
-				{
536
-					try {
537
-						$odfHandler->setVars($key, $value, true, 'UTF-8');
538
-					}
539
-					catch (OdfException $e)
540
-					{
495
+                    }
496
+                    if ($foundtagforlines)
497
+                    {
498
+                        foreach ($object->lines as $line)
499
+                        {
500
+                            $tmparray=$this->get_substitutionarray_shipment_lines($line,$outputlangs);
501
+                            complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
502
+                            // Call the ODTSubstitutionLine hook
503
+                            $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line);
504
+                            $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
505
+                            foreach($tmparray as $key => $val)
506
+                            {
507
+                                try
508
+                                {
509
+                                    $listlines->setVars($key, $val, true, 'UTF-8');
510
+                                }
511
+                                catch(OdfException $e)
512
+                                {
513
+                                    dol_syslog($e->getMessage(), LOG_INFO);
514
+                                }
515
+                                catch(SegmentException $e)
516
+                                {
517
+                                    dol_syslog($e->getMessage(), LOG_INFO);
518
+                                }
519
+                            }
520
+                            $listlines->merge();
521
+                        }
522
+                        $odfHandler->mergeSegment($listlines);
523
+                    }
524
+                }
525
+                catch (OdfException $e)
526
+                {
527
+                    $this->error=$e->getMessage();
528
+                    dol_syslog($this->error, LOG_WARNING);
529
+                    return -1;
530
+                }
531
+
532
+                // Replace labels translated
533
+                $tmparray=$outputlangs->get_translations_for_substitutions();
534
+                foreach($tmparray as $key=>$value)
535
+                {
536
+                    try {
537
+                        $odfHandler->setVars($key, $value, true, 'UTF-8');
538
+                    }
539
+                    catch (OdfException $e)
540
+                    {
541 541
                         dol_syslog($e->getMessage(), LOG_INFO);
542
-					}
543
-				}
544
-
545
-				// Call the beforeODTSave hook
546
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
547
-				$reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
548
-
549
-				// Write new file
550
-				if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
551
-					try {
552
-						$odfHandler->exportAsAttachedPDF($file);
553
-					} catch (Exception $e) {
554
-						$this->error=$e->getMessage();
542
+                    }
543
+                }
544
+
545
+                // Call the beforeODTSave hook
546
+                $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
547
+                $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
548
+
549
+                // Write new file
550
+                if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
551
+                    try {
552
+                        $odfHandler->exportAsAttachedPDF($file);
553
+                    } catch (Exception $e) {
554
+                        $this->error=$e->getMessage();
555 555
                         dol_syslog($e->getMessage(), LOG_INFO);
556
-						return -1;
557
-					}
558
-				}
559
-				else {
560
-					try {
561
-					$odfHandler->saveToDisk($file);
562
-					} catch (Exception $e) {
563
-						$this->error=$e->getMessage();
556
+                        return -1;
557
+                    }
558
+                }
559
+                else {
560
+                    try {
561
+                    $odfHandler->saveToDisk($file);
562
+                    } catch (Exception $e) {
563
+                        $this->error=$e->getMessage();
564 564
                         dol_syslog($e->getMessage(), LOG_INFO);
565
-						return -1;
566
-					}
567
-				}
568
-				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
569
-				$reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
570
-
571
-				if (! empty($conf->global->MAIN_UMASK))
572
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
573
-
574
-				$odfHandler=null;	// Destroy object
575
-
576
-				$this->result = array('fullpath'=>$file);
577
-
578
-				return 1;   // Success
579
-			}
580
-			else
581
-			{
582
-				$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
583
-				return -1;
584
-			}
585
-		}
586
-
587
-		return -1;
588
-	}
565
+                        return -1;
566
+                    }
567
+                }
568
+                $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
569
+                $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
570
+
571
+                if (! empty($conf->global->MAIN_UMASK))
572
+                    @chmod($file, octdec($conf->global->MAIN_UMASK));
573
+
574
+                $odfHandler=null;	// Destroy object
575
+
576
+                $this->result = array('fullpath'=>$file);
577
+
578
+                return 1;   // Success
579
+            }
580
+            else
581
+            {
582
+                $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
583
+                return -1;
584
+            }
585
+        }
586
+
587
+        return -1;
588
+    }
589 589
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/expedition/mod_expedition_ribera.php 1 patch
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -29,125 +29,125 @@
 block discarded – undo
29 29
  */
30 30
 class mod_expedition_ribera extends ModelNumRefExpedition
31 31
 {
32
-	/**
32
+    /**
33 33
      * Dolibarr version of the loaded document
34 34
      * @public string
35 35
      */
36
-	public $version = 'dolibarr';
37
-
38
-	/**
39
-	 * @var string Error message
40
-	 */
41
-	public $error = '';
42
-
43
-	/**
44
-	 * @var string Nom du modele
45
-	 * @deprecated
46
-	 * @see name
47
-	 */
48
-	public $nom='Ribera';
49
-
50
-	/**
51
-	 * @var string model name
52
-	 */
53
-	public $name='Ribera';
54
-
55
-	/**
56
-	 *	Return default description of numbering model
57
-	 *
58
-	 *	@return     string      text description
59
-	 */
60
-	function info()
36
+    public $version = 'dolibarr';
37
+
38
+    /**
39
+     * @var string Error message
40
+     */
41
+    public $error = '';
42
+
43
+    /**
44
+     * @var string Nom du modele
45
+     * @deprecated
46
+     * @see name
47
+     */
48
+    public $nom='Ribera';
49
+
50
+    /**
51
+     * @var string model name
52
+     */
53
+    public $name='Ribera';
54
+
55
+    /**
56
+     *	Return default description of numbering model
57
+     *
58
+     *	@return     string      text description
59
+     */
60
+    function info()
61 61
     {
62
-    	global $conf, $langs;
62
+        global $conf, $langs;
63 63
 
64
-		$langs->load("bills");
64
+        $langs->load("bills");
65 65
 
66
-		$form = new Form($this->db);
66
+        $form = new Form($this->db);
67 67
 
68
-		$texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
69
-		$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
70
-		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
71
-		$texte.= '<input type="hidden" name="action" value="updateMask">';
72
-		$texte.= '<input type="hidden" name="maskconstexpedition" value="EXPEDITION_RIBERA_MASK">';
73
-		$texte.= '<table class="nobordernopadding" width="100%">';
68
+        $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
69
+        $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
70
+        $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
71
+        $texte.= '<input type="hidden" name="action" value="updateMask">';
72
+        $texte.= '<input type="hidden" name="maskconstexpedition" value="EXPEDITION_RIBERA_MASK">';
73
+        $texte.= '<table class="nobordernopadding" width="100%">';
74 74
 
75
-		$tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Shipment"),$langs->transnoentities("Shipment"));
76
-		$tooltip.=$langs->trans("GenericMaskCodes2");
77
-		$tooltip.=$langs->trans("GenericMaskCodes3");
78
-		$tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("Shipment"),$langs->transnoentities("Shipment"));
79
-		$tooltip.=$langs->trans("GenericMaskCodes5");
75
+        $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Shipment"),$langs->transnoentities("Shipment"));
76
+        $tooltip.=$langs->trans("GenericMaskCodes2");
77
+        $tooltip.=$langs->trans("GenericMaskCodes3");
78
+        $tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("Shipment"),$langs->transnoentities("Shipment"));
79
+        $tooltip.=$langs->trans("GenericMaskCodes5");
80 80
 
81
-		$texte.= '<tr><td>'.$langs->trans("Mask").':</td>';
82
-		$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskexpedition" value="'.$conf->global->EXPEDITION_RIBERA_MASK.'">',$tooltip,1,1).'</td>';
83
-		$texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
84
-		$texte.= '</tr>';
85
-		$texte.= '</table>';
86
-		$texte.= '</form>';
81
+        $texte.= '<tr><td>'.$langs->trans("Mask").':</td>';
82
+        $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskexpedition" value="'.$conf->global->EXPEDITION_RIBERA_MASK.'">',$tooltip,1,1).'</td>';
83
+        $texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
84
+        $texte.= '</tr>';
85
+        $texte.= '</table>';
86
+        $texte.= '</form>';
87 87
 
88
-		return $texte;
88
+        return $texte;
89 89
     }
90 90
 
91
-	/**
92
-	 *	Return numbering example
93
-	 *
94
-	 *	@return     string      Example
95
-	 */
91
+    /**
92
+     *	Return numbering example
93
+     *
94
+     *	@return     string      Example
95
+     */
96 96
     function getExample()
97 97
     {
98
-     	global $conf,$langs,$mysoc;
99
-
100
-    	$old_code_client=$mysoc->code_client;
101
-    	$old_code_type=$mysoc->typent_code;
102
-    	$mysoc->code_client='CCCCCCCCCC';
103
-    	$mysoc->typent_code='TTTTTTTTTT';
104
-     	$numExample = $this->getNextValue($mysoc,'');
105
-		$mysoc->code_client=$old_code_client;
106
-		$mysoc->typent_code=$old_code_type;
107
-
108
-		if (! $numExample)
109
-		{
110
-			$numExample = $langs->trans('NotConfigured');
111
-		}
112
-		return $numExample;
98
+            global $conf,$langs,$mysoc;
99
+
100
+        $old_code_client=$mysoc->code_client;
101
+        $old_code_type=$mysoc->typent_code;
102
+        $mysoc->code_client='CCCCCCCCCC';
103
+        $mysoc->typent_code='TTTTTTTTTT';
104
+            $numExample = $this->getNextValue($mysoc,'');
105
+        $mysoc->code_client=$old_code_client;
106
+        $mysoc->typent_code=$old_code_type;
107
+
108
+        if (! $numExample)
109
+        {
110
+            $numExample = $langs->trans('NotConfigured');
111
+        }
112
+        return $numExample;
113 113
     }
114 114
 
115
-	/**
116
-	 *	Return next value
117
-	 *
118
-	 *	@param	Societe		$objsoc     Third party object
119
-	 *	@param	Object		$shipment	Shipment object
120
-	 *	@return string      			Value if OK, 0 if KO
121
-	 */
115
+    /**
116
+     *	Return next value
117
+     *
118
+     *	@param	Societe		$objsoc     Third party object
119
+     *	@param	Object		$shipment	Shipment object
120
+     *	@return string      			Value if OK, 0 if KO
121
+     */
122 122
     function getNextValue($objsoc,$shipment)
123 123
     {
124
-		global $db,$conf;
124
+        global $db,$conf;
125 125
 
126
-		require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
126
+        require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
127 127
 
128
-		$mask=$conf->global->EXPEDITION_RIBERA_MASK;
128
+        $mask=$conf->global->EXPEDITION_RIBERA_MASK;
129 129
 
130
-		if (! $mask)
131
-		{
132
-			$this->error='NotConfigured';
133
-			return 0;
134
-		}
130
+        if (! $mask)
131
+        {
132
+            $this->error='NotConfigured';
133
+            return 0;
134
+        }
135 135
 
136
-		$date = $shipment->date_expedition;
136
+        $date = $shipment->date_expedition;
137 137
 
138
-		$numFinal=get_next_value($db,$mask,'expedition','ref','',$objsoc,$date);
138
+        $numFinal=get_next_value($db,$mask,'expedition','ref','',$objsoc,$date);
139 139
 
140
-		return  $numFinal;
141
-	}
140
+        return  $numFinal;
141
+    }
142 142
 
143 143
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
144
-	/**
145
-	 *  Return next free value
146
-	 *
147
-	 *	@param	Societe		$objsoc     Third party object
148
-	 *	@param	Object		$objforref	Shipment object
149
-	 *	@return string      			Next free value
150
-	 */
144
+    /**
145
+     *  Return next free value
146
+     *
147
+     *	@param	Societe		$objsoc     Third party object
148
+     *	@param	Object		$objforref	Shipment object
149
+     *	@return string      			Next free value
150
+     */
151 151
     function expedition_get_num($objsoc,$objforref)
152 152
     {
153 153
         // phpcs:enable
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/expedition/mod_expedition_safor.php 1 patch
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -28,139 +28,139 @@
 block discarded – undo
28 28
  */
29 29
 class mod_expedition_safor extends ModelNumRefExpedition
30 30
 {
31
-	/**
31
+    /**
32 32
      * Dolibarr version of the loaded document
33 33
      * @public string
34 34
      */
35
-	public $version = 'dolibarr';
35
+    public $version = 'dolibarr';
36 36
 
37
-	public $prefix='SH';
37
+    public $prefix='SH';
38 38
 
39
-	/**
40
-	 * @var string Error code (or message)
41
-	 */
42
-	public $error='';
39
+    /**
40
+     * @var string Error code (or message)
41
+     */
42
+    public $error='';
43 43
 
44
-	/**
45
-	 * @var string Nom du modele
46
-	 * @deprecated
47
-	 * @see name
48
-	 */
49
-	public $nom='Safor';
44
+    /**
45
+     * @var string Nom du modele
46
+     * @deprecated
47
+     * @see name
48
+     */
49
+    public $nom='Safor';
50 50
 
51
-	/**
52
-	 * @var string model name
53
-	 */
54
-	public $name='Safor';
51
+    /**
52
+     * @var string model name
53
+     */
54
+    public $name='Safor';
55 55
 
56 56
 
57
-	/**
58
-	 *	Return default description of numbering model
59
-	 *
60
-	 *	@return     string      text description
61
-	 */
57
+    /**
58
+     *	Return default description of numbering model
59
+     *
60
+     *	@return     string      text description
61
+     */
62 62
     function info()
63 63
     {
64
-    	global $langs;
65
-      	return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
64
+        global $langs;
65
+            return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
66 66
     }
67 67
 
68 68
 
69
-	/**
70
-	 *	Return numbering example
71
-	 *
72
-	 *	@return     string      Example
73
-	 */
74
-	function getExample()
75
-	{
76
-		return $this->prefix."0501-0001";
77
-	}
78
-
79
-
80
-	/**
81
-	 *	Test if existing numbers make problems with numbering
82
-	 *
83
-	 *	@return     boolean     false if conflit, true if ok
84
-	 */
85
-	function canBeActivated()
86
-	{
87
-		global $conf,$langs,$db;
88
-
89
-		$coyymm=''; $max='';
90
-
91
-		$posindice=8;
92
-		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
93
-		$sql.= " FROM ".MAIN_DB_PREFIX."expedition";
94
-		$sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
95
-		$sql.= " AND entity = ".$conf->entity;
96
-
97
-		$resql=$db->query($sql);
98
-		if ($resql)
99
-		{
100
-			$row = $db->fetch_row($resql);
101
-			if ($row) { $coyymm = substr($row[0],0,6); $max=$row[0]; }
102
-		}
103
-		if ($coyymm && ! preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$coyymm))
104
-		{
105
-			$langs->load("errors");
106
-			$this->error=$langs->trans('ErrorNumRefModel', $max);
107
-			return false;
108
-		}
109
-
110
-		return true;
111
-	}
112
-
113
-	/**
114
-	 *	Return next value
115
-	 *
116
-	 *	@param	Societe		$objsoc     Third party object
117
-	 *	@param	Object		$shipment	Shipment object
118
-	 *	@return string      			Value if OK, 0 if KO
119
-	 */
120
-	function getNextValue($objsoc,$shipment)
121
-	{
122
-		global $db,$conf;
123
-
124
-		$posindice=8;
125
-		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
126
-		$sql.= " FROM ".MAIN_DB_PREFIX."expedition";
127
-		$sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
128
-		$sql.= " AND entity = ".$conf->entity;
129
-
130
-		$resql=$db->query($sql);
131
-		if ($resql)
132
-		{
133
-			$obj = $db->fetch_object($resql);
134
-			if ($obj) $max = intval($obj->max);
135
-			else $max=0;
136
-		}
137
-		else
138
-		{
139
-			dol_syslog("mod_expedition_safor::getNextValue", LOG_DEBUG);
140
-			return -1;
141
-		}
142
-
143
-		$date=time();
144
-		$yymm = strftime("%y%m",$date);
145
-
146
-		if ($max >= (pow(10, 4) - 1)) $num=$max+1;	// If counter > 9999, we do not format on 4 chars, we take number as it is
147
-		else $num = sprintf("%04s",$max+1);
148
-
149
-		dol_syslog("mod_expedition_safor::getNextValue return ".$this->prefix.$yymm."-".$num);
150
-		return $this->prefix.$yymm."-".$num;
151
-	}
69
+    /**
70
+     *	Return numbering example
71
+     *
72
+     *	@return     string      Example
73
+     */
74
+    function getExample()
75
+    {
76
+        return $this->prefix."0501-0001";
77
+    }
78
+
79
+
80
+    /**
81
+     *	Test if existing numbers make problems with numbering
82
+     *
83
+     *	@return     boolean     false if conflit, true if ok
84
+     */
85
+    function canBeActivated()
86
+    {
87
+        global $conf,$langs,$db;
88
+
89
+        $coyymm=''; $max='';
90
+
91
+        $posindice=8;
92
+        $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
93
+        $sql.= " FROM ".MAIN_DB_PREFIX."expedition";
94
+        $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
95
+        $sql.= " AND entity = ".$conf->entity;
96
+
97
+        $resql=$db->query($sql);
98
+        if ($resql)
99
+        {
100
+            $row = $db->fetch_row($resql);
101
+            if ($row) { $coyymm = substr($row[0],0,6); $max=$row[0]; }
102
+        }
103
+        if ($coyymm && ! preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$coyymm))
104
+        {
105
+            $langs->load("errors");
106
+            $this->error=$langs->trans('ErrorNumRefModel', $max);
107
+            return false;
108
+        }
109
+
110
+        return true;
111
+    }
112
+
113
+    /**
114
+     *	Return next value
115
+     *
116
+     *	@param	Societe		$objsoc     Third party object
117
+     *	@param	Object		$shipment	Shipment object
118
+     *	@return string      			Value if OK, 0 if KO
119
+     */
120
+    function getNextValue($objsoc,$shipment)
121
+    {
122
+        global $db,$conf;
123
+
124
+        $posindice=8;
125
+        $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
126
+        $sql.= " FROM ".MAIN_DB_PREFIX."expedition";
127
+        $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
128
+        $sql.= " AND entity = ".$conf->entity;
129
+
130
+        $resql=$db->query($sql);
131
+        if ($resql)
132
+        {
133
+            $obj = $db->fetch_object($resql);
134
+            if ($obj) $max = intval($obj->max);
135
+            else $max=0;
136
+        }
137
+        else
138
+        {
139
+            dol_syslog("mod_expedition_safor::getNextValue", LOG_DEBUG);
140
+            return -1;
141
+        }
142
+
143
+        $date=time();
144
+        $yymm = strftime("%y%m",$date);
145
+
146
+        if ($max >= (pow(10, 4) - 1)) $num=$max+1;	// If counter > 9999, we do not format on 4 chars, we take number as it is
147
+        else $num = sprintf("%04s",$max+1);
148
+
149
+        dol_syslog("mod_expedition_safor::getNextValue return ".$this->prefix.$yymm."-".$num);
150
+        return $this->prefix.$yymm."-".$num;
151
+    }
152 152
 
153 153
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
154
-	/**
155
-	 *  Return next free value
156
-	 *
157
-	 *	@param	Societe		$objsoc     Third party object
158
-	 *	@param	Object		$objforref	Shipment object
159
-	 *	@return string      			Next free value
160
-	 */
161
-	function expedition_get_num($objsoc,$objforref)
162
-	{
154
+    /**
155
+     *  Return next free value
156
+     *
157
+     *	@param	Societe		$objsoc     Third party object
158
+     *	@param	Object		$objforref	Shipment object
159
+     *	@return string      			Next free value
160
+     */
161
+    function expedition_get_num($objsoc,$objforref)
162
+    {
163 163
         // phpcs:enable
164
-		return $this->getNextValue($objsoc,$objforref);
165
-	}
164
+        return $this->getNextValue($objsoc,$objforref);
165
+    }
166 166
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/modules/expedition/modules_expedition.php 1 patch
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
  *  \brief      File that contains parent class for sending receipts models
30 30
  *              and parent class for sending receipts numbering models
31 31
  */
32
- require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
32
+    require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
33 33
 
34 34
 /**
35 35
  *	Parent class of sending receipts models
@@ -37,32 +37,32 @@  discard block
 block discarded – undo
37 37
 abstract class ModelePdfExpedition extends CommonDocGenerator
38 38
 {
39 39
     /**
40
-	 * @var string Error code (or message)
41
-	 */
42
-	public $error='';
40
+     * @var string Error code (or message)
41
+     */
42
+    public $error='';
43 43
 
44 44
 
45 45
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
46
-	/**
47
-	 *  Return list of active generation modules
48
-	 *
46
+    /**
47
+     *  Return list of active generation modules
48
+     *
49 49
      *  @param	DoliDB	$db     			Database handler
50 50
      *  @param  integer	$maxfilenamelength  Max length of value to show
51 51
      *  @return	array						List of templates
52
-	 */
53
-	static function liste_modeles($db,$maxfilenamelength=0)
54
-	{
52
+     */
53
+    static function liste_modeles($db,$maxfilenamelength=0)
54
+    {
55 55
         // phpcs:enable
56
-		global $conf;
56
+        global $conf;
57 57
 
58
-		$type='shipping';
59
-		$liste=array();
58
+        $type='shipping';
59
+        $liste=array();
60 60
 
61
-		include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
62
-		$liste=getListOfModels($db,$type,$maxfilenamelength);
61
+        include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
62
+        $liste=getListOfModels($db,$type,$maxfilenamelength);
63 63
 
64
-		return $liste;
65
-	}
64
+        return $liste;
65
+    }
66 66
 }
67 67
 
68 68
 
@@ -71,81 +71,81 @@  discard block
 block discarded – undo
71 71
  */
72 72
 abstract class ModelNumRefExpedition
73 73
 {
74
-	/**
75
-	 * @var string Error code (or message)
76
-	 */
77
-	public $error='';
78
-
79
-	/** Return if a model can be used or not
80
-	 *
81
-	 *  @return		boolean     true if model can be used
82
-	 */
83
-	function isEnabled()
84
-	{
85
-		return true;
86
-	}
87
-
88
-	/**
89
-	 *	Return default description of numbering model
90
-	 *
91
-	 *	@return     string      text description
92
-	 */
93
-	function info()
94
-	{
95
-		global $langs;
96
-		$langs->load("sendings");
97
-		return $langs->trans("NoDescription");
98
-	}
99
-
100
-	/**
101
-	 *	Returns numbering example
102
-	 *
103
-	 *	@return     string      Example
104
-	 */
105
-	function getExample()
106
-	{
107
-		global $langs;
108
-		$langs->load("sendings");
109
-		return $langs->trans("NoExample");
110
-	}
111
-
112
-	/**
113
-	 *	Test if existing numbers make problems with numbering
114
-	 *
115
-	 *	@return     boolean     false if conflit, true if ok
116
-	 */
117
-	function canBeActivated()
118
-	{
119
-		return true;
120
-	}
121
-
122
-	/**
123
-	 *	Returns next value assigned
124
-	 *
125
-	 *	@param	Societe		$objsoc     Third party object
126
-	 *	@param	Object		$shipment	Shipment object
127
-	 *	@return	string					Value
128
-	 */
129
-	function getNextValue($objsoc, $shipment)
130
-	{
131
-		global $langs;
132
-		return $langs->trans("NotAvailable");
133
-	}
134
-
135
-	/**
136
-	 *	Returns version of the numbering model
137
-	 *
138
-	 *	@return     string      Value
139
-	 */
140
-	function getVersion()
141
-	{
142
-		global $langs;
143
-		$langs->load("admin");
144
-
145
-		if ($this->version == 'development') return $langs->trans("VersionDevelopment");
146
-		if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
147
-		if ($this->version == 'dolibarr') return DOL_VERSION;
148
-		if ($this->version) return $this->version;
149
-		return $langs->trans("NotAvailable");
150
-	}
74
+    /**
75
+     * @var string Error code (or message)
76
+     */
77
+    public $error='';
78
+
79
+    /** Return if a model can be used or not
80
+     *
81
+     *  @return		boolean     true if model can be used
82
+     */
83
+    function isEnabled()
84
+    {
85
+        return true;
86
+    }
87
+
88
+    /**
89
+     *	Return default description of numbering model
90
+     *
91
+     *	@return     string      text description
92
+     */
93
+    function info()
94
+    {
95
+        global $langs;
96
+        $langs->load("sendings");
97
+        return $langs->trans("NoDescription");
98
+    }
99
+
100
+    /**
101
+     *	Returns numbering example
102
+     *
103
+     *	@return     string      Example
104
+     */
105
+    function getExample()
106
+    {
107
+        global $langs;
108
+        $langs->load("sendings");
109
+        return $langs->trans("NoExample");
110
+    }
111
+
112
+    /**
113
+     *	Test if existing numbers make problems with numbering
114
+     *
115
+     *	@return     boolean     false if conflit, true if ok
116
+     */
117
+    function canBeActivated()
118
+    {
119
+        return true;
120
+    }
121
+
122
+    /**
123
+     *	Returns next value assigned
124
+     *
125
+     *	@param	Societe		$objsoc     Third party object
126
+     *	@param	Object		$shipment	Shipment object
127
+     *	@return	string					Value
128
+     */
129
+    function getNextValue($objsoc, $shipment)
130
+    {
131
+        global $langs;
132
+        return $langs->trans("NotAvailable");
133
+    }
134
+
135
+    /**
136
+     *	Returns version of the numbering model
137
+     *
138
+     *	@return     string      Value
139
+     */
140
+    function getVersion()
141
+    {
142
+        global $langs;
143
+        $langs->load("admin");
144
+
145
+        if ($this->version == 'development') return $langs->trans("VersionDevelopment");
146
+        if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
147
+        if ($this->version == 'dolibarr') return DOL_VERSION;
148
+        if ($this->version) return $this->version;
149
+        return $langs->trans("NotAvailable");
150
+    }
151 151
 }
Please login to merge, or discard this patch.