Browse Source

Merge remote-tracking branch 'origin/master'

master
n0m1s 10 years ago
parent
commit
e51b2f610f
3 changed files with 66 additions and 1 deletions
  1. +60
    -0
      databaseOperations.php
  2. +3
    -1
      editEvent.php
  3. +3
    -0
      eventAdded.php

+ 60
- 0
databaseOperations.php View File

@ -310,4 +310,64 @@ 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();
}
}
function deleteEvent($db, $id)
{
try
{
$db->beginTransaction();
$request = $db->prepare('DELETE FROM event WHERE event_id=:id');
$request->execute(array('id'=>$id));
$request->closeCursor();
$request = $db->prepare('DELETE FROM eventCategorie WHERE event_id=:id');
$request->execute(array('id'=>$id));
$request->closeCursor();
$db->commit();
}
catch(PDOException $e)
{
$db->rollBack();
//NOTE: change $e->getMessage() by an error message before going to production
echo($e->getMessage());
die();
}
}
?>

+ 3
- 1
editEvent.php View File

@ -40,6 +40,7 @@ $event = getOneEvent($db, $id);
<h1>Modifier un Évènement</h1>
<form id="eventForm" name="eventForm" method="post" action="eventAdded.php" onsubmit="return verifyCheckbox();">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<div id="left">Titre :</div>
<input type="text" name="title" value="<?php echo $event["event_title"]; ?>" required>
<br>
@ -87,7 +88,8 @@ $event = getOneEvent($db, $id);
<div id="left">Contact :</div>
<input type="text" value="<?php echo $event["event_contact"];?>" name="contact">
<br>
<div id="buttonDiv"><button id="submit">Modifier l'évènement !</button></div>
<div id="buttonDiv"><button id="submit">Modifier l'évènement !</button>
<button id="submit" action="alert('TODO');">Supprimer l'évènement !</button></div>
</form>


+ 3
- 0
eventAdded.php View File

@ -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;
?>

Loading…
Cancel
Save