--- extra_voting_forms.js 2009-06-17 10:55:05.000000000 -0400 +++ extra_voting_forms.js.new 2009-06-17 10:58:04.000000000 -0400 @@ -72,7 +72,7 @@ var KarmaSendForm = function() { else if ( form.find('.tmpClicked').length > 0 ) { var tmpclicked = $(form.find('.tmpClicked')[0] ); tmpclicked.removeClass('tmpClicked'); - if ( karma_clicked_indicator( tmpclicked ) == 'clicked' ) { + if (( karma_clicked_indicator( tmpclicked ) == 'clicked' ) && ( Drupal.settings.extra_voting_forms.only_one_vote == 1 ) ) { return false; } else { @@ -201,7 +201,7 @@ var KarmaStripForm = function(form,args // Update all the karma scores for this node $("#" + did + " span.karma_score").text(args.karma_aggregate); var did = prefix + args.oid; - if ( did != fid ) { + if ( ( did != fid ) && ( Drupal.settings.extra_voting_forms.only_one_vote == 1 ) ){ // Disable all drop-down select elements $("#" + did + " *").attr("disabled", "true"); --- extra_voting_forms.module 2009-06-17 10:55:05.000000000 -0400 +++ extra_voting_forms.module.new 2009-06-17 10:58:12.000000000 -0400 @@ -57,6 +57,8 @@ function extra_voting_forms_menu() { * Implementation of hook_init(). */ function extra_voting_forms_init(){ + global $user; + // Create the $css_file_complete variable $css_file = 'extra_voting_forms_all.css'; $widget_dir = variable_get('extra_voting_forms_widget_dir', 'default'); @@ -79,11 +81,20 @@ function extra_voting_forms_init(){ // Add the module-specific js file drupal_add_js(drupal_get_path('module', 'extra_voting_forms') .'/extra_voting_forms.js'); + // Determine if the user is allowed to vote multiple times. + $multiple_votes_allowed = !variable_get('extra_voting_forms_only_one_vote', FALSE); + $is_a_voting_admin = user_access('voting_administrator'); + $belongs_to_multiple_votes_role = isset($user->roles[variable_get('extra_voting_forms_multiple_votes_role', 0)]); + if ($multiple_votes_allowed and ($is_a_voting_admin or $belongs_to_multiple_votes_role)) + {$user_has_only_one_vote = 0;} + else + {$user_has_only_one_vote = 1;} + // Add our JavaScript variables: drupal_add_js(array( 'extra_voting_forms' => array( - // Set the right javascript to see of only one vote is allowed: - 'only_one_vote' => variable_get('extra_voting_forms_only_one_vote', FALSE) && ! user_access('voting administrator') ? 1 : 0, + // Set the right javascript to see if only one vote is allowed: + 'only_one_vote' => $user_has_only_one_vote, // Set the anonymous URL: 'login_page' => extra_voting_forms_anonymous_url(), // Get the base path: @@ -99,7 +110,7 @@ function extra_voting_forms_init(){ * The config form */ function extra_voting_forms_admin_settings() { - + $form['extra_voting_forms_widget_dir_sections'] = array( '#type' => 'fieldset', '#title' => t('Directory for Widgets'), @@ -193,11 +204,30 @@ function extra_voting_forms_admin_settin '#description' => t('Please see documentation to know what each style is'), ); - $form['extra_voting_forms_only_one_vote'] = array( + $form['extra_voting_forms_multiple_votes'] = array( + '#type' => 'fieldset', + '#title' => t('Multiple Votes'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + ); + + $form['extra_voting_forms_multiple_votes']['extra_voting_forms_only_one_vote'] = array( '#type' => 'checkbox', - '#title' => t('Only allow one vote - no re-voting allowed'), + '#title' => t('Users may only cast one vote per node, and votes can be changed.'), '#default_value' => variable_get('extra_voting_forms_only_one_vote', TRUE), ); + + // Get an array of non-anonymous roles, and prefix the array with "None". + $roles_for_multiple_votes = user_roles(TRUE); + $roles_for_multiple_votes[0] = 'None'; + + $form['extra_voting_forms_multiple_votes']['extra_voting_forms_multiple_votes_role'] = array( + '#type' => 'select', + '#title' => t('Which group is allowed to cast multiple votes on the same content?'), + '#default_value' => variable_get('extra_voting_forms_multiple_votes_role', 0), + '#options' => $roles_for_multiple_votes, + '#description' => t('NOTE: This setting will have no effect if users may only cast one vote per node.'), + ); $form['extra_voting_forms_hide_given_select_votes'] = array( '#type' => 'checkbox', @@ -861,6 +891,14 @@ function extra_voting_forms_give_vote($o } } + # Determine whether or not this user is allowed to cast multiple votes on this content. + if ($only_one_vote_allowed === true) + {$vote_deletion_criteria = null;} + else if (isset($account->roles[variable_get('extra_voting_forms_multiple_votes_role', 0)])) + {$vote_deletion_criteria = array();} + else + {$vote_deletion_criteria = null;} + // Give the actual vote using the Voting API $votes = array(); $votes['content_type'] = extra_voting_forms_c($o->sk_type); @@ -868,7 +906,7 @@ function extra_voting_forms_give_vote($o $votes['uid'] = $account->uid; $votes['value_type'] = 'points'; $votes['value'] = $vote; - $result = votingapi_set_votes($votes); + $result = votingapi_set_votes($votes, $vote_deletion_criteria); // Get the current number of votes $criteria = array();