|
1
|
|
|
<?php |
|
2
|
|
|
/**************************************************************************\ |
|
3
|
|
|
* eGroupWare SiteMgr - Web Content Management * |
|
4
|
|
|
* http://www.egroupware.org * |
|
5
|
|
|
* -------------------------------------------- * |
|
6
|
|
|
* This program is free software; you can redistribute it and/or modify it * |
|
7
|
|
|
* under the terms of the GNU General Public License as published by the * |
|
8
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your * |
|
9
|
|
|
* option) any later version. * |
|
10
|
|
|
\**************************************************************************/ |
|
11
|
|
|
|
|
12
|
|
|
use EGroupware\Api; |
|
13
|
|
|
use EGroupware\Api\Framework; |
|
14
|
|
|
use EGroupware\Api\Acl; |
|
15
|
|
|
|
|
16
|
|
|
/* $Id$ */ |
|
17
|
|
|
|
|
18
|
|
|
class module_calendar_month extends Module |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Instance of the business object of calendar |
|
22
|
|
|
* |
|
23
|
|
|
* @var bo |
|
24
|
|
|
*/ |
|
25
|
|
|
var $bo; |
|
26
|
|
|
/** |
|
27
|
|
|
* Instance of the user interface object of calendar |
|
28
|
|
|
* |
|
29
|
|
|
* @var ui |
|
30
|
|
|
*/ |
|
31
|
|
|
var $ui; |
|
32
|
|
|
/** |
|
33
|
|
|
* Instance of the user interface object of calendar |
|
34
|
|
|
* |
|
35
|
|
|
* @var ui |
|
36
|
|
|
*/ |
|
37
|
|
|
var $uiviews; |
|
38
|
|
|
/** |
|
39
|
|
|
* Instance of the Api\Accounts object |
|
40
|
|
|
* |
|
41
|
|
|
* @var Api\Accounts |
|
42
|
|
|
*/ |
|
43
|
|
|
var $accounts; |
|
44
|
|
|
/** |
|
45
|
|
|
* Default CSS style |
|
46
|
|
|
* |
|
47
|
|
|
* @var default_css |
|
|
|
|
|
|
48
|
|
|
*/ |
|
49
|
|
|
var $default_css = '/calendar/templates/default/app.css'; |
|
50
|
|
|
|
|
51
|
|
|
function __construct() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->bo = new calendar_bo(); |
|
|
|
|
|
|
54
|
|
|
$this->arguments = array( |
|
|
|
|
|
|
55
|
|
|
'category' => array( |
|
56
|
|
|
'type' => 'select', |
|
57
|
|
|
'label' => lang('Choose a category'), |
|
58
|
|
|
'options' => array(), // specification of options is postponed into the get_user_interface function |
|
59
|
|
|
'multiple' => true, |
|
60
|
|
|
), |
|
61
|
|
|
'numWeeks' => array( |
|
62
|
|
|
'type' => 'textfield', |
|
63
|
|
|
'label' => lang('Number of weeks to show'), |
|
64
|
|
|
'default' => 2, |
|
65
|
|
|
'params' => array('size' => 1) |
|
66
|
|
|
), |
|
67
|
|
|
'showWeeks' => array( |
|
68
|
|
|
'type' => 'checkbox', |
|
69
|
|
|
'label' => lang('Should the number of weeks be shown on top of the calendar'), |
|
70
|
|
|
'default' => false, |
|
71
|
|
|
), |
|
72
|
|
|
'showTitle' => array( |
|
73
|
|
|
'type' => 'checkbox', |
|
74
|
|
|
'label' => lang('Show a calendar title'), |
|
75
|
|
|
'default' => false, |
|
76
|
|
|
), |
|
77
|
|
|
'search' => array( |
|
78
|
|
|
'type' => 'textfield', |
|
79
|
|
|
'label' => lang('Search string for the events'), |
|
80
|
|
|
), |
|
81
|
|
|
'users' => array( |
|
82
|
|
|
'type' => 'select', |
|
83
|
|
|
'options' => array(), |
|
84
|
|
|
'label' => lang('Group(s) or user(s) whose calendars to show (if ACL exists)'), |
|
85
|
|
|
// 'multiple' => true, is set in the get_user_interface function. |
|
86
|
|
|
), |
|
87
|
|
|
'grid' => array( |
|
88
|
|
|
'type' => 'checkbox', |
|
89
|
|
|
'label' => lang('Should the grid be shown in the calendar'), |
|
90
|
|
|
'default' => false, |
|
91
|
|
|
), |
|
92
|
|
|
'css' => array( |
|
93
|
|
|
'type' => 'textfield', |
|
94
|
|
|
'label' => lang('User selectable CSS file for the calendar setup'), |
|
95
|
|
|
'default' => $this->default_css, |
|
96
|
|
|
), |
|
97
|
|
|
'acceptDateParam' => array( |
|
98
|
|
|
'type' => 'checkbox', |
|
99
|
|
|
'label' => lang('Shall the date parameter be accepted (e.g. from calendar module)?'), |
|
100
|
|
|
'default' => false, |
|
101
|
|
|
), |
|
102
|
|
|
); |
|
103
|
|
|
$this->title = lang('Calendar - Multi-Weekly'); |
|
|
|
|
|
|
104
|
|
|
$this->description = lang("This module displays a user's calendar as multiple weeks. Don't give calendar application access to the anon user!"); |
|
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
function get_user_interface() |
|
108
|
|
|
{ |
|
109
|
|
|
// copied from bookmarks module. |
|
110
|
|
|
$cat = createobject('phpgwapi.categories','','calendar'); |
|
|
|
|
|
|
111
|
|
|
$cats = $cat->return_array('all',0,False,'','cat_name','',True); |
|
112
|
|
|
$cat_ids = array(); |
|
113
|
|
|
foreach($cats as $category) |
|
114
|
|
|
{ |
|
115
|
|
|
$cat_ids[$category['id']] = $GLOBALS['egw']->strip_html($category['name']); |
|
116
|
|
|
} |
|
117
|
|
|
$this->arguments['category']['options'] = $cat_ids; |
|
|
|
|
|
|
118
|
|
|
if (count($cat_ids) > 5) { |
|
119
|
|
|
$this->arguments['category']['multiple'] = 5; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
if (! isset($GLOBALS['egw']->accounts)) |
|
123
|
|
|
{ |
|
124
|
|
|
$GLOBALS['egw']->accounts = new Api\Accounts(); |
|
125
|
|
|
} |
|
126
|
|
|
$this->accounts =& $GLOBALS['egw']->accounts; |
|
127
|
|
|
$search_params=array( |
|
128
|
|
|
'type' => 'both', |
|
129
|
|
|
'app' => 'calendar', |
|
130
|
|
|
); |
|
131
|
|
|
$accounts = $this->accounts->search($search_params); |
|
132
|
|
|
$users = array(); |
|
133
|
|
|
$groups = array(); |
|
134
|
|
|
// sort users and groups separately. |
|
135
|
|
|
if (isset($GLOBALS['sitemgr_info']['anonymous_user'])) |
|
136
|
|
|
{ |
|
137
|
|
|
$anon_user = $this->accounts->name2id($GLOBALS['sitemgr_info']['anonymous_user'],'account_lid','u'); |
|
138
|
|
|
} |
|
139
|
|
|
else |
|
140
|
|
|
{ |
|
141
|
|
|
// sitemgr is not in global variables. Get it. |
|
142
|
|
|
/* |
|
143
|
|
|
* Get possible sitemgr paths from the HTTP_REFERRER in order to unreveal the |
|
144
|
|
|
* anonymous user for the correct site. |
|
145
|
|
|
*/ |
|
146
|
|
|
$sitemgr_path = preg_replace('/^[^\/]+:\/\/[^\/]+\/([^\?]*)(\?.*)*$/',"/\${1}",$_SERVER['HTTP_REFERER']); |
|
147
|
|
|
// Remove the trailing file- / pathname if any |
|
148
|
|
|
$sitemgr_path = preg_replace('/[^\/]*$/', '', $sitemgr_path); |
|
149
|
|
|
// Add leading slash if it has been lost. |
|
150
|
|
|
if (strncmp('/', $sitemgr_path, 1) != 0) |
|
151
|
|
|
{ |
|
152
|
|
|
$sitemgr_path = '/'.$sitemgr_path; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
// Code adapted from sitemgr-site/index.php |
|
156
|
|
|
$site_urls = array(); |
|
157
|
|
|
$site_urls[] = $sitemgr_path; |
|
158
|
|
|
$site_urls[] = ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['SERVER_ADDR'] . $sitemgr_path; |
|
159
|
|
|
$site_urls[] = $site_url = ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . $sitemgr_path; |
|
|
|
|
|
|
160
|
|
|
|
|
161
|
|
|
$anon_user = $this->accounts->name2id($GLOBALS['egw']->db->select('egw_sitemgr_sites','anonymous_user,anonymous_passwd,site_id', |
|
162
|
|
|
array('site_url' => $site_urls),__LINE__,__FILE__,false,'','sitemgr')->fetchColumn(),'account_lid','u'); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
$anon_groups = $this->accounts->memberships($anon_user,true); |
|
166
|
|
|
foreach ($accounts as $entry) |
|
167
|
|
|
{ |
|
168
|
|
|
$is_group = false; |
|
169
|
|
|
$has_read_permissions = false; |
|
170
|
|
|
$acl = new Acl($entry['account_id']); |
|
171
|
|
|
$acl->read_repository(); |
|
172
|
|
|
// get the rights for each account to check whether the anon user has read permissions. |
|
173
|
|
|
$rights = $acl->get_rights($anon_user,'calendar'); |
|
174
|
|
|
// also add the anon user if it's his own calendar. |
|
175
|
|
|
if (($rights & Acl::READ) || ($entry['account_id'] == $anon_user)) |
|
176
|
|
|
{ |
|
177
|
|
|
$has_read_permissions = true; |
|
178
|
|
|
} |
|
179
|
|
|
else |
|
180
|
|
|
{ |
|
181
|
|
|
// scan the groups which pass on permissions to the anon user group member |
|
182
|
|
|
// or ass permissions if this is the anon group's calendar. |
|
183
|
|
|
foreach ($anon_groups as $parent_group) |
|
184
|
|
|
{ |
|
185
|
|
|
$rights = $acl->get_rights($parent_group,'calendar'); |
|
186
|
|
|
if (($rights & Acl::READ) || ($entry['account_id'] == $parent_group)) |
|
187
|
|
|
{ |
|
188
|
|
|
$has_read_permissions = true; |
|
189
|
|
|
break; |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
if ($has_read_permissions) |
|
194
|
|
|
{ |
|
195
|
|
|
// Separate groups from users for improved readability. |
|
196
|
|
|
if ($is_group) |
|
197
|
|
|
{ |
|
198
|
|
|
$groups[$entry['account_id']] = $entry['account_lid']; |
|
199
|
|
|
} |
|
200
|
|
|
else |
|
201
|
|
|
{ |
|
202
|
|
|
$users[$entry['account_id']] = Api\Accounts::format_username($entry['account_lid'],$entry['account_firstname'],$entry['account_lastname']); |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
asort($groups); |
|
207
|
|
|
asort($users); |
|
208
|
|
|
// concat users and groups to the option array. |
|
209
|
|
|
$this->arguments['users']['options'] = $groups + $users; |
|
210
|
|
|
if (count($this->arguments['users']['options']) > 10) |
|
211
|
|
|
{ |
|
212
|
|
|
$this->arguments['users']['multiple'] = 10; |
|
213
|
|
|
} |
|
214
|
|
|
else if (count($this->arguments['users']['options']) > 0) |
|
215
|
|
|
{ |
|
216
|
|
|
$this->arguments['users']['multiple'] = true; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
return parent::get_user_interface(); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
function get_content(&$arguments,$properties) |
|
223
|
|
|
{ |
|
224
|
|
|
$html = ""; |
|
225
|
|
|
Api\Translation::add_app('calendar'); |
|
226
|
|
|
$this->ui = new calendar_uiviews(); |
|
|
|
|
|
|
227
|
|
|
$this->ui->allowEdit = false; |
|
228
|
|
|
$this->ui->use_time_grid = isset($arguments['grid']) ? $arguments['grid'] : false; |
|
229
|
|
|
|
|
230
|
|
|
$weeks = $arguments['numWeeks'] ? (int) $arguments['numWeeks'] : 2; |
|
231
|
|
|
|
|
232
|
|
|
if (($arguments['acceptDateParam']) && (get_var('date',array('POST','GET')))) |
|
|
|
|
|
|
233
|
|
|
{ |
|
234
|
|
|
$start = (int) (strtotime(get_var('date',array('POST','GET'))) + |
|
235
|
|
|
(60 * 60 * 24 * 7 * $dateOffset)); |
|
|
|
|
|
|
236
|
|
|
} |
|
237
|
|
|
else |
|
238
|
|
|
{ |
|
239
|
|
|
$start = (int) ($this->bo->now_su + |
|
240
|
|
|
(60 * 60 * 24 * 7 * $dateOffset)); |
|
241
|
|
|
} |
|
242
|
|
|
$start = new Api\DateTime($start); |
|
243
|
|
|
$start->setWeekstart(); |
|
244
|
|
|
$first = $start->format('ts'); |
|
245
|
|
|
$last = strtotime("+$weeks weeks",$first) - 1; |
|
246
|
|
|
|
|
247
|
|
|
if ($arguments['showTitle']) |
|
248
|
|
|
{ |
|
249
|
|
|
$html .= '<div id="divAppboxHeader">'.$GLOBALS['egw_info']['apps']['calendar']['title'].' - '.lang('Weekview').": "; |
|
250
|
|
|
$html .= lang('After %1',$this->bo->long_date($first)); |
|
|
|
|
|
|
251
|
|
|
$html .= "</div>"; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
// set the search parameters |
|
255
|
|
|
$search_params = Array |
|
256
|
|
|
( |
|
257
|
|
|
'offset' => false, |
|
258
|
|
|
'order' => 'cal_start ASC', |
|
259
|
|
|
'start' => $first, |
|
260
|
|
|
'end' => $last, |
|
261
|
|
|
'daywise' => true, |
|
262
|
|
|
); |
|
263
|
|
|
$search_string = trim($arguments['search']); |
|
264
|
|
|
if ($search_string != "") |
|
265
|
|
|
{ |
|
266
|
|
|
$search_params['query'] = $search_string; |
|
267
|
|
|
} |
|
268
|
|
|
if (count($arguments['category']) > 0) |
|
269
|
|
|
{ |
|
270
|
|
|
$search_params['cat_id'] = $arguments['category']; |
|
271
|
|
|
} |
|
272
|
|
|
if ((is_array($arguments['users'])) && (count($arguments['users']) > 0)) |
|
273
|
|
|
{ |
|
274
|
|
|
$search_params['users'] = $arguments['users']; |
|
275
|
|
|
} |
|
276
|
|
|
$rows = $this->bo->search($search_params); |
|
277
|
|
|
if ($arguments['showWeeks']) |
|
278
|
|
|
{ |
|
279
|
|
|
$html .= "<div>".lang('Next')." ".lang('%1 weeks', $weeks).":</div>\n"; |
|
280
|
|
|
} |
|
281
|
|
|
$css_file = isset($arguments['css']) ? $arguments['css'] : $this->default_css; |
|
282
|
|
|
$html .= '<!-- BEGIN Calendar info -->'."\n"; |
|
283
|
|
|
$html .= '<style type="text/css">'."\n"; |
|
284
|
|
|
$html .= '<!--'."\n"; |
|
285
|
|
|
$html .= '@import url('.$GLOBALS['egw_info']['server']['webserver_url'].$css_file.");\n"; |
|
286
|
|
|
$html .= '-->'."\n"; |
|
287
|
|
|
$html .= '</style>'."\n"; |
|
288
|
|
|
$html .= '<!-- END Calendar info -->'."\n"; |
|
289
|
|
|
unset($css_file); |
|
290
|
|
|
// we add DAY_s/2 to $this->first (using 12h), to deal with daylight saving changes |
|
291
|
|
|
for ($week_start = $first; $week_start < $last; $week_start = strtotime("+1 week",$week_start)) |
|
292
|
|
|
{ |
|
293
|
|
|
$week = array(); |
|
294
|
|
|
for ($i = 0; $i < 7; ++$i) |
|
295
|
|
|
{ |
|
296
|
|
|
$day_ymd = $this->bo->date2string($i ? strtotime("+$i days",$week_start) : $week_start); |
|
297
|
|
|
$week[$day_ymd] = array_shift($rows); |
|
298
|
|
|
} |
|
299
|
|
|
$week_view = array( |
|
|
|
|
|
|
300
|
|
|
'menuaction' => false, |
|
301
|
|
|
'date' => $this->bo->date2string($week_start), |
|
302
|
|
|
); |
|
303
|
|
|
$title = lang('Wk').' '.adodb_date('W',$week_start); |
|
|
|
|
|
|
304
|
|
|
if (!isset($GLOBALS['egw']->template)) |
|
305
|
|
|
{ |
|
306
|
|
|
$GLOBALS['egw']->template = new Framework\Template; |
|
307
|
|
|
} |
|
308
|
|
|
} |
|
309
|
|
|
// Initialize Tooltips |
|
310
|
|
|
$html .= '<script language="JavaScript" type="text/javascript" src="'.$GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/js/wz_tooltip/wz_tooltip.js"></script>'."\n"; |
|
311
|
|
|
|
|
312
|
|
|
return $html; |
|
313
|
|
|
} |
|
314
|
|
|
} |
|
315
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths