-
Notifications
You must be signed in to change notification settings - Fork 4
/
editBand.php
177 lines (127 loc) · 5.52 KB
/
editBand.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
<?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;
}
$action = $_GET['action'];
$bandID = $_GET['id'];
$sql = "SELECT * FROM cr_bands WHERE bandID = '$bandID'";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$bandLeader = $row['bandLeader'];
}
// If the form has been submitted, then we need to handle the data.
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$bandLeader = $_POST['bandleader'];
$rehearsaldate = $_POST['rehearsaldate'];
if($id == "") {
$sql = "INSERT INTO cr_bands (bandLeader) VALUES ('$bandLeader')";
mysql_query($sql) or die(mysql_error());
$bandID = mysql_insert_id();
} else {
$sql = "UPDATE cr_bands SET bandLeader = '$bandLeader' WHERE bandID = '$bandID'";
mysql_query($sql) or die(mysql_error());
}
// Now we need to deal with the band changes
// First of all, we need to delete all the people already exisiting on this week so we can repopulate with the correct data.
$sql = "DELETE FROM cr_bandMembers WHERE bandID = '$bandID'";
mysql_query($sql) or die(mysql_error());
foreach ($rehearsaldate as $key => $rehearsaldatevalue) {
addPeopleBand($bandID, $rehearsaldatevalue);
}
header ( "Location: viewBands.php" );
}
$formatting = "true";
include('includes/header.php');
?>
<div class="elementBackground">
<h2>Edit a band</h2>
<form action="editBand.php?id=<?php echo $bandID; ?>" method="post" id="createEvent">
<fieldset>
<label for="bandleader"></label>
<input name="bandleader" id="bandleader" type="text" value="<?php echo $bandLeader; ?>" placeholder="Enter band leader" />
</fieldset>
<h2>Add people to the band:</h2>
<fieldset>
<?php
$sqlPeople = "SELECT *,
(SELECT CONCAT(`firstname`, ' ', `lastname`) FROM cr_users WHERE `cr_users`.id = `cr_skills`.`userID` ORDER BY `cr_users`.firstname) AS `name`,
(SELECT skillID FROM cr_bandMembers WHERE `cr_bandMembers`.`skillID` = `cr_skills`.`skillID` AND `cr_bandMembers`.`bandID` = '$bandID'
LIMIT 1) AS `inBand`
FROM cr_skills WHERE groupID = 2 ORDER BY groupID, name";
$resultPeople = mysql_query($sqlPeople) or die(mysql_error());
$i = 1;
$position = 1;
?><div>
<?php while($viewPeople = mysql_fetch_array($resultPeople, MYSQL_ASSOC)) {
$identifier = $viewPeople['groupID'];
if(isAdmin()) {
$usefulBits = " <a href='index.php?notifyIndividual=$viewPeople[userID]&eventID=$eventID&skillID=$viewPeople[skillID]'><img src='graphics/email.png' /></a> <a href='index.php?skillremove=true&eventID=$eventID&skillID=$viewPeople[skillID]'><img src='graphics/close.png' /></a> <br />";
} else {
$usefulBits = "<br />";
}
if($viewPeople['inBand'] != '')
{ $checked = 'checked="checked"'; } else { $checked = ""; }
if($viewPeople['skill'] != "") {
$skill = " - <em>" . $viewPeople['skill'] . "</em>";
} else {
$skill = "";
}
if($position == 2) {
echo "<div class='checkboxitem right'><label class='styled' for='rehearsaldate[" . $viewPeople['skillID'] . "]'>" .
$viewPeople['name'] . $skill . "</em></label><input class='styled' " . $checked . "type='checkbox' id='rehearsaldate[" .
$viewPeople['skillID'] . "]' name='rehearsaldate[]' value='" .
$viewPeople['skillID'] . "' /></div></div>";
$position = 1;
} else {
if($i == "1") {
$class = "";
$i = "0";
} else {
$class = "";
$i = "1";
}
echo "<div class='row" . $class . "'>
<div class='checkboxitem'><label class='styled' for='rehearsaldate[" . $viewPeople['skillID'] . "]'>" .
$viewPeople['name'] . $skill . "</em></label><input class='styled' " . $checked . "type='checkbox' id='rehearsaldate[" .
$viewPeople['skillID'] . "]' name='rehearsaldate[]' value='" .
$viewPeople['skillID'] . "' /></div>";
$position = 2;
}
}
if ($position == 2) {
echo "</div>";
$position = 1;
}
echo "</div>";
?>
<input type="submit" value="Edit band" />
</fieldset>
</form>
</div>
<?php include('includes/footer.php'); ?>