// Get ID $id = fRequest::get('id', 'integer'); try { // Get consumable via ID $c = new Consumable($id); if (fRequest::isPost()) { // Try to validate options $validator = new fValidation(); $validator->addOneOrMoreRule('col_c', 'col_y', 'col_m', 'col_k'); $validator->overrideFieldName(array('col_c' => 'Colour (Cyan)', 'col_y' => 'Colour (Yellow)', 'col_m' => 'Colour (Magenta)', 'col_k' => 'Colour (Black)')); $validator->validate(); // Update consumable object from POST data and save $c->populate(); $c->linkModels(); $c->linkTags(); $c->store(); // Messaging fMessaging::create('affected', fURL::get(), $c->getId()); fMessaging::create('success', fURL::get(), 'The consumable ' . $c->getName() . ' was successfully updated.'); fURL::redirect(fURL::get()); } } catch (fNotFoundException $e) { fMessaging::create('error', fURL::get(), 'The consumable requested, ID ' . $id . ', could not be found.'); fURL::redirect(fURL::get()); } catch (fExpectedException $e) { fMessaging::create('error', fURL::get(), $e->getMessage()); } // Get manufacturers also for drop-down box #$manufacturers = fRecordSet::build('Manufacturer', NULL, array('name' => 'asc')); // Get list of models $models = Model::getSimple($db);
include_once 'inc/core.php'; // Get parameters $redirect = fRequest::get('redirect', 'string'); $consumable_id = fRequest::get('consumable_id', 'integer?'); $qty = fRequest::get('qty'); $cost = fRequest::get('cost', 'float?'); // Determine status - show page or update stock if (fRequest::isPost() && $consumable_id != NULL) { // Increase stock try { // Get objects matching the printer/consumable $consumable = new Consumable($consumable_id); // Update cost if present if ($cost) { $consumable->setCost($cost); $consumable->store(); } // Update consumable $updated = $consumable->increaseStockBy($qty); #die(var_export($updated)); // Check status of installation if ($updated == FALSE) { fMessaging::create('error', $redirect, $consumable->err); fURL::redirect($redirect); } else { fMessaging::create('success', $redirect, sprintf('The consumable stock for %s has been updated.', $consumable->getName())); fURL::redirect($redirect); } } catch (fNotFoundException $e) { fMessaging::create('error', $redirect, 'The requested object with ID ' . $id . ', could not be found.'); fURL::redirect($redirect);