squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

addrbook_search.php
Go to the documentation of this file.
1 <?php
2 
20 define('PAGE_NAME', 'addrbook_search');
21 
26 define('SM_PATH','../');
27 
29 require_once(SM_PATH . 'include/validate.php');
30 require_once(SM_PATH . 'functions/html.php');
31 require_once(SM_PATH . 'functions/forms.php');
32 require_once(SM_PATH . 'functions/addressbook.php');
33 
35 sqgetGlobalVar('key', $key, SQ_COOKIE);
36 sqgetGlobalVar('username', $username, SQ_SESSION);
37 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
38 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
39 
40 sqgetGlobalVar('show' , $show);
41 sqgetGlobalVar('query', $query, SQ_POST);
42 sqgetGlobalVar('listall', $listall, SQ_POST);
43 sqgetGlobalVar('backend', $backend, SQ_POST);
44 
49 function insert_javascript() {
50  ?>
51  <script language="Javascript"><!--
52 
53  function to_and_close($addr) {
54  to_address($addr);
55  parent.close();
56  }
57 
58  function to_address($addr) {
59  var prefix = "";
60  var pwintype = typeof parent.opener.document.compose;
61 
62  $addr = $addr.replace(/ {1,35}$/, "");
63 
64  if (pwintype != "undefined") {
65  if (parent.opener.document.compose.send_to.value) {
66  prefix = ", ";
67  parent.opener.document.compose.send_to.value =
68  parent.opener.document.compose.send_to.value + ", " + $addr;
69  } else {
70  parent.opener.document.compose.send_to.value = $addr;
71  }
72  }
73  }
74 
75  function cc_address($addr) {
76  var prefix = "";
77  var pwintype = typeof parent.opener.document.compose;
78 
79  $addr = $addr.replace(/ {1,35}$/, "");
80 
81  if (pwintype != "undefined") {
82  if (parent.opener.document.compose.send_to_cc.value) {
83  prefix = ", ";
84  parent.opener.document.compose.send_to_cc.value =
85  parent.opener.document.compose.send_to_cc.value + ", " + $addr;
86  } else {
87  parent.opener.document.compose.send_to_cc.value = $addr;
88  }
89  }
90  }
91 
92  function bcc_address($addr) {
93  var prefix = "";
94  var pwintype = typeof parent.opener.document.compose;
95 
96  $addr = $addr.replace(/ {1,35}$/, "");
97 
98  if (pwintype != "undefined") {
99  if (parent.opener.document.compose.send_to_bcc.value) {
100  prefix = ", ";
101  parent.opener.document.compose.send_to_bcc.value =
102  parent.opener.document.compose.send_to_bcc.value + ", " + $addr;
103  } else {
104  parent.opener.document.compose.send_to_bcc.value = $addr;
105  }
106  }
107  }
108 
109 // --></script>
110 <?php
111 } /* End of included JavaScript */
112 
113 
120 function display_result($res, $includesource = true) {
121  global $color;
122 
123  if(sizeof($res) <= 0) return;
124 
126 
127  $line = 0;
128  echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
129  html_tag( 'tr', '', '', $color[9] ) .
130  html_tag( 'th', '&nbsp;', 'left' ) .
131  html_tag( 'th', '&nbsp;' . _("Name"), 'left' ) .
132  html_tag( 'th', '&nbsp;' . _("E-mail"), 'left' ) .
133  html_tag( 'th', '&nbsp;' . _("Info"), 'left' );
134 
135  if ($includesource) {
136  echo html_tag( 'th', '&nbsp;' . _("Source"), 'left', '', 'width="10%"' );
137  }
138  echo "</tr>\n";
139 
140  while (list($undef, $row) = each($res)) {
141  $email = htmlspecialchars(addcslashes(AddressBook::full_address($row), "'"), ENT_QUOTES);
142  if ($line % 2) {
143  $tr_bgcolor = $color[12];
144  } else {
145  $tr_bgcolor = $color[4];
146  }
147  echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
148  html_tag( 'td',
149  '<small><a href="javascript:to_address(' .
150  "'" . $email . "');\">"._("To")."</a> | " .
151  '<a href="javascript:cc_address(' .
152  "'" . $email . "');\">"._("Cc")."</a> | " .
153  '<a href="javascript:bcc_address(' .
154  "'" . $email . "');\">"._("Bcc")."</a></small>",
155  'center', '', 'valign="top" width="5%" nowrap' ) .
156  html_tag( 'td', '&nbsp;' . htmlspecialchars($row['name']), 'left', '', 'valign="top" nowrap' ) .
157  html_tag( 'td', '&nbsp;' .
158  '<a href="javascript:to_and_close(' .
159  "'" . $email . "');\">" . htmlspecialchars($row['email']) . '</a>'
160  , 'left', '', 'valign="top"' ) .
161  html_tag( 'td', htmlspecialchars($row['label']), 'left', '', 'valign="top" nowrap' );
162  if ($includesource) {
163  echo html_tag( 'td', '&nbsp;' . $row['source'], 'left', '', 'valign="top" nowrap' );
164  }
165 
166  echo "</tr>\n";
167  $line++;
168  }
169  echo '</table>';
170 }
171 
172 /* ================= End of functions ================= */
173 
174 
176 
177 /* Initialize vars */
178 if (!isset($query)) { $query = ''; }
179 if (!isset($show)) { $show = ''; }
180 if (!isset($backend)) { $backend = ''; }
181 
182 /* Choose correct colors for top and bottom frame */
183 if ($show == 'form' && !isset($listall)) {
184  echo '<body text="' . $color[6] . '" bgcolor="' . $color[3] . '" ' .
185  'link="' . $color[6] . '" vlink="' . $color[6] . '" ' .
186  'alink="' . $color[6] . '" ' .
187  'OnLoad="document.sform.query.focus();">';
188 } else {
189  echo '<body text="' . $color[8] . '" bgcolor="' . $color[4] . '" ' .
190  'link="' . $color[7] . '" vlink="' . $color[7] . '" ' .
191  'alink="' . $color[7] . "\">\n";
192 }
193 
194 /* Empty search */
195 if (empty($query) && empty($show) && empty($listall)) {
196  echo html_tag( 'p', '<br />' .
197  _("No persons matching your search were found"),
198  'center' ) .
199  "\n</body></html>\n";
200  exit;
201 }
202 
203 /* Initialize addressbook */
205 
206 /* Create search form */
207 if ($show == 'form' && empty($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%"' ) .
211  html_tag( 'tr' ) .
212  html_tag( 'td', ' <strong>' . _("Search for") . "</strong>\n", 'left', '', 'nowrap valign="middle" width="10%"' ) .
213  html_tag( 'td', '', 'left', '', '' ) .
214  addInput('query', $query, 28);
215 
216  /* List all backends to allow the user to choose where to search */
217  if ($abook->numbackends > 1) {
218  echo '<strong>' . _("in") . '</strong>&nbsp;'."\n";
219  $selopts = array();
220  $selopts['-1'] = _("All address books");
221 
222  $ret = $abook->get_backend_list();
223  while (list($undef,$v) = each($ret)) {
224  $selopts[$v->bnum] = $v->sname;
225  }
226  echo addSelect('backend', $selopts, '-1', TRUE);
227  } else {
228  echo addHidden('backend', '-1');
229  }
230 
231  echo '</td></tr>' .
232  html_tag( 'tr',
233  html_tag( 'td', '', 'left' ) .
234  html_tag( 'td',
235  '<input type="submit" value="' . _("Search") . '" name="show" />' .
236  '&nbsp;|&nbsp;<input type="submit" value="' . _("List all") .
237  '" name="listall" />' . "\n" .
238  '&nbsp;|&nbsp;<input type="button" value="' . _("Close") .
239  '" onclick="parent.close();" />' . "\n" ,
240  'left' )
241  ) .
242  '</table></form>' . "\n";
243 } else {
244 
245  /* Show personal addressbook */
246  if ($show == 'blank' && empty($listall)) {
247 
248  if($backend != -1 || $show == 'blank') {
249  if ($show == 'blank') {
250  $backend = $abook->localbackend;
251  }
252  $res = $abook->list_addr($backend);
253 
254  if(is_array($res)) {
255  usort($res,'alistcmp');
256  display_result($res, false);
257  } else {
258  echo html_tag( 'p', '<strong>' .
259  sprintf(_("Unable to list addresses from %s"),
260  $abook->backends[$backend]->sname) . '</strong>' ,
261  'center' ) . "\n";
262  }
263  } else {
264  $res = $abook->list_addr();
265  usort($res,'alistcmp');
266  display_result($res, true);
267  }
268 
269  } else {
270  if( !empty( $listall ) ){
271  $query = '*';
272  }
273 
274  /* Do the search */
275  if (!empty($query)) {
276 
277  if($backend == -1) {
278  $res = $abook->s_search($query);
279  } else {
280  $res = $abook->s_search($query, $backend);
281  }
282 
283  if (!is_array($res)) {
284  echo html_tag( 'p', '<b><br />' .
285  _("Your search failed with the following error(s)") .
286  ':<br />' . $abook->error . "</b>\n" ,
287  'center' ) .
288  "\n</body></html>\n";
289  exit;
290  }
291 
292  if (sizeof($res) == 0) {
293  echo html_tag( 'p', '<br /><b>' .
294  _("No persons matching your search were found") . "</b>\n" ,
295  'center' ) .
296  "\n</body></html>\n";
297  exit;
298  }
299 
300  display_result($res);
301  }
302  }
303 
304 }
305 ?>
306 </body></html>
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
$ret
$ret
Definition: webmail.php:172
html_tag
html_tag( $tag, $val='', $align='', $bgcolor='', $xtra='')
Definition: html.php:27
AddressBook\full_address
full_address($row)
Definition: addressbook.php:353
SQ_SESSION
const SQ_SESSION
Definition: global.php:18
SM_PATH
const SM_PATH
Definition: addrbook_search.php:26
sprintf
powered by Systran sprintf(_("Number of supported language pairs: %s"), '36').' '
Definition: options.php:107
html
Definition: html.class.php:18
$username
global $username
Definition: validate.php:55
addInput
addInput($name, $value='', $size=0, $maxlength=0, $extra_attributes='')
Definition: forms.php:65
addSelect
addSelect($name, $values, $default=null, $usekeys=false)
Definition: forms.php:86
display_result
display_result($res, $includesource=true)
Definition: addrbook_search.php:120
insert_javascript
insert_javascript()
Definition: addrbook_search.php:49
addHidden
addHidden($name, $value)
Definition: forms.php:58
displayHtmlHeader
displayHtmlHeader( $title='SquirrelMail', $xtra='', $do_hook=TRUE)
Definition: page_header.php:21
SQ_POST
const SQ_POST
Definition: global.php:17
exit
exit
Definition: help.php:128
_
_($str)
Definition: gettext.php:160
$base_uri
if(!(bool) ini_get('session.use_cookies')||ini_get('session.use_cookies')=='off') $base_uri
Definition: global.php:173
$color
$color
Definition: load_prefs.php:28
SQ_COOKIE
const SQ_COOKIE
Definition: global.php:19
$abook
if(empty($query) &&empty($show) &&empty($listall)) $abook
Definition: addrbook_search.php:204
addressbook_init
addressbook_init($showerr=true, $onlylocal=false)
Definition: addressbook.php:32