X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Faddrbook_search.php;h=6c42aa1804c2b36fc74da7d8e893bad2384f5e99;hb=c45c3f60f4ff4c2140e1183177f587d8dedfd71b;hp=d67bd619d025ceef9ecbbe0afeae2681a5901e78;hpb=138f26f6e7092a59ebac3ead587bb6a9b0d28ad3;p=squirrelmail.git diff --git a/src/addrbook_search.php b/src/addrbook_search.php index d67bd619..6c42aa18 100644 --- a/src/addrbook_search.php +++ b/src/addrbook_search.php @@ -2,99 +2,42 @@ /** ** addrbook_search.php ** + ** Copyright (c) 1999-2000 The SquirrelMail development team + ** Licensed under the GNU GPL. For full terms see the file COPYING. + ** ** Handle addressbook searching in the popup window. ** + ** NOTE: A lot of this code is similar to the code in + ** addrbook_search_html.html -- If you change one, + ** change the other one too! + ** + ** $Id$ **/ - if(!isset($logged_in)) { - echo _("You must login first."); - exit; - } - if(!isset($username) || !isset($key)) { - echo _("You need a valid user and password to access this page!"); - exit; - } - - if (!isset($config_php)) - include("../config/config.php"); - if (!isset($array_php)) - include("../functions/array.php"); - if (!isset($strings_php)) - include("../functions/strings.php"); - if (!isset($imap_php)) - include("../functions/imap.php"); - if (!isset($page_header_php)) - include("../functions/page_header.php"); - if (!isset($addressbook_php)) - include("../functions/addressbook.php"); - - // Authenticate user and load prefs - $imapConnection = sqimap_login($username, $key, - $imapServerAddress, $imapPort, 10); - include("../src/load_prefs.php"); - sqimap_logout ($imapConnection); - -?> - - - - -<?php - printf("%s: %s", $org_title, _("Address Book")); -?> - - -"; - } else { - echo "\n"; - } - - // Just make a blank page and exit - if(($show == "blank") || (empty($query) && empty($show))) { - printf("


%s

\n\n", - _("Search results will display here")); - exit; - } - - // Create search form - if($show == "form") { - printf("
\n", - $PHP_SELF); - printf(""); - printf("
\n"); - printf(" %s:\n\n", - _("Search for")); - printf(" \n", - htmlspecialchars($query)); - printf("\n"); - printf(" ", - _("Search")); - printf("\n"); - printf("\n", - _("Close window")); - printf("
\n"); - } + include("../src/validate.php"); - // Include JavaScript code if this is search results - if(!empty($query)) { + // Function to include JavaScript code + function insert_javascript() { ?> '; + printf(" ". + " %s %s". + " %s", + _("Name"), _("E-mail"), _("Info")); + + if($includesource) + printf(" %s", _("Source")); + + print "\n"; + + while(list($undef, $row) = each($res)) { + printf("". + "To | ". + "Cc | ". + "Bcc". + " %s ". + " %s ". + " %s ", + ($line % 2) ? " bgcolor=\"$color[0]\"" : "", + $row["email"], $row["email"], $row["email"], + $row["name"], $row["email"], $row["email"], + $row["label"]); + + if($includesource) + printf(" %s", $row["source"]); + + print "\n"; + $line++; + } + print ''; + } + + /* ================= End of functions ================= */ + + include('../functions/array.php'); + include('../functions/strings.php'); + include('../functions/addressbook.php'); + + displayHtmlHeader(); + + // Initialize vars + if(!isset($query)) $query = ""; + if(!isset($show)) $show = ""; + + // Choose correct colors for top and bottom frame + if($show == 'form') { + echo "'; + } else { + echo "\n"; + } + + // Empty search + if(empty($query) && empty($show) && empty($listall)) { + printf("


%s

\n\n", + _("No persons matching your search was found")); + exit; + } + + // Initialize addressbook + $abook = addressbook_init(); + + // Create search form + if($show == 'form') { + printf("
\n", + $PHP_SELF); + print(''); + print("
\n"); + printf(" %s\n", _("Search for")); + printf(" \n", + htmlspecialchars($query)); + + // List all backends to allow the user to choose where to search + if($abook->numbackends > 1) { + printf("%s \n"; + } else { + print "\n"; + } + + printf("", + _("Search")); + printf(" | \n", + _("List all")); + print "\n"; + printf("\n", + _("Close window")); + print "
\n"; + } else + + // Show personal addressbook + if($show == 'blank' || !empty($listall)) { + + if($backend != -1 || $show == 'blank') { + if($show == 'blank') + $backend = $abook->localbackend; + + //printf("

%s

\n", $abook->backends[$backend]->sname); + + $res = $abook->list_addr($backend); + + if(is_array($res)) { + display_result($res, false); + } else { + printf("

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

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


%s.

\n\n", - _("No persons matching your search was found")); + printf("


%s:
%s

\n\n", + _("Your search failed with the following error(s)"), + $abook->error); exit; } - // List search results - $line = 0; - print ""; - print "\n"; - - while(list($key, $row) = each($res)) { - printf("\n", - ($line % 2) ? " bgcolor=\"$color[0]\"" : "", $row["email"], - $row["email"], $row["name"], $row["email"], $row["label"], - $row["source"]); - $line++; + if(sizeof($res) == 0) { + printf("


%s.

\n\n", + _("No persons matching your search was found")); + exit; } - print "
 NameE-mailInfoSource
To | Cc%s %s %s %s
"; + + display_result($res); } ?>