rendered paste bodyfunction nmoderation_uservote_delete($vote_id) {
$output = drupal_get_form('nmoderation_uservote_delete_form', $vote_id);
return $output;
}
function nmoderation_uservote_delete_form($vote_id) {
$form['vote_id'] = array('#type' => 'value', '#value' => $vote_id);
$output = confirm_form(
$form,
t('Are you sure you want to delete this vote?'),
$_GET['destination'] ? $_GET['destination'] : 'nmoderation/voted',
t('This action cannot be undone.'),
t('Delete Vote'),
t('Cancel')
);
var_export($output);
return $output;
}
function nmoderation_uservote_delete_form_submit($form_id, $form_values) {
global $user;
if ($form_values['confirm']) {
$sql = 'SELECT * FROM {votingapi_vote} WHERE vote_id = %d';
$vote = db_fetch_object(db_query($sql, $vote_id));
if ($user->uid == $vote->uid || user_access('administer node moderation votes')) {
votingapi_delete_vote($vote);
votingapi_recalculate_results($vote->content_type, $vote->content_id);
nmoderation_set_promote($vote->content_id, $vote->content_type);
drupal_set_message(t('Vote deleted.'));
drupal_goto('nmoderation/voted');
}
else {
drupal_access_denied();
}
}
}