-
Notifications
You must be signed in to change notification settings - Fork 4
/
editSkills.php
138 lines (114 loc) · 4.32 KB
/
editSkills.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
<?php
// Include files, including the database connection
include('includes/dbConfig.php');
include('includes/functions.php');
// Start the session. This checks whether someone is logged in and if not redirects them
session_start();
if (isset($_SESSION['is_logged_in']) || $_SESSION['db_is_logged_in'] == true) {
// Just continue the code
} else {
header('Location: login.php');
exit;
}
if (!isAdmin()) {
header('Location: error.php?no=100&page='.basename($_SERVER['SCRIPT_FILENAME']));
exit;
}
// Get the query string
$skillID = $_GET["skillID"];
$skillremove = $_GET['skillremove'];
$skillmove = $_GET['skillmove'];
$value = $_GET['value'];
$method = $_GET['method'];
if ($skillremove == "true") {
removeSkillGroups($skillID);
}
if ($skillmove == "true") {
moveSkillGroups($skillID, $value);
}
// If the form has been submitted, then we need to handle the data.
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if($method == 'newskill') {
$groupID = $_POST['groups'];
$newskill = $_POST['newskill'];
$newskill = strip_tags($newskill);
$rehearsal = $_POST['rehearsal'];
$rehearsal = strip_tags($rehearsal);
$sql = ("INSERT INTO cr_groups (description, rehearsal, formatgroup) VALUES ('$newskill', '$rehearsal', '3')");
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
} else {
// Handle renaming of the titles
$formindex = $_POST['formindex'];
$description = $_POST['description'];
$formArray = array_combine($formindex, $description);
while (list ($key, $valadd) = each ($formArray)) {
updateSkill($key, $valadd);
}
}
// After we have inserted the data, we want to head back to the main users page
header('Location: editSkills.php'); // Move to the home page of the admin section
exit;
}
include('includes/header.php');
?>
<div class="elementBackground">
<h2>Edit Skills / Change Groups</h2>
<p>
<form action="editSkills.php" method="post">
<fieldset>
<strong>Group 1:</strong><br />
<?php $sql = "SELECT * FROM cr_groups ORDER BY formatgroup, groupid";
$result = mysql_query($sql) or die(mysql_error());
$formatgroup = 1;
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$skillID = $row['groupID'];
if ($row['formatgroup'] == $formatgroup) {
// Do nothing, because they are all in the same group
$down = $formatgroup + 1;
$up = $formatgroup - 1;
} else {
// Update the group heading
$formatgroup = $row['formatgroup'];
$down = $formatgroup + 1;
$up = $formatgroup - 1;
echo "<br /><strong>Group " . $formatgroup . "</strong><br />";
}
echo '<input type="hidden" name="formindex[]" value="' . $row['groupID'] . '" />';
echo "<input name='description[]' value='" . $row['description'] . "' />";
echo " <a class='smalllink' href='editSkills.php?skillmove=true&value=" . $down . "&skillID=" . $skillID . "'><img src='graphics/down.png' /> </a>";
echo "<a class='smalllink' href='editSkills.php?skillmove=true&value=" . $up . "&skillID=" . $skillID . "'><img src='graphics/up.png' /> </a>";
?>
<a href="editsingleskill.php?id=<?php echo $skillID; ?>">
<img src='graphics/tool.png' /></a>
<?php
if ($skillID != 2) {
//delete button, only if not skillgroup "band", because of its hardcoded special status (band members)
echo "<a href='editSkills.php?skillremove=true&skillID=" . $skillID . "'><img src='graphics/close.png' /></a><br />";
}
} ?>
</fieldset>
<input type="submit" value="Update skills" /></p>
</form>
<h2>Add a new skill:</h2>
<p><form action="editSkills.php?method=newskill" method="post" id="addSkill">
<fieldset>
<label for="newskill">New skill:</label>
<input id="newskill" name="newskill" type="text" placeholder="Enter skill name" />
<label for="rehearsal">This skill group must attend rehearsals:</label>
<input name="rehearsal" id="rehearsal" type="checkbox" value="1" />
<input type="submit" value="Add new skill" />
</fieldset>
</form>
</p>
</div>
<?php
if(isAdmin()) { ?>
<div id="right">
<div class="item"><a href="settings.php">Back to settings</a></div>
<div class="item"><a href="viewUsers.php">View all users</a></div>
</div>
<?php } ?>
<?php include('includes/footer.php'); ?>