From aa86e073b0111e61b1ba9a080604d945381ccb6a Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 12 Apr 2017 14:04:56 +0200 Subject: [locationinfo] Format php files --- modules-available/locationinfo/api.inc.php | 29 ++- .../locationinfo/inc/coursebackend.inc.php | 22 +- .../coursebackend/coursebackend_davinci.inc.php | 4 +- .../inc/coursebackend/coursebackend_dummy.inc.php | 129 +++++++----- .../coursebackend/coursebackend_hisinone.inc.php | 31 ++- modules-available/locationinfo/page.inc.php | 222 +++++++++++++-------- 6 files changed, 268 insertions(+), 169 deletions(-) diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php index f3b99e45..4792a103 100644 --- a/modules-available/locationinfo/api.inc.php +++ b/modules-available/locationinfo/api.inc.php @@ -315,11 +315,12 @@ function getConfig($locationID) } /** - * Creates and returns a default config for room that didn't saved a config yet. - * - * @return Return a default config. - */ -function defaultConfig(&$config) { + * Creates and returns a default config for room that didn't saved a config yet. + * + * @return Return a default config. + */ +function defaultConfig(&$config) +{ $config['language'] = 'en'; $config['mode'] = 1; $config['vertical'] = false; @@ -445,7 +446,10 @@ function getCalendar($idList) if (!empty($idList)) { // Build SQL query for multiple ids. - $query = "SELECT locationid, l.serverid AS serverid, serverurl, servertype, credentials FROM `location_info` AS l LEFT JOIN setting_location_info AS s ON s.serverid = l.serverid WHERE locationid IN ("; + $query = "SELECT locationid, l.serverid AS serverid, serverurl, servertype, credentials + FROM `location_info` AS l + LEFT JOIN setting_location_info AS s ON (s.serverid = l.serverid) + WHERE locationid IN ("; $query .= implode(",", $idList); @@ -457,7 +461,12 @@ function getCalendar($idList) $lastservertype = ""; while ($dbresult = $dbquery->fetch(PDO::FETCH_ASSOC)) { if (!isset($serverList[$dbresult['serverid']])) { - $serverList[$dbresult['serverid']] = array('credentials' => json_decode($dbresult['credentials'], true), 'url' => $dbresult['serverurl'], 'type' => $dbresult['servertype'], 'idlist' => array()); + $serverList[$dbresult['serverid']] = array( + 'credentials' => json_decode($dbresult['credentials'], true), + 'url' => $dbresult['serverurl'], + 'type' => $dbresult['servertype'], + 'idlist' => array() + ); } $serverList[$dbresult['serverid']]['idlist'][] = $dbresult['locationid']; } @@ -477,9 +486,11 @@ function getCalendar($idList) 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))); + 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)); + Database::exec("UPDATE `setting_location_info` SET error=NULL WHERE serverid=:id", + array('id' => $serverid)); } if (is_array($calendarFromBackend)) { foreach ($calendarFromBackend as $key => $value) { diff --git a/modules-available/locationinfo/inc/coursebackend.inc.php b/modules-available/locationinfo/inc/coursebackend.inc.php index e14e9443..11d833e6 100644 --- a/modules-available/locationinfo/inc/coursebackend.inc.php +++ b/modules-available/locationinfo/inc/coursebackend.inc.php @@ -140,7 +140,7 @@ abstract class CourseBackend */ public final function fetchSchedule($roomIDs) { - if(empty($roomIDs)){ + if (empty($roomIDs)) { $this->error = true; $this->errormsg = 'No roomid was given to fetch Shedule'; return false; @@ -171,15 +171,17 @@ abstract class CourseBackend foreach ($dbquery4->fetchAll(PDO::FETCH_COLUMN) as $row) { if (isset($row['lastcalendarupdate'])) { $lastUpdate = $row['lastcalendarupdate']; - if ($lastUpdate < strtotime("-" . $this->getRefreshTime() . "seconds") && $lastUpdate > strtotime("-" . $this->getCacheTime() . "seconds"&& $igetRefreshTime() . "seconds") + && $lastUpdate > strtotime("-" . $this->getCacheTime() . "seconds" + && $i < self::nrOtherRooms)) { $sRoomIDs[$row['locationid']] = $row['serverroomid']; - $i = $i +1; + $i = $i + 1; } } } } //This is true if there is no need to check the HisInOne Server - if(empty($sRoomIDs)){ + if (empty($sRoomIDs)) { return $result; } $results = $this->fetchSchedulesInternal($sRoomIDs); @@ -195,12 +197,17 @@ abstract class CourseBackend foreach ($newResult as $key => $value) { $value = json_encode($value); $now = strtotime('Now'); - Database::simpleQuery("UPDATE location_info SET calendar = :ttable, lastcalendarupdate = :now WHERE locationid = :id ", array('id' => $key, 'ttable' => $value, 'now' => $now)); + Database::simpleQuery("UPDATE location_info SET calendar = :ttable, lastcalendarupdate = :now + WHERE locationid = :id ", array( + 'id' => $key, + 'ttable' => $value, + 'now' => $now + )); } } //get all schedules that are wanted from roomIDs foreach ($roomIDs as $id) { - if(isset($newResult[$id])){ + if (isset($newResult[$id])) { $result[$id] = $newResult[$id]; } } @@ -217,6 +224,7 @@ abstract class CourseBackend } return false; } + /** * Query path in array-representation of XML document. * e.g. 'path/syntax/foo/wanteditem' @@ -262,7 +270,7 @@ abstract class CourseBackend $return = []; foreach ($array[$element] as $item) { $test = $this->getAttributes($item, $path); - If(gettype($test) == "array" ){ + If (gettype($test) == "array") { $return = array_merge($return, $test); } diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php index 3a2e4e0c..2d53e762 100644 --- a/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php +++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php @@ -89,7 +89,7 @@ class Coursebackend_Davinci extends CourseBackend $output = curl_exec($ch); if ($output === false) { $this->error = true; - $this->errormsg = 'Curl error: ' . curl_error($ch).$url; + $this->errormsg = 'Curl error: ' . curl_error($ch) . $url; return false; } else { $this->error = false; @@ -109,7 +109,7 @@ class Coursebackend_Davinci extends CourseBackend if ($return === false) { return false; } - $lessons = $this->getAttributes($return,'Lessons/Lesson'); + $lessons = $this->getAttributes($return, 'Lessons/Lesson'); if (!$lessons) { $this->error = true; $this->errormsg = "url send a xml in a wrong format"; diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php index 482ca097..484a5286 100644 --- a/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php +++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_dummy.inc.php @@ -1,6 +1,8 @@ pw = $x['password']; + 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; - } - } + if ($this->pw === "mfg") { + $this->error = false; + return true; + } else { + $this->errormsg = "USE mfg as password!"; + $this->error = true; + return false; + } + } /** * @return boolean true if the connection works, false otherwise */ - public function checkConnection(){ - if ($this->pw == "mfg") { - $this->error = false; - return true; - } else { - $this->errormsg = "USE mfg as password!"; - $this->error = true; - return false; - } - } + public function checkConnection() + { + if ($this->pw == "mfg") { + $this->error = false; + return true; + } else { + $this->errormsg = "USE mfg as password!"; + $this->error = true; + return false; + } + } /** * @returns array with parameter name as key and and an array with type, help text and mask as value */ - public function getCredentials(){ - $options = ["opt1", "opt2", "opt3", "opt4", "opt5", "opt6", "opt7", "opt8"]; - $credentials = ["username" => "string","password"=>"password","integer"=>"int","option"=>$options,"CheckTheBox" =>"bool","CB2 t" =>"bool"]; - return $credentials; - } + public function getCredentials() + { + $options = ["opt1", "opt2", "opt3", "opt4", "opt5", "opt6", "opt7", "opt8"]; + $credentials = [ + "username" => "string", + "password" => "password", + "integer" => "int", + "option" => $options, + "CheckTheBox" => "bool", + "CB2 t" => "bool" + ]; + return $credentials; + } /** * @return string return display name of backend */ - public function getDisplayName(){ - return'Dummy with array'; - } + public function getDisplayName() + { + return 'Dummy with array'; + } + /** * @return int desired caching time of results, in seconds. 0 = no caching */ - public function getCacheTime(){ - return 0; - } + public function getCacheTime() + { + return 0; + } + /** - * @return int age after which timetables are no longer refreshed should be - * greater then CacheTime - */ - public function getRefreshTime(){ - return 0; - } + * @return int age after which timetables are no longer refreshed should be + * greater then CacheTime + */ + public function getRefreshTime() + { + return 0; + } /** * Internal version of fetch, to be overridden by subclasses. @@ -76,22 +93,24 @@ class Coursebackend_Dummy extends CourseBackend { * 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] */ - public function fetchSchedulesInternal($roomId){ - $a = array(); - foreach ($roomId as $id) { - $x['id'] = $id; - $calendar['title'] = "test exam"; - $calendar['start'] = "2017-3-08 13:00:00"; - $calendar['end'] = "2017-3-08 16:00:00"; - $calarray = array(); - $calarray[] = $calendar; - $x['calendar'] = $calarray; - $a[$id] = $calarray; - } + public function fetchSchedulesInternal($roomId) + { + $a = array(); + foreach ($roomId as $id) { + $x['id'] = $id; + $calendar['title'] = "test exam"; + $calendar['start'] = "2017-3-08 13:00:00"; + $calendar['end'] = "2017-3-08 16:00:00"; + $calarray = array(); + $calarray[] = $calendar; + $x['calendar'] = $calarray; + $a[$id] = $calarray; + } - return $a; - } + return $a; + } } + ?> diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php index ee79cec9..0e7c5328 100644 --- a/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php +++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_hisinone.inc.php @@ -31,7 +31,6 @@ class CourseBackend_HisInOne extends CourseBackend return false; } - return true; } @@ -79,7 +78,7 @@ class CourseBackend_HisInOne extends CourseBackend $body->appendChild($findUnit); $termYearN = $doc->createElement('termYear', $termYear); $findUnit->appendChild($termYearN); - if($termType1 !=3 && $termType1 != 10){ + if ($termType1 != 3 && $termType1 != 10) { $termTypeValueId = $doc->createElement('termTypeValueId', $termType); $findUnit->appendChild($termTypeValueId); } @@ -101,12 +100,12 @@ class CourseBackend_HisInOne extends CourseBackend $this->errormsg = $response2['soapenvBody']['soapenvFault']['faultcode'] . " " . $response2['soapenvBody']['soapenvFault']['faultstring']; return false; } elseif ($this->open) { - $units = $this->getAttributes($response2,'soapenvBody/hisfindUnitResponse/hisunits/hisunit'); + $units = $this->getAttributes($response2, 'soapenvBody/hisfindUnitResponse/hisunits/hisunit'); foreach ($units as $unit) { $id[] = $unit['hisid']; } } elseif (!$this->open) { - $id = $this->getAttributes($response2,'soapenvBody/hisfindUnitResponse/hisunitIds/hisid'); + $id = $this->getAttributes($response2, 'soapenvBody/hisfindUnitResponse/hisunitIds/hisid'); } else { $this->error = true; $this->errormsg = "url send a xml in a wrong format"; @@ -199,14 +198,12 @@ class CourseBackend_HisInOne extends CourseBackend } - public function getCacheTime() { - return 30* 60; + return 30 * 60; } - public function getRefreshTime() { return 60 * 60; @@ -221,12 +218,11 @@ class CourseBackend_HisInOne extends CourseBackend public function getCredentials() { - $credentials = ["username" => "string", "role" =>"string", "password" => "password", "open" => "bool"]; + $credentials = ["username" => "string", "role" => "string", "password" => "password", "open" => "bool"]; return $credentials; } - public function fetchSchedulesInternal($param) { if (empty($param)) { @@ -270,18 +266,19 @@ class CourseBackend_HisInOne extends CourseBackend $timetable = array(); //Here I go over the soapresponse foreach ($events as $event) { - $name = $this->getAttributes($event,'/hisunit/hisdefaulttext'); - if($name==false){ + $name = $this->getAttributes($event, '/hisunit/hisdefaulttext'); + if ($name == false) { //if HisInOne has no default text then there is no name $name = ['']; } - $dates = $this->getAttributes($event,'/hisunit/hisplanelements/hisplanelement/hisplannedDates/hisplannedDate/hisindividualDates/hisindividualDate'); + $dates = $this->getAttributes($event, + '/hisunit/hisplanelements/hisplanelement/hisplannedDates/hisplannedDate/hisindividualDates/hisindividualDate'); foreach ($dates as $date) { - $roomID =$this->getAttributes($date,'/hisroomId')[0]; - $datum = $this->getAttributes($date,'/hisexecutiondate')[0]; + $roomID = $this->getAttributes($date, '/hisroomId')[0]; + $datum = $this->getAttributes($date, '/hisexecutiondate')[0]; if (intval($roomID) == $room && in_array($datum, $currentWeek)) { - $startTime = $this->getAttributes($date,'hisstarttime')[0]; - $endTime = $this->getAttributes($date,'hisendtime')[0]; + $startTime = $this->getAttributes($date, 'hisstarttime')[0]; + $endTime = $this->getAttributes($date, 'hisendtime')[0]; $json = array( 'title' => $name[0], 'start' => $datum . " " . $startTime, @@ -331,7 +328,7 @@ class CourseBackend_HisInOne extends CourseBackend if ($response2 != false) { if (isset($response2['soapenvBody']['soapenvFault'])) { $this->error = true; - $this->errormsg = 'SOAP-Fault'.$response2['soapenvBody']['soapenvFault']['faultcode'] . " " . $response2['soapenvBody']['soapenvFault']['faultstring']; + $this->errormsg = 'SOAP-Fault' . $response2['soapenvBody']['soapenvFault']['faultcode'] . " " . $response2['soapenvBody']['soapenvFault']['faultstring']; return false; } elseif (isset($response2['soapenvBody']['hisreadUnitResponse'])) { $this->error = false; diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php index 2969f832..d507c4c3 100644 --- a/modules-available/locationinfo/page.inc.php +++ b/modules-available/locationinfo/page.inc.php @@ -17,9 +17,9 @@ class Page_LocationInfo extends Page } $this->action = Request::post('action'); - if ($this->action === 'updateOpeningTimeExpert') { + if ($this->action === 'updateOpeningTimeExpert') { $this->updateOpeningTimeExpert(); - } elseif($this->action === 'updateOpeningTimeEasy') { + } elseif ($this->action === 'updateOpeningTimeEasy') { $this->updateOpeningTimeEasy(); } elseif ($this->action === 'updateConfig') { $this->updateConfig(); @@ -48,7 +48,7 @@ class Page_LocationInfo extends Page $this->getInfoScreenTable(); } - if($getAction == 'updateroomdb') { + if ($getAction == 'updateroomdb') { $this->updateInfoscreenDb(); Util::redirect('?do=locationinfo&action=infoscreen'); } @@ -65,15 +65,21 @@ class Page_LocationInfo extends Page /** * Updates the server in the db. */ - private function updateServer() { + private function updateServer() + { $id = Request::post('id', 0, 'int'); if ($id == 0) { Database::exec("INSERT INTO `setting_location_info` (servername, serverurl, servertype) VALUES (:name, :url, :type)", - array('name' => Request::post('name', '', 'string'), 'url' => Request::post('url', '', 'string'), 'type' => Request::post('type', '', 'string'))); + array('name' => Request::post('name', '', 'string'), + 'url' => Request::post('url', '', 'string'), + 'type' => Request::post('type', '', 'string'))); } else { Database::exec("INSERT INTO `setting_location_info` (serverid, servername, servertype, serverurl) VALUES (:id, :name, :type, :url) 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'))); + array('id' => $id, + 'name' => Request::post('name', '', 'string'), + 'url' => Request::post('url', '', 'string'), + 'type' => Request::post('type', '', 'string'))); } $this->checkConnection(); @@ -82,7 +88,8 @@ class Page_LocationInfo extends Page /** * Deletes the server from the db. */ - private function deleteServer() { + private function deleteServer() + { $id = Request::post('id', 0, 'int'); Database::exec("DELETE FROM `setting_location_info` WHERE serverid=:id", array('id' => $id)); } @@ -108,20 +115,25 @@ class Page_LocationInfo extends Page $result['roomupdate'] = Request::post('roomupdate', 30, 'int'); $result['configupdate'] = Request::post('configupdate', 180, 'int'); $serverid = Request::post('serverid', 0, 'int'); - $serverroomid = Request::post('serverroomid','', 'string'); + $serverroomid = Request::post('serverroomid', '', 'string'); Database::exec("INSERT INTO `location_info` (locationid, serverid, serverroomid, config, lastcalendarupdate) VALUES (:id, :serverid, :serverroomid, :config, :lastcalendarupdate) ON DUPLICATE KEY UPDATE config=:config, serverid=:serverid, serverroomid=:serverroomid, lastcalendarupdate=:lastcalendarupdate", - array('id' => $locationid, 'config' => json_encode($result, true), 'serverid' => $serverid, 'serverroomid' => $serverroomid, 'lastcalendarupdate' => 0)); + array('id' => $locationid, + 'config' => json_encode($result, true), + 'serverid' => $serverid, + 'serverroomid' => $serverroomid, + 'lastcalendarupdate' => 0)); - Message::addSuccess('config-saved'); - Util::redirect('?do=locationinfo'); + Message::addSuccess('config-saved'); + Util::redirect('?do=locationinfo'); } /** * Updates the server settings in the db. */ - private function updateServerSettings() { + private function updateServerSettings() + { $serverid = Request::post('id', -1, 'int'); $servername = Request::post('name', 'unnamed', 'string'); $serverurl = Request::post('url', '', 'string'); @@ -138,16 +150,26 @@ class Page_LocationInfo extends Page } if ($serverid == 0) { Database::exec('INSERT INTO `setting_location_info` (servername, serverurl, servertype, credentials) VALUES (:name, :url, :type, :credentials)', - array('name' => $servername, 'url' => $serverurl, 'type' => $servertype, 'credentials' => json_encode($credentialsJson, true))); + array('name' => $servername, + 'url' => $serverurl, + 'type' => $servertype, + 'credentials' => json_encode($credentialsJson, true))); $dbresult = Database::queryFirst('SELECT serverid FROM `setting_location_info` WHERE servername = :name AND serverurl = :url AND servertype = :type AND credentials = :credentials', - array('name' => $servername, 'url' => $serverurl, 'type' => $servertype, 'credentials' => json_encode($credentialsJson, true))); + array('name' => $servername, + 'url' => $serverurl, + 'type' => $servertype, + 'credentials' => json_encode($credentialsJson, true))); $this->checkConnection($dbresult['serverid']); } else { Database::exec('UPDATE `setting_location_info` SET servername = :name, serverurl = :url, servertype = :type, credentials = :credentials WHERE serverid = :id', - array('id' => $serverid, 'name' => $servername, 'url' => $serverurl, 'type' => $servertype, 'credentials' => json_encode($credentialsJson, true))); - $this->checkConnection(); + array('id' => $serverid, + 'name' => $servername, + 'url' => $serverurl, + 'type' => $servertype, + 'credentials' => json_encode($credentialsJson, true))); + $this->checkConnection(); } } @@ -170,7 +192,7 @@ class Page_LocationInfo extends Page if (!$easyMode) { $dbquery = Database::simpleQuery("SELECT openingtime FROM `location_info` WHERE locationid = :id", array('id' => $locationid)); - while($dbdata=$dbquery->fetch(PDO::FETCH_ASSOC)) { + while ($dbdata = $dbquery->fetch(PDO::FETCH_ASSOC)) { $resulttmp = json_decode($dbdata['openingtime'], true); } @@ -199,7 +221,7 @@ class Page_LocationInfo extends Page if (!empty($days) && !is_array($days)) { Message::addError('no-days-selected'); Util::redirect('?do=locationinfo'); - } else{ + } else { $dayz = array(); $da = array(); @@ -227,7 +249,7 @@ class Page_LocationInfo extends Page } Database::exec("INSERT INTO `location_info` (locationid, openingtime) VALUES (:id, :openingtime) ON DUPLICATE KEY UPDATE openingtime=:openingtime", - array('id' => $locationid, 'openingtime' => json_encode($result, true))); + array('id' => $locationid, 'openingtime' => json_encode($result, true))); if ($deleteCounter > 0) { Message::addSuccess('deleted-x-entries', $deleteCounter); @@ -242,13 +264,14 @@ class Page_LocationInfo extends Page /** * Updates the opening time in the db from the easy mode. */ - private function updateOpeningTimeEasy() { + private function updateOpeningTimeEasy() + { $locationid = Request::post('id', 0, 'int'); $openingtime = Request::post('openingtime'); $closingtime = Request::post('closingtime'); $result = array(); - $opt0['days'] = array ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday"); + $opt0['days'] = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday"); if (isset($openingtime[0]) && isset($closingtime[0])) { if ($closingtime[0] != "" && $openingtime[0] != "") { $opt0['openingtime'] = $openingtime[0]; @@ -257,7 +280,7 @@ class Page_LocationInfo extends Page } } - $opt1['days'] = array ("Saturday"); + $opt1['days'] = array("Saturday"); if (isset($openingtime[1]) && isset($closingtime[1])) { if ($closingtime[1] != "" && $closingtime[1] != "") { $opt1['openingtime'] = $openingtime[1]; @@ -266,7 +289,7 @@ class Page_LocationInfo extends Page } } - $opt2['days'] = array ("Sunday"); + $opt2['days'] = array("Sunday"); if (isset($openingtime[2]) && isset($closingtime[2])) { if ($closingtime[2] != "" && $openingtime[2] != "") { $opt2['openingtime'] = $openingtime[2]; @@ -276,7 +299,7 @@ class Page_LocationInfo extends Page } Database::exec("INSERT INTO `location_info` (locationid, openingtime) VALUES (:id, :openingtime) ON DUPLICATE KEY UPDATE openingtime=:openingtime", - array('id' => $locationid, 'openingtime' => json_encode($result, true))); + array('id' => $locationid, 'openingtime' => json_encode($result, true))); Message::addSuccess('openingtime-updated'); Util::redirect('?do=locationinfo'); @@ -287,7 +310,8 @@ class Page_LocationInfo extends Page * * @param int $id Server id which connection should be checked. */ - private function checkConnection($id = 0) { + private function checkConnection($id = 0) + { $serverid = Request::post('id', 0, 'int'); if ($id != 0) { $serverid = $id; @@ -306,9 +330,10 @@ class Page_LocationInfo extends Page if (!$setCredentials || !$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)); + 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)); } } } @@ -319,8 +344,10 @@ class Page_LocationInfo extends Page * @param $id The location id which was toggled * @param $val The hidden value true / false */ - 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)); + 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)); $this->checkChildRecursive($id, $val); $this->checkParentRecursive($id); @@ -333,15 +360,17 @@ class Page_LocationInfo extends Page * @param $id The location id which childs should be checked * @param $val The hidden value */ - protected function checkChildRecursive($id, $val) { + protected function checkChildRecursive($id, $val) + { $dbquery = Database::simpleQuery("SELECT locationid FROM `location` WHERE parentlocationid = :locationid", array('locationid' => $id)); $childs = array(); - while($dbdata=$dbquery->fetch(PDO::FETCH_ASSOC)) { + while ($dbdata = $dbquery->fetch(PDO::FETCH_ASSOC)) { $childs[] = $dbdata['locationid']; } foreach ($childs as $key) { - Database::exec("INSERT INTO `location_info` (locationid, hidden) VALUES (:id, :hidden) ON DUPLICATE KEY UPDATE hidden=:hidden", array('id' => $key, 'hidden' => $val)); + Database::exec("INSERT INTO `location_info` (locationid, hidden) VALUES (:id, :hidden) ON DUPLICATE KEY UPDATE hidden=:hidden", array('id' => $key, + 'hidden' => $val)); $this->checkChildRecursive($key, $val); } @@ -352,32 +381,35 @@ class Page_LocationInfo extends Page * * @param $id The id of the location which was toggled. */ - protected function checkParentRecursive($id) { + protected function checkParentRecursive($id) + { $dbquery = Database::simpleQuery("SELECT parentlocationid FROM `location` WHERE locationid = :locationid", array('locationid' => $id)); $parent = 0; - while($dbdata=$dbquery->fetch(PDO::FETCH_ASSOC)) { + while ($dbdata = $dbquery->fetch(PDO::FETCH_ASSOC)) { $parent = (int)$dbdata['parentlocationid']; } if ($parent === 0) { return; } else { - $dbq = Database::simpleQuery("SELECT COUNT(case li.hidden when '0' then 1 else null end) AS '0', - COUNT(case li.hidden when '1' then 1 else null end) AS '1', - COUNT(*) - COUNT(case li.hidden when '0' then 1 else null end) - COUNT(case li.hidden when '1' then 1 else null end) AS 'NULL' + $dbq = Database::simpleQuery("SELECT COUNT(CASE li.hidden WHEN '0' THEN 1 ELSE NULL END) AS '0', + COUNT(CASE li.hidden WHEN '1' THEN 1 ELSE NULL END) AS '1', + COUNT(*) - COUNT(CASE li.hidden WHEN '0' THEN 1 ELSE NULL END) - COUNT(CASE li.hidden WHEN '1' THEN 1 ELSE NULL END) AS 'NULL' FROM `location` AS l LEFT JOIN `location_info` AS li ON l.locationid=li.locationid WHERE parentlocationid = :parentId;", array('parentId' => $parent)); $amountofzero = 0; $amountofnull = 0; - while($dbd=$dbq->fetch(PDO::FETCH_ASSOC)) { + while ($dbd = $dbq->fetch(PDO::FETCH_ASSOC)) { $amountofzero = (int)$dbd['0']; $amountofnull = (int)$dbd['NULL']; } if ($amountofzero == 0 AND $amountofnull == 0) { - Database::exec("INSERT INTO `location_info` (locationid, hidden) VALUES (:id, :hidden) ON DUPLICATE KEY UPDATE hidden=:hidden", array('id' => $parent, 'hidden' => 1)); + Database::exec("INSERT INTO `location_info` (locationid, hidden) VALUES (:id, :hidden) ON DUPLICATE KEY UPDATE hidden=:hidden", array('id' => $parent, + 'hidden' => 1)); } else { - Database::exec("INSERT INTO `location_info` (locationid, hidden) VALUES (:id, :hidden) ON DUPLICATE KEY UPDATE hidden=:hidden", array('id' => $parent, 'hidden' => 0)); + Database::exec("INSERT INTO `location_info` (locationid, hidden) VALUES (:id, :hidden) ON DUPLICATE KEY UPDATE hidden=:hidden", array('id' => $parent, + 'hidden' => 0)); } $this->checkParentRecursive($parent); @@ -387,12 +419,13 @@ class Page_LocationInfo extends Page /** * Loads the Infoscreen page in the admin-panel and passes all needed information. */ - protected function getInfoScreenTable() { + protected function getInfoScreenTable() + { // Get a table with the needed location info. name, id, hidden, pcState (Count of pcs that are in use), total pcs $dbquery = Database::simpleQuery("SELECT l.locationname, l.locationid, li.hidden, m.pcState, m.total FROM `location_info` AS li RIGHT JOIN `location` AS l ON li.locationid=l.locationid LEFT JOIN - (SELECT locationid, Count(case m.logintime WHEN NOT 1 THEN null else 1 end) AS pcState, Count(*) AS total FROM `machine` AS m + (SELECT locationid, Count(CASE m.logintime WHEN NOT 1 THEN NULL ELSE 1 END) AS pcState, Count(*) AS total FROM `machine` AS m WHERE locationid IS NOT NULL GROUP BY locationid) AS m ON l.locationid=m.locationid"); $pcs = array(); @@ -402,25 +435,25 @@ class Page_LocationInfo extends Page $data['locationid'] = (int)$loc['locationid']; $data['locationname'] = $loc['locationname']; $data['depth'] = $loc['depth']; - $data['hidden'] = NULL; + $data['hidden'] = null; $locid = (int)$loc['locationid']; $pcs[$locid] = $data; } } - while($roominfo=$dbquery->fetch(PDO::FETCH_ASSOC)) { + while ($roominfo = $dbquery->fetch(PDO::FETCH_ASSOC)) { $locid = (int)$roominfo['locationid']; - if ($roominfo['hidden'] == NULL) { + if ($roominfo['hidden'] == null) { $pcs[$locid]['hidden'] = 0; } else { $pcs[$locid]['hidden'] = $roominfo['hidden']; } - if ($roominfo['pcState'] != NULL) { + if ($roominfo['pcState'] != null) { $pcs[$locid]['pcState'] = $roominfo['pcState']; } - if ($roominfo['total'] != NULL) { + if ($roominfo['total'] != null) { $pcs[$locid]['total'] = $roominfo['total']; $pcs[$locid]['hasPcs'] = true; } else { @@ -441,7 +474,7 @@ class Page_LocationInfo extends Page // Get the Serverlist from the DB and make it mustache accesable $serverlist = array(); $dbquery2 = Database::simpleQuery("SELECT * FROM `setting_location_info`"); - while($db=$dbquery2->fetch(PDO::FETCH_ASSOC)) { + while ($db = $dbquery2->fetch(PDO::FETCH_ASSOC)) { $server['id'] = $db['serverid']; $server['name'] = $db['servername']; $server['type'] = $db['servertype']; @@ -452,7 +485,7 @@ class Page_LocationInfo extends Page } } - if ($db['error'] == NULL) { + if ($db['error'] == null) { $server['auth'] = true; } else { $server['auth'] = false; @@ -469,13 +502,14 @@ class Page_LocationInfo extends Page // Pass the data to the html and render it. Render::addTemplate('location-info', array( - 'list' => array_values($pcs), 'serverlist' => array_values($serverlist), + 'list' => array_values($pcs), + 'serverlist' => array_values($serverlist), )); } /** - * AJAX - */ + * AJAX + */ protected function doAjax() { User::load(); @@ -500,7 +534,8 @@ class Page_LocationInfo extends Page * * @param $id Serverid */ - private function ajaxServerSettings($id) { + private function ajaxServerSettings($id) + { $dbresult = Database::queryFirst('SELECT servername, serverurl, servertype, credentials FROM `setting_location_info` WHERE serverid = :id', array('id' => $id)); // Credentials stuff. @@ -528,7 +563,7 @@ class Page_LocationInfo extends Page $credential['uid'] = $counter; $credential['name'] = Dictionary::translateFile($s, $key);; $credential['type'] = $value; - $credential['title'] = Dictionary::translateFile($s, $key."_title"); + $credential['title'] = Dictionary::translateFile($s, $key . "_title"); if (Property::getPasswordFieldType() === 'text') { $credential['mask'] = false; @@ -540,7 +575,7 @@ class Page_LocationInfo extends Page if ($backend['typ'] == $dbresult['servertype']) { foreach ($dbcredentials as $k => $v) { - if($k == $key) { + if ($k == $key) { $credential['value'] = $v; break; } @@ -582,7 +617,11 @@ class Page_LocationInfo extends Page $serverBackends[] = $backend; } - echo Render::parse('server-settings', array('id' => $id, 'name' => $dbresult['servername'], 'url' => $dbresult['serverurl'], 'servertype' => $dbresult['servertype'], 'backendList' => array_values($serverBackends))); + echo Render::parse('server-settings', array('id' => $id, + 'name' => $dbresult['servername'], + 'url' => $dbresult['serverurl'], + 'servertype' => $dbresult['servertype'], + 'backendList' => array_values($serverBackends))); } /** @@ -590,21 +629,27 @@ class Page_LocationInfo extends Page * * @param $id id of the location */ - private function ajaxTimeTable($id) { + private function ajaxTimeTable($id) + { $array = array(); $dbquery = Database::simpleQuery("SELECT openingtime FROM `location_info` WHERE locationid = :id", array('id' => $id)); $dbresult = array(); - while($dbdata=$dbquery->fetch(PDO::FETCH_ASSOC)) { + while ($dbdata = $dbquery->fetch(PDO::FETCH_ASSOC)) { $dbresult[] = json_decode($dbdata['openingtime'], true); } - if($this->isEasyMode($dbresult)) { - echo Render::parse('timetable', array('id' => $id, 'openingtime0' => $dbresult[0][0]['openingtime'], - 'closingtime0' => $dbresult[0][0]['closingtime'], 'openingtime1' => $dbresult[0][1]['openingtime'], - 'closingtime1' => $dbresult[0][1]['closingtime'], 'openingtime2' => $dbresult[0][2]['openingtime'], - 'closingtime2' => $dbresult[0][2]['closingtime'], 'easyMode' => true, 'expertMode' => false)); + if ($this->isEasyMode($dbresult)) { + echo Render::parse('timetable', array('id' => $id, + 'openingtime0' => $dbresult[0][0]['openingtime'], + 'closingtime0' => $dbresult[0][0]['closingtime'], + 'openingtime1' => $dbresult[0][1]['openingtime'], + 'closingtime1' => $dbresult[0][1]['closingtime'], + 'openingtime2' => $dbresult[0][2]['openingtime'], + 'closingtime2' => $dbresult[0][2]['closingtime'], + 'easyMode' => true, + 'expertMode' => false)); - } else{ - foreach($dbresult as $db) { + } else { + foreach ($dbresult as $db) { $index = 0; foreach ($db as $key) { $str = ""; @@ -627,7 +672,10 @@ class Page_LocationInfo extends Page $index++; } } - echo Render::parse('timetable', array('id' => $id, 'openingtimes' => array_values($array), 'easyMode' => false, 'expertMode' => true)); + echo Render::parse('timetable', array('id' => $id, + 'openingtimes' => array_values($array), + 'easyMode' => false, + 'expertMode' => true)); } } @@ -637,10 +685,12 @@ class Page_LocationInfo extends Page * @param $array Array of the saved openingtimes. * @return bool True if easy mode, false if expert mode */ - private function isEasyMode($array) { - if(count($array[0]) == 3) { - if ($array[0][0]['days'] == array ("Monday","Tuesday","Wednesday","Thursday","Friday") - && $array[0][1]['days'] == array ("Saturday") && $array[0][2]['days'] == array ("Sunday")) { + private function isEasyMode($array) + { + if (count($array[0]) == 3) { + if ($array[0][0]['days'] == array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday") + && $array[0][1]['days'] == array("Saturday") && $array[0][2]['days'] == array("Sunday") + ) { return true; } else { return false; @@ -657,14 +707,15 @@ class Page_LocationInfo extends Page * * @param $id Location ID */ - private function ajaxConfig($id) { + private function ajaxConfig($id) + { $array = array(); // Get Config data from db $dbquery = Database::simpleQuery("SELECT config, serverid, serverroomid FROM `location_info` WHERE locationid = :id", array('id' => $id)); $serverid; $serverroomid; - while($dbdata=$dbquery->fetch(PDO::FETCH_ASSOC)) { + while ($dbdata = $dbquery->fetch(PDO::FETCH_ASSOC)) { $array = json_decode($dbdata['config'], true); $serverid = $dbdata['serverid']; $serverroomid = $dbdata['serverroomid']; @@ -673,17 +724,30 @@ class Page_LocationInfo extends Page // get Server / ID list $dbq = Database::simpleQuery("SELECT serverid, servername FROM `setting_location_info`"); $serverList = array(); - while($dbd=$dbq->fetch(PDO::FETCH_ASSOC)) { + while ($dbd = $dbq->fetch(PDO::FETCH_ASSOC)) { $d['sid'] = $dbd['serverid']; $d['sname'] = $dbd['servername']; $serverList[] = $d; } - echo Render::parse('config', array('id' => $id, 'language' => $array['language'], 'mode' => 'mode'.$array['mode'], 'vertical' => $array['vertical'], - 'eco' => $array['eco'], 'daystoshow' => 'day'.$array['daystoshow'], 'scaledaysauto' => $array['scaledaysauto'], 'rotation' => 'rotation'.$array['rotation'], - 'scale' => $array['scale'], 'switchtime' => $array['switchtime'], 'calupdate' => $array['calupdate'], - 'roomupdate' => $array['roomupdate'], 'configupdate' => $array['configupdate'], - 'serverlist' => array_values($serverList), 'serverid' => $serverid, 'serverroomid' => $serverroomid)); + echo Render::parse('config', array( + 'id' => $id, + 'language' => $array['language'], + 'mode' => 'mode' . $array['mode'], + 'vertical' => $array['vertical'], + 'eco' => $array['eco'], + 'daystoshow' => 'day' . $array['daystoshow'], + 'scaledaysauto' => $array['scaledaysauto'], + 'rotation' => 'rotation' . $array['rotation'], + 'scale' => $array['scale'], + 'switchtime' => $array['switchtime'], + 'calupdate' => $array['calupdate'], + 'roomupdate' => $array['roomupdate'], + 'configupdate' => $array['configupdate'], + 'serverlist' => array_values($serverList), + 'serverid' => $serverid, + 'serverroomid' => $serverroomid + )); } } -- cgit v1.2.3-55-g7522