X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Faddressbook.php;h=6745b429e17ed9f2a88230f0a5d798c0bb5523d4;hb=24fc49052db9408811aadf5b2e2740371553ace2;hp=634e5c744106292d8708a51f2fd59148722e3cea;hpb=f6c945b9f6c7870dda5c65997f60adceb408cdcc;p=squirrelmail.git diff --git a/src/addressbook.php b/src/addressbook.php index 634e5c74..6745b429 100644 --- a/src/addressbook.php +++ b/src/addressbook.php @@ -11,56 +11,82 @@ * $Id$ */ -require_once('../src/validate.php'); -require_once('../functions/array.php'); -require_once('../functions/display_messages.php'); -require_once('../functions/addressbook.php'); - -/* Sort array by the key "name" */ -function alistcmp($a,$b) { - if($a['backend'] > $b['backend']) { - return 1; - } else { - if($a['backend'] < $b['backend']) { - return -1; - } - } - return (strtolower($a['name']) > strtolower($b['name'])) ? 1 : -1; +/* Path for SquirrelMail required files. */ +define('SM_PATH','../'); + +/* SquirrelMail required files. */ +require_once(SM_PATH . 'include/validate.php'); +require_once(SM_PATH . 'functions/array.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'); + +/* lets get the global vars we may need */ +$key = $_COOKIE['key']; + +$username = $_SESSION['username']; +$onetimepad = $_SESSION['onetimepad']; +$base_uri = $_SESSION['base_uri']; +$delimiter = $_SESSION['delimiter']; + +/* 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']; +} +$sel = &$_POST['sel']; + +if (isset($_POST['oldnick'])) { + $oldnick = $_POST['oldnick']; +} +if (isset($_POST['backend'])) { + $backend = $_POST['backend']; +} +if (isset($_POST['doedit'])) { + $doedit = $_POST['doedit']; } /* Make an input field */ function adressbook_inp_field($label, $field, $name, $size, $values, $add) { global $color; - echo '' . - $label . ':' . - '' . - '' . $add . '' . "\n"; + $td_str .= '">' . $add . ''; + return html_tag( 'tr' , + html_tag( 'td', $label . ':', 'right', $color[4]) . + html_tag( 'td', $td_str, 'left', $color[4]) + ) + . "\n"; } /* Output form to add and modify address data */ function address_form($name, $submittext, $values = array()) { global $color; - - echo '' ."\n"; - - adressbook_inp_field(_("Nickname"), 'nickname', $name, 15, $values, - '' . _("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, ''); - - echo '' . - "\n
' . "\n" . - '
\n"; + + echo html_tag( 'table', + adressbook_inp_field(_("Nickname"), 'nickname', $name, 15, $values, + ' ' . _("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); @@ -73,22 +99,24 @@ if($abook->localbackend == 0) { displayPageHeader($color, 'None'); - $defdata = array(); $formerror = ''; $abortform = false; $showaddrlist = true; $defselected = array(); +$form_url = 'addressbook.php'; /* Handle user's actions */ -if($REQUEST_METHOD == 'POST') { +if($_SERVER['REQUEST_METHOD'] == 'POST') { /************************************************** * Add new address * **************************************************/ if (!empty($addaddr['nickname'])) { - + foreach( $addaddr as $k => $adr ) { + $addaddr[$k] = strip_tags( $adr ); + } $r = $abook->add($addaddr, $abook->localbackend); /* Handle error messages */ @@ -101,7 +129,6 @@ if($REQUEST_METHOD == 'POST') { $showaddrlist = false; $defdata = $addaddr; } - } else { /************************************************ @@ -171,13 +198,15 @@ if($REQUEST_METHOD == 'POST') { $olddata = $abook->lookup($enick, $ebackend); /* Display the "new address" form */ - echo '
' . + echo '' . "\n" . - '' . "\n" . - '\n
' . "\n" . '' . - _("Update address") . - "\n
\n"; + html_tag( 'table', + html_tag( 'tr', + html_tag( 'td', + "\n". '' . _("Update address") . '' ."\n", + 'center', $color[0] ) + ), + 'center', '', 'width="100%" ' ); address_form("editaddr", _("Update address"), $olddata); echo '\n" . @@ -196,20 +225,25 @@ if($REQUEST_METHOD == 'POST') { /* Handle error messages */ if (!$r) { /* Display error */ - echo '' . - "\n" . '\n
' . "\n" . - '
' . _("ERROR") . ": " . $abook->error . - '' . "\n
\n"; + echo html_tag( 'table', + html_tag( 'tr', + html_tag( 'td', + "\n". '
' . _("ERROR") . ': ' . $abook->error . '' ."\n", + 'center' ) + ), + 'center', '', 'width="100%"' ); /* Display the "new address" form again */ - echo '' . "\n" . - '' . - "\n" . '\n
' . "\n" . '' . - _("Update address") . - "\n
\n"; + html_tag( 'table', + html_tag( 'tr', + html_tag( 'td', + "\n". '
' . _("Update address") . '' ."\n", + 'center', $color[0] ) + ), + 'center', '', 'width="100%"' ) . address_form("editaddr", _("Update address"), $newdata); echo '\n" . @@ -245,10 +279,14 @@ if($REQUEST_METHOD == 'POST') { /* Display error messages */ if (!empty($formerror)) { - echo '' . "\n" . - '\n
\n
' . - '' . _("ERROR") . ': ' . $formerror . - '' . "\n
\n"; + echo html_tag( 'table', + html_tag( 'tr', + html_tag( 'td', + "\n". '
' . _("ERROR") . ': ' . $formerror . '' ."\n", + 'center' ) + ), + 'center', '', 'width="100%"' ); } @@ -265,87 +303,109 @@ if ($showaddrlist) { $prevbackend = -1; $headerprinted = false; - echo '

' . - _("Add address") . "

\n"; + echo html_tag( 'p', '' . _("Add address") . '', 'center' ) . "\n"; /* List addresses */ - echo '' . "\n"; - while(list($undef,$row) = each($alist)) { - - /* New table header for each backend */ - if($prevbackend != $row['backend']) { - if($prevbackend >= 0) { - echo '' . "\n" . - '\n" . - '\n\n" . - '' . - ' 
' . "\n"; + if (count($alist) > 0) { + echo '' . "\n"; + while(list($undef,$row) = each($alist)) { + + /* New table header for each backend */ + if($prevbackend != $row['backend']) { + if($prevbackend < 0) { + echo html_tag( 'table', + html_tag( 'tr', + html_tag( 'td', + '\n" . + '\n", + 'center', '', 'colspan="5"' ) + ) . + html_tag( 'tr', + html_tag( 'td', ' 
', 'center', '', 'colspan="5"' ) + ) , + 'center' ); + } + + echo html_tag( 'table', + html_tag( 'tr', + html_tag( 'td', "\n" . '' . $row['source'] . '' . "\n", 'center', $color[0] ) + ) , + 'center', '', 'width="95%"' ) ."\n" + . html_tag( 'table', '', 'center', '', 'border="0" cellpadding="1" cellspacing="0" width="90%"' ) . + html_tag( 'tr', "\n" . + html_tag( 'th', ' ', 'left', '', 'width="1%"' ) . + html_tag( 'th', _("Nickname"), 'left', '', 'width="1%"' ) . + html_tag( 'th', _("Name"), 'left', '', 'width="1%"' ) . + html_tag( 'th', _("E-mail"), 'left', '', 'width="1%"' ) . + html_tag( 'th', _("Info"), 'left', '', 'width="1%"' ) , + '', $color[9] ) . "\n"; + + $line = 0; + $headerprinted = true; + } /* End of header */ + + $prevbackend = $row['backend']; + + /* Check if this user is selected */ + if(in_array($row['backend'] . ':' . $row['nickname'], $defselected)) { + $selected = 'CHECKED'; + } else { + $selected = ''; } - - echo '' . "\n" . - '\n
' . "\n" . - '' . $row['source'] . - "\n
\n" . - '' . - '\n"; - - $line = 0; - $headerprinted = true; - } /* End of header */ - - $prevbackend = $row['backend']; - - /* Check if this user is selected */ - if(in_array($row['backend'] . ':' . $row['nickname'], $defselected)) { - $selected = 'CHECKED'; - } else { - $selected = ''; + + /* Print one row */ + $tr_bgcolor = ''; + if ($line % 2) { $tr_bgcolor = $color[0]; } + echo html_tag( 'tr', '') . + html_tag( 'td', + '' . + '' , + 'center', '', 'valign="top" width="1%"' ) . + html_tag( 'td', ' ' . $row['nickname'] . ' ', 'left', '', 'valign="top" width="1%" nowrap' ) . + html_tag( 'td', ' ' . $row['name'] . ' ', 'left', '', 'valign="top" width="1%" nowrap' ) . + html_tag( 'td', '', 'left', '', 'valign="top" width="1%" nowrap' ) . ' '; + $email = $abook->full_address($row); + if ($compose_new_win == '1') { + echo ''; + } + else { + echo ''; + } + echo htmlspecialchars($row['email']) . ' '."\n". + html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'valign="top" width="1%"' ) . + "\n"; + $line++; } - - /* Print one row */ - echo '' . - '' . - '', - ''."\n", - '' . - "\n"; - $line++; - } - - /* End of list. Close table. */ - if ($headerprinted) { - echo '
 ' . - _("Nickname") . '' . _("Name") . - '' . _("E-mail") . - '' . _("Info") . "
' . - ' ' . $row['nickname'] . - '  ' . $row['name'] . - '  ' . - '' . $row['email'] . '  ' . $row['label'] . ' 
' . "\n" . - '\n" . - '\n" . '
'; + + /* End of list. Close table. */ + if ($headerprinted) { + echo html_tag( 'tr', + html_tag( 'td', + '\n" . + '\n", + 'center', '', 'colspan="5"' ) + ); + } + echo ''; } } /* end of addresslist */ /* Display the "new address" form */ echo '' . "\n" . - '
' . "\n" . - '' . "\n" . - '\n" . - "
' . "\n" . '', - sprintf(_("Add to %s"), $abook->localbackendname) . - "\n
\n"; + '' . "\n" . + html_tag( 'table', + html_tag( 'tr', + html_tag( 'td', "\n". '' . sprintf(_("Add to %s"), $abook->localbackendname) . '' . "\n", + 'center', $color[0] + ) + ) + , 'center', '', 'width="100%"' ) ."\n"; address_form('addaddr', _("Add address"), $defdata); echo '
';