<?php
// vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker:

/** 
* Ambiente para pruebas de regresión.
 *
 * PHP version 5
 *
 * @category  SIVeL
 * @package   SIVeL-pruebas
 * @author    Vladimir Támara <vtamara@pasosdeJesus.org>
 * @copyright 2006 Dominio público. Sin garantías.
 * @license   http://creativecommons.org/licenses/publicdomain/ Dominio Público. Sin garantías.
 * @version   $Id: ambiente.php,v 1.20 2009/05/03 12:23:21 vtamara Exp $
 * @link      http://sivel.sf.net
*/

/** 
 * Ambiente para pruebas de regresión.
 */
$include_path = ini_get("include_path");
ini_set("include_path", $include_path . ":/var/www/pear/:.:..");

$_COOKIE['PHPSESSID'] = 'vr3gae8jvi47847dfnutd6rkr7';
$_SESSION['_auth_PHPSESSID']['registered'] = 
    $_SESSION['_authsession']['registered'] = '1';
$_SESSION['_auth_PHPSESSID']['username'] =
    $_SESSION['_authsession']['username'] = 'sivel-prueba';
$_SESSION['_auth_PHPSESSID']['timestamp'] =
    $_SESSION['_authsession']['timestamp'] = '1150453479';
$_SESSION['_auth_PHPSESSID']['idle'] =
    $_SESSION['_authsession']['idle'] = '1150454683';
$_SESSION['id_funcionario'] = '1';


$_SESSION['opciones'][0] = 0;
$_SESSION['opciones'][1] = 11;
$_SESSION['opciones'][2] = 12;
$_SESSION['opciones'][3] = 21;
$_SESSION['opciones'][4] = 31;
$_SESSION['opciones'][5] = 41;
$_SESSION['opciones'][6] = 42;
$_SESSION['opciones'][7] = 43;
$_SESSION['opciones'][8] = 51;
$_SESSION['opciones'][9] = 44;
$_SESSION['opciones'][10] = 45;
$_SESSION['opciones'][11] = 46;
$_SESSION['opciones'][12] = 47;
$_SESSION['opciones'][13] = 48;
$_SESSION['opciones'][14] = 49;
$_SESSION['opciones'][15] = 60;


require_once "aut/conf.php";
require_once "DB.php";

/** 
 * Agrega datos a una pestaña del formulario Ficha.
 * Sólo puede llamarse una vez por cada ejecución de php (pues el
 * require se ejecuta una vez)
 *
 * @param handle  &$db          Conexión a BD
 * @param string  $tabla_prueba Tabla que debe incrementarse tras pasar pestaña
 * @param string  $post         Valor que debe tomar la variable $_POST
 * @param integer $basicos_id   Cód. caso si falta $_SESSION['basicos_id']
 * @param boolean $terminaError Si hay error terminar
 *
 * @return nada 
 */
function pasaPestanaFicha(&$db, $tabla_prueba, $post, $basicos_id = null,
    $terminaError = true) 
{

    if (!isset($db) || PEAR::isError($db)) {
        echo "Error en conexión " . $db->getMesssage();
        exit(1);
    }
    $_SESSION['fvloc_pag'] = '0';
    $_SESSION['fub_pag'] = '0';
    $_SESSION['ff_pag'] = '0';
    $_SESSION['fd_pag'] = '0';
    $_SESSION['fpr_pag'] = '0';
    $_SESSION['fvi_pag'] = '0';
    $_SESSION['fvc_pag'] = '0';
    $_SESSION['fvm_pag'] = '0';
    $_SESSION['__container']['defaults']['borderpainted'] = '';
    $_SESSION['__container']['defaults']['borderclass'] = 'progressBarBorder';
    $_SESSION['__container']['defaults']['borderstyle']['style'] = 'solid';
    $_SESSION['__container']['defaults']['borderstyle']['width'] = '0';
    $_SESSION['__container']['defaults']['borderstyle']['color'] = '#000000';
    $_SESSION['__container']['defaults']['cellid'] = 'progressCell%01s';
    $_SESSION['__container']['defaults']['cellclass'] = 'cell';
    $_SESSION['__container']['defaults']['cellvalue']['min'] = '0';
    $_SESSION['__container']['defaults']['cellvalue']['max'] = '100';
    $_SESSION['__container']['defaults']['cellvalue']['inc'] = '1';
    $_SESSION['__container']['defaults']['cellsize']['width'] = '15';
    $_SESSION['__container']['defaults']['cellsize']['height'] = '20';
    $_SESSION['__container']['defaults']['cellsize']['spacing'] = '2';
    $_SESSION['__container']['defaults']['cellsize']['count'] = '10';
    $_SESSION['__container']['defaults']['cellcolor']['active'] = '#006600';
    $_SESSION['__container']['defaults']['cellcolor']['inactive'] = '#CCCCCC';
    $_SESSION['__container']['defaults']['cellfont']['family'] = 
        'Courier, Verdana';
    $_SESSION['__container']['defaults']['cellfont']['size'] = '8';
    $_SESSION['__container']['defaults']['cellfont']['color'] = '#000000';
    $_SESSION['__container']['defaults']['stringpainted'] = '';
    $_SESSION['__container']['defaults']['stringid'] = 'installationProgress';
    $_SESSION['__container']['defaults']['stringsize']['width'] = '50';
    $_SESSION['__container']['defaults']['stringsize']['height'] = '';
    $_SESSION['__container']['defaults']['stringsize']['bgcolor'] = '#FFFFFF';
    $_SESSION['__container']['defaults']['stringvalign'] = 'right';
    $_SESSION['__container']['defaults']['stringalign'] = 'right';
    $_SESSION['__container']['defaults']['stringfont']['family'] = 
        'Verdana, Arial, Helvetica, sans-serif';
    $_SESSION['__container']['defaults']['stringfont']['size'] = '10';
    $_SESSION['__container']['defaults']['stringfont']['color'] = '#000000';
    $_SESSION['__container']['defaults']['phpcss']['P'] = '1';
    $_SESSION['__container']['valid']['basicos'] = '';
    $_SESSION['__container']['valid']['localizacion'] = '';
    $_SESSION['__container']['valid']['ubicacion'] = '';
    $_SESSION['__container']['valid']['frecuentes'] = '';
    $_SESSION['__container']['valid']['otras'] = '';
    $_SESSION['__container']['valid']['tipoViolencia'] = '';
    $_SESSION['__container']['valid']['pResponsables'] = '';
    $_SESSION['__container']['valid']['victimaIndividual'] = '';
    $_SESSION['__container']['valid']['victimaColectiva'] = '';
    $_SESSION['__container']['valid']['victimaCombatiente'] = '';
    $_SESSION['__container']['valid']['memo'] = '';
    $_SESSION['__container']['valid']['evaluacion'] = '';

    $_SERVER['REQUEST_URI'] = '127.0.0.1';

    $_SESSION['sin_csrf'] =  $post['evita_csrf'] = 1234;

    //print_r($db);
    if (isset($basicos_id) && $basicos_id!= null &&
        !isset($_SESSION['basicos_id'])) {
        $_SESSION['basicos_id'] = $basicos_id;
    }

    foreach ($tabla_prueba as $nt) { 
        $q = "SELECT COUNT(*) FROM $nt";
        $na[$nt] = (int)($db->getOne($q));
    }
    $_REQUEST = $_POST = $post;


    require_once "../captura_caso.php";

    /* Verificando */
    foreach ($tabla_prueba as $nt) { 
        $q = "SELECT COUNT(*) FROM $nt";
        $nd[$nt] = (int)($db->getOne($q));
        //echo " nd[nt] = $nd[$nt] ";
        if (($nd[$nt]-$na[$nt])!= 1) {
            echo "No insertaron datos de pestaña en tabla $nt";
            if ($terminaError) {
                exit(1);
            }
        }
    }

}


$options = array(
    'debug'       => 5
);
$db = & DB::connect($dsn, $options);

if (PEAR::isError($db)) {
    echo $db->getMessage();
    exit(1);
}        

?>
