<?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(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}


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($_POST['gotoPage']))
{

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


	$qryopt="";

	if(isset($_POST['cmbSearchType']) && $_POST['cmbSearchType']!="all")
	{
	
		$qryopt = " AND report.nreport_product_id = ".$_POST['cmbSearchType'];
	
	
	}
	
	$sql = " SELECT pr.product_name,report.nproduct_view_count,usr.first_name,usr.last_name
		 	 FROM ".$tableprefix."products pr,".$tableprefix."report_product report,".$tableprefix."users usr
		   	 WHERE pr.product_id = report.nreport_product_id 
		     AND report.nreport_customerid = usr.user_id " . $qryopt . " 
		     ORDER BY pr.product_name,report.dproduct_view_date 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);


		   
		   
/*$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.frmProductViewed.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 PRO_VIEW;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
            		<br>
											
					<div align="left">
					
					<form action="" method="post" name="frmProductViewed">


					
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
											<tr><td height="35"><?php include_once("../includes/reportmenu.php")?></td>
			</tr>
								<tr>
									<td width="100%" align=left valign="bottom" class=''><?php echo PRODUCT;?> ::
									<select class="textarea2" name="cmbSearchType" >
									<option value="all"><?php echo ALL_PRODUCTS;?></option>
<?php

	$select_product = "SELECT pr.product_id,pr.product_name 
					   FROM ".$tableprefix."products pr,
						".$tableprefix."report_product report 
					   WHERE pr.product_id = report.nreport_product_id 
					   GROUP BY report.nreport_product_id ORDER BY pr.product_name ASC";
	$result_product = mysql_query($select_product) or die(mysql_error());
	
	if(mysql_num_rows($result_product) != 0)
	{
	
		while($product_row = mysql_fetch_array($result_product))
		{
		
			if($product_row['product_id'] == $_POST['cmbSearchType'])
			{
			
				$product_checked = "selected";
			
			}
			else
			{
			
				$product_checked = "";
			
			}
		
?>		
									
									<option value="<?php echo $product_row['product_id']?>" <?php echo $product_checked?>><?php echo stripslashes($product_row['product_name'])?></option>
								
								
<?php	

		}

	}

?>		
									</select>
										&nbsp;
										<a onClick="return clickSearch();" class="search_button"><?php echo BTN_SEARCH; ?></a>
								  </td>
								</tr>
							</table>
						
			</form>
			
			</div>
										
			<div align="left">
										
					
				
				<form action="" method="post" name="frmProductViewed1">
							<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
								<tr class="form_header">
									<th width="6%" align="center" valign="middle">#</th>
									<th width="33%" align="left" valign="middle"><?php echo PRODUCT_NAME;?></th>
									<th width="29%" align="left" valign="middle"><?php echo CUSTOMER;?></th>
									<th align="center" valign="middle" colspan="3"><?php echo PRO_VC;?></th>
								</tr>
<?php
$i = 1;

if(mysql_num_rows($result) > 0 )
{
	while($row = mysql_fetch_array($rs))
	{
																													
?>
								<tr>
									<td align="center" valign="middle"><?php echo (($page*$limit)+$i-$limit)?></td>
									<td align="left" valign="middle"><?php echo stripslashes($row["product_name"])?></td>
									<td align="left" valign="middle"><?php echo $row["first_name"]."&nbsp;".$row["last_name"]?></td>
									<td align="center" valign="middle" colspan="3"><?php echo $row["nproduct_view_count"]?>&nbsp;<?php echo TIME."(".S.")";?></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']."?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']."?page=$pagenext alt='Next' border='0' class='small_gray_button'>".TEXT_NEXT."</a>";
	
}	
	
																				
?>
										<tr>
										  <td class="page_nos" colspan="3" align="center">&nbsp;</td>
										  <td width="16%" align="right" valign="middle" class="page_nos">&nbsp;</td>
										  <td width="16%" align="left" valign="middle" class="btn_gotbl">&nbsp;</td>
							  </tr>
										 <?php
							  if($page < $numofpages || $page > 1)
							  {
							  ?><tr>
											<td class="page_nos" colspan="5" align="right">
												<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="padding:4px 5px; margin-bottom:1px; ">
  <?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.frmProductViewed1.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";
?>


