Bad handling of graphic links in certain browsers
[fa-stable.git] / reporting / includes / pdf_report.inc
index b9ae9410a22d56d2d8e52f243a3553ae1d55e9a4..c849f98fea60c9253257280a9d499d659cf1bbe6 100644 (file)
@@ -1,12 +1,22 @@
 <?php
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU Affero General Public License,
+       AGPL, as published by the Free Software Foundation, either version 
+       3 of the License, or (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+    See the License here <http://www.gnu.org/licenses/agpl-3.0.html>.
+***********************************************************************/
 /* $Revision$ */
 $page_security = 8;
 //include_once($path_to_root . "reporting/includes/class.pdf.inc");
 include_once(dirname(__FILE__)."/class.pdf.inc");
 include_once(dirname(__FILE__)."/printer_class.inc");
-include_once($path_to_root . "admin/db/company_db.inc");
-include_once($path_to_root . "admin/db/printers_db.inc");
-include_once($path_to_root . "config.php");
+include_once($path_to_root . "/admin/db/company_db.inc");
+include_once($path_to_root . "/admin/db/printers_db.inc");
+include_once($path_to_root . "/config.php");
 class FrontReport extends Cpdf
 {
        var $size;
@@ -140,7 +150,7 @@ class FrontReport extends Cpdf
        function Info($params, $cols, $headers, $aligns,
                $cols2 = null, $headers2 = null, $aligns2 = null)
        {
-               global $app_title, $version, $power_by, $power_url, $path_to_root,      $db_connections;
+               global $app_title, $version, $power_by, $power_url;
 
                $this->addinfo('Title', $this->title);
                $this->addinfo('Subject', $this->title);
@@ -154,7 +164,6 @@ class FrontReport extends Cpdf
                $this->fiscal_year = sql2date($year['begin']) . " - " . sql2date($year['end']) . "  " . "(" . $how . ")";
                $this->company = get_company_prefs();
                $this->user = $_SESSION["wa_current_user"]->name;
-               //$this->host = $db_connections[$_SESSION["wa_current_user"]->company]["host"];
                $this->host = $_SERVER['SERVER_NAME'];
                $this->params = $params;
                $this->cols = $cols;
@@ -258,14 +267,14 @@ class FrontReport extends Cpdf
                $header2type = true;
                if ($this->currency != $myrow['curr_code'])
                {
-                       include($path_to_root . "reporting/includes/doctext2.inc");
+                       include($path_to_root . "/reporting/includes/doctext2.inc");
                }
                else
                {
-                       include($path_to_root . "reporting/includes/doctext.inc");
+                       include($path_to_root . "/reporting/includes/doctext.inc");
                }
 
-               include($path_to_root . "reporting/includes/header2.inc");
+               include($path_to_root . "/reporting/includes/header2.inc");
 
                $this->row = $temp;
        }
@@ -351,7 +360,7 @@ class FrontReport extends Cpdf
        function NewLine($l=1, $np=0)
        {
                $this->row -= ($l * $this->lineHeight);
-               if ($np > 0 &&  $this->row < $this->bottomMargin + ($np * $this->lineHeight))
+               if ($this->row < $this->bottomMargin + ($np * $this->lineHeight))
                        $this->Header();
        }
 
@@ -361,9 +370,7 @@ class FrontReport extends Cpdf
 
                if ($pdf_debug == 1)
                {
-                       $buf = $this->Output();
-                       $len = strlen($buf);
-                       $pdfcode = $buf;
+                       $pdfcode = $this->Output('','S');
                        $pdfcode = str_replace("\n", "\n<br>", htmlspecialchars($pdfcode));
                        echo '<html><body>';
                        echo trim($pdfcode);
@@ -379,8 +386,6 @@ class FrontReport extends Cpdf
                else
                {
 
-                       $buf = $this->Output();
-                       $len = strlen($buf);
                        $dir =  $comp_path.'/'.user_company(). '/pdf_files';
                        //save the file
                        if (!file_exists($dir))
@@ -389,13 +394,8 @@ class FrontReport extends Cpdf
                        }
                        // 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);
+                       $fname = $dir.'/'.uniqid('').'.pdf';
+                       $this->Output($fname, 'F');
                        if ($email == 1)
                        {
                                $emailtype = true;
@@ -458,23 +458,13 @@ class FrontReport extends Cpdf
                        {
                                $printer = get_report_printer(user_print_profile(), $_POST['REP_ID']);
                                if ($printer == false) {
-                                       if(in_Ajax()) {
+                                       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;
-
-                                               $Ajax->redirect($fname);
+
+                                               if (user_rep_popup()) 
+                                                       $Ajax->popup($fname); // when embeded pdf viewer used
+                                               else
+                                                       $Ajax->redirect($fname); // otherwise use faster method
                                        } else {
                                        //echo '<html>
                                        //              <head>