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 $paper_size = $this->Tformat[
'paper-size'];
357 if (!is_string($paper_size) || $paper_size !=
'custom') {
358 $this->format = $paper_size;
361 $resolution = array($this->Tformat[
'custom_x'], $this->Tformat[
'custom_y']);
362 $this->format = $resolution;
365 if (!is_object($outputlangs)) {
366 $outputlangs = $langs;
370 $outputlangs->charset_output =
'ISO-8859-1';
374 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"admin",
"members"));
376 if (empty($mode) || $mode ==
'member') {
377 $title = $outputlangs->transnoentities(
'MembersCards');
378 $keywords = $outputlangs->transnoentities(
'MembersCards').
" ".$outputlangs->transnoentities(
"Foundation").
" ".$outputlangs->convToOutputCharset($mysoc->name);
386 $outputdir = $conf->adherent->dir_output;
388 $file = $dir.
'/'.$filename;
390 $outputdir = $conf->adherent->dir_temp;
392 $file = $dir.
'/'.$filename;
397 if (!file_exists($dir)) {
399 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
404 $pdf =
pdf_getInstance($this->format, $this->Tformat[
'metric'], $this->Tformat[
'orientation']);
406 if (class_exists(
'TCPDF')) {
407 $pdf->setPrintHeader(
false);
408 $pdf->setPrintFooter(
false);
412 $pdf->SetTitle($title);
413 $pdf->SetSubject($title);
414 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
415 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
416 $pdf->SetKeyWords($keywords);
418 $pdf->SetCompression(
false);
421 $pdf->SetMargins(0, 0);
422 $pdf->SetAutoPageBreak(
false);
424 $this->_Metric_Doc = $this->Tformat[
'metric'];
438 $this->_COUNTX = $posX;
439 $this->_COUNTY = $posY;
448 foreach ($arrayofrecords as $val) {
450 $this->
Add_PDF_card($pdf, $val[
'textleft'], $val[
'textheader'], $val[
'textfooter'], $langs, $val[
'textright'], $val[
'id'], $val[
'photo']);
458 $pdf->Output($file,
'F');
462 $this->result = array(
'fullpath' => $file);
465 if (empty($nooutput)) {
476 header(
'Content-Type: '.$type);
479 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
481 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
485 header(
'Cache-Control: Public, must-revalidate');
486 header(
'Pragma: public');