| 1 | <?php
|
| 2 |
|
| 3 | /*
|
| 4 |
|
| 5 | Copyright (C) 2010, All Rights Reserved.
|
| 6 |
|
| 7 | This file is part of RPInventory.
|
| 8 |
|
| 9 | RPInventory is free software: you can redistribute it and/or modify
|
| 10 | it under the terms of the GNU General Public License as published by
|
| 11 | the Free Software Foundation, either version 3 of the License, or
|
| 12 | (at your option) any later version.
|
| 13 |
|
| 14 | RPInventory is distributed in the hope that it will be useful,
|
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 | GNU General Public License for more details.
|
| 18 |
|
| 19 | You should have received a copy of the GNU General Public License
|
| 20 | along with RPInventory. If not, see <http://www.gnu.org/licenses/>.
|
| 21 |
|
| 22 | */
|
| 23 |
|
| 24 | require_once("lib/auth.lib.php"); //Session
|
| 25 | require_once('lib/inventory.lib.php');
|
| 26 | require_once('lib/loans.lib.php');
|
| 27 | require_once('lib/checkouts.lib.php');
|
| 28 | require_once('lib/locations.lib.php');
|
| 29 | require_once('class/database.class.php');
|
| 30 |
|
| 31 | // Connect
|
| 32 | $db = new database();
|
| 33 |
|
| 34 | //Authenticate
|
| 35 | $auth = GetAuthority();
|
| 36 | if($auth < 1)
|
| 37 | die("You dont have permission to access this page");
|
| 38 |
|
| 39 | //id
|
| 40 | $id = (int)$_GET["id"];
|
| 41 | if($id == 0)
|
| 42 | die("Invalid ID");
|
| 43 |
|
| 44 | //Verify no items use the location before deleting
|
| 45 | $inventory = getInventoryFromLocation($id, $db);
|
| 46 |
|
| 47 | if ( count($inventory) != 0) {
|
| 48 | die("Location still in use! Deletion will not be allowed until all inventory using this location are updated.");
|
| 49 | }
|
| 50 |
|
| 51 | // Make sure no items are loaned out that have the location as their original location
|
| 52 | $loanItems = getActiveLoansByOriginalLocation($id, $db);
|
| 53 | $numLoanItems = count($loanItems);
|
| 54 |
|
| 55 | $checkoutItems = getActiveCheckoutsByOriginalLocation($id, $db);
|
| 56 | $numCheckoutItems = count($checkoutItems);
|
| 57 |
|
| 58 | if ( $numItems != 0 | $numCheckoutItems != 0)
|
| 59 | {
|
| 60 | die("Loaned/Checked out item is stored at this location! Deletion will not be allowed until all inventory using this location are updated.");
|
| 61 | }
|
| 62 |
|
| 63 | deleteLocation($id, $db);
|
| 64 |
|
| 65 | $db->close();
|
| 66 |
|
| 67 | header('Location: manageLocations.php');
|
| 68 |
|
| 69 | ?>
|
| 70 | |