diff options
Diffstat (limited to 'program/steps')
-rw-r--r-- | program/steps/addressbook/copy.inc | 2 | ||||
-rw-r--r-- | program/steps/addressbook/delete.inc | 38 | ||||
-rw-r--r-- | program/steps/addressbook/func.inc | 50 | ||||
-rw-r--r-- | program/steps/addressbook/list.inc | 44 | ||||
-rw-r--r-- | program/steps/addressbook/move.inc | 206 | ||||
-rw-r--r-- | program/steps/addressbook/undo.inc | 25 | ||||
-rw-r--r-- | program/steps/mail/func.inc | 2 | ||||
-rw-r--r-- | program/steps/mail/move_del.inc | 4 |
8 files changed, 271 insertions, 100 deletions
diff --git a/program/steps/addressbook/copy.inc b/program/steps/addressbook/copy.inc index 59b4ffcc6..82917e2ac 100644 --- a/program/steps/addressbook/copy.inc +++ b/program/steps/addressbook/copy.inc @@ -118,7 +118,7 @@ foreach ($cids as $source => $cid) } } -if ($success == 0) +if (!$success) $OUTPUT->show_message($errormsg, 'error'); else $OUTPUT->show_message('copysuccess', 'notice', array('nr' => $success)); diff --git a/program/steps/addressbook/delete.inc b/program/steps/addressbook/delete.inc index 56118583c..3bb2ef500 100644 --- a/program/steps/addressbook/delete.inc +++ b/program/steps/addressbook/delete.inc @@ -68,48 +68,14 @@ foreach ($cids as $source => $cid) $page = isset($_SESSION['page']) ? $_SESSION['page'] : 1; // update saved search after data changed -if (($search_request = $_REQUEST['_search']) && isset($_SESSION['search'][$search_request])) { - $sort_col = $RCMAIL->config->get('addressbook_sort_col', 'name'); - $afields = $RCMAIL->config->get('contactlist_fields'); - $search = (array)$_SESSION['search'][$search_request]; - $records = array(); - - // Get records from all sources (refresh search) - 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; - } - - 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; - +if (($records = rcmail_search_update(true)) !== false) { // create resultset object $count = count($records); $first = ($page-1) * $PAGE_SIZE; $result = new rcube_result_set($count, $first); + $pages = ceil((count($records) + $delcnt) / $PAGE_SIZE); // get records from the next page to add to the list - $pages = ceil((count($records) + $delcnt) / $PAGE_SIZE); if ($_GET['_from'] != 'show' && $pages > 1 && $page < $pages) { // sort the records ksort($records, SORT_LOCALE_STRING); diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc index c7f7fb479..8ec581f9a 100644 --- a/program/steps/addressbook/func.inc +++ b/program/steps/addressbook/func.inc @@ -322,7 +322,7 @@ function rcmail_contacts_list($attrib) $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; } @@ -779,6 +779,54 @@ 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 diff --git a/program/steps/addressbook/list.inc b/program/steps/addressbook/list.inc index 6f3a3e0f3..aca58d279 100644 --- a/program/steps/addressbook/list.inc +++ b/program/steps/addressbook/list.inc @@ -19,47 +19,20 @@ +-----------------------------------------------------------------------+ */ -$afields = $RCMAIL->config->get('contactlist_fields'); +if (!empty($_GET['_page'])) + $page = intval($_GET['_page']); +else + $page = !empty($_SESSION['page']) ? $_SESSION['page'] : 1; -// Use search result -if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']])) -{ - $search = (array)$_SESSION['search'][$_REQUEST['_search']]; - $records = array(); - - if (!empty($_GET['_page'])) - $page = intval($_GET['_page']); - else - $page = isset($_SESSION['page']) ? $_SESSION['page'] : 1; - - $_SESSION['page'] = $page; - $sort_col = $RCMAIL->config->get('addressbook_sort_col', 'name'); - - // Get records from all sources - 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); - - while ($row = $result->next()) { - $row['sourceid'] = $s; - $key = rcube_addressbook::compose_contact_key($row, $sort_col); - $records[$key] = $row; - } - unset($result); - } +$_SESSION['page'] = $page; +// Use search result +if (($records = rcmail_search_update(true)) !== false) { // sort the records ksort($records, SORT_LOCALE_STRING); // create resultset object - $count = count($records); + $count = count($records); $first = ($page-1) * $PAGE_SIZE; $result = new rcube_result_set($count, $first); @@ -72,6 +45,7 @@ if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search } // List selected directory else { + $afields = $RCMAIL->config->get('contactlist_fields'); $CONTACTS = rcmail_contact_source(null, true); // get contacts for this user diff --git a/program/steps/addressbook/move.inc b/program/steps/addressbook/move.inc new file mode 100644 index 000000000..42180d777 --- /dev/null +++ b/program/steps/addressbook/move.inc @@ -0,0 +1,206 @@ +<?php + +/* + +-----------------------------------------------------------------------+ + | program/steps/addressbook/move.inc | + | | + | This file is part of the Roundcube Webmail client | + | Copyright (C) 2007-2013, The Roundcube Dev Team | + | | + | 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: | + | Move a contact record from one direcotry to another | + +-----------------------------------------------------------------------+ + | Author: Thomas Bruederli <roundcube@gmail.com> | + | Author: Aleksander Machniak <alec@alec.pl> | + +-----------------------------------------------------------------------+ +*/ + +// only process ajax requests +if (!$OUTPUT->ajax_call) { + return; +} + +$cids = rcmail_get_cids(); +$target = get_input_value('_to', RCUBE_INPUT_POST); +$target_group = get_input_value('_togid', RCUBE_INPUT_POST); + +$all = 0; +$deleted = 0; +$success = 0; +$errormsg = 'moveerror'; +$maxnum = $RCMAIL->config->get('max_group_members', 0); +$page = !empty($_SESSION['page']) ? $_SESSION['page'] : 1; + +foreach ($cids as $source => $source_cids) { + // Something wrong, target not specified + if (!strlen($target)) { + break; + } + + // It maight happen when moving records from search result + // Do nothing, go to next source + if ((string)$target === (string)$source) { + continue; + } + + $CONTACTS = $RCMAIL->get_address_book($source); + $TARGET = $RCMAIL->get_address_book($target); + + if (!$TARGET || !$TARGET->ready || $TARGET->readonly) { + break; + } + + if (!$CONTACTS || !$CONTACTS->ready || $CONTACTS->readonly) { + continue; + } + + $ids = array(); + + foreach ($source_cids as $idx => $cid) { + $a_record = $CONTACTS->get_record($cid, true); + + // avoid moving groups + if ($a_record['_type'] == 'group') { + unset($source_cids[$idx]); + continue; + } + + // Check if contact exists, if so, we'll need it's ID + // Note: Some addressbooks allows empty email address field + if (!empty($a_record['email'])) + $result = $TARGET->search('email', $a_record['email'], 1, true, true); + else if (!empty($a_record['name'])) + $result = $TARGET->search('name', $a_record['name'], 1, true, true); + else + $result = new rcube_result_set(); + + // insert contact record + if (!$result->count) { + $plugin = $RCMAIL->plugins->exec_hook('contact_create', array( + 'record' => $a_record, 'source' => $target, 'group' => $target_group)); + + if (!$plugin['abort']) { + if ($insert_id = $TARGET->insert($plugin['record'], false)) { + $ids[] = $insert_id; + $success++; + } + } + else if ($plugin['result']) { + $ids = array_merge($ids, $plugin['result']); + $success++; + } + } + else { + $record = $result->first(); + $ids[] = $record['ID']; + $errormsg = empty($a_record['email']) ? 'contactnameexists' : 'contactexists'; + } + } + + // remove source contacts + if ($success && !empty($source_cids)) { + $all += count($source_cids); + $plugin = $RCMAIL->plugins->exec_hook('contact_delete', array( + 'id' => $source_cids, 'source' => $source)); + + $del_status = !$plugin['abort'] ? $CONTACTS->delete($source_cids) : $plugin['result']; + + if ($del_status) { + $deleted += $del_status; + } + } + + // assign to group + if ($target_group && $TARGET->groups && !empty($ids)) { + $plugin = $RCMAIL->plugins->exec_hook('group_addmembers', array( + 'group_id' => $target_group, 'ids' => $ids, 'source' => $target)); + + if (!$plugin['abort']) { + $TARGET->reset(); + $TARGET->set_group($target_group); + + if ($maxnum && ($TARGET->count()->count + count($plugin['ids']) > $maxnum)) { + $OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum)); + $OUTPUT->send(); + } + + if (($cnt = $TARGET->add_to_group($target_group, $plugin['ids'])) && $cnt > $success) + $success = $cnt; + } + else if ($plugin['result']) { + $success = $plugin['result']; + } + + $errormsg = $plugin['message'] ? $plugin['message'] : 'moveerror'; + } +} + +if (!$deleted || $deleted != $all) { + // update saved search after data changed + if ($deleted) { + rcmail_search_update(); + } + $OUTPUT->command('list_contacts'); +} +else { + // update saved search after data changed + if (($records = rcmail_search_update(true)) !== false) { + // create resultset object + $count = count($records); + $first = ($page-1) * $PAGE_SIZE; + $result = new rcube_result_set($count, $first); + $pages = ceil((count($records) + $delcnt) / $PAGE_SIZE); + + // get records from the next page to add to the list + if ($_GET['_from'] != 'show' && $pages > 1 && $page < $pages) { + // sort the records + ksort($records, SORT_LOCALE_STRING); + + $first += $PAGE_SIZE; + // create resultset object + $res = new rcube_result_set($count, $first - $deleted); + + if ($PAGE_SIZE < $count) { + $records = array_slice($records, $first - $deleted, $deleted); + } + + $res->records = array_values($records); + $records = $res; + } + else { + unset($records); + } + } + else { + // count contacts for this user + $result = $CONTACTS->count(); + // get records from the next page to add to the list + $pages = ceil(($result->count + $deleted) / $PAGE_SIZE); + + if ($_GET['_from'] != 'show' && $pages > 1 && $page < $pages) { + $CONTACTS->set_page($page); + $records = $CONTACTS->list_records(null, -$deleted); + } + } + + // update message count display + $OUTPUT->set_env('pagecount', ceil($result->count / $PAGE_SIZE)); + $OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($result)); + + // add new rows from next page (if any) + if (!empty($records)) { + rcmail_js_contacts_list($records); + } +} + +if (!$success) + $OUTPUT->show_message($errormsg, 'error'); +else + $OUTPUT->show_message('movesuccess', 'notice', array('nr' => $success)); + +// send response +$OUTPUT->send(); diff --git a/program/steps/addressbook/undo.inc b/program/steps/addressbook/undo.inc index 9c171143c..c23bd1cb6 100644 --- a/program/steps/addressbook/undo.inc +++ b/program/steps/addressbook/undo.inc @@ -46,30 +46,7 @@ foreach ((array)$undo['data'] as $source => $cid) } // update saved search after data changed -if ($delcnt && ($search_request = $_REQUEST['_search']) && isset($_SESSION['search'][$search_request])) { - $search = (array)$_SESSION['search'][$search_request]; - - 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(array('name', 'email')); - - if (!$result->count) { - unset($search[$s]); - continue; - } - - $search[$s] = $source->get_search_set(); - } - - $_SESSION['search'][$search_request] = $search; -} +rcmail_search_update(); $RCMAIL->session->remove('contact_undo'); diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 07c315ea7..454650628 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -149,7 +149,7 @@ $RCMAIL->register_action_map(array( 'refresh' => 'check_recent.inc', 'preview' => 'show.inc', 'print' => 'show.inc', - 'moveto' => 'move_del.inc', + 'move' => 'move_del.inc', 'delete' => 'move_del.inc', 'send' => 'sendmail.inc', 'expunge' => 'folders.inc', diff --git a/program/steps/mail/move_del.inc b/program/steps/mail/move_del.inc index e21ba2c6b..f15cd2460 100644 --- a/program/steps/mail/move_del.inc +++ b/program/steps/mail/move_del.inc @@ -29,7 +29,7 @@ $old_count = $RCMAIL->storage->count(NULL, $threading ? 'THREADS' : 'ALL'); $old_pages = ceil($old_count / $RCMAIL->storage->get_pagesize()); // move messages -if ($RCMAIL->action == 'moveto' && !empty($_POST['_uid']) && strlen($_POST['_target_mbox'])) { +if ($RCMAIL->action == 'move' && !empty($_POST['_uid']) && strlen($_POST['_target_mbox'])) { $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST)))); $target = get_input_value('_target_mbox', RCUBE_INPUT_POST, true); $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true); @@ -126,7 +126,7 @@ else rcmail_set_unseen_count($mbox, $unseen_count); } - if ($RCMAIL->action == 'moveto' && strlen($target)) { + if ($RCMAIL->action == 'move' && strlen($target)) { rcmail_send_unread_count($target, true); } |