You are here

function uc_product_power_tools_class_settings in Ubercart Product Power Tools 6

Same name and namespace in other branches
  1. 6.2 uc_product_power_tools.admin.inc \uc_product_power_tools_class_settings()
  2. 7 uc_product_power_tools.admin.inc \uc_product_power_tools_class_settings()

Administration settings form.

See also

uc_product_power_tools_class_settings()

1 string reference to 'uc_product_power_tools_class_settings'
uc_product_power_tools_menu in ./uc_product_power_tools.module
Implements hook_menu().

File

./uc_product_power_tools.admin.inc, line 102
Settings and config for uc_product_power_tools module.

Code

function uc_product_power_tools_class_settings() {
  $tmp = explode("/", $_GET['q']);
  $prodclass = $tmp[4];
  $data = db_fetch_array(db_query("SELECT * FROM {uc_power_tools} WHERE pcid = '%s'", $prodclass));
  $class = $prodclass != 'product' ? db_fetch_array(db_query("SELECT name from {uc_product_classes} WHERE pcid = '%s'", $prodclass)) : array(
    'name' => 'Default Ubercart Product Content Type',
  );
  $sign_flag = variable_get('uc_sign_after_amount', FALSE);
  $currency_sign = variable_get('uc_currency_sign', '$');
  $form = array();

  // ------------
  // Issue #883544
  // Feature Request
  // Ability to clone an existing product class' settings.
  //
  $form['clone_class'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Clone Settings of Existing Product Class'),
  );
  $form['clone_class']['clone_from'] = array(
    '#type' => 'radios',
    '#default_value' => 0,
    '#options' => _get_available_clone_classes($prodclass),
  );
  $form['clone_class']['clone_submit'] = array(
    '#type' => 'submit',
    '#value' => t('Clone'),
  );

  // ------------
  $form['product_class'] = array(
    '#type' => 'hidden',
    '#value' => $prodclass,
  );
  $form['power_tools'] = array(
    '#type' => 'fieldset',
    '#title' => t('@class "Power Tools" Settings', array(
      '@class' => $class['name'],
    )),
    '#collapsible' => FALSE,
  );
  $form['power_tools']['autosku'] = array(
    '#type' => 'fieldset',
    '#title' => t('Auto SKU Generation'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['power_tools']['autosku']['asku'] = array(
    '#type' => 'radios',
    '#default_value' => isset($data['asku']) ? $data['asku'] : 0,
    '#options' => array(
      0 => t('Show SKU field on product entry form'),
      2 => t('Show SKU field, but for new products give the option to Automatically Generate from replacement pattern below:'),
      3 => t('Disable (show but do not allow editing) SKU field and Automatically Generate from replacement pattern below:'),
      1 => t('Hide SKU field and Automatically Generate from replacement pattern below:'),
    ),
  );
  if (module_exists('token')) {
    $description = t('This string will be used as SKU.');
    if (module_exists('token')) {
      $description .= ' ' . t('Use the syntax [token] if you want to insert a replacement pattern.<br />Note: CCK Fields that are not assigned to products in this product class will return no value. If using the Auto Node Title module, [title] and [title-raw] will return "ant".');
    }
    $form['power_tools']['autosku']['asku_pattern'] = array(
      '#type' => 'textarea',
      '#title' => t('Pattern for the SKU'),
      '#description' => $description,
      '#default_value' => isset($data['asku_settings']) ? $data['asku_settings'] : '',
    );
  }
  if (module_exists('token')) {
    $form['power_tools']['autosku']['token_help'] = array(
      '#title' => t('Replacement patterns'),
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#description' => t('Prefer raw-text replacements for text to avoid problems with HTML entities!'),
    );
    $form['power_tools']['autosku']['token_help']['help'] = array(
      '#value' => theme('token_help', 'node'),
    );
  }
  $form['power_tools']['pricing'] = array(
    '#type' => 'fieldset',
    '#title' => t('Prices'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['power_tools']['pricing']['lp'] = array(
    '#type' => 'fieldset',
    '#title' => t('List Price'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['power_tools']['pricing']['lp']['lponoff'] = array(
    '#type' => 'radios',
    '#default_value' => isset($data['lp']) ? $data['lp'] : 0,
    '#options' => array(
      t('Show List Price field on product entry form'),
      t('Hide List Price field & Use Sell Price Value entered on product form'),
      t('Hide List Price field & Use default value below:'),
      t('Show List Price field & Use default value below:'),
    ),
  );
  $form['power_tools']['pricing']['lp']['lp_settings'] = array(
    '#type' => 'textfield',
    '#size' => 32,
    '#title' => t('List price'),
    '#required' => FALSE,
    '#default_value' => isset($data['lp_settings']) ? $data['lp_settings'] : 0,
    '#weight' => 0,
    '#size' => 20,
    '#maxlength' => 35,
    '#field_prefix' => $sign_flag ? '' : $currency_sign,
    '#field_suffix' => $sign_flag ? $currency_sign : '',
  );
  $form['power_tools']['pricing']['cost'] = array(
    '#type' => 'fieldset',
    '#title' => t('Cost'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['power_tools']['pricing']['cost']['costonoff'] = array(
    '#type' => 'radios',
    '#default_value' => isset($data['cost']) ? $data['cost'] : 0,
    '#options' => array(
      t('Show Cost field on product entry form'),
      t('Hide Cost field & Use default value below:'),
      t('Show Cost field & Use default value below:'),
    ),
  );
  $form['power_tools']['pricing']['cost']['cost_settings'] = array(
    '#type' => 'textfield',
    '#size' => 32,
    '#title' => t('Cost'),
    '#required' => FALSE,
    '#default_value' => isset($data['cost_settings']) ? $data['cost_settings'] : 0,
    '#weight' => 0,
    '#size' => 20,
    '#maxlength' => 35,
    '#field_prefix' => $sign_flag ? '' : $currency_sign,
    '#field_suffix' => $sign_flag ? $currency_sign : '',
  );
  $form['power_tools']['pricing']['sp'] = array(
    '#type' => 'fieldset',
    '#title' => t('Sell Price'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['power_tools']['pricing']['sp']['sponoff'] = array(
    '#type' => 'radios',
    '#default_value' => isset($data['sp']) ? $data['sp'] : 0,
    '#options' => array(
      t('Show Sell Price field on product entry form'),
      t('Hide Sell Price field & Use default value below:'),
      t('Show Sell Price field & Use default value below:'),
    ),
  );
  $form['power_tools']['pricing']['sp']['sp_settings'] = array(
    '#type' => 'textfield',
    '#size' => 32,
    '#title' => t('Sell price'),
    '#required' => FALSE,
    '#default_value' => isset($data['sp_settings']) ? $data['sp_settings'] : 0,
    '#weight' => 0,
    '#size' => 20,
    '#maxlength' => 35,
    '#field_prefix' => $sign_flag ? '' : $currency_sign,
    '#field_suffix' => $sign_flag ? $currency_sign : '',
  );
  $form['power_tools']['qtys'] = array(
    '#type' => 'fieldset',
    '#title' => t('Quantities'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['power_tools']['qtys']['dq'] = array(
    '#type' => 'fieldset',
    '#title' => t('Default Quantity'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['power_tools']['qtys']['dq']['dqonoff'] = array(
    '#type' => 'radios',
    '#default_value' => isset($data['dq']) ? $data['dq'] : 0,
    '#options' => array(
      t('Show Default Quantity field on product entry form'),
      t('Hide Default Quantity field & Use default value below:'),
      t('Show Default Quantity field & Use default value below:'),
    ),
  );
  $form['power_tools']['qtys']['dq']['dq_settings'] = array(
    '#type' => 'textfield',
    '#size' => 32,
    '#title' => t('Default Quantity'),
    '#description' => t('Default quantity to add to cart'),
    '#required' => FALSE,
    '#default_value' => isset($data['dq_settings']) ? $data['dq_settings'] : 1,
    '#weight' => 0,
    '#size' => 20,
  );
  $form['power_tools']['qtys']['pq'] = array(
    '#type' => 'fieldset',
    '#title' => t('Package Quantity'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['power_tools']['qtys']['pq']['pqonoff'] = array(
    '#type' => 'radios',
    '#default_value' => isset($data['pq']) ? $data['pq'] : 0,
    '#options' => array(
      t('Show Default Package Quantity field on product entry form'),
      t('Hide Default Package Quantity field & Use default value below:'),
      t('Show Default Package Quantity field & Use default value below:'),
    ),
  );
  $form['power_tools']['qtys']['pq']['pq_settings'] = array(
    '#type' => 'textfield',
    '#size' => 32,
    '#title' => t('Package Quantity'),
    '#description' => t('For a package containing only this product, how many are in it?'),
    '#required' => FALSE,
    '#default_value' => isset($data['pq_settings']) ? $data['pq_settings'] : 1,
    '#weight' => 0,
    '#size' => 20,
  );
  $form['power_tools']['lpos'] = array(
    '#type' => 'fieldset',
    '#title' => t('List Position'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['power_tools']['lpos']['lposonoff'] = array(
    '#type' => 'radios',
    '#default_value' => isset($data['lpos']) ? $data['lpos'] : 0,
    '#options' => array(
      t('Show List Position field on product entry form'),
      t('Hide List Position field & Use default value below:'),
    ),
  );
  $form['power_tools']['lpos']['lpos_settings'] = array(
    '#type' => 'textfield',
    '#size' => 32,
    '#title' => t('List Position'),
    '#description' => t('List Position weight of products of this class.'),
    '#required' => FALSE,
    '#default_value' => isset($data['lpos_settings']) ? $data['lpos_settings'] : 0,
    '#weight' => 0,
    '#size' => 20,
  );
  $form['power_tools']['ship'] = array(
    '#type' => 'fieldset',
    '#title' => t('Shipping'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['power_tools']['ship']['ship_settings'] = array(
    '#type' => 'radios',
    '#default_value' => isset($data['ship']) ? $data['ship'] : 0,
    '#options' => array(
      t('Product is Shippable. Show checkbox & all shipping fields on product entry form'),
      t('Product is Shippable. Hide checkbox, but show other shipping fields on product entry form'),
      t('Product is NOT Shippable. Hide checkbox, but show other shipping fields on product entry form'),
      t('Product is NOT Shippable. Hide checkbox & all shipping fields on product entry form'),
      t('Show checkbox but hide all shipping fields on product entry form'),
      t('Product is Shippable. Hide checkbox & all shipping fields on product entry form'),
    ),
    '#description' => t('The last option will only hide weight and size fields.'),
  );
  $form['power_tools']['ship']['weight'] = array(
    '#weight' => 15,
    '#theme' => 'uc_product_form_weight',
  );
  $form['power_tools']['ship']['weight']['weight'] = array(
    '#type' => 'textfield',
    '#title' => t('Weight'),
    '#default_value' => isset($data['weight']) ? $data['weight'] : 0,
    '#size' => 10,
    '#maxlength' => 15,
  );
  $units = array(
    'lb' => t('Pounds'),
    'kg' => t('Kilograms'),
    'oz' => t('Ounces'),
    'g' => t('Grams'),
  );
  $form['power_tools']['ship']['weight']['weight_units'] = array(
    '#type' => 'select',
    '#title' => t('Unit of measurement'),
    '#default_value' => isset($data['weight_units']) ? $data['weight_units'] : variable_get('uc_weight_unit', 'lb'),
    '#options' => $units,
  );
  $form['power_tools']['ship']['dimensions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Dimensions'),
    '#description' => t('Physical dimensions of the packaged product.'),
    '#weight' => 20,
    '#theme' => 'uc_product_dimensions_form',
  );
  $form['power_tools']['ship']['dimensions']['length_units'] = array(
    '#type' => 'select',
    '#title' => t('Units of measurement'),
    '#options' => array(
      'in' => t('Inches'),
      'ft' => t('Feet'),
      'cm' => t('Centimeters'),
      'mm' => t('Millimeters'),
    ),
    '#default_value' => isset($data['length_units']) ? $data['length_units'] : variable_get('uc_length_unit', 'in'),
  );
  $form['power_tools']['ship']['dimensions']['length'] = array(
    '#type' => 'textfield',
    '#title' => t('Length'),
    '#default_value' => isset($data['length']) ? $data['length'] : '',
    '#size' => 10,
  );
  $form['power_tools']['ship']['dimensions']['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Width'),
    '#default_value' => isset($data['width']) ? $data['width'] : '',
    '#size' => 10,
  );
  $form['power_tools']['ship']['dimensions']['height'] = array(
    '#type' => 'textfield',
    '#title' => t('Height'),
    '#default_value' => isset($data['height']) ? $data['height'] : '',
    '#size' => 10,
  );
  if (module_exists('uc_stock')) {
    $form['power_tools']['stock'] = array(
      '#type' => 'fieldset',
      '#title' => t('Stock'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['power_tools']['stock']['stockonoff'] = array(
      '#type' => 'radios',
      '#default_value' => isset($data['stock']) ? $data['stock'] : 0,
      '#options' => array(
        t('Do not set stock level'),
        t('Set stock level using default value below'),
      ),
      '#description' => t('If setting a default stock level, stock will be set to active for products of this type.'),
    );
    $form['power_tools']['stock']['stock_settings'] = array(
      '#type' => 'textfield',
      '#size' => 32,
      '#title' => t('Default Stock'),
      '#description' => t('Default Stock level for products of this class.'),
      '#required' => FALSE,
      '#default_value' => isset($data['stock_settings']) ? $data['stock_settings'] : 0,
      '#weight' => 0,
      '#size' => 20,
    );
    $form['power_tools']['stock']['stock_threshold'] = array(
      '#type' => 'textfield',
      '#size' => 32,
      '#title' => t('Notification Threshold'),
      '#description' => t('When stock drops below this level you will be notified.'),
      '#required' => FALSE,
      '#default_value' => isset($data['stock_threshold']) ? $data['stock_threshold'] : 0,
      '#weight' => 0,
      '#size' => 20,
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#weight' => 10,
  );
  return $form;
}