source: subversion/trunk/roundcubemail/program/steps/addressbook/func.inc @ 4836

Last change on this file since 4836 was 4836, checked in by alec, 2 years ago
  • Call addressbook_get hook only if build-in addressbook doesn't match wanted ID (for better performance), other improvements
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.4 KB
Line 
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, The Roundcube Dev Team                       |
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$SEARCH_MODS_DEFAULT = array('name'=>1, 'firstname'=>1, 'surname'=>1, 'email'=>1, '*'=>1);
23
24// select source
25$source = get_input_value('_source', RCUBE_INPUT_GPC);
26
27if (!$RCMAIL->action && !$OUTPUT->ajax_call) {
28    // add list of address sources to client env
29    $js_list = $RCMAIL->get_address_sources();
30
31    // if source is not set use first directory
32    if (empty($source))
33        $source = $js_list[key($js_list)]['id'];
34
35    $search_mods = $RCMAIL->config->get('addressbook_search_mods', $SEARCH_MODS_DEFAULT);
36    $OUTPUT->set_env('search_mods', $search_mods);
37    $OUTPUT->set_env('address_sources', $js_list);
38}
39
40// instantiate a contacts object according to the given source
41$CONTACTS = $RCMAIL->get_address_book($source);
42
43$CONTACTS->set_pagesize($CONFIG['pagesize']);
44
45// set list properties and session vars
46if (!empty($_GET['_page']))
47    $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page'])));
48else
49    $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1);
50
51if (!empty($_REQUEST['_gid']))
52    $CONTACTS->set_group(get_input_value('_gid', RCUBE_INPUT_GPC));
53/*
54// set message set for search result
55if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
56    $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]);
57*/
58// set data source env
59$OUTPUT->set_env('source', $source ? $source : '0');
60$OUTPUT->set_env('readonly', $CONTACTS->readonly, false);
61if (!$OUTPUT->ajax_call) {
62    $search_mods = $RCMAIL->config->get('addressbook_search_mods', $SEARCH_MODS_DEFAULT);
63    $OUTPUT->set_env('search_mods', $search_mods);
64    $OUTPUT->set_pagetitle(rcube_label('addressbook'));
65}
66
67
68// general definition of contact coltypes
69$CONTACT_COLTYPES = array(
70  'name'         => array('type' => 'text', 'size' => 40, 'limit' => 1, 'label' => rcube_label('name'), 'category' => 'main'),
71  'firstname'    => array('type' => 'text', 'size' => 19, 'limit' => 1, 'label' => rcube_label('firstname'), 'category' => 'main'),
72  'surname'      => array('type' => 'text', 'size' => 19, 'limit' => 1, 'label' => rcube_label('surname'), 'category' => 'main'),
73  'email'        => array('type' => 'text', 'size' => 40, 'label' => rcube_label('email'), 'subtypes' => array('home','work','other'), 'category' => 'main'),
74  'middlename'   => array('type' => 'text', 'size' => 19, 'limit' => 1, 'label' => rcube_label('middlename'), 'category' => 'main'),
75  'prefix'       => array('type' => 'text', 'size' => 8,  'limit' => 1, 'label' => rcube_label('nameprefix'), 'category' => 'main'),
76  'suffix'       => array('type' => 'text', 'size' => 8,  'limit' => 1, 'label' => rcube_label('namesuffix'), 'category' => 'main'),
77  'nickname'     => array('type' => 'text', 'size' => 40, 'limit' => 1, 'label' => rcube_label('nickname'), 'category' => 'main'),
78  'jobtitle'     => array('type' => 'text', 'size' => 40, 'limit' => 1, 'label' => rcube_label('jobtitle'), 'category' => 'main'),
79  'organization' => array('type' => 'text', 'size' => 19, 'limit' => 1, 'label' => rcube_label('organization'), 'category' => 'main'),
80  'department'   => array('type' => 'text', 'size' => 19, 'limit' => 1, 'label' => rcube_label('department'), 'category' => 'main'),
81  'gender'       => array('type' => 'select', 'limit' => 1, 'label' => rcube_label('gender'), 'options' => array('male' => rcube_label('male'), 'female' => rcube_label('female')), 'category' => 'personal'),
82  'maidenname'   => array('type' => 'text', 'size' => 40, 'limit' => 1, 'label' => rcube_label('maidenname'), 'category' => 'personal'),
83  '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'), 'category' => 'main'),
84  'address'      => array('type' => 'composite', 'label' => rcube_label('address'), 'subtypes' => array('home','work','other'), 'childs' => array(
85    'street'     => array('type' => 'text', 'size' => 40, 'label' => rcube_label('street'), 'category' => 'main'),
86    'locality'   => array('type' => 'text', 'size' => 28, 'label' => rcube_label('locality'), 'category' => 'main'),
87    'zipcode'    => array('type' => 'text', 'size' => 8, 'label' => rcube_label('zipcode'), 'category' => 'main'),
88    'region'     => array('type' => 'text', 'size' => 12, 'label' => rcube_label('region'), 'category' => 'main'),
89    'country'    => array('type' => 'text', 'size' => 40, 'label' => rcube_label('country'), 'category' => 'main'),
90  ), 'category' => 'main'),
91  'birthday'     => array('type' => 'date', 'size' => 12, 'label' => rcube_label('birthday'), 'limit' => 1, 'render_func' => 'rcmail_format_date_col', 'category' => 'personal'),
92  'anniversary'  => array('type' => 'date', 'size' => 12, 'label' => rcube_label('anniversary'), 'limit' => 1, 'render_func' => 'rcmail_format_date_col', 'category' => 'personal'),
93  'website'      => array('type' => 'text', 'size' => 40, 'label' => rcube_label('website'), 'subtypes' => array('homepage','work','blog','other'), 'category' => 'main'),
94  'im'           => array('type' => 'text', 'size' => 40, 'label' => rcube_label('instantmessenger'), 'subtypes' => array('aim','icq','msn','yahoo','jabber','skype','other'), 'category' => 'main'),
95  'notes'        => array('type' => 'textarea', 'size' => 40, 'rows' => 15, 'label' => rcube_label('notes'), 'limit' => 1),
96  'photo'        => array('type' => 'image', 'limit' => 1, 'category' => 'main'),
97  'assistant'    => array('type' => 'text', 'size' => 40, 'limit' => 1, 'label' => rcube_label('assistant'), 'category' => 'personal'),
98  'manager'      => array('type' => 'text', 'size' => 40, 'limit' => 1, 'label' => rcube_label('manager'), 'category' => 'personal'),
99  'spouse'       => array('type' => 'text', 'size' => 40, 'limit' => 1, 'label' => rcube_label('spouse'), 'category' => 'personal'),
100  // TODO: define fields for vcards like GEO, KEY
101);
102
103// reduce/extend $CONTACT_COLTYPES with specification from the current $CONTACT object
104if (is_array($CONTACTS->coltypes)) {
105    // remove cols not listed by the backend class
106    $contact_cols = $CONTACTS->coltypes[0] ? array_flip($CONTACTS->coltypes) : $CONTACTS->coltypes;
107    $CONTACT_COLTYPES = array_intersect_key($CONTACT_COLTYPES, $contact_cols);
108    // add associative coltypes definition
109    if (!$CONTACTS->coltypes[0]) {
110        foreach ($CONTACTS->coltypes as $col => $colprop)
111            $CONTACT_COLTYPES[$col] = $CONTACT_COLTYPES[$col] ? array_merge($CONTACT_COLTYPES[$col], $colprop) : $colprop;
112    }
113}
114
115$OUTPUT->set_env('photocol', is_array($CONTACT_COLTYPES['photo']));
116
117
118function rcmail_directory_list($attrib)
119{
120    global $RCMAIL, $OUTPUT;
121
122    if (!$attrib['id'])
123        $attrib['id'] = 'rcmdirectorylist';
124
125    $out = '';
126    $local_id = '0';
127    $jsdata = array();
128    $current = get_input_value('_source', RCUBE_INPUT_GPC);
129    $line_templ = html::tag('li', array(
130        'id' => 'rcmli%s', 'class' => 'addressbook %s'),
131        html::a(array('href' => '%s',
132            'rel' => '%s',
133            'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s'));
134
135    // currently selected is the first address source in the list
136    if (!isset($current))
137        $current = strval(key((array)$OUTPUT->env['address_sources']));
138
139    foreach ((array)$OUTPUT->env['address_sources'] as $j => $source) {
140        $id = strval($source['id'] ? $source['id'] : $j);
141        $js_id = JQ($id);
142        $out .= sprintf($line_templ,
143            html_identifier($id),
144            ($current === $id ? 'selected' : ''),
145            Q(rcmail_url(null, array('_source' => $id))),
146            $source['id'],
147            $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id)));
148
149        $groupdata = array('out' => $out, 'jsdata' => $jsdata, 'source' => $id);
150        if ($source['groups'])
151            $groupdata = rcmail_contact_groups($groupdata);
152        $jsdata = $groupdata['jsdata'];
153        $out = $groupdata['out'];
154    }
155
156    $OUTPUT->set_env('contactgroups', $jsdata);
157    $OUTPUT->add_gui_object('folderlist', $attrib['id']);
158
159    return html::tag('ul', $attrib, $out, html::$common_attrib);
160}
161
162
163function rcmail_contact_groups($args)
164{
165    global $RCMAIL;
166
167    $groups = $RCMAIL->get_address_book($args['source'])->list_groups();
168
169    if (!empty($groups)) {
170        $line_templ = html::tag('li', array(
171            'id' => 'rcmliG%s', 'class' => 'contactgroup'),
172            html::a(array('href' => '#',
173                'rel' => '%s:%s',
174                'onclick' => "return ".JS_OBJECT_NAME.".command('listgroup',{'source':'%s','id':'%s'},this)"), '%s'));
175
176        $jsdata = array();
177        foreach ($groups as $group) {
178            $args['out'] .= sprintf($line_templ,
179                html_identifier($args['source'] . $group['ID']),
180                $args['source'], $group['ID'],
181                $args['source'], $group['ID'], Q($group['name'])
182            );
183            $args['jsdata']['G'.$args['source'].$group['ID']] = array(
184                'source' => $args['source'], 'id' => $group['ID'],
185                'name' => $group['name'], 'type' => 'group');
186        }
187    }
188
189    return $args;
190}
191
192
193// return the message list as HTML table
194function rcmail_contacts_list($attrib)
195{
196    global $CONTACTS, $OUTPUT;
197
198    // define list of cols to be displayed
199    $a_show_cols = array('name');
200
201    // count contacts for this user
202    $result = $CONTACTS->list_records($a_show_cols);
203
204    // add id to message list table if not specified
205    if (!strlen($attrib['id']))
206        $attrib['id'] = 'rcmAddressList';
207
208    // create XHTML table
209    $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key);
210
211    // set client env
212    $OUTPUT->add_gui_object('contactslist', $attrib['id']);
213    $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page);
214    $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size));
215    $OUTPUT->include_script('list.js');
216
217    // add some labels to client
218    $OUTPUT->add_label('deletecontactconfirm');
219
220    return $out;
221}
222
223
224function rcmail_js_contacts_list($result, $prefix='')
225{
226    global $OUTPUT;
227
228    if (empty($result) || $result->count == 0)
229        return;
230
231    // define list of cols to be displayed
232    $a_show_cols = array('name');
233
234    while ($row = $result->next()) {
235        $a_row_cols = array();
236
237        // format each col
238        foreach ($a_show_cols as $col)
239            $a_row_cols[$col] = Q($row[$col]);
240
241        $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
242    }
243}
244
245
246// similar function as /steps/settings/identities.inc::rcmail_identity_frame()
247function rcmail_contact_frame($attrib)
248{
249    global $OUTPUT;
250
251    if (!$attrib['id'])
252        $attrib['id'] = 'rcmcontactframe';
253   
254    $attrib['name'] = $attrib['id'];
255
256    $OUTPUT->set_env('contentframe', $attrib['name']);
257    $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
258
259    return html::iframe($attrib);
260}
261
262
263function rcmail_rowcount_display($attrib)
264{
265    global $OUTPUT;
266
267    if (!$attrib['id'])
268        $attrib['id'] = 'rcmcountdisplay';
269
270    $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
271
272    return html::span($attrib, rcmail_get_rowcount_text());
273}
274
275
276function rcmail_get_rowcount_text()
277{
278    global $CONTACTS;
279 
280    // read nr of contacts
281    $result = $CONTACTS->get_result();
282    if (!$result) {
283        $result = $CONTACTS->count();
284    }
285
286    if ($result->count == 0)
287        $out = rcube_label('nocontactsfound');
288    else
289        $out = rcube_label(array(
290            'name'  => 'contactsfromto',
291            'vars'  => array(
292            'from'  => $result->first + 1,
293            'to'    => min($result->count, $result->first + $CONTACTS->page_size),
294            'count' => $result->count)
295        ));
296
297    return $out;
298}
299
300
301function rcmail_get_type_label($type)
302{
303    $label = 'type'.$type;
304    if (rcube_label_exists($label))
305        return rcube_label($label);
306    else if (preg_match('/\w+(\d+)$/', $label, $m)
307            && ($label = preg_replace('/(\d+)$/', '', $label))
308            && rcube_label_exists($label))
309        return rcube_label($label) . ' ' . $m[1];
310   
311    return ucfirst($type);
312}
313
314
315function rcmail_contact_form($form, $record, $attrib = null)
316{
317    global $RCMAIL, $CONFIG;
318
319    // Allow plugins to modify contact form content
320    $plugin = $RCMAIL->plugins->exec_hook('contact_form', array(
321        'form' => $form, 'record' => $record));
322
323    $form = $plugin['form'];
324    $record = $plugin['record'];
325    $edit_mode = $RCMAIL->action != 'show';
326    $del_button = $attrib['deleteicon'] ? html::img(array('src' => $CONFIG['skin_path'] . $attrib['deleteicon'], 'alt' => rcube_label('delete'))) : rcube_label('delete');
327    unset($attrib['deleteicon']);
328    $out = '';
329   
330    // get default coltypes
331    $coltypes = $GLOBALS['CONTACT_COLTYPES'];
332    $coltype_labels = array();
333   
334    foreach ($coltypes as $col => $prop) {
335        if ($prop['subtypes']) {
336            $subtype_names = array_map('rcmail_get_type_label', $prop['subtypes']);
337            $select_subtype = new html_select(array('name' => '_subtype_'.$col.'[]', 'class' => 'contactselectsubtype'));
338            $select_subtype->add($subtype_names, $prop['subtypes']);
339            $coltypes[$col]['subtypes_select'] = $select_subtype->show();
340        }
341        if ($prop['childs']) {
342            foreach ($prop['childs'] as $childcol => $cp)
343                $coltype_labels[$childcol] = array('label' => $cp['label']);
344        }
345    }
346
347    foreach ($form as $section => $fieldset) {
348        // skip empty sections
349        if (empty($fieldset['content']))
350            continue;
351
352        $select_add = new html_select(array('class' => 'addfieldmenu', 'rel' => $section));
353        $select_add->add(rcube_label('addfield'), '');
354
355        // render head section with name fields (not a regular list of rows)
356        if ($section == 'head') {
357            $content = '';
358
359            // unset display name if it is composed from name parts (same composition function as in save.inc)
360            if ($record['name'] == rcube_addressbook::compose_display_name(array('name' => '') + (array)$record))
361              unset($record['name']);
362
363            // group fields
364            $field_blocks = array(
365                'names'    => array('prefix','firstname','middlename','surname','suffix'),
366                'displayname' => array('name'),
367                'nickname' => array('nickname'),
368                'jobnames' => array('organization','department','jobtitle'),
369            );
370            foreach ($field_blocks as $blockname => $colnames) {
371                $fields = '';
372                foreach ($colnames as $col) {
373                    // skip cols unknown to the backend
374                    if (!$coltypes[$col])
375                        continue;
376                   
377                    // only string values are expected here
378                    if (is_array($record[$col]))
379                        $record[$col] = join(' ', $record[$col]);
380
381                    if ($RCMAIL->action == 'show') {
382                        if (!empty($record[$col]))
383                            $fields .= html::span('namefield ' . $col, Q($record[$col])) . " ";
384                    }
385                    else {
386                        $colprop = (array)$fieldset['content'][$col] + (array)$coltypes[$col];
387                        $colprop['id'] = 'ff_'.$col;
388                        if (empty($record[$col]) && !$colprop['visible']) {
389                            $colprop['style'] = 'display:none';
390                            $select_add->add($colprop['label'], $col);
391                        }
392                        $fields .= rcmail_get_edit_field($col, $record[$col], $colprop, $colprop['type']);
393                    }
394                }
395                $content .= html::div($blockname, $fields);
396            }
397           
398            if ($edit_mode)
399                $content .= html::p('addfield', $select_add->show(null));
400
401            $out .= html::tag('fieldset', $attrib, (!empty($fieldset['name']) ? html::tag('legend', null, Q($fieldset['name'])) : '') . $content) ."\n";
402            continue;
403        }
404
405        $content = '';
406        if (is_array($fieldset['content'])) {
407            foreach ($fieldset['content'] as $col => $colprop) {
408                // remove subtype part of col name
409                list($field, $subtype) = explode(':', $col);
410                if (!$subtype) $subtype = 'home';
411                $fullkey = $col.':'.$subtype;
412
413                // skip cols unknown to the backend
414                if (!$coltypes[$field])
415                    continue;
416
417                // merge colprop with global coltype configuration
418                $colprop += $coltypes[$field];
419                $label = isset($colprop['label']) ? $colprop['label'] : rcube_label($col);
420
421                // prepare subtype selector in edit mode
422                if ($edit_mode && is_array($colprop['subtypes'])) {
423                    $subtype_names = array_map('rcmail_get_type_label', $colprop['subtypes']);
424                    $select_subtype = new html_select(array('name' => '_subtype_'.$col.'[]', 'class' => 'contactselectsubtype'));
425                    $select_subtype->add($subtype_names, $colprop['subtypes']);
426                }
427                else
428                    $select_subtype = null;
429
430                if (!empty($colprop['value'])) {
431                    $values = (array)$colprop['value'];
432                }
433                else {
434                    // iterate over possible subtypes and collect values with their subtype
435                    if (is_array($colprop['subtypes'])) {
436                        $values = $subtypes = array();
437                        foreach ($colprop['subtypes'] as $i => $st) {
438                            $newval = false;
439                            if ($record[$field.':'.$st]) {
440                                $subtypes[count($values)] = $st;
441                                $newval = $record[$field.':'.$st];
442                            }
443                            else if ($i == 0 && $record[$field]) {
444                                $subtypes[count($values)] = $st;
445                                $newval = $record[$field];
446                            }
447                            if ($newval !== false) {
448                                if (is_array($newval) && isset($newval[0]))
449                                    $values = array_merge($values, $newval);
450                                else
451                                    $values[] = $newval;
452                            }
453                        }
454                    }
455                    else {
456                        $values = $record[$fullkey] ? $record[$fullkey] : $record[$field];
457                        $subtypes = null;
458                    }
459                }
460
461                // hack: create empty values array to force this field to be displayed
462                if (empty($values) && $colprop['visible'])
463                    $values[] = '';
464
465                $rows = '';
466                foreach ((array)$values as $i => $val) {
467                    if ($subtypes[$i])
468                        $subtype = $subtypes[$i];
469
470                    // render composite field
471                    if ($colprop['type'] == 'composite') {
472                        $composite = array(); $j = 0;
473                        $template = $RCMAIL->config->get($col . '_template', '{'.join('} {', array_keys($colprop['childs'])).'}');
474                        foreach ($colprop['childs'] as $childcol => $cp) {
475                            $childvalue = $val[$childcol] ? $val[$childcol] : $val[$j];
476
477                            if ($edit_mode) {
478                                if ($colprop['subtypes'] || $colprop['limit'] != 1) $cp['array'] = true;
479                                $composite['{'.$childcol.'}'] = rcmail_get_edit_field($childcol, $childvalue, $cp, $cp['type']) . " ";
480                            }
481                            else {
482                                $childval = $cp['render_func'] ? call_user_func($cp['render_func'], $childvalue, $childcol) : Q($childvalue);
483                                $composite['{'.$childcol.'}'] = html::span('data ' . $childcol, $childval) . " ";
484                            }
485                            $j++;
486                        }
487
488                        $coltypes[$field] += (array)$colprop;
489                        $coltypes[$field]['count']++;
490                        $val = strtr($template, $composite);
491                    }
492                    else if ($edit_mode) {
493                        // call callback to render/format value
494                        if ($colprop['render_func'])
495                            $val = call_user_func($colprop['render_func'], $val, $col);
496
497                        $coltypes[$field] = (array)$colprop + $coltypes[$field];
498
499                        if ($colprop['subtypes'] || $colprop['limit'] != 1)
500                            $colprop['array'] = true;
501
502                        $val = rcmail_get_edit_field($col, $val, $colprop, $colprop['type']);
503                        $coltypes[$field]['count']++;
504                    }
505                    else if ($colprop['render_func'])
506                        $val = call_user_func($colprop['render_func'], $val, $col);
507                    else if (is_array($colprop['options']) && isset($colprop['options'][$val]))
508                        $val = $colprop['options'][$val];
509                    else
510                        $val = Q($val);
511
512                    // use subtype as label
513                    if ($colprop['subtypes'])
514                        $label = rcmail_get_type_label($subtype);
515
516                    // add delete button/link
517                    if ($edit_mode && !($colprop['visible'] && $colprop['limit'] == 1))
518                        $val .= html::a(array('href' => '#del', 'class' => 'contactfieldbutton deletebutton', 'title' => rcube_label('delete'), 'rel' => $col), $del_button);
519
520                    // display row with label
521                    if ($label) {
522                        $rows .= html::div('row',
523                            html::div('contactfieldlabel label', $select_subtype ? $select_subtype->show($subtype) : Q($label)) .
524                            html::div('contactfieldcontent '.$colprop['type'], $val));
525                    }
526                    else   // row without label
527                        $rows .= html::div('row', html::div('contactfield', $val));
528                }
529               
530                // add option to the add-field menu
531                if (!$colprop['limit'] || $coltypes[$field]['count'] < $colprop['limit']) {
532                    $select_add->add($colprop['label'], $col);
533                    $select_add->_count++;
534                }
535               
536                // wrap rows in fieldgroup container
537                $content .= html::tag('fieldset', array('class' => 'contactfieldgroup ' . ($colprop['subtypes'] ? 'contactfieldgroupmulti ' : '') . 'contactcontroller' . $col, 'style' => ($rows ? null : 'display:none')),
538                  ($colprop['subtypes'] ? html::tag('legend', null, Q($colprop['label'])) : ' ') .
539                  $rows);
540            }
541
542            // also render add-field selector
543            if ($edit_mode)
544                $content .= html::p('addfield', $select_add->show(null, array('style' => $select_add->_count ? null : 'display:none')));
545
546            $content = html::div(array('id' => 'contactsection' . $section), $content);
547        }
548        else {
549            $content = $fieldset['content'];
550        }
551
552        $out .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $content) ."\n";
553    }
554
555    if ($edit_mode) {
556      $RCMAIL->output->set_env('coltypes', $coltypes + $coltype_labels);
557      $RCMAIL->output->set_env('delbutton', $del_button);
558      $RCMAIL->output->add_label('delete');
559    }
560
561    return $out;
562}
563
564
565function rcmail_contact_photo($attrib)
566{
567    global $CONTACTS, $CONTACT_COLTYPES, $RCMAIL, $CONFIG;
568
569    if (!$CONTACT_COLTYPES['photo'])
570        return '';
571
572    if ($result = $CONTACTS->get_result())
573        $record = $result->first();
574
575    $photo_img = $attrib['placeholder'] ? $CONFIG['skin_path'] . $attrib['placeholder'] : 'program/blank.gif';
576    $RCMAIL->output->set_env('photo_placeholder', $photo_img);
577    unset($attrib['placeholder']);
578
579    if (strpos($record['photo'], 'http:') === 0)
580        $photo_img = $record['photo'];
581    else if ($record['photo'])
582        $photo_img = $RCMAIL->url(array('_action' => 'photo', '_cid' => $record['ID'], '_source' => $_REQUEST['_source']));
583    else
584        $ff_value = '-del-'; // will disable delete-photo action
585
586    $img = html::img(array('src' => $photo_img, 'border' => 1, 'alt' => ''));
587    $content = html::div($attrib, $img);
588
589    if ($RCMAIL->action == 'edit' || $RCMAIL->action == 'add') {
590        $RCMAIL->output->add_gui_object('contactphoto', $attrib['id']);
591        $hidden = new html_hiddenfield(array('name' => '_photo', 'id' => 'ff_photo', 'value' => $ff_value));
592        $content .= $hidden->show();
593    }
594
595    return $content;
596}
597
598
599function rcmail_format_date_col($val)
600{
601    global $RCMAIL;
602    return format_date($val, $RCMAIL->config->get('date_format', 'Y-m-d'));
603}
604
605
606// register UI objects
607$OUTPUT->add_handlers(array(
608    'directorylist' => 'rcmail_directory_list',
609//  'groupslist' => 'rcmail_contact_groups',
610    'addresslist' => 'rcmail_contacts_list',
611    'addressframe' => 'rcmail_contact_frame',
612    'recordscountdisplay' => 'rcmail_rowcount_display',
613    'searchform' => array($OUTPUT, 'search_form')
614));
615
616// register action aliases
617$RCMAIL->register_action_map(array(
618    'add' => 'edit.inc',
619    'photo' => 'show.inc',
620    'upload-photo' => 'save.inc',
621    'group-create' => 'groups.inc',
622    'group-rename' => 'groups.inc',
623    'group-delete' => 'groups.inc',
624    'group-addmembers' => 'groups.inc',
625    'group-delmembers' => 'groups.inc',
626));
Note: See TracBrowser for help on using the repository browser.