<?php
	require_once('upload_func.php');	
	require_once(SABLE_CLASS_PATH.'sable_file_browser.php');
	require(SABLE_WORKING_PATH.'includes/list_header.php');
	SableSystem::verifySession();

	$field 		=	$_SERVER['argv'][0];
	$imgField 	=	$_SERVER['argv'][1];
	$fileType 	=	$_SERVER['argv'][2]; //1,2 = image, 3=downloadable document
	$multi		=	$_SERVER['argv'][3]; //true = allow upload of multiple files, false = 1 file only
	//SableDebug::debug($_SERVER['argv']);
	//var_dump($multi);
	if ($multi==="true") //$_SERVER['argv'] comes as a string in the parameter list!!
	{
		$heading 	= 	"Please browse for the files you wish to upload.";
		$mm			=	"multiple";
		$nm			= 	"edtFileName[]";
	}
	else
	{
		$heading 	= 	"Please browse for the file you wish to upload.";
		$mm			=	"";
		$nm			= 	"edtFileName";
	}
	/*
	debug($heading);
	debug($mm);
	debug($nm);
	*/
	switch ($fileType)
	{
		case("1"):{$filePath = SABLE_WORKING_PATH.'media/images/';			break;} //images	
		case("2"):{$filePath = SABLE_WORKING_PATH.'media/images/stock/'; 	break;} //stock
		case("3"):{$filePath = checkAccessLevel('media/images/profile/'); 	break;} //profile
		case("4"):{$filePath = SABLE_WORKING_PATH.'media/images/gallery/'; 	break;} //gallery
		case("5"):{$filePath = SABLE_WORKING_PATH.'media/images/blog/'; 		break;} //blog
		case("6"):{$filePath = SABLE_WORKING_PATH.'media/images/filetypes/'; 	break;} //filetypes	
		case("7"):{$filePath = checkAccessLevel('media/images/inspection/'); 	break;} //inspection
			
		case("10"):{$filePath = SABLE_WORKING_PATH.'media/videos/';				break;}	//videos
		case("20"):{$filePath = checkAccessLevel('media/downloads/'); 			break;} //downloads/documents
		case("30"):{$filePath = SABLE_WORKING_PATH.'media/audio/'; 				break;} //audio

		default	 :{$filePath = SABLE_WORKING_PATH.'media/images/gallery'; 	break;} //user profile
	}
	
	$ft = intval($fileType);
	$cc = ($ft === 3) || ($ft === 20);
	$browser = new SableFileBrowser($filePath);
	$browser->getDirContents('',$cc);
?> 
<p><label class="title">Browse for a file to upload</label></p>
<p></p>
<form id="frmUpload" name="frmUpload" enctype="multipart/form-data" action="upload_val.php" method="post" style="height:25vh;">
    <input type="hidden" value="<?php echo($field)?>" 		name="hddnField" 	id="hddnField"/>
    <input type="hidden" value="<?php echo($imgField)?>" 	name="hddnImgField"	id="hddnImgField"/>
    <input type="hidden" value="<?php echo($fileType)?>" 	name="hddnFileType" id="hddnFileType"/>
    <input type="hidden" value="<?php echo($multi)?>" 		name="hddnMulti" 	id="hddnMulti"/>
    <?php 	
	if (SABLE_UPLOAD_PROGRESS)
	{ 
		$id = ini_get("session.upload_progress.name");
	?>
    <input type="hidden" name="<?php echo($id); ?>" id="<?php echo($id); ?>" />
    <?php 	
	} 
	?>
    <div class="forms"> 
        <p></p>
        <!--// file -->
        <div class="container">
            <div class="forms-grids">
                <div class="col-md-4 forms-grid">
                    <div class="fallback">
                        <input class="textbox" name="<?php echo($nm)?>" type="file" id="edtFileName" tabindex="1"
                        <?php echo($mm); ?> onkeypress="handleEnter(this, event)" style="width:100%" />			
                    </div>
                </div>                
                <div class="clearfix"> </div>
            </div>
        </div>
        <p></p>
        <!-- file //-->           
        <p></p>
        <!--// buttons -->
        <div class="container">
            <div class="forms-grids">
                <div class="col-lg-1 col-md-1 col-sm-2 col-xs-2 forms-grid">                            
                    <input type="button" class="submit" id="btnOk" value="Upload" onClick="doUpload();"/>
                </div> 
                <p></p>           
                <div class="col-lg-1 col-md-1 col-sm-2 col-xs-2 forms-grid">                            
                    <input type="button" class="submit" id="btnCancel" value="Cancel" onclick="window.close();" />
                </div>
            </div>                                            
        </div> 
        <!-- buttons //--> 
        <p></p> 
        <div class="container">
            <div class="forms-grids">
                <div class="col-md-1 forms-grid">                            
                    <img src="" id="uploadProgress" width="100%"/>
                </div>
            </div>                                            
        </div>          
    </div>
</form>

<?php 
	//include_once(SABLE_WORKING_PATH.'upload/upload_library.php'); 
	if(SABLE_UPLOAD_PROGRESS){ ?>
<div id="bar_blank"><div id="bar_color"></div></div>
<div id="status"></div>
<iframe id="hidden_iframe" name="hidden_iframe" src="about:blank"></iframe>
<?php } ?>
<script src="upload.js"></script>
<?php require(SABLE_WORKING_PATH.'includes/list_footer.php'); ?>