From 5e8ae687fd8a303e707a6a4fa677313056eb87c7 Mon Sep 17 00:00:00 2001 From: baelmyhu Date: Fri, 23 Jan 2015 16:22:14 +0100 Subject: [PATCH] Adds cookie warning message see #7478 A configuration option is required in configuration.php: chamilo_use_cookie_warning_validation --- index.php | 16 +++++++++ main/admin/index.php | 16 +++++++++ main/css/base.css | 13 ++++++++ main/inc/lib/main_api.lib.php | 17 ++++++++++ main/inc/lib/template.lib.php | 35 ++++++++++++++------ main/install/configuration.dist.php | 2 ++ main/template/default/layout/main_header.tpl | 23 +++++++++++++ user_portal.php | 16 +++++++++ 8 files changed, 128 insertions(+), 10 deletions(-) diff --git a/index.php b/index.php index e7081aa280..50c2625968 100755 --- a/index.php +++ b/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'])) { diff --git a/main/admin/index.php b/main/admin/index.php index d253267552..ccbb7df266 100644 --- a/main/admin/index.php +++ b/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 diff --git a/main/css/base.css b/main/css/base.css index bb731da0e9..4065870f87 100755 --- a/main/css/base.css +++ b/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; +} diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index ffc5332883..be10a77ddb 100755 --- a/main/inc/lib/main_api.lib.php +++ b/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']); +} diff --git a/main/inc/lib/template.lib.php b/main/inc/lib/template.lib.php index 4d26ca5bc9..8ab7e14191 100755 --- a/main/inc/lib/template.lib.php +++ b/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 diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index 413520c59e..ac98ffd6a9 100755 --- a/main/install/configuration.dist.php +++ b/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; diff --git a/main/template/default/layout/main_header.tpl b/main/template/default/layout/main_header.tpl index e6d00cdec1..0b40700e7f 100755 --- a/main/template/default/layout/main_header.tpl +++ b/main/template/default/layout/main_header.tpl @@ -11,6 +11,29 @@ + +{% if displayCookieUsageWarning == true %} + + {% if toolBarDisplayed == true %} +
 
+ {% endif %} +
+ +
+ {{ "youDeclareToAcceptCookies" | get_lang }} + + ({{"More" | get_lang }}) + +
+ {{ "helpCookieUsageValidation" | get_lang}} +
+ + ({{"Accept" | get_lang }}) + +
+
+{% endif %} + {% if show_header == true %}