summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules-available/locations/inc/location.inc.php5
-rw-r--r--modules-available/roomplanner/page.inc.php38
2 files changed, 34 insertions, 9 deletions
diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php
index 71a621db..81ee342f 100644
--- a/modules-available/locations/inc/location.inc.php
+++ b/modules-available/locations/inc/location.inc.php
@@ -26,6 +26,11 @@ class Location
return $rows;
}
+ public static function get($locationId)
+ {
+ return Database::queryFirst("SELECT * FROM location WHERE locationid = :locationId", compact('locationId'));
+ }
+
public static function getName($locationId)
{
self::getLocationsAssoc();
diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php
index d437fdd0..9e01eca3 100644
--- a/modules-available/roomplanner/page.inc.php
+++ b/modules-available/roomplanner/page.inc.php
@@ -6,12 +6,25 @@ class Page_Roomplanner extends Page
/**
* @var int locationid of location we're editing
*/
- private $locationid;
+ private $locationid = false;
+
+ /**
+ * @var array location data from location table
+ */
+ private $location = false;
/**
* @var string action to perform
*/
- private $action;
+ private $action = false;
+
+ private function loadRequestedLocation()
+ {
+ $this->locationid = Request::get('locationid', false, 'integer');
+ if ($this->locationid !== false) {
+ $this->location = Location::get($this->locationid);
+ }
+ }
protected function doPreprocess()
{
@@ -22,18 +35,22 @@ class Page_Roomplanner extends Page
Util::redirect('?do=Main');
}
- $this->locationid = Request::get('locationid', null, 'integer');
$this->action = Request::any('action', 'show', 'string');
-
- if ($this->locationid === null) {
+ $this->loadRequestedLocation();
+ if ($this->locationid === false) {
Message::addError('need-locationid');
Util::redirect('?do=locations');
}
+ if ($this->location === false) {
+ Message::addError('invalid-locationid');
+ Util::redirect('?do=locations');
+ }
if ($this->action === 'save') {
$this->handleSaveRequest(false);
Util::redirect("?do=roomplanner&locationid={$this->locationid}&action=show");
}
+ Render::setTitle($this->location['locationname']);
}
protected function doRender()
@@ -56,10 +73,10 @@ class Page_Roomplanner extends Page
protected function doAjax()
{
- $this->action = Request::any('action', null, 'string');
+ $this->action = Request::any('action', false, 'string');
if ($this->action === 'getmachines') {
- $query = Request::get('query', null, 'string');
+ $query = Request::get('query', false, 'string');
/* the query could be anything: UUID, IP or macaddr */
// $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname '
@@ -84,10 +101,13 @@ class Page_Roomplanner extends Page
}
echo json_encode($returnObject);
} elseif ($this->action === 'save') {
- $this->locationid = Request::any('locationid', null, 'integer');
- if ($this->locationid === null) {
+ $this->loadRequestedLocation();
+ if ($this->locationid === false) {
die('Missing locationid in save data');
}
+ if ($this->location === false) {
+ die('Location with id ' . $this->locationid . ' does not exist.');
+ }
$this->handleSaveRequest(true);
die('SUCCESS');
} else {