function uc_object_options_form in Ubercart 5
Same name and namespace in other branches
- 6.2 uc_attribute/uc_attribute.admin.inc \uc_object_options_form()
- 7.3 uc_attribute/uc_attribute.admin.inc \uc_object_options_form()
1 string reference to 'uc_object_options_form'
- uc_attribute_menu in uc_attribute/
uc_attribute.module - Implementation of hook_menu().
File
- uc_attribute/
uc_attribute.module, line 948
Code
function uc_object_options_form($id, $type) {
if ($type == 'product') {
$product = node_load($id);
drupal_set_title(check_plain($product->title));
$attributes = uc_product_get_attributes($id);
$table = '{uc_product_options}';
$id_type = 'nid';
$sql_type = '%d';
}
else {
if ($type == 'class') {
$class = uc_product_class_load($id);
drupal_set_title(check_plain($class->name));
$attributes = uc_class_get_attributes($id);
$table = '{uc_class_attribute_options}';
$id_type = 'pcid';
$sql_type = "'%s'";
}
}
foreach ($attributes as $aid => $attribute) {
$form['attributes'][$aid]['name'] = array(
'#value' => $attribute->name,
);
$form['attributes'][$aid]['aid'] = array(
'#type' => 'hidden',
'#value' => $attribute->aid,
);
$form['attributes'][$aid]['ordering'] = array(
'#type' => 'value',
'#value' => $attribute->ordering,
);
$form['attributes'][$aid]['options'] = array(
'#weight' => 2,
);
$base_attr = uc_attribute_load($attribute->aid);
if ($base_attr->options) {
$options = array();
$result = db_query("SELECT ao.aid, ao.oid, ao.name, ao.cost AS default_cost, ao.price AS default_price, ao.weight AS default_weight, ao.ordering AS default_ordering, po.cost, po.price, po.weight, po.ordering, po.ordering IS NULL AS null_order FROM {uc_attribute_options} AS ao LEFT JOIN {$table} AS po ON ao.oid = po.oid AND po.{$id_type} = {$sql_type} WHERE aid = %d ORDER BY null_order, po.ordering, default_ordering, ao.name", $id, $attribute->aid);
while ($option = db_fetch_object($result)) {
$oid = $option->oid;
$options[$oid] = '';
$form['attributes'][$aid]['options'][$oid]['select'] = array(
'#type' => 'checkbox',
'#default_value' => isset($attribute->options[$oid]) ? TRUE : FALSE,
'#title' => $option->name,
);
$form['attributes'][$aid]['options'][$oid]['cost'] = array(
'#type' => 'textfield',
'#default_value' => is_null($option->cost) ? $option->default_cost : $option->cost,
'#size' => 6,
);
$form['attributes'][$aid]['options'][$oid]['price'] = array(
'#type' => 'textfield',
'#default_value' => is_null($option->price) ? $option->default_price : $option->price,
'#size' => 6,
);
$form['attributes'][$aid]['options'][$oid]['weight'] = array(
'#type' => 'textfield',
'#default_value' => is_null($option->weight) ? $option->default_weight : $option->weight,
'#size' => 5,
);
$form['attributes'][$aid]['options'][$oid]['ordering'] = array(
'#type' => 'weight',
'#default_value' => is_null($option->ordering) ? $option->default_ordering : $option->ordering,
);
}
$form['attributes'][$aid]['default'] = array(
'#type' => 'radios',
'#options' => $options,
'#default_value' => $attribute->default_option,
);
}
else {
$form['attributes'][$aid]['default'] = array(
'#value' => t('This attribute does not have any options.'),
);
}
}
if (!empty($form['attributes'])) {
$form['attributes']['#tree'] = TRUE;
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#weight' => 10,
);
}
$form['id'] = array(
'#type' => 'value',
'#value' => $id,
);
$form['type'] = array(
'#type' => 'value',
'#value' => $type,
);
return $form;
}