You are here

function advpoll_electoral_list_form in Advanced Poll 7

Same name and namespace in other branches
  1. 5 advpoll.module \advpoll_electoral_list_form()
  2. 6.3 advpoll.module \advpoll_electoral_list_form()
  3. 6 advpoll.module \advpoll_electoral_list_form()
  4. 6.2 advpoll.module \advpoll_electoral_list_form()
  5. 7.3 includes/advpoll.pages.inc \advpoll_electoral_list_form()
  6. 7.2 includes/advpoll.pages.inc \advpoll_electoral_list_form()

Build electorial list form.

1 string reference to 'advpoll_electoral_list_form'
advpoll_electoral_list_page in includes/advpoll.pages.inc

File

includes/advpoll.pages.inc, line 178

Code

function advpoll_electoral_list_form($form, &$form_state, $nid) {
  $form['electoral_list'] = array(
    '#type' => 'fieldset',
    '#tree' => TRUE,
    '#title' => t('Administer electoral list'),
    '#collapsible' => TRUE,
    '#weight' => 2,
  );
  $form['electoral_list']['add_user'] = array(
    '#type' => 'textfield',
    '#title' => t('Add user'),
    '#size' => 40,
    '#description' => t('Add an individual user to the electoral list.'),
  );

  // Enable autocompletion if user has required permission.
  if (user_access('access user profiles')) {
    $form['electoral_list']['add_user']['#autocomplete_path'] = 'user/autocomplete';
  }

  // List all roles with "vote on polls" permission, but don't include anonymous users.
  $result = db_query("SELECT r.name, r.rid FROM {role} r LEFT JOIN {role_permission} p ON p.rid = r.rid WHERE p.permission LIKE '%vote on polls%' AND r.rid <> 1 ORDER BY r.name");
  $role_options = array(
    0 => t('(Select a role)'),
  );
  foreach ($result as $record) {
    $role_options[$record->rid] = $record->name;
  }
  $form['electoral_list']['add_role'] = array(
    '#type' => 'select',
    '#title' => t('Add users by role'),
    '#description' => t('Only roles that have the "vote on polls" permission are listed.'),
    '#options' => $role_options,
  );
  $form['electoral_list']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Add to electoral list'),
  );
  $form['electoral_list']['reset'] = array(
    '#type' => 'button',
    '#value' => t('Clear electoral list'),
  );
  $form['nid'] = array(
    '#type' => 'hidden',
    '#value' => $nid,
  );
  return $form;
}