<?php 
session_start();
ob_start();
include("../leadsnew/branch_connection.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_company(){
             var ccompany = $('#ccompany').val();
             var cprefix = $('#cprefix').val();
             var ccontact = $('#ccontact').val();
             var cmob = $('#cmob').val();
             var cemail = $('#cemail').val();
             var caddress = $('#caddress').val();
             var ccountry = $('#ccountry').val();
             var cstate = $('#cstate').val();
             var cdistrict = $('#cdistrict').val();
             var cstatus = $('#cstatus').val();
             if(ccompany == ''){
                alert("Enter The Company");   	
             } else if(cmob == ''){
             	alert("Enter Mobile");
             } else if(caddress == ''){
             	alert("Enter Address");
             } else {                    
                  $.ajax({
                    type: "POST",
                    url: "ajaxmarket.php",
                     data: {
                          add_new_company: 1,
                          ccompany     : ccompany,
                          cprefix      : cprefix,
                          ccontact     : ccontact,
                          cmob         : cmob,
                          cemail       : cemail,
                          caddress     : caddress,
                          ccountry     : ccountry,
                          cstate       : cstate,
                          cdistrict    : cdistrict,
                          cstatus     : cstatus
                     },
                     cache: true,
                     success: function(res23)
                     {
                     	   	$('#ccompany').val('');
                     	   	$('#cprefix').val('');
                     	   	$('#ccontact').val('');
                           	$('#cmob').val('');
                           	$('#cemail').val('');
                           	$('#cstate').val('');
                           	$('#cdistrict').val('');
                           	$('#caddress').val('');
                           	$('#ccountry').val('');
                           	$('#cstatus').val('');   
                           	$("#marketingdiv123").load("company.php #marketingdiv123");   
                            datat2();                    
                      }
                   }); 
    	    }
        }
              
   function edit_news_company()
   {
             var ccompany = $('#ccompany').val();
             var cprefix = $('#cprefix').val();
             var ccontact = $('#ccontact').val();
             var cmob = $('#cmob').val();
             var cemail = $('#cemail').val();
             var caddress = $('#caddress').val();
             var ccountry = $('#ccountry').val();
             var cstate = $('#cstate').val();
             var cdistrict = $('#cdistrict').val();
             var cstatus = $('#cstatus').val();
             var hidvall = $('#hidvall').val();
             
             if(ccompany == ''){
                alert("Enter Company Name");   	
             } else if(cmob == ''){
             	alert("Enter Mobile");
             } else if(caddress == ''){
             	alert("Enter Address");
             } else {                    
                  $.ajax({
                    type: "POST",
                    url: "ajaxmarket.php",
                     data: {
                          edit_new_company: 1,
                          ccompany     : ccompany,
                          cprefix      : cprefix,
                          ccontact     : ccontact,
                          cmob         : cmob,
                          cemail       : cemail,
                          caddress     : caddress,
                          ccountry     : ccountry,
                          cstate       : cstate,
                          cdistrict    : cdistrict,
                          cstatus      : cstatus,
                          hidvall      : hidvall
                     },
                     cache: true,
                     success: function(res23)
                     {
                     	   	$('#ccompany').val('');
                     	   	$('#cprefix').val('');
                     	   	$('#ccontact').val('');
                           	$('#cmob').val('');
                           	$('#cemail').val('');
                           	$('#cstate').val('');
                           	$('#cdistrict').val('');
                           	$('#caddress').val('');
                           	$('#ccountry').val('');
                           	$('#cstatus').val('');   
                           	$("#marketingdiv123").load("company.php #marketingdiv123");   
                            datat2();                    
                      }
                   }); 
    	       }   
        }
        
      	function delete_company(id)
    	{
    		var result = confirm("Want to delete?");
			if (result) 
			{
     		$.ajax({
			type: "POST",
			url: "ajaxmarket.php",
			data: {
			btn_delete_company: 1,
			id:id
			},
			cache: true,
			success: function(res)
			{
			      $("#marketingdiv123").load("company.php #marketingdiv123");
			      datat();
        	}  
			});
   			}
    	}
    	
    	
    	function edit_company(id)
    	{
    		$.ajax({
			type: "POST",
			url: "ajaxmarket.php",
			data: {
			btn_edit_market: 1,
			id:id
			},
			cache: true,
			success: function(res)
			{
		     	$("#marketingdiv2").load("company.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("cdistrict").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> Company
          	<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">Company</li> 
          </ol>
        </section>
  <!-- Main content -->
  <section class="content" >
   

<div class="box-body" id="marketingdiv2">
 <?php
    
      if(empty($_GET)){
        
      //$idd2 = strip_tags(base64_decode($_GET['idd2']));
      $comp11='';
      $prefix11='';
      $conpers11='';
      $mob11='';
      $email11='';
      $address11='';
      $status11='';
      }else{
     
      $idd2 = strip_tags(base64_decode($_GET['idd2']));
	    $sq = mysqli_query($conn, "SELECT * FROM `p_company` WHERE `cid`='$idd2' " );
	    $rs = mysqli_fetch_assoc($sq);
      $comp11=$rs['c_conpers'];
      $prefix11=$rs['c_prefex'];
      $conpers11=$rs['c_conpers'];
      $mob11=$rs['c_mob'];
      $email11=$rs['c_email'];
      $address11=$rs['c_address'];
      $status11=$rs['c_status'];
      }	  
 ?>	  	
<div class="box-body" >
<div class="row">	
<div class="col-md-12" >

<div class="col-md-4"  style="padding-left:2px;padding-right: 0px; ">					
<div class="form-group">
	<input type="text" name="ccompany" id="ccompany" class="form-control" placeholder="Company Name" value="<?php echo $comp11; ?>"/>	
</div></div>

<div class="col-md-2" style="padding-left:2px;padding-right: 0px;">					
  <div class="form-group">
	<input type="text" name="cprefix" id="cprefix" class="form-control" placeholder="Prefix" value="<?php echo $prefix11; ?>"/>	
 </div></div>


<div class="col-md-3" style="padding-left:2px;padding-right: 0px; ">					
  <div class="form-group">
	<input type="text" name="ccontact" id="ccontact" class="form-control" placeholder="Contact Person" value="<?php echo $conpers11; ?>"/>	
 </div></div>


 <div class="col-md-3" style="padding-left:2px;padding-right: 0px;" >					
  <div class="form-group">
	<input type="text" name="cmob" id="cmob" class="form-control" placeholder="Mobile" onkeypress="return isNumber(event)" value="<?php echo $mob11; ?>"/>	
 </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="caddress" id="caddress" class="form-control" placeholder="Address" style=" height: 83px;"><?php echo $address11; ?></textarea>  
</div></div>

 <div class="col-md-4" style="padding-left:2px;padding-right: 0px; ">         
  <div class="form-group">
  <input type="email" name="cemail" id="cemail" class="form-control" placeholder="Email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$" value="<?php echo $email11; ?>"/>  
 </div></div>



<div class="col-md-2" style="padding-left:2px;padding-right: 0px;">					
<div class="form-group">
   <select name="ccountry" id="ccountry" class="form-control">
   	<option value="">Country</option>
   	<?php
	$sq2 = mysqli_query($conn,"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['c_country'] == $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="cstate" name="cstate" onchange="state_change(this.value);">
  	<option value="">State</option>
        <?php
        $stmt01 = mysqli_query($conn,"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['c_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="cdistrict" name="cdistrict">
    	<option value="">District</option>
     <?php 
     $dis = $rs['c_district'];
	 $sta = $rs['c_state'];
	 if($sta == ''){
	 	$sta = 'Kerala';
	 }
	 $stmt01 = mysqli_query($conn,"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="cstatus" id="cstatus" 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;float: right;">					
<div class="form-group">
  <?php if(!empty($_GET)){ ?>
<input type="hidden" name="hidvall" id="hidvall" value="<?php echo $rs['cid']; ?>" />
<input type="submit" class="btn btn-primary" name="frasubmit" id="frasubmit" value="Update" onclick="edit_news_company();" style=" float: right; " /> 

<?php } else { ?>
<input type="submit" class="btn btn-primary" name="frasubmit" id="frasubmit" value="Submit" onclick="add_new_company();" 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>#</th>                    	
                    <th>Company</th>
                    <th>Prefix</th>
                    <th>Contact Person</th>
                    <th>Mobile</th>
                    <th>State</th>
                    <th>Status</th>
                    <th></th>
                    </tr>
                    </thead>
                    <tbody>
   <?php 
    $sql2 = mysqli_query($conn,"SELECT * FROM `p_company` ORDER BY cid DESC ");
	$k=1;
    while($res2 = mysqli_fetch_assoc($sql2)) { 
   ?>                 	
                    <tr>
                    <td><?php echo $k; ?></td>
                    <td><?php echo $res2['c_comp']; ?></td>
                    <td><?php echo $res2['c_prefex']; ?></td>
                    <td><?php echo $res2['c_conpers']; ?></td>
                    <td><?php echo $res2['c_mob']; ?></td>
                    <td><?php echo $res2['c_state']; ?></td>
                    <td><?php if($res2['c_status'] == '1'){ echo "Active"; } else { echo "InActive"; } ?></td>
                    <td>
     &nbsp;  <a href="" data-toggle="modal" data-target="#myModal<?php echo $res2['cid']; ?>" style=" cursor: pointer;"><span class="glyphicon glyphicon-eye-open" style="font-size:14px;"></span></a> &nbsp;                	
    <a onClick="edit_company('<?php echo base64_encode($res2['cid']); ?>');" style=" cursor: pointer;" ><span class="fa fa-pencil" style="font-size:14px;"></span></a> &nbsp; 
    <a onClick="delete_company('<?php echo base64_encode($res2['cid']); ?>');" 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['cid']; ?>" 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">Company 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;">Prefix </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res2["c_prefex"]; ?></div>
   
    <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Contact Person </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res2["c_conpers"]; ?></div>
     <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Mobile </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res2["c_mob"]; ?></div>
      <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Email </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res2["c_email"]; ?></div>
       <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Address </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res2["c_address"]; ?></div>
        <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Country </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res2["c_country"]; ?></div>
        
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">State </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res2["c_state"]; ?></div>
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">District </div><div style="width:375px;">: &nbsp;&nbsp; <?php echo $res2["c_district"]; ?></div>
   <div style=" float:left; width:150px;font-size:14px;color:#0000FF;">Status </div><div style="width:375px;">: &nbsp;&nbsp; <?php if($res2["c_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>
          
</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>
      $(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>
