summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/inc
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/locationinfo/inc')
-rw-r--r--modules-available/locationinfo/inc/coursebackend.inc.php74
-rw-r--r--modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php3
-rw-r--r--modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php17
-rw-r--r--modules-available/locationinfo/inc/infopanel.inc.php28
-rw-r--r--modules-available/locationinfo/inc/locationinfo.inc.php7
5 files changed, 95 insertions, 34 deletions
diff --git a/modules-available/locationinfo/inc/coursebackend.inc.php b/modules-available/locationinfo/inc/coursebackend.inc.php
index 1fe87202..7162c885 100644
--- a/modules-available/locationinfo/inc/coursebackend.inc.php
+++ b/modules-available/locationinfo/inc/coursebackend.inc.php
@@ -47,17 +47,20 @@ abstract class CourseBackend
foreach (glob(dirname(__FILE__) . '/coursebackend/coursebackend_*.inc.php', GLOB_NOSORT) as $file) {
require_once $file;
preg_match('#coursebackend_([^/\.]+)\.inc\.php$#i', $file, $out);
- if (!class_exists('coursebackend_' . $out[1])) {
- trigger_error("Backend type source unit $file doesn't seem to define class CourseBackend_{$out[1]}", E_USER_ERROR);
+ $className = 'CourseBackend_' . $out[1];
+ if (!class_exists($className)) {
+ trigger_error("Backend type source unit $file doesn't seem to define class $className", E_USER_ERROR);
}
+ if (!CONFIG_DEBUG && defined("$className::DEBUG") && constant("$className::DEBUG"))
+ continue;
self::$backendTypes[$out[1]] = true;
}
}
/**
- * Get all known config module types.
+ * Get all known backend types.
*
- * @return array list of modules
+ * @return array list of backends
*/
public static function getList()
{
@@ -65,24 +68,30 @@ abstract class CourseBackend
return array_keys(self::$backendTypes);
}
+ public static function exists($backendType)
+ {
+ self::loadDb();
+ return isset(self::$backendTypes[$backendType]);
+ }
+
/**
- * Get fresh instance of ConfigModule subclass for given module type.
+ * Get fresh instance of CourseBackend subclass for given backend type.
*
- * @param string $moduleType name of module type
- * @return \CourseBackend module instance
+ * @param string $backendType name of module type
+ * @return \CourseBackend|false module instance
*/
- public static function getInstance($moduleType)
+ public static function getInstance($backendType)
{
self::loadDb();
- if (!isset(self::$backendTypes[$moduleType])) {
- error_log('Unknown module type: ' . $moduleType);
+ if (!isset(self::$backendTypes[$backendType])) {
+ error_log('Unknown module type: ' . $backendType);
return false;
}
- if (!is_object(self::$backendTypes[$moduleType])) {
- $class = "coursebackend_$moduleType";
- self::$backendTypes[$moduleType] = new $class;
+ if (!is_object(self::$backendTypes[$backendType])) {
+ $class = "coursebackend_$backendType";
+ self::$backendTypes[$backendType] = new $class;
}
- return self::$backendTypes[$moduleType];
+ return self::$backendTypes[$backendType];
}
/**
@@ -131,6 +140,19 @@ abstract class CourseBackend
*/
protected abstract function fetchSchedulesInternal($roomId);
+ private static function fixTime(&$start, &$end)
+ {
+ if (!preg_match('/^\d+-\d+-\d+T\d+:\d+:\d+$/', $start) || !preg_match('/^\d+-\d+-\d+T\d+:\d+:\d+$/', $start))
+ return false;
+ $start = strtotime($start);
+ $end = strtotime($end);
+ if ($start >= $end)
+ return false;
+ $start = date('Y-m-d\TH:i:s', $start);
+ $end = date('Y-m-d\TH:i:s', $end);
+ return true;
+ }
+
/**
* Method for fetching the schedule of the given rooms on a server.
*
@@ -184,18 +206,31 @@ abstract class CourseBackend
return false;
}
- if ($this->getCacheTime() > 0) {
- // Caching requested by backend, write to DB
- foreach ($backendResponse as $serverRoomId => $calendar) {
+ foreach ($backendResponse as $serverRoomId => &$calendar) {
+ $calendar = array_values($calendar);
+ for ($i = 0; $i < count($calendar); ++$i) {
+ if (empty($calendar[$i]['title'])) {
+ $calendar[$i]['title'] = '-';
+ }
+ if (!self::fixTime($calendar[$i]['start'], $calendar[$i]['end'])) {
+ error_log("Ignoring calendar entry '{$calendar[$i]['title']}' with bad time format");
+ unset($calendar[$i]);
+ }
+ }
+ $calendar = array_values($calendar);
+ if ($this->getCacheTime() > 0) {
+ // Caching requested by backend, write to DB
$value = json_encode($calendar);
Database::simpleQuery("UPDATE locationinfo_locationconfig SET calendar = :ttable, lastcalendarupdate = :now
- WHERE serverid = :serverid AND serverlocationid = :serverlocationid", array(
+ WHERE serverid = :serverid AND serverlocationid = :serverlocationid", array(
'serverid' => $this->serverId,
'serverlocationid' => $serverRoomId,
'ttable' => $value,
'now' => $NOW
));
}
+
+ unset($calendar);
}
// Add rooms that were requested to the final return value
foreach ($remoteIds as $location => $serverRoomId) {
@@ -302,6 +337,9 @@ abstract class CourseBackend
$xml = new SimpleXMLElement($cleanresponse);
} catch (Exception $e) {
$this->error = 'Could not parse reply as XML, got ' . get_class($e) . ': ' . $e->getMessage();
+ if (CONFIG_DEBUG) {
+ error_log($cleanresponse);
+ }
return false;
}
$array = json_decode(json_encode((array)$xml), true);
diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php
index fac3f296..8843e372 100644
--- a/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php
+++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php
@@ -106,6 +106,9 @@ class CourseBackend_Davinci extends CourseBackend
}
$return = $this->xmlStringToArray($return);
if ($return === false) {
+ if (CONFIG_DEBUG) {
+ error_log('Room was ' . $roomId);
+ }
continue;
}
$lessons = $this->getArrayPath($return, '/Lessons/Lesson');
diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php
index e2577284..adff8b1b 100644
--- a/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php
+++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php
@@ -4,6 +4,8 @@ class CourseBackend_Dummy extends CourseBackend
{
private $pw;
+ const DEBUG = true;
+
/**
* uses json to setCredentials, the json must follow the form given in
* getCredentials
@@ -87,13 +89,24 @@ class CourseBackend_Dummy extends CourseBackend
*
* @param $roomIds array with local ID as key and serverId as value
* @return array a recursive array that uses the roomID as key
- * and has the schedule array as value. A shedule array contains an array in this format:
- * ["start"=>'JJJJ-MM-DD HH:MM:SS',"end"=>'JJJJ-MM-DD HH:MM:SS',"title"=>string]
+ * and has the schedule array as value. A schedule array contains an array in this format:
+ * ["start"=>'YYYY-MM-DD<T>HH:MM:SS',"end"=>'YYYY-MM-DD<T>HH:MM:SS',"title"=>string]
*/
public function fetchSchedulesInternal($roomId)
{
$a = array();
foreach ($roomId as $id) {
+ if ($id == 1) {
+ $now = time();
+ return array($id => array(
+ array(
+ 'title' => 'Lange',
+ 'start' => date('Y-m-d', $now) . 'T0:00:00',
+ 'end' => date('Y-m-d', $now + 86400 * 3) . 'T0:00:00',
+ )
+ ));
+ }
+ // Normal
$x = array();
$time = strtotime('today');
$end = strtotime('+7 days', $time);
diff --git a/modules-available/locationinfo/inc/infopanel.inc.php b/modules-available/locationinfo/inc/infopanel.inc.php
index 94f264bb..12b6aec7 100644
--- a/modules-available/locationinfo/inc/infopanel.inc.php
+++ b/modules-available/locationinfo/inc/infopanel.inc.php
@@ -45,17 +45,27 @@ class InfoPanel
}
$config['locations'] = array();
$lids = array_map('intval', explode(',', $panel['locationids']));
- foreach ($lids as $lid) {
- $config['locations'][$lid] = array(
- 'id' => $lid,
- 'name' => isset($locations[$lid]) ? $locations[$lid]['locationname'] : 'noname00.pas',
- );
- // Now apply any overrides from above
- if (isset($overrides[$lid]) && is_array($overrides[$lid])) {
- $config['locations'][$lid]['config'] = $overrides[$lid];
+ // Locations -
+ if ($panel['paneltype'] === 'SUMMARY') {
+ $lids = Location::getRecursiveFlat($lids);
+ $lids = array_keys($lids);
+ foreach ($lids as $lid) {
+ $config['locations'][$lid] = array('id' => $lid);
+ }
+ }
+ if ($panel['paneltype'] === 'DEFAULT') {
+ foreach ($lids as $lid) {
+ $config['locations'][$lid] = array(
+ 'id' => $lid,
+ 'name' => isset($locations[$lid]) ? $locations[$lid]['locationname'] : 'noname00.pas',
+ );
+ // Now apply any overrides from above
+ if (isset($overrides[$lid]) && is_array($overrides[$lid])) {
+ $config['locations'][$lid]['config'] = $overrides[$lid];
+ }
}
+ self::appendMachineData($config['locations'], $lids, true);
}
- self::appendMachineData($config['locations'], $lids, true);
self::appendOpeningTimes($config['locations'], $lids);
$config['ts'] = (int)$panel['lastchange'];
diff --git a/modules-available/locationinfo/inc/locationinfo.inc.php b/modules-available/locationinfo/inc/locationinfo.inc.php
index 64070cd4..2ed3622d 100644
--- a/modules-available/locationinfo/inc/locationinfo.inc.php
+++ b/modules-available/locationinfo/inc/locationinfo.inc.php
@@ -36,11 +36,7 @@ class LocationInfo
$idArray = array_map('intval', explode(',', $panel['locationids']));
if ($panel['paneltype'] == "SUMMARY" && $recursive) {
$idList = Location::getRecursiveFlat($idArray);
- $idArray = array();
-
- foreach ($idList as $key => $value) {
- $idArray[] = $key;
- }
+ $idArray = array_keys($idList);
}
return $idArray;
}
@@ -143,6 +139,7 @@ class LocationInfo
ConfigHolder::add('SLX_SCREEN_STANDBY_TIMEOUT', '', 1000);
ConfigHolder::add('SLX_SYSTEM_STANDBY_TIMEOUT', '', 1000);
ConfigHolder::add('SLX_AUTOLOGIN', '1', 1000);
+ ConfigHolder::add('SLX_BROWSER_INSECURE', '1'); // TODO: Sat server might redirect to HTTPS, which in turn could have a self-signed cert - push to client
}
}