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

Documentation generated on Thu, 23 May 2013 04:18:19 +0200 by phpDocumentor 1.4.3