forked from mikeygh2/CS430-APO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_event.php
More file actions
182 lines (126 loc) · 4.87 KB
/
Copy pathcreate_event.php
File metadata and controls
182 lines (126 loc) · 4.87 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
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
<?
function newPDO(){
$dsn = "mysql:host=localhost;dbname=CS430";
$user = "root";
$pass = "root";
return new PDO($dsn, $user, $pass);
}
function validateForm(){
// retrieve all post values
$eventName = $_POST['eventName'];
$eventDescription = $_POST['eventDescription'];
$eventDate = $_POST['eventDate'];
$type = $_POST['type'];
$type = 1;
$fundraising = $_POST['fundraising'];
$eventLocation = $_POST['eventLocation'];
$publicNotes = $_POST['publicNotes'];
$privateNotes = $_POST['privateNotes'];
$recurring = $_POST['recurring'];
$startTime = $_POST['startTime'];
$endTime = $_POST['endTime'];
echo "<br/>.".$startTime.".<br/>.".$endTime.".<br/>";
$max = $_POST['max'];
$projectLeader = $_POST['projectLeader'];
$startDate = $eventDate." ".$startTime.":00";
echo $startDate;
$endDate = $eventDate." ".$endTime.":00";
echo "<br/>";
// check to see if required items have values
if($eventName == NULL || $eventDescription == NULL || $eventDate == NULL || $eventLocation == NULL || $max == NULL)
{
echo '<div class="entry"><strong>All of the required fields were not filled out. Please try again.</strong></div>';
// print_form();
}
// if the event is recurring, additional information is required
if($recurring != NULL && ($startTime == NULL || $endTime == NULL)){
echo '<div class="entry"><strong>All of the required fields were not filled out. Please try again.</strong></div>';
// print_form();
}
// next steps are to range check some of the values and then insert them into the appropriate tables
$db = newPDO();
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
$sql = "INSERT INTO Event (Name,startDate,endDate,Description,Type,Location,publicNotes,privateNotes,Recurring,Fundraising)
VALUES (:eventName,:startDate,:endDate,:eventDescription,:type,:eventLocation,:publicNotes,:privateNotes,:Recurring,:Fundraising)";
$stmt = $db->prepare($sql);
$stmt->execute(array(':eventName'=>$eventName,
':startDate'=>$startDate,
':endDate'=>$endDate,
':eventDescription'=>$eventDescription,
':type'=>$type,
':eventLocation'=>$eventLocation,
':publicNotes'=>$publicNotes,
':privateNotes'=>$privateNotes,
':Recurring'=>$recurring,
':Fundraising'=>$fundraising));
print_r($stmt->errorInfo());
$affected_rows = $stmt->rowCount();
echo $affected_rows."<br/>";
$E_Id_LastInsert = $db->lastInsertId();
echo $E_Id_LastInsert;
$sql = "INSERT INTO Shift (E_Id,startTime,endTime,max)
VALUES (:E_Id,:startTime,:endTime,:max)";
$stmt = $db->prepare($sql);
echo "<br/>".$max."<br/>";
$stmt->bindParam(":E_Id",$E_Id_LastInsert,PDO::PARAM_INT);
$stmt->bindParam(":startTime",$startTime,PDO::PARAM_STR);
$stmt->bindParam(":endTime",$endTime,PDO::PARAM_STR);
$stmt->bindParam(":max",$max,PDO::PARAM_INT);
$stmt->execute();
/*
$stmt->execute(array(':E_Id'=>$E_Id_LastInsert,
':startTime'=>$startTime,
':endTime'=>$endTime,
':max'=>$max));
*/
print_r($stmt->errorInfo());
}
function createEvent() {
echo <<<END
<div class="content">
<form method="POST">
<p>
<b>The "Create Event" Form</b><br/>
<label for="eventName">Event Name</label>
<input type="text" name="eventName" value="Sample Event Name"/><br/>
<label for="eventDescription">Event Description</label><br/>
<textarea rows="3" cols="20" name="eventDescription">Event Description goes here</textarea><br/>
<label for="eventDate">Event Date</label>
<input type="date" name="eventDate"/><br/>
<label for="eventStartTime">Start Time: </label>
<input type="time" name="startTime"/><br/>
<label for="eventEndTime">End Time: </label>
<input type="time" name="endTime"/><br/>
<label for="type">Event Type</label>
<select name="type">
<option value="" selected>Community</option>
<option value="">Chapter</option>
<option value="">Campus</option>
<option value="">Country</option>
<option value="">Broho</option>
</select><br/>
<label for="fundraising">Fundraising?</label>
<input type="radio" name="fundraising" value="T">yes
<input type="radio" name="fundraising" value="F" checked>no<br/>
<label for="Location">Location</label>
<input type="text" name="eventLocation" value="SUB"/><br/>
<label for="Notes">Public Notes</label><br/>
<textarea rows="3" cols="20" name="publicNotes">public note test</textarea><br/>
<label for="Notes">Private Notes</label><br/>
<textarea rows="3" cols="20" name="privateNotes">private note test</textarea><br/>
<label for="Recurring">Recurring?</label><br/>
<input type="radio" name="recurring" value="T">yes
<input type="radio" name="recurring" value="F" checked>no<br/>
<label for="maxEnrollment">Max Enrollment</label>
<input type="number" name="max" min="1" max="150" value="10"/><br/>
<input type="hidden" name="stage" value="verify" />
<p align="left"><input type="submit" value="Submit" /></p>
</form>
END;
echo "<hr/>";
}
if(isset($_POST['stage'])){
validateForm();
}else{
createEvent();
}