alecpl
2008-07-01 e6e5c60aae745a580a2d7fca1e2b7104c3907352
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/addressbook/func.inc                                    |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
f11541 8  | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland                 |
30233b 9  | Licensed under the GNU GPL                                            |
4e17e6 10  |                                                                       |
T 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
f11541 22 // instantiate a contacts object according to the given source
T 23 if (($source = get_input_value('_source', RCUBE_INPUT_GPC)) && isset($CONFIG['ldap_public'][$source]))
24   $CONTACTS = new rcube_ldap($CONFIG['ldap_public'][$source]);
ed5ed9 25 else if (strtolower($CONFIG['address_book_type']) == 'ldap') {
4f9c83 26     // Get the first LDAP address book.
S 27     $source = key((array)$CONFIG['ldap_public']);
28     $prop = current((array)$CONFIG['ldap_public']);
29     $CONTACTS = new rcube_ldap($prop);
6153e2 30 } else {
4f9c83 31     $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
S 32 } // end else
f11541 33
T 34 $CONTACTS->set_pagesize($CONFIG['pagesize']);
4e17e6 35
T 36 // set list properties and session vars
f11541 37 if (!empty($_GET['_page']))
c57996 38   $CONTACTS->set_page(($_SESSION['page'] = intval($_GET['_page'])));
4e17e6 39 else
f11541 40   $CONTACTS->set_page(isset($_SESSION['page']) ?$_SESSION['page'] : 1);
4e17e6 41
f11541 42 // set message set for search result
T 43 if (!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
597c09 50 // add list of address sources to client env
4f9c83 51 $js_list = array();
ed5ed9 52 if (strtolower($CONFIG['address_book_type']) != 'ldap') {
4f9c83 53   // We are using the DB address book, add it.
S 54   $js_list = array("0" => array('id' => 0, 'readonly' => false));
55 } // end if
3dc20a 56 else if (!empty($CONFIG['ldap_public'])) {
A 57   foreach ($CONFIG['ldap_public'] as $id => $prop)
58     $js_list[$id] = array('id' => $id, 'readonly' => !$prop['writable']);
59 }
597c09 60 $OUTPUT->set_env('address_sources', $js_list);
T 61
f11541 62
T 63 function rcmail_directory_list($attrib)
64 {
65   global $CONFIG, $OUTPUT;
c0da98 66   
f11541 67   if (!$attrib['id'])
T 68     $attrib['id'] = 'rcmdirectorylist';
69
70   $local_id = '0';
71   $current = get_input_value('_source', RCUBE_INPUT_GPC);
72   $line_templ = '<li id="%s" class="%s"><a href="%s"' .
73     ' onclick="return %s.command(\'list\',\'%s\',this)"' .
74     ' onmouseover="return %s.focus_folder(\'%s\')"' .
75     ' onmouseout="return %s.unfocus_folder(\'%s\')"' .
76     ' onmouseup="return %s.folder_mouse_up(\'%s\')">%s'.
77     "</a></li>\n";
78     
79   // allow the following attributes to be added to the <ul> tag
80   $out = '<ul' . create_attrib_string($attrib, array('style', 'class', 'id')) . ">\n";
ed5ed9 81   if (strtolower($CONFIG['address_book_type']) != 'ldap') {
4f9c83 82     $out .= sprintf($line_templ,
S 83       'rcmli'.$local_id,
84       !$current ? 'selected' : '',
85       Q(rcmail_url('list', array('_source' => 0))),
86       JS_OBJECT_NAME,
87       $local_id,
88       JS_OBJECT_NAME,
89       $local_id,
90       JS_OBJECT_NAME,
91       $local_id,
92       JS_OBJECT_NAME,
93       $local_id,
94       rcube_label('personaladrbook'));
95   } // end if
96   else {
97     // DB address book not used, see if a source is set, if not use the
98     // first LDAP directory.
99     if (!$current) {
100       $current = key((array)$CONFIG['ldap_public']);
101     } // end if
102   } // end else
f11541 103   
T 104   foreach ((array)$CONFIG['ldap_public'] as $id => $prop)
105   {
106     $js_id = JQ($id);
107     $dom_id = preg_replace('/[^a-z0-9\-_]/i', '', $id);
108     $out .= sprintf($line_templ,
109       'rcmli'.$dom_id,
110       $current == $id ? 'selected' : '',
41bece 111       Q(rcmail_url('list', array('_source' => $id))),
f11541 112       JS_OBJECT_NAME,
T 113       $js_id,
114       JS_OBJECT_NAME,
115       $js_id,
116       JS_OBJECT_NAME,
117       $js_id,
118       JS_OBJECT_NAME,
119       $js_id,
120       !empty($prop['name']) ? Q($prop['name']) : Q($id));
121   }
122   
123   $out .= '</ul>';
124
125   $OUTPUT->add_gui_object('folderlist', $attrib['id']);
126   
127   return $out;
128 }
129
4e17e6 130
T 131 // return the message list as HTML table
132 function rcmail_contacts_list($attrib)
133   {
f11541 134   global $CONTACTS, $OUTPUT;
4e17e6 135   
T 136   // count contacts for this user
f11541 137   $result = $CONTACTS->list_records();
T 138   
4e17e6 139   // add id to message list table if not specified
T 140   if (!strlen($attrib['id']))
141     $attrib['id'] = 'rcmAddressList';
142   
f11541 143   // define list of cols to be displayed
T 144   $a_show_cols = array('name');
4e17e6 145
f11541 146   // create XHTML table
T 147   $out = rcube_table_output($attrib, $result->records, $a_show_cols, $CONTACTS->primary_key);
148   
149   // set client env
150   $OUTPUT->add_gui_object('contactslist', $attrib['id']);
151   $OUTPUT->set_env('current_page', (int)$CONTACTS->list_page);
152   $OUTPUT->set_env('pagecount', ceil($result->count/$CONTACTS->page_size));
153   $OUTPUT->include_script('list.js');
154   
5e3512 155   // add some labels to client
T 156   rcube_add_label('deletecontactconfirm');
f11541 157   
4e17e6 158   return $out;
T 159   }
160
161
f11541 162 function rcmail_js_contacts_list($result, $prefix='')
4e17e6 163   {
f11541 164   global $OUTPUT;
4e17e6 165
f11541 166   if (empty($result) || $result->count == 0)
T 167     return;
4e17e6 168
T 169   // define list of cols to be displayed
f11541 170   $a_show_cols = array('name');
T 171   
172   while ($row = $result->next())
4e17e6 173     {
T 174     $a_row_cols = array();
f11541 175     
4e17e6 176     // format each col
T 177     foreach ($a_show_cols as $col)
47124c 178       $a_row_cols[$col] = Q($row[$col]);
4e17e6 179     
f11541 180     $OUTPUT->command($prefix.'add_contact_row', $row['ID'], $a_row_cols);
T 181     }
4e17e6 182   }
T 183
184
185 // similar function as /steps/settings/identities.inc::rcmail_identity_frame()
186 function rcmail_contact_frame($attrib)
187   {
f11541 188   global $OUTPUT;
4e17e6 189
T 190   if (!$attrib['id'])
191     $attrib['id'] = 'rcmcontactframe';
192     
193   $attrib['name'] = $attrib['id'];
194   $attrib_str = create_attrib_string($attrib, array('name', 'id', 'class', 'style', 'src', 'width', 'height', 'frameborder'));
f11541 195
T 196   $OUTPUT->set_env('contentframe', $attrib['name']);
197   $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
198   return '<iframe'. $attrib_str . '></iframe>';
4e17e6 199   }
T 200
201
202 function rcmail_rowcount_display($attrib)
203   {
f11541 204   global $OUTPUT;
4e17e6 205   
T 206   if (!$attrib['id'])
207     $attrib['id'] = 'rcmcountdisplay';
208
f11541 209   $OUTPUT->add_gui_object('countdisplay', $attrib['id']);
4e17e6 210
T 211   // allow the following attributes to be added to the <span> tag
212   $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
213
214   $out = '<span' . $attrib_str . '>';
215   $out .= rcmail_get_rowcount_text();
216   $out .= '</span>';
217   return $out;
218   }
219
220
221
f11541 222 function rcmail_get_rowcount_text()
4e17e6 223   {
f11541 224   global $CONTACTS;
4e17e6 225   
f11541 226   // read nr of contacts
T 227   $result = $CONTACTS->get_result();
228   if (!$result)
229     $result = $CONTACTS->count();
230   
231   if ($result->count == 0)
4e17e6 232     $out = rcube_label('nocontactsfound');
T 233   else
f11541 234     $out = rcube_label(array(
T 235       'name' => 'contactsfromto',
236       'vars' => array(
237         'from'  => $result->first + 1,
238         'to'    => min($result->count, $result->first + $CONTACTS->page_size),
239         'count' => $result->count)
240       ));
4e17e6 241
T 242   return $out;
243   }
a55606 244
A 245 $OUTPUT->set_pagetitle(rcube_label('addressbook'));
f11541 246   
T 247 // register UI objects
248 $OUTPUT->add_handlers(array(
249   'directorylist' => 'rcmail_directory_list',
250   'addresslist' => 'rcmail_contacts_list',
251   'addressframe' => 'rcmail_contact_frame',
252   'recordscountdisplay' => 'rcmail_rowcount_display',
47124c 253   'searchform' => array($OUTPUT, 'search_form')
f11541 254 ));
4e17e6 255
d1d2c4 256 ?>