util_addressbook.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * util_addressbook.php
  4. *
  5. * Functions to make working with address books easier
  6. *
  7. * @copyright &copy; 1999-2007 The SquirrelMail Project Team
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @version $Id$
  10. * @package squirrelmail
  11. * @subpackage templates
  12. */
  13. //FIXME: the functions in this file should be reviewed and moved to functions/template/abook_util.php and this file should be removed
  14. /**
  15. * Create a link to compose an email to the email address given.
  16. *
  17. * @param array $row contact as given to the addressbook_list.tpl template
  18. * @author Steve Brown
  19. * @since 1.5.2
  20. */
  21. function composeLink ($row) {
  22. return makeComposeLink('src/compose.php?send_to=' .
  23. rawurlencode($row['RawFullAddress']),
  24. htmlspecialchars($row['Email']));
  25. }
  26. /**
  27. * Format the address book into a format that is easy for template authors
  28. * to use
  29. *
  30. * @param array $addresses all contacts as given by calling $abook->list_addr()
  31. * @return array
  32. * @author Steve Brown
  33. * @since 1.5.2
  34. */
  35. function formatAddressList ($addresses) {
  36. if (!is_array($addresses) || count($addresses) == 0)
  37. return array();
  38. $contacts = array();
  39. while(list($undef,$row) = each($addresses)) {
  40. $contact = array (
  41. 'FirstName' => htmlspecialchars($row['firstname']),
  42. 'LastName' => htmlspecialchars($row['lastname']),
  43. 'FullName' => htmlspecialchars($row['name']),
  44. 'NickName' => htmlspecialchars($row['nickname']),
  45. 'Email' => htmlspecialchars($row['email']),
  46. 'FullAddress' => htmlspecialchars(AddressBook::full_address($row)),
  47. 'RawFullAddress' => AddressBook::full_address($row),
  48. 'Info' => htmlspecialchars($row['label']),
  49. 'Extra' => (isset($row['extra']) ? $row['extra'] : NULL),
  50. 'Source' => htmlspecialchars($row['source']),
  51. 'JSEmail' => htmlspecialchars(addcslashes(AddressBook::full_address($row), "'"), ENT_QUOTES),
  52. );
  53. $contacts[] = $contact;
  54. }
  55. return $contacts;
  56. }
  57. /**
  58. * Function to include JavaScript code
  59. * @return void
  60. */
  61. function insert_javascript() {
  62. ?>
  63. <script type="text/javascript"><!--
  64. function to_and_close($addr) {
  65. to_address($addr);
  66. parent.close();
  67. }
  68. function to_address($addr) {
  69. var prefix = "";
  70. var pwintype = typeof parent.opener.document.compose;
  71. $addr = $addr.replace(/ {1,35}$/, "");
  72. if (pwintype != "undefined") {
  73. if (parent.opener.document.compose.send_to.value) {
  74. prefix = ", ";
  75. parent.opener.document.compose.send_to.value =
  76. parent.opener.document.compose.send_to.value + ", " + $addr;
  77. } else {
  78. parent.opener.document.compose.send_to.value = $addr;
  79. }
  80. }
  81. }
  82. function cc_address($addr) {
  83. var prefix = "";
  84. var pwintype = typeof parent.opener.document.compose;
  85. $addr = $addr.replace(/ {1,35}$/, "");
  86. if (pwintype != "undefined") {
  87. if (parent.opener.document.compose.send_to_cc.value) {
  88. prefix = ", ";
  89. parent.opener.document.compose.send_to_cc.value =
  90. parent.opener.document.compose.send_to_cc.value + ", " + $addr;
  91. } else {
  92. parent.opener.document.compose.send_to_cc.value = $addr;
  93. }
  94. }
  95. }
  96. function bcc_address($addr) {
  97. var prefix = "";
  98. var pwintype = typeof parent.opener.document.compose;
  99. $addr = $addr.replace(/ {1,35}$/, "");
  100. if (pwintype != "undefined") {
  101. if (parent.opener.document.compose.send_to_bcc.value) {
  102. prefix = ", ";
  103. parent.opener.document.compose.send_to_bcc.value =
  104. parent.opener.document.compose.send_to_bcc.value + ", " + $addr;
  105. } else {
  106. parent.opener.document.compose.send_to_bcc.value = $addr;
  107. }
  108. }
  109. }
  110. // --></script>
  111. <?php
  112. } /* End of included JavaScript */
  113. /**
  114. * Function to build a list of available backends for searching
  115. *
  116. * @return array
  117. * @author Steve Brown
  118. * @since 1.5.2
  119. */
  120. function getBackends () {
  121. global $abook;
  122. $backends = array();
  123. $backends['-1'] = _("All address books");
  124. $ret = $abook->get_backend_list();
  125. while (list($undef,$v) = each($ret)) {
  126. if ($v->btype == 'local' && !$v->listing) {
  127. continue;
  128. }
  129. $backends[$v->bnum] = $v->sname;
  130. }
  131. return $backends;
  132. }