function updateObject() { $taglist = genericAssertion('taglist', 'array0'); genericAssertion('num_attrs', 'uint0'); genericAssertion('object_name', 'string0'); genericAssertion('object_label', 'string0'); genericAssertion('object_asset_no', 'string0'); genericAssertion('object_comment', 'string0'); genericAssertion('object_type_id', 'uint'); $object_id = getBypassValue(); global $dbxlink, $sic; $dbxlink->beginTransaction(); commitUpdateObject($object_id, $_REQUEST['object_name'], $_REQUEST['object_label'], isCheckSet('object_has_problems', 'yesno'), $_REQUEST['object_asset_no'], $_REQUEST['object_comment']); updateObjectAttributes($object_id); $object = spotEntity('object', $object_id); if ($sic['object_type_id'] != $object['objtype_id']) { if (!array_key_exists($sic['object_type_id'], getObjectTypeChangeOptions($object_id))) { throw new InvalidRequestArgException('new type_id', $sic['object_type_id'], 'incompatible with requested attribute values'); } usePreparedUpdateBlade('Object', array('objtype_id' => $sic['object_type_id']), array('id' => $object_id)); } // Invalidate thumb cache of all racks objects could occupy. foreach (getResidentRacksData($object_id, FALSE) as $rack_id) { usePreparedDeleteBlade('RackThumbnail', array('rack_id' => $rack_id)); } $dbxlink->commit(); rebuildTagChainForEntity('object', $object_id, buildTagChainFromIds($taglist), TRUE); showFuncMessage(__FUNCTION__, 'OK'); }
} // skip noops if ($value === $oldvalue) { continue; } // finally update our value error_log("update attribute ID {$attr_id} from {$oldvalue} to {$value}"); commitUpdateAttrValue($object_id, $attr_id, $value); } } // see if we also need to update the object type $object = spotEntity('object', $object_id); if ($sic['object_type_id'] != $object['objtype_id']) { error_log("object type id for object {$object_id} will be changed from " . $object['objtype_id'] . ' to ' . $sic['object_type_id']); // check that the two types are compatible if (!array_key_exists($sic['object_type_id'], getObjectTypeChangeOptions($object_id))) { throw new InvalidRequestArgException('new type_id', $sic['object_type_id'], 'incompatible with requested attribute values'); } usePreparedUpdateBlade('RackObject', array('objtype_id' => $sic['object_type_id']), array('id' => $object_id)); } // Invalidate thumb cache of all racks objects could occupy. foreach (getResidentRacksData($object_id, FALSE) as $rack_id) { usePreparedDeleteBlade('RackThumbnail', array('rack_id' => $rack_id)); } // ok, now we're good $dbxlink->commit(); // redirect to the get_object URL for the edited object redirectUser($_SERVER['SCRIPT_NAME'] . "?method=get_object&object_id={$object_id}"); break; // update user-defined tags for an object // UI equivalent: /index.php?module=redirect&page=object&tab=tags&op=saveTags
function renderEditObjectForm() { global $pageno; $object_id = getBypassValue(); $object = spotEntity('object', $object_id); startPortlet(); printOpFormIntro('update'); // static attributes echo '<table border=0 cellspacing=0 cellpadding=3 align=center>'; echo "<tr><td> </td><th colspan=2><h2>Attributes</h2></th></tr>"; echo '<tr><td> </td><th class=tdright>Type:</th><td class=tdleft>'; printSelect(getObjectTypeChangeOptions($object['id']), array('name' => 'object_type_id'), $object['objtype_id']); echo '</td></tr>'; // baseline info echo "<tr><td> </td><th class=tdright>Common name:</th><td class=tdleft><input type=text name=object_name value='{$object['name']}'></td></tr>\n"; echo "<tr><td> </td><th class=tdright>Visible label:</th><td class=tdleft><input type=text name=object_label value='{$object['label']}'></td></tr>\n"; echo "<tr><td> </td><th class=tdright>Asset tag:</th><td class=tdleft><input type=text name=object_asset_no value='{$object['asset_no']}'></td></tr>\n"; echo "<tr><td> </td><th class=tdright>Tags:</th><td class=tdleft>"; printTagsPicker(); echo "</td></tr>\n"; // parent selection if (objectTypeMayHaveParent($object['objtype_id'])) { $parents = getEntityRelatives('parents', 'object', $object_id); foreach ($parents as $link_id => $parent_details) { if (!isset($label)) { $label = count($parents) > 1 ? 'Containers:' : 'Container:'; } echo "<tr><td> </td>"; echo "<th class=tdright>{$label}</th><td class=tdleft>"; echo mkA($parent_details['name'], 'object', $parent_details['entity_id']); echo " "; echo getOpLink(array('op' => 'unlinkObjects', 'link_id' => $link_id), '', 'cut', 'Unlink container'); echo "</td></tr>\n"; $label = ' '; } echo "<tr><td> </td>"; echo "<th class=tdright>Select container:</th><td class=tdleft>"; echo "<span"; $helper_args = array('object_id' => $object_id); $popup_args = 'height=700, width=400, location=no, menubar=no, ' . 'resizable=yes, scrollbars=yes, status=no, titlebar=no, toolbar=no'; echo " onclick='window.open(\"" . makeHrefForHelper('objlist', $helper_args); echo "\",\"findlink\",\"{$popup_args}\");'>"; printImageHREF('attach', 'Select a container'); echo "</span></td></tr>\n"; } // optional attributes $i = 0; $values = getAttrValuesSorted($object_id); if (count($values) > 0) { foreach ($values as $record) { if (!permitted(NULL, NULL, NULL, array(array('tag' => '$attr_' . $record['id']), array('tag' => '$any_op')))) { continue; } echo "<input type=hidden name={$i}_attr_id value={$record['id']}>"; echo '<tr><td>'; if (strlen($record['value'])) { echo getOpLink(array('op' => 'clearSticker', 'attr_id' => $record['id']), '', 'clear', 'Clear value', 'need-confirmation'); } else { echo ' '; } echo '</td>'; echo "<th class=sticker>{$record['name']}"; if ($record['type'] == 'date') { echo ' (' . datetimeFormatHint(getConfigVar('DATETIME_FORMAT')) . ')'; } echo ':</th><td class=tdleft>'; switch ($record['type']) { case 'uint': case 'float': case 'string': echo "<input type=text name={$i}_value value='{$record['value']}'>"; break; case 'dict': $chapter = readChapter($record['chapter_id'], 'o'); $chapter[0] = '-- NOT SET --'; $chapter = cookOptgroups($chapter, $object['objtype_id'], $record['key']); printNiftySelect($chapter, array('name' => "{$i}_value"), $record['key']); break; case 'date': $date_value = $record['value'] ? datetimestrFromTimestamp($record['value']) : ''; echo "<input type=text name={$i}_value value='{$date_value}'>"; break; } echo "</td></tr>\n"; $i++; } } echo '<input type=hidden name=num_attrs value=' . $i . ">\n"; echo "<tr><td> </td><th class=tdright>Has problems:</th><td class=tdleft><input type=checkbox name=object_has_problems"; if ($object['has_problems'] == 'yes') { echo ' checked'; } echo "></td></tr>\n"; echo "<tr><td> </td><th class=tdright>Actions:</th><td class=tdleft>"; echo getOpLink(array('op' => 'deleteObject', 'page' => 'depot', 'tab' => 'addmore', 'object_id' => $object_id), '', 'destroy', 'Delete object', 'need-confirmation'); echo " "; echo getOpLink(array('op' => 'resetObject'), '', 'clear', 'Reset (cleanup) object', 'need-confirmation'); echo "</td></tr>\n"; echo "<tr><td colspan=3><b>Comment:</b><br><textarea name=object_comment rows=10 cols=80>{$object['comment']}</textarea></td></tr>"; echo "<tr><th class=submit colspan=3>"; printImageHREF('SAVE', 'Save changes', TRUE); echo "</form></th></tr></table>\n"; finishPortlet(); echo '<table border=0 width=100%><tr><td>'; startPortlet('history'); renderObjectHistory($object_id); finishPortlet(); echo '</td></tr></table>'; }
function updateObject() { genericAssertion('num_attrs', 'uint0'); genericAssertion('object_name', 'string0'); genericAssertion('object_label', 'string0'); genericAssertion('object_asset_no', 'string0'); genericAssertion('object_comment', 'string0'); genericAssertion('object_type_id', 'uint'); $object_id = getBypassValue(); global $dbxlink, $sic; $dbxlink->beginTransaction(); commitUpdateObject($object_id, $_REQUEST['object_name'], $_REQUEST['object_label'], isCheckSet('object_has_problems', 'yesno'), $_REQUEST['object_asset_no'], $_REQUEST['object_comment']); // Update optional attributes $oldvalues = getAttrValues($object_id); for ($i = 0; $i < $_REQUEST['num_attrs']; $i++) { genericAssertion("{$i}_attr_id", 'uint'); $attr_id = $_REQUEST["{$i}_attr_id"]; if (!array_key_exists($attr_id, $oldvalues)) { throw new InvalidRequestArgException('attr_id', $attr_id, 'malformed request'); } $value = $_REQUEST["{$i}_value"]; if ('date' == $oldvalues[$attr_id]['type']) { assertDateArg("{$i}_value", TRUE); if ($value != '') { $value = strtotime($value); } } # Delete attribute and move on, when the field is empty or if the field # type is a dictionary and it is the "--NOT SET--" value of 0. if ($value == '' || $oldvalues[$attr_id]['type'] == 'dict' && $value == 0) { if (permitted(NULL, NULL, NULL, array(array('tag' => '$attr_' . $attr_id)))) { commitUpdateAttrValue($object_id, $attr_id); } else { showError('Permission denied, "' . $oldvalues[$attr_id]['name'] . '" left unchanged'); } continue; } // The value could be uint/float, but we don't know ATM. Let SQL // server check this and complain. assertStringArg("{$i}_value"); switch ($oldvalues[$attr_id]['type']) { case 'uint': case 'float': case 'string': case 'date': $oldvalue = $oldvalues[$attr_id]['value']; break; case 'dict': $oldvalue = $oldvalues[$attr_id]['key']; break; default: } if ($value === $oldvalue) { // ('' == 0), but ('' !== 0) continue; } if (permitted(NULL, NULL, NULL, array(array('tag' => '$attr_' . $attr_id)))) { commitUpdateAttrValue($object_id, $attr_id, $value); } else { showError('Permission denied, "' . $oldvalues[$attr_id]['name'] . '" left unchanged'); } } $object = spotEntity('object', $object_id); if ($sic['object_type_id'] != $object['objtype_id']) { if (!array_key_exists($sic['object_type_id'], getObjectTypeChangeOptions($object_id))) { throw new InvalidRequestArgException('new type_id', $sic['object_type_id'], 'incompatible with requested attribute values'); } usePreparedUpdateBlade('Object', array('objtype_id' => $sic['object_type_id']), array('id' => $object_id)); } // Invalidate thumb cache of all racks objects could occupy. foreach (getResidentRacksData($object_id, FALSE) as $rack_id) { usePreparedDeleteBlade('RackThumbnail', array('rack_id' => $rack_id)); } $dbxlink->commit(); return showFuncMessage(__FUNCTION__, 'OK'); }