Browse Source

Adds cookie warning message see #7478

A configuration option is required in configuration.php:

chamilo_use_cookie_warning_validation
baelmyhu 10 years ago
parent
commit
5e8ae687fd

+ 16 - 0
index.php

@@ -149,6 +149,22 @@ if (!api_is_anonymous()) {
 $hot_courses = null;
 $announcements_block = null;
 
+
+// Display the Site Use Cookie Warning Validation
+$useCookieValidation = api_get_configuration_value('chamilo_use_cookie_warning_validation');
+if ($useCookieValidation) {
+    if (isset($_POST['acceptCookies'])) {
+        api_set_site_use_cookie_warning_cookie();
+    } else if (!api_site_use_cookie_warning_cookie_exist()) {
+        if (Template::isToolBarDisplayedForUser()) {
+            $controller->tpl->assign('toolBarDisplayed', true);
+        } else {
+            $controller->tpl->assign('toolBarDisplayed', false);
+        }
+        $controller->tpl->assign('displayCookieUsageWarning', true);
+    }
+}
+
 // When loading a chamilo page do not include the hot courses and news
 
 if (!isset($_REQUEST['include'])) {

+ 16 - 0
main/admin/index.php

@@ -338,6 +338,22 @@ if (api_is_platform_admin()) {
 $admin_ajax_url = api_get_path(WEB_AJAX_PATH).'admin.ajax.php';
 
 $tpl = new Template();
+
+// Display the Site Use Cookie Warning Validation
+$useCookieValidation = api_get_configuration_value('chamilo_use_cookie_warning_validation');
+if ($useCookieValidation) {
+    if (isset($_POST['acceptCookies'])) {
+        api_set_site_use_cookie_warning_cookie();
+    } else if (!api_site_use_cookie_warning_cookie_exist()) {
+        if (Template::isToolBarDisplayedForUser()) {
+            $tpl->assign('toolBarDisplayed', true);
+        } else {
+            $tpl->assign('toolBarDisplayed', false);
+        }
+        $tpl->assign('displayCookieUsageWarning', true);
+    }
+}
+
 $tpl->assign('web_admin_ajax_url', $admin_ajax_url);
 $tpl->assign('blocks', $blocks);
 // The template contains the call to the AJAX version checker

+ 13 - 0
main/css/base.css

@@ -5291,3 +5291,16 @@ i.size-32.icon-new-work{
     margin-right: auto;
     max-width: 100%;
 }
+
+/* display the cookie usage warning validation */
+.cookieUsageValidation {
+    padding: 5px;
+    background-color: #333333;
+    color:#E0E0E0;
+    text-align:center;
+}
+
+.displayUnderToolbar
+{
+    height: 52px;
+}

+ 17 - 0
main/inc/lib/main_api.lib.php

@@ -7496,3 +7496,20 @@ function api_register_campus($listCampus = true) {
     }
     // Reload the settings.
 }
+
+/**
+ * Set the Site Use Cookie Warning for 1 year
+ */
+function api_set_site_use_cookie_warning_cookie()
+{
+    setcookie("ChamiloUsesCookies", "ok", time()+31556926);
+}
+
+/**
+ * Return true if the Site Use Cookie Warning Cookie warning exists
+ * @return bool
+ */
+function api_site_use_cookie_warning_cookie_exist()
+{
+    return isset($_COOKIE['ChamiloUsesCookies']);
+}

+ 25 - 10
main/inc/lib/template.lib.php

@@ -301,35 +301,50 @@ class Template
     }
 
     /**
-     * Sets the header visibility
-     * @param bool true if we show the header
+     * return true if toolbar has to be displayed for user
+     * @return bool
      */
-    public function set_header($status)
+    public static function isToolBarDisplayedForUser()
     {
-        $this->show_header = $status;
-        $this->assign('show_header', $status);
-
         //Toolbar
         $show_admin_toolbar = api_get_setting('show_admin_toolbar');
-        $show_toolbar       = 0;
+        $show_toolbar = false;
 
         switch ($show_admin_toolbar) {
             case 'do_not_show':
                 break;
             case 'show_to_admin':
                 if (api_is_platform_admin()) {
-                    $show_toolbar = 1;
+                    $show_toolbar = true;
                 }
                 break;
             case 'show_to_admin_and_teachers':
                 if (api_is_platform_admin() || api_is_allowed_to_edit()) {
-                    $show_toolbar = 1;
+                    $show_toolbar = true;
                 }
                 break;
             case 'show_to_all':
-                $show_toolbar = 1;
+                $show_toolbar = true;
                 break;
         }
+        return $show_toolbar;
+    }
+
+    /**
+     * Sets the header visibility
+     * @param bool true if we show the header
+     */
+    public function set_header($status)
+    {
+        $this->show_header = $status;
+        $this->assign('show_header', $status);
+
+        $show_toolbar = 0;
+
+        if (self::isToolBarDisplayedForUser()) {
+            $show_toolbar = 1;
+        }
+
         $this->assign('show_toolbar', $show_toolbar);
 
         //Only if course is available

+ 2 - 0
main/install/configuration.dist.php

@@ -282,3 +282,5 @@ $_configuration['system_stable']     = NEW_VERSION_STABLE;
 //$_configuration['name_order_conventions'] = array(
 //  'french' => array('format' => 'title last_name first_name',  'sort_by' => 'last_name')
 //);
+// Shows a warning message that the site use cookies
+//$_configuration['chamilo_use_cookie_warning_validation'] = false;

+ 23 - 0
main/template/default/layout/main_header.tpl

@@ -11,6 +11,29 @@
 <body dir="{{ text_direction }}" class="{{ section_name }} {{ login_class }}">
 <noscript>{{ "NoJavascript"|get_lang }}</noscript>
 
+<!-- Display the Chamilo Uses Cookies Warning Validation if needed -->
+{% if displayCookieUsageWarning == true %}
+    <!-- If toolbar is displayed, we have to display this block bellow it -->
+    {% if toolBarDisplayed == true %}
+        <div class="displayUnderToolbar" >&nbsp;</div>
+    {% endif %}
+    <form onSubmit="$(this).toggle('slow')" action="" method="post">
+        <input value=1 type="hidden" name="acceptCookies"/>
+        <div class="cookieUsageValidation">
+            {{ "youDeclareToAcceptCookies" | get_lang }}
+            <span style="margin-left:20px;" onclick="$(this).next().toggle('slow'); $(this).toggle('slow')">
+                ({{"More" | get_lang }})
+            </span>
+            <div style="display:none; margin:20px 0;">
+                {{ "helpCookieUsageValidation" | get_lang}}
+            </div>
+            <span style="margin-left:20px;" onclick="$(this).parent().parent().submit()">
+                ({{"Accept" | get_lang }})
+            </span>
+        </div>
+    </form>
+{% endif %}
+
 {% if show_header == true %}
     <div class="skip">
         <ul>

+ 16 - 0
user_portal.php

@@ -164,6 +164,22 @@ if (api_get_setting('allow_browser_sniffer') == 'true') {
 	}
 }
 
+
+// Display the Site Use Cookie Warning Validation
+$useCookieValidation = api_get_configuration_value('chamilo_use_cookie_warning_validation');
+if ($useCookieValidation) {
+	if (isset($_POST['acceptCookies'])) {
+		api_set_site_use_cookie_warning_cookie();
+	} else if (!api_site_use_cookie_warning_cookie_exist()) {
+		if (Template::isToolBarDisplayedForUser()) {
+			$controller->tpl->assign('toolBarDisplayed', true);
+		} else {
+			$controller->tpl->assign('toolBarDisplayed', false);
+		}
+		$controller->tpl->assign('displayCookieUsageWarning', true);
+	}
+}
+
 //check for flash and message
 $sniff_notification = '';
 $some_activex = isset($_SESSION['sniff_check_some_activex']) ? $_SESSION['sniff_check_some_activex'] : null;