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

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