function advpoll_electoral_list_form_submit in Advanced Poll 6.3
Same name and namespace in other branches
- 5 advpoll.module \advpoll_electoral_list_form_submit()
- 6 advpoll.module \advpoll_electoral_list_form_submit()
- 6.2 advpoll.module \advpoll_electoral_list_form_submit()
- 7.3 includes/advpoll.pages.inc \advpoll_electoral_list_form_submit()
- 7 includes/advpoll.pages.inc \advpoll_electoral_list_form_submit()
- 7.2 includes/advpoll.pages.inc \advpoll_electoral_list_form_submit()
Process advpoll_electorial_list form submissions.
Submit changes to the electoral list.
File
- ./
advpoll.module, line 1066 - Advanced Poll - a sophisticated polling module for voting, elections, and group decision-making.
Code
function advpoll_electoral_list_form_submit($form, &$form_state) {
$add_user = $form_state['values']['electoral_list']['add_user'];
if ($add_user) {
db_query("REPLACE INTO {advpoll_electoral_list} (nid, uid) SELECT '%d', u.uid FROM {users} u WHERE u.name = '%s'", $form_state['values']['nid'], $add_user);
drupal_set_message(t('%user added to electoral list.', array(
'%user' => $add_user,
)));
}
$add_role = $form_state['values']['electoral_list']['add_role'];
if ($add_role) {
// Get the current electoral list.
$result = db_query('SELECT uid FROM {advpoll_electoral_list} WHERE nid = %d', $form_state['values']['nid']);
$current_list = array(
0,
);
while ($user = db_fetch_object($result)) {
$current_list[] = $user->uid;
}
$user_in_string = implode(',', $current_list);
// Check if all authenticated users should be added.
$is_authenticated = db_result(db_query("SELECT COUNT(*) FROM {role} r WHERE r.name = 'authenticated user' AND r.rid = %d", $add_role));
if ($is_authenticated) {
// Special case: any authenticated user can vote.
// Add all current users to electoral list.
$result = db_query("INSERT INTO {advpoll_electoral_list} (nid, uid) SELECT '%d', u.uid FROM {users} u WHERE u.uid NOT IN('%s')", $form_state['values']['nid'], $user_in_string);
}
else {
// Insert new users into the electoral_list based on the role chosen.
$result = db_query("INSERT INTO {advpoll_electoral_list} (nid, uid) SELECT '%d', u.uid FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid WHERE ur.rid = %d AND u.uid NOT IN('%s')", $form_state['values']['nid'], $add_role, $user_in_string);
}
drupal_set_message(format_plural(db_affected_rows($result), 'Added 1 user to the electoral list.', 'Added @count users to the electoral list.'));
}
}