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
|
<?php
include_once 'includes/init.php';
$my_event = false;
$can_edit = false;
// First, check to see if this user should be able to delete this event.
if ( $id > 0 ) {
// first see who has access to edit this entry
if ( $is_admin ) {
$can_edit = true;
} else if ( $readonly == "Y" ) {
$can_edit = false;
} else {
$can_edit = false;
$sql = "SELECT webcal_entry.cal_id FROM webcal_entry, " .
"webcal_entry_user WHERE webcal_entry.cal_id = " .
"webcal_entry_user.cal_id AND webcal_entry.cal_id = $id " .
"AND (webcal_entry.cal_create_by = '$login' " .
"OR webcal_entry_user.cal_login = '$login')";
$res = dbi_query ( $sql );
if ( $res ) {
$row = dbi_fetch_row ( $res );
if ( $row && $row[0] > 0 )
$can_edit = true;
dbi_free_result ( $res );
}
}
}
// See who owns the event. Owner should be able to delete.
$res = dbi_query (
"SELECT cal_create_by FROM webcal_entry WHERE cal_id = $id" );
if ( $res ) {
$row = dbi_fetch_row ( $res );
$owner = $row[0];
dbi_free_result ( $res );
if ( $owner == $login || $is_assistant && ( $user == $owner ) || $is_nonuser_admin && ( $user == $owner ) ) {
$my_event = true;
$can_edit = true;
}
}
if ( $readonly == 'Y' )
$cat_edit = false;
if ( ! $can_edit ) {
$error = translate ( "You are not authorized" );
}
// Is this a repeating event?
$event_repeats = false;
$res = dbi_query ( "SELECT COUNT(cal_id) FROM webcal_entry_repeats " .
"WHERE cal_id = $id" );
if ( $res ) {
$row = dbi_fetch_row ( $res );
if ( $row[0] > 0 )
$event_repeats = true;
dbi_free_result ( $res );
}
$override_repeat = false;
if ( ! empty ( $date ) && $event_repeats && ! empty ( $override ) ) {
$override_repeat = true;
}
if ( $id > 0 && empty ( $error ) ) {
if ( ! empty ( $date ) ) {
$thisdate = $date;
} else {
$res = dbi_query ( "SELECT cal_date FROM webcal_entry WHERE cal_id = $id" );
if ( $res ) {
// date format is 19991231
$row = dbi_fetch_row ( $res );
$thisdate = $row[0];
}
}
// Only allow delete of webcal_entry & webcal_entry_repeats
// if owner or admin, not participant.
if ( $is_admin || $my_event ) {
// Email participants that the event was deleted
// First, get list of participants (with status Approved or
// Waiting on approval).
$sql = "SELECT cal_login FROM webcal_entry_user WHERE cal_id = $id " .
"AND cal_status IN ('A','W')";
$res = dbi_query ( $sql );
$partlogin = array ();
if ( $res ) {
while ( $row = dbi_fetch_row ( $res ) ) {
if ( $row[0] != $login )
$partlogin[] = $row[0];
}
dbi_free_result($res);
}
// Get event name
$sql = "SELECT cal_name, cal_date, cal_time " .
"FROM webcal_entry WHERE cal_id = $id";
$res = dbi_query($sql);
if ( $res ) {
$row = dbi_fetch_row ( $res );
$name = $row[0];
$eventdate = $row[1];
$eventtime = $row[2];
dbi_free_result ( $res );
}
// TODO: switch transation language based on user so each user
// gets message in their selected language.
for ( $i = 0; $i < count ( $partlogin ); $i++ ) {
// Log the deletion
activity_log ( $id, $login, $partlogin[$i], $LOG_DELETE, "" );
$do_send = get_pref_setting ( $partlogin[$i], "EMAIL_EVENT_DELETED" );
user_load_variables ( $partlogin[$i], "temp" );
if ( $partlogin[$i] != $login && $do_send == "Y" && boss_must_be_notified ( $login, $partlogin[$i] ) &&
strlen ( $tempemail ) && $send_email != "N" ) {
$msg = translate("Hello") . ", " . $tempfullname . ".\n\n" .
translate("An appointment has been canceled for you by") .
" " . $login_fullname . ". " .
translate("The subject was") . " \"" . $name . "\"\n" .
translate("Date") . ": " . date_to_str ($thisdate) . "\n";
if ( $eventtime != '-1' ) $msg .= translate("Time") . ": " . display_time ($eventtime);
$msg .= "\n\n";
if ( strlen ( $login_email ) )
$extra_hdrs = "From: $login_email\r\nX-Mailer: " .
translate($application_name);
else
$extra_hdrs = "From: $email_fallback_from\r\nX-Mailer: " .
translate($application_name);
mail ( $tempemail,
translate($application_name) . " " .
translate("Notification") . ": " . $name,
html_to_8bits ($msg), $extra_hdrs );
}
}
// Instead of deleting from the database... mark it as deleted
// by setting the status for each participant to "D" (instead
// of "A"/Accepted, "W"/Waiting-on-approval or "R"/Rejected)
if ( $override_repeat ) {
dbi_query ( "INSERT INTO webcal_entry_repeats_not ( cal_id, cal_date ) " .
"VALUES ( $id, $date )" );
// Should we log this to the activity log???
} else {
// If it's a repeating event, delete any event exceptions
// that were entered.
if ( $event_repeats ) {
$res = dbi_query ( "SELECT cal_id FROM webcal_entry " .
"WHERE cal_group_id = $id" );
if ( $res ) {
$ex_events = array ();
while ( $row = dbi_fetch_row ( $res ) ) {
$ex_events[] = $row[0];
}
dbi_free_result ( $res );
for ( $i = 0; $i < count ( $ex_events ); $i++ ) {
$res = dbi_query ( "SELECT cal_login FROM " .
"webcal_entry_user WHERE cal_id = $ex_events[$i]" );
if ( $res ) {
$delusers = array ();
while ( $row = dbi_fetch_row ( $res ) ) {
$delusers[] = $row[0];
}
dbi_free_result ( $res );
for ( $j = 0; $j < count ( $delusers ); $j++ ) {
// Log the deletion
activity_log ( $ex_events[$i], $login, $delusers[$j],
$LOG_DELETE, "" );
dbi_query ( "UPDATE webcal_entry_user SET cal_status = 'D' " .
"WHERE cal_id = $ex_events[$i] " .
"AND cal_login = '$delusers[$j]'" );
}
}
}
}
}
// Now, mark event as deleted for all users.
dbi_query ( "UPDATE webcal_entry_user SET cal_status = 'D' " .
"WHERE cal_id = $id" );
}
} else {
// Not the owner of the event and are not the admin.
// Just delete the event from this user's calendar.
// We could just set the status to 'D' instead of deleting.
// (but we would need to make some changes to edit_entry_handler.php
// to accomodate this).
dbi_query ( "DELETE FROM webcal_entry_user " .
"WHERE cal_id = $id AND cal_login = '$login'" );
activity_log ( $id, $login, $login, $LOG_REJECT, "" );
}
}
$ret = getValue ( "ret" );
if ( ! empty ( $ret ) ) {
if ( $ret == "list" ) {
$url = "list_unapproved.php";
if ( ! empty ( $user ) )
$url .= "?user=$user";
}
else
$url = "$STARTVIEW.php";
} else if ( strlen ( get_last_view() ) ) {
$url = get_last_view();
} else {
$redir = "";
if ( $thisdate != "" )
$redir = "?date=$thisdate";
if ( $user != "" ) {
if ( $redir != "" )
$redir .= "&";
$redir .= "user=$user";
}
$url = "$STARTVIEW.php" . $redir;
}
if ( empty ( $error ) ) {
if ($is_assistant || $is_nonuser_admin)
$url = $url . (strpos($url, "?") === false ? "?" : "&") . "user=$user";
do_redirect ( $url );
exit;
}
print_header();
?>
<h2><?php etranslate("Error")?></h2>
<blockquote>
<?php echo $error; ?>
</blockquote>
<?php print_trailer(); ?>
</body>
</html>
|