Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

list_contacts.inc 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/mail/list_contacts.inc |
  5. | |
  6. | This file is part of the Roundcube Webmail client |
  7. | Copyright (C) 2012-2014, The Roundcube Dev Team |
  8. | |
  9. | Licensed under the GNU General Public License version 3 or |
  10. | any later version with exceptions for skins & plugins. |
  11. | See the README file for a full license statement. |
  12. | |
  13. | PURPOSE: |
  14. | Send contacts list to client (as remote response) |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Thomas Bruederli <roundcube@gmail.com> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. $afields = $RCMAIL->config->get('contactlist_fields');
  21. $addr_sort_col = $RCMAIL->config->get('addressbook_sort_col', 'name');
  22. $page_size = $RCMAIL->config->get('addressbook_pagesize', $RCMAIL->config->get('pagesize', 50));
  23. $list_page = max(1, intval($_GET['_page']));
  24. $jsresult = array();
  25. // Use search result
  26. if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']])) {
  27. $search = (array)$_SESSION['search'][$_REQUEST['_search']];
  28. $sparam = $_SESSION['search_params']['id'] == $_REQUEST['_search'] ? $_SESSION['search_params']['data'] : array();
  29. // get records from all sources
  30. foreach ($search as $s => $set) {
  31. $CONTACTS = $RCMAIL->get_address_book($s);
  32. // list matching groups of this source (on page one)
  33. if ($sparam[1] && $CONTACTS->groups && $list_page == 1) {
  34. $jsresult += rcmail_compose_contact_groups($CONTACTS, $s, $sparam[1], (int)$RCMAIL->config->get('addressbook_search_mode'));
  35. }
  36. // reset page
  37. $CONTACTS->set_page(1);
  38. $CONTACTS->set_pagesize(9999);
  39. $CONTACTS->set_search_set($set);
  40. // get records
  41. $result = $CONTACTS->list_records($afields);
  42. while ($row = $result->next()) {
  43. $row['sourceid'] = $s;
  44. $key = rcube_addressbook::compose_contact_key($row, $addr_sort_col);
  45. $records[$key] = $row;
  46. }
  47. unset($result);
  48. }
  49. // sort the records
  50. ksort($records, SORT_LOCALE_STRING);
  51. // create resultset object
  52. $count = count($records);
  53. $first = ($list_page-1) * $page_size;
  54. $result = new rcube_result_set($count, $first);
  55. // we need only records for current page
  56. if ($page_size < $count) {
  57. $records = array_slice($records, $first, $page_size);
  58. }
  59. $result->records = array_values($records);
  60. }
  61. // list contacts from selected source
  62. else {
  63. $source = rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC);
  64. $CONTACTS = $RCMAIL->get_address_book($source);
  65. if ($CONTACTS && $CONTACTS->ready) {
  66. // set list properties
  67. $CONTACTS->set_pagesize($page_size);
  68. $CONTACTS->set_page($list_page);
  69. if ($group_id = rcube_utils::get_input_value('_gid', rcube_utils::INPUT_GPC)) {
  70. $CONTACTS->set_group($group_id);
  71. }
  72. // list groups of this source (on page one)
  73. else if ($CONTACTS->groups && $CONTACTS->list_page == 1) {
  74. $jsresult = rcmail_compose_contact_groups($CONTACTS, $source);
  75. }
  76. // get contacts for this user
  77. $result = $CONTACTS->list_records($afields);
  78. }
  79. }
  80. if (!empty($result) && !$result->count && $result->searchonly) {
  81. $OUTPUT->show_message('contactsearchonly', 'notice');
  82. }
  83. else if (!empty($result) && $result->count > 0) {
  84. // create javascript list
  85. while ($row = $result->next()) {
  86. $name = rcube_addressbook::compose_list_name($row);
  87. // add record for every email address of the contact
  88. $emails = $CONTACTS->get_col_values('email', $row, true);
  89. foreach ($emails as $i => $email) {
  90. $row_id = $row['ID'].'-'.$i;
  91. $jsresult[$row_id] = format_email_recipient($email, $name);
  92. $classname = $row['_type'] == 'group' ? 'group' : 'person';
  93. $keyname = $row['_type'] == 'group' ? 'contactgroup' : 'contact';
  94. $OUTPUT->command('add_contact_row', $row_id, array(
  95. $keyname => html::a(array('title' => $email), rcube::Q($name ?: $email) .
  96. ($name && count($emails) > 1 ? '&nbsp;' . html::span('email', rcube::Q($email)) : '')
  97. )), $classname);
  98. }
  99. }
  100. }
  101. // update env
  102. $OUTPUT->set_env('contactdata', $jsresult);
  103. $OUTPUT->set_env('pagecount', ceil($result->count / $page_size));
  104. $OUTPUT->command('set_page_buttons');
  105. // send response
  106. $OUTPUT->send();