<? 
require_once "include/application.php"; 
require_once "include/paginator.php";
require_once "include/paginator_html.php";
require_once "include/function.php";
require_once "include/newvalue_lib.php";

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="sddm.css" >
<script src="include/validation.js" type="text/javascript"></script>
<title><? echo TITLE?></title>
</head>
<body>

<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#f1efd8">
  <tr>
    <td  colspan="2" align="center"><? require_once "include/header.php"; ?></td>
  </tr>
  <tr>
    <td colspan="2" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td width="185" valign="top" bgcolor="e6f3f9">
	
<? require_once "include/columnLeft.php"; 
if(array_search("Membership",$menulist)==false)
		print("<script type='text/javascript'>location.href='index.php'</script>");

?>	</td>
    <td width="834" valign="top">
	<form name="form" method="post" action="<?=$PHP_SELF ?>" >
	  <table width="810" border="0" align="center" cellpadding="0" cellspacing="0">
      
      <tr>

        <td valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="100%" height="30" class="TitleH3">Membership Search </td>
          </tr>
          <tr>
            <td height="1" bgcolor="#B8ED83"></td>
          </tr>
          <tr>
            <td ><? echo "<div class='Msg'>$action_msg</div>" ?>&nbsp;
              <input name="ty" type="hidden" id="ty" value="<? echo $ty ?>" /></td>
          </tr>

        </table>
          <table border="0" cellpadding="1" width="100%" cellspacing="2" class="small">
            <tr>
              <td height="7" colspan="10" class="text12"><span class="TextH1">
                <select name="sType" id="sType">
                  <option value="CardNo">Card No</option>
                  <option value="FormNo">Form No</option>
                  <option value="Name">Name of Applicant </option>
                  <option value="CardName">Name on the Card</option>
                  <option value="NRIC">NRIC/Passport </option>
                  <option value="ProductCode">Product Code</option>
                </select>
                <input name="sReferral" type="text" id="sReferral" value="<? echo $sReferral ?>" />
                Type of Products
                <select name="scheme" id="scheme" style="WIDTH: 180px">
                  <option value=""></option>
                  <?
			 
			 	$sql="select * from ivc_products order by ip_name";
				$result=mysql_query($sql) or die(mysql_error());				
				while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC)){
					echo "<option value='".$myrow["ip_id"]."' ";
					if($scheme==$myrow["ip_id"])echo "selected";
					echo ">".$myrow["ip_name"]."</option>";
				}
			
?>
                </select>
                <? stayfocus("form","sType",$sType) ?>
              </span></td>
            </tr>
            <tr>
              <td height="7" colspan="10" class="TextH1">Category of Membership
                <select name="category" id="category" style="WIDTH: 180px">
                  <option value=""></option>
                  <option value="Individual">Individual</option>
                  <option value="Corporate">Corporate</option>
                </select>
                
                Country 
                <select name="country" id="country">
                  <option value=""></option>
                  <? require "country.php"; ?>
                  </select>
                <? stayfocus("form","country",$country) ?>
                <span class="text12">
                 <input name="btnSearch" type="submit" class="btn" id="btnSearch" value="Search"/>
                  </span></td></tr>
            <tr>
              <td height="17" colspan="10" class="text12"><input type="button" name="btnAdd" value="Add New Membersip" class="btn150" onclick="location.href='newMembers.php'"/></td>
            </tr>
            <tr>
              <td width="131" height="23" background="images/tab-btns.gif" class="TextH1"><div align="center">Form No </div></td>
              <td width="188" background="images/tab-btns.gif" class="TextH1"><div align="center">Name of Applicant </div></td>
              <td width="154" background="images/tab-btns.gif" class="TextH1"><div align="center">Card No </div></td>
              <td width="133" background="images/tab-btns.gif" class="TextH1"><div align="center">NRIC/Passport</div></td>
              <td width="103" background="images/tab-btns.gif" class="TextH1"><div align="center">Product Code</div></td>
              <td width="23" background="images/tab-btns.gif">&nbsp;</td>
              <td width="23" background="images/tab-btns.gif">&nbsp;</td>
            </tr>
            <?

	$sql="select im_id,im_name,im_cardno,im_formno,im_scheme,im_ic,im_expired, ip_code,ip_name from ivc_members left join ivc_products 
	on im_scheme=ip_id where 1 ";
	if($sReferral){
		if($sType=="Name")$sql.=" and im_name like '%$sReferral%'";			
		else if($sType=="FormNo")$sql.=" and im_formno like '%$sReferral%'";				
		else if($sType=="CardNo")$sql.=" and im_cardno like '%$sReferral%'";				
		else if($sType=="CardName")$sql.=" and im_cardname like '%$sReferral%'";				
		else if($sType=="NRIC")$sql.=" and im_ic like '%$sReferral%'";				
		else if($sType=="ProductCode")$sql.=" and ip_code like '%$sReferral%'";				
	}	
	if($scheme)$sql.=" and im_scheme='$scheme'";
	if($category)$sql.=" and im_category='$category'";
	if($country)$sql.=" and im_country='$country'";

	$result=mysql_query($sql);
	$num_rows=mysql_num_rows($result);
	
	$pass="so=1&sReferral=$sReferral&sType=$sType&scheme=$scheme&category=$category&country=$country";
    $a =& new Paginator_html($_GET['page'],$num_rows,$pass);	
	$a->set_Limit(15);
	$a->set_Links(10);  	
	$limit1 = $a->getRange1();  
	$limit2 = $a->getRange2();  
	$sql.=" order by im_name limit $limit1,$limit2 ";	
	$result=mysql_query($sql) or die(mysql_error());

	while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC))
	{
		echo "<tr bgcolor='#ffffff' class='TextH1'>"; 
		$id=$myrow["im_id"];
	    echo "<td height='20' align='center' class='text12'>".$myrow["im_formno"]."</td>";	  				
	    echo "<td height='20' align='center' class='text12'>".$myrow["im_name"]."</td>";	  				
	    echo "<td align='center' class='text12'>".$myrow["im_cardno"]."</td>";	  				
	    echo "<td align='center' class='text12'>".$myrow["im_ic"]."</td>";	  										
	    echo "<td align='center' class='text12'>".$myrow["ip_code"]." - ".$myrow["ip_name"]."</td>";	  										
		echo "<td align='center' class='text12'><a href='membersEdit.php?id=$id'><img src='images/view.png' border='0'></a>";

		if($myrow["im_expired"] >= date("Y-m-d")){
			echo "<td align='center' class='text12'><a href='membersUpgrade.php?id=$id'><img src='images/up.jpg' border='0'></a>";
		}else echo "<td>&nbsp;</td>";
		echo "</td>";	  								
		echo "</tr>";

	}

?>
            <tr>
              <td colspan="10" class="TextH2"><? echo "Total Record :[".$num_rows."] "; if($num_rows)$a->previousNext();?></td>
            </tr>
          </table></td>

      </tr>
 
    </table>
	  <br />
	</form>	</td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#333333"><div align="center"><span class="Footer">
      <br />
      <? require_once "footer.php"; ?>
    </span></div></td>
  </tr>
</table>
</body>
</html>
