Merged changes from main trunk up to 2.2.3
[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 function find_report_file($rep) {
21         global $installed_extensions, $comp_path, $path_to_root;
22
23         // customized per company versions 
24         $path = $comp_path.'/'.user_company()."/reporting";
25         $rep_file = $path."/rep$rep.php";
26         if (file_exists($rep_file)) {
27                 // add local include path for custom reports
28                 set_include_path($path.PATH_SEPARATOR.get_include_path());
29                 return $rep_file;
30         }
31         // reports added by active extension modules
32         if (count($installed_extensions) > 0)
33         {
34                 $extensions = $installed_extensions;
35                 foreach ($extensions as $ext)
36                         if (($ext['active'] && $ext['type'] == 'module')) {
37                                 $path = $path_to_root.'/'.$ext['path']."/reporting";
38                                 $rep_file = $path."/rep$rep.php";
39                                 if (file_exists($rep_file)) {
40                                         set_include_path($path.PATH_SEPARATOR.get_include_path());
41                                         return $rep_file;
42                                 }
43                         }
44         }
45         // standard reports
46         $rep_file = $path_to_root ."/reporting/rep$rep.php";
47         if (file_exists($rep_file))
48                 return $rep_file;
49
50         return null;
51 }
52
53 if (isset($_GET['xls']))
54 {
55         $filename = $_GET['filename'];
56         $unique_name = $_GET['unique'];
57         $path =  $comp_path.'/'.user_company(). '/pdf_files/';
58         header("Content-type: application/vnd.ms-excel");
59         header("Content-Disposition: attachment; filename=$filename" );
60         header("Expires: 0");
61         header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
62         header("Pragma: public");
63         echo file_get_contents($path.$unique_name);
64         exit();
65 }
66 elseif (isset($_GET['xml']))
67 {
68         $filename = $_GET['filename'];
69         $unique_name = $_GET['unique'];
70         $path =  $comp_path.'/'.user_company(). '/pdf_files/';
71         header("content-type: text/xml");
72         header("Content-Disposition: attachment; filename=$filename");
73         header("Expires: 0");
74         header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
75         header("Pragma: public");
76         echo file_get_contents($path.$unique_name);
77         exit();
78 }
79         
80 if (!isset($_POST['REP_ID'])) { // print link clicked
81         $def_pars = array(0, 0, '', '', 0, '', '', 0); //default values
82         $rep = $_POST['REP_ID'] = $_GET['REP_ID'];
83         for($i=0; $i<8; $i++) {
84                 $_POST['PARAM_'.$i] = isset($_GET['PARAM_'.$i]) 
85                         ? $_GET['PARAM_'.$i] : $def_pars[$i];
86         }
87 }
88 $rep = $_POST['REP_ID'];
89
90 $rep_file = find_report_file($rep);
91 require($rep_file);
92 exit();
93
94 ?>