summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/page.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2017-04-19 23:43:24 +0200
committerSimon Rettberg2017-04-19 23:43:24 +0200
commitc781a551ae84127ef05eaa36909dca44e49e1200 (patch)
tree81992a3b781285c2ce6e1916b5d5fd349d5ac45d /modules-available/locationinfo/page.inc.php
parent[locationinfo] Enable 30 minutes caching for davinci (diff)
downloadslx-admin-c781a551ae84127ef05eaa36909dca44e49e1200.tar.gz
slx-admin-c781a551ae84127ef05eaa36909dca44e49e1200.tar.xz
slx-admin-c781a551ae84127ef05eaa36909dca44e49e1200.zip
[locationinfo] Better backend-specific property handling, get rid of URL
- The backend URL still had special treatment for legacy reasons, when it would be perfectly fine to make it just another generic property the backend has to define. - Allow for the backend to declare a default value for properties. - Base class will now check and sanitize the setCredentials() input.
Diffstat (limited to 'modules-available/locationinfo/page.inc.php')
-rw-r--r--modules-available/locationinfo/page.inc.php42
1 files changed, 19 insertions, 23 deletions
diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php
index 31702dff..263d07d0 100644
--- a/modules-available/locationinfo/page.inc.php
+++ b/modules-available/locationinfo/page.inc.php
@@ -106,7 +106,6 @@ class Page_LocationInfo extends Page
{
$serverid = Request::post('id', -1, 'int');
$servername = Request::post('name', 'unnamed', 'string');
- $serverurl = Request::post('url', '', 'string');
$servertype = Request::post('type', '', 'string');
$backend = CourseBackend::getInstance($servertype);
@@ -119,24 +118,23 @@ class Page_LocationInfo extends Page
$credentialsJson = array();
$counter = 0;
- foreach ($tmptypeArray as $key => $value) {
- $credentialsJson[$key] = Request::post($counter);
+ foreach ($tmptypeArray as $cred) {
+ $credentialsJson[$cred->property] = Request::post($counter);
$counter++;
}
$params = array(
'name' => $servername,
- 'url' => $serverurl,
'type' => $servertype,
'credentials' => json_encode($credentialsJson)
);
if ($serverid === 0) {
- Database::exec('INSERT INTO `setting_location_info` (servername, serverurl, servertype, credentials)
- VALUES (:name, :url, :type, :credentials)', $params);
+ Database::exec('INSERT INTO `setting_location_info` (servername, servertype, credentials)
+ VALUES (:name, :type, :credentials)', $params);
$this->checkConnection(Database::lastInsertId());
} else {
$params['id'] = $serverid;
Database::exec('UPDATE `setting_location_info`
- SET servername = :name, serverurl = :url, servertype = :type, credentials = :credentials
+ SET servername = :name, servertype = :type, credentials = :credentials
WHERE serverid = :id', $params);
$this->checkConnection($serverid);
}
@@ -280,7 +278,7 @@ class Page_LocationInfo extends Page
Util::traceError('checkConnection called with no server id');
}
- $dbresult = Database::queryFirst("SELECT servertype, credentials, serverurl
+ $dbresult = Database::queryFirst("SELECT servertype, credentials
FROM `setting_location_info`
WHERE serverid = :serverid", array('serverid' => $serverid));
@@ -289,7 +287,7 @@ class Page_LocationInfo extends Page
LocationInfo::setServerError($serverid, 'Unknown backend type: ' . $dbresult['servertype']);
return;
}
- $credentialsOk = $serverInstance->setCredentials(json_decode($dbresult['credentials'], true), $dbresult['serverurl'], $serverid);
+ $credentialsOk = $serverInstance->setCredentials($serverid, json_decode($dbresult['credentials'], true));
if ($credentialsOk) {
$connectionOk = $serverInstance->checkConnection();
@@ -439,7 +437,7 @@ class Page_LocationInfo extends Page
*/
private function ajaxServerSettings($id)
{
- $dbresult = Database::queryFirst('SELECT servername, serverurl, servertype, credentials
+ $dbresult = Database::queryFirst('SELECT servername, servertype, credentials
FROM `setting_location_info` WHERE serverid = :id', array('id' => $id));
// Credentials stuff.
@@ -463,35 +461,34 @@ class Page_LocationInfo extends Page
$backend['credentials'] = array();
$counter = 0;
- foreach ($credentials as $key => $value) {
+ foreach ($credentials as $cred) {
$credential['uid'] = $counter;
- $credential['name'] = Dictionary::translateFile($s, $key);
- $credential['type'] = $value;
- $credential['title'] = Dictionary::translateFile($s, $key . "_title");
+ $credential['name'] = Dictionary::translateFile($s, $cred->property);
+ $credential['type'] = $cred->type;
+ $credential['title'] = Dictionary::translateFile($s, $cred->property . "_title");
if (Property::getPasswordFieldType() === 'text') {
$credential['mask'] = false;
} else {
- if ($value == "password") {
+ if ($cred->type === "password") {
$credential['mask'] = true;
}
}
if ($backend['typ'] == $dbresult['servertype']) {
- foreach ($dbcredentials as $k => $v) {
- if ($k == $key) {
- $credential['value'] = $v;
- break;
- }
+ if (isset($dbcredentials[$cred->property])) {
+ $credential['value'] = $dbcredentials[$cred->property];
+ } else {
+ $credential['value'] = $cred->default;
}
}
$selection = array();
- if (is_array($value)) {
+ if (is_array($cred->type)) {
$selfirst = true;
- foreach ($value as $opt) {
+ foreach ($cred->type as $opt) {
$option['option'] = $opt;
if (isset($credential['value'])) {
if ($opt == $credential['value']) {
@@ -523,7 +520,6 @@ class Page_LocationInfo extends Page
echo Render::parse('server-settings', array('id' => $id,
'name' => $dbresult['servername'],
- 'url' => $dbresult['serverurl'],
'servertype' => $dbresult['servertype'],
'backendList' => array_values($serverBackends)));
}