<?
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'])
	{
	
			if($_FILES['bannerpath']['tmp_name']!='' && is_uploaded_file($_FILES['bannerpath']['tmp_name']))
			{		
		
			mysql_query("insert into zb_banners(banner_title, banner_type, banner_text, pagename, banner_location, url,created_date,created_time) values('".$_POST['banner_title']."', '".$_POST['btype']."', '".$_POST['bannertxt']."', '".$_POST['pagename']."','".$_POST['location']."', '".$_POST['url']."', CURDATE(), CURTIME())");
			
			 $productId = mysql_insert_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='$productId'");

									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);
											}	
								}
						}
					}
					}
							
		header("Location: new_banner.php?action=".$_POST['banner_title']." banner has been added");

	}	
	
?>
<!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;
		var ext=banner_path.substr(len-4,4);		
		
		if(document.form1.banner_title.value.length<1){
			alert("You must enter banner title");
			document.form1.banner_title.focus();
			return false;
		}	
		
	if(len<1){
				alert("you must browse banner image");
				document.form1.bannerpath.focus();
				//document.form1.bannerpath.select;
				return false;
			} 
	
						
			if(len>0 && ext!='.gif' && ext!='.jpg' && ext!='.png' && ext!='.swf' && ext!='.bmp'){							
				alert("Please browse gif,jpg,bmp,png,swf type only");
				document.form1.bannerpath.focus();
				//document.form1.bannerpath.select;
				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("Please select the page");
		document.form1.pagename.focus();
		return false;
		}
		
	}

	function backtolist(){
		window.location="banners.php";
	}
	
</script>
</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:750px">
<div class="maximum">
 
  <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"><?
			include("left.php");
		?>
      </td>
      <!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::left ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
      <td width="85%" bgcolor="#FFFFFF" valign="top">
        <table align="center" >
          <tr>
            <td width="543" align="LEFT" valign="top" >
            <table width="70%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
                <tr>
                  <td><strong>&nbsp;ADD NEW BANNER</strong></td>
                </tr>
              </table>
              <table  width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt" bgcolor="#d7d8dd">
                <tr>
                  <td valign="top" bgcolor="#d7d8dd"><br>
                    <? if($_GET['action']){ print "<strong>".$_GET['action']."</strong>";}?>
                    <br>
                    <FORM ACTION="" METHOD="post" enctype="multipart/form-data" name="form1" onSubmit="return validatefrm(this)">
                      <table width="85%"  border="0" cellpadding="2" cellspacing="1" bgcolor="#d7d8dd" align="center">
                        <tr  bgcolor="#d7d8dd">
                          <td width="27%" bgcolor="#d7d8dd" style="padding-left:10px;"><strong>Banner Title</strong></td>
                          <td width="73%" bgcolor="#d7d8dd" style="padding-left:10px;">
                          <input name="banner_title" type="text" class="whiteselectslightbig" maxlength="100" size="40"></td>
                        </tr>
                                           
                        <tr  bgcolor="#d7d8dd" id="rowidimage">
                          <td style="padding-left:10px;"><strong>Image :</strong></td>
                          <td style="padding-left:10px;"><input name="bannerpath" type="file" class="whiteselect" size="40"></td>
                        </tr>
                        <tr  bgcolor="#d7d8dd">
                          <td style="padding-left:10px;"><strong>URL :</strong></td>
                          <td style="padding-left:10px;">
                          <input name="url" type="text" class="whiteselectslightbig" maxlength="255" size="40" onfocus="">
                            (Redirect after click on banner) </td>
                        </tr>
                        <tr  bgcolor="#d7d8dd">
                          <td style="padding-left:10px;"><strong>Page :</strong></td>
                          <td style="padding-left:10px;">
                          <select name="pagename" class="whiteselect" style="width:150px" onChange="populate(this.options[this.selectedIndex].value, document.form1);">
                              <option value="0">Select Page</option>
                              <option value="homepage">Home Page</option>
                              <option value="innerpage">Inner Page</option>
                              <option value="loginpage">Login Page</option>
                            </select></td>
                        </tr>
                        <tr  bgcolor="#d7d8dd">
                          <td style="padding-left:10px;"><strong>Location :</strong></td>
                          <td style="padding-left:10px;">
                           <select name="location" class="whiteselect" valstyle="width:150px" >
                              <option value="0">Select location</option>                             
                            </select>
                          </td>
                        </tr>
                      </table>
                      <br>
                      <table width="85%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC" align="center">
                        <tr>
                          <td align="center" bgcolor="#EDEDED"><input name="sub_btn" type="submit" class="inputsubmit" value="Save">
                            &nbsp;&nbsp;
                            <input name="back" type="button" class="inputsubmit" onClick="backtolist()" value="Back To List">
                          </td>
                        </tr>
                      </table>
                    </FORM>
                    <br>
                  </td>
                </tr>
              </table></td>
          </tr>
        </table></td>
    </tr>
  </table>
</div>
</div>
<div class="bottom_links_show"><? include("footer.php");	?></div>
</div>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::footer ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
</body>
</html>
