Source for file util_addressbook.php

Documentation is available at util_addressbook.php

  1. <?php
  2. /**
  3.  * util_addressbook.php
  4.  *
  5.  * Functions to make working with address books easier
  6.  * 
  7.  * @copyright &copy; 1999-2006 The SquirrelMail Project Team
  8.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9.  * @version $Id: util_addressbook.php,v 1.2 2006/08/15 15:43:55 stevetruckstuff Exp $
  10.  * @package squirrelmail
  11.  * @subpackage templates
  12.  */
  13.  
  14. /**
  15.  * Display a column header with sort buttons
  16.  * 
  17.  * @param string $field which field to display
  18.  * @author Steve Brown
  19.  * @since 1.5.2
  20.  */
  21. function addAbookSort ($field{
  22.     global $abook_sort_order;
  23.     
  24.     switch ($field{
  25.         case 'nickname':
  26.             $str _("Nickname");
  27.             $alt _("sort by nickname");
  28.             $down 0;
  29.             $up 1;
  30.             $has_sort true;
  31.             break;
  32.         case 'fullname':
  33.             $str _("Name");
  34.             $alt _("sort by name");
  35.             $down 2;
  36.             $up 3;
  37.             $has_sort true;
  38.             break;
  39.         case 'email':
  40.             $str _("E-mail");
  41.             $alt _("sort by email");
  42.             $down 4;
  43.             $up 5;
  44.             $has_sort true;
  45.             break;
  46.         case 'info':
  47.             $str _("Info");
  48.             $alt _("sort by info");
  49.             $down 6;
  50.             $up 7;
  51.             $has_sort true;
  52.             break;
  53.         default:
  54.             return 'BAD SORT FIELD GIVEN: "'.$field.'"';
  55.     }
  56.     
  57.     return $str ($has_sort show_abook_sort_button($abook_sort_order$alt$down$up'');
  58. }
  59.  
  60. /**
  61.  * Create a link to compose an email to the email address given.
  62.  * 
  63.  * @param array $row contact as given to the addressbook_list.tpl template
  64.  * @author Steve Brown
  65.  * @since 1.5.2
  66.  */
  67. function composeLink ($row{
  68.     return makeComposeLink('src/compose.php?send_to=' .
  69.                            rawurlencode($row['FullAddress']),
  70.                            htmlspecialchars($row['Email']));
  71. }
  72.  
  73. /**
  74.  * Format the address book into a format that is easy for template authors
  75.  * to use
  76.  * 
  77.  * @param array $addresses all contacts as given by calling $abook->list_addr()
  78.  * @return array 
  79.  * @author Steve Brown
  80.  * @since 1.5.2
  81.  */
  82. function formatAddressList ($addresses{
  83.     if (!is_array($addresses|| count($addresses== 0)
  84.         return array();
  85.         
  86.     $contacts array();
  87.     while(list($undef,$roweach($addresses)) {
  88.         $contact array (
  89.                             'FirstName'     => htmlspecialchars($row['firstname']),
  90.                             'LastName'      => htmlspecialchars($row['lastname']),
  91.                             'FullName'      => htmlspecialchars($row['name']),
  92.                             'NickName'      => htmlspecialchars($row['nickname']),
  93.                             'Email'         => htmlspecialchars($row['email']),
  94.                             'FullAddress'   => htmlspecialchars(AddressBook::full_address($row)),
  95.                             'Info'          => htmlspecialchars($row['label']),
  96.                             'Extra'         => (isset($row['extra']$row['extra'NULL),
  97.                             'Source'        => htmlspecialchars($row['source']),
  98.                             'JSEmail'       => htmlspecialchars(addcslashes(AddressBook::full_address($row)"'")ENT_QUOTES),
  99.                          );
  100.         $contacts[$contact;
  101.     }
  102.     
  103.     return $contacts;
  104. }
  105.  
  106. /**
  107.  * Function to include JavaScript code
  108.  * @return void 
  109.  */
  110. function insert_javascript({
  111.     ?>
  112.     <script type="text/javascript"><!--
  113.  
  114.     function to_and_close($addr) {
  115.         to_address($addr);
  116.         parent.close();
  117.     }
  118.  
  119.     function to_address($addr) {
  120.         var prefix    = "";
  121.         var pwintype = typeof parent.opener.document.compose;
  122.  
  123.         $addr = $addr.replace(/ {1,35}$/, "");
  124.  
  125.         if (pwintype != "undefined") {
  126.             if (parent.opener.document.compose.send_to.value) {
  127.                 prefix = ", ";
  128.                 parent.opener.document.compose.send_to.value =
  129.                     parent.opener.document.compose.send_to.value + ", " + $addr;
  130.             } else {
  131.                 parent.opener.document.compose.send_to.value = $addr;
  132.             }
  133.         }
  134.     }
  135.  
  136.     function cc_address($addr) {
  137.         var prefix    = "";
  138.         var pwintype = typeof parent.opener.document.compose;
  139.  
  140.         $addr = $addr.replace(/ {1,35}$/, "");
  141.  
  142.         if (pwintype != "undefined") {
  143.             if (parent.opener.document.compose.send_to_cc.value) {
  144.                 prefix = ", ";
  145.                 parent.opener.document.compose.send_to_cc.value =
  146.                     parent.opener.document.compose.send_to_cc.value + ", " + $addr;
  147.             } else {
  148.                 parent.opener.document.compose.send_to_cc.value = $addr;
  149.             }
  150.         }
  151.     }
  152.  
  153.     function bcc_address($addr) {
  154.         var prefix    = "";
  155.         var pwintype = typeof parent.opener.document.compose;
  156.  
  157.         $addr = $addr.replace(/ {1,35}$/, "");
  158.  
  159.         if (pwintype != "undefined") {
  160.             if (parent.opener.document.compose.send_to_bcc.value) {
  161.                 prefix = ", ";
  162.                 parent.opener.document.compose.send_to_bcc.value =
  163.                     parent.opener.document.compose.send_to_bcc.value + ", " + $addr;
  164.             } else {
  165.                 parent.opener.document.compose.send_to_bcc.value = $addr;
  166.             }
  167.         }
  168.     }
  169.  
  170. // --></script>
  171. <?php
  172. /* End of included JavaScript */
  173.  
  174. /**
  175.  * Function to build a list of available backends for searching
  176.  * 
  177.  * @return array 
  178.  * @author Steve Brown
  179.  * @since 1.5.2
  180.  */
  181. function getBackends ({
  182.     global $abook;
  183.     
  184.     $backends array();
  185.     $backends['-1'_("All address books");
  186.     $ret $abook->get_backend_list();
  187.     while (list($undef,$veach($ret)) {
  188.         $backends[$v->bnum$v->sname;
  189.     }
  190.     
  191.     return $backends;
  192. }
  193. ?>

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