Example #1
0
function createXexecRedemptionExport($post)
{
    global $db;
    setMyCookie($post, 'crukRed');
    $CSVMaster = "<table>";
    $sqlWhere = getRedeemSQL($post["EmpNum"]);
    $dateSQL = getRedeemDates($post, "bo.");
    $sql = "SELECT *\n \t\t\tFROM tblbasket b, tblbasketorders bo, tblempall a\n \t\t\tWHERE b.orderID IS NOT NULL \n\t\t\tAND b.orderID = bo.id \n\t\t\tAND b.EmpNum = a.EmpNum \n\t\t\t" . $sqlWhere . $dateSQL . " ORDER BY bo.id DESC";
    $stmt = $db->prepare($sql);
    $stmt->execute();
    $CSVLine .= "<tr>";
    if ($post["NomineeID"] == "yes") {
        $CSVLine .= "<td>Nominee ID</td>";
    }
    if ($post["Nominee"] == "yes") {
        $CSVLine .= "<td>Nominee</td>";
    }
    if ($post["Department"] == "yes") {
        $CSVLine .= "<td>Department</td>";
    }
    if ($post["NomGrade"] == "yes") {
        $CSVLine .= "<td>Grade</td>";
    }
    if ($post["RedeemDate"] == "yes") {
        $CSVLine .= "<td>Redeem Date</td>";
    }
    if ($post["TransCode"] == "yes") {
        $CSVLine .= "<td>Order Ref</td>";
    }
    if ($post["ProdCat"] == "yes") {
        $CSVLine .= "<td>Product Category</td>";
    }
    if ($post["Product"] == "yes") {
        $CSVLine .= "<td>Product</td>";
    }
    if ($post["AmountSpent"] == "yes") {
        $CSVLine .= "<td>Amount Spent</td>";
    }
    if ($post["CurrentBalance"] == "yes") {
        $CSVLine .= "<td>Current Balance</td>";
    }
    $CSVLine .= "<td>Address 1</td>";
    $CSVLine .= "<td>Address 2</td>";
    $CSVLine .= "<td>Town</td>";
    $CSVLine .= "<td>Postcode</td>";
    $CSVLine .= "</tr>";
    $CSVMaster .= $CSVLine;
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        $CSVLine = "<tr>";
        $dbline = $row;
        $Nominee = getUser($dbline["EmpNum"]);
        $EmpAwards = getAvailable($dbline["EmpNum"]);
        $ProdData = getProductByID($dbline["prID"]);
        $CCTrans = getCCTransaction($dbline["orderID"]);
        $prodCat = getProductCategory($ProdData["subID"]);
        // We check each field and then add it to the CSV
        if ($post["NomineeID"] == "yes") {
            $CSVLine .= "<td>" . $dbline["EmpNum"] . "</td>";
        }
        if ($post["Nominee"] == "yes") {
            $CSVLine .= "<td>" . Trim($Nominee->Fname) . " " . Trim($Nominee->Sname) . "</td>";
        }
        if ($post["Department"] == "yes") {
            $CSVLine .= "<td>" . Trim($Nominee->Department) . "</td>";
        }
        if ($post["NomGrade"] == "yes") {
            $CSVLine .= "<td>" . Trim($Nominee->Grade) . "</td>";
        }
        if ($post["RedeemDate"] == "yes") {
            $CSVLine .= "<td>" . $dbline["date"] . "</td>";
        }
        if ($post["TransCode"] == "yes") {
            $CSVLine .= "<td>CR" . $dbline["orderID"] . "</td>";
        }
        if ($post["ProdCat"] == "yes") {
            $CSVLine .= "<td>" . Trim($prodCat["label"]) . "</td>";
        }
        if ($post["Product"] == "yes") {
            $CSVLine .= "<td>" . Trim($ProdData["aTitle"]) . "</td>";
        }
        $totalprice = floatval($dbline["totalPrice"]) + floatval($CCTrans->Amount);
        if ($post["AmountSpent"] == "yes") {
            $CSVLine .= "<td>" . Trim($totalprice) . "</td>";
        }
        if ($post["CurrentBalance"] == "yes") {
            $CSVLine .= "<td>" . $EmpAwards . "</td>";
        }
        $CSVLine .= "<td>" . Trim($dbline["address1"]) . "</td>";
        $CSVLine .= "<td>" . Trim($dbline["address2"]) . "</td>";
        $CSVLine .= "<td>" . Trim($dbline["town"]) . "</td>";
        $CSVLine .= "<td>" . Trim($dbline["postcode"]) . "</td>";
        $CSVLine .= "</tr>";
        $CSVMaster .= $CSVLine;
    }
    $CSVMaster .= $CSVLine . "</table>";
    return $CSVMaster;
}
<?php

include 'database.php';
header('Content-Type: text/plain; charset=utf-8');
if (isset($_POST['sale_order_id'])) {
    $sale_order_id = $_POST['sale_order_id'];
}
if (isset($_POST['sale_order_line_id'])) {
    $sale_order_line_id = $_POST['sale_order_line_id'];
    $req = mysql_query("SELECT * FROM uc_order_products WHERE order_product_id={$sale_order_line_id} ") or die(mysql_error());
    if (mysql_num_rows($req) > 0) {
        $res = mysql_fetch_array($req);
        $product_id = $res["nid"];
        $category_list = getProductCategory($product_id);
        $sql = "";
        for ($i = 0; $i < count($category_list); $i++) {
            $categories = split("/", $category_list[$i]);
            $name = $categories[count($categories) - 1];
            $sql .= "SELECT '" . $category_list[$i] . "' as category , tn.tid as distinction ";
            $sql .= "FROM term_node tn ";
            $sql .= "LEFT OUTER JOIN term_data td ON tn.tid = td.tid ";
            $sql .= " where td.name='{$name}' ";
            if (isset($product_id)) {
                $sql .= " AND nid=" . $product_id . " ";
            }
            if ($i < count($category_list) - 1) {
                $sql .= " UNION ";
            }
        }
        if (!empty($sql)) {
            echo executeSQL($sql);