2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_PRINTERS';
14 include($path_to_root . "/includes/session.inc");
16 page(_($help_context = "Printer Locations"));
18 include($path_to_root . "/admin/db/printers_db.inc");
19 include($path_to_root . "/includes/ui.inc");
21 simple_page_mode(true);
22 //-------------------------------------------------------------------------------------------
23 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
28 if (empty($_POST['name']))
31 display_error( _("Printer name cannot be empty."));
34 elseif (empty($_POST['host']))
36 display_notification_centered( _("You have selected printing to server at user IP."));
38 elseif (!check_num('tout', 0, 60))
41 display_error( _("Timeout cannot be less than zero nor longer than 60 (sec)."));
47 write_printer_def($selected_id, get_post('name'), get_post('descr'),
48 get_post('queue'), get_post('host'), input_num('port',0),
51 display_notification_centered($selected_id==-1?
52 _('New printer definition has been created')
53 :_('Selected printer definition has been updated'));
58 if ($Mode == 'Delete')
60 // PREVENT DELETES IF DEPENDENT RECORDS IN print_profiles
62 $sql= "SELECT COUNT(*) FROM ".TB_PREF."print_profiles WHERE printer = ".db_escape($selected_id);
63 $result = db_query($sql,"check printers relations failed");
64 $myrow = db_fetch_row($result);
67 display_error(_("Cannot delete this printer definition, because print profile have been created using it."));
71 $sql="DELETE FROM ".TB_PREF."printers WHERE id=".db_escape($selected_id);
72 db_query($sql,"could not delete printer definition");
73 display_notification(_('Selected printer definition has been deleted'));
83 //-------------------------------------------------------------------------------------------------
85 $result = get_all_printers();
87 start_table($table_style);
88 $th = array(_("Name"), _("Description"), _("Host"), _("Printer Queue"),'','');
91 $k = 0; //row colour counter
92 while ($myrow = db_fetch($result))
94 alt_table_row_color($k);
96 label_cell($myrow['name']);
97 label_cell($myrow['description']);
98 label_cell($myrow['host']);
99 label_cell($myrow['queue']);
100 edit_button_cell("Edit".$myrow['id'], _("Edit"));
101 delete_button_cell("Delete".$myrow['id'], _("Delete"));
105 } //END WHILE LIST LOOP
111 //-------------------------------------------------------------------------------------------------
115 start_table($table_style2);
117 if ($selected_id != -1)
119 if ($Mode == 'Edit') {
120 $myrow = get_printer($selected_id);
121 $_POST['name'] = $myrow['name'];
122 $_POST['descr'] = $myrow['description'];
123 $_POST['queue'] = $myrow['queue'];
124 $_POST['tout'] = $myrow['timeout'];
125 $_POST['host'] = $myrow['host'];
126 $_POST['port'] = $myrow['port'];
128 hidden('selected_id', $selected_id);
130 if(!isset($_POST['host']))
131 $_POST['host'] = 'localhost';
132 if(!isset($_POST['port']))
133 $_POST['port'] = '515';
136 text_row(_("Printer Name").':', 'name', null, 20, 20);
137 text_row(_("Printer Description").':', 'descr', null, 40, 60);
138 text_row(_("Host name or IP").':', 'host', null, 30, 40);
139 text_row(_("Port").':', 'port', null, 5, 5);
140 text_row(_("Printer Queue").':', 'queue', null, 20, 20);
141 text_row(_("Timeout").':', 'tout', null, 5, 5);
145 submit_add_or_update_center($selected_id == -1, '', 'both');