<?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";
include_once "../classes/cls_user.php";
include_once "../classes/cls_store.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;
}





//echo $cmbSearchType;
$cmbSearchType = $_REQUEST["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




if (isset($_POST['gotoPage'])) {

	header("Location:" . $_SERVER['PHP_SELF'] . "?page=" . $_POST['gotoPage'] . "&msg=" . $message);
	exit;
}


//echo $cmbSearchType;



$qryopt = "";

$searchCriteria =   "";

if($cmbSearchType!='')
    {
        if($cmbSearchType=="all")
            {
            $qryopt     =   "";
        }else{

            $searchCriteria = "ip_address=".$cmbSearchType;
            
            $qryopt     =   "WHERE ip_address='".$cmbSearchType."' ";
        }

 }

 $sql = " SELECT u.*
		FROM " . $tableprefix . "users u " . $qryopt . "  order by user_id DESC  ";


if (!(isset($pagenum))) {
	$pagenum = 1;
}

$limit = getSettingsValue('npagination_limit');

$page = isset($_GET['page']) ? trim($_GET['page']) : 1;


if (empty($page)) {
    $page = 1;
}

$result = mysql_query($sql) or die(mysql_error());

$totalrows = mysql_num_rows($result);

$limitvalue = ($page - 1) * $limit;

$query_string = " LIMIT $limitvalue, $limit";

$sql = $sql . $query_string;

$rs = mysql_query($sql) or die(mysql_error());

$numofpages = ceil($totalrows / $limit);


//List all Ip Address

$ip_array_list  =   User::getAllIpAddress();




/* $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,2,2,"&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 = "<?php echo DISABLE; ?>";
        }else{
            changeto = "<?php echo ENABLE; ?>";
        }//alert(status);
        
        //alert(changeto);
        if(confirm("<?php echo ARE_YOU_SURE_YOU_WANT_TO;?>"+ changeto +"<?php echo THIS_USER;?>")){
            frm.postback1.value="CS";
            frm.uid.value=id;
            frm.changeto.value=status;
            frm.submit();
        }

    }
</script>

<body>
	<center>

		<div align="left" id="layout">


			<!--header area start -->
			<?php
			include_once("../includes/topheader_admin.php")
			?>

			<!--header area end -->


			<div align="left" class="main_body">
				<!--main body start -->

				<?php
				include_once("../includes/admintopmenu.php")
				?>


				<div align="left" class="content_area">

					<!--content area start -->
					<div align="left" class="page_title">
						<?php echo MENU_USER_IP_ADDRESS;?>
					</div>
					<div align="center" class="text_information grey_tr">
						<?php echo $message ?>
					</div>
					<br>

					<div align="right">
						<form action="" method="post" name="frmUsers">
							<table width="100%" border="0" cellpadding="0" cellspacing="0"
								class="manage_top">
								<tr>
                                                                    <td width="55%" align="left" valign="middle" class=""><select
										class="textarea" name="cmbSearchType">
											<option value="all" <?php if($cmbSearchType=="all") {  echo "selected" ; } ?>>
												<?php echo ALL_IP_ADDRESS;?>
											</option>
											<?php foreach($ip_array_list as $ipObj) {
                                                                                            ?>
                                                                                        <option value="<?php echo $ipObj->ip_address?>" <?php if($cmbSearchType==$ipObj->ip_address) {  echo "selected" ; } ?>>
												<?php echo $ipObj->ip_address?>
											</option>
                                                                                        <?php
                                                                                        }
                                                                                        ?>
									</select> &nbsp;  <a
										style="cursor: pointer" onClick="javascript:clickSearch();" class="search_button"><?php echo BTN_SEARCH; ?></a>
									</td>


								</tr>
							</table>
						</form>
					</div>

					<div align="right">

						<form action="" method="post" name="frmUsers1">

							<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table" >
                                                            
                                                         <?php if($totalrows>0) { ?>   <tr><td colspan="6" align="right"><b><a href="user_ip_info_export_csv.php?<?php echo $searchCriteria;?>"><?php echo USER_IP_EXPORT_CSV;?></a></b></td></tr> <?php  } ?>

								<tr class="form_header">
									<th width="5%" align="center" valign="middle">#</th>
									<th width="19%" align="right" valign="middle"><?php echo NAME;?>
									</th>
									
									<th width="19%" align="right" valign="middle"><?php echo EMAIL;?>
									</th>
									<th width="25%" align="center" valign="middle"><?php echo REG_DATE;?>(<?php echo MM."/".DD."/".YYYY;?>)</th>
									<th width="10%" align="center" valign="middle" ><?php echo USER_IP_ADDRESS;?></th>
                                                                        <th width="25%" align="center" valign="middle" ><?php echo USER_IP_LOCATION;?></th>
									
								</tr>


								

								<?php
								$i = 1;

								if (mysql_num_rows($result) > 0) {

                                while ($row = mysql_fetch_array($rs)) {


                                    // Check seller account activated for this seller 
                                   
                                    $link = "<a class=links href='#'>";

                                   

                                    if (!empty($row["user_name"])) {
                                        ?>

								<tr>
								<td align="center" valign="middle"><?php echo (($page * $limit) + $i - $limit) ?> </td>
									
									<td align="right" valign="middle"><?php echo  ($row["first_name"] . " " . $row["last_name"]) . " &nbsp;(".$row["user_name"] . ")" ; ?>
									</td>
									<td align="right" valign="middle"><?php echo ($row["email"]) ; ?>
									</td>
									<td align="center" valign="middle"><?php echo  dateFormat($row["date_registered"], "Y-m-d", "m/d/Y"); ?>
									</td>
									<td  align="center" valign="middle"><?php echo  htmlentities($row["ip_address"]); ?>
									</td>
                                                                       
                                                                        <td  align="center" valign="middle"><?php echo  htmlentities($row["ip_location"]); ?>
									</td>
								</tr>
								<?php
        }

        $i++;
    }
} else {
    ?>

								<tr>
									<td align="center" valign="middle" colspan="7"
										class="text_information"><?php echo NO_RECORDS_FOUND;?> !!</td>
								</tr>




								<?php
}


if ($page > 1) {
    $pageprev = $page - 1;

    $previous_page = "<a href=" . $_SERVER['PHP_SELF'] . "?rghtMenu=" . $_GET["rghtMenu"] . "&page=$pageprev alt='Previous' border='0' class='small_gray_button'>".TEXT_PREV."</a>";
}


if ($page < $numofpages) {
    $pagenext = ($page + 1);

    $next = "<a href=" . $_SERVER['PHP_SELF'] . "?rghtMenu=" . $_GET["rghtMenu"] . "&page=$pagenext alt='Next' border='0' class='small_gray_button'>".TEXT_NEXT."</a>";
}
?>
								<tr>
									<td align="right" valign="middle" class="page_nos">&nbsp;</td>
									<td align="left" class="btn_gotbl" valign="middle">&nbsp;</td>
									<td class="page_nos" colspan="4" align="center">&nbsp;</td>
								</tr>
								<?php
								if ($page < $numofpages || $page > 1) {
                                ?>
								<tr>
									<td colspan="6" align="left" valign="middle">
									
									<table width="100%" border="0" cellspacing="10" cellpadding="0">
									  <tr align="left" valign="middle">
										<td width="21%" align="right"><?php echo $previous_page ?></td>
										<td width="23%" align="right">
											<?php echo PAGE."(".S.")";?>
											<?php echo $page ?>/<?php echo $numofpages ?>&nbsp;&nbsp;<?php echo GO_TO;?>
										</td>
										<td width="8%" align="right">
											<select class="textarea2" name="gotoPage" style="margin-bottom:1px; padding:4px 5px; ">
												<?php
												for ($i = 1; $i <= $numofpages; $i++) {
													if ($i == $_GET['page']) {
														$page_selected = "selected";
													} else {
														$page_selected = "";
													}
												?>
												<option value="<?php echo $i ?>" <?php echo $page_selected ?>>
													<?php echo $i ?>
												</option>
	
												<?php
												}
												?>
											</select>
										</td>
										<td width="7%">
											<a onClick="Javascript:document.frmUsers1.submit();" class="go_button_2"><?php echo GO; ?></a>
										</td>
										<td width="41%" align="center"><?php echo $next ?></td>
									  </tr>
									</table>
										
									</td>
								</tr>
								<?php
                                        }
                                        ?>
							</table>

						</form>

					</div>


					<!--content area end-->

				</div>


				<div align="left" class="clear_float">
					<img src="<?php echo $imagefolder; ?>/clear.gif" alt="" width="1"
						height="1" />
				</div>
				<!--main body end -->
			</div>


			<?php
			include "../includes/footer.php";
			?>