PageRenderTime 25ms CodeModel.GetById 8ms RepoModel.GetById 0ms 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. //make array of week
  17. $t = date_create("$today");
  18. $byDate[date_format($t,"Y-m-d")][]=' ';
  19. for ($x=1; $x<=6; $x++) {
  20. date_add($t,date_interval_create_from_date_string("1 days"));
  21. $byDate[date_format($t,"Y-m-d")][]=' ';
  22. }
  23. //get date 6 days from today (to create a week, including today)
  24. $date=date_create("$today");
  25. date_add($date,date_interval_create_from_date_string("6 days"));
  26. //echo "Seven days from now is: ".date_format($date,"Y-m-d")."</br>";
  27. //sql query selects all events between today's date and 6 days from now
  28. $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']."'";
  29. if (!mysqli_query($con,$sql))
  30. {
  31. die('Error: ' . mysqli_error());
  32. }
  33. else
  34. {
  35. //execute the SQL query
  36. $result = mysqli_query($con,$sql);
  37. }
  38. //$byDate needs to be initialized first so that days with no events still show up...
  39. echo "</br>Events in the Next 7 days: </br>";
  40. while ($row = mysqli_fetch_array($result)) {
  41. //for each event, display its name as a link to detailed event info, with eid in the url
  42. // echo "<a href='./eventInfo.php?eid=".$row['eid']."'>".$row['name']."</a><br>";
  43. $byDate[$row['date']][]=$row;
  44. }
  45. //print_r($byDate);
  46. echo "<div id='links'>";
  47. echo "</br>";
  48. //if session user is set (from logging in), show link to create event and log out
  49. if(isset($_SESSION['User'])){
  50. echo "Welcome ".$_SESSION['User']."</br>";
  51. echo "<a href='./CreateEvent.php'>Create Event</a></br>";
  52. echo "<a href='./CreateOrganization.php'>Create Organization</a></br>";
  53. echo "<a href='./addMembers.php'>Add Members to Org</a></br>";
  54. $sql2="SELECT supervisor FROM Users WHERE uid = '$_SESSION[uid]'";
  55. if (!mysqli_query($con,$sql2)) {
  56. die('Error: ' . mysqli_error());
  57. }
  58. else {
  59. //execute the SQL query
  60. $result2 = mysqli_query($con,$sql2);
  61. }
  62. $row = mysqli_fetch_array($result2);
  63. if($row['supervisor']==1) {
  64. echo "<a href='./approveEvents.php'>Approve Events</a></br>";
  65. }
  66. echo "<a href='./logout.php'>Don't forget to logout</a><br>";
  67. }
  68. else {
  69. //if session user is not set, show link to log in and to create user
  70. $_SESSION['User'] = null;
  71. echo "<a href='./login.php'>Log In</a></br>";
  72. echo "<a href='./CreateUser.php'>Create User</a></br>";
  73. }
  74. ?>
  75. <!DOCTYPE HTML>
  76. <title> Midd Events </title>
  77. <html>
  78. <form method="POST" action="insert1.php">
  79. Search: <input type="text" name="Search" /> <br> <br>
  80. <input type="submit" value="Search"/> <br> <br>
  81. </form>
  82. <!--This creates the drop down list-->
  83. <form name="thisForm" method="POST" action="eventsByGenre.php">
  84. <p>Select Genre: <select size="1" name="genre">
  85. <option value="Dance"> Dance </option>
  86. <option value="Party"> Party </option>
  87. <option value="Clam Bake"> Clam Bake </option>
  88. <option value="Pineapple"> Pineapple </option>
  89. <option value="drinking"> drinking </option>
  90. <option value="sports"> sports </option>
  91. <input type="submit" value="Go">
  92. </select></p>
  93. <p>
  94. </p>
  95. </form>
  96. <?php
  97. echo "</div>";
  98. $days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday','Thursday','Friday', 'Saturday');
  99. $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');
  100. echo "</br>";
  101. echo "<div id='content'>";
  102. echo "<div id='table1'>";
  103. echo "<table>";
  104. echo "<tr>";
  105. foreach($byDate as $key => $value) {
  106. echo "<td>";
  107. echo "<div class = 'date'>";
  108. echo "<a href='./date.php?date=".$key."' >";
  109. echo $days[date( "w", strtotime($key))]."</br>";
  110. echo $months[date( "m", strtotime($key))]." ".date( "d", strtotime($key))."</br></br>";
  111. echo "</a></div>";
  112. //array shift removes first value of array, which kept being current time for some reason.
  113. array_shift($value);
  114. //print out each event that occurs on day, as a link to more details
  115. foreach($value as $event){
  116. echo "<a href='./eventInfo.php?eid=".$event['eid']."'>".$event['name']."</a> ".date('g:i',strtotime($event['time']))."<br>";
  117. }
  118. echo "</td>";
  119. }
  120. echo "</tr>";
  121. echo "</table>";
  122. echo "</div>";
  123. echo "</div>";
  124. //Display events
  125. //echo "</br>Events in the Next 7 days: </br>";
  126. //while ($row = mysqli_fetch_array($result)) {
  127. //for each event, display its name as a link to detailed event info, with eid in the url
  128. // echo "<a href='./eventInfo.php?eid=".$row['eid']."'>".$row['name']."</a><br>";
  129. //}
  130. //view session data:
  131. //print_r($_SESSION);
  132. //close connection
  133. mysql_close($con);
  134. ?>
  135. </body>
  136. </html>
  137. <style>
  138. #genres{
  139. float:top;
  140. }
  141. a:visited, a:link {
  142. color:#0066CC;
  143. }
  144. a{
  145. font-size:20;
  146. }
  147. #links {
  148. border-radius: 25px;
  149. color: pink;
  150. position:fixed;
  151. background-color:black;
  152. opacity: .90;
  153. width:10%;
  154. padding-top: 20px;
  155. padding-bottom: 20px;
  156. padding-right: 10%;
  157. padding-left: 10%;
  158. border-width: 3px;
  159. border-color: black;
  160. margin-top: 10%;
  161. margin-right: 20%;
  162. margin-left: 65%;
  163. z-index: 1;
  164. //background-color: white;
  165. //opacity: .9;
  166. //float:left;
  167. //width: 200px ;
  168. }
  169. #content {
  170. float:left;
  171. }
  172. #table1 {
  173. border-radius: 25px;
  174. opacity: .9;
  175. color: pink;
  176. background-color: black;
  177. width: 1100px ;
  178. margin-left: auto ;
  179. margin-right: auto ;
  180. }
  181. div.date a:link,div.date a:visited {
  182. text-transform:uppercase;
  183. font-weight:bold;
  184. color: #0066CC;
  185. }
  186. table, th, td {
  187. border-radius: 25px;
  188. border: 1px solid white;
  189. text-align:center;
  190. }
  191. td {
  192. vertical-align:top;
  193. width:50;
  194. }
  195. </style>