<?php session_start();  //Developed by ITechScripts
error_reporting(0);
$adate=$_SESSION['adate'];
$bdate=$_SESSION['bdate'];
$cdate=$_SESSION['cdate'];
$ddate=$_SESSION['ddate'];
require 'include/configurations.php'; // ITECHBIDS Configuration File
require 'include/header.php';
$val=$_GET['val'];
if($val=='')
$val='actv';
$uid=$_POST['uid'];
$amnt=$_POST['amnt'];
$pthru=$_POST['pthru'];
$mode=$_GET['mode'];
$catid=$_GET['id'];
/*Relisting items*/
if($mode=="relist")
{
$productid=$_GET[productid];
$itemsql="select * from auction_details where productid=$productid";
$itemsqlqry=mysql_query($itemsql);
$itemfetch=mysql_fetch_array($itemsqlqry);
$date=$itemfetch[expire_date];
$dur=$itemfetch[duration];
         $elts = explode("-", $date); 
         $inter=$dur*24*3600; 
         $dcour=mktime(1,0,0,$elts[1],$elts[2],$elts[0]); 
         $dres=$dcour+$inter; 
         $date1=date("Y-m-d",$dres);
         $sec=date("G:i:s");
         $ret_date="$date1"." "."$sec";
		 $expiredate=$ret_date;
$relistsql="update auction_details set expire_date='$expiredate' where productid=$productid";
$relistsqlqry=mysql_query($relistsql);
}
/*End of relisting items*/
if($mode=="Active" or $mode=="paid")
{
$productid=$_GET[productid];
$up_sql="update auction_details set status='Active' where productid=$productid";
$up_res=mysql_query($up_sql);
$msg="<b><font size=2 color=red>Updated Successfully</font></b><br>";
}
if($mode=="close")
{
$productid=$_GET[productid];
$up_sql="update auction_details set status='Closed' where productid=$productid";
$up_res=mysql_query($up_sql);
$msg="<b><font size=2 color=red>Updated Successfully</font></b><br>";
}
if($val=='exp')
$sql="select * from auction_details where status='Closed' and selling_method='ads'";
else if($val=='today')
$sql="select * from auction_details  where TO_DAYS((bid_starting_date))=TO_DAYS( NOW( )) and selling_method='ads' ";
else if($val=='actv')
$sql="select * from auction_details  where status='Active' and selling_method='ads' ";
else if($val=='sold')
$sql="select * from auction_details where quantity_sold > 0 and selling_method='ads'";
else if($val=='unpaid')
$sql="select * from auction_details where status='new' and selling_method='ads'";

$res=mysql_query($sql);
$id=$_POST['id'];
if(isset($_POST['btn_release']))
{
$coid=$_POST['chkSub'];
foreach($coid as $cnid)
{
$masql="delete from auction_details where productid=$cnid";
$mares=mysql_query($masql);
$masql="delete from site_bids where productid=$cnid";
$mares=mysql_query($masql);
$masql="delete from watch_list where productid=$cnid";
$mares=mysql_query($masql);
$masql="delete from featuredproducts where productid=$cnid";
$mares=mysql_query($masql);
$message="Items deleted sucessfully";
}
}
?>
>
<style type="text/css">
<!--
.style1 {
	color: #666666;
	font-weight: bold;
}
.style3 {color: #666666; font-size: 11px; font-family:Arial, Helvetica, sans-serif}
-->
</style>
<table align="center" width="95%" height="35">
 <? require 'include/search.php' ?>
  <tr class="ft" heught=25">
    <td width="10%" align="center"><a href="auction.php" id="link3">Simple Auction </a></td>
    <td width="13%" align="center"><a href="dutch_auction.php" id="link3"> Dutch Auction </a></td>
    <td width="18%" align="center"><a href="fixed.php" id="link3">Fixed Price Sale </a></td>
    <td width="12%" align="center"><a href="classified.php" id="link3">Classified Ads</a></td>
  </tr>
</table>
 <? if($msg)
  {
  ?>
 <table width="100%"> <tr align="center"><td colspan="2"><br> <?=$msg;?> </td></tr></table>
  <?
  $msg="";
  }
  ?>
 
<form name="frm1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> 
  <table align="center" width="60%"> 
    <tr> 
      <td align="center"><a href="classified.php?val=today" id="tablink">New Items</a></td> 
      <td align="center"><a href="classified.php?val=actv" id="tablink">Live Items</a></td> 
	  <td align="center"><a href="classified.php?val=unpaid" id="tablink">Unpaid Items</a></td> 
 <!--      <td align="center"><a href="classified.php?val=sold" id="tablink">Sold Items</a></td> -->
      <td align="center"><a href="classified.php?val=exp" id="tablink">Expired Items</a></td> 
	 </tr> 
  </table> 
  <table align="center" width="80%" class="ft"> 
    <tr class="ct" height="25"> 
      <td height="24" colspan="9">
	  <? if($val=='today') echo 'New ';else if($val=='actv') echo 'Active ';else if($val=='sold') echo 'Sold';else if($val=='exp') echo 'Expired ';?> Items</td> 
    </tr> 
    <tr class="ct" height="25"> 
      <td width="4%"><input type="checkbox" name="chkMain" onClick="chkall();" class="check" value=1></td> 
      <td width="23%">Item Name</td> 
     <!--	  <td width="23%">
	  <? if($val!="sold") echo "Buy Now Price"; else if($val=="sold") echo "Sold Amount"; ?> </td>  -->
	  
      <td width="25%">Seller</td> 
     
	  <td width="13%">
	   <? if($val!="sold") echo "Ends"; else if($val=="sold") echo "Buyer"; ?> 
	  </td> 
      <?
	  if($val=="today" or $val=='actv')
	  {
	  ?>
	  <td width="13%">
	  Relist
	  </td> 
	  <?
	  }
	  ?>
       <td width="21%"># of Clicks</td> 
	   
	  <? if($val!="sold")
	  {
	  ?> 

	   <td width="21%">Status</td> 
	  <?
	  }
	  ?> 
	    <td width="21%">Action</td>
   </tr> 
 <?php
 if($catid!="")
 {
 $cat_sql="select * from site_categories where category_head_id=$catid"; 
 $cat_res=mysql_query($cat_sql);
 $tot_rec=mysql_num_rows($cat_res);
 
 $cat="category_id=";
 if($tot_rec>0)
 {
   while($cat_row=mysql_fetch_array($cat_res))
   {
    $cat=$cat.$cat_row[category_id]." or category_id=";
   }
 $cat=rtrim($cat," or category_id=");
 }
 
 else
 {
 $cat="category_id=$cate_id";
 }
 
 $sql="select * from auction_details where ( $cat ) and status='Active'";
 }
 if($adate!='' && $adate!='--')
 $sql.="and  bid_starting_date >='$adate' ";
 if($bdate!='' && $bdate!='--' )
 $sql.="and  bid_starting_date <='$bdate' ";
 
 if($cdate!='' && $cdate!='--')
 $sql.="and  expire_date  >='$cdate'  ";
 if($ddate!='' && $ddate!='--' )
 $sql.=" and expire_date  <='$ddate' ";	

$res=mysql_query($sql);	
$tot=mysql_num_rows($res);
$curpage=$_GET['curpage'];
if(strlen($_GET['curpage']) == 0) $curpage=1;
$start=($curpage-1) * 10;
$end=10;
$sql.=" limit $start,$end";
 $res=mysql_query($sql);
?> 
    <tr> 
      <td align="right" colspan="7"> <?php
	if($curpage!=1) {
?> 
        <a href="fixed.php?curpage=<?=($curpage-1);?>" id="link2">Prev</a> |
        <?php
}
?> 
        <?php
if($tot > ($start + $end)) {
?> 
        <a href="fixed.php?curpage=<?=($curpage+1);?>" id="link2">Next</a> 
        <?php
}
?> </td> 
    </tr> 
    <?php
if($tot>0)
{
while($row=mysql_fetch_array($res))
{
?> 
    <tr > 
      <td><input name="chkSub[]" id="chkSub" type="checkbox" class="check" value="<?php echo $row['productid'];  ?>">
	  <input type="hidden" name="id" value="<?=$row['deposit_id']; ?>"></td> 
      <td><a href="item_itechds.php?id=<?= $row[productid]?>" id="link3"><?php
	 echo $row['producttitle'];
?></a></td> 
<td><a href="useritechds.php?id=<?= $row[user_id] ?>&type=gen" id="link3"><?php
$mres=mysql_query("select * from member_details where user_id=".$row['user_id']); 
$mrow=mysql_fetch_array($mres);
echo $mrow['user_name'];
?></a>
</td> 
      <td>
	  <?
	  if($val!="sold")
	 {
	  $expire_date=$row['expire_date'];
	  require 'ends.php'; 
	  echo "$string_difference" ;
	  }
	  else if($val=="sold")
	  {
      $cur_sql="select * from site_bids where  user_pos='yes' and productid=".$row['productid'];
      $cur_res=mysql_query($cur_sql);
      $cur_row=mysql_fetch_array($cur_res);
	  $mres=mysql_query("select * from member_details where user_id=".$cur_row['user_id']); 
      $mrow=mysql_fetch_array($mres);
	  ?>
	  <a href="useritechds.php?id=<?= $row[user_id] ?>&type=gen" id="link3">
	  <?
      echo $mrow['user_name'];
	  ?>
	  </a>
	  <?
	  }
	  ?></td> 
	  <? if($val=="today" or $val=='actv')
	  {
	  ?>
	  <td width="13%">
	  <a href="auction.php?productid=<?=$row['productid']?>&mode=relist" id="link3">Relist</a>
	  </td> 
	  <?
	 }
	  ?>
      <!-- <td>
	  <a href="bid_itechd.php?productid=<?= $row['productid']; ?>" id="link3"><?
	  $bid_sql="select * from site_bids where productid=".$row['productid'];
      $bid_res=mysql_query($bid_sql);
      $bid_row=mysql_fetch_array($bid_res);
      $no_of_bid=mysql_num_rows($bid_res); ?>
	  <?=$no_of_bid; ?> </a></td> -->
     <td width="3%"> <?php
     echo $row['clicks'];
?></td>  
<? if($val!="sold")
	  {
	  ?> 
<td>
     <? 
	  if($row[status]=="Active")
	  {
	  ?>
	  <a href="classified.php?productid=<?= $row['productid']; ?>&mode=close" id="link3"> <?= "Close" ?> </a>
	  <?
	  }
	   else if($row[status]=="Suspend")
	   {
	  ?>
	   <a href="classified.php?productid=<?= $row['productid']; ?>&mode=Active" id="link3"> <?= "Active" ?> </a>
	  <?
	  } 
	  else if ($row[status]=="Closed")
	  {
      ?>
	   <a href="classified.php?productid=<?= $row['productid']; ?>&mode=Active" id="link3"> <?= "Active" ?> </a>
	  <?
	  }
	   else if ($row[status]=="new")
	  {
      ?>
	   <a href="classified.php?productid=<?= $row['productid']; ?>&mode=paid" id="link3"> Paid </a>
	  <?
	  }
	  ?>
	  
</td>
<?
}
?>
<td><a href="modifyauction.php?productid=<?= $row['productid']; ?>" > Edit</a> </td>

    </tr>
<input type="hidden" name="uid"  value="<?=$row['member_id']; ?>">
<input type="hidden" name="amnt"  value="<?=$row['amount']; ?>">
<input type="hidden" name="pthru"  value="<?=$row['payment_thro']; ?>">
    <?php
}
?> 
    <?php if($val!='actv') { ?> 
    <tr> 
      <td colspan="7"> 
	  <input type="submit" class="button"   name="<?php if($val=='new') echo 'btn_new'; else if($val=='mature') echo 'btn_mature'; else echo 'btn_release'; ?>" value="<?php if($val=='new') echo 'Activate'; else  echo 'Delete';  ?>" ></td> 
    </tr> 
    <?php } ?> 
    <?
}
else 
echo '<tr align=center><td colspan=7><font color=#FF0000>No items Found</font></td></tr>';
?> 
  </table> 
</form> <?php
require 'include/footer.php';
?> 
<script language="JavaScript">
function chkall() {
	len=document.frm1.chkSub.length;
	if(len > 1) {
	for(i=0;i<len;i++) {
		if(document.frm1.chkMain.checked==true) {
			document.frm1.chkSub[i].checked=true;
		}
		else {
			document.frm1.chkSub[i].checked=false;
		}
	}
	}
	else {
		if(document.frm1.chkMain.checked==true) {
			document.frm1.chkSub.checked=true;
		}
		else {
			document.frm1.chkSub.checked=false;
		}
	
	}
	}

function condelete()
{
var confrm;
confrm=window.confirm("Are You sure you want to delete");
return confrm;
}
</script> 
