129  public function write_file($object, $outputlangs, $srctemplatepath = 
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 
  132    global $user, $langs, $conf, $mysoc, $db, $hookmanager;
 
  134    if (!is_object($outputlangs)) {
 
  135      $outputlangs = $langs;
 
  139      $outputlangs->charset_output = 
'ISO-8859-1';
 
  143    $outputlangs->loadLangs(array(
"main", 
"interventions", 
"dict", 
"companies"));
 
  146    if ($object->statut == $object::STATUS_DRAFT && (
getDolGlobalString(
'FICHINTER_DRAFT_WATERMARK'))) {
 
  147      $this->watermark = $conf->global->FICHINTER_DRAFT_WATERMARK;
 
  150    if ($conf->ficheinter->dir_output) {
 
  151      $object->fetch_thirdparty();
 
  154      if ($object->specimen) {
 
  155        $dir = $conf->ficheinter->dir_output;
 
  156        $file = $dir.
"/SPECIMEN.pdf";
 
  159        $dir = $conf->ficheinter->dir_output.
"/".$objectref;
 
  160        $file = $dir.
"/".$objectref.
".pdf";
 
  163      if (!file_exists($dir)) {
 
  165          $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
 
  170      if (file_exists($dir)) {
 
  172        if (!is_object($hookmanager)) {
 
  173          include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
 
  177        $hookmanager->initHooks(array(
'pdfgeneration'));
 
  178        $parameters = array(
'file'=>$file, 
'object'=>$object, 
'outputlangs'=>$outputlangs);
 
  180        $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action); 
 
  182        $nblines = count($object->lines);
 
  187        $heightforinfotot = 50; 
 
  188        $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5); 
 
  189        $heightforfooter = $this->marge_basse + 8; 
 
  191          $heightforfooter += 6;
 
  193        $pdf->SetAutoPageBreak(1, 0);
 
  195        if (class_exists(
'TCPDF')) {
 
  196          $pdf->setPrintHeader(
false);
 
  197          $pdf->setPrintFooter(
false);
 
  202          $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.
'/' . 
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
 
  203          $tplidx = $pdf->importPage(1);
 
  208        $pdf->SetDrawColor(128, 128, 128);
 
  210        $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
 
  211        $pdf->SetSubject($outputlangs->transnoentities(
"InterventionCard"));
 
  212        $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
 
  213        $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
 
  214        $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"InterventionCard"));
 
  216          $pdf->SetCompression(
false);
 
  219        $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); 
 
  223        if (!empty($tplidx)) {
 
  224          $pdf->useTemplate($tplidx);
 
  227        $this->
_pagehead($pdf, $object, 1, $outputlangs);
 
  228        $pdf->SetFont(
'', 
'', $default_font_size - 1);
 
  229        $pdf->SetTextColor(0, 0, 0);
 
  232        $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 : 10);
 
  234        $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
 
  237        $notetoshow = empty($object->note_public) ? 
'' : $object->note_public;
 
  246          $pdf->SetFont(
'', 
'', $default_font_size - 1);
 
  247          $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, 
dol_htmlentitiesbr($notetoshow), 0, 1);
 
  248          $nexY = $pdf->GetY();
 
  249          $height_note = $nexY - $tab_top;
 
  252          $pdf->SetDrawColor(192, 192, 192);
 
  253          $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
 
  255          $tab_height = $tab_height - $height_note;
 
  256          $tab_top = $nexY + 6;
 
  261        $iniY = $tab_top + 7;
 
  262        $curY = $tab_top + 7;
 
  263        $nexY = $tab_top + 7;
 
  265        $pdf->SetXY($this->marge_gauche, $tab_top);
 
  266        $pdf->MultiCell(190, 5, $outputlangs->transnoentities(
"Description"), 0, 
'L', 0);
 
  267        $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
 
  269        $pdf->SetFont(
'', 
'', $default_font_size - 1);
 
  271        $pdf->SetXY($this->marge_gauche, $tab_top + 5);
 
  272        $text = $object->description;
 
  273        if ($object->duration > 0) {
 
  274          $totaltime = 
convertSecondToTime($object->duration, 
'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
 
  275          $text .= ($text ? 
' - ' : 
'').$langs->trans(
"Total").
": ".$totaltime;
 
  280        $pdf->writeHTMLCell(180, 3, $this->posxdesc - 1, $tab_top + 5, $outputlangs->convToOutputCharset($desc), 0, 1);
 
  281        $nexY = $pdf->GetY();
 
  283        $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
 
  285        $nblines = count($object->lines);
 
  288        for ($i = 0; $i < $nblines; $i++) {
 
  289          $objectligne = $object->lines[$i];
 
  291          $valide = empty($objectligne->id) ? 0 : $objectligne->fetch($objectligne->id);
 
  292          if ($valide > 0 || $object->specimen) {
 
  294            $pdf->SetFont(
'', 
'', $default_font_size - 1); 
 
  295            $pdf->SetTextColor(0, 0, 0);
 
  297            $pdf->setTopMargin($tab_top_newpage);
 
  298            $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); 
 
  299            $pageposbefore = $pdf->getPage();
 
  302            $curX = $this->posxdesc - 1;
 
  306              $txt = $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($objectligne->datei, 
'dayhour', 
false, $outputlangs, 
true);
 
  308              $txt = $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($objectligne->datei, 
'day', 
false, $outputlangs, 
true);
 
  311            if ($objectligne->duration > 0) {
 
  312              $txt .= 
" - ".$outputlangs->transnoentities(
"Duration").
" : ".
convertSecondToTime($objectligne->duration);
 
  314            $txt = 
'<strong>'.dol_htmlentitiesbr($txt, 1, $outputlangs->charset_output).
'</strong>';
 
  317            $pdf->startTransaction();
 
  318            $pdf->writeHTMLCell(0, 0, $curX, $curY + 1, 
dol_concatdesc($txt, $desc), 0, 1, 0);
 
  319            $pageposafter = $pdf->getPage();
 
  320            if ($pageposafter > $pageposbefore) { 
 
  321              $pdf->rollbackTransaction(
true);
 
  322              $pageposafter = $pageposbefore;
 
  324              $pdf->setPageOrientation(
'', 1, $heightforfooter); 
 
  325              $pdf->writeHTMLCell(0, 0, $curX, $curY, 
dol_concatdesc($txt, $desc), 0, 1, 0);
 
  326              $pageposafter = $pdf->getPage();
 
  327              $posyafter = $pdf->GetY();
 
  329              if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { 
 
  330                if ($i == ($nblines - 1)) { 
 
  331                  $pdf->AddPage(
'', 
'', 
true);
 
  332                  if (!empty($tplidx)) {
 
  333                    $pdf->useTemplate($tplidx);
 
  336                    $this->
_pagehead($pdf, $object, 0, $outputlangs);
 
  338                  $pdf->setPage($pageposafter + 1);
 
  342              $pdf->commitTransaction();
 
  345            $nexY = $pdf->GetY();
 
  346            $pageposafter = $pdf->getPage();
 
  347            $pdf->setPage($pageposbefore);
 
  348            $pdf->setTopMargin($this->marge_haute);
 
  349            $pdf->setPageOrientation(
'', 1, 0); 
 
  352            if ($pageposafter > $pageposbefore) {
 
  353              $pdf->setPage($pageposafter);
 
  354              $curY = $tab_top_newpage;
 
  357            $pdf->SetFont(
'', 
'', $default_font_size - 1); 
 
  360            while ($pagenb < $pageposafter) {
 
  361              $pdf->setPage($pagenb);
 
  363                $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object);
 
  365                $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object);
 
  367              $this->
_pagefoot($pdf, $object, $outputlangs, 1);
 
  369              $pdf->setPage($pagenb);
 
  370              $pdf->setPageOrientation(
'', 1, 0); 
 
  372                $this->
_pagehead($pdf, $object, 0, $outputlangs);
 
  374              if (!empty($tplidx)) {
 
  375                $pdf->useTemplate($tplidx);
 
  378            if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
 
  380                $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object);
 
  382                $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object);
 
  384              $this->
_pagefoot($pdf, $object, $outputlangs, 1);
 
  387              if (!empty($tplidx)) {
 
  388                $pdf->useTemplate($tplidx);
 
  392                $this->
_pagehead($pdf, $object, 0, $outputlangs);
 
  400          $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object);
 
  401          $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
 
  403          $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object);
 
  404          $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
 
  407        $this->
_pagefoot($pdf, $object, $outputlangs);
 
  408        if (method_exists($pdf, 
'AliasNbPages')) {
 
  409          $pdf->AliasNbPages();
 
  413        $pdf->Output($file, 
'F');
 
  416        $hookmanager->initHooks(array(
'pdfgeneration'));
 
  417        $parameters = array(
'file'=>$file, 
'object'=>$object, 
'outputlangs'=>$outputlangs);
 
  419        $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action); 
 
  421          $this->error = $hookmanager->error;
 
  422          $this->errors = $hookmanager->errors;
 
  427        $this->result = array(
'fullpath'=>$file);
 
  431        $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
 
  435      $this->error = $langs->trans(
"ErrorConstantNotDefined", 
"FICHEINTER_OUTPUTDIR");
 
 
  523  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
 
  525    global $conf, $langs;
 
  529    $outputlangs->loadLangs(array(
"main", 
"dict", 
"companies", 
"interventions"));
 
  534    $pdf->SetTextColor(0, 0, 60);
 
  535    $pdf->SetFont(
'', 
'B', $default_font_size + 3);
 
  537    $posx = $this->page_largeur - $this->marge_droite - 100;
 
  538    $posy = $this->marge_haute;
 
  540    $pdf->SetXY($this->marge_gauche, $posy);
 
  543    $logo = $conf->mycompany->dir_output.
'/logos/'.$this->emetteur->logo;
 
  544    if ($this->emetteur->logo) {
 
  545      if (is_readable($logo)) {
 
  547        $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); 
 
  549        $pdf->SetTextColor(200, 0, 0);
 
  550        $pdf->SetFont(
'', 
'B', $default_font_size - 2);
 
  551        $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0, 
'L');
 
  552        $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0, 
'L');
 
  555      $text = $this->emetteur->name;
 
  556      $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 
'L');
 
  559    $pdf->SetFont(
'', 
'B', $default_font_size + 3);
 
  560    $pdf->SetXY($posx, $posy);
 
  561    $pdf->SetTextColor(0, 0, 60);
 
  562    $title = $outputlangs->transnoentities(
"InterventionCard");
 
  563    $pdf->MultiCell(100, 4, $title, 
'', 
'R');
 
  565    $pdf->SetFont(
'', 
'B', $default_font_size + 2);
 
  568    $pdf->SetXY($posx, $posy);
 
  569    $pdf->SetTextColor(0, 0, 60);
 
  570    $pdf->MultiCell(100, 4, $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset($object->ref), 
'', 
'R');
 
  573    $pdf->SetFont(
'', 
'', $default_font_size);
 
  576    $pdf->SetXY($posx, $posy);
 
  577    $pdf->SetTextColor(0, 0, 60);
 
  578    $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"Date").
" : ".
dol_print_date($object->datec, 
"day", 
false, $outputlangs, 
true), 
'', 
'R');
 
  580    if (!empty($object->ref_client)) {
 
  582      $pdf->SetXY($posx, $posy);
 
  583      $pdf->SetTextColor(0, 0, 60);
 
  584      $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"RefCustomer") . 
" : " . 
dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65), 
'', 
'R');
 
  588    if (!
getDolGlobalString(
'MAIN_PDF_HIDE_CUSTOMER_CODE') && $object->thirdparty->code_client) {
 
  590      $pdf->SetXY($posx, $posy);
 
  591      $pdf->SetTextColor(0, 0, 60);
 
  592      $pdf->MultiCell(100, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client), 
'', 
'R');
 
  597      $carac_emetteur = 
'';
 
  599      $arrayidcontact = $object->getIdContact(
'internal', 
'INTERREPFOLL');
 
  600      if (count($arrayidcontact) > 0) {
 
  601        $object->fetch_user($arrayidcontact[0]);
 
  602        $labelbeforecontactname = ($outputlangs->transnoentities(
"FromContactName") != 
'FromContactName' ? $outputlangs->transnoentities(
"FromContactName") : $outputlangs->transnoentities(
"Name"));
 
  603        $carac_emetteur .= ($carac_emetteur ? 
"\n" : 
'').$labelbeforecontactname.
": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs));
 
  605        $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_PHONE_AFTER_USER_CONTACT') && !empty($object->user->office_phone)) ? $object->user->office_phone : 
'';
 
  607        $carac_emetteur .= (
getDolGlobalInt(
'PDF_SHOW_EMAIL_AFTER_USER_CONTACT') && !empty($object->user->email)) ? $object->user->email : 
'';
 
  609        $carac_emetteur .= 
"\n";
 
  612      $carac_emetteur .= 
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, 
'', 0, 
'source', $object);
 
  616      $posx = $this->marge_gauche;
 
  618        $posx = $this->page_largeur - $this->marge_droite - 80;
 
  624        $pdf->SetTextColor(0, 0, 0);
 
  625        $pdf->SetFont(
'', 
'', $default_font_size - 2);
 
  626        $pdf->SetXY($posx, $posy - 5);
 
  627        $pdf->SetXY($posx, $posy);
 
  628        $pdf->SetFillColor(230, 230, 230);
 
  629        $pdf->MultiCell(82, $hautcadre, 
"", 0, 
'R', 1);
 
  634        $pdf->SetXY($posx + 2, $posy + 3);
 
  635        $pdf->SetTextColor(0, 0, 60);
 
  636        $pdf->SetFont(
'', 
'B', $default_font_size);
 
  637        $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 
'L');
 
  638        $posy = $pdf->getY();
 
  642      $pdf->SetFont(
'', 
'', $default_font_size - 1);
 
  643      $pdf->SetXY($posx + 2, $posy);
 
  644      $pdf->MultiCell(80, 4, $carac_emetteur, 0, 
'L');
 
  649      $arrayidcontact = $object->getIdContact(
'external', 
'CUSTOMER');
 
  650      if (count($arrayidcontact) > 0) {
 
  652        $result = $object->fetch_contact($arrayidcontact[0]);
 
  656      if ($usecontact && ($object->contact->socid != $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || 
getDolGlobalString(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')))) {
 
  657        $thirdparty = $object->contact;
 
  659        $thirdparty = $object->thirdparty;
 
  664      $carac_client = 
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, (isset($object->contact) ? $object->contact : 
''), $usecontact, 
'target', $object);
 
  668      if ($this->page_largeur < 210) {
 
  672      $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
 
  674        $posx = $this->marge_gauche;
 
  679        $pdf->SetTextColor(0, 0, 0);
 
  680        $pdf->SetFont(
'', 
'', $default_font_size - 2);
 
  681        $pdf->SetXY($posx + 2, $posy - 5);
 
  682        $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
 
  683        $pdf->SetTextColor(0, 0, 0);
 
  687      $pdf->SetXY($posx + 2, $posy + 3);
 
  688      $pdf->SetFont(
'', 
'B', $default_font_size);
 
  689      $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 
'L');
 
  691      $posy = $pdf->getY();
 
  694      $pdf->SetFont(
'', 
'', $default_font_size - 1);
 
  695      $pdf->SetXY($posx + 2, $posy);
 
  696      $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 
'L');