<?php

  $debugin        = $decoded['debug'];
  $usr_id         = $decoded['usr_id'];

  if( $usr_id ){

    //User
    $Query = "
      SELECT
        usr.id
      FROM usuarios_app usr
      WHERE
        usr.id = '$usr_id'
        AND usr.activo = '1'
    ";
    $Result = mysqli_query($mysqli, $Query);
    $Usr = mysqli_fetch_assoc($Result);
    if( $Usr[id] ){

      //Categorias
      $Query = "
        SELECT
          cat.id, cat.categoria AS nombre
        FROM cat_articulos_categorias cat
        WHERE cat.activo = '1'
        ORDER BY cat.categoria
      ";
      $Cats = $mysqli->query($Query);
      mysqli_data_seek($Cats, 0);
      while($Cat = mysqli_fetch_array($Cats)) {

        $Categorias[] = array(
          'categoria_id'  => $Cat[id],
          'nombre'    => $Cat[nombre]
        );

      }

      $Data = array(
        'categorias'   => $Categorias
      );
      echo json_encode($Data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);

    }else{

      //Error
      $Query = "
        SELECT
          err.Id, err.error, err.msn
        FROM api_errores err
        WHERE err.error = 'uv-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);

    }

  }

?>
