<?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";
  

			
if(isset($_POST['update']))
{

		$image_flag = 0;
						
		for($i=1;$i<=10;$i++)
		{
	
			$product_image = "txtImage_".$i;
			$productfiletype 	= $_FILES[$product_image]['type'];
		    $productfilename 	= $_FILES[$product_image]['name'];
			$producttempname	= $_FILES[$product_image]['tmp_name'];


				if($_FILES[$product_image]['name'][0] != "")
				{
					if (!isValidWebImageType($productfiletype,$productfilename,$producttempname))
					{
						$message .= " * Image$i is no a valid image !! Upload an image (jpg/gif/png)" . "<br>";
						$image_flag = 1;
					}
					else
					{
							
						$imagewidth_height_type_array = explode(":", ImageTypeBanner($_FILES[$product_image]['tmp_name']));
						$imagetype = $imagewidth_height_type_array[0];
			
						$bulk_image_buffer = "txtImageBuffer_".$i;	
						
						
			
						if($_FILES[$product_image] != '')
						{
			
						//if($_POST[$bulk_image_buffer])
							$assignedname = "affiliate_" . time() . $i . str_replace(' ','',$_FILES[$product_image]['name']);
							
							if(move_uploaded_file($_FILES[$product_image]['tmp_name'], "../banners/" . $assignedname))
							{
							
								chmod("../banners/".$assignedname, 0777);
													
								//$banner_size  = split(',',$banner_image_size);
								
																																
								/*$update_product_images = "UPDATE ".$tableprefix."product_view_images
														  SET vimage_name = ".GetSQLValueString($assignedname,"text")."
														   WHERE nimage_productid = ".$_GET['edit_id'];*/
														   
								$update_product_images = "UPDATE ".$tableprefix."affiliate_banner
							  	  						   SET vaff_banner_name = ".GetSQLValueString($assignedname,"text").
														  " WHERE vaff_banner_name = ".GetSQLValueString($_POST[$bulk_image_buffer],"text");
																															
								mysql_query($update_product_images) or die(mysql_error());	
																				
								//$image_flag = 1;
								
								if($_POST[$bulk_image_buffer] != '')
								{
									$buffer_image = $_POST[$bulk_image_buffer];
									unlink('../banners/'.$buffer_image);
								
								}		
								
								
								generateThumbNail("../banners/".$assignedname,"../banners/".$assignedname,174,54);
								
																									  
							}					
							
							
							
						}
						 
									  
					}					  
								  
				}
							  
		}
						
	if($image_flag == 0)
	{
	
		$message = DET_UPD."!!";
	
	}
		
}
?>

<script>
function checkAddBannerForm()
{

  var form_name = new Array('txtBannerName','txtBannerLocation','txtBannerImage');		
  var display_name = new Array('Banner Name','Banner Location Url','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 -->
				
				
				
				
				<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 AFFILIATE_BANNER_MANAGEMENT;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
                    <br>											
					<div align="left">									
					
					<form name="frmProductImages" action="#" method="POST" enctype="multipart/form-data" onSubmit="">
					
					<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
						<tr><td colspan="3">&nbsp;</td></tr>
						<tr><td colspan="3" align="right"><span class="required">*</span>&nbsp;<?php echo FIELDS_ARE_MANDATORY;?></td></tr>
						<tr>
						  <td width="32%" align="left" valign=top>&nbsp;</td>
						  <td width="3%" >&nbsp;</td>
							<td width="65%" align="left" valign=top>
							
																						
<?php

	
	/*$java_script = "<script>
	function checkProductImages()
	{";	*/
	
	
	$select_view_images = "SELECT vaff_banner_name
						   FROM ".$tableprefix."affiliate_banner
						   WHERE 1";
																												   
	$result_view_images = mysql_query($select_view_images) or die(mysql_error());	
	
	$i = 1;
	
	if(mysql_num_rows($result_view_images) > 0)
	{
	
																								
		while($image_view_row = mysql_fetch_array($result_view_images))				
		{							
		
			
		
				$bulk_image_name = "txtImage_".$i;
				$bulk_image_buffer = "txtImageBuffer_".$i;
				
		
?>					
																											
					<tr><td align="right"><?php echo IMAGE;?>&nbsp;<?php echo $i?><span class="required">*</span></td>
					<td>&nbsp;</td>
						<td align="left">
						<input type="file" name="<?php echo $bulk_image_name?>" class="">
						&nbsp;[jpg,gif,png]
						&nbsp;<img src="../banners/<?php echo $image_view_row['vaff_banner_name']?>" height="40" width="60">
						<input type="hidden" name="<?php echo $bulk_image_buffer?>" value="<?php echo $image_view_row['vaff_banner_name']?>">
						</td>
					</tr>
				
					
<?php


			$i++;
		}	
		
	}	
	
	else
	{
										
?>					
							<tr>
									<td align="center" valign="middle" colspan="6"  class="text_information"><?php echo NO_RECORDS_FOUND;?> !!</td>
							</tr>			
								
<?php										
	}
	
?>					
					
					<tr>
						<td colspan="3">&nbsp;</td>
					</tr>
					<tr>
						<td colspan="3" align="center">
							<input type="submit" value="<?php echo BTN_UPDATE;?>" name="update" class="button">
						</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();
?>