<?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">
    <!-- 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">
    <!-- iCheck -->
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    
      <!-- DataTables -->
    <link rel="stylesheet" href="<?php echo $sujpath; ?>plugins/datatables/dataTables.bootstrap.css">
    
    <script>
    	function add_cat(){
    		var gcat = $('#gcat').val();
            var gstat = $('#gstat').val();
            if(gcat == ''){
            	alert("Enter The Category");
            	return false;
            }  else {
            $.ajax({
                type: "POST",
                url: "ajaxmarket.php",
                data: {
                    add_cat_gal    : 1,
                    gcat           : gcat,
                    gstat          : gstat                   
                },
                cache: true,
                success: function(res09)
                {
                      $('#gcat').val('');
                      $("#marketingdiv123").load("gallery.php #marketingdiv123");
                      datat2();
                }
            });
          }
    	}
    	
    	
      function add_gal()
      {
      var galcat = $('#galcat').val();
      var gal_img_up =1;
      var input = document.getElementById("file1");
      file = input.files[0];
      if(file != undefined){
      formData= new FormData();
      if(!!file.type.match(/image.*/)){
      formData.append("image", file);
      
      formData.append("galcat", galcat);
      formData.append("gal_img_up", gal_img_up);
        $.ajax({
        url: "ajaxmarket.php",
        type: "POST",
        data: formData,
        processData: false,
        contentType: false,
        cache: false,
        success: function(data){
        	$('#galcat').val('');
        	
           // $("#marketingdiv123").load("gallery.php #marketingdiv123");
            $("#tab_2").load("gallery.php #tab_2");
           datat2();
        }
     });   
   		
    }else{
      alert('Not a valid image!');
    }
  }else{
    alert('Please Enter Values');
  }    		
  }
        
        
        
        
        function delete_gal(id)
    	{
    		var result = confirm("Want to delete?");
			if (result) 
			{
     		$.ajax({
			type: "POST",
			url: "ajaxmarket.php",
			data: {
			btn_delete_gall: 1,
			id:id
			},
			cache: true,
			success: function(res)
			{
			     //$("#marketingdiv123").load("gallery.php #marketingdiv123");
			      $("#tab_2").load("gallery.php #tab_2");
			      datat();
    		}  
			});
   			}
    	}
    	
    	
    	
    	function delete_cat(id)
    	{
    		var result = confirm("Want to delete?");
			if (result) 
			{
     		$.ajax({
			type: "POST",
			url: "ajaxmarket.php",
			data: {
			btn_delet_cat: 1,
			id:id
			},
			cache: true,
			success: function(res)
			{
			      $("#marketingdiv123").load("gallery.php #marketingdiv123");
			      datat();
         	
			}  
			});
   			}
    	}
    	
    	
    	
    	function edit_cat(id)
    	{
    		$.ajax({
			type: "POST",
			url: "ajaxmarket.php",
			data: {
			btn_edit_market: 1,
			id:id
			},
			cache: true,
			success: function(res)
			{
	           $("#gal_catid").load("gallery.php?idd2="+id+" #gal_catid");
	        }  
			});
    	 }
    	 
    	 
    	 
    	 function edit_cat_update()
        {
            var gcat = $('#gcat').val();
            var gstat = $('#gstat').val();
            var hidcat = $('#hidcat').val(); 
          
            $.ajax({
                type: "POST",
                url: "ajaxmarket.php",
                data: {
                    edit_cat_up    : 1,
                    gcat           : gcat,
                    gstat          : gstat,
                    hidcat         : hidcat
                },
                cache: true,
                success: function(res09)
                { 
                	   $('#gcat').val('');
                       $('#gstat').val('');
                      $("#marketingdiv123").load("gallery.php #marketingdiv123");
                      //$("#tab_2").load("gallery.php #tab_2"); 	
                      //$("#gal_catid").load("gallery.php #gal_catid");
                       datat3();
                }
              });

           }
           
           
           
           function edit_gal(id)
    	   {
    		$.ajax({
			type: "POST",
			url: "ajaxmarket.php",
			data: {
			btn_edit_market: 1,
			id:id
			},
			cache: true,
			success: function(res)
			{
	           $("#gal_imgid").load("gallery.php?idd3="+id+" #gal_imgid");
	        }  
			 });
    	    }
    	    
    	    
    	    
     function edit_gal_up()
     {
        var galcat = $('#galcat').val();
        var hiddgal = $('#hiddgal').val();
        var gal_edit_data =1;
        var input = document.getElementById("file1");
      file = input.files[0];
      if(file != undefined){
      formData= new FormData();
      if(!!file.type.match(/image.*/)){
      formData.append("image", file);
      formData.append("galcat", galcat);
      formData.append("hiddgal", hiddgal);
      formData.append("gal_edit_data", gal_edit_data);
        $.ajax({
        url: "ajaxmarket.php",
        type: "POST",
        data: formData,
        processData: false,
        contentType: false,
        cache: false,
        success: function(data){
        	$('#galcat').val('');
        	//$("#marketingdiv2").load("logo.php #marketingdiv2");
           // $("#marketingdiv123").load("gallery.php #marketingdiv123");
              $("#tab_2").load("gallery.php #tab_2");
           datat2();
        }
     });   
   		
    }else{
      alert('Not a valid image!');
    }
  }else{
    alert('Please Enter Values');
  }    		
  }
    	    
    	</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>
           Gallery 
           <small>- Control panel</small> 
          </h1>  
          <ol class="breadcrumb">
            <li><a href="<?php echo $sujpath; ?>dash_board.php"><i class="fa fa-dashboard"></i> Home</a></li>
          </ol>
          </section>

       
       
        <!-- Main content -->
        <section class="content">

        
        
        
         <div class="row">
            <div class="col-md-12">
            	
        
        <br>
        <div id="marketingdiv123">
        
          <div class="row">
            <div class="col-md-12">
              <!-- Custom Tabs -->
              <div class="nav-tabs-custom">
                <ul class="nav nav-tabs">
                  <li class="active"><a href="#tab_1" data-toggle="tab" style="background-color	:#696969; color:#FFFFFF; width: 133px;">Category</a></li>
                  <li><a href="#tab_2" data-toggle="tab" style="background-color:#696969;width: 133px;color:#FFFFFF;">Gallery</a></li>
                 
                  
                </ul>
                <div class="tab-content">
                  <div class="tab-pane active" id="tab_1">
                    <!--<b>Add Category</b> --><br>
                    
          <div id="gal_catid">
          	          
         <div class="row" >
            <div class="col-xs-12" >
       <?php
      $idd2 = strip_tags(base64_decode($_GET['idd2']));
	  $sql2= $db_con->prepare("SELECT * FROM `cat` WHERE `cid`='$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">
      <input type="text" class="form-control" id="gcat" name="gcat" placeholder="Category*" value="<?php echo $resul2['cname']; ?>" >
      </div></div>	
   
      <div class="col-md-3"  style=" padding-left: 2px; padding-right: 0px; ">				
      <div class="form-group">
      <select name="gstat" id="gstat" class="form-control">
      	<option value="1" <?php if($resul2['cstatus'] == '1'){ ?> selected <?php } ?>>Active</option>
        <option value="0" <?php if($resul2['cstatus'] == '0'){ ?> selected <?php } ?>>InActive</option>
      </select>
      </div></div>	
      
        <div class="col-md-3"  style=" padding-left: 2px; padding-right: 0px; ">				
      <div class="form-group">
      <?php if($idd2 != ''){ ?>	
      	<input type="hidden" name="hidcat" id="hidcat" value="<?php echo $resul2['cid']; ?>" />
      	<input type="submit" class="btn btn-primary" name="frasubmit" id="frasubmit" value="Update" onclick="edit_cat_update();" />
      <?php } else { ?>
      	<input type="submit" class="btn btn-primary" name="frasubmit" id="frasubmit" value="Submit" onclick="add_cat();" />
      <?php } ?>	
      </div></div>	
      
      </div></div>

      </div>




   <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: 25px;">#</th>                    	
                     <th>Category</th>
                     <th>Status</th>
                     <th></th>
                    </tr>
                    </thead>
                    <tbody>
 
 <?php
 $sq2= $db_con->prepare("SELECT * FROM `cat` ORDER BY `cid` DESC ");
 $sq2->execute();
 $k=1;
 while($res2=$sq2->fetch(PDO::FETCH_ASSOC)){
 ?>
  <tr>
  	<td><?php echo $k; ?></td>
  	 <td style=" text-align: center;"><?php echo $res2['cname']; ?></td>
  	 <td ><?php if($res2['cstatus'] == 1) { echo "Active"; } else { echo "InActive"; } ?></td>
    <td >
    <a onClick="edit_cat('<?php echo base64_encode($res2['cid']); ?>');" style=" cursor: pointer;" ><span class="fa fa-pencil" style="font-size:14px;"></span></a> &nbsp; &nbsp;
    <a onClick="delete_cat('<?php echo base64_encode($res2['cid']); ?>');" 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><!-- /.tab-pane -->
    






             
        <div class="tab-pane" id="tab_2">
        <br>  
            
        <div id="gal_imgid">
        <?php 
        $idd3 = strip_tags(base64_decode($_GET['idd3']));
		$sj = $db_con->prepare("SELECT * FROM `gallry` WHERE `gid`= '$idd3' ");
		$sj->execute();
		$rj=$sj->fetch(PDO::FETCH_ASSOC);
        ?> 	          
        <div class="row" >
        <div class="col-xs-12" >
             
        <div class="col-md-3"  style=" padding-left: 2px; padding-right: 0px; ">				
        <div class="form-group">
        <select name="galcat" id="galcat" class="form-control">
         <option value="">Select Category</option>
         <?php
         $sq = $db_con->prepare("SELECT * FROM `cat`");
         $sq->execute();
         while($rs=$sq->fetch(PDO::FETCH_ASSOC)){ 
         if($rs['cid'] == $rj['gcat']){		?>
        <option value="<?php echo $rs['cid']; ?>" selected><?php echo $rs['cname']; ?></option> 	
         <?php } else { ?>	
         <option value="<?php echo $rs['cid']; ?>"><?php echo $rs['cname']; ?></option>
         <?php } } ?>
        </select>
        </div></div>
        	
         <div class="col-md-4"  style=" float: left; ">				
         <div class="form-group">
         <input id="file1" type="file" name="file1"  />
          
          <!--<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($rj['gimg'] != ''){ ?>
		   	<img id="uploadPreview1" src="../images/gallery/<?php echo $rj['gimg']; ?>" style="width:65px;" /><br />	
		   	<?php } else { ?> 
		    <img id="uploadPreview1" src="noimage.png" style="width:85px; height:65px;" /><br />
		    <?php } ?> 
			<span><input id="file1" type="file" name="file1" onchange="PreviewImage(1);" /></span>
			</label>
	   </div> -->
	   
	   
          
         </div></div>	
        
        
        <div class="col-md-3"  style=" padding-left: 2px; padding-right: 0px; ">				
        <div class="form-group">
        <?php if($idd3 != ''){ ?>
        <input type="hidden" name="hiddgal" id="hiddgal" value="<?php echo $rj['gid']; ?>" />	
        <input type="submit" class="btn btn-primary" name="frasubmit2" id="frasubmit2" value="Update" onclick="edit_gal_up();" />	
        <?php } else { ?>	 	
      	<input type="submit" class="btn btn-primary" name="frasubmit2" id="frasubmit2" value="Submit" onclick="add_gal();" />
        <?php } ?>	
        </div></div>	
      
        </div></div>
        
        </div>
        
        
        
         <div class="box-body" >
        <div class="box-body table-responsive no-padding">
   
  	                 	
                  <table id="example2" class="table table-bordered table-striped">
                    <thead >
                     <tr >
                     <th style="width: 25px;">#</th>                    	
                     <th>Category</th>
                     <th>Photo</th>
                     <th></th>
                    </tr>
                    </thead>
                    <tbody>
 
 <?php
 $sq2= $db_con->prepare("SELECT * FROM `gallry` ORDER BY `gid` DESC ");
 $sq2->execute();
 $j=1;
 while($res2=$sq2->fetch(PDO::FETCH_ASSOC)){
$gcat = $res2['gcat']; 	
$sqq=$db_con->prepare("SELECT cname FROM `cat` WHERE `cid`='$gcat' ");
$sqq->execute();
$rss = $sqq->fetch(PDO::FETCH_ASSOC); ?>
  <tr>
  	<td><?php echo $j; ?></td>
  	 <td style=" text-align: center;"><?php echo $rss['cname']; ?></td>
  	 <td><img src="../images/gallery/<?php echo $res2['gimg']; ?>" width="60" height="40"></td>
  	<td >
    <a onClick="edit_gal('<?php echo base64_encode($res2['gid']); ?>');" style=" cursor: pointer;" ><span class="fa fa-pencil" style="font-size:14px;"></span></a> &nbsp; &nbsp;
    <a onClick="delete_gal('<?php echo base64_encode($res2['gid']); ?>');" style=" cursor: pointer;" ><span class="fa fa-trash-o" style="font-size:14px;"></span></a> &nbsp;
    </td>
  </tr> 
  <?php $j=$j+1; } ?>               
                    </tbody>
                    </table>
  
         		  </div>
                </div><!-- /.box-body -->           
                    
                    
                    
                    
                    
                    
                  </div><!-- /.tab-pane -->
                  
                </div><!-- /.tab-content -->
              </div><!-- nav-tabs-custom -->
            </div><!-- /.col -->


      </div>


 </div></div>
        
        
        
        
        
     
</div>


        </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>
    <!-- Morris.js charts -->
    <script src="<?php echo $sujpath; ?>dist/js/app.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>
    <!-- AdminLTE for demo purposes -->
    <script src="<?php echo $sujpath; ?>dist/js/demo.js"></script>
    
     <script type="text/javascript">
    function PreviewImage(no) {
        var oFReader = new FileReader();
        oFReader.readAsDataURL(document.getElementById("uploadImage1"+no).files[0]);

        oFReader.onload = function (oFREvent) {
            document.getElementById("uploadPreview"+no).src = oFREvent.target.result;
        };
    }
   </script>
   
<style>
label.filebutton {
    width:125px;
    height:60px;
    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();
      });
      
      $(document).ready(function() {
        $("#example2").DataTable();
      });
      
   function datat(){
	  alert("Data Deleted Successfully.");
      $(document).ready(function() {
        $("#example1").DataTable();
        $("#example2").DataTable();
      });
    }
    function datat2(){
	  alert("Data Added Successfully");
      $(document).ready(function() {
        $("#example1").DataTable();
        $("#example2").DataTable();       
      });
    }
    function datat3(){
	  alert("Updated Successfully");
      $(document).ready(function() {
        $("#example1").DataTable();
        $("#example2").DataTable();       
      });
    }
   </script>  
   
   
  
  </body>
</html>
