MAX_FILE_SIZE hidden field must be before the file input according to the PHP docs
[squirrelmail.git] / templates / 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-2009 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
14 //FIXME: the functions in this file should be reviewed and moved to functions/template/abook_util.php and this file should be removed
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 */
22 function composeLink ($row) {
23 return makeComposeLink('src/compose.php?send_to=' .
24 rawurlencode($row['RawFullAddress']),
25 htmlspecialchars($row['Email']));
26 }
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 */
37 function 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 'RawFullAddress' => AddressBook::full_address($row),
51 'Info' => htmlspecialchars($row['label']),
52 'Extra' => (isset($row['extra']) ? $row['extra'] : NULL),
53 'Source' => htmlspecialchars($row['source']),
54 'JSEmail' => htmlspecialchars(addcslashes(AddressBook::full_address($row), "'"), ENT_QUOTES),
55 );
56 $contacts[] = $contact;
57 }
58
59 return $contacts;
60 }
61
62 /**
63 * Function to include JavaScript code
64 * @return void
65 */
66 function insert_javascript() {
67 ?>
68 <script type="text/javascript"><!--
69
70 function to_and_close($addr) {
71 to_address($addr);
72 parent.close();
73 }
74
75 function to_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.value) {
83 prefix = ", ";
84 parent.opener.document.compose.send_to.value =
85 parent.opener.document.compose.send_to.value + ", " + $addr;
86 } else {
87 parent.opener.document.compose.send_to.value = $addr;
88 }
89 }
90 }
91
92 function cc_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_cc.value) {
100 prefix = ", ";
101 parent.opener.document.compose.send_to_cc.value =
102 parent.opener.document.compose.send_to_cc.value + ", " + $addr;
103 } else {
104 parent.opener.document.compose.send_to_cc.value = $addr;
105 }
106 }
107 }
108
109 function bcc_address($addr) {
110 var prefix = "";
111 var pwintype = typeof parent.opener.document.compose;
112
113 $addr = $addr.replace(/ {1,35}$/, "");
114
115 if (pwintype != "undefined") {
116 if (parent.opener.document.compose.send_to_bcc.value) {
117 prefix = ", ";
118 parent.opener.document.compose.send_to_bcc.value =
119 parent.opener.document.compose.send_to_bcc.value + ", " + $addr;
120 } else {
121 parent.opener.document.compose.send_to_bcc.value = $addr;
122 }
123 }
124 }
125
126 // --></script>
127 <?php
128 } /* End of included JavaScript */
129
130 /**
131 * Function to build a list of available backends for searching
132 *
133 * @return array
134 * @author Steve Brown
135 * @since 1.5.2
136 */
137 function getBackends () {
138 global $abook;
139
140 $backends = array();
141 $backends['-1'] = _("All address books");
142 $ret = $abook->get_backend_list();
143 while (list($undef,$v) = each($ret)) {
144 if ($v->btype == 'local' && !$v->listing) {
145 continue;
146 }
147 $backends[$v->bnum] = $v->sname;
148 }
149
150 return $backends;
151 }