From 8c9896f9b9c1bb9bf6509b6e07a83c5ed4a8dbff Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Thu, 22 Dec 2011 19:16:18 +0000 Subject: [PATCH] Add new Add Incident page --- source/webui/pages/admin/add-incident.php | 89 +++++++++++++++ source/webui/templates/admin/add-incident.tpl | 106 ++++++++++++++++++ source/webui/templates/home.tpl | 2 +- 3 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 source/webui/pages/admin/add-incident.php create mode 100644 source/webui/templates/admin/add-incident.tpl diff --git a/source/webui/pages/admin/add-incident.php b/source/webui/pages/admin/add-incident.php new file mode 100644 index 0000000..c6e32aa --- /dev/null +++ b/source/webui/pages/admin/add-incident.php @@ -0,0 +1,89 @@ +request(); +$auth = $main->auth(); +$session = $main->session(); + +if ( ! $auth->isAuthenticated() || ! $auth->hasPermission(StatusBoard_Permission::PERM_UpdateIncidents)) { + throw new StatusBoard_Exception_NotAuthorised(); +} + +if ($request->exists('do')) { + + $service_id = StatusBoard_Main::issetelse($_POST['service'], 'Sihnon_Exception_InvalidParameters'); + $site_id = StatusBoard_Main::issetelse($_POST['site'], 'Sihnon_Exception_InvalidParameters'); + $reference = StatusBoard_Main::issetelse($_POST['reference'], 'Sihnon_Exception_InvalidParameters'); + $description = StatusBoard_Main::issetelse($_POST['description'], 'Sihnon_Exception_InvalidParameters'); + $status = StatusBoard_Main::issetelse($_POST['status'], 'Sihnon_Exception_InvalidParameters'); + $start_time = StatusBoard_Main::issetelse($_POST['starttime'], 'Sihnon_Exception_InvalidParameters'); + $estimated_end_time = StatusBoard_Main::issetelse($_POST['estimatedendtime'], 'Sihnon_Exception_InvalidParameters'); + + $incident = null; + + try { + $service = StatusBoard_Service::fromId($service_id); + $site = StatusBoard_Site::fromId($site_id); + + $start_time = strtotime($start_time); + if ($start_time === null) { + throw new StatusBoard_Exception_InvalidParameters('starttime'); + } + $estimated_end_time = strtotime($estimated_end_time); + if ($estimated_end_time === null) { + throw new StatusBoard_Exception_InvalidParameters('estimatedendtime'); + } + + $incident = $site->newIncident($reference, $description, $status, $start_time, $estimated_end_time); + + $messages[] = array( + 'severity' => 'success', + 'content' => 'The incident was created succesfully.', + ); + } catch (StatusBoard_Exception_ResultCountMismatch $e) { + $messages[] = array( + 'severity' => 'error', + 'content' => 'The incident was not created because the Service or Site could not be found.', + ); + } + + $session->set('messages', $messages); + StatusBoard_Page::redirect("admin/incident/service/{$service->id}/site/{$site->id}/id/{$incident->id}/"); +} + +$service_id = $request->get('service'); +$site_id = $request->get('site'); + +$service = null; +$site = null; + +$services = StatusBoard_Service::all(); +try { + if ($service_id) { + $service = StatusBoard_Service::fromId($service_id); + } + if ($site_id) { + $site = StatusBoard_Site::fromId($site_id); + } +} catch (Sihnon_Exception_ResultCountMismatch $e) { + throw new StatusBoard_Exception_FileNotFound(); +} + +$all_sites = array(); +if ($service) { + $all_sites[$service->id] = $service->sites(); +} else { + foreach ($services as $all_service) { + $all_sites[$all_service->id] = $all_service->sites(); + } +} + + + +$this->smarty->assign('services', $services); +$this->smarty->assign('service', $service); +$this->smarty->assign('all_sites', $all_sites); +$this->smarty->assign('site', $site); +$this->smarty->assign('messages', $messages); + +?> \ No newline at end of file diff --git a/source/webui/templates/admin/add-incident.tpl b/source/webui/templates/admin/add-incident.tpl new file mode 100644 index 0000000..9e20ad6 --- /dev/null +++ b/source/webui/templates/admin/add-incident.tpl @@ -0,0 +1,106 @@ +
+
+
+

Add Incident

+

Use this form to add a new incident

+
+
+ +
+
+
+ +
+ {if $service} + + {$service->name|escape:html} + {else} + + {/if} +
+
+ +
+ +
+ {if $service && $site} + + {$site->name|escape:html} + {else} + + {/if} +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+
+ + \ No newline at end of file diff --git a/source/webui/templates/home.tpl b/source/webui/templates/home.tpl index dce12ae..57958e8 100644 --- a/source/webui/templates/home.tpl +++ b/source/webui/templates/home.tpl @@ -4,7 +4,7 @@

{$site_title}

-Add Incident +Add Incident