From 3b58137679b28b9e6e7bed0c9a521c33131ed5a6 Mon Sep 17 00:00:00 2001 From: AmarOk Date: Thu, 10 Mar 2016 11:54:21 +0100 Subject: [PATCH] edit event --- databaseOperations.php | 37 +++++++++++++++++++++++++++++++++++++ editEvent.php | 4 +++- eventAdded.php | 3 +++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/databaseOperations.php b/databaseOperations.php index d662fbc..5a59a70 100755 --- a/databaseOperations.php +++ b/databaseOperations.php @@ -310,4 +310,41 @@ function addEvent($db, $titre, $catArray, $localisation, $dtstart, $dtend, $desc die(); } } + +function updateEvent($db, $id, $titre, $catArray, $localisation, $dtstart, $dtend, $description, $url, $urlImage, $contact) +{ + try + { + $db->beginTransaction(); + $request = $db->prepare('UPDATE event SET event_tile=:title, event_localisation=:localisation, event_dtstart=:dstart, event_dtend=:dtend, event_description=:description, event_url=:url, event_urlImage=:urlImage, event_contact=:contact WHERE event_id=:id'); + $request->execute(array('title'=>$titre, + 'localisation'=>$localisation, + 'dtend'=>date("Y-m-d H:i:s",$dtstart), + 'dstart'=>date("Y-m-d H:i:s",$dtend), + 'description'=>$description, + 'url'=>$url, + 'urlImage'=>$urlImage, + 'contact'=>$contact, + 'id'=>$id)); + $request->closeCursor(); + $request = $db->prepare('DELETE FROM eventCategorie WHERE event_id=:id'); + $request->execute(array('id'=>$id)); + $request->closeCursor(); + $newEventId = $db->lastInsertId(); + $request = $db->prepare('INSERT INTO eventCategorie(event_id, cat_id) VALUES(:eventId, :catId)'); + foreach($catArray as $cat) + { + $request->execute(array('eventId'=>$newEventId, + 'catId'=>$cat)); + } + $db->commit(); + } + catch(PDOException $e) + { + $db->rollBack(); + //NOTE: change $e->getMessage() by an error message before going to production + echo($e->getMessage()); + die(); + } +} ?> diff --git a/editEvent.php b/editEvent.php index d9a8c91..f8257f9 100644 --- a/editEvent.php +++ b/editEvent.php @@ -40,6 +40,7 @@ $event = getOneEvent($db, $id);

Modifier un Évènement

+
Titre :
" required>
@@ -87,7 +88,8 @@ $event = getOneEvent($db, $id);
Contact :
" name="contact">
-
+
+
diff --git a/eventAdded.php b/eventAdded.php index a7026c6..ac6e3d7 100644 --- a/eventAdded.php +++ b/eventAdded.php @@ -11,7 +11,10 @@ $url = $_POST['site']; $urlImage = $_POST['urlImage']; $contact = $_POST['contact']; $catArray = $_POST['chk_group']; +if(!isset($_POST['id']) addEvent($db, $titre, $catArray, $localisation, $dtstart, $dtend, $description, $url, $urlImage, $contact); +else +updateEvent($db, $id, $titre, $catArray, $localisation, $dtstart, $dtend, $description, $url, $urlImage, $contact); header('Location:./'); exit; ?>