<?php
include('../include/config.php');
error_reporting(0);
session_start();
$iduser=$_SESSION['user_idd'];
$date = new DateTime("now", new DateTimeZone('Africa/Nairobi') );
$timenow=$date->format('Y-m-d H:i:s');
$timenow2=$date->format('Y-m-d');
$month=$date->format('M');

$em='';

if(isset($_POST['lev']))
{
$uza=addslashes($_POST['id']);
$lev=addslashes($_POST['lev']);


$queryy=mysqli_query($con,"select * from Staffs where id='$uza'");
while($row=mysqli_fetch_array($queryy))
{
$em=htmlentities($row['Email']);
}



$query=mysqli_query($con,"SELECT * FROM users WHERE userid='$uza'");
$num=mysqli_fetch_array($query);
if($num>0)
{
echo "Selected employee is already a user !!";
}else
{
    
$sql=mysqli_query($con,"INSERT INTO users(userid,Level,Email,Aces,CreateDate) values('$uza','$lev','$em','Yes','$timenow2')");
$sq=mysqli_query($con,"UPDATE staffs SET User='Yes' WHERE id='$uza'");
if($sql)
{
    
$sq=mysqli_query($con,"UPDATE Staffs SET User='Yes' where id='$uza'");
    
$msg='added new user';
$sql3=mysqli_query($con,"INSERT INTO activity(user,Action,Tim,Dat,shortmsg,Month)values('$iduser','$msg','$timenow','$timenow2','save','$month')");

echo "saved";
}else
{
echo 'Unable to save';
}
}
}

?>