Feature 5388: Print Invoices (documents) list gets too long. Fixed by default 180...
[fa-stable.git] / admin / printers.php
1 <?php
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';
13 $path_to_root="..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_($help_context = "Printer Locations"));
17
18 include($path_to_root . "/admin/db/printers_db.inc");
19 include($path_to_root . "/includes/ui.inc");
20
21 simple_page_mode(true);
22 //-------------------------------------------------------------------------------------------
23 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
24 {
25
26         $error = 0;
27
28         if (empty($_POST['name']))
29         {
30                 $error = 1;
31                 display_error( _("Printer name cannot be empty."));
32                 set_focus('name');
33         } 
34         elseif (empty($_POST['host'])) 
35         {
36                 display_notification_centered( _("You have selected printing to server at user IP."));
37         } 
38         elseif (!check_num('tout', 0, 60)) 
39         {
40                 $error = 1;
41                 display_error( _("Timeout cannot be less than zero nor longer than 60 (sec)."));
42                 set_focus('tout');
43         } 
44
45         if ($error != 1)
46         {
47                 write_printer_def($selected_id, get_post('name'), get_post('descr'),
48                         get_post('queue'), get_post('host'), input_num('port',0),
49                         input_num('tout',0));
50
51                 display_notification_centered($selected_id==-1? 
52                         _('New printer definition has been created') 
53                         :_('Selected printer definition has been updated'));
54                 $Mode = 'RESET';
55         }
56 }
57
58 if ($Mode == 'Delete')
59 {
60         // PREVENT DELETES IF DEPENDENT RECORDS IN print_profiles
61
62         if (key_in_foreign_table($selected_id, 'print_profiles', 'printer'))
63         {
64                 display_error(_("Cannot delete this printer definition, because print profile have been created using it."));
65         } 
66         else 
67         {
68                 delete_printer($selected_id);
69                 display_notification(_('Selected printer definition has been deleted'));
70         }
71         $Mode = 'RESET';
72 }
73
74 if ($Mode == 'RESET')
75 {
76         $selected_id = -1;
77         unset($_POST);
78 }
79 //-------------------------------------------------------------------------------------------------
80
81 $result = get_all_printers();
82 start_form();
83 start_table(TABLESTYLE);
84 $th = array(_("Name"), _("Description"), _("Host"), _("Printer Queue"),'','');
85 table_header($th);
86
87 $k = 0; //row colour counter
88 while ($myrow = db_fetch($result)) 
89 {
90         alt_table_row_color($k);
91
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"));
98     end_row();
99
100
101 } //END WHILE LIST LOOP
102
103 end_table();
104 end_form();
105 echo '<br>';
106
107 //-------------------------------------------------------------------------------------------------
108
109 start_form();
110
111 start_table(TABLESTYLE2);
112
113 if ($selected_id != -1) 
114 {
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'];
123         }
124         hidden('selected_id', $selected_id);
125 } else {
126         if(!isset($_POST['host']))
127                 $_POST['host'] = 'localhost';
128         if(!isset($_POST['port']))
129                 $_POST['port'] = '515';
130 }
131
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);
138
139 end_table(1);
140
141 submit_add_or_update_center($selected_id == -1, '', 'both');
142
143 end_form();
144
145 end_page();
146