<?php
if (! class_exists('RechercheSynequaArtFam')) {

    class RechercheSynequaArtFam extends BaseSynequa
    {

        var $cod_art = '';

        var $cod_frs = '';

        // Création d'un tableau contenant les catalogues multifournisseur
        protected $liste_cata_multi_frs = array();

        public function &getliste_cata_multi_frs()
        {
            return $this->liste_cata_multi_frs;
        }

        function &ReturnData($page, $nligne, $texte, $txt_frs, $COD_FOURN = '', $CODE_SFAM = '', $RS_FAB = '', $LIB_GAM = '', $ID_CAT = '')
        {
            $indice = $_SESSION['nb_page_demande'];
            $_SESSION["req_syn_COD_FOURN_{$indice}"] = $COD_FOURN;
            $_SESSION["req_syn_LIB_SFAM_{$indice}"] = $CODE_SFAM;
            $_SESSION["req_syn_RS_FAB_{$indice}"] = $RS_FAB;
            $_SESSION["req_syn_LIB_GAM_{$indice}"] = $LIB_GAM;
            
            $result = null;
            $this->count_row = 0;
            $this->arr_cod_fourn = null;
            $this->arr_lib_sfam = null;
            $this->arr_rs_fab = null;
            $this->arr_lib_gam = null;
            
            if ('' != $CODE_SFAM) {
                $CODE_SFAM = ReplaceSqlPointeur($CODE_SFAM);
                $where .= " and SSFAM =''$CODE_SFAM'' ";
            }
                        
            $req = "EXEC Oxaproc_GenArtFreeRankDes '".$_SESSION["Session_Login"]."','".$_SESSION['Session_Langue']."','SSF','$texte','','$where',$nligne,$page";
            
            //TODO NEW CONNECTEUR
            $requete = new RequeteSQL($req, DB_OXAFTDB);
            $listeRow = $requete->TrouveTous();
            
            foreach($listeRow as $row) {
                $this->count_row = $this->count_row+1;
                $result[] = array(
                    'PROVENANCE' => 'ARTGEN',
                    'ID_CAT' => '',
                    'COD_ART' => $row['CODE_ART'],
                    'COD_FOURN' => '',
                    'RS_FOURN' => '',
                    'VILLE_FOURN' => '',
                    'REF_FOURN' => '',
                    'COD_FAB' => '',
                    'RS_FAB' => '',
                    'COD_GAM' => '',
                    'LIB_GAM' => '',
                    'REF_FAB' => '',
                    'COD_SFAM' => $row['SSFAM'],
                    'LIB_SFAM' => $row['DESIGN'],
                    'COD_FAM' => (array_key_exists('CODE_FAM', $row) ? $row['CODE_FAM'] : ''), // En rapport avec le dossier 14122
                    'DES_ART' => $row['DESIGN'],
                    'DES_COMP' => $row['DESIGNLG'],
                    'COD_UNIT' => $row['UNITE'],
                    'PX_ART' => '',
                    'DELAI' => '',
                    'CARACT' => '',
                    'IMGART' => '',
                    'TYPIMAGE' => '',
                    'COD_ACD' => '',
                    'CPOSTAL' => '',
                    'VILLE1' => '',
                    'TYPECATA' => '',
                    // DOSSIER 30642
                    'FICHTECH' => false,
                    'SERIALIZATION' => & $row['ROW_COMPTEUR'],
                    'DATABASEID' => '',
                    'ARTASSOCIE' => false,
                    'PRIXDEGRESSIF' => false,
                    'INFO_BULLE' => '',
                    'PER_REC_AUTO' => $row['PER_REC_AUTO'],
                    'RECEP_AUTO' => BoolSql($row['RECEP_AUTO']),
                    'NONRECEPT' => BoolSql($row['NONRECEPT'])
                );
            }
            
            return $result;
            
            if ($this->connect()) {
                // Selection des catalogues privés de l'utilisateur
                
                $where = "IDSTRUC = 'SSF' ";
                
                if ($texte != '' && $texte != '*')
                    $where .= ($where == '' ? '' : ' AND ') . " TEXT CONTAINS '" . ReplaceSqlPointeur($texte) . "' ";
                
                if ('' != $CODE_SFAM) {
                    $CODE_SFAM = ReplaceSqlPointeur($CODE_SFAM);
                    $where .= " and SSFAM ='$CODE_SFAM' ";
                }
                
                $requete = 'select query-expansion,' . '* ' . 'from ' . $_SESSION['INTUITION_HAP'] . ' ' . "where {$where} " . " AND LANGUAGE = '{$this->LANGAGE}' " . ($_SESSION['Session_Langue'] != '' && Param::isMultiLanguages() ? "and LANGUE = '{$_SESSION['Session_Langue']}' " : '') . "and globalrelevance > " . RechercheArticle::getTauxPertinence() . " order by globalrelevance desc " . "SKIP " . (($this->page_demande - 1) * $nligne) . " COUNT {$nligne}" . "  ";
                
                // recherche sur des metas
                $the_query = BaseSynequa::$the_session->in_query($requete);
                
                if ($the_query) {
                    $this->count_row = $the_query->in_num_rows();
                    while ($row = & $the_query->in_fetch_row()) {
                        $result[] = array(
                            'PROVENANCE' => 'ARTGEN',
                            'ID_CAT' => '',
                            'COD_ART' => '',
                            'COD_FOURN' => '',
                            'RS_FOURN' => '',
                            'VILLE_FOURN' => '',
                            'REF_FOURN' => '',
                            'COD_FAB' => '',
                            'RS_FAB' => '',
                            'COD_GAM' => '',
                            'LIB_GAM' => '',
                            'REF_FAB' => '',
                            'COD_SFAM' => & $row['ssfam'],
                            'LIB_SFAM' => Trad($row['ssfam'], 'sfam', $row['design']),
                            'COD_FAM' => (array_key_exists('code_fam', $row) ? $row['code_fam'] : ''), // En rapport avec le dossier 14122
                            'DES_ART' => & $row['design'],
                            'DES_COMP' => & $row['designlg'],
                            'COD_UNIT' => & $row['unite'],
                            'PX_ART' => '',
                            'DELAI' => '',
                            'CARACT' => '',
                            'IMGART' => '',
                            'TYPIMAGE' => '',
                            '' => '',
                            'CPOSTAL' => '',
                            'VILLE1' => '',
                            'SFAM_COMMENT' => $row['title'],
                            'FICHTECH' => false,
                            'SERIALIZATION' => & $row['serialization'],
                            'DATABASEID' => & $row['databaseid'], // Utilisation reference unique information
                            'ARTASSOCIE' => false,
                            'PRIXDEGRESSIF' => false,
                            'TYPECATA' => & $row['typecata'],
                            'RECEP_AUTO' => BoolSql($row['RECEP_AUTO']),
                            'PER_REC_AUTO' => BoolSql($row['PER_REC_AUTO'])
                        );
                    }
                }
                
                BaseSynequa::disconnect();
                
                return $result;
            }
        }
    }
}
