source: github/program/steps/addressbook/func.inc @ ca7dda4

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