<?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 = PRO_IMAGES_SAVED."!.";
}

$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_CSV."<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 .= "* ".MSG_INVALID_CSV. " ! <br>";
    } // end format check 

    if (!empty($_FILES['txtUploadZip']['name'])) { // moving files to folder
                        $filename = $_FILES['txtUploadZip']['name'];
                        $file_extn = end(explode(".",$filename));
                        $filename = "csv_".rand().$file_extn;
			$tempFile=$_FILES['txtUploadZip']['tmp_name'];
			$destFolder="../csv/".$filename;

        if ($_FILES['txtUploadZip']['size'] > $maximagesizeinPHP) {
            $message.= "* ".SIZE_EXCEEDS.$maximagesizestringinPHP.".<br>";
        }

        if (is_file($destFolder) && file_exists($destFolder)) {
            $message .= "* ".CSV_ALREADY_EXIST. "<br>";
        } // end if file exists check 
 //echo $message;
        if ($message == '') {
			
            $file = move_uploaded_file($tempFile, $destFolder);
           
            if ($file) { //echo "wwww";
				//header("Location:index.php");
                header("Location:bulkupload_check.php?file=$filename&sellerid=$sellerid");
                exit();
            }
        }
    } // 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('<?php echo DISABLE_BULKIMG;?>')
	
        }
        else if(val == 'Y')
        {
	
            return confirm('<?php echo ENABLE_BULKIMG;?>')
	
        }	
	

    }

    function deleteImages()
    {
			
        return confirm('<?php echo DELETE_BULKIMG;?>')
    }

</script>

<body>

<center>

    <div align="right" id="layout">




        <!--header area start -->
        <?php
        include_once("../includes/topheader_admin.php")
        ?>

        <!--header area end -->




        <div align="right" class="main_body">
            <!--main body start -->



            <?php
            include_once("../includes/admintopmenu.php")
            ?>		


            <div align="right" class="content_area">

                <!--content area start -->

                <div align="left" class="page_title"><?php echo BULK_PRO_UPLOAD;?></div>
                <div align="center" class="text_information grey_tr"><?php echo $message ?></div>
                <br>

                <div align="right">		
                    <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" align="left"><?php echo MAX_UPLOAD_SIZE;?> : <b><?php echo $maximagesizestringinPHP; ?></b></td>
                            </tr>
                            <tr>
                                <td height="33" colspan="3" align="left"><h4><?php echo MSG_DWNLD_CSV.JUST_DWNLD?> <a href="../includes/download.php?f=../csv/sample.csv" class="csvlink"><?php echo SAMPLE_CSV;?>.</a> <?php echo KEEP_HEADER_SAME;?>. </h4></td>
                            </tr>


                            <tr>
                                <td height="33" colspan="3" align="left"><b><i><?php echo NOTE;?> : </i></b>  <?php echo MSG_NO_BULK_UPLD;?>.</td>
                            </tr>
                            <tr>
                            <td width="33%" height="34" align="right"><?php echo SELECT_SELLER;?></td>
                             <td width="1%">&nbsp;</td>
                                <td width="66%" align="left"><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>
                                                <?php
                                            } // end while
                                        } //end if 
                                        ?>
                                    </select></td>
                               
								
                            </tr>
                            <tr>
                            	<td align="right"><?php echo UPLOAD_CSV_FILE;?> </td>
								 <td>&nbsp;</td>
                                <td align="left"><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 align="left"><input type="submit" name="btnSave" value="<?php echo NEXT;?>" class="button"></td>                                
                                <td>&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";
        ?>
        <script language="javascript">

            function valiadtion()

            {
                if(document.frmbulkupload.txtBulkUpload.value=="")
                {
		
                    return confirm("<?php echo PLS_UPLOAD_FILE;?>");
                    document.frmbulkupload.txtBulkUpload.focus();
                    return false;
		
                }
                if(document.frmbulkupload.seller.value=="")
                {
		
                	return confirm("<?php echo PLS_SEL_SELLER;?>");
                    document.frmbulkupload.seller.focus();
                    return false;
		
                }
		
		
                else
                {
		
                    return true;
		
                }	

            }

        </script>