? settings_tab.patch
Index: headerimage.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/headerimage/headerimage.module,v
retrieving revision 1.16
diff -u -p -r1.16 headerimage.module
--- headerimage.module	4 May 2008 11:10:40 -0000	1.16
+++ headerimage.module	8 May 2008 16:11:32 -0000
@@ -127,6 +127,7 @@ function headerimage_block($op = 'list',
     case 'configure':
       return headerimage_block_configure($delta);
     case 'save':
+      variable_set('headerimage_block_'. $delta .'_random_fallback', $edit['random_fallback']);
       break;
     case 'view':
       if (user_access('view header image')) {
@@ -164,7 +165,9 @@ function headerimage_block($op = 'list',
  * Select a node to be displayed in the block
  *
  * Node selection by (1)weight and (2)condition.
- *     If multiple conditions are present, any true condition will select the node
+ * If multiple conditions are present, any true condition will select the node.
+ * If no node is selected by the conditions and random fallback selection is
+ * enabled for the block, one of the available nodes will be selected at random.
  *
  * @param $block
  *   The headerimage block number ($delta)
@@ -178,6 +181,8 @@ function headerimage_select_node($block)
   while ($header_image = db_fetch_object($result)) {
     $conditions = unserialize($header_image->conditions);
     $match = false;
+    // Store the nid in an array for the random selection fallback option.
+    $block_nids[] = $header_image->nid; 
     $selected_types = variable_get(headerimage_condition_types, array('nid' => 'nid'));
     foreach ($conditions as $type => $condition) {
       if (!empty($condition) && !empty($selected_types[$type])) {
@@ -206,7 +211,11 @@ function headerimage_select_node($block)
     }
     if ($match) break;
   }
-  return $match ? $header_image->nid : null;
+  if ($match) {
+    return $header_image->nid;
+  } elseif (variable_get('headerimage_block_'. $block .'_random_fallback', 0) && count($block_nids)) {
+    return $block_nids[array_rand($block_nids)];
+  }
 }
 
 /**
@@ -523,6 +532,12 @@ function headerimage_block_configure($de
     '#value' => $output,
     '#suffix' => '</div>',
   );
+  $form['headerimage']['random_fallback'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Enable a random fallback selection'),
+    '#default_value' => variable_get('headerimage_block_'. $delta .'_random_fallback', 0),
+    '#description' => t('If no node is selected by the conditions, select a random node from those assigned to this block.'),
+  );
   return $form;
 }
 
