<?php

  if( $Debug == 1 ){
    echo "Edit View";
  }

  $id             = $decoded['id'];
  $email          = $decoded['email'];
  $cel            = $decoded['cel'];

  if( $id || $email || $cel  ){

    $WHERE = "
      WHERE usr.Id != '0'
    ";

    //Id
    if( $id ){
      $WHERE .= "
        AND usr.id = '$id'
      ";
    }
    //End Id

    //Email
    if( $email ){
      $WHERE .= "
        AND usr.email = '$email'
      ";
    }
    //End Email

    //Cel
    if( $cel ){
      $WHERE .= "
        AND usr.celular = '$cel'
      ";
    }
    //End Cel

    //Datos de Usuarios Tendero
    $Query = "
      SELECT
        usr.id,
        usr.nombre, usr.apellido_paterno, usr.apellido_materno,
        usr.celular, usr.email, usr.fecha_alta, usr.clave,
        usr.puntos, usr.activo
      FROM usuarios_app usr
      $WHERE
    ";
    $Result = mysqli_query($mysqli, $Query);
	  $Usr = mysqli_fetch_assoc($Result);

    if( $Usr[id] ){

      $FechaAlta = date('Y-m-d', strtotime($Usr[fecha_alta]));
      $HoraAlta  = date('H:i:s', strtotime($Usr[fecha_alta]));

      $Data = array(
        'action'             => 'ok',
        'id_user'            => "$Usr[id]",
        'puntos'             => "$Usr[puntos]"
      );
      echo json_encode($Data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);

    }else{

      //Error uv-1 ( El Usuario no se encontró. )
      $Query = "
        SELECT
          err.Id, err.error, err.msn
        FROM api_errores err
        WHERE err.error = 'uc-1'
      ";
      $Result = mysqli_query($mysqli, $Query);
      $Error = mysqli_fetch_assoc($Result);

      $Data = array(
        'action'      => 'error',
        'error'       => $Error[error],
        'error_msn'   => $Error[msn]
      );
      echo json_encode($Data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);

    }

  }

?>
