PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/middCalendar/events.php

https://github.com/gkipkorir/public_html
PHP | 337 lines | 275 code | 42 blank | 20 comment | 6 complexity | f1e90ea951dc995689541e4f179ab538 MD5 | raw file
  1. <?php session_start(); ?>
  2. <?php
  3. //start session
  4. //must happen before anything else on the page
  5. //print_r($_SESSION);
  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. {
  21. date_add($t,date_interval_create_from_date_string("1 days"));
  22. $byDate[date_format($t,"Y-m-d")][]=' ';
  23. }
  24. //get date 6 days from today (to create a week, including today)
  25. $date=date_create("$today");
  26. date_add($date,date_interval_create_from_date_string("6 days"));
  27. //echo "Seven days from now is: ".date_format($date,"Y-m-d")."</br>";
  28. //sql query selects all events between today's date and 6 days from now
  29. $sql="SELECT * FROM Events WHERE date BETWEEN '".date_format($date1,"Y-m-d")."' AND '".date_format($date,"Y-m-d")."' AND approved=1 ORDER BY date, time";
  30. if (!mysqli_query($con,$sql))
  31. {
  32. die('Error: ' . mysqli_error());
  33. }
  34. else
  35. {
  36. //execute the SQL query
  37. $result = mysqli_query($con,$sql);
  38. }
  39. //$byDate needs to be initialized first so that days with no events still show up...
  40. function sortFunction( $a, $b ) {
  41. return strtotime($a['date']) - strtotime($b["date"]);
  42. }
  43. while ($row = mysqli_fetch_array($result)) {
  44. $result1[] = $row;
  45. }
  46. //usort($result1, "sortFunction");
  47. //while ($row = mysqli_fetch_array($result)) {
  48. //for each event, display its name as a link to detailed event info, with eid in the url
  49. // echo "<a href='./eventInfo.php?eid=".$row['eid']."'>".$row['name']."</a><br>";
  50. foreach($result1 as $row){
  51. $byDate[$row['date']][]=$row;
  52. }
  53. //}
  54. //print_r($byDate);
  55. $days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday','Thursday','Friday', 'Saturday');
  56. $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');
  57. echo "</br>";
  58. echo "<div id='content'>";
  59. echo "<div id='table1'>";
  60. echo "<div id='more'><a id='b1' href='javascript:toggle();'>More</a></div>";
  61. /////////////////////////////
  62. echo "<div id='links'>";
  63. //if session user is set (from logging in), show link to create event and log out
  64. if(isset($_SESSION['User'])){
  65. echo "Welcome ".$_SESSION['User']."</br>";
  66. echo "<a href='./MyEvents.php'>My Events</a></br>";
  67. echo "<a href='./CreateEvent.php'>Create Event</a></br>";
  68. echo "<a href='./CreateOrganization.php'>Create Organization</a></br>";
  69. echo "<a href='./addMembers.php'>Add Members to Org</a></br>";
  70. $sql2="SELECT supervisor FROM Users WHERE uid = '$_SESSION[uid]'";
  71. if (!mysqli_query($con,$sql2))
  72. {
  73. die('Error: ' . mysqli_error());
  74. }
  75. else
  76. {
  77. //execute the SQL query
  78. $result2 = mysqli_query($con,$sql2);
  79. }
  80. $row = mysqli_fetch_array($result2);
  81. if($row['supervisor']==1){
  82. echo "<a href='./approveEvents.php'>Approve Events</a></br>";
  83. }
  84. echo "<a href='./logout.php'>Don't forget to logout</a><br>";
  85. }
  86. else{ //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. //link to search page
  92. ?>
  93. <html>
  94. <body>
  95. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  96. <SCRIPT LANGUAGE="javascript">
  97. $(links).hide();
  98. function toggle() {
  99. if($(links).is(':visible')){
  100. $(links).hide();
  101. document.getElementById('b1').innerHTML = "More";
  102. }else{
  103. $(links).show();
  104. document.getElementById('b1').innerHTML = "Less";
  105. }
  106. }
  107. </SCRIPT>
  108. <form action="insert1.php" method="post">
  109. <label for="midd_search_query">Search</label>
  110. <input type="search" id="midd_search_query" class="search_query x-webkit-speech" name="Search" placeholder="Search Calendar" x-webkit-speech required>
  111. <input type="submit" value="Go">
  112. <!--<input type="hidden" id="midd_ajax_search_url" value="/go/search">-->
  113. </form>
  114. <!--This creates the insert boxes
  115. <form action="insert1.php" method="post">
  116. Search: <input type="text" name="Search" /> <br> <br>
  117. <input type="submit" value="Search"/> <br> <br>
  118. </form>-->
  119. <!--This creates the drop down list-->
  120. <form name="thisForm" method="POST" action="query.php">
  121. <p>Select Genre: <select size="1" name="my_dropdown">
  122. <option value="Dance"> Dance </option>
  123. <option value="Party"> Party </option>
  124. <option value="Clam Bake"> Clam Bake </option>
  125. <option value="Pineapple"> Pineapple </option>
  126. <option value="OldCalendar"> Old Calendar </option>
  127. <option value="sports"> sports </option>
  128. <input type="submit" value="Go" name="btm_submit">
  129. </select></p>
  130. <p>
  131. </p>
  132. </form>
  133. </body>
  134. </html>
  135. <?php
  136. echo "</div>";
  137. //////////////////////////
  138. echo "<table>";
  139. echo "<tr>";
  140. foreach($byDate as $key => $value)
  141. {
  142. echo "</br>";
  143. //echo "<td>";
  144. echo "<div class = 'date'>";
  145. echo "<a href='./date.php?date=".$key."' >";
  146. echo $days[date( "w", strtotime($key))]."</br>";
  147. echo $months[date( "m", strtotime($key))]." ".date( "d", strtotime($key))."</br></br>";
  148. echo "</a></div>";
  149. //array shift removes first value of array, which kept being current time for some reason.
  150. array_shift($value);
  151. //print out each event that occurs on day, as a link to more details
  152. foreach($value as $event){
  153. echo "<a href='./eventInfo.php?eid=".$event['eid']."'>".$event['name']."</a> ".date('g:i A',strtotime($event['time']));
  154. //echo "<a href='./eventInfo.php?eid=".$event['eid']."'>".$event['name']."</a> ".date("l jS \of F Y h:i:s A",strtotime($event['time']))."<br>";
  155. echo "<div class = 'description'>".substr($event['description'],0,35)."...</div>";
  156. }
  157. //echo "</td>";
  158. }
  159. echo "</tr>";
  160. echo "</table>";
  161. echo "</div>";
  162. echo "</div>";
  163. //Display events
  164. //echo "</br>Events in the Next 7 days: </br>";
  165. //while ($row = mysqli_fetch_array($result)) {
  166. //for each event, display its name as a link to detailed event info, with eid in the url
  167. // echo "<a href='./eventInfo.php?eid=".$row['eid']."'>".$row['name']."</a><br>";
  168. //}
  169. //view session data:
  170. //print_r($_SESSION);
  171. //close connection
  172. mysql_close($con)
  173. ?>
  174. <style>
  175. html{
  176. background: #737373;
  177. background-image:url('./1003background1.png');
  178. background-attachment: fixed;
  179. }
  180. a:visited, a:link{
  181. color:#0066CC;
  182. }
  183. #links{
  184. border-radius: 25px;
  185. color: pink;
  186. //position:fixed;
  187. background-color:black;
  188. opacity: .90;
  189. width:50%;
  190. //padding-top: 20px;
  191. padding-bottom: 20px;
  192. padding-right: 10%;
  193. //padding-left: 10%;
  194. border-width: 3px;
  195. border-color: black;
  196. margin-top: 4%;
  197. margin-right: 20%;
  198. //margin-left: 65%;
  199. z-index: 1;
  200. //float:left;
  201. //width: 200px ;
  202. //background: white;
  203. //opacity:0.9;
  204. }
  205. #content{
  206. //float:left;
  207. }
  208. #table1{
  209. border-radius: 25px;
  210. opacity: .9;
  211. color: pink;
  212. background-color: black;
  213. width: 1100px ;
  214. margin-left: auto ;
  215. margin-right: auto ;
  216. text-align:center;
  217. font-size: 28;
  218. }
  219. div.date a:link,div.date a:visited{
  220. text-transform:uppercase;
  221. font-weight:bold;
  222. color:white;
  223. font-size:35;
  224. }
  225. .description{
  226. color: #585858;
  227. font-size:22;
  228. }
  229. tr{
  230. text-align:center;
  231. }
  232. table, th, td
  233. {
  234. font-size:20;
  235. border: 1px solid black;
  236. text-align:center;
  237. }
  238. td{
  239. vertical-align:top;
  240. width:200;
  241. }
  242. #more{
  243. text-align:left;
  244. }
  245. </style>
  246. <!DOCTYPE HTML>
  247. <html>
  248. <title> Midd Events </title>
  249. <body>
  250. </body>
  251. </html>