forked from tsugitools/ckpaper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
128 lines (113 loc) · 3.37 KB
/
edit.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\Util\Net;
use \Tsugi\Core\LTIX;
use \Tsugi\Core\Settings;
use \Tsugi\UI\SettingsForm;
// 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('edit.php') ) ;
return;
}
// Handle Post Data
$p = $CFG->dbprefix;
$old_content = $LAUNCH->result->getJsonKey('content', '');
if ( count($_POST) > 0 ) {
$LAUNCH->result->setJsonKey('content', U::get($_POST, 'content') );
$_SESSION['success'] = 'Updated';
header( 'Location: '.addSession('index.php') ) ;
return;
}
$menu = new \Tsugi\UI\MenuSet();
$menu->addLeft(__('Main'), 'index');
if ( $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(__('Instructor'), $submenu);
} else {
$menu->addRight(__('Settings'), '#', /* push */ false, SettingsForm::attr());
}
// Render view
$OUTPUT->header();
// https://github.com/jitbit/HtmlSanitizer
$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();
?>
<div id="spinner"><img src="<?= $OUTPUT->getSpinnerUrl() ?>"/></div>
<div id="editor_div" style="display: none;">
<form method="post">
<textarea name="content" id="editor">
</textarea>
<p><input type="submit" value="Submit"></p>
</form>
</div>
<?php
$OUTPUT->footerStart();
?>
<script src="https://cdn.jsdelivr.net/gh/jitbit/HtmlSanitizer@master/HtmlSanitizer.js"></script>
<script src="https://cdn.ckeditor.com/ckeditor5/16.0.0/classic/ckeditor.js"></script>
<script type="text/javascript">
ClassicEditor.defaultConfig = {
toolbar: {
items: [
'heading',
'|',
'bold',
'italic',
'link',
'bulletedList',
'numberedList',
// 'imageUpload',
'blockQuote',
'insertTable',
'mediaEmbed',
'undo',
'redo'
]
},
}
$(document).ready( function () {
$.get('<?= addSession('load_text.php') ?>', function(data) {
console.log(data);
var html = HtmlSanitizer.SanitizeHtml(data);
console.log(html);
$('#editor').html(html);
$('#output_div').html(html);
ClassicEditor
.create( document.querySelector( '#editor' ) ,
{
}
).then(editor => {
// editor.isReadOnly = true;
$('#spinner').hide();
$('#editor_div').show();
} ).catch( error => {
console.error( error );
} );
})
}
);
</script>
<?php
$OUTPUT->footerEnd();