92 public function Add_PDF_card(&$pdf, $textleft, $header, $footer, $outputlangs, $textright =
'', $idmember = 0, $photo =
'')
95 global $db, $mysoc, $conf, $langs;
96 global $forceimgscalewidth, $forceimgscaleheight;
98 $imgscalewidth = (empty($forceimgscalewidth) ? 0.3 : $forceimgscalewidth);
99 $imgscaleheight = (empty($forceimgscalewidth) ? 0.5 : $forceimgscalewidth);
102 if (($this->_COUNTX == 0) && ($this->_COUNTY == 0) and (!$this->_First == 1)) {
106 $_PosX = $this->_Margin_Left + ($this->_COUNTX * ($this->_Width + $this->_X_Space));
107 $_PosY = $this->_Margin_Top + ($this->_COUNTY * ($this->_Height + $this->_Y_Space));
110 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
111 if (!is_readable($logo)) {
113 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small)) {
114 $logo = $conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small;
115 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$mysoc->logo)) {
116 $logo = $conf->mycompany->dir_output.
'/logos/'.$mysoc->logo;
121 $member->id = $idmember;
122 $member->ref = $idmember;
125 $dir = $conf->adherent->dir_output;
126 if (!empty($photo)) {
127 $file =
get_exdir(0, 0, 0, 0, $member,
'member').
'photos/'.$photo;
128 $photo = $dir.
'/'.$file;
129 if (!is_readable($photo)) {
135 $backgroundimage =
'';
137 $backgroundimage = $conf->adherent->dir_output.
'/' .
getDolGlobalString(
'ADHERENT_CARD_BACKGROUND');
141 if ($this->code ==
"CARD") {
142 $this->Tformat = $this->_Avery_Labels[
"CARD"];
144 $this->
_Croix($pdf, $_PosX, $_PosY, $_PosX + $this->_Width, $_PosY + $this->_Height, 0.1, 10);
148 if ($backgroundimage) {
149 $pdf->image($backgroundimage, $_PosX, $_PosY, $this->_Width, $this->_Height);
157 if ($this->code ==
"CARD") {
158 $pdf->SetDrawColor(128, 128, 128);
159 $pdf->Line($_PosX, $_PosY + $this->_Line_Height + 1, $_PosX + $this->_Width, $_PosY + $this->_Line_Height + 1);
160 $pdf->SetDrawColor(0, 0, 0);
162 $pdf->SetXY($_PosX + $xleft, $_PosY + 1);
163 $pdf->Cell($this->_Width - 2 * $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($header), 0, 1,
'C');
167 $ytop += (empty($header) ? 0 : (1 + $this->_Line_Height));
170 $maxwidthtouse = round(($this->_Width - 2 * $xleft) * $imgscalewidth);
171 $maxheighttouse = round(($this->_Height - 2 * $ytop) * $imgscaleheight);
172 $defaultratio = ($maxwidthtouse / $maxheighttouse);
173 $widthtouse = $maxwidthtouse;
176 if (isset($tmp[
'height'])) {
177 $imgratio = $tmp[
'width'] / $tmp[
'height'];
178 if ($imgratio >= $defaultratio) {
179 $widthtouse = $maxwidthtouse;
180 $heighttouse = round($widthtouse / $imgratio);
182 $heighttouse = $maxheighttouse;
183 $widthtouse = round($heighttouse * $imgratio);
189 if ($textright ==
'') {
191 if ($textleft ==
'__LOGO__' && $logo) {
192 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
193 } elseif ($textleft ==
'__PHOTO__' && $photo) {
194 $pdf->Image($photo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
196 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
197 $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
199 } elseif ($textleft !=
'' && $textright !=
'') {
200 if ($textleft ==
'__LOGO__' || $textleft ==
'__PHOTO__') {
201 if ($textleft ==
'__LOGO__' && $logo) {
202 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
203 } elseif ($textleft ==
'__PHOTO__' && $photo) {
204 $pdf->Image($photo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
206 $pdf->SetXY($_PosX + $xleft + $widthtouse + 1, $_PosY + $ytop);
207 $pdf->MultiCell($this->_Width - $xleft - $xleft - $widthtouse - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
208 } elseif ($textright ==
'__LOGO__' || $textright ==
'__PHOTO__') {
209 if ($textright ==
'__LOGO__' && $logo) {
210 $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
211 } elseif ($textright ==
'__PHOTO__' && $photo) {
212 $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
214 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
215 $pdf->MultiCell($this->_Width - $widthtouse - $xleft - $xleft - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
217 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
218 $pdf->MultiCell(round($this->_Width / 2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0,
'L');
219 $pdf->SetXY($_PosX + round($this->_Width / 2), $_PosY + $ytop);
220 $pdf->MultiCell(round($this->_Width / 2) - 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
224 if ($textright ==
'__LOGO__' && $logo) {
225 $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
226 } elseif ($textright ==
'__PHOTO__' && $photo) {
227 $pdf->Image($photo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
229 $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop);
230 $pdf->MultiCell($this->_Width - $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0,
'R');
236 if ($this->code ==
"CARD") {
237 $pdf->SetDrawColor(128, 128, 128);
238 $pdf->Line($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 2, $_PosX + $this->_Width, $_PosY + $this->_Height - $this->_Line_Height - 2);
239 $pdf->SetDrawColor(0, 0, 0);
241 $pdf->SetXY($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 1);
242 $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer), 0, 1,
'C');
248 if ($this->_COUNTY == $this->_Y_Number) {
254 if ($this->_COUNTX == $this->_X_Number) {
273 public function write_file($object, $outputlangs, $srctemplatepath, $mode =
'member', $nooutput = 0, $filename =
'tmp_cards')
276 global $user, $conf, $langs, $mysoc, $_Avery_Labels;
278 $this->code = $srctemplatepath;
280 if (is_object($object)) {
281 if ($object->country ==
'-') {
282 $object->country =
'';
291 $substitutionarray = array(
292 '__ID__' => $object->id,
293 '__REF__' => $object->ref,
294 '__LOGIN__' => empty($object->login) ?
'' : $object->login,
295 '__FIRSTNAME__' => empty($object->firstname) ?
'' : $object->firstname,
296 '__LASTNAME__' => empty($object->lastname) ?
'' : $object->lastname,
297 '__FULLNAME__' => $object->getFullName($langs),
298 '__COMPANY__' => empty($object->company) ?
'' : $object->company,
299 '__ADDRESS__' => empty($object->address) ?
'' : $object->address,
300 '__ZIP__' => empty($object->zip) ?
'' : $object->zip,
301 '__TOWN__' => empty($object->town) ?
'' : $object->town,
302 '__COUNTRY__' => empty($object->country) ?
'' : $object->country,
303 '__COUNTRY_CODE__' => empty($object->country_code) ?
'' : $object->country_code,
304 '__EMAIL__' => empty($object->email) ?
'' : $object->email,
306 '__TYPE__' => empty($object->type) ?
'' : $object->type,
308 '__MONTH__' => $month,
310 '__DOL_MAIN_URL_ROOT__' => DOL_MAIN_URL_ROOT,
311 '__SERVER__' =>
"https://".$_SERVER[
"SERVER_NAME"].
"/"
321 $nb = $_Avery_Labels[$this->code][
'NX'] * $_Avery_Labels[$this->code][
'NY'];
326 for ($j = 0; $j < $nb; $j++) {
327 $arrayofmembers[] = array(
328 'textleft'=>$textleft,
329 'textheader'=>$textheader,
330 'textfooter'=>$textfooter,
331 'textright'=>$textright,
332 'id'=>(isset($object->id) ? $object->id :
""),
333 'photo'=>(isset($object->photo) ? $object->photo :
"")
337 $arrayofrecords = $arrayofmembers;
340 $arrayofrecords = $object;
343 $this->Tformat = $_Avery_Labels[$this->code];
344 if (empty($this->Tformat)) {
353 if ($this->Tformat[
'paper-size'] !=
'custom') {
354 $this->format = $this->Tformat[
'paper-size'];
357 $resolution = array($this->Tformat[
'custom_x'], $this->Tformat[
'custom_y']);
358 $this->format = $resolution;
361 if (!is_object($outputlangs)) {
362 $outputlangs = $langs;
366 $outputlangs->charset_output =
'ISO-8859-1';
370 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"admin",
"members"));
372 if (empty($mode) || $mode ==
'member') {
373 $title = $outputlangs->transnoentities(
'MembersCards');
374 $keywords = $outputlangs->transnoentities(
'MembersCards').
" ".$outputlangs->transnoentities(
"Foundation").
" ".$outputlangs->convToOutputCharset($mysoc->name);
381 if (is_object($object)) {
382 $outputdir = $conf->adherent->dir_output;
383 $dir = $outputdir.
"/".
get_exdir(0, 0, 0, 0, $object,
'member');
384 $file = $dir.
'/'.$filename;
386 $outputdir = $conf->adherent->dir_temp;
388 $file = $dir.
'/'.$filename;
393 if (!file_exists($dir)) {
395 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
400 $pdf =
pdf_getInstance($this->format, $this->Tformat[
'metric'], $this->Tformat[
'orientation']);
402 if (class_exists(
'TCPDF')) {
403 $pdf->setPrintHeader(
false);
404 $pdf->setPrintFooter(
false);
408 $pdf->SetTitle($title);
409 $pdf->SetSubject($title);
410 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
411 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
412 $pdf->SetKeyWords($keywords);
414 $pdf->SetCompression(
false);
417 $pdf->SetMargins(0, 0);
418 $pdf->SetAutoPageBreak(
false);
420 $this->_Metric_Doc = $this->Tformat[
'metric'];
434 $this->_COUNTX = $posX;
435 $this->_COUNTY = $posY;
444 foreach ($arrayofrecords as $val) {
446 $this->
Add_PDF_card($pdf, $val[
'textleft'], $val[
'textheader'], $val[
'textfooter'], $langs, $val[
'textright'], $val[
'id'], $val[
'photo']);
454 $pdf->Output($file,
'F');
458 $this->result = array(
'fullpath'=>$file);
461 if (empty($nooutput)) {
472 header(
'Content-Type: '.$type);
475 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
477 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
481 header(
'Cache-Control: Public, must-revalidate');
482 header(
'Pragma: public');