From a87a37ca7b7e79d259330718aa2e5406a6f3d3a4 Mon Sep 17 00:00:00 2001
From: Sae126V
Date: Thu, 31 Aug 2023 11:16:26 +0000
Subject: [PATCH 01/10] [GT-187] Add feature selecting multiple sites
---
.../controllers/downtime/add_downtime.php | 70 ++++----
.../controllers/downtime/downtime_utils.php | 169 ++++++++++++++++++
.../controllers/downtime/edit_downtime.php | 67 ++++---
.../downtime/view_endpoint_tree.php | 35 +++-
.../views/downtime/add_downtime.php | 98 +++++++---
.../views/downtime/added_downtime.php | 26 ++-
.../views/downtime/confirm_add_downtime.php | 82 ++++++---
...wntime_edit_view_nested_endpoints_list.php | 14 +-
.../views/downtime/edit_downtime.php | 28 ++-
.../downtime/view_nested_endpoints_list.php | 17 +-
10 files changed, 461 insertions(+), 145 deletions(-)
create mode 100644 htdocs/web_portal/controllers/downtime/downtime_utils.php
diff --git a/htdocs/web_portal/controllers/downtime/add_downtime.php b/htdocs/web_portal/controllers/downtime/add_downtime.php
index becb0c73f..1238f731d 100644
--- a/htdocs/web_portal/controllers/downtime/add_downtime.php
+++ b/htdocs/web_portal/controllers/downtime/add_downtime.php
@@ -24,6 +24,7 @@
require_once __DIR__.'/../../../../lib/Gocdb_Services/Factory.php';
require_once __DIR__.'/../utils.php';
require_once __DIR__.'/../../../web_portal/components/Get_User_Principle.php';
+require_once __DIR__ . '/downtime_utils.php';
/**
* Controller for a new_downtime request.
@@ -71,53 +72,52 @@ function submit(\User $user = null) {
if($confirmed == true){
//Downtime is confirmed, submit it
//$downtimeInfo = unserialize($_REQUEST['newValues']); // didn't cater for UTF-8 chars
+ /**
+ * If confirmed by an user, submit the details of affected services
+ * and endpoints along with other details for each individual site.
+ */
$downtimeInfo = json_decode($_POST['newValues'], TRUE);
$serv = \Factory::getDowntimeService();
+ $downtimeInfo = unsetVariables($downtimeInfo, 'add');
+ $params = [];
+
+ foreach ($downtimeInfo['SITE_LEVEL_DETAILS'] as $siteID) {
+ $downtimeInfo['Impacted_Services'] = $siteID['services'];
+ $downtimeInfo['Impacted_Endpoints'] = $siteID['endpoints'];
+
+ $params['submittedDowntimes'][$siteID['siteName']] =
+ $serv->addDowntime($downtimeInfo, $user);
+ }
- $params['dt'] = $serv->addDowntime($downtimeInfo, $user);
show_view("downtime/added_downtime.php", $params);
}else{
//Show user confirmation screen with their input
$downtimeInfo = getDtDataFromWeb();
- //Need to sort the impacted_ids into impacted services and impacted endpoints
- $impactedids = $downtimeInfo['IMPACTED_IDS'];
+ list(
+ $siteLevelDetails,
+ $serviceWithEndpoints
+ ) = endpointToServiceMapping($downtimeInfo['IMPACTED_IDS']);
- $services=array();
- $endpoints=array();
+ // Delete the unsorted IDs from the downtime info
+ unset($downtimeInfo['IMPACTED_IDS']);
- //For each impacted id sort between endpoints and services using the prepended letter
- foreach($impactedids as $id){
- if (strpos($id, 's') !== FALSE){
- //This is a service id
- $services[] = str_replace('s', '', $id); //trim off the identifying char before storing in array
- }else{
- //This is an endpoint id
- $endpoints[] = str_replace('e', '', $id); //trim off the identifying char before storing in array
- }
+ if (!count($siteLevelDetails) > 1) {
+ $downtimeInfo['SINGLE_TIMEZONE'] = true;
}
- unset($downtimeInfo['IMPACTED_IDS']); //Delete the unsorted Ids from the downtime info
-
- $downtimeInfo['Impacted_Endpoints'] = $endpoints;
-
-
- $serv = \Factory::getServiceService();
-
- /** For endpoint put into downtime we want the parent service also. If a user has selected
- * endpoints but not the parent service here we will add the service to maintain the link beteween
- * a downtime having both the service and the endpoint.
- */
- foreach($downtimeInfo['Impacted_Endpoints'] as $endpointIds){
- $endpoint = $serv->getEndpoint($endpointIds);
- $services[] = $endpoint->getService()->getId();
- }
-
- //Remove any duplicate service ids and store the array of ids
- $services = array_unique($services);
-
- //Assign the impacted services and endpoints to their own arrays for us by the addDowntime method
- $downtimeInfo['Impacted_Services'] = $services;
+ list(
+ $siteLevelDetails,
+ $serviceWithEndpoints
+ ) = addParentServiceForEndpoints(
+ $serviceWithEndpoints,
+ $siteLevelDetails,
+ false,
+ $downtimeInfo['DOWNTIME']
+ );
+
+ $downtimeInfo['SITE_LEVEL_DETAILS'] = $siteLevelDetails;
+ $downtimeInfo['SERVICE_WITH_ENDPOINTS'] = $serviceWithEndpoints;
show_view("downtime/confirm_add_downtime.php", $downtimeInfo);
}
diff --git a/htdocs/web_portal/controllers/downtime/downtime_utils.php b/htdocs/web_portal/controllers/downtime/downtime_utils.php
new file mode 100644
index 000000000..f0905c4f6
--- /dev/null
+++ b/htdocs/web_portal/controllers/downtime/downtime_utils.php
@@ -0,0 +1,169 @@
+ $siteData) {
+ $siteDetails[$siteID]['services'] = [];
+
+ $newSite = \Factory::getSiteService()->getSite($siteID);
+ $siteDetails[$siteID]['siteName'] = $newSite->getShortName();
+
+ if ($hasMultipleTimezones) {
+ list(
+ $siteDetails[$siteID]['START_TIMESTAMP'],
+ $siteDetails[$siteID]['END_TIMESTAMP']
+ ) = setLocalTimeForSites($downtimeDetails, $siteID);
+ }
+
+ foreach (array_keys($siteData) as $serviceID) {
+ $servWithEndpoints[$siteID][$serviceID]['services'] = [];
+ $servWithEndpoints[$siteID][$serviceID]['services'][] = $serviceID;
+ // Ensuring that service IDs are unique for the selected sites.
+ $siteDetails[$siteID]['services'][] = $serviceID;
+ }
+ }
+
+ return [$siteDetails, $servWithEndpoints];
+}
+
+/**
+ * Converts UTC start and end timestamps to the local timezone
+ * of a specific site based on that site's timezone.
+ *
+ * @param mixed $downtimeDetails Downtime information.
+ * @param integer $siteID Site ID
+ */
+function setLocalTimeForSites($downtimeDetails, $siteID)
+{
+ $site = \Factory::getSiteService()->getSite($siteID);
+
+ $siteTimezone = $site->getTimeZoneId();
+
+ $startTimeAsString = $downtimeDetails['START_TIMESTAMP'];
+ $utcEndTime = $downtimeDetails['END_TIMESTAMP'];
+
+ $utcStartDateTime = DateTime::createFromFormat(
+ 'd/m/Y H:i',
+ $startTimeAsString,
+ new DateTimeZone('UTC')
+ );
+ $utcEndDateTime = DateTime::createFromFormat(
+ 'd/m/Y H:i',
+ $utcEndTime,
+ new DateTimeZone('UTC')
+ );
+
+ $targetSiteTimezone = new DateTimeZone($siteTimezone);
+ $utcOffset = $targetSiteTimezone->getOffset($utcStartDateTime);
+
+ // Calculate the equivalent time in the target timezone.
+ // Ref: https://www.php.net/manual/en/datetime.modify.php
+ $siteStartDateTime = $utcStartDateTime->modify("-$utcOffset seconds");
+ $siteEndDateTime = $utcEndDateTime->modify("-$utcOffset seconds");
+
+ return [
+ $siteStartDateTime->format('d/m/Y H:i'),
+ $siteEndDateTime->format('d/m/Y H:i')
+ ];
+}
+
+/**
+ * Unset a given variable, helper method to destroy the specified variables.
+ *
+ * @param mixed $downtimeObj Object to destroy specified variables.
+ * @param string $fromLocation Location from where the
+ * function is being called.
+ */
+function unsetVariables($downtimeObj, $fromLocation)
+{
+ if ($fromLocation == "add") {
+ unset($downtimeObj['SERVICE_WITH_ENDPOINTS']);
+ unset($downtimeObj['SINGLE_TIMEZONE']);
+ } else {
+ unset($downtimeObj['DOWNTIME']['EXISTINGID']);
+ unset($downtimeObj['isEdit']);
+ unset($downtimeObj['SERVICE_WITH_ENDPOINTS']);
+ unset($downtimeObj['SINGLE_TIMEZONE']);
+ }
+
+ return $downtimeObj;
+}
diff --git a/htdocs/web_portal/controllers/downtime/edit_downtime.php b/htdocs/web_portal/controllers/downtime/edit_downtime.php
index 9bf244428..3f74cb16f 100644
--- a/htdocs/web_portal/controllers/downtime/edit_downtime.php
+++ b/htdocs/web_portal/controllers/downtime/edit_downtime.php
@@ -21,6 +21,7 @@
require_once __DIR__ . '/../../../../lib/Gocdb_Services/Factory.php';
require_once __DIR__ . '/../../../../htdocs/web_portal/components/Get_User_Principle.php';
require_once __DIR__ . '/../utils.php';
+require_once __DIR__ . '/downtime_utils.php';
/**
* Controller for an edit downtime request
@@ -88,11 +89,18 @@ function submit(\User $user = null) {
if($confirmed == true){
//Downtime is confirmed, submit it
$downtimeInfo = json_decode($_POST['newValues'], TRUE);
-
+ $params = [];
$serv = \Factory::getDowntimeService();
$dt = $serv->getDowntime($downtimeInfo['DOWNTIME']['EXISTINGID']);
- unset($downtimeInfo['DOWNTIME']['EXISTINGID']);
- unset($downtimeInfo['isEdit']);
+ $downtimeInfo = unsetVariables($downtimeInfo, 'edit');
+
+ foreach ($downtimeInfo['SITE_LEVEL_DETAILS'] as $siteIDs) {
+ $downtimeInfo['Impacted_Services'] = $siteIDs['services'];
+ $downtimeInfo['Impacted_Endpoints'] = $siteIDs['endpoints'];
+ }
+
+ unset($downtimeInfo['SITE_LEVEL_DETAILS']);
+
$params['dt'] = $serv->editDowntime($dt, $downtimeInfo, $user);
show_view("downtime/edited_downtime.php", $params);
@@ -101,43 +109,30 @@ function submit(\User $user = null) {
$downtimeInfo = getDtDataFromWeb();
//Need to sort the impacted_ids into impacted services and impacted endpoints
- $impactedids = $downtimeInfo['IMPACTED_IDS'];
-
- $services=array();
- $endpoints=array();
-
- //For each impacted id sort between endpoints and services using the prepended letter
- foreach($impactedids as $id){
- if (strpos($id, 's') !== FALSE){
- //This is a service id
- $services[] = str_replace('s', '', $id); //trim off the identifying char before storing in array
- }else{
- //This is an endpoint id
- $endpoints[] = str_replace('e', '', $id); //trim off the identifying char before storing in array
- }
- }
-
- unset($downtimeInfo['IMPACTED_IDS']); //Delete the unsorted Ids from the downtime info
-
- $downtimeInfo['Impacted_Endpoints'] = $endpoints;
+ list(
+ $siteLevelDetails,
+ $serviceWithEndpoints
+ ) = endpointToServiceMapping($downtimeInfo['IMPACTED_IDS']);
+ // Delete the unsorted IDs from the downtime info
+ unset($downtimeInfo['IMPACTED_IDS']);
- $serv = \Factory::getServiceService();
-
- /** For endpoint put into downtime we want the parent service also. If a user has selected
- * endpoints but not the parent service here we will add the service to maintain the link beteween
- * a downtime having both the service and the endpoint.
- */
- foreach($downtimeInfo['Impacted_Endpoints'] as $endpointIds){
- $endpoint = $serv->getEndpoint($endpointIds);
- $services[] = $endpoint->getService()->getId();
+ if (!count($siteLevelDetails) > 1) {
+ $downtimeInfo['SINGLE_TIMEZONE'] = true;
}
- //Remove any duplicate service ids and store the array of ids
- $services = array_unique($services);
-
- //Assign the impacted services and endpoints to their own arrays for us by the addDowntime method
- $downtimeInfo['Impacted_Services'] = $services;
+ list(
+ $siteLevelDetails,
+ $serviceWithEndpoints
+ ) = addParentServiceForEndpoints(
+ $serviceWithEndpoints,
+ $siteLevelDetails,
+ false,
+ $downtimeInfo['DOWNTIME']
+ );
+
+ $downtimeInfo['SITE_LEVEL_DETAILS'] = $siteLevelDetails;
+ $downtimeInfo['SERVICE_WITH_ENDPOINTS'] = $serviceWithEndpoints;
//Pass the edit variable so the confirm_add view works as the confirm edit view.
$downtimeInfo['isEdit'] = true;
show_view("downtime/confirm_add_downtime.php", $downtimeInfo);
diff --git a/htdocs/web_portal/controllers/downtime/view_endpoint_tree.php b/htdocs/web_portal/controllers/downtime/view_endpoint_tree.php
index eb9f81946..c8451d787 100644
--- a/htdocs/web_portal/controllers/downtime/view_endpoint_tree.php
+++ b/htdocs/web_portal/controllers/downtime/view_endpoint_tree.php
@@ -19,19 +19,30 @@
* limitations under the License.
*
/*====================================================== */
+use Doctrine\Common\Collections\ArrayCollection;
+use Exception;
+
function getServiceandEndpointList() {
require_once __DIR__ . '/../utils.php';
require_once __DIR__ . '/../../../web_portal/components/Get_User_Principle.php';
+ $params = [];
$dn = Get_User_Principle();
$user = \Factory::getUserService()->getUserByPrinciple($dn);
$params['portalIsReadOnly'] = portalIsReadOnlyAndUserIsNotAdmin($user);
+ $siteIDs = $_REQUEST['site_id'];
- if (!isset($_REQUEST['site_id']) || !is_numeric($_REQUEST['site_id']) ){
- throw new Exception("An id must be specified");
+ if (empty($siteIDs)) {
+ throw new Exception("Please select at least one site.");
}
- $site = \Factory::getSiteService()->getSite($_REQUEST['site_id']);
- $services = $site->getServices();
+
+ $services = new ArrayCollection();
+
+ foreach ($siteIDs as $value) {
+ $site = \Factory::getSiteService()->getSite($value);
+ $services[$value] = $site->getServices();
+ }
+
$params['services'] = $services;
show_view("downtime/view_nested_endpoints_list.php", $params, null, true);
}
@@ -41,18 +52,26 @@ function editDowntimePopulateEndpointTree() {
require_once __DIR__ . '/../utils.php';
require_once __DIR__ . '/../../../web_portal/components/Get_User_Principle.php';
+ $params = [];
$dn = Get_User_Principle();
$user = \Factory::getUserService()->getUserByPrinciple($dn);
$params['portalIsReadOnly'] = portalIsReadOnlyAndUserIsNotAdmin($user);
+ $siteIDs = $_REQUEST['site_id'];
- if (!isset($_REQUEST['site_id']) || !is_numeric($_REQUEST['site_id']) ){
- throw new Exception("A site id must be specified");
+ if (empty($_REQUEST['site_id'])) {
+ throw new Exception("Please select at least one site.");
}
if (!isset($_REQUEST['dt_id']) || !is_numeric($_REQUEST['dt_id']) ){
throw new Exception("A downtime id must be specified");
}
- $site = \Factory::getSiteService()->getSite($_REQUEST['site_id']);
- $services = $site->getServices();
+
+ $services = new ArrayCollection();
+
+ foreach ($siteIDs as $value) {
+ $site = \Factory::getSiteService()->getSite($value);
+ $services[$value] = $site->getServices();
+ }
+
$params['services'] = $services;
$downtime = \Factory::getDowntimeService()->getDowntime($_REQUEST['dt_id']);
diff --git a/htdocs/web_portal/views/downtime/add_downtime.php b/htdocs/web_portal/views/downtime/add_downtime.php
index 35508c0d2..6435dd6ec 100644
--- a/htdocs/web_portal/views/downtime/add_downtime.php
+++ b/htdocs/web_portal/views/downtime/add_downtime.php
@@ -67,7 +67,13 @@
-
+
@@ -147,10 +153,15 @@
$size = sizeof($sites) + 2;
}
?>
-
';
+ ?>
+
- Severity:
- Description:
@@ -38,30 +53,38 @@
//echo date_format($timestamp, 'l jS \of F Y \a\t\: h:i A');
xecho($params['DOWNTIME']['END_TIMESTAMP']);
?>
- 1)){
- echo "- Affecting Services:";
- }else{
- echo "
- Affecting Service:";
- }
- ?>
-
+
+ $siteDetails) : ?>
getService($id);
- $safeHostName = xssafe($service->getHostname());
- echo "- " . $safeHostName . "
";
- }
+ $siteName = $params['SITE_LEVEL_DETAILS'][$siteID]['siteName'];
+
+ echo '- Site Name: ';
+ echo $siteName;
+ echo '
';
?>
-
-
- 1)){
- echo "- Affecting Endpoints:";
- }else{
- echo "
- Affecting Endpoint:";
- }
- ?>
+
+
+ -
+ Affecting Service and Endpoint(s):
+
+ $data) : ?>
+ getService($serviceID);
+ $safeHostName = xssafe($service->getHostname());
+ ?>
+
+
+ -
+ getServiceType()->getName() .
+ ') '
+ );
+ echo $safeHostName;
+ ?>
-
+
+
+
+
+
+
diff --git a/htdocs/web_portal/views/downtime/downtime_edit_view_nested_endpoints_list.php b/htdocs/web_portal/views/downtime/downtime_edit_view_nested_endpoints_list.php
index 5be329d0e..2727fbbd6 100644
--- a/htdocs/web_portal/views/downtime/downtime_edit_view_nested_endpoints_list.php
+++ b/htdocs/web_portal/views/downtime/downtime_edit_view_nested_endpoints_list.php
@@ -26,7 +26,8 @@ class="form-control" onclick=""
style="width:99%; margin-left:1%"
onChange="selectServicesEndpoint()" multiple>
$siteServiceList) {
+ foreach ($siteServiceList as $service) {
$count=0;
// Set the html 'SELECTED' attribute on the ");
@@ -52,10 +56,14 @@ class="form-control" onclick=""
$name = xssafe($endpoint->getName());
}
//Option styling doesn't work well cross browser so just use 4 spaces to indent the branch
- echo "";
+ echo "";
$count++;
}
}
+}
?>
diff --git a/htdocs/web_portal/views/downtime/edit_downtime.php b/htdocs/web_portal/views/downtime/edit_downtime.php
index 0f1fcd761..f6319caeb 100644
--- a/htdocs/web_portal/views/downtime/edit_downtime.php
+++ b/htdocs/web_portal/views/downtime/edit_downtime.php
@@ -154,10 +154,15 @@ class="glyphicon glyphicon-time">
$size = sizeof($sites) + 2;
}
?>
-
-
+
Select Affected Services+Endpoints (Ctrl+click to select)
$siteServiceList) {
+ foreach ($siteServiceList as $service) {
$count=0;
- echo "";
+
+ echo "";
+
foreach($service->getEndpointLocations() as $endpoint){
if($endpoint->getName() == ''){
$name = xssafe('myEndpoint');
@@ -17,10 +25,13 @@
$name = xssafe($endpoint->getName());
}
//Option styling doesn't work well cross browser so just use 4 spaces to indent the branch
- echo "";
+ echo "";
$count++;
}
}
+}
?>
From b3dd024f90112f069b01ce09673b3a37ee9ed4bc Mon Sep 17 00:00:00 2001
From: Sae126V
Date: Thu, 31 Aug 2023 14:39:03 +0000
Subject: [PATCH 02/10] [GT-187] Change Name to site ONLY
---
htdocs/web_portal/controllers/downtime/add_downtime.php | 2 +-
htdocs/web_portal/controllers/downtime/downtime_utils.php | 4 ++--
htdocs/web_portal/controllers/downtime/edit_downtime.php | 2 +-
htdocs/web_portal/views/downtime/confirm_add_downtime.php | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/htdocs/web_portal/controllers/downtime/add_downtime.php b/htdocs/web_portal/controllers/downtime/add_downtime.php
index 1238f731d..3afc5a312 100644
--- a/htdocs/web_portal/controllers/downtime/add_downtime.php
+++ b/htdocs/web_portal/controllers/downtime/add_downtime.php
@@ -103,7 +103,7 @@ function submit(\User $user = null) {
unset($downtimeInfo['IMPACTED_IDS']);
if (!count($siteLevelDetails) > 1) {
- $downtimeInfo['SINGLE_TIMEZONE'] = true;
+ $downtimeInfo['SINGLE_SITE'] = true;
}
list(
diff --git a/htdocs/web_portal/controllers/downtime/downtime_utils.php b/htdocs/web_portal/controllers/downtime/downtime_utils.php
index f0905c4f6..ed5fffe36 100644
--- a/htdocs/web_portal/controllers/downtime/downtime_utils.php
+++ b/htdocs/web_portal/controllers/downtime/downtime_utils.php
@@ -157,12 +157,12 @@ function unsetVariables($downtimeObj, $fromLocation)
{
if ($fromLocation == "add") {
unset($downtimeObj['SERVICE_WITH_ENDPOINTS']);
- unset($downtimeObj['SINGLE_TIMEZONE']);
+ unset($downtimeObj['SINGLE_SITE']);
} else {
unset($downtimeObj['DOWNTIME']['EXISTINGID']);
unset($downtimeObj['isEdit']);
unset($downtimeObj['SERVICE_WITH_ENDPOINTS']);
- unset($downtimeObj['SINGLE_TIMEZONE']);
+ unset($downtimeObj['SINGLE_SITE']);
}
return $downtimeObj;
diff --git a/htdocs/web_portal/controllers/downtime/edit_downtime.php b/htdocs/web_portal/controllers/downtime/edit_downtime.php
index 3f74cb16f..4b26cc751 100644
--- a/htdocs/web_portal/controllers/downtime/edit_downtime.php
+++ b/htdocs/web_portal/controllers/downtime/edit_downtime.php
@@ -118,7 +118,7 @@ function submit(\User $user = null) {
unset($downtimeInfo['IMPACTED_IDS']);
if (!count($siteLevelDetails) > 1) {
- $downtimeInfo['SINGLE_TIMEZONE'] = true;
+ $downtimeInfo['SINGLE_SITE'] = true;
}
list(
diff --git a/htdocs/web_portal/views/downtime/confirm_add_downtime.php b/htdocs/web_portal/views/downtime/confirm_add_downtime.php
index 255c99c28..dcaf6a5f9 100644
--- a/htdocs/web_portal/views/downtime/confirm_add_downtime.php
+++ b/htdocs/web_portal/views/downtime/confirm_add_downtime.php
@@ -21,7 +21,7 @@
echo 'Please review your ';
if (!($edit)) {
- if ($params['SINGLE_TIMEZONE']) {
+ if ($params['SINGLE_SITE']) {
echo 'chosen site and the downtime ';
} else {
echo 'chosen sites and their downtimes ';
From bf7c1caceb0b158abeb6d04b9251e00cae578b8b Mon Sep 17 00:00:00 2001
From: Sae126V
Date: Thu, 31 Aug 2023 14:44:35 +0000
Subject: [PATCH 03/10] [GT-187] Remove support for mutiple timezones
---
.../controllers/downtime/add_downtime.php | 14 ++---
.../controllers/downtime/downtime_utils.php | 57 +------------------
.../controllers/downtime/edit_downtime.php | 14 ++---
3 files changed, 11 insertions(+), 74 deletions(-)
diff --git a/htdocs/web_portal/controllers/downtime/add_downtime.php b/htdocs/web_portal/controllers/downtime/add_downtime.php
index 3afc5a312..def60f42e 100644
--- a/htdocs/web_portal/controllers/downtime/add_downtime.php
+++ b/htdocs/web_portal/controllers/downtime/add_downtime.php
@@ -106,15 +106,11 @@ function submit(\User $user = null) {
$downtimeInfo['SINGLE_SITE'] = true;
}
- list(
- $siteLevelDetails,
- $serviceWithEndpoints
- ) = addParentServiceForEndpoints(
- $serviceWithEndpoints,
- $siteLevelDetails,
- false,
- $downtimeInfo['DOWNTIME']
- );
+ list($siteLevelDetails, $serviceWithEndpoints) =
+ addParentServiceForEndpoints(
+ $serviceWithEndpoints,
+ $siteLevelDetails
+ );
$downtimeInfo['SITE_LEVEL_DETAILS'] = $siteLevelDetails;
$downtimeInfo['SERVICE_WITH_ENDPOINTS'] = $serviceWithEndpoints;
diff --git a/htdocs/web_portal/controllers/downtime/downtime_utils.php b/htdocs/web_portal/controllers/downtime/downtime_utils.php
index ed5fffe36..9701a9945 100644
--- a/htdocs/web_portal/controllers/downtime/downtime_utils.php
+++ b/htdocs/web_portal/controllers/downtime/downtime_utils.php
@@ -67,19 +67,12 @@ function endpointToServiceMapping($impactedIDs)
* stores all affected service ID(s) and an
* `endpoints` that stores all affected
* endpoint ID(s).
- * @param bool $hasMultipleTimezones If the user selects multiple sites in
- * the web portal along with the option
- * "site timezone" it will be true;
- * otherwise, it will be false.
- * @param mixed $downtimeDetails Downtime information.
*
* @return array An array containing `$siteDetails` and `servWithEndpoints`.
*/
function addParentServiceForEndpoints(
$servWithEndpoints,
- $siteDetails,
- $hasMultipleTimezones,
- $downtimeDetails
+ $siteDetails
) {
foreach ($servWithEndpoints as $siteID => $siteData) {
$siteDetails[$siteID]['services'] = [];
@@ -87,13 +80,6 @@ function addParentServiceForEndpoints(
$newSite = \Factory::getSiteService()->getSite($siteID);
$siteDetails[$siteID]['siteName'] = $newSite->getShortName();
- if ($hasMultipleTimezones) {
- list(
- $siteDetails[$siteID]['START_TIMESTAMP'],
- $siteDetails[$siteID]['END_TIMESTAMP']
- ) = setLocalTimeForSites($downtimeDetails, $siteID);
- }
-
foreach (array_keys($siteData) as $serviceID) {
$servWithEndpoints[$siteID][$serviceID]['services'] = [];
$servWithEndpoints[$siteID][$serviceID]['services'][] = $serviceID;
@@ -105,47 +91,6 @@ function addParentServiceForEndpoints(
return [$siteDetails, $servWithEndpoints];
}
-/**
- * Converts UTC start and end timestamps to the local timezone
- * of a specific site based on that site's timezone.
- *
- * @param mixed $downtimeDetails Downtime information.
- * @param integer $siteID Site ID
- */
-function setLocalTimeForSites($downtimeDetails, $siteID)
-{
- $site = \Factory::getSiteService()->getSite($siteID);
-
- $siteTimezone = $site->getTimeZoneId();
-
- $startTimeAsString = $downtimeDetails['START_TIMESTAMP'];
- $utcEndTime = $downtimeDetails['END_TIMESTAMP'];
-
- $utcStartDateTime = DateTime::createFromFormat(
- 'd/m/Y H:i',
- $startTimeAsString,
- new DateTimeZone('UTC')
- );
- $utcEndDateTime = DateTime::createFromFormat(
- 'd/m/Y H:i',
- $utcEndTime,
- new DateTimeZone('UTC')
- );
-
- $targetSiteTimezone = new DateTimeZone($siteTimezone);
- $utcOffset = $targetSiteTimezone->getOffset($utcStartDateTime);
-
- // Calculate the equivalent time in the target timezone.
- // Ref: https://www.php.net/manual/en/datetime.modify.php
- $siteStartDateTime = $utcStartDateTime->modify("-$utcOffset seconds");
- $siteEndDateTime = $utcEndDateTime->modify("-$utcOffset seconds");
-
- return [
- $siteStartDateTime->format('d/m/Y H:i'),
- $siteEndDateTime->format('d/m/Y H:i')
- ];
-}
-
/**
* Unset a given variable, helper method to destroy the specified variables.
*
diff --git a/htdocs/web_portal/controllers/downtime/edit_downtime.php b/htdocs/web_portal/controllers/downtime/edit_downtime.php
index 4b26cc751..2ebf2e271 100644
--- a/htdocs/web_portal/controllers/downtime/edit_downtime.php
+++ b/htdocs/web_portal/controllers/downtime/edit_downtime.php
@@ -121,15 +121,11 @@ function submit(\User $user = null) {
$downtimeInfo['SINGLE_SITE'] = true;
}
- list(
- $siteLevelDetails,
- $serviceWithEndpoints
- ) = addParentServiceForEndpoints(
- $serviceWithEndpoints,
- $siteLevelDetails,
- false,
- $downtimeInfo['DOWNTIME']
- );
+ list($siteLevelDetails, $serviceWithEndpoints) =
+ addParentServiceForEndpoints(
+ $serviceWithEndpoints,
+ $siteLevelDetails
+ );
$downtimeInfo['SITE_LEVEL_DETAILS'] = $siteLevelDetails;
$downtimeInfo['SERVICE_WITH_ENDPOINTS'] = $serviceWithEndpoints;
From 484394936858aec44dacc18e35860bfe5998b29e Mon Sep 17 00:00:00 2001
From: Sae126V
Date: Thu, 31 Aug 2023 14:47:14 +0000
Subject: [PATCH 04/10] [GT-187] Change warning message in add downtime
---
htdocs/web_portal/views/downtime/add_downtime.php | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/htdocs/web_portal/views/downtime/add_downtime.php b/htdocs/web_portal/views/downtime/add_downtime.php
index 6435dd6ec..32953588a 100644
--- a/htdocs/web_portal/views/downtime/add_downtime.php
+++ b/htdocs/web_portal/views/downtime/add_downtime.php
@@ -69,9 +69,8 @@
From 211dec0779eba0010ab86031d19f600e4a84005d Mon Sep 17 00:00:00 2001
From: Sae126V
Date: Thu, 31 Aug 2023 14:51:25 +0000
Subject: [PATCH 05/10] [GT-187] Intend existing code
---
htdocs/web_portal/views/downtime/confirm_add_downtime.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/web_portal/views/downtime/confirm_add_downtime.php b/htdocs/web_portal/views/downtime/confirm_add_downtime.php
index dcaf6a5f9..be5da25fc 100644
--- a/htdocs/web_portal/views/downtime/confirm_add_downtime.php
+++ b/htdocs/web_portal/views/downtime/confirm_add_downtime.php
@@ -72,7 +72,7 @@
$endpoints = $data['endpoints'];
$service = \Factory::getServiceService()
->getService($serviceID);
- $safeHostName = xssafe($service->getHostname());
+ $safeHostName = xssafe($service->getHostname());
?>
From fc5a9e9d34c1aa79287549c90180a7a5f8c4611c Mon Sep 17 00:00:00 2001
From: Sae126V
Date: Thu, 31 Aug 2023 14:59:11 +0000
Subject: [PATCH 06/10] [GT-187] Change view for the list items
---
htdocs/web_portal/controllers/downtime/add_downtime.php | 6 ++----
htdocs/web_portal/controllers/downtime/edit_downtime.php | 6 ++----
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/htdocs/web_portal/controllers/downtime/add_downtime.php b/htdocs/web_portal/controllers/downtime/add_downtime.php
index def60f42e..a8c2547df 100644
--- a/htdocs/web_portal/controllers/downtime/add_downtime.php
+++ b/htdocs/web_portal/controllers/downtime/add_downtime.php
@@ -94,10 +94,8 @@ function submit(\User $user = null) {
//Show user confirmation screen with their input
$downtimeInfo = getDtDataFromWeb();
- list(
- $siteLevelDetails,
- $serviceWithEndpoints
- ) = endpointToServiceMapping($downtimeInfo['IMPACTED_IDS']);
+ list($siteLevelDetails, $serviceWithEndpoints) =
+ endpointToServiceMapping($downtimeInfo['IMPACTED_IDS']);
// Delete the unsorted IDs from the downtime info
unset($downtimeInfo['IMPACTED_IDS']);
diff --git a/htdocs/web_portal/controllers/downtime/edit_downtime.php b/htdocs/web_portal/controllers/downtime/edit_downtime.php
index 2ebf2e271..7d238932f 100644
--- a/htdocs/web_portal/controllers/downtime/edit_downtime.php
+++ b/htdocs/web_portal/controllers/downtime/edit_downtime.php
@@ -109,10 +109,8 @@ function submit(\User $user = null) {
$downtimeInfo = getDtDataFromWeb();
//Need to sort the impacted_ids into impacted services and impacted endpoints
- list(
- $siteLevelDetails,
- $serviceWithEndpoints
- ) = endpointToServiceMapping($downtimeInfo['IMPACTED_IDS']);
+ list($siteLevelDetails, $serviceWithEndpoints) =
+ endpointToServiceMapping($downtimeInfo['IMPACTED_IDS']);
// Delete the unsorted IDs from the downtime info
unset($downtimeInfo['IMPACTED_IDS']);
From 294ebd1283736a0778bf80a6b070150b8a7fab5a Mon Sep 17 00:00:00 2001
From: Sae126V
Date: Thu, 31 Aug 2023 15:01:20 +0000
Subject: [PATCH 07/10] [GT-187] Add a space for anchor tag
---
htdocs/web_portal/views/downtime/added_downtime.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/htdocs/web_portal/views/downtime/added_downtime.php b/htdocs/web_portal/views/downtime/added_downtime.php
index 42bd8cb54..0911934c2 100644
--- a/htdocs/web_portal/views/downtime/added_downtime.php
+++ b/htdocs/web_portal/views/downtime/added_downtime.php
@@ -16,10 +16,10 @@
echo '';
foreach ($params['submittedDowntimes'] as $siteName => $downtimeDetails) {
echo '- ';
- echo $siteName . ':';
+ echo $siteName . ': ';
echo ' Downtime ' . $downtimeDetails->getId() . '';
+ echo '">Downtime ' . $downtimeDetails->getId() . '';
echo '
';
}
echo '
';
From 2fce820b84488cbc2ba64ea363c122c25f05a2b7 Mon Sep 17 00:00:00 2001
From: Sae126V
Date: Thu, 31 Aug 2023 15:24:46 +0000
Subject: [PATCH 08/10] [GT-187] Add comment to give insight on variables.
---
htdocs/web_portal/controllers/downtime/downtime_utils.php | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/htdocs/web_portal/controllers/downtime/downtime_utils.php b/htdocs/web_portal/controllers/downtime/downtime_utils.php
index 9701a9945..b85cce426 100644
--- a/htdocs/web_portal/controllers/downtime/downtime_utils.php
+++ b/htdocs/web_portal/controllers/downtime/downtime_utils.php
@@ -44,6 +44,12 @@ function endpointToServiceMapping($impactedIDs)
* sort between endpoints and services using the prepended letter.
*/
foreach ($impactedIDs as $id) {
+ /**
+ * `$siteNumber` => It's about Site ID
+ * `$parentService` => It's about service ID endpoint belongs too
+ * `idType` => It's about to differentiate
+ * the endpoint vs service selection.
+ */
list($siteNumber, $parentService, $idType) = explode(':', $id);
$type = strpos($idType, 's') !== false ? 'services' : 'endpoints';
From 876e49092248975f333e008f147f1ca5161ca058 Mon Sep 17 00:00:00 2001
From: Sae126V
Date: Fri, 1 Sep 2023 09:06:26 +0000
Subject: [PATCH 09/10] [GT-187] Update copyright information
---
htdocs/web_portal/controllers/downtime/downtime_utils.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/htdocs/web_portal/controllers/downtime/downtime_utils.php b/htdocs/web_portal/controllers/downtime/downtime_utils.php
index b85cce426..34464560a 100644
--- a/htdocs/web_portal/controllers/downtime/downtime_utils.php
+++ b/htdocs/web_portal/controllers/downtime/downtime_utils.php
@@ -3,13 +3,12 @@
/*_____________________________________________________________________________
*=============================================================================
* File: downtime_utils.php
- * Author: GOCDB DEV TEAM, STFC.
* Description: Helper functions which can be re-used while adding
* or editing a downtime.
*
* License information
*
- * Copyright 2013 STFC
+ * Copyright 2023 STFC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
From 4a40ac030928fe34530395e64f2f2240c32ce6eb Mon Sep 17 00:00:00 2001
From: Sae126V
Date: Tue, 12 Sep 2023 12:54:56 +0000
Subject: [PATCH 10/10] [GT-187] Simplified the flow - Only one variable
---
.../controllers/downtime/add_downtime.php | 49 ++++++-----
.../controllers/downtime/downtime_utils.php | 81 +++++--------------
.../controllers/downtime/edit_downtime.php | 38 +++++----
.../downtime/view_endpoint_tree.php | 25 +++---
.../views/downtime/add_downtime.php | 47 +++++------
.../views/downtime/added_downtime.php | 2 +
.../views/downtime/confirm_add_downtime.php | 48 ++++++-----
...wntime_edit_view_nested_endpoints_list.php | 6 +-
.../views/downtime/edit_downtime.php | 5 +-
.../downtime/view_nested_endpoints_list.php | 6 +-
10 files changed, 148 insertions(+), 159 deletions(-)
diff --git a/htdocs/web_portal/controllers/downtime/add_downtime.php b/htdocs/web_portal/controllers/downtime/add_downtime.php
index a8c2547df..bf352e178 100644
--- a/htdocs/web_portal/controllers/downtime/add_downtime.php
+++ b/htdocs/web_portal/controllers/downtime/add_downtime.php
@@ -76,16 +76,32 @@ function submit(\User $user = null) {
* If confirmed by an user, submit the details of affected services
* and endpoints along with other details for each individual site.
*/
+ $params = [];
$downtimeInfo = json_decode($_POST['newValues'], TRUE);
$serv = \Factory::getDowntimeService();
$downtimeInfo = unsetVariables($downtimeInfo, 'add');
- $params = [];
- foreach ($downtimeInfo['SITE_LEVEL_DETAILS'] as $siteID) {
- $downtimeInfo['Impacted_Services'] = $siteID['services'];
- $downtimeInfo['Impacted_Endpoints'] = $siteID['endpoints'];
+ foreach (
+ $downtimeInfo['SERVICE_WITH_ENDPOINTS'] as $siteID => $serviceIDs
+ ) {
+ $serviceIDList = [];
+ $endpointIDList = [];
+
+ foreach ($serviceIDs as $serviceID => $endpointsInfo) {
+ $serviceIDList[] = $serviceID;
+ $endpointIDList = array_merge(
+ $endpointIDList,
+ $endpointsInfo['endpointIDs']
+ );
+ }
+
+ $downtimeInfo['Impacted_Services'] = $serviceIDList;
+ $downtimeInfo['Impacted_Endpoints'] = $endpointIDList;
- $params['submittedDowntimes'][$siteID['siteName']] =
+ $siteDetails = \Factory::getSiteService()->getSite($siteID);
+ $siteName = $siteDetails->getShortName();
+
+ $params['submittedDowntimes'][$siteName] =
$serv->addDowntime($downtimeInfo, $user);
}
@@ -94,25 +110,20 @@ function submit(\User $user = null) {
//Show user confirmation screen with their input
$downtimeInfo = getDtDataFromWeb();
- list($siteLevelDetails, $serviceWithEndpoints) =
- endpointToServiceMapping($downtimeInfo['IMPACTED_IDS']);
+ $downtimeInfo['SERVICE_WITH_ENDPOINTS'] = endpointToServiceMapping(
+ $downtimeInfo['IMPACTED_IDS']
+ );
- // Delete the unsorted IDs from the downtime info
+ /**
+ * Delete the `IMPACTED_IDS` from the `downtimeInfo` as we
+ * extracted the details we need in `endpointToServiceMapping`.
+ */
unset($downtimeInfo['IMPACTED_IDS']);
- if (!count($siteLevelDetails) > 1) {
- $downtimeInfo['SINGLE_SITE'] = true;
+ if (count($downtimeInfo['SERVICE_WITH_ENDPOINTS']) === 1) {
+ $downtimeInfo['SELECTED_SINGLE_SITE'] = true;
}
- list($siteLevelDetails, $serviceWithEndpoints) =
- addParentServiceForEndpoints(
- $serviceWithEndpoints,
- $siteLevelDetails
- );
-
- $downtimeInfo['SITE_LEVEL_DETAILS'] = $siteLevelDetails;
- $downtimeInfo['SERVICE_WITH_ENDPOINTS'] = $serviceWithEndpoints;
-
show_view("downtime/confirm_add_downtime.php", $downtimeInfo);
}
}
diff --git a/htdocs/web_portal/controllers/downtime/downtime_utils.php b/htdocs/web_portal/controllers/downtime/downtime_utils.php
index 34464560a..a8cd1bee5 100644
--- a/htdocs/web_portal/controllers/downtime/downtime_utils.php
+++ b/htdocs/web_portal/controllers/downtime/downtime_utils.php
@@ -22,78 +22,42 @@
/*====================================================== */
require_once __DIR__ . '/../../../../lib/Gocdb_Services/Factory.php';
-use DateTime;
-use DateTimeZone;
-
/**
* Sorts the impacted IDs into impacted services and impacted endpoints.
*
* @param array $impactedIDs An array of `impactedIDs` which user has selected.
*
- * @return array An array containing
- * `$siteLevelDetails` and `serviceWithEndpoints`.
+ * @return array `serviceWithEndpoints` An array with
+ * 'SiteID->serviceID->EndpointID(s)' details.
*/
function endpointToServiceMapping($impactedIDs)
{
- $siteLevelDetails = [];
$serviceWithEndpoints = [];
/**
- * For each impacted ID,
- * sort between endpoints and services using the prepended letter.
+ * For each impacted ID, sort between endpoints and services
+ * using the prepended letter.
*/
- foreach ($impactedIDs as $id) {
+ foreach ($impactedIDs as $impactedID) {
+ $indexPosition = 0;
+
+ list($siteID, $serviceID, $idType) = explode(':', $impactedID);
/**
- * `$siteNumber` => It's about Site ID
- * `$parentService` => It's about service ID endpoint belongs too
- * `idType` => It's about to differentiate
- * the endpoint vs service selection.
+ * `idType` => It will have either `s` followed by service ID or
+ * `e` followed by endpoint ID.
*/
- list($siteNumber, $parentService, $idType) = explode(':', $id);
-
- $type = strpos($idType, 's') !== false ? 'services' : 'endpoints';
- $id = str_replace(['s', 'e'], '', $idType);
-
- $siteLevelDetails[$siteNumber][$type][] = $id;
- $serviceWithEndpoints[$siteNumber][$parentService][$type][] = $id;
- }
-
- return [$siteLevelDetails, $serviceWithEndpoints];
-}
+ $trimmedID = str_replace(['s', 'e'], '', $idType);
-/**
- * If a user has selected endpoints but not the parent service here
- * we will add the service to maintain the link between a downtime
- * having both the service and the endpoint.
- *
- * @param array $servWithEndpoints Used for displaying affected service
- * with endpoint(s).
- * @param array $siteDetails Each site ID will have a `services` that
- * stores all affected service ID(s) and an
- * `endpoints` that stores all affected
- * endpoint ID(s).
- *
- * @return array An array containing `$siteDetails` and `servWithEndpoints`.
- */
-function addParentServiceForEndpoints(
- $servWithEndpoints,
- $siteDetails
-) {
- foreach ($servWithEndpoints as $siteID => $siteData) {
- $siteDetails[$siteID]['services'] = [];
-
- $newSite = \Factory::getSiteService()->getSite($siteID);
- $siteDetails[$siteID]['siteName'] = $newSite->getShortName();
-
- foreach (array_keys($siteData) as $serviceID) {
- $servWithEndpoints[$siteID][$serviceID]['services'] = [];
- $servWithEndpoints[$siteID][$serviceID]['services'][] = $serviceID;
- // Ensuring that service IDs are unique for the selected sites.
- $siteDetails[$siteID]['services'][] = $serviceID;
+ if (strpos($idType, 's') === $indexPosition) {
+ continue;
}
+
+ // Using '+' to ensure we have an integer value after type coercion.
+ $serviceWithEndpoints[$siteID][$serviceID]['endpointIDs'][] =
+ +$trimmedID;
}
- return [$siteDetails, $servWithEndpoints];
+ return $serviceWithEndpoints;
}
/**
@@ -105,15 +69,12 @@ function addParentServiceForEndpoints(
*/
function unsetVariables($downtimeObj, $fromLocation)
{
- if ($fromLocation == "add") {
- unset($downtimeObj['SERVICE_WITH_ENDPOINTS']);
- unset($downtimeObj['SINGLE_SITE']);
- } else {
+ if ($fromLocation == "edit") {
unset($downtimeObj['DOWNTIME']['EXISTINGID']);
unset($downtimeObj['isEdit']);
- unset($downtimeObj['SERVICE_WITH_ENDPOINTS']);
- unset($downtimeObj['SINGLE_SITE']);
}
+ unset($downtimeObj['SELECTED_SINGLE_SITE']);
+
return $downtimeObj;
}
diff --git a/htdocs/web_portal/controllers/downtime/edit_downtime.php b/htdocs/web_portal/controllers/downtime/edit_downtime.php
index 7d238932f..33d28d519 100644
--- a/htdocs/web_portal/controllers/downtime/edit_downtime.php
+++ b/htdocs/web_portal/controllers/downtime/edit_downtime.php
@@ -94,12 +94,25 @@ function submit(\User $user = null) {
$dt = $serv->getDowntime($downtimeInfo['DOWNTIME']['EXISTINGID']);
$downtimeInfo = unsetVariables($downtimeInfo, 'edit');
- foreach ($downtimeInfo['SITE_LEVEL_DETAILS'] as $siteIDs) {
- $downtimeInfo['Impacted_Services'] = $siteIDs['services'];
- $downtimeInfo['Impacted_Endpoints'] = $siteIDs['endpoints'];
+ foreach (
+ $downtimeInfo['SERVICE_WITH_ENDPOINTS'] as $serviceIDs
+ ) {
+ $serviceIDList = [];
+ $endpointIDList = [];
+
+ foreach ($serviceIDs as $serviceID => $endpointsInfo) {
+ $serviceIDList[] = $serviceID;
+ $endpointIDList = array_merge(
+ $endpointIDList,
+ $endpointsInfo['endpointIDs']
+ );
+ }
+
+ $downtimeInfo['Impacted_Services'] = $serviceIDList;
+ $downtimeInfo['Impacted_Endpoints'] = $endpointIDList;
}
- unset($downtimeInfo['SITE_LEVEL_DETAILS']);
+ unset($downtimeInfo['SERVICE_WITH_ENDPOINTS']);
$params['dt'] = $serv->editDowntime($dt, $downtimeInfo, $user);
@@ -109,24 +122,17 @@ function submit(\User $user = null) {
$downtimeInfo = getDtDataFromWeb();
//Need to sort the impacted_ids into impacted services and impacted endpoints
- list($siteLevelDetails, $serviceWithEndpoints) =
- endpointToServiceMapping($downtimeInfo['IMPACTED_IDS']);
+ $downtimeInfo['SERVICE_WITH_ENDPOINTS'] = endpointToServiceMapping(
+ $downtimeInfo['IMPACTED_IDS']
+ );
// Delete the unsorted IDs from the downtime info
unset($downtimeInfo['IMPACTED_IDS']);
- if (!count($siteLevelDetails) > 1) {
- $downtimeInfo['SINGLE_SITE'] = true;
+ if (count($downtimeInfo['SERVICE_WITH_ENDPOINTS']) === 1) {
+ $downtimeInfo['SELECTED_SINGLE_SITE'] = true;
}
- list($siteLevelDetails, $serviceWithEndpoints) =
- addParentServiceForEndpoints(
- $serviceWithEndpoints,
- $siteLevelDetails
- );
-
- $downtimeInfo['SITE_LEVEL_DETAILS'] = $siteLevelDetails;
- $downtimeInfo['SERVICE_WITH_ENDPOINTS'] = $serviceWithEndpoints;
//Pass the edit variable so the confirm_add view works as the confirm edit view.
$downtimeInfo['isEdit'] = true;
show_view("downtime/confirm_add_downtime.php", $downtimeInfo);
diff --git a/htdocs/web_portal/controllers/downtime/view_endpoint_tree.php b/htdocs/web_portal/controllers/downtime/view_endpoint_tree.php
index c8451d787..d2be2bed4 100644
--- a/htdocs/web_portal/controllers/downtime/view_endpoint_tree.php
+++ b/htdocs/web_portal/controllers/downtime/view_endpoint_tree.php
@@ -36,14 +36,17 @@ function getServiceandEndpointList() {
throw new Exception("Please select at least one site.");
}
- $services = new ArrayCollection();
+ $siteIdWithServices = new ArrayCollection();
- foreach ($siteIDs as $value) {
- $site = \Factory::getSiteService()->getSite($value);
- $services[$value] = $site->getServices();
+ foreach ($siteIDs as $siteID) {
+ // Using '+' to ensure we have integer value after type coercion.
+ $siteID = +$siteID;
+ $site = \Factory::getSiteService()->getSite($siteID);
+ $siteIdWithServices[$siteID] = $site->getServices();
}
- $params['services'] = $services;
+ $params['siteIdWithServices'] = $siteIdWithServices;
+
show_view("downtime/view_nested_endpoints_list.php", $params, null, true);
}
@@ -65,14 +68,16 @@ function editDowntimePopulateEndpointTree() {
throw new Exception("A downtime id must be specified");
}
- $services = new ArrayCollection();
+ $siteIdWithServices = new ArrayCollection();
- foreach ($siteIDs as $value) {
- $site = \Factory::getSiteService()->getSite($value);
- $services[$value] = $site->getServices();
+ foreach ($siteIDs as $siteID) {
+ // Using '+' to ensure we have integer value after type coercion.
+ $siteID = +$siteID;
+ $site = \Factory::getSiteService()->getSite($siteID);
+ $siteIdWithServices[$siteID] = $site->getServices();
}
- $params['services'] = $services;
+ $params['siteIdWithServices'] = $siteIdWithServices;
$downtime = \Factory::getDowntimeService()->getDowntime($_REQUEST['dt_id']);
$params['downtime'] = $downtime;
diff --git a/htdocs/web_portal/views/downtime/add_downtime.php b/htdocs/web_portal/views/downtime/add_downtime.php
index 32953588a..b5643d344 100644
--- a/htdocs/web_portal/views/downtime/add_downtime.php
+++ b/htdocs/web_portal/views/downtime/add_downtime.php
@@ -69,8 +69,8 @@
@@ -242,7 +242,7 @@ class="form-control"
validate();
});
- hasSitesWithSingleTimezones();
+ selectedValidTimezoneUsecase();
});
@@ -305,20 +305,21 @@ function updateStartEndTimesInUtc(){
}
}
- function hasSitesWithSingleTimezones()
+ function selectedValidTimezoneUsecase()
{
- let siteId = $('#Select_Sites').val();
- let selectedSiteTZ = $('#siteRadioButton').is(':checked');
- let hasSingleTimezone = true;
+ let siteID = $('#Select_Sites').val();
+ let selectedSiteTz = $('#siteRadioButton').is(':checked');
+ let validSelection = true;
+
+ if ((siteID && siteID.length > 1) && selectedSiteTz) {
+ validSelection = false;
- if((siteId && siteId.length > 1) && selectedSiteTZ) {
- hasSingleTimezone = false;
$('#invalidSelection').show();
} else {
$('#invalidSelection').hide();
}
- return hasSingleTimezone;
+ return validSelection;
}
/*
@@ -466,15 +467,15 @@ function validate(){
}
//----------Verify whether the site has mutiple timezones----------//
- const hasSingleTimezone = hasSitesWithSingleTimezones();
+ const timezoneValid = selectedValidTimezoneUsecase();
//----------Set the Button based on validate status-------------//
if (
- epValid &&
- severityValid &&
- descriptionValid &&
- datesValid &&
- hasSingleTimezone
+ epValid
+ && severityValid
+ && descriptionValid
+ && datesValid
+ && timezoneValid
) {
$('#submitDowntime_btn').addClass('btn btn-success');
$('#submitDowntime_btn').prop('disabled', false);
@@ -534,9 +535,8 @@ function getSitesServices(){
$('#chooseEndpoints').empty(); //Remove any previous content from the endpoints select list
$('#chooseServices').load(
'index.php?Page_Type=Downtime_view_endpoint_tree',
- {site_id: siteId},
- function(response, status, xhr)
- {
+ { site_id: siteId },
+ function(response, status, xhr) {
if (status == "success") {
validate();
}
@@ -569,14 +569,14 @@ function updateSiteTimezoneVars(siteId){
//console.log('fetching selected site timezone label');
$.get(
'index.php',
- {Page_Type: 'Add_Downtime', siteid_timezone: siteId[0]},
- function(data)
- {
- var jsonRsp = JSON.parse(data);
+ { Page_Type: 'Add_Downtime', siteid_timezone: siteId[0] },
+ function(data) {
+ let jsonRsp = JSON.parse(data);
// Update global variables - used when calculating DT rules
TARGETTIMEZONEID = jsonRsp[0];
// Returns the targetTimezone offset in seconds from UTC
TARGETTIMEZONEOFFSETFROMUTCSECS = jsonRsp[1];
+
$('#siteTimezoneText').val(TARGETTIMEZONEID);
updateStartEndTimesInUtc();
@@ -585,6 +585,7 @@ function(data)
} else {
TARGETTIMEZONEID = "UTC";
TARGETTIMEZONEOFFSETFROMUTCSECS = 0;
+
$('#siteTimezoneText').val(TARGETTIMEZONEID);
updateStartEndTimesInUtc();
diff --git a/htdocs/web_portal/views/downtime/added_downtime.php b/htdocs/web_portal/views/downtime/added_downtime.php
index 0911934c2..b7332e704 100644
--- a/htdocs/web_portal/views/downtime/added_downtime.php
+++ b/htdocs/web_portal/views/downtime/added_downtime.php
@@ -14,6 +14,7 @@
}
echo '';
+
foreach ($params['submittedDowntimes'] as $siteName => $downtimeDetails) {
echo '- ';
echo $siteName . ': ';
@@ -22,6 +23,7 @@
echo '">Downtime ' . $downtimeDetails->getId() . '';
echo '
';
}
+
echo '
';
?>
\ No newline at end of file
diff --git a/htdocs/web_portal/views/downtime/confirm_add_downtime.php b/htdocs/web_portal/views/downtime/confirm_add_downtime.php
index be5da25fc..6138a5b24 100644
--- a/htdocs/web_portal/views/downtime/confirm_add_downtime.php
+++ b/htdocs/web_portal/views/downtime/confirm_add_downtime.php
@@ -21,7 +21,7 @@
echo 'Please review your ';
if (!($edit)) {
- if ($params['SINGLE_SITE']) {
+ if ($params['SELECTED_SINGLE_SITE']) {
echo 'chosen site and the downtime ';
} else {
echo 'chosen sites and their downtimes ';
@@ -54,24 +54,25 @@
xecho($params['DOWNTIME']['END_TIMESTAMP']);
?>
- $siteDetails) : ?>
+ $serviceIDs) : ?>
getSite($siteID);
+ $siteName = $siteDetails->getShortName();
- echo '- Site Name: ';
- echo $siteName;
- echo '
';
+ echo '- Site Name: ';
+ echo $siteName;
+ echo '
';
?>
-
Affecting Service and Endpoint(s):
- $data) : ?>
+ $endpointsInfo) : ?>
getService($serviceID);
+ ->getService($serviceID);
$safeHostName = xssafe($service->getHostname());
?>
@@ -85,19 +86,22 @@
);
echo $safeHostName;
?>
-
- getEndpoint($id);
- if($endpoint->getName() != ''){
- $name = xssafe($endpoint->getName());
- }else{
- $name = xssafe("myEndpoint");
- }
- echo "- " . $name . "
";
- }
- ?>
-
+
+ getEndpoint($endpointID);
+
+ if ($endpoint->getName() != '') {
+ $name = xssafe($endpoint->getName());
+ } else {
+ $name = xssafe("myEndpoint");
+ }
+
+ echo "- " . $name . "
";
+ }
+ ?>
+
diff --git a/htdocs/web_portal/views/downtime/downtime_edit_view_nested_endpoints_list.php b/htdocs/web_portal/views/downtime/downtime_edit_view_nested_endpoints_list.php
index 2727fbbd6..f367c0ff1 100644
--- a/htdocs/web_portal/views/downtime/downtime_edit_view_nested_endpoints_list.php
+++ b/htdocs/web_portal/views/downtime/downtime_edit_view_nested_endpoints_list.php
@@ -1,5 +1,5 @@
$siteServiceList) {
- foreach ($siteServiceList as $service) {
+foreach ($siteIdWithServices as $siteID => $services) {
+ foreach ($services as $service) {
$count=0;
// Set the html 'SELECTED' attribute on the