These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | require_once('common.inc.php'); |
||
4 | |||
5 | if (isset($_REQUEST['course_url'])) { |
||
6 | $eventsApi = new CanvasPest($_SESSION['apiUrl'], $_SESSION['apiToken']); |
||
7 | |||
8 | // TODO work nicely with the cache (purge uncached events, or only cached events, etc.) |
||
9 | |||
10 | $events = $eventsApi->get('calendar_events', |
||
11 | array( |
||
12 | 'type' => 'event', |
||
13 | 'all_events' => true, |
||
14 | 'context_codes[]' => preg_replace('|.*/courses/(\d+)/?.*|', "course_$1", $_REQUEST['course_url']) |
||
15 | ) |
||
16 | ); |
||
17 | do { |
||
18 | foreach($events as $event) { |
||
19 | $api->delete("calendar_events/{$event['id']}", |
||
20 | array( |
||
21 | 'cancel_reason' => $metadata['APP_NAME'] . " course_url={$_REQUEST['course_url']}" |
||
22 | ) |
||
23 | ); |
||
24 | } |
||
25 | } while($events = $eventsApi->nextPage()); |
||
26 | |||
27 | $smarty->assign('content', 'Calendar purged.'); |
||
28 | } else { |
||
29 | $smarty->assign('content', '<form action="' . $_SERVER['PHP_SELF'] . '" method="post"><label for="course_url">Course URL <input id="course_url" name="course_url" type="text" /><input type="submit" value="Purge All Calendar Events" /></form>'); |
||
30 | } |
||
31 | |||
32 | $smarty->display(); |
||
33 | |||
34 | ?> |
||
0 ignored issues
–
show
|
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.