<?php
require_once 'application/class/class_ManageSession.php';
/**
 * Affichage de la liste des secteurs d'imputation
 */
$flg_popup = true;

// si on est en mode HTML, on charge l'entête.
$isHttp = (GetValue('THROUGH') == 'TRUE');
if (! isset($flg_popup))
    $flg_popup == false;

$fichier_xsl = 'application/xsl/liste_simple.xsl';

$brwListe = new NewBrowse('BrwListe', 'Code', 'Libelle');
$brwListe->EntColonne('Code', 'Libelle');
$brwListe->appel_prg(NomFile(__FILE__));
$brwListe->ElementUnique[0] = 'Code';
$brwListe->flg_titre = false;
$brwListe->flg_rech = false;
$brwListe->flg_nbr = false;
$brwListe->AffEntete = false;
$brwListe->NbLig = 10;
$brwListe->onClick = true;
$brwListe->form = 'frm_recherche';
$brwListe->separator = chr(126);

$cod_rech = getValue('cod_rech');
$lib_rech = getValue('lib_rech');

$class = new RechercheSynequaListeSSFam();

// Renvoi l'array de resultat
/**
 * $page = 0;
 * $nligne = $obj_browse->NbLig;
 * if ($result = $obj_browse->cls_query->ReturnData($page,$nligne,$texte,$txt_frs,$cod_fourn_sinequa,$code_sfam_sinequa,$lib_rsfab_sinequa,$lib_gam_sinequa,$id_cat))
 * {
 *
 * }
 */

if ($isHttp) {
    $obj_xml = new GenXslt();
    switch (GetValue('MODE')) {
        // Mode appserveur
        case 'httpreq': // mode reponse sur les updates
            $object = GetValue('OBJECT');
            $form_parent = GetValue('form_parent');
            $champ = GetValue('champ');
            $prg_appel = GetValue('prg_appel');
            
            if (strpos($object, 'rUser_') === 0) {
                $rep = '';
                $code_retour = explode($brwListe->separator, getValue($object));
                
                $chs = explode(',', $champ);
                
                $rep .= " me().opener.document.{$form_parent}.{$chs[1]}.value = '" . getValue($object) . "';";
                $rep .= " me().opener.Traite('rech_avance.php?target={$chs[2]}',me().opener.document.{$form_parent}.{$chs[1]}) ; masquePopup();";
                
                echo $rep;
            } else {
                $sql = $class->ReturnData(getValue('lib_rech'), getValue('cod_rech'));
                $brwListe->AffBrowse('', $sql, DB_OXASQLDB);
                $array['browse'][$brwListe->NomBrowse()] = & $brwListe->xml_gen;
                
                $obj_xml->XslHtml($fichier_xsl, $array);
                $obj_xml->echoHtml('brw_' . $brwListe->NomBrowse());
            }
            break;
        case 'brw_' . $brwListe->NomBrowse():
            $sql = $class->ReturnData(getValue('lib_rech'), getValue('cod_rech'));
            $brwListe->AffBrowse('', $sql, DB_OXASQLDB);
            $array['browse'][$brwListe->NomBrowse()] = & $brwListe->xml_gen;
            
            $obj_xml->XslHtml($fichier_xsl, $array);
            $obj_xml->echoHtml('brw_' . $brwListe->NomBrowse());
            break;
        default:
            break;
    }
} else {
    $obj_xml = new GenXslt(true);
    if ($_SERVER['REQUEST_METHOD'] == 'GET') {
        $sql = $class->ReturnData(getValue('lib_rech'), getValue('cod_rech'));
        $brwListe->AffBrowse('', $sql, DB_OXASQLDB);
        $array['browse'][$brwListe->NomBrowse()] = & $brwListe->xml_gen;
    }
    $array['fenetre'] = array(
        '!form' => 'frm_popup',
        '!form_parent' => getValue('form_parent'),
        '!prg_appel' => getValue('prg_appel'),
        '!champ' => getValue('champ'),
        '!titre' => trad('Liste des Sous Familles'),
        '!num_lig' => getValue('num_lig'),
        '!onclick' => "Traite('" . NomFile(__FILE__) . "',document.frm_recherche.cod_rech)"
    );
    
    echo $obj_xml->XslHtml($fichier_xsl, $array);
}

$connecteur->disconnect();