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

Last change on this file since 623 was 623, checked in by till, 6 years ago

+ switch from global to rc_registry is complete
+ more logging/debugging
+ many CS changes
+ put different functions into their own file

# todo: fix JS inclusion (probably in template class)

File size: 7.0 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: func.inc 578 2007-05-18 13:06:01Z thomasb $
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($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
44  $CONTACTS->set_search_set($_SESSION['search'][$_REQUEST['_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// add list of address sources to client env
51$js_list = array("0" => array('id' => 0, 'readonly' => false));
52foreach ((array)$CONFIG['ldap_public'] as $id => $prop)
53  $js_list[$id] = array('id' => $id, 'readonly' => !$prop['writeable']);
54$OUTPUT->set_env('address_sources', $js_list);
55
56
57function rcmail_directory_list($attrib)
58{
59  global $CONFIG, $OUTPUT;
60 
61  if (!$attrib['id'])
62    $attrib['id'] = 'rcmdirectorylist';
63
64  $local_id = '0';
65  $current = get_input_value('_source', RCUBE_INPUT_GPC);
66  $line_templ = '<li id="%s" class="%s"><a href="%s"' .
67    ' onclick="return %s.command(\'list\',\'%s\',this)"' .
68    ' onmouseover="return %s.focus_folder(\'%s\')"' .
69    ' onmouseout="return %s.unfocus_folder(\'%s\')"' .
70    ' onmouseup="return %s.folder_mouse_up(\'%s\')">%s'.
71    "</a></li>\n";
72   
73  // allow the following attributes to be added to the <ul> tag
74  $out = '<ul' . rc_main::create_attrib_string($attrib, array('style', 'class', 'id')) . ">\n";
75  $out .= sprintf($line_templ,
76    'rcmli'.$local_id,
77    !$current ? 'selected' : '',
78    rc_main::Q(rc_main::rcmail_url('list', array('_source' => 0))),
79    JS_OBJECT_NAME,
80    $local_id,
81    JS_OBJECT_NAME,
82    $local_id,
83    JS_OBJECT_NAME,
84    $local_id,
85    JS_OBJECT_NAME,
86    $local_id,
87    rcube_label('personaladrbook'));
88 
89  foreach ((array)$CONFIG['ldap_public'] as $id => $prop)
90  {
91    $js_id = rc_main_::JQ($id);
92    $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id);
93    $out .= sprintf($line_templ,
94      'rcmli'.$dom_id,
95      $current == $id ? 'selected' : '',
96      rc_main::Q(rc_main::rcmail_url('list', array('_source' => $id))),
97      JS_OBJECT_NAME,
98      $js_id,
99      JS_OBJECT_NAME,
100      $js_id,
101      JS_OBJECT_NAME,
102      $js_id,
103      JS_OBJECT_NAME,
104      $js_id,
105      !empty($prop['name']) ? rc_main::Q($prop['name']) : rc_main::Q($id));
106  }
107 
108  $out .= '</ul>';
109
110  $OUTPUT->add_gui_object('folderlist', $attrib['id']);
111 
112  return $out;
113}
114
115
116// return the message list as HTML table
117function rcmail_contacts_list($attrib)
118  {
119  global $CONTACTS, $OUTPUT;
120 
121  // count contacts for this user
122  $result = $CONTACTS->list_records();
123 
124  // add id to message list table if not specified
125  if (!strlen($attrib['id']))
126    $attrib['id'] = 'rcmAddressList';
127 
128  // define list of cols to be displayed
129  $a_show_cols = array('name');
130
131  // create XHTML table
132  $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key);
133 
134  // set client env
135  $OUTPUT->add_gui_object('contactslist', $attrib['id']);
136  $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page);
137  $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size));
138  $OUTPUT->include_script('list.js');
139 
140  // add some labels to client
141  rcube_add_label('deletecontactconfirm');
142 
143  return $out;
144  }
145
146
147function rcmail_js_contacts_list($result, $prefix='')
148  {
149  global $OUTPUT;
150
151  if (empty($result) || $result->count == 0)
152    return;
153
154  // define list of cols to be displayed
155  $a_show_cols = array('name');
156 
157  while ($row = $result->next())
158    {
159    $a_row_cols = array();
160   
161    // format each col
162    foreach ($a_show_cols as $col)
163      $a_row_cols[$col] = $row[$col];
164   
165    $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
166    }
167  }
168
169
170// similar function as /steps/settings/identities.inc::rcmail_identity_frame()
171function rcmail_contact_frame($attrib)
172  {
173  global $OUTPUT;
174
175  if (!$attrib['id'])
176    $attrib['id'] = 'rcmcontactframe';
177   
178  $attrib['name'] = $attrib['id'];
179  $attrib_str = rc_main::create_attrib_string($attrib, array('name', 'id', 'class', 'style', 'src', 'width', 'height', 'frameborder'));
180
181  $OUTPUT->set_env('contentframe', $attrib['name']);
182  $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
183  return '<iframe'. $attrib_str . '></iframe>';
184  }
185
186
187function rcmail_rowcount_display($attrib)
188  {
189  global $OUTPUT;
190 
191  if (!$attrib['id'])
192    $attrib['id'] = 'rcmcountdisplay';
193
194  $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
195
196  // allow the following attributes to be added to the <span> tag
197  $attrib_str = rc_main::create_attrib_string($attrib, array('style', 'class', 'id'));
198
199  $out = '<span' . $attrib_str . '>';
200  $out .= rcmail_get_rowcount_text();
201  $out .= '</span>';
202  return $out;
203  }
204
205
206
207function rcmail_get_rowcount_text()
208  {
209  global $CONTACTS;
210 
211  // read nr of contacts
212  $result = $CONTACTS->get_result();
213  if (!$result)
214    $result = $CONTACTS->count();
215 
216  if ($result->count == 0)
217    $out = rcube_label('nocontactsfound');
218  else
219    $out = rcube_label(array(
220      'name' => 'contactsfromto',
221      'vars' => array(
222        'from'  => $result->first + 1,
223        'to'    => min($result->count, $result->first + $CONTACTS->page_size),
224        'count' => $result->count)
225      ));
226
227  return $out;
228  }
229 
230 
231// register UI objects
232$OUTPUT->add_handlers(array(
233  'directorylist' => 'rcmail_directory_list',
234  'addresslist' => 'rcmail_contacts_list',
235  'addressframe' => 'rcmail_contact_frame',
236  'recordscountdisplay' => 'rcmail_rowcount_display',
237  'searchform' => 'rcmail_search_form'
238));
239
240?>
Note: See TracBrowser for help on using the repository browser.