! -> Note
$ -> Affected files
+15-Oct-2008 Janusz Dobrowolski
++ Added remote printing support
+$ /admin/print_profiles.php (new)
+ /admin/printers.php (new)
+ /admin/db/printers_db.inc (new)
+ /reporting/prn_redirect.php (new)
+ /reporting/includes/printer_class.inc (new)
+ /sql/alter2.1.sql (new)
+ /config.php
+ /admin/display_prefs.php
+ /admin/users.php
+ /admin/db/users_db.inc
+ /applications/setup.php
+ /includes/current_user.inc
+ /includes/prefs/userprefs.inc
+ /includes/ui/ui_lists.inc
+ /js/inserts.js
+ /js/utils.js
+ /reporting/rep109.php
+ /reporting/reports_main.php
+ /reporting/includes/pdf_report.inc
+ /reporting/includes/reporting.inc
+ /reporting/includes/reports_classes.inc
+!Fixes related to changed printing api.
+$ /admin/view_print_transaction.php
+ /purchasing/inquiry/po_search.php
+ /purchasing/inquiry/po_search_completed.php
+ /sales/customer_credit_invoice.php
+ /sales/customer_delivery.php
+ /sales/customer_invoice.php
+ /sales/sales_order_entry.php
+ /sales/inquiry/customer_inquiry.php
+ /sales/inquiry/sales_deliveries_view.php
+ /sales/inquiry/sales_orders_view.php
++ Added optional id parameter for label helpers; added value for buttons.
+$ /includes/ui/ui_input.inc
++ Added ajax popup screen command.
+$ /includes/ajax.inc
+# Skipping index.php file during flush_dir()
+$ /includes/main.inc
+
06-Oct-2008 Janusz Dobrowolski
+ Menu hotkeys system implementation.
$ /includes/page/header.inc
--- /dev/null
+<?php
+function write_printer_def($id, $name, $descr, $queue, $host, $port, $timeout)
+{
+ if ($id>0)
+ $sql = "UPDATE ".TB_PREF."printers SET description=".db_escape($descr)
+ .",name=".db_escape($name).",queue=".db_escape($queue)
+ .",host=".db_escape($host).",port='$port',timeout='$timeout' "
+ ."WHERE id=$id";
+ else
+ $sql = "INSERT INTO ".TB_PREF."printers ("
+ ."name,description,queue,host,port,timeout) "
+ ."VALUES (".db_escape($name).",".db_escape($descr).","
+ .db_escape($queue).",".db_escape($host).",'$port','$timeout')";
+
+ return db_query($sql,"could not write printer definition");
+}
+
+function get_all_printers()
+{
+ $sql = "SELECT * FROM ".TB_PREF."printers";
+ return db_query($sql,"could not get printer definitions");
+}
+
+function get_printer($id)
+{
+ $sql = "SELECT * FROM ".TB_PREF."printers
+ WHERE id=$id";
+
+ $result = db_query($sql,"could not get printer definition");
+ return db_fetch($result);
+}
+
+//============================================================================
+// printer profiles functions
+//
+function update_printer_profile($name, $dest)
+{
+ foreach( $dest as $rep => $printer) {
+ if ($printer != '' || $rep == '') {
+ $sql = "REPLACE INTO ".TB_PREF."print_profiles "
+ ."(profile, report, printer) VALUES ("
+ .db_escape($name).","
+ .db_escape($rep).","
+ .db_escape($printer).")";
+ } else {
+ $sql = "DELETE FROM ".TB_PREF."print_profiles WHERE ("
+ ."report=" . db_escape($rep)
+ ." AND profile=".db_escape($name).")";
+ }
+ $result = db_query($sql,"could not update printing profile");
+ if(!$result) {
+ return false;
+ }
+ }
+ return true;
+}
+//
+// Get destination for report defined in given printing profile.
+//
+function get_report_printer($profile, $report)
+{
+ $sql = "SELECT printer FROM ".TB_PREF."print_profiles WHERE "
+ ."profile=".db_escape($profile)." AND report=";
+
+ $result = db_query($sql.db_escape($report), 'report printer lookup failed');
+
+ if (!$result) return false;
+ $ret = db_fetch($result);
+ if ($ret === false) {
+ $result = db_query($sql."''", 'default report printer lookup failed');
+ if (!$result) return false;
+
+ $ret = db_fetch($result);
+ if (!$ret) return false;
+ }
+ return get_printer($ret['printer']);
+}
+
+function delete_printer_profile($name)
+{
+ $sql="DELETE FROM ".TB_PREF."print_profiles WHERE profile=".db_escape($name);
+ return db_query($sql,"could not delete printing profile");
+}
+//
+// Get all report destinations for given profile.
+//
+function get_print_profile($name)
+{
+ $sql = "SELECT * FROM ".TB_PREF."print_profiles WHERE profile=".db_escape($name);
+ return db_query($sql,"could not get printing profile");
+}
+
+?>
\ No newline at end of file
<?php
-function add_user($user_id, $real_name, $password, $phone, $email, $full_access, $language)
+function add_user($user_id, $real_name, $password, $phone, $email, $full_access,
+ $language, $profile)
{
- $sql = "INSERT INTO ".TB_PREF."users (user_id, real_name, password, phone, email, full_access, language)
+ $sql = "INSERT INTO ".TB_PREF."users (user_id, real_name, password, phone, email, full_access, language, print_profile)
VALUES (".db_escape($user_id).",
".db_escape($real_name).", ".db_escape($password) .",".db_escape($phone).",
- ".db_escape($email).", $full_access, ".db_escape($language).")";
+ ".db_escape($email).", $full_access, ".db_escape($language).",
+ ".db_escape($profile).")";
db_query($sql, "could not add user for $user_id");
}
//-----------------------------------------------------------------------------------------------
-function update_user($user_id, $real_name, $phone, $email, $full_access, $language)
+function update_user($user_id, $real_name, $phone, $email, $full_access,
+ $language, $profile)
{
$sql = "UPDATE ".TB_PREF."users SET real_name=".db_escape($real_name).
", phone=".db_escape($phone).",
email=".db_escape($email).",
full_access=$full_access,
- language=".db_escape($language)."
+ language=".db_escape($language).",
+ print_profile=".db_escape($profile)."
WHERE user_id = ".db_escape($user_id);
-
db_query($sql, "could not update user for $user_id");
}
//-----------------------------------------------------------------------------------------------
function update_user_display_prefs($user_id, $price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl,
- $showcodes, $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints)
+ $showcodes, $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints, $profile)
{
$sql = "UPDATE ".TB_PREF."users SET
prices_dec=".db_escape($price_dec).",
dec_sep=".db_escape($dec_sep).",
theme=".db_escape($theme).",
page_size=".db_escape($pagesize).",
- show_hints=$show_hints
+ show_hints=$show_hints,
+ print_profile=".db_escape($profile)."
WHERE user_id = ".db_escape($user_id);
db_query($sql, "could not update user display prefs for $user_id");
check_value('show_codes'),
$_POST['date_format'], $_POST['date_sep'],
$_POST['tho_sep'], $_POST['dec_sep'],
- $_POST['theme'], $_POST['page_size'], check_value('show_hints'));
+ $_POST['theme'], $_POST['page_size'], check_value('show_hints'),
+ $_POST['profile']);
language::set_language($_POST['language']);
/* The array $pagesizes is set up in config.php for modifications
possible separators can be added by modifying the array definition by editing that file */
+if (!isset($_POST['profile']))
+ $_POST['profile'] = user_print_profile();
+
+print_profiles_list_row(_("Printing profile"). ':', 'profile',
+ null, _('Browser printing support'));
+
table_section_title(_("Language"));
if (!isset($_POST['language']))
end_table(1);
-submit_center('setprefs', _("Update"));
+submit_center('setprefs', _("Update"), true, '', true);
end_form(2);
--- /dev/null
+<?php
+$page_security = 15;
+$path_to_root="..";
+include($path_to_root . "/includes/session.inc");
+include($path_to_root . "/admin/db/printers_db.inc");
+include($path_to_root . "/includes/ui.inc");
+
+page(_("Printing Profiles"));
+
+$selected_id = get_post('profile_id','');
+
+//-------------------------------------------------------------------------------------------------
+// Returns array of defined reports
+//
+function get_reports() {
+ global $path_to_root, $comp_path, $go_debug;
+
+if ($go_debug || !isset($_SESSION['reports'])) {
+ // to save time, store in session.
+ $paths = array (
+ $path_to_root.'/reporting/',
+ $comp_path .'/'. user_company() . '/reporting/');
+ $reports = array( '' => _('Default printing destination'));
+
+ foreach($paths as $dirno => $path) {
+ $repdir = opendir($path);
+ while(false !== ($fname = readdir($repdir)))
+ {
+ // reports have filenames in form rep(repid).php
+ // where repid must contain at least one digit (reports_main.php is not ;)
+ if (is_file($path.$fname)
+// && preg_match('/.*[^0-9]([0-9]+)[.]php/', $fname, $match))
+ && preg_match('/rep(.*[0-9]+.*)[.]php/', $fname, $match))
+ {
+ $repno = $match[1];
+ $title = '';
+
+ $line = file_get_contents($path.$fname);
+ if (preg_match('/.*(FrontReport\()\s*_\([\'"]([^\'"]*)/', $line, $match)) {
+ $title = trim($match[2]);
+ }
+ else // for any 3rd party printouts without FrontReport() class use
+ if (preg_match('/.*(\$Title).*[\'"](.*)[\'"].+/', $line, $match)) {
+ $title = trim($match[2]);
+ }
+ $reports[$repno] = $title;
+ }
+ }
+ closedir();
+ }
+ ksort($reports);
+ $_SESSION['reports'] = $reports;
+ }
+ return $_SESSION['reports'];
+}
+
+function clear_form()
+{
+ global $selected_id, $Ajax;
+
+ $selected_id = '';
+ $_POST['name'] = '';
+ $Ajax->activate('_page_body');
+}
+
+function check_delete($name)
+{
+// check if selected profile is used by any user
+ if ($name=='') return 0; // cannot delete system default profile
+ $sql = "SELECT * FROM ".TB_PREF."users WHERE print_profile='$name'";
+ $res = db_query($sql,'cannot check printing profile usage');
+ return db_num_rows($res);
+}
+//-------------------------------------------------------------------------------------------
+if ( get_post('submit'))
+{
+
+ $error = 0;
+
+ if ($_POST['profile_id'] == '' && empty($_POST['name']))
+ {
+ $error = 1;
+ display_error( _("Printing profile name cannot be empty."));
+ set_focus('name');
+ }
+
+ if (!$error)
+ {
+ $prof = array('' => get_post('Prn')); // store default value/profile name
+ foreach (get_reports() as $rep => $descr) {
+ $val = get_post('Prn'.$rep);
+ $prof[$rep] = $val;
+ }
+ if ($_POST['profile_id']=='')
+ $_POST['profile_id'] = get_post('name');
+
+ update_printer_profile($_POST['profile_id'], $prof);
+ if ($selected_id == '') {
+ display_notification_centered(_('New printing profile has been created'));
+ clear_form();
+ } else {
+ display_notification_centered(_('Printing profile has been updated'));
+ }
+ }
+}
+
+if(get_post('delete'))
+{
+ if (!check_delete(get_post('name'))) {
+ delete_printer_profile($selected_id);
+ display_notification(_('Selected printing profile has been deleted'));
+ clear_form();
+ }
+}
+
+if(get_post('_profile_id_update')) {
+ $Ajax->activate('_page_body');
+}
+
+start_form();
+start_table();
+print_profiles_list_row(_('Select printing profile'). ':', 'profile_id', null,
+ _('New printing profile'), true);
+end_table();
+echo '<hr>';
+start_table();
+if (get_post('profile_id') == '')
+ text_row(_("Printing Profile Name").':', 'name', null, 30, 30);
+else
+ label_cells(_("Printing Profile Name").':', get_post('profile_id'));
+end_table(1);
+
+$result = get_print_profile(get_post('profile_id'));
+$prints = array();
+while ($myrow = db_fetch($result)) {
+ $prints[$myrow['report']] = $myrow['printer'];
+}
+
+start_table($table_style);
+$th = array(_("Report Id"), _("Description"), _("Printer"));
+table_header($th);
+
+$k = 0;
+$unkn = 0;
+foreach(get_reports() as $rep => $descr)
+{
+ alt_table_row_color($k);
+
+ label_cell($rep=='' ? '-' : $rep, 'align=center');
+ label_cell($descr == '' ? '???<sup>1)</sup>' : _($descr));
+ $_POST['Prn'.$rep] = isset($prints[$rep]) ? $prints[$rep] : '';
+ echo '<td>';
+ printers_list('Prn'.$rep, null,
+ $rep == '' ? _('Browser support') : _('Default'));
+ echo '</td>';
+ if ($descr == '') $unkn = 1;
+ end_row();
+}
+end_table();
+if ($unkn)
+ display_note('<sup>1)</sup> - '._("no title was found in this report definition file."), 0, 1, '');
+else
+ echo '<br>';
+
+div_start('controls');
+if (get_post('profile_id') == '') {
+ submit_center('submit', _("Add New Profile"), true, '', true);
+} else {
+ submit_center_first('submit', _("Update Profile"),
+ _('Update printer profile'), true);
+ submit_center_last('delete', _("Delete Profile"),
+ _('Delete printer profile (only if not used by any user)'), true);
+}
+div_end();
+
+end_form();
+end_page();
+
+?>
--- /dev/null
+<?php
+
+$page_security = 15;
+$path_to_root="..";
+include($path_to_root . "/includes/session.inc");
+
+page(_("Printer Locations"));
+
+include($path_to_root . "/admin/db/printers_db.inc");
+include($path_to_root . "/includes/ui.inc");
+
+simple_page_mode(true);
+//-------------------------------------------------------------------------------------------
+if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
+{
+
+ $error = 0;
+
+ if (empty($_POST['name']))
+ {
+ $error = 1;
+ display_error( _("Printer name cannot be empty."));
+ set_focus('name');
+ }
+ elseif (empty($_POST['host']))
+ {
+ display_notification_centered( _("You have selected printing to server at user IP."));
+ }
+ elseif (!check_num('tout', 0, 60))
+ {
+ $error = 1;
+ display_error( _("Timeout cannot be less than zero nor longer than 60 (sec)."));
+ set_focus('tout');
+ }
+
+ if ($error != 1)
+ {
+ write_printer_def($selected_id, get_post('name'), get_post('descr'),
+ get_post('queue'), get_post('host'), input_num('port',0),
+ input_num('tout',0));
+
+ display_notification_centered($selected_id==-1?
+ _('New printer definition has been created')
+ :_('Selected printer definition has been updated'));
+ $Mode = 'RESET';
+ }
+}
+
+if ($Mode == 'Delete')
+{
+ // PREVENT DELETES IF DEPENDENT RECORDS IN print_profiles
+
+ $sql= "SELECT COUNT(*) FROM ".TB_PREF."print_profiles WHERE printer = '$selected_id'";
+ $result = db_query($sql,"check printers relations failed");
+ $myrow = db_fetch_row($result);
+ if ($myrow[0] > 0)
+ {
+ display_error(_("Cannot delete this printer definition, because print profile have been created using it."));
+ }
+ else
+ {
+ $sql="DELETE FROM ".TB_PREF."printers WHERE id='$selected_id'";
+ db_query($sql,"could not delete printer definition");
+ display_notification(_('Selected printer definition has been deleted'));
+ }
+ $Mode = 'RESET';
+}
+
+if ($Mode == 'RESET')
+{
+ $selected_id = -1;
+ unset($_POST);
+}
+//-------------------------------------------------------------------------------------------------
+
+$result = get_all_printers();
+start_form();
+start_table($table_style);
+$th = array(_("Name"), _("Description"), _("Host"), _("Printer Queue"),'','');
+table_header($th);
+
+$k = 0; //row colour counter
+while ($myrow = db_fetch($result))
+{
+ alt_table_row_color($k);
+
+ label_cell($myrow['name']);
+ label_cell($myrow['description']);
+ label_cell($myrow['host']);
+ label_cell($myrow['queue']);
+ edit_button_cell("Edit".$myrow['id'], _("Edit"));
+ edit_button_cell("Delete".$myrow['id'], _("Delete"));
+ end_row();
+
+
+} //END WHILE LIST LOOP
+
+end_table();
+end_form();
+echo '<br>';
+
+//-------------------------------------------------------------------------------------------------
+
+start_form();
+
+start_table($table_style2);
+
+if ($selected_id != -1)
+{
+ if ($Mode == 'Edit') {
+ $myrow = get_printer($selected_id);
+ $_POST['name'] = $myrow['name'];
+ $_POST['descr'] = $myrow['description'];
+ $_POST['queue'] = $myrow['queue'];
+ $_POST['tout'] = $myrow['timeout'];
+ $_POST['host'] = $myrow['host'];
+ $_POST['port'] = $myrow['port'];
+ }
+ hidden('selected_id', $selected_id);
+} else {
+ if(!isset($_POST['host']))
+ $_POST['host'] = 'localhost';
+ if(!isset($_POST['port']))
+ $_POST['port'] = '515';
+}
+
+text_row(_("Printer Name").':', 'name', null, 20, 20);
+text_row(_("Printer Description").':', 'descr', null, 40, 60);
+text_row(_("Host name or IP").':', 'host', null, 30, 40);
+text_row(_("Port").':', 'port', null, 5, 5);
+text_row(_("Printer Queue").':', 'queue', null, 20, 20);
+text_row(_("Timeout").':', 'tout', null, 5, 5);
+
+end_table(1);
+
+submit_add_or_update_center($selected_id == -1, '', true);
+
+end_form();
+
+end_page();
+
+?>
if ($selected_id != '')
{
update_user($_POST['user_id'], $_POST['real_name'], $_POST['phone'],
- $_POST['email'], $_POST['Access'], $_POST['language']);
+ $_POST['email'], $_POST['Access'], $_POST['language'],
+ $_POST['profile']);
if ($_POST['password'] != "")
update_user_password($_POST['user_id'], md5($_POST['password']));
else
{
add_user($_POST['user_id'], $_POST['real_name'], md5($_POST['password']),
- $_POST['phone'], $_POST['email'], $_POST['Access'], $_POST['language']);
+ $_POST['phone'], $_POST['email'], $_POST['Access'], $_POST['language'],
+ $_POST['profile']);
display_notification_centered(_("A new user has been added."));
}
$_POST['email'] = $myrow["email"];
$_POST['Access'] = $myrow["full_access"];
$_POST['language'] = $myrow["language"];
+ $_POST['profile'] = $myrow["print_profile"];
}
hidden('selected_id', $selected_id);
hidden('user_id');
languages_list_row(_("Language:"), 'language', null);
+print_profiles_list_row(_("Printing profile"). ':', 'profile', null,
+ _('Browser printing support'));
+
end_table(1);
submit_add_or_update_center($selected_id == '', '', true);
$this->add_rapp_function(0, "","");
$this->add_rapp_function(0, _("System and &General GL Setup"),"admin/gl_setup.php?");
$this->add_rapp_function(0, _("&Fiscal Years"),"admin/fiscalyears.php?");
+ $this->add_rapp_function(0, _("&Print Profiles"),"admin/print_profiles.php?");
$this->add_module(_("Miscellaneous"));
$this->add_lapp_function(1, _("Pa&yment Terms"),"admin/payment_terms.php?");
$this->add_lapp_function(1, _("Shi&pping Company"),"admin/shipping_companies.php?");
+ $this->add_rapp_function(1, _("&Printers"),"admin/printers.php?");
$this->add_module(_("Maintanance"));
$this->add_lapp_function(2, _("&Void a Transaction"),"admin/void_transaction.php?");
$debug = 1;
$show_sql = 0;
$go_debug = 1;
+ $pdf_debug = 0;
if ($go_debug == 1)
{
error_reporting(E_ALL);
}
function update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
- $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints) {
+ $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints, $profile) {
update_user_display_prefs($this->username, $price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl,
- $showcodes, $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints);
+ $showcodes, $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints, $profile);
// re-read the prefs
$user = get_user($this->username);
return $_SESSION["wa_current_user"]->prefs->show_hints();
}
+function user_print_profile()
+{
+ return $_SESSION["wa_current_user"]->prefs->print_profile();
+}
+
function set_user_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
- $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints)
+ $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints,
+ $print_profile)
{
$_SESSION["wa_current_user"]->update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
- $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints);
+ $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints,
+ $print_profile);
}
function add_user_js_data() {
var $tho_sep;
var $dec_sep;
var $theme;
+ var $print_profile;
var $pagesize; // for printing
var $show_hints;
$this->theme = $user["theme"];
$this->pagesize = $user["page_size"];
$this->show_hints = $user["show_hints"];
+ $this->print_profile = $user["print_profile"];
}
function language()
return $this->show_hints;
}
+ function print_profile()
+ {
+ return $this->print_profile;
+ }
+
function set_dec($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes)
{
$this->price_dec = $price_dec;
$selector = $first_opt = '';
$first_id = false;
$found = false;
-//if($name=='SelectStockFromList') display_error($sql);
+//if($name=='contact_sel') display_error($sql);
if($result = db_query($sql)) {
while ($contact_row = db_fetch($result)) {
$value = $contact_row[0];
$descr = $opts['format']==null ? $contact_row[1] :
call_user_func($opts['format'], $contact_row);
$sel = '';
- if (get_post($search_submit) && ($txt === $value)) {
- $selected_id = $value;
- }
if (get_post($search_submit) && ($txt === $value)) {
$selected_id = $value;
}
echo "</tr>\n";
}
+function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=false,
+ $submit_on_change=true)
+{
+ $sql = "SELECT profile FROM ".TB_PREF."print_profiles"
+ ." GROUP BY profile";
+ $result = db_query($sql, 'cannot get all profile names');
+ $profiles = array();
+ while($myrow=db_fetch($result)) {
+ $profiles[$myrow['profile']] = $myrow['profile'];
+ }
+
+ echo "<tr>";
+ if ($label != null)
+ echo "<td>$label</td>\n";
+ echo "<td>";
+
+ array_selector($name, $selected_id, $profiles,
+ array( 'select_submit'=> $submit_on_change,
+ 'spec_option'=>$spec_opt,
+ 'spec_id' => ''
+ ));
+
+ echo "</td></tr>\n";
+}
+
+function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
+{
+ static $printers; // query only once for page display
+
+ if (!$printers) {
+ $sql = "SELECT id, name, description FROM ".TB_PREF."printers";
+ $result = db_query($sql, 'cannot get all printers');
+ $printers = array();
+ while($myrow=db_fetch($result)) {
+ $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description'];
+ }
+ }
+ array_selector($name, $selected_id, $printers,
+ array( 'select_submit'=> $submit_on_change,
+ 'spec_option'=>$spec_opt,
+ 'spec_id' => ''
+ ));
+}
+
+
?>
\ No newline at end of file
};
}
},
+ 'a.printlink': function(l) {
+ l.onclick = function() {
+ save_focus(this);
+ JsHttpRequest.request(this);
+ return false;
+ }
+ },
'ul.ajaxtabs': function(ul) {
var ulist=ul.getElementsByTagName("li");
for (var x=0; x<ulist.length; x++){ //loop through each LI e
// request is directed to current location
//
JsHttpRequest.request= function(trigger, form) {
-
+ if (trigger.tagName=='A') {
+ var content = {};
+ var upload = 0;
+ var url = trigger.href;
+ } else {
var submitObj = typeof(trigger) == "string" ?
document.getElementsByName(trigger)[0] : trigger;
var content = this.formInputs(trigger, form, upload);
if (!form) url = url.substring(0, url.indexOf('?'));
-
+
if (!submitObj)
content[trigger] = 1;
- // this is to avoid caching problems
+
+ }
+ // this is to avoid caching problems
content['_random'] = Math.random()*1234567;
JsHttpRequest.query(
eval(data);
} else if(cmd=='rd') { // client-side redirection
window.location = data;
+ } else if(cmd=='pu') { // pop-up
+ window.open(data,'REP_WINDOW','toolbar=no,scrollbar=no,resizable=yes,menubar=no');
} else {
errors = errors+'<br>Unknown ajax function: '+cmd;
}
$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");
class FrontReport extends Cpdf
{
function End($email=0, $subject=null, $myrow=null, $doctype = 0)
{
- global $go_debug, $path_to_root, $comp_path;
+ global $pdf_debug, $path_to_root, $comp_path;
- if ($go_debug == 1)
+ if ($pdf_debug == 1)
{
$buf = $this->Output();
$len = strlen($buf);
}
else
{
+
$buf = $this->Output();
$len = strlen($buf);
$dir = $comp_path.'/'.user_company(). '/pdf_files';
{
mkdir ($dir,0777);
}
- $fname = $dir . '/' . $this->filename;
+ // 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);
}
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();
-
+ $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;
+
+ $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']);
+ }
}
- // also have a look through the directory, and remove the files that are older than a week
- // rather want to save 'em
- /*if ($d = @opendir($dir)) {
+ // first have a look through the directory,
+ // and remove old temporary pdfs
+ if ($d = @opendir($dir)) {
while (($file = readdir($d)) !== false) {
- // then check to see if this one is too old
+ if (!is_file($dir.'/'.$file) || $file == 'index.php') continue;
+ // then check to see if this one is too old
$ftime = filemtime($dir.'/'.$file);
- if (time()-$ftime > 3600*24*7){
+ // seems 3 min is enough for any report download, isn't it?
+ if (time()-$ftime > 180){
unlink($dir.'/'.$file);
}
}
closedir($d);
- }*/
+ }
}
}
}
--- /dev/null
+<?php
+/*
+ * remote_printer class.
+ * All needed filters should be set for the printer in printercap file.
+ * Based on PrintSendLPR class by Mick Sear, eCreate
+ */
+
+class remote_printer {
+
+ var $host;
+ var $port;
+ var $timeout;
+ var $queue;
+ //
+ // Setting connection parameters
+ //
+ function remote_printer($queue, $host='', $port=515, $timeout=20){
+ if ($host == '')
+ $host = $_SERVER['REMOTE_ADDR']; // default is user's host
+ $this->host = $host;
+ $this->port = $port;
+ $this->timeout = $timeout;
+ $this->queue = $queue;
+ }
+ //
+ // Send file to remote network printer.
+ //
+ function print_file($fname){
+
+ $queue = $this->queue;
+
+ //Private static function prints waiting jobs on the queue.
+ $ret = $this->flush_queue($queue);
+// if($ret) return $ret;
+
+ //Open a new connection to send the control file and data.
+ $stream = fsockopen("tcp://".$this->host, $this->port, $errNo, $errStr, $this->timeout);
+ if(!$stream){
+ return _('Cannot open connection to printer');
+ }
+ if (!isset($_SESSION['_print_job'])) {
+ $_SESSION['print_job'] = 0;
+ }
+ $job = $_SESSION['print_job']++;
+ //Set printer to receive file
+ fwrite($stream, chr(2).$queue."\n");
+ $ack = fread($stream, 1);
+ if ($ack != 0) {
+ fclose($stream);
+ return _('Printer does not acept the job').' ('.ord($ack).')';
+ }
+
+ // Send Control file.
+ $server = $_SERVER['SERVER_NAME'];
+ $ctrl = "H".$server."\nP". substr($_SESSION["wa_current_user"]->loginname,0,31)
+ ."\nfdfA".$job.$server."\n";
+ fwrite($stream, chr(2).strlen($ctrl)." cfA".$job.$server."\n");
+ $ack = fread($stream, 1);
+ if ($ack != 0) {
+ fclose($stream);
+ return _('Error sending print job control file').' ('.ord($ack).')';
+ }
+
+ fwrite($stream, $ctrl.chr(0)); //Write null to indicate end of stream
+ $ack = fread($stream, 1);
+ if ($ack != 0) {
+ fclose($stream);
+ return _('Print control file not accepted').' ('.ord($ack).')';
+ }
+
+ $data = fopen($fname, "rb");
+ fwrite($stream, chr(3).filesize($fname)." dfA".$job.$server."\n");
+ $ack = fread($stream, 1);
+ if ($ack != 0) {
+ fclose($stream);
+ return _('Cannot send report to printer').' ('.ord($ack).')';
+ }
+
+ while(!feof($data)){
+ if (fwrite($stream, fread($data, 8192))<8192) break;
+ }
+ fwrite($stream, chr(0)); //Write null to indicate end of stream
+ $ack = fread($stream, 1);
+ if ($ack != 0) {
+ fclose($stream);
+ return _('No ack after report printout').' ('.ord($ack).')';
+ }
+
+ fclose($data);
+ fclose($stream);
+
+ return '';
+ }
+ //
+ // Print all waiting jobs on remote printer queue.
+ //
+ function flush_queue($queue){
+ $stream = fsockopen("tcp://".$this->host, $this->port,$errNo, $errStr, $this->timeout);
+ if (!$stream){
+ return _('Cannot flush printing queue');
+ // .':<br>' . $errNo." (".$errStr.")"; return 0 (success) even on failure
+ } else {
+ //Print any waiting jobs
+ fwrite($stream, chr(1).$queue."\n");
+ while(!feof($stream)){
+ fread($stream, 1);
+ }
+ }
+ return false;
+ }
+
+}
+
+?>
<?php
+// Link to printing single document with bulk report template file.
+// Ex. label_cell(print_document_link($myrow['order_no'], _("Print")), $type);
+// or display_note(print_document_link($order_no, _("Print this order")));
+// You only need full parameter list for invoices/credit notes
-// Put this on the page only once an outside a form, e.g. print_hidden_script(systypes::sales_order());
-// If you have both invoices and credit notes on the same page use 10 or 11. Is doesn't matter which.
-
-function print_hidden_script($type_no)
+function print_document_link($doc_no, $link_text, $link=true, $type_no)
{
global $path_to_root;
include_once($path_to_root . "/includes/types.inc");
- $action = "";
+
+ $url = $path_to_root.'/reporting/prn_redirect.php?';
switch ($type_no)
{
case systypes::sales_order() :
- $action = "$path_to_root/reporting/rep109.php";
+ $rep = 109;
+ // from, to, currency, bank acc, email, quote, comments
$ar = array(
- 'PARAM_0' => 0, // from - these values are updated in print_document_link()
- 'PARAM_1' => 0, // to
- 'PARAM_2' => "", // currency
- 'PARAM_3' => get_first_bank_account(), // bank account
- 'PARAM_4' => 0, // email
- 'PARAM_5' => 0, // quote
- 'PARAM_6' => ""); // comments
+ 'PARAM_0' => $doc_no,
+ 'PARAM_1' => $doc_no,
+ 'PARAM_2' => "",
+ 'PARAM_3' => get_first_bank_account(),
+ 'PARAM_4' => 0,
+ 'PARAM_5' => 0,
+ 'PARAM_6' => "");
break;
case systypes::cust_dispatch() :
- $action = "$path_to_root/reporting/rep110.php";
+ $rep = 110;
+ // from, to, email, comments
$ar = array(
- 'PARAM_0' => 0, // from - these values are updated in print_document_link()
- 'PARAM_1' => 0, // to
- 'PARAM_2' => 0, // email
- 'PARAM_3' => ""); // comments
+ 'PARAM_0' => $doc_no,
+ 'PARAM_1' => $doc_no,
+ 'PARAM_2' => 0,
+ 'PARAM_3' => "");
break;
case 10 : // Sales Invoice
case 11 : // Customer Credit Note
- $action = "$path_to_root/reporting/rep107.php";
+ $rep = 107;
+ // from, to, currency, bank acc, email, paylink, comments, type
$ar = array(
- 'PARAM_0' => 0, // from - these values are updated in print_document_link()
- 'PARAM_1' => 0, // to
- 'PARAM_2' => "", // currency
- 'PARAM_3' => get_first_bank_account(), // bank account
- 'PARAM_4' => 0, // email
- 'PARAM_5' => "", // paylink
- 'PARAM_6' => "", // comments
- 'PARAM_7' => 0); // IV or CN
+ 'PARAM_0' => $doc_no,
+ 'PARAM_1' => $doc_no,
+ 'PARAM_2' => "",
+ 'PARAM_3' => get_first_bank_account(),
+ 'PARAM_4' => 0,
+ 'PARAM_5' => "",
+ 'PARAM_6' => "",
+ 'PARAM_7' => $type_no);
break;
case systypes::po() :
- $action = "$path_to_root/reporting/rep209.php";
+ $rep = 209;
+ // from, to, currency, bank acc, email, comments
$ar = array(
- 'PARAM_0' => 0, // from - these values are updated in print_document_link()
- 'PARAM_1' => 0, // to
- 'PARAM_2' => "", // currency
- 'PARAM_3' => get_first_bank_account(), // bank account
- 'PARAM_4' => 0, // email
- 'PARAM_5' => ""); // comments
+ 'PARAM_0' => $doc_no,
+ 'PARAM_1' => $doc_no,
+ 'PARAM_2' => "",
+ 'PARAM_3' => get_first_bank_account(),
+ 'PARAM_4' => 0,
+ 'PARAM_5' => "");
break;
+// default: $ar = array();
}
- $st = "<form method='post' name='pdf_form' action='$action'>";
- foreach ($ar as $key => $value)
- {
- $st .= "<input type='hidden' name='$key' value='$value' />";
- }
- $st .= "</form>\n";
- $st .= "<script type='text/javascript'>
-<!--
-function printDocument(docno, typeno) {
- document.pdf_form.PARAM_0.value = document.pdf_form.PARAM_1.value = docno;
- if (typeno == 10 || typeno == 11)
- document.pdf_form.PARAM_7.value = typeno;
- window.open('','REP_WINDOW','toolbar=no,scrollbar=no,resizable=yes,menubar=no');
- document.pdf_form.target='REP_WINDOW';
- document.pdf_form.submit();
-}
--->
-</script>\n";
-
- echo $st;
+
+ return print_link($link_text, $rep, $ar);
}
-
-// Ex. label_cell(print_document_link($myrow['order_no'], _("Print")));
-// or display_note(print_document_link($order_no, _("Print this order")));
-// or if a button
-// button("button", _("Print this order"), print_document_link($order_no, "", false))";
-// or if a button inside a TD
-// button_cell("button", _("Print this order"), print_document_link($order_no, "", false))";
//
-// You only need full parameter list for invoices/credit notes
-
-function print_document_link($doc_no, $link_text, $link=true, $type_no=0)
+// Universal link to any kind of report.
+//
+function print_link($link_text, $rep, $pars = array(), $dir = '')
{
- if ($link)
- return "<a href=\"javascript:printDocument('$doc_no', '$type_no');\">$link_text</a>";
- else
- return "javascript:printDocument('$doc_no', '$type_no');";
+ global $path_to_root;
+
+ $url = $dir == '' ? $path_to_root.'/reporting/prn_redirect.php?' : $dir;
+
+ foreach($pars as $par => $val) {
+ $pars[$par] = "$par=".urlencode($val);
+ }
+ $pars[] = 'REP_ID='.urlencode($rep);
+ $url .= implode ('&', $pars);
+
+ return "<a class='printlink' target='_blank' href='$url'>$link_text</a>";
}
function get_first_bank_account()
function getDisplay($class=null)
{
- global $table_style2;
+ global $table_style2, $comp_path, $path_to_root;
+
$temp = array_values($this->ar_classes);
$display_class = $class==null ? $temp[0] : $this->ar_classes[$class];
$class_counter = 0;
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>";
- $st_params .= "<table border=0 id='REP_" . $rep_counter++ . "' style='display:none'>";
- $st_params .= "<tr><td>" . $report->getDisplay() . "</td></tr></table>";
+
+ $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'>\n"
+ . $report->getDisplay()
+ . "\n</form>\n"
+ . "</td></tr></table></div>";
+
}
$st_reports .= "</table>";
}
}
}
function showReport(pId) {
+// JsHttpRequest.request('Rep'+pId);
var tab;
for(i=0; i<$rep_counter; i++) {
eval('document.getElementById(\"REP_\" + i).style.display=\"none\"')
}
eval('document.getElementById(\"REP_\" + pId).style.display=\"block\"')
}
+ function checkDate(pObj) {
+ var re = /^(3[01]|0[1-9]|[12]\d)\/(0[1-9]|1[012])\/\d{4}/;
+ if (re.test(pObj.value)==false) {
+ alert('" . _("Invalid date format") . "')
+ }
+ }
</script>
";
$st .= "<table align='center' width='80%' $table_style2><tr valign='top'>";
$this->name = $name;
$this->ar_params = $ar_params;
}
+
function getDisplay()
{
- global $comp_path, $path_to_root, $use_date_picker;
-
- $rep_file = $comp_path.'/'.user_company().
- "/reporting/rep".$this->id.".php";
- if (!file_exists($rep_file))
- $rep_file = $path_to_root ."/reporting/rep".$this->id.".php";
-
- $st = "
-<script language='javascript'>
- function displayReport_" . $this->id . "() {
- pParamCount = " . count($this->ar_params) . ";
- document.forms[0].REP_ID.value = " . $this->id . ";
- document.forms[0].PARAM_COUNT.value = pParamCount;
- for (i=0; i<pParamCount; i++) {
- eval('document.forms[0].PARAM_' + i + '.value=document.forms[0].RP_" . $this->id . "_' + i + '.value');
- }
+ global $path_to_root, $use_date_picker;
- window.open('','REP_WINDOW','toolbar=no,scrollbar=no,resizable=yes,menubar=no');
- document.forms[0].target='REP_WINDOW';
- document.forms[0].action= '$rep_file';
- document.forms[0].submit();
- }
- function checkDate(pObj) {
- var re = /^(3[01]|0[1-9]|[12]\d)\/(0[1-9]|1[012])\/\d{4}/;
- if (re.test(pObj.value)==false) {
- alert('" . _("Invalid date format") . "')
- }
- }
-</script>
- ";
- $st .= "<input type='button' onclick='javascript:displayReport_" . $this->id ."()' value='" . _("Display: ") . $this->name . "'><br><br>";
+ $st = hidden('REP_ID', $this->id, false);
+ $st .= submit('Rep'.$this->id,
+ _("Display: ") . access_string($this->name,true),
+ false, '', true) . '<br><br>';
$dummy = "";
if ($this->ar_params==null)
return "";
{
case 'CURRENCY':
$sql = "SELECT curr_abrev, concat(curr_abrev,' - ', currency) FROM ".TB_PREF."currencies";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Currency Filter"));
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Currency Filter"));
break;
case 'DATE':
case 'DATEBEGIN':
$date = begin_month($bdate);
}
}
- $name = "RP_" . $this->id . "_$index";
- //$st .= "<input type='text' name='$name' value='$date' onblur='javascript:checkDate(this)'>";
+ $name = "PARAM_$index";
+
$st .= "<input type='text' name='$name' value='$date'>";
if ($use_date_picker)
$st .= "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
break;
case 'YES_NO':
$sel = array(_('No'), _("Yes"));
- $st .= dup_simple_name_list("RP_" . $this->id . "_$index", $sel);
+ $st .= dup_simple_name_list("PARAM_$index", $sel);
break;
case 'PAYMENT_LINK':
$sel = array(_("No Payment Link"), "PayPal");
- $st .= dup_simple_name_list("RP_" . $this->id . "_$index", $sel);
+ $st .= dup_simple_name_list("PARAM_$index", $sel);
break;
case 'COMPARE':
$sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
- $st .= dup_simple_name_list("RP_" . $this->id . "_$index", $sel);
+ $st .= dup_simple_name_list("PARAM_$index", $sel);
break;
case 'GRAPHIC':
$sel = array(_("No Graphics"), _("Vertical bars"), _("Horizontal bars"), _("Dots"), _("Lines"), _("Pie"), _("Donut"));
- $st .= dup_simple_name_list("RP_" . $this->id . "_$index", $sel);
+ $st .= dup_simple_name_list("PARAM_$index", $sel);
break;
case 'SYS_TYPES':
- $st .= dup_systypes_list("RP_" . $this->id . "_$index", $dummy, true, _("No Type Filter"), true);
+ $st .= dup_systypes_list("PARAM_$index", $dummy, true, _("No Type Filter"), true);
break;
case 'TEXT':
- $st .= "<input type='text' name='RP_" . $this->id . "_$index'>";
+ $st .= "<input type='text' name='PARAM_$index'>";
break;
case 'TEXTBOX':
- $st .= "<textarea rows=4 cols=30 name='RP_" . $this->id . "_$index'></textarea>";
+ $st .= "<textarea rows=4 cols=30 name='PARAM_$index'></textarea>";
break;
case 'ACCOUNTS':
$sql = "SELECT id, name FROM ".TB_PREF."chart_types ORDER BY name";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Account Group Filter"), true);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Account Group Filter"), true);
break;
case 'GL_ACCOUNTS':
$sql = "SELECT account_code, concat(account_code, ' - ', account_name) as account_name FROM ".TB_PREF."chart_master ORDER BY account_code";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
break;
case 'BANK_ACCOUNTS':
$sql = "SELECT ".TB_PREF."bank_accounts.account_code, concat(bank_account_name, if (bank_curr_code=curr_default,'', concat(' - ', bank_curr_code))) FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master, ".TB_PREF."company
WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
break;
case 'DIMENSION':
$sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions ORDER BY reference";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
break;
case 'DIMENSIONS':
$sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions ORDER BY reference";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Dimension Filter"), true);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Dimension Filter"), true);
break;
case 'DIMENSION1':
$sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index". "_$index", $dummy);
break;
case 'DIMENSIONS1':
$sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Dimension Filter"), true);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Dimension Filter"), true);
break;
case 'DIMENSION2':
$sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
break;
case 'DIMENSIONS2':
$sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Dimension Filter"), true);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Dimension Filter"), true);
break;
case 'CUSTOMERS_NO_FILTER':
case 'CUSTOMERS':
$sql = "SELECT debtor_no, name FROM ".TB_PREF."debtors_master ORDER BY name";
if ($param->param_type == 'CUSTOMERS_NO_FILTER')
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Customer Filter"), true);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Customer Filter"), true);
else
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
break;
case 'SUPPLIERS_NO_FILTER':
case 'SUPPLIERS':
$sql = "SELECT supplier_id, supp_name FROM ".TB_PREF."suppliers ORDER BY supp_name";
if ($param->param_type == 'SUPPLIERS_NO_FILTER')
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Supplier Filter"), true);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Supplier Filter"), true);
else
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
break;
case 'INVOICE':
$IV = _("IV");
$sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, if (type=10, ' $IV ', ' $CN '), ".TB_PREF."debtors_master.name) as IName
FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE (type=10 OR type=11) AND ".TB_PREF."debtors_master.debtor_no=".TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
break;
case 'DELIVERY':
$DN = _("DN");
FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans
WHERE type=13 AND ".TB_PREF."debtors_master.debtor_no=".
TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
break;
case 'ORDERS':
$sql = "SELECT ".TB_PREF."sales_orders.order_no, concat(".TB_PREF."sales_orders.order_no, '-',
".TB_PREF."debtors_master.name) as IName
FROM ".TB_PREF."debtors_master, ".TB_PREF."sales_orders WHERE ".TB_PREF."debtors_master.debtor_no=".TB_PREF."sales_orders.debtor_no ORDER BY ".TB_PREF."sales_orders.order_no DESC";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
break;
case 'PO':
$sql = "SELECT ".TB_PREF."purch_orders.order_no, concat(".TB_PREF."purch_orders.order_no, '-',
".TB_PREF."suppliers.supp_name) as IName
FROM ".TB_PREF."suppliers, ".TB_PREF."purch_orders WHERE ".TB_PREF."suppliers.supplier_id=".TB_PREF."purch_orders.supplier_id ORDER BY ".TB_PREF."purch_orders.order_no DESC";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
break;
case 'ITEMS':
$sql = "SELECT stock_id, concat(stock_id, '-', description) as name FROM ".TB_PREF."stock_master WHERE (mb_flag='A' OR mb_flag='M') ORDER BY stock_id";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
break;
case 'LOCATIONS':
$sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations ORDER BY location_name";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Location Filter"), false);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Location Filter"), false);
break;
case 'CATEGORIES':
$sql = "SELECT category_id, description FROM ".TB_PREF."stock_category ORDER BY description";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Category Filter"), true);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Category Filter"), true);
break;
case 'SALESTYPES':
$sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types ORDER BY sales_type";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
break;
case 'AREAS':
$sql = "SELECT area_code, description FROM ".TB_PREF."areas ORDER BY description";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Area Filter"), true);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Area Filter"), true);
break;
case 'SALESMEN':
$sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman ORDER BY salesman_name";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Sales Folk Filter"), true);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Sales Folk Filter"), true);
break;
case 'TRANS_YEARS':
$sql = "SELECT DISTINCT YEAR(tran_date), YEAR(tran_date) FROM ".TB_PREF."gl_trans";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
break;
case 'ACCOUNTS_NO_FILTER':
$sql = "SELECT id, name FROM ".TB_PREF."chart_types ORDER BY name";
- $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
+ $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
break;
}
--- /dev/null
+<?php
+/*
+ Print request redirector. This file is fired via print link or
+ print button in reporting module.
+*/
+$path_to_root = "../";
+$page_security = 2; // this level is later overriden in rep file
+include_once($path_to_root . "includes/session.inc");
+
+if (!isset($_POST['REP_ID'])) { // print link clicked
+ $def_pars = array(0, 0, '', '', 0, '', '', 0); //default values
+ $rep = $_POST['REP_ID'] = $_GET['REP_ID'];
+ for($i=0; $i<8; $i++) {
+ $_POST['PARAM_'.$i] = isset($_GET['PARAM_'.$i])
+ ? $_GET['PARAM_'.$i] : $def_pars[$i];
+ }
+}
+ $rep = $_POST['REP_ID'];
+ $rep_file = $comp_path.'/'.user_company().
+ "/reporting/rep$rep.php";
+ if (!file_exists($rep_file)) {
+ $rep_file = $path_to_root ."/reporting/rep$rep.php";
+ }
+ require($rep_file);
+ exit();
+
+?>
\ No newline at end of file
if ($email == 0)
{
- if ($print_as_quote == 1)
- $rep = new FrontReport(_("QUOTE"), "QuoteBulk.pdf", user_pagesize());
- else
+ if ($print_as_quote == 0)
$rep = new FrontReport(_("SALES ORDER"), "SalesOrderBulk.pdf", user_pagesize());
+ else
+ $rep = new FrontReport(_("QUOTE"), "QuoteBulk.pdf", user_pagesize());
$rep->currency = $cur;
$rep->Font();
$rep->Info($params, $cols, null, $aligns);
new ReportParam(_('Summary Only'),'YES_NO'),
new ReportParam(_('Comments'),'TEXTBOX')));
-echo "
-<form method=post>
- <input type='hidden' name='REP_ID' value=''>
- <input type='hidden' name='PARAM_COUNT' value=''>
- <input type='hidden' name='PARAM_0' value=''>
- <input type='hidden' name='PARAM_1' value=''>
- <input type='hidden' name='PARAM_2' value=''>
- <input type='hidden' name='PARAM_3' value=''>
- <input type='hidden' name='PARAM_4' value=''>
- <input type='hidden' name='PARAM_5' value=''>
- <input type='hidden' name='PARAM_6' value=''>
-
- <script language='javascript'>
+echo "<script language='javascript'>
function onWindowLoad() {
showClass(" . $_GET['Class'] . ")
}
</script>
";
echo $reports->getDisplay();
-echo "</form>";
end_page();
?>
\ No newline at end of file
--- /dev/null
+
+ALTER TABLE `0_users` ADD `print_profile` VARCHAR(30) DEFAULT '' AFTER `show_hints` ;
+
+DROP TABLE IF EXISTS `0_print_profiles`;
+CREATE TABLE `0_print_profiles` (
+ `id` tinyint(11) NOT NULL auto_increment,
+ `profile` varchar(30) NOT NULL,
+ `report` varchar(5) NOT NULL,
+ `printer` tinyint(5) NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `profile` (`profile`,`report`)
+) ENGINE=MyISAM AUTO_INCREMENT=10;
+
+INSERT INTO `0_print_profiles` VALUES ('1', 'Out of office', '', '0');
+INSERT INTO `0_print_profiles` VALUES ('2', 'Sales Department', '', '0');
+INSERT INTO `0_print_profiles` VALUES ('3', 'Central', '', '2');
+INSERT INTO `0_print_profiles` VALUES ('4', 'Sales Department', '104', '2');
+INSERT INTO `0_print_profiles` VALUES ('5', 'Sales Department', '105', '2');
+INSERT INTO `0_print_profiles` VALUES ('6', 'Sales Department', '107', '2');
+INSERT INTO `0_print_profiles` VALUES ('7', 'Sales Department', '109', '2');
+INSERT INTO `0_print_profiles` VALUES ('8', 'Sales Department', '110', '2');
+INSERT INTO `0_print_profiles` VALUES ('9', 'Sales Department', '201', '2');
+
+DROP TABLE IF EXISTS `0_printers`;
+
+CREATE TABLE `0_printers` (
+ `id` smallint(6) NOT NULL auto_increment,
+ `name` varchar(20) NOT NULL,
+ `description` varchar(60) NOT NULL,
+ `queue` varchar(20) NOT NULL,
+ `host` varchar(40) NOT NULL,
+ `port` smallint(11) unsigned NOT NULL,
+ `timeout` tinyint(3) unsigned NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `name` (`name`)
+) ENGINE=MyISAM AUTO_INCREMENT=4;
+
+INSERT INTO `0_printers` VALUES ('1', 'QL500', 'Label printer', 'QL500', 'server', '127', '20');
+INSERT INTO `0_printers` VALUES ('2', 'Samsung', 'Main network printer', 'scx4521F', 'server', '515', '5');
+INSERT INTO `0_printers` VALUES ('3', 'Local', 'Local print server at user IP', 'lp', '', '515', '10');