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 if (key_in_foreign_table($selected_id, 'print_profiles', 'printer'))
64 display_error(_("Cannot delete this printer definition, because print profile have been created using it."));
68 delete_printer($selected_id);
69 display_notification(_('Selected printer definition has been deleted'));
79 //-------------------------------------------------------------------------------------------------
81 $result = get_all_printers();
83 start_table(TABLESTYLE);
84 $th = array(_("Name"), _("Description"), _("Host"), _("Printer Queue"),'','');
87 $k = 0; //row colour counter
88 while ($myrow = db_fetch($result))
90 alt_table_row_color($k);
92 label_cell($myrow['name']);
93 label_cell($myrow['description']);
94 label_cell($myrow['host']);
95 label_cell($myrow['queue']);
96 edit_button_cell("Edit".$myrow['id'], _("Edit"));
97 delete_button_cell("Delete".$myrow['id'], _("Delete"));
101 } //END WHILE LIST LOOP
107 //-------------------------------------------------------------------------------------------------
111 start_table(TABLESTYLE2);
113 if ($selected_id != -1)
115 if ($Mode == 'Edit') {
116 $myrow = get_printer($selected_id);
117 $_POST['name'] = $myrow['name'];
118 $_POST['descr'] = $myrow['description'];
119 $_POST['queue'] = $myrow['queue'];
120 $_POST['tout'] = $myrow['timeout'];
121 $_POST['host'] = $myrow['host'];
122 $_POST['port'] = $myrow['port'];
124 hidden('selected_id', $selected_id);
126 if(!isset($_POST['host']))
127 $_POST['host'] = 'localhost';
128 if(!isset($_POST['port']))
129 $_POST['port'] = '515';
132 text_row(_("Printer Name").':', 'name', null, 20, 20);
133 text_row(_("Printer Description").':', 'descr', null, 40, 60);
134 text_row(_("Host name or IP").':', 'host', null, 30, 40);
135 text_row(_("Port").':', 'port', null, 5, 5);
136 text_row(_("Printer Queue").':', 'queue', null, 20, 20);
137 text_row(_("Timeout").':', 'tout', null, 5, 5);
141 submit_add_or_update_center($selected_id == -1, '', 'both');