<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'];

$edit_user_name = $_GET['edit_user_name_text'];
$edit_user_password = $_GET['edit_user_password_text'];
if (isset($_GET['access_checkbox'])) {$edit_access = 'yes' ;} else {$edit_access = 'no';}
$edit_email = $_GET['edit_email_text'];

$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";
$saved_system_query = "SELECT password_text, access_limit, email FROM $table_name WHERE username = '".$edit_user_name."' ";
$saved_system_result = $con->query($saved_system_query);
$saved_system_num = mysqli_num_rows($saved_system_result);
$row = mysqli_fetch_assoc($saved_system_result);
$saved_password_text = $row["password_text"];
$saved_access = $row["access_limit"];
$saved_email = $row["email"];


$table_name = "system_users";
$system_query = "UPDATE $table_name SET password_text = '".$edit_user_password."', password = '".md5($edit_user_password)."', email = '".$edit_email."', access_limit = '".$edit_access."' WHERE username = '".$edit_user_name."' ";
$system_result = $con->query($system_query);

$table_name = "tlh_users";
$system_query = "UPDATE $table_name SET password = '".md5($edit_user_password)."', email = '".$edit_email."' WHERE username = '".$edit_user_name."' ";
$system_result = $con->query($system_query);

$table_name = "ftw_users";
$system_query = "UPDATE $table_name SET password = '".md5($edit_user_password)."', email = '".$edit_email."' WHERE username = '".$edit_user_name."' ";
$system_result = $con->query($system_query);

$table_name = "rds_users";
$system_query = "UPDATE $table_name SET password = '".md5($edit_user_password)."', email = '".$edit_email."' WHERE username = '".$edit_user_name."' ";
$system_result = $con->query($system_query);

$table_name = "nmb_users";
$system_query = "UPDATE $table_name SET password = '".md5($edit_user_password)."', email = '".$edit_email."' WHERE username = '".$edit_user_name."' ";
$system_result = $con->query($system_query);

$table_name = "vertex_users";
$system_query = "UPDATE $table_name SET password = '".md5($edit_user_password)."', email = '".$edit_email."' WHERE username = '".$edit_user_name."' ";
$system_result = $con->query($system_query);




if ($saved_password_text!=$edit_user_password) {
	 	$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."', '14', '".$edit_user_name."','".$saved_password_text."','".$edit_user_password."', 'Password' )";
		$tracking_result = $con->query($tracking_query);
}

if ($saved_access!=$edit_access) {
	 	$table_name = "system_admin_tracking";
		$tracking_uery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$login_name."', '14', '".$edit_user_name."','".$saved_access."','".$edit_access."', 'Access limit' )";
		$tracking_result = $con->query($tracking_query);
}

if ($saved_email!=$edit_email) {
	 	$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."', '14', '".$edit_user_name."','".$saved_email."','".$edit_email."', 'Email' )";
		$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
//}
?>



																  