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

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