<?php 
session_start();
ob_start();
include("../../pidbco/pidbjoin.php");
if(!isset($_SESSION['franchiseelogin']['user_name'])){
	header("Location : index.php");
}
$sujpath="./";
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title><?php echo $pageTitle; ?></title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>font-awesome/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>font-awesome/ionicons.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>plugins/datatables/dataTables.bootstrap.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>dist/css/skins/_all-skins.min.css">
    <link rel="stylesheet" type="text/css" href="tcal.css" />    
    <script type="text/javascript" src="tcal.js"></script>
    
    <script>
    function banner_add(){
      var topstatus = $('#topstatus').val();		
      var input = document.getElementById("uploadImage1");
      var banner_adds =1;
      file = input.files[0];
  
      if(file != undefined){
      formData= new FormData();
     // if(!!file.type.match(/image.*/)){
      formData.append("image", file);
      formData.append("banner_adds", banner_adds);
      formData.append("topstatus", topstatus);
      
        $.ajax({
        url: "ajaxmarket.php",
        type: "POST",
        data: formData,
        processData: false,
        contentType: false,
        cache: false,
        success: function(data){
            //alert(data);
              $("#marketingdiv2").load("banners.php #marketingdiv2");
              $("#marketingdiv123").load("banners.php #marketingdiv123");
              datat2();
        }
     });   
   		
   /* }else{
      alert('Not a valid image!');
   }  */
  }else{
    alert('Please Enter Values');
  }    
    		
    	}
    	
    	
    	
    
     function edit_banner_up()
     {
      var topstatus = $('#topstatus').val();
      var hidvall = $('#hidvall').val();		
      var banner_edit_up =1;
      var input = document.getElementById("uploadImage1");
      file = input.files[0];
     // if(file != undefined){
      formData= new FormData();
      //if(!!file.type.match(/image.*/)){
      formData.append("image", file);
      formData.append("banner_edit_up", banner_edit_up);
      formData.append("topstatus", topstatus);
      formData.append("hidvall", hidvall);
      
        $.ajax({
        url: "ajaxmarket.php",
        type: "POST",
        data: formData,
        processData: false,
        contentType: false,
        cache: false,
        success: function(data){
        
        	$("#marketingdiv2").load("banners.php #marketingdiv2");
            $("#marketingdiv123").load("banners.php #marketingdiv123");
           datat3();
        }
     });   
   		
   /*  }else{
      alert('Not a valid image!');
    }
  }else{
    alert('Please Enter Values');
  }   */ 

        }
    	
        
    	
    	    	
    	function delete_banner(id)
    	{
    		var result = confirm("Want to delete?");
			if (result) 
			{
     		$.ajax({
			type: "POST",
			url: "ajaxmarket.php",
			data: {
			btn_delete_banners: 1,
			id:id
			},
			cache: true,
			success: function(res)
			{
			      $("#marketingdiv123").load("banners.php #marketingdiv123");
			      datat();
         	
			}  
			});
   			}
    	}
    	
    	
    	function edit_banner(id)
    	{
    		$.ajax({
			type: "POST",
			url: "ajaxmarket.php",
			data: {
			btn_edit_market: 1,
			id:id
			},
			cache: true,
			success: function(res)
			{
			
	         	$("#marketingdiv2").load("banners.php?idd2="+id+" #marketingdiv2"); 	
			}  
			});
    	}
    	
    	
    </script>
    
  </head>
  <body class="hold-transition skin-blue sidebar-mini">
     <div class="wrapper">
  <?php include("head.php");
    include("left.php"); ?> 
	 
      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>Banner
          	<small>- Control panel</small>
          	</h1>
          <ol class="breadcrumb">
            <li><a href="dash_board.php"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Banner</li> 
          </ol>
        </section>
<?php
if(isset($_SESSION['SUCMSG'])){
	echo $_SESSION['SUCMSG'];
	unset($_SESSION['SUCMSG']);
}
?>     <!-- Main content -->
        <section class="content" >
          <div class="row" >
            <div class="col-xs-12" >





   <div class="box-body" id="marketingdiv2">
    	<div class="box-body" >
<?php
      $idd2 = strip_tags(base64_decode($_GET['idd2']));
	  $sql2= $db_con->prepare("SELECT * FROM `gbanner` WHERE `bid`='$idd2' ");
      $sql2->execute();
	  $resul2=$sql2->fetch(PDO::FETCH_ASSOC);	  
?>	 
<div class="col-md-3"  style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">

<div style=" float: left; width:120px; margin-left: 15px; ">
		   	<img src="mainimg.png" />
	</div> 	&nbsp; &nbsp;
	<div style=" float: left; width:80px; margin-left: 15px;">
		   	<label class="filebutton" >
		 	<?php if($resul2['bpic'] != ''){ ?>
		   	<img id="uploadPreview1" src="../images/banner/<?php echo $resul2['bpic']; ?>" style="width:65px;" /><br />	
		   	<?php } else { ?> 
		    <img id="uploadPreview1" src="noimage.png" style="width:85px; height:65px;" /><br />
		    <?php } ?> 
			<span><input id="uploadImage1" type="file" name="uploadImage1" onchange="PreviewImage(1);" /></span>
			</label>
	</div>
	
	
</div></div>	

<div class="col-md-3"  style=" padding-left: 2px; padding-right: 0px; ">					
<div class="form-group">
<select name="topstatus" id="topstatus" class="form-control" >
 	<option value="1" <?php if($resul2['bstatus'] == '1'){ ?> selected <?php } ?>>Active</option>
 	<option value="0" <?php if($resul2['bstatus'] == '0'){ ?> selected <?php } ?>>InActive</option>
    </select>	
</div></div>		
	



<div class="col-md-1"  style=" padding-left: 2px; padding-right: 0px;  ">				
<div class="form-group">
	<?php if($idd2 != ''){ ?>
	<input type="hidden" name="hidvall" id="hidvall" value="<?php echo $resul2['bid']; ?>" />
<input type="submit" class="btn btn-primary" name="frasubmit" id="frasubmit" value="Update" onclick="edit_banner_up();" style=" float: right; 
margin-right: 20px; " /> 

<?php } else { ?>
   <input type="submit" class="btn btn-primary" name="frasubmit" id="frasubmit" value="Submit"  onclick="banner_add();" style=" float: right;"  />
<?php } ?>   
</div></div>



</div>
  </div>
  
  
  
  
  
  
<div id="marketingdiv123">


<div class="box" >
   <div class="box-body" >
        <div class="box-body table-responsive no-padding" >
   
  	                 	
                  <table id="example1" class="table table-bordered table-striped" >
                    <thead >
                     <tr >
 <th style=" width: 30px;">#</th>                    	
 <th>Banner</th>
 <th>Status</th>
 <th></th>
 </tr>
                    </thead>
                    <tbody>
             <?php
             $suj = $db_con->prepare("SELECT * FROM `gbanner` ");
             $suj->execute();
			 $k=1;
             while($rss = $suj->fetch(PDO::FETCH_ASSOC)){
             ?>       	
 <tr>
 	<td><?php echo $k; ?></td>
 	<td><img src="../images/banner/<?php echo $rss['bpic']; ?>" width="50" height="50"></td>
 	<td><?php if($rss['bstatus'] == '1'){ echo "Active"; } else{ echo 'InActive'; } ?></td>
 	<td>
 		<a onClick="edit_banner('<?php echo base64_encode($rss['bid']); ?>');" style=" cursor: pointer;" ><span class="fa fa-pencil" style="font-size:14px;"></span></a> &nbsp; &nbsp;
    <a onClick="delete_banner('<?php echo base64_encode($rss['bid']); ?>');" style=" cursor: pointer;" ><span class="fa fa-trash-o" style="font-size:14px;"></span></a> &nbsp;	
 	</td>
 </tr>
           <?php $k =$k+1; } ?>  
                    </tbody>
                    </table>
  
         		  </div>
                </div><!-- /.box-body -->
              </div><!-- /.box -->
	
	
</div>
	
		
			
			
			








                           
            </div><!-- /.col -->
          </div><!-- /.row -->
        </section><!-- /.content -->
  </div><!-- /.content-wrapper -->
  </div>
	<!-- <?php include("footer.php"); ?> -->
 <!-- jQuery 2.1.4 -->
    <script src="<?php echo $sujpath; ?>plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="<?php echo $sujpath; ?>bootstrap/js/bootstrap.min.js"></script>
    <!-- DataTables -->
	<script src="<?php echo $sujpath; ?>plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="<?php echo $sujpath; ?>plugins/datatables/dataTables.bootstrap.min.js"></script>
    <!-- SlimScroll -->
    <script src="<?php echo $sujpath; ?>plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- FastClick -->
    <script src="<?php echo $sujpath; ?>plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="<?php echo $sujpath; ?>dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="<?php echo $sujpath; ?>dist/js/demo.js"></script>
    <!-- page script -->
    
    <script type="text/javascript">
    function PreviewImage(no) {
    	var oFReader = new FileReader();
        oFReader.readAsDataURL(document.getElementById("uploadImage"+no).files[0]);
        oFReader.onload = function (oFREvent) {
            document.getElementById("uploadPreview"+no).src = oFREvent.target.result;
        };
    }
</script>

<style>
label.filebutton {
    width:120px;
    height:80px;
    overflow:hidden;
    position:relative;
}
label span input {
    z-index: 999;
    line-height: 0;
    font-size: 50px;
    position: absolute;
    top: -2px;
    left: -700px;
    opacity: 0;
    filter: alpha(opacity = 0);
    -ms-filter: "alpha(opacity=0)";
    cursor: pointer;
    _cursor: hand;
    margin: 0;
    padding:0;
}
</style> 

    <script>
      $(document).ready(function() {
        $("#example1").DataTable();
      });
      
	function datat(){
	  alert("Data Deleted Successfully.");
      $(document).ready(function() {
        $("#example1").DataTable();
       
      });
    }
    function datat2(){
	  alert("Data Added Successfully");
      $(document).ready(function() {
        $("#example1").DataTable();
       
      });
    }
    function datat3(){
	  alert("Updated Successfully");
      $(document).ready(function() {
        $("#example1").DataTable();
       
      });
    }
   </script>  
   
  </body>
</html>
