Ejemplo n.º 1
0
/**
 * 
 * @param \User $user current user
 * @throws Exception
 */
function submit(\User $user = null)
{
    //Check if this is a confirmed submit or intial submit
    $confirmed = $_POST['CONFIRMED'];
    if ($confirmed == true) {
        //Downtime is confirmed, submit it
        $downtimeInfo = json_decode($_POST['newValues'], TRUE);
        $serv = \Factory::getDowntimeService();
        $dt = $serv->getDowntime($downtimeInfo['DOWNTIME']['EXISTINGID']);
        unset($downtimeInfo['DOWNTIME']['EXISTINGID']);
        unset($downtimeInfo['isEdit']);
        $params['dt'] = $serv->editDowntime($dt, $downtimeInfo, $user);
        show_view("downtime/edited_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'];
        $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;
        $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;
        //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);
    }
}
Ejemplo n.º 2
0
function view()
{
    require_once __DIR__ . '/../utils.php';
    require_once __DIR__ . '/../../../web_portal/components/Get_User_Principle.php';
    if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) {
        throw new Exception("An id must be specified");
    }
    $downtime = \Factory::getDowntimeService()->getDowntime($_REQUEST['id']);
    if ($downtime == null) {
        throw new Exception('No downtime with id [' . $_REQUEST['id'] . ']');
    }
    $dn = Get_User_Principle();
    $user = \Factory::getUserService()->getUserByPrinciple($dn);
    $params['portalIsReadOnly'] = portalIsReadOnlyAndUserIsNotAdmin($user);
    $params['downtime'] = $downtime;
    $title = $downtime->getDescription();
    show_view("downtime/view_downtime.php", $params, $title);
}
Ejemplo n.º 3
0
function view()
{
    require_once __DIR__ . '/../utils.php';
    require_once __DIR__ . '/../../../web_portal/components/Get_User_Principle.php';
    $dn = Get_User_Principle();
    $user = \Factory::getUserService()->getUserByPrinciple($dn);
    $params['portalIsReadOnly'] = portalIsReadOnlyAndUserIsNotAdmin($user);
    $timePeriod = 1;
    if (isset($_REQUEST['timePeriod'])) {
        $timePeriod = $_REQUEST['timePeriod'];
    }
    $days = 7 * $timePeriod;
    $windowStart = date("Y-m-d");
    $windowEnd = date_add(date_create(date("Y-m-d")), date_interval_create_from_date_string($days . ' days'));
    $downtimesA = \Factory::getDowntimeService()->getActiveDowntimes();
    $downtimesI = \Factory::getDowntimeService()->getImminentDowntimes($windowStart, $windowEnd);
    $params['timePeriod'] = $timePeriod;
    $params['downtimesActive'] = $downtimesA;
    $params['downtimesImmenent'] = $downtimesI;
    show_view("downtime/downtimes_overview.php", $params);
}
Ejemplo n.º 4
0
/**
 * Controller for an edit downtime request
 * @global array $_POST only set if the browser has POSTed data
 * @return null
 */
function endDt()
{
    require_once __DIR__ . '/../../../../lib/Gocdb_Services/Factory.php';
    require_once __DIR__ . '/../../../../htdocs/web_portal/components/Get_User_Principle.php';
    require_once __DIR__ . '/../utils.php';
    if (!isset($_POST['id']) || !is_numeric($_POST['id'])) {
        throw new Exception("A downtime id must be specified");
    }
    $serv = \Factory::getDowntimeService();
    $dt = $serv->getDowntime($_POST['id']);
    if ($dt == null) {
        throw new Exception("No downtime with that id");
    }
    $dn = Get_User_Principle();
    $user = \Factory::getUserService()->getUserByPrinciple($dn);
    //Check the portal is not in read only mode, returns exception if it is and user is not an admin
    checkPortalIsNotReadOnlyOrUserIsAdmin($user);
    $serv->endDowntime($dt, $user);
    $params = array('downtime' => $dt);
    show_view("downtime/ended_downtime.php", $params);
}
Ejemplo n.º 5
0
/**
 * Controller for a delete downtime request
 * @return null
 */
function delete()
{
    require_once __DIR__ . '/../../../../lib/Gocdb_Services/Factory.php';
    require_once __DIR__ . '/../../../../htdocs/web_portal/components/Get_User_Principle.php';
    require_once __DIR__ . '/../utils.php';
    $dn = Get_User_Principle();
    $user = \Factory::getUserService()->getUserByPrinciple($dn);
    if (is_null($user)) {
        throw new \Exception("Unregistered users can't delete a downtime.");
    }
    //Check the portal is not in read only mode, returns exception if it is and user is not an admin
    checkPortalIsNotReadOnlyOrUserIsAdmin($user);
    if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) {
        throw new Exception("An id must be specified");
    }
    $serv = \Factory::getDowntimeService();
    if (isset($_REQUEST['id'])) {
        $dt = $serv->getDowntime($_REQUEST['id']);
        if ($dt != null) {
            $serv->deleteDowntime($dt, $user);
        }
    }
    show_view('downtime/deleted_downtime.php');
}