- //echo '<html>
- // <head>
- // <SCRIPT LANGUAGE="JavaScript"><!--
- // function go_now () { window.location.href = "'.$fname.'"; }
- // //--></SCRIPT>
- // </head>
- // <body onLoad="go_now()"; >
- // <a href="'.$fname.'">click here</a> if you are not re-directed.
- // </body>
- // </html>';
- 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 '<html>
+ // <head>
+ // <SCRIPT LANGUAGE="JavaScript"><!--
+ // function go_now () { window.location.href = "'.$fname.'"; }
+ // //--></SCRIPT>
+ // </head>
+ // <body onLoad="go_now()"; >
+ // <a href="'.$fname.'">click here</a> if you are not re-directed.
+ // </body>
+ // </html>';
+ 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']);
+ }