<?php include("sass/icon_for_datepicker_and_datatable.php");?>
        <div class="wrapper row-offcanvas row-offcanvas-left">
            <!-- Left side column. contains the logo and sidebar -->
            <?php include("sass/sidebar.php");?>
 <?php
$errMsg=""; 
if(isset($_POST['submit'])) // To check 'submmited or not' by if(isset($_POST['submit'])) 
{
	$unit_type_name = $_POST['unit_type_name'];
	
	if(empty($unit_type_name)) $errMsg="Write section Name";
	if(empty($errMsg))
	{
		
		
		mysqli_query($connection,"INSERT INTO section (section_name) VALUES ('$unit_type_name')")
		or die(mysqli_error()); 
		$errMsg="section Name Successfully Inserted";
	
}
}
?>
            <!-- Right side column. Contains the navbar and content of the page -->
               <aside class="right-side">
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                       <?php echo $company_name ; ?>
                        <small>Control panel</small>
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li class="active">Dashboard</li>
                    </ol>
                </section>
                 <section class="content">
                <?php
							if (!empty($errMsg))
							{echo "<div class='alert alert-warning alert-dismissible' role='alert'>$errMsg";
							echo "<button type='button' class='close' data-dismiss='alert'><span aria-hidden='false'>&times;</span><span class='sr-only'>		Close</span></button>
                        </div>";}
                        ?>
					<div class="box box-primary">
                                <div class="box-header">
                                    <h3 class="box-title">Create New section</h3>
                                </div><!-- /.box-header -->
                                <!-- form start -->
                                <form role="form"  action="<?php echo "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" method="post">
                                    <div class="box-body">
                                        <div class="form-group col-md-6">
                                            <label for="exampleInputEmail1">section Name</label>
                                            <input type="text" class="form-control" name="unit_type_name">
                                        </div>
                                    </div><!-- /.box-body -->

                                    <div class="box-footer">
                                        <button type="submit" name="submit" class="btn btn-primary">Submit</button>
                                    </div>
                                </form>
                            </div>
                            
                            
                            <div class="box">
                                <div class="box-header">
                                    <h3 class="box-title">All section Name</h3>
                                </div><!-- /.box-header -->
                                <div class="box-body table-responsive">
                                    <table id="example1" class="table table-bordered table-striped">
                                        <thead>
                                            <tr>
                                                <th>Name</th>
                                               
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            
												<?php
                                                
                                                $query = "SELECT * FROM section";
                                                $result = mysqli_query($connection,$query);
                                                
                                                $i=0;
                                                while($row=mysqli_fetch_array($result))
                                                {
                                                $i++;
                                                $section_id = $row['section_id'];
                                                $section_name = $row['section_name'];
                                                
                                                
                                                echo "<tr>";
                                                echo "<td>$section_name
												
										<input type='hidden' id='name$i' value='$section_name'/></td>";
                                                echo "<td><input type='hidden' id='zipsearch$i' value='$section_id'/> <button type='button' class='btn btn-primary' data-toggle='modal' data-target='#myModal' onClick='sync$i()'><i class='fa fa-edit'></i> &nbsp;Edit</button>
												<button type='button' class='btn btn-danger' data-toggle='modal' data-target='#delmodel$i'><i class='fa fa-times'></i> &nbsp;Delete</button>
												
												</td>";
                                                echo "</tr>";
												
												
												
						echo "<script>
function sync$i()
{
  var collect = document.getElementById('zipsearch$i');
  var entry = document.getElementById('xpaytype');
  
  
  var namecollect = document.getElementById('name$i');
  var nameentry = document.getElementById('name');
  
  
  
  entry.value = collect.value;
  nameentry.value = namecollect.value;
}
</script> ";


echo "<div class='modal fade' id='delmodel$i' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>
  <div class='modal-dialog'>
    <div class='modal-content'>
      <div class='modal-header'>
        <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
        <h4 class='modal-title' id='myModalLabel'>Delete Section</h4>
      </div>
      <div class='modal-body'>
     Are You sure you want to delete  $section_name ?
      </div>
      <div class='modal-footer'>
        <button type='button' class='btn btn-default' data-dismiss='modal'>No</button>
        <a href='delete_section.php?section_id=$section_id'><button type='button' class='btn btn-danger'>Yes</button></a>
      </div>
    </div>
  </div>
</div>";

                                                }
                                                
                                                ?>
                                         
                                        </tbody>
                                        <tfoot>
                                            <tr>
                                                <th>Name</th>
                                               
                                                <th>Action</th>
                                            </tr>
                                        </tfoot>
                                    </table>
                                </div><!-- /.box-body -->
                            </div>
                            
                            
                            <form method='post' action='update_section.php'>
										<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>
  <div class='modal-dialog'>
    <div class='modal-content'>
      <div class='modal-header'>
        <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
        <h4 class='modal-title' id='myModalLabel'>Update section</h4>
      </div>
      <div class='modal-body'>
      <input type="hidden" id='xpaytype' name='upload_id' class='form-control'/>
        
                    <div class="form-group">
                        <input type="text" id='name' name="name" class="form-control" placeholder="Movie Name"/>
                    </div>
      </div>
      <div class='modal-footer'>
        <button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>
        <button type='submit'  name="submit" class='btn btn-primary'>Save</button>
      </div>
    </div>
  </div>
</div>
</form>
                </section><!-- /.content -->
            </aside><!-- /.right-side -->
        </div><!-- ./wrapper -->

    <?php include("sass/footer_for_datepicker_and_datatable.php");?>

    </body>
</html>