Index: decisions.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/decisions/decisions.module,v
retrieving revision 1.105
diff -u -r1.105 decisions.module
--- decisions.module	19 Oct 2006 08:18:33 -0000	1.105
+++ decisions.module	19 Oct 2006 12:14:32 -0000
@@ -121,13 +121,8 @@
  * This hook displays the form necessary to edit the *node* (ie. not the votes).
  */
 function decisions_form($node) {
-	$node->in_preview = isset($_POST['edit']);
-
 	$mode = _decisions_get_mode($node);
 
-	$enabled = array(0 => t('Disabled'), 1 => t('Enabled'));
-
-  /* standard node elements */
   $form['title'] = array(
     '#type' => 'textfield',
     '#title' => ucfirst($mode) . ' ' . t('Question'),
@@ -142,106 +137,46 @@
     '#default_value' => $node->body,
   );
 
-	if ($node->in_preview) {
-		// Figure out the number of non-blank choices
-		$node->choice = array();
-		$node->choices = 0;
-  	foreach ($_POST['edit']['ChoiceGroup'] as $key => $choice) {
-  		$order = str_replace('Choice_', '', $key);
-			if ($order != $key && $choice != '') {
-				$node->choices++;
-				$node->choice[$order] = $choice;
-			}
-			else {
-				
-			}
-		}
-
-		// If all of them are blank, default to 5 again
-		if ($node->choices == 0) {
-			$node->choices = 5;
-		}
-	}
-
-  if (!isset($node->choices)) {
-		// in the process of creating a new decision
-
-		if ($node->in_preview) {
-			// previewing a decision that hasn't been created yet
-
-			if ($_POST['edit']['ChoiceGroup']['morechoices']) {
-				// morechoices checked
-
-				// double number of previously shown choices (including blanks)
-				$node->choices = 2 * $_POST['edit']['ChoiceGroup']['choices'];
-			}
-			else {
-				// morechoices not checked
-
-				// Only show non-blank previous choices
-
-				// $node->choices should already be set to the correct number
-				// so don't do anything.
-			}
-		}
-		else {
-			// this is a new decision, so default to 5 choices	
-    	$node->choices = 5;
-		}
-	}
-	else {
-		// Editing an old decision
-
-		if ($node->in_preview) {
-			// previewing a previously edited node
-
-			if ($_POST['edit']['ChoiceGroup']['morechoices']) {
-				// Double number of previously shown choices, including blanks
-				$node->choices = 2 * $_POST['edit']['ChoiceGroup']['choices'];
-			}
-			else {
-				// morechoices not checked
-
-				// Only show non-blank previous choices
-
-				// $node->choices should already be set to the correct number
-				// so don't do anything.
-			}
-		}
+ $form['choice']['choices'] = array(
+    '#type' => 'hidden',
+    '#default_value' => max(2, count($node->choice) ? count($node->choice) : 5)
+  );
+  
+  $form['choice']['morechoices'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Need more choices'),
+    '#default_value' => 0,
+    '#description' => t("If the amount of boxes above isn't enough, check this box and click the Preview button below to add some more."),
+    '#weight' => 1
+  );
+  
+  $form['choice'] = form_builder($node->type . '_node_form', $form['choice']);
+  
+  if ($form['choice']['morechoices']['#value']) {
+    $form['choice']['morechoices']['#value'] = 0;
+    $form['choice']['choices']['#value'] *= 2;
   }
 
-	// Choices list
-  $form['ChoiceGroup'] = array(
+  // If the value was changed in a previous iteration, retain it.
+  $node->choices = $form['choice']['choices']['#value'];
+
+  // Desicions choices
+  $form['choice'] += array(
     '#type' => 'fieldset',
-    '#tree' => TRUE,
-    '#title' => t('Decision Choices'),
-    '#collapsible' => TRUE,
-		'#weight' => 1,
+    '#title' => t('Choices'),
+    '#prefix' => '<div class="poll-form">',
+    '#suffix' => '</div>', '#tree' => TRUE,
+    '#weight' => 1,
   );
-
-  for ($cnum = 1; $cnum <= $node->choices; $cnum++) {
-    $form['ChoiceGroup']['Choice_' . $cnum] = array(
+    
+  for ($a = 0; $a < $node->choices; $a++) {
+    $form['choice'][$a]['chtext'] = array(
       '#type' => 'textfield',
-      '#title' => t('Choice %n', array('%n' => $cnum)),
-      '#required' => FALSE,
-      '#default_value' => $node->choice[$cnum],
-      '#size' => 50,
-      '#maxlength' => 127,
+      '#title' => t('Choice %n', array('%n' => ($a + 1))),
+      '#default_value' => $node->choice[$a]['chtext']
     );
   }
 
-  $form['ChoiceGroup']['choices'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->choices,
-  );
-
-  $form['ChoiceGroup']['morechoices'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Need more choices'),
-    '#value' => 0,
-    '#description' => t("If the amount of boxes above isn't enough, check this box and click the Preview button below to add some more."),
-  );
-
 	$form['settings'] = array(
     '#type' => 'fieldset',
     '#tree' => TRUE,
@@ -367,7 +302,7 @@
   $decision = db_fetch_object(db_query("SELECT * FROM {decisions} WHERE nid = %d", $node->nid));
   $result = db_query("SELECT chorder, chtext FROM {decisions_choices} WHERE nid = %d ORDER BY chorder", $node->nid);
   while ($choice = db_fetch_array($result)) {
-  	$decision->choice[$choice['chorder']] = $choice['chtext'];
+  	$decision->choice[$choice['chorder']] = $choice;
   }
   $decision->choices = count($decision->choice);
 
@@ -525,11 +460,11 @@
 			$rows[$key]['name'] = $vote->name ? theme('username', $vote) : check_plain($vote->hostname);
 			if ($node->type == 'decisions-ranking') {
 				// Need two dimensional results (if equal rankings are allowed)
-      	$rows[$key]['votes'][$vote->value][] = check_plain($node->choice[$vote->tag]);
+      	$rows[$key]['votes'][$vote->value][] = check_plain($node->choice[$vote->tag]['chtext']);
 			}
 			else {
 				// Just need one dimensional results
-      	$rows[$key]['votes'][] = check_plain($node->choice[$vote->tag]);
+      	$rows[$key]['votes'][] = check_plain($node->choice[$vote->tag]['chtext']);
 			}
     }
 		
@@ -646,12 +581,10 @@
   # XXX: ... but before doing so, the code below must be factored out in a seperate function for usage in decisions_insert()
   db_query('DELETE FROM {decisions_choices} WHERE nid = %d', $node->nid);
 
-  foreach ($node->ChoiceGroup as $key => $choice) {
-  	$order = str_replace('Choice_', '', $key);
-		if ($order != $key && $choice != '') {
-			db_query("INSERT INTO {decisions_choices} (nid, chtext, chorder) VALUES (%d, '%s', %d)", $node->nid, $choice, intval($order));
-	  }
-	# ignore entries other than choices
+  foreach ($node->choice as $choice) {
+  	 if ($choice['chtext'] != '') {
+      db_query("INSERT INTO {decisions_choices} (nid, chtext, chorder) VALUES (%d, '%s', %d)", $node->nid, $choice['chtext'], $i++);
+    }
   }
 }
 
Index: modes/poll.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/decisions/modes/poll.inc,v
retrieving revision 1.6
diff -u -r1.6 poll.inc
--- modes/poll.inc	17 Oct 2006 22:17:55 -0000	1.6
+++ modes/poll.inc	19 Oct 2006 12:15:22 -0000
@@ -19,7 +19,7 @@
 		if ($node->maxchoices == 1) {
 			// plurality voting
     	foreach ($node->choice as $i => $choice) {
-      	$list[$i] = check_plain($choice);
+      	$list[$i] = check_plain($choice['chtext']);
     	}
 
     	$form['choice'] = array(
@@ -32,7 +32,7 @@
 		else {
 			// approval voting
 			foreach ($node->choice as $i => $choice) {
-      	$list[$i] = check_plain($choice);
+      	$list[$i] = check_plain($choice['chtext']);
     	}
 			
     	$form['choice'] = array(
@@ -98,7 +98,7 @@
 				$votes[$i] = 0;
 			}
 			$percentage = round(100 * $votes[$i] / $totalVotes, 0);
-			$output .= theme('decisions_bar',  check_plain($ch), $percentage, format_plural($votes[$i], '1 vote', '%count votes'), $block);
+			$output .= theme('decisions_bar',  check_plain($ch['chtext']), $percentage, format_plural($votes[$i], '1 vote', '%count votes'), $block);
 		}
 		$output .= '</div>';
 	}
Index: modes/ranking.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/decisions/modes/ranking.inc,v
retrieving revision 1.10
diff -u -r1.10 ranking.inc
--- modes/ranking.inc	18 Oct 2006 22:49:19 -0000	1.10
+++ modes/ranking.inc	19 Oct 2006 12:15:32 -0000
@@ -51,7 +51,7 @@
     foreach ($node->choice as $key => $choice) {
       $form['choice'][$key] = array(
         '#type' => 'select',
-        '#title' => check_plain($choice),
+        '#title' => check_plain($choice['chtext']),
 				'#options' => $choices,
       );
     }
@@ -95,7 +95,7 @@
 
 			// Loop through all choices with this ranking
 			foreach ($results->ranking[$i]['choices'] as $choice) {
-				$output .= ($firstOne? '' : ', ') . $node->choice[$choice];
+				$output .= ($firstOne? '' : ', ') . check_plain($node->choice[$choice]['chtext']);
 				$firstOne = false;
 			}
 
@@ -112,8 +112,8 @@
     	$output .= '<br />Internal values, for debugging purposes:';
     	// output the table of algorithm rounds
     	$output .= '<table border="1"><tr><td>Round</td>';
-    	foreach ($node->choice as $key => $choicename) {
-      	$output .= "<td>$choicename</td>";
+    	foreach ($node->choice as $choice) {
+      	$output .= '<td>' . check_plain($choice['chtext']) . '</td>';
     	}
     	$output .= '</tr>';
     	$round = 1;
