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


 if(isset($_POST['update']))
    {
	
$model_id = $_POST['model_id'];
$model_name = $_POST['model_name'];

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

mysqli_query($connection,"UPDATE model SET model_name ='$model_name' WHERE model_id = '$model_id'")
			or die(mysqli_error()); 
	$errMsg="Model 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 Model</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">Model Name</label>
                                            <input type="text" class="form-control" name="model_name" 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 Model 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 model WHERE branch_id  = '$branch_id_for_header_user'";
                                                $result = mysqli_query($connection,$query);
                                                
                                                $i=0;
                                                while($row=mysqli_fetch_array($result))
                                                {
                                                $i++;
                                                $model_id = $row['model_id'];
                                                $model_name = $row['model_name'];
                                                
                                                
                                                echo "<tr>";
                                                echo "<td>$model_name
												
										<input type='hidden' id='name$i' value='$model_name'/></td>";
                                                echo "<td><input type='hidden' id='zipsearch$i' value='$model_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 model</h4>
      </div>
      <div class='modal-body'>
     Are You sure you want to delete  $model_name ?
      </div>
      <div class='modal-footer'>
        <button type='button' class='btn btn-default' data-dismiss='modal'>No</button>
        <a href='delete.php?tbl=model&idcol=model_id&id=$model_id&redirect=model_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 Model</h4>
      </div>
      <div class='modal-body'>
      <input type="hidden" id='xpaytype' name='model_id' class='form-control'/>
        
                    <div class="form-group">
                        <input type="text" id='name' name="model_name" 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>