-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeleteEvent.php
97 lines (73 loc) · 3.38 KB
/
deleteEvent.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
<?php
require "logged_in_check.php";
if ($_SESSION['isAdmin']==0 && $_SESSION['isEventAdmin']==0) {
echo "<meta http-equiv=\"REFRESH\" content=\"0;url=points.php\">";
die;
} else {}
require "database_connect.php";
require "html_header_begin.txt";
require "html_header_end.txt";
$tempEventID = $_POST['eventID'];
$query = $db->prepare("DELETE FROM Event WHERE eventID=:tempEventID");
$query->execute(array('tempEventID'=>$tempEventID));
// CALCULATE ALL MEMBERS' TOTAL POINTS
//------------------------------------
$resultMem = $db->query("SELECT memberID FROM Member WHERE status != 'alumni'");
$resultMem->setFetchMode(PDO::FETCH_ASSOC);
while($rowMem = $resultMem->fetch()) {
$tempMemberID = $rowMem['memberID'];
$query = $db->prepare("SELECT pointValue, type FROM AttendsEvent JOIN Event ON AttendsEvent.eventID = Event.eventID WHERE memberID = :tempMemberID");
$query->execute(array('tempMemberID'=>$tempMemberID));
$query->setFetchMode(PDO::FETCH_ASSOC);
$num = 0;
$mandatory = 0;
$sports = 0;
$social = 0;
$work = 0;
while($row = $query->fetch()) {
if($row['type']=='mandatory'){
$mandatory++;
$num += $row['pointValue'];
}
else if($row['type']=='sports'){
$sports++;
$num += $row['pointValue'];
}
else if($row['type']=='social'){
$social++;
$num += $row['pointValue'];
}
else if($row['type']=='work'){
$work++;
$num += $row['pointValue'];
}
}
// SET ALL MEMBERS' TOTAL POINTS IN DATABASE
//------------------------------------------------------
$query2 = $db->prepare("UPDATE Member SET memberPoints = :num, mandatoryEventCount = :mandatory, sportsEventCount = :sports, socialEventCount = :social, workEventCount = :work WHERE memberID = :tempMemberID");
$query2->execute(array('num'=>$num, 'mandatory'=>$mandatory, 'sports'=>$sports, 'social'=>$social, 'work'=>$work, 'tempMemberID'=>$tempMemberID));
}
// CALCULATE ALL FAMILIES' TOTAL POINTS
//-------------------------------------
$resultFam = $db->query("SELECT familyID FROM Family");
$resultFam->setFetchMode(PDO::FETCH_ASSOC);
while($rowFam = $resultFam->fetch()) {
$tempFamilyID = $rowFam['familyID'];
$famnum = 0;
$query = $db->prepare("SELECT SUM(points) AS pts FROM
(SELECT SUM(pointValue) AS points FROM Member JOIN (AttendsEvent JOIN Event ON AttendsEvent.eventID = Event.eventID) ON Member.memberID = AttendsEvent.memberID WHERE Member.memFamilyID = :tempFamilyID AND (Member.status != 'alumni')
UNION ALL
SELECT SUM(pointValue) FROM AttendsEvent JOIN Event ON AttendsEvent.eventID = Event.eventID WHERE AttendsEvent.familyID = :tempFamilyID AND AttendsEvent.memberID IS NULL) subquery");
$query->execute(array('tempFamilyID'=>$tempFamilyID));
$query->setFetchMode(PDO::FETCH_ASSOC);
$row = $query->fetch();
$famnum = $row['pts'];
// SET ALL FAMILIES' TOTAL POINTS IN DATABASE
// ------------------------------------------
$query2 = $db->prepare("UPDATE Family SET familyPoints = :famnum WHERE familyID = :tempFamilyID");
$query2->execute(array('famnum'=>$famnum, 'tempFamilyID'=>$tempFamilyID));
}
echo "<h3>Event Deleted</h3>";
echo "<meta http-equiv=\"refresh\" content=\"2; url=editEvents.php\">";
require "html_footer.txt";
?>