<?php session_start();  //Developed by ITechScripts
require 'include/configurations.php'; // ITECHBIDS Configuration File
require 'include/header.php';
//clean duration
$query ="select * from genaralsettings where set_id = 20 ";
$tab=mysql_query($query);
if($row=mysql_fetch_array($tab))
$cleanup_duration = $row['set_value'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Admin</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>
<body>
<table align="center" width="100%" height="35" class="ft" heught=25">
<tr><td align="center"><strong>Old Item Clean Up</strong></td></tr>
</table>

<?

$page_query="select * from genaralsettings where set_id=22";
$page_table=mysql_query($page_query);
if($page_row=mysql_fetch_array($page_table));
$page_length=$page_row['set_value'];
{

   $check=$_REQUEST['check1']; 
   $delete1=$_REQUEST['delete1'];
   $deleteall1=$_REQUEST[deleteall1];
 
   if(($delete1==1)&&(count($check)!=0))
   {  
      $w=0; 
      foreach($check as $mycheck)
      {	
        $w++;
        $del="delete from auction_details where productid=$mycheck";
       $res=mysql_query($del);
      }
	  echo "<br> <font color='#ff0000' ><strong> $w Rows Deleted On Successfully ! </strong></font> ";
   } 
   
   
   if(($deleteall1==1))
   {  
         $del="delete from auction_details where status='closed' and (to_days(now()) - to_days(expire_date) >$cleanup_duration)";
         if($res=mysql_query($del))      
	    echo "<br> <font color='#ff0000' ><strong> All	 Rows Deleted On Successfully ! </strong></font> ";
   } 

}
?>
<form name="myform" method="post" action="<?= $_SERVER['php_self'] ?>" >
<?
$query="select * from auction_details where status='Closed' and (to_days(now()) - to_days(expire_date) >$cleanup_duration)  ";
$tab=mysql_query($query);
?>
<?
if(mysql_num_rows($tab)==0)
{
 echo "<table width=100% >";
 echo "<tr  height=30 ><td  align=center >";
 echo "<strong> No Rows Selected <strong>";
 echo "</td></tr>";
 echo "<tr><td colspan=7 >";
 require 'include/footer.php';
 echo "</td></tr>";
 echo "</table>";
 exit();
}

?>


<?

$total=mysql_num_rows($tab);
$totalx=($total/$page_length);

$reminder=($total%$page_length);
settype($totalx,'int');

if(($reminder==0)&&($total!=0))
$totalx=$totalx-1;

$set=$_REQUEST['set'];
if($set=="")$set=0;
$href ="cleanup.php?";

$href.="&set=";
?>
<table width="60%" align="center">
<tr><td colspan="8" align="center" >
<b>There are <?= $total; ?> Rows Selected.</b>
</td>
<td>
<? if($set!=0){ ?>  <a href="<?=$href.($set-1) ?>  style="text-decoration:none"  id="link1"">  <? }?>    Prev <? if($set!=0) {?> </a>  <? }?>
</td><td>
<? if($set!=$totalx){ ?>  <a href="<?=$href.($set+1) ?>  style="text-decoration:none"  id="link1"">  <? }?>     Next  <? if($set!=$totalx) {?> </a> <? }?>

</td></tr>
</table>
<table align="center" width="80%" class="ft">
<tr class="ct" height="25">
<td width="4%">&nbsp;</td>
<td align="center">Item Id</td>
<td align="center">Item Name</td>
<td align="center">Seller Name</td>
<td align="center">Quantity </td>
<td align="center">Expire Date</td>
<td align="center">Location</td>
</tr>
<?
$start= $set*$page_length +1;
$end=$set*$page_length +$page_length;
$i=0;
while($row=mysql_fetch_array($tab))
{
$i++;
if(($i<$start)||($i>$end))
continue;
?>
<tr >
<td><input name="check1[]" id="chkSub" type="checkbox" class="check" value="<?php echo $row['productid'];  ?>"></td>
<td><?= $row['productid']; ?></td>
<td><?= $row['producttitle']; ?></td>

<?
$queryx="select * from member_details where user_id ='$row[user_id]'";
$tabx=mysql_query($queryx);
if($rowx=mysql_fetch_array($tabx));
$user_name=$rowx['user_name'];

?>
<td><?= $user_name ?></td>
<td><?= $row['Quantity']; ?></td>
<td><?= $row['expire_date']; ?></td>
<?
$item_sql="select * from auction_details where productid=".$row['productid'];
$item_res=mysql_query($item_sql);
$item_row=mysql_fetch_array($item_res);
$item_sqll="select * from member_details where user_id=".$item_row['user_id'];
$item_ress=mysql_query($item_sqll);
$item_roww=mysql_fetch_array($item_ress);
if($rowx['country'])
{
$item_country="select * from site_countries where country_id=".$rowx['country'];
$country=mysql_query($item_country);
$country_row=mysql_fetch_array($country);
}

?>	
<td><?= $country_row['country'] ?></td>



</tr>
<?
}
?>
<tr>
    <td colspan="8" >
      <input type="hidden" name="del" value="1">
	  <? echo $row['productid']; ?>
      <input type="hidden" name="del_id" value="<?php echo $row['productid']; ?>">
      <input type="hidden" name="delete1" value=0>	
	  <input type="hidden" name="deleteall1" vlalue=0 >
	  <input type="button" name="delete" value="Delete"   onclick="mydel()" >
	  <input type="button" name="delete_all" value="Delete All"   onclick="mydelall()" >
    </td>
</tr>

</table>
</form>

</body>
<?
require 'include/footer.php';
?>
</html>
<script language="javascript">
function mydel()
{
  var where_to= confirm("Are U Sure U Want to delete the items?");
  if (where_to== true)
  {
    document.myform.delete1.value=1;
    document.myform.submit();
  }
  else
  {
    window.location="cleanup.php";
    document.myform.submit();
  } 
}

function mydelall()
{
  var where_to= confirm("Are U Sure U Want to delete the items?");
  if (where_to== true)
  {
    document.myform.deleteall1.value=1;
    document.myform.submit();
  }
  else
  {
    window.location="cleanup.php";
    document.myform.submit();
  } 
}

</script>