|
|
@ -4,35 +4,66 @@ |
|
|
# header("Location:.");
|
|
|
# header("Location:.");
|
|
|
# exit;
|
|
|
# exit;
|
|
|
# }
|
|
|
# }
|
|
|
function connect() |
|
|
|
|
|
{ |
|
|
|
|
|
try |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @brief connects to the database |
|
|
|
|
|
* @return a PDO connection to the database |
|
|
|
|
|
*/ |
|
|
|
|
|
function connect() |
|
|
|
|
|
{ |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
$pdo = new PDO("sqlite:testdb.db"); |
|
|
|
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
|
|
|
|
return $pdo; |
|
|
|
|
|
} |
|
|
|
|
|
catch(PDOException $e) |
|
|
|
|
|
{ |
|
|
|
|
|
//NOTE: change $e->getMessage() by an error message before going to production
|
|
|
|
|
|
echo($e->getMessage()); |
|
|
|
|
|
die(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @brief queries the database for the events on a certain date |
|
|
|
|
|
* @param $db: the PDO connection to the database |
|
|
|
|
|
* @param $date: the date to search for |
|
|
|
|
|
* @return a list of all the events at the date $date |
|
|
|
|
|
*/ |
|
|
|
|
|
function getEventsByDate($db, $date) |
|
|
|
|
|
{ |
|
|
|
|
|
try |
|
|
{ |
|
|
{ |
|
|
$pdo = new PDO("sqlite:testdb.db"); |
|
|
|
|
|
|
|
|
$request = $db->prepare('SELECT * FROM events, categorie WHERE events.categorie = categorie.id AND dtstart <= :date AND dtend >= :date'); |
|
|
|
|
|
$request->execute(array('date'=>$date)); |
|
|
|
|
|
$result = $request->fetchAll(); |
|
|
|
|
|
$request->closeCursor(); |
|
|
|
|
|
return $result; |
|
|
} |
|
|
} |
|
|
catch(Exception $e) |
|
|
|
|
|
|
|
|
catch(PDOException $e) |
|
|
{ |
|
|
{ |
|
|
echo("Impossible d'acceder à la base de donnée"); |
|
|
|
|
|
die(); |
|
|
|
|
|
|
|
|
//NOTE: change $e->getMessage() by an error message before going to production
|
|
|
|
|
|
echo($e->getMessage()); |
|
|
|
|
|
die(); |
|
|
} |
|
|
} |
|
|
return $pdo; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function getEvents() |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
function getEvents() |
|
|
|
|
|
{ |
|
|
$pdo = connect(); |
|
|
$pdo = connect(); |
|
|
$stmt = $pdo->prepare('SELECT titre, localisation, dtstart, dtend, description, url FROM events, categorie WHERE events.categorie = categorie.id'); |
|
|
$stmt = $pdo->prepare('SELECT titre, localisation, dtstart, dtend, description, url FROM events, categorie WHERE events.categorie = categorie.id'); |
|
|
$stmt->execute(); |
|
|
$stmt->execute(); |
|
|
$result = $stmt->fetchAll(); |
|
|
$result = $stmt->fetchAll(); |
|
|
return $result; |
|
|
return $result; |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function getEvent($id) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
function getEvent($id) |
|
|
|
|
|
{ |
|
|
$pdo = connect(); |
|
|
$pdo = connect(); |
|
|
$stmt = $pdo->prepare('SELECT titre, localisation, dtstart, dtend, description, url FROM events WHERE id = ?'); |
|
|
$stmt = $pdo->prepare('SELECT titre, localisation, dtstart, dtend, description, url FROM events WHERE id = ?'); |
|
|
$stmt->execute(array($id)); |
|
|
$stmt->execute(array($id)); |
|
|
$result = $stmt->fetch(); |
|
|
$result = $stmt->fetch(); |
|
|
return $result; |
|
|
return $result; |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
?>
|
|
|
?>
|