diff options
Diffstat (limited to 'program/steps/addressbook/func.inc')
-rw-r--r-- | program/steps/addressbook/func.inc | 187 |
1 files changed, 38 insertions, 149 deletions
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc index f94d15338..989b7c1c4 100644 --- a/program/steps/addressbook/func.inc +++ b/program/steps/addressbook/func.inc @@ -183,10 +183,11 @@ function rcmail_directory_list($attrib) $attrib['id'] = 'rcmdirectorylist'; $out = ''; + $local_id = '0'; $jsdata = array(); $line_templ = html::tag('li', array( - 'id' => 'rcmli%s', 'class' => '%s', 'noclose' => true), + 'id' => 'rcmli%s', 'class' => '%s'), html::a(array('href' => '%s', 'rel' => '%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s')); @@ -212,7 +213,7 @@ function rcmail_directory_list($attrib) $name = !empty($source['name']) ? $source['name'] : $id; $out .= sprintf($line_templ, - rcube_utils::html_identifier($id, true), + html_identifier($id), $class_name, Q(rcmail_url(null, array('_source' => $id))), $source['id'], @@ -223,11 +224,10 @@ function rcmail_directory_list($attrib) $groupdata = rcmail_contact_groups($groupdata); $jsdata = $groupdata['jsdata']; $out = $groupdata['out']; - $out .= '</li>'; } $line_templ = html::tag('li', array( - 'id' => 'rcmli%s', 'class' => '%s'), + 'id' => 'rcmliS%s', 'class' => '%s'), html::a(array('href' => '#', 'rel' => 'S%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('listsearch', '%s', this)"), '%s')); @@ -245,17 +245,14 @@ function rcmail_directory_list($attrib) $class_name .= ' ' . $source['class_name']; $out .= sprintf($line_templ, - rcube_utils::html_identifier('S'.$id, true), + html_identifier($id), $class_name, $id, $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id))); } $OUTPUT->set_env('contactgroups', $jsdata); - $OUTPUT->set_env('collapsed_abooks', (string)$RCMAIL->config->get('collapsed_abooks','')); $OUTPUT->add_gui_object('folderlist', $attrib['id']); - $OUTPUT->include_script('treelist.js'); - // add some labels to client $OUTPUT->add_label('deletegroupconfirm', 'groupdeleting', 'addingmember', 'removingmember'); @@ -267,23 +264,19 @@ function rcmail_contact_groups($args) { global $RCMAIL; - $groups_html = ''; $groups = $RCMAIL->get_address_book($args['source'])->list_groups(); if (!empty($groups)) { $line_templ = html::tag('li', array( - 'id' => 'rcmli%s', 'class' => 'contactgroup'), + 'id' => 'rcmliG%s', 'class' => 'contactgroup'), html::a(array('href' => '#', 'rel' => '%s:%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('listgroup',{'source':'%s','id':'%s'},this)"), '%s')); - // append collapse/expand toggle and open a new <ul> - $is_collapsed = strpos($RCMAIL->config->get('collapsed_abooks',''), '&'.rawurlencode($args['source']).'&') !== false; - $args['out'] .= html::div('treetoggle ' . ($is_collapsed ? 'collapsed' : 'expanded'), ' '); - + $jsdata = array(); foreach ($groups as $group) { - $groups_html .= sprintf($line_templ, - rcube_utils::html_identifier('G' . $args['source'] . $group['ID'], true), + $args['out'] .= sprintf($line_templ, + html_identifier($args['source'] . $group['ID']), $args['source'], $group['ID'], $args['source'], $group['ID'], Q($group['name']) ); @@ -293,10 +286,6 @@ function rcmail_contact_groups($args) } } - $args['out'] .= html::tag('ul', - array('class' => 'groups', 'style' => ($is_collapsed || empty($groups) ? "display:none;" : null)), - $groups_html); - return $args; } @@ -307,7 +296,7 @@ function rcmail_contacts_list($attrib) global $CONTACTS, $OUTPUT; // define list of cols to be displayed - $a_show_cols = array('name','action'); + $a_show_cols = array('name'); // add id to message list table if not specified if (!strlen($attrib['id'])) @@ -322,7 +311,7 @@ function rcmail_contacts_list($attrib) $OUTPUT->include_script('list.js'); // add some labels to client - $OUTPUT->add_label('deletecontactconfirm', 'copyingcontact', 'movingcontact', 'contactdeleting'); + $OUTPUT->add_label('deletecontactconfirm', 'copyingcontact', 'contactdeleting'); return $out; } @@ -336,73 +325,31 @@ function rcmail_js_contacts_list($result, $prefix='') return; // define list of cols to be displayed - $a_show_cols = array('name','action'); + $a_show_cols = array('name'); 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'); + $classes = array('person'); // org records will follow some day // build contact ID with source ID if (isset($row['sourceid'])) { $row['ID'] = $row['ID'].'-'.$row['sourceid']; - $source_id = $row['sourceid']; } // format each col foreach ($a_show_cols as $col) { - $val = ''; - switch ($col) { - case 'name': - $val = Q(rcube_addressbook::compose_list_name($row)); - break; - - case 'action': - if ($row['_type'] == 'group') { - $val = html::a(array( - 'href' => '#list', - 'rel' => $row['ID'], - 'title' => rcube_label('listgroup'), - 'onclick' => sprintf("return %s.command('pushgroup',{'source':'%s','id':'%s'},this,event)", JS_OBJECT_NAME, $source_id, $row['CID']), - ), '»'); - } - else - $val = ' '; - break; - - default: - $val = Q($row[$col]); - break; - } - - $a_row_cols[$col] = $val; + $val = $col == 'name' ? rcube_addressbook::compose_list_name($row) : $row[$col]; + $a_row_cols[$col] = Q($val); } if ($row['readonly']) $classes[] = 'readonly'; - $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))); + $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols, join(' ', $classes)); } } -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); -} - - // similar function as /steps/settings/identities.inc::rcmail_identity_frame() function rcmail_contact_frame($attrib) { @@ -471,7 +418,7 @@ function rcmail_get_type_label($type) function rcmail_contact_form($form, $record, $attrib = null) { - global $RCMAIL; + global $RCMAIL, $CONFIG; // Allow plugins to modify contact form content $plugin = $RCMAIL->plugins->exec_hook('contact_form', array( @@ -480,7 +427,7 @@ function rcmail_contact_form($form, $record, $attrib = null) $form = $plugin['form']; $record = $plugin['record']; $edit_mode = $RCMAIL->action != 'show'; - $del_button = $attrib['deleteicon'] ? html::img(array('src' => $RCMAIL->output->get_skin_file($attrib['deleteicon']), 'alt' => rcube_label('delete'))) : rcube_label('delete'); + $del_button = $attrib['deleteicon'] ? html::img(array('src' => $CONFIG['skin_path'] . $attrib['deleteicon'], 'alt' => rcube_label('delete'))) : rcube_label('delete'); unset($attrib['deleteicon']); $out = ''; @@ -593,13 +540,22 @@ 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 (rcube_addressbook::get_col_values($field, $record) as $st => $vals) { - foreach((array)$vals as $value) { - $i = count($values); - $subtypes[$i] = $st; - $values[$i] = $value; + 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; } - // TODO: add $st to $select_subtype if missing ? } } else { @@ -737,42 +693,23 @@ function rcmail_contact_form($form, $record, $attrib = null) function rcmail_contact_photo($attrib) { - global $SOURCE_ID, $CONTACTS, $CONTACT_COLTYPES, $RCMAIL; + global $SOURCE_ID, $CONTACTS, $CONTACT_COLTYPES, $RCMAIL, $CONFIG; if ($result = $CONTACTS->get_result()) $record = $result->first(); - $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']); - + $photo_img = $attrib['placeholder'] ? $CONFIG['skin_path'] . $attrib['placeholder'] : 'program/resources/blank.gif'; $RCMAIL->output->set_env('photo_placeholder', $photo_img); unset($attrib['placeholder']); $plugin = $RCMAIL->plugins->exec_hook('contact_photo', array('record' => $record, 'data' => $record['photo'])); - // check if we have photo data from contact form - if ($GLOBALS['EDIT_RECORD']) { - $rec = $GLOBALS['EDIT_RECORD']; - if ($rec['photo'] == '-del-') { - $record['photo'] = ''; - } - else if ($_SESSION['contacts']['files'][$rec['photo']]) { - $record['photo'] = $file_id = $rec['photo']; - } - } - if ($plugin['url']) $photo_img = $plugin['url']; else if (preg_match('!^https?://!i', $record['photo'])) $photo_img = $record['photo']; - else if ($record['photo']) { - $url = array('_action' => 'photo', '_cid' => $record['ID'], '_source' => $SOURCE_ID); - if ($file_id) { - $url['_photo'] = $ff_value = $file_id; - } - $photo_img = $RCMAIL->url($url); - } + else if ($record['photo']) + $photo_img = $RCMAIL->url(array('_action' => 'photo', '_cid' => $record['ID'], '_source' => $SOURCE_ID)); else $ff_value = '-del-'; // will disable delete-photo action @@ -795,54 +732,6 @@ function rcmail_format_date_col($val) 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 @@ -900,7 +789,6 @@ $OUTPUT->add_handlers(array( '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') @@ -909,6 +797,7 @@ $OUTPUT->add_handlers(array( // register action aliases $RCMAIL->register_action_map(array( 'add' => 'edit.inc', + 'photo' => 'show.inc', 'group-create' => 'groups.inc', 'group-rename' => 'groups.inc', 'group-delete' => 'groups.inc', |