<?php session_start();
include("./../../config/config.php");
require_once("./validated_admin.php");


/*file upload*/
print_r($_FILES[SESS_MASTER.'upload_banner']['name']);

$type =$_REQUEST[SESS_MASTER.'type'];

if($type=='slider'){
for($k==1;$k<7;$k++){

if($k==1){
	$banner=1;
}
if($k==2){
	$banner=2;
}
if($k==3){
	$banner=3;
}
if($k==4){
	$banner=4;
}
if($k==5){
	$banner=5;
}
if($k==6){
	$banner=6;
}
   
if(!empty($_FILES[SESS_MASTER.'upload_banner'.$k]['name'])){
$company_logoload_flag="true";
$company_logo_size=$_FILES[SESS_MASTER.'upload_banner'.$k]['size'];
if ($_FILES[SESS_MASTER.'upload_banner'.$k]['size']>2500000){
$msg=$msg."Your uploaded file size is more than 2500KB ";
$msg.=" so please reduce the file size and then upload.<BR>";
$company_logoload_flag="false";
}

// allow only jpeg or gif files, remove this if not required //
if (!($_FILES[SESS_MASTER.'upload_banner'.$k]['type']=="image/jpeg" OR $_FILES[SESS_MASTER.'upload_banner'.$k]['type'] =="image/png")){
$msg=$msg."Your uploaded file must be of JPG or GIF. ";
$msg.="Other file types are not allowed<BR>";
$company_logoload_flag="false";}

$file_name=$_FILES[SESS_MASTER.'upload_banner'.$k]['name'];
// the path with the file name where the file will be stored
$add="../../images/banners/banner_".$k.".jpg"; 
$add_data="images/banners/banner_".$k.".jpg";

if($company_logoload_flag=="true"){ // checking the Flag value 
echo $_FILES[SESS_MASTER.'upload_banner'.$k]['name'];
if(!file_exists($add)){
if(move_uploaded_file($_FILES[SESS_MASTER.'upload_banner'.$k]['tmp_name'], $add)){
// do your coding here to give a thanks message or any other thing.
$msg="File successfully uploaded";
}else{
echo "Failed to upload file Contact Site admin to fix the problem";
}
}else{
	unlink($add);
if(move_uploaded_file($_FILES[SESS_MASTER.'upload_banner'.$k]['tmp_name'], $add)){
// do your coding here to give a thanks message or any other thing.
$msg="File successfully uploaded";
}


} }   
else{
$msg .= " Failed to upload file ";
}

 $sqlc = "SELECT * FROM banner_master   WHERE banner='$banner' AND slider_type='banner'";
   
    $myq=$conn->query($sqlc);
  $mydar= $myq->fetchAll()  ;
  
  $rows_fou = $myq->rowCount();
if( $rows_fou>0){
	$olgaquery="UPDATE banner_master SET banner_path='$add_data' WHERE banner='$banner' AND slider_type='banner'"; 
    $stmt = $conn->prepare($olgaquery);
    $stmt->execute();

}else{
$olgaquery="INSERT INTO banner_master SET slider_type='banner',banner='$banner',banner_path='$add_data',activestatus='0'"; 
    $stmt = $conn->prepare($olgaquery);
    $stmt->execute();
}
}
}
}

if($type=='discount'){

	for($k==1;$k<7;$k++){

if($k==1){
	$banner=1;
}
if($k==2){
	$banner=2;
}
if($k==3){
	$banner=3;
}
if($k==4){
	$banner=4;
}
if($k==5){
	$banner=5;
}
if($k==6){
	$banner=6;
}
   
if(!empty($_FILES[SESS_MASTER.'upload_banner'.$k]['name'])){
$company_logoload_flag="true";
$company_logo_size=$_FILES[SESS_MASTER.'upload_banner'.$k]['size'];
if ($_FILES[SESS_MASTER.'upload_banner'.$k]['size']>2500000){
$msg=$msg."Your uploaded file size is more than 2500KB ";
$msg.=" so please reduce the file size and then upload.<BR>";
$company_logoload_flag="false";
}

// allow only jpeg or gif files, remove this if not required //
if (!($_FILES[SESS_MASTER.'upload_banner'.$k]['type']=="image/jpeg" OR $_FILES[SESS_MASTER.'upload_banner'.$k]['type'] =="image/png"))
{$msg=$msg."Your uploaded file must be of JPG or GIF. ";
$msg.="Other file types are not allowed<BR>";
$company_logoload_flag="false";}

$file_name=$_FILES[SESS_MASTER.'upload_banner'.$k]['name'];
// the path with the file name where the file will be stored
$add="./../../images/banners/banner_dis".$k.".jpg"; 
$add_data="images/banners/banner_dis".$k.".jpg";

if($company_logoload_flag=="true"){ // checking the Flag value 
echo $_FILES[SESS_MASTER.'upload_banner'.$k]['name'];
if(!file_exists($add)){
if(move_uploaded_file($_FILES[SESS_MASTER.'upload_banner'.$k]['tmp_name'], $add)){
// do your coding here to give a thanks message or any other thing.
$msg="File successfully uploaded";
}else{
echo "Failed to upload file Contact Site admin to fix the problem";
}
}else{
	unlink($add);
if(move_uploaded_file($_FILES[SESS_MASTER.'upload_banner'.$k]['tmp_name'], $add)){
// do your coding here to give a thanks message or any other thing.
$msg="File successfully uploaded";
}


} }   else{
$msg .= " Failed to upload file ";
}

 $sqlc = "SELECT * FROM banner_master   WHERE banner='$banner' AND slider_type='discount_banner'";
   
    $myq=$conn->query($sqlc);
  $mydar= $myq->fetchAll()  ;
  
  $rows_fou = $myq->rowCount();
if( $rows_fou>0){
	$olgaquery="UPDATE banner_master SET banner_path='$add_data' WHERE banner='$banner' AND slider_type='discount_banner'"; 
    $stmt = $conn->prepare($olgaquery);
    $stmt->execute();

}else{
$olgaquery="INSERT INTO banner_master SET slider_type='discount_banner',banner='$banner',banner_path='$add_data',activestatus='0'"; 
    $stmt = $conn->prepare($olgaquery);
    $stmt->execute();
}
}
}


}
/*file upload*/

 header("location:../banner-slider.php");


?>