<?php

require_once ( 'ew_data_ew.php' );


if (!isset($html_charset)) {
    $html_charset = 'UTF-8'; //ISO-8859-1
}


if (!isset($db_charset)) {
    $db_charset = '';
}


// esto es para posicionar bien los scripts que se ejecutan en modo comando.
function getraiz() {
    global $argv;

    if (isset($_SERVER["DOCUMENT_ROOT"]) && ($_SERVER["DOCUMENT_ROOT"] != "")) {
        $raiz = $_SERVER["DOCUMENT_ROOT"];
        return $raiz;
    }
    $prg = $argv[0];
    $raiz = "";
    $i = strpos($prg, "public_html/");
    if ($i !== false) {
        $raiz = substr($prg, 0, $i + strlen("public_html"));
    } else {
        $i = strpos($prg, "www/");
        if ($i !== false) {
            $raiz = substr($prg, 0, $i + strlen("www"));
        } else {
            $i = strrpos( $prg, '/'); // ultimo
            if ($i !== FALSE) {
                $raiz = "";
            } else {
                $raiz = substr($prg, 0, $i);
            }
        }
    }
    return $raiz;
}

$root_dir = getraiz();
$DOCUMENT_ROOT = $root_dir;

if (!isset($_SERVER["DOCUMENT_ROOT"])) {
    $_SERVER["DOCUMENT_ROOT"] = $root_dir;
}
if ($_SERVER["DOCUMENT_ROOT"] == "") {
    $_SERVER["DOCUMENT_ROOT"] = $root_dir;
}

function draiz_(){
    global $DOCUMENT_ROOT, $subcarpeta_raiz;
    return   $DOCUMENT_ROOT . $subcarpeta_raiz;
}

function url_raiz(){
    global $subcarpeta_raiz;
    if ( !isset( $_SERVER['SERVER_NAME'] ) ){
        $_SERVER['SERVER_NAME'] = 'localhost';
    }
    return $_SERVER['SERVER_NAME'].$subcarpeta_raiz;
}

function subcarpeta_raiz(){
    global $subcarpeta_raiz;
    return $subcarpeta_raiz;
}
