X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=src%2Faddrbook_search.php;h=7e2672003d13a49b63283649d77b083c6c25396d;hp=a1c0b7be3b7df331a15a80e058e9d4d3539e9503;hb=1a4bc4a62fa812d0e0fa8fd48ea804e045bab040;hpb=6dda64534206bf0aa35c57e826605573809176e7 diff --git a/src/addrbook_search.php b/src/addrbook_search.php index a1c0b7be..7e267200 100644 --- a/src/addrbook_search.php +++ b/src/addrbook_search.php @@ -1,114 +1,31 @@ - -\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 ''; + $oTemplate->assign('compose_addr_pop', true); + $oTemplate->assign('include_abook_name', $includesource); + $oTemplate->assign('addresses', formatAddressList($res)); + + $oTemplate->display('addrbook_search_list.tpl'); } /* ================= End of functions ================= */ -require_once('../functions/strings.php'); -require_once('../functions/addressbook.php'); +/** lets get the global vars we may need */ + +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 = ''; +} displayHtmlHeader(); +echo "\n"; /** set correct value of $default_charset */ -global $default_charset; set_my_charset(); -/* 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"; -} - /* Empty search */ -if (empty($query) && empty($show) && empty($listall)) { - echo html_tag( 'p', '
' . - _("No persons matching your search were found"), - 'center' ) . - "\n\n"; - exit; +if (empty($query) && empty($show) && !isset($listall)) { + $oTemplate->assign('note', htmlspecialchars(_("No persons matching your search were found"))); + $oTemplate->display('note.tpl'); +# exit; } /* Initialize addressbook, show init errors only in bottom frame */ $showerr=($show=='form' ? false : true); $abook = addressbook_init($showerr); -/* 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', '', '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 '' . _("in") . ' '."\n". - $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 { - echo addHidden('backend', '-1'); - } - - echo '' . - html_tag( 'tr', - html_tag( 'td', '', 'left' ) . - html_tag( 'td', - '' . - ' | ' . "\n" . - ' | ' . "\n" , - 'left' ) - ) . - '
' . "\n"; +/* Create search form (top frame) */ +if ($show == 'form' && ! isset($listall)) { + echo "
\n"; + + $oTemplate->assign('compose_addr_pop', true); + $oTemplate->assign('backends', getBackends()); + $oTemplate->display('addressbook_search_form.tpl'); + + echo "
\n"; } else { - - /* Show personal addressbook */ - if ($show == 'blank' && empty($listall)) { + /** + * 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') { @@ -260,10 +107,7 @@ if ($show == 'form' && empty($listall)) { 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"; + plain_error_message(sprintf(_("Unable to list addresses from %s"), $abook->backends[$backend]->sname)); } } else { $res = $abook->list_addr(); @@ -271,41 +115,30 @@ if ($show == 'form' && empty($listall)) { display_result($res, true); } - } 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; - } + } elseif (!empty($query)) { + /* Do the search (listall is not set. query is set.)*/ - if (sizeof($res) == 0) { - echo html_tag( 'p', '
' . - _("No persons matching your search were found") . "\n" , - 'center' ) . - "\n\n"; - exit; - } + if($backend == -1) { + $res = $abook->s_search($query); + } else { + $res = $abook->s_search($query, $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 { 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")); } - } -?> - \ No newline at end of file + +$oTemplate->display('footer.tpl');