From: Janusz Dobrowolski Date: Wed, 15 Oct 2008 13:36:23 +0000 (+0000) Subject: Added remote printing support. X-Git-Tag: v2.4.2~19^2~1847 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=37da0ea920fdff712ccef4e1324aa822e981c8fc;p=fa-stable.git Added remote printing support. --- diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 533191a4..fef45358 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,47 @@ Legend: ! -> 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 diff --git a/admin/db/printers_db.inc b/admin/db/printers_db.inc new file mode 100644 index 00000000..043268a6 --- /dev/null +++ b/admin/db/printers_db.inc @@ -0,0 +1,93 @@ +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 diff --git a/admin/db/users_db.inc b/admin/db/users_db.inc index 6e1be6fe..7b82e609 100644 --- a/admin/db/users_db.inc +++ b/admin/db/users_db.inc @@ -1,11 +1,13 @@ _('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 '
'; +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 == '' ? '???1)' : _($descr)); + $_POST['Prn'.$rep] = isset($prints[$rep]) ? $prints[$rep] : ''; + echo ''; + printers_list('Prn'.$rep, null, + $rep == '' ? _('Browser support') : _('Default')); + echo ''; + if ($descr == '') $unkn = 1; + end_row(); +} +end_table(); +if ($unkn) + display_note('1) - '._("no title was found in this report definition file."), 0, 1, ''); +else + echo '
'; + +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(); + +?> diff --git a/admin/printers.php b/admin/printers.php new file mode 100644 index 00000000..89d64476 --- /dev/null +++ b/admin/printers.php @@ -0,0 +1,142 @@ + 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 '
'; + +//------------------------------------------------------------------------------------------------- + +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(); + +?> diff --git a/admin/users.php b/admin/users.php index bd3b0eb3..f7ed2075 100644 --- a/admin/users.php +++ b/admin/users.php @@ -54,7 +54,8 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 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'])); @@ -64,7 +65,8 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 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.")); } @@ -147,6 +149,7 @@ if ($selected_id != '') $_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'); @@ -179,6 +182,9 @@ security_headings_list_row(_("Access Level:"), 'Access', null); 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); diff --git a/applications/setup.php b/applications/setup.php index a4085a58..b1e4dbf0 100644 --- a/applications/setup.php +++ b/applications/setup.php @@ -19,10 +19,12 @@ $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?"); diff --git a/config.php b/config.php index 625b5421..40ce1193 100644 --- a/config.php +++ b/config.php @@ -24,6 +24,7 @@ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_ $debug = 1; $show_sql = 0; $go_debug = 1; + $pdf_debug = 0; if ($go_debug == 1) { error_reporting(E_ALL); diff --git a/includes/current_user.inc b/includes/current_user.inc index 7a9f1763..e2dd4f37 100644 --- a/includes/current_user.inc +++ b/includes/current_user.inc @@ -96,9 +96,9 @@ class current_user } 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); @@ -247,12 +247,19 @@ function user_hints() 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() { diff --git a/includes/prefs/userprefs.inc b/includes/prefs/userprefs.inc index 1bd5b022..6dd37663 100644 --- a/includes/prefs/userprefs.inc +++ b/includes/prefs/userprefs.inc @@ -18,6 +18,7 @@ class user_prefs var $tho_sep; var $dec_sep; var $theme; + var $print_profile; var $pagesize; // for printing var $show_hints; @@ -41,6 +42,7 @@ class user_prefs $this->theme = $user["theme"]; $this->pagesize = $user["page_size"]; $this->show_hints = $user["show_hints"]; + $this->print_profile = $user["print_profile"]; } function language() @@ -125,6 +127,11 @@ class user_prefs 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; diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc index 0ce2546a..b0b8d689 100644 --- a/includes/ui/ui_lists.inc +++ b/includes/ui/ui_lists.inc @@ -133,16 +133,13 @@ $opts = array( // default options $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; } @@ -1747,4 +1744,49 @@ function number_list_row($label, $name, $selected, $from, $to, $no_option=false) echo "\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 ""; + if ($label != null) + echo "$label\n"; + echo ""; + + array_selector($name, $selected_id, $profiles, + array( 'select_submit'=> $submit_on_change, + 'spec_option'=>$spec_opt, + 'spec_id' => '' + )); + + echo "\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 diff --git a/js/inserts.js b/js/inserts.js index 11a72f40..a3c0b2a2 100644 --- a/js/inserts.js +++ b/js/inserts.js @@ -257,6 +257,13 @@ var inserts = { }; } }, + '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; xUnknown ajax function: '+cmd; } diff --git a/reporting/includes/pdf_report.inc b/reporting/includes/pdf_report.inc index f09ab57f..b9ae9410 100644 --- a/reporting/includes/pdf_report.inc +++ b/reporting/includes/pdf_report.inc @@ -3,7 +3,9 @@ $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 { @@ -355,9 +357,9 @@ 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); @@ -376,6 +378,7 @@ class FrontReport extends Cpdf } else { + $buf = $this->Output(); $len = strlen($buf); $dir = $comp_path.'/'.user_company(). '/pdf_files'; @@ -384,7 +387,12 @@ class FrontReport extends Cpdf { 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); @@ -448,36 +456,67 @@ class FrontReport extends Cpdf } else { - //echo ' - // - // - // - // - // click here if you are not re-directed. - // - // '; - 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 ' + // + // + // + // + // click here if you are not re-directed. + // + // '; + 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); - }*/ + } } } } diff --git a/reporting/includes/printer_class.inc b/reporting/includes/printer_class.inc new file mode 100644 index 00000000..1b5a14e3 --- /dev/null +++ b/reporting/includes/printer_class.inc @@ -0,0 +1,114 @@ +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'); + // .':
' . $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; + } + +} + +?> diff --git a/reporting/includes/reporting.inc b/reporting/includes/reporting.inc index 75b8d76f..c79aee7e 100644 --- a/reporting/includes/reporting.inc +++ b/reporting/includes/reporting.inc @@ -1,96 +1,85 @@ 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 = "
"; - foreach ($ar as $key => $value) - { - $st .= ""; - } - $st .= "
\n"; - $st .= "\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 "$link_text"; - 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 "$link_text"; } function get_first_bank_account() diff --git a/reporting/includes/reports_classes.inc b/reporting/includes/reports_classes.inc index e180ed3b..8f501fe0 100644 --- a/reporting/includes/reports_classes.inc +++ b/reporting/includes/reports_classes.inc @@ -20,7 +20,8 @@ class BoxReports 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; @@ -37,8 +38,16 @@ class BoxReports foreach($value as $report) { $acc = access_string($report->name); $st_reports .= "$acc[0]"; - $st_params .= ""; - $st_params .= ""; + + $action = $path_to_root.'/reporting/prn_redirect.php'; + + $st_params .= ""; + } $st_reports .= ""; } @@ -54,12 +63,19 @@ class BoxReports } } 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") . "') + } + } "; $st .= ""; @@ -84,39 +100,15 @@ class Report $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 = " - - "; - $st .= "

"; + $st = hidden('REP_ID', $this->id, false); + $st .= submit('Rep'.$this->id, + _("Display: ") . access_string($this->name,true), + false, '', true) . '

'; $dummy = ""; if ($this->ar_params==null) return ""; @@ -127,7 +119,7 @@ class Report { 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': @@ -159,8 +151,8 @@ class Report $date = begin_month($bdate); } } - $name = "RP_" . $this->id . "_$index"; - //$st .= ""; + $name = "PARAM_$index"; + $st .= ""; if ($use_date_picker) $st .= "" @@ -169,81 +161,81 @@ class Report 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 .= ""; + $st .= ""; break; case 'TEXTBOX': - $st .= ""; + $st .= ""; 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"); @@ -251,7 +243,7 @@ class Report $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"); @@ -261,51 +253,51 @@ class Report 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; } diff --git a/reporting/prn_redirect.php b/reporting/prn_redirect.php new file mode 100644 index 00000000..262f8109 --- /dev/null +++ b/reporting/prn_redirect.php @@ -0,0 +1,27 @@ + \ No newline at end of file diff --git a/reporting/rep109.php b/reporting/rep109.php index e9be5d76..0360afdc 100644 --- a/reporting/rep109.php +++ b/reporting/rep109.php @@ -54,10 +54,10 @@ function print_sales_orders() 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); diff --git a/reporting/reports_main.php b/reporting/reports_main.php index 7f8ecde6..24431c23 100644 --- a/reporting/reports_main.php +++ b/reporting/reports_main.php @@ -274,19 +274,7 @@ $reports->addReport(_('General Ledger'),709,_('Ta&x Report'), new ReportParam(_('Summary Only'),'YES_NO'), new ReportParam(_('Comments'),'TEXTBOX'))); -echo " -
- - - - - - - - - - - "; echo $reports->getDisplay(); -echo ""; end_page(); ?> \ No newline at end of file diff --git a/sql/alter2.1.sql b/sql/alter2.1.sql new file mode 100644 index 00000000..8ae7a66c --- /dev/null +++ b/sql/alter2.1.sql @@ -0,0 +1,40 @@ + +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');