<?php
session_start();
include ("include/db.php");
include ("include/setting.php");
include ("include/clean.php");
?>








<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title><?php echo $site_name;?></title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
  <!-- iCheck -->
  <link rel="stylesheet" href="plugins/iCheck/square/blue.css">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

  <!-- Google Font -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition register-page">
<div class="register-box">
  <div class="register-logo">
    <a href="#"><b></b>Supervisor Registration</a>
  </div>

  <div class="register-box-body">
  <?php 
  if (isset($_POST["name"]))
  {
	
$name=cucidata($_POST["name"]);
$sn=cucidata($_POST["sn"]);
//$sno=cucidata($_POST["sno"]);
//$pic=cucidata($_POST["pic"]);
$hp=cucidata($_POST["hp"]);
$fa=cucidata($_POST["fa"]);
$rn=cucidata($_POST["rn"]);
$rl=cucidata($_POST["rl"]);
$rlo=cucidata($_POST["rlo"]);
$ex=cucidata($_POST["ex"]);
$email=cucidata($_POST["email"]);
$pwd1=cucidata($_POST["pwd1"]);
$pwd2=cucidata($_POST["pwd2"]);
$pic=$_FILES["pic"]["name"];

//step 1 - check record exist

$dataWujud=mysqli_query($con,"select * from supervisor where sup_id='$sn'");  //sql query
$showData=mysqli_fetch_array($dataWujud); //put data into array
$bil_rekod=mysqli_num_rows($dataWujud); //check number of records
$imageFileType = strtolower(pathinfo($pic,PATHINFO_EXTENSION)); //dapatkan jenis file

if ($bil_rekod!=0)
{$msg="<div class='callout callout-danger'><h4>Registration Status</h4> <p>The student with the ID <b>$uitmid</b> existed in the system. Please <a href='register.php'>try</a> again or click <a href='index.php'>here</a> to login. </p></div>";}





elseif ($pwd1!=$pwd2) //check password matching
{$msg="<div class='callout callout-danger'><h4>Registration Status</h4> <p>Password did not match. Please <a href='register.php'>try</a> again or click <a href='index.php'>here</a> to login. </p></div>";}




elseif ($_FILES["pic"]["size"] > 500000)
{$msg="<div class='callout callout-danger'><h4>Registration Status</h4> <p>Error! Check your file size (not exceeding 500kb). Please <a href='register.php'>try</a> again or click <a href='index.php'>here</a> to login. </p></div>";}

elseif ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg")
{$msg="<div class='callout callout-danger'><h4>Registration Status</h4> <p>Error! Check your file size (not exceeding 500kb) and file types (PNG and JPEG). Please <a href='register.php'>try</a> again or click <a href='index.php'>here</a> to login. </p></div>";}

else
{
	
 $imgData =addslashes(file_get_contents($_FILES['pic']['tmp_name']));
	$imageProperties = getimageSize($_FILES['pic']['tmp_name']);
	
	
	
	
//execute SQL query	
	
mysqli_query($con, "insert into supervisor (sup_name,sup_email,sup_hp,sup_faculty,sup_location,sup_level,sup_rn,sup_extension,sup_sn,sup_password,pic,pic_type) values ('$name','$email','$hp','$fa','$rlo','$rl','$rn','$ex','$sn','$pwd1','$imgData','{$imageProperties['mime']}')") or die (mysqli_error($con));
	
	$msg="<div class='callout callout-success'><h4>Registration Status</h4> <p>Successfully registered a new account. Click <a href='index.php'>here</a> to login </p></div>";
	
	
	
	
	
	
}
echo $msg;  
	  
  }
  else
  {
	?>
  
  
  
  
  
  
  
    <p class="login-box-msg">Register a new membership</p>















	



    <form action="" method="post" enctype="multipart/form-data">
      <div class="form-group has-feedback">
        <input type="text" class="form-control" name="name" placeholder="Full Name" required autocomplete="off">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>

 	<div class="form-group has-feedback">
        <input type="text" class="form-control" name="sn" placeholder="Staff Number" required autocomplete="off">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>
      
      
      <div class="form-group has-feedback">
        <input type="file" class="form-control" name="pic" placeholder="Supervisor Pic" required>
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>

<?php

$getFaculty=mysqli_query ($con, "SELECT * from faculty");

?>


<div class="form-group has-feedback">
<select class="form-control" name="fa">          

<?php

while ($showFaculty=mysqli_fetch_array($getFaculty))
{
?>

<option value="<?php echo $showFaculty['faculty_id']; ?>">
<?php echo $showFaculty['faculty_name']; ?>
</option>

<?php
}
?>

</select>
       
      </div>






 <div class="form-group has-feedback">
        <input type="text" class="form-control" name="hp" placeholder="Contact Number" required autocomplete="off">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>



 <div class="form-group has-feedback">
        <input type="text" class="form-control" name="rn" placeholder="Room Number" required autocomplete="off">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>



      
      
       <div class="form-group has-feedback">
        <input type="text" class="form-control" name="rl" placeholder="Room Level" required autocomplete="off">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>
      
      
      <div class="form-group has-feedback">
        <input type="text" class="form-control" name="rlo" placeholder="Room Location" required autocomplete="off">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>


<div class="form-group has-feedback">
        <input type="text" class="form-control" name="ex" placeholder="Extension" required autocomplete="off">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>


      <div class="form-group has-feedback">
        <input type="text" class="form-control" name="email" placeholder="Email" required autocomplete="off">
        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="text" class="form-control" name="pwd1" placeholder="Password" required autocomplete="off">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="text" class="form-control" name="pwd2" placeholder="Retype password" required autocomplete="off">
        <span class="glyphicon glyphicon-log-in form-control-feedback"></span>
      </div>
      <div class="row">
        <div class="col-xs-8">
          <div class="checkbox icheck">
            <label>
              <input type="checkbox" required> I agree to the <a href="#">terms</a>
            </label>
          </div>
        </div>
        <!-- /.col -->
        <div class="col-xs-4">
          <button type="submit" class="btn btn-primary btn-block btn-flat">Register</button>
        </div>
        <!-- /.col -->
      </div>
    </form>

   

    <a href="index.php" class="text-center">I already have a membership</a>
    
    <?php
  }
  ?>
    
    
  </div>
  <!-- /.form-box -->
</div>
<!-- /.register-box -->

<!-- jQuery 3 -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- iCheck -->
<script src="plugins/iCheck/icheck.min.js"></script>
<script>
  $(function () {
    $('input').iCheck({
      checkboxClass: 'icheckbox_square-blue',
      radioClass: 'iradio_square-blue',
      increaseArea: '20%' /* optional */
    });
  });
</script>
</body>
</html>
