You are here

function advpoll_electoral_list_form_submit in Advanced Poll 7.3

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

Handles results of submitting electoral administration form.

File

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

Code

function advpoll_electoral_list_form_submit($form, &$form_state) {
  $add_user = $form_state['values']['electoral_list']['add_user'];
  $nid = $form_state['values']['nid'];

  /* Using new db_merge method to avoid having to write multiple checks for
   * insert.
   */
  if ($add_user) {
    $uid = db_query("\n      SELECT uid\n      FROM {users}\n      WHERE name = :user\n    ", array(
      ':user' => $add_user,
    ))
      ->fetchField();
    db_merge('advpoll_electoral_list')
      ->key(array(
      'nid' => $nid,
      'uid' => $uid,
    ))
      ->fields(array(
      'nid' => $nid,
      'uid' => $uid,
    ))
      ->execute();
    drupal_set_message(t('%user added to electoral list.', array(
      '%user' => $add_user,
    )));
  }
  $add_role = $form_state['values']['electoral_list']['add_role'];
  $roles = $form['electoral_list']['add_role']['#options'];
  if ($add_role) {
    $result = db_query("\n      SELECT u.uid\n      FROM {users} u\n      LEFT JOIN {users_roles} ur ON u.uid = ur.uid\n      WHERE ur.rid = :rid\n    ", array(
      ':rid' => $add_role,
    ));
    foreach ($result as $record) {
      db_merge('advpoll_electoral_list')
        ->key(array(
        'nid' => $nid,
        'uid' => $record->uid,
      ))
        ->fields(array(
        'nid' => $nid,
        'uid' => $record->uid,
      ))
        ->execute();
    }
    drupal_set_message(t('All users with %role role added to electoral list.', array(
      '%role' => $roles[$add_role],
    )));
  }
}