X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Faddressbook.php;h=9a1ced25a9d4966cec17b26bef9a70adedd2a352;hb=823d08e55104565e7d94d879c3a3244d6719a5c4;hp=6e17d228d7b07e71b0992e8270316ef8d54a14f0;hpb=625c8b787b79d07a1e53ba05213f66451d73651e;p=squirrelmail.git diff --git a/src/addressbook.php b/src/addressbook.php index 6e17d228..9a1ced25 100644 --- a/src/addressbook.php +++ b/src/addressbook.php @@ -3,101 +3,78 @@ /** * addressbook.php * - * Copyright (c) 1999-2002 The SquirrelMail Project Team - * Licensed under the GNU GPL. For full terms see the file COPYING. - * * Manage personal address book. * - * $Id$ + * @copyright © 1999-2007 The SquirrelMail Project Team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + * @version $Id$ + * @package squirrelmail + * @subpackage addressbook */ -/* Path for SquirrelMail required files. */ -define('SM_PATH','../'); +/** This is the addressbook page */ +define('PAGE_NAME', 'addressbook'); + +/** + * Include the SquirrelMail initialization file. + */ +include('../include/init.php'); -/* SquirrelMail required files. */ -require_once(SM_PATH . 'include/validate.php'); -require_once(SM_PATH . 'functions/display_messages.php'); +/** SquirrelMail required files. */ +/* address book functions */ require_once(SM_PATH . 'functions/addressbook.php'); -require_once(SM_PATH . 'functions/strings.php'); -require_once(SM_PATH . 'functions/html.php'); +include_once(SM_PATH . 'templates/util_addressbook.php'); -/* lets get the global vars we may need */ -$key = $_COOKIE['key']; +/* form functions */ +require_once(SM_PATH . 'functions/forms.php'); -$username = $_SESSION['username']; -$onetimepad = $_SESSION['onetimepad']; -$base_uri = $_SESSION['base_uri']; -$delimiter = $_SESSION['delimiter']; +/** lets get the global vars we may need */ /* From the address form */ -if ( isset($_POST['addaddr']) ) { - $addaddr = &$_POST['addaddr']; -} -if ( isset($_POST['editaddr']) ) { - $editaddr = &$_POST['editaddr']; -} -if ( isset($_POST['deladdr']) ) { - $deladdr = &$_POST['deladdr']; +sqgetGlobalVar('addaddr', $addaddr, SQ_POST); +sqgetGlobalVar('editaddr', $editaddr, SQ_POST); +sqgetGlobalVar('deladdr', $deladdr, SQ_POST); +sqgetGlobalVar('sel', $sel, SQ_POST); +sqgetGlobalVar('oldnick', $oldnick, SQ_POST); +sqgetGlobalVar('backend', $backend, SQ_POST); +sqgetGlobalVar('doedit', $doedit, SQ_POST); + +/* Get sorting order */ +$abook_sort_order = get_abook_sort(); + +/* Create page header before addressbook_init in order to display error messages correctly. */ +displayPageHeader($color); + +/* Open addressbook with error messages on. + remote backends (LDAP) are enabled because they can be used. (list_addr function) +*/ +$abook = addressbook_init(true, false); + +// FIXME: do we have to stop use of address book, when localbackend is not present. +if($abook->localbackend == 0) { + plain_error_message(_("No personal address book is defined. Contact administrator.")); + exit(); } -$sel = &$_POST['sel']; -if (isset($_POST['oldnick'])) { - $oldnick = $_POST['oldnick']; -} -if (isset($_POST['backend'])) { - $backend = $_POST['backend']; -} -if (isset($_POST['doedit'])) { - $doedit = $_POST['doedit']; +$current_backend = $abook->localbackend; +if (sqgetGlobalVar('new_bnum',$new_backend,SQ_POST) && array_key_exists($new_backend,$abook->backends)) { + $current_backend = (int) $new_backend; } -/* Make an input field */ -function adressbook_inp_field($label, $field, $name, $size, $values, $add) { - global $color; - $td_str = '' . _("Must be unique") . '') . - adressbook_inp_field(_("E-mail address"), 'email', $name, 45, $values, '') . - adressbook_inp_field(_("First name"), 'firstname', $name, 45, $values, '') . - adressbook_inp_field(_("Last name"), 'lastname', $name, 45, $values, '') . - adressbook_inp_field(_("Additional info"), 'label', $name, 45, $values, '') . - html_tag( 'tr', - html_tag( 'td', - '', - 'center', $color[4], 'colspan="2"') - ) - , 'center', '', 'border="0" cellpadding="1" width="90%"') ."\n"; -} - -/* Open addressbook, with error messages on but without LDAP (the * - * second "true"). Don't need LDAP here anyway */ -$abook = addressbook_init(true, true); -if($abook->localbackend == 0) { - plain_error_message( - _("No personal address book is defined. Contact administrator."), - $color); - exit(); } -displayPageHeader($color, 'None'); - $defdata = array(); $formerror = ''; $abortform = false; @@ -105,18 +82,18 @@ $showaddrlist = true; $defselected = array(); $form_url = 'addressbook.php'; - /* Handle user's actions */ -if($_SERVER['REQUEST_METHOD'] == 'POST') { +if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'POST') { /************************************************** * Add new address * **************************************************/ - if (!empty($addaddr['nickname'])) { - foreach( $addaddr as $k => $adr ) { - $addaddr[$k] = strip_tags( $adr ); + if (isset($addaddr)) { + if (isset($backend)) { + $r = $abook->add($addaddr, $backend); + } else { + $r = $abook->add($addaddr, $abook->localbackend); } - $r = $abook->add($addaddr, $abook->localbackend); /* Handle error messages */ if (!$r) { @@ -137,14 +114,14 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') { $orig_sel = $sel; sort($sel); - /* The selected addresses are identidied by "backend:nickname". * + /* The selected addresses are identidied by "nickname_backend". * * Sort the list and process one backend at the time */ $prevback = -1; $subsel = array(); $delfailed = false; for ($i = 0 ; (($i < sizeof($sel)) && !$delfailed) ; $i++) { - list($sbackend, $snick) = explode(':', $sel[$i]); + list($snick, $sbackend) = explode('_', $sel[$i]); /* When we get to a new backend, process addresses in * * previous one. */ @@ -184,7 +161,6 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') { * Update/modify address * ***********************************************/ if (!empty($editaddr)) { - /* Stage one: Copy data into form */ if (isset($sel) && sizeof($sel) > 0) { if(sizeof($sel) > 1) { @@ -193,80 +169,55 @@ if($_SERVER['REQUEST_METHOD'] == 'POST') { $defselected = $sel; } else { $abortform = true; - list($ebackend, $enick) = explode(':', $sel[0]); + list($enick, $ebackend) = explode('_', current($sel)); $olddata = $abook->lookup($enick, $ebackend); - - /* Display the "new address" form */ - echo '
'; + // Test if $olddata really contains anything and return an error message if it doesn't + if (!$olddata) { + error_box(nl2br(htmlspecialchars($abook->error))); + } else { + /* Display the "new address" form */ + abook_create_form($form_url,'editaddr',_("Update address"),_("Update address"),$olddata); + echo addHidden('oldnick', $olddata['nickname']). + addHidden('backend', $olddata['backend']). + addHidden('doedit', '1'). + ''; + } } - } else { - + } elseif ($doedit == 1) { /* Stage two: Write new data */ - if ($doedit = 1) { - $newdata = $editaddr; - $r = $abook->modify($oldnick, $newdata, $backend); - - /* Handle error messages */ - if (!$r) { - /* Display error */ - echo html_tag( 'table', - html_tag( 'tr', - html_tag( 'td', - "\n". '