13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Setting Up Accounts<br />

667<br />

Look back at the script in Listing 29.2.This time around because of the value of<br />

$action, you get different behavior.You get a slightly different header, as follows:<br />

do_html_header($_SESSION['auth_user'], "Warm Mail - ".<br />

format_action($action),<br />

$_SESSION['selected_account']);<br />

More importantly, you get a different body, as follows:<br />

case 'store-settings':<br />

case 'account-setup':<br />

case 'delete-account':<br />

display_account_setup($_SESSION['auth_user']);<br />

break;<br />

This is the typical pattern: Each comm<strong>and</strong> calls a function. In this case, you call the<br />

display_account_setup() function.The code for this function is shown in Listing<br />

29.3.<br />

Listing 29.3 display_account_setup() Function from output_fns.php—<br />

Function to Get <strong>and</strong> Display Account Details<br />

function display_account_setup($auth_user) {<br />

//display empty 'new account' form<br />

display_account_form($auth_user);<br />

$list = get_accounts($auth_user);<br />

$accounts = sizeof($list);<br />

// display each stored account<br />

foreach($list as $key => $account) {<br />

// display form for each accounts details.<br />

// note that we are going to send the password for all accounts in the HTML<br />

// this is not really a very good idea<br />

display_account_form($auth_user, $account['accountid'], $account['server'],<br />

$account['remoteuser'], $account['remotepassword'],<br />

$account['type'], $account['port']);<br />

}<br />

}<br />

When you call the display_account_setup() function, it displays a blank form to add<br />

a new account, followed by editable forms containing each of the user’s current email<br />

accounts.The display_account_form() function displays the form shown in Figure<br />

29.4.You use it in two different ways here:You use it with no parameters to display an<br />

empty form, <strong>and</strong> you use it with a full set of parameters to display an existing record.<br />

This function is in the output_fns.php library; it simply outputs HTML, so we do not<br />

go through it here.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!