Пример #1
0
 function UpdateCustomValues($template, $status)
 {
     /* Note: if a user changes the value or required status of an attribute that is not "all devices" and does not
     			enable it on the device_templates screen, it won't update here. it is a weird ui experience, but it
     			seems like the proper functionality since we aren't saving data for anything that isn't enabled */
     $dcaList = DeviceCustomAttribute::GetDeviceCustomAttributeList();
     $template->DeleteCustomValues();
     if (isset($_POST['tdca']) && is_array($_POST['tdca'])) {
         foreach ($_POST["tdca"] as $dcaid => $currentdca) {
             if (isset($currentdca["enabled"]) && $currentdca["enabled"] === "on") {
                 $insertval = '';
                 $requiredval = 0;
                 if (isset($currentdca["value"]) && trim($currentdca["value"] != '')) {
                     $insertval = trim($currentdca["value"]);
                 }
                 if (isset($currentdca["required"]) && $currentdca["required"] == "on") {
                     $requiredval = 1;
                 }
                 $status = $template->InsertCustomValue($dcaid, $insertval, $requiredval) ? $status : __('Error updating device template custom values');
             } elseif (array_key_exists($dcaid, $dcaList) && $dcaList[$dcaid]->AllDevices == 1) {
                 /* since the enabled checkbox for attributes marked as "all devices" is disabled, it doesn't get passed in with the form,
                 			so parse through and if the value or required status are different than the defaults, add a row for them as well. this
                 			helps keep the table clean of a bunch of default values too */
                 $insertval = $dcaList[$dcaid]->DefaultValue;
                 $requiredval = $dcaList[$dcaid]->Required;
                 // don't check if the value is empty - this lets us overwrite a default value from the config page with empty here
                 if (isset($currentdca["value"])) {
                     $insertval = trim($currentdca["value"]);
                 }
                 if (isset($currentdca["required"]) && $currentdca["required"] == "on") {
                     $requiredval = 1;
                 }
                 if ($insertval != $dcaList[$dcaid]->DefaultValue || $requiredval != $dcaList[$dcaid]->Required) {
                     $status = $template->InsertCustomValue($dcaid, $insertval, $requiredval) ? $status : __('Error updating device template custom values');
                 }
             }
         }
     }
     return $status;
 }
Пример #2
0
function updateCustomValues($device)
{
    $template = new DeviceTemplate();
    $template->TemplateID = $device->TemplateID;
    $template->GetTemplateByID();
    $dcaList = DeviceCustomAttribute::GetDeviceCustomAttributeList();
    $tdcaList = $template->CustomValues;
    $defaultvalues = array();
    if (isset($dcaList)) {
        foreach ($dcaList as $dca) {
            if ($dca->AllDevices == 1) {
                $defaultvalues[$dca->AttributeID]["value"] = $dca->DefaultValue;
                $defaultvalues[$dca->AttributeID]["required"] = $dca->Required;
            }
        }
    }
    if (isset($tdcaList)) {
        foreach ($tdcaList as $AttributeID => $tdca) {
            $defaultvalues[$AttributeID]["value"] = $tdca["value"];
            $defaultvalues[$AttributeID]["required"] = $tdca["required"];
        }
    }
    $device->DeleteCustomValues();
    if (isset($_POST["customvalue"])) {
        foreach ($_POST["customvalue"] as $AttributeID => $value) {
            if (trim($value) != trim($defaultvalues[$AttributeID]["value"])) {
                $device->InsertCustomValue($AttributeID, $value);
            }
        }
    }
}
Пример #3
0
 static function RowToObject($dbRow, $filterrights = true, $extendmodel = true)
 {
     /*
      * Generic function that will take any row returned from the fac_Devices
      * table and convert it to an object for use in array or other
      *
      * Pass false to filterrights when you don't need to check for rights for 
      * whatever reason.
      */
     $dev = new Device();
     $dev->DeviceID = $dbRow["DeviceID"];
     $dev->Label = $dbRow["Label"];
     $dev->SerialNo = $dbRow["SerialNo"];
     $dev->AssetTag = $dbRow["AssetTag"];
     $dev->PrimaryIP = $dbRow["PrimaryIP"];
     $dev->v3SecurityLevel = $dbRow["v3SecurityLevel"];
     $dev->v3AuthProtocol = $dbRow["v3AuthProtocol"];
     $dev->v3AuthPassphrase = $dbRow["v3AuthPassphrase"];
     $dev->v3PrivProtocol = $dbRow["v3PrivProtocol"];
     $dev->v3PrivPassphrase = $dbRow["v3PrivPassphrase"];
     $dev->SNMPVersion = $dbRow["SNMPVersion"];
     $dev->SNMPCommunity = $dbRow["SNMPCommunity"];
     $dev->SNMPFailureCount = $dbRow["SNMPFailureCount"];
     $dev->ESX = $dbRow["ESX"];
     $dev->Owner = $dbRow["Owner"];
     // Suppressing errors on the following two because they can be null and that generates an apache error
     @($dev->EscalationTimeID = $dbRow["EscalationTimeID"]);
     @($dev->EscalationID = $dbRow["EscalationID"]);
     $dev->PrimaryContact = $dbRow["PrimaryContact"];
     $dev->Cabinet = $dbRow["Cabinet"];
     $dev->Position = $dbRow["Position"];
     $dev->Height = $dbRow["Height"];
     $dev->Ports = $dbRow["Ports"];
     $dev->FirstPortNum = $dbRow["FirstPortNum"];
     $dev->TemplateID = $dbRow["TemplateID"];
     $dev->NominalWatts = $dbRow["NominalWatts"];
     $dev->PowerSupplyCount = $dbRow["PowerSupplyCount"];
     $dev->DeviceType = $dbRow["DeviceType"];
     $dev->ChassisSlots = $dbRow["ChassisSlots"];
     $dev->RearChassisSlots = $dbRow["RearChassisSlots"];
     $dev->ParentDevice = $dbRow["ParentDevice"];
     $dev->MfgDate = $dbRow["MfgDate"];
     $dev->InstallDate = $dbRow["InstallDate"];
     $dev->WarrantyCo = $dbRow["WarrantyCo"];
     @($dev->WarrantyExpire = $dbRow["WarrantyExpire"]);
     $dev->Notes = $dbRow["Notes"];
     $dev->Reservation = $dbRow["Reservation"];
     $dev->HalfDepth = $dbRow["HalfDepth"];
     $dev->BackSide = $dbRow["BackSide"];
     $dev->AuditStamp = $dbRow["AuditStamp"];
     $dev->GetCustomValues();
     $dev->MakeDisplay();
     if ($extendmodel) {
         // Extend our device model
         if ($dev->DeviceType == "CDU") {
             $pdu = new PowerDistribution();
             $pdu->PDUID = $dev->DeviceID;
             $pdu->GetPDU();
             foreach ($pdu as $prop => $val) {
                 $dev->{$prop} = $val;
             }
         }
         // This will extend the device model but isn't currently being used anywhere
         $dev->GetCustomValues();
         if (count($dev->CustomValues)) {
             $dcaList = DeviceCustomAttribute::GetDeviceCustomAttributeList();
             foreach ($dev->CustomValues as $dcaid => $val) {
                 $label = $dcaList[$dcaid]->Label;
                 // Keep users from attempting to overwrite shit like devicetype
                 if (!isset($dev->{$label})) {
                     $dev->{$label} = $val;
                 }
             }
             unset($dev->CustomValues);
         }
     }
     if ($filterrights) {
         $dev->FilterRights();
     }
     return $dev;
 }
Пример #4
0
        $mediatypes .= '<div>
					<div><img src="images/del.gif"></div>
					<div><input type="text" name="mediatype[]" data=' . $mt->MediaID . ' value="' . $mt->MediaType . '"></div>
					<div><select name="mediacolorcode[]"><option value=""></option>';
        foreach ($codeList as $cc) {
            $selected = $mt->ColorID == $cc->ColorID ? ' selected' : '';
            $mediatypes .= "<option value=\"{$cc->ColorID}\"{$selected}>{$cc->Name}</option>";
        }
        $mediatypes .= '</select></div>
				</div>';
    }
}
// build list of existing device custom attributes
$customattrs = "";
$dcaTypeList = DeviceCustomAttribute::GetDeviceCustomAttributeTypeList();
$dcaList = DeviceCustomAttribute::GetDeviceCustomAttributeList();
if (count($dcaList) > 0) {
    foreach ($dcaList as $dca) {
        $customattrs .= '<div>
					<div><img src="images/del.gif"></div>
					<div><input type="text" name="dcalabel[]" data=' . $dca->AttributeID . ' value="' . $dca->Label . '"></div>
					<div><select name="dcatype[]" id="dcatype">';
        foreach ($dcaTypeList as $dcatype) {
            $selected = $dca->AttributeType == $dcatype ? ' selected' : '';
            $customattrs .= "<option value=\"{$dcatype}\"{$selected}>{$dcatype}</option>";
        }
        $customattrs .= '</select></div>
					<div><input type="checkbox" name="dcarequired[]"';
        if ($dca->Required) {
            $customattrs .= ' checked';
        }