--- userpoints_votingapi.module	2009-03-20 23:36:33.000000000 -0700
+++ userpoints_votingapi.module.new	2009-06-16 22:42:28.000000000 -0700
@@ -36,13 +36,28 @@ function userpoints_votingapi_form_alter
       '#maxlength' => 5,
     );
 
-    $form[$group][userpoints_votingapi_daily_threshold] = array(
-      '#type' => 'select',
-      '#title' => t('Daily threshold'),
-      '#options' => drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50)),
-      '#default_value' => variable_get(userpoints_votingapi_daily_threshold, 0),
-      '#description' => t('The maximum number of votes -- that will earn User Points -- in a 24-hour period.<br />Select 0 to ignore.'),
+    $form[$group][userpoints_votingapi_threshold] = array(
+      '#type' => 'textfield',
+      '#title' => t('Threshold'),
+      '#size' => 5,
+      '#maxlength' => 5,
+      '#default_value' => variable_get(userpoints_votingapi_threshold, 0),
+      '#description' => t('The maximum number of votes -- that will earn User Points -- during the selected period.<br />Enter 0 to ignore.'),
     );
+    
+    $form[$group][userpoints_votingapi_period] = array(
+    '#type' => 'select',
+    '#title' => t('Period'),
+    '#options' => array(
+      '3600' => t('Hourly'),
+      '86400' => t('Daily'),
+      '604800' => t('Weekly'),
+      '2592000' => t('Monthly (30 days)'),
+      '31536000' => t('Annually'),
+    ),
+    '#default_value' => variable_get(userpoints_votingapi_period, 86400),
+    '#description' => t('The time period during which the threshold applies.'),
+  );
 
     $form[$group]['userpoints_votingapi_tid'] = array(
       '#type' => 'select',
@@ -61,7 +76,7 @@ function userpoints_votingapi_form_alter
  */
 function userpoints_votingapi_votingapi_insert($vote) {
   $vote = $vote[0];
-  $threshold = variable_get(userpoints_votingapi_daily_threshold, 0);
+  $threshold = variable_get(userpoints_votingapi_threshold, 0);
   if (($threshold == '0') OR (userpoints_votingapi_within_threshold($vote['uid'], $threshold))) {
   userpoints_userpointsapi(array(
     'uid' => $vote['uid'],
@@ -84,7 +99,7 @@ function userpoints_votingapi_votingapi_
  */
 function userpoints_votingapi_votingapi_delete($vote) {
   $vote = $vote[0];
-  $threshold = variable_get(userpoints_votingapi_daily_threshold, 0);
+  $threshold = variable_get(userpoints_votingapi_threshold, 0);
   if (($threshold == '0') OR (userpoints_votingapi_within_threshold($vote['uid'], $threshold))) {
   userpoints_userpointsapi(array(
     'uid' => $vote['uid'],
@@ -102,6 +117,6 @@ function userpoints_votingapi_votingapi_
 }
 
 function userpoints_votingapi_within_threshold($uid, $threshold) {
-  $number = db_result(db_query("SELECT COUNT(*) FROM {votingapi_vote} WHERE uid = %d AND timestamp > %d", $uid, time() - 86400));
-  return ($number <= $threshold ? TRUE : FALSE);
-}
\ No newline at end of file
+  $number = db_result(db_query("SELECT COUNT(*) FROM {userpoints_txn} WHERE uid = %d AND time_stamp > %d AND operation = 'vote' AND points > 0", $uid, time() - variable_get(userpoints_votingapi_period, 86400)));
+  return ($number < $threshold ? TRUE : FALSE);
+}
