<?php 
include "config.php";
session_start();
$userid=$_SESSION['log'];
$code = $_POST['employeecode'];
$name = $_POST['employeename'];
$user = $_POST['username'];
$password = $_POST['password'];
$statuslive = $_POST['statuslive'];
$usertype = $_POST['usertype'];
$filename=$_POST['filename'];

$sql = "insert into employeedetails (employeecode,employeename,username,usertype,password,statuslive,editdate,edittime,editby,status) values('$code','$name','$user','$usertype','$password','$statuslive',CURDATE(),CURTIME(),'$userid','')";
echo $sql;

foreach ($filename as $id => $value ){
  if($usertype == 'admin')
{
$insertuser = "insert into userpermission(employeename,employeecode,username,filename,datashow,dataadd,dataedit,datadelete,dataprint,dataexcel)values('$name','$code','$user','$filename[$id]','1','1','1','1','1','1')";
echo $insertuser;
$gouser = mysqli_query($connect,$insertuser);
}
if($usertype == 'general')
{
$insertuser = "insert into userpermission(employeename,employeecode,username,filename,datashow,dataadd,dataedit,datadelete,dataprint,dataexcel)values('$name','$code','$user','$filename[$id]','','','','','','')";
$gouser = mysqli_query($connect,$insertuser);
    }
}
 $go = mysqli_query($connect,$sql);
 header('Location:userpermission.php');

?>