5 include($path_to_root . "/includes/session.inc");
7 page(_("Inventory Locations"));
9 include_once($path_to_root . "/includes/ui.inc");
11 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
13 simple_page_mode(true);
15 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
18 //initialise no input errors assumed initially before we test
21 /* actions to take once the user has clicked the submit button
22 ie the page has called itself with some user input */
24 //first off validate inputs sensible
25 $_POST['loc_code'] = strtoupper($_POST['loc_code']);
27 if (strlen($_POST['loc_code']) > 5)
30 display_error( _("The location code must be five characters or less long."));
31 set_focus('loc_code');
33 elseif (strlen($_POST['location_name']) == 0)
36 display_error( _("The location name must be entered."));
37 set_focus('location_name');
40 if ($input_error != 1)
42 if ($selected_id != -1)
45 update_item_location($selected_id, $_POST['location_name'], $_POST['delivery_address'],
46 $_POST['phone'], $_POST['fax'], $_POST['email'], $_POST['contact']);
47 display_notification(_('Selected location has been updated'));
52 /*selected_id is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new Location form */
54 add_item_location($_POST['loc_code'], $_POST['location_name'], $_POST['delivery_address'],
55 $_POST['phone'], $_POST['fax'], $_POST['email'], $_POST['contact']);
56 display_notification(_('New location has been added'));
63 function can_delete($selected_id)
65 $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_moves WHERE loc_code='$selected_id'";
66 $result = db_query($sql, "could not query stock moves");
67 $myrow = db_fetch_row($result);
70 display_error(_("Cannot delete this location because item movements have been created using this location."));
74 $sql= "SELECT COUNT(*) FROM ".TB_PREF."workorders WHERE loc_code='$selected_id'";
75 $result = db_query($sql, "could not query work orders");
76 $myrow = db_fetch_row($result);
79 display_error(_("Cannot delete this location because it is used by some work orders records."));
83 $sql= "SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE default_location='$selected_id'";
84 $result = db_query($sql, "could not query customer branches");
85 $myrow = db_fetch_row($result);
88 display_error(_("Cannot delete this location because it is used by some branch records as the default location to deliver from."));
95 //----------------------------------------------------------------------------------
97 if ($Mode == 'Delete')
100 if (can_delete($selected_id))
102 delete_item_location($selected_id);
103 display_notification(_('Selected location has been deleted'));
105 } //end if Delete Location
108 if ($Mode == 'RESET')
114 $sql = "SELECT * FROM ".TB_PREF."locations";
115 $result = db_query($sql, "could not query locations");;
118 start_table("$table_style width=30%");
119 $th = array(_("Location Code"), _("Location Name"), "", "");
121 $k = 0; //row colour counter
122 while ($myrow = db_fetch_row($result))
125 alt_table_row_color($k);
127 label_cell($myrow[0]);
128 label_cell($myrow[1]);
129 edit_button_cell("Edit".$myrow[0], _("Edit"));
130 edit_button_cell("Delete".$myrow[0], _("Delete"));
133 //END WHILE LIST LOOP
135 //end of ifs and buts!
144 start_table($table_style2);
146 if ($selected_id != -1)
148 //editing an existing Location
150 if ($Mode == 'Edit') {
151 $myrow = get_item_location($selected_id);
153 $_POST['loc_code'] = $myrow["loc_code"];
154 $_POST['location_name'] = $myrow["location_name"];
155 $_POST['delivery_address'] = $myrow["delivery_address"];
156 $_POST['contact'] = $myrow["contact"];
157 $_POST['phone'] = $myrow["phone"];
158 $_POST['fax'] = $myrow["fax"];
159 $_POST['email'] = $myrow["email"];
161 hidden("selected_id", $selected_id);
163 label_row(_("Location Code:"), $_POST['loc_code']);
166 { //end of if $selected_id only do the else when a new record is being entered
167 text_row(_("Location Code:"), 'loc_code', null, 5, 5);
170 text_row_ex(_("Location Name:"), 'location_name', 50, 50);
171 text_row_ex(_("Contact for deliveries:"), 'contact', 30, 30);
173 textarea_row(_("Address:"), 'delivery_address', null, 35, 5);
175 text_row_ex(_("Telephone No:"), 'phone', 30, 30);
176 text_row_ex(_("Facsimile No:"), 'fax', 30, 30);
177 text_row_ex(_("Email:"), 'email', 30, 30);
180 submit_add_or_update_center($selected_id == -1, '', true);