<?php
ob_start();
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com © 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php

include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";


if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE); 
} 

if(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}


include "../includes/htmltop.php";

/*taken from the general site settings table*/

$banner_image_size = getSettingsValue('banner_size');
			
if(isset($_POST['add']))
{


	/*check whether banner with the same name exists in the database*/
		
	$select_banner = "SELECT * FROM ".$tableprefix."banners WHERE LOWER(vbanner_name) = ".GetSQLValueString(strtolower($_POST['txtBannerName']),"text");
	$result_banner = mysql_query($select_banner) or die(mysql_error());
	
	if(mysql_num_rows($result_banner)>0)
	{
	
		$message = BANNER_ALREADY_EXIST." !!";
	}
	else
	{	
	
		$bannerfiletype = $_FILES['txtBannerImage']['type'];
		$bannerfilename = $_FILES['txtBannerImage']['name'];
		$bannertempname	= $_FILES['txtBannerImage']['tmp_name'];
							
		if ($_FILES['txtBannerImage']['name'][0] != "")
		{
			if (!isValidWebImageType($bannerfiletype,$bannerfilename,$bannertempname))
			{
				
				$message .= " * ".INVALID_IMAGE."<br>";
				
			}
			else
			{
		
				
				$imagewidth_height_type_array = explode(":", ImageTypeBanner($_FILES['txtBannerImage']['tmp_name']));
				$imagetype = $imagewidth_height_type_array[0];
	
				$assignedname = "banner" . time() . "." . $imagetype;
				
				if (move_uploaded_file($_FILES['txtBannerImage']['tmp_name'], "../banners/" . $assignedname))
				{
				
					
					chmod("../banners/$assignedname", 0777);
										
					$banner_size  = split(',',$banner_image_size);
					generateThumbNail("../banners/".$assignedname,"../banners/".$assignedname,$banner_size[0],$banner_size[1]);
					$insert_banner = "INSERT INTO ".$tableprefix."banners(vbanner_name,vbanner_locurl,vbanner_image,dbanner_date,nbanner_display_count,vbannerdelete_status)
									  VALUES(".GetSQLValueString($_POST['txtBannerName'],"text").","
									  .GetSQLValueString(str_replace('http://','',$_POST['txtBannerLocation']),"text").",'"
									  .$assignedname."',now(),0,'N')";
									  
					  
					mysql_query($insert_banner) or die(mysql_error());									  

				header('Location:banners.php?msg1='.BANNER_ADD_SUCCESS);								  
				}					  
							  
			}					  
						  
						  
		}						  
						  
						  
	}						  

}
?>
<body topmargin="0">
<script>
function checkAddBannerForm()
{

  var form_name = new Array('txtBannerName','txtBannerLocation','txtBannerImage');		
  var display_name = new Array('<?php echo BANNER_NAME;?>','<?php echo BANNER_LOCATION_URL;?>','<?php echo BANNER_IMAGE;?>');
  var count = 3;	

  if(check_fields('frmAddBanner',form_name,display_name,count))	
  {
  
  	
	 //document.frmAddBanner.submit();	
   
  }
  else
  {
  
  		return false;
  
  }
   
}

</script>

		<body>
		
		<center>
		
		<div align="left" id="layout">
		
		
				
				
				<!--header area start -->
<?php

	include_once("../includes/topheader_admin.php")

?>
				
				<!--header area end -->
				
				<?php //echo BANNER_IMAGE;?>
				
				
				<div align="left" class="main_body">
				<!--main body start -->
				
				
				
<?php
		include_once("../includes/admintopmenu.php")
?>		
																					
								
					<div align="left" class="content_area">
					
					<!--content area start -->
							
					<div align="left" class="page_title"><?php echo ADD_BANNER;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
                    <br>
											
					<div align="left">										
					<form name="frmAddBanner" action="#" method="POST" enctype="multipart/form-data" onSubmit="return checkAddBannerForm();">
					
					<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
																					
					<tr><td colspan="3" align="right"><span class="required">*</span>&nbsp;<?php echo FIELDS_ARE_MANDATORY;?></td></tr>
					<tr><td width="34%" align="right" valign="top"><?php echo BANNER_NAME;?>&nbsp;<span class="required">*</span></td>
					<td width="3%" >&nbsp;</td>
						<td width="63%" align="left" valign="top"><input class="textarea" type="text" name="txtBannerName" value="" size="30" maxlength="50"></td>
					</tr>
					<tr>
					  <td align="right" valign=top><?php echo BANNER_LOCATION_URL;?>&nbsp;<span class="required">*</span></td>
					  <td >&nbsp;</td>
						<td valign=top align="left">http://&nbsp;<input class="textarea" type="text" name="txtBannerLocation" value="" size="23" maxlength="250"></td>
					</tr>
					<tr><td align="right" valign=top><?php echo BANNER_IMAGE;?>&nbsp;<span class="required">*</span></td>
					<td >&nbsp;</td>
						<td valign=top align="left"><input type="file" name="txtBannerImage" size="30"><br>
						&nbsp;[<?php echo JPG_GIF_PNG;?>]&nbsp;[<?php echo str_replace(',','*',$banner_image_size)?>]&nbsp;
						</td>
					</tr>
					<tr><td colspan="3">&nbsp;</td></tr>
					<tr>
						<td colspan="3" align="center">
							
							<input type="button" class="button" name="back" value="&nbsp;<?php echo BACK;?>&nbsp;" onClick="history.go(-1)">
                                                        <input type="submit" value="&nbsp;<?php echo ADD_TEXT;?>&nbsp;" name="add" class="button">
						</td>
					</tr>
					<tr><td colspan="3">&nbsp;</td></tr>
				</table>
				
				</form>
				
				</div>
						
						
				<!--content area end-->
								
				</div>
				
								
					<div align="left" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
				</div>
				
				
<?php
	include "../includes/footer.php";
	
	ob_end_flush();
?>