Add more functions for address book templating
authorstevetruckstuff <stevetruckstuff@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 15 Aug 2006 15:43:55 +0000 (15:43 +0000)
committerstevetruckstuff <stevetruckstuff@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 15 Aug 2006 15:43:55 +0000 (15:43 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@11591 7612ce4b-ef26-0410-bec9-ea0150e637f0

templates/util_addressbook.php

index ca2967b37d414f5ed99561eee2972c35e863bae4..09cde519b72d64483145919f7ef9371afe85faad 100644 (file)
@@ -69,4 +69,125 @@ function composeLink ($row) {
                            rawurlencode($row['FullAddress']),
                            htmlspecialchars($row['Email']));
 }
                            rawurlencode($row['FullAddress']),
                            htmlspecialchars($row['Email']));
 }
+
+/**
+ * Format the address book into a format that is easy for template authors
+ * to use
+ * 
+ * @param array $addresses all contacts as given by calling $abook->list_addr()
+ * @return array
+ * @author Steve Brown
+ * @since 1.5.2
+ */
+function formatAddressList ($addresses) {
+    if (!is_array($addresses) || count($addresses) == 0)
+        return array();
+        
+    $contacts = array();
+    while(list($undef,$row) = each($addresses)) {
+        $contact = array (
+                            'FirstName'     => htmlspecialchars($row['firstname']),
+                            'LastName'      => htmlspecialchars($row['lastname']),
+                            'FullName'      => htmlspecialchars($row['name']),
+                            'NickName'      => htmlspecialchars($row['nickname']),
+                            'Email'         => htmlspecialchars($row['email']),
+                            'FullAddress'   => htmlspecialchars(AddressBook::full_address($row)),
+                            'Info'          => htmlspecialchars($row['label']),
+                            'Extra'         => (isset($row['extra']) ? $row['extra'] : NULL),
+                            'Source'        => htmlspecialchars($row['source']),
+                            'JSEmail'       => htmlspecialchars(addcslashes(AddressBook::full_address($row), "'"), ENT_QUOTES),
+                         );
+        $contacts[] = $contact;
+    }
+    
+    return $contacts;
+}
+
+/**
+ * Function to include JavaScript code
+ * @return void
+ */
+function insert_javascript() {
+    ?>
+    <script type="text/javascript"><!--
+
+    function to_and_close($addr) {
+        to_address($addr);
+        parent.close();
+    }
+
+    function to_address($addr) {
+        var prefix    = "";
+        var pwintype = typeof parent.opener.document.compose;
+
+        $addr = $addr.replace(/ {1,35}$/, "");
+
+        if (pwintype != "undefined") {
+            if (parent.opener.document.compose.send_to.value) {
+                prefix = ", ";
+                parent.opener.document.compose.send_to.value =
+                    parent.opener.document.compose.send_to.value + ", " + $addr;
+            } else {
+                parent.opener.document.compose.send_to.value = $addr;
+            }
+        }
+    }
+
+    function cc_address($addr) {
+        var prefix    = "";
+        var pwintype = typeof parent.opener.document.compose;
+
+        $addr = $addr.replace(/ {1,35}$/, "");
+
+        if (pwintype != "undefined") {
+            if (parent.opener.document.compose.send_to_cc.value) {
+                prefix = ", ";
+                parent.opener.document.compose.send_to_cc.value =
+                    parent.opener.document.compose.send_to_cc.value + ", " + $addr;
+            } else {
+                parent.opener.document.compose.send_to_cc.value = $addr;
+            }
+        }
+    }
+
+    function bcc_address($addr) {
+        var prefix    = "";
+        var pwintype = typeof parent.opener.document.compose;
+
+        $addr = $addr.replace(/ {1,35}$/, "");
+
+        if (pwintype != "undefined") {
+            if (parent.opener.document.compose.send_to_bcc.value) {
+                prefix = ", ";
+                parent.opener.document.compose.send_to_bcc.value =
+                    parent.opener.document.compose.send_to_bcc.value + ", " + $addr;
+            } else {
+                parent.opener.document.compose.send_to_bcc.value = $addr;
+            }
+        }
+    }
+
+// --></script>
+<?php
+} /* End of included JavaScript */
+
+/**
+ * Function to build a list of available backends for searching
+ * 
+ * @return array
+ * @author Steve Brown
+ * @since 1.5.2
+ */
+function getBackends () {
+    global $abook;
+    
+    $backends = array();
+    $backends['-1'] = _("All address books");
+    $ret = $abook->get_backend_list();
+    while (list($undef,$v) = each($ret)) {
+        $backends[$v->bnum] = $v->sname;
+    }
+    
+    return $backends;
+}
 ?>
\ No newline at end of file
 ?>
\ No newline at end of file