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

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