| 1 | <?php |
| 2 | /** |
| 3 | * util_addressbook.php |
| 4 | * |
| 5 | * Functions to make working with address books easier |
| 6 | * |
| 7 | * @copyright 1999-2021 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 | sm_encode_html_special_chars($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 | foreach($addresses as $row) { |
| 43 | $contact = array ( |
| 44 | 'FirstName' => sm_encode_html_special_chars($row['firstname']), |
| 45 | 'LastName' => sm_encode_html_special_chars($row['lastname']), |
| 46 | 'FullName' => sm_encode_html_special_chars($row['name']), |
| 47 | 'NickName' => sm_encode_html_special_chars($row['nickname']), |
| 48 | 'Email' => sm_encode_html_special_chars($row['email']), |
| 49 | 'FullAddress' => sm_encode_html_special_chars(AddressBook::full_address($row)), |
| 50 | 'RawFullAddress' => AddressBook::full_address($row), |
| 51 | 'Info' => sm_encode_html_special_chars($row['label']), |
| 52 | 'Extra' => (isset($row['extra']) ? $row['extra'] : NULL), |
| 53 | 'Source' => sm_encode_html_special_chars($row['source']), |
| 54 | 'JSEmail' => sm_encode_html_special_chars(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 | function CheckAll(ch) { |
| 127 | var chkObj = ""; |
| 128 | for (var i = 0; i < document.addressbook.elements.length; i++) { |
| 129 | chkObj = document.addressbook.elements[i]; |
| 130 | if (chkObj.type == "checkbox" && chkObj.name.substr(0,16) == "send_to_search[" + ch) { |
| 131 | chkObj.checked = !(chkObj.checked); |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | // --></script> |
| 137 | <?php |
| 138 | } /* End of included JavaScript */ |
| 139 | |
| 140 | /** |
| 141 | * Function to build a list of available backends for searching |
| 142 | * |
| 143 | * @return array |
| 144 | * @author Steve Brown |
| 145 | * @since 1.5.2 |
| 146 | */ |
| 147 | function getBackends () { |
| 148 | global $abook; |
| 149 | |
| 150 | $backends = array(); |
| 151 | $backends['-1'] = _("All address books"); |
| 152 | $ret = $abook->get_backend_list(); |
| 153 | foreach ($ret as $v) { |
| 154 | if ($v->btype == 'local' && !$v->listing) { |
| 155 | continue; |
| 156 | } |
| 157 | $backends[$v->bnum] = $v->sname; |
| 158 | } |
| 159 | |
| 160 | return $backends; |
| 161 | } |