Specifications

This SELECT option is generated in the do_html_header() function from output_fns.php,as
shown in the following code fragment:
<?
// include the account select box only if the user has more than one account
if(number_of_accounts($auth_user)>1)
{
echo “<form target=’index.php?action=open-mailbox’ method=post>”;
echo ‘<td bgcolor = “#ff6600” align = right valign = middle>’;
display_account_select($auth_user, $selected_account);
echo ‘</td>’;
echo “</form>”;
}
?>
We have generally avoided discussing the HTML used in the examples in this book, but the
HTML generated by the function display_account_select() bears a visit.
Depending on the accounts the current user has, display_account_select() will generate
HTML like this:
<select onchange=window.location=this.options[selectedIndex].value name=account>
<option value = 0 selected>
Choose Account</a>
<option value = ‘index.php?action=select-account&account=10’>
mail.domain.com
</option>
<option value = ‘index.php?action=select-account&account=11’>
mail.server.com
</option>
<option value = ‘index.php?action=select-account&account=9’>
localhost
</option>
</select>
Most of this code is just an HTML select element, but it also includes a little JavaScript. In the
same way that PHP can generate HTML, it can also be used to generate client-side scripts.
Whenever a change event happens to this element, JavaScript will set window.location to the
value of the option. If your user selects the first option in the select, window.location will be
set to ‘index.php?action=select-account&account=10’. This will result in this URL being
loaded. Obviously, if the user has a browser that does not support JavaScript or has JavaScript
disabled, this code will have no effect.
The display_account_select() function, from output_fns.php, is used to get the available
account list and display the SELECT. It also uses the get_account_list() function we dis-
cussed previously.
Building a Web-Based Email Service
C
HAPTER 27
27
BUILDING A
WEB-BASED
EMAIL
SERVICE
639
33 7842 CH27 3/6/01 3:41 PM Page 639