-
Notifications
You must be signed in to change notification settings - Fork 4
/
editsingleskill.php
138 lines (110 loc) · 4.12 KB
/
editsingleskill.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
/*
This file is part of Church Rota.
Copyright (C) 2011 David Bunce
Church Rota is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Church Rota is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Church Rota. If not, see <http://www.gnu.org/licenses/>.
*/
// 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;
}
$skillID = $_GET['id'];
$sql = "SELECT *
FROM cr_groups
WHERE groupID = '$skillID'";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$id = $row['id'];
$skilldescription = $row['description'];
}
// If the form has been submitted, then we need to handle the data.
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$postdata = $_POST['rehearsaldate'];
if(empty($postdata)) {
$sql = "DELETE FROM cr_skills WHERE groupID = '$skillID'";
mysql_query($sql) or die(mysql_error());
} else {
$sqlPeople = "SELECT *
FROM cr_skills
WHERE groupID = '$skillID'";
$resultPeople = mysql_query($sqlPeople) or die('mysql_error()');
$result = mysql_num_rows($resultPeople);
while($viewPeople = mysql_fetch_array($resultPeople, MYSQL_ASSOC)) {
$membersArray[] = $viewPeople['userID'];
}
$addarray = array_diff($postdata, $membersArray);
while (list ($key, $userid) = each ($addarray)) {
addPeopleSkill($skillID, $userid);
}
// Compare the other way to notice what's disappeared
$deletearray = array_diff($membersArray, $postdata);
while (list ($key2, $userid) = each ($deletearray)) {
removeEventMemberSkill($skillID, $userid);
}
}
// header ( "Location: index.php#section" . $eventID);
}
$formatting = "true";
include('includes/header.php');
?>
<div class="elementBackground">
<h2>Edit skill: <?php echo $skilldescription; ?></h2>
<form action="editsingleskill.php?id=<?php if(isset($skillID)) echo $skillID; ?>" method="post" id="createEvent">
<fieldset>
<?php
$sqlPeople = "SELECT *,
(SELECT groupID FROM cr_skills WHERE cr_skills.userid = cr_users.id AND cr_skills.groupID = '$skillID' LIMIT 1) as existing
FROM cr_users
ORDER BY firstName";
$resultPeople = mysql_query($sqlPeople) or die(mysql_error());
$result = mysql_num_rows($resultPeople);
$half = $result / 2;
$i = 0;
$position = 1;
?><div>
<div class="checkboxlistleft">
<?php while($viewPeople = mysql_fetch_array($resultPeople, MYSQL_ASSOC)) {
?>
<?php if($half == $i): ?>
</div>
<div class="checkboxlistright">
<?php endif; ?>
<div class='checkboxitem'>
<label class='styled' for='rehearsaldate[<?php echo $viewPeople['id']; ?>]'><?php echo $viewPeople['firstName']; ?> <?php echo $viewPeople['lastName']; ?>
<input class='styled'
<?php
if($viewPeople['existing'] != '') {
echo 'checked="checked"';
} ?>
type='checkbox' id='rehearsaldate[<?php echo $viewPeople['id']; ?>]' name='rehearsaldate[]' value='<?php echo $viewPeople['id']; ?>' /></div>
<?php
$i = $i + 1;
}
?>
</div>
</div>
<input type="submit" value="Save" />
</fieldset>
</form>
</div>
<?php include('includes/footer.php'); ?>