<?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'])) 
{
	$particulars = $_POST['particulars'];
	
	if(empty($particulars)) $errMsg="Write Particulars Name";
	if(empty($errMsg))
	{
		$check=mysqli_query($connection,"select * from particulars where particulars='$particulars'");
		$checkrows=mysqli_num_rows($check);
		if($checkrows>0){$errMsg="You have entered this particulars Name before";}
		
		else{
		
		mysqli_query($connection,"INSERT INTO particulars (particulars) VALUES ('$particulars')")
		or die(mysqli_error()); 
		$errMsg="particulars Name Successfully Inserted";
	}
}
}


 if(isset($_POST['update']))
    {
	
$particulars_id = $_POST['particulars_id'];
$particulars = $_POST['particulars'];

$check=mysqli_query($connection,"select * from particulars where particulars='$particulars'");
		$checkrows=mysqli_num_rows($check);
		if($checkrows>0){$errMsg="You have entered this particulars Name before";}
		
		else{

mysqli_query($connection,"UPDATE particulars SET particulars ='$particulars' WHERE particulars_id = '$particulars_id'")
			or die(mysqli_error()); 
	$errMsg="particulars 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 Ledger Sub-Head</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">Ledger Sub-Head Name</label>
                                            <input type="text" class="form-control" name="particulars" 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 Ledger Sub-Head 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 particulars where particulars_id > 17";
                                                $result = mysqli_query($connection,$query);
                                                
                                                $i=0;
                                                while($row=mysqli_fetch_array($result))
                                                {
                                                $i++;
                                                $particulars_id = $row['particulars_id'];
                                                $particulars = $row['particulars'];
                                                
                                                
                                                echo "<tr>";
                                                echo "<td>$particulars
												
										<input type='hidden' id='name$i' value='$particulars'/></td>";
                                                echo "<td><input type='hidden' id='zipsearch$i' value='$particulars_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='#delparticulars$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='delparticulars$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 particulars</h4>
      </div>
      <div class='modal-body'>
     Are You sure you want to delete  $particulars ?
      </div>
      <div class='modal-footer'>
        <button type='button' class='btn btn-default' data-dismiss='modal'>No</button>
        <a href='delete.php?tbl=particulars&idcol=particulars_id&id=$particulars_id&redirect=particulars_setup'><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 particulars</h4>
      </div>
      <div class='modal-body'>
      <input type="hidden" id='xpaytype' name='particulars_id' class='form-control'/>
        
                    <div class="form-group">
                        <input type="text" id='name' name="particulars" class="form-control" placeholder="Movie Name" required/>
                    </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>