$T['hide_titre'] = true; // recette $T['recette']['recette'] = str_replace("\r", '', $T['recette']['recette']); // suppr des \r $T['recette']['recette'] = '<ul>' . $T['recette']['recette'] . '</li></ul>'; // wrapping $T['recette']['recette'] = preg_replace("#(\n)? ?\\* ?#is", '</li><li>', $T['recette']['recette']); // * -> <li> $T['recette']['recette'] = preg_replace_callback('#(\\n)?===(.+)===#isU', create_function('$matches', 'return "</li></ul><h3>".trim($matches[2])."</h3><ul>";'), $T['recette']['recette']); // === titre === => <h3>titre</h3> $T['recette']['recette'] = str_replace('<ul></li>', '<ul>', $T['recette']['recette']); // suppr </li> en trop $T['recette']['recette'] = str_replace('<ul></ul>', '', $T['recette']['recette']); // suppr <ul> vides $T['recette']['recette'] = nl2br($T['recette']['recette']); // nl2br // ingredients $T['ingredients'] = MySQL::query(' SELECT ' . DB_PREF . 'details.mesure, ' . DB_PREF . 'details.unite, ' . DB_PREF . 'ingredients.nom FROM ' . DB_PREF . 'details JOIN ' . DB_PREF . 'ingredients ON ' . DB_PREF . 'details.id_ingredient = ' . DB_PREF . 'ingredients.id WHERE id_recette = :1 ORDER BY nom ASC ', $id); $T['pers'] = 0; if (!empty($_GET['pers']) && ($T['pers'] = (int) $_GET['pers'])) { foreach ($T['ingredients'] as $k => $i) { convertir_personnes($T['ingredients'][$k]['mesure'], $T['recette']['personnes'], $T['pers']); } } }
// affichage du panier if (isset($_GET['panier'])) { $T['titre'] = 'Panier'; $T['panier'] = true; // on sélectionne la recette $T['recettes'] = sizeof($PANIER) != 0 ? MySQL::query('SELECT id, titre, note, duree, personnes FROM ' . DB_PREF . 'recettes WHERE id IN (' . implode_panier($PANIER) . ') ORDER BY id DESC') : array(); $ingredients = sizeof($PANIER) != 0 ? MySQL::query('SELECT mesure, unite, id_ingredient, id_recette FROM ' . DB_PREF . 'details WHERE id_recette IN (' . implode_panier($PANIER) . ') ORDER BY id_ingredient ASC') : array(); $ingredients_sum = array(); $recettes = array(); // nombre de personnes par recette foreach ($T['recettes'] as $r) { $recettes[$r['id']] = $r['personnes']; } // cumul des ingredients foreach ($ingredients as $i) { convertir_personnes($i['mesure'], $recettes[$i['id_recette']], $PANIER[$i['id_recette']]); convertir_mesure($i['mesure'], $i['unite']); if (!isset($ingredients_sum[$i['id_ingredient']][$i['unite']])) { $ingredients_sum[$i['id_ingredient']][$i['unite']] = 0; } $ingredients_sum[$i['id_ingredient']][$i['unite']] += $i['mesure']; } $T['all_ingredients'] = get_ingredients(); $T['ingredients'] = $ingredients_sum; } else { $recettes = MySQL::query('SELECT id, dir, parent, titre, note, duree, personnes FROM ' . DB_PREF . 'recettes ORDER BY titre ASC'); // LIMIT 0,5'); $childs = array(); $T['recettes'] = array(); foreach ($recettes as $r) { // si a parent, dans les enfants, sinon, a la racine