]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/addressbook/func.inc
Imported Upstream version 0.1~beta2.2~dfsg
[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, 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 127 2006-01-25 22:56:53Z roundcube $
19
20 */
21
22 $CONTACTS_LIST = array();
23
24 // set list properties and session vars
25 if (strlen($_GET['_page']))
26   {
27   $CONTACTS_LIST['page'] = $_GET['_page'];
28   $_SESSION['page'] = $_GET['_page'];
29   }
30 else
31   $CONTACTS_LIST['page'] = $_SESSION['page'] ? $_SESSION['page'] : 1;
32
33 // disable the ldap public search button if there's no servers configured
34 $enable_ldap = 'true';
35 if (!$CONFIG['ldap_public'])
36   $enable_ldap = 'false';
37   
38 $OUTPUT->add_script("$JS_OBJECT_NAME.set_env('ldappublicsearch', $enable_ldap);");  
39
40 // return the message list as HTML table
41 function rcmail_contacts_list($attrib)
42   {
43   global $DB, $CONFIG, $OUTPUT, $CONTACTS_LIST, $JS_OBJECT_NAME;
44   
45   //$skin_path = $CONFIG['skin_path'];
46   //$image_tag = '<img src="%s%s" alt="%s" border="0" />';
47   
48   // count contacts for this user
49   $sql_result = $DB->query("SELECT COUNT(contact_id) AS rows
50                             FROM ".get_table_name('contacts')."
51                             WHERE  del<>1
52                             AND    user_id=?",
53                             $_SESSION['user_id']);
54
55   $sql_arr = $DB->fetch_assoc($sql_result);
56   $rowcount = $sql_arr['rows'];
57
58   if ($rowcount)
59     {
60     $start_row = ($CONTACTS_LIST['page']-1) * $CONFIG['pagesize'];
61
62     // get contacts from DB
63     $sql_result = $DB->limitquery("SELECT * FROM ".get_table_name('contacts')."
64                                    WHERE  del<>1
65                                    AND    user_id= ?
66                                    ORDER BY name",
67                                    $start_row,
68                                    $CONFIG['pagesize'],
69                                    $_SESSION['user_id']);
70     }
71   else
72     $sql_result = NULL;
73
74
75   // add id to message list table if not specified
76   if (!strlen($attrib['id']))
77     $attrib['id'] = 'rcmAddressList';
78
79   // define list of cols to be displayed
80   $a_show_cols = array('name', 'email');
81
82   // create XHTML table  
83   $out = rcube_table_output($attrib, $sql_result, $a_show_cols, 'contact_id');
84
85   // set client env
86   $javascript = sprintf("%s.gui_object('contactslist', '%s');\n", $JS_OBJECT_NAME, $attrib['id']);
87   $javascript .= sprintf("%s.set_env('current_page', %d);\n", $JS_OBJECT_NAME, $CONTACTS_LIST['page']);
88   $javascript .= sprintf("%s.set_env('pagecount', %d);\n", $JS_OBJECT_NAME, ceil($rowcount/$CONFIG['pagesize']));
89   $javascript .= "rcmail.set_env('newcontact', '" . rcube_label('newcontact') . "');";
90   //$javascript .= sprintf("%s.set_env('contacts', %s);", $JS_OBJECT_NAME, array2js($a_js_message_arr));
91   
92   $OUTPUT->add_script($javascript);  
93
94   // add some labels to client
95   rcube_add_label('deletecontactconfirm');
96
97   return $out;
98   }
99
100
101
102 function rcmail_js_contacts_list($sql_result, $obj_name='this')
103   {
104   global $DB;
105
106   $commands = '';
107   
108   if (!$sql_result)
109     return '';
110
111   // define list of cols to be displayed
112   $a_show_cols = array('name', 'email');
113     
114   while ($sql_arr = $DB->fetch_assoc($sql_result))
115     {
116     $a_row_cols = array();
117             
118     // format each col
119     foreach ($a_show_cols as $col)
120       {
121       $cont = rep_specialchars_output($sql_arr[$col]);
122       $a_row_cols[$col] = $cont;
123       }
124   
125     $commands .= sprintf("%s.add_contact_row(%s, %s);\n",
126                          $obj_name,
127                          $sql_arr['contact_id'],
128                          array2js($a_row_cols));
129     }
130     
131   return $commands;
132   }
133
134
135 // similar function as /steps/settings/identities.inc::rcmail_identity_frame()
136 function rcmail_contact_frame($attrib)
137   {
138   global $OUTPUT, $JS_OBJECT_NAME;
139
140   if (!$attrib['id'])
141     $attrib['id'] = 'rcmcontactframe';
142     
143   $attrib['name'] = $attrib['id'];
144
145   $OUTPUT->add_script(sprintf("%s.set_env('contentframe', '%s');", $JS_OBJECT_NAME, $attrib['name']));
146
147   $attrib_str = create_attrib_string($attrib, array('name', 'id', 'class', 'style', 'src', 'width', 'height', 'frameborder'));
148   $out = '<iframe'. $attrib_str . '></iframe>';
149     
150   return $out;
151   }
152
153
154 function rcmail_rowcount_display($attrib)
155   {
156   global $OUTPUT, $JS_OBJECT_NAME;
157   
158   if (!$attrib['id'])
159     $attrib['id'] = 'rcmcountdisplay';
160
161   $OUTPUT->add_script(sprintf("%s.gui_object('countdisplay', '%s');", $JS_OBJECT_NAME, $attrib['id']));
162
163   // allow the following attributes to be added to the <span> tag
164   $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
165
166   
167   $out = '<span' . $attrib_str . '>';
168   $out .= rcmail_get_rowcount_text();
169   $out .= '</span>';
170   return $out;
171   }
172
173
174
175 function rcmail_get_rowcount_text($max=NULL)
176   {
177   global $CONTACTS_LIST, $CONFIG, $DB;
178   
179   $start_row = ($CONTACTS_LIST['page']-1) * $CONFIG['pagesize'] + 1;
180
181   // get nr of contacts
182   if ($max===NULL)
183     {
184     $sql_result = $DB->query("SELECT 1 FROM ".get_table_name('contacts')."
185                               WHERE  del<>1
186                               AND    user_id=?",
187                               $_SESSION['user_id']);
188
189     $max = $DB->num_rows($sql_result);
190     }
191
192   if ($max==0)
193     $out = rcube_label('nocontactsfound');
194   else
195     $out = rcube_label(array('name' => 'contactsfromto',
196                              'vars' => array('from'  => $start_row,
197                                              'to'    => min($max, $start_row + $CONFIG['pagesize'] - 1),
198                                              'count' => $max)));
199
200   return $out;
201   }
202
203 ?>