source: subversion/branches/devel-addressbook/program/steps/addressbook/func.inc @ 499

Last change on this file since 499 was 499, checked in by thomasb, 6 years ago

devel-addressbook: interface to public ldap directories with drag & drop copying

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 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
22require_once('include/rcube_contacts.inc');
23require_once('include/rcube_ldap.inc');
24
25// instantiate a contacts object according to the given source
26if (($source = get_input_value('_source', RCUBE_INPUT_GPC)) && isset($CONFIG['ldap_public'][$source]))
27  $CONTACTS = new rcube_ldap($CONFIG['ldap_public'][$source]);
28else
29  $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
30
31$CONTACTS->set_pagesize($CONFIG['pagesize']);
32
33// set list properties and session vars
34if (!empty($_GET['_page']))
35  {
36  $CONTACTS->set_page(intval($_GET['_page']));
37  $_SESSION['page'] = $_GET['_page'];
38  }
39else
40  $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1);
41
42// set message set for search result
43if (!empty($_GET['_search']) && isset($_SESSION['search'][$_GET['_search']]))
44  $CONTACTS->set_search_set($_SESSION['search'][$_GET['_search']]);
45
46// set data source env
47$OUTPUT->set_env('source', $source ? $source : '0');
48$OUTPUT->set_env('readonly', $CONTACTS->readonly, false);
49
50
51function rcmail_directory_list($attrib)
52{
53  global $CONFIG, $OUTPUT;
54 
55  if (!$attrib['id'])
56    $attrib['id'] = 'rcmdirectorylist';
57
58  $local_id = '0';
59  $current = get_input_value('_source', RCUBE_INPUT_GPC);
60  $line_templ = '<li id="%s" class="%s"><a href="%s"' .
61    ' onclick="return %s.command(\'list\',\'%s\',this)"' .
62    ' onmouseover="return %s.focus_folder(\'%s\')"' .
63    ' onmouseout="return %s.unfocus_folder(\'%s\')"' .
64    ' onmouseup="return %s.folder_mouse_up(\'%s\')">%s'.
65    "</a></li>\n";
66   
67  $js_list = array("$local_id" => array('id' => $local_id, 'readonly' => false));
68
69  // allow the following attributes to be added to the <ul> tag
70  $out = '<ul' . create_attrib_string($attrib, array('style', 'class', 'id')) . ">\n";
71  $out .= sprintf($line_templ,
72    'rcmli'.$local_id,
73    !$current ? 'selected' : '',
74    Q(rcmail_self_url('list', array('_source' => 0))),
75    JS_OBJECT_NAME,
76    $local_id,
77    JS_OBJECT_NAME,
78    $local_id,
79    JS_OBJECT_NAME,
80    $local_id,
81    JS_OBJECT_NAME,
82    $local_id,
83    rcube_label('personaladrbook'));
84 
85  foreach ((array)$CONFIG['ldap_public'] as $id => $prop)
86  {
87    $js_id = JQ($id);
88    $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id);
89    $out .= sprintf($line_templ,
90      'rcmli'.$dom_id,
91      $current == $id ? 'selected' : '',
92      Q(rcmail_self_url('list', array('_source' => $id))),
93      JS_OBJECT_NAME,
94      $js_id,
95      JS_OBJECT_NAME,
96      $js_id,
97      JS_OBJECT_NAME,
98      $js_id,
99      JS_OBJECT_NAME,
100      $js_id,
101      !empty($prop['name']) ? Q($prop['name']) : Q($id));
102     
103    $js_list[$dom_id] = array('id' => $id, 'readonly' => !$prop['writeable']);
104  }
105 
106  $out .= '</ul>';
107
108  $OUTPUT->add_gui_object('folderlist', $attrib['id']);
109  $OUTPUT->set_env('address_sources', $js_list);
110 
111  return $out;
112}
113
114
115// return the message list as HTML table
116function rcmail_contacts_list($attrib)
117  {
118  global $CONTACTS, $OUTPUT;
119 
120  // count contacts for this user
121  $result = $CONTACTS->list_records();
122 
123  // add id to message list table if not specified
124  if (!strlen($attrib['id']))
125    $attrib['id'] = 'rcmAddressList';
126 
127  // define list of cols to be displayed
128  $a_show_cols = array('name');
129
130  // create XHTML table
131  $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key);
132 
133  // set client env
134  $OUTPUT->add_gui_object('contactslist', $attrib['id']);
135  $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page);
136  $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size));
137  $OUTPUT->include_script('list.js');
138 
139  // add some labels to client
140  rcube_add_label('deletecontactconfirm');
141 
142  return $out;
143  }
144
145
146function rcmail_js_contacts_list($result, $prefix='')
147  {
148  global $OUTPUT;
149
150  if (empty($result) || $result->count == 0)
151    return;
152
153  // define list of cols to be displayed
154  $a_show_cols = array('name');
155 
156  while ($row = $result->next())
157    {
158    $a_row_cols = array();
159   
160    // format each col
161    foreach ($a_show_cols as $col)
162      $a_row_cols[$col] = $row[$col];
163   
164    $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
165    }
166  }
167
168
169// similar function as /steps/settings/identities.inc::rcmail_identity_frame()
170function rcmail_contact_frame($attrib)
171  {
172  global $OUTPUT;
173
174  if (!$attrib['id'])
175    $attrib['id'] = 'rcmcontactframe';
176   
177  $attrib['name'] = $attrib['id'];
178  $attrib_str = create_attrib_string($attrib, array('name', 'id', 'class', 'style', 'src', 'width', 'height', 'frameborder'));
179
180  $OUTPUT->set_env('contentframe', $attrib['name']);
181  $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
182  return '<iframe'. $attrib_str . '></iframe>';
183  }
184
185
186function rcmail_rowcount_display($attrib)
187  {
188  global $OUTPUT;
189 
190  if (!$attrib['id'])
191    $attrib['id'] = 'rcmcountdisplay';
192
193  $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
194
195  // allow the following attributes to be added to the <span> tag
196  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
197
198  $out = '<span' . $attrib_str . '>';
199  $out .= rcmail_get_rowcount_text();
200  $out .= '</span>';
201  return $out;
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 
230// register UI objects
231$OUTPUT->add_handlers(array(
232  'directorylist' => 'rcmail_directory_list',
233  'addresslist' => 'rcmail_contacts_list',
234  'addressframe' => 'rcmail_contact_frame',
235  'recordscountdisplay' => 'rcmail_rowcount_display',
236  'searchform' => 'rcmail_search_form'
237));
238
239?>
Note: See TracBrowser for help on using the repository browser.