<?php
- /**
- ** addrbook_search.php
- **
- ** Handle addressbook searching with pure html. This file is included from compose.php
- **
- **/
-
- session_start();
-
- if (!isset($config_php))
- include("../config/config.php");
- if (!isset($strings_php))
- include("../functions/strings.php");
- if (!isset($page_header_php))
- include("../functions/page_header.php");
- if (!isset($imap_php))
- include("../functions/imap.php");
- if (!isset($date_php))
- include("../functions/date.php");
- if (!isset($mime_php))
- include("../functions/mime.php");
- if (!isset($smtp_php))
- include("../functions/smtp.php");
- if (!isset($display_messages_php))
- include("../functions/display_messages.php");
- if (!isset($addressbook_php))
- include("../functions/addressbook.php");
-
- include("../src/load_prefs.php");
-
-
- echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
- displayPageHeader($color, "None");
- //<form method=post action="compose.php?html_addr_search=true">
-
- $body = stripslashes($body);
- $send_to = stripslashes($send_to);
- $send_to_cc = stripslashes($send_to_cc);
- $send_to_bcc = stripslashes($send_to_bcc);
- $subject = stripslashes($subject);
-
- echo "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
- echo " <TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>\n";
- echo _("Address Book Search");
- echo " </TD></TR>\n";
- echo "</TABLE>\n";
-
-
- echo "<center>";
- echo "<form method=post action=\"compose.php?html_addr_search=true\">";
- echo _("Enter your search criteria:") . "<br>";
- echo " <input type=text value=\"$query\"name=query>";
- echo " <input type=submit value=Submit>";
- echo " <input type=hidden value=\"$body\" name=body>";
- echo " <input type=hidden value=\"$subject\" name=subject>";
- echo " <input type=hidden value=\"$send_to\" name=send_to>";
- echo " <input type=hidden value=\"$send_to_cc\" name=send_to_cc>";
- echo " <input type=hidden value=\"$send_to_bcc\" name=send_to_bcc>";
- echo "</form>";
- echo "</center>";
-
- if(!empty($query)) {
- $abook = addressbook_init();
- $res = $abook->s_search($query);
-
- if(!is_array($res)) {
- printf("<P ALIGN=center><BR>%s:<br>%s</P>\n</BODY></HTML>\n",
- _("Your search failed with the following error(s)"),
- $abook->error);
- exit;
- }
-
- if(sizeof($res) == 0) {
- printf("<P ALIGN=center><BR>%s.</P>\n</BODY></HTML>\n",
- _("No persons matching your search was found"));
- exit;
- }
-
- // List search results
- $line = 0;
- print "<table border=0 width=\"98%\" align=center>";
- printf("<tr bgcolor=\"$color[9]\"><TH align=left> ".
- "<TH align=left> %s<TH align=left> %s".
- "<TH align=left> %s<TH align=left width=\"10%%\">".
- " %s</tr>\n",
- _("Name"), _("E-mail"), _("Info"), _("Source"));
-
- ?>
- <form method=post action"compose.php?html_addr_search_done=true">
- <?
- echo " <input type=hidden value=\"$body\" name=body>";
- echo " <input type=hidden value=\"$subject\" name=subject>";
- echo " <input type=hidden value=\"$send_to\" name=send_to>";
- echo " <input type=hidden value=\"$send_to_cc\" name=send_to_cc>";
- echo " <input type=hidden value=\"$send_to_bcc\" name=send_to_bcc>";
-
- while(list($key, $row) = each($res)) {
- printf("<tr%s nowrap><td nowrap align=center width=\"5%%\">".
- "<input type=checkbox name=send_to_search[] value=\"%s\"> To".
- "<input type=checkbox name=send_to_cc_search[] value=\"%s\"> Cc ".
- "<td nowrap> %s <td nowrap> ".
- "%s".
- "<td nowrap> %s <td nowrap> %s</tr>\n",
- ($line % 2) ? " bgcolor=\"$color[0]\"" : "", $row["email"],
- $row["email"], $row["name"], $row["email"],
- $row["label"], $row["source"]);
- $line++;
- }
- print "</TABLE>";
- echo "<input type=hidden value=1 name=html_addr_search_done>";
- echo "<center><input type=submit name=addr_search_done value=\"Use Addresses\"></center>";
- echo "</form>";
+/**
+ * addrbook_search_html.php
+ *
+ * Handle addressbook searching with pure html.
+ *
+ * This file is included from compose.php
+ *
+ * @copyright © 1999-2006 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ * @version $Id$
+ * @package squirrelmail
+ * @subpackage addressbook
+ */
+
+/**
+ * Include the SquirrelMail initialization file.
+ * Because this file can also be included within compose we check for the $bInit
+ * var which is set inside ini.php. It's needed because compose already includes
+ * init.php.
+ */
+if (!isset($bInit)) {
+ include('../include/init.php');
+}
+
+/** SquirrelMail required files. */
+include_once(SM_PATH . 'functions/date.php');
+include_once(SM_PATH . 'functions/addressbook.php');
+include_once(SM_PATH . 'templates/util_addressbook.php');
+
+sqgetGlobalVar('session', $session, SQ_POST);
+sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
+if (! sqgetGlobalVar('query', $addrquery, SQ_POST))
+ $addrquery='';
+sqgetGlobalVar('listall', $listall, SQ_POST);
+sqgetGlobalVar('backend', $backend, SQ_POST);
+
+/**
+ * Insert hidden data
+ */
+function addr_insert_hidden() {
+ global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
+ $identity, $session;
+
+ if (substr($body, 0, 1) == "\r") {
+ echo addHidden('body', "\n".$body);
+ } else {
+ echo addHidden('body', $body);
}
+ echo addHidden('session', $session).
+ addHidden('subject', $subject).
+ addHidden('send_to', $send_to).
+ addHidden('send_to_bcc', $send_to_bcc).
+ addHidden('send_to_cc', $send_to_cc).
+ addHidden('identity', $identity).
+ addHidden('mailbox', $mailbox).
+ addHidden('from_htmladdr_search', 'true');
+}
+
+
+/**
+ * List search results
+ * @param array $res Array containing results of search
+ * @param bool $includesource If true, adds backend column to address listing
+ */
+function addr_display_result($res, $includesource = true) {
+ global $color, $PHP_SELF, $squirrelmail_language;
+
+ global $oTemplate, $oErrorHandler;
+
+ if (sizeof($res) <= 0) return;
+
+ echo addForm($PHP_SELF, 'post', 'addressbook').
+ addHidden('html_addr_search_done', 'true');
+ addr_insert_hidden();
+
+ $oTemplate->assign('use_js', false);
+ $oTemplate->assign('include_abook_name', $includesource);
+ $oTemplate->assign('addresses', formatAddressList($res));
+
+ $oTemplate->display('addrbook_search_list.tpl');
+
+ echo '</form>';
+}
+
+/* --- End functions --- */
+
+if ($compose_new_win == '1') {
+ compose_Header($color, $mailbox);
+}
+else {
+ displayPageHeader($color, $mailbox);
+}
+
+/** set correct value of $default_charset */
+global $default_charset;
+set_my_charset();
+
+/* Initialize addressbook */
+$abook = addressbook_init();
+
+
+/* Search form */
+echo addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f');
+addr_insert_hidden();
+if (isset($session)) {
+ echo addHidden('session', $session);
+}
+
+$oTemplate->assign('use_js', false);
+$oTemplate->assign('backends', getBackends());
+
+$oTemplate->display('addressbook_search_form.tpl');
+
+echo "</form>\n";
+do_hook('addrbook_html_search_below', $null);
+/* End search form */
+
+/* List addresses. Show personal addressbook */
+if ($addrquery == '' || ! empty($listall)) {
+ // TODO: recheck all conditions and simplity if statements
+ if (! isset($backend) || $backend != -1 || $addrquery == '') {
+ if ($addrquery == '' && empty($listall)) {
+ $backend = $abook->localbackend;
+ }
+
+ $res = $abook->list_addr($backend);
+
+ if (is_array($res)) {
+ usort($res,'alistcmp');
+ addr_display_result($res, false);
+ } else {
+ plain_error_message(_("Unable to list addresses from %s"), $abook->backends[$backend]->sname);
+ }
+
+ } else {
+ $res = $abook->list_addr();
+ usort($res,'alistcmp');
+ addr_display_result($res, true);
+ }
+ $oTemplate->display('footer.tpl');
+ exit;
+} elseif (!empty($addrquery)) {
+ /* Do the search */
+ if ($backend == -1) {
+ $res = $abook->s_search($addrquery);
+ } else {
+ $res = $abook->s_search($addrquery, $backend);
+ }
+
+ if (!is_array($res)) {
+ plain_error_message(_("Your search failed with the following error(s)") .':<br />'. nl2br(htmlspecialchars($abook->error)));
+ } elseif (sizeof($res) == 0) {
+ $oTemplate->assign('note', _("No persons matching your search were found"));
+ $oTemplate->display('note.tpl');
+ } else {
+ addr_display_result($res);
+ }
+} else {
+ // not first time display, not listall and search is empty
+ // TODO: I think, this part of control structure is never reached.
+ plain_error_message(_("Nothing to search"));
+}
+
+if ($addrquery == '' || sizeof($res) == 0) {
+ echo '<div style="text-align: center;">'.
+ addForm('compose.php','post','k');
+ addr_insert_hidden();
+ echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
+ '</form></div></nobr>';
+}
+
+echo '<hr />';
+
+$oTemplate->display('footer.tpl');
?>