Moved all SQL statements from PHP files into relevant *_db.inc files.
[fa-stable.git] / admin / shipping_companies.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_SHIPPING';
13 $path_to_root="..";
14 include($path_to_root . "/includes/session.inc");
15 page(_($help_context = "Shipping Company"));
16 include($path_to_root . "/includes/ui.inc");
17 include($path_to_root . "/admin/db/shipping_db.inc");
18
19 simple_page_mode(true);
20 //----------------------------------------------------------------------------------------------
21
22 function can_process() 
23 {
24         if (strlen($_POST['shipper_name']) == 0) 
25         {
26                 display_error(_("The shipping company name cannot be empty."));
27                 set_focus('shipper_name');
28                 return false;
29         }
30         return true;
31 }
32
33 //----------------------------------------------------------------------------------------------
34 if ($Mode=='ADD_ITEM' && can_process()) 
35 {
36         add_shipper($_POST['shipper_name'], $_POST['contact'], $_POST['phone'], $_POST['phone2'], $_POST['address']);
37         display_notification(_('New shipping company has been added'));
38         $Mode = 'RESET';
39 }
40
41 //----------------------------------------------------------------------------------------------
42
43 if ($Mode=='UPDATE_ITEM' && can_process()) 
44 {
45         update_shipper($selected_id, $_POST['shipper_name'], $_POST['contact'], $_POST['phone'], $_POST['phone2'], $_POST['address']);
46         display_notification(_('Selected shipping company has been updated'));
47         $Mode = 'RESET';
48 }
49
50 //----------------------------------------------------------------------------------------------
51
52 if ($Mode == 'Delete')
53 {
54 // PREVENT DELETES IF DEPENDENT RECORDS IN 'sales_orders'
55
56         if (sales_orders_has_shipper($selected_id))
57         {
58                 $cancel_delete = 1;
59                 display_error(_("Cannot delete this shipping company because sales orders have been created using this shipper."));
60         } 
61         else 
62         {
63                 // PREVENT DELETES IF DEPENDENT RECORDS IN 'debtor_trans'
64
65                 if (debtor_trans_has_shipper($selected_id))
66                 {
67                         $cancel_delete = 1;
68                         display_error(_("Cannot delete this shipping company because invoices have been created using this shipping company."));
69                 } 
70                 else 
71                 {
72                         delete_shipper($selected_id);
73                         display_notification(_('Selected shipping company has been deleted'));
74                 }
75         }
76         $Mode = 'RESET';
77 }
78
79 if ($Mode == 'RESET')
80 {
81         $selected_id = -1;
82         $sav = get_post('show_inactive');
83         unset($_POST);
84         $_POST['show_inactive'] = $sav;
85 }
86 //----------------------------------------------------------------------------------------------
87
88 $result = get_shippers(check_value('show_inactive'));
89
90 start_form();
91 start_table($table_style);
92 $th = array(_("Name"), _("Contact Person"), _("Phone Number"), _("Secondary Phone"), _("Address"), "", "");
93 inactive_control_column($th);
94 table_header($th);
95
96 $k = 0; //row colour counter
97
98 while ($myrow = db_fetch($result)) 
99 {
100         alt_table_row_color($k);
101         label_cell($myrow["shipper_name"]);
102         label_cell($myrow["contact"]);
103         label_cell($myrow["phone"]);
104         label_cell($myrow["phone2"]);
105         label_cell($myrow["address"]);
106         inactive_control_cell($myrow["shipper_id"], $myrow["inactive"], 'shippers', 'shipper_id');
107         edit_button_cell("Edit".$myrow["shipper_id"], _("Edit"));
108         delete_button_cell("Delete".$myrow["shipper_id"], _("Delete"));
109         end_row();
110 }
111
112 inactive_control_row($th);
113 end_table(1);
114
115 //----------------------------------------------------------------------------------------------
116
117 start_table($table_style2);
118
119 if ($selected_id != -1) 
120 {
121         if ($Mode == 'Edit') {
122                 //editing an existing Shipper
123
124                 $myrow = get_shipper($selected_id);
125
126                 $_POST['shipper_name']  = $myrow["shipper_name"];
127                 $_POST['contact']       = $myrow["contact"];
128                 $_POST['phone'] = $myrow["phone"];
129                 $_POST['phone2']        = $myrow["phone2"];
130                 $_POST['address'] = $myrow["address"];
131         }
132         hidden('selected_id', $selected_id);
133 }
134
135 text_row_ex(_("Name:"), 'shipper_name', 40);
136
137 text_row_ex(_("Contact Person:"), 'contact', 30);
138
139 text_row_ex(_("Phone Number:"), 'phone', 32, 30);
140
141 text_row_ex(_("Secondary Phone Number:"), 'phone2', 32, 30);
142
143 text_row_ex(_("Address:"), 'address', 50);
144
145 end_table(1);
146
147 submit_add_or_update_center($selected_id == -1, '', 'both');
148
149 end_form();
150 end_page();
151 ?>