From 8c7e121d9461e66ee236431f44075bd812398f13 Mon Sep 17 00:00:00 2001 From: TheMrNomis Date: Thu, 10 Dec 2015 10:23:10 +0100 Subject: [PATCH 1/8] small bugfix --- event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/event.php b/event.php index d8a0c00..bb07a57 100755 --- a/event.php +++ b/event.php @@ -29,7 +29,7 @@
-

+

Date et lieu

From c0024459d87f31121ec0b526241fa505c4867c4e Mon Sep 17 00:00:00 2001 From: TheMrNomis Date: Thu, 10 Dec 2015 10:49:29 +0100 Subject: [PATCH 2/8] moved day and months arrays to a separate file --- datetimeOperations.php | 36 ++++++++++++++++++++++++++++++++++++ index.php | 25 +------------------------ 2 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 datetimeOperations.php diff --git a/datetimeOperations.php b/datetimeOperations.php new file mode 100644 index 0000000..685eb22 --- /dev/null +++ b/datetimeOperations.php @@ -0,0 +1,36 @@ + htmlentities("Lun"), + 2 => htmlentities("Mar"), + 3 => htmlentities("Mer"), + 4 => htmlentities("Jeu"), + 5 => htmlentities("Ven"), + 6 => htmlentities("Sam"), + 7 => htmlentities("Dim") +); + +$daysFull = array( + 1 => htmlentities("Lundi"), + 2 => htmlentities("Mardi"), + 3 => htmlentities("Mercredi"), + 4 => htmlentities("Jeudi"), + 5 => htmlentities("Vendredi"), + 6 => htmlentities("Samedi"), + 7 => htmlentities("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") +); +?> diff --git a/index.php b/index.php index d2ae3dc..f70ac60 100644 --- a/index.php +++ b/index.php @@ -1,32 +1,9 @@ "Lun", - 2 => "Mar", - 3 => "Mer", - 4 => "Jeu", - 5 => "Ven", - 6 => "Sam", - 7 => "Dim" -); -$months = array( - 1 => "Janvier", - 2 => "Fevrier", - 3 => "Mars", - 4 => "Avril", - 5 => "Mai", - 6 => "Juin", - 7 => "Juillet", - 8 => "Août", - 9 => "Septembre", - 10 => "Octobre", - 11 => "Novembre", - 12 => "Decembre" -); - if(isset($_GET['w'])&&is_numeric($_GET['w'])) $weekOffset = $_GET['w']; else From eca65dc007984d8773a3d4c5eb934d1fbe2a6ce7 Mon Sep 17 00:00:00 2001 From: TheMrNomis Date: Thu, 10 Dec 2015 11:17:12 +0100 Subject: [PATCH 3/8] pretty formatted datetime string for event --- datetimeOperations.php | 126 ++++++++++++++++++++++++++++++++--------- event.php | 98 +++++++++++++++----------------- 2 files changed, 146 insertions(+), 78 deletions(-) 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']); ?> - - KiWi calendar : <?php echo $event["event_title"]; ?> - - - - - - - -
- logo ESIR - -
-
-

-

Date et lieu

-
- format('Y-m-d') == $dtend->format('Y-m-d')) - echo strftime('Le %d %B %Y, ', strtotime($event['event_dtstart'])).strftime('de %Hh%M ', strtotime($event['event_dtstart'])).strftime('à %Hh%M', strtotime($event['event_dtend'])); - else - echo strftime('Du %d %B %Y, %Hh%M', strtotime($event['event_dtstart'])).strftime(' à %d %B %Y, %Hh%M',strtotime($event['event_dtend'])); - ?>
- + + + KiWi calendar : <?php echo $event["event_titre"]; ?> + + + + + + + + +
+ logo ESIR + +
+
+

+ +

Date et lieu

+
+ +
+ '.$event["event_localisation"].'
'; $url = 'https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($event["event_localisation"]).'&key=AIzaSyB8Cd8NP8VOa0wIlvvYGEMZMzCKwROiHxU'; $obj = json_decode(file_get_contents($url), true); @@ -54,23 +48,23 @@ src="'.$urlFrame.'" style="width:100%;height:500px;margin-bottom:-30px;">'; if(isset($event["event_urlImage"]) || isset($event["event_description"])) - echo '

Description

'; + echo '

Description

'; if(isset($event["event_urlImage"])) - echo '
'; + echo '
'; if(isset($event["event_description"])) - echo '
'.$event["event_description"].'
'; + echo '
'.$event["event_description"].'
'; if(isset($event["event_site"]) || isset($event["event_contact"])) - echo '

Informations

'; + echo '

Informations

'; if(isset($event["event_site"])) - echo ''; + echo ''; if(isset($event["event_contact"])) - echo ''; - ?> -
+ echo ''; + ?> +
- - + + - + From 72d1ad9231243c87241f7f8172422a4ac7ed69eb Mon Sep 17 00:00:00 2001 From: TheMrNomis Date: Thu, 10 Dec 2015 11:23:38 +0100 Subject: [PATCH 4/8] merging new database schema (event_title instead of event_titre) --- day.php | 2 +- event.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/day.php b/day.php index e5bf648..42866c4 100644 --- a/day.php +++ b/day.php @@ -28,7 +28,7 @@ $date = strtotime(htmlspecialchars($_GET['date'])); foreach ($ret as $row) { echo "
\n"; - echo "

".$row['event_titre']."

\n"; + echo "

".$row['event_title']."

\n"; echo "
".date('H:i',strtotime($row['event_dtstart']))." - ".date('H:i',strtotime($row['event_dtend'])).". ".$row['event_localisation']."
\n"; echo "
".$row['event_description'] ."
\n\n
\n"; } diff --git a/event.php b/event.php index 75d3d5e..f761b73 100755 --- a/event.php +++ b/event.php @@ -16,7 +16,7 @@ $dtend = strtotime($event['event_dtend']); - KiWi calendar : <?php echo $event["event_titre"]; ?> + KiWi calendar : <?php echo $event["event_title"]; ?> @@ -30,7 +30,7 @@ $dtend = strtotime($event['event_dtend']);
-

+

Date et lieu

From 5bc360c2fb79bf36aae3466e5848d696c388f536 Mon Sep 17 00:00:00 2001 From: TheMrNomis Date: Thu, 10 Dec 2015 11:24:11 +0100 Subject: [PATCH 5/8] small script to generate a test database --- makedatabase.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 makedatabase.sh diff --git a/makedatabase.sh b/makedatabase.sh new file mode 100755 index 0000000..f2f8acd --- /dev/null +++ b/makedatabase.sh @@ -0,0 +1,3 @@ +rm testdb.db +cat makedatabase.sql | sqlite3 testdb.db +cat populateDatabase.sql | sqlite3 testdb.db From a9544ccb4724660723cf02ef46be0f432e5bbbe8 Mon Sep 17 00:00:00 2001 From: TheMrNomis Date: Thu, 10 Dec 2015 11:29:35 +0100 Subject: [PATCH 6/8] removed debug var dump --- event.php | 1 - 1 file changed, 1 deletion(-) diff --git a/event.php b/event.php index f761b73..523c3d8 100755 --- a/event.php +++ b/event.php @@ -24,7 +24,6 @@ $dtend = strtotime($event['event_dtend']); -
logo ESIR From 6409b56604b676d3283b42a43b4f7d1849827046 Mon Sep 17 00:00:00 2001 From: TheMrNomis Date: Thu, 10 Dec 2015 11:34:40 +0100 Subject: [PATCH 7/8] updated TODO list --- TODO.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/TODO.md b/TODO.md index 786a399..642c60e 100644 --- a/TODO.md +++ b/TODO.md @@ -9,8 +9,6 @@ ## Index Page + Add event -+ BUG: Show the first day -+ Connect to day page + ENT + Sync with others calendars From 6f63b78e3d56d80c54b248e25e47805ccf9b0cba Mon Sep 17 00:00:00 2001 From: TheMrNomis Date: Thu, 10 Dec 2015 11:38:58 +0100 Subject: [PATCH 8/8] updated TODO list --- TODO.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TODO.md b/TODO.md index 642c60e..0f41648 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,8 @@ # TODO List +## global ++ use categories + ## Event Page + Clean code