PageRenderTime 123ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

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

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