echo "+"; } else { // The component does exist, merge the details in - UPDATE. $components[$component_key] = array_merge($components[$component_key], $array); echo "."; } } /* * 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 ($tblCBQOS 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 }
function edit_components() { global $config; $app = \Slim\Slim::getInstance(); $router = $app->router()->getCurrentRoute()->getParams(); $hostname = $router['hostname']; $data = json_decode(file_get_contents('php://input'), true); // use hostname as device_id if it's all digits $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); $COMPONENT = new component(); if ($COMPONENT->setComponentPrefs($device_id, $data)) { // Edit Success. $code = 200; $status = 'ok'; $message = ''; } else { // Edit Failure. $code = 500; $status = 'error'; $message = 'Components could not be edited.'; } $output = array('status' => "{$status}", 'err-msg' => $message, 'count' => count($data)); $app->response->setStatus($code); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); }
$UPDATE[$ID] = true; } } // Is the component ignored? if (isset($_POST['ign_' . $ID])) { // Yes it is, was it ignored before? if ($COMPONENTS[$ID]['ignore'] == 0) { // No it wasn't, best we ignore it then.. $COMPONENTS[$ID]['ignore'] = 1; $UPDATE[$ID] = true; } } else { // No its not, was it ignored before? if ($COMPONENTS[$ID]['ignore'] == 1) { // Yes it was, best we un-ignore it then.. $COMPONENTS[$ID]['ignore'] = 0; $UPDATE[$ID] = true; } } } if (count($UPDATE) > 0) { // Update our edited components. $STATUS = $OBJCOMP->setComponentPrefs($device_id, $COMPONENTS); $message = count($UPDATE) . ' Device records updated.'; $status = 'ok'; } else { $message = 'Record unchanged. No update necessary.'; $status = 'ok'; } $response = array('status' => $status, 'message' => $message); echo _json_encode($response);