source: github/program/steps/addressbook/func.inc @ bb8012c

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since bb8012c was bb8012c, checked in by alecpl <alec@…>, 3 years ago
  • Extend contact groups support (#1486682)
  • Property mode set to 100644
File size: 7.2 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/steps/addressbook/func.inc                                    |
6 |                                                                       |
7 | This file is part of the RoundCube Webmail client                     |
8 | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland                 |
9 | Licensed under the GNU GPL                                            |
10 |                                                                       |
11 | PURPOSE:                                                              |
12 |   Provide addressbook functionality and GUI objects                   |
13 |                                                                       |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16 +-----------------------------------------------------------------------+
17
18 $Id$
19
20*/
21
22// add list of address sources to client env
23$js_list = $RCMAIL->get_address_sources();
24
25// select source
26$source = get_input_value('_source', RCUBE_INPUT_GPC);
27
28// if source is not set use first directory
29if (empty($source))
30  $source = $js_list[key($js_list)]['id'];
31
32// instantiate a contacts object according to the given source
33$CONTACTS = $RCMAIL->get_address_book($source);
34
35$CONTACTS->set_pagesize($CONFIG['pagesize']);
36
37// set list properties and session vars
38if (!empty($_GET['_page']))
39  $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page'])));
40else
41  $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1);
42 
43if (!empty($_REQUEST['_gid']))
44  $CONTACTS->set_group(get_input_value('_gid', RCUBE_INPUT_GPC));
45
46// set message set for search result
47if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
48  $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_search']]);
49
50// set data source env
51$OUTPUT->set_env('source', $source ? $source : '0');
52$OUTPUT->set_env('readonly', $CONTACTS->readonly, false);
53if(! $OUTPUT->ajax_call)
54  $OUTPUT->set_env('address_sources', $js_list);
55
56
57function rcmail_directory_list($attrib)
58{
59  global $RCMAIL, $OUTPUT;
60 
61  if (!$attrib['id'])
62    $attrib['id'] = 'rcmdirectorylist';
63
64  $out = '';
65  $local_id = '0';
66  $jsdata = array();
67  $current = get_input_value('_source', RCUBE_INPUT_GPC);
68  $line_templ = html::tag('li', array('id' => 'rcmli%s', 'class' => 'addressbook %s'),
69    html::a(array('href' => '%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s'));
70
71  if (!$current && strtolower($RCMAIL->config->get('address_book_type', 'sql')) != 'ldap') {
72    $current = '0';
73  }
74  else if (!$current) {
75    // DB address book not used, see if a source is set, if not use the
76    // first LDAP directory.
77    $current = key((array)$RCMAIL->config->get('ldap_public', array()));
78  }
79
80  foreach ((array)$OUTPUT->env['address_sources'] as $j => $source) {
81    $id = $source['id'] ? $source['id'] : $j;
82    $js_id = JQ($id);
83    $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id);
84    $out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''),
85      Q(rcmail_url(null, array('_source' => $id))), $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id)));
86    $groupdata = rcmail_contact_groups(array('out' => $out, 'jsdata' => $jsdata, 'source' => $id));
87    $jsdata = $groupdata['jsdata'];
88    $out = $groupdata['out'];
89  }
90
91  $OUTPUT->set_env('contactgroups', $jsdata);
92  $OUTPUT->add_gui_object('folderlist', $attrib['id']);
93 
94  return html::tag('ul', $attrib, $out, html::$common_attrib);
95}
96
97
98function rcmail_contact_groups($args)
99{
100  global $RCMAIL;
101
102  $groups = $RCMAIL->get_address_book($args['source'])->list_groups();
103
104  if (!empty($groups)) {
105    $line_templ = html::tag('li', array('id' => 'rcmliG%s%s', 'class' => 'contactgroup'),
106      html::a(array('href' => '#', 'onclick' => "return ".JS_OBJECT_NAME.".command('listgroup',{'source':'%s','id':'%s'},this)"), '%s'));
107
108    $jsdata = array();
109    foreach ($groups as $group) {
110      $args['out'] .= sprintf($line_templ, $args['source'], $group['ID'], $args['source'], $group['ID'], Q($group['name']));
111      $args['jsdata']['G'.$args['source'].$group['ID']] = array(
112        'source' => $args['source'], 'id' => $group['ID'], 'name' => $group['name'], 'type' => 'group');
113    }
114  }
115
116  return $args;
117}
118
119
120// return the message list as HTML table
121function rcmail_contacts_list($attrib)
122  {
123  global $CONTACTS, $OUTPUT;
124 
125  // count contacts for this user
126  $result = $CONTACTS->list_records();
127 
128  // add id to message list table if not specified
129  if (!strlen($attrib['id']))
130    $attrib['id'] = 'rcmAddressList';
131 
132  // define list of cols to be displayed
133  $a_show_cols = array('name');
134
135  // create XHTML table
136  $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key);
137 
138  // set client env
139  $OUTPUT->add_gui_object('contactslist', $attrib['id']);
140  $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page);
141  $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size));
142  $OUTPUT->include_script('list.js');
143 
144  // add some labels to client
145  $OUTPUT->add_label('deletecontactconfirm');
146 
147  return $out;
148  }
149
150
151function rcmail_js_contacts_list($result, $prefix='')
152  {
153  global $OUTPUT;
154
155  if (empty($result) || $result->count == 0)
156    return;
157
158  // define list of cols to be displayed
159  $a_show_cols = array('name');
160 
161  while ($row = $result->next())
162    {
163    $a_row_cols = array();
164   
165    // format each col
166    foreach ($a_show_cols as $col)
167      $a_row_cols[$col] = Q($row[$col]);
168   
169    $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
170    }
171  }
172
173
174// similar function as /steps/settings/identities.inc::rcmail_identity_frame()
175function rcmail_contact_frame($attrib)
176  {
177  global $OUTPUT;
178
179  if (!$attrib['id'])
180    $attrib['id'] = 'rcmcontactframe';
181   
182  $attrib['name'] = $attrib['id'];
183
184  $OUTPUT->set_env('contentframe', $attrib['name']);
185  $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
186
187  return html::iframe($attrib);
188  }
189
190
191function rcmail_rowcount_display($attrib)
192  {
193  global $OUTPUT;
194 
195  if (!$attrib['id'])
196    $attrib['id'] = 'rcmcountdisplay';
197
198  $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
199
200  return html::span($attrib, rcmail_get_rowcount_text());
201  }
202
203
204
205function rcmail_get_rowcount_text()
206  {
207  global $CONTACTS;
208 
209  // read nr of contacts
210  $result = $CONTACTS->get_result();
211  if (!$result)
212    $result = $CONTACTS->count();
213 
214  if ($result->count == 0)
215    $out = rcube_label('nocontactsfound');
216  else
217    $out = rcube_label(array(
218      'name' => 'contactsfromto',
219      'vars' => array(
220        'from'  => $result->first + 1,
221        'to'    => min($result->count, $result->first + $CONTACTS->page_size),
222        'count' => $result->count)
223      ));
224
225  return $out;
226  }
227
228
229$OUTPUT->set_pagetitle(rcube_label('addressbook'));
230 
231// register UI objects
232$OUTPUT->add_handlers(array(
233  'directorylist' => 'rcmail_directory_list',
234//  'groupslist' => 'rcmail_contact_groups',
235  'addresslist' => 'rcmail_contacts_list',
236  'addressframe' => 'rcmail_contact_frame',
237  'recordscountdisplay' => 'rcmail_rowcount_display',
238  'searchform' => array($OUTPUT, 'search_form')
239));
240
241?>
Note: See TracBrowser for help on using the repository browser.