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 ""; + 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 "
  • " . AUTH_DB_USEREXISTS . "
  • "; + } + // Insert user + $spassword = $this->_hashAndSalt($username, $passwd); + + $query="insert into {$xerte_toolkits_site->database_table_prefix}user set firstname=?, surname=?, username=?, password=?"; + $params = array($firstname, $surname, $username, $spassword); + $res = db_query($query, $params); + if ($res) + return ""; + else + return "
  • " . AUTH_DB_USERADDFAILED . "
  • "; + } + + public function delUser($username) + { + $query="delete from {$xerte_toolkits_site->database_table_prefix}user where username=?"; + $params = array($username); + $res = db_query($query, $params); + if ($res) + return ""; + else + return "
  • " . AUTH_DB_USERDELFAILED . "
  • "; + + } + + public function changePassword($username, $newpassword) + { + $spassword = $this->_hashAndSalt($username, $newpassword); + $query="update {$xerte_toolkits_site->database_table_prefix}user set password=? where username=?"; + $params = array($spassword, $username); + $res = db_query($query, $params); + if ($res) + return ""; + else + return "
  • " . AUTH_DB_CHANGEPASSWORDFAILED . "
  • "; + } + } diff --git a/library/Xerte/Authentication/Db/adduser.php b/library/Xerte/Authentication/Db/adduser.php new file mode 100644 index 0000000000..e7a4b81c5d --- /dev/null +++ b/library/Xerte/Authentication/Db/adduser.php @@ -0,0 +1,63 @@ +authentication_method); + } + + // Easy checks first + $mesg = ""; + if (!isset($_POST['username']) || strlen($_POST['username']) == 0) + { + $mesg .= "
  • " . AUTH_DB_ADDUSER_INVALIDUSERNAME . "
  • "; + } + if (!isset($_POST['firstname']) || strlen($_POST['firstname']) == 0) + { + $mesg .= "
  • " . AUTH_DB_ADDUSER_INVALIDFIRSTNAME . "
  • "; + } + if (!isset($_POST['surname']) || strlen($_POST['surname']) == 0) + { + $mesg .= "
  • " . AUTH_DB_ADDUSER_INVALIDSURNAME . "
  • "; + } + if (!isset($_POST['password']) || strlen($_POST['password']) == 0) + { + $mesg .= "
  • " . AUTH_DB_ADDUSER_INVALIDPASSWORD . "
  • "; + } + else if (isset($_POST['password']) && strlen(urldecode(['password'])) < 5) + { + $mesg .= "
  • " . AUTH_DB_ADDUSER_PASSWORDTOOSHORT . "
  • "; + } + if (strlen($mesg) == 0) + { + $mesg = $authmech->addUser(urldecode($_POST['username']), urldecode($_POST['firstname']), urldecode($_POST['surname']), urldecode($_POST['password'])); + } + if (strlen($mesg) > 0) + { + $finalmesg = "

    " . AUTH_DB_ADDUSER_FAILED . "

    "; + $finalmesg .= "

    "; + } + else + { + $finalmesg = "

    " . AUTH_DB_ADDUSER_SUCCEEDED . "

    "; + } + $authmech->getUserList(true, $finalmesg); +} + +?> \ No newline at end of file diff --git a/library/Xerte/Authentication/Db/changepassword.php b/library/Xerte/Authentication/Db/changepassword.php new file mode 100644 index 0000000000..374869b484 --- /dev/null +++ b/library/Xerte/Authentication/Db/changepassword.php @@ -0,0 +1,56 @@ +authentication_method); + } + + // Easy checks first + $mesg = ""; + if (!isset($_POST['username']) || strlen($_POST['username']) == 0) + { + $mesg .= "
  • " . AUTH_DB_CHANGEPASSWORD_INVALIDUSERNAME . "
  • "; + } + if (!isset($_POST['password']) || strlen($_POST['password']) == 0) + { + $mesg .= "
  • " . AUTH_DB_CHANGEPASSWORD_INVALIDPASSWORD . "
  • "; + } + else if (isset($_POST['password']) && strlen(urldecode($_POST['password'])) < 5) + { + $mesg .= "
  • " . AUTH_DB_CHANGEPASSWORD_PASSWORDTOOSHORT . "
  • "; + } + + if (strlen($mesg) == 0) + { + $mesg = $authmech->changePassword(urldecode($_POST['username']), urldecode($_POST['password'])); + } + if (strlen($mesg) > 0) + { + $finalmesg = "

    " . AUTH_DB_CHANGEPASSWORD_FAILED . "

    "; + $finalmesg .= "

    "; + } + else + { + $finalmesg = "

    " . AUTH_DB_CHANGEPASSWORD_SUCCEEDED . "

    "; + } + $authmech->getUserList(true, $finalmesg); +} + +?> \ No newline at end of file diff --git a/library/Xerte/Authentication/Db/deluser.php b/library/Xerte/Authentication/Db/deluser.php new file mode 100644 index 0000000000..4d7a2456a3 --- /dev/null +++ b/library/Xerte/Authentication/Db/deluser.php @@ -0,0 +1,47 @@ +authentication_method); + } + + // Easy checks first + $mesg = ""; + if (!isset($_POST['username']) || strlen($_POST['username']) == 0) + { + $mesg .= "
  • " . AUTH_DB_DELUSER_INVALIDUSERNAME . "
  • "; + } + if (strlen($mesg) == 0) + { + $mesg = $authmech->delUser(urldecode($_POST['username'])); + } + if (strlen($mesg) > 0) + { + $finalmesg = "

    " . AUTH_DB_DELUSER_FAILED . "

    "; + $finalmesg .= "

    "; + } + else + { + $finalmesg = "

    " . AUTH_DB_DELUSER_SUCCEEDED . "

    "; + } + $authmech->getUserList(true, $finalmesg); +} + +?> \ No newline at end of file diff --git a/management.php b/management.php index fd6462d87d..00c0c2d1ea 100644 --- a/management.php +++ b/management.php @@ -132,6 +132,12 @@ function mgt_page($xerte_toolkits_site, $extra) */ } else { + global $authmech; + + if (!isset($authmech)) + { + $authmech = Xerte_Authentication_Factory::create($xerte_toolkits_site->authentication_method); + } if (($_POST["login"] == $xerte_toolkits_site->admin_username) && ($_POST["password"] == $xerte_toolkits_site->admin_password)) { $_SESSION['toolkits_logon_id'] = "site_administrator"; @@ -179,6 +185,11 @@ function mgt_page($xerte_toolkits_site, $extra) _include_javascript_file("website_code/scripts/import.js"); _include_javascript_file("website_code/scripts/template_management.js"); _include_javascript_file("website_code/scripts/logout.js"); + + if ($authmech->canManageUser($jsscript)) + { + _include_javascript_file($jsscript); + } ?> diff --git a/website_code/php/import/dUnzip2.inc.php b/website_code/php/dUnzip2.inc.php similarity index 100% rename from website_code/php/import/dUnzip2.inc.php rename to website_code/php/dUnzip2.inc.php diff --git a/website_code/php/display_library.php b/website_code/php/display_library.php index cadbfdf7f9..90e61cf010 100644 --- a/website_code/php/display_library.php +++ b/website_code/php/display_library.php @@ -280,7 +280,7 @@ function list_users_projects($sort_type) { echo " src=\"{$xerte_toolkits_site->site_url}/website_code/images/folder_workspace.gif\""; - echo " />Workspace

    "; + echo " />" . INDEX_WORKSPACE . "

    "; $level = 1; diff --git a/website_code/php/import/import.php b/website_code/php/import/import.php index cc78e31f22..c669bd4bbe 100644 --- a/website_code/php/import/import.php +++ b/website_code/php/import/import.php @@ -368,7 +368,7 @@ function folder_loop($path){ if(@move_uploaded_file($_FILES['filenameuploaded']['tmp_name'], $new_file_name)){ - require_once dirname(__FILE__) . "/dUnzip2.inc.php"; + require_once dirname(__FILE__) . "/../dUnzip2.inc.php"; $zip = new dUnzip2($new_file_name); diff --git a/website_code/php/import/import_template.php b/website_code/php/import/import_template.php index 56f62d2ade..66b922dc93 100644 --- a/website_code/php/import/import_template.php +++ b/website_code/php/import/import_template.php @@ -109,7 +109,7 @@ function copy_loop($path){ if(@move_uploaded_file($_FILES['filenameuploaded']['tmp_name'], $new_file_name)){ - require_once dirname(__FILE__)."/dUnzip2.inc.php"; + require_once dirname(__FILE__) . "/dUnzip2.inc.php"; $zip = new dUnzip2($new_file_name); diff --git a/website_code/php/language/delete_language.php b/website_code/php/language/delete_language.php new file mode 100644 index 0000000000..9e2d6bc24d --- /dev/null +++ b/website_code/php/language/delete_language.php @@ -0,0 +1,91 @@ +root_file_path . "languages/" . $_POST['code'])){ + + $code = $_POST['code']; + + if(!is_writeable($xerte_toolkits_site->root_file_path . "languages/" . $code)) { + _debug("{$xerte_toolkits_site->root_file_path}languages/{$code} needs to be writeable. Cannot perform import"); + echo DELETE_LANGUAGE_FAILED . $lang_dir . $xerte_toolkits_site->root_file_path . "languages/" . $code . DELETE_LANGUAGE_WRITABLE; + exit(0); + } + + $abort = false; + if (file_exists($xerte_toolkits_site->root_file_path . "languages/" . $code)) + { + $p = folder_delete($xerte_toolkits_site->root_file_path . "languages/" . $code . "/"); + if ($p != "") + { + echo DELETE_LANGUAGE_FAILED . $lang_dir . DELETE_LANGUAGE_UNABLE_TO_DELETE . $p; + $abort = true; + + } + } + if (file_exists($xerte_toolkits_site->root_file_path . "modules/xerte/parent_templates/Nottingham/wizards/" . $code)) + { + $p = folder_delete($xerte_toolkits_site->root_file_path . "modules/xerte/parent_templates/Nottingham/wizards/" . $code . "/"); + if ($p != "") + { + echo DELETE_LANGUAGE_FAILED . $lang_dir . DELETE_LANGUAGE_UNABLE_TO_DELETE . $p; + $abort=true; + } + } + if (!$abort) + { + echo DELETE_LANGUAGE_SUCCEEDED . $code; + echo "****"; + language_details(true); + } + +} +else +{ + echo DELETE_LANGUAGE_FAILED . DELETE_LANGUAGE_INVALIDCODE; +} +?> \ No newline at end of file diff --git a/website_code/php/language/import_language.php b/website_code/php/language/import_language.php new file mode 100644 index 0000000000..591d4477e2 --- /dev/null +++ b/website_code/php/language/import_language.php @@ -0,0 +1,175 @@ +import_path)) { + _debug("{$xerte_toolkits_site->import_path} needs to be writeable. Cannot perform import"); + echo IMPORT_LANGUAGE_FAILED . $lang_dir . $xerte_toolkits_site->import_path . IMPORT_LANGUAGE_WRITABLE; + exit(0); + } + if(!is_writeable($xerte_toolkits_site->root_file_path . "languages/")) { + _debug("{$xerte_toolkits_site->root_file_path} languages/ needs to be writeable. Cannot perform import"); + echo IMPORT_LANGUAGE_FAILED . $lang_dir . $xerte_toolkits_site->root_file_path . "languages/" . IMPORT_LANGUAGE_WRITABLE; + exit(0); + } + if(!is_writeable($xerte_toolkits_site->root_file_path . "modules/xerte/parent_templates/Nottingham/wizards/")) { + _debug("{$xerte_toolkits_site->root_file_path} modules/xerte/parent_templates/Nottingham/wizards/ needs to be writeable. Cannot perform import"); + echo IMPORT_LANGUAGE_FAILED . $lang_dir . $xerte_toolkits_site->root_file_path . "modules/xerte/parent_templates/Nottingham/wizards/" . IMPORT_LANGUAGE_WRITABLE; + exit(0); + } + + $ok = mkdir($xerte_toolkits_site->import_path . $this_dir) && chmod($xerte_toolkits_site->import_path . $this_dir,0777); + if(!$ok) { + _debug("Warning: we had problems either creating the temp dir {$xerte_toolkits_site->import_path}$this_dir or chmod'ing it 0777."); + } + + $new_file_name = $xerte_toolkits_site->import_path . $this_dir . time() . $_FILES['filenameuploaded']['name']; + + if(@move_uploaded_file($_FILES['filenameuploaded']['tmp_name'], $new_file_name)){ + + require_once dirname(__FILE__) . "/../dUnzip2.inc.php"; + + $zip = new dUnzip2($new_file_name); + + $zip->debug = false; + + $zip->getList(); + + $file_data = array(); + + $template_data_equivalent = null; + + $lang_dir = null; + /* + * Look for the folders in the zip and move files accordingly + */ + $nottingham_language_found = false; + $xot_language_found = false; + + foreach($zip->compressedList as $x){ + + $y=$x['file_name']; + if(!(strpos($y,"languages/")===false)){ + + $string = $zip->unzip($y, false, 0777); + + $temp_array = array($y,$string,"languages"); + + array_push($file_data,$temp_array); + + if ($lang_dir == null) + { + $lang_dir = substr($y, 10, 5); + } + $xot_language_found = true; + + } + + if((strpos($y,"wizards/")!==false)){ + + $string = $zip->unzip($y, false, 0777); + + $temp_array = array($y,$string,"wizards"); + + array_push($file_data,$temp_array); + if ($lang_dir == null) + { + $lang_dir = substr($y, 8, 5); + } + $nottingham_language_found = true; + } + } + /* + * Make some new folders + */ + + if ($xot_language_found && !file_exists($xerte_toolkits_site->root_file_path . "languages/" . $lang_dir)) + { + mkdir($xerte_toolkits_site->root_file_path . "languages/" . $lang_dir); + } + + if ($nottingham_language_found && !file_exists($xerte_toolkits_site->root_file_path . "modules/xerte/parent_templates/Nottingham/wizards/" . $lang_dir)) + { + mkdir($xerte_toolkits_site->root_file_path . "modules/xerte/parent_templates/Nottingham/wizards/" . $lang_dir); + } + + /* + * Put the files into the right folders + */ + + while($file_to_create = array_pop($file_data)){ + + if($file_to_create[2]=="languages"){ + + $paths = array(); + $file = dirname($file_to_create[0]); + + while ($file != ".") + { + $paths[] = $file; + $file = dirname($file); + } + for( $i=count($paths)-1; $i>=0; $i--) + { + if (!file_exists($xerte_toolkits_site->root_file_path . $paths[$i])) + { + mkdir($xerte_toolkits_site->root_file_path . $paths[$i]); + } + } + $fp = fopen($xerte_toolkits_site->root_file_path . $file_to_create[0],"w"); + + fwrite($fp,$file_to_create[1]); + + fclose($fp); + + chmod($xerte_toolkits_site->import_path . $this_dir . $file_to_create[0],0777); + + }else if($file_to_create[2]=="wizards"){ + + $fp = fopen($xerte_toolkits_site->root_file_path . "modules/xerte/parent_templates/Nottingham/" . $file_to_create[0],"w"); + + fwrite($fp,$file_to_create[1]); + + fclose($fp); + + } + + } + + $zip->close(); + + unlink($new_file_name); + + rmdir($xerte_toolkits_site->import_path . $this_dir); + + echo IMPORT_LANGUAGE_SUCCEEDED . $lang_dir; + echo ".****"; + } +} +else +{ + + echo IMPORT_LANGUAGE_FAILED . IMPORT_LANGUAGE_NOVALIDZIP; +} +?> diff --git a/website_code/php/language/refresh_language.php b/website_code/php/language/refresh_language.php new file mode 100644 index 0000000000..e7e2eb308a --- /dev/null +++ b/website_code/php/language/refresh_language.php @@ -0,0 +1,22 @@ + \ No newline at end of file diff --git a/website_code/php/management/management_library.php b/website_code/php/management/management_library.php index 5309c167c9..ffdd10d507 100644 --- a/website_code/php/management/management_library.php +++ b/website_code/php/management/management_library.php @@ -1,7 +1,7 @@ " . MANAGEMENT_LIBRARY_LANGUAGES_EXPLAINED . "

    "; + echo "

    " . MANAGEMENT_LIBRARY_ADD_LANGUAGE . "

    "; + echo "




    "; + echo "

    " . MANAGEMENT_LIBRARY_EXISTING_LANGUAGES . "

    "; + $langs = getLanguages(); + $codes = array_keys($langs); + echo ""; + if ($changed) + { + echo "

    ". MANAGEMENT_LIBRARY_LANGUAGES_UPDATED . "

    "; + } + + } ?> \ No newline at end of file diff --git a/website_code/php/management/site.php b/website_code/php/management/site.php index 3bbf654a46..ddcc94cb09 100644 --- a/website_code/php/management/site.php +++ b/website_code/php/management/site.php @@ -7,6 +7,7 @@ _load_language_file("/website_code/php/management/site.inc"); require_once("../user_library.php"); +require_once("management_library.php"); if(is_user_admin()){ @@ -167,6 +168,12 @@ echo "
    "; + echo "
    "; + echo "

    " . MANAGEMENT_LIBRARY_LANGUAGES . "

    "; + language_details(false); + echo "
    "; + echo ""; + echo "

    " . MANAGEMENT_SITE_LTI . "

    "; @@ -230,11 +237,12 @@ echo "
    "; } + echo ""; + echo ""; + - echo ""; - echo ""; - echo ""; + echo ""; }else{ diff --git a/website_code/php/management/user_details_management.php b/website_code/php/management/user_details_management.php index dc78417066..9350aa33b2 100644 --- a/website_code/php/management/user_details_management.php +++ b/website_code/php/management/user_details_management.php @@ -13,7 +13,7 @@ $query="update {$xerte_toolkits_site->database_table_prefix}logindetails set firstname=?, surname=?, username=? WHERE login_id = ?"; $params = array($_POST['firstname'], $_POST['surname'], $_POST['username'], $_POST['user_id']); - $res =db_querY($query, $params); + $res =db_query($query, $params); if($res) { echo USERS_UPDATE_SUCCESS; }else{ diff --git a/website_code/php/management/users.php b/website_code/php/management/users.php index bf0a092203..aaebe4dd4d 100644 --- a/website_code/php/management/users.php +++ b/website_code/php/management/users.php @@ -8,6 +8,19 @@ require("management_library.php"); if(is_user_admin()){ + global $authmech; + if (!isset($authmech)) + { + $authmech = Xerte_Authentication_Factory::create($xerte_toolkits_site->authentication_method); + } + if ($authmech->canManageUser($jsscript)) + { + echo "

    " . USERS_MANAGE_AUTH . "

    "; + echo "
    "; + $authmech->getUserList(false, ""); + echo "
    "; + echo "

    " . USERS_MANAGE_ACTIVE . "

    "; + } $database_id = database_connect("templates list connected","template list failed"); diff --git a/website_code/scripts/management.js b/website_code/scripts/management.js index a0b5e5a5c5..ac828026f9 100644 --- a/website_code/scripts/management.js +++ b/website_code/scripts/management.js @@ -712,6 +712,158 @@ function delete_template(template){ } + +var iframe_language_interval = 0; + +function iframe_language_check_upload(){ + + if(window["upload_iframe"].document.body.innerHTML!=""){ + + if(window["upload_iframe"].document.body.innerHTML.indexOf("****")!=-1){ + + clearInterval(iframe_language_interval); + + string = window["upload_iframe"].document.body.innerHTML.substr(window["upload_iframe"].document.body.innerHTML.indexOf(">")+1); + + string = string.substr(0,string.length-4); + + alert(string); + + refresh_languages(); + + window["upload_iframe"].document.body.innerHTML=""; + + }else{ + + clearInterval(iframe_language_interval); + + string = window["upload_iframe"].document.body.innerHTML.substr(window["upload_iframe"].document.body.innerHTML.indexOf(">")+1); + + alert(PHP_ERROR + " - " + string); + + } + + } + +} + +var iframe_language_interval = 0; + +function iframe_language_check(){ + + if(window["upload_iframe"].document.body.innerHTML!=""){ + + if(window["upload_iframe"].document.body.innerHTML.indexOf("****")!=-1){ + + clearInterval(iframe_language_interval); + + string = window["upload_iframe"].document.body.innerHTML.substr(window["upload_iframe"].document.body.innerHTML.indexOf(">")+1); + + string = string.substr(0,string.length-4); + + alert(string); + + if(typeof window_reference==="undefined"){ + + window.opener.screen_refresh(); + + }else{ + + window_reference.screen_refresh(); + + } + + window["upload_iframe"].document.body.innerHTML=""; + + }else{ + + clearInterval(iframe_language_interval); + + string = window["upload_iframe"].document.body.innerHTML.substr(window["upload_iframe"].document.body.innerHTML.indexOf(">")+1); + + alert(PHP_ERROR + " - " + string); + + } + + } + +} + +/** + * + * Function iframe upload check initialise + * This function starts checking the iframe for the response text every 5 seconds (used by the media quota import page). + * @version 1.0 + * @author Patrick Lockley + */ + +function iframe_upload_language_check_initialise(){ + + iframe_language_interval = setInterval("iframe_language_check_upload()",500); + +} + +function iframe_language_check_initialise(){ + + iframe_language_interval = setInterval("iframe_language_check()",500); + +} + +function management_languageChanged(){ + + if (xmlHttp.readyState==4){ + + response = xmlHttp.responseText.trim(); + if(response!=""){ + p = response.indexOf("****"); + if (p != -1) + { + msg = response.substr(0, p); + innerhtml = response.substr(p+4); + elmnt = document.getElementById('languagedetails_child'); + elmnt.innerHTML = innerhtml; + if (msg != "") + alert(msg); + } + else + { + alert(response); + } + + } + } +} + +function delete_language(code){ + var answer = confirm(MANAGEMENT_DELETE_LANGUAGE + code); + if (answer) + { + if (setup_ajax() != false) + { + var url = "../language/delete_language.php"; + + xmlHttp.open("post",management_ajax_php_path + url,true); + xmlHttp.onreadystatechange=management_languageChanged; + xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + + xmlHttp.send('code=' + code); + } + } +} + +function refresh_languages() +{ + if (setup_ajax() != false) + { + var url = "../language/refresh_language.php"; + + xmlHttp.open("post",management_ajax_php_path + url,true); + xmlHttp.onreadystatechange=management_languageChanged; + xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + + xmlHttp.send(); + } +} // Function give a project // // Version 1.0 University of Nottingham