<?php

  if( $Debug == 1 ){
    echo "Add User Tendero";
  }

  $debugin        = $decoded['debug'];
  echo $usr_id         = $decoded['usr_id'];
  $nombre         = $decoded['nombre'];
  $apellidop      = $decoded['apellidop'];
  $apellidom      = $decoded['apellidom'];
  $email          = $decoded['email'];
  $cel            = $decoded['cel'];

  $FechaHoy       = date('Y-m-d H:i:s');

  if( $usr_id ){

    //Verifica I Usuario
    $Query = "
      SELECT
        usr.id
      FROM usuarios_app usr
      WHERE
        usr.id = '$usr_id'
    ";
    $Result = mysqli_query($mysqli, $Query);
	  $ValidarUsr = mysqli_fetch_assoc($Result);

    if( $ValidarUsr[id] ){

      //Actualiza Usuario
      $Query = "
        UPDATE usuarios_app
        SET
          nombre = '$nombre',
          apellido_paterno = '$apellidop',
          apellido_materno = '$apellidom',
          email = '$email',
          celular = '$cel'
        WHERE Id = '$ValidarUsr[id]'
      ";
      $Result = mysqli_query($mysqli, $Query);
      //End Usuario

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

    }else{

      //Error ua-1 ( No se guardo en la BD )
      $Query = "
        SELECT
          err.Id, err.error, err.msn
        FROM api_errores err
        WHERE err.error = 'ua-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);

    }

  }


?>
