alecpl
2010-10-28 a79417d4efda43e99fdc9210c8662890676bebd7
- Plugin API: added 'contact_form' hook
- Re-designed contact frame using Tabs


7 files modified
640 ■■■■■ changed files
CHANGELOG 1 ●●●● patch | view | raw | blame | history
program/steps/addressbook/edit.inc 111 ●●●● patch | view | raw | blame | history
program/steps/addressbook/func.inc 327 ●●●●● patch | view | raw | blame | history
program/steps/addressbook/show.inc 150 ●●●●● patch | view | raw | blame | history
skins/default/templates/addcontact.html 15 ●●●● patch | view | raw | blame | history
skins/default/templates/editcontact.html 15 ●●●● patch | view | raw | blame | history
skins/default/templates/showcontact.html 21 ●●●● patch | view | raw | blame | history
CHANGELOG
@@ -52,6 +52,7 @@
- Add support for selection options from LIST-EXTENDED extension (RFC 5258)
- Don't list subscribed but non-existent folders (#1486225)
- Fix handling of URLs with tilde (~) or semicolon (;) character (#1487087, #1487088)
- Plugin API: added 'contact_form' hook
RELEASE 0.4.2
-------------
program/steps/addressbook/edit.inc
@@ -21,93 +21,92 @@
if (($cid = get_input_value('_cid', RCUBE_INPUT_GPC)) && ($record = $CONTACTS->get_record($cid, true)))
  $OUTPUT->set_env('cid', $record['ID']);
    $OUTPUT->set_env('cid', $record['ID']);
// adding not allowed here
if ($CONTACTS->readonly)
{
  $OUTPUT->show_message('sourceisreadonly');
  rcmail_overwrite_action('show');
  return;
if ($CONTACTS->readonly) {
    $OUTPUT->show_message('sourceisreadonly');
    rcmail_overwrite_action('show');
    return;
}
function rcmail_contact_editform($attrib)
{
  global $RCMAIL, $CONTACTS, $OUTPUT;
   global $RCMAIL, $CONTACTS, $OUTPUT;
  // check if we have a valid result
  if ($RCMAIL->action != 'add' && !(($result = $CONTACTS->get_result()) && ($record = $result->first())))
  {
    $OUTPUT->show_message('contactnotfound');
    return false;
  }
    // check if we have a valid result
    if ($RCMAIL->action != 'add'
        && !(($result = $CONTACTS->get_result()) && ($record = $result->first()))
    ) {
        $OUTPUT->show_message('contactnotfound');
        return false;
    }
  // add some labels to client
  $OUTPUT->add_label('noemailwarning', 'nonamewarning');
    // add some labels to client
    $OUTPUT->add_label('noemailwarning', 'nonamewarning');
  list($form_start, $form_end) = get_form_tags($attrib);
  unset($attrib['form']);
    $i_size = !empty($attrib['size']) ? $attrib['size'] : 40;
    $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 6;
    $t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40;
  // a specific part is requested
  if ($attrib['part'])
  {
    $out = $form_start;
    $out .= rcmail_get_edit_field($attrib['part'], $record[$attrib['part']], $attrib);
    return $out;
  }
    $form = array(
        'info' => array(
            'name'    => rcube_label('contactproperties'),
            'content' => array(
                'name' => array('type' => 'text', 'size' => $i_size),
                'firstname' => array('type' => 'text', 'size' => $i_size),
                'surname' => array('type' => 'text', 'size' => $i_size),
                'email' => array('type' => 'text', 'size' => $i_size),
            ),
        ),
    );
  // return the complete address edit form as table
  $out = "$form_start<table>\n\n";
    list($form_start, $form_end) = get_form_tags($attrib);
    unset($attrib['form']);
  $a_show_cols = array('name', 'firstname', 'surname', 'email');
  foreach ($a_show_cols as $col)
  {
    $attrib['id'] = 'rcmfd_'.$col;
    $value = rcmail_get_edit_field($col, $record[$col], $attrib);
    $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
                    $attrib['id'],
                    Q(rcube_label($col)),
                    $value);
  }
    // return the complete address edit form as table
    $out = rcmail_contact_form($form, $record);
  $out .= "\n</table>$form_end";
  return $out;
    return $form_start . $out . $form_end;
}
$OUTPUT->add_handler('contacteditform', 'rcmail_contact_editform');
// similar function as in /steps/settings/edit_identity.inc
function get_form_tags($attrib)
{
  global $CONTACTS, $EDIT_FORM, $RCMAIL;
    global $CONTACTS, $EDIT_FORM, $RCMAIL;
  $form_start = $form_end = '';
    $form_start = $form_end = '';
  
  if (empty($EDIT_FORM)) {
    $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
    $hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id));
    if (empty($EDIT_FORM)) {
        $hiddenfields = new html_hiddenfield(array(
            'name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
        $hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id));
    
    if (($result = $CONTACTS->get_result()) && ($record = $result->first()))
      $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
        if (($result = $CONTACTS->get_result()) && ($record = $result->first()))
            $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
    
    $form_start = $RCMAIL->output->request_form(array('name' => "form", 'method' => "post", 'task' => $RCMAIL->task, 'action' => 'save', 'request' => 'save.'.intval($record['ID']), 'noclose' => true) + $attrib, $hiddenfields->show());
    $form_end = !strlen($attrib['form']) ? '</form>' : '';
        $form_start = $RCMAIL->output->request_form(array(
            'name' => "form", 'method' => "post",
            'task' => $RCMAIL->task, 'action' => 'save',
            'request' => 'save.'.intval($record['ID']),
            'noclose' => true) + $attrib, $hiddenfields->show());
        $form_end = !strlen($attrib['form']) ? '</form>' : '';
    $EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form';
    $RCMAIL->output->add_gui_object('editform', $EDIT_FORM);
  }
        $EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form';
        $RCMAIL->output->add_gui_object('editform', $EDIT_FORM);
    }
  return array($form_start, $form_end);
    return array($form_start, $form_end);
}
$OUTPUT->add_handler('contacteditform', 'rcmail_contact_editform');
if (!$CONTACTS->get_result() && $OUTPUT->template_exists('addcontact'))
  $OUTPUT->send('addcontact');
    $OUTPUT->send('addcontact');
// this will be executed if no template for addcontact exists
$OUTPUT->send('editcontact');
program/steps/addressbook/func.inc
@@ -27,7 +27,7 @@
// if source is not set use first directory
if (empty($source))
  $source = $js_list[key($js_list)]['id'];
    $source = $js_list[key($js_list)]['id'];
// instantiate a contacts object according to the given source
$CONTACTS = $RCMAIL->get_address_book($source);
@@ -36,203 +36,260 @@
// set list properties and session vars
if (!empty($_GET['_page']))
  $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page'])));
    $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page'])));
else
  $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1);
    $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1);
  
if (!empty($_REQUEST['_gid']))
  $CONTACTS->set_group(get_input_value('_gid', RCUBE_INPUT_GPC));
    $CONTACTS->set_group(get_input_value('_gid', RCUBE_INPUT_GPC));
// set message set for search result
if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
  $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]);
    $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]);
// set data source env
$OUTPUT->set_env('source', $source ? $source : '0');
$OUTPUT->set_env('readonly', $CONTACTS->readonly, false);
if(! $OUTPUT->ajax_call) {
  $OUTPUT->set_env('address_sources', $js_list);
  $OUTPUT->set_pagetitle(rcube_label('addressbook'));
if (!$OUTPUT->ajax_call) {
    $OUTPUT->set_env('address_sources', $js_list);
    $OUTPUT->set_pagetitle(rcube_label('addressbook'));
}
function rcmail_directory_list($attrib)
{
  global $RCMAIL, $OUTPUT;
  if (!$attrib['id'])
    $attrib['id'] = 'rcmdirectorylist';
    global $RCMAIL, $OUTPUT;
  $out = '';
  $local_id = '0';
  $jsdata = array();
  $current = get_input_value('_source', RCUBE_INPUT_GPC);
  $line_templ = html::tag('li', array('id' => 'rcmli%s', 'class' => 'addressbook %s'),
    html::a(array('href' => '%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s'));
    if (!$attrib['id'])
        $attrib['id'] = 'rcmdirectorylist';
  if (!$current && strtolower($RCMAIL->config->get('address_book_type', 'sql')) != 'ldap') {
    $current = '0';
  }
  else if (!$current) {
    // DB address book not used, see if a source is set, if not use the
    // first LDAP directory.
    $current = key((array)$RCMAIL->config->get('ldap_public', array()));
  }
    $out = '';
    $local_id = '0';
    $jsdata = array();
    $current = get_input_value('_source', RCUBE_INPUT_GPC);
    $line_templ = html::tag('li', array(
        'id' => 'rcmli%s', 'class' => 'addressbook %s'),
        html::a(array('href' => '%s',
            'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s'));
  foreach ((array)$OUTPUT->env['address_sources'] as $j => $source) {
    $id = $source['id'] ? $source['id'] : $j;
    $js_id = JQ($id);
    $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id);
    $out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''),
      Q(rcmail_url(null, array('_source' => $id))), $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id)));
    $groupdata = rcmail_contact_groups(array('out' => $out, 'jsdata' => $jsdata, 'source' => $id));
    $jsdata = $groupdata['jsdata'];
    $out = $groupdata['out'];
  }
    if (!$current && strtolower($RCMAIL->config->get('address_book_type', 'sql')) != 'ldap') {
        $current = '0';
    }
    else if (!$current) {
        // DB address book not used, see if a source is set, if not use the
        // first LDAP directory.
        $current = key((array)$RCMAIL->config->get('ldap_public', array()));
    }
  $OUTPUT->set_env('contactgroups', $jsdata);
  $OUTPUT->add_gui_object('folderlist', $attrib['id']);
  return html::tag('ul', $attrib, $out, html::$common_attrib);
    foreach ((array)$OUTPUT->env['address_sources'] as $j => $source) {
        $id = $source['id'] ? $source['id'] : $j;
        $js_id = JQ($id);
        $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id);
        $out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''),
            Q(rcmail_url(null, array('_source' => $id))),
            $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id)));
        $groupdata = rcmail_contact_groups(array('out' => $out, 'jsdata' => $jsdata, 'source' => $id));
        $jsdata = $groupdata['jsdata'];
        $out = $groupdata['out'];
    }
    $OUTPUT->set_env('contactgroups', $jsdata);
    $OUTPUT->add_gui_object('folderlist', $attrib['id']);
    return html::tag('ul', $attrib, $out, html::$common_attrib);
}
function rcmail_contact_groups($args)
{
  global $RCMAIL;
    global $RCMAIL;
  $groups = $RCMAIL->get_address_book($args['source'])->list_groups();
    $groups = $RCMAIL->get_address_book($args['source'])->list_groups();
  if (!empty($groups)) {
    $line_templ = html::tag('li', array('id' => 'rcmliG%s%s', 'class' => 'contactgroup'),
      html::a(array('href' => '#', 'onclick' => "return ".JS_OBJECT_NAME.".command('listgroup',{'source':'%s','id':'%s'},this)"), '%s'));
    if (!empty($groups)) {
        $line_templ = html::tag('li', array(
            'id' => 'rcmliG%s%s', 'class' => 'contactgroup'),
            html::a(array('href' => '#',
                'onclick' => "return ".JS_OBJECT_NAME.".command('listgroup',{'source':'%s','id':'%s'},this)"), '%s'));
    $jsdata = array();
    foreach ($groups as $group) {
      $args['out'] .= sprintf($line_templ, $args['source'], $group['ID'], $args['source'], $group['ID'], Q($group['name']));
      $args['jsdata']['G'.$args['source'].$group['ID']] = array(
        'source' => $args['source'], 'id' => $group['ID'], 'name' => $group['name'], 'type' => 'group');
        $jsdata = array();
        foreach ($groups as $group) {
            $args['out'] .= sprintf($line_templ, $args['source'], $group['ID'], $args['source'], $group['ID'], Q($group['name']));
            $args['jsdata']['G'.$args['source'].$group['ID']] = array(
                'source' => $args['source'], 'id' => $group['ID'],
                'name' => $group['name'], 'type' => 'group');
        }
    }
  }
  return $args;
    return $args;
}
// return the message list as HTML table
function rcmail_contacts_list($attrib)
  {
  global $CONTACTS, $OUTPUT;
  // count contacts for this user
  $result = $CONTACTS->list_records();
  // add id to message list table if not specified
  if (!strlen($attrib['id']))
    $attrib['id'] = 'rcmAddressList';
  // define list of cols to be displayed
  $a_show_cols = array('name');
{
    global $CONTACTS, $OUTPUT;
  // create XHTML table
  $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key);
  // set client env
  $OUTPUT->add_gui_object('contactslist', $attrib['id']);
  $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page);
  $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size));
  $OUTPUT->include_script('list.js');
  // add some labels to client
  $OUTPUT->add_label('deletecontactconfirm');
  return $out;
  }
    // count contacts for this user
    $result = $CONTACTS->list_records();
    // add id to message list table if not specified
    if (!strlen($attrib['id']))
        $attrib['id'] = 'rcmAddressList';
    // define list of cols to be displayed
    $a_show_cols = array('name');
    // create XHTML table
    $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key);
    // set client env
    $OUTPUT->add_gui_object('contactslist', $attrib['id']);
    $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page);
    $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size));
    $OUTPUT->include_script('list.js');
    // add some labels to client
    $OUTPUT->add_label('deletecontactconfirm');
    return $out;
}
function rcmail_js_contacts_list($result, $prefix='')
  {
  global $OUTPUT;
{
    global $OUTPUT;
  if (empty($result) || $result->count == 0)
    return;
    if (empty($result) || $result->count == 0)
        return;
  // define list of cols to be displayed
  $a_show_cols = array('name');
    // define list of cols to be displayed
    $a_show_cols = array('name');
  
  while ($row = $result->next())
    {
    $a_row_cols = array();
    while ($row = $result->next()) {
        $a_row_cols = array();
    
    // format each col
    foreach ($a_show_cols as $col)
      $a_row_cols[$col] = Q($row[$col]);
    $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
        // format each col
        foreach ($a_show_cols as $col)
            $a_row_cols[$col] = Q($row[$col]);
        $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
    }
  }
}
// similar function as /steps/settings/identities.inc::rcmail_identity_frame()
function rcmail_contact_frame($attrib)
  {
  global $OUTPUT;
{
    global $OUTPUT;
  if (!$attrib['id'])
    $attrib['id'] = 'rcmcontactframe';
    if (!$attrib['id'])
        $attrib['id'] = 'rcmcontactframe';
    
  $attrib['name'] = $attrib['id'];
    $attrib['name'] = $attrib['id'];
  $OUTPUT->set_env('contentframe', $attrib['name']);
  $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
    $OUTPUT->set_env('contentframe', $attrib['name']);
    $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
  return html::iframe($attrib);
  }
    return html::iframe($attrib);
}
function rcmail_rowcount_display($attrib)
  {
  global $OUTPUT;
  if (!$attrib['id'])
    $attrib['id'] = 'rcmcountdisplay';
{
    global $OUTPUT;
  $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
    if (!$attrib['id'])
        $attrib['id'] = 'rcmcountdisplay';
  return html::span($attrib, rcmail_get_rowcount_text());
  }
    $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
    return html::span($attrib, rcmail_get_rowcount_text());
}
function rcmail_get_rowcount_text()
  {
  global $CONTACTS;
{
    global $CONTACTS;
  
  // read nr of contacts
  $result = $CONTACTS->get_result();
  if (!$result)
    $result = $CONTACTS->count();
  if ($result->count == 0)
    $out = rcube_label('nocontactsfound');
  else
    $out = rcube_label(array(
      'name' => 'contactsfromto',
      'vars' => array(
        'from'  => $result->first + 1,
        'to'    => min($result->count, $result->first + $CONTACTS->page_size),
        'count' => $result->count)
      ));
    // read nr of contacts
    $result = $CONTACTS->get_result();
    if (!$result) {
        $result = $CONTACTS->count();
    }
  return $out;
  }
    if ($result->count == 0)
        $out = rcube_label('nocontactsfound');
    else
        $out = rcube_label(array(
            'name'  => 'contactsfromto',
            'vars'  => array(
            'from'  => $result->first + 1,
            'to'    => min($result->count, $result->first + $CONTACTS->page_size),
            'count' => $result->count)
        ));
    return $out;
}
function rcmail_contact_form($form, $record)
{
    global $RCMAIL;
    // Allow plugins to modify contact form content
    $plugin = $RCMAIL->plugins->exec_hook('contact_form', array(
        'form' => $form, 'record' => $record));
    $form = $plugin['form'];
    $record = $plugin['record'];
    $out = '';
    foreach ($form as $fieldset) {
        if (empty($fieldset['content']))
            continue;
        $content = '';
        if (is_array($fieldset['content'])) {
            $table = new html_table(array('cols' => 2));
            foreach ($fieldset['content'] as $col => $colprop) {
                $colprop['id'] = 'rcmfd_'.$col;
                $label = !empty($colprop['label']) ? $colprop['label'] : rcube_label($col);
                if (!empty($colprop['value'])) {
                    $value = $colprop['value'];
                }
                else if ($RCMAIL->action == 'show') {
                    $value = $record[$col];
                }
                else {
                    $value = rcmail_get_edit_field($col, $record[$col], $colprop, $colprop['type']);
                }
                $table->add('title', sprintf('<label for="%s">%s</label>', $colprop['id'], Q($label)));
                $table->add(null, $value);
            }
            $content = $table->show();
        }
        else {
            $content = $fieldset['content'];
        }
        $out .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $content) ."\n";
    }
  
    return $out;
}
// register UI objects
$OUTPUT->add_handlers(array(
  'directorylist' => 'rcmail_directory_list',
    'directorylist' => 'rcmail_directory_list',
//  'groupslist' => 'rcmail_contact_groups',
  'addresslist' => 'rcmail_contacts_list',
  'addressframe' => 'rcmail_contact_frame',
  'recordscountdisplay' => 'rcmail_rowcount_display',
  'searchform' => array($OUTPUT, 'search_form')
    'addresslist' => 'rcmail_contacts_list',
    'addressframe' => 'rcmail_contact_frame',
    'recordscountdisplay' => 'rcmail_rowcount_display',
    'searchform' => array($OUTPUT, 'search_form')
));
program/steps/addressbook/show.inc
@@ -22,88 +22,108 @@
// read contact record
if (($cid = get_input_value('_cid', RCUBE_INPUT_GPC)) && ($record = $CONTACTS->get_record($cid, true))) {
  $OUTPUT->set_env('cid', $record['ID']);
    $OUTPUT->set_env('cid', $record['ID']);
}
$GROUPS = $CONTACTS->list_groups();
$OUTPUT->set_env('groups', !empty($GROUPS));
function rcmail_contact_details($attrib)
{
  global $CONTACTS, $OUTPUT;
    global $CONTACTS, $RCMAIL;
  // check if we have a valid result
  if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
    $OUTPUT->show_message('contactnotfound');
    return false;
  }
  // a specific part is requested
  if ($attrib['part']) {
    return Q($record[$attrib['part']]);
  }
  // return the complete address record as table
  $table = new html_table(array('cols' => 2));
  $a_show_cols = array('name', 'firstname', 'surname', 'email');
  $microformats = array('name' => 'fn', 'email' => 'email');
  foreach ($a_show_cols as $col) {
    if ($col == 'email' && !empty($record[$col])) {
      $value = html::a(array(
        'href' => 'mailto:' . $record[$col],
        'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($record[$col])),
        'title' => rcube_label('composeto'),
        'class' => $microformats[$col],
      ), Q($record[$col]));
    // check if we have a valid result
    if (!(($result = $CONTACTS->get_result()) && ($record = $result->first()))) {
        $RCMAIL->output->show_message('contactnotfound');
        return false;
    }
    else if (!empty($record[$col])) {
      $value = html::span($microformats[$col], Q($record[$col]));
    $i_size = !empty($attrib['size']) ? $attrib['size'] : 40;
    $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 6;
    $t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40;
    $microformats = array('name' => 'fn', 'email' => 'email');
    $form = array(
        'info' => array(
            'name'    => rcube_label('contactproperties'),
            'content' => array(
                'name' => array('type' => 'text', 'size' => $i_size),
                'firstname' => array('type' => 'text', 'size' => $i_size),
                'surname' => array('type' => 'text', 'size' => $i_size),
                'email' => array('type' => 'text', 'size' => $i_size),
            ),
        ),
        'groups' => array(
            'name'    => rcube_label('groups'),
            'content' => '',
        ),
    );
    // Get content of groups fieldset
    if ($groups = rcmail_contact_record_groups($record['ID'])) {
        $form['groups']['content'] = $groups;
    }
    else
      $value = '';
    $table->add('title', Q(rcube_label($col)));
    $table->add(null, $value);
  }
  return $table->show($attrib + array('class' => 'vcard'));
    else {
        unset($form['groups']);
    }
    if (!empty($record['email'])) {
        $form['info']['content']['email']['value'] = html::a(array(
            'href' => 'mailto:' . $record['email'],
            'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($record['email'])),
            'title' => rcube_label('composeto'),
            'class' => $microformats['email'],
        ), Q($record['email']));
    }
    foreach (array('name', 'firstname', 'surname') as $col) {
        if ($record[$col]) {
            $form['info']['content'][$col]['value'] = html::span($microformats[$col], Q($record[$col]));
        }
    }
    return rcmail_contact_form($form, $record);
}
function rcmail_contact_record_groups($attrib)
function rcmail_contact_record_groups($contact_id)
{
  global $RCMAIL, $CONTACTS, $GROUPS;
  // check if we have a valid result
  if (!(($result = $CONTACTS->get_result()) && ($record = $result->first())))
    return false;
  $table = new html_table(array('cols' => 2, 'cellspacing' => 0, 'border' => 0));
  $members = $CONTACTS->get_record_groups($record['ID']);
  $checkbox = new html_checkbox(array('name' => '_gid[]', 'class' => 'groupmember', 'disabled' => $CONTACTS->readonly));
  foreach ($GROUPS as $group) {
    $gid = $group['ID'];
    $table->add(null, $checkbox->show($members[$gid] ? $gid : null, array('value' => $gid, 'id' => 'ff_gid' . $gid)));
    $table->add(null, html::label('ff_gid' . $gid, Q($group['name'])));
  }
  $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
  $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
  $form_start = $RCMAIL->output->request_form(array('name' => "form", 'method' => "post", 'task' => $RCMAIL->task, 'action' => 'save', 'request' => 'save.'.intval($record['ID']), 'noclose' => true) + $attrib, $hiddenfields->show());
  $form_end = !strlen($attrib['form']) ? '</form>' : '';
    global $RCMAIL, $CONTACTS, $GROUPS;
  $RCMAIL->output->add_gui_object('editform', !empty($attrib['form']) ? $attrib['form'] : 'form');
    $GROUPS = $CONTACTS->list_groups();
    if (empty($GROUPS)) {
        return '';
    }
    $table = new html_table(array('cols' => 2, 'cellspacing' => 0, 'border' => 0));
    $members = $CONTACTS->get_record_groups($contact_id);
    $checkbox = new html_checkbox(array('name' => '_gid[]',
        'class' => 'groupmember', 'disabled' => $CONTACTS->readonly));
    foreach ($GROUPS as $group) {
        $gid = $group['ID'];
        $table->add(null, $checkbox->show($members[$gid] ? $gid : null,
            array('value' => $gid, 'id' => 'ff_gid' . $gid)));
        $table->add(null, html::label('ff_gid' . $gid, Q($group['name'])));
    }
    $hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
    $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
    $form_start = $RCMAIL->output->request_form(array(
        'name' => "form", 'method' => "post",
        'task' => $RCMAIL->task, 'action' => 'save',
        'request' => 'save.'.intval($contact_id),
        'noclose' => true), $hiddenfields->show());
    $form_end = '</form>';
    $RCMAIL->output->add_gui_object('editform', 'form');
  
  return $form_start . $table->show($attrib) . $form_end;
    return $form_start . $table->show() . $form_end;
}
//$OUTPUT->framed = $_framed;
$OUTPUT->add_handler('contactdetails', 'rcmail_contact_details');
$OUTPUT->add_handler('contactgroups', 'rcmail_contact_record_groups');
$OUTPUT->send('showcontact');
skins/default/templates/addcontact.html
@@ -3,21 +3,20 @@
<head>
<title><roundcube:object name="pagetitle" /></title>
<roundcube:include file="/includes/links.html" />
<script type="text/javascript" src="/functions.js"></script>
</head>
<body class="iframe">
<div id="contact-title" class="boxtitle"><roundcube:label name="addcontact" /></div>
<div id="contact-details" class="boxcontent">
<roundcube:object name="contacteditform" size="40" />
<p><br />
<input type="button" value="<roundcube:label name="cancel" />" class="button" onclick="history.back()" />&nbsp;
<roundcube:button command="save" type="input" class="button mainaction" label="save" />
</p>
  <roundcube:object name="contacteditform" size="40" />
  <p>
    <input type="button" value="<roundcube:label name="cancel" />" class="button" onclick="history.back()" />&nbsp;
    <roundcube:button command="save" type="input" class="button mainaction" label="save" />
  </p>
</form>
</div>
<script type="text/javascript">rcube_init_tabs('contact-details')</script>
</body>
</html>
skins/default/templates/editcontact.html
@@ -3,21 +3,20 @@
<head>
<title><roundcube:object name="pagetitle" /></title>
<roundcube:include file="/includes/links.html" />
<script type="text/javascript" src="/functions.js"></script>
</head>
<body class="iframe">
<div id="contact-title" class="boxtitle"><roundcube:label name="editcontact" /></div>
<div id="contact-details" class="boxcontent">
<roundcube:object name="contacteditform" size="40" />
<p><br />
<roundcube:button command="show" type="input" class="button" label="cancel" />&nbsp;
<roundcube:button command="save" type="input" class="button mainaction" label="save" />
</p>
  <roundcube:object name="contacteditform" size="40" />
  <p>
    <roundcube:button command="show" type="input" class="button" label="cancel" />&nbsp;
    <roundcube:button command="save" type="input" class="button mainaction" label="save" />
  </p>
</form>
</div>
<script type="text/javascript">rcube_init_tabs('contact-details')</script>
</body>
</html>
skins/default/templates/showcontact.html
@@ -3,27 +3,18 @@
<head>
<title><roundcube:object name="pagetitle" /></title>
<roundcube:include file="/includes/links.html" />
<script type="text/javascript" src="/functions.js"></script>
</head>
<body class="iframe">
<div id="contact-title" class="boxtitle"><roundcube:object name="contactdetails" part="name" /></div>
<div id="contact-title" class="boxtitle"><roundcube:label name="contactproperties" /></div>
<div id="contact-details" class="boxcontent">
<fieldset>
  <legend><roundcube:label name="contactproperties" /></legend>
  <roundcube:object name="contactdetails" />
  <p><br /><roundcube:button command="edit" type="input" class="button" label="editcontact" condition="!ENV:readonly" /></p>
</fieldset>
<roundcube:if condition="ENV:groups" />
<fieldset>
  <legend><roundcube:label name="groups" /></legend>
  <roundcube:object name="contactgroups" />
</fieldset>
<roundcube:endif />
  <p>
    <roundcube:button command="edit" type="input" class="button" label="editcontact" condition="!ENV:readonly" />
  </p>
</div>
<script type="text/javascript">rcube_init_tabs('contact-details')</script>
</body>
</html>