X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=src%2Faddrbook_search.php;h=372bbdf64fb3ab843927048dc071c8ea5427d880;hp=9557065cf1f74af43075cf0a90a5c0c613912141;hb=d72549cb90b0473f1d7a99e796ede80dac1b1ec3;hpb=9487c2ff3a9d36af3dc93bd231a6f85fe7a6f762 diff --git a/src/addrbook_search.php b/src/addrbook_search.php index 9557065c..372bbdf6 100644 --- a/src/addrbook_search.php +++ b/src/addrbook_search.php @@ -1,244 +1,144 @@ - +/* Initialize addressbook, show init errors only in bottom frame */ +$showerr=($show=='form' ? false : true); +$abook = addressbook_init($showerr); -'; - printf(" ". - " %s %s". - " %s", - _("Name"), _("E-mail"), _("Info")); - - if($includesource) - printf(" %s", _("Source")); - - echo "\n"; +/* Create search form (top frame) */ +if ($show == 'form' && ! isset($listall)) { + echo "
\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"]); + $oTemplate->assign('compose_addr_pop', true); + $oTemplate->assign('backends', getBackends()); + $oTemplate->display('addressbook_search_form.tpl'); - if($includesource) - printf(" %s", $row["source"]); - - echo "\n"; - $line++; - } - echo ''; - } - - /* ================= End of functions ================= */ - - require_once('../functions/array.php'); - require_once('../functions/strings.php'); - require_once('../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') { - echo "\n"; - echo ''; - echo "
\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)) { + echo "\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') + if ($show == 'blank') { $backend = $abook->localbackend; - + } $res = $abook->list_addr($backend); if(is_array($res)) { + usort($res,'alistcmp'); display_result($res, false); } else { - printf("

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

\n", $abook->backends[$backend]->sname); + plain_error_message(sprintf(_("Unable to list addresses from %s"), $abook->backends[$backend]->sname)); } - } else { - $res = $abook->list_addr(); - display_result($res, true); + $res = $abook->list_addr(); + usort($res,'alistcmp'); + display_result($res, true); } - } else + } elseif (!empty($query)) { + /* Do the search (listall is not set. query is set.)*/ - // 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; + + if (!is_array($res)) { + plain_error_message( _("Your search failed with the following error(s)") .':
'. nl2br(sm_encode_html_special_chars($abook->error)) ); + } elseif (sizeof($res) == 0) { + $oTemplate->assign('note', _("No persons matching your search were found")); + $oTemplate->display('note.tpl'); + } else { + display_result($res); } - - display_result($res); + } else { + /** + * listall is not set, query is not set or empty. + * User hit search button without entering search expression. + */ + plain_error_message(_("Nothing to search")); } - - echo "\n"; - -?> \ No newline at end of file +} + +$oTemplate->display('footer.tpl');