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

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