<?php
include_once("utiles.php");
//include_once("apt_funciones.php");

date_default_timezone_set("America/Panama");
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
mysqli_report(MYSQLI_REPORT_STRICT);

if (!$connection = connectDb()) {
    die("err db");
} else {
    $connection->query("SET NAMES 'utf8';");
}
session_start();
mysqli_set_charset($connection, 'utf8');
$_SESSION['database'] = $_GET['database'];
$_SESSION['cod_sucu'] = $_GET['cod_sucu'];

$cDbName = $_SESSION['database'];
$cCodSuc = $_SESSION['cod_sucu'];

$cSql_Ln =   "
SELECT
    UPPER(TRIM(suc_descripcion)) AS suc_descripcion          ,  
    suc_id            , suc_id_fiscal   ,  
    suc_dv            , suc_tipo_persona, suc_coordenadas    ,  
    suc_prov_fe_cod   , suc_prov_fe_desc, suc_dist_fe_cod    ,  
    suc_dist_fe_desc  , suc_corr_fe_cod , suc_corr_fe_desc   ,  
    suc_ubica_cod_fe  , suc_direccion   , suc_correo         ,  
    suc_telefono1     , suc_telefono2            
FROM $cDbName.sucursales
WHERE (suc_id=$cCodSuc) AND (IFNULL(suc_activa,0)=1) ORDER BY 1";

$oData = mysqli_query($connection, $cSql_Ln);

$jsonData = array();
$jsonTempData = array();

while ($row = mysqli_fetch_array($oData, MYSQLI_ASSOC)) {
    $jsonTempData['suc_id'] = $row['suc_id'];
    $jsonTempData['suc_descripcion'] = mb_convert_encoding($row['suc_descripcion'], 'UTF-8', 'auto');
    $jsonTempData['suc_id_fiscal'] = mb_convert_encoding($row['suc_id_fiscal'], 'UTF-8', 'auto');
    $jsonTempData['suc_dv'] = mb_convert_encoding($row['suc_dv'], 'UTF-8', 'auto');
    $jsonTempData['suc_tipo_persona'] = $row['suc_tipo_persona'];
    $jsonTempData['suc_coordenadas'] = mb_convert_encoding($row['suc_coordenadas'], 'UTF-8', 'auto');
    $jsonTempData['suc_prov_fe_cod'] = $row['suc_prov_fe_cod'];
    $jsonTempData['suc_prov_fe_desc'] = mb_convert_encoding($row['suc_prov_fe_desc'], 'UTF-8', 'auto');
    $jsonTempData['suc_dist_fe_cod'] = $row['suc_dist_fe_cod'];
    $jsonTempData['suc_dist_fe_desc'] = mb_convert_encoding($row['suc_dist_fe_desc'], 'UTF-8', 'auto');
    $jsonTempData['suc_corr_fe_cod'] = $row['suc_corr_fe_cod'];
    $jsonTempData['suc_corr_fe_desc'] = mb_convert_encoding($row['suc_corr_fe_desc'], 'UTF-8', 'auto');
    $jsonTempData['suc_ubica_cod_fe'] = mb_convert_encoding($row['suc_ubica_cod_fe'], 'UTF-8', 'auto');
    $jsonTempData['suc_direccion'] = mb_convert_encoding($row['suc_direccion'], 'UTF-8', 'auto');
    $jsonTempData['suc_correo'] = mb_convert_encoding($row['suc_correo'], 'UTF-8', 'auto');
    $jsonTempData['suc_telefono1'] = mb_convert_encoding($row['suc_telefono1'], 'UTF-8', 'auto');
    $jsonTempData['suc_telefono2'] = mb_convert_encoding($row['suc_telefono2'], 'UTF-8', 'auto');

    $jsonData[] = $jsonTempData;
}
header('Content-type: application/json;charset=utf-8');
print_r(json_encode($jsonData));

$row = NULL;
$jsonData = NULL;
$jsonTempData = NULL;

mysqli_free_result($oData);
mysqli_close($connection);
/*
ULTIMA MODICICASION 2023-11-13 JOHNN GUTIERREZ
*/
?>