--- sites/all/modules/pollfield/pollfield.module	2009-11-09 17:38:22.000000000 -0600
+++ sites/all/modules/pollfield/pollfield.module_new	2009-11-09 17:36:54.000000000 -0600
@@ -21,15 +21,15 @@ function pollfield_menu() {
  */
 function pollfield_perm() {
 
-  //get table
-	$fields = content_fields();
+  // get table
+  $fields = content_fields();
   foreach ($fields as $i => $key) {
-		if ($fields[$i]['module']=='pollfield'){
-		  $permission[]='view pollfield results '.$i;
-		}
-	}
-  
-	return $permission;
+    if ($fields[$i]['module']=='pollfield') {
+      $permission[]='view pollfield results '. $i;
+    }
+  }
+
+  return $permission;
 }
 
 /**
@@ -87,576 +87,557 @@ function pollfield_theme() {
 
 /**
  * What you see in the edit node
- *
- * @param unknown_type $element
- * @return unknown
  */
 function theme_pollfield($element) {
 
-  $output = "<fieldset class='menu-item-form collapsible collapsed pollfield-form'><legend>Pollfield settings</legend>".$element['#children'].'</fieldset>';
+  $output = '<fieldset class="menu-item-form collapsible collapsed pollfield-form"><legend>Pollfield settings</legend>'. $element['#children'] .'</fieldset>';
   return $output;
 }
 
 /**
- * what you see in the node view
- *
- * @param unknown_type $element
- * @return unknown
+ * What you see in the node view
  */
-function theme_pollfield_formatter_default($element) { 
+function theme_pollfield_formatter_default($element) {
   global $user;
   $items      = $element['#item'];
   $node       = $element['#node'];
   $type = $element['#type_name'];
   $field = $element['#field_name'];
   $field_name_delta=$element['#item']['#delta'];
-  //adding up the results
-  // kjh: default to showing form as false and enable it when we have an 
+  // adding up the results
+  // kjh: default to showing form as FALSE and enable it when we have an
   // at least one choice configured
-  $show_form = false;
-  if (is_array($items['poll_features'])){
-		$choices = $items['group'];
-		$poll_features = $items['poll_features'];
-	}
-	else{
+  $show_form = FALSE;
+  if (is_array($items['poll_features'])) {
+    $choices = $items['group'];
+    $poll_features = $items['poll_features'];
+  }
+  else{
     $choices = unserialize($items['choice']);
-		$poll_features = unserialize($items['poll_features']);
-	}
-	
-	//is user voted
-	$field_table=$node->type;$field_name=$field;
-	$is_vote = pollfield_user_voted($node,$field_table,$field_name,$field_name_delta);
-	$user_votes = pollfield_user_votes($node,$field_table,$field_name,$field_name_delta);
-	$is_results_allow=$poll_features['ResultsAllow'];
-	
-	
+    $poll_features = unserialize($items['poll_features']);
+  }
+
+  // is user voted
+  $field_table=$node->type;$field_name=$field;
+  $is_vote = pollfield_user_voted($node, $field_table, $field_name, $field_name_delta);
+  $user_votes = pollfield_user_votes($node, $field_table, $field_name, $field_name_delta);
+  $is_results_allow=$poll_features['ResultsAllow'];
+
+
   $votes=array();$choices_array=array();
-	if (!empty($choices)){
-		foreach ($choices as $delta => $choice) {
-		
-			if (!empty($choice['choice'])){
-				$show_form = true;
-				$choices_array[] = check_plain($choice['choice']);
-				$count = db_result(db_query("SELECT count(*) FROM {pollfield_votes} WHERE nid = %d AND delta=%d 
-						AND field_table='%s' AND field_name='%s' AND field_name_delta=%d",
-								$node->nid, $delta,$type,$field,$field_name_delta));
-				$votes[] = $count+$choice['votes'];
-				$sum = $sum+$count+$choice['votes'];//countig all votes		
-			}
-		}
-	}
-
-	//geting results
-	$i=0;
-	$poll_result="<div id='pollfield'>";
-  
-  while (!empty($choices_array[$i]) && $sum>0){
-		$percent = floatval(($votes[$i]*100.0)/$sum);
-		$percent = round($percent,1);
-		//$votes[$i]=$percent;
-		$percent_string = $percent."% (".$votes[$i]." ".t('votes').")";
-	
-		//check user voted
-		$is_this_user_vote = false;
-		if (is_array($user_votes)){
-			//get if user voted on this choice
-			foreach($user_votes as $value){
-				if ($value==$i){
-					$is_this_user_vote = true;
-				}
-			}
-		}
-		//marked chosen answer
-	  if ($is_this_user_vote){
-			$poll_result .= "<div class='pollfield-row pollfield-chosen'><div class='text'>".$choices_array[$i]."</div><div class='barcell'><div 
-			class='bar'><div class='pollfield-foreground' style='width: ".$percent."%;'></div></div></div><div class='pollfield-percent'>".
-			$percent_string."</div></div>";
-		}
-		else{
-			$poll_result .= "<div class='pollfield-row'><div class='text'>".$choices_array[$i]."</div><div class='barcell'>
-			<div class='bar'><div class='pollfield-foreground' style='width: ".$percent."%;'></div></div></div><div class='pollfield-percent'>".
-			$percent_string."</div></div>";
-
-		}
-		$i++;
-  }
-	$poll_result .= "</div>";
-	
-   
+  if (!empty($choices)) {
+    foreach ($choices as $delta => $choice) {
+
+      if (!empty($choice['choice'])) {
+        $show_form = TRUE;
+        $choices_array[] = check_plain($choice['choice']);
+        $count = db_result(db_query("SELECT count(*) FROM {pollfield_votes} WHERE nid = %d AND delta=%d
+            AND field_table='%s' AND field_name='%s' AND field_name_delta=%d",
+                $node->nid, $delta, $type, $field, $field_name_delta));
+        $votes[] = $count+$choice['votes'];
+        $sum = $sum+$count+$choice['votes']; // countig all votes
+      }
+    }
+  }
+
+  // geting results
+  $i=0;
+  $poll_result='<div id="pollfield">';
+
+  while (!empty($choices_array[$i]) && $sum>0) {
+    $percent = floatval(($votes[$i]*100.0)/$sum);
+    $percent = round($percent, 1);
+    // $votes[$i]=$percent;
+    $percent_string = $percent .'% ('. $votes[$i] .' '. t('votes') .')';
+
+    // check user voted
+    $is_this_user_vote = FALSE;
+    if (is_array($user_votes)) {
+      // get if user voted on this choice
+      foreach ($user_votes as $value) {
+        if ($value==$i) {
+          $is_this_user_vote = TRUE;
+        }
+      }
+    }
+    // marked chosen answer
+    if ($is_this_user_vote) {
+      $poll_result .= "<div class='pollfield-row pollfield-chosen'><div class='text'>". $choices_array[$i] ."</div><div class='barcell'><div
+      class='bar'><div class='pollfield-foreground' style='width: ". $percent ."%;'></div></div></div><div class='pollfield-percent'>".
+      $percent_string ."</div></div>";
+    }
+    else {
+      $poll_result .= "<div class='pollfield-row'><div class='text'>". $choices_array[$i] ."</div><div class='barcell'>
+      <div class='bar'><div class='pollfield-foreground' style='width: ". $percent ."%;'></div></div></div><div class='pollfield-percent'>".
+      $percent_string ."</div></div>";
+
+    }
+    $i++;
+  }
+  $poll_result .= "</div>";
+
+
   if ($show_form) {
-		$form = pollfield_voting_form($element);
-		$out = '<div class="pollfield-form">';
-    
-    if ($element['#item']['question']!="' '"){
-    	$out .= '<div class="pollfield-title">'.check_plain($element['#item']['question']).'</div>';
-		}
-
-		$out .= $form;
-		$permission='view pollfield results '.$field_name;
-		if (user_access($permission)){
-			if ( $is_vote || $is_results_allow){
-				$out .= $poll_result;
-			}
-		}
-		$out .= '</div>';
-		return $out;
-  } 
-  
+    $form = pollfield_voting_form($element);
+    $out = '<div class="pollfield-form">';
+
+    if ($element['#item']['question']!="' '") {
+      $out .= '<div class="pollfield-title">'. check_plain($element['#item']['question']) .'</div>';
+    }
+
+    $out .= $form;
+    $permission='view pollfield results '. $field_name;
+    if (user_access($permission)) {
+      if ( $is_vote || $is_results_allow) {
+        $out .= $poll_result;
+      }
+    }
+    $out .= '</div>';
+    return $out;
+  }
+
 }
 
 function theme_pollfield_formatter_results($element) {
-    // todo and other formattings
+    // @todo and other formattings
 
   global $user;
   $items      = $element['#item'];
   $node       = $element['#node'];
   $type = $element['#type_name'];
   $field = $element['#field_name'];
-	$field_name_delta = $element['#item']['#delta'];
-  //adding up the results
-  // kjh: default to showing form as false and enable it when we have an 
+  $field_name_delta = $element['#item']['#delta'];
+  // adding up the results
+  // kjh: default to showing form as FALSE and enable it when we have an
   // at least one choice configured
-  $show_form = false;
-  if (is_array($items['poll_features'])){
-		$choices=$items['group'];
-		$poll_features=$items['poll_features'];
-	}
-	else{
+  $show_form = FALSE;
+  if (is_array($items['poll_features'])) {
+    $choices=$items['group'];
+    $poll_features=$items['poll_features'];
+  }
+  else{
     $choices = unserialize($items['choice']);
-		$poll_features = unserialize($items['poll_features']);
-	}
-	
-	//is user voted
-	$field_table = $node->type;$field_name = $field;
-	$is_vote = pollfield_user_voted($node,$field_table,$field_name,$field_name_delta);
-	$user_votes = pollfield_user_votes($node,$field_table,$field_name,$field_name_delta);
-	$is_results_allow = $poll_features['ResultsAllow'];
-	
+    $poll_features = unserialize($items['poll_features']);
+  }
+
+  // is user voted
+  $field_table = $node->type;$field_name = $field;
+  $is_vote = pollfield_user_voted($node, $field_table, $field_name, $field_name_delta);
+  $user_votes = pollfield_user_votes($node, $field_table, $field_name, $field_name_delta);
+  $is_results_allow = $poll_features['ResultsAllow'];
+
   $votes = array();$choices_array = array();
-  if (!empty($choices)){
-		foreach ($choices as $delta => $choice) {
-			if (!empty($choice['choice'])){
-				$show_form = true;
-				$choices_array[] = check_plain($choice['choice']);
-				$count = db_result(db_query("SELECT count(*) FROM {pollfield_votes} WHERE nid = %d AND delta=%d 
-						AND field_table='%s' AND field_name='%s'",$node->nid, $delta,$type,$field));
-				$votes[] = $count+$choice['votes'];
-				$sum = $sum+$count+$choice['votes'];//countig all votes
-			}
-		}
+  if (!empty($choices)) {
+    foreach ($choices as $delta => $choice) {
+      if (!empty($choice['choice'])) {
+        $show_form = TRUE;
+        $choices_array[] = check_plain($choice['choice']);
+        $count = db_result(db_query("SELECT count(*) FROM {pollfield_votes} WHERE nid = %d AND delta=%d
+            AND field_table='%s' AND field_name='%s'", $node->nid, $delta, $type, $field));
+        $votes[] = $count+$choice['votes'];
+        $sum = $sum+$count+$choice['votes']; // countig all votes
+      }
+    }
   }
-	
-  //geting results
+
+  // geting results
   $i = 0;
   $poll_result = " ";
 
-	while (!empty($choices_array[$i]) && $sum>0){
-		$percent = floatval(($votes[$i]*100.0)/$sum);
-		$percent = round($percent,1);
-		$percent_string = $percent."% (".$votes[$i]." ".t('votes').")";
-		//$votes[$i]=$percent;
-		$is_this_user_vote = false;
-			
-		if ($is_vote){
-			//get if user voted on this choice
-			foreach($user_votes as $value){
-				if ($value==$i){
-					$is_this_user_vote = true;
-				}
-			}
-		}
-	  //marked chosen answer
-    if ($is_this_user_vote){
-			$poll_result .= "<div class='pollfield-row pollfield-chosen'><div class='text'>".$choices_array[$i]."</div><div class='barcell'>
-			<div class='bar'><div class='pollfield-foreground' style='width: ".$percent."%;'></div></div></div><div class='pollfield-percent'>".
-			$percent_string."</div></div>";
-		}
-		else{
-			$poll_result .= "<div class='pollfield-row'><div class='text'>".$choices_array[$i]."</div><div class='barcell'>
-			<div class='bar'><div class='pollfield-foreground' style='width: ".$percent."%;'></div></div></div><div class='pollfield-percent'>".
-			$percent_string."</div></div>";
-		}
-		$i++;
-	}
+  while (!empty($choices_array[$i]) && $sum>0) {
+    $percent = floatval(($votes[$i]*100.0)/$sum);
+    $percent = round($percent, 1);
+    $percent_string = $percent ."% (". $votes[$i] ." ". t('votes') .")";
+    // $votes[$i]=$percent;
+    $is_this_user_vote = FALSE;
+
+    if ($is_vote) {
+      // get if user voted on this choice
+      foreach ($user_votes as $value) {
+        if ($value==$i) {
+          $is_this_user_vote = TRUE;
+        }
+      }
+    }
+    // marked chosen answer
+    if ($is_this_user_vote) {
+      $poll_result .= "<div class='pollfield-row pollfield-chosen'><div class='text'>". $choices_array[$i] ."</div><div class='barcell'>
+      <div class='bar'><div class='pollfield-foreground' style='width: ". $percent ."%;'></div></div></div><div class='pollfield-percent'>".
+      $percent_string ."</div></div>";
+    }
+    else{
+      $poll_result .= "<div class='pollfield-row'><div class='text'>". $choices_array[$i] ."</div><div class='barcell'>
+      <div class='bar'><div class='pollfield-foreground' style='width: ". $percent ."%;'></div></div></div><div class='pollfield-percent'>".
+      $percent_string ."</div></div>";
+    }
+    $i++;
+  }
 
 
   if ($show_form) {
-		$form = pollfield_voting_form($element);
-		$out = '<div class="pollfield-results">';
-	
-		if ($element['#item']['question']!="' '")
-		  	$out .= '<div class="pollfield-title">'.check_plain($element['#item']['question']).'</div>';	
-
-		$permission='view pollfield results '.$field;
-		if (user_access($permission)){
-			$out .= $poll_result;
-		}
-		$out .= '</div>';
-		
-		return $out;
-  } 
+    $form = pollfield_voting_form($element);
+    $out = '<div class="pollfield-results">';
+
+    if ($element['#item']['question']!="' '")
+        $out .= '<div class="pollfield-title">'. check_plain($element['#item']['question']) .'</div>';
+
+    $permission='view pollfield results '. $field;
+    if (user_access($permission)) {
+      $out .= $poll_result;
+    }
+    $out .= '</div>';
+
+    return $out;
+  }
 }
 
 function theme_pollfield_formatter_choices($element) {
-  
+
   global $user;
   $items      = $element['#item'];
   $node       = $element['#node'];
   $type = $element['#type_name'];
   $field = $element['#field_name'];
-  //adding up the results
-  // kjh: default to showing form as false and enable it when we have an 
+  // adding up the results
+  // kjh: default to showing form as FALSE and enable it when we have an
   // at least one choice configured
-  $show_form = false;
-  if (is_array($items['poll_features'])){
-		$choices = $items['group'];
-		$poll_features = $items['poll_features'];
-	}
-	else{
-		$choices = unserialize($items['choice']);
-		$poll_features = unserialize($items['poll_features']);
-	}
-	
+  $show_form = FALSE;
+  if (is_array($items['poll_features'])) {
+    $choices = $items['group'];
+    $poll_features = $items['poll_features'];
+  }
+  else{
+    $choices = unserialize($items['choice']);
+    $poll_features = unserialize($items['poll_features']);
+  }
+
   $votes=array();$choices_array=array();
-  if (!empty($choices)){
-		foreach ($choices as $delta => $choice) {
-		  if (!empty($choice['choice'])){
-				$show_form = true;
-				$choices_array[] = check_plain($choice['choice']);
-				$count = db_result(db_query("SELECT count(*) FROM {pollfield_votes} WHERE nid = %d AND delta=%d 
-						AND field_table='%s' AND field_name='%s'",$node->nid, $delta,$type,$field));
-				$votes[]=$count+$choice['votes'];
-				$sum=$sum+$count+$choice['votes'];//countig all votes
-		
-		  }
-		}
+  if (!empty($choices)) {
+    foreach ($choices as $delta => $choice) {
+      if (!empty($choice['choice'])) {
+        $show_form = TRUE;
+        $choices_array[] = check_plain($choice['choice']);
+        $count = db_result(db_query("SELECT count(*) FROM {pollfield_votes} WHERE nid = %d AND delta=%d
+            AND field_table='%s' AND field_name='%s'", $node->nid, $delta, $type, $field));
+        $votes[]=$count+$choice['votes'];
+        $sum=$sum+$count+$choice['votes'];// countig all votes
+
+      }
+    }
   }
 
-  //geting results
+  // geting results
   $i = 0;
   $poll_result = " ";
 
-  while (!empty($choices_array[$i]) && $sum>0){
-		$percent = floatval(($votes[$i]*100.0)/$sum);
-		$percent = round($percent,1);
-		//$votes[$i]=$percent;
-		$percent_string = $percent."% (".$votes[$i]." ".t('votes').")";
-		$poll_result .= "<div class='pollfield-row'>".check_plain($choices_array[$i])."</div>";
-		$i++;
+  while (!empty($choices_array[$i]) && $sum>0) {
+    $percent = floatval(($votes[$i]*100.0)/$sum);
+    $percent = round($percent, 1);
+    // $votes[$i]=$percent;
+    $percent_string = $percent ."% (". $votes[$i] ." ". t('votes') .")";
+    $poll_result .= "<div class='pollfield-row'>". check_plain($choices_array[$i]) ."</div>";
+    $i++;
   }
 
   if ($show_form) {
-		$out = '<div class="pollfield-responses">';
-		$out .= $poll_result;
-		$out .= '</div>';
-	
-		return $out;
-  } 
-  
-  
+    $out = '<div class="pollfield-responses">';
+    $out .= $poll_result;
+    $out .= '</div>';
+
+    return $out;
+  }
+
+
 }
 
 function theme_pollfield_formatter_question($element) {
-  // todo and other formattings
+  // @todo and other formattings
   global $user;
   $items      = $element['#item'];
   $node       = $element['#node'];
   $type = $element['#type_name'];
   $field = $element['#field_name'];
-  //adding up the results
-  // kjh: default to showing form as false and enable it when we have an 
+  // adding up the results
+  // kjh: default to showing form as FALSE and enable it when we have an
   // at least one choice configured
-  $show_form = false;
-  if (is_array($items['poll_features'])){
-		$choices = $items['group'];
-		$poll_features = $items['poll_features'];
-	}
-	else{
-		$choices = unserialize($items['choice']);
-		$poll_features = unserialize($items['poll_features']);
-	}
-	
+  $show_form = FALSE;
+  if (is_array($items['poll_features'])) {
+    $choices = $items['group'];
+    $poll_features = $items['poll_features'];
+  }
+  else{
+    $choices = unserialize($items['choice']);
+    $poll_features = unserialize($items['poll_features']);
+  }
+
   $votes=array();$choices_array=array();
-  if (!empty($choices)){
-		foreach ($choices as $delta => $choice) {
-			if (!empty($choice['choice'])){
-				$show_form = true;
-				$choices_array[] = check_plain($choice['choice']);
-				$count = db_result(db_query("SELECT count(*) FROM {pollfield_votes} WHERE nid = %d AND delta=%d 
-						AND field_table='%s' AND field_name='%s'",$node->nid, $delta,$type,$field));
-				$votes[]=$count+$choice['votes'];
-				$sum = $sum+$count+$choice['votes'];//countig all votes
-			
-			}
-		}
+  if (!empty($choices)) {
+    foreach ($choices as $delta => $choice) {
+      if (!empty($choice['choice'])) {
+        $show_form = TRUE;
+        $choices_array[] = check_plain($choice['choice']);
+        $count = db_result(db_query("SELECT count(*) FROM {pollfield_votes} WHERE nid = %d AND delta=%d
+            AND field_table='%s' AND field_name='%s'", $node->nid, $delta, $type, $field));
+        $votes[]=$count+$choice['votes'];
+        $sum = $sum+$count+$choice['votes']; // counting all votes
+      }
+    }
   }
-	
-  //geting results
+
+  // geting results
 
   if ($show_form) {
-		$out = '<div class="pollfield-questions">';
-		    
-		if ($element['#item']['question']!="' '"){
-		  $out .= '<div class="pollfield-row">'.check_plain($element['#item']['question']).'</div>';
-		}
-		$out .= '</div>';
-	
-		return $out;
-  } 
-  
+    $out = '<div class="pollfield-questions">';
+
+    if ($element['#item']['question']!="' '") {
+      $out .= '<div class="pollfield-row">'. check_plain($element['#item']['question']) .'</div>';
+    }
+    $out .= '</div>';
+
+    return $out;
+  }
+
 }
 
 function theme_pollfield_formatter_runtime($element) {
-    // todo and other formattings
-  
+    // @todo and other formattings
+
   global $user;
   $items      = $element['#item'];
   $node       = $element['#node'];
   $type = $element['#type_name'];
   $field = $element['#field_name'];
-  //adding up the results
-  $show_form = false;
-  if (is_array($items['poll_features'])){
-		$choices = $items['group'];
-		$poll_features = $items['poll_features'];
-	}
-	else{
-		$choices = unserialize($items['choice']);
-		$poll_features = unserialize($items['poll_features']);
-	}
-
-	$votes=array();$choices_array=array();
-  if (!empty($choices)){
-		foreach ($choices as $delta => $choice) {
-			if (!empty($choice['choice'])){
-				$show_form = true;
-				$choices_array[] = check_plain($choice['choice']);
-				$count = db_result(db_query("SELECT count(*) FROM {pollfield_votes} WHERE nid = %d AND delta=%d 
-						AND field_table='%s' AND field_name='%s'",$node->nid, $delta,$type,$field));
-				$votes[]=$count+$choice['votes'];
-				$sum = $sum+$count+$choice['votes'];//countig all votes
-			
-			}
-		}
+  // adding up the results
+  $show_form = FALSE;
+  if (is_array($items['poll_features'])) {
+    $choices = $items['group'];
+    $poll_features = $items['poll_features'];
+  }
+  else{
+    $choices = unserialize($items['choice']);
+    $poll_features = unserialize($items['poll_features']);
   }
-   
-  //geting results
+
+  $votes=array();$choices_array=array();
+  if (!empty($choices)) {
+    foreach ($choices as $delta => $choice) {
+      if (!empty($choice['choice'])) {
+        $show_form = TRUE;
+        $choices_array[] = check_plain($choice['choice']);
+        $count = db_result(db_query("SELECT count(*) FROM {pollfield_votes} WHERE nid = %d AND delta=%d
+            AND field_table='%s' AND field_name='%s'", $node->nid, $delta, $type, $field));
+        $votes[]=$count+$choice['votes'];
+        $sum = $sum+$count+$choice['votes']; // countig all votes
+
+      }
+    }
+  }
+
+  // geting results
 
   if ($show_form) {
-  	if ($element['#item']['runtime']>0){
-			$runtime = t('!duration duration of poll in seconds',array('!duration'=>$element['#item']['runtime']));
-		}
-		else{
-			$runtime = t('Unlimited poll duration.');
-		}
-		$out = '<div class="pollfield-runtime">'.check_plain($runtime).'</div>';
-		return $out;
-  } 
-  
+    if ($element['#item']['runtime']>0) {
+      $runtime = t('!duration duration of poll in seconds', array('!duration' => $element['#item']['runtime']));
+    }
+    else{
+      $runtime = t('Unlimited poll duration.');
+    }
+    $out = '<div class="pollfield-runtime">'. check_plain($runtime) .'</div>';
+    return $out;
+  }
+
 }
 
 
-//only user choice
-function theme_user_vote($node,$comment) {
-  // todo and other formattings
+// only user choice
+function theme_user_vote($node, $comment) {
+  // @todo and other formattings
   global $user;
-	$poll_output = "<div id='pollfield' class='pollfield_results'>";
-	foreach ($node as $key => $value) {
-		//get field name
-		if (strncmp($key,'field_',6)==0)
-		{
-			//get table name
-			$fields = content_fields();
-			$db_info = content_database_info($fields[$key]);
-			$table_content = $db_info['table'];
-			$column_choice = $key."_choice";
-			$column_question = $key."_question";
-			$column = 'delta';
-			$is_delta_exist = db_column_exists($table_content, $column);
-			$poll_result = db_query("SELECT * FROM {%s} WHERE nid = %d",$table_content,$node->nid);
-			
-			while ($pollfield = db_fetch_object($poll_result)) {
-	
-				if ($is_delta_exist){
-					$field_name_delta=$pollfield->delta;
-				}
-				else
-				{
-				   $field_name_delta=0;
-				}
-				$choices = unserialize($pollfield->$column_choice);
-				//is user vote
-				$is_vote = 0;
-				$is_vote = db_result(db_query("SELECT count(*) FROM {pollfield_votes} WHERE nid = %d AND field_name_delta=%d 
-							AND field_table='%s' AND field_name='%s' AND uid=%d",
-							$node->nid, $field_name_delta,$node->type,$key,$comment->uid));
-				
-				//get user vote
-				$user_choice = db_result(db_query("SELECT delta FROM {pollfield_votes} WHERE nid = %d AND field_name_delta=%d 
-							AND field_table='%s' AND field_name='%s' AND uid=%d",
-							$node->nid, $field_name_delta,$node->type,$key,$comment->uid));
-				
-				$user_choice_response=$choices[$user_choice]['choice'];
-				
-				if ($is_vote>0) {
-					if ($pollfield->$column_question=="' '"){	
-						$poll_output .= "<p>".$node->title.": ".check_plain($user_choice_response)."</p>";
-					}
-					else{
-						$poll_output .= "<p>".$pollfield->$column_question.": ".check_plain($user_choice_response)."</p>";
-					}
-					$out = $poll_output;
-			  	} 
-		  		
-				
-			}
-		}
-	}
-	$out.="</div>";
-	return $out;
+  $poll_output = "<div id='pollfield' class='pollfield_results'>";
+  foreach ($node as $key => $value) {
+    // get field name
+    if (strncmp($key, 'field_', 6)==0) {
+      // get table name
+      $fields = content_fields();
+      $db_info = content_database_info($fields[$key]);
+      $table_content = $db_info['table'];
+      $column_choice = $key ."_choice";
+      $column_question = $key ."_question";
+      $column = 'delta';
+      $is_delta_exist = db_column_exists($table_content, $column);
+      $poll_result = db_query("SELECT * FROM {%s} WHERE nid = %d", $table_content, $node->nid);
+
+      while ($pollfield = db_fetch_object($poll_result)) {
+
+        if ($is_delta_exist) {
+          $field_name_delta=$pollfield->delta;
+        }
+        else {
+          $field_name_delta=0;
+        }
+        $choices = unserialize($pollfield->$column_choice);
+        // is user vote
+        $is_vote = 0;
+        $is_vote = db_result(db_query("SELECT count(*) FROM {pollfield_votes} WHERE nid = %d AND field_name_delta=%d
+              AND field_table='%s' AND field_name='%s' AND uid=%d",
+              $node->nid, $field_name_delta, $node->type, $key, $comment->uid));
+
+        // get user vote
+        $user_choice = db_result(db_query("SELECT delta FROM {pollfield_votes} WHERE nid = %d AND field_name_delta=%d
+              AND field_table='%s' AND field_name='%s' AND uid=%d",
+              $node->nid, $field_name_delta, $node->type, $key, $comment->uid));
+
+        $user_choice_response=$choices[$user_choice]['choice'];
+
+        if ($is_vote>0) {
+          if ($pollfield->$column_question=="' '") {
+            $poll_output .= "<p>". $node->title .": ". check_plain($user_choice_response) ."</p>";
+          }
+          else{
+            $poll_output .= "<p>". $pollfield->$column_question .": ". check_plain($user_choice_response) ."</p>";
+          }
+          $out = $poll_output;
+        }
+      }
+    }
+  }
+  $out .= '</div>';
+  return $out;
 }
 
 function pollfield_voting_form(&$element) {
   global $user;
-	
-	$form = array();
-	$form_state = array();
-	$table = $element['#type_name'];
-	$field_name = $element['#field_name'];
-	$field_name_delta = $element['#item']['#delta'];
-	$items = $element['#item'];
-	$node = $element['#node'];
-	$hostname = $_SERVER['REMOTE_ADDR'];
-	if (is_array($element['#item']['poll_features'])){
-		$poll_features=$element['#item']['poll_features'];
-	}
-	else{
-		$poll_features = unserialize($element['#item']['poll_features']);
-	}
-
-	$nid=$node->nid;
-
-	//get table
-	$fields = content_fields();
-	$db_info = content_database_info($fields[$field_name]);
-	$table_content = $db_info['table'];
-	$column = 'delta';
-	$is_delta_exist = db_column_exists($table_content, $column);
-
-	if ($is_delta_exist)
-	{
-		//get anonymous voting politics
-		$field_anon = $field_name."_anonymous";
-		$anonymous = db_result(db_query("SELECT %s FROM {%s} WHERE nid=%d AND delta=%d",$field_anon,$table_content,$nid,$field_name_delta));
-		
-	}
-	else
-	{
-		//get anonymous voting politics
-		$field_anon = $field_name."_anonymous";
-		$anonymous = db_result(db_query("SELECT %s FROM {%s} WHERE nid=%d",$field_anon,$table_content,$nid));
-	}
-	
-  	//check if user has voted 
-	$field_table = $table;
-	$voted = pollfield_user_voted($node,$field_table,$field_name,$field_name_delta);
-	
-	
-	if ($voted)
-	{
-		 
-		 if ($user->uid){
-	
-			  if ($poll_features['CancelVote_Allow']){//allow cancel vote
-				  $cancel=1;
-				  $form['field_name_delta'] = array('#type' => 'hidden', '#value' => $field_name_delta);
-				  $form['field_name'] = array('#type' => 'hidden', '#value' => $field_name);
-				  $form['nid'] = array('#type' => 'hidden', '#value' => $node->nid);
-				  $form['vote'] = array('#type' => 'submit', '#value' => t('Cancel Vote'));
-				  $form['table'] = array('#type' => 'hidden', '#value' => $table);
-				  $form['cancel'] = array('#type' => 'hidden', '#value' => $cancel);
-				  $form['#type'] = 'form';
-				  $form['#action'] = url('pollfield/vote');
-			}
-		}
-		else{
-			
-			if ($anonymous=='anon_non')
-				return $output;
-			else
-			{
-    			
-				if ($poll_features['CancelVote_Allow']){//allow cancel vote
-				  $cancel = 1;
-				  $form['field_name_delta'] = array('#type' => 'hidden', '#value' => $field_name_delta);
-				  $form['field_name'] = array('#type' => 'hidden', '#value' => $field_name);
-				  $form['nid'] = array('#type' => 'hidden', '#value' => $node->nid);
-				  $form['vote'] = array('#type' => 'submit', '#value' => t('Cancel Vote'));
-				  $form['table'] = array('#type' => 'hidden', '#value' => $table);
-				  $form['cancel'] = array('#type' => 'hidden', '#value' => $cancel);
-				  $form['#type'] = 'form';
-				  $form['#action'] = url('pollfield/vote');
-				}
-			}
-		}
-	 }
-	else//if user not voted
-	{
-	  if ($user->uid==0){
-			if ($anonymous=='anon_non')
-				return $output;	
-	  }
-     
-	  if ($items) {
-			$list = array();
-			$choices = unserialize($items['choice']);
-			
-			if (!empty($choices)) {
-				  foreach ($choices as $delta => $choice) {
-				  	if (!empty($choice['choice'])){
-							$list[$delta] = check_plain($choice['choice']);
-						}
-				  }
-				  
-				  //choose form for specific type of poll
-				  if ($poll_features['PollType']=='0'){//single choice
-			  		$form['choice'] = array('#type' => 'radios', '#title' => $question, '#default_value' => -1, '#options' => $list);
-				  }
-				  if ($poll_features['PollType']=='1'){//multi choice
-						$form['choice'] = array('#type' => 'checkboxes', '#title' => $question, '#options' => $list);
-				  }
-
-			}
-		
-	  }
-	  
-	 
-	  $cancel = 0;
-	  $form['field_name_delta'] = array('#type' => 'hidden', '#value' => $field_name_delta);
-	  $form['field_name'] = array('#type' => 'hidden', '#value' => $field_name);
-	  $form['nid'] = array('#type' => 'hidden', '#value' => $node->nid);
-	  $form['vote'] = array('#type' => 'submit', '#value' => t('Vote'));
-	  $form['table'] = array('#type' => 'hidden', '#value' => $table);
-	  $form['cancel'] = array('#type' => 'hidden', '#value' => $cancel);
-	  $form['#action'] = url('pollfield/vote');
-	  $form['#type'] = 'form';
-
-
-	}
-  
-  //enable and disable vote form
- 
-	
+
+  $form = array();
+  $form_state = array();
+  $table = $element['#type_name'];
+  $field_name = $element['#field_name'];
+  $field_name_delta = $element['#item']['#delta'];
+  $items = $element['#item'];
+  $node = $element['#node'];
+  $hostname = $_SERVER['REMOTE_ADDR'];
+  if (is_array($element['#item']['poll_features'])) {
+    $poll_features=$element['#item']['poll_features'];
+  }
+  else{
+    $poll_features = unserialize($element['#item']['poll_features']);
+  }
+
+  $nid=$node->nid;
+
+  // get table
+  $fields = content_fields();
+  $db_info = content_database_info($fields[$field_name]);
+  $table_content = $db_info['table'];
+  $column = 'delta';
+  $is_delta_exist = db_column_exists($table_content, $column);
+
+  if ($is_delta_exist) {
+    // get anonymous voting politics
+    $field_anon = $field_name .'_anonymous';
+    $anonymous = db_result(db_query("SELECT %s FROM {%s} WHERE nid=%d AND delta=%d", $field_anon, $table_content, $nid, $field_name_delta));
+
+  }
+  else {
+    // get anonymous voting politics
+    $field_anon = $field_name .'_anonymous';
+    $anonymous = db_result(db_query("SELECT %s FROM {%s} WHERE nid=%d", $field_anon, $table_content, $nid));
+  }
+
+    // check if user has voted
+  $field_table = $table;
+  $voted = pollfield_user_voted($node, $field_table, $field_name, $field_name_delta);
+
+
+  if ($voted) {
+    if ($user->uid) {
+      if ($poll_features['CancelVote_Allow']) {// allow cancel vote
+        $cancel=1;
+        $form['field_name_delta'] = array('#type' => 'hidden', '#value' => $field_name_delta);
+        $form['field_name'] = array('#type' => 'hidden', '#value' => $field_name);
+        $form['nid'] = array('#type' => 'hidden', '#value' => $node->nid);
+        $form['vote'] = array('#type' => 'submit', '#value' => t('Cancel Vote'));
+        $form['table'] = array('#type' => 'hidden', '#value' => $table);
+        $form['cancel'] = array('#type' => 'hidden', '#value' => $cancel);
+        $form['#type'] = 'form';
+        $form['#action'] = url('pollfield/vote');
+      }
+    }
+    else{
+      if ($anonymous=='anon_non')
+        return $output;
+      else {
+        if ($poll_features['CancelVote_Allow']) {// allow cancel vote
+          $cancel = 1;
+          $form['field_name_delta'] = array('#type' => 'hidden', '#value' => $field_name_delta);
+          $form['field_name'] = array('#type' => 'hidden', '#value' => $field_name);
+          $form['nid'] = array('#type' => 'hidden', '#value' => $node->nid);
+          $form['vote'] = array('#type' => 'submit', '#value' => t('Cancel Vote'));
+          $form['table'] = array('#type' => 'hidden', '#value' => $table);
+          $form['cancel'] = array('#type' => 'hidden', '#value' => $cancel);
+          $form['#type'] = 'form';
+          $form['#action'] = url('pollfield/vote');
+        }
+      }
+    }
+  }
+  // if user not voted
+  else {
+    if ($user->uid==0) {
+      if ($anonymous=='anon_non')
+        return $output;
+    }
+
+    if ($items) {
+      $list = array();
+      $choices = unserialize($items['choice']);
+
+      if (!empty($choices)) {
+          foreach ($choices as $delta => $choice) {
+            if (!empty($choice['choice'])) {
+              $list[$delta] = check_plain($choice['choice']);
+            }
+          }
+
+          // choose form for specific type of poll
+          if ($poll_features['PollType']=='0') {// single choice
+            $form['choice'] = array('#type' => 'radios', '#title' => $question, '#default_value' => -1, '#options' => $list);
+          }
+          if ($poll_features['PollType']=='1') {// multi choice
+            $form['choice'] = array('#type' => 'checkboxes', '#title' => $question, '#options' => $list);
+          }
+
+      }
+
+    }
+
+
+    $cancel = 0;
+    $form['field_name_delta'] = array('#type' => 'hidden', '#value' => $field_name_delta);
+    $form['field_name'] = array('#type' => 'hidden', '#value' => $field_name);
+    $form['nid'] = array('#type' => 'hidden', '#value' => $node->nid);
+    $form['vote'] = array('#type' => 'submit', '#value' => t('Vote'));
+    $form['table'] = array('#type' => 'hidden', '#value' => $table);
+    $form['cancel'] = array('#type' => 'hidden', '#value' => $cancel);
+    $form['#action'] = url('pollfield/vote');
+    $form['#type'] = 'form';
+
+
+  }
+
+  // enable and disable vote form
+
+
   $result = db_query("SELECT active FROM {pollfield} WHERE field_table='%s' AND field_name='%s' AND nid=%d AND field_name_delta=%d",
-			$table,$field_name,$node->nid,$field_name_delta);
+      $table, $field_name, $node->nid, $field_name_delta);
   while ($pollfield = db_fetch_object($result)) {
-		$is_active=$pollfield->active;
+    $is_active=$pollfield->active;
   }
-  if ($is_active==1){				   
-		$form = form_builder('voting', $form, $form_state);
-		$output = drupal_render($form);
+  if ($is_active==1) {
+    $form = form_builder('voting', $form, $form_state);
+    $output = drupal_render($form);
   }
-  
+
 
   return $output;
 }
@@ -704,11 +685,12 @@ function pollfield_field_settings($op, $
 }
 /**
  * Implementation of hook_cron().
+ *
  * Closes pollfields that have exceeded their allowed runtime.
  */
 function pollfield_cron() {
   $time = time();
-  $result = db_query('SELECT p.nid, p.field_name,p.field_table,p.field_name_delta FROM {pollfield} p INNER JOIN {node} n ON p.nid = n.nid WHERE (n.created + p.runtime) < '. $time .' AND p.active = 1 AND p.runtime <> 0');
+  $result = db_query('SELECT p.nid, p.field_name, p.field_table, p.field_name_delta FROM {pollfield} p INNER JOIN {node} n ON p.nid = n.nid WHERE (n.created + p.runtime) < '. $time .' AND p.active = 1 AND p.runtime <> 0');
   while ($pollfield = db_fetch_object($result)) {
     db_query("UPDATE {pollfield} SET active = 0 WHERE nid = %d AND field_table = '%s' AND field_name = '%s' AND field_name_delta=%d",
       $pollfield->nid, $pollfield->field_table, $pollfield->field_name, $pollfield->field_name_delta);
@@ -759,7 +741,7 @@ function pollfield_field($op, &$node, $f
       $choices = array();
       db_query("DELETE  from {pollfield} WHERE nid=%d AND field_name='%s' AND field_table='%s' AND field_name_delta=%d",
         $node->nid, $field_name, $field_table, $key);
-      db_query("INSERT INTO {pollfield} (nid,field_table,field_name,runtime,active,field_name_delta) VALUES (%d,'%s','%s',%d,%d,%d)",
+      db_query("INSERT INTO {pollfield} (nid, field_table, field_name, runtime, active, field_name_delta) VALUES (%d, '%s', '%s', %d, %d, %d)",
         $node->nid, $field_table, $field_name, $item['runtime'], $item['active'], $key);
       // handling publishing option
       // it is publising
@@ -805,7 +787,7 @@ function pollfield_field($op, &$node, $f
       $choices = array();
       db_query("DELETE  from {pollfield} WHERE nid=%d AND field_name='%s' AND field_table='%s' AND field_name_delta=%d",
         $node->nid, $field_name, $field_table, $key);
-      db_query("INSERT INTO {pollfield} (nid,field_table,field_name,runtime,active,field_name_delta) VALUES (%d,'%s','%s',%d,%d,%d)",
+      db_query("INSERT INTO {pollfield} (nid, field_table, field_name, runtime, active, field_name_delta) VALUES (%d, '%s', '%s', %d, %d, %d)",
         $node->nid, $field_table, $field_name, $item['runtime'], $item['active'], $key);
       if (!empty($item['group'])) {
         foreach ($item['group'] as $delta => $group) {
@@ -899,7 +881,6 @@ function pollfield_elements() {
  * note that $element['#value'] is already set.
  *
  * The $fields array is in $form['#field_info'][$element['#field_name']].
- *
  */
 function pollfield_pollfield_process($element, $edit, $form_state, $form) {
   $field1 = $form['#field_info'][$element['#field_name']];
@@ -1047,7 +1028,6 @@ function pollfield_pollfield_process($el
 
 /**
  * Implementation of hook_widget().
- *
  */
 function pollfield_widget(&$form, &$form_state, $field, $items, $delta = 0) {
   $element = array(
@@ -1156,8 +1136,8 @@ function pollfield_save_multiple_choice(
     foreach ($form_values['choice'] as $value) {
       $choice = $value;
       if ($user->uid>0) {
-        db_query("INSERT INTO {pollfield_votes} (nid, field_table, field_name,uid,delta,field_name_delta)
-        VALUES (%d, '%s', '%s' , %d, %d,%d)", $nid, $field_table, $field_name, $uid, $choice, $field_name_delta);
+        db_query("INSERT INTO {pollfield_votes} (nid, field_table, field_name, uid, delta, field_name_delta)
+        VALUES (%d, '%s', '%s' , %d, %d, %d)", $nid, $field_table, $field_name, $uid, $choice, $field_name_delta);
         // increment total votes
         if ($existing_field == 1) {
           $total_votes++;
@@ -1170,8 +1150,8 @@ function pollfield_save_multiple_choice(
         }
       }
       else {
-        db_query("INSERT INTO {pollfield_votes} (nid, field_table, field_name, delta, hostname,field_name_delta,cookie)
-          VALUES (%d,'%s','%s',%d,'%s',%d,'%s')",
+        db_query("INSERT INTO {pollfield_votes} (nid, field_table, field_name, delta, hostname, field_name_delta, cookie)
+          VALUES (%d, '%s', '%s', %d, '%s', %d, '%s')",
           $nid, $field_table, $field_name, $choice, $hostname, $field_name_delta, $cookie_db);
       }
     }
@@ -1229,8 +1209,8 @@ function pollfield_save_single_choice($f
   if ($voted == 0) {
     $uid = $user->uid;
     if ($user->uid>0) {
-      db_query("INSERT INTO {pollfield_votes} (nid, field_table, field_name,uid,delta,field_name_delta)
-        VALUES (%d, '%s', '%s' , %d, %d,%d)", $nid, $field_table, $field_name, $uid, $choice, $field_name_delta);
+      db_query("INSERT INTO {pollfield_votes} (nid, field_table, field_name, uid, delta, field_name_delta)
+        VALUES (%d, '%s', '%s' , %d, %d, %d)", $nid, $field_table, $field_name, $uid, $choice, $field_name_delta);
       // increment total votes
       if ($existing_field == 1) {
         $total_votes++;
@@ -1243,8 +1223,8 @@ function pollfield_save_single_choice($f
       }
     }
     else {
-      db_query("INSERT INTO {pollfield_votes} (nid, field_table, field_name, delta, hostname,field_name_delta,cookie)
-        VALUES (%d,'%s','%s',%d,'%s',%d,'%s')",
+      db_query("INSERT INTO {pollfield_votes} (nid, field_table, field_name, delta, hostname, field_name_delta, cookie)
+        VALUES (%d, '%s', '%s', %d, '%s', %d, '%s')",
         $nid, $field_table, $field_name, $choice, $hostname, $field_name_delta, $cookie_db);
     }
 
