<?php include ("kfunctions.php");?>
<html>

<head>
<?php kheader(); ?>

</head>

<body>

    <div id="wrapper">

        <!-- Navigation -->
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
          <?php ktopbar(); ?>
            <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
        <?php kleftbar(); ?>

            <!-- /.navbar-collapse -->
        </nav>


        <!-- Navigation -->
   

        <div id="page-wrapper">

            <div class="container-fluid">
      

<div class='col-lg-12'>
<div class='panel panel-yellow'><!--Initiative-->
<div class='panel-heading'><h3 class='panel-title'>Add user</h3></div>
<div class='panel-body'>
<?php
if(isset($_POST["submit_user"])){
$fname=$_POST["fname"];
$lname=$_POST["lname"];
$phone1=$_POST["phone1"];
$email=$_POST["email"];
$title=$_POST["title"];

$yy=date("Y");
$mm=date("m");
$dd=date("d");
$ourdate=strtotime($yy."-".$mm."-".$dd);

$dt=date("Y-m-d", strtotime("+3 month" , $ourdate));

include("connect.php");
$result_user=$dbh->prepare("select * from users where role='$title' order by autoid desc");
$result_user->execute();
$row_user=$result_user->fetchObject();
$count_user=$result_user->rowCount();

$theno=$row_user->autoid+1;
$rolenumber=$title.$theno;

$insert_users=$dbh->prepare("insert into users (role,firstname,lastname,phonenumber,email,username,password,title,status,rolenumber) values('$title','$fname','$lname','$phone1','$email','$lname','$lname','$row_user->title','1','$rolenumber')");
$insert_users->execute();

$insert_kfield=$dbh->prepare("INSERT into keyfields (rolenumber,username,password,pswdexpiry) values('$rolenumber','$lname','$lname','$dt')");
$insert_kfield->execute();

}
?>
<form method="post">
<div class='col-lg-2'>
<input type='text' class='form-control' name='fname' placeholder='Firstname' required>
</div>
<div class='col-lg-2'>
<input type='text' class='form-control' name='lname' placeholder='Lastname' required>
</div>

<div class='col-lg-3'>
<input type='text' class='form-control' name='phone1' placeholder='Phone Number' required>
</div>


<div class='col-lg-3'>
<input type='text' class='form-control' name='email' placeholder='Email'>
</div>
<div class='col-lg-2'>
<select class="form-control" name="title" required>
<option value="">Title</option>
<?php
include("connect.php");
$result_user=$dbh->query("select distinct(title),role from users");
$row_user=$result_user->fetchObject();
$count_user=$result_user->rowcount();

if($count_user>0){
do{
echo "<option value='".$row_user->role."'>".$row_user->title."</option>";
}while($row_user=$result_user->fetchObject());
}else{
    echo "<option value=''>Please contact your IT department.</option>";
}
?>
</select>
</div>

<div class='col-lg-2'>
<input type="submit" class="btn btn-sm btn-primary" name="submit_user" value="Submit user">
</div>
</div>
</form>
</div> 
</div>
</div>
</div>
<!--the body-->

      </div>
    </div>                         


                
                <!-- /.row -->
<div style="margin-top: 20px;">.</div>

                  </div>
                <!-- /.row -->

            </div>
            <!-- /.container-fluid -->

        </div>
        <!-- /#page-wrapper -->

    <!-- jQuery -->
    <script src="js/input_down.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>
     <script type="text/javascript" src="js/jquery-1.8.3.min.js" charset="UTF-8"></script>
</body>

</html>
