<script language="JavaScript" src="jscript/md5.min.js"  type="text/javascript"></script>

<?php
include("dbset.php");

$con = mysqli_connect("localhost",$dbu,$dbp);
if (!$con)
  {
  die('Could not connect to database: ' . mysqli_error());
  }
   
mysqli_select_db($con, $dbs);

date_default_timezone_set('Africa/Gaborone');
$entry_date = date("Y-m-d H:i:s", time()); 

$cx =$_GET['cx'];
$username = $_GET['user_name_text'];
$userpassword = $_GET['user_password_text'];
$email = $_GET['email_text'];

if (isset($_GET['access_checkbox'])) {$access = 'yes' ;} else {$access = 'no';}
if (isset($_GET['tlh_gab_checkbox'])) {$tlh_gab = 1;} else {$tlh_gab = 0;}
if (isset($_GET['tlh_ftw_checkbox'])) {$tlh_ftw = 1;} else {$tlh_ftw = 0;}
if (isset($_GET['rad_gab_checkbox'])) {$rad_gab = 1;} else {$rad_gab = 0;}
if (isset($_GET['rad_nam_checkbox'])) {$rad_nam = 1;} else {$rad_nam = 0;}
if (isset($_GET['vertex_checkbox'])) {$vertex = 1;} else {$vertex = 0;}
if (isset($_GET['pecus_checkbox'])) {$pecus = 1;} else {$pecus = 0;}
if (isset($_GET['admin_checkbox'])) {$admin = 1;} else {$admin = 0;}


$table_name = "system_users";
$access_query = "SELECT username FROM $table_name WHERE access_id = '".$cx."' ";
$access_result = $con->query($access_query);
$row = mysqli_fetch_assoc($access_result);
$login_name = $row["username"];


$table_name = "system_users";
$check_query = "SELECT username FROM $table_name WHERE username = '". $username."' ";
$check_result = $con->query($check_query);
$check_num = mysqli_num_rows($check_result);
if ($check_num!=0) { ?>
<script language="javascript" type="text/javascript">
          window.location="admin_settings.php?s=2&cx=<?php echo $cx ?>";
</script>
<?php   
}
else { 
$userid = $username.$username;
$table_name = "system_users";
$user_query  = "INSERT INTO $table_name (username, password_text, password, userid, email, access_id, access_limit, tlh_gab, tlh_ftw, rad_gab, rad_nam, vertex, pecus, admin) VALUES ('".$username."', '".$userpassword."', '".md5($userpassword)."','".md5($userid)."', '".$email."', '".md5($username)."', '".$access."', '".$tlh_gab."', '".$tlh_ftw."', '".$rad_gab."', '".$rad_nam."', '".$vertex."', '".$pecus."', '".$admin."')";
$user_result = $con->query($user_query);

$table_name = "system_admin_tracking";
$tracking_query = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$login_name."', '10', '".$username."','','', '' )";
$tracking_result = $con->query($tracking_query);

if ($tlh_gab==1) {
$table_name = "tlh_users";
$tlh_gab_query = "INSERT INTO $table_name (username, password, userid, email, access_id) VALUES ('".$username."', '".md5($userpassword)."','".md5($userid)."', '".$email."', '".md5($username)."')";
$tlh_gab_result = $con->query($tlh_gab_query);

$table_name = "system_admin_tracking";
$tracking_query = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$login_name."', '11', '".$username."','Tlhomeso Gaborone','', '' )";
$tracking_result = $con->query($tracking_query);
}

if ($tlh_ftw==1) {
$table_name = "ftw_users";
$tlh_ftw_query = "INSERT INTO $table_name (username, password, userid, email, access_id) VALUES ('".$username."', '".md5($userpassword)."','".md5($userid)."', '".$email."', '".md5($username)."')";
$tlh_ftw_result = $con->query($tlh_ftw_query);

$table_name = "system_admin_tracking";
$tracking_query = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$login_name."', '11', '".$username."','Tlhomeso Francistown','', '' )";
$tracking_result = $con->query($tracking_query);
}


if ($rad_gab==1) {
$table_name = "rds_users";
$rad_gab_query = "INSERT INTO $table_name (username, password, userid, email, access_id) VALUES ('".$username."', '".md5($userpassword)."','".md5($userid)."', '".$email."', '".md5($username)."')";
$rad_gab_result = $con->query($rad_gab_query);

$table_name = "system_admin_tracking";
$tracking_query = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$login_name."', '11', '".$username."','Radstone Gaborone','', '' )";
$tracking_result = $con->query($tracking_query);
}

if ($rad_nam==1) {
$table_name = "nmb_users";
$rad_nam_query = "INSERT INTO $table_name (username, password, userid, email, access_id) VALUES ('".$username."', '".md5($userpassword)."','".md5($userid)."', '".$email."', '".md5($username)."')";
$rad_nam_result = $con->query($rad_nam_query);

$table_name = "system_admin_tracking";
$tracking_query = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$login_name."', '11', '".$username."','Radstone Namibia','', '' )";
$tracking_result = $con->query($tracking_query);
}

if ($vertex==1) {
$table_name = "ver_users";
$vertex_query = "INSERT INTO $table_name (username, password, userid, email, access_id) VALUES ('".$username."', '".md5($userpassword)."','".md5($userid)."', '".$email."', '".md5($username)."')";
$vertex_result = $con->query($vertex_query);

$table_name = "system_admin_tracking";
$tracking_query = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$login_name."', '11', '".$username."','Vertex','', '' )";
$tracking_result = $con->query($tracking_query);
}

if ($pecus==1) {
$table_name = "pec_users";
$pecus_query = "INSERT INTO $table_name (username, password, userid, email, access_id) VALUES ('".$username."', '".md5($userpassword)."','".md5($userid)."', '".$email."', '".md5($username)."')";
$pecus_result = $con->query($pecus_query);

$table_name = "system_admin_tracking";
$tracking_query = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$login_name."', '11', '".$username."','Pecus','', '' )";
$tracking_result = $con->query($tracking_query);
}


if ($admin==1) {

$table_name = "system_admin_tracking";
$tracking_query = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$login_name."', '11', '".$username."','System admin','', '' )";
$tracking_result = $con->query($tracking_query);
}



?>
<script language="javascript" type="text/javascript">
      window.location="admin_settings.php?s=1&cx=<?php echo $cx ?>";
</script>
<?php
}
?>



																  