diff --git a/datetimeOperations.php b/datetimeOperations.php index 685eb22..dc31e0f 100644 --- a/datetimeOperations.php +++ b/datetimeOperations.php @@ -1,36 +1,110 @@ htmlentities("Lun"), - 2 => htmlentities("Mar"), - 3 => htmlentities("Mer"), - 4 => htmlentities("Jeu"), - 5 => htmlentities("Ven"), - 6 => htmlentities("Sam"), - 7 => htmlentities("Dim") + 1 => "Lun", + 2 => "Mar", + 3 => "Mer", + 4 => "Jeu", + 5 => "Ven", + 6 => "Sam", + 7 => "Dim" ); $daysFull = array( - 1 => htmlentities("Lundi"), - 2 => htmlentities("Mardi"), - 3 => htmlentities("Mercredi"), - 4 => htmlentities("Jeudi"), - 5 => htmlentities("Vendredi"), - 6 => htmlentities("Samedi"), - 7 => htmlentities("Dimamche") + 1 => "Lundi", + 2 => "Mardi", + 3 => "Mercredi", + 4 => "Jeudi", + 5 => "Vendredi", + 6 => "Samedi", + 7 => "Dimamche" ); $months = array( - 1 => htmlentities("Janvier"), - 2 => htmlentities("Fevrier"), - 3 => htmlentities("Mars"), - 4 => htmlentities("Avril"), - 5 => htmlentities("Mai"), - 6 => htmlentities("Juin"), - 7 => htmlentities("Juillet"), - 8 => htmlentities("Août"), - 9 => htmlentities("Septembre"), - 10 => htmlentities("Octobre"), - 11 => htmlentities("Novembre"), - 12 => htmlentities("Décembre") + 1 => "Janvier", + 2 => "Fevrier", + 3 => "Mars", + 4 => "Avril", + 5 => "Mai", + 6 => "Juin", + 7 => "Juillet", + 8 => "Août", + 9 => "Septembre", + 10 => "Octobre", + 11 => "Novembre", + 12 => "Décembre" ); + +/** + * @brief gets a pretty formatted hour string + * + * @param $datetime: the strtotime() representation of the time to show + * + * @return a string containing the time (pretty printed) + */ +function printableHour($datetime) +{ + $hour = date('G', $datetime); + $minutes = date('I', $datetime); + + $ret = $hour.'h'; + if($minutes != '00') + $ret .= $minutes; + + return $ret; +} + +/** + * @brief gets a pretty formatted date and time interval + * + * @param $dtstart: the start datetime of the time interval + * @param $dtend: the end datetime of the time interval + * + * @return a string containing the french representation of the interval + */ +function printableDateTime($dtstart, $dtend) +{ + if(date('Y-m-d', $dtstart) == date('Y-m-d', $dtend)) + return 'Le '.date('Y-m-d', $dtstart).', de '.printableHour($dtstart).' à '.printableHour($dtend); + else + { + $stringDateTime = 'Du '; + if(date('Y', $dtstart) != date('Y', $dtend)) + $stringDateTime .= printableDate($dtstart, true, true); + else if(date('n', $dtstart) != date('n', $dtend)) + $stringDateTime .= printableDate($dtstart, true); + else + $stringDateTime .= printableDate($dtstart); + + $stringDateTime .= ' à '.printableHour($dtstart).' au '.printableDate($dtend, true, true).' à '.printableHour($dtend); + + return $stringDateTime; + } +} + +/** + * @brief gets a pretty formatted date + * + * @param $datetime: the datetime to print + * @param $useMonth: should the function print the month? + * @param $useYear: should the function print the year? + * + * @return a string containing the well-formatted date + */ +function printableDate($datetime, $useMonth = false, $useYear = false) +{ + global $days, $daysFull, $months; + + $year = date('Y', $datetime); + $month = $months[date('n', $datetime)]; + $day = date('j', $datetime); + $dayInWeek = strtolower($daysFull[date('N', $datetime)]); + + $ret = $dayInWeek.' '.$day; + if($useMonth) + $ret .= ' '.$month; + if($useYear) + $ret .= ' '.$year; + + return $ret; +} ?> diff --git a/event.php b/event.php index bb07a57..75d3d5e 100755 --- a/event.php +++ b/event.php @@ -1,48 +1,42 @@ - - open('testdb.db'); - } - } +include_once('databaseOperations.php'); +include('datetimeOperations.php'); +$db = connect(); + +if(!isset($_GET['id']) || !is_numeric($_GET['id'])) + header('Location:./'); + +$id = htmlspecialchars($_GET['id']); - $db = new MyDB(); - if(!$db) echo $db->lastErrorMsg(); - $id = $_GET["id"]; - $ret = $db->query('SELECT * FROM event WHERE event_id="'. $id .'"'); - $event = $ret->fetchArray(SQLITE3_ASSOC); +$event = getOneEvent($db, $id); +$dtstart = strtotime($event['event_dtstart']); +$dtend = strtotime($event['event_dtend']); ?> -
-
-
-
+
+