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

if(count($personclm)==0){
echo "Please at lease one person column !!";
exit();
}
$ar_fld[]=count($personclm);
$ar_fld[]=count($addrclm);
$ar_fld[]=count($postalclm);
$ar_fld[]=count($othersclm);

if(!$user)$user=$_SESSION["egoUser"];


?>
<!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" />
<title>Daily Payout Summary Report</title>
<link rel="stylesheet" type="text/css" href="style.css" >
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	background-color: #FFFFFF;
}

-->
</style>
</head>

<body>
<table width="1000" border="0" cellpadding="0" cellspacing="0" >
  <tr>
    <td width="1024" height="30" colspan="2" class="TextH2"><strong>     Membership Details Report </strong></td>
  </tr>
  
  
  <tr>
    <td colspan="2" class="TextH1"><br />
 User : <? echo $user; ?><br />
 Date Printed : <? echo date("d/m/Y") ?><br />
<br />
    <br /></td>
  </tr>
</table>

<table width="<? echo max($ar_fld)*100 ?>" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#D0E3F6"><td colspan="<? echo max($ar_fld) ?>"><hr /></td></tr>
  <tr >
  <?
  for($i=0;$i<count($personclm);$i++)
    echo '<td height="25" class="TextH1" width="100">'.substr($personclm[$i],3).'</td>';
?>
</tr>
<? if(is_array($addrclm)){ 
$sql="select im_id,".implode(",",$addrclm)." 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'";
if($active)$sql.=" and im_active='$active'";

$result=mysql_query($sql) or die(mysql_error());
while($myrow=MySQL_fetch_row($result))
{  
	$dt=array();
	$dt[]=$myrow[0];
	for($i=0;$i<count($addrclm);$i++){
		if($addrclm[$i]=="p_preference" || $addrclm[$i]=="p_phone1_label" || $addrclm[$i]=="p_phone2_label"  || $addrclm[$i]=="p_phone3_label" || $addrclm[$i]=="p_msg1_label" || $addrclm[$i]=="p_msg2_label"){
			if($myrow[$i+1]>1)$val=$nv[$myrow[$i+1]];
			else $val="";
		}else $val=$myrow[$i+1];
		
		$dt[]=$val;
	
	}
	$ar_addr[$myrow[0]]=$dt;
}
?>
  <tr>
  <?
  for($i=0;$i<count($addrclm);$i++)
    echo '<td height="25" class="TextH1" width="100">'.substr($addrclm[$i],3).'</td>';
 ?>	
  </tr>
<? } ?>
<? if(is_array($postalclm)){ 
$sql="select im_id,".implode(",",$postalclm)." from ivc_members 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'";
if($active)$sql.=" and im_active='$active'";

$result=mysql_query($sql) or die(mysql_error());
while($myrow=MySQL_fetch_row($result))
{  
	$dt=array();
	$dt[]=$myrow[0];
	for($i=0;$i<count($postalclm);$i++){
		$dt[]=$myrow[$i+1];
	
	}
	$ar_postal[$myrow[0]]=$dt;
}


?>
  <tr>
  <?
  for($i=0;$i<count($postalclm);$i++)
    echo '<td height="25" class="TextH1" width="100">'.substr($postalclm[$i],3).'</td>';
 ?>	
  </tr>
<? } ?>


<?
$sql="select im_id,".implode(",",$personclm)." from ivc_members 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'";
if($active)$sql.=" and im_active='$active'";

$result=mysql_query($sql) or die(mysql_error());
while($myrow=MySQL_fetch_row($result))
{  
	$dt=array();
	$dt[]=$myrow[0];
	for($i=0;$i<count($personclm);$i++){
		if($personclm[$i]=="p_title" || $personclm[$i]=="p_role" || $personclm[$i]=="p_race" || $personclm[$i]=="p_status" || $personclm[$i]=="p_type" || $personclm[$i]=="p_industry" || $personclm[$i]=="p_source" || $personclm[$i]=="p_classification")$val=$nv[$myrow[$i+1]];
		else if($personclm[$i]=="p_company"){
			if($myrow[$i+1] > 0){	
				$ret=get_data("c_name","company","where c_id='".$myrow[$i+1]."'");
				$val=$ret["c_name"];
			}else $val="";
		}else $val=$myrow[$i+1];
		
		$dt[]=$val;
	
	}
	$ar_person[$myrow[0]]=$dt;
}

 ?>	
  </tr>
<tr bgcolor="#D0E3F6"><td colspan="<? echo max($ar_fld) ?>"><hr /></td></tr>
  <?
if(count($ar_person)>0){
  while (list($key, $val) = each($ar_person)) {
	echo "<tr>";
	for($i=1;$i<count($ar_person[$key]);$i++){	
		echo "<td width='100' class='TextH1'>".$ar_person[$key][$i]."</td>";
	}
	echo "</tr>";	

	echo "<tr>";	
	for($i=1;$i<count($ar_addr[$key]);$i++){	
		echo "<td width='100' class='TextH1'>".$ar_addr[$key][$i]."</td>";
	}
	echo "</tr>";		

	echo "<tr>";	
	for($i=1;$i<count($ar_postal[$key]);$i++){	
		echo "<td width='100' class='TextH1'>".$ar_postal[$key][$i]."</td>";
	}
	echo "</tr>";		

	

	echo "<tr><td colspan='".max($ar_fld)."'><hr /></td></tr>	";
 }

}	
	?>



</table>
</body>
</html>
