Source for file addrbook_search.php

Documentation is available at addrbook_search.php

  1. <?php
  2. /**
  3.  * addrbook_search.php
  4.  *
  5.  * Handle addressbook searching in the popup window.
  6.  *
  7.  * NOTE: A lot of this code is similar to the code in
  8.  *       addrbook_search_html.html -- If you change one,
  9.  *       change the other one too!
  10.  *
  11.  * @copyright 1999-2020 The SquirrelMail Project Team
  12.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  13.  * @version $Id: addrbook_search.php 14845 2020-01-07 08:09:34Z pdontthink $
  14.  * @package squirrelmail
  15.  * @subpackage addressbook
  16.  */
  17.  
  18. /** This is the addrbook_search page */
  19. define('PAGE_NAME''addrbook_search');
  20.  
  21. /**
  22.  * Include the SquirrelMail initialization file.
  23.  */
  24. require('../include/init.php');
  25.  
  26. include_once(SM_PATH 'functions/forms.php');
  27. include_once(SM_PATH 'functions/addressbook.php');
  28. include_once(SM_PATH 'templates/util_addressbook.php');
  29.  
  30. /**
  31.  * List search results
  32.  * @param array $res Array of search results
  33.  * @param bool $includesource [Default=true]
  34.  * @return void 
  35.  */
  36. function display_result($res$includesource true{
  37.     global $oTemplate$oErrorHandler;
  38.  
  39.     if(sizeof($res<= 0return;
  40.  
  41.     $oTemplate->assign('compose_addr_pop'true);
  42.     $oTemplate->assign('include_abook_name'$includesource);
  43.     $oTemplate->assign('addresses'formatAddressList($res));
  44.     
  45.     $oTemplate->display('addrbook_search_list.tpl');    
  46. }
  47.  
  48. /* ================= End of functions ================= */
  49.  
  50. /** lets get the global vars we may need */
  51.  
  52. if (sqgetGlobalVar('show' $show)) {
  53.     $show '';
  54. }
  55. if (sqgetGlobalVar('query'$querySQ_POST)) {
  56.     $query '';
  57. }
  58. if (sqgetGlobalVar('listall'$listallSQ_POST)) {
  59.     unset($listall);
  60. }
  61. if (sqgetGlobalVar('backend'$backendSQ_POST)) {
  62.     $backend '';
  63. }
  64.  
  65. echo "<body>\n";
  66.  
  67. /** set correct value of $default_charset */
  68.  
  69. /* Empty search */
  70. if (empty($query&& empty($show&& !isset($listall)) {
  71.     $oTemplate->assign('note'sm_encode_html_special_chars(_("No persons matching your search were found")));
  72.     $oTemplate->display('note.tpl');
  73. #    exit;
  74. }
  75.  
  76. /* Initialize addressbook, show init errors only in bottom frame */
  77. $showerr=($show=='form' false true);
  78. $abook addressbook_init($showerr);
  79.  
  80. /* Create search form (top frame) */
  81. if ($show == 'form' && isset($listall)) {
  82.     echo "<form name=\"sform\" target=\"abookres\" action=\"addrbook_search.php\" method=\"post\">\n";
  83.     
  84.     $oTemplate->assign('compose_addr_pop'true);
  85.     $oTemplate->assign('backends'getBackends());
  86.     $oTemplate->display('addressbook_search_form.tpl');
  87.     
  88.     echo "</form>\n";
  89. else {
  90.     /**
  91.      * List addresses (bottom frame)
  92.      * If listall is set, list all entries in selected backend.
  93.      * If $show is 'blank' (initial call of address book popup) - list
  94.      * personal address book.
  95.      */
  96.     if ($show == 'blank' || isset($listall)) {
  97.  
  98.         if($backend != -|| $show == 'blank'{
  99.             if ($show == 'blank'{
  100.                 $backend $abook->localbackend;
  101.             }
  102.             $res $abook->list_addr($backend);
  103.  
  104.             if(is_array($res)) {
  105.                 usort($res,'alistcmp');
  106.                 display_result($resfalse);
  107.             else {
  108.                 plain_error_message(sprintf(_("Unable to list addresses from %s")$abook->backends[$backend]->sname));
  109.             }
  110.         else {
  111.             $res $abook->list_addr();
  112.             usort($res,'alistcmp');
  113.             display_result($restrue);
  114.         }
  115.  
  116.     elseif (!empty($query)) {
  117.         /* Do the search (listall is not set. query is set.)*/
  118.  
  119.         if($backend == -1{
  120.             $res $abook->s_search($query);
  121.         else {
  122.             $res $abook->s_search($query$backend);
  123.         }
  124.  
  125.         if (!is_array($res)) {
  126.             plain_error_message_("Your search failed with the following error(s)".':<br />'nl2br(sm_encode_html_special_chars($abook->error)) );
  127.         elseif (sizeof($res== 0{
  128.             $oTemplate->assign('note'_("No persons matching your search were found"));
  129.             $oTemplate->display('note.tpl');
  130.         else {
  131.             display_result($res);
  132.         }
  133.     else {
  134.         /**
  135.          * listall is not set, query is not set or empty.
  136.          * User hit search button without entering search expression.
  137.          */
  138.         plain_error_message(_("Nothing to search"));
  139.     }
  140. }
  141.  
  142. $oTemplate->display('footer.tpl');

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