| Conditions | 80 |
| Paths | > 20000 |
| Total Lines | 493 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 157 | public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0) |
||
| 158 | { |
||
| 159 | // phpcs:enable |
||
| 160 | global $user,$conf,$langs,$hookmanager; |
||
| 161 | |||
| 162 | $object->fetch_thirdparty(); |
||
| 163 | |||
| 164 | if (! is_object($outputlangs)) $outputlangs=$langs; |
||
| 165 | // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO |
||
| 166 | if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; |
||
| 167 | |||
| 168 | // Load traductions files requiredby by page |
||
| 169 | $outputlangs->loadLangs(array("main", "bills", "products", "dict", "companies", "propal", "deliveries", "sendings", "productbatch")); |
||
| 170 | |||
| 171 | $nblines = count($object->lines); |
||
| 172 | |||
| 173 | // Loop on each lines to detect if there is at least one image to show |
||
| 174 | $realpatharray=array(); |
||
| 175 | if (! empty($conf->global->MAIN_GENERATE_SHIPMENT_WITH_PICTURE)) |
||
| 176 | { |
||
| 177 | $objphoto = new Product($this->db); |
||
| 178 | |||
| 179 | for ($i = 0 ; $i < $nblines ; $i++) |
||
| 180 | { |
||
| 181 | if (empty($object->lines[$i]->fk_product)) continue; |
||
| 182 | |||
| 183 | $objphoto = new Product($this->db); |
||
| 184 | $objphoto->fetch($object->lines[$i]->fk_product); |
||
| 185 | |||
| 186 | $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product') . $object->lines[$i]->fk_product ."/photos/"; |
||
| 187 | $dir = $conf->product->dir_output.'/'.$pdir; |
||
| 188 | |||
| 189 | $realpath=''; |
||
| 190 | |||
| 191 | foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) |
||
| 192 | { |
||
| 193 | if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo |
||
| 194 | { |
||
| 195 | if ($obj['photo_vignette']) |
||
| 196 | { |
||
| 197 | $filename=$obj['photo_vignette']; |
||
| 198 | } |
||
| 199 | else |
||
| 200 | { |
||
| 201 | $filename=$obj['photo']; |
||
| 202 | } |
||
| 203 | } |
||
| 204 | else |
||
| 205 | { |
||
| 206 | $filename=$obj['photo']; |
||
| 207 | } |
||
| 208 | |||
| 209 | $realpath = $dir.$filename; |
||
| 210 | break; |
||
| 211 | } |
||
| 212 | |||
| 213 | if ($realpath) $realpatharray[$i]=$realpath; |
||
| 214 | } |
||
| 215 | } |
||
| 216 | |||
| 217 | if (count($realpatharray) == 0) $this->posxpicture=$this->posxweightvol; |
||
| 218 | |||
| 219 | if ($conf->expedition->dir_output) |
||
| 220 | { |
||
| 221 | // Definition de $dir et $file |
||
| 222 | if ($object->specimen) |
||
| 223 | { |
||
| 224 | $dir = $conf->expedition->dir_output."/sending"; |
||
| 225 | $file = $dir . "/SPECIMEN.pdf"; |
||
| 226 | } |
||
| 227 | else |
||
| 228 | { |
||
| 229 | $expref = dol_sanitizeFileName($object->ref); |
||
| 230 | $dir = $conf->expedition->dir_output."/sending/" . $expref; |
||
| 231 | $file = $dir . "/" . $expref . ".pdf"; |
||
| 232 | } |
||
| 233 | |||
| 234 | if (! file_exists($dir)) |
||
| 235 | { |
||
| 236 | if (dol_mkdir($dir) < 0) |
||
| 237 | { |
||
| 238 | $this->error=$langs->transnoentities("ErrorCanNotCreateDir", $dir); |
||
| 239 | return 0; |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | if (file_exists($dir)) |
||
| 244 | { |
||
| 245 | // Add pdfgeneration hook |
||
| 246 | if (! is_object($hookmanager)) |
||
| 247 | { |
||
| 248 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
||
| 249 | $hookmanager=new HookManager($this->db); |
||
| 250 | } |
||
| 251 | $hookmanager->initHooks(array('pdfgeneration')); |
||
| 252 | $parameters=array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs); |
||
| 253 | global $action; |
||
| 254 | $reshook=$hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
| 255 | |||
| 256 | // Set nblines with the new facture lines content after hook |
||
| 257 | $nblines = count($object->lines); |
||
| 258 | |||
| 259 | $pdf=pdf_getInstance($this->format); |
||
| 260 | $default_font_size = pdf_getPDFFontSize($outputlangs); |
||
| 261 | $heightforinfotot = 8; // Height reserved to output the info and total part |
||
| 262 | $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5); // Height reserved to output the free text on last page |
||
| 263 | $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) |
||
| 264 | if ($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS >0) $heightforfooter+= 6; |
||
| 265 | $pdf->SetAutoPageBreak(1, 0); |
||
| 266 | |||
| 267 | if (class_exists('TCPDF')) |
||
| 268 | { |
||
| 269 | $pdf->setPrintHeader(false); |
||
| 270 | $pdf->setPrintFooter(false); |
||
| 271 | } |
||
| 272 | $pdf->SetFont(pdf_getPDFFont($outputlangs)); |
||
| 273 | // Set path to the background PDF File |
||
| 274 | if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) |
||
| 275 | { |
||
| 276 | $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); |
||
| 277 | $tplidx = $pdf->importPage(1); |
||
| 278 | } |
||
| 279 | |||
| 280 | $pdf->Open(); |
||
| 281 | $pagenb=0; |
||
| 282 | $pdf->SetDrawColor(128, 128, 128); |
||
| 283 | |||
| 284 | if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages(); |
||
| 285 | |||
| 286 | $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); |
||
| 287 | $pdf->SetSubject($outputlangs->transnoentities("Shipment")); |
||
| 288 | $pdf->SetCreator("Dolibarr ".DOL_VERSION); |
||
| 289 | $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); |
||
| 290 | $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Shipment")); |
||
| 291 | if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); |
||
| 292 | |||
| 293 | $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right |
||
| 294 | |||
| 295 | // New page |
||
| 296 | $pdf->AddPage(); |
||
| 297 | if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
||
| 298 | $pagenb++; |
||
| 299 | $this->_pagehead($pdf, $object, 1, $outputlangs); |
||
| 300 | $pdf->SetFont('', '', $default_font_size - 1); |
||
| 301 | $pdf->MultiCell(0, 3, ''); // Set interline to 3 |
||
| 302 | $pdf->SetTextColor(0, 0, 0); |
||
| 303 | |||
| 304 | $tab_top = 90; |
||
| 305 | $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); |
||
| 306 | $tab_height = 130; |
||
| 307 | $tab_height_newpage = 150; |
||
| 308 | |||
| 309 | // Incoterm |
||
| 310 | $height_incoterms = 0; |
||
| 311 | if ($conf->incoterm->enabled) |
||
| 312 | { |
||
| 313 | $desc_incoterms = $object->getIncotermsForPDF(); |
||
| 314 | if ($desc_incoterms) |
||
| 315 | { |
||
| 316 | $tab_top = 88; |
||
| 317 | |||
| 318 | $pdf->SetFont('', '', $default_font_size - 1); |
||
| 319 | $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1); |
||
| 320 | $nexY = $pdf->GetY(); |
||
| 321 | $height_incoterms=$nexY-$tab_top; |
||
| 322 | |||
| 323 | // Rect prend une longueur en 3eme param |
||
| 324 | $pdf->SetDrawColor(192, 192, 192); |
||
| 325 | $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1); |
||
| 326 | |||
| 327 | $tab_top = $nexY+6; |
||
| 328 | $height_incoterms += 4; |
||
| 329 | } |
||
| 330 | } |
||
| 331 | |||
| 332 | if (! empty($object->note_public) || ! empty($object->tracking_number)) |
||
| 333 | { |
||
| 334 | $tab_top = 88 + $height_incoterms; |
||
| 335 | $tab_top_alt = $tab_top; |
||
| 336 | |||
| 337 | $pdf->SetFont('', 'B', $default_font_size - 2); |
||
| 338 | $pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top-1, $outputlangs->transnoentities("TrackingNumber")." : " . $object->tracking_number, 0, 1, false, true, 'L'); |
||
| 339 | |||
| 340 | $tab_top_alt = $pdf->GetY(); |
||
| 341 | //$tab_top_alt += 1; |
||
| 342 | |||
| 343 | // Tracking number |
||
| 344 | if (! empty($object->tracking_number)) |
||
| 345 | { |
||
| 346 | $object->getUrlTrackingStatus($object->tracking_number); |
||
| 347 | if (! empty($object->tracking_url)) |
||
| 348 | { |
||
| 349 | if ($object->shipping_method_id > 0) |
||
| 350 | { |
||
| 351 | // Get code using getLabelFromKey |
||
| 352 | $code=$outputlangs->getLabelFromKey($this->db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code'); |
||
| 353 | $label=''; |
||
| 354 | if ($object->tracking_url != $object->tracking_number) $label.=$outputlangs->trans("LinkToTrackYourPackage")."<br>"; |
||
| 355 | $label.=$outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code)); |
||
| 356 | //var_dump($object->tracking_url != $object->tracking_number);exit; |
||
| 357 | if ($object->tracking_url != $object->tracking_number) |
||
| 358 | { |
||
| 359 | $label.=" : "; |
||
| 360 | $label.=$object->tracking_url; |
||
| 361 | } |
||
| 362 | $pdf->SetFont('', 'B', $default_font_size - 2); |
||
| 363 | $pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top_alt, $label, 0, 1, false, true, 'L'); |
||
| 364 | |||
| 365 | $tab_top_alt = $pdf->GetY(); |
||
| 366 | } |
||
| 367 | } |
||
| 368 | } |
||
| 369 | |||
| 370 | // Notes |
||
| 371 | if (! empty($object->note_public)) |
||
| 372 | { |
||
| 373 | $pdf->SetFont('', '', $default_font_size - 1); // Dans boucle pour gerer multi-page |
||
| 374 | $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1); |
||
| 375 | } |
||
| 376 | |||
| 377 | $nexY = $pdf->GetY(); |
||
| 378 | $height_note=$nexY-$tab_top; |
||
| 379 | |||
| 380 | // Rect prend une longueur en 3eme param |
||
| 381 | $pdf->SetDrawColor(192, 192, 192); |
||
| 382 | $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1); |
||
| 383 | |||
| 384 | $tab_height = $tab_height - $height_note; |
||
| 385 | $tab_top = $nexY+6; |
||
| 386 | } |
||
| 387 | else |
||
| 388 | { |
||
| 389 | $height_note=0; |
||
| 390 | } |
||
| 391 | |||
| 392 | |||
| 393 | // Use new auto collum system |
||
| 394 | $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref); |
||
| 395 | |||
| 396 | // Simulation de tableau pour connaitre la hauteur de la ligne de titre |
||
| 397 | $pdf->startTransaction(); |
||
| 398 | $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop); |
||
| 399 | $pdf->rollbackTransaction(true); |
||
| 400 | |||
| 401 | |||
| 402 | $iniY = $tab_top + $this->tabTitleHeight + 2; |
||
| 403 | $curY = $tab_top + $this->tabTitleHeight + 2; |
||
| 404 | $nexY = $tab_top + $this->tabTitleHeight + 2; |
||
| 405 | |||
| 406 | // Loop on each lines |
||
| 407 | for ($i = 0; $i < $nblines; $i++) |
||
| 408 | { |
||
| 409 | $curY = $nexY; |
||
| 410 | $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage |
||
| 411 | $pdf->SetTextColor(0, 0, 0); |
||
| 412 | |||
| 413 | // Define size of image if we need it |
||
| 414 | $imglinesize=array(); |
||
| 415 | if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]); |
||
| 416 | |||
| 417 | $pdf->setTopMargin($tab_top_newpage); |
||
| 418 | $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. |
||
| 419 | $pageposbefore=$pdf->getPage(); |
||
| 420 | |||
| 421 | $showpricebeforepagebreak=1; |
||
| 422 | $posYAfterImage=0; |
||
| 423 | $posYAfterDescription=0; |
||
| 424 | |||
| 425 | if($this->getColumnStatus('photo')) |
||
| 426 | { |
||
| 427 | // We start with Photo of product line |
||
| 428 | if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot))) // If photo too high, we moved completely on new page |
||
| 429 | { |
||
| 430 | $pdf->AddPage('', '', true); |
||
| 431 | if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
||
| 432 | //if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
| 433 | $pdf->setPage($pageposbefore+1); |
||
| 434 | |||
| 435 | $curY = $tab_top_newpage; |
||
| 436 | $showpricebeforepagebreak=0; |
||
| 437 | } |
||
| 438 | |||
| 439 | |||
| 440 | if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) |
||
| 441 | { |
||
| 442 | $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi |
||
| 443 | // $pdf->Image does not increase value return by getY, so we save it manually |
||
| 444 | $posYAfterImage=$curY+$imglinesize['height']; |
||
| 445 | } |
||
| 446 | } |
||
| 447 | |||
| 448 | // Description of product line |
||
| 449 | if($this->getColumnStatus('desc')) |
||
| 450 | { |
||
| 451 | $pdf->startTransaction(); |
||
| 452 | pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->getColumnContentWidth('desc'), 3, $this->getColumnContentXStart('desc'), $curY, $hideref, $hidedesc); |
||
| 453 | $pageposafter=$pdf->getPage(); |
||
| 454 | if ($pageposafter > $pageposbefore) // There is a pagebreak |
||
| 455 | { |
||
| 456 | $pdf->rollbackTransaction(true); |
||
| 457 | $pageposafter=$pageposbefore; |
||
| 458 | //print $pageposafter.'-'.$pageposbefore;exit; |
||
| 459 | $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. |
||
| 460 | pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->getColumnContentWidth('desc'), 3, $this->getColumnContentXStart('desc'), $curY, $hideref, $hidedesc); |
||
| 461 | |||
| 462 | $pageposafter=$pdf->getPage(); |
||
| 463 | $posyafter=$pdf->GetY(); |
||
| 464 | //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit; |
||
| 465 | if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforsignature+$heightforinfotot))) // There is no space left for total+free text |
||
| 466 | { |
||
| 467 | if ($i == ($nblines-1)) // No more lines, and no space left to show total, so we create a new page |
||
| 468 | { |
||
| 469 | $pdf->AddPage('', '', true); |
||
| 470 | if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
||
| 471 | //if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
| 472 | $pdf->setPage($pageposafter+1); |
||
| 473 | } |
||
| 474 | } |
||
| 475 | else |
||
| 476 | { |
||
| 477 | // We found a page break |
||
| 478 | $showpricebeforepagebreak=0; |
||
| 479 | } |
||
| 480 | } |
||
| 481 | else // No pagebreak |
||
| 482 | { |
||
| 483 | $pdf->commitTransaction(); |
||
| 484 | } |
||
| 485 | $posYAfterDescription=$pdf->GetY(); |
||
| 486 | } |
||
| 487 | |||
| 488 | $nexY = $pdf->GetY(); |
||
| 489 | $pageposafter=$pdf->getPage(); |
||
| 490 | |||
| 491 | $pdf->setPage($pageposbefore); |
||
| 492 | $pdf->setTopMargin($this->marge_haute); |
||
| 493 | $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. |
||
| 494 | |||
| 495 | // We suppose that a too long description or photo were moved completely on next page |
||
| 496 | if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { |
||
| 497 | $pdf->setPage($pageposafter); $curY = $tab_top_newpage; |
||
| 498 | } |
||
| 499 | |||
| 500 | // We suppose that a too long description is moved completely on next page |
||
| 501 | if ($pageposafter > $pageposbefore) { |
||
| 502 | $pdf->setPage($pageposafter); $curY = $tab_top_newpage; |
||
| 503 | } |
||
| 504 | |||
| 505 | $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut |
||
| 506 | |||
| 507 | // weight |
||
| 508 | |||
| 509 | $weighttxt=''; |
||
| 510 | if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->weight) |
||
| 511 | { |
||
| 512 | $weighttxt=round($object->lines[$i]->weight * $object->lines[$i]->qty_shipped, 5).' '.measuring_units_string($object->lines[$i]->weight_units, "weight"); |
||
| 513 | } |
||
| 514 | $voltxt=''; |
||
| 515 | if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->volume) |
||
| 516 | { |
||
| 517 | $voltxt=round($object->lines[$i]->volume * $object->lines[$i]->qty_shipped, 5).' '.measuring_units_string($object->lines[$i]->volume_units?$object->lines[$i]->volume_units:0, "volume"); |
||
| 518 | } |
||
| 519 | |||
| 520 | |||
| 521 | if ($this->getColumnStatus('weight')) |
||
| 522 | { |
||
| 523 | $this->printStdColumnContent($pdf, $curY, 'weight', $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt, array('html'=>1)); |
||
| 524 | $nexY = max($pdf->GetY(), $nexY); |
||
| 525 | } |
||
| 526 | |||
| 527 | if ($this->getColumnStatus('qty_asked')) |
||
| 528 | { |
||
| 529 | $this->printStdColumnContent($pdf, $curY, 'qty_asked', $object->lines[$i]->qty_asked); |
||
| 530 | $nexY = max($pdf->GetY(), $nexY); |
||
| 531 | } |
||
| 532 | |||
| 533 | if ($this->getColumnStatus('qty_shipped')) |
||
| 534 | { |
||
| 535 | $this->printStdColumnContent($pdf, $curY, 'qty_shipped', $object->lines[$i]->qty_shipped); |
||
| 536 | $nexY = max($pdf->GetY(), $nexY); |
||
| 537 | } |
||
| 538 | |||
| 539 | if ($this->getColumnStatus('subprice')) |
||
| 540 | { |
||
| 541 | $this->printStdColumnContent($pdf, $curY, 'subprice', price($object->lines[$i]->subprice, 0, $outputlangs)); |
||
| 542 | $nexY = max($pdf->GetY(), $nexY); |
||
| 543 | } |
||
| 544 | |||
| 545 | |||
| 546 | |||
| 547 | $nexY+=3; |
||
| 548 | if ($weighttxt && $voltxt) $nexY+=2; |
||
| 549 | |||
| 550 | // Add line |
||
| 551 | if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) |
||
| 552 | { |
||
| 553 | $pdf->setPage($pageposafter); |
||
| 554 | $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80,80,80))); |
||
| 555 | //$pdf->SetDrawColor(190,190,200); |
||
| 556 | $pdf->line($this->marge_gauche, $nexY-1, $this->page_largeur - $this->marge_droite, $nexY-1); |
||
| 557 | $pdf->SetLineStyle(array('dash'=>0)); |
||
| 558 | } |
||
| 559 | |||
| 560 | // Detect if some page were added automatically and output _tableau for past pages |
||
| 561 | while ($pagenb < $pageposafter) |
||
| 562 | { |
||
| 563 | $pdf->setPage($pagenb); |
||
| 564 | if ($pagenb == 1) |
||
| 565 | { |
||
| 566 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); |
||
| 567 | } |
||
| 568 | else |
||
| 569 | { |
||
| 570 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); |
||
| 571 | } |
||
| 572 | $this->_pagefoot($pdf, $object, $outputlangs, 1); |
||
| 573 | $pagenb++; |
||
| 574 | $pdf->setPage($pagenb); |
||
| 575 | $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. |
||
| 576 | if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
| 577 | } |
||
| 578 | if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak) |
||
| 579 | { |
||
| 580 | if ($pagenb == 1) |
||
| 581 | { |
||
| 582 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); |
||
| 583 | } |
||
| 584 | else |
||
| 585 | { |
||
| 586 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); |
||
| 587 | } |
||
| 588 | $this->_pagefoot($pdf, $object, $outputlangs, 1); |
||
| 589 | // New page |
||
| 590 | $pdf->AddPage(); |
||
| 591 | if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
||
| 592 | $pagenb++; |
||
| 593 | if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
| 594 | } |
||
| 595 | } |
||
| 596 | |||
| 597 | // Show square |
||
| 598 | if ($pagenb == 1) |
||
| 599 | { |
||
| 600 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); |
||
| 601 | $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
||
| 602 | } |
||
| 603 | else |
||
| 604 | { |
||
| 605 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); |
||
| 606 | $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
||
| 607 | } |
||
| 608 | |||
| 609 | // Affiche zone totaux |
||
| 610 | $posy=$this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs); |
||
| 611 | |||
| 612 | // Pied de page |
||
| 613 | $this->_pagefoot($pdf, $object, $outputlangs); |
||
| 614 | if (method_exists($pdf, 'AliasNbPages')) $pdf->AliasNbPages(); |
||
| 615 | |||
| 616 | $pdf->Close(); |
||
| 617 | |||
| 618 | $pdf->Output($file, 'F'); |
||
| 619 | |||
| 620 | // Add pdfgeneration hook |
||
| 621 | $hookmanager->initHooks(array('pdfgeneration')); |
||
| 622 | $parameters=array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs); |
||
| 623 | global $action; |
||
| 624 | $reshook=$hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
||
| 625 | if ($reshook < 0) |
||
| 626 | { |
||
| 627 | $this->error = $hookmanager->error; |
||
| 628 | $this->errors = $hookmanager->errors; |
||
| 629 | } |
||
| 630 | |||
| 631 | if (! empty($conf->global->MAIN_UMASK)) |
||
| 632 | @chmod($file, octdec($conf->global->MAIN_UMASK)); |
||
| 633 | |||
| 634 | $this->result = array('fullpath'=>$file); |
||
| 635 | |||
| 636 | return 1; // No error |
||
| 637 | } |
||
| 638 | else |
||
| 639 | { |
||
| 640 | $this->error=$langs->transnoentities("ErrorCanNotCreateDir", $dir); |
||
| 641 | return 0; |
||
| 642 | } |
||
| 643 | } |
||
| 644 | else |
||
| 645 | { |
||
| 646 | $this->error=$langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR"); |
||
| 647 | return 0; |
||
| 648 | } |
||
| 649 | } |
||
| 650 | |||
| 1230 |