diff options
author | alecpl <alec@alec.pl> | 2010-10-28 07:10:11 +0000 |
---|---|---|
committer | alecpl <alec@alec.pl> | 2010-10-28 07:10:11 +0000 |
commit | a79417d4efda43e99fdc9210c8662890676bebd7 (patch) | |
tree | 00ae35c8d55ab44311859c41eac5751052912053 | |
parent | 022bcd11320398b6652eacc5c264a87adc16af84 (diff) |
- Plugin API: added 'contact_form' hook
- Re-designed contact frame using Tabs
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | program/steps/addressbook/edit.inc | 131 | ||||
-rw-r--r-- | program/steps/addressbook/func.inc | 343 | ||||
-rw-r--r-- | program/steps/addressbook/show.inc | 150 | ||||
-rw-r--r-- | skins/default/templates/addcontact.html | 15 | ||||
-rw-r--r-- | skins/default/templates/editcontact.html | 15 | ||||
-rw-r--r-- | skins/default/templates/showcontact.html | 21 |
7 files changed, 371 insertions, 305 deletions
@@ -52,6 +52,7 @@ CHANGELOG Roundcube Webmail - 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 ------------- diff --git a/program/steps/addressbook/edit.inc b/program/steps/addressbook/edit.inc index 71c706fc4..d975c76f1 100644 --- a/program/steps/addressbook/edit.inc +++ b/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; - - // 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'); - - list($form_start, $form_end) = get_form_tags($attrib); - unset($attrib['form']); - - // a specific part is requested - if ($attrib['part']) - { - $out = $form_start; - $out .= rcmail_get_edit_field($attrib['part'], $record[$attrib['part']], $attrib); - return $out; - } - - - // return the complete address edit form as table - $out = "$form_start<table>\n\n"; - - $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); - } - - $out .= "\n</table>$form_end"; - - return $out; + 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; + } + + // add some labels to client + $OUTPUT->add_label('noemailwarning', 'nonamewarning'); + + $i_size = !empty($attrib['size']) ? $attrib['size'] : 40; + $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 6; + $t_cols = !empty($attrib['textareacols']) ? $attrib['textareacols'] : 40; + + $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), + ), + ), + ); + + + list($form_start, $form_end) = get_form_tags($attrib); + unset($attrib['form']); + + // return the complete address edit form as table + $out = rcmail_contact_form($form, $record); + + 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>' : ''; - - $EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form'; - $RCMAIL->output->add_gui_object('editform', $EDIT_FORM); - } - - return array($form_start, $form_end); + $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); + } + + 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'); - diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc index 561b4fe3d..f875ea68a 100644 --- a/program/steps/addressbook/func.inc +++ b/program/steps/addressbook/func.inc @@ -27,7 +27,7 @@ $source = get_input_value('_source', RCUBE_INPUT_GPC); // 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 @@ $CONTACTS->set_pagesize($CONFIG['pagesize']); // 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'; - - $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 (!$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())); - } - - 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); -} + global $RCMAIL, $OUTPUT; + if (!$attrib['id']) + $attrib['id'] = 'rcmdirectorylist'; -function rcmail_contact_groups($args) -{ - global $RCMAIL; + $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 (!$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())); + } + + 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']; + } - $groups = $RCMAIL->get_address_book($args['source'])->list_groups(); + $OUTPUT->set_env('contactgroups', $jsdata); + $OUTPUT->add_gui_object('folderlist', $attrib['id']); - 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')); + return html::tag('ul', $attrib, $out, html::$common_attrib); +} - $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'); + +function rcmail_contact_groups($args) +{ + global $RCMAIL; + + $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')); + + $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(); - - // format each col - foreach ($a_show_cols as $col) - $a_row_cols[$col] = Q($row[$col]); + while ($row = $result->next()) { + $a_row_cols = array(); - $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; - - // read nr of contacts - $result = $CONTACTS->get_result(); - if (!$result) - $result = $CONTACTS->count(); +{ + global $CONTACTS; - 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; - } + // 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) + )); + + 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') )); - diff --git a/program/steps/addressbook/show.inc b/program/steps/addressbook/show.inc index c5784d61d..67eaa53ef 100644 --- a/program/steps/addressbook/show.inc +++ b/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; + } + + $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 if (!empty($record[$col])) { - $value = html::span($microformats[$col], Q($record[$col])); + else { + unset($form['groups']); } - else - $value = ''; - - $table->add('title', Q(rcube_label($col))); - $table->add(null, $value); - } - - return $table->show($attrib + array('class' => 'vcard')); + + 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; + + $GROUPS = $CONTACTS->list_groups(); + + if (empty($GROUPS)) { + return ''; + } + + $table = new html_table(array('cols' => 2, 'cellspacing' => 0, 'border' => 0)); - $RCMAIL->output->add_gui_object('editform', !empty($attrib['form']) ? $attrib['form'] : 'form'); + $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'); diff --git a/skins/default/templates/addcontact.html b/skins/default/templates/addcontact.html index 08f5ca2b1..1a10f10ac 100644 --- a/skins/default/templates/addcontact.html +++ b/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()" /> -<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()" /> + <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> diff --git a/skins/default/templates/editcontact.html b/skins/default/templates/editcontact.html index 44111959e..a15aaf22a 100644 --- a/skins/default/templates/editcontact.html +++ b/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" /> -<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" /> + <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> diff --git a/skins/default/templates/showcontact.html b/skins/default/templates/showcontact.html index a6819f376..06d0fbee5 100644 --- a/skins/default/templates/showcontact.html +++ b/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> |