<?php include("session_controller.php"); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  //$theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($theValue) : mysqli_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
//format date function
function dateformatReverse($datetime){
$received_timestamp = "";
 if($datetime != ""){
 $full_date = explode(" ", $datetime);
 $date = explode("-", $full_date[0]);
 $d = $date[2];
 $mo = $date[1];
 $y = $date[0];
 $time = explode(":",$full_date[1]);
 $h = $time[0];
 $min = $time[1];
 $s = $time[2];
 
 $received_timestamp = $d."/".$mo."/".$y." ".$h.":".$min.":".$s;
 }
 return $received_timestamp;
 }
 
function dateformat($datetime){
$received_timestamp = "";
 if($datetime != ""){
 $full_date = explode(" ", $datetime);
 $date = explode("/", $full_date[0]);
 $d = $date[0];
 $mo = $date[1];
 $y = $date[2];
 $time = explode(":",$full_date[1]);
 $h = $time[0];
 $min = $time[1];
 $s = $time[2];
 
 $received_timestamp = $y."-".$mo."-".$d." ".$h.":".$min.":".$s;
 }
 return $received_timestamp;
 }
 
 $colname_Recordset1 = "-1";

 

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
 

mysqli_select_db($conn, $database_conn);    
		 
 $updateSQL = sprintf("INSERT INTO admin (name, email, phone, location, username, password, role) values( %s, %s, %s, %s, %s, %s, %s)",
   GetSQLValueString($_POST['name'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['phone'], "text"),
					   GetSQLValueString($_POST['location'], "text"),
					  GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString(($_POST['password']), "text"),
                       GetSQLValueString(($_POST['role']), "text"));

  $Result1 = mysqli_query($conn, $updateSQL) or die(mysqli_error($conn));
}
        
  
if($Result1){

  $updateGoTo = "users.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
  
}

?>


<html>
<head>
<title> Create User</title>
<link href="style.css" rel="stylesheet" type="text/css" />

</head>
<body>
<?php include("links.php");?>
<div class="container">
<div class="row">
<div class="col-sm-6">

<div style="font-family:Century Gothic; font-size:18px; font-weight:bold">Create New User</div>



<form method="post" name="form1" action="<?php echo $editFormAction; ?>" class="form-group">
  <div class="table-responsive">	
	<br/>
 <div style="font-family:Century Gothic; font-size:15px;"> Name</div>
  <input type="textfield" name="name" value="" class="form-control">
   
   <br/>
   <div style="font-family:Century Gothic; font-size:15px;">Email:</div>
     <input type="textfield" name="email" value="" class="form-control">
     <!-- <input type="text" name="sex" value="" size="32" /> -->
     <!-- <select name="tranx_type" class="form-control">
							  <option selected="selected" value="">Select</option>
							  <option value="credit" >Credit</option>
							  <option value="debit" >Debit</option>
						  
      </select>
    -->
      <br/>
      <div style="font-family:Century Gothic; font-size:15px;">Phone:</div>
   <input type="text" name="phone" value="" class="form-control"> 

    <br/>
      <div style="font-family:Century Gothic; font-size:15px;">Location:</div>
       <select name="location"  class="form-control" >
                <option selected="selected" value="" >Select City</option>
                                <option value="Abia" >Abia</option>
                                <option value="Adamawa" >Adamawa</option>
                                <option value="Akwa Ibom" >Akwa Ibom</option>
                                <option value="Anambra" >Anambra</option>
                                <option value="Bauchi"  >Bauchi</option>
                                <option value="Bayelsa" >Bayelsa</option>
                                <option value="Benue" >Benue</option>
                                <option value="Borno" >Borno</option>
                                <option value="Cross River">Cross River</option>
                                <option value="Delta" >Delta</option>
                                <option value="Ebonyi" >Ebonyi</option>
                                <option value="Edo" >Edo</option>
                                <option value="Ekiti">Ekiti</option>
                                <option value="Enugu" >Enugu</option>
                                <option value="FCT" >FCT</option>
                                <option value="Gombe">Gombe</option>
                                <option value="Imo" >Imo</option>
                                <option value="Jigawa" >Jigawa</option>
                                <option value="Kaduna" >Kaduna</option>
                                <option value="Kano" >Kano</option>
                                <option value="Katsina" >Katsina</option>
                                <option value="Kebbi">Kebbi</option>
                                <option value="Kogi" >Kogi</option>
                                <option value="Kwara" >Kwara</option>
                                <option value="Lagos" >Lagos</option>
                                <option value="Nasarawa">Nasarawa</option>
                                <option value="Niger" >Niger</option>
                                <option value="Ogun" >Ogun</option>
                                <option value="Ondo" >Ondo</option>
                                <option value="Osun" >Osun</option>
                                <option value="Oyo">Oyo</option>
                                <option value="Plateau">Plateau</option>
                                <option value="Rivers">Rivers</option>
                                <option value="Sokoto">Sokoto</option>
                                <option value="Taraba">Taraba</option>
                                <option value="Yobe">Yobe</option>
                                <option value="Zamfara">Zamfara</option>              
                            </select>

    
  <br/>
 <div style="font-family:Century Gothic; font-size:15px;">Username:</div>
  <input type="text" name="username" value="" class="form-control">
  <br/>
  
<div style="font-family:Century Gothic; font-size:15px;">Password:</div>
  <input type="text" name="password" value="" class="form-control">   

  <br/>
  
<div style="font-family:Century Gothic; font-size:15px;">Role:</div>
 <select name="role" class="form-control">
               
                <option value="user" selected="selected">User</option>
                <option value="admin">Admin</option>
              
      </select>	
        
        <br/><br/>				 
	<input type="submit" value="SAVE" class="btn btn-primary" style="width:40%; height:auto;padding-left:10px;padding-left:10px; background-color:#f2f1f3; border-radius:5px; color:#333"/> &nbsp; &nbsp; &nbsp; &nbsp; <a href="assets.php" class="btn btn-primary" style="width:40%; height:auto;padding-left:10px;padding-left:10px; background-color:#f2f1f3; border-radius:5px; color:#333">CANCEL </a></td>
   
  </div>

  <input type="hidden" name="MM_update" value="form1">


</form>

  </form></div></div></div>

<br />
 </body>
 
 </html>

