summaryrefslogtreecommitdiffstats
path: root/modules-available
diff options
context:
space:
mode:
authorJannik Schönartz2017-03-09 00:23:56 +0100
committerJannik Schönartz2017-03-09 00:23:56 +0100
commit326766e9ce7caeaa653cb2bac20962d1147a7e6a (patch)
treefa48f4e8530dc64cabb4a48c04bde9149ba62155 /modules-available
parentfrontend: fixed vertical mode in doorsign (diff)
downloadslx-admin-326766e9ce7caeaa653cb2bac20962d1147a7e6a.tar.gz
slx-admin-326766e9ce7caeaa653cb2bac20962d1147a7e6a.tar.xz
slx-admin-326766e9ce7caeaa653cb2bac20962d1147a7e6a.zip
Locationinfo: Errors from the CourseBackend are now safes in the db and shown in the Admin-Panel. Refresh-button added for the servers. Install.php needs to be executed!
Diffstat (limited to 'modules-available')
-rw-r--r--modules-available/locationinfo/api.inc.php12
-rw-r--r--modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php24
-rw-r--r--modules-available/locationinfo/install.inc.php11
-rw-r--r--modules-available/locationinfo/lang/de/messages.json2
-rw-r--r--modules-available/locationinfo/lang/en/messages.json2
-rw-r--r--modules-available/locationinfo/page.inc.php41
-rw-r--r--modules-available/locationinfo/templates/credentials.html2
-rw-r--r--modules-available/locationinfo/templates/location-info.html15
8 files changed, 82 insertions, 27 deletions
diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php
index 4fd7eee5..96685cab 100644
--- a/modules-available/locationinfo/api.inc.php
+++ b/modules-available/locationinfo/api.inc.php
@@ -66,13 +66,17 @@ function getCalendar($idList) {
$resultarray = array();
foreach ($serverList as $serverid => $server) {
$serverInstance = CourseBackend::getInstance($server['type']);
- $serverInstance->setCredentials($server['credentials'], $server['url'], $serverid);
- echo $serverInstance->getError();
+ $setCred = $serverInstance->setCredentials($server['credentials'], $server['url'], $serverid);
+
$calendarFromBackend = $serverInstance->fetchSchedule($server['idlist']);
$formattedArray = array();
- if ($calendarFromBackend === false) {
- // TODO: write error in db.
+ if ($calendarFromBackend === false || $setCred === false) {
+ $error['timestamp'] = time();
+ $error['error'] = $serverInstance->getError();
+ Database::exec("UPDATE `setting_location_info` Set error=:error WHERE serverid=:id", array('id' => $serverid, 'error' => json_encode($error, true)));
+ } else {
+ Database::exec("UPDATE `setting_location_info` Set error=NULL WHERE serverid=:id", array('id' => $serverid));
}
foreach ($calendarFromBackend as $key => $value) {
diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php
index 02883df5..3dd0f7aa 100644
--- a/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php
+++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php
@@ -1,14 +1,30 @@
<?php
class Coursebackend_Dummy extends CourseBackend {
-
-
-
+ private $pw;
public function setCredentials($json,$location,$serverID) {
+ $x = $json;
+ $this->pw = $x['password'];
+
+ if ($this->pw == "mfg") {
+ $this->error = false;
+ return true;
+ } else {
+ $this->errormsg = "USE mfg as password!";
+ $this->error = true;
+ return false;
+ }
}
public function checkConnection(){
- return "Your Error could be shown here!";
+ if ($this->pw == "mfg") {
+ $this->error = false;
+ return true;
+ } else {
+ $this->errormsg = "USE mfg as password!";
+ $this->error = true;
+ return false;
+ }
}
public function getCredentials(){
diff --git a/modules-available/locationinfo/install.inc.php b/modules-available/locationinfo/install.inc.php
index c6e8f1f3..a371ad02 100644
--- a/modules-available/locationinfo/install.inc.php
+++ b/modules-available/locationinfo/install.inc.php
@@ -19,11 +19,20 @@ $res[] = tableCreate('setting_location_info', '
`servername` VARCHAR(2000) NOT NULL,
`serverurl` VARCHAR(2000) NOT NULL,
`servertype` VARCHAR(100) NOT NULL,
- `auth` VARCHAR(100) NOT NULL,
+ `credentials` VARCHAR(2000),
+ `error` VARCHAR(2000),
PRIMARY KEY (`serverid`)
');
// Create response for browser
+if (!tableHasColumn('setting_location_info', 'error')) {
+ $ret = Database::exec("ALTER TABLE `setting_location_info` ADD `error` VARCHAR(2000) AFTER `credentials`");
+ if ($ret === false) {
+ finalResponse(UPDATE_FAILED, 'Adding column error failed: ' . Database::lastError());
+ }
+ $res[] = UPDATE_DONE;
+}
+
if (!tableHasColumn('setting_location_info', 'credentials')) {
$ret = Database::exec("ALTER TABLE `setting_location_info` ADD `credentials` VARCHAR(2000) AFTER `servertype`");
if ($ret === false) {
diff --git a/modules-available/locationinfo/lang/de/messages.json b/modules-available/locationinfo/lang/de/messages.json
index 426374f6..d2ea6b05 100644
--- a/modules-available/locationinfo/lang/de/messages.json
+++ b/modules-available/locationinfo/lang/de/messages.json
@@ -4,5 +4,5 @@
"deleted-x-entries": "Eintr\u00e4ge gelöscht: {{0}}",
"openingtime-updated": "Öffnungszeiten aktualisierts.",
"config-saved": "Einstellungen erfolgreich gespeichert.",
- "auth-failed": "Authentifizierung fehlgeschlagen: Locationid {{0}} Error: {{1}}"
+ "auth-failed": "[{{0}}] {{1}} Error: {{2}}"
}
diff --git a/modules-available/locationinfo/lang/en/messages.json b/modules-available/locationinfo/lang/en/messages.json
index 9537fba1..b85b56cd 100644
--- a/modules-available/locationinfo/lang/en/messages.json
+++ b/modules-available/locationinfo/lang/en/messages.json
@@ -4,5 +4,5 @@
"deleted-x-entries": "Entries deleted: {{0}}",
"openingtime-updated": "Openingtime updated.",
"config-saved": "Config successfully saved.",
- "auth-failed": "Authentification failed: Locationid {{0}} Error: {{1}}"
+ "auth-failed": "[{{0}}] {{1}} Error: {{2}}"
}
diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php
index 578a773c..ede1ac37 100644
--- a/modules-available/locationinfo/page.inc.php
+++ b/modules-available/locationinfo/page.inc.php
@@ -29,6 +29,8 @@ class Page_LocationInfo extends Page
$this->deleteServer();
} elseif ($this->action === 'updateCredentials') {
$this->updateCredentials();
+ } elseif ($this->action === 'checkConnection') {
+ $this->checkConnection();
}
}
@@ -70,13 +72,13 @@ class Page_LocationInfo extends Page
ON DUPLICATE KEY UPDATE servername=:name, serverurl=:url, servertype=:type",
array('id' => $id, 'name' => Request::post('name', '', 'string'), 'url' => Request::post('url', '', 'string'), 'type' => Request::post('type', '', 'string')));
}
- Util::redirect('?do=locationinfo&action=infoscreen');
+
+ $this->checkConnection();
}
private function deleteServer() {
$id = Request::post('id', 0, 'int');
Database::exec("DELETE FROM `setting_location_info` WHERE serverid=:id", array('id' => $id));
- Util::redirect('?do=locationinfo&action=infoscreen');
}
private function updateConfig()
@@ -118,6 +120,7 @@ class Page_LocationInfo extends Page
$credentialsJson[$key] = Request::post($key);
}
Database::exec('UPDATE `setting_location_info` SET credentials = :credentials WHERE serverid = :id', array('id' => $serverid, 'credentials' => json_encode($credentialsJson, true)));
+ $this->checkConnection();
}
private function updateOpeningTimeExpert()
@@ -232,6 +235,27 @@ class Page_LocationInfo extends Page
Util::redirect('?do=locationinfo');
}
+ private function checkConnection() {
+ $serverid = Request::post('id', 0, 'int');
+
+ if ($serverid != 0) {
+ $dbresult = Database::queryFirst("SELECT * FROM `setting_location_info` WHERE serverid = :serverid", array('serverid' => $serverid));
+
+ $serverInstance = CourseBackend::getInstance($dbresult['servertype']);
+ $serverInstance->setCredentials(json_decode($dbresult['credentials'], true), $dbresult['serverurl'], $serverid);
+ //$setCred = $serverInstance->fetchSchedule(array(42));
+ $setCred = $serverInstance->checkConnection();
+
+ if (!$setCred) {
+ $error['timestamp'] = time();
+ $error['error'] = $serverInstance->getError();
+ Database::exec("UPDATE `setting_location_info` Set error=:error WHERE serverid=:id", array('id' => $serverid, 'error' => json_encode($error, true)));
+ } else {
+ Database::exec("UPDATE `setting_location_info` Set error=NULL WHERE serverid=:id", array('id' => $serverid));
+ }
+ }
+ }
+
protected function toggleHidden($id, $val) {
Database::exec("INSERT INTO `location_info` (locationid, hidden) VALUES (:id, :hidden) ON DUPLICATE KEY UPDATE hidden=:hidden", array('id' => $id, 'hidden' => $val));
@@ -345,16 +369,15 @@ class Page_LocationInfo extends Page
$server['id'] = $db['serverid'];
$server['name'] = $db['servername'];
- // Instance the backend and set the credentials to check if the Authentification is accepted.
- $backendType = CourseBackend::getInstance($db['servertype']);
- $backendType->setCredentials(json_decode($db['credentials'], true), $db['serverurl'], $db['serverid']);
-
- $connection = $backendType->checkConnection();
- if ($connection === true) {
+ if ($db['error'] == NULL) {
$server['auth'] = true;
} else {
$server['auth'] = false;
- Message::addError('auth-failed', $server['id'], $connection);
+ $error = json_decode($db['error'], true);
+
+ $time = date('Y/m/d H:i:s', $error['timestamp']);
+
+ Message::addError('auth-failed', $server['id'], $time, $error['error']);
}
$serverty = array();
diff --git a/modules-available/locationinfo/templates/credentials.html b/modules-available/locationinfo/templates/credentials.html
index 6933db75..70e96982 100644
--- a/modules-available/locationinfo/templates/credentials.html
+++ b/modules-available/locationinfo/templates/credentials.html
@@ -16,7 +16,7 @@
} else if("{{type}}" == "int") {
$("#div").before('<label>{{name}}</label><br><input required type="number" name="{{name}}" value="{{value}}" form="credentialsForm"><br><br>');
} else if("{{type}}" == "bool") {
- $("#div").before('<label>{{name}}</label><br><input required type="checkbox" name="{{name}}" value="{{value}}" form="credentialsForm"><br><br>');
+ $("#div").before('<label>{{name}}</label><br><input type="checkbox" name="{{name}}" value="{{value}}" form="credentialsForm"><br><br>');
} else if("{{type}}" == "array") {
$("#div").before('<label>{{name}}</label><br>\
<select name="{{name}}" form="credentialsForm">\
diff --git a/modules-available/locationinfo/templates/location-info.html b/modules-available/locationinfo/templates/location-info.html
index 65a7a0dc..16318615 100644
--- a/modules-available/locationinfo/templates/location-info.html
+++ b/modules-available/locationinfo/templates/location-info.html
@@ -11,7 +11,7 @@
<th width="90">{{lang_serverType}}</th>
<th>{{lang_locationName}}</th>
<th>{{lang_serverUrl}}</th>
- <th width="80" style="text-align: center;"></th>
+ <th width="130" style="text-align: center;"></th>
<th width="80" style="text-align: center;"></th>
</tr>
{{#serverlist}}
@@ -37,7 +37,8 @@
</td>
<td align="center" id="credentials-{{id}}" onclick="event.cancelBubble = true;">
- <button {{#auth}}class="btn btn-sm btn-success"{{/auth}}{{^auth}}class="btn btn-sm btn-danger"{{/auth}} id="credentials-btn-{{id}}" type="button" title="credentials" onclick="loadCredentialModal({{id}},'{{name}}');" id="credentials">{{lang_credentials}}</button>
+ <button {{#auth}}class="btn btn-sm btn-success"{{/auth}}{{^auth}}class="btn btn-sm btn-danger"{{/auth}} id="credentials-btn-{{id}}" type="button" title="credentials" onclick="loadCredentialModal({{id}},'{{name}}');">{{lang_credentials}}</button>
+ <button class="btn btn-sm btn-primary table-refresh" id="refresh-btn-{{id}}" title="refresh" onclick="refreshButtonClick({{id}});">&#8634</button>
</td>
<td align="center" id="btncell-{{id}}">
<button class="btn btn-sm btn-primary table-edit" title="{{lang_edit}}" onclick="editButtonClick({{id}});" id="edit">&#x270E</button>
@@ -208,16 +209,17 @@ function editButtonClick(id) {
<button class="btn btn-sm btn-danger" title="{{lang_cancel}}" onclick="cancelButtonClick(' + id + ');">&#10008</button>');
$('.table-edit').attr('disabled', true);
$('.table-delete').attr('disabled', true);
+ $('.table-refresh').attr('disabled', true);
$('#addServerButton').attr('disabled', true);
};
function saveButtonClick(id) {
- //$('#input-name-' + id).val($('#lname-' + id).text());
- //$('#input-url-' + id).val($('#lurl-' + id).text());
- //$('#input-user-' + id).val($('#luser-' + id).text());
- //$('#input-password-' + id).val($('#lpassword-' + id).text());
$('#serverFormAction-' + id).val("updateServer");
+ $('#submit-serverForm-' + id).trigger("click");
+};
+function refreshButtonClick(id) {
+ $('#serverFormAction-' + id).val("checkConnection");
$('#submit-serverForm-' + id).trigger("click");
};
@@ -257,6 +259,7 @@ function cancelButtonClick(id) {
<button class="btn btn-sm btn-danger table-delete" type="button" title="{{lang_delete}}" onclick="deleteButtonClick(' + id + ');">&#10008</button>');
$('.table-edit').attr('disabled', false);
$('.table-delete').attr('disabled', false);
+ $('.table-refresh').attr('disabled', false);
$('#addServerButton').attr('disabled', false);
}