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

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