<?
ob_start();
session_start();
 include("../include/db.inc.php"); 
   $db1=new db;
   $db1->open();
    mysql_query("SET NAMES 'utf8'");
// for new addition
		if(isset($_POST['Addnew_btn'])){
			$sql_qry=mysql_query("select * from t123go_bidpackage where total_bid='".$_POST['total_bid']."' and bid_type='".$_POST['bid_type']."'");
				if(mysql_num_rows($sql_qry)){
					$action=base64_encode("\t'".$_POST['total_bid']."' package already exists");
					header("location:bid_package.php?action=".$action);
				}
			else{
			if(is_uploaded_file($_FILES['image']['tmp_name'])){		
				$source=$_FILES['image']['tmp_name'];
				
				$ext=substr($_FILES['image']['name'],strlen($_FILES['image']['name'])-4,4);
				$package_title=str_replace(' ','_',trim($_POST['total_bid']));
				$package_file_name=$package_title.$ext; 
				$dest="../images/".$package_file_name;
				@copy($source,$dest);
			
			
			
				$sql_qry=mysql_query("insert into t123go_bidpackage(total_bid,total_price,image,bid_type)
					values('".$_POST['total_bid']."','".$_POST['total_price']."','".$package_file_name."','".$_POST['bid_type']."')");
					$action=base64_encode('"'.$_POST['total_bid'].'" package has been added');
					header("location:bid_package.php?action=".$action);
					}		
				}
			}
			
		
// for edit  
		if(isset($_POST['edit_btn'])){	
			$sql_qry=mysql_query("select * from t123go_bidpackage where total_bid='".trim($_POST['total_bid'])."' and pkgid!=".$_GET['id']);
			$category_exists=mysql_num_rows($sql_qry);		
		
			if($category_exists){
				header("location:bid_package.php?id=".$_GET['id']."&action=".base64_encode("You edited package already exists"));
			}
		else{
		
				if(is_uploaded_file($_FILES['image']['tmp_name']) && $_FILES['image']['size']){		
				
					$current_banner_arr=mysql_fetch_array(mysql_query("select * from t123go_bidpackage where pkgid=".$_GET['id']));
					@unlink("../images/".$current_banner_arr['image']);
					
					$source=$_FILES['image']['tmp_name'];					
					// find ext name of video clip file
					$ext=substr($_FILES['image']['name'],strlen($_FILES['image']['name'])-4,4);
					$package_title=str_replace(' ','_',trim($_POST['total_bid']));
					$package_file_name=$package_title.$ext; // assign title name to banner file name
					$dest="../images/".$package_file_name;					
					@copy($source,$dest);
					$package_image=",image='".$package_file_name."'";
				}else{
					$package_image=",image='".$_POST['image_new']."'";
				}		
			
				
			$sql_qry1="update t123go_bidpackage set total_bid='".$_POST['total_bid']."',
					total_price='".$_POST['total_price']."', bid_type='".$_POST['bid_type']."' ".$package_image." where pkgid=".$_GET['id'];
					mysql_query($sql_qry1);
				$action=base64_encode('package has been edited');
		}			header("location:bid_package.php?id=".$_GET['id']."&action=".$action);
		}
if(isset($_GET['del'])){
		$sql_qry=mysql_query("delete  from t123go_bidpackage where pkgid=".$_GET['del']);
		header("location:bid_package.php");
	}

	if($_GET['id']){
		$sql_qry=mysql_query("select * from t123go_bidpackage where pkgid=".$_GET['id']);
		$myrec=mysql_fetch_array($sql_qry);		
		$id_found=mysql_num_rows($sql_qry);
	}
	
	$sql_qry=mysql_query("select * from t123go_bidpackage");
	$tot_found=mysql_num_rows($sql_qry);
	
?>
 <!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>

<title>Money-Auctions Administion Console</title>
<script language="JavaScript" src="../js/common.js"></script>
<link href="../css/stylesheet.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
	function veiws(url){				
		window.open(url,'','width=600,height=670,top=5,left=180');		
	}
	
</script>
<script language="javascript">
function validate()
{

     if(document.addnewfrm.total_bid.value=='')
	{
		 alert("Enter No. Of Bids");
		 document.addnewfrm.total_bid.focus();
		return false;

	} 
	  if(document.addnewfrm.total_price.value=='')
	{
		 alert("Enter BidPack Price");
		 document.addnewfrm.total_price.focus();
		return false;

	}
		  if(document.addnewfrm.bid_type.value=='')
	{
		 alert("Enter BidPack Type");
		 document.addnewfrm.bid_type.focus();
		return false;

	} 
 
	}
	</script>

<style type="text/css">
<!--
.style1 {color: #093A9C}
.style2 {color: #FE6905}
-->
</style>
</head>
<body bgcolor="#ffffff">
<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/>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::header starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<table width="100%" border="1" cellspacing="0" cellpadding="0" style="border-collapse:collapse; border-color:#ffffff">
  <tr>
    <td><? //include("header.php");?></td>
  </tr>
</table>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::header ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->

<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::center starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<div style="margin-top:5px">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%" style="border-collapse:collapse; border-color:#404193">
  <tr height="417">
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::left starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->   
    
	<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::left ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->    
<td width="81%" bgcolor="#FFFFFF" valign="top">
		
<table  width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
  <tr> 
    <td width="15" valign="top">&nbsp;</td>
          <td valign="top"><br> <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="22%"><strong>BidBox LIST</strong> </td>
                      <td width="52%">&nbsp;</td>
                      <td width="26%" align="right">
					  <a href="bid_package.php#new" class="link5">Add New</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="22" valign="top" background="img/tbl-left04.gif"><img src="img/tbl-left04.gif" width="22" height="13"></td>
          <td valign="top" align="center">		  		  		             
	 <? if($_GET['error_action']){ print "<font color='red'><strong>".base64_decode($_GET['error_action'])."</strong></font>";}else if($_GET['action']){ print "<strong>".base64_decode($_GET['action'])."</strong>";}
		if($tot_found){
	 ?>
<br>
<form action="" method="post" enctype="multipart/form-data" name="form1">
                    <table width="90%" border="1" cellspacing="1" cellpadding="1" style="border-collapse:collapse; border-color:#FED267">
                      <tr bgcolor="#FED267"> 
                       <td width="100" ><strong><font color="#FFFFFF">Package Image</font></strong></td>
                        <td width="176" ><strong><font color="#FFFFFF">Total bid</font></strong></td>
                        <td width="100" ><strong><font color="#FFFFFF">Bid Type</font></strong></td>
                         <td width="78" align="center"><strong><font color="#FFFFFF">
                             Total Price</font></strong></td>
                        <td width="57" >&nbsp;</td>
                        <td width="56" height="20" align="center"><strong><font color="#FFFFFF">Delete</font></strong></td>
                      </tr>
                      <? $i=0;
				while($myrow=mysql_fetch_array($sql_qry)){
					if($i%2==0){$col='#E6E4E3';}else{$col='#FFFFFF';}
			?>
                      <tr bgcolor="<?php /*?><?=$col?><?php */?>" onMouseOver="this.style.backgroundColor='#FFECBF'" onMouseOut="this.style.backgroundColor='#ffffff'"> 
                        <td > <img src="../images/<?=$myrow['image']?>" width="77" height="52" />
                         
                        </td>
                        <td > 
                          <?=$myrow['total_bid']?>&nbsp;Bids
                        </td>
                        <td >Greenpack&nbsp;
                          <?=$myrow['bid_type']?>
                        </td>
                        <td align="center"> 
                          <?=$myrow['total_price']?>
                        </td>
                        <td align="center" ><a href="bid_package.php?id=<?=$myrow['pkgid']?>#edit" class="link5" title="Click To Edit"> Edit</a></td>
                        <td align="center">                           
                          <table>
                            <tr>
                              <td></td>
                              <td><a href="bid_package.php?del=<?=$myrow['pkgid']?>" onclick="return confirm('Are You Sure Delete This Bid package')"><img src="../images/category/imgdelete.gif" border="0"></a></td>
                            </tr>
                          </table> </td>
                      </tr>
                      <? $i++;}?>
                    </table>
                      
                   
</form>
<? }else{ echo '<br><br><br><br><strong>No record found</strong><br><br><br><br>';} ?>
</td>
          <td width="19" 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>
    </td>
    <td width="15" valign="top">&nbsp;</td>
  </tr>
</table>
<br>
      <? 
	if($_GET['action']){ echo '<div align="center"><strong>'.base64_decode($_GET['action']).'</strong></div>';}
if(!$_GET['id'] && !$id_found){?><a name="new">
      <TABLE WIDTH="78%" 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="14%" ><strong><font color="#003366">Add New</font></strong></td>
                <td width="79%" 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"> <form action="" method="post" enctype="multipart/form-data" name="addnewfrm" onSubmit="return validate();">
        <table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#003366" >
         <tr bgcolor="#FFFFFF"> 
            <td height="20">Image</td>
            <td><input name="image" type="file" ></td>
          </tr>
          <tr bgcolor="#FFFFFF"> 
            <td height="20">Total Bid</td>
            <td><input name="total_bid" type="text" class="inputtext" size="80" maxlength="145"></td>
          </tr>
          <tr bgcolor="#FFFFFF"> 
            <td height="20">Total price</td>
            <td><input name="total_price" type="text" class="inputtext" size="80" maxlength="145"></td>
          </tr>
          <tr bgcolor="#FFFFFF"> 
            <td height="20">Bidpack Type</td>
            <td><input name="bid_type" type="text" class="inputtext" size="80" maxlength="145"></td>
          </tr>
          
         
          <tr bgcolor="#E6F2FF"> 
            <td height="30">&nbsp;</td>
            <td><input name="Addnew_btn" type="submit" class="inputtext" value="Save"  style="padding-bottom:20px;"></td>
          </tr>
        </table>
        </form></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>
      <? }else if($_GET['id'] && $id_found){?><a name="edit">
      <TABLE WIDTH="74%" 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 height="34" valign="top" > <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td width="7%" align="center"><strong><font color="#003366">Edit</font></strong></td>
                <td width="95%" 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"> <form action="" method="post" enctype="multipart/form-data" name="editfrm" >
	 <input type="hidden" name="image_new" value="<?=$myrec['image']?>"
        <table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#003366" >
		<tr bgcolor="#FFFFFF"> 
            <td height="20">Image</td>
            <td><input name="image" type="file" ></td>
          </tr>
          
          <tr bgcolor="#FFFFFF"> 
            <td height="20">Total Bid</td>
            <td><input name="total_bid" type="text" class="inputtext" size="80" maxlength="145" value="<?=$myrec['total_bid']?>"></td>
          </tr>
         
          <tr bgcolor="#FFFFFF"> 
           <td height="20">Total Price</td>
            <td><input name="total_price" type="text" class="inputtext" size="80" maxlength="145" value="<?=$myrec['total_price']?>"></td>
          </tr>
          <tr bgcolor="#FFFFFF"> 
            <td height="20">Bidpack Type</td>
            <td><input name="bid_type" type="text" class="inputtext" size="80" maxlength="145" value="<?=$myrec['bid_type']?>"></td>
          </tr>
          
                    <tr bgcolor="#E6F2FF"> 
            <td height="35">&nbsp;</td>
            <td><input name="edit_btn" type="submit" class="inputtext" value="Save"  style="padding-bottom:20px;"></td>
          </tr>
        </table>
      </form></TD>
          <TD width="35" 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>
      <? }?>

        </td>
  </tr>
</table>
</div>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::center ends:::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::footer starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
</div></div>
<div class="bottom_links_show"><? include("footer.php");	?></div>
</div>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::footer ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
</body>
</html>
