PageRenderTime 127ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1_0_4/squirrelmail/src/addrbook_search.php

#
PHP | 274 lines | 197 code | 50 blank | 27 comment | 58 complexity | 56430ef3fc5d34d98c37284e38d58cc1 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?php
  2. /**
  3. ** addrbook_search.php
  4. **
  5. ** Copyright (c) 1999-2000 The SquirrelMail development team
  6. ** Licensed under the GNU GPL. For full terms see the file COPYING.
  7. **
  8. ** Handle addressbook searching in the popup window.
  9. **
  10. ** NOTE: A lot of this code is similar to the code in
  11. ** addrbook_search_html.html -- If you change one,
  12. ** change the other one too!
  13. **
  14. ** $Id: addrbook_search.php 1052 2001-02-05 09:28:11Z pallo $
  15. **/
  16. // Function to include JavaScript code
  17. function insert_javascript() {
  18. ?>
  19. <SCRIPT LANGUAGE="Javascript"><!--
  20. function to_and_close($addr) {
  21. to_address($addr);
  22. parent.close();
  23. }
  24. function to_address($addr) {
  25. var prefix = "";
  26. var pwintype = typeof parent.opener.document.compose;
  27. $addr = $addr.replace(/ {1,35}$/, "");
  28. if(pwintype != "undefined" ) {
  29. if ( parent.opener.document.compose.send_to.value ) {
  30. prefix = ", ";
  31. parent.opener.document.compose.send_to.value =
  32. parent.opener.document.compose.send_to.value + ", " + $addr;
  33. } else {
  34. parent.opener.document.compose.send_to.value = $addr;
  35. }
  36. }
  37. }
  38. function cc_address($addr) {
  39. var prefix = "";
  40. var pwintype = typeof parent.opener.document.compose;
  41. $addr = $addr.replace(/ {1,35}$/, "");
  42. if(pwintype != "undefined" ) {
  43. if ( parent.opener.document.compose.send_to_cc.value ) {
  44. prefix = ", ";
  45. parent.opener.document.compose.send_to_cc.value =
  46. parent.opener.document.compose.send_to_cc.value + ", " + $addr;
  47. } else {
  48. parent.opener.document.compose.send_to_cc.value = $addr;
  49. }
  50. }
  51. }
  52. function bcc_address($addr) {
  53. var prefix = "";
  54. var pwintype = typeof parent.opener.document.compose;
  55. $addr = $addr.replace(/ {1,35}$/, "");
  56. if(pwintype != "undefined" ) {
  57. if ( parent.opener.document.compose.send_to_bcc.value ) {
  58. prefix = ", ";
  59. parent.opener.document.compose.send_to_bcc.value =
  60. parent.opener.document.compose.send_to_bcc.value + ", " + $addr;
  61. } else {
  62. parent.opener.document.compose.send_to_bcc.value = $addr;
  63. }
  64. }
  65. }
  66. // --></SCRIPT>
  67. <?php
  68. } // End of included JavaScript
  69. // List search results
  70. function display_result($res, $includesource = true) {
  71. global $color;
  72. if(sizeof($res) <= 0) return;
  73. insert_javascript();
  74. $line = 0;
  75. print '<TABLE BORDER="0" WIDTH="98%" ALIGN=center>';
  76. printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left>&nbsp;".
  77. "<TH ALIGN=left>&nbsp;%s<TH ALIGN=left>&nbsp;%s".
  78. "<TH ALIGN=left>&nbsp;%s",
  79. _("Name"), _("E-mail"), _("Info"));
  80. if($includesource)
  81. printf("<TH ALIGN=left WIDTH=\"10%%\">&nbsp;%s", _("Source"));
  82. print "</TR>\n";
  83. while(list($undef, $row) = each($res)) {
  84. printf("<tr%s nowrap><td valign=top nowrap align=center width=\"5%%\">".
  85. "<small><a href=\"javascript:to_address('%s');\">To</A> | ".
  86. "<a href=\"javascript:cc_address('%s');\">Cc</A> | ".
  87. "<a href=\"javascript:bcc_address('%s');\">Bcc</A></small>".
  88. "<td nowrap valign=top>&nbsp;%s&nbsp;<td nowrap valign=top>".
  89. "&nbsp;<a href=\"javascript:to_and_close('%s');\">%s</A>&nbsp;".
  90. "<td valign=top>&nbsp;%s&nbsp;",
  91. ($line % 2) ? " bgcolor=\"$color[0]\"" : "",
  92. $row["email"], $row["email"], $row["email"],
  93. $row["name"], $row["email"], $row["email"],
  94. $row["label"]);
  95. if($includesource)
  96. printf("<td nowrap valign=top>&nbsp;%s", $row["source"]);
  97. print "</TR>\n";
  98. $line++;
  99. }
  100. print '</TABLE>';
  101. }
  102. /* ================= End of functions ================= */
  103. session_start();
  104. if (!isset($strings_php))
  105. include("../functions/strings.php");
  106. if (!isset($i18n_php))
  107. include('../functions/i18n.php');
  108. if(!isset($logged_in) || !isset($username) || !isset($key)) {
  109. include ('../themes/default_theme.php');
  110. include ('../functions/display_messages.php');
  111. printf('<html><BODY TEXT="%s" BGCOLOR="%s" LINK="%s" VLINK="%s" ALINK="%s">',
  112. $color[8], $color[4], $color[7], $color[7], $color[7]);
  113. plain_error_message(_("You need a valid user and password to access this page!")
  114. . '<br><a href="../src/login.php">'
  115. . _("Click here to log back in.") . "</a>.", $color);
  116. echo '</body></html>';
  117. exit;
  118. }
  119. if (!isset($config_php))
  120. include('../config/config.php');
  121. if (!isset($array_php))
  122. include('../functions/array.php');
  123. if (!isset($auth_php))
  124. include('../functions/auth.php');
  125. if (!isset($strings_php))
  126. include('../functions/strings.php');
  127. if (!isset($page_header_php))
  128. include('../functions/page_header.php');
  129. if (!isset($addressbook_php))
  130. include('../functions/addressbook.php');
  131. is_logged_in();
  132. include('../src/load_prefs.php');
  133. displayHtmlHeader();
  134. // Initialize vars
  135. if(!isset($query)) $query = "";
  136. if(!isset($show)) $show = "";
  137. // Choose correct colors for top and bottom frame
  138. if($show == 'form') {
  139. echo "<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" ";
  140. echo "LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\" ";
  141. echo 'OnLoad="document.sform.query.focus();">';
  142. } else {
  143. echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" ";
  144. echo "LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
  145. }
  146. // Empty search
  147. if(empty($query) && empty($show) && empty($listall)) {
  148. printf("<P ALIGN=center><BR>%s</P>\n</BODY></HTML>\n",
  149. _("No persons matching your search was found"));
  150. exit;
  151. }
  152. // Initialize addressbook
  153. $abook = addressbook_init();
  154. // Create search form
  155. if($show == 'form') {
  156. printf("<FORM NAME=sform TARGET=abookres ACTION=\"%s\" METHOD=\"POST\">\n",
  157. $PHP_SELF);
  158. print('<TABLE BORDER="0" WIDTH="100%" HEIGHT="100%">');
  159. print("<TR><TD NOWRAP VALIGN=middle>\n");
  160. printf(" <STRONG>%s</STRONG>\n", _("Search for"));
  161. printf(" <INPUT TYPE=text NAME=query VALUE=\"%s\" SIZE=26>\n",
  162. htmlspecialchars($query));
  163. // List all backends to allow the user to choose where to search
  164. if($abook->numbackends > 1) {
  165. printf("<STRONG>%s</STRONG>&nbsp;<SELECT NAME=backend>\n",
  166. _("in"));
  167. printf("<OPTION VALUE=-1 SELECTED>%s\n",
  168. _("All address books"));
  169. $ret = $abook->get_backend_list();
  170. while(list($undef,$v) = each($ret))
  171. printf("<OPTION VALUE=%d>%s\n", $v->bnum, $v->sname);
  172. print "</SELECT>\n";
  173. } else {
  174. print "<INPUT TYPE=hidden NAME=backend VALUE=-1>\n";
  175. }
  176. printf("<INPUT TYPE=submit VALUE=\"%s\">",
  177. _("Search"));
  178. printf("&nbsp;|&nbsp;<INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
  179. _("List all"));
  180. print "</TD><TD ALIGN=right>\n";
  181. printf("<INPUT TYPE=button VALUE=\"%s\" onclick=\"parent.close();\">\n",
  182. _("Close window"));
  183. print "</TD></TR></TABLE></FORM>\n";
  184. } else
  185. // Show personal addressbook
  186. if($show == 'blank' || !empty($listall)) {
  187. if($backend != -1 || $show == 'blank') {
  188. if($show == 'blank')
  189. $backend = $abook->localbackend;
  190. //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname);
  191. $res = $abook->list_addr($backend);
  192. if(is_array($res)) {
  193. display_result($res, false);
  194. } else {
  195. printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
  196. "</STRONG></P>\n", $abook->backends[$backend]->sname);
  197. }
  198. } else {
  199. $res = $abook->list_addr();
  200. display_result($res, true);
  201. }
  202. } else
  203. // Do the search
  204. if(!empty($query) && empty($listall)) {
  205. if($backend == -1) {
  206. $res = $abook->s_search($query);
  207. } else {
  208. $res = $abook->s_search($query, $backend);
  209. }
  210. if(!is_array($res)) {
  211. printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n",
  212. _("Your search failed with the following error(s)"),
  213. $abook->error);
  214. exit;
  215. }
  216. if(sizeof($res) == 0) {
  217. printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n",
  218. _("No persons matching your search was found"));
  219. exit;
  220. }
  221. display_result($res);
  222. }
  223. ?>
  224. </BODY></HTML>