<?php
require_once ("../config.inc.php");
require_once ("../includes/adminlogincheck.inc.php");
require_once ("../includes/mysql.inc.php");
require_once ("../includes/arrays.inc.php");
require_once ("../classes/users.class.php");
require_once ("../includes/Pager/Pager.php");
$message	= "";
$pages		= "";
$data		= array();
$array		= array();
$page		= isset($_REQUEST['page'])	?	trim($_REQUEST['page'])	:	"1";
$flag		= isset($_REQUEST['act'])	?	trim($_REQUEST['act'])	:	"0";

if (!isset($_REQUEST['page'])) {
	$_SESSION['api_search']	= "";
}

if (!$objDB) {
	$message	= "Unable to Locate Database Server.";
} else {
	$objU		= new users($objDB);
	if ($flag == "1") {
		$message	= "Your update was successful<br>";
	} 
	if (isset($_POST['DelNow'])) {
		$message	= $objU->delete_users($_POST);
	}
	if (isset($_POST['SearchNow'])) {
		$array		= $objU->search_users($_POST, true);
	} else {
		$array		= $objU->search_users($_SESSION);
	}
//	$array		= $objU->get_users();
	$params 	= array(
		'mode'      => 'Sliding',
		'perPage'   => PAGESIZE,
		'urlVar'    => 'page',
		'extraVars' => array(),
		'itemData'  => $array
	);
	$objP 		= & Pager::factory($params);
	$data  		= $objP->getPageData();
	
	if (empty($data))
		$message	.= "No record(s) exists.<br>";
}
include_once('title.inc.php');
?>
<script type="text/javascript" src="../scripts/calendar.js"></script>
<script type="text/javascript" src="../scripts/calendar-setup.js"></script>
<script type="text/javascript" src="../scripts/calendar-en.js"></script>
<link href="../scripts/calendar.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/jquery.autocomplete.js"></script>
<link href="../js/searchstyle.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript">
function confirm_check()
{
	var chkVar;
	for (var i = 0; i < document.form1.elements.length; i++) 
	{
		var e = document.form1.elements[i];
		if (e.name == "ids[]") 
		{
			if(e.checked==true)
			{
				chkVar=true;
			}//end if
		}//end if
	}//end for loop

	 if(chkVar==true)
	{
		 var where_to= confirm("Do you really want to delete these users for permenantly??");
		 if (where_to== true)
		 {
		   return true;
		 }
		 else
		 {
		  return false;
		  }
	}//end if
}
</script>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top" class="white"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="72%" valign="top"><?php include_once('tophtml.php');?>
			<table width="100%"  border="0" cellspacing="0" cellpadding="5">
          <tr>
            <td><table width="100%"  border="0" cellspacing="0" cellpadding="5">
              <tr>
                <td width="41%" class="headings1">User List</td>
                <td width="59%" align="right" class="headings1"><a href="manage_user.php" class="signupbuttonlink">Add New User</a></td>
              </tr>
              <tr>
                <td class="maintext">&nbsp;</td>
                <td align="right" class="maintext"><table width="70%" border="0" cellpadding="0" cellspacing="0" class="maintext">
                        <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" name="frmSearch">
						<tr>
                          <th align="left" scope="col">User</th>
                          <th align="left" scope="col">Name</th>
                          <th align="left" scope="col">Gender</th>
                          <th scope="col">&nbsp;</th>
                        </tr>
                        <tr>
                          <td scope="col"> <input name="user" id="user" type="text" maxlength="100" value="<?php echo isset($objU->arrSearch['user'])?stripslashes($objU->arrSearch['user']):""?>" class="textbox"> </td>
                          <td scope="col"><input name="name" type="text" maxlength="100" value="<?php echo isset($objU->arrSearch['name'])?stripslashes($objU->arrSearch['name']):""?>"  class="textbox"></td>
                          <td scope="col"><select name="gend" class="textbox">
                                <?php foreach ($arrGenderSearch as $keys => $values) { ?>
                                <option value="<?php echo $keys?>" <?php echo isset($objU->arrSearch['gend'])&&($objU->arrSearch['gend']==$keys)?"selected":""?>>
                                <?php echo $values?>
                                </option>
                                <?php } ?>
								 </select>	 </td>
                          <td scope="col">  <input name="imageField" type="image" class="nuller" src="../images/search.gif" width="63" height="20" border="0">                            <input type="hidden" name="SearchNow" value="SearchNow">                          </td>
                        </tr>
<script type="text/javascript">
$(document).ready(function() {
	$("#user").autocomplete("takeusernames.php", { minChars:1, matchSubset:1, matchContains:1, selectOnly:1 });
});
</script>

						</form>
                      </table></td>
              </tr>
            </table></td>
          </tr>
        </table>
		<form name="form1" method="post" action="" onSubmit="return confirm_check();">
          <table width="100%"  border="0" cellspacing="0" cellpadding="5">
            <tr>
              <td><table width="100%"  border="0" cellspacing="2" cellpadding="0">
					<?php 	if(isset($message) && $message!='')
							{
					?>
                <tr align="left">
                  <td align="center" class="maintext2">&nbsp;</td>
                  <td colspan="8" class="maintext2 warning"><?php echo $message;?></td>
                  </tr>
					<?php  	}//end if
				      if (is_resource($objDB)) 
					  { 
                 			if (!empty($data)) 
							{ 
				?>
                <tr align="left">
                  <td height="40" align="center" class="maintext2"><strong class="boldtext">#</strong></td>
                  <td class="maintext2"><strong class="boldtext">Username</strong></td>
                  <td class="maintext2"><strong class="boldtext">Name</strong></td>
                  <td class="maintext2"><strong class="boldtext">Gender</strong></td>
                  <td class="maintext2"><strong class="boldtext">Date</strong></td>
                  <td class="maintext2"><strong class="boldtext">Email</strong></td>
                  <td class="maintext2"><strong class="boldtext">Status</strong></td>
                  <td class="maintext2"><strong class="boldtext">Action</strong></td>
                  <td class="maintext2">&nbsp;</td>
                </tr>
					<?php  
							foreach ($data as $key => $value) 
							{ 
				?>
                <tr align="left">
                  <td width="3%" align="center" class="maintext2"><?php echo $key+1?></td>
                  <td width="22%" class="maintext2"><?php echo htmlspecialchars(stripslashes($value['vLogin']))?></td>
                  <td width="11%" class="maintext2"><?php echo htmlspecialchars(stripslashes($value['vFirstName']))?> <?php echo htmlspecialchars(stripslashes($value['vMiddleName']))?> <?php echo htmlspecialchars(stripslashes($value['vLastName']))?></td>
                  <td width="22%" class="maintext2"><?php echo $value['vGender']?></td>
                  <td width="14%" class="maintext2"><?php echo date("F d, Y",strtotime($value['dStartDate']))?></td>
                  <td width="14%" class="maintext2"><?php echo htmlspecialchars(stripslashes($value['vEmail']))?></td>
                  <td width="14%" align="center" class="maintext2"><?php if ($value['vStatus'] == "ANNN") echo "Active"; else if ($value['vStatus'] == "SNNN") echo "Suspended"; else if ($value['vStatus'] == "ENNN") echo "Expired";else echo "InActive";?></td>
                  <td width="14%" align="center" class="maintext2"><a href="manage_user.php?id=<?php echo $value['nUser_Id']?>&page=<?php echo $objP->getCurrentPageID()?>" class="signupbuttonlink">Edit</a></td>
                  <td width="14%" align="center" class="maintext2"><input name="ids[]" type="checkbox" value="<?php echo $value['nUser_Id']?>"></td>
                </tr>
				<?php 			}//end foreach
				?>
					                <tr align="left">
                  <td align="center" class="maintext2">&nbsp;</td>
                  <td colspan="7" class="maintext2">&nbsp;</td>
                  <td align="center" class="maintext2"><input type="submit" name="DelNow" value="Delete" class="loginbutton"></td>
                </tr>

				<?php
					 		}//end if
						}//end first if
				?>
              </table>
                <?php if(!empty($data))
					  {
				?>
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="82%">&nbsp;</td>
                    <td width="18%"><table width="100%"  border="0" cellspacing="2" cellpadding="0">
                        <tr align="center" class="textbox">
                          <?php echo $objP->links;?>
                          </tr>
                    </table></td>
                  </tr>
                </table><?php }//end if?>
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="right"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td>&nbsp;</td>
                      </tr>
                    </table></td>
                  </tr>
                </table></td>
            </tr>
          </table></form></td>
        </tr>
    </table>      
    </td>
  </tr>
</table>
<?php include_once('bottomhtml.php');?>