Source for file addrbook_search_html.php

Documentation is available at addrbook_search_html.php

  1. <?php
  2.  
  3. /**
  4.  * addrbook_search_html.php
  5.  *
  6.  * Handle addressbook searching with pure html.
  7.  *
  8.  * This file is included from compose.php
  9.  *
  10.  * @copyright 1999-2020 The SquirrelMail Project Team
  11.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  12.  * @version $Id: addrbook_search_html.php 14840 2020-01-07 07:42:38Z pdontthink $
  13.  * @package squirrelmail
  14.  * @subpackage addressbook
  15.  */
  16.  
  17. /** This is the addrbook_search_html page */
  18. if (defined('PAGE_NAME') ) {
  19.     define('PAGE_NAME''addrbook_search_html');
  20. }
  21.  
  22. /** 
  23.  * Path for SquirrelMail required files.
  24.  * @ignore
  25.  */
  26. if (defined('SM_PATH') ) {
  27.     define('SM_PATH','../');
  28. }
  29.  
  30. /** SquirrelMail required files. */
  31. require_once(SM_PATH 'include/validate.php');
  32. require_once(SM_PATH 'functions/global.php');
  33. require_once(SM_PATH 'functions/date.php');
  34. require_once(SM_PATH 'functions/display_messages.php');
  35. require_once(SM_PATH 'functions/addressbook.php');
  36. require_once(SM_PATH 'functions/plugin.php');
  37. require_once(SM_PATH 'functions/strings.php');
  38. require_once(SM_PATH 'functions/html.php');
  39.  
  40. sqgetGlobalVar('session',   $session,   SQ_POST);
  41. sqgetGlobalVar('mailbox',   $mailbox,   SQ_POST);
  42. sqgetGlobalVar('addrquery'$addrquerySQ_POST);
  43. sqgetGlobalVar('listall',   $listall,   SQ_POST);
  44. sqgetGlobalVar('backend',   $backend,   SQ_POST);
  45.  
  46. /**
  47.  * Insert hidden data
  48.  */
  49. function addr_insert_hidden({
  50.     global $body$subject$send_to$send_to_cc$send_to_bcc$mailbox$action,
  51.            $mailprio$request_mdn$request_dr$identity$session$composeMessage;
  52.  
  53.    // someone tell me why this is needed and if so, why it isn't something like replace \r\n with \n
  54.    // if (substr($body, 0, 1) == "\r") {
  55.    //     echo addHidden('body', "\n".$body);
  56.    // } else {
  57.        echo addHidden('body'$body);
  58.    // }
  59.  
  60.    if (is_object($composeMessage&& $composeMessage->entities)
  61.        echo addHidden('attachments'serialize($composeMessage->entities));
  62.  
  63.    echo addHidden('session'$session).
  64.         addHidden('smaction'$action).
  65.         addHidden('subject'$subject).
  66.         addHidden('send_to'$send_to).
  67.         addHidden('send_to_bcc'$send_to_bcc).
  68.         addHidden('send_to_cc'$send_to_cc).
  69.         addHidden('mailprio'$mailprio).
  70.         addHidden('request_mdn'$request_mdn).
  71.         addHidden('request_dr'$request_dr).
  72.         addHidden('identity'$identity).
  73.         addHidden('mailbox'$mailbox).
  74.         addHidden('from_htmladdr_search''true');
  75. }
  76.  
  77.  
  78. /**
  79.  * List search results
  80.  * @param array $res Array containing results of search
  81.  * @param bool $includesource If true, adds backend column to address listing
  82.  */
  83. function addr_display_result($res$includesource true{
  84.     global $color$javascript_on$PHP_SELF$squirrelmail_language;
  85.  
  86.     if (sizeof($res<= 0return;
  87.  
  88.     echo addForm($PHP_SELF'POST''addrbook'''''''TRUE).
  89.          addHidden('html_addr_search_done''true');
  90.     $line 0;
  91.  
  92.     if ($javascript_on{
  93.         print
  94.             '<script language="JavaScript" type="text/javascript">' .
  95.             "\n<!-- \n" .
  96.             "function CheckAll(ch) {\n" .
  97.             "   for (var i = 0; i < document.addrbook.elements.length; i++) {\n" .
  98.             "       if( document.addrbook.elements[i].type == 'checkbox' &&\n" .
  99.             "           document.addrbook.elements[i].name.substr(0,16) == 'send_to_search['+ch ) {\n" .
  100.             "           document.addrbook.elements[i].checked = !(document.addrbook.elements[i].checked);\n".
  101.             "       }\n" .
  102.             "   }\n" .
  103.             "}\n" .
  104.             "//-->\n" .
  105.             "</script>\n";
  106.         $chk_all '<a href="#" onClick="CheckAll(\'T\');">' _("All"'</a>&nbsp;<font color="'.$color[6].'">'._("To").'</font>'.
  107.             '&nbsp;&nbsp;'.
  108.             '<a href="#" onClick="CheckAll(\'C\');">' _("All"'</a>&nbsp;<font color="'.$color[6].'">'._("Cc").'</font>'.
  109.             '&nbsp;&nbsp;'.
  110.             '<a href="#" onClick="CheckAll(\'B\');">' _("All"'</a>&nbsp;<font color="'.$color[6].'">'._("Bcc").'</font>';
  111.     else {
  112.         // check_all links are implemented only in JavaScript. disable links in js=off environment.
  113.         $chk_all '';
  114.     }
  115.     echo html_tag'table''''center''''border="0" width="98%"' .
  116.     html_tag'tr'''''$color[9.
  117.     html_tag'th''&nbsp;' $chk_all'left'''' style="white-space: nowrap;" ' .
  118.     html_tag'th''&nbsp;' _("Name")'left' .
  119.     html_tag'th''&nbsp;' _("E-mail")'left' .
  120.     html_tag'th''&nbsp;' _("Info")'left' );
  121.  
  122.     if ($includesource{
  123.         echo html_tag'th''&nbsp;' _("Source")'left''''width="10%"' );
  124.     }
  125.  
  126.     echo "</tr>\n";
  127.  
  128.     foreach ($res as $row{
  129.         $email AddressBook::full_address($row);
  130.         if ($line 2
  131.             $tr_bgcolor $color[12];
  132.         else {
  133.             $tr_bgcolor $color[4];
  134.         }
  135.         if ($squirrelmail_language == 'ja_JP')
  136.             {
  137.         echo html_tag'tr'''''$tr_bgcolor'nowrap' .
  138.         html_tag'td',
  139.              '<input type="checkbox" name="send_to_search[T' $line ']" value = "' .
  140.              sm_encode_html_special_chars($email'" />&nbsp;' _("To"'&nbsp;' .
  141.              '<input type="checkbox" name="send_to_search[C' $line ']" value = "' .
  142.              sm_encode_html_special_chars($email'" />&nbsp;' _("Cc"'&nbsp;' .
  143.              '<input type="checkbox" name="send_to_search[B' $line ']" value = "' .
  144.              sm_encode_html_special_chars($email'" />&nbsp;' _("Bcc"'&nbsp;' ,
  145.         'center''''width="5%" nowrap' .
  146.         html_tag'td''&nbsp;' sm_encode_html_special_chars($row['lastname']' ' sm_encode_html_special_chars($row['firstname']'&nbsp;''left''''nowrap' .
  147.         html_tag'td''&nbsp;' sm_encode_html_special_chars($row['email']'&nbsp;''left''''nowrap' .
  148.         html_tag'td''&nbsp;' sm_encode_html_special_chars($row['label']'&nbsp;''left''''nowrap' );
  149.             else {
  150.         echo html_tag'tr'''''$tr_bgcolor'nowrap' .
  151.         html_tag'td',
  152.             addCheckBox('send_to_search[T'.$line.']'FALSE$email).
  153.             '&nbsp;' _("To"'&nbsp;' .
  154.             addCheckBox('send_to_search[C'.$line.']'FALSE$email).
  155.             '&nbsp;' _("Cc"'&nbsp;' .
  156.             addCheckBox('send_to_search[B'.$line.']'FALSE$email).
  157.             '&nbsp;' _("Bcc"'&nbsp;' ,
  158.         'center''''width="5%" nowrap' .
  159.         html_tag'td''&nbsp;' sm_encode_html_special_chars($row['name']'&nbsp;''left''''nowrap' .
  160.         html_tag'td''&nbsp;' sm_encode_html_special_chars($row['email']'&nbsp;''left''''nowrap' .
  161.         html_tag'td''&nbsp;' sm_encode_html_special_chars($row['label']'&nbsp;''left''''nowrap' );
  162.             }
  163.  
  164.          if ($includesource{
  165.              echo html_tag'td''&nbsp;' $row['source''&nbsp;''left''''nowrap' );
  166.          }
  167.          echo "</tr>\n";
  168.          $line ++;
  169.     }
  170.     if ($includesource$td_colspan '5'else $td_colspan '4'}
  171.     echo html_tag'tr',
  172.                 html_tag'td',
  173.                         '<input type="submit" name="addr_search_done" value="' .
  174.                         _("Use Addresses"'" /> ' .
  175.             '<input type="submit" name="addr_search_cancel" value="' .
  176.             _("Cancel"'" />',
  177.                 'center''''colspan="'$td_colspan .'"' )
  178.             .
  179.          '</table>' .
  180.          addHidden('html_addr_search_done''1').
  181.          '</form>';
  182. }
  183.  
  184. /* --- End functions --- */
  185.  
  186. if ($compose_new_win == '1'{
  187.     compose_Header($color$mailbox);
  188. }
  189. else {
  190.     displayPageHeader($color$mailbox);
  191. }
  192. /* Initialize addressbook */
  193. $abook addressbook_init();
  194.  
  195.  
  196. echo '<br />' .
  197. html_tag'table',
  198.     html_tag'tr',
  199.         html_tag'td''<b>' _("Address Book Search"'</b>''center'$color[0)
  200.     ,
  201. 'center''''width="95%" cellpadding="2" cellspacing="2" border="0"' );
  202.  
  203.  
  204. /* Search form */
  205. echo addForm($PHP_SELF.'?html_addr_search=true''post''f').
  206.     '<center>' .
  207.     html_tag'table''''center''''border="0"' .
  208.     html_tag'tr' .
  209.     html_tag'td''''left''''nowrap valign="middle"' "\n" .
  210.     "\n<center>\n" .
  211.     '  <nobr><strong>' _("Search for""</strong>\n";
  212. if (isset($addrquery))
  213.     $addrquery '';
  214. echo addInput('addrquery'$addrquery26);
  215.  
  216. /* List all backends to allow the user to choose where to search */
  217. if (!isset($backend)) $backend ''}
  218. if ($abook->numbackends 1{
  219.     echo '<strong>' _("in"'</strong>&nbsp;';
  220.     
  221.     $selopts['-1'_("All address books")
  222.     $ret $abook->get_backend_list();
  223.     
  224.     while (list($undef,$veach($ret)) {
  225.         $selopts[$v->bnum$v->sname;
  226.     }
  227.     echo addSelect('backend'$selopts$backendTRUE);
  228. else {
  229.     echo addHidden('backend''-1');
  230. }
  231. if (isset($session)) {
  232.     echo addHidden('session'$session);
  233. }
  234.  
  235. echo '<input type="submit" value="' _("Search"'" />' .
  236.      '&nbsp;|&nbsp;<input type="submit" value="' _("List all".
  237.      '" name="listall" />' "\n" .
  238.      '</center></td></tr></table>' "\n";
  239. echo '</center></form>';
  240. do_hook('addrbook_html_search_below');
  241. /* End search form */
  242.  
  243. /* Show personal addressbook */
  244.  
  245. if !empty$listall ) ){
  246.     $addrquery '*';
  247. }
  248.  
  249. if ($addrquery == '' && empty($listall)) {
  250.  
  251.     if (isset($backend|| $backend != -|| $addrquery == ''{
  252.         if ($addrquery == ''{
  253.             $backend $abook->localbackend;
  254.         }
  255.  
  256.         /* echo '<h3 align="center">' . $abook->backends[$backend]->sname) . "</h3>\n"; */
  257.  
  258.         $res $abook->list_addr($backend);
  259.  
  260.         if (is_array($res)) {
  261.             usort($res,'alistcmp');
  262.             addr_display_result($resfalse);
  263.         else {
  264.             echo html_tag'p''<strong><br />' .
  265.                  sprintf(_("Unable to list addresses from %s")
  266.                  $abook->backends[$backend]->sname"</strong>\n" ,
  267.             'center' );
  268.         }
  269.  
  270.     else {
  271.         $res $abook->list_addr();
  272.         usort($res,'alistcmp');
  273.         addr_display_result($restrue);
  274.     }
  275.     echo '</body></html>';
  276.     exit;
  277. }
  278. else {
  279.  
  280.     /* Do the search */
  281.     if (!empty($addrquery)) {
  282.  
  283.         if ($backend == -1{
  284.             $res $abook->s_search($addrquery);
  285.         else {
  286.             $res $abook->s_search($addrquery$backend);
  287.         }
  288.  
  289.         if (!is_array($res)) {
  290.             echo html_tag'p''<b><br />' .
  291.                              _("Your search failed with the following error(s)".
  292.                             ':<br />' $abook->error "</b>\n" ,
  293.                    'center' .
  294.             "\n</body></html>\n";
  295.         else {
  296.             if (sizeof($res== 0{
  297.                 echo html_tag'p''<br /><b>' .
  298.                                  _("No persons matching your search were found""</b>\n" ,
  299.                        'center' .
  300.                 "\n</body></html>\n";
  301.             else {
  302.                 addr_display_result($res);
  303.             }
  304.         }
  305.     }
  306. }
  307.  
  308. if ($addrquery == '' || sizeof($res== 0{
  309.     /* printf('<center><form method="post" name="k" action="compose.php">'."\n", $PHP_SELF); */
  310.     echo '<center>'.
  311.         addForm('compose.php','POST','k'''''''TRUE);
  312.     echo '<input type="submit" value="' _("Return"'" name="return" />' "\n" .
  313.          '</form></center></nobr>';
  314. }
  315.  
  316. ?>
  317. </body></html>

Documentation generated on Mon, 13 Jan 2020 04:24:12 +0100 by phpDocumentor 1.4.3