summaryrefslogtreecommitdiff
path: root/program/steps/addressbook
diff options
context:
space:
mode:
Diffstat (limited to 'program/steps/addressbook')
-rw-r--r--program/steps/addressbook/export.inc4
-rw-r--r--program/steps/addressbook/func.inc55
-rw-r--r--program/steps/addressbook/import.inc15
-rw-r--r--program/steps/addressbook/save.inc4
-rw-r--r--program/steps/addressbook/show.inc8
5 files changed, 45 insertions, 41 deletions
diff --git a/program/steps/addressbook/export.inc b/program/steps/addressbook/export.inc
index 15bf8b0d4..761f26b75 100644
--- a/program/steps/addressbook/export.inc
+++ b/program/steps/addressbook/export.inc
@@ -138,7 +138,9 @@ header('Content-Disposition: attachment; filename="contacts.vcf"');
while ($result && ($row = $result->next())) {
// we already have a vcard record
if ($row['vcard'] && $row['name']) {
- $row['vcard'] = preg_replace('/\r?\n/', rcube_vcard::$eol, $row['vcard']);
+ // fix folding and end-of-line chars
+ $row['vcard'] = preg_replace('/\r|\n\s+/', '', $row['vcard']);
+ $row['vcard'] = preg_replace('/\n/', rcube_vcard::$eol, $row['vcard']);
echo rcube_vcard::rfc2425_fold($row['vcard']) . rcube_vcard::$eol;
}
// copy values into vcard object
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index 60a19845e..c7f7fb479 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -26,7 +26,7 @@ $CONTACT_COLTYPES = array(
'name' => array('type' => 'text', 'size' => 40, 'maxlength' => 50, 'limit' => 1, 'label' => rcube_label('name'), 'category' => 'main'),
'firstname' => array('type' => 'text', 'size' => 19, 'maxlength' => 50, 'limit' => 1, 'label' => rcube_label('firstname'), 'category' => 'main'),
'surname' => array('type' => 'text', 'size' => 19, 'maxlength' => 50, 'limit' => 1, 'label' => rcube_label('surname'), 'category' => 'main'),
- 'email' => array('type' => 'text', 'size' => 40, 'maxlength' => 50, 'label' => rcube_label('email'), 'subtypes' => array('home','work','other'), 'category' => 'main'),
+ 'email' => array('type' => 'text', 'size' => 40, 'maxlength' => 254, 'label' => rcube_label('email'), 'subtypes' => array('home','work','other'), 'category' => 'main'),
'middlename' => array('type' => 'text', 'size' => 19, 'maxlength' => 50, 'limit' => 1, 'label' => rcube_label('middlename'), 'category' => 'main'),
'prefix' => array('type' => 'text', 'size' => 8, 'maxlength' => 20, 'limit' => 1, 'label' => rcube_label('nameprefix'), 'category' => 'main'),
'suffix' => array('type' => 'text', 'size' => 8, 'maxlength' => 20, 'limit' => 1, 'label' => rcube_label('namesuffix'), 'category' => 'main'),
@@ -167,7 +167,7 @@ function rcmail_set_sourcename($abook)
// get address book name (for display)
if ($abook && $_SESSION['addressbooks_count'] > 1) {
$name = $abook->get_name();
- if (!$name && $source == 0) {
+ if (!$name) {
$name = rcube_label('personaladrbook');
}
$OUTPUT->set_env('sourcename', html_entity_decode($name, ENT_COMPAT, 'UTF-8'));
@@ -183,7 +183,6 @@ function rcmail_directory_list($attrib)
$attrib['id'] = 'rcmdirectorylist';
$out = '';
- $local_id = '0';
$jsdata = array();
$line_templ = html::tag('li', array(
@@ -268,8 +267,8 @@ function rcmail_contact_groups($args)
{
global $RCMAIL;
+ $groups_html = '';
$groups = $RCMAIL->get_address_book($args['source'])->list_groups();
- $js_id = $RCMAIL->JQ($args['source']);
if (!empty($groups)) {
$line_templ = html::tag('li', array(
@@ -282,8 +281,6 @@ function rcmail_contact_groups($args)
$is_collapsed = strpos($RCMAIL->config->get('collapsed_abooks',''), '&'.rawurlencode($args['source']).'&') !== false;
$args['out'] .= html::div('treetoggle ' . ($is_collapsed ? 'collapsed' : 'expanded'), ' ');
- $jsdata = array();
- $groups_html = '';
foreach ($groups as $group) {
$groups_html .= sprintf($line_templ,
rcube_utils::html_identifier('G' . $args['source'] . $group['ID'], true),
@@ -297,7 +294,7 @@ function rcmail_contact_groups($args)
}
$args['out'] .= html::tag('ul',
- array('class' => 'groups', 'style' => ($is_collapsed ? "display:none;" : null)),
+ array('class' => 'groups', 'style' => ($is_collapsed || empty($groups) ? "display:none;" : null)),
$groups_html);
return $args;
@@ -596,22 +593,13 @@ function rcmail_contact_form($form, $record, $attrib = null)
// iterate over possible subtypes and collect values with their subtype
if (is_array($colprop['subtypes'])) {
$values = $subtypes = array();
- foreach ($colprop['subtypes'] as $i => $st) {
- $newval = false;
- if ($record[$field.':'.$st]) {
- $subtypes[count($values)] = $st;
- $newval = $record[$field.':'.$st];
- }
- else if ($i == 0 && $record[$field]) {
- $subtypes[count($values)] = $st;
- $newval = $record[$field];
- }
- if ($newval !== false) {
- if (is_array($newval) && isset($newval[0]))
- $values = array_merge($values, $newval);
- else
- $values[] = $newval;
+ foreach (rcube_addressbook::get_col_values($field, $record) as $st => $vals) {
+ foreach((array)$vals as $value) {
+ $i = count($values);
+ $subtypes[$i] = $st;
+ $values[$i] = $value;
}
+ // TODO: add $st to $select_subtype if missing ?
}
}
else {
@@ -814,20 +802,27 @@ function rcmail_get_cids($filter = null)
return array();
}
- $cid = explode(',', $cid);
- $result = array();
+ $cid = explode(',', $cid);
+ $got_source = strlen($source);
+ $result = array();
// create per-source contact IDs array
foreach ($cid as $id) {
- // get source from decoded ID
- if ($sep = strrpos($id, '-')) {
- $contact_id = substr($id, 0, $sep);
- $source_id = substr($id, $sep+1);
- if (strlen($source_id)) {
- $result[(string)$source_id][] = $contact_id;
+ // extract source ID from contact ID (it's there in search mode)
+ // see #1488959 and #1488862 for reference
+ if (!$got_source) {
+ if ($sep = strrpos($id, '-')) {
+ $contact_id = substr($id, 0, $sep);
+ $source_id = (string) substr($id, $sep+1);
+ if (strlen($source_id)) {
+ $result[$source_id][] = $contact_id;
+ }
}
}
else {
+ if (substr($id, -($got_source+1)) === "-$source") {
+ $id = substr($id, 0, -($got_source+1));
+ }
$result[$source][] = $id;
}
}
diff --git a/program/steps/addressbook/import.inc b/program/steps/addressbook/import.inc
index df07d64bc..915aac884 100644
--- a/program/steps/addressbook/import.inc
+++ b/program/steps/addressbook/import.inc
@@ -88,7 +88,7 @@ function rcmail_import_confirm($attrib)
$content = html::p(null, rcube_label(array(
'name' => 'importconfirm',
- 'nr' => $IMORT_STATS->inserted,
+ 'nr' => $IMPORT_STATS->inserted,
'vars' => $vars,
)) . ($IMPORT_STATS->names ? ':' : '.'));
@@ -98,7 +98,7 @@ function rcmail_import_confirm($attrib)
if ($IMPORT_STATS->skipped) {
$content .= html::p(null, rcube_label(array(
'name' => 'importconfirmskipped',
- 'nr' => $IMORT_STATS->skipped,
+ 'nr' => $IMPORT_STATS->skipped,
'vars' => $vars,
)) . ':');
$content .= html::p('em', join(', ', array_map('Q', $IMPORT_STATS->skipped_names)));
@@ -209,6 +209,15 @@ if (is_array($_FILES['_file'])) {
foreach ($vcards as $vcard) {
$a_record = $vcard->get_assoc();
+ // Generate contact's display name (must be before validation), the same we do in save.inc
+ if (empty($a_record['name'])) {
+ $a_record['name'] = rcube_addressbook::compose_display_name($a_record, true);
+ // Reset it if equals to email address (from compose_display_name())
+ if ($a_record['name'] == $a_record['email'][0]) {
+ $a_record['name'] = '';
+ }
+ }
+
// skip invalid (incomplete) entries
if (!$CONTACTS->validate($a_record, true)) {
$IMPORT_STATS->invalid++;
@@ -250,7 +259,7 @@ if (is_array($_FILES['_file'])) {
if ($success) {
$IMPORT_STATS->inserted++;
- $IMPORT_STATS->names[] = $vcard->displayname ? $vcard->displayname : $email;
+ $IMPORT_STATS->names[] = $a_record['name'] ? $a_record['name'] : $email;
}
else {
$IMPORT_STATS->errors++;
diff --git a/program/steps/addressbook/save.inc b/program/steps/addressbook/save.inc
index 7bd7da302..e7e5efc63 100644
--- a/program/steps/addressbook/save.inc
+++ b/program/steps/addressbook/save.inc
@@ -82,7 +82,7 @@ if (empty($a_record['name'])) {
// do input checks (delegated to $CONTACTS instance)
if (!$CONTACTS->validate($a_record)) {
$err = (array)$CONTACTS->get_error();
- $OUTPUT->show_message($err['message'] ? $err['message'] : 'formincomplete', 'warning');
+ $OUTPUT->show_message($err['message'] ? Q($err['message']) : 'formincomplete', 'warning');
$GLOBALS['EDIT_RECORD'] = $a_record; // store submitted data to be used in edit form
rcmail_overwrite_action($return_action);
return;
@@ -192,7 +192,7 @@ else {
if (($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($counts->count + 1 > $maxnum))
$OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum));
- $CONTACTS->add_to_group($gid, $plugin['ids']);
+ $CONTACTS->add_to_group($plugin['group_id'], $plugin['ids']);
}
}
else
diff --git a/program/steps/addressbook/show.inc b/program/steps/addressbook/show.inc
index b5870f463..63abc8c4b 100644
--- a/program/steps/addressbook/show.inc
+++ b/program/steps/addressbook/show.inc
@@ -101,8 +101,6 @@ function rcmail_contact_head($attrib)
return false;
}
- $microformats = array('name' => 'fn', 'email' => 'email');
-
$form = array(
'head' => array( // section 'head' is magic!
'content' => array(
@@ -177,7 +175,7 @@ function rcmail_contact_details($attrib)
}
-function rcmail_render_email_value($email, $col)
+function rcmail_render_email_value($email)
{
return html::a(array(
'href' => 'mailto:' . $email,
@@ -188,7 +186,7 @@ function rcmail_render_email_value($email, $col)
}
-function rcmail_render_url_value($url, $col)
+function rcmail_render_url_value($url)
{
$prefix = preg_match('!^(http|ftp)s?://!', $url) ? '' : 'http://';
return html::a(array(
@@ -226,7 +224,7 @@ function rcmail_contact_record_groups($contact_id)
}
$hiddenfields = new html_hiddenfield(array('name' => '_source', 'value' => get_input_value('_source', RCUBE_INPUT_GPC)));
- $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
+ $hiddenfields->add(array('name' => '_cid', 'value' => $contact_id));
$form_start = $RCMAIL->output->request_form(array(
'name' => "form", 'method' => "post",