You are here

function uc_wishlist_search_form in UC Wish List 6

Same name and namespace in other branches
  1. 7 uc_wishlist.pages.inc \uc_wishlist_search_form()
1 string reference to 'uc_wishlist_search_form'
uc_wishlist_menu in ./uc_wishlist.module
Implementation of hook_menu().

File

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

Code

function uc_wishlist_search_form($form_state, $keywords = '') {
  global $user;
  $form = array();

  // Generate link to 'create or manage your wish list'.
  $path = 'wishlist';
  $query = NULL;
  if (!$user->uid && !variable_get('uc_wishlist_allow_anonymous', FALSE)) {
    $path = 'user';
    $query = 'destination=wishlist';
  }
  $form['wishlist_link'] = array(
    '#value' => '<div>' . l(t('Create or manage your wish list.'), $path, array(
      'query' => $query,
    )) . '</div>',
  );
  $form['search'] = array(
    '#type' => 'fieldset',
  );
  $form['search']['keywords'] = array(
    '#type' => 'textfield',
    '#title' => t('Search keywords'),
    '#description' => t('Enter the keywords to use to search wish list titles and addresses.'),
    '#default_value' => $keywords,
  );
  $form['search']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
  );
  if (!empty($keywords)) {

    // Check for user, wish list title, or address matches.
    $result = pager_query("SELECT DISTINCT w.wid, w.title FROM {uc_wishlists} AS w JOIN {users} AS u ON w.uid = u.uid WHERE u.name LIKE '%%%s%%' OR w.title LIKE '%%%s%%' OR w.address LIKE '%%firstname%%%s%%addr1%%' ORDER BY w.title", 25, 0, NULL, $keywords, $keywords, $keywords);
  }
  else {
    $result = pager_query("SELECT wid, title FROM {uc_wishlists} ORDER BY title", 25);
  }
  $links = array();
  while ($wishlist = db_fetch_object($result)) {
    $links[] = array(
      'title' => filter_xss($wishlist->title, array()),
      'href' => 'wishlist/' . $wishlist->wid,
    );
  }
  if (!empty($links)) {
    $output = theme_links($links, array(
      'class' => 'wishlist',
    ));
  }
  else {
    $output = t('No wish lists found.');
  }
  $form['output'] = array(
    '#value' => '<div><h2>' . t('Wish lists:') . '</h2>' . $output . '</div>',
  );
  return $form;
}