<?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'])) 
{
	$sector = $_POST['sector'];
	
	if(empty($sector)) $errMsg="Write expense_sector Name";
	if(empty($errMsg))
	{
		
		
		mysqli_query($connection,"INSERT INTO expense_sector (sector) VALUES ('$sector')")
		or die(mysqli_error()); 
		$errMsg="Expense Sector Name Successfully Inserted";
	
}
}


 if(isset($_POST['update']))
    {
	
$id = $_POST['id'];
$sector = $_POST['sector'];



mysqli_query($connection,"UPDATE expense_sector SET sector ='$sector' WHERE id = '$id'")
			or die(mysqli_error()); 
	$errMsg="Expense Sector Name Successfully Updated";
	}
?>
            <!-- 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 Expense Ssector</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">Expense Sector Name</label>
                                            <input type="text" class="form-control" name="sector" maxlength="20" required />
                                        </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 Expense Sector 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 expense_sector";
                                                $result = mysqli_query($connection,$query);
                                                
                                                $i=0;
                                                while($row=mysqli_fetch_array($result))
                                                {
                                                $i++;
                                                $id = $row['id'];
                                                $sector = $row['sector'];
                                                
                                                
                                                echo "<tr>";
                                                echo "<td>$sector
												
										<input type='hidden' id='name$i' value='$sector'/></td>";
                                                echo "<td><input type='hidden' id='zipsearch$i' value='$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='#delexpense_sector$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='delexpense_sector$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 expense_sector</h4>
      </div>
      <div class='modal-body'>
     Are You sure you want to delete  $sector ?
      </div>
      <div class='modal-footer'>
        <button type='button' class='btn btn-default' data-dismiss='modal'>No</button>
        <a href='delete.php?tbl=expense_sector&idcol=id&id=$id&redirect=expense_sector'><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='<?php echo $_SERVER['SCRIPT_NAME']; ?>'>
										<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 expense_sector</h4>
      </div>
      <div class='modal-body'>
      <input type="hidden" id='xpaytype' name='id' class='form-control'/>
        
                    <div class="form-group">
                        <input type="text" id='name' name="sector" 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="update" class='btn btn-primary'>Update</button>
      </div>
    </div>
  </div>
</div>
</form>
                </section><!-- /.content -->
            </aside><!-- /.right-side -->
        </div><!-- ./wrapper -->

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

    </body>
</html>