From: pdontthink Date: Thu, 15 May 2008 05:49:56 +0000 (+0000) Subject: Make sort links and add form return to the same backend that is currently being viewed X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=caa596b29982636a056f813f41b43d1ec036d6a2;p=squirrelmail.git Make sort links and add form return to the same backend that is currently being viewed git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@13140 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/addressbook.php b/functions/addressbook.php index b65f993b..b0dd88c3 100644 --- a/functions/addressbook.php +++ b/functions/addressbook.php @@ -169,20 +169,29 @@ function addressbook_init($showerr = true, $onlylocal = false) { } /** - * Display the "new address" form + * Constructs the "new address" form + * + * NOTE! The form is not closed - the caller + * must add the closing form tag itself. * - * Form is not closed and you must add closing form tag. * @since 1.5.1 - * @param string $form_url form action url - * @param string $name form name - * @param string $title form title - * @param string $button form button name - * @param array $defdata values of form fields + * + * @param string $form_url Form action url + * @param string $name Form name + * @param string $title Form title + * @param string $button Form button name + * @param int $backend The current backend being displayed + * @param array $defdata Values of form fields + * + * @return string The desired address form display code + * */ -function abook_create_form($form_url,$name,$title,$button,$defdata=array()) { +function abook_create_form($form_url, $name, $title, $button, + $backend, $defdata=array()) { + global $oTemplate; - echo addForm($form_url, 'post', 'f_add'); + $output = addForm($form_url, 'post', 'f_add'); if ($button == _("Update address")) { $edit = true; @@ -207,8 +216,11 @@ function abook_create_form($form_url,$name,$title,$button,$defdata=array()) { $oTemplate->assign('writable_backends', $backends); $oTemplate->assign('values', $values); $oTemplate->assign('edit', $edit); + $oTemplate->assign('current_backend', $backend); - $oTemplate->display('addrbook_addedit.tpl'); + $output .= $oTemplate->fetch('addrbook_addedit.tpl'); + + return $output; } @@ -316,13 +328,24 @@ function get_abook_sort() { /** * This function shows the address book sort button. * - * @param integer $abook_sort_order current sort value - * @param string $alt_tag alt tag value (string visible to text only browsers) - * @param integer $Down sort value when list is sorted ascending - * @param integer $Up sort value when list is sorted descending + * @param integer $abook_sort_order Current sort value + * @param string $alt_tag The alt tag value (string + * visible to text only browsers) + * @param integer $Down Sort value when list is sorted + * ascending + * @param integer $Up Sort value when list is sorted + * descending + * @param array $uri_extra Any additional parameters to add + * to the button's link, as an + * associative array of key/value pairs + * (OPTIONAL; default none) + * * @return string html code with sorting images and urls + * */ -function show_abook_sort_button($abook_sort_order, $alt_tag, $Down, $Up ) { +function show_abook_sort_button($abook_sort_order, $alt_tag, + $Down, $Up, $uri_extra=array() ) { + global $form_url, $icon_theme_path; /* Figure out which image we want to use. */ @@ -340,11 +363,17 @@ function show_abook_sort_button($abook_sort_order, $alt_tag, $Down, $Up ) { $which = 8; } + $uri = $form_url .'?abook_sort_order=' . $which; + foreach ($uri_extra as $key => $value) + $uri = set_url_var($uri, $key, $value, FALSE); + /* Now that we have everything figured out, show the actual button. */ - return ' ' . - getIcon($icon_theme_path, $img, $text_icon, $alt_tag) . - ''; + return create_hyperlink($uri, + getIcon($icon_theme_path, $img, $text_icon, $alt_tag), + '', '', '', '', '', + array('style' => 'text-decoration:none', + 'title' => $alt_tag), + FALSE); } diff --git a/functions/template/abook_util.php b/functions/template/abook_util.php new file mode 100644 index 00000000..53bfb400 --- /dev/null +++ b/functions/template/abook_util.php @@ -0,0 +1,66 @@ + $backend)) : ''); +} + + diff --git a/src/addressbook.php b/src/addressbook.php index 9a1ced25..4d755e11 100644 --- a/src/addressbook.php +++ b/src/addressbook.php @@ -57,7 +57,8 @@ if($abook->localbackend == 0) { } $current_backend = $abook->localbackend; -if (sqgetGlobalVar('new_bnum',$new_backend,SQ_POST) && array_key_exists($new_backend,$abook->backends)) { +if (sqgetGlobalVar('new_bnum', $new_backend, SQ_FORM) + && array_key_exists($new_backend, $abook->backends)) { $current_backend = (int) $new_backend; } @@ -176,7 +177,11 @@ if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'P error_box(nl2br(htmlspecialchars($abook->error))); } else { /* Display the "new address" form */ - abook_create_form($form_url,'editaddr',_("Update address"),_("Update address"),$olddata); + echo abook_create_form($form_url, 'editaddr', + _("Update address"), + _("Update address"), + $current_backend, + $olddata); echo addHidden('oldnick', $olddata['nickname']). addHidden('backend', $olddata['backend']). addHidden('doedit', '1'). @@ -194,7 +199,11 @@ if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'P plain_error_message( nl2br(htmlspecialchars($abook->error))); /* Display the "new address" form again */ - abook_create_form($form_url,'editaddr',_("Update address"),_("Update address"),$newdata); + echo abook_create_form($form_url, 'editaddr', + _("Update address"), + _("Update address"), + $current_backend, + $newdata); echo addHidden('oldnick', $oldnick). addHidden('backend', $backend). addHidden('doedit', '1'). @@ -259,6 +268,7 @@ while (list($k, $backend) = each ($abook->backends)) { if ($showaddrlist) { +//FIXME: Remove HTML from here! echo addForm($form_url, 'post', 'address_book_form'); $oTemplate->assign('addresses', $addresses); @@ -273,9 +283,13 @@ if ($showaddrlist) { } /* Display the "new address" form */ -//FIXME: Remove HTML from here! +//FIXME: Remove HTML from here! (echo abook_create_form() is OK, since it is all template based output echo '' . "\n"; -abook_create_form($form_url,'addaddr',_("Add to address book"),_("Add address"),$defdata); +echo abook_create_form($form_url, 'addaddr', + _("Add to address book"), + _("Add address"), + $current_backend, + $defdata); echo "\n"; /* Hook for extra address book blocks */ diff --git a/templates/default/addrbook_addedit.tpl b/templates/default/addrbook_addedit.tpl index 6bc5fc64..f03dc439 100644 --- a/templates/default/addrbook_addedit.tpl +++ b/templates/default/addrbook_addedit.tpl @@ -119,6 +119,7 @@ $formname = $edit ? 'editaddr' : 'addaddr'; ?> + name="[SUBMIT]" /> diff --git a/templates/default/addressbook_list.tpl b/templates/default/addressbook_list.tpl index 5b82bcf5..dbbbce05 100644 --- a/templates/default/addressbook_list.tpl +++ b/templates/default/addressbook_list.tpl @@ -43,7 +43,7 @@ */ /** add required includes **/ -include_once(SM_PATH . 'templates/util_addressbook.php'); +include_once(SM_PATH . 'functions/template/abook_util.php'); /** extract template variables **/ extract($t); @@ -86,10 +86,10 @@ $colspan = $abook_has_extra_field ? 6 : 5; " onclick="toggle_all('address_book_form', 'sel', false); return false;" /> - - - - + + + + '; diff --git a/templates/util_addressbook.php b/templates/util_addressbook.php index 49d05df6..92c1b2fe 100644 --- a/templates/util_addressbook.php +++ b/templates/util_addressbook.php @@ -11,52 +11,7 @@ * @subpackage templates */ -/** - * Display a column header with sort buttons - * - * @param string $field which field to display - * @author Steve Brown - * @since 1.5.2 - */ -function addAbookSort ($field) { - global $abook_sort_order; - - switch ($field) { - case 'nickname': - $str = _("Nickname"); - $alt = _("sort by nickname"); - $down = 0; - $up = 1; - $has_sort = true; - break; - case 'fullname': - $str = _("Name"); - $alt = _("sort by name"); - $down = 2; - $up = 3; - $has_sort = true; - break; - case 'email': - $str = _("E-mail"); - $alt = _("sort by email"); - $down = 4; - $up = 5; - $has_sort = true; - break; - case 'info': - $str = _("Info"); - $alt = _("sort by info"); - $down = 6; - $up = 7; - $has_sort = true; - break; - default: - return 'BAD SORT FIELD GIVEN: "'.$field.'"'; - } - - return $str . ($has_sort ? show_abook_sort_button($abook_sort_order, $alt, $down, $up) : ''); -} - +//FIXME: the functions in this file should be reviewed and moved to functions/template/abook_util.php and this file should be removed /** * Create a link to compose an email to the email address given. *