From 99b780ba034f88db98e01b53144ed3d4b8b4f606 Mon Sep 17 00:00:00 2001 From: adriy <> Date: Sun, 21 May 2017 14:59:04 +0200 Subject: [PATCH] first commit --- .gitignore | 1 + config.php.sample | 15 +++ index.php | 249 ++++++++++++++++++++++++++++++++++++++++++++++ post.php | 151 ++++++++++++++++++++++++++++ 4 files changed, 416 insertions(+) create mode 100644 .gitignore create mode 100644 config.php.sample create mode 100644 index.php create mode 100644 post.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f4773f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.php diff --git a/config.php.sample b/config.php.sample new file mode 100644 index 0000000..5cb0ab5 --- /dev/null +++ b/config.php.sample @@ -0,0 +1,15 @@ + 'localhost', + 'username' => 'root', + 'password' => 'root', + 'dbname' => 'root', + 'timestampDeadLine' => 1488229200, + 'IP_LOCAL' => '192.168.0.86', + 'recaptcha_private' => '', + 'recaptcha_public' => '', + 'main_pw' => '1223T', +); + +?> diff --git a/index.php b/index.php new file mode 100644 index 0000000..8988bee --- /dev/null +++ b/index.php @@ -0,0 +1,249 @@ +$timestampDeadLine)?1:0; + +if(isset($_SESSION['accesOk']) || $_SERVER['HTTP_HOST'] == $config['IP_LOCAL']) +{ + try + { + $bdd = new PDO('mysql:host='.$config['host'].';dbname='.$config['dbname'].';charset=utf8', $config['username'], $config['password']); + } + catch (Exception $e) + { + die('Erreur : ' . $e->getMessage()); + } + ?> + + + + + Titre de la page + + + + + + +
+
BETA

"; + echo "

".$_SESSION['nomPanier']; + if($_SESSION['deadLine']) + echo "(Dead Line passée)"; + echo "

"; + echo "Dead Line : ".date('d/m/y H:i', $timestampDeadLine)."

"; + ?> + + + + + query('SELECT * FROM panier WHERE idEtudiant='.$_SESSION['idEtudiant'].' AND panierId='.$_SESSION['panierId']); //vas chercher les produit de l'etudiant + while ($data = $rep->fetch()) + { + $rep2 = $bdd->query('SELECT * FROM article WHERE id='.$data['idArticle'].' AND panierId='.$_SESSION['panierId']); + $data2 = $rep2->fetch(); + if($data['nombre'] > 0) + { + ?> + + + + + + + + +
Ma commande ()
refDescriptionPrixQuantitéPrix totale
+ Sous total HTVA :
+ Sous total TTC (21%) :
+
+ + + + query('SELECT * FROM article WHERE panierId='.$_SESSION['panierId']); //va chercher tt les article + $ssTotal = 0; + while ($data = $rep->fetch()) + { + + $rep2 = $bdd->query('SELECT * FROM panier WHERE idArticle='.$data['id']); //chercher les elem du panier qui appartienne a l'article en cours + $nbr = 0; + $meNbr = 0; + $student = ""; + while($data2 = $rep2->fetch()) + { + + //if($data2['idEtudiant'] == $_SESSION['idEtudiant']) + //$meNbr = $data2['nombre']; + //$nbr = $nbr+$data2['nombre']; + if($data2['nombre']>0) + { + $rep3 = $bdd->query('SELECT * FROM etudiant WHERE id='.$data2['idEtudiant']); //Va voir le nom etudiant qui le commande + $data3 = $rep3->fetch(); + if($data3['enable']) + { + + if($data2['idEtudiant'] == $_SESSION['idEtudiant']) + $meNbr = $data2['nombre']; + $nbr = $nbr+$data2['nombre']; + + $student = $student."".$data3['pseudo']."(".$data2['nombre']."); "; + if(isset($sommeParEtudian[$data3['id']]['somme'])) + { + $sommeParEtudian[$data3['id']]['somme'] += $data['prix']*$data2['nombre']; + } + else + { + $sommeParEtudian[$data3['id']]['somme'] = $data['prix']*$data2['nombre']; + $sommeParEtudian[$data3['id']]['pseudo'] = $data3['pseudo']; + if($data3['id']>$idEtudianMax) + $idEtudianMax = $data3['id']; + } + } + else + { + + if(isset($sommeParEtudian[$data3['id']]['somme'])) + { + $sommeParEtudian[$data3['id']]['somme'] += $data['prix']*$data2['nombre']; + } + else + { + $sommeParEtudian[$data3['id']]['somme'] = $data['prix']*$data2['nombre']; + $sommeParEtudian[$data3['id']]['pseudo'] = $data3['pseudo'].'(NP)'; + if($data3['id']>$idEtudianMax) + $idEtudianMax = $data3['id']; + } + + + } + } + + }; + $ssTotal = $ssTotal + ($data['prix']*$nbr); + if($_SESSION['deadLine'] && $nbr > 0 || !$_SESSION['deadLine']) + { + ?> + + + + +
Commande de groupe
refDescriptionPrixQuantitéPrix totaleJ'en veuxEtudiant qui a commander
+ Sous total HTVA :
+ Sous total TTC (21%) :
+ +
+ + + + "; + } + } + ?> +
Récapitulatif de la commande par étudiant
PseudoPrix HTVAPrix TTC
".$sommeParEtudian[$i]['pseudo']."".$sommeParEtudian[$i]['somme']."".round($sommeParEtudian[$i]['somme']*1.21,2)."
+ +

BETA

"; + ?> + +
+ + +
Pseudo* :
Mot de passe (vous pouvez laisser vide)
+
+
+ + + + +urlencode($config['recaptcha_private']), 'response'=>urlencode($_POST['g-recaptcha-response'])); + $defaults = array( + CURLOPT_URL => 'https://www.google.com/recaptcha/api/siteverify', + CURLOPT_POST => true, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_POSTFIELDS => $params, + ); + curl_setopt_array($ch, $defaults); + $data = curl_exec($ch); + $result = json_decode($data, true); + if($result["success"] && $_POST['pw']== $config['main_pw']) + { + $_SESSION['accesOk'] = ""; + header("Refresh:0"); + } + else { + ?> + + + + + + + + + + +
+ + +
+ +
+ + + + + + + + + + + + + +
+ + +
+ +
+ + diff --git a/post.php b/post.php new file mode 100644 index 0000000..df471e5 --- /dev/null +++ b/post.php @@ -0,0 +1,151 @@ +getMessage()); +} +if(isset($_POST['quant']) && isset($_POST['ref']) && isset($_POST['description']) && isset($_POST['prix']) && !$deadLine) +{ + $req = $bdd->prepare('SELECT * FROM article WHERE ref=:ref'); + $data = $req->execute(array( + 'ref' => $_POST['ref'] + )); + $id; + $data = $req->fetch(); + if(isset($data['ref'])) + { + $req = $bdd->prepare('UPDATE panier SET nombre=:nbr WHERE id=:id'); + $req->execute(array( + 'nbr' => $_POST['quant'], + 'id' => $data['id'] + )); + } + else + { + $req = $bdd->prepare('INSERT INTO article(ref, description, prix, panierId) VALUES(:ref, :description, :prix, :panierId)'); + $req->execute(array( + 'ref' => $_POST["ref"], + 'description' => $_POST['description'], + 'prix' => $_POST['prix'], + 'panierId' => $_SESSION['panierId'] + )); + + $id = $bdd->lastInsertId(); + $req = $bdd->prepare('INSERT INTO panier(idEtudiant, idArticle, nombre, panierId) VALUES(:idEtudiant, :idAdrticle, :nombre, :panierId)'); + $req->execute(array( + 'idEtudiant' => $_SESSION["idEtudiant"], + 'idAdrticle' => $id, + 'nombre' => $_POST['quant'], + 'panierId' => $_SESSION['panierId'] + )); + } + +} +else if(isset($_POST['user']) && isset($_POST['pw'])) +{ + $req = $bdd->prepare('SELECT * FROM etudiant WHERE lower(pseudo)=:pseudo'); + $data = $req->execute(array( + 'pseudo' => strtolower($_POST['user']) + )); + $data = $req->fetch(); + if($data) + { + if($data['pw'] == (empty($_POST['pw'])?'':md5($_POST['pw']))) + { + $_SESSION['idEtudiant'] = $data['id']; + $_SESSION['pseudo'] = $data['pseudo']; + $_SESSION['admin'] = $data['admin']; + $_SESSION['panierId'] = 1; + $_SESSION['nomPanier'] = "farnell projet 1"; + echo json_encode(array('loggin'=> '1')); + } + else + { + echo json_encode(array('loggin'=> '2')); + } + } + else + { + $req = $bdd->prepare('INSERT INTO etudiant(pseudo,pw) VALUE(:pseudo,:pw)'); + $req->execute(array( + 'pseudo' => htmlspecialchars($_POST['user']), + 'pw' => empty($_POST['pw'])?'':md5($_POST['pw']) + )); + $id = $bdd->lastInsertId(); + $_SESSION['idEtudiant'] = $id; + $_SESSION['admin'] = 0; + $_SESSION['pseudo'] = $_POST['user']; + $_SESSION['admin'] = 0; + $_SESSION['panierId'] = 1; + $_SESSION['nomPanier'] = "farnell projet 1"; + echo json_encode(array('loggin'=> '3')); + } +} +else if(isset($_POST['quant']) && !$deadLine){ + if(isset($_POST['idarticle'])) //Pour ma commande j'envois un id + { + $req = $bdd->prepare('SELECT * FROM panier WHERE id=:id'); + $rep = $req->execute(array( + 'id' => $_POST['idarticle'] + )); + $data = $req->fetch(); + if(isset($data['idEtudiant']) && $data['idEtudiant'] == $_SESSION['idEtudiant'])//C'est bien le bonne etudiant + { + $req = $bdd->prepare('UPDATE panier SET nombre=:nbr WHERE id=:id'); + $req->execute(array( + 'nbr' => $_POST['quant'], + 'id' => $_POST['idarticle'] + )); + } + else { + echo json_encode("err"); + } + } + else if(isset($_POST['refId']))//quand je passe par la commande globale je passe par la identifiant de la ref + { + $req = $bdd->prepare('SELECT * FROM panier WHERE idArticle=:refId AND idEtudiant=:idEtudiant');//Tchek si l'etudiant a déja l'article + $rep = $req->execute(array( + 'refId' => $_POST['refId'], + 'idEtudiant' => $_SESSION['idEtudiant'] + )); + $data = $req->fetch(); + if($data) + { + $req = $bdd->prepare('UPDATE panier SET nombre=:nbr WHERE id=:id'); + $req->execute(array( + 'nbr' => $_POST['quant'], + 'id' => $data['id'] + )); + } + else { + $req = $bdd->prepare('INSERT INTO panier(idEtudiant, idArticle, nombre, panierId) VALUES(:idEtudiant, :idAdrticle, :nombre, :panierId)'); + $req->execute(array( + 'idEtudiant' => $_SESSION["idEtudiant"], + 'idAdrticle' => $_POST['refId'], + 'nombre' => $_POST['quant'], + 'panierId' => $_SESSION['panierId'] + )); + } + } +} +else if(isset($_POST['quant']) && $deadLine) +{ + http_response_code(401); + echo "N'est plus autorisé ! DeadLine Dépaséé !"; +} +else { + session_destroy(); + session_start(); + $_SESSION['accesOk'] = ""; +} +?>