<?php
session_start();
require('45789417/ref4780.php');
if (!isset($_SESSION['userid'])) {
  echo "<script language='Javascript'> location.href='login.php';</script>";
    exit();
  };
if ($_SESSION['type_user_live'] == "Paciente") {
   	echo "<script type='text/javascript'>  
	window.location='paci_virtual/index.php';
	</script>";
    }
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8"> 
<title>Historia Clínica, Clínica Los Robles</title>
</head>
<body>
<?php
$id = $_POST['id'];
$name  = $_POST['name'];
$email  = $_POST['email'];
$query = mysqli_query($con,"UPDATE user SET name='$name', email='$email' WHERE id = '$id'");
if( $_POST['password_actual'] != "" ){
		
		$password_actual = $_POST['password_actual'];
		$password = md5("7981".$_POST["password2"]);  
		$pass3 = md5("7981".$_POST["password_actual"]);  
		$consulta_mysql= mysqli_query($con,"SELECT id,name,type_user,password FROM user WHERE id = '$id'");
		$registro = mysqli_fetch_assoc($consulta_mysql);  
		$pass_actual = $registro["password"];
		if($pass3 != $pass_actual){
			echo "<script language='Javascript'> 
			alert('la contraseña actual no coincide');
			location.href='user.php';
			</script>";
		    exit();
		} ;
	$query = $query = mysqli_query($con,"UPDATE user SET password='$password'  WHERE id = '$id'");
	};
echo "<script language='Javascript'> location.href='user.php?update=1';</script>";
?>

</body>
</html>
