forked from tsugitools/ckpaper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
127 lines (111 loc) · 4.09 KB
/
index.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
<?php
require_once "../config.php";
// The Tsugi PHP API Documentation is available at:
// http://do1.dr-chuck.com/tsugi/phpdoc/
use \Tsugi\Util\U;
use \Tsugi\Core\LTIX;
use \Tsugi\Core\Settings;
use \Tsugi\UI\SettingsForm;
use \Tsugi\UI\Annotate;
use \Tsugi\Core\Annotate as AnnotateModel;
// No parameter means we require CONTEXT, USER, and LINK
$LAUNCH = LTIX::requireData();
// If settings were updated
if ( SettingsForm::handleSettingsPost() ) {
$_SESSION["success"] = "Settings updated.";
header( 'Location: '.addSession('index.php') ) ;
return;
}
$next = U::safe_href(U::get($_GET, 'next', 'edit.php'));
$user_id = U::safe_href(U::get($_GET, 'user_id'));
if ( $user_id && ! $LAUNCH->user->instructor ) {
http_response_code(403);
die('Not authorized');
}
if ( ! $user_id ) $user_id = $LAUNCH->user->id;
$inst_note = $LAUNCH->result->getNote($user_id );
$annotations = AnnotateModel::loadAnnotations($LAUNCH, $user_id);
// Load and parse the old JSON
$json = $LAUNCH->result->getJsonForUser($user_id);
$json = json_decode($json);
if ( $json == null ) $json = new \stdClass();
$lock = isset($json->lock) && $json->lock;
$edit_text = __('Edit');
if ( $next != 'edit.php' ) $edit_text = __('Back');
$load_url = $user_id ? 'load_text.php?user_id=' . $user_id : 'load_text.php';
$menu = new \Tsugi\UI\MenuSet();
if ( $lock && ! $LAUNCH->user->instructor ) {
$menu->addLeft(__('Entry Locked'), false);
} else {
$menu->addLeft($edit_text, $next);
}
if ( count($annotations) > 0 ) {
$menu->addRight(__('Annotations:').' '.count($annotations), false);
}
if ( $LAUNCH->user->instructor ) {
$submenu = new \Tsugi\UI\Menu();
$submenu->addLink(__('Student Data'), 'grades');
$submenu->addLink(__('Settings'), '#', /* push */ false, SettingsForm::attr());
if ( $CFG->launchactivity ) {
$submenu->addLink(__('Analytics'), 'analytics');
}
$menu->addRight(__('Help'), '#', /* push */ false, 'data-toggle="modal" data-target="#helpModal"');
$menu->addRight(__('Instructor'), $submenu, /* push */ false);
} else {
if ( strlen($inst_note) > 0 ) $menu->addRight(__('Note'), '#', /* push */ false, 'data-toggle="modal" data-target="#noteModal"');
$menu->addRight(__('Help'), '#', /* push */ false, 'data-toggle="modal" data-target="#helpModal"');
$menu->addRight(__('Settings'), '#', /* push */ false, SettingsForm::attr());
}
$old_content = $LAUNCH->result->getJsonKeyForUser('content', '', $user_id);
// Render view
$OUTPUT->header();
echo(Annotate::header());
$OUTPUT->bodyStart();
$OUTPUT->topNav($menu);
$OUTPUT->flashMessages();
SettingsForm::start();
SettingsForm::checkbox('sendgrade',__('Send a grade'));
?>
<p>This tool uses technology from the
<a href="http://annotatorjs.org/" target="_blank">Annotator JS</a> project and
<a href="https://ckeditor.com/" target="_blank">CKEditor 5.0</a>.
</p>
<?php
SettingsForm::done();
SettingsForm::end();
$OUTPUT->helpModal("Annotation Tool",
"You can edit and annotate formatted text with this tool. Your teacher can also annotate your document.
To annotate, simply highlight text and an edit dialog will pop up so you can add, edit, or delete a comment.");
if ( strlen($inst_note) > 0 ) {
echo($OUTPUT->modalString(__("Instructor Note"), htmlentities($inst_note), "noteModal"));
}
if ( strlen($old_content) < 1 ) {
$OUTPUT->welcomeUserCourse();
echo("<p>Please edit your submission.</p>\n");
$OUTPUT->footer();
return;
}
?>
<div id="spinner"><img src="<?= $OUTPUT->getSpinnerUrl() ?>"/></div>
<div id="output_div" style="display: none;">
</div>
<?php
$OUTPUT->footerStart();
echo(Annotate::footer($user_id));
// https://github.com/jitbit/HtmlSanitizer
?>
<script src="https://cdn.jsdelivr.net/gh/jitbit/HtmlSanitizer@master/HtmlSanitizer.js"></script>
<script type="text/javascript">
$(document).ready( function () {
$.get('<?= addSession($load_url) ?>', function(data) {
var html = HtmlSanitizer.SanitizeHtml(data);
$('#output_div').html(html);
$('#spinner').hide();
$('#output_div').show();
tsugiStartAnnotation('#output_div');
})
}
);
</script>
<?php
$OUTPUT->footerEnd();