source: github/program/steps/addressbook/func.inc @ 1a4fa6f

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since 1a4fa6f was 1a4fa6f, checked in by alecpl <alec@…>, 3 years ago
  • don't set pagetitle in ajax requests
  • 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  $OUTPUT->set_pagetitle(rcube_label('addressbook'));
56}
57
58function rcmail_directory_list($attrib)
59{
60  global $RCMAIL, $OUTPUT;
61 
62  if (!$attrib['id'])
63    $attrib['id'] = 'rcmdirectorylist';
64
65  $out = '';
66  $local_id = '0';
67  $jsdata = array();
68  $current = get_input_value('_source', RCUBE_INPUT_GPC);
69  $line_templ = html::tag('li', array('id' => 'rcmli%s', 'class' => 'addressbook %s'),
70    html::a(array('href' => '%s', 'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s'));
71
72  if (!$current && strtolower($RCMAIL->config->get('address_book_type', 'sql')) != 'ldap') {
73    $current = '0';
74  }
75  else if (!$current) {
76    // DB address book not used, see if a source is set, if not use the
77    // first LDAP directory.
78    $current = key((array)$RCMAIL->config->get('ldap_public', array()));
79  }
80
81  foreach ((array)$OUTPUT->env['address_sources'] as $j => $source) {
82    $id = $source['id'] ? $source['id'] : $j;
83    $js_id = JQ($id);
84    $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id);
85    $out .= sprintf($line_templ, $dom_id, ($current == $id ? 'selected' : ''),
86      Q(rcmail_url(null, array('_source' => $id))), $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id)));
87    $groupdata = rcmail_contact_groups(array('out' => $out, 'jsdata' => $jsdata, 'source' => $id));
88    $jsdata = $groupdata['jsdata'];
89    $out = $groupdata['out'];
90  }
91
92  $OUTPUT->set_env('contactgroups', $jsdata);
93  $OUTPUT->add_gui_object('folderlist', $attrib['id']);
94 
95  return html::tag('ul', $attrib, $out, html::$common_attrib);
96}
97
98
99function rcmail_contact_groups($args)
100{
101  global $RCMAIL;
102
103  $groups = $RCMAIL->get_address_book($args['source'])->list_groups();
104
105  if (!empty($groups)) {
106    $line_templ = html::tag('li', array('id' => 'rcmliG%s%s', 'class' => 'contactgroup'),
107      html::a(array('href' => '#', 'onclick' => "return ".JS_OBJECT_NAME.".command('listgroup',{'source':'%s','id':'%s'},this)"), '%s'));
108
109    $jsdata = array();
110    foreach ($groups as $group) {
111      $args['out'] .= sprintf($line_templ, $args['source'], $group['ID'], $args['source'], $group['ID'], Q($group['name']));
112      $args['jsdata']['G'.$args['source'].$group['ID']] = array(
113        'source' => $args['source'], 'id' => $group['ID'], 'name' => $group['name'], 'type' => 'group');
114    }
115  }
116
117  return $args;
118}
119
120
121// return the message list as HTML table
122function rcmail_contacts_list($attrib)
123  {
124  global $CONTACTS, $OUTPUT;
125 
126  // count contacts for this user
127  $result = $CONTACTS->list_records();
128 
129  // add id to message list table if not specified
130  if (!strlen($attrib['id']))
131    $attrib['id'] = 'rcmAddressList';
132 
133  // define list of cols to be displayed
134  $a_show_cols = array('name');
135
136  // create XHTML table
137  $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key);
138 
139  // set client env
140  $OUTPUT->add_gui_object('contactslist', $attrib['id']);
141  $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page);
142  $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size));
143  $OUTPUT->include_script('list.js');
144 
145  // add some labels to client
146  $OUTPUT->add_label('deletecontactconfirm');
147 
148  return $out;
149  }
150
151
152function rcmail_js_contacts_list($result, $prefix='')
153  {
154  global $OUTPUT;
155
156  if (empty($result) || $result->count == 0)
157    return;
158
159  // define list of cols to be displayed
160  $a_show_cols = array('name');
161 
162  while ($row = $result->next())
163    {
164    $a_row_cols = array();
165   
166    // format each col
167    foreach ($a_show_cols as $col)
168      $a_row_cols[$col] = Q($row[$col]);
169   
170    $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
171    }
172  }
173
174
175// similar function as /steps/settings/identities.inc::rcmail_identity_frame()
176function rcmail_contact_frame($attrib)
177  {
178  global $OUTPUT;
179
180  if (!$attrib['id'])
181    $attrib['id'] = 'rcmcontactframe';
182   
183  $attrib['name'] = $attrib['id'];
184
185  $OUTPUT->set_env('contentframe', $attrib['name']);
186  $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
187
188  return html::iframe($attrib);
189  }
190
191
192function rcmail_rowcount_display($attrib)
193  {
194  global $OUTPUT;
195 
196  if (!$attrib['id'])
197    $attrib['id'] = 'rcmcountdisplay';
198
199  $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
200
201  return html::span($attrib, rcmail_get_rowcount_text());
202  }
203
204
205
206function rcmail_get_rowcount_text()
207  {
208  global $CONTACTS;
209 
210  // read nr of contacts
211  $result = $CONTACTS->get_result();
212  if (!$result)
213    $result = $CONTACTS->count();
214 
215  if ($result->count == 0)
216    $out = rcube_label('nocontactsfound');
217  else
218    $out = rcube_label(array(
219      'name' => 'contactsfromto',
220      'vars' => array(
221        'from'  => $result->first + 1,
222        'to'    => min($result->count, $result->first + $CONTACTS->page_size),
223        'count' => $result->count)
224      ));
225
226  return $out;
227  }
228 
229// register UI objects
230$OUTPUT->add_handlers(array(
231  'directorylist' => 'rcmail_directory_list',
232//  'groupslist' => 'rcmail_contact_groups',
233  'addresslist' => 'rcmail_contacts_list',
234  'addressframe' => 'rcmail_contact_frame',
235  'recordscountdisplay' => 'rcmail_rowcount_display',
236  'searchform' => array($OUTPUT, 'search_form')
237));
238
239?>
Note: See TracBrowser for help on using the repository browser.