/**
  *	Function to build pdf onto disk
  *
  *	@param		Object		$object			Object expedition to generate (or id if old method)
  *	@param		Translate	$outputlangs		Lang output object
  *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int			$hidedetails		Do not show line details
  *  @param		int			$hidedesc			Do not show desc
  *  @param		int			$hideref			Do not show ref
  *  @return     int         	    			1=OK, 0=KO
  */
 function write_file(&$object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 {
     global $user, $conf, $langs, $hookmanager;
     $object->fetch_thirdparty();
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     $outputlangs->load("propal");
     $outputlangs->load("deliveries");
     $outputlangs->load("sendings");
     if ($conf->expedition->dir_output) {
         // Definition de $dir et $file
         if ($object->specimen) {
             $dir = $conf->expedition->dir_output . "/sending";
             $file = $dir . "/SPECIMEN.pdf";
         } else {
             $expref = dol_sanitizeFileName($object->ref);
             $dir = $conf->expedition->dir_output . "/sending/" . $expref;
             $file = $dir . "/" . $expref . ".pdf";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             $nblignes = count($object->lines);
             $pdf = pdf_getInstance($this->format);
             $default_font_size = pdf_getPDFFontSize($outputlangs);
             $heightforinfotot = 0;
             // Height reserved to output the info and total part
             $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
             $heightforfooter = $this->marge_basse + 8;
             // Height reserved to output the footer (value include bottom margin)
             $pdf->SetAutoPageBreak(1, 0);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             if (method_exists($pdf, 'AliasNbPages')) {
                 $pdf->AliasNbPages();
             }
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("Shipment"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Shipment"));
             if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             // New page
             $pdf->AddPage();
             if (!empty($tplidx)) {
                 $pdf->useTemplate($tplidx);
             }
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 90;
             $tab_top_newpage = empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10;
             $tab_height = 130;
             $tab_height_newpage = 150;
             if (!empty($object->note_public) || !empty($object->tracking_number) && !empty($object->shipping_method_id)) {
                 $tab_top = 88;
                 $tab_top_alt = $tab_top;
                 // Tracking number
                 if (!empty($object->tracking_number)) {
                     $object->GetUrlTrackingStatus($object->tracking_number);
                     if (!empty($object->tracking_url)) {
                         if ($object->shipping_method_id > 0) {
                             // Get code using getLabelFromKey
                             $code = $outputlangs->getLabelFromKey($this->db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
                             $label = $outputlangs->trans("LinkToTrackYourPackage") . "<br>";
                             $label .= $outputlangs->trans("SendingMethod" . strtoupper($code)) . " :";
                             $pdf->SetFont('', 'B', $default_font_size - 2);
                             $pdf->writeHTMLCell(60, 7, $this->posxdesc - 1, $tab_top - 1, $label . " " . $object->tracking_url, 0, 1, false, true, 'L');
                             $tab_top_alt += 7;
                         }
                     }
                 }
                 // Affiche notes
                 if (!empty($object->note_public)) {
                     $pdf->SetFont('', '', $default_font_size - 1);
                     // Dans boucle pour gerer multi-page
                     $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1);
                 }
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - $tab_top;
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             $num = count($object->lines);
             // Loop on each lines
             for ($i = 0; $i < $num; $i++) {
                 $curY = $nexY;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Into loop to work with multipage
                 $pdf->SetTextColor(0, 0, 0);
                 $pdf->setTopMargin($tab_top_newpage);
                 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
                 // The only function to edit the bottom margin of current page to set it.
                 $pageposbefore = $pdf->getPage();
                 // Description de la ligne produit
                 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxqtyordered - 10, 3, $this->posxdesc, $curY, 0, 1);
                 $nexY = $pdf->GetY();
                 $pageposafter = $pdf->getPage();
                 $pdf->setPage($pageposbefore);
                 $pdf->setTopMargin($this->marge_haute);
                 $pdf->setPageOrientation('', 1, 0);
                 // The only function to edit the bottom margin of current page to set it.
                 // We suppose that a too long description is moved completely on next page
                 if ($pageposafter > $pageposbefore) {
                     $pdf->setPage($pageposafter);
                     $curY = $tab_top_newpage;
                 }
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // On repositionne la police par defaut
                 $pdf->SetXY($this->posxqtyordered, $curY);
                 $pdf->MultiCell($this->posxqtytoship - $this->posxqtyordered, 3, $object->lines[$i]->qty_asked, '', 'C');
                 $pdf->SetXY($this->posxqtytoship, $curY);
                 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxqtytoship, 3, $object->lines[$i]->qty_shipped, '', 'C');
                 // Add line
                 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < $nblignes - 1) {
                     $pdf->setPage($pageposafter);
                     $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(210, 210, 210)));
                     //$pdf->SetDrawColor(190,190,200);
                     $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
                     $pdf->SetLineStyle(array('dash' => 0));
                 }
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // Detect if some page were added automatically and output _tableau for past pages
                 while ($pagenb < $pageposafter) {
                     $pdf->setPage($pagenb);
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     $pagenb++;
                     $pdf->setPage($pagenb);
                     $pdf->setPageOrientation('', 1, 0);
                     // The only function to edit the bottom margin of current page to set it.
                 }
                 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     // New page
                     $pdf->AddPage();
                     if (!empty($tplidx)) {
                         $pdf->useTemplate($tplidx);
                     }
                     $pagenb++;
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext - $heightforinfotot, 0, $outputlangs, 0, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfreetext - $heightforinfotot + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext - $heightforinfotot, 0, $outputlangs, 1, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfreetext - $heightforinfotot + 1;
             }
             // Pied de page
             $this->_pagefoot($pdf, $object, $outputlangs);
             if (method_exists($pdf, 'AliasNbPages')) {
                 $pdf->AliasNbPages();
             }
             $pdf->Close();
             $pdf->Output($file, 'F');
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
         } else {
             $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     } else {
         $this->error = $langs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
         return 0;
     }
     $this->error = $langs->transnoentities("ErrorUnknown");
     return 0;
     // Erreur par defaut
 }
Example #2
0
 /**
  *	Fonction generant le projet sur le disque
  *
  *	@param	Project		$object   		Object project a generer
  *	@param	Translate	$outputlangs	Lang output object
  *	@return	int         				1 if OK, <=0 if KO
  */
 function write_file($object, $outputlangs)
 {
     global $conf, $hookmanager, $langs, $user;
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("projects");
     if ($conf->projet->dir_output) {
         //$nblignes = count($object->lines);  // This is set later with array of tasks
         $objectref = dol_sanitizeFileName($object->ref);
         $dir = $conf->projet->dir_output;
         if (!preg_match('/specimen/i', $objectref)) {
             $dir .= "/" . $objectref;
         }
         $file = $dir . "/" . $objectref . ".pdf";
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             // Add pdfgeneration hook
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action);
             // Note that $action and $object may have been modified by some hooks
             $pdf = pdf_getInstance($this->format);
             $default_font_size = pdf_getPDFFontSize($outputlangs);
             // Must be after pdf_getInstance
             $heightforinfotot = 50;
             // Height reserved to output the info and total part
             $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
             $heightforfooter = $this->marge_basse + 8;
             // Height reserved to output the footer (value include bottom margin)
             $pdf->SetAutoPageBreak(1, 0);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Complete object by loading several other informations
             $task = new Task($this->db);
             $tasksarray = $task->getTasksArray(0, 0, $object->id);
             if (!$object->id > 0) {
                 $tasksarray = array_slice($tasksarray, 0, min(5, count($tasksarray)));
             }
             $object->lines = $tasksarray;
             $nblignes = count($object->lines);
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("Project"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Project"));
             if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             // New page
             $pdf->AddPage();
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 50;
             $tab_height = 200;
             $tab_top_newpage = 40;
             $tab_height_newpage = 210;
             // Affiche notes
             if (!empty($object->note_public)) {
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2, dol_htmlentitiesbr($object->note_public), 0, 1);
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - ($tab_top - 2);
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 3, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             // Boucle sur les lignes
             for ($i = 0; $i < $nblignes; $i++) {
                 $curY = $nexY;
                 // Description of ligne
                 $ref = $object->lines[$i]->ref;
                 $libelleline = $object->lines[$i]->label;
                 $progress = $object->lines[$i]->progress . '%';
                 $datestart = dol_print_date($object->lines[$i]->date_start, 'day');
                 $dateend = dol_print_date($object->lines[$i]->date_end, 'day');
                 $planned_workload = convertSecondToTime($object->lines[$i]->planned_workload, 'allhourmin');
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Dans boucle pour gerer multi-page
                 $pdf->SetXY($this->posxref, $curY);
                 $pdf->MultiCell($this->posxlabel - $this->posxref, 3, $outputlangs->convToOutputCharset($ref), 0, 'L');
                 $pdf->SetXY($this->posxlabel, $curY);
                 $pdf->MultiCell($this->posxworkload - $this->posxlabel, 3, $outputlangs->convToOutputCharset($libelleline), 0, 'L');
                 $pdf->SetXY($this->posxworkload, $curY);
                 $pdf->MultiCell($this->posxprogress - $this->posxworkload, 3, $planned_workload, 0, 'R');
                 $pdf->SetXY($this->posxprogress, $curY);
                 $pdf->MultiCell($this->posxdatestart - $this->posxprogress, 3, $progress, 0, 'R');
                 $pdf->SetXY($this->posxdatestart, $curY);
                 $pdf->MultiCell($this->posxdateend - $this->posxdatestart, 3, $datestart, 0, 'C');
                 $pdf->SetXY($this->posxdateend, $curY);
                 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxdateend, 3, $dateend, 0, 'C');
                 $pageposafter = $pdf->getPage();
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // On repositionne la police par defaut
                 $nexY = $pdf->GetY();
                 // Add line
                 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < $nblignes - 1) {
                     $pdf->setPage($pageposafter);
                     $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
                     //$pdf->SetDrawColor(190,190,200);
                     $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
                     $pdf->SetLineStyle(array('dash' => 0));
                 }
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // Detect if some page were added automatically and output _tableau for past pages
                 while ($pagenb < $pageposafter) {
                     $pdf->setPage($pagenb);
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     $pagenb++;
                     $pdf->setPage($pagenb);
                     $pdf->setPageOrientation('', 1, 0);
                     // The only function to edit the bottom margin of current page to set it.
                 }
                 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     // New page
                     $pdf->AddPage();
                     if (!empty($tplidx)) {
                         $pdf->useTemplate($tplidx);
                     }
                     $pagenb++;
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             }
             /*
              * Pied de page
              */
             $this->_pagefoot($pdf, $object, $outputlangs);
             if (method_exists($pdf, 'AliasNbPages')) {
                 $pdf->AliasNbPages();
             }
             $pdf->Close();
             $pdf->Output($file, 'F');
             // Add pdfgeneration hook
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
             // Pas d'erreur
         } else {
             $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     }
     $this->error = $langs->transnoentities("ErrorConstantNotDefined", "LIVRAISON_OUTPUTDIR");
     return 0;
 }
 /**
  *  Function to build pdf onto disk
  *
  *  @param		Object		$object				Object to generate
  *  @param		Translate	$outputlangs		Lang output object
  *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int			$hidedetails		Do not show line details
  *  @param		int			$hidedesc			Do not show desc
  *  @param		int			$hideref			Do not show ref
  *  @return     int         	    			1=OK, 0=KO
  */
 function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 {
     global $user, $langs, $conf, $mysoc, $db, $hookmanager;
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     $nblignes = count($object->lines);
     // Loop on each lines to detect if there is at least one image to show
     $realpatharray = array();
     if (!empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) {
         for ($i = 0; $i < $nblignes; $i++) {
             if (empty($object->lines[$i]->fk_product)) {
                 continue;
             }
             $objphoto = new Product($this->db);
             $objphoto->fetch($object->lines[$i]->fk_product);
             $pdir = get_exdir($object->lines[$i]->fk_product, 2, 0, 0, $objphoto, 'product') . $object->lines[$i]->fk_product . "/photos/";
             $dir = $conf->product->dir_output . '/' . $pdir;
             $realpath = '';
             foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
                 $filename = $obj['photo'];
                 //if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette'];
                 $realpath = $dir . $filename;
                 break;
             }
             if ($realpath) {
                 $realpatharray[$i] = $realpath;
             }
         }
     }
     if (count($realpatharray) == 0) {
         $this->posxpicture = $this->posxtva;
     }
     if ($conf->facture->dir_output) {
         $object->fetch_thirdparty();
         $deja_regle = $object->getSommePaiement();
         $amount_credit_notes_included = $object->getSumCreditNotesUsed();
         $amount_deposits_included = $object->getSumDepositsUsed();
         // Definition of $dir and $file
         if ($object->specimen) {
             $dir = $conf->facture->dir_output;
             $file = $dir . "/SPECIMEN.pdf";
         } else {
             $objectref = dol_sanitizeFileName($object->ref);
             $dir = $conf->facture->dir_output . "/" . $objectref;
             $file = $dir . "/" . $objectref . ".pdf";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             // Add pdfgeneration hook
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action);
             // Note that $action and $object may have been modified by some hooks
             // Set nblignes with the new facture lines content after hook
             $nblignes = count($object->lines);
             // Create pdf instance
             $pdf = pdf_getInstance($this->format);
             $default_font_size = pdf_getPDFFontSize($outputlangs);
             // Must be after pdf_getInstance
             $heightforinfotot = 50;
             // Height reserved to output the info and total part
             $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
             $heightforfooter = $this->marge_basse + 8;
             // Height reserved to output the footer (value include bottom margin)
             $pdf->SetAutoPageBreak(1, 0);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("Invoice"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Invoice"));
             if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             // Positionne $this->atleastonediscount si on a au moins une remise
             for ($i = 0; $i < $nblignes; $i++) {
                 if ($object->lines[$i]->remise_percent) {
                     $this->atleastonediscount++;
                 }
             }
             if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS)) {
                 $this->posxpicture += $this->postotalht - $this->posxdiscount;
                 $this->posxtva += $this->postotalht - $this->posxdiscount;
                 $this->posxup += $this->postotalht - $this->posxdiscount;
                 $this->posxqty += $this->postotalht - $this->posxdiscount;
                 $this->posxdiscount += $this->postotalht - $this->posxdiscount;
                 //$this->postotalht;
             }
             // Situation invoice handling
             if ($object->situation_cycle_ref) {
                 $this->situationinvoice = True;
                 $progress_width = 14;
                 $this->posxtva -= $progress_width;
                 $this->posxup -= $progress_width;
                 $this->posxqty -= $progress_width;
                 $this->posxdiscount -= $progress_width;
                 $this->posxprogress -= $progress_width;
             }
             // New page
             $pdf->AddPage();
             if (!empty($tplidx)) {
                 $pdf->useTemplate($tplidx);
             }
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 90;
             $tab_top_newpage = empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10;
             $tab_height = 130;
             $tab_height_newpage = 150;
             // Incoterm
             $height_incoterms = 0;
             if ($conf->incoterm->enabled) {
                 $desc_incoterms = $object->getIncotermsForPDF();
                 if ($desc_incoterms) {
                     $tab_top = 88;
                     $pdf->SetFont('', '', $default_font_size - 1);
                     $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
                     $nexY = $pdf->GetY();
                     $height_incoterms = $nexY - $tab_top;
                     // Rect prend une longueur en 3eme param
                     $pdf->SetDrawColor(192, 192, 192);
                     $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
                     $tab_top = $nexY + 6;
                     $height_incoterms += 4;
                 }
             }
             // Affiche notes
             $notetoshow = empty($object->note_public) ? '' : $object->note_public;
             if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
                 // Get first sale rep
                 if (is_object($object->thirdparty)) {
                     $salereparray = $object->thirdparty->getSalesRepresentatives($user);
                     $salerepobj = new User($this->db);
                     $salerepobj->fetch($salereparray[0]['id']);
                     if (!empty($salerepobj->signature)) {
                         $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
                     }
                 }
             }
             if ($notetoshow) {
                 $tab_top = 88 + $height_incoterms;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - $tab_top;
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             // Loop on each lines
             for ($i = 0; $i < $nblignes; $i++) {
                 $curY = $nexY;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Into loop to work with multipage
                 $pdf->SetTextColor(0, 0, 0);
                 // Define size of image if we need it
                 $imglinesize = array();
                 if (!empty($realpatharray[$i])) {
                     $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
                 }
                 $pdf->setTopMargin($tab_top_newpage);
                 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
                 // The only function to edit the bottom margin of current page to set it.
                 $pageposbefore = $pdf->getPage();
                 $showpricebeforepagebreak = 1;
                 $posYAfterImage = 0;
                 $posYAfterDescription = 0;
                 // We start with Photo of product line
                 if (isset($imglinesize['width']) && isset($imglinesize['height']) && $curY + $imglinesize['height'] > $this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)) {
                     $pdf->AddPage('', '', true);
                     if (!empty($tplidx)) {
                         $pdf->useTemplate($tplidx);
                     }
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs);
                     }
                     $pdf->setPage($pageposbefore + 1);
                     $curY = $tab_top_newpage;
                     $showpricebeforepagebreak = 0;
                 }
                 if (isset($imglinesize['width']) && isset($imglinesize['height'])) {
                     $curX = $this->posxpicture - 1;
                     $pdf->Image($realpatharray[$i], $curX + ($this->posxtva - $this->posxpicture - $imglinesize['width']) / 2, $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300);
                     // Use 300 dpi
                     // $pdf->Image does not increase value return by getY, so we save it manually
                     $posYAfterImage = $curY + $imglinesize['height'];
                 }
                 // Description of product line
                 $curX = $this->posxdesc - 1;
                 $pdf->startTransaction();
                 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
                 $pageposafter = $pdf->getPage();
                 if ($pageposafter > $pageposbefore) {
                     $pdf->rollbackTransaction(true);
                     $pageposafter = $pageposbefore;
                     //print $pageposafter.'-'.$pageposbefore;exit;
                     $pdf->setPageOrientation('', 1, $heightforfooter);
                     // The only function to edit the bottom margin of current page to set it.
                     pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxpicture - $curX, 3, $curX, $curY, $hideref, $hidedesc);
                     $pageposafter = $pdf->getPage();
                     $posyafter = $pdf->GetY();
                     //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
                     if ($posyafter > $this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)) {
                         if ($i == $nblignes - 1) {
                             $pdf->AddPage('', '', true);
                             if (!empty($tplidx)) {
                                 $pdf->useTemplate($tplidx);
                             }
                             if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                                 $this->_pagehead($pdf, $object, 0, $outputlangs);
                             }
                             $pdf->setPage($pageposafter + 1);
                         }
                     } else {
                         // We found a page break
                         $showpricebeforepagebreak = 0;
                     }
                 } else {
                     $pdf->commitTransaction();
                 }
                 $posYAfterDescription = $pdf->GetY();
                 $nexY = $pdf->GetY();
                 $pageposafter = $pdf->getPage();
                 $pdf->setPage($pageposbefore);
                 $pdf->setTopMargin($this->marge_haute);
                 $pdf->setPageOrientation('', 1, 0);
                 // The only function to edit the bottom margin of current page to set it.
                 // We suppose that a too long description or photo were moved completely on next page
                 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
                     $pdf->setPage($pageposafter);
                     $curY = $tab_top_newpage;
                 }
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // On repositionne la police par defaut
                 // VAT Rate
                 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
                     $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
                     $pdf->SetXY($this->posxtva, $curY);
                     $pdf->MultiCell($this->posxup - $this->posxtva - 0.8, 3, $vat_rate, 0, 'R');
                 }
                 // Unit price before discount
                 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
                 $pdf->SetXY($this->posxup, $curY);
                 $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, $up_excl_tax, 0, 'R', 0);
                 // Quantity
                 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
                 $pdf->SetXY($this->posxqty, $curY);
                 // Enough for 6 chars
                 if ($conf->global->PRODUCT_USE_UNITS) {
                     $pdf->MultiCell($this->posxunit - $this->posxqty - 0.8, 4, $qty, 0, 'R');
                 } else {
                     $pdf->MultiCell($this->posxdiscount - $this->posxqty - 0.8, 4, $qty, 0, 'R');
                 }
                 // Unit
                 if ($conf->global->PRODUCT_USE_UNITS) {
                     $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
                     $pdf->SetXY($this->posxunit, $curY);
                     $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 4, $unit, 0, 'L');
                 }
                 // Discount on line
                 if ($object->lines[$i]->remise_percent) {
                     $pdf->SetXY($this->posxdiscount - 2, $curY);
                     $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
                     $pdf->MultiCell($this->posxprogress - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
                 }
                 if ($this->situationinvoice) {
                     // Situation progress
                     $progress = pdf_getlineprogress($object, $i, $outputlangs, $hidedetails);
                     $pdf->SetXY($this->posxprogress, $curY);
                     $pdf->MultiCell($this->postotalht - $this->posxprogress, 3, $progress, 0, 'R');
                 }
                 // Total HT line
                 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
                 $pdf->SetXY($this->postotalht, $curY);
                 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
                 // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
                 $prev_progress = $object->lines[$i]->get_prev_progress();
                 if ($prev_progress > 0) {
                     if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) {
                         $tvaligne = $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
                     } else {
                         $tvaligne = $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
                     }
                 } else {
                     if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) {
                         $tvaligne = $object->lines[$i]->multicurrency_total_tva;
                     } else {
                         $tvaligne = $object->lines[$i]->total_tva;
                     }
                 }
                 $localtax1ligne = $object->lines[$i]->total_localtax1;
                 $localtax2ligne = $object->lines[$i]->total_localtax2;
                 $localtax1_rate = $object->lines[$i]->localtax1_tx;
                 $localtax2_rate = $object->lines[$i]->localtax2_tx;
                 $localtax1_type = $object->lines[$i]->localtax1_type;
                 $localtax2_type = $object->lines[$i]->localtax2_type;
                 if ($object->remise_percent) {
                     $tvaligne -= $tvaligne * $object->remise_percent / 100;
                 }
                 if ($object->remise_percent) {
                     $localtax1ligne -= $localtax1ligne * $object->remise_percent / 100;
                 }
                 if ($object->remise_percent) {
                     $localtax2ligne -= $localtax2ligne * $object->remise_percent / 100;
                 }
                 $vatrate = (string) $object->lines[$i]->tva_tx;
                 // Retrieve type from database for backward compatibility with old records
                 if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') && (!empty($localtax1_rate) || !empty($localtax2_rate))) {
                     $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
                     $localtax1_type = $localtaxtmp_array[0];
                     $localtax2_type = $localtaxtmp_array[2];
                 }
                 // retrieve global local tax
                 if ($localtax1_type && $localtax1ligne != 0) {
                     $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
                 }
                 if ($localtax2_type && $localtax2ligne != 0) {
                     $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
                 }
                 if (($object->lines[$i]->info_bits & 0x1) == 0x1) {
                     $vatrate .= '*';
                 }
                 if (!isset($this->tva[$vatrate])) {
                     $this->tva[$vatrate] = '';
                 }
                 $this->tva[$vatrate] += $tvaligne;
                 if ($posYAfterImage > $posYAfterDescription) {
                     $nexY = $posYAfterImage;
                 }
                 // Add line
                 if ($conf->global->MAIN_PDF_DASH_BETWEEN_LINES && $i < $nblignes - 1) {
                     $pdf->setPage($pageposafter);
                     $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
                     //$pdf->SetDrawColor(190,190,200);
                     $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
                     $pdf->SetLineStyle(array('dash' => 0));
                 }
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // Detect if some page were added automatically and output _tableau for past pages
                 while ($pagenb < $pageposafter) {
                     $pdf->setPage($pagenb);
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     $pagenb++;
                     $pdf->setPage($pagenb);
                     $pdf->setPageOrientation('', 1, 0);
                     // The only function to edit the bottom margin of current page to set it.
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs);
                     }
                 }
                 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     // New page
                     $pdf->AddPage();
                     if (!empty($tplidx)) {
                         $pdf->useTemplate($tplidx);
                     }
                     $pagenb++;
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs);
                     }
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             }
             // Affiche zone infos
             $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
             // Affiche zone totaux
             $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
             // Affiche zone versements
             if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
                 $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs);
             }
             // Pied de page
             $this->_pagefoot($pdf, $object, $outputlangs);
             if (method_exists($pdf, 'AliasNbPages')) {
                 $pdf->AliasNbPages();
             }
             $pdf->Close();
             $pdf->Output($file, 'F');
             // Add pdfgeneration hook
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
             // Pas d'erreur
         } else {
             $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     } else {
         $this->error = $langs->trans("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
         return 0;
     }
     $this->error = $langs->trans("ErrorUnknown");
     return 0;
     // Erreur par defaut
 }
Example #4
0
 /**	Load an object from its id and create a new one in database
  *
  *	@param	int		$fromid     			Id of object to clone
  *  @param	int		$project_id				Id of project to attach clone task
  *  @param	int		$parent_task_id			Id of task to attach clone task
  *  @param	bool	$clone_change_dt		recalculate date of task regarding new project start date
  *	@param	bool	$clone_affectation		clone affectation of project
  *	@param	bool	$clone_time				clone time of project
  *	@param	bool	$clone_file				clone file of project
  *  @param	bool	$clone_note				clone note of project
  *	@param	bool	$clone_prog				clone progress of project
  * 	@return	int								New id of clone
  */
 function createFromClone($fromid, $project_id, $parent_task_id, $clone_change_dt = false, $clone_affectation = false, $clone_time = false, $clone_file = false, $clone_note = false, $clone_prog = false)
 {
     global $user, $langs, $conf;
     $error = 0;
     //Use 00:00 of today if time is use on task.
     $now = dol_mktime(0, 0, 0, dol_print_date(dol_now(), '%m'), dol_print_date(dol_now(), '%d'), dol_print_date(dol_now(), '%Y'));
     $datec = $now;
     $clone_task = new Task($this->db);
     $origin_task = new Task($this->db);
     $clone_task->context['createfromclone'] = 'createfromclone';
     $this->db->begin();
     // Load source object
     $clone_task->fetch($fromid);
     $origin_task->fetch($fromid);
     $defaultref = '';
     $obj = empty($conf->global->PROJECT_TASK_ADDON) ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
     if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . $conf->global->PROJECT_TASK_ADDON . ".php")) {
         require_once DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . $conf->global->PROJECT_TASK_ADDON . '.php';
         $modTask = new $obj();
         $defaultref = $modTask->getNextValue(0, $clone_task);
     }
     $ori_project_id = $clone_task->fk_project;
     $clone_task->id = 0;
     $clone_task->ref = $defaultref;
     $clone_task->fk_project = $project_id;
     $clone_task->fk_task_parent = $parent_task_id;
     $clone_task->date_c = $datec;
     $clone_task->planned_workload = $origin_task->planned_workload;
     $clone_task->rang = $origin_task->rang;
     //Manage Task Date
     if ($clone_change_dt) {
         $projectstatic = new Project($this->db);
         $projectstatic->fetch($ori_project_id);
         //Origin project strat date
         $orign_project_dt_start = $projectstatic->date_start;
         //Calcultate new task start date with difference between origin proj start date and origin task start date
         if (!empty($clone_task->date_start)) {
             $clone_task->date_start = $now + $clone_task->date_start - $orign_project_dt_start;
         }
         //Calcultate new task end date with difference between origin proj end date and origin task end date
         if (!empty($clone_task->date_end)) {
             $clone_task->date_end = $now + $clone_task->date_end - $orign_project_dt_start;
         }
     }
     if (!$clone_prog) {
         $clone_task->progress = 0;
     }
     // Create clone
     $result = $clone_task->create($user);
     // Other options
     if ($result < 0) {
         $this->error = $clone_task->error;
         $error++;
     }
     // End
     if (!$error) {
         $clone_task_id = $clone_task->id;
         $clone_task_ref = $clone_task->ref;
         //Note Update
         if (!$clone_note) {
             $clone_task->note_private = '';
             $clone_task->note_public = '';
         } else {
             $this->db->begin();
             $res = $clone_task->update_note(dol_html_entity_decode($clone_task->note_public, ENT_QUOTES), '_public');
             if ($res < 0) {
                 $this->error .= $clone_task->error;
                 $error++;
                 $this->db->rollback();
             } else {
                 $this->db->commit();
             }
             $this->db->begin();
             $res = $clone_task->update_note(dol_html_entity_decode($clone_task->note_private, ENT_QUOTES), '_private');
             if ($res < 0) {
                 $this->error .= $clone_task->error;
                 $error++;
                 $this->db->rollback();
             } else {
                 $this->db->commit();
             }
         }
         //Duplicate file
         if ($clone_file) {
             require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
             //retreive project origin ref to know folder to copy
             $projectstatic = new Project($this->db);
             $projectstatic->fetch($ori_project_id);
             $ori_project_ref = $projectstatic->ref;
             if ($ori_project_id != $project_id) {
                 $projectstatic->fetch($project_id);
                 $clone_project_ref = $projectstatic->ref;
             } else {
                 $clone_project_ref = $ori_project_ref;
             }
             $clone_task_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($clone_project_ref) . "/" . dol_sanitizeFileName($clone_task_ref);
             $ori_task_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($ori_project_ref) . "/" . dol_sanitizeFileName($fromid);
             $filearray = dol_dir_list($ori_task_dir, "files", 0, '', '(\\.meta|_preview\\.png)$', '', SORT_ASC, 1);
             foreach ($filearray as $key => $file) {
                 if (!file_exists($clone_task_dir)) {
                     if (dol_mkdir($clone_task_dir) < 0) {
                         $this->error .= $langs->trans('ErrorInternalErrorDetected') . ':dol_mkdir';
                         $error++;
                     }
                 }
                 $rescopy = dol_copy($ori_task_dir . '/' . $file['name'], $clone_task_dir . '/' . $file['name'], 0, 1);
                 if (is_numeric($rescopy) && $rescopy < 0) {
                     $this->error .= $langs->trans("ErrorFailToCopyFile", $ori_task_dir . '/' . $file['name'], $clone_task_dir . '/' . $file['name']);
                     $error++;
                 }
             }
         }
         // clone affectation
         if ($clone_affectation) {
             $origin_task = new Task($this->db);
             $origin_task->fetch($fromid);
             foreach (array('internal', 'external') as $source) {
                 $tab = $origin_task->liste_contact(-1, $source);
                 $num = count($tab);
                 $i = 0;
                 while ($i < $num) {
                     $clone_task->add_contact($tab[$i]['id'], $tab[$i]['code'], $tab[$i]['source']);
                     if ($clone_task->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
                         $langs->load("errors");
                         $this->error .= $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
                         $error++;
                     } else {
                         if ($clone_task->error != '') {
                             $this->error .= $clone_task->error;
                             $error++;
                         }
                     }
                     $i++;
                 }
             }
         }
         if ($clone_time) {
             //TODO clone time of affectation
         }
     }
     unset($clone_task->context['createfromclone']);
     if (!$error) {
         $this->db->commit();
         return $clone_task_id;
     } else {
         $this->db->rollback();
         dol_syslog(get_class($this) . "::createFromClone nbError: " . $error . " error : " . $this->error, LOG_ERR);
         return -1;
     }
 }
Example #5
0
        $object->tva_intra			= $_POST["tva_intra"];

        $object->commercial_id		= $_POST["commercial_id"];
        $object->default_lang		= $_POST["default_lang"];

        $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);

        // Gestion du logo de la société
        $dir     = $conf->societe->multidir_output[$object->entity]."/".$object->id."/logos";
        $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
        if ($file_OK)
        {
            if (image_format_supported($_FILES['photo']['name']))
            {
                dol_mkdir($dir);

                if (@is_dir($dir))
                {
                    $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
                    $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);

                    if (! $result > 0)
                    {
                        $errors[] = "ErrorFailedToSaveFile";
                    }
                    else
                    {
                        // Create small thumbs for company (Ratio is near 16/9)
                        // Used on logon for example
                        $imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
 /**
  *		Function called when module is enabled.
  *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  *		It also creates data directories.
  *      @return     int             1 if OK, 0 if KO
  */
 function init()
 {
     global $db, $conf, $langs;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     $dirodt = DOL_DATA_ROOT . '/produit';
     dol_mkdir($dirodt);
     dol_copy(dol_buildpath('/pos/frontend/img/noimage.jpg', 0), $dirodt . '/noimage.jpg', 0, 0);
     if (empty($conf->global->POS_TICKET) && empty($conf->global->POS_FACTURE)) {
         dolibarr_set_const($db, "POS_FACTURE", '1', 'chaine', 0, '', $conf->entity);
     }
     if (empty($conf->global->POS_MAX_TTC)) {
         dolibarr_set_const($db, "POS_MAX_TTC", '100', 'chaine', 0, '', $conf->entity);
     }
     $sql = array();
     $result = $this->load_tables();
     return $this->_init($sql);
 }
Example #7
0
 if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) {
     $pdf->SetCompression(false);
 }
 // Add all others
 foreach ($files as $file) {
     // Charge un document PDF depuis un fichier.
     $pagecount = $pdf->setSourceFile($file);
     for ($i = 1; $i <= $pagecount; $i++) {
         $tplidx = $pdf->importPage($i);
         $s = $pdf->getTemplatesize($tplidx);
         $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
         $pdf->useTemplate($tplidx);
     }
 }
 // Create output dir if not exists
 dol_mkdir($diroutputpdf);
 // Save merged file
 $filename = strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid")));
 if ($option == 'late') {
     $filename .= '_' . strtolower(dol_sanitizeFileName($langs->transnoentities("Late")));
 }
 if ($pagecount) {
     $now = dol_now();
     $file = $diroutputpdf . '/' . $filename . '_' . dol_print_date($now, 'dayhourlog') . '.pdf';
     $pdf->Output($file, 'F');
     if (!empty($conf->global->MAIN_UMASK)) {
         @chmod($file, octdec($conf->global->MAIN_UMASK));
     }
 } else {
     $mesg = '<div class="error">' . $langs->trans('NoPDFAvailableForChecked') . '</div>';
 }
Example #8
0
     $stdobject = new GenericObject($db);
     $stdobject->barcode_type = $fk_barcode_type;
     $result = $stdobject->fetch_barcode();
     if ($result <= 0) {
         $error++;
         setEventMessages('Failed to get bar code type information ' . $stdobject->error, $stdobject->errors, 'errors');
     }
 }
 if (!$error) {
     $code = $forbarcode;
     $generator = $stdobject->barcode_type_coder;
     // coder (loaded by fetch_barcode). Engine.
     $encoding = strtoupper($stdobject->barcode_type_code);
     // code (loaded by fetch_barcode). Example 'ean', 'isbn', ...
     $diroutput = $conf->barcode->dir_temp;
     dol_mkdir($diroutput);
     // Generate barcode
     $dirbarcode = array_merge(array("/core/modules/barcode/doc/"), $conf->modules_parts['barcode']);
     foreach ($dirbarcode as $reldir) {
         $dir = dol_buildpath($reldir, 0);
         $newdir = dol_osencode($dir);
         // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
         if (!is_dir($newdir)) {
             continue;
         }
         $result = @(include_once $newdir . $generator . '.modules.php');
         if ($result) {
             break;
         }
     }
     // Load barcode class for generating barcode image
 /**
  *      Build export file.
  *      File is built into directory $conf->export->dir_temp.'/'.$user->id
  *      Arrays this->array_export_xxx are already loaded for required datatoexport
  *
  *      @param      User		$user               User that export
  *      @param      string		$model              Export format
  *      @param      string		$datatoexport       Name of dataset to export
  *      @param      array		$array_selected     Filter on array of fields to export
  *      @param      array		$array_filterValue  Filter on array of fields with a filter
  *      @param		string		$sqlquery			If set, transmit the sql request for select (otherwise, sql request is generated from arrays)
  *      @return		int								<0 if KO, >0 if OK
  */
 function build_file($user, $model, $datatoexport, $array_selected, $array_filterValue, $sqlquery = '')
 {
     global $conf, $langs;
     $indice = 0;
     asort($array_selected);
     dol_syslog(get_class($this) . "::" . __FUNCTION__ . " " . $model . ", " . $datatoexport . ", " . implode(",", $array_selected));
     // Check parameters or context properties
     if (empty($this->array_export_fields) || !is_array($this->array_export_fields)) {
         $this->error = "ErrorBadParameter";
         return -1;
     }
     // Creation de la classe d'export du model ExportXXX
     $dir = DOL_DOCUMENT_ROOT . "/core/modules/export/";
     $file = "export_" . $model . ".modules.php";
     $classname = "Export" . $model;
     require_once $dir . $file;
     $objmodel = new $classname($this->db);
     if (!empty($sqlquery)) {
         $sql = $sqlquery;
     } else {
         // Define value for indice from $datatoexport
         $foundindice = 0;
         foreach ($this->array_export_code as $key => $dataset) {
             if ($datatoexport == $dataset) {
                 $indice = $key;
                 $foundindice++;
                 //print "Found indice = ".$indice." for dataset=".$datatoexport."\n";
                 break;
             }
         }
         if (empty($foundindice)) {
             $this->error = "ErrorBadParameter can't find dataset " . $datatoexport . " into preload arrays this->array_export_code";
             return -1;
         }
         $sql = $this->build_sql($indice, $array_selected, $array_filterValue);
     }
     // Run the sql
     $this->sqlusedforexport = $sql;
     dol_syslog(get_class($this) . "::" . __FUNCTION__ . " sql=" . $sql);
     $resql = $this->db->query($sql);
     if ($resql) {
         //$this->array_export_label[$indice]
         $filename = "export_" . $datatoexport;
         $filename .= '.' . $objmodel->getDriverExtension();
         $dirname = $conf->export->dir_temp . '/' . $user->id;
         $outputlangs = dol_clone($langs);
         // We clone to have an object we can modify (for example to change output charset by csv handler) without changing original value
         // Open file
         dol_mkdir($dirname);
         $result = $objmodel->open_file($dirname . "/" . $filename, $outputlangs);
         if ($result >= 0) {
             // Genere en-tete
             $objmodel->write_header($outputlangs);
             // Genere ligne de titre
             $objmodel->write_title($this->array_export_fields[$indice], $array_selected, $outputlangs, $this->array_export_TypeFields[$indice]);
             $var = true;
             while ($objp = $this->db->fetch_object($resql)) {
                 $var = !$var;
                 // Process special operations
                 if (!empty($this->array_export_special[$indice])) {
                     foreach ($this->array_export_special[$indice] as $key => $value) {
                         if (!array_key_exists($key, $array_selected)) {
                             continue;
                         }
                         // Field not selected
                         // Operation NULLIFNEG
                         if ($this->array_export_special[$indice][$key] == 'NULLIFNEG') {
                             //$alias=$this->array_export_alias[$indice][$key];
                             $alias = str_replace(array('.', '-'), '_', $key);
                             if ($objp->{$alias} < 0) {
                                 $objp->{$alias} = '';
                             }
                         }
                         // Operation ZEROIFNEG
                         if ($this->array_export_special[$indice][$key] == 'ZEROIFNEG') {
                             //$alias=$this->array_export_alias[$indice][$key];
                             $alias = str_replace(array('.', '-'), '_', $key);
                             if ($objp->{$alias} < 0) {
                                 $objp->{$alias} = '0';
                             }
                         }
                     }
                 }
                 // end of special operation processing
                 $objmodel->write_record($array_selected, $objp, $outputlangs, $this->array_export_TypeFields[$indice]);
             }
             // Genere en-tete
             $objmodel->write_footer($outputlangs);
             // Close file
             $objmodel->close_file();
             return 1;
         } else {
             $this->error = $objmodel->error;
             dol_syslog("Export::build_file Error: " . $this->error, LOG_ERR);
             return -1;
         }
     } else {
         $this->error = $this->db->error() . " - sql=" . $sql;
         dol_syslog("Export::build_file Error: " . $this->error, LOG_ERR);
         return -1;
     }
 }
Example #10
0
 /**
  *	Fonction generant le rapport sur le disque
  *
  *	@param	string		$_dir			Directory
  *	@param	string		$number			Number
  *	@param	Translate	$outputlangs	Lang output object
  *	@return	int     					1=ok, 0=ko
  */
 function write_file($_dir, $number, $outputlangs)
 {
     global $user, $conf, $langs;
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     $sav_charset_output = $outputlangs->charset_output;
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     $outputlangs->load("compta");
     $dir = $_dir . "/" . get_exdir($number, 2, 1) . $number;
     if (!is_dir($dir)) {
         $result = dol_mkdir($dir);
         if ($result < 0) {
             $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
             return -1;
         }
     }
     $month = sprintf("%02d", $month);
     $year = sprintf("%04d", $year);
     $_file = $dir . "/bordereau-" . $number . ".pdf";
     // Create PDF instance
     $pdf = pdf_getInstance($this->format);
     if (class_exists('TCPDF')) {
         $pdf->setPrintHeader(false);
         $pdf->setPrintFooter(false);
     }
     $pdf->SetFont(pdf_getPDFFont($outputlangs));
     $pdf->Open();
     $pagenb = 0;
     $pdf->SetDrawColor(128, 128, 128);
     $pdf->SetTitle($outputlangs->transnoentities("CheckReceipt") . " " . $number);
     $pdf->SetSubject($outputlangs->transnoentities("CheckReceipt"));
     $pdf->SetCreator("Dolibarr " . DOL_VERSION);
     $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
     $pdf->SetKeyWords($outputlangs->transnoentities("CheckReceipt") . " " . $number);
     if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) {
         $pdf->SetCompression(false);
     }
     $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
     // Left, Top, Right
     $pdf->SetAutoPageBreak(1, 0);
     $nboflines = count($this->lines);
     // Define nb of page
     $pages = intval($nboflines / $this->line_per_page);
     if ($nboflines % $this->line_per_page > 0) {
         $pages++;
     }
     if ($pages == 0) {
         // force to build at least one page if report has no lines
         $pages = 1;
     }
     $pdf->AddPage();
     $pagenb++;
     $this->Header($pdf, $pagenb, $pages, $outputlangs);
     $this->Body($pdf, $pagenb, $pages, $outputlangs);
     // Pied de page
     $this->_pagefoot($pdf, '', $outputlangs);
     $pdf->AliasNbPages();
     $pdf->Close();
     $pdf->Output($_file, 'F');
     if (!empty($conf->global->MAIN_UMASK)) {
         @chmod($_file, octdec($conf->global->MAIN_UMASK));
     }
     $outputlangs->charset_output = $sav_charset_output;
     return 1;
     // Pas d'erreur
 }
Example #11
0
/**
 * Migrate file from old path to new one for product $product
 *
 * @param 	Product	$product 	Object product
 * @return	void
 */
function migrate_product_photospath($product)
{
    global $conf;
    $dir = $conf->product->multidir_output[$product->entity];
    $origin = $dir . '/' . get_exdir($product->id, 2) . $product->id . "/photos";
    $destin = $dir . '/' . dol_sanitizeFileName($product->ref);
    $error = 0;
    $origin_osencoded = dol_osencode($origin);
    $destin_osencoded = dol_osencode($destin);
    dol_mkdir($destin);
    if (dol_is_dir($origin)) {
        $handle = opendir($origin_osencoded);
        if (is_resource($handle)) {
            while (($file = readdir($handle)) != false) {
                if ($file != '.' && $file != '..' && is_dir($origin_osencoded . '/' . $file)) {
                    $thumbs = opendir($origin_osencoded . '/' . $file);
                    if (is_resource($thumbs)) {
                        dol_mkdir($destin . '/' . $file);
                        while (($thumb = readdir($thumbs)) != false) {
                            dol_move($origin . '/' . $file . '/' . $thumb, $destin . '/' . $file . '/' . $thumb);
                        }
                        //		    			dol_delete_dir($origin.'/'.$file);
                    }
                } else {
                    if (dol_is_file($origin . '/' . $file)) {
                        dol_move($origin . '/' . $file, $destin . '/' . $file);
                    }
                }
            }
        }
    }
}
Example #12
0
             print ' ' . $langs->trans("YouMustCreateItAndAllowServerToWrite");
             print '</td><td>';
             print '<font class="error">' . $langs->trans("Error") . '</font>';
             print "</td></tr>";
             print '<tr><td colspan="2"><br>' . $langs->trans("CorrectProblemAndReloadPage", $_SERVER['PHP_SELF'] . '?testget=ok') . '</td></tr>';
         } else {
             //ODT templates
             require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
             $srcroot = $main_dir . '/install/doctemplates';
             $destroot = $main_data_dir . '/doctemplates';
             $docs = array('thirdparties' => 'thirdparty', 'proposals' => 'proposal', 'orders' => 'order', 'invoices' => 'invoice', 'projects' => 'project', 'tasks' => 'task_summary');
             foreach ($docs as $cursordir => $cursorfile) {
                 $src = $srcroot . '/' . $cursordir . '/template_' . $cursorfile . '.odt';
                 $dirodt = $destroot . '/' . $cursordir;
                 $dest = $dirodt . '/template_' . $cursorfile . '.odt';
                 dol_mkdir($dirodt);
                 $result = dol_copy($src, $dest, 0, 0);
                 if ($result < 0) {
                     print '<tr><td colspan="2"><br>' . $langs->trans('ErrorFailToCopyFile', $src, $dest) . '</td></tr>';
                 }
             }
         }
     }
 }
 // Table prefix
 $main_db_prefix = !empty($db_prefix) ? $db_prefix : 'llx_';
 // Force https
 $main_force_https = GETPOST("main_force_https") && (GETPOST("main_force_https") == "on" || GETPOST("main_force_https") == 1) ? '1' : '0';
 // Use alternative directory
 $main_use_alt_dir = GETPOST("main_use_alt_dir") && (GETPOST("main_use_alt_dir") == "on" || GETPOST("main_use_alt_dir") == 1) ? '' : '//';
 // Alternative root directory name
Example #13
0
/**
 *      Return a PDF instance object. We create a FPDI instance that instantiate TCPDF.
 *
 *      @param	string		$format         Array(width,height). Keep empty to use default setup.
 *      @param	string		$metric         Unit of format ('mm')
 *      @param  string		$pagetype       'P' or 'l'
 *      @return TPDF						PDF object
 */
function pdf_getInstance($format = '', $metric = 'mm', $pagetype = 'P')
{
    global $conf;
    // Define constant for TCPDF
    if (!defined('K_TCPDF_EXTERNAL_CONFIG')) {
        define('K_TCPDF_EXTERNAL_CONFIG', 1);
        // this avoid using tcpdf_config file
        define('K_PATH_CACHE', DOL_DATA_ROOT . '/admin/temp/');
        define('K_PATH_URL_CACHE', DOL_DATA_ROOT . '/admin/temp/');
        dol_mkdir(K_PATH_CACHE);
        define('K_BLANK_IMAGE', '_blank.png');
        define('PDF_PAGE_FORMAT', 'A4');
        define('PDF_PAGE_ORIENTATION', 'P');
        define('PDF_CREATOR', 'TCPDF');
        define('PDF_AUTHOR', 'TCPDF');
        define('PDF_HEADER_TITLE', 'TCPDF Example');
        define('PDF_HEADER_STRING', "by Dolibarr ERP CRM");
        define('PDF_UNIT', 'mm');
        define('PDF_MARGIN_HEADER', 5);
        define('PDF_MARGIN_FOOTER', 10);
        define('PDF_MARGIN_TOP', 27);
        define('PDF_MARGIN_BOTTOM', 25);
        define('PDF_MARGIN_LEFT', 15);
        define('PDF_MARGIN_RIGHT', 15);
        define('PDF_FONT_NAME_MAIN', 'helvetica');
        define('PDF_FONT_SIZE_MAIN', 10);
        define('PDF_FONT_NAME_DATA', 'helvetica');
        define('PDF_FONT_SIZE_DATA', 8);
        define('PDF_FONT_MONOSPACED', 'courier');
        define('PDF_IMAGE_SCALE_RATIO', 1.25);
        define('HEAD_MAGNIFICATION', 1.1);
        define('K_CELL_HEIGHT_RATIO', 1.25);
        define('K_TITLE_MAGNIFICATION', 1.3);
        define('K_SMALL_RATIO', 2 / 3);
        define('K_THAI_TOPCHARS', true);
        define('K_TCPDF_CALLS_IN_HTML', true);
        define('K_TCPDF_THROW_EXCEPTION_ERROR', false);
    }
    if (!empty($conf->global->MAIN_USE_FPDF) && !empty($conf->global->MAIN_DISABLE_FPDI)) {
        return "Error MAIN_USE_FPDF and MAIN_DISABLE_FPDI can't be set together";
    }
    // We use by default TCPDF else FPDF
    if (empty($conf->global->MAIN_USE_FPDF)) {
        require_once TCPDF_PATH . 'tcpdf.php';
    } else {
        require_once FPDF_PATH . 'fpdf.php';
    }
    // We need to instantiate tcpdi or fpdi object (instead of tcpdf) to use merging features. But we can disable it (this will break all merge features).
    if (empty($conf->global->MAIN_DISABLE_TCPDI)) {
        require_once TCPDI_PATH . 'tcpdi.php';
    } else {
        if (empty($conf->global->MAIN_DISABLE_FPDI)) {
            require_once FPDI_PATH . 'fpdi.php';
        }
    }
    //$arrayformat=pdf_getFormat();
    //$format=array($arrayformat['width'],$arrayformat['height']);
    //$metric=$arrayformat['unit'];
    // Protection and encryption of pdf
    if (empty($conf->global->MAIN_USE_FPDF) && !empty($conf->global->PDF_SECURITY_ENCRYPTION)) {
        /* Permission supported by TCPDF
        		- print : Print the document;
        		- modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';
        		- copy : Copy or otherwise extract text and graphics from the document;
        		- annot-forms : Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields);
        		- fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;
        		- extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);
        		- assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;
        		- print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality.
        		- owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.
        		*/
        if (class_exists('TCPDI')) {
            $pdf = new TCPDI($pagetype, $metric, $format);
        } else {
            if (class_exists('FPDI')) {
                $pdf = new FPDI($pagetype, $metric, $format);
            } else {
                $pdf = new TCPDF($pagetype, $metric, $format);
            }
        }
        // For TCPDF, we specify permission we want to block
        $pdfrights = array('modify', 'copy');
        $pdfuserpass = '';
        // Password for the end user
        $pdfownerpass = NULL;
        // Password of the owner, created randomly if not defined
        $pdf->SetProtection($pdfrights, $pdfuserpass, $pdfownerpass);
    } else {
        if (class_exists('TCPDI')) {
            $pdf = new TCPDI($pagetype, $metric, $format);
        } else {
            if (class_exists('FPDI')) {
                $pdf = new FPDI($pagetype, $metric, $format);
            } else {
                $pdf = new TCPDF($pagetype, $metric, $format);
            }
        }
    }
    // If we use FPDF class, we may need to add method writeHTMLCell
    if (!empty($conf->global->MAIN_USE_FPDF) && !method_exists($pdf, 'writeHTMLCell')) {
        // Declare here a class to overwrite FPDI to add method writeHTMLCell
        /**
         *	This class is an enhanced FPDI class that support method writeHTMLCell
         */
        class FPDI_DolExtended extends FPDI
        {
            /**
             * __call
             *
             * @param 	string	$method		Method
             * @param 	mixed	$args		Arguments
             * @return 	void
             */
            public function __call($method, $args)
            {
                if (isset($this->{$method})) {
                    $func = $this->{$method};
                    $func($args);
                }
            }
            /**
             * writeHTMLCell
             *
             * @param	int		$w				Width
             * @param 	int		$h				Height
             * @param 	int		$x				X
             * @param 	int		$y				Y
             * @param 	string	$html			Html
             * @param 	int		$border			Border
             * @param 	int		$ln				Ln
             * @param 	boolean	$fill			Fill
             * @param 	boolean	$reseth			Reseth
             * @param 	string	$align			Align
             * @param 	boolean	$autopadding	Autopadding
             * @return 	void
             */
            public function writeHTMLCell($w, $h, $x, $y, $html = '', $border = 0, $ln = 0, $fill = false, $reseth = true, $align = '', $autopadding = true)
            {
                $this->SetXY($x, $y);
                $val = str_replace('<br>', "\n", $html);
                //$val=dol_string_nohtmltag($val,false,'ISO-8859-1');
                $val = dol_string_nohtmltag($val, false, 'UTF-8');
                $this->MultiCell($w, $h, $val, $border, $align, $fill);
            }
        }
        $pdf2 = new FPDI_DolExtended($pagetype, $metric, $format);
        unset($pdf);
        $pdf = $pdf2;
    }
    return $pdf;
}
 /**
  *		Function called when module is enabled.
  *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  *		It also creates data directories
  *
  *      @param      string	$options    Options when enabling module ('', 'noboxes')
  *      @return     int             	1 if OK, 0 if KO
  */
 function init($options = '')
 {
     global $conf, $langs;
     // We disable this to prevent pb of modules not correctly disabled
     //$this->remove($options);
     //ODT template
     $src = DOL_DOCUMENT_ROOT . '/install/doctemplates/thirdparties/template_thirdparty.odt';
     $dirodt = DOL_DATA_ROOT . '/doctemplates/thirdparties';
     $dest = $dirodt . '/template_thirdparty.odt';
     if (file_exists($src) && !file_exists($dest)) {
         require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
         dol_mkdir($dirodt);
         $result = dol_copy($src, $dest, 0, 0);
         if ($result < 0) {
             $langs->load("errors");
             $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
             return 0;
         }
     }
     $sql = array();
     return $this->_init($sql, $options);
 }
Example #15
0
}
if (!isset($num)) {
    $sql .= " OR b.num_releve is null";
}
$sql .= " AND b.fk_account = ba.rowid";
$sql .= $db->order("b.num_releve, b.datev, b.datec", "ASC");
// We add date of creation to have correct order when everything is done the same day
//print $sql;
$resql = $db->query($sql);
if ($resql) {
    $balancebefore = array();
    $numrows = $db->num_rows($resql);
    if ($numrows > 0) {
        // Open file
        print 'Open file ' . $filename . ' into directory ' . $dirname . "\n";
        dol_mkdir($dirname);
        $result = $objmodel->open_file($dirname . "/" . $filename, $outputlangs);
        if ($result < 0) {
            print 'Failed to create file ' . $filename . ' into dir ' . $dirname . '.' . "\n";
            return -1;
        }
        // Genere en-tete
        $objmodel->write_header($outputlangs);
        // Genere ligne de titre
        $objmodel->write_title($array_fields, $array_selected, $outputlangs, $array_export_TypeFields);
    }
    $i = 0;
    while ($i < $numrows) {
        $thirdparty = '';
        $accountelem = '';
        $comment = '';
 /**
  *  Function to build pdf onto disk
  *
  *  @param		Object		$object				Object to generate
  *  @param		Translate	$outputlangs		Lang output object
  *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int			$hidedetails		Do not show line details
  *  @param		int			$hidedesc			Do not show desc
  *  @param		int			$hideref			Do not show ref
  *  @param		object		$hookmanager		Hookmanager object
  *  @return     int         	    			1=OK, 0=KO
  */
 function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0, $hookmanager = false)
 {
     global $user, $langs, $conf, $mysoc, $db;
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     if ($conf->facture->dir_output) {
         $object->fetch_thirdparty();
         $deja_regle = $object->getSommePaiement();
         $amount_credit_notes_included = $object->getSumCreditNotesUsed();
         $amount_deposits_included = $object->getSumDepositsUsed();
         // Definition of $dir and $file
         if ($object->specimen) {
             $dir = $conf->facture->dir_output;
             $file = $dir . "/SPECIMEN.pdf";
         } else {
             $objectref = dol_sanitizeFileName($object->ref);
             $dir = $conf->facture->dir_output . "/" . $objectref;
             $file = $dir . "/" . $objectref . ".pdf";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             $nblignes = count($object->lines);
             $pdf = pdf_getInstance($this->format);
             $default_font_size = pdf_getPDFFontSize($outputlangs);
             // Must be after pdf_getInstance
             $heightforinfotot = 50;
             // Height reserved to output the info and total part
             $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
             $heightforfooter = $this->marge_basse + 8;
             // Height reserved to output the footer (value include bottom margin)
             $pdf->SetAutoPageBreak(1, 0);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("Invoice"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Invoice"));
             if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             // Positionne $this->atleastonediscount si on a au moins une remise
             for ($i = 0; $i < $nblignes; $i++) {
                 if ($object->lines[$i]->remise_percent) {
                     $this->atleastonediscount++;
                 }
             }
             // New page
             $pdf->AddPage();
             if (!empty($tplidx)) {
                 $pdf->useTemplate($tplidx);
             }
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs, $hookmanager);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 90;
             $tab_top_newpage = empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10;
             $tab_height = 130;
             $tab_height_newpage = 150;
             // Affiche notes
             if (!empty($object->note_public)) {
                 $tab_top = 88;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - $tab_top;
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             // Loop on each lines
             for ($i = 0; $i < $nblignes; $i++) {
                 $curY = $nexY;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Into loop to work with multipage
                 $pdf->SetTextColor(0, 0, 0);
                 $pdf->setTopMargin($tab_top_newpage);
                 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
                 // The only function to edit the bottom margin of current page to set it.
                 $pageposbefore = $pdf->getPage();
                 // Description of product line
                 $curX = $this->posxdesc - 1;
                 $showpricebeforepagebreak = 1;
                 $pdf->startTransaction();
                 pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 0, $hookmanager);
                 $pageposafter = $pdf->getPage();
                 if ($pageposafter > $pageposbefore) {
                     $pdf->rollbackTransaction(true);
                     $pageposafter = $pageposbefore;
                     //print $pageposafter.'-'.$pageposbefore;exit;
                     $pdf->setPageOrientation('', 1, $heightforfooter);
                     // The only function to edit the bottom margin of current page to set it.
                     pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc, 0, $hookmanager);
                     $pageposafter = $pdf->getPage();
                     $posyafter = $pdf->GetY();
                     //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
                     if ($posyafter > $this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)) {
                         if ($i == $nblignes - 1) {
                             $pdf->AddPage('', '', true);
                             if (!empty($tplidx)) {
                                 $pdf->useTemplate($tplidx);
                             }
                             if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                                 $this->_pagehead($pdf, $object, 0, $outputlangs, $hookmanager);
                             }
                             $pdf->setPage($pagenb + 1);
                         }
                     } else {
                         // We found a page break
                         $showpricebeforepagebreak = 0;
                     }
                 } else {
                     $pdf->commitTransaction();
                 }
                 $nexY = $pdf->GetY();
                 $pageposafter = $pdf->getPage();
                 $pdf->setPage($pageposbefore);
                 $pdf->setTopMargin($this->marge_haute);
                 $pdf->setPageOrientation('', 1, 0);
                 // The only function to edit the bottom margin of current page to set it.
                 // We suppose that a too long description is moved completely on next page
                 if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
                     $pdf->setPage($pageposafter);
                     $curY = $tab_top_newpage;
                 }
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // On repositionne la police par defaut
                 // VAT Rate
                 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
                     $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails, $hookmanager);
                     $pdf->SetXY($this->posxtva, $curY);
                     $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0, 'R');
                 }
                 // Unit price before discount
                 $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager);
                 $pdf->SetXY($this->posxup, $curY);
                 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 3, $up_excl_tax, 0, 'R', 0);
                 // Quantity
                 $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails, $hookmanager);
                 $pdf->SetXY($this->posxqty, $curY);
                 $pdf->MultiCell($this->posxdiscount - $this->posxqty - 1, 3, $qty, 0, 'R');
                 // Enough for 6 chars
                 // Discount on line
                 if ($object->lines[$i]->remise_percent) {
                     $pdf->SetXY($this->posxdiscount - 2, $curY);
                     $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails, $hookmanager);
                     $pdf->MultiCell($this->postotalht - $this->posxdiscount + 2, 3, $remise_percent, 0, 'R');
                 }
                 // Total HT line
                 $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager);
                 $pdf->SetXY($this->postotalht, $curY);
                 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
                 // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
                 $tvaligne = $object->lines[$i]->total_tva;
                 $localtax1ligne = $object->lines[$i]->total_localtax1;
                 $localtax2ligne = $object->lines[$i]->total_localtax2;
                 $localtax1_rate = $object->lines[$i]->localtax1_tx;
                 $localtax2_rate = $object->lines[$i]->localtax2_tx;
                 $localtax1_type = $object->lines[$i]->localtax1_type;
                 $localtax2_type = $object->lines[$i]->localtax2_type;
                 if ($object->remise_percent) {
                     $tvaligne -= $tvaligne * $object->remise_percent / 100;
                 }
                 if ($object->remise_percent) {
                     $localtax1ligne -= $localtax1ligne * $object->remise_percent / 100;
                 }
                 if ($object->remise_percent) {
                     $localtax2ligne -= $localtax2ligne * $object->remise_percent / 100;
                 }
                 $vatrate = (string) $object->lines[$i]->tva_tx;
                 // TODO : store local taxes types into object lines and remove this
                 $localtax1_array = getLocalTaxesFromRate($vatrate, 1, $mysoc);
                 $localtax2_array = getLocalTaxesFromRate($vatrate, 2, $mysoc);
                 if (!isset($localtax1_type)) {
                     $localtax1_type = $localtax1_array[0];
                 }
                 if (!isset($localtax2_type)) {
                     $localtax2_type = $localtax2_array[0];
                 }
                 //end TODO
                 // retrieve global local tax
                 if ($localtax1_type == '7') {
                     $localtax1_rate = $localtax1_array[1];
                 }
                 if ($localtax2_type == '7') {
                     $localtax2_rate = $localtax2_array[1];
                 }
                 if ($localtax1_type && ($localtax1ligne != 0 || $localtax1_type == '7')) {
                     $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
                 }
                 if ($localtax2_type && ($localtax2ligne != 0 || $localtax2_type == '7')) {
                     $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
                 }
                 if (($object->lines[$i]->info_bits & 0x1) == 0x1) {
                     $vatrate .= '*';
                 }
                 if (!isset($this->tva[$vatrate])) {
                     $this->tva[$vatrate] = '';
                 }
                 $this->tva[$vatrate] += $tvaligne;
                 // Add line
                 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < $nblignes - 1) {
                     $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(210, 210, 210)));
                     //$pdf->SetDrawColor(190,190,200);
                     $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
                     $pdf->SetLineStyle(array('dash' => 0));
                 }
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // Detect if some page were added automatically and output _tableau for past pages
                 while ($pagenb < $pageposafter) {
                     $pdf->setPage($pagenb);
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     $pagenb++;
                     $pdf->setPage($pagenb);
                     $pdf->setPageOrientation('', 1, 0);
                     // The only function to edit the bottom margin of current page to set it.
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs, $hookmanager);
                     }
                 }
                 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     // New page
                     $pdf->AddPage();
                     if (!empty($tplidx)) {
                         $pdf->useTemplate($tplidx);
                     }
                     $pagenb++;
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs, $hookmanager);
                     }
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             }
             // Affiche zone infos
             $posy = $this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
             // Affiche zone totaux
             $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
             // Affiche zone versements
             if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) {
                 $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs);
             }
             // Pied de page
             $this->_pagefoot($pdf, $object, $outputlangs);
             //$pdf->AliasNbPages();
             $pdf->Close();
             $pdf->Output($file, 'F');
             // Add pdfgeneration hook
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
             // Pas d'erreur
         } else {
             $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     } else {
         $this->error = $langs->trans("ErrorConstantNotDefined", "FAC_OUTPUTDIR");
         return 0;
     }
     $this->error = $langs->trans("ErrorUnknown");
     return 0;
     // Erreur par defaut
 }
 /**
  *	Function to build a document on disk using the generic odt module.
  *
  *	@param		Propale		$object				Object source to build document
  *	@param		Translate	$outputlangs		Lang output object
  * 	@param		string		$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int			$hidedetails		Do not show line details
  *  @param		int			$hidedesc			Do not show desc
  *  @param		int			$hideref			Do not show ref
  *	@return		int         					1 if OK, <=0 if KO
  */
 function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 {
     global $user, $langs, $conf, $mysoc, $hookmanager;
     if (empty($srctemplatepath)) {
         dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING);
         return -1;
     }
     // Add odtgeneration hook
     if (!is_object($hookmanager)) {
         include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
         $hookmanager = new HookManager($this->db);
     }
     $hookmanager->initHooks(array('odtgeneration'));
     global $action;
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     $sav_charset_output = $outputlangs->charset_output;
     $outputlangs->charset_output = 'UTF-8';
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     if ($conf->supplier_proposal->dir_output) {
         // If $object is id instead of object
         if (!is_object($object)) {
             $id = $object;
             $object = new SupplierProposal($this->db);
             $result = $object->fetch($id);
             if ($result < 0) {
                 dol_print_error($this->db, $object->error);
                 return -1;
             }
         }
         $dir = $conf->supplier_proposal->dir_output;
         $objectref = dol_sanitizeFileName($object->ref);
         if (!preg_match('/specimen/i', $objectref)) {
             $dir .= "/" . $objectref;
         }
         $file = $dir . "/" . $objectref . ".odt";
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return -1;
             }
         }
         if (file_exists($dir)) {
             //print "srctemplatepath=".$srctemplatepath;	// Src filename
             $newfile = basename($srctemplatepath);
             $newfiletmp = preg_replace('/\\.od(t|s)/i', '', $newfile);
             $newfiletmp = preg_replace('/template_/i', '', $newfiletmp);
             $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp);
             $newfiletmp = $objectref . '_' . $newfiletmp;
             // Get extension (ods or odt)
             $newfileformat = substr($newfile, strrpos($newfile, '.') + 1);
             if (!empty($conf->global->MAIN_DOC_USE_TIMING)) {
                 $filename = $newfiletmp . '.' . dol_print_date(dol_now(), '%Y%m%d%H%M%S') . '.' . $newfileformat;
             } else {
                 $filename = $newfiletmp . '.' . $newfileformat;
             }
             $file = $dir . '/' . $filename;
             //print "newdir=".$dir;
             //print "newfile=".$newfile;
             //print "file=".$file;
             //print "conf->propal->dir_temp=".$conf->propal->dir_temp;
             dol_mkdir($conf->supplier_proposal->dir_temp);
             // If BILLING contact defined on invoice, we use it
             $usecontact = false;
             $arrayidcontact = $object->getIdContact('external', 'BILLING');
             if (count($arrayidcontact) > 0) {
                 $usecontact = true;
                 $result = $object->fetch_contact($arrayidcontact[0]);
             }
             // Recipient name
             if (!empty($usecontact)) {
                 // On peut utiliser le nom de la societe du contact
                 if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
                     $socobject = $object->contact;
                 } else {
                     $socobject = $object->client;
                 }
             } else {
                 $socobject = $object->client;
             }
             // Make substitution
             $substitutionarray = array('__FROM_NAME__' => $this->emetteur->name, '__FROM_EMAIL__' => $this->emetteur->email, '__TOTAL_TTC__' => $object->total_ttc, '__TOTAL_HT__' => $object->total_ht, '__TOTAL_VAT__' => $object->total_vat);
             complete_substitutions_array($substitutionarray, $langs, $object);
             // Call the ODTSubstitution hook
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$substitutionarray);
             $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             // Line of free text
             $newfreetext = '';
             $paramfreetext = 'SUPPLIER_PROPOSAL_FREE_TEXT';
             if (!empty($conf->global->{$paramfreetext})) {
                 $newfreetext = make_substitutions($conf->global->{$paramfreetext}, $substitutionarray);
             }
             // Open and load template
             require_once ODTPHP_PATH . 'odf.php';
             try {
                 $odfHandler = new odf($srctemplatepath, array('PATH_TO_TMP' => $conf->supplier_proposal->dir_temp, 'ZIP_PROXY' => 'PclZipProxy', 'DELIMITER_LEFT' => '{', 'DELIMITER_RIGHT' => '}'));
             } catch (Exception $e) {
                 $this->error = $e->getMessage();
                 return -1;
             }
             // After construction $odfHandler->contentXml contains content and
             // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by
             // [!-- BEGIN lines --]*[!-- END lines --]
             //print html_entity_decode($odfHandler->__toString());
             //print exit;
             // Make substitutions into odt of freetext
             try {
                 $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8');
             } catch (OdfException $e) {
             }
             // Make substitutions into odt
             $array_user = $this->get_substitutionarray_user($user, $outputlangs);
             $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs);
             $array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs);
             $array_objet = $this->get_substitutionarray_object($object, $outputlangs);
             $array_other = $this->get_substitutionarray_other($outputlangs);
             $tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_objet, $array_other);
             complete_substitutions_array($tmparray, $outputlangs, $object);
             // Call the ODTSubstitution hook
             $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
             $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             foreach ($tmparray as $key => $value) {
                 try {
                     if (preg_match('/logo$/', $key)) {
                         if (file_exists($value)) {
                             $odfHandler->setImage($key, $value);
                         } else {
                             $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8');
                         }
                     } else {
                         $odfHandler->setVars($key, $value, true, 'UTF-8');
                     }
                 } catch (OdfException $e) {
                 }
             }
             // Replace tags of lines
             try {
                 $listlines = $odfHandler->setSegment('lines');
                 foreach ($object->lines as $line) {
                     $tmparray = $this->get_substitutionarray_lines($line, $outputlangs);
                     complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines");
                     // Call the ODTSubstitutionLine hook
                     $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray, 'line' => $line);
                     $reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action);
                     // Note that $action and $object may have been modified by some hooks
                     foreach ($tmparray as $key => $val) {
                         try {
                             $listlines->setVars($key, $val, true, 'UTF-8');
                         } catch (OdfException $e) {
                         } catch (SegmentException $e) {
                         }
                     }
                     $listlines->merge();
                 }
                 $odfHandler->mergeSegment($listlines);
             } catch (OdfException $e) {
                 $this->error = $e->getMessage();
                 dol_syslog($this->error, LOG_WARNING);
                 return -1;
             }
             // Replace labels translated
             $tmparray = $outputlangs->get_translations_for_substitutions();
             foreach ($tmparray as $key => $value) {
                 try {
                     $odfHandler->setVars($key, $value, true, 'UTF-8');
                 } catch (OdfException $e) {
                 }
             }
             // Call the beforeODTSave hook
             $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
             $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             // Write new file
             if (!empty($conf->global->MAIN_ODT_AS_PDF)) {
                 try {
                     $odfHandler->exportAsAttachedPDF($file);
                 } catch (Exception $e) {
                     $this->error = $e->getMessage();
                     return -1;
                 }
             } else {
                 try {
                     $odfHandler->saveToDisk($file);
                 } catch (Exception $e) {
                     $this->error = $e->getMessage();
                     return -1;
                 }
             }
             $parameters = array('odfHandler' => &$odfHandler, 'file' => $file, 'object' => $object, 'outputlangs' => $outputlangs, 'substitutionarray' => &$tmparray);
             $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             $odfHandler = null;
             // Destroy object
             return 1;
             // Success
         } else {
             $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
             return -1;
         }
     }
     return -1;
 }
Example #18
0
 /**
  *		Function called when module is enabled.
  *		The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  *		It also creates data directories
  *
  *      @param      string	$options    Options when enabling module ('', 'noboxes')
  *      @return     int             	1 if OK, 0 if KO
  */
 function init($options = '')
 {
     global $conf, $langs;
     // Permissions
     $this->remove($options);
     //ODT template
     require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     $dirodt = DOL_DATA_ROOT . '/doctemplates/orders';
     dol_mkdir($dirodt);
     $src = DOL_DOCUMENT_ROOT . '/install/doctemplates/orders/template_order.odt';
     $dest = $dirodt . '/template_order.odt';
     $result = dol_copy($src, $dest, 0, 0);
     if ($result < 0) {
         $langs->load("errors");
         $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
         return 0;
     }
     $sql = array("DELETE FROM " . MAIN_DB_PREFIX . "document_model WHERE nom = '" . $this->const[0][2] . "' AND entity = " . $conf->entity, "INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('" . $this->const[0][2] . "','order'," . $conf->entity . ")");
     return $this->_init($sql, $options);
 }
 /**
  *  Write the object to document file to disk
  *
  *	@param	Don			$don	        Donation object
  *  @param  Translate	$outputlangs    Lang object for output language
  *	@return	int             			>0 if OK, <0 if KO
  */
 function write_file($don, $outputlangs)
 {
     global $user, $conf, $langs, $mysoc;
     $now = dol_now();
     $id = !is_object($don) ? $don : '';
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     $outputlangs->load("donations");
     if (!empty($conf->don->dir_output)) {
         // Definition de l'objet $don (pour compatibilite ascendante)
         if (!is_object($don)) {
             $don = new Don($this->db);
             $ret = $don->fetch($id);
             $id = $don->id;
         }
         // Definition de $dir et $file
         if (!empty($don->specimen)) {
             $dir = $conf->don->dir_output;
             $file = $dir . "/SPECIMEN.html";
         } else {
             $donref = dol_sanitizeFileName($don->ref);
             $dir = $conf->don->dir_output . "/" . get_exdir($donref, 2);
             $file = $dir . "/" . $donref . ".html";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
                 return -1;
             }
         }
         if (file_exists($dir)) {
             $formclass = new Form($this->db);
             //This is not the proper way to do it but $formclass->form_modes_reglement
             //prints the translation instead of returning it
             if ($don->modepaiementid) {
                 $formclass->load_cache_types_paiements();
                 $paymentmode = $formclass->cache_types_paiements[$don->modepaiementid]['label'];
             } else {
                 $paymentmode = '';
             }
             // Defini contenu
             $donmodel = DOL_DOCUMENT_ROOT . "/core/modules/dons/html_cerfafr.html";
             $form = implode('', file($donmodel));
             $form = str_replace('__REF__', $don->id, $form);
             $form = str_replace('__DATE__', dol_print_date($don->date, 'day', false, $outputlangs), $form);
             //$form = str_replace('__IP__',$user->ip,$form); // TODO $user->ip not exist
             $form = str_replace('__AMOUNT__', $don->amount, $form);
             $form = str_replace('__CURRENCY__', $outputlangs->transnoentitiesnoconv("Currency" . $conf->currency), $form);
             $form = str_replace('__CURRENCYCODE__', $conf->currency, $form);
             $form = str_replace('__MAIN_INFO_SOCIETE_NOM__', $mysoc->name, $form);
             $form = str_replace('__MAIN_INFO_SOCIETE_ADDRESS__', $mysoc->address, $form);
             $form = str_replace('__MAIN_INFO_SOCIETE_ZIP__', $mysoc->zip, $form);
             $form = str_replace('__MAIN_INFO_SOCIETE_TOWN__', $mysoc->town, $form);
             $form = str_replace('__DONATOR_FIRSTNAME__', $don->firstname, $form);
             $form = str_replace('__DONATOR_LASTNAME__', $don->lastname, $form);
             $form = str_replace('__DONATOR_ADDRESS__', $don->address, $form);
             $form = str_replace('__DONATOR_ZIP__', $don->zip, $form);
             $form = str_replace('__DONATOR_TOWN__', $don->town, $form);
             $form = str_replace('__PAYMENTMODE_LIB__ ', $paymentmode, $form);
             $form = str_replace('__NOW__', dol_print_date($now, '', false, $outputlangs), $form);
             $form = str_replace('__DonationRef__', $outputlangs->trans("DonationRef"), $form);
             $form = str_replace('__DonationReceipt__', $outputlangs->trans("DonationReceipt"), $form);
             $form = str_replace('__DonationRecipient__', $outputlangs->trans("DonationRecipient"), $form);
             $form = str_replace('__DatePayment__', $outputlangs->trans("DatePayment"), $form);
             $form = str_replace('__PaymentMode__', $outputlangs->trans("PaymentMode"), $form);
             $form = str_replace('__Name__', $outputlangs->trans("Name"), $form);
             $form = str_replace('__Address__', $outputlangs->trans("Address"), $form);
             $form = str_replace('__Zip__', $outputlangs->trans("Zip"), $form);
             $form = str_replace('__Town__', $outputlangs->trans("Town"), $form);
             $form = str_replace('__Donor__', $outputlangs->trans("Donor"), $form);
             $form = str_replace('__Date__', $outputlangs->trans("Date"), $form);
             $form = str_replace('__Signature__', $outputlangs->trans("Signature"), $form);
             $form = str_replace('__ThankYou__', $outputlangs->trans("ThankYou"), $form);
             $form = str_replace('__IConfirmDonationReception__', $outputlangs->trans("IConfirmDonationReception"), $form);
             $frencharticle = '';
             if (preg_match('/fr/i', $outputlangs->defaultlang)) {
                 $frencharticle = '<font size="+1"><b>(Article 200-5 du Code Général des Impôts)</b></font><br>+ article 238 bis';
             }
             $form = str_replace('__FrenchArticle__', $frencharticle, $form);
             // Sauve fichier sur disque
             dol_syslog("html_cerfafr::write_file {$file}");
             $handle = fopen($file, "w");
             fwrite($handle, $form);
             fclose($handle);
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
         } else {
             $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     } else {
         $this->error = $langs->trans("ErrorConstantNotDefined", "DON_OUTPUTDIR");
         return 0;
     }
     $this->error = $langs->trans("ErrorUnknown");
     return 0;
     // Erreur par defaut
 }
Example #20
0
$day = dol_print_date($datetime, "%d");
if (!empty($_GET["year"])) {
    $year = sprintf("%04d", $_GET["year"]);
}
if (!empty($_GET["month"])) {
    $month = sprintf("%02d", $_GET["month"]);
}
$acct = new Account($db);
if ($_GET["account"] && !preg_match('/,/', $_GET["account"])) {
    $result = $acct->fetch($_GET["account"]);
}
if ($_GET["ref"]) {
    $result = $acct->fetch(0, $_GET["ref"]);
    $account = $acct->id;
}
$result = dol_mkdir($conf->banque->dir_temp);
if ($result < 0) {
    $langs->load("errors");
    $error++;
    setEventMessages($langs->trans("ErrorFailedToCreateDir"), null, 'errors');
} else {
    // Calcul $min and $max
    $sql = "SELECT MIN(b.datev) as min, MAX(b.datev) as max";
    $sql .= " FROM " . MAIN_DB_PREFIX . "bank as b";
    $sql .= ", " . MAIN_DB_PREFIX . "bank_account as ba";
    $sql .= " WHERE b.fk_account = ba.rowid";
    $sql .= " AND ba.entity IN (" . getEntity('bank_account', 1) . ")";
    if ($account && $_GET["option"] != 'all') {
        $sql .= " AND b.fk_account IN (" . $account . ")";
    }
    $resql = $db->query($sql);
Example #21
0
					{
						$filetarget=$dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/'.$name.$ext;
						$filetargetsmall=$dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/thumbs/'.$name.'_small'.$ext;
						$existt=dol_is_file($filetarget);
						if (! $existt)
						{
							dol_mkdir($dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos');

							print "  &nbsp; &nbsp; &nbsp; -> Copy file ".$filetotest." -> ".$filetarget."<br>\n";
							dol_copy($filetotest, $filetarget, '', 0);
						}

						$existtt=dol_is_file($filetargetsmall);
						if (! $existtt)
						{
							dol_mkdir($dolibarr_main_data_root.'/societe/'.$obj->rowid.'/logos/thumbs');

							print "  &nbsp; &nbsp; &nbsp; -> Copy file ".$filetotestsmall." -> ".$filetargetsmall."<br>\n";
							dol_copy($filetotestsmall, $filetargetsmall, '', 0);
						}
					}
				}

				$i++;
			}
		}
		else
		{
			$ok=0;
			dol_print_error($db);
		}
Example #22
0
 */
require "../../main.inc.php";
require_once DOL_DOCUMENT_ROOT . "/expedition/class/expedition.class.php";
require_once DOL_DOCUMENT_ROOT . "/expedition/class/expeditionstats.class.php";
require_once DOL_DOCUMENT_ROOT . "/core/class/dolgraph.class.php";
/*
 * View
 */
llxHeader();
$WIDTH = 500;
$HEIGHT = 200;
$mesg = '';
print_fiche_titre($langs->trans("StatisticsOfSendings") . ' ' . $_GET["year"], $mesg);
$stats = new ExpeditionStats($db);
$data = $stats->getNbExpeditionByMonth($_GET["year"]);
dol_mkdir($conf->expedition->dir_temp);
$filename = $conf->expedition->dir_temp . "/expedition" . $year . ".png";
$fileurl = DOL_URL_ROOT . '/viewimage.php?modulepart=expeditionstats&file=expedition' . $year . '.png';
$px = new DolGraph();
$mesg = $px->isGraphKo();
if (!$mesg) {
    $px->SetData($data);
    $px->SetMaxValue($px->GetCeilMaxValue());
    $px->SetWidth($WIDTH);
    $px->SetHeight($HEIGHT);
    $px->SetYLabel($langs->trans("NbOfOrders"));
    $px->SetShading(3);
    $px->SetHorizTickIncrement(1);
    $px->SetPrecisionY(0);
    $px->draw($filename, $fileurl);
}
 /**
  *  Function to build pdf onto disk
  *
  *  @param		Object		$object				Object to generate
  *  @param		Translate	$outputlangs		Lang output object
  *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int			$hidedetails		Do not show line details
  *  @param		int			$hidedesc			Do not show desc
  *  @param		int			$hideref			Do not show ref
  *  @return     int             				1=OK, 0=KO
  */
 function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 {
     global $user, $langs, $conf, $mysoc, $db, $hookmanager;
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("trips");
     $outputlangs->load("project");
     $nblignes = count($object->lines);
     if ($conf->expensereport->dir_output) {
         // Definition of $dir and $file
         if ($object->specimen) {
             $dir = $conf->expensereport->dir_output;
             $file = $dir . "/SPECIMEN.pdf";
         } else {
             $objectref = dol_sanitizeFileName($object->ref);
             $dir = $conf->expensereport->dir_output . "/" . $objectref;
             $file = $dir . "/" . $objectref . ".pdf";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (isset($object->lignes) && !isset($object->lines)) {
             $object->lines = $object->lignes;
         }
         if (file_exists($dir)) {
             // Add pdfgeneration hook
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action);
             // Note that $action and $object may have been modified by some hooks
             // Create pdf instance
             $pdf = pdf_getInstance($this->format);
             $default_font_size = pdf_getPDFFontSize($outputlangs);
             // Must be after pdf_getInstance
             $heightforinfotot = 50;
             // Height reserved to output the info and total part
             $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
             $heightforfooter = $this->marge_basse + 8;
             // Height reserved to output the footer (value include bottom margin)
             $pdf->SetAutoPageBreak(1, 0);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref_number));
             $pdf->SetSubject($outputlangs->transnoentities("Trips"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Trips"));
             if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             // Positionne $this->atleastonediscount si on a au moins une remise
             for ($i = 0; $i < $nblignes; $i++) {
                 if ($object->lines[$i]->remise_percent) {
                     $this->atleastonediscount++;
                 }
             }
             // New page
             $pdf->AddPage();
             if (!empty($tplidx)) {
                 $pdf->useTemplate($tplidx);
             }
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 95;
             $tab_top_newpage = empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 95 : 10;
             $tab_height = 110;
             $tab_height_newpage = 110;
             // Show notes
             $notetoshow = empty($object->note_public) ? '' : $object->note_public;
             if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
                 // Get first sale rep
                 if (is_object($object->thirdparty)) {
                     $salereparray = $object->thirdparty->getSalesRepresentatives($user);
                     $salerepobj = new User($this->db);
                     $salerepobj->fetch($salereparray[0]['id']);
                     if (!empty($salerepobj->signature)) {
                         $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
                     }
                 }
             }
             if ($notetoshow) {
                 $tab_top = 95;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->writeHTMLCell(190, 3, $this->posxpiece - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - $tab_top;
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             // Loop on each lines
             for ($i = 0; $i < $nblignes; $i++) {
                 $piece_comptable = $i + 1;
                 $curY = $nexY;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 // Into loop to work with multipage
                 $pdf->SetTextColor(0, 0, 0);
                 $pdf->setTopMargin($tab_top_newpage);
                 $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
                 // The only function to edit the bottom margin of current page to set it.
                 $pageposbefore = $pdf->getPage();
                 // Description of product line
                 $curX = $this->posxdesc - 1;
                 $showpricebeforepagebreak = 1;
                 // Accountancy piece
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->writeHTMLCell($this->posxcomment - $this->posxpiece - 1, 3, $this->posxpiece - 1, $curY, $piece_comptable, 0, 1);
                 // Comments
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->SetXY($this->posxcomment, $curY);
                 $pdf->writeHTMLCell($this->posxdate - $this->posxdesc - 1, 3, $this->posxdesc - 1, $curY, $object->lines[$i]->comments, 0, 1);
                 //nexY
                 $nexY = $pdf->GetY();
                 $pageposafter = $pdf->getPage();
                 $pdf->setPage($pageposbefore);
                 $pdf->setTopMargin($this->marge_haute);
                 $pdf->setPageOrientation('', 1, 0);
                 // The only function to edit the bottom margin of current page to set it.
                 // Date
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->SetXY($this->posxdate, $curY);
                 $pdf->MultiCell($this->posxtype - $this->posxdate - 1, 3, dol_print_date($object->lines[$i]->date, "day", false, $outpulangs), 0, 'C');
                 // Type
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->SetXY($this->posxtype, $curY);
                 $pdf->MultiCell($this->posxprojet - $this->posxtype - 1, 3, $outputlangs->transnoentities($object->lines[$i]->type_fees_code), 0, 'C');
                 // Project
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->SetXY($this->posxprojet, $curY);
                 $pdf->MultiCell($this->posxtva - $this->posxprojet - 1, 3, $object->lines[$i]->projet_ref, 0, 'C');
                 // VAT Rate
                 if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
                     $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
                     $pdf->SetFont('', '', $default_font_size - 1);
                     $pdf->SetXY($this->posxtva, $curY);
                     $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0, 'R');
                 }
                 // Unit price
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->SetXY($this->posxup, $curY);
                 $pdf->MultiCell($this->posxqty - $this->posxup - 1, 3, price($object->lines[$i]->value_unit), 0, 'R');
                 // Quantity
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->SetXY($this->posxqty, $curY);
                 $pdf->MultiCell($this->postotalttc - $this->posxqty, 3, $object->lines[$i]->qty, 0, 'C');
                 // Total with all taxes
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->SetXY($this->postotalttc - 1, $curY);
                 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalttc, 3, price($object->lines[$i]->total_ttc), 0, 'R');
                 $nexY += 5;
                 // Cherche nombre de lignes a venir pour savoir si place suffisante
                 if ($i < $nblignes - 1) {
                     //on recupere la description du produit suivant
                     $follow_descproduitservice = $object->lines[$i + 1]->desc;
                     //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres)
                     $nblineFollowDesc = dol_nboflines_bis($follow_descproduitservice, 52, $outputlangs->charset_output) * 4;
                     // Et si on affiche dates de validite, on ajoute encore une ligne
                     if ($object->lines[$i]->date_start && $object->lines[$i]->date_end) {
                         $nblineFollowDesc += 4;
                     }
                 } else {
                     $nblineFollowDesc = 0;
                 }
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // Detect if some page were added automatically and output _tableau for past pages
                 while ($pagenb < $pageposafter) {
                     $pdf->setPage($pagenb);
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     $pagenb++;
                     $pdf->setPage($pagenb);
                     $pdf->setPageOrientation('', 1, 0);
                     // The only function to edit the bottom margin of current page to set it.
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs);
                     }
                 }
                 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     // New page
                     $pdf->AddPage();
                     if (!empty($tplidx)) {
                         $pdf->useTemplate($tplidx);
                     }
                     $pagenb++;
                     if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                         $this->_pagehead($pdf, $object, 0, $outputlangs);
                     }
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             }
             // Show total area box
             $posy = $bottomlasttab + 5;
             //$nexY+95;
             $pdf->SetXY(100, $posy);
             $pdf->MultiCell(60, 5, $outputlangs->transnoentities("TotalHT"), 1, 'L');
             $pdf->SetXY(160, $posy);
             $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 160, 5, price($object->total_ht), 1, 'R');
             $pdf->SetFillColor(248, 248, 248);
             if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
                 $posy += 5;
                 $pdf->SetXY(100, $posy);
                 $pdf->SetTextColor(0, 0, 60);
                 $pdf->MultiCell(60, 5, $outputlangs->transnoentities("TotalVAT"), 1, 'L');
                 $pdf->SetXY(160, $posy);
                 $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 160, 5, price($object->total_tva), 1, 'R');
             }
             $posy += 5;
             $pdf->SetXY(100, $posy);
             $pdf->SetFont('', 'B', 10);
             $pdf->SetTextColor(0, 0, 60);
             $pdf->MultiCell(60, 5, $outputlangs->transnoentities("TotalTTC"), 1, 'L');
             $pdf->SetXY(160, $posy);
             $pdf->MultiCell($this->page_largeur - $this->marge_gauche - 160, 5, price($object->total_ttc), 1, 'R');
             // Pied de page
             $this->_pagefoot($pdf, $object, $outputlangs);
             if (method_exists($pdf, 'AliasNbPages')) {
                 $pdf->AliasNbPages();
             }
             $pdf->Close();
             $pdf->Output($file, 'F');
             // Add pdfgeneration hook
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
             // Pas d'erreur
         } else {
             $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     } else {
         $this->error = $langs->trans("ErrorConstantNotDefined", "EXPENSEREPORT_OUTPUTDIR");
         return 0;
     }
     $this->error = $langs->trans("ErrorUnknown");
     return 0;
     // Erreur par defaut
 }
Example #24
0
 /**
  * 	Dump a LDAP message to ldapinput.in file
  *
  *	@param	string		$dn			DN entry key
  *	@param	array		$info		Attributes array
  *	@return	int						<0 if KO, >0 if OK
  */
 function dump($dn, $info)
 {
     global $conf;
     // Create content
     $content = $this->dump_content($dn, $info);
     //Create file
     $result = dol_mkdir($conf->ldap->dir_temp);
     $outputfile = $conf->ldap->dir_temp . '/ldapinput.in';
     $fp = fopen($outputfile, "w");
     if ($fp) {
         fputs($fp, $content);
         fclose($fp);
         if (!empty($conf->global->MAIN_UMASK)) {
             @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
         }
         return 1;
     } else {
         return -1;
     }
 }
Example #25
0
  * path for PDF fonts
  * use K_PATH_MAIN.'fonts/old/' for old non-UTF8 fonts
  */
 define('K_PATH_FONTS', K_PATH_MAIN . 'fonts/');
 /**
  * cache directory for temporary files (full path)
  */
 //	define ('K_PATH_CACHE', K_PATH_MAIN.'cache/');
 define('K_PATH_CACHE', DOL_DATA_ROOT . '/admin/temp/');
 dol_mkdir(K_PATH_CACHE);
 /**
  * cache directory for temporary files (url path)
  */
 //	define ('K_PATH_URL_CACHE', K_PATH_URL.'cache/');
 define('K_PATH_URL_CACHE', DOL_DATA_ROOT . '/admin/temp/');
 dol_mkdir(K_PATH_URL_CACHE);
 /**
  *images directory
  */
 define('K_PATH_IMAGES', K_PATH_MAIN . 'images/');
 /**
  * blank image
  */
 define('K_BLANK_IMAGE', K_PATH_IMAGES . '_blank.png');
 /**
  * page format
  */
 define('PDF_PAGE_FORMAT', 'A4');
 /**
  * page orientation (P=portrait, L=landscape)
  */
Example #26
0
 /**
  *  Function to build pdf onto disk
  *
  *  @param		Object			$object				Object to generate
  *  @param		Translate		$outputlangs		Lang output object
  *  @param		string			$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int				$hidedetails		Do not show line details
  *  @param		int				$hidedesc			Do not show desc
  *  @param		int				$hideref			Do not show ref
  *  @return		int									1=OK, 0=KO
  */
 function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 {
     global $user, $langs, $conf, $mysoc, $db, $hookmanager;
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("interventions");
     if ($conf->ficheinter->dir_output) {
         $object->fetch_thirdparty();
         // Definition of $dir and $file
         if ($object->specimen) {
             $dir = $conf->ficheinter->dir_output;
             $file = $dir . "/SPECIMEN.pdf";
         } else {
             $objectref = dol_sanitizeFileName($object->ref);
             $dir = $conf->ficheinter->dir_output . "/" . $objectref;
             $file = $dir . "/" . $objectref . ".pdf";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             // Add pdfgeneration hook
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action);
             // Note that $action and $object may have been modified by some hooks
             $nblignes = count($object->lines);
             // Create pdf instance
             $pdf = pdf_getInstance($this->format);
             $default_font_size = pdf_getPDFFontSize($outputlangs);
             // Must be after pdf_getInstance
             $heightforinfotot = 50;
             // Height reserved to output the info and total part
             $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
             $heightforfooter = $this->marge_basse + 8;
             // Height reserved to output the footer (value include bottom margin)
             $pdf->SetAutoPageBreak(1, 0);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("InterventionCard"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("InterventionCard"));
             if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             // New page
             $pdf->AddPage();
             if (!empty($tplidx)) {
                 $pdf->useTemplate($tplidx);
             }
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 90;
             $tab_top_newpage = empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10;
             $tab_height = 130;
             $tab_height_newpage = 150;
             // Affiche notes
             $notetoshow = empty($object->note_public) ? '' : $object->note_public;
             if ($notetoshow) {
                 $tab_top = 88;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - $tab_top;
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             $pdf->SetXY($this->marge_gauche, $tab_top);
             $pdf->MultiCell(190, 5, $outputlangs->transnoentities("Description"), 0, 'L', 0);
             $pdf->line($this->marge_gauche, $tab_top + 5, $this->page_largeur - $this->marge_droite, $tab_top + 5);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->SetXY($this->marge_gauche, $tab_top + 5);
             $text = $object->description;
             if ($object->duree > 0) {
                 $totaltime = convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
                 $text .= ($text ? ' - ' : '') . $langs->trans("Total") . ": " . $totaltime;
             }
             $desc = dol_htmlentitiesbr($text, 1);
             //print $outputlangs->convToOutputCharset($desc); exit;
             $pdf->writeHTMLCell(180, 3, 10, $tab_top + 5, $outputlangs->convToOutputCharset($desc), 0, 1);
             $nexY = $pdf->GetY();
             $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
             $nblines = count($object->lines);
             // Loop on each lines
             for ($i = 0; $i < $nblines; $i++) {
                 $objectligne = $object->lines[$i];
                 $valide = empty($objectligne->id) ? 0 : $objectligne->fetch($objectligne->id);
                 if ($valide > 0 || $object->specimen) {
                     $curY = $nexY;
                     $pdf->SetFont('', '', $default_font_size - 1);
                     // Into loop to work with multipage
                     $pdf->SetTextColor(0, 0, 0);
                     $pdf->setTopMargin($tab_top_newpage);
                     $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
                     // The only function to edit the bottom margin of current page to set it.
                     $pageposbefore = $pdf->getPage();
                     // Description of product line
                     $curX = $this->posxdesc - 1;
                     // Description of product line
                     $txt = $outputlangs->transnoentities("Date") . " : " . dol_print_date($objectligne->datei, 'dayhour', false, $outputlangs, true);
                     if ($objectligne->duration > 0) {
                         $txt .= " - " . $outputlangs->transnoentities("Duration") . " : " . convertSecondToTime($objectligne->duration);
                     }
                     $txt = '<strong>' . dol_htmlentitiesbr($txt, 1, $outputlangs->charset_output) . '</strong>';
                     $desc = dol_htmlentitiesbr($objectligne->desc, 1);
                     $pdf->startTransaction();
                     $pdf->writeHTMLCell(0, 0, $curX, $curY + 1, dol_concatdesc($txt, $desc), 0, 1, 0);
                     $pageposafter = $pdf->getPage();
                     if ($pageposafter > $pageposbefore) {
                         $pdf->rollbackTransaction(true);
                         $pageposafter = $pageposbefore;
                         //print $pageposafter.'-'.$pageposbefore;exit;
                         $pdf->setPageOrientation('', 1, $heightforfooter);
                         // The only function to edit the bottom margin of current page to set it.
                         $pdf->writeHTMLCell(0, 0, $curX, $curY, $txt . '<br>' . $desc, LR, 1, 0);
                         $pageposafter = $pdf->getPage();
                         $posyafter = $pdf->GetY();
                         //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
                         if ($posyafter > $this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)) {
                             if ($i == $nblines - 1) {
                                 $pdf->AddPage('', '', true);
                                 if (!empty($tplidx)) {
                                     $pdf->useTemplate($tplidx);
                                 }
                                 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                                     $this->_pagehead($pdf, $object, 0, $outputlangs);
                                 }
                                 $pdf->setPage($pageposafter + 1);
                             }
                         }
                     } else {
                         $pdf->commitTransaction();
                     }
                     $nexY = $pdf->GetY();
                     $pageposafter = $pdf->getPage();
                     $pdf->setPage($pageposbefore);
                     $pdf->setTopMargin($this->marge_haute);
                     $pdf->setPageOrientation('', 1, 0);
                     // The only function to edit the bottom margin of current page to set it.
                     // We suppose that a too long description is moved completely on next page
                     if ($pageposafter > $pageposbefore) {
                         $pdf->setPage($pageposafter);
                         $curY = $tab_top_newpage;
                     }
                     $pdf->SetFont('', '', $default_font_size - 1);
                     // On repositionne la police par defaut
                     // Detect if some page were added automatically and output _tableau for past pages
                     while ($pagenb < $pageposafter) {
                         $pdf->setPage($pagenb);
                         if ($pagenb == 1) {
                             $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                         } else {
                             $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                         }
                         $this->_pagefoot($pdf, $object, $outputlangs, 1);
                         $pagenb++;
                         $pdf->setPage($pagenb);
                         $pdf->setPageOrientation('', 1, 0);
                         // The only function to edit the bottom margin of current page to set it.
                         if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                             $this->_pagehead($pdf, $object, 0, $outputlangs);
                         }
                     }
                     if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
                         if ($pagenb == 1) {
                             $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                         } else {
                             $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                         }
                         $this->_pagefoot($pdf, $object, $outputlangs, 1);
                         // New page
                         $pdf->AddPage();
                         if (!empty($tplidx)) {
                             $pdf->useTemplate($tplidx);
                         }
                         $pagenb++;
                         if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
                             $this->_pagehead($pdf, $object, 0, $outputlangs);
                         }
                     }
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             }
             $this->_pagefoot($pdf, $object, $outputlangs);
             if (method_exists($pdf, 'AliasNbPages')) {
                 $pdf->AliasNbPages();
             }
             $pdf->Close();
             $pdf->Output($file, 'F');
             // Add pdfgeneration hook
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
         } else {
             $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     } else {
         $this->error = $langs->trans("ErrorConstantNotDefined", "FICHEINTER_OUTPUTDIR");
         return 0;
     }
     $this->error = $langs->trans("ErrorUnknown");
     return 0;
     // Erreur par defaut
 }
 /**
  * Creates directories
  *
  * @return  int Error count (0 if OK)
  */
 function create_dirs()
 {
     global $langs, $conf;
     $err = 0;
     if (isset($this->dirs) && is_array($this->dirs)) {
         foreach ($this->dirs as $key => $value) {
             $addtodatabase = 0;
             if (!is_array($value)) {
                 $dir = $value;
             } else {
                 $constname = $this->const_name . "_DIR_";
                 $dir = $this->dirs[$key][1];
                 $addtodatabase = empty($this->dirs[$key][2]) ? '' : $this->dirs[$key][2];
                 // Create constante in llx_const
                 $subname = empty($this->dirs[$key][3]) ? '' : strtoupper($this->dirs[$key][3]);
                 // Add submodule name (ex: $conf->module->submodule->dir_output)
                 $forcename = empty($this->dirs[$key][4]) ? '' : strtoupper($this->dirs[$key][4]);
                 // Change the module name if different
                 if (!empty($forcename)) {
                     $constname = 'MAIN_MODULE_' . $forcename . "_DIR_";
                 }
                 if (!empty($subname)) {
                     $constname = $constname . $subname . "_";
                 }
                 $name = $constname . strtoupper($this->dirs[$key][0]);
             }
             // Define directory full path ($dir must start with "/")
             if (empty($conf->global->MAIN_MODULE_MULTICOMPANY) || $conf->entity == 1) {
                 $fulldir = DOL_DATA_ROOT . $dir;
             } else {
                 $fulldir = DOL_DATA_ROOT . "/" . $conf->entity . $dir;
             }
             // Create dir if it does not exists
             if (!empty($fulldir) && !file_exists($fulldir)) {
                 if (dol_mkdir($fulldir, DOL_DATA_ROOT) < 0) {
                     $this->error = $langs->trans("ErrorCanNotCreateDir", $fulldir);
                     dol_syslog(get_class($this) . "::_init " . $this->error, LOG_ERR);
                     $err++;
                 }
             }
             // Define the constant in database if requested (not the default mode)
             if (!empty($addtodatabase)) {
                 $result = $this->insert_dirs($name, $dir);
                 if ($result) {
                     $err++;
                 }
             }
         }
     }
     return $err;
 }
 /**
  *	Function to build pdf onto disk
  *
  *	@param		Object		&$object			Object expedition to generate (or id if old method)
  *	@param		Translate	$outputlangs		Lang output object
  *  @param		string		$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int			$hidedetails		Do not show line details
  *  @param		int			$hidedesc			Do not show desc
  *  @param		int			$hideref			Do not show ref
  *  @return     int         	    			1=OK, 0=KO
  */
 function write_file(&$object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 {
     global $user, $conf, $langs, $mysoc, $hookmanager;
     $object->fetch_thirdparty();
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("bills");
     $outputlangs->load("products");
     $outputlangs->load("propal");
     $outputlangs->load("deliveries");
     $outputlangs->load("sendings");
     if ($conf->expedition->dir_output) {
         $object->fetch_thirdparty();
         $origin = $object->origin;
         //Creation de l expediteur
         $this->expediteur = $mysoc;
         //Creation du destinataire
         $idcontact = $object->{$origin}->getIdContact('external', 'SHIPPING');
         $this->destinataire = new Contact($this->db);
         if (!empty($idcontact[0])) {
             $this->destinataire->fetch($idcontact[0]);
         }
         //Creation du livreur
         $idcontact = $object->{$origin}->getIdContact('internal', 'LIVREUR');
         $this->livreur = new User($this->db);
         if (!empty($idcontact[0])) {
             $this->livreur->fetch($idcontact[0]);
         }
         // Definition de $dir et $file
         if ($object->specimen) {
             $dir = $conf->expedition->dir_output . "/sending";
             $file = $dir . "/SPECIMEN.pdf";
         } else {
             $expref = dol_sanitizeFileName($object->ref);
             $dir = $conf->expedition->dir_output . "/sending/" . $expref;
             $file = $dir . "/" . $expref . ".pdf";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             $nblignes = count($object->lines);
             $pdf = pdf_getInstance($this->format, 'mm', 'l');
             $default_font_size = pdf_getPDFFontSize($outputlangs);
             $heightforinfotot = 0;
             // Height reserved to output the info and total part
             $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
             $heightforfooter = $this->marge_basse + 8;
             // Height reserved to output the footer (value include bottom margin)
             $pdf->SetAutoPageBreak(1, 0);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             //$pdf->AliasNbPages();
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("Sending"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Sending"));
             if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             // New page
             $pdf->AddPage();
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $pdf->SetFont('', '', $default_font_size - 3);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 52;
             $tab_top_newpage = empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10;
             $tab_height = $this->page_hauteur - $tab_top - $heightforfooter;
             $tab_height_newpage = $this->page_hauteur - $tab_top_newpage - $heightforfooter;
             // Affiche notes
             if (!empty($object->note_public)) {
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - $tab_top;
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $pdf->SetFillColor(240, 240, 240);
             $pdf->SetTextColor(0, 0, 0);
             $pdf->SetXY(10, $tab_top + 5);
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             $num = count($object->lines);
             // Loop on each lines
             for ($i = 0; $i < $num; $i++) {
                 $curY = $nexY;
                 $pdf->SetFont('', '', $default_font_size - 3);
                 $pdf->SetTextColor(0, 0, 0);
                 $pdf->setTopMargin($tab_top_newpage);
                 $pdf->setPageOrientation('', 1, $heightforfooter);
                 // The only function to edit the bottom margin of current page to set it.
                 $pageposbefore = $pdf->getPage();
                 // Description de la ligne produit
                 $libelleproduitservice = pdf_writelinedesc($pdf, $object, $i, $outputlangs, 90, 3, 50, $curY, 0, 1);
                 $nexY = $pdf->GetY();
                 $pageposafter = $pdf->getPage();
                 $pdf->setPage($pageposbefore);
                 $pdf->setTopMargin($this->marge_haute);
                 $pdf->setPageOrientation('', 1, 0);
                 // The only function to edit the bottom margin of current page to set it.
                 // We suppose that a too long description is moved completely on next page
                 if ($pageposafter > $pageposbefore) {
                     $pdf->setPage($pageposafter);
                     $curY = $tab_top_newpage;
                 }
                 $pdf->SetFont('', '', $default_font_size - 3);
                 //Creation des cases a cocher
                 $pdf->Rect(10 + 3, $curY, 3, 3);
                 $pdf->Rect(20 + 3, $curY, 3, 3);
                 //Insertion de la reference du produit
                 $pdf->SetXY(30, $curY);
                 $pdf->SetFont('', 'B', $default_font_size - 3);
                 $pdf->MultiCell(24, 3, $outputlangs->convToOutputCharset($object->lines[$i]->ref), 0, 'L', 0);
                 $pdf->SetXY(140, $curY);
                 $pdf->MultiCell(30, 3, $object->lines[$i]->qty_asked, 0, 'C', 0);
                 $pdf->SetXY(170, $curY);
                 $pdf->MultiCell(30, 3, $object->lines[$i]->qty_shipped, 0, 'C', 0);
                 // Add line
                 if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < $nblignes - 1) {
                     $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(210, 210, 210)));
                     //$pdf->SetDrawColor(190,190,200);
                     $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
                     $pdf->SetLineStyle(array('dash' => 0));
                 }
                 $nexY += 2;
                 // Passe espace entre les lignes
                 // Detect if some page were added automatically and output _tableau for past pages
                 while ($pagenb < $pageposafter) {
                     $pdf->setPage($pagenb);
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     $pagenb++;
                     $pdf->setPage($pagenb);
                     $pdf->setPageOrientation('', 1, 0);
                     // The only function to edit the bottom margin of current page to set it.
                 }
                 if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
                     if ($pagenb == 1) {
                         $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                     } else {
                         $this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                     }
                     $this->_pagefoot($pdf, $object, $outputlangs, 1);
                     // New page
                     $pdf->AddPage();
                     $pagenb++;
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
             }
             // Pied de page
             $this->_pagefoot($pdf, $object, $outputlangs);
             //$pdf->AliasNbPages();
             $pdf->Close();
             $pdf->Output($file, 'F');
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
         } else {
             $this->error = $outputlangs->transnoentities("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     } else {
         $this->error = $outputlangs->transnoentities("ErrorConstantNotDefined", "EXP_OUTPUTDIR");
         return 0;
     }
     $this->error = $outputlangs->transnoentities("ErrorUnknown");
     return 0;
     // Erreur par defaut
 }
Example #29
0
}
if (!$sortfield) {
    $sortfield = "name";
}
$object = new Account($db);
if ($id) {
    $object->fetch($id);
}
/*
 * Actions
 */
// Envoi fichier
if ($_POST["sendit"] && !empty($conf->global->MAIN_UPLOAD_DOC)) {
    if ($object->fetch($id)) {
        $upload_dir = $conf->bank->dir_output . "/" . $object->ref;
        if (dol_mkdir($upload_dir) >= 0) {
            $resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']), 0, 0, $_FILES['userfile']['error']);
            if (is_numeric($resupload) && $resupload > 0) {
                if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1) {
                    // Create small thumbs for image (Ratio is near 16/9)
                    // Used on logon for example
                    $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
                    // Create mini thumbs for image (Ratio is near 16/9)
                    // Used on menu or for setup page for example
                    $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
                }
                $mesg = '<div class="ok">' . $langs->trans("FileTransferComplete") . '</div>';
            } else {
                $langs->load("errors");
                if ($resupload < 0) {
                    // Unknown error
Example #30
0
        $label = $listeall[$key];
        print '<td>' . $form->textwithpicto($label, $text) . '</td>';
        print '<td>' . $objmodelexport->getLibLabelForKey($key) . '</td><td align="right">' . $objmodelexport->getLibVersionForKey($key) . '</td></tr>' . "\n";
    }
    print '</table>';
    print '</div>';
    print '<table width="100%">';
    if ($sqlusedforexport && $user->admin) {
        print '<tr><td>';
        print info_admin($langs->trans("SQLUsedForExport") . ':<br> ' . $sqlusedforexport);
        print '</td></tr>';
    }
    print '</table>';
    print '<table width="100%"><tr><td width="50%">';
    if (!is_dir($conf->export->dir_temp)) {
        dol_mkdir($conf->export->dir_temp);
    }
    // Affiche liste des documents
    // NB: La fonction show_documents rescanne les modules qd genallowed=1, sinon prend $liste
    $formfile->show_documents('export', '', $upload_dir, $_SERVER["PHP_SELF"] . '?step=5&datatoexport=' . $datatoexport, $liste, 1, !empty($_POST['model']) ? $_POST['model'] : 'csv', 1, 1);
    print '</td><td width="50%">&nbsp;</td></tr>';
    print '</table>';
}
print '<br>';
llxFooter();
$db->close();
exit;
// don't know why but apache hangs with php 5.3.10-1ubuntu3.12 and apache 2.2.2 if i remove this exit or replace with return
/**
 * 	Return table name of an alias. For this, we look for the "tablename as alias" in sql string.
 *