function export()
{
    global $_POST;
    $OUT = printStk($_POST);
    $OUT = clean_html($OUT);
    require_lib("xls");
    StreamXLS("Stock", $OUT);
}
#
#
#
#
#
#
#
require "settings.php";
require "libs/ext.lib.php";
if (isset($_GET["stkid"])) {
    $OUTPUT = details($_GET);
} else {
    if (isset($_POST["key"])) {
        switch ($_POST["key"]) {
            case "view":
                $OUTPUT = printStk($_POST);
                break;
            case "report":
                $OUTPUT = report($_POST);
                break;
            default:
                $OUTPUT = slct();
                break;
        }
    } else {
        # Display default output
        $OUTPUT = slct();
    }
}
require "template.php";
# Default view
#
#
#
#
#
#
#
#
#
#
#
require "settings.php";
if (isset($_POST["export"])) {
    $OUTPUT = export();
} else {
    $OUTPUT = printStk();
}
require "template.php";
# show stock
function printStk()
{
    # Set up table to display in
    $printStk = "\n\t\t<center>\n\t\t<h3>Available Stock</h3>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Store</th>\n\t\t\t\t<th>Category</th>\n\t\t\t\t<th>Stock Code</th>\n\t\t\t\t<th>Stock Description</th>\n\t\t\t\t<th>Product class</th>\n\t\t\t\t<th>Available units</th>\n\t\t\t\t<th>Cost Amount</th>\n\t\t\t\t<th>Minimun Level</th>\n\t\t\t\t<th>Maximum Level</th>\n\t\t\t\t<th>Selling Price</th>\n\t\t\t</tr>";
    # connect to database
    db_connect();
    # Query server
    $i = 0;
    $tot_avail = 0;
    $tot_cost = 0;
    $tot_sell = 0;
    $sql = "SELECT * FROM stock WHERE units > 0 AND div = '" . USER_DIV . "' ORDER BY stkdes ASC";