X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Faddressbook.php;h=c0ff11ff9b4dec2f14897fc251c18cbefd5890f0;hb=50d5212cd729d067bd9d4243fd66eed39d608207;hp=cb3bd0e9898afb4593dad30df2799083eccd728d;hpb=abdfb4d05045aafa3170747a2dca7ce5243e840f;p=squirrelmail.git
diff --git a/src/addressbook.php b/src/addressbook.php
index cb3bd0e9..c0ff11ff 100644
--- a/src/addressbook.php
+++ b/src/addressbook.php
@@ -1,218 +1,501 @@
strtolower($b["name"])) ? 1 : -1;
- }
-
- // Output form to add and modify address data
- function address_form($name, $submittext, $values = array()) {
- global $color;
- print "
\n";
- printf("%s: | ",
- _("Nickname"));
- printf("".
- "".
- " %s |
\n",
- $color[4], $name, htmlspecialchars($values["nickname"]),
- _("Must be unique"));
- printf("%s: | ",
- _("E-mail address"));
- printf("".
- " |
\n",
- $color[4], $name, htmlspecialchars($values["email"]));
- printf("%s: | ",
- _("First name"));
- printf("".
- " |
\n",
- $color[4], $name, htmlspecialchars($values["firstname"]));
- printf("%s: | ",
- _("Last name"));
- printf("".
- " |
\n",
- $color[4], $name, htmlspecialchars($values["lastname"]));
- printf("%s: | ",
- _("Additional info"));
- printf("".
- " |
\n",
- $color[4], $name, htmlspecialchars($values["label"]));
-
- printf("\n".
- " |
\n",
- $color[4], $name, $submittext);
-
- print "
\n";
- }
-
-
- // IMAP Login
- $imapConnection = sqimap_login ($username, $key,
- $imapServerAddress, $imapPort, 10);
- include("../src/load_prefs.php");
- sqimap_logout ($imapConnection);
-
-
- // 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();
- }
-
- print "\n";
- print "\n";
- printf("%s: %s\n", $org_title, _("Address Book"));
- print "\n\n";
-
- printf('',
- $color[8], $color[4], $color[7], $color[7], $color[7]);
- displayPageHeader($color, "None");
-
-
- $defdata = array();
- $formerror = "";
- $abortform = false;
- $showaddrlist = true;
-
-
- // Handle user's actions
- if($REQUEST_METHOD == "POST") {
-
- // Check for user addition
- $add_data = $HTTP_POST_VARS["addaddr"];
- if(!empty($add_data["nickname"])) {
-
- $r = $abook->add($add_data, $abook->localbackend);
-
- // Handle error messages
- if(!$r) {
- // Remove backend name from error string
- $errstr = $abook->error;
- $errstr = ereg_replace("^\[.*\] *", "", $errstr);
-
- $formerror = $errstr;
- $showaddrlist = false;
- $defdata = $add_data;
- }
-
- }
- // Check for "delete address"
- if((!empty($HTTP_POST_VARS["deladdr"])) &&
- sizeof($HTTP_POST_VARS["sel"]) > 0) {
- plain_error_message("Delete address not implemented yet", $color);
- $abortform = true;
- }
+/**
+ * addressbook.php
+ *
+ * Copyright (c) 1999-2004 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * Manage personal address book.
+ *
+ * @version $Id$
+ * @package squirrelmail
+ */
- // Check for "edit address"
- if((!empty($HTTP_POST_VARS["editaddr"])) &&
- sizeof($HTTP_POST_VARS["sel"]) > 0) {
- plain_error_message("Edit address not implemented yet", $color);
- $abortform = true;
- }
+/**
+ * Path for SquirrelMail required files.
+ * @ignore
+ */
+define('SM_PATH','../');
- // Some times we end output before forms are printed
- if($abortform) {
- print "\n";
- exit();
- }
+/** 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/addressbook.php');
+require_once(SM_PATH . 'functions/strings.php');
+require_once(SM_PATH . 'functions/html.php');
+require_once(SM_PATH . 'functions/forms.php');
+
+/** lets get the global vars we may need */
+sqgetGlobalVar('key', $key, SQ_COOKIE);
+
+sqgetGlobalVar('username', $username, SQ_SESSION);
+sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
+sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
+sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
+
+/* From the address form */
+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);
- }
-
- // ===================================================================
- // The following is only executed on a GET request, or on a POST when
- // a user is added, or when "delete" or "modify" was successful.
- // ===================================================================
-
- // Display error messages
- if(!empty($formerror)) {
- print "\n";
- print "\n ";
- print ""._("ERROR").": $formerror";
- print "\n |
\n";
- print "
\n";
- }
-
- // Display the address management part
- if($showaddrlist) {
- printf("";
- }
-
- // Display the "new address" form
- printf("";
+ }
+ $ret .= "";
+ return html_tag( 'tr',
+ html_tag( 'td', _("Add to:"),'right', $color[4] ) .
+ html_tag( 'td', $ret, 'left', $color[4] )) . "\n";
+ } else {
+ return html_tag( 'tr',
+ html_tag( 'td',
+ addHidden('backend', '1'),
+ 'center', $color[4], 'colspan="2"')) . "\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;
+$showaddrlist = true;
+$defselected = array();
+$form_url = 'addressbook.php';
+
+
+/* Handle user's actions */
+if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'POST') {
+
+ /**************************************************
+ * Add new address *
+ **************************************************/
+ if (isset($addaddr)) {
+ if (isset($backend)) {
+ $r = $abook->add($addaddr, $backend);
+ } else {
+ $r = $abook->add($addaddr, $abook->localbackend);
+ }
+
+ /* Handle error messages */
+ if (!$r) {
+ /* Remove backend name from error string */
+ $errstr = $abook->error;
+ $errstr = ereg_replace('^\[.*\] *', '', $errstr);
+
+ $formerror = $errstr;
+ $showaddrlist = false;
+ $defdata = $addaddr;
+ }
+ } else {
+
+ /************************************************
+ * Delete address(es) *
+ ************************************************/
+ if ((!empty($deladdr)) && sizeof($sel) > 0) {
+ $orig_sel = $sel;
+ sort($sel);
+
+ /* The selected addresses are identidied by "backend:nickname". *
+ * 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]);
+
+ /* When we get to a new backend, process addresses in *
+ * previous one. */
+ if ($prevback != $sbackend && $prevback != -1) {
+
+ $r = $abook->remove($subsel, $prevback);
+ if (!$r) {
+ $formerror = $abook->error;
+ $i = sizeof($sel);
+ $delfailed = true;
+ break;
+ }
+ $subsel = array();
+ }
+
+ /* Queue for processing */
+ array_push($subsel, $snick);
+ $prevback = $sbackend;
+ }
+
+ if (!$delfailed) {
+ $r = $abook->remove($subsel, $prevback);
+ if (!$r) { /* Handle errors */
+ $formerror = $abook->error;
+ $delfailed = true;
+ }
+ }
-