<?php

session_start();
date_default_timezone_set('Asia/Colombo');
require_once('connectioni.php');

if ($_GET["Command"] == "save") {

    $sql = "insert into dlr_rmk (date,rep,c_code,c_name,remark,loc,tgt,outst,retch,ord,outstCltd,retchStld) values ('" . date('Y-m-d') . "', '" . $_SESSION["refRep"] . "', '" . $_GET["c_code"] . "', '" . $_GET["c_name"] . "','" . $_GET["rmk"] . "','" . $_GET["loc"] . "', '" . $_GET["tgt"] . "', '" . $_GET["outst"] . "', '" . $_GET["retch"] . "','" . $_GET["ord"] . "', '" . $_GET["outstCltd"] . "','" . $_GET["retchStld"] . "')";
    $results = mysqli_query($GLOBALS['dbinv'], $sql);

    if (!$results) {
        echo "not saved! $sql";
    } else {
        echo "successfully saved!";
    }
}

if ($_GET["Command"] == "setRep") {
    $_SESSION["refRep"] = $_GET["rep"];
    echo "session item refRep is set to " .$_SESSION["refRep"];
}

if ($_GET["Command"] == "pass_rmk") {

    header('Content-Type: text/xml');
    echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";

    $ResponseXML = "";
    $ResponseXML .= "<salesdetails>";

    $sql = "Select * from dlr_rmk where id='" . $_GET["id"] . "' ";

    $result = mysqli_query($GLOBALS['dbinv'], $sql);
    while ($row = mysqli_fetch_array($result)) {

        $ResponseXML .= "<id><![CDATA[" . $row['c_code'] . "]]></id>";
        $ResponseXML .= "<str_customername><![CDATA[" . $row['c_name'] . "]]></str_customername>";

        $ResponseXML .= "<outst><![CDATA[" . $row['outst'] . "]]></outst>";
        $ResponseXML .= "<retch><![CDATA[" . $row['retch'] . "]]></retch>";

        $ResponseXML .= "<date><![CDATA[" . $row['date'] . "]]></date>";
        $ResponseXML .= "<remark><![CDATA[" . $row['remark'] . "]]></remark>";
        $ResponseXML .= "<loc><![CDATA[" . $row['loc'] . "]]></loc>";
        $ResponseXML .= "<tgt><![CDATA[" . $row['tgt'] . "]]></tgt>";
        $ResponseXML .= "<ord><![CDATA[" . $row['ord'] . "]]></ord>";
    }
    $ResponseXML .= "</salesdetails>";
    echo $ResponseXML;
}
?>
