1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * eGroupWare - email/addressbook * |
---|
4 | * http://www.eGroupWare.org * |
---|
5 | * Originaly written by Bettina Gille [ceb@phpgroupware.org] * |
---|
6 | * ----------------------------------------------- * |
---|
7 | * This program is free software; you can redistribute it and/or modify it * |
---|
8 | * under the terms of the GNU General Public License as published by the * |
---|
9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
10 | * option) any later version. * |
---|
11 | \**************************************************************************/ |
---|
12 | |
---|
13 | |
---|
14 | $GLOBALS['phpgw_info']['flags'] = array( |
---|
15 | 'noheader' => True, |
---|
16 | 'nonavbar' => True, |
---|
17 | 'currentapp' => 'addressbook', |
---|
18 | 'enable_nextmatchs_class' => True |
---|
19 | ); |
---|
20 | |
---|
21 | include('../header.inc.php'); |
---|
22 | |
---|
23 | // add a content-type header to overwrite an existing default charset in apache (AddDefaultCharset directiv) |
---|
24 | header('Content-type: text/html; charset='.$GLOBALS['phpgw']->translation->charset()); |
---|
25 | |
---|
26 | include('templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'].'/head.inc.php'); |
---|
27 | |
---|
28 | $GLOBALS['phpgw']->template->set_root(PHPGW_TEMPLATE_DIR); |
---|
29 | $GLOBALS['phpgw']->template->set_file(array( |
---|
30 | 'addressbook_list_t' => 'addressbook.tpl', |
---|
31 | )); |
---|
32 | $GLOBALS['phpgw']->template->set_block('addressbook_list_t','addressbook_list','list'); |
---|
33 | |
---|
34 | $contacts = CreateObject('phpgwapi.contacts'); |
---|
35 | $cats = CreateObject('phpgwapi.categories'); |
---|
36 | $cats->app_name = 'addressbook'; |
---|
37 | |
---|
38 | $include_personal = True; |
---|
39 | |
---|
40 | $GLOBALS['phpgw']->template->set_var(array( |
---|
41 | 'lang_search' => lang('Search'), |
---|
42 | 'lang_select_cats' => lang('Show all categorys'), |
---|
43 | 'lang_done' => lang('Done'), |
---|
44 | 'to' => lang('To'), |
---|
45 | 'cc' => lang('Cc'), |
---|
46 | 'bcc' => lang('Bcc'), |
---|
47 | 'lang_email' => lang('Select work email address'), |
---|
48 | 'lang_hemail' => lang('Select home email address'), |
---|
49 | 'lang_to_title' => lang('Select all %1 %2 for %3') |
---|
50 | )); |
---|
51 | |
---|
52 | $start = (int)get_var('start',array('POST','GET'),0); |
---|
53 | $filter = get_var('filter',array('POST','GET'),'none'); |
---|
54 | $cat_id = (int)get_var('cat_id',array('POST','GET'),0); |
---|
55 | $query = get_var('query',array('POST','GET')); |
---|
56 | $sort = get_var('sort',array('POST','GET')); |
---|
57 | $order = get_var('order',array('POST','GET')); |
---|
58 | list($all) = @each($_POST['all']); |
---|
59 | $inserted = $_GET['inserted']; |
---|
60 | |
---|
61 | $common_vars = array( |
---|
62 | 'filter' => $filter, |
---|
63 | 'cat_id' => $cat_id, |
---|
64 | 'query' => $query, |
---|
65 | 'sort' => $sort, |
---|
66 | 'order' => $order, |
---|
67 | ); |
---|
68 | |
---|
69 | $link = '/phpgwapi/addressbook.php'; |
---|
70 | $full_link = $GLOBALS['phpgw']->link($link,$common_vars+array( |
---|
71 | 'start' => $start, |
---|
72 | )); |
---|
73 | $GLOBALS['phpgw']->template->set_var('form_action',$full_link); |
---|
74 | |
---|
75 | $qfilter = 'tid=n'; |
---|
76 | switch($filter) |
---|
77 | { |
---|
78 | case 'none': |
---|
79 | break; |
---|
80 | case 'private': |
---|
81 | $qfilter .=',access=private'; |
---|
82 | // fall-through |
---|
83 | case 'yours': |
---|
84 | $qfilter .= ',owner='.$GLOBALS['phpgw_info']['user']['account_id']; |
---|
85 | break; |
---|
86 | default: |
---|
87 | if(is_numeric($filter)) |
---|
88 | { |
---|
89 | $qfilter = ',owner='.$filter; |
---|
90 | } |
---|
91 | break; |
---|
92 | } |
---|
93 | |
---|
94 | if ($cat_id) |
---|
95 | { |
---|
96 | $qfilter .= ',cat_id='.$cat_id; |
---|
97 | } |
---|
98 | |
---|
99 | if ($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0) |
---|
100 | { |
---|
101 | $offset = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']; |
---|
102 | } |
---|
103 | else |
---|
104 | { |
---|
105 | $offset = 15; |
---|
106 | } |
---|
107 | |
---|
108 | $account_id = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
109 | |
---|
110 | $cols = array ( |
---|
111 | 'n_given' => 'n_given', |
---|
112 | 'n_family' => 'n_family', |
---|
113 | 'org_name' => 'org_name', |
---|
114 | 'email' => 'email', |
---|
115 | 'email_home' => 'email_home' |
---|
116 | ); |
---|
117 | |
---|
118 | if ($all) |
---|
119 | { |
---|
120 | $qfilter .= ',email'.($all[0] == 'h' ? '_home' : '')."=!''"; |
---|
121 | $entries = $contacts->read(0,0,$cols,$query,$qfilter,$sort,$order,$account_id); |
---|
122 | //echo "<pre>".print_r($entries,True)."</pre>\n"; |
---|
123 | if (!$entries) |
---|
124 | { |
---|
125 | $all = False; |
---|
126 | $inserted = 0; |
---|
127 | } |
---|
128 | } |
---|
129 | if (!$all) |
---|
130 | { |
---|
131 | $entries = $contacts->read($start,$offset,$cols,$query,$qfilter,$sort,$order,$account_id); |
---|
132 | } |
---|
133 | //------------------------------------------- nextmatch -------------------------------------------- |
---|
134 | $GLOBALS['phpgw']->template->set_var('left',$GLOBALS['phpgw']->nextmatchs->left( |
---|
135 | $link,$start,$contacts->total_records,'&'.explode('&',$common_vars))); |
---|
136 | $GLOBALS['phpgw']->template->set_var('right',$GLOBALS['phpgw']->nextmatchs->right( |
---|
137 | $link,$start,$contacts->total_records,'&'.explode('&',$common_vars))); |
---|
138 | foreach(array( |
---|
139 | 'n_given' => lang('Firstname'), |
---|
140 | 'n_family' => lang('Lastname'), |
---|
141 | 'org_name' => lang('Company'), |
---|
142 | ) as $col => $translation) |
---|
143 | { |
---|
144 | $GLOBALS['phpgw']->template->set_var('sort_'.$col,$GLOBALS['phpgw']->nextmatchs->show_sort_order( |
---|
145 | $sort,$col,$order,$link,$translation,'&cat_id='.$cat_id)); |
---|
146 | } |
---|
147 | |
---|
148 | if ($contacts->total_records > $offset) |
---|
149 | { |
---|
150 | $GLOBALS['phpgw']->template->set_var('lang_showing',lang('showing %1 - %2 of %3', |
---|
151 | 1+$start,$start+$offset>$contacts->total_records ? $contacts->total_records : $start+$offset, |
---|
152 | $contacts->total_records)); |
---|
153 | } |
---|
154 | |
---|
155 | else |
---|
156 | { |
---|
157 | $GLOBALS['phpgw']->template->set_var('lang_showing',lang('showing %1',$contacts->total_records)); |
---|
158 | } |
---|
159 | // --------------------------------------- end nextmatch ------------------------------------------ |
---|
160 | |
---|
161 | foreach(array( |
---|
162 | 'work' => lang('work email'), |
---|
163 | 'home' => lang('home email') |
---|
164 | ) as $type => $lang_type) |
---|
165 | { |
---|
166 | foreach(array( |
---|
167 | 'to' => lang('To'), |
---|
168 | 'cc' => lang('Cc'), |
---|
169 | 'bcc'=> lang('Bcc')) as $target => $lang_target) |
---|
170 | { |
---|
171 | $GLOBALS['phpgw']->template->set_var('title_'.$type.'_'.$target, |
---|
172 | lang('Insert all %1 addresses of the %2 contacts in %3',$lang_type, |
---|
173 | $contacts->total_records,$lang_target)); |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | // ------------------- list header variable template-declaration ----------------------- |
---|
178 | $GLOBALS['phpgw']->template->set_var('cats_list',$cats->formated_list('select','all',$cat_id,'True')); |
---|
179 | |
---|
180 | $filter_list = ''; |
---|
181 | foreach(array( |
---|
182 | 'none' => lang('Show all'), |
---|
183 | 'yours' => lang('Only yours'), |
---|
184 | 'private' => lang('Only private'), |
---|
185 | ) as $id => $translation) |
---|
186 | { |
---|
187 | $filter_list .= "<option value=\"$id\"".($filter == $id ? ' selected':'').">$translation</option>\n"; |
---|
188 | } |
---|
189 | $GLOBALS['phpgw']->template->set_var(array( |
---|
190 | 'query' => $query, |
---|
191 | 'filter_list' => $filter_list, |
---|
192 | )); |
---|
193 | // --------------------------- end header declaration ---------------------------------- |
---|
194 | |
---|
195 | $all_emails = array(); |
---|
196 | if ($entries) |
---|
197 | foreach ($entries as $entry) |
---|
198 | { |
---|
199 | $GLOBALS['phpgw']->template->set_var('tr_class', |
---|
200 | $GLOBALS['phpgw']->nextmatchs->alternate_row_color('',True)); |
---|
201 | |
---|
202 | $firstname = $entry['n_given']; |
---|
203 | if (!$firstname) |
---|
204 | { |
---|
205 | $firstname = ' '; |
---|
206 | } |
---|
207 | $lastname = $entry['n_family']; |
---|
208 | if (!$lastname) |
---|
209 | { |
---|
210 | $lastname = ' '; |
---|
211 | } |
---|
212 | // thanks to dave.hall@mbox.com.au for adding company |
---|
213 | $company = $entry['org_name']; |
---|
214 | if (!$company) |
---|
215 | { |
---|
216 | $company = ' '; |
---|
217 | } |
---|
218 | |
---|
219 | $personal_firstname = ''; |
---|
220 | $personal_lastname = ''; |
---|
221 | $personal_part = ''; |
---|
222 | if ((isset($firstname)) && |
---|
223 | ($firstname != '') && |
---|
224 | ($firstname != ' ')) |
---|
225 | { |
---|
226 | $personal_firstname = $firstname.' '; |
---|
227 | } |
---|
228 | if ((isset($lastname)) && |
---|
229 | ($lastname != '') && |
---|
230 | ($lastname != ' ')) |
---|
231 | { |
---|
232 | $personal_lastname = $lastname; |
---|
233 | } |
---|
234 | $personal_part = $personal_firstname.$personal_lastname; |
---|
235 | |
---|
236 | if (($personal_part == '') || |
---|
237 | ($include_personal == False)) |
---|
238 | { |
---|
239 | $id = $entry['id']; |
---|
240 | $email = $entry['email']; |
---|
241 | $hemail = $entry['email_home']; |
---|
242 | } |
---|
243 | else |
---|
244 | { |
---|
245 | $id = $entry['id']; |
---|
246 | if ((isset($entry['email'])) && |
---|
247 | (trim($entry['email']) != '')) |
---|
248 | { |
---|
249 | $email = '"'.$personal_part.'" <'.$entry['email'].'>'; |
---|
250 | } |
---|
251 | else |
---|
252 | { |
---|
253 | $email = $entry['email']; |
---|
254 | } |
---|
255 | if ((isset($entry['email_home'])) && |
---|
256 | (trim($entry['email_home']) != '')) |
---|
257 | { |
---|
258 | $hemail = '"'.$personal_part.'" <'.$entry['email_home'].'>'; |
---|
259 | } |
---|
260 | else |
---|
261 | { |
---|
262 | $hemail = $entry['email_home']; |
---|
263 | } |
---|
264 | } |
---|
265 | if ($all) |
---|
266 | { |
---|
267 | $all_emails[] = $all[0] == 'h' ? $hemail : $email; |
---|
268 | } |
---|
269 | else |
---|
270 | { |
---|
271 | $email = htmlspecialchars($email); |
---|
272 | $hemail = htmlspecialchars($hemail); |
---|
273 | |
---|
274 | // --------------------- template declaration for list records -------------------------- |
---|
275 | $GLOBALS['phpgw']->template->set_var(array( |
---|
276 | 'firstname' => $firstname, |
---|
277 | 'lastname' => $lastname, |
---|
278 | 'company' => $company |
---|
279 | )); |
---|
280 | |
---|
281 | $GLOBALS['phpgw']->template->set_var('id',$id); |
---|
282 | $GLOBALS['phpgw']->template->set_var('email',$email); |
---|
283 | $GLOBALS['phpgw']->template->set_var('hemail',$hemail); |
---|
284 | |
---|
285 | $GLOBALS['phpgw']->template->parse('list','addressbook_list',True); |
---|
286 | } |
---|
287 | } |
---|
288 | // --------------------------- end record declaration --------------------------- |
---|
289 | |
---|
290 | if ($all && count($all_emails)) |
---|
291 | { |
---|
292 | $full_link .= '&inserted='.count($all_emails); |
---|
293 | $target = substr($all,1); |
---|
294 | echo "<script type=\"text/javascript\"> |
---|
295 | if (opener.document.doit.$target.value != '') |
---|
296 | { |
---|
297 | opener.document.doit.$target.value += ','; |
---|
298 | } |
---|
299 | opener.document.doit.$target.value += '".str_replace("'","\\'",implode(',',$all_emails))."'; |
---|
300 | window.location.href = '$full_link'; |
---|
301 | </script> |
---|
302 | </body> |
---|
303 | </html>\n"; |
---|
304 | } |
---|
305 | else |
---|
306 | { |
---|
307 | if ($inserted || $inserted === 0) |
---|
308 | { |
---|
309 | $GLOBALS['phpgw']->template->set_var('message','<b>'. |
---|
310 | lang('%1 email addresses inserted',(int)$_GET['inserted']).'</b>'); |
---|
311 | } |
---|
312 | $GLOBALS['phpgw']->template->parse('out','addressbook_list_t',True); |
---|
313 | $GLOBALS['phpgw']->template->p('out'); |
---|
314 | } |
---|
315 | $GLOBALS['phpgw']->common->phpgw_exit(); |
---|
316 | ?> |
---|