X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=src%2Faddrbook_search_html.php;h=0322132feb0dc6d29b79dd3b7593c6f1918ae86f;hp=fae1d4f3207e18d42148a92c7230084ac53a356b;hb=ebd2391cb0c5e3049870f90fa8a8b28707e9571a;hpb=d51894be063bf2e1349762bc554358c62d368e36 diff --git a/src/addrbook_search_html.php b/src/addrbook_search_html.php index fae1d4f3..0322132f 100644 --- a/src/addrbook_search_html.php +++ b/src/addrbook_search_html.php @@ -1,223 +1,178 @@ ' . "\n"; - echo '' . "\n"; - echo '' . "\n"; - echo "' . "\n"; - echo "' . "\n"; - echo "\n"; - } - - - // List search results - function addr_display_result($res, $includesource = true) { - global $color, $PHP_SELF; - - if(sizeof($res) <= 0) return; - - printf('
'."\n", - $PHP_SELF); - addr_insert_hidden(); - $line = 0; - - print ""; - printf("\n"; - - while(list($undef, $row) = each($res)) { - printf("\n"; - $line++; - } - printf('', - 4 + ($includesource ? 1 : 0), - _("Use Addresses")); - print '
 ". - " %s %s". - " %s", - _("Name"), _("E-mail"), _("Info")); - - if($includesource) - printf(" %s", _("Source")); - - print "
". - " To". - " Cc ". - " %s  ". - "%s". - " %s ", - ($line % 2) ? " bgcolor=\"$color[0]\"" : "", - htmlspecialchars($row["email"]), htmlspecialchars($row["email"]), - $row["name"], $row["email"], $row["label"]); - if($includesource) - printf(" %s", $row["source"]); - - print "
'; - print ''; - print '
'; - } - - // --- End functions --- - - displayPageHeader($color, 'None'); - - // Initialize addressbook - $abook = addressbook_init(); - -?> - -
- -
-
-
- -\n"; - print "\n"; - print "
\n"; - printf('
'."\n", $PHP_SELF); - print "
\n"; - printf(" %s\n", _("Search for")); - addr_insert_hidden(); - if (! isset($addrquery)) - $addrquery = ""; - printf(" \n", - htmlspecialchars($addrquery)); - - // List all backends to allow the user to choose where to search - if($abook->numbackends > 1) { - printf("%s \n"; +/** + * addrbook_search_html.php + * + * Handle addressbook searching with pure html. + * + * This file is included from compose.php + * + * @copyright © 1999-2007 The SquirrelMail Project Team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + * @version $Id$ + * @package squirrelmail + * @subpackage addressbook + */ + +/** + * Include the SquirrelMail initialization file. + * Because this file can also be included within compose we check for the $bInit + * var which is set inside ini.php. It's needed because compose already includes + * init.php. + */ +if (!isset($bInit)) { + /** This is the addrbook_search_html page */ + define('PAGE_NAME', 'addrbook_search_html'); + + include('../include/init.php'); +} + +/** SquirrelMail required files. */ +include_once(SM_PATH . 'functions/date.php'); +include_once(SM_PATH . 'functions/addressbook.php'); +include_once(SM_PATH . 'templates/util_addressbook.php'); + +sqgetGlobalVar('session', $session, SQ_POST); +sqgetGlobalVar('mailbox', $mailbox, SQ_POST); +if (! sqgetGlobalVar('query', $addrquery, SQ_POST)) + $addrquery=''; +sqgetGlobalVar('listall', $listall, SQ_POST); +sqgetGlobalVar('backend', $backend, SQ_POST); + +/** + * Insert hidden data + */ +function addr_insert_hidden() { + global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox, + $request_mdn, $request_dr, $identity, $session; + + if (substr($body, 0, 1) == "\r") { + echo addHidden('body', "\n".$body); } else { - print "\n"; + echo addHidden('body', $body); } - printf("", - _("Search")); - printf(" | \n", - _("List all")); - print '
'; - - print "
\n"; - addr_insert_hidden(); - print ""; - do_hook('addrbook_html_search_below'); - // End search form - - // Show personal addressbook - if(!isset($addrquery) || !empty($listall)) { - - if(! isset($backend) || $backend != -1 || !isset($addrquery)) { - if(!isset($addrquery)) - $backend = $abook->localbackend; - //printf("

%s

\n", $abook->backends[$backend]->sname); + echo addHidden('session', $session). + addHidden('subject', $subject). + addHidden('send_to', $send_to). + addHidden('send_to_bcc', $send_to_bcc). + addHidden('send_to_cc', $send_to_cc). + addHidden('mailprio', $mailprio). + addHidden('request_mdn', $request_mdn). + addHidden('request_dr', $request_dr). + addHidden('identity', $identity). + addHidden('mailbox', $mailbox). + addHidden('from_htmladdr_search', 'true'); +} + + +/** + * List search results + * @param array $res Array containing results of search + * @param bool $includesource If true, adds backend column to address listing + */ +function addr_display_result($res, $includesource = true) { + global $PHP_SELF, $oTemplate, $oErrorHandler; + + + echo addForm($PHP_SELF, 'post', 'addressbook'). + addHidden('html_addr_search_done', 'true'); + addr_insert_hidden(); + + $oTemplate->assign('use_js', false); + $oTemplate->assign('include_abook_name', $includesource); + $oTemplate->assign('addresses', formatAddressList($res)); + + $oTemplate->display('addrbook_search_list.tpl'); + + echo ''; +} + +/* --- End functions --- */ + +if ($compose_new_win == '1') { + compose_Header($color, $mailbox); +} +else { + displayPageHeader($color, $mailbox); +} + +/** set correct value of $default_charset */ +set_my_charset(); + +/* Initialize addressbook */ +$abook = addressbook_init(); + + +/* Search form */ +echo addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f'); +addr_insert_hidden(); +if (isset($session)) { + echo addHidden('session', $session); +} + +$oTemplate->assign('use_js', false); +$oTemplate->assign('backends', getBackends()); + +$oTemplate->display('addressbook_search_form.tpl'); + +echo "\n"; +do_hook('addrbook_html_search_below', $null); +/* End search form */ + +/* List addresses. Show personal addressbook */ +if ($addrquery == '' || ! empty($listall)) { + // TODO: recheck all conditions and simplity if statements + if (! isset($backend) || $backend != -1 || $addrquery == '') { + if ($addrquery == '' && empty($listall)) { + $backend = $abook->localbackend; + } - $res = $abook->list_addr($backend); + $res = $abook->list_addr($backend); - if(is_array($res)) { + if (is_array($res)) { + usort($res,'alistcmp'); addr_display_result($res, false); - } else { - printf("

"._("Unable to list addresses from %s"). - "

\n", $abook->backends[$backend]->sname); - } - - } else { - $res = $abook->list_addr(); - addr_display_result($res, true); - } - exit; - - } else - - // Do the search - if(!empty($addrquery) && empty($listall)) { - - if($backend == -1) { - $res = $abook->s_search($addrquery); - } else { - $res = $abook->s_search($addrquery, $backend); - } - - if(!is_array($res)) { - printf("


%s:
%s

\n\n", - _("Your search failed with the following error(s)"), - $abook->error); - } else if(sizeof($res) == 0) { - printf("


%s.

\n\n", - _("No persons matching your search was found")); - } else { - addr_display_result($res); - } - } - - if (!$addrquery || sizeof($res) == 0) { - printf('
'."\n", $PHP_SELF); - addr_insert_hidden(); - printf("\n", _("Return")); - print '
'; - print '
'; - } - -?> - + } else { + plain_error_message(_("Unable to list addresses from %s"), $abook->backends[$backend]->sname); + } + + } else { + $res = $abook->list_addr(); + usort($res,'alistcmp'); + addr_display_result($res, true); + } + $oTemplate->display('footer.tpl'); + exit; +} elseif (!empty($addrquery)) { + /* Do the search */ + if ($backend == -1) { + $res = $abook->s_search($addrquery); + } else { + $res = $abook->s_search($addrquery, $backend); + } + + if (!is_array($res)) { + plain_error_message(_("Your search failed with the following error(s)") .':
'. nl2br(htmlspecialchars($abook->error))); + } elseif (sizeof($res) == 0) { + $oTemplate->assign('note', _("No persons matching your search were found")); + $oTemplate->display('note.tpl'); + } else { + addr_display_result($res); + } +} else { + // not first time display, not listall and search is empty + // TODO: I think, this part of control structure is never reached. + plain_error_message(_("Nothing to search")); +} + +if ($addrquery == '' || sizeof($res) == 0) { + echo '
'. + addForm('compose.php','post','k'); + addr_insert_hidden(); + echo '' . "\n" . + '
'; +} + +echo '
'; + +$oTemplate->display('footer.tpl');