$id = mydb::cxn()->real_escape_string($_GET['itemID']);
        $new_qty = mydb::cxn()->real_escape_string($_GET['newQty']);
        //Get old quantity
        $query = "SELECT quantity FROM inventory WHERE id = " . $id;
        $result = mydb::cxn()->query($query);
        $row = $result->fetch_assoc();
        $old_qty = $row['quantity'];
        //Change quantity
        $query = "UPDATE inventory SET quantity = " . $new_qty . " WHERE id = " . $id;
        $result = mydb::cxn()->query($query);
        //Get new quantity
        $query = "SELECT quantity FROM inventory WHERE id = " . $id;
        $result = mydb::cxn()->query($query);
        $row = $result->fetch_assoc();
        $new_qty = $row['quantity'];
        if (mydb::cxn()->error == '') {
            echo $row['quantity'];
            update_item_history($id, "quantity", $old_qty, $new_qty);
        }
        break;
    case "check_in":
        if (!isset($_POST['itemID']) || $_POST['itemID'] == '') {
            throw new Exception('Invalid query (no itemID)');
        }
        check_in($_POST['itemID']);
        //Defined in 'inv_functions.php'
        // Send the itemID as a response to the calling function
        echo $_POST['itemID'];
        break;
}
// End switch()
Пример #2
0
function check_in($id)
{
    $result = mydb::cxn()->query("SELECT checked_out_to_id FROM inventory WHERE id like '" . $id . "'") or die("Error during item check-in: " . mydb::cxn()->error);
    $row = $result->fetch_assoc();
    $old_value = $row['checked_out_to_id'];
    if ($old_value == -2) {
        $result = mydb::cxn()->query("SELECT name FROM vip WHERE item_id like '" . $id . "'") or die("Error during VIP item check-in: " . mydb::cxn()->error);
        $row = $result->fetch_assoc();
        $old_value = $row['name'];
        mydb::cxn()->query("\tUPDATE inventory\n\t\t\t\t\t\tSET checked_out_to_id = -1\n\t\t\t\t\t\tWHERE id like '" . $id . "'") or die("Error during VIP item check-in: " . mydb::cxn()->error);
        mydb::cxn()->query("\tDELETE FROM vip\n\t\t\t\t\t\tWHERE item_id like '" . $id . "'") or die("Error during VIP item check-in: " . mydb::cxn()->error);
        update_item_history($id, 'checked_out_to_name', $old_value, '-1');
    } else {
        mydb::cxn()->query("\tUPDATE inventory\n\t\t\t\t\t\tSET checked_out_to_id = -1\n\t\t\t\t\t\tWHERE id like '" . $id . "'") or die("Error during item check-in: " . mydb::cxn()->error);
        update_item_history($id, 'checked_out_to_id', $old_value, '-1');
    }
}