94 public function Add_PDF_card(&$pdf, $textleft, $header, $footer, $outputlangs, $textright =
'', $idmember = 0, $photo =
'')
97 global $db, $mysoc, $conf, $langs;
98 global $forceimgscalewidth, $forceimgscaleheight;
100 $imgscalewidth = (empty($forceimgscalewidth) ? 0.3 : $forceimgscalewidth);
101 $imgscaleheight = (empty($forceimgscalewidth) ? 0.5 : $forceimgscalewidth);
104 if (($this->_COUNTX == 0) && ($this->_COUNTY == 0) and (!$this->_First == 1)) {
108 $_PosX = $this->_Margin_Left + ($this->_COUNTX * ($this->_Width + $this->_X_Space));
109 $_PosY = $this->_Margin_Top + ($this->_COUNTY * ($this->_Height + $this->_Y_Space));
112 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
113 if (!is_readable($logo)) {
115 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small)) {
116 $logo = $conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small;
117 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$mysoc->logo)) {
118 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
123 $member->id = $idmember;
124 $member->ref = (string) $idmember;
127 $dir = $conf->adherent->dir_output;
128 if (!empty($photo)) {
129 $file =
get_exdir(0, 0, 0, 0, $member,
'member').
'photos/'.$photo;
130 $photo = $dir.
'/'.$file;
131 if (!is_readable($photo)) {
137 $backgroundimage =
'';
139 $backgroundimage = $conf->adherent->dir_output.
'/' .
getDolGlobalString(
'ADHERENT_CARD_BACKGROUND');
143 if ($this->code ==
"CARD") {
144 $this->Tformat = $this->_Avery_Labels[
"CARD"];
146 $this->
_Croix($pdf, $_PosX, $_PosY, $_PosX + $this->_Width, $_PosY + $this->_Height, 0.1, 10);
150 if ($backgroundimage) {
151 $pdf->image($backgroundimage, $_PosX, $_PosY, $this->_Width, $this->_Height);
159 if ($this->code ==
"CARD") {
160 $pdf->SetDrawColor(128, 128, 128);
161 $pdf->Line($_PosX, $_PosY + $this->_Line_Height + 1, $_PosX + $this->_Width, $_PosY + $this->_Line_Height + 1);
162 $pdf->SetDrawColor(0, 0, 0);
164 $pdf->SetXY($_PosX + $xleft, $_PosY + 1);
165 $pdf->Cell($this->_Width - 2 * $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($header), 0, 1,
'C');
169 $ytop += (empty($header) ? 0 : (1 + $this->_Line_Height));
172 $maxwidthtouse = round(($this->_Width - 2 * $xleft) * $imgscalewidth);
173 $maxheighttouse = round(($this->_Height - 2 * $ytop) * $imgscaleheight);
174 $defaultratio = ($maxwidthtouse / $maxheighttouse);
175 $widthtouse = $maxwidthtouse;
178 if (isset($tmp[
'height'])) {
179 $imgratio = $tmp[
'width'] / $tmp[
'height'];
180 if ($imgratio >= $defaultratio) {
181 $widthtouse = $maxwidthtouse;
182 $heighttouse = round($widthtouse / $imgratio);
184 $heighttouse = $maxheighttouse;
185 $widthtouse = round($heighttouse * $imgratio);
191 if ($textright ==
'') {
193 if ($textleft ==
'__LOGO__' && $logo) {
194 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
195 } elseif ($textleft ==
'__PHOTO__' && $photo) {
196 $pdf->Image($photo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
198 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
199 $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
201 } elseif ($textleft !=
'' && $textright !=
'') {
202 if ($textleft ==
'__LOGO__' || $textleft ==
'__PHOTO__') {
203 if ($textleft ==
'__LOGO__' && $logo) {
204 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
205 } elseif ($textleft ==
'__PHOTO__' && $photo) {
206 $pdf->Image($photo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
208 $pdf->SetXY($_PosX + $xleft + $widthtouse + 1, $_PosY + $ytop);
209 $pdf->MultiCell($this->_Width - $xleft - $xleft - $widthtouse - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
210 } elseif ($textright ==
'__LOGO__' || $textright ==
'__PHOTO__') {
211 if ($textright ==
'__LOGO__' && $logo) {
212 $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
213 } elseif ($textright ==
'__PHOTO__' && $photo) {
214 $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
216 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
217 $pdf->MultiCell($this->_Width - $widthtouse - $xleft - $xleft - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
219 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
220 $pdf->MultiCell(round($this->_Width / 2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
221 $pdf->SetXY($_PosX + round($this->_Width / 2), $_PosY + $ytop);
222 $pdf->MultiCell(round($this->_Width / 2) - 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
226 if ($textright ==
'__LOGO__' && $logo) {
227 $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
228 } elseif ($textright ==
'__PHOTO__' && $photo) {
229 $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
231 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
232 $pdf->MultiCell($this->_Width - $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
238 if ($this->code ==
"CARD") {
239 $pdf->SetDrawColor(128, 128, 128);
240 $pdf->Line($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 2, $_PosX + $this->_Width, $_PosY + $this->_Height - $this->_Line_Height - 2);
241 $pdf->SetDrawColor(0, 0, 0);
243 $pdf->SetXY($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 1);
244 $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer), 0, 1,
'C');
250 if ($this->_COUNTY == $this->_Y_Number) {
256 if ($this->_COUNTX == $this->_X_Number) {
275 public function write_file(
$object, $outputlangs, $srctemplatepath, $mode =
'member', $nooutput = 0, $filename =
'tmp_cards')
278 global $user, $conf, $langs, $mysoc, $_Avery_Labels;
280 $this->code = $srctemplatepath;
293 $substitutionarray = array(
297 '__FIRSTNAME__' => empty(
$object->firstname) ?
'' :
$object->firstname,
298 '__LASTNAME__' => empty(
$object->lastname) ?
'' :
$object->lastname,
299 '__FULLNAME__' =>
$object->getFullName($langs),
305 '__COUNTRY_CODE__' => empty(
$object->country_code) ?
'' :
$object->country_code,
310 '__MONTH__' => $month,
312 '__DOL_MAIN_URL_ROOT__' => DOL_MAIN_URL_ROOT,
313 '__SERVER__' =>
"https://".$_SERVER[
"SERVER_NAME"].
"/"
323 $nb = $_Avery_Labels[$this->code][
'NX'] * $_Avery_Labels[$this->code][
'NY'];
328 $arrayofmembers = array();
329 for ($j = 0; $j < $nb; $j++) {
330 $arrayofmembers[] = array(
331 'textleft' => $textleft,
332 'textheader' => $textheader,
333 'textfooter' => $textfooter,
334 'textright' => $textright,
340 $arrayofrecords = $arrayofmembers;
346 $this->Tformat = $_Avery_Labels[$this->code];
347 if (empty($this->Tformat)) {
356 if ($this->Tformat[
'paper-size'] !=
'custom') {
357 $this->format = $this->Tformat[
'paper-size'];
360 $resolution = array($this->Tformat[
'custom_x'], $this->Tformat[
'custom_y']);
361 $this->format = $resolution;
364 if (!is_object($outputlangs)) {
365 $outputlangs = $langs;
369 $outputlangs->charset_output =
'ISO-8859-1';
373 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"admin",
"members"));
375 if (empty($mode) || $mode ==
'member') {
376 $title = $outputlangs->transnoentities(
'MembersCards');
377 $keywords = $outputlangs->transnoentities(
'MembersCards').
" ".$outputlangs->transnoentities(
"Foundation").
" ".$outputlangs->convToOutputCharset($mysoc->name);
385 $outputdir = $conf->adherent->dir_output;
387 $file = $dir.
'/'.$filename;
389 $outputdir = $conf->adherent->dir_temp;
391 $file = $dir.
'/'.$filename;
396 if (!file_exists($dir)) {
398 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
403 $pdf =
pdf_getInstance($this->format, $this->Tformat[
'metric'], $this->Tformat[
'orientation']);
405 if (class_exists(
'TCPDF')) {
406 $pdf->setPrintHeader(
false);
407 $pdf->setPrintFooter(
false);
411 $pdf->SetTitle($title);
412 $pdf->SetSubject($title);
413 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
414 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
415 $pdf->SetKeyWords($keywords);
417 $pdf->SetCompression(
false);
420 $pdf->SetMargins(0, 0);
421 $pdf->SetAutoPageBreak(
false);
423 $this->_Metric_Doc = $this->Tformat[
'metric'];
437 $this->_COUNTX = $posX;
438 $this->_COUNTY = $posY;
447 foreach ($arrayofrecords as $val) {
449 $this->
Add_PDF_card($pdf, $val[
'textleft'], $val[
'textheader'], $val[
'textfooter'], $langs, $val[
'textright'], $val[
'id'], $val[
'photo']);
457 $pdf->Output($file,
'F');
461 $this->result = array(
'fullpath' => $file);
464 if (empty($nooutput)) {
475 header(
'Content-Type: '.$type);
478 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
480 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
484 header(
'Cache-Control: Public, must-revalidate');
485 header(
'Pragma: public');