From 52406c0dd2017baed38df39a0574f1e8bbd549b8 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Mon, 27 Feb 2017 07:53:38 +0100 Subject: Admin panel: New server GUI now using the backend types. --- modules-available/locationinfo/api.inc.php | 174 ++++++++++++--------- .../inc/coursebackend/coursebackend_dummy.inc.php | 37 +++++ .../locationinfo/lang/de/template-tags.json | 3 +- .../locationinfo/lang/en/template-tags.json | 3 +- modules-available/locationinfo/page.inc.php | 81 ++++++++-- .../locationinfo/templates/config.html | 2 - .../locationinfo/templates/credentials.html | 31 ++++ .../locationinfo/templates/location-info.html | 24 +-- 8 files changed, 250 insertions(+), 105 deletions(-) create mode 100644 modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php create mode 100644 modules-available/locationinfo/templates/credentials.html (limited to 'modules-available') 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; } +// ########## ########### +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."; +} +// ########## ########## + +// ######################################################################## +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); } -// ########## ########## +// ########## ########### // ########## ########## 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 @@ + "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 @@
- -
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 @@ +
+ + + + +
+ + +
+ 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 @@ {{lang_serverType}} {{lang_locationName}} {{lang_serverUrl}} - {{lang_serverUser}} - {{lang_serverPassword}} + {{#serverlist}} @@ -26,7 +25,7 @@ @@ -36,11 +35,9 @@ - - - - - + + + @@ -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('\ \ \ \ \ - \ - \ \ \ \ -- cgit v1.2.3-55-g7522