<?php

/***************************************************************************
 *   copyright            : (C) 2012 PCRepairTracker.com
 *   email                : info@pcrepairtracker.com
 *   This program is a copyrighted work.
 *   Please see the license.txt file for details
 *
 ***************************************************************************/

if (array_key_exists('func',$_REQUEST)) {
$func = $_REQUEST['func'];
} else {
$func = "";
}


                                                                                                    
function nothing() {
require_once("header.php");


require_once("footer.php");
                                                                                                    
}

function add_item() {

require("deps.php");

require("common.php");

require_once("validate.php");

$qty = pv($_REQUEST['qty']);
$itemdesc = pv($_REQUEST['itemdesc']);
$status = pv($_REQUEST['status']);
if (array_key_exists('stockid',$_REQUEST)) {
$stockid = $_REQUEST['stockid'];
} else {
$stockid = 0;
}






$rs_insert_cart = "INSERT INTO shoplist (qty,itemdesc,itemstatus,byuser,stockid) VALUES  ('$qty','$itemdesc','$status','$ipofpc','$stockid')";
@mysqli_query($rs_connect, $rs_insert_cart);

header("Location: index.php");

}



function remove_item() {

$item_id = $_REQUEST['item_id'];


require("deps.php");
require("common.php");

require_once("validate.php");






$rs_delete_cart = "DELETE FROM shoplist WHERE shopid = '$item_id'";
@mysqli_query($rs_connect, $rs_delete_cart);

header("Location: index.php");
}

function edititem() {

require("deps.php");
require("common.php");

require_once("validate.php");

$shopid = $_REQUEST['shopid'];
$qty = $_REQUEST['qty'];
$itemdesc = pv($_REQUEST['itemdesc']);
$status = pv($_REQUEST['status']);
                                                                                                                                               



                                                                                                                                         
                                                                                                                                               
$rs_update = "UPDATE shoplist SET qty = '$qty', itemdesc = '$itemdesc', itemstatus = '$status' WHERE shopid = '$shopid'";
@mysqli_query($rs_connect, $rs_update);
                                                                                                                                               
header("Location: index.php");
}

function edititemq() {

$dir = $_REQUEST['dir'];
$shopid = $_REQUEST['shopid'];


require("deps.php");
require("common.php");

require_once("validate.php");






if ($dir =="up") {
$rs_update = "UPDATE shoplist SET qty = (qty + 1) WHERE shopid = '$shopid'";
} else {
$rs_update = "UPDATE shoplist SET qty = (qty - 1) WHERE shopid = '$shopid'";
}

@mysqli_query($rs_connect, $rs_update);

header("Location: index.php");
}



switch($func) {
                                                                                                    
    default:
    nothing();
    break;
                                
    case "add_item":
    add_item();
    break;

                                   
    case "remove_item":
    remove_item();
    break;
                                 
    case "edititem":
    edititem();
    break;
                                                                                                                             
    case "edititemq":
    edititemq();
    break;



}

?>
