Ejemplo n.º 1
0
function viewProfiles($userID, $domainID, $errorMessage = null, $alertMessage = null)
{
    if (isset($_POST['ContactUse'])) {
        $contactUse = $_POST['ContactUse'];
        $basicProfiles = $_POST['basicProfiles'];
        $_SESSION['ContactUse'] = $contactUse;
        $_SESSION['basicProfiles'] = $basicProfiles;
    } else {
        $contactUse = $_SESSION['ContactUse'];
        $basicProfiles = $_SESSION['basicProfiles'];
    }
    $vpSpin = 0;
    if (isset($_SESSION['VpSpin'])) {
        $vpSpin = $_SESSION['VpSpin'];
        $vpSpin++;
    }
    $_SESSION['VpSpin'] = $vpSpin;
    $contactManager = new ContactManager($domainID, $userID);
    $priorities = $contactManager->GetPriorities();
    $contactUses = $contactManager->GetContactUses();
    $uniqueProfiles = $contactManager->GetUniqueProfiles();
    $contactValueTypes = $contactManager->GetContactValueTypes();
    $contactValueSubtypes = $contactManager->GetContactValueSubtypes();
    $prioritySelect = "";
    $priorityOne = null;
    $priorityTwo = null;
    foreach ($priorities as $inx => $priority) {
        $prioritySelect .= "<option value=\"" . $priority->ID() . "\">" . humanPriority($priority->description()) . "</option>\n";
        if ($priority->level() == 1) {
            $priorityOne = clone $priority;
        }
        if ($priority->level() == 2) {
            $priorityTwo = clone $priority;
        }
    }
    $cvtSelect = "";
    $cvtEmail = null;
    $cvtPhone = null;
    foreach ($contactValueTypes as $inx => $cvTypes) {
        $cvtSelect .= "<option value=\"" . $cvTypes->ID() . "\">" . $cvTypes->description() . "</option>\n";
        if ($cvTypes->Name() == "email") {
            $cvtEmail = clone $cvTypes;
        }
        if ($cvTypes->Name() == "phone") {
            $cvtPhone = clone $cvTypes;
        }
    }
    $cvsSelect = "";
    foreach ($contactValueSubtypes as $inx => $cvSubtypes) {
        $cvsSelect .= "<option value=\"" . $cvSubtypes->ID() . "\">" . $cvSubtypes->description() . "</option>\n";
    }
    foreach ($contactUses as $inx => $cu) {
        if ($contactUse == $cu->name()) {
            $contactUse = clone $cu;
            break;
        }
    }
    $form = '';
    $btnIndex = 0;
    //preDebugger($basicProfiles);
    foreach ($basicProfiles as $iny => $state) {
        $uniqueProfile = clone $uniqueProfiles[$iny];
        $upID = $uniqueProfile->ID();
        $form .= "<input type=\"hidden\" name=\"ContactUse\" value=\"" . $contactUse->ID() . "\"/>";
        //mcb 2010.06.03
        // if valuable, this can display the error on top of the form set
        //if (is_array($errorMessage) && array_key_exists($uniqueProfile->ID(), $errorMessage)) $form .= $errorMessage[$uniqueProfile->ID()];
        $form .= '<table cellpadding="5" cellspacing="0" border="0"></thead><tr><th colspan="8" align="center">' . $uniqueProfile->description() . ' for ' . $contactUse->description() . " Notifications</th></tr>\n";
        $form .= "<tr align=\"left\">\n            <th style=\"border-bottom: 1px solid #FFFFFF;\">&nbsp;</th>\n\t\t\t<th style=\"border-bottom: 1px solid #FFFFFF;\">Owner</th>\n\t\t\t<th style=\"border-bottom: 1px solid #FFFFFF;\">Type</th>\n\t\t\t<th style=\"border-bottom: 1px solid #FFFFFF;\">Location</th>\n\t\t\t<th style=\"border-bottom: 1px solid #FFFFFF;\">Value</th>\n\t\t\t<th style=\"border-bottom: 1px solid #FFFFFF;\">Priority</th>\n\t\t\t<th style=\"border-bottom: 1px solid #FFFFFF;\">Status</th>\n\t\t\t<th style=\"border-bottom: 1px solid #FFFFFF;\">&nbsp;</th></tr></thead>\n";
        $form .= "<tbody>\n";
        $contactProfiles = $contactManager->GetContactProfiles($uniqueProfiles[$iny], $contactUse);
        $availablePriority = 0;
        $lineCount = 0;
        for ($inx = 0; $inx < count($contactProfiles); $inx++) {
            $lineCount++;
            $ownerName = $contactProfiles[$inx]->contactValue()->contactOwner()->name();
            //print $ownerName;
            $availablePriority = max($availablePriority, $contactProfiles[$inx]->priority()->level());
            $coID = strlen($ownerName) ? $contactProfiles[$inx]->contactValue()->contactOwner()->ID() : -$inx;
            $cpID = $contactProfiles[$inx]->ID();
            $cvID = $contactProfiles[$inx]->contactValue()->ID();
            $isInactiveForAll = $contactProfiles[$inx]->contactValue()->isInactive();
            if ($isInactiveForAll) {
                $isActive = false;
                $isInactiveForUse = false;
            } else {
                $isInactiveForUse = $contactProfiles[$inx]->isInactive();
                $isActive = !$isInactiveForUse;
            }
            $coKey = "[" . $vpSpin . "][" . $upID . "][" . $coID . "]";
            $idKey = "[" . $vpSpin . "][" . $upID . "][" . $cvID . "]";
            $form .= "<tr align=\"left\">" . "<td class=\"cmTable\">" . $lineCount . "</td>\n" . "<td class=\"cmTable\">" . "<input class=\"cmForm\" name=\"OwnerName" . $coKey . "\" id=\"OwnerName" . $coKey . "\" type=\"text\" size=\"20\" value=\"" . $ownerName . "\" \\/>" . "<input class=\"cmForm\" name=\"OldOwnerName" . $coKey . "\" id=\"OldOwnerName" . $coKey . "\" type=\"hidden\" value=\"" . $ownerName . "\" \\/>" . "</td>\n" . "<td class=\"cmTable\">\n" . "<select name=\"ContactValueType" . $idKey . "\" id=\"ContactValueType" . $idKey . "\">";
            foreach ($contactValueTypes as $iny => $cvType) {
                $form .= "<option value=\"" . $cvType->ID() . "\"" . ($contactProfiles[$inx]->contactValue()->contactValueTypeID() == $cvType->ID() ? " selected>" : ">") . $cvType->description() . "</option>\n";
            }
            $form .= "</select>\n" . "<input name=\"OldContactValueType" . $idKey . "\" id=\"OldContactValueType" . $idKey . "\" type=\"hidden\" value=\"" . $contactProfiles[$inx]->contactValue()->contactValueTypeID() . "\"/>" . "</td>\n" . "<td class=\"cmTable\">\n" . "<select name=\"ContactValueSubtype" . $idKey . "\" id=\"ContactValueSubtype" . $idKey . "\">";
            foreach ($contactValueSubtypes as $iny => $cvSubtype) {
                $form .= "<option value=\"" . $cvSubtype->ID() . "\"" . ($contactProfiles[$inx]->contactValue()->contactValueSubtypeID() == $cvSubtype->ID() ? " selected>" : ">") . $cvSubtype->description() . "</option>\n";
            }
            $form .= "</select>\n" . "<input name=\"OldContactValueSubtype" . $idKey . "\" id=\"OldContactValueSubtype" . $idKey . "\" type=\"hidden\" value=\"" . $contactProfiles[$inx]->contactValue()->contactValueSubtypeID() . "\"/>" . "</td>\n" . "<td class=\"cmTable\">\n" . "<input name=\"ContactValue" . $idKey . "\" id=\"ContactValue" . $idKey . "\" type=\"text\" size=\"30\" value=\"" . $contactProfiles[$inx]->contactValue()->contactValue() . "\" \\>" . "<input name=\"OldContactValue" . $idKey . "\" id=\"OldContactValue[" . $vpSpin . "][" . $upID . "][" . $cvID . "]\" type=\"hidden\" value=\"" . $contactProfiles[$inx]->contactValue()->contactValue() . "\" \\/>" . "</td>\n" . "<td class=\"cmTable\">\n" . "<select name=\"Priority" . $idKey . "\" id=\"Priority" . $idKey . "\">";
            foreach ($priorities as $iny => $priority) {
                if ($contactProfiles[$inx]->contactValue()->contactValueTypeID() == $cvtEmail->ID() && ($contactManager->hasPriorityOneEmail() && $contactProfiles[$inx]->priority()->ID() != $priorityOne->ID() && $priority->ID() == $priorityOne->ID())) {
                    continue;
                } elseif ($contactProfiles[$inx]->contactValue()->contactValueTypeID() == $cvtEmail->ID() && ($contactManager->hasPriorityTwoEmail() && $contactProfiles[$inx]->priority()->ID() != $priorityTwo->ID() && $priority->ID() == $priorityTwo->ID())) {
                    continue;
                } elseif ($contactProfiles[$inx]->contactValue()->contactValueTypeID() == $cvtPhone->ID() && ($contactManager->hasPriorityOnePhone() && $contactProfiles[$inx]->priority()->ID() != $priorityOne->ID() && $priority->ID() == $priorityOne->ID())) {
                    continue;
                } elseif ($contactProfiles[$inx]->contactValue()->contactValueTypeID() == $cvtPhone->ID() && ($contactManager->hasPriorityTwoPhone() && $contactProfiles[$inx]->priority()->ID() != $priorityTwo->ID() && $priority->ID() == $priorityTwo->ID())) {
                    continue;
                } else {
                    $form .= "<option value=\"" . $priority->ID() . "\"" . ($contactProfiles[$inx]->priority()->ID() == $priority->ID() ? " selected>" : ">") . humanPriority($priority->description()) . "</option>\n";
                }
            }
            $form .= "</select>\n" . "<input name=\"OldPriority" . $idKey . "\" id=\"OldPriority" . $idKey . "\" type=\"hidden\" value=\"" . $contactProfiles[$inx]->priority()->ID() . "\"/>" . "</td>\n" . "<td class=\"cmTable\">\n" . "<select name=\"CvStatus" . $idKey . "\" id=\"CvStatus" . $idKey . "\"><option value=\"Active\"" . ($isActive ? ">" : " selected>") . "Active</option>\n" . "<option value=\"InactiveForUse\"" . ($isInactiveForUse ? " selected>" : ">") . "Inactive for Use</option>\n" . "<option value=\"InactiveForAll\"" . ($isInactiveForAll ? " selected>" : ">") . "Inactive for All</option>\n" . "<option value=\"DeleteFromUse\">Delete from Use</option>\n" . "<option value=\"DeleteFromAll\">Delete from All</option>\n" . "</select>" . "<input name=\"OldCvStatus" . $idKey . "\" id=\"OldCvStatus" . $idKey . "\" type=\"hidden\" value=\"" . ($isActive ? "Active" : ($isInactiveForUse ? "InactiveForUse" : "InactiveForAll")) . "\"\\/>" . "</td>\n" . "<td class=\"cmTable\">\n                            <input type=\"submit\" id=\"updateContactValue.{$btnIndex}\" name=\"updateContactValue[" . $upID . "]\" value=\"Update\" class=\"cpButton\" onClick=\"if(validate('Update','" . $contactValueTypes[$contactProfiles[$inx]->contactValue()->contactValueTypeID()]->description() . "', \$('ContactValue" . $idKey . "'))){processContactUpdates(" . $vpSpin . ", " . $upID . ", " . $cpID . ", " . $coID . ", " . $cvID . ", " . $contactUse->ID() . ",this.id);}\" />\n                            </td>\n" . "<td id=\"updateMessage.{$btnIndex}\" width=\"20\" onClick=\"javascript:dojo.byId(this.id).innerHTML = '';\"></td>" . "</tr>\n";
            $btnIndex++;
        }
        $form .= "<tr><td colspan=\"7\">&nbsp;</td></tr>";
        // mcb 2010.06.03
        if (is_array($errorMessage) && array_key_exists($uniqueProfile->ID(), $errorMessage)) {
            $form .= '<tr><td colspan="7">' . $errorMessage[$uniqueProfile->ID()] . '</td></tr>';
        }
        $form .= "<tr align=\"left\">" . "<td>&nbsp;</td>" . "<td class=\"cmTable\"><input name=\"OwnerName[" . $vpSpin . "][" . $upID . "]\" id=\"OwnerName[" . $vpSpin . "][" . $upID . "]\" type=\"text\" size=\"20\"></td>\n" . "<td class=\"cmTable\"><select class=\"cmForm\" name=\"CvType[" . $vpSpin . "][" . $upID . "]\" id=\"CvType[" . $vpSpin . "][" . $upID . "]\">" . $cvtSelect . "</select></td>\n" . "<td class=\"cmTable\"><select class=\"cmForm\" name=\"CvSubtype[" . $vpSpin . "][" . $upID . "]\" id=\"CvSubtype[" . $vpSpin . "][" . $upID . "]\">" . $cvsSelect . "</select></td>\n" . "<td class=\"cmTable\"><input class=\"cmForm\" name=\"ContactValue[" . $vpSpin . "][" . $upID . "]\" id=\"ContactValue[" . $vpSpin . "][" . $upID . "]\" type=\"text\" size=\"30\"></td>\n" . "<td class=\"cmTable\">\n" . "<select name=\"Priority[" . $vpSpin . "][" . $upID . "]\" id=\"Priority[" . $vpSpin . "][" . $upID . "]\">" . $prioritySelect . "</select>\n" . "<input name=\"DenyPriorityOneEmail[" . $vpSpin . "][" . $upID . "]\" id=\"DenyPriorityOneEmail[" . $vpSpin . "][" . $upID . "]\" type=\"hidden\" value=\"" . ($contactManager->hasPriorityOneEmail() ? "1" : "0") . "\"/>\n" . "<input name=\"DenyPriorityTwoEmail[" . $vpSpin . "][" . $upID . "]\" id=\"DenyPriorityTwoEmail[" . $vpSpin . "][" . $upID . "]\" type=\"hidden\" value=\"" . ($contactManager->hasPriorityTwoEmail() ? "1" : "0") . "\"/>\n" . "<input name=\"DenyPriorityOnePhone[" . $vpSpin . "][" . $upID . "]\" id=\"DenyPriorityOnePhone[" . $vpSpin . "][" . $upID . "]\" type=\"hidden\" value=\"" . ($contactManager->hasPriorityOnePhone() ? "1" : "0") . "\"/>\n" . "<input name=\"DenyPriorityTwoPhone[" . $vpSpin . "][" . $upID . "]\" id=\"DenyPriorityTwoPhone[" . $vpSpin . "][" . $upID . "]\" type=\"hidden\" value=\"" . ($contactManager->hasPriorityTwoPhone() ? "1" : "0") . "\"/>\n" . "</td>\n" . "<td  class=\"cmTable\" align=\"center\"><input type=\"submit\" id=\"newContactValue\" name=\"newContactValue[" . $vpSpin . "][" . $upID . "]\" value=\"Add\" class=\"cpButton\" onClick=\"if(validate('Add','CvType[" . $vpSpin . "][" . $upID . "]', \$('ContactValue[" . $vpSpin . "][" . $upID . "]'))){processContactAdditions(" . $vpSpin . ", " . $upID . ", " . $contactUse->ID() . ")}\" /></td>\n" . "<td class=\"cmTable\">&nbsp;</td>\n" . "</tr>\n";
        $form .= "</tbody></table><br>\n";
        $associatedPoints = $contactManager->GetAssociatedPoints($upID);
        //$contactManager->preDebugger($associatedPoints);
        $formItems = '';
        for ($inx = 0; $inx < count($associatedPoints); $inx++) {
            if ($associatedPoints[$inx]->description()) {
                $activeString = $associatedPoints[$inx]->isInactive() ? '[Inactive]' : '';
                $formItems .= "<li>" . $associatedPoints[$inx]->description() . " : Asset " . $associatedPoints[$inx]->assetIdentifier() . " " . $activeString . "</li>\n";
            }
        }
        $form .= "<div style=\"text-align: left;\">The above contacts are associated with the following points:<br><br><ul>\n";
        $form .= $formItems == '' ? 'None' : $formItems;
        $form .= "</ul></div>";
        if ($formItems == '') {
            $noAssociation = '<div style="text-align: center;"><span style="color: red; font-weight: bold;">The ' . $uniqueProfile->description() . ' is not associated with any ISO-NE Registered Assets</span></div>';
        } else {
            $noAssociation = null;
        }
        $form = $noAssociation . $form;
    }
    return $form;
}