Changed db_escape function to avoid XSS attacks via js db injection
[fa-stable.git] / inventory / includes / db / items_locations_db.inc
1 <?php
2
3 function add_item_location($loc_code, $location_name, $delivery_address, $phone, $fax, $email, $contact)
4 {
5         $sql = "INSERT INTO ".TB_PREF."locations (loc_code, location_name, delivery_address, phone, fax, email, contact)
6                 VALUES (".db_quote($loc_code).", ".db_quote($location_name).", ".db_quote($delivery_address).", ".db_quote($phone).", ".db_quote($fax).", ".db_quote($email).", ".db_quote($contact).")";
7
8         db_query($sql,"a location could not be added");
9
10         /* Also need to add loc_stock records for all existing items */
11         $sql = "INSERT INTO ".TB_PREF."loc_stock (loc_code, stock_id, reorder_level)
12                 SELECT '$loc_code', ".TB_PREF."stock_master.stock_id, 0 FROM ".TB_PREF."stock_master";
13
14         db_query($sql,"a location could not be added");
15 }
16
17 //------------------------------------------------------------------------------------
18
19 function update_item_location($loc_code, $location_name, $delivery_address, $phone, $fax, $email, $contact)
20
21 {
22     $sql = "UPDATE ".TB_PREF."locations SET location_name=".db_quote($location_name).",
23         delivery_address=".db_quote($delivery_address).",
24         phone=".db_quote($phone).", fax=".db_quote($fax).",
25         email=".db_quote($email).", contact=".db_quote($contact)."
26         WHERE loc_code = '$loc_code'";
27
28         db_query($sql,"a location could not be updated");
29 }
30
31 //------------------------------------------------------------------------------------
32
33 function delete_item_location($item_location)
34 {
35         $sql="DELETE FROM ".TB_PREF."locations WHERE loc_code='$item_location'";
36         db_query($sql,"a location could not be deleted");
37
38         $sql = "DELETE FROM ".TB_PREF."loc_stock WHERE loc_code ='$item_location'";
39         db_query($sql,"a location could not be deleted");
40 }
41
42 //------------------------------------------------------------------------------------
43
44 function get_item_location($item_location)
45 {
46         $sql="SELECT * FROM ".TB_PREF."locations WHERE loc_code='$item_location'";
47
48         $result = db_query($sql,"a location could not be retrieved");
49
50         return db_fetch($result);
51 }
52
53 //------------------------------------------------------------------------------------
54
55 function set_reorder_level($stock_id, $loc_code, $reorder_level)
56 {
57         $sql = "UPDATE ".TB_PREF."loc_stock SET reorder_level = $reorder_level
58                 WHERE stock_id = '$stock_id' AND loc_code = '$loc_code'";
59
60         db_query($sql,"an item reorder could not be set");
61 }
62
63 //------------------------------------------------------------------------------------
64
65 function get_loc_details($stock_id)
66 {
67         $sql = "SELECT ".TB_PREF."loc_stock.*, ".TB_PREF."locations.location_name
68                 FROM ".TB_PREF."loc_stock, ".TB_PREF."locations
69                 WHERE ".TB_PREF."loc_stock.loc_code=".TB_PREF."locations.loc_code
70                 AND ".TB_PREF."loc_stock.stock_id = '" . $stock_id . "' ORDER BY ".TB_PREF."loc_stock.loc_code";
71         return db_query($sql,"an item reorder could not be retreived");
72 }
73
74 //------------------------------------------------------------------------------------
75
76 ?>