<?
session_start();ob_start();
	include("../include/db.inc.php");
	include("../include/bit_functions.inc.php");
	include("../include/pager.php");
	include("thumb_function.php");

	$db1=new db;
	$db1->open();
	if($_POST['sub_btn']){
		
 $banner_exists=mysql_num_rows(mysql_query("select * from zb_banners where banner_title='".trim($_POST[banner_title])."' and bid!=".$_GET['id']));	
	
		
		if($banner_exists){
			header("Location:edit_banner.php?id=".$_GET['id']."&action=Your banner title already exists");
			exit;			
		}
		
		if($_FILES['bannerpath']['tmp_name']!='' && is_uploaded_file($_FILES['bannerpath']['tmp_name']))
			{
			       $banner_id=$_GET['id'];
                    $productId = $banner_id;
					if($productId)
					{
						$maindir = "../images/banners";
						$thumbnail = $_FILES['bannerpath']['name'];
						if($thumbnail<>"")
						{
								$randstr= rand(11111,99999);
								$uploaddir = $maindir;
								if(!file_exists($uploaddir)){
									@mkdir($uploaddir,0777);
								}

								$uploadfile = $uploaddir."/".$thumbnail;

								if(copy($_FILES['bannerpath']['tmp_name'], $uploadfile))
								{
									
									
									$upload_file6 = $thumbnail;

									$file_tbl_name = $upload_file6;

									//$feature=0;
								mysql_query("update zb_banners set banner_image ='".$file_tbl_name."' where bid='$banner_id'");

									if($ext=='jpg'){	
												banner_jpgimage($uploadfile,$upload_file6);
											}else if($ext=='gif'){
												banner_gifimage($uploadfile,$upload_file6);
											}else if($ext=='png'){
												banner_pngimage($uploadfile,$upload_file6);
											}	
								}
						}
					}

				}else{
					$file_tbl_name=$_POST['banner_image'];
				}

	
		
			mysql_query("update zb_banners set banner_title='".$_POST['banner_title']."',url='".$_POST['url']."',banner_type='".$_POST['btype']."',banner_image='".$file_tbl_name."',pagename='".$_POST['pagename']."',banner_location='".$_POST['location']."' where bid=".$_GET['id']);
			header("Location: edit_banner.php?id=".$_GET['id']."&action=".($_POST['banner_title']." banner has been edited"));
	}
		
	$mybanner= mysql_fetch_array(mysql_query("select * from zb_banners where bid=".$_GET['id']));
?> 
<!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 Administion Console</title>
<link href="index.css" rel="stylesheet" type="text/css" />

<link href="../include/stylesheet.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
function populate(pagename, form1)
{	
	  for(x=form1['location'].length; x>=0; x=x-1)
	    {
		form1['location'][x]=null;	
		}
		
	if(pagename=='homepage')
	{
	form1['location'][form1['location'].length]=new Option("Right", "right", "", false);	
	
	}
	else if(pagename=='innerpage')
	{
	form1['location'][form1['location'].length]=new Option("Bottom", "bottom", "", false);	
	}	
	else if(pagename=='loginpage')
	{
	form1['location'][form1['location'].length]=new Option("Bottom", "bottom", "", false);	
	}
		
}

	function validatefrm(){
		var banner_path=document.form1.bannerpath.value;
		var len=banner_path.length;
		
		if(document.form1.banner_title.value.length<1){
			alert("You must enter banner title");
			document.form1.banner_title.focus();
			return false;
		}	
		if(document.form1.url.value.length<1){
		alert("you must enter the url");
		document.form1.url.focus();
		return false;
		}
		
		
		if(document.form1.pagename.value==0)
		{
		alert("You must select the page");
		document.form1.pagename.focus();
		return false;
		}
		
		if(document.form1.btype(0).checked==true){
				var ext=banner_path.substr(len-4,4);						
				if(len>0 && ext!='.gif' && ext!='.jpg'){							
					alert("Please browse .gif or .jpg type only");
					document.form1.bannerpath.focus();
					//document.form1.bannerpath.select;
					return false;								
				} 
				
				
			
		}else if(document.form1.btype(1).checked==true && document.form1.bannertxt.value.length<1){
			alert("You must enter banner text");
			document.form1.bannertxt.focus();
			return false;
		}
	}

	function hiderow(showid,hideid){		
		document.getElementById(showid).style.display='';
		document.getElementById(hideid).style.display='none';
	}
	function bimageivew(mpath){
		window.open(mpath,'','width=600,height=500');
	}
	function selectlocation(optval){
		if(optval==3){
			document.getElementById("loc11").style.display="none";
			document.getElementById("loc22").style.display="";
		}else if(optval==1 || optval==2){
			document.getElementById("loc11").style.display="";
			document.getElementById("loc22").style.display="none";		
		}
	}
	
	function backtolist(){
		window.location="banners.php";
	}
	
	function bimageivew(url){				
		window.open(url,'','width=600,height=670,top=5,left=180');		
	}
	
</script>
</head>

<link href="<?=_BASEURL_?>/css/style.css" rel="stylesheet" type="text/css" >
<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:750px"> 
<div class="maximum">
</table>
<!-- ImageReady Slices (apanel.psd) -->

<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:::::::::::::::::::::::::::::::::::::::::::::::::::::-->   
    <td width="15%"  valign="top">
		<!--Start Left Panel-->
		<?
			include("left.php");
		?>
		<!--End Left Panel-->
		</td>
	<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::left ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->    
    <td width="85%" bgcolor="#FFFFFF" valign="top">
<!--MAIN BODY -->
<table width="98%" border="0" cellpadding="0" cellspacing="0">
  <tr>   
    <td width="10" align="center" valign="top">&nbsp;</td>
    <td align="center" valign="top"><table  width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
        <tr> 
          <td width="1" valign="top">&nbsp;</td>
          <td width="957" 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"><strong>&nbsp;EDIT BANNER</strong></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"> <br> 
                  <? if($_GET['action']){ print "<strong>".($_GET['action'])."</strong>";}?>
                  <br> <FORM ACTION="" METHOD="post" enctype="multipart/form-data" name="form1" onSubmit="return validatefrm(this)">                  <input type="hidden" name="banner_image" value="<?=$mybanner['banner_image']?>">

                    <table width="100%"  border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
                      <tr bgcolor="#FFFFFF"> 
                        <td style="padding-left:10px;"><strong>Banner Title</strong></td>
                        <td style="padding-left:10px;">
						<input name="banner_title" type="text" class="inp" maxlength="100" size="40" value="<?=$mybanner['banner_title']?>"></td>
                      </tr>
                      <tr bgcolor="#FFFFFF"> 
                        <td style="padding-left:10px;"><strong>URl</strong></td>
                        <td style="padding-left:10px;"> <input type="text" name="url" class="inp" maxlength="100" size="40" value="<?=$mybanner['url']?>" />
                        <table width="99%" border="0" cellspacing="0" cellpadding="0">
                            <tr> 
                              <td width="6%">&nbsp;</td>
                              <td width="73%">&nbsp;</td>
                            </tr>
                          </table></td>
                     
                      <tr bgcolor="#FFFFFF" id="rowidimage" <? if($mybanner['banner_type']==2){echo 'style="display:none"';}?>> 
                        <td style="padding-left:10px;"><strong>Image :</strong></td>
                        <td style="padding-left:10px;">
						<input name="bannerpath" type="file" size="40">
						&nbsp; <a href="javascript:bimageivew('../images/banners/<?=$mybanner[banner_image]?>')"  class="link" style="color:#000000;">Current Image</a>
						</td>
                      </tr>
                      <tr bgcolor="#FFFFFF">
                        <td style="padding-left:10px;"><strong>Page</strong></td>
                        <td style="padding-left:10px;">
						<select name="pagename" class="inp" style="width:150px" onChange="populate(this.options[this.selectedIndex].value, document.form1);">						
                       <option value="0">Select Page</option>
                              <option value="homepage" <? if($mybanner[pagename]=='homepage') echo 'selected';?>>Home Page</option>
                              <option value="innerpage" <? if($mybanner[pagename]=='innerpage') echo 'selected';?>>Inner Page</option>
                              <option value="loginpage" <? if($mybanner[pagename]=='loginpage') echo 'selected';?>>Login Page</option>
                             
                            </select></td>
                      </tr>
                      
                      <tr bgcolor="#FFFFFF"> 
                        <td style="padding-left:10px;"><strong>Location :</strong></td>
                        <td style="padding-left:10px;"> 
<select id="loc11" name="location" class="inp" style="width:150px">
                      
                             <option value="<?=$mybanner['banner_location']?>"><?=$mybanner['banner_location']?></option>                         
                            </select>												
						</td>
                      </tr>
                    </table>
                    <br>
                    <table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
                      <tr> 
                        <td align="center" bgcolor="#EDEDED"> <input name="sub_btn" type="submit" class="inp" value="Save">
                          &nbsp;&nbsp;
                          <input name="btn" type="button" class="inp" onClick="backtolist()" value="Back To List"> </td>
                      </tr>
                    </table>
                    </FORM>
                  <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 align="right" background="img/tbl-bg.gif"><img src="img/tbl-right05.gif" width="35" height="12"></td> -->
              </tr>
            </table></td>
          <td width="20" valign="top">&nbsp;</td>
        </tr>
      </table>
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
    </td>
  </tr>
</table>
<!--MAIN BODY end-->
</td>
  </tr>
</table>

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