X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Faddrbook_search.php;h=89143a808bad4c006201a5bcca985a8e04e249bd;hb=a11df61b949068712242d77e2c18311c93e63979;hp=55dc5cae61b509b4a694783bcdee8e52f06bf408;hpb=10455998ff36ac23c25799914656fd4f13c14b6f;p=squirrelmail.git diff --git a/src/addrbook_search.php b/src/addrbook_search.php index 55dc5cae..89143a80 100644 --- a/src/addrbook_search.php +++ b/src/addrbook_search.php @@ -1,266 +1,296 @@ - +"; - printf(" ". - " %s %s". - " %s", - _("Name"), _("E-mail"), _("Info")); - if($includesource) - printf(" %s", _("Source")); +/* List search results */ +function display_result($res, $includesource = true) { + global $color; + + if(sizeof($res) <= 0) return; + + insert_javascript(); + + $line = 0; + echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) . + html_tag( 'tr', '', '', $color[9] ) . + html_tag( 'th', ' ', 'left' ) . + html_tag( 'th', ' ' . _("Name"), 'left' ) . + html_tag( 'th', ' ' . _("E-mail"), 'left' ) . + html_tag( 'th', ' ' . _("Info"), 'left' ); + + if ($includesource) { + echo html_tag( 'th', ' ' . _("Source"), 'left', 'width="10%"' ); + } + echo "\n"; + + while (list($undef, $row) = each($res)) { + $tr_bgcolor = ''; + $email = htmlspecialchars(addcslashes(AddressBook::full_address($row), "'"), ENT_QUOTES); + if ($line % 2) { $tr_bgcolor = $color[0]; } + echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) . + html_tag( 'td', + 'To | " . + 'Cc | " . + 'Bcc", + 'center', '', 'valign="top" width="5%" nowrap' ) . + html_tag( 'td', ' ' . htmlspecialchars($row['name']), 'left', '', 'valign="top" nowrap' ) . + html_tag( 'td', ' ' . + '" . htmlspecialchars($row['email']) . '' + , 'left', '', 'valign="top"' ) . + html_tag( 'td', htmlspecialchars($row['label']), 'left', '', 'valign="top" nowrap' ); + if ($includesource) { + echo html_tag( 'td', ' ' . $row['source'], 'left', '', 'valign="top" nowrap' ); + } + + echo "\n"; + $line++; + } + echo ''; +} - 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"]); +/* ================= End of functions ================= */ + +require_once('../functions/strings.php'); +require_once('../functions/addressbook.php'); + +displayHtmlHeader(); + +/* Initialize vars */ +if (!isset($query)) { $query = ''; } +if (!isset($show)) { $show = ''; } +if (!isset($backend)) { $backend = ''; } + +/* Choose correct colors for top and bottom frame */ +if ($show == 'form' && !isset($listall)) { + echo ''; +} else { + echo '\n"; +} - if($includesource) - printf(" %s", $row["source"]); +/* Empty search */ +if (empty($query) && empty($show) && empty($listall)) { + echo html_tag( 'p', '
' . + _("No persons matching your search was found"), + 'center' ) . + "\n\n", + exit; +} - print "\n"; - $line++; - } - print ""; - } +/* Initialize addressbook */ +$abook = addressbook_init(); + +/* Create search form */ +if ($show == 'form' && empty($listall)) { + echo '
' . "\n" . + html_tag( 'table', '', '', '', 'border="0" width="100%" height="100%"' ) . + html_tag( 'tr' ) . + html_tag( 'td', ' ' . _("Search for") . "\n", 'left', '', 'nowrap valign="middle" width="10%"' ) . + html_tag( 'td', '', 'left', '', '' ) . + '\n"; + + /* List all backends to allow the user to choose where to search */ + if ($abook->numbackends > 1) { + echo '' . _("in") . ' \n"; + } else { + echo '' . "\n"; + } + + echo '' . + html_tag( 'tr', + html_tag( 'td', '', 'left' ) . + html_tag( 'td', + '' . + ' | ' . "\n" . + ' | ' . "\n" , + 'left' ) + ) . + '
' . "\n"; +} else { + + /* Show personal addressbook */ + if ($show == 'blank' && empty($listall)) { + + if($backend != -1 || $show == 'blank') { + if ($show == 'blank') { + $backend = $abook->localbackend; + } + $res = $abook->list_addr($backend); + + if(is_array($res)) { + usort($res,'alistcmp'); + display_result($res, false); + } else { + echo html_tag( 'p', '' . + sprintf(_("Unable to list addresses from %s"), + $abook->backends[$backend]->sname) . '' , + 'center' ) . "\n"; + } + } else { + $res = $abook->list_addr(); + usort($res,'alistcmp'); + display_result($res, true); + } - /* ================= End of functions ================= */ + } else { + if( !empty( $listall ) ){ + $query = '*'; + } + + /* Do the search */ + if (!empty($query)) { + + if($backend == -1) { + $res = $abook->s_search($query); + } else { + $res = $abook->s_search($query, $backend); + } + + if (!is_array($res)) { + echo html_tag( 'p', '
' . + _("Your search failed with the following error(s)") . + ':
' . $abook->error . "
\n" , + 'center' ) . + "\n\n"; + exit; + } + + if (sizeof($res) == 0) { + echo html_tag( 'p', '
' . + _("No persons matching your search was found") . "\n" , + 'center' ) . + "\n\n"; + exit; + } + + display_result($res); + } + } + +} - session_start(); +echo "\n"; - if (!isset($i18n_php)) - include("../functions/i18n.php"); - - if(!isset($logged_in) || !isset($username) || !isset($key)) { - include ("../themes/default_theme.php"); - include ("../functions/display_messages.php"); - printf('', - $color[8], $color[4], $color[7], $color[7], $color[7]); - plain_error_message(_("You need a valid user and password to access this page!") - . "
" - . _("Click here to log back in.") . ".", $color); - echo ""; - exit; - } - if (!isset($config_php)) - include("../config/config.php"); - if (!isset($array_php)) - include("../functions/array.php"); - if (!isset($auth_php)) - include("../functions/auth.php"); - if (!isset($strings_php)) - include("../functions/strings.php"); - if (!isset($page_header_php)) - include("../functions/page_header.php"); - if (!isset($addressbook_php)) - include("../functions/addressbook.php"); - - is_logged_in(); - include("../src/load_prefs.php"); - - displayHtmlHeader(); - - // 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); - printf(""); - printf("
\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 { - printf("\n"); - } - - printf("", - _("Search")); - printf(" | \n", - _("List all")); - printf("\n"); - printf("\n", - _("Close window")); - printf("
\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) && empty($listall)) { - - if($backend == -1) { - $res = $abook->s_search($query); - } else { - $res = $abook->s_search($query, $backend); - } - - if(!is_array($res)) { - printf("


%s:
%s

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


%s.

\n\n", - _("No persons matching your search was found")); - exit; - } - - display_result($res); - } ?> - -