<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

if(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}


if($_POST['postback1'] == "CS"){//for changing status
        $id=$_POST['uid'];
        $changeto=$_POST['changeto'];
        $sqlcs = "UPDATE ".$tableprefix."users  SET deleted = '$changeto' where user_id =$id  ";
        //echo $sqlcs;
         mysql_query($sqlcs);

}



if($_GET["begin"] == ""){
	$begin=0;
	$num=1;
	$numBegin=1;
}

if(isset($_GET["txtSearch"]) and $_GET["txtSearch"]!=""){
	$txtSearch = $_GET["txtSearch"];
	$cmbSearchType = $_GET["cmbSearchType"];
}else if(isset($_POST["txtSearch"]) and $_POST["txtSearch"]!=""){
	$txtSearch = $_POST["txtSearch"];
	$cmbSearchType = $_POST["cmbSearchType"];
}

if(isset($_GET["msg"]) and $_GET["msg"]!=""){
	$msg = $_GET["msg"];
	switch($msg){
		case "deleted": $message = MSG_USER_DELETED;
			break;
		default: $message = $msg;
			break;
	} // switch

}

$qryopt="";
if($txtSearch != ""){
   if($cmbSearchType == "username"){
            $qryopt .= "  WHERE  u.user_name like '" . addslashes($txtSearch) . "%'";
   }else if($cmbSearchType == "dateofregn"){
   		$dt = $txtSearch;
		$arrdt = explode("/",$dt) ;
		$day = $arrdt[1];
		$month = $arrdt[0];
		$year = $arrdt[2];
		$dt = $year."-". $month ."-".$day;
		$qryopt .= "  WHERE  u.date_registered like '" . addslashes($dt) . "%'";
   }else if($cmbSearchType == "email"){
            $qryopt .= "  WHERE  u.email like '" . addslashes($txtSearch) . "%'";
   }
}
$sql=" SELECT u.*,CASE WHEN deleted = 'N' THEN 'Yes' ELSE 'No' END AS user_active
	   FROM ".$tableprefix."users u " . $qryopt . "  order by date_registered DESC ";
$sess_back= $_SERVER["PHP_SELF"] . "?begin=" . $begin . "&num=" . $num . "&numBegin=" . $numBegin . "&cmbSearchType=" . $cmbSearchType . "&txtSearch=" . $txtSearch;
$_SESSION["gbackurl"] = $sess_back;

$totalrows = mysql_num_rows(mysql_query($sql));

$navigate = pageBrowser($totalrows,10,10,"&cmbSearchType=$cmbSearchType&txtSearch=$txtSearch",$_GET[numBegin],$_GET[start],$_GET[begin],$_GET[num]);
$sql = $sql.$navigate[0];
$rs = mysql_query($sql);

include "../includes/htmltop.php";
?>
<script language="JavaScript" type="text/JavaScript">
function clickSearch()
{
	document.frmUsers.submit();
}
function ChangeStatus(id,status){

        var frm = document.frmUsers1;
        if(status == "Y"){
                changeto = "deactivate";
        }else{
                changeto = "activate";
        }
        if(confirm("Are you sure you want to "+ changeto +" this user?")){
                frm.postback1.value="CS";
                frm.uid.value=id;
                frm.changeto.value=status;
                frm.submit();
        }

}
</script>

<body>
	<table cellpadding="0" cellspacing="0" border="0" width="100%">
		<tr>
			<td colspan="2"><?php include_once( "../includes/topheader_admin.php");?></td>
		</tr>	
		<tr>
			<td colspan="2">&nbsp;</td>
		</tr>
		<tr>
			<td width="15%" valign="top"><?php include_once("../includes/admintopmenu.php");?></td>
			<td align="center" valign="top">
			
			
<!--
	
		Multicart 2.0 Design Integration 

-->			
																					
																					
																					
																					
																						
		<table width="100%">
		<tr><td colspan="3" align="center" class="headingbig">Users</td></tr>
			<tr>
				<td width="94%">
					<!-- ***************************************************** -->
					
						<table width="98%"  border="0" cellpadding="0" cellspacing="0" class="" align="center">
						
							<tr>
								<td class="listingborder">
									<table width="100%"  border="0" cellpadding="2" cellspacing="1" class="maintext">
										<tr align="center" class="whitebg">
											<td align="center" colspan="6" class="message"><?php echo $message?></td>
										</tr>
										<form action="" method="post" name="frmUsers">
										<tr class="whitebg" valign="top">
											<td align="right" colspan="6" valign="top" >
											
												<table width="100%" border=0  >
													<tr>
														<td width="100%" align=right valign="baseline" class=''>Search ::
															<select name="cmbSearchType" class="textbox">
																<option value="username"  <?php if($cmbSearchType == "username" || $cmbSearchType == ""){ echo("selected"); } ?>>User Name</option>
																<option value="email"  <?php if($cmbSearchType == "email"){ echo("selected"); } ?>>Email</option>
																<option value="dateofregn"  <?php if($cmbSearchType == "dateofregn"){ echo("selected"); } ?>>Date of Regn (mm/dd/yyyy)</option>
															</select> &nbsp;
															<input type="text" name="txtSearch" size="20" maxlength="50" value="<? echo(htmlentities($txtSearch)); ?>"  onKeyPress="if(window.event.keyCode == '13'){ return false; }" class="textbox">
															&nbsp;
															<a href="javascript:clickSearch();" class="search_button"><?php echo BTN_SEARCH; ?></a>&nbsp;
														</td>
													</tr>
												</table>

											</td>
										</tr>
										</form>

										<tr class="whitebg"><td align="left" colspan="5"><?php echo("Listing $navigate[1] of $totalrows results."); ?></td></tr>
										<tr><td colspan="6">
										<form action="" method="post" name="frmUsers1">
										<table BORDER="0" width="100%" class='boxborder'>
										<tr class="whitebg">
											<td width="5%">#</td>
											<td width="20%" class=boxalternatecolor2>Login Name</td>
											<td width="10%">Name</td>
											<td width="9%">Email</td>
											<td width="28%" class=boxalternatecolor>Date of Regn (mm/dd/yyyy)</td>
											<td width="28%">Active</td>
										</tr>

					<input name="postback1" type="hidden" id="postback1">
					<input name="uid" type="hidden" id="uid">
					<input name="changeto" type="hidden" id="changeto">

										<?php
										$i=$begin+1;
										while($row = mysql_fetch_array($rs)){
											$link = "<a class=links href='edituser.php?userid=".$row["user_id"]."' class='smalllink'>";

											if($row["deleted"] == "N"){
													//$statusimg = "cross.gif";
													$changestatuslink = "ChangeStatus(".$row["user_id"].",'Y');";
											}else{
													  //$statusimg = "tick.gif";
													  $changestatuslink = "ChangeStatus(".$row["user_id"].",'N');";
											}
											$link1 = "<a class=links href=\"#\" class='smalllink' onclick=\"$changestatuslink\">";


										?>
										<tr class="whitebg">
											<td><?php echo $i?></td>
											<td align="left" class=boxalternatecolor2><?php echo $link .htmlentities($row["user_name"])."</a>";?></td>
											<td align="left"><?php echo $link .htmlentities($row["first_name"]." ". $row["last_name"] )."</a>";?></td>
											<td align="left"><?php echo $link .htmlentities($row["email"])."</a>";?></td>
											<td align="center" class=boxalternatecolor><?php echo $link .dateFormat($row["date_registered"], "Y-m-d", "m/d/Y")."</a>";?></td>
											<td align="left"><?php echo $link1 .htmlentities($row["user_active"])."</a>";?>&nbsp;</td>
										</tr>
										<?php
										$i++;
										}


										?>

										<tr class="whitebg"><td align="center" colspan="7"><?php echo($navigate[2]); ?></td></tr>
										<tr class="whitebg"><td align="center" colspan="7">&nbsp;</td></tr>
										</table>
										</form>
										</td></tr>
									</table>
								</td>
							</tr>
						</table>

					<!-- ***************************************************** -->
				</td>
			</tr>
		</table>


<!--

Multicart 2.0 Upgradation starts

-->				



</td>
</tr>
</table>
</td>
</tr>
</table>  	
															
															
<!--
	
		Multicart 2.0 Design Integration 

-->											
																									
																									
		</td>
		</tr>
		<tr>
			<td colspan="2">&nbsp;</td>
		</tr>
		<tr>
			<td colspan="2"><?php include_once("../includes/adminbottommenu.php");?></td>
		</tr>
		<tr>
			<td colspan="2">&nbsp;</td>
		</tr>
		<tr>
			<td colspan="2"><?php include_once("../includes/footer.php");?></td>
		</tr>
	</table>
</body>
<html>