29 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonstickergenerator.class.php';
66 public function Add_PDF_card(&$pdf, $textleft, $header, $footer, $outputlangs, $textright =
'', $idmember = 0, $photo =
'')
69 global $db, $mysoc, $conf, $langs;
70 global $forceimgscalewidth, $forceimgscaleheight;
72 $imgscalewidth = (empty($forceimgscalewidth) ? 0.3 : $forceimgscalewidth);
73 $imgscaleheight = (empty($forceimgscalewidth) ? 0.5 : $forceimgscalewidth);
76 if (($this->_COUNTX == 0) && ($this->_COUNTY == 0) and (!$this->_First == 1)) {
80 $_PosX = $this->_Margin_Left + ($this->_COUNTX * ($this->_Width + $this->_X_Space));
81 $_PosY = $this->_Margin_Top + ($this->_COUNTY * ($this->_Height + $this->_Y_Space));
84 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
85 if (!is_readable($logo))
88 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small))
90 $logo = $conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small;
91 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$mysoc->logo))
93 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
98 $member->id = $idmember;
99 $member->ref = $idmember;
102 $dir = $conf->adherent->dir_output;
105 $file =
get_exdir(0, 0, 0, 0, $member,
'member').
'photos/'.$photo;
106 $photo = $dir.
'/'.$file;
107 if (!is_readable($photo)) $photo =
'';
111 $backgroundimage =
'';
112 if (!empty($conf->global->ADHERENT_CARD_BACKGROUND) && file_exists($conf->adherent->dir_output.
'/'.$conf->global->ADHERENT_CARD_BACKGROUND))
114 $backgroundimage = $conf->adherent->dir_output.
'/'.$conf->global->ADHERENT_CARD_BACKGROUND;
118 if ($this->
code ==
"CARD")
120 $this->Tformat = $this->_Avery_Labels[
"CARD"];
122 $this->
_Croix($pdf, $_PosX, $_PosY, $_PosX + $this->_Width, $_PosY + $this->_Height, 0.1, 10);
126 if ($backgroundimage)
128 $pdf->image($backgroundimage, $_PosX, $_PosY, $this->_Width, $this->_Height);
131 $xleft = 2; $ytop = 2;
136 if ($this->
code ==
"CARD")
138 $pdf->SetDrawColor(128, 128, 128);
139 $pdf->Line($_PosX, $_PosY + $this->_Line_Height + 1, $_PosX + $this->_Width, $_PosY + $this->_Line_Height + 1);
140 $pdf->SetDrawColor(0, 0, 0);
142 $pdf->SetXY($_PosX + $xleft, $_PosY + 1);
143 $pdf->Cell($this->_Width - 2 * $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($header), 0, 1,
'C');
147 $ytop += (empty($header) ? 0 : (1 + $this->_Line_Height));
150 $maxwidthtouse = round(($this->_Width - 2 * $xleft) * $imgscalewidth); $maxheighttouse = round(($this->_Height - 2 * $ytop) * $imgscaleheight);
151 $defaultratio = ($maxwidthtouse / $maxheighttouse);
152 $widthtouse = $maxwidthtouse; $heighttouse = 0;
156 $imgratio = $tmp[
'width'] / $tmp[
'height'];
157 if ($imgratio >= $defaultratio) { $widthtouse = $maxwidthtouse; $heighttouse = round($widthtouse / $imgratio); }
else { $heightouse = $maxheighttouse; $widthtouse = round($heightouse * $imgratio); }
162 if ($textright ==
'')
165 if ($textleft ==
'__LOGO__' && $logo) $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
166 elseif ($textleft ==
'__PHOTO__' && $photo) $pdf->Image($photo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
168 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
169 $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
171 } elseif ($textleft !=
'' && $textright !=
'')
173 if ($textleft ==
'__LOGO__' || $textleft ==
'__PHOTO__')
175 if ($textleft ==
'__LOGO__' && $logo) $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
176 elseif ($textleft ==
'__PHOTO__' && $photo) $pdf->Image($photo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
177 $pdf->SetXY($_PosX + $xleft + $widthtouse + 1, $_PosY + $ytop);
178 $pdf->MultiCell($this->_Width - $xleft - $xleft - $widthtouse - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
179 } elseif ($textright ==
'__LOGO__' || $textright ==
'__PHOTO__')
181 if ($textright ==
'__LOGO__' && $logo) $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
182 elseif ($textright ==
'__PHOTO__' && $photo) $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
183 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
184 $pdf->MultiCell($this->_Width - $widthtouse - $xleft - $xleft - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
187 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
188 $pdf->MultiCell(round($this->_Width / 2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
189 $pdf->SetXY($_PosX + round($this->_Width / 2), $_PosY + $ytop);
190 $pdf->MultiCell(round($this->_Width / 2) - 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
195 if ($textright ==
'__LOGO__' && $logo) $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
196 elseif ($textright ==
'__PHOTO__' && $photo) $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
198 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
199 $pdf->MultiCell($this->_Width - $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
206 if ($this->
code ==
"CARD")
208 $pdf->SetDrawColor(128, 128, 128);
209 $pdf->Line($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 2, $_PosX + $this->_Width, $_PosY + $this->_Height - $this->_Line_Height - 2);
210 $pdf->SetDrawColor(0, 0, 0);
212 $pdf->SetXY($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 1);
213 $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer), 0, 1,
'C');
219 if ($this->_COUNTY == $this->_Y_Number) {
225 if ($this->_COUNTX == $this->_X_Number) {
243 public function write_file($object, $outputlangs, $srctemplatepath, $mode =
'member', $nooutput = 0)
246 global $user, $conf, $langs, $mysoc, $_Avery_Labels;
248 $this->
code = $srctemplatepath;
250 if (is_object($object))
252 if ($object->country ==
'-') $object->country =
'';
260 $substitutionarray = array(
261 '__ID__' => $object->id,
262 '__LOGIN__'=>$object->login,
263 '__FIRSTNAME__'=>$object->firstname,
264 '__LASTNAME__'=>$object->lastname,
265 '__FULLNAME__'=>$object->getFullName($langs),
266 '__COMPANY__'=>$object->company,
267 '__ADDRESS__'=>$object->address,
268 '__ZIP__'=>$object->zip,
269 '__TOWN__'=>$object->town,
270 '__COUNTRY__'=>$object->country,
271 '__COUNTRY_CODE__'=>$object->country_code,
272 '__EMAIL__'=>$object->email,
274 '__TYPE__'=>$object->type,
278 '__DOL_MAIN_URL_ROOT__'=>DOL_MAIN_URL_ROOT,
279 '__SERVER__'=>
"http://".$_SERVER[
"SERVER_NAME"].
"/"
284 $textleft =
make_substitutions($conf->global->ADHERENT_CARD_TEXT, $substitutionarray);
285 $textheader =
make_substitutions($conf->global->ADHERENT_CARD_HEADER_TEXT, $substitutionarray);
286 $textfooter =
make_substitutions($conf->global->ADHERENT_CARD_FOOTER_TEXT, $substitutionarray);
287 $textright =
make_substitutions($conf->global->ADHERENT_CARD_TEXT_RIGHT, $substitutionarray);
289 $nb = $_Avery_Labels[$this->code][
'NX'] * $_Avery_Labels[$this->code][
'NY'];
290 if ($nb <= 0) $nb = 1;
292 for ($j = 0; $j < $nb; $j++)
294 $arrayofmembers[] = array(
295 'textleft'=>$textleft,
296 'textheader'=>$textheader,
297 'textfooter'=>$textfooter,
298 'textright'=>$textright,
299 'id'=>$object->rowid,
300 'photo'=>$object->photo
304 $arrayofrecords = $arrayofmembers;
306 $arrayofrecords = $object;
311 $this->Tformat = $_Avery_Labels[$this->code];
312 if (empty($this->Tformat)) {
dol_print_error(
'',
'ErrorBadTypeForCard'.$this->
code); exit; }
315 if ($this->Tformat[
'paper-size'] !=
'custom') {
316 $this->format = $this->Tformat[
'paper-size'];
319 $resolution = array($this->Tformat[
'custom_x'], $this->Tformat[
'custom_y']);
320 $this->format = $resolution;
323 if (!is_object($outputlangs)) $outputlangs = $langs;
325 if (!empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output =
'ISO-8859-1';
328 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"admin",
"members"));
330 if (empty($mode) || $mode ==
'member')
332 $title = $outputlangs->transnoentities(
'MembersCards');
333 $keywords = $outputlangs->transnoentities(
'MembersCards').
" ".$outputlangs->transnoentities(
"Foundation").
" ".$outputlangs->convToOutputCharset($mysoc->name);
339 $filename =
'tmp_cards.pdf';
340 if (is_object($object))
342 $outputdir = $conf->adherent->dir_output;
343 $dir = $outputdir.
"/".
get_exdir(0, 0, 0, 0, $object,
'member');
344 $file = $dir.
'/'.$filename;
346 $outputdir = $conf->adherent->dir_temp;
348 $file = $dir.
'/'.$filename;
353 if (!file_exists($dir))
357 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
362 $pdf =
pdf_getInstance($this->format, $this->Tformat[
'metric'], $this->Tformat[
'orientation']);
364 if (class_exists(
'TCPDF'))
366 $pdf->setPrintHeader(
false);
367 $pdf->setPrintFooter(
false);
371 $pdf->SetTitle($title);
372 $pdf->SetSubject($title);
373 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
374 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
375 $pdf->SetKeyWords($keywords);
376 if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(
false);
378 $pdf->SetMargins(0, 0);
379 $pdf->SetAutoPageBreak(
false);
381 $this->_Metric_Doc = $this->Tformat[
'metric'];
385 if ($posX > 0) $posX--;
else $posX = 0;
386 if ($posY > 0) $posY--;
else $posY = 0;
387 $this->_COUNTX = $posX;
388 $this->_COUNTY = $posY;
397 foreach ($arrayofrecords as $val)
400 $this->
Add_PDF_card($pdf, $val[
'textleft'], $val[
'textheader'], $val[
'textfooter'], $langs, $val[
'textright'], $val[
'id'], $val[
'photo']);
408 $pdf->Output($file,
'F');
410 if (!empty($conf->global->MAIN_UMASK))
411 @chmod($file, octdec($conf->global->MAIN_UMASK));
414 $this->result = array(
'fullpath'=>$file);
417 if (empty($nooutput))
422 if (!empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment =
false;
426 if ($type) header(
'Content-Type: '.$type);
427 if ($attachment) header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
428 else header(
'Content-Disposition: inline; filename="'.$filename.
'"');
431 header(
'Cache-Control: Public, must-revalidate');
432 header(
'Pragma: public');
_Croix(&$pdf, $x1=0, $y1=0, $x2=210, $y2=297, $epaisseur=1, $taille=4)
protected Function realisant une croix aux 4 coins des cartes
if(!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'] country if(!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'] typent code
dol_getImageSize($file, $url=false)
Return size of image file on disk (Supported extensions are gif, jpg, png and bmp) ...
dol_now($mode= 'auto')
Return date for now.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
Class to generate stick sheet with format Avery or other personalised.
write_file($object, $outputlangs, $srctemplatepath, $mode= 'member', $nooutput=0)
Function to build PDF on disk, then output on HTTP stream.
Class to generate expense report based on standard model.
dol_mimetype($file, $default= 'application/octet-stream', $mode=0)
Return mime type of a file.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart= '')
Return a path to have a the directory according to object where files are stored. ...
Class to manage members of a foundation.
pdf_getInstance($format= '', $metric= 'mm', $pagetype= 'P')
Return a PDF instance object.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
_Set_Format(&$pdf, $format)
protected Set format
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
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) ...
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
addSticker(&$pdf, $outputlangs, $param)
Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) ...
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
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...