X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=reporting%2Fincludes%2Fpdf_report.inc;h=e3d84a1914e94c8dfda83a6cb954534bab8cfc0f;hb=ba6ef7ddb2676a61cb46091d299708473beb659e;hp=ffd0fe6bc371baf3a953787314e8abdf2299494e;hpb=ab7ef36ac4dc1d5187c86345de6706c7481b959f;p=fa-stable.git diff --git a/reporting/includes/pdf_report.inc b/reporting/includes/pdf_report.inc index ffd0fe6b..e3d84a19 100644 --- a/reporting/includes/pdf_report.inc +++ b/reporting/includes/pdf_report.inc @@ -1,8 +1,11 @@ titleCol = $this->leftMargin + 100; $this->lineHeight = 12; $this->fontSize = $fontsize; + $this->oldFontSize = 0; + $this->row = $this->pageHeight - $this->topMargin; $this->currency = ''; - $this->rtl = ($_SESSION['language']->dir == 'rtl'); - // for quick testing - //$this->rtl = true; - $this->Cpdf($this->size); + $rtl = ($_SESSION['language']->dir === 'rtl' ? 'rtl' : 'ltr'); + $code = $_SESSION['language']->code; + $enc = strtoupper($_SESSION['language']->encoding); + // for the language array in class.pdf.inc + $l = array('a_meta_charset' => $enc, 'a_meta_dir' => $rtl, 'a_meta_language' => $code, 'w_page' => 'page'); + $this->Cpdf($size, $l); } function Font($style = 'normal') { - global $path_to_root; - $own = false; - $locale = $path_to_root . "lang/" . $_SESSION['language']->code . "/locale.inc"; - if (file_exists($locale)) - { - $fontinclude = true; - include($locale); - } - if (!$own) - { - if ($style == 'italic') - $path = $path_to_root . 'reporting/fonts/Helvetica-Oblique.afm'; - elseif ($style == 'bold') - $path = $path_to_root . 'reporting/fonts/Helvetica-Bold.afm'; - else // even take misspelled styles - $path = $path_to_root . 'reporting/fonts/Helvetica.afm'; - } - $this->selectFont($path, 'WinAnsiEncoding'); + $this->selectFont("", $style); } function Info($params, $cols, $headers, $aligns, @@ -236,7 +227,7 @@ class FrontReport extends Cpdf $this->Font(); } $str = _("Page") . ' ' . $this->pageNumber; - $this->Text($this->endLine - 35, $str); + $this->Text($this->endLine - 38, $str); $this->Line($this->row - 5, 1); $this->row -= ($this->lineHeight + 6); @@ -281,8 +272,6 @@ class FrontReport extends Cpdf function AddImage($logo, $x, $y, $w, $h) { - if ($this->rtl) - $x = $this->pageWidth - $x - $w; if (strpos($logo, ".png") || strpos($logo, ".PNG")) $this->addPngFromFile($logo, $x, $y, $w, $h); else @@ -291,12 +280,12 @@ class FrontReport extends Cpdf function SetDrawColor($r, $g, $b) { - $this->setStrokeColor($r / 255, $g / 255, $b / 255); + $this->setStrokeColor($r, $g, $b); } function SetTextColor($r, $g, $b) { - $this->setColor($r / 255, $g / 255, $b / 255); + TCPDF::SetTextColor($r, $g, $b); } function Text($c, $txt, $n=0, $corr=0, $r=0) @@ -309,14 +298,10 @@ class FrontReport extends Cpdf function TextWrap($xpos, $ypos, $len, $str, $align = 'left') { - if ($this->rtl) + if ($this->fontSize != $this->oldFontSize) { - $str = strrev($str); - $xpos = $this->pageWidth - $xpos - $len; - if ($align == 'left') - $align = 'right'; - elseif ($align == 'right') - $align = 'left'; + $this->SetFontSize($this->fontSize); + $this->oldFontSize = $this->fontSize; } return $this->addTextWrap($xpos, $ypos, $len, $this->fontSize, $str, $align); } @@ -331,7 +316,13 @@ class FrontReport extends Cpdf return $this->TextWrap($this->cols2[$c], $this->row - $r, $this->cols2[$n] - $this->cols2[$c] + $corr, $txt, $this->aligns2[$c]); } - function TextColLines($c, $n, $txt, $corr=0) + function TextColLines($c, $n, $txt, $corr=0, $r=0) + { + $this->row -= $r; + $this->TextWrapLines($this->cols[$c], $this->cols[$n] - $this->cols[$c] + $corr, $txt, $this->aligns[$c]); + } + + function TextWrapLines($c, $width, $txt, $align='left') { $str = Explode("\n", $txt); for ($i = 0; $i < count($str); $i++) @@ -339,7 +330,7 @@ class FrontReport extends Cpdf $l = $str[$i]; do { - $l = $this->TextCol($c, $n, $l, $corr); + $l = $this->TextWrap($c, $this->row , $width, $l, $align); $this->NewLine(); } while ($l != ''); @@ -366,17 +357,11 @@ class FrontReport extends Cpdf function End($email=0, $subject=null, $myrow=null, $doctype = 0) { - global $go_debug, $path_to_root, $comp_path; + global $pdf_debug, $path_to_root, $comp_path; - // this is no good in IE so has been replaced, see down under - // but good for debugging purposes in IE - //session_write_close(); - - if ($go_debug == 1) + if ($pdf_debug == 1) { - $buf = $this->output(1); - $len = strlen($buf); - $pdfcode = $buf; + $pdfcode = $this->Output(); $pdfcode = str_replace("\n", "\n
", htmlspecialchars($pdfcode)); echo ''; echo trim($pdfcode); @@ -391,7 +376,8 @@ class FrontReport extends Cpdf } else { - $buf = $this->output(); + + $buf = $this->Output(); $len = strlen($buf); $dir = $comp_path.'/'.user_company(). '/pdf_files'; //save the file @@ -399,7 +385,12 @@ class FrontReport extends Cpdf { mkdir ($dir,0777); } - $fname = $dir . '/' . $this->filename; + // do not use standard filenames or your sensitive company data + // are world readable +// $fname = $dir . '/' . $this->filename; + $fname = tempnam($dir, 'xx'); + rename($fname, $fname.'.pdf'); + $fname .= '.pdf'; $fp = fopen($fname,'w'); fwrite($fp,$buf); fclose($fp); @@ -463,36 +454,70 @@ class FrontReport extends Cpdf } else { - //echo ' - // - // - // - // - // click here if you are not re-directed. - // - // '; - header('Content-type: application/pdf'); - header("Content-Disposition: inline; filename=$this->filename"); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Pragma: public'); - $this->stream(); - + $printer = get_report_printer(user_print_profile(), $_POST['REP_ID']); + if ($printer == false) { + if(in_Ajax()) { + global $Ajax; + // in case of ajax call non-ajax page reload is forced. + // the alternative is to differ browser support from + // call to remote printing by some attribute of print links, + // but in this case we should check related printer target + // for any link on the page, even if never used. + + // display in popup window ... +// $Ajax->popup($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']); + // ... or fire browser download popup + // $Ajax->redirect($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']); +// strip document root from file path + $fname = substr(realpath($fname), strlen($_SERVER['DOCUMENT_ROOT'])); + if (substr($fname,0,1) != '/') $fname = '/'.$fname; + + if (user_rep_popup()) + $Ajax->popup($fname); + else + $Ajax->redirect($fname); + } else { + //echo ' + // + // + // + // + // click here if you are not re-directed. + // + // '; + header('Content-type: application/pdf'); + header("Content-Disposition: inline; filename=$this->filename"); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + $this->Stream(); + } + } else { // send report to network printer + $prn = new remote_printer($printer['queue'],$printer['host'], + $printer['port'], $printer['timeout']); + $error = $prn->print_file($fname); + if ($error) + display_error($error); + else + display_notification(_('Report has been sent to network printer ').$printer['name']); + } } - // also have a look through the directory, and remove the files that are older than a week - // rather want to save 'em - /*if ($d = @opendir($dir)) { + // first have a look through the directory, + // and remove old temporary pdfs + if ($d = @opendir($dir)) { while (($file = readdir($d)) !== false) { - // then check to see if this one is too old + if (!is_file($dir.'/'.$file) || $file == 'index.php') continue; + // then check to see if this one is too old $ftime = filemtime($dir.'/'.$file); - if (time()-$ftime > 3600*24*7){ + // seems 3 min is enough for any report download, isn't it? + if (time()-$ftime > 180){ unlink($dir.'/'.$file); } } closedir($d); - }*/ + } } } }