Example #1
0
function arbreBoucle($depart, $profondeur = 0, $i = 0)
{
    $rec = "";
    $i++;
    if ($i == $profondeur && $profondeur != 0) {
        return;
    }
    $trubrique = new Rubrique();
    $query = "select * from {$trubrique->table} where parent=\"{$depart}\"";
    $resul = CacheBase::getCache()->query($query);
    if ($resul == "" || count($resul) == 0) {
        return "";
    }
    foreach ($resul as $row) {
        $rec .= $row->id . ",";
        $rec .= arbreBoucle($row->id, $profondeur, $i);
    }
    return $rec;
}
Example #2
0
function boucleProduit($texte, $args, $type = 0)
{
    global $page, $totbloc, $ref, $id_rubrique;
    // récupération des arguments
    $rubrique = lireTag($args, "rubrique", "int_list");
    $rubcourante = lireTag($args, "rubcourante", "int");
    $deb = lireTag($args, "deb", "int");
    $num = lireTag($args, "num", "int");
    $passage = lireTag($args, "passage", "int");
    $ligne = lireTag($args, "ligne", "int");
    $bloc = lireTag($args, "bloc", "int+-");
    $nouveaute = lireTag($args, "nouveaute", "int");
    $promo = lireTag($args, "promo", "int");
    $reappro = lireTag($args, "reappro", "int");
    $refp = lireTag($args, "ref", "string");
    $id = lireTag($args, "id", "int_list");
    $garantie = lireTag($args, "garantie", "int");
    $motcle = lireTag($args, "motcle", "string+\\s\\'");
    $classement = lireTag($args, "classement", "string");
    $aleatoire = lireTag($args, "aleatoire", "int");
    $prixmin = lireTag($args, "prixmin", "float");
    $prixmax = lireTag($args, "prixmax", "float");
    $caracteristique = lireTag($args, "caracteristique", "int+-");
    $caracdisp = lireTag($args, "caracdisp", "int+-\\*");
    $caracval = lireTag($args, "caracval", "string+\\s\\'\\/\\*");
    $typech = lireTag($args, "typech", "string");
    $declinaison = lireTag($args, "declinaison", "int+-");
    $declidisp = lireTag($args, "declidisp", "int+-");
    $declistockmini = lireTag($args, "declistockmini", "int");
    $stockmini = lireTag($args, "stockmini", "int");
    $courant = lireTag($args, "courant", "int");
    $profondeur = lireTag($args, "profondeur", "int");
    $exclusion = lireTag($args, "exclusion", "int_list");
    $exclurub = lireTag($args, "exclurub", "int_list");
    $poids = lireTag($args, "poids", "float");
    $stockvide = lireTag($args, "stockvide", "int");
    $forcepage = lireTag($args, "forcepage", "int");
    if ($bloc) {
        $totbloc = $bloc;
    }
    if (!$deb) {
        $deb = 0;
    }
    if ($page) {
        $_SESSION['navig']->page = $page;
    }
    if (!$page || $page == 1) {
        $page = 0;
    }
    if (!$totbloc) {
        $totbloc = 1;
    }
    if ($page) {
        $deb = ($page - 1) * $totbloc * $num + $deb;
    }
    if ($forcepage != "") {
        if ($forcepage == 1) {
            $forcepage = 0;
            $deb = 0;
        }
        if ($forcepage) {
            $deb = ($forcepage - 1) * $totbloc * $num + $deb;
        }
    }
    $produit = new Produit();
    // initialisation de variables
    $search = "";
    $order = "";
    $comptbloc = 0;
    $limit = "";
    $pourcentage = "";
    $res = "";
    $virg = "";
    if ($rubcourante == "1" && $rubrique != $id_rubrique) {
        return "";
    }
    // preparation de la requete
    if ($courant == "1") {
        $search .= " and ref=\"{$ref}\"";
    } else {
        if ($courant == "0") {
            $search .= " and ref<>\"{$ref}\"";
        }
    }
    if ($exclusion != "") {
        $search .= " and {$produit->table}.id not in({$exclusion})";
    }
    if ($exclurub != "") {
        $search .= " and rubrique not in({$exclurub})";
    }
    if ($rubrique != "") {
        $srub = "";
        if ($profondeur == "") {
            $profondeur = 0;
        }
        $tabrub = explode(",", $rubrique);
        for ($compt = 0; $compt < count($tabrub); $compt++) {
            $rec = arbreBoucle($tabrub[$compt], $profondeur);
            $rec = rtrim($rec, ",");
            if ($rec) {
                $virg = ",";
            }
            $srub .= $tabrub[$compt] . $virg . $rec . ',';
        }
        $srub = rtrim($srub, ",");
        $search .= " and rubrique in({$srub})";
    }
    if ($ligne == "") {
        $ligne = "1";
    }
    if ($ligne != "-1") {
        $search .= " and ligne=\"{$ligne}\"";
    }
    if ($id != "") {
        $search .= " and {$produit->table}.id in ({$id})";
    }
    if ($nouveaute != "") {
        $search .= " and nouveaute=\"{$nouveaute}\"";
    }
    if ($promo != "") {
        $search .= " and promo=\"{$promo}\"";
    }
    if ($reappro != "") {
        $search .= " and reappro=\"{$reappro}\"";
    }
    if ($garantie != "") {
        $search .= " and garantie=\"{$garantie}\"";
    }
    if ($prixmin != "") {
        $search .= " and ((prix2>=\"{$prixmin}\" and promo=\"1\") or (prix>=\"{$prixmin}\" and promo=\"0\"))";
    }
    if ($prixmax != "") {
        $search .= " and ((prix2<=\"{$prixmax}\" and promo=\"1\") or (prix<=\"{$prixmax}\" and promo=\"0\"))";
    }
    if ($poids != "") {
        $search .= " and poids<=\"{$poids}\"";
    }
    if ($stockmini != "" && $declistockmini == "") {
        $search .= " and stock>=\"{$stockmini}\"";
    }
    if ("" != $stockvide) {
        if (0 < $stockvide) {
            $search .= " and stock<=\"0\"";
        } elseif (0 >= $stockvide) {
            $search .= " and stock>\"0\"";
        }
    }
    if ($refp != "") {
        $search .= " and ref=\"{$refp}\"";
    }
    if ($bloc == "-1") {
        $bloc = "999999999";
    }
    if ($bloc != "" && $num != "") {
        $limit .= " limit {$deb},{$bloc}";
    } else {
        if ($num != "") {
            $limit .= " limit {$deb},{$num}";
        }
    }
    if ($aleatoire) {
        $order = "order by " . " RAND()";
    } else {
        $listeClassement = explode(',', $classement);
        $choixClassement = array();
        for ($i = 0; $i < count($listeClassement); $i++) {
            if ($listeClassement[$i] == "prixmin") {
                $choixClassement[] = "IF(promo, prix2, prix) ASC";
            } else {
                if ($listeClassement[$i] == "prixmax") {
                    $choixClassement[] = "IF(promo, prix2, prix) DESC";
                } else {
                    if ($listeClassement[$i] == "rubrique") {
                        $choixClassement[] = "rubrique";
                    } else {
                        if ($listeClassement[$i] == "manuel") {
                            $choixClassement[] = "classement";
                        } else {
                            if ($listeClassement[$i] == "inverse") {
                                $choixClassement[] = "classement desc";
                            } else {
                                if ($listeClassement[$i] == "date") {
                                    $choixClassement[] = "datemodif desc";
                                } else {
                                    if ($listeClassement[$i] == "titre") {
                                        $choixClassement[] = "titre";
                                    } else {
                                        if ($listeClassement[$i] == "titreinverse") {
                                            $choixClassement[] = "titre desc";
                                        } else {
                                            if ($listeClassement[$i] == "ref") {
                                                $choixClassement[] = "ref";
                                            } else {
                                                if ($listeClassement[$i] == "promo") {
                                                    $choixClassement[] = "promo desc";
                                                } else {
                                                    if ($listeClassement[$i] == "poids") {
                                                        $choixClassement[] = "poids";
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if (empty($choixClassement)) {
            $order = "order by classement";
        } else {
            $order = "order by " . implode(',', $choixClassement);
        }
    }
    /* Demande de caracteristiques */
    if ($caracdisp != "") {
        if (substr($caracteristique, -1) != "-") {
            $caracteristique .= "-";
        }
        if (substr($caracdisp, -1) != "-") {
            $caracdisp .= "-";
        }
        $lcaracteristique = explode("-", $caracteristique);
        $lcaracdisp = explode("-", $caracdisp);
        $i = 0;
        $tcaracval = new Caracval();
        while ($i < count($lcaracteristique) - 1) {
            $caracteristique = $lcaracteristique[$i];
            $caracdisp = $lcaracdisp[$i];
            if ($caracdisp == "*") {
                $query = "select * from {$tcaracval->table} where caracteristique='{$caracteristique}' and caracdisp<>''";
            } else {
                $query = "select * from {$tcaracval->table} where caracteristique='{$caracteristique}' and caracdisp='{$caracdisp}'";
            }
            $liste = "";
            $resul = CacheBase::getCache()->query($query);
            if (empty($resul)) {
                return;
            }
            foreach ($resul as $row) {
                $liste .= "'{$row->produit}',";
            }
            $liste = rtrim($liste, ",");
            $i++;
            if ($liste != "") {
                $search .= " and {$produit->table}.id in({$liste})";
            } else {
                return "";
            }
        }
    }
    if ($caracval != "") {
        $i = 0;
        $liste = "";
        $tcaracval = new Caracval();
        if ($caracval == "*") {
            $query = "select * from {$tcaracval->table} where caracteristique='{$caracteristique}' and valeur<>''";
        } else {
            if ($caracval == "-") {
                $query = "select * from {$tcaracval->table} where caracteristique='{$caracteristique}' and valeur=''";
            } else {
                if ($typech == "like") {
                    $query = "select * from {$tcaracval->table} where caracteristique='{$caracteristique}' and valeur like '{$caracval}'";
                } else {
                    $query = "select * from {$tcaracval->table} where caracteristique='{$caracteristique}' and valeur ='{$caracval}'";
                }
            }
        }
        $liste = "";
        $resul = CacheBase::getCache()->query($query);
        if ($resul == "" || count($resul) == 0) {
            return "";
        }
        foreach ($resul as $row) {
            $liste .= "'{$row->produit}',";
        }
        $liste = rtrim($liste, ",");
        $i++;
        if ($liste != "") {
            $search .= " and {$produit->table}.id in({$liste})";
        } else {
            return "";
        }
    }
    /* Demande de declinaisons */
    if ($declidisp != "") {
        if (!strstr($declinaison, "-")) {
            $declinaison .= "-";
        }
        if (!strstr($declidisp, "-")) {
            $declidisp .= "-";
        }
        if (!strstr($declistockmini, "-")) {
            $declistockmini .= "-";
        }
        $ldeclinaison = explode("-", $declinaison);
        $ldeclidisp = explode("-", $declidisp);
        $ldeclistockmini = explode("-", $declistockmini);
        $i = 0;
        $liste = "";
        $exdecprod = new Exdecprod();
        $stock = new Stock();
        while ($i < count($ldeclinaison) - 1) {
            $declinaison = $ldeclinaison[$i];
            $declidisp = $ldeclidisp[$i];
            $declistockmini = $ldeclistockmini[$i];
            $query = "select * from {$exdecprod->table} where declidisp='{$declidisp}'";
            $resul = CacheBase::getCache()->query($query);
            if (count($resul) > 0) {
                foreach ($resul as $row) {
                    $liste .= "'{$row->produit}',";
                }
            }
            if ($liste != "") {
                $liste = rtrim($liste, ",");
                $search .= " and {$produit->table}.id not in({$liste})";
            }
            $liste = "";
            if ($declistockmini != "") {
                $query = "select * from {$stock->table} where declidisp='{$declidisp}' and valeur>='{$declistockmini}'";
                $resul = CacheBase::getCache()->query($query);
                if (count($resul) > 0) {
                    foreach ($resul as $row) {
                        $liste .= "'{$row->produit}',";
                    }
                }
                if ($liste != "") {
                    $liste = rtrim($liste, ",");
                    $search .= " and {$produit->table}.id in({$liste})";
                } else {
                    return "";
                }
            }
            $i++;
        }
    }
    $produit = new Produit();
    $produitdesc = new Produitdesc();
    if ($motcle) {
        $motcle = $produit->escape_string(strip_tags(trim($motcle)));
        $liste = "";
        $query = "\n\t\t\t\tSELECT pd.produit FROM\n\t\t\t\t\t{$produitdesc->table} pd\n\t\t\t\tLEFT JOIN\n\t\t\t\t\t{$produit->table} p ON p.id=pd.produit\n\t\t\t\tWHERE\n                    pd.lang = " . ActionsLang::instance()->get_id_langue_courante() . "\n                AND\n\t\t\t\t\tp.ref='{$motcle}'\n\t\t\t\tOR (\n\t\t\t\t\tmatch(pd.titre, pd.chapo, pd.description, pd.postscriptum) AGAINST ('{$motcle}' IN BOOLEAN MODE)\n\t\t\t\tOR\n\t\t\t\t\tpd.titre REGEXP '[[:<:]]{$motcle}[[:>:]]'\n\t\t\t\tOR\n\t\t\t\t  \tpd.chapo REGEXP '[[:<:]]{$motcle}[[:>:]]'\n\t\t\t\tOR\n\t\t\t\t \tpd.description REGEXP '[[:<:]]{$motcle}[[:>:]]'\n\t\t\t\tOR\n\t\t\t\t \tpd.postscriptum REGEXP '[[:<:]]{$motcle}[[:>:]]'\n    \t\t\t)\n\t\t\t";
        $resul = CacheBase::getCache()->query($query);
        if (empty($resul)) {
            return "";
        }
        foreach ($resul as $row) {
            $liste .= "'{$row->produit}',";
        }
        $liste = rtrim($liste, ',');
        $search .= "and {$produit->table}.id in ({$liste})";
    }
    if ($classement != "titre" && $classement != "titreinverse") {
        $query = "select * from {$produit->table} where 1 {$search} {$order}";
    } else {
        if (ActionsLang::instance()->get_action_si_trad_absente() == ActionsLang::UTILISER_LANGUE_INDIQUEE) {
            // On retourne uniquement les produit traduites
            $search .= " and {$produitdesc->table}.id is not null";
        }
        $query = "\n\t\t\t\tselect {$produit->table}.* from {$produit->table}\n\t\t\t\tleft join {$produitdesc->table} on {$produitdesc->table}.produit = {$produit->table}.id and lang=" . ActionsLang::instance()->get_id_langue_courante() . "\n\t\t\t\twhere  1 {$search} {$order}\n\t\t\t";
    }
    $nbres = count(CacheBase::getCache()->query($query));
    $query .= " {$limit}";
    $resul = CacheBase::getCache()->query($query);
    if (empty($resul)) {
        return "";
    }
    // substitutions
    if ($type) {
        return $query;
    }
    $count_query = "\n\t\t\tselect\n\t\t\t\tcount({$produit->table}.id) as totcount\n\t\t\tfrom\n\t\t\t\t{$produit->table}\n\t\t\tleft join\n\t\t\t\t{$produitdesc->table} on {$produitdesc->table}.produit = {$produit->table}.id and {$produitdesc->table}.lang=" . ActionsLang::instance()->get_id_langue_courante() . "\n\t\t\twhere\n\t\t\t\t1 {$search}\n\t\t";
    $countres = CacheBase::getCache()->query($count_query);
    $nbproduits = $countres ? $countres[0]->totcount : 0;
    $compt = 0;
    foreach ($resul as $row) {
        $compt++;
        if ($passage != "" && $comptbloc > $passage - 1) {
            break;
        }
        if ($num > 0) {
            if ($comptbloc >= ceil($nbproduits / $num) && $bloc != "") {
                continue;
            }
        }
        if ($comptbloc == 0) {
            $debcourant = 0;
        } else {
            $debcourant = $num * $comptbloc;
        }
        $comptbloc++;
        $prodid = $row->id;
        $rubriquedesc = new Rubriquedesc();
        $rubriquedesc->charger($row->rubrique);
        $produitdesc = new Produitdesc();
        $produitdesc->charger($prodid);
        $temp = $texte;
        if ($row->promo == "1") {
            $temp = preg_replace("/\\#PROMO\\[([^]]*)\\]\\[([^]]*)\\]/", "\\1", $temp);
        } else {
            $temp = preg_replace("/\\#PROMO\\[([^]]*)\\]\\[([^]]*)\\]/", "\\2", $temp);
        }
        if ($row->nouveaute == "1") {
            $temp = preg_replace("/\\#NOUVEAU\\[([^]]*)\\]\\[([^]]*)\\]/", "\\1", $temp);
        } else {
            $temp = preg_replace("/\\#NOUVEAU\\[([^]]*)\\]\\[([^]]*)\\]/", "\\2", $temp);
        }
        if ($row->promo == '1' && $row->prix) {
            $pourcentage = round(100 * ($row->prix - $row->prix2) / $row->prix, 0);
        } else {
            $pourcentage = null;
        }
        $prixorig = $row->prix;
        $prix2orig = $row->prix2;
        $prix = $row->prix - $row->prix * $_SESSION['navig']->client->pourcentage / 100;
        $prix2 = $row->prix2 - $row->prix2 * $_SESSION['navig']->client->pourcentage / 100;
        $ecotaxe = $row->ecotaxe;
        $pays = new Pays();
        $pays->charger($_SESSION['navig']->client->pays);
        $zone = new Zone();
        $zone->charger($pays->zone);
        $prixht = $prix / (1 + $row->tva / 100);
        $prix2ht = $prix2 / (1 + $row->tva / 100);
        $prixoright = $prixorig / (1 + $row->tva / 100);
        $prix2oright = $prix2orig / (1 + $row->tva / 100);
        $ecotaxeht = $row->ecotaxe / (1 + $row->tva / 100);
        $prix = formatter_somme($prix);
        $prix2 = formatter_somme($prix2);
        $prixht = formatter_somme($prixht);
        $prix2ht = formatter_somme($prix2ht);
        $prixorig = formatter_somme($prixorig);
        $prix2orig = formatter_somme($prix2orig);
        $prixoright = formatter_somme($prixoright);
        $prix2oright = formatter_somme($prix2oright);
        if ($deb != "" && !$page) {
            $debcourant += $deb - 1;
        }
        $temp = str_replace("#NBRES_TOTAL", $nbres, $temp);
        $temp = str_replace("#NBRES", $nbproduits, $temp);
        $temp = str_replace("#REF", "{$row->ref}", $temp);
        $temp = str_replace("#COMPT", "{$compt}", $temp);
        $temp = str_replace("#DATE", substr($row->datemodif, 0, 10), $temp);
        $temp = str_replace("#HEURE", substr($row->datemodif, 11), $temp);
        $temp = str_replace("#DEBCOURANT", "{$debcourant}", $temp);
        $temp = str_replace("#ID", "{$prodid}", $temp);
        $temp = str_replace("#PRIX2ORIGHT", "{$prix2oright}", $temp);
        $temp = str_replace("#PRIX2ORIG", "{$prix2orig}", $temp);
        $temp = str_replace("#PRIXORIGHT", "{$prixoright}", $temp);
        $temp = str_replace("#PRIXORIG", "{$prixorig}", $temp);
        $temp = str_replace("#PRIX2HT", "{$prix2ht}", $temp);
        $temp = str_replace("#PRIX2", "{$prix2}", $temp);
        $temp = str_replace("#PRIXHT", "{$prixht}", $temp);
        $temp = str_replace("#PRIX", "{$prix}", $temp);
        $temp = str_replace("#PROMO", "{$row->promo}", $temp);
        $temp = str_replace("#TVA", "{$row->tva}", $temp);
        $temp = str_replace("#ECOTAXEHT", "{$ecotaxeht}", $temp);
        $temp = str_replace("#ECOTAXE", "{$row->ecotaxe}", $temp);
        $temp = str_replace("#STOCK", "{$row->stock}", $temp);
        $temp = str_replace("#POURCENTAGE", "{$pourcentage}", $temp);
        $temp = str_replace("#RUBRIQUE", "{$row->rubrique}", $temp);
        $temp = str_replace("#PERSO", "{$row->perso}", $temp);
        $temp = str_replace("#POIDS", "{$row->poids}", $temp);
        $temp = str_replace("#TITRE", "{$produitdesc->titre}", $temp);
        $temp = str_replace("#STRIPTITRE", strip_tags($produitdesc->titre), $temp);
        $temp = str_replace("#CHAPO", "{$produitdesc->chapo}", $temp);
        $temp = str_replace("#STRIPCHAPO", strip_tags($produitdesc->chapo), $temp);
        $temp = str_replace("#DESCRIPTION", str_replace("../", "", $produitdesc->description), $temp);
        $temp = str_replace("#POSTSCRIPTUM", "{$produitdesc->postscriptum}", $temp);
        $temp = str_replace("#STRIPDESCRIPTION", strip_tags($produitdesc->description), $temp);
        $temp = str_replace("#URL", $produitdesc->getUrl(), $temp);
        $temp = str_replace("#REWRITEURL", $produitdesc->getUrl(), $temp);
        $temp = str_replace("#GARANTIE", "{$row->garantie}", $temp);
        $temp = str_replace("#PANIERAPPEND", urlfond("panier", "action=" . "ajouter&amp;ref=" . "{$row->ref}" . "&amp;" . "append=1", true), $temp);
        $temp = str_replace("#PANIER", urlfond("panier", "action=" . "ajouter" . "&amp;" . "ref=" . "{$row->ref}", true), $temp);
        $temp = str_replace("#RUBTITRE", "{$rubriquedesc->titre}", $temp);
        $res .= $temp;
    }
    return $res;
}