You are here

function user_badges_products_list_form in User Badges 6

Same name and namespace in other branches
  1. 6.2 user_badges_products.module \user_badges_products_list_form()

Form builder; list of badges

1 string reference to 'user_badges_products_list_form'
user_badges_products_menu in ./user_badges_products.module
Implementation of hook_menu().

File

./user_badges_products.module, line 58
@brief User Badges Product module file

Code

function user_badges_products_list_form() {

  // load the badges that we want to display
  $form['header'] = array(
    '#type' => 'value',
    '#value' => array(
      array(
        'data' => t('Product'),
        'field' => 'title',
        'sort' => 'asc',
      ),
      array(
        'data' => t('Badge'),
        'field' => 'weight',
      ),
      array(
        'data' => t('Remove'),
      ),
      array(
        'data' => t('New Badge'),
      ),
    ),
  );
  $result = pager_query('SELECT ubb.*, n.title, n.nid FROM {ec_product} p INNER JOIN {node} n ON p.nid = n.nid LEFT JOIN {user_badges_product} ubp ON ubp.nid=p.nid LEFT JOIN {user_badges_badges} ubb ON ubp.bid=ubb.bid' . tablesort_sql($form['header']['#value']), 50);

  // build a table listing the appropriate badges
  while ($badgeprod = db_fetch_object($result)) {
    $form['name'][$badgeprod->nid] = array(
      '#value' => check_plain($badgeprod->title),
    );
    $form['newbadge'][$badgeprod->nid] = array(
      '#type' => 'textfield',
      '#size' => 40,
      '#maxlength' => 255,
      '#autocomplete_path' => 'user_badges/autocomplete',
    );

    //Only make these elements active if there is a badge
    if ($badgeprod->bid) {
      $form['badge'][$badgeprod->nid] = array(
        '#value' => theme('user_badge', $badgeprod),
      );
      $form['clear']['clear' . $badgeprod->nid] = array(
        '#type' => 'checkbox',
        '#return_value' => 1,
        '#default_value' => 0,
      );
    }
    else {
      $form['badge'][$badgeprod->nid] = array(
        '#value' => ' ',
      );
      $form['clear']['clear' . $badgeprod->nid] = array(
        '#value' => ' ',
      );
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
  );
  $form['pager'] = array(
    '#value' => theme('pager', NULL, 50, 0),
  );
  return $form;
}