Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function connection()
- {
- $user = "root";
- $pass = "ArtemisLL";
- try
- {
- $bdd = new PDO('mysql:host=localhost;dbname=poulgoazec', $user, $pass, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
- }
- catch(Exception $e)
- {
- echo $e->getMessage();
- }
- return $bdd;
- }
- if(isset($_POST['action']) && !empty($_POST['action'])) {
- $action = $_POST['action'];
- switch($action) {
- case 'loadOffer' : loadOffer();break;
- case 'postOffer' : postOffer();break;
- }
- }
- function loadBasket() {
- try{
- $db = connection();
- $q = $db->query("SELECT l.id,l.DatePeche,l.dateEnchere,e.nomEspece,t.specification,q.libelle,b.tare,l.prixEnchere FROM lot l,espece e,taille t,qualite q,bac b WHERE e.id = l.Espece AND t.id = l.taille AND q.id = l.qualite AND b.id = l.Bac AND l.Acheteur = ".$_SESSION["id"]." ORDER BY l.dateEnchere");
- } catch (PDOException $e) {
- echo $e->getMessage();
- }
- }
- function loadOffer() {
- $db = connection();
- $result = $db->query("SELECT L.id AS id_LOT, L.datePeche, L.Bateau, GREATEST(IFNULL(Pmax.enchereMax, 0), L.prixDepart) AS prixMax
- FROM lot AS L
- LEFT JOIN (SELECT P.Lot, P.datePeche, P.Bateau, MAX(P.prixEnchere) AS enchereMax
- FROM poster AS P
- GROUP BY P.Lot, P.DatePeche, P.Bateau) AS Pmax
- ON L.id=Pmax.Lot AND L.datePeche=Pmax.datePeche AND L.Bateau=Pmax.Bateau
- WHERE dateEnchere=CURDATE()");
- $result->setFetchMode(PDO::FETCH_ASSOC);
- echo json_encode($result->fetchAll());
- }
- function postOffer() {
- $db = connection();
- if (!(empty($_POST['id_LOT']) || empty($_POST['datePeche']) || empty($_POST['Bateau']) || empty($_POST['enchere']))) {
- $q = $db->prepare('SELECT MAX(P.prixEnchere) AS prixMax FROM poster AS P WHERE P.Lot=:id_LOT AND P.datePeche=:datePeche AND P.Bateau=:id_BATEAU');
- $q->execute(array(
- ':id_LOT' => $_POST['id_LOT'],
- ':datePeche' => $_POST['datePeche'],
- ':id_BATEAU' => $_POST['Bateau']
- ));
- $r = $q->fetch();
- if ($r['prixMax'] < $_POST['enchere']) {
- $query = $db->prepare('INSERT INTO poster (prixEnchere, heureEnchere, Acheteur, Lot, datePeche, Bateau)'
- . ' VALUES (:enchere, NOW(), :id_UTILISATEUR, :id_LOT, :datePeche, :id_BATEAU)');
- $query->execute(array(
- 'enchere' => $_POST['enchere'],
- 'id_UTILISATEUR' => $_SESSION['id'],
- 'id_LOT' => $_POST['id_LOT'],
- 'datePeche' => $_POST['datePeche'],
- 'id_BATEAU' => $_POST['Bateau']
- ));
- echo '1';
- } else {
- echo '2';
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement