}
/**
- * 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;
$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;
}
/**
* 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. */
$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 ' <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);
}
--- /dev/null
+<?php
+
+/**
+ * abook_util.php
+ *
+ * The following functions are utility functions for templates. Do not
+ * echo output in these functions.
+ *
+ * @copyright © 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)) : '');
+}
+
+
}
$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;
}
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').
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').
if ($showaddrlist) {
+//FIXME: Remove HTML from here!
echo addForm($form_url, 'post', 'address_book_form');
$oTemplate->assign('addresses', $addresses);
}
/* 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 */
?>
<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>
*/
/** 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);
</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>';
* @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.
*