-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_units2_2.php
208 lines (163 loc) · 7.77 KB
/
edit_units2_2.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
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
<?php
include('top_include.php');
?>
<div class="container">
<?php topbar('Unit Tracker'); ?>
</div>
<div class="container-fluid">
<?php
/**
* Created by JetBrains PhpStorm.
* User: DATTWOOD
* Date: 04/07/12
* Time: 13:04
* To change this template use File | Settings | File Templates.
*/
$courseId = $_GET['courseId'];
// stuff to process the incoming forms
if (isset($_POST['deleteUnit'])) {
$query = "DELETE FROM {$CFG->prefix}unit_tracker_units WHERE id='" . $_POST['id'] . "'";
// echo $query;
$DB->execute($query);
// unset the post variables
}
if (isset($_POST['updateUnit'])) {
$query = "UPDATE {$CFG->prefix}unit_tracker_units set markid='" . $_POST['marking'] . "', name='" . $_POST['unitName'] . "', description='" . $_POST['unitDescription'] . "' WHERE id='" . $_POST['unitId'] . "'";
// echo $query;
$DB->execute($query);
// unset the post variables
}
if (isset($_POST['add_new_unit'])) {
$query = "INSERT INTO {$CFG->prefix}unit_tracker_units (name, description, courseid, markid) VALUES ('" . $_POST['unitName'] . "','" . $_POST['unitDescription'] . "','" . $courseId . "','" . $_POST['marking'] . "')";
// echo $query;
$DB->execute($query);
unset($_POST['add_new_unit']);
// unset the post variables
}
//global $CFG, $COURSE, $USER, $DB;
?>
<a class="btn btn-success" href="tracker2.php"><i class=" icon-chevron-left icon-white"></i>Back to the Unit Tracker</a>
<div class="well units">
<h1>Edit and Add Units for Course <?php echo $courseName ?> </h1>
<?php
// Get all the units for the course
$query = "SELECT {$CFG->prefix}unit_tracker_units.id, name, courseid, description, markid, {$CFG->prefix}unit_tracker_marks.id as markid2, type
FROM {$CFG->prefix}unit_tracker_units JOIN {$CFG->prefix}unit_tracker_marks ON {$CFG->prefix}unit_tracker_units.markid={$CFG->prefix}unit_tracker_marks.id
WHERE courseid='" . $courseId . "'";
//echo $query;
$result = $DB->get_records_sql($query);
if (count($result) == 0) {
echo '<div class="alert alert-error">There are no units yet for this course</div>';
} else {
?>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Unit name</th>
<th>Description</th>
<th>Marking Scheme</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
foreach ($result as $row) {
?>
<tr>
<td>
<?php echo $row->id; ?>
<form action="tracker2.php" method="POST">
<input type="hidden" name="unitId" value="<?php echo $row->id; ?>"/>
</td>
<td>
<input type="text" name="unitName" value="<?php echo $row->name; ?>"/>
</td>
<td>
<textarea name="unitDescription"><?php echo $row->description; ?></textarea>
</td>
<td>
<?php
// echo ' markid ' . $row->markid;
$queryMark = "SELECT id, type FROM {$CFG->prefix}unit_tracker_marks";
// echo $queryMark;
$resultMark = $DB->get_records_sql($queryMark);
echo '<select name="marking"/>';
foreach ($resultMark as $rowMark) {
if ($rowMark->id == $row->markid) {
$selected = 'selected="selected" ';
} else {
$selected = ' ';
}
echo '<option ' . $selected . 'value="' . $rowMark->id . '" >' . $rowMark->type . '</option>';
}
echo '</select>';
?>
</td>
<td>
<input class="btn btn-success" type="submit" name="updateUnit" value="Update"/>
</form>
</td>
<td>
<form action="edit_units2_2.php?courseId=<?php echo $courseId; ?>" method="POST">
<input type="hidden" name="id" value="<?php echo $row->id; ?>"/>
<input class="btn btn-danger" type="submit" name="deleteUnit" value="Delete"/>
</form>
</td>
<td>
<button class="btn btn-info" data-toggle="collapse"
data-target="#crit_<?php echo $row->id;?>">
<i class="icon-zoom-in icon-white"></i> Show Unit Criteria
</button>
</td>
</tr>
<tr>
<td colspan="7">
<div id="crit_<?php echo $row->id;?>" class="collapse">
<?php
// get all the criteria
echo '<div class="well breakout">';
include('edit_crits.php');
echo '</div>';
?>
</div>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php } ?>
</table>
<div class="button-right"><a class="btn btn-success" data-toggle="modal" href="#Add_unit"><i
class="icon-plus-sign icon-white"></i> Add a new unit</a></div>
<div class="modal hide" id="Add_unit">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Add a new unit to <?php echo $courseName; ?></h3>
</div>
<form class="well" action="edit_units2_2.php?courseId=<?php echo $courseId; ?>" method="POST">
<label class="control-label" for="unitName">Unit name</label>
<input type="text" name="unitName" id="unitName"/>
<label class="control-label" for="unitDescription">Unit Description</label>
<textarea name="unitDescription" id="unitDescription"></textarea>
<?php
// Get possbile marking schemes
$query = "SELECT id, type FROM {$CFG->prefix}unit_tracker_marks";
$result = $DB->get_records_sql($query);
echo '<label class="control-label" for="marking">Marking Scheme</label>';
echo '<select name="marking" id="marking">';
foreach ($result as $row) {
echo '<option value="', $row->id, '">', $row->type, '</option>';
}
echo '</select>';
?>
<br>
<input class="btn btn-primary" type="submit" name="add_new_unit" value="Add new unit "/>
</form>
</div>
</div>
</div>
</div>