<?
ob_start();
session_start();

 	include("../include/db.inc.php"); 
	include("../include/bit_functions.inc.php");
 	include("../include/pager.php");	
   $db1=new db;
   $db1->open();
    mysql_query("SET NAMES 'utf8'");
   mysql_query("SET NAMES 'utf8'");
   if($_SESSION['uname']=='' || $_SESSION['pwd']=='')
		{
			header("location:login.php");
		}
		 
  if(isset($_GET['status_id'])) {
	$status=$_GET['status'];
	
	if ($status==1)
	   $status=0;
	else if($status==0)
	   $status=1;   
	 $pid = $_GET['status_id'];
	$qu="Update t123go_product set status='$status' where pid='$pid'"; 
	mysql_query($qu);
	header("location:auction_list.php");
	exit();
	
	} 
	 if(isset($_POST['start_time'])) {
	$start_time=$_POST['start_time'];
	$pid = $_POST['auction_time_id'];
	$qu_start_time="Update t123go_product set start_time='$start_time' where pid='$pid'";
	mysql_query($qu_start_time);
	
	} 
	 
	 if(isset($_POST['end_time'])) {
	$end_time=$_POST['end_time'];
	$pid = $_POST['auction_time_id'];
	 $qu_end_time="Update t123go_product set end_time='$end_time' where pid='$pid'";
	mysql_query($qu_end_time);
	header("location:auction_list.php");
	exit();
	} 
	 
	if(isset($_GET['return'])){  
		
		   $return_query=mysql_query("select id,uid from t123go_bid where pid='".$_GET['return']."' and noti_status='0' order by uid");
		   while($return_user=mysql_fetch_array($return_query)){
		   $user_bid=mysql_fetch_array(mysql_query("select no_bids from user where id='".$return_user[uid]."'"));
		    $total_bid=$user_bid[no_bids]+1;
		   mysql_query("update user set no_bids='".$total_bid."' where id='".$return_user[uid]."'");
		   mysql_query("update t123go_bid set noti_status='1' where id='".$return_user[id]."' and noti_status='0'");
		   }
			
		}
     
		if($_GET['del']){  
		
		   $del_query=mysql_query("delete from t123go_product where pid=".$_GET['del']);
			
		}
if(isset($_GET['search']))
		{
		
		
				$select="select * from t123go_product where 1=1";
		 
					  if($_GET['pname']<>''){
				  		$select.=" and (pname like '%".$_GET['pname']."%') ";
						}
						else
					  {
					  $select.=" ";
					  }
					  if($_GET['description']<>''){
					  $select.=" and (description like '%".$_GET['description']."%') ";
					  }	else
					  {
					  $select.=" ";
					  }
					   if($_GET['brand']<>''){
					  $select.=" and (brand like '%".$_GET['brand']."%') ";
					  }	else
					  {
					  $select.=" ";
					  }
					   if($_GET['type']<>''){
					  $select.=" and type1='".$_GET['type']."' ";
					  }	else
					  {
					  $select.=" ";
					  }
					   
					  if($_GET['orderby']==1)
					  {
					  $select.=" order by pname";
					  }	
					  else if($_GET['orderby']==2)
					  {
					   $select.=" order by start_time ";
					  }
					  else if($_GET['orderby']==3)
					  {
					   $select.=" order by end_time ";
					  }
					  else if($_GET['orderby']==4)
					  {
					   $select.=" order by price ";
					  }
					   else if($_GET['orderby']==5)
					  {
					  $select.=" order by rand() ";
					  }
		
		
		}
		else
		{
		$select="select * from t123go_product order by pid ";
		}
			$limit=20;
			$sel_query=mysql_query(dopaging($select,$limit));
 	    	$tot=mysql_num_rows($sel_query);
  ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Money Auctions | Admin Controls</title>
<link href="index.css" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet" href="<?=_BASEURLCSSNEW_?>/dhtmlgoodies_calendar.css?random=20051112" media="screen" />
<script language="JavaScript" src="../js/common.js"></script>
<script language="javascript" src="../js/dhtmlgoodies_calendar.js?random=20060118"></script>
<script language="JavaScript">
function veiws(pid){

		window.open('thumbnail.php?id='+pid,'','scrollbars,width=800,height=600,top=50,left=180');
	}
	function viewproduct(id){
		window.open('view_product.php?id='+id,'','scrollbars,width=920,height=700,top=5,left=180');		
	}
	function sendmail(id){
		window.open('send_mail.php?id='+id,'','scrollbars,width=800,height=500,top=50,left=180');		
	}
</script>
</head>
<body>
<div class="admin_wrapper">
<div class="logo_show"><? include("minorlogout.php");?></div>
<div style="float:left; width:200px">
<div class="topg_links_show"><? include("left.php");	?></div>
<div class="top_links_show"><? include("belowleft1.php");	?></div></div>
<div style="float:left; width:800px">
<div class="maximum"><br />
<br />
<TABLE WIDTH="100%" BORDER=0 CELLPADDING=0 CELLSPACING=0 align="center">
        <TR> 
          <TD> <img border='0' src="border_img/circle_01.gif" WIDTH=36 HEIGHT=35 ALT=""></TD>
          <TD width="901" height="34" valign="top" > <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
               
                <td width="100%" background="border_img/circle_02.gif">&nbsp;</td>
              </tr>
            </table></TD>
          <TD> <img border='0' src="border_img/circle_03.gif" WIDTH=35 HEIGHT=35 ALT=""></TD>
        </TR>
        <TR> 
          <TD width="36" background="border_img/circle_04.gif">&nbsp; </TD>
          <TD align="left" valign="top"> 
		<table width="91%" border="0" cellpadding="1" cellspacing="0">
		<form name="search_form" action="auction_list.php" method="get">
		<tr>
		<td width="18%">Product Name:</td>
		<td width="26%"><input type="text" name="pname" /></td>
		<td width="22%">&nbsp;</td>
		<td width="9%"> Order By</td>
		<td width="25%"><select name="orderby" style="width:150px">
		<option value="0">--Select Order By--</option>
		<option value="1">Product Name</option>
		<option value="2">Start Time</option>
		<option value="3">End Time</option>
		<option value="4">Price</option>
		<option value="5">random</option>
		
		</select></td>
		</tr>
		<tr>
		<td>Description:</td>
		<td><input type="text" name="description" /></td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td></td>
		</tr>
		<tr>
		<td>Brand:</td>
		<td><input type="text" name="brand" /></td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td></td>
		</tr>
		<tr>
		<td>Auction Type:</td>
		<td><select name="type" style="width:150px">
		<option value="">--Select Auction Type--</option>
		  <? $sql_type="select type_id,auction_type from t123go_auctiontype";
			$type=mysql_query($sql_type);
			while($row_type=mysql_fetch_array($type))
				{?>
			  <option value="<?php echo $row_type['type_id'];?>"  > <?php echo ucfirst($row_type['auction_type']);?> </option>
			  <?
				}?>
		</select></td>
		<td>&nbsp;</td>
		<td></td>
		</tr>
		
		<tr>
		<td colspan="5"><input type="submit" name="search" value="SEARCH" /></td>
		
		</tr>
		</form>
	</table>
 </TD>
          <TD width="36" background="border_img/circle_06.gif">&nbsp; </TD>
        </TR>
        <TR> 
          <TD> <img border='0' src="border_img/circle_07.gif" WIDTH=36 HEIGHT=34 ALT=""></TD>
          <TD height="34" background="border_img/circle_08.gif">&nbsp; </TD>
          <TD> <img border='0' src="border_img/circle_09.gif" WIDTH=35 HEIGHT=34 ALT=""></TD>
        </TR>
      </TABLE>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
        <tr> 
          <td width="33" valign="top"><img src="img/03.gif" width="33" height="23"></td>
                <td background="img/bg01.gif">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="20%"><strong>VIEW AUCTIONS</strong> </td>
                      <td width="54%">&nbsp;</td>
                      <td width="26%" align="right">
					  <a href="product_new.php" class="link5">Add Product</a>
					  </td>
                    </tr>
                  </table></td>
          <td width="35"><img src="img/04.gif" width="35" height="23"></td>
        </tr>
      </table>
      <table  width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
        <tr> 
          <td width="12" valign="top" background="img/tbl-left04.gif"><img src="img/tbl-left04.gif" width="22" height="13"></td>
                <td valign="top" align="center"> 
    <br>
                    <? if($tot!=0){?>
                    <table width="100%" border="1" cellspacing="1" cellpadding="1" bgcolor="#FFFFFF" style="border-collapse:collapse; border-color:#FED267">
                            <tr bgcolor="#FED267"> 
							<td width="30"  ><strong><font color="#FFFFFF" size="+0">S.No.</font></strong></td>
                              <td width="50" align="center" ><strong><font color="#FFFFFF" size="+0">Thumbnail</font></strong></td>
							   <td width="97" ><strong><font color="#FFFFFF" size="+0">Product Name</font></strong></td>
							   <td width="49"  ><strong><font color="#FFFFFF" size="+0">Auction Type</font></strong></td>
                              <td width="49"  ><strong><font color="#FFFFFF" size="+0">Return Bids</font></strong></td>
                              <td width="32"  ><strong><font color="#FFFFFF" size="+0">Email</font></strong></td>
                              <td width="41" align="center"><strong><font color="#FFFFFF" size="+0">Status</font></strong></td>
							  <td width="66" align="center"><strong><font color="#FFFFFF" size="+0">Start Time</font></strong></td>
							  <td width="66" align="center"><strong><font color="#FFFFFF" size="+0">End Time</font></strong></td>
							  <td width="32"height="20" align="center"><strong><font color="#FFFFFF" size="+0">Edit</font></strong></td>
                              <td width="44" height="20" align="center"><strong><font color="#FFFFFF" size="+0">Delete</font></strong></td>
	                        </tr>
							<?  
							$num=getStart($limit);
								$i=1;	
                       		 while($myrow=mysql_fetch_array($sel_query)){  
							 $num++;
							
							 ?>
							  
                            <tr onMouseOver="this.style.backgroundColor='#FFECBF'" onMouseOut="this.style.backgroundColor='#ffffff'"> 
							 <td ><?=$num;?></td>
                              <td align="center" valign="top"><a href="javascript:veiws('<?=$myrow['pid']?>')">
							  <?=image_50($myrow['pid'])?>
							 </a>
                              </td>
                              <td ><? echo '<a href="javascript:viewproduct('.$myrow['pid'].')" class="link11">'.$myrow['pname'].'</a>'?></td>
							  <td >
								  <?
								  if($myrow[type1]==1){
								  
								  echo "Fixed Price";
								  }
								  else if($myrow[type1]==2){
								  
								  echo "Penny";
								  }
								  else if($myrow[type1]==3){
								  
								  echo "100% Off";
								  }
								  
								  
								  
								  ?>
							  
							  </td>
							  
                              <td  align="center"><a href="product_list.php?return=<?=$myrow['pid']?>">Return Bids</a></td>
                              <td ><? echo '<a href="javascript:sendmail('.$myrow['pid'].')" class="link11">send</a>'?>  </td>
                             
							  <input type="hidden" name="auction_id" value="<?=$myrow['pid']?>" />
                              <td align="center"> 
							  <a href="auction_list.php?status_id=<?=$myrow['pid']?>&status=0">
                              <input type="radio"   value="1" <? if($myrow['status']==1){ echo "checked";} ?> />
							  </a>
							  ON
							  <br />
							   <a href="auction_list.php?status_id=<?=$myrow['pid']?>&status=1">
								<input type="radio"  value="0" <? if($myrow['status']==0){ echo "checked";}?> onChange="this.form.submit();"/>
								</a>
								OFF
                        		</td>
							
								<? $num_sold=mysql_num_rows(mysql_query("select id from t123go_product_sold where pid=".$myrow['pid']));
								
								if($num_sold > 0){?>
								
								
								<td><input type="text" name="start_time"  value="<?=$myrow['start_time']?>" size="13" >
							<img src="" width="16" height="16" onClick="displayCalendar(document.forms[<?=$i?>].start_time,'yyyy-mm-dd hh:ii',this,true)" />
                               </td>
								<td><input type="text" name="end_time"  value="<?=$myrow['end_time']?>" size="13"  >
                              <img src="" width="16" height="16" onClick="displayCalendar(document.forms[<?=$i?>].end_time,'yyyy-mm-dd hh:ii',this,true)" />
                                </td>
								
								<td align="center" >Sold</td>
								<? } else
								{
								?>
								<form action="" method="post"  name="form_<?=$i?>">
								<input type="hidden" name="auction_time_id" value="<?=$myrow['pid']?>" />
								<td><input type="text" name="start_time"  value="<?=$myrow['start_time']?>" size="13" onChange="this.form.submit();">
							<img src="../images/cal.gif" width="16" height="16" onClick="displayCalendar(document.form_<?=$i?>.start_time,'yyyy-mm-dd hh:ii',this,true)" />
                               </td>
								<td><input type="text" name="end_time"  value="<?=$myrow['end_time']?>" size="13" onChange="this.form.submit();" >
                               <img src="../images/cal.gif" width="16" height="16" onClick="displayCalendar(document.form_<?=$i?>.end_time,'yyyy-mm-dd hh:ii',this,true)" />
                                </td>
								</form>
								<td align="center" >
								
								<a href="edit_product.php?id=<?=$myrow['pid']?>&featured=1" class="link5" title="Click To Edit">Edit</a>
								| <a href="add_pimage.php?id=<?=$myrow['pid']?>&featured=1" class="link5" title="Click To New">New</a>
								
                              </td>
							  <? }?> 
                              <td align="center">
                           <a href="auction_list.php?del=<?=$myrow['pid']?>" onClick="return confirm('Are you sure to delete this Product ?');">
						   <img src="../images/category/imgdelete.gif" border="0"></a>
                            </td>
                            </tr>
                                <?
				
		$i++;
		
			}	// end of while loop
		
			if(rightpaging()){	// if there are more than one pages then only display paging
		?>
				<tr>
					<td colspan="9" align="center"><br><? echo rightpaging(); ?></td>
				</tr>
		<?
			}	// end of paging display
		?>
                      </table>
					  <? }else{
					  
					  echo "No Products";
					  }?>
					  

</td>
          <td width="12" valign="top" background="img/tbl-right04.gif"><img src="img/tbl-right04.gif" width="19" height="9"></td>
        </tr>
      </table>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
              <tr> 
                <td width="33"><img src="img/tbl-bot01.gif" width="33" height="12"></td>
                <td  width="709" align="right" background="img/tbl-bg.gif"></td>
                <td width="33"><img src="img/tbl-right05.gif" width="35" height="12"></td>
              </tr>
            </table>
            <br />
<br />

</div></div>
<div class="bottom_links_show"><? include("footer.php");	?></div>

</html>
</div>
</body>
</html>
