Hi Guys

I wrote some code to easily select the default front page of a Drupal 5 website, given a Menu ID to list all the items from. One or two functions present in this code are defined in my earlier post, about a different proposal, at http://drupal.org/node/247166 .

Is anybody interested in formalizing this?

<?php

function tchmd_home_page_selector_menu($may_cache)
{
$items = array();

if ($may_cache)
{
$items[] = array(
		'path' => 'admin/homepageselector',
		'title' => t('Home Page Selector'),
		'callback' => 'drupal_get_form',
		'callback arguments' => 'tchmd_home_page_selector',
		);
}

return $items;
}

function tchmd_home_page_selector()
{
$form['home_page_options'] = array(
	'#type' => 'radios',
	'#title' => 'Select a page as your Home Page',
	'#options' => tchmd_menu_sorter_read_menu_db_table(),
	);

$d = tchmd_home_page_selector_discover_home_page();
	if($d != NULL)
	{
	$form['home_page_options']['#default_value'] = $d;
	}

$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));

return $form;
}

function tchmd_home_page_selector_submit($form_id, $form_values)
{
tchmd_home_page_selector_commit_to_db($form_values);

drupal_set_message('Your changes have been saved.');
}

function tchmd_home_page_selector_commit_to_db($form_values)
{
// what was submitted?
$a = $form_values['home_page_options'];
// what does it point to?
$sql = 'SELECT path FROM menu WHERE mid='.$a;
$result = db_query($sql);
$data = db_fetch_object($result); // we have $data->path now
// lets write the change to drupal's registry
variable_set('site_frontpage', $data->path);
}

function tchmd_home_page_selector_discover_home_page()
{
$b = variable_get('site_frontpage', 'node');
// who points to this path
$sql = 'SELECT mid FROM menu WHERE path=\''.$b.'\'';
$result = db_query($sql);

	if(db_num_rows($result) > 0)
	{
	$data = db_fetch_object($result);

	$c = tchmd_menu_sorter_read_menu_db_table();

		if(isset($c[$data->mid]))
		{
		return $data->mid;
		}
	}
return NULL;
}