Thomas Bruederli
2012-11-03 79f1c6f8091525aee2a6b64836c8f5e25dc7b79c
program/steps/addressbook/save.inc
@@ -6,7 +6,10 @@
 |                                                                       |
 | This file is part of the Roundcube Webmail client                     |
 | Copyright (C) 2005-2011, The Roundcube Dev Team                       |
 | Licensed under the GNU GPL                                            |
 |                                                                       |
 | Licensed under the GNU General Public License version 3 or            |
 | any later version with exceptions for skins & plugins.                |
 | See the README file for a full license statement.                     |
 |                                                                       |
 | PURPOSE:                                                              |
 |   Save a contact entry or to add a new one                            |
@@ -50,10 +53,12 @@
      foreach ((array)$vals as $i => $val)
        $values[$i][$childcol] = $val;
    }
    $subtypes = get_input_value('_subtype_' . $col, RCUBE_INPUT_POST);
    foreach ($subtypes as $i => $subtype)
    $subtypes = isset($_REQUEST['_subtype_' . $col]) ? (array)get_input_value('_subtype_' . $col, RCUBE_INPUT_POST) : array('');
    foreach ($subtypes as $i => $subtype) {
      $suffix = $subtype ? ':'.$subtype : '';
      if ($values[$i])
        $a_record[$col.':'.$subtype][] = $values[$i];
        $a_record[$col.$suffix][] = $values[$i];
     }
  }
  // assign values and subtypes
  else if (is_array($_POST[$fname])) {
@@ -79,8 +84,8 @@
// do input checks (delegated to $CONTACTS instance)
if (!$CONTACTS->validate($a_record)) {
    $err = (array)$CONTACTS->get_error() + array('message' => 'formincomplete', 'type' => 'warning');
    $OUTPUT->show_message($err['message'], $err['type']);
    $err = (array)$CONTACTS->get_error();
    $OUTPUT->show_message($err['message'] ? $err['message'] : 'formincomplete', 'warning');
    $GLOBALS['EDIT_RECORD'] = $a_record;  // store submitted data to be used in edit form
    rcmail_overwrite_action($return_action);
    return;
@@ -130,8 +135,7 @@
    $a_js_cols = array();
    $record = $CONTACTS->get_record($newcid ? $newcid : $cid, true);
    $record['email'] = reset($CONTACTS->get_col_values('email', $record, true));
    if (empty($record['name']))
      $record['name']  = rcube_addressbook::compose_display_name($record, true);
    $record['name']  = rcube_addressbook::compose_list_name($record);
    foreach (array('name', 'email') as $col)
      $a_js_cols[] = Q((string)$record[$col]);
@@ -162,7 +166,7 @@
  // show notice if existing contacts with same e-mail are found
  $existing = false;
  foreach ($CONTACTS->get_col_values('email', $a_record, true) as $email) {
      if ($email && ($res = $CONTACTS->search('email', $email, false, false, true)) && $res->count) {
      if ($email && ($res = $CONTACTS->search('email', $email, 1, false, true)) && $res->count) {
          $OUTPUT->show_message('contactexists', 'notice', null, false);
          break;
      }
@@ -179,18 +183,24 @@
    $insert_id = $plugin['result'];
  if ($insert_id) {
    $CONTACTS->reset();
    // add new contact to the specified group
    if ($CONTACTS->groups && $CONTACTS->group_id) {
      $plugin = $RCMAIL->plugins->exec_hook('group_addmembers', array(
        'group_id' => $CONTACTS->group_id, 'ids' => $insert_id, 'source' => $source));
      $counts = $CONTACTS->count();
      if (!$plugin['abort']) {
        if (($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($CONTACTS->count()->count + 1 > $maxnum))
        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']);
      }
    }
    else
      $counts = $CONTACTS->count();
    if ((string)$source === (string)$orig_source) {
      // add contact row or jump to the page where it should appear
@@ -202,7 +212,7 @@
      // update record count display
      $CONTACTS->reset();
      $OUTPUT->command('parent.set_rowcount', rcmail_get_rowcount_text());
      $OUTPUT->command('parent.set_rowcount', rcmail_get_rowcount_text($counts));
    }
    else {
      // re-set iframe