<?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 © 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_artistid"]) and $_SESSION["sess_artistid"]!= ""){
	$artistid = $_SESSION["sess_artistid"];
}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);

// check if bulk upload Enabled in Settins

	$qry="select * from ".$tableprefix."settings ";
	$rs_q=mysql_query($qry) or die(mysql_error());
	
	
	if(mysql_num_rows($rs_q)>0)
	
		{ // check number of rows 
		
			$rr_settings=mysql_fetch_array($rs_q);
			$chkupload=$rr_settings['enable_bulkupload'];
		
		} // end check 
	

// end check 

$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 
		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=$_FILES['txtUploadZip']['name'];
			$tempFile=$_FILES['txtUploadZip']['tmp_name'];
			
			$finalFile="sample_".time().$filename;
			$destFolder="../csv/$finalFile";
			
			 if ($_FILES['txtUploadZip']['size'] >$maximagesizeinPHP)
		  {
       			 $message.= "*  Size exceeds. Maximum allowed size is $maximagesizestringinPHP.<br>";
		  }
			
			if(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:mybulkupload_check.php?file=$finalFile&sellerid=$artistid");
				 }
			}
		} // 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_seller.php")

?>
				
				<!--header area end -->
				
				
				
				
				<div align="left" class="main_body">
				<!--main body start -->
				
				
				
<?php
		include_once("../includes/artisttopmenu.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">																			
						<form action="" method="post" enctype="multipart/form-data" name="frmbulkupload">
					<?php if($chkupload=='Y'){ ?>		
						<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.  <a href="../includes/download.php?f=../csv/sample.csv">Click Here to Download Sample CSV File</a> for format . keep the headers as the same for formatting.</td>
						  </tr>
						<tr>
						  <td width="26%" height="38">Upload CSV File </td>
						  <td width="1%">:</td>
						  <td width="73%"><input name="txtUploadZip" class="textarea" 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>
						
						<? } // end if check bulk upload ?>
						
						<?php if($chkupload=='N') { // Bulk Upload is not enabled then ?>
						<table width="98%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
						<tr>
						  <td height="29" colspan="3" align="center" class="text_information">Product Bulk Uploading is not Enabled, Contact with the Administrator to Enable Bulk Upload</b></td>
						  </tr>
						<tr>
						  <td colspan="3">&nbsp;</td>
						  </tr>
						
						</table>
						
						<? } // end if ?>
						
					  </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>