You are here

function uc_stock_edit_form in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_stock/uc_stock.admin.inc \uc_stock_edit_form()
  2. 7.3 uc_stock/uc_stock.admin.inc \uc_stock_edit_form()
1 string reference to 'uc_stock_edit_form'
uc_stock_menu in uc_stock/uc_stock.module
Implementation of hook_menu().

File

uc_stock/uc_stock.module, line 122

Code

function uc_stock_edit_form($nid) {
  $node = node_load($nid);
  drupal_set_title(check_plain($node->title));
  $form = array();
  $skus = uc_stock_skus($nid);
  if (!$skus) {
    drupal_not_found();
  }
  $form['stock'] = array(
    '#tree' => TRUE,
  );
  foreach ((array) $skus as $id => $sku) {
    $stock = db_fetch_array(db_query("SELECT * FROM {uc_product_stock} WHERE sku = '%s'", $sku));
    $form['stock'][$id]['sku'] = array(
      '#type' => 'value',
      '#value' => $sku,
    );

    // Checkbox to mark this as active.
    $form['stock'][$id]['active'] = array(
      '#type' => 'checkbox',
      '#default_value' => !empty($stock['active']) ? $stock['active'] : 0,
    );

    // Sanitized version of the SKU for display.
    $form['stock'][$id]['display_sku'] = array(
      '#value' => check_plain($sku),
    );

    // Textfield for entering the stock level.
    $form['stock'][$id]['stock'] = array(
      '#type' => 'textfield',
      '#default_value' => !empty($stock['stock']) ? $stock['stock'] : 0,
      '#maxlength' => 9,
      '#size' => 9,
    );

    // Textfield for entering the threshold level.
    $form['stock'][$id]['threshold'] = array(
      '#type' => 'textfield',
      '#default_value' => !empty($stock['threshold']) ? $stock['threshold'] : 0,
      '#maxlength' => 9,
      '#size' => 9,
    );
  }
  $form['nid'] = array(
    '#type' => 'value',
    '#value' => $nid,
  );
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save changes'),
  );
  return $form;
}