summaryrefslogtreecommitdiffstats
path: root/modules-available
diff options
context:
space:
mode:
authorJannik Schönartz2017-02-27 07:53:38 +0100
committerJannik Schönartz2017-02-27 07:53:38 +0100
commit52406c0dd2017baed38df39a0574f1e8bbd549b8 (patch)
tree2335acef3bfb593d43e8eac28c5700b8c02646ed /modules-available
parentBugfixes (diff)
downloadslx-admin-52406c0dd2017baed38df39a0574f1e8bbd549b8.tar.gz
slx-admin-52406c0dd2017baed38df39a0574f1e8bbd549b8.tar.xz
slx-admin-52406c0dd2017baed38df39a0574f1e8bbd549b8.zip
Admin panel: New server GUI now using the backend types.
Diffstat (limited to 'modules-available')
-rw-r--r--modules-available/locationinfo/api.inc.php174
-rw-r--r--modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php37
-rw-r--r--modules-available/locationinfo/lang/de/template-tags.json3
-rw-r--r--modules-available/locationinfo/lang/en/template-tags.json3
-rw-r--r--modules-available/locationinfo/page.inc.php81
-rw-r--r--modules-available/locationinfo/templates/config.html2
-rw-r--r--modules-available/locationinfo/templates/credentials.html31
-rw-r--r--modules-available/locationinfo/templates/location-info.html24
8 files changed, 250 insertions, 105 deletions
diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php
index 8a8c01fd..c65746f9 100644
--- a/modules-available/locationinfo/api.inc.php
+++ b/modules-available/locationinfo/api.inc.php
@@ -27,12 +27,16 @@ function HandleParameters() {
} elseif ($getAction == "roomtree") {
$roomIDS = Request::get('ids', 0, 'string');
getRoomTree($roomIDS);
- } elseif ($getAction == "calendar") {
- $getRoomID = Request::get('id', 0, 'int');
- echo getCalendar($getRoomID);
- } elseif ($getAction == "calendars") {
- $roomIDS = Request::get('ids', 0, 'string');
- getCalendars($roomIDS);
+ //} elseif ($getAction == "calendar") {
+// $getRoomID = Request::get('id', 0, 'int');
+// echo getCalendar($getRoomID);
+// } elseif ($getAction == "calendars") {
+// $roomIDS = Request::get('ids', 0, 'string');
+// getCalendars($roomIDS);
+ } elseif ($getAction == "test") {
+ $roomIDs = Request::get('id', 0, 'string');
+ $array = getMultipleInformations($roomIDs);
+ getCalendar($array);
}
}
@@ -42,6 +46,56 @@ function getMultipleInformations($roomids) {
return $filteredIdList;
}
+// ########## <Calendar> ###########
+function getCalendar($idList) {
+
+ //// Build SQL query for multiple ids.
+ $query = "SELECT locationid, l.serverid, serverurl, s.servertype FROM `location_info` as l LEFT JOIN setting_location_info as s ON s.serverid WHERE locationid IN (";
+
+ $query .= implode(",", $idList);
+
+ $query .= ") AND l.serverid = s.serverid ORDER BY servertype ASC";
+
+ $dbquery = Database::simpleQuery($query);
+
+ while($dbresult=$dbquery->fetch(PDO::FETCH_ASSOC)) {
+
+ }
+ echo "TODO: Not implemented yet.";
+}
+// ########## </Calendar> ##########
+
+// ########################################################################
+function randomCalendarGenerator() {
+ $randNum = rand(3, 7);
+
+ $result = array();
+
+ for ($i = 0; $i < $randNum; $i++) {
+ $c = array();
+ $c['title'] = getRandomWord();
+
+ $randH = rand(8, 16);
+ $rand2 = $randH + 2;
+ $date = getdate();
+ $mday = $date['mday'] + $i;
+ $todays = $date['year'] . "-" . $date['month'] . "-" . $mday . " " . $randH . ":00:00";
+ $c['start'] = $todays;
+ $todaye = $date['year'] . "-" . $date['month'] . "-" . $mday . " " . $rand2 . ":00:00";
+ $c['end'] = $todaye;
+ $result[] = $c;
+ }
+
+ return json_encode($result);
+}
+
+function getRandomWord($len = 10) {
+ $word = array_merge(range('a', 'z'), range('A', 'Z'));
+ shuffle($word);
+ return substr(implode($word), 0, $len);
+}
+
+/*
// TODO FILTER 2 weeks or some days only
function getCalendars($ids) {
$idList = getMultipleInformations($ids);
@@ -55,6 +109,46 @@ function getCalendars($ids) {
echo json_encode($calendars);
}
+function getCalendar($getRoomID) {
+ // TODO GET AND RETURN THE ACTUAL calendar
+ //echo randomCalendarGenerator();
+
+ $dbquery = Database::simpleQuery("SELECT calendar, lastcalendarupdate, serverid, serverroomid FROM `location_info` WHERE locationid=:locationID", array('locationID' => $getRoomID));
+
+ $calendar;
+ $lastupdate;
+ $serverid;
+ $serverroomid;
+ while($dbresult=$dbquery->fetch(PDO::FETCH_ASSOC)) {
+ $lastupdate = (int) $dbresult['lastcalendarupdate'];
+ $calendar = $dbresult['calendar'];
+ $serverid = $dbresult['serverid'];
+ $serverroomid = $dbresult['serverroomid'];
+ }
+
+ $NOW = time();
+ if ($lastupdate == 0 || $NOW - $lastupdate > 900) {
+ return updateCalendar($getRoomID, $serverid, $serverroomid);
+ } else {
+ return $calendar;
+ }
+}
+
+function updateCalendar($locationid, $serverid, $serverroomid) {
+ // TODO CALL UpdateCalendar($serverid, $serverroomid);
+ $result = randomCalendarGenerator();
+ // ^ replace with the actual call
+
+ // Save in db and update timestamp
+ $NOW = time();
+ Database::exec("UPDATE `location_info` Set calendar=:calendar, lastcalendarupdate=:now WHERE locationid=:id", array('id' => $locationid, 'calendar' => $result, 'now' => $NOW));
+
+ return $result;
+}
+*/
+// ########################################################################
+
+
function getPcStates($idList) {
$pcStates = array();
@@ -123,72 +217,6 @@ function getChildsRecursive($id) {
return $array;
}
-function randomCalendarGenerator() {
- $randNum = rand(3, 7);
-
- $result = array();
-
- for ($i = 0; $i < $randNum; $i++) {
- $c = array();
- $c['title'] = getRandomWord();
-
- $randH = rand(8, 16);
- $rand2 = $randH + 2;
- $date = getdate();
- $mday = $date['mday'] + $i;
- $todays = $date['year'] . "-" . $date['month'] . "-" . $mday . " " . $randH . ":00:00";
- $c['start'] = $todays;
- $todaye = $date['year'] . "-" . $date['month'] . "-" . $mday . " " . $rand2 . ":00:00";
- $c['end'] = $todaye;
- $result[] = $c;
- }
-
- return json_encode($result);
-}
-
-function getRandomWord($len = 10) {
- $word = array_merge(range('a', 'z'), range('A', 'Z'));
- shuffle($word);
- return substr(implode($word), 0, $len);
-}
-
-function getCalendar($getRoomID) {
- // TODO GET AND RETURN THE ACTUAL calendar
- //echo randomCalendarGenerator();
-
- $dbquery = Database::simpleQuery("SELECT calendar, lastcalendarupdate, serverid, serverroomid FROM `location_info` WHERE locationid=:locationID", array('locationID' => $getRoomID));
-
- $calendar;
- $lastupdate;
- $serverid;
- $serverroomid;
- while($dbresult=$dbquery->fetch(PDO::FETCH_ASSOC)) {
- $lastupdate = (int) $dbresult['lastcalendarupdate'];
- $calendar = $dbresult['calendar'];
- $serverid = $dbresult['serverid'];
- $serverroomid = $dbresult['serverroomid'];
- }
-
- $NOW = time();
- if ($lastupdate == 0 || $NOW - $lastupdate > 900) {
- return updateCalendar($getRoomID, $serverid, $serverroomid);
- } else {
- return $calendar;
- }
-}
-
-function updateCalendar($locationid, $serverid, $serverroomid) {
- // TODO CALL UpdateCalendar($serverid, $serverroomid);
- $result = randomCalendarGenerator();
- // ^ replace with the actual call
-
- // Save in db and update timestamp
- $NOW = time();
- Database::exec("UPDATE `location_info` Set calendar=:calendar, lastcalendarupdate=:now WHERE locationid=:id", array('id' => $locationid, 'calendar' => $result, 'now' => $NOW));
-
- return $result;
-}
-
function getConfig($locationID) {
$dbquery = Database::simpleQuery("SELECT l.locationname, li.config, li.serverroomid, s.servertype, s.serverurl FROM `location_info` AS li
RIGHT JOIN `location` AS l ON l.locationid=li.locationid
@@ -287,7 +315,7 @@ function getRoomInfo($idList, $coords) {
return json_encode($dbresult, true);
}
-// ########## </Roominfo> ##########
+// ########## </Roominfo> ###########
// ########## <Openingtime> ##########
diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php
new file mode 100644
index 00000000..6fa4f32f
--- /dev/null
+++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php
@@ -0,0 +1,37 @@
+<?php
+class Coursebackend_Dummy extends CourseBackend {
+
+ private $location;
+ public $serverID;
+
+ function __construct($location, $serverID) {
+
+ }
+
+ public function setCredentials($json,$location,$serverID) {
+ }
+
+ public function getCredentials(){
+ $options = ["opt1", "opt2", "opt3", "opt4", "opt5", "opt6", "opt7", "opt8"];
+ $credentials = ["username" => "string","password"=>"string","option"=>$options];
+ return $credentials;
+ }
+
+ public function getDisplayName(){
+ return'Dummy with array';
+ }
+
+ public function getCacheTime(){
+ return 0;
+ }
+
+ public function getRefreshTime(){
+ return 0;
+ }
+
+ public function fetchSchedulesInternal($roomId){
+
+ }
+
+}
+?>
diff --git a/modules-available/locationinfo/lang/de/template-tags.json b/modules-available/locationinfo/lang/de/template-tags.json
index d43ab0f4..f7094cee 100644
--- a/modules-available/locationinfo/lang/de/template-tags.json
+++ b/modules-available/locationinfo/lang/de/template-tags.json
@@ -74,5 +74,6 @@
"lang_serverID": "Server ID",
"lang_sID": "sID",
"lang_server": "Server",
- "lang_serverRoomId": "Server: Raum ID"
+ "lang_serverRoomId": "Server: Raum ID",
+ "lang_credentials": "Anmeldeinformationen"
}
diff --git a/modules-available/locationinfo/lang/en/template-tags.json b/modules-available/locationinfo/lang/en/template-tags.json
index 9efeb2c4..3b3a9e56 100644
--- a/modules-available/locationinfo/lang/en/template-tags.json
+++ b/modules-available/locationinfo/lang/en/template-tags.json
@@ -74,5 +74,6 @@
"lang_serverID": "Server ID",
"lang_sID": "sID",
"lang_server": "Server",
- "lang_serverRoomId": "Server: Room ID"
+ "lang_serverRoomId": "Server: Room ID",
+ "lang_credentials": "Credentials"
}
diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php
index 7dae0762..6a9fae42 100644
--- a/modules-available/locationinfo/page.inc.php
+++ b/modules-available/locationinfo/page.inc.php
@@ -27,6 +27,8 @@ class Page_LocationInfo extends Page
$this->updateServer();
} elseif ($this->action === 'deleteServer') {
$this->deleteServer();
+ } elseif ($this->action === 'updateCredentials') {
+ $this->updateCredentials();
}
}
@@ -105,6 +107,19 @@ class Page_LocationInfo extends Page
Util::redirect('?do=locationinfo');
}
+ private function updateCredentials() {
+ $serverid = Request::post('id', 0, 'int');
+ $dbresult = Database::queryFirst('SELECT servertype FROM `setting_location_info` WHERE serverid = :id', array('id' => $serverid));
+ $backend = CourseBackend::getInstance($dbresult['servertype']);
+ $tmptypeArray = $backend->getCredentials();
+
+ $credentialsJson = array();
+ foreach ($tmptypeArray as $key => $value) {
+ $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)));
+ }
+
private function updateOpeningTimeExpert()
{
$days = Request::post('days');
@@ -311,12 +326,13 @@ class Page_LocationInfo extends Page
}
$servertypes = array();
- $type['type'] = "HISinOne";
- $servertypes[] = $type;
- $type['type'] = "DAVINCI";
- $servertypes[] = $type;
- $type['type'] = "Frontend";
- $servertypes[] = $type;
+ $s_list = CourseBackend::getList();
+ foreach ($s_list as $s) {
+ $type['type'] = $s;
+ $typeInstance = CourseBackend::getInstance($s);
+ $type['display'] = $typeInstance->getDisplayName();
+ $servertypes[] = $type;
+ }
$serverlist = array();
$dbquery2 = Database::simpleQuery("SELECT * FROM `setting_location_info`");
@@ -329,6 +345,7 @@ class Page_LocationInfo extends Page
$st = array();
if ($type['type'] == $db['servertype']) {
$st['type'] = $type['type'];
+ $st['display'] = $type['display'];
$st['active'] = true;
} else {
$st['type'] = $type['type'];
@@ -337,18 +354,8 @@ class Page_LocationInfo extends Page
$serverty[] = $st;
}
$server['types'] = $serverty;
-/*
- if ($db['servertype'] == 'HISinOne') {
- $server['HISinOne'] = true;
- $server['DAVINCI'] = false;
- } elseif ($db['servertype'] == 'DAVINCI') {
- $server['HISinOne'] = false;
- $server['DAVINCI'] = true;
- }
-*/
+
$server['url'] = $db['serverurl'];
- $server['user'] = "TODO: Auth";
- $server['password'] = "Needs a change to Auth";
$serverlist[] = $server;
}
@@ -376,6 +383,9 @@ class Page_LocationInfo extends Page
} elseif ($action === 'config') {
$id = Request::any('id', 0, 'int');
$this->ajaxConfig($id);
+ } elseif ($action === 'credentials') {
+ $id = Request::any('id', 0, 'int');
+ $this->ajaxCredentials($id);
}
}
@@ -404,6 +414,43 @@ class Page_LocationInfo extends Page
));
}
+ private function ajaxCredentials($id) {
+ $dbresult = Database::queryFirst('SELECT servertype, credentials FROM `setting_location_info` WHERE serverid = :id', array('id' => $id));
+ $tmpcredentialArray = json_decode($dbresult['credentials'], true);
+ $backend = CourseBackend::getInstance($dbresult['servertype']);
+ $tmptypeArray = $backend->getCredentials();
+ $credentialsArray = array();
+ foreach ($tmptypeArray as $key => $value) {
+ $x['name'] = $key;
+
+ foreach ($tmpcredentialArray as $ke => $val) {
+ if($ke == $key) {
+ $x['value'] = $val;
+ break;
+ }
+ }
+ $x['type'] = $value;
+
+ if (is_array($value)) {
+ $selection = array();
+ foreach ($value as $opt) {
+ $option['option'] = $opt;
+ if ($opt == $x['value']) {
+ $option['active'] = true;
+ } else {
+ $option['active'] = false;
+ }
+ $selection[] = $option;
+ }
+ $x['type'] = "array";
+ $x['array'] = $selection;
+ }
+ $credentialsArray[] = $x;
+ }
+
+ echo Render::parse('credentials', array('id' => $id, 'credentials' => array_values($credentialsArray)));
+ }
+
private function ajaxTimeTable($id) {
$array = array();
$dbquery = Database::simpleQuery("SELECT openingtime FROM `location_info` WHERE locationid = :id", array('id' => $id));
diff --git a/modules-available/locationinfo/templates/config.html b/modules-available/locationinfo/templates/config.html
index 1cbcbe31..778b5c55 100644
--- a/modules-available/locationinfo/templates/config.html
+++ b/modules-available/locationinfo/templates/config.html
@@ -1,6 +1,4 @@
<div>
-
-
<form method="post" action="?do=locationinfo" id="configForm">
<input type="hidden" name="token" value="{{token}}">
<input type="hidden" name="action" value="updateConfig">
diff --git a/modules-available/locationinfo/templates/credentials.html b/modules-available/locationinfo/templates/credentials.html
new file mode 100644
index 00000000..6933db75
--- /dev/null
+++ b/modules-available/locationinfo/templates/credentials.html
@@ -0,0 +1,31 @@
+<div>
+ <form method="post" action="?do=locationinfo" id="credentialsForm">
+ <input type="hidden" name="token" value="{{token}}">
+ <input type="hidden" name="action" value="updateCredentials">
+ <input type="hidden" name="id" value="{{id}}">
+ <div id="div"></div>
+ <button type="submit" class="btn btn-primary">{{lang_save}}</button>
+ </form>
+</div>
+<script type="text/javascript">
+
+// {{name}} name of auth {{type}} type of auth (string, int etc.) {{value}} value from the db
+{{#credentials}}
+ if("{{type}}" == "string") {
+ $("#div").before('<label>{{name}}</label><br><input required type="text" name="{{name}}" value="{{value}}" form="credentialsForm"><br><br>');
+ } 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>');
+ } else if("{{type}}" == "array") {
+ $("#div").before('<label>{{name}}</label><br>\
+ <select name="{{name}}" form="credentialsForm">\
+ {{#array}}\
+ <option value="{{option}}" {{#active}}selected{{/active}}>{{option}}</option>\
+ {{/array}}\
+ </select>\
+ <br><br>');
+ }
+{{/credentials}}
+
+</script>
diff --git a/modules-available/locationinfo/templates/location-info.html b/modules-available/locationinfo/templates/location-info.html
index 82b0ad15..f10831e3 100644
--- a/modules-available/locationinfo/templates/location-info.html
+++ b/modules-available/locationinfo/templates/location-info.html
@@ -11,8 +11,7 @@
<th width="90">{{lang_serverType}}</th>
<th>{{lang_locationName}}</th>
<th>{{lang_serverUrl}}</th>
- <th>{{lang_serverUser}}</th>
- <th>{{lang_serverPassword}}</th>
+ <th width="80" style="text-align: center;"></th>
<th width="80" style="text-align: center;"></th>
</tr>
{{#serverlist}}
@@ -26,7 +25,7 @@
<td id="type-{{id}}">
<select disabled id="input-type-{{id}}" name="type" value="{{type}}" onchange="servertype_changed(this.value, {{id}});">
{{#types}}
- <option id="{{type}}" value="{{type}}" {{#active}}selected{{/active}} >{{type}}
+ <option id="{{type}}" value="{{type}}" {{#active}}selected{{/active}} >{{display}}
{{/types}}
</select>
</td>
@@ -36,11 +35,9 @@
<td id="url-{{id}}" style="padding:8px;">
<input readonly required id="input-url-{{id}}" name="url" type="text" value="{{url}}" style="padding:0;height:100%;width:100%;"></input>
</td>
- <td id="user-{{id}}" style="padding:8px;">
- <input readonly required id="input-user-{{id}}" name="user" type="text" value="{{user}}" style="padding:0;height:100%;width:100%;"></input>
- </td>
- <td id="password-{{id}}" style="padding:8px;">
- <input readonly required id="input-password-{{id}}" name="password" type="text" value="{{password}}" style="padding:0;height:100%;width:100%;"></input>
+
+ <td align="center" id="credentials-{{id}}" onclick="event.cancelBubble = true;">
+ <button class="btn btn-sm btn-primary" type="button" title="credentials" onclick="loadCredentialModal({{id}},'{{name}}');" id="credentials">{{lang_credentials}}</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>
@@ -134,6 +131,13 @@ function cbClick(cb, locID) {
window.location.href = "?do=locationinfo&action=hide&id=" + locID + "&value=" + value;
}
+function loadCredentialModal(serverid, servername) {
+ $('#myModalHeader').text("[" + serverid + "] " + servername).css("font-weight","Bold");
+
+ $('#myModal').modal('show');
+ $('#myModalBody').load("?do=locationinfo&action=credentials&id=" + serverid);
+}
+
function loadTimeModal(locationId, locationName) {
$('#myModalHeader').text("[" + locationId + "] " + locationName).css("font-weight","Bold");
@@ -268,12 +272,10 @@ function addNewServerRow() {
$('#lastServerTableElement').before('<tr class=tablerow id="new">\
<td align="center"><input id="input-id-0" name="id" type="hidden" form="serverForm-0" value="0"></td>\
<td id="type-0"><select id="input-type-0" name="type" form="serverForm-0" onchange="servertype_changed(this.value, 0)">\
- {{#servertypelist}}<option value="{{type}}"> {{type}}{{/servertypelist}}\
+ {{#servertypelist}}<option value="{{type}}"> {{display}}{{/servertypelist}}\
</select></td>\
<td id="name-0" style="padding:0;"><input required id="input-name-0" name="name" type="text" form="serverForm-0" value="" style="padding:0;height:100%;width:100%;"></input></td>\
<td id="url-0" style="padding:0;"><a><input required id="input-url-0" name="url" type="text" form="serverForm-0" value="" style="padding:0;height:100%;width:100%;"></input></a></td>\
- <td id="user-0" style="padding:0;"><input required id="input-user-0" name="user" type="text" form="serverForm-0" value="" style="padding:0;height:100%;width:100%;"></input></td>\
- <td id="password-0" style="padding:0;"><input required id="input-password-0" name="password" type="text" form="serverForm-0" value="" style="padding:0;height:100%;width:100%;"></input></td>\
<td align="center" id="btncell-new">\
<button class="btn btn-sm btn-success" title="{{lang_save}}" onclick="addNewServer();">&#10004</button> \
<button class="btn btn-sm btn-danger" title="{{lang_cancel}}" onclick="deleteNewServer();">&#10008</button>\