Update from usntable branch.
[fa-stable.git] / reporting / prn_redirect.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 /*
13         Print request redirector. This file is fired via print link or 
14         print button in reporting module. 
15 */
16 $path_to_root = "..";
17 $page_security = 'SA_OPEN';     // this level is later overriden in rep file
18 include_once($path_to_root . "/includes/session.inc");
19
20 /*
21         Find report definition file.
22         Standard reports can be superseded by report with the same id
23         included in active extension, or company customized report.
24 */
25 function find_report_file($rep) {
26         global $installed_extensions, $comp_path, $path_to_root;
27
28         // customized per company versions 
29         $rep_file = $comp_path.'/'.user_company()."/reporting/rep$rep.php";
30         if (file_exists($rep_file)) 
31                 return $rep_file;
32         // reports added by active extension modules
33         if (count($installed_extensions) > 0)
34         {
35                 $extensions = $installed_extensions;
36                 foreach ($extensions as $ext)
37                         if (($ext['active'] && $ext['type'] == 'module')) {
38                                 $rep_file = $path_to_root.'/'.$ext['path']."/reporting/rep$rep.php";
39                                 if (file_exists($rep_file))
40                                         return $rep_file;
41                         }
42         }
43         // standard reports
44         $rep_file = $path_to_root ."/reporting/rep$rep.php";
45         if (file_exists($rep_file))
46                 return $rep_file;
47
48         return null;
49 }
50
51 if (isset($_GET['xls']))
52 {
53         $filename = $_GET['filename'];
54         $unique_name = $_GET['unique'];
55         $path =  $comp_path.'/'.user_company(). '/pdf_files/';
56         header("Content-type: application/vnd.ms-excel");
57         header("Content-Disposition: attachment; filename=$filename" );
58         header("Expires: 0");
59         header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
60         header("Pragma: public");
61         echo file_get_contents($path.$unique_name);
62         exit();
63 }
64 elseif (isset($_GET['xml']))
65 {
66         $filename = $_GET['filename'];
67         $unique_name = $_GET['unique'];
68         $path =  $comp_path.'/'.user_company(). '/pdf_files/';
69         header("content-type: text/xml");
70         header("Content-Disposition: attachment; filename=$filename");
71         header("Expires: 0");
72         header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
73         header("Pragma: public");
74         echo file_get_contents($path.$unique_name);
75         exit();
76 }
77         
78 if (!isset($_POST['REP_ID'])) { // print link clicked
79         $def_pars = array(0, 0, '', '', 0, '', '', 0); //default values
80         $rep = $_POST['REP_ID'] = $_GET['REP_ID'];
81         for($i=0; $i<8; $i++) {
82                 $_POST['PARAM_'.$i] = isset($_GET['PARAM_'.$i]) 
83                         ? $_GET['PARAM_'.$i] : $def_pars[$i];
84         }
85 }
86 $rep = $_POST['REP_ID'];
87
88 $rep_file = find_report_file($rep);
89 require($rep_file);
90 exit();
91
92 ?>