<?php

session_start();
;
    include_once("config.inc.php");
	include_once("DBConnector.php");

include_once ("connection.php");

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

    //if(isset($_GET['customername'])){
    //$letters = $_GET['customername'];
    //$letters = $_GET['letters'];
    //	$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
    //	$res = mysql_query("SELECT * FROM mast_family where name like '".$letters."%'") or die(mysql_error());
    //$res = mysql_query("SELECT distinct trn_involved.str_name FROM trn_involved where str_name like '".$letters."%'") or die(mysql_error());
    //SELECT * FROM occupation_details where str_first_name like 'k%'
    //echo $res;

    $ResponseXML .= "";
    //$ResponseXML .= "<invdetails>";

    $ResponseXML .= "<table width=\"735\" border=\"0\" class=\"form-matrix-table\">
                            <tr>
                              <td width=\"121\"  background=\"\" ><font color=\"#FFFFFF\">Customer No</font></td>
                              <td width=\"424\"  background=\"\"><font color=\"#FFFFFF\">Customer</font></td>
                             <td width=\"424\"  background=\"\"><font color=\"#FFFFFF\">Address</font></td>
   							</tr>";

    if ($_GET["mstatus"] == "cusno") {
        $letters = $_GET['cusno'];
        //$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
        if ($_GET["incen"] == "1") {
            $sql = mysql_query("SELECT * from vendor where CODE like  '$letters%'   order by CODE limit 50") or die(mysql_error());
        } else if ($_GET["incen"] == "2") {
            $sql = mysql_query("SELECT * from vendor where CODE like  '$letters%'   order by CODE limit 50") or die(mysql_error());
        } else {
            $sql = mysql_query("SELECT * from vendor where CODE like  '$letters%'   order by CODE limit 50") or die(mysql_error());
        }
    } else if ($_GET["mstatus"] == "customername") {
        $letters = $_GET['customername'];
        //$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
        if ($_GET["incen"] == "1") {
            $sql = mysql_query("SELECT * from vendor where NAME like  '$letters%'   order by CODE limit 50") or die(mysql_error()) or die(mysql_error());
        } else if ($_GET["incen"] == "2") {
            $sql = mysql_query("SELECT * from vendor where NAME like  '$letters%'  order by CODE limit 50") or die(mysql_error()) or die(mysql_error());
        } else {
            $sql = mysql_query("SELECT * from vendor where NAME like  '$letters%'   order by CODE limit 50") or die(mysql_error()) or die(mysql_error());
        }
    } else {

        $letters = $_GET['customername'];
        //$letters = preg_replace("/[^a-z0-9 ]/si","",$letters);
        if ($_GET["incen"] == "1") {
            $sql = mysql_query("SELECT * from vendor where NAME like  '$letters%'    order by CODE limit 50") or die(mysql_error()) or die(mysql_error());
        } else if ($_GET["incen"] == "2") {
            $sql = mysql_query("SELECT * from vendor where NAME like  '$letters%' order by CODE limit 50") or die(mysql_error()) or die(mysql_error());
        } else {
            $sql = mysql_query("SELECT * from vendor where NAME like  '$letters%'   order by CODE limit 50") or die(mysql_error()) or die(mysql_error());
        }
    }
 
    while ($row = mysql_fetch_array($sql)) {
        $cuscode = $row["CODE"];
        $stname = $_GET["stname"];
        $ResponseXML .= "<tr>
                              <td onclick=\"custno('$cuscode', '$stname');\">" . $row['CODE'] . "</a></td>
                              <td onclick=\"custno('$cuscode', '$stname');\">" . $row['NAME'] . "</a></td>
                              <td onclick=\"custno('$cuscode', '$stname');\">" . $row['ADD2'] . "</a></td>                          	
                            </tr>";
    }

    $ResponseXML .= "   </table>";

    echo $ResponseXML;
    //	}
}

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

   

    $_SESSION["custno"] = $_GET['custno'];

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

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

    $cuscode = $_GET["custno"];
    $sql = mysql_query("Select * from vendor where CODE='" . $cuscode . "'") or die(mysql_error());
    if ($row = mysql_fetch_array($sql)) {

        $ResponseXML .= "<id><![CDATA[" . $row['CODE'] . "]]></id>";
        $ResponseXML .= "<str_customername><![CDATA[" . $row['NAME'] . "]]></str_customername>";
        $address = $row['ADD1'] . "," . $row['ADD2'];
        $ResponseXML .= "<str_address><![CDATA[" . $address . "]]></str_address>";
        $ResponseXML .= "<str_vatno><![CDATA[" . $row['vatno'] . "]]></str_vatno>";
        $ResponseXML .= "<AltMessage><![CDATA[" . $row['AltMessage'] . "]]></AltMessage>";
        
    }
    $ResponseXML .= "</salesdetails>";
    echo $ResponseXML;
}

?>
