| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | +-----------------------------------------------------------------------+ |
|---|
| 5 | | program/steps/addressbook/func.inc | |
|---|
| 6 | | | |
|---|
| 7 | | This file is part of the Roundcube Webmail client | |
|---|
| 8 | | Copyright (C) 2005-2007, Roundcube Dev. - Switzerland | |
|---|
| 9 | | Licensed under the GNU GPL | |
|---|
| 10 | | | |
|---|
| 11 | | PURPOSE: | |
|---|
| 12 | | Provide addressbook functionality and GUI objects | |
|---|
| 13 | | | |
|---|
| 14 | +-----------------------------------------------------------------------+ |
|---|
| 15 | | Author: Thomas Bruederli <roundcube@gmail.com> | |
|---|
| 16 | +-----------------------------------------------------------------------+ |
|---|
| 17 | |
|---|
| 18 | $Id$ |
|---|
| 19 | |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | // add list of address sources to client env |
|---|
| 23 | $js_list = $RCMAIL->get_address_sources(); |
|---|
| 24 | |
|---|
| 25 | // select source |
|---|
| 26 | $source = get_input_value('_source', RCUBE_INPUT_GPC); |
|---|
| 27 | |
|---|
| 28 | // if source is not set use first directory |
|---|
| 29 | if (empty($source)) |
|---|
| 30 | $source = $js_list[key($js_list)]['id']; |
|---|
| 31 | |
|---|
| 32 | // instantiate a contacts object according to the given source |
|---|
| 33 | $CONTACTS = $RCMAIL->get_address_book($source); |
|---|
| 34 | |
|---|
| 35 | $CONTACTS->set_pagesize($CONFIG['pagesize']); |
|---|
| 36 | |
|---|
| 37 | // set list properties and session vars |
|---|
| 38 | if (!empty($_GET['_page'])) |
|---|
| 39 | $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page']))); |
|---|
| 40 | else |
|---|
| 41 | $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1); |
|---|
| 42 | |
|---|
| 43 | if (!empty($_REQUEST['_gid'])) |
|---|
| 44 | $CONTACTS->set_group(get_input_value('_gid', RCUBE_INPUT_GPC)); |
|---|
| 45 | |
|---|
| 46 | // set message set for search result |
|---|
| 47 | if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']])) |
|---|
| 48 | $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]); |
|---|
| 49 | |
|---|
| 50 | // set data source env |
|---|
| 51 | $OUTPUT->set_env('source', $source ? $source : '0'); |
|---|
| 52 | $OUTPUT->set_env('readonly', $CONTACTS->readonly, false); |
|---|
| 53 | if (!$OUTPUT->ajax_call) { |
|---|
| 54 | $OUTPUT->set_env('address_sources', $js_list); |
|---|
| 55 | $OUTPUT->set_pagetitle(rcube_label('addressbook')); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | // general definition of contact coltypes |
|---|
| 60 | $CONTACT_COLTYPES = array( |
|---|
| 61 | 'name' => array('type' => 'text', 'size' => 40, 'limit' => 1, 'label' => rcube_label('name')), |
|---|
| 62 | 'firstname' => array('type' => 'text', 'size' => 19, 'limit' => 1, 'label' => rcube_label('firstname')), |
|---|
| 63 | 'surname' => array('type' => 'text', 'size' => 19, 'limit' => 1, 'label' => rcube_label('surname')), |
|---|
| 64 | 'middlename' => array('type' => 'text', 'size' => 19, 'limit' => 1, 'label' => rcube_label('middlename')), |
|---|
| 65 | 'prefix' => array('type' => 'text', 'size' => 8, 'limit' => 1, 'label' => rcube_label('nameprefix')), |
|---|
| 66 | 'suffix' => array('type' => 'text', 'size' => 8, 'limit' => 1, 'label' => rcube_label('namesuffix')), |
|---|
| 67 | 'nickname' => array('type' => 'text', 'size' => 40, 'limit' => 1, 'label' => rcube_label('nickname')), |
|---|
| 68 | 'jobtitle' => array('type' => 'text', 'size' => 40, 'limit' => 1, 'label' => rcube_label('jobtitle')), |
|---|
| 69 | 'organization' => array('type' => 'text', 'size' => 19, 'limit' => 1, 'label' => rcube_label('organization')), |
|---|
| 70 | 'department' => array('type' => 'text', 'size' => 19, 'limit' => 1, 'label' => rcube_label('department')), |
|---|
| 71 | 'gender' => array('type' => 'select', 'limit' => 1, 'label' => rcube_label('gender'), 'options' => array('male' => rcube_label('male'), 'female' => rcube_label('female'))), |
|---|
| 72 | 'maidenname' => array('type' => 'text', 'size' => 40, 'limit' => 1, 'label' => rcube_label('maidenname')), |
|---|
| 73 | 'email' => array('type' => 'text', 'size' => 40, 'label' => rcube_label('email'), 'subtypes' => array('home','work','other')), |
|---|
| 74 | 'phone' => array('type' => 'text', 'size' => 40, 'label' => rcube_label('phone'), 'subtypes' => array('home','home2','work','work2','mobile','main','homefax','workfax','car','pager','video','assistant','other')), |
|---|
| 75 | 'address' => array('type' => 'composite', 'label' => rcube_label('address'), 'subtypes' => array('home','work','other'), 'childs' => array( |
|---|
| 76 | 'street' => array('type' => 'text', 'size' => 40, 'label' => rcube_label('street')), |
|---|
| 77 | 'locality' => array('type' => 'text', 'size' => 28, 'label' => rcube_label('locality')), |
|---|
| 78 | 'zipcode' => array('type' => 'text', 'size' => 8, 'label' => rcube_label('zipcode')), |
|---|
| 79 | 'region' => array('type' => 'text', 'size' => 12, 'label' => rcube_label('region')), |
|---|
| 80 | 'country' => array('type' => 'text', 'size' => 40, 'label' => rcube_label('country')), |
|---|
| 81 | )), |
|---|
| 82 | 'birthday' => array('type' => 'date', 'size' => 12, 'label' => rcube_label('birthday'), 'limit' => 1, 'render_func' => 'rcmail_format_date_col'), |
|---|
| 83 | 'website' => array('type' => 'text', 'size' => 40, 'label' => rcube_label('website'), 'subtypes' => array('home','work','blog','other')), |
|---|
| 84 | 'im' => array('type' => 'text', 'size' => 40, 'label' => rcube_label('instantmessenger'), 'subtypes' => array('aim','icq','msn','yahoo','jabber','other')), |
|---|
| 85 | 'notes' => array('type' => 'textarea', 'size' => 40, 'rows' => 15, 'label' => rcube_label('notes'), 'limit' => 1), |
|---|
| 86 | // TODO: define fields for vcards GEO, PHOTO, KEY, X-ANNIVERSARY, X-ASSISTANT, X-MANAGER |
|---|
| 87 | ); |
|---|
| 88 | |
|---|
| 89 | // reduce/extend $CONTACT_COLTYPES with specification from the current $CONTACT object |
|---|
| 90 | if (is_array($CONTACTS->coltypes)) { |
|---|
| 91 | // remove cols not listed by the backend class |
|---|
| 92 | $contact_cols = $CONTACTS->coltypes[0] ? array_flip($CONTACTS->coltypes) : $CONTACTS->coltypes; |
|---|
| 93 | $CONTACT_COLTYPES = array_intersect_key($CONTACT_COLTYPES, $contact_cols); |
|---|
| 94 | // add associative coltypes definition |
|---|
| 95 | if (!$CONTACTS->coltypes[0]) { |
|---|
| 96 | foreach ($CONTACTS->coltypes as $col => $colprop) |
|---|
| 97 | $CONTACT_COLTYPES[$col] = $CONTACT_COLTYPES[$col] ? array_merge($CONTACT_COLTYPES[$col], $colprop) : $colprop; |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | function rcmail_directory_list($attrib) |
|---|
| 103 | { |
|---|
| 104 | global $RCMAIL, $OUTPUT; |
|---|
| 105 | |
|---|
| 106 | if (!$attrib['id']) |
|---|
| 107 | $attrib['id'] = 'rcmdirectorylist'; |
|---|
| 108 | |
|---|
| 109 | $out = ''; |
|---|
| 110 | $local_id = '0'; |
|---|
| 111 | $jsdata = array(); |
|---|
| 112 | $current = get_input_value('_source', RCUBE_INPUT_GPC); |
|---|
| 113 | $line_templ = html::tag('li', array( |
|---|
| 114 | 'id' => 'rcmli%s', 'class' => 'addressbook %s'), |
|---|
| 115 | html::a(array('href' => '%s', |
|---|
| 116 | 'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s')); |
|---|
| 117 | |
|---|
| 118 | if (!$current && strtolower($RCMAIL->config->get('address_book_type', 'sql')) != 'ldap') { |
|---|
| 119 | $current = '0'; |
|---|
| 120 | } |
|---|
| 121 | else if (!$current) { |
|---|
| 122 | // DB address book not used, see if a source is set, if not use the |
|---|
| 123 | // first LDAP directory. |
|---|
| 124 | $current = key((array)$RCMAIL->config->get('ldap_public', array())); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | foreach ((array)$OUTPUT->env['address_sources'] as $j => $source) { |
|---|
| 128 | $id = $source['id'] ? $source['id'] : $j; |
|---|
| 129 | $js_id = JQ($id); |
|---|
| 130 | $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id); |
|---|
| 131 | $out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''), |
|---|
| 132 | Q(rcmail_url(null, array('_source' => $id))), |
|---|
| 133 | $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id))); |
|---|
| 134 | $groupdata = rcmail_contact_groups(array('out' => $out, 'jsdata' => $jsdata, 'source' => $id)); |
|---|
| 135 | $jsdata = $groupdata['jsdata']; |
|---|
| 136 | $out = $groupdata['out']; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | $OUTPUT->set_env('contactgroups', $jsdata); |
|---|
| 140 | $OUTPUT->add_gui_object('folderlist', $attrib['id']); |
|---|
| 141 | |
|---|
| 142 | return html::tag('ul', $attrib, $out, html::$common_attrib); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | function rcmail_contact_groups($args) |
|---|
| 147 | { |
|---|
| 148 | global $RCMAIL; |
|---|
| 149 | |
|---|
| 150 | $groups = $RCMAIL->get_address_book($args['source'])->list_groups(); |
|---|
| 151 | |
|---|
| 152 | if (!empty($groups)) { |
|---|
| 153 | $line_templ = html::tag('li', array( |
|---|
| 154 | 'id' => 'rcmliG%s%s', 'class' => 'contactgroup'), |
|---|
| 155 | html::a(array('href' => '#', |
|---|
| 156 | 'onclick' => "return ".JS_OBJECT_NAME.".command('listgroup',{'source':'%s','id':'%s'},this)"), '%s')); |
|---|
| 157 | |
|---|
| 158 | $jsdata = array(); |
|---|
| 159 | foreach ($groups as $group) { |
|---|
| 160 | $args['out'] .= sprintf($line_templ, $args['source'], $group['ID'], $args['source'], $group['ID'], Q($group['name'])); |
|---|
| 161 | $args['jsdata']['G'.$args['source'].$group['ID']] = array( |
|---|
| 162 | 'source' => $args['source'], 'id' => $group['ID'], |
|---|
| 163 | 'name' => $group['name'], 'type' => 'group'); |
|---|
| 164 | } |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | return $args; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | // return the message list as HTML table |
|---|
| 172 | function rcmail_contacts_list($attrib) |
|---|
| 173 | { |
|---|
| 174 | global $CONTACTS, $OUTPUT; |
|---|
| 175 | |
|---|
| 176 | // count contacts for this user |
|---|
| 177 | $result = $CONTACTS->list_records(); |
|---|
| 178 | |
|---|
| 179 | // add id to message list table if not specified |
|---|
| 180 | if (!strlen($attrib['id'])) |
|---|
| 181 | $attrib['id'] = 'rcmAddressList'; |
|---|
| 182 | |
|---|
| 183 | // define list of cols to be displayed |
|---|
| 184 | $a_show_cols = array('name'); |
|---|
| 185 | |
|---|
| 186 | // create XHTML table |
|---|
| 187 | $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key); |
|---|
| 188 | |
|---|
| 189 | // set client env |
|---|
| 190 | $OUTPUT->add_gui_object('contactslist', $attrib['id']); |
|---|
| 191 | $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page); |
|---|
| 192 | $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size)); |
|---|
| 193 | $OUTPUT->include_script('list.js'); |
|---|
| 194 | |
|---|
| 195 | // add some labels to client |
|---|
| 196 | $OUTPUT->add_label('deletecontactconfirm'); |
|---|
| 197 | |
|---|
| 198 | return $out; |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | function rcmail_js_contacts_list($result, $prefix='') |
|---|
| 203 | { |
|---|
| 204 | global $OUTPUT; |
|---|
| 205 | |
|---|
| 206 | if (empty($result) || $result->count == 0) |
|---|
| 207 | return; |
|---|
| 208 | |
|---|
| 209 | // define list of cols to be displayed |
|---|
| 210 | $a_show_cols = array('name'); |
|---|
| 211 | |
|---|
| 212 | while ($row = $result->next()) { |
|---|
| 213 | $a_row_cols = array(); |
|---|
| 214 | |
|---|
| 215 | // format each col |
|---|
| 216 | foreach ($a_show_cols as $col) |
|---|
| 217 | $a_row_cols[$col] = Q($row[$col]); |
|---|
| 218 | |
|---|
| 219 | $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols); |
|---|
| 220 | } |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | // similar function as /steps/settings/identities.inc::rcmail_identity_frame() |
|---|
| 225 | function rcmail_contact_frame($attrib) |
|---|
| 226 | { |
|---|
| 227 | global $OUTPUT; |
|---|
| 228 | |
|---|
| 229 | if (!$attrib['id']) |
|---|
| 230 | $attrib['id'] = 'rcmcontactframe'; |
|---|
| 231 | |
|---|
| 232 | $attrib['name'] = $attrib['id']; |
|---|
| 233 | |
|---|
| 234 | $OUTPUT->set_env('contentframe', $attrib['name']); |
|---|
| 235 | $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif'); |
|---|
| 236 | |
|---|
| 237 | return html::iframe($attrib); |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | function rcmail_rowcount_display($attrib) |
|---|
| 242 | { |
|---|
| 243 | global $OUTPUT; |
|---|
| 244 | |
|---|
| 245 | if (!$attrib['id']) |
|---|
| 246 | $attrib['id'] = 'rcmcountdisplay'; |
|---|
| 247 | |
|---|
| 248 | $OUTPUT->add_gui_object('countdisplay', $attrib['id']); |
|---|
| 249 | |
|---|
| 250 | return html::span($attrib, rcmail_get_rowcount_text()); |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | function rcmail_get_rowcount_text() |
|---|
| 255 | { |
|---|
| 256 | global $CONTACTS; |
|---|
| 257 | |
|---|
| 258 | // read nr of contacts |
|---|
| 259 | $result = $CONTACTS->get_result(); |
|---|
| 260 | if (!$result) { |
|---|
| 261 | $result = $CONTACTS->count(); |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | if ($result->count == 0) |
|---|
| 265 | $out = rcube_label('nocontactsfound'); |
|---|
| 266 | else |
|---|
| 267 | $out = rcube_label(array( |
|---|
| 268 | 'name' => 'contactsfromto', |
|---|
| 269 | 'vars' => array( |
|---|
| 270 | 'from' => $result->first + 1, |
|---|
| 271 | 'to' => min($result->count, $result->first + $CONTACTS->page_size), |
|---|
| 272 | 'count' => $result->count) |
|---|
| 273 | )); |
|---|
| 274 | |
|---|
| 275 | return $out; |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | function rcmail_contact_form($form, $record, $attrib = null) |
|---|
| 280 | { |
|---|
| 281 | global $RCMAIL, $CONFIG; |
|---|
| 282 | |
|---|
| 283 | // Allow plugins to modify contact form content |
|---|
| 284 | $plugin = $RCMAIL->plugins->exec_hook('contact_form', array( |
|---|
| 285 | 'form' => $form, 'record' => $record)); |
|---|
| 286 | |
|---|
| 287 | $form = $plugin['form']; |
|---|
| 288 | $record = $plugin['record']; |
|---|
| 289 | $formdata = array(); |
|---|
| 290 | $del_button = $attrib['deleteicon'] ? html::img(array('src' => $CONFIG['skin_path'] . $attrib['deleteicon'], 'alt' => rcube_label('delete'))) : rcube_label('delete'); |
|---|
| 291 | $edit_mode = $RCMAIL->action != 'show'; |
|---|
| 292 | $out = ''; |
|---|
| 293 | |
|---|
| 294 | // get default coltypes |
|---|
| 295 | $coltypes = $GLOBALS['CONTACT_COLTYPES']; |
|---|
| 296 | $coltype_lables = array(); |
|---|
| 297 | |
|---|
| 298 | foreach ($coltypes as $col => $prop) { |
|---|
| 299 | if ($prop['subtypes']) { |
|---|
| 300 | $select_subtype = new html_select(array('name' => '_subtype_'.$col.'[]', 'class' => 'contactselectsubtype')); |
|---|
| 301 | $select_subtype->add($prop['subtypes']); |
|---|
| 302 | $coltypes[$col]['subtypes_select'] = $select_subtype->show(); |
|---|
| 303 | } |
|---|
| 304 | if ($prop['childs']) { |
|---|
| 305 | foreach ($prop['childs'] as $childcol => $cp) |
|---|
| 306 | $coltype_lables[$childcol] = array('label' => $cp['label']); |
|---|
| 307 | } |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | foreach ($form as $section => $fieldset) { |
|---|
| 311 | // skip empty sections |
|---|
| 312 | if (empty($fieldset['content'])) |
|---|
| 313 | continue; |
|---|
| 314 | |
|---|
| 315 | $select_add = new html_select(array('class' => 'addfieldmenu', 'rel' => $section)); |
|---|
| 316 | $select_add->add(rcube_label('addfield'), ''); |
|---|
| 317 | |
|---|
| 318 | // render head section with name fields (not a regular list of rows) |
|---|
| 319 | if ($section == 'head') { |
|---|
| 320 | $content = ''; |
|---|
| 321 | |
|---|
| 322 | $names_arr = array($record['prefix'], $record['firstname'], $record['middlename'], $record['surname'], $record['suffix']); |
|---|
| 323 | if ($record['name'] == join(' ', array_filter($names_arr))) |
|---|
| 324 | unset($record['name']); |
|---|
| 325 | |
|---|
| 326 | // group fields |
|---|
| 327 | $field_blocks = array( |
|---|
| 328 | 'names' => array('prefix','firstname','middlename','surname','suffix'), |
|---|
| 329 | 'addnames' => array('name','nickname'), |
|---|
| 330 | 'jobnames' => array('organization','department','jobtitle'), |
|---|
| 331 | ); |
|---|
| 332 | foreach ($field_blocks as $blockname => $colnames) { |
|---|
| 333 | $fields = ''; |
|---|
| 334 | foreach ($colnames as $col) { |
|---|
| 335 | // skip cols unknown to the backend |
|---|
| 336 | if (!$coltypes[$col]) |
|---|
| 337 | continue; |
|---|
| 338 | |
|---|
| 339 | if ($RCMAIL->action == 'show') { |
|---|
| 340 | if (!empty($record[$col])) |
|---|
| 341 | $fields .= html::span('namefield ' . $col, Q($record[$col])) . " "; |
|---|
| 342 | } |
|---|
| 343 | else { |
|---|
| 344 | $colprop = (array)$fieldset['content'][$col] + (array)$coltypes[$col]; |
|---|
| 345 | $colprop['id'] = 'ff_'.$col; |
|---|
| 346 | if (empty($record[$col]) && !$colprop['visible']) { |
|---|
| 347 | $colprop['style'] = 'display:none'; |
|---|
| 348 | $select_add->add($colprop['label'], $col); |
|---|
| 349 | } |
|---|
| 350 | $fields .= rcmail_get_edit_field($col, $record[$col], $colprop, $colprop['type']); |
|---|
| 351 | } |
|---|
| 352 | } |
|---|
| 353 | $content .= html::div($blockname, $fields); |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | if ($edit_mode) |
|---|
| 357 | $content .= html::p('addfield', $select_add->show(null)); |
|---|
| 358 | |
|---|
| 359 | $out .= html::tag('fieldset', $attrib, (!empty($fieldset['name']) ? html::tag('legend', null, Q($fieldset['name'])) : '') . $content) ."\n"; |
|---|
| 360 | continue; |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | $content = ''; |
|---|
| 364 | if (is_array($fieldset['content'])) { |
|---|
| 365 | foreach ($fieldset['content'] as $col => $colprop) { |
|---|
| 366 | // remove subtype part of col name |
|---|
| 367 | list($field, $subtype) = explode(':', $col); |
|---|
| 368 | if (!$subtype) $subtype = 'home'; |
|---|
| 369 | $fullkey = $col.':'.$subtype; |
|---|
| 370 | |
|---|
| 371 | // skip cols unknown to the backend |
|---|
| 372 | if (!$coltypes[$field]) |
|---|
| 373 | continue; |
|---|
| 374 | |
|---|
| 375 | // merge colprop with global coltype configuration |
|---|
| 376 | $colprop += $coltypes[$field]; |
|---|
| 377 | $label = isset($colprop['label']) ? $colprop['label'] : rcube_label($col); |
|---|
| 378 | |
|---|
| 379 | // prepare subtype selector in edit mode |
|---|
| 380 | if ($edit_mode && is_array($colprop['subtypes'])) { |
|---|
| 381 | $select_subtype = new html_select(array('name' => '_subtype_'.$col.'[]', 'class' => 'contactselectsubtype')); |
|---|
| 382 | $select_subtype->add($colprop['subtypes']); |
|---|
| 383 | } |
|---|
| 384 | else |
|---|
| 385 | $select_subtype = null; |
|---|
| 386 | |
|---|
| 387 | if (!empty($colprop['value'])) { |
|---|
| 388 | $values = (array)$colprop['value']; |
|---|
| 389 | } |
|---|
| 390 | else { |
|---|
| 391 | // iterate over possible subtypes and collect values with their subtype |
|---|
| 392 | if (is_array($colprop['subtypes'])) { |
|---|
| 393 | $values = $subtypes = array(); |
|---|
| 394 | foreach ($colprop['subtypes'] as $i => $st) { |
|---|
| 395 | $newval = false; |
|---|
| 396 | if ($record[$field.':'.$st]) { |
|---|
| 397 | $subtypes[count($values)] = $st; |
|---|
| 398 | $newval = $record[$field.':'.$st]; |
|---|
| 399 | } |
|---|
| 400 | else if ($i == 0 && $record[$field]) { |
|---|
| 401 | $subtypes[count($values)] = $st; |
|---|
| 402 | $newval = $record[$field]; |
|---|
| 403 | } |
|---|
| 404 | if ($newval !== false) { |
|---|
| 405 | if (is_array($newval) && isset($newval[0])) |
|---|
| 406 | $values = array_merge($values, $newval); |
|---|
| 407 | else |
|---|
| 408 | $values[] = $newval; |
|---|
| 409 | } |
|---|
| 410 | } |
|---|
| 411 | } |
|---|
| 412 | else { |
|---|
| 413 | $values = $record[$fullkey] ? $record[$fullkey] : $record[$field]; |
|---|
| 414 | $subtypes = null; |
|---|
| 415 | } |
|---|
| 416 | } |
|---|
| 417 | |
|---|
| 418 | // hack: create empty values array to force this field to be displayed |
|---|
| 419 | if (empty($values) && $colprop['visible']) |
|---|
| 420 | $values[] = ''; |
|---|
| 421 | |
|---|
| 422 | $rows = ''; |
|---|
| 423 | foreach ((array)$values as $i => $val) { |
|---|
| 424 | if ($subtypes[$i]) |
|---|
| 425 | $subtype = $subtypes[$i]; |
|---|
| 426 | |
|---|
| 427 | // render composite field |
|---|
| 428 | if ($colprop['type'] == 'composite') { |
|---|
| 429 | $composite = ''; $j = 0; |
|---|
| 430 | foreach ($colprop['childs'] as $childcol => $cp) { |
|---|
| 431 | $childvalue = $val[$childcol] ? $val[$childcol] : $val[$j]; |
|---|
| 432 | |
|---|
| 433 | if ($edit_mode) { |
|---|
| 434 | if ($colprop['subtypes'] || $colprop['limit'] != 1) $cp['array'] = true; |
|---|
| 435 | $composite .= rcmail_get_edit_field($childcol, $childvalue, $cp, $cp['type']) . " "; |
|---|
| 436 | } |
|---|
| 437 | else { |
|---|
| 438 | $childval = $cp['render_func'] ? call_user_func($cp['render_func'], $childvalue, $childcol) : Q($childvalue); |
|---|
| 439 | $composite .= html::span('data ' . $childcol, $childval) . " "; |
|---|
| 440 | } |
|---|
| 441 | $j++; |
|---|
| 442 | } |
|---|
| 443 | |
|---|
| 444 | $coltypes[$field] += (array)$colprop; |
|---|
| 445 | $coltypes[$field]['count']++; |
|---|
| 446 | $val = $composite; |
|---|
| 447 | } |
|---|
| 448 | else if ($edit_mode) { |
|---|
| 449 | // call callback to render/format value |
|---|
| 450 | if ($colprop['render_func']) |
|---|
| 451 | $val = call_user_func($colprop['render_func'], $val, $col); |
|---|
| 452 | |
|---|
| 453 | $coltypes[$field] = (array)$colprop + $coltypes[$field]; |
|---|
| 454 | $formdata[$field][] = array('subtype' => $subtype, 'value' => $val); |
|---|
| 455 | |
|---|
| 456 | if ($colprop['subtypes'] || $colprop['limit'] != 1) |
|---|
| 457 | $colprop['array'] = true; |
|---|
| 458 | |
|---|
| 459 | $val = rcmail_get_edit_field($col, $val, $colprop, $colprop['type']); |
|---|
| 460 | $coltypes[$field]['count']++; |
|---|
| 461 | } |
|---|
| 462 | else if ($colprop['render_func']) |
|---|
| 463 | $val = call_user_func($colprop['render_func'], $val, $col); |
|---|
| 464 | else if (is_array($colprop['options']) && isset($colprop['options'][$val])) |
|---|
| 465 | $val = $colprop['options'][$val]; |
|---|
| 466 | else |
|---|
| 467 | $val = Q($val); |
|---|
| 468 | |
|---|
| 469 | // use subtype as label |
|---|
| 470 | if ($colprop['subtypes']) |
|---|
| 471 | $label = $subtype; |
|---|
| 472 | |
|---|
| 473 | // add delete button/link |
|---|
| 474 | if ($edit_mode && !($colprop['visible'] && $colprop['limit'] == 1)) |
|---|
| 475 | $val .= html::a(array('href' => '#del', 'class' => 'contactfieldbutton deletebutton', 'title' => rcube_label('delete'), 'rel' => $col), $del_button); |
|---|
| 476 | |
|---|
| 477 | // display row with label |
|---|
| 478 | if ($label) { |
|---|
| 479 | $rows .= html::div('row', |
|---|
| 480 | html::div('contactfieldlabel label', $select_subtype ? $select_subtype->show($subtype) : Q($label)) . |
|---|
| 481 | html::div('contactfieldcontent '.$colprop['type'], $val)); |
|---|
| 482 | } |
|---|
| 483 | else // row without label |
|---|
| 484 | $rows .= html::div('row', html::div('contactfield', $val)); |
|---|
| 485 | } |
|---|
| 486 | |
|---|
| 487 | // add option to the add-field menu |
|---|
| 488 | if (!$colprop['limit'] || $coltypes[$field]['count'] < $colprop['limit']) { |
|---|
| 489 | $select_add->add($colprop['label'], $col); |
|---|
| 490 | $select_add->_count++; |
|---|
| 491 | } |
|---|
| 492 | |
|---|
| 493 | // wrap rows in fieldgroup container |
|---|
| 494 | $content .= html::div('contactfieldgroup contactcontroller' . $col, $rows); |
|---|
| 495 | } |
|---|
| 496 | |
|---|
| 497 | // also render add-field selector |
|---|
| 498 | if ($edit_mode && $select_add->_count) |
|---|
| 499 | $content .= html::p('addfield', $select_add->show(null)); |
|---|
| 500 | |
|---|
| 501 | $content = html::div(array('id' => 'contactsection' . $section), $content); |
|---|
| 502 | } |
|---|
| 503 | else { |
|---|
| 504 | $content = $fieldset['content']; |
|---|
| 505 | } |
|---|
| 506 | |
|---|
| 507 | $out .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $content) ."\n"; |
|---|
| 508 | } |
|---|
| 509 | |
|---|
| 510 | if ($edit_mode) { |
|---|
| 511 | $RCMAIL->output->set_env('contactdata', $formdata); |
|---|
| 512 | $RCMAIL->output->set_env('coltypes', $coltypes + $coltype_lables); |
|---|
| 513 | $RCMAIL->output->set_env('delbutton', $del_button); |
|---|
| 514 | $RCMAIL->output->add_label('delete'); |
|---|
| 515 | } |
|---|
| 516 | |
|---|
| 517 | return $out; |
|---|
| 518 | } |
|---|
| 519 | |
|---|
| 520 | |
|---|
| 521 | function rcmail_format_date_col($val) |
|---|
| 522 | { |
|---|
| 523 | global $RCMAIL; |
|---|
| 524 | return format_date($val, $RCMAIL->config->get('date_format', 'Y-m-d')); |
|---|
| 525 | } |
|---|
| 526 | |
|---|
| 527 | |
|---|
| 528 | // register UI objects |
|---|
| 529 | $OUTPUT->add_handlers(array( |
|---|
| 530 | 'directorylist' => 'rcmail_directory_list', |
|---|
| 531 | // 'groupslist' => 'rcmail_contact_groups', |
|---|
| 532 | 'addresslist' => 'rcmail_contacts_list', |
|---|
| 533 | 'addressframe' => 'rcmail_contact_frame', |
|---|
| 534 | 'recordscountdisplay' => 'rcmail_rowcount_display', |
|---|
| 535 | 'searchform' => array($OUTPUT, 'search_form') |
|---|
| 536 | )); |
|---|