<?php 

session_name('super_admin_session');

if (!is_dir(dirname(__DIR__) . '/session_data/super')) { mkdir(dirname(__DIR__) . '/session_data/super', 0700, true); } session_save_path(dirname(__DIR__) . '/session_data/super');

session_set_cookie_params(['path' => '/', 'httponly' => true, 'samesite' => 'Strict']);

session_start();

error_reporting(0);

include('includes/dbconnection.php');
include('includes/flash.php');

if(isset($_POST['submit']))

{

  $password1=($_POST['password']); 

  $password2=($_POST['password1']); 



  if($password1 != $password2) {

    flash_alert('Password and Confirm Password Field do not match  !!');

  }else

  {

    $name=$_POST['name'];

    $lastname=$_POST['lastname'];

    $username=$_POST['username'];

    $email=$_POST['email'];

    $permission=$_POST['permission'];

    $sex=$_POST['sex'];

    $mobile=$_POST['mobile'];

    $title=$_POST['title'];

    $password=md5($_POST['password']);

    $status=1; 

    if ($permission == 'Teacher') {

      $status = 2; // Set status to 0 for Teacher

    } 

    $sql="INSERT INTO  tblusers(name,username,email,password,status,mobile,sex,lastname,permission,title) VALUES(:name,:username,:email,:password,:status,:mobile,:sex,:lastname,:permission,:title)";

    $query = $dbh->prepare($sql);

    $query->bindParam(':name',$name,PDO::PARAM_STR);

    $query->bindParam(':lastname',$lastname,PDO::PARAM_STR);

    $query->bindParam(':sex',$sex,PDO::PARAM_STR);

    $query->bindParam(':mobile',$mobile,PDO::PARAM_STR);

    $query->bindParam(':status',$status,PDO::PARAM_STR);

    $query->bindParam(':username',$username,PDO::PARAM_STR);

    $query->bindParam(':email',$email,PDO::PARAM_STR);

    $query->bindParam(':permission',$permission,PDO::PARAM_STR);

    $query->bindParam(':password',$password,PDO::PARAM_STR);    

    $query->bindParam(':title',$title,PDO::PARAM_STR);



    $query->execute();

    $lastInsertId = $dbh->lastInsertId();

    if($lastInsertId)

    {

      flash_alert('Registered successfuly');

       header('Location: userregister.php'); exit;

      

    }

    else 

    {

      flash_alert('Something went wrong. Please try again');

    }

  }

}

?>



<form role="form" method="post" enctype="multipart/form-data" style="background:#fff;border-radius:16px;padding:24px;box-shadow:0 4px 20px rgba(15,23,42,.06);">
  <div class="row">
    <div class="form-group col-md-4">
      <label style="font-size:.72rem;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:#64748b;margin-bottom:6px;">Title</label>
      <select name="title" class="form-control modal-select2" required style="height:44px;border:1.5px solid #e2e8f0;border-radius:12px;background:#f8fafc;">
        <option value="">Select Title</option>
        <option value="Mr">Mr</option>
        <option value="Mrs">Mrs</option>
        <option value="Miss">Miss</option>
        <option value="Ms">Ms</option>
        <option value="Master">Master</option>
        <option value="Madam">Madam</option>
      </select>
    </div>
    <div class="form-group col-md-4">
      <label style="font-size:.72rem;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:#64748b;margin-bottom:6px;">First Name</label>
      <input type="text" name="name" class="form-control" placeholder="First Name" required style="height:44px;border:1.5px solid #e2e8f0;border-radius:12px;padding:0 14px;background:#f8fafc;font-size:.88rem;">
    </div>
    <div class="form-group col-md-4">
      <label style="font-size:.72rem;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:#64748b;margin-bottom:6px;">Last Name</label>
      <input type="text" name="lastname" class="form-control" placeholder="Last Name" required style="height:44px;border:1.5px solid #e2e8f0;border-radius:12px;padding:0 14px;background:#f8fafc;font-size:.88rem;">
    </div>
    <div class="form-group col-md-4">
      <label style="font-size:.72rem;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:#64748b;margin-bottom:6px;">Gender</label>
      <select name="sex" class="form-control modal-select2" required style="height:44px;border:1.5px solid #e2e8f0;border-radius:12px;background:#f8fafc;">
        <option value="">Select Gender</option>
        <option value="Male">Male</option>
        <option value="Female">Female</option>
      </select>
    </div>
    <div class="form-group col-md-4">
      <label style="font-size:.72rem;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:#64748b;margin-bottom:6px;">Username</label>
      <input type="text" name="username" class="form-control" placeholder="Username" required style="height:44px;border:1.5px solid #e2e8f0;border-radius:12px;padding:0 14px;background:#f8fafc;font-size:.88rem;">
    </div>
    <div class="form-group col-md-4">
      <label style="font-size:.72rem;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:#64748b;margin-bottom:6px;">Permission</label>
      <select name="permission" class="form-control modal-select2" required style="height:44px;border:1.5px solid #e2e8f0;border-radius:12px;background:#f8fafc;">
        <option value="">Select Permission</option>
        <option value="Super User">Super User</option>
        <option value="Admin">Admin</option>
        <option value="Student Search">Student Search Officer</option>
        <option value="Teacher">Teacher</option>
      </select>
    </div>
    <div class="form-group col-md-4">
      <label style="font-size:.72rem;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:#64748b;margin-bottom:6px;">Email Address</label>
      <input type="email" name="email" class="form-control" placeholder="Enter email" required style="height:44px;border:1.5px solid #e2e8f0;border-radius:12px;padding:0 14px;background:#f8fafc;font-size:.88rem;">
    </div>
    <div class="form-group col-md-4">
      <label style="font-size:.72rem;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:#64748b;margin-bottom:6px;">Mobile</label>
      <input type="text" name="mobile" class="form-control" placeholder="Enter mobile" required style="height:44px;border:1.5px solid #e2e8f0;border-radius:12px;padding:0 14px;background:#f8fafc;font-size:.88rem;">
    </div>
    <div class="form-group col-md-4">
      <label style="font-size:.72rem;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:#64748b;margin-bottom:6px;">Password</label>
      <input type="password" name="password" class="form-control" placeholder="Password" required style="height:44px;border:1.5px solid #e2e8f0;border-radius:12px;padding:0 14px;background:#f8fafc;font-size:.88rem;">
    </div>
    <div class="form-group col-md-4">
      <label style="font-size:.72rem;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:#64748b;margin-bottom:6px;">Confirm Password</label>
      <input type="password" name="password1" class="form-control" placeholder="Confirm password" required style="height:44px;border:1.5px solid #e2e8f0;border-radius:12px;padding:0 14px;background:#f8fafc;font-size:.88rem;">
    </div>
  </div>
  <div style="margin-top:20px;padding-top:20px;border-top:1px solid #e2e8f0;display:flex;justify-content:flex-end;gap:10px;">
    <button type="button" class="btn" data-dismiss="modal" style="background:#e2e8f0;color:#475569;border:none;border-radius:10px;padding:10px 24px;font-weight:600;font-size:.85rem;">Cancel</button>
    <button type="submit" name="submit" class="btn" style="background:linear-gradient(135deg,#1e3a5f,#3b82f6);color:#fff;border:none;border-radius:10px;padding:10px 24px;font-weight:600;font-size:.85rem;box-shadow:0 4px 14px rgba(59,130,246,.4);">
      <i class="fas fa-check-circle"></i> Register User
    </button>
  </div>
</form>

