6 * Handle addressbook searching in the popup window.
8 * NOTE: A lot of this code is similar to the code in
9 * addrbook_search_html.html -- If you change one,
10 * change the other one too!
12 * @copyright © 1999-2006 The SquirrelMail Project Team
13 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
15 * @package squirrelmail
16 * @subpackage addressbook
20 * Include the SquirrelMail initialization file.
22 require('../include/init.php');
24 include_once(SM_PATH
. 'functions/forms.php');
25 include_once(SM_PATH
. 'functions/addressbook.php');
28 * Function to include JavaScript code
31 function insert_javascript() {
33 <script type
="text/javascript"><!--
35 function to_and_close($addr) {
40 function to_address($addr) {
42 var pwintype
= typeof parent
.opener
.document
.compose
;
44 $addr = $addr.replace(/ {1,35}$
/, "");
46 if (pwintype
!= "undefined") {
47 if (parent
.opener
.document
.compose
.send_to
.value
) {
49 parent
.opener
.document
.compose
.send_to
.value
=
50 parent
.opener
.document
.compose
.send_to
.value +
", " +
$addr;
52 parent
.opener
.document
.compose
.send_to
.value
= $addr;
57 function cc_address($addr) {
59 var pwintype
= typeof parent
.opener
.document
.compose
;
61 $addr = $addr.replace(/ {1,35}$
/, "");
63 if (pwintype
!= "undefined") {
64 if (parent
.opener
.document
.compose
.send_to_cc
.value
) {
66 parent
.opener
.document
.compose
.send_to_cc
.value
=
67 parent
.opener
.document
.compose
.send_to_cc
.value +
", " +
$addr;
69 parent
.opener
.document
.compose
.send_to_cc
.value
= $addr;
74 function bcc_address($addr) {
76 var pwintype
= typeof parent
.opener
.document
.compose
;
78 $addr = $addr.replace(/ {1,35}$
/, "");
80 if (pwintype
!= "undefined") {
81 if (parent
.opener
.document
.compose
.send_to_bcc
.value
) {
83 parent
.opener
.document
.compose
.send_to_bcc
.value
=
84 parent
.opener
.document
.compose
.send_to_bcc
.value +
", " +
$addr;
86 parent
.opener
.document
.compose
.send_to_bcc
.value
= $addr;
93 } /* End of included JavaScript */
98 * @param array $res Array of search results
99 * @param bool $includesource [Default=true]
102 function display_result($res, $includesource = true) {
105 if(sizeof($res) <= 0) return;
110 echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
111 html_tag( 'tr', '', '', $color[9] ) .
112 html_tag( 'th', ' ', 'left' ) .
113 html_tag( 'th', ' ' . _("Name"), 'left' ) .
114 html_tag( 'th', ' ' . _("E-mail"), 'left' ) .
115 html_tag( 'th', ' ' . _("Info"), 'left' );
117 if ($includesource) {
118 echo html_tag( 'th', ' ' . _("Source"), 'left', '', 'width="10%"' );
122 while (list($undef, $row) = each($res)) {
123 $email = htmlspecialchars(addcslashes(AddressBook
::full_address($row), "'"), ENT_QUOTES
);
125 $tr_bgcolor = $color[12];
127 $tr_bgcolor = $color[4];
129 echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) .
131 '<small><a href="javascript:to_address(' .
132 "'" . $email . "');\">"._("To")."</a> | " .
133 '<a href="javascript:cc_address(' .
134 "'" . $email . "');\">"._("Cc")."</a> | " .
135 '<a href="javascript:bcc_address(' .
136 "'" . $email . "');\">"._("Bcc")."</a></small>",
137 'center', '', 'valign="top" width="5%" style="white-space: nowrap;"' ) .
138 html_tag( 'td', ' ' . htmlspecialchars($row['name']), 'left', '', 'valign="top" style="white-space: nowrap;"' ) .
139 html_tag( 'td', ' ' .
140 '<a href="javascript:to_and_close(' .
141 "'" . $email . "');\">" . htmlspecialchars($row['email']) . '</a>'
142 , 'left', '', 'valign="top"' ) .
143 html_tag( 'td', htmlspecialchars($row['label']), 'left', '', 'valign="top" style="white-space: nowrap;"' );
144 if ($includesource) {
145 echo html_tag( 'td', ' ' . $row['source'], 'left', '', 'valign="top" style="white-space: nowrap;"' );
154 /* ================= End of functions ================= */
156 /** lets get the global vars we may need */
157 sqgetGlobalVar('key', $key, SQ_COOKIE
);
158 sqgetGlobalVar('username', $username, SQ_SESSION
);
159 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
160 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
162 if (! sqgetGlobalVar('show' , $show)) {
165 if (! sqgetGlobalVar('query', $query, SQ_POST
)) {
168 if (! sqgetGlobalVar('listall', $listall, SQ_POST
)) {
171 if (! sqgetGlobalVar('backend', $backend, SQ_POST
)) {
177 /** set correct value of $default_charset */
178 global $default_charset;
181 /* Choose correct colors for top and bottom frame */
182 if ($show == 'form' && !isset($listall)) {
183 echo '<body text="' . $color[6] . '" bgcolor="' . $color[3] . '" ' .
184 'link="' . $color[6] . '" vlink="' . $color[6] . '" ' .
185 'alink="' . $color[6] . '" ' .
186 'OnLoad="document.sform.query.focus();">';
188 echo '<body text="' . $color[8] . '" bgcolor="' . $color[4] . '" ' .
189 'link="' . $color[7] . '" vlink="' . $color[7] . '" ' .
190 'alink="' . $color[7] . "\">\n";
194 if (empty($query) && empty($show) && !isset($listall)) {
195 echo html_tag( 'p', '<br />' .
196 _("No persons matching your search were found"),
198 "\n</body></html>\n";
202 /* Initialize addressbook, show init errors only in bottom frame */
203 $showerr=($show=='form' ?
false : true);
204 $abook = addressbook_init($showerr);
206 /* Create search form (top frame) */
207 if ($show == 'form' && ! isset($listall)) {
208 echo '<form name="sform" target="abookres" action="addrbook_search.php'.
209 '" method="post">' . "\n" .
210 html_tag( 'table', '', '', '', 'border="0" width="100%" height="100%"' ) .
212 html_tag( 'td', ' <strong><label for="query">' . _("Search for") .
213 "</label></strong>\n", 'left', '',
214 'style="white-space: nowrap;" valign="middle" width="10%"' ) .
215 html_tag( 'td', '', 'left', '', '' ) .
216 addInput('query', $query, 28);
218 /* List all backends to allow the user to choose where to search */
219 if ($abook->numbackends
> 1) {
220 echo '<strong><label for="backend">' . _("in") . '</label></strong> '."\n";
222 $selopts['-1'] = _("All address books");
224 $ret = $abook->get_backend_list();
225 while (list($undef,$v) = each($ret)) {
226 $selopts[$v->bnum
] = $v->sname
;
228 echo addSelect('backend', $selopts, '-1', TRUE);
230 echo addHidden('backend', '-1');
235 html_tag( 'td', '', 'left' ) .
237 '<input type="submit" value="' . _("Search") . '" name="show" />' .
238 ' | <input type="submit" value="' . _("List all") .
239 '" name="listall" />' . "\n" .
240 ' | <input type="button" value="' . _("Close") .
241 '" onclick="parent.close();" />' . "\n" ,
244 '</table></form>' . "\n";
247 * List addresses (bottom frame)
248 * If listall is set, list all entries in selected backend.
249 * If $show is 'blank' (initial call of address book popup) - list
250 * personal address book.
252 if ($show == 'blank' ||
isset($listall)) {
254 if($backend != -1 ||
$show == 'blank') {
255 if ($show == 'blank') {
256 $backend = $abook->localbackend
;
258 $res = $abook->list_addr($backend);
261 usort($res,'alistcmp');
262 display_result($res, false);
264 echo html_tag( 'p', '<strong>' .
265 sprintf(_("Unable to list addresses from %s"),
266 $abook->backends
[$backend]->sname
) . '</strong>' ,
270 $res = $abook->list_addr();
271 usort($res,'alistcmp');
272 display_result($res, true);
275 } elseif (!empty($query)) {
276 /* Do the search (listall is not set. query is set.)*/
279 $res = $abook->s_search($query);
281 $res = $abook->s_search($query, $backend);
284 if (!is_array($res)) {
285 echo html_tag( 'p', '<b><br />' .
286 _("Your search failed with the following error(s)") .
287 ':<br />' . nl2br(htmlspecialchars($abook->error
)) . "</b>\n" ,
289 } elseif (sizeof($res) == 0) {
290 echo html_tag( 'p', '<br /><b>' .
291 _("No persons matching your search were found") . "</b>\n" ,
294 display_result($res);
298 * listall is not set, query is not set or empty.
299 * User hit search button without entering search expression.
301 echo html_tag( 'p', '<br /><b>' . _("Nothing to search") . "</b>\n",'center' );
304 $oTemplate->display('footer.tpl');