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