Aleksander Machniak
2013-07-01 a45f9b7bf58475ccc812e819f159638403c00419
program/steps/addressbook/func.inc
@@ -26,7 +26,7 @@
  '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 @@
    // 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 @@
        $attrib['id'] = 'rcmdirectorylist';
    $out = '';
    $local_id = '0';
    $jsdata = array();
    $line_templ = html::tag('li', array(
@@ -268,8 +267,8 @@
{
    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 @@
        $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 @@
    }
    $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;
@@ -325,7 +322,7 @@
    $OUTPUT->include_script('list.js');
    // add some labels to client
    $OUTPUT->add_label('deletecontactconfirm', 'copyingcontact', 'contactdeleting');
    $OUTPUT->add_label('deletecontactconfirm', 'copyingcontact', 'movingcontact', 'contactdeleting');
    return $out;
}
@@ -343,6 +340,8 @@
    while ($row = $result->next()) {
        $row['CID'] = $row['ID'];
        $row['email'] = reset(rcube_addressbook::get_col_values('email', $row, true));
        $source_id = $OUTPUT->get_env('source');
        $a_row_cols = array();
        $classes = array($row['_type'] ? $row['_type'] : 'person');
@@ -367,9 +366,11 @@
                            'href' => '#list',
                            'rel' => $row['ID'],
                            'title' => rcube_label('listgroup'),
                            'onclick' => sprintf("return %s.command('pushgroup',{'source':'%s','id':'%s'},this)", JS_OBJECT_NAME, $source_id, $row['CID']),
                            'onclick' => sprintf("return %s.command('pushgroup',{'source':'%s','id':'%s'},this,event)", JS_OBJECT_NAME, $source_id, $row['CID']),
                        ), '»');
                    }
                    else
                        $val = ' ';
                    break;
                default:
@@ -383,8 +384,22 @@
        if ($row['readonly'])
            $classes[] = 'readonly';
        $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols, join(' ', $classes), $row);
        $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols, join(' ', $classes), array_intersect_key($row, array('ID'=>1,'readonly'=>1,'_type'=>1,'email'=>1,'name'=>1)));
    }
}
function rcmail_contacts_list_title($attrib)
{
    global $OUTPUT;
    $attrib += array('label' => 'contacts', 'id' => 'rcmabooklisttitle', 'tag' => 'span');
    unset($attrib['name']);
    $OUTPUT->add_gui_object('addresslist_title', $attrib['id']);
    $OUTPUT->add_label('contacts');
    return html::tag($attrib['tag'], $attrib, rcube_label($attrib['label']), html::$common_attrib);
}
@@ -456,7 +471,7 @@
function rcmail_contact_form($form, $record, $attrib = null)
{
    global $RCMAIL, $CONFIG;
    global $RCMAIL;
    // Allow plugins to modify contact form content
    $plugin = $RCMAIL->plugins->exec_hook('contact_form', array(
@@ -465,7 +480,7 @@
    $form = $plugin['form'];
    $record = $plugin['record'];
    $edit_mode = $RCMAIL->action != 'show';
    $del_button = $attrib['deleteicon'] ? html::img(array('src' => $CONFIG['skin_path'] . $attrib['deleteicon'], 'alt' => rcube_label('delete'))) : rcube_label('delete');
    $del_button = $attrib['deleteicon'] ? html::img(array('src' => $RCMAIL->output->get_skin_file($attrib['deleteicon']), 'alt' => rcube_label('delete'))) : rcube_label('delete');
    unset($attrib['deleteicon']);
    $out = '';
@@ -578,22 +593,13 @@
                    // 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];
                        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;
                            }
                            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;
                            }
                            // TODO: add $st to $select_subtype if missing ?
                        }
                    }
                    else {
@@ -731,12 +737,15 @@
function rcmail_contact_photo($attrib)
{
    global $SOURCE_ID, $CONTACTS, $CONTACT_COLTYPES, $RCMAIL, $CONFIG;
    global $SOURCE_ID, $CONTACTS, $CONTACT_COLTYPES, $RCMAIL;
    if ($result = $CONTACTS->get_result())
        $record = $result->first();
    $photo_img = $attrib['placeholder'] ? $CONFIG['skin_path'] . $attrib['placeholder'] : 'program/resources/blank.gif';
    $photo_img = $attrib['placeholder'] ? $RCMAIL->output->get_skin_file($attrib['placeholder']) : 'program/resources/blank.gif';
    if ($record['_type'] == 'group' && $attrib['placeholdergroup'])
        $photo_img = $RCMAIL->output->get_skin_file($attrib['placeholdergroup']);
    $RCMAIL->output->set_env('photo_placeholder', $photo_img);
    unset($attrib['placeholder']);
@@ -770,6 +779,54 @@
    return format_date($val, $RCMAIL->config->get('date_format', 'Y-m-d'), false);
}
/**
 * Updates saved search after data changed
 */
function rcmail_search_update($return = false)
{
    global $RCMAIL;
    if (($search_request = $_REQUEST['_search']) && isset($_SESSION['search'][$search_request])) {
        $search   = (array)$_SESSION['search'][$search_request];
        $sort_col = $RCMAIL->config->get('addressbook_sort_col', 'name');
        $afields  = $return ? $RCMAIL->config->get('contactlist_fields') : array('name', 'email');
        $records  = array();
        foreach ($search as $s => $set) {
            $source = $RCMAIL->get_address_book($s);
            // reset page
            $source->set_page(1);
            $source->set_pagesize(9999);
            $source->set_search_set($set);
            // get records
            $result = $source->list_records($afields);
            if (!$result->count) {
                unset($search[$s]);
                continue;
            }
            if ($return) {
                while ($row = $result->next()) {
                    $row['sourceid'] = $s;
                    $key = rcube_addressbook::compose_contact_key($row, $sort_col);
                    $records[$key] = $row;
                }
                unset($result);
            }
            $search[$s] = $source->get_search_set();
        }
        $_SESSION['search'][$search_request] = $search;
        return $records;
    }
    return false;
}
/**
 * Returns contact ID(s) and source(s) from GET/POST data
@@ -793,20 +850,27 @@
        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;
        }
    }
@@ -820,6 +884,7 @@
    'directorylist' => 'rcmail_directory_list',
//  'groupslist' => 'rcmail_contact_groups',
    'addresslist' => 'rcmail_contacts_list',
    'addresslisttitle' => 'rcmail_contacts_list_title',
    'addressframe' => 'rcmail_contact_frame',
    'recordscountdisplay' => 'rcmail_rowcount_display',
    'searchform' => array($OUTPUT, 'search_form')