290 lines
8.5 KiB
PHP
290 lines
8.5 KiB
PHP
|
<?php
|
||
|
|
||
|
// affiche le contenu dans dossier à télécharger
|
||
|
|
||
|
function affich_dir($dirname)
|
||
|
{
|
||
|
|
||
|
$dir = scandir($dirname);
|
||
|
echo "<ul>";
|
||
|
foreach($dir as $file)
|
||
|
{
|
||
|
if($file != '.' && $file != '..' && !is_dir( $dirname . $file ) )
|
||
|
{
|
||
|
echo '<li><a href="' . $dirname . $file . '">' . $file . '</a></li>';
|
||
|
}
|
||
|
|
||
|
}
|
||
|
echo "</ul><br /><br />";
|
||
|
}
|
||
|
|
||
|
|
||
|
// vérifie que la césure de la chaine de caractère ne se fait pas au mileiu d'une balise html
|
||
|
// $n l nombre de caractères à garder
|
||
|
|
||
|
function verif_partiel( $string, $n)
|
||
|
{
|
||
|
$string = trim( stripslashes( $string ) );
|
||
|
$string = mb_substr( $string, 0, $n );
|
||
|
$pos = strrpos( $string, " " );
|
||
|
$string = substr( $string, 0, $pos );
|
||
|
$x = $z = 0;
|
||
|
$pos1 = $pos_d = 0;
|
||
|
$balises = array();
|
||
|
|
||
|
do
|
||
|
{
|
||
|
$z = $z + 1;
|
||
|
if ( $z >=50 )
|
||
|
{
|
||
|
log_error( "verif_partiel : erreur de boucle sans fin dans la ligne : $string<br />" . print_r( $balises ) . __file__ . " ligne " . __line__ );
|
||
|
}
|
||
|
|
||
|
$pos1 = strpos( $string, "<", $pos_d );
|
||
|
if ( $pos1 !== FALSE )
|
||
|
{
|
||
|
$pos2 = strpos( $string, ">", $pos1 );
|
||
|
$pos3 = strpos( $string, "<", $pos1+1 );
|
||
|
|
||
|
if ( $pos1 AND $pos2 === FALSE )
|
||
|
{
|
||
|
$string = substr( $string, 0, $pos1);
|
||
|
}else
|
||
|
{
|
||
|
if ( $pos3 !== FALSE AND $pos3 < $pos2 )
|
||
|
{
|
||
|
$pos1 = $pos3;
|
||
|
}
|
||
|
$pos_d = $pos2 + 1;
|
||
|
|
||
|
$balise_e = $titre = "panier";
|
||
|
$css = "main.css";substr( $string, $pos1, $pos2 - $pos1 + 1 );
|
||
|
$pos = strpos( $balise_e, " " );
|
||
|
|
||
|
if ( $pos !== FALSE )
|
||
|
{
|
||
|
$pos2 = $pos + $pos1;
|
||
|
}
|
||
|
$pos_slash = strpos( $balise_e, "/" );
|
||
|
if ( $pos_slash !== FALSE AND $pos_slash == 1 )
|
||
|
{
|
||
|
//echo "BALISE FERMANTE<br />";
|
||
|
$balise = trim( substr ( $balise_e, 2, ($pos2 - $pos1 - 2) ) );
|
||
|
if ( $balises[ $x-1 ] != $balise )
|
||
|
{
|
||
|
log_error( "verif_partiel : erreur de balise '$balise_e' dans la ligne : $string<br />" . print_r( $balises ) . __file__ . " ligne " . __line__ );
|
||
|
}else
|
||
|
{
|
||
|
$x = $x -1;
|
||
|
}
|
||
|
}elseif ( $pos_slash === FALSE )
|
||
|
{
|
||
|
//echo "BALISE OUVRANTE<br />";
|
||
|
$balises[ $x++ ] = trim( substr ( $balise_e, 1, ($pos2 - $pos1 -1) ) );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}while ( $pos1 !== FALSE );
|
||
|
$string .= " ...";
|
||
|
if ( $x >0 )
|
||
|
{
|
||
|
for ( $i = $x-1; $i >= 0; $i--)
|
||
|
{
|
||
|
$string .= "</" . $balises[ $i ] . ">";
|
||
|
}
|
||
|
}
|
||
|
//echo "string finale => $string<br />";
|
||
|
return $string;
|
||
|
}
|
||
|
|
||
|
// $var clef à rechercher dans $_POST, $_GET, et $_SESSION (si $session=true)
|
||
|
// $default valeur retournée si aucune valeur n'est trouvée
|
||
|
// $session: si true, rechercher aussi dans $_SESSION
|
||
|
|
||
|
//
|
||
|
|
||
|
function getpost( $var, $default="", $session=false )
|
||
|
{
|
||
|
//echo '$var =>' . $var . "<br />";
|
||
|
if ( isset($_GET[$var]) )
|
||
|
{
|
||
|
//echo '$_get -> $var =>' . $var . "<br />";
|
||
|
return $_GET[$var];
|
||
|
}
|
||
|
elseif ( isset($_POST[$var]) )
|
||
|
{
|
||
|
//echo '$_POST -> $var =>' . $var . "<br />";
|
||
|
return $_POST[$var];
|
||
|
}else
|
||
|
{
|
||
|
if ( isset($_SESSION[$var]) AND $session==true )
|
||
|
{
|
||
|
return $_SESSION[$var];
|
||
|
}else
|
||
|
{
|
||
|
//echo 'default -> $var =>' . $var . "<br />";
|
||
|
return $default;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// affiche les composants du menus
|
||
|
// pas de retour
|
||
|
|
||
|
function menu($page, $text)
|
||
|
{
|
||
|
echo '<a href="' . $page . '" class="menu"';
|
||
|
if ( $_SERVER['SCRIPT_NAME'] == $page ) echo ' style="color : red"';
|
||
|
echo '>' . $text . ' </a>';
|
||
|
}
|
||
|
|
||
|
function bouton_rouge( $text, $lien )
|
||
|
{
|
||
|
print '<div style="position:relative; height:400px">
|
||
|
<div style="position:absolute;z-index:1">
|
||
|
<img src="/images/bouton_rouge.png">
|
||
|
</div>
|
||
|
<div style="position:absolute;top:10px; z-index:2;">
|
||
|
<a href="' . $lien . '">
|
||
|
<center><b>' . $text .'</b></center></a>
|
||
|
</div>
|
||
|
</div>';
|
||
|
}
|
||
|
|
||
|
// MET LA PREMIÈRE LETTRE D'UN MOT EN MAJUSCULE ( utf8 compliant )
|
||
|
|
||
|
function mb_ucfirst($str) {
|
||
|
$char = mb_substr($str,0,1,"UTF8");
|
||
|
$str = mb_substr( $str, 1, NULL, "UTF8");
|
||
|
$char = mb_strtoupper( $char, "UTF8");
|
||
|
return $char . $str;
|
||
|
}
|
||
|
|
||
|
// affiche le panier en cours
|
||
|
// si $modif =,= true affiche une case de saisie avec la quantité
|
||
|
|
||
|
function affiche_panier( $modif=false )
|
||
|
{
|
||
|
global $base_url, $path, $page;
|
||
|
$total = 0;
|
||
|
$hc = 0;
|
||
|
//echo "============";print_r($_SESSION);echo "#################";
|
||
|
$nombre_ref = $_SESSION['panier_n_ref'];
|
||
|
$nombre_art = 0;
|
||
|
echo '<table class="panier_tab"><tr><th style="width : 3em; text-align : center;">n°</th><th style="width : 5em; text-align : center;">quantité</th><th align="center" style="width: 40%;">Produit</th><th style="width : 7em; text-align : center;">Durée</th><th style="width : 7em; text-align : center;">Type</th><th style="width : 8em;" align="center">Huile chaude<br />Supplément 5€</th><th style="width : 6em; text-align : center;">prix</th><th style="width : 8em; text-align : center;">total</th><th style="width : 8em; text-align : center;">valable jusqu\'au</th></tr>';
|
||
|
$art = $_SESSION["panier"];
|
||
|
for ($i = 0 ; $i < $nombre_ref ; $i++ )
|
||
|
{
|
||
|
$nombre_art += $art["qte"][$i];
|
||
|
$total += $total_col = $art["qte"][$i] * ( $art["prix"][$i] + ($art["huile_chaude"][$i]?5:0) );
|
||
|
echo '<tr><td style="padding : 5px; text-align : center;">' . ($i + 1) . '</td><td align="center">';
|
||
|
if ( $modif )
|
||
|
{
|
||
|
echo '<input style="color: brown;" type="text" name="qtes[' . $i . ']" value="' . $art["qte"][$i] . '" maxlength="3" size="2" onchange="document.getElementById( \'commande\' ).submit()" />';
|
||
|
}else
|
||
|
{
|
||
|
echo $art["qte"][$i];
|
||
|
}
|
||
|
echo '</td><td style="width: 40%;">' . $art["libelle"][$i] . '</td><td align="center">' . $art["duree"][$i] . '</td><td align="center">' . $art["type"][$i] . '</td>';
|
||
|
echo '<td align="center">';
|
||
|
if ($modif)
|
||
|
{
|
||
|
if ( $art["hc"][$i] )
|
||
|
{
|
||
|
echo '<input type="checkbox" name="huile_chaude[' . $i . ']" onchange="javascript:window.location.replace( \'' . $base_url . $path . $page . '?action=recalc&i=' . $i . '\');"';
|
||
|
if ( $art["huile_chaude"][$i] )
|
||
|
{
|
||
|
echo 'checked ';
|
||
|
}
|
||
|
echo '/>';
|
||
|
}else
|
||
|
{
|
||
|
echo 'non disponible';
|
||
|
}
|
||
|
}else
|
||
|
{
|
||
|
if ( $art["huile_chaude"][$i] )
|
||
|
{
|
||
|
echo 'oui';
|
||
|
$hc = 5;
|
||
|
}else
|
||
|
{
|
||
|
echo 'non';
|
||
|
$hc = 0;
|
||
|
}
|
||
|
}
|
||
|
echo '</td>';
|
||
|
$prix_article = $art["prix"][$i] + $hc;
|
||
|
echo '<td align="right">' . $prix_article . ' €</td><td align="right">' . $total_col . ' €</td><td align="right">' . $art["date_validite"][$i]->format("j/m/Y") . '</td></tr>';
|
||
|
}
|
||
|
echo '<tr><td colspan="4"></td><td colspan="3" align="center">total du panier</td><td align="right">' . "$total €</td><td></td></tr>";
|
||
|
echo '</table>';
|
||
|
|
||
|
echo "nombre de références : $nombre_ref<br />";
|
||
|
echo "nombre d'articles : $nombre_art";
|
||
|
|
||
|
}
|
||
|
|
||
|
function ajout_panier( $id )
|
||
|
{
|
||
|
//echo '<form method="post" action=""><input type="number" name="' . $id . '" min="0" max="999" value="1" />';
|
||
|
return '<img title="Ajouter au panier" src="./img/shop.png" width="24" height="24" alt="Ajouter au panier" onclick="javascript:open_panier_add(\'' . $id . '\');" />';
|
||
|
}
|
||
|
|
||
|
function affiche_commande( $id )
|
||
|
{
|
||
|
$total = 0;
|
||
|
$db = new db();
|
||
|
$db->open();
|
||
|
$query = "SELECT * FROM commandes_articles AS ca LEFT JOIN articles AS art ON ca.id_art=art.id LEFT join libelle_art AS la ON la.id=art.id_libelle WHERE ca.id_commande='" . $db->protect($id) . "'";
|
||
|
$db->query( $query );
|
||
|
echo '<tr style="font-weight: bold;"><td text-align : center;">Article</td>';
|
||
|
echo '<td text-align : center;">Quantité</td>';
|
||
|
echo "<td text-align : center;>huile_chaude</td>";
|
||
|
echo '<td text-align : center;">Prix</td>';
|
||
|
echo '<td text-align : center;">Type</td>';
|
||
|
echo '<td text-align : center;">Date de validité</td>';
|
||
|
echo '<td style="width : 3em; text-align : center;">Total article</td>';
|
||
|
echo '</tr>';
|
||
|
while ( $donnees = mysqli_fetch_array($db->result) )
|
||
|
{
|
||
|
|
||
|
echo '<tr><td text-align : center;">' . $donnees["libelle"] . '</td>';
|
||
|
echo '<td text-align : center;">' . $donnees["quantite"] . '</td>';
|
||
|
if ( $donnees["huile_chaude"] )
|
||
|
{
|
||
|
echo "<td text-align : center;>huile_chaude</td>";
|
||
|
}
|
||
|
echo '<td text-align : center;">' . $donnees["prix"] . '</td>';
|
||
|
echo '<td text-align : center;">' . $donnees["type"] . '</td>';
|
||
|
echo '<td text-align : center;">' . $donnees["date_validite"] . '</td>';
|
||
|
$total_article = $donnees["prix"] * $donnees["quantite"];
|
||
|
$total += $total_article;
|
||
|
echo '<td style="width : 3em; text-align : center;">' . $total_article . '</td>';
|
||
|
|
||
|
|
||
|
}
|
||
|
echo '<tr><th>Total de la commande</th><th style="width : 3em; text-align : center;">' . $total . '</th></tr>';
|
||
|
return $total;
|
||
|
$db->close();
|
||
|
}
|
||
|
|
||
|
function delete_cart()
|
||
|
{
|
||
|
$_SESSION['panier'] = array();
|
||
|
$_SESSION['panier_n_ref'] = 0;
|
||
|
if ( ! session_regenerate_id( true) )
|
||
|
{
|
||
|
log_error("impossible de régénérer l'ID de session");
|
||
|
}
|
||
|
print '<script type="text/javascript">
|
||
|
<!--
|
||
|
|
||
|
window.opener.document.getElementById("panier").style.visibility="hidden";
|
||
|
window.close();
|
||
|
-->
|
||
|
</script>';
|
||
|
}
|
||
|
?>
|