From ce34e9d7460dd7e62ea071c55822cbcbbb732246 Mon Sep 17 00:00:00 2001 From: rtschu Date: Sun, 16 Jan 2022 19:34:10 +0100 Subject: [PATCH 1/3] implemented cookie consent --- classes/cookie_consent_allocation.php | 37 +++++++++++ db/install.xml | 21 +++++++ db/upgrade.php | 40 ++++++++++++ lang/de/theme_wwu2019.php | 37 ++++++++++- lang/en/theme_wwu2019.php | 35 +++++++++++ lib.php | 63 +++++++++++++++++++ scss/wwu2019/general.scss | 89 +++++++++++++++++++++++++++ templates/collapsible_topic.mustache | 24 ++++++++ templates/cookie_consent.mustache | 50 +++++++++++++++ version.php | 2 +- 10 files changed, 396 insertions(+), 2 deletions(-) create mode 100644 classes/cookie_consent_allocation.php create mode 100644 db/install.xml create mode 100644 db/upgrade.php create mode 100644 templates/collapsible_topic.mustache create mode 100644 templates/cookie_consent.mustache diff --git a/classes/cookie_consent_allocation.php b/classes/cookie_consent_allocation.php new file mode 100644 index 0000000..cc054e0 --- /dev/null +++ b/classes/cookie_consent_allocation.php @@ -0,0 +1,37 @@ +. + +namespace theme_wwu2019; + +use core\persistent; + +class cookie_consent_allocation extends persistent { + + const TABLE = "theme_wwu2019_cookie_consent"; + + protected static function define_properties() { + return array( + 'userid' => array( + 'type' => PARAM_INT, + 'message' => new \lang_string('invaliduserid', 'error') + ), + 'consentdate' => array( + 'type' => PARAM_INT, + 'message' => new \lang_string('invalidconsentdate', 'theme_wwu2019') + ) + ); + } +} diff --git a/db/install.xml b/db/install.xml new file mode 100644 index 0000000..1f4c3db --- /dev/null +++ b/db/install.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + +
+
+
\ No newline at end of file diff --git a/db/upgrade.php b/db/upgrade.php new file mode 100644 index 0000000..d932c16 --- /dev/null +++ b/db/upgrade.php @@ -0,0 +1,40 @@ +. + +function xmldb_theme_wwu2019_upgrade ($oldversion) { + global $DB; + $dbman = $DB->get_manager(); + if ($oldversion < 2022010100) { + + $table = new xmldb_table('theme_wwu2019_cookie_consent'); + + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + $table->add_field('consentdate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id')); + + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + upgrade_plugin_savepoint(true, 2022010100, 'theme', 'wwu2019'); + } +} \ No newline at end of file diff --git a/lang/de/theme_wwu2019.php b/lang/de/theme_wwu2019.php index 998a881..a0c7ce0 100644 --- a/lang/de/theme_wwu2019.php +++ b/lang/de/theme_wwu2019.php @@ -90,9 +90,44 @@ $string['viewfullsection'] = 'Kompletten Abschnitt anschauen'; -// Theme switcher +// Theme switcher. $string['choosetheme'] = 'Theme auswählen'; $string['light'] = 'Hell'; $string['dark'] = 'Dunkel'; $string['ostheme'] = 'Systemfarben'; $string['ostheme_help'] = 'Wechselt zwischen hellem und dunklem Theme basierend auf den Systemeinstellungen.'; + +// Cookie consent. +$string['cookie_consent_title'] = "Zustimmung zur Verwendung von Cookies"; +$string['cookie_consent_title_one'] = "Diese Website verwendet Cookies"; +$string['cookie_consent_body_one'] = "Das Learnweb braucht Cookies um zu funktionieren." . + " Da wir kein Interesse am Verkauf deiner Daten haben setzen wir nur solche Cookies ein, die zum Betrieb der Website notwendig sind."; +$string['cookie_explanation_title'] = "Was sind Cookies?"; +$string['cookie_explanation_body'] = "Cookies sind kleine Textdateien die das Learnweb auf Ihrem PC speichert." + . " In dieser Textdatei wird dann ein Wert und ein Ablaufdatum gespeichert." + . " Der Name dieser Textdatei, sowie ihr Inhalt werden dann immer an das Learnweb gesendet wenn Sie es besuchen." + . " Wenn das gespeicherte Ablaufdatum erreicht ist wird der Cookie automatisch von ihrem PC gelöscht."; +$string['cookie_classes_title'] = "Was für Arten von Cookies gibt es?"; +$string['cookie_classes_body'] = "Grundsätzlich unterscheidet man vier Arten von Cookies:" . + "
"; + +$string['cookie_reason_title'] = "Wofür benutzt das Learnweb Cookies?"; +$string['cookie_reason_body'] = "Das Learnweb setzt Cookies für verschiedene Zwecke ein. Wenn Sie sich Beispielsweise einloggen " + . "speichert das Learnweb einen Cookie der einen Zugangscode für Sie enthält. Wenn sie dann eine andere Seite des Learnwebs aufrufen " + . "kann das Learnweb sie anhand dieses Codes identifizieren und Sie müssen sich nicht erneut einloggen.
" + . "Ein anderer Anwendungsbereich sind einige Texteditoren des Learnwebs. Wenn sie einen Text schreiben so speichert ihr PC diesen Text " + . "während des Schreibens immer wieder in einem Cookie. Somit ist sichergestellt, dass sie auch bei Verbindungsabbruch oder zwischenzeitlichem " + . "Verlassen des Learnwebs keinen Verlust ihres Textes befürchten müssen."; +$string['agree'] = "Zustimmung erteilen"; + +$string['invalidconsentdate'] = "Ungültiges Datum für Zustimmungserteilung"; diff --git a/lang/en/theme_wwu2019.php b/lang/en/theme_wwu2019.php index 0c0767a..40466b8 100644 --- a/lang/en/theme_wwu2019.php +++ b/lang/en/theme_wwu2019.php @@ -97,3 +97,38 @@ $string['ostheme'] = 'System colors'; $string['ostheme_help'] = 'Switches between light and dark theme depending on the OS settings.'; +// Cookie consent. +$string['cookie_consent_title'] = "Zustimmung zur Verwendung von Cookies"; +$string['cookie_consent_title_one'] = "Diese Website verwendet Cookies"; +$string['cookie_consent_body_one'] = "Das Learnweb braucht Cookies um zu funktionieren." . + " Da wir kein Interesse am Verkauf deiner Daten haben setzen wir nur solche Cookies ein, die zum Betrieb der Website notwendig sind."; +$string['cookie_explanation_title'] = "Was sind Cookies?"; +$string['cookie_explanation_body'] = "Cookies sind kleine Textdateien die das Learnweb auf Ihrem PC speichert." + . " In dieser Textdatei wird dann ein Wert und ein Ablaufdatum gespeichert." + . " Der Name dieser Textdatei, sowie ihr Inhalt werden dann immer an das Learnweb gesendet wenn Sie es besuchen." + . " Wenn das gespeicherte Ablaufdatum erreicht ist wird der Cookie automatisch von ihrem PC gelöscht."; +$string['cookie_classes_title'] = "Was für Arten von Cookies gibt es?"; +$string['cookie_classes_body'] = "Grundsätzlich unterscheidet man vier Arten von Cookies:" . + "
"; + +$string['cookie_reason_title'] = "Wofür benutzt das Learnweb Cookies?"; +$string['cookie_reason_body'] = "Das Learnweb setzt Cookies für verschiedene Zwecke ein. Wenn Sie sich Beispielsweise einloggen " + . "speichert das Learnweb einen Cookie der einen Zugangscode für Sie enthält. Wenn sie dann eine andere Seite des Learnwebs aufrufen " + . "kann das Learnweb sie anhand dieses Codes identifizieren und Sie müssen sich nicht erneut einloggen.
" + . "Ein anderer Anwendungsbereich sind einige Texteditoren des Learnwebs. Wenn sie einen Text schreiben so speichert ihr PC diesen Text " + . "während des Schreibens immer wieder in einem Cookie. Somit ist sichergestellt, dass sie auch bei Verbindungsabbruch oder zwischenzeitlichem " + . "Verlassen des Learnwebs keinen Verlust ihres Textes befürchten müssen."; + +$string['agree'] = "Zustimmung erteilen"; + +$string['invalidconsentdate'] = "Invalid date for consentdate"; diff --git a/lib.php b/lib.php index 2f83e91..c4342ad 100644 --- a/lib.php +++ b/lib.php @@ -92,3 +92,66 @@ function theme_wwu2019_extend_navigation_course($navigation, $course, $context) $navigation->add_node($node); } + +const CONSENT_COOKIE = "cookie_policy_consent"; +function theme_wwu2019_before_standard_top_of_body_html() { + global $USER, $OUTPUT; + if (isloggedin()) { + if (isset($_COOKIE[CONSENT_COOKIE])) { + $consentdataraw = $_COOKIE[CONSENT_COOKIE]; + $consentdata = json_decode($consentdataraw, true); + $userid = $USER->id; + $useridhash = md5($userid); + foreach ($consentdata as $consenteduser => $consentdate) { + if ($consenteduser == $useridhash) { + $consentexpirydate = strtotime("+1 year", $consentdate); + if ($consentexpirydate > time()) { + return null; + } + } + } + } + + $consentpersistent = \theme_wwu2019\cookie_consent_allocation::get_record(["userid" => $USER->id]); + if ($consentpersistent) { + $consentdate = $consentpersistent->get('consentdate'); + $consentexpirydate = strtotime("+1 year", $consentdate); + if ($consentexpirydate > time()) { + add_consent_cooke($consentpersistent); + } + return null; + } + + $consentgiven = optional_param('theme_wwu2019_cookie_consent_given', false, PARAM_BOOL); + if ($consentgiven) { + $data = new stdClass(); + $data->userid = $USER->id; + $data->consentdate = time(); + $consentpersistent = new \theme_wwu2019\cookie_consent_allocation(0, $data); + $consentpersistent->create(); + add_consent_cooke($consentpersistent); + return null; + } + + $consentdialog = $OUTPUT->render_from_template("theme_wwu2019/cookie_consent", []); + + return $consentdialog; + } + return null; +} + +function add_consent_cooke($consentpersistent) { + global $CFG; + if (isset($_COOKIE[CONSENT_COOKIE])) { + $consentdata = json_decode($_COOKIE[CONSENT_COOKIE], true); + } else { + $consentdata = []; + } + + $consentdate = $consentpersistent->get('consentdate'); + $hashedid = md5($consentpersistent->get('userid')); + $consentdata[$hashedid] = $consentdate; + $encodeddata = json_encode($consentdata); + $consentexpirydate = strtotime("+1 year", $consentdate); + setcookie(CONSENT_COOKIE, $encodeddata, $consentexpirydate, $CFG->sessioncookiepath); +} diff --git a/scss/wwu2019/general.scss b/scss/wwu2019/general.scss index 96d3bb9..c4cf906 100644 --- a/scss/wwu2019/general.scss +++ b/scss/wwu2019/general.scss @@ -374,4 +374,93 @@ a:not([class]):focus, margin-top: 1em; margin-bottom: 1em; } +} + +#theme_wwu2019_cookie_consent_overlay { + position: fixed; + width: 100%; + height: 100%; + background-color: rgba(0,0,0,0.5); + z-index: 2000; // to be above nav +} + +#theme_wwu2019_cookie_consent_dialog_header { + background-color: $primary; +} + +.theme_wwu2019_cookie_consent_body { + text-align: left; + color: black; +} + +.vertical-center { + margin: 0 auto; +} + +.theme_wwu2019_bold_text { + font-weight: bold; + color: white; + margin: 0; +} + +.dialog_center { + width: 40%; + display: inline-table; + height: auto; + margin: 10% auto auto; + position: absolute; + top: 0; + bottom: 0; + right: 0; + left: 0; + border-top-left-radius: calc(0.3rem - 1px); + border-top-right-radius: calc(0.3rem - 1px); +} + +.theme_wwu2019_cookie_consent_form { + margin-top: 10px; + margin-bottom: 10px; +} + +.dialog_overlay { + z-index: 2001; + background-color: white; +} +.theme_wwu2019_switch_wrapper { + text-align: left; + padding-top: 5px; + border-bottom: 1px solid lightgrey; + border-top: 1px solid lightgrey; + background: white; +} + +.theme_wwu2019_switch_label { + background-image: url([[pix:theme_wwu2019|arrow_up]]); + height: 1em; + background-size: contain; + background-repeat: no-repeat; + margin: 0 0 0 5px; + padding-left: calc(1em + 5px); + color: $primary; + font-weight: bold; +} + +:checked ~ .theme_wwu2019_switch_label { + background-image: url([[pix:theme_wwu2019|arrow_down]]); +} + +.theme_wwu2019_switched_text { + display: none; +} + +:checked ~ .theme_wwu2019_switched_text { + display: block; +} + +.theme_wwu2019_switch_input { + display: none; +} + +.text-bold { + font-weight: bold; } \ No newline at end of file diff --git a/templates/collapsible_topic.mustache b/templates/collapsible_topic.mustache new file mode 100644 index 0000000..adb837c --- /dev/null +++ b/templates/collapsible_topic.mustache @@ -0,0 +1,24 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template theme_wwu2019/collapsible_topic +}} +
+ + +
{{$text}}{{/text}}
+
\ No newline at end of file diff --git a/templates/cookie_consent.mustache b/templates/cookie_consent.mustache new file mode 100644 index 0000000..59565a1 --- /dev/null +++ b/templates/cookie_consent.mustache @@ -0,0 +1,50 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template theme_wwu2019/cookie_consent +}} + + +