|
|
|
@ -538,9 +538,17 @@ function rcmail_contact_form($form, $record, $attrib = null)
|
|
|
|
|
$record = $plugin['record'];
|
|
|
|
|
$head_fields = $plugin['head_fields'];
|
|
|
|
|
$edit_mode = $RCMAIL->action != 'show' && $RCMAIL->action != 'print';
|
|
|
|
|
$del_button = $attrib['deleteicon'] ? html::img(array('src' => $RCMAIL->output->get_skin_file($attrib['deleteicon']), 'alt' => $RCMAIL->gettext('delete'))) : $RCMAIL->gettext('delete');
|
|
|
|
|
$compact = rcube_utils::get_boolean($attrib['compact-form']);
|
|
|
|
|
$use_labels = rcube_utils::get_boolean($attrib['use-labels']);
|
|
|
|
|
$out = '';
|
|
|
|
|
|
|
|
|
|
if ($attrib['deleteicon']) {
|
|
|
|
|
$del_button = html::img(array('src' => $RCMAIL->output->get_skin_file($attrib['deleteicon']), 'alt' => $RCMAIL->gettext('delete')));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$del_button = html::span('inner', $RCMAIL->gettext('delete'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unset($attrib['deleteicon']);
|
|
|
|
|
|
|
|
|
|
// get default coltypes
|
|
|
|
@ -566,7 +574,7 @@ function rcmail_contact_form($form, $record, $attrib = null)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$select_add = new html_select(array('class' => 'addfieldmenu', 'rel' => $section));
|
|
|
|
|
$select_add = new html_select(array('class' => 'addfieldmenu', 'rel' => $section, 'data-compact' => $compact ? "true" : null));
|
|
|
|
|
$select_add->add($RCMAIL->gettext('addfield'), '');
|
|
|
|
|
|
|
|
|
|
// render head section with name fields (not a regular list of rows)
|
|
|
|
@ -579,11 +587,14 @@ function rcmail_contact_form($form, $record, $attrib = null)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($head_fields as $blockname => $colnames) {
|
|
|
|
|
$fields = '';
|
|
|
|
|
$fields = '';
|
|
|
|
|
$block_attr = array('class' => $blockname . (count($colnames) == 1 ? ' row' : ''));
|
|
|
|
|
|
|
|
|
|
foreach ($colnames as $col) {
|
|
|
|
|
// skip cols unknown to the backend
|
|
|
|
|
if (!$coltypes[$col])
|
|
|
|
|
if (!$coltypes[$col]) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// skip cols not listed in the form definition
|
|
|
|
|
if (is_array($fieldset['content']) && !in_array($col, array_keys($fieldset['content']))) {
|
|
|
|
@ -591,28 +602,50 @@ function rcmail_contact_form($form, $record, $attrib = null)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// only string values are expected here
|
|
|
|
|
if (is_array($record[$col]))
|
|
|
|
|
if (is_array($record[$col])) {
|
|
|
|
|
$record[$col] = join(' ', $record[$col]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$edit_mode) {
|
|
|
|
|
if (!empty($record[$col]))
|
|
|
|
|
$fields .= html::span('namefield ' . $col, rcube::Q($record[$col])) . " ";
|
|
|
|
|
if (!empty($record[$col])) {
|
|
|
|
|
$fields .= html::span('namefield ' . $col, rcube::Q($record[$col])) . ' ';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$colprop = (array)$fieldset['content'][$col] + (array)$coltypes[$col];
|
|
|
|
|
$colprop['id'] = 'ff_'.$col;
|
|
|
|
|
$colprop = (array)$fieldset['content'][$col] + (array)$coltypes[$col];
|
|
|
|
|
$colprop['id'] = 'ff_' . $col;
|
|
|
|
|
$visible = true;
|
|
|
|
|
|
|
|
|
|
if (empty($record[$col]) && !$colprop['visible']) {
|
|
|
|
|
$colprop['style'] = 'display:none';
|
|
|
|
|
$visible = false;
|
|
|
|
|
$colprop['style'] = $use_labels ? null : 'display:none';
|
|
|
|
|
$select_add->add($colprop['label'], $col);
|
|
|
|
|
}
|
|
|
|
|
$fields .= rcube_output::get_edit_field($col, $record[$col], $colprop, $colprop['type']);
|
|
|
|
|
|
|
|
|
|
$input = rcube_output::get_edit_field($col, $record[$col], $colprop, $colprop['type']);
|
|
|
|
|
|
|
|
|
|
if ($use_labels) {
|
|
|
|
|
$_content = html::label($colprop['id'], rcube::Q($colprop['label'])) . html::div(null, $input);
|
|
|
|
|
if (count($colnames) > 1) {
|
|
|
|
|
$fields .= html::div(array('class' => 'row', 'style' => $visible ? null : 'display:none'), $_content);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$fields .= $_content;
|
|
|
|
|
$block_attr['style'] = $visible ? null : 'display:none';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$fields .= $input;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$content .= html::div($blockname, $fields);
|
|
|
|
|
|
|
|
|
|
$content .= html::div($block_attr, $fields);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($edit_mode)
|
|
|
|
|
if ($edit_mode) {
|
|
|
|
|
$content .= html::p('addfield', $select_add->show(null));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$out .= html::tag('fieldset', $attrib, (!empty($fieldset['name']) ? html::tag('legend', null, rcube::Q($fieldset['name'])) : '') . $content) ."\n";
|
|
|
|
|
continue;
|
|
|
|
@ -702,11 +735,11 @@ function rcmail_contact_form($form, $record, $attrib = null)
|
|
|
|
|
|
|
|
|
|
if ($edit_mode) {
|
|
|
|
|
if ($colprop['subtypes'] || $colprop['limit'] != 1) $cp['array'] = true;
|
|
|
|
|
$composite['{'.$childcol.'}'] = rcube_output::get_edit_field($childcol, $childvalue, $cp, $cp['type']) . " ";
|
|
|
|
|
$composite['{'.$childcol.'}'] = rcube_output::get_edit_field($childcol, $childvalue, $cp, $cp['type']) . ' ';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$childval = $cp['render_func'] ? call_user_func($cp['render_func'], $childvalue, $childcol) : rcube::Q($childvalue);
|
|
|
|
|
$composite['{'.$childcol.'}'] = html::span('data ' . $childcol, $childval) . " ";
|
|
|
|
|
$composite['{'.$childcol.'}'] = html::span('data ' . $childcol, $childval) . ' ';
|
|
|
|
|
}
|
|
|
|
|
$j++;
|
|
|
|
|
}
|
|
|
|
@ -714,58 +747,86 @@ function rcmail_contact_form($form, $record, $attrib = null)
|
|
|
|
|
$coltypes[$field] += (array)$colprop;
|
|
|
|
|
$coltypes[$field]['count']++;
|
|
|
|
|
$val = preg_replace('/\{\w+\}/', '', strtr($template, $composite));
|
|
|
|
|
|
|
|
|
|
if ($compact) {
|
|
|
|
|
$val = html::div('content', str_replace('<br/>', '', $val));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ($edit_mode) {
|
|
|
|
|
// call callback to render/format value
|
|
|
|
|
if ($colprop['render_func'])
|
|
|
|
|
if ($colprop['render_func']) {
|
|
|
|
|
$val = call_user_func($colprop['render_func'], $val, $col);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$coltypes[$field] = (array)$colprop + $coltypes[$field];
|
|
|
|
|
|
|
|
|
|
if ($colprop['subtypes'] || $colprop['limit'] != 1)
|
|
|
|
|
if ($colprop['subtypes'] || $colprop['limit'] != 1) {
|
|
|
|
|
$colprop['array'] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// load jquery UI datepicker for date fields
|
|
|
|
|
if ($colprop['type'] == 'date') {
|
|
|
|
|
$colprop['class'] .= ($colprop['class'] ? ' ' : '') . 'datepicker';
|
|
|
|
|
if (!$colprop['render_func'])
|
|
|
|
|
if (!$colprop['render_func']) {
|
|
|
|
|
$val = rcmail_format_date_col($val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$val = rcube_output::get_edit_field($col, $val, $colprop, $colprop['type']);
|
|
|
|
|
$coltypes[$field]['count']++;
|
|
|
|
|
}
|
|
|
|
|
else if ($colprop['render_func'])
|
|
|
|
|
else if ($colprop['render_func']) {
|
|
|
|
|
$val = call_user_func($colprop['render_func'], $val, $col);
|
|
|
|
|
else if (is_array($colprop['options']) && isset($colprop['options'][$val]))
|
|
|
|
|
}
|
|
|
|
|
else if (is_array($colprop['options']) && isset($colprop['options'][$val])) {
|
|
|
|
|
$val = $colprop['options'][$val];
|
|
|
|
|
else
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$val = rcube::Q($val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// use subtype as label
|
|
|
|
|
if ($colprop['subtypes'])
|
|
|
|
|
if ($colprop['subtypes']) {
|
|
|
|
|
$label = rcmail_get_type_label($subtype);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$_del_btn = html::a(array('href' => '#del', 'class' => 'contactfieldbutton deletebutton', 'title' => $RCMAIL->gettext('delete'), 'rel' => $col), $del_button);
|
|
|
|
|
|
|
|
|
|
// add delete button/link
|
|
|
|
|
if ($edit_mode && !($colprop['visible'] && $colprop['limit'] == 1))
|
|
|
|
|
$val .= html::a(array('href' => '#del', 'class' => 'contactfieldbutton deletebutton', 'title' => $RCMAIL->gettext('delete'), 'rel' => $col), $del_button);
|
|
|
|
|
if (!$compact && $edit_mode && !($colprop['visible'] && $colprop['limit'] == 1)) {
|
|
|
|
|
$val .= $_del_btn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// display row with label
|
|
|
|
|
if ($label) {
|
|
|
|
|
if ($RCMAIL->action == 'print') {
|
|
|
|
|
$_label = rcube::Q($colprop['label'] . ($label != $colprop['label'] ? ' (' . $label . ')' : ''));
|
|
|
|
|
if (!$compact) {
|
|
|
|
|
$_label = html::div('contactfieldlabel label', $_label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ($select_subtype) {
|
|
|
|
|
$_label = $select_subtype->show($subtype);
|
|
|
|
|
if (!$compact) {
|
|
|
|
|
$_label = html::div('contactfieldlabel label', $_label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$_label = html::label(array('class' => 'contactfieldlabel label', 'for' => $colprop['id']), rcube::Q($label));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$compact) {
|
|
|
|
|
$val = html::div('contactfieldcontent ' . $colprop['type'], $val);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$_label = $select_subtype ? $select_subtype->show($subtype) : html::label($colprop['id'], rcube::Q($label));
|
|
|
|
|
$val .= $_del_btn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$rows .= html::div('row',
|
|
|
|
|
html::div('contactfieldlabel label', $_label) .
|
|
|
|
|
html::div('contactfieldcontent '.$colprop['type'], $val));
|
|
|
|
|
$rows .= html::div('row', $_label . $val);
|
|
|
|
|
}
|
|
|
|
|
// row without label
|
|
|
|
|
else {
|
|
|
|
|
$rows .= html::div('row', html::div('contactfield', $val));
|
|
|
|
|
$rows .= html::div('row', $compact ? $val : html::div('contactfield', $val));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -787,12 +848,14 @@ function rcmail_contact_form($form, $record, $attrib = null)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$content && (!$edit_mode || !$select_add->_count))
|
|
|
|
|
if (!$content && (!$edit_mode || !$select_add->_count)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// also render add-field selector
|
|
|
|
|
if ($edit_mode)
|
|
|
|
|
if ($edit_mode) {
|
|
|
|
|
$content .= html::p('addfield', $select_add->show(null, array('style' => $select_add->_count ? null : 'display:none')));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$content = html::div(array('id' => 'contactsection' . $section), $content);
|
|
|
|
|
}
|
|
|
|
@ -800,8 +863,10 @@ function rcmail_contact_form($form, $record, $attrib = null)
|
|
|
|
|
$content = $fieldset['content'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($content)
|
|
|
|
|
$out .= html::tag('fieldset', null, html::tag('legend', null, rcube::Q($fieldset['name'])) . $content) ."\n";
|
|
|
|
|
if ($content) {
|
|
|
|
|
$out .= html::tag('fieldset', array('class' => $attrib['fieldset-class']),
|
|
|
|
|
html::tag('legend', null, rcube::Q($fieldset['name'])) . $content) . "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($edit_mode) {
|
|
|
|
|