29 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonstickergenerator.class.php';
40 public $version =
'dolibarr';
50 global $conf, $langs, $mysoc;
53 $langs->loadLangs(array(
"main",
"admin"));
56 $this->
name =
"standard";
57 $this->
description = $langs->trans(
'TemplateforBusinessCards');
60 $this->
type =
'pdf-various-sizes';
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->id,
295 '__LOGIN__'=>$object->login,
296 '__FIRSTNAME__'=>$object->firstname,
297 '__LASTNAME__'=>$object->lastname,
298 '__FULLNAME__'=>$object->getFullName($langs),
299 '__COMPANY__'=>$object->company,
300 '__ADDRESS__'=>$object->address,
301 '__ZIP__'=>$object->zip,
302 '__TOWN__'=>$object->town,
303 '__COUNTRY__'=>$object->country,
304 '__COUNTRY_CODE__'=>$object->country_code,
305 '__EMAIL__'=>$object->email,
307 '__TYPE__'=>$object->type,
311 '__DOL_MAIN_URL_ROOT__'=>DOL_MAIN_URL_ROOT,
312 '__SERVER__'=>
"https://".$_SERVER[
"SERVER_NAME"].
"/"
322 $nb = $_Avery_Labels[$this->code][
'NX'] * $_Avery_Labels[$this->code][
'NY'];
327 for ($j = 0; $j < $nb; $j++) {
328 $arrayofmembers[] = array(
329 'textleft'=>$textleft,
330 'textheader'=>$textheader,
331 'textfooter'=>$textfooter,
332 'textright'=>$textright,
333 'id'=>(isset($object->rowid) ? $object->rowid :
""),
334 'photo'=>(isset($object->photo) ? $object->photo :
"")
338 $arrayofrecords = $arrayofmembers;
340 $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');
458 if (!empty($conf->global->MAIN_UMASK)) {
459 @chmod($file, octdec($conf->global->MAIN_UMASK));
463 $this->result = array(
'fullpath'=>$file);
466 if (empty($nooutput)) {
470 if (!empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) {
477 header(
'Content-Type: '.$type);
480 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
482 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
486 header(
'Cache-Control: Public, must-revalidate');
487 header(
'Pragma: public');
Class to manage members of a foundation.
Class to generate stick sheet with format Avery or other personalised.
_Croix(&$pdf, $x1=0, $y1=0, $x2=210, $y2=297, $epaisseur=1, $taille=4)
protected Function realisant une croix aux 4 coins des cartes
_Set_Format(&$pdf, $format)
protected Set format
Class to generate expense report based on standard model.
Add_PDF_card(&$pdf, $textleft, $header, $footer, $outputlangs, $textright='', $idmember=0, $photo='')
Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0)
__construct($db)
Constructor.
addSticker(&$pdf, $outputlangs, $param)
Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0)
write_file($object, $outputlangs, $srctemplatepath, $mode='member', $nooutput=0, $filename='tmp_cards')
Function to build PDF on disk, then output on HTTP stream.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_getImageSize($file, $url=false)
Return size of image file on disk (Supported extensions are gif, jpg, png, bmp and webp)
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.
$conf db
API class for accounts.
print *****$script_file(".$version.") pid code
! Closing after partial payment: discount_vat, badcustomer or badsupplier, bankcharge,...