You are here

function advpoll_electoral_list_form in Advanced Poll 7.3

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 includes/advpoll.pages.inc \advpoll_electoral_list_form()
  6. 7.2 includes/advpoll.pages.inc \advpoll_electoral_list_form()

Form for adding or removing users on the electoral list page.

1 string reference to 'advpoll_electoral_list_form'
advpoll_electoral_list_page in includes/advpoll.pages.inc
Displays contents of electoral list page.

File

includes/advpoll.pages.inc, line 226
Advanced Poll Pages Include.

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';
  }

  /* Check to see if basic authorized users (2) have permission to vote.
   * If this is the case, new roles added after auth was selected in permissions
   * may not show up in list. This check ensures that all roles get added to the
   * list if auth users are included.
   */
  $auth = db_query("\n    SELECT r.name, r.rid\n    FROM {role} r\n    LEFT JOIN {role_permission} p ON p.rid = r.rid\n    WHERE p.permission LIKE '%vote on polls%'\n    AND r.rid = 2 ORDER BY r.name\n  ")
    ->fetchField();

  /* List all roles with "vote on polls" permission, but don't include anonymous
   * users.
   */
  if ($auth) {
    $result = db_query("\n      SELECT r.name, r.rid\n      FROM {role} r\n      WHERE r.rid <> 1 ORDER BY r.name\n    ");
  }
  else {
    $result = db_query("\n      SELECT r.name, r.rid\n      FROM {role} r\n      LEFT JOIN {role_permission} p ON p.rid = r.rid\n      WHERE p.permission LIKE '%vote on polls%'\n      AND r.rid <> 1 ORDER BY r.name\n    ");
  }
  $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;
}