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