=================================================================== RCS file: /cvsroot/squirrelmail/squirrelmail/functions/identity.php,v retrieving revision 1.4.4.6 retrieving revision 1.4.4.7 diff -u -r1.4.4.6 -r1.4.4.7 --- squirrelmail/squirrelmail/functions/identity.php 2005/06/13 02:51:49 1.4.4.6 +++ squirrelmail/squirrelmail/functions/identity.php 2005/06/29 20:02:33 1.4.4.7 @@ -59,4 +59,139 @@ return $identities; } +/** + * Function to save the identities array + * + * @param array $identities Array of identities + */ +function save_identities($identities) { + + global $username, $data_dir, $domain; + + if (empty($identities) || !is_array($identities)) { + return; + } + + + $num_cur = getPref($data_dir, $username, 'identities'); + + $cnt = count($identities); + + // Remove any additional identities in prefs // + for($i=$cnt; $i <= $num_cur; $i++) { + removePref($data_dir, $username, 'full_name' . $i); + removePref($data_dir, $username, 'email_address' . $i); + removePref($data_dir, $username, 'reply_to' . $i); + setSig($data_dir, $username, $i, ''); + } + + foreach($identities as $id=>$ident) { + + $key = ($id?$id:''); + + setPref($data_dir, $username, 'full_name' . $key, $ident['full_name']); + setPref($data_dir, $username, 'email_address' . $key, $ident['email_address']); + setPref($data_dir, $username, 'reply_to' . $key, $ident['reply_to']); + + if ($id === 0) { + setSig($data_dir, $username, 'g', $ident['signature']); + } else { + setSig($data_dir, $username, $key, $ident['signature']); + } + + } + + setPref($data_dir, $username, 'identities', $cnt); + +} + +/** + * Returns an array with a fixed set of identities + * + * @param array $identities Array of identities + * @param int $id Identity to modify + * @param string $action Action to perform + * @return array + */ +function sqfixidentities( $identities, $id, $action ) { + + $fixed = array(); + $tmp_hold = array(); + $i = 0; + + if (empty($identities) || !is_array($identities)) { + return $fixed; + } + + foreach( $identities as $key=>$ident ) { + + if (empty_identity($ident)) { + continue; + } + + switch($action) { + + case 'makedefault': + + if ($key == $id) { + $fixed[0] = $ident; + continue 2; + } else { + $fixed[$i+1] = $ident; + } + break; + + case 'move': + + if ($key == ($id - 1)) { + $tmp_hold = $ident; + continue 2; + } else { + $fixed[$i] = $ident; + + if ($key == $id) { + $i++; + $fixed[$i] = $tmp_hold; + } + } + break; + + case 'delete': + + if ($key == $id) { + continue 2; + } else { + $fixed[$i] = $ident; + } + break; + + // we should never hit this but just in case // + default: + $fixed[$i] = $ident; + + } + + // Inc array index // + $i++; + } + + ksort($fixed); + return $fixed; + +} + +/** + * Function to test if identity is empty + * + * @param array $identity Identitiy Array + * @return boolean + */ +function empty_identity($ident) { + if (empty($ident['full_name']) && empty($ident['email_address']) && empty($ident['signature']) && empty($ident['reply_to'])) { + return true; + } else { + return false; + } +} + ?> Index: options_identities.php =================================================================== RCS file: /cvsroot/squirrelmail/squirrelmail/src/options_identities.php,v retrieving revision 1.22.2.4 retrieving revision 1.22.2.6 diff -u -w -r1.22.2.4 -r1.22.2.6 --- options_identities.php 27 Dec 2004 15:04:00 -0000 1.22.2.4 +++ options_identities.php 1 Jul 2005 08:04:48 -0000 1.22.2.6 @@ -20,55 +21,69 @@ /* SquirrelMail required files. */ require_once(SM_PATH . 'include/validate.php'); -require_once(SM_PATH . 'functions/global.php'); -require_once(SM_PATH . 'functions/display_messages.php'); -require_once(SM_PATH . 'functions/html.php'); - -/* POST data var names are dynamic because - of the possible multiple idents so lets get - them all -*/ -if (!empty($_POST)) { - extract($_POST); -} -/* got 'em all */ +include_once(SM_PATH . 'functions/global.php'); +include_once(SM_PATH . 'functions/display_messages.php'); +include_once(SM_PATH . 'functions/html.php'); +include_once(SM_PATH . 'functions/identity.php'); - if (isset($return)) { - SaveUpdateFunction(); - header('Location: options_personal.php'); - exit(); +if (!sqgetGlobalVar('identities', $identities, SQ_SESSION)) { + $identities = get_identities(); } +sqgetGlobalVar('newidentities', $newidentities, SQ_POST); +sqgetGlobalVar('smaction', $smaction, SQ_POST); +sqgetGlobalVar('return', $return, SQ_POST); - displayPageHeader($color, 'None'); +// First lets see if there are any actions to perform // +if (!empty($smaction) && is_array($smaction)) { + + $doaction = ''; + $identid = 0; - $Info = do_hook('options_identities_process', 0); - if ($Info[1]) { - SaveUpdateFunction(); + foreach($smaction as $action=>$row) { + // we only need to extract the action and the identity we are + // altering + + foreach($row as $key=>$data) { + $identid = $key; } - if (CheckAndDoDefault() || CheckAndDoPromote()) { - SaveUpdateFunction(); + $doaction = $action; } - if (isset($update) || CheckForDelete()) { - SaveUpdateFunction(); + + $identities = sqfixidentities( $newidentities , $identid , $action ); + save_identities($identities); } +if (!empty($return)) { + header('Location: ' . get_location() . '/options_personal.php'); + exit; +} + +displayPageHeader($color, 'None'); + do_hook('options_identities_top'); - LoadInfo($full_name, $email_address, $reply_to, $signature, ''); + $td_str = ''; - $td_str .= '
'; + +echo '