<html>
<head>
   <title>Material</title>
</head>
<body>
<script type="text/javascript">
function sendValue(s,a,b){
var selvalue = s;
var selvalue2 = a;
var selvalue3 = b;

window.opener.document.form1.txt_matnr.value = selvalue;
window.opener.document.form1.txt_matnr2.value = selvalue2;
window.opener.document.form1.txt_erfme.value = selvalue3;

window.close();
}
</script>
<style type="text/css">
a:link {
	color: #000;
}
a:visited {
	color: #000;
}
a:hover {
	color: #000;
}
a:active {
	color: #000;
}
</style>
<style type="text/css">
body,td,th {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 12px;
}
</style>
<h1>Material</h1><br>
  <strong><em>Search
by:</em></strong>
  <form name="form1" method="get" action="">
  <table width="455" border="0" cellspacing="1" cellpadding="1">
    <tr>
      <th bgcolor="#CCCCCC">Material number :</th>
      <td><input name="txt_matnr" type="text" id="txt_matnr" value="<?php echo strtoupper($_GET['txt_matnr']); ?>" size="18" maxlength="18"></td>
    </tr>
    <tr>
      <th bgcolor="#CCCCCC">Material description :</th>
      <td><input name="txt_maktx" type="text" id="txt_maktx" value="<?php echo strtoupper($_GET['txt_maktx']); ?>" size="40" maxlength="40"></td>
    </tr>
    <tr>
      <th width="156">&nbsp;</th>
      <td width="240"><label for="txt_max"></label>
        <label for="txt_maktx">
          <input type="submit" name="button" id="button" value="Search">
    </label></td>
    </tr>
  </table>
</form>
  <?php
  if($_GET['txt_maktx'] != '' || $_GET['txt_matnr'] != '' )
  		{
		
       include_once("sap.php");
	   include_once("lib.php");

    $sap = new SAPConnection();
    $sap->Connect(connection_string());
    if ($sap->GetStatus() == SAPRFC_OK ) $sap->Open ();
    if ($sap->GetStatus() != SAPRFC_OK ) {
       $sap->PrintStatus();
       exit;
    }

    $fce = &$sap->NewFunction ("YFM_MATNUM_CIS");
    if ($fce == false ) {
       $sap->PrintStatus();
       exit;
    }
	
	
	  	$fce->GR_MAKTX->row["SIGN"] = "I";
		$fce->GR_MAKTX->row["OPTION"] = "CP";
		$fce->GR_MAKTX->row["LOW"] = "*".strtoupper($_GET['txt_maktx'])."*";
		$fce->GR_MAKTX->row["HIGH"] = " ";
		$fce->GR_MAKTX->Append($fce->GR_MAKTX->row);
		
		$fce->GR_MATNR->row["SIGN"] = "I";
		$fce->GR_MATNR->row["OPTION"] = "CP";
		$fce->GR_MATNR->row["LOW"] = "*".strtoupper($_GET['txt_matnr'])."*";
		$fce->GR_MATNR->row["HIGH"] = " ";
		$fce->GR_MATNR->Append($fce->GR_MATNR->row); 
  		
	
	/*if($_GET['txt_max'] != '' )
  		{
			$fce->GV_MAX_ROWS=$_GET['txt_max'];
		}*/
    $fce->Call();
	
    if ($fce->GetStatus() == SAPRFC_OK) {
		
		
        //Tables
        echo "<table border=1 bordercolor='#000000' cellpadding='0' cellspacing='0'><tr  bgcolor='#CCCCCC'><th>Material description</th><th>Material</th></tr>";
        $fce->GI_HEADER_MARA->Reset();
		//Display Tables
        while ( $fce->GI_HEADER_MARA->Next() ){
			if($bg==0)
           {
           echo"<tr style=background-color:#eeeeee;>";
           $bg++;
           }
          else
			{
			echo"<tr style=background-color:#;>";
			$bg--;
			}
       echo '<td><a href="#" onClick="sendValue('.'\''.fm_delete_zero_value2($fce->GI_HEADER_MARA->row["MATNR"]).'\''.','.'\''.$fce->GI_HEADER_MARA->row["MAKTX"].'\''.','.'\''.$fce->GI_HEADER_MARA->row["MEINS"].'\''.');" >'.$fce->GI_HEADER_MARA->row["MAKTX"].'</a></td>
	   <td><a href="#" onClick="sendValue('.'\''.fm_delete_zero_value2($fce->GI_HEADER_MARA->row["MATNR"]).'\''.','.'\''.$fce->GI_HEADER_MARA->row["MAKTX"].'\''.','.'\''.$fce->GI_HEADER_MARA->row["MEINS"].'\''.');" >'.fm_delete_zero_value2($fce->GI_HEADER_MARA->row["MATNR"]).'</a></td></tr>';
		}
        echo "</table>";							
    } else
        $fce->PrintStatus();
	$sap->Close();
		}
		else
		{
			
			echo '<center><font color="#FF0000"><b>Please input your search keyword</b></font></center>';
			
		}
  ?>

</body>
</html>
