forked from craigk5n/webcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_unapproved.php
313 lines (287 loc) · 10.9 KB
/
list_unapproved.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<?php
/**
* This file lists unapproved entries for one or more users.
*
* Optional parameters in URL:
* url=user specifies that we should only display unapproved
* events for that one user
*
* The user will be allowed to approve/reject the event if:
* it is on their own calendar
*
* @author Craig Knudsen <[email protected]>
* @copyright Craig Knudsen, <[email protected]>, http://k5n.us/webcalendar
* @license https://gnu.org/licenses/old-licenses/gpl-2.0.html GNU GPL
* @package WebCalendar
*/
require_once 'includes/init.php';
send_no_cache_header();
if ( empty ( $user ) )
$user = $login;
if ( ! empty ( $_POST ) ) {
$process_action = getPostValue ( 'process_action' );
$process_user = getPostValue ( 'process_user' );
if ( ! empty ( $process_action ) ) {
foreach ( $_POST as $tid => $app_user ) {
if ( substr ( $tid, 0, 5 ) == 'entry' ) {
$type = substr ( $tid, 5, 1 );
$id = substr ( $tid, 6 );
if ( empty ( $error ) && $id > 0 )
update_status ( $process_action, $app_user, $id, $type );
}
}
}
}
// Only admin user or assistant can specify a username other than his own.
if ( ! $is_admin && $user != $login && ! $is_assistant && ! access_is_enabled() )
$user = $login;
// Make sure we return after editing an event via this page.
remember_this_view();
$key = 0;
$eventinfo = $noret = '';
/**
* List all unapproved events for the specified user.
* Exclude "extension" events (used when an event goes past midnight).
* TODO: Only include delete link if they have permission to delete
* when user access control is enabled.
* NOTE: this function is almost identical to the one in rss_unapproved.php.
* Just the format (RSS vs HTML) is different.
*/
function list_unapproved ( $user ) {
global $eventinfo, $key, $login, $NONUSER_ENABLED, $noret, $temp_fullname;
user_load_variables ( $user, 'temp_' );
$rssLink = '<a href="rss_unapproved.php?user=' .
htmlspecialchars ( $user ) . '"><img class="button-icon-inverse" src="images/bootstrap-icons/rss-fill.svg" alt="RSS 2.0 - ' .
htmlspecialchars ( $temp_fullname ) . '"></a>';
$count = 0;
$ret = '';
$sql = 'SELECT we.cal_id, we.cal_name, we.cal_description, weu.cal_login,
we.cal_priority, we.cal_date, we.cal_time, we.cal_duration,
weu.cal_status, we.cal_type
FROM webcal_entry we, webcal_entry_user weu
WHERE we.cal_id = weu.cal_id AND weu.cal_login = ? AND weu.cal_status = \'W\'
ORDER BY weu.cal_login, we.cal_date';
$rows = dbi_get_cached_rows ( $sql, [$user] );
if ( $rows ) {
$allDayStr = translate ( 'All day event' );
$appConStr = translate ( 'Approve/Confirm' );
$appSelStr = translate ( 'Approve Selected' );
$checkAllStr = translate ( 'Check All' );
$deleteStr = translate ( 'Delete' );
$emailStr = translate ( 'Emails Will Not Be Sent' );
$rejectSelStr = translate ( 'Reject Selected' );
$rejectStr = translate ( 'Reject' );
$uncheckAllStr = translate ( 'Uncheck All' );
$viewStr = translate ( 'View this entry' );
for ( $i = 0, $cnt = count ( $rows ); $i < $cnt; $i++ ) {
$row = $rows[$i];
$key++;
$id = $row[0];
$name = $row[1];
$description = $row[2];
$cal_user = $row[3];
$pri = $row[4];
$date = $row[5];
$time = sprintf ( "%06d", $row[6] );
$duration = $row[7];
$status = $row[8];
$type = $row[9];
$view_link = 'view_entry';
$entryID = 'entry' . $type . $id;
$linkid = "pop$id-$key";
$timestr = '';
if ( $time > 0 || ( $time == 0 && $duration != 1440 ) ) {
$eventstart = date_to_epoch ( $date . $time );
$eventstop = $eventstart + $duration;
$eventdate = date_to_str ( date ( 'Ymd', $eventstart ) );
$timestr = display_time ( '', 0, $eventstart )
. ( $duration > 0 ? ' - ' . display_time ( '', 0, $eventstop ) : '' );
} else {
// Don't shift date if All Day or Untimed.
$eventdate = date_to_str ( $date );
// If All Day display in popup.
if ( $time == 0 && $duration == 1440 )
$timestr = $allDayStr;
}
$ret .= ( $count == 0 ? '
<tr>
<td colspan="5"><h3>' . $temp_fullname . ' ' . $rssLink . '</h3></td>
</tr>' : '' ) . '
<tr ' . ( $count % 2 == 0 ? '' : 'class="odd"' ) . '>
<td width="5%" class="alignright"><input type="checkbox" name="'
. $entryID . '" value="' . $user . '"></td>
<td><a title="' . $viewStr . '" class="entry" id="' . $linkid
. '" href="' . $view_link . '.php?id=' . $id . '&user=' . $cal_user
. '">' . htmlspecialchars ( $name ) . '</a> (' . $eventdate . '):</td>'
/* approve */ . '
<td class="aligncenter"><input type="image" src="images/bootstrap-icons/check-circle.svg" title="'
. $appConStr . '" onclick="return do_confirm( \'approve\', \''
. $cal_user . '\', \'' . $entryID . '\' );"></td>'
/* reject */ . '
<td class="aligncenter"><input type="image" src="images/bootstrap-icons/dash-circle.svg" title="'
. $rejectStr . '" onclick="return do_confirm( \'reject\', \''
. $cal_user . '\', \'' . $entryID . '\' );"></td>'
/* delete */
. ( ! access_is_enabled() || access_user_calendar ( 'edit', $user ) ? '
<td class="aligncenter"><input type="image" src="images/bootstrap-icons/trash.svg" title="'
. $deleteStr . '" onclick="return do_confirm( \'delete\', \''
. $cal_user . '\', \'' . $entryID . '\' );\"></td>' : '' ) . '
</tr>';
$eventinfo .= build_entry_popup ( 'eventinfo-' . $linkid, $cal_user,
$description, $timestr, site_extras_for_popup ( $id ) );
$count++;
}
if ( $count > 1 )
$ret .= '
<tr>
<td colspan="5" nowrap>
<img src="images/bootstrap-icons/arrow-90deg-up.svg" alt="">
<label><a title="' . $checkAllStr . '" onclick="check_all( \''
. $user . '\' );">' . $checkAllStr . '</a> / <a title="' . $uncheckAllStr
. '" onclick="uncheck_all( \'' . $user . '\' );">' . $uncheckAllStr
. '</a></label>
<input type="image" src="images/bootstrap-icons/check-circle.svg" title="' . $appSelStr
. '" onclick="return do_confirm( \'approveSelected\', \'' . $cal_user
. '\' );">
<input type="image" src="images/bootstrap-icons/dash-circle.svg" title="' . $rejectSelStr
. '" onclick="return do_confirm( \'rejectSelected\', \'' . $cal_user
. '\' );"> ( ' . $emailStr . ' )
</td>
</tr>';
}
if ( $count == 0 )
$noret .= '
<tr>
<td colspan="5" class="nounapproved">'
. str_replace ( 'XXX', $temp_fullname,
translate ( 'No unapproved entries for XXX.' ) ) .
' ' . $rssLink . '</td>
</tr>';
return $ret;
} //end list_unapproved()
print_header ( ['js/popups.js/true'], generate_refresh_meta() );
echo '<h2>' . translate ( 'Unapproved Entries' ) . '</h2>';
$app_user_hash = $app_users = $my_non_users = [];
$non_users = get_nonuser_cals();
foreach ( $non_users as $nonuser ) {
if ( user_is_nonuser_admin ( $login, $nonuser['cal_login'] ) )
$my_non_users[]['cal_login'] = $nonuser['cal_login'];
}
// If a user is specified, we list just that user.
if ( ( $is_assistant || $is_nonuser_admin || $is_admin ||
access_is_enabled() ) && ! empty ( $user ) && $user != $login ) {
if ( ! access_is_enabled() ||
access_user_calendar ( 'approve', $user ) ) {
$app_user_hash[$user] = 1;
$app_users[] = $user;
} else
// Not authorized to approve for specified user.
echo translate ( 'Not authorized' );
} else {
// First, we list ourself.
$app_user_hash[$login] = 1;
$app_users[] = $login;
if ( access_is_enabled() ) {
$all = ( $NONUSER_ENABLED == 'Y'
? array_merge ( get_my_users(), $my_non_users )
: get_my_users() );
for ( $j = 0, $cnt = count ( $all ); $j < $cnt; $j++ ) {
$x = $all[$j]['cal_login'];
if ( access_user_calendar ( 'approve', $x ) &&
empty ( $app_user_hash[$x] ) ) {
$app_user_hash[$x] = 1;
$app_users[] = $x;
}
}
} else {
if ( $is_admin && $PUBLIC_ACCESS == 'Y' &&
( empty ( $user ) || $user != '__public__' ) ) {
$app_users_hash['__public__'] = 1;
$app_users[] = '__public__';
}
$all = $my_non_users;
for ( $j = 0, $cnt = count ( $all ); $j < $cnt; $j++ ) {
$x = $all[$j]['cal_login'];
if ( empty ( $app_user_hash[$x] ) ) {
$app_user_hash[$x] = 1;
$app_users[] = $x;
}
}
}
}
echo '
<form action="list_unapproved.php" name="listunapproved" method="post">
<table>';
print_form_key();
for ( $i = 0, $cnt = count ( $app_users ); $i < $cnt; $i++ ) {
// List unapproved entries for this user.
echo list_unapproved ( $app_users[$i] );
}
echo '
<tr>
<td colspan="5"> </td>
</tr>' // List users with no events.
. $noret . '
</table>
<input type="hidden" name="process_action" value="">
<input type="hidden" name="process_user" value="">
</form>' . ( ! empty ( $eventinfo ) ? $eventinfo : '' ) . '
<script>
<!-- <![CDATA[
function check_all ( user ) {
var
theForm = document.forms [ \'listunapproved\' ],
z;
for ( z = 0; z < theForm.length; z++ ) {
if ( theForm[z].type == \'checkbox\' && theForm[z].value == user )
theForm[z].checked = true;
}
}
function uncheck_all ( user ) {
var
theForm = document.forms[\'listunapproved\'],
z;
for ( z = 0; z < theForm.length; z++ ) {
if ( theForm[z].type == \'checkbox\' && theForm[z].value == user )
theForm[z].checked = false;
}
}
function do_confirm ( phrase, user, id ) {
form = document.listunapproved;
switch ( phrase ) {
case "approve":
str = "' . translate ( 'Approve this entry?', true ) . '";
action = \'A\';
break;
case "reject":
str = "' . translate ( 'Reject this entry?', true ) . '";
action = \'R\';
break;
case "delete":
str = "'
. translate( 'Are you sure you want to delete this entry?' ) . '";
action = \'D\';
break;
case "approveSelected":
str = "' . translate ( 'Approve Selected entries?', true ) . '";
action = \'A\';
break;
case "rejectSelected":
str = "' . translate ( 'Reject Selected entries?', true ) . '";
action = \'R\';
break;
default:
str = action = \'\';
}
form.process_action.value = action;
form.process_user.value = user;
conf = confirm ( str );
// We need this if only single operation.
if ( id && conf )
form.elements[id].checked = true;
return conf;
}
//]]> -->
</script>
' . print_trailer ();
?>