<?php

include ("header.php");

        $titulo="Nuevo Usuario";

        $tituloBoton="Guardar";

        $edt=0;

        $guardado=0;

        $consulta='nada';

        $nombre='';

        $telefono='';

        $celular='';

        $email='';

        $direccion='';

        $referido='';

        $id=0;

        $borrar='';

        $error=0;

        if (!empty($_GET))

            {

                $edt = $_GET['edt'];

                $id = $_GET['id'];

                $borrar = $_GET['borrar'];

                $titulo="Modificar Usuarios";

                $tituloBoton="Modificar";

                $id = $_GET['id'];

                $sql="SELECT * FROM `usuarios` WHERE id = $id";

                $result = $mysqli->query($sql); 

                $row = $result->fetch_assoc();

                $nombre=$row['nombre'];

                $usuario=$row['usuario'];

                $correo=$row['correo'];

                $cedula=$row['cedula'];

                $password=$row['password'];

                

            }





        if (!empty($_POST))

        {

            $nuevo = $mysqli->real_escape_string($_POST['nuevo']);

            $actual=$mysqli->real_escape_string($_POST['actual']);

            $confirmar=$mysqli->real_escape_string($_POST['confirmar']);

            $password=$mysqli->real_escape_string($_POST['password']);

            $opc=$mysqli->real_escape_string($_POST['opc']); 



            if($password==$actual)

            {

            if($nuevo==$confirmar)

            {

            $consulta="UPDATE `usuarios` SET `password`='".$nuevo."'  WHERE `id`='".$id."'";

            $stmt = $mysqli->prepare($consulta);

            if ($stmt->execute()){

                

            $guardado=1;

            $textguardar='modificado';



            } 

            else

                $error=1;    

            }

            else

                $error=1;

            }

            else

                $error=1;



        }



        if ($id > 0)

        {$opc=1;}

    else

        {$opc=2;}

?>



        <div class="content-wrapper">

            <!-- START PAGE CONTENT-->

            <div class="page-heading">

                <h1 class="page-title">Usuario</h1>

            </div>

            <div class="page-content fade-in-up">

                    <div class="ibox-body">

                    <div class="page-content fade-in-up">

                <div class="row">

                    <div class="col-md-3">

                        <div class="ibox">

                      

                            <div class="ibox-head">

                                <div class="ibox-title">Datos Usuario</div>

                                <div class="ibox-tools">

                                    <a class="ibox-collapse"><i class="fa fa-minus"></i></a>

                                    <a class="fullscreen-link"><i class="fa fa-expand"></i></a>

                                </div>

                            </div>

                            <div class="ibox-body">

                            <form id="signupform" class="form-horizontal" role="form" action="<?php $_SERVER['PHP_SELF'] ?>" method="POST" autocomplete="off">

                                    <div class="row">

                                    <div class="col-sm-12 form-group">

                                            <label>Usuario</label>

                                            <input name="usuario" class="form-control" type="text" placeholder="Usuario para abrir sistema" value="<?php echo $usuario; ?>" readonly>

                                        </div>



                                        <div class="col-sm-12 form-group">

                                            <label>Nombre</label>

                                            <input name="nombre" class="form-control" type="text" placeholder="Nombre de Usuario" value="<?php echo $nombre; ?>" readonly>

                                        </div>

                                    <div class="col-sm-12 form-group">

                                            <label>Correo</label>

                                            <input name="correo" class="form-control" type="text" placeholder="Email" value="<?php echo $correo; ?>" readonly>

                                        </div>

                                        <div class="col-sm-12 form-group">

                                            <label>Cedula</label>

                                            <input name="cedula" class="form-control" type="text" placeholder="Cedula profesional" value="<?php echo $cedula; ?>" readonly>

                                        </div>

                                    

                    

                                   

                            </div>

                        </div>

                    </div>

                            

                            

                            

                            

                            

                            

                            

                            

                            

                            

            </div>

                        

                        

                                            <div class="col-md-3">

                        <div class="ibox">

                        <?php

                            if ($guardado == 1){?>

                        <div class="alert alert-success " role="alert">

                            Password <?php echo $textguardar;?> con exito...

                            

                        </div>

                        <?php

                        }

                        if ($error == 1){?>

                            <div class="alert alert-danger " role="alert">

                                Error al guardar, verifique los datos...

                               

                            

                            <?php

                            }

                        ?>

                            <div class="ibox-head">

                                <div class="ibox-title">Modificar Password</div>

                                <div class="ibox-tools">

                                    <a class="ibox-collapse"><i class="fa fa-minus"></i></a>

                                    <a class="fullscreen-link"><i class="fa fa-expand"></i></a>

                                </div>

                            </div>

                            <div class="ibox-body">

                            <form id="signupform" class="form-horizontal" role="form" action="<?php $_SERVER['PHP_SELF'] ?>" method="POST" autocomplete="off">

                                    <div class="row">

                                    <div class="col-sm-12 form-group">

                                            <label>Password Actual</label>

                                            <input name="actual" class="form-control" type="password" autofocus required>

                                        </div>



                                        <div class="col-sm-12 form-group">

                                            <label>Nuevo Password</label>

                                            <input name="nuevo" class="form-control" type="password" required>

                                        </div>

                                    <div class="col-sm-12 form-group">

                                            <label>Confirmar Password</label>

                                            <input name="confirmar" class="form-control" type="password" required>

                                        </div>



                                    

                    

                                    <input id="opc" name="opc" type="hidden" value="<?php echo $opc;?>">

                                    <input id="password" name="password" type="hidden" value="<?php echo $password;?>">

                                    <div class="col-sm-12 form-group">

                                    <button class="btn btn-info" type="submit"><?php echo $tituloBoton;?></button>

                                    <a href="usuarios.php" class="btn btn-primary" role="button" data-bs-toggle="button">Regresar</a>

                                    </div>

                                </form>

                            </div>

                        </div>

                    </div>

        </div>     

<?php 

    include ('footer.php');

?>