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

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