Improved report module performance, usable also in non-js browsers.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 23 Oct 2008 17:23:08 +0000 (17:23 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 23 Oct 2008 17:23:08 +0000 (17:23 +0000)
reporting/includes/class.pdf.inc
reporting/includes/header2.inc
reporting/includes/pdf_report.inc
reporting/includes/reports_classes.inc
reporting/reports_main.php

index 7c182017526dc8cd406e95c39f3946f55e719ed5..fe6011e1b450f3ed57cb2aad7caa95ce83d8d8d3 100644 (file)
@@ -202,16 +202,12 @@ class Cpdf extends TCPDF {
        {
                TCPDF::Ellipse($x0, $y0, $r1, $r2, $angle, $astart. $afinish, ($close?'C':''), "", "", $nSeg);
        }
+
        function Stream()
        {
                TCPDF::Output('', 'I');
        }
 
-       function Output()
-       {
-               return TCPDF::Output('','S');
-       }
-
        function calcTextWrap($txt, $width, $spacebreak=false)
        {
                $ret = "";
index 07c73f9677db6c49c496e9dfc1d5a540ab76279e..341788040cbf1e052ea78f6d12e89f7573452328 100644 (file)
                // 2008-06-16. Added customer's reference
                $this->NewLine();
                $this->Text($ccol, $doc_Customers_Ref, $ccol2);
-               if ($sales_order != NULL)
+               if (isset($sales_order["customer_ref"]))
                        $this->Text($ccol2, $sales_order["customer_ref"], $mcol);
                $locale = $path_to_root . "lang/" . $_SESSION['language']->code . "/locale.inc";
                if (file_exists($locale))
index b3fffbe49e66a79bab907ceca3473446623347df..115fa929d24ab9a34469ed9bffab0707fba42b7d 100644 (file)
@@ -361,7 +361,7 @@ class FrontReport extends Cpdf
 
                if ($pdf_debug == 1)
                {
-                       $pdfcode = $this->Output();
+                       $pdfcode = $this->Output('','S');
                        $pdfcode = str_replace("\n", "\n<br>", htmlspecialchars($pdfcode));
                        echo '<html><body>';
                        echo trim($pdfcode);
@@ -377,8 +377,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))
@@ -388,9 +386,7 @@ class FrontReport extends Cpdf
                        // do not use standard filenames or your sensitive company data 
                        // are world readable
                        $fname = $dir.'/'.uniqid('').'.pdf';
-                       $fp = fopen($fname,'w');
-                       fwrite($fp,$buf);
-                       fclose($fp);
+                       $this->Output($fname, 'F');
                        if ($email == 1)
                        {
                                $emailtype = true;
index e244b8ff89c0cbaa9e1e230571668212167b6092..fd08842fa0a54ce361367cc89f606f2ceb62f38f 100644 (file)
@@ -20,7 +20,7 @@ class BoxReports
 
        function getDisplay($class=null)
        {
-               global $table_style2, $comp_path, $path_to_root;
+               global $table_style2, $comp_path, $path_to_root, $pdf_debug, $Ajax;
 
                $temp = array_values($this->ar_classes);
                $display_class = $class==null ? $temp[0] : $this->ar_classes[$class];
@@ -31,44 +31,50 @@ class BoxReports
                $st_classes = "<b>" . _("Report Classes:") . "</b><br>";
                foreach($this->ar_classes as $key=>$value)
                {
-                       $style = $class_counter==0 ? '' : $style = "style='display:none'";
+                       $style = $class_counter==$_REQUEST['Class'] ? '' : "style='display:none'";
                        $acc = access_string($key);
-                       $st_classes .= "<a href='javascript:showClass($class_counter)'$acc[1]>$acc[0]</a> <br>";
-                       $st_reports .= "<table id='TAB_" . $class_counter++ ."' $style cellpadding=0 cellspacing=0 border=0 width='100%'><tr><td><b>" . _("Reports For Class: ") . "&nbsp;$key</b></td></tr>";
+                       $st_classes .= "<a href='"
+                               .$_SERVER['PHP_SELF']."?Class=$class_counter"
+                               ."' onclick='return showClass($class_counter);'$acc[1]>$acc[0]</a> <br>";
+                       $st_reports .= "<table id='TAB_" . $class_counter ."' $style cellpadding=0 cellspacing=0 border=0 width='100%'><tr><td><b>" . _("Reports For Class: ") . "&nbsp;$key</b></td></tr>\n";
                        foreach($value as $report)
-                       {       $acc = access_string($report->name);
-                               $st_reports .= "<tr><td><a href='javascript:showReport($rep_counter)'$acc[1]>$acc[0]</a></td></tr>";
-
-                               $action = $path_to_root.'/reporting/prn_redirect.php';
-
-                               $st_params .= "<div id='REP_" . $rep_counter++ . "' style='display:none'>";
-                               $st_params .= "<table border=0><tr><td>\n"
-                                                               . "<form method='POST' action='$action' target='_blank'>\n" 
-                                                               . $report->getDisplay() 
-                                                               . "\n</form>\n"
-                                                               . "</td></tr></table></div>";
+                       {
+                               $acc = access_string($report->name);
+                               $st_reports .= "<tr><td><a class='printlink' href='"
+                                       .$_SERVER['PHP_SELF']."?Class=$class_counter&rep_id=$report->id"
+                                       ."'$acc[1]>$acc[0]</a><tr><td>\n";
+                               if (isset($_REQUEST['rep_id']) && $_REQUEST['rep_id']==$report->id) {
 
+                                       $action = $path_to_root.'/reporting/prn_redirect.php';
+       
+                                       $st_params = "<table border=0><tr><td>\n"
+                                               . "<form method='POST' action='$action' target='_blank'>\n";
+                                       $st_params .= hidden('REP_ID', $report->id, false);
+                                       $st_params .= submit('Rep'.$report->id,  
+                                               _("Display: ") . access_string($report->name,true),
+                                               false, '', $pdf_debug==0) . '<br><br>';
+                                       $st_params .= $report->getDisplay() 
+                                               . "\n</form></td></tr></table>\n";
+                                       $Ajax->addUpdate(true, 'rep_form', $st_params);
+                               }
                        }
                        $st_reports .= "</table>";
+                       $class_counter++;
                }
 
+               $st_params = "<div id='rep_form'>".
+                       "$st_params</div>";
+               
+
                $st =   "<script language='javascript'>
                                        function showClass(pClass) {
                                                for(i=0; i<$class_counter; i++) {
-                                                       eval('document.getElementById(\"TAB_\" + i).style.display=\"none\"')
-                                               }
-                                               eval('document.getElementById(\"TAB_\" + pClass).style.display=\"block\"')
-                                               for (i=0; i<$rep_counter; i++) {
-                                                       eval('document.getElementById(\"REP_\" + i).style.display=\"none\"')
-                                               }
-                                       }
-                                       function showReport(pId) {
-//                                             JsHttpRequest.request('Rep'+pId);
-                                               var tab;
-                                               for(i=0; i<$rep_counter; i++) {
-                                                       eval('document.getElementById(\"REP_\" + i).style.display=\"none\"')
+                                                       document.getElementById(\"TAB_\" + i).style.display=
+                                                       i==pClass ? \"block\" : \"none\";
                                                }
-                                               eval('document.getElementById(\"REP_\" + pId).style.display=\"block\"')
+                                               document.getElementById('rep_form').innerHTML = '';
+//                                             document.getElementById('rep_form').style.display = 'none';
+                                               return false;
                                        }
                                        function checkDate(pObj) {
                                                var re = /^(3[01]|0[1-9]|[12]\d)\/(0[1-9]|1[012])\/\d{4}/;
@@ -105,10 +111,7 @@ class Report
        {
                global $path_to_root, $use_date_picker, $pdf_debug;
 
-               $st  = hidden('REP_ID', $this->id, false);
-               $st .= submit('Rep'.$this->id,  
-                       _("Display: ") . access_string($this->name,true),
-                       false, '', $pdf_debug==0) . '<br><br>';
+               $st = '';
                $dummy = "";
                if ($this->ar_params==null)
                        return "";
index 24431c2348066bc41df07329b787c6f0672c24be..42b1ad5901f95f7ddd25af126ae9fbcd6dfcb3cb 100644 (file)
@@ -11,7 +11,7 @@ include_once($path_to_root . "/reporting/includes/reports_classes.inc");
 $js = "";
 if ($use_date_picker)
        $js .= get_js_date_picker();
-page(_("Reports and Analysis"), false, false, "", $js, true);
+page(_("Reports and Analysis"), false, false, "", $js);
 
 $reports = new BoxReports;