From 86423a7cc2f52a8f7428b8c75e7260a1f9439cda Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 7 Sep 2016 11:39:51 +0200 Subject: [roomplanner] Show location name in title --- modules-available/roomplanner/page.inc.php | 38 +++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'modules-available/roomplanner/page.inc.php') 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 { -- cgit v1.2.3-55-g7522