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 =
'';
136 if (!empty($conf->global->ADHERENT_CARD_BACKGROUND) && file_exists($conf->adherent->dir_output.
'/'.$conf->global->ADHERENT_CARD_BACKGROUND)) {
137 $backgroundimage = $conf->adherent->dir_output.
'/'.$conf->global->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');
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');
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;
282 if (is_object($object)) {
283 if ($object->country ==
'-') {
284 $object->country =
'';
293 $substitutionarray = array(
294 '__ID__' => $object->rowid,
295 '__REF__' => $object->ref,
296 '__LOGIN__' => empty($object->login) ?
'' : $object->login,
297 '__FIRSTNAME__' => empty($object->firstname) ?
'' : $object->firstname,
298 '__LASTNAME__' => empty($object->lastname) ?
'' : $object->lastname,
299 '__FULLNAME__' => $object->getFullName($langs),
300 '__COMPANY__' => empty($object->company) ?
'' : $object->company,
301 '__ADDRESS__' => empty($object->address) ?
'' : $object->address,
302 '__ZIP__' => empty($object->zip) ?
'' : $object->zip,
303 '__TOWN__' => empty($object->town) ?
'' : $object->town,
304 '__COUNTRY__' => empty($object->country) ?
'' : $object->country,
305 '__COUNTRY_CODE__' => empty($object->country_code) ?
'' : $object->country_code,
306 '__EMAIL__' => empty($object->email) ?
'' : $object->email,
308 '__TYPE__' => empty($object->type) ?
'' : $object->type,
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 for ($j = 0; $j < $nb; $j++) {
329 $arrayofmembers[] = array(
330 'textleft'=>$textleft,
331 'textheader'=>$textheader,
332 'textfooter'=>$textfooter,
333 'textright'=>$textright,
334 'id'=>(isset($object->rowid) ? $object->rowid :
""),
335 'photo'=>(isset($object->photo) ? $object->photo :
"")
339 $arrayofrecords = $arrayofmembers;
342 $arrayofrecords = $object;
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;
367 if (!empty($conf->global->MAIN_USE_FPDF)) {
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);
383 if (is_object($object)) {
384 $outputdir = $conf->adherent->dir_output;
385 $dir = $outputdir.
"/".
get_exdir(0, 0, 0, 0, $object,
'member');
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)) {
467 if (!empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) {
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');