Commit 1cdc0486 authored by Son Nguyen's avatar Son Nguyen Committed by Gerrit Code Review

Add class JavascriptDetector for checking if javascript is enabled

1. Add the begining of PHP file, call
JavascriptDetector::check_javascript();

2. Call JavascriptDetector::is_javascript_activated()
 or $SESSION->get('javascriptenabled') to get the current status.

3. Call JavascriptDetector::reset() when users logout.

Change-Id: Ia12e1678ae2f3f74f3b8e5fb2c0bfdd20d5ae906
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent acabfc92
......@@ -422,6 +422,9 @@ function auth_setup () {
$USER->logout();
$SESSION->add_ok_msg(get_string('loggedoutok'));
// reset Javascript Detector
require_once(get_config('libroot') . 'jsCheck/jsdetector.php');
JavascriptDetector::reset();
redirect();
}
if ($sessionlogouttime > time()) {
......
......@@ -393,6 +393,10 @@ else {
$SESSION->set('tablet', false);
}
// Javascript detection
require_once(get_config('libroot') . 'jsCheck/jsdetector.php');
JavascriptDetector::check_javascript();
/*
* Initializes our performance info early.
*
......
Javascript check in Mahara
===============
Website: http://www.phpclasses.org/browse/file/26690.html
Author: Gustav Eklundh
This class will check whether Javascript is enabled in the browser or
not. If javascript is enabled this class does js check only once, then
uses set $SESSION variable, which only gets cleared on logout.
Changes:
* Replace $_SESSION by the Mahara global $SESSION variable
* Add reset method
<?php
/*
* jsCheck - By Gustav Eklundh
* A PHP-class to check if JavaScript is activated or not.
*
* Copyright (C) 2009 Gustav Eklundh
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License v3 as published
* by the Free Software Foundation.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* Homepage: http://threebyte.eu/
* Email: gustav@xcoders.info
**/
/**
*
* This class will detect if the browser supports javascript and store the result in $_SESSION['javascriptenabled'].
*
* How to use:
* // At the begining of your PHP file
* JavascriptDetector::check_javascript();
* ...
* ...
* // When you need to know if the browser supports javascript or not
* if (JavascriptDetector::is_javascript_activated()) {
* // Code for javascript is enabled
* ...
* }
* else {
* // Code for javascript is disabled
* ...
* }
* // You can also use $SESSION->get('javascriptenabled')
* if ($SESSION->get('javascriptenabled')) {
* // Code for javascript is supported
* ...
* }
*
* The following method should be called when the user does logout
* JavascriptDetector::reset(); // to force the JavascriptDetector to detect again
*/
class JavascriptDetector {
static public function check_javascript() {
global $SESSION;
if (isset($_POST['javascriptenabled'])) {
$SESSION->set('javascriptenabled', true);
}
if ($SESSION->get('javascriptenabled') === null) {
$SESSION->set('javascriptenabled', false);
echo <<<JS
<form name="jsdetector_form" id="jsdetector_form" method="post">
<input name="javascriptenabled" type="hidden" value="true" />
<script type="text/javascript">
document.jsdetector_form.submit();
</script>
</form>
JS;
}
}
static public function reset() {
global $SESSION;
$SESSION->clear('javascriptenabled');
}
static public function is_javascript_activated() {
global $SESSION;
return ($SESSION->get('javascriptenabled') === true);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment