Exemple #1
0
function delete_components()
{
    global $config;
    $app = \Slim\Slim::getInstance();
    $router = $app->router()->getCurrentRoute()->getParams();
    $cid = $router['component'];
    $COMPONENT = new LibreNMS\Component();
    if ($COMPONENT->deleteComponent($cid)) {
        // Edit Success.
        $code = 200;
        $status = 'ok';
        $message = '';
    } else {
        // Edit Failure.
        $code = 500;
        $status = 'error';
        $message = 'Components could not be deleted.';
    }
    $output = array('status' => "{$status}", 'err-msg' => $message);
    $app->response->setStatus($code);
    $app->response->headers->set('Content-Type', 'application/json');
    echo _json_encode($output);
}
Exemple #2
0
    /*
     * Loop over the Component data to see if we need to DELETE any components.
     */
    foreach ($components as $key => $array) {
        // Guilty until proven innocent
        $found = false;
        foreach ($tblComponents as $k => $v) {
            if ($array['UID'] == $v['UID']) {
                // Yay, we found it...
                $found = true;
            }
        }
        if ($found === false) {
            // The component has not been found. we should delete it.
            echo "-";
            $component->deleteComponent($key);
        }
    }
    // Write the Components back to the DB.
    $component->setComponentPrefs($device['device_id'], $components);
    echo "\n";
}
// End if not error
$module = strtolower($module);
if (count($components) > 0) {
    if (dbFetchCell('SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ?', array($device['device_id'], $module)) == '0') {
        dbInsert(array('device_id' => $device['device_id'], 'app_type' => $module), 'applications');
    }
} else {
    dbDelete('applications', '`device_id` = ? AND `app_type` = ?', array($device['device_id'], $module));
}