-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupdate_lesson_instructions.php
More file actions
87 lines (75 loc) · 2.13 KB
/
update_lesson_instructions.php
File metadata and controls
87 lines (75 loc) · 2.13 KB
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
<?php
/**
* Update Lesson Instructions
*
* Handle Updating Lesson Instructions
*
* PHP version 7.2.5
*
* @category Main_App
* @package UnlockED
* @author UnlockedLabs <developers@unlockedlabs.org>
* @license https://www.gnu.org/licenses/gpl.html GPLv3
* @link http://unlockedlabs.org
*/
namespace unlockedlabs\unlocked;
require_once 'session-validation.php';
//ensure admin user (admin is 2 and above)
if (($_SESSION['admin_num'] < 2)) {
die('<h1>Restricted Action!</h1>');
}
// include database and object files
require_once dirname(__FILE__).'/config/core.php';
require_once dirname(__FILE__).'/config/database.php';
require_once dirname(__FILE__).'/objects/lesson.php';
// instantiate database and product object
$database = new Database();
$db = $database->getConnection();
$lesson = new Lesson($db);
$id = isset($_GET['lesson_id']) ? $_GET['lesson_id'] : die('ERROR: Lesson ID.');
$editor_html = isset($_POST['editor_html']) ? $_POST['editor_html'] : die('ERROR: Editor Html.');
//set object properties
$lesson->id = $id;
$lesson->editor_html = $editor_html;
//update html
if ($lesson->updateEditorHtml()) {
echo <<<_ALERT
<script>
swal({
title: '<h4>Instructions Updated!</h4>',
type: 'success',
confirmButtonColor: '#3085d6',
confirmButtonClass: 'btn btn-info',
allowOutsideClick: false,
confirmButtonText: 'OK',
onClose: function() {
//pass
},
});
</script>
_ALERT;
} else {
echo <<<_ALERT
<script>
swal({
title: '<h4>Instructions Could Not Be Updated!</h4>',
type: 'error',
confirmButtonColor: '#3085d6',
confirmButtonClass: 'btn btn-info',
allowOutsideClick: false,
confirmButtonText: 'OK',
onClose: function() {
//pass
},
});
</script>
_ALERT;
}
/*
* This may be an unnecessary query as $editor_html holds the post html.
* Will the post and db strings ever differ?
* If not, omit this query.
*/
$lesson->readOne();
//return new html
echo $lesson->editor_html;