Make sort links and add form return to the same backend that is currently being viewed
authorpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 15 May 2008 05:49:56 +0000 (05:49 +0000)
committerpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 15 May 2008 05:49:56 +0000 (05:49 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@13140 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/addressbook.php
functions/template/abook_util.php [new file with mode: 0644]
src/addressbook.php
templates/default/addrbook_addedit.tpl
templates/default/addressbook_list.tpl
templates/util_addressbook.php

index b65f993..b0dd88c 100644 (file)
@@ -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 '&nbsp;<a href="' . $form_url .'?abook_sort_order=' . $which .
-           '" style="text-decoration:none" title="'.$alt_tag.'">' .
-           getIcon($icon_theme_path, $img, $text_icon, $alt_tag) .
-           '</a>';
+    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 (file)
index 0000000..53bfb40
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+
+/**
+ * abook_util.php
+ *
+ * The following functions are utility functions for templates. Do not
+ * echo output in these functions.
+ *
+ * @copyright &copy; 2005-2008 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ * @version $Id$
+ * @package squirrelmail
+ */
+
+
+/**
+ * Display a column header with sort buttons
+ *
+ * @param string $field   Which field to display
+ * @param int    $backend The abook backend to be shown when
+ *                        sort link is clicked
+ *
+ * @author Steve Brown
+ * @since 1.5.2
+ */
+function addAbookSort ($field, $backend) {
+    global $abook_sort_order, $nbsp;
+
+    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.'"';
+    }
+
+    // show_abook_sort_button() creates a hyperlink (using hyperlink.tpl) that encompases an image, using a getImage() call
+    return $str . ($has_sort ? $nbsp . show_abook_sort_button($abook_sort_order, $alt, $down, $up, array('new_bnum' => $backend)) : '');
+}
+
+
index 9a1ced2..4d755e1 100644 (file)
@@ -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 '<a name="AddAddress"></a>' . "\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 "</form>\n";
 
 /* Hook for extra address book blocks */
index 6bc5fc6..f03dc43 100644 (file)
@@ -119,6 +119,7 @@ $formname = $edit ? 'editaddr' : 'addaddr';
  ?>
  <tr>
   <td colspan="2" class="addButton">
+   <input type="hidden" name="new_bnum" value="<?php echo $current_backend; ?>" />
    <input type="submit" value=<?php echo '"'.($edit ? _("Update address") : _("Add address")).'"'; ?> name="<?php echo $formname; ?>[SUBMIT]" />
   </td>
  </tr>
index 5b82bcf..dbbbce0 100644 (file)
@@ -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;
  </tr>
  <tr>
   <td class="colHeader" style="width:1%"><input type="checkbox" name="toggleAll" id="toggleAll" title="<?php echo _("Toggle All"); ?>" onclick="toggle_all('address_book_form', 'sel', false); return false;" /></td>
-  <td class="colHeader" style="width:15%"><?php echo addAbookSort('nickname'); ?></td>
-  <td class="colHeader"><?php echo addAbookSort('fullname'); ?></td>
-  <td class="colHeader"><?php echo addAbookSort('email'); ?></td>
-  <td class="colHeader"><?php echo addAbookSort('info'); ?></td>
+  <td class="colHeader" style="width:15%"><?php echo addAbookSort('nickname', $current_backend); ?></td>
+  <td class="colHeader"><?php echo addAbookSort('fullname', $current_backend); ?></td>
+  <td class="colHeader"><?php echo addAbookSort('email', $current_backend); ?></td>
+  <td class="colHeader"><?php echo addAbookSort('info', $current_backend); ?></td>
   <?php
    if ($abook_has_extra_field) {
     echo '<td class="colHeader"></td>';
index 49d05df..92c1b2f 100644 (file)
  * @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.
  *