Source for file addrbook_search.php

Documentation is available at addrbook_search.php

  1. <?php
  2.  
  3. /**
  4.  * addrbook_search.php
  5.  *
  6.  * Handle addressbook searching in the popup window.
  7.  *
  8.  * NOTE: A lot of this code is similar to the code in
  9.  *       addrbook_search_html.html -- If you change one,
  10.  *       change the other one too!
  11.  *
  12.  * @copyright 1999-2014 The SquirrelMail Project Team
  13.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  14.  * @version $Id: addrbook_search.php 14422 2014-01-01 20:59:43Z pdontthink $
  15.  * @package squirrelmail
  16.  * @subpackage addressbook
  17.  */
  18.  
  19. /** This is the addrbook_search page */
  20. define('PAGE_NAME''addrbook_search');
  21.  
  22. /**
  23.  * Path for SquirrelMail required files.
  24.  * @ignore
  25.  */
  26. define('SM_PATH','../');
  27.  
  28. /** SquirrelMail required files. */
  29. require_once(SM_PATH 'include/validate.php');
  30. require_once(SM_PATH 'functions/html.php');
  31. require_once(SM_PATH 'functions/forms.php');
  32. require_once(SM_PATH 'functions/addressbook.php');
  33.  
  34. /** lets get the global vars we may need */
  35. sqgetGlobalVar('key',       $key,           SQ_COOKIE);
  36. sqgetGlobalVar('username',  $username,      SQ_SESSION);
  37. sqgetGlobalVar('onetimepad',$onetimepad,    SQ_SESSION);
  38. sqgetGlobalVar('base_uri',  $base_uri,      SQ_SESSION);
  39.  
  40. sqgetGlobalVar('show' ,   $show);
  41. sqgetGlobalVar('query',   $query,   SQ_POST);
  42. sqgetGlobalVar('listall'$listallSQ_POST);
  43. sqgetGlobalVar('backend'$backendSQ_POST);
  44.  
  45. /**
  46.  * Function to include JavaScript code
  47.  * @return void 
  48.  */
  49. function insert_javascript({
  50.     ?>
  51.     <script language="Javascript"><!--
  52.  
  53.     function to_and_close($addr) {
  54.         to_address($addr);
  55.         parent.close();
  56.     }
  57.  
  58.     function to_address($addr) {
  59.         var prefix    = "";
  60.         var pwintype = typeof parent.opener.document.compose;
  61.  
  62.         $addr = $addr.replace(/ {1,35}$/, "");
  63.  
  64.         if (pwintype != "undefined") {
  65.             if (parent.opener.document.compose.send_to.value) {
  66.                 prefix = ", ";
  67.                 parent.opener.document.compose.send_to.value =
  68.                     parent.opener.document.compose.send_to.value + ", " + $addr;
  69.             } else {
  70.                 parent.opener.document.compose.send_to.value = $addr;
  71.             }
  72.         }
  73.     }
  74.  
  75.     function cc_address($addr) {
  76.         var prefix    = "";
  77.         var pwintype = typeof parent.opener.document.compose;
  78.  
  79.         $addr = $addr.replace(/ {1,35}$/, "");
  80.  
  81.         if (pwintype != "undefined") {
  82.             if (parent.opener.document.compose.send_to_cc.value) {
  83.                 prefix = ", ";
  84.                 parent.opener.document.compose.send_to_cc.value =
  85.                     parent.opener.document.compose.send_to_cc.value + ", " + $addr;
  86.             } else {
  87.                 parent.opener.document.compose.send_to_cc.value = $addr;
  88.             }
  89.         }
  90.     }
  91.  
  92.     function bcc_address($addr) {
  93.         var prefix    = "";
  94.         var pwintype = typeof parent.opener.document.compose;
  95.  
  96.         $addr = $addr.replace(/ {1,35}$/, "");
  97.  
  98.         if (pwintype != "undefined") {
  99.             if (parent.opener.document.compose.send_to_bcc.value) {
  100.                 prefix = ", ";
  101.                 parent.opener.document.compose.send_to_bcc.value =
  102.                     parent.opener.document.compose.send_to_bcc.value + ", " + $addr;
  103.             } else {
  104.                 parent.opener.document.compose.send_to_bcc.value = $addr;
  105.             }
  106.         }
  107.     }
  108.  
  109. // --></script>
  110. <?php
  111. /* End of included JavaScript */
  112.  
  113.  
  114. /**
  115.  * List search results
  116.  * @param array $res Array of search results
  117.  * @param bool $includesource [Default=true]
  118.  * @return void 
  119.  */
  120. function display_result($res$includesource true{
  121.     global $color;
  122.         
  123.     if(sizeof($res<= 0return;
  124.         
  125.         
  126.     $line 0;
  127.     echo html_tag'table''''center''''border="0" width="98%"' .
  128.     html_tag'tr'''''$color[9.
  129.     html_tag'th''&nbsp;''left' .
  130.     html_tag'th''&nbsp;' _("Name")'left' .
  131.     html_tag'th''&nbsp;' _("E-mail")'left' .
  132.     html_tag'th''&nbsp;' _("Info")'left' );
  133.  
  134.     if ($includesource{
  135.         echo html_tag'th''&nbsp;' _("Source")'left''''width="10%"' );
  136.     }    
  137.     echo "</tr>\n";
  138.     
  139.     while (list($undef$roweach($res)) {
  140.         $email sm_encode_html_special_chars(addcslashes(AddressBook::full_address($row)"'")ENT_QUOTES);
  141.         if ($line 2
  142.             $tr_bgcolor $color[12];
  143.         else {
  144.             $tr_bgcolor $color[4];
  145.         }
  146.         echo html_tag'tr'''''$tr_bgcolor'nowrap' .
  147.         html_tag'td',
  148.              '<small><a href="javascript:to_address(' 
  149.                                        "'" $email "');\">"._("To")."</a> | " .
  150.              '<a href="javascript:cc_address(' 
  151.                                        "'" $email "');\">"._("Cc")."</a> | " .
  152.              '<a href="javascript:bcc_address(' 
  153.                                  "'" $email "');\">"._("Bcc")."</a></small>",
  154.         'center''''valign="top" width="5%" nowrap' .
  155.         html_tag'td''&nbsp;' sm_encode_html_special_chars($row['name'])'left''''valign="top" nowrap' .
  156.         html_tag'td''&nbsp;' .
  157.              '<a href="javascript:to_and_close(' .
  158.                  "'" $email "');\">" sm_encode_html_special_chars($row['email']'</a>'
  159.         'left''''valign="top"' .
  160.         html_tag'td'sm_encode_html_special_chars($row['label'])'left''''valign="top" nowrap' );
  161.         if ($includesource{
  162.             echo html_tag'td''&nbsp;' $row['source']'left''''valign="top" nowrap' );
  163.         }
  164.  
  165.         echo "</tr>\n";
  166.         $line++;
  167.     }
  168.     echo '</table>';
  169. }
  170.  
  171. /* ================= End of functions ================= */
  172.     
  173.     
  174.     
  175. /* Initialize vars */
  176. if (!isset($query)) $query ''}
  177. if (!isset($show))  $show  ''}
  178. if (!isset($backend)) $backend ''}
  179.  
  180. /* Choose correct colors for top and bottom frame */
  181. if ($show == 'form' && !isset($listall)) {
  182.     echo '<body text="' $color[6'" bgcolor="' $color[3'" ' .
  183.                'link="' $color[6'" vlink="'   $color[6'" ' .
  184.                                         'alink="'   $color[6'" ' .
  185.          'OnLoad="document.sform.query.focus();">';
  186. else {
  187.     echo '<body text="' $color[8'" bgcolor="' $color[4'" ' .
  188.                'link="' $color[7'" vlink="'   $color[7'" ' .
  189.                                         'alink="'   $color[7"\">\n";
  190. }
  191.  
  192. /* Empty search */
  193. if (empty($query&& empty($show&& empty($listall)) {
  194.     echo html_tag'p''<br />' .
  195.                       _("No persons matching your search were found"),
  196.             'center' .
  197.           "\n</body></html>\n";
  198.     exit;
  199. }
  200.  
  201. /* Initialize addressbook */
  202. $abook addressbook_init();
  203.  
  204. /* Create search form */
  205. if ($show == 'form' && empty($listall)) {
  206.     echo '<form name="sform" target="abookres" action="addrbook_search.php'
  207.             '" method="post">' "\n" .
  208.          html_tag'table''''''''border="0" width="100%" height="100%"' .
  209.          html_tag'tr' .
  210.          html_tag'td''  <strong>' _("Search for""</strong>\n"'left''''nowrap valign="middle" width="10%"' .
  211.          html_tag'td''''left''''' .
  212.          addInput('query'$query28);
  213.  
  214.     /* List all backends to allow the user to choose where to search */
  215.     if ($abook->numbackends 1{
  216.         echo '<strong>' _("in"'</strong>&nbsp;'."\n";
  217.         $selopts array();
  218.         $selopts['-1'_("All address books");
  219.  
  220.         $ret $abook->get_backend_list();
  221.         while (list($undef,$veach($ret)) {
  222.             $selopts[$v->bnum$v->sname;
  223.         }
  224.         echo addSelect('backend'$selopts'-1'TRUE);
  225.     else {
  226.         echo addHidden('backend''-1');
  227.     }
  228.         
  229.     echo '</td></tr>' .
  230.     html_tag'tr',
  231.                     html_tag'td''''left' .
  232.                     html_tag'td',
  233.                             '<input type="submit" value="' _("Search"'" name="show" />' .
  234.                             '&nbsp;|&nbsp;<input type="submit" value="' _("List all".
  235.                             '" name="listall" />' "\n" .
  236.                             '&nbsp;|&nbsp;<input type="button" value="' _("Close".
  237.                             '" onclick="parent.close();" />' "\n" ,
  238.                     'left' )
  239.             .
  240.          '</table></form>' "\n";
  241. else {
  242.  
  243.     /* Show personal addressbook */
  244.     if ($show == 'blank' && empty($listall)) {
  245.  
  246.         if($backend != -|| $show == 'blank'{
  247.             if ($show == 'blank'{
  248.                 $backend $abook->localbackend;
  249.             }
  250.             $res $abook->list_addr($backend);
  251.  
  252.             if(is_array($res)) {
  253.                 usort($res,'alistcmp');
  254.                 display_result($resfalse);
  255.             else {
  256.                 echo html_tag'p''<strong>' .
  257.                                  sprintf(_("Unable to list addresses from %s"),
  258.                                      $abook->backends[$backend]->sname'</strong>' ,
  259.                        'center' "\n";
  260.             }
  261.         else {
  262.             $res $abook->list_addr();
  263.             usort($res,'alistcmp');
  264.             display_result($restrue);
  265.         }
  266.  
  267.     else {
  268.         if!empty$listall ) ){
  269.           $query '*';
  270.         }
  271.  
  272.         /* Do the search */
  273.         if (!empty($query)) {
  274.     
  275.             if($backend == -1{
  276.                 $res $abook->s_search($query);
  277.             else {
  278.                 $res $abook->s_search($query$backend);
  279.             }
  280.         
  281.             if (!is_array($res)) {
  282.                 echo html_tag'p''<b><br />' .
  283.                                  _("Your search failed with the following error(s)".
  284.                                  ':<br />' $abook->error "</b>\n" ,
  285.                        'center' .
  286.                 "\n</body></html>\n";
  287.                 exit;
  288.             }
  289.         
  290.             if (sizeof($res== 0{
  291.                 echo html_tag'p''<br /><b>' .
  292.                                  _("No persons matching your search were found""</b>\n" ,
  293.                        'center' .
  294.                 "\n</body></html>\n";
  295.                 exit;
  296.             }
  297.         
  298.             display_result($res);
  299.         }
  300.     }
  301.    
  302. }
  303. ?>
  304. </body></html>

Documentation generated on Fri, 24 Oct 2014 04:20:18 +0200 by phpDocumentor 1.4.3