<?php
include "chkuser.php";
include "includefilemng.php";

$perpage=10;
$serchstr='';
$searchsql='';
$strSearch='';
if((isset($_POST['searchtext'])) || (isset($_GET['searchtext'])))
			{
			if(isset($_POST['searchtext']))
			{
			$searchtext = $_POST['searchtext'];
			}
			else
			{
			$searchtext = $_GET['searchtext'];
			}
			if(strlen(trim($searchtext)) >0)
			{
			$strSearch = " WHERE email LIKE '%" . $searchtext. "%' ";
			$str = "&searchtext=$searchtext";
			}
			}
			else
			{
			$searchtext = "";
			}

if(isset($_REQUEST['page'])){
$serchstr.="&page=".$_REQUEST['page'];
$serchstr.="&perpage=".$_REQUEST['perpage'];
}



if(isset($_REQUEST['search'])){

if(isset($_REQUEST['payment']) && strlen($_REQUEST['payment'])>0 ){
$serchstr.="&payment=".$_REQUEST['payment'];
$searchsql.=" AND od.pay ='".$_REQUEST['payment']."'";
}

if(strlen($searchsql)>5){
$searchsql=substr($searchsql,4,strlen($searchsql));
$searchsql="WHERE ".$searchsql;
}
if(strlen($serchstr)>2){
$serchstr="&search=1".$serchstr;
}



}
//$searchsql="WHERE dd.id is null";

$TABLE_NAME="subscribedusers     pg

 ";

$FIELD_SELECT=" distinct pg.id as id ,
pg.email,
pg.name 
 ";

$ORDER_BY=" ORDER BY pg.id desc  ";
$WHERE_CLOUSE=$searchsql. $strSearch;


// end urlstr 
function del_real($delid)
	{
	
	$pdel="delete from subscribedusers  where id='$delid'";
	$rdel=mysql_query($pdel);
	$errormsg = "Record deleted";
	}
if (isset($_POST['delete']))
{
	$del_all=$_POST['chk'];
	
	$j= 0;
	for($i=0;$i<count($del_all);$i++)
	{
		if(is_numeric($del_all[$i]))
		{
			$orderid = $del_all[$i];
			del_real($orderid);
					
			
			$j = $j +1;
		}
	}
	$rmsg = $j ." records deleted";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Control Panel </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="ssi.css" rel="stylesheet" type="text/css">
<script src="includenp/functions.js"></script>
<script language="javascript">

function docheck() 
{
	var abc = confirm("Do you really want to delete this record?");
	
if(abc) {
	
	} else {
		return false;
	}
}
function openSWIN()
{
popwin = open("",'NewWin','height=500,width=500,toolbars=no,menubar=no,scrollbars=yes') 
}				
function openIWIN()
{
popwin = open("",'NewWin','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=632,height=370,left = 362,top = 234') 
}				
</script>
</head>
<body>
<table width="98%" border="0" cellspacing="0" cellpadding="2" align="center">
  <tr>
    <td width="1%"  bgcolor="#C9C9C9"></td>
	<td width="98%"><?php include_once "top.php";?></td>
	<td width="1%"  bgcolor="#C9C9C9"></td>
  </tr>
  <tr>
   <td width="1%"  bgcolor="#C9C9C9"></td>
    <td width="98%"><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="centertable">
      <tr>
        <td><table width="80%"  border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="59%" height="50"></td>
            <td width="41%"><form  method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
			<span class="bigblueTxt">Search By  Email:</span>
			<input name="searchtext" type="text" class="inputBOX" id="searchtext2" value="<?php if(isset($searchtext)){ echo $searchtext;} ?>">
			<input name="search" type="submit" class="hbutton" id="search2" value="Search">
			</form></td>
          </tr>
          <tr>
            <td colspan="2"><?php 

		  if(isset($errormsg))
		  	{
				echo display_error_msg($errormsg);
		   	}
			?>
			
            </td>
          </tr>
          <tr>
            <td colspan="2">
              <table width="100%"  border="0" cellpadding="2" cellspacing="0">
              
                  <tr>
                    <td width="100%" align="center">
			<?php 
			$sqln=$SQL_QUERY=" SELECT * FROM ".$TABLE_NAME.$WHERE_CLOUSE;
			$resultn = mysql_query($sqln,$eclipse); 
			$numrows = $row = mysql_num_rows($resultn);
     			if($numrows > 0 )
				{
				?>
				<form action="<?php echo $_SERVER['PHP_SELF'];?>?<?php echo $serchstr;?>" method="post"  name="form1" ID="form1">
				
				<TABLE class=table cellSpacing=3 cellPadding=3 width="98%" align=center border=0>
                      <TR valign="top" class="thbg">
                      <TH height="20" colspan="2" align="center" class="bluebold">Delete</TH>
					  <TH width="21%" align="center" class="bluebold">Edit</TH>
					 
					  <TH width="19%" align="center"  class="bluebold"> Name <br>
					    </TH>
					  <TH colspan="2" align="center"  class="bluebold">Email</TH>
					  </TR>
			 <?php	
			if(!isset($_GET['page'])){$_GET['page']=1;} 
			if (!isset($recordstart)) {$recordstart=1;}
			
			$recordstart = ($_GET['page']-1)*$perpage; 
			
		 	 if(isset($_GET['page']))
			 {
		     $itk = ($_GET['page']* $perpage) - $perpage + 1;
		 	 }
			 	
			 /*$sql = "SELECT
			 * from products";*/
			 
			 $sql=$SQL_QUERY=" SELECT ".$FIELD_SELECT."  FROM ".$TABLE_NAME.$WHERE_CLOUSE.$ORDER_BY."LIMIT $recordstart,$perpage";
			 $result = mysql_query($sql); 
			
			 while ($row = mysql_fetch_array($result))
			 {								
			 extract($row); 					 
			 ?>
                    <TR valign="top" class="trbg">
                      <TD colspan="2" align=center>
                        <input name="chk[]" type="checkbox" id="chk[]" value="<?php  echo $id;?>" size="4">
                        </TD>
					  <TD align=center><a href="edituser.php?editid=<?php echo $id; ?><?php echo $serchstr;?>">
                        
                        <img src="panelimages/b_edit.png" width="16" height="16" border="0"></a></TD>
					 
					  <TD align="center" class="normalTxt"><?php
					 
						  echo $name;
					
					  ?></TD>
					  <TD colspan="2" align="center" class="normalTxt"><?php
					
					  echo $email ;?></TD>
					  <?php
				}
				
				?>	
				 </TR>
                    <TR valign="top" class="trbg">
                      <TD width="12%" align=center><a href="JavaScript:checkAll(document.form1)" class="normalLink">Check all</a> </TD>
                      <TD width="16%" align=left><a href="JavaScript:uncheckAll(document.form1)" class="normalLink">Uncheck all</a> </TD>
                      <TD align=center><span class="normalTxt">
                        <input name="delete" type="submit"   class="hbutton" id="delete2" value="DELETE SELECTED" onClick="return docheck()">
                      </span></TD>
                      <TD colspan="2" align=left><span class="normalTxt">
                      </span></TD>
                      <TD width="19%" colspan="2" align="center" class="normalTxt">&nbsp;</TD>
                      </TR>	
                </TABLE>
				</form>
				
<?php 
$query=$sqln;
$result = mysql_query($query); 
$totalreturned = mysql_num_rows($result); 
$pagecount = ceil($totalreturned/$perpage);     
$recordstart = ($_GET['page']-1)*$perpage; 
echo page_records($_GET['page'],$pagecount,$recordstart,$perpage,$serchstr); 
?>
				<?php
				}
				else
				{
				?>
				
				<TABLE class=table cellSpacing=1 cellPadding=0 
                                width="100%" align=center border=0>
                 
                    <TR>
                      <TD align=center class="bluebold">No Records to view </td>
                    </TR>
                 
                </TABLE>
				<?php
				}
				?></td>
                  </tr>
           
            </table></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
    <td width="1%"  bgcolor="#C9C9C9"></td>
  </tr>
  <tr>
    <td  bgcolor="#C9C9C9" width="1%"></td>
	<td><?php include_once "footer.php";?></td>
	<td width="1%"  bgcolor="#C9C9C9"></td>
  </tr>
</table>
</body>
</html>
