X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Faddrbook_search.php;h=843303cc9e5815503b5b015bb85d7fa7151d143b;hb=190dc452bedb05364a6f5842142b5e484995b1ca;hp=fd814e6c7555049afe4c4d313baedcd7d518398d;hpb=a4fe507d376dc9bcb3337e8007441b0af706017f;p=squirrelmail.git diff --git a/src/addrbook_search.php b/src/addrbook_search.php index fd814e6c..843303cc 100644 --- a/src/addrbook_search.php +++ b/src/addrbook_search.php @@ -1,258 +1,305 @@ - +\n"; + + while (list($undef, $row) = each($res)) { + $email = htmlspecialchars(addcslashes(AddressBook::full_address($row), "'"), ENT_QUOTES); + if ($line % 2) { + $tr_bgcolor = $color[12]; + } else { + $tr_bgcolor = $color[4]; + } + echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) . + html_tag( 'td', + '"._("To")." | " . + '"._("Cc")." | " . + '"._("Bcc")."", + 'center', '', 'valign="top" width="5%" style="white-space: nowrap;"' ) . + html_tag( 'td', ' ' . htmlspecialchars($row['name']), 'left', '', 'valign="top" style="white-space: nowrap;"' ) . + html_tag( 'td', ' ' . + '" . htmlspecialchars($row['email']) . '' + , 'left', '', 'valign="top"' ) . + html_tag( 'td', htmlspecialchars($row['label']), 'left', '', 'valign="top" style="white-space: nowrap;"' ); + if ($includesource) { + echo html_tag( 'td', ' ' . $row['source'], 'left', '', 'valign="top" style="white-space: nowrap;"' ); + } + + echo "\n"; + $line++; } - } + echo ''; +} + +/* ================= End of functions ================= */ + +/** 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); + +if (! sqgetGlobalVar('show' , $show)) { + $show = ''; +} +if (! sqgetGlobalVar('query', $query, SQ_POST)) { + $query = ''; +} +if (! sqgetGlobalVar('listall', $listall, SQ_POST)) { + unset($listall); +} +if (! sqgetGlobalVar('backend', $backend, SQ_POST)) { + $backend = ''; } -function cc_address($addr) { - var prefix = ""; - var pwintype = typeof parent.opener.document.compose; +displayHtmlHeader(); + +/** set correct value of $default_charset */ +global $default_charset; +set_my_charset(); + +/* Choose correct colors for top and bottom frame */ +if ($show == 'form' && !isset($listall)) { + echo ''; +} else { + echo '\n"; +} - $addr = $addr.replace(/ {1,35}$/, ""); +/* Empty search */ +if (empty($query) && empty($show) && !isset($listall)) { + echo html_tag( 'p', '
' . + _("No persons matching your search were found"), + 'center' ) . + "\n\n"; + exit; +} - if(pwintype != "undefined" ) { - if ( parent.opener.document.compose.send_to_cc.value ) { - prefix = ", "; - parent.opener.document.compose.send_to_cc.value = - parent.opener.document.compose.send_to_cc.value + ", " + $addr; +/* Initialize addressbook, show init errors only in bottom frame */ +$showerr=($show=='form' ? false : true); +$abook = addressbook_init($showerr); + +/* Create search form (top frame) */ +if ($show == 'form' && ! isset($listall)) { + echo '
' . "\n" . + html_tag( 'table', '', '', '', 'border="0" width="100%" height="100%"' ) . + html_tag( 'tr' ) . + html_tag( 'td', ' \n", 'left', '', + 'style="white-space: nowrap;" valign="middle" width="10%"' ) . + html_tag( 'td', '', 'left', '', '' ) . + addInput('query', $query, 28); + + /* List all backends to allow the user to choose where to search */ + if ($abook->numbackends > 1) { + echo ' '."\n"; + $selopts = array(); + $selopts['-1'] = _("All address books"); + + $ret = $abook->get_backend_list(); + while (list($undef,$v) = each($ret)) { + $selopts[$v->bnum] = $v->sname; + } + echo addSelect('backend', $selopts, '-1', TRUE); } else { - parent.opener.document.compose.send_to_cc.value = $addr; + echo addHidden('backend', '-1'); } - } -} -function bcc_address($addr) { - var prefix = ""; - var pwintype = typeof parent.opener.document.compose; - - $addr = $addr.replace(/ {1,35}$/, ""); - - if(pwintype != "undefined" ) { - if ( parent.opener.document.compose.send_to_bcc.value ) { - prefix = ", "; - parent.opener.document.compose.send_to_bcc.value = - parent.opener.document.compose.send_to_bcc.value + ", " + $addr; + echo '' . + html_tag( 'tr', + html_tag( 'td', '', 'left' ) . + html_tag( 'td', + '' . + ' | ' . "\n" . + ' | ' . "\n" , + 'left' ) + ) . + '
' . "\n"; +} else { + /** + * List addresses (bottom frame) + * If listall is set, list all entries in selected backend. + * If $show is 'blank' (initial call of address book popup) - list + * personal address book. + */ + if ($show == 'blank' || isset($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); + } + + } elseif (!empty($query)) { + /* Do the search (listall is not set. query is set.)*/ + + 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)") . + ':
' . nl2br(htmlspecialchars($abook->error)) . "
\n" , + 'center' ); + } elseif (sizeof($res) == 0) { + echo html_tag( 'p', '
' . + _("No persons matching your search were found") . "\n" , + 'center' ); + } else { + display_result($res); + } } else { - parent.opener.document.compose.send_to_bcc.value = $addr; + /** + * listall is not set, query is not set or empty. + * User hit search button without entering search expression. + */ + echo html_tag( 'p', '
' . _("Nothing to search") . "\n",'center' ); } - } } - -// --> - -"; - printf(" ". - " %s %s". - " %s", - _("Name"), _("E-mail"), _("Info")); - - if($includesource) - printf(" %s", _("Source")); - - print "\n"; - - while(list($key, $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 ================= */ - - session_start(); - - 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); - - 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); - } +$oTemplate->display('footer.tpl'); ?> - -