public function copy_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('svc_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $svcName = $this->getParam('svcName');
     $svcInfo = $this->fetchSvcInfo($deployment, 'copy_write', $modrevision);
     if (RevDeploy::existsDeploymentSvc($deployment, $svcName, $modrevision) === true) {
         $viewData->error = 'Service template information exists for ' . $svcName . ' into ' . $deployment . ' Deployment';
         $viewData->action = 'copy_write';
         $viewData->deployment = $deployment;
         $viewData->svctemplates = RevDeploy::getCommonMergedDeploymentSvcTemplates($deployment, $modrevision);
         $viewData->svcgroups = RevDeploy::getCommonMergedDeploymentSvcGroups($deployment, $modrevision);
         $viewData->svcchkcmds = RevDeploy::getCommonMergedDeploymentCommands($deployment, $modrevision);
         $viewData->timeperiods = RevDeploy::getCommonMergedDeploymentTimeperiods($deployment, $modrevision);
         $viewData->contacts = RevDeploy::getCommonMergedDeploymentContacts($deployment, $modrevision);
         $viewData->contactgroups = RevDeploy::getCommonMergedDeploymentContactGroups($deployment, $modrevision);
         $viewData->svcInfo = $svcInfo;
         $this->sendResponse('svc_action_stage', $viewData);
     }
     if (RevDeploy::createDeploymentSvc($deployment, $svcName, $svcInfo, $modrevision) === false) {
         $viewData->header = $this->getErrorHeader('svc_error');
         $viewData->error = 'Unable to write service tempalte information for ' . $svcName . ' into ' . $deployment . ' Deployment';
         $this->sendError('generic_error', $viewData);
     }
     $viewData->deployment = $deployment;
     $viewData->svc = $svcName;
     $this->sendResponse('svc_write', $viewData);
 }
 public function copy_common_stage()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('timeperiod_error');
     $timeName = $this->getParam('timeperiod');
     if ($timeName === false) {
         $viewData->header = $this->getErrorHeader('timeperiod_error');
         $viewData->error = 'Unable to detect timeperiod specified in post params';
         $this->sendError('generic_error', $viewData);
     }
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $commonRepo = RevDeploy::getDeploymentCommonRepo($deployment);
     $commonrevision = RevDeploy::getDeploymentRev($commonRepo);
     $timeInfo = RevDeploy::getDeploymentTimeperiodInfo($commonRepo, $timeName, $commonrevision);
     if (empty($timeInfo)) {
         $viewData->header = $this->getErrorHeader('timeperiod_error');
         $viewData->error = 'Unable to fetch timeperiod information for ' . $timeName . ' from data store';
         $this->sendError('generic_error', $viewData);
     }
     $timeData = RevDeploy::getDeploymentTimeperiodData($commonRepo, $timeName, $commonrevision);
     if (empty($timeData)) {
         $viewData->header = $this->getErrorHeader('timeperiod_error');
         $viewData->error = 'Unable to fetch timeperiod data for ' . $timeName . ' from data store';
         $this->sendError('generic_error', $viewData);
     }
     $viewData->timeperiods = RevDeploy::getCommonMergedDeploymentTimeperiods($deployment, $modrevision);
     $viewData->deployment = $deployment;
     $viewData->timeInfo = $timeInfo;
     unset($_SESSION[$deployment]['timeperiods']);
     $_SESSION[$deployment]['timeperiods'] = array();
     foreach ($timeData as $md5Key => $tpArray) {
         $_SESSION[$deployment]['timeperiods'][$md5Key] = $tpArray;
     }
     $viewData->action = 'copy_write';
     $this->sendResponse('timeperiod_action_stage', $viewData);
 }
 public function copy_to_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('contact_error');
     $contactName = $this->getParam('contactName');
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $contactInfo = $this->fetchContactInfo($deployment, 'copy_to_write', $modrevision);
     $todeployment = $this->getParam('todeployment');
     if ($todeployment === false) {
         $viewData->error = 'Unable to detect contact to copy contact to';
         $viewData->availdeployments = $this->getDeploymentsAvailToUser();
         $viewData->contactInfo = $contactInfo;
         $viewData->contacttemplates = RevDeploy::getCommonMergedDeploymentContactTemplates($deployment, $modrevision);
         $viewData->notifycmds = RevDeploy::getCommonMergedDeploymentNotifyCommands($deployment, $modrevision);
         $viewData->timeperiods = RevDeploy::getCommonMergedDeploymentTimeperiods($deployment, $modrevision);
         $viewData->deployment = $deployment;
         $viewData->action = 'copy_to_write';
         $this->sendResponse('contact_action_stage', $viewData);
     }
     $this->checkGroupAuth($todeployment);
     $this->checkDeploymentRevStatus($todeployment);
     $tdRev = RevDeploy::getDeploymentNextRev($todeployment);
     if (RevDeploy::existsDeploymentContact($todeployment, $contactName, $tdRev) === true) {
         RevDeploy::modifyDeploymentContact($todeployment, $contactName, $contactInfo, $tdRev);
     } else {
         RevDeploy::createDeploymentContact($todeployment, $contactName, $contactInfo, $tdRev);
     }
     $viewData->deployment = $deployment;
     $viewData->todeployment = $todeployment;
     $viewData->contact = $contactName;
     $this->sendResponse('contact_write', $viewData);
 }
    $request = $app->request();
    $commonMerge = $request->get('common');
    // Load up Current Timeperiods or Staged Timeperiods
    if ($staged == 1) {
        $revs = RevDeploy::getDeploymentRevs($deployment);
        if ($revs['currrev'] == $revs['nextrev']) {
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect staged revision to reference");
            $app->halt(404, $apiResponse->returnJson());
        }
        $deployRev = $revs['nextrev'];
    } else {
        $deployRev = RevDeploy::getDeploymentRev($deployment);
    }
    $apiResponse = new APIViewData(0, $deployment, false);
    if ($commonMerge == 1) {
        $apiResponse->setExtraResponseData('timeperiods', RevDeploy::getCommonMergedDeploymentTimeperiods($deployment, $deployRev));
    } else {
        $apiResponse->setExtraResponseData('timeperiods', RevDeploy::getDeploymentTimeperiodswInfo($deployment, $deployRev));
    }
    $apiResponse->printJson();
})->name('saigon-api-get-timeperiods');
$app->get('/sapi/timeperiods/:deployment(/:staged)', function ($deployment, $staged = false) use($app) {
    check_deployment_exists($app, $deployment);
    $request = $app->request();
    $commonMerge = $request->get('common');
    // Load up Current Timeperiods or Staged Timeperiods
    if ($staged == 1) {
        $revs = RevDeploy::getDeploymentRevs($deployment);
        if ($revs['currrev'] == $revs['nextrev']) {
            $apiResponse = new APIViewData(1, $deployment, "Unable to detect staged revision to reference");
            $app->halt(404, $apiResponse->returnJson());
 public function copy_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('contact_template_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $contactName = $this->getParam('contactName');
     $contactInfo = $this->fetchContactTemplateInfo($deployment, 'copy_write', $modrevision);
     if (RevDeploy::existsDeploymentContactTemplate($deployment, $contactName, $modrevision) === true) {
         $viewData->error = 'Contact template information exists for ' . $contactName . ' into ' . $deployment . ' Deployment';
         $viewData->action = 'copy_write';
         $viewData->contacttemplate = $contactName;
         $viewData->deployment = $deployment;
         $viewData->contacttemplates = RevDeploy::getCommonMergedDeploymentContactTemplates($deployment, $modrevision);
         $viewData->notifycmds = RevDeploy::getCommonMergedDeploymentNotifyCommands($deployment, $modrevision);
         $viewData->timeperiods = RevDeploy::getCommonMergedDeploymentTimeperiods($deployment, $modrevision);
         $viewData->contactInfo = $contactInfo;
         $this->sendResponse('contact_template_action_stage', $viewData);
     }
     if (RevDeploy::createDeploymentContactTemplate($deployment, $contactName, $contactInfo, $modrevision) === false) {
         $viewData->header = $this->getErrorHeader('contact_template_error');
         $viewData->error = 'Unable to write contact tempalte information for ' . $contactName . ' into ' . $deployment . ' Deployment';
         $this->sendError('generic_error', $viewData);
     }
     $viewData->deployment = $deployment;
     $viewData->contact = $contactName;
     $this->sendResponse('contact_template_write', $viewData);
 }