? decisions_arrayfilter_crash.patch
? decisions_morechoices.module
? decisions_morechoices2.module
? decisions_morechoices3.module
? ranking_plainttext.patch
Index: decisions.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/decisions/decisions.module,v
retrieving revision 1.94
diff -u -r1.94 decisions.module
--- decisions.module	15 Oct 2006 20:55:41 -0000	1.94
+++ decisions.module	15 Oct 2006 22:28:40 -0000
@@ -108,13 +108,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'),
@@ -129,104 +124,34 @@
     '#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.
-			}
-		}
-  }
-
-	// Choices list
-  $form['ChoiceGroup'] = array(
-    '#type' => 'fieldset',
-    '#tree' => TRUE,
-    '#title' => t('Decision Choices'),
-    '#collapsible' => TRUE,
-  );
-
-  for ($cnum = 1; $cnum <= $node->choices; $cnum++) {
-    $form['ChoiceGroup']['Choice_' . $cnum] = array(
-      '#type' => 'textfield',
-      '#title' => t('Choice %n', array('%n' => $cnum)),
-      '#required' => FALSE,
-      '#default_value' => $node->choice[$cnum],
-      '#size' => 50,
-      '#maxlength' => 127,
-    );
-  }
-
-  $form['ChoiceGroup']['choices'] = array(
+  $form['choice']['choices'] = array(
     '#type' => 'hidden',
-    '#value' => $node->choices,
+    '#default_value' => max(2, count($node->choice) ? count($node->choice) : 5)
   );
-
-  $form['ChoiceGroup']['morechoices'] = array(
+  
+  $form['choice']['morechoices'] = array(
     '#type' => 'checkbox',
     '#title' => t('Need more choices'),
-    '#value' => 0,
+    '#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;
+  }
+
+  // If the value was changed in a previous iteration, retain it.
+  $node->choices = $form['choice']['choices']['#value'];
+
+  // Desicions choices
+  $form['choice'] += array('#type' => 'fieldset', '#title' => t('Choices'), '#prefix' => '<div class="poll-form">', '#suffix' => '</div>', '#tree' => TRUE);
+  for ($a = 0; $a < $node->choices; $a++) {
+    $form['choice'][$a]['chtext'] = array('#type' => 'textfield', '#title' => t('Choice %n', array('%n' => ($a + 1))), '#default_value' => $node->choice[$a]['chtext']);
+  }
 
 	$form['settings'] = array(
     '#type' => 'fieldset',
@@ -240,7 +165,6 @@
 		$maxChoiceList[$i] = ($i == 0? 'No limit' : $i);
 	}
 
-
   $form['settings']['maxchoices'] = array(
 		'#type' => 'select',
 		'#title' => t('Maximum Choices'),
@@ -253,8 +177,8 @@
 	if ($mode == 'ranking') {
 		$algs = array('instant runoff', 'borda count');
 	}
-	else {
-		// mode == poll
+	else { 
+    // mode == poll
 		$algs = array('plurality');
 	}
 
@@ -265,7 +189,6 @@
 	$defaultalg = ($_POST['edit']['settings']['algorithm']?
 		$_POST['edit']['settings']['algorithm'] : 
 			$node->algorithm);
-			
 
 	$form['settings']['algorithm'] = array(
 		'#type' => 'select',
@@ -275,19 +198,6 @@
 		'#description' => 'Voting algorithm to use to calculate the winner.',
 	);
 
-/*
-	$form['settings']['maxchoices'] = array(
-		'#type' => 'textfield',
-		'#required' => TRUE,
-		'#title' => t('Maximum Choices'),
-		'#size' => 5,
-		'#maxlength' => 10,
-		'#description' => t('The number of choices voters may select. Set to 0 for no limit.'),
-   	'#default_value' => (isset($node->settings['maxchoices'])?
-			$node->settings['maxchoices'] : 0),
-	);
-	*/
-
 	$active = array(1 => t('Active'), 0 => t('Closed'));
 	$form['settings']['active'] = array(
 		'#type' => 'radios',
@@ -307,23 +217,8 @@
 		'#description' => t('After this period, the decision will be closed automatically.')
 	);
 
-
 	// only show for new decisions (not when editing)
 	if (!(isset($node) && $node->nid)) {
-
-  	// to pick a reasonable default, configurable
-		/*
-  	$modes = _decisions_mode_list();
-
-	  $form['settings']['mode'] = array(
-			'#type' => 'select',
-			'#title' => t('Decision mode'),
-			'#required' => TRUE,
-			'#choices' => _decisions_mode_list(),
-			'#default_value' => variable_get('decisions_default_mode', $modes[0]),
-  	);
-		// */
-
 		$form['settings']['uselist'] = array(
 			'#type' => 'checkbox',
 			'#title' => t('Set the eligible voters upon creation'),
@@ -332,7 +227,6 @@
 		);
 	}
   
-	$form['format'] = filter_form($node->form);
 	return $form;
 }
 
@@ -361,7 +255,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);
 
@@ -523,12 +417,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++);
+    }
   }
 }
 
@@ -614,7 +506,7 @@
   }
 
 	// Previewing a node, so don't show results
-	if ($node->in_preview) {
+/*	if ($node->in_preview) { TODO: Chris, could you take a look at this? This is what's causes Opera to behave stangely. Not updated to the last changes though.
 		// Copy the form values to the choices array
 		$node->choice = array();
 		$node->choices = 0;
@@ -624,11 +516,11 @@
 				$node->choices++;
 				$node->choice[$order] = $choice;
 			}
-		}
+		} 
 
 		// Show the voting form but don't let them vote
     $output .= decisions_view_voting($node, $teaser, $page, $block);
-	}
+	} */
   else if (!$node->voted && arg(2) != 'results' && $node->active) {
 		// User hasn't voted and we're not on the results tab
 		if (!$valid && decisions_eligible($node)) {
Index: modes/poll.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/decisions/modes/poll.inc,v
retrieving revision 1.5
diff -u -r1.5 poll.inc
--- modes/poll.inc	14 Oct 2006 07:14:18 -0000	1.5
+++ modes/poll.inc	15 Oct 2006 22:19:24 -0000
@@ -20,7 +20,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(
@@ -34,11 +34,9 @@
 			// approval voting
 			$form['choice'] = array();
 			foreach ($node->choice as $key => $choice) {
-				$list[$i] = check_plain($choice);
-
       	$form['choice']['Choice_' . $key] = array(
         	'#type' => 'checkbox',
-        	'#title' => check_plain($choice),
+        	'#title' => check_plain($choice['chtext']),
         	'#required' => FALSE,
         	'#weight' => $weight++,
       	);
@@ -101,7 +99,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.6
diff -u -r1.6 ranking.inc
--- modes/ranking.inc	15 Oct 2006 20:55:42 -0000	1.6
+++ modes/ranking.inc	15 Oct 2006 22:17:50 -0000
@@ -45,11 +45,9 @@
 
 		$form['choice'] = array();
     foreach ($node->choice as $key => $choice) {
-      $list[$i] = check_plain($choice);
-
       $form['choice']['Choice_' . $key] = array(
         '#type' => 'select',
-        '#title' => check_plain($choice),
+        '#title' => check_plain($choice['chtext']),
         '#required' => FALSE,
         /* XXX: that's not the right way, we need to fetch the vote using votingapi */
 /*        '#default_value' => $node->choice[$key],*/
@@ -105,7 +103,7 @@
 
 			// Loop through all choices with this ranking
 			foreach ($results->ranking[$i] as $choice) {
-				$output .= ($firstOne? '' : ', ') . $node->choice[$choice];
+				$output .= ($firstOne? '' : ', ') . $node->choice[$choice]['chtext'];
 				$firstOne = false;
 			}
 
@@ -122,8 +120,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;
