<link href="<?php echo site_url();?>assets/css/fSelect.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="<?php echo site_url();?>assets/css/fSelect.js"></script>

<script>
(function($) {
    $(function() {
        $('.test').fSelect();
    });
})(jQuery);
</script>
<div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <h3 class="page-header">Component</h3>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-lg-12">
                       <!--    <a href="<?php echo site_url();?>admin/Company/user_add" class="btn btn-info"> Add User</a>-->
                    <div class="panel panel-default">
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <?php $success_message = $this->session->flashdata('success_message');
                            if (!empty($success_message)) {?>
                                <div class="alert alert-success">
                                      <a class="close" data-dismiss="alert" href="components-popups.html#" aria-hidden="true">×</a>
                                      <strong><?php echo $this->session->flashdata('success_message');  ?></strong>
                                </div> 
                            <?php }  ?>
                            <?php $failure_message = $this->session->flashdata('failure_message');
                            if (!empty($failure_message)) {?>
                                <div class="alert alert-warning">
                                      <a class="close" data-dismiss="alert" href="components-popups.html#" aria-hidden="true">×</a>
                                      <strong><?php echo $this->session->flashdata('failure_message');  ?></strong>
                                </div> 
                            <?php }  ?>
							<?php
							if($_GET['id'])
							{
								$id=$_GET['id'];
								$sql="select * from component where component_no='$id'";
								$r=$this->db->query($sql);
								$rr=$r->result_array();
								
								
									$category=$rr[0]['category'];
									$component=$rr[0]['component'];
								 $sql = "SELECT * FROM category where category_no='$category'";
									$record = $this->db->query($sql);
									$category_name=$record->row('category');
									
									$heading11=$rr[0]['heading'];
								 $sql1 = "SELECT * FROM headingmaster where heading_no='$heading11'";
									$record1 = $this->db->query($sql1);
									$heading1=$record1->row('heading');	
									
									$master_product=$rr[0]['master_product'];
								 $sql11 = "SELECT * FROM product where id='$master_product'";
									$record11 = $this->db->query($sql11);
									$master_product1=$record11->row('product');
		
		
					
								?>
			 <form role="form" action="<?php echo site_url();?>admin/Component/update_component" method="post" role="form" class="form-horizontal">
			 <input type="hidden" value="<?=$id?>" name="id">
						<div class="form-group">
							<label class="control-label col-md-2">Component :<font color="red">*</font></label>
							<div class="col-md-4">
							<input type="text" required name="component" value="<?php echo set_value('component')?set_value('component'):$rr[0]['component']?>" class="form-control">
							</div>
							<label class="control-label col-md-2">Price :<font color="red">*</font></label>
							<div class="col-md-4">
							<input type="text" required name="price" value="<?php echo set_value('price')?set_value('price'):$rr[0]['price']?>" class="form-control">
							</div>
						</div>	
						
						<div class="form-group">
							<label class="control-label col-md-2">Master Product :<font color="red">*</font></label>
								<div class="col-md-4">
									<select required name="master_product[]" multiple="multiple" class="test form-control">
							<?php
							$sql3="select DISTINCT master_product from component where component='$component' and IsActive=0";
							$r3=$this->db->query($sql3);
							$rr3=$r3->result_array();
				//	print_r($rr3);
						//	$i=0;
								foreach($rr3 as $r5)
								{
									//pri
								$master_product=$r5['master_product'];
								 $sql = "SELECT DISTINCT * FROM product where id='$master_product' and IsActive=0";
									$record = $this->db->query($sql);
									$master_product1=$record->row('product');
									$master_product_id=$record->row('id');
									?>
							<option selected value="<?=$master_product_id?>"><?php echo $master_product1;?></option>
							<?php
								
					
								}
								 $sqlq = "SELECT * FROM product WHERE IsActive='0'";
							//	 echo  $sqlq;
								 $recordq = $this->db->query($sqlq);
								$product_info=$recordq->result_array();
							foreach($product_info as $rr2)
							{
								$p_id=$rr2['id'];
								$sqlqcc="select count(*) as count from component where master_product='$p_id' and component='$component'";
								$rcc=$this->db->query($sqlqcc);
								$rrc=$rcc->row('count');
								if($rrc <=0)
								{
								?>
								
									<option value="<?=$rr2['id']?>"><?=$rr2['product']?></option>
								<?php
								}
							//	$i++;
							}
							
						//	$i++;
								
								
							?>
							</select>
								</div>
						 
							<label class="control-label col-md-2">Category :<font color="red">*</font></label>
							<div class="col-md-4">							
							<select name="category" class="form-control">
							<option value="<?=$category?>"><?=$category_name?></option>
							<?php
							
							foreach($category_info as $rr2)
							{
								?>
									<option value="<?=$rr2['category_no']?>"><?=$rr2['category']?></option>
								<?php
							}
							?>
							</select>
							</div>
						
						
								
						</div>
						<div class="form-group">
							<label class="control-label col-md-2">Heading Master :<font color="red">*</font></label>
							<div class="col-md-4">
						
							<select name="heading" class="form-control">
							<option value="<?=$heading11?>"><?=$heading1?></option>
							<?php
							foreach($heading as $rr44)
							{
								?>
									<option value="<?=$rr44['heading_no']?>"><?=$rr44['heading']?></option>
								<?php
							}
							?>
							</select>
							</div>
						<div class="col-md-2">
								<button id="signupSubmit" type="submit" class="btn btn-warning btn-block pull-right">Submit</button>
							</div>
						</div>
					
					</form>	
					<?php
						}
						else
						{
						?>
					<form role="form" action="<?php echo site_url();?>admin/Component/save_component" method="post" role="form" class="form-horizontal">
						<div class="form-group">
							<label class="control-label col-md-2">Component :<font color="red">*</font></label>
							<div class="col-md-4">
							<input type="text" required name="component" value="<?php echo set_value('component')?set_value('component'):'';?>" class="form-control">
							</div>
							<label class="control-label col-md-2">Price :<font color="red">*</font></label>
							<div class="col-md-4">
							<input type="text" required name="price" value="<?php echo set_value('price')?set_value('price'):'';?>" class="form-control">
							</div>
						</div>	

						<div class="form-group">
							<label class="control-label col-md-2">Master Product :<font color="red">*</font></label>
								<div class="col-md-4">
									<select id="city" name="master_product[]" multiple="multiple" class="test form-control" required>
									<?php
									 $sql = "SELECT * FROM product where IsActive=0";
									$record = $this->db->query($sql);
									$product_info=$record->result_array();
									foreach($product_info as $p)
									{
										?>
										<option value="<?=$p['id']?>"><?=$p['product']?></option>
										<?php										
									}
									?>
									</select>
								</div>
						 
							<label class="control-label col-md-2">Category :<font color="red">*</font></label>
							<div class="col-md-4">							
							<select required name="category" class="form-control">
							<option value="<?=$rr[0]['category']?>"><?=$category_name?></option>
							<?php
							foreach($category_info as $rr2)
							{
								?>
									<option value="<?=$rr2['category_no']?>"><?=$rr2['category']?></option>
								<?php
							}
							?>
							</select>
							</div>
						
						
								
						</div>
						<div class="form-group">
							<label class="control-label col-md-2">Heading Master :<font color="red">*</font></label>
							<div class="col-md-4">
						
							<select required name="heading" class="form-control">
							<option value="<?=$rr[0]['heading']?>"><?=$heading1?></option>
							<?php
							foreach($heading as $rr44)
							{
								?>
									<option value="<?=$rr44['heading_no']?>"><?=$rr44['heading']?></option>
								<?php
							}
							?>
							</select>
							</div>
						<div class="col-md-2">
								<button id="signupSubmit" type="submit" class="btn btn-warning btn-block pull-right">Submit</button>
							</div>
						</div>
					
					</form>
					<?php
						}
						?>
           <div style="overflow-x:auto;">
              
     <table id="example1" class="table table-striped table-bordered responsive">
        <thead>
            <tr>
				<th>Sr.No</th>
				<th>Component</th>				
				<th>Price</th>				
				<th>Product</th>				
				<th>Category</th>				
				<th>Heading</th>				
				<th>Edit</th>                
				<th>Delete</th>                
            </tr>
        </thead>
        <tbody>
			  
<?php 
$sql = "SELECT * FROM component where IsActive=0 group by component";
        $record = $this->db->query($sql);
        $component_info= $record->result_array();
foreach($component_info as $r)
{
	
	$category=$r['category'];
	$component=$r['component'];
	 $sql5 = "SELECT * FROM category where category_no='$category'";
 //echo $sql;
        $record5 = $this->db->query($sql5);
        $category_name=$record5->row('category');
		
		$heading=$r['heading'];
	 $sql1 = "SELECT * FROM headingmaster where heading_no='$heading'";
        $record1 = $this->db->query($sql1);
        $heading=$record1->row('heading');
		
			$master_product1=$r['master_product'];
			 $sql111 = "SELECT * FROM product where id='$master_product1'";
			// echo $sql111;
			$record111 = $this->db->query($sql111);
			$master_product111=$record111->row('product');
?>							
					<tr class="gradeX">
					<td><?php echo $r['id']?></td>
					<td><?php echo $r['component']?></td>
					<td><?php echo $r['price']?></td>
					<td>
						<?php
					$sqlc = "SELECT DISTINCT master_product FROM component where IsActive=0 and component='$component'";
					$recordc = $this->db->query($sqlc);
					$category_infoc= $recordc->result_array();
					foreach($category_infoc as $c)
					{
						$master_product2=$c['master_product'];
						$sql1 = "SELECT * FROM product where id='$master_product2'";
						$record1 = $this->db->query($sql1);
						$master_product11=$record1->row('product');
								
					
					 echo ' '.$master_product11;
					}
					?>
					
					</td>
					<td><?php echo $category_name?></td>
					<td><?php echo $heading?></td>
					<td><a href="<?php echo site_url();?>admin/Component/add_component?id=<?=$r['component_no']?>" title="Edit Component" class="btn btn-primary btn-circle"><i class="fa fa-pencil" aria-hidden="true"></i></td>
					<td><a href="<?php echo site_url();?>admin/Component/delete_component/<?php echo $r['component_no']?>" title="Delete Component" class="btn btn-danger btn-circle"><i class="fa fa-trash" aria-hidden="true"></i></td>
					</tr>
<?php
}

?>			
             
        </tbody>
    </table>
	</div>
	
	    <link href="<?php echo site_url();?>assets/css/jquery.dataTables.min.css" rel="stylesheet">
	    <link href="https://cdn.datatables.net/buttons/1.4.2/css/buttons.dataTables.min.css" rel="stylesheet">
    
	<script src="//code.jquery.com/jquery-1.12.4.js"></script> 
	<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script> 
	<script src="https://cdn.datatables.net/buttons/1.4.2/js/dataTables.buttons.min.js"></script> 
	<script src="//cdn.datatables.net/buttons/1.4.2/js/buttons.flash.min.js"></script> 
	<script src="//cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script> 
	<script src="//cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script> 
	<script src="//cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script> 
	<script src="//cdn.datatables.net/buttons/1.4.2/js/buttons.html5.min.js"></script> 
	<script src="//cdn.datatables.net/buttons/1.4.2/js/buttons.print.min.js"></script> 

	
	<script>
$(document).ready(function() {
    $('#example1').DataTable( {
        dom: 'Bfrtip',
		"paging": false,
        buttons: [
             'csv', 'excel'
        ]
    } );
} );			
	</script>
                            
                          
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->            
        </div>
        <!-- /#page-wrapper -->

<!-- DataTables JavaScript -->
   <script type="text/javascript">
$(document).ready(function() {
    $('#example').DataTable( {
        dom: 'T<"clear">lfrtip',
        tableTools: {
            "sSwfPath": "../js/datatables/extras/TableTools/media/swf/copy_csv_xls_pdf.swf"
        }
    } );
} );

</script>
<script>
function doconfirm()
{
    job=confirm("Are you sure to delete permanently?");
    if(job!=true)
    {
        return false;
    }
}
</script>
<script>
$(document).ready(function($) {
    $("#city").change(function() {
        var search_id = $(this).val();
	//	alert(search_id);
        $.ajax({
			url : 'http://pctest.spectracloud.net/spectra/admin/Component/auo_product3',
            method: "post",
            data: {search_id:search_id},
            success: function(data){
                $("#district").html(data);
            }
        })
    });
});
			  
	</script>
	<script>
$(document).ready(function($) {
    $("#city").change(function() {
        var search_id = $(this).val();
	//	alert(search_id);
        $.ajax({
			url : 'http://pctest.spectracloud.net/spectra/admin/Component/auo_product4',
            method: "post",
            data: {search_id:search_id},
            success: function(data){
                $("#hm").html(data);
            }
        })
    });
});
			  
	</script>