<?php
/* 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 (C) 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(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}
if(isset($_REQUEST['stat']) && $_REQUEST['stat']=='Y')
{
	$message="Your products and images saved successfully!.";

}	

$maximagesizestringinPHP = ini_get("upload_max_filesize");
$maximagesizeinPHP = $maximagesizestringinPHP * (1024 * 1024);

$sql_artists="select artist_id,artist_name from ".$tableprefix."artists where vapproved='Y' ";
$rs_id=mysql_query($sql_artists) or die(mysql_error());
$numrows=mysql_num_rows($rs_id);


if(isset($_POST['btnSave']) && $_POST['btnSave']!='')
{ // check button for save 
	
	$message="";
	
		if (!isNotNull($_FILES['txtUploadZip']['name']))
		{
			$message .= "* Upload a CSV file ! <br>";
		}
		$sellerid=$_POST['seller'];
		$uploadfile =ReplaceArrayImage($_FILES['txtUploadZip']['name']); 
		$types=array('csv');
		preg_match('/\.([a-zA-Z]+?)$/', $uploadfile, $matches);
		if(!in_array(strtolower($matches[1]),$types))
					{ // check file format is valid or not 
						$message .= "* Invalid file format for CSV file ! <br>";
					} // end format check 
		
		if (!empty($_FILES['txtUploadZip']['name']))
		{ // moving files to folder
		
			$filename= time() . $_FILES['txtUploadZip']['name'];
			$tempFile=$_FILES['txtUploadZip']['tmp_name'];
			
			$destFolder="../csv/".$filename;
			
			 if ($_FILES['txtUploadZip']['size'] >$maximagesizeinPHP)
		  {
       			 $message.= "*  Size exceeds. Maximum allowed size is $maximagesizestringinPHP.<br>";
		  }
			
			if(is_file($destFolder) && file_exists($destFolder))
			{
				$message .= "* CSV file name already exists, Rename your file and try agian ! <br>";
			} // end if file exists check 
		
			if($message=='')
			{
				 $file=move_uploaded_file($tempFile,$destFolder);
				 if($file)
				 {
				 			header("Location:bulkupload_check.php?file=$filename&sellerid=$sellerid");
				 }
			}
		} // end if 
	
} // end if button check 

include "../includes/htmltop.php";
?>
<script language="JavaScript" type="text/JavaScript">

function clickSearch()
{

	 document.frmProductBulkImages.submit();	
 
}

function blockImages(val)
{


	if(val == 'N')
	{

		return confirm('Are You Sure You Want To Disable The Product Bulk Images !!')
	
	}
	else if(val == 'Y')
	{
	
		return confirm('Are You Sure You Want To Enable The Product Bulk Images !!')
	
	}	
	

}

function deleteImages()
{
			
	return confirm('Are You Sure You Want To Delete The Product Bulk Images !!')
}

</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">Bulk Products Upload</div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
            		<br>
											
					<div align="left">		
					<table>
					<tr><td height="35"><?php include_once("../includes/imagemenu.php")?></td>
					</tr></table>																	
						<form action="" method="post" enctype="multipart/form-data" name="frmbulkupload">
							
						<table width="98%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
						
						<tr>
						  <td colspan="3">Maximum Upload File Size : <b><?php echo $maximagesizestringinPHP;?></b></td>
						  </tr>
						<tr>
						  <td height="33" colspan="3">You can import products to your store from a CSV file. Just download the <a href="../includes/download.php?f=../csv/sample.csv">Sample.CSV</a> and keep the headers the same when you format it. </td>
						  </tr>
						<tr>
						  <td width="33%" height="34" align="right">Select Seller to Upload Products</td>
						  <td width="1%">&nbsp;</td>
						  <td width="66%"><select class="textarea2" name="seller">
						  <?php if($numrows>0)
						  {
						  	while($rr=mysql_fetch_array($rs_id))
							{
							?>
							<option value="<?php echo $rr['artist_id'];?>"><?php echo $rr['artist_name'];?></option>
						<?	
						} // end while
						  } //end if ?>
					      </select></td>
						</tr>
						<tr>
						  <td align="right">Upload CSV File </td>
						  <td>&nbsp;</td>
						  <td><input name="txtUploadZip" type="file" id="txtUploadZip"></td>
						</tr>
						<tr>
						  <td>&nbsp;</td>
						  <td>&nbsp;</td>
						  <td>&nbsp;</td>
						</tr>
						<tr>
						  <td>&nbsp;</td>
						  <td>&nbsp;</td>
						  <td>&nbsp;</td>
						</tr>
						<tr>
						  <td>&nbsp;</td>
						  <td>&nbsp;</td>
						  <td><input type="submit" name="btnSave" value="Next" 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>
				
				
<?
	include "../includes/footer.php";
?>
<script language="javascript">

function valiadtion()

{
		if(document.frmbulkupload.txtBulkUpload.value=="")
		{
		
			alert("Please Upload Your file");
			document.frmbulkupload.txtBulkUpload.focus();
			return false;
		
		}
		if(document.frmbulkupload.seller.value=="")
		{
		
			alert("Please select a seller");
			document.frmbulkupload.seller.focus();
			return false;
		
		}
		
		
		else
		{
		
		return true;
		
	}	

}

</script>