<?php
//DB Data
require_once("../../../db.php");
require_once("../../../includes/bootstrap_frontend.php");
sessionsClass::site_protection(true,true,true,false);

//Variables Post
$user_id = $_POST['user_id'];
$user_name = $_POST['user_name'];
$user_role = $_POST['user_role'];
$user_email = $_POST['user_email'];
$current_pass = $_POST['current_pass'];
$new_pass = $_POST['new_pass'];

if(isset($_POST['new_pass'])){
    
    //new passwords
    $p1  = md5(dbase::globalMagic($new_pass));
    $p2  = md5(dbase::globalMagic($new_pass));
    //current password
    $p4  = md5(dbase::globalMagic($current_pass));
    
    
    $passwordResponse = validator::passwordValidate($p1,$p2,0);
    
    if ($passwordResponse['Ack']=='fail'){
        $valid = 'fail';
    }
    
    $passwordResponse = validator::checkPasswordDB($p4,$user_id);
    
    if ($passwordResponse['validAck']=='fail'){
        $valid = 'fail';
    }
    
    if ($valid != 'fail'){
        $salt = general::generate_salt();
        $phash = general::doubleSalt($p1,$salt);
		
		mysql_query("UPDATE user_table SET username = '$user_name', screenname = '$user_name', p_hash = '$phash', s_hash = '$salt', email = '$user_email' WHERE userid = $user_id", $conn);
		
    }
    else{
        $chpass_msg = 'correct the errors and try again.';
		mysql_query("UPDATE user_table SET username = '$user_name', screenname = '$user_name', email = '$user_email' WHERE userid = $user_id", $conn);
    }
    
} 

header("Location: ../../manage-user.php?userid=".$user_id);
?>