Additional conflict fixes after merge.
[fa-stable.git] / admin / printers.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU Affero General Public License,
5         AGPL, as published by the Free Software Foundation, either version 
6         3 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/agpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 15;
13 $path_to_root="..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_("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         $sql= "SELECT COUNT(*) FROM ".TB_PREF."print_profiles WHERE printer = '$selected_id'";
63         $result = db_query($sql,"check printers relations failed");
64         $myrow = db_fetch_row($result);
65         if ($myrow[0] > 0) 
66         {
67                 display_error(_("Cannot delete this printer definition, because print profile have been created using it."));
68         } 
69         else 
70         {
71                         $sql="DELETE FROM ".TB_PREF."printers WHERE id='$selected_id'";
72                         db_query($sql,"could not delete printer definition");
73                         display_notification(_('Selected printer definition has been deleted'));
74         }
75         $Mode = 'RESET';
76 }
77
78 if ($Mode == 'RESET')
79 {
80         $selected_id = -1;
81         unset($_POST);
82 }
83 //-------------------------------------------------------------------------------------------------
84
85 $result = get_all_printers();
86 start_form();
87 start_table($table_style);
88 $th = array(_("Name"), _("Description"), _("Host"), _("Printer Queue"),'','');
89 table_header($th);
90
91 $k = 0; //row colour counter
92 while ($myrow = db_fetch($result)) 
93 {
94         alt_table_row_color($k);
95
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"));
102     end_row();
103
104
105 } //END WHILE LIST LOOP
106
107 end_table();
108 end_form();
109 echo '<br>';
110
111 //-------------------------------------------------------------------------------------------------
112
113 start_form();
114
115 start_table($table_style2);
116
117 if ($selected_id != -1) 
118 {
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'];
127         }
128         hidden('selected_id', $selected_id);
129 } else {
130         if(!isset($_POST['host']))
131                 $_POST['host'] = 'localhost';
132         if(!isset($_POST['port']))
133                 $_POST['port'] = '515';
134 }
135
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);
142
143 end_table(1);
144
145 submit_add_or_update_center($selected_id == -1, '', true);
146
147 end_form();
148
149 end_page();
150
151 ?>