<?
include_once("../include/main.inc.php");
if($_GET['id1']=='mainCategory') {
	$catid=$_REQUEST['q'];
	if ($catid) {
		echo categoryDropDown("industryType","$industryType","$catid");
	}
	exit;
}
check_session('MyCpanel','index.php');

################ Paging Starts From Here ##################
@extract($_REQUEST);
$start = (intval($start)==0 or $start=="")?$start=0:$start;
$pagesize = intval($pagesize)==0?$pagesize=10:$pagesize;

$record_type="Member";
$script_name="manage_paid_memberships.php";
$table_name="member_tbl";

if ($_POST['action_register']=="save") {
	@extract($_POST);	
  //checkHTTPREFERER();
  $all_categories="";
  for ($i=0; $i<count($industryType); $i++) {
	  $catids=getCategoryHierarchy($industryType[$i]);
	  $all_categories.=$catids;
  }
  $all_categories=substr($all_categories,0,-1);
  $tmp=explode("^",$all_categories);
  asort($tmp);
  $tmp=array_unique($tmp);
  $all_categories=implode("^",$tmp);
  $allCategories="^".$all_categories."^";		
  
  if (count($industryType) > 1) {
	  $industryType1=implode("^",$industryType);
	  $industryType2="^".$industryType1."^";
  }
  else {
	  $industryType2="^".$industryType[0]."^";
  }
  $industryType=$industryType2;
			
	updateTable("member_tbl"," nameTitle='$nameTitle', memberName='$memberName', companyName='$companyName', jobTitle='$jobTitle', address='$address', city='$city', state='$state', zipcode='$zipcode', country='$country', countryCodePhone='$countryCodePhone', areaCodePhone='$areaCodePhone', phone='$phone', countryCodeFax='$countryCodeFax', areaCodeFax='$areaCodeFax', fax='$fax', mobileNo='$mobileNo', alternateEmail='$alternateEmail', ownerName='$ownerName', ownershipType='$ownershipType', yoe='$yoe', certification='$certification', mainMarket='$mainMarket', companySize='$companySize', annualTurnover='$annualTurnover', businessCountry='$businessCountry', businessNature='$businessNature', mainCategory='$mainCategory', industryType='$industryType', allCategories='$allCategories', companyDescription='$companyDescription', website='$website' where memberID='$memID'");
	
	adminheader_popup("Edit Member Details");
	echo "<br/><br/><center>Member Details has been updated successfully</center><br/><br/>";
	adminfooter_popup();
	exit;
}

if($id=="edit"){
	adminheader_popup("Edit Member Details");
	echo addEditMemberAdmin($recordID);
	adminfooter_popup();
	exit;
}

if($id=="View"){
	adminheader_popup("View Member Details");
	echo view_member_details($recordID);
	adminfooter_popup();
	exit;
}

if($_POST[action]=="Delete"){
	if(sizeof($_POST[cid])==0) {
		$_SESSION[session_message]='Please select a record first.';
		header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
		exit;
	}
	for ($x=0; $x < sizeof($_POST[cid]); $x++){
		$arr=$_POST[cid];
		updateTable($table_name," status='D', featuredMember='N' where memberID='$arr[$x]'");		
	}
	$_SESSION[session_message]='Record has been deleted from the admin panel.';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}

if($_POST[action]=="Activate"){
	if(sizeof($_POST[cid])==0) {
		$_SESSION[session_message]='Please select a record first.';
		header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=$start&pagesize=$pagesize");
		exit;
	}
	for ($x=0; $x < sizeof($_POST[cid]); $x++){
		$arr=$_POST[cid];
		updateTable($table_name," status='Y' where memberID='$arr[$x]'");
	}
	$_SESSION[session_message]='Selected record(s) activated successfully.';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}

if($_POST[action]=="Deactivate"){
	if(sizeof($_POST[cid])==0) {
		$_SESSION[session_message]='Please select a record first.';
		header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=$start&pagesize=$pagesize");
		exit;
	}
	for ($x=0; $x < sizeof($_POST[cid]); $x++){
		$arr=$_POST[cid];
		updateTable($table_name," status='N', featuredMember='N' where memberID='$arr[$x]'");
	}
	$_SESSION[session_message]='Selected record(s) deactivated successfully.';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}

if($id=="deactivate") {
	updateTable($table_name," status='N', featuredMember='N' where memberID='$recordID' and status='Y' ");	
	$_SESSION[session_message]=$record_type.' has been deactivated successfully.';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}

if($id=="activate") {
	updateTable($table_name," status='Y' where memberID='$recordID' and status='N' ");
	$_SESSION[session_message]=$record_type.' has been activated successfully.';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}

if ($id=="delete") {
	updateTable($table_name," status='D', featuredMember='N' where memberID='$recordID'");
	$_SESSION[session_message]=$record_type.' has been deleted successfully.';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;
}

if ($_POST[action]=="update_membership") {
	if ($planType < 3) {
		$memRes=getResult("member_tbl"," where memberID='$recordID'");
		
		if ($expiryDate=="") {
			$res=getResult("membership_plan_tbl"," where membershipType='$planType'");
			$dur=$res[planDuration];
			$expiryDate=date("Y-m-d", mktime(0,0,0,date("m"),date("d")+$dur,date("Y")));		
		}
		/*
		if ($memRes[expiryDate]!="" && $memRes[expiryDate]!="0000-00-00") {
			$dt=explode("-",$memRes[expiryDate]);
			$yy=$dt[0];
			$mm=$dt[1];
			$dd=$dt[2];
			$expiryDate=date("Y-m-d", mktime(0,0,0,$mm,$dd+$dur,$yy));
		}
		*/
		
		updateTable($table_name, " membershipType='$planType', activationDate='$wdt', expiryDate='$expiryDate' where memberID='$recordID'");
	}
	else {		
		updateTable($table_name, " membershipType='$planType', expiryDate='$wdt' where memberID='$recordID'");
	}
	$_SESSION[session_message]=$record_type.' has been updated successfully.';
	header("Location: ".SITE_ADMIN_URL."/".$script_name."?start=".$start."&pagesize=".$pagesize);
	exit;	
}

admin_header();
?>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" valign="top">
 <tr>
	<td align="left" width="50%"><strong><b class="myTitle">Manage <?=$record_type;?>s</b></strong></td>
	<td align="right">
	 <form name="pg_form" action="<?=$PHP_SELF?>" method="post" style="margin:0px;padding:0px;">
	 <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" valign="top">
	  <tr>
	   <td align="right">Records Per Page:
	    <select name="pagesize" onchange="this.form.submit();">
	     <option value="0">Select</option>
	     <?php
	     foreach($_GLOBALS[pgsize_arr] as $val) {
		     if(trim($pagesize)==trim($val)) {
			     echo '<option value="'.$val.'" selected>'.$val.'</option>';
		     }
		     else{
			     echo '<option value="'.$val.'">'.$val.'</option>';
		     }
	     }
	     ?>
	    </select>
	    <input type="hidden" name="keyword" value="<?=$keyword;?>" />
	    <input type="hidden" name="status" value="<?=$status;?>" />
		 </td>
		</tr>
	 </table>
	 </form>
	</td>
 </tr>
</table>
<hr size="2" width="99%" color="#DA251C">

<?
if ($status!="") {
	$cond="where status='$status'";
	$link="&status=$status";
}
else {
	$cond="where 1";
}
$qry1="select * from $table_name $cond";
$keyword=trim($keyword);
if($keyword!=""){
  $qry1.=" and (email LIKE '%$keyword%' or memberName LIKE '%$keyword%' )"; 
}

if($_REQUEST[sortName]!=''){
	$qry1 .= " order by $_REQUEST[sortName] $_REQUEST[sortBy]";
}
else {
	$qry1 .= " order by memberID desc";
}

$reccnt = NumRows(db_query($qry1));
$qry1.=" limit $start, $pagesize";
#echo $qry1;
$qry= db_query($qry1);
echo pageNavigation($reccnt,$pagesize,$start,$link);
print_message(); 
?>

<table width="100%"  border="0" cellpadding="6" cellspacing="2" class="lightBorder">
 <tr>
  <td class="lightGrayBg" align="left"><b>Search Members</b><br>
  <form name="search2" method="POST" action="">
   Keyword: <input name="keyword" type="text" class="input" size="25" value="<?=$keyword;?>">
   <input type="hidden"  class="button" name="id" value="Search2">
   <input type="submit"  class="button" name="search" value="Search">	
  </form>
  </td>
  <td class="lightGrayBg">
  <b>Sort Members<b><br>
  <form name="search3" method="POST" action="">
   <select name="sortName" size=1>
    <option value=''>--------Select---------</option>
    <option value='recvDate' <? if($sortName=="recvDate"){ echo "selected";}?>>Join Date</option>
    <option value='memberName' <? if($sortName=="memberName"){ echo "selected";}?>>Member Name</option>
    <option value='email' <? if($sortName=="email"){ echo "selected";}?>>Member Email</option>
   </select>
   <select name="sortBy">
    <option value=''>-----Sort By-----</option>
    <option value="asc" <? if($sortBy=="asc"){ echo "selected";}?>>Ascending</option>
    <option value="desc" <? if($sortBy=="desc"){ echo "selected";}?>>Descending</option>
   </select>
   <input type="hidden"  class="button" name="id" value="Search3">
   <input type="submit"  class="button" name="search" value="Sort">
  </form>
  </td>
  <td class="lightGrayBg">
   <b>Select Status</b><br/>
   <form name="sts_form" action="<?=$PHP_SELF?>" method="post" style="margin:0px;padding:0px;">
	 <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0" valign="top">
	  <tr>
	   <td align="left">
	    <select name="status" onchange="this.form.submit();">
	     <option value="">All Members</option>
	     <option value="Y" <? if($status=="Y"){ echo "selected";}?>>Active</option>
	     <option value="N" <? if($status=="N"){ echo "selected";}?>>InActive</option>
	     <option value="D" <? if($status=="D"){ echo "selected";}?>>Deleted</option>
	    </select>
	    <input type="hidden" name="keyword" value="<?=$keyword;?>" />
	    <input type="hidden" name="pagesize" value="<?=$pagesize;?>" />
		 </td>
		</tr>
	 </table>
	 </form>
	</td> 
 </tr>
</table><br />

<?
if($reccnt>0){
	?>
	<table width="99%" border="0" cellpadding="2" cellspacing="2" class="lightBorder">
	 <tr height="25" bgcolor="#EAEAEA">
	  <td width="3%">SL.</td>
	  <td width="30%"><b>Member Details</b></td>
	  <td width=17%><b>Address Details</td>
	  <td width=15%><b>Membership Type</td>
	  <td width=10% align="center"><b>Join Date</b></td>
	  <td width=8% align="center"><b>Status</b></td>
	  <td width=17%><b>Options</b></td>
	 </tr>
	 <?
	 $sl=$start+1;
	 while ($arr=mysql_fetch_array($qry)) {
		 $arr=ms_htmlentities_decode($arr);
		 if($sl%2!=0){
			 $color="#ffffff";
		 }
		 else {
			 $color="#f6f6f6";
		 }
		 if ($arr[expiryDate]!="0000-00-00") {
			 $expiryDate=$arr[expiryDate];
		 }
		 else {
			 $expiryDate="";
		 }
		 
		 $video_link="";
		 if($arr['companyVideo']!="") {
			 $video_link='&nbsp;<a onClick="window.open(\''.SITE_URL_PATH.'/view_video.php?video_name='.$arr['companyVideo'].'\',\'royale\', \'toolbar=no,width=450,height=340,left=275,top=225, screenX=250,screenY=150,status=no,scrollbars=no, resizable=no,\');return false" href="javascript:void(0);"><img src="'.SITE_URL_PATH.'/images/video-icon.gif" alt="View Video" border="0" /></a>';
		 }
		 ?>
		 <tr bgcolor="<?=$color;?>">
		  <td class="<?=$class?>" valign="top"><?=$sl;?>.</td>
		  <td class="<?=$class?>" valign="top">
		   <b><?=$arr[nameTitle];?> <?=$arr[memberName];?></b>
		   <?
		   if($arr[email]!=""){
			   ?>
			   <br /><b>Email</b>: <?=$arr[email];?>
			   <br /><b>Password</b>: <?php echo $arr[pwd];			   
		   }		   
		   ?>
		   <br/><b>Company Name</b>: <?php echo ucwords($arr[companyName]);?>
			 <br/><b>Job Title</b>: <?php echo ucwords($arr[jobTitle]);?>
			 <br/><b>Business Type</b>: <?php echo getBusinessType($arr[businessType]);?>
			 <br/><b>Business Nature</b>: <?php echo getBusinessNature($arr[businessNature]);?>
			 <br/><b>Establish Year</b>: <?php echo $arr[yoe];			 
			 if ($arr['addedBy'] != "") {
				 ?>
				 <br/><b>Added By</b>: <?php echo getAdminStaffName($arr['addedBy']);
			 }
			 ?>
		  </td>
      <td valign='top' class="<?=$class?>">
			 <b>Address</b>: <?php echo ucwords($arr[address]);	 
			 if($arr[city]!=""){
				 ?>
				 <br /><b>City</b>: <?php echo ucwords($arr[city]);
			 }
			 if($arr[state]!=""){
				 ?>
				 <br /><b>State</b>: <?php echo ucwords($arr[state]);
			 }			 
			 if($arr[country]!="") {
				 ?>
				 <br /><b>Country</b>: <?php echo $arr[country];
			 }
			 if($arr[zipcode]!=""){
				 ?>
				 <br /><b>Zipcode</b>: <?php echo $arr[zipcode];				 
			 }
			 if($arr[mobileNo]!=""){
				 ?>
				 <br /><b>Mobile No</b>: <?php echo $arr[mobileNo];				 
			 }
			 if($arr[phone]!=""){
				 ?>
				 <br /><b>Phone</b>: <?php echo $arr[countryCodePhone]."-".$arr[areaCodePhone]."-".$arr[phone];
			 }
			 if($arr[fax]!="") {
				 ?>
				 <br /><b>Fax</b>: <?php echo $arr[countryCodeFax]."-".$arr[areaCodeFax]."-".$arr[fax];
			 }
			 ?>			 
      </td>
			<td valign='top' class="<?=$class?>">
			 <strong><?php echo getMembershipPlanName($arr[membershipType]);?></strong>
			 <?
			 if ($expiryDate) {
				 ?>
				 <br/><br/><i>Activation Date</i>:<br/><strong><?=show_date($arr[activationDate])?></strong><br/><br/><i>Expiry Date</i>:<br/><strong><?=show_date($arr[expiryDate])?></strong>
				 <?
			 }
			 ?>
			</td>
			<td class="<?=$class?>" valign='top' align="center"><?=show_date($arr[recvDate])?></td>
			<td valign='top' align="center">
		   <?
		   if($arr[status]=='Y') {
			   ?>
			   <strong>Active</strong>
			   <?
		   }
		   else if($arr[status]=='D') {
			   ?>
			   <strong>Deleted</strong>
			   <?
		   }
		   else {
			   ?>
			   <strong>Inactive</strong>
			   <?
		   }
		   if ($video_link != "") {
			   ?>
			   <br/><br/>
			   <?php
			   echo $video_link;
		   }
		   ?>
		  </td>
			<td class="<?=$class?>" valign='top'>
			 <?
		   if($arr[status]=='Y') {
			   ?>
			   &nbsp;<a href="<?=SITE_ADMIN_URL?>/<?=$script_name;?>?id=deactivate&recordID=<?=$arr[memberID];?>&start=<?=$start;?>&pagesize=<?=$pagesize?>"><img src="<?=SITE_ADMIN_URL?>/images/active.gif" alt="Deactivate This <?=$record_type;?>" title="Deactivate This <?=$record_type;?>" border="0"></a>
			   <?
		   }
		   if($arr[status]=='N') {
			   ?>
			   &nbsp;<a href="<?=SITE_ADMIN_URL?>/<?=$script_name;?>?id=activate&recordID=<?=$arr[memberID];?>&start=<?=$start;?>&pagesize=<?=$pagesize?>"><img src="<?=SITE_ADMIN_URL?>/images/deactive.gif" alt="Activate This <?=$record_type;?>" title="Activate This <?=$record_type;?>" border="0"></a>
			   <?
		   }
		   ?>
		   &nbsp;<a href="javascript:void(0);" onclick="window.open('<?=SITE_ADMIN_URL?>/<?=$script_name;?>?id=View&recordID=<?=$arr[memberID]?>&start=<?=$start?>&pagesize=<?=$pagesize?>','pop','height=550,width=550,scrollbars=yes,resizable=yes');"><img src="<?=SITE_ADMIN_URL?>/images/preview.gif" alt="View This <?=$record_type;?> Details" title="View This <?=$record_type;?> Details" border="0"></a>
			 &nbsp;<a  href="javascript:void(0);" onclick="javascript:window.open('<?=$script_name;?>?id=edit&recordID=<?=$arr[memberID];?>&offset=<?=$offset;?>&pageno=<?=$pageno;?>&status=<?=$status;?>#bot','popup','scrollbars=yes,width=700,height=500')"><img src="<?=SITE_ADMIN_URL?>/images/edit.gif" alt="Edit This <?=$record_type;?>" title="Edit This <?=$record_type;?>" border="0"></a>
			 <? if($arr[status]!='D') { ?>
			 &nbsp;<a href="<?=$script_name;?>?id=delete&recordID=<?=$arr[memberID]?>&start=<?=$start?>&pagesize=<?=$pagesize?>" onClick="return confirm('Are you sure you want to delete this record')"><img src="<?=SITE_ADMIN_URL?>/images/cancel.gif" alt="Delete This <?=$record_type;?>" title="Delete This <?=$record_type;?>" border="0"></a>
			 <? } ?>
			 <?
			 if ($arr[status]=="Y") {
				 ?>
				 <br/><br/>
				 <form name="membership_form<?=$arr[memberID];?>" action="" method="POST">
				 <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0" valign="top">			  
				  <tr>
				   <td align="left"><strong>Set Member As</strong><br/>
				    <select name="planType">
				     <option value="1" <? if($arr[membershipType]=="1"){ echo "selected";}?>><?=getmembershipPlanName(1);?></option>
				     <option value="2" <? if($arr[membershipType]=="2"){ echo "selected";}?>><?=getmembershipPlanName(2);?></option>
				     <option value="3" <? if($arr[membershipType]=="3"){ echo "selected";}?>><?=getmembershipPlanName(3);?></option>
				     <? if($arr[membershipType] < 4) { ?>
				     <option value="4" <? if($arr[membershipType]=="4"){ echo "selected";}?>><?=getmembershipPlanName(4);?></option>
				     <? } ?>
				    </select>
				   </td>
				  </tr>
				  <tr>
				   <td align="left"><strong>Set Expiry Date<br/></strong><input type="text" name="expiryDate" id="expiryDate" size="12" maxlength="12" value="<?=$expiryDate;?>" class="txtfieldadmin" readonly="readonly" />&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.membership_form<?=$arr[memberID];?>.expiryDate);return false;" ><img name="popcal" align="absmiddle" src="../js/calendar1/themes/Normal/calbtn.gif" width="34" height="22" border="0" alt=""></a></td>
				  </tr>
				  </tr>
				  <tr>
				   <td align="left">
				    <input type="submit" name="submit" value="Update" class="button" />
				    <input type="hidden" name="action" value="update_membership" />
				    <input type="hidden" name="recordID" value="<?=$arr[memberID];?>" />
				    <input type="hidden" name="keyword" value="<?=$keyword;?>" />
				    <input type="hidden" name="status" value="<?=$status;?>" />
				    <input type="hidden" name="pagesize" value="<?=$pagesize;?>" />
				   </td>
				  </tr>
				 </table>
				 </form>
				 <?
			 }
			 ?>
			</td>
		 </tr>
		 <?
		 $sl++;
	 }
	 ?>	 
	</table><br>
	<iframe width=174 height=189 name="gToday:normal:agenda.js" id="gToday:normal:agenda.js" src="../js/calendar1/themes/Normal/ipopeng.htm" scrolling="no" frameborder="0" style="visibility:visible; z-index:999; position:absolute; top:-500px; left:-500px;"></iframe>
	<?
}
else{
	?>
	<table width="100%"  border="0" cellpadding="6" cellspacing="2" class="lightBorder">
	 <tr><td><br /><b>No Record Found.............</b><br /><br /></td></tr>
	</table>
	<?
}

admin_footer();	
exit;
?>