PageRenderTime 123ms CodeModel.GetById 106ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/middCalendar/eventsByGenre.php

https://github.com/gkipkorir/public_html
PHP | 232 lines | 200 code | 17 blank | 15 comment | 7 complexity | 8c8cb329656511b21329e6113c6e838e MD5 | raw file
  1<?php 
  2	//start session
  3	//must happen before anything else on the page
  4	session_start();
  5	echo " <body background=1003background1.png>";
  6	//set up the connection to the database
  7	define('DB_SERVER','panther.cs.middlebury.edu');
  8	define('DB_USERNAME','wschaaf');
  9	define('DB_PASSWORD','wschaaf');
 10	define('DB_DATABASE','wschaaf_Calendar');
 11	$con = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE) or die("Could not connect");
 12	//get todays date in form (y-m-d)
 13	$date = getdate();
 14	$today = $date['year']."-".$date['mon']."-".$date['mday'];
 15	$date1 = date_create("$today");
 16
 17
 18	//make array of week
 19	$t = date_create("$today");
 20	$byDate[date_format($t,"Y-m-d")][]=' ';
 21	for ($x=1; $x<=6; $x++) {
 22	   date_add($t,date_interval_create_from_date_string("1 days"));
 23	   $byDate[date_format($t,"Y-m-d")][]=' ';
 24	}
 25
 26	//get date 6 days from today (to create a week, including today)
 27	$date=date_create("$today");
 28	date_add($date,date_interval_create_from_date_string("6 days"));
 29	//echo "Seven days from now is: ".date_format($date,"Y-m-d")."</br>";
 30
 31	//sql query selects all events between today's date and 6 days from now
 32	$sql="SELECT * FROM Events WHERE date BETWEEN '".date_format($date1,"Y-m-d")."' AND '".date_format($date,"Y-m-d")."' AND approved=1 AND genre = '".$_POST['genre']."'";
 33
 34
 35	if (!mysqli_query($con,$sql))
 36	{
 37	  die('Error: ' . mysqli_error());
 38	}
 39	else
 40	{
 41	 //execute the SQL query
 42	 $result = mysqli_query($con,$sql);
 43	}
 44
 45
 46	//$byDate needs to be initialized first so that days with no events still show up...
 47
 48	echo "</br>Events in the Next 7 days: </br>";
 49	while ($row = mysqli_fetch_array($result)) {
 50	 //for each event, display its name as a link to detailed event info, with eid in the url
 51	// echo "<a href='./eventInfo.php?eid=".$row['eid']."'>".$row['name']."</a><br>";
 52	$byDate[$row['date']][]=$row;
 53	}
 54
 55	//print_r($byDate);
 56
 57
 58
 59
 60	echo "<div id='links'>";
 61
 62
 63	echo "</br>";
 64
 65	//if session user is set (from logging in), show link to create event and log out
 66	if(isset($_SESSION['User'])){
 67	    echo "Welcome ".$_SESSION['User']."</br>";
 68	    echo "<a href='./CreateEvent.php'>Create Event</a></br>";
 69	    echo "<a href='./CreateOrganization.php'>Create Organization</a></br>";
 70	    echo "<a href='./addMembers.php'>Add Members to Org</a></br>";
 71	    $sql2="SELECT supervisor FROM Users WHERE uid = '$_SESSION[uid]'";
 72	  	if (!mysqli_query($con,$sql2)) {
 73			die('Error: ' . mysqli_error());
 74	  	}
 75	  	else {
 76	 		//execute the SQL query
 77			$result2 = mysqli_query($con,$sql2);	    
 78	  	}    
 79		$row = mysqli_fetch_array($result2);
 80		if($row['supervisor']==1) {
 81		    echo "<a href='./approveEvents.php'>Approve Events</a></br>";
 82		}
 83	    echo "<a href='./logout.php'>Don't forget to logout</a><br>";
 84	}
 85	else { 
 86		//if session user is not set, show link to log in and to create user
 87	    $_SESSION['User'] = null;
 88	    echo "<a href='./login.php'>Log In</a></br>";
 89	    echo "<a href='./CreateUser.php'>Create User</a></br>";
 90	}
 91?>
 92
 93
 94
 95
 96<!DOCTYPE HTML>
 97<title> Midd Events </title>
 98<html>
 99
100
101      
102	<form method="POST" action="insert1.php">
103	Search: <input type="text" name="Search" /> <br> <br>
104	<input type="submit" value="Search"/> <br> <br>
105	</form>
106
107	<!--This creates the drop down list-->
108	<form name="thisForm" method="POST" action="eventsByGenre.php">
109	<p>Select Genre: <select size="1" name="genre">
110	<option value="Dance"> Dance </option>
111	<option value="Party"> Party </option>
112	<option value="Clam Bake"> Clam Bake </option>
113	<option value="Pineapple"> Pineapple </option>
114	<option value="drinking"> drinking </option>
115	<option value="sports"> sports </option>
116	<input type="submit" value="Go">
117	</select></p>
118	<p>
119	</p>
120	</form>
121
122	<?php
123		echo "</div>";
124
125		$days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday','Thursday','Friday', 'Saturday');
126		$months = array('01'=>'January', '02'=>'February', '03'=>'March', '04'=>'April','05'=>'May','06'=>'June', '07'=>'July', '08'=>'August', '09'=>'September', '10'=>'October', '11'=>'November', '12'=>'December');
127
128		echo "</br>";
129		echo "<div id='content'>";
130		echo "<div id='table1'>";
131		echo "<table>";
132		echo "<tr>";
133		foreach($byDate as $key => $value) {
134			echo "<td>";
135			echo "<div class = 'date'>";
136			echo "<a href='./date.php?date=".$key."' >";
137			echo $days[date( "w", strtotime($key))]."</br>";
138			echo $months[date( "m", strtotime($key))]." ".date( "d", strtotime($key))."</br></br>";
139			echo "</a></div>";
140			//array shift removes first value of array, which kept being current time for some reason.
141			array_shift($value);
142			//print out each event that occurs on day, as a link to more details
143			foreach($value as $event){
144				echo "<a href='./eventInfo.php?eid=".$event['eid']."'>".$event['name']."</a> ".date('g:i',strtotime($event['time']))."<br>";
145			}
146			echo "</td>";
147		}
148		echo "</tr>";
149		echo "</table>";
150		echo "</div>";
151		echo "</div>";
152
153		//Display events
154		//echo "</br>Events in the Next 7 days: </br>";
155		//while ($row = mysqli_fetch_array($result)) {
156		 //for each event, display its name as a link to detailed event info, with eid in the url
157		// echo "<a href='./eventInfo.php?eid=".$row['eid']."'>".$row['name']."</a><br>";
158		//}
159		//view session data:
160		//print_r($_SESSION);
161		//close connection
162		mysql_close($con);
163	?>
164</body>
165
166</html>
167
168
169<style>
170	#genres{
171		float:top;
172	}
173	a:visited, a:link {
174		color:#0066CC;
175	}
176
177	a{
178		font-size:20;
179	}
180	#links {
181		border-radius: 25px;
182		color: pink;
183		position:fixed;				
184		background-color:black;
185		opacity: .90;
186		width:10%;
187		padding-top: 20px;
188		padding-bottom: 20px;
189		padding-right: 10%;
190		padding-left: 10%;
191		border-width: 3px;
192		border-color: black;
193		margin-top: 10%;
194		margin-right: 20%;
195		margin-left: 65%;
196		z-index: 1;
197		//background-color: white;
198		//opacity: .9;
199		//float:left;
200		//width: 200px ;
201	}
202	#content {
203		float:left;
204	}
205	#table1 {
206		border-radius: 25px;
207		opacity: .9;
208		color: pink;
209		background-color: black;
210		width: 1100px ;
211		margin-left: auto ;
212		margin-right: auto ;
213	
214	}
215	div.date a:link,div.date a:visited {
216		text-transform:uppercase;
217		font-weight:bold;
218		color: #0066CC;
219	}
220
221	table, th, td {
222		border-radius: 25px;
223		border: 1px solid white;
224		text-align:center;
225	}
226	td {
227		vertical-align:top;
228		width:50;
229	}
230</style>
231
232