<?php
session_start();
if($_SESSION[id]!="")
{
include ('dbf.php');
if (isset($_POST['delh']))
{
	$fg=mysql_query("select * from history order by ip");
	$v=mysql_num_rows($fg);
	if ($v>'500')
	{
		$fv=$v-'500';
		$fs=mysql_query("select * from history  order by ip");
		$i=1;
		while($v=mysql_fetch_assoc($fs))
		{
		if ($i==$fv)
		{
		$er=$v[ip];
		}
		$i++;
		}
		$fg=mysql_query("delete from `history` where (ip<='{$er}')");
		?>
		<script>
			window.alert("                       .500 عمليات آخر ذخيره و مابقي اطلاعات حذف شد");
		</script>
		<?php
	}
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<html dir="rtl">
<head>
<title>نرم افزار کتابداری نوین</title>
</head>
<body bgcolor="#FDE2C5">

<table width="90%" align="center" border="0">
	<tr>
		<td align="center" valign="bottom" height="70">
			<?php  include ('menu.php'); ?>
		</td>
	</tr>
</table>
<br/>
<table width="90%" align="center" border="2" style="border-color:blue">
	<tr>
		<td align="center">
			<table width="100%" align="center">
				<tr>
					<td align="center">
						<b>لیست حافظه عملیاتی</b>
					</td>
				</tr>
				<tr>
					<td align="center">
						<table width="50%" border="1" align="center" bgcolor="aqua">
							<tr align="center" style="font-family:tahoma">
								<td width="1%" title="مشاهده ریز مشخصات حافظه">--</td>
								<td width="5%">ردیف</td>
								<td width="15%">تاریخ</td>
								<td  width="10%">تعداد مراجعین</td>
							</tr>
							<?php
							$color=array('#488AC7','#BBD9EE'); $a=0;
							$fg=mysql_query("select * from history  group by date order by date");
							$i=1;
							while($v=mysql_fetch_assoc($fg))
							{
							$fg166=mysql_query("select count(ip) as poo from history where (date='{$v['date']}') order by date");
							$v166=mysql_fetch_assoc($fg166);

								$ccode=$v['ip'];
								echo "<tr  align='center'  bgcolor=$color[$a] >
								<td><a  title='مشاهده ریز مشخصات حافظه' href='history.php?ip=".$ccode."&date=".$v['date']."'><img src='images/12.png' border='0' width='20' height='20'></a></td>
								<td>".$i."</td>";
								echo "<td>".$v['date']."</td>";
								echo "<td>".$v166['poo']."</td>";
								$i++;
								if($a==1) $a=0;  else $a=1;
							}
							?>
							<form name="ee" action="history.php" method="post">
							<tr>
								<td align="center" height="1" colspan="10" valign="top" bgcolor="aqua" title="حذف اطلاعات اضافه و نگهداري تنها 500 عمليات آخر" width="1%">
									<input type="submit" name="delh" value="بروز رساني"  style="font-family:tahoma;font-size:11pt">
								</td>
							</tr>
							</form>
						</table>
					</td>
				</tr>
				<?php
				if (isset($_GET['date']))
				{
				?>
				<tr>
					<td width="100%" align="center" height="80" valign="bottom">
						<span style="font-family:tahoma;font-size:10pt"><b>
						مشاهده حافظه مربوط به تاریخ :
						<span style="font-family:tahoma;font-size:10pt;color:red"><b>
						<?php
						echo $_GET['date'];
						?>
						</b></span>
					</td>
				</tr>
				<tr>
					<td align="center">
						<table width="50%" border="1" align="center" bgcolor="aqua">
							<tr align="center" style="font-family:tahoma">
								<td width="5%">ردیف</td>
								<td width="15%">تاریخ</td>
								<td  width="40%">نام </td>
								<td  width="40%">نام خانوادگی</td>
							</tr>
							<?php
							$color=array('#488AC7','#BBD9EE'); $a=0;
							$fg=mysql_query("select * from history  where (date='{$_GET['date']}') order by date");
							$i=1;
							while($v=mysql_fetch_assoc($fg))
							{
								echo "<tr  align='center'  bgcolor=$color[$a] >
								<td>".$i."</td>";
								echo "<td>".$v['date']."</td>";
								echo "<td>".$v['fname']."</td>";
								echo "<td>".$v['lname']."</td>";
								$i++;
								if($a==1) $a=0;  else $a=1;
							}
							?>
							<tr>
								<td colspan="10" align="center"  bgcolor="aqua">
								<table border="0">
								<tr>
								<td>
									<a href="history.php" tabindex="1" title="بازگشت">
									<img src="images/r1.png" name="Add"  border="0" width="46" height="41" >
									</a>
								</td>

								</tr>
								</table>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<?php
				}
				?>
			</table>
		</td>
	</tr>
</table>
<?php
}
else
include('index.php');
?>
</body>