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

Documentation generated on Wed, 22 May 2013 04:21:46 +0200 by phpDocumentor 1.4.3