<?php 
session_start();
ob_start();
include("../../pidbco/pidbjoin.php");
$sujpath="./";
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Projects</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">
   
    
    <script>
    function add_new_branch(){
      	     var bcompany = $('#bcompany').val();
             var brname = $('#brname').val();
             var brmob = $('#brmob').val();
             var bremail = $('#bremail').val();
             var braddres = $('#braddres').val();
             var brcountry = $('#brcountry').val();
             var bstate = $('#bstate').val();
             var bdistrict = $('#bdistrict').val();
             var bstatus = $('#bstatus').val();
             if(bcompany == ''){
                alert("Enter Company Name");   	
             } else if(brname == ''){
             	alert("Enter Branch Name");
             } else if(brmob == ''){
             	alert("Enter Mobile");
             } else if(braddres == ''){
             	alert("Enter Address");
             } else {                    
                  $.ajax({
                    type: "POST",
                    url: "ajaxmarket.php",
                     data: {
                          add_new_branch: 1,
                          bcompany      : bcompany,
                          brname        : brname,
                          brmob         : brmob,
                          bremail       : bremail,
                          braddres      : braddres,
                          brcountry     : brcountry,
                          bstate        : bstate,
                          bdistrict     : bdistrict,
                          bstatus       : bstatus
                     },
                     cache: true,
                     success: function(res23)
                     {
                     	   	$('#bcompany').val('');
                           	$('#brname').val('');
                           	$('#brmob').val('');
                           	$('#bremail').val('');
                           	$('#braddres').val('');
                           	$('#brcountry').val('');
                           	$('#bstate').val('');
                           	datat2();
                           	$("#marketingdiv123").load("branch.php #marketingdiv123");   
                                                
                      }
                   }); 
    	    }
     }


    	
    	
   function edit_news_branch()
   {
   	         var bcompany = $('#bcompany').val();
             var brname = $('#brname').val();
             var brmob = $('#brmob').val();
             var bremail = $('#bremail').val();
             var braddres = $('#braddres').val();
             var brcountry = $('#brcountry').val();
             var bstate = $('#bstate').val();
             var bdistrict = $('#bdistrict').val();
             var bstatus = $('#bstatus').val();
             var hidvall = $('#hidvall').val();
             if(bcompany == ''){
                alert("Enter Company Name");   	
             } else if(brname == ''){
             	alert("Enter Branch Name");
             } else if(brmob == ''){
             	alert("Enter Mobile");
             } else if(braddres == ''){
             	alert("Enter Address");
             } else {                    
                  $.ajax({
                    type: "POST",
                    url: "ajaxmarket.php",
                     data: {
                          edit_new_branch: 1,
                          bcompany      : bcompany,
                          brname        : brname,
                          brmob         : brmob,
                          bremail       : bremail,
                          braddres      : braddres,
                          brcountry     : brcountry,
                          bstate        : bstate,
                          bdistrict     : bdistrict,
                          bstatus       : bstatus,
                          hidvall       : hidvall
                     },
                     cache: true,
                     success: function(res23)
                     {
                     	   	$('#bcompany').val('');
                           	$('#brname').val('');
                           	$('#brmob').val('');
                           	$('#bremail').val('');
                           	$('#braddres').val('');
                           	$('#brcountry').val('');
                           	$('#bstate').val('');
                           	$("#marketingdiv123").load("branch.php #marketingdiv123");   
                            datat2();                    
                      }
                   }); 
    	    }
   }
        
        
    	
    	    	
    	function delete_branch(id)
    	{
    		var result = confirm("Want to delete?");
			if (result) 
			{
     		$.ajax({
			type: "POST",
			url: "ajaxmarket.php",
			data: {
			btn_delete_branch: 1,
			id:id
			},
			cache: true,
			success: function(res)
			{
			      $("#marketingdiv123").load("branch.php #marketingdiv123");
			      datat();
         	
			}  
			});
   			}
    	}
    	
    	
    	function edit_branch(id)
    	{
    		$.ajax({
			type: "POST",
			url: "ajaxmarket.php",
			data: {
			btn_edit_market: 1,
			id:id
			},
			cache: true,
			success: function(res)
			{
			
	         	$("#marketingdiv2").load("branch.php?idd2="+id+" #marketingdiv2"); 	
			}  
			});
    	}
    	
    
function state_change(str)
{
  var xmlhttp;
  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
  else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("bdistrict").innerHTML=xmlhttp.responseText;
    }
  }
  xmlhttp.open("GET","ajaxmarket.php?state_idd="+str,true);
  xmlhttp.send();
}
	
    </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> Branch
          	<small>- Control panel</small>
          	</h1>
          <ol class="breadcrumb">
            <li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Branch</li> 
          </ol>
        </section>
  <!-- Main content -->
        <section class="content" >
          <div class="row" >
            <div class="col-xs-12" >





   <div class="box-body" id="marketingdiv2">
 	 <?php
      if(empty($_GET)){
        
      //$idd2 = strip_tags(base64_decode($_GET['idd2']));
      $branch11='';
      $mob11='';
      $email11='';
      $addrs11='';
      $status11='';

      }else{
        $idd2 = strip_tags(base64_decode($_GET['idd2']));
	     $sq = mysqli_query($con, "SELECT * FROM `p_branch` WHERE `bid`='$idd2' " );
	     $rs = mysqli_fetch_assoc($sq);
       $branch11=$rs['b_branchna'];
       $mob11=$rs['b_mob'];
       $email11=$rs['b_email'];
       $addrs11=$rs['b_addrs'];
       $status11=$rs['b_status'];
      }
        
       
 ?>	 
			  	
	<div class="box-body" >
 <div class="row" >	
<div class="col-md-12" style="" >
	
<div class="col-md-3"  style="padding-left: 2px;padding-right: 0px;">					
<div class="form-group">
	<select class="form-control" id="bcompany" name="bcompany">
		<option selected="selected" value="">Select Company</option>
	<?php
	$sq2 = mysqli_query($con,"SELECT cid,c_comp,c_prefex FROM `p_company` ");
	while($res2 = mysqli_fetch_array($sq2)){
		if($rs['b_comp'] == $res2['cid']){
	?>	
	<option value="<?php echo $res2['cid']; ?>" selected><?php echo $res2['c_prefex']; ?></option>
	<?php } else {  ?>
		<option value="<?php echo $res2['cid']; ?>"><?php echo $res2['c_prefex']; ?></option>
    <?php } } ?>		
	</select>	
</div></div>

<div class="col-md-3" style="padding-left: 2px;padding-right: 0px;">					
  <div class="form-group">
	<input type="text" name="brname" id="brname" class="form-control" placeholder="Branch Name" value="<?php echo $branch11; ?>"/>	
 </div></div>
	
 <div class="col-md-3" style="padding-left: 2px;padding-right: 0px;">					
  <div class="form-group">
	<input type="text" name="brmob" id="brmob" class="form-control" placeholder="Mobile" value="<?php echo $mob11; ?>" onkeypress="return isNumber(event)" />	
 </div></div>	
 
  <div class="col-md-3" style="padding-left: 2px;padding-right: 0px;">					
  <div class="form-group">
	<input type="email" name="bremail" id="bremail" class="form-control" placeholder="Email" value="<?php echo $email11 ?>" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$"/>	
 </div></div>
 
 
  
 	
 	</div>	

</div>	


<div class="row" >	
<div class="col-md-12" style="" >


<div class="col-md-6"  style=" padding-left: 2px; padding-right: 0px; ">			
<div class="form-group">
	<textarea name="braddres" id="braddres" class="form-control" placeholder="Address" style=" height: 83px;"><?php echo $addrs11; ?></textarea>	
</div></div>
	
<div class="col-md-2" style="padding-left: 2px;padding-right: 0px;">			
<div class="form-group">
	<select class="form-control" id="brcountry" name="brcountry">
		<option value="">Country</option>
		<?php
	$sq2 = mysqli_query($con,"SELECT id,country_name FROM `countries` ");
	while($res2 = mysqli_fetch_array($sq2)){
	   if($res2['country_name'] == 'India'){ ?>	
	<option value="<?php echo $res2['country_name']; ?>" selected><?php echo ucfirst($res2['country_name']); ?></option>
	<?php } else if($rs['b_countr'] == $res2['country_name']) { ?>
	<option value="<?php echo $res2['country_name']; ?>" selected><?php echo ucfirst($res2['country_name']); ?></option>
	<?php } else { ?>
		<option value="<?php echo $res2['country_name']; ?>"><?php echo ucfirst($res2['country_name']); ?></option>
    <?php } } ?>
	</select>	
</div></div>
			
<div class="col-md-2" style="padding-left: 2px;padding-right: 0px;">			
<div class="form-group">
  <select class="form-control" id="bstate" name="bstate" onchange="state_change(this.value);">
           <option value="">State</option>
    <?php
        $stmt01 = mysqli_query($con,"SELECT * FROM `states` ");
        while($res01 = mysqli_fetch_array($stmt01)) {
        if($res01['state_name'] == 'KERALA'){ ?>
        <option value="<?php echo $res01['state_name']; ?>" selected><?php echo $res01['state_name']; ?></option>	 	
        <?php } else if($rs['b_state'] == $res01['state_name']){ ?>
        <option value="<?php echo $res01['state_name']; ?>" selected><?php echo $res01['state_name']; ?></option>
	    <?php } else { ?>		 
         <option value="<?php echo $res01['state_name']; ?>"><?php echo $res01['state_name']; ?></option>
        <?php } } ?>
  </select> 
</div></div>


<div class="col-md-2" style="padding-left: 2px;padding-right: 0px;">					
<div class="form-group">
    <select class="form-control" id="bdistrict" name="bdistrict">
    	<option value="">District</option>
        <?php 
        $dis = $rs['b_distri'];
	    $sta = $rs['b_state'];
		if($sta == ''){
	 	$sta = 'Kerala';
	    }
	    $stmt01 = mysqli_query($con,"SELECT * FROM `cities` WHERE `state_name`='$sta' ");
        while($res01 = mysqli_fetch_array($stmt01)) {
       	if($res01['cities_name'] == 'Thrissur'){ ?> 
       	<option value="<?php echo $res01['cities_name']; ?>" selected><?php echo $res01['cities_name']; ?></option>
        <?php } else if($res01['cities_name'] == $dis){ ?> 
        <option value="<?php echo $res01['cities_name']; ?>" selected><?php echo $res01['cities_name']; ?></option>	
        <?php } else { ?>	
        <option value="<?php echo $res01['cities_name']; ?>"><?php echo $res01['cities_name']; ?></option>		
       <?php } } ?>
    </select>
</div></div>


<div class="col-md-2" style="padding-left: 2px;padding-right: 0px;">					
<div class="form-group">
    <select name="bstatus" id="bstatus" class="form-control">
  	<option value="1" <?php if($status11 == '1'){ ?> selected <?php } ?>>Active</option>
  	<option value="0" <?php if($status11 == '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(!empty($_GET)){ ?>
	<input type="hidden" name="hidvall" id="hidvall" value="<?php echo $rs['bid']; ?>" />
<input type="submit" class="btn btn-primary" name="frasubmit" id="frasubmit" value="Update" onclick="edit_news_branch();" style=" float: right; " /> 

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

</div>




</div>



	
	

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


<div class="box" >
   <div class="box-body" style="padding-left: 10px;padding-right: 10px" >
        <div class="box-body table-responsive no-padding" >
   
  	                 	
                  <table id="example1" class="table table-bordered table-striped" >
                    <thead >
                    <tr >
<th style="display: none;">#</th>                    	
<th>Company</th>
<th>Branch</th>
<th>Mobile</th>
<th>State</th>
<th>Status</th>
<th></th>
</tr>
                    </thead>
                    <tbody>
<?php 
    $sql2 = mysqli_query($con,"SELECT * FROM `p_branch` AS b, `p_company` AS c WHERE b.`b_comp`= c.`cid` ORDER BY bid DESC");
	$k=1;
    while($res2 = mysqli_fetch_assoc($sql2)) { 
   ?>                 	
                    <tr>
                    <td style="display: none;"><?php echo $k; ?></td>
                    <td><?php echo $res2['c_comp'] . " ( " . $res2['c_prefex'] . " ) "; ?></td>
                    <td><?php echo $res2['b_branchna']; ?></td>
                    <td><?php echo $res2['b_mob']; ?></td>
                    <td><?php echo $res2['b_state']; ?></td>
                    <td><?php if($res2['b_status'] == '1'){ echo 'Active'; } else { echo 'InActive'; } ?></td>
                    <td>
    &nbsp; <a href="" data-toggle="modal" data-target="#myModal<?php echo $res2['bid']; ?>" style=" cursor: pointer;"><span class="glyphicon glyphicon-eye-open" style="font-size:14px;"></span></a> &nbsp;                	
    <a onClick="edit_branch('<?php echo base64_encode($res2['bid']); ?>');" style=" cursor: pointer;" ><span class="fa fa-pencil" style="font-size:14px;"></span></a> &nbsp; 
    <a onClick="delete_branch('<?php echo base64_encode($res2['bid']); ?>');" style=" cursor: pointer;" ><span class="fa fa-trash-o" style="font-size:14px;"></span></a> &nbsp;	
                    </td>
                    </tr>
                    
                    
 <div class="modal fade" id="myModal<?php echo $res2['bid']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header" style=" background-color: #E8E8E8;">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Branch Details</h4>
      </div>
      <div class="modal-body" id="myModal2">
  
 <div style=" width:550px; ">
   <div style=" float:left; width:150px;  font-size:14px; color:#0000FF; ">Company Name</div><div style="width:375px; ">: &nbsp;&nbsp; <?php echo $res2["c_comp"]; ?></div>
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Branch Name </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res2["b_branchna"]; ?></div>
   
     <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Mobile </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res2["b_mob"]; ?></div>
      <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Email </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res2["b_email"]; ?></div>
       <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Address </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res2["b_addrs"]; ?></div>
        <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Country </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res2["b_countr"]; ?></div>
        
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">State </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res2["b_state"]; ?></div>
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">District </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res2["b_distri"]; ?></div>
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Status </div><div style="width:375px;">: &nbsp;&nbsp; <?php if($res2["b_status"] == '1'){ echo "Active"; } else { echo "InActive"; } ?></div>
        

 </div>
  
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
       
      </div>
    </div>
  </div>
</div>           	
    <?php $k = $k+1; } ?>
                    </tbody>
                    </table>
  
         		  </div>
                </div><!-- /.box-body -->
              </div><!-- /.box -->
	
	
</div>
	
		
			
			
			








                           
            </div><!-- /.col -->
          </div><!-- /.row -->
        </section><!-- /.content -->
  </div><!-- /.content-wrapper -->
  </div>
 <!-- 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>
