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 1999-2020 The SquirrelMail Project Team
  10.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11.  * @version $Id: addrbook_search_html.php 14845 2020-01-07 08:09:34Z pdontthink $
  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.     /** This is the addrbook_search_html page */
  24.     define('PAGE_NAME', 'addrbook_search_html');
  25.  
  26.     include('../include/init.php');
  27. }
  28.  
  29. /** SquirrelMail required files. */
  30. include_once(SM_PATH . 'functions/date.php');
  31. include_once(SM_PATH . 'functions/addressbook.php');
  32. include_once(SM_PATH . 'templates/util_addressbook.php');
  33.  
  34. sqgetGlobalVar('session',   $session,   SQ_POST);
  35. sqgetGlobalVar('mailbox',   $mailbox,   SQ_POST);
  36. if (! sqgetGlobalVar('query', $addrquery, SQ_POST))
  37.      $addrquery='';
  38. sqgetGlobalVar('listall',   $listall,   SQ_POST);
  39. sqgetGlobalVar('backend',   $backend,   SQ_POST);
  40.  
  41. /**
  42.  * Insert hidden data
  43.  */
  44. function addr_insert_hidden() {
  45.     global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox, $mailprio,
  46.            $request_mdn, $request_dr, $identity, $session, $composeMessage, $action;
  47.  
  48. //FIXME Do not echo HTML from the core.  This file already uses templates mostly, so why are we echoing here at all?!?
  49.    // someone tell me why this is needed and if so, why it isn't something like replace \r\n with \n
  50.    // if (substr($body, 0, 1) == "\r") {
  51.    //     echo addHidden('body', "\n".$body);
  52.    // } else {
  53.        echo addHidden('body', $body);
  54.    // }
  55.  
  56.    if (is_object($composeMessage) && $composeMessage->entities)
  57.        echo addHidden('attachments', urlencode(serialize($composeMessage->entities)));
  58.  
  59.    echo addHidden('session', $session).
  60.         addHidden('smaction', $action).
  61.         addHidden('subject', $subject).
  62.         addHidden('send_to', $send_to).
  63.         addHidden('send_to_bcc', $send_to_bcc).
  64.         addHidden('send_to_cc', $send_to_cc).
  65.         addHidden('mailprio', $mailprio).
  66.         addHidden('request_mdn', $request_mdn).
  67.         addHidden('request_dr', $request_dr).
  68.         addHidden('identity', $identity).
  69.         addHidden('mailbox', $mailbox).
  70.         addHidden('from_htmladdr_search', 'true');
  71. }
  72.  
  73.  
  74. /**
  75.  * List search results
  76.  * @param array $res Array containing results of search
  77.  * @param bool $includesource If true, adds backend column to address listing
  78.  */
  79. function addr_display_result($res, $includesource = true) {
  80.     global $PHP_SELF, $oTemplate, $oErrorHandler;
  81.     
  82.  
  83. //FIXME: no HTML output from core
  84.     echo addForm($PHP_SELF, 'post', 'addressbook', '', '', array(), TRUE).
  85.          addHidden('html_addr_search_done', 'true');
  86.     
  87.     $oTemplate->assign('compose_addr_pop', false);
  88.     $oTemplate->assign('include_abook_name', $includesource);
  89.     $oTemplate->assign('addresses', formatAddressList($res));
  90.     
  91.     $oTemplate->display('addrbook_search_list.tpl');
  92.     
  93.     echo '</form>';
  94. }
  95.  
  96. /* --- End functions --- */
  97.  
  98. if ($compose_new_win == '1') {
  99.     compose_Header($color, $mailbox);
  100. }
  101. else {
  102.     displayPageHeader($color, $mailbox);
  103. }
  104.  
  105. /** set correct value of $default_charset */
  106.  
  107. /* Initialize addressbook */
  108. $abook = addressbook_init();
  109.  
  110.  
  111. /* Search form */
  112. echo addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f');
  113. if (isset($session)) {
  114.     echo addHidden('session', $session);
  115. }
  116.  
  117. $oTemplate->assign('compose_addr_pop', false);
  118. $oTemplate->assign('backends', getBackends());
  119.  
  120. $oTemplate->display('addressbook_search_form.tpl');
  121.  
  122. echo "</form>\n";
  123. do_hook('addrbook_html_search_below', $null);
  124. /* End search form */
  125.  
  126. /* List addresses. Show personal addressbook */
  127. if ($addrquery == '' || ! empty($listall)) {
  128.     // TODO: recheck all conditions and simplity if statements
  129.     if (! isset($backend) || $backend != -1 || $addrquery == '') {
  130.         if ($addrquery == '' && empty($listall)) {
  131.             $backend = $abook->localbackend;
  132.         }
  133.  
  134.         $res = $abook->list_addr($backend);
  135.  
  136.         if (is_array($res)) {
  137.             usort($res,'alistcmp');
  138.             addr_display_result($res, false);
  139.         } else {
  140.             plain_error_message(_("Unable to list addresses from %s"), $abook->backends[$backend]->sname);
  141.         }
  142.  
  143.     } else {
  144.         $res = $abook->list_addr();
  145.         usort($res,'alistcmp');
  146.         addr_display_result($res, true);
  147.     }
  148.     $oTemplate->display('footer.tpl');
  149.     exit;
  150. } elseif (!empty($addrquery)) {
  151.     /* Do the search */
  152.     if ($backend == -1) {
  153.         $res = $abook->s_search($addrquery);
  154.     } else {
  155.         $res = $abook->s_search($addrquery, $backend);
  156.     }
  157.  
  158.     if (!is_array($res)) {
  159.         plain_error_message(_("Your search failed with the following error(s)") .':<br />'. nl2br(sm_encode_html_special_chars($abook->error)));
  160.     } elseif (sizeof($res) == 0) {
  161.         $oTemplate->assign('note', _("No persons matching your search were found"));
  162.         $oTemplate->display('note.tpl');
  163.     } else {
  164.         addr_display_result($res);
  165.     }
  166. } else {
  167.     // not first time display, not listall and search is empty
  168.     // TODO: I think, this part of control structure is never reached.
  169.     plain_error_message(_("Nothing to search"));
  170. }
  171.  
  172. if ($addrquery == '' || sizeof($res) == 0) {
  173. //FIXME don't echo HTML from core -- especially convoluted given that there is template code immediately above AND below this block
  174.     echo '<div style="text-align: center;">'.
  175.         addForm('compose.php','post','k', '', '', array(), TRUE);
  176.     echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
  177.          '</form></div></nobr>';
  178. }
  179.  
  180. echo '<hr />';
  181.  
  182. $oTemplate->display('footer.tpl');

Documentation generated on Mon, 13 Jan 2020 04:21:58 +0100 by phpDocumentor 1.4.3