-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcreatelevels.inc
More file actions
75 lines (62 loc) · 2.02 KB
/
createlevels.inc
File metadata and controls
75 lines (62 loc) · 2.02 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
<?php
$sel = $_GET['sel'];
$selectList .= "
<script>
function handleThis(value) {
// alert('test');
window.location='index.php?cmd=createlevels&sel=' + value;
}
</script>
";
$electives = $db->get_results("SELECT * from subjects ", ARRAY_A);
$selectList .= "<select name=listid onChange='javascritp:handleThis(this.value);'>
<option value=''>--</option>";
foreach($electives as $el) {
$id = $el['id'];
$select = ($id == $sel) ? "selected": "";
$selectList .= "<option value=\"$id\" $select>$id</option>";
}
$selectList .= "</select>";
$body .= selectEditStdMenu();
$body .= <<<END
$selectList
Create/Edit Level<br>
<form action='' method=post>
<table>
<tr>
<td>Level: <input type=text name=level size=2></td>
<td>Name: <input type=text name=name></td>
<td>Weight: <input type=text name=weight size=3></td>
<td>
<input type=submit name=button value=Create>
</td>
</tr>
</table>
</form>
END;
if($_POST['button'] == 'Create') {
$db->get_results("INSERT INTO level set subject = '$sel', name = '{$_POST['name']}',weight = '{$_POST['weight']}', level = '{$_POST['level']}' ");
} else if($_POST['button'] == 'Save') {
$levels = $_POST['levels'];
$names = $_POST['names'];
$weights = $_POST['weights'];
for($i = 0; $i < count($levels); $i++) {
$sql = "UPDATE level set name = '{$names[$i]}', weight='{$weights[$i]}' WHERE subject = '{$sel}' and level = '{$levels[$i]}' ";
// echo $sql;
$db->get_results($sql);
}
}
$electives = $db->get_results("SELECT * from level where subject = '$sel' ", ARRAY_A);
$body .= "<form action='' method=post><table border=1><tr><th>Level</th><th>Name</th><th>Weight</th></tr>";
foreach($electives as $el) {
$body .= "<tr><td>{$el['level']}</td>
<td>
<input type=text name=names[] value='{$el['name']}'>
<input type=hidden name=levels[] value='{$el['level']}'>
</td>
<td><input type=text name=weights[] value='{$el['weight']}' size=3></td>
</tr>";
}
$body .= "</table><input type=submit name=button value=Save>";
include ("template.inc");
?>