Index: votingapi.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/votingapi/votingapi.module,v
retrieving revision 1.38
diff -u -p -r1.38 votingapi.module
--- votingapi.module	1 Jul 2006 14:07:46 -0000	1.38
+++ votingapi.module	28 May 2007 13:57:58 -0000
@@ -115,16 +115,23 @@ function votingapi_set_vote($content_typ
       $vote->tag = VOTINGAPI_VALUE_DEFAULT_TAG;
     }
 
-    $result = db_query("SELECT * FROM {votingapi_vote} WHERE content_type='%s' AND content_id=%d AND tag='%s' AND value_type='%s' AND uid=%d", $content_type, $content_id, $vote->tag, $vote->value_type, $uid);
+  if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
+    $hostname = $_SERVER['HTTP_X_FORWARDED_FOR'];
+  }
+  else {
+    $hostname = $_SERVER['REMOTE_ADDR'];
+  }
+
+    $result = db_query("SELECT * FROM {votingapi_vote} WHERE content_type='%s' AND content_id=%d AND tag='%s' AND value_type='%s' AND uid=%d AND hostname='%s'", $content_type, $content_id, $vote->tag, $vote->value_type, $uid, $hostname);
     while ($vobj = db_fetch_object($result)) {
       votingapi_change_vote($vobj, $vote->value);
       $exists = TRUE;
     }
     if (!$exists) {
-      votingapi_add_vote($content_type, $content_id, $vote->value, $vote->value_type, $vote->tag, $uid);
+      votingapi_add_vote($content_type, $content_id, $vote->value, $vote->value_type, $vote->tag, $uid, $hostname );
     }
   }
-
+  
   if ($recursion) {
     return $vobj;
   }
@@ -153,8 +160,9 @@ function votingapi_unset_vote($content_t
     global $user;
     $uid = $user->uid;
   }
+  $hostname = $uid ? NULL : $user->hostname;
 
-  $votes = votingapi_get_user_votes($content_type, $content_id, $uid);
+  $votes = votingapi_get_user_votes($content_type, $content_id, $uid, $hostname);
   foreach ($votes as $vobj) {
     votingapi_delete_vote($vobj);
   }
@@ -190,7 +198,7 @@ function votingapi_unset_vote($content_t
  * @return
  *   The $vote object cast.
  */
-function votingapi_add_vote($content_type, $content_id, $value, $value_type = VOTINGAPI_VALUE_DEFAULT_TYPE, $tag = VOTINGAPI_VALUE_DEFAULT_TAG, $uid = NULL) {
+function votingapi_add_vote($content_type, $content_id, $value, $value_type = VOTINGAPI_VALUE_DEFAULT_TYPE, $tag = VOTINGAPI_VALUE_DEFAULT_TAG, $uid = NULL, $hostname=NULL) {
   if ($uid == NULL) {
     global $user;
     $uid = $user->uid;
@@ -204,13 +212,15 @@ function votingapi_add_vote($content_typ
   $vobj->tag = $tag;
   $vobj->uid = $uid;
   $vobj->timestamp = time();
+
+  $vobj->hostname = $_SERVER['REMOTE_ADDR'];
+  //Append internal IP if it exists.
   if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
-    $vobj->hostname = $_SERVER['HTTP_X_FORWARDED_FOR'];
-  }
-  else {
-    $vobj->hostname = $_SERVER['REMOTE_ADDR'];
+    $vobj->hostname .= '-'. $_SERVER['HTTP_X_FORWARDED_FOR'];
   }
-
+  if($hostname != NULL)
+  $vobj->hostname = $hostname;
+    
   db_query("INSERT INTO {votingapi_vote} (vote_id, content_type, content_id, value, value_type, tag, uid, timestamp, hostname) VALUES (%d, '%s', %d, %f, '%s', '%s', %d, %d, '%s')", 
     $vobj->vote_id, $vobj->content_type, $vobj->content_id, $vobj->value, $vobj->value_type, $vobj->tag, $vobj->uid, $vobj->timestamp, $vobj->hostname);
 
@@ -275,7 +285,7 @@ function votingapi_delete_votes($votes =
 /**
  * An internal utility function used to pull raw votes for processing. Undocumented at the moment..
  */
-function _votingapi_get_raw_votes($content_type, $content_id, $value_type = NULL, $tag_list = NULL, $uid = NULL) {
+function _votingapi_get_raw_votes($content_type, $content_id, $value_type = NULL, $tag_list = NULL, $uid = NULL, $hostname = NULL) {
   if ($tag_list) {
     $filter_string .= " AND v.tag IN ('" . implode("','",$tag_list) . "')";
   }
@@ -300,6 +310,10 @@ function _votingapi_get_raw_votes($conte
     $filter_string .= " AND v.value_type = '" . $value_type . "'";
   }
 
+  if ($hostname != NULL) { 
+    $filter_string .= " AND hostname = '$hostname'";
+  }
+
   $votes = array();
   $result = db_query("SELECT * FROM {votingapi_vote} v WHERE content_type='%s' AND content_id=%d $filter_string", $content_type, $content_id);
   while ($vobj = db_fetch_object($result)) {
@@ -323,12 +337,12 @@ function _votingapi_get_raw_votes($conte
  * @return
  *   An array of matching votingapi_vote records.
  */
-function votingapi_get_user_votes($content_type, $content_id, $uid = NULL) {
+function votingapi_get_user_votes($content_type, $content_id, $uid = NULL, $hostname = NULL) {
   if ($uid == NULL) {
     global $user;
     $uid = $user->uid;
   }
-  return _votingapi_get_raw_votes($content_type, $content_id, NULL, NULL, $uid);
+  return _votingapi_get_raw_votes($content_type, $content_id, NULL, NULL, $uid, $hostname);
 }
 
 
@@ -739,4 +753,4 @@ function votingapi_vote_value_types() {
   }
   return $votingapi_vote_value_types;
 }
- 
\ No newline at end of file
+ 
