95 public function Add_PDF_card(&$pdf, $textleft, $header, $footer, $outputlangs, $textright =
'', $idmember = 0, $photo =
'')
98 global $db,
$mysoc, $conf, $langs;
99 global $forceimgscalewidth, $forceimgscaleheight;
101 $imgscalewidth = (empty($forceimgscalewidth) ? 0.3 : $forceimgscalewidth);
102 $imgscaleheight = (empty($forceimgscalewidth) ? 0.5 : $forceimgscalewidth);
105 if (($this->_COUNTX == 0) && ($this->_COUNTY == 0) and (!$this->_First == 1)) {
109 $_PosX = $this->_Margin_Left + ($this->_COUNTX * ($this->_Width + $this->_X_Space));
110 $_PosY = $this->_Margin_Top + ($this->_COUNTY * ($this->_Height + $this->_Y_Space));
113 $logo = $conf->mycompany->dir_output.
'/logos/'.
$mysoc->logo;
114 if (!is_readable($logo)) {
116 if (!empty(
$mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.
$mysoc->logo_small)) {
117 $logo = $conf->mycompany->dir_output.
'/logos/thumbs/'.
$mysoc->logo_small;
118 } elseif (!empty(
$mysoc->logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.
$mysoc->logo)) {
119 $logo = $conf->mycompany->dir_output.
'/logos/'.
$mysoc->logo;
124 $member->id = $idmember;
125 $member->ref = (string) $idmember;
128 $dir = $conf->adherent->dir_output;
129 if (!empty($photo)) {
130 $file =
get_exdir(0, 0, 0, 0, $member,
'member').
'photos/'.$photo;
131 $photo = $dir.
'/'.$file;
132 if (!is_readable($photo)) {
138 $backgroundimage =
'';
140 $backgroundimage = $conf->adherent->dir_output.
'/' .
getDolGlobalString(
'ADHERENT_CARD_BACKGROUND');
144 if ($this->code ==
"CARD") {
145 $this->Tformat = $this->_Avery_Labels[
"CARD"];
147 $this->
_Croix($pdf, $_PosX, $_PosY, $_PosX + $this->_Width, $_PosY + $this->_Height, 0.1, 10);
151 if ($backgroundimage) {
152 $pdf->image($backgroundimage, $_PosX, $_PosY, $this->_Width, $this->_Height);
160 if ($this->code ==
"CARD") {
161 $pdf->SetDrawColor(128, 128, 128);
162 $pdf->Line($_PosX, $_PosY + $this->_Line_Height + 1, $_PosX + $this->_Width, $_PosY + $this->_Line_Height + 1);
163 $pdf->SetDrawColor(0, 0, 0);
165 $pdf->SetXY($_PosX + $xleft, $_PosY + 1);
166 $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__' || $textleft ==
'__MEMBER_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__' || $textleft ==
'__MEMBER_PHOTO__') {
203 if ($textleft ==
'__LOGO__' && $logo) {
204 $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
205 } elseif (($textleft ==
'__PHOTO__' || $textright ==
'__MEMBER_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__' || $textright ==
'__MEMBER_PHOTO__') {
211 if ($textright ==
'__LOGO__' && $logo) {
212 $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse);
213 } elseif (($textright ==
'__PHOTO__' || $textright ==
'__MEMBER_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__' || $textright ==
'__MEMBER_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 =
'', $filename =
'tmp_cards')
278 global $user, $conf, $langs,
$mysoc;
280 $this->code = $srctemplatepath;
282 if (!is_object($outputlangs)) {
283 $outputlangs = $langs;
298 $substitutionarray = array(
299 '__MEMBER_ID__' => (
string)
$object->id,
300 '__MEMBER_REF__' =>
$object->ref,
301 '__MEMBER_LOGIN__' => empty(
$object->login) ?
'' :
$object->login,
302 '__MEMBER_CIVILITY__' => empty(
$object->civility) ?
'' : $outputlangs->trans(
"Civility".
$object->civility),
303 '__MEMBER_FIRSTNAME__' => empty(
$object->firstname) ?
'' :
$object->firstname,
304 '__MEMBER_LASTNAME__' => empty(
$object->lastname) ?
'' :
$object->lastname,
305 '__MEMBER_FULLNAME__' =>
$object->getFullName($outputlangs),
306 '__MEMBER_COMPANY__' => empty(
$object->company) ?
'' :
$object->company,
307 '__MEMBER_ADDRESS__' => empty(
$object->address) ?
'' :
$object->address,
310 '__MEMBER_COUNTRY__' => empty(
$object->country) ?
'' :
$object->country,
311 '__MEMBER_COUNTRY_CODE__' => empty(
$object->country_code) ?
'' :
$object->country_code,
312 '__MEMBER_EMAIL__' => empty(
$object->email) ?
'' :
$object->email,
316 '__MONTH__' => $month,
318 '__DOL_MAIN_URL_ROOT__' => (string) DOL_MAIN_URL_ROOT,
319 '__SERVER__' =>
"https://".$_SERVER[
"SERVER_NAME"].
"/"
323 $substitutionarrayold = array(
324 '__ID__' => (
string)
$object->id,
327 '__CIVILITY__' => empty(
$object->civility) ?
'' : $outputlangs->trans(
"Civility".
$object->civility),
328 '__FIRSTNAME__' => empty(
$object->firstname) ?
'' :
$object->firstname,
329 '__LASTNAME__' => empty(
$object->lastname) ?
'' :
$object->lastname,
330 '__FULLNAME__' =>
$object->getFullName($outputlangs),
336 '__COUNTRY_CODE__' => empty(
$object->country_code) ?
'' :
$object->country_code,
350 $substitutionarray = array_merge($substitutionarray, $substitutionarrayold);
359 $nb = $this->_Avery_Labels[$this->code][
'NX'] * $this->_Avery_Labels[$this->code][
'NY'];
364 $arrayofmembers = array();
365 for ($j = 0; $j < $nb; $j++) {
366 $arrayofmembers[] = array(
367 'textleft' => $textleft,
368 'textheader' => $textheader,
369 'textfooter' => $textfooter,
370 'textright' => $textright,
376 $arrayofrecords = $arrayofmembers;
383 $this->Tformat = $this->_Avery_Labels[$this->code];
384 if (empty($this->Tformat)) {
393 $paper_size = $this->Tformat[
'paper-size'];
394 if (!is_string($paper_size) || $paper_size !=
'custom') {
395 $this->format = $paper_size;
398 $resolution = array($this->Tformat[
'custom_x'], $this->Tformat[
'custom_y']);
399 $this->format = $resolution;
404 $outputlangs->charset_output =
'ISO-8859-1';
408 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"admin",
"members"));
410 if (empty($mode) || $mode ==
'member') {
411 $title = $outputlangs->transnoentities(
'MembersCards');
412 $keywords = $outputlangs->transnoentities(
'MembersCards').
" ".$outputlangs->transnoentities(
"Foundation").
" ".$outputlangs->convToOutputCharset(
$mysoc->name);
420 $outputdir = $conf->adherent->dir_output;
422 $file = $dir.
'/'.$filename;
424 $outputdir = $conf->adherent->dir_temp;
426 $file = $dir.
'/'.$filename;
429 if (!file_exists($dir)) {
431 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
436 $pdf =
pdf_getInstance($this->format, $this->Tformat[
'metric'], $this->Tformat[
'orientation']);
438 if (class_exists(
'TCPDF')) {
439 $pdf->setPrintHeader(
false);
440 $pdf->setPrintFooter(
false);
444 $pdf->SetTitle($title);
445 $pdf->SetSubject($title);
446 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
447 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
448 $pdf->SetKeyWords($keywords);
450 $pdf->SetCompression(
false);
453 $pdf->SetMargins(0, 0);
454 $pdf->setAutoPageBreak(
false);
456 $this->_Metric_Doc = $this->Tformat[
'metric'];
470 $this->_COUNTX = $posX;
471 $this->_COUNTY = $posY;
480 foreach ($arrayofrecords as $val) {
482 $this->
Add_PDF_card($pdf, $val[
'textleft'], $val[
'textheader'], $val[
'textfooter'], $langs, $val[
'textright'], $val[
'id'], $val[
'photo']);
490 $pdf->Output($file,
'F');
494 $this->result = array(
'fullpath' => $file);
497 if (empty($nooutput)) {
508 header(
'Content-Type: '.$type);
511 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
513 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
517 header(
'Cache-Control: Public, must-revalidate');
518 header(
'Pragma: public');