X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Faddrbook_search.php;h=cfbe3ba8b6c296026aad418691ccefd89ca84794;hb=6a2f68354009082148e09f5c82a29d1b17f69190;hp=2adb5ad5a1802616fb0c749af59e9b04912c5ded;hpb=00a065a69448f66db8f29fda00961878926a5912;p=squirrelmail.git diff --git a/src/addrbook_search.php b/src/addrbook_search.php index 2adb5ad5..cfbe3ba8 100644 --- a/src/addrbook_search.php +++ b/src/addrbook_search.php @@ -1,202 +1,99 @@ - -assign('use_js', true); + $oTemplate->assign('include_abook_name', $includesource); + $oTemplate->assign('addresses', formatAddressList($res)); + + $oTemplate->display('addrbook_search_list.tpl'); +} +/* ================= End of functions ================= */ -/* List search results */ -function display_result($res, $includesource = true) { - global $color; - - if(sizeof($res) <= 0) return; - - insert_javascript(); - - $line = 0; - echo '' . - '\n"; - - while (list($undef, $row) = each($res)) { - echo '\n"; - $line++; - } - echo '
 ' . - ' ' . _("Name") . - ' ' . _("E-mail") . - ' ' . _("Info"); - - if ($includesource) { - echo ' ' . _("Source"); - } - echo "
' . - 'To | " . - 'Cc | " . - 'Bcc" . - ' ' . - $row['name'] . ' ' . - ' " . $row['email'] . ' ' . - ' ' . $row['label'] . ' '; - if ($includesource) { - echo ' ' . $row['source']; - } +/** lets get the global vars we may need */ - echo "
'; +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 = ''; } -/* ================= 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"; -} +echo "\n"; + +/** set correct value of $default_charset */ +global $default_charset; +set_my_charset(); /* Empty search */ -if (empty($query) && empty($show) && empty($listall)) { - echo '


' . - _("No persons matching your search was found") . - "

\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 */ -$abook = addressbook_init(); - -/* Create search form */ -if ($show == 'form') { - echo '
' . "\n" . - '' . - '
' . "\n" . - ' ' . _("Search for") . "\n" . - ' \n"; - - /* List all backends to allow the user to choose where to search */ - if ($abook->numbackends > 1) { - echo '' . _("in") . ' \n"; - } else { - echo '' . "\n"; - } - - echo '' . - ' | ' . "\n" . - '' . "\n" . - '' . "\n" . - '
' . "\n"; -} else { +/* Initialize addressbook, show init errors only in bottom frame */ +$showerr=($show=='form' ? false : true); +$abook = addressbook_init($showerr); - /* Show personal addressbook */ - if ($show == 'blank' || !empty($listall)) { +/* Create search form (top frame) */ +if ($show == 'form' && ! isset($listall)) { + echo "
\n"; + + $oTemplate->assign('use_js', true); + $oTemplate->assign('backends', getBackends()); + $oTemplate->display('addressbook_search_form.tpl'); + + 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') { @@ -205,49 +102,42 @@ if ($show == 'form') { $res = $abook->list_addr($backend); if(is_array($res)) { + usort($res,'alistcmp'); display_result($res, false); } else { - echo '

' . - sprintf(_("Unable to list addresses from %s"), - $abook->backends[$backend]->sname) . - '

' . "\n"; + plain_error_message(sprintf(_("Unable to list addresses from %s"), $abook->backends[$backend]->sname)); } } else { $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)) { - echo '


' . - _("Your search failed with the following error(s)") . - ':
' . $abook->error . "

\n\n"; - exit; - } - - if (sizeof($res) == 0) { - echo '


' . - _("No persons matching your search was found") . - ".

\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")); } - } -echo "\n"; - -?> +$oTemplate->display('footer.tpl'); +?> \ No newline at end of file