Source for file addrbook_search_html.php

Documentation is available at addrbook_search_html.php

  1. <?php
  2. /**
  3.  * addrbook_search_html.php
  4.  *
  5.  * Handle addressbook searching with pure html.
  6.  *
  7.  * This file is included from compose.php
  8.  *
  9.  * @copyright &copy; 1999-2006 The SquirrelMail Project Team
  10.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11.  * @version $Id: addrbook_search_html.php,v 1.87 2006/08/15 17:35:28 stevetruckstuff Exp $
  12.  * @package squirrelmail
  13.  * @subpackage addressbook
  14.  */
  15.  
  16. /**
  17.  * Include the SquirrelMail initialization file.
  18.  * Because this file can also be included within compose we check for the $bInit
  19.  * var which is set inside ini.php. It's needed because compose already includes
  20.  * init.php.
  21.  */
  22. if (!isset($bInit)) {
  23.     include('../include/init.php');
  24. }
  25.  
  26. /** SquirrelMail required files. */
  27. include_once(SM_PATH . 'functions/date.php');
  28. include_once(SM_PATH . 'functions/addressbook.php');
  29. include_once(SM_PATH . 'templates/util_addressbook.php');
  30.  
  31. sqgetGlobalVar('session',   $session,   SQ_POST);
  32. sqgetGlobalVar('mailbox',   $mailbox,   SQ_POST);
  33. if (! sqgetGlobalVar('query', $addrquery, SQ_POST))
  34.      $addrquery='';
  35. sqgetGlobalVar('listall',   $listall,   SQ_POST);
  36. sqgetGlobalVar('backend',   $backend,   SQ_POST);
  37.  
  38. /**
  39.  * Insert hidden data
  40.  */
  41. function addr_insert_hidden() {
  42.     global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
  43.            $identity, $session;
  44.  
  45.    if (substr($body, 0, 1) == "\r") {
  46.        echo addHidden('body', "\n".$body);
  47.    } else {
  48.        echo addHidden('body', $body);
  49.    }
  50.  
  51.    echo addHidden('session', $session).
  52.         addHidden('subject', $subject).
  53.         addHidden('send_to', $send_to).
  54.         addHidden('send_to_bcc', $send_to_bcc).
  55.         addHidden('send_to_cc', $send_to_cc).
  56.         addHidden('identity', $identity).
  57.         addHidden('mailbox', $mailbox).
  58.         addHidden('from_htmladdr_search', 'true');
  59. }
  60.  
  61.  
  62. /**
  63.  * List search results
  64.  * @param array $res Array containing results of search
  65.  * @param bool $includesource If true, adds backend column to address listing
  66.  */
  67. function addr_display_result($res, $includesource = true) {
  68.     global $color, $javascript_on, $PHP_SELF, $squirrelmail_language;
  69.  
  70.     global $oTemplate, $oErrorHandler;
  71.     
  72.     if (sizeof($res) <= 0) return;
  73.  
  74.     echo addForm($PHP_SELF, 'post', 'addressbook').
  75.          addHidden('html_addr_search_done', 'true');
  76.  
  77.     $oTemplate->assign('use_js', false);
  78.     $oTemplate->assign('include_abook_name', $includesource);
  79.     $oTemplate->assign('addresses', formatAddressList($res));
  80.     
  81.     $oTemplate->display('addrbook_search_list.tpl');
  82.     
  83.     echo '</form>';
  84. }
  85.  
  86. /* --- End functions --- */
  87.  
  88. if ($compose_new_win == '1') {
  89.     compose_Header($color, $mailbox);
  90. }
  91. else {
  92.     displayPageHeader($color, $mailbox);
  93. }
  94.  
  95. /** set correct value of $default_charset */
  96. global $default_charset;
  97.  
  98. /* Initialize addressbook */
  99. $abook = addressbook_init();
  100.  
  101.  
  102. /* Search form */
  103. echo addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f');
  104. if (isset($session)) {
  105.     echo addHidden('session', $session);
  106. }
  107.  
  108. $oTemplate->assign('use_js', false);
  109. $oTemplate->assign('backends', getBackends());
  110.  
  111. $oTemplate->display('addressbook_search_form.tpl');
  112.  
  113. echo "</form>\n";
  114. do_hook('addrbook_html_search_below');
  115. /* End search form */
  116.  
  117. /* List addresses. Show personal addressbook */
  118. if ($addrquery == '' || ! empty($listall)) {
  119.     // TODO: recheck all conditions and simplity if statements
  120.         if (! isset($backend) || $backend != -1 || $addrquery == '') {
  121.         if ($addrquery == '' && empty($listall)) {
  122.             $backend = $abook->localbackend;
  123.         }
  124.  
  125.         $res = $abook->list_addr($backend);
  126.  
  127.         if (is_array($res)) {
  128.             usort($res,'alistcmp');
  129.             addr_display_result($res, false);
  130.         } else {
  131.             plain_error_message(_("Unable to list addresses from %s"), $abook->backends[$backend]->sname);
  132.         }
  133.  
  134.     } else {
  135.         $res = $abook->list_addr();
  136.         usort($res,'alistcmp');
  137.         addr_display_result($res, true);
  138.     }
  139.     $oTemplate->display('footer.tpl');
  140.     exit;
  141. } elseif (!empty($addrquery)) {
  142.     /* Do the search */
  143.     if ($backend == -1) {
  144.         $res = $abook->s_search($addrquery);
  145.     } else {
  146.         $res = $abook->s_search($addrquery, $backend);
  147.     }
  148.  
  149.     if (!is_array($res)) {
  150.         plain_error_message(_("Your search failed with the following error(s)") .':<br />'. nl2br(htmlspecialchars($abook->error)));
  151.     } elseif (sizeof($res) == 0) {
  152.         $oTemplate->assign('note', _("No persons matching your search were found"));
  153.         $oTemplate->display('note.tpl');
  154.     } else {
  155.         addr_display_result($res);
  156.     }
  157. } else {
  158.     // not first time display, not listall and search is empty
  159.     // TODO: I think, this part of control structure is never reached.
  160.         plain_error_message(_("Nothing to search"));
  161. }
  162.  
  163. if ($addrquery == '' || sizeof($res) == 0) {
  164.     echo '<div style="text-align: center;">'.
  165.         addForm('compose.php','post','k');
  166.     echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
  167.          '</form></div></nobr>';
  168. }
  169.  
  170. echo '<hr />';
  171.  
  172. $oTemplate->display('footer.tpl');
  173. ?>

Documentation generated on Sat, 07 Oct 2006 16:08:41 +0300 by phpDocumentor 1.3.0RC6