30 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonstickergenerator.class.php';
41 public $version =
'dolibarr';
51 global $conf, $langs, $mysoc;
54 $langs->loadLangs(array(
"main",
"admin"));
57 $this->
name =
"standard";
58 $this->
description = $langs->trans(
'TemplateforBusinessCards');
61 $this->
type =
'pdf-various-sizes';
93 public function Add_PDF_card(&$pdf, $textleft, $header, $footer, $outputlangs, $textright =
'', $idmember = 0, $photo =
'')
96 global $db, $mysoc, $conf, $langs;
97 global $forceimgscalewidth, $forceimgscaleheight;
99 $imgscalewidth = (empty($forceimgscalewidth) ? 0.3 : $forceimgscalewidth);
100 $imgscaleheight = (empty($forceimgscalewidth) ? 0.5 : $forceimgscalewidth);
103 if (($this->_COUNTX == 0) && ($this->_COUNTY == 0) and (!$this->_First == 1)) {
107 $_PosX = $this->_Margin_Left + ($this->_COUNTX * ($this->_Width + $this->_X_Space));
108 $_PosY = $this->_Margin_Top + ($this->_COUNTY * ($this->_Height + $this->_Y_Space));
111 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
112 if (!is_readable($logo)) {
114 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small)) {
115 $logo = $conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small;
116 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$mysoc->logo)) {
117 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
122 $member->id = $idmember;
123 $member->ref = (string) $idmember;
126 $dir = $conf->adherent->dir_output;
127 if (!empty($photo)) {
128 $file =
get_exdir(0, 0, 0, 0, $member,
'member').
'photos/'.$photo;
129 $photo = $dir.
'/'.$file;
130 if (!is_readable($photo)) {
136 $backgroundimage =
'';
138 $backgroundimage = $conf->adherent->dir_output.
'/' .
getDolGlobalString(
'ADHERENT_CARD_BACKGROUND');
142 if ($this->
code ==
"CARD") {
143 $this->Tformat = $this->_Avery_Labels[
"CARD"];
145 $this->
_Croix($pdf, $_PosX, $_PosY, $_PosX + $this->_Width, $_PosY + $this->_Height, 0.1, 10);
149 if ($backgroundimage) {
150 $pdf->image($backgroundimage, $_PosX, $_PosY, $this->_Width, $this->_Height);
158 if ($this->
code ==
"CARD") {
159 $pdf->SetDrawColor(128, 128, 128);
160 $pdf->Line($_PosX, $_PosY + $this->_Line_Height + 1, $_PosX + $this->_Width, $_PosY + $this->_Line_Height + 1);
161 $pdf->SetDrawColor(0, 0, 0);
163 $pdf->SetXY($_PosX + $xleft, $_PosY + 1);
164 $pdf->Cell($this->_Width - 2 * $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($header), 0, 1,
'C');
168 $ytop += (empty($header) ? 0 : (1 + $this->_Line_Height));
171 $maxwidthtouse = round(($this->_Width - 2 * $xleft) * $imgscalewidth);
172 $maxheighttouse = round(($this->_Height - 2 * $ytop) * $imgscaleheight);
173 $defaultratio = ($maxwidthtouse / $maxheighttouse);
174 $widthtouse = $maxwidthtouse;
177 if (isset($tmp[
'height'])) {
178 $imgratio = $tmp[
'width'] / $tmp[
'height'];
179 if ($imgratio >= $defaultratio) {
180 $widthtouse = $maxwidthtouse;
181 $heighttouse = round($widthtouse / $imgratio);
183 $heighttouse = $maxheighttouse;
184 $widthtouse = round($heighttouse * $imgratio);
190 if ($textright ==
'') {
192 if ($textleft ==
'__LOGO__' && $logo) {
193 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
194 } elseif ($textleft ==
'__PHOTO__' && $photo) {
195 $pdf->Image($photo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
197 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
198 $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
200 } elseif ($textleft !=
'' && $textright !=
'') {
201 if ($textleft ==
'__LOGO__' || $textleft ==
'__PHOTO__') {
202 if ($textleft ==
'__LOGO__' && $logo) {
203 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
204 } elseif ($textleft ==
'__PHOTO__' && $photo) {
205 $pdf->Image($photo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
207 $pdf->SetXY($_PosX + $xleft + $widthtouse + 1, $_PosY + $ytop);
208 $pdf->MultiCell($this->_Width - $xleft - $xleft - $widthtouse - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
209 } elseif ($textright ==
'__LOGO__' || $textright ==
'__PHOTO__') {
210 if ($textright ==
'__LOGO__' && $logo) {
211 $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
212 } elseif ($textright ==
'__PHOTO__' && $photo) {
213 $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
215 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
216 $pdf->MultiCell($this->_Width - $widthtouse - $xleft - $xleft - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
218 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
219 $pdf->MultiCell(round($this->_Width / 2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
220 $pdf->SetXY($_PosX + round($this->_Width / 2), $_PosY + $ytop);
221 $pdf->MultiCell(round($this->_Width / 2) - 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
225 if ($textright ==
'__LOGO__' && $logo) {
226 $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
227 } elseif ($textright ==
'__PHOTO__' && $photo) {
228 $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
230 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
231 $pdf->MultiCell($this->_Width - $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
237 if ($this->
code ==
"CARD") {
238 $pdf->SetDrawColor(128, 128, 128);
239 $pdf->Line($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 2, $_PosX + $this->_Width, $_PosY + $this->_Height - $this->_Line_Height - 2);
240 $pdf->SetDrawColor(0, 0, 0);
242 $pdf->SetXY($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 1);
243 $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer), 0, 1,
'C');
249 if ($this->_COUNTY == $this->_Y_Number) {
255 if ($this->_COUNTX == $this->_X_Number) {
274 public function write_file(
$object, $outputlangs, $srctemplatepath, $mode =
'member', $nooutput = 0, $filename =
'tmp_cards')
277 global $user, $conf, $langs, $mysoc, $_Avery_Labels;
279 $this->
code = $srctemplatepath;
292 $substitutionarray = array(
296 '__FIRSTNAME__' => empty(
$object->firstname) ?
'' :
$object->firstname,
297 '__LASTNAME__' => empty(
$object->lastname) ?
'' :
$object->lastname,
298 '__FULLNAME__' =>
$object->getFullName($langs),
304 '__COUNTRY_CODE__' => empty(
$object->country_code) ?
'' :
$object->country_code,
309 '__MONTH__' => $month,
311 '__DOL_MAIN_URL_ROOT__' => DOL_MAIN_URL_ROOT,
312 '__SERVER__' =>
"https://".$_SERVER[
"SERVER_NAME"].
"/"
322 $nb = $_Avery_Labels[$this->code][
'NX'] * $_Avery_Labels[$this->code][
'NY'];
327 $arrayofmembers = array();
328 for ($j = 0; $j < $nb; $j++) {
329 $arrayofmembers[] = array(
330 'textleft' => $textleft,
331 'textheader' => $textheader,
332 'textfooter' => $textfooter,
333 'textright' => $textright,
339 $arrayofrecords = $arrayofmembers;
345 $this->Tformat = $_Avery_Labels[$this->code];
346 if (empty($this->Tformat)) {
355 if ($this->Tformat[
'paper-size'] !=
'custom') {
356 $this->format = $this->Tformat[
'paper-size'];
359 $resolution = array($this->Tformat[
'custom_x'], $this->Tformat[
'custom_y']);
360 $this->format = $resolution;
363 if (!is_object($outputlangs)) {
364 $outputlangs = $langs;
368 $outputlangs->charset_output =
'ISO-8859-1';
372 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"admin",
"members"));
374 if (empty($mode) || $mode ==
'member') {
375 $title = $outputlangs->transnoentities(
'MembersCards');
376 $keywords = $outputlangs->transnoentities(
'MembersCards').
" ".$outputlangs->transnoentities(
"Foundation").
" ".$outputlangs->convToOutputCharset($mysoc->name);
384 $outputdir = $conf->adherent->dir_output;
386 $file = $dir.
'/'.$filename;
388 $outputdir = $conf->adherent->dir_temp;
390 $file = $dir.
'/'.$filename;
395 if (!file_exists($dir)) {
397 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
402 $pdf =
pdf_getInstance($this->format, $this->Tformat[
'metric'], $this->Tformat[
'orientation']);
404 if (class_exists(
'TCPDF')) {
405 $pdf->setPrintHeader(
false);
406 $pdf->setPrintFooter(
false);
410 $pdf->SetTitle($title);
411 $pdf->SetSubject($title);
412 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
413 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
414 $pdf->SetKeyWords($keywords);
416 $pdf->SetCompression(
false);
419 $pdf->SetMargins(0, 0);
420 $pdf->SetAutoPageBreak(
false);
422 $this->_Metric_Doc = $this->Tformat[
'metric'];
436 $this->_COUNTX = $posX;
437 $this->_COUNTY = $posY;
446 foreach ($arrayofrecords as $val) {
448 $this->
Add_PDF_card($pdf, $val[
'textleft'], $val[
'textheader'], $val[
'textfooter'], $langs, $val[
'textright'], $val[
'id'], $val[
'photo']);
456 $pdf->Output($file,
'F');
460 $this->result = array(
'fullpath' => $file);
463 if (empty($nooutput)) {
474 header(
'Content-Type: '.$type);
477 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
479 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
483 header(
'Cache-Control: Public, must-revalidate');
484 header(
'Pragma: public');
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage members of a foundation.
Class to generate stick sheet with format Avery or other personalised.
_Croix(&$pdf, $x1=0, $y1=0, $x2=210, $y2=297, $epaisseur=1, $taille=4)
protected Function realisant une croix aux 4 coins des cartes
_Set_Format(&$pdf, $format)
protected Set format
Class to generate expense report based on standard model.
Add_PDF_card(&$pdf, $textleft, $header, $footer, $outputlangs, $textright='', $idmember=0, $photo='')
Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0)
__construct($db)
Constructor.
addSticker(&$pdf, $outputlangs, $param)
Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0)
write_file($object, $outputlangs, $srctemplatepath, $mode='member', $nooutput=0, $filename='tmp_cards')
Function to build PDF on disk, then output on HTTP stream.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_getImageSize($file, $url=false)
Return size of image file on disk (Supported extensions are gif, jpg, png, bmp and webp)
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.
print *****$script_file(".$version.") pid code
1: frais de port 2: ecotaxe 3: option line (when qty = 0)