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

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