-
Notifications
You must be signed in to change notification settings - Fork 74
/
reject_entry.php
165 lines (143 loc) · 5.3 KB
/
reject_entry.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
<?php
require_once 'includes/init.php';
require_once 'includes/classes/WebCalMailer.php';
$mail = new WebCalMailer;
$error = '';
if ( $readonly == 'Y' )
$error = print_not_auth();
// Give user a chance to add comments to rejection email.
if ( ! empty ( $_POST ) )
$comments = getPostValue ( 'comments' );
else {
print_header();
echo '
<form action="reject_entry.php'
. ( empty ( $_SERVER['QUERY_STRING'] ) ? '' : '?' . $_SERVER['QUERY_STRING'] )
. '" method="post" name="add_comments">';
print_form_key ();
echo '<table cellspacing="5">
<tr>
<td class="aligncenter alignbottom"><h3>'
. translate ( 'Additional Comments (optional)' ) . '</h3></td>
</tr>
<tr>
<td class="aligncenter"><textarea name="comments" rows="5" cols="60">'
. '</textarea></td>
</tr>
<tr>
<td class="AlignCenter"><button type="submit">'
. translate ( 'Continue' ) . '</button></td>
</tr>
<tr>
<td>'
. translate ( '(Your comments will be emailed to the other participants.)' )
. '</td>
</tr>
</table>
</form>';
echo print_trailer();
exit;
}
$user = getValue ( 'user' );
$id = getValue ( 'id' );
// Allow administrators to approve public events.
$app_user = ( $PUBLIC_ACCESS == 'Y' && ! empty ( $public ) && $is_admin
? '__public__' : ( $is_assistant || $is_nonuser_admin ? $user : $login ) );
// If User Access Control is enabled,
// we check to see if they are allowed to approve for the specified user.
if ( access_is_enabled() && ! empty ( $user ) && $user != $login ) {
if ( access_user_calendar ( 'approve', $user ) )
$app_user = $user;
}
if ( empty ( $error ) && $id > 0 ) {
update_status ( 'R', $app_user, $id, getGetValue ( 'type' ) );
// Email participants to notify that it was rejected.
// Get list of participants.
$res = dbi_execute ( 'SELECT cal_login FROM webcal_entry_user
WHERE cal_id = ?
AND cal_status = "A"', [$id] );
$partlogin = [];
if ( $res ) {
while ( $row = dbi_fetch_row ( $res ) ) {
$partlogin[] = $row[0];
}
dbi_free_result ( $res );
}
// Get the name of the event.
$res = dbi_execute ( 'SELECT cal_name, cal_description, cal_date, cal_time
FROM webcal_entry
WHERE cal_id = ?', [$id] );
if ( $res ) {
$row = dbi_fetch_row ( $res );
$name = $row[0];
$description = $row[1];
$fmtdate = $row[2];
$time = sprintf ( "%06d", $row[3] );
dbi_free_result ( $res );
}
$eventstart = date_to_epoch ( $fmtdate . $time );
for ( $i = 0, $cnt = count ( $partlogin ); $i < $cnt; $i++ ) {
// Does this user want email for this?
$send_user_mail = get_pref_setting ( $partlogin[$i],
'EMAIL_EVENT_REJECTED' );
// Check UAC.
$can_mail = 'Y';
if ( access_is_enabled() )
$can_mail = access_user_calendar ( 'email', $partlogin[$i], $login );
$htmlmail = get_pref_setting ( $partlogin[$i], 'EMAIL_HTML' );
$t_format = get_pref_setting ( $partlogin[$i], 'TIME_FORMAT' );
user_load_variables ( $partlogin[$i], 'temp' );
$user_TIMEZONE = get_pref_setting ( $partlogin[$i], 'TIMEZONE' );
set_env ( 'TZ', $user_TIMEZONE );
$user_language = get_pref_setting ( $partlogin[$i], 'LANGUAGE' );
if ( $send_user_mail == 'Y' &&
strlen ( $tempemail ) && $SEND_EMAIL != 'N' && $can_mail == 'Y' ) {
reset_language ( empty ( $user_language ) || $user_language == 'none'
? $LANGUAGE : $user_language );
$msg =
str_replace ( 'XXX', $tempfullname, translate ( 'Hello, XXX.' ) ) . '
' . str_replace ( 'XXX', $login_fullname,
translate ( 'XXX has rejected an appointment.' ) ) . '
' . str_replace ( 'XXX', $name, translate ( 'Subject XXX' ) ) . '
' . str_replace ( 'XXX', $description, translate ( 'Description XXX' ) ) . '
' . str_replace ( 'XXX', translate ( date_to_str ( $fmtdate ), 'N' ),
translate ( 'Date XXX' ) ) . '
' . ( empty ( $hour ) && empty ( $minute ) ? ''
: // Display using user's TIMEZONE and display TZID.
str_replace ( 'XXX',
translate ( display_time ( '', 2, $eventstart, $t_format ), 'N' ),
translate ( 'Time XXX' ) ) );
if ( ! empty ( $SERVER_URL ) ) {
// DON'T change & to & here. Email will handle it.
$url = $SERVER_URL . 'view_entry.php?id=' . $id . '&em=1';
$msg .= '
' . ( $htmlmail == 'Y' ? activate_urls ( $url ) : $url );
}
if ( strlen ( $comments ) )
$msg .= '
' . str_replace ( 'XXX', $comments, translate ( 'Comments XXX' ) );
$from = $EMAIL_FALLBACK_FROM;
if ( strlen ( $login_email ) )
$from = $login_email;
// Send via WebCalMailer class.
$mail->WC_Send ( $login_fullname, $tempemail,
$tempfullname, $name, $msg, $htmlmail, $from );
activity_log ( $id, $login, $partlogin[$i], LOG_NOTIFICATION,
str_replace ( 'XXX', $app_user, translate ( 'Rejected by XXX.' ) ) );
}
}
}
// Return to login TIMEZONE.
set_env ( 'TZ', $TIMEZONE );
if ( empty ( $error ) && empty ( $mailerError ) ) {
if ( ! empty ( $ret ) && $ret == 'listall' )
do_redirect ( 'list_unapproved.php' );
else
do_redirect ( ( ! empty ( $ret ) && $ret == 'list'
? 'list_unapproved.php?' : 'view_entry.php?id=' . $id . '&' )
. 'user=' . $app_user );
exit;
}
// Process errors.
$mail->MailError ( $mailerError, $error );
?>