-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
pdf.lib.php
2265 lines (2042 loc) · 94.3 KB
/
pdf.lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2010-2017 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2012-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
* Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com>
* Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
*/
/**
* \file htdocs/core/lib/pdf.lib.php
* \brief Set of functions used for PDF generation
* \ingroup core
*/
/**
* Return array with format properties of default PDF format
*
* @param Translate $outputlangs Output lang to use to autodetect output format if we need 'auto' detection
* @param string $mode 'setup' = Use setup, 'auto' = Force autodetection whatever is setup
* @return array Array('width'=>w,'height'=>h,'unit'=>u);
*/
function pdf_getFormat(Translate $outputlangs = null, $mode = 'setup')
{
global $conf, $db, $langs;
dol_syslog("pdf_getFormat Get paper format with mode=".$mode." MAIN_PDF_FORMAT=".(empty($conf->global->MAIN_PDF_FORMAT)?'null':$conf->global->MAIN_PDF_FORMAT)." outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null')." and langs->defaultlang=".(is_object($langs) ? $langs->defaultlang : 'null'));
// Default value if setup was not done and/or entry into c_paper_format not defined
$width=210; $height=297; $unit='mm';
if ($mode == 'auto' || empty($conf->global->MAIN_PDF_FORMAT) || $conf->global->MAIN_PDF_FORMAT == 'auto')
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$pdfformat=dol_getDefaultFormat($outputlangs);
}
else
{
$pdfformat=$conf->global->MAIN_PDF_FORMAT;
}
$sql="SELECT code, label, width, height, unit FROM ".MAIN_DB_PREFIX."c_paper_format";
$sql.=" WHERE code = '".$db->escape($pdfformat)."'";
$resql=$db->query($sql);
if ($resql)
{
$obj=$db->fetch_object($resql);
if ($obj)
{
$width=(int) $obj->width;
$height=(int) $obj->height;
$unit=$obj->unit;
}
}
//print "pdfformat=".$pdfformat." width=".$width." height=".$height." unit=".$unit;
return array('width'=>$width,'height'=>$height,'unit'=>$unit);
}
/**
* Return a PDF instance object. We create a FPDI instance that instantiate TCPDF.
*
* @param string $format Array(width,height). Keep empty to use default setup.
* @param string $metric Unit of format ('mm')
* @param string $pagetype 'P' or 'l'
* @return TCPDF PDF object
*/
function pdf_getInstance($format = '', $metric = 'mm', $pagetype = 'P')
{
global $conf;
// Define constant for TCPDF
if (! defined('K_TCPDF_EXTERNAL_CONFIG'))
{
define('K_TCPDF_EXTERNAL_CONFIG', 1); // this avoid using tcpdf_config file
define('K_PATH_CACHE', DOL_DATA_ROOT.'/admin/temp/');
define('K_PATH_URL_CACHE', DOL_DATA_ROOT.'/admin/temp/');
dol_mkdir(K_PATH_CACHE);
define('K_BLANK_IMAGE', '_blank.png');
define('PDF_PAGE_FORMAT', 'A4');
define('PDF_PAGE_ORIENTATION', 'P');
define('PDF_CREATOR', 'TCPDF');
define('PDF_AUTHOR', 'TCPDF');
define('PDF_HEADER_TITLE', 'TCPDF Example');
define('PDF_HEADER_STRING', "by Dolibarr ERP CRM");
define('PDF_UNIT', 'mm');
define('PDF_MARGIN_HEADER', 5);
define('PDF_MARGIN_FOOTER', 10);
define('PDF_MARGIN_TOP', 27);
define('PDF_MARGIN_BOTTOM', 25);
define('PDF_MARGIN_LEFT', 15);
define('PDF_MARGIN_RIGHT', 15);
define('PDF_FONT_NAME_MAIN', 'helvetica');
define('PDF_FONT_SIZE_MAIN', 10);
define('PDF_FONT_NAME_DATA', 'helvetica');
define('PDF_FONT_SIZE_DATA', 8);
define('PDF_FONT_MONOSPACED', 'courier');
define('PDF_IMAGE_SCALE_RATIO', 1.25);
define('HEAD_MAGNIFICATION', 1.1);
define('K_CELL_HEIGHT_RATIO', 1.25);
define('K_TITLE_MAGNIFICATION', 1.3);
define('K_SMALL_RATIO', 2/3);
define('K_THAI_TOPCHARS', true);
define('K_TCPDF_CALLS_IN_HTML', true);
define('K_TCPDF_THROW_EXCEPTION_ERROR', false);
}
// Load TCPDF
require_once TCPDF_PATH.'tcpdf.php';
// We need to instantiate tcpdi object (instead of tcpdf) to use merging features. But we can disable it (this will break all merge features).
if (empty($conf->global->MAIN_DISABLE_TCPDI)) require_once TCPDI_PATH.'tcpdi.php';
//$arrayformat=pdf_getFormat();
//$format=array($arrayformat['width'],$arrayformat['height']);
//$metric=$arrayformat['unit'];
$pdfa=false; // PDF-1.3
if (! empty($conf->global->PDF_USE_1A)) $pdfa=true; // PDF1/A
if (class_exists('TCPDI')) $pdf = new TCPDI($pagetype, $metric, $format, true, 'UTF-8', false, $pdfa);
else $pdf = new TCPDF($pagetype, $metric, $format, true, 'UTF-8', false, $pdfa);
// Protection and encryption of pdf
if (! empty($conf->global->PDF_SECURITY_ENCRYPTION))
{
/* Permission supported by TCPDF
- print : Print the document;
- modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';
- copy : Copy or otherwise extract text and graphics from the document;
- annot-forms : Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields);
- fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;
- extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);
- assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;
- print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality.
- owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.
*/
// For TCPDF, we specify permission we want to block
$pdfrights = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS)?json_decode($conf->global->PDF_SECURITY_ENCRYPTION_RIGHTS, true):array('modify','copy')); // Json format in llx_const
// Password for the end user
$pdfuserpass = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_USERPASS)?$conf->global->PDF_SECURITY_ENCRYPTION_USERPASS:'');
// Password of the owner, created randomly if not defined
$pdfownerpass = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_OWNERPASS)?$conf->global->PDF_SECURITY_ENCRYPTION_OWNERPASS:null);
// For encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit
$encstrength = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH)?$conf->global->PDF_SECURITY_ENCRYPTION_STRENGTH:0);
// Array of recipients containing public-key certificates ('c') and permissions ('p').
// For example: array(array('c' => 'file://../examples/data/cert/tcpdf.crt', 'p' => array('print')))
$pubkeys = (! empty($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS)?json_decode($conf->global->PDF_SECURITY_ENCRYPTION_PUBKEYS, true):null); // Json format in llx_const
$pdf->SetProtection($pdfrights, $pdfuserpass, $pdfownerpass, $encstrength, $pubkeys);
}
return $pdf;
}
/**
* Return if pdf file is protected/encrypted
*
* @param string $pathoffile Path of file
* @return boolean True or false
*/
function pdf_getEncryption($pathoffile)
{
require_once TCPDF_PATH.'tcpdf_parser.php';
$isencrypted = false;
$content = file_get_contents($pathoffile);
//ob_start();
@($parser = new \TCPDF_PARSER(ltrim($content)));
list($xref, $data) = $parser->getParsedData();
unset($parser);
//ob_end_clean();
if (isset($xref['trailer']['encrypt'])) {
$isencrypted = true; // Secured pdf file are currently not supported
}
if (empty($data)) {
$isencrypted = true; // Object list not found. Possible secured file
}
return $isencrypted;
}
/**
* Return font name to use for PDF generation
*
* @param Translate $outputlangs Output langs object
* @return string Name of font to use
*/
function pdf_getPDFFont($outputlangs)
{
global $conf;
if (! empty($conf->global->MAIN_PDF_FORCE_FONT)) return $conf->global->MAIN_PDF_FORCE_FONT;
$font='Helvetica'; // By default, for FPDI, or ISO language on TCPDF
if (class_exists('TCPDF')) // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
{
if ($outputlangs->trans('FONTFORPDF')!='FONTFORPDF')
{
$font=$outputlangs->trans('FONTFORPDF');
}
}
return $font;
}
/**
* Return font size to use for PDF generation
*
* @param Translate $outputlangs Output langs object
* @return int Size of font to use
*/
function pdf_getPDFFontSize($outputlangs)
{
$size=10; // By default, for FPDI or ISO language on TCPDF
if (class_exists('TCPDF')) // If TCPDF on, we can use an UTF8 one like DejaVuSans if required (slower)
{
if ($outputlangs->trans('FONTSIZEFORPDF')!='FONTSIZEFORPDF')
{
$size = (int) $outputlangs->trans('FONTSIZEFORPDF');
}
}
return $size;
}
/**
* Return height to use for Logo onto PDF
*
* @param string $logo Full path to logo file to use
* @param bool $url Image with url (true or false)
* @return number
*/
function pdf_getHeightForLogo($logo, $url = false)
{
global $conf;
$height=(empty($conf->global->MAIN_DOCUMENTS_LOGO_HEIGHT)?22:$conf->global->MAIN_DOCUMENTS_LOGO_HEIGHT);
$maxwidth=130;
include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
$tmp=dol_getImageSize($logo, $url);
if ($tmp['height'])
{
$width=round($height*$tmp['width']/$tmp['height']);
if ($width > $maxwidth) $height=$height*$maxwidth/$width;
}
//print $tmp['width'].' '.$tmp['height'].' '.$width; exit;
return $height;
}
/**
* Function to try to calculate height of a HTML Content
*
* @param TCPDF $pdf PDF initialized object
* @param string $htmlcontent HTML Contect
* @return int Height
* @see getStringHeight()
*/
function pdfGetHeightForHtmlContent(&$pdf, $htmlcontent)
{
// store current object
$pdf->startTransaction();
// store starting values
$start_y = $pdf->GetY();
//var_dump($start_y);
$start_page = $pdf->getPage();
// call printing functions with content
$pdf->writeHTMLCell(0, 0, 0, $start_y, $htmlcontent, 0, 1, false, true, 'J', true);
// get the new Y
$end_y = $pdf->GetY();
$end_page = $pdf->getPage();
// calculate height
$height = 0;
if ($end_page == $start_page) {
$height = $end_y - $start_y;
}
else
{
for ($page=$start_page; $page <= $end_page; ++$page) {
$pdf->setPage($page);
$tmpm=$pdf->getMargins();
$tMargin = $tmpm['top'];
if ($page == $start_page) {
// first page
$height = $pdf->getPageHeight() - $start_y - $pdf->getBreakMargin();
} elseif ($page == $end_page) {
// last page
$height = $end_y - $tMargin;
} else {
$height = $pdf->getPageHeight() - $tMargin - $pdf->getBreakMargin();
}
}
}
// restore previous object
$pdf = $pdf->rollbackTransaction();
return $height;
}
/**
* Returns the name of the thirdparty
*
* @param Societe|Contact $thirdparty Contact or thirdparty
* @param Translate $outputlangs Output language
* @param int $includealias 1=Include alias name after name
* @return string String with name of thirdparty (+ alias if requested)
*/
function pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includealias = 0)
{
global $conf;
// Recipient name
$socname = '';
if ($thirdparty instanceof Societe) {
$socname .= $thirdparty->name;
if (($includealias || ! empty($conf->global->PDF_INCLUDE_ALIAS_IN_THIRDPARTY_NAME)) && !empty($thirdparty->name_alias)) {
$socname .= "\n".$thirdparty->name_alias;
}
} elseif ($thirdparty instanceof Contact) {
$socname = $thirdparty->socname;
} else {
throw new InvalidArgumentException('Parameter 1 $thirdparty is not a Societe nor Contact');
}
return $outputlangs->convToOutputCharset($socname);
}
/**
* Return a string with full address formated for output on documents
*
* @param Translate $outputlangs Output langs object
* @param Societe $sourcecompany Source company object
* @param Societe|string|null $targetcompany Target company object
* @param Contact|string|null $targetcontact Target contact object
* @param int $usecontact Use contact instead of company
* @param string $mode Address type ('source', 'target', 'targetwithdetails', 'targetwithdetails_xxx': target but include also phone/fax/email/url)
* @param Object $object Object we want to build document for
* @return string String with full address
*/
function pdf_build_address($outputlangs, $sourcecompany, $targetcompany = '', $targetcontact = '', $usecontact = 0, $mode = 'source', $object = null)
{
global $conf, $hookmanager;
if ($mode == 'source' && ! is_object($sourcecompany)) return -1;
if ($mode == 'target' && ! is_object($targetcompany)) return -1;
if (! empty($sourcecompany->state_id) && empty($sourcecompany->state)) $sourcecompany->state=getState($sourcecompany->state_id);
if (! empty($targetcompany->state_id) && empty($targetcompany->state)) $targetcompany->state=getState($targetcompany->state_id);
$reshook=0;
$stringaddress = '';
if (is_object($hookmanager))
{
$parameters = array('sourcecompany'=>&$sourcecompany, 'targetcompany'=>&$targetcompany, 'targetcontact'=>&$targetcontact, 'outputlangs'=>$outputlangs, 'mode'=>$mode, 'usecontact'=>$usecontact);
$action='';
$reshook = $hookmanager->executeHooks('pdf_build_address', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
$stringaddress.=$hookmanager->resPrint;
}
if (empty($reshook))
{
if ($mode == 'source')
{
$withCountry = 0;
if (!empty($sourcecompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) $withCountry = 1;
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($sourcecompany, $withCountry, "\n", $outputlangs))."\n";
if (empty($conf->global->MAIN_PDF_DISABLESOURCEDETAILS))
{
// Phone
if ($sourcecompany->phone) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("PhoneShort").": ".$outputlangs->convToOutputCharset($sourcecompany->phone);
// Fax
if ($sourcecompany->fax) $stringaddress .= ($stringaddress ? ($sourcecompany->phone ? " - " : "\n") : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($sourcecompany->fax);
// EMail
if ($sourcecompany->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($sourcecompany->email);
// Web
if ($sourcecompany->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($sourcecompany->url);
}
// Intra VAT
if (! empty($conf->global->MAIN_TVAINTRA_IN_SOURCE_ADDRESS))
{
if ($sourcecompany->tva_intra) $stringaddress.=($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($sourcecompany->tva_intra);
}
// Professionnal Ids
if (! empty($conf->global->MAIN_PROFID1_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof1))
{
$tmp=$outputlangs->transcountrynoentities("ProfId1", $sourcecompany->country_code);
if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp=$reg[1];
$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof1);
}
if (! empty($conf->global->MAIN_PROFID2_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof2))
{
$tmp=$outputlangs->transcountrynoentities("ProfId2", $sourcecompany->country_code);
if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp=$reg[1];
$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof2);
}
if (! empty($conf->global->MAIN_PROFID3_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof3))
{
$tmp=$outputlangs->transcountrynoentities("ProfId3", $sourcecompany->country_code);
if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp=$reg[1];
$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof3);
}
if (! empty($conf->global->MAIN_PROFID4_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof4))
{
$tmp=$outputlangs->transcountrynoentities("ProfId4", $sourcecompany->country_code);
if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp=$reg[1];
$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof4);
}
if (! empty($conf->global->MAIN_PROFID5_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof5))
{
$tmp=$outputlangs->transcountrynoentities("ProfId5", $sourcecompany->country_code);
if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp=$reg[1];
$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof5);
}
if (! empty($conf->global->MAIN_PROFID6_IN_SOURCE_ADDRESS) && ! empty($sourcecompany->idprof6))
{
$tmp=$outputlangs->transcountrynoentities("ProfId6", $sourcecompany->country_code);
if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp=$reg[1];
$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($sourcecompany->idprof6);
}
}
if ($mode == 'target' || preg_match('/targetwithdetails/', $mode))
{
if ($usecontact)
{
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs, 1));
if (!empty($targetcontact->address)) {
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcontact));
} else {
$companytouseforaddress = $targetcompany;
// Contact on a thirdparty that is a different thirdparty than the thirdparty of object
if ($targetcontact->socid > 0 && $targetcontact->socid != $targetcompany->id)
{
$targetcontact->fetch_thirdparty();
$companytouseforaddress = $targetcontact->thirdparty;
}
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($companytouseforaddress));
}
// Country
if (!empty($targetcontact->country_code) && $targetcontact->country_code != $sourcecompany->country_code) {
$stringaddress.= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->country_code));
}
elseif (empty($targetcontact->country_code) && !empty($targetcompany->country_code) && ($targetcompany->country_code != $sourcecompany->country_code)) {
$stringaddress.= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code));
}
if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || preg_match('/targetwithdetails/', $mode))
{
// Phone
if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_phone/', $mode))
{
if (! empty($targetcontact->phone_pro) || ! empty($targetcontact->phone_mobile)) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ";
if (! empty($targetcontact->phone_pro)) $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_pro);
if (! empty($targetcontact->phone_pro) && ! empty($targetcontact->phone_mobile)) $stringaddress .= " / ";
if (! empty($targetcontact->phone_mobile)) $stringaddress .= $outputlangs->convToOutputCharset($targetcontact->phone_mobile);
}
// Fax
if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_fax/', $mode))
{
if ($targetcontact->fax) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcontact->fax);
}
// EMail
if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_email/', $mode))
{
if ($targetcontact->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcontact->email);
}
// Web
if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_url/', $mode))
{
if ($targetcontact->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcontact->url);
}
}
}
else
{
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcompany));
// Country
if (!empty($targetcompany->country_code) && $targetcompany->country_code != $sourcecompany->country_code) $stringaddress.=($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->country_code));
if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || preg_match('/targetwithdetails/', $mode))
{
// Phone
if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_phone/', $mode))
{
if (! empty($targetcompany->phone) || ! empty($targetcompany->phone_mobile)) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ";
if (! empty($targetcompany->phone)) $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone);
if (! empty($targetcompany->phone) && ! empty($targetcompany->phone_mobile)) $stringaddress .= " / ";
if (! empty($targetcompany->phone_mobile)) $stringaddress .= $outputlangs->convToOutputCharset($targetcompany->phone_mobile);
}
// Fax
if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_fax/', $mode))
{
if ($targetcompany->fax) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Fax").": ".$outputlangs->convToOutputCharset($targetcompany->fax);
}
// EMail
if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_email/', $mode))
{
if ($targetcompany->email) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$outputlangs->convToOutputCharset($targetcompany->email);
}
// Web
if (! empty($conf->global->MAIN_PDF_ADDALSOTARGETDETAILS) || $mode == 'targetwithdetails' || preg_match('/targetwithdetails_url/', $mode))
{
if ($targetcompany->url) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$outputlangs->convToOutputCharset($targetcompany->url);
}
}
}
// Intra VAT
if (empty($conf->global->MAIN_TVAINTRA_NOT_IN_ADDRESS))
{
if ($targetcompany->tva_intra) $stringaddress.=($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("VATIntraShort").': '.$outputlangs->convToOutputCharset($targetcompany->tva_intra);
}
// Professionnal Ids
if (! empty($conf->global->MAIN_PROFID1_IN_ADDRESS) && ! empty($targetcompany->idprof1))
{
$tmp=$outputlangs->transcountrynoentities("ProfId1", $targetcompany->country_code);
if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp=$reg[1];
$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof1);
}
if (! empty($conf->global->MAIN_PROFID2_IN_ADDRESS) && ! empty($targetcompany->idprof2))
{
$tmp=$outputlangs->transcountrynoentities("ProfId2", $targetcompany->country_code);
if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp=$reg[1];
$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof2);
}
if (! empty($conf->global->MAIN_PROFID3_IN_ADDRESS) && ! empty($targetcompany->idprof3))
{
$tmp=$outputlangs->transcountrynoentities("ProfId3", $targetcompany->country_code);
if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp=$reg[1];
$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof3);
}
if (! empty($conf->global->MAIN_PROFID4_IN_ADDRESS) && ! empty($targetcompany->idprof4))
{
$tmp=$outputlangs->transcountrynoentities("ProfId4", $targetcompany->country_code);
if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp=$reg[1];
$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof4);
}
if (! empty($conf->global->MAIN_PROFID5_IN_ADDRESS) && ! empty($targetcompany->idprof5))
{
$tmp=$outputlangs->transcountrynoentities("ProfId5", $targetcompany->country_code);
if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp=$reg[1];
$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof5);
}
if (! empty($conf->global->MAIN_PROFID6_IN_ADDRESS) && ! empty($targetcompany->idprof6))
{
$tmp=$outputlangs->transcountrynoentities("ProfId6", $targetcompany->country_code);
if (preg_match('/\((.+)\)/', $tmp, $reg)) $tmp=$reg[1];
$stringaddress.=($stringaddress ? "\n" : '' ).$tmp.': '.$outputlangs->convToOutputCharset($targetcompany->idprof6);
}
// Public note
if (! empty($conf->global->MAIN_PUBLIC_NOTE_IN_ADDRESS))
{
if ($mode == 'source' && ! empty($sourcecompany->note_public))
{
$stringaddress.=($stringaddress ? "\n" : '' ).dol_string_nohtmltag($sourcecompany->note_public);
}
if (($mode == 'target' || preg_match('/targetwithdetails/', $mode)) && ! empty($targetcompany->note_public))
{
$stringaddress.=($stringaddress ? "\n" : '' ).dol_string_nohtmltag($targetcompany->note_public);
}
}
}
}
return $stringaddress;
}
/**
* Show header of page for PDF generation
*
* @param TCPDF $pdf Object PDF
* @param Translate $outputlangs Object lang for output
* @param int $page_height Height of page
* @return void
*/
function pdf_pagehead(&$pdf, $outputlangs, $page_height)
{
global $conf;
// Add a background image on document
if (! empty($conf->global->MAIN_USE_BACKGROUND_ON_PDF)) // Warning, this option make TCPDF generation being crazy and some content disappeared behind the image
{
$pdf->SetAutoPageBreak(0, 0); // Disable auto pagebreak before adding image
$pdf->Image($conf->mycompany->dir_output.'/logos/'.$conf->global->MAIN_USE_BACKGROUND_ON_PDF, (isset($conf->global->MAIN_USE_BACKGROUND_ON_PDF_X)?$conf->global->MAIN_USE_BACKGROUND_ON_PDF_X:0), (isset($conf->global->MAIN_USE_BACKGROUND_ON_PDF_Y)?$conf->global->MAIN_USE_BACKGROUND_ON_PDF_Y:0), 0, $page_height);
$pdf->SetAutoPageBreak(1, 0); // Restore pagebreak
}
}
/**
* Return array of possible substitutions for PDF content (without external module substitutions).
*
* @param Translate $outputlangs Output language
* @param array $exclude Array of family keys we want to exclude. For example array('mycompany', 'object', 'date', 'user', ...)
* @param Object $object Object
* @param int $onlykey 1=Do not calculate some heavy values of keys (performance enhancement when we need only the keys), 2=Values are truncated and html sanitized (to use for help tooltip)
* @return array Array of substitutions
*/
function pdf_getSubstitutionArray($outputlangs, $exclude = null, $object = null, $onlykey = 0)
{
$substitutionarray = getCommonSubstitutionArray($outputlangs, $onlykey, $exclude, $object);
$substitutionarray['__FROM_NAME__']='__FROM_NAME__';
$substitutionarray['__FROM_EMAIL__']='__FROM_EMAIL__';
return $substitutionarray;
}
/**
* Add a draft watermark on PDF files
*
* @param TCPDF $pdf Object PDF
* @param Translate $outputlangs Object lang
* @param int $h Height of PDF
* @param int $w Width of PDF
* @param string $unit Unit of height (mm, pt, ...)
* @param string $text Text to show
* @return void
*/
function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
{
global $langs, $mysoc, $user;
// Print Draft Watermark
if ($unit=='pt') $k=1;
elseif ($unit=='mm') $k=72/25.4;
elseif ($unit=='cm') $k=72/2.54;
elseif ($unit=='in') $k=72;
// Make substitution
$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, null);
complete_substitutions_array($substitutionarray, $outputlangs, null);
$text=make_substitutions($text, $substitutionarray, $outputlangs);
$text=$outputlangs->convToOutputCharset($text);
$savx=$pdf->getX(); $savy=$pdf->getY();
$watermark_angle=atan($h/$w)/2;
$watermark_x_pos=0;
$watermark_y_pos=$h/3;
$watermark_x=$w/2;
$watermark_y=$h/3;
$pdf->SetFont('', 'B', 40);
$pdf->SetTextColor(255, 192, 203);
//rotate
$pdf->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm', cos($watermark_angle), sin($watermark_angle), -sin($watermark_angle), cos($watermark_angle), $watermark_x*$k, ($h-$watermark_y)*$k, -$watermark_x*$k, -($h-$watermark_y)*$k));
//print watermark
$pdf->SetXY($watermark_x_pos, $watermark_y_pos);
$pdf->Cell($w-20, 25, $outputlangs->convToOutputCharset($text), "", 2, "C", 0);
//antirotate
$pdf->_out('Q');
$pdf->SetXY($savx, $savy);
}
/**
* Show bank informations for PDF generation
*
* @param TCPDF $pdf Object PDF
* @param Translate $outputlangs Object lang
* @param int $curx X
* @param int $cury Y
* @param Account $account Bank account object
* @param int $onlynumber Output only number (bank+desk+key+number according to country, but without name of bank and domiciliation)
* @param int $default_font_size Default font size
* @return float The Y PDF position
*/
function pdf_bank(&$pdf, $outputlangs, $curx, $cury, $account, $onlynumber = 0, $default_font_size = 10)
{
global $mysoc, $conf;
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbank.class.php';
$diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE);
$diffsizecontent=(empty($conf->global->PDF_DIFFSIZE_CONTENT)?4:$conf->global->PDF_DIFFSIZE_CONTENT);
$pdf->SetXY($curx, $cury);
if (empty($onlynumber))
{
$pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByTransferOnThisBankAccount').':', 0, 'L', 0);
$cury+=4;
}
$outputlangs->load("banks");
// Use correct name of bank id according to country
$bickey="BICNumber";
if ($account->getCountryCode() == 'IN') $bickey="SWIFT";
// Get format of bank account according to its country
$usedetailedbban=$account->useDetailedBBAN();
//$onlynumber=0; $usedetailedbban=1; // For tests
if ($usedetailedbban)
{
$savcurx=$curx;
if (empty($onlynumber))
{
$pdf->SetFont('', '', $default_font_size - $diffsizecontent);
$pdf->SetXY($curx, $cury);
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
$cury+=3;
}
if (empty($conf->global->PDF_BANK_HIDE_NUMBER_SHOW_ONLY_BICIBAN)) // Note that some countries still need bank number, BIC/IBAN not enougth for them
{
// Note:
// bank = code_banque (FR), sort code (GB, IR. Example: 12-34-56)
// desk = code guichet (FR), used only when $usedetailedbban = 1
// number = account number
// key = check control key used only when $usedetailedbban = 1
if (empty($onlynumber)) $pdf->line($curx+1, $cury+1, $curx+1, $cury+6);
foreach ($account->getFieldsToShow() as $val)
{
$pdf->SetXY($curx, $cury+4);
$pdf->SetFont('', '', $default_font_size - 3);
if ($val == 'BankCode') {
// Bank code
$tmplength = 18;
$content = $account->code_banque;
} elseif ($val == 'DeskCode') {
// Desk
$tmplength = 18;
$content = $account->code_guichet;
} elseif ($val == 'BankAccountNumber') {
// Number
$tmplength = 24;
$content = $account->number;
} elseif ($val == 'BankAccountNumberKey') {
// Key
$tmplength = 15;
$content = $account->cle_rib;
}elseif ($val == 'IBAN' || $val == 'BIC') {
// Key
$tmplength = 0;
$content = '';
} else {
dol_print_error($account->db, 'Unexpected value for getFieldsToShow: '.$val);
break;
}
$pdf->MultiCell($tmplength, 3, $outputlangs->convToOutputCharset($content), 0, 'C', 0);
$pdf->SetXY($curx, $cury + 1);
$curx += $tmplength;
$pdf->SetFont('', 'B', $default_font_size - $diffsizecontent);
$pdf->MultiCell($tmplength, 3, $outputlangs->transnoentities($val), 0, 'C', 0);
if (empty($onlynumber)) {
$pdf->line($curx, $cury + 1, $curx, $cury + 7);
}
}
$curx=$savcurx;
$cury+=8;
}
}
else
{
$pdf->SetFont('', 'B', $default_font_size - $diffsizecontent);
$pdf->SetXY($curx, $cury);
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("Bank").': ' . $outputlangs->convToOutputCharset($account->bank), 0, 'L', 0);
$cury+=3;
$pdf->SetFont('', 'B', $default_font_size - $diffsizecontent);
$pdf->SetXY($curx, $cury);
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("BankAccountNumber").': ' . $outputlangs->convToOutputCharset($account->number), 0, 'L', 0);
$cury+=3;
if ($diffsizecontent <= 2) $cury+=1;
}
$pdf->SetFont('', '', $default_font_size - $diffsizecontent);
if (empty($onlynumber) && ! empty($account->domiciliation))
{
$pdf->SetXY($curx, $cury);
$val=$outputlangs->transnoentities("Residence").': ' . $outputlangs->convToOutputCharset($account->domiciliation);
$pdf->MultiCell(100, 3, $val, 0, 'L', 0);
//$nboflines=dol_nboflines_bis($val,120);
//$cury+=($nboflines*3)+2;
$tmpy=$pdf->getStringHeight(100, $val);
$cury+=$tmpy;
}
if (! empty($account->proprio))
{
$pdf->SetXY($curx, $cury);
$val=$outputlangs->transnoentities("BankAccountOwner").': ' . $outputlangs->convToOutputCharset($account->proprio);
$pdf->MultiCell(100, 3, $val, 0, 'L', 0);
$tmpy=$pdf->getStringHeight(100, $val);
$cury+=$tmpy;
$cur+=1;
}
elseif (! $usedetailedbban) $cury+=1;
// Use correct name of bank id according to country
$ibankey = FormBank::getIBANLabel($account);
if (! empty($account->iban))
{
//Remove whitespaces to ensure we are dealing with the format we expect
$ibanDisplay_temp = str_replace(' ', '', $outputlangs->convToOutputCharset($account->iban));
$ibanDisplay = "";
$nbIbanDisplay_temp = dol_strlen($ibanDisplay_temp);
for ($i = 0; $i < $nbIbanDisplay_temp; $i++)
{
$ibanDisplay .= $ibanDisplay_temp[$i];
if($i%4 == 3 && $i > 0) $ibanDisplay .= " ";
}
$pdf->SetFont('', 'B', $default_font_size - 3);
$pdf->SetXY($curx, $cury);
$pdf->MultiCell(100, 3, $outputlangs->transnoentities($ibankey).': ' . $ibanDisplay, 0, 'L', 0);
$cury+=3;
}
if (! empty($account->bic))
{
$pdf->SetFont('', 'B', $default_font_size - 3);
$pdf->SetXY($curx, $cury);
$pdf->MultiCell(100, 3, $outputlangs->transnoentities($bickey).': ' . $outputlangs->convToOutputCharset($account->bic), 0, 'L', 0);
}
return $pdf->getY();
}
/**
* Show footer of page for PDF generation
*
* @param TCPDF $pdf The PDF factory
* @param Translate $outputlangs Object lang for output
* @param string $paramfreetext Constant name of free text
* @param Societe $fromcompany Object company
* @param int $marge_basse Margin bottom we use for the autobreak
* @param int $marge_gauche Margin left (no more used)
* @param int $page_hauteur Page height (no more used)
* @param Object $object Object shown in PDF
* @param int $showdetails Show company adress details into footer (0=Nothing, 1=Show address, 2=Show managers, 3=Both)
* @param int $hidefreetext 1=Hide free text, 0=Show free text
* @return int Return height of bottom margin including footer text
*/
function pdf_pagefoot(&$pdf, $outputlangs, $paramfreetext, $fromcompany, $marge_basse, $marge_gauche, $page_hauteur, $object, $showdetails = 0, $hidefreetext = 0)
{
global $conf,$user,$mysoc;
$outputlangs->load("dict");
$line='';
$dims=$pdf->getPageDimensions();
// Line of free text
if (empty($hidefreetext) && ! empty($conf->global->$paramfreetext))
{
$substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
// More substitution keys
$substitutionarray['__FROM_NAME__']=$fromcompany->name;
$substitutionarray['__FROM_EMAIL__']=$fromcompany->email;
complete_substitutions_array($substitutionarray, $outputlangs, $object);
$newfreetext=make_substitutions($conf->global->$paramfreetext, $substitutionarray, $outputlangs);
// Make a change into HTML code to allow to include images from medias directory.
// <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&entity=1&file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
// become
// <img alt="" src="'.DOL_DATA_ROOT.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" />
$newfreetext=preg_replace('/(<img.*src=")[^\"]*viewimage\.php[^\"]*modulepart=medias[^\"]*file=([^\"]*)("[^\/]*\/>)/', '\1'.DOL_DATA_ROOT.'/medias/\2\3', $newfreetext);
$line.=$outputlangs->convToOutputCharset($newfreetext);
}
// First line of company infos
$line1=""; $line2=""; $line3=""; $line4="";
if ($showdetails == 1 || $showdetails == 3)
{
// Company name
if ($fromcompany->name)
{
$line1.=($line1?" - ":"").$outputlangs->transnoentities("RegisteredOffice").": ".$fromcompany->name;
}
// Address
if ($fromcompany->address)
{
$line1.=($line1?" - ":"").str_replace("\n", ", ", $fromcompany->address);
}
// Zip code
if ($fromcompany->zip)
{
$line1.=($line1?" - ":"").$fromcompany->zip;
}
// Town
if ($fromcompany->town)
{
$line1.=($line1?" ":"").$fromcompany->town;
}
// Country
if ($fromcompany->country)
{
$line1.=($line1?", ":"").$fromcompany->country;
}
// Phone
if ($fromcompany->phone)
{
$line2.=($line2?" - ":"").$outputlangs->transnoentities("Phone").": ".$fromcompany->phone;
}
// Fax
if ($fromcompany->fax)
{
$line2.=($line2?" - ":"").$outputlangs->transnoentities("Fax").": ".$fromcompany->fax;
}
// URL
if ($fromcompany->url)
{
$line2.=($line2?" - ":"").$fromcompany->url;
}
// Email
if ($fromcompany->email)
{
$line2.=($line2?" - ":"").$fromcompany->email;
}
}
if ($showdetails == 2 || $showdetails == 3 || ($fromcompany->country_code == 'DE'))
{
// Managers
if ($fromcompany->managers)
{
$line2.=($line2?" - ":"").$fromcompany->managers;
}
}
// Line 3 of company infos
// Juridical status
if ($fromcompany->forme_juridique_code)
{
$line3.=($line3?" - ":"").$outputlangs->convToOutputCharset(getFormeJuridiqueLabel($fromcompany->forme_juridique_code));
}
// Capital
if ($fromcompany->capital)
{
$tmpamounttoshow = price2num($fromcompany->capital); // This field is a free string
if (is_numeric($tmpamounttoshow) && $tmpamounttoshow > 0) $line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf", price($tmpamounttoshow, 0, $outputlangs, 0, 0, 0, $conf->currency));
else $line3.=($line3?" - ":"").$outputlangs->transnoentities("CapitalOf", $tmpamounttoshow, $outputlangs);
}
// Prof Id 1
if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2))
{
$field=$outputlangs->transcountrynoentities("ProfId1", $fromcompany->country_code);
if (preg_match('/\((.*)\)/i', $field, $reg)) $field=$reg[1];
$line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof1);
}
// Prof Id 2
if ($fromcompany->idprof2)
{
$field=$outputlangs->transcountrynoentities("ProfId2", $fromcompany->country_code);
if (preg_match('/\((.*)\)/i', $field, $reg)) $field=$reg[1];
$line3.=($line3?" - ":"").$field.": ".$outputlangs->convToOutputCharset($fromcompany->idprof2);
}