Exemple #1
0
//	URL:	/api/v1/device/:deviceid
//	Method:	GET
//	Params:	deviceid (passed in URL)
//	Returns:  All devices for which the user's rights have access to view
//
$app->get('/device/:deviceid', function ($deviceid) {
    $dev = new Device();
    $dev->DeviceID = intval($deviceid);
    if (!$dev->GetDevice()) {
        $response['error'] = true;
        $response['errorcode'] = 404;
        $response['message'] = __("No device found with DeviceID") . $deviceid;
        echoResponse(200, $response);
    } else {
        if (is_array($dev->CustomValues)) {
            $cattr = new DeviceCustomAttribute();
            $newList = array();
            foreach ($dev->CustomValues as $key => $val) {
                $cattr->AttributeID = $key;
                $cattr->GetDeviceCustomAttribute();
                $newList[$cattr->Label] = $val;
            }
            $dev->CustomValues = $newList;
        }
        $response['error'] = false;
        $response['errorcode'] = 200;
        $response['device'] = $dev;
        echoResponse(200, $response);
    }
});
//
 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;
 }
Exemple #3
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);
            }
        }
    }
}
Exemple #4
0
 static function GetDeviceCustomAttributeList()
 {
     global $dbh;
     $dcaList = array();
     $sql = "SELECT AttributeID, Label, AttributeType, Required, AllDevices, DefaultValue\r\n\t\t\tFROM fac_DeviceCustomAttribute\r\n\t\t\tORDER BY Label, AttributeID;";
     foreach ($dbh->query($sql) as $dcaRow) {
         $dcaList[$dcaRow["AttributeID"]] = DeviceCustomAttribute::RowToObject($dcaRow);
     }
     return $dcaList;
 }
Exemple #5
0
        }
        exit;
    } else {
        if ($dca->CreateDeviceCustomAttribute()) {
            echo $dca->AttributeID;
        } else {
            echo 'f';
        }
        exit;
    }
    exit;
}
if (isset($_POST['dcaused'])) {
    $count = DeviceCustomAttribute::TimesUsed($_POST['dcaused']);
    if ($count == 0 && isset($_POST['remove'])) {
        $dca = new DeviceCustomAttribute();
        $dca->AttributeID = $_POST['dcaused'];
        if ($dca->RemoveDeviceCustomAttribute()) {
            echo $count;
            exit;
        } else {
            echo "fail";
            exit;
        }
    }
    echo $count;
    exit;
}
// END AJAX Requests
if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "Update") {
    foreach ($config->ParameterArray as $key => $value) {