From 1e9c2d713864ac46c60c2a09bbb6edf70c25e232 Mon Sep 17 00:00:00 2001
From: Tom Reijnders
Date: Sat, 23 Mar 2013 13:37:33 +0000
Subject: [PATCH] - Added management pages to manage languages (in the site
tab) - Added user management to management page in case of Db authentication
git-svn-id: https://xerteonlinetoolkits.googlecode.com/svn/trunk@729 912cdd6b-5c7d-d5a7-a2ba-d0f0cdb91641
---
functions.php | 11 +-
languages/en-GB/index.inc | 2 +
.../en-GB/library/Xerte/Authentication/Db.inc | 22 +++
.../en-GB/library/Xerte/Authentication/Db.js | 8 +
.../Xerte/Authentication/Db/adduser.inc | 18 ++
.../Authentication/Db/changepassword.inc | 16 ++
.../Xerte/Authentication/Db/deluser.inc | 14 ++
.../php/language/delete_language.inc | 15 ++
.../php/language/import_language.inc | 7 +
.../php/management/management_library.inc | 6 +
.../website_code/php/management/site.inc | 1 -
.../website_code/php/management/users.inc | 4 +
.../en-GB/website_code/scripts/management.js | 4 +-
library/Xerte/Authentication/Abstract.php | 42 +++++
library/Xerte/Authentication/Db.js | 80 ++++++++
library/Xerte/Authentication/Db.php | 110 ++++++++++-
library/Xerte/Authentication/Db/adduser.php | 63 +++++++
.../Authentication/Db/changepassword.php | 56 ++++++
library/Xerte/Authentication/Db/deluser.php | 47 +++++
management.php | 11 ++
website_code/php/{import => }/dUnzip2.inc.php | 0
website_code/php/display_library.php | 2 +-
website_code/php/import/import.php | 2 +-
website_code/php/import/import_template.php | 2 +-
website_code/php/language/delete_language.php | 91 +++++++++
website_code/php/language/import_language.php | 175 ++++++++++++++++++
.../php/language/refresh_language.php | 22 +++
.../php/management/management_library.php | 36 +++-
website_code/php/management/site.php | 14 +-
.../management/user_details_management.php | 2 +-
website_code/php/management/users.php | 13 ++
website_code/scripts/management.js | 152 +++++++++++++++
32 files changed, 1026 insertions(+), 22 deletions(-)
create mode 100644 languages/en-GB/library/Xerte/Authentication/Db.inc
create mode 100644 languages/en-GB/library/Xerte/Authentication/Db.js
create mode 100644 languages/en-GB/library/Xerte/Authentication/Db/adduser.inc
create mode 100644 languages/en-GB/library/Xerte/Authentication/Db/changepassword.inc
create mode 100644 languages/en-GB/library/Xerte/Authentication/Db/deluser.inc
create mode 100644 languages/en-GB/website_code/php/language/delete_language.inc
create mode 100644 languages/en-GB/website_code/php/language/import_language.inc
create mode 100644 library/Xerte/Authentication/Db.js
create mode 100644 library/Xerte/Authentication/Db/adduser.php
create mode 100644 library/Xerte/Authentication/Db/changepassword.php
create mode 100644 library/Xerte/Authentication/Db/deluser.php
rename website_code/php/{import => }/dUnzip2.inc.php (100%)
create mode 100644 website_code/php/language/delete_language.php
create mode 100644 website_code/php/language/import_language.php
create mode 100644 website_code/php/language/refresh_language.php
diff --git a/functions.php b/functions.php
index e8fb01cba1..2e16ea3e44 100755
--- a/functions.php
+++ b/functions.php
@@ -124,6 +124,7 @@ function _load_language_file($file_path)
function _include_javascript_file($file_path)
{
+ global $xerte_toolkits_site;
$languages = 'languages/';
if (isset($_GET['language']) && is_dir($languages . $_GET['language'])) {
@@ -158,9 +159,9 @@ function _include_javascript_file($file_path)
_debug($language);
_debug($real_file_path);
_debug($en_gb_file_path);
- echo "";
- if (file_exists($en_gb_file_path)) {
- echo "";
+ echo "";
+ if (file_exists(dirname(__FILE__) . "/" . $en_gb_file_path)) {
+ echo "";
} else {
// stuff will break at this point.
//die("Where was $real_file_path?");
@@ -170,8 +171,8 @@ function _include_javascript_file($file_path)
if ($language != "en-GB")
{
- if(file_exists($real_file_path)) {
- echo "";
+ if(file_exists(dirname(__FILE__) . "/" . $real_file_path)) {
+ echo "";
}
else
{
diff --git a/languages/en-GB/index.inc b/languages/en-GB/index.inc
index 94350d2189..4c5dcdb9b1 100644
--- a/languages/en-GB/index.inc
+++ b/languages/en-GB/index.inc
@@ -40,6 +40,8 @@ define("INDEX_FOLDER_PROMPT","What would you like to call your folder?");
define("INDEX_WORKSPACE_TITLE","My Projects");
+define("INDEX_WORKSPACE","Workspace");
+
define("INDEX_CREATE","Create a new project");
define("INDEX_TEMPLATES","Here are the templates currently available.");
diff --git a/languages/en-GB/library/Xerte/Authentication/Db.inc b/languages/en-GB/library/Xerte/Authentication/Db.inc
new file mode 100644
index 0000000000..ff6220ae0d
--- /dev/null
+++ b/languages/en-GB/library/Xerte/Authentication/Db.inc
@@ -0,0 +1,22 @@
+
\ No newline at end of file
diff --git a/languages/en-GB/library/Xerte/Authentication/Db.js b/languages/en-GB/library/Xerte/Authentication/Db.js
new file mode 100644
index 0000000000..c8126606b8
--- /dev/null
+++ b/languages/en-GB/library/Xerte/Authentication/Db.js
@@ -0,0 +1,8 @@
+/**
+ * Created with JetBrains PhpStorm.
+ * User: tom
+ * Date: 23-3-13
+ * Time: 11:16
+ * To change this template use File | Settings | File Templates.
+ */
+var REMOVE_USER_PROMPT = "Are you sure you want to remove this user?";
\ No newline at end of file
diff --git a/languages/en-GB/library/Xerte/Authentication/Db/adduser.inc b/languages/en-GB/library/Xerte/Authentication/Db/adduser.inc
new file mode 100644
index 0000000000..4fa22ceb07
--- /dev/null
+++ b/languages/en-GB/library/Xerte/Authentication/Db/adduser.inc
@@ -0,0 +1,18 @@
+
\ No newline at end of file
diff --git a/languages/en-GB/library/Xerte/Authentication/Db/changepassword.inc b/languages/en-GB/library/Xerte/Authentication/Db/changepassword.inc
new file mode 100644
index 0000000000..b0e172a3ec
--- /dev/null
+++ b/languages/en-GB/library/Xerte/Authentication/Db/changepassword.inc
@@ -0,0 +1,16 @@
+
\ No newline at end of file
diff --git a/languages/en-GB/library/Xerte/Authentication/Db/deluser.inc b/languages/en-GB/library/Xerte/Authentication/Db/deluser.inc
new file mode 100644
index 0000000000..fa7c58b110
--- /dev/null
+++ b/languages/en-GB/library/Xerte/Authentication/Db/deluser.inc
@@ -0,0 +1,14 @@
+
\ No newline at end of file
diff --git a/languages/en-GB/website_code/php/language/delete_language.inc b/languages/en-GB/website_code/php/language/delete_language.inc
new file mode 100644
index 0000000000..f9176b9fef
--- /dev/null
+++ b/languages/en-GB/website_code/php/language/delete_language.inc
@@ -0,0 +1,15 @@
+
\ No newline at end of file
diff --git a/languages/en-GB/website_code/php/language/import_language.inc b/languages/en-GB/website_code/php/language/import_language.inc
new file mode 100644
index 0000000000..ad674717d3
--- /dev/null
+++ b/languages/en-GB/website_code/php/language/import_language.inc
@@ -0,0 +1,7 @@
+
\ No newline at end of file
diff --git a/languages/en-GB/website_code/php/management/management_library.inc b/languages/en-GB/website_code/php/management/management_library.inc
index 3a372f1215..36b1af3cff 100644
--- a/languages/en-GB/website_code/php/management/management_library.inc
+++ b/languages/en-GB/website_code/php/management/management_library.inc
@@ -46,4 +46,10 @@
define("MANAGEMENT_LIBRARY_FAIL", "the feature is for administrators only");
+ define("MANAGEMENT_LIBRARY_ADD_LANGUAGE", "Add or update a language definition");
+ define("MANAGEMENT_LIBRARY_EXISTING_LANGUAGES", "Manage existing languages");
+ define("MANAGEMENT_LIBRARY_LANGUAGE_INSTALL", "Install language definition");
+ define("MANAGEMENT_LIBRARY_LANGUAGES", "Language settings");
+ define("MANAGEMENT_LIBRARY_LANGUAGES_EXPLAINED", "Upload and refresh the language definitions using the upload button below. New language definitions can be found in the download section of the Xerte Community website (http://www.xerte.org.uk). There are three different kinds of packages. You can use any of them here.");
+ define("MANAGEMENT_LIBRARY_LANGUAGES_UPDATED", "Language definitions are updated.");
?>
\ No newline at end of file
diff --git a/languages/en-GB/website_code/php/management/site.inc b/languages/en-GB/website_code/php/management/site.inc
index f61bcf3841..93f6364792 100644
--- a/languages/en-GB/website_code/php/management/site.inc
+++ b/languages/en-GB/website_code/php/management/site.inc
@@ -160,5 +160,4 @@ define("LTI_KEYS_ADD_SUBMIT","Add New LTI Key");
define("LTI_KEYS_EDIT_SUBMIT","Save LTI Key");
define("LTI_KEYS_DELETE_SUBMIT","Delete LTI Key");
-
?>
\ No newline at end of file
diff --git a/languages/en-GB/website_code/php/management/users.inc b/languages/en-GB/website_code/php/management/users.inc
index e2d6596bc8..30d72eeea8 100644
--- a/languages/en-GB/website_code/php/management/users.inc
+++ b/languages/en-GB/website_code/php/management/users.inc
@@ -20,5 +20,9 @@
define("USERS_KNOWN", "The user's surname is ");
define("USERS_USERNAME", "The user's username is");
+
+ define("USERS_MANAGE_AUTH", "Authorized users");
+
+ define("USERS_MANAGE_ACTIVE", "Active users with Learning Objects");
?>
\ No newline at end of file
diff --git a/languages/en-GB/website_code/scripts/management.js b/languages/en-GB/website_code/scripts/management.js
index 638e047fb9..57166cd61b 100644
--- a/languages/en-GB/website_code/scripts/management.js
+++ b/languages/en-GB/website_code/scripts/management.js
@@ -4,4 +4,6 @@ var USER_CHANGED = "User successfully changed";
var MANAGEMENT_SHOW = "Show";
-var MANAGEMENT_HIDE = "Hide";
\ No newline at end of file
+var MANAGEMENT_HIDE = "Hide";
+
+var MANAGEMENT_DELETE_LANGUAGE = "Are you sure you want to remove this language: ";
\ No newline at end of file
diff --git a/library/Xerte/Authentication/Abstract.php b/library/Xerte/Authentication/Abstract.php
index 933c5e8046..eee51ad33b 100755
--- a/library/Xerte/Authentication/Abstract.php
+++ b/library/Xerte/Authentication/Abstract.php
@@ -72,4 +72,46 @@ abstract public function check();
public function needsLogin() {
return true;
}
+
+ /**
+ * canManageUser
+ *
+ * Change this to return true if the four AJAX functions getUserList(), addUser(), delUser() and changePassword() are implemented.
+ * Using these four functions the users can be fully managed in the management page
+ */
+ public function canManageUser(&$jsscript)
+ {
+ $jsscript="";
+ return false;
+ }
+
+ /**
+ * getUserList
+ *
+ * Create a form that contains a list, or selection box with all users, and the capability to change password, delete user, and add a new user
+ * @param $changed, indicates whether this function is called after an update. It should mention that the list has been updated and displays $mesg below the form,
+ * see Db.php for an example
+ * @param $mesg, message to display if $changed is true
+ * @return string, contains the form code to manage users. It will be placed dynamically in the Users management page
+ */
+ public function getUserList($changed, $mesg)
+ {
+ echo "";
+ }
+
+ public function addUser($username, $passwd, $firstname, $lastname)
+ {
+ $this->getUserList(true, "");
+ }
+
+ public function delUser($username)
+ {
+ $this->getUserList(true, "");
+ }
+
+ public function changePassword($username, $newpassword)
+ {
+ $this->getUserList(true, "");
+ }
+
}
diff --git a/library/Xerte/Authentication/Db.js b/library/Xerte/Authentication/Db.js
new file mode 100644
index 0000000000..81af0e886a
--- /dev/null
+++ b/library/Xerte/Authentication/Db.js
@@ -0,0 +1,80 @@
+/**
+ * Created with JetBrains PhpStorm.
+ * User: tom
+ * Date: 23-3-13
+ * Time: 10:56
+ * To change this template use File | Settings | File Templates.
+ */
+
+
+function authdb_ajax_send_prepare(url){
+
+ xmlHttp.open("post","library/Xerte/Authentication/Db/" + url,true);
+ xmlHttp.onreadystatechange=authdb_stateChanged;
+ xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+
+}
+
+/**
+ *
+ * Function folders properties state changed
+ * This function handles all of the responses from the ajax queries
+ * @version 1.0
+ * @author Patrick Lockley
+ */
+
+function authdb_stateChanged(){
+
+ if (xmlHttp.readyState==4){
+
+ if(xmlHttp.responseText!=""){
+
+ document.getElementById('manage_auth_users').innerHTML = xmlHttp.responseText;
+
+ }
+ }
+}
+
+function delete_authDb_user() {
+ if(setup_ajax()!=false){
+ var answer = confirm(REMOVE_USER_PROMPT);
+
+ if(answer){
+ var url="deluser.php";
+
+ authdb_ajax_send_prepare(url);
+
+ xmlHttp.send('username=' + encodeURIComponent(document.getElementById('authDb_list_user').value));
+ }
+
+ }
+}
+
+function changepassword_authDb_user() {
+ if(setup_ajax()!=false){
+
+ var url="changepassword.php";
+
+ authdb_ajax_send_prepare(url);
+
+ var passwd = document.getElementById('authDb_changepassword').value;
+ var encodedpasswd = encodeURIComponent(document.getElementById('authDb_changepassword').value);
+ xmlHttp.send('username=' + encodeURIComponent(document.getElementById('authDb_list_user').value) + '&password=' + encodeURIComponent(document.getElementById('authDb_changepassword').value));
+
+ }
+}
+
+function add_authDb_user() {
+ if(setup_ajax()!=false){
+
+ var url="adduser.php";
+
+ authdb_ajax_send_prepare(url);
+
+ xmlHttp.send('username=' + encodeURIComponent(document.getElementById('authDb_username').value) +
+ '&firstname=' + encodeURIComponent(document.getElementById('authDb_firstname').value) +
+ '&surname=' + encodeURIComponent(document.getElementById('authDb_surname').value) +
+ '&password=' + encodeURIComponent(document.getElementById('authDb_password').value));
+
+ }
+}
\ No newline at end of file
diff --git a/library/Xerte/Authentication/Db.php b/library/Xerte/Authentication/Db.php
index b00d9a50f3..462394dae9 100755
--- a/library/Xerte/Authentication/Db.php
+++ b/library/Xerte/Authentication/Db.php
@@ -9,6 +9,9 @@
*
* @see Xerte_Authentication_Abstract
*/
+
+_load_language_file("/library/Xerte/Authentication/Db.inc");
+
class Xerte_Authentication_Db extends Xerte_Authentication_Abstract
{
@@ -44,19 +47,26 @@ public function check()
$this->addError("MySQL not available?");
return false;
}
- // TODO - add query here to check for existance of the 'user' db table?
- $x = db_query("SHOW CREATE TABLE user");
+ // check for existence of the 'user' db table?
+ $x = db_query("SHOW CREATE TABLE {$xerte_toolkits_site->database_table_prefix}user");
if (empty($x)) {
- $this->addError("Does the user table exist?");
- return false;
+ // Create the user table
+ $x = db_query("create table {$xerte_toolkits_site->database_table_prefix}user ( 'iduser' INT NOT NULL, 'username' VARCHAR(45) NULL , 'password' VARCHAR(45) NULL , 'firstname' VARCHAR(45) NULL , 'surname' VARCHAR(45) NULL , PRIMARY KEY ('iduser') )");
+ if (empty($x))
+ {
+ $this->addError("Does the user table exist?");
+ return false;
+ }
+ else
+ return true;
}
- return true;
+ return true;
}
public function login($username, $password)
{
$spassword = $this->_hashAndSalt($username, $password);
- $row = db_query_one("SELECT * FROM user WHERE username = ? AND password = ?", array($username, $spassword));
+ $row = db_query_one("SELECT * FROM {$xerte_toolkits_site->database_table_prefix}user WHERE username = ? AND password = ?", array($username, $spassword));
if (!empty($row)) {
$this->_record = $row;
return true;
@@ -76,4 +86,92 @@ private function _hashAndSalt($username, $password)
return sha1("stablehorseboltapple" . $username . $password);
}
+ public function canManageUser(&$jsscript)
+ {
+ $jsscript = "library/Xerte/Authentication/Db.js";
+ return true;
+ }
+
+ /**
+ * getUserList
+ *
+ * Create a form that contains a list, or selection box with all users, and the capability to change password, delete user, and add a new user
+ * @param $changed, indicates whether this function is called after an update. It should mention that the list has been updated and displays $mesg below the form,
+ * see Db.php for an example
+ * @param $mesg, message to display if $changed is true
+ * @return string, contains the form code to manage users. It will be placed dynamically in the Users management page
+ */
+ public function getUserList($changed, $mesg)
+ {
+ $result = db_query("SELECT * FROM {$xerte_toolkits_site->database_table_prefix}user order by surname,firstname,username");
+
+ //_include_javascript_file("library/Xerte/Authentication/Db.js");
+
+ echo "
";
+ echo " ";
+ echo "
" . AUTH_DB_USERNAME . "
";
+ echo "
" . AUTH_DB_FIRSTNAME . "
";
+ echo "
" . AUTH_DB_SURNAME . "
";
+ echo "
" . AUTH_DB_PASSWORD . "
";
+ echo "";
+ echo "";
+ if ($changed)
+ {
+ echo $mesg;
+ }
+ }
+
+ public function addUser($username, $firstname, $surname, $passwd)
+ {
+ // Check if user exists
+ $row = db_query_one("SELECT * FROM {$xerte_toolkits_site->database_table_prefix}user WHERE username = ?", array($username));
+ if (!empty($row))
+ {
+ return "