<?php


if(session_status() != PHP_SESSION_ACTIVE)
{

if (isset($_SERVER['HTTPS']) &&
        ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
        isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
        $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
            session_set_cookie_params(["samesite" => "None", 'Secure' => true]);
           
    }
    session_name('__OxaProc-PHPSESSID');
    session_start();
}

require_once 'application/class/class_panier.php';

global $connecteur;

if (getValue('action') == 'voirShortList') {
    
    $Fournisseur = new Fournisseur();
    $results = $Fournisseur->getShortListFourn(getValue('codeFrs'));
    if (! is_null($results)) {
        foreach ($results as $result) {
            $array['short'][] = array(
                'CODLST' => $result['CODLST'],
                'LIBELLE' => $result['LIBELLE']
            );
        }
    } else
        $array = array();
    
    $array['codeShortListeTable'] = Trad('Code Short List');
    $array['libelleShortListeTable'] = Trad('Libellé');
    $array['optionShortListeTable'] = Trad('');
    $array['codeFrs'] = getValue('codeFrs');
    
    $array['popup_title'] = trad('Short lists');
    
    $ObjXSLT = new GenXslt(true);
    
    if (getValue('refresh')) {
        
        $ObjXSLT->XslHtml('application/xsl/gest_fourniss/gest_short_list_fournisseur.xsl', $array);
        
        echo $ObjXSLT->echoHtml('shortListTable');
    } else
        echo $ObjXSLT->XslHtml('application/xsl/gest_fourniss/gest_short_list_fournisseur.xsl', $array);
}
if (getValue('action') == 'deleteTuple') {
    
    $Fournisseur = new Fournisseur();
    $results = $Fournisseur->deleteShortListFourn(getValue('codeFrs'), getValue('codlist'));
}

if (getValue('action') == 'voirShortListAll') {
    
    $Fournisseur = new Fournisseur();
    if (getValue('content')) {
        $results = $Fournisseur->getShortListFourn(getValue('codeFrs'), 1, getValue('content'));
    } else
        $results = $Fournisseur->getShortListFourn(getValue('codeFrs'), 1);
    if (! is_null($results)) {
        foreach ($results as $result) {
            $array['short'][] = array(
                'CODLST' => $result['CODLST'],
                'LIBELLE' => $result['LIBELLE']
            );
        }
    } else
        $array = array();
    
    $array['codeShortListeTable'] = Trad('Code Short List');
    $array['libelleShortListeTable'] = Trad('Libellé');
    $array['optionShortListeTable'] = Trad('');
    $array['codeFrs'] = getValue('codeFrs');
    
    $array['popup_title'] = trad('Liste des short lists');
    $ObjXSLT = new GenXslt(true);
    
    if (getValue('refresh')) {
        $ObjXSLT->XslHtml('application/xsl/gest_fourniss/gest_short_list_fournisseur_all.xsl', $array);
        echo $ObjXSLT->echoHtml('shortListTableall');
    } else {
        
        echo $ObjXSLT->XslHtml('application/xsl/gest_fourniss/gest_short_list_fournisseur_all.xsl', $array);
    }
}

if (getValue('action') == 'addTuple') {
    
    $Fournisseur = new Fournisseur();
    $result = $Fournisseur->addShortListFourn(getValue('codeFrs'), getValue('codlist'));
    
    // echo 'Oxa_getDevice().closePopup("voir_short_list_all");';
    
    echo "me().opener.window.CallUrl('popup_short_list.php?action=voirShortList&codeFrs=" . urlencode(getValue('codeFrs')) . "&refresh=true');";
    
    echo "me().window.window.CallUrl('popup_short_list.php?action=voirShortListAll&codeFrs=" . urlencode(getValue('codeFrs')) . "&refresh=true');";
    
    // echo "child.document.getElementById('shortListTable').innerHTML =('<td>".$result."</td><td>".$result."</td>');";
}

$connecteur->disconnect();
exit();
