You are here

function uc_wishlist_settings_form in UC Wish List 6

Same name and namespace in other branches
  1. 7 uc_wishlist.pages.inc \uc_wishlist_settings_form()
1 string reference to 'uc_wishlist_settings_form'
uc_wishlist_display in ./uc_wishlist.pages.inc
Display a wish list for viewing or altering.

File

./uc_wishlist.pages.inc, line 96
Page callback and functions for wish lists.

Code

function uc_wishlist_settings_form($form_state, $wishlist, $collapsed = FALSE) {
  global $user;
  drupal_add_js(drupal_get_path('module', 'uc_wishlist') . '/uc_wishlist.js');
  $expiration = getdate($wishlist->expiration);
  $expiration['day'] = $expiration['mday'];
  $expiration['month'] = $expiration['mon'];
  $form = array();
  $form['wishlist'] = array(
    '#type' => 'fieldset',
    '#title' => t('Wish list settings'),
    '#collapsible' => TRUE,
    '#collapsed' => $collapsed,
  );
  $form['wishlist']['wid'] = array(
    '#type' => 'hidden',
    '#value' => $wishlist->wid,
  );
  $form['wishlist']['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => $wishlist->title,
    '#required' => TRUE,
  );
  $form['wishlist']['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#default_value' => $wishlist->description,
    '#description' => t('Description of the Wishlist.'),
  );
  $form['wishlist']['expiration'] = array(
    '#type' => 'date',
    '#title' => t('Event or expiration date'),
    '#default_value' => $expiration,
    '#description' => t('If this wish list is associated with an event or will no longer be relevant on a specific date, enter it here.'),
  );
  $form['wishlist']['address'] = array(
    '#type' => 'fieldset',
    '#title' => t('Mailing address'),
    '#description' => t('The address you enter here will be available as a shipping address to anyone who purchases an item from your wish list.'),
  );
  if ($user->uid) {
    $addresses = uc_select_address($user->uid, 'delivery', 'apply_address(\'delivery\', this.value);', t('Saved addresses'), TRUE);
    if (!empty($addresses)) {
      $form['wishlist']['address']['delivery_address_select'] = $addresses;
      unset($form['wishlist']['address']['delivery_address_select']['#suffix']);
    }
  }
  if (uc_address_field_enabled('first_name')) {
    $form['wishlist']['address']['delivery_first_name'] = uc_textfield(uc_get_field_name('first_name'), $wishlist->address->firstname, uc_address_field_required('first_name'));
  }
  if (uc_address_field_enabled('last_name')) {
    $form['wishlist']['address']['delivery_last_name'] = uc_textfield(uc_get_field_name('last_name'), $wishlist->address->lastname, uc_address_field_required('last_name'));
  }
  if (uc_address_field_enabled('company')) {
    $form['wishlist']['address']['delivery_company'] = uc_textfield(uc_get_field_name('company'), $wishlist->address->company, uc_address_field_required('company'), NULL, 64);
  }
  if (uc_address_field_enabled('street1')) {
    $form['wishlist']['address']['delivery_street1'] = uc_textfield(uc_get_field_name('street1'), $wishlist->address->addr1, uc_address_field_required('street1'), NULL, 64);
  }
  if (uc_address_field_enabled('street2')) {
    $form['wishlist']['address']['delivery_street2'] = uc_textfield(uc_get_field_name('street2'), $wishlist->address->addr2, uc_address_field_required('street2'), NULL, 64);
  }
  if (uc_address_field_enabled('city')) {
    $form['wishlist']['address']['delivery_city'] = uc_textfield(uc_get_field_name('city'), $wishlist->address->city, uc_address_field_required('city'));
  }
  if (uc_address_field_enabled('country')) {
    $form['wishlist']['address']['delivery_country'] = uc_country_select(uc_get_field_name('country'), $wishlist->address->country, NULL, 'name', uc_address_field_required('country'));
  }
  if (uc_address_field_enabled('zone')) {
    if (isset($_POST['delivery_country'])) {
      $country_id = intval($_POST['delivery_country']);
    }
    else {
      $country_id = $wishlist->address->country;
    }
    $form['wishlist']['address']['delivery_zone'] = uc_zone_select(uc_get_field_name('zone'), $wishlist->address->zone, NULL, $country_id, 'name', uc_address_field_required('zone'));
    if (isset($_POST['panes']) && count($form['wishlist']['address']['delivery_zone']['#options']) == 1) {
      $form['wishlist']['address']['delivery_zone']['#required'] = FALSE;
    }
  }
  if (uc_address_field_enabled('postal_code')) {
    $form['wishlist']['address']['delivery_postal_code'] = uc_textfield(uc_get_field_name('postal_code'), $wishlist->address->postcode, uc_address_field_required('postal_code'), NULL, 10, 10);
  }
  if (uc_address_field_enabled('phone')) {
    $form['wishlist']['address']['delivery_phone'] = uc_textfield(uc_get_field_name('phone'), $wishlist->address->phone, uc_address_field_required('phone'), NULL, 32, 16);
  }
  $form['wishlist']['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save settings'),
  );
  return $form;
}